lazycodex-ai 4.16.0 → 4.16.2

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 (137) hide show
  1. package/dist/cli/codex-ulw-loop.d.ts +8 -0
  2. package/dist/cli/get-local-version/types.d.ts +1 -1
  3. package/dist/cli/index.js +260 -207
  4. package/dist/cli-node/index.js +260 -207
  5. package/docs/reference/web-terminal-visual-qa.md +39 -45
  6. package/package.json +3 -2
  7. package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
  8. package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +1 -1
  9. package/packages/omo-codex/plugin/components/bootstrap/package.json +1 -1
  10. package/packages/omo-codex/plugin/components/codegraph/package.json +1 -1
  11. package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
  12. package/packages/omo-codex/plugin/components/comment-checker/package.json +1 -1
  13. package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
  14. package/packages/omo-codex/plugin/components/git-bash/package.json +1 -1
  15. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/hooks/hooks.json +1 -1
  16. package/packages/omo-codex/plugin/components/lazycodex-executor-verify/package.json +1 -1
  17. package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
  18. package/packages/omo-codex/plugin/components/lsp/package.json +1 -1
  19. package/packages/omo-codex/plugin/components/rules/bundled-rules/hephaestus.md +1 -1
  20. package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
  21. package/packages/omo-codex/plugin/components/rules/package.json +1 -1
  22. package/packages/omo-codex/plugin/components/start-work-continuation/directive.md +3 -3
  23. package/packages/omo-codex/plugin/components/start-work-continuation/hooks/hooks.json +2 -2
  24. package/packages/omo-codex/plugin/components/start-work-continuation/package.json +1 -1
  25. package/packages/omo-codex/plugin/components/start-work-continuation/test/codex-hook.test.ts +1 -1
  26. package/packages/omo-codex/plugin/components/teammode/AGENTS.md +1 -1
  27. package/packages/omo-codex/plugin/components/teammode/hooks/hooks.json +1 -1
  28. package/packages/omo-codex/plugin/components/teammode/package.json +1 -1
  29. package/packages/omo-codex/plugin/components/teammode/skills/teammode/SKILL.md +3 -3
  30. package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
  31. package/packages/omo-codex/plugin/components/telemetry/package.json +1 -1
  32. package/packages/omo-codex/plugin/components/ultrawork/directive.md +19 -10
  33. package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
  34. package/packages/omo-codex/plugin/components/ultrawork/package.json +1 -1
  35. package/packages/omo-codex/plugin/components/ultrawork/skills/ultrawork/SKILL.md +19 -10
  36. package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/SKILL.md +13 -0
  37. package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/full-workflow.md +2 -0
  38. package/packages/omo-codex/plugin/components/ultrawork/test/codex-hook.test.ts +22 -1
  39. package/packages/omo-codex/plugin/components/ulw-loop/CHANGELOG.md +4 -0
  40. package/packages/omo-codex/plugin/components/ulw-loop/directive.md +19 -10
  41. package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-commands.js +15 -2
  42. package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-steering.js +2 -1
  43. package/packages/omo-codex/plugin/components/ulw-loop/dist/cli.js +89 -27
  44. package/packages/omo-codex/plugin/components/ulw-loop/dist/plan-io.d.ts +6 -0
  45. package/packages/omo-codex/plugin/components/ulw-loop/dist/plan-io.js +55 -9
  46. package/packages/omo-codex/plugin/components/ulw-loop/dist/steering-snapshot.d.ts +15 -0
  47. package/packages/omo-codex/plugin/components/ulw-loop/dist/steering-snapshot.js +33 -0
  48. package/packages/omo-codex/plugin/components/ulw-loop/dist/steering-types.d.ts +10 -3
  49. package/packages/omo-codex/plugin/components/ulw-loop/dist/steering.js +15 -11
  50. package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +2 -2
  51. package/packages/omo-codex/plugin/components/ulw-loop/package.json +1 -1
  52. package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/SKILL.md +3 -1
  53. package/packages/omo-codex/plugin/components/ulw-loop/skills/ulw-loop/references/full-workflow.md +7 -7
  54. package/packages/omo-codex/plugin/components/ulw-loop/src/cli-commands.ts +17 -2
  55. package/packages/omo-codex/plugin/components/ulw-loop/src/cli-steering.ts +2 -1
  56. package/packages/omo-codex/plugin/components/ulw-loop/src/plan-io.ts +59 -11
  57. package/packages/omo-codex/plugin/components/ulw-loop/src/steering-snapshot.ts +38 -0
  58. package/packages/omo-codex/plugin/components/ulw-loop/src/steering-types.ts +11 -3
  59. package/packages/omo-codex/plugin/components/ulw-loop/src/steering.ts +15 -7
  60. package/packages/omo-codex/plugin/components/ulw-loop/test/cli-create-goals.test.ts +16 -0
  61. package/packages/omo-codex/plugin/components/ulw-loop/test/plan-io.test.ts +260 -2
  62. package/packages/omo-codex/plugin/components/ulw-loop/test/skill-contract.test.ts +1 -1
  63. package/packages/omo-codex/plugin/components/ulw-loop/test/steering-snapshot.test.ts +124 -0
  64. package/packages/omo-codex/plugin/components/ulw-loop/test/steering.test.ts +101 -2
  65. package/packages/omo-codex/plugin/hooks/post-compact-resetting-git-bash-mcp-reminder.json +1 -1
  66. package/packages/omo-codex/plugin/hooks/post-compact-resetting-lsp-diagnostics-cache.json +1 -1
  67. package/packages/omo-codex/plugin/hooks/post-compact-resetting-project-rule-cache.json +1 -1
  68. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-codegraph-init-guidance.json +1 -1
  69. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-comments.json +1 -1
  70. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-lsp-diagnostics.json +1 -1
  71. package/packages/omo-codex/plugin/hooks/post-tool-use-checking-thread-title-hygiene.json +1 -1
  72. package/packages/omo-codex/plugin/hooks/post-tool-use-matching-project-rules.json +1 -1
  73. package/packages/omo-codex/plugin/hooks/pre-tool-use-enforcing-unlimited-goal-budget.json +1 -1
  74. package/packages/omo-codex/plugin/hooks/pre-tool-use-recommending-git-bash-mcp.json +1 -1
  75. package/packages/omo-codex/plugin/hooks/session-start-checking-auto-update.json +1 -1
  76. package/packages/omo-codex/plugin/hooks/session-start-checking-bootstrap-provisioning.json +1 -1
  77. package/packages/omo-codex/plugin/hooks/session-start-checking-codegraph-bootstrap.json +1 -1
  78. package/packages/omo-codex/plugin/hooks/session-start-loading-project-rules.json +1 -1
  79. package/packages/omo-codex/plugin/hooks/session-start-recording-session-telemetry.json +1 -1
  80. package/packages/omo-codex/plugin/hooks/stop-checking-start-work-continuation.json +1 -1
  81. package/packages/omo-codex/plugin/hooks/subagent-stop-checking-start-work-continuation.json +1 -1
  82. package/packages/omo-codex/plugin/hooks/subagent-stop-verifying-lazycodex-executor-evidence.json +1 -1
  83. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ultrawork-trigger.json +1 -1
  84. package/packages/omo-codex/plugin/hooks/user-prompt-submit-checking-ulw-loop-steering.json +1 -1
  85. package/packages/omo-codex/plugin/hooks/user-prompt-submit-loading-project-rules.json +1 -1
  86. package/packages/omo-codex/plugin/package-lock.json +13 -13
  87. package/packages/omo-codex/plugin/package.json +1 -1
  88. package/packages/omo-codex/plugin/scripts/auto-update.mjs +64 -17
  89. package/packages/omo-codex/plugin/scripts/hook-status-message.mjs +10 -6
  90. package/packages/omo-codex/plugin/scripts/migrate-codex-config/multi-agent-v2-guard.mjs +186 -20
  91. package/packages/omo-codex/plugin/scripts/migrate-codex-config/subagent-limit-guard.mjs +51 -3
  92. package/packages/omo-codex/plugin/scripts/migrate-codex-config.mjs +33 -5
  93. package/packages/omo-codex/plugin/scripts/sync-skills.mjs +1 -1
  94. package/packages/omo-codex/plugin/skills/frontend/SKILL.md +9 -9
  95. package/packages/omo-codex/plugin/skills/frontend/references/design/README.md +7 -3
  96. package/packages/omo-codex/plugin/skills/frontend/references/design/_INDEX.md +1 -1
  97. package/packages/omo-codex/plugin/skills/frontend/references/design/design-system-architecture.md +24 -2
  98. package/packages/omo-codex/plugin/skills/frontend/references/designpowers/README.md +2 -2
  99. package/packages/omo-codex/plugin/skills/frontend/references/designpowers/lane-b-execution.md +1 -1
  100. package/packages/omo-codex/plugin/skills/init-deep/SKILL.md +1 -1
  101. package/packages/omo-codex/plugin/skills/refactor/SKILL.md +1 -1
  102. package/packages/omo-codex/plugin/skills/remove-ai-slops/SKILL.md +1 -1
  103. package/packages/omo-codex/plugin/skills/review-work/SKILL.md +1 -1
  104. package/packages/omo-codex/plugin/skills/start-work/SKILL.md +3 -3
  105. package/packages/omo-codex/plugin/skills/teammode/SKILL.md +3 -3
  106. package/packages/omo-codex/plugin/skills/ultrawork/SKILL.md +19 -10
  107. package/packages/omo-codex/plugin/skills/ulw-loop/SKILL.md +3 -1
  108. package/packages/omo-codex/plugin/skills/ulw-loop/references/full-workflow.md +7 -7
  109. package/packages/omo-codex/plugin/skills/ulw-plan/SKILL.md +13 -0
  110. package/packages/omo-codex/plugin/skills/ulw-plan/references/full-workflow.md +2 -0
  111. package/packages/omo-codex/plugin/skills/ulw-research/SKILL.md +1 -1
  112. package/packages/omo-codex/plugin/skills/visual-qa/SKILL.md +14 -18
  113. package/packages/omo-codex/plugin/test/aggregate-hooks.test.mjs +4 -4
  114. package/packages/omo-codex/plugin/test/aggregate-plugin-fixture.mjs +1 -1
  115. package/packages/omo-codex/plugin/test/auto-update.test.mjs +35 -1
  116. package/packages/omo-codex/plugin/test/bootstrap-hooks.test.mjs +1 -1
  117. package/packages/omo-codex/plugin/test/hook-status-message.test.mjs +22 -9
  118. package/packages/omo-codex/plugin/test/migrate-codex-config.test.mjs +275 -19
  119. package/packages/omo-codex/plugin/test/subagent-limit-migration.test.mjs +33 -0
  120. package/packages/omo-codex/plugin/test/sync-hook-status-messages.test.mjs +6 -6
  121. package/packages/omo-codex/plugin/test/sync-skills-orchestration.test.mjs +4 -2
  122. package/packages/omo-codex/plugin/test/ulw-plan-skill-contract.test.mjs +52 -0
  123. package/packages/omo-codex/scripts/install-dist/install-local.mjs +65 -39
  124. package/packages/shared-skills/skills/frontend/SKILL.md +9 -9
  125. package/packages/shared-skills/skills/frontend/references/design/README.md +7 -3
  126. package/packages/shared-skills/skills/frontend/references/design/_INDEX.md +1 -1
  127. package/packages/shared-skills/skills/frontend/references/design/design-system-architecture.md +24 -2
  128. package/packages/shared-skills/skills/frontend/references/designpowers/README.md +2 -2
  129. package/packages/shared-skills/skills/frontend/references/designpowers/lane-b-execution.md +1 -1
  130. package/packages/shared-skills/skills/review-work/SKILL.md +3 -1
  131. package/packages/shared-skills/skills/start-work/SKILL.md +4 -2
  132. package/packages/shared-skills/skills/ulw-research/SKILL.md +3 -1
  133. package/packages/shared-skills/skills/visual-qa/SKILL.md +13 -17
  134. package/script/qa/strip-ansi.mjs +10 -0
  135. package/script/qa/web-terminal-visual-qa.mjs +112 -195
  136. package/script/qa/xterm-live-terminal.mjs +180 -0
  137. package/script/qa/web-terminal-renderer.mjs +0 -218
@@ -1,7 +1,8 @@
1
1
  // biome-ignore-all format: compact steering module must stay below the 240 pure-LOC budget
2
2
  import { isUlwLoopDone } from "./goal-status.js";
3
3
  import { seedDefaultSuccessCriteria } from "./plan-crud.js";
4
- import { appendLedger, readSteeringLedgerEntries, readUlwLoopPlan, withUlwLoopMutationLock, writePlan } from "./plan-io.js";
4
+ import { appendLedger, findAcceptedSteeringLedgerEntry, readUlwLoopPlan, withUlwLoopMutationLock, writePlan } from "./plan-io.js";
5
+ import { buildSteeringPlanSnapshot, changedGoalIdsBetween } from "./steering-snapshot.js";
5
6
  import { iso, ULW_LOOP_STEERING_MUTATION_KINDS, ULW_LOOP_SUCCESS_CRITERION_USER_MODELS } from "./types.js";
6
7
  const SOURCES = ["user_prompt_submit", "finding", "cli"];
7
8
  const PROTECTED = new Set(["aggregateCompletion", "codexObjective", "codexObjectiveAliases", "originalConstraints", "qualityGate", "status", "completedAt", "completionStatus"]);
@@ -260,15 +261,22 @@ export async function steerUlwLoop(repoRoot, proposal, scope) {
260
261
  return withUlwLoopMutationLock(repoRoot, scope, async () => {
261
262
  const plan = await readUlwLoopPlan(repoRoot, scope);
262
263
  const key = proposal.idempotencyKey ?? proposal.promptSignature;
263
- const prior = key === undefined ? undefined : (await readSteeringLedgerEntries(repoRoot, scope)).find((entry) => entry.steering?.invariant.accepted === true && (entry.idempotencyKey === key || entry.steering.idempotencyKey === key || entry.steering.promptSignature === key));
264
- if (prior?.steering !== undefined)
265
- return { plan, accepted: true, audit: { ...prior.steering, deduped: true }, rejectedReasons: [], deduped: true };
264
+ const prior = key === undefined ? undefined : await findAcceptedSteeringLedgerEntry(repoRoot, key, scope);
265
+ if (prior?.steering !== undefined) {
266
+ // Legacy entries embedded full-plan before/after snapshots; never
267
+ // re-surface those multi-MB payloads on the dedup path.
268
+ const { before: _before, after: _after, ...compactPrior } = prior.steering;
269
+ return { plan, accepted: true, audit: { ...compactPrior, deduped: true }, rejectedReasons: [], deduped: true };
270
+ }
266
271
  const audit = validateUlwLoopSteeringProposal(plan, proposal);
267
272
  const accepted = audit.invariant.accepted;
268
273
  const next = accepted ? applySteeringMutation(plan, proposal, audit) : plan;
269
- const finalAudit = { ...audit, before: plan };
270
- if (accepted)
271
- finalAudit.after = next;
274
+ const finalAudit = { ...audit };
275
+ if (accepted) {
276
+ const changed = changedGoalIdsBetween(plan, next);
277
+ finalAudit.before = buildSteeringPlanSnapshot(plan, changed);
278
+ finalAudit.after = buildSteeringPlanSnapshot(next, changed);
279
+ }
272
280
  if (accepted)
273
281
  await writePlan(repoRoot, next, scope);
274
282
  await appendLedger(repoRoot, ledgerEntry(proposal, finalAudit, proposal.now?.toISOString() ?? iso()), scope);
@@ -284,9 +292,5 @@ function ledgerEntry(proposal, audit, at) {
284
292
  entry.criterionId = proposal.criterionId;
285
293
  if (proposal.idempotencyKey !== undefined)
286
294
  entry.idempotencyKey = proposal.idempotencyKey;
287
- if (audit.before !== undefined)
288
- entry.before = audit.before;
289
- if (audit.after !== undefined)
290
- entry.after = audit.after;
291
295
  return entry;
292
296
  }
@@ -7,7 +7,7 @@
7
7
  "type": "command",
8
8
  "command": "node \"${PLUGIN_ROOT}/dist/cli.js\" hook user-prompt-submit --with-ultrawork",
9
9
  "timeout": 10,
10
- "statusMessage": "(OmO) Checking Ulw-Loop Steering"
10
+ "statusMessage": "(OmO 4.16.2) Checking Ulw-Loop Steering"
11
11
  }
12
12
  ]
13
13
  }
@@ -20,7 +20,7 @@
20
20
  "type": "command",
21
21
  "command": "node \"${PLUGIN_ROOT}/dist/cli.js\" hook pre-tool-use",
22
22
  "timeout": 5,
23
- "statusMessage": "(OmO) Enforcing Unlimited Ulw-Loop Budget"
23
+ "statusMessage": "(OmO 4.16.2) Enforcing Unlimited Ulw-Loop Budget"
24
24
  }
25
25
  ]
26
26
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@code-yeongyu/codex-ulw-loop",
3
- "version": "4.16.0",
3
+ "version": "4.16.2",
4
4
  "description": "Codex plugin: durable repo-native multi-goal orchestration with embedded success criteria and observable evidence audit.",
5
5
  "type": "module",
6
6
  "packageManager": "npm@11.12.1",
@@ -22,7 +22,7 @@ This skill is intentionally compact. The full workflow lives in `references/full
22
22
  - Use the ulw-loop CLI state under `.omo/ulw-loop`; do not hand-edit goal state.
23
23
  - After any compaction or context loss, re-read brief + goals + ledger FIRST plus `omo ulw-loop status --json`, then resume; never re-plan from scratch.
24
24
  - If `omo ulw-loop create-goals` says the existing aggregate is already complete, start unrelated new work with a fresh `--session-id <new-id>` instead of steering or forcing the completed default state. Use `--force` only to intentionally overwrite completed evidence.
25
- - Every success criterion needs observable evidence from a real surface: a channel (tmux, HTTP, browser, computer-use) or, for CLI- or data-shaped criteria, an auxiliary surface (CLI stdout, DB diff, parsed config dump).
25
+ - Every success criterion needs observable evidence from a real surface: a channel (terminal/TUI via the xterm.js web terminal, HTTP, browser, computer-use) or, for CLI- or data-shaped criteria, an auxiliary surface (CLI stdout, DB diff, parsed config dump).
26
26
  - Record evidence through the CLI only after cleanup receipts are available.
27
27
  - Delegate code edits, test writes, fixes, and QA execution to right-sized Codex subagents when the workflow requires it.
28
28
  - Every `multi_agent_v1.spawn_agent` message starts with `TASK:`, then names `DELIVERABLE`, `SCOPE`, and `VERIFY`; put role and specialty instructions inside `message`; use `fork_context: false` unless full history is truly required.
@@ -46,4 +46,6 @@ The full workflow may mention OpenCode-style orchestration examples. In Codex, t
46
46
  | Wait for background result | `multi_agent_v1.wait_agent(...)` |
47
47
  | Clean up finished worker | `multi_agent_v1.close_agent(...)` |
48
48
 
49
+ Flat `spawn_agent` requiring `task_name` instead (`multi_agent_v2`)? Rewrite rows: add `"task_name"`, `"fork_context":false` → `"fork_turns":"none"`, `wait_agent` takes only `timeout_ms`, no `close_agent` — finished agents end on their own.
50
+
49
51
  When translating `load_skills=[...]`, include the requested skill names in the spawned agent's `message`.
@@ -19,16 +19,16 @@ Audit each pass, fail, block, steering change, and checkpoint in `.omo/ulw-loop/
19
19
  Run each criterion's real-surface proof yourself through the channel that faithfully exercises it; capture the artifact before recording PASS.
20
20
 
21
21
  1. **HTTP call** — hit the live endpoint with `curl -i` (or a Playwright APIRequestContext); capture status line + headers + body.
22
- 2. **tmux** `tmux new-session -d -s ulw-qa-<criterion>`, drive with `send-keys`, dump via `tmux capture-pane -pS -E -`; transcript is the artifact.
22
+ 2. **Terminal / TUI** - prove it through the xterm.js web terminal; tmux `send-keys` is fine for a boot smoke, but NEVER `tmux capture-pane` for color/layout/CJK evidence (it degrades truecolor).
23
23
  3. **Browser use** — in Codex, use `browser:control-in-app-browser` first when available and the scenario does not need an authenticated or persistent user browser profile. Otherwise use Chrome to drive the REAL page; if unavailable, use agent-browser. Capture action log + screenshot path. Never downgrade a browser-facing criterion.
24
24
  4. **Computer use** — for desktop/GUI apps, drive the running app via OS automation (computer-use, AppleScript, xdotool, etc.); capture action log + screenshot.
25
25
 
26
- For TUI visual QA, pair the tmux transcript with a browser-rendered terminal
27
- screenshot. In this repo run `node script/qa/web-terminal-visual-qa.mjs
28
- --from-file <capture.txt> --evidence-dir <dir>` and record `terminal.png`,
29
- `terminal.html`, `terminal.txt`, and `metadata.json` as the visual evidence
30
- bundle. This is mandatory when a PR or review needs to inspect the terminal
31
- screen, not just the text.
26
+ For TUI visual QA, render the terminal through the real xterm.js web terminal and
27
+ screenshot it - NEVER a `tmux capture-pane` dump (it degrades color and wide-glyph
28
+ width). In this repo run `node script/qa/web-terminal-visual-qa.mjs --command
29
+ "<cmd>" --input "{Enter}" --evidence-dir <dir>` (live pty + xterm.js in Chrome;
30
+ `--from-file` replays a raw stream) and record `terminal.png`, `terminal.txt`, and
31
+ `metadata.json`. Mandatory when a PR or review must inspect the terminal screen.
32
32
 
33
33
  Auxiliary surfaces (CLI stdout / DB state diff / parsed config dump) are first-class evidence for CLI- or data-shaped criteria; use a channel scenario when the behavior is user-facing. `--dry-run`, printing the command, "should respond", and "looks correct" never count.
34
34
 
@@ -39,8 +39,8 @@ export async function ulwLoopCommand(argv: readonly string[]): Promise<number> {
39
39
  const rest = argv.slice(1);
40
40
  const repoRoot = process.cwd();
41
41
  const json = hasFlag(rest, "--json");
42
- const scope = commandScope(rest);
43
42
  try {
43
+ const scope = commandScope(rest);
44
44
  if (!isUlwLoopSubcommand(command)) {
45
45
  if (json) {
46
46
  printJsonError(
@@ -94,7 +94,22 @@ function unhandledSubcommand(command: never): never {
94
94
  throw new UlwLoopError(`Unhandled ulw-loop subcommand: ${String(command)}.`, "ULW_LOOP_SUBCOMMAND_UNHANDLED");
95
95
  }
96
96
 
97
+ const SESSION_ID_FLAG = "--session-id";
98
+
99
+ function sessionIdFlagPresent(argv: readonly string[]): boolean {
100
+ return hasFlag(argv, SESSION_ID_FLAG) || argv.some((arg) => arg.startsWith(`${SESSION_ID_FLAG}=`));
101
+ }
102
+
97
103
  function commandScope(argv: readonly string[]): UlwLoopScope | undefined {
98
- const sessionId = readValue(argv, "--session-id") ?? resolveUlwLoopSessionIdFromEnv();
104
+ if (sessionIdFlagPresent(argv)) {
105
+ const sessionId = readValue(argv, SESSION_ID_FLAG)?.trim();
106
+ if (!sessionId) {
107
+ throw new UlwLoopError(`${SESSION_ID_FLAG} requires a non-empty value.`, "ULW_LOOP_SESSION_ID_REQUIRED", {
108
+ details: { flag: SESSION_ID_FLAG },
109
+ });
110
+ }
111
+ return { sessionId };
112
+ }
113
+ const sessionId = resolveUlwLoopSessionIdFromEnv();
99
114
  return sessionId === null ? undefined : { sessionId };
100
115
  }
@@ -73,7 +73,8 @@ function model(value: string | undefined): UlwLoopSuccessCriterionUserModel | un
73
73
  function neverKind(kind: never): never { return fail(`Unsupported steering kind: ${String(kind)}.`, "ULW_LOOP_STEERING_KIND_UNSUPPORTED", { kind }); }
74
74
 
75
75
  export async function parseSteeringProposal(argv: readonly string[]): Promise<CliSteeringProposal> {
76
- const kind = parseSteeringKind(argv); const source = parseSteeringSource(argv); const base = { kind, source, evidence: required(argv, "--evidence"), rationale: required(argv, "--rationale") };
76
+ const kind = parseSteeringKind(argv); const source = parseSteeringSource(argv); const idempotencyKey = text(readValue(argv, "--idempotency-key"), "--idempotency-key");
77
+ const base = { kind, source, evidence: required(argv, "--evidence"), rationale: required(argv, "--rationale"), ...(idempotencyKey === undefined ? {} : { idempotencyKey }) };
77
78
  switch (kind) {
78
79
  case "add_subgoal": return normalizeSteeringProposal({ ...base, title: required(argv, "--title"), objective: required(argv, "--objective") });
79
80
  case "split_subgoal": { const goalId = requiredGoal(argv); return normalizeSteeringProposal({ ...base, goalId, targetGoalId: goalId, childGoals: await children(argv, "--children", true) }); }
@@ -1,4 +1,6 @@
1
+ import { createReadStream } from "node:fs";
1
2
  import { appendFile, mkdir, readFile, rename, writeFile } from "node:fs/promises";
3
+ import { createInterface } from "node:readline";
2
4
 
3
5
  import { aggregateCodexObjectiveForScope } from "./goal-status.js";
4
6
  import {
@@ -14,7 +16,7 @@ import { iso, ULW_LOOP_DIR, ULW_LOOP_GOALS, ULW_LOOP_LEDGER, UlwLoopError } from
14
16
 
15
17
  const LEGACY_OBJECTIVE_PREFIX = `Complete all ulw-loop stories in ${ULW_LOOP_DIR}/${ULW_LOOP_GOALS}: `;
16
18
  const LEGACY_OBJECTIVE = `Complete all ulw-loop stories listed in ${ULW_LOOP_DIR}/${ULW_LOOP_GOALS}. Use ${ULW_LOOP_DIR}/${ULW_LOOP_LEDGER} as the durable audit trail.`;
17
- const locks = new Map<string, Promise<unknown>>();
19
+ const locks = new Map<string, Promise<undefined>>();
18
20
 
19
21
  function hasCode(error: unknown, code: string): boolean {
20
22
  return error instanceof Error && "code" in error && error.code === code;
@@ -43,12 +45,19 @@ export async function withUlwLoopMutationLock<T>(
43
45
  const fn = typeof scopeOrFn === "function" ? scopeOrFn : maybeFn;
44
46
  if (fn === undefined) throw new UlwLoopError("Missing ulw-loop mutation body.", "ULW_LOOP_LOCK_BODY_MISSING");
45
47
  const lockKey = `${repoRoot}\0${ulwLoopRelativeDir(scope)}`;
46
- const prior = locks.get(lockKey) ?? Promise.resolve();
48
+ const prior = locks.get(lockKey) ?? Promise.resolve(undefined);
47
49
  const run = prior.then(fn, fn);
48
- locks.set(
49
- lockKey,
50
- run.catch(() => undefined),
50
+ // The stored gate resolves to undefined so the map never retains fn's result
51
+ // (plans/audits), and it removes itself once no newer waiter replaced it —
52
+ // otherwise a long-lived host leaks one entry per (repo, scope) forever.
53
+ const gate: Promise<undefined> = run.then(
54
+ () => undefined,
55
+ () => undefined,
51
56
  );
57
+ locks.set(lockKey, gate);
58
+ void gate.then(() => {
59
+ if (locks.get(lockKey) === gate) locks.delete(lockKey);
60
+ });
52
61
  return run;
53
62
  }
54
63
 
@@ -107,18 +116,57 @@ export async function appendLedger(repoRoot: string, entry: UlwLoopLedgerEntry,
107
116
  await appendFile(ulwLoopLedgerPath(repoRoot, scope), `${JSON.stringify(entry)}\n`, "utf8");
108
117
  }
109
118
 
110
- export async function readSteeringLedgerEntries(repoRoot: string, scope?: UlwLoopScope): Promise<UlwLoopLedgerEntry[]> {
111
- let raw: string;
119
+ /**
120
+ * Streams raw ledger lines without materializing the file. Real ledgers reach
121
+ * many MB (legacy entries embedded full-plan snapshots), so `readFile` here
122
+ * ballooned every steer/dedup path; line-at-a-time keeps memory O(longest line).
123
+ */
124
+ async function* ledgerLines(repoRoot: string, scope?: UlwLoopScope): AsyncGenerator<string> {
125
+ const stream = createReadStream(ulwLoopLedgerPath(repoRoot, scope), { encoding: "utf8" });
126
+ const lines = createInterface({ input: stream, crlfDelay: Number.POSITIVE_INFINITY });
112
127
  try {
113
- raw = await readFile(ulwLoopLedgerPath(repoRoot, scope), "utf8");
128
+ for await (const line of lines) {
129
+ if (line.trim().length > 0) yield line;
130
+ }
114
131
  } catch (error) {
115
- if (hasCode(error, "ENOENT")) return [];
116
- throw error;
132
+ if (!hasCode(error, "ENOENT")) throw error;
133
+ } finally {
134
+ lines.close();
135
+ stream.destroy();
117
136
  }
137
+ }
138
+
139
+ export async function readSteeringLedgerEntries(repoRoot: string, scope?: UlwLoopScope): Promise<UlwLoopLedgerEntry[]> {
118
140
  const entries: UlwLoopLedgerEntry[] = [];
119
- for (const line of raw.split(/\r?\n/).filter(Boolean)) {
141
+ for await (const line of ledgerLines(repoRoot, scope)) {
120
142
  const entry: UlwLoopLedgerEntry = JSON.parse(line);
121
143
  if (isSteeringKind(entry.kind)) entries.push(entry);
122
144
  }
123
145
  return entries;
124
146
  }
147
+
148
+ /**
149
+ * First accepted steering entry matching an idempotency key/prompt signature.
150
+ * A cheap substring probe on the raw line skips JSON.parse for the vast
151
+ * majority of entries, so dedup stays flat even on legacy multi-MB ledgers.
152
+ */
153
+ export async function findAcceptedSteeringLedgerEntry(
154
+ repoRoot: string,
155
+ key: string,
156
+ scope?: UlwLoopScope,
157
+ ): Promise<UlwLoopLedgerEntry | undefined> {
158
+ const probe = JSON.stringify(key);
159
+ for await (const line of ledgerLines(repoRoot, scope)) {
160
+ if (!line.includes(probe)) continue;
161
+ const entry: UlwLoopLedgerEntry = JSON.parse(line);
162
+ if (!isSteeringKind(entry.kind)) continue;
163
+ if (entry.steering?.invariant.accepted !== true) continue;
164
+ if (
165
+ entry.idempotencyKey === key ||
166
+ entry.steering.idempotencyKey === key ||
167
+ entry.steering.promptSignature === key
168
+ )
169
+ return entry;
170
+ }
171
+ return undefined;
172
+ }
@@ -0,0 +1,38 @@
1
+ import type { UlwLoopItem, UlwLoopPlan } from "./domain-types.js";
2
+ import type { UlwLoopSteeringPlanSnapshot } from "./steering-types.js";
3
+
4
+ /**
5
+ * Compact before/after snapshots for steering ledger entries.
6
+ *
7
+ * Ledger entries used to embed the FULL plan (every goal, criterion, and
8
+ * evidence string) twice per audit and twice more at the entry top level.
9
+ * That made each accepted steer O(plan size) on disk, so the ledger grew
10
+ * quadratically over a run, and every dedup scan re-hydrated all of it into
11
+ * memory. A snapshot instead records plan-level counters plus only the goals
12
+ * the mutation actually touched, keeping each entry O(changed goals).
13
+ */
14
+ export function buildSteeringPlanSnapshot(
15
+ plan: UlwLoopPlan,
16
+ changedGoalIds: ReadonlySet<string>,
17
+ ): UlwLoopSteeringPlanSnapshot {
18
+ const snapshot: UlwLoopSteeringPlanSnapshot = {
19
+ updatedAt: plan.updatedAt,
20
+ goalCount: plan.goals.length,
21
+ goalIds: plan.goals.map((goal) => goal.id),
22
+ goals: plan.goals.filter((goal) => changedGoalIds.has(goal.id)),
23
+ };
24
+ return plan.activeGoalId === undefined ? snapshot : { ...snapshot, activeGoalId: plan.activeGoalId };
25
+ }
26
+
27
+ /** Ids of goals that differ between two plans, including added or removed goals. */
28
+ export function changedGoalIdsBetween(before: UlwLoopPlan, after: UlwLoopPlan): Set<string> {
29
+ const beforeById = new Map<string, UlwLoopItem>(before.goals.map((goal) => [goal.id, goal]));
30
+ const changed = new Set<string>();
31
+ for (const goal of after.goals) {
32
+ const prior = beforeById.get(goal.id);
33
+ if (prior === undefined || JSON.stringify(prior) !== JSON.stringify(goal)) changed.add(goal.id);
34
+ beforeById.delete(goal.id);
35
+ }
36
+ for (const id of beforeById.keys()) changed.add(id);
37
+ return changed;
38
+ }
@@ -1,5 +1,5 @@
1
1
  import type { UlwLoopSteeringMutationKind, UlwLoopSteeringSource } from "./constants.js";
2
- import type { UlwLoopPlan } from "./domain-types.js";
2
+ import type { UlwLoopItem, UlwLoopPlan } from "./domain-types.js";
3
3
 
4
4
  export interface UlwLoopSteeringInvariantResult {
5
5
  accepted: boolean;
@@ -44,13 +44,21 @@ export interface UlwLoopSteeringProposal {
44
44
  now?: Date;
45
45
  }
46
46
 
47
+ export interface UlwLoopSteeringPlanSnapshot {
48
+ readonly updatedAt: string;
49
+ readonly activeGoalId?: string;
50
+ readonly goalCount: number;
51
+ readonly goalIds: readonly string[];
52
+ readonly goals: readonly UlwLoopItem[];
53
+ }
54
+
47
55
  export interface UlwLoopSteeringAudit {
48
56
  kind: UlwLoopSteeringMutationKind;
49
57
  source: UlwLoopSteeringSource;
50
58
  targetGoalIds: string[];
51
59
  criterionId?: string;
52
- before?: unknown;
53
- after?: unknown;
60
+ before?: UlwLoopSteeringPlanSnapshot;
61
+ after?: UlwLoopSteeringPlanSnapshot;
54
62
  evidence: string;
55
63
  rationale: string;
56
64
  invariant: UlwLoopSteeringInvariantResult;
@@ -2,7 +2,8 @@
2
2
  import { isUlwLoopDone } from "./goal-status.js";
3
3
  import type { UlwLoopScope } from "./paths.js";
4
4
  import { seedDefaultSuccessCriteria } from "./plan-crud.js";
5
- import { appendLedger, readSteeringLedgerEntries, readUlwLoopPlan, withUlwLoopMutationLock, writePlan } from "./plan-io.js";
5
+ import { appendLedger, findAcceptedSteeringLedgerEntry, readUlwLoopPlan, withUlwLoopMutationLock, writePlan } from "./plan-io.js";
6
+ import { buildSteeringPlanSnapshot, changedGoalIdsBetween } from "./steering-snapshot.js";
6
7
  import type {
7
8
  SteerUlwLoopResult,
8
9
  UlwLoopItem,
@@ -245,13 +246,22 @@ export async function steerUlwLoop(repoRoot: string, proposal: UlwLoopSteeringPr
245
246
  return withUlwLoopMutationLock(repoRoot, scope, async () => {
246
247
  const plan = await readUlwLoopPlan(repoRoot, scope);
247
248
  const key = proposal.idempotencyKey ?? proposal.promptSignature;
248
- const prior = key === undefined ? undefined : (await readSteeringLedgerEntries(repoRoot, scope)).find((entry) => entry.steering?.invariant.accepted === true && (entry.idempotencyKey === key || entry.steering.idempotencyKey === key || entry.steering.promptSignature === key));
249
- if (prior?.steering !== undefined) return { plan, accepted: true, audit: { ...prior.steering, deduped: true }, rejectedReasons: [], deduped: true };
249
+ const prior = key === undefined ? undefined : await findAcceptedSteeringLedgerEntry(repoRoot, key, scope);
250
+ if (prior?.steering !== undefined) {
251
+ // Legacy entries embedded full-plan before/after snapshots; never
252
+ // re-surface those multi-MB payloads on the dedup path.
253
+ const { before: _before, after: _after, ...compactPrior } = prior.steering;
254
+ return { plan, accepted: true, audit: { ...compactPrior, deduped: true }, rejectedReasons: [], deduped: true };
255
+ }
250
256
  const audit = validateUlwLoopSteeringProposal(plan, proposal);
251
257
  const accepted = audit.invariant.accepted;
252
258
  const next = accepted ? applySteeringMutation(plan, proposal, audit) : plan;
253
- const finalAudit: UlwLoopSteeringAudit = { ...audit, before: plan };
254
- if (accepted) finalAudit.after = next;
259
+ const finalAudit: UlwLoopSteeringAudit = { ...audit };
260
+ if (accepted) {
261
+ const changed = changedGoalIdsBetween(plan, next);
262
+ finalAudit.before = buildSteeringPlanSnapshot(plan, changed);
263
+ finalAudit.after = buildSteeringPlanSnapshot(next, changed);
264
+ }
255
265
  if (accepted) await writePlan(repoRoot, next, scope);
256
266
  await appendLedger(repoRoot, ledgerEntry(proposal, finalAudit, proposal.now?.toISOString() ?? iso()), scope);
257
267
  return { plan: next, accepted, audit: finalAudit, rejectedReasons: audit.invariant.rejectedReasons, deduped: false };
@@ -264,7 +274,5 @@ function ledgerEntry(proposal: UlwLoopSteeringProposal, audit: UlwLoopSteeringAu
264
274
  if (goalId !== undefined) entry.goalId = goalId;
265
275
  if (proposal.criterionId !== undefined) entry.criterionId = proposal.criterionId;
266
276
  if (proposal.idempotencyKey !== undefined) entry.idempotencyKey = proposal.idempotencyKey;
267
- if (audit.before !== undefined) entry.before = audit.before;
268
- if (audit.after !== undefined) entry.after = audit.after;
269
277
  return entry;
270
278
  }
@@ -169,4 +169,20 @@ describe("ulwLoopCommand create-goals", () => {
169
169
 
170
170
  expect(await readFile(join(testDir, ".omo/ulw-loop/manual-456/goals.json"), "utf8")).toContain("Manual scoped");
171
171
  });
172
+
173
+ it("#given a valueless --session-id #when creating goals #then it fails and writes no plan", async () => {
174
+ const code = await ulwLoopCommand(["create-goals", "--session-id", "--brief", "- Alpha"]);
175
+
176
+ expect(code).toBe(1);
177
+ expect(err.join("")).toContain("--session-id requires a non-empty value");
178
+ await expect(readFile(join(testDir, ".omo/ulw-loop/goals.json"), "utf8")).rejects.toThrow();
179
+ });
180
+
181
+ it("#given an empty --session-id= #when creating goals #then it fails and writes no plan", async () => {
182
+ const code = await ulwLoopCommand(["create-goals", "--session-id=", "--brief", "- Alpha"]);
183
+
184
+ expect(code).toBe(1);
185
+ expect(err.join("")).toContain("--session-id requires a non-empty value");
186
+ await expect(readFile(join(testDir, ".omo/ulw-loop/goals.json"), "utf8")).rejects.toThrow();
187
+ });
172
188
  });