@mininglamp-oss/octo-runtime 1.1.12 → 1.1.13

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 (172) 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 +153 -23
  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 +1 -1
  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 +15 -14
  25. package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +24 -28
  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 +22 -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/index.d.ts +14 -68
  31. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/dist/index.js +60 -43
  32. package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
  33. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.d.ts +19 -31
  34. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/dist/index.js +29 -18
  35. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
  36. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.d.ts +6 -5
  37. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/app-server.js +32 -26
  38. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/engine.d.ts +54 -0
  39. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/engine.js +147 -0
  40. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/environment.js +4 -8
  41. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.d.ts +20 -92
  42. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +104 -216
  43. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/mcp.d.ts +2 -2
  44. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/mcp.js +4 -11
  45. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.d.ts +9 -5
  46. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/service.js +77 -81
  47. package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
  48. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +4 -2
  49. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +12 -14
  50. package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +3 -3
  51. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.d.ts +14 -14
  52. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/adapter.js +23 -30
  53. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +4 -7
  54. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.d.ts +13 -21
  55. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/index.js +48 -26
  56. package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
  57. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.d.ts +16 -14
  58. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/dist/index.js +15 -7
  59. package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
  60. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.d.ts +16 -14
  61. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/dist/index.js +14 -6
  62. package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
  63. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.d.ts +16 -14
  64. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/dist/index.js +15 -7
  65. package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
  66. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.d.ts +7 -3
  67. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/dist/index.js +27 -29
  68. package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
  69. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +16 -25
  70. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +109 -178
  71. package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
  72. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.d.ts +16 -14
  73. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/dist/index.js +15 -6
  74. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +3 -2
  75. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.d.ts +16 -14
  76. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/dist/index.js +15 -6
  77. package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +3 -2
  78. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +5 -1
  79. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/agent-env.d.ts +49 -0
  80. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/agent-env.js +256 -0
  81. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/approval.js +7 -2
  82. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +1 -1
  83. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/execution-scope.d.ts +5 -1
  84. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +25 -12
  85. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +116 -58
  86. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +1 -1
  87. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/process-launch.d.ts +11 -1
  88. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/process-launch.js +89 -8
  89. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/provider-launch.d.ts +10 -0
  90. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/provider-launch.js +25 -0
  91. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +10 -3
  92. package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
  93. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.d.ts +19 -1
  94. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/adapters.js +153 -23
  95. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
  96. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/codex.d.ts +5 -0
  97. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/codex.js +36 -0
  98. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/kernel.d.ts +4 -0
  99. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/kernel.js +84 -0
  100. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +8 -7
  101. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +33 -22
  102. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.d.ts +1 -0
  103. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +8 -4
  104. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +21 -12
  105. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/provider-launch.d.ts +28 -0
  106. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/provider-launch.js +52 -0
  107. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/providers.d.ts +182 -0
  108. package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/providers.js +34 -0
  109. package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +20 -20
  110. package/node_modules/@mininglamp-oss/octo-runtime-client/build-info.json +2 -2
  111. package/node_modules/@mininglamp-oss/octo-runtime-client/dist/client.js +2 -2
  112. package/node_modules/@mininglamp-oss/octo-runtime-client/package.json +5 -5
  113. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-ipc.schema.json +3 -104
  114. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/protocol.schema.json +173 -1295
  115. package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
  116. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.d.ts +0 -2
  117. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +26 -54
  118. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.d.ts +2 -2
  119. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/invoke-input.js +13 -85
  120. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.d.ts +3 -1
  121. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/watchdog.js +5 -0
  122. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
  123. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +1 -1
  124. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +1 -1
  125. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.d.ts +5 -0
  126. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/server.js +17 -20
  127. package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +5 -5
  128. package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
  129. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.d.ts +0 -2
  130. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/browser.js +0 -2
  131. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-catalog.d.ts +0 -1
  132. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-catalog.js +3 -5
  133. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context-configuration.js +1 -8
  134. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.d.ts +1 -2
  135. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/context.js +3 -267
  136. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +2 -0
  137. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +17 -3
  138. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +102 -396
  139. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.js +32 -1
  140. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.d.ts +6 -15
  141. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/index.js +33 -178
  142. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.d.ts +11 -22
  143. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/invoke-input.js +38 -78
  144. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/multimodal.js +6 -0
  145. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.d.ts +2 -1
  146. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/run-protocol.js +5 -28
  147. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/service-processes.js +2 -1
  148. package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
  149. package/package.json +34 -37
  150. package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +3 -104
  151. package/packages/octo-runtime-protocol/schema/protocol.schema.json +173 -1295
  152. package/dist/public/codex.d.ts +0 -1
  153. package/dist/public/codex.js +0 -1
  154. package/dist/public/dsh.d.ts +0 -2
  155. package/dist/public/dsh.js +0 -1
  156. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-configuration-fixtures.json +0 -1219
  157. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/context-fixtures.json +0 -5988
  158. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/kernel-client.behavior.json +0 -56
  159. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/native-invoke-fixtures.json +0 -116
  160. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/run-protocol-fixtures.json +0 -761
  161. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/runtime-selection-fixtures.json +0 -663
  162. package/node_modules/@mininglamp-oss/octo-runtime-client/schema/session-name-fixtures.json +0 -191
  163. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/context.d.ts +0 -12
  164. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/context.js +0 -89
  165. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/execution-preparation.d.ts +0 -33
  166. package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/execution-preparation.js +0 -93
  167. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/execution-plan.d.ts +0 -3
  168. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/execution-plan.js +0 -80
  169. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/model-context.d.ts +0 -3
  170. package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/model-context.js +0 -9
  171. /package/node_modules/@mininglamp-oss/octo-runtime-client/{schema → fixtures}/kernel-ipc-fixtures.json +0 -0
  172. /package/packages/octo-runtime-protocol/{schema → test/fixtures}/kernel-ipc-fixtures.json +0 -0
@@ -1,19 +1,23 @@
1
+ import { invocationEffort, invocationWorkdir } from "./agent-env.js";
1
2
  import { execFile, spawn } from "node:child_process";
2
3
  import { constants } from "node:fs";
3
4
  import { access, stat } from "node:fs/promises";
4
- import { delimiter, isAbsolute, resolve } from "node:path";
5
+ import { resolve } from "node:path";
5
6
  import { createInterface } from "node:readline";
6
7
  import { promisify } from "node:util";
7
- import { invocationEnvironment, mergeProcessEnvironment, processEnvironmentValue } from "./environment.js";
8
+ import { invocationEnvironment, mergeProcessEnvironment } from "./environment.js";
8
9
  import { createProcessCleanup } from "./process-cleanup.js";
9
- import { resolveProcessLaunch } from "./process-launch.js";
10
+ import { defaultAgentEnv, assertAdapterAgentEnv, assertAdapterWorkdir, bindInvocationConnection, invocationApprovalMode, invocationAgentSource, invocationRuntimeLimits } from "./agent-env.js";
11
+ export * from "./agent-env.js";
12
+ import { assertProviderCommand } from "./provider-launch.js";
13
+ export { snapshotProviderLaunch, assertProviderCommand } from "./provider-launch.js";
10
14
  import { watchLineLimit } from "./line-limit.js";
11
15
  import { mapReasoningEffort, reasoningLevelMap } from "./reasoning.js";
12
16
  export { invocationEnvironment, invocationEnvs, mergeProcessEnvironment, processEnvironmentValue } from "./environment.js";
13
17
  export { invocationMcpServers, expandMcpValue, assertMcpOptions } from "./mcp.js";
14
18
  export { actmodeEvidence } from "./actmode.js";
15
19
  import { DEFAULT_STREAM_LIMIT_POLICY, isTerminal, assertProtocolSupport } from "@mininglamp-oss/octo-runtime-protocol";
16
- export { freshFallbackInputText, initialControlInstructions, hasImageInput, providerInputParts, providerInputText } from "@mininglamp-oss/octo-runtime-protocol";
20
+ export { freshFallbackInputText, hasImageInput, providerInputParts, providerInputText } from "@mininglamp-oss/octo-runtime-protocol";
17
21
  export { acpToolTerminalStatus, normalizeAcpToolUpdate } from "./acp-tool.js";
18
22
  export { AcpTurnNormalizer } from "./acp-turn.js";
19
23
  export { AcpApprovalBridge } from "./approval.js";
@@ -25,6 +29,34 @@ export { RuntimeLogging, assertRuntimeLogging, noopRuntimeLog } from "./runtime-
25
29
  export { kernelStatusRecord } from "./service-status.js";
26
30
  export { sanitizePublicValue, sanitizeDiagnosticBody } from "./public-display.js";
27
31
  export { DEFAULT_REASONING_LEVEL_MAPS, OMNI_REASONING_LEVELS, mapReasoningEffort, reasoningLevelMap } from "./reasoning.js";
32
+ const preparationFailures = new WeakMap();
33
+ /**
34
+ * 执行尚未启动 Provider 的纯配置/目录校验;返回后才能开始探针或执行。
35
+ * 回调不得创建 Provider 资源。失败证据只绑定本次 context,供 Core 核对清理责任。
36
+ */
37
+ export async function runAdapterPreparation(context, prepare) {
38
+ try {
39
+ await prepare();
40
+ }
41
+ catch (error) {
42
+ if (context && error !== null && typeof error === "object") {
43
+ const contexts = preparationFailures.get(error) ?? new WeakSet();
44
+ contexts.add(context);
45
+ preparationFailures.set(error, contexts);
46
+ }
47
+ throw error;
48
+ }
49
+ }
50
+ /** SDK 尚未调用 Provider 的准备失败;Core 可确认此路径没有 Provider 资源待回收。 */
51
+ export function isAdapterPreparationFailure(error, context) {
52
+ if (error === null || typeof error !== "object")
53
+ return false;
54
+ const contexts = preparationFailures.get(error);
55
+ if (!contexts?.has(context))
56
+ return false;
57
+ contexts.delete(context);
58
+ return true;
59
+ }
28
60
  /**
29
61
  * 接收编写输入并返回可注册的 Adapter,省略协议时仅补 canonical-only 声明。
30
62
  * 返回类型必须保留字段必有的保证;不得根据缺省声明推断 native 支持。
@@ -42,21 +74,45 @@ export function defineAdapter(adapter, levels = reasoningLevelMap(adapter.metada
42
74
  modes: ["canonical"],
43
75
  nativeMethods: []
44
76
  };
77
+ const defaults = structuredClone(adapter.defaultAgentEnv ??
78
+ defaultAgentEnv(metadata.type, metadata.agentSources.includes("provisioned") ? "provisioned" : "preset"));
45
79
  return Object.freeze({
46
80
  ...adapter,
81
+ get defaultAgentEnv() {
82
+ return structuredClone(defaults);
83
+ },
47
84
  metadata: {
48
85
  ...metadata,
49
86
  protocolSupport
50
87
  },
51
88
  async *invoke(request, context) {
52
- assertProtocolSupport(protocolSupport, {
53
- protocolMode: context?.protocolMode ?? "canonical"
89
+ // 可信连接归本次调用;同一低层请求被并发复用时也不能相互覆盖。
90
+ if (context?.providerOptions)
91
+ request = { ...request };
92
+ bindInvocationConnection(request, context?.providerOptions);
93
+ let requested;
94
+ let native;
95
+ await runAdapterPreparation(context, async () => {
96
+ assertAdapterAgentEnv(request);
97
+ context?.configureRuntimeLimits?.(invocationRuntimeLimits(request));
98
+ if (request.agentEnv.items.some((item) => item.namespace === "octo.execution" && item.name === "agent") &&
99
+ !metadata.agentSources.includes(invocationAgentSource(request)))
100
+ throw new Error(`AGENT_SOURCE_UNSUPPORTED: ${metadata.type}`);
101
+ if (invocationApprovalMode(request) !== "full_access" &&
102
+ (context?.protocolMode === "native"
103
+ ? !adapter.respondNative
104
+ : !adapter.respondInteraction))
105
+ throw new Error(`APPROVAL_MODE_UNSUPPORTED: ${metadata.type} does not implement execution-time approval responses`);
106
+ await assertAdapterWorkdir(request, metadata.workspace !== false);
107
+ assertProtocolSupport(protocolSupport, {
108
+ protocolMode: context?.protocolMode ?? "canonical"
109
+ });
110
+ const mcp = request.agentEnv.items.find((item) => item.namespace === "octo.execution" && item.name === "mcp");
111
+ if (mcp && Object.keys(mcp.payload.mcpServers).length && !adapter.metadata.mcp)
112
+ throw new Error(`MCP_UNSUPPORTED: ${adapter.metadata.type}`);
113
+ requested = invocationEffort(request);
114
+ native = mapReasoningEffort(adapter.metadata.type, requested, levels);
54
115
  });
55
- const mcp = request.context.items.find((item) => item.namespace === "octo.execution" && item.name === "mcp");
56
- if (mcp && Object.keys(mcp.payload.mcpServers).length && !adapter.metadata.mcp)
57
- throw new Error(`MCP_UNSUPPORTED: ${adapter.metadata.type}`);
58
- const requested = request.agentConfig.effort;
59
- const native = mapReasoningEffort(adapter.metadata.type, requested, levels);
60
116
  if (requested !== undefined && context?.protocolMode !== "native") {
61
117
  if (native === undefined || native !== requested)
62
118
  yield {
@@ -92,9 +148,9 @@ export function defineAdapter(adapter, levels = reasoningLevelMap(adapter.metada
92
148
  */
93
149
  export async function* spawnJsonLines(options) {
94
150
  const { command, args = [], cwd, env, input, signal, parseLine, onInputWritten } = options;
95
- const processEnv = mergeProcessEnvironment(process.env, env ?? {});
96
- const launch = resolveProcessLaunch(command, args, { cwd, env: processEnv });
97
- const child = spawn(launch.command, launch.args, {
151
+ assertProviderCommand(command);
152
+ const processEnv = mergeProcessEnvironment(env ?? {});
153
+ const child = spawn(command, args, {
98
154
  cwd,
99
155
  env: processEnv,
100
156
  stdio: ["pipe", "pipe", "pipe"],
@@ -241,8 +297,8 @@ export function createJsonCliAdapter(options) {
241
297
  };
242
298
  for await (const native of spawnJsonLines({
243
299
  ...spec,
244
- cwd: spec.cwd ?? request.workdir,
245
- env: invocationEnvironment(request, spec.env),
300
+ cwd: spec.cwd ?? invocationWorkdir(request),
301
+ env: invocationEnvironment(request, spec.env, {}),
246
302
  signal: request.signal,
247
303
  rawMessageMaxBytes: context?.streamLimits?.rawMessageMaxBytes,
248
304
  parseLine: parseJsonLine
@@ -271,51 +327,53 @@ export function createJsonCliAdapter(options) {
271
327
  }, options.reasoningLevels);
272
328
  }
273
329
  /**
274
- * Resolve whether a command is runnable. A path-qualified command is checked
275
- * directly; a bare name is searched across `PATH` (`;`-separated on Windows).
276
- * Returns the first executable match, else `command_not_found`.
330
+ * 探测宿主已绑定的绝对启动链;不搜索安装,版本参数接在宿主前缀参数之后。
331
+ * 返回目标可执行性和可选版本;版本命令失败不等于目标不可用,版本门禁由 Provider 决定。
332
+ * 文件缺失与权限不足分别报告,失败不选择其他安装,也不解释前缀参数中的入口。
277
333
  */
278
- export async function probeCommand(command, { env = process.env, cwd } = {}) {
279
- const candidates = isAbsolute(command) || command.includes("/") || command.includes("\\")
280
- ? [command]
281
- : (processEnvironmentValue(env, "PATH") ?? "").split(delimiter).flatMap((directory) => {
282
- const extensions = process.platform === "win32" && !/\.[^\\/]+$/.test(command)
283
- ? [
284
- "",
285
- ...(processEnvironmentValue(env, "PATHEXT") ?? ".EXE;.CMD;.BAT;.COM").split(";")
286
- ]
287
- : [""];
288
- return extensions.map((extension) => resolve(directory, command + extension));
289
- });
290
- for (const candidate of candidates) {
334
+ export async function probeCommand(command, { env = {}, cwd, args = [] } = {}) {
335
+ assertProviderCommand(command);
336
+ const candidate = command;
337
+ try {
338
+ await access(candidate, constants.X_OK);
339
+ if (!(await stat(candidate)).isFile())
340
+ return { available: false, command, reason: "invalid_executable" };
341
+ let version = null;
291
342
  try {
292
- await access(candidate, constants.X_OK);
293
- if (!(await stat(candidate)).isFile())
294
- continue;
295
- let version = null;
296
- try {
297
- const launch = resolveProcessLaunch(resolve(candidate), ["--version"], { env, cwd });
298
- const { stdout } = await promisify(execFile)(launch.command, launch.args, {
299
- env,
300
- cwd,
301
- timeout: 2_000,
302
- maxBuffer: 4096,
303
- windowsHide: true
304
- });
305
- const output = stdout.trim();
306
- // Keep a version label, not arbitrary CLI banners or diagnostics.
307
- version =
308
- output.match(/(?:^|\s)v?(\d+\.\d+(?:\.\d+)?(?:[-+][A-Za-z0-9.-]+)?)(?=\s|$)/)?.[1] ??
309
- null;
310
- }
311
- catch {
312
- // Executable availability does not imply support for --version.
313
- }
314
- return { available: true, command: resolve(candidate), version };
343
+ const { stdout } = await promisify(execFile)(candidate, [...args, "--version"], {
344
+ env,
345
+ cwd,
346
+ timeout: 2_000,
347
+ maxBuffer: 4096,
348
+ windowsHide: true
349
+ });
350
+ const output = stdout.trim();
351
+ // Keep a version label, not arbitrary CLI banners or diagnostics.
352
+ version =
353
+ output.match(/(?:^|\s)v?(\d+\.\d+(?:\.\d+)?(?:[-+][A-Za-z0-9.-]+)?)(?=\s|$)/)?.[1] ?? null;
315
354
  }
316
- catch {
317
- // Current candidate is not executable; keep scanning the next PATH entry.
355
+ catch (error) {
356
+ const { code, syscall } = error;
357
+ // spawn 的系统错误表明目标不能启动;非零退出、超时或输出过大只使版本未知。
358
+ if (syscall?.startsWith("spawn"))
359
+ return {
360
+ available: false,
361
+ command,
362
+ reason: code === "EACCES" || code === "EPERM"
363
+ ? "permission_denied"
364
+ : code === "ENOENT" || code === "ENOTDIR"
365
+ ? "command_not_found"
366
+ : "command_launch_failed"
367
+ };
318
368
  }
369
+ return { available: true, command: resolve(candidate), version };
370
+ }
371
+ catch (error) {
372
+ const code = error.code;
373
+ return {
374
+ available: false,
375
+ command,
376
+ reason: code === "EACCES" || code === "EPERM" ? "permission_denied" : "command_not_found"
377
+ };
319
378
  }
320
- return { available: false, command, reason: "command_not_found" };
321
379
  }
@@ -12,7 +12,7 @@ export function expandMcpValue(value, env, path) {
12
12
  });
13
13
  }
14
14
  export function invocationMcpServers(request, env = invocationEnvironment(request)) {
15
- const payload = contextItem(request.context, "octo.execution", "mcp")?.payload ?? {
15
+ const payload = contextItem(request.agentEnv, "octo.execution", "mcp")?.payload ?? {
16
16
  mcpServers: {}
17
17
  };
18
18
  assertContextMcp(payload);
@@ -1,5 +1,6 @@
1
+ import { type ProviderLaunch } from "./provider-launch.js";
1
2
  /**
2
- * 在 Provider 启动和版本探测前同步解析 Windows npm 包装器,保持 spawn 的同步返回合同。
3
+ * 仅由宿主在装配时解析 Windows npm 包装器;Adapter 和 transport 不调用此函数。
3
4
  * JS 入口交给 Node,原生入口直接执行;argv 独立传递,未知 batch 沿原路径报错。
4
5
  * 返回启动命令和参数;ChildProcess、管道及清理仍由调用方负责。
5
6
  */
@@ -10,3 +11,12 @@ export declare function resolveProcessLaunch(command: string, args: readonly str
10
11
  command: string;
11
12
  args: readonly string[];
12
13
  };
14
+ /**
15
+ * 仅供宿主装配调用:选择一个安装并解析 npm/Node 启动链,返回可注入快照。
16
+ * 首个已有候选损坏时立即失败,不换安装;不校验协议版本、不安装或启动程序。
17
+ */
18
+ export declare function resolveHostProviderLaunch(command: string, { env, cwd, args }: {
19
+ env: NodeJS.ProcessEnv;
20
+ cwd: string;
21
+ args?: readonly string[];
22
+ }): Required<ProviderLaunch>;
@@ -1,6 +1,7 @@
1
- import { readFileSync, statSync } from "node:fs";
2
- import { basename, delimiter, dirname, extname, join, resolve } from "node:path";
1
+ import { accessSync, closeSync, constants, lstatSync, openSync, readFileSync, readSync, realpathSync, statSync } from "node:fs";
2
+ import { basename, delimiter, dirname, extname, isAbsolute, join, resolve } from "node:path";
3
3
  import { processEnvironmentValue } from "./environment.js";
4
+ import { snapshotProviderLaunch } from "./provider-launch.js";
4
5
  function fileSize(file) {
5
6
  try {
6
7
  const info = statSync(file);
@@ -12,26 +13,57 @@ function fileSize(file) {
12
13
  throw error;
13
14
  }
14
15
  }
16
+ /** 有界读取 shebang;无扩展名的 Node 入口也必须在宿主固定运行器。 */
17
+ function isNodeScript(file) {
18
+ let descriptor;
19
+ try {
20
+ descriptor = openSync(file, "r");
21
+ }
22
+ catch (error) {
23
+ // 原生文件可以只有执行权限;读 shebang 不是原生 exec 的先决条件。
24
+ if (error.code === "EACCES")
25
+ return false;
26
+ throw error;
27
+ }
28
+ try {
29
+ const header = Buffer.alloc(256);
30
+ const length = readSync(descriptor, header, 0, header.length, 0);
31
+ const firstLine = header.toString("utf8", 0, length).split("\n", 1)[0];
32
+ if (!firstLine.startsWith("#!"))
33
+ return /\.[cm]?js$/i.test(file);
34
+ if (!/^#![^\r\n]*[/\s]node(?:\s|$)/.test(firstLine))
35
+ return false;
36
+ if (!/^#!\s*(?:\S*\/env\s+node|\S*\/node)\s*$/.test(firstLine))
37
+ throw new TypeError("PROVIDER_LAUNCH_INVALID: inject Node and shebang arguments explicitly");
38
+ return true;
39
+ }
40
+ finally {
41
+ closeSync(descriptor);
42
+ }
43
+ }
15
44
  function commandPath(command, env, cwd) {
16
45
  if (/[/\\]/.test(command) || /^[A-Za-z]:/.test(command))
17
46
  return resolve(cwd, command);
18
- const extensions = extname(command)
47
+ const extensions = process.platform !== "win32" || extname(command)
19
48
  ? [""]
20
49
  : (processEnvironmentValue(env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD")
21
50
  .split(";")
22
51
  .filter((extension) => /^\.(exe|com|cmd|bat)$/i.test(extension));
23
- const path = processEnvironmentValue(env, "PATH") ?? processEnvironmentValue(process.env, "PATH") ?? "";
24
- for (const directory of [cwd, ...path.split(delimiter)]) {
52
+ const path = processEnvironmentValue(env, "PATH") ?? "";
53
+ const directories = process.platform === "win32" ? [cwd, ...path.split(delimiter)] : path.split(delimiter);
54
+ for (const directory of directories) {
25
55
  for (const extension of extensions) {
26
56
  const candidate = resolve(cwd, directory.replace(/^"(.*)"$/, "$1"), command + extension);
27
- if (fileSize(candidate) !== undefined)
57
+ if (fileSize(candidate) !== undefined) {
58
+ accessSync(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);
28
59
  return candidate;
60
+ }
29
61
  }
30
62
  }
31
63
  return undefined;
32
64
  }
33
65
  /**
34
- * 在 Provider 启动和版本探测前同步解析 Windows npm 包装器,保持 spawn 的同步返回合同。
66
+ * 仅由宿主在装配时解析 Windows npm 包装器;Adapter 和 transport 不调用此函数。
35
67
  * JS 入口交给 Node,原生入口直接执行;argv 独立传递,未知 batch 沿原路径报错。
36
68
  * 返回启动命令和参数;ChildProcess、管道及清理仍由调用方负责。
37
69
  */
@@ -86,6 +118,55 @@ export function resolveProcessLaunch(command, args, { env = process.env, cwd = p
86
118
  ? pathNode
87
119
  : basename(process.execPath).toLowerCase() === "node.exe"
88
120
  ? process.execPath
89
- : "node";
121
+ : undefined;
122
+ if (!node)
123
+ throw Object.assign(new Error("Provider Node runtime not found"), { code: "ENOENT" });
90
124
  return { command: node, args: [entry, ...args] };
91
125
  }
126
+ /**
127
+ * 仅供宿主装配调用:选择一个安装并解析 npm/Node 启动链,返回可注入快照。
128
+ * 首个已有候选损坏时立即失败,不换安装;不校验协议版本、不安装或启动程序。
129
+ */
130
+ export function resolveHostProviderLaunch(command, { env, cwd, args = [] }) {
131
+ if (!command || command.includes("\0"))
132
+ throw new TypeError("PROVIDER_LAUNCH_INVALID");
133
+ const qualified = isAbsolute(command) || /[/\\]/.test(command) || /^[A-Za-z]:/.test(command);
134
+ const extensions = process.platform === "win32" && !extname(command)
135
+ ? (processEnvironmentValue(env, "PATHEXT") ?? ".EXE;.CMD;.BAT;.COM").split(";")
136
+ : [""];
137
+ const directories = qualified
138
+ ? [""]
139
+ : (processEnvironmentValue(env, "PATH") ?? "").split(delimiter);
140
+ let selected;
141
+ for (const directory of directories) {
142
+ for (const extension of extensions) {
143
+ const candidate = resolve(cwd, directory.replace(/^"(.*)"$/, "$1"), command + extension);
144
+ try {
145
+ lstatSync(candidate);
146
+ }
147
+ catch (error) {
148
+ if (["ENOENT", "ENOTDIR"].includes(error.code ?? ""))
149
+ continue;
150
+ throw error;
151
+ }
152
+ accessSync(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);
153
+ if (!statSync(candidate).isFile())
154
+ throw new TypeError("PROVIDER_LAUNCH_INVALID");
155
+ selected = candidate;
156
+ break;
157
+ }
158
+ if (selected)
159
+ break;
160
+ }
161
+ if (!selected)
162
+ throw Object.assign(new Error("Provider command not found"), { code: "ENOENT" });
163
+ let launch = resolveProcessLaunch(selected, args, { env, cwd });
164
+ const physical = realpathSync(selected);
165
+ if (process.platform !== "win32" && isNodeScript(physical)) {
166
+ const node = process.versions.electron ? commandPath("node", env, cwd) : process.execPath;
167
+ if (!node)
168
+ throw Object.assign(new Error("Provider Node runtime not found"), { code: "ENOENT" });
169
+ launch = { command: node, args: [physical, ...args] };
170
+ }
171
+ return snapshotProviderLaunch({ ...launch, env });
172
+ }
@@ -0,0 +1,10 @@
1
+ /** 宿主已选定的本地启动目标;args 只含运行器/入口前缀,协议参数由 Adapter 追加。 */
2
+ export interface ProviderLaunch {
3
+ command: string;
4
+ args?: readonly string[];
5
+ env?: NodeJS.ProcessEnv;
6
+ }
7
+ /** 构造时复制宿主绑定,不发现安装、不启动程序;本轮环境不能重新选择 executable。 */
8
+ export declare function snapshotProviderLaunch(launch: ProviderLaunch): Required<ProviderLaunch>;
9
+ /** 纯执行层只接受已解析的绝对路径;不解析 PATH、cwd、shim 或备用安装。 */
10
+ export declare function assertProviderCommand(command: unknown): asserts command is string;
@@ -0,0 +1,25 @@
1
+ import { isAbsolute } from "node:path";
2
+ /** 构造时复制宿主绑定,不发现安装、不启动程序;本轮环境不能重新选择 executable。 */
3
+ export function snapshotProviderLaunch(launch) {
4
+ assertProviderCommand(launch?.command);
5
+ const args = launch.args ?? [];
6
+ if (!Array.isArray(args) ||
7
+ args.some((arg) => typeof arg !== "string" || arg.includes("\0")))
8
+ throw new TypeError("PROVIDER_LAUNCH_INVALID");
9
+ return Object.freeze({
10
+ command: launch.command,
11
+ args: Object.freeze(Array.from(args, (arg) => {
12
+ if (typeof arg !== "string")
13
+ throw new TypeError("PROVIDER_LAUNCH_INVALID");
14
+ return arg;
15
+ })),
16
+ env: Object.freeze({ ...(launch.env ?? {}) })
17
+ });
18
+ }
19
+ /** 纯执行层只接受已解析的绝对路径;不解析 PATH、cwd、shim 或备用安装。 */
20
+ export function assertProviderCommand(command) {
21
+ if (command === undefined)
22
+ throw new TypeError("PROVIDER_LAUNCH_REQUIRED");
23
+ if (typeof command !== "string" || !command || command.includes("\0") || !isAbsolute(command))
24
+ throw new TypeError("PROVIDER_LAUNCH_INVALID");
25
+ }
@@ -30,10 +30,17 @@ export function sanitizeDiagnosticBody(body) {
30
30
  safe = "[REDACTED]";
31
31
  // Headers can occur inside a JSON message too. Drop the entire suffix at the first
32
32
  // sensitive key instead of guessing where a spaced or truncated credential ends.
33
- const keys = /["']?([\w-]+)[\\"']*\s*[:=]/g;
33
+ // 先消费完整 key,再单向检查分隔符,避免无分隔符长输入反复回溯后缀。
34
+ const keys = /[\w-]+/g;
34
35
  for (const match of safe.matchAll(keys)) {
35
- if (SENSITIVE_OUTPUT_KEY.test(match[1])) {
36
- safe = `${safe.slice(0, match.index)}[REDACTED]`;
36
+ let end = match.index + match[0].length;
37
+ while (end < safe.length && /[\\"']/.test(safe[end]))
38
+ end += 1;
39
+ while (end < safe.length && /\s/.test(safe[end]))
40
+ end += 1;
41
+ if ((safe[end] === ":" || safe[end] === "=") && SENSITIVE_OUTPUT_KEY.test(match[0])) {
42
+ const start = match.index > 0 && /["']/.test(safe[match.index - 1]) ? match.index - 1 : match.index;
43
+ safe = `${safe.slice(0, start)}[REDACTED]`;
37
44
  break;
38
45
  }
39
46
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mininglamp-oss/octo-runtime-adapter-sdk",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "private": true,
5
5
  "type": "module",
6
6
  "exports": {
@@ -10,7 +10,7 @@
10
10
  "./module-manifest": "./dist/module-manifest.js"
11
11
  },
12
12
  "dependencies": {
13
- "@mininglamp-oss/octo-runtime-protocol": "1.1.12",
13
+ "@mininglamp-oss/octo-runtime-protocol": "1.1.13",
14
14
  "import-meta-resolve": "4.2.0"
15
15
  },
16
16
  "types": "./dist/index.d.ts",
@@ -1,7 +1,25 @@
1
1
  import { type AdapterModuleEntry } from "@mininglamp-oss/octo-runtime-adapter-sdk/module-manifest";
2
2
  import type { HostedAdapter } from "@mininglamp-oss/octo-runtime-executor-kernel";
3
+ import { type ServiceCleanupResult } from "@mininglamp-oss/octo-runtime-executor-kernel";
4
+ import type { AdapterScopeCleanup, ServiceProcessSnapshot } from "@mininglamp-oss/octo-runtime-adapter-sdk";
5
+ /** CLI 默认每种 Harness 一个自有实例;工厂不按调用分池,SDK 自管装配不受此约定限制。 */
6
+ export interface CliAdapterResource {
7
+ adapter: HostedAdapter;
8
+ processes?(): readonly ServiceProcessSnapshot[];
9
+ beginShutdown?(): void;
10
+ close(deadline: number): Promise<AdapterScopeCleanup>;
11
+ }
12
+ export interface CliAdapters {
13
+ adapters: HostedAdapter[];
14
+ processes(): readonly ServiceProcessSnapshot[];
15
+ beginShutdown(): void;
16
+ close(deadline: number): Promise<AdapterScopeCleanup>;
17
+ }
3
18
  /** CLI 只加载所选模块并构造实例;Kernel 不接触清单、模块路径或产品准备。 */
4
19
  export declare function loadCliAdapters(entries: readonly AdapterModuleEntry[], options?: {
5
20
  profileRoot: string;
6
21
  syncOpenClawTools: boolean;
7
- }): Promise<HostedAdapter[]>;
22
+ env?: NodeJS.ProcessEnv;
23
+ }): Promise<CliAdapters>;
24
+ /** 将宿主资源清理事实投影到既有启动诊断;主失败与 pending/failed 资源分别保留。 */
25
+ export declare function cliCleanupResult(cleanup: AdapterScopeCleanup): ServiceCleanupResult;