@litfamily/litgravity 0.1.11 → 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 (51) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +15 -2
  3. package/README_ko-KR.md +15 -2
  4. package/package.json +1 -1
  5. package/plugin/hooks/lib/goal.mjs +267 -0
  6. package/plugin/hooks/lib/policy.mjs +6 -1
  7. package/plugin/hooks/lib/reentry.mjs +5 -1
  8. package/plugin/hooks/lib/rewind/collect.mjs +98 -14
  9. package/plugin/hooks/lib/rewind/verdict.mjs +250 -0
  10. package/plugin/hooks/lib/routes.mjs +84 -12
  11. package/plugin/hooks/lib/skill-plan.mjs +171 -0
  12. package/plugin/hooks/lib/workflow-stack.mjs +3 -3
  13. package/plugin/hooks/pre-invocation.mjs +65 -9
  14. package/plugin/hooks/session-start.mjs +4 -0
  15. package/plugin/hooks/stop.mjs +11 -0
  16. package/plugin/plugin.json +1 -1
  17. package/plugin/skills/autoconference/SKILL.md +1 -1
  18. package/plugin/skills/autoconference/modes/core.md +1 -1
  19. package/plugin/skills/lit-adhd/SKILL.md +96 -58
  20. package/plugin/skills/lit-adhd/references/board-and-detail.md +48 -0
  21. package/plugin/skills/lit-adhd/references/recap-view.md +59 -0
  22. package/plugin/skills/lit-comprehend/SKILL.md +2 -2
  23. package/plugin/skills/lit-handoff/SKILL.md +2 -2
  24. package/plugin/skills/lit-handoff/evals/evals.json +1 -1
  25. package/plugin/skills/lit-handoff/reference/PROVENANCE.md +1 -1
  26. package/plugin/skills/lit-handoff/scripts/verify-closure.mjs +1 -1
  27. package/plugin/skills/lit-init/SKILL.md +1 -1
  28. package/plugin/skills/lit-loop/SKILL.md +1 -1
  29. package/plugin/skills/lit-plan/SKILL.md +15 -15
  30. package/plugin/skills/lit-plan/references/goal-condition.md +78 -0
  31. package/plugin/skills/lit-plan/references/risk-and-recovery.md +1 -1
  32. package/plugin/skills/lit-plan/scripts/goal-propose.mjs +18 -0
  33. package/plugin/skills/lit-plan/templates/plan.md +4 -1
  34. package/plugin/skills/lit-team/SKILL.md +37 -21
  35. package/plugin/skills/lit-team/references/team-orchestration.md +3 -3
  36. package/plugin/skills/litgoal/SKILL.md +8 -8
  37. package/plugin/skills/litgoal/references/host-goal-binding.md +30 -22
  38. package/plugin/skills/litwork/SKILL.md +2 -2
  39. package/plugin/skills/start-work/SKILL.md +1 -1
  40. package/plugin/skills/start-work/references/admission-and-selection.md +1 -1
  41. package/plugin/skills/start-work/references/final-wave.md +1 -1
  42. package/plugin/skills/ultra-brainstorm/SKILL.md +114 -0
  43. package/plugin/skills/ultra-brainstorm/references/lenses.md +40 -0
  44. package/plugin/skills/ultra-brainstorm/references/workflow-script.md +129 -0
  45. package/plugin/skills/ultra-brainstorm/scripts/estimate.mjs +76 -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 -168
  49. package/plugin/skills/lit-recap/references/recap-shapes.md +0 -166
  50. package/plugin/skills/lit-recap/references/source-reading.md +0 -105
  51. package/plugin/skills/lit-recap/references/stale-state-checks.md +0 -74
@@ -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;
@@ -0,0 +1,171 @@
1
+ // The skill plan of a `lit <task>` prompt. The router still picks one primary route, exactly as before; this module
2
+ // adds the companions: the other intent routes the same task matched, in the router's priority order, without
3
+ // duplicates and capped, plus lit-crucible when the ask is a large or risky design. agy has no skill-loading tool, so
4
+ // the model reads each companion's SKILL.md with read_file when its part of the work starts. `lit +viz +ui <task>`
5
+ // names the plan outright.
6
+ //
7
+ // A moved skill (MOVED_SKILLS) is offered only when its standalone copy is installed for agy, in
8
+ // ~/.gemini/config/skills/<id>/ or the workspace's .agents/skills/<id>/; otherwise the plan names it once with the
9
+ // install command. A read-only primary (lit-adhd, review-work, litresearch, the brainstorms) never gains a companion
10
+ // that writes.
11
+ import { existsSync } from 'node:fs';
12
+ import { homedir } from 'node:os';
13
+ import { join } from 'node:path';
14
+ import { PLUGIN_ROOT } from './common.mjs';
15
+ import { MOVED_SKILLS, SKILL_IDS, SKILL_ROUTES, companionIntents, extensionCommand } from './routes.mjs';
16
+
17
+ export const PLAN_CAP = 3;
18
+
19
+ // `lit +<alias>` names: short words a user can type without looking anything up. Any skill id works too.
20
+ export const PLAN_ALIASES = Object.freeze({
21
+ viz: 'lit-scientific-visualization',
22
+ plot: 'lit-scientific-visualization',
23
+ figure: 'lit-scientific-visualization',
24
+ ui: 'frontend-ui-ux',
25
+ design: 'frontend-ui-ux',
26
+ qa: 'visual-qa',
27
+ crucible: 'lit-crucible',
28
+ plan: 'lit-plan',
29
+ research: 'litresearch',
30
+ review: 'review-work',
31
+ debug: 'debugging',
32
+ deck: 'lit-pptx',
33
+ slides: 'lit-pptx',
34
+ pptx: 'lit-pptx',
35
+ doc: 'lit-docx',
36
+ docx: 'lit-docx',
37
+ diagram: 'lit-diagram-drawer',
38
+ schematic: 'lit-schematic',
39
+ motion: 'lit-typographic-motion',
40
+ video: 'lit-typographic-motion',
41
+ readme: 'readme-studio',
42
+ ast: 'structural-search',
43
+ refactor: 'refactor',
44
+ brainstorm: 'lit-brainstorm',
45
+ ultra: 'ultra-brainstorm',
46
+ humanize: 'lit-humanizer',
47
+ commit: 'lit-commit',
48
+ });
49
+
50
+ // Routes that only read. A plan led by one of these keeps only companions from this set.
51
+ export const READ_ONLY_SKILLS = Object.freeze(new Set(['lit-adhd', 'review-work', 'litresearch', 'lit-brainstorm', 'ultra-brainstorm', 'lit-crucible', 'lit-comprehend']));
52
+ const READ_ONLY_PRIMARIES = new Set(['lit-adhd', 'review-work', 'litresearch', 'lit-brainstorm', 'ultra-brainstorm']);
53
+
54
+ // The skills the catalog may offer, each with its route-table purpose. Moved ones appear only when installed.
55
+ const CATALOG_IDS = ['lit-plan', 'lit-crucible', 'lit-brainstorm', 'ultra-brainstorm', 'litresearch', 'review-work', 'debugging', 'refactor',
56
+ 'structural-search', 'lit-humanizer', 'lit-commit', 'browser-drive', ...Object.keys(MOVED_SKILLS)];
57
+ const WHEN = new Map(SKILL_ROUTES.map((r) => [r.id, r.when.replace(/ \(moved\)$/u, '')]));
58
+
59
+ // Large or risky design asks: lit-crucible joins as the first companion. A request to explain or describe stays out.
60
+ const RISKY_DESIGN = /\b(?:redesign(?:ing)?|re-?architect(?:ure|ing)?|architecture|migrat(?:e|ion|ing)|overhaul(?:ing)?)\b|재설계|설계|아키텍처|마이그레이션|전면\s?개편/iu;
61
+ const EXPLAIN = /\b(?:explain|describe|summari[sz]e|what\s+is)\b|설명|요약/iu;
62
+ const DELIVERABLES = new Set(['lit-pptx', 'lit-docx', 'frontend-ui-ux', 'lit-scientific-visualization', 'lit-diagram-drawer', 'lit-schematic', 'lit-typographic-motion', 'readme-studio']);
63
+
64
+ export const wantsCrucible = (task, ids) => {
65
+ if (EXPLAIN.test(task)) return false;
66
+ return RISKY_DESIGN.test(task) || ids.filter((id) => DELIVERABLES.has(id)).length >= 3;
67
+ };
68
+
69
+ /** Text that only quotes something (a fence, inline code, a quoted span) routes nothing. */
70
+ export const inertStripped = (text) => String(text ?? '')
71
+ .replace(/```[\s\S]*?(?:```|$)/gu, ' ')
72
+ .replace(/`[^`\n]*`/gu, ' ')
73
+ .replace(/"[^"\n]*"|“[^”\n]*”|'[^'\n]{3,}'|「[^」\n]*」/gu, ' ');
74
+
75
+ /** Where agy would load an installed standalone copy of a moved skill from, or null. */
76
+ export const installedCopy = (id, { env = process.env, workspace = null } = {}) => {
77
+ const home = env.HOME || homedir();
78
+ const candidates = [
79
+ ...(workspace ? [join(workspace, '.agents', 'skills', id, 'SKILL.md')] : []),
80
+ join(home, '.gemini', 'config', 'skills', id, 'SKILL.md'),
81
+ ];
82
+ return candidates.find((path) => existsSync(path)) ?? null;
83
+ };
84
+
85
+ /** `+viz +ui` → skill ids in the user's order, plus the names nothing knows. */
86
+ export const resolveForced = (names) => {
87
+ const skills = [];
88
+ const unknown = [];
89
+ for (const name of names ?? []) {
90
+ const id = PLAN_ALIASES[name] ?? (SKILL_IDS.has(name) ? name : null);
91
+ if (!id) unknown.push(name);
92
+ else if (!skills.includes(id)) skills.push(id);
93
+ }
94
+ return { skills, unknown };
95
+ };
96
+
97
+ /**
98
+ * The ordered plan for a routed hit, or null when the plan is the primary alone (an ordinary prompt's activation
99
+ * stays exactly as it was). `hit.task` is the task text, `hit.forced` the `+name` words.
100
+ */
101
+ export const buildSkillPlan = (hit, { env = process.env, workspace = null } = {}) => {
102
+ const primary = hit?.route;
103
+ if (typeof primary !== 'string' || !primary) return null;
104
+ const forced = Array.isArray(hit.forced) ? resolveForced(hit.forced) : null;
105
+ const task = inertStripped(hit.task ?? '');
106
+ const readOnly = READ_ONLY_PRIMARIES.has(primary);
107
+ const dropped = [];
108
+ let picked;
109
+ if (forced) {
110
+ picked = forced.skills.filter((id) => id !== primary);
111
+ } else {
112
+ picked = companionIntents(task).filter((id) => id !== primary);
113
+ if (!readOnly && primary !== 'lit-crucible' && wantsCrucible(`${hit.keyword ?? ''} ${task}`, [primary, ...picked])) picked.unshift('lit-crucible');
114
+ }
115
+ picked = [...new Set(picked)].filter((id) => {
116
+ if (readOnly && !READ_ONLY_SKILLS.has(id)) {
117
+ dropped.push({ id, why: `${primary} is read-only` });
118
+ return false;
119
+ }
120
+ return true;
121
+ });
122
+ for (const id of picked.slice(PLAN_CAP - 1)) dropped.push({ id, why: 'over the cap of 3' });
123
+ picked = picked.slice(0, PLAN_CAP - 1);
124
+ if (picked.length === 0 && !forced) return null;
125
+ const entries = [primary, ...picked].map((id) => {
126
+ const moved = Boolean(MOVED_SKILLS[id]);
127
+ const copy = moved ? installedCopy(id, { env, workspace }) : null;
128
+ return { id, moved, family: MOVED_SKILLS[id] ?? null, path: moved ? copy : join(PLUGIN_ROOT, 'skills', id, 'SKILL.md'), installed: moved ? Boolean(copy) : true };
129
+ });
130
+ return { entries, dropped, forced: Boolean(forced), unknown: forced?.unknown ?? [], readOnly };
131
+ };
132
+
133
+ const label = (entry, index) => {
134
+ const lead = index === 0 ? ' (primary)' : '';
135
+ if (!entry.moved) return `${entry.id}${lead}`;
136
+ if (entry.installed) return `${entry.id}${lead} (${entry.family} extension)`;
137
+ return `${entry.id}${lead} (not installed: ${extensionCommand(entry.id)})`;
138
+ };
139
+
140
+ /** `Skill plan: 1 lit-loop (primary) → 2 lit-scientific-visualization (figures extension) → 3 …` */
141
+ export const skillPlanLine = (plan) => `Skill plan: ${plan.entries.map((entry, index) => `${index + 1} ${label(entry, index)}`).join(' → ')}`;
142
+
143
+ const catalogLines = (plan, env, workspace) => {
144
+ const inPlan = new Set(plan.entries.map(({ id }) => id));
145
+ return CATALOG_IDS
146
+ .filter((id) => !inPlan.has(id))
147
+ .filter((id) => !plan.readOnly || READ_ONLY_SKILLS.has(id))
148
+ .filter((id) => !MOVED_SKILLS[id] || installedCopy(id, { env, workspace }))
149
+ .map((id) => `${id} — ${WHEN.get(id)}`);
150
+ };
151
+
152
+ /** The model-facing block: fixed text around the plan. Nothing from the prompt is echoed. */
153
+ export const skillPlanContext = (plan, { env = process.env, workspace = null } = {}) => {
154
+ const lines = [skillPlanLine(plan)];
155
+ if (plan.forced) {
156
+ lines.push('The user named this plan with `lit +…`: keep it exactly, add nothing and drop nothing.');
157
+ if (plan.unknown.length) lines.push(`Ignored unknown plan names: ${plan.unknown.map((name) => `+${name}`).join(' ')}.`);
158
+ } else {
159
+ lines.push('The companions after the primary are candidates the router matched, not orders: confirm or drop each one for this request, and add at most one skill from the catalog below when the work clearly needs it.');
160
+ }
161
+ for (const { id, why } of plan.dropped) lines.push(`Left out: ${id} (${why}).`);
162
+ lines.push('State the final plan on the line right after the ignition line, in the same `Skill plan: 1 … → 2 …` form. The primary is the skill named above; read each companion\'s SKILL.md with read_file only when its part of the work starts, never all up front. A skill marked not installed is not read: give its install command once and carry on without it.');
163
+ const paths = plan.entries.slice(1).filter((entry) => entry.installed).map((entry) => `${entry.id}: ${entry.path}`);
164
+ if (paths.length) lines.push(`Companion files: ${paths.join('; ')}.`);
165
+ const catalog = plan.forced ? [] : catalogLines(plan, env, workspace);
166
+ if (catalog.length) lines.push(`Catalog (installed here): ${catalog.join('; ')}.`);
167
+ return lines.join('\n');
168
+ };
169
+
170
+ /** The plan's skill ids, for the ledger line. */
171
+ export const skillPlanIds = (plan) => (plan ? plan.entries.map(({ id }) => id) : []);
@@ -16,16 +16,16 @@ export const MAX_FRAMES = 3;
16
16
  export const MAX_HISTORY = 20;
17
17
  export const MAX_STACK_BYTES = 64 * 1024;
18
18
  export const STACK_DROP_MS = 24 * 60 * 60 * 1000;
19
- export const READ_ONLY_DISCIPLINES = Object.freeze(['lit-recap', 'lit-comprehend', 'lit-handoff', 'lit-adhd', 'lit-rewind']);
19
+ export const READ_ONLY_DISCIPLINES = Object.freeze(['lit-comprehend', 'lit-handoff', 'lit-adhd', 'lit-rewind']);
20
20
 
21
21
  // The main-chain stage families and entry points; a newcomer of a higher rank succeeds the frame below.
22
22
  const CHAIN_RANK = Object.freeze({
23
- 'deep-interview': 0, 'lit-brainstorm': 0, 'lit-crucible': 1, 'lit-plan': 1,
23
+ 'deep-interview': 0, 'lit-brainstorm': 0, 'ultra-brainstorm': 0, 'lit-crucible': 1, 'lit-plan': 1,
24
24
  'start-work': 2, litwork: 2, litgoal: 2, autoresearch: 2, 'lit-loop': 2, 'review-work': 3,
25
25
  });
26
26
 
27
27
  const DISCIPLINE_FAMILY = {
28
- 'deep-interview': 'main', 'lit-brainstorm': 'main', 'lit-crucible': 'main', 'lit-plan': 'main',
28
+ 'deep-interview': 'main', 'lit-brainstorm': 'main', 'ultra-brainstorm': 'main', 'lit-crucible': 'main', 'lit-plan': 'main',
29
29
  'start-work': 'main', litwork: 'main', litgoal: 'main', autoresearch: 'main', 'review-work': 'main',
30
30
  litresearch: 'research', 'lit-loop': 'loop',
31
31
  };