@ycodium-ai/agent-opencode 0.2.2169 → 0.2.2510
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 +169 -87
- package/locales/en.json +24 -0
- package/locales/zh-CN.json +24 -0
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -538,7 +538,6 @@ import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
|
538
538
|
|
|
539
539
|
// src/card.ts
|
|
540
540
|
var OPENCODE_DRIVER_KIND = "opencode";
|
|
541
|
-
var OPENCODE_BINDING_PROVIDER_ID = "ycodium";
|
|
542
541
|
var OPENCODE_CARD = {
|
|
543
542
|
driverKind: OPENCODE_DRIVER_KIND,
|
|
544
543
|
displayName: "OpenCode",
|
|
@@ -565,9 +564,6 @@ var OPENCODE_CARD = {
|
|
|
565
564
|
defaultTextGenerationModel: "openai/gpt-5",
|
|
566
565
|
customModelIdExample: "openai/gpt-5",
|
|
567
566
|
modelSlugAliases: {},
|
|
568
|
-
modelsDevProviderIds: [],
|
|
569
|
-
modelsDevSlugPrefixed: true,
|
|
570
|
-
modelSlugPrefix: "",
|
|
571
567
|
mcpTransports: ["stdio", "http"],
|
|
572
568
|
pluginManaged: true,
|
|
573
569
|
verifiedSkills: true,
|
|
@@ -586,14 +582,47 @@ var OPENCODE_CARD = {
|
|
|
586
582
|
// OpenCode 凭据由 CLI 自己管在 XDG 目录,probe 从已连接 provider 推断,不读 auth.json。
|
|
587
583
|
credentialSources: [],
|
|
588
584
|
diagnostics: [],
|
|
585
|
+
// 设置表单照这份画:带 x-ycodium-form 的属性才进表单(enabled、customModels 等另有入口,不在此列),
|
|
586
|
+
// 顺序看 x-ycodium-form-order;文案键在本插件 locales/<locale>.json 里解析,宿主不兜底。
|
|
589
587
|
configSchema: {
|
|
590
588
|
type: "object",
|
|
589
|
+
"x-ycodium-form-order": ["binaryPath", "serverUrl", "serverPassword", "homePath"],
|
|
591
590
|
properties: {
|
|
592
591
|
enabled: { type: "boolean" },
|
|
593
|
-
binaryPath: {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
592
|
+
binaryPath: {
|
|
593
|
+
type: "string",
|
|
594
|
+
"x-ycodium-form": {
|
|
595
|
+
titleKey: "form.binaryPath.title",
|
|
596
|
+
descriptionKey: "form.binaryPath.description",
|
|
597
|
+
placeholderKey: "form.binaryPath.placeholder",
|
|
598
|
+
control: "executable-path"
|
|
599
|
+
}
|
|
600
|
+
},
|
|
601
|
+
serverUrl: {
|
|
602
|
+
type: "string",
|
|
603
|
+
"x-ycodium-form": {
|
|
604
|
+
titleKey: "form.serverUrl.title",
|
|
605
|
+
descriptionKey: "form.serverUrl.description",
|
|
606
|
+
placeholderKey: "form.serverUrl.placeholder"
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
serverPassword: {
|
|
610
|
+
type: "string",
|
|
611
|
+
"x-ycodium-form": {
|
|
612
|
+
titleKey: "form.serverPassword.title",
|
|
613
|
+
descriptionKey: "form.serverPassword.description",
|
|
614
|
+
placeholderKey: "form.serverPassword.placeholder",
|
|
615
|
+
control: "password"
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
homePath: {
|
|
619
|
+
type: "string",
|
|
620
|
+
"x-ycodium-form": {
|
|
621
|
+
titleKey: "form.homePath.title",
|
|
622
|
+
descriptionKey: "form.homePath.description",
|
|
623
|
+
placeholderKey: "form.homePath.placeholder"
|
|
624
|
+
}
|
|
625
|
+
},
|
|
597
626
|
customModels: { type: "array" },
|
|
598
627
|
driver: { type: "string" },
|
|
599
628
|
config: { type: "object" },
|
|
@@ -602,29 +631,26 @@ var OPENCODE_CARD = {
|
|
|
602
631
|
additionalProperties: true
|
|
603
632
|
},
|
|
604
633
|
modelConnectivity: {
|
|
605
|
-
//
|
|
606
|
-
// `/chat/completions
|
|
607
|
-
// 不算——投递不换这一栏。别家的脑经宿主翻译接上;打到别的路由的请求,本机端点按那一笔
|
|
608
|
-
// 的路径另挑翻译对。
|
|
634
|
+
// 只报下面那段配置说的格式:它把 `npm` 定死成 openai-compatible,后缀是
|
|
635
|
+
// `/chat/completions`,请求说 chat。换 `@ai-sdk/anthropic` 能说 messages 不算。
|
|
609
636
|
dialects: ["openai-chat-completions"],
|
|
610
637
|
acceptsExternalEndpoints: true,
|
|
611
638
|
supportsNativeSubscription: true,
|
|
612
639
|
// opencode 不认「地址一个变量、凭据一个变量」——它读的是
|
|
613
|
-
// `provider.<id>.options.{baseURL,apiKey}
|
|
640
|
+
// `provider.<id>.options.{baseURL,apiKey}`,而给这份配置最干净的路是
|
|
614
641
|
// `OPENCODE_CONFIG_CONTENT`(内联 JSON,压过磁盘上的全局与项目配置)。插件本来就在
|
|
615
|
-
// 设这个变量(`cliParse.ts` 的 `resolveOpenCodeConfigContent`),默认 `{}
|
|
642
|
+
// 设这个变量(`cliParse.ts` 的 `resolveOpenCodeConfigContent`),默认 `{}`,
|
|
643
|
+
// 机器环境里已有的值不覆盖。
|
|
616
644
|
//
|
|
617
645
|
// `npm: "@ai-sdk/openai-compatible"` 定死它说 chat-completions;换成
|
|
618
|
-
// `@ai-sdk/anthropic` 就是 messages——那时后缀与 `dialects`
|
|
619
|
-
// 认手说的方言,兼容判定据此挑直通还是翻译。
|
|
646
|
+
// `@ai-sdk/anthropic` 就是 messages——那时后缀与 `dialects` 要跟着一起换。
|
|
620
647
|
//
|
|
621
|
-
// **还有三层压在这个变量之上**:org 远程配置、`/etc/opencode/`、macOS MDM
|
|
622
|
-
// 代理时宿主会 logWarning(`provider.proxy.never-reached`)。
|
|
648
|
+
// **还有三层压在这个变量之上**:org 远程配置、`/etc/opencode/`、macOS MDM。
|
|
623
649
|
nativePathSuffix: "/chat/completions",
|
|
624
650
|
extraEnv: [
|
|
625
651
|
{
|
|
626
652
|
name: "OPENCODE_CONFIG_CONTENT",
|
|
627
|
-
value:
|
|
653
|
+
value: '{"provider":{"ycodium":{"npm":"@ai-sdk/openai-compatible","name":"Ycodium","options":{"baseURL":"$baseUrl","apiKey":"$credential"},"models":{"$model":{"name":"$model"}}}},"model":"ycodium/$model"}'
|
|
628
654
|
}
|
|
629
655
|
]
|
|
630
656
|
}
|
|
@@ -1194,7 +1220,7 @@ function isOpenCodeDefaultTitle(title) {
|
|
|
1194
1220
|
return OPENCODE_DEFAULT_TITLE_PATTERN.test(title);
|
|
1195
1221
|
}
|
|
1196
1222
|
function parseGenericCliVersion(output) {
|
|
1197
|
-
const match = output.match(/\
|
|
1223
|
+
const match = output.match(/\bv?(\d+\.\d+\.\d+)\b/);
|
|
1198
1224
|
return match?.[1] ?? null;
|
|
1199
1225
|
}
|
|
1200
1226
|
function compareSemverVersions(left, right) {
|
|
@@ -1263,12 +1289,6 @@ function modelIdFromSelection(selection) {
|
|
|
1263
1289
|
return typeof model === "string" ? model.trim() || void 0 : void 0;
|
|
1264
1290
|
}
|
|
1265
1291
|
function chooseOpenCodeModel(input) {
|
|
1266
|
-
if (input.boundModelId !== void 0) {
|
|
1267
|
-
const bound = input.match(input.requested, [
|
|
1268
|
-
`${OPENCODE_BINDING_PROVIDER_ID}/${input.boundModelId}`
|
|
1269
|
-
]);
|
|
1270
|
-
return parseOpenCodeModelSlug(bound) ?? void 0;
|
|
1271
|
-
}
|
|
1272
1292
|
const own = parseOpenCodeModelSlug(input.requested);
|
|
1273
1293
|
if (own) return own;
|
|
1274
1294
|
input.match(input.requested, []);
|
|
@@ -1375,6 +1395,22 @@ function openCodeProbeModels(inventory) {
|
|
|
1375
1395
|
...model.capabilities.optionDescriptors.length > 0 ? { capabilities: model.capabilities } : {}
|
|
1376
1396
|
}));
|
|
1377
1397
|
}
|
|
1398
|
+
function flattenOpenCodeSkills(skills) {
|
|
1399
|
+
const flattened = [];
|
|
1400
|
+
for (const skill of skills ?? []) {
|
|
1401
|
+
const name = nonEmptyTrimmed(skill.name);
|
|
1402
|
+
const path = nonEmptyTrimmed(skill.location);
|
|
1403
|
+
if (!name || !path) continue;
|
|
1404
|
+
const description = nonEmptyTrimmed(skill.description);
|
|
1405
|
+
flattened.push({
|
|
1406
|
+
name,
|
|
1407
|
+
path,
|
|
1408
|
+
enabled: true,
|
|
1409
|
+
...description ? { description, shortDescription: description } : {}
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
return flattened.toSorted((left, right) => left.name.localeCompare(right.name));
|
|
1413
|
+
}
|
|
1378
1414
|
function formatOpenCodeProbeError(input) {
|
|
1379
1415
|
const raw = toMessage(input.cause, String(input.cause));
|
|
1380
1416
|
const detail = hideGenericEffectText(raw);
|
|
@@ -1439,14 +1475,47 @@ function isOpenCodeNativeModeId(value) {
|
|
|
1439
1475
|
function openCodeNativeModeFor(runtimeMode, nativeModeId) {
|
|
1440
1476
|
return nativeModeId !== void 0 && isOpenCodeNativeModeId(nativeModeId) ? nativeModeId : OPENCODE_NATIVE_MODE_BY_RUNTIME_MODE[runtimeMode];
|
|
1441
1477
|
}
|
|
1442
|
-
function openCodePermissionRulesForNativeMode(nativeModeId) {
|
|
1478
|
+
function openCodePermissionRulesForNativeMode(nativeModeId, readOnlyDirectories) {
|
|
1443
1479
|
if (nativeModeId === "allow-all") {
|
|
1444
1480
|
return buildOpenCodePermissionRules("full-access");
|
|
1445
1481
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1482
|
+
const base = buildOpenCodePermissionRules(
|
|
1483
|
+
nativeModeId === "accept-edits" ? "auto-accept-edits" : "approval-required"
|
|
1484
|
+
);
|
|
1485
|
+
const readOnly = openCodeReadOnlyDirectoryRules(readOnlyDirectories);
|
|
1486
|
+
return readOnly.length === 0 ? base : [...base, ...readOnly];
|
|
1487
|
+
}
|
|
1488
|
+
function openCodeReadOnlyDirectoryRules(directories) {
|
|
1489
|
+
const rules = [];
|
|
1490
|
+
for (const directory of directories ?? []) {
|
|
1491
|
+
const patterns = openCodeDirectoryPatterns(directory);
|
|
1492
|
+
if (patterns === void 0) continue;
|
|
1493
|
+
rules.push({ permission: "external_directory", pattern: patterns.absolute, action: "allow" });
|
|
1494
|
+
rules.push({ permission: "read", pattern: patterns.absolute, action: "allow" });
|
|
1495
|
+
rules.push({ permission: "edit", pattern: patterns.absolute, action: "ask" });
|
|
1496
|
+
for (const suffix of patterns.suffixes) {
|
|
1497
|
+
rules.push({ permission: "read", pattern: suffix, action: "allow" });
|
|
1498
|
+
rules.push({ permission: "edit", pattern: suffix, action: "ask" });
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
return rules;
|
|
1502
|
+
}
|
|
1503
|
+
function openCodeDirectoryPatterns(directory) {
|
|
1504
|
+
const trimmed = directory.trim();
|
|
1505
|
+
if (/[*?]/.test(trimmed)) return void 0;
|
|
1506
|
+
const isWindowsPath = /^[A-Za-z]:[\\/]/.test(trimmed) || trimmed.startsWith("\\\\");
|
|
1507
|
+
const isPosixPath = /^\/[^/]/.test(trimmed);
|
|
1508
|
+
if (!isWindowsPath && !isPosixPath) return void 0;
|
|
1509
|
+
const separatorPattern = isWindowsPath ? /[\\/]+/ : /\/+/;
|
|
1510
|
+
const separator = isWindowsPath && trimmed.includes("\\") ? "\\" : "/";
|
|
1511
|
+
const segments = trimmed.split(separatorPattern).filter((segment) => segment !== "");
|
|
1512
|
+
const absolute = `${trimmed.replace(new RegExp(`${separatorPattern.source}$`), "")}${separator}*`;
|
|
1513
|
+
const tail = segments.slice(-2);
|
|
1514
|
+
const suffixSeparators = isWindowsPath ? ["/", "\\"] : ["/"];
|
|
1515
|
+
return {
|
|
1516
|
+
absolute,
|
|
1517
|
+
suffixes: tail.length === 2 ? suffixSeparators.map((sep) => `*${tail.join(sep)}${sep}*`) : []
|
|
1518
|
+
};
|
|
1450
1519
|
}
|
|
1451
1520
|
function buildOpenCodePermissionRules(runtimeMode) {
|
|
1452
1521
|
if (runtimeMode === "full-access") {
|
|
@@ -1532,6 +1601,7 @@ function mapPermissionDecision(reply) {
|
|
|
1532
1601
|
}
|
|
1533
1602
|
|
|
1534
1603
|
// src/probe.ts
|
|
1604
|
+
import * as NodeOS4 from "node:os";
|
|
1535
1605
|
import {
|
|
1536
1606
|
ExecutorSpawnRefusedError as ExecutorSpawnRefusedError2
|
|
1537
1607
|
} from "@ycodium-ai/plugin-api/executor";
|
|
@@ -6946,12 +7016,10 @@ var import_cross_spawn = __toESM(require_cross_spawn(), 1);
|
|
|
6946
7016
|
// src/server.ts
|
|
6947
7017
|
import {
|
|
6948
7018
|
ExecutorSpawnRefusedError,
|
|
6949
|
-
mergeLaunchEnv
|
|
6950
|
-
brainSlotEnvKeys
|
|
7019
|
+
mergeLaunchEnv
|
|
6951
7020
|
} from "@ycodium-ai/plugin-api/executor";
|
|
6952
7021
|
|
|
6953
7022
|
// src/cliParse.ts
|
|
6954
|
-
var OPENCODE_SERVER_READY_PREFIX = "opencode server listening";
|
|
6955
7023
|
var DEFAULT_OPENCODE_SERVER_TIMEOUT_MS = 3e4;
|
|
6956
7024
|
var DEFAULT_HOSTNAME = "127.0.0.1";
|
|
6957
7025
|
var OPENCODE_SKILL_DISCOVERY_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
|
|
@@ -6959,16 +7027,13 @@ var OPENCODE_EMPTY_CONFIG_CONTENT = "{}";
|
|
|
6959
7027
|
var SLUG_LINE_RE = /^(\S+\/\S+)\s*$/;
|
|
6960
7028
|
var AGENT_HEADER_RE = /^(.+)\s+\((\S+)\)\s*$/;
|
|
6961
7029
|
var KNOWN_HIDDEN_AGENTS = /* @__PURE__ */ new Set(["compaction", "summary", "title"]);
|
|
6962
|
-
function resolveOpenCodeConfigContent(
|
|
6963
|
-
return
|
|
7030
|
+
function resolveOpenCodeConfigContent(inheritedEnvironment) {
|
|
7031
|
+
return inheritedEnvironment.OPENCODE_CONFIG_CONTENT ?? OPENCODE_EMPTY_CONFIG_CONTENT;
|
|
6964
7032
|
}
|
|
6965
7033
|
function parseServerUrlFromOutput(output) {
|
|
6966
7034
|
for (const line of output.split("\n")) {
|
|
6967
|
-
|
|
6968
|
-
|
|
6969
|
-
}
|
|
6970
|
-
const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
|
|
6971
|
-
return match?.[1] ?? null;
|
|
7035
|
+
const match = line.match(/server listening on\s+(https?:\/\/[^\s]+)/i);
|
|
7036
|
+
if (match?.[1]) return match[1];
|
|
6972
7037
|
}
|
|
6973
7038
|
return null;
|
|
6974
7039
|
}
|
|
@@ -7105,19 +7170,14 @@ async function findAvailablePort() {
|
|
|
7105
7170
|
});
|
|
7106
7171
|
});
|
|
7107
7172
|
}
|
|
7108
|
-
function buildSpawnEnv(
|
|
7109
|
-
const xdgHome = makeOpenCodeEnvironment(
|
|
7173
|
+
function buildSpawnEnv(recipe) {
|
|
7174
|
+
const xdgHome = makeOpenCodeEnvironment(recipe.homePath, {});
|
|
7110
7175
|
return mergeLaunchEnv({
|
|
7111
|
-
brainSlots: brainSlotEnvKeys(OPENCODE_CARD),
|
|
7112
7176
|
accountHome: xdgHome,
|
|
7113
|
-
instanceTable:
|
|
7177
|
+
instanceTable: recipe.environment,
|
|
7114
7178
|
handOverrides: {
|
|
7115
|
-
OPENCODE_CONFIG_CONTENT: resolveOpenCodeConfigContent(
|
|
7116
|
-
|
|
7117
|
-
input.processEnv ?? process.env
|
|
7118
|
-
)
|
|
7119
|
-
},
|
|
7120
|
-
launch: input.processEnv
|
|
7179
|
+
OPENCODE_CONFIG_CONTENT: resolveOpenCodeConfigContent(process.env)
|
|
7180
|
+
}
|
|
7121
7181
|
});
|
|
7122
7182
|
}
|
|
7123
7183
|
async function terminateOwnedProcess(handle) {
|
|
@@ -7149,7 +7209,7 @@ async function terminateOwnedProcess(handle) {
|
|
|
7149
7209
|
async function spawnOpenCodeServer(input) {
|
|
7150
7210
|
const port = await findAvailablePort();
|
|
7151
7211
|
const hostname = DEFAULT_HOSTNAME;
|
|
7152
|
-
const env = buildSpawnEnv(
|
|
7212
|
+
const env = buildSpawnEnv(input.recipe);
|
|
7153
7213
|
const spawned = await input.host.process.spawn({
|
|
7154
7214
|
program: input.program,
|
|
7155
7215
|
args: ["serve", `--hostname=${hostname}`, `--port=${port}`],
|
|
@@ -7241,7 +7301,6 @@ async function connectToOpenCodeServer(input) {
|
|
|
7241
7301
|
return spawnOpenCodeServer({
|
|
7242
7302
|
host: input.host,
|
|
7243
7303
|
recipe: input.recipe,
|
|
7244
|
-
processEnv: input.processEnv,
|
|
7245
7304
|
directory: input.directory,
|
|
7246
7305
|
program,
|
|
7247
7306
|
...input.onSpawn === void 0 ? {} : { onSpawn: input.onSpawn }
|
|
@@ -7265,7 +7324,7 @@ function createOpenCodeSdkClient(input) {
|
|
|
7265
7324
|
});
|
|
7266
7325
|
}
|
|
7267
7326
|
async function runOpenCodeCommand(input) {
|
|
7268
|
-
const env = buildSpawnEnv(
|
|
7327
|
+
const env = buildSpawnEnv(input.recipe);
|
|
7269
7328
|
const spawned = await input.host.process.spawn({
|
|
7270
7329
|
program: input.program,
|
|
7271
7330
|
args: [...input.args],
|
|
@@ -7273,12 +7332,31 @@ async function runOpenCodeCommand(input) {
|
|
|
7273
7332
|
env,
|
|
7274
7333
|
owner: { bindingId: input.host.bindingId }
|
|
7275
7334
|
});
|
|
7276
|
-
const
|
|
7335
|
+
const collected = Promise.all([
|
|
7277
7336
|
collectText(spawned.stdout, input.maxOutputBytes ?? Number.POSITIVE_INFINITY),
|
|
7278
7337
|
collectText(spawned.stderr, input.maxOutputBytes ?? Number.POSITIVE_INFINITY),
|
|
7279
7338
|
spawned.exited
|
|
7280
7339
|
]);
|
|
7281
|
-
|
|
7340
|
+
if (input.timeoutMs === void 0) {
|
|
7341
|
+
const [stdout, stderr, exitCode] = await collected;
|
|
7342
|
+
return { stdout, stderr, exitCode };
|
|
7343
|
+
}
|
|
7344
|
+
let timer;
|
|
7345
|
+
const timedOut = new Promise((resolve2) => {
|
|
7346
|
+
timer = setTimeout(() => resolve2("timeout"), input.timeoutMs);
|
|
7347
|
+
});
|
|
7348
|
+
try {
|
|
7349
|
+
const settled = await Promise.race([collected, timedOut]);
|
|
7350
|
+
if (settled === "timeout") {
|
|
7351
|
+
collected.catch(() => void 0);
|
|
7352
|
+
await spawned.kill("SIGKILL").catch(() => void 0);
|
|
7353
|
+
throw new Error(`OpenCode CLI ${input.args.join(" ")} timed out after ${input.timeoutMs}ms.`);
|
|
7354
|
+
}
|
|
7355
|
+
const [stdout, stderr, exitCode] = settled;
|
|
7356
|
+
return { stdout, stderr, exitCode };
|
|
7357
|
+
} finally {
|
|
7358
|
+
clearTimeout(timer);
|
|
7359
|
+
}
|
|
7282
7360
|
}
|
|
7283
7361
|
async function withOneSecondRetry(run) {
|
|
7284
7362
|
try {
|
|
@@ -7304,13 +7382,12 @@ function inventoryFromCli(models, agents, skills) {
|
|
|
7304
7382
|
};
|
|
7305
7383
|
}
|
|
7306
7384
|
async function loadInventoryFromCli(input) {
|
|
7307
|
-
const run = (args, maxOutputBytes) => runOpenCodeCommand({
|
|
7385
|
+
const run = (args, maxOutputBytes, cwd = input.cwd) => runOpenCodeCommand({
|
|
7308
7386
|
host: input.host,
|
|
7309
7387
|
recipe: input.recipe,
|
|
7310
|
-
...input.processEnv ? { processEnv: input.processEnv } : {},
|
|
7311
7388
|
program: input.program,
|
|
7312
7389
|
args,
|
|
7313
|
-
...
|
|
7390
|
+
...cwd ? { cwd } : {},
|
|
7314
7391
|
...maxOutputBytes !== void 0 ? { maxOutputBytes } : {}
|
|
7315
7392
|
});
|
|
7316
7393
|
const modelsRun = async () => {
|
|
@@ -7343,7 +7420,11 @@ async function loadInventoryFromCli(input) {
|
|
|
7343
7420
|
const skillsRun = async () => {
|
|
7344
7421
|
try {
|
|
7345
7422
|
const result = await withOneSecondRetry(async () => {
|
|
7346
|
-
const command = await run(
|
|
7423
|
+
const command = await run(
|
|
7424
|
+
["debug", "skill"],
|
|
7425
|
+
OPENCODE_SKILL_DISCOVERY_MAX_OUTPUT_BYTES,
|
|
7426
|
+
input.skillsCwd ?? input.cwd
|
|
7427
|
+
);
|
|
7347
7428
|
if (command.exitCode !== 0) {
|
|
7348
7429
|
throw new Error(`opencode debug skill exited ${command.exitCode}`);
|
|
7349
7430
|
}
|
|
@@ -7355,10 +7436,12 @@ async function loadInventoryFromCli(input) {
|
|
|
7355
7436
|
return [];
|
|
7356
7437
|
}
|
|
7357
7438
|
};
|
|
7358
|
-
const
|
|
7439
|
+
const models = await modelsRun();
|
|
7440
|
+
const agents = await agentsRun();
|
|
7441
|
+
const skills = await skillsRun();
|
|
7359
7442
|
return inventoryFromCli(models, agents, skills);
|
|
7360
7443
|
}
|
|
7361
|
-
async function loadOpenCodeInventory(client2) {
|
|
7444
|
+
async function loadOpenCodeInventory(client2, skillsClient = client2) {
|
|
7362
7445
|
const listed = await client2.provider.list();
|
|
7363
7446
|
const providerList = listed.data;
|
|
7364
7447
|
if (!providerList) {
|
|
@@ -7373,7 +7456,7 @@ async function loadOpenCodeInventory(client2) {
|
|
|
7373
7456
|
}
|
|
7374
7457
|
let skills = [];
|
|
7375
7458
|
try {
|
|
7376
|
-
const listedSkills = await
|
|
7459
|
+
const listedSkills = await skillsClient.app.skills();
|
|
7377
7460
|
skills = (listedSkills.data ?? []).map((skill) => ({
|
|
7378
7461
|
name: skill.name,
|
|
7379
7462
|
...skill.description !== void 0 ? { description: skill.description } : {},
|
|
@@ -7397,6 +7480,7 @@ async function loadOpenCodeInventory(client2) {
|
|
|
7397
7480
|
}
|
|
7398
7481
|
|
|
7399
7482
|
// src/probe.ts
|
|
7483
|
+
var OPENCODE_VERSION_PROBE_TIMEOUT_MS = 4e3;
|
|
7400
7484
|
var OPENCODE_NATIVE_MODE_REPORT = {
|
|
7401
7485
|
nativeModes: OPENCODE_NATIVE_MODES.map((mode) => ({
|
|
7402
7486
|
id: mode.id,
|
|
@@ -7433,9 +7517,9 @@ async function probeOpenCode(input) {
|
|
|
7433
7517
|
const result = await runOpenCodeCommand({
|
|
7434
7518
|
host: input.host,
|
|
7435
7519
|
recipe: input.recipe,
|
|
7436
|
-
...input.processEnv ? { processEnv: input.processEnv } : {},
|
|
7437
7520
|
program,
|
|
7438
|
-
args: ["--version"]
|
|
7521
|
+
args: ["--version"],
|
|
7522
|
+
timeoutMs: OPENCODE_VERSION_PROBE_TIMEOUT_MS
|
|
7439
7523
|
});
|
|
7440
7524
|
version = parseGenericCliVersion(`${result.stdout}
|
|
7441
7525
|
${result.stderr}`);
|
|
@@ -7459,7 +7543,6 @@ ${result.stderr}`);
|
|
|
7459
7543
|
const handle = await connectToOpenCodeServer({
|
|
7460
7544
|
host: input.host,
|
|
7461
7545
|
recipe: input.recipe,
|
|
7462
|
-
processEnv: input.processEnv ?? void 0,
|
|
7463
7546
|
directory: "."
|
|
7464
7547
|
});
|
|
7465
7548
|
try {
|
|
@@ -7468,7 +7551,13 @@ ${result.stderr}`);
|
|
|
7468
7551
|
directory: ".",
|
|
7469
7552
|
password: handle.password
|
|
7470
7553
|
});
|
|
7471
|
-
const
|
|
7554
|
+
const skillsClient = createOpenCodeSdkClient({
|
|
7555
|
+
url: handle.url,
|
|
7556
|
+
directory: NodeOS4.homedir(),
|
|
7557
|
+
password: handle.password
|
|
7558
|
+
});
|
|
7559
|
+
const inventory2 = await loadOpenCodeInventory(client2, skillsClient);
|
|
7560
|
+
const skills2 = flattenOpenCodeSkills(inventory2.skills);
|
|
7472
7561
|
const connectedCount2 = inventory2.providerList.connected.length;
|
|
7473
7562
|
if (connectedCount2 > 0) {
|
|
7474
7563
|
return {
|
|
@@ -7477,6 +7566,7 @@ ${result.stderr}`);
|
|
|
7477
7566
|
readiness: "ready",
|
|
7478
7567
|
auth: { status: "authenticated", type: "opencode" },
|
|
7479
7568
|
models: openCodeProbeModels(inventory2),
|
|
7569
|
+
skills: skills2,
|
|
7480
7570
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7481
7571
|
};
|
|
7482
7572
|
}
|
|
@@ -7485,6 +7575,7 @@ ${result.stderr}`);
|
|
|
7485
7575
|
version,
|
|
7486
7576
|
readiness: "error",
|
|
7487
7577
|
auth: { status: "unauthenticated" },
|
|
7578
|
+
skills: skills2,
|
|
7488
7579
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7489
7580
|
};
|
|
7490
7581
|
} finally {
|
|
@@ -7494,9 +7585,10 @@ ${result.stderr}`);
|
|
|
7494
7585
|
const inventory = await loadInventoryFromCli({
|
|
7495
7586
|
host: input.host,
|
|
7496
7587
|
recipe: input.recipe,
|
|
7497
|
-
|
|
7498
|
-
|
|
7588
|
+
program,
|
|
7589
|
+
skillsCwd: NodeOS4.homedir()
|
|
7499
7590
|
});
|
|
7591
|
+
const skills = flattenOpenCodeSkills(inventory.skills);
|
|
7500
7592
|
const connectedCount = inventory.providerList.connected.length;
|
|
7501
7593
|
if (connectedCount > 0) {
|
|
7502
7594
|
return {
|
|
@@ -7505,6 +7597,7 @@ ${result.stderr}`);
|
|
|
7505
7597
|
readiness: "ready",
|
|
7506
7598
|
auth: { status: "authenticated", type: "opencode" },
|
|
7507
7599
|
models: openCodeProbeModels(inventory),
|
|
7600
|
+
skills,
|
|
7508
7601
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7509
7602
|
};
|
|
7510
7603
|
}
|
|
@@ -7513,6 +7606,7 @@ ${result.stderr}`);
|
|
|
7513
7606
|
version,
|
|
7514
7607
|
readiness: "error",
|
|
7515
7608
|
auth: { status: "unauthenticated" },
|
|
7609
|
+
skills,
|
|
7516
7610
|
...OPENCODE_NATIVE_MODE_REPORT
|
|
7517
7611
|
};
|
|
7518
7612
|
} catch (cause) {
|
|
@@ -8552,7 +8646,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8552
8646
|
const handle = await connectToOpenCodeServer({
|
|
8553
8647
|
host,
|
|
8554
8648
|
recipe,
|
|
8555
|
-
processEnv: input.processEnv,
|
|
8556
8649
|
directory: input.cwd
|
|
8557
8650
|
});
|
|
8558
8651
|
shared.handle = handle;
|
|
@@ -8575,7 +8668,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8575
8668
|
const handle = await connectToOpenCodeServer({
|
|
8576
8669
|
host,
|
|
8577
8670
|
recipe,
|
|
8578
|
-
processEnv: input.processEnv,
|
|
8579
8671
|
directory: input.cwd,
|
|
8580
8672
|
program
|
|
8581
8673
|
});
|
|
@@ -8601,15 +8693,10 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8601
8693
|
const runOpenCodeJson = async (input) => {
|
|
8602
8694
|
const agent = getModelSelectionStringOptionValue(input.modelSelection, "agent");
|
|
8603
8695
|
const variant = getModelSelectionStringOptionValue(input.modelSelection, "variant");
|
|
8604
|
-
const client2 = await acquireClient({
|
|
8605
|
-
cwd: input.cwd,
|
|
8606
|
-
...input.launch?.processEnv ? { processEnv: input.launch.processEnv } : {}
|
|
8607
|
-
});
|
|
8696
|
+
const client2 = await acquireClient({ cwd: input.cwd });
|
|
8608
8697
|
try {
|
|
8609
|
-
const boundModelId = input.launch?.requestedModelId?.trim() || void 0;
|
|
8610
8698
|
const model = chooseOpenCodeModel({
|
|
8611
|
-
requested:
|
|
8612
|
-
boundModelId,
|
|
8699
|
+
requested: modelIdFromSelection(input.modelSelection) ?? "openai/gpt-5",
|
|
8613
8700
|
match: matchModel
|
|
8614
8701
|
});
|
|
8615
8702
|
if (input.signal?.aborted) {
|
|
@@ -8666,7 +8753,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8666
8753
|
prompt,
|
|
8667
8754
|
schemaKeys: includeBranch ? ["subject", "body", "branch"] : ["subject", "body"],
|
|
8668
8755
|
modelSelection: input["modelSelection"],
|
|
8669
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8670
8756
|
...signal === void 0 ? {} : { signal }
|
|
8671
8757
|
});
|
|
8672
8758
|
return {
|
|
@@ -8696,7 +8782,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8696
8782
|
prompt,
|
|
8697
8783
|
schemaKeys: ["title", "body"],
|
|
8698
8784
|
modelSelection: input["modelSelection"],
|
|
8699
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8700
8785
|
...signal === void 0 ? {} : { signal }
|
|
8701
8786
|
});
|
|
8702
8787
|
return {
|
|
@@ -8721,7 +8806,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8721
8806
|
prompt,
|
|
8722
8807
|
schemaKeys: ["branch"],
|
|
8723
8808
|
modelSelection: input["modelSelection"],
|
|
8724
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8725
8809
|
...signal === void 0 ? {} : { signal }
|
|
8726
8810
|
});
|
|
8727
8811
|
return { branch: sanitizeBranchFragment(readString3(generated["branch"])) };
|
|
@@ -8744,7 +8828,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8744
8828
|
prompt,
|
|
8745
8829
|
schemaKeys: ["title"],
|
|
8746
8830
|
modelSelection: input["modelSelection"],
|
|
8747
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8748
8831
|
...signal === void 0 ? {} : { signal }
|
|
8749
8832
|
});
|
|
8750
8833
|
return { title: sanitizeThreadTitle(readString3(generated["title"])) };
|
|
@@ -8764,7 +8847,6 @@ function createOpenCodeTextGeneration(recipe, host) {
|
|
|
8764
8847
|
prompt,
|
|
8765
8848
|
schemaKeys: ["summary"],
|
|
8766
8849
|
modelSelection: input["modelSelection"],
|
|
8767
|
-
...isRecord2(input["launch"]) ? { launch: input["launch"] } : {},
|
|
8768
8850
|
...signal === void 0 ? {} : { signal }
|
|
8769
8851
|
});
|
|
8770
8852
|
return { summary: readString3(generated["summary"]).trim() };
|
|
@@ -8887,7 +8969,6 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
8887
8969
|
const server = await connectToOpenCodeServer({
|
|
8888
8970
|
host,
|
|
8889
8971
|
recipe,
|
|
8890
|
-
processEnv: input.launch.processEnv,
|
|
8891
8972
|
directory,
|
|
8892
8973
|
program: recipe.binaryPath,
|
|
8893
8974
|
onSpawn: (resource) => {
|
|
@@ -8903,7 +8984,10 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
8903
8984
|
password: server.password
|
|
8904
8985
|
});
|
|
8905
8986
|
const nativeModeId = openCodeNativeModeFor(input.runtimeMode, input.nativeModeId);
|
|
8906
|
-
const permission = openCodePermissionRulesForNativeMode(
|
|
8987
|
+
const permission = openCodePermissionRulesForNativeMode(
|
|
8988
|
+
nativeModeId,
|
|
8989
|
+
input.readOnlyDirectories
|
|
8990
|
+
);
|
|
8907
8991
|
const resume = input.discardResumeCursor === true ? void 0 : parseOpenCodeResume(input.resumeCursor);
|
|
8908
8992
|
let sessionId;
|
|
8909
8993
|
let createdSession = false;
|
|
@@ -9012,7 +9096,6 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9012
9096
|
compaction: void 0,
|
|
9013
9097
|
attachmentsApi: attachments,
|
|
9014
9098
|
runtimeMode: input.runtimeMode,
|
|
9015
|
-
boundModelId: input.launch.requestedModelId?.trim() || void 0,
|
|
9016
9099
|
matchModel: createCatalogModelMatcher2(host.log)
|
|
9017
9100
|
};
|
|
9018
9101
|
const winner = sessions.get(input.threadId);
|
|
@@ -9056,7 +9139,6 @@ function createOpenCodeInstance(config, host, attachments) {
|
|
|
9056
9139
|
const requestedModel = modelIdFromSelection(input.modelSelection) ?? readString2(input.modelSelection?.model) ?? context.session.model;
|
|
9057
9140
|
const parsedSlug = chooseOpenCodeModel({
|
|
9058
9141
|
requested: requestedModel,
|
|
9059
|
-
boundModelId: context.boundModelId,
|
|
9060
9142
|
match: context.matchModel
|
|
9061
9143
|
});
|
|
9062
9144
|
const queuedDecline = declineRelay.take(input.threadId);
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"form": {
|
|
3
|
+
"binaryPath": {
|
|
4
|
+
"title": "Program path",
|
|
5
|
+
"description": "Path to the OpenCode program this provider runs.",
|
|
6
|
+
"placeholder": "opencode"
|
|
7
|
+
},
|
|
8
|
+
"serverUrl": {
|
|
9
|
+
"title": "Server URL",
|
|
10
|
+
"description": "Leave blank to let Ycodium spawn the server when needed.",
|
|
11
|
+
"placeholder": "http://127.0.0.1:4096"
|
|
12
|
+
},
|
|
13
|
+
"serverPassword": {
|
|
14
|
+
"title": "Server password",
|
|
15
|
+
"description": "Stored in plain text on disk.",
|
|
16
|
+
"placeholder": "Optional"
|
|
17
|
+
},
|
|
18
|
+
"homePath": {
|
|
19
|
+
"title": "Account directory",
|
|
20
|
+
"description": "Where this account's login and history live. Leave empty to use the CLI's default.",
|
|
21
|
+
"placeholder": "e.g. ~/.opencode-work"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"form": {
|
|
3
|
+
"binaryPath": {
|
|
4
|
+
"title": "程序路径",
|
|
5
|
+
"description": "此 provider 运行的 OpenCode 程序的路径。",
|
|
6
|
+
"placeholder": "opencode"
|
|
7
|
+
},
|
|
8
|
+
"serverUrl": {
|
|
9
|
+
"title": "服务器 URL",
|
|
10
|
+
"description": "留空则由 Ycodium 在需要时启动服务器。",
|
|
11
|
+
"placeholder": "http://127.0.0.1:4096"
|
|
12
|
+
},
|
|
13
|
+
"serverPassword": {
|
|
14
|
+
"title": "服务器密码",
|
|
15
|
+
"description": "以明文保存在磁盘上。",
|
|
16
|
+
"placeholder": "可选"
|
|
17
|
+
},
|
|
18
|
+
"homePath": {
|
|
19
|
+
"title": "账户目录",
|
|
20
|
+
"description": "此账户的登录信息与历史记录所在的目录。留空则使用该命令行工具的默认目录。",
|
|
21
|
+
"placeholder": "例如 ~/.opencode-work"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
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.2510",
|
|
4
4
|
"description": "OpenCode executor: OpenCode CLI via @opencode-ai/sdk/v2.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
12
|
"assets",
|
|
13
|
+
"locales",
|
|
13
14
|
"README.md"
|
|
14
15
|
],
|
|
15
16
|
"type": "module",
|
|
@@ -23,7 +24,8 @@
|
|
|
23
24
|
"@types/node": "24.12.4",
|
|
24
25
|
"esbuild": "0.28.1",
|
|
25
26
|
"vite-plus": "0.2.2",
|
|
26
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
27
|
+
"@ycodium-ai/plugin-api": "0.2.2510",
|
|
28
|
+
"ycodium-executor-testing": "0.0.0"
|
|
27
29
|
},
|
|
28
30
|
"ycodium": {
|
|
29
31
|
"plugin": "./dist/index.js",
|