@litfamily/litmuse 0.1.14 → 0.1.15

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 (48) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +8 -7
  3. package/README_ko-KR.md +8 -7
  4. package/bin/litmuse.mjs +1 -1
  5. package/lib/stage-card.mjs +4 -12
  6. package/package.json +1 -1
  7. package/plugin/.muse-plugin/plugin.json +16 -16
  8. package/plugin/commands/lit-status.md +1 -1
  9. package/plugin/commands/lit.md +6 -5
  10. package/plugin/hooks/lib/goal.mjs +165 -0
  11. package/plugin/hooks/lib/routes.mjs +27 -10
  12. package/plugin/hooks/lib/skill-plan.mjs +199 -0
  13. package/plugin/hooks/lib/stage.mjs +4 -1
  14. package/plugin/hooks/lib/workflow-stack.mjs +1 -1
  15. package/plugin/hooks/post-tool-use.mjs +39 -0
  16. package/plugin/hooks/pre-tool-use.mjs +34 -1
  17. package/plugin/hooks/session-start.mjs +4 -0
  18. package/plugin/hooks/stop.mjs +53 -3
  19. package/plugin/hooks/user-prompt-submit.mjs +161 -9
  20. package/plugin/lib/rewind/collect.mjs +93 -15
  21. package/plugin/lib/rewind/rainbow.mjs +13 -0
  22. package/plugin/lib/rewind/verdict.mjs +258 -0
  23. package/plugin/skills/autoconference/SKILL.md +1 -1
  24. package/plugin/skills/autoconference/modes/core.md +1 -1
  25. package/plugin/skills/browser-drive/scripts/capability-probe.mjs +25 -11
  26. package/plugin/skills/lit-adhd/SKILL.md +56 -32
  27. package/plugin/skills/lit-brainstorm/SKILL.md +1 -0
  28. package/plugin/skills/lit-comprehend/SKILL.md +4 -3
  29. package/plugin/skills/lit-crucible/SKILL.md +1 -0
  30. package/plugin/skills/lit-handoff/SKILL.md +3 -2
  31. package/plugin/skills/lit-init/SKILL.md +1 -1
  32. package/plugin/skills/lit-plan/SKILL.md +8 -4
  33. package/plugin/skills/lit-plan/scripts/goal-propose.mjs +50 -0
  34. package/plugin/skills/lit-plan/templates/plan.md +4 -0
  35. package/plugin/skills/lit-team/SKILL.md +97 -64
  36. package/plugin/skills/lit-team/references/team-orchestration.md +6 -4
  37. package/plugin/skills/litgoal/SKILL.md +3 -1
  38. package/plugin/skills/litresearch/SKILL.md +1 -0
  39. package/plugin/skills/litwork/SKILL.md +6 -6
  40. package/plugin/skills/review-work/SKILL.md +1 -0
  41. package/plugin/skills/start-work/SKILL.md +1 -1
  42. package/plugin/skills/ultra-brainstorm/SKILL.md +107 -0
  43. package/plugin/skills/ultra-brainstorm/references/lenses.md +38 -0
  44. package/plugin/skills/ultra-brainstorm/references/workflow-script.md +169 -0
  45. package/plugin/skills/ultra-brainstorm/scripts/estimate.mjs +57 -0
  46. package/plugin/skills/wikify/SKILL.md +2 -2
  47. package/plugin/skills/wikify/modes/init.md +1 -1
  48. package/plugin/skills/lit-recap/SKILL.md +0 -232
@@ -1,10 +1,13 @@
1
- import { run, emitContext, readSession, writeSession, safeId, sessionPath, workspaceOf } from './lib/common.mjs';
1
+ import { run, emitContext, readSession, writeSession, safeId, sessionPath, workspaceOf, PLUGIN_ROOT } from './lib/common.mjs';
2
2
  import { detectRoute } from './lib/routes.mjs';
3
3
  import { liveRoute, resumablePlan } from './lib/reentry.mjs';
4
- import { readStage, recordRoute, stageFile } from './lib/stage.mjs';
4
+ import { readLiveness, readStage, recordRoute, stageFile, stageRoot, workspaceHash } from './lib/stage.mjs';
5
5
  import { movedActivation } from './lib/moved.mjs';
6
6
  import { applyStackEvent, readStack, writeStack, resolveProjectStateRoot, READ_ONLY_DISCIPLINES } from './lib/workflow-stack.mjs';
7
7
  import { isGoPrompt, takeNextStep } from './lib/next-step.mjs';
8
+ import { ROUTE_INTENTS } from './lib/routes.mjs';
9
+ import { buildSkillPlan, matchedSkills, parseSkillHatch, skillPlanContext, skillPlanIds } from './lib/skill-plan.mjs';
10
+ import { GOAL_STATUS, consentAnswer, consentIsLive, readGoalRecord, writeGoalRecord } from './lib/goal.mjs';
8
11
  import { readFileSync, writeFileSync, mkdirSync, readdirSync, statSync } from 'node:fs';
9
12
  import { resolve, join, dirname } from 'node:path';
10
13
 
@@ -83,9 +86,16 @@ function activation(hit, payload) {
83
86
  if (READ_ONLY_DISCIPLINES.includes(hit.route)) {
84
87
  lines.push('This is a READ-ONLY route: report from what the skill reads; it starts, pauses, resumes and finishes nothing.');
85
88
  }
86
- if (hit.route === 'lit-adhd') {
87
- lines.push('Run `litmuse rewind --lang <ko|en>` once (`ko` for a Korean prompt) with `--session` set to this session id, and show the KPI board it prints as given: do this now, at a glance, milestones, done lately, still to do, don\'t forget. Add `--detail` only when the user asks for detail (`lit adhd 자세히`, `lit adhd detail`); the per-session list then sits under the board. `litmuse rewind --json` holds the same records and the board fields.');
88
- lines.push('The collector draws every bar (`██████░░░░ 6/10 (60%)`), count and reminder; never redraw, round or add to them. In the detail list, gauges follow D9 (`[▉▉▉░░] 3/5`, one cell per item up to ten, scaled above) with the remaining items under each gauge; an unknown total is never `?`: copy the `… N steps` fact line instead, never a guess.');
89
+ // The collector shipped beside these hooks: a `litmuse` bin on PATH can be an older package that prints another view.
90
+ const rewind = `node "${join(PLUGIN_ROOT, 'skills', 'lit-adhd', 'scripts', 'rewind.mjs')}"`;
91
+ // The language is chosen here, never by the model: Korean unless the prompt asks for English in so many words.
92
+ const lang = /(?:^|\s)--en\b|--lang\s+en\b|\bin english\b|영어로/iu.test(String(payload.prompt ?? '')) ? 'en' : 'ko';
93
+ if (hit.route === 'lit-adhd' && hit.recap) {
94
+ const flag = hit.movedFrom ? ' --moved' : '';
95
+ lines.push(`This is the recap view: run \`${rewind} --recap${flag} [<session id or its first characters>] --lang ${lang}\` once, the session id only when the user named one, and show what it prints as given${flag ? ', starting with its first line, the note that lit-recap moved here' : ''}. Write nothing and start nothing.`);
96
+ } else if (hit.route === 'lit-adhd') {
97
+ lines.push('Run `' + rewind + ' --lang ' + lang + '` once, with exactly that language flag, with `--session` set to this session id, and show the verdict card it prints exactly as given: about six lines (since your last look, the one thing to do now, the exact text to type, why and what happens if not, what waits next, what was read). Never add a second action, reorder the lines or soften a `네 확인 필요` / `Your call` line into an action.');
98
+ lines.push('Only when the user asks for detail (`lit adhd 자세히`, `lit adhd detail`) add `--detail`: it prints the KPI board (bars, milestones, done, left, reminders) with the per-session list under it. The collector draws every bar and count; never redraw, round or add to them. `' + rewind + ' --json` holds the same records, the board and the verdict.');
89
99
  }
90
100
  if (hit.trailing) {
91
101
  lines.push('Soft-confirm: `lit` came last in the prompt. If the request reads like ordinary prose, say in one line that you are starting a lit-loop and carry on; a stray English `lit` is recoverable.');
@@ -96,6 +106,19 @@ function activation(hit, payload) {
96
106
  return lines.join('\n');
97
107
  }
98
108
 
109
+ // The skill plan of a full activation: the cascade's route stays the primary, the other skills the task matched become
110
+ // companions (or the `lit +…` list replaces them). A bare, resuming or recap prompt has no task to plan. Best effort:
111
+ // any failure leaves the single route alone.
112
+ function skillPlanFor(hit, hatch) {
113
+ try {
114
+ if (hit.bare || hit.resume || hit.recap || (!hatch && typeof hit.task !== 'string')) return null;
115
+ const companions = hatch ? [] : matchedSkills(hit.task, ROUTE_INTENTS);
116
+ return buildSkillPlan({ primary: hit.route, companions, forced: hatch, task: hit.task ?? '' });
117
+ } catch {
118
+ return null;
119
+ }
120
+ }
121
+
99
122
  // Re-entry: a `lit` while its route is active continues it (state kept, except start-work); a bare `lit` resumes started plan work;
100
123
  // `lit new` / `lit restart`, a different route, a new session or unreadable state get the full activation.
101
124
  const PAUSE = /(^|\s)(stop|pause|cancel|halt|wait)(\s|[.!,?]|$)|멈춰|중단|그만|잠깐|일시\s*정지|취소/i;
@@ -169,7 +192,120 @@ function goHint(why) {
169
192
  ].join('\n');
170
193
  }
171
194
 
195
+ // Why `yes` cannot start start-work on this plan now, or null. The same preconditions the typed start path relies on:
196
+ // the plan exists with an open row, and no other live session of this workspace already runs start-work on it.
197
+ function startRefusal(payload, plan) {
198
+ const cwd = workspaceOf(payload);
199
+ let text;
200
+ try {
201
+ text = readFileSync(resolve(cwd, plan), 'utf8');
202
+ } catch {
203
+ return `${plan} was not found`;
204
+ }
205
+ if (!text.split('\n').some((line) => /^- \[ \] (?:\d+|F\d+)\. /u.test(line))) return `${plan} has no open row`;
206
+ const here = workspaceHash(cwd);
207
+ const live = new Map(readLiveness().map((rec) => [rec.session, rec]));
208
+ let names = [];
209
+ try { names = readdirSync(stageRoot()).filter((n) => n.endsWith('.json') && n !== 'latest.json'); } catch { /* no stage records */ }
210
+ for (const name of names) {
211
+ const rec = readStage(join(stageRoot(), name));
212
+ if (!rec || rec.session === payload.session_id || rec.workspace !== here || rec.route !== 'start-work' || rec.plan !== plan) continue;
213
+ const beat = live.get(rec.session);
214
+ if (beat && beat.state === 'alive' && Date.now() - Date.parse(beat.at) <= 15 * 60_000) return `another session is already running start-work on ${plan}`;
215
+ }
216
+ return null;
217
+ }
218
+
219
+ // The answer to the plan-approval question. Only an exact `yes`, `edit` or `no`, typed in the session that was asked,
220
+ // while the question is live counts;
221
+ // any other prompt leaves the question as it was, and a read-only skill holding the session leaves it for the planning
222
+ // session. `yes` approves the plan, starts start-work on it (the same start the typed `lit start plans/<f>.md` makes)
223
+ // and arms its goal; the model then sets the goal with create_goal, which PreToolUse admits only with this exact
224
+ // objective. When the start is refused, no goal is armed either.
225
+ function goalAnswer(payload) {
226
+ const answer = consentAnswer(payload.prompt);
227
+ if (!answer) return false;
228
+ const root = resolveProjectStateRoot(workspaceOf(payload));
229
+ const consent = readGoalRecord(root, 'consent');
230
+ if (!consentIsLive(consent)) return false;
231
+ // Only the session that was asked can answer. A yes typed elsewhere (or on a question no session was stamped on)
232
+ // starts nothing, but says why and how to start the plan instead of passing silently.
233
+ if (!consent.sessionId || consent.sessionId !== (payload.session_id ?? null)) {
234
+ if (answer !== 'yes') return false;
235
+ emitContext('UserPromptSubmit', [
236
+ ...banner('LIT CONTINUES', 'lit-plan'),
237
+ `Show this line to the user as given: ${GOAL_STATUS.notRecorded(consent.plan)}. Start no work and set no goal.`,
238
+ ].join('\n'));
239
+ return true;
240
+ }
241
+ if (READ_ONLY_DISCIPLINES.includes(readSession(payload)?.route)) return false;
242
+ const now = new Date().toISOString();
243
+ writeGoalRecord(root, 'consent', { ...consent, answeredAt: now, answer });
244
+ if (answer === 'edit') {
245
+ writeGoalRecord(root, 'consent', consent);
246
+ emitContext('UserPromptSubmit', [
247
+ ...banner('LIT CONTINUES', 'lit-plan'),
248
+ `The user wants to edit the plan before approving. Ask in one line what should change (for the goal, the plan's \`## Done when\` check in ${consent.plan}), rewrite the plan, run goal-propose on it again and ask the approval question again with what it prints. Start no work.`,
249
+ ].join('\n'));
250
+ return true;
251
+ }
252
+ if (answer === 'no') {
253
+ emitContext('UserPromptSubmit', [
254
+ ...banner('LIT CONTINUES', 'lit-plan'),
255
+ `Show this line as given: ${GOAL_STATUS.declined}. The plan ${consent.plan} stays as written; \`lit start ${consent.plan}\` starts it later. Start no work now.`,
256
+ ].join('\n'));
257
+ return true;
258
+ }
259
+ const refused = startRefusal(payload, consent.plan);
260
+ if (refused) {
261
+ emitContext('UserPromptSubmit', [
262
+ ...banner('LIT CONTINUES', 'lit-plan'),
263
+ `Show this line as given: ${GOAL_STATUS.notStarted(refused)}. Start no work and set no goal.`,
264
+ ].join('\n'));
265
+ return true;
266
+ }
267
+ const withGoal = typeof consent.condition === 'string';
268
+ if (withGoal) writeGoalRecord(root, 'intent', { version: 1, condition: consent.condition, hash: consent.hash, id: consent.id, plan: consent.plan, check: consent.check, sessionId: payload.session_id ?? null, armedAt: now });
269
+ const turnId = payload.turn_id ?? null;
270
+ const pauseRequested = false;
271
+ writeSession(payload, { route: 'start-work', turnId, activatedAt: Date.now(), stopHeldFor: null, pauseRequested });
272
+ stackStart(payload, 'start-work', { plan: consent.plan }, false);
273
+ recordRoute(payload, { route: 'start-work', keyword: 'yes', kind: 'ignite', plan: consent.plan, activatedAt: Date.now() });
274
+ const lines = [activation({ route: 'start-work', keyword: 'yes', bare: false, resume: false, restart: false, trailing: false }, payload)];
275
+ if (withGoal) {
276
+ lines.push(
277
+ `Plan: ${consent.plan}. The user's yes approves the plan, starts the work and sets its goal: the work starts now; work through its open rows in order.`,
278
+ `Before the first row, set the goal: call get_goal. With no unfinished goal, call create_goal with objective exactly \`${consent.condition}\` and nothing else. With an unfinished goal already there, leave it untouched and show: ${GOAL_STATUS.yours} If create_goal is refused, show: ${GOAL_STATUS.notConfirmed(consent.condition)}`,
279
+ `When every row is ticked and \`${consent.check}\` exits 0, call update_goal with status complete and show: ${GOAL_STATUS.met(consent.id)}. On a BLOCKED stop, call update_goal with status blocked and show: ${GOAL_STATUS.cleared(consent.id, 'blocked')}.`,
280
+ );
281
+ } else {
282
+ lines.push(`Plan: ${consent.plan}. The user's yes approves the plan and starts the work now; work through its open rows in order. Show this line once as given: ${GOAL_STATUS.skipped(consent.reason ?? 'no goal for this plan')}. Set no goal.`);
283
+ }
284
+ emitContext('UserPromptSubmit', lines.join('\n'));
285
+ return true;
286
+ }
287
+
288
+ // `lit cancel` while this session owns an open LitMuse goal: close that goal only, never a goal the user set.
289
+ function cancelOwnedGoal(payload) {
290
+ if (!/^\s*\/?(?:litmuse:)?lit\s+cancel\s*$/iu.test(String(payload.prompt ?? ''))) return null;
291
+ try {
292
+ const owner = readGoalRecord(resolveProjectStateRoot(workspaceOf(payload)), 'owner');
293
+ if (!owner || owner.closed || owner.sessionId !== (payload.session_id ?? null)) return null;
294
+ return `This session holds the LitMuse goal [lit:${owner.id}]. Call get_goal: when its objective is exactly \`${owner.condition}\`, call update_goal with status blocked and show: ${GOAL_STATUS.cleared(owner.id, 'cancelled')}. When it is any other goal, leave it untouched and show: ${GOAL_STATUS.yours}`;
295
+ } catch {
296
+ return null;
297
+ }
298
+ }
299
+
172
300
  run((payload) => {
301
+ try {
302
+ if (goalAnswer(payload)) return;
303
+ } catch { /* an unwritable goal record leaves the prompt as ordinary text */ }
304
+ const cancelNote = cancelOwnedGoal(payload);
305
+ if (cancelNote) {
306
+ emitContext('UserPromptSubmit', [...banner('LIT CONTINUES', 'litgoal'), cancelNote, 'Then stop the current work at the next safe point and say what is left.'].join('\n'));
307
+ return;
308
+ }
173
309
  const pauseRequested = PAUSE.test(String(payload.prompt ?? ''));
174
310
  // `go` after a lit-adhd brief continues the briefed step in this session within 30 minutes.
175
311
  // Without a record it is ordinary text that changes nothing.
@@ -232,7 +368,9 @@ run((payload) => {
232
368
  emitContext('UserPromptSubmit', goHint('an unreadable next step'));
233
369
  return;
234
370
  }
235
- const hit = detectRoute(payload.prompt);
371
+ // `lit +viz +ui <task>` names the skill plan; the route is read from the prompt without the `+` words.
372
+ const hatch = parseSkillHatch(payload.prompt);
373
+ const hit = detectRoute(hatch ? hatch.rest : payload.prompt);
236
374
  const previous = readSession(payload);
237
375
  if (!hit) {
238
376
  if (previous && previous.route) {
@@ -268,12 +406,26 @@ run((payload) => {
268
406
  return;
269
407
  }
270
408
  const named = hit.route === 'start-work' ? typedPlan(payload.prompt) : null;
409
+ // The run record always names its plan, so a reader can tell a finished run by that plan's rows: the typed one, else
410
+ // the one open plan start-work would pick. The context's approval line stays for a typed plan only.
411
+ const runPlan = hit.route === 'start-work' ? named ?? soleOpenPlan(workspaceOf(payload)) : null;
412
+ const skillPlan = skillPlanFor(hit, hatch);
271
413
  writeSession(payload, { route: hit.route, turnId, activatedAt: Date.now(), stopHeldFor: null, pauseRequested });
272
- stackStart(payload, hit.route, named ? { plan: named } : undefined, hit.restart);
273
- recordRoute(payload, { route: hit.route, keyword: hit.keyword ?? null, kind: 'ignite', plan: named, activatedAt: Date.now() });
274
- emitContext('UserPromptSubmit', activation(hit, payload) + (named ? `\nPlan: ${named}. The typed command is the approval: the work starts without a separate approval turn; work through its open rows in order.` : ''));
414
+ stackStart(payload, hit.route, runPlan ? { plan: runPlan } : undefined, hit.restart);
415
+ recordRoute(payload, { route: hit.route, keyword: hit.keyword ?? null, kind: 'ignite', plan: runPlan, activatedAt: Date.now(), skills: skillPlanIds(skillPlan) });
416
+ emitContext('UserPromptSubmit', activation(hit, payload)
417
+ + (named ? `\nPlan: ${named}. The typed command is the approval: the work starts without a separate approval turn; work through its open rows in order.` : '')
418
+ + (skillPlan ? `\n${skillPlanContext(skillPlan)}` : ''));
275
419
  });
276
420
 
421
+ // The one plan under plans/ with an open row, or null when there are none or several.
422
+ function soleOpenPlan(cwd) {
423
+ let names = [];
424
+ try { names = readdirSync(join(cwd, 'plans')).filter((name) => /^[A-Za-z0-9._-]+\.md$/u.test(name)); } catch { return null; }
425
+ const open = names.map((name) => `plans/${name}`).filter((plan) => planHasOpenRows(cwd, plan));
426
+ return open.length === 1 ? open[0] : null;
427
+ }
428
+
277
429
  // Column-zero task rows with an open box, the same grammar start-work ticks.
278
430
  // Fail closed: an unreadable plan reads as having no open row.
279
431
  function planHasOpenRows(cwd, plan) {
@@ -4,17 +4,19 @@
4
4
  // redacted, capped JSON brief. A source that is not there reads `unknown`; nothing is inferred.
5
5
  // It writes one file only: this session's next-step record for `go`.
6
6
  import { execFileSync } from 'node:child_process';
7
- import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readdirSync, existsSync } from 'node:fs';
7
+ import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, renameSync, writeFileSync, existsSync } from 'node:fs';
8
+ import { createHash } from 'node:crypto';
8
9
  import { homedir } from 'node:os';
9
- import { basename, join, resolve } from 'node:path';
10
+ import { basename, dirname, join, resolve } from 'node:path';
10
11
 
11
12
  import { parsePlanTaskRows } from '../plan-task-rows.mjs';
12
13
  import { PULSE_UNKNOWN, aggregateProgress, clipToWidth, displayWidth, progressOf } from './gauge.mjs';
13
14
  import { buildBoard } from './board.mjs';
15
+ import { nextCursor, renderVerdict } from './verdict.mjs';
14
16
  import { chooseNextStep, writeNextStep } from './next-step.mjs';
15
17
  import { makeRedactor } from './redact.mjs';
16
18
  import { findTranscripts, makeBudget, readTranscriptLines, sessionRecord } from './transcripts.mjs';
17
- import { rainbowLine } from '../../../lib/stage-card.mjs';
19
+ import { rainbowLine } from './rainbow.mjs';
18
20
  import { projectKey, resolveProjectStateRoot } from '../../hooks/lib/workflow-stack.mjs';
19
21
  import { readLiveness } from '../../hooks/lib/stage.mjs';
20
22
 
@@ -247,17 +249,23 @@ const PLAN_NAME = /^plans\/[A-Za-z0-9._-]+\.md$/u;
247
249
  const stageDirOf = (env) => join(env.XDG_STATE_HOME || join(env.HOME || homedir(), '.local', 'state'), 'litmuse', 'stage');
248
250
  const STAGE_RECORDS_MAX = 200;
249
251
 
252
+ // Only an old record carries no plan; for it, a folder with no open plan is the guess that the run finished.
253
+ const anyOpenPlan = (root, budget) => (entries(join(root, 'plans')) ?? [])
254
+ .filter((item) => item.isFile() && PLAN_NAME.test(`plans/${item.name}`))
255
+ .some((item) => parsePlanTaskRows(readSmallFile(join(root, 'plans', item.name), budget) ?? '').some((row) => !row.checked));
256
+
250
257
  const runOf = (root, record, sessionId, budget, redact) => {
251
258
  const plan = typeof record.plan === 'string' && PLAN_NAME.test(record.plan) ? record.plan : null;
252
259
  const planText = plan ? readSmallFile(join(root, plan), budget) : null;
253
260
  const rows = planText === null ? [] : parsePlanTaskRows(planText);
254
261
  const open = rows.filter((row) => !row.checked);
255
262
  const id = typeof record.session === 'string' ? record.session : sessionId ?? null;
263
+ const finished = plan ? rows.length > 0 && !open.length : !anyOpenPlan(root, budget);
256
264
  return {
257
265
  worktree: redact(root),
258
266
  workId: `stage-${id ?? 'unknown'}`,
259
267
  plan: plan ?? 'unknown',
260
- status: rows.length && !open.length ? 'complete' : 'active',
268
+ status: finished ? 'complete' : 'active',
261
269
  sessionId: id,
262
270
  id8: typeof id === 'string' ? id.slice(0, 8) : 'unknown',
263
271
  completedMs: rows.length && !open.length ? mtimeOf(join(root, plan)) : null,
@@ -328,7 +336,9 @@ const lanesOf = (sessions, herdr, sessionId, roots, env) => {
328
336
  for (const item of herdr.raw ?? []) {
329
337
  if (!LANE_AGENT.has(item.agent_status)) continue;
330
338
  if (env.HERDR_PANE_ID && item.pane_id === env.HERDR_PANE_ID) continue;
331
- const here = (env.HERDR_WORKSPACE_ID && item.workspace_id === env.HERDR_WORKSPACE_ID) || inside(item.cwd, roots) || inside(item.foreground_cwd, roots);
339
+ // Only an agent working inside this repo races `go`; sharing the herdr workspace is not enough (a machine-wide
340
+ // workspace holds agents of other repos).
341
+ const here = inside(item.cwd, roots) || inside(item.foreground_cwd, roots);
332
342
  if (!here) continue;
333
343
  const session = typeof item.agent_session?.value === 'string' ? item.agent_session.value : null;
334
344
  if (session && (session === sessionId || counted.has(session))) continue;
@@ -400,9 +410,24 @@ export const collectRewind = ({
400
410
 
401
411
  const transcripts = findTranscripts(sessionStoreDir(env), roots);
402
412
  const sessions = [];
413
+ // What the verdict card's coverage line reports: session logs changed inside the window that this run did not read.
414
+ const notRead = { budget: 0, limit: 0, unreadable: 0 };
403
415
  for (const file of transcripts.files) {
404
- if (sessions.length >= limit || budget.exhausted) break;
416
+ let changed = null;
417
+ try {
418
+ changed = lstatSync(file.path).mtimeMs;
419
+ } catch { /* gone since the listing */ }
420
+ if (changed !== null && now - changed > sinceMs) continue;
421
+ if (sessions.length >= limit) {
422
+ notRead.limit += 1;
423
+ continue;
424
+ }
425
+ if (budget.exhausted) {
426
+ notRead.budget += 1;
427
+ continue;
428
+ }
405
429
  const lines = readTranscriptLines(file.path, budget);
430
+ if (!lines) notRead.unreadable += 1;
406
431
  const session = lines ? sessionRecord(file.sessionId, lines, { redact, now }) : null;
407
432
  if (!session || (session.lastMs !== null && now - session.lastMs > sinceMs)) continue;
408
433
  if (here && session.cwd && resolve(session.cwd) !== start) continue;
@@ -475,6 +500,7 @@ export const collectRewind = ({
475
500
  herdr: herdr.status,
476
501
  },
477
502
  budget: { bytesRead: budget.used, limit: budget.limit, exhausted: budget.exhausted },
503
+ coverage: { notRead },
478
504
  summary: {
479
505
  sessions: sessions.length,
480
506
  waitingOnUser: sessions.filter((session) => session.status === 'waiting-on-user').length,
@@ -500,6 +526,7 @@ export const collectRewind = ({
500
526
  items: lanes.slice(0, 10).map(({ id8, waiting, worktree }) => ({ id8: redact(String(id8)), waiting, worktree })),
501
527
  },
502
528
  };
529
+ data.worktreeState = roots.map((root) => worktreeStateOf(root, exec, redact));
503
530
  const next = chooseNextStep(data, sessionId);
504
531
  data.next = next;
505
532
  data.opener = openerOf(data, sessionId, redact(start));
@@ -515,7 +542,7 @@ export const collectRewind = ({
515
542
  next,
516
543
  step: stepOf(data),
517
544
  handoffNext: handoffNextOf(data),
518
- worktreeState: roots.map((root) => worktreeStateOf(root, exec, redact)),
545
+ worktreeState: data.worktreeState,
519
546
  unread: budget.exhausted || skippedPlans.count > 0,
520
547
  }, lang);
521
548
  data.nextRecorded = false;
@@ -902,17 +929,50 @@ export const renderRewind = (data, width = 100, { color = false } = {}) => {
902
929
  return `${out.join('\n')}\n`;
903
930
  };
904
931
 
932
+ // The verdict card's "since your last look" cursor: one small file per project under LitMuse's state home
933
+ // ($XDG_STATE_HOME/litmuse/adhd), outside every repository. It moves only after a card was printed.
934
+ export const adhdCursorPath = (env, cwd) => {
935
+ const home = env.XDG_STATE_HOME || join(env.HOME || homedir(), '.local', 'state');
936
+ const key = createHash('sha256').update(projectKey(resolve(cwd))).digest('hex').slice(0, 16);
937
+ return join(home, 'litmuse', 'adhd', `cursor-${key}.json`);
938
+ };
939
+
940
+ const readCursor = (path) => {
941
+ try {
942
+ const cursor = JSON.parse(readFileSync(path, 'utf8'));
943
+ return cursor && typeof cursor === 'object' && typeof cursor.at === 'string' ? cursor : null;
944
+ } catch {
945
+ return null;
946
+ }
947
+ };
948
+
949
+ const writeCursor = (path, cursor) => {
950
+ try {
951
+ mkdirSync(dirname(path), { recursive: true });
952
+ const staging = `${path}.${process.pid}.tmp`;
953
+ writeFileSync(staging, `${JSON.stringify(cursor)}\n`);
954
+ renameSync(staging, path);
955
+ } catch { /* an unwritable cursor only means the next card keeps the same baseline */ }
956
+ };
957
+
905
958
  /**
906
- * `litmuse rewind [--lang ko|en] [--detail] [--json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]`.
907
- * Prints the KPI board; `--detail` adds the per-session brief under it; `--json` prints the records
908
- * with the board's fields and text in `board`.
959
+ * `litmuse rewind [--lang ko|en | --en] [--detail | --recap [<session>] | --json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]`.
960
+ * The default is the verdict card (Korean unless English is asked for). `--detail` prints the KPI board with the
961
+ * per-session brief under it; `--recap [<session>]` prints the per-session brief alone, of one session when its id or
962
+ * first characters are given; `--json` prints the records with the board and the verdict.
909
963
  */
964
+ // The one line the old lit-recap names lead with; the collector prints it so it is always the view's first line.
965
+ export const RECAP_MOVED_NOTE = 'lit-recap moved into lit-adhd; this is its recap view (lit adhd recap).';
966
+
910
967
  export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, stdout = process.stdout, stderr = process.stderr, exec, now } = {}) => {
911
968
  const options = { cwd, env, here: false, since: DEFAULT_SINCE, max: DEFAULT_MAX, sessionId: null, lang: 'en', ...(exec ? { exec } : {}), ...(now ? { now } : {}) };
912
969
  let json = false;
913
970
  let detail = false;
971
+ let recap = null;
972
+ let moved = false;
973
+ let lang = null;
914
974
  let width = Number(stdout.columns) || 100;
915
- const usage = 'Usage: litmuse rewind [--lang ko|en] [--detail] [--json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]';
975
+ const usage = 'Usage: litmuse rewind [--lang ko|en | --en] [--detail | --recap [<session>] [--moved] | --json] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]';
916
976
  if (args.some((arg) => arg === '--help' || arg === '-h')) {
917
977
  stdout.write(`${usage}\n`);
918
978
  return 0;
@@ -921,7 +981,10 @@ export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, std
921
981
  const arg = args[index];
922
982
  if (arg === '--json') json = true;
923
983
  else if (arg === '--detail') detail = true;
924
- else if (arg === '--lang' && ['ko', 'en'].includes(args[index + 1])) options.lang = args[++index];
984
+ else if (arg === '--recap') recap = /^[A-Za-z0-9._:-]{1,160}$/u.test(args[index + 1] ?? '') && !args[index + 1].startsWith('--') ? args[++index] : '';
985
+ else if (arg === '--moved') moved = true;
986
+ else if (arg === '--lang' && ['ko', 'en'].includes(args[index + 1])) lang = args[++index];
987
+ else if (arg === '--en') lang = 'en';
925
988
  else if (arg === '--here') options.here = true;
926
989
  else if (arg === '--since' && parseSince(args[index + 1])) options.since = args[++index];
927
990
  else if (arg === '--max' && /^\d{1,2}$/u.test(args[index + 1] ?? '')) options.max = Number(args[++index]);
@@ -932,13 +995,28 @@ export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, std
932
995
  return 64;
933
996
  }
934
997
  }
998
+ // The board and the per-session brief keep their English default; the verdict card is Korean unless asked.
999
+ options.lang = lang ?? (detail || recap !== null || json ? 'en' : 'ko');
935
1000
  const data = collectRewind(options);
1001
+ const cursorPath = adhdCursorPath(env, cwd);
936
1002
  if (json) {
1003
+ data.verdict = renderVerdict(data, { lang: options.lang, cursor: readCursor(cursorPath) });
937
1004
  stdout.write(`${JSON.stringify(data, null, 2)}\n`);
938
1005
  return 0;
939
1006
  }
940
- // The board is the default; the per-session brief sits under it only on request. The static
941
- // rainbow marks the adhd turn on a real terminal only, never in pipes.
942
- stdout.write(detail ? `${data.board.text}\n${renderRewind(data, width, { color: stdout.isTTY === true })}` : data.board.text);
1007
+ if (recap !== null) {
1008
+ const sessions = recap ? data.sessions.filter((session) => session.id8.startsWith(recap.slice(0, 8))) : data.sessions;
1009
+ stdout.write(`${moved ? `${RECAP_MOVED_NOTE}\n` : ''}${renderRewind({ ...data, sessions }, width, { color: stdout.isTTY === true })}`);
1010
+ return 0;
1011
+ }
1012
+ // `detail` keeps the KPI board with the per-session brief under it. The static rainbow marks the adhd turn on a real
1013
+ // terminal only, never in pipes.
1014
+ if (detail) {
1015
+ stdout.write(`${data.board.text}\n${renderRewind(data, width, { color: stdout.isTTY === true })}`);
1016
+ return 0;
1017
+ }
1018
+ const card = renderVerdict(data, { lang: options.lang, cursor: readCursor(cursorPath) });
1019
+ stdout.write(card.text);
1020
+ writeCursor(cursorPath, nextCursor(card.verdict, Date.parse(data.generatedAt)));
943
1021
  return 0;
944
1022
  };
@@ -0,0 +1,13 @@
1
+ // The static rainbow for a headline on a real terminal: no animation, no blinking, no full-field luminance swing, so it
2
+ // stays flash-safe on any terminal. It lives inside plugin/ because the installed bundle holds
3
+ // plugin/ only; lib/stage-card.mjs re-exports it for the status card.
4
+ const RAINBOW = [196, 208, 226, 46, 51, 21, 201];
5
+
6
+ export function rainbowLine(text) {
7
+ let color = 0;
8
+ let out = '';
9
+ for (const ch of String(text)) {
10
+ out += ch === ' ' ? ch : `\u001b[38;5;${RAINBOW[color++ % RAINBOW.length]}m${ch}`;
11
+ }
12
+ return `${out}\u001b[0m`;
13
+ }