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
@@ -56,9 +56,10 @@ exercises the surface; capture the artifact.
56
56
  1. HTTP call — hit the live endpoint with `curl -i` (or a
57
57
  Playwright APIRequestContext); capture status line + headers +
58
58
  body.
59
- 2. tmux `tmux new-session -d -s ulw-qa-<criterion>`, drive with
60
- `send-keys`, dump via `tmux capture-pane -pS -E -`; transcript
61
- is the artifact.
59
+ 2. Terminal / TUI - drive a real pty and prove it through the
60
+ xterm.js web terminal (see the TUI visual QA note below). tmux
61
+ `send-keys` is fine for a boot smoke; NEVER `tmux capture-pane`
62
+ for color / layout / CJK evidence, which degrades truecolor.
62
63
  3. Browser use — in Codex, use `browser:control-in-app-browser`
63
64
  first when available and no authenticated/persistent user browser
64
65
  profile is required. Otherwise use Chrome to drive the REAL page;
@@ -86,13 +87,13 @@ channel scenario when the behavior is user-facing. `--dry-run`,
86
87
  printing the command, "should respond", and "looks correct" never
87
88
  count.
88
89
 
89
- For TUI visual QA, terminal transcripts alone are not enough when a
90
- visual surface is being evaluated. In this repo, prefer
91
- `node script/qa/web-terminal-visual-qa.mjs --title "<surface>" --from-file <capture.txt> --evidence-dir <dir>`
92
- or the helper's `--command` tmux-backed PTY connector when available.
93
- Outside this repo, capture equivalent browser/computer-use rendered
94
- terminal evidence: screenshot, plain transcript, rendered HTML or action
95
- log, and cleanup receipt.
90
+ For TUI visual QA, render the terminal through the real xterm.js web
91
+ terminal and screenshot it - never a `tmux capture-pane` dump, which
92
+ degrades color and wide-glyph width. In this repo:
93
+ `node script/qa/web-terminal-visual-qa.mjs --title "<surface>" --command "<cmd>" --input "{Enter}" --evidence-dir <dir>`
94
+ (live pty + xterm.js in Chrome; `--from-file <capture>` replays a raw
95
+ stream). Outside this repo, capture equivalent browser-rendered terminal
96
+ evidence: screenshot + plain transcript + cleanup receipt.
96
97
 
97
98
  # Bootstrap (DO ALL FOUR BEFORE ANY OTHER WORK — NO SKIPPING)
98
99
 
@@ -265,6 +266,7 @@ Every `multi_agent_v1.spawn_agent` message is self-contained and starts with
265
266
  handoff. Use `fork_context: false` unless full history is truly
266
267
  required; paste only the context the child needs. Full-history forks can
267
268
  make the child continue old parent context instead of the delegated task.
269
+ If your tool list has a flat `spawn_agent` with a required `task_name` instead of `multi_agent_v1.*` (`multi_agent_v2`), rewrite: `fork_context: false` becomes `fork_turns: "none"`, `send_input` becomes `send_message`, finished agents end on their own (no `close_agent`; `followup_task` re-tasks, `interrupt_agent` stops), and `wait_agent` takes only `timeout_ms`, returning on any child mailbox activity.
268
270
 
269
271
  # TOML-backed subagent routing compatibility
270
272
  Treat TOML-backed role routing as **routing-unverified**. The
@@ -294,6 +296,13 @@ evidence for that step. Do not start dependent implementation until the
294
296
  audit, research, or review result is integrated or explicitly recorded
295
297
  as inconclusive. Do not generate a plan before spawned research lanes
296
298
  that feed the plan have returned or been closed as inconclusive.
299
+ Spawn every independent child for the current wave first. After the wave
300
+ is launched, run `multi_agent_v1.wait_agent` for each spawned child until
301
+ each reaches terminal status (`completed`, `failed`, `blocked`, or
302
+ explicitly recorded inconclusive) before any dependent `update_plan`
303
+ transition, `create_goal` continuation, implementation tool call, plan
304
+ drafting, approval-gate work, PR handoff, or final response. A timeout is
305
+ not terminal status.
297
306
  Do not write the final answer, PR handoff, or completion summary while
298
307
  active child agents remain open. Use short `multi_agent_v1.wait_agent` cycles.
299
308
  After two silent waits send `TASK STILL ACTIVE: return <deliverable> or
@@ -67,6 +67,19 @@ Fan out read-only research before deciding. Every spawn names DELIVERABLE / SCOP
67
67
  multi_agent_v1.spawn_agent({"message":"TASK: act as an explorer. DELIVERABLE: ... SCOPE: ... VERIFY: ...","agent_type":"explorer","fork_context":false})
68
68
  ```
69
69
 
70
+ If your tool list has a flat `spawn_agent` with a required `task_name` instead of `multi_agent_v1.*` (`multi_agent_v2`), rewrite: add `"task_name":"<lowercase_digits_underscores>"`, replace `"fork_context":false` with `"fork_turns":"none"`, and `wait_agent` takes only `timeout_ms`, returning on any child mailbox activity (finished agents end on their own).
71
+
72
+ Spawn every independent child for the current wave first. After the wave
73
+ is launched, use `multi_agent_v1.wait_agent` for each child until each
74
+ reaches terminal status. A timeout is not terminal status. Do not start dependent planning, drafting, approval-gate work, or final handoff until each child result is integrated or recorded as inconclusive.
75
+
76
+ For work likely to exceed one wait cycle, require the child to send
77
+ `WORKING: <task> - <current phase>` before long passes and
78
+ `BLOCKED: <reason>` only when progress stops. A `multi_agent_v1.wait_agent`
79
+ timeout only means no new mailbox update arrived. Treat a running child as
80
+ alive. Fallback only when the child is completed without the deliverable,
81
+ ack-only after followup, explicitly `BLOCKED:`, or no longer running.
82
+
70
83
  Roles: `explorer` (internal patterns/conventions/tests), `librarian` (external docs/contracts), `metis` (gap analysis), `momus` (high-accuracy plan review). Full spawn/wait/fallback discipline is in `references/full-workflow.md`.
71
84
 
72
85
  ## Stop rules
@@ -96,6 +96,8 @@ Every spawn starts with `TASK:`, then DELIVERABLE / SCOPE / VERIFY inside `messa
96
96
  multi_agent_v1.spawn_agent({"message":"TASK: act as an explorer. DELIVERABLE: ... SCOPE: ... VERIFY: ...","agent_type":"explorer","fork_context":false})
97
97
  ```
98
98
 
99
+ If your tool list has a flat `spawn_agent` with a required `task_name` instead of `multi_agent_v1.*` (`multi_agent_v2`), rewrite: add `"task_name":"<lowercase_digits_underscores>"`, replace `"fork_context":false` with `"fork_turns":"none"`, and `wait_agent` takes only `timeout_ms`, returning on any child mailbox activity (finished agents end on their own — skip the close step).
100
+
99
101
  Roles: `explorer`, `librarian`, `metis`, `momus`. Spawn long plan/reviewer agents in the background and poll with short waits; require the child to send `WORKING: <task> - <phase>` before long passes and `BLOCKED: <reason>` only when progress stops. A wait timeout only means no new mailbox update arrived; treat a running child as alive. Fall back only when the child completed without the deliverable, is ack-only after followup, explicitly `BLOCKED:`, or no longer running; then respawn a smaller `fork_context: false` job. Close each agent after integrating its result.
100
102
 
101
103
  ## Stop rules
@@ -190,7 +190,7 @@ describe("codex ultrawork hook", () => {
190
190
  expect(parsed.hookSpecificOutput.additionalContext).toMatch(/# Manual-QA channels/);
191
191
  expect(parsed.hookSpecificOutput.additionalContext).toMatch(/TESTS ALONE NEVER PROVE DONE/);
192
192
  expect(parsed.hookSpecificOutput.additionalContext).toMatch(/1\. HTTP call/);
193
- expect(parsed.hookSpecificOutput.additionalContext).toMatch(/2\. tmux/);
193
+ expect(parsed.hookSpecificOutput.additionalContext).toMatch(/2\. Terminal \/ TUI/);
194
194
  expect(parsed.hookSpecificOutput.additionalContext).toMatch(/3\. Browser use/);
195
195
  expect(parsed.hookSpecificOutput.additionalContext).toMatch(/4\. Computer use/);
196
196
  expect(parsed.hookSpecificOutput.additionalContext).toMatch(/CLEANUP \(PAIRED/);
@@ -244,6 +244,27 @@ describe("codex ultrawork hook", () => {
244
244
  expect(directive).toMatch(/WORKING:/);
245
245
  });
246
246
 
247
+ it("#given directive #when inspected #then blocks dependent work until spawned planners finish", () => {
248
+ // given
249
+ const payload = {
250
+ hook_event_name: "UserPromptSubmit",
251
+ prompt: "ulw",
252
+ };
253
+
254
+ // when
255
+ const output = runUserPromptSubmitHook(payload, { skillFilePath: null });
256
+ const parsed = parseHookOutput(output);
257
+
258
+ // then
259
+ const directive = parsed.hookSpecificOutput.additionalContext;
260
+ expect(directive).toMatch(/Subagent-dependent transition barrier/);
261
+ expect(directive).toMatch(/Spawn every independent child for the current wave first/);
262
+ expect(directive).toMatch(/After the wave\s+is launched[\s\S]{0,240}wait_agent[\s\S]{0,240}terminal status/);
263
+ expect(directive).not.toMatch(/Immediately after any `multi_agent_v1\.spawn_agent`/);
264
+ expect(directive).toMatch(/Do not start dependent implementation/);
265
+ expect(directive).toMatch(/Do not mark an `update_plan` step `completed`/);
266
+ });
267
+
247
268
  it("#given directive #when inspected #then keeps impact-proportional sizing invariants", () => {
248
269
  // given
249
270
  const payload = {
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## [0.1.0] - unreleased
4
4
 
5
+ - **Memory:** steering ledger entries no longer embed the full plan four times (`before`/`after` at both the audit and entry level). Accepted steers now record a compact `UlwLoopSteeringPlanSnapshot` (plan counters + only the goals the mutation touched), shrinking a measured real-world entry from 189KB to 7.8KB (~24x) and ending quadratic `ledger.jsonl` growth over long runs.
6
+ - **Memory:** steering dedup (`--idempotency-key` / `promptSignature`) streams the ledger line-by-line with a substring pre-filter instead of `JSON.parse`-ing every entry into memory; dedup returns strip legacy full-plan `before`/`after` payloads from re-surfaced audits. `readSteeringLedgerEntries` streams too.
7
+ - **Memory:** `withUlwLoopMutationLock` no longer retains the mutation result (full plan/audit) per `(repo, scope)` in its module-level lock map; settled gates self-evict, so long-lived embedders stop accumulating entries.
8
+ - **Fix:** `omo ulw-loop steer --idempotency-key` was parsed but never forwarded into the proposal, so CLI steers never deduped. It is now wired through.
5
9
  - Standalone ultrawork injection (`--with-ultrawork`) now emits the same compact bootstrap pointer as the ultrawork component (opener mandate, `create_goal` with `objective` only, read the bundled `ultrawork` skill at a runtime-resolved absolute path), falling back to the full bundled directive when the plugin skills tree is absent. Keeps the injected payload below Codex App's hook-output truncation budget (code-yeongyu/oh-my-openagent#5828).
6
10
  - Initial scaffold of codex-ulw-loop plugin.
7
11
  - Per-Criterion Cycle: `EXECUTE` is now **EXECUTE-AS-SCENARIO** — the agent must run the Manual-QA channel scenario the criterion named (HTTP call / tmux / browser use / computer use; see new `## Manual-QA channels` section). Inserted a new **CLEAN (PAIRED, NEVER SKIP)** step that tears down every QA-spawned process / `tmux` session / browser context / container / port / temp dir before recording evidence; the cleanup receipt is embedded in the `--evidence` string. Missing receipt → record BLOCKED, not PASS. Added Constraint #13 and a Stop Rule for leftover state.
@@ -49,9 +49,10 @@ exercises the surface; capture the artifact.
49
49
  1. HTTP call — hit the live endpoint with `curl -i` (or a
50
50
  Playwright APIRequestContext); capture status line + headers +
51
51
  body.
52
- 2. tmux `tmux new-session -d -s ulw-qa-<criterion>`, drive with
53
- `send-keys`, dump via `tmux capture-pane -pS -E -`; transcript
54
- is the artifact.
52
+ 2. Terminal / TUI - drive a real pty and prove it through the
53
+ xterm.js web terminal (see the TUI visual QA note below). tmux
54
+ `send-keys` is fine for a boot smoke; NEVER `tmux capture-pane`
55
+ for color / layout / CJK evidence, which degrades truecolor.
55
56
  3. Browser use — in Codex, use `browser:control-in-app-browser`
56
57
  first when available and no authenticated/persistent user browser
57
58
  profile is required. Otherwise use Chrome to drive the REAL page;
@@ -79,13 +80,13 @@ channel scenario when the behavior is user-facing. `--dry-run`,
79
80
  printing the command, "should respond", and "looks correct" never
80
81
  count.
81
82
 
82
- For TUI visual QA, terminal transcripts alone are not enough when a
83
- visual surface is being evaluated. In this repo, prefer
84
- `node script/qa/web-terminal-visual-qa.mjs --title "<surface>" --from-file <capture.txt> --evidence-dir <dir>`
85
- or the helper's `--command` tmux-backed PTY connector when available.
86
- Outside this repo, capture equivalent browser/computer-use rendered
87
- terminal evidence: screenshot, plain transcript, rendered HTML or action
88
- log, and cleanup receipt.
83
+ For TUI visual QA, render the terminal through the real xterm.js web
84
+ terminal and screenshot it - never a `tmux capture-pane` dump, which
85
+ degrades color and wide-glyph width. In this repo:
86
+ `node script/qa/web-terminal-visual-qa.mjs --title "<surface>" --command "<cmd>" --input "{Enter}" --evidence-dir <dir>`
87
+ (live pty + xterm.js in Chrome; `--from-file <capture>` replays a raw
88
+ stream). Outside this repo, capture equivalent browser-rendered terminal
89
+ evidence: screenshot + plain transcript + cleanup receipt.
89
90
 
90
91
  # Bootstrap (DO ALL FOUR BEFORE ANY OTHER WORK — NO SKIPPING)
91
92
 
@@ -258,6 +259,7 @@ Every `multi_agent_v1.spawn_agent` message is self-contained and starts with
258
259
  handoff. Use `fork_context: false` unless full history is truly
259
260
  required; paste only the context the child needs. Full-history forks can
260
261
  make the child continue old parent context instead of the delegated task.
262
+ If your tool list has a flat `spawn_agent` with a required `task_name` instead of `multi_agent_v1.*` (`multi_agent_v2`), rewrite: `fork_context: false` becomes `fork_turns: "none"`, `send_input` becomes `send_message`, finished agents end on their own (no `close_agent`; `followup_task` re-tasks, `interrupt_agent` stops), and `wait_agent` takes only `timeout_ms`, returning on any child mailbox activity.
261
263
 
262
264
  # TOML-backed subagent routing compatibility
263
265
  Treat TOML-backed role routing as **routing-unverified**. The
@@ -287,6 +289,13 @@ evidence for that step. Do not start dependent implementation until the
287
289
  audit, research, or review result is integrated or explicitly recorded
288
290
  as inconclusive. Do not generate a plan before spawned research lanes
289
291
  that feed the plan have returned or been closed as inconclusive.
292
+ Spawn every independent child for the current wave first. After the wave
293
+ is launched, run `multi_agent_v1.wait_agent` for each spawned child until
294
+ each reaches terminal status (`completed`, `failed`, `blocked`, or
295
+ explicitly recorded inconclusive) before any dependent `update_plan`
296
+ transition, `create_goal` continuation, implementation tool call, plan
297
+ drafting, approval-gate work, PR handoff, or final response. A timeout is
298
+ not terminal status.
290
299
  Do not write the final answer, PR handoff, or completion summary while
291
300
  active child agents remain open. Use short `multi_agent_v1.wait_agent` cycles.
292
301
  After two silent waits send `TASK STILL ACTIVE: return <deliverable> or
@@ -24,8 +24,8 @@ export async function ulwLoopCommand(argv) {
24
24
  const rest = argv.slice(1);
25
25
  const repoRoot = process.cwd();
26
26
  const json = hasFlag(rest, "--json");
27
- const scope = commandScope(rest);
28
27
  try {
28
+ const scope = commandScope(rest);
29
29
  if (!isUlwLoopSubcommand(command)) {
30
30
  if (json) {
31
31
  printJsonError(new UlwLoopError(`Unknown ulw-loop subcommand: ${command}.`, "ULW_LOOP_SUBCOMMAND_UNKNOWN", {
@@ -79,7 +79,20 @@ export async function ulwLoopCommand(argv) {
79
79
  function unhandledSubcommand(command) {
80
80
  throw new UlwLoopError(`Unhandled ulw-loop subcommand: ${String(command)}.`, "ULW_LOOP_SUBCOMMAND_UNHANDLED");
81
81
  }
82
+ const SESSION_ID_FLAG = "--session-id";
83
+ function sessionIdFlagPresent(argv) {
84
+ return hasFlag(argv, SESSION_ID_FLAG) || argv.some((arg) => arg.startsWith(`${SESSION_ID_FLAG}=`));
85
+ }
82
86
  function commandScope(argv) {
83
- const sessionId = readValue(argv, "--session-id") ?? resolveUlwLoopSessionIdFromEnv();
87
+ if (sessionIdFlagPresent(argv)) {
88
+ const sessionId = readValue(argv, SESSION_ID_FLAG)?.trim();
89
+ if (!sessionId) {
90
+ throw new UlwLoopError(`${SESSION_ID_FLAG} requires a non-empty value.`, "ULW_LOOP_SESSION_ID_REQUIRED", {
91
+ details: { flag: SESSION_ID_FLAG },
92
+ });
93
+ }
94
+ return { sessionId };
95
+ }
96
+ const sessionId = resolveUlwLoopSessionIdFromEnv();
84
97
  return sessionId === null ? undefined : { sessionId };
85
98
  }
@@ -83,7 +83,8 @@ function neverKind(kind) { return fail(`Unsupported steering kind: ${String(kind
83
83
  export async function parseSteeringProposal(argv) {
84
84
  const kind = parseSteeringKind(argv);
85
85
  const source = parseSteeringSource(argv);
86
- const base = { kind, source, evidence: required(argv, "--evidence"), rationale: required(argv, "--rationale") };
86
+ const idempotencyKey = text(readValue(argv, "--idempotency-key"), "--idempotency-key");
87
+ const base = { kind, source, evidence: required(argv, "--evidence"), rationale: required(argv, "--rationale"), ...(idempotencyKey === undefined ? {} : { idempotencyKey }) };
87
88
  switch (kind) {
88
89
  case "add_subgoal": return normalizeSteeringProposal({ ...base, title: required(argv, "--title"), objective: required(argv, "--objective") });
89
90
  case "split_subgoal": {
@@ -521,7 +521,9 @@ function formatCodexGoalReconciliation(reconciliation) {
521
521
  }
522
522
 
523
523
  // components/ulw-loop/src/plan-io.ts
524
+ import { createReadStream } from "node:fs";
524
525
  import { appendFile, mkdir, readFile as readFile4, rename, writeFile } from "node:fs/promises";
526
+ import { createInterface } from "node:readline";
525
527
  var LEGACY_OBJECTIVE_PREFIX = `Complete all ulw-loop stories in ${ULW_LOOP_DIR}/${ULW_LOOP_GOALS}: `;
526
528
  var 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.`;
527
529
  var locks = new Map;
@@ -540,11 +542,18 @@ async function withUlwLoopMutationLock(repoRoot, scopeOrFn, maybeFn) {
540
542
  if (fn === undefined)
541
543
  throw new UlwLoopError("Missing ulw-loop mutation body.", "ULW_LOOP_LOCK_BODY_MISSING");
542
544
  const lockKey = `${repoRoot}\x00${ulwLoopRelativeDir(scope)}`;
543
- const prior = locks.get(lockKey) ?? Promise.resolve();
545
+ const prior = locks.get(lockKey) ?? Promise.resolve(undefined);
544
546
  const run = prior.then(fn, fn);
545
- locks.set(lockKey, run.catch(() => {
547
+ const gate = run.then(() => {
546
548
  return;
547
- }));
549
+ }, () => {
550
+ return;
551
+ });
552
+ locks.set(lockKey, gate);
553
+ gate.then(() => {
554
+ if (locks.get(lockKey) === gate)
555
+ locks.delete(lockKey);
556
+ });
548
557
  return run;
549
558
  }
550
559
  async function readUlwLoopPlan(repoRoot, scope) {
@@ -591,22 +600,36 @@ async function appendLedger(repoRoot, entry, scope) {
591
600
  await appendFile(ulwLoopLedgerPath(repoRoot, scope), `${JSON.stringify(entry)}
592
601
  `, "utf8");
593
602
  }
594
- async function readSteeringLedgerEntries(repoRoot, scope) {
595
- let raw;
603
+ async function* ledgerLines(repoRoot, scope) {
604
+ const stream = createReadStream(ulwLoopLedgerPath(repoRoot, scope), { encoding: "utf8" });
605
+ const lines = createInterface({ input: stream, crlfDelay: Number.POSITIVE_INFINITY });
596
606
  try {
597
- raw = await readFile4(ulwLoopLedgerPath(repoRoot, scope), "utf8");
607
+ for await (const line of lines) {
608
+ if (line.trim().length > 0)
609
+ yield line;
610
+ }
598
611
  } catch (error) {
599
- if (hasCode(error, "ENOENT"))
600
- return [];
601
- throw error;
612
+ if (!hasCode(error, "ENOENT"))
613
+ throw error;
614
+ } finally {
615
+ lines.close();
616
+ stream.destroy();
602
617
  }
603
- const entries = [];
604
- for (const line of raw.split(/\r?\n/).filter(Boolean)) {
618
+ }
619
+ async function findAcceptedSteeringLedgerEntry(repoRoot, key, scope) {
620
+ const probe = JSON.stringify(key);
621
+ for await (const line of ledgerLines(repoRoot, scope)) {
622
+ if (!line.includes(probe))
623
+ continue;
605
624
  const entry = JSON.parse(line);
606
- if (isSteeringKind(entry.kind))
607
- entries.push(entry);
625
+ if (!isSteeringKind(entry.kind))
626
+ continue;
627
+ if (entry.steering?.invariant.accepted !== true)
628
+ continue;
629
+ if (entry.idempotencyKey === key || entry.steering.idempotencyKey === key || entry.steering.promptSignature === key)
630
+ return entry;
608
631
  }
609
- return entries;
632
+ return;
610
633
  }
611
634
 
612
635
  // components/ulw-loop/src/evidence.ts
@@ -1254,7 +1277,8 @@ function neverKind(kind) {
1254
1277
  async function parseSteeringProposal(argv) {
1255
1278
  const kind = parseSteeringKind(argv);
1256
1279
  const source = parseSteeringSource(argv);
1257
- const base = { kind, source, evidence: required2(argv, "--evidence"), rationale: required2(argv, "--rationale") };
1280
+ const idempotencyKey = text(readValue(argv, "--idempotency-key"), "--idempotency-key");
1281
+ const base = { kind, source, evidence: required2(argv, "--evidence"), rationale: required2(argv, "--rationale"), ...idempotencyKey === undefined ? {} : { idempotencyKey } };
1258
1282
  switch (kind) {
1259
1283
  case "add_subgoal":
1260
1284
  return normalizeSteeringProposal({ ...base, title: required2(argv, "--title"), objective: required2(argv, "--objective") });
@@ -1725,6 +1749,30 @@ async function recordFinalReviewBlockers(repoRoot, args, scope) {
1725
1749
  });
1726
1750
  }
1727
1751
 
1752
+ // components/ulw-loop/src/steering-snapshot.ts
1753
+ function buildSteeringPlanSnapshot(plan, changedGoalIds) {
1754
+ const snapshot = {
1755
+ updatedAt: plan.updatedAt,
1756
+ goalCount: plan.goals.length,
1757
+ goalIds: plan.goals.map((goal) => goal.id),
1758
+ goals: plan.goals.filter((goal) => changedGoalIds.has(goal.id))
1759
+ };
1760
+ return plan.activeGoalId === undefined ? snapshot : { ...snapshot, activeGoalId: plan.activeGoalId };
1761
+ }
1762
+ function changedGoalIdsBetween(before, after) {
1763
+ const beforeById = new Map(before.goals.map((goal) => [goal.id, goal]));
1764
+ const changed = new Set;
1765
+ for (const goal of after.goals) {
1766
+ const prior = beforeById.get(goal.id);
1767
+ if (prior === undefined || JSON.stringify(prior) !== JSON.stringify(goal))
1768
+ changed.add(goal.id);
1769
+ beforeById.delete(goal.id);
1770
+ }
1771
+ for (const id of beforeById.keys())
1772
+ changed.add(id);
1773
+ return changed;
1774
+ }
1775
+
1728
1776
  // components/ulw-loop/src/steering.ts
1729
1777
  var SOURCES2 = ["user_prompt_submit", "finding", "cli"];
1730
1778
  var PROTECTED = new Set(["aggregateCompletion", "codexObjective", "codexObjectiveAliases", "originalConstraints", "qualityGate", "status", "completedAt", "completionStatus"]);
@@ -1982,15 +2030,20 @@ async function steerUlwLoop(repoRoot, proposal, scope) {
1982
2030
  return withUlwLoopMutationLock(repoRoot, scope, async () => {
1983
2031
  const plan = await readUlwLoopPlan(repoRoot, scope);
1984
2032
  const key = proposal.idempotencyKey ?? proposal.promptSignature;
1985
- 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));
1986
- if (prior?.steering !== undefined)
1987
- return { plan, accepted: true, audit: { ...prior.steering, deduped: true }, rejectedReasons: [], deduped: true };
2033
+ const prior = key === undefined ? undefined : await findAcceptedSteeringLedgerEntry(repoRoot, key, scope);
2034
+ if (prior?.steering !== undefined) {
2035
+ const { before: _before, after: _after, ...compactPrior } = prior.steering;
2036
+ return { plan, accepted: true, audit: { ...compactPrior, deduped: true }, rejectedReasons: [], deduped: true };
2037
+ }
1988
2038
  const audit = validateUlwLoopSteeringProposal(plan, proposal);
1989
2039
  const accepted = audit.invariant.accepted;
1990
2040
  const next = accepted ? applySteeringMutation(plan, proposal, audit) : plan;
1991
- const finalAudit = { ...audit, before: plan };
1992
- if (accepted)
1993
- finalAudit.after = next;
2041
+ const finalAudit = { ...audit };
2042
+ if (accepted) {
2043
+ const changed = changedGoalIdsBetween(plan, next);
2044
+ finalAudit.before = buildSteeringPlanSnapshot(plan, changed);
2045
+ finalAudit.after = buildSteeringPlanSnapshot(next, changed);
2046
+ }
1994
2047
  if (accepted)
1995
2048
  await writePlan(repoRoot, next, scope);
1996
2049
  await appendLedger(repoRoot, ledgerEntry(proposal, finalAudit, proposal.now?.toISOString() ?? iso()), scope);
@@ -2006,10 +2059,6 @@ function ledgerEntry(proposal, audit, at) {
2006
2059
  entry.criterionId = proposal.criterionId;
2007
2060
  if (proposal.idempotencyKey !== undefined)
2008
2061
  entry.idempotencyKey = proposal.idempotencyKey;
2009
- if (audit.before !== undefined)
2010
- entry.before = audit.before;
2011
- if (audit.after !== undefined)
2012
- entry.after = audit.after;
2013
2062
  return entry;
2014
2063
  }
2015
2064
 
@@ -2205,8 +2254,8 @@ async function ulwLoopCommand(argv) {
2205
2254
  const rest = argv.slice(1);
2206
2255
  const repoRoot = process.cwd();
2207
2256
  const json = hasFlag(rest, "--json");
2208
- const scope = commandScope(rest);
2209
2257
  try {
2258
+ const scope = commandScope(rest);
2210
2259
  if (!isUlwLoopSubcommand(command)) {
2211
2260
  if (json) {
2212
2261
  printJsonError(new UlwLoopError(`Unknown ulw-loop subcommand: ${command}.`, "ULW_LOOP_SUBCOMMAND_UNKNOWN", {
@@ -2264,8 +2313,21 @@ async function ulwLoopCommand(argv) {
2264
2313
  function unhandledSubcommand(command) {
2265
2314
  throw new UlwLoopError(`Unhandled ulw-loop subcommand: ${String(command)}.`, "ULW_LOOP_SUBCOMMAND_UNHANDLED");
2266
2315
  }
2316
+ var SESSION_ID_FLAG = "--session-id";
2317
+ function sessionIdFlagPresent(argv) {
2318
+ return hasFlag(argv, SESSION_ID_FLAG) || argv.some((arg) => arg.startsWith(`${SESSION_ID_FLAG}=`));
2319
+ }
2267
2320
  function commandScope(argv) {
2268
- const sessionId = readValue(argv, "--session-id") ?? resolveUlwLoopSessionIdFromEnv();
2321
+ if (sessionIdFlagPresent(argv)) {
2322
+ const sessionId2 = readValue(argv, SESSION_ID_FLAG)?.trim();
2323
+ if (!sessionId2) {
2324
+ throw new UlwLoopError(`${SESSION_ID_FLAG} requires a non-empty value.`, "ULW_LOOP_SESSION_ID_REQUIRED", {
2325
+ details: { flag: SESSION_ID_FLAG }
2326
+ });
2327
+ }
2328
+ return { sessionId: sessionId2 };
2329
+ }
2330
+ const sessionId = resolveUlwLoopSessionIdFromEnv();
2269
2331
  return sessionId === null ? undefined : { sessionId };
2270
2332
  }
2271
2333
 
@@ -6,3 +6,9 @@ export declare function readUlwLoopPlan(repoRoot: string, scope?: UlwLoopScope):
6
6
  export declare function writePlan(repoRoot: string, plan: UlwLoopPlan, scope?: UlwLoopScope): Promise<void>;
7
7
  export declare function appendLedger(repoRoot: string, entry: UlwLoopLedgerEntry, scope?: UlwLoopScope): Promise<void>;
8
8
  export declare function readSteeringLedgerEntries(repoRoot: string, scope?: UlwLoopScope): Promise<UlwLoopLedgerEntry[]>;
9
+ /**
10
+ * First accepted steering entry matching an idempotency key/prompt signature.
11
+ * A cheap substring probe on the raw line skips JSON.parse for the vast
12
+ * majority of entries, so dedup stays flat even on legacy multi-MB ledgers.
13
+ */
14
+ export declare function findAcceptedSteeringLedgerEntry(repoRoot: string, key: string, scope?: UlwLoopScope): Promise<UlwLoopLedgerEntry | undefined>;
@@ -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
  import { aggregateCodexObjectiveForScope } from "./goal-status.js";
3
5
  import { repoRelative, ulwLoopDir, ulwLoopGoalsPath, ulwLoopLedgerPath, ulwLoopRelativeDir, } from "./paths.js";
4
6
  import { iso, ULW_LOOP_DIR, ULW_LOOP_GOALS, ULW_LOOP_LEDGER, UlwLoopError } from "./types.js";
@@ -20,9 +22,17 @@ export async function withUlwLoopMutationLock(repoRoot, scopeOrFn, maybeFn) {
20
22
  if (fn === undefined)
21
23
  throw new UlwLoopError("Missing ulw-loop mutation body.", "ULW_LOOP_LOCK_BODY_MISSING");
22
24
  const lockKey = `${repoRoot}\0${ulwLoopRelativeDir(scope)}`;
23
- const prior = locks.get(lockKey) ?? Promise.resolve();
25
+ const prior = locks.get(lockKey) ?? Promise.resolve(undefined);
24
26
  const run = prior.then(fn, fn);
25
- locks.set(lockKey, run.catch(() => undefined));
27
+ // The stored gate resolves to undefined so the map never retains fn's result
28
+ // (plans/audits), and it removes itself once no newer waiter replaced it —
29
+ // otherwise a long-lived host leaks one entry per (repo, scope) forever.
30
+ const gate = run.then(() => undefined, () => undefined);
31
+ locks.set(lockKey, gate);
32
+ void gate.then(() => {
33
+ if (locks.get(lockKey) === gate)
34
+ locks.delete(lockKey);
35
+ });
26
36
  return run;
27
37
  }
28
38
  export async function readUlwLoopPlan(repoRoot, scope) {
@@ -69,21 +79,57 @@ export async function appendLedger(repoRoot, entry, scope) {
69
79
  await mkdir(ulwLoopDir(repoRoot, scope), { recursive: true });
70
80
  await appendFile(ulwLoopLedgerPath(repoRoot, scope), `${JSON.stringify(entry)}\n`, "utf8");
71
81
  }
72
- export async function readSteeringLedgerEntries(repoRoot, scope) {
73
- let raw;
82
+ /**
83
+ * Streams raw ledger lines without materializing the file. Real ledgers reach
84
+ * many MB (legacy entries embedded full-plan snapshots), so `readFile` here
85
+ * ballooned every steer/dedup path; line-at-a-time keeps memory O(longest line).
86
+ */
87
+ async function* ledgerLines(repoRoot, scope) {
88
+ const stream = createReadStream(ulwLoopLedgerPath(repoRoot, scope), { encoding: "utf8" });
89
+ const lines = createInterface({ input: stream, crlfDelay: Number.POSITIVE_INFINITY });
74
90
  try {
75
- raw = await readFile(ulwLoopLedgerPath(repoRoot, scope), "utf8");
91
+ for await (const line of lines) {
92
+ if (line.trim().length > 0)
93
+ yield line;
94
+ }
76
95
  }
77
96
  catch (error) {
78
- if (hasCode(error, "ENOENT"))
79
- return [];
80
- throw error;
97
+ if (!hasCode(error, "ENOENT"))
98
+ throw error;
99
+ }
100
+ finally {
101
+ lines.close();
102
+ stream.destroy();
81
103
  }
104
+ }
105
+ export async function readSteeringLedgerEntries(repoRoot, scope) {
82
106
  const entries = [];
83
- for (const line of raw.split(/\r?\n/).filter(Boolean)) {
107
+ for await (const line of ledgerLines(repoRoot, scope)) {
84
108
  const entry = JSON.parse(line);
85
109
  if (isSteeringKind(entry.kind))
86
110
  entries.push(entry);
87
111
  }
88
112
  return entries;
89
113
  }
114
+ /**
115
+ * First accepted steering entry matching an idempotency key/prompt signature.
116
+ * A cheap substring probe on the raw line skips JSON.parse for the vast
117
+ * majority of entries, so dedup stays flat even on legacy multi-MB ledgers.
118
+ */
119
+ export async function findAcceptedSteeringLedgerEntry(repoRoot, key, scope) {
120
+ const probe = JSON.stringify(key);
121
+ for await (const line of ledgerLines(repoRoot, scope)) {
122
+ if (!line.includes(probe))
123
+ continue;
124
+ const entry = JSON.parse(line);
125
+ if (!isSteeringKind(entry.kind))
126
+ continue;
127
+ if (entry.steering?.invariant.accepted !== true)
128
+ continue;
129
+ if (entry.idempotencyKey === key ||
130
+ entry.steering.idempotencyKey === key ||
131
+ entry.steering.promptSignature === key)
132
+ return entry;
133
+ }
134
+ return undefined;
135
+ }
@@ -0,0 +1,15 @@
1
+ import type { UlwLoopPlan } from "./domain-types.js";
2
+ import type { UlwLoopSteeringPlanSnapshot } from "./steering-types.js";
3
+ /**
4
+ * Compact before/after snapshots for steering ledger entries.
5
+ *
6
+ * Ledger entries used to embed the FULL plan (every goal, criterion, and
7
+ * evidence string) twice per audit and twice more at the entry top level.
8
+ * That made each accepted steer O(plan size) on disk, so the ledger grew
9
+ * quadratically over a run, and every dedup scan re-hydrated all of it into
10
+ * memory. A snapshot instead records plan-level counters plus only the goals
11
+ * the mutation actually touched, keeping each entry O(changed goals).
12
+ */
13
+ export declare function buildSteeringPlanSnapshot(plan: UlwLoopPlan, changedGoalIds: ReadonlySet<string>): UlwLoopSteeringPlanSnapshot;
14
+ /** Ids of goals that differ between two plans, including added or removed goals. */
15
+ export declare function changedGoalIdsBetween(before: UlwLoopPlan, after: UlwLoopPlan): Set<string>;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Compact before/after snapshots for steering ledger entries.
3
+ *
4
+ * Ledger entries used to embed the FULL plan (every goal, criterion, and
5
+ * evidence string) twice per audit and twice more at the entry top level.
6
+ * That made each accepted steer O(plan size) on disk, so the ledger grew
7
+ * quadratically over a run, and every dedup scan re-hydrated all of it into
8
+ * memory. A snapshot instead records plan-level counters plus only the goals
9
+ * the mutation actually touched, keeping each entry O(changed goals).
10
+ */
11
+ export function buildSteeringPlanSnapshot(plan, changedGoalIds) {
12
+ const snapshot = {
13
+ updatedAt: plan.updatedAt,
14
+ goalCount: plan.goals.length,
15
+ goalIds: plan.goals.map((goal) => goal.id),
16
+ goals: plan.goals.filter((goal) => changedGoalIds.has(goal.id)),
17
+ };
18
+ return plan.activeGoalId === undefined ? snapshot : { ...snapshot, activeGoalId: plan.activeGoalId };
19
+ }
20
+ /** Ids of goals that differ between two plans, including added or removed goals. */
21
+ export function changedGoalIdsBetween(before, after) {
22
+ const beforeById = new Map(before.goals.map((goal) => [goal.id, goal]));
23
+ const changed = new Set();
24
+ for (const goal of after.goals) {
25
+ const prior = beforeById.get(goal.id);
26
+ if (prior === undefined || JSON.stringify(prior) !== JSON.stringify(goal))
27
+ changed.add(goal.id);
28
+ beforeById.delete(goal.id);
29
+ }
30
+ for (const id of beforeById.keys())
31
+ changed.add(id);
32
+ return changed;
33
+ }
@@ -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
  export interface UlwLoopSteeringInvariantResult {
4
4
  accepted: boolean;
5
5
  structuralInvariantAccepted: boolean;
@@ -39,13 +39,20 @@ export interface UlwLoopSteeringProposal {
39
39
  idempotencyKey?: string;
40
40
  now?: Date;
41
41
  }
42
+ export interface UlwLoopSteeringPlanSnapshot {
43
+ readonly updatedAt: string;
44
+ readonly activeGoalId?: string;
45
+ readonly goalCount: number;
46
+ readonly goalIds: readonly string[];
47
+ readonly goals: readonly UlwLoopItem[];
48
+ }
42
49
  export interface UlwLoopSteeringAudit {
43
50
  kind: UlwLoopSteeringMutationKind;
44
51
  source: UlwLoopSteeringSource;
45
52
  targetGoalIds: string[];
46
53
  criterionId?: string;
47
- before?: unknown;
48
- after?: unknown;
54
+ before?: UlwLoopSteeringPlanSnapshot;
55
+ after?: UlwLoopSteeringPlanSnapshot;
49
56
  evidence: string;
50
57
  rationale: string;
51
58
  invariant: UlwLoopSteeringInvariantResult;