@litfamily/litcodex 1.0.33 → 1.0.35

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 (59) hide show
  1. package/README-Ko-KR.md +9 -9
  2. package/README.md +9 -9
  3. package/dist/cli.js +63 -0
  4. package/dist/install/agent-file/apply.d.ts +35 -0
  5. package/dist/install/agent-file/apply.js +141 -0
  6. package/dist/install/agent-file/attribution.d.ts +15 -0
  7. package/dist/install/agent-file/attribution.js +54 -0
  8. package/dist/install/agent-file/bodies.d.ts +14 -0
  9. package/dist/install/agent-file/bodies.js +40 -0
  10. package/dist/install/agent-file/cli.d.ts +70 -0
  11. package/dist/install/agent-file/cli.js +174 -0
  12. package/dist/install/agent-file/managed-block.d.ts +28 -0
  13. package/dist/install/agent-file/managed-block.js +103 -0
  14. package/dist/install/agent-file/mode.d.ts +13 -0
  15. package/dist/install/agent-file/mode.js +52 -0
  16. package/dist/install/doctor-render.js +2 -0
  17. package/dist/install/doctor.js +20 -0
  18. package/dist/install/generated-skill-payload-hashes.d.ts +10 -10
  19. package/dist/install/generated-skill-payload-hashes.js +10 -10
  20. package/dist/install/index.js +48 -6
  21. package/dist/install/install-options.js +2 -0
  22. package/dist/install/types.d.ts +5 -0
  23. package/dist/install/uninstall.js +1 -0
  24. package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +1 -1
  25. package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
  26. package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
  27. package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
  28. package/marketplace/plugins/litcodex/components/lit-loop/dist/herdr-agents.d.ts +18 -0
  29. package/marketplace/plugins/litcodex/components/lit-loop/dist/herdr-agents.js +63 -0
  30. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-go.js +19 -2
  31. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind.d.ts +21 -2
  32. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind.js +169 -13
  33. package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
  34. package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
  35. package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
  36. package/marketplace/plugins/litcodex/components/start-work-continuation/dist/lifecycle-store.js +21 -2
  37. package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
  38. package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
  39. package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
  40. package/marketplace/plugins/litcodex/skills/lit-adhd/SKILL.md +9 -6
  41. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover.mjs +1 -1
  42. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-gate.mjs +1 -0
  43. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-kit.js +43 -1
  44. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-render.mjs +1 -0
  45. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage.mjs +133 -5
  46. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +27 -3
  47. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/runtime/requirements-audio.txt +92 -89
  48. package/marketplace/plugins/litcodex/skills/readme-studio/templates/hyperframes-cover/package-lock.json +4 -4
  49. package/marketplace/plugins/litcodex/skills/readme-studio/templates/remotion-cover/package-lock.json +3 -3
  50. package/marketplace/plugins/litcodex/skills/readme-studio/templates/remotion-cover/package.json +3 -0
  51. package/node_modules/@litcodex/lit-loop/dist/herdr-agents.d.ts +18 -0
  52. package/node_modules/@litcodex/lit-loop/dist/herdr-agents.js +63 -0
  53. package/node_modules/@litcodex/lit-loop/dist/rewind-go.js +19 -2
  54. package/node_modules/@litcodex/lit-loop/dist/rewind.d.ts +21 -2
  55. package/node_modules/@litcodex/lit-loop/dist/rewind.js +169 -13
  56. package/node_modules/@litcodex/lit-loop/package.json +1 -1
  57. package/node_modules/@litcodex/lit-loop/skills/lit-adhd/SKILL.md +9 -6
  58. package/package.json +2 -2
  59. package/readme-assets/badge-version.svg +1 -1
@@ -11,6 +11,8 @@ import { join } from "node:path";
11
11
  import readline from "node:readline/promises";
12
12
  import { migrateCodexConfig, readLitCodexOutputStyleId } from "../config-migration/index.js";
13
13
  import { humanLabel, preflightLabel, renderBanner, renderInstallFailure, renderInstallReceipt, renderPreflightIntro, renderStepIntro, renderStepResult, Spinner, shouldDecorate, } from "../ui.js";
14
+ import { clearAttributionMode } from "./agent-file/attribution.js";
15
+ import { AGENT_FILE_QUESTION, ATTRIBUTION_QUESTION, agentFileDryRunLine, removeGlobalAgentFile, runInstallAgentFile, } from "./agent-file/cli.js";
14
16
  import { codexSpawnInvocation, resolveCodexHome } from "./codex.js";
15
17
  import { doctorScopeFor, renderDoctorText, runDoctor } from "./doctor.js";
16
18
  import { exitCodeForInstallError, InstallError, toErrorJson } from "./errors.js";
@@ -246,6 +248,7 @@ export async function runInstallCli(args, io = defaultIo()) {
246
248
  if (opts.dryRun) {
247
249
  // ZERO spawns, ZERO fs writes: render and return.
248
250
  io.stdout.write(`${renderInstallPlan(plan)}\n`);
251
+ io.stdout.write(`${agentFileDryRunLine(opts.codexHome)}\n`);
249
252
  return 0;
250
253
  }
251
254
  let result;
@@ -338,6 +341,40 @@ export async function runInstallCli(args, io = defaultIo()) {
338
341
  finally {
339
342
  marketplaceSource?.cleanup();
340
343
  }
344
+ const agentPrompt = interactiveInstall(opts, io)
345
+ ? async () => {
346
+ const rl = installReadline(opts, io);
347
+ try {
348
+ return !/^\s*n/iu.test((await rl.question(AGENT_FILE_QUESTION)).trim());
349
+ }
350
+ finally {
351
+ rl.close();
352
+ }
353
+ }
354
+ : undefined;
355
+ const attributionPrompt = agentPrompt
356
+ ? async () => {
357
+ const rl = installReadline(opts, io);
358
+ try {
359
+ return /^\s*y/iu.test((await rl.question(ATTRIBUTION_QUESTION)).trim());
360
+ }
361
+ finally {
362
+ rl.close();
363
+ }
364
+ }
365
+ : undefined;
366
+ const agentFileLine = await runInstallAgentFile({
367
+ env: io.env,
368
+ stdout: io.stdout,
369
+ codexHome: opts.codexHome,
370
+ version: PACKAGE_VERSION,
371
+ yes: opts.yes,
372
+ noAgentFile: opts.noAgentFile,
373
+ dryRun: false,
374
+ json: opts.json,
375
+ ...(agentPrompt === undefined ? {} : { prompt: agentPrompt }),
376
+ ...(attributionPrompt === undefined ? {} : { attributionPrompt }),
377
+ });
341
378
  const officeRuntime = result.ok ? prepareOfficeRuntime(opts.codexHome, spawnSync, io.env) : undefined;
342
379
  if (officeRuntime)
343
380
  io.stderr.write(`[litcodex] ${officeRuntimeNotice(officeRuntime.ready, officeRuntime.detail)}\n`);
@@ -345,7 +382,7 @@ export async function runInstallCli(args, io = defaultIo()) {
345
382
  if (motionRuntime)
346
383
  io.stderr.write(`[litcodex] ${motionRuntime.receipt}\n`);
347
384
  if (opts.json) {
348
- io.stdout.write(`${JSON.stringify(result)}\n`);
385
+ io.stdout.write(`${JSON.stringify({ ...result, agentFile: agentFileLine })}\n`);
349
386
  }
350
387
  else if (decorate) {
351
388
  io.stdout.write(renderInstallReceipt(result, {
@@ -427,14 +464,19 @@ export function runUninstallCli(args, io = defaultIo()) {
427
464
  },
428
465
  },
429
466
  });
467
+ const agentRemoval = removeGlobalAgentFile(codexHome, PACKAGE_VERSION);
468
+ clearAttributionMode(codexHome);
430
469
  if (json) {
431
- io.stdout.write(`${JSON.stringify(result)}\n`);
432
- }
433
- else if (result.ok) {
434
- io.stdout.write("litcodex uninstall: complete\n");
470
+ io.stdout.write(`${JSON.stringify({ ...result, agentFile: agentRemoval })}\n`);
435
471
  }
436
472
  else {
437
- io.stderr.write("[litcodex] uninstall: codex plugin remove failed\n");
473
+ io.stdout.write(`${agentRemoval}\n`);
474
+ if (result.ok) {
475
+ io.stdout.write("litcodex uninstall: complete\n");
476
+ }
477
+ else {
478
+ io.stderr.write("[litcodex] uninstall: codex plugin remove failed\n");
479
+ }
438
480
  }
439
481
  return result.ok ? 0 : 3;
440
482
  }
@@ -6,6 +6,7 @@ import { managedMarketplaceRoot } from "./marketplace.js";
6
6
  const KNOWN_FLAGS = new Set([
7
7
  "--dry-run",
8
8
  "--no-tui",
9
+ "--no-agent-file",
9
10
  "--codex-autonomous",
10
11
  "--force",
11
12
  "--json",
@@ -44,6 +45,7 @@ export function parseInstallOptions(args, context) {
44
45
  force: args.includes("--force"),
45
46
  json: args.includes("--json"),
46
47
  yes: args.includes("--yes"),
48
+ noAgentFile: args.includes("--no-agent-file"),
47
49
  profile: lead.profile,
48
50
  leadModel: lead.id,
49
51
  effort,
@@ -6,6 +6,7 @@ export interface InstallOptions {
6
6
  readonly force: boolean;
7
7
  readonly json: boolean;
8
8
  readonly yes: boolean;
9
+ readonly noAgentFile: boolean;
9
10
  readonly profile: import("../config-migration/gpt56-policy.js").Gpt56Profile;
10
11
  /** Explicit lead model id (e.g. "gpt-5.6-sol", "gpt-5.6", "gpt-5.6-luna"). */
11
12
  readonly leadModel: string;
@@ -84,6 +85,10 @@ export interface DoctorReport {
84
85
  readonly skillCatalogComplete: boolean;
85
86
  readonly missingSkillIds: readonly string[];
86
87
  readonly missingSkillResourcePaths: readonly string[];
88
+ /** `off` when the stored switch is off, else the global AGENTS.md section state. */
89
+ readonly agentFile: string;
90
+ /** `keep` or `off`: whether the block asks the model not to add AI attribution. */
91
+ readonly attribution: string;
87
92
  readonly handoffInstalled: boolean;
88
93
  readonly scientificVisualizationInstalled: boolean;
89
94
  readonly capabilities: import("./host-capabilities.js").HostCapabilities;
@@ -39,6 +39,7 @@ export function uninstallPlanSteps(codexHome) {
39
39
  `Remove the marketplace: codex plugin marketplace remove ${LITCODEX_MARKETPLACE}, then delete ${managedMarketplaceRoot(codexHome)} only if the marketplace removal succeeds`,
40
40
  `Remove LitCodex agent roles from ${join(codexHome, "agents")} and the native default route ${join(codexHome, NATIVE_DEFAULT_AGENT_FILE)}, when they still match what LitCodex installed`,
41
41
  `Remove the managed [agents] defaults from ${join(codexHome, "config.toml")} and LitCodex-generated profile files from ${codexHome}`,
42
+ `Remove the LitFamily block from ${join(codexHome, "AGENTS.md")} (your own text stays; a file the block alone created is deleted)`,
42
43
  `If the marketplace root or config.toml is a symlink or otherwise unsafe, uninstall refuses to change anything`,
43
44
  ];
44
45
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litcodex",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "author": {
5
5
  "name": "LitCodex Authors"
6
6
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litcodex/auto-update",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "LitCodex foreground update barrier for the SessionStart and management lifecycles.",
5
5
  "type": "module",
6
6
  "private": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litcodex/comment-checker",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "LitCodex Comment-Checker hook: flags low-value / AI-slop comments introduced by edits.",
5
5
  "type": "module",
6
6
  "private": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litcodex/git-bash",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "LitCodex Git-Bash hook: reminds Windows sessions to prefer the git_bash MCP before the built-in shell.",
5
5
  "type": "module",
6
6
  "private": true,
@@ -0,0 +1,18 @@
1
+ export interface HerdrAgent {
2
+ readonly agent: string;
3
+ readonly status: string;
4
+ readonly pane: string | null;
5
+ readonly workspace: string | null;
6
+ readonly cwd: string | null;
7
+ readonly foregroundCwd: string | null;
8
+ readonly session: string | null;
9
+ }
10
+ export interface HerdrAgents {
11
+ readonly state: "off" | "ok" | "unknown";
12
+ readonly agents: readonly HerdrAgent[];
13
+ }
14
+ /** Runs `herdr agent list` and returns its stdout, or null when it fails. Injectable for tests. */
15
+ export type HerdrRunner = () => string | null;
16
+ export declare const runHerdr: HerdrRunner;
17
+ /** The agents herdr reports; `off` unless `HERDR_ENV=1`, `unknown` when the list cannot be read. */
18
+ export declare function readHerdrAgents(env: NodeJS.ProcessEnv, run?: HerdrRunner): HerdrAgents;
@@ -0,0 +1,63 @@
1
+ // src/herdr-agents.ts — the agents a herdr session reports, read only when `HERDR_ENV=1`.
2
+ //
3
+ // `herdr agent list` prints one JSON document, `{"result":{"agents":[…]}}`. The brief reads it to count the
4
+ // lanes still at work beside this session. The call is bounded by a short timeout; a missing binary, a slow
5
+ // answer or a document that does not parse makes the source `unknown`, never a guess. Outside herdr the source
6
+ // is `off` and nothing runs.
7
+ import { execFileSync } from "node:child_process";
8
+ import { clean } from "./control-chars.js";
9
+ const HERDR_TIMEOUT_MS = 2000;
10
+ const MAX_AGENTS = 64;
11
+ const PANE = /^[A-Za-z0-9:_-]{1,32}$/u;
12
+ export const runHerdr = () => {
13
+ try {
14
+ return execFileSync("herdr", ["agent", "list"], {
15
+ encoding: "utf8",
16
+ timeout: HERDR_TIMEOUT_MS,
17
+ stdio: ["ignore", "pipe", "ignore"],
18
+ maxBuffer: 1_000_000,
19
+ });
20
+ }
21
+ catch {
22
+ return null;
23
+ }
24
+ };
25
+ function isRecord(value) {
26
+ return typeof value === "object" && value !== null && !Array.isArray(value);
27
+ }
28
+ const text = (value) => typeof value === "string" && value.length > 0 && value.length <= 4096 ? clean(value) : null;
29
+ /** The agents herdr reports; `off` unless `HERDR_ENV=1`, `unknown` when the list cannot be read. */
30
+ export function readHerdrAgents(env, run = runHerdr) {
31
+ if (env["HERDR_ENV"] !== "1")
32
+ return { state: "off", agents: [] };
33
+ const out = run();
34
+ if (out === null)
35
+ return { state: "unknown", agents: [] };
36
+ let parsed;
37
+ try {
38
+ parsed = JSON.parse(out);
39
+ }
40
+ catch {
41
+ return { state: "unknown", agents: [] };
42
+ }
43
+ const list = isRecord(parsed) && isRecord(parsed["result"]) ? parsed["result"]["agents"] : undefined;
44
+ if (!Array.isArray(list))
45
+ return { state: "unknown", agents: [] };
46
+ const agents = list
47
+ .filter(isRecord)
48
+ .slice(0, MAX_AGENTS)
49
+ .map((entry) => {
50
+ const pane = text(entry["pane_id"]);
51
+ const session = isRecord(entry["agent_session"]) ? text(entry["agent_session"]["value"]) : null;
52
+ return {
53
+ agent: text(entry["agent"]) ?? "agent",
54
+ status: text(entry["agent_status"]) ?? "unknown",
55
+ pane: pane !== null && PANE.test(pane) ? pane : null,
56
+ workspace: text(entry["workspace_id"]),
57
+ cwd: text(entry["cwd"]),
58
+ foregroundCwd: text(entry["foreground_cwd"]),
59
+ session,
60
+ };
61
+ });
62
+ return { state: "ok", agents };
63
+ }
@@ -18,7 +18,14 @@ const MAX_NOTE_BYTES = 8 * 1024;
18
18
  export function isGoPrompt(prompt) {
19
19
  return GO_PROMPT.test(prompt);
20
20
  }
21
- const KINDS = ["resume-frame", "approve-boundary", "continue-work", "start-plan"];
21
+ const KINDS = [
22
+ "resume-frame",
23
+ "approve-boundary",
24
+ "continue-work",
25
+ "start-plan",
26
+ "other-session",
27
+ "wait-lanes",
28
+ ];
22
29
  function readNote(cwd, sessionId) {
23
30
  const id = normalizeSessionId(sessionId);
24
31
  if (id === null || !isAbsolute(cwd) || !plainDirsOrMissing(cwd, ADHD_DIR))
@@ -47,12 +54,15 @@ function readNote(cwd, sessionId) {
47
54
  kind: kind,
48
55
  at,
49
56
  plan: typeof fields["plan"] === "string" ? fields["plan"] : null,
57
+ work: typeof fields["work"] === "string" ? fields["work"] : null,
50
58
  text: typeof fields["text"] === "string" ? clean(fields["text"]) : "",
51
59
  };
52
60
  }
53
61
  const EXPIRED = "The user said `go`, but the briefed next step is older than 30 minutes, so nothing was started. Tell the user that in one sentence and offer `lit adhd` for a fresh brief; start no other work.";
54
62
  const STALE = "The user said `go`, but the briefed next step no longer holds, so nothing was started. Tell the user that in one sentence and offer `lit adhd` for a fresh brief; start no other work.";
55
63
  const BOUNDARY = "The user said `go`, but the briefed step is a start-work boundary waiting for an answer. `go` never approves it: tell the user in one sentence to answer `lit approve` or `lit deny` themselves; start nothing.";
64
+ const LANES = "The user said `go`, but the brief offered no step for `go`: other lanes in this repository were still working, so nothing was started. Tell the user that in one sentence: wait for those lanes (or answer the one that waits on them), then ask for a fresh `lit adhd`; start no other work.";
65
+ const ELSEWHERE = "The user said `go`, but the briefed run belongs to another session, so nothing was started. Tell the user in one sentence to continue it in that session; start no other work.";
56
66
  /**
57
67
  * What a go-word prompt means in this session. Null when the session has no note (the prompt is then an
58
68
  * ordinary one); a hint when a note existed but cannot run; otherwise the prompt to route in its place.
@@ -65,6 +75,10 @@ export function takeGo(cwd, sessionId, now) {
65
75
  return { kind: "hint", text: EXPIRED };
66
76
  if (note.kind === "approve-boundary")
67
77
  return { kind: "hint", text: BOUNDARY };
78
+ if (note.kind === "wait-lanes")
79
+ return { kind: "hint", text: LANES };
80
+ if (note.kind === "other-session")
81
+ return { kind: "hint", text: ELSEWHERE };
68
82
  const fresh = chooseNext(cwd, sessionId);
69
83
  // A note naming its plan (a saved lit-plan, or a brief) holds while that plan is open and nothing outranks it,
70
84
  // even when a second open plan means the brief alone would name none.
@@ -76,7 +90,10 @@ export function takeGo(cwd, sessionId, now) {
76
90
  note: `go: start work on ${named.name}, ${named.done} of ${named.total} tasks done`,
77
91
  };
78
92
  }
79
- if (fresh.kind !== note.kind || (note.kind === "start-plan" && fresh.plan !== note.plan)) {
93
+ // The run the note named must still be the active one, still owned by this session.
94
+ if (fresh.kind !== note.kind ||
95
+ (note.kind === "start-plan" && fresh.plan !== note.plan) ||
96
+ (note.kind === "continue-work" && note.work !== null && fresh.work !== note.work)) {
80
97
  return { kind: "hint", text: STALE };
81
98
  }
82
99
  if (note.kind === "start-plan" && fresh.plan !== undefined) {
@@ -1,3 +1,4 @@
1
+ import { type HerdrRunner } from "./herdr-agents.js";
1
2
  export declare const ADHD_DIR = ".litcodex/adhd";
2
3
  /** A session written to in the last quarter hour is still running. */
3
4
  export declare const ACTIVE_MS: number;
@@ -6,8 +7,11 @@ export declare const GO_WINDOW_MS: number;
6
7
  export declare const DEFAULT_SINCE_MS: number;
7
8
  export declare const DEFAULT_MAX = 12;
8
9
  export type SessionStatus = "waiting-on-user" | "active" | "idle" | "done" | "ended" | "unknown";
9
- /** `handoff` is shown, never run: a `go` over it starts nothing. */
10
- export type NextKind = "resume-frame" | "approve-boundary" | "continue-work" | "start-plan" | "handoff" | "none";
10
+ /**
11
+ * `handoff` is shown, never run: a `go` over it starts nothing. `other-session` is a start-work run another
12
+ * session owns, and `wait-lanes` holds a step back while other lanes of this repo still work; `go` runs neither.
13
+ */
14
+ export type NextKind = "resume-frame" | "approve-boundary" | "continue-work" | "start-plan" | "handoff" | "other-session" | "wait-lanes" | "none";
11
15
  export interface NextStep {
12
16
  readonly kind: NextKind;
13
17
  readonly text: string;
@@ -16,6 +20,18 @@ export interface NextStep {
16
20
  readonly n?: number;
17
21
  readonly total?: number;
18
22
  readonly plan?: string;
23
+ /** The start-work run a `continue-work` step continues, so `go` can check it is still this one. */
24
+ readonly work?: string;
25
+ /** How many lanes a `wait-lanes` step waits for. */
26
+ readonly lanes?: number;
27
+ }
28
+ /** Other live sessions of this repo and, under herdr, its working or blocked agents, each counted once. */
29
+ export interface RewindLanes {
30
+ readonly count: number;
31
+ /** Lanes that wait on the user: a session asking something, or a blocked agent. */
32
+ readonly waiting: number;
33
+ readonly labels: readonly string[];
34
+ readonly herdr: "off" | "ok" | "unknown";
19
35
  }
20
36
  export interface RewindSession {
21
37
  readonly id: string;
@@ -87,6 +103,7 @@ export interface RewindResult {
87
103
  readonly sessions: readonly RewindSession[];
88
104
  readonly worktrees: readonly RewindWorktree[];
89
105
  readonly next: NextStep;
106
+ readonly lanes: RewindLanes;
90
107
  /**
91
108
  * A step to recommend when `next.kind` is `none`, chosen from the records: a session that waits on the user, a
92
109
  * paused workflow, an open plan item, the latest active session, the latest ended one. Shown, never recorded.
@@ -125,6 +142,8 @@ export interface RewindOptions {
125
142
  readonly codexHome?: string | null;
126
143
  /** Overrides the whole-run read allowance in bytes (a test seam). */
127
144
  readonly budgetBytes?: number;
145
+ /** Overrides the `herdr agent list` call (a test seam); it runs only under `HERDR_ENV=1`. */
146
+ readonly herdr?: HerdrRunner;
128
147
  }
129
148
  /** `7d`, `36h`, `90m` as milliseconds; null for anything else. */
130
149
  export declare function parseSince(text: string): number | null;
@@ -12,11 +12,12 @@ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync } f
12
12
  import { homedir } from "node:os";
13
13
  import { basename, isAbsolute, join, relative } from "node:path";
14
14
  import { clean, cleanDeep, cleanLines } from "./control-chars.js";
15
+ import { readHerdrAgents } from "./herdr-agents.js";
15
16
  import { displayWidth, fit } from "./hud.js";
16
17
  import { codexHomeFrom, plainDirsOrMissing, readSmallJson, writeFileAtomic } from "./live-step.js";
17
18
  import { makeRedactor } from "./rewind-redact.js";
18
19
  import { listRollouts, newBudget, readRollout, TOTAL_BYTES, } from "./rewind-rollout.js";
19
- import { readLiveness } from "./session-liveness.js";
20
+ import { readLiveness, readSessionsLiveness } from "./session-liveness.js";
20
21
  import { normalizeSessionId } from "./state-paths.js";
21
22
  import { countPlanRows, planProgress, planRows, readWorkflowSignals } from "./workflow-map.js";
22
23
  import { frameLabel, frameNote, pausedSpine, readStack, STACK_DIR, stackGauge, } from "./workflow-stack.js";
@@ -202,24 +203,32 @@ function pausedFramesOf(path) {
202
203
  }
203
204
  return out;
204
205
  }
205
- /** The first 16 KiB of this folder's HANDOFF note, or null. */
206
+ /** The first 16 KiB of this folder's newest HANDOFF note (by change time, then name), or null. */
206
207
  function handoffText(path) {
207
- for (const name of listDir(path, ".md", 200)
208
- .filter((file) => /^HANDOFF/iu.test(file))
209
- .slice(0, 1)) {
208
+ const notes = [];
209
+ for (const name of listDir(path, ".md", 200).filter((file) => /^HANDOFF/iu.test(file))) {
210
210
  try {
211
211
  const full = join(path, name);
212
212
  const stat = lstatSync(full);
213
- if (!stat.isFile())
214
- continue;
215
- return readFileSync(full, "utf8").slice(0, MAX_HANDOFF_BYTES);
213
+ if (stat.isFile())
214
+ notes.push({ full, mtimeMs: stat.mtimeMs });
216
215
  }
217
216
  catch {
218
- return null;
217
+ // An unreadable note is left out.
219
218
  }
220
219
  }
221
- return null;
220
+ const newest = notes.sort((a, b) => b.mtimeMs - a.mtimeMs)[0];
221
+ if (newest === undefined)
222
+ return null;
223
+ try {
224
+ return readFileSync(newest.full, "utf8").slice(0, MAX_HANDOFF_BYTES);
225
+ }
226
+ catch {
227
+ return null;
228
+ }
222
229
  }
230
+ /** A Next item already finished: ticked, struck through, or marked ✅, ✓, DONE or SHIPPED (those words in capitals). */
231
+ const DONE_ITEM = /^\s*(?:[-*+]|\d+[.)])?\s*(?:\[[xX]\]|~~.*~~\s*$)|[✅✔✓]|\b(?:DONE|SHIPPED)\b/u;
223
232
  function handoffHeading(path) {
224
233
  const text = handoffText(path);
225
234
  return text === null ? null : (/^#{1,3}\s+(.+)$/mu.exec(text)?.[1]?.trim() ?? null);
@@ -229,7 +238,7 @@ function handoffNext(path) {
229
238
  const text = handoffText(path);
230
239
  const body = text === null ? undefined : /^##\s+Next\b[^\n]*\n([\s\S]*?)(?=^#{1,2}\s|(?![\s\S]))/imu.exec(text)?.[1];
231
240
  for (const line of (body ?? "").split("\n")) {
232
- if (/^\s*[-*+]\s+\[[xX]\]/u.test(line))
241
+ if (DONE_ITEM.test(line))
233
242
  continue;
234
243
  const item = line
235
244
  .replace(/^\s*(?:[-*+]|\d+[.)])\s+(?:\[ \]\s+)?/u, "")
@@ -347,6 +356,26 @@ function pendingBoundary(cwd) {
347
356
  .filter(isRecord)
348
357
  .some((work) => work["status"] === "paused" && isRecord(work["pending_boundary"]));
349
358
  }
359
+ /** The start-work run under way here (active, or paused without a boundary), and whether this session owns it. */
360
+ function workUnderWay(cwd, sessionId) {
361
+ if (!plainDirsOrMissing(cwd, ".litcodex/start-work"))
362
+ return null;
363
+ const state = readSmallJson(join(cwd, ".litcodex/start-work/state.json"), MAX_STATE_BYTES);
364
+ if (!isRecord(state) || !isRecord(state["works"]))
365
+ return null;
366
+ const activeId = state["active_work_id"];
367
+ const work = Object.values(state["works"])
368
+ .filter(isRecord)
369
+ .find((entry) => entry["work_id"] === activeId && (entry["status"] === "active" || entry["status"] === "paused"));
370
+ if (work === undefined || typeof activeId !== "string")
371
+ return null;
372
+ const owners = Array.isArray(work["session_ids"]) ? work["session_ids"] : [];
373
+ const mine = sessionId !== null &&
374
+ owners.some((owner) => typeof owner === "string" &&
375
+ owner.startsWith("codex:") &&
376
+ normalizeSessionId(owner.slice("codex:".length)) === sessionId);
377
+ return { id: activeId, mine };
378
+ }
350
379
  /**
351
380
  * The one step worth taking next, in priority order: the paused frame of this session's stack, then a boundary
352
381
  * waiting for an answer (shown, never started), then work already under way, then the single open plan.
@@ -377,9 +406,18 @@ function chooseNextRaw(cwd, sessionId) {
377
406
  const signals = readWorkflowSignals(cwd, sessionId);
378
407
  const work = signals.work;
379
408
  if (work !== null && work.status !== "completed" && work.done < work.total) {
409
+ // Another session's run is shown where it runs, never continued from here.
410
+ const run = workUnderWay(cwd, sessionId === null ? null : normalizeSessionId(sessionId));
411
+ if (run === null || !run.mine) {
412
+ return {
413
+ kind: "other-session",
414
+ text: `another session runs the ${work.status} start-work plan, ${work.done} of ${work.total} tasks done: continue it there`,
415
+ };
416
+ }
380
417
  return {
381
418
  kind: "continue-work",
382
419
  text: `continue the ${work.status} start-work plan, ${work.done} of ${work.total} tasks done`,
420
+ work: run.id,
383
421
  };
384
422
  }
385
423
  if (signals.goals !== null && signals.goals.done < signals.goals.total) {
@@ -414,6 +452,7 @@ export function writeNext(cwd, sessionId, next, now) {
414
452
  try {
415
453
  if (!plainDirsOrMissing(cwd, ADHD_DIR))
416
454
  return;
455
+ // A handoff or nothing at all leaves no note; a held-back step leaves one so `go` can say why it waits.
417
456
  if (next.kind === "none" || next.kind === "handoff") {
418
457
  rmSync(path, { force: true });
419
458
  return;
@@ -559,7 +598,19 @@ export function collectRewind(options) {
559
598
  .find((tree) => insideDir(where, homed(tree.path)));
560
599
  return { ...session, tree: owner?.path ?? null };
561
600
  });
562
- const next = chooseNext(options.cwd, sessionId);
601
+ const herdr = readHerdrAgents(env, options.herdr);
602
+ const lanes = lanesOf(placed, laneRootsOf(options.cwd, git), sessionId, env, herdr, now, homed);
603
+ const chosen = chooseNext(options.cwd, sessionId);
604
+ // While another lane works, no step that would resume or start work here is offered: only a
605
+ // boundary approval, which stays the user's call either way. The live signal wins.
606
+ const next = lanes.count > 0 &&
607
+ (chosen.kind === "resume-frame" ||
608
+ chosen.kind === "continue-work" ||
609
+ chosen.kind === "start-plan" ||
610
+ chosen.kind === "handoff" ||
611
+ chosen.kind === "none")
612
+ ? { kind: "wait-lanes", text: waitText(lanes), lanes: lanes.count }
613
+ : chosen;
563
614
  if (sessionId !== null)
564
615
  writeNext(options.cwd, sessionId, next, now);
565
616
  // Commit subjects, branch names, plan rows and names, goals and paths are record text: none of it may carry a control.
@@ -569,12 +620,111 @@ export function collectRewind(options) {
569
620
  sessions: placed,
570
621
  worktrees,
571
622
  next,
623
+ lanes: { count: lanes.count, waiting: lanes.waiting, labels: lanes.labels, herdr: herdr.state },
572
624
  suggestion: suggestionOf(placed, worktrees),
573
625
  scope: { sinceMs, worktrees: worktrees.length },
574
626
  sources: { sessions: sessionsState, git: gitState, state: "ok" },
575
627
  budget: { limit, used: limit - budget.remaining, exhausted: budget.exhausted },
576
628
  });
577
629
  }
630
+ // ── Lanes ────────────────────────────────────────────────────────────────────
631
+ /** This checkout's top folder and the other worktrees of its repository; the folder alone when git cannot say. */
632
+ function laneRootsOf(cwd, git) {
633
+ const top = git(cwd, ["rev-parse", "--show-toplevel"])?.trim();
634
+ if (top === undefined || top === "")
635
+ return [cwd];
636
+ const porcelain = git(top, ["worktree", "list", "--porcelain"]);
637
+ const listed = porcelain === null ? [] : [...porcelain.matchAll(/^worktree (.+)$/gmu)].map((match) => match[1] ?? "");
638
+ return [...new Set([top, ...listed.filter((path) => isAbsolute(path))])];
639
+ }
640
+ const LANE_LABELS = 3;
641
+ /**
642
+ * Other lanes at work in this repository, each once: a session that runs or waits on the user, a session whose
643
+ * liveness record says it is working, and, under herdr, a working or blocked agent of this workspace or repo.
644
+ * The asking session and its own pane never count.
645
+ */
646
+ function lanesOf(sessions, roots, sessionId, env, herdr, now, homed) {
647
+ const inRepo = (path) => path !== null && isAbsolute(homed(path)) && roots.some((root) => insideDir(homed(path), root));
648
+ const own = (id) => id !== null && sessionId !== null && normalizeSessionId(id) === sessionId;
649
+ const lanes = [];
650
+ const known = new Map(sessions.map((session) => [normalizeSessionId(session.id), session.status]));
651
+ for (const session of sessions) {
652
+ if (session.current || own(session.id) || !inRepo(session.cwd))
653
+ continue;
654
+ if (session.status !== "active" && session.status !== "waiting-on-user")
655
+ continue;
656
+ lanes.push({
657
+ session: normalizeSessionId(session.id),
658
+ pane: null,
659
+ waiting: session.status === "waiting-on-user",
660
+ label: `${session.shortId} in ${placeOf(session)}`,
661
+ });
662
+ }
663
+ for (const root of roots) {
664
+ for (const record of readSessionsLiveness(root, now)) {
665
+ const id = normalizeSessionId(record.sessionId);
666
+ if (record.state !== "alive" || id === null || own(id))
667
+ continue;
668
+ const seen = lanes.find((lane) => lane.session === id);
669
+ if (seen !== undefined) {
670
+ seen.pane ??= record.herdrPane;
671
+ continue;
672
+ }
673
+ // A session the records show as finished or idle is not at work, whatever its last tool call wrote.
674
+ const status = known.get(id);
675
+ if (status !== undefined && status !== "active" && status !== "waiting-on-user")
676
+ continue;
677
+ lanes.push({
678
+ session: id,
679
+ pane: record.herdrPane,
680
+ waiting: false,
681
+ label: `${shortIdOf(id)} in ${basename(root)}`,
682
+ });
683
+ }
684
+ }
685
+ const ownPane = env["HERDR_PANE_ID"];
686
+ const ownWorkspace = env["HERDR_WORKSPACE_ID"];
687
+ for (const agent of herdr.agents) {
688
+ if (agent.status !== "working" && agent.status !== "blocked")
689
+ continue;
690
+ if (agent.pane !== null && agent.pane === ownPane)
691
+ continue;
692
+ if (own(agent.session))
693
+ continue;
694
+ const here = (typeof ownWorkspace === "string" && ownWorkspace !== "" && agent.workspace === ownWorkspace) ||
695
+ inRepo(agent.cwd) ||
696
+ inRepo(agent.foregroundCwd);
697
+ if (!here)
698
+ continue;
699
+ const id = agent.session === null ? null : normalizeSessionId(agent.session);
700
+ const seen = lanes.find((lane) => (id !== null && lane.session === id) || (agent.pane !== null && lane.pane === agent.pane));
701
+ if (seen !== undefined) {
702
+ seen.waiting ||= agent.status === "blocked";
703
+ continue;
704
+ }
705
+ lanes.push({
706
+ session: id,
707
+ pane: agent.pane,
708
+ waiting: agent.status === "blocked",
709
+ label: `${agent.agent} in pane ${agent.pane ?? "unknown"}`,
710
+ });
711
+ }
712
+ const ordered = [...lanes.filter((lane) => lane.waiting), ...lanes.filter((lane) => !lane.waiting)];
713
+ return {
714
+ count: lanes.length,
715
+ waiting: ordered.filter((lane) => lane.waiting).length,
716
+ labels: ordered.slice(0, LANE_LABELS).map((lane) => lane.label),
717
+ };
718
+ }
719
+ /** The held-back step: answer the lane that waits on the user, else wait for the lanes to finish. */
720
+ function waitText(lanes) {
721
+ const first = lanes.labels[0] ?? "the other lane";
722
+ if (lanes.waiting > 0) {
723
+ const rest = lanes.count - 1;
724
+ return `answer ${first}: it waits on you${rest > 0 ? `; ${plural(rest, "more lane")} still at work` : ""}`;
725
+ }
726
+ return `wait for ${plural(lanes.count, "lane")} to finish: ${lanes.labels.join(", ")}`;
727
+ }
578
728
  // ── Suggestion ───────────────────────────────────────────────────────────────
579
729
  const homeless = (path) => (path === null ? "unknown" : basename(path));
580
730
  /** The worktree folder a session runs in, else the folder it started in, as a short name. */
@@ -790,7 +940,11 @@ function nextBox(result, width) {
790
940
  ? "answer `lit approve` or `lit deny` yourself"
791
941
  : result.next.kind === "handoff"
792
942
  ? "a step from the handoff note; `go` does not run it, so say what to do"
793
- : "say `go` to run it";
943
+ : result.next.kind === "other-session"
944
+ ? "that run belongs to another session; `go` here does not run it"
945
+ : result.next.kind === "wait-lanes"
946
+ ? "do not type `go` until they finish"
947
+ : "say `go` to run it";
794
948
  const box = (text) => `│ ${pad(text, inner)} │`;
795
949
  return [
796
950
  "```",
@@ -856,6 +1010,8 @@ export function renderBrief(result, width = 96) {
856
1010
  const unknown = Object.entries(result.sources)
857
1011
  .filter(([, state]) => state === "unknown")
858
1012
  .map(([name]) => name);
1013
+ if (result.lanes.herdr === "unknown")
1014
+ unknown.push("herdr agents");
859
1015
  if (unknown.length > 0)
860
1016
  lines.push("", `*not readable: ${unknown.join(", ")}*`);
861
1017
  const skipped = result.worktrees.reduce((sum, tree) => sum + tree.skippedPlans, 0);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litcodex/lit-loop",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "LitCodex Lit-Loop runtime: durable repo-native multi-goal orchestration with embedded success criteria and observable evidence audit.",
5
5
  "type": "module",
6
6
  "private": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litcodex/lsp",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "description": "LitCodex LSP hook (inert placeholder): post-edit diagnostics + cache reset, no-op until an LSP daemon is provided.",
5
5
  "type": "module",
6
6
  "private": true,