@mininglamp-oss/octo-runtime 1.1.12 → 1.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (195) hide show
  1. package/README.md +1 -1
  2. package/apps/cli/dist/adapters.d.ts +19 -1
  3. package/apps/cli/dist/adapters.js +154 -28
  4. package/apps/cli/dist/build-info.json +2 -2
  5. package/apps/cli/dist/codex.d.ts +5 -0
  6. package/apps/cli/dist/codex.js +36 -0
  7. package/apps/cli/dist/kernel.d.ts +4 -0
  8. package/apps/cli/dist/kernel.js +84 -0
  9. package/apps/cli/dist/main.js +8 -7
  10. package/apps/cli/dist/manifest.json +33 -22
  11. package/apps/cli/dist/output.d.ts +1 -0
  12. package/apps/cli/dist/output.js +8 -4
  13. package/apps/cli/dist/playboard.js +21 -12
  14. package/apps/cli/dist/provider-launch.d.ts +28 -0
  15. package/apps/cli/dist/provider-launch.js +52 -0
  16. package/apps/cli/dist/providers.d.ts +182 -0
  17. package/apps/cli/dist/providers.js +34 -0
  18. package/dist/public/adapter-sdk.d.ts +2 -0
  19. package/dist/public/adapter-sdk.js +2 -0
  20. package/dist/public/protocol.d.ts +2 -2
  21. package/dist/public/protocol.js +1 -1
  22. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +4 -4
  23. package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
  24. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +26 -10
  25. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +44 -53
  26. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
  27. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/dist/index.d.ts +10 -35
  28. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/dist/index.js +21 -29
  29. package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
  30. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/agent-env.d.ts +3 -0
  31. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/agent-env.js +10 -0
  32. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.d.ts +14 -68
  33. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.js +77 -61
  34. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  35. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.d.ts +19 -31
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.js +28 -18
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/agent-env.d.ts +3 -0
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/agent-env.js +10 -0
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.d.ts +6 -5
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +55 -54
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/engine.d.ts +54 -0
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/engine.js +147 -0
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/environment.js +4 -8
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +20 -92
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +103 -217
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/mcp.d.ts +2 -2
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/mcp.js +4 -11
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.d.ts +9 -5
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.js +77 -81
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-SMTJTIN7.js → chunk-AE3OJBDS.js} +1 -1
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-H3S6WM37.js → chunk-NGR74QLF.js} +0 -1
  54. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/{chunk-RISQ6NGV.js → chunk-XIUZ6GXG.js} +1 -1
  55. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +0 -1
  56. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +1 -1
  57. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +6 -8
  58. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +16 -21
  59. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +2 -2
  60. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +2 -2
  61. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  62. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.d.ts +14 -16
  63. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.js +29 -46
  64. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/agent-env.d.ts +3 -0
  65. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/agent-env.js +10 -0
  66. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +4 -7
  67. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.d.ts +13 -21
  68. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.js +47 -36
  69. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  70. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.d.ts +24 -8
  71. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.js +14 -7
  72. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  73. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.d.ts +24 -8
  74. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.js +13 -6
  75. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  76. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.d.ts +24 -8
  77. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.js +14 -7
  78. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  79. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.d.ts +7 -7
  80. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +28 -31
  81. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  82. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +16 -25
  83. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +113 -179
  84. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  85. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.d.ts +24 -8
  86. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.js +14 -6
  87. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +3 -2
  88. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.d.ts +24 -8
  89. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.js +14 -6
  90. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +3 -2
  91. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +5 -1
  92. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/agent-env.d.ts +48 -0
  93. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/agent-env.js +234 -0
  94. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/approval.js +7 -2
  95. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +1 -1
  96. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.d.ts +5 -1
  97. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +25 -14
  98. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +112 -59
  99. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +1 -1
  100. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/process-launch.d.ts +11 -1
  101. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/process-launch.js +89 -8
  102. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/provider-launch.d.ts +10 -0
  103. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/provider-launch.js +25 -0
  104. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +10 -3
  105. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  106. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.d.ts +19 -1
  107. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.js +154 -28
  108. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  109. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/codex.d.ts +5 -0
  110. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/codex.js +36 -0
  111. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/kernel.d.ts +4 -0
  112. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/kernel.js +84 -0
  113. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +8 -7
  114. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +33 -22
  115. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.d.ts +1 -0
  116. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +8 -4
  117. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +21 -12
  118. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/provider-launch.d.ts +28 -0
  119. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/provider-launch.js +52 -0
  120. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/providers.d.ts +182 -0
  121. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/providers.js +34 -0
  122. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +20 -20
  123. package/node_modules/@mininglamp-oss/octo-runtime-client/build-info.json +2 -2
  124. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.js +2 -2
  125. package/node_modules/@mininglamp-oss/octo-runtime-client/package.json +5 -5
  126. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc.schema.json +3 -104
  127. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/protocol.schema.json +166 -1870
  128. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  129. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +0 -2
  130. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +122 -65
  131. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.d.ts +2 -2
  132. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.js +13 -85
  133. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-output-silence.d.ts +21 -0
  134. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/model-output-silence.js +176 -0
  135. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.d.ts +3 -2
  136. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.js +8 -4
  137. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  138. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +1 -1
  139. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +1 -1
  140. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.d.ts +5 -0
  141. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +17 -20
  142. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +5 -5
  143. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
  144. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/adapter-metadata.d.ts +1 -1
  145. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.d.ts +0 -2
  146. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.js +0 -2
  147. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-catalog.d.ts +0 -1
  148. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-catalog.js +3 -9
  149. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-configuration.js +1 -8
  150. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.d.ts +1 -5
  151. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +3 -292
  152. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/experience.js +7 -0
  153. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +2 -0
  154. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +18 -13
  155. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +90 -608
  156. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.js +32 -1
  157. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +7 -18
  158. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +34 -189
  159. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.d.ts +11 -22
  160. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +38 -78
  161. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/multimodal.js +6 -0
  162. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.d.ts +2 -1
  163. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.js +5 -40
  164. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.js +2 -1
  165. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  166. package/package.json +34 -37
  167. package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +3 -104
  168. package/packages/octo-runtime-protocol/schema/protocol.schema.json +166 -1870
  169. package/dist/public/codex.d.ts +0 -1
  170. package/dist/public/codex.js +0 -1
  171. package/dist/public/dsh.d.ts +0 -2
  172. package/dist/public/dsh.js +0 -1
  173. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/actmode.d.ts +0 -5
  174. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/actmode.js +0 -8
  175. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-configuration-fixtures.json +0 -1219
  176. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-fixtures.json +0 -5988
  177. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-client.behavior.json +0 -56
  178. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/native-invoke-fixtures.json +0 -116
  179. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/run-protocol-fixtures.json +0 -761
  180. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/runtime-selection-fixtures.json +0 -663
  181. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/session-name-fixtures.json +0 -191
  182. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/context.d.ts +0 -12
  183. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/context.js +0 -89
  184. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/execution-preparation.d.ts +0 -33
  185. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/execution-preparation.js +0 -93
  186. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/actmode.d.ts +0 -4
  187. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/actmode.js +0 -36
  188. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/execution-plan.d.ts +0 -3
  189. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/execution-plan.js +0 -80
  190. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/model-context.d.ts +0 -3
  191. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/model-context.js +0 -9
  192. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/runtime-selection.d.ts +0 -3
  193. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/runtime-selection.js +0 -68
  194. /package/node_modules/@mininglamp-oss/octo-runtime-client/{schema → fixtures}/kernel-ipc-fixtures.json +0 -0
  195. /package/packages/octo-runtime-protocol/{schema → test/fixtures}/kernel-ipc-fixtures.json +0 -0
@@ -1,107 +1,52 @@
1
- import { invocationEnvironment, invocationMcpServers, mergeProcessEnvironment, processEnvironmentValue } from "@mininglamp-oss/octo-runtime-adapter-sdk";
2
- import { codexMcpConfig } from "./mcp.js";
3
- /**
4
- * Assembly entry point for the Codex adapter.
5
- *
6
- * 描述对象注册时创建独立 scope;按兼容配置选择常驻服务,再绑定本轮 channel。
7
- * scope 负责最终关闭,逐轮 developer instructions 仍放在原生 thread 参数中。
8
- */
9
- import { defineAdapter, probeCommand } from "@mininglamp-oss/octo-runtime-adapter-sdk";
10
- import { hasImageInput, resolveStreamLimitPolicy } from "@mininglamp-oss/octo-runtime-protocol";
11
- import { homedir } from "node:os";
12
- import { join } from "node:path";
13
- import { buildCodexAppServerArgs, runCodexAppServerTurn } from "./app-server.js";
14
- import { CodexService } from "./service.js";
15
- import { createHmac, randomBytes, randomUUID } from "node:crypto";
16
- import { realpathSync, statSync } from "node:fs";
17
- import { delimiter, isAbsolute, resolve } from "node:path";
1
+ export const codexMetadata = {
2
+ type: "codex",
3
+ mcp: true,
4
+ processModel: "host-owned-engine",
5
+ transport: "codex-channel",
6
+ protocolSupport: {
7
+ protocol: "codex.app-server",
8
+ modes: ["native", "canonical"],
9
+ nativeMethods: [
10
+ "thread/start",
11
+ "thread/resume",
12
+ "turn/start",
13
+ "turn/interrupt",
14
+ "item/commandExecution/requestApproval",
15
+ "execCommandApproval",
16
+ "item/fileChange/requestApproval",
17
+ "applyPatchApproval",
18
+ "item/tool/requestUserInput",
19
+ "mcpServer/elicitation/request"
20
+ ]
21
+ }
22
+ };
23
+ import { defineAdapter } from "@mininglamp-oss/octo-runtime-adapter-sdk";
24
+ import { runCodexAppServerTurn } from "./app-server.js";
25
+ import { assertCodexHome, assertCodexInvocationHome } from "./engine.js";
26
+ export * from "./engine.js";
18
27
  export { buildCodexAppServerArgs, CodexEventNormalizer, CodexAppServerProcessError, CodexAppServerRpcError, normalizeCodexEvent, runCodexAppServerTurn } from "./app-server.js";
19
28
  /**
20
- * Convert an Octo Runtime InvokeRequest into a launchable app-server process spec.
21
- *
22
- * The user prompt never appears in argv; it is written to stdin later via
23
- * turn/start. The parent process environment is inherited whole and only
24
- * The complete real CODEX_HOME is reused. Per-run instructions are sent through
25
- * thread/start or thread/resume `developerInstructions`, never written to the
26
- * user's config.toml.
29
+ * 宿主先构造 Codex 访问依赖,再注册 Adapter;注册只创建本地调用 scope。
30
+ * scope 释放自身 lease 和路由,永不关闭 Engine;宿主最终关闭其 owner。
31
+ * 这是 Codex 专用签名,不限制其他 Adapter 的类、工厂、闭包及任意依赖参数。
27
32
  */
28
- export function buildCodexCommand(req, command = "codex", appServerArgs = buildCodexAppServerArgs(), env = process.env) {
29
- const runEnv = invocationEnvironment(req, {}, env);
30
- const mcp = codexMcpConfig(req, runEnv);
31
- const realHome = processEnvironmentValue(runEnv, "CODEX_HOME") || join(homedir(), ".codex");
32
- return {
33
- command,
34
- args: [...appServerArgs, ...nativeCapacityOverrides(req)],
35
- cwd: req.workdir,
36
- env: mergeProcessEnvironment(runEnv, mcp.env, { CODEX_HOME: realHome }),
37
- ...(Object.keys(mcp.servers).length ? { mcpServers: mcp.servers } : {}),
38
- cleanup: () => undefined
39
- };
40
- }
41
- /** 宿主已核实的窗口同步给 Codex;历史由原生自动压缩处理,绝不重发已接受的 turn。 */
42
- function nativeCapacityOverrides(request) {
43
- const value = request.runMetadata?.contextCapacity;
44
- if (!value)
45
- return [];
46
- const window = value.contextWindow;
47
- const reserve = value.outputReserveTokens;
48
- if (value.management !== "provider_native" ||
49
- typeof window !== "number" ||
50
- !Number.isSafeInteger(window) ||
51
- window < 1024 ||
52
- typeof reserve !== "number" ||
53
- !Number.isSafeInteger(reserve) ||
54
- reserve < 0 ||
55
- reserve >= window)
56
- throw new TypeError("CONTEXT_CAPACITY_UNAVAILABLE");
57
- return [
58
- "-c",
59
- `model_context_window=${window}`,
60
- "-c",
61
- `model_auto_compact_token_limit=${window - reserve}`
62
- ];
63
- }
64
- export function createCodexAdapter({ command = "codex", appServerArgs = buildCodexAppServerArgs(), spawnFn, env = process.env } = {}) {
33
+ export function createCodexAdapter({ engine }) {
34
+ if (!engine || typeof engine.acquire !== "function")
35
+ throw new TypeError("CODEX_ENGINE_REQUIRED");
36
+ assertCodexHome(engine.codexHome);
65
37
  return defineAdapter({
66
- metadata: {
67
- mcp: true,
68
- protocolSupport: {
69
- protocol: "codex.app-server",
70
- modes: ["native", "canonical"],
71
- nativeMethods: [
72
- "thread/start",
73
- "thread/resume",
74
- "turn/start",
75
- "turn/interrupt",
76
- "item/commandExecution/requestApproval",
77
- "execCommandApproval",
78
- "item/fileChange/requestApproval",
79
- "applyPatchApproval",
80
- "item/tool/requestUserInput",
81
- "mcpServer/elicitation/request"
82
- ]
83
- },
84
- type: "codex",
85
- agentSources: ["provisioned"],
86
- processModel: "service-owned-subprocess",
87
- transport: "json-rpc-2.0/stdio"
88
- },
89
- probe: () => probeCommand(command),
90
- createExecutionScope: ({ log }) => {
91
- const scopeId = randomUUID();
92
- const salt = randomBytes(32);
93
- const services = new Map();
38
+ metadata: codexMetadata,
39
+ ...(engine.probe ? { probe: () => engine.probe() } : {}),
40
+ createExecutionScope: () => {
41
+ const active = new Set();
42
+ const failed = new Set();
43
+ const settled = new Map();
94
44
  const interactionResponders = new Map();
95
45
  const nativeResponders = new Map();
96
- const active = new Set();
97
46
  let closing = false;
98
- let close;
99
- const unresolved = new Set();
100
- const failed = new Set();
101
47
  const scope = {
102
48
  metadata: {
103
49
  type: "codex",
104
- agentSources: ["provisioned"],
105
50
  mcp: true,
106
51
  protocolSupport: {
107
52
  protocol: "codex.app-server",
@@ -111,44 +56,27 @@ export function createCodexAdapter({ command = "codex", appServerArgs = buildCod
111
56
  },
112
57
  async *invoke(request, context) {
113
58
  if (closing)
114
- throw new Error("CODEX_SERVICE_CLOSED");
59
+ throw new Error("CODEX_ADAPTER_CLOSED");
115
60
  if (active.has(request.invocationId))
116
61
  throw new Error("CODEX_INVOCATION_BUSY");
62
+ assertCodexInvocationHome(request, engine.codexHome);
117
63
  active.add(request.invocationId);
64
+ let finish;
65
+ settled.set(request.invocationId, new Promise((done) => {
66
+ finish = done;
67
+ }));
118
68
  try {
119
- const runEnv = invocationEnvironment(request, {}, env);
120
- const rawMessageMaxBytes = resolveStreamLimitPolicy(context?.streamLimits).rawMessageMaxBytes;
121
- // 比较解析后的语义,而非每轮随机 MCP header 环境名;私有键从不进入诊断。
122
- const semantic = stableJson({
123
- command: executableIdentity(command, runEnv, request.workdir),
124
- args: [...appServerArgs, ...nativeCapacityOverrides(request)],
125
- cwd: request.workdir,
126
- env: runEnv,
127
- home: processEnvironmentValue(runEnv, "CODEX_HOME") || join(homedir(), ".codex"),
128
- mcp: invocationMcpServers(request, runEnv),
129
- revision: request.agentConfig.providerOptions?.codexServiceRevision ?? "",
130
- rawMessageMaxBytes
131
- });
132
- const key = createHmac("sha256", salt).update(semantic).digest("hex");
133
- let entry = services.get(key);
134
- if (entry && entry.semantic !== semantic)
135
- throw new Error("CODEX_SERVICE_KEY_COLLISION");
136
- if (!entry) {
137
- if (services.size >= 8)
138
- throw new Error("CODEX_SERVICE_CONFIGURATIONS_EXCEEDED");
139
- entry = {
140
- semantic,
141
- service: new CodexService(scopeId, buildCodexCommand(request, command, appServerArgs, env), spawnFn, rawMessageMaxBytes)
142
- };
143
- services.set(key, entry);
144
- }
145
- const channel = await entry.service.acquire(request.signal, Buffer.byteLength(JSON.stringify(request)), context?.protocolMode !== "native" && hasImageInput(request));
69
+ const lease = await engine.acquire(request, context);
146
70
  try {
71
+ // acquire 可晚于 scope 关闭返回;仍须 release,不能接纳迟到调用。
72
+ if (closing)
73
+ throw new Error("CODEX_ADAPTER_CLOSED");
74
+ request.signal?.throwIfAborted();
147
75
  yield* runCodexAppServerTurn({
148
76
  request,
149
- spec: entry.service.spec,
150
- channel,
151
77
  context,
78
+ channel: lease.channel,
79
+ spec: lease.configuration,
152
80
  onInteractionResponder: (responder) => {
153
81
  if (responder)
154
82
  interactionResponders.set(request.invocationId, responder);
@@ -164,124 +92,82 @@ export function createCodexAdapter({ command = "codex", appServerArgs = buildCod
164
92
  });
165
93
  }
166
94
  finally {
167
- await channel.close();
95
+ await release();
96
+ }
97
+ // 保留 release 失败作为独立 scope 清理事实;原执行终态不因此变为成功。
98
+ async function release() {
99
+ try {
100
+ await lease.channel.close();
101
+ }
102
+ catch (error) {
103
+ failed.add(request.invocationId);
104
+ throw error;
105
+ }
168
106
  }
169
107
  }
170
108
  finally {
171
109
  active.delete(request.invocationId);
110
+ settled.delete(request.invocationId);
111
+ finish();
172
112
  interactionResponders.delete(request.invocationId);
173
113
  nativeResponders.delete(request.invocationId);
174
114
  }
175
115
  },
176
- async respondNative(invocationId, response) {
177
- const responder = nativeResponders.get(invocationId);
116
+ async respondInteraction(id, response) {
117
+ const responder = interactionResponders.get(id);
178
118
  if (!responder)
179
119
  throw new Error("INTERACTION_NOT_ACTIVE");
180
120
  await responder(response);
181
121
  },
182
- async respondInteraction(invocationId, response) {
183
- const responder = interactionResponders.get(invocationId);
122
+ async respondNative(id, response) {
123
+ const responder = nativeResponders.get(id);
184
124
  if (!responder)
185
125
  throw new Error("INTERACTION_NOT_ACTIVE");
186
126
  await responder(response);
187
127
  },
188
- processes: () => [...services.values()].map(({ service }) => service.snapshot()),
189
128
  beginShutdown() {
190
129
  closing = true;
191
- for (const { service } of services.values())
192
- service.beginShutdown();
193
130
  },
194
- close({ deadline }) {
195
- scope.beginShutdown();
196
- if (!close) {
197
- for (const { service } of services.values())
198
- unresolved.add(service.id);
199
- close = Promise.all([...services.values()].map(async ({ service }) => {
200
- try {
201
- await service.close();
202
- unresolved.delete(service.id);
203
- }
204
- catch {
205
- failed.add(service.id);
206
- log("warn", "codex.service.cleanup_incomplete", { service_id: service.id });
207
- }
208
- })).then(() => { });
131
+ async close({ deadline }) {
132
+ if (!Number.isFinite(deadline))
133
+ throw new TypeError("CLEANUP_DEADLINE_INVALID");
134
+ closing = true;
135
+ // Core 取消和排空自身调用;不得借此关闭宿主共享 Engine。
136
+ let timer;
137
+ try {
138
+ await Promise.race([
139
+ Promise.all([...settled.values()]),
140
+ new Promise((done) => {
141
+ timer = setTimeout(done, Math.max(0, deadline - performance.now()));
142
+ })
143
+ ]);
209
144
  }
210
- return (async () => {
211
- let timer;
212
- try {
213
- await Promise.race([
214
- close,
215
- new Promise((resolve) => {
216
- timer = setTimeout(resolve, Math.max(0, deadline - performance.now()));
217
- })
218
- ]);
219
- }
220
- finally {
221
- clearTimeout(timer);
222
- }
223
- return {
224
- complete: unresolved.size === 0,
225
- unresolvedServiceIds: [...unresolved],
226
- failedCleanupServiceIds: [...failed]
227
- };
228
- })();
145
+ finally {
146
+ clearTimeout(timer);
147
+ }
148
+ return {
149
+ complete: active.size === 0 && failed.size === 0,
150
+ unresolvedServiceIds: [...new Set([...active, ...failed])],
151
+ failedCleanupServiceIds: [...failed]
152
+ };
229
153
  }
230
154
  };
231
- const defined = defineAdapter(scope);
232
- return { ...scope, invoke: defined.invoke };
155
+ return { ...scope, invoke: defineAdapter(scope).invoke };
233
156
  },
234
- respondNative(invocationId, response) {
235
- void invocationId;
236
- void response;
237
- return Promise.reject(new Error("CODEX_SERVICE_SCOPE_REQUIRED"));
157
+ respondNative(_id, _response) {
158
+ void _id;
159
+ void _response;
160
+ return Promise.reject(new Error("CODEX_ADAPTER_SCOPE_REQUIRED"));
238
161
  },
239
- respondInteraction(invocationId, response) {
240
- void invocationId;
241
- void response;
242
- return Promise.reject(new Error("CODEX_SERVICE_SCOPE_REQUIRED"));
162
+ respondInteraction(_id, _response) {
163
+ void _id;
164
+ void _response;
165
+ return Promise.reject(new Error("CODEX_ADAPTER_SCOPE_REQUIRED"));
243
166
  },
244
- invoke(request, context) {
245
- void request;
246
- void context;
247
- throw new Error("CODEX_SERVICE_SCOPE_REQUIRED");
167
+ invoke(_request, _context) {
168
+ void _request;
169
+ void _context;
170
+ throw new Error("CODEX_ADAPTER_SCOPE_REQUIRED");
248
171
  }
249
172
  });
250
173
  }
251
- function stableJson(value) {
252
- if (Array.isArray(value))
253
- return `[${value.map(stableJson).join(",")}]`;
254
- if (value && typeof value === "object")
255
- return `{${Object.entries(value)
256
- .filter(([, entry]) => entry !== undefined)
257
- .sort(([a], [b]) => a.localeCompare(b))
258
- .map(([key, entry]) => `${JSON.stringify(key)}:${stableJson(entry)}`)
259
- .join(",")}}`;
260
- return JSON.stringify(value);
261
- }
262
- /** 每轮校验入口文件身份;安装文件变化会换服务,不额外启动版本探针。 */
263
- function executableIdentity(command, env, cwd) {
264
- const extensions = process.platform === "win32" && !/\.[a-z]+$/i.test(command)
265
- ? (processEnvironmentValue(env, "PATHEXT") ?? ".EXE;.CMD;.BAT").split(";")
266
- : [""];
267
- // 带路径的命令只相对 cwd 解析一次;裸命令仍按 PATH 搜索。
268
- const directories = isAbsolute(command) || /[/\\]/.test(command)
269
- ? [""]
270
- : (processEnvironmentValue(env, "PATH") ?? "").split(delimiter);
271
- for (const directory of directories)
272
- for (const extension of extensions) {
273
- try {
274
- const path = realpathSync(resolve(cwd, directory, command + extension));
275
- const info = statSync(path);
276
- if (info.isFile())
277
- return { path, dev: info.dev, ino: info.ino, size: info.size, mtime: info.mtimeMs };
278
- }
279
- catch (error) {
280
- if (!["ENOENT", "ENOTDIR"].includes(error.code ?? ""))
281
- throw error;
282
- }
283
- }
284
- return { command };
285
- }
286
- export const codexAdapter = createCodexAdapter();
287
- export default codexAdapter;
@@ -1,8 +1,8 @@
1
1
  import { type InvokeRequest } from "@mininglamp-oss/octo-runtime-adapter-sdk";
2
- /** Header secrets travel in the subprocess environment, never argv or persisted config. */
2
+ /** 本轮 MCP 经私有 thread RPC 传递;不依赖共享进程环境,不写 argv 或配置文件。 */
3
3
  export declare function codexMcpConfig(request: InvokeRequest, env: NodeJS.ProcessEnv): {
4
4
  servers: {
5
5
  [k: string]: Record<string, unknown>;
6
6
  };
7
- env: NodeJS.ProcessEnv;
7
+ env: {};
8
8
  };
@@ -1,11 +1,8 @@
1
- import { randomUUID } from "node:crypto";
2
1
  import { invocationMcpServers } from "@mininglamp-oss/octo-runtime-adapter-sdk";
3
- /** Header secrets travel in the subprocess environment, never argv or persisted config. */
2
+ /** 本轮 MCP 经私有 thread RPC 传递;不依赖共享进程环境,不写 argv 或配置文件。 */
4
3
  export function codexMcpConfig(request, env) {
5
- const prefix = `OCTO_MCP_${randomUUID().replaceAll("-", "")}`;
6
4
  const servers = invocationMcpServers(request, env);
7
- const secrets = {};
8
- const native = Object.fromEntries(Object.entries(servers).map(([name, server], index) => {
5
+ const native = Object.fromEntries(Object.entries(servers).map(([name, server]) => {
9
6
  const entry = {};
10
7
  if (server.type === "stdio") {
11
8
  entry.command = server.command;
@@ -18,11 +15,7 @@ export function codexMcpConfig(request, env) {
18
15
  }
19
16
  else {
20
17
  entry.url = server.url;
21
- entry.env_http_headers = Object.fromEntries(Object.entries(server.headers ?? {}).map(([key, value], header) => {
22
- const variable = `${prefix}_${index}_${header}`;
23
- secrets[variable] = value;
24
- return [key, variable];
25
- }));
18
+ entry.http_headers = server.headers ?? {};
26
19
  }
27
20
  if (server.required !== undefined)
28
21
  entry.required = server.required;
@@ -32,5 +25,5 @@ export function codexMcpConfig(request, env) {
32
25
  entry.tool_timeout_sec = server.toolTimeoutMs / 1000;
33
26
  return [name, entry];
34
27
  }));
35
- return { servers: native, env: secrets };
28
+ return { servers: native, env: {} };
36
29
  }
@@ -11,6 +11,7 @@ export declare class CodexTurnChannel {
11
11
  readonly service: CodexService;
12
12
  readonly incarnation: number;
13
13
  readonly allowInputEcho: boolean;
14
+ readonly rawMessageMaxBytes: number;
14
15
  onMessage: (message: Message) => void;
15
16
  onFailure: (error: Error) => void;
16
17
  threadId?: string;
@@ -19,9 +20,10 @@ export declare class CodexTurnChannel {
19
20
  closed: boolean;
20
21
  startingTurn: boolean;
21
22
  startingThread: boolean;
23
+ freshThread: boolean;
22
24
  readonly buffered: Message[];
23
25
  bufferedBytes: number;
24
- constructor(service: CodexService, incarnation: number, allowInputEcho?: boolean);
26
+ constructor(service: CodexService, incarnation: number, allowInputEcho?: boolean, rawMessageMaxBytes?: number);
25
27
  reserveRequestId(): Id;
26
28
  write(message: Message, onError: (error: Error) => void, onWritten?: () => void, options?: {
27
29
  control?: boolean;
@@ -31,7 +33,7 @@ export declare class CodexTurnChannel {
31
33
  close(): Promise<void>;
32
34
  errorMessage(error: unknown): string;
33
35
  }
34
- /** Core 作用域内的一种兼容配置;惰性首次启动,之后空闲退出也主动恢复,业务动作从不重放。 */
36
+ /** owner 的唯一进程与关联器;多调用共享 stdio,故障替代不重放业务动作。 */
35
37
  export declare class CodexService {
36
38
  #private;
37
39
  readonly scopeId: string;
@@ -40,8 +42,8 @@ export declare class CodexService {
40
42
  readonly rawMessageMaxBytes: number;
41
43
  readonly id: `${string}-${string}-${string}-${string}-${string}`;
42
44
  constructor(scopeId: string, spec: CodexAppServerCommand, spawnFn?: CodexAppServerSpawn, rawMessageMaxBytes?: number);
43
- /** 取消等待不取消共享启动;等待者数和活动 thread 数分别有界。 */
44
- acquire(signal?: AbortSignal, retainedBytes?: number, allowInputEcho?: boolean): Promise<CodexTurnChannel>;
45
+ /** 所有调用等待同一次启动;取消等待仅影响本调用,不取消共享启动。 */
46
+ acquire(signal?: AbortSignal, allowInputEcho?: boolean, rawMessageMaxBytes?: number): Promise<CodexTurnChannel>;
45
47
  snapshot(): ServiceProcessSnapshot;
46
48
  stderr(generation: number): string;
47
49
  reserveRequestId(): Id;
@@ -50,8 +52,10 @@ export declare class CodexService {
50
52
  timeoutMs?: number;
51
53
  }): () => void;
52
54
  cancelPending(channel: CodexTurnChannel, error: Error): void;
53
- /** 未确认中断/退订时保留 thread 和容量,阻止迟到通知进入后续调用。 */
55
+ /** 未确认中断/退订时保留 thread 归属,阻止迟到通知进入后续调用。 */
54
56
  release(channel: CodexTurnChannel): Promise<void>;
57
+ /** 宿主停止新获取/恢复,但已有健康 channel 仍可定向取消与收尾。 */
58
+ stopRecovery(): void;
55
59
  beginShutdown(): void;
56
60
  close(): Promise<void>;
57
61
  }