oh-my-codex 0.20.0 → 0.20.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 (661) hide show
  1. package/Cargo.lock +6 -6
  2. package/Cargo.toml +1 -1
  3. package/README.md +10 -1
  4. package/dist/adapt/__tests__/hermes.test.js.map +1 -1
  5. package/dist/adapt/contracts.d.ts.map +1 -1
  6. package/dist/agents/native-config.js.map +1 -1
  7. package/dist/auth/__tests__/hotswap.test.d.ts +2 -0
  8. package/dist/auth/__tests__/hotswap.test.d.ts.map +1 -0
  9. package/dist/auth/__tests__/hotswap.test.js +183 -0
  10. package/dist/auth/__tests__/hotswap.test.js.map +1 -0
  11. package/dist/auth/hotswap.d.ts.map +1 -1
  12. package/dist/auth/hotswap.js +17 -4
  13. package/dist/auth/hotswap.js.map +1 -1
  14. package/dist/auth/paths.js.map +1 -1
  15. package/dist/auth/storage.js.map +1 -1
  16. package/dist/autopilot/__tests__/ralplan-gate.test.js +4 -4
  17. package/dist/autopilot/__tests__/ralplan-gate.test.js.map +1 -1
  18. package/dist/autopilot/completion-gate.js.map +1 -1
  19. package/dist/autopilot/fsm.d.ts +1 -1
  20. package/dist/autopilot/fsm.d.ts.map +1 -1
  21. package/dist/autoresearch/goal.js.map +1 -1
  22. package/dist/autoresearch/runtime.js.map +1 -1
  23. package/dist/capabilities/lockfile.js.map +1 -1
  24. package/dist/catalog/reader.js.map +1 -1
  25. package/dist/catalog/skill-mirror.js.map +1 -1
  26. package/dist/cli/__tests__/adapt-help.test.js.map +1 -1
  27. package/dist/cli/__tests__/agents-init.test.js.map +1 -1
  28. package/dist/cli/__tests__/agents.test.js.map +1 -1
  29. package/dist/cli/__tests__/api.test.js.map +1 -1
  30. package/dist/cli/__tests__/ask.test.js.map +1 -1
  31. package/dist/cli/__tests__/auth.test.js.map +1 -1
  32. package/dist/cli/__tests__/autoresearch-guided.test.js.map +1 -1
  33. package/dist/cli/__tests__/autoresearch.test.js.map +1 -1
  34. package/dist/cli/__tests__/capabilities.test.js.map +1 -1
  35. package/dist/cli/__tests__/codex-plugin-layout.test.js +27 -0
  36. package/dist/cli/__tests__/codex-plugin-layout.test.js.map +1 -1
  37. package/dist/cli/__tests__/doctor-context-window-warning.test.js +83 -78
  38. package/dist/cli/__tests__/doctor-context-window-warning.test.js.map +1 -1
  39. package/dist/cli/__tests__/doctor-invalid-config.test.js +56 -4
  40. package/dist/cli/__tests__/doctor-invalid-config.test.js.map +1 -1
  41. package/dist/cli/__tests__/doctor-team.test.js.map +1 -1
  42. package/dist/cli/__tests__/doctor-warning-copy.test.js +735 -14
  43. package/dist/cli/__tests__/doctor-warning-copy.test.js.map +1 -1
  44. package/dist/cli/__tests__/exec.test.js.map +1 -1
  45. package/dist/cli/__tests__/imagegen-continuation.test.js.map +1 -1
  46. package/dist/cli/__tests__/index.test.js +216 -11
  47. package/dist/cli/__tests__/index.test.js.map +1 -1
  48. package/dist/cli/__tests__/launch-fallback.test.js +49 -3
  49. package/dist/cli/__tests__/launch-fallback.test.js.map +1 -1
  50. package/dist/cli/__tests__/mcp-parity.test.js +84 -12
  51. package/dist/cli/__tests__/mcp-parity.test.js.map +1 -1
  52. package/dist/cli/__tests__/native-hook-claim-journal.test.d.ts +2 -0
  53. package/dist/cli/__tests__/native-hook-claim-journal.test.d.ts.map +1 -0
  54. package/dist/cli/__tests__/native-hook-claim-journal.test.js +128 -0
  55. package/dist/cli/__tests__/native-hook-claim-journal.test.js.map +1 -0
  56. package/dist/cli/__tests__/nested-help-routing.test.js.map +1 -1
  57. package/dist/cli/__tests__/question.test.js.map +1 -1
  58. package/dist/cli/__tests__/ralph-deslop-contract.test.js.map +1 -1
  59. package/dist/cli/__tests__/ralph-goal-mode-contract.test.js +6 -0
  60. package/dist/cli/__tests__/ralph-goal-mode-contract.test.js.map +1 -1
  61. package/dist/cli/__tests__/ralph-prd-deep-interview.test.js.map +1 -1
  62. package/dist/cli/__tests__/ralph-prd-smoke.test.js.map +1 -1
  63. package/dist/cli/__tests__/ralph.test.js +8 -3
  64. package/dist/cli/__tests__/ralph.test.js.map +1 -1
  65. package/dist/cli/__tests__/ralplan-bootstrap-3181.test.d.ts +2 -0
  66. package/dist/cli/__tests__/ralplan-bootstrap-3181.test.d.ts.map +1 -0
  67. package/dist/cli/__tests__/ralplan-bootstrap-3181.test.js +187 -0
  68. package/dist/cli/__tests__/ralplan-bootstrap-3181.test.js.map +1 -0
  69. package/dist/cli/__tests__/ralplan.test.d.ts +2 -0
  70. package/dist/cli/__tests__/ralplan.test.d.ts.map +1 -0
  71. package/dist/cli/__tests__/ralplan.test.js +129 -0
  72. package/dist/cli/__tests__/ralplan.test.js.map +1 -0
  73. package/dist/cli/__tests__/resume.test.js +6 -1
  74. package/dist/cli/__tests__/resume.test.js.map +1 -1
  75. package/dist/cli/__tests__/session-scoped-runtime.test.js +25 -0
  76. package/dist/cli/__tests__/session-scoped-runtime.test.js.map +1 -1
  77. package/dist/cli/__tests__/session-search-help.test.js.map +1 -1
  78. package/dist/cli/__tests__/session-search.test.js.map +1 -1
  79. package/dist/cli/__tests__/setup-agents-overwrite.test.js +79 -0
  80. package/dist/cli/__tests__/setup-agents-overwrite.test.js.map +1 -1
  81. package/dist/cli/__tests__/setup-gh-star.test.js.map +1 -1
  82. package/dist/cli/__tests__/setup-hooks-shared-ownership.test.js +131 -5
  83. package/dist/cli/__tests__/setup-hooks-shared-ownership.test.js.map +1 -1
  84. package/dist/cli/__tests__/setup-hooks-trust-e2e.test.d.ts +2 -0
  85. package/dist/cli/__tests__/setup-hooks-trust-e2e.test.d.ts.map +1 -0
  86. package/dist/cli/__tests__/setup-hooks-trust-e2e.test.js +285 -0
  87. package/dist/cli/__tests__/setup-hooks-trust-e2e.test.js.map +1 -0
  88. package/dist/cli/__tests__/setup-install-mode.test.js +2264 -17
  89. package/dist/cli/__tests__/setup-install-mode.test.js.map +1 -1
  90. package/dist/cli/__tests__/setup-preferences.test.d.ts +2 -0
  91. package/dist/cli/__tests__/setup-preferences.test.d.ts.map +1 -0
  92. package/dist/cli/__tests__/setup-preferences.test.js +79 -0
  93. package/dist/cli/__tests__/setup-preferences.test.js.map +1 -0
  94. package/dist/cli/__tests__/setup-refresh.test.js +168 -5
  95. package/dist/cli/__tests__/setup-refresh.test.js.map +1 -1
  96. package/dist/cli/__tests__/setup-scope.test.js +73 -6
  97. package/dist/cli/__tests__/setup-scope.test.js.map +1 -1
  98. package/dist/cli/__tests__/sparkshell-cli.test.js.map +1 -1
  99. package/dist/cli/__tests__/state.test.js +37 -0
  100. package/dist/cli/__tests__/state.test.js.map +1 -1
  101. package/dist/cli/__tests__/team.test.js.map +1 -1
  102. package/dist/cli/__tests__/ultragoal.test.js +61 -1
  103. package/dist/cli/__tests__/ultragoal.test.js.map +1 -1
  104. package/dist/cli/__tests__/uninstall.test.js +2067 -26
  105. package/dist/cli/__tests__/uninstall.test.js.map +1 -1
  106. package/dist/cli/__tests__/update.test.js +58 -0
  107. package/dist/cli/__tests__/update.test.js.map +1 -1
  108. package/dist/cli/__tests__/url.test.js.map +1 -1
  109. package/dist/cli/__tests__/windows-popup-loop-contract.test.js.map +1 -1
  110. package/dist/cli/adapt.js.map +1 -1
  111. package/dist/cli/agents-init.js.map +1 -1
  112. package/dist/cli/agents.js.map +1 -1
  113. package/dist/cli/api.js.map +1 -1
  114. package/dist/cli/ask.d.ts +1 -1
  115. package/dist/cli/ask.d.ts.map +1 -1
  116. package/dist/cli/ask.js.map +1 -1
  117. package/dist/cli/auth.js.map +1 -1
  118. package/dist/cli/autoresearch-guided.js.map +1 -1
  119. package/dist/cli/autoresearch-intake.js.map +1 -1
  120. package/dist/cli/capabilities.js.map +1 -1
  121. package/dist/cli/cleanup.js.map +1 -1
  122. package/dist/cli/codex-feature-probe.js.map +1 -1
  123. package/dist/cli/codex-home.js.map +1 -1
  124. package/dist/cli/doctor.d.ts +20 -0
  125. package/dist/cli/doctor.d.ts.map +1 -1
  126. package/dist/cli/doctor.js +636 -161
  127. package/dist/cli/doctor.js.map +1 -1
  128. package/dist/cli/explore.js.map +1 -1
  129. package/dist/cli/index.d.ts +11 -3
  130. package/dist/cli/index.d.ts.map +1 -1
  131. package/dist/cli/index.js +108 -20
  132. package/dist/cli/index.js.map +1 -1
  133. package/dist/cli/mcp-serve.js.map +1 -1
  134. package/dist/cli/mission.js.map +1 -1
  135. package/dist/cli/native-assets.js.map +1 -1
  136. package/dist/cli/native-hook-claim-journal.d.ts +18 -0
  137. package/dist/cli/native-hook-claim-journal.d.ts.map +1 -0
  138. package/dist/cli/native-hook-claim-journal.js +239 -0
  139. package/dist/cli/native-hook-claim-journal.js.map +1 -0
  140. package/dist/cli/omx.js.map +1 -1
  141. package/dist/cli/plugin-marketplace.js.map +1 -1
  142. package/dist/cli/project-runtime-codex-homes.js.map +1 -1
  143. package/dist/cli/question.js.map +1 -1
  144. package/dist/cli/ralph.d.ts.map +1 -1
  145. package/dist/cli/ralph.js +3 -2
  146. package/dist/cli/ralph.js.map +1 -1
  147. package/dist/cli/ralplan.d.ts +14 -0
  148. package/dist/cli/ralplan.d.ts.map +1 -0
  149. package/dist/cli/ralplan.js +203 -0
  150. package/dist/cli/ralplan.js.map +1 -0
  151. package/dist/cli/setup-preferences.d.ts +11 -0
  152. package/dist/cli/setup-preferences.d.ts.map +1 -1
  153. package/dist/cli/setup-preferences.js +32 -0
  154. package/dist/cli/setup-preferences.js.map +1 -1
  155. package/dist/cli/setup.d.ts +53 -0
  156. package/dist/cli/setup.d.ts.map +1 -1
  157. package/dist/cli/setup.js +1403 -400
  158. package/dist/cli/setup.js.map +1 -1
  159. package/dist/cli/sparkshell.js.map +1 -1
  160. package/dist/cli/star-prompt.js.map +1 -1
  161. package/dist/cli/state.d.ts.map +1 -1
  162. package/dist/cli/state.js +2 -1
  163. package/dist/cli/state.js.map +1 -1
  164. package/dist/cli/team.js.map +1 -1
  165. package/dist/cli/ultragoal.d.ts +5 -1
  166. package/dist/cli/ultragoal.d.ts.map +1 -1
  167. package/dist/cli/ultragoal.js +34 -2
  168. package/dist/cli/ultragoal.js.map +1 -1
  169. package/dist/cli/uninstall.d.ts +8 -0
  170. package/dist/cli/uninstall.d.ts.map +1 -1
  171. package/dist/cli/uninstall.js +947 -99
  172. package/dist/cli/uninstall.js.map +1 -1
  173. package/dist/cli/update.d.ts.map +1 -1
  174. package/dist/cli/update.js +8 -1
  175. package/dist/cli/update.js.map +1 -1
  176. package/dist/cli/url.js.map +1 -1
  177. package/dist/compat/__tests__/doctor-contract.test.js +5 -1
  178. package/dist/compat/__tests__/doctor-contract.test.js.map +1 -1
  179. package/dist/compat/__tests__/rust-runtime-compat.test.js.map +1 -1
  180. package/dist/config/__tests__/codex-hooks.test.js +1287 -11
  181. package/dist/config/__tests__/codex-hooks.test.js.map +1 -1
  182. package/dist/config/__tests__/generator-idempotent.test.js +1049 -135
  183. package/dist/config/__tests__/generator-idempotent.test.js.map +1 -1
  184. package/dist/config/__tests__/generator-notify.test.js +28 -49
  185. package/dist/config/__tests__/generator-notify.test.js.map +1 -1
  186. package/dist/config/codex-feature-flags.d.ts.map +1 -1
  187. package/dist/config/codex-feature-flags.js.map +1 -1
  188. package/dist/config/codex-hooks.d.ts +124 -1
  189. package/dist/config/codex-hooks.d.ts.map +1 -1
  190. package/dist/config/codex-hooks.js +2142 -265
  191. package/dist/config/codex-hooks.js.map +1 -1
  192. package/dist/config/commit-lore-guard.js.map +1 -1
  193. package/dist/config/generator.d.ts +40 -26
  194. package/dist/config/generator.d.ts.map +1 -1
  195. package/dist/config/generator.js +1159 -288
  196. package/dist/config/generator.js.map +1 -1
  197. package/dist/config/mcp-registry.js.map +1 -1
  198. package/dist/config/models.d.ts +2 -2
  199. package/dist/config/models.d.ts.map +1 -1
  200. package/dist/config/models.js.map +1 -1
  201. package/dist/config/omx-first-party-mcp.js.map +1 -1
  202. package/dist/config/team-mode.d.ts.map +1 -1
  203. package/dist/document-refresh/__tests__/enforcer.test.js.map +1 -1
  204. package/dist/document-refresh/enforcer.js.map +1 -1
  205. package/dist/exec/followup.js.map +1 -1
  206. package/dist/goal-workflows/artifacts.js.map +1 -1
  207. package/dist/hooks/__tests__/agents-overlay.test.js +7 -4
  208. package/dist/hooks/__tests__/agents-overlay.test.js.map +1 -1
  209. package/dist/hooks/__tests__/analyze-routing-contract.test.js.map +1 -1
  210. package/dist/hooks/__tests__/analyze-skill-contract.test.js.map +1 -1
  211. package/dist/hooks/__tests__/anti-slop-workflow.test.js.map +1 -1
  212. package/dist/hooks/__tests__/autopilot-skill-contract.test.js +9 -3
  213. package/dist/hooks/__tests__/autopilot-skill-contract.test.js.map +1 -1
  214. package/dist/hooks/__tests__/code-review-skill-contract.test.js.map +1 -1
  215. package/dist/hooks/__tests__/consensus-execution-handoff.test.js.map +1 -1
  216. package/dist/hooks/__tests__/deep-interview-contract.test.js.map +1 -1
  217. package/dist/hooks/__tests__/design-skill.test.js.map +1 -1
  218. package/dist/hooks/__tests__/keyword-detector.test.js +1372 -2
  219. package/dist/hooks/__tests__/keyword-detector.test.js.map +1 -1
  220. package/dist/hooks/__tests__/notify-fallback-watcher.test.js +14 -0
  221. package/dist/hooks/__tests__/notify-fallback-watcher.test.js.map +1 -1
  222. package/dist/hooks/__tests__/notify-hook-all-workers-idle.test.js.map +1 -1
  223. package/dist/hooks/__tests__/notify-hook-auto-nudge.test.js +669 -1
  224. package/dist/hooks/__tests__/notify-hook-auto-nudge.test.js.map +1 -1
  225. package/dist/hooks/__tests__/notify-hook-cross-worktree-heartbeat.test.js +2 -0
  226. package/dist/hooks/__tests__/notify-hook-cross-worktree-heartbeat.test.js.map +1 -1
  227. package/dist/hooks/__tests__/notify-hook-managed-tmux.test.js +142 -1
  228. package/dist/hooks/__tests__/notify-hook-managed-tmux.test.js.map +1 -1
  229. package/dist/hooks/__tests__/notify-hook-modules.test.js.map +1 -1
  230. package/dist/hooks/__tests__/notify-hook-non-omx-guard.test.js +48 -2
  231. package/dist/hooks/__tests__/notify-hook-non-omx-guard.test.js.map +1 -1
  232. package/dist/hooks/__tests__/notify-hook-ralph-resume.test.js +61 -44
  233. package/dist/hooks/__tests__/notify-hook-ralph-resume.test.js.map +1 -1
  234. package/dist/hooks/__tests__/notify-hook-regression-205.test.js.map +1 -1
  235. package/dist/hooks/__tests__/notify-hook-session-idle-dedupe.test.js +3 -2
  236. package/dist/hooks/__tests__/notify-hook-session-idle-dedupe.test.js.map +1 -1
  237. package/dist/hooks/__tests__/notify-hook-session-scope.test.js +243 -4
  238. package/dist/hooks/__tests__/notify-hook-session-scope.test.js.map +1 -1
  239. package/dist/hooks/__tests__/notify-hook-team-dispatch.test.js.map +1 -1
  240. package/dist/hooks/__tests__/notify-hook-team-leader-nudge.test.js +8 -1
  241. package/dist/hooks/__tests__/notify-hook-team-leader-nudge.test.js.map +1 -1
  242. package/dist/hooks/__tests__/notify-hook-team-tmux-guard.test.js.map +1 -1
  243. package/dist/hooks/__tests__/notify-hook-tmux-heal.test.js.map +1 -1
  244. package/dist/hooks/__tests__/notify-hook-tmux-scrollback.test.js.map +1 -1
  245. package/dist/hooks/__tests__/notify-hook-visual-verdict.test.js.map +1 -1
  246. package/dist/hooks/__tests__/notify-hook-worker-idle.test.js.map +1 -1
  247. package/dist/hooks/__tests__/openclaw-setup-contract.test.js.map +1 -1
  248. package/dist/hooks/__tests__/pre-context-gate-skills.test.js.map +1 -1
  249. package/dist/hooks/__tests__/prometheus-strict-contract.test.js.map +1 -1
  250. package/dist/hooks/__tests__/prompt-guidance-fragments.test.js.map +1 -1
  251. package/dist/hooks/__tests__/prompt-guidance-test-helpers.js.map +1 -1
  252. package/dist/hooks/__tests__/prompt-session-provenance.test.d.ts +2 -0
  253. package/dist/hooks/__tests__/prompt-session-provenance.test.d.ts.map +1 -0
  254. package/dist/hooks/__tests__/prompt-session-provenance.test.js +82 -0
  255. package/dist/hooks/__tests__/prompt-session-provenance.test.js.map +1 -0
  256. package/dist/hooks/__tests__/session.test.js +532 -11
  257. package/dist/hooks/__tests__/session.test.js.map +1 -1
  258. package/dist/hooks/__tests__/skill-catalog-hygiene.test.js.map +1 -1
  259. package/dist/hooks/__tests__/team-runtime-gating-docs-contract.test.js.map +1 -1
  260. package/dist/hooks/__tests__/visual-ralph-skill.test.js.map +1 -1
  261. package/dist/hooks/__tests__/visual-verdict-loop.test.js.map +1 -1
  262. package/dist/hooks/agents-overlay.js +5 -5
  263. package/dist/hooks/agents-overlay.js.map +1 -1
  264. package/dist/hooks/code-simplifier/index.js.map +1 -1
  265. package/dist/hooks/explore-routing.js.map +1 -1
  266. package/dist/hooks/extensibility/dispatcher.js.map +1 -1
  267. package/dist/hooks/extensibility/events.js.map +1 -1
  268. package/dist/hooks/extensibility/loader.js.map +1 -1
  269. package/dist/hooks/extensibility/plugin-runner-stdin.js.map +1 -1
  270. package/dist/hooks/extensibility/sdk/logging.js.map +1 -1
  271. package/dist/hooks/keyword-detector.d.ts +33 -7
  272. package/dist/hooks/keyword-detector.d.ts.map +1 -1
  273. package/dist/hooks/keyword-detector.js +2228 -119
  274. package/dist/hooks/keyword-detector.js.map +1 -1
  275. package/dist/hooks/keyword-registry.d.ts +12 -0
  276. package/dist/hooks/keyword-registry.d.ts.map +1 -1
  277. package/dist/hooks/keyword-registry.js +41 -0
  278. package/dist/hooks/keyword-registry.js.map +1 -1
  279. package/dist/hooks/prompt-session-provenance.d.ts +87 -0
  280. package/dist/hooks/prompt-session-provenance.d.ts.map +1 -0
  281. package/dist/hooks/prompt-session-provenance.js +180 -0
  282. package/dist/hooks/prompt-session-provenance.js.map +1 -0
  283. package/dist/hooks/session.d.ts +139 -34
  284. package/dist/hooks/session.d.ts.map +1 -1
  285. package/dist/hooks/session.js +1239 -317
  286. package/dist/hooks/session.js.map +1 -1
  287. package/dist/hooks/task-size-detector.js.map +1 -1
  288. package/dist/hud/__tests__/state.test.js.map +1 -1
  289. package/dist/hud/authority.js.map +1 -1
  290. package/dist/hud/constants.js.map +1 -1
  291. package/dist/hud/index.js.map +1 -1
  292. package/dist/hud/reconcile.js.map +1 -1
  293. package/dist/hud/render.js.map +1 -1
  294. package/dist/hud/state.js.map +1 -1
  295. package/dist/hud/tmux.js.map +1 -1
  296. package/dist/leader/__tests__/contract.test.js +146 -2
  297. package/dist/leader/__tests__/contract.test.js.map +1 -1
  298. package/dist/leader/contract.d.ts +26 -5
  299. package/dist/leader/contract.d.ts.map +1 -1
  300. package/dist/leader/contract.js +131 -7
  301. package/dist/leader/contract.js.map +1 -1
  302. package/dist/mcp/__tests__/bootstrap.test.js.map +1 -1
  303. package/dist/mcp/__tests__/server-lifecycle.test.js +15 -2
  304. package/dist/mcp/__tests__/server-lifecycle.test.js.map +1 -1
  305. package/dist/mcp/__tests__/state-paths.test.js +98 -1
  306. package/dist/mcp/__tests__/state-paths.test.js.map +1 -1
  307. package/dist/mcp/bootstrap.js.map +1 -1
  308. package/dist/mcp/code-intel-server.d.ts +58 -58
  309. package/dist/mcp/code-intel-server.d.ts.map +1 -1
  310. package/dist/mcp/code-intel-server.js.map +1 -1
  311. package/dist/mcp/hermes-bridge.js.map +1 -1
  312. package/dist/mcp/hermes-server.d.ts +70 -70
  313. package/dist/mcp/hermes-server.d.ts.map +1 -1
  314. package/dist/mcp/lifecycle-telemetry.js.map +1 -1
  315. package/dist/mcp/memory-server.d.ts +34 -34
  316. package/dist/mcp/memory-server.d.ts.map +1 -1
  317. package/dist/mcp/memory-server.js.map +1 -1
  318. package/dist/mcp/state-paths.d.ts +14 -0
  319. package/dist/mcp/state-paths.d.ts.map +1 -1
  320. package/dist/mcp/state-paths.js +96 -20
  321. package/dist/mcp/state-paths.js.map +1 -1
  322. package/dist/mcp/state-server.d.ts +47 -47
  323. package/dist/mcp/state-server.d.ts.map +1 -1
  324. package/dist/mcp/trace-server.d.ts +4 -4
  325. package/dist/mcp/trace-server.d.ts.map +1 -1
  326. package/dist/mcp/trace-server.js.map +1 -1
  327. package/dist/mcp/wiki-server.d.ts +23 -23
  328. package/dist/mcp/wiki-server.d.ts.map +1 -1
  329. package/dist/mcp/wiki-server.js.map +1 -1
  330. package/dist/modes/__tests__/base-session-scope.test.js +53 -1
  331. package/dist/modes/__tests__/base-session-scope.test.js.map +1 -1
  332. package/dist/modes/base.d.ts.map +1 -1
  333. package/dist/modes/base.js +5 -5
  334. package/dist/modes/base.js.map +1 -1
  335. package/dist/notifications/__tests__/lifecycle-dedupe.test.js.map +1 -1
  336. package/dist/notifications/__tests__/reply-listener.test.js.map +1 -1
  337. package/dist/notifications/__tests__/session-idle-tail-dedupe.test.js +177 -85
  338. package/dist/notifications/__tests__/session-idle-tail-dedupe.test.js.map +1 -1
  339. package/dist/notifications/__tests__/session-registry.test.js.map +1 -1
  340. package/dist/notifications/__tests__/template-engine.test.js.map +1 -1
  341. package/dist/notifications/__tests__/verbosity.test.js.map +1 -1
  342. package/dist/notifications/http-client.js.map +1 -1
  343. package/dist/notifications/index.d.ts +4 -1
  344. package/dist/notifications/index.d.ts.map +1 -1
  345. package/dist/notifications/index.js +3 -9
  346. package/dist/notifications/index.js.map +1 -1
  347. package/dist/notifications/lifecycle-dedupe.js.map +1 -1
  348. package/dist/notifications/reply-listener.d.ts.map +1 -1
  349. package/dist/notifications/reply-listener.js.map +1 -1
  350. package/dist/notifications/session-registry.js.map +1 -1
  351. package/dist/notifications/session-status.js.map +1 -1
  352. package/dist/notifications/temp-contract.js.map +1 -1
  353. package/dist/notifications/tmux-detector.js.map +1 -1
  354. package/dist/notifications/tmux.js.map +1 -1
  355. package/dist/openclaw/config.js.map +1 -1
  356. package/dist/openclaw/dispatcher.js.map +1 -1
  357. package/dist/pipeline/__tests__/orchestrator.test.js.map +1 -1
  358. package/dist/pipeline/__tests__/stages.test.js +8 -5
  359. package/dist/pipeline/__tests__/stages.test.js.map +1 -1
  360. package/dist/pipeline/stages/code-review.js.map +1 -1
  361. package/dist/pipeline/stages/ralph-verify.js.map +1 -1
  362. package/dist/pipeline/stages/ralplan.js.map +1 -1
  363. package/dist/pipeline/stages/team-exec.js.map +1 -1
  364. package/dist/pipeline/stages/ultragoal.js.map +1 -1
  365. package/dist/pipeline/stages/ultraqa.js.map +1 -1
  366. package/dist/planning/__tests__/approved-execution-lifecycle-matrix.test.js.map +1 -1
  367. package/dist/planning/artifact-names.js.map +1 -1
  368. package/dist/planning/artifacts.js.map +1 -1
  369. package/dist/question/__tests__/state.test.js.map +1 -1
  370. package/dist/question/__tests__/ui.test.js.map +1 -1
  371. package/dist/question/autopilot-wait.js.map +1 -1
  372. package/dist/question/client.d.ts.map +1 -1
  373. package/dist/question/client.js.map +1 -1
  374. package/dist/question/deep-interview.js.map +1 -1
  375. package/dist/question/events.js.map +1 -1
  376. package/dist/question/renderer.js.map +1 -1
  377. package/dist/question/state.d.ts.map +1 -1
  378. package/dist/question/state.js.map +1 -1
  379. package/dist/question/ui.js.map +1 -1
  380. package/dist/ralph/contract.d.ts +1 -1
  381. package/dist/ralph/contract.d.ts.map +1 -1
  382. package/dist/ralplan/__tests__/consensus-gate.test.js +403 -8
  383. package/dist/ralplan/__tests__/consensus-gate.test.js.map +1 -1
  384. package/dist/ralplan/__tests__/runtime.test.js +112 -14
  385. package/dist/ralplan/__tests__/runtime.test.js.map +1 -1
  386. package/dist/ralplan/consensus-gate.d.ts +3 -3
  387. package/dist/ralplan/consensus-gate.d.ts.map +1 -1
  388. package/dist/ralplan/consensus-gate.js +155 -60
  389. package/dist/ralplan/consensus-gate.js.map +1 -1
  390. package/dist/ralplan/runtime.d.ts +2 -2
  391. package/dist/ralplan/runtime.d.ts.map +1 -1
  392. package/dist/ralplan/runtime.js +1 -2
  393. package/dist/ralplan/runtime.js.map +1 -1
  394. package/dist/runtime/bridge.d.ts.map +1 -1
  395. package/dist/runtime/bridge.js.map +1 -1
  396. package/dist/runtime/process-tree.js.map +1 -1
  397. package/dist/runtime/run-loop.js.map +1 -1
  398. package/dist/runtime/run-outcome.d.ts +3 -3
  399. package/dist/runtime/run-outcome.d.ts.map +1 -1
  400. package/dist/runtime/run-outcome.js.map +1 -1
  401. package/dist/runtime/run-state.js.map +1 -1
  402. package/dist/scripts/__tests__/codex-native-hook.test.js +5414 -801
  403. package/dist/scripts/__tests__/codex-native-hook.test.js.map +1 -1
  404. package/dist/scripts/__tests__/fixtures/issue-3138-installed-smoke.d.ts +2 -0
  405. package/dist/scripts/__tests__/fixtures/issue-3138-installed-smoke.d.ts.map +1 -0
  406. package/dist/scripts/__tests__/fixtures/issue-3138-installed-smoke.js +634 -0
  407. package/dist/scripts/__tests__/fixtures/issue-3138-installed-smoke.js.map +1 -0
  408. package/dist/scripts/__tests__/generate-release-body.test.js.map +1 -1
  409. package/dist/scripts/__tests__/hook-derived-watcher.test.js.map +1 -1
  410. package/dist/scripts/__tests__/notify-dispatcher.test.js.map +1 -1
  411. package/dist/scripts/__tests__/notify-fallback-delivery.test.d.ts +2 -0
  412. package/dist/scripts/__tests__/notify-fallback-delivery.test.d.ts.map +1 -0
  413. package/dist/scripts/__tests__/notify-fallback-delivery.test.js +174 -0
  414. package/dist/scripts/__tests__/notify-fallback-delivery.test.js.map +1 -0
  415. package/dist/scripts/__tests__/notify-state-io.test.js +57 -1
  416. package/dist/scripts/__tests__/notify-state-io.test.js.map +1 -1
  417. package/dist/scripts/__tests__/role-intent-bootstrap-e2e-3181.test.d.ts +2 -0
  418. package/dist/scripts/__tests__/role-intent-bootstrap-e2e-3181.test.d.ts.map +1 -0
  419. package/dist/scripts/__tests__/role-intent-bootstrap-e2e-3181.test.js +205 -0
  420. package/dist/scripts/__tests__/role-intent-bootstrap-e2e-3181.test.js.map +1 -0
  421. package/dist/scripts/__tests__/role-intent-durable-recovery-3181.test.d.ts +2 -0
  422. package/dist/scripts/__tests__/role-intent-durable-recovery-3181.test.d.ts.map +1 -0
  423. package/dist/scripts/__tests__/role-intent-durable-recovery-3181.test.js +175 -0
  424. package/dist/scripts/__tests__/role-intent-durable-recovery-3181.test.js.map +1 -0
  425. package/dist/scripts/__tests__/run-test-files.test.js.map +1 -1
  426. package/dist/scripts/__tests__/smoke-packed-install.test.js +848 -4
  427. package/dist/scripts/__tests__/smoke-packed-install.test.js.map +1 -1
  428. package/dist/scripts/__tests__/test-reply-listener-live.test.js.map +1 -1
  429. package/dist/scripts/build-api.js.map +1 -1
  430. package/dist/scripts/build-explore-harness.js.map +1 -1
  431. package/dist/scripts/build-sparkshell.js.map +1 -1
  432. package/dist/scripts/cleanup-explore-harness.js.map +1 -1
  433. package/dist/scripts/codex-execution-surface.js.map +1 -1
  434. package/dist/scripts/codex-native-hook.d.ts.map +1 -1
  435. package/dist/scripts/codex-native-hook.js +825 -172
  436. package/dist/scripts/codex-native-hook.js.map +1 -1
  437. package/dist/scripts/generate-native-release-manifest.js.map +1 -1
  438. package/dist/scripts/generate-release-body.js.map +1 -1
  439. package/dist/scripts/hook-payload-guard.d.ts.map +1 -1
  440. package/dist/scripts/hook-payload-guard.js.map +1 -1
  441. package/dist/scripts/notify-fallback-delivery.d.ts +48 -0
  442. package/dist/scripts/notify-fallback-delivery.d.ts.map +1 -0
  443. package/dist/scripts/notify-fallback-delivery.js +419 -0
  444. package/dist/scripts/notify-fallback-delivery.js.map +1 -0
  445. package/dist/scripts/notify-fallback-watcher.js +136 -30
  446. package/dist/scripts/notify-fallback-watcher.js.map +1 -1
  447. package/dist/scripts/notify-hook/auto-nudge.d.ts +18 -9
  448. package/dist/scripts/notify-hook/auto-nudge.d.ts.map +1 -1
  449. package/dist/scripts/notify-hook/auto-nudge.js +39 -13
  450. package/dist/scripts/notify-hook/auto-nudge.js.map +1 -1
  451. package/dist/scripts/notify-hook/managed-tmux.d.ts +23 -0
  452. package/dist/scripts/notify-hook/managed-tmux.d.ts.map +1 -1
  453. package/dist/scripts/notify-hook/managed-tmux.js +122 -12
  454. package/dist/scripts/notify-hook/managed-tmux.js.map +1 -1
  455. package/dist/scripts/notify-hook/orchestration-intent.d.ts +7 -7
  456. package/dist/scripts/notify-hook/orchestration-intent.d.ts.map +1 -1
  457. package/dist/scripts/notify-hook/ralph-session-resume.d.ts +5 -2
  458. package/dist/scripts/notify-hook/ralph-session-resume.d.ts.map +1 -1
  459. package/dist/scripts/notify-hook/ralph-session-resume.js +33 -37
  460. package/dist/scripts/notify-hook/ralph-session-resume.js.map +1 -1
  461. package/dist/scripts/notify-hook/state-io.d.ts +17 -0
  462. package/dist/scripts/notify-hook/state-io.d.ts.map +1 -1
  463. package/dist/scripts/notify-hook/state-io.js +73 -11
  464. package/dist/scripts/notify-hook/state-io.js.map +1 -1
  465. package/dist/scripts/notify-hook/team-dispatch.d.ts +1 -1
  466. package/dist/scripts/notify-hook/team-dispatch.js.map +1 -1
  467. package/dist/scripts/notify-hook/team-leader-nudge.d.ts +2 -2
  468. package/dist/scripts/notify-hook/team-tmux-guard.d.ts +4 -4
  469. package/dist/scripts/notify-hook/team-worker-posttooluse.js.map +1 -1
  470. package/dist/scripts/notify-hook/team-worker-stop.d.ts +1 -1
  471. package/dist/scripts/notify-hook/team-worker.d.ts +2 -2
  472. package/dist/scripts/notify-hook/tmux-injection.d.ts +8 -1
  473. package/dist/scripts/notify-hook/tmux-injection.d.ts.map +1 -1
  474. package/dist/scripts/notify-hook/tmux-injection.js +25 -16
  475. package/dist/scripts/notify-hook/tmux-injection.js.map +1 -1
  476. package/dist/scripts/notify-hook/visual-verdict.d.ts +1 -1
  477. package/dist/scripts/notify-hook/visual-verdict.d.ts.map +1 -1
  478. package/dist/scripts/notify-hook/visual-verdict.js +15 -13
  479. package/dist/scripts/notify-hook/visual-verdict.js.map +1 -1
  480. package/dist/scripts/notify-hook.d.ts +24 -1
  481. package/dist/scripts/notify-hook.d.ts.map +1 -1
  482. package/dist/scripts/notify-hook.js +266 -90
  483. package/dist/scripts/notify-hook.js.map +1 -1
  484. package/dist/scripts/postinstall.js.map +1 -1
  485. package/dist/scripts/prompt-inventory.js.map +1 -1
  486. package/dist/scripts/smoke-packed-install.d.ts +879 -2
  487. package/dist/scripts/smoke-packed-install.d.ts.map +1 -1
  488. package/dist/scripts/smoke-packed-install.js +1528 -7
  489. package/dist/scripts/smoke-packed-install.js.map +1 -1
  490. package/dist/scripts/sync-plugin-mirror.js.map +1 -1
  491. package/dist/scripts/test-reply-listener-live.js.map +1 -1
  492. package/dist/scripts/test-sparkshell.js.map +1 -1
  493. package/dist/scripts/verify-native-agents.js.map +1 -1
  494. package/dist/session-history/friction.js.map +1 -1
  495. package/dist/session-history/search.js.map +1 -1
  496. package/dist/sidecar/__tests__/boundary.test.js.map +1 -1
  497. package/dist/sidecar/collector.js.map +1 -1
  498. package/dist/sidecar/index.js.map +1 -1
  499. package/dist/sidecar/render.js.map +1 -1
  500. package/dist/sidecar/tmux.js.map +1 -1
  501. package/dist/state/__tests__/operations.test.js +64 -15
  502. package/dist/state/__tests__/operations.test.js.map +1 -1
  503. package/dist/state/__tests__/skill-active.test.js +19 -1
  504. package/dist/state/__tests__/skill-active.test.js.map +1 -1
  505. package/dist/state/__tests__/workflow-transition.test.js +61 -0
  506. package/dist/state/__tests__/workflow-transition.test.js.map +1 -1
  507. package/dist/state/mode-state-context.js.map +1 -1
  508. package/dist/state/operations.d.ts +1 -1
  509. package/dist/state/operations.d.ts.map +1 -1
  510. package/dist/state/operations.js +49 -55
  511. package/dist/state/operations.js.map +1 -1
  512. package/dist/state/paths.d.ts +1 -1
  513. package/dist/state/paths.d.ts.map +1 -1
  514. package/dist/state/paths.js +1 -1
  515. package/dist/state/paths.js.map +1 -1
  516. package/dist/state/skill-active.d.ts +13 -1
  517. package/dist/state/skill-active.d.ts.map +1 -1
  518. package/dist/state/skill-active.js +43 -4
  519. package/dist/state/skill-active.js.map +1 -1
  520. package/dist/state/terminal-normalization.js.map +1 -1
  521. package/dist/state/workflow-transition-reconcile.d.ts.map +1 -1
  522. package/dist/state/workflow-transition-reconcile.js +20 -4
  523. package/dist/state/workflow-transition-reconcile.js.map +1 -1
  524. package/dist/state/workflow-transition.d.ts +1 -1
  525. package/dist/state/workflow-transition.d.ts.map +1 -1
  526. package/dist/state/workflow-transition.js.map +1 -1
  527. package/dist/subagents/__tests__/adapted-role-binding.test.d.ts +2 -0
  528. package/dist/subagents/__tests__/adapted-role-binding.test.d.ts.map +1 -0
  529. package/dist/subagents/__tests__/adapted-role-binding.test.js +988 -0
  530. package/dist/subagents/__tests__/adapted-role-binding.test.js.map +1 -0
  531. package/dist/subagents/__tests__/leader-bootstrap-3181.test.d.ts +2 -0
  532. package/dist/subagents/__tests__/leader-bootstrap-3181.test.d.ts.map +1 -0
  533. package/dist/subagents/__tests__/leader-bootstrap-3181.test.js +273 -0
  534. package/dist/subagents/__tests__/leader-bootstrap-3181.test.js.map +1 -0
  535. package/dist/subagents/__tests__/tracker.test.js +1550 -10
  536. package/dist/subagents/__tests__/tracker.test.js.map +1 -1
  537. package/dist/subagents/adapted-role-binding.d.ts +17 -0
  538. package/dist/subagents/adapted-role-binding.d.ts.map +1 -0
  539. package/dist/subagents/adapted-role-binding.js +75 -0
  540. package/dist/subagents/adapted-role-binding.js.map +1 -0
  541. package/dist/subagents/role-routing-marker.d.ts +10 -0
  542. package/dist/subagents/role-routing-marker.d.ts.map +1 -0
  543. package/dist/subagents/role-routing-marker.js +136 -0
  544. package/dist/subagents/role-routing-marker.js.map +1 -0
  545. package/dist/subagents/tracker.d.ts +172 -0
  546. package/dist/subagents/tracker.d.ts.map +1 -1
  547. package/dist/subagents/tracker.js +1077 -61
  548. package/dist/subagents/tracker.js.map +1 -1
  549. package/dist/team/__tests__/approved-execution.test.js.map +1 -1
  550. package/dist/team/__tests__/delivery-e2e-smoke.test.js.map +1 -1
  551. package/dist/team/__tests__/model-contract.test.js +231 -1
  552. package/dist/team/__tests__/model-contract.test.js.map +1 -1
  553. package/dist/team/__tests__/role-router.test.js.map +1 -1
  554. package/dist/team/__tests__/runtime.test.js +401 -1
  555. package/dist/team/__tests__/runtime.test.js.map +1 -1
  556. package/dist/team/__tests__/scaling.test.js +181 -0
  557. package/dist/team/__tests__/scaling.test.js.map +1 -1
  558. package/dist/team/__tests__/state-root.test.js.map +1 -1
  559. package/dist/team/__tests__/tmux-session.test.js +434 -4
  560. package/dist/team/__tests__/tmux-session.test.js.map +1 -1
  561. package/dist/team/__tests__/tmux-test-fixture.js.map +1 -1
  562. package/dist/team/api-interop.d.ts +2 -2
  563. package/dist/team/api-interop.d.ts.map +1 -1
  564. package/dist/team/api-interop.js.map +1 -1
  565. package/dist/team/commit-hygiene.js.map +1 -1
  566. package/dist/team/contracts.d.ts +5 -5
  567. package/dist/team/contracts.d.ts.map +1 -1
  568. package/dist/team/delivery-log.js.map +1 -1
  569. package/dist/team/followup-planner.js.map +1 -1
  570. package/dist/team/goal-workflow.js.map +1 -1
  571. package/dist/team/idle-nudge.d.ts.map +1 -1
  572. package/dist/team/model-contract.d.ts +20 -1
  573. package/dist/team/model-contract.d.ts.map +1 -1
  574. package/dist/team/model-contract.js +267 -30
  575. package/dist/team/model-contract.js.map +1 -1
  576. package/dist/team/orchestrator.js.map +1 -1
  577. package/dist/team/pane-status.js.map +1 -1
  578. package/dist/team/phase-controller.js.map +1 -1
  579. package/dist/team/reminder-intents.d.ts +1 -1
  580. package/dist/team/reminder-intents.d.ts.map +1 -1
  581. package/dist/team/reminder-intents.js.map +1 -1
  582. package/dist/team/runtime-cli.js.map +1 -1
  583. package/dist/team/runtime.d.ts.map +1 -1
  584. package/dist/team/runtime.js +83 -52
  585. package/dist/team/runtime.js.map +1 -1
  586. package/dist/team/scaling.d.ts +9 -7
  587. package/dist/team/scaling.d.ts.map +1 -1
  588. package/dist/team/scaling.js +69 -28
  589. package/dist/team/scaling.js.map +1 -1
  590. package/dist/team/state/dispatch-lock.js.map +1 -1
  591. package/dist/team/state/dispatch.js.map +1 -1
  592. package/dist/team/state/events.js.map +1 -1
  593. package/dist/team/state/tasks.js.map +1 -1
  594. package/dist/team/state-root.js.map +1 -1
  595. package/dist/team/state.js.map +1 -1
  596. package/dist/team/team-identity.d.ts.map +1 -1
  597. package/dist/team/team-identity.js.map +1 -1
  598. package/dist/team/tmux-session.d.ts +2 -0
  599. package/dist/team/tmux-session.d.ts.map +1 -1
  600. package/dist/team/tmux-session.js +90 -42
  601. package/dist/team/tmux-session.js.map +1 -1
  602. package/dist/team/worker-bootstrap.js.map +1 -1
  603. package/dist/team/worktree.js.map +1 -1
  604. package/dist/ultragoal/__tests__/artifacts.test.js.map +1 -1
  605. package/dist/ultragoal/__tests__/docs-contract.test.js.map +1 -1
  606. package/dist/ultragoal/artifacts.d.ts.map +1 -1
  607. package/dist/ultragoal/artifacts.js +4 -1
  608. package/dist/ultragoal/artifacts.js.map +1 -1
  609. package/dist/url-reader/index.js.map +1 -1
  610. package/dist/utils/__tests__/agents-md.test.js +16 -0
  611. package/dist/utils/__tests__/agents-md.test.js.map +1 -1
  612. package/dist/utils/agents-md.d.ts.map +1 -1
  613. package/dist/utils/agents-md.js +4 -3
  614. package/dist/utils/agents-md.js.map +1 -1
  615. package/dist/utils/agents-model-table.js.map +1 -1
  616. package/dist/utils/package.js.map +1 -1
  617. package/dist/utils/paths.js.map +1 -1
  618. package/dist/utils/platform-command.js.map +1 -1
  619. package/dist/utils/repo-deps.js.map +1 -1
  620. package/dist/utils/version.js.map +1 -1
  621. package/dist/verification/__tests__/ci-rust-gates.test.js +1 -1
  622. package/dist/verification/__tests__/dev-merge-issue-close-workflow.test.js.map +1 -1
  623. package/dist/verification/verifier.js.map +1 -1
  624. package/dist/visual/constants.d.ts +1 -1
  625. package/dist/visual/constants.d.ts.map +1 -1
  626. package/dist/vscode/__tests__/index.test.js.map +1 -1
  627. package/dist/vscode/index.js.map +1 -1
  628. package/dist/wiki/__tests__/cjk-tokenize.test.js.map +1 -1
  629. package/dist/wiki/__tests__/lint.test.js.map +1 -1
  630. package/dist/wiki/__tests__/query.test.js.map +1 -1
  631. package/dist/wiki/__tests__/storage.test.js.map +1 -1
  632. package/dist/wiki/__tests__/test-helpers.d.ts.map +1 -1
  633. package/dist/wiki/lint.js.map +1 -1
  634. package/dist/wiki/query.js.map +1 -1
  635. package/dist/wiki/storage.js.map +1 -1
  636. package/package.json +2 -2
  637. package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
  638. package/plugins/oh-my-codex/skills/omx-setup/SKILL.md +10 -5
  639. package/plugins/oh-my-codex/skills/ralph/SKILL.md +4 -2
  640. package/plugins/oh-my-codex/skills/ralplan/SKILL.md +5 -2
  641. package/skills/omx-setup/SKILL.md +10 -5
  642. package/skills/ralph/SKILL.md +4 -2
  643. package/skills/ralplan/SKILL.md +5 -2
  644. package/src/scripts/__tests__/codex-native-hook.test.ts +20497 -12377
  645. package/src/scripts/__tests__/fixtures/issue-3138-installed-smoke.ts +734 -0
  646. package/src/scripts/__tests__/notify-fallback-delivery.test.ts +177 -0
  647. package/src/scripts/__tests__/notify-state-io.test.ts +73 -0
  648. package/src/scripts/__tests__/role-intent-bootstrap-e2e-3181.test.ts +215 -0
  649. package/src/scripts/__tests__/role-intent-durable-recovery-3181.test.ts +193 -0
  650. package/src/scripts/__tests__/smoke-packed-install.test.ts +991 -4
  651. package/src/scripts/codex-native-hook.ts +918 -172
  652. package/src/scripts/notify-fallback-delivery.ts +416 -0
  653. package/src/scripts/notify-fallback-watcher.ts +132 -40
  654. package/src/scripts/notify-hook/auto-nudge.ts +43 -12
  655. package/src/scripts/notify-hook/managed-tmux.ts +149 -12
  656. package/src/scripts/notify-hook/ralph-session-resume.ts +37 -36
  657. package/src/scripts/notify-hook/state-io.ts +100 -13
  658. package/src/scripts/notify-hook/tmux-injection.ts +38 -21
  659. package/src/scripts/notify-hook/visual-verdict.ts +22 -12
  660. package/src/scripts/notify-hook.ts +335 -90
  661. package/src/scripts/smoke-packed-install.ts +1829 -6
@@ -1,19 +1,22 @@
1
1
  /**
2
2
  * omx uninstall - Remove oh-my-codex configuration and installed artifacts
3
3
  */
4
- import { readFile, writeFile, readdir, rm } from "fs/promises";
5
- import { existsSync } from "fs";
6
- import { join, basename, dirname } from "path";
7
- import { formatTomlStringArray, getRootTomlArray, isOmxManagedNotifyCommand, sanitizePreviousNotifyCommand, stripExistingOmxBlocks, stripOmxEnvSettings, stripOmxTopLevelKeys, stripOmxFeatureFlags, upsertCodexHooksFeatureFlag, stripOmxSeededBehavioralDefaults, } from "../config/generator.js";
8
- import { hasUserCodexHooksAfterManagedRemoval, parseCodexHooksConfig, removeManagedCodexHooks, } from "../config/codex-hooks.js";
4
+ import { chmod, copyFile, lstat, open, readFile, readdir, rename, rm, writeFile } from "fs/promises";
5
+ import { constants, existsSync } from "fs";
6
+ import { join, basename, dirname, isAbsolute, relative } from "path";
7
+ import { randomUUID } from "crypto";
8
+ import { clearNativeHookClaimJournal, persistNativeHookClaimJournal, recoverNativeHookClaimJournal, syncNativeHookClaimParent, restoreNativeHookClaimNoClobber, } from "./native-hook-claim-journal.js";
9
+ import { formatTomlStringArray, getRootTomlArray, isOmxManagedNotifyCommand, sanitizePreviousNotifyCommand, stripExistingOmxBlocks, stripManagedCodexHookTrustState, stripOmxEnvSettings, stripOmxTopLevelKeys, stripOmxFeatureFlags, upsertCodexHooksFeatureFlag, stripOmxSeededBehavioralDefaults, } from "../config/generator.js";
10
+ import { buildManagedCodexNativeHookWindowsShimContent, buildManagedCodexNativeHookWindowsShimPath, classifyManagedCodexNativeHookWindowsShimOwnership, planManagedCodexHooksRemoval, ManagedCodexHooksPlanError, } from "../config/codex-hooks.js";
9
11
  import { getPackageRoot } from "../utils/package.js";
10
12
  import { AGENT_DEFINITIONS } from "../agents/definitions.js";
11
13
  import { detectLegacySkillRootOverlap } from "../utils/paths.js";
12
- import { resolveScopeDirectories } from "./setup.js";
14
+ import { decideWindowsNativeHookShimReference, resolveScopeDirectories, } from "./setup.js";
13
15
  import { resolveCodexHookFeatureFlagForCli } from "./codex-feature-probe.js";
14
16
  import { readPersistedSetupScope } from "./index.js";
15
- import { isOmxGeneratedAgentsMd } from "../utils/agents-md.js";
17
+ import { isOmxGeneratedAgentsMd, OMX_MANAGED_AGENTS_END_MARKER, OMX_MANAGED_AGENTS_START_MARKER, } from "../utils/agents-md.js";
16
18
  import { OMX_FIRST_PARTY_MCP_SERVER_NAMES } from "../config/omx-first-party-mcp.js";
19
+ import TOML from "@iarna/toml";
17
20
  function detectOmxConfigArtifacts(config) {
18
21
  const hasMcpServers = OMX_FIRST_PARTY_MCP_SERVER_NAMES.filter((name) => new RegExp(`\\[mcp_servers\\.${name}\\]`).test(config));
19
22
  const agentNames = Object.keys(AGENT_DEFINITIONS);
@@ -29,20 +32,17 @@ function detectOmxConfigArtifacts(config) {
29
32
  const hasTopLevelKeys = /^\s*notify\s*=.*node/m.test(config) ||
30
33
  /^\s*model_reasoning_effort\s*=/m.test(config) ||
31
34
  /^\s*developer_instructions\s*=.*oh-my-codex/m.test(config);
32
- const hasFeatureFlags = /^\s*multi_agent\s*=\s*true/m.test(config) ||
33
- /^\s*child_agents_md\s*=\s*true/m.test(config) ||
35
+ const hasFeatureFlags = /^\s*child_agents_md\s*=\s*true/m.test(config) ||
34
36
  /^\s*hooks\s*=\s*true/m.test(config) ||
35
37
  /^\s*codex_hooks\s*=\s*true/m.test(config) ||
36
38
  /^\s*goals\s*=\s*true/m.test(config) ||
37
39
  /^\s*goal\s*=\s*true/m.test(config);
38
- const hasExploreRoutingEnv = /^\s*USE_OMX_EXPLORE_CMD\s*=/m.test(config);
39
40
  return {
40
41
  hasMcpServers,
41
42
  hasAgentEntries,
42
43
  hasTuiSection,
43
44
  hasTopLevelKeys,
44
45
  hasFeatureFlags,
45
- hasExploreRoutingEnv,
46
46
  };
47
47
  }
48
48
  function hasNativeHooksFeatureFlag(config) {
@@ -61,17 +61,176 @@ function hasNativeHooksFeatureFlag(config) {
61
61
  .slice(featuresStart + 1, sectionEnd)
62
62
  .some((line) => /^\s*(?:hooks|codex_hooks)\s*=\s*true/.test(line));
63
63
  }
64
- async function shouldPreserveHooksFeatureFlag(hooksFilePath) {
65
- if (!existsSync(hooksFilePath))
66
- return false;
64
+ function fileIdentity(stat) {
65
+ return {
66
+ dev: stat.dev,
67
+ ino: stat.ino,
68
+ size: stat.size,
69
+ mode: stat.mode,
70
+ mtimeMs: stat.mtimeMs,
71
+ ctimeMs: stat.ctimeMs,
72
+ links: stat.nlink,
73
+ };
74
+ }
75
+ function hasSameFileIdentity(left, right) {
76
+ return left.dev === right.dev &&
77
+ left.ino === right.ino &&
78
+ left.size === right.size &&
79
+ left.mode === right.mode &&
80
+ left.mtimeMs === right.mtimeMs &&
81
+ left.ctimeMs === right.ctimeMs &&
82
+ left.links === right.links;
83
+ }
84
+ function isMissingPathError(error) {
85
+ return (typeof error === "object" &&
86
+ error !== null &&
87
+ "code" in error &&
88
+ error.code === "ENOENT");
89
+ }
90
+ async function captureControlledTopology(root, path) {
91
+ const parentPath = dirname(path);
92
+ const relativeParent = relative(root, parentPath);
93
+ if (isAbsolute(relativeParent) ||
94
+ relativeParent === ".." ||
95
+ relativeParent.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) ||
96
+ relativeParent.startsWith("/")) {
97
+ throw new Error(`Refusing to process ${path}: it is outside controlled Codex scope ${root}.`);
98
+ }
99
+ const ancestors = [];
100
+ let currentPath = root;
101
+ for (const segment of ["", ...relativeParent.split(/[\\/]/).filter(Boolean)]) {
102
+ if (segment)
103
+ currentPath = join(currentPath, segment);
104
+ try {
105
+ const stat = await lstat(currentPath);
106
+ if (stat.isSymbolicLink() || !stat.isDirectory()) {
107
+ throw new Error(`Refusing to process ${path}: controlled ancestor ${currentPath} must be a non-symbolic-link directory.`);
108
+ }
109
+ ancestors.push({
110
+ path: currentPath,
111
+ identity: { dev: stat.dev, ino: stat.ino },
112
+ });
113
+ }
114
+ catch (error) {
115
+ if (!isMissingPathError(error))
116
+ throw error;
117
+ ancestors.push({ path: currentPath, identity: null });
118
+ break;
119
+ }
120
+ }
121
+ return { root, ancestors };
122
+ }
123
+ async function assertControlledTopologyCurrent(topology) {
124
+ if (!topology)
125
+ return;
126
+ for (const ancestor of topology.ancestors) {
127
+ try {
128
+ const stat = await lstat(ancestor.path);
129
+ if (ancestor.identity === null ||
130
+ stat.isSymbolicLink() ||
131
+ !stat.isDirectory() ||
132
+ stat.dev !== ancestor.identity.dev ||
133
+ stat.ino !== ancestor.identity.ino) {
134
+ throw new Error(`Refusing uninstall because controlled ancestor ${ancestor.path} changed topology after planning.`);
135
+ }
136
+ }
137
+ catch (error) {
138
+ if (error instanceof Error && error.message.includes("changed topology")) {
139
+ throw error;
140
+ }
141
+ if (isMissingPathError(error) && ancestor.identity === null)
142
+ continue;
143
+ if (isMissingPathError(error)) {
144
+ throw new Error(`Refusing uninstall because controlled ancestor ${ancestor.path} changed topology after planning.`);
145
+ }
146
+ throw error;
147
+ }
148
+ }
149
+ }
150
+ function decodeStrictUtf8(path, bytes) {
67
151
  try {
68
- const existing = await readFile(hooksFilePath, "utf-8");
69
- return hasUserCodexHooksAfterManagedRemoval(existing);
152
+ const content = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(bytes);
153
+ if (!Buffer.from(content, "utf-8").equals(bytes)) {
154
+ throw new Error("decoded text did not round-trip to the original bytes");
155
+ }
156
+ return content;
70
157
  }
71
158
  catch {
72
- return false;
159
+ throw new ManagedCodexHooksPlanError("invalid_document", `Refusing to process ${path}: it is not valid UTF-8.`, { path });
73
160
  }
74
161
  }
162
+ async function readFileSnapshot(path, options = {}) {
163
+ const topology = options.controlledRoot
164
+ ? await captureControlledTopology(options.controlledRoot, path)
165
+ : null;
166
+ let before;
167
+ try {
168
+ before = await lstat(path);
169
+ }
170
+ catch (error) {
171
+ if (isMissingPathError(error)) {
172
+ await assertControlledTopologyCurrent(topology);
173
+ return {
174
+ path,
175
+ content: null,
176
+ bytes: null,
177
+ mode: null,
178
+ identity: null,
179
+ topology,
180
+ };
181
+ }
182
+ throw error;
183
+ }
184
+ if (before.isSymbolicLink() || !before.isFile() || before.nlink !== 1) {
185
+ throw new Error(`Refusing to process ${path}: expected a regular file, not a symbolic link or other filesystem object.`);
186
+ }
187
+ const bytes = await readFile(path);
188
+ const after = await lstat(path);
189
+ await assertControlledTopologyCurrent(topology);
190
+ if (after.isSymbolicLink() || !after.isFile() || after.nlink !== 1 || !hasSameFileIdentity(fileIdentity(before), fileIdentity(after))) {
191
+ throw new Error(`Refusing to process ${path}: it changed while uninstall was planning.`);
192
+ }
193
+ return {
194
+ path,
195
+ content: options.strictUtf8 === false ? bytes.toString("utf-8") : decodeStrictUtf8(path, bytes),
196
+ bytes,
197
+ mode: after.mode & 0o7777,
198
+ identity: fileIdentity(after),
199
+ topology,
200
+ };
201
+ }
202
+ async function planHooksRemoval(hooks, pkgRoot, platform, controlledRoot) {
203
+ let plan;
204
+ if (hooks.content !== null) {
205
+ const result = planManagedCodexHooksRemoval(hooks.content, hooks.path, {
206
+ platform,
207
+ codexHomeDir: dirname(hooks.path),
208
+ });
209
+ if (!result.ok)
210
+ throw result.error;
211
+ plan = result;
212
+ }
213
+ if (platform !== "win32")
214
+ return { hooks, plan };
215
+ const shimPath = buildManagedCodexNativeHookWindowsShimPath(dirname(hooks.path));
216
+ const shim = await readFileSnapshot(shimPath, {
217
+ strictUtf8: false,
218
+ // On non-Windows hosts the test-only platform seam intentionally produces
219
+ // a win32 path that the host filesystem cannot place under this root.
220
+ controlledRoot: platform === process.platform ? controlledRoot : undefined,
221
+ });
222
+ if (shim.bytes !== null) {
223
+ const expectedShim = Buffer.from(buildManagedCodexNativeHookWindowsShimContent(pkgRoot), "utf-8");
224
+ if (classifyManagedCodexNativeHookWindowsShimOwnership(shim.bytes, expectedShim) === "modified") {
225
+ throw new Error(`Refusing to remove modified native hook Windows shim at ${shim.path}.`);
226
+ }
227
+ const shimReference = decideWindowsNativeHookShimReference(plan?.finalContent ?? null, shim.path);
228
+ if (shimReference !== "not_referenced") {
229
+ return { hooks, plan, preservedShimPrecondition: shim };
230
+ }
231
+ }
232
+ return { hooks, plan, shim };
233
+ }
75
234
  function insertRootTomlKey(config, line) {
76
235
  const lines = config.split(/\r?\n/);
77
236
  const firstTableIndex = lines.findIndex((candidate) => /^\s*\[/.test(candidate));
@@ -79,30 +238,90 @@ function insertRootTomlKey(config, line) {
79
238
  lines.splice(insertAt, 0, line);
80
239
  return lines.join("\n").replace(/\n{3,}/g, "\n\n");
81
240
  }
82
- async function restorePreviousNotifyIfDispatcher(configPath, strippedConfig, originalConfig) {
83
- const currentNotify = getRootTomlArray(originalConfig, "notify");
84
- if (!isOmxManagedNotifyCommand(currentNotify, getPackageRoot()) ||
85
- !currentNotify?.some((part) => /(?:^|[\\/])notify-dispatcher\.js$/.test(part))) {
86
- return strippedConfig;
241
+ function isManagedDispatcherNotify(config) {
242
+ const currentNotify = getRootTomlArray(config, "notify");
243
+ return Boolean(isOmxManagedNotifyCommand(currentNotify, getPackageRoot()) &&
244
+ currentNotify?.some((part) => /(?:^|[\\/])notify-dispatcher\.js$/.test(part)));
245
+ }
246
+ function invalidNotifyMetadata(path, reason) {
247
+ return new ManagedCodexHooksPlanError("invalid_document", `Refusing to use notification metadata ${path}: ${reason}.`, { path });
248
+ }
249
+ function parseNotifyMetadata(snapshot, currentNotify) {
250
+ if (snapshot.content === null) {
251
+ throw invalidNotifyMetadata(snapshot.path, "the managed dispatcher metadata is missing");
87
252
  }
88
- const metadataPath = join(dirname(configPath), ".omx", "notify-dispatch.json");
253
+ if (!currentNotify.includes(snapshot.path)) {
254
+ throw invalidNotifyMetadata(snapshot.path, "the managed dispatcher does not reference the controlled metadata path");
255
+ }
256
+ let parsed;
89
257
  try {
90
- const metadata = JSON.parse(await readFile(metadataPath, "utf-8"));
91
- const previousNotify = metadata.previousNotify;
92
- if (Array.isArray(previousNotify) &&
93
- previousNotify.every((item) => typeof item === "string")) {
94
- const sanitizedPreviousNotify = sanitizePreviousNotifyCommand(previousNotify, getPackageRoot());
95
- if (sanitizedPreviousNotify) {
96
- return insertRootTomlKey(strippedConfig, `notify = ${formatTomlStringArray(sanitizedPreviousNotify)}`);
97
- }
258
+ parsed = JSON.parse(snapshot.content);
259
+ }
260
+ catch (error) {
261
+ throw invalidNotifyMetadata(snapshot.path, `invalid JSON (${error instanceof Error ? error.message : String(error)})`);
262
+ }
263
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
264
+ throw invalidNotifyMetadata(snapshot.path, "expected a JSON object");
265
+ }
266
+ const metadata = parsed;
267
+ if (metadata.managedBy !== "oh-my-codex" || metadata.version !== 1) {
268
+ throw invalidNotifyMetadata(snapshot.path, "expected OMX ownership and version 1");
269
+ }
270
+ const validateStringArray = (value, name) => {
271
+ if (!Array.isArray(value) || !value.every((item) => typeof item === "string")) {
272
+ throw invalidNotifyMetadata(snapshot.path, `${name} must be an array of strings`);
98
273
  }
274
+ return [...value];
275
+ };
276
+ const previousNotify = metadata.previousNotify;
277
+ if (!Object.hasOwn(metadata, "previousNotify") ||
278
+ (previousNotify !== null &&
279
+ (!Array.isArray(previousNotify) ||
280
+ !previousNotify.every((item) => typeof item === "string")))) {
281
+ throw invalidNotifyMetadata(snapshot.path, "previousNotify must be null or an array of strings");
99
282
  }
100
- catch {
101
- // Missing or malformed metadata means uninstall falls back to removing OMX notify.
283
+ validateStringArray(metadata.omxNotify, "omxNotify");
284
+ const dispatcherNotify = validateStringArray(metadata.dispatcherNotify, "dispatcherNotify");
285
+ if (dispatcherNotify.length !== currentNotify.length ||
286
+ dispatcherNotify.some((part, index) => part !== currentNotify[index])) {
287
+ throw invalidNotifyMetadata(snapshot.path, "dispatcherNotify does not match the managed dispatcher command");
102
288
  }
103
- return strippedConfig;
289
+ return {
290
+ snapshot,
291
+ previousNotify: Array.isArray(previousNotify) ? [...previousNotify] : null,
292
+ };
104
293
  }
105
- async function cleanConfig(configPath, options) {
294
+ async function planNotifyMetadata(configSnapshot, codexHomeDir) {
295
+ if (configSnapshot.content === null || !isManagedDispatcherNotify(configSnapshot.content)) {
296
+ return undefined;
297
+ }
298
+ const currentNotify = getRootTomlArray(configSnapshot.content, "notify");
299
+ if (!currentNotify) {
300
+ throw invalidNotifyMetadata(join(codexHomeDir, ".omx", "notify-dispatch.json"), "the managed dispatcher command is invalid");
301
+ }
302
+ let snapshot;
303
+ try {
304
+ snapshot = await readFileSnapshot(join(codexHomeDir, ".omx", "notify-dispatch.json"), { controlledRoot: codexHomeDir });
305
+ }
306
+ catch (error) {
307
+ if (error instanceof ManagedCodexHooksPlanError)
308
+ throw error;
309
+ throw invalidNotifyMetadata(join(codexHomeDir, ".omx", "notify-dispatch.json"), `unreadable (${error instanceof Error ? error.message : String(error)})`);
310
+ }
311
+ return parseNotifyMetadata(snapshot, currentNotify);
312
+ }
313
+ function restorePreviousNotifyIfDispatcher(strippedConfig, originalConfig, metadataPlan) {
314
+ if (!isManagedDispatcherNotify(originalConfig))
315
+ return strippedConfig;
316
+ if (!metadataPlan) {
317
+ throw new Error("Missing planned notification metadata for a managed dispatcher.");
318
+ }
319
+ const sanitizedPreviousNotify = sanitizePreviousNotifyCommand(metadataPlan.previousNotify, getPackageRoot());
320
+ return sanitizedPreviousNotify
321
+ ? insertRootTomlKey(strippedConfig, `notify = ${formatTomlStringArray(sanitizedPreviousNotify)}`)
322
+ : strippedConfig;
323
+ }
324
+ async function planConfigCleanup(configSnapshot, options) {
106
325
  const result = {
107
326
  configCleaned: false,
108
327
  mcpServersRemoved: [],
@@ -111,12 +330,10 @@ async function cleanConfig(configPath, options) {
111
330
  topLevelKeysRemoved: false,
112
331
  featureFlagsRemoved: false,
113
332
  };
114
- if (!existsSync(configPath)) {
115
- if (options.verbose)
116
- console.log(" config.toml not found, skipping.");
117
- return result;
333
+ const original = configSnapshot.content;
334
+ if (original === null) {
335
+ return { config: configSnapshot, finalContent: null, result };
118
336
  }
119
- const original = await readFile(configPath, "utf-8");
120
337
  const detected = detectOmxConfigArtifacts(original);
121
338
  const shouldRestoreHooksFeatureFlag = options.preserveHooksFeatureFlag && hasNativeHooksFeatureFlag(original);
122
339
  result.mcpServersRemoved = detected.hasMcpServers;
@@ -124,18 +341,33 @@ async function cleanConfig(configPath, options) {
124
341
  result.tuiSectionRemoved = detected.hasTuiSection;
125
342
  result.topLevelKeysRemoved = detected.hasTopLevelKeys;
126
343
  result.featureFlagsRemoved = detected.hasFeatureFlags;
344
+ // Verify proof ownership against the untouched source before marker stripping
345
+ // can hide a foreign sibling in an otherwise OMX-looking trust declaration.
346
+ stripManagedCodexHookTrustState(original, {
347
+ priorManagedHookTrustState: options.priorHookTrustState,
348
+ managedTrustState: options.finalHookTrustState,
349
+ });
127
350
  // Strip OMX tables block (MCP servers, agents, tui)
128
351
  let config = original;
129
- const { cleaned } = stripExistingOmxBlocks(config);
352
+ const { cleaned } = stripExistingOmxBlocks(config, {
353
+ managedTrustState: options.finalHookTrustState,
354
+ priorManagedHookTrustState: options.priorHookTrustState,
355
+ });
130
356
  config = cleaned;
131
357
  // Strip OMX top-level keys, then restore a pre-existing user notify when
132
358
  // setup had wrapped it in the OMX dispatcher.
133
359
  config = stripOmxTopLevelKeys(config);
134
- config = await restorePreviousNotifyIfDispatcher(configPath, config, original);
360
+ config = restorePreviousNotifyIfDispatcher(config, original, options.notifyMetadata);
135
361
  // Strip OMX-seeded behavioral defaults only when the seeded pair is unchanged.
136
362
  config = stripOmxSeededBehavioralDefaults(config);
363
+ // Remove only trust tables whose hashes and coordinates match the planned
364
+ // managed hooks before their removal. User-owned conflicts remain intact.
365
+ config = stripManagedCodexHookTrustState(config, {
366
+ priorManagedHookTrustState: options.priorHookTrustState,
367
+ managedTrustState: options.finalHookTrustState,
368
+ });
137
369
  // Strip feature flags
138
- config = stripOmxFeatureFlags(config);
370
+ config = stripOmxFeatureFlags(config, { preserveMultiAgent: true });
139
371
  if (shouldRestoreHooksFeatureFlag) {
140
372
  config = upsertCodexHooksFeatureFlag(config, resolveCodexHookFeatureFlagForCli({
141
373
  codexFeaturesProbe: options.codexFeaturesProbe,
@@ -146,20 +378,8 @@ async function cleanConfig(configPath, options) {
146
378
  config = stripOmxEnvSettings(config);
147
379
  // Normalize trailing whitespace
148
380
  config = config.trimEnd() + "\n";
149
- if (config !== original) {
150
- result.configCleaned = true;
151
- if (!options.dryRun) {
152
- await writeFile(configPath, config);
153
- }
154
- if (options.verbose) {
155
- console.log(` ${options.dryRun ? "Would clean" : "Cleaned"} ${configPath}`);
156
- }
157
- }
158
- else {
159
- if (options.verbose)
160
- console.log(" No OMX config entries found.");
161
- }
162
- return result;
381
+ result.configCleaned = config !== original;
382
+ return { config: configSnapshot, finalContent: config, result };
163
383
  }
164
384
  async function removeInstalledPrompts(promptsDir, pkgRoot, options) {
165
385
  const srcPromptsDir = join(pkgRoot, "prompts");
@@ -240,6 +460,19 @@ async function removeAgentsMd(agentsMdPath, options) {
240
460
  return false;
241
461
  try {
242
462
  const content = await readFile(agentsMdPath, "utf-8");
463
+ const startIndex = content.indexOf(OMX_MANAGED_AGENTS_START_MARKER);
464
+ const endIndex = content.indexOf(OMX_MANAGED_AGENTS_END_MARKER);
465
+ if (startIndex >= 0 && endIndex > startIndex) {
466
+ const blockEnd = endIndex + OMX_MANAGED_AGENTS_END_MARKER.length;
467
+ const preserved = `${content.slice(0, startIndex).trimEnd()}\n${content.slice(blockEnd).trimStart()}`.trim();
468
+ if (preserved) {
469
+ if (!options.dryRun)
470
+ await writeFile(agentsMdPath, `${preserved}\n`, "utf-8");
471
+ if (options.verbose)
472
+ console.log(" Removed OMX-managed AGENTS.md sections and preserved user guidance.");
473
+ return false;
474
+ }
475
+ }
243
476
  if (!isOmxGeneratedAgentsMd(content)) {
244
477
  if (options.verbose)
245
478
  console.log(" AGENTS.md is not OMX-generated, skipping.");
@@ -256,29 +489,561 @@ async function removeAgentsMd(agentsMdPath, options) {
256
489
  console.log(` ${options.dryRun ? "Would remove" : "Removed"} AGENTS.md`);
257
490
  return true;
258
491
  }
259
- async function removeHooksFile(hooksFilePath, options) {
260
- if (!existsSync(hooksFilePath))
261
- return false;
262
- const existing = await readFile(hooksFilePath, "utf-8");
263
- const { nextContent, removedCount } = removeManagedCodexHooks(existing);
264
- const parsed = parseCodexHooksConfig(existing);
265
- const emptyManagedArtifact = parsed !== null &&
266
- Object.keys(parsed.hooks).length === 0 &&
267
- Object.keys(parsed.root).every((key) => key === "hooks");
268
- if (removedCount === 0 && !emptyManagedArtifact)
269
- return false;
270
- if (!options.dryRun) {
271
- if (nextContent === null || emptyManagedArtifact) {
272
- await rm(hooksFilePath, { force: true });
492
+ function assertValidHooksJson(content) {
493
+ JSON.parse(content);
494
+ }
495
+ function assertValidToml(content) {
496
+ TOML.parse(content);
497
+ }
498
+ function transactionTemporaryPath(path, purpose, options) {
499
+ return options.transactionTemporaryPath?.(path, purpose) ?? join(dirname(path), `.${basename(path)}.omx-uninstall-${purpose}-${process.pid}-${randomUUID()}.tmp`);
500
+ }
501
+ function transactionClaimPath(path) {
502
+ return join(dirname(path), `.${basename(path)}.omx-uninstall-claim-${process.pid}-${randomUUID()}.tmp`);
503
+ }
504
+ async function restoreUninstallClaim(claimPath, destinationPath) {
505
+ await restoreNativeHookClaimNoClobber(claimPath, destinationPath);
506
+ }
507
+ function snapshotReadOptions(snapshot) {
508
+ return {
509
+ strictUtf8: false,
510
+ controlledRoot: snapshot.topology?.root,
511
+ };
512
+ }
513
+ async function captureCurrentSnapshot(reference) {
514
+ return readFileSnapshot(reference.path, snapshotReadOptions(reference));
515
+ }
516
+ function renamedDestinationOwnership(snapshot, destinationPath, topology) {
517
+ if (snapshot.bytes === null || snapshot.mode === null || snapshot.identity === null) {
518
+ throw new Error(`Replacement temporary ${snapshot.path} was not fully captured before rename.`);
519
+ }
520
+ return {
521
+ path: destinationPath,
522
+ bytes: snapshot.bytes,
523
+ mode: snapshot.mode,
524
+ identity: { dev: snapshot.identity.dev, ino: snapshot.identity.ino },
525
+ topology,
526
+ };
527
+ }
528
+ async function captureRenamedDestinationOwnership(ownership) {
529
+ await assertControlledTopologyCurrent(ownership.topology);
530
+ const current = await readFileSnapshot(ownership.path, {
531
+ strictUtf8: false,
532
+ controlledRoot: ownership.topology?.root,
533
+ });
534
+ if (current.bytes === null ||
535
+ current.mode !== ownership.mode ||
536
+ !current.bytes.equals(ownership.bytes) ||
537
+ current.identity === null ||
538
+ current.identity.dev !== ownership.identity.dev ||
539
+ current.identity.ino !== ownership.identity.ino) {
540
+ throw new Error(`Uninstall replacement ownership changed for ${ownership.path}.`);
541
+ }
542
+ return current;
543
+ }
544
+ async function assertSnapshotCurrent(snapshot) {
545
+ await assertControlledTopologyCurrent(snapshot.topology);
546
+ const current = await captureCurrentSnapshot(snapshot);
547
+ if (snapshot.bytes === null && current.bytes === null)
548
+ return;
549
+ if (snapshot.bytes !== null &&
550
+ current.bytes !== null &&
551
+ snapshot.identity !== null &&
552
+ current.identity !== null &&
553
+ snapshot.bytes.equals(current.bytes) &&
554
+ hasSameFileIdentity(snapshot.identity, current.identity)) {
555
+ return;
556
+ }
557
+ throw new Error(`Refusing uninstall because planned artifact ${snapshot.path} changed, was created, or was removed after planning.`);
558
+ }
559
+ async function assertSnapshotAtPath(path, expected, context) {
560
+ await assertControlledTopologyCurrent(expected.topology);
561
+ const actual = await readFileSnapshot(path, snapshotReadOptions(expected));
562
+ if (expected.bytes === null ||
563
+ actual.bytes === null ||
564
+ expected.identity === null ||
565
+ actual.identity === null ||
566
+ !expected.bytes.equals(actual.bytes) ||
567
+ actual.mode !== expected.mode ||
568
+ actual.identity.dev !== expected.identity.dev ||
569
+ actual.identity.ino !== expected.identity.ino) {
570
+ throw new Error(`Refusing uninstall because ${context} ${path} is not the planned artifact.`);
571
+ }
572
+ return actual;
573
+ }
574
+ async function assertSnapshotMatchesPlannedContent(actual, expected, context) {
575
+ await assertControlledTopologyCurrent(expected.topology);
576
+ if (actual.bytes === null ||
577
+ expected.bytes === null ||
578
+ actual.mode !== expected.mode ||
579
+ !actual.bytes.equals(expected.bytes)) {
580
+ throw new Error(`Uninstall ${context} mismatch for ${expected.path}.`);
581
+ }
582
+ }
583
+ async function assertSnapshotsCurrent(snapshots) {
584
+ for (const snapshot of snapshots)
585
+ await assertSnapshotCurrent(snapshot);
586
+ }
587
+ async function removeOwnedTemporary(path, snapshot, originalError, description) {
588
+ try {
589
+ if (!snapshot) {
590
+ throw new Error(`${description} path was not fully captured after writing.`);
273
591
  }
274
- else {
275
- await writeFile(hooksFilePath, nextContent);
592
+ await assertSnapshotCurrent(snapshot);
593
+ const claimPath = transactionClaimPath(path);
594
+ await rename(path, claimPath);
595
+ try {
596
+ await assertSnapshotAtPath(claimPath, snapshot, `${description} cleanup claim`);
597
+ }
598
+ catch (error) {
599
+ try {
600
+ await restoreUninstallClaim(claimPath, path);
601
+ }
602
+ catch (recoveryError) {
603
+ throw new Error(`${error instanceof Error ? error.message : String(error)}; preserved claim ${claimPath} for manual recovery: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`);
604
+ }
605
+ throw error;
276
606
  }
607
+ await rm(claimPath);
277
608
  }
278
- if (options.verbose) {
279
- console.log(` ${options.dryRun ? "Would clean" : nextContent === null || emptyManagedArtifact ? "Removed" : "Cleaned"} ${basename(hooksFilePath)}`);
609
+ catch (cleanupError) {
610
+ const message = originalError instanceof Error
611
+ ? originalError.message
612
+ : String(originalError);
613
+ throw new Error(`Uninstall artifact transaction failed (${message}) and preserved ${description} ${path} for manual recovery after cleanup verification failed: ${cleanupError instanceof Error ? cleanupError.message : String(cleanupError)}`);
614
+ }
615
+ }
616
+ async function atomicReplaceFile(mutation, expectedCurrent, content, options, stage, onRename, assertApplied) {
617
+ if (mutation.snapshot.mode === null) {
618
+ throw new Error(`Refusing to replace ${mutation.snapshot.path}: uninstall did not plan a regular-file mode.`);
619
+ }
620
+ const temporaryPath = transactionTemporaryPath(mutation.snapshot.path, "write", options);
621
+ let handle;
622
+ let temporaryCreated = false;
623
+ let temporarySnapshot;
624
+ let claimPath;
625
+ let claimCreated = false;
626
+ let journaledClaim = false;
627
+ try {
628
+ await options.transactionFailureInjector?.(stage === "write" ? "before-temp-write" : "before-rollback");
629
+ await assertApplied?.();
630
+ await assertSnapshotCurrent(expectedCurrent);
631
+ handle = await open(temporaryPath, "wx", mutation.snapshot.mode);
632
+ temporaryCreated = true;
633
+ await handle.writeFile(content);
634
+ await chmod(temporaryPath, mutation.snapshot.mode);
635
+ await handle.sync();
636
+ await handle.close();
637
+ handle = undefined;
638
+ temporarySnapshot = await readFileSnapshot(temporaryPath, snapshotReadOptions(mutation.snapshot));
639
+ if (temporarySnapshot.bytes === null ||
640
+ temporarySnapshot.mode !== mutation.snapshot.mode ||
641
+ !temporarySnapshot.bytes.equals(content)) {
642
+ throw new Error(`Read-back verification failed for replacement temporary ${temporaryPath}.`);
643
+ }
644
+ await options.transactionFailureInjector?.(stage === "write" ? "before-rename" : "before-rollback-rename");
645
+ await assertApplied?.();
646
+ await assertControlledTopologyCurrent(mutation.snapshot.topology);
647
+ await assertSnapshotCurrent(expectedCurrent);
648
+ await assertSnapshotCurrent(temporarySnapshot);
649
+ await options.transactionFailureInjector?.(stage === "write"
650
+ ? "after-final-rename-validation"
651
+ : "after-final-restore-validation");
652
+ if (!temporarySnapshot) {
653
+ throw new Error(`Replacement temporary ${temporaryPath} was not fully captured before install.`);
654
+ }
655
+ claimPath = transactionClaimPath(mutation.snapshot.path);
656
+ const controlledRoot = mutation.snapshot.topology?.root;
657
+ if (expectedCurrent.bytes !== null && controlledRoot) {
658
+ await persistNativeHookClaimJournal(controlledRoot, {
659
+ canonicalPath: mutation.snapshot.path,
660
+ claimPath,
661
+ before: expectedCurrent.bytes,
662
+ after: content,
663
+ });
664
+ journaledClaim = true;
665
+ await rename(mutation.snapshot.path, claimPath);
666
+ claimCreated = true;
667
+ await syncNativeHookClaimParent(claimPath);
668
+ await assertSnapshotAtPath(claimPath, expectedCurrent, "replacement claim");
669
+ }
670
+ await copyFile(temporaryPath, mutation.snapshot.path, constants.COPYFILE_EXCL);
671
+ await chmod(mutation.snapshot.path, mutation.snapshot.mode);
672
+ const installedHandle = await open(mutation.snapshot.path, "r");
673
+ try {
674
+ await installedHandle.sync();
675
+ }
676
+ finally {
677
+ await installedHandle.close();
678
+ }
679
+ await syncNativeHookClaimParent(mutation.snapshot.path);
680
+ const actual = await captureCurrentSnapshot(mutation.snapshot);
681
+ if (actual.bytes === null || actual.mode !== mutation.snapshot.mode || !actual.bytes.equals(content)) {
682
+ throw new Error(`Read-back verification failed for replacement ${mutation.snapshot.path}.`);
683
+ }
684
+ if (claimCreated && claimPath) {
685
+ await rm(claimPath);
686
+ await syncNativeHookClaimParent(claimPath);
687
+ claimCreated = false;
688
+ }
689
+ if (journaledClaim && controlledRoot) {
690
+ await clearNativeHookClaimJournal(controlledRoot);
691
+ journaledClaim = false;
692
+ }
693
+ await rm(temporaryPath);
694
+ temporaryCreated = false;
695
+ const ownership = renamedDestinationOwnership(actual, mutation.snapshot.path, mutation.snapshot.topology);
696
+ onRename(ownership);
697
+ if (stage === "write") {
698
+ await options.transactionFailureInjector?.("after-rename");
699
+ }
700
+ const verified = await captureRenamedDestinationOwnership(ownership);
701
+ if (stage === "write" && mutation.validate) {
702
+ mutation.validate(decodeStrictUtf8(mutation.snapshot.path, verified.bytes));
703
+ }
704
+ return verified;
705
+ }
706
+ catch (error) {
707
+ await handle?.close().catch(() => undefined);
708
+ if (claimCreated && claimPath) {
709
+ try {
710
+ await restoreUninstallClaim(claimPath, mutation.snapshot.path);
711
+ await syncNativeHookClaimParent(mutation.snapshot.path);
712
+ claimCreated = false;
713
+ const controlledRoot = mutation.snapshot.topology?.root;
714
+ if (journaledClaim && controlledRoot) {
715
+ await clearNativeHookClaimJournal(controlledRoot);
716
+ journaledClaim = false;
717
+ }
718
+ }
719
+ catch (recoveryError) {
720
+ throw new Error(`Uninstall replacement failed (${error instanceof Error ? error.message : String(error)}) and preserved ${claimPath} for manual recovery: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`);
721
+ }
722
+ }
723
+ if (temporaryCreated) {
724
+ await removeOwnedTemporary(temporaryPath, temporarySnapshot, error, "temporary");
725
+ }
726
+ throw error;
727
+ }
728
+ }
729
+ async function stageAndRemoveFile(mutation, execution, options, assertApplied) {
730
+ if (mutation.snapshot.bytes === null || mutation.snapshot.mode === null) {
731
+ throw new Error(`Refusing to remove ${mutation.snapshot.path}: uninstall did not plan a regular-file snapshot.`);
732
+ }
733
+ const stagedPath = transactionTemporaryPath(mutation.snapshot.path, "delete", options);
734
+ let handle;
735
+ let stagedCreated = false;
736
+ try {
737
+ await options.transactionFailureInjector?.("before-temp-write");
738
+ await assertApplied();
739
+ await assertSnapshotCurrent(mutation.snapshot);
740
+ handle = await open(stagedPath, "wx", mutation.snapshot.mode);
741
+ stagedCreated = true;
742
+ await handle.writeFile(mutation.snapshot.bytes);
743
+ await chmod(stagedPath, mutation.snapshot.mode);
744
+ await handle.sync();
745
+ await handle.close();
746
+ handle = undefined;
747
+ const stagedDeletion = await readFileSnapshot(stagedPath, snapshotReadOptions(mutation.snapshot));
748
+ await assertSnapshotMatchesPlannedContent(stagedDeletion, mutation.snapshot, "staged deletion");
749
+ execution.stagedDeletion = stagedDeletion;
750
+ await options.transactionFailureInjector?.("before-remove");
751
+ await assertControlledTopologyCurrent(mutation.snapshot.topology);
752
+ await assertSnapshotCurrent(mutation.snapshot);
753
+ await assertSnapshotCurrent(stagedDeletion);
754
+ await assertApplied();
755
+ await options.transactionFailureInjector?.("after-final-remove-validation");
756
+ await assertSnapshotCurrent(stagedDeletion);
757
+ const claimPath = transactionClaimPath(mutation.snapshot.path);
758
+ const controlledRoot = mutation.snapshot.topology?.root;
759
+ if (controlledRoot && mutation.snapshot.bytes !== null) {
760
+ await persistNativeHookClaimJournal(controlledRoot, {
761
+ canonicalPath: mutation.snapshot.path,
762
+ claimPath,
763
+ before: mutation.snapshot.bytes,
764
+ after: null,
765
+ });
766
+ }
767
+ await rename(mutation.snapshot.path, claimPath);
768
+ if (controlledRoot)
769
+ await syncNativeHookClaimParent(claimPath);
770
+ execution.appliedSnapshot = {
771
+ path: mutation.snapshot.path,
772
+ content: null,
773
+ bytes: null,
774
+ mode: null,
775
+ identity: null,
776
+ topology: mutation.snapshot.topology,
777
+ };
778
+ execution.phase = "destructive";
779
+ try {
780
+ await assertSnapshotAtPath(claimPath, mutation.snapshot, "removal claim");
781
+ }
782
+ catch (error) {
783
+ try {
784
+ await restoreUninstallClaim(claimPath, mutation.snapshot.path);
785
+ if (controlledRoot)
786
+ await syncNativeHookClaimParent(mutation.snapshot.path);
787
+ if (controlledRoot)
788
+ await clearNativeHookClaimJournal(controlledRoot);
789
+ execution.appliedSnapshot = undefined;
790
+ execution.phase = "prepared";
791
+ }
792
+ catch (recoveryError) {
793
+ throw new Error(`Uninstall removal claim failed (${error instanceof Error ? error.message : String(error)}) and preserved ${claimPath} for manual recovery: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`);
794
+ }
795
+ throw error;
796
+ }
797
+ await rm(claimPath);
798
+ if (controlledRoot)
799
+ await syncNativeHookClaimParent(claimPath);
800
+ if (controlledRoot)
801
+ await clearNativeHookClaimJournal(controlledRoot);
802
+ await options.transactionFailureInjector?.("after-remove");
803
+ await assertControlledTopologyCurrent(mutation.snapshot.topology);
804
+ const absent = await captureCurrentSnapshot(mutation.snapshot);
805
+ if (absent.bytes !== null) {
806
+ throw new Error(`Read-back verification failed for ${mutation.snapshot.path}: expected absence.`);
807
+ }
808
+ execution.phase = "verified";
809
+ }
810
+ catch (error) {
811
+ await handle?.close().catch(() => undefined);
812
+ if (stagedCreated && execution.phase === "prepared") {
813
+ await removeOwnedTemporary(stagedPath, execution.stagedDeletion, error, "staged deletion");
814
+ }
815
+ throw error;
816
+ }
817
+ }
818
+ async function applyFileMutation(execution, executions, options) {
819
+ const { mutation } = execution;
820
+ if (mutation.finalContent === null) {
821
+ await stageAndRemoveFile(mutation, execution, options, () => assertAppliedTransactionSnapshots(executions));
822
+ return;
823
+ }
824
+ const appliedSnapshot = await atomicReplaceFile(mutation, mutation.snapshot, Buffer.from(mutation.finalContent, "utf-8"), options, "write", (ownership) => {
825
+ execution.renamedOwnership = ownership;
826
+ execution.phase = "destructive";
827
+ }, () => assertAppliedTransactionSnapshots(executions));
828
+ execution.appliedSnapshot = appliedSnapshot;
829
+ execution.renamedOwnership = undefined;
830
+ execution.phase = "verified";
831
+ }
832
+ function mutationStage(kind) {
833
+ switch (kind) {
834
+ case "hooks":
835
+ return "before-hooks-commit";
836
+ case "shim":
837
+ return "before-shim-removal";
838
+ case "config":
839
+ return "before-config-commit";
840
+ }
841
+ }
842
+ async function captureRollbackOwnedSnapshot(execution) {
843
+ if (execution.appliedSnapshot) {
844
+ await assertSnapshotCurrent(execution.appliedSnapshot);
845
+ return execution.appliedSnapshot;
846
+ }
847
+ if (execution.renamedOwnership) {
848
+ return captureRenamedDestinationOwnership(execution.renamedOwnership);
849
+ }
850
+ throw new Error(`Refusing stale rollback for ${execution.mutation.snapshot.path}: the mutation did not produce a verifiable state.`);
851
+ }
852
+ async function restoreFileSnapshot(execution, options, assertRollbackState) {
853
+ const { mutation } = execution;
854
+ const appliedSnapshot = await captureRollbackOwnedSnapshot(execution);
855
+ if (execution.stagedDeletion && !execution.stagedDeletionCleaned) {
856
+ await assertSnapshotCurrent(execution.stagedDeletion);
857
+ }
858
+ if (mutation.snapshot.bytes === null) {
859
+ await options.transactionFailureInjector?.("before-rollback");
860
+ await options.transactionFailureInjector?.("before-rollback-remove");
861
+ await assertRollbackState();
862
+ await assertControlledTopologyCurrent(mutation.snapshot.topology);
863
+ await assertSnapshotCurrent(appliedSnapshot);
864
+ await options.transactionFailureInjector?.("after-final-restore-validation");
865
+ const claimPath = transactionClaimPath(mutation.snapshot.path);
866
+ await rename(mutation.snapshot.path, claimPath);
867
+ execution.appliedSnapshot = {
868
+ path: mutation.snapshot.path,
869
+ content: null,
870
+ bytes: null,
871
+ mode: null,
872
+ identity: null,
873
+ topology: mutation.snapshot.topology,
874
+ };
875
+ execution.renamedOwnership = undefined;
876
+ try {
877
+ await assertSnapshotAtPath(claimPath, appliedSnapshot, "rollback removal claim");
878
+ }
879
+ catch (error) {
880
+ try {
881
+ await restoreUninstallClaim(claimPath, mutation.snapshot.path);
882
+ }
883
+ catch (recoveryError) {
884
+ throw new Error(`Uninstall rollback removal claim failed (${error instanceof Error ? error.message : String(error)}) and preserved ${claimPath} for manual recovery: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`);
885
+ }
886
+ throw error;
887
+ }
888
+ await rm(claimPath);
889
+ const absent = await captureCurrentSnapshot(mutation.snapshot);
890
+ if (absent.bytes !== null) {
891
+ throw new Error(`Uninstall rollback mismatch for ${mutation.snapshot.path}: expected absence.`);
892
+ }
893
+ return;
894
+ }
895
+ const restored = await atomicReplaceFile(mutation, appliedSnapshot, mutation.snapshot.bytes, options, "rollback", (ownership) => {
896
+ execution.renamedOwnership = ownership;
897
+ }, assertRollbackState);
898
+ execution.appliedSnapshot = restored;
899
+ execution.renamedOwnership = undefined;
900
+ await assertSnapshotMatchesPlannedContent(restored, mutation.snapshot, "rollback");
901
+ }
902
+ async function cleanupStagedDeletions(executions, options, stage, transaction, assertRollbackState) {
903
+ for (const execution of executions) {
904
+ if (!execution.stagedDeletion || execution.stagedDeletionCleaned)
905
+ continue;
906
+ if (stage === "rollback") {
907
+ await options.transactionFailureInjector?.("before-rollback-remove");
908
+ }
909
+ await options.transactionFailureInjector?.("before-staged-cleanup");
910
+ if (transaction) {
911
+ await assertUnmutatedTransactionPreconditions(transaction, executions);
912
+ await assertAppliedTransactionSnapshots(executions);
913
+ }
914
+ await assertRollbackState?.();
915
+ const stagedDeletion = execution.stagedDeletion;
916
+ await assertSnapshotCurrent(stagedDeletion);
917
+ const claimPath = transactionClaimPath(stagedDeletion.path);
918
+ await rename(stagedDeletion.path, claimPath);
919
+ try {
920
+ await assertSnapshotAtPath(claimPath, stagedDeletion, "staged deletion cleanup claim");
921
+ }
922
+ catch (error) {
923
+ try {
924
+ await restoreUninstallClaim(claimPath, stagedDeletion.path);
925
+ }
926
+ catch (recoveryError) {
927
+ throw new Error(`Uninstall staged deletion cleanup claim failed (${error instanceof Error ? error.message : String(error)}) and preserved ${claimPath} for manual recovery: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`);
928
+ }
929
+ throw error;
930
+ }
931
+ await rm(claimPath);
932
+ execution.stagedDeletionCleaned = true;
933
+ await assertRollbackState?.();
934
+ }
935
+ }
936
+ async function assertRollbackTransactionState(executions) {
937
+ for (const execution of executions) {
938
+ if (execution.phase === "prepared")
939
+ continue;
940
+ if (execution.stagedDeletion && !execution.stagedDeletionCleaned) {
941
+ await assertSnapshotCurrent(execution.stagedDeletion);
942
+ }
943
+ await captureRollbackOwnedSnapshot(execution);
944
+ }
945
+ }
946
+ async function rollbackArtifactMutations(executions, options) {
947
+ const failures = [];
948
+ const restored = [];
949
+ try {
950
+ await assertRollbackTransactionState(executions);
951
+ }
952
+ catch (error) {
953
+ failures.push(`recovery preflight: ${String(error)}`);
954
+ }
955
+ if (failures.length === 0) {
956
+ for (const execution of [...executions].reverse()) {
957
+ if (execution.phase === "prepared")
958
+ continue;
959
+ try {
960
+ await assertRollbackTransactionState(executions);
961
+ await restoreFileSnapshot(execution, options, () => assertRollbackTransactionState(executions));
962
+ restored.push(execution);
963
+ await assertRollbackTransactionState(executions);
964
+ }
965
+ catch (error) {
966
+ failures.push(`${execution.mutation.kind}: ${String(error)}`);
967
+ }
968
+ }
969
+ }
970
+ if (failures.length === 0) {
971
+ try {
972
+ await assertRollbackTransactionState(executions);
973
+ await cleanupStagedDeletions(restored, options, "rollback", undefined, () => assertRollbackTransactionState(executions));
974
+ await assertRollbackTransactionState(executions);
975
+ }
976
+ catch (error) {
977
+ failures.push(`staged deletion cleanup: ${String(error)}`);
978
+ }
979
+ }
980
+ if (failures.length > 0) {
981
+ throw new Error(`Uninstall artifact rollback failed; manual recovery is required: ${failures.join("; ")}`);
982
+ }
983
+ }
984
+ async function assertUnmutatedTransactionPreconditions(transaction, executions) {
985
+ const mutatedPaths = new Set(executions
986
+ .filter((execution) => execution.phase !== "prepared")
987
+ .map((execution) => execution.mutation.snapshot.path));
988
+ await assertSnapshotsCurrent(transaction.preconditions.filter((snapshot) => !mutatedPaths.has(snapshot.path)));
989
+ }
990
+ async function assertAppliedTransactionSnapshots(executions) {
991
+ for (const execution of executions) {
992
+ if (execution.phase === "prepared")
993
+ continue;
994
+ if (!execution.appliedSnapshot) {
995
+ throw new Error(`Refusing uninstall because ${execution.mutation.snapshot.path} did not register an applied snapshot.`);
996
+ }
997
+ await assertSnapshotCurrent(execution.appliedSnapshot);
998
+ }
999
+ }
1000
+ async function commitUninstallArtifactTransaction(transaction, options) {
1001
+ const mutations = [transaction.hooks, transaction.shim, transaction.config]
1002
+ .filter((mutation) => mutation !== undefined);
1003
+ for (const mutation of mutations) {
1004
+ if (mutation.finalContent !== null)
1005
+ mutation.validate?.(mutation.finalContent);
1006
+ }
1007
+ await assertSnapshotsCurrent(transaction.preconditions);
1008
+ if (mutations.length === 0)
1009
+ return;
1010
+ const executions = [];
1011
+ let stagedCleanupStarted = false;
1012
+ try {
1013
+ for (const mutation of mutations) {
1014
+ await options.transactionFailureInjector?.(mutationStage(mutation.kind));
1015
+ await assertUnmutatedTransactionPreconditions(transaction, executions);
1016
+ await assertAppliedTransactionSnapshots(executions);
1017
+ const execution = { mutation, phase: "prepared" };
1018
+ executions.push(execution);
1019
+ await applyFileMutation(execution, executions, options);
1020
+ if (mutation.kind === "config") {
1021
+ await options.transactionFailureInjector?.("after-config-commit");
1022
+ }
1023
+ await assertUnmutatedTransactionPreconditions(transaction, executions);
1024
+ await assertAppliedTransactionSnapshots(executions);
1025
+ }
1026
+ await assertUnmutatedTransactionPreconditions(transaction, executions);
1027
+ await assertAppliedTransactionSnapshots(executions);
1028
+ stagedCleanupStarted = true;
1029
+ await cleanupStagedDeletions(executions, options, "commit", transaction);
1030
+ await options.transactionFailureInjector?.("after-staged-cleanup");
1031
+ await assertUnmutatedTransactionPreconditions(transaction, executions);
1032
+ await assertAppliedTransactionSnapshots(executions);
1033
+ }
1034
+ catch (error) {
1035
+ if (stagedCleanupStarted &&
1036
+ executions.some((execution) => execution.stagedDeletionCleaned)) {
1037
+ throw new Error(`Uninstall artifact transaction committed but staged deletion cleanup failed during finalization: ${String(error)}`);
1038
+ }
1039
+ try {
1040
+ await rollbackArtifactMutations(executions, options);
1041
+ }
1042
+ catch (rollbackError) {
1043
+ throw new Error(`Uninstall artifact transaction failed (${String(error)}); ${String(rollbackError)}`);
1044
+ }
1045
+ throw error;
280
1046
  }
281
- return true;
282
1047
  }
283
1048
  async function removeCacheDirectory(projectRoot, options) {
284
1049
  const omxDir = join(projectRoot, ".omx");
@@ -329,10 +1094,10 @@ function printSummary(summary, dryRun) {
329
1094
  console.log(" Top-level keys (notify, model_reasoning_effort, developer_instructions)");
330
1095
  }
331
1096
  if (summary.featureFlagsRemoved) {
332
- console.log(" Feature flags (multi_agent, child_agents_md, goals; hooks preserved when user hooks remain)");
1097
+ console.log(" Feature flags (child_agents_md, goals; multi_agent and hooks are preserved when user-owned)");
333
1098
  }
334
1099
  }
335
- else if (!summary.configCleaned && summary.mcpServersRemoved.length === 0) {
1100
+ else if (summary.mcpServersRemoved.length === 0) {
336
1101
  console.log(" config.toml: no OMX entries found (or --keep-config used)");
337
1102
  }
338
1103
  if (summary.hooksFileRemoved) {
@@ -374,6 +1139,73 @@ export async function uninstall(options = {}) {
374
1139
  // Resolve scope (explicit --scope overrides persisted scope)
375
1140
  const scope = options.scope ?? readPersistedSetupScope(projectRoot) ?? "user";
376
1141
  const scopeDirs = resolveScopeDirectories(scope, projectRoot);
1142
+ if (!dryRun) {
1143
+ await recoverNativeHookClaimJournal(scopeDirs.codexHomeDir);
1144
+ }
1145
+ const transactionPlatform = options.transactionPlatform ?? process.platform;
1146
+ // Precompute and validate every artifact before the first uninstall write.
1147
+ const hooksSnapshot = await readFileSnapshot(scopeDirs.codexHooksFile, {
1148
+ controlledRoot: scopeDirs.codexHomeDir,
1149
+ });
1150
+ const configSnapshot = await readFileSnapshot(scopeDirs.codexConfigFile, {
1151
+ controlledRoot: scopeDirs.codexHomeDir,
1152
+ });
1153
+ const hooksRemoval = await planHooksRemoval(hooksSnapshot, pkgRoot, transactionPlatform, scopeDirs.codexHomeDir);
1154
+ const notifyMetadata = keepConfig
1155
+ ? undefined
1156
+ : await planNotifyMetadata(configSnapshot, scopeDirs.codexHomeDir);
1157
+ const preserveHooksFeatureFlag = hooksRemoval.plan?.hasForeignHooks ?? false;
1158
+ const configCleanup = keepConfig
1159
+ ? undefined
1160
+ : await planConfigCleanup(configSnapshot, {
1161
+ preserveHooksFeatureFlag,
1162
+ priorHookTrustState: hooksRemoval.plan?.priorTrustState,
1163
+ finalHookTrustState: hooksRemoval.plan?.finalTrustState,
1164
+ notifyMetadata,
1165
+ codexFeaturesProbe: options.codexFeaturesProbe,
1166
+ codexVersionProbe: options.codexVersionProbe,
1167
+ });
1168
+ const artifactTransaction = {
1169
+ preconditions: [
1170
+ hooksRemoval.hooks,
1171
+ ...(hooksRemoval.shim
1172
+ ? [hooksRemoval.shim]
1173
+ : hooksRemoval.preservedShimPrecondition
1174
+ ? [hooksRemoval.preservedShimPrecondition]
1175
+ : []),
1176
+ configSnapshot,
1177
+ ...(notifyMetadata ? [notifyMetadata.snapshot] : []),
1178
+ ],
1179
+ ...(hooksRemoval.plan?.changed
1180
+ ? {
1181
+ hooks: {
1182
+ kind: "hooks",
1183
+ snapshot: hooksRemoval.hooks,
1184
+ finalContent: hooksRemoval.plan.finalContent,
1185
+ validate: assertValidHooksJson,
1186
+ },
1187
+ }
1188
+ : {}),
1189
+ ...(hooksRemoval.shim !== undefined && hooksRemoval.shim.bytes !== null
1190
+ ? {
1191
+ shim: {
1192
+ kind: "shim",
1193
+ snapshot: hooksRemoval.shim,
1194
+ finalContent: null,
1195
+ },
1196
+ }
1197
+ : {}),
1198
+ ...(configCleanup?.result.configCleaned && configCleanup.finalContent !== null
1199
+ ? {
1200
+ config: {
1201
+ kind: "config",
1202
+ snapshot: configCleanup.config,
1203
+ finalContent: configCleanup.finalContent,
1204
+ validate: assertValidToml,
1205
+ },
1206
+ }
1207
+ : {}),
1208
+ };
377
1209
  console.log("oh-my-codex uninstall");
378
1210
  console.log("=====================\n");
379
1211
  if (dryRun) {
@@ -396,31 +1228,47 @@ export async function uninstall(options = {}) {
396
1228
  legacySkillRootWarning: null,
397
1229
  };
398
1230
  summary.legacySkillRootWarning = await detectLegacySkillRootWarning(scope);
399
- const preserveHooksFeatureFlag = await shouldPreserveHooksFeatureFlag(scopeDirs.codexHooksFile);
400
- // Step 1: Clean config.toml
401
- if (keepConfig) {
402
- console.log("[1/5] Skipping config.toml cleanup (--keep-config).");
403
- }
404
- else {
405
- console.log("[1/5] Cleaning config.toml...");
406
- const configResult = await cleanConfig(scopeDirs.codexConfigFile, {
407
- dryRun,
408
- verbose,
409
- preserveHooksFeatureFlag,
410
- codexFeaturesProbe: options.codexFeaturesProbe,
411
- codexVersionProbe: options.codexVersionProbe,
1231
+ summary.hooksFileRemoved =
1232
+ artifactTransaction.hooks !== undefined || artifactTransaction.shim !== undefined;
1233
+ if (configCleanup)
1234
+ Object.assign(summary, configCleanup.result);
1235
+ // Hooks, proof-owned shim, and config are one compensating transaction. The
1236
+ // config mutation is intentionally last so hooks never reference unwritten trust.
1237
+ console.log("[1/6] Removing native hooks artifact...");
1238
+ if (!keepConfig)
1239
+ console.log("[2/6] Cleaning config.toml...");
1240
+ if (!dryRun) {
1241
+ await commitUninstallArtifactTransaction(artifactTransaction, {
1242
+ transactionFailureInjector: options.transactionFailureInjector,
1243
+ transactionTemporaryPath: options.transactionTemporaryPath,
412
1244
  });
413
- Object.assign(summary, configResult);
414
1245
  }
415
- console.log();
416
- // Step 2: Remove installed prompts
417
- console.log("[2/6] Removing native hooks artifact...");
418
- summary.hooksFileRemoved = await removeHooksFile(scopeDirs.codexHooksFile, {
419
- dryRun,
420
- verbose,
421
- });
1246
+ if (verbose) {
1247
+ if (artifactTransaction.hooks) {
1248
+ console.log(` ${dryRun ? "Would clean" : artifactTransaction.hooks.finalContent === null ? "Removed" : "Cleaned"} ${basename(scopeDirs.codexHooksFile)}`);
1249
+ }
1250
+ if (artifactTransaction.shim) {
1251
+ console.log(` ${dryRun ? "Would remove" : "Removed"} ${basename(artifactTransaction.shim.snapshot.path)}`);
1252
+ }
1253
+ }
422
1254
  console.log(` ${dryRun ? "Would clean" : "Cleaned"} ${summary.hooksFileRemoved ? 1 : 0} hooks artifact(s).`);
423
1255
  console.log();
1256
+ // Step 2: config cleanup is calculated before Step 1 and committed last.
1257
+ if (keepConfig) {
1258
+ console.log("[2/6] Skipping config.toml cleanup (--keep-config).");
1259
+ }
1260
+ else if (verbose) {
1261
+ if (configCleanup?.config.content === null) {
1262
+ console.log(" config.toml not found, skipping.");
1263
+ }
1264
+ else if (configCleanup?.result.configCleaned) {
1265
+ console.log(` ${dryRun ? "Would clean" : "Cleaned"} ${scopeDirs.codexConfigFile}`);
1266
+ }
1267
+ else {
1268
+ console.log(" No OMX config entries found.");
1269
+ }
1270
+ }
1271
+ console.log();
424
1272
  // Step 3: Remove installed prompts
425
1273
  console.log("[3/6] Removing agent prompts...");
426
1274
  summary.promptsRemoved = await removeInstalledPrompts(scopeDirs.promptsDir, pkgRoot, { dryRun, verbose });