@openclaw/opencode-provider 2026.8.1-beta.2 → 2026.9.1-beta.1

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.
@@ -1,4 +1,4 @@
1
- import { buildStaticOpencodeZenProviderConfig } from "./provider-catalog.js";
1
+ import { n as buildStaticOpencodeZenProviderConfig } from "./provider-catalog-Dak_lvHJ.js";
2
2
  //#region extensions/opencode/provider-discovery.ts
3
3
  const opencodeProviderDiscovery = {
4
4
  id: "opencode",
@@ -1,4 +1,4 @@
1
- import { resolveClaudeThinkingProfile } from "openclaw/plugin-sdk/provider-model-shared";
1
+ import { resolveClaudeThinkingProfile } from "openclaw/plugin-sdk/claude-model-runtime";
2
2
  //#region extensions/opencode/provider-policy-api.ts
3
3
  const FIXED_REASONING_PROFILE = {
4
4
  levels: [{
@@ -1,41 +1,19 @@
1
- import { OPENCODE_LOCAL_SESSION_HOST_ID, OPENCODE_NODE_INVOKE_TIMEOUT_MS, OPENCODE_SESSIONS_CAPABILITY, OPENCODE_SESSIONS_LIST_COMMAND, OPENCODE_SESSION_ID_PATTERN, OPENCODE_SESSION_READ_COMMAND, OPENCODE_TERMINAL_RESUME_COMMAND, OpenCodeCatalogParamsError } from "./session-catalog-shared.js";
2
- import { isExactOpenCodeSessionCursor, listLocalOpenCodeSessionPage, readLocalOpenCodeTranscriptPage } from "./session-catalog.js";
3
- import { createOpenCodeTerminalNodeHostCommand, openOpenCodeCatalogTerminal } from "./session-catalog-terminal.js";
1
+ import { OPENCODE_LOCAL_SESSION_HOST_ID, OPENCODE_NODE_INVOKE_TIMEOUT_MS, OPENCODE_SESSIONS_CAPABILITY, OPENCODE_SESSIONS_LIST_COMMAND, OPENCODE_SESSION_ID_PATTERN, OPENCODE_SESSION_READ_COMMAND, OPENCODE_TERMINAL_RESUME_COMMAND } from "./session-catalog-shared.js";
2
+ import { isExactOpenCodeSessionCursor, listLocalOpenCodeSessionPage, readLocalOpenCodeTranscriptPage, requireLocalOpenCodeSession } from "./session-catalog.js";
4
3
  import { checkOpenCodeUpstreamActivity, linkContinuedOpenCodeSession } from "./session-upstream-activity.js";
5
4
  import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
6
5
  import { accessSync, constants, statSync } from "node:fs";
7
6
  import path from "node:path";
8
7
  import process from "node:process";
9
8
  import { resolveAcpSessionAvailability } from "openclaw/plugin-sdk/acp-runtime";
10
- import { resolveDefaultAgentId } from "openclaw/plugin-sdk/agent-runtime";
9
+ import { resolveSessionAgentIds } from "openclaw/plugin-sdk/agent-runtime";
11
10
  import { resolveNodeHostExecutable } from "openclaw/plugin-sdk/node-host";
12
- import { createSessionCatalogAdoptionCoordinator, importSessionCatalogHistory, listAdoptedSessionCatalogSessions, sessionCatalogAdoptedSessionKey, sessionCatalogAdoptedSourceKey } from "openclaw/plugin-sdk/session-catalog";
11
+ import { createSessionCatalogFamily, createSessionCatalogNodeHostBindings, importSessionCatalogHistory, listAdoptedSessionCatalogSessions, sessionCatalogAdoptedSessionKey } from "openclaw/plugin-sdk/session-catalog";
13
12
  //#region extensions/opencode/session-catalog-plugin.ts
14
13
  const MAX_HOSTS = 100;
15
- const TRANSCRIPT_ITEM_TYPES = /* @__PURE__ */ new Set([
16
- "userMessage",
17
- "agentMessage",
18
- "reasoning",
19
- "toolCall",
20
- "toolResult",
21
- "other"
22
- ]);
23
14
  const ACPX_BACKEND_ID = "acpx";
24
15
  const OPENCODE_ACP_AGENT_ID = "opencode";
25
16
  const OPENCODE_ADOPTED_SESSION_KEY_PREFIX = "plugin:opencode:catalog-adopt:";
26
- const continueAdoption = createSessionCatalogAdoptionCoordinator();
27
- function isOptionalString(value) {
28
- return value === void 0 || typeof value === "string";
29
- }
30
- function isOptionalNumber(value) {
31
- return value === void 0 || typeof value === "number";
32
- }
33
- function isNodeSession(value) {
34
- return isRecord(value) && typeof value.threadId === "string" && OPENCODE_SESSION_ID_PATTERN.test(value.threadId) && typeof value.status === "string" && value.status.length > 0 && typeof value.archived === "boolean" && typeof value.canContinue === "boolean" && typeof value.canArchive === "boolean" && isOptionalString(value.name) && isOptionalString(value.cwd) && isOptionalString(value.source) && isOptionalString(value.modelProvider) && isOptionalString(value.cliVersion) && isOptionalString(value.gitBranch) && isOptionalString(value.sessionKey) && isOptionalNumber(value.createdAt) && isOptionalNumber(value.updatedAt) && isOptionalNumber(value.recencyAt);
35
- }
36
- function isNodeTranscriptItem(value) {
37
- return isRecord(value) && typeof value.type === "string" && TRANSCRIPT_ITEM_TYPES.has(value.type) && isOptionalString(value.id) && isOptionalString(value.text) && isOptionalString(value.timestamp) && isOptionalString(value.model) && (value.truncated === void 0 || typeof value.truncated === "boolean");
38
- }
39
17
  function executableOnPath(command, env) {
40
18
  const pathValue = env.PATH ?? env.Path ?? "";
41
19
  const delimiter = process.platform === "win32" ? ";" : path.delimiter;
@@ -72,229 +50,14 @@ function openCodeUsesProcessHomeFallback(env) {
72
50
  return !env.OPENCODE_DB?.trim() && !path.isAbsolute(env.XDG_DATA_HOME?.trim() ?? "");
73
51
  }
74
52
  function assertOpenCodeLocalAccess(hostId, allowProcessHomeFallback) {
75
- if (hostId === "gateway" && allowProcessHomeFallback === false && openCodeUsesProcessHomeFallback(process.env)) throw new OpenCodeCatalogParamsError("local OpenCode sessions are unavailable in isolated state");
76
- }
77
- function createOpenCodeSessionNodeHostCommands(api) {
78
- const available = ({ config, env }) => fullConfigCatalogEnabled(config) && executableOnPath("opencode", env);
79
- return [
80
- {
81
- command: OPENCODE_SESSIONS_LIST_COMMAND,
82
- cap: OPENCODE_SESSIONS_CAPABILITY,
83
- dangerous: false,
84
- isAvailable: available,
85
- handle: async (paramsJSON) => JSON.stringify(await listLocalOpenCodeSessionPage(parseNodeParams(paramsJSON), { configIdentity: currentOpenCodeCatalogConfig(api) }))
86
- },
87
- {
88
- command: OPENCODE_SESSION_READ_COMMAND,
89
- cap: OPENCODE_SESSIONS_CAPABILITY,
90
- dangerous: false,
91
- isAvailable: available,
92
- handle: async (paramsJSON) => JSON.stringify(await readLocalOpenCodeTranscriptPage(parseNodeParams(paramsJSON)))
93
- },
94
- createOpenCodeTerminalNodeHostCommand(available)
95
- ];
96
- }
97
- function createOpenCodeSessionNodeInvokePolicies() {
98
- return [{
99
- commands: [
100
- OPENCODE_SESSIONS_LIST_COMMAND,
101
- OPENCODE_SESSION_READ_COMMAND,
102
- OPENCODE_TERMINAL_RESUME_COMMAND
103
- ],
104
- defaultPlatforms: [
105
- "macos",
106
- "linux",
107
- "windows"
108
- ],
109
- handle: (context) => context.command === "opencode.terminal.resume.v1" ? { ok: true } : context.invokeNode()
110
- }];
111
- }
112
- function nodeLabel(node) {
113
- return node.displayName?.trim() || node.remoteIp?.trim() || node.nodeId;
114
- }
115
- function unwrapNodePayload(value) {
116
- return isRecord(value) && typeof value.payloadJSON === "string" ? JSON.parse(value.payloadJSON) : value;
117
- }
118
- function setCatalogCapabilities(page, capabilities) {
119
- for (const session of page.sessions) {
120
- session.canContinue = capabilities.canContinue;
121
- session.canOpenTerminal = capabilities.canOpenTerminal;
122
- }
123
- return page;
124
- }
125
- function projectOpenCodeAdoptedSessions(page, adopted) {
126
- return {
127
- ...page,
128
- sessions: page.sessions.map((session) => {
129
- const sessionKey = adopted.get(sessionCatalogAdoptedSourceKey(OPENCODE_LOCAL_SESSION_HOST_ID, session.threadId));
130
- return sessionKey ? {
131
- ...session,
132
- sessionKey
133
- } : session;
134
- })
135
- };
136
- }
137
- async function listOpenCodeNodeHost(runtime, query, node) {
138
- const hostId = `node:${node.nodeId}`;
139
- const common = {
140
- hostId,
141
- label: nodeLabel(node),
142
- kind: "node",
143
- connected: node.connected === true,
144
- nodeId: node.nodeId
145
- };
146
- if (node.connected !== true) return {
147
- ...common,
148
- sessions: [],
149
- error: {
150
- code: "NODE_OFFLINE",
151
- message: "Paired node is offline"
152
- }
153
- };
154
- try {
155
- const cursor = query.cursors?.[hostId];
156
- if (cursor !== void 0 && !isExactOpenCodeSessionCursor(cursor)) throw new Error("cursor is invalid");
157
- const page = parseNodeSessionPage(unwrapNodePayload(await runtime.nodes.invoke({
158
- nodeId: node.nodeId,
159
- command: OPENCODE_SESSIONS_LIST_COMMAND,
160
- params: {
161
- ...query.limitPerHost ? { limit: query.limitPerHost } : {},
162
- ...query.search ? { searchTerm: query.search } : {},
163
- ...cursor !== void 0 ? { cursor } : {}
164
- },
165
- timeoutMs: OPENCODE_NODE_INVOKE_TIMEOUT_MS,
166
- scopes: ["operator.write"]
167
- })));
168
- const canOpenTerminal = (node.invocableCommands ?? node.commands)?.includes(OPENCODE_TERMINAL_RESUME_COMMAND) === true;
169
- return {
170
- ...common,
171
- ...setCatalogCapabilities(page, {
172
- canContinue: false,
173
- canOpenTerminal
174
- })
175
- };
176
- } catch {
177
- return {
178
- ...common,
179
- sessions: [],
180
- error: {
181
- code: "NODE_INVOKE_FAILED",
182
- message: "Paired node OpenCode sessions are unavailable"
183
- }
184
- };
185
- }
186
- }
187
- function parseNodeSessionPage(value) {
188
- if (!isRecord(value) || !Array.isArray(value.sessions) || value.sessions.length > 100) throw new Error("OpenCode node returned an invalid session page");
189
- if (!value.sessions.every(isNodeSession)) throw new Error("OpenCode node returned an invalid session page");
190
- const sessions = value.sessions;
191
- const nextCursor = value.nextCursor;
192
- if (nextCursor !== void 0 && !isExactOpenCodeSessionCursor(nextCursor)) throw new Error("OpenCode node returned an invalid cursor");
193
- return {
194
- sessions,
195
- ...nextCursor !== void 0 ? { nextCursor } : {}
196
- };
197
- }
198
- function parseNodeTranscriptPage(value, threadId) {
199
- if (!isRecord(value) || value.threadId !== threadId || !Array.isArray(value.items) || value.items.length > 100 || !value.items.every(isNodeTranscriptItem)) throw new Error("OpenCode node returned an invalid transcript page");
200
- const nextCursor = value.nextCursor;
201
- if (nextCursor !== void 0 && !isExactOpenCodeSessionCursor(nextCursor)) throw new Error("OpenCode node returned an invalid cursor");
202
- return {
203
- hostId: OPENCODE_LOCAL_SESSION_HOST_ID,
204
- threadId,
205
- items: value.items,
206
- ...nextCursor !== void 0 ? { nextCursor } : {}
207
- };
208
- }
209
- async function listOpenCodeHosts(api, query) {
210
- const runtime = api.runtime;
211
- const config = currentOpenCodeCatalogConfig(api);
212
- const canContinue = resolveAcpSessionAvailability({
213
- config,
214
- backendId: ACPX_BACKEND_ID,
215
- agentId: OPENCODE_ACP_AGENT_ID
216
- }).available;
217
- const adopted = query.sessionEntries ? listAdoptedOpenCodeSessions(api, query.sessionEntries) : /* @__PURE__ */ new Map();
218
- const requested = query.hostIds ? new Set(query.hostIds) : void 0;
219
- const hosts = [];
220
- if ((!requested || requested.has("gateway")) && (query.allowProcessHomeFallback !== false || !openCodeUsesProcessHomeFallback(process.env)) && resolveNodeHostExecutable("opencode", {
221
- env: process.env,
222
- pathEnv: process.env.PATH ?? "",
223
- strategy: "fallback"
224
- })) try {
225
- hosts.push({
226
- hostId: OPENCODE_LOCAL_SESSION_HOST_ID,
227
- label: "Local OpenCode",
228
- kind: "gateway",
229
- connected: true,
230
- ...await listLocalOpenCodeSessionPage({
231
- limit: query.limitPerHost,
232
- ...query.search ? { searchTerm: query.search } : {},
233
- cursor: query.cursors?.[OPENCODE_LOCAL_SESSION_HOST_ID]
234
- }, { configIdentity: config }).then((page) => projectOpenCodeAdoptedSessions(setCatalogCapabilities(page, {
235
- canContinue,
236
- canOpenTerminal: true
237
- }), adopted))
238
- });
239
- } catch {
240
- hosts.push({
241
- hostId: OPENCODE_LOCAL_SESSION_HOST_ID,
242
- label: "Local OpenCode",
243
- kind: "gateway",
244
- connected: true,
245
- sessions: [],
246
- error: {
247
- code: "LOCAL_READ_FAILED",
248
- message: "Local OpenCode sessions are unavailable"
249
- }
250
- });
251
- }
252
- let nodes;
253
- try {
254
- nodes = (await (query.listNodes?.() ?? runtime.nodes.list())).nodes;
255
- } catch {
256
- return hosts;
257
- }
258
- const eligible = nodes.filter((node) => node.commands?.includes("opencode.sessions.list.v1") && (!requested || requested.has(`node:${node.nodeId}`))).toSorted((left, right) => nodeLabel(left).localeCompare(nodeLabel(right))).slice(0, MAX_HOSTS - hosts.length);
259
- const nodeHosts = await Promise.all(eligible.map((node) => listOpenCodeNodeHost(runtime, query, node)));
260
- return [...hosts, ...nodeHosts];
261
- }
262
- async function readOpenCodeTranscript(runtime, request) {
263
- const cursor = request.cursor;
264
- if (cursor !== void 0 && !isExactOpenCodeSessionCursor(cursor)) throw new Error("cursor is invalid");
265
- if (request.hostId === "gateway") {
266
- assertOpenCodeLocalAccess(request.hostId, request.allowProcessHomeFallback);
267
- return await readLocalOpenCodeTranscriptPage({
268
- threadId: request.threadId,
269
- ...request.limit ? { limit: request.limit } : {},
270
- ...cursor !== void 0 ? { cursor } : {}
271
- });
272
- }
273
- if (!request.hostId.startsWith("node:")) throw new Error("hostId is invalid");
274
- const nodeId = request.hostId.slice(5);
275
- const node = (await runtime.nodes.list()).nodes.find((candidate) => candidate.nodeId === nodeId && candidate.connected === true && candidate.commands?.includes("opencode.sessions.read.v1"));
276
- if (!node) throw new Error("paired-node OpenCode session host is unavailable");
277
- return {
278
- ...parseNodeTranscriptPage(unwrapNodePayload(await runtime.nodes.invoke({
279
- nodeId,
280
- command: OPENCODE_SESSION_READ_COMMAND,
281
- params: {
282
- threadId: request.threadId,
283
- ...request.limit ? { limit: request.limit } : {},
284
- ...cursor !== void 0 ? { cursor } : {}
285
- },
286
- timeoutMs: OPENCODE_NODE_INVOKE_TIMEOUT_MS,
287
- scopes: ["operator.write"]
288
- })), request.threadId),
289
- hostId: request.hostId,
290
- label: nodeLabel(node)
291
- };
53
+ if (hostId === "gateway" && allowProcessHomeFallback === false && openCodeUsesProcessHomeFallback(process.env)) throw new Error("local OpenCode sessions are unavailable in isolated state");
292
54
  }
293
55
  function currentOpenCodeCatalogConfig(api) {
294
56
  return api.runtime.config?.current?.() ?? api.config ?? {};
295
57
  }
296
- function listAdoptedOpenCodeSessions(api, sessionEntries) {
58
+ function listAdoptedOpenCodeSessions(api, agentId, sessionEntries) {
297
59
  return listAdoptedSessionCatalogSessions({
60
+ ...agentId ? { agentId } : {},
298
61
  config: currentOpenCodeCatalogConfig(api),
299
62
  pluginId: api.id,
300
63
  runtime: api.runtime,
@@ -309,99 +72,177 @@ function listAdoptedOpenCodeSessions(api, sessionEntries) {
309
72
  }
310
73
  });
311
74
  }
312
- async function continueOpenCodeSession(api, hostId, threadId) {
313
- if (hostId.startsWith("node:")) throw new OpenCodeCatalogParamsError("paired-node OpenCode session rows are view-only");
314
- if (hostId !== "gateway") throw new OpenCodeCatalogParamsError("OpenCode session catalog hostId is invalid");
315
- const availability = resolveAcpSessionAvailability({
316
- config: currentOpenCodeCatalogConfig(api),
317
- backendId: ACPX_BACKEND_ID,
318
- agentId: OPENCODE_ACP_AGENT_ID
319
- });
320
- if (!availability.available) throw new OpenCodeCatalogParamsError(availability.message);
321
- const sourceKey = sessionCatalogAdoptedSourceKey(hostId, threadId);
322
- return await continueAdoption({
323
- sourceKey,
324
- findExisting: () => listAdoptedOpenCodeSessions(api).get(sourceKey),
325
- create: async () => {
326
- const config = currentOpenCodeCatalogConfig(api);
327
- const record = (await listLocalOpenCodeSessionPage({
328
- searchTerm: threadId,
329
- limit: 100
330
- }, {
331
- configIdentity: config,
332
- forceRefresh: true
333
- }).catch(() => void 0))?.sessions.find((session) => session.threadId === threadId);
334
- if (!record) throw new OpenCodeCatalogParamsError("OpenCode session is unavailable");
335
- const currentAvailability = resolveAcpSessionAvailability({
336
- config,
337
- backendId: ACPX_BACKEND_ID,
338
- agentId: OPENCODE_ACP_AGENT_ID
339
- });
340
- if (!currentAvailability.available) throw new OpenCodeCatalogParamsError(currentAvailability.message);
341
- const marker = { sourceThreadId: threadId };
342
- return { sessionKey: (await api.runtime.agent.session.createSessionEntry({
343
- cfg: config,
344
- key: sessionCatalogAdoptedSessionKey(OPENCODE_ADOPTED_SESSION_KEY_PREFIX, threadId),
345
- agentId: resolveDefaultAgentId(config),
346
- recoverMatchingInitialEntry: true,
347
- ...record.name ? { label: record.name } : {},
348
- ...record.cwd ? { spawnedCwd: record.cwd } : {},
349
- initialEntry: {
350
- acpBackendId: ACPX_BACKEND_ID,
351
- acpSessionBinding: {
352
- acpAgentId: OPENCODE_ACP_AGENT_ID,
353
- agentSessionId: threadId
354
- },
355
- pluginExtensions: { opencode: { sessionCatalog: marker } }
356
- },
357
- afterCreate: async (entry) => {
358
- await importSessionCatalogHistory({
359
- catalogId: "opencode",
360
- threadId,
361
- read: async ({ cursor, limit }) => await readOpenCodeTranscript(api.runtime, {
362
- hostId,
363
- threadId,
364
- limit,
365
- ...cursor ? { cursor } : {}
366
- }),
367
- sessionId: entry.sessionId,
368
- sessionKey: entry.key,
369
- agentId: entry.agentId,
370
- ...record.cwd ? { cwd: record.cwd } : {},
371
- config
372
- });
373
- return { pluginExtensions: { opencode: { sessionCatalog: marker } } };
374
- }
375
- })).key };
75
+ async function loadContinuableOpenCodeSession(api, threadId) {
76
+ const session = (await listLocalOpenCodeSessionPage({
77
+ searchTerm: threadId,
78
+ limit: 100
79
+ }, {
80
+ configIdentity: currentOpenCodeCatalogConfig(api),
81
+ forceRefresh: true
82
+ }).catch(() => void 0))?.sessions.find((candidate) => candidate.threadId === threadId);
83
+ if (!session) throw new Error("OpenCode session is unavailable");
84
+ return session;
85
+ }
86
+ async function createAdoptedOpenCodeSession(params) {
87
+ const config = currentOpenCodeCatalogConfig(params.api);
88
+ const marker = { sourceThreadId: params.threadId };
89
+ return { sessionKey: (await params.api.runtime.agent.session.createSessionEntry({
90
+ cfg: config,
91
+ key: sessionCatalogAdoptedSessionKey(OPENCODE_ADOPTED_SESSION_KEY_PREFIX, params.threadId),
92
+ agentId: params.agentId,
93
+ recoverMatchingInitialEntry: true,
94
+ ...params.session.name ? { label: params.session.name } : {},
95
+ ...params.session.cwd ? { spawnedCwd: params.session.cwd } : {},
96
+ initialEntry: {
97
+ acpBackendId: ACPX_BACKEND_ID,
98
+ acpSessionBinding: {
99
+ acpAgentId: OPENCODE_ACP_AGENT_ID,
100
+ agentSessionId: params.threadId
101
+ },
102
+ pluginExtensions: { opencode: { sessionCatalog: marker } }
376
103
  },
377
- complete: async (continued) => await linkContinuedOpenCodeSession(continued.sessionKey, threadId)
104
+ afterCreate: async (entry) => {
105
+ await importSessionCatalogHistory({
106
+ catalogId: "opencode",
107
+ threadId: params.threadId,
108
+ read: async ({ cursor, limit }) => await readLocalOpenCodeTranscriptPage({
109
+ threadId: params.threadId,
110
+ limit,
111
+ ...cursor ? { cursor } : {}
112
+ }),
113
+ sessionId: entry.sessionId,
114
+ sessionKey: entry.key,
115
+ agentId: entry.agentId,
116
+ ...params.session.cwd ? { cwd: params.session.cwd } : {},
117
+ config
118
+ });
119
+ return { pluginExtensions: { opencode: { sessionCatalog: marker } } };
120
+ }
121
+ })).key };
122
+ }
123
+ function createOpenCodeNodeHostBindings(api) {
124
+ const available = ({ config, env }) => fullConfigCatalogEnabled(config) && executableOnPath("opencode", env);
125
+ return createSessionCatalogNodeHostBindings({
126
+ capability: OPENCODE_SESSIONS_CAPABILITY,
127
+ listCommand: OPENCODE_SESSIONS_LIST_COMMAND,
128
+ readCommand: OPENCODE_SESSION_READ_COMMAND,
129
+ terminalCommand: OPENCODE_TERMINAL_RESUME_COMMAND,
130
+ sessionIdPattern: OPENCODE_SESSION_ID_PATTERN,
131
+ executable: "opencode",
132
+ args: (threadId) => ["--session", threadId],
133
+ listAvailable: available,
134
+ terminalAvailable: available,
135
+ parseParams: parseNodeParams,
136
+ list: async (params) => await listLocalOpenCodeSessionPage(params, { configIdentity: currentOpenCodeCatalogConfig(api) }),
137
+ read: readLocalOpenCodeTranscriptPage,
138
+ requireSession: requireLocalOpenCodeSession,
139
+ terminalIoRequiredMessage: "OpenCode terminal command requires duplex transport",
140
+ terminalUnavailableMessage: "OpenCode CLI is unavailable",
141
+ invalidThreadIdMessage: "INVALID_REQUEST: threadId is invalid"
378
142
  });
379
143
  }
380
144
  function registerOpenCodeSessionCatalog(api) {
381
145
  if (!isOpenCodeSessionCatalogEnabled(api.pluginConfig)) return;
146
+ const provider = createSessionCatalogFamily({
147
+ runtime: api.runtime,
148
+ local: {
149
+ hostId: OPENCODE_LOCAL_SESSION_HOST_ID,
150
+ label: "Local OpenCode",
151
+ available: (query) => (query.allowProcessHomeFallback !== false || !openCodeUsesProcessHomeFallback(process.env)) && resolveNodeHostExecutable("opencode", {
152
+ env: process.env,
153
+ pathEnv: process.env.PATH ?? "",
154
+ strategy: "fallback"
155
+ }) !== void 0,
156
+ list: async (query) => await listLocalOpenCodeSessionPage({
157
+ limit: query.limitPerHost,
158
+ ...query.search ? { searchTerm: query.search } : {},
159
+ cursor: query.cursors?.[OPENCODE_LOCAL_SESSION_HOST_ID]
160
+ }, { configIdentity: currentOpenCodeCatalogConfig(api) }),
161
+ read: async (request) => await readLocalOpenCodeTranscriptPage({
162
+ threadId: request.threadId,
163
+ ...request.limit ? { limit: request.limit } : {},
164
+ ...request.cursor !== void 0 ? { cursor: request.cursor } : {}
165
+ }),
166
+ assertAccess: assertOpenCodeLocalAccess
167
+ },
168
+ node: {
169
+ listCommand: OPENCODE_SESSIONS_LIST_COMMAND,
170
+ readCommand: OPENCODE_SESSION_READ_COMMAND,
171
+ terminalCommand: OPENCODE_TERMINAL_RESUME_COMMAND,
172
+ timeoutMs: OPENCODE_NODE_INVOKE_TIMEOUT_MS,
173
+ maxHosts: MAX_HOSTS,
174
+ maxPageLimit: 100,
175
+ sessionIdPattern: OPENCODE_SESSION_ID_PATTERN
176
+ },
177
+ capabilities: {
178
+ local: () => ({
179
+ canContinue: resolveAcpSessionAvailability({
180
+ config: currentOpenCodeCatalogConfig(api),
181
+ backendId: ACPX_BACKEND_ID,
182
+ agentId: OPENCODE_ACP_AGENT_ID
183
+ }).available,
184
+ canOpenTerminal: true
185
+ }),
186
+ node: (node) => {
187
+ return {
188
+ canContinue: false,
189
+ canOpenTerminal: (node.invocableCommands ?? node.commands)?.includes(OPENCODE_TERMINAL_RESUME_COMMAND) === true
190
+ };
191
+ },
192
+ project: (session, capabilities) => ({
193
+ ...session,
194
+ ...capabilities
195
+ })
196
+ },
197
+ messages: {
198
+ invalidNodeCursor: "OpenCode node returned an invalid cursor",
199
+ invalidNodeSessionPage: "OpenCode node returned an invalid session page",
200
+ invalidNodeTranscriptPage: "OpenCode node returned an invalid transcript page",
201
+ invalidHostId: "OpenCode session catalog hostId is invalid",
202
+ localReadFailed: "Local OpenCode sessions are unavailable",
203
+ nodeInvokeFailed: "Paired node OpenCode sessions are unavailable",
204
+ nodeReadUnavailable: "paired-node OpenCode session host is unavailable",
205
+ nodeTerminalUnavailable: "paired-node OpenCode terminal is unavailable",
206
+ sessionUnavailable: "OpenCode session is unavailable"
207
+ },
208
+ continuation: {
209
+ resolveAgentId: (agentId) => resolveSessionAgentIds({
210
+ config: api.config,
211
+ agentId
212
+ }).sessionAgentId,
213
+ availability: () => resolveAcpSessionAvailability({
214
+ config: currentOpenCodeCatalogConfig(api),
215
+ backendId: ACPX_BACKEND_ID,
216
+ agentId: OPENCODE_ACP_AGENT_ID
217
+ }),
218
+ listAdopted: (agentId, sessionEntries) => listAdoptedOpenCodeSessions(api, agentId, sessionEntries),
219
+ loadSession: async (threadId) => await loadContinuableOpenCodeSession(api, threadId),
220
+ validateSession: () => void 0,
221
+ create: async (params) => await createAdoptedOpenCodeSession({
222
+ api,
223
+ ...params
224
+ }),
225
+ complete: async (continued, threadId) => await linkContinuedOpenCodeSession(continued.sessionKey, threadId),
226
+ nodeReadOnlyMessage: "paired-node OpenCode session rows are view-only"
227
+ },
228
+ terminal: {
229
+ executable: "opencode",
230
+ args: (threadId) => ["--session", threadId],
231
+ title: (threadId) => `opencode --session ${threadId.slice(0, 12)}…`,
232
+ requireLocalSession: requireLocalOpenCodeSession,
233
+ unavailableMessage: "OpenCode CLI is unavailable"
234
+ },
235
+ checkUpstreamActivity: (probes, policy) => checkOpenCodeUpstreamActivity(probes.filter((probe) => probe.hostId !== "gateway" || policy?.allowProcessHomeFallback !== false || !openCodeUsesProcessHomeFallback(process.env)))
236
+ }, isExactOpenCodeSessionCursor);
382
237
  api.registerSessionCatalog({
383
238
  id: "opencode",
384
239
  label: "OpenCode",
385
240
  supportsProcessHomeIsolation: true,
386
- list: async (query) => await listOpenCodeHosts(api, query),
387
- read: async (request) => await readOpenCodeTranscript(api.runtime, request),
388
- continueSession: async (request) => {
389
- assertOpenCodeLocalAccess(request.hostId, request.allowProcessHomeFallback);
390
- return await continueOpenCodeSession(api, request.hostId, request.threadId);
391
- },
392
- checkUpstreamActivity: (probes, policy) => checkOpenCodeUpstreamActivity(probes.filter((probe) => probe.hostId !== "gateway" || policy?.allowProcessHomeFallback !== false || !openCodeUsesProcessHomeFallback(process.env))),
393
- openTerminal: async (request) => {
394
- assertOpenCodeLocalAccess(request.hostId, request.allowProcessHomeFallback);
395
- return await openOpenCodeCatalogTerminal({
396
- runtime: api.runtime,
397
- ...request,
398
- parseNodeSessionPage,
399
- unwrapNodePayload
400
- });
401
- }
241
+ ...provider
402
242
  });
403
- for (const command of createOpenCodeSessionNodeHostCommands(api)) api.registerNodeHostCommand(command);
404
- for (const policy of createOpenCodeSessionNodeInvokePolicies()) api.registerNodeInvokePolicy(policy);
243
+ const nodeHost = createOpenCodeNodeHostBindings(api);
244
+ for (const command of nodeHost.commands) api.registerNodeHostCommand(command);
245
+ for (const policy of nodeHost.policies) api.registerNodeInvokePolicy(policy);
405
246
  }
406
247
  //#endregion
407
248
  export { registerOpenCodeSessionCatalog };
@@ -7,6 +7,5 @@ const OPENCODE_LOCAL_SESSION_HOST_ID = "gateway";
7
7
  const OPENCODE_SESSION_CATALOG_MAX_PAGE_LIMIT = 100;
8
8
  const OPENCODE_NODE_INVOKE_TIMEOUT_MS = 35e3;
9
9
  const OPENCODE_SESSION_ID_PATTERN = /^(?!-)[A-Za-z0-9._:-]{1,256}$/u;
10
- var OpenCodeCatalogParamsError = class extends Error {};
11
10
  //#endregion
12
- export { OPENCODE_LOCAL_SESSION_HOST_ID, OPENCODE_NODE_INVOKE_TIMEOUT_MS, OPENCODE_SESSIONS_CAPABILITY, OPENCODE_SESSIONS_LIST_COMMAND, OPENCODE_SESSION_CATALOG_MAX_PAGE_LIMIT, OPENCODE_SESSION_ID_PATTERN, OPENCODE_SESSION_READ_COMMAND, OPENCODE_TERMINAL_RESUME_COMMAND, OpenCodeCatalogParamsError };
11
+ export { OPENCODE_LOCAL_SESSION_HOST_ID, OPENCODE_NODE_INVOKE_TIMEOUT_MS, OPENCODE_SESSIONS_CAPABILITY, OPENCODE_SESSIONS_LIST_COMMAND, OPENCODE_SESSION_CATALOG_MAX_PAGE_LIMIT, OPENCODE_SESSION_ID_PATTERN, OPENCODE_SESSION_READ_COMMAND, OPENCODE_TERMINAL_RESUME_COMMAND };