@litfamily/litclaude 1.0.48 → 1.0.49
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 +31 -0
- package/README.md +8 -8
- package/README_ko-KR.md +8 -8
- package/docs/assets/readme/badge-version.svg +1 -1
- package/docs/hooks.md +45 -13
- package/package.json +1 -1
- package/plugins/litclaude/.claude-plugin/plugin.json +1 -1
- package/plugins/litclaude/agents/lit-executor.md +13 -9
- package/plugins/litclaude/bin/litclaude-hook.js +76 -21
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/commands/lit-adhd.md +17 -11
- package/plugins/litclaude/commands/lit-loop.md +6 -5
- package/plugins/litclaude/commands/lit-rewind.md +17 -11
- package/plugins/litclaude/commands/start-work.md +16 -7
- package/plugins/litclaude/lib/canonical-skill-resources.mjs +6 -5
- package/plugins/litclaude/lib/mod/state.mjs +8 -2
- package/plugins/litclaude/lib/mod/workflow.mjs +2 -1
- package/plugins/litclaude/lib/rewind/board.mjs +408 -0
- package/plugins/litclaude/lib/rewind/brief.mjs +6 -6
- package/plugins/litclaude/lib/rewind/collect.mjs +57 -7
- package/plugins/litclaude/lib/start-work-cli.mjs +1 -1
- package/plugins/litclaude/lib/start-work-lifecycle.mjs +331 -100
- package/plugins/litclaude/skills/lit-adhd/SKILL.md +56 -16
- package/plugins/litclaude/skills/lit-adhd/references/card-examples.md +107 -0
- package/plugins/litclaude/skills/lit-adhd/references/status-taxonomy.md +17 -2
- package/plugins/litclaude/skills/lit-loop/SKILL.md +8 -5
- package/plugins/litclaude/skills/lit-plan/SKILL.md +2 -1
- package/plugins/litclaude/skills/start-work/SKILL.md +23 -11
|
@@ -33,6 +33,7 @@ const MAX_HISTORY = 16;
|
|
|
33
33
|
const MAX_IDEMPOTENCY = 16;
|
|
34
34
|
const MAX_CONTINUATION_RECEIPTS = MAX_STATE_EVENTS;
|
|
35
35
|
const MAX_GRANTS = 64;
|
|
36
|
+
const MAX_PARKED = 16;
|
|
36
37
|
const MAX_PLAN_BYTES = 1024 * 1024;
|
|
37
38
|
const allowedActions = new Set(["read", "write", "execute", "test", "package", "vcs-read"]);
|
|
38
39
|
const forbiddenActions = new Set([
|
|
@@ -267,6 +268,15 @@ const readState = (root, { optional = false } = {}) => {
|
|
|
267
268
|
work.authority.consumed_grants ??= [];
|
|
268
269
|
work.continuation ??= {};
|
|
269
270
|
work.continuation.receipts ??= {};
|
|
271
|
+
// Before parked boundaries, one boundary froze the whole work as `paused`; read it as one parked step.
|
|
272
|
+
work.pending_boundaries ??= [];
|
|
273
|
+
if (work.status === "paused") {
|
|
274
|
+
if (work.pending_boundary && !work.pending_boundaries.some(({ boundary_id: id }) => id === work.pending_boundary.boundary_id)) {
|
|
275
|
+
work.pending_boundaries.push({ ...work.pending_boundary, hits: 1, last_seen: work.pending_boundary.requested_at });
|
|
276
|
+
}
|
|
277
|
+
work.status = "active";
|
|
278
|
+
}
|
|
279
|
+
work.pending_boundary = null;
|
|
270
280
|
}
|
|
271
281
|
return state;
|
|
272
282
|
};
|
|
@@ -592,6 +602,7 @@ export const initializeStartWork = (root, request) => withLock(root, () => {
|
|
|
592
602
|
},
|
|
593
603
|
progress,
|
|
594
604
|
pending_boundary: null,
|
|
605
|
+
pending_boundaries: [],
|
|
595
606
|
continuation: {
|
|
596
607
|
last_emitted_progress_fingerprint: progress.fingerprint,
|
|
597
608
|
receipts: {},
|
|
@@ -629,17 +640,17 @@ export const pauseStartWork = (root, request) => withLock(root, () => {
|
|
|
629
640
|
return response;
|
|
630
641
|
}
|
|
631
642
|
|
|
643
|
+
// A pause parks the boundary beside the others; the work itself keeps running.
|
|
632
644
|
const boundaryId = `boundary-${shortHash(`${work.work_id}:${action}:${targetRoot}`)}`;
|
|
633
|
-
if (work.
|
|
634
|
-
if (work.pending_boundary?.boundary_id !== boundaryId) throw new StartWorkLifecycleError("work is paused at a different authority boundary", 409);
|
|
645
|
+
if (work.pending_boundaries.some(({ boundary_id: id }) => id === boundaryId)) {
|
|
635
646
|
const response = { ok: true, operation: "pause", already_authorized: false, state: publicState(state) };
|
|
636
647
|
rememberIdempotency(state, request.idempotencyKey, fingerprint, response);
|
|
637
648
|
saveState(canonicalRoot, state);
|
|
638
649
|
return response;
|
|
639
650
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
work.
|
|
651
|
+
if (work.pending_boundaries.length >= MAX_PARKED) throw new StartWorkLifecycleError("too many parked boundaries", 409);
|
|
652
|
+
const requestedAt = nowIso();
|
|
653
|
+
work.pending_boundaries.push({
|
|
643
654
|
boundary_id: boundaryId,
|
|
644
655
|
action,
|
|
645
656
|
root: targetRoot,
|
|
@@ -647,9 +658,11 @@ export const pauseStartWork = (root, request) => withLock(root, () => {
|
|
|
647
658
|
origin_prompt_id: request.originPromptId ?? "cli-pause",
|
|
648
659
|
origin_tool_use_id: request.originToolUseId ?? null,
|
|
649
660
|
grant_id: request.grantId ?? `grant-${shortHash(`${work.work_id}:${action}:${targetRoot}:${request.originPromptId ?? "manual"}`)}`,
|
|
650
|
-
requested_at:
|
|
651
|
-
|
|
652
|
-
|
|
661
|
+
requested_at: requestedAt,
|
|
662
|
+
last_seen: requestedAt,
|
|
663
|
+
hits: 1,
|
|
664
|
+
});
|
|
665
|
+
appendEvent(state, work, "work.boundary_parked", { boundary_id: boundaryId, action, root: targetRoot });
|
|
653
666
|
const response = { ok: true, operation: "pause", already_authorized: false, state: publicState(state) };
|
|
654
667
|
rememberIdempotency(state, request.idempotencyKey, fingerprint, response);
|
|
655
668
|
saveState(canonicalRoot, state);
|
|
@@ -679,11 +692,12 @@ const validateTrustedResume = (state, request) => {
|
|
|
679
692
|
throw new StartWorkLifecycleError("resume token already consumed", 409);
|
|
680
693
|
}
|
|
681
694
|
if (state.idempotency[key]) throw new StartWorkLifecycleError("resume token already consumed", 409);
|
|
682
|
-
const work = requireActiveWork(state, request, ["
|
|
683
|
-
|
|
684
|
-
if (
|
|
685
|
-
if (
|
|
686
|
-
if (
|
|
695
|
+
const work = requireActiveWork(state, request, ["active"]);
|
|
696
|
+
const boundary = work.pending_boundaries.find(({ boundary_id: id }) => id === request.boundaryId);
|
|
697
|
+
if (!boundary) throw new StartWorkLifecycleError("resume boundary identity does not match", 409);
|
|
698
|
+
if (boundary.origin_session_id !== request.sessionId) throw new StartWorkLifecycleError("resume session identity does not match", 409);
|
|
699
|
+
if (boundary.origin_prompt_id !== request.originPromptId) throw new StartWorkLifecycleError("resume prompt identity does not match", 409);
|
|
700
|
+
if (boundary.grant_id !== request.grantId) throw new StartWorkLifecycleError("resume grant identity does not match", 409);
|
|
687
701
|
if (!/^grant-[a-f0-9]{20}$/u.test(request.grantId)) throw new StartWorkLifecycleError("invalid grant id", 64);
|
|
688
702
|
if (typeof request.consumedByPromptId !== "string" || !/^[A-Za-z0-9._:-]{1,160}$/u.test(request.consumedByPromptId)) {
|
|
689
703
|
throw new StartWorkLifecycleError("resume consumption prompt identity is missing or invalid", 409);
|
|
@@ -694,7 +708,7 @@ const validateTrustedResume = (state, request) => {
|
|
|
694
708
|
if (work.authority.grants.length >= MAX_GRANTS || work.authority.consumed_grants.length >= MAX_GRANTS) {
|
|
695
709
|
throw new StartWorkLifecycleError("authority grant limit exceeded", 77);
|
|
696
710
|
}
|
|
697
|
-
return { key, fingerprint, work };
|
|
711
|
+
return { key, fingerprint, work, boundary };
|
|
698
712
|
};
|
|
699
713
|
|
|
700
714
|
export const resumeStartWorkFromUserPrompt = (root, request) => {
|
|
@@ -702,13 +716,13 @@ export const resumeStartWorkFromUserPrompt = (root, request) => {
|
|
|
702
716
|
validateTrustedResume(readState(canonicalRoot), request);
|
|
703
717
|
return withLock(canonicalRoot, () => {
|
|
704
718
|
const state = readState(canonicalRoot);
|
|
705
|
-
const { key, fingerprint, work } = validateTrustedResume(state, request);
|
|
719
|
+
const { key, fingerprint, work, boundary } = validateTrustedResume(state, request);
|
|
706
720
|
const timestamp = nowIso();
|
|
707
721
|
const grant = {
|
|
708
722
|
grant_id: request.grantId,
|
|
709
723
|
boundary_id: request.boundaryId,
|
|
710
|
-
action:
|
|
711
|
-
root:
|
|
724
|
+
action: boundary.action,
|
|
725
|
+
root: boundary.root,
|
|
712
726
|
issued_by: "trusted-user-prompt-submit",
|
|
713
727
|
issued_at: timestamp,
|
|
714
728
|
};
|
|
@@ -723,8 +737,7 @@ export const resumeStartWorkFromUserPrompt = (root, request) => {
|
|
|
723
737
|
consumed_at: timestamp,
|
|
724
738
|
});
|
|
725
739
|
work.authority.authority_roots = [...new Set([...work.authority.authority_roots, grant.root])];
|
|
726
|
-
work.
|
|
727
|
-
work.pending_boundary = null;
|
|
740
|
+
work.pending_boundaries = work.pending_boundaries.filter(({ boundary_id: id }) => id !== request.boundaryId);
|
|
728
741
|
appendEvent(state, work, "work.resumed", {
|
|
729
742
|
boundary_id: request.boundaryId,
|
|
730
743
|
grant_id: request.grantId,
|
|
@@ -759,6 +772,18 @@ export const recordStartWorkProgress = (root, request) => withLock(root, () => {
|
|
|
759
772
|
return response;
|
|
760
773
|
});
|
|
761
774
|
|
|
775
|
+
// Ends the active work inside a lock the caller already holds (the mkdir lock is not reentrant).
|
|
776
|
+
const closeWork = (state, work, operation, details = {}) => {
|
|
777
|
+
work.status = operation === "complete" ? "completed" : "cancelled";
|
|
778
|
+
work.pending_boundary = null;
|
|
779
|
+
work.pending_boundaries = [];
|
|
780
|
+
appendEvent(state, work, operation === "complete" ? "work.completed" : "work.cancelled", details);
|
|
781
|
+
work.terminal_revision = state.revision;
|
|
782
|
+
work.terminal_at = state.updated_at;
|
|
783
|
+
state.active_work_id = null;
|
|
784
|
+
state.history.push(terminalSummary(work));
|
|
785
|
+
};
|
|
786
|
+
|
|
762
787
|
const finishWork = (root, operation, request) => withLock(root, () => {
|
|
763
788
|
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
764
789
|
const state = readState(canonicalRoot);
|
|
@@ -766,8 +791,7 @@ const finishWork = (root, operation, request) => withLock(root, () => {
|
|
|
766
791
|
const fingerprint = requestHash(operation, normalized);
|
|
767
792
|
const replay = idempotentReplay(state, request.idempotencyKey, fingerprint);
|
|
768
793
|
if (replay) return replay;
|
|
769
|
-
const work = requireActiveWork(state, request,
|
|
770
|
-
if (operation === "complete" && work.status === "paused") throw new StartWorkLifecycleError("paused work cannot complete", 409);
|
|
794
|
+
const work = requireActiveWork(state, request, ["active"]);
|
|
771
795
|
if (operation === "complete") {
|
|
772
796
|
if (Object.values(work.lanes ?? {}).some(({ status }) => status === "active")) {
|
|
773
797
|
throw new StartWorkLifecycleError("active lane must finalize before work can complete", 409);
|
|
@@ -777,13 +801,7 @@ const finishWork = (root, operation, request) => withLock(root, () => {
|
|
|
777
801
|
if (progress.unchecked > 0) throw new StartWorkLifecycleError("plan has an unchecked top-level task");
|
|
778
802
|
work.progress = progress;
|
|
779
803
|
}
|
|
780
|
-
work
|
|
781
|
-
work.pending_boundary = null;
|
|
782
|
-
appendEvent(state, work, operation === "complete" ? "work.completed" : "work.cancelled");
|
|
783
|
-
work.terminal_revision = state.revision;
|
|
784
|
-
work.terminal_at = state.updated_at;
|
|
785
|
-
state.active_work_id = null;
|
|
786
|
-
state.history.push(terminalSummary(work));
|
|
804
|
+
closeWork(state, work, operation);
|
|
787
805
|
const response = { ok: true, operation, state: publicState(state) };
|
|
788
806
|
rememberIdempotency(state, request.idempotencyKey, fingerprint, response);
|
|
789
807
|
saveState(canonicalRoot, state);
|
|
@@ -791,6 +809,68 @@ const finishWork = (root, operation, request) => withLock(root, () => {
|
|
|
791
809
|
});
|
|
792
810
|
|
|
793
811
|
export const cancelStartWork = (root, request) => finishWork(root, "cancel", request);
|
|
812
|
+
|
|
813
|
+
const PROMPT_IDENTITY = /^[A-Za-z0-9._:-]{1,160}$/u;
|
|
814
|
+
const MAX_CANCEL_NOTICES = 16;
|
|
815
|
+
|
|
816
|
+
/** Whether `root` holds a running start-work (status active); reads without the lock. */
|
|
817
|
+
export const hasActiveStartWork = (root) => {
|
|
818
|
+
try {
|
|
819
|
+
const state = readState(canonicalDirectory(root, "cwd root"), { optional: true });
|
|
820
|
+
const work = state?.active_work_id ? state.works[state.active_work_id] : null;
|
|
821
|
+
return Boolean(work && ["active", "paused"].includes(work.status));
|
|
822
|
+
} catch {
|
|
823
|
+
return false;
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* `lit cancel` typed as a whole prompt: the user's own words end the project's running work from
|
|
829
|
+
* any session, so no work id, revision or owner check applies (those guard the model-callable CLI).
|
|
830
|
+
* The owner session is told on its next changing tool call, until the user types there again.
|
|
831
|
+
* Returns `{ cancelled }` (a replay of the same prompt returns the first answer) or null.
|
|
832
|
+
*/
|
|
833
|
+
export const cancelStartWorkFromUserPrompt = (root, { sessionId, promptId }) => {
|
|
834
|
+
if (typeof sessionId !== "string" || !PROMPT_IDENTITY.test(sessionId)) return null;
|
|
835
|
+
if (typeof promptId !== "string" || !PROMPT_IDENTITY.test(promptId)) return null;
|
|
836
|
+
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
837
|
+
if (!existsSync(startWorkStatePath(canonicalRoot))) return null;
|
|
838
|
+
return withLock(canonicalRoot, () => {
|
|
839
|
+
const state = readState(canonicalRoot);
|
|
840
|
+
const key = `typed-cancel:${sessionId}:${promptId}`;
|
|
841
|
+
if (state.idempotency[key]) return clone(state.idempotency[key].response);
|
|
842
|
+
const work = state.active_work_id ? state.works[state.active_work_id] : null;
|
|
843
|
+
if (!work || !["active", "paused"].includes(work.status)) return null;
|
|
844
|
+
const owner = work.root_session_id;
|
|
845
|
+
const lanes = Object.values(work.lanes ?? {}).filter(({ status }) => status === "active").map(({ agent_type: type }) => type);
|
|
846
|
+
closeWork(state, work, "cancel", { source: "user-prompt", by_session_id: sessionId, origin_prompt_id: promptId });
|
|
847
|
+
state.cancel_notices = Object.fromEntries(Object.entries({
|
|
848
|
+
...(state.cancel_notices ?? {}),
|
|
849
|
+
[owner]: { work_id: work.work_id, plan_name: work.plan_name, by_session_id: sessionId, recorded_at: state.updated_at },
|
|
850
|
+
}).slice(-MAX_CANCEL_NOTICES));
|
|
851
|
+
const response = { cancelled: { workId: work.work_id, plan: work.plan_name, otherSession: owner !== sessionId, lanes } };
|
|
852
|
+
rememberIdempotency(state, key, requestHash("typed-cancel", { sessionId, promptId }), response);
|
|
853
|
+
saveState(canonicalRoot, state);
|
|
854
|
+
return response;
|
|
855
|
+
});
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
/** Drops this session's cancel notice once the user types a new prompt there. */
|
|
859
|
+
/** Lifts this session's cancel notice; returns the lifted notice, or null when there was none. */
|
|
860
|
+
export const clearStartWorkCancelNotice = (root, sessionId) => {
|
|
861
|
+
if (typeof sessionId !== "string") return null;
|
|
862
|
+
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
863
|
+
const peek = readState(canonicalRoot, { optional: true });
|
|
864
|
+
if (!peek?.cancel_notices?.[sessionId]) return null;
|
|
865
|
+
return withLock(canonicalRoot, () => {
|
|
866
|
+
const state = readState(canonicalRoot);
|
|
867
|
+
const notice = state.cancel_notices?.[sessionId];
|
|
868
|
+
if (!notice) return null;
|
|
869
|
+
delete state.cancel_notices[sessionId];
|
|
870
|
+
saveState(canonicalRoot, state);
|
|
871
|
+
return notice;
|
|
872
|
+
});
|
|
873
|
+
};
|
|
794
874
|
export const completeStartWork = (root, request) => finishWork(root, "complete", request);
|
|
795
875
|
|
|
796
876
|
export const readStartWorkStatus = (root) => {
|
|
@@ -851,7 +931,7 @@ export const startWorkStructuredContext = (root, sessionId, response = null) =>
|
|
|
851
931
|
})),
|
|
852
932
|
forbidden_actions: work.authority.forbidden_actions,
|
|
853
933
|
},
|
|
854
|
-
|
|
934
|
+
parked_boundaries: (work.pending_boundaries ?? []).map(({ action, root: parkedRoot }) => ({ action, root: parkedRoot })),
|
|
855
935
|
};
|
|
856
936
|
const json = JSON.stringify(data).replaceAll("<", "\\u003c").replaceAll(">", "\\u003e");
|
|
857
937
|
return `<litclaude-start-work-context>\n${json}\n</litclaude-start-work-context>`;
|
|
@@ -1329,7 +1409,7 @@ const isOwnRewindScript = (path, cwd) => {
|
|
|
1329
1409
|
// A Bash shape the guard cannot verify is refused, not paused, so the refusal says what does run;
|
|
1330
1410
|
// without it a session tried a script in the write-only temp folder and stopped. Forbidden actions
|
|
1331
1411
|
// (push, publish, tag, reset) never get this note.
|
|
1332
|
-
const BASH_WAY_OUT = "This start-work guard verifies one plain command per Bash call: no `;`, `||`, `$`, backticks or quoted code, redirects only as `2>&1`, at most four plain commands joined by ` && `, and an optional trailing `| tail`, `head`, `grep`, `wc` or `sort` with flags only. Split the command into separate calls. To run code, write a script inside the project
|
|
1412
|
+
const BASH_WAY_OUT = "This start-work guard verifies one plain command per Bash call: no `;`, `||`, `$`, backticks or quoted code, redirects only as `2>&1`, at most four plain commands joined by ` && `, and an optional trailing `| tail`, `head`, `grep`, `wc` or `sort` with flags only. Split the command into separate calls. To run code, write a script inside the project and run `node <script>`, then remove it. This is not an approval prompt; `lit approve` does not apply, and the user can end the run with `lit cancel`.";
|
|
1333
1413
|
const bashDenial = (reason) => denial(`${reason}. ${BASH_WAY_OUT}`);
|
|
1334
1414
|
|
|
1335
1415
|
// The plugin this module ships in: reading its own skills, commands and references is never a
|
|
@@ -1344,22 +1424,98 @@ const PLUGIN_ROOT = (() => {
|
|
|
1344
1424
|
const pluginSelfRead = (classified) => classified.action === "read" && PLUGIN_ROOT !== null
|
|
1345
1425
|
&& (classified.targetRoots ?? [classified.targetRoot]).every((target) => rootCovers(PLUGIN_ROOT, target));
|
|
1346
1426
|
|
|
1347
|
-
//
|
|
1348
|
-
//
|
|
1349
|
-
//
|
|
1350
|
-
//
|
|
1351
|
-
const
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1427
|
+
// Secrets and settings a start-work never opens or changes: a plain refusal, never a pause, a grant
|
|
1428
|
+
// or a queued step. Paths compare in NFC, case-folded where the filesystem folds case (macOS,
|
|
1429
|
+
// Windows), after links resolve. Only direct file access is checked: a script or a folder-wide
|
|
1430
|
+
// search can still read such a file.
|
|
1431
|
+
const FOLDS_CASE = process.platform === "darwin" || process.platform === "win32";
|
|
1432
|
+
const foldPath = (path) => (FOLDS_CASE ? path.normalize("NFC").toLowerCase() : path.normalize("NFC"));
|
|
1433
|
+
const ENV_FILE = /^\.env(?:\.[\w-]+)*$|^\.envrc$/u;
|
|
1434
|
+
const ENV_EXAMPLE = /\.(?:example|sample|template)$/u;
|
|
1435
|
+
const SSH_KEY = /^id_(?:rsa|dsa|ecdsa|ed25519)$/u;
|
|
1436
|
+
const SHELL_RC = new Set([".zshrc", ".zprofile", ".zshenv", ".bashrc", ".bash_profile", ".profile"]);
|
|
1437
|
+
const sensitiveReason = (target, action) => {
|
|
1438
|
+
const home = foldPath(homedir());
|
|
1439
|
+
const config = foldPath(process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"));
|
|
1440
|
+
const path = foldPath(target);
|
|
1441
|
+
const name = path.split(/[\\/]/u).at(-1) ?? "";
|
|
1442
|
+
const under = (root) => rootCovers(root, path);
|
|
1443
|
+
const segments = path.split(/[\\/]/u);
|
|
1444
|
+
if ([".ssh", ".aws", ".gnupg", ".codex"].some((dir) => under(join(home, dir)))) return "a secret or tool-config folder";
|
|
1445
|
+
if (path === join(home, ".npmrc") || path === join(home, ".claude.json") || (dirname(path) === home && SHELL_RC.has(name))) return "a credential or shell file";
|
|
1446
|
+
if (dirname(path) === config && /^settings(?:\.[\w-]+)?\.json$/u.test(name)) return "Claude Code settings";
|
|
1447
|
+
if (segments.at(-2) === ".claude" && /^settings(?:\.[\w-]+)?\.json$/u.test(name)) return "Claude Code project settings";
|
|
1448
|
+
if (name === ".mcp.json") return "an MCP server config";
|
|
1449
|
+
if ((ENV_FILE.test(name) && !ENV_EXAMPLE.test(name)) || SSH_KEY.test(name) || name.endsWith(".pem")) return "a secret file";
|
|
1450
|
+
if (action === "read") return null;
|
|
1451
|
+
const gitAt = segments.lastIndexOf(".git");
|
|
1452
|
+
if (gitAt >= 0 && ["hooks", "config", "worktrees"].includes(segments[gitAt + 1])) return "git configuration";
|
|
1453
|
+
const stateAt = segments.lastIndexOf(".litclaude");
|
|
1454
|
+
if (stateAt >= 0 && (segments[stateAt + 1] === "boulder.json" || segments[stateAt + 1] === "start-work")) return "the start-work state";
|
|
1455
|
+
return null;
|
|
1456
|
+
};
|
|
1457
|
+
const sensitiveDenial = (classified) => {
|
|
1458
|
+
const links = classified.chain ? classified.chain.filter((link) => !link.control) : [classified];
|
|
1459
|
+
for (const link of links) {
|
|
1460
|
+
for (const target of link.targetRoots ?? (link.targetRoot ? [link.targetRoot] : [])) {
|
|
1461
|
+
const reason = sensitiveReason(target, link.action);
|
|
1462
|
+
if (reason) {
|
|
1463
|
+
return denial(`LitClaude start-work: ${target} is protected for this run (${reason}); a start-work never opens or changes secrets or settings. This is not an approval prompt. If the task needs it, add a \`BLOCKED: <reason>\` line under that task in the plan and ask the user.`);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
return null;
|
|
1468
|
+
};
|
|
1469
|
+
|
|
1470
|
+
// Folders Claude Code keeps for this very session, which the run (and its subagents, which carry
|
|
1471
|
+
// the root session id) reads without a boundary: its spilled tool results and subagent transcripts
|
|
1472
|
+
// under `<config>/projects/<key>/<session>/`, the project's memory, the user's CLAUDE.md and skills,
|
|
1473
|
+
// the host's `tasks` and `scratchpad` folders under `<CLAUDE_CODE_TMPDIR or /tmp>/claude-<uid>/<key>/<session>/`,
|
|
1474
|
+
// the host's bundled skills, and the run's own private temp folder. The scratchpad may also be
|
|
1475
|
+
// written, since the host tells the session to put temp files there. The key is the folder the
|
|
1476
|
+
// session started in, with every non-alphanumeric character as `-`; the transcript path names it
|
|
1477
|
+
// even when the run's root is elsewhere (a worktree lane). Another session's folders, and any other
|
|
1478
|
+
// write, stay boundaries; a symlink is judged by where it points.
|
|
1479
|
+
const projectKey = (dir) => dir.replace(/[^A-Za-z0-9]/gu, "-");
|
|
1480
|
+
const harnessRoots = (work, input, projectDirs) => {
|
|
1481
|
+
const sessionId = input?.session_id;
|
|
1482
|
+
if (typeof sessionId !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$/u.test(sessionId)) return { read: [], write: [] };
|
|
1483
|
+
const config = process.env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
|
|
1484
|
+
const projects = join(config, "projects");
|
|
1485
|
+
const keys = new Set();
|
|
1486
|
+
if (typeof input.transcript_path === "string") {
|
|
1487
|
+
const inside = relative(resolve(projects), resolve(input.transcript_path));
|
|
1488
|
+
const key = inside.split(/[\\/]/u)[0];
|
|
1489
|
+
if (key && !inside.startsWith("..") && !isAbsolute(inside) && key !== "." ) keys.add(key);
|
|
1490
|
+
}
|
|
1491
|
+
for (const dir of [process.env.CLAUDE_PROJECT_DIR, ...projectDirs]) {
|
|
1492
|
+
if (typeof dir === "string" && dir.length > 0) keys.add(projectKey(dir));
|
|
1493
|
+
}
|
|
1494
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : null;
|
|
1495
|
+
const hostTmp = uid === null ? null : join(process.env.CLAUDE_CODE_TMPDIR || "/tmp", `claude-${uid}`);
|
|
1496
|
+
const read = [join(config, "CLAUDE.md"), join(config, "skills"), join(tmpdir(), `litclaude-${work.work_id}`)];
|
|
1497
|
+
const write = [];
|
|
1498
|
+
if (hostTmp) read.push(join(hostTmp, "bundled-skills"));
|
|
1499
|
+
for (const key of keys) {
|
|
1500
|
+
read.push(join(projects, key, sessionId, "tool-results"), join(projects, key, sessionId, "subagents"), join(projects, key, "memory"));
|
|
1501
|
+
if (hostTmp) {
|
|
1502
|
+
read.push(join(hostTmp, key, sessionId, "tasks"), join(hostTmp, key, sessionId, "scratchpad"));
|
|
1503
|
+
write.push(join(hostTmp, key, sessionId, "scratchpad"));
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
const canonical = (paths) => paths.flatMap((path) => {
|
|
1356
1507
|
try {
|
|
1357
|
-
return [canonicalTarget(
|
|
1508
|
+
return [canonicalTarget(path, "harness folder")];
|
|
1358
1509
|
} catch {
|
|
1359
1510
|
return [];
|
|
1360
1511
|
}
|
|
1361
1512
|
});
|
|
1362
|
-
return
|
|
1513
|
+
return { read: canonical(read), write: canonical(write) };
|
|
1514
|
+
};
|
|
1515
|
+
const harnessAccess = (classified, work, input, projectDirs) => {
|
|
1516
|
+
if (classified.action !== "read" && classified.action !== "write") return false;
|
|
1517
|
+
const roots = harnessRoots(work, input, projectDirs)[classified.action];
|
|
1518
|
+
return (classified.targetRoots ?? [classified.targetRoot]).every((target) => roots.some((root) => rootCovers(root, target)));
|
|
1363
1519
|
};
|
|
1364
1520
|
|
|
1365
1521
|
// What an approved boundary covers: a read reaches the target's folder, or the toplevel of another
|
|
@@ -1383,14 +1539,10 @@ const boundaryRoot = (action, target, projectRoot) => {
|
|
|
1383
1539
|
return toplevel && !rootCovers(toplevel, projectRoot) && !rootCovers(projectRoot, toplevel) ? toplevel : directory;
|
|
1384
1540
|
};
|
|
1385
1541
|
|
|
1386
|
-
// What the model reads when a
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
return boundary
|
|
1391
|
-
? `LitClaude start-work paused: ${boundary.action} access to ${boundary.root} is outside this plan's scope. Reply "lit approve" to allow it for this work, or "lit deny".`
|
|
1392
|
-
: "LitClaude start-work is paused. Reply \"lit approve\" or \"lit deny\".";
|
|
1393
|
-
};
|
|
1542
|
+
// What the model reads when a call meets a boundary: only that call is set aside and the run goes on.
|
|
1543
|
+
const parkedMessage = (boundary) => (boundary.hits >= 3
|
|
1544
|
+
? `LitClaude start-work: ${boundary.action} access to ${boundary.root} is already parked (asked ${boundary.hits} times); do not retry it. Carry on with the plan's other tasks, and mark a task that cannot be done without it with a \`BLOCKED: <reason>\` line under its row.`
|
|
1545
|
+
: `LitClaude start-work parked this call: ${boundary.action} access to ${boundary.root} is outside this plan's scope, so this one call did not run. The run keeps going: carry on with the plan's other tasks. If a task cannot be done without it, add a \`BLOCKED: <reason>\` line under that task's row and move on. Do not stop to ask; the user can allow parked steps later with \`lit approve\` (optional) or end the run with \`lit cancel\`.`);
|
|
1394
1546
|
|
|
1395
1547
|
// A run is stale, and another session may take it over, once its owning session has ended or the
|
|
1396
1548
|
// lifecycle has not been written for two hours (plans/lit-adhd.md D8).
|
|
@@ -1477,6 +1629,7 @@ const observeSearch = (args, cwd) => {
|
|
|
1477
1629
|
if (word.glob) return false;
|
|
1478
1630
|
if (!pattern) pattern = true;
|
|
1479
1631
|
else if (word.quoted || !PLAIN_PATH_WORD.test(word.text) || !existsSync(resolve(cwd, word.text))) return false;
|
|
1632
|
+
else if (sensitiveReason(canonicalTarget(resolve(cwd, word.text), "search operand"), "read")) return false;
|
|
1480
1633
|
}
|
|
1481
1634
|
return pattern;
|
|
1482
1635
|
};
|
|
@@ -1569,6 +1722,8 @@ const otherSessionDecision = (root, work, input, now) => {
|
|
|
1569
1722
|
try {
|
|
1570
1723
|
const executionRoot = canonicalDirectory(typeof input.cwd === "string" ? input.cwd : root, "tool cwd");
|
|
1571
1724
|
const classified = classifyToolAuthority(executionRoot, input);
|
|
1725
|
+
const protectedPath = classified.denied || classified.control ? null : sensitiveDenial(classified);
|
|
1726
|
+
if (protectedPath) return protectedPath;
|
|
1572
1727
|
reads = !classified.denied && !classified.control
|
|
1573
1728
|
&& (classified.chain ? classified.chain.every((link) => !link.control && READ_ACTIONS.has(link.action)) : READ_ACTIONS.has(classified.action));
|
|
1574
1729
|
} catch {
|
|
@@ -1590,7 +1745,7 @@ const otherSessionDecision = (root, work, input, now) => {
|
|
|
1590
1745
|
const takeover = isStale(work, now)
|
|
1591
1746
|
? `That session has ended or gone idle, so you can take the work over by typing ${route} here.`
|
|
1592
1747
|
: `Once that session ends or sits idle for 2 hours, you can take it over by typing ${route} here.`;
|
|
1593
|
-
return denial(`LitClaude start-work ${work.work_id} (${work.plan_name}) belongs to another session in this project (last activity ${age} ago), so this session may read but not change files. It frees up when that session finishes the work. ${takeover}
|
|
1748
|
+
return denial(`LitClaude start-work ${work.work_id} (${work.plan_name}) belongs to another session in this project (last activity ${age} ago), so this session may read but not change files. It frees up when that session finishes the work. ${takeover} To end it now, tell the user to type \`lit cancel\` here (no command line is needed).`);
|
|
1594
1749
|
};
|
|
1595
1750
|
|
|
1596
1751
|
/**
|
|
@@ -1614,7 +1769,7 @@ export const adoptStartWork = (root, { sessionId, plan, promptId = null, now = D
|
|
|
1614
1769
|
return { refused: `start-work ${work.work_id} (${work.plan_name}) is running in another session; ${plan} was not found, so nothing was taken over.` };
|
|
1615
1770
|
}
|
|
1616
1771
|
if (wanted !== work.active_plan.normalize("NFC")) {
|
|
1617
|
-
return { refused: `start-work ${work.work_id} runs a different plan (${work.plan_name}) in another session; finish or cancel it before starting ${plan}.` };
|
|
1772
|
+
return { refused: `start-work ${work.work_id} runs a different plan (${work.plan_name}) in another session; finish it, or type \`lit cancel\` to end it, before starting ${plan}.` };
|
|
1618
1773
|
}
|
|
1619
1774
|
if (!isStale(work, now)) {
|
|
1620
1775
|
return { refused: `start-work ${work.work_id} (${work.plan_name}) is still running in another session (last activity ${formatAge(idleMs(work, now))} ago); it can be taken over once that session ends or sits idle for 2 hours.` };
|
|
@@ -1625,34 +1780,59 @@ export const adoptStartWork = (root, { sessionId, plan, promptId = null, now = D
|
|
|
1625
1780
|
work.root_session_id = sessionId;
|
|
1626
1781
|
work.active_session_id = sessionId;
|
|
1627
1782
|
delete work.root_session_ended_at;
|
|
1783
|
+
// The new owner inherits the parked steps, so its `lit approve` / `lit deny` can settle them.
|
|
1784
|
+
for (const boundary of work.pending_boundaries ?? []) boundary.origin_session_id = sessionId;
|
|
1628
1785
|
appendEvent(state, work, "work.adopted", { from_session_id: from, from_age: fromAge, ...(promptId ? { origin_prompt_id: promptId } : {}) });
|
|
1629
1786
|
saveState(canonicalRoot, state);
|
|
1630
1787
|
return { adopted: { workId: work.work_id, plan: work.plan_name, fromAge } };
|
|
1631
1788
|
});
|
|
1632
1789
|
};
|
|
1633
1790
|
|
|
1791
|
+
// After `lit cancel`, the cancelled run's session (and its lanes) may still read, but every other
|
|
1792
|
+
// call is refused until the user types a new prompt there.
|
|
1793
|
+
const cancelNoticeDecision = (root, state, input) => {
|
|
1794
|
+
const notice = typeof input?.session_id === "string" ? state.cancel_notices?.[input.session_id] : null;
|
|
1795
|
+
if (!notice) return null;
|
|
1796
|
+
let reads = input.tool_name === "Skill";
|
|
1797
|
+
if (!reads) {
|
|
1798
|
+
try {
|
|
1799
|
+
const executionRoot = canonicalDirectory(typeof input.cwd === "string" ? input.cwd : root, "tool cwd");
|
|
1800
|
+
const classified = classifyToolAuthority(executionRoot, input);
|
|
1801
|
+
reads = !classified.denied && !classified.control
|
|
1802
|
+
&& (classified.chain ? classified.chain.every((link) => !link.control && READ_ACTIONS.has(link.action)) : READ_ACTIONS.has(classified.action));
|
|
1803
|
+
} catch {
|
|
1804
|
+
reads = false;
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
if (reads) return { decision: "allow-normal", action: "read", root, roots: [root] };
|
|
1808
|
+
return denial(`The user typed \`lit cancel\` and cancelled start-work ${notice.work_id} (${notice.plan_name}). Stop working on that plan: change nothing more, end this turn and tell the user it was cancelled. Reads still work; the next prompt the user types in this session lifts this.`);
|
|
1809
|
+
};
|
|
1810
|
+
|
|
1634
1811
|
export const handleStartWorkPreToolUse = (root, input, { now = Date.now() } = {}) => {
|
|
1635
1812
|
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
1636
1813
|
if (!existsSync(startWorkStatePath(canonicalRoot))) return { decision: "allow-normal" };
|
|
1637
1814
|
return withLock(canonicalRoot, () => {
|
|
1638
1815
|
const state = readState(canonicalRoot);
|
|
1639
|
-
|
|
1640
|
-
const
|
|
1641
|
-
if (!
|
|
1816
|
+
const work = state.active_work_id ? state.works[state.active_work_id] : null;
|
|
1817
|
+
const running = Boolean(work && ["active", "paused"].includes(work.status));
|
|
1818
|
+
if (!running || work.root_session_id !== input?.session_id) {
|
|
1819
|
+
const notice = cancelNoticeDecision(canonicalRoot, state, input);
|
|
1820
|
+
if (notice) return notice;
|
|
1821
|
+
}
|
|
1822
|
+
if (!running) return { decision: "allow-normal" };
|
|
1642
1823
|
if (typeof input?.session_id !== "string" || input.session_id !== work.root_session_id) {
|
|
1643
1824
|
return otherSessionDecision(canonicalRoot, work, input, now);
|
|
1644
1825
|
}
|
|
1645
|
-
if (work.status === "paused") {
|
|
1646
|
-
return denial(pausedMessage(work));
|
|
1647
|
-
}
|
|
1648
1826
|
const executionRoot = canonicalDirectory(typeof input.cwd === "string" ? input.cwd : canonicalRoot, "tool cwd");
|
|
1649
1827
|
const classified = classifyToolAuthority(executionRoot, input);
|
|
1650
1828
|
if (classified.denied) {
|
|
1651
1829
|
return input.tool_name === "Bash" && !classified.denied.startsWith("forbidden") ? bashDenial(classified.denied) : denial(classified.denied);
|
|
1652
1830
|
}
|
|
1831
|
+
const protectedPath = classified.control ? null : sensitiveDenial(classified);
|
|
1832
|
+
if (protectedPath) return protectedPath;
|
|
1653
1833
|
if (classified.control) return { decision: "allow-normal", action: "control", root: executionRoot, roots: [executionRoot] };
|
|
1654
1834
|
if (pluginSelfRead(classified)) return { decision: "allow-normal", action: "read", root: PLUGIN_ROOT, roots: [PLUGIN_ROOT] };
|
|
1655
|
-
if (!classified.chain &&
|
|
1835
|
+
if (!classified.chain && harnessAccess(classified, work, input, [canonicalRoot, input.cwd])) {
|
|
1656
1836
|
return { decision: "allow-normal", action: "read", root: classified.targetRoots?.[0] ?? classified.targetRoot, roots: classified.targetRoots ?? [classified.targetRoot] };
|
|
1657
1837
|
}
|
|
1658
1838
|
if (classified.chain) {
|
|
@@ -1673,31 +1853,47 @@ export const handleStartWorkPreToolUse = (root, input, { now = Date.now() } = {}
|
|
|
1673
1853
|
if (refused) {
|
|
1674
1854
|
return denial(`LitClaude start-work: the user denied ${refused.action} access to ${refused.root} for this work. Carry on without it, or ask the user if the task cannot be done otherwise.`);
|
|
1675
1855
|
}
|
|
1676
|
-
if (typeof input.prompt_id !== "string" || !/^[A-Za-z0-9._:-]{1,160}$/u.test(input.prompt_id)) {
|
|
1677
|
-
return denial("missing valid prompt identity for a new authority boundary");
|
|
1678
|
-
}
|
|
1679
1856
|
const targetRoot = boundaryRoot(classified.action, targetRoots[0], canonicalRoot);
|
|
1680
1857
|
const boundaryId = `boundary-${shortHash(`${work.work_id}:${classified.action}:${targetRoot}`)}`;
|
|
1681
|
-
const
|
|
1682
|
-
|
|
1683
|
-
|
|
1858
|
+
const queued = work.pending_boundaries.find(({ boundary_id: id }) => id === boundaryId);
|
|
1859
|
+
if (queued) {
|
|
1860
|
+
// A repeat changes no revision, so a lane's progress call with the revision it holds still lands.
|
|
1861
|
+
queued.hits = (queued.hits ?? 1) + 1;
|
|
1862
|
+
queued.last_seen = nowIso();
|
|
1863
|
+
saveState(canonicalRoot, state);
|
|
1864
|
+
return denial(parkedMessage(queued));
|
|
1865
|
+
}
|
|
1866
|
+
if (work.pending_boundaries.length >= MAX_PARKED) {
|
|
1867
|
+
return denial(`LitClaude start-work: ${classified.action} access to ${targetRoot} is outside this plan's scope, and ${MAX_PARKED} steps are already parked, so this call did not run. Finish what the plan allows, mark the rest \`BLOCKED: <reason>\`, and end the turn; the user decides with \`lit approve\` or \`lit cancel\`.`);
|
|
1868
|
+
}
|
|
1869
|
+
const validId = (value) => typeof value === "string" && /^[A-Za-z0-9._:-]{1,160}$/u.test(value);
|
|
1870
|
+
const originPromptId = validId(input.prompt_id) ? input.prompt_id : validId(input.tool_use_id) ? `tool:${input.tool_use_id}`.slice(0, 160) : null;
|
|
1871
|
+
if (!originPromptId) {
|
|
1872
|
+
return denial(`LitClaude start-work: ${classified.action} access to ${targetRoot} is outside this plan's scope and the call carries no prompt identity, so it did not run. Carry on with the plan's other tasks and mark a task that needs it \`BLOCKED: <reason>\`.`);
|
|
1873
|
+
}
|
|
1874
|
+
const grantId = `grant-${shortHash(`${work.work_id}:${classified.action}:${targetRoot}:${originPromptId}:${input.tool_use_id ?? "unknown"}`)}`;
|
|
1875
|
+
const requestedAt = nowIso();
|
|
1876
|
+
const boundary = {
|
|
1684
1877
|
boundary_id: boundaryId,
|
|
1685
1878
|
action: classified.action,
|
|
1686
1879
|
root: targetRoot,
|
|
1687
1880
|
origin_session_id: input.session_id,
|
|
1688
|
-
origin_prompt_id:
|
|
1881
|
+
origin_prompt_id: originPromptId,
|
|
1689
1882
|
origin_tool_use_id: typeof input.tool_use_id === "string" ? input.tool_use_id : null,
|
|
1690
1883
|
grant_id: grantId,
|
|
1691
|
-
requested_at:
|
|
1884
|
+
requested_at: requestedAt,
|
|
1885
|
+
last_seen: requestedAt,
|
|
1886
|
+
hits: 1,
|
|
1692
1887
|
};
|
|
1693
|
-
|
|
1888
|
+
work.pending_boundaries.push(boundary);
|
|
1889
|
+
appendEvent(state, work, "work.boundary_parked", {
|
|
1694
1890
|
boundary_id: boundaryId,
|
|
1695
1891
|
action: classified.action,
|
|
1696
1892
|
root: targetRoot,
|
|
1697
|
-
origin_prompt_id:
|
|
1893
|
+
origin_prompt_id: originPromptId,
|
|
1698
1894
|
});
|
|
1699
1895
|
saveState(canonicalRoot, state);
|
|
1700
|
-
return denial(
|
|
1896
|
+
return denial(parkedMessage(boundary));
|
|
1701
1897
|
});
|
|
1702
1898
|
};
|
|
1703
1899
|
|
|
@@ -1780,6 +1976,11 @@ export const recordStartWorkSessionEnd = (root, input) => {
|
|
|
1780
1976
|
});
|
|
1781
1977
|
};
|
|
1782
1978
|
|
|
1979
|
+
const clipText = (text) => {
|
|
1980
|
+
const plain = String(text).replace(/[\p{Cc}\p{Cf}]/gu, " ");
|
|
1981
|
+
return plain.length > 120 ? `…${plain.slice(-119)}` : plain;
|
|
1982
|
+
};
|
|
1983
|
+
|
|
1783
1984
|
export const handleStartWorkStop = (root, input) => {
|
|
1784
1985
|
if (input?.stop_hook_active === true) return { handled: true, output: null };
|
|
1785
1986
|
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
@@ -1796,9 +1997,16 @@ export const handleStartWorkStop = (root, input) => {
|
|
|
1796
1997
|
if (!promptId || typeof input.stop_hook_active !== "boolean") return { handled: false, output: null };
|
|
1797
1998
|
const receiptKey = `${input.session_id}:${promptId}`;
|
|
1798
1999
|
const progress = readPlanProgress(work.active_plan);
|
|
1799
|
-
|
|
2000
|
+
// Parked steps join the fingerprint, so a newly parked step earns one more continuation.
|
|
2001
|
+
const parked = work.pending_boundaries ?? [];
|
|
2002
|
+
const fingerprint = parked.length
|
|
2003
|
+
? `${progress.fingerprint}:${shortHash(parked.map(({ boundary_id: id }) => id).join(","))}`
|
|
2004
|
+
: progress.fingerprint;
|
|
2005
|
+
if (fingerprint === work.continuation.last_emitted_progress_fingerprint) {
|
|
1800
2006
|
return { handled: false, output: null };
|
|
1801
2007
|
}
|
|
2008
|
+
const parkedList = parked.slice(0, 5).map(({ action, root: parkedRoot }) => `${action} ${clipText(parkedRoot)}`).join("; ")
|
|
2009
|
+
+ (parked.length > 5 ? ` (+${parked.length - 5} more)` : "");
|
|
1802
2010
|
|
|
1803
2011
|
work.progress = progress;
|
|
1804
2012
|
appendEvent(state, work, "work.continuation-emitted", {
|
|
@@ -1807,21 +2015,24 @@ export const handleStartWorkStop = (root, input) => {
|
|
|
1807
2015
|
checked: progress.checked,
|
|
1808
2016
|
unchecked: progress.unchecked,
|
|
1809
2017
|
});
|
|
2018
|
+
const parkedNote = parked.length
|
|
2019
|
+
? ` Parked, not run: ${parkedList}. Mark a task that cannot be done without one with a \`BLOCKED: <reason>\` line under its row and carry on with the others.`
|
|
2020
|
+
: "";
|
|
1810
2021
|
const next = progress.next_task
|
|
1811
|
-
? `Continue work ${work.work_id} with next top-level task: ${progress.next_task}
|
|
2022
|
+
? `Continue work ${work.work_id} with next top-level task: ${progress.next_task}.${parkedNote}`
|
|
1812
2023
|
: `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}\`.`;
|
|
1813
2024
|
// Every open task waits on the user (BLOCKED:): say so once and let the session stop. The
|
|
1814
2025
|
// fingerprint below keeps the next Stop silent until the plan changes.
|
|
1815
2026
|
const waiting = !progress.next_task && progress.unchecked > 0;
|
|
1816
2027
|
const output = {
|
|
1817
2028
|
...(waiting
|
|
1818
|
-
? { 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
|
|
2029
|
+
? { 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)` : ""}.${parked.length ? ` Parked steps: ${parkedList.replace(/[\p{Cc}\p{Cf}]/gu, " ")}. Type \`lit approve\` to allow them, or \`lit cancel\` to end the run.` : " Remove BLOCKED: from a task or reply to carry on."}` }
|
|
1819
2030
|
: { decision: "block", reason: `LitClaude start-work continuation: ${next}` }),
|
|
1820
2031
|
work_id: work.work_id,
|
|
1821
2032
|
revision: work.revision,
|
|
1822
|
-
continuation_id: `continuation-${shortHash(`${input.session_id}:${promptId}:${work.work_id}:${work.revision}:${
|
|
2033
|
+
continuation_id: `continuation-${shortHash(`${input.session_id}:${promptId}:${work.work_id}:${work.revision}:${fingerprint}`)}`,
|
|
1823
2034
|
};
|
|
1824
|
-
work.continuation.last_emitted_progress_fingerprint =
|
|
2035
|
+
work.continuation.last_emitted_progress_fingerprint = fingerprint;
|
|
1825
2036
|
work.continuation.receipts ??= {};
|
|
1826
2037
|
work.continuation.receipts[receiptKey] = {
|
|
1827
2038
|
continuation_id: output.continuation_id,
|
|
@@ -1842,14 +2053,16 @@ export const handleStartWorkStop = (root, input) => {
|
|
|
1842
2053
|
const INVOCATION = /^\/(?:litclaude:)?start-work(?:[ \t]+(\S+))?$/u;
|
|
1843
2054
|
const APPROVE_TOKEN = /^lit[ \t]+(?:approve|승인)$/u;
|
|
1844
2055
|
const DENY_TOKEN = /^lit[ \t]+(?:deny|거절)$/u;
|
|
2056
|
+
const CANCEL_TOKEN = /^lit[ \t]+(?:cancel|취소)$/u;
|
|
1845
2057
|
const NATURAL_START = /^lit(?:work)?[ \t]+start[ \t]+work$/u;
|
|
1846
2058
|
|
|
1847
|
-
/** `{kind: "start", plan, natural?}`, `{kind: "approve"}`, `{kind: "deny"}`, or null. */
|
|
2059
|
+
/** `{kind: "start", plan, natural?}`, `{kind: "approve"}`, `{kind: "deny"}`, `{kind: "cancel"}`, or null. */
|
|
1848
2060
|
export const parseStartWorkInvocation = (prompt) => {
|
|
1849
2061
|
if (typeof prompt !== "string" || prompt.length > 512) return null;
|
|
1850
2062
|
const text = prompt.trim();
|
|
1851
2063
|
if (APPROVE_TOKEN.test(text)) return { kind: "approve" };
|
|
1852
2064
|
if (DENY_TOKEN.test(text)) return { kind: "deny" };
|
|
2065
|
+
if (CANCEL_TOKEN.test(text)) return { kind: "cancel" };
|
|
1853
2066
|
if (NATURAL_START.test(text)) return { kind: "start", plan: null, natural: true };
|
|
1854
2067
|
const match = INVOCATION.exec(text);
|
|
1855
2068
|
if (!match) return null;
|
|
@@ -1918,7 +2131,7 @@ export const startWorkFromInvocation = (root, { sessionId, promptId, plan = null
|
|
|
1918
2131
|
if (running.root_session_id === sessionId && running.active_plan.normalize("NFC") === planPath.normalize("NFC")) {
|
|
1919
2132
|
return { running: { workId: running.work_id, plan: running.plan_name, status: running.status } };
|
|
1920
2133
|
}
|
|
1921
|
-
return { refused: `start-work ${running.work_id} (${running.plan_name}) is already running here; finish or cancel it
|
|
2134
|
+
return { refused: `start-work ${running.work_id} (${running.plan_name}) is already running here; finish it first, or type \`lit cancel\` to end it.` };
|
|
1922
2135
|
}
|
|
1923
2136
|
const slug = basename(planPath, ".md").toLowerCase().replace(/[^a-z0-9]+/gu, "-").replace(/^-|-$/gu, "").slice(0, 40) || "plan";
|
|
1924
2137
|
const workId = `work-${slug}-${hash(`${sessionId}:${planPath}:${promptId}`).slice(0, 8)}`;
|
|
@@ -1937,28 +2150,46 @@ export const startWorkFromInvocation = (root, { sessionId, promptId, plan = null
|
|
|
1937
2150
|
|
|
1938
2151
|
const pendingFor = (state, sessionId) => {
|
|
1939
2152
|
const work = state?.active_work_id ? state.works[state.active_work_id] : null;
|
|
1940
|
-
return work?.status === "
|
|
2153
|
+
return work?.status === "active" && work.root_session_id === sessionId
|
|
2154
|
+
&& work.pending_boundaries.some(({ origin_session_id: origin }) => origin === sessionId) ? work : null;
|
|
1941
2155
|
};
|
|
1942
2156
|
|
|
1943
|
-
/**
|
|
2157
|
+
/**
|
|
2158
|
+
* `lit approve`: grants every parked boundary of this session's work, one fresh revision each, up to
|
|
2159
|
+
* the grant limit. Returns `{ approved: { workId, granted, remaining } }` or null when nothing is parked.
|
|
2160
|
+
*/
|
|
1944
2161
|
export const approveStartWorkBoundary = (root, { sessionId, promptId }) => {
|
|
1945
2162
|
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
1946
|
-
const
|
|
1947
|
-
if (!
|
|
1948
|
-
const
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
2163
|
+
const first = pendingFor(readState(canonicalRoot, { optional: true }), sessionId);
|
|
2164
|
+
if (!first) return null;
|
|
2165
|
+
const granted = [];
|
|
2166
|
+
let response = null;
|
|
2167
|
+
for (let step = 0; step < MAX_PARKED; step += 1) {
|
|
2168
|
+
const work = pendingFor(readState(canonicalRoot, { optional: true }), sessionId);
|
|
2169
|
+
const boundary = work?.pending_boundaries.find(({ origin_session_id: origin }) => origin === sessionId);
|
|
2170
|
+
if (!boundary) break;
|
|
2171
|
+
try {
|
|
2172
|
+
response = resumeStartWorkFromUserPrompt(canonicalRoot, {
|
|
2173
|
+
workId: work.work_id,
|
|
2174
|
+
expectedRevision: work.revision,
|
|
2175
|
+
boundaryId: boundary.boundary_id,
|
|
2176
|
+
originPromptId: boundary.origin_prompt_id,
|
|
2177
|
+
grantId: boundary.grant_id,
|
|
2178
|
+
sessionId,
|
|
2179
|
+
consumedByPromptId: promptId,
|
|
2180
|
+
});
|
|
2181
|
+
} catch (error) {
|
|
2182
|
+
if (granted.length === 0) throw error;
|
|
2183
|
+
break;
|
|
2184
|
+
}
|
|
2185
|
+
granted.push({ action: boundary.action, root: boundary.root });
|
|
2186
|
+
}
|
|
2187
|
+
const left = pendingFor(readState(canonicalRoot, { optional: true }), sessionId);
|
|
2188
|
+
const remaining = (left?.pending_boundaries ?? []).map(({ action, root: parkedRoot }) => ({ action, root: parkedRoot }));
|
|
2189
|
+
return { approved: { workId: first.work_id, granted, remaining }, response };
|
|
1959
2190
|
};
|
|
1960
2191
|
|
|
1961
|
-
/** `lit deny`:
|
|
2192
|
+
/** `lit deny`: refuses every parked boundary of this session's work; those paths then stay refused. */
|
|
1962
2193
|
export const denyStartWorkBoundary = (root, { sessionId, promptId }) => {
|
|
1963
2194
|
const canonicalRoot = canonicalDirectory(root, "cwd root");
|
|
1964
2195
|
if (!pendingFor(readState(canonicalRoot, { optional: true }), sessionId)) return null;
|
|
@@ -1966,18 +2197,18 @@ export const denyStartWorkBoundary = (root, { sessionId, promptId }) => {
|
|
|
1966
2197
|
const state = readState(canonicalRoot);
|
|
1967
2198
|
const work = pendingFor(state, sessionId);
|
|
1968
2199
|
if (!work) return null;
|
|
1969
|
-
const
|
|
1970
|
-
|
|
2200
|
+
const refused = work.pending_boundaries.filter(({ origin_session_id: origin }) => origin === sessionId);
|
|
2201
|
+
const deniedAt = nowIso();
|
|
2202
|
+
work.authority.denied_boundaries = [...(work.authority.denied_boundaries ?? []), ...refused.map((boundary) => ({
|
|
1971
2203
|
boundary_id: boundary.boundary_id,
|
|
1972
2204
|
action: boundary.action,
|
|
1973
2205
|
root: boundary.root,
|
|
1974
2206
|
denied_by_prompt_id: typeof promptId === "string" ? promptId : null,
|
|
1975
|
-
denied_at:
|
|
1976
|
-
}].slice(-MAX_GRANTS);
|
|
1977
|
-
work.
|
|
1978
|
-
work.
|
|
1979
|
-
appendEvent(state, work, "work.boundary_denied", { boundary_id: boundary.boundary_id, action: boundary.action, root: boundary.root });
|
|
2207
|
+
denied_at: deniedAt,
|
|
2208
|
+
}))].slice(-MAX_GRANTS);
|
|
2209
|
+
work.pending_boundaries = work.pending_boundaries.filter((boundary) => !refused.includes(boundary));
|
|
2210
|
+
appendEvent(state, work, "work.boundary_denied", { boundary_ids: refused.map(({ boundary_id: id }) => id) });
|
|
1980
2211
|
saveState(canonicalRoot, state);
|
|
1981
|
-
return { denied: { workId: work.work_id,
|
|
2212
|
+
return { denied: { workId: work.work_id, refused: refused.map(({ action, root: parkedRoot }) => ({ action, root: parkedRoot })) } };
|
|
1982
2213
|
});
|
|
1983
2214
|
};
|