Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 99 additions & 16 deletions dashboard/app/planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,53 @@ def add_months(y, m, k):
return yy, mm + 1


def _items(lines, start=0):
"""Checkbox items from a run of lines: {'line', 'orig', 'text', 'state': todo|doing|done|note, 'sub': [text]}."""
items = []
for i, line in enumerate(lines, start):
line = line.rstrip()
if line.startswith("- "):
mt = re.match(r"- \[([ xX.])\] (.*)", line)
state = ({" ": "todo", ".": "doing"}.get(mt.group(1).lower(), "done")) if mt else "note"
items.append(dict(line=i, orig=line, text=mt.group(2) if mt else line[2:], state=state, sub=[]))
elif items and re.match(r"^\s+- ", line):
items[-1]["sub"].append(re.sub(r"^\s+- (\[[ xX.]\] )?", "", line))
return items


def read_deliverables(text):
"""'## Deliverables' → {(year, month): [(heading, [item])]}: one '### YYYY-MM …' block per rung, in file order."""
out, lines = {}, text.split("\n")
head = next((i for i, l in enumerate(lines) if l.rstrip() == "## Deliverables"), None)
if head is None:
return out
block, start = None, None
def close(end):
if block:
out.setdefault(block[0], []).append((block[1], _items(lines[start:end], start)))
for i in range(head + 1, len(lines) + 1):
line = lines[i].rstrip() if i < len(lines) else "## "
if line.startswith("## "):
close(i)
break
m = re.match(r"### (\d{4})-(0[1-9]|1[0-2])\b\s*[—–-]?\s*(.*)", line)
if m:
close(i)
block, start = ((int(m.group(1)), int(m.group(2))), m.group(3).strip()), i + 1
return out


def read_ladder(path, rel):
"""One ladder file: its '## Rungs' rows grouped by (year, month), gate cells tagged as ladder.py tags them."""
"""One ladder file: its '## Rungs' rows grouped by (year, month), gate cells tagged as ladder.py tags them,
and each rung's '## Deliverables' checklist (matched by month, then by rung name when a month has several)."""
lad = dict(rel=rel, label=rel, title="", months={}, gates=[], errors=[], missing=not path.exists())
if lad["missing"]:
return lad
text = _text(path)
lad["title"] = next((l[2:].strip() for l in text.split("\n") if l.startswith("# ")), rel)
lad["label"] = lad["title"]
lad["gates"] = _table(text, "Gates")
deliverables = read_deliverables(text)
for row in _table(text, "Rungs"):
m = re.fullmatch(r"(\d{4})-(0[1-9]|1[0-2])", row.get("month", ""))
if not m:
Expand All @@ -84,6 +122,14 @@ def read_ladder(path, rel):
lad["errors"].append("rung %r: unknown gate tag %s" % (row.get("rung", "?"), tag.group(0).strip()))
row[g] = dict(state=state, text=value)
lad["months"].setdefault((int(m.group(1)), int(m.group(2))), []).append(row)
for ym, rows in lad["months"].items():
blocks = deliverables.get(ym, [])
for row in rows:
# a block names its rung ("### 2026-11 — 50 µm"); an unnamed block, or the month's only block, fits the month's only rung
hit = next((b for b in blocks if b[0] and b[0] in row.get("rung", "")), None)
if hit is None and len(rows) == 1 and blocks:
hit = blocks[0]
row["items"] = hit[1] if hit else []
return lad


Expand All @@ -100,12 +146,16 @@ def ladders(settings):


def plan_path(settings, rel):
"""The one file a plan edit may touch: plan/days/YYYY-MM-DD.md or plan/weeks/YYYY-MM-DD.md (a Monday)."""
"""The one file a plan edit may touch: plan/days/YYYY-MM-DD.md, plan/weeks/YYYY-MM-DD.md (a Monday),
or a sprint file plan/<name>.md (its deliverables checklist)."""
if not isinstance(rel, str):
raise Error(400, "invalid_path", "Plan path must be a string")
sprint = re.fullmatch(r"plan/([A-Za-z0-9][A-Za-z0-9_.-]*)\.md", rel)
if sprint and ".." not in sprint.group(1):
return resolve_within(settings.repo_root, "plan", sprint.group(1) + ".md")
m = re.fullmatch(r"plan/(days|weeks)/(\d{4}-\d{2}-\d{2})\.md", rel)
if not m:
raise Error(400, "invalid_path", "Plan path must be plan/days/YYYY-MM-DD.md or plan/weeks/YYYY-MM-DD.md")
raise Error(400, "invalid_path", "Plan path must be plan/<sprint>.md, plan/days/YYYY-MM-DD.md or plan/weeks/YYYY-MM-DD.md")
try:
day = dt.date.fromisoformat(m.group(2))
except ValueError:
Expand Down Expand Up @@ -137,9 +187,7 @@ def read_plan(settings, rel):
if sec is None:
sec = dict(name="(no project)", level=2, items=[])
info["sections"].append(sec)
mt = re.match(r"- \[([ xX.])\] (.*)", line)
state = ({" ": "todo", ".": "doing"}.get(mt.group(1).lower(), "done")) if mt else "note"
sec["items"].append(dict(line=i, orig=line, text=mt.group(2) if mt else line[2:], state=state, sub=[]))
sec["items"] += _items([line], i)
elif sec and sec["items"] and re.match(r"^\s+- ", line):
sec["items"][-1]["sub"].append(re.sub(r"^\s+- (\[[ xX.]\] )?", "", line))
return info
Expand Down Expand Up @@ -247,16 +295,10 @@ def render_ladder(settings, today=None):
notes, problems = [], []
for lad in lads:
cells.append('<div class="lname">%s<small>%s</small></div>' % (html.escape(lad["label"]), html.escape(lad["rel"])))
names = _gate_names(lad["gates"])
for ym in months:
cls = " now" if ym == cur else " past" if ym < cur else ""
rungs = ""
for r in lad["months"].get(ym, []):
gates = "".join('<span class="g %s" title="%s · %s: %s">%s</span>' % (
r[g]["state"], g.upper(), r[g]["state"], html.escape(r[g]["text"] or "—"), g.upper()) for g in ("g1", "g2", "g3"))
rungs += ('<div class="rung"><div class="rtop"><b>%s</b><span class="rdata">%s</span></div><div class="gates">%s</div>'
'<div class="rstat">%s</div><div class="rnb">%s</div></div>'
% (inline(r.get("rung", "")), inline(r.get("data", "")), gates, inline(r.get("status", "")),
inline(r.get("notebook_question", ""))))
rungs = "".join(_rung_card(lad["rel"], r, names) for r in lad["months"].get(ym, []))
cells.append('<div class="lcell%s">%s</div>' % (cls, rungs))
if lad["missing"]:
notes.append('<p class="empty"><b>%s</b> is missing, so its row is empty.</p>' % html.escape(lad["rel"]))
Expand All @@ -267,15 +309,56 @@ def render_ladder(settings, today=None):
% (html.escape(lad["title"]), html.escape(lad["rel"]), gates))
problems += ["%s: %s" % (lad["rel"], e) for e in lad["errors"]]
body = ('<h1>%s · ladders by month · %d row%s, %d months (scroll sideways; ‹ › move one month)</h1>'
'<p class="legend">Gates: <span class="g met">met</span> <span class="g open">open</span> <span class="g failed">failed</span> '
'<span class="g target">target</span> <span class="g none">—</span> · tags are read from each ladder file, never inferred; hover a gate for its text</p>'
'<p class="legend">A rung is one month\'s deliverable; it passes when its three gates are met: '
'<b>G1 it ran</b> · <b>G2 quality</b> · <b>G3 cost</b> (each ladder\'s own gate table is under the grid). '
'Gate colours: <span class="g met">met</span> <span class="g open">open</span> <span class="g failed">failed</span> '
'<span class="g target">target</span> <span class="g none">—</span>, read from the ladder file, never inferred. '
'Below the gates, the rung\'s deliverables are a checklist (<span class="dot done"></span> done '
'<span class="dot doing"></span> in progress <span class="dot todo"></span> open) edited in place.</p>'
'<div class="lwrap"><button class="larr" data-dir="-1" title="earlier month">‹</button>'
'<div class="lscroll" id="lscroll"><div class="lgrid" data-n="%d">%s</div></div>'
'<button class="larr" data-dir="1" title="later month">›</button></div>%s'
% (today.strftime("%a %m/%d"), len(lads), "s" if len(lads) != 1 else "", len(months), len(months), "".join(cells), "".join(notes)))
return page("Plan · Ladder", "plan", "ladder", body, problems, "Rows: every plan/*.md with a ## Rungs table (one per sprint).")


GATE_WORDS = {"g1": "it ran", "g2": "quality", "g3": "cost"}
GATE_STATE = {"met": "met", "open": "open", "failed": "failed", "target": "target", "none": "—"}


def _gate_names(gates):
"""{'g1': ('it ran', question)} from a ladder's Gates table, with the default words when the table lacks them."""
names = {}
for g in gates:
m = re.match(r"\**(G[123])\**\s*[—–-]+\s*(.+?)\**$", g.get("gate", ""))
if m:
names[m.group(1).lower()] = (m.group(2).strip("* "), g.get("question", ""))
return {k: names.get(k, (GATE_WORDS[k], "")) for k in GATE_WORDS}


def _rung_card(rel, r, names):
"""One rung: header (name, data, overall state), one row per gate, then the deliverables checklist."""
states = [r[g]["state"] for g in ("g1", "g2", "g3")]
overall = ("failed" if "failed" in states else "met" if states[0] == "met" and states[1] == "met" and states[2] in ("met", "none")
else "open" if "met" in states or "open" in states else "target" if "target" in states else "none")
rows = ""
for g in ("g1", "g2", "g3"):
word, question = names[g]
rows += ('<div class="gate %s" title="%s"><span class="g %s">%s</span><span class="gw">%s</span><span class="gt">%s</span></div>'
% (r[g]["state"], html.escape(question, quote=True), r[g]["state"], g.upper(), html.escape(word),
inline(r[g]["text"]) if r[g]["text"].strip() not in ("", "-", "—") else '<i class="none">no evidence yet</i>'))
items = r.get("items", [])
done = sum(1 for it in items if it["state"] == "done")
todo = ('<div class="dhead">deliverables <span class="dn">%d / %d</span></div><ul class="todo">%s</ul>'
% (done, len(items), "".join(_todo(rel, it) for it in items))) if items else ""
nb = r.get("notebook_question", "").strip()
nb = '<div class="rnb">%s</div>' % inline(nb, links=True) if nb not in ("", "-", "—") else ""
return ('<div class="rung %s"><div class="rtop"><b>%s</b><span class="rdata">%s</span><span class="g %s">%s</span></div>'
'<div class="gates">%s</div>%s<div class="rstat">%s</div>%s</div>'
% (overall, inline(r.get("rung", "")), inline(r.get("data", "")), overall, GATE_STATE[overall], rows, todo,
inline(r.get("status", "")), nb))


def _todo(rel, item):
box = ('<input type="checkbox" data-op="toggle"%s>' % (" checked" if item["state"] == "done" else "")) if item["state"] != "note" else ""
subs = "".join('<span class="sub">– %s</span>' % inline(s) for s in item["sub"])
Expand Down
27 changes: 19 additions & 8 deletions dashboard/app/static/planner.css
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ button.primary { background:var(--accent); color:#fff; border-color:var(--accent
.lname small { display:block; font-weight:400; font-size:11px; word-break:break-all }
.lmon { scroll-snap-align:start; font-weight:600; font-size:13px; color:var(--mute); text-align:center; background:var(--bg) }
.lmon.now { color:var(--accent); background:var(--now) } .lcell.now { background:var(--now) } .lcell.past { opacity:.7 }
.rung { border:1px solid var(--line); border-radius:8px; padding:6px 8px; margin-bottom:6px; background:var(--card); font-size:12px }
.rtop { display:flex; justify-content:space-between; gap:6px; font-size:13px } .rdata { color:var(--mute); white-space:nowrap }
.gates { display:flex; gap:4px; margin:5px 0 }
.g { border-radius:4px; padding:0 6px; font-size:11px; font-weight:600; border:1px solid var(--line); color:var(--mute); cursor:help }
.rung { border:1px solid var(--line); border-left:5px solid var(--line); border-radius:8px; padding:7px 9px; margin-bottom:8px; background:var(--card); font-size:12px }
.rung.met { border-left-color:var(--done) } .rung.open { border-left-color:var(--open) } .rung.failed { border-left-color:var(--late) }
.rung.target { border-left-style:dashed; border-left-color:var(--mute) }
.rtop { display:flex; align-items:center; gap:6px; font-size:13px } .rtop b { flex:1 } .rdata { color:var(--mute); white-space:nowrap }
.gates { display:flex; flex-direction:column; gap:3px; margin:6px 0 }
.gate { display:flex; align-items:baseline; gap:6px; line-height:1.35 } .gate .gw { color:var(--mute); white-space:nowrap; min-width:46px } .gate .gt { flex:1 }
.gate.met .gt { color:var(--fg) } .gate .gt i.none { color:var(--mute) }
.g { border-radius:4px; padding:0 6px; font-size:11px; font-weight:600; border:1px solid var(--line); color:var(--mute); white-space:nowrap }
.g.met { background:var(--done); border-color:var(--done); color:#fff } .g.open { background:var(--open); border-color:var(--open); color:#fff }
.g.failed { background:var(--late); border-color:var(--late); color:#fff } .g.target { border-style:dashed; color:var(--fg) } .g.none { opacity:.4 }
.rstat { color:var(--fg) } .rnb { color:var(--mute); font-size:11px }
.g.failed { background:var(--late); border-color:var(--late); color:#fff } .g.target { border-style:dashed; color:var(--fg) } .g.none { opacity:.5 }
.dhead { margin:6px 0 2px; font-size:11px; font-weight:600; color:var(--mute); text-transform:uppercase; letter-spacing:.03em }
.dhead .dn { margin-left:6px; font-weight:600; color:var(--done); text-transform:none }
.rung ul.todo { font-size:12px } .rung ul.todo li { padding:3px 0 } .rung ul.todo .sub { font-size:11px }
.rstat { color:var(--mute); font-size:11px; margin-top:5px } .rnb { color:var(--mute); font-size:11px } .rnb a { color:var(--accent) }
.dot { display:inline-block; width:9px; height:9px; border-radius:50%; border:1px solid var(--line); vertical-align:middle }
.dot.done { background:var(--done); border-color:var(--done) } .dot.doing { background:var(--open); border-color:var(--open) }
.legend { font-size:12px; color:var(--mute); margin-bottom:8px } .legend .g { cursor:default }
/* daily / weekly */
.daynav { display:flex; gap:6px; align-items:center; margin-bottom:12px; flex-wrap:wrap }
Expand All @@ -43,8 +52,10 @@ button.primary { background:var(--accent); color:#fff; border-color:var(--accent
.proj h4 { font-size:12px; color:var(--mute); margin:8px 0 4px } .proj p { margin:4px 0 }
ul.todo { list-style:none; margin:0; padding:0 } ul.todo li { display:flex; gap:8px; align-items:flex-start; padding:4px 0; border-top:1px solid var(--line) }
ul.todo li:first-child { border-top:0 } ul.todo input { margin:4px 0 0; flex:0 0 auto } ul.todo .txt { flex:1 }
ul.todo li.done .txt { color:var(--mute); text-decoration:line-through }
ul.todo li.doing .txt::before { content:"doing · "; color:var(--soon); font-size:11px; font-weight:600 }
ul.todo li.done .txt { color:var(--mute) } ul.todo li.done .txt::before { content:"✓ "; color:var(--done); font-weight:700 }
ul.todo li.todo .txt::before { content:"○ "; color:var(--mute) }
ul.todo li.done input, ul.todo li.todo input, ul.todo li.doing input { accent-color:var(--done) }
ul.todo li.doing .txt::before { content:"◐ "; color:var(--soon); font-weight:700 } ul.todo li.doing .txt { color:var(--fg) }
ul.todo li.note { padding-left:24px } ul.todo .sub { display:block; color:var(--mute); font-size:12px; margin-top:2px }
.del { border:0; background:none; color:var(--mute); font-size:15px; line-height:1; padding:2px 4px; visibility:hidden }
ul.todo li:hover .del { visibility:visible } .del:hover { color:var(--late) }
Expand Down
26 changes: 26 additions & 0 deletions dashboard/tests/test_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ def test_sprints_are_plan_files_with_rungs(self):
self.assertIn(needle, html)
self.assertNotIn("style=", html) # the CSP blocks inline style attributes; the grid collapsed to one column once

def test_rung_deliverables_are_a_checklist_edited_in_the_ladder_file(self):
shutil.copyfile(FIXTURES / "LADDER.md", self.repo / "plan/LADDER.md")
text = (self.repo / "plan/LADDER.md").read_text() + (
"\n## Deliverables\n\n### 2026-10 — 20 µm\n\n- [x] ran the cube\n - note under it\n- [.] score it\n- [ ] write it up\n"
"\n### 2026-11 — 50 µm\n\n- [ ] decode\n\n### 2026-11 — 20 µm iteration\n\n- [x] iter-01\n\n## After\n\n- [ ] not a deliverable\n")
(self.repo / "plan/LADDER.md").write_text(text)
lad = planner.ladders(self.settings)[0]
oct_ = lad["months"][(2026, 10)][0]["items"]
self.assertEqual([(i["state"], i["text"], i["sub"]) for i in oct_],
[("done", "ran the cube", ["note under it"]), ("doing", "score it", []), ("todo", "write it up", [])])
by_name = {r["rung"]: [i["text"] for i in r["items"]] for r in lad["months"][(2026, 11)]}
self.assertEqual(by_name, {"20 µm iteration": ["iter-01"], "50 µm": ["decode"], "100 µm": []})
self.assertEqual(lad["months"][(2026, 9)][0]["items"], [])
html = planner.render_ladder(self.settings, self.today)
self.assertIn('<span class="dn">1 / 3</span>', html)
self.assertIn('<span class="gw">quality</span>', html)
self.assertIn('class="gate met"', html)
self.assertIn('data-path="plan/LADDER.md"', html)
self.assertNotIn("style=", html)
line = oct_[2]["line"]
self.assertEqual(planner.apply_edit(self.settings, "plan/LADDER.md", line, oct_[2]["orig"], "toggle"), "toggle: plan/LADDER.md:%d" % (line + 1))
self.assertIn("- [x] write it up", (self.repo / "plan/LADDER.md").read_text())
for bad in ("plan/../LADDER.md", "plan/sub/x.md", "LADDER.md", "plan/.hidden.md"):
with self.assertRaises(Error):
planner.plan_path(self.settings, bad)

def test_day_file_parse_toggle_delete_and_create(self):
self.assertFalse(planner.read_plan(self.settings, DAY)["exists"])
self.assertIn("Create it", planner.render_daily(self.settings, self.today, self.today))
Expand Down
Loading