@warren-dean/code-kit 0.25.0 → 0.26.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +24 -0
  4. package/README.md +70 -59
  5. package/bin/code-kit.mjs +113 -3
  6. package/hooks/act.mjs +96 -0
  7. package/hooks/guard-bash.mjs +27 -1
  8. package/hooks/hooks.json +42 -1
  9. package/hooks/lib/config.mjs +26 -2
  10. package/hooks/lib/events.mjs +626 -0
  11. package/hooks/lib/harness.mjs +8 -0
  12. package/hooks/lib/instructions.mjs +1 -1
  13. package/hooks/lib/next.mjs +22 -0
  14. package/hooks/lib/plan.mjs +45 -9
  15. package/hooks/lib/publish.mjs +144 -0
  16. package/hooks/lib/queue.mjs +36 -0
  17. package/hooks/lib/snapshot.mjs +33 -3
  18. package/hooks/lib/storymap.mjs +54 -17
  19. package/hooks/lib/timeline.mjs +94 -44
  20. package/hooks/lib/worktrees.mjs +19 -11
  21. package/hooks/mod/art.mjs +0 -81
  22. package/hooks/mod/board.mjs +1743 -0
  23. package/hooks/mod/characters.mjs +516 -0
  24. package/hooks/mod/loop.mjs +17 -3
  25. package/hooks/mod/mission.mjs +2 -93
  26. package/hooks/mod/panes.mjs +111 -422
  27. package/hooks/mod/register.mjs +482 -184
  28. package/hooks/mod/surface/character.mjs +79 -0
  29. package/hooks/mod/surface/clock.mjs +37 -0
  30. package/hooks/mod/surface/rail.mjs +33 -0
  31. package/hooks/mod/view.mjs +30 -602
  32. package/hooks/session.mjs +14 -11
  33. package/package.json +2 -1
  34. package/skills/decide/SKILL.md +1 -1
  35. package/skills/dispatch/SKILL.md +1 -1
  36. package/skills/init/SKILL.md +1 -1
  37. package/skills/next/SKILL.md +1 -1
  38. package/skills/review/SKILL.md +1 -1
  39. package/templates/agent.md +1 -1
  40. package/templates/claude-md.md +2 -2
  41. package/hooks/mod/register.test.ts +0 -4932
@@ -15,6 +15,7 @@ import {
15
15
  RESULT_ID,
16
16
  SETTINGS_ID,
17
17
  approvalsText,
18
+ agentsAlive,
18
19
  agentsAtWork,
19
20
  shownState,
20
21
  attribution,
@@ -23,7 +24,6 @@ import {
23
24
  approvePane,
24
25
  questionAsidePrompt,
25
26
  commandItself,
26
- band,
27
27
  bandLines,
28
28
  finishedStories,
29
29
  ago,
@@ -35,23 +35,40 @@ import {
35
35
  refusalView,
36
36
  resultPane,
37
37
  settingsView,
38
+ usageSection,
38
39
  usageSummary,
39
40
  usageForReport,
40
41
  presenceOf,
41
42
  withUsage,
42
43
  } from './view.mjs';
43
44
  import { holdable } from './hold.mjs';
44
- import { axisStart, barCells, poseOf, rasterCells, sprite, tintOf } from './art.mjs';
45
+ import { axisStart, barCells } from './art.mjs';
45
46
  import {
46
- DEFAULT_UI,
47
47
  SENDBACK_ID,
48
- closeGoesBack,
48
+ codeTab,
49
+ decisionsTab,
50
+ journalTab,
49
51
  laneActions,
50
- lanesFrame,
51
52
  liveLevel,
53
+ mapTab,
52
54
  sendBackPane,
55
+ storyPane,
53
56
  toolLine,
54
57
  } from './panes.mjs';
58
+ import {
59
+ BOARD_UI,
60
+ bandOf,
61
+ board,
62
+ escapeGoesBack,
63
+ lanesAtWork,
64
+ moveSelection,
65
+ needsOf,
66
+ poseFor,
67
+ selectable,
68
+ sheetView,
69
+ viewFrame,
70
+ } from './board.mjs';
71
+ import { charactersOf } from './characters.mjs';
55
72
  import {
56
73
  agentFileModel,
57
74
  answeredPrompt,
@@ -196,16 +213,27 @@ const activityOf = (agentId, now) => {
196
213
  const harness = () => harnessSettings(model.check?.harness);
197
214
  // Panes v2 (spec 11): the Lanes pane's own state, the lead's last tool call, and a send-back waiting
198
215
  // for the person's reason.
199
- let paneUi = { ...DEFAULT_UI };
216
+ let paneUi = { ...BOARD_UI };
200
217
  let leadLast = null; // { tool, at }
201
218
  let sendingBack = null; // { lane, branch, story, reason, error }
202
219
  let storyOpen = null; // the drill-down's story (VIEW-7): { id, lane, data, error }
203
220
  const personAsks = []; // prompts the person asked for (stop an agent), waiting for the lead to be idle
204
- // VIEW-3: the characters' animation, and the surface the Lanes pane was last drawn on.
205
- let frame = 0;
206
- let animation = null; // the timer repainting working characters, while one works
221
+ // The surface the Lanes pane was last drawn on, and its room.
207
222
  let paneSurface = null;
208
223
  let paneColumns = 80;
224
+ let paneRows = 40;
225
+ let paneOpen = false; // whether the Lanes pane is open, as the last look found it
226
+ // UI-11: each lane's one-off move at an event, while it plays: lane → { kind, key, at }; UI-2: the
227
+ // requirements that turned tested, while their segment fills: id → at.
228
+ const moves = new Map();
229
+ const freshTested = new Map();
230
+ const MOVE_MS = 1500;
231
+ // UI-12: the surfaces a surface module failed on, which draw everything still from then on.
232
+ const faulted = {};
233
+ // UI-4: each card's story map (`code-kit map <story> --json`), and each lane's refusals not yet
234
+ // resolved: lane → [{ layer, path }].
235
+ const storyMaps = {};
236
+ const troubles = new Map();
209
237
  let codeMap = null; // MAP-1: `code-kit map <story> --json` for the Code map tab's story
210
238
  let trailData = null; // TRAIL-1: `code-kit trail --json` while the Trail tab shows
211
239
  let journalData = null; // JOURNAL-1: `code-kit journal --json`, for the Journal tab and the decisions
@@ -227,7 +255,9 @@ export function register(on) {
227
255
  await $.command
228
256
  .register({
229
257
  name: 'lanes',
230
- description: "code-kit's lanes: agents, stories, branches and what's ready",
258
+ description:
259
+ "code-kit's pane: the build, what needs you, the lanes, the queue and the log; or a view: trail, map, journal, usage, characters",
260
+ argumentHint: '[trail|map|journal|usage|characters]',
231
261
  immediate: true,
232
262
  })
233
263
  .catch(unavailable('lanes'));
@@ -267,9 +297,16 @@ export function register(on) {
267
297
  // The held call's answer, for the `code-kit hold` it waits in.
268
298
  const answerHeld = (id, answer) =>
269
299
  $.process.run(['node', cli, 'hold', id, '--answer', answer], { cwd });
300
+ // A read that fails or outlasts its time is null, like one that can't say: one slow read never
301
+ // takes the band or the pane down with it.
270
302
  const json = async (...args) => {
271
- const ran = await $.process.run(['node', cli, ...args, '--json'], { cwd });
272
- return ran.exitCode === 0 ? parseJson(ran.stdout) : null;
303
+ const ran = await $.process.run(['node', cli, ...args, '--json'], { cwd }).catch((err) => {
304
+ $.ui.log(`code-kit: \`code-kit ${args[0]}\` didn't answer: ${err?.message ?? err}`, {
305
+ to: 'debug',
306
+ });
307
+ return null;
308
+ });
309
+ return ran?.exitCode === 0 ? parseJson(ran.stdout) : null;
273
310
  };
274
311
  // What a CLI run said, in a line: why it refused, for a notice.
275
312
  const firstLine = (ran) => (ran.stderr || ran.stdout).trim().split('\n')[0];
@@ -361,6 +398,7 @@ export function register(on) {
361
398
  : null;
362
399
  // The agents at work; none where the session has none bound (claude -p before it mounts).
363
400
  const atWork = agentsAtWork(await $.agent.list().catch(() => []));
401
+ const before = { state: model.state, status: model.status, queue: model.queue };
364
402
  model = {
365
403
  state: projectState(check, status, nextStep, atWork),
366
404
  requests,
@@ -387,14 +425,61 @@ export function register(on) {
387
425
  elsewhere: owned?.elsewhere ?? [],
388
426
  };
389
427
  if (model.state.kind === 'ok') await act.registerReviewer();
428
+ await act.events(before, await $.clock.now());
390
429
  await act.readMaps();
391
430
  $.ui.invalidate('ui.render');
392
431
  },
432
+ // UI-11: a lane's one-off move at each event (a story arriving, handed back, sent back or
433
+ // merged); UI-2: the requirements that turned tested. Each plays once, then the pane is still.
434
+ events: async (before, now) => {
435
+ if (before.state?.kind !== 'ok' || model.state?.kind !== 'ok') return;
436
+ const was = new Map(before.state.lanes.map((l) => [l.name, l]));
437
+ const done = new Set(
438
+ (model.state.stories ?? []).filter((s) => s.state === 'done').map((s) => s.id),
439
+ );
440
+ for (const l of model.state.lanes) {
441
+ const prev = was.get(l.name);
442
+ if (!prev) continue;
443
+ const then = shownState(prev, before.queue ?? []);
444
+ const nowShown = shownState(l, model.queue ?? []);
445
+ let kind = null;
446
+ if (prev.story?.id && prev.story.id !== l.story?.id && done.has(prev.story.id))
447
+ kind = 'merged';
448
+ else if (l.story?.id && l.story.id !== prev.story?.id && l.state === 'building')
449
+ kind = 'arriving';
450
+ else if (nowShown === 'sent back' && then !== 'sent back') kind = 'sent-back';
451
+ else if (['in review', 'queued'].includes(nowShown) && then === 'building')
452
+ kind = 'handed-back';
453
+ if (!kind) continue;
454
+ moves.set(l.name, {
455
+ kind,
456
+ key: `${kind}:${l.story?.id ?? prev.story?.id}:${now}`,
457
+ at: now,
458
+ });
459
+ // A story merged or moved on leaves no refusal of the lane's standing.
460
+ if (kind === 'merged' || kind === 'arriving') troubles.delete(l.name);
461
+ }
462
+ const tested = (status) =>
463
+ new Set(
464
+ (status?.requirements ?? [])
465
+ .filter((r) => r.state === 'done' && r.tests?.length)
466
+ .map((r) => r.id),
467
+ );
468
+ if (before.status) {
469
+ const old = tested(before.status);
470
+ for (const id of tested(model.status)) if (!old.has(id)) freshTested.set(id, now);
471
+ }
472
+ if (moves.size || freshTested.size)
473
+ $.clock
474
+ .sleep(MOVE_MS + 100)
475
+ .then(() => $.ui.invalidate('ui.render'))
476
+ .catch(() => {});
477
+ },
393
478
  // MAP-1, TRAIL-1: what the Code map and Trail tabs draw, read while they show.
394
479
  readMaps: async () => {
395
480
  if (model.state?.kind !== 'ok') return;
396
- if (paneUi.tab === 'code') {
397
- const id = mapStoryOf(stateNow(), paneUi.selected, paneUi.mapStory);
481
+ if (paneUi.view === 'code') {
482
+ const id = mapStoryOf(stateNow(), selectedLaneName(), paneUi.mapStory);
398
483
  // MAP-5: the whole project reads every code file, so at most every 30 seconds.
399
484
  const now = await $.clock.now();
400
485
  const fresh =
@@ -404,13 +489,24 @@ export function register(on) {
404
489
  if (id === 'project') projectRead = now;
405
490
  }
406
491
  }
407
- if (paneUi.tab === 'map') trailData = (await json('trail')) ?? trailData;
492
+ if (paneUi.view === 'trail') trailData = (await json('trail')) ?? trailData;
493
+ // UI-4: each card's story map, for the layers its changed files are in.
494
+ if (paneOpen)
495
+ for (const l of lanesAtWork(stateNow(), model.queue ?? []).atWork) {
496
+ const id = l.story?.id;
497
+ if (id && l.story.state !== 'done')
498
+ storyMaps[id] = (await json('map', id)) ?? storyMaps[id];
499
+ }
408
500
  // TEAM-6: since you last looked, read once each time its tab opens, which marks it read.
409
501
  if (teamUi.tab === 'activity' && model.check?.team && !teamSince)
410
502
  teamSince = (await json('team', 'since')) ?? { people: {} };
411
503
  // JOURNAL-1, DECIDE-2: the lineage, for the Journal tab and the decisions' cards.
412
504
  const deciding = held.size > 0 || (model.requests?.open ?? []).length > 0;
413
- if (model.check?.docs?.plan && (['journal', 'decisions'].includes(paneUi.tab) || deciding))
505
+ // UI-5: the Log reads it whenever the pane is open.
506
+ if (
507
+ model.check?.docs?.plan &&
508
+ (paneOpen || ['journal', 'decision'].includes(paneUi.view) || deciding)
509
+ )
414
510
  journalData = (await json('journal')) ?? journalData;
415
511
  },
416
512
  // REVW-2: the reviewer, read-only by the hooks' rule for agents outside the lanes. Registered
@@ -558,13 +654,43 @@ export function register(on) {
558
654
  [...agentsAtWork(await $.agent.list().catch(() => []))].sort().join(','),
559
655
  ].join('\n');
560
656
  },
561
- // PANE-1: open the Lanes pane, or close it when it's open.
562
- lanes: async () => {
657
+ // PANE-1: open the Lanes pane, or close it when it's open. UI-6: `/lanes trail`, `map`,
658
+ // `journal`, `usage` and `characters` open that view, over the panels.
659
+ lanes: async (args = '') => {
660
+ const asked = (typeof args === 'string' ? args : '').trim().split(/\s+/)[0].toLowerCase();
661
+ const views = {
662
+ trail: 'trail',
663
+ map: 'code',
664
+ journal: 'journal',
665
+ usage: 'usage',
666
+ characters: 'characters',
667
+ };
668
+ if (asked && !views[asked])
669
+ return {
670
+ text: `/lanes ${asked} isn't a view: try /lanes, or /lanes trail, map, journal, usage or characters.`,
671
+ };
563
672
  // Asked, not remembered: the person may have closed it with Escape.
564
- if ((await $.ui.panes()).some((p) => p.id === PANE_ID)) {
673
+ const isOpen = (await $.ui.panes()).some((p) => p.id === PANE_ID);
674
+ if (isOpen && !asked) {
565
675
  await $.ui.close({ id: PANE_ID });
676
+ paneOpen = false;
677
+ return {};
678
+ }
679
+ if (asked) {
680
+ paneUi = {
681
+ ...paneUi,
682
+ view: views[asked],
683
+ ...(asked === 'map' ? { mapStory: 'project', mapFile: null } : {}),
684
+ };
685
+ storyOpen = null;
686
+ }
687
+ if (isOpen) {
688
+ $.ui.invalidate('ui.render');
689
+ await act.readMaps();
690
+ $.ui.invalidate('ui.render');
566
691
  return {};
567
692
  }
693
+ paneOpen = true;
568
694
  await act.reload();
569
695
  if (model.state.kind === 'none') return { text: NOT_CODE_KIT };
570
696
  const placed = await $.ui.open({
@@ -580,11 +706,16 @@ export function register(on) {
580
706
  // DECIDE-3: the Decisions tab, on the decision the person asked about.
581
707
  decide: async (line) => {
582
708
  const cards = cardsNow(await $.clock.now());
709
+ // UI-3: the card of the very line chosen, else the first of its kind.
710
+ const exact = cards.findIndex(
711
+ (c) => c.source?.kind === line?.kind && c.source?.text === line?.text,
712
+ );
583
713
  const at = Math.max(
584
714
  0,
585
- cards.findIndex((c) => c.line.kind === line?.kind),
715
+ exact >= 0 ? exact : cards.findIndex((c) => c.line.kind === line?.kind),
586
716
  );
587
- paneUi = { ...paneUi, tab: 'decisions', decision: at, story: null };
717
+ paneUi = { ...paneUi, view: 'decision', decision: at };
718
+ storyOpen = null;
588
719
  if (!(await $.ui.panes()).some((p) => p.id === PANE_ID))
589
720
  await $.ui.open({ id: PANE_ID, title: 'Lanes', focus: true, closeOnEscape: true });
590
721
  $.ui.invalidate('ui.render');
@@ -1706,8 +1837,9 @@ export function register(on) {
1706
1837
  beaten = at;
1707
1838
  await $.process.run(['node', cli, 'sessions', 'beat', '--session', session], { cwd });
1708
1839
  },
1709
- // SCHED-1: a lane this session's agent claimed, with no agent of that lane still running here for a
1710
- // minute (stopped with TaskStop, or gone without its finish), is released for its next story.
1840
+ // SCHED-1: a lane this session's agent claimed, with no agent of that lane left here for a minute
1841
+ // (ended, stopped with TaskStop, or gone without its finish), is released for its next story. One
1842
+ // pending, waiting or idle is still alive, and keeps it.
1711
1843
  freeLanes: async () => {
1712
1844
  const at = await $.clock.now();
1713
1845
  // The first look only starts the clock: a session's first minute frees nothing.
@@ -1716,14 +1848,10 @@ export function register(on) {
1716
1848
  lanesFreed = at;
1717
1849
  const claims = ((await json('lanes')) ?? []).filter((c) => c.session === session);
1718
1850
  if (!claims.length) return;
1719
- const running = new Set(
1720
- ((await $.agent.list().catch(() => [])) ?? [])
1721
- .filter((a) => a.status === 'running')
1722
- .map((a) => a.type),
1723
- );
1851
+ const alive = agentsAlive(await $.agent.list().catch(() => []));
1724
1852
  for (const c of claims) {
1725
1853
  const type = model.check?.lanes?.[c.lane]?.agent;
1726
- if (!type || running.has(type) || at - Date.parse(c.since) < LANES_FREE_MS) continue;
1854
+ if (!type || alive.has(type) || at - Date.parse(c.since) < LANES_FREE_MS) continue;
1727
1855
  await $.process.run(['node', cli, 'lanes', 'release', c.lane], { cwd }).catch(() => {});
1728
1856
  await act.record('free', `${c.lane}${c.story ? ` · ${c.story}` : ''}`);
1729
1857
  }
@@ -1779,6 +1907,7 @@ export function register(on) {
1779
1907
  id: agent.id,
1780
1908
  story: a.story,
1781
1909
  minutes: h.stall.restartMinutes,
1910
+ cli,
1782
1911
  }),
1783
1912
  });
1784
1913
  await act.record('restart', `${lane} · ${a.story} (${n}/${h.stall.maxRestarts})`);
@@ -1804,34 +1933,6 @@ export function register(on) {
1804
1933
  }
1805
1934
  if (loop.pending.length) await act.step('tick');
1806
1935
  },
1807
- // VIEW-3: working characters repaint in place while the pane shows them; nothing runs otherwise.
1808
- animate: async () => {
1809
- const open = (await $.ui.panes()).some((p) => p.id === PANE_ID);
1810
- const now = await $.clock.now();
1811
- const art = artNow(now, liveNow(now));
1812
- const working = Object.keys(art.poses).filter((n) => art.poses[n] === 'working');
1813
- if (!open || paneSurface !== 'terminal' || !working.length) {
1814
- animation?.cancel();
1815
- animation = null;
1816
- return;
1817
- }
1818
- if (animation) return;
1819
- animation = $.clock.every(400, async () => {
1820
- frame = (frame + 1) % 2;
1821
- const at = await $.clock.now();
1822
- const still = artNow(at, liveNow(at));
1823
- for (const name of Object.keys(still.poses).filter((n) => still.poses[n] === 'working'))
1824
- await $.ui
1825
- .blit({
1826
- requestId: PANE_ID,
1827
- key: `char-${name}`,
1828
- cells: rasterCells(
1829
- sprite('working', frame, still.tints[name], { lead: name === 'lead' }),
1830
- ),
1831
- })
1832
- .catch(() => {});
1833
- });
1834
- },
1835
1936
  // --- panes v2: the selected lane's acts (VIEW-6) ----------------------------------------
1836
1937
  // A prompt the person asked for: submitted now if the lead is idle, else when it next is.
1837
1938
  askLead: async (prompt, kind, target) => {
@@ -1934,7 +2035,7 @@ export function register(on) {
1934
2035
  openStory: async (lane) => {
1935
2036
  if (!lane.story) return;
1936
2037
  const id = lane.story.id;
1937
- paneUi = { ...paneUi, story: id, file: null };
2038
+ paneUi = { ...paneUi, view: 'story', file: null };
1938
2039
  storyOpen = { id, lane: lane.name, data: null, error: null };
1939
2040
  $.ui.invalidate('ui.render');
1940
2041
  const ran = await $.process.run(['node', cli, 'story', id, '--json'], {
@@ -1952,7 +2053,7 @@ export function register(on) {
1952
2053
  $.ui.invalidate('ui.render');
1953
2054
  },
1954
2055
  closeStory: () => {
1955
- paneUi = { ...paneUi, story: null, file: null };
2056
+ paneUi = { ...paneUi, view: null, file: null };
1956
2057
  storyOpen = null;
1957
2058
  $.ui.invalidate('ui.render');
1958
2059
  },
@@ -1997,11 +2098,11 @@ export function register(on) {
1997
2098
  await act.beat().catch(() => {});
1998
2099
  await act.stalls();
1999
2100
  await act.freeLanes().catch(() => {});
2000
- await act.animate();
2101
+ paneOpen = (await $.ui.panes()).some((p) => p.id === PANE_ID);
2001
2102
  const now = await act.fingerprint();
2002
- const paneOpen = (await $.ui.panes()).some((p) => [PANE_ID, TEAM_ID].includes(p.id));
2103
+ const anyPane = (await $.ui.panes()).some((p) => [PANE_ID, TEAM_ID].includes(p.id));
2003
2104
  quiet += 1;
2004
- if (now === seen && quiet < (paneOpen ? 5 : 30)) return;
2105
+ if (now === seen && quiet < (anyPane ? 5 : 30)) return;
2005
2106
  quiet = 0;
2006
2107
  await act.reload();
2007
2108
  // Taken again: what it covers (the plan) can change with what was read.
@@ -2042,7 +2143,9 @@ export function register(on) {
2042
2143
  const starting = (name) => ({
2043
2144
  text: `code-kit is still starting; try /${name} again in a moment.`,
2044
2145
  });
2045
- on('command.run', { command: 'lanes' }, async ($, e) => (act ? act.lanes() : starting('lanes')));
2146
+ on('command.run', { command: 'lanes' }, async ($, e) =>
2147
+ act ? act.lanes(e.args) : starting('lanes'),
2148
+ );
2046
2149
  on('command.run', { command: 'team' }, async ($, e) =>
2047
2150
  act ? act.team(null, { toggle: true }) : starting('team'),
2048
2151
  );
@@ -2129,7 +2232,7 @@ export function register(on) {
2129
2232
  if (touch && touchLane) {
2130
2233
  touches.push({ ...touch, lane: touchLane, at: calledAt });
2131
2234
  if (touches.length > TOUCHES_KEPT) touches.shift();
2132
- if (paneUi.tab === 'code') $.ui.invalidate('ui.render');
2235
+ if (paneUi.view === 'code') $.ui.invalidate('ui.render');
2133
2236
  }
2134
2237
  try {
2135
2238
  const res = await next(e);
@@ -2151,6 +2254,15 @@ export function register(on) {
2151
2254
  refusals.set(e.tool_use_id, text);
2152
2255
  if (refusals.size > REFUSALS_KEPT) refusals.delete(refusals.keys().next().value);
2153
2256
  }
2257
+ // UI-4: a refusal the lane hasn't resolved turns its story's map chip red, until the same file
2258
+ // is written; a write refused for its layer rules names the layer.
2259
+ const troubleLane = busy ? busy.lane : e.agentId ? null : 'lead';
2260
+ if (troubleLane && touch?.verb === 'edit') {
2261
+ const found = text ? troubleOf(text, touch.path) : [];
2262
+ const kept = (troubles.get(troubleLane) ?? []).filter((t) => t.path !== touch.path);
2263
+ troubles.set(troubleLane, [...kept, ...found]);
2264
+ $.ui.invalidate('ui.render');
2265
+ }
2154
2266
  const ask = text ? holdable(text) : null;
2155
2267
  const settings = model.check?.harness;
2156
2268
  const minutes = settings?.hold?.minutes ?? 2;
@@ -2192,6 +2304,14 @@ export function register(on) {
2192
2304
  }
2193
2305
  }
2194
2306
  }).catch(($, e, next) => next(e)); // whatever fails here, the call goes on as it would
2307
+ // UI-4: what a refused write leaves unresolved: each layer rule it would break, or the write itself.
2308
+ const troubleOf = (text, path) => {
2309
+ const layers = [
2310
+ ...String(text).matchAll(/^\s+(\S+) \(([^()]+)\) (?:imports|may not import)/gm),
2311
+ ];
2312
+ if (layers.length) return layers.map((m) => ({ layer: m[2], path: m[1] }));
2313
+ return refusalCard(text)?.kind === 'write' ? [{ layer: null, path }] : [];
2314
+ };
2195
2315
  // A refused call's text: kept from its tool.call, or the output its row carries (what the model read).
2196
2316
  const refusalOf = (id, output) =>
2197
2317
  refusalCard(refusals.get(id) ?? (typeof output === 'string' ? output : null));
@@ -2458,10 +2578,10 @@ export function register(on) {
2458
2578
  }),
2459
2579
  );
2460
2580
  };
2461
- // VIEW-2, VIEW-3: each lane's pose and tint, and its story's bar on the shared axis.
2581
+ // UI-4, UI-11, UI-12: each lane's pose and the move it's playing, its story's bar on the shared
2582
+ // axis (for swimlanes), the requirements newly tested, and the surfaces drawn still.
2462
2583
  const artNow = (now, live) => {
2463
2584
  const lanesNow = stateNow()?.kind === 'ok' ? stateNow().lanes : [];
2464
- const names = lanesNow.map((l) => l.name);
2465
2585
  const queue = model.queue ?? [];
2466
2586
  const asking = new Set([
2467
2587
  ...[...held.values()].map((c) => c.lane ?? 'lead'),
@@ -2472,23 +2592,34 @@ export function register(on) {
2472
2592
  lanesNow.some((l) => l.story?.id === t.id),
2473
2593
  );
2474
2594
  const start = axisStart(times, now);
2475
- const width = Math.max(10, Math.min(120, paneColumns - 14));
2595
+ // VIEW-2: the time axis, as wide as a card's text has room for.
2596
+ const width = Math.max(10, Math.min(40, paneColumns - 40));
2476
2597
  const poses = {};
2477
- const tints = {};
2478
2598
  const bars = {};
2599
+ const playing = {};
2600
+ for (const [lane, m] of moves) if (now - m.at < MOVE_MS) playing[lane] = m;
2479
2601
  for (const l of lanesNow) {
2480
- poses[l.name] = poseOf(l, {
2602
+ poses[l.name] = poseFor(l, {
2481
2603
  live: live[l.name],
2482
2604
  waiting: asking.has(l.name),
2483
- flagged: stalled.has(l.name),
2484
- shown: shownState(l, queue),
2605
+ stalled: stalled.has(l.name),
2606
+ queue,
2485
2607
  });
2486
- tints[l.name] = tintOf(l.name, names);
2487
2608
  const t = times.find((x) => x.id === l.story?.id);
2488
2609
  if (t) bars[l.name] = barCells(t, { start, now, width });
2489
2610
  }
2490
- return { surface: paneSurface, frame, poses, tints, bars, svgWidth: width * 6 };
2611
+ return {
2612
+ surface: paneSurface,
2613
+ motion: harness().motion,
2614
+ poses,
2615
+ moves: playing,
2616
+ bars,
2617
+ faulted,
2618
+ fresh: [...freshTested].filter(([, at]) => now - at < MOVE_MS).map(([id]) => id),
2619
+ };
2491
2620
  };
2621
+ /** The lane selected in the pane, if a lane is. */
2622
+ const selectedLaneName = () => (paneUi.sel?.kind === 'lane' ? paneUi.sel.id : null);
2492
2623
  const liveNow = (now) => {
2493
2624
  const stall = harness().stall;
2494
2625
  const live = {};
@@ -2585,151 +2716,305 @@ export function register(on) {
2585
2716
  return card ? { ...l, context: contextOf(card) } : l;
2586
2717
  });
2587
2718
  };
2719
+ // UI-3, UI-8: most urgent first, every action numbered in that order, wherever they're shown.
2588
2720
  const linesNowRaw = (now) =>
2589
- bandLines({
2590
- ...model,
2591
- reviewing,
2592
- notice,
2593
- ...usageNow(),
2594
- held: [...held.values()],
2595
- now,
2596
- loop: loopNow(now),
2597
- leadBusy: Boolean(leadTurn),
2598
- live: liveNow(now),
2599
- nextStep: loop.nextStep,
2600
- combined: combinedNow(),
2601
- team: model.team ?? null,
2602
- });
2721
+ needsOf(
2722
+ bandLines({
2723
+ ...model,
2724
+ reviewing,
2725
+ notice,
2726
+ ...usageNow(),
2727
+ held: [...held.values()],
2728
+ now,
2729
+ loop: loopNow(now),
2730
+ leadBusy: Boolean(leadTurn),
2731
+ live: liveNow(now),
2732
+ nextStep: loop.nextStep,
2733
+ combined: combinedNow(),
2734
+ team: model.team ?? null,
2735
+ }),
2736
+ );
2603
2737
 
2604
2738
  on('ui.render', { component: 'Pane', requestId: PANE_ID }, async ($, e) => {
2605
2739
  const now = await $.clock.now();
2606
2740
  paneSurface = e.surface;
2607
2741
  paneColumns = e.props.bodyColumns ?? paneColumns;
2742
+ paneRows = e.props.scroll?.bodyRows ?? paneRows;
2743
+ paneOpen = true;
2744
+ const els = $.ui.resolve(e);
2608
2745
  const { usage, plan } = usageNow();
2609
- const lanesNow = stateNow()?.kind === 'ok' ? stateNow().lanes : [];
2610
- return lanesFrame(
2611
- {
2612
- state: stateNow(),
2746
+ const state = stateNow();
2747
+ const live = liveNow(now);
2748
+ const needs = needsOf(linesNow(now));
2749
+ const loopView = { ...loopNow(now), queue: model.queue ?? [] };
2750
+ const lanesNow = state?.kind === 'ok' ? state.lanes : [];
2751
+ const back = () => {
2752
+ if (paneUi.view === 'story') return act?.closeStory();
2753
+ paneUi = { ...paneUi, view: null };
2754
+ $.ui.invalidate('ui.render');
2755
+ };
2756
+ const looks = charactersOf(lanesNow.map((l) => l.name));
2757
+ const tints = Object.fromEntries(Object.entries(looks).map(([n, c]) => [n, c.tint]));
2758
+ // UI-6: the full views, over the panels; Escape (or Back) returns.
2759
+ if (paneUi.view === 'story' && storyOpen)
2760
+ return viewFrame(
2761
+ `${storyOpen.id}`,
2762
+ storyPane({ ...storyNow(storyOpen, now, usage), columns: paneColumns }, els, {
2763
+ onBack: back,
2764
+ onFile: (file) => {
2765
+ paneUi = { ...paneUi, file };
2766
+ $.ui.invalidate('ui.render');
2767
+ },
2768
+ // JOIN-4: a file in the adapter's own view, through the command it names.
2769
+ onOpenIn: (adapter, path) =>
2770
+ $.command.run({ command: adapter.open.command, args: path }).catch((err) => {
2771
+ notice = `Couldn't open ${path} in ${adapter.name}: ${err?.message ?? err}`;
2772
+ $.ui.invalidate('ui.render');
2773
+ }),
2774
+ onAct: (id) => {
2775
+ const lane = lanesNow.find((l) => l.name === storyOpen?.lane);
2776
+ if (lane) act?.laneAct(id, lane);
2777
+ },
2778
+ }),
2779
+ els,
2780
+ { onBack: back },
2781
+ [{ key: 'esc', label: 'back' }],
2782
+ { head: false },
2783
+ );
2784
+ if (paneUi.view === 'trail')
2785
+ return viewFrame(
2786
+ 'Trail',
2787
+ mapTab(
2788
+ model.status ?? null,
2789
+ paneUi.cell,
2790
+ els,
2791
+ {
2792
+ onCell: (cell) => {
2793
+ paneUi = { ...paneUi, cell };
2794
+ $.ui.invalidate('ui.render');
2795
+ },
2796
+ },
2797
+ trailData,
2798
+ { surface: paneSurface, columns: paneColumns },
2799
+ ),
2800
+ els,
2801
+ { onBack: back },
2802
+ [
2803
+ { key: '←→', label: 'requirement' },
2804
+ { key: 'esc', label: 'back' },
2805
+ ],
2806
+ );
2807
+ if (paneUi.view === 'code')
2808
+ return viewFrame(
2809
+ 'Code map',
2810
+ codeTab(
2811
+ {
2812
+ state,
2813
+ ui: {
2814
+ selected: selectedLaneName(),
2815
+ mapStory: paneUi.mapStory,
2816
+ mapFile: paneUi.mapFile,
2817
+ },
2818
+ codeMap,
2819
+ art: { tints },
2820
+ glow: glowOf(touches, now),
2821
+ surface: paneSurface,
2822
+ columns: paneColumns,
2823
+ },
2824
+ els,
2825
+ {
2826
+ onMapStory: (id) => {
2827
+ paneUi = { ...paneUi, mapStory: id, mapFile: null };
2828
+ $.ui.invalidate('ui.render');
2829
+ act?.readMaps().then(() => $.ui.invalidate('ui.render'));
2830
+ },
2831
+ onMapFile: (path) => {
2832
+ paneUi = { ...paneUi, mapFile: path };
2833
+ $.ui.invalidate('ui.render');
2834
+ },
2835
+ // MAP-3: the file in Context Graph's own view, through the command its adapter names.
2836
+ onOpenFile: (path) => {
2837
+ const command = codeMap?.open?.command;
2838
+ if (!command) return;
2839
+ $.command.run({ command, args: path }).catch((err) => {
2840
+ notice = `Couldn't open ${path}: ${err?.message ?? err}`;
2841
+ $.ui.invalidate('ui.render');
2842
+ });
2843
+ },
2844
+ },
2845
+ ),
2846
+ els,
2847
+ { onBack: back },
2848
+ );
2849
+ if (paneUi.view === 'journal') {
2850
+ const events = journalNow();
2851
+ return viewFrame(
2852
+ 'Journal',
2853
+ events.length
2854
+ ? journalTab(events, els, now)
2855
+ : [
2856
+ els.Text({
2857
+ dimColor: true,
2858
+ children: ['Nothing recorded yet: the journal starts with the brief.'],
2859
+ }),
2860
+ ],
2861
+ els,
2862
+ { onBack: back },
2863
+ );
2864
+ }
2865
+ if (paneUi.view === 'usage') {
2866
+ const body = usageSection(
2613
2867
  usage,
2614
2868
  plan,
2615
- loop: { ...loopNow(now), queue: model.queue ?? [] },
2616
- needs: linesNow(now).filter((l) => !l.mission),
2617
- cards: cardsNow(now),
2618
- journal: journalNow(),
2619
- now,
2620
- live: liveNow(now),
2869
+ (v, st = {}) => els.Text({ ...st, children: [v] }),
2870
+ els.Box,
2871
+ );
2872
+ return viewFrame(
2873
+ 'Usage',
2874
+ body.length
2875
+ ? body
2876
+ : [els.Text({ dimColor: true, children: ['No usage measured yet this session.'] })],
2877
+ els,
2878
+ { onBack: back },
2879
+ );
2880
+ }
2881
+ if (paneUi.view === 'decision') {
2882
+ const cards = cardsNow(now);
2883
+ if (cards.length)
2884
+ return viewFrame(
2885
+ 'Decision',
2886
+ decisionsTab(cards, paneUi, els, {
2887
+ onDecision: (i) => {
2888
+ paneUi = { ...paneUi, decision: i };
2889
+ $.ui.invalidate('ui.render');
2890
+ },
2891
+ onNeed: (id, line) => act?.[id]?.(line),
2892
+ }),
2893
+ els,
2894
+ { onBack: back },
2895
+ [
2896
+ { key: 'j/k', label: 'decision' },
2897
+ { key: 'esc', label: 'back' },
2898
+ ],
2899
+ );
2900
+ paneUi = { ...paneUi, view: null };
2901
+ }
2902
+ if (paneUi.view === 'characters')
2903
+ return viewFrame(
2904
+ 'Characters',
2905
+ sheetView(
2906
+ lanesNow.map((l) => l.name),
2907
+ els,
2908
+ { surface: faulted[paneSurface] ? 'still' : paneSurface, motion: harness().motion },
2909
+ ),
2910
+ els,
2911
+ { onBack: back },
2912
+ );
2913
+ const order = () => {
2914
+ const { atWork, resting } = lanesAtWork(state, model.queue ?? [], {
2915
+ ...(loopView.laneNotes ?? {}),
2916
+ ...artNow(now, live).moves,
2917
+ });
2918
+ return selectable(needs, [...atWork, ...resting]);
2919
+ };
2920
+ return board(
2921
+ {
2922
+ state,
2923
+ status: model.status ?? null,
2924
+ loop: loopView,
2925
+ needs,
2926
+ live,
2621
2927
  held: [...held.values()],
2622
2928
  requests: model.requests?.open ?? [],
2623
- ui: paneUi,
2624
- status: model.status ?? null,
2625
- // VIEW-6: what each lane owns, for the selected lane's detail.
2929
+ leadBusy: Boolean(leadTurn),
2930
+ journal: journalNow(),
2931
+ maps: storyMaps,
2932
+ combined: combinedNow(),
2933
+ usage,
2934
+ // LANES-3: what each lane owns, for the selected lane's detail.
2626
2935
  paths: {
2627
2936
  lead: model.check?.lead?.paths ?? [],
2628
2937
  ...Object.fromEntries(
2629
2938
  Object.entries(model.check?.lanes ?? {}).map(([n, l]) => [n, l.paths ?? []]),
2630
2939
  ),
2631
2940
  },
2632
- art: artNow(now, liveNow(now)),
2633
- combined: combinedNow(),
2634
- codeMap,
2635
- trail: trailData,
2636
- glow: glowOf(touches, now),
2637
- surface: paneSurface,
2638
- columns: paneColumns,
2941
+ trouble: Object.fromEntries(
2942
+ lanesNow.map((l) => {
2943
+ const f = (model.adapters ?? []).some((a) => a.lanes) ? factsOf(l) : null;
2944
+ return [l.name, { refused: troubles.get(l.name) ?? [], owed: f?.cardsOwed ?? [] }];
2945
+ }),
2946
+ ),
2947
+ art: artNow(now, live),
2948
+ now,
2949
+ ui: paneUi,
2639
2950
  placement: e.props.placement,
2640
- story: storyOpen ? storyNow(storyOpen, now, usage) : null,
2951
+ columns: paneColumns,
2952
+ rows: paneRows,
2641
2953
  },
2642
- $.ui.resolve(e),
2954
+ els,
2643
2955
  {
2644
- onTab: (tab) => {
2645
- paneUi = { ...paneUi, tab };
2646
- $.ui.invalidate('ui.render');
2647
- act?.readMaps().then(() => $.ui.invalidate('ui.render'));
2648
- },
2649
- onDecision: (i) => {
2650
- paneUi = { ...paneUi, decision: i };
2651
- $.ui.invalidate('ui.render');
2652
- },
2653
- onMapStory: (id) => {
2654
- paneUi = { ...paneUi, mapStory: id, mapFile: null };
2655
- $.ui.invalidate('ui.render');
2656
- act?.readMaps().then(() => $.ui.invalidate('ui.render'));
2657
- },
2658
- onMapFile: (path) => {
2659
- paneUi = { ...paneUi, mapFile: path };
2660
- $.ui.invalidate('ui.render');
2661
- },
2662
- // MAP-3: the file in Context Graph's own view, through the command its adapter names.
2663
- onOpenFile: (path) => {
2664
- const command = codeMap?.open?.command;
2665
- if (!command) return;
2666
- $.command.run({ command, args: path }).catch((err) => {
2667
- notice = `Couldn't open ${path}: ${err?.message ?? err}`;
2668
- $.ui.invalidate('ui.render');
2669
- });
2670
- },
2671
- onFilter: (state) => {
2672
- paneUi = { ...paneUi, filter: paneUi.filter === state ? null : state };
2956
+ onNeed: (id, line) => act?.[id]?.(line),
2957
+ onDecide: (i, line) => act?.decide(line),
2958
+ onSelect: (sel) => {
2959
+ paneUi = { ...paneUi, sel, ...(sel.kind === 'need' ? { need: Number(sel.id) } : {}) };
2673
2960
  $.ui.invalidate('ui.render');
2674
2961
  },
2675
2962
  onMove: (step) => {
2676
- if (!lanesNow.length) return;
2677
- const at = lanesNow.findIndex((l) => l.name === paneUi.selected);
2678
- const to =
2679
- at < 0
2680
- ? step > 0
2681
- ? 0
2682
- : lanesNow.length - 1
2683
- : (at + step + lanesNow.length) % lanesNow.length;
2684
- paneUi = { ...paneUi, selected: lanesNow[to].name };
2963
+ const sel = moveSelection(order(), paneUi.sel, step);
2964
+ if (!sel) return;
2965
+ paneUi = { ...paneUi, sel, ...(sel.kind === 'need' ? { need: Number(sel.id) } : {}) };
2685
2966
  $.ui.invalidate('ui.render');
2686
- // VIEW-6: Enter opens the selected lane's story: the focus waits on its Open button.
2687
- if (
2688
- lanesNow[to].story ||
2689
- (model.state?.stories ?? []).some((s) => s.lane === lanesNow[to].name)
2690
- )
2691
- $.ui.focus({ requestId: PANE_ID, key: 'open-story' }).catch(() => {});
2967
+ // UI-8: Enter opens what's selected: the focus waits on its button.
2968
+ $.ui
2969
+ .focus({ requestId: PANE_ID, key: sel.kind === 'need' ? 'need-why' : 'open-story' })
2970
+ .catch(() => {});
2692
2971
  },
2693
2972
  onOpen: (lane) => act?.openStory(lane),
2694
- // TRACE-2: a cell selected by its keys or the requirement list.
2695
- onCell: (cell) => {
2696
- paneUi = { ...paneUi, cell };
2973
+ onView: (view, at = null) => {
2974
+ const reqs = at?.story?.requirements ?? [];
2975
+ paneUi = {
2976
+ ...paneUi,
2977
+ view,
2978
+ ...(view === 'trail' && reqs.length ? { cell: reqs[0] } : {}),
2979
+ ...(view === 'code' && at?.story ? { mapStory: at.story.id, mapFile: null } : {}),
2980
+ };
2697
2981
  $.ui.invalidate('ui.render');
2982
+ act?.readMaps().then(() => $.ui.invalidate('ui.render'));
2698
2983
  },
2699
- story: {
2700
- onBack: () => act?.closeStory(),
2701
- onFile: (file) => {
2702
- paneUi = { ...paneUi, file };
2703
- $.ui.invalidate('ui.render');
2704
- },
2705
- // JOIN-4: a file in the adapter's own view, through the command it names.
2706
- onOpenIn: (adapter, path) =>
2707
- $.command.run({ command: adapter.open.command, args: path }).catch((err) => {
2708
- notice = `Couldn't open ${path} in ${adapter.name}: ${err?.message ?? err}`;
2709
- $.ui.invalidate('ui.render');
2710
- }),
2711
- onAct: (id) => {
2712
- const lane = lanesNow.find((l) => l.name === storyOpen?.lane);
2713
- if (lane) act?.laneAct(id, lane);
2714
- },
2715
- },
2716
- onNeed: (id, line) => act?.[id]?.(line),
2717
2984
  onLane: (id, lane) => act?.laneAct(id, lane),
2718
2985
  onSearch: (search) => {
2719
- paneUi = { ...paneUi, search };
2986
+ paneUi = { ...paneUi, search, filtering: Boolean(search) || paneUi.filtering };
2987
+ $.ui.invalidate('ui.render');
2988
+ },
2989
+ onFocusSearch: () => {
2990
+ paneUi = { ...paneUi, filtering: true };
2720
2991
  $.ui.invalidate('ui.render');
2992
+ $.ui.focus({ requestId: PANE_ID, key: 'filter' }).catch(() => {});
2721
2993
  },
2722
- onFocusSearch: () => $.ui.focus({ requestId: PANE_ID, key: 'filter' }).catch(() => {}),
2723
2994
  },
2724
2995
  );
2725
2996
  });
2726
2997
 
2727
- // VIEW-6: Escape on a story goes back to the lanes; on the lanes, it closes the pane.
2998
+ // UI-6: Escape on a full view goes back to the panels; on the panels, it closes the pane.
2728
2999
  on('ui.close', async ($, e, next) => {
2729
- if (closeGoesBack(e, PANE_ID, paneUi)) {
2730
- act?.closeStory();
3000
+ if (escapeGoesBack(e, PANE_ID, paneUi)) {
3001
+ if (paneUi.view === 'story') act?.closeStory();
3002
+ else {
3003
+ paneUi = { ...paneUi, view: null };
3004
+ $.ui.invalidate('ui.render');
3005
+ }
2731
3006
  return;
2732
3007
  }
3008
+ if (e.id === PANE_ID) paneOpen = false;
3009
+ return next(e);
3010
+ });
3011
+
3012
+ // UI-12: a surface module that fails draws everything still on that surface from then on.
3013
+ on('ui.fault', async ($, e, next) => {
3014
+ if (String(e.module ?? '').includes('surface/')) {
3015
+ faulted[e.surface] = true;
3016
+ $.ui.invalidate('ui.render');
3017
+ }
2733
3018
  return next(e);
2734
3019
  });
2735
3020
 
@@ -2744,12 +3029,25 @@ export function register(on) {
2744
3029
  }),
2745
3030
  );
2746
3031
 
2747
- // BAND-2: absent when nothing waits. Its lines go above whatever else the band holds (another
2748
- // plugin's lines, such as Context Graph's, or Claude Code's own), which it keeps.
3032
+ // UI-9: the band speaks only when it's needed: what needs the person, else one line while the
3033
+ // build moves, else nothing. Its lines go above whatever else the band holds (another plugin's, such
3034
+ // as Context Graph's, or Claude Code's own), which it keeps.
2749
3035
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
2750
- const lines = linesNow(await $.clock.now());
2751
- if (!lines.length || !act) return next(e);
2752
- const ours = band(lines, $.ui.resolve(e), (id, line) => act[id](line));
3036
+ if (!act) return next(e);
3037
+ const now = await $.clock.now();
3038
+ const ours = bandOf(
3039
+ {
3040
+ state: stateNow(),
3041
+ status: model.status ?? null,
3042
+ loop: { ...loopNow(now), queue: model.queue ?? [] },
3043
+ needs: needsOf(linesNow(now)),
3044
+ leadBusy: Boolean(leadTurn),
3045
+ columns: e.props.bodyColumns,
3046
+ },
3047
+ $.ui.resolve(e),
3048
+ (id, line) => act[id](line),
3049
+ );
3050
+ if (!ours) return next(e);
2753
3051
  const below = await next(e);
2754
3052
  return below ? $.ui.resolve(e).Box({ flexDirection: 'column', children: [ours, below] }) : ours;
2755
3053
  });