@litfamily/litclaude 1.0.34 → 1.0.36
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 +59 -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/plugin.json +1 -1
- package/plugins/litclaude/bin/litclaude-hook.js +166 -17
- package/plugins/litclaude/bin/litclaude-lsp-doctor.js +10 -3
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/bundled-rules/lit-humanizer.md +1 -0
- 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 +72 -38
- package/plugins/litclaude/lib/deliverable-hedge-guard.mjs +173 -48
- 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-humanizer/SKILL.md +4 -0
- package/plugins/litclaude/skills/lit-humanizer/scripts/core.mjs +94 -1
- package/plugins/litclaude/skills/lit-humanizer/scripts/detect.mjs +3 -2
- package/plugins/litclaude/skills/lit-humanizer/scripts/scan-input.mjs +15 -2
- 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
|
@@ -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 {
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
writeFileSync,
|
|
17
17
|
} from "node:fs";
|
|
18
18
|
import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
|
|
19
|
+
import { fileURLToPath } from "node:url";
|
|
19
20
|
|
|
20
21
|
import { parsePlanTaskRows } from "./plan-task-rows.mjs";
|
|
21
22
|
import { ensureStateDirIgnored } from "./project-state-root.mjs";
|
|
@@ -788,6 +789,17 @@ const activeWorkForSession = (state, sessionId) => {
|
|
|
788
789
|
return work;
|
|
789
790
|
};
|
|
790
791
|
|
|
792
|
+
// Which work this session is running, for the prompt hook's resume note: id, status and plan only.
|
|
793
|
+
export const activeStartWorkSummary = (root, sessionId) => {
|
|
794
|
+
try {
|
|
795
|
+
const stored = readState(canonicalDirectory(root, "cwd root"), { optional: true });
|
|
796
|
+
const work = activeWorkForSession(stored ? publicState(stored) : null, sessionId);
|
|
797
|
+
return work ? { workId: work.work_id, status: work.status, plan: work.active_plan } : null;
|
|
798
|
+
} catch {
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
};
|
|
802
|
+
|
|
791
803
|
export const startWorkStructuredContext = (root, sessionId, response = null) => {
|
|
792
804
|
let state;
|
|
793
805
|
try {
|
|
@@ -825,6 +837,9 @@ export const startWorkStructuredContext = (root, sessionId, response = null) =>
|
|
|
825
837
|
|
|
826
838
|
const forbiddenShellPattern = /(?:\bgit\b[^\n;&|]*\b(?:commit|push|tag|reset|clean|config)\b|\b(?:npm|pnpm|yarn)\b[^\n;&|]*\b(?:publish|version)\b|\bgh\b[^\n;&|]*\brelease\s+create\b|\bdefaults\s+write\b)/iu;
|
|
827
839
|
const shellRelocationPattern = /(?:^|\s)(?:--prefix|--cwd|--directory|--chdir)(?:=|\s|$)|(?:^|\s)-C(?:\s|$)/u;
|
|
840
|
+
// For grep and rg, `-C <n>` is the context-lines flag, not a change of directory.
|
|
841
|
+
const searchRelocationPattern = /(?:^|\s)(?:--prefix|--cwd|--directory|--chdir)(?:=|\s|$)/u;
|
|
842
|
+
const relocationPatternFor = (segment) => (/^(?:grep|rg)[ \t]/u.test(segment) ? searchRelocationPattern : shellRelocationPattern);
|
|
828
843
|
|
|
829
844
|
const canonicalBashTargets = (cwd, targets, action) => {
|
|
830
845
|
if (targets.some((target) => /[~$*?\[\]{}]/u.test(target))) {
|
|
@@ -848,12 +863,19 @@ const shellWords = (command) => {
|
|
|
848
863
|
const words = [];
|
|
849
864
|
let word = null;
|
|
850
865
|
let quote = null;
|
|
851
|
-
|
|
866
|
+
const chars = [...command];
|
|
867
|
+
for (const [index, ch] of chars.entries()) {
|
|
852
868
|
if (ch === "\n") return null;
|
|
853
869
|
if (quote === "'" || quote === '"') {
|
|
854
870
|
if (ch === quote) quote = null;
|
|
855
|
-
else if (quote === '"' && /[
|
|
856
|
-
else
|
|
871
|
+
else if (quote === '"' && /[$`]/u.test(ch)) return null;
|
|
872
|
+
else if (quote === '"' && ch === "\\") {
|
|
873
|
+
// Inside double quotes a backslash only escapes $ ` " \ and newline; before any other
|
|
874
|
+
// character it is a literal, so a pattern like "a\|b" stays data.
|
|
875
|
+
const next = chars[index + 1];
|
|
876
|
+
if (next === undefined || /[$`"\\\n]/u.test(next)) return null;
|
|
877
|
+
word.text += ch;
|
|
878
|
+
} else word.text += ch;
|
|
857
879
|
continue;
|
|
858
880
|
}
|
|
859
881
|
if (/\s/u.test(ch)) {
|
|
@@ -938,6 +960,33 @@ const classifyNodeScriptWords = (args, cwd) => {
|
|
|
938
960
|
const LITCLAUDE_CLI_NAMES = new Set(["litclaude-ai", "litclaude"]);
|
|
939
961
|
const START_WORK_SELF_MOVES = new Set(["progress", "complete", "cancel"]);
|
|
940
962
|
|
|
963
|
+
// This install's own CLI entry points: the plugin's bin/litclaude-ai that Claude Code puts on PATH,
|
|
964
|
+
// and the package's bin/litclaude-ai.js. A command naming either by path runs code the guard
|
|
965
|
+
// ships, so its lifecycle controls need no grant over the directory the file sits in.
|
|
966
|
+
const TRUSTED_CLI_PATHS = (() => {
|
|
967
|
+
const lib = fileURLToPath(new URL(".", import.meta.url));
|
|
968
|
+
const trusted = new Set();
|
|
969
|
+
for (const candidate of [resolve(lib, "..", "bin", "litclaude-ai"), resolve(lib, "..", "..", "..", "bin", "litclaude-ai.js")]) {
|
|
970
|
+
try {
|
|
971
|
+
trusted.add(realpathSync(candidate));
|
|
972
|
+
} catch {
|
|
973
|
+
// Not part of this layout.
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
return trusted;
|
|
977
|
+
})();
|
|
978
|
+
const isTrustedCliPath = (text, cwd) => {
|
|
979
|
+
if (!text.includes("/")) return false;
|
|
980
|
+
try {
|
|
981
|
+
return TRUSTED_CLI_PATHS.has(realpathSync(resolve(cwd, text)));
|
|
982
|
+
} catch {
|
|
983
|
+
return false;
|
|
984
|
+
}
|
|
985
|
+
};
|
|
986
|
+
// The lifecycle's own controls record start-work state or the LIT card's stage. They grant nothing
|
|
987
|
+
// and write no project file, so a trusted CLI running one is not held to the grants.
|
|
988
|
+
const lifecycleControl = { control: true };
|
|
989
|
+
|
|
941
990
|
// Read-only git: status, diff, log and show over plain words. A flag that writes a file or runs an
|
|
942
991
|
// external program is refused. An operand after `--`, one holding a `/` or one naming an existing
|
|
943
992
|
// file is a path, checked as a read under the grants; other operands (HEAD~1, a commit, main..topic)
|
|
@@ -969,26 +1018,33 @@ const classifyBashWords = (words, cwd) => {
|
|
|
969
1018
|
if (head.text === "grep" || head.text === "rg") return classifySearchWords(head.text, args, cwd);
|
|
970
1019
|
let cli = null;
|
|
971
1020
|
let rest = [];
|
|
972
|
-
|
|
1021
|
+
let trusted = false;
|
|
1022
|
+
if (LITCLAUDE_CLI_NAMES.has(head.text) || isTrustedCliPath(head.text, cwd)) {
|
|
973
1023
|
cli = [];
|
|
1024
|
+
trusted = true;
|
|
974
1025
|
rest = args.map(({ text }) => text);
|
|
1026
|
+
} else if (head.text === "node" && args[0] && isTrustedCliPath(args[0].text, cwd)) {
|
|
1027
|
+
cli = [];
|
|
1028
|
+
trusted = true;
|
|
1029
|
+
rest = args.slice(1).map(({ text }) => text);
|
|
975
1030
|
} else if (head.text === "node" && args[0] && basename(args[0].text) === "litclaude-ai.js") {
|
|
976
1031
|
cli = [args[0].text];
|
|
977
1032
|
rest = args.slice(1).map(({ text }) => text);
|
|
978
1033
|
}
|
|
1034
|
+
const movesLifecycle = (targets, action) => (trusted ? lifecycleControl : canonicalBashTargets(cwd, targets, action));
|
|
979
1035
|
if (cli) {
|
|
980
1036
|
// `start-work status` only reads the lifecycle state; `workflow-stage` writes the LIT card's
|
|
981
1037
|
// small stage record under the project's .litclaude directory.
|
|
982
1038
|
if (rest[0] === "start-work" && rest[1] === "status" && rest.slice(2).every((word) => word === "--json")) {
|
|
983
|
-
return
|
|
1039
|
+
return movesLifecycle(cli, "read");
|
|
984
1040
|
}
|
|
985
1041
|
if (rest[0] === "workflow-stage" && rest.every((word) => !word.includes("/"))) {
|
|
986
|
-
return
|
|
1042
|
+
return movesLifecycle([cwd, ...cli], "write");
|
|
987
1043
|
}
|
|
988
1044
|
// The lifecycle's own moves for the active work write its state under the project's .litclaude
|
|
989
1045
|
// directory. `init` declares grants and `--root` points at another lifecycle, so neither passes.
|
|
990
1046
|
if (rest[0] === "start-work" && START_WORK_SELF_MOVES.has(rest[1]) && !rest.includes("--root") && rest.every((word) => !word.includes("/"))) {
|
|
991
|
-
return
|
|
1047
|
+
return movesLifecycle([cwd, ...cli], "write");
|
|
992
1048
|
}
|
|
993
1049
|
// `pause` is how the work asks the user for a new boundary: it records the pending boundary
|
|
994
1050
|
// and grants nothing, so the root it names may lie outside the grants, and the lifecycle
|
|
@@ -996,20 +1052,74 @@ const classifyBashWords = (words, cwd) => {
|
|
|
996
1052
|
// the bare CLI name passes: a `node <path>/litclaude-ai.js` file is checked by name, not content.
|
|
997
1053
|
if (cli.length === 0 && rest[0] === "start-work" && rest[1] === "pause" && !rest.includes("--root")
|
|
998
1054
|
&& rest.every((word, index) => !word.includes("/") || rest[index - 1] === "--target-root")) {
|
|
999
|
-
return
|
|
1055
|
+
return movesLifecycle([cwd, ...cli], "write");
|
|
1000
1056
|
}
|
|
1001
1057
|
}
|
|
1002
1058
|
if (head.text === "node") return classifyNodeScriptWords(args, cwd);
|
|
1003
1059
|
return null;
|
|
1004
1060
|
};
|
|
1005
1061
|
|
|
1062
|
+
// A plain path word: no quote, expansion, glob, operator or leading dash.
|
|
1063
|
+
const PLAIN_PATH_WORD = /^[\p{L}\p{N}_.\/@+,:=][\p{L}\p{N}_.\/@+,:=-]*$/u;
|
|
1064
|
+
|
|
1065
|
+
// `git -C <dir> status|diff|log|show ...`: the same read-only git, run in another directory. The
|
|
1066
|
+
// directory is a read target and every operand is checked against it. A second -C, a variable or
|
|
1067
|
+
// any other subcommand meets the relocation refusal below.
|
|
1068
|
+
const classifyRelocatedGit = (command, cwd) => {
|
|
1069
|
+
const match = /^git[ \t]+-C[ \t]+(\S+)[ \t]+((?:status|diff|log|show)(?:[ \t].*)?)$/u.exec(command);
|
|
1070
|
+
if (!match) return null;
|
|
1071
|
+
if (!PLAIN_PATH_WORD.test(match[1])) return pathArgumentDenied;
|
|
1072
|
+
const directory = canonicalBashTargets(cwd, [match[1]], "read");
|
|
1073
|
+
if (directory.denied) return directory;
|
|
1074
|
+
return classifyReadOnlyGit(`git ${match[2]}`, directory.targetRoots[0]) ?? pathArgumentDenied;
|
|
1075
|
+
};
|
|
1076
|
+
|
|
1077
|
+
// `cd <dir>`: a read of the directory. It moves the working directory for the commands chained after it.
|
|
1078
|
+
const classifyCd = (command, cwd) => {
|
|
1079
|
+
const match = /^cd[ \t]+(\S+)$/u.exec(command);
|
|
1080
|
+
if (!match) return null;
|
|
1081
|
+
if (!PLAIN_PATH_WORD.test(match[1])) return pathArgumentDenied;
|
|
1082
|
+
const directory = canonicalBashTargets(cwd, [match[1]], "read");
|
|
1083
|
+
if (directory.denied) return directory;
|
|
1084
|
+
try {
|
|
1085
|
+
if (!lstatSync(directory.targetRoots[0]).isDirectory()) return pathArgumentDenied;
|
|
1086
|
+
} catch {
|
|
1087
|
+
return pathArgumentDenied;
|
|
1088
|
+
}
|
|
1089
|
+
return { ...directory, cd: directory.targetRoots[0] };
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
const MAX_CHAIN_SEGMENTS = 4;
|
|
1093
|
+
|
|
1094
|
+
// Commands joined by ` && ` are classified one by one, each in the directory the `cd` before it
|
|
1095
|
+
// left. Every other joiner (`;`, `||`, a pipe, a redirect) stays unverified inside its segment.
|
|
1006
1096
|
const classifyBash = (command, cwd) => {
|
|
1007
1097
|
if (typeof command !== "string" || command.length === 0 || command.length > 32_768) {
|
|
1008
1098
|
return { denied: "unclassified mutating Bash command" };
|
|
1009
1099
|
}
|
|
1010
1100
|
if (forbiddenShellPattern.test(command)) return { denied: "forbidden authority action in Bash command" };
|
|
1011
1101
|
const trimmed = command.trim();
|
|
1012
|
-
|
|
1102
|
+
const segments = trimmed.split(/[ \t]+&&[ \t]+/u);
|
|
1103
|
+
if (segments.length === 1) return classifyBashSegment(trimmed, cwd);
|
|
1104
|
+
if (segments.length > MAX_CHAIN_SEGMENTS) return pathArgumentDenied;
|
|
1105
|
+
const chain = [];
|
|
1106
|
+
let here = cwd;
|
|
1107
|
+
for (const segment of segments) {
|
|
1108
|
+
if (segment.length === 0) return pathArgumentDenied;
|
|
1109
|
+
const classified = classifyBashSegment(segment, here);
|
|
1110
|
+
if (classified.denied) return classified;
|
|
1111
|
+
chain.push(classified);
|
|
1112
|
+
if (classified.cd) here = classified.cd;
|
|
1113
|
+
}
|
|
1114
|
+
return { chain };
|
|
1115
|
+
};
|
|
1116
|
+
|
|
1117
|
+
const classifyBashSegment = (trimmed, cwd) => {
|
|
1118
|
+
const relocated = classifyRelocatedGit(trimmed, cwd);
|
|
1119
|
+
if (relocated) return relocated;
|
|
1120
|
+
if (relocationPatternFor(trimmed).test(trimmed)) return { denied: "Bash relocation flags are not authorized" };
|
|
1121
|
+
const cd = classifyCd(trimmed, cwd);
|
|
1122
|
+
if (cd) return cd;
|
|
1013
1123
|
const git = classifyReadOnlyGit(trimmed, cwd);
|
|
1014
1124
|
if (git) return git;
|
|
1015
1125
|
const words = shellWords(trimmed);
|
|
@@ -1126,6 +1236,12 @@ export const handleStartWorkPreToolUse = (root, input) => {
|
|
|
1126
1236
|
const executionRoot = canonicalDirectory(typeof input.cwd === "string" ? input.cwd : canonicalRoot, "tool cwd");
|
|
1127
1237
|
const classified = classifyToolAuthority(executionRoot, input);
|
|
1128
1238
|
if (classified.denied) return denial(classified.denied);
|
|
1239
|
+
if (classified.control) return { decision: "allow-normal", action: "control", root: executionRoot, roots: [executionRoot] };
|
|
1240
|
+
if (classified.chain) {
|
|
1241
|
+
const covered = classified.chain.every((link) => link.control
|
|
1242
|
+
|| link.targetRoots.every((targetRoot) => work.authority.grants.some((grant) => grantCovers(grant, link.action, targetRoot))));
|
|
1243
|
+
return covered ? { decision: "allow-normal", action: "chain", root: executionRoot, roots: [executionRoot] } : denial("Bash target is outside the effective authority grant");
|
|
1244
|
+
}
|
|
1129
1245
|
const targetRoots = classified.targetRoots ?? [classified.targetRoot];
|
|
1130
1246
|
const authorized = targetRoots.every((targetRoot) => work.authority.grants.some((grant) => grantCovers(grant, classified.action, targetRoot)));
|
|
1131
1247
|
if (authorized) {
|
|
@@ -95,7 +95,7 @@ Deep Interview is an intent-first Socratic clarification loop that runs before p
|
|
|
95
95
|
<Do_Not_Use_When>
|
|
96
96
|
- The request already has concrete file/symbol targets and clear acceptance criteria
|
|
97
97
|
- The user explicitly asks to skip planning/interview and execute immediately
|
|
98
|
-
- The user
|
|
98
|
+
- The user wants open-ended brainstorming (many options, a name, "what could we do"): send it to `lit-brainstorm` (`lit brainstorm <topic>`), and return here only when the pick is still vague
|
|
99
99
|
- A complete spec/plan already exists and execution should start
|
|
100
100
|
</Do_Not_Use_When>
|
|
101
101
|
|