@litfamily/litclaude 1.0.39 → 1.0.41
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 +36 -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 +35 -8
- package/package.json +1 -1
- package/plugins/litclaude/.claude-plugin/plugin.json +1 -1
- package/plugins/litclaude/bin/litclaude-hook.js +11 -2
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/hooks/lit-band-client.mjs +1 -1
- package/plugins/litclaude/hooks/lit-mod.mjs +66 -8
- package/plugins/litclaude/lib/canonical-skill-resources.mjs +11 -11
- package/plugins/litclaude/lib/interface-probe-gate.mjs +4 -5
- package/plugins/litclaude/lib/lit-plan-persistence.mjs +4 -5
- package/plugins/litclaude/lib/litgoal/autoloop.mjs +4 -5
- package/plugins/litclaude/lib/litgoal/cli.mjs +4 -5
- package/plugins/litclaude/lib/litgoal/ledger.mjs +4 -5
- package/plugins/litclaude/lib/litgoal/state.mjs +4 -6
- package/plugins/litclaude/lib/mod/frame.mjs +47 -28
- package/plugins/litclaude/lib/mod/looks.mjs +36 -0
- package/plugins/litclaude/lib/mod/motion.mjs +2 -3
- package/plugins/litclaude/lib/mod/state.mjs +6 -3
- package/plugins/litclaude/lib/mod/svg-card.mjs +4 -1
- package/plugins/litclaude/lib/mod/timeline.mjs +3 -3
- package/plugins/litclaude/lib/mod/view.mjs +80 -11
- package/plugins/litclaude/lib/mod/workflow.mjs +2 -0
- package/plugins/litclaude/lib/motion-render-gate.mjs +4 -5
- package/plugins/litclaude/lib/project-state-root.mjs +44 -2
- package/plugins/litclaude/lib/rewind/brief.mjs +5 -2
- package/plugins/litclaude/lib/rewind/collect.mjs +16 -12
- package/plugins/litclaude/lib/rewind/next-step.mjs +4 -5
- package/plugins/litclaude/lib/rewind/redact.mjs +28 -8
- package/plugins/litclaude/lib/rewind/suggest.mjs +9 -4
- package/plugins/litclaude/lib/rewind/transcripts.mjs +4 -4
- package/plugins/litclaude/lib/start-work-lifecycle.mjs +6 -9
- package/plugins/litclaude/lib/workflow-stack.mjs +4 -5
- package/plugins/litclaude/lib/workflow-stage.mjs +104 -22
- package/plugins/litclaude/skills/lit-hijack/references/capture-and-provenance.md +8 -0
- package/plugins/litclaude/skills/lit-hijack/references/distil-and-licence.md +5 -0
- package/plugins/litclaude/skills/lit-hijack/scripts/hijack.mjs +115 -15
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/assets.mjs +110 -15
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-serve.mjs +13 -3
- package/plugins/litclaude/skills/lit-typographic-motion/references/treatment.md +10 -7
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { basename } from "node:path";
|
|
9
9
|
|
|
10
10
|
import { clipToWidth, displayWidth } from "./gauge.mjs";
|
|
11
|
+
import { stripControls } from "./redact.mjs";
|
|
11
12
|
|
|
12
13
|
const WORDS = {
|
|
13
14
|
en: {
|
|
@@ -152,9 +153,11 @@ const stamp = (iso) => {
|
|
|
152
153
|
return `${two(at.getMonth() + 1)}-${two(at.getDate())} ${two(at.getHours())}:${two(at.getMinutes())}`;
|
|
153
154
|
};
|
|
154
155
|
// Inline code that cannot be broken by a backtick inside the data.
|
|
155
|
-
const code = (text) => `\`${
|
|
156
|
+
const code = (text) => `\`${stripControls(text).replace(/`/gu, "'")}\``;
|
|
156
157
|
// One line of data as Markdown text: no line breaks, no tags, and its emphasis marks escaped.
|
|
157
|
-
|
|
158
|
+
// Every value printed passes through here or `code`, so a control sequence the collector missed
|
|
159
|
+
// (an older record, a hand-made fixture) still cannot reach the terminal.
|
|
160
|
+
const bare = (text) => stripControls(text).replace(/\s+/gu, " ").trim();
|
|
158
161
|
const plain = (text) => bare(text).replace(/[<>`]/gu, (ch) => ({ "<": "‹", ">": "›", "`": "'" }[ch])).replace(/[*_|[\]\\]/gu, (ch) => `\\${ch}`);
|
|
159
162
|
|
|
160
163
|
// The last question the session asked, from its last assistant words.
|
|
@@ -105,9 +105,9 @@ const plansIn = (root, budget, redact, local) => {
|
|
|
105
105
|
plan: `plans/${entry.name}`,
|
|
106
106
|
local,
|
|
107
107
|
changedMs: mtimeOf(join(root, "plans", entry.name)),
|
|
108
|
-
rows: rows.map((row) => ({ checked: row.checked, title: redact(
|
|
109
|
-
current: redact(
|
|
110
|
-
progress: progressOf(done, rows.length, open.map((row) => redact(
|
|
108
|
+
rows: rows.map((row) => ({ checked: row.checked, title: clipToWidth(redact(row.text), NAME_MAX) })),
|
|
109
|
+
current: clipToWidth(redact(open[0].text), NAME_MAX),
|
|
110
|
+
progress: progressOf(done, rows.length, open.map((row) => clipToWidth(redact(row.text), NAME_MAX))),
|
|
111
111
|
}];
|
|
112
112
|
});
|
|
113
113
|
};
|
|
@@ -116,11 +116,11 @@ const litgoalOf = (root, budget, redact) => {
|
|
|
116
116
|
const goals = readJson(join(root, ".litclaude", "litgoal", "goals.json"), budget);
|
|
117
117
|
if (!goals || !Array.isArray(goals.criteria)) return null;
|
|
118
118
|
const passed = goals.criteria.filter((criterion) => criterion?.status === "passed");
|
|
119
|
-
const remaining = goals.criteria.filter((criterion) => criterion?.status !== "passed").map((criterion) => redact(
|
|
119
|
+
const remaining = goals.criteria.filter((criterion) => criterion?.status !== "passed").map((criterion) => clipToWidth(redact(String(criterion?.description ?? criterion?.id ?? "unknown")), NAME_MAX));
|
|
120
120
|
return {
|
|
121
121
|
worktree: redact(root),
|
|
122
122
|
status: typeof goals.status === "string" ? goals.status : "unknown",
|
|
123
|
-
objective: redact(
|
|
123
|
+
objective: clipToWidth(redact(String(goals.objective ?? "unknown").split("\n")[0]), 120),
|
|
124
124
|
progress: progressOf(passed.length, goals.criteria.length, remaining),
|
|
125
125
|
};
|
|
126
126
|
};
|
|
@@ -129,7 +129,7 @@ const handoffsOf = (root, budget, redact) => (entries(root) ?? [])
|
|
|
129
129
|
.filter((entry) => entry.isFile() && /^HANDOFF.*\.md$/u.test(entry.name))
|
|
130
130
|
.map((entry) => {
|
|
131
131
|
const text = readSmallFile(join(root, entry.name), budget) ?? "";
|
|
132
|
-
const headings = text.split("\n").slice(0, 40).filter((line) => /^#{1,3} /u.test(line)).map((line) => redact(
|
|
132
|
+
const headings = text.split("\n").slice(0, 40).filter((line) => /^#{1,3} /u.test(line)).map((line) => clipToWidth(redact(line), 100));
|
|
133
133
|
return { worktree: redact(root), file: entry.name, headings };
|
|
134
134
|
});
|
|
135
135
|
|
|
@@ -140,7 +140,7 @@ const commitsOf = (root, sinceMs, now, exec, redact) => {
|
|
|
140
140
|
const out = exec("git", ["log", `--since=${since}`, "--max-count=20", "--format=%H%x09%cI%x09%s"], { cwd: root, timeout: GIT_TIMEOUT_MS });
|
|
141
141
|
return out.split("\n").filter(Boolean).map((line) => {
|
|
142
142
|
const [hash, at, ...subject] = line.split("\t");
|
|
143
|
-
return { worktree: redact(root), branch: redact(branch), hash: hash.slice(0, 7), at, atMs: Date.parse(at), subject: redact(
|
|
143
|
+
return { worktree: redact(root), branch: redact(branch), hash: hash.slice(0, 7), at, atMs: Date.parse(at), subject: clipToWidth(redact(subject.join("\t")), 100) };
|
|
144
144
|
});
|
|
145
145
|
} catch {
|
|
146
146
|
return null;
|
|
@@ -163,7 +163,7 @@ const stacksOf = (root, budget, redact) => {
|
|
|
163
163
|
role: frame.role === "spine" ? "spine" : "side",
|
|
164
164
|
status: frame.status === "paused" ? "paused" : "active",
|
|
165
165
|
at: typeof frame.at === "string" ? frame.at : "unknown",
|
|
166
|
-
progress: progressOf(frame.n, frame.total, Array.isArray(frame.remaining) ? frame.remaining.map((name) => redact(
|
|
166
|
+
progress: progressOf(frame.n, frame.total, Array.isArray(frame.remaining) ? frame.remaining.map((name) => clipToWidth(redact(String(name)), NAME_MAX)) : undefined),
|
|
167
167
|
}));
|
|
168
168
|
});
|
|
169
169
|
};
|
|
@@ -178,8 +178,8 @@ const startWorkOf = (root, budget, redact) => {
|
|
|
178
178
|
const rows = planText === null ? [] : parsePlanTaskRows(planText);
|
|
179
179
|
const open = rows.filter((row) => !row.checked);
|
|
180
180
|
const progress = rows.length
|
|
181
|
-
? progressOf(rows.length - open.length, rows.length, open.map((row) => redact(
|
|
182
|
-
: progressOf(work.progress?.checked, work.progress?.total, work.progress?.next_task ? [redact(
|
|
181
|
+
? progressOf(rows.length - open.length, rows.length, open.map((row) => clipToWidth(redact(row.text), NAME_MAX)))
|
|
182
|
+
: progressOf(work.progress?.checked, work.progress?.total, work.progress?.next_task ? [clipToWidth(redact(work.progress.next_task), NAME_MAX)] : undefined);
|
|
183
183
|
return [{
|
|
184
184
|
worktree: redact(root),
|
|
185
185
|
workId: work.work_id,
|
|
@@ -196,7 +196,7 @@ const herdrOf = (env, exec, redact) => {
|
|
|
196
196
|
if (env.HERDR_ENV !== "1") return { status: "unknown", agents: [] };
|
|
197
197
|
try {
|
|
198
198
|
const out = exec("herdr", ["agent", "list"], { timeout: HERDR_TIMEOUT_MS });
|
|
199
|
-
return { status: "ok", agents: out.split("\n").filter((line) => line.trim()).slice(0, 20).map((line) => redact(
|
|
199
|
+
return { status: "ok", agents: out.split("\n").filter((line) => line.trim()).slice(0, 20).map((line) => clipToWidth(redact(line.trim()), 120)) };
|
|
200
200
|
} catch {
|
|
201
201
|
return { status: "unknown", agents: [] };
|
|
202
202
|
}
|
|
@@ -230,6 +230,7 @@ export const collectRewind = ({
|
|
|
230
230
|
const listed = here ? null : worktreesOf(start, exec);
|
|
231
231
|
const roots = [...new Set([start, ...(here ? [] : listed ?? [stateRoot])])];
|
|
232
232
|
|
|
233
|
+
const rootSet = new Set(roots.map((root) => resolve(root).normalize("NFC")));
|
|
233
234
|
const transcripts = findTranscripts(env.CLAUDE_CONFIG_DIR || join(home, ".claude"), roots);
|
|
234
235
|
const sessions = [];
|
|
235
236
|
for (const file of transcripts.files) {
|
|
@@ -237,7 +238,10 @@ export const collectRewind = ({
|
|
|
237
238
|
const lines = readTranscriptLines(file, budget);
|
|
238
239
|
const session = lines ? sessionRecord(lines, { redact, now }) : null;
|
|
239
240
|
if (!session || (session.lastMs !== null && now - session.lastMs > sinceMs)) continue;
|
|
240
|
-
|
|
241
|
+
// Claude's folder slug maps every non-alphanumeric to `-`, so `client_a` and `client-a` share one
|
|
242
|
+
// folder; a session counts only when the cwd it recorded is one of the folders asked about.
|
|
243
|
+
const recorded = session.cwd ? resolve(session.cwd).normalize("NFC") : null;
|
|
244
|
+
if (here ? recorded && recorded !== start.normalize("NFC") : !recorded || !rootSet.has(recorded)) continue;
|
|
241
245
|
sessions.push(session);
|
|
242
246
|
}
|
|
243
247
|
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
// 4. a single open plan with no work running -> start-plan (`/litclaude:start-work <plan>`)
|
|
7
7
|
// 5. otherwise -> none
|
|
8
8
|
|
|
9
|
-
import { closeSync, constants, fstatSync,
|
|
9
|
+
import { closeSync, constants, fstatSync, openSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
11
|
|
|
12
12
|
import { ignitionFileName } from "../mod/state.mjs";
|
|
13
|
-
import {
|
|
13
|
+
import { requireStateDir, STATE_WRITE_FLAG } from "../project-state-root.mjs";
|
|
14
14
|
|
|
15
15
|
export const chooseNextStep = (data, sessionId) => {
|
|
16
16
|
const ownStack = data.workflows.find((frame) => frame.sessionId === sessionId && frame.role === "spine" && frame.status === "paused");
|
|
@@ -36,10 +36,9 @@ export const nextStepPath = (stateRoot, sessionId) => join(stateRoot, ".litclaud
|
|
|
36
36
|
/** Writes `{kind, target, at}` for this session, whole, through a temporary file. */
|
|
37
37
|
export const writeNextStep = (stateRoot, sessionId, step, now = new Date()) => {
|
|
38
38
|
const path = nextStepPath(stateRoot, sessionId);
|
|
39
|
-
|
|
40
|
-
ensureStateDirIgnored(path);
|
|
39
|
+
requireStateDir(dirname(path));
|
|
41
40
|
const staging = `${path}.${process.pid}.tmp`;
|
|
42
|
-
writeFileSync(staging, `${JSON.stringify({ kind: step.kind, target: step.target, at: now.toISOString() })}\n
|
|
41
|
+
writeFileSync(staging, `${JSON.stringify({ kind: step.kind, target: step.target, at: now.toISOString() })}\n`, { flag: STATE_WRITE_FLAG });
|
|
43
42
|
renameSync(staging, path);
|
|
44
43
|
return path;
|
|
45
44
|
};
|
|
@@ -1,22 +1,40 @@
|
|
|
1
|
-
// Redaction for every string the lit-adhd collector emits.
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
1
|
+
// Redaction for every string the lit-adhd collector emits. Terminal escape sequences, control and
|
|
2
|
+
// format characters go first, so neither an OSC link in a commit subject nor a zero-width space
|
|
3
|
+
// inside a key survives. Credential shapes, webhook URLs and URI userinfo come next; `NAME=value`
|
|
4
|
+
// and JSON `"name": "value"` pairs with a secret-like name lose their value; any substring equal to
|
|
5
|
+
// a current environment value of 8+ characters is replaced (compared here, never printed); the home
|
|
6
|
+
// directory becomes `~`. Path-shaped and locale/terminal values are not credentials and stay, or
|
|
7
|
+
// every path in the brief would be blanked; a URL is kept only when it is a bare origin. Callers
|
|
8
|
+
// redact the whole text and clip afterwards, so a clip cannot cut a secret below its shape.
|
|
6
9
|
|
|
7
10
|
import { SECRET_SHAPE_PATTERNS, URI_USERINFO_PATTERN } from "../secret-shapes.mjs";
|
|
8
11
|
|
|
9
12
|
const MASK = "[redacted]";
|
|
10
|
-
const SECRET_NAME = /KEY|TOKEN|SECRET|PASS|AUTH|COOKIE/iu;
|
|
13
|
+
const SECRET_NAME = /KEY|TOKEN|SECRET|PASS|AUTH|COOKIE|WEBHOOK/iu;
|
|
11
14
|
const ASSIGNMENT = /\b([A-Za-z_][A-Za-z0-9_]*)=("[^"]*"|'[^']*'|[^\s"'`]+)/gu;
|
|
15
|
+
const JSON_PAIR = /"([A-Za-z_][A-Za-z0-9_-]*)"(\s*:\s*)"(?:[^"\\]|\\.)*"/gu;
|
|
16
|
+
const WEBHOOK = /\bhttps?:\/\/(?:hooks\.slack\.com\/(?:services|workflows|triggers)|(?:[a-z0-9-]+\.)?discord(?:app)?\.com\/api\/webhooks|[a-z0-9-]+\.webhook\.office\.com|outlook\.office\.com\/webhook)\/[^\s"'`<>]+/giu;
|
|
17
|
+
// CSI and OSC sequences whole, then any other C0/C1 control (tab and newline stay) and format character.
|
|
18
|
+
const TERMINAL_SEQUENCE = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)?|\u009b[0-?]*[ -/]*[@-~]|\u009d[^\u0007\u001b]*(?:\u0007|\u001b\\)?|\u001b[@-_]?/gu;
|
|
19
|
+
const CONTROL = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\p{Cf}]/gu;
|
|
20
|
+
export const stripControls = (text) => String(text).replace(TERMINAL_SEQUENCE, "").replace(CONTROL, "");
|
|
12
21
|
const PLAIN_ENV_NAMES = /^(?:PATH|HOME|PWD|OLDPWD|SHELL|USER|LOGNAME|LANG|LANGUAGE|TERM|TERM_PROGRAM|TERM_PROGRAM_VERSION|COLORTERM|EDITOR|VISUAL|PAGER|TMPDIR|SHLVL|LC_[A-Z]+|XPC_[A-Z_]+|__CF[A-Z_]*|COMMAND_MODE|_)$/u;
|
|
13
22
|
const globalOf = (pattern) => new RegExp(pattern.source, pattern.flags.includes("g") ? pattern.flags : `${pattern.flags}g`);
|
|
14
23
|
const SHAPES = [...SECRET_SHAPE_PATTERNS.map(globalOf)];
|
|
15
24
|
const USERINFO = globalOf(URI_USERINFO_PATTERN);
|
|
16
25
|
|
|
26
|
+
// A URL-form value is a secret when it carries more than an origin: a webhook path, a query or userinfo.
|
|
27
|
+
const carriesUrlSecret = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
const url = new URL(value);
|
|
30
|
+
return /^https?:$/u.test(url.protocol) && (url.pathname.length > 1 || url.search !== "" || url.username !== "");
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
17
35
|
const envSecrets = (env) => Object.entries(env ?? {})
|
|
18
36
|
.filter(([name, value]) => typeof value === "string" && value.length >= 8 && !PLAIN_ENV_NAMES.test(name)
|
|
19
|
-
&& !/^[~/]/u.test(value) && !value.includes(":/") && !/^(?:true|false|\d+)$/iu.test(value))
|
|
37
|
+
&& !/^[~/]/u.test(value) && (!value.includes(":/") || carriesUrlSecret(value)) && !/^(?:true|false|\d+)$/iu.test(value))
|
|
20
38
|
.map(([, value]) => value)
|
|
21
39
|
.sort((a, b) => b.length - a.length);
|
|
22
40
|
|
|
@@ -25,10 +43,12 @@ export const makeRedactor = ({ env = process.env, home = env?.HOME } = {}) => {
|
|
|
25
43
|
const values = envSecrets(env);
|
|
26
44
|
return (input) => {
|
|
27
45
|
if (typeof input !== "string" || input === "") return input;
|
|
28
|
-
let text = input;
|
|
46
|
+
let text = stripControls(input);
|
|
29
47
|
for (const value of values) if (text.includes(value)) text = text.split(value).join(MASK);
|
|
48
|
+
text = text.replace(WEBHOOK, MASK);
|
|
30
49
|
text = text.replace(USERINFO, (match) => match.replace(/\/\/[^/?#\s]+@/u, `//${MASK}@`));
|
|
31
50
|
text = text.replace(ASSIGNMENT, (match, name) => (SECRET_NAME.test(name) ? `${name}=${MASK}` : match));
|
|
51
|
+
text = text.replace(JSON_PAIR, (match, name, colon) => (SECRET_NAME.test(name) ? `"${name}"${colon}"${MASK}"` : match));
|
|
32
52
|
for (const pattern of SHAPES) text = text.replace(pattern, MASK);
|
|
33
53
|
if (typeof home === "string" && home.length > 1) text = text.split(home).join("~");
|
|
34
54
|
return text;
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
// last three days, say once a day that `lit adhd` briefs them all on one screen. It looks only at
|
|
3
3
|
// this folder's own transcript folder (no scan of other projects) and stats file times, never
|
|
4
4
|
// contents, so it stays cheap on every session start. A marker under `.litclaude/adhd/` keeps it
|
|
5
|
-
// to one nudge per calendar day per project.
|
|
6
|
-
|
|
5
|
+
// to one nudge per calendar day per project. A symlinked `.litclaude`, folder or marker (a cloned
|
|
6
|
+
// repository can carry one) is never followed: the nudge is then skipped, not written elsewhere.
|
|
7
|
+
import { lstatSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
|
|
7
8
|
import { join } from "node:path";
|
|
8
9
|
|
|
10
|
+
import { prepareStateDir, STATE_WRITE_FLAG } from "../project-state-root.mjs";
|
|
9
11
|
import { projectSlug } from "./transcripts.mjs";
|
|
10
12
|
|
|
11
13
|
export const RECENT_MS = 3 * 24 * 60 * 60 * 1000;
|
|
@@ -40,12 +42,15 @@ export const adhdSuggestion = ({ cwd, sessionId, configDir, stateRoot, now = Dat
|
|
|
40
42
|
if (count === 0) return null;
|
|
41
43
|
const dir = join(stateRoot, ".litclaude", "adhd");
|
|
42
44
|
const marker = join(dir, "suggested.json");
|
|
45
|
+
if (!prepareStateDir(dir)) return null;
|
|
43
46
|
try {
|
|
47
|
+
if (lstatSync(marker).isSymbolicLink()) return null;
|
|
44
48
|
if (JSON.parse(readFileSync(marker, "utf8")).day === dayOf(now)) return null;
|
|
45
49
|
} catch {
|
|
46
50
|
// No marker yet, or an unreadable one: suggest and rewrite it.
|
|
47
51
|
}
|
|
48
|
-
|
|
49
|
-
writeFileSync(
|
|
52
|
+
const staging = `${marker}.${process.pid}.tmp`;
|
|
53
|
+
writeFileSync(staging, `${JSON.stringify({ day: dayOf(now) })}\n`, { flag: STATE_WRITE_FLAG });
|
|
54
|
+
renameSync(staging, marker);
|
|
50
55
|
return `${count} other recent ${count === 1 ? "session" : "sessions"} here · type \`lit adhd\` for a one-screen brief of where each stands`;
|
|
51
56
|
};
|
|
@@ -236,7 +236,7 @@ export const sessionRecord = (lines, { redact = (text) => text, now = Date.now()
|
|
|
236
236
|
return inside && !inside.startsWith("..") ? inside : path;
|
|
237
237
|
};
|
|
238
238
|
const changed = [...new Set(files.reverse())].slice(0, 5).map((path) => redact(relativeFile(path)));
|
|
239
|
-
const asked = [...new Set([prompts[0], prompts.at(-1)].filter(Boolean))].slice(0, 2).map((text) => redact(
|
|
239
|
+
const asked = [...new Set([prompts[0], prompts.at(-1)].filter(Boolean))].slice(0, 2).map((text) => clip(redact(text), 160));
|
|
240
240
|
const waiting = lastEntry?.role === "assistant" && WAITING_TEXT.test(lastEntry.text.slice(-400));
|
|
241
241
|
const status = last === null ? "unknown" : waiting ? "waiting-on-user" : now - last < ACTIVE_MS ? "active" : "ended";
|
|
242
242
|
return {
|
|
@@ -248,11 +248,11 @@ export const sessionRecord = (lines, { redact = (text) => text, now = Date.now()
|
|
|
248
248
|
started: started === null ? "unknown" : new Date(started).toISOString(),
|
|
249
249
|
last: last === null ? "unknown" : new Date(last).toISOString(),
|
|
250
250
|
lastMs: last,
|
|
251
|
-
title: redact(
|
|
251
|
+
title: clip(redact(customTitle ?? aiTitle ?? prompts[0] ?? "unknown"), 80),
|
|
252
252
|
asked: asked.length ? asked : ["unknown"],
|
|
253
253
|
done: { tools, files: changed, commits: [] },
|
|
254
|
-
lastAction: lastAction ? { tool: lastAction.tool, ...(lastAction.target ? { target: redact(
|
|
255
|
-
result: result ? redact(
|
|
254
|
+
lastAction: lastAction ? { tool: lastAction.tool, ...(lastAction.target ? { target: clip(redact(lastAction.target), 60) } : {}) } : null,
|
|
255
|
+
result: result ? clip(redact(result), 240) : "unknown",
|
|
256
256
|
status,
|
|
257
257
|
...(waiting ? { waitingReason: "asked the user" } : {}),
|
|
258
258
|
};
|
|
@@ -21,7 +21,7 @@ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:pat
|
|
|
21
21
|
import { fileURLToPath } from "node:url";
|
|
22
22
|
|
|
23
23
|
import { parsePlanTaskRows } from "./plan-task-rows.mjs";
|
|
24
|
-
import {
|
|
24
|
+
import { requireStateDir, STATE_APPEND_FLAG, STATE_WRITE_FLAG } from "./project-state-root.mjs";
|
|
25
25
|
import { pathIdentity, samePathIdentity } from "./secure-path-read.mjs";
|
|
26
26
|
|
|
27
27
|
const SCHEMA_VERSION = 3;
|
|
@@ -67,10 +67,9 @@ export const startWorkLockDir = (root) => join(startWorkStateDir(root), ".lock")
|
|
|
67
67
|
const startWorkLockOwnerPath = (root) => join(startWorkLockDir(root), "owner.json");
|
|
68
68
|
|
|
69
69
|
const atomicWriteJson = (path, value) => {
|
|
70
|
-
|
|
71
|
-
ensureStateDirIgnored(path);
|
|
70
|
+
requireStateDir(dirname(path));
|
|
72
71
|
const temporary = `${path}.${process.pid}.${Date.now()}.tmp`;
|
|
73
|
-
writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
|
|
72
|
+
writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600, flag: STATE_WRITE_FLAG });
|
|
74
73
|
const fd = openSync(temporary, "r");
|
|
75
74
|
fsyncSync(fd);
|
|
76
75
|
closeSync(fd);
|
|
@@ -107,8 +106,7 @@ const readLockOwner = (root) => {
|
|
|
107
106
|
|
|
108
107
|
export const acquireStartWorkLock = (root, options = {}) => {
|
|
109
108
|
const lockDir = startWorkLockDir(root);
|
|
110
|
-
|
|
111
|
-
ensureStateDirIgnored(lockDir);
|
|
109
|
+
requireStateDir(dirname(lockDir));
|
|
112
110
|
const configured = Number.parseInt(process.env.LITCLAUDE_START_WORK_LOCK_TIMEOUT_MS ?? "5000", 10);
|
|
113
111
|
const timeout = Number.isFinite(options.timeoutMs)
|
|
114
112
|
? Math.max(0, options.timeoutMs)
|
|
@@ -319,14 +317,13 @@ const assertLedgerCompatible = (existing, stateEvents) => {
|
|
|
319
317
|
|
|
320
318
|
const reconcileLedger = (root, state) => {
|
|
321
319
|
const path = startWorkLedgerPath(root);
|
|
322
|
-
|
|
323
|
-
ensureStateDirIgnored(path);
|
|
320
|
+
requireStateDir(dirname(path));
|
|
324
321
|
const existing = ledgerRecords(root);
|
|
325
322
|
assertLedgerCompatible(existing, state.events);
|
|
326
323
|
const ids = new Set(existing.map(({ event_id: eventId }) => eventId).filter(Boolean));
|
|
327
324
|
for (const event of state.events) {
|
|
328
325
|
if (ids.has(event.event_id)) continue;
|
|
329
|
-
appendFileSync(path, `${JSON.stringify(event)}\n`, { mode: 0o600 });
|
|
326
|
+
appendFileSync(path, `${JSON.stringify(event)}\n`, { mode: 0o600, flag: STATE_APPEND_FLAG });
|
|
330
327
|
ids.add(event.event_id);
|
|
331
328
|
}
|
|
332
329
|
if (existsSync(path)) {
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
// card reads it back through its own guarded read. Frames keep skills, stages and counts only;
|
|
11
11
|
// never a prompt, a command or a path other than a project-relative plan name.
|
|
12
12
|
|
|
13
|
-
import { closeSync, constants, fstatSync, lstatSync,
|
|
13
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, renameSync, writeFileSync } from "node:fs";
|
|
14
14
|
import { dirname, join } from "node:path";
|
|
15
15
|
|
|
16
16
|
import { ignitionFileName } from "./mod/state.mjs";
|
|
17
17
|
import { DISCIPLINE_ENTRY, REVIEW_LANES, STAGE_UNITS, VERDICT_STATES, normalizeStage } from "./mod/workflow.mjs";
|
|
18
|
-
import {
|
|
18
|
+
import { requireStateDir, resolveProjectStateRoot, STATE_WRITE_FLAG } from "./project-state-root.mjs";
|
|
19
19
|
|
|
20
20
|
export const MAX_FRAMES = 3;
|
|
21
21
|
export const MAX_HISTORY = 20;
|
|
@@ -234,10 +234,9 @@ export const readStack = (cwd, sessionId) => {
|
|
|
234
234
|
/** Writes the whole stack through a temporary file; a link at the destination is replaced, never followed. */
|
|
235
235
|
export const writeStack = (cwd, sessionId, stack) => {
|
|
236
236
|
const path = stackPath(cwd, sessionId);
|
|
237
|
-
|
|
238
|
-
ensureStateDirIgnored(path);
|
|
237
|
+
requireStateDir(dirname(path));
|
|
239
238
|
const staging = `${path}.${process.pid}.tmp`;
|
|
240
|
-
writeFileSync(staging, `${JSON.stringify(stack)}\n`, { flag:
|
|
239
|
+
writeFileSync(staging, `${JSON.stringify(stack)}\n`, { flag: STATE_WRITE_FLAG });
|
|
241
240
|
renameSync(staging, path);
|
|
242
241
|
return stack;
|
|
243
242
|
};
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
// only which stage, which lane and how many; never a path, a command or a prompt.
|
|
15
15
|
|
|
16
16
|
import { closeSync, lstatSync, openSync, readFileSync, readSync, readdirSync, realpathSync, statSync } from "node:fs";
|
|
17
|
-
import { join, relative, resolve } from "node:path";
|
|
17
|
+
import { dirname, join, relative, resolve } from "node:path";
|
|
18
18
|
|
|
19
19
|
import { DISCIPLINE_ENTRY, STAGE_UNITS, VERDICT_STATES, WORKFLOW_FAMILIES, WORKFLOW_FRESH_MS, normalizeStage, reviewLaneOf } from "./mod/workflow.mjs";
|
|
20
|
-
import { resolveProjectStateRoot } from "./project-state-root.mjs";
|
|
20
|
+
import { requireStateDir, resolveProjectStateRoot } from "./project-state-root.mjs";
|
|
21
21
|
import { appendLitgoalLedger } from "./litgoal/ledger.mjs";
|
|
22
22
|
import { litgoalGoalsPath, litgoalLedgerPath } from "./litgoal/paths.mjs";
|
|
23
23
|
import { readLitgoalState } from "./litgoal/state.mjs";
|
|
24
|
+
import { acquireOwnerLock, OwnerLockError, releaseOwnerLock } from "./owner-lock.mjs";
|
|
24
25
|
import { readPlanProgress } from "./start-work-lifecycle.mjs";
|
|
25
26
|
import { applyStackEvent, readStack, stackPath, writeStack } from "./workflow-stack.mjs";
|
|
26
27
|
|
|
@@ -59,11 +60,43 @@ const logStackTransitions = (cwd, transitions) => {
|
|
|
59
60
|
}
|
|
60
61
|
};
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
// Hooks run as separate processes, and five background reviewers can stop within the same second:
|
|
64
|
+
// each move reads, applies and writes under the stack's lock, so one never drops another's verdict.
|
|
65
|
+
// A lock held past the timeout leaves the move unlocked rather than lost.
|
|
66
|
+
const withStackLock = (cwd, sessionId, body) => {
|
|
67
|
+
const lockDir = `${stackPath(cwd, sessionId)}.lock`;
|
|
68
|
+
requireStateDir(dirname(lockDir));
|
|
69
|
+
let owner = null;
|
|
70
|
+
try {
|
|
71
|
+
owner = acquireOwnerLock(lockDir, { timeoutMs: 2_000, staleMs: 30_000 });
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if (!(error instanceof OwnerLockError)) throw error;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
return body();
|
|
77
|
+
} finally {
|
|
78
|
+
if (owner) releaseOwnerLock(lockDir, owner);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const applyAndWrite = (cwd, sessionId, event, now = new Date()) => withStackLock(cwd, sessionId, () => {
|
|
63
83
|
const { stack, transitions } = applyStackEvent(readStack(cwd, sessionId), event, now);
|
|
64
84
|
writeStack(cwd, sessionId, stack);
|
|
65
85
|
logStackTransitions(cwd, transitions);
|
|
66
86
|
return { stack, transitions };
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* SessionEnd: marks the session's stack `endedAt`, so other sessions' cards drop its row at once
|
|
91
|
+
* instead of after the stack goes quiet. The next move of a resumed session writes the stack anew,
|
|
92
|
+
* without the mark. A session with no frames writes nothing.
|
|
93
|
+
*/
|
|
94
|
+
export const endWorkflowStack = (cwd, sessionId, now = new Date()) => {
|
|
95
|
+
if (typeof sessionId !== "string" || !sessionId) return;
|
|
96
|
+
withStackLock(cwd, sessionId, () => {
|
|
97
|
+
const stack = readStack(cwd, sessionId);
|
|
98
|
+
if (stack.frames.length) writeStack(cwd, sessionId, { ...stack, endedAt: now.toISOString() });
|
|
99
|
+
});
|
|
67
100
|
};
|
|
68
101
|
|
|
69
102
|
/**
|
|
@@ -409,40 +442,89 @@ export const observeWorkflowPostTool = (cwd, input, { filePaths = [], lifecycleR
|
|
|
409
442
|
return moved;
|
|
410
443
|
};
|
|
411
444
|
|
|
412
|
-
//
|
|
413
|
-
const
|
|
445
|
+
// `bytes` of a reviewer's transcript from `at` ("head" or "tail"), or "" when it is not a file.
|
|
446
|
+
const readTranscript = (path, bytes, at) => {
|
|
414
447
|
if (typeof path !== "string" || !path.endsWith(".jsonl")) return "";
|
|
415
448
|
let fd;
|
|
416
|
-
let head = "";
|
|
417
449
|
try {
|
|
418
|
-
|
|
450
|
+
const info = lstatSync(path);
|
|
451
|
+
if (!info.isFile()) return "";
|
|
419
452
|
fd = openSync(path, "r");
|
|
420
|
-
const
|
|
421
|
-
|
|
453
|
+
const start = at === "tail" ? Math.max(0, info.size - bytes) : 0;
|
|
454
|
+
const buffer = Buffer.alloc(Math.min(bytes, info.size));
|
|
455
|
+
return buffer.subarray(0, readSync(fd, buffer, 0, buffer.length, start)).toString("utf8");
|
|
422
456
|
} catch {
|
|
423
457
|
return "";
|
|
424
458
|
} finally {
|
|
425
459
|
if (fd !== undefined) closeSync(fd);
|
|
426
460
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
const entryOf = (line) => {
|
|
464
|
+
try {
|
|
465
|
+
return JSON.parse(line);
|
|
466
|
+
} catch {
|
|
467
|
+
return null; // A line cut off at either end of the read, or not an entry at all.
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
// The prompt a reviewer was given: the first user message in the head of its transcript.
|
|
472
|
+
const transcriptPrompt = (path) => {
|
|
473
|
+
for (const line of readTranscript(path, 65_536, "head").split("\n").slice(0, 20)) {
|
|
474
|
+
const entry = entryOf(line);
|
|
475
|
+
if (entry?.type === "user" || entry?.message?.role === "user") return resultText(entry.message?.content ?? entry.message);
|
|
476
|
+
}
|
|
477
|
+
return "";
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
// A reviewer's final report from the end of its transcript: the message of its `SubagentHandback`
|
|
481
|
+
// call (how a background agent reports), or the text of a last assistant message that calls no
|
|
482
|
+
// tool. "" while the last assistant entry is still mid-work or not on disk yet.
|
|
483
|
+
const transcriptReport = (path) => {
|
|
484
|
+
const lines = readTranscript(path, 262_144, "tail").split("\n");
|
|
485
|
+
for (let index = lines.length - 1; index >= 0; index -= 1) {
|
|
486
|
+
const entry = entryOf(lines[index]);
|
|
487
|
+
const content = entry?.type === "assistant" || entry?.message?.role === "assistant" ? entry.message?.content : undefined;
|
|
488
|
+
if (!Array.isArray(content)) continue;
|
|
489
|
+
const handback = content.findLast((block) => block?.type === "tool_use" && block.name === "SubagentHandback");
|
|
490
|
+
if (handback) return typeof handback.input?.message === "string" ? handback.input.message : "";
|
|
491
|
+
if (content.some((block) => block?.type === "tool_use")) return "";
|
|
492
|
+
return content.filter((block) => block?.type === "text").map((block) => block.text).join("\n");
|
|
435
493
|
}
|
|
436
494
|
return "";
|
|
437
495
|
};
|
|
438
496
|
|
|
439
|
-
|
|
497
|
+
// The host can run SubagentStop before it flushes the lane's last entries to the transcript, so a
|
|
498
|
+
// lane's report is read again for a short while until it is on disk.
|
|
499
|
+
const REPORT_WAIT_MS = 3_000;
|
|
500
|
+
const REPORT_POLL_MS = 100;
|
|
501
|
+
const awaitReport = (path) => {
|
|
502
|
+
const deadline = Date.now() + REPORT_WAIT_MS;
|
|
503
|
+
for (;;) {
|
|
504
|
+
const report = transcriptReport(path);
|
|
505
|
+
if (report || Date.now() >= deadline) return report;
|
|
506
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, REPORT_POLL_MS);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* SubagentStop: a reviewer's verdict for the lane its prompt names: a `Review lane:` title, else
|
|
512
|
+
* (for a lane review-work already marked) the prompt's first line, which is how the model headed a
|
|
513
|
+
* background lane's prompt on the host. The verdict is the last message's, else the transcript's
|
|
514
|
+
* final report.
|
|
515
|
+
*/
|
|
440
516
|
export const observeWorkflowSubagentStop = (cwd, input) => {
|
|
441
517
|
const sessionId = typeof input?.session_id === "string" ? input.session_id : null;
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
518
|
+
if (!sessionId) return null;
|
|
519
|
+
const prompt = transcriptPrompt(input.agent_transcript_path);
|
|
520
|
+
let lane = laneFromTitle(prompt);
|
|
521
|
+
if (!lane) {
|
|
522
|
+
const heading = reviewLaneOf(prompt.trimStart().split("\n", 1)[0]);
|
|
523
|
+
lane = heading && nearestRecord(cwd, sessionId, "main", "review")?.verdicts?.[heading] ? heading : null;
|
|
524
|
+
}
|
|
525
|
+
if (!lane) return null;
|
|
526
|
+
const verdict = verdictFrom(input.last_assistant_message) ?? verdictFrom(awaitReport(input.agent_transcript_path));
|
|
527
|
+
return verdict ? markLane(cwd, sessionId, currentRecord(cwd, sessionId), lane, verdict) : null;
|
|
446
528
|
};
|
|
447
529
|
|
|
448
530
|
const USAGE = `Usage: litclaude-ai workflow-stage <family> <stage> [--n N] [--total M] [--unit ${STAGE_UNITS.join("|")}] [--verdict <name>=${VERDICT_STATES.join("|")}]... [--session <id>] [--json]
|
|
@@ -72,6 +72,14 @@ terms, and a single skill folder can be source-available inside an otherwise per
|
|
|
72
72
|
title, the author and date from the page's metadata, and a `rel=license` link if there is one
|
|
73
73
|
(Creative Commons pages usually carry it). Scripts, styles and navigation are dropped from the text.
|
|
74
74
|
|
|
75
|
+
Every fetch is https only, on the first request and on each redirect. Redirects are followed one
|
|
76
|
+
hop at a time, at most five, and a hop to `localhost`, a loopback, link-local or private address, or
|
|
77
|
+
a name that resolves to one is refused, so a public page cannot bounce the capture into the cloud
|
|
78
|
+
metadata service or the local network. The connection goes to the address the check approved, so a
|
|
79
|
+
name that answers again with a private address cannot move it. The body is counted while it streams and dropped past 20 MiB,
|
|
80
|
+
whatever length the server declares. For an `http://` page, ask the user for a saved copy and capture
|
|
81
|
+
it with `--kind file --url <url>`.
|
|
82
|
+
|
|
75
83
|
- A page that needs a login, shows a challenge, or answers with a cookie wall is not captured. Ask
|
|
76
84
|
the user for an export or a saved copy, then capture that file with `--kind file --url <url>`.
|
|
77
85
|
- A page that loads its article with scripts may come back nearly empty. Check the extracted text
|
|
@@ -93,6 +93,11 @@ wording. `hijack.mjs licence` applies this table from the captured licence evide
|
|
|
93
93
|
| Anything else | unrecognised | `ideas-only` | Treated as all rights reserved until a person says otherwise |
|
|
94
94
|
| Text that states reuse terms | restricted-terms | `needs-review` | "do not copy", "no part of this", "source-available", "proprietary", "confidential" |
|
|
95
95
|
|
|
96
|
+
Reuse terms count on any line of the source and outrank a permissive identifier: a page that says
|
|
97
|
+
MIT in one paragraph and "do not redistribute this guide" in another is `needs-review`. A checklist
|
|
98
|
+
label such as "DO NOT COPY: the hero layout" (a prohibition followed by a colon) is advice about the
|
|
99
|
+
subject, not a term, and does not count.
|
|
100
|
+
|
|
96
101
|
`needs-review` blocks the licence phase until a person decides:
|
|
97
102
|
|
|
98
103
|
```text
|