@litfamily/litclaude 1.0.40 → 1.0.42

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.
Files changed (38) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/README.md +8 -8
  3. package/README_ko-KR.md +8 -8
  4. package/docs/assets/readme/badge-version.svg +1 -1
  5. package/docs/hooks.md +35 -8
  6. package/package.json +1 -1
  7. package/plugins/litclaude/.claude-plugin/plugin.json +1 -1
  8. package/plugins/litclaude/bin/litclaude-hook.js +49 -8
  9. package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
  10. package/plugins/litclaude/commands/lit-plan.md +5 -2
  11. package/plugins/litclaude/commands/start-work.md +8 -0
  12. package/plugins/litclaude/hooks/lit-band-client.mjs +1 -1
  13. package/plugins/litclaude/hooks/lit-mod.mjs +89 -9
  14. package/plugins/litclaude/lib/canonical-skill-resources.mjs +10 -10
  15. package/plugins/litclaude/lib/lit-plan-persistence.mjs +15 -4
  16. package/plugins/litclaude/lib/mod/frame.mjs +55 -29
  17. package/plugins/litclaude/lib/mod/looks.mjs +36 -0
  18. package/plugins/litclaude/lib/mod/motion.mjs +2 -3
  19. package/plugins/litclaude/lib/mod/state.mjs +72 -7
  20. package/plugins/litclaude/lib/mod/svg-card.mjs +13 -5
  21. package/plugins/litclaude/lib/mod/timeline.mjs +3 -3
  22. package/plugins/litclaude/lib/mod/view.mjs +155 -19
  23. package/plugins/litclaude/lib/mod/workflow.mjs +2 -0
  24. package/plugins/litclaude/lib/plan-scope-roots.mjs +76 -0
  25. package/plugins/litclaude/lib/rewind/brief.mjs +62 -8
  26. package/plugins/litclaude/lib/rewind/collect.mjs +114 -25
  27. package/plugins/litclaude/lib/session-liveness.mjs +36 -0
  28. package/plugins/litclaude/lib/start-work-lifecycle.mjs +158 -5
  29. package/plugins/litclaude/lib/workflow-stage.mjs +104 -22
  30. package/plugins/litclaude/scripts/scaffold-plan.mjs +8 -2
  31. package/plugins/litclaude/skills/lit-adhd/SKILL.md +18 -11
  32. package/plugins/litclaude/skills/lit-adhd/references/card-examples.md +2 -2
  33. package/plugins/litclaude/skills/lit-adhd/references/status-taxonomy.md +8 -3
  34. package/plugins/litclaude/skills/lit-hijack/references/capture-and-provenance.md +2 -1
  35. package/plugins/litclaude/skills/lit-hijack/scripts/hijack.mjs +40 -12
  36. package/plugins/litclaude/skills/lit-plan/SKILL.md +10 -3
  37. package/plugins/litclaude/skills/lit-typographic-motion/engine/node/assets.mjs +45 -17
  38. package/plugins/litclaude/skills/lit-typographic-motion/references/treatment.md +2 -1
@@ -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
- const applyAndWrite = (cwd, sessionId, event, now = new Date()) => {
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
- // The prompt a reviewer was given: the first user message in the head of its transcript.
413
- const transcriptPrompt = (path, bytes = 65_536) => {
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
- if (!lstatSync(path).isFile()) return "";
450
+ const info = lstatSync(path);
451
+ if (!info.isFile()) return "";
419
452
  fd = openSync(path, "r");
420
- const buffer = Buffer.alloc(bytes);
421
- head = buffer.subarray(0, readSync(fd, buffer, 0, bytes, 0)).toString("utf8");
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
- for (const line of head.split("\n").slice(0, 20)) {
428
- try {
429
- const entry = JSON.parse(line);
430
- const message = entry?.message;
431
- if (entry?.type === "user" || message?.role === "user") return resultText(message?.content ?? message);
432
- } catch {
433
- // A line cut off at the end of the head, or not an entry at all.
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
- /** SubagentStop: a reviewer's verdict, from its last message, for the lane its prompt named. */
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
- const verdict = verdictFrom(input?.last_assistant_message);
443
- if (!sessionId || !verdict) return null;
444
- const lane = laneFromTitle(transcriptPrompt(input.agent_transcript_path));
445
- return lane ? markLane(cwd, sessionId, currentRecord(cwd, sessionId), lane, verdict) : null;
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]
@@ -29,6 +29,7 @@ import { realpathSync } from "node:fs";
29
29
  import { dirname, isAbsolute, join, relative, resolve } from "node:path";
30
30
  import { fileURLToPath } from "node:url";
31
31
 
32
+ import { describeScopePath, uncoveredScopePaths } from "../lib/plan-scope-roots.mjs";
32
33
  import { parsePlanTaskRows, planLinesOutsideFences } from "../lib/plan-task-rows.mjs";
33
34
  import { ensureStateDirIgnored, resolveProjectStateRoot } from "../lib/project-state-root.mjs";
34
35
  import { readRegularStable, samePathIdentity } from "../lib/secure-path-read.mjs";
@@ -950,7 +951,7 @@ export async function scaffold(cwd, { slug, intent, reset = false, force = false
950
951
  * UNCHECKED at this point. `scripts/audit-plan-checkboxes.mjs` is the different,
951
952
  * post-completion audit that requires them checked.
952
953
  */
953
- export function checkPlanStructure(text) {
954
+ export function checkPlanStructure(text, projectRoot = null) {
954
955
  const problems = [];
955
956
  const lines = text.split(/\r?\n/u);
956
957
  const visibleLines = planLinesOutsideFences(text);
@@ -1008,6 +1009,11 @@ export function checkPlanStructure(text) {
1008
1009
  problems.push("unfilled <fill ...> placeholders remain — the plan is not decision-complete");
1009
1010
  }
1010
1011
 
1012
+ // A folder outside the project that a todo names is granted up front, never asked for mid-run.
1013
+ if (projectRoot) {
1014
+ for (const entry of uncoveredScopePaths(text, projectRoot)) problems.push(describeScopePath(entry));
1015
+ }
1016
+
1011
1017
  return { ok: problems.length === 0, problems };
1012
1018
  }
1013
1019
 
@@ -1019,7 +1025,7 @@ async function runCheck(checkPath, cwd) {
1019
1025
  throw new Error(`refused: --check cannot safely read ${checkPath}: ${read.failure}`);
1020
1026
  }
1021
1027
  const text = read.bytes.toString("utf8");
1022
- const { ok, problems } = checkPlanStructure(text);
1028
+ const { ok, problems } = checkPlanStructure(text, cwd);
1023
1029
  if (ok) {
1024
1030
  process.stdout.write(`PLAN_STRUCTURE_PASS: ${checkPath}\n`);
1025
1031
  return 0;
@@ -46,18 +46,19 @@ verdicts: [PASS, FAIL, BLOCKED]
46
46
 
47
47
  ## #contract.outputs
48
48
 
49
- The collector draws the brief in Markdown (`lib/rewind/brief.mjs`), so its shape is the same every time and a tired reader finds each part where it was last time. It has five parts, in this order:
49
+ The collector draws the brief in Markdown (`lib/rewind/brief.mjs`), so its shape is the same every time and a tired reader finds each part where it was last time. It opens with three lines, then has five parts, in this order:
50
50
 
51
+ 0. **Three opening lines**, from records only: `Done so far:` this worktree's newest commits in the window (two at most), then its completed start-work runs (`<plan> (start-work complete)`) and its plans with every row ticked (`<plan> [▉▉] 2/2`), three items at most, else its finished litgoal objective, else "nothing finished in this window"; `Doing now:` this session's top workflow frame (skill, stage, gauge), else its running start-work plan, else the newest active session's title, else "nothing running"; `Next:` the recommended step with the word to type in brackets (`(type go)`). In Korean: `지금까지:`, `지금:`, `다음: … (go 입력)`.
51
52
  1. **Headline.** One `## 🧭` line: sessions found, how many wait on the user, how many are active, and the next step in plain words: `세션 7개 · 나를 기다리는 것 1 · 진행 중 4 · 다음: 멈춘 lit-loop(verify) 이어가기` / `7 sessions · 1 waits on you · 4 active · next: Resume the paused lit-loop at verify`. A dim line under it gives the window and how many worktrees were read.
52
53
  2. **Live session cards, grouped by worktree and branch.** Sessions that wait on the user or are active come first: a `### 🌿 branch · worktree` heading per group, then one quoted card per session:
53
- - a coloured status badge (🟠 waiting on you, 🟢 active, ⚪ ended, ⚫ unknown; see `references/status-taxonomy.md`) with the reason it waits, its `id8`, how long ago it last moved, and `this session` / `이 세션` for the current one;
54
+ - a coloured status badge (🟠 waiting on you, 🟢 active, 💤 idle, ✅ done, ⚪ ended, ⚫ unknown; see `references/status-taxonomy.md`) with the reason it waits, its `id8`, how long ago it last moved, and `this session` / `이 세션` for the current one;
54
55
  - the goal in bold, from the session's title, else its first ask;
55
56
  - its progress: a gauge with the next remaining items when both numbers are recorded, otherwise the known facts after ⏳ (how long it ran and its last ask);
56
57
  - ✅ what was done: edited files and commits, or, before any edit, the tools it used most;
57
- - ▶ what is next for that session: answer the question it asked, resume its paused frame, approve its boundary, its plan's current item, or what it is doing now (its last tool call: `Bash “Run the gates”`).
58
+ - ▶ what is next for that session: answer the question it asked, resume its paused frame, approve its boundary, its plan's current item, or what it is doing now (its last tool call: `Bash “Run the gates”`, for an active session only). A done session names the plan its run finished; an idle or done session's last tool call is never offered as its next step.
58
59
  3. **Ended sessions, one table row each.** A `### ⚪ Ended · N` table (id, where, goal, ended, done), at most 8 rows and a count of the rest.
59
60
  4. **Roadmap timeline.** A `### 🗺️` heading with this worktree's roadmap gauge, then ✓ finished commits with their dates and branch, ▶ the current item of each open plan of this worktree and of plans another worktree changed inside the window (with its worktree name) with its gauge, ○ the items after it, then litgoal objectives. Stale plans elsewhere, unfilled plan scaffolds and another worktree's finished objectives are left out.
60
- 5. **One recommended next step** in a box, from `next`, with the word to type (`go`, `lit continue` or `lit approve`), then one line: "Type `go` to continue." When nothing can run on `go`, the box still recommends a real step from the records (a session waiting on the user, a paused workflow, an open plan item, the latest active session, the latest ended one) and says that nothing runs on its own.
61
+ 5. **One recommended next step** in a box, from `next`, with the word to type (`go`, `lit continue` or `lit approve`), then one line: "Type `go` to continue." When nothing can run on `go`, the box still recommends a real step from the records: first the first item under `## Next` or `## Next Steps` in this worktree's own `HANDOFF*.md`, then a session waiting on the user, a paused workflow, an open plan item, the latest active session, then the newest listed session that is not running (review what a done one finished, or pick up an idle or ended one). Only a window with no session and no plan says there is nothing to start. It says that nothing runs on its own, and a HANDOFF step never carries a word to type.
61
62
 
62
63
  **Progress gauges (D9), required.** A gauge appears only when both numbers are real, in the form `[▉▉▉░░] 3/5` (filled `▉` done, light `░` remaining, then done/total). An unknown total has no gauge: the card states what is known in words instead. Never a question-mark gauge, never a guess, never an estimate, never a gauge of your own.
63
64
 
@@ -102,24 +103,27 @@ The collector (`plugins/litclaude/lib/rewind/collect.mjs`, served as `litclaude-
102
103
  | Source | What it gives | Missing reads |
103
104
  | --- | --- | --- |
104
105
  | Claude Code transcripts, `<config>/projects/<slug>/*.jsonl` | per session: title (custom, then AI, then first prompt), first and last ask, tools used, files changed, last assistant text, status | `transcripts: unknown` |
105
- | `plans/*.md` checkbox rows | open plans, current item, done/total, remaining names | `plans: unknown` |
106
+ | `plans/*.md` checkbox rows | open plans changed inside the window (this worktree's too), current item, done/total, remaining names | `plans: unknown` |
106
107
  | `.litclaude/litgoal/goals.json` | objective and passed/total criteria | `litgoal: unknown` |
107
- | `HANDOFF*.md` | headings from the first 40 lines only | `handoffs: unknown` |
108
+ | `HANDOFF*.md` | headings from the first 40 lines; for this worktree's own file only, the first item under `## Next` / `## Next Steps` | `handoffs: unknown` |
108
109
  | `git log --since` | commits in the window, matched to sessions by time and branch | `git: unknown` |
109
110
  | `.litclaude/workflow-stack/*.json` | running and paused disciplines with stage and k/n | `workflowStack: unknown` |
110
- | `.litclaude/boulder.json` | active start-work, its plan progress and any boundary waiting for approval | `startWork: unknown` |
111
+ | `.litclaude/boulder.json` | active start-work, its plan progress and any boundary waiting for approval; completed runs from its history | `startWork: unknown` |
112
+ | `.litclaude/liveness/*.json` | each session's last hook event (`alive`, `idle`, `ended`), written by PostToolUse, Stop and SessionEnd | the transcript time alone decides |
111
113
  | `herdr agent list` (only when `HERDR_ENV=1`) | agent panes | `herdr: unknown` |
112
114
 
113
- Transcripts are read head (64 KiB) and tail (256 KiB) only, under one 8 MiB budget for the whole run, through descriptors opened without following links; subagent transcripts and sidechain lines are skipped. The slug is the session's absolute cwd with every character outside `[A-Za-z0-9]` turned into `-`; a folder whose slug is missing is found by the `cwd` its newest transcript records. Every string is redacted before it leaves the collector: credential shapes, `NAME=value` with a secret-like name, URI userinfo, any current environment value of eight or more characters, and the home directory (shown as `~`).
115
+ Plans, litgoal, handoffs, workflow stacks and start-work are read first, then transcripts, so a busy transcript folder never crowds out the plans; a plan met after the budget ran out is counted and the brief says how many were not read. Transcripts are read head (64 KiB) and tail (256 KiB) only, under one 8 MiB budget for the whole run, through descriptors opened without following links; subagent transcripts and sidechain lines are skipped. The slug is the session's absolute cwd with every character outside `[A-Za-z0-9]` turned into `-`; a folder whose slug is missing is found by the `cwd` its newest transcript records. Every string is redacted before it leaves the collector: credential shapes, `NAME=value` with a secret-like name, URI userinfo, any current environment value of eight or more characters, and the home directory (shown as `~`).
114
116
 
115
117
  ## Status taxonomy
116
118
 
117
119
  - `waiting-on-user`: the session's last word was the assistant asking something, or it holds a paused workflow frame or a start-work boundary awaiting `lit approve`.
118
120
  - `active`: written to within the last 15 minutes and not waiting.
119
- - `ended`: quiet for longer than that.
121
+ - `done`: its start-work run completed in the window and it has not moved since.
122
+ - `idle`: its last hook event was a Stop at least as new as its last transcript line (another session's only; this session is always active while it runs the brief).
123
+ - `ended`: quiet for longer than 15 minutes, or its last hook event was SessionEnd.
120
124
  - `unknown`: the transcript held no timestamp.
121
125
 
122
- Sessions waiting on the user come first, then active ones, newest first.
126
+ Sessions waiting on the user come first, then active ones, then idle and done ones, newest first.
123
127
 
124
128
  ## The next step
125
129
 
@@ -163,6 +167,9 @@ The colours move by hue at a steady lightness, so the card never flashes: at mos
163
167
  | The brief says no session records were found | No `projects/` folder under the Claude config dir | Print it as drawn; plans and goals still show |
164
168
  | The brief says older sessions were not read | The 8 MiB budget ran out | Print it as drawn |
165
169
  | A card shows ⏳ facts and no gauge | No stack, plan or start-work records a total for that session | Print it as drawn; do not estimate |
166
- | The box recommends a step with no word to type | `next.kind: none`; the step is drawn from the records | Print it as drawn; do not run it or invent another |
170
+ | The box recommends a step with no word to type | `next.kind: none`; the step is drawn from the records (this worktree's HANDOFF.md Next item first) | Print it as drawn; do not run it or invent another |
171
+ | The brief says N plans were not read | The read budget ran out before those plan files | Print it as drawn |
172
+ | A plan you expected is missing | It was last changed before the window (`--since`, 7 days by default) | Print it as drawn; a wider `--since` lists it |
173
+ | `Doing now: nothing running` | No frame, start-work or active session is on record | Print it as drawn |
167
174
 
168
175
  See `references/card-examples.md` for complete briefs in English and Korean and `references/status-taxonomy.md` for the status wording in both languages.
@@ -57,7 +57,7 @@ with the language.
57
57
  - ○ later · 12. go continues
58
58
  - ○ later · 13. card
59
59
 
60
- ```text
60
+ ```
61
61
  ╭─ RECOMMENDED NEXT STEP ──────────────╮
62
62
  │ Resume the paused lit-loop at verify │
63
63
  │ type: lit continue │
@@ -104,7 +104,7 @@ Type **`lit continue`** to continue.
104
104
  - ○ 이후 · 12. go continues
105
105
  - ○ 이후 · 13. card
106
106
 
107
- ```text
107
+ ```
108
108
  ╭─ 추천하는 다음 단계 ───────────╮
109
109
  │ 멈춘 lit-loop(verify) 이어가기 │
110
110
  │ 입력: lit continue │
@@ -1,20 +1,25 @@
1
1
  # lit-adhd status taxonomy
2
2
 
3
3
  The collector assigns every session exactly one status. The brief renders it in the user's language
4
- with the words below and never invents a fifth.
4
+ with the words below and never invents another.
5
5
 
6
6
  | Status | Set when | English | 한국어 |
7
7
  | --- | --- | --- | --- |
8
8
  | `waiting-on-user` | The last transcript entry is the assistant asking something (a closing `?`, `lit approve`, `확인해 주세요`, `할까요`…), or the session holds a paused workflow frame or a start-work boundary | waiting on you | 나를 기다림 |
9
9
  | `active` | A transcript write within the last 15 minutes and not waiting | active | 진행 중 |
10
- | `ended` | Quiet for longer than 15 minutes | ended | 끝남 |
10
+ | `done` | Its start-work run completed inside the window (boulder history) and its liveness record shows no activity after that | done | 완료 |
11
+ | `idle` | Another session whose newest liveness record is `idle`, at least as new as its last transcript line | idle | 쉬는 중 |
12
+ | `ended` | Quiet for longer than 15 minutes, or its newest liveness record is `ended` | ended | 끝남 |
11
13
  | `unknown` | The transcript held no timestamp | unknown | 모름 |
12
14
 
15
+ The session running the brief is always `active`, and a `waiting-on-user` session keeps that status
16
+ whatever its liveness record says.
17
+
13
18
  `waitingReason` says why a session waits: `asked the user`, `paused workflow` or
14
19
  `start-work boundary`. Name it in the card's status cell when present: `waiting on you (paused
15
20
  workflow)` / `나를 기다림 (멈춘 워크플로)`.
16
21
 
17
- Order in the brief: waiting sessions first, then active, ended and unknown; newest first inside each group.
22
+ Order in the brief: waiting sessions first, then active, then idle and done, then ended and unknown; newest first inside each group.
18
23
 
19
24
  ## Sources
20
25
 
@@ -75,7 +75,8 @@ title, the author and date from the page's metadata, and a `rel=license` link if
75
75
  Every fetch is https only, on the first request and on each redirect. Redirects are followed one
76
76
  hop at a time, at most five, and a hop to `localhost`, a loopback, link-local or private address, or
77
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 body is counted while it streams and dropped past 20 MiB,
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,
79
80
  whatever length the server declares. For an `http://` page, ask the user for a saved copy and capture
80
81
  it with `--kind file --url <url>`.
81
82
 
@@ -6,8 +6,10 @@ import { spawnSync } from "node:child_process";
6
6
  import { createHash } from "node:crypto";
7
7
  import { lookup as dnsLookup } from "node:dns/promises";
8
8
  import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, writeFileSync } from "node:fs";
9
+ import { request as httpsRequest } from "node:https";
9
10
  import { isIP, isIPv4, isIPv6 } from "node:net";
10
11
  import { extname, isAbsolute, join, relative, resolve } from "node:path";
12
+ import { Readable } from "node:stream";
11
13
  import { fileURLToPath } from "node:url";
12
14
 
13
15
  export const LEDGER_SCHEMA = "litclaude.hijack-ledger.v1";
@@ -556,6 +558,8 @@ export const buildImplementerBrief = (run) => {
556
558
  // A capture follows redirects by hand: every hop must be https and name a public host, so a public
557
559
  // page cannot bounce the fetch into loopback, the cloud metadata address or the local network. The
558
560
  // body is counted as it streams and dropped past the cap, whatever length the server declared.
561
+ // The connection goes to the address the check approved, so a name that answers again with a
562
+ // private address (DNS rebinding) cannot move it; TLS still checks the certificate for the name.
559
563
  const FETCH_HOPS = 5;
560
564
  const privateV4 = (ip) => {
561
565
  const [a, b] = ip.split(".").map(Number);
@@ -579,12 +583,31 @@ const checkHop = async (href, lookup) => {
579
583
  if (url.protocol !== "https:") throw new Error(`refusing ${url.protocol} ${href}: captures fetch https only`);
580
584
  const host = url.hostname.replace(/^\[|\]$/gu, "");
581
585
  if (host === "localhost" || host.endsWith(".localhost") || isPrivateAddress(host)) throw new Error(`refusing ${href}: a loopback, link-local or private host`);
582
- if (!isIP(host) && lookup) {
583
- const addresses = await lookup(host, { all: true });
584
- if (addresses.some(({ address }) => isPrivateAddress(address))) throw new Error(`refusing ${href}: ${host} resolves to a private address`);
585
- }
586
- return url.href;
587
- };
586
+ if (isIP(host)) return { href: url.href, address: host, family: isIP(host) };
587
+ if (!lookup) return { href: url.href, address: null, family: 0 };
588
+ const addresses = await lookup(host, { all: true });
589
+ if (addresses.length === 0) throw new Error(`refusing ${href}: ${host} does not resolve`);
590
+ if (addresses.some(({ address }) => isPrivateAddress(address))) throw new Error(`refusing ${href}: ${host} resolves to a private address`);
591
+ return { href: url.href, address: addresses[0].address, family: addresses[0].family };
592
+ };
593
+ // node:https with a lookup that answers only with the approved address, read back as a Response.
594
+ const pinnedFetch = (request) => (href, { headers, signal }, { address, family }) => new Promise((resolveResponse, reject) => {
595
+ const pin = (_host, options, callback) => (options?.all ? callback(null, [{ address, family }]) : callback(null, address, family));
596
+ const req = request(href, { headers, signal, lookup: pin }, (res) => {
597
+ const answer = new Headers();
598
+ for (const [name, value] of Object.entries(res.headers)) for (const item of [value].flat()) if (item !== undefined) answer.append(name, String(item));
599
+ const empty = [204, 205, 304].includes(res.statusCode);
600
+ if (empty) res.resume();
601
+ try {
602
+ resolveResponse(new Response(empty ? null : Readable.toWeb(res), { status: res.statusCode, headers: answer }));
603
+ } catch (error) {
604
+ res.destroy();
605
+ reject(error);
606
+ }
607
+ });
608
+ req.on("error", reject);
609
+ req.end();
610
+ });
588
611
  const readCapped = async (response, url, limit) => {
589
612
  const declared = Number(response.headers.get("content-length"));
590
613
  const tooLarge = () => new Error(`${url} is larger than ${limit} bytes`);
@@ -612,16 +635,21 @@ const readCapped = async (response, url, limit) => {
612
635
  }
613
636
  };
614
637
 
615
- /** Fetches a public https URL; `fetchImpl` and `lookup` are injectable for tests. */
616
- export const fetchBytes = async (url, { fetchImpl = fetch, lookup = fetchImpl === fetch ? dnsLookup : null, limit = FETCH_LIMIT } = {}) => {
617
- let current = await checkHop(url, lookup);
638
+ /**
639
+ * Fetches a public https URL over a connection pinned to the checked address. `fetchImpl` (a
640
+ * fetch-shaped stub, unpinned), `request` (node:https's) and `lookup` are injectable for tests.
641
+ */
642
+ export const fetchBytes = async (url, { fetchImpl = null, request = httpsRequest, lookup = fetchImpl ? null : dnsLookup, limit = FETCH_LIMIT } = {}) => {
643
+ const send = fetchImpl ? (href, init) => fetchImpl(href, init) : pinnedFetch(request);
644
+ let hop = await checkHop(url, lookup);
618
645
  const signal = AbortSignal.timeout(30_000);
619
- for (let hop = 0; hop <= FETCH_HOPS; hop += 1) {
620
- const response = await fetchImpl(current, { headers: { "user-agent": "litclaude-lit-hijack/1 (+capture)" }, redirect: "manual", signal });
646
+ for (let count = 0; count <= FETCH_HOPS; count += 1) {
647
+ const current = hop.href;
648
+ const response = await send(current, { headers: { "user-agent": "litclaude-lit-hijack/1 (+capture)" }, redirect: "manual", signal }, hop);
621
649
  const location = response.status >= 300 && response.status < 400 ? response.headers.get("location") : null;
622
650
  if (location) {
623
651
  await response.body?.cancel?.();
624
- current = await checkHop(new URL(location, current).href, lookup);
652
+ hop = await checkHop(new URL(location, current).href, lookup);
625
653
  continue;
626
654
  }
627
655
  if (!response.ok) throw new Error(`${current} answered HTTP ${response.status}`);
@@ -89,11 +89,18 @@ fresh Claude Code session execute without re-solving the architecture.
89
89
  This skill is **planning-only**. You must not implement, must not edit files for
90
90
  product changes, and must not run mutating commands. Do not call any start-work
91
91
  tool from inside planning mode. Close the saved plan with one step: tell the
92
- user to type `/litclaude:start-work plans/<slug>.md`; typing it approves this plan and runs it,
93
- so no second confirm reply and no `/goal` line is needed. The hook starts the work
92
+ user to type `go` within 30 minutes, or `/litclaude:start-work plans/<slug>.md`;
93
+ typing it approves this plan and runs it, so no second confirm reply and no `/goal` line is needed. The
94
+ Stop hook saves the plan as this session's next step once the plan file is written, which is
95
+ what lets the one word `go` start it. The hook starts the work
94
96
  with grants derived from the project; a plan that needs more names it on a line
95
97
  such as `Scope roots: <path> (read)`, and anything else outside the
96
- project pauses until the user answers `lit approve` or `lit deny`.
98
+ project pauses until the user answers `lit approve` or `lit deny`. Every absolute
99
+ path a todo names outside the project must sit under such a line: `scaffold-plan.mjs
100
+ --check` and the Stop hook list each uncovered one with the exact line to paste
101
+ (`Scope roots: <existing folder> (read)`), and the Stop hook blocks until it is there.
102
+ Widen `(read)` by hand when a lane must write in that folder. A command quoted in
103
+ backticks is data and is not read for paths.
97
104
 
98
105
  ## Planning Contract
99
106
 
@@ -8,8 +8,10 @@
8
8
  import { createHash } from "node:crypto";
9
9
  import { lookup as dnsLookup } from "node:dns/promises";
10
10
  import { mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
11
+ import { request as httpsRequest } from "node:https";
11
12
  import { isIP, isIPv4, isIPv6 } from "node:net";
12
13
  import path from "node:path";
14
+ import { Readable } from "node:stream";
13
15
  import { EXIT } from "../core/constants.mjs";
14
16
  import { BlockedError } from "./chrome.mjs";
15
17
  import { rasterInfo } from "./stage-serve.mjs";
@@ -84,6 +86,8 @@ export function pageFacts(html, base) {
84
86
  // Every hop, the first request and each redirect, must be https to a public host: a product page
85
87
  // or README image must not bounce the fetch into loopback, the cloud metadata address or the local
86
88
  // network. Bodies are counted as they stream, so a missing or false content-length cannot buffer more.
89
+ // The request connects to the address the check approved, so a name that answers again with a
90
+ // private address (DNS rebinding) cannot move it; TLS still checks the certificate for the name.
87
91
  const MAX_HOPS = 5;
88
92
  const privateV4 = (ip) => {
89
93
  const [a, b] = ip.split(".").map(Number);
@@ -107,11 +111,32 @@ async function checkHop(href, lookup) {
107
111
  if (url.protocol !== "https:") throw new Error(`refusing ${url.protocol} ${href}: assets are fetched over https only`);
108
112
  const host = url.hostname.replace(/^\[|\]$/gu, "");
109
113
  if (host === "localhost" || host.endsWith(".localhost") || privateAddress(host)) throw new Error(`refusing ${href}: a loopback, link-local or private host`);
110
- if (!isIP(host) && lookup) {
111
- const addresses = await lookup(host, { all: true });
112
- if (addresses.some(({ address }) => privateAddress(address))) throw new Error(`refusing ${href}: ${host} resolves to a private address`);
113
- }
114
- return url.href;
114
+ if (isIP(host)) return { href: url.href, address: host, family: isIP(host) };
115
+ if (!lookup) return { href: url.href, address: null, family: 0 };
116
+ const addresses = await lookup(host, { all: true });
117
+ if (addresses.length === 0) throw new Error(`refusing ${href}: ${host} does not resolve`);
118
+ if (addresses.some(({ address }) => privateAddress(address))) throw new Error(`refusing ${href}: ${host} resolves to a private address`);
119
+ return { href: url.href, address: addresses[0].address, family: addresses[0].family };
120
+ }
121
+ // node:https with a lookup that answers only with the approved address, read back as a Response.
122
+ function pinnedFetch(request) {
123
+ return (href, { headers, signal }, { address, family }) => new Promise((resolve, reject) => {
124
+ const pin = (_host, options, callback) => (options?.all ? callback(null, [{ address, family }]) : callback(null, address, family));
125
+ const req = request(href, { headers, signal, lookup: pin }, (res) => {
126
+ const answer = new Headers();
127
+ for (const [name, value] of Object.entries(res.headers)) for (const item of [value].flat()) if (item !== undefined) answer.append(name, String(item));
128
+ const empty = [204, 205, 304].includes(res.statusCode);
129
+ if (empty) res.resume();
130
+ try {
131
+ resolve(new Response(empty ? null : Readable.toWeb(res), { status: res.statusCode, headers: answer }));
132
+ } catch (error) {
133
+ res.destroy();
134
+ reject(error);
135
+ }
136
+ });
137
+ req.on("error", reject);
138
+ req.end();
139
+ });
115
140
  }
116
141
  async function readCapped(res, url, limit) {
117
142
  const declared = Number(res.headers.get("content-length"));
@@ -139,15 +164,16 @@ async function readCapped(res, url, limit) {
139
164
  }
140
165
  }
141
166
 
142
- async function get(fetchImpl, url, { accept, limit, lookup }) {
143
- let current = await checkHop(url, lookup);
167
+ async function get(send, url, { accept, limit, lookup }) {
168
+ let hop = await checkHop(url, lookup);
144
169
  const signal = AbortSignal.timeout(ASSET_LIMITS.timeoutMs);
145
- for (let hop = 0; hop <= MAX_HOPS; hop += 1) {
146
- const res = await fetchImpl(current, { headers: { accept, "user-agent": "lit-typographic-motion-assets" }, redirect: "manual", signal });
170
+ for (let count = 0; count <= MAX_HOPS; count += 1) {
171
+ const current = hop.href;
172
+ const res = await send(current, { headers: { accept, "user-agent": "lit-typographic-motion-assets" }, redirect: "manual", signal }, hop);
147
173
  const location = res.status >= 300 && res.status < 400 ? res.headers.get("location") : null;
148
174
  if (location) {
149
175
  await res.body?.cancel?.();
150
- current = await checkHop(new URL(location, current).href, lookup);
176
+ hop = await checkHop(new URL(location, current).href, lookup);
151
177
  continue;
152
178
  }
153
179
  if (!res.ok) throw new Error(`${res.status} from ${current}`);
@@ -162,10 +188,12 @@ function roleFor(url, fallback) {
162
188
  }
163
189
 
164
190
  /**
165
- * Fetch a product's assets into <out>. `fetchImpl` is injectable for tests. Returns { code, message,
166
- * product }; throws BlockedError 22 when nothing could be reached.
191
+ * Fetch a product's assets into <out> over connections pinned to each checked address. `fetchImpl` (a
192
+ * fetch-shaped stub, unpinned), `request` (node:https's) and `lookup` are injectable for tests.
193
+ * Returns { code, message, product }; throws BlockedError 22 when nothing could be reached.
167
194
  */
168
- export async function fetchAssets({ out, url, into = "stage", fetchImpl = globalThis.fetch, lookup = fetchImpl === globalThis.fetch ? dnsLookup : null, now = () => new Date() }) {
195
+ export async function fetchAssets({ out, url, into = "stage", fetchImpl = null, request = httpsRequest, lookup = fetchImpl ? null : dnsLookup, now = () => new Date() }) {
196
+ const send = fetchImpl ? (href, init) => fetchImpl(href, init) : pinnedFetch(request);
169
197
  let link;
170
198
  try {
171
199
  link = new URL(url);
@@ -187,7 +215,7 @@ export async function fetchAssets({ out, url, into = "stage", fetchImpl = global
187
215
  const [, owner, rname] = repo;
188
216
  name = rname;
189
217
  try {
190
- const meta = JSON.parse((await get(fetchImpl, `https://api.github.com/repos/${owner}/${rname}`, { accept: "application/vnd.github+json", limit: ASSET_LIMITS.pageBytes, lookup })).toString("utf8"));
218
+ const meta = JSON.parse((await get(send, `https://api.github.com/repos/${owner}/${rname}`, { accept: "application/vnd.github+json", limit: ASSET_LIMITS.pageBytes, lookup })).toString("utf8"));
191
219
  Object.assign(words, { name: meta.name ?? rname, description: meta.description ?? null, homepage: meta.homepage || null, topics: meta.topics ?? [] });
192
220
  name = meta.name ?? rname;
193
221
  if (meta.owner?.avatar_url) candidates.push({ url: meta.owner.avatar_url, role: "icon", note: "owner avatar" });
@@ -195,7 +223,7 @@ export async function fetchAssets({ out, url, into = "stage", fetchImpl = global
195
223
  problems.push(`repository: ${error.message}`);
196
224
  }
197
225
  try {
198
- const readme = (await get(fetchImpl, `https://api.github.com/repos/${owner}/${rname}/readme`, { accept: "application/vnd.github.raw", limit: ASSET_LIMITS.pageBytes, lookup })).toString("utf8");
226
+ const readme = (await get(send, `https://api.github.com/repos/${owner}/${rname}/readme`, { accept: "application/vnd.github.raw", limit: ASSET_LIMITS.pageBytes, lookup })).toString("utf8");
199
227
  writeFileSync(path.join(wordsDir, "README.md"), readme);
200
228
  words.readme = "product/README.md";
201
229
  const images = readmeImages(readme, `https://raw.githubusercontent.com/${owner}/${rname}/HEAD/`).map((u) => ({ url: u.replace(/^https:\/\/github\.com\/([^/]+\/[^/]+)\/blob\//u, "https://raw.githubusercontent.com/$1/"), role: "readme-image" }));
@@ -205,7 +233,7 @@ export async function fetchAssets({ out, url, into = "stage", fetchImpl = global
205
233
  }
206
234
  } else {
207
235
  try {
208
- const html = (await get(fetchImpl, link.href, { accept: "text/html", limit: ASSET_LIMITS.pageBytes, lookup })).toString("utf8");
236
+ const html = (await get(send, link.href, { accept: "text/html", limit: ASSET_LIMITS.pageBytes, lookup })).toString("utf8");
209
237
  const facts = pageFacts(html, link.href);
210
238
  Object.assign(words, { title: facts.title, description: facts.description });
211
239
  if (facts.title) name = facts.title.split(/\s[|·—–-]\s/u)[0].trim() || name;
@@ -221,7 +249,7 @@ export async function fetchAssets({ out, url, into = "stage", fetchImpl = global
221
249
  for (const c of candidates) {
222
250
  if (assets.length >= ASSET_LIMITS.files) break;
223
251
  try {
224
- const buf = await get(fetchImpl, c.url, { accept: "image/*", limit: ASSET_LIMITS.fileBytes, lookup });
252
+ const buf = await get(send, c.url, { accept: "image/*", limit: ASSET_LIMITS.fileBytes, lookup });
225
253
  const kind = sniffImage(buf);
226
254
  if (!kind) throw new Error("not an image");
227
255
  if (kind === "svg" && !cleanSvg(buf.toString("utf8"))) throw new Error("an SVG with script or outside links");
@@ -157,7 +157,8 @@ node scripts/motion.mjs assets --out <dir> --url <the link from the request>
157
157
  ```
158
158
 
159
159
  It reaches only `https` pages, on every redirect too: a hop to `localhost` or a loopback, link-local
160
- or private address is refused, and each body is counted as it streams. For a GitHub repository it
160
+ or private address is refused, each connection goes to the address that check approved, and each
161
+ body is counted as it streams. For a GitHub repository it
161
162
  reads the repository metadata, the owner avatar and the README with its images (badges skipped); for
162
163
  another site, its `og:image` and icons. Each raster is sniffed and decoded before it is kept,
163
164
  animated images are skipped, an SVG is cleaned of scripts, and the limits are 8 files, 4 MB a file