@ycodium-ai/agent-opencode 0.2.3254 → 0.2.3272

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 (2) hide show
  1. package/dist/index.js +124 -54
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -133,9 +133,7 @@ var OPENCODE_CARD = {
133
133
  };
134
134
 
135
135
  // src/opencodeInstance.ts
136
- import {
137
- createCatalogModelMatcher as createCatalogModelMatcher2
138
- } from "@ycodium-ai/plugin-api/executor";
136
+ import "@ycodium-ai/plugin-api/executor";
139
137
 
140
138
  // src/config.ts
141
139
  function isRecord(value) {
@@ -579,8 +577,11 @@ function watchListLoad(api, directory, signal) {
579
577
  })();
580
578
  return { connected, loaded };
581
579
  }
582
- async function readWhenLoaded(api, directory, read, complete, timeoutMs) {
580
+ async function readWhenLoaded(api, directory, read, complete, timeoutMs, signal) {
581
+ if (signal?.aborted) throw new Error("aborted");
583
582
  const abort = new AbortController();
583
+ const onAbort = () => abort.abort();
584
+ signal?.addEventListener("abort", onAbort, { once: true });
584
585
  let timer;
585
586
  const deadline = new Promise((resolve2) => {
586
587
  timer = setTimeout(resolve2, timeoutMs);
@@ -588,21 +589,26 @@ async function readWhenLoaded(api, directory, read, complete, timeoutMs) {
588
589
  try {
589
590
  const watch = watchListLoad(api, directory, abort.signal);
590
591
  await Promise.race([watch.connected, deadline]);
592
+ if (signal?.aborted) throw new Error("aborted");
591
593
  const first = await read();
594
+ if (signal?.aborted) throw new Error("aborted");
592
595
  if (complete(first)) return first;
593
596
  await Promise.race([watch.loaded, deadline]);
597
+ if (signal?.aborted) throw new Error("aborted");
594
598
  return await read();
595
599
  } finally {
596
600
  clearTimeout(timer);
601
+ signal?.removeEventListener("abort", onAbort);
597
602
  abort.abort();
598
603
  }
599
604
  }
600
- var listOpenCodeModelsWhenLoaded = (api, directory, timeoutMs = OPENCODE_LIST_WARMUP_MS) => readWhenLoaded(
605
+ var listOpenCodeModelsWhenLoaded = (api, directory, timeoutMs, signal) => readWhenLoaded(
601
606
  api,
602
607
  directory,
603
608
  () => api.listModels(directory),
604
609
  (models) => models.length > 0,
605
- timeoutMs
610
+ timeoutMs ?? OPENCODE_LIST_WARMUP_MS,
611
+ signal
606
612
  );
607
613
  async function listOpenCodeAgentsForSelection(api, directory, chosen) {
608
614
  if (chosen === void 0) {
@@ -677,11 +683,21 @@ function openCodeTooOldDetail(version) {
677
683
  }
678
684
 
679
685
  // src/model.ts
680
- async function loadOpenCodeInventory(api, directory) {
681
- const models = await listOpenCodeModelsWhenLoaded(api, directory);
682
- const agents = await api.listAgents(directory).catch(() => []);
683
- const skills = await api.listSkills(directory).catch(() => []);
684
- const defaultModel = await api.defaultModel(directory).catch(() => void 0);
686
+ async function loadOpenCodeInventory(api, directory, signal) {
687
+ const optional = async (read, empty) => {
688
+ if (signal?.aborted) throw new Error("aborted");
689
+ try {
690
+ return await read();
691
+ } catch (cause) {
692
+ if (signal?.aborted) throw cause;
693
+ return empty;
694
+ }
695
+ };
696
+ if (signal?.aborted) throw new Error("aborted");
697
+ const models = await listOpenCodeModelsWhenLoaded(api, directory, void 0, signal);
698
+ const agents = await optional(() => api.listAgents(directory), []);
699
+ const skills = await optional(() => api.listSkills(directory), []);
700
+ const defaultModel = await optional(() => api.defaultModel(directory), void 0);
685
701
  return {
686
702
  models,
687
703
  agents,
@@ -739,7 +755,7 @@ function modelIdFromSelection(selection) {
739
755
  return typeof model === "string" ? model.trim() || void 0 : void 0;
740
756
  }
741
757
  function toOpenCodeModelRef(input) {
742
- const parsed = chooseOpenCodeModel({ requested: input.requested, match: input.match });
758
+ const parsed = chooseOpenCodeModel(input.requested);
743
759
  if (parsed === void 0) return void 0;
744
760
  const variant = getModelSelectionStringOptionValue(input.modelSelection, "variant");
745
761
  return {
@@ -748,11 +764,17 @@ function toOpenCodeModelRef(input) {
748
764
  ...variant === void 0 ? {} : { variant }
749
765
  };
750
766
  }
751
- function chooseOpenCodeModel(input) {
752
- const own = parseOpenCodeModelSlug(input.requested);
767
+ function chooseOpenCodeModel(requested) {
768
+ const own = parseOpenCodeModelSlug(requested);
753
769
  if (own) return own;
754
- input.match(input.requested, []);
755
- return void 0;
770
+ const trimmed = requested?.trim() ?? "";
771
+ if (trimmed.length === 0) return void 0;
772
+ throw Object.assign(
773
+ new Error(
774
+ `Requested model "${trimmed}" is not in this agent's catalog; it is on "the server's current model". This turn was not sent.`
775
+ ),
776
+ { failureCategory: "model-unavailable" }
777
+ );
756
778
  }
757
779
  function boundInstanceIdFromSelection(selection) {
758
780
  if (!isRecord2(selection)) return void 0;
@@ -1232,7 +1254,8 @@ var ServerSentEventParser = class {
1232
1254
  // src/server.ts
1233
1255
  import * as NodeCrypto2 from "node:crypto";
1234
1256
  import {
1235
- mergeLaunchEnv as mergeLaunchEnv2
1257
+ mergeLaunchEnv as mergeLaunchEnv2,
1258
+ throwIfExecutorSpawnAborted
1236
1259
  } from "@ycodium-ai/plugin-api/executor";
1237
1260
  import { drainStderrTail } from "@ycodium-ai/plugin-api/process-stdin";
1238
1261
 
@@ -1437,6 +1460,7 @@ async function terminateOwnedProcess(handle) {
1437
1460
  }
1438
1461
  async function spawnOpenCodeServer(input) {
1439
1462
  const port = await reserveFetchSafePort();
1463
+ throwIfExecutorSpawnAborted(input.signal);
1440
1464
  const hostname = DEFAULT_HOSTNAME;
1441
1465
  const password = NodeCrypto2.randomBytes(32).toString("base64url");
1442
1466
  const env = buildSpawnEnv(input.recipe, input.configContent, password);
@@ -1446,7 +1470,8 @@ async function spawnOpenCodeServer(input) {
1446
1470
  args,
1447
1471
  cwd: input.directory,
1448
1472
  env,
1449
- owner: { bindingId: input.host.bindingId }
1473
+ owner: { bindingId: input.host.bindingId },
1474
+ ...input.signal === void 0 ? {} : { signal: input.signal }
1450
1475
  });
1451
1476
  const processHandle = {
1452
1477
  kill: spawned.kill,
@@ -1538,7 +1563,8 @@ async function connectToOpenCodeServer(input) {
1538
1563
  directory: input.directory,
1539
1564
  program,
1540
1565
  ...configContent === void 0 ? {} : { configContent },
1541
- ...input.onSpawn === void 0 ? {} : { onSpawn: input.onSpawn }
1566
+ ...input.onSpawn === void 0 ? {} : { onSpawn: input.onSpawn },
1567
+ ...input.signal === void 0 ? {} : { signal: input.signal }
1542
1568
  });
1543
1569
  }
1544
1570
  var OPENCODE_HEALTH_TIMEOUT_MS = 5e3;
@@ -1571,9 +1597,13 @@ function versionFromInfoBody(body) {
1571
1597
  }
1572
1598
  async function readOpenCodeServerVersion(server) {
1573
1599
  const authorization = openCodeAuthorization(server.password);
1600
+ const signals = [
1601
+ AbortSignal.timeout(OPENCODE_HEALTH_TIMEOUT_MS),
1602
+ ...server.signal === void 0 ? [] : [server.signal]
1603
+ ];
1574
1604
  const response = await fetch(new URL("/api/info", server.url), {
1575
1605
  ...authorization === void 0 ? {} : { headers: { Authorization: authorization } },
1576
- signal: AbortSignal.timeout(OPENCODE_HEALTH_TIMEOUT_MS)
1606
+ signal: AbortSignal.any(signals)
1577
1607
  }).catch((cause) => {
1578
1608
  const code = errorCode(typeof cause === "object" && cause !== null ? cause : void 0);
1579
1609
  if (code === void 0) throw cause;
@@ -1605,7 +1635,8 @@ async function runOpenCodeCommand(input) {
1605
1635
  program: input.program,
1606
1636
  args: [...input.args],
1607
1637
  env,
1608
- owner: { bindingId: input.host.bindingId }
1638
+ owner: { bindingId: input.host.bindingId },
1639
+ ...input.signal === void 0 ? {} : { signal: input.signal }
1609
1640
  });
1610
1641
  const collected = Promise.all([
1611
1642
  collectText(spawned.stdout),
@@ -1750,6 +1781,7 @@ function createOpenCodeApi(server) {
1750
1781
  const authorization = openCodeAuthorization(server.password);
1751
1782
  const send = async (method, path, options) => {
1752
1783
  const signals = [
1784
+ ...server.signal === void 0 ? [] : [server.signal],
1753
1785
  ...options.signal === void 0 ? [] : [options.signal],
1754
1786
  ...options.stream === true ? [] : [AbortSignal.timeout(OPENCODE_REQUEST_TIMEOUT_MS)]
1755
1787
  ];
@@ -1766,7 +1798,7 @@ function createOpenCodeApi(server) {
1766
1798
  ...signals.length === 0 ? {} : { signal: AbortSignal.any(signals) }
1767
1799
  });
1768
1800
  } catch (cause) {
1769
- if (options.signal?.aborted === true) throw cause;
1801
+ if (server.signal?.aborted === true || options.signal?.aborted === true) throw cause;
1770
1802
  throw new OpenCodeApiError({ kind: "transport", method, path, cause });
1771
1803
  }
1772
1804
  if (!response.ok) {
@@ -2001,7 +2033,8 @@ async function addOpenCodeMcpServers(input) {
2001
2033
  // src/probe.ts
2002
2034
  import * as NodeOS4 from "node:os";
2003
2035
  import {
2004
- ExecutorSpawnRefusedError
2036
+ ExecutorSpawnRefusedError,
2037
+ raceAbort
2005
2038
  } from "@ycodium-ai/plugin-api/executor";
2006
2039
  var OPENCODE_VERSION_PROBE_TIMEOUT_MS = 4e3;
2007
2040
  var OPENCODE_NATIVE_MODE_REPORT = {
@@ -2014,7 +2047,7 @@ var OPENCODE_NATIVE_MODE_REPORT = {
2014
2047
  nativeModeByRuntimeMode: OPENCODE_NATIVE_MODE_BY_RUNTIME_MODE
2015
2048
  };
2016
2049
  async function probeOpenCode(input) {
2017
- void input.signal;
2050
+ if (input.signal?.aborted) throw new Error("aborted");
2018
2051
  if (!input.recipe.enabled) {
2019
2052
  return {
2020
2053
  installed: false,
@@ -2037,13 +2070,17 @@ async function probeOpenCode(input) {
2037
2070
  let version = null;
2038
2071
  if (!isExternal) {
2039
2072
  try {
2040
- const result = await runOpenCodeCommand({
2041
- host: input.host,
2042
- recipe: input.recipe,
2043
- program,
2044
- args: ["--version"],
2045
- timeoutMs: OPENCODE_VERSION_PROBE_TIMEOUT_MS
2046
- });
2073
+ const result = await raceAbort(
2074
+ runOpenCodeCommand({
2075
+ host: input.host,
2076
+ recipe: input.recipe,
2077
+ program,
2078
+ args: ["--version"],
2079
+ timeoutMs: OPENCODE_VERSION_PROBE_TIMEOUT_MS,
2080
+ ...input.signal === void 0 ? {} : { signal: input.signal }
2081
+ }),
2082
+ input.signal
2083
+ );
2047
2084
  version = parseGenericCliVersion(`${result.stdout}
2048
2085
  ${result.stderr}`);
2049
2086
  const tooOld = version ? openCodeTooOldDetail(version) : void 0;
@@ -2060,21 +2097,27 @@ ${result.stderr}`);
2060
2097
  }
2061
2098
  } catch (cause) {
2062
2099
  if (cause instanceof ExecutorSpawnRefusedError) throw cause;
2100
+ if (input.signal?.aborted) throw cause;
2063
2101
  return formatOpenCodeProbeError({ cause, isExternalServer: false, version });
2064
2102
  }
2065
2103
  }
2066
2104
  try {
2067
- const handle = await connectToOpenCodeServer({
2068
- host: input.host,
2069
- recipe: input.recipe,
2070
- directory: isExternal ? "." : NodeOS4.homedir(),
2071
- program
2072
- });
2105
+ const handle = await raceAbort(
2106
+ connectToOpenCodeServer({
2107
+ host: input.host,
2108
+ recipe: input.recipe,
2109
+ directory: isExternal ? "." : NodeOS4.homedir(),
2110
+ program,
2111
+ ...input.signal === void 0 ? {} : { signal: input.signal }
2112
+ }),
2113
+ input.signal
2114
+ );
2073
2115
  try {
2074
2116
  if (isExternal) {
2075
2117
  version = await readOpenCodeServerVersion({
2076
2118
  url: handle.url,
2077
- password: handle.password
2119
+ password: handle.password,
2120
+ ...input.signal === void 0 ? {} : { signal: input.signal }
2078
2121
  }).catch((cause) => {
2079
2122
  if (cause instanceof OpenCodeServerTooOldError) return null;
2080
2123
  throw cause;
@@ -2091,8 +2134,13 @@ ${result.stderr}`);
2091
2134
  };
2092
2135
  }
2093
2136
  }
2094
- const api = createOpenCodeApi({ url: handle.url, password: handle.password });
2095
- const inventory = await loadOpenCodeInventory(api, NodeOS4.homedir());
2137
+ if (input.signal?.aborted) throw new Error("aborted");
2138
+ const api = createOpenCodeApi({
2139
+ url: handle.url,
2140
+ password: handle.password,
2141
+ ...input.signal === void 0 ? {} : { signal: input.signal }
2142
+ });
2143
+ const inventory = await loadOpenCodeInventory(api, NodeOS4.homedir(), input.signal);
2096
2144
  const skills = flattenOpenCodeSkills(inventory.skills);
2097
2145
  const models = openCodeProbeModels(inventory);
2098
2146
  if (models.length > 0) {
@@ -2119,6 +2167,7 @@ ${result.stderr}`);
2119
2167
  }
2120
2168
  } catch (cause) {
2121
2169
  if (cause instanceof ExecutorSpawnRefusedError) throw cause;
2170
+ if (input.signal?.aborted) throw cause;
2122
2171
  const mapped = formatOpenCodeProbeError({ cause, isExternalServer: isExternal, version });
2123
2172
  if (mapped.detail) {
2124
2173
  const hidden = hideGenericEffectText(mapped.detail);
@@ -2130,6 +2179,34 @@ ${result.stderr}`);
2130
2179
  return mapped;
2131
2180
  }
2132
2181
  }
2182
+ async function readOpenCodeCliVersion(input) {
2183
+ if (!input.recipe.enabled) return null;
2184
+ if (input.recipe.serverUrl.trim().length > 0) {
2185
+ try {
2186
+ return await readOpenCodeServerVersion({
2187
+ url: input.recipe.serverUrl,
2188
+ password: input.recipe.serverPassword
2189
+ });
2190
+ } catch {
2191
+ return null;
2192
+ }
2193
+ }
2194
+ const program = input.recipe.binaryPath.trim();
2195
+ if (program.length === 0) return null;
2196
+ try {
2197
+ const result = await runOpenCodeCommand({
2198
+ host: input.host,
2199
+ recipe: input.recipe,
2200
+ program,
2201
+ args: ["--version"],
2202
+ timeoutMs: OPENCODE_VERSION_PROBE_TIMEOUT_MS
2203
+ });
2204
+ return parseGenericCliVersion(`${result.stdout}
2205
+ ${result.stderr}`);
2206
+ } catch {
2207
+ return null;
2208
+ }
2209
+ }
2133
2210
 
2134
2211
  // src/workspaceInventory.ts
2135
2212
  import * as NodePath5 from "node:path";
@@ -2944,8 +3021,7 @@ async function applyOpenCodeTurnSelection(input) {
2944
3021
  const { context } = input;
2945
3022
  const model = toOpenCodeModelRef({
2946
3023
  requested: input.requestedModel,
2947
- modelSelection: input.modelSelection,
2948
- match: context.matchModel
3024
+ modelSelection: input.modelSelection
2949
3025
  });
2950
3026
  if (model !== void 0 && !sameModel(context.selectedModel, model)) {
2951
3027
  await context.api.selectModel(context.sessionId, model);
@@ -3202,9 +3278,7 @@ function buildTurnSummaryPrompt(raw) {
3202
3278
  }
3203
3279
 
3204
3280
  // src/textGeneration.ts
3205
- import {
3206
- createCatalogModelMatcher
3207
- } from "@ycodium-ai/plugin-api/executor";
3281
+ import "@ycodium-ai/plugin-api/executor";
3208
3282
 
3209
3283
  // src/textGenerationUtils.ts
3210
3284
  function limitSection(value, maxChars) {
@@ -3604,7 +3678,6 @@ function createOpenCodeTextGeneration(recipe, host) {
3604
3678
  idleTimer: null
3605
3679
  };
3606
3680
  let mutex = Promise.resolve();
3607
- const matchModel = createCatalogModelMatcher(host.log);
3608
3681
  const withMutex = async (fn) => {
3609
3682
  let release;
3610
3683
  const previous = mutex;
@@ -3691,8 +3764,7 @@ function createOpenCodeTextGeneration(recipe, host) {
3691
3764
  try {
3692
3765
  const model = toOpenCodeModelRef({
3693
3766
  requested: modelIdFromSelection(input.modelSelection),
3694
- modelSelection: input.modelSelection,
3695
- match: matchModel
3767
+ modelSelection: input.modelSelection
3696
3768
  });
3697
3769
  if (input.signal?.aborted) {
3698
3770
  throw new Error(`${input.operation}: aborted.`);
@@ -3918,6 +3990,7 @@ function createOpenCodeInstance(config, host, attachments, lifecycleOptions) {
3918
3990
  host,
3919
3991
  ...signal ? { signal } : {}
3920
3992
  }),
3993
+ readCliVersion: () => readOpenCodeCliVersion({ recipe, host }),
3921
3994
  // 项目里的命令与技能:探测在 home 下列,只看得到整机的;这里把 server 的工作目录设成项目再读。
3922
3995
  workspaceInventory: ({ cwd }) => {
3923
3996
  if (disposed) return Promise.reject(new Error("OpenCode instance has been disposed."));
@@ -3970,11 +4043,9 @@ function createOpenCodeInstance(config, host, attachments, lifecycleOptions) {
3970
4043
  selectedAgent: void 0
3971
4044
  };
3972
4045
  const requestedTitle = input.title?.trim();
3973
- const matchModel = createCatalogModelMatcher2(host.log);
3974
4046
  const model = toOpenCodeModelRef({
3975
4047
  requested: requestedModelOf(input.modelSelection),
3976
- modelSelection: input.modelSelection,
3977
- match: matchModel
4048
+ modelSelection: input.modelSelection
3978
4049
  });
3979
4050
  const createFresh = async () => {
3980
4051
  const created = await api.createSession({
@@ -4071,8 +4142,7 @@ function createOpenCodeInstance(config, host, attachments, lifecycleOptions) {
4071
4142
  declinedToolCalls: /* @__PURE__ */ new Set(),
4072
4143
  abortedByDecline: false,
4073
4144
  compaction: void 0,
4074
- ...selection,
4075
- matchModel
4145
+ ...selection
4076
4146
  };
4077
4147
  await startEventPump({
4078
4148
  events,
@@ -4312,7 +4382,7 @@ var executors = [
4312
4382
  ];
4313
4383
  var index_default = definePlugin({
4314
4384
  id: "agent-opencode",
4315
- apiVersion: 30,
4385
+ apiVersion: 32,
4316
4386
  executors,
4317
4387
  activate(ctx) {
4318
4388
  capturedAttachments = ctx.attachments;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-opencode",
3
- "version": "0.2.3254",
3
+ "version": "0.2.3272",
4
4
  "description": "OpenCode executor: OpenCode CLI (2.x) over its HTTP API.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -21,10 +21,10 @@
21
21
  "@types/node": "24.12.4",
22
22
  "esbuild": "0.28.1",
23
23
  "vite-plus": "0.2.2",
24
+ "@ycodium-ai/plugin-api": "0.2.3272",
25
+ "ycodium-executor-testing": "0.0.0",
24
26
  "ycodium-fetch-ports": "0.0.0",
25
- "@ycodium-ai/plugin-api": "0.2.3254",
26
- "ycodium-sse-stream": "0.0.0",
27
- "ycodium-executor-testing": "0.0.0"
27
+ "ycodium-sse-stream": "0.0.0"
28
28
  },
29
29
  "ycodium": {
30
30
  "plugin": "./dist/index.js",