@litfamily/litclaude 1.0.41 โ†’ 1.0.42

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.
@@ -124,8 +124,12 @@ const topRow = (model, accent, animate, rewind = false) => {
124
124
  ? pill(pad, y, "๐Ÿ”ฅ LIT", { fill: "url(#lit-rainbow)", ink: C.ink, veil: true })
125
125
  : pill(pad, y, "๐Ÿ”ฅ LIT", { fill: C.pink, ink: C.ink, breath: animate.breath ? C.orange : null });
126
126
  const indicator = rewind && !model.completion ? { label: "REWIND <<", fill: "url(#lit-rainbow)" } : indicatorOf(model, accent);
127
- const right = text(width - pad, y, indicator.label, { fill: indicator.fill, bold: !indicator.plain, anchor: "end" });
128
- const room = width - pad - widthOf(indicator.label) - 16 - brand.end - widthOf(" ยท ");
127
+ // A newer LitClaude installed than the one loaded: `restart to <version>` left of the indicator.
128
+ const chip = model.restart ? `restart to ${model.restart}` : null;
129
+ const chipEnd = width - pad - widthOf(indicator.label) - 16;
130
+ const right = text(width - pad, y, indicator.label, { fill: indicator.fill, bold: !indicator.plain, anchor: "end" })
131
+ + (chip ? text(chipEnd, y, chip, { fill: C.amber, anchor: "end" }) : "");
132
+ const room = width - pad - widthOf(indicator.label) - 16 - (chip ? widthOf(chip) + 16 : 0) - brand.end - widthOf(" ยท ");
129
133
  const name = truncateToWidth(model.title ?? "ready", Math.max(4, Math.floor(room / SVG_CARD.cell)));
130
134
  const title = run(brand.end + 4, y, [[" ยท ", { fill: C.dim }], [name, model.idle && !rewind ? { fill: C.dim } : { fill: accent, bold: true }]]);
131
135
  return brand.markup + title.markup + right;
@@ -423,7 +427,7 @@ const pulseSvg = (x, y, animate, fill) => {
423
427
  */
424
428
  const threadRowsSvg = (model, { animate = false, rewind = false } = {}) => {
425
429
  const { width, pad } = SVG_CARD;
426
- const { chain, lanes, others, laneCount = 0, taskCount = 0, more } = model.threads;
430
+ const { chain, lanes, herdrLanes = [], others, laneCount = 0, taskCount = 0, more } = model.threads;
427
431
  const lines = [];
428
432
  chain.forEach((thread, index) => lines.push({ thread, lead: index === 0 ? "" : `${" ".repeat(index - 1)}โ””โ”€ ` }));
429
433
  const under = " ".repeat(Math.max(0, chain.length - 1));
@@ -434,6 +438,7 @@ const threadRowsSvg = (model, { animate = false, rewind = false } = {}) => {
434
438
  } else {
435
439
  lanes.forEach((thread) => lines.push({ thread, lead: chain.length ? `${under}โ””โ”€ ` : "" }));
436
440
  }
441
+ herdrLanes.forEach((thread) => lines.push({ thread, lead: "" }));
437
442
  others.forEach((thread) => lines.push({ thread, lead: "" }));
438
443
  const threads = lines.filter(({ thread }) => thread).map(({ thread }) => thread);
439
444
  const nameCells = Math.min(28, Math.max(...threads.map(({ name }) => textWidth(name))));
@@ -518,7 +523,7 @@ export const svgCardAlt = (model) => {
518
523
  parts.push(`phase ${LABELS[current]}`);
519
524
  }
520
525
  if (model.step) parts.push(`running ${model.step.name}`);
521
- const threads = model.threads ? [...model.threads.chain, ...model.threads.lanes, ...model.threads.others] : [];
526
+ const threads = model.threads ? [...model.threads.chain, ...model.threads.lanes, ...(model.threads.herdrLanes ?? []), ...model.threads.others] : [];
522
527
  if (threads.length) parts.push(`threads ${threads.map((thread) => `${thread.name} ${gauge(thread.done, thread.total) ? `${gauge(thread.done, thread.total)} ${thread.state}` : threadFacts(thread)}`).join(", ")}${model.threads.more ? `, ${model.threads.more} more` : ""}`);
523
528
  if (model.skills.length) parts.push(`skills ${model.skills.map(({ id }) => id).join(", ")}`);
524
529
  const { context, rates } = model.figures;
@@ -103,6 +103,9 @@ const PARALLEL_ROWS = 3;
103
103
  // Another session of this project counts as live while its stack was written this recently and
104
104
  // SessionEnd has not marked it ended.
105
105
  export const OTHER_SESSION_MS = 15 * 60 * 1000;
106
+ // A finished start-work (or any thread marked done) keeps its check mark this long after it
107
+ // finished, then leaves the card.
108
+ export const DONE_LINGER_MS = 60_000;
106
109
 
107
110
  const countOrNull = (value) => (Number.isInteger(value) && value >= 0 ? value : null);
108
111
 
@@ -241,22 +244,59 @@ const frameCount = (frame, snapshot, mainList) => {
241
244
 
242
245
  // A thread with no total carries what is known instead: its finished steps, how long it has run
243
246
  // and its last step (knownFacts in rewind/gauge.mjs words them).
247
+ // A frame is finished when its record says so, or when it is a start-work, not paused, whose plan has
248
+ // every row checked; a paused one at k/k still waits (for a review to hand back, say). `doneAt` is
249
+ // when: the plan file's last change, else the record's or the frame's time.
244
250
  const frameThread = (frame, index, snapshot, active, mainList = null, now = null, mainEntry = null) => {
245
251
  const { done, total } = frameCount(frame, snapshot, active ? mainList : null);
246
252
  const started = Number.isFinite(frame.at) ? frame.at : frame.record?.at;
253
+ const finished = Boolean(frame.record?.done) || (frame.skill === "start-work" && frame.status !== "paused" && total > 0 && done === total);
254
+ const doneAt = [frame.planAt, frame.record?.at, started].find(Number.isFinite) ?? null;
247
255
  return {
248
256
  key: `frame-${index}`,
249
257
  name: frame.skill ?? frame.record?.family ?? "work",
250
258
  stage: frame.record?.step ?? frame.record?.stage ?? null,
251
259
  done,
252
260
  total,
253
- state: frame.record?.done ? "done" : frame.status === "paused" ? "paused" : frame.skill === "start-work" && snapshot.work?.status === "paused" ? "blocked" : "running",
261
+ state: finished ? "done" : frame.status === "paused" ? "paused" : frame.skill === "start-work" && snapshot.work?.status === "paused" ? "blocked" : "running",
262
+ doneAt: finished ? doneAt : null,
254
263
  active,
255
264
  steps: active && mainEntry ? mainEntry.steps : null,
256
265
  last: active && mainEntry ? mainEntry.last ?? null : null,
257
266
  elapsedMs: Number.isFinite(now) && Number.isFinite(started) ? Math.max(0, now - started) : null,
258
267
  };
259
268
  };
269
+ const lingering = (thread, now) => thread.state !== "done" || !Number.isFinite(thread.doneAt) || now - thread.doneAt <= DONE_LINGER_MS;
270
+
271
+ // Another session's row: its liveness record says running (`alive`), `idle` or `ended` (hidden);
272
+ // without one, a stack written within OTHER_SESSION_MS and not marked ended counts as running.
273
+ // A stack that moved after the record (a resumed session's first tool call) outranks it.
274
+ const otherState = (thread, liveness) => (liveness?.state === "idle" && thread.state === "running" ? "idle" : thread.state);
275
+ const currentLiveness = (liveness, stackAt) => (liveness && !(Number.isFinite(stackAt) && stackAt > liveness.at) ? liveness : null);
276
+ const seenAt = (other) => Math.max(Number.isFinite(other.at) ? other.at : -Infinity, Number.isFinite(other.liveness?.at) ? other.liveness.at : -Infinity);
277
+ // Running first, then idle, then the rest (paused, done), each newest first.
278
+ const STATE_ORDER = { running: 0, idle: 1 };
279
+ const runningFirst = (a, b) => (STATE_ORDER[a.state] ?? 2) - (STATE_ORDER[b.state] ?? 2) || b.seenAt - a.seenAt;
280
+
281
+ // herdr lanes of this project: sessions whose hooks ran in a herdr pane (their liveness record keeps
282
+ // the pane id), drawn as lanes named `<top skill or claude> ยท <pane>`. This session, and any session
283
+ // in this session's own pane, are never listed.
284
+ const herdrLanesOf = (snapshot, others, now) => {
285
+ const liveness = snapshot.workflow?.liveness ?? {};
286
+ const self = snapshot.workflow?.sessionId ?? null;
287
+ const ownPane = self ? liveness[self]?.herdrPane ?? null : null;
288
+ return Object.entries(liveness)
289
+ .filter(([id, entry]) => id !== self && entry.herdrPane && entry.herdrPane !== ownPane)
290
+ .map(([id, entry]) => {
291
+ const other = others.find((candidate) => candidate.sessionId === id);
292
+ const live = currentLiveness(entry, other?.at);
293
+ if (live?.state === "ended" || (!live && other?.ended) || now - Math.max(entry.at, other?.at ?? -Infinity) > OTHER_SESSION_MS) return null;
294
+ const top = other?.frames?.length ? frameThread(other.frames.at(-1), 0, {}, false, null, now) : { name: "claude", stage: null, done: null, total: null, state: "running", doneAt: null, active: false, elapsedMs: null };
295
+ return { ...top, key: `herdr-${entry.herdrPane}`, sessionId: id, name: `${top.name} ยท ${entry.herdrPane}`, state: otherState(top, live), seenAt: Math.max(entry.at, other?.at ?? -Infinity) };
296
+ })
297
+ .filter((thread) => thread && lingering(thread, now))
298
+ .sort(runningFirst);
299
+ };
260
300
 
261
301
  // A lane's k/n: its own todo or task list, then the tasks a loop gave it by name; else no total,
262
302
  // with the steps it has finished and its last one.
@@ -274,7 +314,8 @@ const laneCount = (entry, lists, name) => listProgress(entry) ?? ownedProgress(l
274
314
  const threadsOf = ({ snapshot, lanes, tasks, lists, now, threadReserve }) => {
275
315
  const frames = snapshot.workflow?.stack?.frames ?? [];
276
316
  const mainList = listProgress(lists.main);
277
- const chain = frames.map((frame, index) => frameThread(frame, index, snapshot, index === frames.length - 1, mainList, now, lists.main));
317
+ const chain = frames.map((frame, index) => frameThread(frame, index, snapshot, index === frames.length - 1, mainList, now, lists.main))
318
+ .filter((thread) => lingering(thread, now));
278
319
  const laneThreads = lanes.map((lane, index) => ({
279
320
  key: `lane-${lane.id ?? index}`,
280
321
  name: lane.name,
@@ -286,23 +327,36 @@ const threadsOf = ({ snapshot, lanes, tasks, lists, now, threadReserve }) => {
286
327
  }));
287
328
  const taskThreads = tasks.map((task) => ({ key: `task-${task.id}`, name: task.name, stage: task.kind, done: null, total: null, state: "running", active: false, task: task.kind, elapsedMs: Number.isFinite(task.at) ? Math.max(0, now - task.at) : null }));
288
329
  const parallel = [...laneThreads, ...taskThreads];
330
+ const herdrLanes = herdrLanesOf(snapshot, snapshot.workflow?.others ?? [], now);
331
+ const inHerdr = new Set(herdrLanes.map(({ sessionId }) => sessionId));
289
332
  const others = (snapshot.workflow?.others ?? [])
290
- .filter((other) => !other.ended && Number.isFinite(other.at) && now - other.at <= OTHER_SESSION_MS && other.frames?.length)
291
- .map((other) => ({ ...frameThread(other.frames.at(-1), 0, {}, false, null, now), key: `session-${other.id8}`, session: other.id8 }));
292
- const total = chain.length + parallel.length + others.length;
293
- if (total < 2) return null;
333
+ .filter((other) => {
334
+ const live = currentLiveness(other.liveness, other.at);
335
+ return (live ? live.state !== "ended" : !other.ended) && !inHerdr.has(other.sessionId) && now - seenAt(other) <= OTHER_SESSION_MS && other.frames?.length;
336
+ })
337
+ .map((other) => {
338
+ const thread = frameThread(other.frames.at(-1), 0, {}, false, null, now);
339
+ return { ...thread, key: `session-${other.id8}`, session: other.id8, state: otherState(thread, currentLiveness(other.liveness, other.at)), seenAt: seenAt(other) };
340
+ })
341
+ .filter((thread) => lingering(thread, now))
342
+ .sort(runningFirst);
343
+ const total = chain.length + parallel.length + herdrLanes.length + others.length;
344
+ // A lone own thread keeps the plain card; a herdr lane or another session always gets its row.
345
+ if (total < 2 && herdrLanes.length + others.length === 0) return null;
294
346
  const room = Math.max(PARALLEL_ROWS, THREAD_ROWS - chain.length);
295
347
  const keptLanes = parallel.slice(0, room);
296
- const keptOthers = others.slice(0, Math.max(0, room - keptLanes.length));
348
+ const keptHerdr = herdrLanes.slice(0, Math.max(0, room - keptLanes.length));
349
+ const keptOthers = others.slice(0, Math.max(0, room - keptLanes.length - keptHerdr.length));
297
350
  const fork = parallel.length >= 2 ? 1 : 0;
298
- const needed = chain.length + keptLanes.length + keptOthers.length + fork;
351
+ const needed = chain.length + keptLanes.length + keptHerdr.length + keptOthers.length + fork;
299
352
  return {
300
353
  chain,
301
354
  lanes: keptLanes,
355
+ herdrLanes: keptHerdr,
302
356
  others: keptOthers,
303
357
  laneCount: laneThreads.length,
304
358
  taskCount: taskThreads.length,
305
- more: total - chain.length - keptLanes.length - keptOthers.length,
359
+ more: total - chain.length - keptLanes.length - keptHerdr.length - keptOthers.length,
306
360
  reserve: Math.max(needed, Number.isInteger(threadReserve) ? threadReserve : 0),
307
361
  };
308
362
  };
@@ -394,7 +448,19 @@ export const stepName = (tool) => {
394
448
  * (noteBackgroundTask). `turnStartedAt` is when the main loop's current turn began, `waiting`
395
449
  * what the session waits on the user for (`{ reason }`, null while it does not).
396
450
  */
397
- export const buildBandModel = ({ snapshot, agents = [], activity = EMPTY_ACTIVITY, usage = null, now, band = "always", isWorking = false, notice = null, completion = null, skills = [], lastDiscipline = null, git = null, step = null, threadReserve = 0, lists = EMPTY_LISTS, tasks = EMPTY_TASKS, turnStartedAt = null, waiting = null }) => {
451
+ const versionParts = (version) => {
452
+ const match = typeof version === "string" ? /^(\d+)\.(\d+)\.(\d+)/u.exec(version) : null;
453
+ return match ? match.slice(1, 4).map(Number) : null;
454
+ };
455
+ /** The installed version when it is newer than the loaded one by `major.minor.patch`, else null. */
456
+ export const restartVersion = ({ loaded = null, installed = null } = {}) => {
457
+ const [have, want] = [versionParts(loaded), versionParts(installed)];
458
+ if (!have || !want) return null;
459
+ const order = want.map((part, i) => part - have[i]).find((diff) => diff !== 0) ?? 0;
460
+ return order > 0 ? installed.slice(0, 40) : null;
461
+ };
462
+
463
+ export const buildBandModel = ({ snapshot, agents = [], activity = EMPTY_ACTIVITY, usage = null, now, band = "always", isWorking = false, notice = null, completion = null, skills = [], lastDiscipline = null, git = null, step = null, threadReserve = 0, lists = EMPTY_LISTS, tasks = EMPTY_TASKS, turnStartedAt = null, waiting = null, versions = null }) => {
398
464
  const discipline = snapshot.ignition?.discipline ?? null;
399
465
  const progress = progressOf(snapshot);
400
466
  const completing = completion !== null;
@@ -430,6 +496,7 @@ export const buildBandModel = ({ snapshot, agents = [], activity = EMPTY_ACTIVIT
430
496
  return {
431
497
  visible,
432
498
  idle: !active && !lit,
499
+ restart: restartVersion(versions ?? undefined),
433
500
  look,
434
501
  rewind,
435
502
  waiting: waiting?.reason ?? null,
@@ -0,0 +1,76 @@
1
+ // Outside folders a plan's todos name must be granted before the work starts, so a lane never stops
2
+ // to ask the user for them. start-work reads `Scope roots:` lines with SCOPE_LINE; lit-plan's checks
3
+ // use uncoveredScopePaths to name each todo path no such line covers, with the line to paste.
4
+ import { realpathSync, statSync } from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
7
+
8
+ import { planLinesOutsideFences } from "./plan-task-rows.mjs";
9
+
10
+ // `Scope roots: <path> (<action>, <action>)` lines in the plan widen the grants it starts with.
11
+ // Global, for `matchAll` only: `.test()` or `.exec()` on this shared object would carry `lastIndex`.
12
+ export const SCOPE_LINE = /^Scope roots?:[ \t]*(\S+)[ \t]*\(([a-z, -]+)\)[ \t]*$/gmu;
13
+
14
+ // An absolute path of two or more segments. A command quoted in an inline code span (it holds a
15
+ // space) is data, not a folder the work reaches, so only spans that are one path count.
16
+ const PATH_TOKEN = /(?<![\w.~\/-])\/[\w.@+%,=~-]+(?:\/[\w.@+%,=~-]+)+\/?/gu;
17
+ const pathMentions = (line) => line.replace(/`([^`]*)`/gu, (_, span) => (/\s/u.test(span.trim()) ? " " : ` ${span.trim()} `)).match(PATH_TOKEN) ?? [];
18
+
19
+ const covers = (root, path) => {
20
+ const inside = relative(root, path);
21
+ return inside === "" || (!inside.startsWith("..") && !isAbsolute(inside));
22
+ };
23
+ const real = (path) => {
24
+ try {
25
+ return realpathSync(path);
26
+ } catch {
27
+ return path;
28
+ }
29
+ };
30
+ const nearestDirectory = (path) => {
31
+ for (let at = path; ; at = dirname(at)) {
32
+ try {
33
+ if (statSync(at).isDirectory()) return at;
34
+ } catch {
35
+ // Not there yet; climb.
36
+ }
37
+ if (dirname(at) === at) return at;
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Each absolute path under `## Todos` (before `## Final verification wave`, outside fences) that
43
+ * lies outside the project and outside every `Scope roots:` line, as `{ path, suggestion }` with
44
+ * the line to paste, or `{ path, problem }` when the nearest existing folder is too broad to grant.
45
+ * One entry per folder.
46
+ */
47
+ export const uncoveredScopePaths = (planText, projectRoot) => {
48
+ const project = real(resolve(projectRoot));
49
+ const scoped = [...planText.matchAll(SCOPE_LINE)].map(([, path]) => real(isAbsolute(path) ? path : resolve(project, path)));
50
+ let inTodos = false;
51
+ const found = new Map();
52
+ for (const { line } of planLinesOutsideFences(planText)) {
53
+ const heading = line.trimEnd();
54
+ if (heading === "## Todos") inTodos = true;
55
+ else if (heading === "## Final verification wave") inTodos = false;
56
+ if (!inTodos) continue;
57
+ for (const mention of pathMentions(line)) {
58
+ const path = mention.replace(/[.,:;)]+$/u, "");
59
+ const directory = real(nearestDirectory(path));
60
+ if ([path, directory].some((candidate) => covers(project, real(candidate)) || scoped.some((root) => covers(root, real(candidate))))) continue;
61
+ if (found.has(directory)) continue;
62
+ // The filesystem root, a top-level folder or the home folder itself is never suggested.
63
+ const parent = dirname(directory);
64
+ const tooBroad = parent === dirname(parent) || directory === real(homedir());
65
+ found.set(directory, tooBroad
66
+ ? { path, problem: `${path} is outside the project; name a narrower existing folder on a Scope roots line` }
67
+ : { path, suggestion: `Scope roots: ${directory} (read)` });
68
+ }
69
+ }
70
+ return [...found.values()];
71
+ };
72
+
73
+ export const describeScopePath = (entry) => entry.suggestion
74
+ ? `${entry.path} is outside the project and no Scope roots line covers it; add: ${entry.suggestion}`
75
+ : entry.problem;
76
+
@@ -17,7 +17,8 @@ const WORDS = {
17
17
  active: (n) => `${n} active`,
18
18
  next: "next",
19
19
  window: (since, trees) => `last ${since} ยท ${trees} ${trees === 1 ? "worktree" : "worktrees"}`,
20
- badge: { "waiting-on-user": "๐ŸŸ  **WAITING ON YOU**", active: "๐ŸŸข **ACTIVE**", ended: "โšช ended", unknown: "โšซ unknown" },
20
+ badge: { "waiting-on-user": "๐ŸŸ  **WAITING ON YOU**", active: "๐ŸŸข **ACTIVE**", idle: "๐Ÿ’ค idle", done: "โœ… done", ended: "โšช ended", unknown: "โšซ unknown" },
21
+ runDone: (plan) => `start-work finished ${plan}`,
21
22
  reason: { "asked the user": "it asked you something", "paused workflow": "paused workflow", "start-work boundary": "start-work needs approval" },
22
23
  ago: (text) => `${text} ago`,
23
24
  justNow: "just now",
@@ -63,13 +64,16 @@ const WORDS = {
63
64
  plan: ({ plan, item }) => `Next in ${plan}: ${item}`,
64
65
  check: ({ id8, goal, where, doing }) => `Check on ${id8} in ${where} (${goal})${doing ? `, now ${doing}` : ""}`,
65
66
  pickUp: ({ id8, goal, where }) => `Pick up ${id8} in ${where}: ${goal}`,
67
+ review: ({ id8, where, plan }) => `Review what ${id8} finished in ${where}: ${plan}`,
66
68
  start: () => "No session or plan in this window: say what to start",
67
69
  },
68
70
  goLine: (say) => `Type **\`${say}\`** to continue.`,
69
71
  noGo: "Nothing runs on its own here: open that session, or say what to do.",
70
72
  unknownSources: (list) => `Not read: ${list}.`,
71
73
  older: "Older sessions were not read (read budget used up).",
74
+ plansSkipped: (n) => `${n} ${n === 1 ? "plan was" : "plans were"} not read (read budget used up).`,
72
75
  noSessions: "No Claude Code session records in this window.",
76
+ opener: { done: "Done so far", doing: "Doing now", next: "Next", nothingDone: "nothing finished in this window", nothingRunning: "nothing running", type: (say) => `(type ${say})`, finishedRun: (plan) => `${plan} (start-work complete)` },
73
77
  },
74
78
  ko: {
75
79
  sessions: (n) => `์„ธ์…˜ ${n}๊ฐœ`,
@@ -77,7 +81,8 @@ const WORDS = {
77
81
  active: (n) => `์ง„ํ–‰ ์ค‘ ${n}`,
78
82
  next: "๋‹ค์Œ",
79
83
  window: (since, trees) => `์ตœ๊ทผ ${since} ยท ์›ŒํฌํŠธ๋ฆฌ ${trees}๊ฐœ`,
80
- badge: { "waiting-on-user": "๐ŸŸ  **๋‚˜๋ฅผ ๊ธฐ๋‹ค๋ฆผ**", active: "๐ŸŸข **์ง„ํ–‰ ์ค‘**", ended: "โšช ๋๋‚จ", unknown: "โšซ ๋ชจ๋ฆ„" },
84
+ badge: { "waiting-on-user": "๐ŸŸ  **๋‚˜๋ฅผ ๊ธฐ๋‹ค๋ฆผ**", active: "๐ŸŸข **์ง„ํ–‰ ์ค‘**", idle: "๐Ÿ’ค ์‰ฌ๋Š” ์ค‘", done: "โœ… ์™„๋ฃŒ", ended: "โšช ๋๋‚จ", unknown: "โšซ ๋ชจ๋ฆ„" },
85
+ runDone: (plan) => `${plan} start-work ์™„๋ฃŒ`,
81
86
  reason: { "asked the user": "์งˆ๋ฌธ์— ๋‹ต์„ ๊ธฐ๋‹ค๋ฆผ", "paused workflow": "๋ฉˆ์ถ˜ ์›Œํฌํ”Œ๋กœ", "start-work boundary": "start-work ์Šน์ธ ๋Œ€๊ธฐ" },
82
87
  ago: (text) => `${text} ์ „`,
83
88
  justNow: "๋ฐฉ๊ธˆ",
@@ -123,12 +128,15 @@ const WORDS = {
123
128
  plan: ({ plan, item }) => `${plan} ๋‹ค์Œ ํ•ญ๋ชฉ: ${item}`,
124
129
  check: ({ id8, goal, where, doing }) => `${where}์˜ ${id8} ํ™•์ธ (${goal})${doing ? `, ์ง€๊ธˆ ${doing}` : ""}`,
125
130
  pickUp: ({ id8, goal, where }) => `${where}์˜ ${id8} ์ด์–ด๋ฐ›๊ธฐ: ${goal}`,
131
+ review: ({ id8, where, plan }) => `${where}์˜ ${id8}๊ฐ€ ๋๋‚ธ ${plan} ๊ฒ€ํ† ํ•˜๊ธฐ`,
126
132
  start: () => "์ด ๊ธฐ๊ฐ„์— ์„ธ์…˜ยท๊ณ„ํš์ด ์—†์Šต๋‹ˆ๋‹ค. ์‹œ์ž‘ํ•  ์ผ์„ ๋งํ•ด ์ฃผ์„ธ์š”",
127
133
  },
128
134
  goLine: (say) => `**\`${say}\`** ๋ผ๊ณ  ์ž…๋ ฅํ•˜๋ฉด ์ด์–ด๊ฐ‘๋‹ˆ๋‹ค.`,
129
135
  noGo: "์ €์ ˆ๋กœ ์‹คํ–‰๋˜๋Š” ๋‹จ๊ณ„๋Š” ์•„๋‹™๋‹ˆ๋‹ค. ๊ทธ ์„ธ์…˜์„ ์—ด๊ฑฐ๋‚˜ ํ•  ์ผ์„ ๋งํ•ด ์ฃผ์„ธ์š”.",
130
136
  unknownSources: (list) => `์ฝ์ง€ ๋ชปํ•จ: ${list}.`,
131
137
  older: "์˜ค๋ž˜๋œ ์„ธ์…˜์€ ์ฝ์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค(์ฝ๊ธฐ ์˜ˆ์‚ฐ ์†Œ์ง„).",
138
+ plansSkipped: (n) => `๊ณ„ํš ${n}๊ฐœ๋Š” ์ฝ์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค(์ฝ๊ธฐ ์˜ˆ์‚ฐ ์†Œ์ง„).`,
139
+ opener: { done: "์ง€๊ธˆ๊นŒ์ง€", doing: "์ง€๊ธˆ", next: "๋‹ค์Œ", nothingDone: "์ด ๊ธฐ๊ฐ„์— ๋๋‚ธ ์ผ ์—†์Œ", nothingRunning: "์‹คํ–‰ ์ค‘์ธ ์ผ ์—†์Œ", type: (say) => `(${say} ์ž…๋ ฅ)`, finishedRun: (plan) => `${plan} (start-work ์™„๋ฃŒ)` },
132
140
  noSessions: "์ด ๊ธฐ๊ฐ„์˜ Claude Code ์„ธ์…˜ ๊ธฐ๋ก์ด ์—†์Šต๋‹ˆ๋‹ค.",
133
141
  },
134
142
  };
@@ -212,6 +220,8 @@ const nextOf = (session, data, w) => {
212
220
  const work = (data.startWork ?? []).find((item) => item.id8 === session.id8);
213
221
  const plan = work ? (data.roadmap?.plans ?? []).find((item) => item.plan === work.plan) : null;
214
222
  if (plan && plan.current) return w.planNow(code(plan.plan), plain(plan.current));
223
+ // A finished or idle session's last tool call is history, never its next step.
224
+ if (session.status === "done") return session.finishedPlan ? w.runDone(code(session.finishedPlan)) : w.nothing;
215
225
  if (session.status === "active") {
216
226
  if (frames.length) return `${frames.at(-1).skill} ยท ${frames.at(-1).stage}`;
217
227
  const doing = actionOf(session);
@@ -276,8 +286,11 @@ const suggestion = (data, w) => {
276
286
  if (plan) return w.suggest.plan({ plan: plan.local ? plan.plan : `${basename(String(plan.worktree))}/${plan.plan}`, item: clipToWidth(bare(plan.current), 60) });
277
287
  const active = sessions.find((session) => session.status === "active" && !session.self);
278
288
  if (active) return w.suggest.check({ id8: active.id8, goal: goal(active), where: where(active), doing: actionOf(active, bare) });
279
- const ended = sessions.find((session) => session.status === "ended" && !session.self);
280
- if (ended) return w.suggest.pickUp({ id8: ended.id8, goal: goal(ended), where: where(ended) });
289
+ // Otherwise the newest listed session that is not running: review what a done one finished, or pick
290
+ // up an idle or ended one. Only an empty window says there is nothing.
291
+ const settled = sessions.find((session) => ["done", "idle", "ended"].includes(session.status) && !session.self);
292
+ if (settled?.status === "done") return w.suggest.review({ id8: settled.id8, where: where(settled), plan: settled.finishedPlan ? bare(settled.finishedPlan) : goal(settled) });
293
+ if (settled) return w.suggest.pickUp({ id8: settled.id8, goal: goal(settled), where: where(settled) });
281
294
  return w.suggest.start();
282
295
  };
283
296
 
@@ -311,7 +324,7 @@ const roadmapLines = (data, w) => {
311
324
  const box = (title, body) => {
312
325
  const width = Math.max(displayWidth(title) + 2, ...body.map((line) => displayWidth(line))) + 2;
313
326
  const pad = (line) => `${line}${" ".repeat(Math.max(0, width - 2 - displayWidth(line)))}`;
314
- return ["```text", `โ•ญโ”€ ${title} ${"โ”€".repeat(Math.max(1, width - displayWidth(title) - 3))}โ•ฎ`, ...body.map((line) => `โ”‚ ${pad(line)} โ”‚`), `โ•ฐ${"โ”€".repeat(width)}โ•ฏ`, "```"].join("\n");
327
+ return ["```", `โ•ญโ”€ ${title} ${"โ”€".repeat(Math.max(1, width - displayWidth(title) - 3))}โ•ฎ`, ...body.map((line) => `โ”‚ ${pad(line)} โ”‚`), `โ•ฐ${"โ”€".repeat(width)}โ•ฏ`, "```"].join("\n");
315
328
  };
316
329
 
317
330
  // Wraps a step to the box at word breaks, three lines at most, the last one clipped.
@@ -333,13 +346,50 @@ const stepText = (next, w) => {
333
346
  return bare(describe({ skill: target.skill, stage: target.stage, plan: target.plan, action: target.action, root: target.root }));
334
347
  };
335
348
 
349
+ // The three lines that open the brief, from records only. Done: this worktree's newest commits in
350
+ // the window (two at most), then its completed start-work runs and its plans with every row ticked
351
+ // (three items at most), else its finished litgoal. Doing: this session's top frame, else its
352
+ // running start-work, else the newest active session's title. Next: the step and the word to type.
353
+ const openerLines = (data, step, w) => {
354
+ const local = data.scope?.worktrees?.[0];
355
+ const subjects = (data.commits ?? []).filter((commit) => commit.worktree === local).slice(0, 2).map((commit) => plain(commit.subject));
356
+ const runs = (data.finished?.runs ?? []).filter((run) => run.worktree === local);
357
+ const runPlans = new Set(runs.map((run) => run.plan));
358
+ const finished = [
359
+ ...runs.map((run) => w.opener.finishedRun(code(run.plan))),
360
+ ...(data.finished?.plans ?? []).filter((plan) => plan.worktree === local && !runPlans.has(plan.plan)).map((plan) => `${code(plan.plan)}${plan.gauge ? ` ${code(plan.gauge)}` : ""}`),
361
+ ];
362
+ const items = [...subjects, ...[...new Set(finished)]].slice(0, 3);
363
+ const finishedGoal = (data.roadmap?.litgoal ?? []).find((goal) => goal.local && goal.status === "complete");
364
+ const done = items.length ? items.join("; ") : finishedGoal ? plain(finishedGoal.objective) : w.opener.nothingDone;
365
+ const sessions = data.sessions ?? [];
366
+ const selfId = sessions.find((session) => session.self)?.id8 ?? null;
367
+ const frame = (data.workflows ?? []).filter((item) => item.self || (selfId && item.id8 === selfId)).at(-1);
368
+ const work = (data.startWork ?? []).find((item) => item.self && item.status === "active");
369
+ const active = sessions.find((session) => session.status === "active");
370
+ const gaugeOf = (progress) => (progress?.gauge ? code(progress.gauge) : null);
371
+ const doing = frame
372
+ ? [frame.skill, frame.stage, gaugeOf(frame.progress)].filter((part) => part && part !== "unknown").join(" ยท ")
373
+ : work
374
+ ? ["start-work", work.plan, gaugeOf(work.progress)].filter(Boolean).join(" ยท ")
375
+ : active ? plain(clipToWidth(goalOf(active), 80)) : w.opener.nothingRunning;
376
+ const say = data.next?.say ?? null;
377
+ return [
378
+ `${w.opener.done}: ${done} `,
379
+ `${w.opener.doing}: ${doing} `,
380
+ `${w.opener.next}: ${plain(step)}${say ? ` ${w.opener.type(say)}` : ""}`,
381
+ ];
382
+ };
383
+
336
384
  /** The brief as Markdown. `lang` is `ko` or `en`; `now` the clock the relative times use. */
337
385
  export const renderBrief = (data, { lang = "en", now = Date.parse(data.generatedAt) || Date.now(), width = 72 } = {}) => {
338
386
  const w = WORDS[lang] ?? WORDS.en;
339
387
  const sessions = data.sessions ?? [];
340
388
  const summary = data.summary ?? { sessions: sessions.length, waitingOnUser: 0, active: 0 };
341
- const step = data.next?.kind && data.next.kind !== "none" ? stepText(data.next, w) : bare(suggestion(data, w));
342
- const out = [];
389
+ // With no step for `go`, this worktree's HANDOFF.md Next item comes before the generic suggestion.
390
+ const handoffNext = (data.handoffs ?? []).find((handoff) => handoff.local && handoff.next)?.next ?? null;
391
+ const step = data.next?.kind && data.next.kind !== "none" ? stepText(data.next, w) : bare(handoffNext ?? suggestion(data, w));
392
+ const out = [...openerLines(data, step, w), ""];
343
393
  out.push(`## ๐Ÿงญ ${[w.sessions(summary.sessions), w.waiting(summary.waitingOnUser), w.active(summary.active)].join(" ยท ")} ยท ${w.next}: ${plain(step)}`);
344
394
  out.push(`*${w.window(data.scope?.since ?? "7d", (data.scope?.worktrees ?? []).length || 1)}*`);
345
395
  if (!sessions.length) out.push("", w.noSessions);
@@ -367,7 +417,11 @@ export const renderBrief = (data, { lang = "en", now = Date.parse(data.generated
367
417
  out.push("", box(w.recommended, body));
368
418
  out.push("", say ? w.goLine(say) : w.noGo);
369
419
  const unknown = Object.entries(data.sources ?? {}).filter(([, status]) => status !== "ok").map(([name]) => name);
370
- const notes = [unknown.length ? w.unknownSources(unknown.join(", ")) : null, data.budget?.exhausted ? w.older : null].filter(Boolean);
420
+ const notes = [
421
+ unknown.length ? w.unknownSources(unknown.join(", ")) : null,
422
+ data.budget?.exhausted ? w.older : null,
423
+ data.roadmap?.plansSkipped > 0 ? w.plansSkipped(data.roadmap.plansSkipped) : null,
424
+ ].filter(Boolean);
371
425
  if (notes.length) out.push("", `*${notes.join(" ")}*`);
372
426
  return `${out.join("\n")}\n`;
373
427
  };