@mininglamp-oss/octo-runtime 1.1.3 → 1.1.4
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.
- package/README.md +1 -1
- package/apps/cli/dist/build-info.json +2 -2
- package/apps/cli/dist/help.js +5 -1
- package/apps/cli/dist/main.js +32 -6
- package/apps/cli/dist/manifest.json +5 -0
- package/apps/cli/dist/openclaw.js +32 -8
- package/apps/cli/dist/output.js +3 -0
- package/apps/cli/dist/playboard.d.ts +5 -0
- package/apps/cli/dist/playboard.js +41 -13
- package/dist/public/dsh.d.ts +2 -0
- package/dist/public/dsh.js +1 -0
- package/dist/public/executor-kernel.d.ts +1 -1
- package/dist/public/executor-kernel.js +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/dist/index.js +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-acp-client/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/dist/index.js +26 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-acp/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-antigravity/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-claude-code/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codebuddy/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/dist/index.js +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-codex/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-DYOJCNWF.js +854 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-G5PWGRL5.js +209 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/chunk-UOQRXV3Q.js +340 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/desktop-entry.js +16 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-NOTICE.txt +6 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-client-LICENSE.txt +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/dsh-sdk-protocol-LICENSE.txt +21 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.d.ts +35 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/errors.js +14 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.d.ts +52 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/index.js +306 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.d.ts +11 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/launch.js +13 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.d.ts +12 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/dist/trajectory.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-dsh/package.json +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/dist/client.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-grok-build/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-hermes/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-kimi-code/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-mcode/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-openclaw/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.d.ts +10 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/dist/index.js +214 -55
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-opencode/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qodercli/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-qoderclicn/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/activity.d.ts +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/environment.js +24 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/hourly-log.js +11 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.d.ts +12 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/index.js +30 -8
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/mcp.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/public-display.js +15 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/dist/runtime-log.js +29 -1
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-sdk/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/dist/index.js +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-adapter-zcode-gui/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/build-info.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/help.js +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/main.js +32 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/manifest.json +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/openclaw.js +32 -8
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/output.js +3 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-cli/dist/playboard.js +41 -13
- package/node_modules/@mininglamp-oss/octo-runtime-cli/package.json +24 -23
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.d.ts +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/common.js +16 -6
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/systemd.js +9 -7
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.d.ts +4 -1
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/dist/windows-task.js +36 -11
- package/node_modules/@mininglamp-oss/octo-runtime-cross-service/package.json +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/dist/index.js +7 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-core/package.json +3 -3
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.d.ts +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/index.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-lifecycle.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.d.ts +16 -1
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/invocation-manifest.js +152 -21
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/serve.js +9 -2
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.d.ts +8 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/dist/submission-error.js +17 -0
- package/node_modules/@mininglamp-oss/octo-runtime-executor-kernel/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/config-schema.json +56 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/im-channel.js +167 -25
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/application/session-store.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/contracts.d.ts +19 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.d.ts +23 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifact-policy.js +43 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.d.ts +15 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/delivery/artifacts.js +283 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/dispatcher.js +15 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.d.ts +5 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/task.js +48 -13
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.d.ts +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/execution/tool-environment.js +5 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/lifecycle/configuration.js +26 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/cards.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.d.ts +1 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/client.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/conversations.js +3 -2
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.d.ts +4 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/files.js +104 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/rules.js +4 -3
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.d.ts +2 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/api/url.js +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/auth.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.d.ts +9 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/channel.js +44 -13
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/image-input.js +2 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.d.ts +7 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/dist/transport/wukong.js +10 -7
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-gateway/package.json +6 -6
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/im-channel.js +141 -16
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/dist/application/session-store.d.ts +3 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-channel-wecom/package.json +5 -5
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-CXTvRGim.js +74 -0
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/index.html +1 -1
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/package.json +2 -2
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/extra-config.js +33 -9
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/dist/home.js +9 -4
- package/node_modules/@mininglamp-oss/octo-runtime-host-sdk/package.json +4 -4
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.d.ts +5 -0
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/failure.js +39 -1
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/dist/generated/protocol-types.d.ts +76 -7
- package/node_modules/@mininglamp-oss/octo-runtime-protocol/package.json +1 -1
- package/package.json +35 -29
- package/packages/octo-runtime-extra-channel-gateway/config-schema.json +56 -0
- package/packages/octo-runtime-protocol/schema/kernel-ipc.schema.json +443 -56
- package/packages/octo-runtime-protocol/schema/protocol.schema.json +357 -37
- package/node_modules/@mininglamp-oss/octo-runtime-extra-webui/dist/web/assets/index-DiPc-ipL.js +0 -74
|
@@ -1,15 +1,81 @@
|
|
|
1
|
-
import { initialControlInstructions, hasImageInput, mapReasoningEffort, invocationEnvironment, invocationMcpServers, assertMcpOptions } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
1
|
+
import { initialControlInstructions, hasImageInput, mapReasoningEffort, invocationEnvironment, processEnvironmentValue, invocationMcpServers, assertMcpOptions } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
2
2
|
import { canonicalTerminalStatus } from "@mininglamp-oss/octo-runtime-protocol";
|
|
3
3
|
/**
|
|
4
4
|
* OpenCode adapter: wraps the OpenCode CLI (`opencode run --format json
|
|
5
5
|
* --thinking --auto`) for full access and ACP for interactive approval.
|
|
6
6
|
* Both transports normalize provider output into canonical events.
|
|
7
7
|
*/
|
|
8
|
-
import { createAcpAdapter } from "@mininglamp-oss/octo-runtime-adapter-acp";
|
|
9
|
-
import { createJsonCliAdapter, probeCommand, providerInputText } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
8
|
+
import { AcpInvocationError, createAcpAdapter } from "@mininglamp-oss/octo-runtime-adapter-acp";
|
|
9
|
+
import { createJsonCliAdapter, probeCommand, providerInputText, ProviderProcessError } from "@mininglamp-oss/octo-runtime-adapter-sdk";
|
|
10
10
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
|
-
import { join } from "node:path";
|
|
12
|
+
import { delimiter, join, parse, resolve } from "node:path";
|
|
13
|
+
export const MINIMUM_OPENCODE_VERSION = "2.1.3";
|
|
14
|
+
class OpenCodeInputError extends Error {
|
|
15
|
+
}
|
|
16
|
+
/** 检查本轮实际选中的程序;未知版本与 V1 都不能进入执行传输。 */
|
|
17
|
+
export async function probeOpenCode(command = "opencode", env = process.env, cwd = process.cwd()) {
|
|
18
|
+
const qualified = command.includes("/") || command.includes("\\") || parse(command).root !== "";
|
|
19
|
+
// 本机 path 规则保留绝对路径;Windows 根相对和盘符相对路径也绑定本轮 cwd。
|
|
20
|
+
const selected = qualified ? resolve(cwd, command) : command;
|
|
21
|
+
const probeEnv = { ...env };
|
|
22
|
+
if (process.platform === "win32") {
|
|
23
|
+
// 普通对象的键区分大小写;与 Node 子进程一致,重复别名取字典序首项。
|
|
24
|
+
for (const name of ["PATH", "PATHEXT"]) {
|
|
25
|
+
const aliases = Object.keys(env)
|
|
26
|
+
.filter((key) => key.toUpperCase() === name)
|
|
27
|
+
.sort();
|
|
28
|
+
const value = aliases.length ? env[aliases[0]] : undefined;
|
|
29
|
+
for (const alias of aliases)
|
|
30
|
+
delete probeEnv[alias];
|
|
31
|
+
if (value !== undefined)
|
|
32
|
+
probeEnv[name] = value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// 空项和相对项按子进程 cwd 查找;绝对项按本机规则保留原有含义。
|
|
36
|
+
probeEnv.PATH = (probeEnv.PATH ?? "")
|
|
37
|
+
.split(delimiter)
|
|
38
|
+
.map((entry) => resolve(cwd, entry))
|
|
39
|
+
.join(delimiter);
|
|
40
|
+
const result = await probeCommand(selected, {
|
|
41
|
+
cwd,
|
|
42
|
+
env: probeEnv
|
|
43
|
+
});
|
|
44
|
+
if (!result.available)
|
|
45
|
+
return result;
|
|
46
|
+
if (!result.version)
|
|
47
|
+
return {
|
|
48
|
+
...result,
|
|
49
|
+
available: false,
|
|
50
|
+
reason: "OPENCODE_VERSION_DETECTION_FAILED: could not determine OpenCode version (--version failed, timed out, or returned invalid output)"
|
|
51
|
+
};
|
|
52
|
+
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(result.version);
|
|
53
|
+
if (!match ||
|
|
54
|
+
Number(match[1]) !== 2 ||
|
|
55
|
+
Number(match[2]) < 1 ||
|
|
56
|
+
(Number(match[2]) === 1 && Number(match[3]) < 3))
|
|
57
|
+
return {
|
|
58
|
+
...result,
|
|
59
|
+
available: false,
|
|
60
|
+
reason: `OPENCODE_VERSION_UNSUPPORTED: detected ${result.version}. ${result.version.startsWith("1.") ? "OpenCode 1 is no longer supported. " : ""}Install OpenCode >= ${MINIMUM_OPENCODE_VERSION} < 3 and retry.`
|
|
61
|
+
};
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
function inlineConfig(request) {
|
|
65
|
+
const content = processEnvironmentValue(invocationEnvironment(request), "OPENCODE_CONFIG_CONTENT");
|
|
66
|
+
if (!content)
|
|
67
|
+
return {};
|
|
68
|
+
let parsed;
|
|
69
|
+
try {
|
|
70
|
+
parsed = JSON.parse(content);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
throw new OpenCodeInputError("OPENCODE_CONFIG_INVALID: OPENCODE_CONFIG_CONTENT must be a JSON object");
|
|
74
|
+
}
|
|
75
|
+
if (!isRecord(parsed))
|
|
76
|
+
throw new OpenCodeInputError("OPENCODE_CONFIG_INVALID: OPENCODE_CONFIG_CONTENT must be a JSON object");
|
|
77
|
+
return parsed;
|
|
78
|
+
}
|
|
13
79
|
/**
|
|
14
80
|
* Build the OpenCode CLI argv/env for one invocation.
|
|
15
81
|
*
|
|
@@ -27,55 +93,75 @@ export async function buildOpenCodeCommand(req, command = "opencode") {
|
|
|
27
93
|
const runEnv = invocationEnvironment(req);
|
|
28
94
|
const servers = invocationMcpServers(req, runEnv);
|
|
29
95
|
assertMcpOptions(servers, "opencode", ["toolTimeoutMs"]);
|
|
30
|
-
const
|
|
31
|
-
const instructions = join(directory, "instructions.md");
|
|
32
|
-
await writeFile(instructions, initialControlInstructions(req), { mode: 0o600 });
|
|
33
|
-
let inline = {};
|
|
34
|
-
if (runEnv.OPENCODE_CONFIG_CONTENT)
|
|
35
|
-
inline = JSON.parse(runEnv.OPENCODE_CONFIG_CONTENT);
|
|
96
|
+
const inline = inlineConfig(req);
|
|
36
97
|
const configuredInstructions = Array.isArray(inline.instructions)
|
|
37
98
|
? inline.instructions.filter((value) => typeof value === "string")
|
|
38
99
|
: [];
|
|
39
|
-
// Inject harness context via a temporary instructions file, without rewriting the user's existing OpenCode config.
|
|
40
|
-
if (initialControlInstructions(req))
|
|
41
|
-
inline.instructions = [...configuredInstructions, instructions];
|
|
42
100
|
if (Object.keys(servers).length) {
|
|
101
|
+
const existing = isRecord(inline.mcp) ? inline.mcp : {};
|
|
43
102
|
inline.mcp = {
|
|
44
|
-
...
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
103
|
+
...existing,
|
|
104
|
+
servers: {
|
|
105
|
+
...(isRecord(existing.servers) ? existing.servers : {}),
|
|
106
|
+
...Object.fromEntries(Object.entries(servers).map(([name, server]) => [
|
|
107
|
+
name,
|
|
108
|
+
{
|
|
109
|
+
...(server.type === "stdio"
|
|
110
|
+
? {
|
|
111
|
+
type: "local",
|
|
112
|
+
command: [server.command, ...(server.args ?? [])],
|
|
113
|
+
environment: server.env ?? {}
|
|
114
|
+
}
|
|
115
|
+
: { type: "remote", url: server.url, headers: server.headers ?? {} }),
|
|
116
|
+
disabled: false,
|
|
117
|
+
...(server.toolTimeoutMs !== undefined
|
|
118
|
+
? { timeout: { execution: server.toolTimeoutMs } }
|
|
119
|
+
: {})
|
|
120
|
+
}
|
|
121
|
+
]))
|
|
122
|
+
}
|
|
59
123
|
};
|
|
60
124
|
}
|
|
61
125
|
// Reasoning output and non-interactive tool approval are mandatory parts of
|
|
62
126
|
// this adapter's provider contract.
|
|
63
|
-
const args = ["run", "--format", "json", "--thinking", "--auto"];
|
|
127
|
+
const args = ["run", "--format", "json", "--thinking", "--auto", "--standalone"];
|
|
64
128
|
if (req.providerSession?.sessionId)
|
|
65
129
|
args.push("--session", req.providerSession.sessionId);
|
|
66
|
-
if (req.agentConfig?.model)
|
|
67
|
-
args.push("--model", req.agentConfig.model);
|
|
68
130
|
const variant = mapReasoningEffort("opencode", req.agentConfig?.effort);
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
131
|
+
if (req.agentConfig?.model) {
|
|
132
|
+
const model = req.agentConfig.model;
|
|
133
|
+
args.push("--model", variant ? `${model.split("#")[0]}#${variant}` : model);
|
|
134
|
+
}
|
|
135
|
+
// 先校验和转换,再创建资源;写入失败由本层回收,返回后交给 CLI helper。
|
|
136
|
+
let directory;
|
|
137
|
+
try {
|
|
138
|
+
if (initialControlInstructions(req)) {
|
|
139
|
+
directory = await mkdtemp(join(tmpdir(), "octo-runtime-opencode-"));
|
|
140
|
+
const instructions = join(directory, "instructions.md");
|
|
141
|
+
await writeFile(instructions, initialControlInstructions(req), { mode: 0o600 });
|
|
142
|
+
inline.instructions = [...configuredInstructions, instructions];
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (directory)
|
|
147
|
+
await rm(directory, { recursive: true, force: true });
|
|
148
|
+
throw error;
|
|
149
|
+
}
|
|
72
150
|
return {
|
|
73
151
|
command,
|
|
74
152
|
args,
|
|
75
|
-
|
|
76
|
-
|
|
153
|
+
input: providerInputText(req),
|
|
154
|
+
env: {
|
|
155
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(inline),
|
|
156
|
+
OPENCODE_CLIENT: "octo-runtime",
|
|
157
|
+
PWD: req.workdir
|
|
158
|
+
},
|
|
159
|
+
rpcMethod: "process.stdin",
|
|
77
160
|
providerSessionId: req.providerSession?.sessionId,
|
|
78
|
-
cleanup: () =>
|
|
161
|
+
cleanup: async () => {
|
|
162
|
+
if (directory)
|
|
163
|
+
await rm(directory, { recursive: true, force: true });
|
|
164
|
+
}
|
|
79
165
|
};
|
|
80
166
|
}
|
|
81
167
|
/** Translate one OpenCode native event/part into canonical events; unrelated events yield an empty list. */
|
|
@@ -193,8 +279,6 @@ export function normalizeOpenCodeEvent(native) {
|
|
|
193
279
|
...(stepId ? { stepId } : {})
|
|
194
280
|
}
|
|
195
281
|
});
|
|
196
|
-
if (part.reason === "stop")
|
|
197
|
-
events.push({ protocolVersion: 2, type: "run.completed", payload: {} });
|
|
198
282
|
}
|
|
199
283
|
if (native.type === "error")
|
|
200
284
|
events.push({
|
|
@@ -278,19 +362,17 @@ export class OpenCodeEventNormalizer {
|
|
|
278
362
|
}
|
|
279
363
|
}
|
|
280
364
|
export function createOpenCodeAdapter({ command = "opencode" } = {}) {
|
|
281
|
-
const
|
|
365
|
+
const interactiveAdapters = new Map();
|
|
366
|
+
const createInteractive = (selected) => createAcpAdapter({
|
|
282
367
|
type: "opencode",
|
|
283
368
|
provider: "opencode",
|
|
284
|
-
command,
|
|
369
|
+
command: selected,
|
|
285
370
|
args: ["acp"],
|
|
286
|
-
|
|
371
|
+
// ACP 原生权限策略决定何时请求审批;桥接层逐次处理,不覆盖用户的 deny。
|
|
372
|
+
env: (request) => ({
|
|
287
373
|
OPENCODE_CLIENT: "octo-runtime",
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
? JSON.parse(process.env.OPENCODE_CONFIG_CONTENT)
|
|
291
|
-
: {}),
|
|
292
|
-
permission: "ask"
|
|
293
|
-
})
|
|
374
|
+
PWD: request.workdir,
|
|
375
|
+
OPENCODE_CONFIG_CONTENT: JSON.stringify(inlineConfig(request))
|
|
294
376
|
})
|
|
295
377
|
});
|
|
296
378
|
const options = {
|
|
@@ -299,7 +381,7 @@ export function createOpenCodeAdapter({ command = "opencode" } = {}) {
|
|
|
299
381
|
type: "opencode",
|
|
300
382
|
agentSources: ["provisioned"]
|
|
301
383
|
},
|
|
302
|
-
probe: () =>
|
|
384
|
+
probe: () => probeOpenCode(command),
|
|
303
385
|
buildCommand: (req) => buildOpenCodeCommand(req, command),
|
|
304
386
|
normalize: normalizeOpenCodeEvent,
|
|
305
387
|
onSuccess: () => [
|
|
@@ -314,21 +396,98 @@ export function createOpenCodeAdapter({ command = "opencode" } = {}) {
|
|
|
314
396
|
const adapter = createJsonCliAdapter(options);
|
|
315
397
|
return {
|
|
316
398
|
...adapter,
|
|
317
|
-
respondInteraction
|
|
399
|
+
async respondInteraction(...args) {
|
|
400
|
+
const interactive = interactiveAdapters.get(args[0]);
|
|
401
|
+
if (!interactive)
|
|
402
|
+
throw new Error("INTERACTION_NOT_ACTIVE");
|
|
403
|
+
await interactive.respondInteraction(...args);
|
|
404
|
+
},
|
|
318
405
|
async *invoke(request, context) {
|
|
319
406
|
if (hasImageInput(request))
|
|
320
407
|
throw new Error("UNSUPPORTED_INPUT_MODALITY: opencode does not encode image input");
|
|
321
408
|
if (request.approvalMode === "assisted")
|
|
322
409
|
throw new Error("APPROVAL_MODE_UNSUPPORTED: opencode has no qualified assisted policy");
|
|
410
|
+
request.signal?.throwIfAborted();
|
|
411
|
+
const selected = await probeOpenCode(command, invocationEnvironment(request), request.workdir);
|
|
412
|
+
if (!selected.available)
|
|
413
|
+
throw new Error(selected.reason ?? "OpenCode is unavailable");
|
|
414
|
+
request.signal?.throwIfAborted();
|
|
415
|
+
try {
|
|
416
|
+
inlineConfig(request);
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
if (!(error instanceof OpenCodeInputError))
|
|
420
|
+
throw error;
|
|
421
|
+
yield {
|
|
422
|
+
protocolVersion: 2,
|
|
423
|
+
type: "run.failed",
|
|
424
|
+
payload: { code: "OPENCODE_CONFIG_INVALID", message: error.message }
|
|
425
|
+
};
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
323
428
|
if (request.approvalMode === "ask") {
|
|
324
|
-
|
|
429
|
+
if (interactiveAdapters.has(request.invocationId))
|
|
430
|
+
throw new Error("INVOCATION_ALREADY_ACTIVE");
|
|
431
|
+
const interactive = createInteractive(selected.command);
|
|
432
|
+
interactiveAdapters.set(request.invocationId, interactive);
|
|
433
|
+
try {
|
|
434
|
+
yield* interactive.invoke(request, context);
|
|
435
|
+
}
|
|
436
|
+
catch (error) {
|
|
437
|
+
if (!(error instanceof AcpInvocationError))
|
|
438
|
+
throw error;
|
|
439
|
+
// 只有共享 ACP 确认 close 成功后的调用错误才收敛为失败终态。
|
|
440
|
+
yield { protocolVersion: 2, type: "run.failed", payload: { message: error.message } };
|
|
441
|
+
}
|
|
442
|
+
finally {
|
|
443
|
+
interactiveAdapters.delete(request.invocationId);
|
|
444
|
+
}
|
|
325
445
|
return;
|
|
326
446
|
}
|
|
327
447
|
const normalizer = new OpenCodeEventNormalizer();
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
448
|
+
let finalText = false;
|
|
449
|
+
try {
|
|
450
|
+
yield* createJsonCliAdapter({
|
|
451
|
+
...options,
|
|
452
|
+
reasoningLevels: request.agentConfig.model ? undefined : null,
|
|
453
|
+
buildCommand: (req) => buildOpenCodeCommand(req, selected.command),
|
|
454
|
+
normalize: (native) => {
|
|
455
|
+
const part = native.part ?? native;
|
|
456
|
+
if (native.type === "step_start" || part.type === "step-start")
|
|
457
|
+
finalText = false;
|
|
458
|
+
if ((native.type === "text" || part.type === "text") && typeof part.text === "string")
|
|
459
|
+
finalText = true;
|
|
460
|
+
// 一个 step 的 stop 不能掩盖随后进程的失败;等待私有 CLI 正常退出。
|
|
461
|
+
return normalizer.normalize(native);
|
|
462
|
+
},
|
|
463
|
+
onSuccess: (req) => {
|
|
464
|
+
if (!finalText)
|
|
465
|
+
return [
|
|
466
|
+
{
|
|
467
|
+
protocolVersion: 2,
|
|
468
|
+
type: "run.failed",
|
|
469
|
+
payload: {
|
|
470
|
+
code: "OPENCODE_INCOMPLETE_OUTPUT",
|
|
471
|
+
message: "OPENCODE_INCOMPLETE_OUTPUT: process exited without a final assistant response"
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
];
|
|
475
|
+
return options.onSuccess(req);
|
|
476
|
+
}
|
|
477
|
+
}).invoke(request, context);
|
|
478
|
+
}
|
|
479
|
+
catch (error) {
|
|
480
|
+
// helper 的 finally 已回收进程和临时文件;只收敛已知的进程退出,清理异常继续向上报告。
|
|
481
|
+
if (!(error instanceof ProviderProcessError))
|
|
482
|
+
throw error;
|
|
483
|
+
yield request.signal?.aborted
|
|
484
|
+
? {
|
|
485
|
+
protocolVersion: 2,
|
|
486
|
+
type: "run.cancelled",
|
|
487
|
+
payload: { reason: String(request.signal.reason ?? "cancelled") }
|
|
488
|
+
}
|
|
489
|
+
: { protocolVersion: 2, type: "run.failed", payload: { message: error.message } };
|
|
490
|
+
}
|
|
332
491
|
}
|
|
333
492
|
};
|
|
334
493
|
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-opencode",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@mininglamp-oss/octo-runtime-protocol": "1.1.
|
|
9
|
-
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.
|
|
10
|
-
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.
|
|
8
|
+
"@mininglamp-oss/octo-runtime-protocol": "1.1.4",
|
|
9
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.4",
|
|
10
|
+
"@mininglamp-oss/octo-runtime-adapter-sdk": "1.1.4"
|
|
11
11
|
},
|
|
12
12
|
"types": "./dist/index.d.ts",
|
|
13
13
|
"files": [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-qodercli",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.
|
|
12
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.4"
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mininglamp-oss/octo-runtime-adapter-qoderclicn",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./dist/index.js",
|
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.
|
|
12
|
+
"@mininglamp-oss/octo-runtime-adapter-acp": "1.1.4"
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ProtocolMode, StreamLimitPolicy } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
|
+
import type { RuntimeLog } from "./runtime-log.js";
|
|
2
3
|
/** Provider progress used by the host watchdog to enforce execution deadlines. */
|
|
3
4
|
export interface ProviderActivity {
|
|
4
5
|
kind: "turn_started" | "turn_progress" | "transport_response" | "retry_notice";
|
|
@@ -9,6 +10,8 @@ export interface ProviderActivity {
|
|
|
9
10
|
export interface AdapterInvocationContext {
|
|
10
11
|
protocolMode?: ProtocolMode;
|
|
11
12
|
streamLimits?: Readonly<StreamLimitPolicy>;
|
|
13
|
+
/** Existing host metadata sink; never serialize or log provider bodies. */
|
|
14
|
+
log?: RuntimeLog;
|
|
12
15
|
reportConversion?(): void;
|
|
13
16
|
reportActivity?(activity: ProviderActivity): void;
|
|
14
17
|
}
|
|
@@ -3,3 +3,7 @@ import { type InvokeRequest } from "@mininglamp-oss/octo-runtime-protocol";
|
|
|
3
3
|
export declare function invocationEnvs(request: InvokeRequest): Record<string, string>;
|
|
4
4
|
/** Each invocation owns its environment. Adapter transport settings take precedence. */
|
|
5
5
|
export declare function invocationEnvironment(request: InvokeRequest, overrides?: NodeJS.ProcessEnv, inherited?: NodeJS.ProcessEnv): NodeJS.ProcessEnv;
|
|
6
|
+
/** 每层后写覆盖前层;Windows 环境键不区分大小写,保留最终拼写且不修改输入对象。 */
|
|
7
|
+
export declare function mergeProcessEnvironment<T>(...layers: Record<string, T>[]): Record<string, T>;
|
|
8
|
+
/** 读取实际进程环境时沿用平台键身份;只读自有属性,Windows 后写别名优先。 */
|
|
9
|
+
export declare function processEnvironmentValue(env: NodeJS.ProcessEnv, name: string): string | undefined;
|
|
@@ -7,9 +7,31 @@ export function invocationEnvs(request) {
|
|
|
7
7
|
assertContextEnvs(envs);
|
|
8
8
|
const overrides = request.executionEnvOverrides ?? { env_variables: [] };
|
|
9
9
|
assertContextEnvs(overrides);
|
|
10
|
-
return Object.fromEntries(
|
|
10
|
+
return mergeProcessEnvironment(Object.fromEntries(envs.env_variables.map(({ key, value }) => [key, value])), Object.fromEntries(overrides.env_variables.map(({ key, value }) => [key, value])));
|
|
11
11
|
}
|
|
12
12
|
/** Each invocation owns its environment. Adapter transport settings take precedence. */
|
|
13
13
|
export function invocationEnvironment(request, overrides = {}, inherited = process.env) {
|
|
14
|
-
return
|
|
14
|
+
return mergeProcessEnvironment(inherited, invocationEnvs(request), overrides);
|
|
15
|
+
}
|
|
16
|
+
/** 每层后写覆盖前层;Windows 环境键不区分大小写,保留最终拼写且不修改输入对象。 */
|
|
17
|
+
export function mergeProcessEnvironment(...layers) {
|
|
18
|
+
const entries = new Map();
|
|
19
|
+
for (const layer of layers) {
|
|
20
|
+
for (const [key, value] of Object.entries(layer)) {
|
|
21
|
+
entries.set(process.platform === "win32" ? key.toUpperCase() : key, [key, value]);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return Object.fromEntries(entries.values());
|
|
25
|
+
}
|
|
26
|
+
/** 读取实际进程环境时沿用平台键身份;只读自有属性,Windows 后写别名优先。 */
|
|
27
|
+
export function processEnvironmentValue(env, name) {
|
|
28
|
+
if (process.platform !== "win32")
|
|
29
|
+
return Object.hasOwn(env, name) ? env[name] : undefined;
|
|
30
|
+
const identity = name.toUpperCase();
|
|
31
|
+
let value;
|
|
32
|
+
for (const key of Object.keys(env)) {
|
|
33
|
+
if (key.toUpperCase() === identity)
|
|
34
|
+
value = env[key];
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
15
37
|
}
|
|
@@ -135,12 +135,20 @@ export class HourlyLogWriter {
|
|
|
135
135
|
}
|
|
136
136
|
if (this.#hour() !== hour)
|
|
137
137
|
return false;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
// 在已打开的描述符上验证实际目标;O_NOFOLLOW 拒绝链接,O_NONBLOCK 避免 FIFO 卡住。
|
|
139
|
+
output = openSync(path, constants.O_WRONLY |
|
|
140
|
+
constants.O_CREAT |
|
|
141
|
+
constants.O_APPEND |
|
|
142
|
+
(constants.O_NOFOLLOW ?? 0) |
|
|
143
|
+
(constants.O_NONBLOCK ?? 0), 0o600);
|
|
141
144
|
const stat = fstatSync(output);
|
|
142
145
|
if (!stat.isFile() || stat.nlink !== 1)
|
|
143
146
|
throw new Error("LOG_NOT_REGULAR_FILE");
|
|
147
|
+
if (!constants.O_NOFOLLOW) {
|
|
148
|
+
const entry = lstatSync(path);
|
|
149
|
+
if (!entry.isFile() || entry.dev !== stat.dev || entry.ino !== stat.ino)
|
|
150
|
+
throw new Error("LOG_NOT_REGULAR_FILE");
|
|
151
|
+
}
|
|
144
152
|
if (stat.size + bytes > maximum) {
|
|
145
153
|
this.#fullHour = hour;
|
|
146
154
|
return false;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AdapterInvocationContext } from "./activity.js";
|
|
2
2
|
import { type ReasoningLevelMap } from "./reasoning.js";
|
|
3
3
|
export type { AdapterInvocationContext, ProviderActivity } from "./activity.js";
|
|
4
|
-
export { invocationEnvironment, invocationEnvs } from "./environment.js";
|
|
4
|
+
export { invocationEnvironment, invocationEnvs, mergeProcessEnvironment, processEnvironmentValue } from "./environment.js";
|
|
5
5
|
export { invocationMcpServers, expandMcpValue, assertMcpOptions } from "./mcp.js";
|
|
6
6
|
export { actmodeEvidence } from "./actmode.js";
|
|
7
7
|
import { type CanonicalEvent, type AdapterProtocolSupport, type HostControl, type NativeHostFrame, type InvokeRequest, type StreamLimitPolicy } from "@mininglamp-oss/octo-runtime-protocol";
|
|
@@ -43,7 +43,13 @@ export interface ProbeResult {
|
|
|
43
43
|
export interface Adapter<TOutput extends AdapterOutput = AdapterOutput> {
|
|
44
44
|
metadata: AdapterMetadata;
|
|
45
45
|
probe?: (options?: AdapterProbeOptions) => Promise<ProbeResult>;
|
|
46
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Execute one provider turn, optionally reporting watchdog progress.
|
|
48
|
+
* Iteration may throw on contract rejection (including defineAdapter's protocol/MCP checks).
|
|
49
|
+
* Core rejects unsupported approval/protocol before admission; after admission it converts
|
|
50
|
+
* iteration errors to failure events and independently verifies cleanup. Canonical adapters
|
|
51
|
+
* should yield a failure terminal after confirmed cleanup for expected execution failures.
|
|
52
|
+
*/
|
|
47
53
|
invoke(request: InvokeRequest, context?: AdapterInvocationContext): AsyncIterable<TOutput>;
|
|
48
54
|
}
|
|
49
55
|
/** Provider objects and lifetime signals before the Host assigns stream identity. */
|
|
@@ -63,6 +69,8 @@ export interface CommandSpec {
|
|
|
63
69
|
}
|
|
64
70
|
export interface JsonCliAdapterOptions<TNative> {
|
|
65
71
|
metadata: AdapterMetadata;
|
|
72
|
+
/** 载体没有实际强度 setter 时设为 null,保留请求并返回未应用提示。 */
|
|
73
|
+
reasoningLevels?: ReasoningLevelMap | null;
|
|
66
74
|
buildCommand: (request: InvokeRequest) => CommandSpec | Promise<CommandSpec>;
|
|
67
75
|
normalize: (event: TNative, request: InvokeRequest) => CanonicalEvent[] | undefined;
|
|
68
76
|
probe?: (options?: AdapterProbeOptions) => Promise<ProbeResult>;
|
|
@@ -120,6 +128,7 @@ export declare function createJsonCliAdapter<TNative = Record<string, unknown>>(
|
|
|
120
128
|
* directly; a bare name is searched across `PATH` (`;`-separated on Windows).
|
|
121
129
|
* Returns the first executable match, else `command_not_found`.
|
|
122
130
|
*/
|
|
123
|
-
export declare function probeCommand(command: string, { env }?: {
|
|
131
|
+
export declare function probeCommand(command: string, { env, cwd }?: {
|
|
124
132
|
env?: NodeJS.ProcessEnv;
|
|
133
|
+
cwd?: string;
|
|
125
134
|
}): Promise<ProbeResult>;
|
|
@@ -4,11 +4,11 @@ import { access, stat } from "node:fs/promises";
|
|
|
4
4
|
import { delimiter, isAbsolute, resolve } from "node:path";
|
|
5
5
|
import { createInterface } from "node:readline";
|
|
6
6
|
import { promisify } from "node:util";
|
|
7
|
-
import { invocationEnvironment } from "./environment.js";
|
|
7
|
+
import { invocationEnvironment, mergeProcessEnvironment, processEnvironmentValue } from "./environment.js";
|
|
8
8
|
import { createProcessCleanup } from "./process-cleanup.js";
|
|
9
9
|
import { watchLineLimit } from "./line-limit.js";
|
|
10
10
|
import { mapReasoningEffort, reasoningLevelMap } from "./reasoning.js";
|
|
11
|
-
export { invocationEnvironment, invocationEnvs } from "./environment.js";
|
|
11
|
+
export { invocationEnvironment, invocationEnvs, mergeProcessEnvironment, processEnvironmentValue } from "./environment.js";
|
|
12
12
|
export { invocationMcpServers, expandMcpValue, assertMcpOptions } from "./mcp.js";
|
|
13
13
|
export { actmodeEvidence } from "./actmode.js";
|
|
14
14
|
import { DEFAULT_STREAM_LIMIT_POLICY, isTerminal, assertProtocolSupport } from "@mininglamp-oss/octo-runtime-protocol";
|
|
@@ -90,7 +90,7 @@ export async function* spawnJsonLines(options) {
|
|
|
90
90
|
const { command, args = [], cwd, env, input, signal, parseLine, onInputWritten } = options;
|
|
91
91
|
const child = spawn(command, args, {
|
|
92
92
|
cwd,
|
|
93
|
-
env:
|
|
93
|
+
env: mergeProcessEnvironment(process.env, env ?? {}),
|
|
94
94
|
stdio: ["pipe", "pipe", "pipe"],
|
|
95
95
|
detached: process.platform !== "win32"
|
|
96
96
|
});
|
|
@@ -120,6 +120,16 @@ export async function* spawnJsonLines(options) {
|
|
|
120
120
|
// would incorrectly classify a synchronous write failure as dispatched.
|
|
121
121
|
let controlError;
|
|
122
122
|
const reader = createInterface({ input: child.stdout });
|
|
123
|
+
// Windows 启动失败可同时产生子进程 ENOENT 与输出管道 ENOTCONN。
|
|
124
|
+
// 管道及 readline 错误只结束本次调用;监听保留到句柄关闭,防止清理期间迟到 error 逃逸。
|
|
125
|
+
const outputError = (error) => {
|
|
126
|
+
controlError ??= error;
|
|
127
|
+
reader.close();
|
|
128
|
+
abort();
|
|
129
|
+
};
|
|
130
|
+
child.stdout.on("error", outputError);
|
|
131
|
+
child.stderr.on("error", outputError);
|
|
132
|
+
reader.on("error", outputError);
|
|
123
133
|
const removeLineGuard = watchLineLimit(child.stdout, options.rawMessageMaxBytes ?? DEFAULT_STREAM_LIMIT_POLICY.rawMessageMaxBytes, (error) => {
|
|
124
134
|
Object.assign(error, { boundary: "provider.stdout" });
|
|
125
135
|
controlError ??= error;
|
|
@@ -170,7 +180,15 @@ export async function* spawnJsonLines(options) {
|
|
|
170
180
|
removeLineGuard();
|
|
171
181
|
signal?.removeEventListener("abort", abort);
|
|
172
182
|
// 正常 EOF 也要回收继承进程组、但已关闭 stdio 的后台后代。
|
|
173
|
-
|
|
183
|
+
try {
|
|
184
|
+
await cleanup();
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
// 释放本次调用的所有管道;destroy 不是进程退出证明,cleanup 失败仍向调用方传播。
|
|
188
|
+
child.stdin.destroy();
|
|
189
|
+
child.stdout.destroy();
|
|
190
|
+
child.stderr.destroy();
|
|
191
|
+
}
|
|
174
192
|
}
|
|
175
193
|
}
|
|
176
194
|
/** Raised when a provider subprocess exits non-zero; carries the exit code/signal alongside the captured stderr message. */
|
|
@@ -244,19 +262,22 @@ export function createJsonCliAdapter(options) {
|
|
|
244
262
|
await spec.cleanup?.();
|
|
245
263
|
}
|
|
246
264
|
}
|
|
247
|
-
});
|
|
265
|
+
}, options.reasoningLevels);
|
|
248
266
|
}
|
|
249
267
|
/**
|
|
250
268
|
* Resolve whether a command is runnable. A path-qualified command is checked
|
|
251
269
|
* directly; a bare name is searched across `PATH` (`;`-separated on Windows).
|
|
252
270
|
* Returns the first executable match, else `command_not_found`.
|
|
253
271
|
*/
|
|
254
|
-
export async function probeCommand(command, { env = process.env } = {}) {
|
|
272
|
+
export async function probeCommand(command, { env = process.env, cwd } = {}) {
|
|
255
273
|
const candidates = isAbsolute(command) || command.includes("/") || command.includes("\\")
|
|
256
274
|
? [command]
|
|
257
|
-
: (env
|
|
275
|
+
: (processEnvironmentValue(env, "PATH") ?? "").split(delimiter).flatMap((directory) => {
|
|
258
276
|
const extensions = process.platform === "win32" && !/\.[^\\/]+$/.test(command)
|
|
259
|
-
? [
|
|
277
|
+
? [
|
|
278
|
+
"",
|
|
279
|
+
...(processEnvironmentValue(env, "PATHEXT") ?? ".EXE;.CMD;.BAT;.COM").split(";")
|
|
280
|
+
]
|
|
260
281
|
: [""];
|
|
261
282
|
return extensions.map((extension) => resolve(directory, command + extension));
|
|
262
283
|
});
|
|
@@ -269,6 +290,7 @@ export async function probeCommand(command, { env = process.env } = {}) {
|
|
|
269
290
|
try {
|
|
270
291
|
const { stdout } = await promisify(execFile)(resolve(candidate), ["--version"], {
|
|
271
292
|
env,
|
|
293
|
+
cwd,
|
|
272
294
|
timeout: 2_000,
|
|
273
295
|
maxBuffer: 4096,
|
|
274
296
|
windowsHide: true
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { assertContextMcp, assertMcpServers, contextItem } from "@mininglamp-oss/octo-runtime-protocol";
|
|
2
|
-
import { invocationEnvironment } from "./environment.js";
|
|
2
|
+
import { invocationEnvironment, processEnvironmentValue } from "./environment.js";
|
|
3
3
|
/** Only configuration strings expand. Replacement values are never scanned again. */
|
|
4
4
|
export function expandMcpValue(value, env, path) {
|
|
5
5
|
return value.replace(/\$\$?\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (match, name) => {
|
|
6
6
|
if (match.startsWith("$$"))
|
|
7
7
|
return match.slice(1);
|
|
8
|
-
|
|
8
|
+
const replacement = processEnvironmentValue(env, name);
|
|
9
|
+
if (replacement === undefined)
|
|
9
10
|
throw new Error(`MCP_ENV_MISSING: ${path}: ${name}`);
|
|
10
|
-
return
|
|
11
|
+
return replacement;
|
|
11
12
|
});
|
|
12
13
|
}
|
|
13
14
|
export function invocationMcpServers(request, env = invocationEnvironment(request)) {
|