@litfamily/litclaude 1.0.35 → 1.0.37
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.
- package/CHANGELOG.md +56 -44
- package/README.md +8 -8
- package/README_ko-KR.md +8 -8
- package/bin/litclaude-ai.js +24 -11
- package/docs/agents.md +5 -0
- package/docs/assets/cover-motion-still.webp +0 -0
- package/docs/assets/cover-motion.webp +0 -0
- package/docs/assets/cover.webp +0 -0
- package/docs/assets/litfamily-machines.png +0 -0
- package/docs/assets/readme/ascii-readme.svg +1 -1
- package/docs/assets/readme/badge-version.svg +1 -1
- package/docs/assets/skills/lit-brainstorm.webp +0 -0
- package/docs/hooks.md +77 -14
- package/docs/migration.md +2 -2
- package/package.json +2 -1
- package/plugins/litclaude/.claude-plugin/icon.png +0 -0
- package/plugins/litclaude/.claude-plugin/plugin.json +1 -1
- package/plugins/litclaude/bin/litclaude-hook.js +164 -15
- package/plugins/litclaude/bin/litclaude-lsp-doctor.js +10 -3
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/commands/deep-interview.md +4 -0
- package/plugins/litclaude/commands/lit-brainstorm.md +108 -0
- package/plugins/litclaude/commands/litgoal.md +1 -1
- package/plugins/litclaude/commands/review-work.md +13 -4
- package/plugins/litclaude/hooks/lit-band-client.mjs +7 -4
- package/plugins/litclaude/hooks/lit-mod.mjs +35 -10
- package/plugins/litclaude/lib/automatic-update.mjs +15 -4
- package/plugins/litclaude/lib/canonical-skill-catalog.mjs +1 -0
- package/plugins/litclaude/lib/canonical-skill-resources.mjs +66 -32
- package/plugins/litclaude/lib/lit-activation.mjs +60 -0
- package/plugins/litclaude/lib/lit-mark.mjs +1 -1
- package/plugins/litclaude/lib/mod/frame.mjs +24 -7
- package/plugins/litclaude/lib/mod/motion.mjs +2 -1
- package/plugins/litclaude/lib/mod/skills.mjs +1 -0
- package/plugins/litclaude/lib/mod/svg-card.mjs +2 -2
- package/plugins/litclaude/lib/mod/timeline.mjs +12 -0
- package/plugins/litclaude/lib/mod/toasts.mjs +89 -0
- package/plugins/litclaude/lib/mod/view.mjs +16 -10
- package/plugins/litclaude/lib/mod/workflow.mjs +1 -0
- package/plugins/litclaude/lib/motion-render-gate.mjs +9 -4
- package/plugins/litclaude/lib/npm-invocation.mjs +64 -0
- package/plugins/litclaude/lib/office-runtime.mjs +40 -14
- package/plugins/litclaude/lib/office_runtime_bootstrap.py +13 -1
- package/plugins/litclaude/lib/rules/engine.mjs +23 -5
- package/plugins/litclaude/lib/start-work-lifecycle.mjs +125 -9
- package/plugins/litclaude/skills/deep-interview/SKILL.md +1 -1
- package/plugins/litclaude/skills/lit-brainstorm/SKILL.md +430 -0
- package/plugins/litclaude/skills/lit-brainstorm/references/idea-lenses.md +192 -0
- package/plugins/litclaude/skills/lit-brainstorm/references/scoring-and-convergence.md +149 -0
- package/plugins/litclaude/skills/lit-brainstorm/references/session-notes-template.md +106 -0
- package/plugins/litclaude/skills/lit-diagram-drawer/scripts/export.mjs +3 -4
- package/plugins/litclaude/skills/lit-diagram-drawer/scripts/renderer.mjs +10 -2
- package/plugins/litclaude/skills/lit-docx/SKILL.md +1 -1
- package/plugins/litclaude/skills/lit-docx/scripts/convert_md_to_pdf.py +23 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/acs/template.tex +14 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/elsevier/template.tex +14 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/ieee/template.tex +14 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/korean-generic/template.tex +14 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/nature/template.tex +14 -0
- package/plugins/litclaude/skills/lit-loop/SKILL.md +11 -0
- package/plugins/litclaude/skills/lit-plan/SKILL.md +2 -1
- package/plugins/litclaude/skills/lit-typographic-motion/SKILL.md +14 -5
- package/plugins/litclaude/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +6 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/core/constants.mjs +35 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/chrome.mjs +3 -7
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-assets.mjs +102 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-capture.mjs +210 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-gate.mjs +346 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-image.mjs +141 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-sheet.mjs +76 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-treatment.mjs +106 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-worker.mjs +32 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover.mjs +373 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/done.mjs +68 -2
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/encode.mjs +3 -5
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/host.mjs +31 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/look.mjs +53 -17
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/runtime.mjs +42 -12
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-capture.mjs +2 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-serve.mjs +6 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage.mjs +2 -2
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/treatment.mjs +2 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/webp.mjs +145 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/cover-init.js +37 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/loop-kit.js +106 -0
- package/plugins/litclaude/skills/lit-typographic-motion/fonts/jetbrains-mono/JetBrainsMono-wght-latin.woff2 +0 -0
- package/plugins/litclaude/skills/lit-typographic-motion/fonts/jetbrains-mono/OFL.txt +93 -0
- package/plugins/litclaude/skills/lit-typographic-motion/fonts/manifest.json +18 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/card-scenes/expected.json +16 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/card-scenes/index.html +27 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/reset-sweep/expected.json +16 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/reset-sweep/index.html +17 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/still-glow/expected.json +17 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/still-glow/index.html +18 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/title-slam/expected.json +17 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/title-slam/index.html +30 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +67 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/orbit-loop/index.html +152 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/painted-light/expected.json +95 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/painted-light/index.html +202 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/weight-tide/expected.json +67 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/weight-tide/index.html +100 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/cover.md +372 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/look.md +2 -1
- package/plugins/litclaude/skills/lit-typographic-motion/references/runtime.md +4 -3
- package/plugins/litclaude/skills/lit-typographic-motion/references/stage.md +1 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/treatment.md +4 -0
- package/plugins/litclaude/skills/lit-typographic-motion/scripts/motion-doctor.mjs +26 -6
- package/plugins/litclaude/skills/lit-typographic-motion/scripts/motion.mjs +43 -10
- package/plugins/litclaude/skills/litgoal/SKILL.md +9 -1
- package/plugins/litclaude/skills/lsp-setup/scripts/verify-lsp.ts +47 -6
- package/plugins/litclaude/skills/review-work/SKILL.md +37 -1
- package/plugins/litclaude/skills/start-work/SKILL.md +5 -0
- package/scripts/doctor.mjs +2 -2
- package/scripts/qa-cover-recipes.mjs +172 -0
- package/scripts/validate-plugin.mjs +12 -2
|
@@ -17,6 +17,12 @@ const fractionOf = (model) => {
|
|
|
17
17
|
// surface counts on between models.
|
|
18
18
|
const stepOf = (model, now) => (model.step ? { name: model.step.name, base: model.step.elapsedMs, at: now } : null);
|
|
19
19
|
|
|
20
|
+
// The lanes' clock, kept the same way: the longest-running lane's time as the model carried it.
|
|
21
|
+
const lanesOf = (model, now) => {
|
|
22
|
+
const times = (model.lanes?.list ?? []).map(({ elapsedMs }) => elapsedMs).filter(Number.isFinite);
|
|
23
|
+
return times.length ? { base: Math.max(...times), at: now } : null;
|
|
24
|
+
};
|
|
25
|
+
|
|
20
26
|
const entryEnd = (profile) => 3 * profile.duration(TIMINGS.stagger) + profile.duration(TIMINGS.entry);
|
|
21
27
|
|
|
22
28
|
// One entry per chip: `at` is the firing the model reported, `arrivedAt` when this timeline saw
|
|
@@ -48,6 +54,7 @@ export const createTimeline = (model, now, profile) => {
|
|
|
48
54
|
done: countOf(model)?.done ?? null,
|
|
49
55
|
flashAt: null,
|
|
50
56
|
step: stepOf(model, now),
|
|
57
|
+
lanes: lanesOf(model, now),
|
|
51
58
|
warn: still(model.ctxWarning ? 1 : 0),
|
|
52
59
|
phases: Object.fromEntries(PHASES.map((id) => [id, { from: model.phases[id], to: model.phases[id], at: now }])),
|
|
53
60
|
notice: model.notice ? { data: model.notice, at: restAt } : null,
|
|
@@ -83,9 +90,13 @@ export const advanceTimeline = (timeline, model, now, profile) => {
|
|
|
83
90
|
next.chips = chipsOf(model, now, timeline.chips);
|
|
84
91
|
next.ambient = ambientOf(model, now, profile, timeline.ambient);
|
|
85
92
|
next.step = stepOf(model, now);
|
|
93
|
+
next.lanes = lanesOf(model, now);
|
|
86
94
|
return next;
|
|
87
95
|
};
|
|
88
96
|
|
|
97
|
+
/** True while the card shows a running clock (the live step or the lanes'); it ticks each second. */
|
|
98
|
+
export const clockShown = (timeline) => timeline.exitAt === null && Boolean(timeline.step || timeline.lanes);
|
|
99
|
+
|
|
89
100
|
/** True while the ambient loop runs; the surface module then keeps a slower frame timer going. */
|
|
90
101
|
export const ambientActive = (timeline, profile) => Boolean(profile.ambient) && timeline.exitAt === null && timeline.ambient.on;
|
|
91
102
|
|
|
@@ -184,6 +195,7 @@ export const sampleTimeline = (timeline, now, profile) => {
|
|
|
184
195
|
chips,
|
|
185
196
|
ambient: ambientSample(timeline, now, profile),
|
|
186
197
|
step: timeline.step ? { name: timeline.step.name, elapsedMs: timeline.step.base + Math.max(0, now - timeline.step.at) } : null,
|
|
198
|
+
lanes: timeline.lanes ? { elapsedMs: timeline.lanes.base + Math.max(0, now - timeline.lanes.at) } : null,
|
|
187
199
|
spin: Math.floor(Math.max(0, now) / TIMINGS.spin) % 4,
|
|
188
200
|
};
|
|
189
201
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The toasts the mod raises when the LIT state really changes: a discipline starts or switches, the
|
|
2
|
+
// workflow stage moves, a goal is set or met, a lane starts or finishes. Pure: the mod keeps the last
|
|
3
|
+
// status it saw and a gate, and hands each new status in; what comes back is at most one short line
|
|
4
|
+
// to show, never more than one per TOAST_GAP_MS. Gate notices (state.mjs gates, the auto-handoff)
|
|
5
|
+
// pass through the same gate as `{ kind: "notice", text }`.
|
|
6
|
+
|
|
7
|
+
import { DISCIPLINE_ENTRY } from "./workflow.mjs";
|
|
8
|
+
|
|
9
|
+
export const TOAST_GAP_MS = 3000;
|
|
10
|
+
// A burst longer than this many lines ends in `+N more`.
|
|
11
|
+
const SHOWN = 3;
|
|
12
|
+
|
|
13
|
+
const cut = (text, cells) => (text.length > cells ? `${text.slice(0, cells - 1)}…` : text);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* What a toast compares: the discipline (sticky: a prompt or skill that names none keeps the last),
|
|
17
|
+
* the current stage, the goal and the running lanes by id. `discipline` is the one the session last
|
|
18
|
+
* lit, `model` the band model, `snapshot` the state snapshot.
|
|
19
|
+
*/
|
|
20
|
+
export const statusOf = ({ discipline, model, snapshot }, previous = null) => {
|
|
21
|
+
const flow = model?.workflow;
|
|
22
|
+
const stage = flow && flow.current >= 0 ? flow.stages[flow.current]?.id ?? null : null;
|
|
23
|
+
const goal = snapshot?.goal;
|
|
24
|
+
return {
|
|
25
|
+
discipline: DISCIPLINE_ENTRY[discipline] ? discipline : previous?.discipline ?? null,
|
|
26
|
+
stage: stage && `${flow.family}:${stage}`,
|
|
27
|
+
goal: goal ? { key: goal.createdAt ?? goal.objective, objective: String(goal.objective ?? ""), status: goal.status, passed: goal.criteria.filter(({ status }) => status === "pass").length, total: goal.criteria.length } : null,
|
|
28
|
+
lanes: Object.fromEntries((model?.lanes?.list ?? []).filter(({ id }) => id).map(({ id, name }) => [id, name])),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const laneEntries = (ids, names, verb) => {
|
|
33
|
+
if (ids.length === 0) return [];
|
|
34
|
+
return [{ kind: `lane-${verb}`, text: ids.length === 1 ? `lane ${verb === "start" ? "started" : "finished"} · ${names[ids[0]]}` : `${ids.length} lanes ${verb === "start" ? "started" : "finished"}` }];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The changes from one status to the next, as toast entries; none for the first status seen. */
|
|
38
|
+
export const statusChanges = (previous, next) => {
|
|
39
|
+
if (!previous) return [];
|
|
40
|
+
const entries = [];
|
|
41
|
+
if (next.discipline && next.discipline !== previous.discipline) entries.push({ kind: "discipline", from: previous.discipline, to: next.discipline });
|
|
42
|
+
else if (next.stage && next.stage !== previous.stage) entries.push({ kind: "stage", text: `stage · ${next.stage.split(":")[1]}` });
|
|
43
|
+
const goal = next.goal;
|
|
44
|
+
const sameGoal = goal && previous.goal?.key === goal.key;
|
|
45
|
+
if (goal && !sameGoal && goal.status !== "complete") entries.push({ kind: "goal", text: `goal set · ${cut(goal.objective, 40)}` });
|
|
46
|
+
if (goal?.status === "complete" && !(sameGoal && previous.goal.status === "complete")) entries.push({ kind: "goal", text: `goal met · ${goal.passed}/${goal.total}` });
|
|
47
|
+
const started = Object.keys(next.lanes).filter((id) => !(id in previous.lanes));
|
|
48
|
+
const finished = Object.keys(previous.lanes).filter((id) => !(id in next.lanes));
|
|
49
|
+
entries.push(...laneEntries(started, next.lanes, "start"), ...laneEntries(finished, previous.lanes, "finish"));
|
|
50
|
+
return entries;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* One line for the entries that waited: a chain of switches shows its two ends (and nothing when it
|
|
55
|
+
* came back where it started), a stage only its newest, repeats once, past SHOWN lines `+N more`.
|
|
56
|
+
* Null when nothing is left to say.
|
|
57
|
+
*/
|
|
58
|
+
export const mergeToasts = (entries) => {
|
|
59
|
+
let switched = null;
|
|
60
|
+
let stage = null;
|
|
61
|
+
const lines = [];
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
if (entry.kind === "discipline") {
|
|
64
|
+
switched = switched ? { ...switched, to: entry.to } : { from: entry.from, to: entry.to, at: lines.length };
|
|
65
|
+
} else if (entry.kind === "stage") {
|
|
66
|
+
stage = { text: entry.text, at: lines.length };
|
|
67
|
+
} else if (!lines.includes(entry.text)) {
|
|
68
|
+
lines.push(entry.text);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (stage) lines.splice(stage.at, 0, stage.text);
|
|
72
|
+
if (switched && switched.from !== switched.to) lines.splice(switched.at, 0, switched.from ? `${switched.from} → ${switched.to}` : `${switched.to} started`);
|
|
73
|
+
if (lines.length === 0) return null;
|
|
74
|
+
const shown = lines.length > SHOWN ? [...lines.slice(0, SHOWN), `+${lines.length - SHOWN} more`] : lines;
|
|
75
|
+
return `🔥 ${shown.join(" · ")}`;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The rate gate: `{ lastAt, pending }`. Entries join what is pending; once TOAST_GAP_MS has passed
|
|
80
|
+
* since the last toast, all of it shows as one line. Otherwise `waitMs` says how long until it may.
|
|
81
|
+
*/
|
|
82
|
+
export const gateToast = (gate, entries, now) => {
|
|
83
|
+
const pending = [...gate.pending, ...entries];
|
|
84
|
+
if (pending.length === 0) return { gate, show: null, waitMs: null };
|
|
85
|
+
const waitMs = gate.lastAt + TOAST_GAP_MS - now;
|
|
86
|
+
if (waitMs > 0) return { gate: { ...gate, pending }, show: null, waitMs };
|
|
87
|
+
const show = mergeToasts(pending);
|
|
88
|
+
return { gate: { lastAt: show ? now : gate.lastAt, pending: [] }, show, waitMs: null };
|
|
89
|
+
};
|
|
@@ -6,8 +6,9 @@ import { AUTOLOOP_LIMITS, GATE_LIMITS } from "./state.mjs";
|
|
|
6
6
|
import { buildWorkflow } from "./workflow.mjs";
|
|
7
7
|
|
|
8
8
|
export const STALL_MS = 10 * 60 * 1000;
|
|
9
|
-
// An agent
|
|
10
|
-
// hold the card at work for the rest of the
|
|
9
|
+
// An agent the host does not list, quiet this long with no call in flight, no longer counts as
|
|
10
|
+
// running: a crashed loop or a lost report must not hold the card at work for the rest of the
|
|
11
|
+
// session. One the host lists as live stays, however quiet; it is marked stalled instead.
|
|
11
12
|
export const AGENT_STALE_MS = 30 * 60 * 1000;
|
|
12
13
|
// The context warning starts this many points before the auto-handoff percent.
|
|
13
14
|
export const CONTEXT_LEAD = 5;
|
|
@@ -49,25 +50,29 @@ export const trackAgents = (activity, agents, previousStatus, now) => {
|
|
|
49
50
|
export const noteAgentActivity = (activity, agentId, now) =>
|
|
50
51
|
activity.first[agentId] === undefined ? activity : { ...activity, last: { ...activity.last, [agentId]: now } };
|
|
51
52
|
|
|
52
|
-
// `spawned` maps an agent id to what `agent.spawn` said of it
|
|
53
|
-
// covers the agents `$.agent.list()` never shows (a
|
|
54
|
-
// list catches up; the agent's own `turn.complete`
|
|
55
|
-
|
|
53
|
+
// `spawned` maps an agent id to what `agent.spawn` said of it, when it was last seen working and
|
|
54
|
+
// how many of its tool calls are in flight. It covers the agents `$.agent.list()` never shows (a
|
|
55
|
+
// workflow script's) and the moment before the list catches up; the agent's own `turn.complete`
|
|
56
|
+
// ends it.
|
|
57
|
+
export const noteSpawn = (spawned, { id, description, type, at }) => ({ ...spawned, [id]: { id, description, type, last: at, calls: 0 } });
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
// `calls` is +1 as one of the agent's tool calls starts, -1 as it returns, 0 for other activity.
|
|
60
|
+
export const noteSpawnActivity = (spawned, id, at, calls = 0) => (spawned[id]
|
|
61
|
+
? { ...spawned, [id]: { ...spawned[id], last: at, calls: Math.max(0, (spawned[id].calls ?? 0) + calls) } }
|
|
62
|
+
: spawned);
|
|
58
63
|
|
|
59
64
|
export const noteSpawnEnded = (spawned, id) => Object.fromEntries(Object.entries(spawned).filter(([key]) => key !== id));
|
|
60
65
|
|
|
61
66
|
// Folds the spawn records into one `$.agent.list()` reading. The list speaks for the agents it shows:
|
|
62
67
|
// a record whose agent it lists as ended is dropped. A record it does not show runs until its
|
|
63
|
-
// `turn.complete`, or until it has been quiet for AGENT_STALE_MS.
|
|
68
|
+
// `turn.complete`, or until it has been quiet for AGENT_STALE_MS with no call in flight.
|
|
64
69
|
export const mergeSpawned = (listed, spawned, now) => {
|
|
65
70
|
const byId = new Map(listed.map((agent) => [agent.id, agent]));
|
|
66
71
|
const kept = {};
|
|
67
72
|
const unlisted = [];
|
|
68
73
|
for (const record of Object.values(spawned)) {
|
|
69
74
|
const row = byId.get(record.id);
|
|
70
|
-
if (row ? ENDED_AGENT.has(row.status) : now - record.last > AGENT_STALE_MS) continue;
|
|
75
|
+
if (row ? ENDED_AGENT.has(row.status) : now - record.last > AGENT_STALE_MS && !(record.calls > 0)) continue;
|
|
71
76
|
kept[record.id] = record;
|
|
72
77
|
if (!row) unlisted.push({ id: record.id, description: record.description, type: record.type, status: "running" });
|
|
73
78
|
}
|
|
@@ -170,12 +175,13 @@ export const buildBandModel = ({ snapshot, agents = [], activity = EMPTY_ACTIVIT
|
|
|
170
175
|
const progress = progressOf(snapshot);
|
|
171
176
|
const completing = completion !== null;
|
|
172
177
|
const phases = phasesOf({ snapshot, discipline, progress, completing });
|
|
173
|
-
const liveAgents = agents.filter((agent) => LIVE_AGENT.has(agent.status)
|
|
178
|
+
const liveAgents = agents.filter((agent) => LIVE_AGENT.has(agent.status));
|
|
174
179
|
const boulderLanes = (snapshot.work?.lanes ?? []).filter(({ status }) => status === "active");
|
|
175
180
|
const stalls = stalledLanes(agents, activity, now);
|
|
176
181
|
const stalledIds = new Set(stalls.map(({ id }) => id));
|
|
177
182
|
const lanes = liveAgents.length > 0
|
|
178
183
|
? liveAgents.slice(0, 6).map((agent) => ({
|
|
184
|
+
id: agent.id,
|
|
179
185
|
name: laneName(agent),
|
|
180
186
|
status: stalledIds.has(agent.id) ? "stalled" : agent.status,
|
|
181
187
|
elapsedMs: Number.isFinite(activity.first[agent.id]) ? now - activity.first[agent.id] : null,
|
|
@@ -47,6 +47,7 @@ export const WORKFLOW_FRESH_MS = 6 * 60 * 60 * 1000;
|
|
|
47
47
|
// Where each discipline enters the map.
|
|
48
48
|
export const DISCIPLINE_ENTRY = Object.freeze({
|
|
49
49
|
"deep-interview": { family: "main", stage: "interview" },
|
|
50
|
+
"lit-brainstorm": { family: "main", stage: "interview" },
|
|
50
51
|
"lit-crucible": { family: "main", stage: "plan" },
|
|
51
52
|
"lit-plan": { family: "main", stage: "plan" },
|
|
52
53
|
"start-work": { family: "main", stage: "work" },
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// A missing, unparsable or outdated treatment.json or look.json is a block with a named reason.
|
|
9
9
|
// Only this hook's own state file fails open. After MOTION_MAX_BLOCKS reminders the hook blocks
|
|
10
10
|
// once more to tell the model to say, in the reply, that the film is not done and why; a blocked
|
|
11
|
-
// environment (exit 10-12, 14, 15) goes straight to that notice. A done film with a downgrade, open
|
|
11
|
+
// environment (exit 10-12, 14, 15, 21, 22) goes straight to that notice. A done film with a downgrade, open
|
|
12
12
|
// look items or no image tool blocks once so the reply says so.
|
|
13
13
|
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { isAbsolute, join, resolve } from "node:path";
|
|
@@ -17,8 +17,8 @@ import { ensureStateDirIgnored, resolveProjectStateRoot } from "./project-state-
|
|
|
17
17
|
|
|
18
18
|
export const MOTION_MAX_BLOCKS = 2;
|
|
19
19
|
export const MOTION_DISCIPLINE = "lit-typographic-motion";
|
|
20
|
-
const COMMAND = /\bmotion\.mjs["']?\s+(stage|make|gate|sound|look|stills|sheet|video|perf)\b([^\n;&|]*)/u;
|
|
21
|
-
const BLOCKED_EXITS = new Set([10, 11, 12, 14, 15]);
|
|
20
|
+
const COMMAND = /\bmotion\.mjs["']?\s+(stage|make|cover-gate|cover|gate|sound|look|stills|sheet|video|perf)\b([^\n;&|]*)/u;
|
|
21
|
+
const BLOCKED_EXITS = new Set([10, 11, 12, 14, 15, 21, 22]);
|
|
22
22
|
const DONE_MODULE = new URL("../skills/lit-typographic-motion/engine/node/done.mjs", import.meta.url);
|
|
23
23
|
|
|
24
24
|
export const motionTurnPath = (cwd = resolveProjectStateRoot()) => join(resolveProjectStateRoot(cwd), ".litclaude", "motion", "turn.json");
|
|
@@ -72,6 +72,8 @@ export function parseMotionCommand(command, workdir) {
|
|
|
72
72
|
const abs = (p) => (p ? (isAbsolute(p) ? p : join(workdir, p)) : null);
|
|
73
73
|
const mode = match[1];
|
|
74
74
|
if (mode === "gate") return { mode, out: abs(positional[0]), brief: null, round: null, stillsOnly: false };
|
|
75
|
+
// cover-gate checks a file; it is not a render, so it never becomes the output the Stop hook judges.
|
|
76
|
+
if (mode === "cover-gate") return { mode, out: null, brief: null, round: null, stillsOnly: false };
|
|
75
77
|
const round = values["--round"] === undefined ? null : Number(values["--round"]);
|
|
76
78
|
return { mode, brief: ["make", "stills", "sheet", "video", "perf"].includes(mode) ? abs(positional[0]) : null, out: abs(values["--out"]), round, stillsOnly };
|
|
77
79
|
}
|
|
@@ -145,6 +147,7 @@ export const evaluateMotionStop = async ({ cwd, sessionId, transcriptPath = null
|
|
|
145
147
|
if (verdict.status === "DONE" || verdict.status === "DONE_UNVIEWED") {
|
|
146
148
|
const say = [
|
|
147
149
|
...(verdict.status === "DONE_UNVIEWED" ? ["nobody viewed the frames (no image tool could be reached)"] : []),
|
|
150
|
+
...(verdict.labels ?? []),
|
|
148
151
|
...verdict.downgraded.map((d) => `downgraded: ${d}`),
|
|
149
152
|
...verdict.openItems.map((o) => `open item: ${o}`),
|
|
150
153
|
];
|
|
@@ -160,6 +163,8 @@ export const evaluateMotionStop = async ({ cwd, sessionId, transcriptPath = null
|
|
|
160
163
|
return {
|
|
161
164
|
action: "block",
|
|
162
165
|
why: "not-done",
|
|
163
|
-
reason:
|
|
166
|
+
reason: verdict.mode === "cover"
|
|
167
|
+
? `lit-typographic-motion (cover mode) is not done: ${verdict.reasons.join("; ")}. Finish the loop in references/cover.md: render the cover, open the sheet, the poster and the seam pair with Read, record the look round, and render again when a gate misses TARGET or a look answer asks for it.`
|
|
168
|
+
: `lit-typographic-motion is not done: ${verdict.reasons.join("; ")}. Finish the loop in references/look.md: render, open every listed still with Read, record the look round, and render again when the gate or a look answer asks for it.`,
|
|
164
169
|
};
|
|
165
170
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// How to start npm on this platform. Since the CVE-2024-27980 fix (Node 18.20.2, 20.12.2, 21.7.3
|
|
2
|
+
// and every 22+), Node refuses to spawn a .cmd or .bat file without a shell (spawnSync EINVAL), and
|
|
3
|
+
// npm on Windows is npm.cmd. When npm itself started us, npm_execpath names its npm-cli.js and this
|
|
4
|
+
// Node runs it with no shell at all. Otherwise the .cmd goes through cmd.exe with every argument
|
|
5
|
+
// quoted; an argument cmd.exe could still reinterpret inside quotes is refused, never passed on.
|
|
6
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
+
import { win32 } from "node:path";
|
|
8
|
+
|
|
9
|
+
const CMD_SAFE = /^[\w@.,:=+/\\-]+$/u;
|
|
10
|
+
const CMD_UNSAFE = /["%\r\n]/u;
|
|
11
|
+
|
|
12
|
+
export const quoteForCmd = (arg) => {
|
|
13
|
+
const text = String(arg);
|
|
14
|
+
if (CMD_UNSAFE.test(text)) throw new Error(`refusing to pass ${JSON.stringify(text)} through cmd.exe`);
|
|
15
|
+
// Trailing backslashes are doubled so the closing quote still ends the argument for node.
|
|
16
|
+
return CMD_SAFE.test(text) ? text : `"${text.replace(/(\\+)$/u, "$1$1")}"`;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** { command, args, shell } for spawn/spawnSync; `command` overrides the default npm binary. */
|
|
20
|
+
export function npmInvocation(args, { command, platform = process.platform, env = process.env, execPath = process.execPath } = {}) {
|
|
21
|
+
if (platform !== "win32") return { command: command ?? "npm", args, shell: false };
|
|
22
|
+
if (!command && /npm-cli\.c?js$/iu.test(env.npm_execpath ?? "")) {
|
|
23
|
+
return { command: execPath, args: [env.npm_execpath, ...args], shell: false };
|
|
24
|
+
}
|
|
25
|
+
const bin = command ?? "npm.cmd";
|
|
26
|
+
if (!/\.(?:cmd|bat)$/iu.test(bin)) return { command: bin, args, shell: false };
|
|
27
|
+
return { command: quoteForCmd(bin), args: args.map(quoteForCmd), shell: true };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const NPM_SHIM_TARGET = /"%~?dp0%?\\([^"\r\n]+)"\s+%\*/gu;
|
|
31
|
+
|
|
32
|
+
const findOnWindowsPath = (name, env, exists) => {
|
|
33
|
+
const extensions = (env.PATHEXT || ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean);
|
|
34
|
+
// npm also writes an extensionless sh script beside each .cmd; Windows never runs it, so a bare
|
|
35
|
+
// name is tried only with the PATHEXT extensions, the way cmd.exe resolves it.
|
|
36
|
+
const names = extensions.some((ext) => name.toLowerCase().endsWith(ext.toLowerCase())) ? [name] : extensions.map((ext) => name + ext);
|
|
37
|
+
if (/[\\/]/u.test(name)) return names.find((file) => exists(file)) ?? null;
|
|
38
|
+
for (const dir of (env.PATH ?? env.Path ?? "").split(";").filter(Boolean)) {
|
|
39
|
+
const found = names.map((file) => win32.join(dir, file)).find((file) => exists(file));
|
|
40
|
+
if (found) return found;
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* { command, args } that run an npm-installed CLI (claude, agent-browser, a language server) with
|
|
47
|
+
* no shell. On Windows npm installs these as .cmd shims, which Node will not spawn without one, so
|
|
48
|
+
* the name is found with PATHEXT and a shim is unwrapped to the script it launches (run with this
|
|
49
|
+
* Node) or the binary. No argument passes through cmd.exe; a .cmd that is not an npm shim throws.
|
|
50
|
+
* A name that is not on PATH comes back unchanged, so the spawn reports ENOENT as before.
|
|
51
|
+
*/
|
|
52
|
+
export function shellFreeCommand(name, args, {
|
|
53
|
+
platform = process.platform, env = process.env, execPath = process.execPath,
|
|
54
|
+
exists = existsSync, read = (file) => readFileSync(file, "utf8"),
|
|
55
|
+
} = {}) {
|
|
56
|
+
if (platform !== "win32") return { command: name, args };
|
|
57
|
+
const found = findOnWindowsPath(name, env, exists);
|
|
58
|
+
if (!found) return { command: name, args };
|
|
59
|
+
if (!/\.(?:cmd|bat)$/iu.test(found)) return { command: found, args };
|
|
60
|
+
const target = [...read(found).matchAll(NPM_SHIM_TARGET)].at(-1)?.[1];
|
|
61
|
+
if (!target) throw new Error(`${found} is not an npm shim and cannot run without a shell; put the program's .exe on PATH instead`);
|
|
62
|
+
const resolved = win32.join(win32.dirname(found), target);
|
|
63
|
+
return /\.[cm]?js$/iu.test(resolved) ? { command: execPath, args: [resolved, ...args] } : { command: resolved, args };
|
|
64
|
+
}
|
|
@@ -26,12 +26,16 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, realpathSync, rmSync
|
|
|
26
26
|
import { homedir } from "node:os";
|
|
27
27
|
import path from "node:path";
|
|
28
28
|
import { fileURLToPath } from "node:url";
|
|
29
|
+
import { npmInvocation } from "./npm-invocation.mjs";
|
|
29
30
|
|
|
30
31
|
const LOCK_DIR = fileURLToPath(new URL("./office-runtime-lock/", import.meta.url));
|
|
31
32
|
const NODE_LOCK_FILES = ["package.json", "package-lock.json"];
|
|
32
33
|
const PYTHON_LOCK_FILE = "requirements.lock";
|
|
33
34
|
const READY = ".litclaude-ready";
|
|
34
35
|
const MIN_PYTHON = [3, 10];
|
|
36
|
+
// The newest CPython every pinned package ships a wheel for (pip runs --only-binary). Raise it
|
|
37
|
+
// with the lock; a newer host Python fails pip on the first package without a wheel (PyYAML).
|
|
38
|
+
const MAX_PYTHON = [3, 14];
|
|
35
39
|
const STALE_LOCK_MS = 20 * 60 * 1000;
|
|
36
40
|
|
|
37
41
|
const HOST_TOOLS = [
|
|
@@ -55,17 +59,34 @@ const npmChildEnv = (env) => Object.fromEntries(Object.entries(env).filter(([key
|
|
|
55
59
|
return !NPM_INSTALL_SHAPE_SETTINGS.has(setting);
|
|
56
60
|
}));
|
|
57
61
|
|
|
58
|
-
export function
|
|
59
|
-
return process.env.LITCLAUDE_OFFICE_PYTHON || "python3";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function probePython(command = pythonCommand()) {
|
|
62
|
+
export function probePython(command) {
|
|
63
63
|
const probe = run(command, ["-c", "import sys; print('%d.%d.%d' % sys.version_info[:3])"]);
|
|
64
|
-
if (probe.error || probe.status !== 0) return { ok: false, command, detail: (probe.stderr || probe.error?.message || "not found").trim() };
|
|
64
|
+
if (probe.error || probe.status !== 0) return { ok: false, command, detail: probe.error?.code === "ENOENT" ? "not found" : (probe.stderr || probe.error?.message || "not found").trim() };
|
|
65
65
|
const version = probe.stdout.trim();
|
|
66
66
|
const [major, minor] = version.split(".").map(Number);
|
|
67
|
-
|
|
68
|
-
return { ok, command, version, detail:
|
|
67
|
+
if (major < MIN_PYTHON[0] || (major === MIN_PYTHON[0] && minor < MIN_PYTHON[1])) return { ok: false, command, version, detail: `${version} is older than ${MIN_PYTHON.join(".")}` };
|
|
68
|
+
if (major > MAX_PYTHON[0] || (major === MAX_PYTHON[0] && minor > MAX_PYTHON[1])) return { ok: false, command, version, detail: `${version} is newer than ${MAX_PYTHON.join(".")}` };
|
|
69
|
+
return { ok: true, command, version, detail: version };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The host Python the runtime venv is built from: $LITCLAUDE_OFFICE_PYTHON when set (and nothing
|
|
74
|
+
* else), otherwise the newest python3.X on PATH within MIN_PYTHON..MAX_PYTHON, then python3 and
|
|
75
|
+
* python. A python3 that is too new for the pinned wheels is passed over, not used.
|
|
76
|
+
*/
|
|
77
|
+
export function pickPython(env = process.env, probe = probePython) {
|
|
78
|
+
if (env.LITCLAUDE_OFFICE_PYTHON) return probe(env.LITCLAUDE_OFFICE_PYTHON);
|
|
79
|
+
const candidates = [];
|
|
80
|
+
for (let minor = MAX_PYTHON[1]; minor >= MIN_PYTHON[1]; minor -= 1) candidates.push(`python3.${minor}`);
|
|
81
|
+
candidates.push("python3", "python");
|
|
82
|
+
const tried = [];
|
|
83
|
+
for (const command of candidates) {
|
|
84
|
+
const found = probe(command);
|
|
85
|
+
if (found.ok) return found;
|
|
86
|
+
if (found.detail !== "not found") tried.push(`${command}: ${found.detail}`);
|
|
87
|
+
}
|
|
88
|
+
const range = `${MIN_PYTHON.join(".")} to ${MAX_PYTHON.join(".")}`;
|
|
89
|
+
return { ok: false, command: "python3", detail: `no supported Python (${range}) on PATH${tried.length ? `; tried ${tried.join(", ")}` : ""}` };
|
|
69
90
|
}
|
|
70
91
|
|
|
71
92
|
function lockDigest(files, extra) {
|
|
@@ -85,7 +106,7 @@ export function nodeRuntimeDir() {
|
|
|
85
106
|
return path.join(runtimeRoot(), `node-${lockDigest(NODE_LOCK_FILES, `${process.platform}-${process.arch}`)}`);
|
|
86
107
|
}
|
|
87
108
|
|
|
88
|
-
export function pythonRuntimeDir(python =
|
|
109
|
+
export function pythonRuntimeDir(python = pickPython()) {
|
|
89
110
|
const minor = python.version ? python.version.split(".").slice(0, 2).join(".") : "none";
|
|
90
111
|
return path.join(runtimeRoot(), `python-${lockDigest([PYTHON_LOCK_FILE], `${process.platform}-${process.arch}-py${minor}`)}`);
|
|
91
112
|
}
|
|
@@ -145,10 +166,11 @@ export function ensureNode() {
|
|
|
145
166
|
for (const file of NODE_LOCK_FILES) copyFileSync(path.join(LOCK_DIR, file), path.join(status.dir, file));
|
|
146
167
|
const pins = Object.entries(status.pinned).map(([name, version]) => `${name} ${version}`).join(", ");
|
|
147
168
|
notice(`LitClaude office runtime: installing pinned Node packages (${pins}) into ${status.dir} — first use only.`);
|
|
148
|
-
const npm =
|
|
149
|
-
const result = run(npm,
|
|
169
|
+
const npm = npmInvocation(["ci", "--omit=dev", "--ignore-scripts", "--no-audit", "--no-fund", "--loglevel=error"]);
|
|
170
|
+
const result = run(npm.command, npm.args, {
|
|
150
171
|
cwd: status.dir,
|
|
151
172
|
stdio: ["ignore", "pipe", "pipe"],
|
|
173
|
+
shell: npm.shell,
|
|
152
174
|
env: npmChildEnv(process.env),
|
|
153
175
|
});
|
|
154
176
|
if (result.error || result.status !== 0) {
|
|
@@ -160,7 +182,7 @@ export function ensureNode() {
|
|
|
160
182
|
}
|
|
161
183
|
|
|
162
184
|
export function pythonStatus() {
|
|
163
|
-
const python =
|
|
185
|
+
const python = pickPython();
|
|
164
186
|
const dir = pythonRuntimeDir(python);
|
|
165
187
|
const ready = python.ok && existsSync(path.join(dir, READY)) && existsSync(venvPython(dir));
|
|
166
188
|
return { ready, dir, interpreter: venvPython(dir), host: python, pinned: pinnedPythonPackages() };
|
|
@@ -170,7 +192,7 @@ export function ensurePython() {
|
|
|
170
192
|
const status = pythonStatus();
|
|
171
193
|
if (status.ready) return status;
|
|
172
194
|
if (!status.host.ok) {
|
|
173
|
-
throw new Error(`OFFICE_RUNTIME_PYTHON_UNAVAILABLE: ${status.host.command}: ${status.host.detail}.
|
|
195
|
+
throw new Error(`OFFICE_RUNTIME_PYTHON_UNAVAILABLE: ${status.host.command}: ${status.host.detail}. Fix: install Python ${MAX_PYTHON.join(".")} (any ${MIN_PYTHON.join(".")} to ${MAX_PYTHON.join(".")} works) or set LITCLAUDE_OFFICE_PYTHON to one.`);
|
|
174
196
|
}
|
|
175
197
|
return withLock(status.dir, () => {
|
|
176
198
|
if (existsSync(path.join(status.dir, READY))) return pythonStatus();
|
|
@@ -196,7 +218,11 @@ export function hostToolStatus() {
|
|
|
196
218
|
return HOST_TOOLS.map(({ id, args, feature }) => {
|
|
197
219
|
const probe = run(id, args, { stdio: ["ignore", "pipe", "pipe"], timeout: 20000 });
|
|
198
220
|
const ok = !probe.error && probe.status === 0;
|
|
199
|
-
const
|
|
221
|
+
const firstLine = (text) => `${text ?? ""}`.trim().split(/\r?\n/u)[0];
|
|
222
|
+
const first = ok ? firstLine(probe.stdout || probe.stderr)
|
|
223
|
+
: probe.error?.code === "ENOENT" ? "not found on PATH"
|
|
224
|
+
: probe.error ? `could not start: ${probe.error.message}`
|
|
225
|
+
: `exited ${probe.status}: ${firstLine(probe.stderr || probe.stdout) || "no output"}`;
|
|
200
226
|
return { id, available: ok, detail: first, feature };
|
|
201
227
|
});
|
|
202
228
|
}
|
|
@@ -58,4 +58,16 @@ def ensure_runtime(modules: list[str]) -> None:
|
|
|
58
58
|
)
|
|
59
59
|
env = dict(os.environ, **{_REEXEC_MARK: "1", "PYTHONDONTWRITEBYTECODE": "1"})
|
|
60
60
|
script = os.path.abspath(sys.argv[0])
|
|
61
|
-
|
|
61
|
+
_reexec([interpreter, script, *sys.argv[1:]], env)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _reexec(argv: list[str], env: dict[str, str], platform: str = os.name) -> None:
|
|
65
|
+
"""Run argv in place of this process and end with its exit code.
|
|
66
|
+
|
|
67
|
+
On Windows os.execve starts the child and ends this process at once with
|
|
68
|
+
status 0, so a caller would read success before the helper had run. There the
|
|
69
|
+
child is awaited and its exit code passed on; POSIX keeps the real exec.
|
|
70
|
+
"""
|
|
71
|
+
if platform == "nt":
|
|
72
|
+
sys.exit(subprocess.call(argv, env=env))
|
|
73
|
+
os.execve(argv[0], argv, env)
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import { createHash } from "node:crypto";
|
|
15
15
|
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, realpathSync } from "node:fs";
|
|
16
|
-
import { isAbsolute, relative, resolve, sep } from "node:path";
|
|
16
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
17
17
|
|
|
18
18
|
import {
|
|
19
19
|
DEFAULT_DYNAMIC_MAX_RESULT_CHARS,
|
|
@@ -27,6 +27,7 @@ import { parseRuleFile } from "./frontmatter.mjs";
|
|
|
27
27
|
import { isStaticRule, matchRule } from "./matcher.mjs";
|
|
28
28
|
import { sortCandidates } from "./ordering.mjs";
|
|
29
29
|
import { claimInjectedKeys, ruleKey } from "./session-state.mjs";
|
|
30
|
+
import { resolveProjectStateRoot } from "../project-state-root.mjs";
|
|
30
31
|
import { pathIdentity, samePathIdentity } from "../secure-path-read.mjs";
|
|
31
32
|
|
|
32
33
|
const MAX_RULE_FILE_BYTES = 256 * 1024;
|
|
@@ -98,15 +99,28 @@ const resolveProjectRoot = (cwd) => {
|
|
|
98
99
|
}
|
|
99
100
|
};
|
|
100
101
|
|
|
101
|
-
const
|
|
102
|
-
|
|
102
|
+
const hasRulesStateDirectory = (root) => {
|
|
103
|
+
try {
|
|
104
|
+
return lstatSync(join(resolveProjectStateRoot(root), ".litclaude", "rules")).isDirectory();
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// Without a project marker the working directory holds the session record, so a rule still reaches
|
|
111
|
+
// the model once per session. SessionStart creates that record; a later lane only joins it, so a
|
|
112
|
+
// prompt in a bare directory writes nothing new. If the record cannot be persisted, the rule is sent rather than lost.
|
|
113
|
+
const claimFormattedBlock = ({ rules, format, projectRoot, fallbackRoot, createFallbackState, sessionId }) => {
|
|
114
|
+
if (sessionId === undefined || (projectRoot === null && fallbackRoot === undefined)) return format(rules).text;
|
|
115
|
+
if (projectRoot === null && !createFallbackState && !hasRulesStateDirectory(fallbackRoot)) return format(rules).text;
|
|
116
|
+
const stateRoot = projectRoot ?? fallbackRoot;
|
|
103
117
|
let remaining = rules;
|
|
104
118
|
while (remaining.length > 0) {
|
|
105
119
|
const formatted = format(remaining);
|
|
106
120
|
if (formatted.text.length === 0 || formatted.emittedRules.length === 0) return "";
|
|
107
121
|
const attempted = new Set(formatted.emittedRules.map(ruleKey));
|
|
108
|
-
const claim = claimInjectedKeys(
|
|
109
|
-
if (!claim.persisted) return "";
|
|
122
|
+
const claim = claimInjectedKeys(stateRoot, sessionId, [...attempted]);
|
|
123
|
+
if (!claim.persisted) return projectRoot === null ? formatted.text : "";
|
|
110
124
|
if (claim.claimed.length > 0) {
|
|
111
125
|
const claimed = new Set(claim.claimed);
|
|
112
126
|
return format(formatted.emittedRules.filter((rule) => claimed.has(ruleKey(rule)))).text;
|
|
@@ -130,6 +144,7 @@ export const staticRulesBlock = ({
|
|
|
130
144
|
maxResultBytes,
|
|
131
145
|
sessionId,
|
|
132
146
|
platform,
|
|
147
|
+
createFallbackState = true,
|
|
133
148
|
} = {}) => {
|
|
134
149
|
try {
|
|
135
150
|
const projectRoot = resolveProjectRoot(cwd ?? process.cwd());
|
|
@@ -142,6 +157,8 @@ export const staticRulesBlock = ({
|
|
|
142
157
|
rules: unique,
|
|
143
158
|
format: (selected) => formatStaticBlock(selected, { maxRuleChars, maxResultChars, maxResultBytes }),
|
|
144
159
|
projectRoot,
|
|
160
|
+
fallbackRoot: resolve(cwd ?? process.cwd()),
|
|
161
|
+
createFallbackState,
|
|
145
162
|
sessionId,
|
|
146
163
|
});
|
|
147
164
|
} catch {
|
|
@@ -206,6 +223,7 @@ export const dynamicRulesBlock = ({
|
|
|
206
223
|
rules: unique,
|
|
207
224
|
format: (selected) => formatDynamicBlock(selected, describedTarget, { maxRuleChars, maxResultChars }),
|
|
208
225
|
projectRoot,
|
|
226
|
+
fallbackRoot: workingDirectory,
|
|
209
227
|
sessionId,
|
|
210
228
|
});
|
|
211
229
|
} catch {
|