oh-my-copilot 4.13.2 → 4.13.45

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 (445) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/README.md +9 -1
  4. package/agents/code-reviewer.agent.md +24 -6
  5. package/agents/designer.agent.md +12 -0
  6. package/bridge/cli.cjs +4069 -1732
  7. package/bridge/mcp-server.cjs +774 -269
  8. package/bridge/runtime-cli.cjs +1311 -141
  9. package/bridge/team.js +1778 -133
  10. package/dist/__tests__/agent-registry.test.js +92 -1
  11. package/dist/__tests__/agent-registry.test.js.map +1 -1
  12. package/dist/__tests__/auto-slash-aliases.test.js +91 -0
  13. package/dist/__tests__/auto-slash-aliases.test.js.map +1 -1
  14. package/dist/__tests__/bedrock-model-routing.test.js +18 -17
  15. package/dist/__tests__/bedrock-model-routing.test.js.map +1 -1
  16. package/dist/__tests__/delegation-enforcer.test.js +46 -6
  17. package/dist/__tests__/delegation-enforcer.test.js.map +1 -1
  18. package/dist/__tests__/hooks/session-end-cleanup.test.d.ts +2 -0
  19. package/dist/__tests__/hooks/session-end-cleanup.test.d.ts.map +1 -0
  20. package/dist/__tests__/hooks/session-end-cleanup.test.js +93 -0
  21. package/dist/__tests__/hooks/session-end-cleanup.test.js.map +1 -0
  22. package/dist/__tests__/hud/labels.test.d.ts +2 -0
  23. package/dist/__tests__/hud/labels.test.d.ts.map +1 -0
  24. package/dist/__tests__/hud/labels.test.js +158 -0
  25. package/dist/__tests__/hud/labels.test.js.map +1 -0
  26. package/dist/__tests__/hud/render-rate-limits-priority.test.js +26 -0
  27. package/dist/__tests__/hud/render-rate-limits-priority.test.js.map +1 -1
  28. package/dist/__tests__/hud/stdin.test.d.ts +2 -0
  29. package/dist/__tests__/hud/stdin.test.d.ts.map +1 -0
  30. package/dist/__tests__/hud/stdin.test.js +556 -0
  31. package/dist/__tests__/hud/stdin.test.js.map +1 -0
  32. package/dist/__tests__/hud-marketplace-resolution.test.js +34 -0
  33. package/dist/__tests__/hud-marketplace-resolution.test.js.map +1 -1
  34. package/dist/__tests__/installer-hud-skip.test.js +6 -0
  35. package/dist/__tests__/installer-hud-skip.test.js.map +1 -1
  36. package/dist/__tests__/installer-omc-reference.test.js +1 -1
  37. package/dist/__tests__/installer-omc-reference.test.js.map +1 -1
  38. package/dist/__tests__/mnemosyne/detector.test.js +2 -0
  39. package/dist/__tests__/mnemosyne/detector.test.js.map +1 -1
  40. package/dist/__tests__/model-routing-override-three-site-sync.test.d.ts +2 -0
  41. package/dist/__tests__/model-routing-override-three-site-sync.test.d.ts.map +1 -0
  42. package/dist/__tests__/model-routing-override-three-site-sync.test.js +75 -0
  43. package/dist/__tests__/model-routing-override-three-site-sync.test.js.map +1 -0
  44. package/dist/__tests__/non-claude-provider-detection.test.js +37 -0
  45. package/dist/__tests__/non-claude-provider-detection.test.js.map +1 -1
  46. package/dist/__tests__/notepad.test.js +2 -2
  47. package/dist/__tests__/notepad.test.js.map +1 -1
  48. package/dist/__tests__/package-dir-resolution-regression.test.js +25 -0
  49. package/dist/__tests__/package-dir-resolution-regression.test.js.map +1 -1
  50. package/dist/__tests__/pre-tool-enforcer.test.js +135 -1
  51. package/dist/__tests__/pre-tool-enforcer.test.js.map +1 -1
  52. package/dist/__tests__/ralph-prd-mandatory.test.js +11 -1
  53. package/dist/__tests__/ralph-prd-mandatory.test.js.map +1 -1
  54. package/dist/__tests__/ralph-prd.test.js +40 -2
  55. package/dist/__tests__/ralph-prd.test.js.map +1 -1
  56. package/dist/__tests__/session-start-script-context.test.js +121 -0
  57. package/dist/__tests__/session-start-script-context.test.js.map +1 -1
  58. package/dist/__tests__/setup-claude-md-script.test.js +44 -1
  59. package/dist/__tests__/setup-claude-md-script.test.js.map +1 -1
  60. package/dist/__tests__/skills.test.js +363 -4
  61. package/dist/__tests__/skills.test.js.map +1 -1
  62. package/dist/__tests__/state-root-resolution.test.js +56 -6
  63. package/dist/__tests__/state-root-resolution.test.js.map +1 -1
  64. package/dist/agents/definitions.d.ts.map +1 -1
  65. package/dist/agents/definitions.js +2 -1
  66. package/dist/agents/definitions.js.map +1 -1
  67. package/dist/autoresearch/__tests__/decide-outcome.test.d.ts +2 -0
  68. package/dist/autoresearch/__tests__/decide-outcome.test.d.ts.map +1 -0
  69. package/dist/autoresearch/__tests__/decide-outcome.test.js +69 -0
  70. package/dist/autoresearch/__tests__/decide-outcome.test.js.map +1 -0
  71. package/dist/autoresearch/__tests__/runtime.test.js +225 -28
  72. package/dist/autoresearch/__tests__/runtime.test.js.map +1 -1
  73. package/dist/autoresearch/runtime.d.ts.map +1 -1
  74. package/dist/autoresearch/runtime.js +25 -7
  75. package/dist/autoresearch/runtime.js.map +1 -1
  76. package/dist/cli/__tests__/launch.test.js +23 -0
  77. package/dist/cli/__tests__/launch.test.js.map +1 -1
  78. package/dist/cli/__tests__/self-improve-paths.test.js +3 -2
  79. package/dist/cli/__tests__/self-improve-paths.test.js.map +1 -1
  80. package/dist/cli/__tests__/team.test.js +100 -0
  81. package/dist/cli/__tests__/team.test.js.map +1 -1
  82. package/dist/cli/autoresearch.d.ts +1 -1
  83. package/dist/cli/autoresearch.d.ts.map +1 -1
  84. package/dist/cli/autoresearch.js +4 -4
  85. package/dist/cli/commands/__tests__/team-role-shorthand.test.js +30 -0
  86. package/dist/cli/commands/__tests__/team-role-shorthand.test.js.map +1 -1
  87. package/dist/cli/commands/__tests__/team.test.js +48 -1
  88. package/dist/cli/commands/__tests__/team.test.js.map +1 -1
  89. package/dist/cli/commands/team.d.ts +3 -0
  90. package/dist/cli/commands/team.d.ts.map +1 -1
  91. package/dist/cli/commands/team.js +23 -4
  92. package/dist/cli/commands/team.js.map +1 -1
  93. package/dist/cli/index.js +3 -0
  94. package/dist/cli/index.js.map +1 -1
  95. package/dist/cli/launch.d.ts.map +1 -1
  96. package/dist/cli/launch.js +7 -0
  97. package/dist/cli/launch.js.map +1 -1
  98. package/dist/cli/team.d.ts +6 -0
  99. package/dist/cli/team.d.ts.map +1 -1
  100. package/dist/cli/team.js +57 -4
  101. package/dist/cli/team.js.map +1 -1
  102. package/dist/config/__tests__/loader.test.js +35 -4
  103. package/dist/config/__tests__/loader.test.js.map +1 -1
  104. package/dist/config/__tests__/models.test.js +126 -3
  105. package/dist/config/__tests__/models.test.js.map +1 -1
  106. package/dist/config/models.d.ts +8 -0
  107. package/dist/config/models.d.ts.map +1 -1
  108. package/dist/config/models.js +119 -8
  109. package/dist/config/models.js.map +1 -1
  110. package/dist/features/boulder-state/constants.d.ts +1 -1
  111. package/dist/features/boulder-state/constants.d.ts.map +1 -1
  112. package/dist/features/builtin-skills/skills.d.ts.map +1 -1
  113. package/dist/features/builtin-skills/skills.js +11 -3
  114. package/dist/features/builtin-skills/skills.js.map +1 -1
  115. package/dist/features/builtin-skills/types.d.ts +7 -0
  116. package/dist/features/builtin-skills/types.d.ts.map +1 -1
  117. package/dist/features/delegation-enforcer.d.ts.map +1 -1
  118. package/dist/features/delegation-enforcer.js +10 -9
  119. package/dist/features/delegation-enforcer.js.map +1 -1
  120. package/dist/features/magic-keywords.d.ts.map +1 -1
  121. package/dist/features/magic-keywords.js +30 -1
  122. package/dist/features/magic-keywords.js.map +1 -1
  123. package/dist/features/rate-limit-wait/tmux-detector.d.ts +4 -4
  124. package/dist/features/rate-limit-wait/tmux-detector.js +9 -9
  125. package/dist/features/rate-limit-wait/tmux-detector.js.map +1 -1
  126. package/dist/hooks/__tests__/bridge-routing.test.js +157 -0
  127. package/dist/hooks/__tests__/bridge-routing.test.js.map +1 -1
  128. package/dist/hooks/auto-slash-command/constants.d.ts.map +1 -1
  129. package/dist/hooks/auto-slash-command/constants.js +1 -0
  130. package/dist/hooks/auto-slash-command/constants.js.map +1 -1
  131. package/dist/hooks/auto-slash-command/executor.d.ts.map +1 -1
  132. package/dist/hooks/auto-slash-command/executor.js +29 -0
  133. package/dist/hooks/auto-slash-command/executor.js.map +1 -1
  134. package/dist/hooks/autopilot/enforcement.d.ts.map +1 -1
  135. package/dist/hooks/autopilot/enforcement.js +19 -0
  136. package/dist/hooks/autopilot/enforcement.js.map +1 -1
  137. package/dist/hooks/bridge.d.ts.map +1 -1
  138. package/dist/hooks/bridge.js +210 -5
  139. package/dist/hooks/bridge.js.map +1 -1
  140. package/dist/hooks/learner/detector.js +1 -1
  141. package/dist/hooks/mode-registry/__tests__/session-isolation.test.js +16 -0
  142. package/dist/hooks/mode-registry/__tests__/session-isolation.test.js.map +1 -1
  143. package/dist/hooks/notepad/index.d.ts +4 -1
  144. package/dist/hooks/notepad/index.d.ts.map +1 -1
  145. package/dist/hooks/notepad/index.js +7 -4
  146. package/dist/hooks/notepad/index.js.map +1 -1
  147. package/dist/hooks/persistent-mode/__tests__/ralph-verification-flow.test.js +70 -3
  148. package/dist/hooks/persistent-mode/__tests__/ralph-verification-flow.test.js.map +1 -1
  149. package/dist/hooks/persistent-mode/index.d.ts.map +1 -1
  150. package/dist/hooks/persistent-mode/index.js +10 -9
  151. package/dist/hooks/persistent-mode/index.js.map +1 -1
  152. package/dist/hooks/persistent-mode/stop-hook-blocking.test.js +101 -10
  153. package/dist/hooks/persistent-mode/stop-hook-blocking.test.js.map +1 -1
  154. package/dist/hooks/project-memory/__tests__/integration.test.js +117 -3
  155. package/dist/hooks/project-memory/__tests__/integration.test.js.map +1 -1
  156. package/dist/hooks/project-memory/__tests__/storage.test.js +11 -11
  157. package/dist/hooks/project-memory/__tests__/storage.test.js.map +1 -1
  158. package/dist/hooks/project-memory/index.d.ts.map +1 -1
  159. package/dist/hooks/project-memory/index.js +24 -12
  160. package/dist/hooks/project-memory/index.js.map +1 -1
  161. package/dist/hooks/ralph/index.d.ts +1 -1
  162. package/dist/hooks/ralph/index.d.ts.map +1 -1
  163. package/dist/hooks/ralph/index.js +1 -1
  164. package/dist/hooks/ralph/index.js.map +1 -1
  165. package/dist/hooks/ralph/loop.d.ts +6 -6
  166. package/dist/hooks/ralph/loop.d.ts.map +1 -1
  167. package/dist/hooks/ralph/loop.js +18 -18
  168. package/dist/hooks/ralph/loop.js.map +1 -1
  169. package/dist/hooks/ralph/prd.d.ts +23 -12
  170. package/dist/hooks/ralph/prd.d.ts.map +1 -1
  171. package/dist/hooks/ralph/prd.js +88 -42
  172. package/dist/hooks/ralph/prd.js.map +1 -1
  173. package/dist/hooks/session-end/__tests__/mode-state-cleanup.test.js +20 -0
  174. package/dist/hooks/session-end/__tests__/mode-state-cleanup.test.js.map +1 -1
  175. package/dist/hooks/session-end/index.d.ts +18 -2
  176. package/dist/hooks/session-end/index.d.ts.map +1 -1
  177. package/dist/hooks/session-end/index.js +157 -35
  178. package/dist/hooks/session-end/index.js.map +1 -1
  179. package/dist/hooks/skill-bridge.cjs +6 -5
  180. package/dist/hooks/skill-state/index.d.ts.map +1 -1
  181. package/dist/hooks/skill-state/index.js +1 -0
  182. package/dist/hooks/skill-state/index.js.map +1 -1
  183. package/dist/hud/__tests__/git-status.test.js +18 -0
  184. package/dist/hud/__tests__/git-status.test.js.map +1 -1
  185. package/dist/hud/elements/background.d.ts +3 -3
  186. package/dist/hud/elements/background.d.ts.map +1 -1
  187. package/dist/hud/elements/background.js +5 -4
  188. package/dist/hud/elements/background.js.map +1 -1
  189. package/dist/hud/elements/call-counts.d.ts +2 -2
  190. package/dist/hud/elements/call-counts.d.ts.map +1 -1
  191. package/dist/hud/elements/call-counts.js +7 -6
  192. package/dist/hud/elements/call-counts.js.map +1 -1
  193. package/dist/hud/elements/context.d.ts +3 -3
  194. package/dist/hud/elements/context.d.ts.map +1 -1
  195. package/dist/hud/elements/context.js +5 -4
  196. package/dist/hud/elements/context.js.map +1 -1
  197. package/dist/hud/elements/git.d.ts +2 -1
  198. package/dist/hud/elements/git.d.ts.map +1 -1
  199. package/dist/hud/elements/git.js +7 -6
  200. package/dist/hud/elements/git.js.map +1 -1
  201. package/dist/hud/elements/ralph.d.ts +2 -2
  202. package/dist/hud/elements/ralph.d.ts.map +1 -1
  203. package/dist/hud/elements/ralph.js +3 -2
  204. package/dist/hud/elements/ralph.js.map +1 -1
  205. package/dist/hud/elements/thinking.d.ts +2 -2
  206. package/dist/hud/elements/thinking.d.ts.map +1 -1
  207. package/dist/hud/elements/thinking.js +3 -2
  208. package/dist/hud/elements/thinking.js.map +1 -1
  209. package/dist/hud/elements/token-usage.d.ts +2 -2
  210. package/dist/hud/elements/token-usage.d.ts.map +1 -1
  211. package/dist/hud/elements/token-usage.js +3 -2
  212. package/dist/hud/elements/token-usage.js.map +1 -1
  213. package/dist/hud/render.d.ts.map +1 -1
  214. package/dist/hud/render.js +11 -10
  215. package/dist/hud/render.js.map +1 -1
  216. package/dist/hud/state.d.ts.map +1 -1
  217. package/dist/hud/state.js +18 -1
  218. package/dist/hud/state.js.map +1 -1
  219. package/dist/hud/stdin.d.ts +12 -1
  220. package/dist/hud/stdin.d.ts.map +1 -1
  221. package/dist/hud/stdin.js +123 -18
  222. package/dist/hud/stdin.js.map +1 -1
  223. package/dist/hud/types.d.ts +27 -0
  224. package/dist/hud/types.d.ts.map +1 -1
  225. package/dist/hud/types.js +58 -0
  226. package/dist/hud/types.js.map +1 -1
  227. package/dist/installer/__tests__/hud-cache-wrapper.test.d.ts +2 -0
  228. package/dist/installer/__tests__/hud-cache-wrapper.test.d.ts.map +1 -0
  229. package/dist/installer/__tests__/hud-cache-wrapper.test.js +235 -0
  230. package/dist/installer/__tests__/hud-cache-wrapper.test.js.map +1 -0
  231. package/dist/installer/__tests__/session-start-template.test.d.ts +2 -0
  232. package/dist/installer/__tests__/session-start-template.test.d.ts.map +1 -0
  233. package/dist/installer/__tests__/session-start-template.test.js +174 -0
  234. package/dist/installer/__tests__/session-start-template.test.js.map +1 -0
  235. package/dist/installer/__tests__/standalone-hook-reconcile.test.js +2 -0
  236. package/dist/installer/__tests__/standalone-hook-reconcile.test.js.map +1 -1
  237. package/dist/installer/index.d.ts.map +1 -1
  238. package/dist/installer/index.js +19 -7
  239. package/dist/installer/index.js.map +1 -1
  240. package/dist/lib/__tests__/mode-state-io.test.js +75 -12
  241. package/dist/lib/__tests__/mode-state-io.test.js.map +1 -1
  242. package/dist/lib/__tests__/worktree-paths.test.js +162 -39
  243. package/dist/lib/__tests__/worktree-paths.test.js.map +1 -1
  244. package/dist/lib/mode-state-io.d.ts +11 -0
  245. package/dist/lib/mode-state-io.d.ts.map +1 -1
  246. package/dist/lib/mode-state-io.js +64 -0
  247. package/dist/lib/mode-state-io.js.map +1 -1
  248. package/dist/lib/worktree-paths.d.ts +99 -9
  249. package/dist/lib/worktree-paths.d.ts.map +1 -1
  250. package/dist/lib/worktree-paths.js +284 -27
  251. package/dist/lib/worktree-paths.js.map +1 -1
  252. package/dist/planning/__tests__/artifacts.test.d.ts +2 -0
  253. package/dist/planning/__tests__/artifacts.test.d.ts.map +1 -0
  254. package/dist/planning/__tests__/artifacts.test.js +486 -0
  255. package/dist/planning/__tests__/artifacts.test.js.map +1 -0
  256. package/dist/planning/artifact-names.d.ts +13 -0
  257. package/dist/planning/artifact-names.d.ts.map +1 -0
  258. package/dist/planning/artifact-names.js +108 -0
  259. package/dist/planning/artifact-names.js.map +1 -0
  260. package/dist/planning/artifacts.d.ts +47 -0
  261. package/dist/planning/artifacts.d.ts.map +1 -0
  262. package/dist/planning/artifacts.js +221 -0
  263. package/dist/planning/artifacts.js.map +1 -0
  264. package/dist/team/__tests__/api-interop.compatibility.test.js +194 -5
  265. package/dist/team/__tests__/api-interop.compatibility.test.js.map +1 -1
  266. package/dist/team/__tests__/auto-merge-restart.test.d.ts +2 -0
  267. package/dist/team/__tests__/auto-merge-restart.test.d.ts.map +1 -0
  268. package/dist/team/__tests__/auto-merge-restart.test.js +128 -0
  269. package/dist/team/__tests__/auto-merge-restart.test.js.map +1 -0
  270. package/dist/team/__tests__/auto-merge.perf.test.d.ts +2 -0
  271. package/dist/team/__tests__/auto-merge.perf.test.d.ts.map +1 -0
  272. package/dist/team/__tests__/auto-merge.perf.test.js +85 -0
  273. package/dist/team/__tests__/auto-merge.perf.test.js.map +1 -0
  274. package/dist/team/__tests__/conflict-mailbox.test.d.ts +2 -0
  275. package/dist/team/__tests__/conflict-mailbox.test.d.ts.map +1 -0
  276. package/dist/team/__tests__/conflict-mailbox.test.js +238 -0
  277. package/dist/team/__tests__/conflict-mailbox.test.js.map +1 -0
  278. package/dist/team/__tests__/helpers/git-fixture.d.ts +72 -0
  279. package/dist/team/__tests__/helpers/git-fixture.d.ts.map +1 -0
  280. package/dist/team/__tests__/helpers/git-fixture.js +252 -0
  281. package/dist/team/__tests__/helpers/git-fixture.js.map +1 -0
  282. package/dist/team/__tests__/leader-inbox.test.d.ts +2 -0
  283. package/dist/team/__tests__/leader-inbox.test.d.ts.map +1 -0
  284. package/dist/team/__tests__/leader-inbox.test.js +152 -0
  285. package/dist/team/__tests__/leader-inbox.test.js.map +1 -0
  286. package/dist/team/__tests__/merge-orchestrator.test.d.ts +2 -0
  287. package/dist/team/__tests__/merge-orchestrator.test.d.ts.map +1 -0
  288. package/dist/team/__tests__/merge-orchestrator.test.js +779 -0
  289. package/dist/team/__tests__/merge-orchestrator.test.js.map +1 -0
  290. package/dist/team/__tests__/model-contract.test.js +92 -2
  291. package/dist/team/__tests__/model-contract.test.js.map +1 -1
  292. package/dist/team/__tests__/rebase-smoke.test.d.ts +2 -0
  293. package/dist/team/__tests__/rebase-smoke.test.d.ts.map +1 -0
  294. package/dist/team/__tests__/rebase-smoke.test.js +272 -0
  295. package/dist/team/__tests__/rebase-smoke.test.js.map +1 -0
  296. package/dist/team/__tests__/runtime-cli.test.js +9 -1
  297. package/dist/team/__tests__/runtime-cli.test.js.map +1 -1
  298. package/dist/team/__tests__/runtime-v2.dispatch.test.js +180 -1
  299. package/dist/team/__tests__/runtime-v2.dispatch.test.js.map +1 -1
  300. package/dist/team/__tests__/scaling.test.js +39 -1
  301. package/dist/team/__tests__/scaling.test.js.map +1 -1
  302. package/dist/team/__tests__/teardown-invariant.test.d.ts +2 -0
  303. package/dist/team/__tests__/teardown-invariant.test.d.ts.map +1 -0
  304. package/dist/team/__tests__/teardown-invariant.test.js +176 -0
  305. package/dist/team/__tests__/teardown-invariant.test.js.map +1 -0
  306. package/dist/team/__tests__/worker-bootstrap.test.js +6 -0
  307. package/dist/team/__tests__/worker-bootstrap.test.js.map +1 -1
  308. package/dist/team/__tests__/worker-commit-cadence.test.d.ts +2 -0
  309. package/dist/team/__tests__/worker-commit-cadence.test.d.ts.map +1 -0
  310. package/dist/team/__tests__/worker-commit-cadence.test.js +315 -0
  311. package/dist/team/__tests__/worker-commit-cadence.test.js.map +1 -0
  312. package/dist/team/__tests__/worktree-runtime-e2e.test.d.ts +2 -0
  313. package/dist/team/__tests__/worktree-runtime-e2e.test.d.ts.map +1 -0
  314. package/dist/team/__tests__/worktree-runtime-e2e.test.js +182 -0
  315. package/dist/team/__tests__/worktree-runtime-e2e.test.js.map +1 -0
  316. package/dist/team/api-interop.d.ts.map +1 -1
  317. package/dist/team/api-interop.js +89 -2
  318. package/dist/team/api-interop.js.map +1 -1
  319. package/dist/team/conflict-mailbox.d.ts +49 -0
  320. package/dist/team/conflict-mailbox.d.ts.map +1 -0
  321. package/dist/team/conflict-mailbox.js +98 -0
  322. package/dist/team/conflict-mailbox.js.map +1 -0
  323. package/dist/team/delegation-evidence.d.ts +5 -0
  324. package/dist/team/delegation-evidence.d.ts.map +1 -0
  325. package/dist/team/delegation-evidence.js +29 -0
  326. package/dist/team/delegation-evidence.js.map +1 -0
  327. package/dist/team/leader-inbox.d.ts +28 -0
  328. package/dist/team/leader-inbox.d.ts.map +1 -0
  329. package/dist/team/leader-inbox.js +68 -0
  330. package/dist/team/leader-inbox.js.map +1 -0
  331. package/dist/team/merge-coordinator.d.ts +6 -0
  332. package/dist/team/merge-coordinator.d.ts.map +1 -1
  333. package/dist/team/merge-coordinator.js +6 -2
  334. package/dist/team/merge-coordinator.js.map +1 -1
  335. package/dist/team/merge-orchestrator.d.ts +41 -0
  336. package/dist/team/merge-orchestrator.d.ts.map +1 -0
  337. package/dist/team/merge-orchestrator.js +736 -0
  338. package/dist/team/merge-orchestrator.js.map +1 -0
  339. package/dist/team/model-contract.d.ts +8 -0
  340. package/dist/team/model-contract.d.ts.map +1 -1
  341. package/dist/team/model-contract.js +13 -0
  342. package/dist/team/model-contract.js.map +1 -1
  343. package/dist/team/runtime-cli.d.ts +1 -0
  344. package/dist/team/runtime-cli.d.ts.map +1 -1
  345. package/dist/team/runtime-cli.js +15 -2
  346. package/dist/team/runtime-cli.js.map +1 -1
  347. package/dist/team/runtime-flags.d.ts +5 -0
  348. package/dist/team/runtime-flags.d.ts.map +1 -0
  349. package/dist/team/runtime-flags.js +12 -0
  350. package/dist/team/runtime-flags.js.map +1 -0
  351. package/dist/team/runtime-v2.d.ts +9 -2
  352. package/dist/team/runtime-v2.d.ts.map +1 -1
  353. package/dist/team/runtime-v2.js +188 -9
  354. package/dist/team/runtime-v2.js.map +1 -1
  355. package/dist/team/state/tasks.d.ts +4 -1
  356. package/dist/team/state/tasks.d.ts.map +1 -1
  357. package/dist/team/state/tasks.js +38 -1
  358. package/dist/team/state/tasks.js.map +1 -1
  359. package/dist/team/team-ops.d.ts +4 -1
  360. package/dist/team/team-ops.d.ts.map +1 -1
  361. package/dist/team/team-ops.js +2 -2
  362. package/dist/team/team-ops.js.map +1 -1
  363. package/dist/team/types.d.ts +22 -1
  364. package/dist/team/types.d.ts.map +1 -1
  365. package/dist/team/types.js.map +1 -1
  366. package/dist/team/worker-bootstrap.d.ts +4 -0
  367. package/dist/team/worker-bootstrap.d.ts.map +1 -1
  368. package/dist/team/worker-bootstrap.js +16 -2
  369. package/dist/team/worker-bootstrap.js.map +1 -1
  370. package/dist/team/worker-commit-cadence.d.ts +70 -0
  371. package/dist/team/worker-commit-cadence.d.ts.map +1 -0
  372. package/dist/team/worker-commit-cadence.js +271 -0
  373. package/dist/team/worker-commit-cadence.js.map +1 -0
  374. package/dist/tools/__tests__/memory-tools.test.js +4 -4
  375. package/dist/tools/__tests__/memory-tools.test.js.map +1 -1
  376. package/dist/tools/__tests__/state-tools.test.js +335 -6
  377. package/dist/tools/__tests__/state-tools.test.js.map +1 -1
  378. package/dist/tools/__tests__/wiki-tools-working-directory.test.d.ts +2 -0
  379. package/dist/tools/__tests__/wiki-tools-working-directory.test.d.ts.map +1 -0
  380. package/dist/tools/__tests__/wiki-tools-working-directory.test.js +66 -0
  381. package/dist/tools/__tests__/wiki-tools-working-directory.test.js.map +1 -0
  382. package/dist/tools/state-tools.d.ts +3 -10
  383. package/dist/tools/state-tools.d.ts.map +1 -1
  384. package/dist/tools/state-tools.js +393 -91
  385. package/dist/tools/state-tools.js.map +1 -1
  386. package/dist/tools/wiki-tools.js +8 -8
  387. package/dist/tools/wiki-tools.js.map +1 -1
  388. package/docs/GETTING-STARTED.md +422 -0
  389. package/docs/MIGRATION.md +66 -66
  390. package/docs/REFERENCE.md +21 -4
  391. package/docs/company-context-interface.md +5 -16
  392. package/docs/copilot-instructions.md +1 -1
  393. package/package.json +1 -1
  394. package/scripts/lib/hud-cache-wrapper.sh +122 -0
  395. package/scripts/lib/model-routing-override-message.mjs +21 -0
  396. package/scripts/persistent-mode.cjs +36 -0
  397. package/scripts/persistent-mode.mjs +36 -0
  398. package/scripts/plugin-setup.mjs +10 -1
  399. package/scripts/post-tool-verifier.mjs +119 -5
  400. package/scripts/pre-tool-enforcer.mjs +114 -6
  401. package/scripts/session-start.mjs +234 -3
  402. package/scripts/setup-copilot-instructions.sh +12 -2
  403. package/skills/AGENTS.md +22 -91
  404. package/skills/ai-slop-cleaner/SKILL.md +118 -120
  405. package/skills/ask/SKILL.md +6 -8
  406. package/skills/autopilot/SKILL.md +1 -28
  407. package/skills/autoresearch/SKILL.md +5 -5
  408. package/skills/cancel/SKILL.md +13 -13
  409. package/skills/cccg/SKILL.md +1 -0
  410. package/skills/configure-notifications/SKILL.md +77 -212
  411. package/skills/debug/SKILL.md +3 -2
  412. package/skills/deep-dive/SKILL.md +20 -9
  413. package/skills/deep-interview/SKILL.md +32 -4
  414. package/skills/deepinit/SKILL.md +1 -0
  415. package/skills/external-context/SKILL.md +2 -1
  416. package/skills/hud/SKILL.md +22 -52
  417. package/skills/learner/SKILL.md +90 -57
  418. package/skills/omc-doctor/SKILL.md +1 -1
  419. package/skills/omc-reference/SKILL.md +6 -6
  420. package/skills/omc-setup/SKILL.md +29 -73
  421. package/skills/omc-setup/phases/01-install-claude-md.md +97 -0
  422. package/skills/omc-setup/phases/02-configure.md +25 -40
  423. package/skills/omc-setup/phases/03-integrations.md +100 -69
  424. package/skills/omc-setup/phases/04-welcome.md +104 -46
  425. package/skills/omc-teams/SKILL.md +63 -26
  426. package/skills/plan/SKILL.md +11 -9
  427. package/skills/project-session-manager/SKILL.md +2 -2
  428. package/skills/project-session-manager/psm.sh +1 -1
  429. package/skills/ralph/SKILL.md +42 -41
  430. package/skills/ralplan/SKILL.md +3 -10
  431. package/skills/release/SKILL.md +168 -57
  432. package/skills/remember/SKILL.md +2 -1
  433. package/skills/sciomc/SKILL.md +12 -11
  434. package/skills/self-improve/SKILL.md +4 -4
  435. package/skills/setup/SKILL.md +1 -0
  436. package/skills/skill/SKILL.md +21 -20
  437. package/skills/skillify/SKILL.md +34 -3
  438. package/skills/team/SKILL.md +62 -44
  439. package/skills/ultraqa/SKILL.md +1 -2
  440. package/skills/ultrawork/SKILL.md +28 -21
  441. package/skills/verify/SKILL.md +2 -1
  442. package/skills/writer-memory/SKILL.md +2 -1
  443. package/templates/hooks/lib/model-routing-override-message.mjs +21 -0
  444. package/templates/hooks/pre-tool-use.mjs +144 -45
  445. package/templates/hooks/session-start.mjs +62 -0
@@ -30779,14 +30779,15 @@ var import_os3 = require("os");
30779
30779
  var import_path11 = require("path");
30780
30780
  var OmgPaths = {
30781
30781
  ROOT: ".omcp",
30782
+ SHARED_ROOT: ".omc",
30782
30783
  STATE: ".omcp/state",
30783
30784
  SESSIONS: ".omcp/state/sessions",
30784
- PLANS: ".omcp/plans",
30785
- RESEARCH: ".omcp/research",
30786
- NOTEPAD: ".omcp/notepad.md",
30787
- PROJECT_MEMORY: ".omcp/project-memory.json",
30785
+ PLANS: ".omc/plans",
30786
+ RESEARCH: ".omc/research",
30787
+ NOTEPAD: ".omc/notepad.md",
30788
+ PROJECT_MEMORY: ".omc/project-memory.json",
30788
30789
  DRAFTS: ".omcp/drafts",
30789
- NOTEPADS: ".omcp/notepads",
30790
+ NOTEPADS: ".omc/notepads",
30790
30791
  LOGS: ".omcp/logs",
30791
30792
  SCIENTIST: ".omcp/scientist",
30792
30793
  AUTOPILOT: ".omcp/autopilot",
@@ -30893,8 +30894,95 @@ function getOmcRoot(worktreeRoot) {
30893
30894
  }
30894
30895
  const root = worktreeRoot || getWorktreeRoot() || process.cwd();
30895
30896
  migrateOmgToOmcp(root);
30897
+ migrateOmcpContentToOmc(root);
30896
30898
  return (0, import_path11.join)(root, OmgPaths.ROOT);
30897
30899
  }
30900
+ function getSharedOmcRoot(worktreeRoot) {
30901
+ const customDir = process.env.OMC_STATE_DIR;
30902
+ const root = worktreeRoot || getWorktreeRoot() || process.cwd();
30903
+ if (customDir) {
30904
+ const projectId = getProjectIdentifier(root);
30905
+ return (0, import_path11.join)(customDir, projectId, OmgPaths.SHARED_ROOT);
30906
+ }
30907
+ migrateOmcpContentToOmc(root);
30908
+ return (0, import_path11.join)(root, OmgPaths.SHARED_ROOT);
30909
+ }
30910
+ function migrateOmcpContentToOmc(worktreeRoot) {
30911
+ if (process.env.OMC_STATE_DIR) return false;
30912
+ const omcpRoot = (0, import_path11.join)(worktreeRoot, OmgPaths.ROOT);
30913
+ const omcRoot = (0, import_path11.join)(worktreeRoot, OmgPaths.SHARED_ROOT);
30914
+ if (!(0, import_fs9.existsSync)(omcpRoot)) return false;
30915
+ let moved = false;
30916
+ const fileMoves = [
30917
+ [(0, import_path11.join)(omcpRoot, "notepad.md"), (0, import_path11.join)(omcRoot, "notepad.md")],
30918
+ [(0, import_path11.join)(omcpRoot, "project-memory.json"), (0, import_path11.join)(omcRoot, "project-memory.json")]
30919
+ ];
30920
+ for (const [src, dst] of fileMoves) {
30921
+ if (!(0, import_fs9.existsSync)(src)) continue;
30922
+ if ((0, import_fs9.existsSync)(dst)) {
30923
+ const warningKey = `omcp-content:${src}`;
30924
+ if (!omcpContentWarnings.has(warningKey)) {
30925
+ omcpContentWarnings.add(warningKey);
30926
+ console.warn(
30927
+ `[omc-share] Both ${src} and ${dst} exist. Using ${dst}; remove the legacy file manually after verifying no data loss.`
30928
+ );
30929
+ }
30930
+ continue;
30931
+ }
30932
+ try {
30933
+ (0, import_fs9.mkdirSync)((0, import_path11.dirname)(dst), { recursive: true });
30934
+ (0, import_fs9.renameSync)(src, dst);
30935
+ moved = true;
30936
+ } catch (err) {
30937
+ console.warn(
30938
+ `[omc-share] Failed to relocate ${src} \u2192 ${dst}: ${err instanceof Error ? err.message : err}`
30939
+ );
30940
+ }
30941
+ }
30942
+ for (const sub of ["plans", "research", "notepads"]) {
30943
+ const srcDir = (0, import_path11.join)(omcpRoot, sub);
30944
+ if (!(0, import_fs9.existsSync)(srcDir)) continue;
30945
+ const dstDir = (0, import_path11.join)(omcRoot, sub);
30946
+ try {
30947
+ (0, import_fs9.mkdirSync)(dstDir, { recursive: true });
30948
+ } catch (err) {
30949
+ if (err.code !== "EEXIST") {
30950
+ console.warn(`[omc-share] Could not create ${dstDir}: ${err}`);
30951
+ continue;
30952
+ }
30953
+ }
30954
+ let entries;
30955
+ try {
30956
+ entries = (0, import_fs9.readdirSync)(srcDir);
30957
+ } catch {
30958
+ continue;
30959
+ }
30960
+ for (const entry of entries) {
30961
+ const s = (0, import_path11.join)(srcDir, entry);
30962
+ const d = (0, import_path11.join)(dstDir, entry);
30963
+ if ((0, import_fs9.existsSync)(d)) {
30964
+ const warningKey = `omcp-content:${s}`;
30965
+ if (!omcpContentWarnings.has(warningKey)) {
30966
+ omcpContentWarnings.add(warningKey);
30967
+ console.warn(
30968
+ `[omc-share] Both ${s} and ${d} exist. Using ${d}; remove the legacy entry manually after verifying no data loss.`
30969
+ );
30970
+ }
30971
+ continue;
30972
+ }
30973
+ try {
30974
+ (0, import_fs9.renameSync)(s, d);
30975
+ moved = true;
30976
+ } catch (err) {
30977
+ console.warn(
30978
+ `[omc-share] Failed to relocate ${s} \u2192 ${d}: ${err instanceof Error ? err.message : err}`
30979
+ );
30980
+ }
30981
+ }
30982
+ }
30983
+ return moved;
30984
+ }
30985
+ var omcpContentWarnings = /* @__PURE__ */ new Set();
30898
30986
  function resolveOmcPath(relativePath, worktreeRoot) {
30899
30987
  validatePath(relativePath);
30900
30988
  const omcDir = getOmcRoot(worktreeRoot);
@@ -30921,10 +31009,10 @@ function ensureOmcDir(relativePath, worktreeRoot) {
30921
31009
  return fullPath;
30922
31010
  }
30923
31011
  function getWorktreeNotepadPath(worktreeRoot) {
30924
- return (0, import_path11.join)(getOmcRoot(worktreeRoot), "notepad.md");
31012
+ return (0, import_path11.join)(getSharedOmcRoot(worktreeRoot), "notepad.md");
30925
31013
  }
30926
31014
  function getWorktreeProjectMemoryPath(worktreeRoot) {
30927
- return (0, import_path11.join)(getOmcRoot(worktreeRoot), "project-memory.json");
31015
+ return (0, import_path11.join)(getSharedOmcRoot(worktreeRoot), "project-memory.json");
30928
31016
  }
30929
31017
  var SESSION_ID_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9_-]{0,255}$/;
30930
31018
  function validateSessionId(sessionId) {
@@ -31012,6 +31100,66 @@ function validateWorkingDirectory(workingDirectory) {
31012
31100
  }
31013
31101
  return trustedRoot;
31014
31102
  }
31103
+ function getGitCommonDir(cwd) {
31104
+ try {
31105
+ const commonDir = (0, import_child_process8.execSync)("git rev-parse --path-format=absolute --git-common-dir", {
31106
+ cwd,
31107
+ encoding: "utf-8",
31108
+ stdio: ["pipe", "pipe", "pipe"],
31109
+ timeout: 5e3
31110
+ }).trim();
31111
+ return (0, import_fs9.realpathSync)(commonDir);
31112
+ } catch {
31113
+ return null;
31114
+ }
31115
+ }
31116
+ function validateWorkingDirectoryOrLinkedWorktree(workingDirectory) {
31117
+ const trustedRoot = getWorktreeRoot(process.cwd()) || process.cwd();
31118
+ if (!workingDirectory) {
31119
+ return trustedRoot;
31120
+ }
31121
+ const resolved = (0, import_path11.resolve)(workingDirectory);
31122
+ let trustedRootReal;
31123
+ try {
31124
+ trustedRootReal = (0, import_fs9.realpathSync)(trustedRoot);
31125
+ } catch {
31126
+ trustedRootReal = trustedRoot;
31127
+ }
31128
+ const providedRoot = getWorktreeRoot(resolved);
31129
+ if (providedRoot) {
31130
+ let providedRootReal;
31131
+ try {
31132
+ providedRootReal = (0, import_fs9.realpathSync)(providedRoot);
31133
+ } catch {
31134
+ throw new Error(`workingDirectory '${workingDirectory}' does not exist or is not accessible.`);
31135
+ }
31136
+ if (providedRootReal === trustedRootReal) {
31137
+ return providedRoot;
31138
+ }
31139
+ const trustedCommonDir = getGitCommonDir(trustedRoot);
31140
+ const providedCommonDir = getGitCommonDir(providedRoot);
31141
+ if (trustedCommonDir && providedCommonDir && providedCommonDir === trustedCommonDir) {
31142
+ return providedRoot;
31143
+ }
31144
+ console.error("[worktree] workingDirectory resolved to different git worktree root, using trusted root", {
31145
+ workingDirectory: resolved,
31146
+ providedRoot: providedRootReal,
31147
+ trustedRoot: trustedRootReal
31148
+ });
31149
+ return trustedRoot;
31150
+ }
31151
+ let resolvedReal;
31152
+ try {
31153
+ resolvedReal = (0, import_fs9.realpathSync)(resolved);
31154
+ } catch {
31155
+ throw new Error(`workingDirectory '${workingDirectory}' does not exist or is not accessible.`);
31156
+ }
31157
+ const rel = (0, import_path11.relative)(trustedRootReal, resolvedReal);
31158
+ if (rel.startsWith("..") || (0, import_path11.isAbsolute)(rel)) {
31159
+ throw new Error(`workingDirectory '${workingDirectory}' is outside the trusted worktree root '${trustedRoot}'.`);
31160
+ }
31161
+ return trustedRoot;
31162
+ }
31015
31163
 
31016
31164
  // src/tools/ast-tools.ts
31017
31165
  var import_meta2 = {};
@@ -32362,7 +32510,8 @@ var pythonReplTool = {
32362
32510
  };
32363
32511
 
32364
32512
  // src/tools/state-tools.ts
32365
- var import_fs12 = require("fs");
32513
+ var import_fs13 = require("fs");
32514
+ var import_path15 = require("path");
32366
32515
 
32367
32516
  // src/lib/payload-limits.ts
32368
32517
  var DEFAULT_PAYLOAD_LIMITS = {
@@ -32421,9 +32570,84 @@ function validatePayload(payload, limits = {}) {
32421
32570
  return { valid: true };
32422
32571
  }
32423
32572
 
32424
- // src/hooks/mode-registry/index.ts
32573
+ // src/lib/mode-state-io.ts
32425
32574
  var import_fs11 = require("fs");
32426
32575
  var import_path13 = require("path");
32576
+ function getStateSessionOwner(state) {
32577
+ if (!state || typeof state !== "object") {
32578
+ return void 0;
32579
+ }
32580
+ const meta3 = state._meta;
32581
+ if (meta3 && typeof meta3 === "object") {
32582
+ const metaSessionId = meta3.sessionId;
32583
+ if (typeof metaSessionId === "string" && metaSessionId) {
32584
+ return metaSessionId;
32585
+ }
32586
+ }
32587
+ const topLevelSessionId = state.session_id;
32588
+ return typeof topLevelSessionId === "string" && topLevelSessionId ? topLevelSessionId : void 0;
32589
+ }
32590
+ function canClearStateForSession(state, sessionId) {
32591
+ const ownerSessionId = getStateSessionOwner(state);
32592
+ return !ownerSessionId || ownerSessionId === sessionId;
32593
+ }
32594
+ function resolveStateRoot(directory) {
32595
+ const baseDir = directory || process.cwd();
32596
+ return getWorktreeRoot(baseDir) || baseDir;
32597
+ }
32598
+ function hasSessionEndSummary(baseDir, sessionId) {
32599
+ return (0, import_fs11.existsSync)((0, import_path13.join)(getOmcRoot(baseDir), "sessions", `${sessionId}.json`));
32600
+ }
32601
+ function findSessionOwnedStateFiles(mode, sessionId, directory) {
32602
+ const matches = /* @__PURE__ */ new Set();
32603
+ const baseDir = resolveStateRoot(directory);
32604
+ const expectedPath = resolveSessionStatePath(mode, sessionId, baseDir);
32605
+ if ((0, import_fs11.existsSync)(expectedPath)) {
32606
+ matches.add(expectedPath);
32607
+ }
32608
+ for (const sid of listSessionIds(baseDir)) {
32609
+ const candidatePath = resolveSessionStatePath(mode, sid, baseDir);
32610
+ if (!(0, import_fs11.existsSync)(candidatePath)) {
32611
+ continue;
32612
+ }
32613
+ try {
32614
+ const raw = JSON.parse((0, import_fs11.readFileSync)(candidatePath, "utf-8"));
32615
+ if (getStateSessionOwner(raw) === sessionId) {
32616
+ matches.add(candidatePath);
32617
+ }
32618
+ } catch {
32619
+ }
32620
+ }
32621
+ return [...matches];
32622
+ }
32623
+ function findCompletedSessionStateFiles(mode, directory, requesterSessionId) {
32624
+ const matches = /* @__PURE__ */ new Set();
32625
+ const baseDir = resolveStateRoot(directory);
32626
+ for (const sid of listSessionIds(baseDir)) {
32627
+ if (requesterSessionId && sid === requesterSessionId) {
32628
+ continue;
32629
+ }
32630
+ if (!hasSessionEndSummary(baseDir, sid)) {
32631
+ continue;
32632
+ }
32633
+ const candidatePath = resolveSessionStatePath(mode, sid, baseDir);
32634
+ if (!(0, import_fs11.existsSync)(candidatePath)) {
32635
+ continue;
32636
+ }
32637
+ try {
32638
+ const raw = JSON.parse((0, import_fs11.readFileSync)(candidatePath, "utf-8"));
32639
+ if (raw.active === true) {
32640
+ matches.add(candidatePath);
32641
+ }
32642
+ } catch {
32643
+ }
32644
+ }
32645
+ return [...matches];
32646
+ }
32647
+
32648
+ // src/hooks/mode-registry/index.ts
32649
+ var import_fs12 = require("fs");
32650
+ var import_path14 = require("path");
32427
32651
 
32428
32652
  // src/lib/mode-names.ts
32429
32653
  var MODE_NAMES = {
@@ -32531,26 +32755,26 @@ var MODE_CONFIGS = {
32531
32755
  };
32532
32756
  var EXCLUSIVE_MODES = [MODE_NAMES.AUTOPILOT, MODE_NAMES.AUTORESEARCH];
32533
32757
  function getStateDir(cwd) {
32534
- return (0, import_path13.join)(getOmcRoot(cwd), "state");
32758
+ return (0, import_path14.join)(getOmcRoot(cwd), "state");
32535
32759
  }
32536
32760
  function getStateFilePath(cwd, mode, sessionId) {
32537
32761
  const config2 = MODE_CONFIGS[mode];
32538
32762
  if (sessionId) {
32539
32763
  return resolveSessionStatePath(mode, sessionId, cwd);
32540
32764
  }
32541
- return (0, import_path13.join)(getStateDir(cwd), config2.stateFile);
32765
+ return (0, import_path14.join)(getStateDir(cwd), config2.stateFile);
32542
32766
  }
32543
32767
  function getMarkerFilePath(cwd, mode) {
32544
32768
  const config2 = MODE_CONFIGS[mode];
32545
32769
  if (!config2.markerFile) return null;
32546
- return (0, import_path13.join)(getStateDir(cwd), config2.markerFile);
32770
+ return (0, import_path14.join)(getStateDir(cwd), config2.markerFile);
32547
32771
  }
32548
32772
  var WORKFLOW_SLOT_TOMBSTONE_TTL_MS = 24 * 60 * 60 * 1e3;
32549
32773
  function isWorkflowSlotTombstonedForMode(cwd, mode, sessionId, now = Date.now()) {
32550
32774
  try {
32551
- const ledgerPath = sessionId ? resolveSessionStatePath("skill-active", sessionId, cwd) : (0, import_path13.join)(getStateDir(cwd), "skill-active-state.json");
32552
- if (!(0, import_fs11.existsSync)(ledgerPath)) return false;
32553
- const raw = JSON.parse((0, import_fs11.readFileSync)(ledgerPath, "utf-8"));
32775
+ const ledgerPath = sessionId ? resolveSessionStatePath("skill-active", sessionId, cwd) : (0, import_path14.join)(getStateDir(cwd), "skill-active-state.json");
32776
+ if (!(0, import_fs12.existsSync)(ledgerPath)) return false;
32777
+ const raw = JSON.parse((0, import_fs12.readFileSync)(ledgerPath, "utf-8"));
32554
32778
  const slots = raw.active_skills;
32555
32779
  if (!slots || typeof slots !== "object") return false;
32556
32780
  const slot = slots[mode];
@@ -32573,7 +32797,7 @@ function isJsonModeActive(cwd, mode, sessionId) {
32573
32797
  }
32574
32798
  const sessionStateFile = resolveSessionStatePath(mode, sessionId, cwd);
32575
32799
  try {
32576
- const content = (0, import_fs11.readFileSync)(sessionStateFile, "utf-8");
32800
+ const content = (0, import_fs12.readFileSync)(sessionStateFile, "utf-8");
32577
32801
  const state = JSON.parse(content);
32578
32802
  if (state.session_id && state.session_id !== sessionId) {
32579
32803
  return false;
@@ -32591,7 +32815,7 @@ function isJsonModeActive(cwd, mode, sessionId) {
32591
32815
  }
32592
32816
  const stateFile = getStateFilePath(cwd, mode);
32593
32817
  try {
32594
- const content = (0, import_fs11.readFileSync)(stateFile, "utf-8");
32818
+ const content = (0, import_fs12.readFileSync)(stateFile, "utf-8");
32595
32819
  const state = JSON.parse(content);
32596
32820
  if (config2.activeProperty) {
32597
32821
  return state[config2.activeProperty] === true;
@@ -32631,7 +32855,7 @@ function clearModeState(mode, cwd, sessionId) {
32631
32855
  if (isSessionScopedClear && sessionId) {
32632
32856
  const sessionStateFile = resolveSessionStatePath(mode, sessionId, cwd);
32633
32857
  try {
32634
- (0, import_fs11.unlinkSync)(sessionStateFile);
32858
+ (0, import_fs12.unlinkSync)(sessionStateFile);
32635
32859
  } catch (err) {
32636
32860
  if (err.code !== "ENOENT") {
32637
32861
  success2 = false;
@@ -32645,7 +32869,7 @@ function clearModeState(mode, cwd, sessionId) {
32645
32869
  cwd
32646
32870
  );
32647
32871
  try {
32648
- (0, import_fs11.unlinkSync)(sessionMarkerFile);
32872
+ (0, import_fs12.unlinkSync)(sessionMarkerFile);
32649
32873
  } catch (err) {
32650
32874
  if (err.code !== "ENOENT") {
32651
32875
  success2 = false;
@@ -32654,11 +32878,11 @@ function clearModeState(mode, cwd, sessionId) {
32654
32878
  }
32655
32879
  if (markerFile) {
32656
32880
  try {
32657
- const markerRaw = JSON.parse((0, import_fs11.readFileSync)(markerFile, "utf-8"));
32881
+ const markerRaw = JSON.parse((0, import_fs12.readFileSync)(markerFile, "utf-8"));
32658
32882
  const markerSessionId = markerRaw.session_id ?? markerRaw.sessionId;
32659
32883
  if (!markerSessionId || markerSessionId === sessionId) {
32660
32884
  try {
32661
- (0, import_fs11.unlinkSync)(markerFile);
32885
+ (0, import_fs12.unlinkSync)(markerFile);
32662
32886
  } catch (err) {
32663
32887
  if (err.code !== "ENOENT") {
32664
32888
  success2 = false;
@@ -32667,7 +32891,7 @@ function clearModeState(mode, cwd, sessionId) {
32667
32891
  }
32668
32892
  } catch {
32669
32893
  try {
32670
- (0, import_fs11.unlinkSync)(markerFile);
32894
+ (0, import_fs12.unlinkSync)(markerFile);
32671
32895
  } catch (err) {
32672
32896
  if (err.code !== "ENOENT") {
32673
32897
  success2 = false;
@@ -32679,7 +32903,7 @@ function clearModeState(mode, cwd, sessionId) {
32679
32903
  const stateFile = getStateFilePath(cwd, mode);
32680
32904
  if (!isSessionScopedClear) {
32681
32905
  try {
32682
- (0, import_fs11.unlinkSync)(stateFile);
32906
+ (0, import_fs12.unlinkSync)(stateFile);
32683
32907
  } catch (err) {
32684
32908
  if (err.code !== "ENOENT") {
32685
32909
  success2 = false;
@@ -32689,11 +32913,11 @@ function clearModeState(mode, cwd, sessionId) {
32689
32913
  if (markerFile) {
32690
32914
  if (isSessionScopedClear) {
32691
32915
  try {
32692
- const markerRaw = JSON.parse((0, import_fs11.readFileSync)(markerFile, "utf-8"));
32916
+ const markerRaw = JSON.parse((0, import_fs12.readFileSync)(markerFile, "utf-8"));
32693
32917
  const markerSessionId = markerRaw.session_id ?? markerRaw.sessionId;
32694
32918
  if (!markerSessionId || markerSessionId === sessionId) {
32695
32919
  try {
32696
- (0, import_fs11.unlinkSync)(markerFile);
32920
+ (0, import_fs12.unlinkSync)(markerFile);
32697
32921
  } catch (err) {
32698
32922
  if (err.code !== "ENOENT") {
32699
32923
  success2 = false;
@@ -32702,7 +32926,7 @@ function clearModeState(mode, cwd, sessionId) {
32702
32926
  }
32703
32927
  } catch {
32704
32928
  try {
32705
- (0, import_fs11.unlinkSync)(markerFile);
32929
+ (0, import_fs12.unlinkSync)(markerFile);
32706
32930
  } catch (err) {
32707
32931
  if (err.code !== "ENOENT") {
32708
32932
  success2 = false;
@@ -32711,7 +32935,7 @@ function clearModeState(mode, cwd, sessionId) {
32711
32935
  }
32712
32936
  } else {
32713
32937
  try {
32714
- (0, import_fs11.unlinkSync)(markerFile);
32938
+ (0, import_fs12.unlinkSync)(markerFile);
32715
32939
  } catch (err) {
32716
32940
  if (err.code !== "ENOENT") {
32717
32941
  success2 = false;
@@ -32745,12 +32969,165 @@ var STATE_TOOL_MODES = [
32745
32969
  ];
32746
32970
  var EXTRA_STATE_ONLY_MODES = ["ralplan", "omc-teams", "skill-active"];
32747
32971
  var CANCEL_SIGNAL_TTL_MS = 3e4;
32972
+ function readTeamNamesFromStateFile(statePath) {
32973
+ if (!(0, import_fs13.existsSync)(statePath)) return [];
32974
+ try {
32975
+ const raw = JSON.parse((0, import_fs13.readFileSync)(statePath, "utf-8"));
32976
+ const teamName = typeof raw.team_name === "string" ? raw.team_name.trim() : typeof raw.teamName === "string" ? raw.teamName.trim() : "";
32977
+ return teamName ? [teamName] : [];
32978
+ } catch {
32979
+ return [];
32980
+ }
32981
+ }
32982
+ function pruneMissionBoardTeams(root, teamNames) {
32983
+ const missionStatePath = (0, import_path15.join)(getOmcRoot(root), "state", "mission-state.json");
32984
+ if (!(0, import_fs13.existsSync)(missionStatePath)) return 0;
32985
+ try {
32986
+ const parsed = JSON.parse((0, import_fs13.readFileSync)(missionStatePath, "utf-8"));
32987
+ if (!Array.isArray(parsed.missions)) return 0;
32988
+ const shouldRemoveAll = teamNames == null;
32989
+ const teamNameSet = new Set(teamNames ?? []);
32990
+ const remainingMissions = parsed.missions.filter((mission) => {
32991
+ if (mission.source !== "team") return true;
32992
+ if (shouldRemoveAll) return false;
32993
+ const missionTeamName = typeof mission.teamName === "string" ? mission.teamName.trim() : typeof mission.name === "string" ? mission.name.trim() : "";
32994
+ return !missionTeamName || !teamNameSet.has(missionTeamName);
32995
+ });
32996
+ const removed = parsed.missions.length - remainingMissions.length;
32997
+ if (removed > 0) {
32998
+ (0, import_fs13.writeFileSync)(missionStatePath, JSON.stringify({
32999
+ ...parsed,
33000
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
33001
+ missions: remainingMissions
33002
+ }, null, 2));
33003
+ }
33004
+ return removed;
33005
+ } catch {
33006
+ return 0;
33007
+ }
33008
+ }
33009
+ function cleanupTeamRuntimeState(root, teamNames) {
33010
+ const teamStateRoot = (0, import_path15.join)(getOmcRoot(root), "state", "team");
33011
+ if (!(0, import_fs13.existsSync)(teamStateRoot)) return 0;
33012
+ const shouldRemoveAll = teamNames == null;
33013
+ let removed = 0;
33014
+ if (shouldRemoveAll) {
33015
+ try {
33016
+ (0, import_fs13.rmSync)(teamStateRoot, { recursive: true, force: true });
33017
+ return 1;
33018
+ } catch {
33019
+ return 0;
33020
+ }
33021
+ }
33022
+ for (const teamName of teamNames ?? []) {
33023
+ if (!teamName) continue;
33024
+ try {
33025
+ (0, import_fs13.rmSync)((0, import_path15.join)(teamStateRoot, teamName), { recursive: true, force: true });
33026
+ removed += 1;
33027
+ } catch {
33028
+ }
33029
+ }
33030
+ return removed;
33031
+ }
32748
33032
  function getStatePath(mode, root) {
32749
33033
  if (MODE_CONFIGS[mode]) {
32750
33034
  return getStateFilePath(root, mode);
32751
33035
  }
32752
33036
  return resolveStatePath(mode, root);
32753
33037
  }
33038
+ function getLegacyStateFileCandidates(mode, root) {
33039
+ const normalizedName = mode.endsWith("-state") ? mode : `${mode}-state`;
33040
+ const candidates = [
33041
+ getStatePath(mode, root),
33042
+ (0, import_path15.join)(getOmcRoot(root), `${normalizedName}.json`)
33043
+ ];
33044
+ return [...new Set(candidates)];
33045
+ }
33046
+ function clearLegacyStateCandidates(mode, root, sessionId) {
33047
+ let cleared = 0;
33048
+ let hadFailure = false;
33049
+ for (const legacyPath of getLegacyStateFileCandidates(mode, root)) {
33050
+ if (!(0, import_fs13.existsSync)(legacyPath)) {
33051
+ continue;
33052
+ }
33053
+ try {
33054
+ if (sessionId) {
33055
+ const raw = JSON.parse((0, import_fs13.readFileSync)(legacyPath, "utf-8"));
33056
+ if (!canClearStateForSession(raw, sessionId)) {
33057
+ continue;
33058
+ }
33059
+ }
33060
+ (0, import_fs13.unlinkSync)(legacyPath);
33061
+ cleared++;
33062
+ } catch {
33063
+ hadFailure = true;
33064
+ }
33065
+ }
33066
+ return { cleared, hadFailure };
33067
+ }
33068
+ function clearSessionOwnedStateCandidates(mode, root, sessionId) {
33069
+ let cleared = 0;
33070
+ let hadFailure = false;
33071
+ const paths = findSessionOwnedStateFiles(mode, sessionId, root);
33072
+ for (const statePath of paths) {
33073
+ try {
33074
+ (0, import_fs13.unlinkSync)(statePath);
33075
+ cleared++;
33076
+ } catch {
33077
+ hadFailure = true;
33078
+ }
33079
+ }
33080
+ return { cleared, hadFailure, paths };
33081
+ }
33082
+ function clearCompletedSessionStateCandidates(mode, root, requesterSessionId) {
33083
+ let cleared = 0;
33084
+ let hadFailure = false;
33085
+ const paths = findCompletedSessionStateFiles(mode, root, requesterSessionId);
33086
+ for (const statePath of paths) {
33087
+ try {
33088
+ (0, import_fs13.unlinkSync)(statePath);
33089
+ cleared++;
33090
+ } catch {
33091
+ hadFailure = true;
33092
+ }
33093
+ }
33094
+ return { cleared, hadFailure, paths };
33095
+ }
33096
+ function getModeRuntimeArtifactNames(mode) {
33097
+ return [
33098
+ `${mode}-stop-breaker.json`,
33099
+ `${mode}-last-steer-at`,
33100
+ `${mode}-continue-steer.lock`
33101
+ ];
33102
+ }
33103
+ function clearModeRuntimeArtifacts(mode, root, sessionId) {
33104
+ let cleared = 0;
33105
+ let hadFailure = false;
33106
+ const stateRoot = (0, import_path15.join)(getOmcRoot(root), "state");
33107
+ const candidateDirs = /* @__PURE__ */ new Set([stateRoot]);
33108
+ if (sessionId) {
33109
+ candidateDirs.add((0, import_path15.join)(stateRoot, "sessions", sessionId));
33110
+ } else {
33111
+ for (const sid of listSessionIds(root)) {
33112
+ candidateDirs.add((0, import_path15.join)(stateRoot, "sessions", sid));
33113
+ }
33114
+ }
33115
+ for (const dir of candidateDirs) {
33116
+ for (const artifactName of getModeRuntimeArtifactNames(mode)) {
33117
+ const artifactPath = (0, import_path15.join)(dir, artifactName);
33118
+ if (!(0, import_fs13.existsSync)(artifactPath)) {
33119
+ continue;
33120
+ }
33121
+ try {
33122
+ (0, import_fs13.unlinkSync)(artifactPath);
33123
+ cleared++;
33124
+ } catch {
33125
+ hadFailure = true;
33126
+ }
33127
+ }
33128
+ }
33129
+ return { cleared, hadFailure };
33130
+ }
32754
33131
  function writeSessionCancelSignal(root, sessionId, mode) {
32755
33132
  const now = Date.now();
32756
33133
  const cancelSignalPath = resolveSessionStatePath("cancel-signal", sessionId, root);
@@ -32767,11 +33144,11 @@ function isSessionModeActive(mode, root, sessionId) {
32767
33144
  return isModeActive(mode, root, sessionId);
32768
33145
  }
32769
33146
  const statePath = resolveSessionStatePath(mode, sessionId, root);
32770
- if (!(0, import_fs12.existsSync)(statePath)) {
33147
+ if (!(0, import_fs13.existsSync)(statePath)) {
32771
33148
  return false;
32772
33149
  }
32773
33150
  try {
32774
- const state = JSON.parse((0, import_fs12.readFileSync)(statePath, "utf-8"));
33151
+ const state = JSON.parse((0, import_fs13.readFileSync)(statePath, "utf-8"));
32775
33152
  return state.active === true;
32776
33153
  } catch {
32777
33154
  return false;
@@ -32798,7 +33175,31 @@ var stateReadTool = {
32798
33175
  if (sessionId) {
32799
33176
  validateSessionId(sessionId);
32800
33177
  const statePath2 = MODE_CONFIGS[mode] ? getStateFilePath(root, mode, sessionId) : resolveSessionStatePath(mode, sessionId, root);
32801
- if (!(0, import_fs12.existsSync)(statePath2)) {
33178
+ if (!(0, import_fs13.existsSync)(statePath2)) {
33179
+ const completedSessionPaths = findCompletedSessionStateFiles(mode, root, sessionId);
33180
+ if (completedSessionPaths.length > 0) {
33181
+ const orphanList = completedSessionPaths.map((orphanPath) => {
33182
+ const sessionMarker = `${(0, import_path15.join)("state", "sessions")}/`;
33183
+ const markerIndex = orphanPath.indexOf(sessionMarker);
33184
+ if (markerIndex === -1) return `- ${orphanPath}`;
33185
+ const rest = orphanPath.slice(markerIndex + sessionMarker.length);
33186
+ const orphanSessionId = rest.split(/[\\/]/)[0] || "unknown";
33187
+ return `- session: ${orphanSessionId}
33188
+ path: ${orphanPath}`;
33189
+ }).join("\n");
33190
+ return {
33191
+ content: [{
33192
+ type: "text",
33193
+ text: `No state found for mode: ${mode} in session: ${sessionId}
33194
+ Expected path: ${statePath2}
33195
+
33196
+ Discovered ${completedSessionPaths.length} completed-session orphan state file${completedSessionPaths.length === 1 ? "" : "s"} for this mode:
33197
+ ${orphanList}
33198
+
33199
+ Run state_clear(mode="${mode}", session_id="${sessionId}") to clear the current session plus these completed-session orphan files.`
33200
+ }]
33201
+ };
33202
+ }
32802
33203
  return {
32803
33204
  content: [{
32804
33205
  type: "text",
@@ -32807,7 +33208,7 @@ Expected path: ${statePath2}`
32807
33208
  }]
32808
33209
  };
32809
33210
  }
32810
- const content = (0, import_fs12.readFileSync)(statePath2, "utf-8");
33211
+ const content = (0, import_fs13.readFileSync)(statePath2, "utf-8");
32811
33212
  const state = JSON.parse(content);
32812
33213
  return {
32813
33214
  content: [{
@@ -32823,12 +33224,12 @@ ${JSON.stringify(state, null, 2)}
32823
33224
  };
32824
33225
  }
32825
33226
  const statePath = getStatePath(mode, root);
32826
- const legacyExists = (0, import_fs12.existsSync)(statePath);
33227
+ const legacyExists = (0, import_fs13.existsSync)(statePath);
32827
33228
  const sessionIds = listSessionIds(root);
32828
33229
  const activeSessions = [];
32829
33230
  for (const sid of sessionIds) {
32830
33231
  const sessionStatePath = MODE_CONFIGS[mode] ? getStateFilePath(root, mode, sid) : resolveSessionStatePath(mode, sid, root);
32831
- if ((0, import_fs12.existsSync)(sessionStatePath)) {
33232
+ if ((0, import_fs13.existsSync)(sessionStatePath)) {
32832
33233
  activeSessions.push(sid);
32833
33234
  }
32834
33235
  }
@@ -32851,7 +33252,7 @@ Note: Reading from legacy/aggregate path (no session_id). This may include state
32851
33252
  `;
32852
33253
  if (legacyExists) {
32853
33254
  try {
32854
- const content = (0, import_fs12.readFileSync)(statePath, "utf-8");
33255
+ const content = (0, import_fs13.readFileSync)(statePath, "utf-8");
32855
33256
  const state = JSON.parse(content);
32856
33257
  output += `### Legacy Path (shared)
32857
33258
  Path: ${statePath}
@@ -32876,7 +33277,7 @@ Path: ${statePath}
32876
33277
  for (const sid of activeSessions) {
32877
33278
  const sessionStatePath = MODE_CONFIGS[mode] ? getStateFilePath(root, mode, sid) : resolveSessionStatePath(mode, sid, root);
32878
33279
  try {
32879
- const content = (0, import_fs12.readFileSync)(sessionStatePath, "utf-8");
33280
+ const content = (0, import_fs13.readFileSync)(sessionStatePath, "utf-8");
32880
33281
  const state = JSON.parse(content);
32881
33282
  output += `**Session: ${sid}**
32882
33283
  Path: ${sessionStatePath}
@@ -33032,124 +33433,209 @@ var stateClearTool = {
33032
33433
  session_id: external_exports3.string().optional().describe("Session ID for session-scoped state isolation. When provided, the tool operates only within that session. When omitted, the tool aggregates legacy state plus all session-scoped state (may include other sessions).")
33033
33434
  },
33034
33435
  handler: async (args) => {
33035
- const { mode, workingDirectory, session_id } = args;
33436
+ const { workingDirectory, session_id } = args;
33437
+ const mode = args.mode;
33036
33438
  try {
33037
33439
  const root = validateWorkingDirectory(workingDirectory);
33038
33440
  const sessionId = session_id;
33441
+ const cleanedTeamNames = /* @__PURE__ */ new Set();
33442
+ const collectTeamNamesForCleanup = (statePath) => {
33443
+ if (mode !== "team") return;
33444
+ for (const teamName of readTeamNamesFromStateFile(statePath)) {
33445
+ cleanedTeamNames.add(teamName);
33446
+ }
33447
+ };
33039
33448
  if (sessionId) {
33040
33449
  validateSessionId(sessionId);
33450
+ const requestedSessionOwnedPaths = findSessionOwnedStateFiles(mode, sessionId, root);
33451
+ for (const teamStatePath of findSessionOwnedStateFiles("team", sessionId, root)) {
33452
+ collectTeamNamesForCleanup(teamStatePath);
33453
+ }
33454
+ if (mode === "team") {
33455
+ for (const teamStatePath of findCompletedSessionStateFiles("team", root, sessionId)) {
33456
+ collectTeamNamesForCleanup(teamStatePath);
33457
+ }
33458
+ }
33459
+ const completedSessionCleanup = clearCompletedSessionStateCandidates(mode, root, sessionId);
33460
+ const runtimeCleanup2 = clearModeRuntimeArtifacts(mode, root, sessionId);
33041
33461
  writeSessionCancelSignal(root, sessionId, mode);
33042
33462
  if (MODE_CONFIGS[mode]) {
33043
- const requesterStatePath = getStateFilePath(root, mode, sessionId);
33044
- const hadRequesterState2 = (0, import_fs12.existsSync)(requesterStatePath);
33045
33463
  const success2 = clearModeState(mode, root, sessionId);
33046
- let ghostCleaned2 = false;
33047
- try {
33048
- const legacyPath = getStateFilePath(root, mode);
33049
- if ((0, import_fs12.existsSync)(legacyPath)) {
33050
- const raw = JSON.parse((0, import_fs12.readFileSync)(legacyPath, "utf-8"));
33051
- const meta3 = raw._meta;
33052
- if (!meta3 || meta3.sessionId === sessionId) {
33053
- (0, import_fs12.unlinkSync)(legacyPath);
33054
- ghostCleaned2 = true;
33055
- }
33056
- }
33057
- } catch {
33058
- }
33464
+ const sessionCleanup2 = clearSessionOwnedStateCandidates(mode, root, sessionId);
33465
+ const legacyCleanup2 = clearLegacyStateCandidates(mode, root, sessionId);
33059
33466
  let ownerSessionId2;
33060
- if (!hadRequesterState2 && !ghostCleaned2) {
33467
+ let ownerSessionCleanup2 = { cleared: 0, hadFailure: false, paths: [] };
33468
+ let ownerLegacyCleanup2 = { cleared: 0, hadFailure: false };
33469
+ if (requestedSessionOwnedPaths.length === 0 && completedSessionCleanup.cleared === 0 && sessionCleanup2.cleared === 0 && legacyCleanup2.cleared === 0) {
33061
33470
  ownerSessionId2 = findSingleOwningSessionForMode(mode, root, sessionId);
33062
33471
  if (ownerSessionId2) {
33472
+ if (mode === "team") {
33473
+ for (const teamStatePath of findSessionOwnedStateFiles("team", ownerSessionId2, root)) {
33474
+ collectTeamNamesForCleanup(teamStatePath);
33475
+ }
33476
+ }
33063
33477
  writeSessionCancelSignal(root, ownerSessionId2, mode);
33478
+ const ownerRuntimeCleanup = clearModeRuntimeArtifacts(mode, root, ownerSessionId2);
33479
+ runtimeCleanup2.cleared += ownerRuntimeCleanup.cleared;
33480
+ runtimeCleanup2.hadFailure ||= ownerRuntimeCleanup.hadFailure;
33064
33481
  clearModeState(mode, root, ownerSessionId2);
33482
+ ownerSessionCleanup2 = clearSessionOwnedStateCandidates(mode, root, ownerSessionId2);
33483
+ ownerLegacyCleanup2 = clearLegacyStateCandidates(mode, root, ownerSessionId2);
33065
33484
  }
33066
33485
  }
33067
- const ghostNote2 = ghostCleaned2 ? " (ghost legacy file also removed)" : "";
33068
- const ownerNote2 = ownerSessionId2 ? ` (cleared owning session: ${ownerSessionId2})` : "";
33069
- if (success2 || ownerSessionId2) {
33486
+ const ghostNoteParts2 = [];
33487
+ if (legacyCleanup2.cleared > 0) {
33488
+ ghostNoteParts2.push("ghost legacy file also removed");
33489
+ }
33490
+ if (completedSessionCleanup.cleared > 0) {
33491
+ ghostNoteParts2.push(`removed ${completedSessionCleanup.cleared} completed-session orphan file${completedSessionCleanup.cleared === 1 ? "" : "s"}`);
33492
+ }
33493
+ if (sessionCleanup2.cleared > 0) {
33494
+ ghostNoteParts2.push(`removed ${sessionCleanup2.cleared} recovered session file${sessionCleanup2.cleared === 1 ? "" : "s"}`);
33495
+ }
33496
+ if (runtimeCleanup2.cleared > 0) {
33497
+ ghostNoteParts2.push(`removed ${runtimeCleanup2.cleared} runtime artifact${runtimeCleanup2.cleared === 1 ? "" : "s"}`);
33498
+ }
33499
+ if (ownerSessionId2) {
33500
+ ghostNoteParts2.push(`cleared owning session: ${ownerSessionId2}`);
33501
+ }
33502
+ const ghostNote2 = ghostNoteParts2.length > 0 ? ` (${ghostNoteParts2.join(", ")})` : "";
33503
+ const runtimeCleanupNote2 = (() => {
33504
+ if (mode !== "team") return "";
33505
+ const teamNames = [...cleanedTeamNames];
33506
+ const removedRoots = cleanupTeamRuntimeState(root, teamNames);
33507
+ const prunedMissions = pruneMissionBoardTeams(root, teamNames);
33508
+ const details = [];
33509
+ if (removedRoots > 0) details.push(`removed ${removedRoots} team runtime root(s)`);
33510
+ if (prunedMissions > 0) details.push(`pruned ${prunedMissions} HUD mission entry(ies)`);
33511
+ return details.length > 0 ? ` (${details.join(", ")})` : "";
33512
+ })();
33513
+ if (success2 && !legacyCleanup2.hadFailure && !sessionCleanup2.hadFailure && !completedSessionCleanup.hadFailure && !ownerSessionCleanup2.hadFailure && !ownerLegacyCleanup2.hadFailure && !runtimeCleanup2.hadFailure) {
33070
33514
  return {
33071
33515
  content: [{
33072
33516
  type: "text",
33073
- text: `Successfully cleared state for mode: ${mode} in session: ${sessionId}${ghostNote2}${ownerNote2}`
33517
+ text: `Successfully cleared state for mode: ${mode} in session: ${sessionId}${ghostNote2}${runtimeCleanupNote2}`
33074
33518
  }]
33075
33519
  };
33076
33520
  } else {
33077
33521
  return {
33078
33522
  content: [{
33079
33523
  type: "text",
33080
- text: `Warning: Some files could not be removed for mode: ${mode} in session: ${sessionId}${ghostNote2}${ownerNote2}`
33524
+ text: `Warning: Some files could not be removed for mode: ${mode} in session: ${sessionId}${ghostNote2}${runtimeCleanupNote2}`
33081
33525
  }]
33082
33526
  };
33083
33527
  }
33084
33528
  }
33085
- const statePath = resolveSessionStatePath(mode, sessionId, root);
33086
- const hadRequesterState = (0, import_fs12.existsSync)(statePath);
33087
- if (hadRequesterState) {
33088
- (0, import_fs12.unlinkSync)(statePath);
33089
- }
33090
- let ghostCleaned = false;
33091
- try {
33092
- const legacyPath = resolveStatePath(mode, root);
33093
- if ((0, import_fs12.existsSync)(legacyPath)) {
33094
- const raw = JSON.parse((0, import_fs12.readFileSync)(legacyPath, "utf-8"));
33095
- const meta3 = raw._meta;
33096
- if (!meta3 || meta3.sessionId === sessionId) {
33097
- (0, import_fs12.unlinkSync)(legacyPath);
33098
- ghostCleaned = true;
33099
- }
33100
- }
33101
- } catch {
33102
- }
33529
+ const sessionCleanup = clearSessionOwnedStateCandidates(mode, root, sessionId);
33530
+ const legacyCleanup = clearLegacyStateCandidates(mode, root, sessionId);
33103
33531
  let ownerSessionId;
33104
- if (!hadRequesterState && !ghostCleaned) {
33532
+ let ownerSessionCleanup = { cleared: 0, hadFailure: false, paths: [] };
33533
+ let ownerLegacyCleanup = { cleared: 0, hadFailure: false };
33534
+ if (requestedSessionOwnedPaths.length === 0 && completedSessionCleanup.cleared === 0 && sessionCleanup.cleared === 0 && legacyCleanup.cleared === 0) {
33105
33535
  ownerSessionId = findSingleOwningSessionForMode(mode, root, sessionId);
33106
33536
  if (ownerSessionId) {
33107
- writeSessionCancelSignal(root, ownerSessionId, mode);
33108
- const ownerStatePath = resolveSessionStatePath(mode, ownerSessionId, root);
33109
- if ((0, import_fs12.existsSync)(ownerStatePath)) {
33110
- try {
33111
- (0, import_fs12.unlinkSync)(ownerStatePath);
33112
- } catch {
33537
+ if (mode === "team") {
33538
+ for (const teamStatePath of findSessionOwnedStateFiles("team", ownerSessionId, root)) {
33539
+ collectTeamNamesForCleanup(teamStatePath);
33113
33540
  }
33114
33541
  }
33542
+ writeSessionCancelSignal(root, ownerSessionId, mode);
33543
+ const ownerRuntimeCleanup = clearModeRuntimeArtifacts(mode, root, ownerSessionId);
33544
+ runtimeCleanup2.cleared += ownerRuntimeCleanup.cleared;
33545
+ runtimeCleanup2.hadFailure ||= ownerRuntimeCleanup.hadFailure;
33546
+ ownerSessionCleanup = clearSessionOwnedStateCandidates(mode, root, ownerSessionId);
33547
+ ownerLegacyCleanup = clearLegacyStateCandidates(mode, root, ownerSessionId);
33115
33548
  }
33116
33549
  }
33117
- const ghostNote = ghostCleaned ? " (ghost legacy file also removed)" : "";
33118
- const ownerNote = ownerSessionId ? ` (cleared owning session: ${ownerSessionId})` : "";
33550
+ const ghostNoteParts = [];
33551
+ if (legacyCleanup.cleared > 0) {
33552
+ ghostNoteParts.push("ghost legacy file also removed");
33553
+ }
33554
+ if (completedSessionCleanup.cleared > 0) {
33555
+ ghostNoteParts.push(`removed ${completedSessionCleanup.cleared} completed-session orphan file${completedSessionCleanup.cleared === 1 ? "" : "s"}`);
33556
+ }
33557
+ if (sessionCleanup.cleared > 0) {
33558
+ ghostNoteParts.push(`removed ${sessionCleanup.cleared} recovered session file${sessionCleanup.cleared === 1 ? "" : "s"}`);
33559
+ }
33560
+ if (runtimeCleanup2.cleared > 0) {
33561
+ ghostNoteParts.push(`removed ${runtimeCleanup2.cleared} runtime artifact${runtimeCleanup2.cleared === 1 ? "" : "s"}`);
33562
+ }
33563
+ if (ownerSessionId) {
33564
+ ghostNoteParts.push(`cleared owning session: ${ownerSessionId}`);
33565
+ }
33566
+ const ghostNote = ghostNoteParts.length > 0 ? ` (${ghostNoteParts.join(", ")})` : "";
33567
+ const runtimeCleanupNote = (() => {
33568
+ if (mode !== "team") return "";
33569
+ const teamNames = [...cleanedTeamNames];
33570
+ const removedRoots = cleanupTeamRuntimeState(root, teamNames);
33571
+ const prunedMissions = pruneMissionBoardTeams(root, teamNames);
33572
+ const details = [];
33573
+ if (removedRoots > 0) details.push(`removed ${removedRoots} team runtime root(s)`);
33574
+ if (prunedMissions > 0) details.push(`pruned ${prunedMissions} HUD mission entry(ies)`);
33575
+ return details.length > 0 ? ` (${details.join(", ")})` : "";
33576
+ })();
33119
33577
  return {
33120
33578
  content: [{
33121
33579
  type: "text",
33122
- text: `Successfully cleared state for mode: ${mode} in session: ${sessionId}${ghostNote}${ownerNote}`
33580
+ text: `${legacyCleanup.hadFailure || sessionCleanup.hadFailure || completedSessionCleanup.hadFailure || ownerSessionCleanup.hadFailure || ownerLegacyCleanup.hadFailure || runtimeCleanup2.hadFailure ? "Warning: Some files could not be removed" : "Successfully cleared state"} for mode: ${mode} in session: ${sessionId}${ghostNote}${runtimeCleanupNote}`
33123
33581
  }]
33124
33582
  };
33125
33583
  }
33584
+ {
33585
+ const now = Date.now();
33586
+ const cancelSignalPayload = {
33587
+ active: true,
33588
+ requested_at: new Date(now).toISOString(),
33589
+ expires_at: new Date(now + CANCEL_SIGNAL_TTL_MS).toISOString(),
33590
+ mode,
33591
+ source: "state_clear"
33592
+ };
33593
+ const legacySignalPath = (0, import_path15.join)(getOmcRoot(root), "state", "cancel-signal-state.json");
33594
+ try {
33595
+ atomicWriteJsonSync(legacySignalPath, cancelSignalPayload);
33596
+ } catch {
33597
+ }
33598
+ for (const sid of listSessionIds(root)) {
33599
+ try {
33600
+ const sessionSignalPath = resolveSessionStatePath("cancel-signal", sid, root);
33601
+ atomicWriteJsonSync(sessionSignalPath, cancelSignalPayload);
33602
+ } catch {
33603
+ }
33604
+ }
33605
+ }
33606
+ const runtimeCleanup = clearModeRuntimeArtifacts(mode, root);
33126
33607
  let clearedCount = 0;
33127
33608
  const errors = [];
33609
+ if (mode === "team") {
33610
+ collectTeamNamesForCleanup(getStateFilePath(root, "team"));
33611
+ }
33128
33612
  if (MODE_CONFIGS[mode]) {
33129
- const legacyStatePath = getStateFilePath(root, mode);
33130
- if ((0, import_fs12.existsSync)(legacyStatePath)) {
33613
+ const primaryLegacyStatePath = getStateFilePath(root, mode);
33614
+ if ((0, import_fs13.existsSync)(primaryLegacyStatePath)) {
33131
33615
  if (clearModeState(mode, root)) {
33132
33616
  clearedCount++;
33133
33617
  } else {
33134
33618
  errors.push("legacy path");
33135
33619
  }
33136
33620
  }
33137
- } else {
33138
- const statePath = getStatePath(mode, root);
33139
- if ((0, import_fs12.existsSync)(statePath)) {
33140
- try {
33141
- (0, import_fs12.unlinkSync)(statePath);
33142
- clearedCount++;
33143
- } catch {
33144
- errors.push("legacy path");
33145
- }
33146
- }
33621
+ }
33622
+ const extraLegacyCleanup = clearLegacyStateCandidates(mode, root);
33623
+ clearedCount += extraLegacyCleanup.cleared;
33624
+ if (extraLegacyCleanup.hadFailure) {
33625
+ errors.push("legacy path");
33626
+ }
33627
+ clearedCount += runtimeCleanup.cleared;
33628
+ if (runtimeCleanup.hadFailure) {
33629
+ errors.push("runtime artifacts");
33147
33630
  }
33148
33631
  const sessionIds = listSessionIds(root);
33149
33632
  for (const sid of sessionIds) {
33633
+ if (mode === "team") {
33634
+ collectTeamNamesForCleanup(resolveSessionStatePath("team", sid, root));
33635
+ }
33150
33636
  if (MODE_CONFIGS[mode]) {
33151
33637
  const sessionStatePath = getStateFilePath(root, mode, sid);
33152
- if ((0, import_fs12.existsSync)(sessionStatePath)) {
33638
+ if ((0, import_fs13.existsSync)(sessionStatePath)) {
33153
33639
  if (clearModeState(mode, root, sid)) {
33154
33640
  clearedCount++;
33155
33641
  } else {
@@ -33158,9 +33644,9 @@ var stateClearTool = {
33158
33644
  }
33159
33645
  } else {
33160
33646
  const statePath = resolveSessionStatePath(mode, sid, root);
33161
- if ((0, import_fs12.existsSync)(statePath)) {
33647
+ if ((0, import_fs13.existsSync)(statePath)) {
33162
33648
  try {
33163
- (0, import_fs12.unlinkSync)(statePath);
33649
+ (0, import_fs13.unlinkSync)(statePath);
33164
33650
  clearedCount++;
33165
33651
  } catch {
33166
33652
  errors.push(`session: ${sid}`);
@@ -33168,7 +33654,15 @@ var stateClearTool = {
33168
33654
  }
33169
33655
  }
33170
33656
  }
33171
- if (clearedCount === 0 && errors.length === 0) {
33657
+ let removedTeamRoots = 0;
33658
+ let prunedMissionEntries = 0;
33659
+ if (mode === "team") {
33660
+ const teamNames = [...cleanedTeamNames];
33661
+ const removeSelector = teamNames.length > 0 ? teamNames : void 0;
33662
+ removedTeamRoots = cleanupTeamRuntimeState(root, removeSelector);
33663
+ prunedMissionEntries = pruneMissionBoardTeams(root, removeSelector);
33664
+ }
33665
+ if (clearedCount === 0 && errors.length === 0 && removedTeamRoots === 0 && prunedMissionEntries === 0) {
33172
33666
  return {
33173
33667
  content: [{
33174
33668
  type: "text",
@@ -33182,6 +33676,16 @@ var stateClearTool = {
33182
33676
  message += `
33183
33677
  - Errors: ${errors.join(", ")}`;
33184
33678
  }
33679
+ if (mode === "team") {
33680
+ if (removedTeamRoots > 0) {
33681
+ message += `
33682
+ - Team runtime roots removed: ${removedTeamRoots}`;
33683
+ }
33684
+ if (prunedMissionEntries > 0) {
33685
+ message += `
33686
+ - HUD mission entries pruned: ${prunedMissionEntries}`;
33687
+ }
33688
+ }
33185
33689
  message += "\nWARNING: No session_id provided. Cleared legacy plus all session-scoped state; this is a broad operation that may affect other sessions.";
33186
33690
  return {
33187
33691
  content: [{
@@ -33219,8 +33723,8 @@ var stateListActiveTool = {
33219
33723
  for (const mode of EXTRA_STATE_ONLY_MODES) {
33220
33724
  try {
33221
33725
  const statePath = resolveSessionStatePath(mode, sessionId, root);
33222
- if ((0, import_fs12.existsSync)(statePath)) {
33223
- const content = (0, import_fs12.readFileSync)(statePath, "utf-8");
33726
+ if ((0, import_fs13.existsSync)(statePath)) {
33727
+ const content = (0, import_fs13.readFileSync)(statePath, "utf-8");
33224
33728
  const state = JSON.parse(content);
33225
33729
  if (state.active) {
33226
33730
  activeModes.push(mode);
@@ -33253,9 +33757,9 @@ ${modeList}`
33253
33757
  const legacyActiveModes = [...getActiveModes(root)];
33254
33758
  for (const mode of EXTRA_STATE_ONLY_MODES) {
33255
33759
  const statePath = getStatePath(mode, root);
33256
- if ((0, import_fs12.existsSync)(statePath)) {
33760
+ if ((0, import_fs13.existsSync)(statePath)) {
33257
33761
  try {
33258
- const content = (0, import_fs12.readFileSync)(statePath, "utf-8");
33762
+ const content = (0, import_fs13.readFileSync)(statePath, "utf-8");
33259
33763
  const state = JSON.parse(content);
33260
33764
  if (state.active) {
33261
33765
  legacyActiveModes.push(mode);
@@ -33276,8 +33780,8 @@ ${modeList}`
33276
33780
  for (const mode of EXTRA_STATE_ONLY_MODES) {
33277
33781
  try {
33278
33782
  const statePath = resolveSessionStatePath(mode, sid, root);
33279
- if ((0, import_fs12.existsSync)(statePath)) {
33280
- const content = (0, import_fs12.readFileSync)(statePath, "utf-8");
33783
+ if ((0, import_fs13.existsSync)(statePath)) {
33784
+ const content = (0, import_fs13.readFileSync)(statePath, "utf-8");
33281
33785
  const state = JSON.parse(content);
33282
33786
  if (state.active) {
33283
33787
  sessionActiveModes.push(mode);
@@ -33333,7 +33837,8 @@ var stateGetStatusTool = {
33333
33837
  session_id: external_exports3.string().optional().describe("Session ID for session-scoped state isolation. When provided, the tool operates only within that session. When omitted, the tool aggregates legacy state plus all session-scoped state (may include other sessions).")
33334
33838
  },
33335
33839
  handler: async (args) => {
33336
- const { mode, workingDirectory, session_id } = args;
33840
+ const { workingDirectory, session_id } = args;
33841
+ const mode = args.mode;
33337
33842
  try {
33338
33843
  const root = validateWorkingDirectory(workingDirectory);
33339
33844
  const sessionId = session_id;
@@ -33343,9 +33848,9 @@ var stateGetStatusTool = {
33343
33848
  if (sessionId) {
33344
33849
  validateSessionId(sessionId);
33345
33850
  const statePath = MODE_CONFIGS[mode] ? getStateFilePath(root, mode, sessionId) : resolveSessionStatePath(mode, sessionId, root);
33346
- const active = MODE_CONFIGS[mode] ? isModeActive(mode, root, sessionId) : (0, import_fs12.existsSync)(statePath) && (() => {
33851
+ const active = MODE_CONFIGS[mode] ? isModeActive(mode, root, sessionId) : (0, import_fs13.existsSync)(statePath) && (() => {
33347
33852
  try {
33348
- const content = (0, import_fs12.readFileSync)(statePath, "utf-8");
33853
+ const content = (0, import_fs13.readFileSync)(statePath, "utf-8");
33349
33854
  const state = JSON.parse(content);
33350
33855
  return state.active === true;
33351
33856
  } catch {
@@ -33353,9 +33858,9 @@ var stateGetStatusTool = {
33353
33858
  }
33354
33859
  })();
33355
33860
  let statePreview = "No state file";
33356
- if ((0, import_fs12.existsSync)(statePath)) {
33861
+ if ((0, import_fs13.existsSync)(statePath)) {
33357
33862
  try {
33358
- const content = (0, import_fs12.readFileSync)(statePath, "utf-8");
33863
+ const content = (0, import_fs13.readFileSync)(statePath, "utf-8");
33359
33864
  const state = JSON.parse(content);
33360
33865
  statePreview = JSON.stringify(state, null, 2).slice(0, 500);
33361
33866
  if (statePreview.length >= 500) statePreview += "\n...(truncated)";
@@ -33366,7 +33871,7 @@ var stateGetStatusTool = {
33366
33871
  lines2.push(`### Session: ${sessionId}`);
33367
33872
  lines2.push(`- **Active:** ${active ? "Yes" : "No"}`);
33368
33873
  lines2.push(`- **State Path:** ${statePath}`);
33369
- lines2.push(`- **Exists:** ${(0, import_fs12.existsSync)(statePath) ? "Yes" : "No"}`);
33874
+ lines2.push(`- **Exists:** ${(0, import_fs13.existsSync)(statePath) ? "Yes" : "No"}`);
33370
33875
  lines2.push(`
33371
33876
  ### State Preview
33372
33877
  \`\`\`json
@@ -33380,9 +33885,9 @@ ${statePreview}
33380
33885
  };
33381
33886
  }
33382
33887
  const legacyPath = getStatePath(mode, root);
33383
- const legacyActive = MODE_CONFIGS[mode] ? isModeActive(mode, root) : (0, import_fs12.existsSync)(legacyPath) && (() => {
33888
+ const legacyActive = MODE_CONFIGS[mode] ? isModeActive(mode, root) : (0, import_fs13.existsSync)(legacyPath) && (() => {
33384
33889
  try {
33385
- const content = (0, import_fs12.readFileSync)(legacyPath, "utf-8");
33890
+ const content = (0, import_fs13.readFileSync)(legacyPath, "utf-8");
33386
33891
  const state = JSON.parse(content);
33387
33892
  return state.active === true;
33388
33893
  } catch {
@@ -33392,13 +33897,13 @@ ${statePreview}
33392
33897
  lines2.push(`### Legacy Path`);
33393
33898
  lines2.push(`- **Active:** ${legacyActive ? "Yes" : "No"}`);
33394
33899
  lines2.push(`- **State Path:** ${legacyPath}`);
33395
- lines2.push(`- **Exists:** ${(0, import_fs12.existsSync)(legacyPath) ? "Yes" : "No"}
33900
+ lines2.push(`- **Exists:** ${(0, import_fs13.existsSync)(legacyPath) ? "Yes" : "No"}
33396
33901
  `);
33397
33902
  const activeSessions = MODE_CONFIGS[mode] ? getActiveSessionsForMode(mode, root) : listSessionIds(root).filter((sid) => {
33398
33903
  try {
33399
33904
  const sessionPath = resolveSessionStatePath(mode, sid, root);
33400
- if ((0, import_fs12.existsSync)(sessionPath)) {
33401
- const content = (0, import_fs12.readFileSync)(sessionPath, "utf-8");
33905
+ if ((0, import_fs13.existsSync)(sessionPath)) {
33906
+ const content = (0, import_fs13.readFileSync)(sessionPath, "utf-8");
33402
33907
  const state = JSON.parse(content);
33403
33908
  return state.active === true;
33404
33909
  }
@@ -33440,9 +33945,9 @@ No active sessions for this mode.`);
33440
33945
  for (const mode2 of EXTRA_STATE_ONLY_MODES) {
33441
33946
  const statePath = sessionId ? resolveSessionStatePath(mode2, sessionId, root) : getStatePath(mode2, root);
33442
33947
  let active = false;
33443
- if ((0, import_fs12.existsSync)(statePath)) {
33948
+ if ((0, import_fs13.existsSync)(statePath)) {
33444
33949
  try {
33445
- const content = (0, import_fs12.readFileSync)(statePath, "utf-8");
33950
+ const content = (0, import_fs13.readFileSync)(statePath, "utf-8");
33446
33951
  const state = JSON.parse(content);
33447
33952
  active = state.active === true;
33448
33953
  } catch {
@@ -33478,21 +33983,21 @@ var stateTools = [
33478
33983
  ];
33479
33984
 
33480
33985
  // src/hooks/notepad/index.ts
33481
- var import_fs14 = require("fs");
33482
- var import_path14 = require("path");
33986
+ var import_fs15 = require("fs");
33987
+ var import_path16 = require("path");
33483
33988
 
33484
33989
  // src/lib/file-lock.ts
33485
- var import_fs13 = require("fs");
33990
+ var import_fs14 = require("fs");
33486
33991
  var path6 = __toESM(require("path"), 1);
33487
33992
  var DEFAULT_STALE_LOCK_MS = 3e4;
33488
33993
  var DEFAULT_RETRY_DELAY_MS = 50;
33489
33994
  function isLockStale(lockPath, staleLockMs) {
33490
33995
  try {
33491
- const stat = (0, import_fs13.statSync)(lockPath);
33996
+ const stat = (0, import_fs14.statSync)(lockPath);
33492
33997
  const ageMs = Date.now() - stat.mtimeMs;
33493
33998
  if (ageMs < staleLockMs) return false;
33494
33999
  try {
33495
- const raw = (0, import_fs13.readFileSync)(lockPath, "utf-8");
34000
+ const raw = (0, import_fs14.readFileSync)(lockPath, "utf-8");
33496
34001
  const payload = JSON.parse(raw);
33497
34002
  if (payload.pid && isProcessAlive(payload.pid)) return false;
33498
34003
  } catch {
@@ -33508,21 +34013,21 @@ function lockPathFor(filePath) {
33508
34013
  function tryAcquireSync(lockPath, staleLockMs) {
33509
34014
  ensureDirSync(path6.dirname(lockPath));
33510
34015
  try {
33511
- const fd = (0, import_fs13.openSync)(
34016
+ const fd = (0, import_fs14.openSync)(
33512
34017
  lockPath,
33513
- import_fs13.constants.O_CREAT | import_fs13.constants.O_EXCL | import_fs13.constants.O_WRONLY,
34018
+ import_fs14.constants.O_CREAT | import_fs14.constants.O_EXCL | import_fs14.constants.O_WRONLY,
33514
34019
  384
33515
34020
  );
33516
34021
  try {
33517
34022
  const payload = JSON.stringify({ pid: process.pid, timestamp: Date.now() });
33518
- (0, import_fs13.writeSync)(fd, payload, null, "utf-8");
34023
+ (0, import_fs14.writeSync)(fd, payload, null, "utf-8");
33519
34024
  } catch (writeErr) {
33520
34025
  try {
33521
- (0, import_fs13.closeSync)(fd);
34026
+ (0, import_fs14.closeSync)(fd);
33522
34027
  } catch {
33523
34028
  }
33524
34029
  try {
33525
- (0, import_fs13.unlinkSync)(lockPath);
34030
+ (0, import_fs14.unlinkSync)(lockPath);
33526
34031
  } catch {
33527
34032
  }
33528
34033
  throw writeErr;
@@ -33532,25 +34037,25 @@ function tryAcquireSync(lockPath, staleLockMs) {
33532
34037
  if (err && typeof err === "object" && "code" in err && err.code === "EEXIST") {
33533
34038
  if (isLockStale(lockPath, staleLockMs)) {
33534
34039
  try {
33535
- (0, import_fs13.unlinkSync)(lockPath);
34040
+ (0, import_fs14.unlinkSync)(lockPath);
33536
34041
  } catch {
33537
34042
  }
33538
34043
  try {
33539
- const fd = (0, import_fs13.openSync)(
34044
+ const fd = (0, import_fs14.openSync)(
33540
34045
  lockPath,
33541
- import_fs13.constants.O_CREAT | import_fs13.constants.O_EXCL | import_fs13.constants.O_WRONLY,
34046
+ import_fs14.constants.O_CREAT | import_fs14.constants.O_EXCL | import_fs14.constants.O_WRONLY,
33542
34047
  384
33543
34048
  );
33544
34049
  try {
33545
34050
  const payload = JSON.stringify({ pid: process.pid, timestamp: Date.now() });
33546
- (0, import_fs13.writeSync)(fd, payload, null, "utf-8");
34051
+ (0, import_fs14.writeSync)(fd, payload, null, "utf-8");
33547
34052
  } catch (writeErr) {
33548
34053
  try {
33549
- (0, import_fs13.closeSync)(fd);
34054
+ (0, import_fs14.closeSync)(fd);
33550
34055
  } catch {
33551
34056
  }
33552
34057
  try {
33553
- (0, import_fs13.unlinkSync)(lockPath);
34058
+ (0, import_fs14.unlinkSync)(lockPath);
33554
34059
  } catch {
33555
34060
  }
33556
34061
  throw writeErr;
@@ -33590,11 +34095,11 @@ function acquireFileLockSync(lockPath, opts) {
33590
34095
  }
33591
34096
  function releaseFileLockSync(handle) {
33592
34097
  try {
33593
- (0, import_fs13.closeSync)(handle.fd);
34098
+ (0, import_fs14.closeSync)(handle.fd);
33594
34099
  } catch {
33595
34100
  }
33596
34101
  try {
33597
- (0, import_fs13.unlinkSync)(handle.path);
34102
+ (0, import_fs14.unlinkSync)(handle.path);
33598
34103
  } catch {
33599
34104
  }
33600
34105
  }
@@ -33668,19 +34173,19 @@ function getSectionRegexSet(header) {
33668
34173
  return SECTION_REGEXES[header] ?? createSectionRegexSet(header);
33669
34174
  }
33670
34175
  function getNotepadPath(directory) {
33671
- return (0, import_path14.join)(getOmcRoot(directory), NOTEPAD_FILENAME);
34176
+ return (0, import_path16.join)(getSharedOmcRoot(directory), NOTEPAD_FILENAME);
33672
34177
  }
33673
34178
  function initNotepad(directory) {
33674
- const omcDir = getOmcRoot(directory);
33675
- if (!(0, import_fs14.existsSync)(omcDir)) {
34179
+ const omcDir = getSharedOmcRoot(directory);
34180
+ if (!(0, import_fs15.existsSync)(omcDir)) {
33676
34181
  try {
33677
- (0, import_fs14.mkdirSync)(omcDir, { recursive: true });
34182
+ (0, import_fs15.mkdirSync)(omcDir, { recursive: true });
33678
34183
  } catch {
33679
34184
  return false;
33680
34185
  }
33681
34186
  }
33682
34187
  const notepadPath = getNotepadPath(directory);
33683
- if ((0, import_fs14.existsSync)(notepadPath)) {
34188
+ if ((0, import_fs15.existsSync)(notepadPath)) {
33684
34189
  return true;
33685
34190
  }
33686
34191
  const content = `# Notepad
@@ -33705,11 +34210,11 @@ ${MANUAL_HEADER}
33705
34210
  }
33706
34211
  function readNotepad(directory) {
33707
34212
  const notepadPath = getNotepadPath(directory);
33708
- if (!(0, import_fs14.existsSync)(notepadPath)) {
34213
+ if (!(0, import_fs15.existsSync)(notepadPath)) {
33709
34214
  return null;
33710
34215
  }
33711
34216
  try {
33712
- return (0, import_fs14.readFileSync)(notepadPath, "utf-8");
34217
+ return (0, import_fs15.readFileSync)(notepadPath, "utf-8");
33713
34218
  } catch {
33714
34219
  return null;
33715
34220
  }
@@ -33753,7 +34258,7 @@ function getManualSection(directory) {
33753
34258
  return extractSection(content, MANUAL_HEADER);
33754
34259
  }
33755
34260
  function setPriorityContext(directory, content, config2 = DEFAULT_CONFIG) {
33756
- if (!(0, import_fs14.existsSync)(getNotepadPath(directory))) {
34261
+ if (!(0, import_fs15.existsSync)(getNotepadPath(directory))) {
33757
34262
  if (!initNotepad(directory)) {
33758
34263
  return { success: false };
33759
34264
  }
@@ -33761,7 +34266,7 @@ function setPriorityContext(directory, content, config2 = DEFAULT_CONFIG) {
33761
34266
  const notepadPath = getNotepadPath(directory);
33762
34267
  try {
33763
34268
  return withFileLockSync(lockPathFor(notepadPath), () => {
33764
- let notepadContent = (0, import_fs14.readFileSync)(notepadPath, "utf-8");
34269
+ let notepadContent = (0, import_fs15.readFileSync)(notepadPath, "utf-8");
33765
34270
  const warning = content.length > config2.priorityMaxChars ? `Priority Context exceeds ${config2.priorityMaxChars} chars (${content.length} chars). Consider condensing.` : void 0;
33766
34271
  notepadContent = replaceSection(notepadContent, PRIORITY_HEADER, content);
33767
34272
  atomicWriteFileSync(notepadPath, notepadContent);
@@ -33772,7 +34277,7 @@ function setPriorityContext(directory, content, config2 = DEFAULT_CONFIG) {
33772
34277
  }
33773
34278
  }
33774
34279
  function addWorkingMemoryEntry(directory, content) {
33775
- if (!(0, import_fs14.existsSync)(getNotepadPath(directory))) {
34280
+ if (!(0, import_fs15.existsSync)(getNotepadPath(directory))) {
33776
34281
  if (!initNotepad(directory)) {
33777
34282
  return false;
33778
34283
  }
@@ -33780,7 +34285,7 @@ function addWorkingMemoryEntry(directory, content) {
33780
34285
  const notepadPath = getNotepadPath(directory);
33781
34286
  try {
33782
34287
  return withFileLockSync(lockPathFor(notepadPath), () => {
33783
- let notepadContent = (0, import_fs14.readFileSync)(notepadPath, "utf-8");
34288
+ let notepadContent = (0, import_fs15.readFileSync)(notepadPath, "utf-8");
33784
34289
  const currentMemory = extractSection(notepadContent, WORKING_MEMORY_HEADER) || "";
33785
34290
  const now = /* @__PURE__ */ new Date();
33786
34291
  const timestamp = now.toISOString().slice(0, 16).replace("T", " ");
@@ -33801,7 +34306,7 @@ ${content}
33801
34306
  }
33802
34307
  }
33803
34308
  function addManualEntry(directory, content) {
33804
- if (!(0, import_fs14.existsSync)(getNotepadPath(directory))) {
34309
+ if (!(0, import_fs15.existsSync)(getNotepadPath(directory))) {
33805
34310
  if (!initNotepad(directory)) {
33806
34311
  return false;
33807
34312
  }
@@ -33809,7 +34314,7 @@ function addManualEntry(directory, content) {
33809
34314
  const notepadPath = getNotepadPath(directory);
33810
34315
  try {
33811
34316
  return withFileLockSync(lockPathFor(notepadPath), () => {
33812
- let notepadContent = (0, import_fs14.readFileSync)(notepadPath, "utf-8");
34317
+ let notepadContent = (0, import_fs15.readFileSync)(notepadPath, "utf-8");
33813
34318
  const currentManual = extractSection(notepadContent, MANUAL_HEADER) || "";
33814
34319
  const now = /* @__PURE__ */ new Date();
33815
34320
  const timestamp = now.toISOString().slice(0, 16).replace("T", " ");
@@ -33827,12 +34332,12 @@ ${content}
33827
34332
  }
33828
34333
  function pruneOldEntries(directory, daysOld = DEFAULT_CONFIG.workingMemoryDays) {
33829
34334
  const notepadPath = getNotepadPath(directory);
33830
- if (!(0, import_fs14.existsSync)(notepadPath)) {
34335
+ if (!(0, import_fs15.existsSync)(notepadPath)) {
33831
34336
  return { pruned: 0, remaining: 0 };
33832
34337
  }
33833
34338
  try {
33834
34339
  return withFileLockSync(lockPathFor(notepadPath), () => {
33835
- let notepadContent = (0, import_fs14.readFileSync)(notepadPath, "utf-8");
34340
+ let notepadContent = (0, import_fs15.readFileSync)(notepadPath, "utf-8");
33836
34341
  const workingMemory = extractSection(notepadContent, WORKING_MEMORY_HEADER);
33837
34342
  if (!workingMemory) {
33838
34343
  return { pruned: 0, remaining: 0 };
@@ -33870,7 +34375,7 @@ ${entry.content}`).join("\n\n");
33870
34375
  }
33871
34376
  function getNotepadStats(directory) {
33872
34377
  const notepadPath = getNotepadPath(directory);
33873
- if (!(0, import_fs14.existsSync)(notepadPath)) {
34378
+ if (!(0, import_fs15.existsSync)(notepadPath)) {
33874
34379
  return {
33875
34380
  exists: false,
33876
34381
  totalSize: 0,
@@ -33879,7 +34384,7 @@ function getNotepadStats(directory) {
33879
34384
  oldestEntry: null
33880
34385
  };
33881
34386
  }
33882
- const content = (0, import_fs14.readFileSync)(notepadPath, "utf-8");
34387
+ const content = (0, import_fs15.readFileSync)(notepadPath, "utf-8");
33883
34388
  const priorityContext = extractSection(content, PRIORITY_HEADER) || "";
33884
34389
  const workingMemory = extractSection(content, WORKING_MEMORY_HEADER) || "";
33885
34390
  const wmMatches = workingMemory.match(
@@ -34198,7 +34703,7 @@ var notepadTools = [
34198
34703
  ];
34199
34704
 
34200
34705
  // src/hooks/project-memory/index.ts
34201
- var import_path22 = __toESM(require("path"), 1);
34706
+ var import_path24 = __toESM(require("path"), 1);
34202
34707
 
34203
34708
  // src/features/context-injector/collector.ts
34204
34709
  var PRIORITY_ORDER = {
@@ -34308,18 +34813,18 @@ var ContextCollector = class {
34308
34813
  var contextCollector = new ContextCollector();
34309
34814
 
34310
34815
  // src/hooks/rules-injector/finder.ts
34311
- var import_fs15 = require("fs");
34312
- var import_path16 = require("path");
34816
+ var import_fs16 = require("fs");
34817
+ var import_path18 = require("path");
34313
34818
 
34314
34819
  // src/hooks/rules-injector/constants.ts
34315
- var import_path15 = require("path");
34820
+ var import_path17 = require("path");
34316
34821
  var import_os4 = require("os");
34317
- var OMC_STORAGE_DIR = (0, import_path15.join)((0, import_os4.homedir)(), ".omcp");
34318
- var RULES_INJECTOR_STORAGE = (0, import_path15.join)(OMC_STORAGE_DIR, "rules-injector");
34822
+ var OMC_STORAGE_DIR = (0, import_path17.join)((0, import_os4.homedir)(), ".omcp");
34823
+ var RULES_INJECTOR_STORAGE = (0, import_path17.join)(OMC_STORAGE_DIR, "rules-injector");
34319
34824
 
34320
34825
  // src/hooks/project-memory/storage.ts
34321
34826
  var import_promises = __toESM(require("fs/promises"), 1);
34322
- var import_path17 = __toESM(require("path"), 1);
34827
+ var import_path19 = __toESM(require("path"), 1);
34323
34828
 
34324
34829
  // src/hooks/project-memory/constants.ts
34325
34830
  var CACHE_EXPIRY_MS = 24 * 60 * 60 * 1e3;
@@ -34343,7 +34848,7 @@ async function loadProjectMemory(projectRoot) {
34343
34848
  }
34344
34849
  async function saveProjectMemory(projectRoot, memory) {
34345
34850
  const memoryPath = getMemoryPath(projectRoot);
34346
- const omcDir = import_path17.default.dirname(memoryPath);
34851
+ const omcDir = import_path19.default.dirname(memoryPath);
34347
34852
  try {
34348
34853
  await import_promises.default.mkdir(omcDir, { recursive: true });
34349
34854
  await atomicWriteJson(memoryPath, memory);
@@ -34359,17 +34864,17 @@ async function withProjectMemoryLock(projectRoot, fn) {
34359
34864
 
34360
34865
  // src/hooks/project-memory/detector.ts
34361
34866
  var import_promises3 = __toESM(require("fs/promises"), 1);
34362
- var import_path19 = __toESM(require("path"), 1);
34867
+ var import_path21 = __toESM(require("path"), 1);
34363
34868
 
34364
34869
  // src/hooks/project-memory/directory-mapper.ts
34365
34870
  var import_promises2 = __toESM(require("fs/promises"), 1);
34366
- var import_path18 = __toESM(require("path"), 1);
34871
+ var import_path20 = __toESM(require("path"), 1);
34367
34872
 
34368
34873
  // src/hooks/project-memory/formatter.ts
34369
- var import_path21 = __toESM(require("path"), 1);
34874
+ var import_path23 = __toESM(require("path"), 1);
34370
34875
 
34371
34876
  // src/hooks/project-memory/hot-path-tracker.ts
34372
- var import_path20 = __toESM(require("path"), 1);
34877
+ var import_path22 = __toESM(require("path"), 1);
34373
34878
 
34374
34879
  // src/hooks/project-memory/directive-detector.ts
34375
34880
  function addDirective(directives, newDirective) {
@@ -34754,27 +35259,27 @@ var memoryTools = [
34754
35259
  ];
34755
35260
 
34756
35261
  // src/tools/trace-tools.ts
34757
- var import_fs17 = require("fs");
34758
- var import_path24 = require("path");
35262
+ var import_fs18 = require("fs");
35263
+ var import_path26 = require("path");
34759
35264
 
34760
35265
  // src/hooks/subagent-tracker/session-replay.ts
34761
- var import_fs16 = require("fs");
34762
- var import_path23 = require("path");
35266
+ var import_fs17 = require("fs");
35267
+ var import_path25 = require("path");
34763
35268
  var REPLAY_PREFIX = "agent-replay-";
34764
35269
  var MAX_REPLAY_SIZE_BYTES = 5 * 1024 * 1024;
34765
35270
  function getReplayFilePath(directory, sessionId) {
34766
- const stateDir = (0, import_path23.join)(getOmcRoot(directory), "state");
34767
- if (!(0, import_fs16.existsSync)(stateDir)) {
34768
- (0, import_fs16.mkdirSync)(stateDir, { recursive: true });
35271
+ const stateDir = (0, import_path25.join)(getOmcRoot(directory), "state");
35272
+ if (!(0, import_fs17.existsSync)(stateDir)) {
35273
+ (0, import_fs17.mkdirSync)(stateDir, { recursive: true });
34769
35274
  }
34770
35275
  const safeId = sessionId.replace(/[^a-zA-Z0-9_-]/g, "_");
34771
- return (0, import_path23.join)(stateDir, `${REPLAY_PREFIX}${safeId}.jsonl`);
35276
+ return (0, import_path25.join)(stateDir, `${REPLAY_PREFIX}${safeId}.jsonl`);
34772
35277
  }
34773
35278
  function readReplayEvents(directory, sessionId) {
34774
35279
  const filePath = getReplayFilePath(directory, sessionId);
34775
- if (!(0, import_fs16.existsSync)(filePath)) return [];
35280
+ if (!(0, import_fs17.existsSync)(filePath)) return [];
34776
35281
  try {
34777
- const content = (0, import_fs16.readFileSync)(filePath, "utf-8");
35282
+ const content = (0, import_fs17.readFileSync)(filePath, "utf-8");
34778
35283
  return content.split("\n").filter((line) => line.trim()).map((line) => {
34779
35284
  try {
34780
35285
  return JSON.parse(line);
@@ -34947,12 +35452,12 @@ function getReplaySummary(directory, sessionId) {
34947
35452
  // src/tools/trace-tools.ts
34948
35453
  var REPLAY_PREFIX2 = "agent-replay-";
34949
35454
  function findLatestSessionId(directory) {
34950
- const stateDir = (0, import_path24.join)(directory, ".omcp", "state");
35455
+ const stateDir = (0, import_path26.join)(directory, ".omcp", "state");
34951
35456
  try {
34952
- const files = (0, import_fs17.readdirSync)(stateDir).filter((f) => f.startsWith(REPLAY_PREFIX2) && f.endsWith(".jsonl")).map((f) => ({
35457
+ const files = (0, import_fs18.readdirSync)(stateDir).filter((f) => f.startsWith(REPLAY_PREFIX2) && f.endsWith(".jsonl")).map((f) => ({
34953
35458
  name: f,
34954
35459
  sessionId: f.slice(REPLAY_PREFIX2.length, -".jsonl".length),
34955
- mtime: (0, import_fs17.statSync)((0, import_path24.join)(stateDir, f)).mtimeMs
35460
+ mtime: (0, import_fs18.statSync)((0, import_path26.join)(stateDir, f)).mtimeMs
34956
35461
  })).sort((a, b) => b.mtime - a.mtime);
34957
35462
  return files.length > 0 ? files[0].sessionId : null;
34958
35463
  } catch {
@@ -35296,18 +35801,18 @@ No events recorded.`
35296
35801
  var traceTools = [traceTimelineTool, traceSummaryTool];
35297
35802
 
35298
35803
  // src/lib/shared-memory.ts
35299
- var import_fs18 = require("fs");
35300
- var import_path25 = require("path");
35804
+ var import_fs19 = require("fs");
35805
+ var import_path27 = require("path");
35301
35806
  var CONFIG_FILE_NAME = ".omc-config.json";
35302
35807
  function isSharedMemoryEnabled() {
35303
35808
  try {
35304
- const configPath = (0, import_path25.join)(
35809
+ const configPath = (0, import_path27.join)(
35305
35810
  process.env.HOME || process.env.USERPROFILE || "",
35306
35811
  ".copilot",
35307
35812
  CONFIG_FILE_NAME
35308
35813
  );
35309
- if (!(0, import_fs18.existsSync)(configPath)) return true;
35310
- const raw = JSON.parse((0, import_fs18.readFileSync)(configPath, "utf-8"));
35814
+ if (!(0, import_fs19.existsSync)(configPath)) return true;
35815
+ const raw = JSON.parse((0, import_fs19.readFileSync)(configPath, "utf-8"));
35311
35816
  const enabled = raw?.agents?.sharedMemory?.enabled;
35312
35817
  if (typeof enabled === "boolean") return enabled;
35313
35818
  return true;
@@ -35341,16 +35846,16 @@ function validateKey(key) {
35341
35846
  function getNamespaceDir(namespace, worktreeRoot) {
35342
35847
  validateNamespace(namespace);
35343
35848
  const omcRoot = getOmcRoot(worktreeRoot);
35344
- return (0, import_path25.join)(omcRoot, SHARED_MEMORY_DIR, namespace);
35849
+ return (0, import_path27.join)(omcRoot, SHARED_MEMORY_DIR, namespace);
35345
35850
  }
35346
35851
  function getEntryPath(namespace, key, worktreeRoot) {
35347
35852
  validateKey(key);
35348
- return (0, import_path25.join)(getNamespaceDir(namespace, worktreeRoot), `${key}.json`);
35853
+ return (0, import_path27.join)(getNamespaceDir(namespace, worktreeRoot), `${key}.json`);
35349
35854
  }
35350
35855
  function ensureNamespaceDir(namespace, worktreeRoot) {
35351
35856
  const dir = getNamespaceDir(namespace, worktreeRoot);
35352
- if (!(0, import_fs18.existsSync)(dir)) {
35353
- (0, import_fs18.mkdirSync)(dir, { recursive: true });
35857
+ if (!(0, import_fs19.existsSync)(dir)) {
35858
+ (0, import_fs19.mkdirSync)(dir, { recursive: true });
35354
35859
  }
35355
35860
  return dir;
35356
35861
  }
@@ -35365,9 +35870,9 @@ function writeEntry(namespace, key, value, ttl, worktreeRoot) {
35365
35870
  const lockPath = filePath + ".lock";
35366
35871
  const doWrite = () => {
35367
35872
  let existingCreatedAt = now;
35368
- if ((0, import_fs18.existsSync)(filePath)) {
35873
+ if ((0, import_fs19.existsSync)(filePath)) {
35369
35874
  try {
35370
- const existing = JSON.parse((0, import_fs18.readFileSync)(filePath, "utf-8"));
35875
+ const existing = JSON.parse((0, import_fs19.readFileSync)(filePath, "utf-8"));
35371
35876
  existingCreatedAt = existing.createdAt || now;
35372
35877
  } catch {
35373
35878
  }
@@ -35384,11 +35889,11 @@ function writeEntry(namespace, key, value, ttl, worktreeRoot) {
35384
35889
  entry.expiresAt = new Date(Date.now() + ttl * 1e3).toISOString();
35385
35890
  }
35386
35891
  const tmpPath = `${filePath}.tmp.${process.pid}.${Date.now()}`;
35387
- (0, import_fs18.writeFileSync)(tmpPath, JSON.stringify(entry, null, 2), "utf-8");
35388
- (0, import_fs18.renameSync)(tmpPath, filePath);
35892
+ (0, import_fs19.writeFileSync)(tmpPath, JSON.stringify(entry, null, 2), "utf-8");
35893
+ (0, import_fs19.renameSync)(tmpPath, filePath);
35389
35894
  try {
35390
35895
  const legacyTmp = filePath + ".tmp";
35391
- if ((0, import_fs18.existsSync)(legacyTmp)) (0, import_fs18.unlinkSync)(legacyTmp);
35896
+ if ((0, import_fs19.existsSync)(legacyTmp)) (0, import_fs19.unlinkSync)(legacyTmp);
35392
35897
  } catch {
35393
35898
  }
35394
35899
  return entry;
@@ -35403,12 +35908,12 @@ function readEntry(namespace, key, worktreeRoot) {
35403
35908
  validateNamespace(namespace);
35404
35909
  validateKey(key);
35405
35910
  const filePath = getEntryPath(namespace, key, worktreeRoot);
35406
- if (!(0, import_fs18.existsSync)(filePath)) return null;
35911
+ if (!(0, import_fs19.existsSync)(filePath)) return null;
35407
35912
  try {
35408
- const entry = JSON.parse((0, import_fs18.readFileSync)(filePath, "utf-8"));
35913
+ const entry = JSON.parse((0, import_fs19.readFileSync)(filePath, "utf-8"));
35409
35914
  if (isExpired(entry)) {
35410
35915
  try {
35411
- (0, import_fs18.unlinkSync)(filePath);
35916
+ (0, import_fs19.unlinkSync)(filePath);
35412
35917
  } catch {
35413
35918
  }
35414
35919
  return null;
@@ -35421,14 +35926,14 @@ function readEntry(namespace, key, worktreeRoot) {
35421
35926
  function listEntries(namespace, worktreeRoot) {
35422
35927
  validateNamespace(namespace);
35423
35928
  const dir = getNamespaceDir(namespace, worktreeRoot);
35424
- if (!(0, import_fs18.existsSync)(dir)) return [];
35929
+ if (!(0, import_fs19.existsSync)(dir)) return [];
35425
35930
  const items = [];
35426
35931
  try {
35427
- const files = (0, import_fs18.readdirSync)(dir).filter((f) => f.endsWith(".json"));
35932
+ const files = (0, import_fs19.readdirSync)(dir).filter((f) => f.endsWith(".json"));
35428
35933
  for (const file2 of files) {
35429
35934
  try {
35430
- const filePath = (0, import_path25.join)(dir, file2);
35431
- const entry = JSON.parse((0, import_fs18.readFileSync)(filePath, "utf-8"));
35935
+ const filePath = (0, import_path27.join)(dir, file2);
35936
+ const entry = JSON.parse((0, import_fs19.readFileSync)(filePath, "utf-8"));
35432
35937
  if (!isExpired(entry)) {
35433
35938
  items.push({
35434
35939
  key: entry.key,
@@ -35447,9 +35952,9 @@ function deleteEntry(namespace, key, worktreeRoot) {
35447
35952
  validateNamespace(namespace);
35448
35953
  validateKey(key);
35449
35954
  const filePath = getEntryPath(namespace, key, worktreeRoot);
35450
- if (!(0, import_fs18.existsSync)(filePath)) return false;
35955
+ if (!(0, import_fs19.existsSync)(filePath)) return false;
35451
35956
  try {
35452
- (0, import_fs18.unlinkSync)(filePath);
35957
+ (0, import_fs19.unlinkSync)(filePath);
35453
35958
  return true;
35454
35959
  } catch {
35455
35960
  return false;
@@ -35457,15 +35962,15 @@ function deleteEntry(namespace, key, worktreeRoot) {
35457
35962
  }
35458
35963
  function cleanupExpired(namespace, worktreeRoot) {
35459
35964
  const omcRoot = getOmcRoot(worktreeRoot);
35460
- const sharedMemDir = (0, import_path25.join)(omcRoot, SHARED_MEMORY_DIR);
35461
- if (!(0, import_fs18.existsSync)(sharedMemDir)) return { removed: 0, namespaces: [] };
35965
+ const sharedMemDir = (0, import_path27.join)(omcRoot, SHARED_MEMORY_DIR);
35966
+ if (!(0, import_fs19.existsSync)(sharedMemDir)) return { removed: 0, namespaces: [] };
35462
35967
  const namespacesToClean = [];
35463
35968
  if (namespace) {
35464
35969
  validateNamespace(namespace);
35465
35970
  namespacesToClean.push(namespace);
35466
35971
  } else {
35467
35972
  try {
35468
- const entries = (0, import_fs18.readdirSync)(sharedMemDir, { withFileTypes: true });
35973
+ const entries = (0, import_fs19.readdirSync)(sharedMemDir, { withFileTypes: true });
35469
35974
  for (const entry of entries) {
35470
35975
  if (entry.isDirectory()) {
35471
35976
  namespacesToClean.push(entry.name);
@@ -35478,17 +35983,17 @@ function cleanupExpired(namespace, worktreeRoot) {
35478
35983
  let removed = 0;
35479
35984
  const cleanedNamespaces = [];
35480
35985
  for (const ns of namespacesToClean) {
35481
- const nsDir = (0, import_path25.join)(sharedMemDir, ns);
35482
- if (!(0, import_fs18.existsSync)(nsDir)) continue;
35986
+ const nsDir = (0, import_path27.join)(sharedMemDir, ns);
35987
+ if (!(0, import_fs19.existsSync)(nsDir)) continue;
35483
35988
  let nsRemoved = 0;
35484
35989
  try {
35485
- const files = (0, import_fs18.readdirSync)(nsDir).filter((f) => f.endsWith(".json"));
35990
+ const files = (0, import_fs19.readdirSync)(nsDir).filter((f) => f.endsWith(".json"));
35486
35991
  for (const file2 of files) {
35487
35992
  try {
35488
- const filePath = (0, import_path25.join)(nsDir, file2);
35489
- const entry = JSON.parse((0, import_fs18.readFileSync)(filePath, "utf-8"));
35993
+ const filePath = (0, import_path27.join)(nsDir, file2);
35994
+ const entry = JSON.parse((0, import_fs19.readFileSync)(filePath, "utf-8"));
35490
35995
  if (isExpired(entry)) {
35491
- (0, import_fs18.unlinkSync)(filePath);
35996
+ (0, import_fs19.unlinkSync)(filePath);
35492
35997
  nsRemoved++;
35493
35998
  }
35494
35999
  } catch {
@@ -35505,10 +36010,10 @@ function cleanupExpired(namespace, worktreeRoot) {
35505
36010
  }
35506
36011
  function listNamespaces(worktreeRoot) {
35507
36012
  const omcRoot = getOmcRoot(worktreeRoot);
35508
- const sharedMemDir = (0, import_path25.join)(omcRoot, SHARED_MEMORY_DIR);
35509
- if (!(0, import_fs18.existsSync)(sharedMemDir)) return [];
36013
+ const sharedMemDir = (0, import_path27.join)(omcRoot, SHARED_MEMORY_DIR);
36014
+ if (!(0, import_fs19.existsSync)(sharedMemDir)) return [];
35510
36015
  try {
35511
- const entries = (0, import_fs18.readdirSync)(sharedMemDir, { withFileTypes: true });
36016
+ const entries = (0, import_fs19.readdirSync)(sharedMemDir, { withFileTypes: true });
35512
36017
  return entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
35513
36018
  } catch {
35514
36019
  return [];
@@ -36064,28 +36569,28 @@ var DEFAULT_WIKI_CONFIG = {
36064
36569
  };
36065
36570
 
36066
36571
  // src/hooks/wiki/storage.ts
36067
- var import_fs19 = require("fs");
36068
- var import_path26 = require("path");
36572
+ var import_fs20 = require("fs");
36573
+ var import_path28 = require("path");
36069
36574
  var WIKI_DIR = "wiki";
36070
36575
  var INDEX_FILE = "index.md";
36071
36576
  var LOG_FILE = "log.md";
36072
36577
  var ENVIRONMENT_FILE = "environment.md";
36073
36578
  var RESERVED_FILES = /* @__PURE__ */ new Set([INDEX_FILE, LOG_FILE, ENVIRONMENT_FILE]);
36074
36579
  function getOmcDir(root) {
36075
- return (0, import_path26.join)(root, ".omcp");
36580
+ return (0, import_path28.join)(root, ".omcp");
36076
36581
  }
36077
36582
  function getWikiDir(root) {
36078
- return (0, import_path26.join)(getOmcDir(root), WIKI_DIR);
36583
+ return (0, import_path28.join)(getOmcDir(root), WIKI_DIR);
36079
36584
  }
36080
36585
  function ensureWikiDir(root) {
36081
36586
  const wikiDir = getWikiDir(root);
36082
- if (!(0, import_fs19.existsSync)(wikiDir)) {
36083
- (0, import_fs19.mkdirSync)(wikiDir, { recursive: true });
36587
+ if (!(0, import_fs20.existsSync)(wikiDir)) {
36588
+ (0, import_fs20.mkdirSync)(wikiDir, { recursive: true });
36084
36589
  }
36085
36590
  const omcRoot = getOmcDir(root);
36086
- const gitignorePath = (0, import_path26.join)(omcRoot, ".gitignore");
36087
- if ((0, import_fs19.existsSync)(gitignorePath)) {
36088
- const content = (0, import_fs19.readFileSync)(gitignorePath, "utf-8");
36591
+ const gitignorePath = (0, import_path28.join)(omcRoot, ".gitignore");
36592
+ if ((0, import_fs20.existsSync)(gitignorePath)) {
36593
+ const content = (0, import_fs20.readFileSync)(gitignorePath, "utf-8");
36089
36594
  if (!content.includes("wiki/")) {
36090
36595
  atomicWriteFileSync(gitignorePath, content.trimEnd() + "\nwiki/\n");
36091
36596
  }
@@ -36096,7 +36601,7 @@ function ensureWikiDir(root) {
36096
36601
  }
36097
36602
  function withWikiLock(root, fn) {
36098
36603
  const wikiDir = ensureWikiDir(root);
36099
- const lockPath = lockPathFor((0, import_path26.join)(wikiDir, ".wiki-lock"));
36604
+ const lockPath = lockPathFor((0, import_path28.join)(wikiDir, ".wiki-lock"));
36100
36605
  return withFileLockSync(lockPath, fn, { timeoutMs: 5e3, retryDelayMs: 50 });
36101
36606
  }
36102
36607
  function parseFrontmatter(raw) {
@@ -36178,9 +36683,9 @@ function safeWikiPath(wikiDir, filename) {
36178
36683
  if (filename.includes("/") || filename.includes("\\") || filename.includes("..")) {
36179
36684
  return null;
36180
36685
  }
36181
- const filePath = (0, import_path26.join)(wikiDir, filename);
36182
- const resolved = (0, import_path26.resolve)(filePath);
36183
- if (!resolved.startsWith((0, import_path26.resolve)(wikiDir) + import_path26.sep)) {
36686
+ const filePath = (0, import_path28.join)(wikiDir, filename);
36687
+ const resolved = (0, import_path28.resolve)(filePath);
36688
+ if (!resolved.startsWith((0, import_path28.resolve)(wikiDir) + import_path28.sep)) {
36184
36689
  return null;
36185
36690
  }
36186
36691
  return filePath;
@@ -36189,9 +36694,9 @@ function readPage(root, filename) {
36189
36694
  const wikiDir = getWikiDir(root);
36190
36695
  const filePath = safeWikiPath(wikiDir, filename);
36191
36696
  if (!filePath) return null;
36192
- if (!(0, import_fs19.existsSync)(filePath)) return null;
36697
+ if (!(0, import_fs20.existsSync)(filePath)) return null;
36193
36698
  try {
36194
- const raw = (0, import_fs19.readFileSync)(filePath, "utf-8");
36699
+ const raw = (0, import_fs20.readFileSync)(filePath, "utf-8");
36195
36700
  const parsed = parseFrontmatter(raw);
36196
36701
  if (!parsed) return null;
36197
36702
  return {
@@ -36205,16 +36710,16 @@ function readPage(root, filename) {
36205
36710
  }
36206
36711
  function listPages(root) {
36207
36712
  const wikiDir = getWikiDir(root);
36208
- if (!(0, import_fs19.existsSync)(wikiDir)) return [];
36209
- return (0, import_fs19.readdirSync)(wikiDir).filter((f) => f.endsWith(".md") && !RESERVED_FILES.has(f)).sort();
36713
+ if (!(0, import_fs20.existsSync)(wikiDir)) return [];
36714
+ return (0, import_fs20.readdirSync)(wikiDir).filter((f) => f.endsWith(".md") && !RESERVED_FILES.has(f)).sort();
36210
36715
  }
36211
36716
  function readAllPages(root) {
36212
36717
  return listPages(root).map((f) => readPage(root, f)).filter((p) => p !== null);
36213
36718
  }
36214
36719
  function readIndex(root) {
36215
- const indexPath = (0, import_path26.join)(getWikiDir(root), INDEX_FILE);
36216
- if (!(0, import_fs19.existsSync)(indexPath)) return null;
36217
- return (0, import_fs19.readFileSync)(indexPath, "utf-8");
36720
+ const indexPath = (0, import_path28.join)(getWikiDir(root), INDEX_FILE);
36721
+ if (!(0, import_fs20.existsSync)(indexPath)) return null;
36722
+ return (0, import_fs20.readFileSync)(indexPath, "utf-8");
36218
36723
  }
36219
36724
  function writePageUnsafe(root, page) {
36220
36725
  if (RESERVED_FILES.has(page.filename)) {
@@ -36229,8 +36734,8 @@ function deletePageUnsafe(root, filename) {
36229
36734
  const wikiDir = getWikiDir(root);
36230
36735
  const filePath = safeWikiPath(wikiDir, filename);
36231
36736
  if (!filePath) return false;
36232
- if (!(0, import_fs19.existsSync)(filePath)) return false;
36233
- (0, import_fs19.unlinkSync)(filePath);
36737
+ if (!(0, import_fs20.existsSync)(filePath)) return false;
36738
+ (0, import_fs20.unlinkSync)(filePath);
36234
36739
  return true;
36235
36740
  }
36236
36741
  function updateIndexUnsafe(root) {
@@ -36259,19 +36764,19 @@ function updateIndexUnsafe(root) {
36259
36764
  lines.push("");
36260
36765
  }
36261
36766
  const wikiDir = ensureWikiDir(root);
36262
- atomicWriteFileSync((0, import_path26.join)(wikiDir, INDEX_FILE), lines.join("\n"));
36767
+ atomicWriteFileSync((0, import_path28.join)(wikiDir, INDEX_FILE), lines.join("\n"));
36263
36768
  }
36264
36769
  function appendLogUnsafe(root, entry) {
36265
36770
  const wikiDir = ensureWikiDir(root);
36266
- const logPath = (0, import_path26.join)(wikiDir, LOG_FILE);
36771
+ const logPath = (0, import_path28.join)(wikiDir, LOG_FILE);
36267
36772
  const logLine = `## [${entry.timestamp}] ${entry.operation}
36268
36773
  - **Pages:** ${entry.pagesAffected.join(", ") || "none"}
36269
36774
  - **Summary:** ${entry.summary}
36270
36775
 
36271
36776
  `;
36272
36777
  let existing = "";
36273
- if ((0, import_fs19.existsSync)(logPath)) {
36274
- existing = (0, import_fs19.readFileSync)(logPath, "utf-8");
36778
+ if ((0, import_fs20.existsSync)(logPath)) {
36779
+ existing = (0, import_fs20.readFileSync)(logPath, "utf-8");
36275
36780
  } else {
36276
36781
  existing = "# Wiki Log\n\n";
36277
36782
  }
@@ -36603,7 +37108,7 @@ var wikiIngestTool = {
36603
37108
  },
36604
37109
  handler: async (args) => {
36605
37110
  try {
36606
- const root = validateWorkingDirectory(args.workingDirectory);
37111
+ const root = validateWorkingDirectoryOrLinkedWorktree(args.workingDirectory);
36607
37112
  const result = ingestKnowledge(root, {
36608
37113
  title: args.title,
36609
37114
  content: args.content,
@@ -36644,7 +37149,7 @@ var wikiQueryTool = {
36644
37149
  },
36645
37150
  handler: async (args) => {
36646
37151
  try {
36647
- const root = validateWorkingDirectory(args.workingDirectory);
37152
+ const root = validateWorkingDirectoryOrLinkedWorktree(args.workingDirectory);
36648
37153
  const matches = queryWiki(root, args.query, {
36649
37154
  tags: args.tags,
36650
37155
  category: args.category,
@@ -36693,7 +37198,7 @@ var wikiLintTool = {
36693
37198
  },
36694
37199
  handler: async (args) => {
36695
37200
  try {
36696
- const root = validateWorkingDirectory(args.workingDirectory);
37201
+ const root = validateWorkingDirectoryOrLinkedWorktree(args.workingDirectory);
36697
37202
  const report = lintWiki(root);
36698
37203
  if (report.issues.length === 0) {
36699
37204
  return {
@@ -36741,7 +37246,7 @@ var wikiAddTool = {
36741
37246
  },
36742
37247
  handler: async (args) => {
36743
37248
  try {
36744
- const root = validateWorkingDirectory(args.workingDirectory);
37249
+ const root = validateWorkingDirectoryOrLinkedWorktree(args.workingDirectory);
36745
37250
  const slug = titleToSlug(args.title);
36746
37251
  if (readPage(root, slug)) {
36747
37252
  return {
@@ -36784,7 +37289,7 @@ var wikiListTool = {
36784
37289
  },
36785
37290
  handler: async (args) => {
36786
37291
  try {
36787
- const root = validateWorkingDirectory(args.workingDirectory);
37292
+ const root = validateWorkingDirectoryOrLinkedWorktree(args.workingDirectory);
36788
37293
  const index = readIndex(root);
36789
37294
  if (!index) {
36790
37295
  const pages = listPages(root);
@@ -36830,7 +37335,7 @@ var wikiReadTool = {
36830
37335
  },
36831
37336
  handler: async (args) => {
36832
37337
  try {
36833
- const root = validateWorkingDirectory(args.workingDirectory);
37338
+ const root = validateWorkingDirectoryOrLinkedWorktree(args.workingDirectory);
36834
37339
  const filename = args.page.endsWith(".md") ? args.page : `${args.page}.md`;
36835
37340
  const page = readPage(root, filename);
36836
37341
  if (!page) {
@@ -36878,7 +37383,7 @@ var wikiDeleteTool = {
36878
37383
  },
36879
37384
  handler: async (args) => {
36880
37385
  try {
36881
- const root = validateWorkingDirectory(args.workingDirectory);
37386
+ const root = validateWorkingDirectoryOrLinkedWorktree(args.workingDirectory);
36882
37387
  const filename = args.page.endsWith(".md") ? args.page : `${args.page}.md`;
36883
37388
  const deleted = deletePage(root, filename);
36884
37389
  if (!deleted) {
@@ -36924,23 +37429,23 @@ var wikiTools = [
36924
37429
  ];
36925
37430
 
36926
37431
  // src/tools/skills-tools.ts
36927
- var import_path30 = require("path");
37432
+ var import_path32 = require("path");
36928
37433
  var import_os6 = require("os");
36929
37434
 
36930
37435
  // src/hooks/learner/loader.ts
36931
- var import_fs21 = require("fs");
37436
+ var import_fs22 = require("fs");
36932
37437
  var import_crypto3 = require("crypto");
36933
- var import_path29 = require("path");
37438
+ var import_path31 = require("path");
36934
37439
 
36935
37440
  // src/hooks/learner/finder.ts
36936
- var import_fs20 = require("fs");
36937
- var import_path28 = require("path");
37441
+ var import_fs21 = require("fs");
37442
+ var import_path30 = require("path");
36938
37443
 
36939
37444
  // src/hooks/learner/constants.ts
36940
- var import_path27 = require("path");
37445
+ var import_path29 = require("path");
36941
37446
  var import_os5 = require("os");
36942
- var USER_SKILLS_DIR = (0, import_path27.join)(getConfigDir(), "skills", "omc-learned");
36943
- var GLOBAL_SKILLS_DIR = (0, import_path27.join)((0, import_os5.homedir)(), ".omcp", "skills");
37447
+ var USER_SKILLS_DIR = (0, import_path29.join)(getConfigDir(), "skills", "omc-learned");
37448
+ var GLOBAL_SKILLS_DIR = (0, import_path29.join)((0, import_os5.homedir)(), ".omcp", "skills");
36944
37449
  var PROJECT_SKILLS_SUBDIR = OmgPaths.SKILLS;
36945
37450
  var MAX_RECURSION_DEPTH = 10;
36946
37451
  var SKILL_EXTENSION = ".md";
@@ -36948,12 +37453,12 @@ var DEBUG_ENABLED = process.env.OMC_DEBUG === "1";
36948
37453
 
36949
37454
  // src/hooks/learner/finder.ts
36950
37455
  function findSkillFilesRecursive(dir, results, depth = 0) {
36951
- if (!(0, import_fs20.existsSync)(dir)) return;
37456
+ if (!(0, import_fs21.existsSync)(dir)) return;
36952
37457
  if (depth > MAX_RECURSION_DEPTH) return;
36953
37458
  try {
36954
- const entries = (0, import_fs20.readdirSync)(dir, { withFileTypes: true });
37459
+ const entries = (0, import_fs21.readdirSync)(dir, { withFileTypes: true });
36955
37460
  for (const entry of entries) {
36956
- const fullPath = (0, import_path28.join)(dir, entry.name);
37461
+ const fullPath = (0, import_path30.join)(dir, entry.name);
36957
37462
  if (entry.isDirectory()) {
36958
37463
  findSkillFilesRecursive(fullPath, results, depth + 1);
36959
37464
  } else if (entry.isFile() && entry.name.endsWith(SKILL_EXTENSION)) {
@@ -36968,22 +37473,22 @@ function findSkillFilesRecursive(dir, results, depth = 0) {
36968
37473
  }
36969
37474
  function safeRealpathSync(filePath) {
36970
37475
  try {
36971
- return (0, import_fs20.realpathSync)(filePath);
37476
+ return (0, import_fs21.realpathSync)(filePath);
36972
37477
  } catch {
36973
37478
  return filePath;
36974
37479
  }
36975
37480
  }
36976
37481
  function isWithinBoundary(realPath, boundary) {
36977
- const normalizedReal = (0, import_path28.normalize)(realPath);
36978
- const normalizedBoundary = (0, import_path28.normalize)(safeRealpathSync(boundary));
36979
- return normalizedReal === normalizedBoundary || normalizedReal.startsWith(normalizedBoundary + import_path28.sep);
37482
+ const normalizedReal = (0, import_path30.normalize)(realPath);
37483
+ const normalizedBoundary = (0, import_path30.normalize)(safeRealpathSync(boundary));
37484
+ return normalizedReal === normalizedBoundary || normalizedReal.startsWith(normalizedBoundary + import_path30.sep);
36980
37485
  }
36981
37486
  function findSkillFiles(projectRoot, options) {
36982
37487
  const candidates = [];
36983
37488
  const seenRealPaths = /* @__PURE__ */ new Set();
36984
37489
  const scope = options?.scope ?? "all";
36985
37490
  if (projectRoot && (scope === "project" || scope === "all")) {
36986
- const projectSkillsDir = (0, import_path28.join)(projectRoot, PROJECT_SKILLS_SUBDIR);
37491
+ const projectSkillsDir = (0, import_path30.join)(projectRoot, PROJECT_SKILLS_SUBDIR);
36987
37492
  const projectFiles = [];
36988
37493
  findSkillFilesRecursive(projectSkillsDir, projectFiles);
36989
37494
  for (const filePath of projectFiles) {
@@ -37189,7 +37694,7 @@ function loadAllSkills(projectRoot) {
37189
37694
  const seenIds = /* @__PURE__ */ new Map();
37190
37695
  for (const candidate of candidates) {
37191
37696
  try {
37192
- const rawContent = (0, import_fs21.readFileSync)(candidate.path, "utf-8");
37697
+ const rawContent = (0, import_fs22.readFileSync)(candidate.path, "utf-8");
37193
37698
  const { metadata, content, valid, errors } = parseSkillFile(rawContent);
37194
37699
  if (!valid) {
37195
37700
  if (DEBUG_ENABLED) {
@@ -37198,7 +37703,7 @@ function loadAllSkills(projectRoot) {
37198
37703
  continue;
37199
37704
  }
37200
37705
  const skillId = metadata.id;
37201
- const relativePath = (0, import_path29.normalize)((0, import_path29.relative)(candidate.sourceDir, candidate.path));
37706
+ const relativePath = (0, import_path31.normalize)((0, import_path31.relative)(candidate.sourceDir, candidate.path));
37202
37707
  const skill = {
37203
37708
  path: candidate.path,
37204
37709
  relativePath,
@@ -37224,13 +37729,13 @@ function loadAllSkills(projectRoot) {
37224
37729
  // src/tools/skills-tools.ts
37225
37730
  var ALLOWED_BOUNDARIES = [process.cwd(), (0, import_os6.homedir)()];
37226
37731
  function validateProjectRoot(input) {
37227
- const normalized = (0, import_path30.normalize)((0, import_path30.resolve)(input));
37732
+ const normalized = (0, import_path32.normalize)((0, import_path32.resolve)(input));
37228
37733
  if (input.includes("..")) {
37229
37734
  throw new Error("Invalid project root: path traversal not allowed");
37230
37735
  }
37231
37736
  const isWithinAllowed = ALLOWED_BOUNDARIES.some((boundary) => {
37232
- const normalizedBoundary = (0, import_path30.normalize)(boundary);
37233
- return normalized === normalizedBoundary || normalized.startsWith(normalizedBoundary + import_path30.sep);
37737
+ const normalizedBoundary = (0, import_path32.normalize)(boundary);
37738
+ return normalized === normalizedBoundary || normalized.startsWith(normalizedBoundary + import_path32.sep);
37234
37739
  });
37235
37740
  if (!isWithinAllowed) {
37236
37741
  throw new Error("Invalid project root: path is outside allowed directories");