@ycodium-ai/agent-opencode 0.2.2706 → 0.2.2743
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/dist/index.js +181 -23
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1772,7 +1772,6 @@ import {
|
|
|
1772
1772
|
} from "@ycodium-ai/plugin-api/executor";
|
|
1773
1773
|
|
|
1774
1774
|
// src/server.ts
|
|
1775
|
-
import * as NodeNet from "node:net";
|
|
1776
1775
|
import * as NodeOS4 from "node:os";
|
|
1777
1776
|
|
|
1778
1777
|
// ../../node_modules/.pnpm/@opencode-ai+sdk@1.18.31/node_modules/@opencode-ai/sdk/dist/v2/gen/core/serverSentEvents.gen.js
|
|
@@ -7184,6 +7183,129 @@ import {
|
|
|
7184
7183
|
mergeLaunchEnv as mergeLaunchEnv2
|
|
7185
7184
|
} from "@ycodium-ai/plugin-api/executor";
|
|
7186
7185
|
|
|
7186
|
+
// ../../packages/ycodium-fetch-ports/src/fetchPorts.ts
|
|
7187
|
+
import * as NodeNet from "node:net";
|
|
7188
|
+
var FETCH_BLOCKED_PORTS = /* @__PURE__ */ new Set([
|
|
7189
|
+
1,
|
|
7190
|
+
7,
|
|
7191
|
+
9,
|
|
7192
|
+
11,
|
|
7193
|
+
13,
|
|
7194
|
+
15,
|
|
7195
|
+
17,
|
|
7196
|
+
19,
|
|
7197
|
+
20,
|
|
7198
|
+
21,
|
|
7199
|
+
22,
|
|
7200
|
+
23,
|
|
7201
|
+
25,
|
|
7202
|
+
37,
|
|
7203
|
+
42,
|
|
7204
|
+
43,
|
|
7205
|
+
53,
|
|
7206
|
+
69,
|
|
7207
|
+
77,
|
|
7208
|
+
79,
|
|
7209
|
+
87,
|
|
7210
|
+
95,
|
|
7211
|
+
101,
|
|
7212
|
+
102,
|
|
7213
|
+
103,
|
|
7214
|
+
104,
|
|
7215
|
+
109,
|
|
7216
|
+
110,
|
|
7217
|
+
111,
|
|
7218
|
+
113,
|
|
7219
|
+
115,
|
|
7220
|
+
117,
|
|
7221
|
+
119,
|
|
7222
|
+
123,
|
|
7223
|
+
135,
|
|
7224
|
+
137,
|
|
7225
|
+
139,
|
|
7226
|
+
143,
|
|
7227
|
+
161,
|
|
7228
|
+
179,
|
|
7229
|
+
389,
|
|
7230
|
+
427,
|
|
7231
|
+
465,
|
|
7232
|
+
512,
|
|
7233
|
+
513,
|
|
7234
|
+
514,
|
|
7235
|
+
515,
|
|
7236
|
+
526,
|
|
7237
|
+
530,
|
|
7238
|
+
531,
|
|
7239
|
+
532,
|
|
7240
|
+
540,
|
|
7241
|
+
548,
|
|
7242
|
+
554,
|
|
7243
|
+
556,
|
|
7244
|
+
563,
|
|
7245
|
+
587,
|
|
7246
|
+
601,
|
|
7247
|
+
636,
|
|
7248
|
+
989,
|
|
7249
|
+
990,
|
|
7250
|
+
993,
|
|
7251
|
+
995,
|
|
7252
|
+
1719,
|
|
7253
|
+
1720,
|
|
7254
|
+
1723,
|
|
7255
|
+
2049,
|
|
7256
|
+
3659,
|
|
7257
|
+
4045,
|
|
7258
|
+
4190,
|
|
7259
|
+
5060,
|
|
7260
|
+
5061,
|
|
7261
|
+
6e3,
|
|
7262
|
+
6566,
|
|
7263
|
+
6665,
|
|
7264
|
+
6666,
|
|
7265
|
+
6667,
|
|
7266
|
+
6668,
|
|
7267
|
+
6669,
|
|
7268
|
+
6679,
|
|
7269
|
+
6697,
|
|
7270
|
+
10080
|
|
7271
|
+
]);
|
|
7272
|
+
var isFetchSafePort = (port) => !FETCH_BLOCKED_PORTS.has(port);
|
|
7273
|
+
var MAX_SAFE_PORT_ATTEMPTS = 50;
|
|
7274
|
+
var systemAssigned = () => 0;
|
|
7275
|
+
var listenOnce = (server, host, port) => new Promise((resolve2, reject) => {
|
|
7276
|
+
server.once("error", reject);
|
|
7277
|
+
server.listen(port, host, () => {
|
|
7278
|
+
server.off("error", reject);
|
|
7279
|
+
const address = server.address();
|
|
7280
|
+
resolve2(typeof address === "object" && address !== null ? address.port : 0);
|
|
7281
|
+
});
|
|
7282
|
+
});
|
|
7283
|
+
var listenOnSafePort = async (server, options = {}) => {
|
|
7284
|
+
const host = options.host ?? "127.0.0.1";
|
|
7285
|
+
const portForAttempt = options.portForAttempt ?? systemAssigned;
|
|
7286
|
+
for (let attempt = 0; attempt < MAX_SAFE_PORT_ATTEMPTS; attempt++) {
|
|
7287
|
+
const port = await listenOnce(server, host, portForAttempt(attempt));
|
|
7288
|
+
if (isFetchSafePort(port)) return port;
|
|
7289
|
+
await new Promise((resolve2) => server.close(() => resolve2()));
|
|
7290
|
+
}
|
|
7291
|
+
throw new Error(`\u8FDE\u7EED ${String(MAX_SAFE_PORT_ATTEMPTS)} \u6B21\u5206\u5230 fetch \u7684\u574F\u7AEF\u53E3`);
|
|
7292
|
+
};
|
|
7293
|
+
var reserveFetchSafePort = async (options = {}) => {
|
|
7294
|
+
const probe = NodeNet.createServer();
|
|
7295
|
+
try {
|
|
7296
|
+
const port = await listenOnSafePort(probe, options);
|
|
7297
|
+
await new Promise((resolve2) => probe.close(() => resolve2()));
|
|
7298
|
+
if (port <= 0) throw new Error("\u65E0\u6CD5\u53D6\u5F97\u76D1\u542C\u7AEF\u53E3");
|
|
7299
|
+
return port;
|
|
7300
|
+
} catch (cause) {
|
|
7301
|
+
try {
|
|
7302
|
+
probe.close();
|
|
7303
|
+
} catch {
|
|
7304
|
+
}
|
|
7305
|
+
throw cause;
|
|
7306
|
+
}
|
|
7307
|
+
};
|
|
7308
|
+
|
|
7187
7309
|
// src/cliParse.ts
|
|
7188
7310
|
var DEFAULT_OPENCODE_SERVER_TIMEOUT_MS = 3e4;
|
|
7189
7311
|
var DEFAULT_HOSTNAME = "127.0.0.1";
|
|
@@ -7315,26 +7437,6 @@ async function collectText(stream, maxBytes = Number.POSITIVE_INFINITY) {
|
|
|
7315
7437
|
}
|
|
7316
7438
|
return Buffer.concat(chunks).toString("utf8");
|
|
7317
7439
|
}
|
|
7318
|
-
async function findAvailablePort() {
|
|
7319
|
-
return await new Promise((resolve2, reject) => {
|
|
7320
|
-
const server = NodeNet.createServer();
|
|
7321
|
-
server.once("error", reject);
|
|
7322
|
-
server.listen(0, "127.0.0.1", () => {
|
|
7323
|
-
const address = server.address();
|
|
7324
|
-
server.close((error) => {
|
|
7325
|
-
if (error) {
|
|
7326
|
-
reject(error);
|
|
7327
|
-
return;
|
|
7328
|
-
}
|
|
7329
|
-
if (address === null || typeof address === "string") {
|
|
7330
|
-
reject(new Error("OpenCode could not allocate a local port."));
|
|
7331
|
-
return;
|
|
7332
|
-
}
|
|
7333
|
-
resolve2(address.port);
|
|
7334
|
-
});
|
|
7335
|
-
});
|
|
7336
|
-
});
|
|
7337
|
-
}
|
|
7338
7440
|
function buildSpawnEnv(recipe) {
|
|
7339
7441
|
const xdgHome = makeOpenCodeEnvironment(recipe.homePath, {});
|
|
7340
7442
|
return mergeLaunchEnv2({
|
|
@@ -7372,7 +7474,7 @@ async function terminateOwnedProcess(handle) {
|
|
|
7372
7474
|
}
|
|
7373
7475
|
}
|
|
7374
7476
|
async function spawnOpenCodeServer(input) {
|
|
7375
|
-
const port = await
|
|
7477
|
+
const port = await reserveFetchSafePort();
|
|
7376
7478
|
const hostname = DEFAULT_HOSTNAME;
|
|
7377
7479
|
const env = buildSpawnEnv(input.recipe);
|
|
7378
7480
|
const spawned = await input.host.process.spawn({
|
|
@@ -7815,6 +7917,57 @@ ${result.stderr}`);
|
|
|
7815
7917
|
}
|
|
7816
7918
|
}
|
|
7817
7919
|
|
|
7920
|
+
// src/mcpServers.ts
|
|
7921
|
+
function toOpenCodeMcpConfig(server) {
|
|
7922
|
+
const transport = server.transport;
|
|
7923
|
+
if (transport.type === "stdio") {
|
|
7924
|
+
return {
|
|
7925
|
+
type: "local",
|
|
7926
|
+
command: [transport.command, ...transport.args ?? []],
|
|
7927
|
+
...transport.env ? { environment: { ...transport.env } } : {}
|
|
7928
|
+
};
|
|
7929
|
+
}
|
|
7930
|
+
return {
|
|
7931
|
+
type: "remote",
|
|
7932
|
+
url: transport.url,
|
|
7933
|
+
...transport.headers ? { headers: { ...transport.headers } } : {},
|
|
7934
|
+
// 带着宿主给的凭据,别让 OpenCode 碰到 401 就去走 OAuth 发现。
|
|
7935
|
+
oauth: false
|
|
7936
|
+
};
|
|
7937
|
+
}
|
|
7938
|
+
function failureSummary(cause) {
|
|
7939
|
+
if (cause instanceof Error) return { error: cause.name, message: cause.message };
|
|
7940
|
+
if (cause !== null && typeof cause === "object") {
|
|
7941
|
+
const record = cause;
|
|
7942
|
+
return {
|
|
7943
|
+
error: typeof record.name === "string" ? record.name : "unknown",
|
|
7944
|
+
...typeof record.status === "number" ? { status: record.status } : {}
|
|
7945
|
+
};
|
|
7946
|
+
}
|
|
7947
|
+
return { error: typeof cause };
|
|
7948
|
+
}
|
|
7949
|
+
async function addOpenCodeMcpServers(input) {
|
|
7950
|
+
for (const server of input.servers ?? []) {
|
|
7951
|
+
let failure;
|
|
7952
|
+
try {
|
|
7953
|
+
const added = await input.client.mcp.add({
|
|
7954
|
+
name: server.name,
|
|
7955
|
+
config: toOpenCodeMcpConfig(server)
|
|
7956
|
+
});
|
|
7957
|
+
const status = added.data?.[server.name]?.status;
|
|
7958
|
+
if (status !== "connected") failure = status === void 0 ? {} : { status };
|
|
7959
|
+
} catch (cause) {
|
|
7960
|
+
failure = failureSummary(cause);
|
|
7961
|
+
}
|
|
7962
|
+
if (failure === void 0) continue;
|
|
7963
|
+
input.log.warn("OpenCode could not attach an MCP server; the session continues without it.", {
|
|
7964
|
+
name: server.name,
|
|
7965
|
+
transport: server.transport.type,
|
|
7966
|
+
...failure
|
|
7967
|
+
});
|
|
7968
|
+
}
|
|
7969
|
+
}
|
|
7970
|
+
|
|
7818
7971
|
// src/workspaceInventory.ts
|
|
7819
7972
|
import * as NodePath5 from "node:path";
|
|
7820
7973
|
var isInside = (directory, file) => {
|
|
@@ -9543,6 +9696,11 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9543
9696
|
if (server.external) {
|
|
9544
9697
|
const tooOld = openCodeTooOldDetail(await readOpenCodeServerVersion(client2));
|
|
9545
9698
|
if (tooOld) throw new Error(tooOld);
|
|
9699
|
+
if ((input.mcpServers?.length ?? 0) > 0) {
|
|
9700
|
+
host.log.info("OpenCode runs on an external server; Ycodium does not add MCP servers.");
|
|
9701
|
+
}
|
|
9702
|
+
} else {
|
|
9703
|
+
await addOpenCodeMcpServers({ client: client2, servers: input.mcpServers, log: host.log });
|
|
9546
9704
|
}
|
|
9547
9705
|
const nativeModeId = openCodeNativeModeFor(input.runtimeMode, input.nativeModeId);
|
|
9548
9706
|
const permission = openCodePermissionRulesForNativeMode(
|
|
@@ -9910,7 +10068,7 @@ var executors = [
|
|
|
9910
10068
|
];
|
|
9911
10069
|
var index_default = definePlugin({
|
|
9912
10070
|
id: "agent-opencode",
|
|
9913
|
-
apiVersion:
|
|
10071
|
+
apiVersion: 3,
|
|
9914
10072
|
executors,
|
|
9915
10073
|
activate(ctx) {
|
|
9916
10074
|
capturedAttachments = ctx.attachments;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-opencode",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2743",
|
|
4
4
|
"description": "OpenCode executor: OpenCode CLI via @opencode-ai/sdk/v2.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"@types/node": "24.12.4",
|
|
25
25
|
"esbuild": "0.28.1",
|
|
26
26
|
"vite-plus": "0.2.2",
|
|
27
|
-
"
|
|
27
|
+
"ycodium-fetch-ports": "0.0.0",
|
|
28
|
+
"@ycodium-ai/plugin-api": "0.2.2743",
|
|
28
29
|
"ycodium-executor-testing": "0.0.0"
|
|
29
30
|
},
|
|
30
31
|
"ycodium": {
|