oh-my-codex 0.18.13 → 0.18.14

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 (277) hide show
  1. package/Cargo.lock +6 -6
  2. package/Cargo.toml +1 -1
  3. package/README.md +31 -11
  4. package/dist/agents/__tests__/native-config.test.js +25 -0
  5. package/dist/agents/__tests__/native-config.test.js.map +1 -1
  6. package/dist/agents/native-config.d.ts.map +1 -1
  7. package/dist/agents/native-config.js +5 -1
  8. package/dist/agents/native-config.js.map +1 -1
  9. package/dist/autopilot/__tests__/fsm.test.js +7 -0
  10. package/dist/autopilot/__tests__/fsm.test.js.map +1 -1
  11. package/dist/autopilot/__tests__/planner-routing.test.d.ts +2 -0
  12. package/dist/autopilot/__tests__/planner-routing.test.d.ts.map +1 -0
  13. package/dist/autopilot/__tests__/planner-routing.test.js +74 -0
  14. package/dist/autopilot/__tests__/planner-routing.test.js.map +1 -0
  15. package/dist/autopilot/__tests__/ralplan-gate.test.js +315 -0
  16. package/dist/autopilot/__tests__/ralplan-gate.test.js.map +1 -1
  17. package/dist/autopilot/completion-gate.js +1 -1
  18. package/dist/autopilot/completion-gate.js.map +1 -1
  19. package/dist/autopilot/fsm.d.ts +2 -2
  20. package/dist/autopilot/fsm.d.ts.map +1 -1
  21. package/dist/autopilot/fsm.js +3 -0
  22. package/dist/autopilot/fsm.js.map +1 -1
  23. package/dist/autopilot/planner-routing.d.ts +21 -0
  24. package/dist/autopilot/planner-routing.d.ts.map +1 -0
  25. package/dist/autopilot/planner-routing.js +59 -0
  26. package/dist/autopilot/planner-routing.js.map +1 -0
  27. package/dist/autopilot/ralplan-gate.d.ts.map +1 -1
  28. package/dist/autopilot/ralplan-gate.js +30 -0
  29. package/dist/autopilot/ralplan-gate.js.map +1 -1
  30. package/dist/autoresearch/goal.d.ts.map +1 -1
  31. package/dist/autoresearch/goal.js +10 -1
  32. package/dist/autoresearch/goal.js.map +1 -1
  33. package/dist/cli/__tests__/autoresearch-goal.test.js +33 -0
  34. package/dist/cli/__tests__/autoresearch-goal.test.js.map +1 -1
  35. package/dist/cli/__tests__/codex-plugin-layout.test.js +30 -0
  36. package/dist/cli/__tests__/codex-plugin-layout.test.js.map +1 -1
  37. package/dist/cli/__tests__/doctor-artifact-ownership.test.d.ts +2 -0
  38. package/dist/cli/__tests__/doctor-artifact-ownership.test.d.ts.map +1 -0
  39. package/dist/cli/__tests__/doctor-artifact-ownership.test.js +158 -0
  40. package/dist/cli/__tests__/doctor-artifact-ownership.test.js.map +1 -0
  41. package/dist/cli/__tests__/doctor-spark-routing.test.js +13 -0
  42. package/dist/cli/__tests__/doctor-spark-routing.test.js.map +1 -1
  43. package/dist/cli/__tests__/doctor-warning-copy.test.js +1 -0
  44. package/dist/cli/__tests__/doctor-warning-copy.test.js.map +1 -1
  45. package/dist/cli/__tests__/index.test.js +5 -0
  46. package/dist/cli/__tests__/index.test.js.map +1 -1
  47. package/dist/cli/__tests__/nested-help-routing.test.js +4 -0
  48. package/dist/cli/__tests__/nested-help-routing.test.js.map +1 -1
  49. package/dist/cli/__tests__/package-bin-contract.test.js +7 -1
  50. package/dist/cli/__tests__/package-bin-contract.test.js.map +1 -1
  51. package/dist/cli/__tests__/performance-goal.test.js +22 -0
  52. package/dist/cli/__tests__/performance-goal.test.js.map +1 -1
  53. package/dist/cli/__tests__/resume.test.js +96 -0
  54. package/dist/cli/__tests__/resume.test.js.map +1 -1
  55. package/dist/cli/__tests__/session-scoped-runtime.test.js +162 -0
  56. package/dist/cli/__tests__/session-scoped-runtime.test.js.map +1 -1
  57. package/dist/cli/__tests__/session-search.test.js +36 -0
  58. package/dist/cli/__tests__/session-search.test.js.map +1 -1
  59. package/dist/cli/__tests__/setup-agents-overwrite.test.js +35 -1
  60. package/dist/cli/__tests__/setup-agents-overwrite.test.js.map +1 -1
  61. package/dist/cli/__tests__/setup-install-mode.test.js +33 -0
  62. package/dist/cli/__tests__/setup-install-mode.test.js.map +1 -1
  63. package/dist/cli/__tests__/team.test.js +17 -3
  64. package/dist/cli/__tests__/team.test.js.map +1 -1
  65. package/dist/cli/__tests__/ultragoal.test.js +37 -0
  66. package/dist/cli/__tests__/ultragoal.test.js.map +1 -1
  67. package/dist/cli/__tests__/update.test.js +1 -0
  68. package/dist/cli/__tests__/update.test.js.map +1 -1
  69. package/dist/cli/autoresearch-goal.d.ts.map +1 -1
  70. package/dist/cli/autoresearch-goal.js +2 -1
  71. package/dist/cli/autoresearch-goal.js.map +1 -1
  72. package/dist/cli/doctor.d.ts +22 -0
  73. package/dist/cli/doctor.d.ts.map +1 -1
  74. package/dist/cli/doctor.js +263 -4
  75. package/dist/cli/doctor.js.map +1 -1
  76. package/dist/cli/index.d.ts +1 -1
  77. package/dist/cli/index.d.ts.map +1 -1
  78. package/dist/cli/index.js +65 -4
  79. package/dist/cli/index.js.map +1 -1
  80. package/dist/cli/performance-goal.d.ts.map +1 -1
  81. package/dist/cli/performance-goal.js +4 -2
  82. package/dist/cli/performance-goal.js.map +1 -1
  83. package/dist/cli/plugin-marketplace.d.ts +1 -0
  84. package/dist/cli/plugin-marketplace.d.ts.map +1 -1
  85. package/dist/cli/plugin-marketplace.js +67 -5
  86. package/dist/cli/plugin-marketplace.js.map +1 -1
  87. package/dist/cli/project-runtime-codex-homes.d.ts +2 -0
  88. package/dist/cli/project-runtime-codex-homes.d.ts.map +1 -1
  89. package/dist/cli/project-runtime-codex-homes.js +112 -5
  90. package/dist/cli/project-runtime-codex-homes.js.map +1 -1
  91. package/dist/cli/setup.d.ts.map +1 -1
  92. package/dist/cli/setup.js +15 -6
  93. package/dist/cli/setup.js.map +1 -1
  94. package/dist/cli/ultragoal.d.ts.map +1 -1
  95. package/dist/cli/ultragoal.js +5 -1
  96. package/dist/cli/ultragoal.js.map +1 -1
  97. package/dist/cli/update.d.ts.map +1 -1
  98. package/dist/cli/update.js +3 -0
  99. package/dist/cli/update.js.map +1 -1
  100. package/dist/config/__tests__/models.test.js +21 -1
  101. package/dist/config/__tests__/models.test.js.map +1 -1
  102. package/dist/config/models.d.ts +5 -0
  103. package/dist/config/models.d.ts.map +1 -1
  104. package/dist/config/models.js +23 -0
  105. package/dist/config/models.js.map +1 -1
  106. package/dist/goal-workflows/codex-goal-snapshot.d.ts +2 -0
  107. package/dist/goal-workflows/codex-goal-snapshot.d.ts.map +1 -1
  108. package/dist/goal-workflows/codex-goal-snapshot.js +10 -0
  109. package/dist/goal-workflows/codex-goal-snapshot.js.map +1 -1
  110. package/dist/hooks/__tests__/autopilot-skill-contract.test.js +7 -0
  111. package/dist/hooks/__tests__/autopilot-skill-contract.test.js.map +1 -1
  112. package/dist/hooks/__tests__/keyword-detector.test.js +46 -0
  113. package/dist/hooks/__tests__/keyword-detector.test.js.map +1 -1
  114. package/dist/hooks/__tests__/notify-fallback-watcher.test.js +100 -0
  115. package/dist/hooks/__tests__/notify-fallback-watcher.test.js.map +1 -1
  116. package/dist/hooks/__tests__/notify-hook-all-workers-idle.test.js +75 -0
  117. package/dist/hooks/__tests__/notify-hook-all-workers-idle.test.js.map +1 -1
  118. package/dist/hooks/__tests__/notify-hook-auto-nudge.test.js +225 -0
  119. package/dist/hooks/__tests__/notify-hook-auto-nudge.test.js.map +1 -1
  120. package/dist/hooks/__tests__/notify-hook-team-dispatch.test.js +75 -0
  121. package/dist/hooks/__tests__/notify-hook-team-dispatch.test.js.map +1 -1
  122. package/dist/hooks/__tests__/notify-hook-team-leader-nudge.test.js +200 -0
  123. package/dist/hooks/__tests__/notify-hook-team-leader-nudge.test.js.map +1 -1
  124. package/dist/hooks/__tests__/notify-hook-team-tmux-guard.test.js +187 -12
  125. package/dist/hooks/__tests__/notify-hook-team-tmux-guard.test.js.map +1 -1
  126. package/dist/hooks/__tests__/notify-hook-tmux-heal.test.js +225 -0
  127. package/dist/hooks/__tests__/notify-hook-tmux-heal.test.js.map +1 -1
  128. package/dist/hooks/__tests__/notify-hook-tmux-scrollback.test.js +0 -0
  129. package/dist/hooks/__tests__/notify-hook-tmux-scrollback.test.js.map +1 -1
  130. package/dist/hooks/__tests__/notify-hook-worker-idle.test.js +75 -0
  131. package/dist/hooks/__tests__/notify-hook-worker-idle.test.js.map +1 -1
  132. package/dist/hooks/keyword-detector.d.ts.map +1 -1
  133. package/dist/hooks/keyword-detector.js +4 -0
  134. package/dist/hooks/keyword-detector.js.map +1 -1
  135. package/dist/hud/__tests__/reconcile.test.js +137 -2
  136. package/dist/hud/__tests__/reconcile.test.js.map +1 -1
  137. package/dist/hud/__tests__/state.test.js +107 -0
  138. package/dist/hud/__tests__/state.test.js.map +1 -1
  139. package/dist/hud/__tests__/tmux.test.js +17 -0
  140. package/dist/hud/__tests__/tmux.test.js.map +1 -1
  141. package/dist/hud/reconcile.d.ts.map +1 -1
  142. package/dist/hud/reconcile.js +21 -7
  143. package/dist/hud/reconcile.js.map +1 -1
  144. package/dist/hud/render.d.ts.map +1 -1
  145. package/dist/hud/render.js +9 -0
  146. package/dist/hud/render.js.map +1 -1
  147. package/dist/hud/state.d.ts.map +1 -1
  148. package/dist/hud/state.js +43 -5
  149. package/dist/hud/state.js.map +1 -1
  150. package/dist/hud/types.d.ts +6 -0
  151. package/dist/hud/types.d.ts.map +1 -1
  152. package/dist/hud/types.js.map +1 -1
  153. package/dist/modes/__tests__/base-autopilot-gates.test.js +48 -0
  154. package/dist/modes/__tests__/base-autopilot-gates.test.js.map +1 -1
  155. package/dist/modes/base.d.ts.map +1 -1
  156. package/dist/modes/base.js +1 -0
  157. package/dist/modes/base.js.map +1 -1
  158. package/dist/performance-goal/artifacts.d.ts.map +1 -1
  159. package/dist/performance-goal/artifacts.js +10 -1
  160. package/dist/performance-goal/artifacts.js.map +1 -1
  161. package/dist/ralplan/__tests__/consensus-gate.test.js +112 -0
  162. package/dist/ralplan/__tests__/consensus-gate.test.js.map +1 -1
  163. package/dist/ralplan/consensus-gate.d.ts +23 -0
  164. package/dist/ralplan/consensus-gate.d.ts.map +1 -1
  165. package/dist/ralplan/consensus-gate.js +133 -21
  166. package/dist/ralplan/consensus-gate.js.map +1 -1
  167. package/dist/scripts/__tests__/codex-native-hook.test.js +831 -2
  168. package/dist/scripts/__tests__/codex-native-hook.test.js.map +1 -1
  169. package/dist/scripts/codex-native-hook.d.ts.map +1 -1
  170. package/dist/scripts/codex-native-hook.js +486 -21
  171. package/dist/scripts/codex-native-hook.js.map +1 -1
  172. package/dist/scripts/notify-hook/team-tmux-guard.d.ts.map +1 -1
  173. package/dist/scripts/notify-hook/team-tmux-guard.js +87 -8
  174. package/dist/scripts/notify-hook/team-tmux-guard.js.map +1 -1
  175. package/dist/scripts/notify-hook/tmux-injection.js +1 -1
  176. package/dist/scripts/notify-hook/tmux-injection.js.map +1 -1
  177. package/dist/scripts/run-compiled-ci.d.ts +2 -0
  178. package/dist/scripts/run-compiled-ci.d.ts.map +1 -0
  179. package/dist/scripts/run-compiled-ci.js +77 -0
  180. package/dist/scripts/run-compiled-ci.js.map +1 -0
  181. package/dist/scripts/sync-plugin-mirror.d.ts.map +1 -1
  182. package/dist/scripts/sync-plugin-mirror.js +1 -0
  183. package/dist/scripts/sync-plugin-mirror.js.map +1 -1
  184. package/dist/session-history/search.d.ts.map +1 -1
  185. package/dist/session-history/search.js +24 -9
  186. package/dist/session-history/search.js.map +1 -1
  187. package/dist/state/__tests__/operations.test.js +107 -3
  188. package/dist/state/__tests__/operations.test.js.map +1 -1
  189. package/dist/state/operations.d.ts.map +1 -1
  190. package/dist/state/operations.js +57 -2
  191. package/dist/state/operations.js.map +1 -1
  192. package/dist/team/__tests__/delivery-e2e-smoke.test.js +22 -1
  193. package/dist/team/__tests__/delivery-e2e-smoke.test.js.map +1 -1
  194. package/dist/team/__tests__/model-contract.test.js +57 -1
  195. package/dist/team/__tests__/model-contract.test.js.map +1 -1
  196. package/dist/team/__tests__/runtime.test.js +1468 -110
  197. package/dist/team/__tests__/runtime.test.js.map +1 -1
  198. package/dist/team/__tests__/scaling.test.js +63 -0
  199. package/dist/team/__tests__/scaling.test.js.map +1 -1
  200. package/dist/team/__tests__/state.test.js +24 -1
  201. package/dist/team/__tests__/state.test.js.map +1 -1
  202. package/dist/team/__tests__/tmux-session.test.js +512 -0
  203. package/dist/team/__tests__/tmux-session.test.js.map +1 -1
  204. package/dist/team/__tests__/worker-bootstrap.test.js +42 -9
  205. package/dist/team/__tests__/worker-bootstrap.test.js.map +1 -1
  206. package/dist/team/model-contract.d.ts +16 -0
  207. package/dist/team/model-contract.d.ts.map +1 -1
  208. package/dist/team/model-contract.js +41 -1
  209. package/dist/team/model-contract.js.map +1 -1
  210. package/dist/team/runtime.d.ts.map +1 -1
  211. package/dist/team/runtime.js +116 -30
  212. package/dist/team/runtime.js.map +1 -1
  213. package/dist/team/scaling.d.ts.map +1 -1
  214. package/dist/team/scaling.js +9 -1
  215. package/dist/team/scaling.js.map +1 -1
  216. package/dist/team/state/types.d.ts +2 -0
  217. package/dist/team/state/types.d.ts.map +1 -1
  218. package/dist/team/state/types.js.map +1 -1
  219. package/dist/team/state.d.ts +3 -0
  220. package/dist/team/state.d.ts.map +1 -1
  221. package/dist/team/state.js +20 -0
  222. package/dist/team/state.js.map +1 -1
  223. package/dist/team/tmux-session.d.ts +38 -3
  224. package/dist/team/tmux-session.d.ts.map +1 -1
  225. package/dist/team/tmux-session.js +275 -36
  226. package/dist/team/tmux-session.js.map +1 -1
  227. package/dist/team/worker-bootstrap.d.ts.map +1 -1
  228. package/dist/team/worker-bootstrap.js +26 -1
  229. package/dist/team/worker-bootstrap.js.map +1 -1
  230. package/dist/ultragoal/__tests__/artifacts.test.js +238 -0
  231. package/dist/ultragoal/__tests__/artifacts.test.js.map +1 -1
  232. package/dist/ultragoal/__tests__/docs-contract.test.js +3 -0
  233. package/dist/ultragoal/__tests__/docs-contract.test.js.map +1 -1
  234. package/dist/ultragoal/artifacts.d.ts +15 -0
  235. package/dist/ultragoal/artifacts.d.ts.map +1 -1
  236. package/dist/ultragoal/artifacts.js +167 -4
  237. package/dist/ultragoal/artifacts.js.map +1 -1
  238. package/dist/utils/__tests__/agents-md.test.js +39 -1
  239. package/dist/utils/__tests__/agents-md.test.js.map +1 -1
  240. package/dist/utils/__tests__/agents-model-table.test.js +28 -0
  241. package/dist/utils/__tests__/agents-model-table.test.js.map +1 -1
  242. package/dist/utils/agents-md.d.ts +4 -0
  243. package/dist/utils/agents-md.d.ts.map +1 -1
  244. package/dist/utils/agents-md.js +25 -0
  245. package/dist/utils/agents-md.js.map +1 -1
  246. package/dist/utils/agents-model-table.d.ts +7 -3
  247. package/dist/utils/agents-model-table.d.ts.map +1 -1
  248. package/dist/utils/agents-model-table.js +16 -8
  249. package/dist/utils/agents-model-table.js.map +1 -1
  250. package/dist/verification/__tests__/ci-rust-gates.test.js +4 -0
  251. package/dist/verification/__tests__/ci-rust-gates.test.js.map +1 -1
  252. package/package.json +2 -2
  253. package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
  254. package/plugins/oh-my-codex/hooks/codex-native-hook.mjs +59 -8
  255. package/plugins/oh-my-codex/skills/autopilot/SKILL.md +9 -5
  256. package/plugins/oh-my-codex/skills/autoresearch-goal/SKILL.md +3 -0
  257. package/plugins/oh-my-codex/skills/performance-goal/SKILL.md +3 -0
  258. package/plugins/oh-my-codex/skills/ralplan/SKILL.md +1 -1
  259. package/plugins/oh-my-codex/skills/ultragoal/SKILL.md +22 -4
  260. package/plugins/oh-my-codex/skills/ultrawork/SKILL.md +2 -2
  261. package/plugins/oh-my-codex/skills/ultrawork/references/agent-tiers.md +61 -0
  262. package/skills/autopilot/SKILL.md +9 -5
  263. package/skills/autoresearch-goal/SKILL.md +3 -0
  264. package/skills/ecomode/SKILL.md +1 -1
  265. package/skills/ecomode/references/agent-tiers.md +61 -0
  266. package/skills/performance-goal/SKILL.md +3 -0
  267. package/skills/ralplan/SKILL.md +1 -1
  268. package/skills/ultragoal/SKILL.md +22 -4
  269. package/skills/ultrawork/SKILL.md +2 -2
  270. package/skills/ultrawork/references/agent-tiers.md +61 -0
  271. package/src/scripts/__tests__/codex-native-hook.test.ts +975 -40
  272. package/src/scripts/codex-native-hook.ts +529 -22
  273. package/src/scripts/notify-hook/team-tmux-guard.ts +92 -8
  274. package/src/scripts/notify-hook/tmux-injection.ts +1 -1
  275. package/src/scripts/run-compiled-ci.ts +85 -0
  276. package/src/scripts/sync-plugin-mirror.ts +1 -0
  277. package/templates/AGENTS.md +6 -0
@@ -160,6 +160,31 @@ if [[ "$cmd" == "capture-pane" ]]; then
160
160
  printf '%s\\n' ${captureText}
161
161
  exit 0
162
162
  fi
163
+ if [[ "$cmd" == "set-buffer" ]]; then
164
+ printf '%s' "\${@: -1}" > "${tmuxLogPath}.buffer"
165
+ exit 0
166
+ fi
167
+ if [[ "$cmd" == "show-buffer" ]]; then
168
+ if [[ -f "${tmuxLogPath}.buffer" ]]; then cat "${tmuxLogPath}.buffer"; fi
169
+ exit 0
170
+ fi
171
+ if [[ "$cmd" == "paste-buffer" ]]; then
172
+ target=""
173
+ while [[ "$#" -gt 0 ]]; do
174
+ case "$1" in
175
+ -t) target="$2"; shift 2 ;;
176
+ *) shift ;;
177
+ esac
178
+ done
179
+ if [[ -f "${tmuxLogPath}.buffer" ]]; then
180
+ echo "send-keys -t \${target} -l $(cat "${tmuxLogPath}.buffer")" >> "${tmuxLogPath}"
181
+ fi
182
+ exit 0
183
+ fi
184
+ if [[ "$cmd" == "delete-buffer" ]]; then
185
+ rm -f "${tmuxLogPath}.buffer"
186
+ exit 0
187
+ fi
163
188
  if [[ "$cmd" == "send-keys" ]]; then
164
189
  ${sendDelaySeconds > 0 ? `sleep ${sendDelaySeconds}` : ""}
165
190
  ${removePathOnSend ? `rm -rf ${removePathOnSend}` : ""}
@@ -346,9 +371,9 @@ describe("codex native hook dispatch", () => {
346
371
  assert.equal(result.status, 0, result.stderr || result.stdout);
347
372
  assert.equal(result.stderr, "");
348
373
  const output = parseSingleJsonStdout(result.stdout);
349
- assert.equal(output.continue, false);
374
+ assert.equal(output.continue, undefined);
350
375
  assert.equal(output.decision, undefined);
351
- assert.equal(output.stopReason, "native_hook_stdin_parse_error");
376
+ assert.equal(output.stopReason, undefined);
352
377
  assert.equal(output.hookSpecificOutput, undefined);
353
378
  assert.match(String(output.systemMessage ?? ""), /stdin JSON parsing failed inside codex-native-hook:/);
354
379
  }
@@ -421,6 +446,151 @@ describe("codex native hook dispatch", () => {
421
446
  assert.equal(output.hookSpecificOutput, undefined);
422
447
  assert.match(String(output.systemMessage ?? ""), /stdin JSON parsing failed inside codex-native-hook:/);
423
448
  });
449
+ it("emits no-op JSON stdout for PreToolUse non-Bash tools with null output", async () => {
450
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-pretool-nonbash-noop-"));
451
+ try {
452
+ const result = spawnSync(process.execPath, [nativeHookScriptPath()], {
453
+ cwd,
454
+ input: JSON.stringify({
455
+ hook_event_name: "PreToolUse",
456
+ cwd,
457
+ session_id: "sess-cli-pretool-nonbash-noop",
458
+ thread_id: "thread-cli-pretool-nonbash-noop",
459
+ turn_id: "turn-cli-pretool-nonbash-noop",
460
+ tool_name: "Read",
461
+ tool_input: { file_path: "package.json" },
462
+ }),
463
+ encoding: "utf-8",
464
+ stdio: ["pipe", "pipe", "pipe"],
465
+ });
466
+ assert.equal(result.status, 0, result.stderr || result.stdout);
467
+ assert.equal(result.stderr, "");
468
+ assert.deepEqual(parseSingleJsonStdout(result.stdout), {});
469
+ }
470
+ finally {
471
+ await rm(cwd, { recursive: true, force: true });
472
+ }
473
+ });
474
+ it("emits PreToolUse CLI advisory JSON with only systemMessage", async () => {
475
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-pretool-schema-safe-"));
476
+ try {
477
+ const output = parseSingleJsonStdout(runNativeHookCli({
478
+ hook_event_name: "PreToolUse",
479
+ cwd,
480
+ session_id: "sess-cli-pretool-schema-safe",
481
+ thread_id: "thread-cli-pretool-schema-safe",
482
+ turn_id: "turn-cli-pretool-schema-safe",
483
+ tool_name: "Bash",
484
+ tool_input: { command: "rm -rf dist" },
485
+ }, { cwd }));
486
+ assert.deepEqual(output, {
487
+ systemMessage: "Destructive Bash command detected (`rm -rf dist`). Confirm the target and expected side effects before running it.",
488
+ });
489
+ }
490
+ finally {
491
+ await rm(cwd, { recursive: true, force: true });
492
+ }
493
+ });
494
+ it("emits PreToolUse CLI block JSON with only systemMessage", async () => {
495
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-pretool-block-schema-safe-"));
496
+ try {
497
+ const output = parseSingleJsonStdout(runNativeHookCli({
498
+ hook_event_name: "PreToolUse",
499
+ cwd,
500
+ session_id: "sess-cli-pretool-block-schema-safe",
501
+ thread_id: "thread-cli-pretool-block-schema-safe",
502
+ turn_id: "turn-cli-pretool-block-schema-safe",
503
+ tool_name: "Bash",
504
+ tool_input: { command: 'OMX_LORE_COMMIT_GUARD=1 git commit -m "fix tests"' },
505
+ }, { cwd }));
506
+ assert.deepEqual(Object.keys(output).sort(), ["systemMessage"]);
507
+ assert.match(String(output.systemMessage ?? ""), /Lore protocol/);
508
+ assert.equal(output.decision, undefined);
509
+ assert.equal(output.stopReason, undefined);
510
+ assert.equal(output.hookSpecificOutput, undefined);
511
+ }
512
+ finally {
513
+ await rm(cwd, { recursive: true, force: true });
514
+ }
515
+ });
516
+ it("preserves ralplan PreToolUse planning guard as schema-safe CLI systemMessage", async () => {
517
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-ralplan-pretool-boundary-"));
518
+ const sessionId = "sess-cli-ralplan-pretool-boundary";
519
+ const stateDir = join(cwd, ".omx", "state");
520
+ try {
521
+ await writeJson(join(stateDir, "session.json"), { session_id: sessionId });
522
+ await writeJson(join(stateDir, "sessions", sessionId, "skill-active-state.json"), {
523
+ active: true,
524
+ skill: "ralplan",
525
+ phase: "planning",
526
+ session_id: sessionId,
527
+ active_skills: [{ skill: "ralplan", phase: "planning", active: true, session_id: sessionId }],
528
+ });
529
+ await writeJson(join(stateDir, "sessions", sessionId, "ralplan-state.json"), {
530
+ active: true,
531
+ mode: "ralplan",
532
+ current_phase: "critic-review",
533
+ session_id: sessionId,
534
+ });
535
+ const output = parseSingleJsonStdout(runNativeHookCli({
536
+ hook_event_name: "PreToolUse",
537
+ cwd,
538
+ session_id: sessionId,
539
+ thread_id: "thread-cli-ralplan-pretool-boundary",
540
+ tool_name: "Edit",
541
+ tool_input: { file_path: "src/runtime.ts", old_string: "a", new_string: "b" },
542
+ }, { cwd }));
543
+ assert.deepEqual(Object.keys(output).sort(), ["systemMessage"]);
544
+ assert.match(String(output.systemMessage ?? ""), /Ralplan is active \(phase: critic-review\)/);
545
+ assert.match(String(output.systemMessage ?? ""), /implementation\/write tools are blocked/);
546
+ assert.match(String(output.systemMessage ?? ""), /Write only planning artifacts/);
547
+ assert.equal(output.decision, undefined);
548
+ assert.equal(output.reason, undefined);
549
+ assert.equal(output.hookSpecificOutput, undefined);
550
+ }
551
+ finally {
552
+ await rm(cwd, { recursive: true, force: true });
553
+ }
554
+ });
555
+ it("preserves deep-interview PreToolUse planning guard as schema-safe CLI systemMessage", async () => {
556
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-deep-interview-pretool-boundary-"));
557
+ const sessionId = "sess-cli-deep-interview-pretool-boundary";
558
+ const stateDir = join(cwd, ".omx", "state");
559
+ try {
560
+ await writeJson(join(stateDir, "session.json"), { session_id: sessionId });
561
+ await writeJson(join(stateDir, "sessions", sessionId, "skill-active-state.json"), {
562
+ active: true,
563
+ skill: "deep-interview",
564
+ phase: "planning",
565
+ session_id: sessionId,
566
+ active_skills: [{ skill: "deep-interview", phase: "planning", active: true, session_id: sessionId }],
567
+ });
568
+ await writeJson(join(stateDir, "sessions", sessionId, "deep-interview-state.json"), {
569
+ active: true,
570
+ mode: "deep-interview",
571
+ current_phase: "intent-first",
572
+ session_id: sessionId,
573
+ });
574
+ const output = parseSingleJsonStdout(runNativeHookCli({
575
+ hook_event_name: "PreToolUse",
576
+ cwd,
577
+ session_id: sessionId,
578
+ thread_id: "thread-cli-deep-interview-pretool-boundary",
579
+ tool_name: "Write",
580
+ tool_input: { file_path: "src/runtime.ts", content: "export const changed = true;\n" },
581
+ }, { cwd }));
582
+ assert.deepEqual(Object.keys(output).sort(), ["systemMessage"]);
583
+ assert.match(String(output.systemMessage ?? ""), /Deep-interview is active \(phase: intent-first\)/);
584
+ assert.match(String(output.systemMessage ?? ""), /implementation\/write tools are blocked/);
585
+ assert.match(String(output.systemMessage ?? ""), /requirements\/spec mode/);
586
+ assert.equal(output.decision, undefined);
587
+ assert.equal(output.reason, undefined);
588
+ assert.equal(output.hookSpecificOutput, undefined);
589
+ }
590
+ finally {
591
+ await rm(cwd, { recursive: true, force: true });
592
+ }
593
+ });
424
594
  it("emits parseable no-op JSON stdout for inactive Stop CLI runs", async () => {
425
595
  const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-stop-noop-json-"));
426
596
  try {
@@ -439,6 +609,31 @@ describe("codex native hook dispatch", () => {
439
609
  await rm(cwd, { recursive: true, force: true });
440
610
  }
441
611
  });
612
+ it("emits no-op JSON stdout for Stop payloads with no runtime output", async () => {
613
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-stop-null-output-"));
614
+ try {
615
+ const result = spawnSync(process.execPath, [nativeHookScriptPath()], {
616
+ cwd,
617
+ input: JSON.stringify({
618
+ hook_event_name: "Stop",
619
+ cwd,
620
+ session_id: "sess-cli-stop-null-output",
621
+ thread_id: "thread-cli-stop-null-output",
622
+ turn_id: "turn-cli-stop-null-output",
623
+ stop_hook_active: true,
624
+ }),
625
+ encoding: "utf-8",
626
+ stdio: ["pipe", "pipe", "pipe"],
627
+ });
628
+ assert.equal(result.status, 0, result.stderr || result.stdout);
629
+ assert.equal(result.stderr, "");
630
+ assert.deepEqual(parseSingleJsonStdout(result.stdout), {});
631
+ assert.equal(existsSync(join(cwd, ".omx", "state")), false);
632
+ }
633
+ finally {
634
+ await rm(cwd, { recursive: true, force: true });
635
+ }
636
+ });
442
637
  it("returns empty JSON for oversized Stop stdin without parsing or creating inactive state", async () => {
443
638
  const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-stop-oversized-"));
444
639
  try {
@@ -567,6 +762,79 @@ describe("codex native hook dispatch", () => {
567
762
  await rm(cwd, { recursive: true, force: true });
568
763
  }
569
764
  });
765
+ it("does not block Stop on stale session autopilot mirror when canonical skill state is inactive", async () => {
766
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-stale-autopilot-mirror-"));
767
+ try {
768
+ const sessionId = "sess-stale-autopilot-mirror";
769
+ await writeJson(join(cwd, ".omx", "state", "session.json"), { session_id: sessionId, cwd });
770
+ await writeJson(join(cwd, ".omx", "state", "skill-active-state.json"), {
771
+ version: 1,
772
+ active: false,
773
+ skill: "",
774
+ phase: "cancelled",
775
+ active_skills: [],
776
+ });
777
+ await writeJson(join(cwd, ".omx", "state", "sessions", sessionId, "autopilot-state.json"), {
778
+ active: true,
779
+ mode: "autopilot",
780
+ current_phase: "ultragoal",
781
+ session_id: sessionId,
782
+ });
783
+ await writeJson(join(cwd, ".omx", "state", "sessions", sessionId, "skill-active-state.json"), {
784
+ version: 1,
785
+ active: true,
786
+ skill: "autopilot",
787
+ phase: "ultragoal",
788
+ session_id: sessionId,
789
+ active_skills: [{ skill: "autopilot", phase: "ultragoal", active: true, session_id: sessionId }],
790
+ });
791
+ const stdout = runNativeHookCli({
792
+ hook_event_name: "Stop",
793
+ cwd,
794
+ session_id: sessionId,
795
+ thread_id: "thread-stale-autopilot-mirror",
796
+ }, { cwd });
797
+ assert.deepEqual(parseSingleJsonStdout(stdout), {});
798
+ }
799
+ finally {
800
+ await rm(cwd, { recursive: true, force: true });
801
+ }
802
+ });
803
+ it("includes blocking state source and canonical agreement in Stop diagnostics", async () => {
804
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-autopilot-diagnostic-"));
805
+ try {
806
+ const sessionId = "sess-autopilot-diagnostic";
807
+ await writeJson(join(cwd, ".omx", "state", "session.json"), { session_id: sessionId, cwd });
808
+ await writeJson(join(cwd, ".omx", "state", "skill-active-state.json"), {
809
+ version: 1,
810
+ active: true,
811
+ skill: "autopilot",
812
+ phase: "ultragoal",
813
+ session_id: sessionId,
814
+ active_skills: [{ skill: "autopilot", phase: "ultragoal", active: true, session_id: sessionId }],
815
+ });
816
+ await writeJson(join(cwd, ".omx", "state", "sessions", sessionId, "autopilot-state.json"), {
817
+ active: true,
818
+ mode: "autopilot",
819
+ current_phase: "ultragoal",
820
+ session_id: sessionId,
821
+ });
822
+ const output = parseSingleJsonStdout(runNativeHookCli({
823
+ hook_event_name: "Stop",
824
+ cwd,
825
+ session_id: sessionId,
826
+ thread_id: "thread-autopilot-diagnostic",
827
+ }, { cwd }));
828
+ assert.equal(output.decision, "block");
829
+ assert.match(String(output.reason ?? ""), /state: \.omx\/state\/sessions\/sess-autopilot-diagnostic\/autopilot-state\.json/);
830
+ assert.match(String(output.reason ?? ""), /canonical: canonical_agrees/);
831
+ assert.equal(output.statePath, ".omx/state/sessions/sess-autopilot-diagnostic/autopilot-state.json");
832
+ assert.equal(output.canonicalDisagreement, "canonical_agrees");
833
+ }
834
+ finally {
835
+ await rm(cwd, { recursive: true, force: true });
836
+ }
837
+ });
570
838
  it("emits exactly one parseable JSON object for active Stop CLI continuation", async () => {
571
839
  const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-stop-json-"));
572
840
  try {
@@ -2380,6 +2648,60 @@ standardMaxRounds = 15
2380
2648
  await rm(cwd, { recursive: true, force: true });
2381
2649
  }
2382
2650
  });
2651
+ it("nudges next-goal prompts when a completed Codex goal cleanup step remains", async () => {
2652
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-completed-goal-prompt-"));
2653
+ try {
2654
+ await writeJson(join(cwd, ".omx", "goals", "performance", "latency", "state.json"), {
2655
+ version: 1,
2656
+ workflow: "performance-goal",
2657
+ slug: "latency",
2658
+ objective: "Reduce latency",
2659
+ status: "complete",
2660
+ completedAt: "2026-05-20T00:00:00.000Z",
2661
+ });
2662
+ const result = await dispatchCodexNativeHook({
2663
+ hook_event_name: "UserPromptSubmit",
2664
+ cwd,
2665
+ session_id: "sess-completed-goal-prompt",
2666
+ thread_id: "thread-completed-goal-prompt",
2667
+ prompt: "Start the next performance goal now",
2668
+ }, { cwd });
2669
+ const output = JSON.stringify(result.outputJson);
2670
+ assert.match(output, /run \/goal clear/);
2671
+ assert.match(output, /before calling create_goal/);
2672
+ assert.match(output, /hooks only nudge and must not mutate Codex goal state/);
2673
+ assert.doesNotMatch(output, /cleared Codex goal state/i);
2674
+ }
2675
+ finally {
2676
+ await rm(cwd, { recursive: true, force: true });
2677
+ }
2678
+ });
2679
+ it("blocks Stop when a final answer starts another goal over completed state", async () => {
2680
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-completed-goal-stop-"));
2681
+ try {
2682
+ await writeJson(join(cwd, ".omx", "ultragoal", "goals.json"), {
2683
+ version: 1,
2684
+ aggregateCompletion: { status: "complete", completedAt: "2026-05-20T00:00:00.000Z" },
2685
+ goals: [{ id: "G001-done", status: "complete", objective: "Done" }],
2686
+ });
2687
+ const result = await dispatchCodexNativeHook({
2688
+ hook_event_name: "Stop",
2689
+ cwd,
2690
+ session_id: "sess-completed-goal-stop",
2691
+ thread_id: "thread-completed-goal-stop",
2692
+ last_assistant_message: "Starting another ultragoal now; create_goal payload follows.",
2693
+ }, { cwd });
2694
+ const output = JSON.stringify(result.outputJson);
2695
+ assert.equal(result.outputJson?.decision, "block");
2696
+ assert.equal(result.outputJson?.stopReason, "completed_codex_goal_cleanup_required");
2697
+ assert.match(output, /run \/goal clear/);
2698
+ assert.match(output, /before calling create_goal/);
2699
+ assert.match(output, /hooks only nudge and must not mutate Codex goal state/);
2700
+ }
2701
+ finally {
2702
+ await rm(cwd, { recursive: true, force: true });
2703
+ }
2704
+ });
2383
2705
  it("blocks ultragoal Stop for concise generic goal completion claims", async () => {
2384
2706
  const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-ultragoal-generic-complete-stop-"));
2385
2707
  try {
@@ -5279,6 +5601,127 @@ exit 0
5279
5601
  await rm(cwd, { recursive: true, force: true });
5280
5602
  }
5281
5603
  });
5604
+ it("allows Ralplan read-only inspection and planning artifact writes while blocking implementation targets", async () => {
5605
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-pretool-ralplan-guard-"));
5606
+ try {
5607
+ const stateDir = join(cwd, ".omx", "state");
5608
+ const sessionId = "sess-ralplan-guard";
5609
+ const sessionDir = join(stateDir, "sessions", sessionId);
5610
+ await mkdir(sessionDir, { recursive: true });
5611
+ await writeJson(join(stateDir, "session.json"), { session_id: sessionId, cwd });
5612
+ await writeJson(join(sessionDir, "skill-active-state.json"), {
5613
+ version: 1,
5614
+ active: true,
5615
+ skill: "ralplan",
5616
+ phase: "planning",
5617
+ session_id: sessionId,
5618
+ active_skills: [{ skill: "ralplan", phase: "planning", active: true, session_id: sessionId }],
5619
+ });
5620
+ await writeJson(join(sessionDir, "ralplan-state.json"), {
5621
+ active: true,
5622
+ mode: "ralplan",
5623
+ current_phase: "planning",
5624
+ session_id: sessionId,
5625
+ });
5626
+ const preToolUse = async (tool_name, tool_use_id, tool_input) => dispatchCodexNativeHook({
5627
+ hook_event_name: "PreToolUse",
5628
+ cwd,
5629
+ session_id: sessionId,
5630
+ tool_name,
5631
+ tool_use_id,
5632
+ tool_input,
5633
+ }, { cwd });
5634
+ const readOnlyCommands = [
5635
+ "git status --short",
5636
+ "ls -1 .omx/plans",
5637
+ "find .omx/plans -type f -name '*.md'",
5638
+ "grep -RIn \"Scholastic\" doc tests .omx/plans .omx/context",
5639
+ "rg \"Scholastic\" doc tests .omx/plans .omx/context",
5640
+ "sed -n '1,80p' .omx/plans/demo.md",
5641
+ "cat .omx/plans/demo.md",
5642
+ "git status --short; ls -1 .omx/plans; grep -RIn \"Scholastic\" doc tests .omx/plans .omx/context",
5643
+ ];
5644
+ for (const [index, command] of readOnlyCommands.entries()) {
5645
+ const result = await preToolUse("Bash", `tool-ralplan-read-${index}`, { command });
5646
+ assert.equal(result.outputJson, null, `read-only command should be allowed: ${command}`);
5647
+ }
5648
+ for (const path of [
5649
+ ".omx/context/findings.md",
5650
+ ".omx/plans/issue-2863.md",
5651
+ ".omx/specs/issue-2863.md",
5652
+ ".omx/state/required-planning-state.json",
5653
+ ]) {
5654
+ const writeResult = await preToolUse("Write", `tool-ralplan-write-${path}`, { file_path: path, content: "ok" });
5655
+ assert.equal(writeResult.outputJson, null, `Write should be allowed for ${path}`);
5656
+ }
5657
+ const allowedPatchAdd = await preToolUse("apply_patch", "tool-ralplan-patch-add", {
5658
+ input: "*** Begin Patch\n*** Add File: .omx/plans/issue-2863.md\n+# Plan\n*** End Patch\n",
5659
+ });
5660
+ assert.equal(allowedPatchAdd.outputJson, null);
5661
+ const allowedPatchUpdate = await preToolUse("ApplyPatch", "tool-ralplan-patch-update", {
5662
+ input: "*** Begin Patch\n*** Update File: .omx/plans/issue-2863.md\n@@\n-old\n+new\n*** End Patch\n",
5663
+ });
5664
+ assert.equal(allowedPatchUpdate.outputJson, null);
5665
+ const allowedRedirect = await preToolUse("Bash", "tool-ralplan-redirect-allow", {
5666
+ command: "printf '\\nmore\\n' >> .omx/plans/issue-2863.md",
5667
+ });
5668
+ assert.equal(allowedRedirect.outputJson, null);
5669
+ const allowedTee = await preToolUse("Bash", "tool-ralplan-tee-allow", {
5670
+ command: "printf '\\nmore\\n' | tee -a .omx/specs/issue-2863.md",
5671
+ });
5672
+ assert.equal(allowedTee.outputJson, null);
5673
+ const blockedRedirect = await preToolUse("Bash", "tool-ralplan-redirect-block", {
5674
+ command: "printf 'bad' > src/implementation.ts",
5675
+ });
5676
+ assert.equal(blockedRedirect.outputJson?.decision, "block");
5677
+ const redirectReason = String(blockedRedirect.outputJson?.reason ?? "");
5678
+ assert.match(redirectReason, /Bash redirect write/);
5679
+ assert.match(redirectReason, /src\/implementation\.ts/);
5680
+ const blockedEdit = await preToolUse("Edit", "tool-ralplan-edit-block", {
5681
+ file_path: "src/implementation.ts",
5682
+ old_string: "a",
5683
+ new_string: "b",
5684
+ });
5685
+ assert.equal(blockedEdit.outputJson?.decision, "block");
5686
+ const editReason = String(blockedEdit.outputJson?.reason ?? "");
5687
+ assert.match(editReason, /Edit path/);
5688
+ assert.match(editReason, /src\/implementation\.ts/);
5689
+ const blockedMixedPatch = await preToolUse("apply_patch", "tool-ralplan-patch-mixed", {
5690
+ input: "*** Begin Patch\n*** Add File: .omx/plans/ok.md\n+ok\n*** Add File: src/leak.ts\n+leak\n*** End Patch\n",
5691
+ });
5692
+ assert.equal(blockedMixedPatch.outputJson?.decision, "block");
5693
+ const mixedReason = String(blockedMixedPatch.outputJson?.reason ?? "");
5694
+ assert.match(mixedReason, /apply_patch target/);
5695
+ assert.match(mixedReason, /src\/leak\.ts/);
5696
+ const blockedUnparseablePatch = await preToolUse("apply_patch", "tool-ralplan-patch-unparseable", {
5697
+ input: "not a recognizable patch",
5698
+ });
5699
+ assert.equal(blockedUnparseablePatch.outputJson?.decision, "block");
5700
+ assert.match(String(blockedUnparseablePatch.outputJson?.reason ?? ""), /apply_patch target extraction failed/);
5701
+ const blockedUnresolvedRedirect = await preToolUse("Bash", "tool-ralplan-redirect-unresolved", {
5702
+ command: "cat > \"$PLAN_PATH\" <<'EOF'\ncontent\nEOF",
5703
+ });
5704
+ assert.equal(blockedUnresolvedRedirect.outputJson?.decision, "block");
5705
+ const unresolvedReason = String(blockedUnresolvedRedirect.outputJson?.reason ?? "");
5706
+ assert.match(unresolvedReason, /unresolved Bash write target/);
5707
+ assert.match(unresolvedReason, /\$PLAN_PATH/);
5708
+ const blockedTraversal = await preToolUse("Write", "tool-ralplan-traversal-block", {
5709
+ file_path: ".omx/plans/../../src/leak.ts",
5710
+ content: "bad",
5711
+ });
5712
+ assert.equal(blockedTraversal.outputJson?.decision, "block");
5713
+ assert.match(String(blockedTraversal.outputJson?.reason ?? ""), /\.omx\/plans\/\.\.\/\.\.\/src\/leak\.ts/);
5714
+ const blockedAbsolute = await preToolUse("Write", "tool-ralplan-absolute-block", {
5715
+ file_path: "/tmp/leak.ts",
5716
+ content: "bad",
5717
+ });
5718
+ assert.equal(blockedAbsolute.outputJson?.decision, "block");
5719
+ assert.match(String(blockedAbsolute.outputJson?.reason ?? ""), /\/tmp\/leak\.ts/);
5720
+ }
5721
+ finally {
5722
+ await rm(cwd, { recursive: true, force: true });
5723
+ }
5724
+ });
5282
5725
  it("allows Autopilot ralplan planning artifacts while blocking implementation writes", async () => {
5283
5726
  const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-pretool-autopilot-ralplan-artifact-"));
5284
5727
  try {
@@ -5347,6 +5790,225 @@ exit 0
5347
5790
  await rm(cwd, { recursive: true, force: true });
5348
5791
  }
5349
5792
  });
5793
+ it("allows Ralplan Beads tracker metadata writes during planning", async () => {
5794
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-pretool-ralplan-beads-"));
5795
+ try {
5796
+ const stateDir = join(cwd, ".omx", "state");
5797
+ const sessionDir = join(stateDir, "sessions", "sess-ralplan-beads");
5798
+ await mkdir(sessionDir, { recursive: true });
5799
+ await writeJson(join(stateDir, "session.json"), { session_id: "sess-ralplan-beads", cwd });
5800
+ await writeJson(join(sessionDir, "skill-active-state.json"), {
5801
+ version: 1,
5802
+ active: true,
5803
+ skill: "ralplan",
5804
+ phase: "planning",
5805
+ session_id: "sess-ralplan-beads",
5806
+ thread_id: "thread-ralplan-beads",
5807
+ active_skills: [
5808
+ {
5809
+ skill: "ralplan",
5810
+ phase: "planning",
5811
+ active: true,
5812
+ session_id: "sess-ralplan-beads",
5813
+ thread_id: "thread-ralplan-beads",
5814
+ },
5815
+ ],
5816
+ });
5817
+ await writeJson(join(sessionDir, "ralplan-state.json"), {
5818
+ active: true,
5819
+ mode: "ralplan",
5820
+ current_phase: "planning",
5821
+ session_id: "sess-ralplan-beads",
5822
+ thread_id: "thread-ralplan-beads",
5823
+ });
5824
+ const allowedWrite = await dispatchCodexNativeHook({
5825
+ hook_event_name: "PreToolUse",
5826
+ cwd,
5827
+ session_id: "sess-ralplan-beads",
5828
+ thread_id: "thread-ralplan-beads",
5829
+ tool_name: "Write",
5830
+ tool_use_id: "tool-ralplan-beads-write",
5831
+ tool_input: { file_path: ".beads/issues.db", content: "metadata" },
5832
+ }, { cwd });
5833
+ assert.equal(allowedWrite.outputJson, null);
5834
+ const allowedEdit = await dispatchCodexNativeHook({
5835
+ hook_event_name: "PreToolUse",
5836
+ cwd,
5837
+ session_id: "sess-ralplan-beads",
5838
+ thread_id: "thread-ralplan-beads",
5839
+ tool_name: "Edit",
5840
+ tool_use_id: "tool-ralplan-beads-edit",
5841
+ tool_input: { file_path: ".beads/tasks/issue.json", old_string: "old", new_string: "new" },
5842
+ }, { cwd });
5843
+ assert.equal(allowedEdit.outputJson, null);
5844
+ const allowedPatch = await dispatchCodexNativeHook({
5845
+ hook_event_name: "PreToolUse",
5846
+ cwd,
5847
+ session_id: "sess-ralplan-beads",
5848
+ thread_id: "thread-ralplan-beads",
5849
+ tool_name: "apply_patch",
5850
+ tool_use_id: "tool-ralplan-beads-apply-patch",
5851
+ tool_input: {
5852
+ input: "*** Begin Patch\n*** Add File: .beads/tasks/issue.json\n+{}\n*** End Patch\n",
5853
+ },
5854
+ }, { cwd });
5855
+ assert.equal(allowedPatch.outputJson, null);
5856
+ const allowedCommands = [
5857
+ "bd --db .beads/issues.db create 'Issue title'",
5858
+ "bd --db .beads/issues.db update OMX-1 --title 'Issue title'",
5859
+ "bd --db .beads/issues.db edit OMX-1 --title 'Issue title'",
5860
+ "bd --db .beads/issues.db comments add OMX-1 'evidence'",
5861
+ "bd --db .beads/issues.db close OMX-1",
5862
+ "bd --db .beads/issues.db reopen OMX-1",
5863
+ "bd --db .beads/issues.db status OMX-1",
5864
+ "bd --db .beads/issues.db dep add OMX-1 OMX-2",
5865
+ ];
5866
+ for (const [index, command] of allowedCommands.entries()) {
5867
+ const result = await dispatchCodexNativeHook({
5868
+ hook_event_name: "PreToolUse",
5869
+ cwd,
5870
+ session_id: "sess-ralplan-beads",
5871
+ thread_id: "thread-ralplan-beads",
5872
+ tool_name: "Bash",
5873
+ tool_use_id: `tool-ralplan-beads-bd-${index}`,
5874
+ tool_input: { command },
5875
+ }, { cwd });
5876
+ assert.equal(result.outputJson, null, `expected Beads metadata command to be allowed: ${command}`);
5877
+ }
5878
+ }
5879
+ finally {
5880
+ await rm(cwd, { recursive: true, force: true });
5881
+ }
5882
+ });
5883
+ it("blocks unsafe Beads tracker targets and mixed implementation writes during Autopilot ralplan planning", async () => {
5884
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-pretool-autopilot-beads-block-"));
5885
+ try {
5886
+ const stateDir = join(cwd, ".omx", "state");
5887
+ const sessionDir = join(stateDir, "sessions", "sess-autopilot-beads-block");
5888
+ await mkdir(sessionDir, { recursive: true });
5889
+ await writeJson(join(stateDir, "session.json"), { session_id: "sess-autopilot-beads-block", cwd });
5890
+ await writeJson(join(sessionDir, "skill-active-state.json"), {
5891
+ version: 1,
5892
+ active: true,
5893
+ skill: "autopilot",
5894
+ phase: "ralplan",
5895
+ session_id: "sess-autopilot-beads-block",
5896
+ thread_id: "thread-autopilot-beads-block",
5897
+ active_skills: [
5898
+ {
5899
+ skill: "autopilot",
5900
+ phase: "ralplan",
5901
+ active: true,
5902
+ session_id: "sess-autopilot-beads-block",
5903
+ thread_id: "thread-autopilot-beads-block",
5904
+ },
5905
+ ],
5906
+ });
5907
+ await writeJson(join(sessionDir, "autopilot-state.json"), {
5908
+ active: true,
5909
+ mode: "autopilot",
5910
+ current_phase: "ralplan",
5911
+ session_id: "sess-autopilot-beads-block",
5912
+ thread_id: "thread-autopilot-beads-block",
5913
+ });
5914
+ const blockedCommands = [
5915
+ "bd --db /tmp/outside.db create 'Issue title'",
5916
+ "bd --db ../outside.db create 'Issue title'",
5917
+ "bd --db .beads create 'Issue title'",
5918
+ "bd --db $DB create 'Issue title'",
5919
+ "DB=.beads/issues.db bd --db $DB create 'Issue title'",
5920
+ "env bd --db /tmp/outside.db create 'Issue title'",
5921
+ "command bd --db /tmp/outside.db create 'Issue title'",
5922
+ "bd --db .beads/issues.db export",
5923
+ "bd --db .beads/issues.db create 'Issue title' > src/leak.ts",
5924
+ "bd --db .beads/issues.db create 'Issue title'; cat > src/leak.ts",
5925
+ ];
5926
+ for (const [index, command] of blockedCommands.entries()) {
5927
+ const result = await dispatchCodexNativeHook({
5928
+ hook_event_name: "PreToolUse",
5929
+ cwd,
5930
+ session_id: "sess-autopilot-beads-block",
5931
+ thread_id: "thread-autopilot-beads-block",
5932
+ tool_name: "Bash",
5933
+ tool_use_id: `tool-autopilot-beads-block-${index}`,
5934
+ tool_input: { command },
5935
+ }, { cwd });
5936
+ assert.equal(result.outputJson?.decision, "block", `expected unsafe Beads command to be blocked: ${command}`);
5937
+ }
5938
+ const mentionWithImplementationWrite = await dispatchCodexNativeHook({
5939
+ hook_event_name: "PreToolUse",
5940
+ cwd,
5941
+ session_id: "sess-autopilot-beads-block",
5942
+ thread_id: "thread-autopilot-beads-block",
5943
+ tool_name: "Bash",
5944
+ tool_use_id: "tool-autopilot-beads-mention-write",
5945
+ tool_input: { command: "echo bd --db .beads/issues.db create > src/leak.ts" },
5946
+ }, { cwd });
5947
+ assert.equal(mentionWithImplementationWrite.outputJson?.decision, "block");
5948
+ assert.match(String(mentionWithImplementationWrite.outputJson?.reason ?? ""), /src\/leak\.ts/);
5949
+ const blockedImplementationEdit = await dispatchCodexNativeHook({
5950
+ hook_event_name: "PreToolUse",
5951
+ cwd,
5952
+ session_id: "sess-autopilot-beads-block",
5953
+ thread_id: "thread-autopilot-beads-block",
5954
+ tool_name: "Edit",
5955
+ tool_use_id: "tool-autopilot-beads-src-edit",
5956
+ tool_input: { file_path: "src/implementation.ts", old_string: "a", new_string: "b" },
5957
+ }, { cwd });
5958
+ assert.equal(blockedImplementationEdit.outputJson?.decision, "block");
5959
+ }
5960
+ finally {
5961
+ await rm(cwd, { recursive: true, force: true });
5962
+ }
5963
+ });
5964
+ it("allows Autopilot rework implementation writes while ralplan remains guarded", async () => {
5965
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-pretool-autopilot-rework-"));
5966
+ try {
5967
+ const stateDir = join(cwd, ".omx", "state");
5968
+ const sessionDir = join(stateDir, "sessions", "sess-autopilot-rework");
5969
+ await mkdir(sessionDir, { recursive: true });
5970
+ await writeJson(join(stateDir, "session.json"), { session_id: "sess-autopilot-rework", cwd });
5971
+ await writeJson(join(sessionDir, "skill-active-state.json"), {
5972
+ version: 1,
5973
+ active: true,
5974
+ skill: "autopilot",
5975
+ phase: "rework",
5976
+ session_id: "sess-autopilot-rework",
5977
+ thread_id: "thread-autopilot-rework",
5978
+ active_skills: [
5979
+ {
5980
+ skill: "autopilot",
5981
+ phase: "rework",
5982
+ active: true,
5983
+ session_id: "sess-autopilot-rework",
5984
+ thread_id: "thread-autopilot-rework",
5985
+ },
5986
+ ],
5987
+ });
5988
+ await writeJson(join(sessionDir, "autopilot-state.json"), {
5989
+ active: true,
5990
+ mode: "autopilot",
5991
+ current_phase: "rework",
5992
+ review_cycle: 2,
5993
+ review_verdict: { clean: false, recommendation: "REQUEST_CHANGES", findings: ["src/implementation.ts"] },
5994
+ session_id: "sess-autopilot-rework",
5995
+ thread_id: "thread-autopilot-rework",
5996
+ });
5997
+ const allowedImplementationEdit = await dispatchCodexNativeHook({
5998
+ hook_event_name: "PreToolUse",
5999
+ cwd,
6000
+ session_id: "sess-autopilot-rework",
6001
+ thread_id: "thread-autopilot-rework",
6002
+ tool_name: "Edit",
6003
+ tool_use_id: "tool-autopilot-rework-src-edit",
6004
+ tool_input: { file_path: "src/implementation.ts", old_string: "a", new_string: "b" },
6005
+ }, { cwd });
6006
+ assert.equal(allowedImplementationEdit.outputJson, null);
6007
+ }
6008
+ finally {
6009
+ await rm(cwd, { recursive: true, force: true });
6010
+ }
6011
+ });
5350
6012
  it("allows null-device fd redirects while deep-interview blocks real Bash writes", async () => {
5351
6013
  const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-pretool-deep-interview-null-redirect-"));
5352
6014
  try {
@@ -5488,6 +6150,173 @@ exit 0
5488
6150
  await rm(cwd, { recursive: true, force: true });
5489
6151
  }
5490
6152
  });
6153
+ it("records native subagent capacity exhaustion from spawn_agent PostToolUse output", async () => {
6154
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-subagent-capacity-record-"));
6155
+ try {
6156
+ const result = await dispatchCodexNativeHook({
6157
+ hook_event_name: "PostToolUse",
6158
+ cwd,
6159
+ session_id: "sess-subagent-capacity-record",
6160
+ thread_id: "thread-subagent-capacity-record",
6161
+ turn_id: "turn-subagent-capacity-record",
6162
+ tool_name: "multi_agent_v1.spawn_agent",
6163
+ tool_response: {
6164
+ error: "collab spawn failed: agent thread limit reached",
6165
+ },
6166
+ }, { cwd });
6167
+ assert.equal(result.omxEventName, "post-tool-use");
6168
+ assert.equal(result.outputJson, null);
6169
+ const blocker = JSON.parse(await readFile(join(cwd, ".omx", "state", "native-subagent-capacity-blocker.json"), "utf-8"));
6170
+ assert.equal(blocker.reason, "agent_thread_limit_reached");
6171
+ assert.equal(blocker.session_id, "sess-subagent-capacity-record");
6172
+ assert.equal(blocker.thread_id, "thread-subagent-capacity-record");
6173
+ assert.equal(blocker.tool_name, "multi_agent_v1.spawn_agent");
6174
+ assert.match(String(blocker.error_summary), /agent thread limit reached/);
6175
+ assert.ok(Date.parse(String(blocker.expires_at)) > Date.parse(String(blocker.observed_at)));
6176
+ }
6177
+ finally {
6178
+ await rm(cwd, { recursive: true, force: true });
6179
+ }
6180
+ });
6181
+ it("blocks close_agent cleanup after recent native subagent capacity exhaustion", async () => {
6182
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-subagent-capacity-close-block-"));
6183
+ try {
6184
+ await dispatchCodexNativeHook({
6185
+ hook_event_name: "PostToolUse",
6186
+ cwd,
6187
+ session_id: "sess-subagent-capacity-close-block",
6188
+ thread_id: "thread-subagent-capacity-close-block",
6189
+ turn_id: "turn-subagent-capacity-close-block",
6190
+ tool_name: "multi_agent_v1.spawn_agent",
6191
+ tool_response: "collab spawn failed: agent thread limit reached",
6192
+ }, { cwd });
6193
+ const result = await dispatchCodexNativeHook({
6194
+ hook_event_name: "PreToolUse",
6195
+ cwd,
6196
+ session_id: "sess-subagent-capacity-close-block",
6197
+ thread_id: "thread-subagent-capacity-close-block",
6198
+ tool_name: "multi_agent_v1.close_agent",
6199
+ tool_input: { target: "019ecc36-stale" },
6200
+ }, { cwd });
6201
+ assert.equal(result.omxEventName, "pre-tool-use");
6202
+ assert.equal(result.outputJson?.decision, "block");
6203
+ assert.match(JSON.stringify(result.outputJson), /agent thread limit reached/);
6204
+ assert.match(JSON.stringify(result.outputJson), /multi_agent_v1\.close_agent/);
6205
+ assert.match(JSON.stringify(result.outputJson), /multi_tool_use\.parallel/);
6206
+ assert.match(JSON.stringify(result.outputJson), /bounded capacity blocker/);
6207
+ }
6208
+ finally {
6209
+ await rm(cwd, { recursive: true, force: true });
6210
+ }
6211
+ });
6212
+ it("emits schema-safe PreToolUse CLI stdout for close_agent capacity blocks", async () => {
6213
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-cli-subagent-capacity-close-block-"));
6214
+ try {
6215
+ parseSingleJsonStdout(runNativeHookCli({
6216
+ hook_event_name: "PostToolUse",
6217
+ cwd,
6218
+ session_id: "sess-cli-subagent-capacity-close-block",
6219
+ thread_id: "thread-cli-subagent-capacity-close-block",
6220
+ turn_id: "turn-cli-subagent-capacity-close-block",
6221
+ tool_name: "multi_agent_v1.spawn_agent",
6222
+ tool_response: "collab spawn failed: agent thread limit reached",
6223
+ }, { cwd }));
6224
+ const output = parseSingleJsonStdout(runNativeHookCli({
6225
+ hook_event_name: "PreToolUse",
6226
+ cwd,
6227
+ session_id: "sess-cli-subagent-capacity-close-block",
6228
+ thread_id: "thread-cli-subagent-capacity-close-block",
6229
+ tool_name: "multi_agent_v1.close_agent",
6230
+ tool_input: { target: "019ecc36-stale" },
6231
+ }, { cwd }));
6232
+ assert.deepEqual(Object.keys(output).sort(), ["systemMessage"]);
6233
+ assert.match(String(output.systemMessage ?? ""), /agent thread limit reached/);
6234
+ assert.match(String(output.systemMessage ?? ""), /Do not call multi_agent_v1\.close_agent/);
6235
+ assert.equal(output.decision, undefined);
6236
+ assert.equal(output.hookSpecificOutput, undefined);
6237
+ }
6238
+ finally {
6239
+ await rm(cwd, { recursive: true, force: true });
6240
+ }
6241
+ });
6242
+ it("blocks parallel close_agent cleanup after recent native subagent capacity exhaustion", async () => {
6243
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-subagent-capacity-parallel-close-block-"));
6244
+ try {
6245
+ await dispatchCodexNativeHook({
6246
+ hook_event_name: "PostToolUse",
6247
+ cwd,
6248
+ session_id: "sess-subagent-capacity-parallel-close-block",
6249
+ thread_id: "thread-subagent-capacity-parallel-close-block",
6250
+ tool_name: "multi_agent_v1.spawn_agent",
6251
+ tool_response: "agent thread limit reached",
6252
+ }, { cwd });
6253
+ const result = await dispatchCodexNativeHook({
6254
+ hook_event_name: "PreToolUse",
6255
+ cwd,
6256
+ session_id: "sess-subagent-capacity-parallel-close-block",
6257
+ thread_id: "thread-subagent-capacity-parallel-close-block",
6258
+ tool_name: "multi_tool_use.parallel",
6259
+ tool_input: {
6260
+ tool_uses: [
6261
+ { recipient_name: "multi_agent_v1.close_agent", parameters: { target: "stale-1" } },
6262
+ { recipient_name: "multi_agent_v1.close_agent", parameters: { target: "stale-2" } },
6263
+ ],
6264
+ },
6265
+ }, { cwd });
6266
+ assert.equal(result.outputJson?.decision, "block");
6267
+ assert.match(JSON.stringify(result.outputJson), /Do not call multi_agent_v1\.close_agent/);
6268
+ assert.match(JSON.stringify(result.outputJson), /do not batch close_agent through multi_tool_use\.parallel/);
6269
+ }
6270
+ finally {
6271
+ await rm(cwd, { recursive: true, force: true });
6272
+ }
6273
+ });
6274
+ it("does not block close_agent without a recent native capacity blocker", async () => {
6275
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-subagent-capacity-close-no-blocker-"));
6276
+ try {
6277
+ const result = await dispatchCodexNativeHook({
6278
+ hook_event_name: "PreToolUse",
6279
+ cwd,
6280
+ session_id: "sess-subagent-capacity-close-no-blocker",
6281
+ thread_id: "thread-subagent-capacity-close-no-blocker",
6282
+ tool_name: "multi_agent_v1.close_agent",
6283
+ tool_input: { target: "completed-agent" },
6284
+ }, { cwd });
6285
+ assert.equal(result.omxEventName, "pre-tool-use");
6286
+ assert.equal(result.outputJson, null);
6287
+ }
6288
+ finally {
6289
+ await rm(cwd, { recursive: true, force: true });
6290
+ }
6291
+ });
6292
+ it("does not block close_agent when the native capacity blocker is expired", async () => {
6293
+ const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-subagent-capacity-close-expired-"));
6294
+ try {
6295
+ const stateDir = join(cwd, ".omx", "state");
6296
+ await mkdir(stateDir, { recursive: true });
6297
+ await writeJson(join(stateDir, "native-subagent-capacity-blocker.json"), {
6298
+ schema_version: 1,
6299
+ reason: "agent_thread_limit_reached",
6300
+ session_id: "sess-subagent-capacity-close-expired",
6301
+ error_summary: "agent thread limit reached",
6302
+ observed_at: "2026-06-20T00:00:00.000Z",
6303
+ expires_at: "2026-06-20T00:30:00.000Z",
6304
+ cwd,
6305
+ });
6306
+ const result = await dispatchCodexNativeHook({
6307
+ hook_event_name: "PreToolUse",
6308
+ cwd,
6309
+ session_id: "sess-subagent-capacity-close-expired",
6310
+ thread_id: "thread-subagent-capacity-close-expired",
6311
+ tool_name: "multi_agent_v1.close_agent",
6312
+ tool_input: { target: "completed-agent" },
6313
+ }, { cwd });
6314
+ assert.equal(result.outputJson, null);
6315
+ }
6316
+ finally {
6317
+ await rm(cwd, { recursive: true, force: true });
6318
+ }
6319
+ });
5491
6320
  it("warns on PreToolUse for vague sloppy fallback implementation framing", async () => {
5492
6321
  const cwd = await mkdtemp(join(tmpdir(), "omx-native-hook-pretool-slop-warn-"));
5493
6322
  try {