@litfamily/litclaude 1.0.42 → 1.0.43

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.
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
- import { tmpdir } from "node:os";
2
+ import { homedir, tmpdir } from "node:os";
3
3
  import {
4
4
  appendFileSync,
5
5
  closeSync,
@@ -462,7 +462,8 @@ const readCanonicalPlanText = (planPath) => {
462
462
 
463
463
  export const readPlanProgress = (planPath) => {
464
464
  const text = readCanonicalPlanText(planPath);
465
- const tasks = parsePlanTaskRows(text).map(({ checked, text: taskText }) => ({ checked, text: taskText }));
465
+ // `blocked` joins the fingerprint only when set, so a plan without BLOCKED: tasks keeps its hash.
466
+ const tasks = parsePlanTaskRows(text).map(({ checked, text: taskText, blocked }) => ({ checked, text: taskText, ...(blocked ? { blocked } : {}) }));
466
467
  const fingerprint = hash(JSON.stringify(tasks));
467
468
  const uncheckedTasks = tasks.filter(({ checked }) => !checked);
468
469
  return {
@@ -470,7 +471,8 @@ export const readPlanProgress = (planPath) => {
470
471
  total: tasks.length,
471
472
  checked: tasks.length - uncheckedTasks.length,
472
473
  unchecked: uncheckedTasks.length,
473
- next_task: uncheckedTasks[0]?.text ?? null,
474
+ next_task: uncheckedTasks.find(({ blocked }) => !blocked)?.text ?? null,
475
+ blocked_tasks: uncheckedTasks.filter(({ blocked }) => blocked).map(({ text: taskText }) => taskText),
474
476
  };
475
477
  };
476
478
 
@@ -853,7 +855,15 @@ export const startWorkStructuredContext = (root, sessionId, response = null) =>
853
855
  return `<litclaude-start-work-context>\n${json}\n</litclaude-start-work-context>`;
854
856
  };
855
857
 
856
- 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;
858
+ const forbiddenShellPattern = /(?:\bgit\b[^\n;&|]*\b(?:commit|push|tag|reset|clean|config)\b|\b(?:npm|pnpm|yarn)\b[^\n;&|]*\bpublish\b|\bgh\b[^\n;&|]*\brelease\s+create\b|\bdefaults\s+write\b)/iu;
859
+ // A package manager call that names `version` is a bump unless its subcommand only reads or runs a
860
+ // script (`npm view <pkg> version`, `npm run check:version`). That verb must be the word right after
861
+ // the manager: any flag in front of it (`--prefix run version patch`) leaves the subcommand unknown, refused.
862
+ // The lookahead keeps a nested call (`npm view x version $(npm version patch)`) its own match.
863
+ const PACKAGE_MANAGER_CALL = /\b(?:npm|pnpm|yarn)\b(?=([^\n;&|]*))/giu;
864
+ const VERSION_READ_VERB = /^[ \t]+(?:view|info|show|v|run|run-script)(?:[ \t]|$)/iu;
865
+ const forbiddenShellCommand = (command) => forbiddenShellPattern.test(command)
866
+ || [...command.matchAll(PACKAGE_MANAGER_CALL)].some(([, rest]) => /\b(?:version|verison)\b/iu.test(rest) && !VERSION_READ_VERB.test(rest));
857
867
  const shellRelocationPattern = /(?:^|\s)(?:--prefix|--cwd|--directory|--chdir)(?:=|\s|$)|(?:^|\s)-C(?:\s|$)/u;
858
868
  // For grep and rg, `-C <n>` is the context-lines flag, not a change of directory.
859
869
  const searchRelocationPattern = /(?:^|\s)(?:--prefix|--cwd|--directory|--chdir)(?:=|\s|$)/u;
@@ -1123,7 +1133,7 @@ const classifyBash = (command, cwd) => {
1123
1133
  if (typeof command !== "string" || command.length === 0 || command.length > 32_768) {
1124
1134
  return { denied: "unclassified mutating Bash command" };
1125
1135
  }
1126
- if (forbiddenShellPattern.test(command)) return { denied: "forbidden authority action in Bash command" };
1136
+ if (forbiddenShellCommand(command)) return { denied: "forbidden authority action in Bash command" };
1127
1137
  const trimmed = command.trim();
1128
1138
  const segments = trimmed.split(/[ \t]+&&[ \t]+/u);
1129
1139
  if (segments.length === 1) return classifyBashSegment(trimmed, cwd);
@@ -1332,6 +1342,24 @@ const PLUGIN_ROOT = (() => {
1332
1342
  const pluginSelfRead = (classified) => classified.action === "read" && PLUGIN_ROOT !== null
1333
1343
  && (classified.targetRoots ?? [classified.targetRoot]).every((target) => rootCovers(PLUGIN_ROOT, target));
1334
1344
 
1345
+ // Claude Code spills a long tool result to `<config>/projects/<project key>/<session id>/tool-results/`
1346
+ // and tells the session to read it there. The root session (and its subagents, which share its id) may
1347
+ // read its own folder; the key is the project path with every non-alphanumeric character as `-`.
1348
+ // Another session's folder, and any write, stay boundaries.
1349
+ const ownSpillRead = (classified, sessionId, projectDirs) => {
1350
+ if (classified.action !== "read" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$/u.test(sessionId)) return false;
1351
+ const projects = join(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "projects");
1352
+ const spills = projectDirs.filter((dir) => typeof dir === "string").flatMap((dir) => {
1353
+ const spill = join(projects, dir.replace(/[^A-Za-z0-9]/gu, "-"), sessionId, "tool-results");
1354
+ try {
1355
+ return [canonicalTarget(spill, "spill folder")];
1356
+ } catch {
1357
+ return [];
1358
+ }
1359
+ });
1360
+ return (classified.targetRoots ?? [classified.targetRoot]).every((target) => spills.some((spill) => rootCovers(spill, target)));
1361
+ };
1362
+
1335
1363
  // What an approved boundary covers: a read reaches the target's folder, or the toplevel of another
1336
1364
  // git checkout the target sits in; a write reaches the target's folder only. The next file beside
1337
1365
  // the first then needs no second approval.
@@ -1491,7 +1519,7 @@ const observeFilter = ([head, ...args]) => {
1491
1519
  // calls this; the owner's guard keeps classifyBash.
1492
1520
  export const classifyObservation = (command, cwd) => {
1493
1521
  if (typeof command !== "string" || command.length === 0 || command.length > 32_768) return false;
1494
- if (forbiddenShellPattern.test(command)) return false;
1522
+ if (forbiddenShellCommand(command)) return false;
1495
1523
  const tokens = observationTokens(command.trim());
1496
1524
  if (!tokens?.length) return false;
1497
1525
  const segments = [[]];
@@ -1622,6 +1650,9 @@ export const handleStartWorkPreToolUse = (root, input, { now = Date.now() } = {}
1622
1650
  }
1623
1651
  if (classified.control) return { decision: "allow-normal", action: "control", root: executionRoot, roots: [executionRoot] };
1624
1652
  if (pluginSelfRead(classified)) return { decision: "allow-normal", action: "read", root: PLUGIN_ROOT, roots: [PLUGIN_ROOT] };
1653
+ if (!classified.chain && ownSpillRead(classified, input.session_id, [canonicalRoot, input.cwd])) {
1654
+ return { decision: "allow-normal", action: "read", root: classified.targetRoots?.[0] ?? classified.targetRoot, roots: classified.targetRoots ?? [classified.targetRoot] };
1655
+ }
1625
1656
  if (classified.chain) {
1626
1657
  const covered = classified.chain.every((link) => link.control
1627
1658
  || link.targetRoots.every((targetRoot) => work.authority.grants.some((grant) => grantCovers(grant, link.action, targetRoot))));
@@ -1777,9 +1808,13 @@ export const handleStartWorkStop = (root, input) => {
1777
1808
  const next = progress.next_task
1778
1809
  ? `Continue work ${work.work_id} with next top-level task: ${progress.next_task}.`
1779
1810
  : `Work ${work.work_id} has all top-level tasks checked; run final verification and cleanup, then complete it with \`litclaude-ai start-work complete --work-id ${work.work_id} --session-id ${input.session_id} --expected-revision ${work.revision} --idempotency-key complete-${work.work_id}-${work.revision}\`.`;
1811
+ // Every open task waits on the user (BLOCKED:): say so once and let the session stop. The
1812
+ // fingerprint below keeps the next Stop silent until the plan changes.
1813
+ const waiting = !progress.next_task && progress.unchecked > 0;
1780
1814
  const output = {
1781
- decision: "block",
1782
- reason: `LitClaude start-work continuation: ${next}`,
1815
+ ...(waiting
1816
+ ? { systemMessage: `LitClaude start-work ${work.work_id} is waiting on you; every open task is BLOCKED: ${progress.blocked_tasks.slice(0, 5).map((task) => task.replace(/[\p{Cc}\p{Cf}]/gu, " ").slice(0, 120)).join("; ")}${progress.blocked_tasks.length > 5 ? ` (+${progress.blocked_tasks.length - 5} more)` : ""}. Remove BLOCKED: from a task or reply to carry on.` }
1817
+ : { decision: "block", reason: `LitClaude start-work continuation: ${next}` }),
1783
1818
  work_id: work.work_id,
1784
1819
  revision: work.revision,
1785
1820
  continuation_id: `continuation-${shortHash(`${input.session_id}:${promptId}:${work.work_id}:${work.revision}:${progress.fingerprint}`)}`,
@@ -239,6 +239,11 @@ unavailable:
239
239
  its last checkbox, so do not ask the user to set a goal before executing.
240
240
  - Do not auto-type or send `/goal` text from a skill; if the user invokes `/goal`, respect it.
241
241
 
242
+ When a top-level task cannot move until the user acts, write `BLOCKED: <reason>` on its
243
+ line or as an indented body line under it. The Stop continuation skips such tasks; when
244
+ every open task is blocked it tells the user once and lets the session stop. Removing the
245
+ marker, or the user's reply, resumes the run.
246
+
242
247
  If model-facing goal tools are absent (the case today), continue with Boulder/ledger discipline.
243
248
  If goal tools are not exposed, do not print repeated fallback status; just keep
244
249
  the plan ledger accurate and continue with verified evidence.