oh-my-opencode 4.9.1 → 4.10.0

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 (220) hide show
  1. package/.agents/skills/opencode-qa/SKILL.md +1 -0
  2. package/.agents/skills/opencode-qa/scripts/lib/common.sh +39 -1
  3. package/.agents/skills/opencode-qa/scripts/lib/fake-openai-branches.mjs +39 -0
  4. package/.agents/skills/opencode-qa/scripts/lib/fake-openai-events.mjs +106 -0
  5. package/.agents/skills/opencode-qa/scripts/lib/fake-openai-server.mjs +117 -0
  6. package/.agents/skills/opencode-qa/scripts/serve-wake-split-probe.sh +716 -0
  7. package/.agents/skills/tech-debt-audit/SKILL.md +277 -0
  8. package/.agents/skills/work-with-pr-workspace/iteration-1/eval-5/with_skill/outputs/execution-plan.md +1 -1
  9. package/.opencode/skills/work-with-pr-workspace/iteration-1/eval-5/with_skill/outputs/execution-plan.md +1 -1
  10. package/bin/platform.js +5 -0
  11. package/bin/platform.test.ts +56 -0
  12. package/dist/agents/atlas/agent.d.ts +4 -3
  13. package/dist/agents/gpt-apply-patch-guard.d.ts +2 -2
  14. package/dist/agents/hephaestus/agent.d.ts +5 -0
  15. package/dist/agents/hephaestus/index.d.ts +1 -1
  16. package/dist/agents/metis.d.ts +1 -0
  17. package/dist/agents/prometheus/system-prompt.d.ts +1 -1
  18. package/dist/agents/sisyphus/kimi-k2-7.d.ts +17 -0
  19. package/dist/agents/sisyphus-junior/agent.d.ts +1 -1
  20. package/dist/agents/sisyphus-junior/kimi-k2-7.d.ts +11 -0
  21. package/dist/agents/types.d.ts +2 -2
  22. package/dist/cli/doctor/checks/codex-components.d.ts +13 -0
  23. package/dist/cli/doctor/checks/tui-plugin-config.d.ts +1 -0
  24. package/dist/cli/doctor/constants.d.ts +1 -1
  25. package/dist/cli/index.js +32329 -31437
  26. package/dist/cli/install-codex/codex-cleanup.d.ts +4 -0
  27. package/dist/cli/install-codex/install-codex-test-fixtures.d.ts +34 -0
  28. package/dist/cli/install-codex/link-cached-plugin-agents.d.ts +4 -0
  29. package/dist/cli/model-fallback.d.ts +1 -0
  30. package/dist/cli/provider-availability.d.ts +2 -0
  31. package/dist/cli-node/index.js +32329 -31437
  32. package/dist/config/schema/agent-overrides.d.ts +80 -16
  33. package/dist/config/schema/experimental.d.ts +1 -1
  34. package/dist/config/schema/hooks.d.ts +0 -1
  35. package/dist/config/schema/internal/permission.d.ts +5 -1
  36. package/dist/config/schema/oh-my-opencode-config.d.ts +76 -16
  37. package/dist/create-hooks.d.ts +0 -1
  38. package/dist/features/background-agent/index.d.ts +1 -1
  39. package/dist/features/background-agent/manager.d.ts +6 -0
  40. package/dist/features/background-agent/types.d.ts +2 -0
  41. package/dist/features/claude-code-plugin-loader/types.d.ts +3 -0
  42. package/dist/features/claude-code-session-state/state.d.ts +1 -0
  43. package/dist/features/skill-mcp-manager/manager.d.ts +11 -7
  44. package/dist/features/team-mode/team-mailbox/pending-delivery-recovery.d.ts +31 -0
  45. package/dist/features/team-mode/team-runtime/delete-team.d.ts +2 -1
  46. package/dist/features/team-mode/tools/lifecycle-inline-spec.d.ts +2 -2
  47. package/dist/features/tmux-subagent/stale-tmux-resource-sweeper.d.ts +12 -0
  48. package/dist/features/tool-metadata-store/store.d.ts +5 -0
  49. package/dist/hooks/anthropic-context-window-limit-recovery/storage/constants.d.ts +3 -0
  50. package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery}/storage/messages-reader.d.ts +1 -1
  51. package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery}/storage/part-content.d.ts +1 -1
  52. package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery}/storage/parts-reader.d.ts +1 -1
  53. package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery/storage}/types.d.ts +0 -13
  54. package/dist/hooks/auto-update-checker/checker/bundled-version.d.ts +1 -0
  55. package/dist/hooks/auto-update-checker/checker.d.ts +1 -0
  56. package/dist/hooks/auto-update-checker/constants.d.ts +3 -3
  57. package/dist/hooks/auto-update-checker/hook.d.ts +2 -1
  58. package/dist/hooks/claude-code-hooks/types.d.ts +4 -0
  59. package/dist/hooks/index.d.ts +0 -1
  60. package/dist/hooks/team-session-events/team-idle-wake-hint.d.ts +5 -0
  61. package/dist/index.js +6061 -3714
  62. package/dist/oh-my-opencode.schema.json +123 -18
  63. package/dist/plugin/build-team-idle-wake-hint-client.d.ts +2 -0
  64. package/dist/plugin/event-session-lifecycle.d.ts +0 -3
  65. package/dist/plugin/hooks/create-continuation-hooks.d.ts +0 -6
  66. package/dist/plugin/hooks/create-core-hooks.d.ts +0 -1
  67. package/dist/plugin/hooks/create-session-hooks.d.ts +1 -2
  68. package/dist/shared/command-executor/execute-hook-command.d.ts +7 -0
  69. package/dist/shared/internal-initiator-marker.d.ts +7 -0
  70. package/dist/shared/live-server-route.d.ts +24 -0
  71. package/dist/shared/plugin-identity.d.ts +2 -2
  72. package/dist/shared/prompt-async-gate/prompt-message-state.d.ts +1 -0
  73. package/dist/shared/tmux/tmux-utils/server-health.d.ts +2 -1
  74. package/dist/shared/tmux/tmux-utils/stale-attach-pane-sweep.d.ts +16 -0
  75. package/dist/shared/tmux/tmux-utils.d.ts +1 -0
  76. package/dist/testing/create-plugin-module.d.ts +4 -0
  77. package/dist/tools/background-task/clients.d.ts +2 -0
  78. package/dist/tools/background-task/full-session-format.d.ts +1 -0
  79. package/dist/tools/background-task/types.d.ts +1 -0
  80. package/dist/tools/delegate-task/sync-prompt-sender.d.ts +1 -1
  81. package/dist/tools/delegate-task/sync-session-lifecycle.d.ts +2 -1
  82. package/dist/tools/look-at/look-at-input-preparer.d.ts +6 -2
  83. package/dist/tools/look-at/look-at-prompt.d.ts +2 -1
  84. package/dist/tools/look-at/look-at-session-runner.d.ts +3 -4
  85. package/dist/tools/look-at/types.d.ts +2 -0
  86. package/dist/tools/session-manager/types.d.ts +1 -0
  87. package/dist/tools/skill-mcp/types.d.ts +1 -0
  88. package/package.json +14 -13
  89. package/packages/ast-grep-mcp/dist/cli.js +50 -17
  90. package/packages/lsp-daemon/dist/cli.js +8 -5
  91. package/packages/lsp-daemon/dist/index.js +8 -5
  92. package/packages/lsp-tools-mcp/dist/lsp/connection.js +1 -1
  93. package/packages/lsp-tools-mcp/dist/lsp/server-definitions.js +2 -2
  94. package/packages/lsp-tools-mcp/dist/lsp/transport.d.ts +10 -1
  95. package/packages/lsp-tools-mcp/dist/lsp/transport.js +6 -3
  96. package/packages/omo-codex/lazycodex-repository/.github/workflows/pr-source-guidance.yml +11 -12
  97. package/packages/omo-codex/plugin/.codex-plugin/plugin.json +1 -1
  98. package/packages/omo-codex/plugin/components/bootstrap/dist/cli.js +2583 -0
  99. package/packages/omo-codex/plugin/components/bootstrap/hooks/hooks.json +17 -0
  100. package/packages/omo-codex/plugin/components/bootstrap/manifests/ast-grep.json +22 -0
  101. package/packages/omo-codex/plugin/components/bootstrap/manifests/node.json +10 -0
  102. package/packages/omo-codex/plugin/components/bootstrap/package.json +20 -0
  103. package/packages/omo-codex/plugin/components/bootstrap/scripts/bootstrap.ps1 +310 -0
  104. package/packages/omo-codex/plugin/components/bootstrap/scripts/build.mjs +35 -0
  105. package/packages/omo-codex/plugin/components/bootstrap/scripts/generate-manifests.mjs +115 -0
  106. package/packages/omo-codex/plugin/components/bootstrap/src/cli.ts +153 -0
  107. package/packages/omo-codex/plugin/components/bootstrap/src/download.ts +212 -0
  108. package/packages/omo-codex/plugin/components/bootstrap/src/environment.ts +286 -0
  109. package/packages/omo-codex/plugin/components/bootstrap/src/hook.ts +108 -0
  110. package/packages/omo-codex/plugin/components/bootstrap/src/provision.ts +243 -0
  111. package/packages/omo-codex/plugin/components/bootstrap/src/setup.ts +294 -0
  112. package/packages/omo-codex/plugin/components/bootstrap/src/worker.ts +279 -0
  113. package/packages/omo-codex/plugin/components/bootstrap/test/download.test.ts +295 -0
  114. package/packages/omo-codex/plugin/components/bootstrap/test/environment.test.ts +375 -0
  115. package/packages/omo-codex/plugin/components/bootstrap/test/provision.test.ts +464 -0
  116. package/packages/omo-codex/plugin/components/bootstrap/tsconfig.json +25 -0
  117. package/packages/omo-codex/plugin/components/comment-checker/hooks/hooks.json +1 -1
  118. package/packages/omo-codex/plugin/components/comment-checker/package.json +4 -4
  119. package/packages/omo-codex/plugin/components/git-bash/hooks/hooks.json +2 -2
  120. package/packages/omo-codex/plugin/components/git-bash/package.json +2 -2
  121. package/packages/omo-codex/plugin/components/lsp/dist/codex-hook-cli.js +6 -10
  122. package/packages/omo-codex/plugin/components/lsp/hooks/hooks.json +2 -2
  123. package/packages/omo-codex/plugin/components/lsp/package.json +4 -4
  124. package/packages/omo-codex/plugin/components/lsp/scripts/build-lsp-tools.test.mjs +8 -3
  125. package/packages/omo-codex/plugin/components/lsp/src/codex-hook-cli.ts +5 -8
  126. package/packages/omo-codex/plugin/components/lsp/test/codex-hook-cli.test.ts +24 -1
  127. package/packages/omo-codex/plugin/components/rules/bundled-rules/windows-git-bash.md +3 -1
  128. package/packages/omo-codex/plugin/components/rules/hooks/hooks.json +4 -4
  129. package/packages/omo-codex/plugin/components/rules/package.json +4 -4
  130. package/packages/omo-codex/plugin/components/rules/test/windows-git-bash-bundled-rule.test.ts +35 -1
  131. package/packages/omo-codex/plugin/components/start-work-continuation/hooks/hooks.json +2 -2
  132. package/packages/omo-codex/plugin/components/start-work-continuation/package.json +4 -4
  133. package/packages/omo-codex/plugin/components/telemetry/hooks/hooks.json +1 -1
  134. package/packages/omo-codex/plugin/components/telemetry/package.json +4 -4
  135. package/packages/omo-codex/plugin/components/ultrawork/biome.json +1 -1
  136. package/packages/omo-codex/plugin/components/ultrawork/directive.md +155 -99
  137. package/packages/omo-codex/plugin/components/ultrawork/hooks/hooks.json +1 -1
  138. package/packages/omo-codex/plugin/components/ultrawork/package.json +4 -4
  139. package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/SKILL.md +19 -51
  140. package/packages/omo-codex/plugin/components/ultrawork/skills/ulw-plan/references/full-workflow.md +46 -51
  141. package/packages/omo-codex/plugin/components/ultrawork/test/codex-hook.test.ts +19 -0
  142. package/packages/omo-codex/plugin/components/ultrawork/test/package-smoke.test.ts +0 -1
  143. package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-commands.js +9 -1
  144. package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-output.d.ts +1 -0
  145. package/packages/omo-codex/plugin/components/ulw-loop/dist/cli-output.js +18 -0
  146. package/packages/omo-codex/plugin/components/ulw-loop/dist/plan-crud.js +1 -3
  147. package/packages/omo-codex/plugin/components/ulw-loop/hooks/hooks.json +2 -2
  148. package/packages/omo-codex/plugin/components/ulw-loop/package.json +4 -4
  149. package/packages/omo-codex/plugin/components/ulw-loop/src/cli-commands.ts +6 -2
  150. package/packages/omo-codex/plugin/components/ulw-loop/src/cli-output.ts +19 -0
  151. package/packages/omo-codex/plugin/components/ulw-loop/src/plan-crud.ts +1 -1
  152. package/packages/omo-codex/plugin/components/ulw-loop/test/cli-commands.test.ts +6 -0
  153. package/packages/omo-codex/plugin/components/ulw-loop/test/cli-complete-goals.test.ts +26 -1
  154. package/packages/omo-codex/plugin/components/ulw-loop/test/cli-json-errors.test.ts +89 -0
  155. package/packages/omo-codex/plugin/hooks/hooks.json +27 -16
  156. package/packages/omo-codex/plugin/package-lock.json +193 -193
  157. package/packages/omo-codex/plugin/package.json +1 -1
  158. package/packages/omo-codex/plugin/scripts/auto-update-state.d.mts +20 -0
  159. package/packages/omo-codex/plugin/scripts/auto-update.mjs +28 -8
  160. package/packages/omo-codex/plugin/scripts/build-components.mjs +36 -5
  161. package/packages/omo-codex/plugin/scripts/install-flow.mjs +43 -0
  162. package/packages/omo-codex/plugin/skills/lcx-contribute-bug-fix/SKILL.md +79 -28
  163. package/packages/omo-codex/plugin/skills/lcx-contribute-bug-fix/agents/openai.yaml +2 -2
  164. package/packages/omo-codex/plugin/skills/lcx-report-bug/SKILL.md +7 -6
  165. package/packages/omo-codex/plugin/skills/lcx-report-bug/agents/openai.yaml +1 -1
  166. package/packages/omo-codex/plugin/skills/ulw-plan/SKILL.md +19 -51
  167. package/packages/omo-codex/plugin/skills/ulw-plan/references/full-workflow.md +46 -51
  168. package/packages/omo-codex/plugin/test/aggregate-manifest.test.mjs +1 -0
  169. package/packages/omo-codex/plugin/test/auto-update.test.mjs +145 -0
  170. package/packages/omo-codex/plugin/test/bootstrap-binlinks.test.mjs +250 -0
  171. package/packages/omo-codex/plugin/test/bootstrap-hooks.test.mjs +166 -0
  172. package/packages/omo-codex/plugin/test/bootstrap-orchestration.test.mjs +371 -0
  173. package/packages/omo-codex/plugin/test/bootstrap-ps-guard.test.mjs +134 -0
  174. package/packages/omo-codex/plugin/test/bootstrap-setup.test.mjs +249 -0
  175. package/packages/omo-codex/plugin/test/lcx-bug-skills.test.mjs +10 -1
  176. package/packages/omo-codex/plugin/test/ulw-plan-skill.test.mjs +46 -0
  177. package/packages/omo-codex/scripts/atomic-write.test.mjs +82 -0
  178. package/packages/omo-codex/scripts/install/agents.d.mts +18 -0
  179. package/packages/omo-codex/scripts/install/agents.mjs +78 -5
  180. package/packages/omo-codex/scripts/install/atomic-write.mjs +59 -0
  181. package/packages/omo-codex/scripts/install/bin-dir.d.mts +7 -0
  182. package/packages/omo-codex/scripts/install/bin-links.d.mts +18 -0
  183. package/packages/omo-codex/scripts/install/config.d.mts +35 -0
  184. package/packages/omo-codex/scripts/install/config.mjs +13 -3
  185. package/packages/omo-codex/scripts/install/git-bash-mcp-env.d.mts +5 -0
  186. package/packages/omo-codex/scripts/install/git-bash.d.mts +23 -0
  187. package/packages/omo-codex/scripts/install/hook-trust.d.mts +10 -0
  188. package/packages/omo-codex/scripts/install-agent-links.test.mjs +41 -0
  189. package/packages/omo-codex/scripts/install-local.mjs +3 -2
  190. package/packages/shared-skills/skills/lcx-contribute-bug-fix/SKILL.md +79 -28
  191. package/packages/shared-skills/skills/lcx-contribute-bug-fix/agents/openai.yaml +2 -2
  192. package/packages/shared-skills/skills/lcx-report-bug/SKILL.md +7 -6
  193. package/packages/shared-skills/skills/lcx-report-bug/agents/openai.yaml +1 -1
  194. package/dist/hooks/session-recovery/constants.d.ts +0 -4
  195. package/dist/hooks/session-recovery/detect-error-type.d.ts +0 -4
  196. package/dist/hooks/session-recovery/error-recovery.d.ts +0 -4
  197. package/dist/hooks/session-recovery/hook-types.d.ts +0 -22
  198. package/dist/hooks/session-recovery/hook.d.ts +0 -4
  199. package/dist/hooks/session-recovery/index.d.ts +0 -5
  200. package/dist/hooks/session-recovery/interrupted-idle-message-fetch-timeout.d.ts +0 -7
  201. package/dist/hooks/session-recovery/interrupted-tool-results.d.ts +0 -3
  202. package/dist/hooks/session-recovery/message-state.d.ts +0 -4
  203. package/dist/hooks/session-recovery/recover-thinking-block-order.d.ts +0 -5
  204. package/dist/hooks/session-recovery/recover-thinking-disabled-violation.d.ts +0 -5
  205. package/dist/hooks/session-recovery/recover-tool-result-missing.d.ts +0 -10
  206. package/dist/hooks/session-recovery/recover-unavailable-tool.d.ts +0 -5
  207. package/dist/hooks/session-recovery/resume.d.ts +0 -7
  208. package/dist/hooks/session-recovery/storage/latest-assistant-message.d.ts +0 -5
  209. package/dist/hooks/session-recovery/storage/orphan-thinking-search.d.ts +0 -2
  210. package/dist/hooks/session-recovery/storage/thinking-block-search.d.ts +0 -2
  211. package/dist/hooks/session-recovery/storage/thinking-prepend.d.ts +0 -33
  212. package/dist/hooks/session-recovery/storage/thinking-strip.d.ts +0 -11
  213. package/dist/hooks/session-recovery/storage.d.ts +0 -20
  214. package/dist/plugin/event-session-recovery.d.ts +0 -9
  215. package/dist/plugin/user-abort-interrupted-recovery-guard.d.ts +0 -6
  216. /package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery}/storage/empty-messages.d.ts +0 -0
  217. /package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery}/storage/empty-text.d.ts +0 -0
  218. /package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery}/storage/message-dir.d.ts +0 -0
  219. /package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery}/storage/part-id.d.ts +0 -0
  220. /package/dist/hooks/{session-recovery → anthropic-context-window-limit-recovery}/storage/text-part-injector.d.ts +0 -0
@@ -54,6 +54,7 @@ sandbox, free port, server start/stop, and an EXIT-trap cleanup). It requires
54
54
  | Export a whole session as JSON | D | `scripts/export-roundtrip.sh <ses_id>` | `references/db-investigation.md` |
55
55
  | Check the HTTP server / an endpoint | B | `scripts/server-smoke.sh` | `references/server-api.md` |
56
56
  | Prove a hook / action / event fired | B | `scripts/sse-hook-probe.sh` | `references/events-hooks.md` |
57
+ | Prove serve-topology wake runner-split (reproduced/fixed) | B | `scripts/serve-wake-split-probe.sh --expect reproduced\|fixed --evidence-dir DIR` (self-test: `--self-test`; fake LLM: `scripts/lib/fake-openai-server.mjs`) | `references/events-hooks.md` |
57
58
  | Smoke-test the TUI | C | `scripts/tui-smoke.sh` | `references/tui-tmux.md` |
58
59
  | Write/run a test in the opencode source | - | (bun test) | `references/testing-harness.md` |
59
60
  | Drive opencode from a Bun/TS script | - | (SDK) | `references/sdk.md` |
@@ -54,6 +54,16 @@ oqa_db_query() {
54
54
  opencode db "$1" --format json 2>/dev/null
55
55
  }
56
56
 
57
+ # Preserve HOME-based opencode shims after HOME is sandboxed. Some installed
58
+ # opencode wrappers resolve the real binary via "$HOME/.opencode/bin/opencode";
59
+ # after oqa_mk_isolated_xdg rewrites HOME, that path must still exist.
60
+ oqa_preserve_home_opencode_bin() {
61
+ local real_home="$1" sandbox_home="$2"
62
+ [ -d "$real_home/.opencode/bin" ] || return 0
63
+ mkdir -p "$sandbox_home/.opencode" || return 1
64
+ ln -s "$real_home/.opencode/bin" "$sandbox_home/.opencode/bin" 2>/dev/null || return 1
65
+ }
66
+
57
67
  # Create an isolated XDG sandbox so a spawned opencode never touches the real
58
68
  # DB. Sets globals OQA_XDG_ROOT + OQA_PROJ and exports XDG_*; registers the
59
69
  # root for cleanup.
@@ -63,10 +73,12 @@ oqa_db_query() {
63
73
  # oqa_mk_isolated_xdg # good
64
74
  # root="$OQA_XDG_ROOT" # read the global afterwards
65
75
  oqa_mk_isolated_xdg() {
66
- local root
76
+ local root real_home
67
77
  root="$(mktemp -d -t oqa-xdg.XXXXXX)" || return 1
78
+ real_home="$HOME"
68
79
  OQA_TMPDIRS+=("$root")
69
80
  mkdir -p "$root/data" "$root/config" "$root/cache" "$root/state" "$root/home" "$root/proj"
81
+ oqa_preserve_home_opencode_bin "$real_home" "$root/home" || return 1
70
82
  export OQA_XDG_ROOT="$root"
71
83
  export HOME="$root/home"
72
84
  export OPENCODE_TEST_HOME="$root/home"
@@ -214,6 +226,32 @@ oqa__self_check() {
214
226
  oqa_log "FAIL: sandbox HOME not isolated (HOME='$home' OPENCODE_TEST_HOME='$test_home' root='$isodir')"; fails=$((fails+1))
215
227
  fi
216
228
 
229
+ local shim_marker shim_result
230
+ shim_marker="$(mktemp -t oqa-shim.XXXXXX)"
231
+ bash -c '
232
+ set -u
233
+ . "'"${BASH_SOURCE[0]}"'"
234
+ fake_home="$(mktemp -d -t oqa-fake-home.XXXXXX)"
235
+ mkdir -p "$fake_home/.local/bin" "$fake_home/.opencode/bin"
236
+ printf "%s\n" "#!/usr/bin/env bash" "exec \"\$HOME/.opencode/bin/opencode\" \"\$@\"" > "$fake_home/.local/bin/opencode"
237
+ printf "%s\n" "#!/usr/bin/env bash" "exec \"\$HOME/.opencode/bin/opencode-real\" \"\$@\"" > "$fake_home/.opencode/bin/opencode"
238
+ printf "%s\n" "#!/usr/bin/env bash" "printf fake-opencode-ok" > "$fake_home/.opencode/bin/opencode-real"
239
+ chmod +x "$fake_home/.local/bin/opencode" "$fake_home/.opencode/bin/opencode" "$fake_home/.opencode/bin/opencode-real"
240
+ HOME="$fake_home"
241
+ PATH="$fake_home/.local/bin:$PATH"
242
+ oqa_mk_isolated_xdg
243
+ opencode > "'"$shim_marker"'"
244
+ oqa_cleanup
245
+ rm -rf "$fake_home"
246
+ '
247
+ shim_result="$(cat "$shim_marker" 2>/dev/null)"
248
+ rm -f "$shim_marker"
249
+ if [ "$shim_result" = "fake-opencode-ok" ]; then
250
+ oqa_pass "isolated HOME preserves HOME-based opencode shim"
251
+ else
252
+ oqa_log "FAIL: HOME-based opencode shim returned '$shim_result'"; fails=$((fails+1))
253
+ fi
254
+
217
255
  if [ "$fails" -eq 0 ]; then
218
256
  oqa_pass "common.sh self-check"
219
257
  return 0
@@ -0,0 +1,39 @@
1
+ export const branchCounts = {
2
+ title: 0,
3
+ "parent-tool-call": 0,
4
+ "parent-hold": 0,
5
+ child: 0,
6
+ wake: 0,
7
+ default: 0,
8
+ }
9
+
10
+ export const latches = {
11
+ parentToolCallIssued: false,
12
+ parentHoldIssued: false,
13
+ }
14
+
15
+ export function hasToolResult(inputStr) {
16
+ return (
17
+ inputStr.includes('"type":"function_call_output"') ||
18
+ inputStr.includes('"type": "function_call_output"') ||
19
+ inputStr.includes('"type":"tool_result"') ||
20
+ inputStr.includes('"type": "tool_result"') ||
21
+ inputStr.includes('"role":"tool"') ||
22
+ inputStr.includes('"role": "tool"')
23
+ )
24
+ }
25
+
26
+ export function selectBranch(inputStr) {
27
+ const isTitle = inputStr.includes("Generate a title")
28
+ const isSplitProbe = inputStr.includes("Run the split probe")
29
+ const isChild = inputStr.includes("SPLIT_CHILD_TASK")
30
+ const isWake = inputStr.includes("[BACKGROUND TASK")
31
+ const hasResult = hasToolResult(inputStr)
32
+
33
+ if (isTitle) return "title"
34
+ if (isChild && !isSplitProbe) return "child"
35
+ if (isWake) return "wake"
36
+ if (isSplitProbe && !hasResult && !latches.parentToolCallIssued) return "parent-tool-call"
37
+ if (isSplitProbe && (hasResult || latches.parentToolCallIssued) && !latches.parentHoldIssued) return "parent-hold"
38
+ return "default"
39
+ }
@@ -0,0 +1,106 @@
1
+ import fs from "node:fs"
2
+
3
+ export function completedUsage() {
4
+ return {
5
+ input_tokens: 10,
6
+ output_tokens: 5,
7
+ input_tokens_details: { cached_tokens: 0 },
8
+ output_tokens_details: { reasoning_tokens: 0 },
9
+ }
10
+ }
11
+
12
+ export function sendSse(res, events) {
13
+ res.writeHead(200, {
14
+ "content-type": "text/event-stream; charset=utf-8",
15
+ "cache-control": "no-cache",
16
+ connection: "keep-alive",
17
+ })
18
+ for (const event of events) {
19
+ res.write(`data: ${JSON.stringify(event)}\n\n`)
20
+ }
21
+ res.write("data: [DONE]\n\n")
22
+ res.end()
23
+ }
24
+
25
+ export function textEvents(callCount, text) {
26
+ const id = `resp_${callCount}`
27
+ const item = `msg_${callCount}`
28
+ return [
29
+ {
30
+ type: "response.created",
31
+ response: { id, created_at: Math.floor(Date.now() / 1000), model: "gpt-fake" },
32
+ },
33
+ {
34
+ type: "response.output_item.added",
35
+ output_index: 0,
36
+ item: { type: "message", id: item },
37
+ },
38
+ {
39
+ type: "response.output_text.delta",
40
+ item_id: item,
41
+ output_index: 0,
42
+ delta: text,
43
+ },
44
+ {
45
+ type: "response.output_item.done",
46
+ output_index: 0,
47
+ item: { type: "message", id: item },
48
+ },
49
+ {
50
+ type: "response.completed",
51
+ response: { usage: completedUsage() },
52
+ },
53
+ ]
54
+ }
55
+
56
+ export function toolCallEvents(callCount, name, callId, argsObj) {
57
+ const id = `resp_${callCount}`
58
+ const fcId = `fc_${callCount}`
59
+ const argsStr = JSON.stringify(argsObj)
60
+ return [
61
+ {
62
+ type: "response.created",
63
+ response: { id, created_at: Math.floor(Date.now() / 1000), model: "gpt-fake" },
64
+ },
65
+ {
66
+ type: "response.output_item.added",
67
+ output_index: 0,
68
+ item: {
69
+ type: "function_call",
70
+ id: fcId,
71
+ call_id: callId,
72
+ name,
73
+ arguments: "",
74
+ },
75
+ },
76
+ {
77
+ type: "response.function_call_arguments.delta",
78
+ item_id: fcId,
79
+ output_index: 0,
80
+ delta: argsStr,
81
+ },
82
+ {
83
+ type: "response.output_item.done",
84
+ output_index: 0,
85
+ item: {
86
+ type: "function_call",
87
+ id: fcId,
88
+ call_id: callId,
89
+ name,
90
+ arguments: argsStr,
91
+ status: "completed",
92
+ },
93
+ },
94
+ {
95
+ type: "response.completed",
96
+ response: { usage: completedUsage() },
97
+ },
98
+ ]
99
+ }
100
+
101
+ export function appendLog(logFile, line) {
102
+ try {
103
+ fs.appendFileSync(logFile, line)
104
+ } catch {
105
+ }
106
+ }
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env node
2
+ import http from "node:http"
3
+ import fs from "node:fs"
4
+ import path from "node:path"
5
+ import os from "node:os"
6
+ import { sendSse, textEvents, toolCallEvents, appendLog } from "./fake-openai-events.mjs"
7
+ import { branchCounts, latches, selectBranch } from "./fake-openai-branches.mjs"
8
+
9
+ const requestedPort = Number(process.env.FAKE_OPENAI_PORT ?? 0)
10
+ const logFile = process.env.FAKE_LLM_LOG ?? path.join(os.tmpdir(), "fake-llm.log")
11
+
12
+ let callCount = 0
13
+
14
+ function logBranch(branch, extra = {}) {
15
+ const now = new Date().toISOString()
16
+ const line = `[${now}] branch=${branch} call=${callCount}${Object.keys(extra).length ? " " + JSON.stringify(extra) : ""}\n`
17
+ appendLog(logFile, line)
18
+ process.stdout.write(line)
19
+ }
20
+
21
+ function readBody(req) {
22
+ return new Promise((resolve, reject) => {
23
+ const chunks = []
24
+ req.on("data", (chunk) => chunks.push(chunk))
25
+ req.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")))
26
+ req.on("error", reject)
27
+ })
28
+ }
29
+
30
+ function sleep(ms) {
31
+ return new Promise((resolve) => setTimeout(resolve, ms))
32
+ }
33
+
34
+ const server = http.createServer(async (req, res) => {
35
+ if (req.method === "GET" && req.url === "/health") {
36
+ res.writeHead(200, { "content-type": "text/plain" }).end("ok")
37
+ return
38
+ }
39
+
40
+ if (req.method !== "POST" || !req.url?.includes("/responses")) {
41
+ res.writeHead(404, { "content-type": "application/json" }).end(JSON.stringify({ error: "not found" }))
42
+ return
43
+ }
44
+
45
+ callCount++
46
+ const raw = await readBody(req)
47
+ let body
48
+ try { body = JSON.parse(raw) } catch { body = {} }
49
+
50
+ const inputStr = JSON.stringify(body.input ?? body.messages ?? body)
51
+ const branch = selectBranch(inputStr)
52
+ branchCounts[branch] = (branchCounts[branch] ?? 0) + 1
53
+ logBranch(branch)
54
+
55
+ if (branch === "title") {
56
+ sendSse(res, textEvents(callCount, "wake split probe session"))
57
+ return
58
+ }
59
+
60
+ if (branch === "child") {
61
+ sendSse(res, textEvents(callCount, "DONE"))
62
+ return
63
+ }
64
+
65
+ if (branch === "wake") {
66
+ await sleep(3000)
67
+ sendSse(res, textEvents(callCount, `WAKE_ACK ${callCount}`))
68
+ return
69
+ }
70
+
71
+ if (branch === "parent-tool-call") {
72
+ latches.parentToolCallIssued = true
73
+ sendSse(res, toolCallEvents(callCount, "task", `call_agent_${callCount}`, {
74
+ description: "split probe child",
75
+ prompt: "SPLIT_CHILD_TASK: reply exactly DONE",
76
+ subagent_type: "explore",
77
+ run_in_background: true,
78
+ load_skills: [],
79
+ }))
80
+ return
81
+ }
82
+
83
+ if (branch === "parent-hold") {
84
+ latches.parentHoldIssued = true
85
+ sendSse(res, toolCallEvents(callCount, "bash", `call_bash_${callCount}`, {
86
+ command: "i=0; while [ $i -lt 8 ]; do i=$((i+1)); sleep 1; done",
87
+ description: "hold turn",
88
+ }))
89
+ return
90
+ }
91
+
92
+ if (inputStr.includes("say exactly: TUI_NOREG_OK")) {
93
+ sendSse(res, textEvents(callCount, "TUI_NOREG_OK"))
94
+ return
95
+ }
96
+ sendSse(res, textEvents(callCount, `fake response ${callCount}`))
97
+ })
98
+
99
+ function logFinalCounts() {
100
+ const summary = Object.entries(branchCounts).map(([k, v]) => `${k}=${v}`).join(" ")
101
+ const line = `[${new Date().toISOString()}] FINAL_COUNTS ${summary}\n`
102
+ appendLog(logFile, line)
103
+ process.stdout.write(line)
104
+ }
105
+
106
+ server.listen(requestedPort, "127.0.0.1", () => {
107
+ const addr = server.address()
108
+ const port = typeof addr === "object" && addr !== null ? addr.port : requestedPort
109
+ try {
110
+ fs.mkdirSync(path.dirname(logFile), { recursive: true })
111
+ appendLog(logFile, `[${new Date().toISOString()}] START port=${port}\n`)
112
+ } catch {}
113
+ process.stdout.write(`fake-openai listening on ${port}\n`)
114
+ })
115
+
116
+ process.on("SIGTERM", () => { logFinalCounts(); server.close(() => process.exit(0)) })
117
+ process.on("SIGINT", () => { logFinalCounts(); server.close(() => process.exit(0)) })