@litfamily/litgravity 0.1.10 → 0.1.12

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 (56) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +17 -3
  3. package/README_ko-KR.md +17 -3
  4. package/package.json +1 -1
  5. package/plugin/hooks/lib/auto-handoff.mjs +107 -0
  6. package/plugin/hooks/lib/common.mjs +1 -1
  7. package/plugin/hooks/lib/goal.mjs +267 -0
  8. package/plugin/hooks/lib/policy.mjs +6 -1
  9. package/plugin/hooks/lib/reentry.mjs +5 -1
  10. package/plugin/hooks/lib/rewind/collect.mjs +98 -14
  11. package/plugin/hooks/lib/rewind/verdict.mjs +250 -0
  12. package/plugin/hooks/lib/routes.mjs +84 -12
  13. package/plugin/hooks/lib/shown.mjs +65 -0
  14. package/plugin/hooks/lib/skill-plan.mjs +171 -0
  15. package/plugin/hooks/lib/transcript.mjs +20 -0
  16. package/plugin/hooks/lib/workflow-stack.mjs +3 -3
  17. package/plugin/hooks/pre-invocation.mjs +65 -9
  18. package/plugin/hooks/session-start.mjs +28 -13
  19. package/plugin/hooks/stop.mjs +16 -0
  20. package/plugin/plugin.json +1 -1
  21. package/plugin/rules/AGENTS.md +1 -1
  22. package/plugin/skills/autoconference/SKILL.md +1 -1
  23. package/plugin/skills/autoconference/modes/core.md +1 -1
  24. package/plugin/skills/lit-adhd/SKILL.md +96 -58
  25. package/plugin/skills/lit-adhd/references/board-and-detail.md +48 -0
  26. package/plugin/skills/lit-adhd/references/recap-view.md +59 -0
  27. package/plugin/skills/lit-comprehend/SKILL.md +2 -2
  28. package/plugin/skills/lit-handoff/SKILL.md +2 -2
  29. package/plugin/skills/lit-handoff/evals/evals.json +1 -1
  30. package/plugin/skills/lit-handoff/reference/PROVENANCE.md +1 -1
  31. package/plugin/skills/lit-handoff/scripts/verify-closure.mjs +1 -1
  32. package/plugin/skills/lit-init/SKILL.md +1 -1
  33. package/plugin/skills/lit-loop/SKILL.md +1 -1
  34. package/plugin/skills/lit-plan/SKILL.md +15 -15
  35. package/plugin/skills/lit-plan/references/goal-condition.md +78 -0
  36. package/plugin/skills/lit-plan/references/risk-and-recovery.md +1 -1
  37. package/plugin/skills/lit-plan/scripts/goal-propose.mjs +18 -0
  38. package/plugin/skills/lit-plan/templates/plan.md +4 -1
  39. package/plugin/skills/lit-team/SKILL.md +37 -21
  40. package/plugin/skills/lit-team/references/team-orchestration.md +3 -3
  41. package/plugin/skills/litgoal/SKILL.md +8 -8
  42. package/plugin/skills/litgoal/references/host-goal-binding.md +30 -22
  43. package/plugin/skills/litwork/SKILL.md +2 -2
  44. package/plugin/skills/start-work/SKILL.md +1 -1
  45. package/plugin/skills/start-work/references/admission-and-selection.md +1 -1
  46. package/plugin/skills/start-work/references/final-wave.md +1 -1
  47. package/plugin/skills/ultra-brainstorm/SKILL.md +114 -0
  48. package/plugin/skills/ultra-brainstorm/references/lenses.md +40 -0
  49. package/plugin/skills/ultra-brainstorm/references/workflow-script.md +129 -0
  50. package/plugin/skills/ultra-brainstorm/scripts/estimate.mjs +76 -0
  51. package/plugin/skills/wikify/SKILL.md +2 -2
  52. package/plugin/skills/wikify/modes/init.md +1 -1
  53. package/plugin/skills/lit-recap/SKILL.md +0 -168
  54. package/plugin/skills/lit-recap/references/recap-shapes.md +0 -166
  55. package/plugin/skills/lit-recap/references/source-reading.md +0 -105
  56. package/plugin/skills/lit-recap/references/stale-state-checks.md +0 -74
@@ -3,7 +3,8 @@
3
3
  // A source that is not there reads `unknown`; nothing is inferred.
4
4
 
5
5
  import { execFileSync } from 'node:child_process';
6
- import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readdirSync, realpathSync, statSync } from 'node:fs';
6
+ import { createHash } from 'node:crypto';
7
+ import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, statSync, writeFileSync } from 'node:fs';
7
8
  import { homedir } from 'node:os';
8
9
  import { basename, dirname, join, resolve, sep } from 'node:path';
9
10
 
@@ -14,6 +15,7 @@ import { renderBrief } from './brief.mjs';
14
15
  import { buildBoard, renderBoard } from './board.mjs';
15
16
  import { chooseNextStep, writeNextStep } from './next-step.mjs';
16
17
  import { makeRedactor } from './redact.mjs';
18
+ import { nextCursor, renderVerdict } from './verdict.mjs';
17
19
  import { findTranscripts, makeBudget, readTranscriptLines, sessionRecord } from './transcripts.mjs';
18
20
  import { listLive } from '../liveness.mjs';
19
21
 
@@ -167,7 +169,8 @@ const insideAny = (path, roots) => {
167
169
  };
168
170
 
169
171
  // herdr's agents that work on this repo, read only under HERDR_ENV=1: working or blocked (blocked waits on its user),
170
- // in this herdr workspace or with a cwd inside one of the roots, never this pane. Any failure reads `unknown`.
172
+ // with a cwd inside one of the roots, never this pane. Sharing the herdr workspace is not enough: herdr lists every
173
+ // agent on the machine. Any failure reads `unknown`.
171
174
  const herdrLanes = (env, roots, sessionId, exec) => {
172
175
  if (env.HERDR_ENV !== '1') return null;
173
176
  let agents;
@@ -183,8 +186,7 @@ const herdrLanes = (env, roots, sessionId, exec) => {
183
186
  && ['working', 'blocked'].includes(a.agent_status)
184
187
  && !(ownPane && a.pane_id === ownPane)
185
188
  && !(sessionId && a.agent_session?.value === sessionId)
186
- && ((typeof env.HERDR_WORKSPACE_ID === 'string' && env.HERDR_WORKSPACE_ID && a.workspace_id === env.HERDR_WORKSPACE_ID)
187
- || insideAny(a.cwd, realRoots) || insideAny(a.foreground_cwd, realRoots)))
189
+ && (insideAny(a.cwd, realRoots) || insideAny(a.foreground_cwd, realRoots)))
188
190
  .map((a) => ({
189
191
  pane: typeof a.pane_id === 'string' && PANE.test(a.pane_id) ? a.pane_id : null,
190
192
  session: typeof a.agent_session?.value === 'string' ? a.agent_session.value : null,
@@ -328,9 +330,15 @@ export const collectRewind = ({
328
330
  const geminiDir = join(home, '.gemini', 'antigravity-cli');
329
331
  const transcripts = owner.size ? findTranscripts(geminiDir, [...owner.keys()]) : { status: 'unknown', files: [] };
330
332
  const sessions = [];
331
- for (const { id, path } of transcripts.files) {
332
- if (sessions.length >= limit || budget.exhausted) break;
333
+ // What the verdict card's coverage line names: conversations left unread, by reason.
334
+ const notRead = { budget: 0, limit: 0, unreadable: 0 };
335
+ for (const [index, { id, path }] of transcripts.files.entries()) {
336
+ if (sessions.length >= limit || budget.exhausted) {
337
+ notRead[budget.exhausted ? 'budget' : 'limit'] = transcripts.files.length - index;
338
+ break;
339
+ }
333
340
  const lines = readTranscriptLines(path, budget);
341
+ if (!lines) notRead.unreadable += 1;
334
342
  const session = lines ? sessionRecord(lines, { redact, now, cwd: owner.get(id), live: liveness.get(id) ?? null, finished: finishedIn(id, owner.get(id)) }) : null;
335
343
  if (!session || (session.lastMs !== null && now - session.lastMs > sinceMs)) continue;
336
344
  session.sessionId = id;
@@ -388,6 +396,7 @@ export const collectRewind = ({
388
396
  ...(herdr ? { herdr: herdr.status } : {}),
389
397
  },
390
398
  budget: { bytesRead: budget.used, limit: budget.limit, exhausted: budget.exhausted },
399
+ coverage: { notRead },
391
400
  summary: {
392
401
  sessions: sessions.length,
393
402
  waitingOnUser: sessions.filter((s) => s.status === 'waiting-on-user').length,
@@ -406,8 +415,12 @@ export const collectRewind = ({
406
415
  },
407
416
  repo,
408
417
  workflows: (workflows ?? []).map((f) => ({ ...f, self: Boolean(sessionId) && f.sessionId === sessionId })),
409
- // A start-work run is a start-work frame on a workflow stack; agy keeps no other record of one.
410
- startWork: (workflows ?? []).filter((f) => f.skill === 'start-work').map((f) => ({ sessionId: f.sessionId, status: f.status, plan: f.ref?.plan ?? null })),
418
+ // A start-work run is a start-work frame on a workflow stack; agy keeps no other record of one. The frame outlives
419
+ // the work (nothing pops it when the last row is ticked), so a run whose plan is fully ticked is finished and left
420
+ // out. `lit start`, `go` and the approval `yes` record the plan on the frame; only an older frame without one falls
421
+ // back to the guess: finished once no plan of this folder has an open row.
422
+ startWork: (workflows ?? []).filter((f) => f.skill === 'start-work' && !runFinished(f.ref?.plan ?? null, plans))
423
+ .map((f) => ({ sessionId: f.sessionId, status: f.status, plan: f.ref?.plan ?? null })),
411
424
  handoffs,
412
425
  commits: (commits ?? []).slice(0, 20).map(({ atMs: _atMs, ...c }) => c),
413
426
  };
@@ -443,13 +456,62 @@ export const renderRewind = (data, { lang = 'en', width = 72, detail = false } =
443
456
  return tail.length ? `${board}\n*${tail.join(' ')}*\n` : board;
444
457
  };
445
458
 
446
- export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, stdout = process.stdout, stderr = process.stderr } = {}) => {
447
- const options = { cwd, env, here: false, since: DEFAULT_SINCE, max: DEFAULT_MAX, sessionId: null };
459
+ // The cursor of the verdict card: when this user last looked at this folder's card, kept per workspace under the
460
+ // LitGravity state root (outside the route-state folders, so no reader mistakes it for a conversation).
461
+ export const cursorPath = (cwd, env = process.env) => {
462
+ let real;
463
+ try { real = realpathSync(cwd); } catch { real = resolve(cwd); }
464
+ return join(stateRoot(env), 'adhd', `${createHash('sha256').update(real).digest('hex').slice(0, 16)}.cursor.json`);
465
+ };
466
+ const readCursor = (path) => {
467
+ try {
468
+ const value = JSON.parse(readFileSync(path, 'utf8'));
469
+ return value && typeof value === 'object' ? value : null;
470
+ } catch {
471
+ return null;
472
+ }
473
+ };
474
+ const writeCursor = (path, value) => {
475
+ try {
476
+ mkdirSync(dirname(path), { recursive: true });
477
+ const tmp = `${path}.tmp-${process.pid}`;
478
+ writeFileSync(tmp, `${JSON.stringify(value)}\n`);
479
+ renameSync(tmp, path);
480
+ } catch { /* a card without a cursor shows "first look" next time */ }
481
+ };
482
+
483
+ // The recap view (`lit adhd recap [conversation]`, and the old `lit recap`): one conversation's own card, this one by
484
+ // default, with the plan and goal it touched. Read-only, and the cursor is left alone.
485
+ export const RECAP_MOVED_NOTE = 'lit-recap moved into lit-adhd: this is its recap view.';
486
+ const isOpen = (p) => p.progress?.total !== null && p.progress?.total !== undefined && p.progress.done < p.progress.total;
487
+ const runFinished = (plan, plans) => {
488
+ const local = (plans ?? []).filter((p) => p.local);
489
+ if (!plan) return !local.some(isOpen);
490
+ const own = local.find((p) => p.plan === plan);
491
+ return Boolean(own && own.progress?.total && !isOpen(own));
492
+ };
493
+
494
+ export const renderRecap = (data, { lang = 'ko', width = 72, of = null, moved = false } = {}) => {
495
+ // Reached by an old lit-recap name: the moved note is the view's first line, drawn here so no model can bury it.
496
+ if (moved) return `${RECAP_MOVED_NOTE}\n${renderRecap(data, { lang, width, of })}`;
497
+ const want = typeof of === 'string' && of ? of.slice(0, 8) : null;
498
+ const sessions = (data.sessions ?? []).filter((s) => (want ? s.id8 === want : s.self));
499
+ const picked = sessions.length ? sessions : (want ? [] : (data.sessions ?? []).slice(0, 1));
500
+ const head = lang === 'ko' ? '## 🧾 리캡' : '## 🧾 Recap';
501
+ if (!picked.length) return `${head}\n${lang === 'ko' ? `기록 없음${want ? `: ${want}` : ''} — \`lit adhd\`로 전체를 보세요.` : `No record${want ? ` for ${want}` : ''} — \`lit adhd\` shows every conversation.`}\n`;
502
+ return `${head}\n${renderBrief({ ...data, sessions: picked }, { lang, width: Math.max(40, Math.min(width, 100)) })}`;
503
+ };
504
+
505
+ export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, stdout = process.stdout, stderr = process.stderr, now = Date.now() } = {}) => {
506
+ const options = { cwd, env, here: false, since: DEFAULT_SINCE, max: DEFAULT_MAX, sessionId: null, now };
448
507
  let json = false;
449
508
  let detail = false;
450
- let lang = 'en';
509
+ let recap = false;
510
+ let recapOf = null;
511
+ let moved = false;
512
+ let lang = 'ko';
451
513
  let width = Math.min(Number(stdout.columns) || 72, 72);
452
- const usage = 'Usage: rewind.mjs [--brief|--json] [--detail] [--lang en|ko] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]';
514
+ const usage = 'Usage: rewind.mjs [--brief|--json] [--detail] [--recap [--of <conversation>] [--moved]] [--lang ko|en] [--en] [--here] [--since 7d] [--max 12] [--session <id>] [--width N]';
453
515
  if (args.some((a) => a === '--help' || a === '-h')) {
454
516
  stdout.write(`${usage}\n`);
455
517
  return 0;
@@ -459,6 +521,10 @@ export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, std
459
521
  if (arg === '--json') json = true;
460
522
  else if (arg === '--brief') json = false;
461
523
  else if (arg === '--detail') detail = true;
524
+ else if (arg === '--recap') recap = true;
525
+ else if (arg === '--moved') moved = true;
526
+ else if (arg === '--of' && /^[A-Za-z0-9._:-]{1,160}$/u.test(args[i + 1] ?? '')) recapOf = args[++i];
527
+ else if (arg === '--en') lang = 'en';
462
528
  else if (arg === '--lang' && ['en', 'ko'].includes(args[i + 1])) lang = args[++i];
463
529
  else if (arg === '--here') options.here = true;
464
530
  else if (arg === '--since' && parseSince(args[i + 1])) options.since = args[++i];
@@ -471,7 +537,25 @@ export const runRewindCli = (args, cwd = process.cwd(), { env = process.env, std
471
537
  }
472
538
  }
473
539
  const data = collectRewind(options);
474
- if (json) data.boardText = renderBoard(data, { lang });
475
- stdout.write(json ? `${JSON.stringify(data, null, 2)}\n` : renderRewind(data, { lang, width, detail }));
540
+ const cursorFile = cursorPath(cwd, env);
541
+ const cursor = readCursor(cursorFile);
542
+ if (json) {
543
+ data.boardText = renderBoard(data, { lang });
544
+ data.verdict = renderVerdict(data, { lang, cursor }).verdict;
545
+ stdout.write(`${JSON.stringify(data, null, 2)}\n`);
546
+ return 0;
547
+ }
548
+ if (recap) {
549
+ stdout.write(renderRecap(data, { lang, width, of: recapOf, moved }));
550
+ return 0;
551
+ }
552
+ if (detail) {
553
+ stdout.write(renderRewind(data, { lang, width, detail: true }));
554
+ return 0;
555
+ }
556
+ // The default: the verdict card, then the cursor moves to now, so the next card counts from this look.
557
+ const card = renderVerdict(data, { lang, cursor });
558
+ writeCursor(cursorFile, nextCursor(card.verdict, now));
559
+ stdout.write(card.text);
476
560
  return 0;
477
561
  };
@@ -0,0 +1,250 @@
1
+ // The lit-adhd verdict card: about six lines that answer "what do I do now?" from the collected records alone. A
2
+ // versioned rule table picks ONE verdict, top rule first; the model only prints the card.
3
+ //
4
+ // 1 what changed since the user's last look `18:02 이후: 2개 끝남, 1개가 너를 기다림`
5
+ // 2 the one action and where `지금 할 일: <where> 에서 <action> #<fp>`
6
+ // 3 the exact text to type `입력: \`lit continue\``
7
+ // 4 why, and the cost of not doing it `이유: … · 안 하면: …`
8
+ // 5 the decision queue, at most two `다음 대기: …`
9
+ // 6 coverage `읽음 6/7 세션 — 못 읽음: …`
10
+ //
11
+ // Inputs are evidence-gated. A plan of this folder with every row ticked and a commit are proven done; a conversation
12
+ // that only says it finished is a claim and never counts. Each action carries a fingerprint of the records it rests on
13
+ // and the precondition it needs; when the fingerprint the user last saw no longer holds, the card says it was
14
+ // withdrawn. A push, publish or release is never an action, only `네 확인 필요: <question>`. `지금 할 일 없음` appears
15
+ // only when every source was read. Pure: the cursor file is read and written by the collector CLI.
16
+ import { createHash } from 'node:crypto';
17
+ import { basename } from 'node:path';
18
+ import { clipToWidth } from './gauge.mjs';
19
+
20
+ export const VERDICT_RULES_VERSION = 'adhd-verdict.v1';
21
+ const TEXT_MAX = 64;
22
+
23
+ const LABELS = {
24
+ ko: {
25
+ since: (hhmm) => `${hhmm} 이후`,
26
+ firstLook: '처음 봄 — 기준 없음',
27
+ delta: (done, waiting) => `${done}개 끝남, ${waiting}개가 너를 기다림`,
28
+ nothingChanged: '바뀐 것 없음',
29
+ withdrawn: (fp) => `지난 할 일 #${fp} 철회 — 상태가 바뀜`,
30
+ doNow: '지금 할 일',
31
+ at: (where, action) => (where ? `${where} 에서 ${action}` : action),
32
+ type: '입력',
33
+ noType: (where) => `없음 — ${where ?? '그 창'}에서 직접`,
34
+ waitType: '없음 — 끝날 때까지 기다리기',
35
+ why: '이유',
36
+ ifNot: '안 하면',
37
+ queue: '다음 대기',
38
+ confirm: '네 확인 필요',
39
+ read: (read, found) => `읽음 ${read}/${found} 세션`,
40
+ missing: '못 읽음',
41
+ nothing: (count) => `지금 할 일 없음 — 확인한 기록 ${count}개`,
42
+ unknown: '판단 보류 — 못 읽은 기록이 있음',
43
+ reasons: { budget: '읽기 예산 초과', limit: '최대 개수 초과', unreadable: '읽을 수 없음', transcripts: 'agy 대화 기록 없음', git: 'git 상태' },
44
+ actions: {
45
+ answer: (q) => (q ? `질문에 답하기: ${q}` : '질문에 답하기'),
46
+ resume: (skill) => `멈춘 ${skill} 이어가기`,
47
+ continue: (plan) => `${plan} 이어서 진행`,
48
+ startPlan: (plan) => `${plan} 실행 시작`,
49
+ planItem: (item) => `다음 항목: ${item}`,
50
+ dirty: (count) => `바뀐 파일 ${count}개 확인`,
51
+ wait: (lanes) => `기다리기 — 다른 대화 ${lanes}개 작업 중`,
52
+ },
53
+ why_: {
54
+ answer: '그 대화가 네 답을 기다림',
55
+ resume: '이 대화의 작업이 멈춰 있음',
56
+ continue: '이 대화의 start-work가 진행 중',
57
+ startPlan: '열린 계획이 하나뿐이고 아무것도 안 돌고 있음',
58
+ planItem: '계획에 체크 안 된 항목이 남음',
59
+ dirty: '커밋 안 된 변경이 있음',
60
+ wait: '다른 대화가 같은 곳에서 일하는 중',
61
+ },
62
+ ifNot_: {
63
+ answer: '그 대화가 계속 기다림',
64
+ resume: '멈춘 그대로 남음',
65
+ continue: '남은 항목이 그대로 남음',
66
+ startPlan: '계획이 그대로 남음',
67
+ planItem: '계획이 그대로 남음',
68
+ dirty: '변경이 커밋 안 된 채 남음',
69
+ wait: '없음',
70
+ },
71
+ push: (where, count) => `${where}의 커밋 ${count}개를 push 할까?`,
72
+ stale: (name, days) => `${name} 계획이 ${days}일째 그대로 — 계속할지 닫을지`,
73
+ waitingAt: (where) => `${where} 대화가 답을 기다림`,
74
+ more: (n) => `(+${n})`,
75
+ },
76
+ en: {
77
+ since: (hhmm) => `Since ${hhmm}`,
78
+ firstLook: 'First look — no baseline',
79
+ delta: (done, waiting) => `${done} finished, ${waiting} waiting on you`,
80
+ nothingChanged: 'nothing changed',
81
+ withdrawn: (fp) => `last action #${fp} withdrawn — the state moved`,
82
+ doNow: 'Do now',
83
+ at: (where, action) => (where ? `in ${where}: ${action}` : action),
84
+ type: 'Type',
85
+ noType: (where) => `nothing — answer in ${where ?? 'that window'}`,
86
+ waitType: 'nothing — wait for them to finish',
87
+ why: 'Why',
88
+ ifNot: 'If not',
89
+ queue: 'Next waiting',
90
+ confirm: 'Your call',
91
+ read: (read, found) => `Read ${read}/${found} sessions`,
92
+ missing: 'not read',
93
+ nothing: (count) => `Nothing to do now — ${count} records checked`,
94
+ unknown: 'No verdict — some records were not read',
95
+ reasons: { budget: 'read budget spent', limit: 'over the session cap', unreadable: 'unreadable', transcripts: 'no agy conversation records', git: 'git state' },
96
+ actions: {
97
+ answer: (q) => (q ? `answer: ${q}` : 'answer its question'),
98
+ resume: (skill) => `resume the paused ${skill}`,
99
+ continue: (plan) => `continue ${plan}`,
100
+ startPlan: (plan) => `start ${plan}`,
101
+ planItem: (item) => `next item: ${item}`,
102
+ dirty: (count) => `review ${count} changed file(s)`,
103
+ wait: (lanes) => `wait — ${lanes} other conversation(s) at work`,
104
+ },
105
+ why_: {
106
+ answer: 'that conversation waits for your answer',
107
+ resume: "this conversation's work is paused",
108
+ continue: "this conversation's start-work is running",
109
+ startPlan: 'one open plan and nothing running',
110
+ planItem: 'the plan has unticked rows',
111
+ dirty: 'uncommitted changes',
112
+ wait: 'another conversation works here',
113
+ },
114
+ ifNot_: {
115
+ answer: 'that conversation keeps waiting',
116
+ resume: 'it stays paused',
117
+ continue: 'the open rows stay open',
118
+ startPlan: 'the plan stays as it is',
119
+ planItem: 'the plan stays as it is',
120
+ dirty: 'the changes stay uncommitted',
121
+ wait: 'nothing',
122
+ },
123
+ push: (where, count) => `push ${count} commit(s) in ${where}?`,
124
+ stale: (name, days) => `${name} untouched for ${days} days — keep or close?`,
125
+ waitingAt: (where) => `the conversation in ${where} waits for an answer`,
126
+ more: (n) => `(+${n})`,
127
+ },
128
+ };
129
+
130
+ const placeOf = (worktree) => (worktree && worktree !== 'unknown' ? basename(String(worktree)) : null);
131
+ const short = (text) => clipToWidth(String(text ?? '').replace(/[`*_]/gu, '').replace(/\s+/gu, ' ').trim(), TEXT_MAX);
132
+ const planLabel = (path) => short(basename(String(path ?? 'plan')).replace(/\.md$/u, '').replace(/^\d{4}-\d{2}-\d{2}-/u, ''));
133
+ const lastQuestion = (result) => {
134
+ const text = String(result ?? '');
135
+ const question = text.split(/(?<=[.!??。])\s+|\n+/u).filter((part) => /[??]\s*$/u.test(part)).at(-1);
136
+ return question ? short(question) : null;
137
+ };
138
+ export const fingerprint = (parts) => createHash('sha256').update(JSON.stringify(parts)).digest('hex').slice(0, 6);
139
+
140
+ /** Proven finished items: this folder's plans with every row ticked, and commits. A claim alone never counts. */
141
+ export const provenDone = (data) => [
142
+ ...(data.roadmap?.plans ?? []).filter((p) => p.local && p.progress?.total > 0 && p.progress.done === p.progress.total).map((p) => ({ id: `plan:${p.plan}` })),
143
+ ...(data.commits ?? []).filter((c) => typeof c.hash === 'string').map((c) => ({ id: `commit:${c.hash}` })),
144
+ ];
145
+
146
+ const waitingSessions = (data) => (data.sessions ?? []).filter((s) => !s.self && s.status === 'waiting-on-user' && s.waitingReason !== 'paused workflow');
147
+
148
+ /** Who could not be read. A source the collector could not open counts too. */
149
+ export const coverageOf = (data) => {
150
+ const notRead = data.coverage?.notRead ?? {};
151
+ const missing = [];
152
+ for (const reason of ['budget', 'limit', 'unreadable']) if (notRead[reason] > 0) missing.push({ reason, count: notRead[reason] });
153
+ if (data.sources?.transcripts !== 'ok') missing.push({ reason: 'transcripts', count: null });
154
+ if (data.sources?.git !== 'ok' && !(data.repo ?? []).length) missing.push({ reason: 'git', count: null });
155
+ const read = (data.sessions ?? []).length;
156
+ const skipped = missing.reduce((sum, item) => sum + (item.count ?? 0), 0);
157
+ return { read, found: read + skipped, missing, full: missing.length === 0 };
158
+ };
159
+
160
+ /**
161
+ * The rule table, top first. Each rule returns null or `{ code, kind, where, type, fp, pre, … }`. A change of order or
162
+ * meaning bumps VERDICT_RULES_VERSION and the labelled snapshots in test/fixtures/adhd-verdict/.
163
+ */
164
+ export const RULES = Object.freeze([
165
+ ['answer-session', (data) => {
166
+ const s = waitingSessions(data)[0];
167
+ return s ? { code: 'NEEDS_YOU', kind: 'answer', where: placeOf(s.worktree) ?? s.id8, question: lastQuestion(s.result), type: null, fp: fingerprint(['answer', s.id8, s.last]), pre: "that conversation's last turn asked the user" } : null;
168
+ }],
169
+ ['resume-own-frame', (data) => (data.next?.kind === 'resume-frame' ? { code: 'ONE_ACTION', kind: 'resume', where: null, skill: data.next.target?.skill ?? 'work', type: 'lit continue', fp: fingerprint(['resume', data.next.target]), pre: "this conversation's frame is paused" } : null)],
170
+ ['continue-own-work', (data) => (data.next?.kind === 'continue-work' ? { code: 'ONE_ACTION', kind: 'continue', where: null, plan: planLabel(data.next.target?.plan), type: 'go', fp: fingerprint(['continue', data.next.target]), pre: "this conversation's start-work is active" } : null)],
171
+ ['other-lanes-at-work', (data) => (data.next?.held?.lanes ? { code: 'WAIT', kind: 'wait', where: null, lanes: data.next.held.lanes, type: null, fp: fingerprint(['wait', data.next.held.lanes]), pre: 'another conversation is active here' } : null)],
172
+ ['start-single-plan', (data) => (data.next?.kind === 'start-plan' ? { code: 'ONE_ACTION', kind: 'startPlan', where: null, plan: planLabel(data.next.target?.plan), type: 'go', fp: fingerprint(['start', data.next.target]), pre: 'one open plan, nothing running' } : null)],
173
+ ['uncommitted-work', (data) => {
174
+ const tree = (data.repo ?? []).find((r) => r.uncommitted > 0);
175
+ return tree ? { code: 'ONE_ACTION', kind: 'dirty', where: placeOf(tree.worktree), count: tree.uncommitted, type: 'git status', fp: fingerprint(['dirty', tree.worktree, tree.uncommitted]), pre: 'the worktree has uncommitted changes' } : null;
176
+ }],
177
+ ['next-plan-row', (data) => {
178
+ const plans = data.roadmap?.plans ?? [];
179
+ const plan = plans.find((p) => p.local && p.current) ?? plans.find((p) => p.current);
180
+ return plan ? { code: 'ONE_ACTION', kind: 'planItem', where: plan.local ? null : placeOf(plan.worktree), item: short(plan.current), type: plan.local ? `lit start ${plan.plan}` : null, fp: fingerprint(['row', plan.plan, plan.current]), pre: 'that row is still unticked' } : null;
181
+ }],
182
+ ]);
183
+
184
+ /** The decision queue: what else waits on the user, an irreversible step only as a question. */
185
+ const queueOf = (data, chosen, labels) => {
186
+ const items = [];
187
+ for (const s of waitingSessions(data)) {
188
+ if (chosen?.kind === 'answer' && chosen.fp === fingerprint(['answer', s.id8, s.last])) continue;
189
+ items.push(labels.waitingAt(placeOf(s.worktree) ?? s.id8));
190
+ }
191
+ for (const tree of data.repo ?? []) if (tree.unpushed > 0) items.push(`${labels.confirm}: ${labels.push(placeOf(tree.worktree) ?? 'repo', tree.unpushed)}`);
192
+ for (const plan of [...(data.roadmap?.stale ?? [])].sort((a, b) => b.days - a.days)) items.push(labels.stale(planLabel(plan.plan), plan.days));
193
+ return items;
194
+ };
195
+
196
+ /** The structured verdict: delta, the one action (or nothing / unknown), queue and coverage. */
197
+ export const decideVerdict = (data, { cursor = null } = {}) => {
198
+ const done = provenDone(data);
199
+ const since = cursor && Number.isFinite(Date.parse(cursor.at)) ? Date.parse(cursor.at) : null;
200
+ const seen = new Set(Array.isArray(cursor?.seen) ? cursor.seen : []);
201
+ const newlyDone = since === null ? null : done.filter((item) => !seen.has(item.id)).length;
202
+ const waiting = waitingSessions(data).length;
203
+ let chosen = null;
204
+ let rule = null;
205
+ for (const [name, check] of RULES) {
206
+ chosen = check(data);
207
+ if (chosen) {
208
+ rule = name;
209
+ break;
210
+ }
211
+ }
212
+ const coverage = coverageOf(data);
213
+ const code = chosen?.code ?? (coverage.full ? 'ALL_CLEAR' : 'UNKNOWN');
214
+ const checked = done.length + (data.sessions ?? []).length + (data.roadmap?.plans ?? []).length + (data.repo ?? []).length;
215
+ return { version: VERDICT_RULES_VERSION, code, rule, action: chosen, since, newlyDone, waiting, coverage, checked, done: done.map(({ id }) => id) };
216
+ };
217
+
218
+ const hhmm = (ms) => {
219
+ const d = new Date(ms);
220
+ return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
221
+ };
222
+
223
+ /** The card as text. `lang` is ko (default) or en. */
224
+ export const renderVerdict = (data, { lang = 'ko', cursor = null } = {}) => {
225
+ const labels = LABELS[lang] ?? LABELS.ko;
226
+ const verdict = decideVerdict(data, { cursor });
227
+ const lines = [];
228
+ if (verdict.since === null) lines.push(labels.firstLook);
229
+ else {
230
+ const withdrawn = typeof cursor?.fp === 'string' && /^[0-9a-f]{6}$/u.test(cursor.fp) && cursor.fp !== (verdict.action?.fp ?? null) ? ` · ${labels.withdrawn(cursor.fp)}` : '';
231
+ lines.push(`${labels.since(hhmm(verdict.since))}: ${verdict.newlyDone === 0 && verdict.waiting === 0 ? labels.nothingChanged : labels.delta(verdict.newlyDone, verdict.waiting)}${withdrawn}`);
232
+ }
233
+ const action = verdict.action;
234
+ if (action) {
235
+ const text = labels.actions[action.kind](action.plan ?? action.question ?? action.skill ?? action.item ?? action.count ?? action.lanes);
236
+ lines.push(`${labels.doNow}: ${labels.at(action.where, text)} #${action.fp}`);
237
+ lines.push(`${labels.type}: ${action.type ? `\`${action.type}\`` : action.kind === 'wait' ? labels.waitType : labels.noType(action.where)}`);
238
+ lines.push(`${labels.why}: ${labels.why_[action.kind]} · ${labels.ifNot}: ${labels.ifNot_[action.kind]}`);
239
+ } else {
240
+ lines.push(verdict.code === 'ALL_CLEAR' ? labels.nothing(verdict.checked) : labels.unknown);
241
+ }
242
+ const queue = queueOf(data, action, labels);
243
+ if (queue.length) lines.push(`${labels.queue}: ${queue.slice(0, 2).join(' · ')}${queue.length > 2 ? ` ${labels.more(queue.length - 2)}` : ''}`);
244
+ const { read, found, missing } = verdict.coverage;
245
+ lines.push(`${labels.read(read, found)}${missing.length ? ` — ${labels.missing}: ${missing.map((m) => `${labels.reasons[m.reason]}${m.count ? ` ${m.count}` : ''}`).join(', ')}` : ''}`);
246
+ return { text: `${lines.join('\n')}\n`, verdict };
247
+ };
248
+
249
+ /** The next cursor: when the user looked, which proven items they have now seen, and the action shown. */
250
+ export const nextCursor = (verdict, now) => ({ version: 1, at: new Date(now).toISOString(), seen: verdict.done.slice(0, 500), fp: verdict.action?.fp ?? null });
@@ -8,6 +8,7 @@ export const SKILL_ROUTES = [
8
8
  { id: 'lit-hijack', when: 'port the know-how from someone else\'s published work into your own skill or system, clean-room' },
9
9
  { id: 'lit-plan', when: 'plan before code; the turn writes plans/<slug>.md and nothing else' },
10
10
  { id: 'lit-brainstorm', when: 'open ideation: spread out on options, score a shortlist, hand off' },
11
+ { id: 'ultra-brainstorm', when: 'hundreds of cheap idea agents through run_workflow, then a judged top list to pick from' },
11
12
  { id: 'deep-interview', when: 'the request is vague or broad and needs questions first' },
12
13
  { id: 'lit-crucible', when: 'attack a brief for risks before anyone plans it' },
13
14
  { id: 'start-work', when: 'carry out an approved plan row by row' },
@@ -24,7 +25,6 @@ export const SKILL_ROUTES = [
24
25
  { id: 'wikify', when: 'save findings to, or query, the task wiki under .litgravity/wiki' },
25
26
  { id: 'lit-comprehend', when: 'explain agent-written work so a person can follow it' },
26
27
  { id: 'lit-humanizer', when: 'polish Korean or English prose into the writer\'s own voice' },
27
- { id: 'lit-recap', when: 'where does the work stand (read-only)' },
28
28
  { id: 'lit-handoff', when: 'before stopping or switching conversations' },
29
29
  { id: 'lit-init', when: 'orient in an unfamiliar repository and leave AGENTS.md behind' },
30
30
  { id: 'frontend-ui-ux', when: 'build or restyle a user interface (moved)' },
@@ -38,7 +38,7 @@ export const SKILL_ROUTES = [
38
38
  { id: 'autoresearch', when: 'a budgeted experiment loop against a metric' },
39
39
  { id: 'structural-search', when: 'find or rewrite code by syntax shape' },
40
40
  { id: 'browser-drive', when: 'the answer only exists inside a running web page' },
41
- { id: 'lit-adhd', when: 'cross-session KPI board: the one thing to do now, done and remaining milestones, reminders' },
41
+ { id: 'lit-adhd', when: 'what to do now across sessions, as a short verdict card; `detail` shows the board, `recap` one conversation' },
42
42
  { id: 'lit-team', when: 'two or more child agents behind one durable team packet' },
43
43
  { id: 'autoconference', when: 'a budgeted research conference: parallel researchers, review, synthesis' },
44
44
  { id: 'rules', when: 'which rules, AGENTS.md files and skills agy loads, and in what order' },
@@ -47,6 +47,9 @@ export const SKILL_ROUTES = [
47
47
  ];
48
48
 
49
49
  export const SKILL_IDS = new Set(SKILL_ROUTES.map((r) => r.id));
50
+ // Skills that only read, ask or advise. None of them may arm a goal: only lit-plan's approval question does.
51
+ export const GOAL_NEVER = new Set(['lit-adhd', 'review-work', 'litresearch', 'lit-brainstorm', 'ultra-brainstorm', 'lit-crucible',
52
+ 'deep-interview', 'lit-comprehend', 'lit-handoff', 'lit-init', 'rules', 'lsp', 'comment-checker', 'browser-drive']);
50
53
 
51
54
  // Five content families moved to the separate wjgoarxiv-skills repository. Each id keeps its route and a same-name
52
55
  // pointer stub; the value is the family that holds the skill there. agy installs it from the repository's agy copy,
@@ -91,7 +94,9 @@ export const extensionLines = (id, scope = 'user') => Object.values(extensionSte
91
94
  export const EXTENSIONS_CLI = 'npx @litfamily/litgravity extensions';
92
95
  export const extensionCommand = (id, scope = 'user') => `${EXTENSIONS_CLI} install ${id}${scope === 'project' ? ' --project' : ''} --yes`;
93
96
  // Skill ids that are another name for a skill: typed whole, slashed or after `lit`, they take its route.
94
- export const SKILL_ALIASES = { 'lit-rewind': 'lit-adhd' };
97
+ // `lit-recap` and `litrecap` open lit-adhd's recap view, with a one-line note that the skill moved there.
98
+ export const SKILL_ALIASES = { 'lit-rewind': 'lit-adhd', 'lit-recap': 'lit-adhd', litrecap: 'lit-adhd' };
99
+ export const RECAP_ALIASES = new Set(['lit-recap', 'litrecap']);
95
100
  const skillId = (word) => (SKILL_IDS.has(word) ? word : SKILL_ALIASES[word]);
96
101
 
97
102
  // The word after a leading `lit` picks the route: a word below, or any skill id typed whole (`lit debugging …`,
@@ -108,8 +113,8 @@ export const KEYWORD_ROUTES = {
108
113
  research: 'litresearch',
109
114
  review: 'review-work',
110
115
  start: 'start-work',
111
- recap: 'lit-recap',
112
- status: 'lit-recap',
116
+ recap: 'lit-adhd',
117
+ status: 'lit-adhd',
113
118
  handoff: 'lit-handoff',
114
119
  init: 'lit-init',
115
120
  debug: 'debugging',
@@ -238,6 +243,39 @@ export function frontendIntent(task) {
238
243
  return UI_DESIGN_VERB.test(text) && UI_SURFACE_NOUN.test(text);
239
244
  }
240
245
 
246
+ // Scientific figures and conceptual diagrams have route words only; as companions they are found by intent too.
247
+ const FIGURE_NOUN = /\b(?:plots?|charts?|graphs?|figures?|histograms?|heat\s?maps?)\b|그래프|차트|플롯|히스토그램|그림/iu;
248
+ const FIGURE_VERB = /\b(?:plot|chart|graph|draw|make|create|render|generate|visuali[sz]e)\b|그려|그리|만들|시각화/iu;
249
+ export function figureIntent(task) {
250
+ const text = String(task ?? '');
251
+ return FIGURE_NOUN.test(text) && FIGURE_VERB.test(text) && !SCHEMATIC_STRONG.test(text);
252
+ }
253
+ const DIAGRAM_NOUN = /\b(?:diagrams?|flow\s?charts?|architecture\s+(?:map|diagram|figure)|sequence\s+diagrams?|timelines?)\b|다이어그램|도식|흐름도|구조도/iu;
254
+ export function diagramIntent(task) {
255
+ const text = String(task ?? '');
256
+ return DIAGRAM_NOUN.test(text) && !schematicIntent(text);
257
+ }
258
+
259
+ // Every intent route a task matches, in the router's priority order. The first is the route a `lit <task>` with no
260
+ // route word takes; the rest are companion candidates for the skill plan (skill-plan.mjs).
261
+ export function intentRoutes(task) {
262
+ const found = [];
263
+ if (schematicIntent(task)) found.push('lit-schematic');
264
+ if (motionIntent(task)) found.push('lit-typographic-motion');
265
+ if (deckIntent(task)) found.push('lit-pptx');
266
+ if (frontendIntent(task)) found.push('frontend-ui-ux');
267
+ return found;
268
+ }
269
+ export function companionIntents(task) {
270
+ const found = intentRoutes(task);
271
+ if (figureIntent(task)) found.push('lit-scientific-visualization');
272
+ if (diagramIntent(task)) found.push('lit-diagram-drawer');
273
+ return found;
274
+ }
275
+
276
+ // Skill ids that route when typed first even without `lit` or a slash: names nobody types in ordinary prose.
277
+ const BARE_SKILL_WORDS = new Set(['ultra-brainstorm']);
278
+ const PLAN_HATCH = /^(?:\+[A-Za-z][A-Za-z-]{0,30}(?=$|\s)\s*)+/u;
241
279
  const RESTART_WORDS = new Set(['new', 'restart']);
242
280
  const CONTINUE_WORDS = new Set(['continue', 'resume']);
243
281
  const APPROVE_WORDS = new Set(['approve', 'deny']);
@@ -249,6 +287,21 @@ const firstWord = (s) => (/^([^\s:,.!?]+)/.exec(s)?.[1] ?? '').toLowerCase();
249
287
  // (`lit new` / `lit restart`), `empty` (nothing follows the keyword) and `direct` (a skill id typed as the first word, which is never a continue).
250
288
  // `lit adhd detail` / `lit adhd 자세히` asks for the per-session detail under the board.
251
289
  const ADHD_DETAIL = /(?:^|[\s,.:])(?:detail|details|detailed|자세히|자세하게|상세|상세히)(?=$|[\s,.!?])/iu;
290
+ const ADHD_RECAP = /^(?:recap|리캡|요약)(?=$|[\s,.:!?])/iu;
291
+ // The card is Korean unless the prompt asks for English in so many words; the hook passes the flag, the model never guesses.
292
+ // English only on an explicit ask: `--en` anywhere, `en` / `english` as the whole request after `adhd`, the phrase
293
+ // "in English", or 영어로. A passing mention ("english homework", "the en dash", 영어 공부) stays Korean.
294
+ const ADHD_EN_ANY = /(?:^|\s)--en(?=$|\s)|\bin english\b|영어로/iu;
295
+ const ADHD_EN_ALONE = /^(?:en|english)[.!?]*$/iu;
296
+ const wantsEnglish = (after) => ADHD_EN_ANY.test(after) || ADHD_EN_ALONE.test(after.trim());
297
+ const RECAP_WORDS = new Set(['recap', 'status']);
298
+ // `recap [conversation]`: the recap view, of one conversation when an id (or its first 8 characters) follows.
299
+ function recapOf(hit, after, recap) {
300
+ if (!recap) return;
301
+ hit.recap = true;
302
+ const id = /^[\s:,.]*([A-Za-z0-9][A-Za-z0-9._:-]{3,159})(?=$|\s)/u.exec(after)?.[1];
303
+ if (id && /\d/u.test(id)) hit.recapOf = id;
304
+ }
252
305
 
253
306
  export function detectRoute(prompt) {
254
307
  if (typeof prompt !== 'string') return null;
@@ -264,6 +317,10 @@ export function detectRoute(prompt) {
264
317
  if (lower === 'lit') {
265
318
  if (slash) return null;
266
319
  let rest = text.slice(token.length).replace(SEPARATORS, '');
320
+ // `lit +viz +ui <task>` names the skill plan outright; the words after the `+` names route as usual.
321
+ const hatch = PLAN_HATCH.exec(rest);
322
+ const forced = hatch ? hatch[0].trim().split(/\s+/u).map((w) => w.slice(1).toLowerCase()) : null;
323
+ if (hatch) rest = rest.slice(hatch[0].length).replace(SEPARATORS, '');
267
324
  let word = firstWord(rest);
268
325
  const restart = RESTART_WORDS.has(word);
269
326
  if (restart) {
@@ -276,22 +333,37 @@ export function detectRoute(prompt) {
276
333
  const route = KEYWORD_ROUTES[word] ?? skillId(word);
277
334
  const base = { keyword: route ? word : null, bare, resume, restart, approve: approve ? word : null, direct: false, empty: word === '' || (resume && rest.slice(word.length).trim() === '') };
278
335
  if (!route && !bare && !resume) {
279
- if (schematicIntent(rest)) return { route: 'lit-schematic', ...base, keyword: null };
280
- if (motionIntent(rest)) return { route: 'lit-typographic-motion', ...base, keyword: null };
281
- if (deckIntent(rest)) return { route: 'lit-pptx', ...base, keyword: null };
282
- if (frontendIntent(rest)) return { route: 'frontend-ui-ux', ...base, keyword: null };
336
+ const intent = intentRoutes(rest)[0];
337
+ if (intent) return { route: intent, ...base, keyword: null, task: rest, ...(forced ? { forced } : {}) };
283
338
  }
284
339
  const hit = { route: route ?? 'lit-loop', ...base };
285
- if (hit.route === 'lit-adhd') hit.detail = ADHD_DETAIL.test(rest.slice(word.length));
340
+ const task = rest.slice(route && word ? word.length : 0).replace(SEPARATORS, '');
341
+ if (task) hit.task = task;
342
+ if (forced) hit.forced = forced;
343
+ if (hit.route === 'lit-adhd') {
344
+ const after = rest.slice(word.length).replace(SEPARATORS, '');
345
+ const recap = RECAP_WORDS.has(word) || RECAP_ALIASES.has(word) || ADHD_RECAP.test(after);
346
+ hit.detail = !recap && ADHD_DETAIL.test(rest.slice(word.length));
347
+ recapOf(hit, recap && !RECAP_WORDS.has(word) && !RECAP_ALIASES.has(word) ? after.replace(ADHD_RECAP, '') : after, recap);
348
+ if (RECAP_ALIASES.has(word) || RECAP_WORDS.has(word)) hit.recapMoved = true;
349
+ if (wantsEnglish(rest.slice(word.length).replace(SEPARATORS, ''))) hit.lang = 'en';
350
+ }
286
351
  if (hit.route === 'review-work') {
287
352
  hit.reviewMode = REVIEW_MODES[firstWord(rest.slice(word.length).replace(SEPARATORS, ''))] ?? null;
288
353
  }
289
354
  return hit;
290
355
  }
291
356
  const id = skillId(lower);
292
- if (id && (lower.startsWith('lit') || slash)) {
357
+ if (id && (lower.startsWith('lit') || slash || BARE_SKILL_WORDS.has(lower))) {
293
358
  const hit = { route: id, keyword: null, bare: false, resume: false, restart: false, direct: true, empty: false };
294
- if (id === 'lit-adhd') hit.detail = ADHD_DETAIL.test(text.slice(token.length));
359
+ if (id === 'lit-adhd') {
360
+ const after = text.slice(token.length).replace(SEPARATORS, '');
361
+ const recap = RECAP_ALIASES.has(lower) || ADHD_RECAP.test(after);
362
+ hit.detail = !recap && ADHD_DETAIL.test(text.slice(token.length));
363
+ recapOf(hit, RECAP_ALIASES.has(lower) ? after : after.replace(ADHD_RECAP, ''), recap);
364
+ if (RECAP_ALIASES.has(lower)) hit.recapMoved = true;
365
+ if (wantsEnglish(text.slice(token.length).replace(SEPARATORS, ''))) hit.lang = 'en';
366
+ }
295
367
  return hit;
296
368
  }
297
369
  return null;