aiwcli 0.15.5 → 0.15.7

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 (299) hide show
  1. package/README.md +6 -3
  2. package/dist/capabilities/branch/adapters.d.ts +2 -0
  3. package/dist/capabilities/branch/adapters.js +21 -0
  4. package/dist/capabilities/branch/contracts.d.ts +57 -0
  5. package/dist/capabilities/branch/contracts.js +1 -0
  6. package/dist/capabilities/branch/control-plane.d.ts +2 -0
  7. package/dist/capabilities/branch/control-plane.js +343 -0
  8. package/dist/capabilities/branch/runtime-core.d.ts +5 -0
  9. package/dist/capabilities/branch/runtime-core.js +36 -0
  10. package/dist/capabilities/installation/control-plane/clean-command.d.ts +41 -0
  11. package/dist/capabilities/installation/control-plane/clean-command.js +196 -0
  12. package/dist/capabilities/installation/control-plane/clear-command.d.ts +160 -0
  13. package/dist/capabilities/installation/control-plane/clear-command.js +1220 -0
  14. package/dist/capabilities/installation/control-plane/init-command.d.ts +81 -0
  15. package/dist/capabilities/installation/control-plane/init-command.js +449 -0
  16. package/dist/capabilities/launch/contracts.d.ts +51 -0
  17. package/dist/capabilities/launch/contracts.js +1 -0
  18. package/dist/capabilities/launch/control-plane/execute-launch.d.ts +2 -0
  19. package/dist/capabilities/launch/control-plane/execute-launch.js +222 -0
  20. package/dist/capabilities/launch/runtime-core/launch-options.d.ts +14 -0
  21. package/dist/capabilities/launch/runtime-core/launch-options.js +69 -0
  22. package/dist/cli/base-command.d.ts +18 -0
  23. package/dist/cli/base-command.js +55 -0
  24. package/dist/commands/branch.d.ts +0 -20
  25. package/dist/commands/branch.js +24 -416
  26. package/dist/commands/clean.d.ts +1 -41
  27. package/dist/commands/clean.js +1 -196
  28. package/dist/commands/clear.d.ts +1 -161
  29. package/dist/commands/clear.js +1 -1121
  30. package/dist/commands/init/index.d.ts +1 -98
  31. package/dist/commands/init/index.js +4 -478
  32. package/dist/commands/launch.d.ts +36 -11
  33. package/dist/commands/launch.js +135 -159
  34. package/dist/lib/base-command.d.ts +1 -114
  35. package/dist/lib/base-command.js +1 -153
  36. package/dist/lib/claude-settings-types.d.ts +31 -19
  37. package/dist/lib/context/context-formatter.d.ts +74 -0
  38. package/dist/lib/context/context-formatter.js +493 -0
  39. package/dist/lib/context/context-selector.d.ts +42 -0
  40. package/dist/lib/context/context-selector.js +451 -0
  41. package/dist/lib/context/context-store.d.ts +100 -0
  42. package/dist/lib/context/context-store.js +618 -0
  43. package/dist/lib/context/plan-manager.d.ts +54 -0
  44. package/dist/lib/context/plan-manager.js +282 -0
  45. package/dist/lib/context/task-tracker.d.ts +44 -0
  46. package/dist/lib/context/task-tracker.js +146 -0
  47. package/dist/lib/core-ide-base.d.ts +4 -0
  48. package/dist/lib/core-ide-base.js +77 -0
  49. package/dist/lib/core-installer.d.ts +5 -0
  50. package/dist/lib/core-installer.js +54 -0
  51. package/dist/lib/git-exclude-manager.d.ts +2 -2
  52. package/dist/lib/git-exclude-manager.js +3 -3
  53. package/dist/lib/hooks/hook-utils.d.ts +143 -0
  54. package/dist/lib/hooks/hook-utils.js +609 -0
  55. package/dist/lib/hooks/session-end-logic.d.ts +5 -0
  56. package/dist/lib/hooks/session-end-logic.js +63 -0
  57. package/dist/lib/hooks-merger.js +25 -19
  58. package/dist/lib/ide-path-resolver.d.ts +19 -7
  59. package/dist/lib/ide-path-resolver.js +25 -9
  60. package/dist/lib/install-state.d.ts +34 -0
  61. package/dist/lib/install-state.js +161 -0
  62. package/dist/lib/launch-options.d.ts +1 -0
  63. package/dist/lib/launch-options.js +1 -0
  64. package/dist/lib/lsp-patch.d.ts +12 -0
  65. package/dist/lib/lsp-patch.js +156 -0
  66. package/dist/lib/multiplexer.d.ts +57 -0
  67. package/dist/lib/multiplexer.js +19 -0
  68. package/dist/lib/multiplexers/psmux.d.ts +75 -0
  69. package/dist/lib/multiplexers/psmux.js +384 -0
  70. package/dist/lib/multiplexers/tmux.d.ts +44 -0
  71. package/dist/lib/multiplexers/tmux.js +262 -0
  72. package/dist/lib/mux-utils.d.ts +5 -0
  73. package/dist/lib/mux-utils.js +42 -0
  74. package/dist/lib/paths.d.ts +2 -2
  75. package/dist/lib/paths.js +2 -2
  76. package/dist/lib/platform-commands.d.ts +27 -0
  77. package/dist/lib/platform-commands.js +49 -0
  78. package/dist/lib/runtime/aiw-cli.d.ts +37 -0
  79. package/dist/lib/runtime/aiw-cli.js +74 -0
  80. package/dist/lib/runtime/atomic-write.d.ts +19 -0
  81. package/dist/lib/runtime/atomic-write.js +121 -0
  82. package/dist/lib/runtime/cli-args.d.ts +55 -0
  83. package/dist/lib/runtime/cli-args.js +185 -0
  84. package/dist/lib/runtime/constants.d.ts +56 -0
  85. package/dist/lib/runtime/constants.js +230 -0
  86. package/dist/lib/runtime/executable-policy.d.ts +16 -0
  87. package/dist/lib/runtime/executable-policy.js +57 -0
  88. package/dist/lib/runtime/git-state.d.ts +9 -0
  89. package/dist/lib/runtime/git-state.js +59 -0
  90. package/dist/lib/runtime/inference.d.ts +37 -0
  91. package/dist/lib/runtime/inference.js +262 -0
  92. package/dist/lib/runtime/lint-dispatch.d.ts +40 -0
  93. package/dist/lib/runtime/lint-dispatch.js +285 -0
  94. package/dist/lib/runtime/logger.d.ts +66 -0
  95. package/dist/lib/runtime/logger.js +201 -0
  96. package/dist/lib/runtime/models.d.ts +14 -0
  97. package/dist/lib/runtime/models.js +14 -0
  98. package/dist/lib/runtime/platform-adapter.d.ts +7 -0
  99. package/dist/lib/runtime/platform-adapter.js +21 -0
  100. package/dist/lib/runtime/preflight.d.ts +24 -0
  101. package/dist/lib/runtime/preflight.js +65 -0
  102. package/dist/lib/runtime/sentinel-ipc.d.ts +14 -0
  103. package/dist/lib/runtime/sentinel-ipc.js +67 -0
  104. package/dist/lib/runtime/state-io.d.ts +30 -0
  105. package/dist/lib/runtime/state-io.js +174 -0
  106. package/dist/lib/runtime/stop-words.d.ts +20 -0
  107. package/dist/lib/runtime/stop-words.js +150 -0
  108. package/dist/lib/runtime/subprocess-utils.d.ts +29 -0
  109. package/dist/lib/runtime/subprocess-utils.js +96 -0
  110. package/dist/lib/runtime/tmux-preflight.d.ts +13 -0
  111. package/dist/lib/runtime/tmux-preflight.js +78 -0
  112. package/dist/lib/runtime/utils.d.ts +54 -0
  113. package/dist/lib/runtime/utils.js +162 -0
  114. package/dist/lib/sentinel-wrapper.d.ts +9 -0
  115. package/dist/lib/sentinel-wrapper.js +20 -0
  116. package/dist/lib/shell-quoting.d.ts +5 -0
  117. package/dist/lib/shell-quoting.js +17 -0
  118. package/dist/lib/spawn-errors.d.ts +6 -0
  119. package/dist/lib/spawn-errors.js +15 -0
  120. package/dist/lib/spawn.js +5 -11
  121. package/dist/lib/template-installer.d.ts +4 -5
  122. package/dist/lib/template-installer.js +36 -34
  123. package/dist/lib/template-resolver.d.ts +6 -7
  124. package/dist/lib/template-resolver.js +26 -21
  125. package/dist/lib/template-settings-reconstructor.d.ts +7 -2
  126. package/dist/lib/template-settings-reconstructor.js +76 -45
  127. package/dist/lib/terminal-strategy.d.ts +11 -0
  128. package/dist/lib/terminal-strategy.js +49 -0
  129. package/dist/lib/terminal.d.ts +28 -0
  130. package/dist/lib/terminal.js +162 -112
  131. package/dist/lib/tmux-pane-placement.d.ts +17 -0
  132. package/dist/lib/tmux-pane-placement.js +58 -0
  133. package/dist/lib/tmux-primitives.d.ts +5 -0
  134. package/dist/lib/tmux-primitives.js +15 -0
  135. package/dist/lib/tmux-session.d.ts +32 -0
  136. package/dist/lib/tmux-session.js +86 -0
  137. package/dist/lib/tty-detection.js +1 -1
  138. package/dist/lib/types.d.ts +168 -0
  139. package/dist/lib/types.js +6 -0
  140. package/dist/lib/version.d.ts +1 -1
  141. package/dist/lib/version.js +1 -1
  142. package/dist/platform/launch.d.ts +10 -0
  143. package/dist/platform/launch.js +10 -0
  144. package/dist/templates/CLAUDE.md +31 -40
  145. package/dist/templates/cc-native/.claude/settings.json +27 -27
  146. package/dist/templates/cc-native/CC-NATIVE-README.md +1 -1
  147. package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +10 -9
  148. package/dist/templates/cc-native/_cc-native/CLAUDE.md +18 -18
  149. package/dist/templates/cc-native/_cc-native/artifacts/CLAUDE.md +3 -3
  150. package/dist/templates/cc-native/_cc-native/artifacts/lib/format.ts +14 -14
  151. package/dist/templates/cc-native/_cc-native/artifacts/lib/tracker.ts +1 -1
  152. package/dist/templates/cc-native/_cc-native/artifacts/lib/write.ts +3 -3
  153. package/dist/templates/cc-native/_cc-native/cc-native.config.json +3 -3
  154. package/dist/templates/cc-native/_cc-native/hooks/CLAUDE.md +16 -15
  155. package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +3 -3
  156. package/dist/templates/cc-native/_cc-native/hooks/enhance_plan_post_subagent.ts +2 -2
  157. package/dist/templates/cc-native/_cc-native/hooks/enhance_plan_post_write.ts +2 -2
  158. package/dist/templates/cc-native/_cc-native/hooks/mark_questions_asked.ts +3 -3
  159. package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.ts +2 -2
  160. package/dist/templates/cc-native/_cc-native/hooks/validate_task_prompt.ts +3 -3
  161. package/dist/templates/cc-native/_cc-native/lib-ts/CLAUDE.md +8 -8
  162. package/dist/templates/cc-native/_cc-native/lib-ts/aggregate-agents.ts +1 -1
  163. package/dist/templates/cc-native/_cc-native/lib-ts/cc-native-state.ts +4 -4
  164. package/dist/templates/cc-native/_cc-native/lib-ts/cli-output-parser.ts +1 -1
  165. package/dist/templates/cc-native/_cc-native/lib-ts/config.ts +1 -1
  166. package/dist/templates/cc-native/_cc-native/lib-ts/debug.ts +1 -1
  167. package/dist/templates/cc-native/_cc-native/lib-ts/json-parser.ts +1 -1
  168. package/dist/templates/cc-native/_cc-native/lib-ts/plan-discovery.ts +2 -2
  169. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/logger.ts +1 -1
  170. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/retrieval-pipeline.ts +2 -2
  171. package/dist/templates/cc-native/_cc-native/lib-ts/rlm/types.ts +1 -1
  172. package/dist/templates/cc-native/_cc-native/lib-ts/settings.ts +8 -8
  173. package/dist/templates/cc-native/_cc-native/lib-ts/state.ts +3 -3
  174. package/dist/templates/cc-native/_cc-native/lib-ts/tsconfig.json +2 -2
  175. package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +3 -3
  176. package/dist/templates/cc-native/_cc-native/plan-review/CLAUDE.md +3 -1
  177. package/dist/templates/cc-native/_cc-native/plan-review/lib/__tests__/agent-selection.test.ts +345 -0
  178. package/dist/templates/cc-native/_cc-native/plan-review/lib/__tests__/preflight.test.ts +344 -0
  179. package/dist/templates/cc-native/_cc-native/plan-review/lib/agent-selection.ts +37 -15
  180. package/dist/templates/cc-native/_cc-native/plan-review/lib/corroboration.ts +16 -69
  181. package/dist/templates/cc-native/_cc-native/plan-review/lib/orchestrator.ts +1 -1
  182. package/dist/templates/cc-native/_cc-native/plan-review/lib/output-builder.ts +1 -1
  183. package/dist/templates/cc-native/_cc-native/plan-review/lib/plan-questions.ts +2 -2
  184. package/dist/templates/cc-native/_cc-native/plan-review/lib/preflight.ts +56 -26
  185. package/dist/templates/cc-native/_cc-native/plan-review/lib/review-pipeline.ts +7 -7
  186. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/agent.ts +4 -4
  187. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/base/base-agent.ts +3 -3
  188. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/index.ts +1 -1
  189. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/claude-agent.ts +2 -2
  190. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/codex-agent.ts +4 -4
  191. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/gemini-agent.ts +1 -1
  192. package/dist/templates/cc-native/_cc-native/plan-review/lib/reviewers/providers/orchestrator-claude-agent.ts +5 -6
  193. package/dist/templates/core/.codex/workflows/codex.md +17 -0
  194. package/dist/templates/core/.codex/workflows/handoff.md +5 -0
  195. package/dist/templates/core/.codex/workflows/meta-plan.md +7 -0
  196. package/dist/templates/core/.cognition/AGENTS.md +5 -0
  197. package/dist/templates/core/.cognition/config.json +12 -0
  198. package/dist/templates/{_shared → core}/.windsurf/workflows/handoff.md +1 -1
  199. package/dist/templates/{_shared → core}/.windsurf/workflows/meta-plan.md +1 -1
  200. package/dist/templates/core/hooks-ts/_utils/git-state.ts +2 -0
  201. package/dist/templates/{_shared → core}/hooks-ts/archive_plan.ts +14 -23
  202. package/dist/templates/core/hooks-ts/codex_explorer.ts +160 -0
  203. package/dist/templates/{_shared → core}/hooks-ts/context_monitor.ts +23 -55
  204. package/dist/templates/{_shared → core}/hooks-ts/file-suggestion.ts +4 -3
  205. package/dist/templates/{_shared → core}/hooks-ts/lint_after_edit.ts +7 -9
  206. package/dist/templates/{_shared → core}/hooks-ts/pre_compact.ts +5 -5
  207. package/dist/templates/{_shared → core}/hooks-ts/session_end.ts +38 -78
  208. package/dist/templates/{_shared → core}/hooks-ts/session_start.ts +5 -5
  209. package/dist/templates/core/hooks-ts/task_create_capture.ts +32 -0
  210. package/dist/templates/{_shared → core}/hooks-ts/task_update_capture.ts +9 -24
  211. package/dist/templates/core/hooks-ts/user_prompt_submit.ts +46 -0
  212. package/dist/templates/{_shared → core}/lib-ts/CLAUDE.md +27 -16
  213. package/dist/templates/{_shared → core}/lib-ts/agent-exec/backends/headless.ts +3 -2
  214. package/dist/templates/{_shared → core}/lib-ts/agent-exec/backends/tmux.ts +44 -15
  215. package/dist/templates/{_shared → core}/lib-ts/agent-exec/base-agent.ts +6 -4
  216. package/dist/templates/{_shared → core}/lib-ts/agent-exec/execution-backend.ts +1 -1
  217. package/dist/templates/{_shared → core}/lib-ts/agent-exec/index.ts +2 -2
  218. package/dist/templates/{_shared → core}/lib-ts/agent-exec/structured-output.ts +4 -5
  219. package/dist/templates/{_shared → core}/lib-ts/context/CLAUDE.md +9 -6
  220. package/dist/templates/{_shared → core}/lib-ts/context/context-formatter.ts +16 -21
  221. package/dist/templates/{_shared → core}/lib-ts/context/context-selector.ts +8 -6
  222. package/dist/templates/{_shared → core}/lib-ts/context/context-store.ts +32 -20
  223. package/dist/templates/{_shared → core}/lib-ts/context/plan-manager.ts +19 -15
  224. package/dist/templates/{_shared → core}/lib-ts/context/task-tracker.ts +3 -3
  225. package/dist/templates/core/lib-ts/hooks/context-monitor-logic.ts +32 -0
  226. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/hooks}/hook-utils.ts +168 -41
  227. package/dist/templates/core/lib-ts/hooks/prompt-binding-logic.ts +80 -0
  228. package/dist/templates/core/lib-ts/hooks/session-end-logic.ts +93 -0
  229. package/dist/templates/core/lib-ts/package.json +19 -0
  230. package/dist/templates/core/lib-ts/runtime/agent-launcher.ts +295 -0
  231. package/dist/templates/core/lib-ts/runtime/aiw-cli.ts +106 -0
  232. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/atomic-write.ts +12 -7
  233. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/cli-args.ts +8 -6
  234. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/constants.ts +326 -324
  235. package/dist/templates/core/lib-ts/runtime/executable-policy.ts +89 -0
  236. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/git-state.ts +6 -4
  237. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/inference.ts +59 -10
  238. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/lint-dispatch.ts +25 -23
  239. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/logger.ts +32 -29
  240. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/models.ts +2 -2
  241. package/dist/templates/core/lib-ts/runtime/platform-adapter.ts +33 -0
  242. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/preflight.ts +4 -3
  243. package/dist/templates/core/lib-ts/runtime/sentinel-ipc.ts +91 -0
  244. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/state-io.ts +11 -7
  245. package/dist/templates/core/lib-ts/runtime/stop-words.ts +185 -0
  246. package/dist/templates/core/lib-ts/runtime/subprocess-utils.ts +147 -0
  247. package/dist/templates/core/lib-ts/runtime/tmux-preflight.ts +93 -0
  248. package/dist/templates/{_shared/lib-ts/base → core/lib-ts/runtime}/utils.ts +4 -3
  249. package/dist/templates/{_shared → core}/lib-ts/templates/formatters.ts +7 -5
  250. package/dist/templates/{_shared → core}/lib-ts/templates/plan-context.ts +2 -1
  251. package/dist/templates/{_shared → core}/lib-ts/tsconfig.json +3 -1
  252. package/dist/templates/{_shared → core}/lib-ts/types.ts +78 -77
  253. package/dist/templates/core/scripts/resolve-run.ts +61 -0
  254. package/dist/templates/{_shared → core}/scripts/resolve_context.ts +3 -3
  255. package/dist/templates/{_shared → core}/scripts/status_line.ts +25 -20
  256. package/dist/templates/core/skills/codex/CLAUDE.md +78 -0
  257. package/dist/templates/{_shared → core}/skills/codex/SKILL.md +21 -18
  258. package/dist/templates/{_shared → core}/skills/codex/lib/codex-watcher.ts +76 -103
  259. package/dist/templates/{_shared → core}/skills/codex/scripts/launch-codex.ts +119 -133
  260. package/dist/templates/{_shared → core}/skills/codex/scripts/watch-codex.ts +6 -4
  261. package/dist/templates/core/skills/devin/CLAUDE.md +65 -0
  262. package/dist/templates/core/skills/devin/SKILL.md +73 -0
  263. package/dist/templates/core/skills/devin/lib/devin-watcher.ts +280 -0
  264. package/dist/templates/core/skills/devin/scripts/launch-devin.ts +257 -0
  265. package/dist/templates/{_shared → core}/skills/handoff-system/CLAUDE.md +436 -433
  266. package/dist/templates/{_shared → core}/skills/handoff-system/lib/document-generator.ts +9 -7
  267. package/dist/templates/{_shared → core}/skills/handoff-system/lib/handoff-reader.ts +6 -4
  268. package/dist/templates/{_shared → core}/skills/handoff-system/scripts/resume_handoff.ts +10 -8
  269. package/dist/templates/{_shared → core}/skills/handoff-system/scripts/save_handoff.ts +12 -10
  270. package/dist/templates/{_shared → core}/skills/handoff-system/workflows/handoff-resume.md +2 -2
  271. package/dist/templates/{_shared → core}/skills/handoff-system/workflows/handoff.md +6 -5
  272. package/dist/templates/{_shared → core}/skills/meta-plan/CLAUDE.md +2 -1
  273. package/dist/templates/{_shared → core}/skills/meta-plan/workflows/meta-plan.md +8 -7
  274. package/oclif.manifest.json +89 -13
  275. package/package.json +13 -12
  276. package/dist/templates/_shared/.claude/settings.json +0 -120
  277. package/dist/templates/_shared/.claude/skills/codex/SKILL.md +0 -35
  278. package/dist/templates/_shared/.claude/skills/handoff/SKILL.md +0 -13
  279. package/dist/templates/_shared/.claude/skills/handoff-resume/SKILL.md +0 -13
  280. package/dist/templates/_shared/.claude/skills/meta-plan/SKILL.md +0 -43
  281. package/dist/templates/_shared/.codex/workflows/codex.md +0 -11
  282. package/dist/templates/_shared/.codex/workflows/handoff.md +0 -226
  283. package/dist/templates/_shared/.codex/workflows/meta-plan.md +0 -347
  284. package/dist/templates/_shared/hooks-ts/_utils/git-state.ts +0 -2
  285. package/dist/templates/_shared/hooks-ts/task_create_capture.ts +0 -48
  286. package/dist/templates/_shared/hooks-ts/user_prompt_submit.ts +0 -93
  287. package/dist/templates/_shared/lib-ts/base/launchers/tmux-launcher.ts +0 -173
  288. package/dist/templates/_shared/lib-ts/base/launchers/window-launcher.ts +0 -93
  289. package/dist/templates/_shared/lib-ts/base/launchers/wt-launcher.ts +0 -64
  290. package/dist/templates/_shared/lib-ts/base/pane-launcher.ts +0 -55
  291. package/dist/templates/_shared/lib-ts/base/sentinel-ipc.ts +0 -87
  292. package/dist/templates/_shared/lib-ts/base/stop-words.ts +0 -184
  293. package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +0 -249
  294. package/dist/templates/_shared/lib-ts/base/tmux-driver.ts +0 -341
  295. package/dist/templates/_shared/lib-ts/base/tmux-pane-placement.ts +0 -78
  296. package/dist/templates/_shared/lib-ts/package.json +0 -20
  297. package/dist/templates/_shared/scripts/resolve-run.ts +0 -62
  298. package/dist/templates/_shared/skills/codex/CLAUDE.md +0 -70
  299. /package/dist/templates/{_shared → core}/lib-ts/agent-exec/backends/index.ts +0 -0
@@ -1,29 +1,26 @@
1
1
  import * as fs from "node:fs";
2
2
  import * as os from "node:os";
3
- import * as path from "node:path";
3
+ import path from "node:path";
4
4
 
5
- import { inference } from "../../../lib-ts/base/inference.js";
6
- import { logDebug, logWarn } from "../../../lib-ts/base/logger.js";
7
- import { CODEX_MODELS } from "../../../lib-ts/base/models.js";
8
- import type { PaneBackend } from "../../../lib-ts/base/pane-launcher.js";
9
- import { execFileAsync } from "../../../lib-ts/base/subprocess-utils.js";
10
- import { getTmuxAvailability } from "../../../lib-ts/base/tmux-driver.js";
5
+ import { inference } from "../../../lib-ts/runtime/inference.js";
6
+ import { logWarn } from "../../../lib-ts/runtime/logger.js";
7
+ import { CODEX_MODELS } from "../../../lib-ts/runtime/models.js";
8
+ import { execFileAsync } from "../../../lib-ts/runtime/subprocess-utils.js";
9
+
10
+ // Re-export shared symbols that consumers import from this module
11
+ export {
12
+ type PaneWatchTarget,
13
+ persistSummary,
14
+ sleep,
15
+ waitForPaneClose,
16
+ } from "../../../lib-ts/runtime/agent-launcher.js";
11
17
 
12
- export const POLL_INTERVAL_MS = 2000;
13
- export const POLL_TIMEOUT_MS = 3000;
14
18
  export const SUMMARY_TIMEOUT_SEC = 8;
15
- export const RESUME_TIMEOUT_MS = 45000;
19
+ export const RESUME_TIMEOUT_MS = 45_000;
16
20
  export const MAX_TRANSCRIPT_LINES = 220;
17
21
  export const MAX_LINE_LENGTH = 500;
18
- export const WAIT_TIMEOUT_MS_DEFAULT = 14_400_000;
19
22
  export const SUMMARY_UNAVAILABLE_MESSAGE = "Codex session completed. Summary unavailable.";
20
23
 
21
- export interface PaneWatchTarget {
22
- backend?: PaneBackend;
23
- paneId?: string;
24
- sentinelPath?: string;
25
- }
26
-
27
24
  export const TRANSCRIPT_SUMMARY_PROMPT = `Summarize this Codex session transcript excerpt.
28
25
  Return 3-5 concise bullet points.
29
26
  Focus on:
@@ -43,10 +40,6 @@ Do not ask follow-up questions.
43
40
  Do not request additional input.
44
41
  If the prior session was brief, still provide a best-effort summary.`;
45
42
 
46
- export function sleep(ms: number): Promise<void> {
47
- return new Promise((resolve) => setTimeout(resolve, ms));
48
- }
49
-
50
43
  export function safeCleanup(filePath: string): void {
51
44
  try {
52
45
  if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
@@ -58,7 +51,7 @@ export function safeCleanup(filePath: string): void {
58
51
  export function readTextIfExists(filePath: string): string {
59
52
  try {
60
53
  if (!filePath || !fs.existsSync(filePath)) return "";
61
- return fs.readFileSync(filePath, "utf-8").trim();
54
+ return fs.readFileSync(filePath, "utf8").trim();
62
55
  } catch {
63
56
  return "";
64
57
  }
@@ -66,16 +59,16 @@ export function readTextIfExists(filePath: string): string {
66
59
 
67
60
  export function normalizeText(text: string): string {
68
61
  return text
69
- .replace(/\r/g, "")
70
- .replace(/[\x00-\x08\x0B-\x1F\x7F]/g, "")
71
- .replace(/\s+/g, " ")
62
+ .replaceAll('\r', "")
63
+ .replaceAll(/\p{Cc}/gu, "")
64
+ .replaceAll(/\s+/g, " ")
72
65
  .trim();
73
66
  }
74
67
 
75
68
  export function getMessageContentText(content: unknown): string {
76
69
  if (!Array.isArray(content)) return "";
77
70
  return content
78
- .map((entry: any) => {
71
+ .map((entry: unknown) => {
79
72
  if (!entry || typeof entry !== "object") return "";
80
73
  if (typeof entry.text !== "string") return "";
81
74
  return entry.text;
@@ -90,11 +83,11 @@ export function collectTranscriptLines(sessionFile: string): string[] {
90
83
  const seen = new Set<string>();
91
84
 
92
85
  try {
93
- const raw = fs.readFileSync(sessionFile, "utf-8");
86
+ const raw = fs.readFileSync(sessionFile, "utf8");
94
87
  const lines = raw.split(/\r?\n/).filter((line) => line.trim().length > 0);
95
88
 
96
89
  for (const line of lines) {
97
- let parsed: any;
90
+ let parsed: unknown;
98
91
  try {
99
92
  parsed = JSON.parse(line);
100
93
  } catch {
@@ -142,89 +135,32 @@ export function looksLikeBadSummary(output: string): boolean {
142
135
  );
143
136
  }
144
137
 
145
- async function waitForSentinelClose(sentinelPath: string, timeoutMs: number): Promise<void> {
146
- const deadline = Date.now() + timeoutMs;
147
- while (true) {
148
- if (fs.existsSync(sentinelPath)) return;
149
- if (Date.now() >= deadline) {
150
- logDebug("codex-capture", `watch timeout reached waiting for sentinel ${sentinelPath}`);
151
- return;
152
- }
153
-
154
- const remainingMs = deadline - Date.now();
155
- await sleep(Math.max(0, Math.min(POLL_INTERVAL_MS, remainingMs)));
156
- }
157
- }
158
-
159
- function normalizeWatchTarget(target: string | PaneWatchTarget): PaneWatchTarget {
160
- if (typeof target === "string") {
161
- return { backend: "tmux", paneId: target };
162
- }
163
- return target;
164
- }
165
-
166
- export async function waitForPaneClose(
167
- target: string | PaneWatchTarget,
168
- timeoutMs = WAIT_TIMEOUT_MS_DEFAULT,
169
- ): Promise<void> {
170
- const watch = normalizeWatchTarget(target);
171
-
172
- if (watch.sentinelPath) {
173
- await waitForSentinelClose(watch.sentinelPath, timeoutMs);
174
- return;
175
- }
176
-
177
- const backend = watch.backend ?? "tmux";
178
- const paneId = watch.paneId ?? "";
179
-
180
- if (backend !== "tmux") {
181
- logDebug("codex-capture", `No pane watcher for backend=${backend}; continuing without wait`);
182
- return;
183
- }
184
-
185
- if (!paneId) return;
186
-
187
- const tmux = getTmuxAvailability({ requireSessionEnv: false });
188
- if (!tmux.available || !tmux.tmuxPath) {
189
- logWarn("codex-capture", `tmux unavailable while watching pane ${paneId}: ${tmux.reason ?? "unknown reason"}`);
190
- return;
191
- }
192
-
193
- const deadline = Date.now() + timeoutMs;
194
- while (true) {
195
- if (Date.now() >= deadline) {
196
- logDebug("codex-capture", `watch timeout reached for pane ${paneId} after ${timeoutMs}ms`);
197
- return;
198
- }
199
-
200
- const result = await execFileAsync(tmux.tmuxPath, ["list-panes", "-a", "-F", "#{pane_id}"], {
201
- timeout: POLL_TIMEOUT_MS,
202
- });
203
-
204
- if (result.exitCode !== 0) {
205
- logDebug("codex-capture", `list-panes failed; assuming pane closed (${result.stderr.trim() || "no stderr"})`);
206
- return;
207
- }
208
-
209
- const activePaneIds = result.stdout.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
210
- if (!activePaneIds.includes(paneId)) return;
211
-
212
- const remainingMs = deadline - Date.now();
213
- await sleep(Math.max(0, Math.min(POLL_INTERVAL_MS, remainingMs)));
214
- }
215
- }
216
-
217
- export function summarizeViaSessionFileSpark(sessionFile: string): string | null {
138
+ export async function summarizeViaSessionFile(sessionFile: string): Promise<string | null> {
218
139
  const transcriptLines = collectTranscriptLines(sessionFile);
219
140
  if (transcriptLines.length === 0) return null;
220
141
 
221
142
  const transcript = transcriptLines.join("\n");
143
+ const fullPrompt = `${TRANSCRIPT_SUMMARY_PROMPT}\n\nSession transcript excerpt:\n\n${transcript}`;
144
+
145
+ const codexResult = await execFileAsync(
146
+ "codex",
147
+ ["exec", fullPrompt, "--model", CODEX_MODELS.spark, "--json"],
148
+ { timeout: SUMMARY_TIMEOUT_SEC * 1000 },
149
+ );
150
+ if (codexResult.exitCode === 0 && codexResult.stdout.trim()) {
151
+ const output = codexResult.stdout.trim();
152
+ if (!looksLikeBadSummary(output)) return output;
153
+ }
154
+ logWarn(
155
+ "codex-capture",
156
+ `Codex Spark transcript summary failed (exit=${codexResult.exitCode}), falling back to Haiku`,
157
+ );
158
+
222
159
  const result = inference(
223
160
  TRANSCRIPT_SUMMARY_PROMPT,
224
161
  `Session transcript excerpt:\n\n${transcript}`,
225
162
  "fast",
226
163
  SUMMARY_TIMEOUT_SEC,
227
- { model: CODEX_MODELS.spark },
228
164
  );
229
165
 
230
166
  if (result.success && result.output && result.output.trim() && !looksLikeBadSummary(result.output)) {
@@ -238,6 +174,31 @@ export function summarizeViaSessionFileSpark(sessionFile: string): string | null
238
174
  return null;
239
175
  }
240
176
 
177
+ export function extractResumeSummary(text: string): string {
178
+ if (!text) return "";
179
+
180
+ const normalized = text.replaceAll("\r", "");
181
+ const marker = /(?:^|\n)codex\n/.exec(normalized);
182
+ if (!marker) return "";
183
+
184
+ const lines = normalized.slice(marker.index + marker[0].length).split("\n");
185
+ const bullets: string[] = [];
186
+ let collecting = false;
187
+
188
+ for (const rawLine of lines) {
189
+ const line = rawLine.trim();
190
+ if (!collecting && line.length === 0) continue;
191
+ if (line.startsWith("- ")) {
192
+ bullets.push(line);
193
+ collecting = true;
194
+ continue;
195
+ }
196
+ if (collecting) break;
197
+ }
198
+
199
+ return bullets.length >= 2 ? bullets.join("\n") : "";
200
+ }
201
+
241
202
  export async function summarizeViaResume(sessionId: string): Promise<string | null> {
242
203
  const outputFile = path.join(os.tmpdir(), `codex-resume-summary-${Date.now()}-${process.pid}.txt`);
243
204
 
@@ -261,7 +222,16 @@ export async function summarizeViaResume(sessionId: string): Promise<string | nu
261
222
  safeCleanup(outputFile);
262
223
 
263
224
  if (summary && !looksLikeBadSummary(summary)) return summary;
264
- logWarn("codex-capture", `codex exec resume failed for ${sessionId}: exit=${result.exitCode}, stderr=${result.stderr.trim() || "none"}`);
225
+
226
+ const stdoutSummary = extractResumeSummary(result.stdout);
227
+ if (stdoutSummary && !looksLikeBadSummary(stdoutSummary)) return stdoutSummary;
228
+
229
+ const stderrSummary = extractResumeSummary(result.stderr);
230
+ if (stderrSummary && !looksLikeBadSummary(stderrSummary)) return stderrSummary;
231
+
232
+ const stderrTrimmed = result.stderr.trim();
233
+ const stderrPreview = stderrTrimmed.length > 200 ? `${stderrTrimmed.slice(0, 200)}...` : (stderrTrimmed || "none");
234
+ logWarn("codex-capture", `codex exec resume failed for ${sessionId}: exit=${result.exitCode}, stderr=${stderrPreview}`);
265
235
  return null;
266
236
  }
267
237
 
@@ -270,3 +240,6 @@ export function summarizeFromSessionFileFallback(sessionFile: string): string |
270
240
  if (lines.length === 0) return null;
271
241
  return `Codex session completed. Transcript fallback:\n- ${lines.join("\n- ")}`;
272
242
  }
243
+
244
+
245
+
@@ -9,19 +9,22 @@
9
9
  */
10
10
  import * as fs from "node:fs";
11
11
  import * as os from "node:os";
12
- import * as path from "node:path";
13
-
14
- import { launchDriverInTmuxOrFallback } from "../../../lib-ts/base/tmux-driver.js";
15
- import { cleanupSentinelPath } from "../../../lib-ts/base/sentinel-ipc.js";
16
- import { getProjectRoot } from "../../../lib-ts/base/constants.js";
17
- import { resolveCodexModel, codexReplSpec, buildCliInvocation, isCodexSandbox, type CodexSandbox, type CliArgSpec } from "../../../lib-ts/base/cli-args.js";
18
- import { CODEX_MODELS } from "../../../lib-ts/base/models.js";
19
- import { logDebug, logWarn } from "../../../lib-ts/base/logger.js";
20
- import { displayPath } from "../../../lib-ts/base/utils.js";
21
- import { getContextBySessionId, getContext } from "../../../lib-ts/context/context-store.js";
22
- import { buildExternalAgentContext } from "../../../lib-ts/context/context-formatter.js";
12
+ import path from "node:path";
13
+
23
14
  import { findLatestPlan } from "../../../lib-ts/context/plan-manager.js";
24
- import type { ContextState } from "../../../lib-ts/types.js";
15
+ import {
16
+ findLatestPlanByMtime,
17
+ resolveContextForLaunch,
18
+ sleep,
19
+ writeFileRefPromptFile,
20
+ writeInlinePromptFile,
21
+ } from "../../../lib-ts/runtime/agent-launcher.js";
22
+ import { aiwLaunch } from "../../../lib-ts/runtime/aiw-cli.js";
23
+ import { resolveCodexModel, buildCliInvocation, isCodexSandbox, type CodexSandbox, type CliArgSpec } from "../../../lib-ts/runtime/cli-args.js";
24
+ import { getProjectRoot } from "../../../lib-ts/runtime/constants.js";
25
+ import { logDebug, logWarn } from "../../../lib-ts/runtime/logger.js";
26
+ import { CODEX_MODELS } from "../../../lib-ts/runtime/models.js";
27
+ import { displayPath } from "../../../lib-ts/runtime/utils.js";
25
28
 
26
29
  /** Codex-specific model abbreviations. Checked before tier resolution. */
27
30
  const CODEX_ALIASES: Record<string, string> = {
@@ -30,9 +33,9 @@ const CODEX_ALIASES: Record<string, string> = {
30
33
  gpt: CODEX_MODELS.gpt,
31
34
  };
32
35
 
33
- const SESSION_DISCOVERY_TIMEOUT_MS = 12000;
36
+ const SESSION_DISCOVERY_TIMEOUT_MS = 12_000;
34
37
  const SESSION_DISCOVERY_POLL_MS = 250;
35
- const SESSION_MTIME_WINDOW_MS = 120000;
38
+ const SESSION_MTIME_WINDOW_MS = 120_000;
36
39
 
37
40
  // ---------------------------------------------------------------------------
38
41
  // Helpers
@@ -42,8 +45,12 @@ function eprint(...args: unknown[]): void {
42
45
  process.stderr.write(args.map(String).join(" ") + "\n");
43
46
  }
44
47
 
45
- function sleep(ms: number): Promise<void> {
46
- return new Promise((resolve) => setTimeout(resolve, ms));
48
+ function cleanupSentinel(sentinelPath: string | null | undefined): void {
49
+ if (!sentinelPath) return;
50
+ try {
51
+ const dir = path.dirname(sentinelPath);
52
+ fs.rmSync(dir, { recursive: true, force: true });
53
+ } catch { /* best-effort */ }
47
54
  }
48
55
 
49
56
  function collectSessionJsonlFiles(rootDir: string): string[] {
@@ -83,17 +90,21 @@ function samePath(a: string, b: string): boolean {
83
90
  return left === right;
84
91
  }
85
92
 
86
- function readSessionMeta(sessionFile: string): { sessionId: string; cwd: string } | null {
93
+ function readSessionMeta(sessionFile: string): { sessionId: string; cwd: string; startedAtMs: number } | null {
87
94
  try {
88
- const raw = fs.readFileSync(sessionFile, "utf-8");
95
+ const raw = fs.readFileSync(sessionFile, "utf8");
89
96
  const firstLine = raw.split(/\r?\n/).find((line) => line.trim().length > 0);
90
97
  if (!firstLine) return null;
91
98
  const parsed = JSON.parse(firstLine);
92
99
  if (parsed?.type !== "session_meta") return null;
93
100
  const sessionId = parsed?.payload?.id;
94
101
  const cwd = parsed?.payload?.cwd;
102
+ const startedAt = parsed?.payload?.timestamp;
95
103
  if (typeof sessionId !== "string" || typeof cwd !== "string") return null;
96
- return { sessionId, cwd };
104
+ const startedAtMs = typeof startedAt === "string"
105
+ ? (Date.parse(startedAt) || 0)
106
+ : 0;
107
+ return { sessionId, cwd, startedAtMs };
97
108
  } catch {
98
109
  return null;
99
110
  }
@@ -102,12 +113,14 @@ function readSessionMeta(sessionFile: string): { sessionId: string; cwd: string
102
113
  function findLatestSessionCandidate(
103
114
  projectRoot: string,
104
115
  launchStartedAtMs: number,
116
+ requireProjectCwd = true,
105
117
  ): { sessionId: string; sessionFile: string } | null {
106
118
  const sessionsRoot = path.join(os.homedir(), ".codex", "sessions");
107
119
  const files = collectSessionJsonlFiles(sessionsRoot);
108
120
  if (files.length === 0) return null;
109
121
 
110
122
  const candidates: Array<{ sessionId: string; sessionFile: string; mtimeMs: number }> = [];
123
+ const currentThreadId = process.env.CODEX_THREAD_ID ?? "";
111
124
  for (const sessionFile of files) {
112
125
  let mtimeMs = 0;
113
126
  try {
@@ -119,7 +132,9 @@ function findLatestSessionCandidate(
119
132
 
120
133
  const meta = readSessionMeta(sessionFile);
121
134
  if (!meta) continue;
122
- if (!samePath(meta.cwd, projectRoot)) continue;
135
+ if (currentThreadId && meta.sessionId === currentThreadId) continue;
136
+ if (meta.startedAtMs > 0 && meta.startedAtMs < launchStartedAtMs - 1000) continue;
137
+ if (requireProjectCwd && !samePath(meta.cwd, projectRoot)) continue;
123
138
 
124
139
  candidates.push({ sessionId: meta.sessionId, sessionFile, mtimeMs });
125
140
  }
@@ -136,38 +151,12 @@ async function waitForCaptureSession(
136
151
  ): Promise<{ sessionId: string; sessionFile: string } | null> {
137
152
  const deadline = Date.now() + SESSION_DISCOVERY_TIMEOUT_MS;
138
153
  while (Date.now() < deadline) {
139
- const candidate = findLatestSessionCandidate(projectRoot, launchStartedAtMs);
154
+ const candidate = findLatestSessionCandidate(projectRoot, launchStartedAtMs, true);
140
155
  if (candidate) return candidate;
141
156
  await sleep(SESSION_DISCOVERY_POLL_MS);
142
157
  }
143
- return findLatestSessionCandidate(projectRoot, launchStartedAtMs);
144
- }
145
-
146
- /** Fallback plan discovery: scan all context plan dirs by mtime. */
147
- function findLatestPlanByMtime(projectRoot: string): string | null {
148
- const contextsDir = path.join(projectRoot, "_output", "contexts");
149
- if (!fs.existsSync(contextsDir)) return null;
150
-
151
- let best: { path: string; mtime: number } | null = null;
152
-
153
- for (const ctxEntry of fs.readdirSync(contextsDir)) {
154
- if (ctxEntry.startsWith("_")) continue;
155
- const plansDir = path.join(contextsDir, ctxEntry, "plans");
156
- if (!fs.existsSync(plansDir)) continue;
157
-
158
- for (const file of fs.readdirSync(plansDir)) {
159
- if (!file.endsWith(".md")) continue;
160
- const fullPath = path.join(plansDir, file);
161
- try {
162
- const mtime = fs.statSync(fullPath).mtimeMs;
163
- if (!best || mtime > best.mtime) {
164
- best = { path: fullPath, mtime };
165
- }
166
- } catch { /* skip unreadable */ }
167
- }
168
- }
169
-
170
- return best?.path ?? null;
158
+ // Fallback: tolerate launcher cwd drift (common on Windows pane backends).
159
+ return findLatestSessionCandidate(projectRoot, launchStartedAtMs, false);
171
160
  }
172
161
 
173
162
  // ---------------------------------------------------------------------------
@@ -204,18 +193,32 @@ for (let i = 0; i < rawArgs.length; i++) {
204
193
  contextFlag = rawArgs[++i];
205
194
  } else if (rawArgs[i] === "--prompt" && i + 1 < rawArgs.length) {
206
195
  extraPrompt = rawArgs[++i];
207
- } else if (rawArgs[i] === "--prompt") {
196
+ } else switch (rawArgs[i]) {
197
+ case "--no-watch": {
198
+ watch = false;
199
+
200
+ break;
201
+ }
202
+ case "--no-yolo": {
203
+ yolo = false;
204
+
205
+ break;
206
+ }
207
+ case "--prompt": {
208
208
  eprint("Error: --prompt requires a text argument.");
209
209
  process.exit(1);
210
- } else if (rawArgs[i] === "--yolo") {
210
+
211
+ break;
212
+ }
213
+ case "--yolo": {
211
214
  yolo = true;
212
- } else if (rawArgs[i] === "--no-yolo") {
213
- yolo = false;
214
- } else if (rawArgs[i] === "--no-watch") {
215
- watch = false;
216
- } else {
215
+
216
+ break;
217
+ }
218
+ default: {
217
219
  args.push(rawArgs[i]);
218
220
  }
221
+ }
219
222
  }
220
223
 
221
224
  if (args.length === 0) {
@@ -233,21 +236,9 @@ if (modelFlag) {
233
236
  }
234
237
 
235
238
  let promptPath: string | null = null;
236
- let tempFile: string | null = null;
237
239
 
238
240
  const projectRoot = getProjectRoot(process.cwd());
239
-
240
- // Context lookup — available for all modes (orientation header + plan discovery)
241
- // --context flag preferred (passed by skill caller); CLAUDE_SESSION_ID as fallback (hooks only)
242
- let ctx: ContextState | null = null;
243
- if (contextFlag) {
244
- ctx = getContext(contextFlag, projectRoot) ?? null;
245
- } else {
246
- const sessionId = process.env.CLAUDE_SESSION_ID;
247
- if (sessionId) {
248
- ctx = getContextBySessionId(sessionId, projectRoot) ?? null;
249
- }
250
- }
241
+ const ctx = resolveContextForLaunch(contextFlag, projectRoot);
251
242
 
252
243
  if (args[0] === "plan") {
253
244
  // Plan discovery: context system first, mtime fallback second
@@ -266,8 +257,15 @@ if (args[0] === "plan") {
266
257
  process.exit(1);
267
258
  }
268
259
 
269
- promptPath = planPath;
270
260
  console.log(`Found plan: ${displayPath(planPath)}`);
261
+ promptPath = writeFileRefPromptFile({
262
+ fileReferencePath: path.resolve(planPath),
263
+ label: "plan",
264
+ extraPrompt,
265
+ ctx,
266
+ projectRoot,
267
+ tempFilePrefix: "codex",
268
+ });
271
269
 
272
270
  } else if (args[0] === "--file") {
273
271
  if (!args[1]) {
@@ -279,69 +277,48 @@ if (args[0] === "plan") {
279
277
  eprint(`Error: File not found: ${filePath}`);
280
278
  process.exit(1);
281
279
  }
282
- promptPath = filePath;
280
+ promptPath = writeFileRefPromptFile({
281
+ fileReferencePath: filePath,
282
+ label: "file",
283
+ extraPrompt,
284
+ ctx,
285
+ projectRoot,
286
+ tempFilePrefix: "codex",
287
+ });
283
288
 
284
289
  } else {
285
- // Inline text: join args, write to temp file
286
- const text = args.join(" ");
287
- tempFile = path.join(os.tmpdir(), `codex-prompt-${Date.now()}.md`);
288
- fs.writeFileSync(tempFile, text, "utf-8");
289
- promptPath = tempFile;
290
- }
291
-
292
- // Prepend context orientation if available — graceful degradation on failure
293
- if (ctx && promptPath) {
294
- try {
295
- const orientation = buildExternalAgentContext(ctx, projectRoot);
296
- const original = fs.readFileSync(promptPath, "utf-8");
297
- const combined = `${orientation}\n\n---\n\n${original}`;
298
- const contextPromptPath = path.join(os.tmpdir(), `codex-ctx-prompt-${Date.now()}.md`);
299
- fs.writeFileSync(contextPromptPath, combined, "utf-8");
300
- if (tempFile) {
301
- try { fs.unlinkSync(tempFile); } catch { /* ignore */ }
302
- }
303
- promptPath = contextPromptPath;
304
- tempFile = contextPromptPath;
305
- } catch {
306
- logWarn("codex-skill", `Context orientation prepend failed for ${ctx.id}, continuing without header`);
307
- }
308
- }
309
-
310
- if (extraPrompt && promptPath) {
311
- try {
312
- const base = fs.readFileSync(promptPath, "utf-8");
313
- const combined = `${base}\n\n---\n\n## Additional Instructions\n\n${extraPrompt}`;
314
- const extraPromptPath = path.join(os.tmpdir(), `codex-extra-prompt-${Date.now()}.md`);
315
- fs.writeFileSync(extraPromptPath, combined, "utf-8");
316
- if (tempFile) {
317
- try { fs.unlinkSync(tempFile); } catch { /* ignore */ }
318
- }
319
- promptPath = extraPromptPath;
320
- tempFile = extraPromptPath;
321
- } catch {
322
- logWarn("codex-skill", "Extra prompt append failed, continuing without it");
323
- }
290
+ // Inline text: join args, write to temp file with context + extra prompt
291
+ promptPath = writeInlinePromptFile({
292
+ text: args.join(" "),
293
+ extraPrompt,
294
+ ctx,
295
+ projectRoot,
296
+ tempFilePrefix: "codex",
297
+ });
324
298
  }
325
299
 
326
300
  // ---------------------------------------------------------------------------
327
301
  // Launch Codex
328
302
  // ---------------------------------------------------------------------------
329
303
 
330
- const codexArgs = buildCliInvocation(codexReplSpec(resolvedModel, sandboxFlag, yolo)).args;
304
+ const launchCwd = process.env.AIW_CALLER_CWD?.trim() || process.cwd();
331
305
  if (yolo) console.log("Mode: YOLO (bypass approvals and sandbox)");
332
306
  if (sandboxFlag) console.log(`Sandbox: ${sandboxFlag}`);
333
307
  if (resolvedModel) console.log(`Model: ${resolvedModel}${modelFlag !== resolvedModel ? ` (from "${modelFlag}")` : ""}`);
334
308
 
335
- logDebug("codex-skill", `Launching: model=${resolvedModel ?? "default"}, sandbox=${sandboxFlag ?? "default"}, yolo=${yolo}, extraPrompt=${!!extraPrompt}, source=${args[0]}, bytes=${promptPath ? fs.statSync(promptPath).size : 0}`);
309
+ logDebug("codex-skill", `Launching: model=${resolvedModel ?? "default"}, sandbox=${sandboxFlag ?? "default"}, yolo=${yolo}, extraPrompt=${Boolean(extraPrompt)}, source=${args[0]}, bytes=${promptPath ? fs.statSync(promptPath).size : 0}`);
336
310
 
337
311
  const launchStartedAtMs = Date.now();
338
- const result = await launchDriverInTmuxOrFallback({
339
- toolName: "codex",
340
- mode: "repl",
341
- args: codexArgs,
342
- splitFlag: "auto",
312
+
313
+ // Shell out to `aiw launch` instead of importing tmux modules directly.
314
+ // This consolidates all pane-launching logic in the CLI binary.
315
+ const result = await aiwLaunch({
316
+ codex: true,
317
+ wait: false,
318
+ json: true,
319
+ split: "auto",
343
320
  promptPath: promptPath ?? undefined,
344
- allowExecFallback: false,
321
+ cwd: launchCwd,
345
322
  });
346
323
 
347
324
  if (!result.launched) {
@@ -355,13 +332,13 @@ if (!result.launched) {
355
332
  sandbox: sandboxFlag ?? "danger-full-access",
356
333
  };
357
334
  const execInv = buildCliInvocation(execSpec);
358
- const promptContent = promptPath ? fs.readFileSync(promptPath, "utf-8") : "";
335
+ const promptContent = promptPath ? fs.readFileSync(promptPath, "utf8") : "";
359
336
 
360
- if (tempFile) {
361
- try { fs.unlinkSync(tempFile); } catch { /* ignore */ }
337
+ if (promptPath) {
338
+ try { fs.unlinkSync(promptPath); } catch { /* ignore */ }
362
339
  }
363
340
 
364
- const { execFileAsync } = await import("../../../lib-ts/base/subprocess-utils.js");
341
+ const { execFileAsync } = await import("../../../lib-ts/runtime/subprocess-utils.js");
365
342
  const execResult = await execFileAsync(execInv.cliName, execInv.args, {
366
343
  input: promptContent,
367
344
  env: { ...process.env, ...execInv.env },
@@ -379,11 +356,7 @@ if (!result.launched) {
379
356
  process.exit(0);
380
357
  }
381
358
 
382
- if (tempFile) {
383
- try { fs.unlinkSync(tempFile); } catch { /* ignore */ }
384
- }
385
-
386
- const backendLabel = result.backend === "tmux" ? "tmux pane" : (result.backend === "wt" ? "Windows Terminal pane" : "window");
359
+ const backendLabel = result.backend === "tmux" ? "tmux pane" : result.backend === "psmux" ? "psmux pane" : "window";
387
360
  if (result.paneId) {
388
361
  console.log(`Codex launched in ${backendLabel}: ${result.paneId}`);
389
362
  } else {
@@ -393,10 +366,11 @@ if (result.paneId) {
393
366
  if (watch && (result.paneId || result.sentinelPath)) {
394
367
  try {
395
368
  const {
369
+ persistSummary,
396
370
  SUMMARY_UNAVAILABLE_MESSAGE,
397
371
  summarizeFromSessionFileFallback,
398
372
  summarizeViaResume,
399
- summarizeViaSessionFileSpark,
373
+ summarizeViaSessionFile,
400
374
  waitForPaneClose,
401
375
  } = await import("../lib/codex-watcher.js");
402
376
 
@@ -409,24 +383,36 @@ if (watch && (result.paneId || result.sentinelPath)) {
409
383
 
410
384
  const sessionFile = sessionInfo?.sessionFile ?? "";
411
385
  const sessionId = sessionInfo?.sessionId ?? "";
412
- const summary = summarizeViaSessionFileSpark(sessionFile)
386
+ const summary = (await summarizeViaSessionFile(sessionFile))
413
387
  ?? (sessionId ? await summarizeViaResume(sessionId) : null)
414
388
  ?? summarizeFromSessionFileFallback(sessionFile)
415
389
  ?? SUMMARY_UNAVAILABLE_MESSAGE;
390
+ const summaryPath = persistSummary(summary, "codex", sessionId || undefined);
416
391
 
417
392
  console.log("\n--- Codex Session Summary ---");
418
393
  console.log(summary);
394
+ if (summaryPath) {
395
+ console.log(`\n[summary_file:${summaryPath}]`);
396
+ }
419
397
  } catch (error) {
420
- logWarn("codex-skill", `Watch flow failed for ${result.paneId ?? result.backend}: ${String(error)}`);
398
+ logWarn("codex-skill", `Watch flow failed: ${String(error)}`);
399
+ const fallbackMsg = "Codex session completed. Summary unavailable (watch error).";
400
+ const { persistSummary: persistFallback } = await import("../lib/codex-watcher.js");
401
+ const fallbackPath = persistFallback(fallbackMsg, "codex");
421
402
  console.log("\n--- Codex Session Summary ---");
422
- console.log("Codex session completed. Summary unavailable.");
403
+ console.log(fallbackMsg);
404
+ if (fallbackPath) {
405
+ console.log(`\n[summary_file:${fallbackPath}]`);
406
+ }
423
407
  } finally {
424
- cleanupSentinelPath(result.sentinelPath);
408
+ cleanupSentinel(result.sentinelPath);
425
409
  }
426
410
  } else {
427
- cleanupSentinelPath(result.sentinelPath);
411
+ cleanupSentinel(result.sentinelPath);
428
412
  }
429
413
 
430
414
  if (result.reason) {
431
415
  eprint(`Warning: ${result.reason}`);
432
416
  }
417
+
418
+