@litfamily/litmuse 0.1.13 → 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 (51) hide show
  1. package/CHANGELOG.md +22 -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/install.mjs +11 -2
  6. package/lib/paths.mjs +1 -0
  7. package/lib/shown.mjs +58 -0
  8. package/lib/stage-card.mjs +4 -12
  9. package/package.json +1 -1
  10. package/plugin/.muse-plugin/plugin.json +16 -16
  11. package/plugin/commands/lit-status.md +1 -1
  12. package/plugin/commands/lit.md +6 -5
  13. package/plugin/hooks/lib/goal.mjs +165 -0
  14. package/plugin/hooks/lib/routes.mjs +27 -10
  15. package/plugin/hooks/lib/skill-plan.mjs +199 -0
  16. package/plugin/hooks/lib/stage.mjs +4 -1
  17. package/plugin/hooks/lib/workflow-stack.mjs +1 -1
  18. package/plugin/hooks/post-tool-use.mjs +39 -0
  19. package/plugin/hooks/pre-tool-use.mjs +34 -1
  20. package/plugin/hooks/session-start.mjs +4 -0
  21. package/plugin/hooks/stop.mjs +53 -3
  22. package/plugin/hooks/user-prompt-submit.mjs +161 -9
  23. package/plugin/lib/rewind/collect.mjs +93 -15
  24. package/plugin/lib/rewind/rainbow.mjs +13 -0
  25. package/plugin/lib/rewind/verdict.mjs +258 -0
  26. package/plugin/skills/autoconference/SKILL.md +1 -1
  27. package/plugin/skills/autoconference/modes/core.md +1 -1
  28. package/plugin/skills/browser-drive/scripts/capability-probe.mjs +25 -11
  29. package/plugin/skills/lit-adhd/SKILL.md +56 -32
  30. package/plugin/skills/lit-brainstorm/SKILL.md +1 -0
  31. package/plugin/skills/lit-comprehend/SKILL.md +4 -3
  32. package/plugin/skills/lit-crucible/SKILL.md +1 -0
  33. package/plugin/skills/lit-handoff/SKILL.md +3 -2
  34. package/plugin/skills/lit-init/SKILL.md +1 -1
  35. package/plugin/skills/lit-plan/SKILL.md +8 -4
  36. package/plugin/skills/lit-plan/scripts/goal-propose.mjs +50 -0
  37. package/plugin/skills/lit-plan/templates/plan.md +4 -0
  38. package/plugin/skills/lit-team/SKILL.md +97 -64
  39. package/plugin/skills/lit-team/references/team-orchestration.md +6 -4
  40. package/plugin/skills/litgoal/SKILL.md +3 -1
  41. package/plugin/skills/litresearch/SKILL.md +1 -0
  42. package/plugin/skills/litwork/SKILL.md +6 -6
  43. package/plugin/skills/review-work/SKILL.md +1 -0
  44. package/plugin/skills/start-work/SKILL.md +1 -1
  45. package/plugin/skills/ultra-brainstorm/SKILL.md +107 -0
  46. package/plugin/skills/ultra-brainstorm/references/lenses.md +38 -0
  47. package/plugin/skills/ultra-brainstorm/references/workflow-script.md +169 -0
  48. package/plugin/skills/ultra-brainstorm/scripts/estimate.mjs +57 -0
  49. package/plugin/skills/wikify/SKILL.md +2 -2
  50. package/plugin/skills/wikify/modes/init.md +1 -1
  51. package/plugin/skills/lit-recap/SKILL.md +0 -232
@@ -7,6 +7,7 @@ export const SKILL_ROUTES = [
7
7
  { id: 'litwork', when: 'ship one change with proof: implement, fix, finish' },
8
8
  { id: 'lit-plan', when: 'plan before code; writes plans/<slug>.md only' },
9
9
  { id: 'lit-brainstorm', when: 'open ideation: diverge on options, then score a shortlist and hand off' },
10
+ { id: 'ultra-brainstorm', when: 'wide ideation: hundreds of cheap idea agents, reducers and a judge, then you pick' },
10
11
  { id: 'deep-interview', when: 'the request is vague or broad and needs questions first' },
11
12
  { id: 'lit-crucible', when: 'pressure-test a brief for risks before planning' },
12
13
  { id: 'start-work', when: 'execute an approved plan row by row' },
@@ -23,10 +24,9 @@ export const SKILL_ROUTES = [
23
24
  { id: 'wikify', when: 'save or query findings in the task wiki under .litmuse/wiki' },
24
25
  { id: 'lit-comprehend', when: 'explain agent-written work to a person' },
25
26
  { id: 'lit-humanizer', when: 'polish Korean or English prose into the writer\'s voice' },
26
- { id: 'lit-recap', when: 'where does the work stand (read-only)' },
27
27
  { id: 'lit-handoff', when: 'before stopping or switching sessions' },
28
28
  { id: 'lit-hijack', when: 'port published know-how into your own skill, clean-room' },
29
- { id: 'lit-adhd', when: 'brief every recent session: asked, did, waiting, roadmap, one next step' },
29
+ { id: 'lit-adhd', when: 'what do I do now: one verdict across sessions; `detail` board, `recap` per session (read-only)' },
30
30
  { id: 'lit-init', when: 'orient in an unfamiliar repository; leaves AGENTS.md' },
31
31
  { id: 'frontend-ui-ux', when: 'build or restyle a user interface' },
32
32
  { id: 'readme-studio', when: 'write or refresh a README from repo facts' },
@@ -55,8 +55,8 @@ export const KEYWORD_ROUTES = {
55
55
  research: 'litresearch',
56
56
  review: 'review-work',
57
57
  start: 'start-work',
58
- recap: 'lit-recap',
59
- status: 'lit-recap',
58
+ recap: 'lit-adhd',
59
+ status: 'lit-adhd',
60
60
  handoff: 'lit-handoff',
61
61
  init: 'lit-init',
62
62
  debug: 'debugging',
@@ -72,6 +72,8 @@ export const KEYWORD_ROUTES = {
72
72
  ideate: 'lit-brainstorm',
73
73
  idea: 'lit-brainstorm',
74
74
  ideas: 'lit-brainstorm',
75
+ 'ultra-brainstorm': 'ultra-brainstorm',
76
+ ultra: 'ultra-brainstorm',
75
77
  team: 'lit-team',
76
78
  hijack: 'lit-hijack',
77
79
  hijacking: 'lit-hijack',
@@ -174,13 +176,16 @@ function detectTrailing(prompt) {
174
176
  if (withoutFences.includes('```')) return null;
175
177
  const text = withoutFences.replace(/`[^`\n]*`/g, ' ');
176
178
  if (!TRAILING_LIT.test(text)) return null;
177
- return { route: 'lit-loop', keyword: null, bare: false, resume: false, restart: false, trailing: true };
179
+ return { route: 'lit-loop', keyword: null, bare: false, resume: false, restart: false, trailing: true, task: prompt.replace(/(?:lit|LIT)\s*$/u, '') };
178
180
  }
179
181
 
180
182
  function detectLeading(prompt) {
181
183
  let text = prompt.trimStart();
182
184
  if (text.startsWith('```')) return null;
183
185
  // `/lit <route> <task>` arrives as typed in headless runs; the expanded /lit template starts with a marker line.
186
+ // `/start-work [plans/<f>.md]` (Muse's skill slash) is the same start as `lit start`, so the run record names its plan.
187
+ const startSlash = /^\/(?:litmuse:)?start-work(?=$|\s)/.exec(text);
188
+ if (startSlash) text = `lit start ${text.slice(startSlash[0].length).trimStart()}`;
184
189
  const slash = /^\/(?:litmuse:)?lit(?=$|\s)/.exec(text);
185
190
  const marker = slash ? null : /^LitMuse route request:/.exec(text);
186
191
  if (slash) text = `lit ${text.slice(slash[0].length).trimStart()}`;
@@ -191,6 +196,10 @@ function detectLeading(prompt) {
191
196
  if (/^\/(?:litmuse:)?lit-(?:adhd|rewind)(?=$|\s)/.test(text)) {
192
197
  return { route: 'lit-adhd', keyword: null, bare: false, resume: false, restart: false, trailing: false };
193
198
  }
199
+ // lit-recap moved into lit-adhd: its old names open the recap view with a one-line moved note.
200
+ if (/^\/?(?:litmuse:)?lit-?recap(?=$|[\s:,.!?])/.test(text)) {
201
+ return { route: 'lit-adhd', keyword: 'recap', bare: false, resume: false, restart: false, trailing: false, recap: true, movedFrom: 'lit-recap' };
202
+ }
194
203
  const m = /^([A-Za-z][A-Za-z-]*)(?=$|[\s:,.!?])/.exec(text);
195
204
  if (!m) return null;
196
205
  const token = m[1];
@@ -207,13 +216,21 @@ function detectLeading(prompt) {
207
216
  const resume = !restart && CONTINUE_WORDS.has(word);
208
217
  const bare = !restart && (word === '' || (resume && rest.slice(word.length).trim() === ''));
209
218
  const route = KEYWORD_ROUTES[word];
210
- if (!route && !bare && !resume && schematicIntent(rest)) return { route: 'lit-schematic', keyword: null, bare, resume, restart };
211
- if (!route && !bare && !resume && deckIntent(rest)) return { route: 'lit-pptx', keyword: null, bare, resume, restart };
212
- if (!route && !bare && !resume && motionIntent(rest)) return { route: 'lit-typographic-motion', keyword: null, bare, resume, restart };
213
- if (!route && !bare && !resume && uiBuildIntent(rest)) return { route: 'frontend-ui-ux', keyword: null, bare, resume, restart };
214
- return { route: route ?? 'lit-loop', keyword: route ? word : null, bare, resume, restart };
219
+ const task = route ? rest.slice(word.length).replace(SEPARATORS, '') : rest;
220
+ // `lit recap` / `lit status` open the recap view of lit-adhd; `lit adhd recap [session]` is the same view.
221
+ const recap = (route === 'lit-adhd' && (word === 'recap' || word === 'status')) || (route === 'lit-adhd' && firstWord(task) === 'recap');
222
+ if (!route && !bare && !resume && schematicIntent(rest)) return { route: 'lit-schematic', keyword: null, bare, resume, restart, task };
223
+ if (!route && !bare && !resume && deckIntent(rest)) return { route: 'lit-pptx', keyword: null, bare, resume, restart, task };
224
+ if (!route && !bare && !resume && motionIntent(rest)) return { route: 'lit-typographic-motion', keyword: null, bare, resume, restart, task };
225
+ if (!route && !bare && !resume && uiBuildIntent(rest)) return { route: 'frontend-ui-ux', keyword: null, bare, resume, restart, task };
226
+ const moved = route === 'lit-adhd' && (word === 'recap' || word === 'status') ? { movedFrom: 'lit-recap' } : {};
227
+ return { route: route ?? 'lit-loop', keyword: route ? word : null, bare, resume, restart, task, ...(recap ? { recap: true } : {}), ...moved };
215
228
  }
216
229
  if (lower === 'lit-rewind') return { route: 'lit-adhd', keyword: null, bare: false, resume: false, restart: false, trailing: false };
230
+ if (lower === 'ultra-brainstorm') return { route: 'ultra-brainstorm', keyword: null, bare: false, resume: false, restart: false, task: text.slice(token.length).replace(SEPARATORS, '') };
217
231
  if (lower.startsWith('lit') && SKILL_IDS.has(lower)) return { route: lower, keyword: null, bare: false, resume: false, restart: false };
218
232
  return null;
219
233
  }
234
+
235
+ // The route detectors, for the skill plan's companion list (skill-plan.mjs).
236
+ export const ROUTE_INTENTS = Object.freeze({ schematic: schematicIntent, deck: deckIntent, motion: motionIntent, ui: uiBuildIntent });
@@ -0,0 +1,199 @@
1
+ // The skill plan of a `lit <task>` prompt. The route cascade in routes.mjs still picks ONE primary skill, first match
2
+ // wins; this module lists the other content skills the same task matched, in the cascade's order, without repeats and
3
+ // at most three in all, and adds lit-crucible when the task is a large or risky design ask. The model confirms or drops
4
+ // each companion and states the final plan before it works. `lit +viz +ui <task>` names the plan outright.
5
+ //
6
+ // A moved skill (one of the nine whose bodies live in wjgoarxiv-skills) is offered by its own id only when its Muse
7
+ // edition is installed as a user skill; otherwise the plan names it once with its install line. A read-only primary
8
+ // never gains a companion that can write. Pure apart from `installedCopy`, which checks Muse's user skills folder.
9
+ import { MOVED, movedSkill, installedCopy, installLine } from './moved.mjs';
10
+
11
+ export const PLAN_CAP = 3;
12
+
13
+ // `lit +<alias>` words: short names a user can type without looking anything up.
14
+ export const SKILL_ALIASES = Object.freeze({
15
+ viz: 'lit-scientific-visualization',
16
+ plot: 'lit-scientific-visualization',
17
+ figure: 'lit-scientific-visualization',
18
+ ui: 'frontend-ui-ux',
19
+ design: 'frontend-ui-ux',
20
+ qa: 'visual-qa',
21
+ crucible: 'lit-crucible',
22
+ plan: 'lit-plan',
23
+ research: 'litresearch',
24
+ review: 'review-work',
25
+ debug: 'debugging',
26
+ deck: 'lit-pptx',
27
+ slides: 'lit-pptx',
28
+ doc: 'lit-docx',
29
+ docx: 'lit-docx',
30
+ diagram: 'lit-diagram-drawer',
31
+ schematic: 'lit-schematic',
32
+ motion: 'lit-typographic-motion',
33
+ video: 'lit-typographic-motion',
34
+ readme: 'readme-studio',
35
+ ast: 'structural-search',
36
+ refactor: 'refactor',
37
+ brainstorm: 'lit-brainstorm',
38
+ ultra: 'ultra-brainstorm',
39
+ humanize: 'lit-humanizer',
40
+ commit: 'lit-commit',
41
+ browser: 'browser-drive',
42
+ });
43
+
44
+ // Skills that only read. A plan led by one of these keeps only companions from this set.
45
+ export const READ_ONLY_SKILLS = Object.freeze(new Set(['lit-adhd', 'review-work', 'litresearch', 'lit-brainstorm', 'ultra-brainstorm', 'lit-crucible', 'lit-comprehend']));
46
+ const READ_ONLY_PRIMARIES = new Set(['lit-adhd', 'review-work', 'litresearch', 'lit-brainstorm', 'ultra-brainstorm', 'lit-comprehend', 'lit-handoff']);
47
+
48
+ // One "use when" line per skill the catalog may offer. A moved skill appears only when its copy is installed.
49
+ export const CATALOG = Object.freeze({
50
+ 'lit-plan': 'a decision-complete plan before code',
51
+ 'lit-crucible': 'pressure-test a large or risky design before planning',
52
+ 'lit-brainstorm': 'options for an open question, scored to a short list',
53
+ 'ultra-brainstorm': 'hundreds of cheap idea agents, then a judged top list',
54
+ litresearch: 'prior work and primary sources, with references',
55
+ 'review-work': 'findings-first review of a diff or branch',
56
+ debugging: 'reproduce, localize and fix a failure',
57
+ refactor: 'behaviour-preserving restructure',
58
+ 'structural-search': 'syntax-shaped search or codemod',
59
+ 'lit-humanizer': 'rewrite prose in the writer\'s own voice',
60
+ 'lit-commit': 'commits and git history work',
61
+ 'browser-drive': 'act in a real browser page',
62
+ 'lit-pptx': 'a finished .pptx deck',
63
+ 'lit-docx': 'a finished .docx document',
64
+ 'lit-diagram-drawer': 'a conceptual diagram (architecture, flow, timeline)',
65
+ 'lit-schematic': 'a physical schematic (P&ID, PFD, apparatus, cutaway)',
66
+ 'lit-scientific-visualization': 'a publication figure of measured data',
67
+ 'frontend-ui-ux': 'build or restyle an interface',
68
+ 'visual-qa': 'check a built interface at several widths',
69
+ 'lit-typographic-motion': 'a short kinetic-type film or README cover loop',
70
+ 'readme-studio': 'a factual README with an inspected cover',
71
+ });
72
+
73
+ // `lit +viz +ui <task>`: the named skills in the user's order, the names nobody knows, and the prompt without them.
74
+ const HATCH = /^(\s*\/?(?:litmuse:)?lit)((?:\s+\+[A-Za-z][A-Za-z-]{0,30})+)(?=\s|$)/u;
75
+ export function parseSkillHatch(prompt) {
76
+ const match = HATCH.exec(typeof prompt === 'string' ? prompt : '');
77
+ if (!match) return null;
78
+ const skills = [];
79
+ const unknown = [];
80
+ for (const token of match[2].trim().split(/\s+/u)) {
81
+ const name = token.slice(1).toLowerCase();
82
+ const id = SKILL_ALIASES[name] ?? (Object.hasOwn(CATALOG, name) ? name : null);
83
+ if (!id) unknown.push(name);
84
+ else if (!skills.includes(id)) skills.push(id);
85
+ }
86
+ return { skills: skills.slice(0, PLAN_CAP), extra: skills.slice(PLAN_CAP), unknown, rest: `${match[1]}${prompt.slice(match[0].length)}` };
87
+ }
88
+
89
+ // Companion-only detectors. Neither ever becomes the primary: a chart or diagram word alone must not pull loop work away.
90
+ const VIZ_NOUN = /\b(?:plots?(?!\s+plans?\b)|charts?|graphs?|figures?|histograms?|heat\s?maps?|scatter\s?plots?)\b|그래프|차트|플롯|히스토그램|산점도|시각화/iu;
91
+ const VIZ_CUE = /\b(?:data|dataset|csv|xlsx|measured|measurements?|results?|experiments?|publication|paper|journal|plot|visuali[sz]e)\b|데이터|측정|실험|결과|논문|저널/iu;
92
+ const DIAGRAM_NOUN = /\b(?:diagrams?|flow\s?charts?|sequence\s+diagrams?|architecture\s+(?:diagram|map)|system\s+map)\b|다이어그램|도식|흐름도|구성도|순서도/iu;
93
+ const DRAW_VERB = /\b(?:draw|sketch|make|create|build|render|design|add)\b|그려|그리|만들|작성|넣어/iu;
94
+ const RESEARCH_CUE = /\b(?:prior\s+art|prior\s+work|literature|survey|landscape|state\s+of\s+the\s+art|sources?)\b|선행\s?연구|문헌|조사해|리서치/iu;
95
+ const AST_CUE = /\b(?:ast-grep|codemod|syntax[- ]aware|structural\s+search)\b/iu;
96
+
97
+ // Large or risky design asks: lit-crucible joins as the first companion. A request to explain or describe stays out.
98
+ const RISKY_DESIGN = /\b(?:redesign(?:ing)?|re-?architect(?:ure|ing)?|architecture|migrat(?:e|ion|ing)|overhaul(?:ing)?)\b|설계|아키텍처|마이그레이션|전면\s?개편/iu;
99
+ const EXPLAIN = /\b(?:explain|describe|summari[sz]e|what\s+is)\b|설명|요약/iu;
100
+ const DELIVERABLES = new Set(['lit-pptx', 'lit-docx', 'frontend-ui-ux', 'lit-scientific-visualization', 'lit-diagram-drawer', 'lit-schematic', 'lit-typographic-motion', 'readme-studio']);
101
+
102
+ export function wantsCrucible(task, ids) {
103
+ if (EXPLAIN.test(task)) return false;
104
+ return RISKY_DESIGN.test(task) || ids.filter((id) => DELIVERABLES.has(id)).length >= 3;
105
+ }
106
+
107
+ // Quoted text, code spans and fences are material to work on, never a request: they match nothing.
108
+ export const inertless = (text) => String(text ?? '')
109
+ .replace(/```[\s\S]*?(?:```|$)/gu, ' ')
110
+ .replace(/`[^`\n]*`/gu, ' ')
111
+ .replace(/"[^"\n]*"|“[^”\n]*”|'[^'\n]{3,}'/gu, ' ');
112
+
113
+ /**
114
+ * Every content skill a task matches, in the cascade's order (schematic, deck, film, interface), then the companion-only
115
+ * detectors. `intents` carries the route detectors from routes.mjs so the two files never disagree.
116
+ */
117
+ export function matchedSkills(task, intents) {
118
+ const text = inertless(task);
119
+ const ids = [];
120
+ if (intents.schematic(text)) ids.push('lit-schematic');
121
+ if (intents.deck(text)) ids.push('lit-pptx');
122
+ if (intents.motion(text)) ids.push('lit-typographic-motion');
123
+ if (intents.ui(text)) ids.push('frontend-ui-ux');
124
+ if (VIZ_NOUN.test(text) && VIZ_CUE.test(text)) ids.push('lit-scientific-visualization');
125
+ if (DIAGRAM_NOUN.test(text) && DRAW_VERB.test(text)) ids.push('lit-diagram-drawer');
126
+ if (RESEARCH_CUE.test(text)) ids.push('litresearch');
127
+ if (AST_CUE.test(text)) ids.push('structural-search');
128
+ return [...new Set(ids)];
129
+ }
130
+
131
+ /**
132
+ * The ordered plan: the primary, then companions (or the forced list from `lit +…`). Returns null when the plan is the
133
+ * primary alone, so an ordinary prompt's context stays exactly as it was.
134
+ */
135
+ export function buildSkillPlan({ primary, companions = [], forced = null, task = '', env = process.env }) {
136
+ if (typeof primary !== 'string' || !primary) return null;
137
+ const readOnly = READ_ONLY_PRIMARIES.has(primary);
138
+ const dropped = [];
139
+ let picked = forced ? forced.skills.filter((id) => id !== primary) : companions.filter((id) => id !== primary);
140
+ if (!forced && !readOnly && primary !== 'lit-crucible' && !picked.includes('lit-crucible') && wantsCrucible(inertless(task), [primary, ...picked])) picked.unshift('lit-crucible');
141
+ picked = [...new Set(picked)].filter((id) => {
142
+ if (readOnly && !READ_ONLY_SKILLS.has(id)) {
143
+ dropped.push({ id, why: `${primary} is read-only` });
144
+ return false;
145
+ }
146
+ return true;
147
+ });
148
+ const cap = forced ? PLAN_CAP : PLAN_CAP - 1;
149
+ for (const id of picked.slice(cap)) dropped.push({ id, why: 'over the cap' });
150
+ picked = picked.slice(0, cap);
151
+ if (!picked.length && !forced) return null;
152
+ const entries = [primary, ...picked].map((id) => {
153
+ const moved = movedSkill(id);
154
+ return { id, moved, installed: moved ? installedCopy(moved, env) : true };
155
+ });
156
+ return { entries, dropped, forced: Boolean(forced), unknown: forced?.unknown ?? [], readOnly };
157
+ }
158
+
159
+ function entryLabel(entry, named, first) {
160
+ const lead = first ? ' (primary)' : '';
161
+ if (!entry.moved || entry.installed) return `${entry.id}${lead}`;
162
+ if (named.has(entry.moved.family)) return `${entry.id}${lead} (not installed)`;
163
+ named.add(entry.moved.family);
164
+ return `${entry.id}${lead} (not installed: ${installLine(entry.moved)})`;
165
+ }
166
+
167
+ /** `Skill plan: 1 lit-loop (primary) → 2 lit-scientific-visualization → 3 frontend-ui-ux`. */
168
+ export function skillPlanLine(plan) {
169
+ const named = new Set();
170
+ return `Skill plan: ${plan.entries.map((entry, index) => `${index + 1} ${entryLabel(entry, named, index === 0)}`).join(' → ')}`;
171
+ }
172
+
173
+ /** The skill ids of a plan, bare, for the stage record and the LIT card. */
174
+ export const skillPlanIds = (plan) => (plan ? plan.entries.map(({ id }) => id) : []);
175
+
176
+ function catalogLines(plan, env) {
177
+ const inPlan = new Set(plan.entries.map(({ id }) => id));
178
+ return Object.entries(CATALOG)
179
+ .filter(([id]) => !inPlan.has(id))
180
+ .filter(([id]) => !plan.readOnly || READ_ONLY_SKILLS.has(id))
181
+ .filter(([id]) => !MOVED[id] || installedCopy(movedSkill(id), env))
182
+ .map(([id, use]) => `${id} — ${use}`);
183
+ }
184
+
185
+ /** The model-facing block. Fixed text around the plan; nothing from the prompt is echoed. */
186
+ export function skillPlanContext(plan, env = process.env) {
187
+ const lines = [skillPlanLine(plan)];
188
+ if (plan.forced) {
189
+ lines.push('The user named this plan with `lit +…`: keep it exactly, add nothing and drop nothing.');
190
+ if (plan.unknown.length) lines.push(`Ignored unknown plan names: ${plan.unknown.map((name) => `+${name}`).join(' ')}.`);
191
+ } else {
192
+ lines.push('The companions after the primary are candidates the hook 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.');
193
+ }
194
+ for (const { id, why } of plan.dropped) lines.push(`Left out: ${id} (${why}).`);
195
+ lines.push('State the final plan on the line right after the LIT line, in the same `Skill plan: 1 … → 2 …` form. The primary loads now; load each companion with read_skill when its part of the work starts, never all up front: a LitMuse skill as `plugin:litmuse:<id>`, an installed extension by its bare id. A skill marked not installed is not loaded: give its install line once and carry on without it.');
196
+ const catalog = plan.forced ? [] : catalogLines(plan, env);
197
+ if (catalog.length) lines.push(`Catalog (installed here): ${catalog.join('; ')}.`);
198
+ return `<litmuse-skill-plan>\n${lines.join('\n')}\n</litmuse-skill-plan>`;
199
+ }
@@ -94,7 +94,7 @@ export function updateStage(payload, mutate, env = process.env, { pointer = true
94
94
  }
95
95
  }
96
96
 
97
- export function recordRoute(payload, { route, keyword = null, kind, plan = null, activatedAt = null }, env = process.env) {
97
+ export function recordRoute(payload, { route, keyword = null, kind, plan = null, activatedAt = null, skills = null }, env = process.env) {
98
98
  return updateStage(payload, (rec, now) => {
99
99
  rec.route = route ?? null;
100
100
  rec.keyword = keyword;
@@ -102,6 +102,9 @@ export function recordRoute(payload, { route, keyword = null, kind, plan = null,
102
102
  if (activatedAt !== null) rec.activatedAt = activatedAt ?? now;
103
103
  if (plan !== null) rec.plan = plan;
104
104
  if (kind === 'ignite' && plan === null) delete rec.plan;
105
+ // The skill plan's ids (primary first) when the prompt matched more than one skill.
106
+ if (Array.isArray(skills) && skills.length > 1) rec.skills = skills.slice(0, 3).map(String);
107
+ else if (kind === 'ignite') delete rec.skills;
105
108
  return rec;
106
109
  }, env);
107
110
  }
@@ -15,7 +15,7 @@ export const MAX_FRAMES = 3;
15
15
  export const MAX_HISTORY = 20;
16
16
  export const MAX_STACK_BYTES = 64 * 1024;
17
17
  export const STACK_DROP_MS = 24 * 60 * 60 * 1000;
18
- export const READ_ONLY_DISCIPLINES = Object.freeze(['lit-recap', 'lit-comprehend', 'lit-handoff', 'lit-adhd', 'lit-rewind']);
18
+ export const READ_ONLY_DISCIPLINES = Object.freeze(['lit-comprehend', 'lit-handoff', 'lit-adhd', 'lit-rewind', 'ultra-brainstorm']);
19
19
 
20
20
  // Order in the main chain; a newcomer of a higher rank succeeds the frame below it.
21
21
  const CHAIN_RANK = Object.freeze({
@@ -4,6 +4,8 @@ import { pathToFileURL } from 'node:url';
4
4
  import { run, activeRoute, appendLedger, emitContext, toolName, toolInput, workspaceOf, PLUGIN_ROOT } from './lib/common.mjs';
5
5
  import { extractAddedComments } from './lib/added-comments.mjs';
6
6
  import { markLiveness } from './lib/stage.mjs';
7
+ import { GOAL_STATUS, LIT_TAG, objectiveOf, readGoalRecord, writeGoalRecord } from './lib/goal.mjs';
8
+ import { resolveProjectStateRoot } from './lib/workflow-stack.mjs';
7
9
 
8
10
  const FILE_TOOLS = new Set(['write_file', 'edit_file', 'apply_patch']);
9
11
  const PROSE_FILE = /\.(md|mdx|markdown|txt)$/i;
@@ -83,9 +85,46 @@ async function proseBlock(tool, input, cwd) {
83
85
 
84
86
  run((payload) => {
85
87
  markLiveness(payload, 'alive');
88
+ try { recordGoal(payload); } catch { /* the goal records are best effort; the tool result stands */ }
86
89
  postWrite(payload).catch(() => {});
87
90
  });
88
91
 
92
+ // A successful goal call (failures arrive at PostToolUseFailure instead). `create_goal` with the armed objective makes
93
+ // LitMuse the owner of that goal; `update_goal` complete or blocked closes an owned goal of this session.
94
+ // goal-propose runs in a shell and cannot know its session, so the PostToolUse of that command stamps the asking
95
+ // session on the question it just wrote; only that session's `yes` answers it.
96
+ // (The pattern lives inside the function: run() may call back before a module-level const below it is initialised.)
97
+ function stampConsent(payload) {
98
+ const command = String(toolInput(payload)?.command ?? '');
99
+ if (!payload.session_id || !/(?:^|\s)\S*goal-propose\.mjs\s+plans\/[A-Za-z0-9._-]+\.md\s*$/u.test(command)) return;
100
+ const root = resolveProjectStateRoot(workspaceOf(payload));
101
+ const consent = readGoalRecord(root, 'consent');
102
+ if (!consent || consent.sessionId || consent.answeredAt || Date.now() - Date.parse(consent.askedAt) > 2 * 60_000) return;
103
+ writeGoalRecord(root, 'consent', { ...consent, sessionId: payload.session_id });
104
+ }
105
+
106
+ function recordGoal(payload) {
107
+ const tool = toolName(payload);
108
+ stampConsent(payload);
109
+ if (tool !== 'create_goal' && tool !== 'update_goal') return;
110
+ const root = resolveProjectStateRoot(workspaceOf(payload));
111
+ const input = toolInput(payload);
112
+ const now = new Date().toISOString();
113
+ if (tool === 'create_goal') {
114
+ const objective = objectiveOf(input);
115
+ const intent = readGoalRecord(root, 'intent');
116
+ if (!LIT_TAG.test(objective) || !intent || intent.consumedAt || intent.condition !== objective) return;
117
+ writeGoalRecord(root, 'owner', { version: 1, condition: intent.condition, id: intent.id, plan: intent.plan, check: intent.check, sessionId: payload.session_id ?? null, setAt: now, closed: null });
118
+ writeGoalRecord(root, 'intent', { ...intent, consumedAt: now });
119
+ emitContext('PostToolUse', `Show this line to the user as given: ${GOAL_STATUS.set(intent.id)}`);
120
+ return;
121
+ }
122
+ const owner = readGoalRecord(root, 'owner');
123
+ const status = String(input.status ?? '').toLowerCase();
124
+ if (!owner || owner.closed || owner.sessionId !== (payload.session_id ?? null) || !['complete', 'blocked'].includes(status)) return;
125
+ writeGoalRecord(root, 'owner', { ...owner, closed: { status, at: now } });
126
+ }
127
+
89
128
  async function postWrite(payload) {
90
129
  const state = activeRoute(payload);
91
130
  const tool = toolName(payload);
@@ -3,6 +3,9 @@ import { resolve, dirname, sep, basename } from 'node:path';
3
3
  import { run, block, activeRoute, toolName, toolInput, workspaceOf } from './lib/common.mjs';
4
4
  import { addedHedgeCluster, HEDGE_MESSAGE } from './lib/hedge.mjs';
5
5
  import { LIT_PLAN_READ_ONLY_TOOLS, FILE_TOOLS, SHELL_TOOLS, READ_ONLY_AGENTS, shellReadOnly } from './lib/policy.mjs';
6
+ import { LIT_TAG, objectiveOf, readGoalRecord } from './lib/goal.mjs';
7
+ import { resolveProjectStateRoot } from './lib/workflow-stack.mjs';
8
+ import { PLUGIN_ROOT } from './lib/common.mjs';
6
9
 
7
10
  const PROSE_FILE = /\.(md|mdx|markdown|txt)$/i;
8
11
  const EN_PLEDGE = /\b(never|do not|don't|does not|doesn't|cannot|can't|will not|won't|must not|should not|shouldn't)\b/i;
@@ -113,6 +116,31 @@ function proseWrites(tool, input, cwd) {
113
116
 
114
117
  const PLAN_HINT = 'Write the plan under plans/ with write_file; implementation waits for /start-work.';
115
118
 
119
+ // The one non-read-only command a planning turn may run: this plugin's own goal-propose script on a plan under plans/.
120
+ const GOAL_PROPOSE = resolve(PLUGIN_ROOT, 'skills', 'lit-plan', 'scripts', 'goal-propose.mjs');
121
+ function isGoalPropose(command) {
122
+ const match = /^node\s+(\S+)\s+(plans\/[A-Za-z0-9._-]+\.md)$/u.exec(String(command ?? '').trim());
123
+ if (!match || /[;&|<>`$\\\n\r(){}'"]/u.test(command)) return false;
124
+ try {
125
+ return realpathSync(match[1]) === realpathSync(GOAL_PROPOSE);
126
+ } catch {
127
+ return false;
128
+ }
129
+ }
130
+
131
+ // A goal tagged `[lit:<id>]` exists only after the user's exact yes at plan approval: its objective must equal the armed
132
+ // intent of this session. An untagged goal is the user's own business and passes.
133
+ function litGoalRefusal(payload, input) {
134
+ const objective = objectiveOf(input);
135
+ if (!LIT_TAG.test(objective)) return null;
136
+ let intent = null;
137
+ try {
138
+ intent = readGoalRecord(resolveProjectStateRoot(workspaceOf(payload)), 'intent');
139
+ } catch { /* unreadable reads as no intent */ }
140
+ if (intent && !intent.consumedAt && intent.condition === objective && (!intent.sessionId || intent.sessionId === payload.session_id)) return null;
141
+ return 'LitMuse sets a [lit:…] goal only after the user typed yes to the plan-approval goal question, with that exact objective. Ask the question again (run goal-propose on the plan) instead of creating it.';
142
+ }
143
+
116
144
  run((payload) => {
117
145
  const tool = toolName(payload);
118
146
  const input = toolInput(payload);
@@ -124,6 +152,11 @@ run((payload) => {
124
152
  if (hit) block(`LitMuse keeps route state for its hooks; ${hit} is not writable by tools.`);
125
153
  }
126
154
 
155
+ if (tool === 'create_goal') {
156
+ const refusal = litGoalRefusal(payload, input);
157
+ if (refusal) block(refusal);
158
+ }
159
+
127
160
  const state = activeRoute(payload);
128
161
  if (!state) return;
129
162
 
@@ -132,7 +165,7 @@ run((payload) => {
132
165
  // read-only: allowed
133
166
  } else if (SHELL_TOOLS.has(tool)) {
134
167
  const command = input.command ?? input.cmd ?? input.script;
135
- if (tool === 'bash_input' || !shellReadOnly(command)) {
168
+ if (tool === 'bash_input' || (!shellReadOnly(command) && !isGoalPropose(command))) {
136
169
  block(`LitMuse lit-plan is a planning turn: shell is limited to one plain read-only command (ls, cat, head, tail, wc, rg, git log/status/diff/show) with listed flags and no ; & | < > \` $ or line breaks. Refused: ${tool}. ${PLAN_HINT}`);
137
170
  }
138
171
  } else if (tool === 'subagent_spawn') {
@@ -7,6 +7,8 @@ import { MOVED } from './lib/moved.mjs';
7
7
  import { takeFirstSessionNotice } from './lib/extensions.mjs';
8
8
  import { readFreshSnapshot } from './lib/handoff-snapshot.mjs';
9
9
  import { recordLoadedVersion } from './lib/stage.mjs';
10
+ import { sweepGoalState } from './lib/goal.mjs';
11
+ import { resolveProjectStateRoot } from './lib/workflow-stack.mjs';
10
12
 
11
13
  const STDOUT_BUDGET = 15 * 1024;
12
14
  const STYLE_FILES = { eli5: 'style-eli5.md', 'asd-ste100': 'style-asd-ste100.md' };
@@ -60,6 +62,8 @@ function fenced(text, room) {
60
62
  run((payload) => {
61
63
  const version = pluginVersion();
62
64
  recordLoadedVersion(payload, version);
65
+ // A crashed or abandoned approval leaves a stale goal question or armed intent behind; drop it, silently.
66
+ try { sweepGoalState(resolveProjectStateRoot(workspaceOf(payload))); } catch { /* nothing to sweep */ }
63
67
  const base = readFileSync(join(PLUGIN_ROOT, 'context', 'session.md'), 'utf8').replaceAll('{{version}}', version);
64
68
  const routes = SKILL_ROUTES.map((r) => `- ${r.id}: ${r.when}`).join('\n');
65
69
  const moved = `LitFamily extensions, kept on the wjgoarxiv-skills shelf (each id loads a LitMuse stub that hands over to an installed copy or gives its one-skill install line, and builds nothing itself): ${Object.keys(MOVED).join(', ')}.`;
@@ -1,6 +1,8 @@
1
- import { existsSync, readdirSync, statSync } from 'node:fs';
1
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { run, block, activeRoute, writeSession, workspaceOf } from './lib/common.mjs';
3
+ import { run, block, activeRoute, writeSession, workspaceOf, PLUGIN_ROOT } from './lib/common.mjs';
4
+ import { GOAL_STATUS, readGoalRecord, writeGoalRecord } from './lib/goal.mjs';
5
+ import { resolveProjectStateRoot } from './lib/workflow-stack.mjs';
4
6
  import { continuationHold } from './lib/continuation.mjs';
5
7
  import { putNextStep } from './lib/next-step.mjs';
6
8
  import { markLiveness } from './lib/stage.mjs';
@@ -23,19 +25,67 @@ function planWrittenSince(cwd, since) {
23
25
  return best?.name ?? null;
24
26
  }
25
27
 
28
+ const readText = (path) => {
29
+ try {
30
+ return readFileSync(path, 'utf8');
31
+ } catch {
32
+ return null;
33
+ }
34
+ };
35
+
36
+ // A saved plan with a `## Done when` check needs its goal question before the turn ends: the consent record must name
37
+ // this plan and be newer than it. Returns the hold message, or null.
38
+ function goalQuestionMissing(cwd, saved) {
39
+ const text = readText(join(cwd, saved));
40
+ if (text === null || !/^##\s+Done when\s*$/imu.test(text) || /^goal:\s*never\s*$/mu.test(text)) return null;
41
+ const consent = readGoalRecord(resolveProjectStateRoot(cwd), 'consent');
42
+ if (consent && consent.plan === saved && Date.parse(consent.askedAt) >= statSync(join(cwd, saved)).mtimeMs - 1000) return null;
43
+ return `LitMuse lit-plan gate: ${saved} has a \`## Done when\` block but no goal question yet. Run \`node ${join(PLUGIN_ROOT, 'skills', 'lit-plan', 'scripts', 'goal-propose.mjs')} ${saved}\` once and put the one line it prints into the approval question, then end the turn.`;
44
+ }
45
+
46
+ // At turn end the goal LitMuse owns is checked the only way a 5 s hook can: when every row of its plan is ticked, the
47
+ // session is asked once to run the check and close the goal. Advisory; the model runs the check.
48
+ // Independent of the live route: the goal outlives the prompt that started it. Asked once per turn (owner.askedFor).
49
+ function ownedGoalReady(payload) {
50
+ const cwd = workspaceOf(payload);
51
+ const root = resolveProjectStateRoot(cwd);
52
+ const owner = readGoalRecord(root, 'owner');
53
+ const turn = payload.turn_id ?? 'turn';
54
+ if (!owner || owner.closed || owner.sessionId !== (payload.session_id ?? null) || owner.askedFor === turn) return null;
55
+ const text = readText(join(cwd, String(owner.plan ?? '')));
56
+ if (text === null || /^- \[ \] (?:\d+|F\d+)\. /mu.test(text) || !/^- \[x\] /imu.test(text)) return null;
57
+ writeGoalRecord(root, 'owner', { ...owner, askedFor: turn });
58
+ return `LitMuse goal check [lit:${owner.id}]: every row of ${owner.plan} is ticked. Run \`${owner.check}\` once. When it exits 0, call update_goal with status complete and show: ${GOAL_STATUS.met(owner.id)}. When it fails, say which test failed and keep the goal open.`;
59
+ }
60
+
61
+ const safely = (read) => {
62
+ try {
63
+ return read();
64
+ } catch {
65
+ return null;
66
+ }
67
+ };
68
+
26
69
  // The lit-plan gate holds a turn at most once, so a model that cannot write the plan still ends.
27
70
  run((payload) => {
28
71
  markLiveness(payload, 'idle');
72
+ const goalHold = safely(() => ownedGoalReady(payload));
73
+ if (goalHold) block(goalHold);
29
74
  const state = activeRoute(payload);
30
75
  if (!state) return;
76
+ const turn = payload.turn_id ?? state.turnId ?? 'turn';
31
77
  if (state.route !== 'lit-plan') {
32
78
  continuationHold(payload, state);
33
79
  return;
34
80
  }
35
- const turn = payload.turn_id ?? state.turnId ?? 'turn';
36
81
  const saved = planWrittenSince(workspaceOf(payload), state.activatedAt ?? 0);
37
82
  // A saved plan arms a one-word `go` for this session; the skill's closing line says so.
38
83
  if (saved) {
84
+ const ask = state.stopHeldFor === `goal:${turn}` ? null : safely(() => goalQuestionMissing(workspaceOf(payload), saved));
85
+ if (ask) {
86
+ writeSession(payload, { ...state, stopHeldFor: `goal:${turn}` });
87
+ block(ask);
88
+ }
39
89
  putNextStep(payload, saved);
40
90
  return;
41
91
  }