@getpaseo/server 0.1.71 → 0.1.72
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/server/server/agent/agent-response-loop.d.ts.map +1 -1
- package/dist/server/server/agent/agent-response-loop.js +2 -1
- package/dist/server/server/agent/agent-response-loop.js.map +1 -1
- package/dist/server/server/agent/create-agent-title.d.ts +8 -0
- package/dist/server/server/agent/create-agent-title.d.ts.map +1 -0
- package/dist/server/server/agent/create-agent-title.js +29 -0
- package/dist/server/server/agent/create-agent-title.js.map +1 -0
- package/dist/server/server/agent/import-sessions.d.ts +20 -1
- package/dist/server/server/agent/import-sessions.d.ts.map +1 -1
- package/dist/server/server/agent/import-sessions.js +101 -0
- package/dist/server/server/agent/import-sessions.js.map +1 -1
- package/dist/server/server/agent/provider-registry.d.ts.map +1 -1
- package/dist/server/server/agent/provider-registry.js +2 -1
- package/dist/server/server/agent/provider-registry.js.map +1 -1
- package/dist/server/server/agent/providers/codex/app-server-transport.d.ts +25 -0
- package/dist/server/server/agent/providers/codex/app-server-transport.d.ts.map +1 -0
- package/dist/server/server/agent/providers/codex/app-server-transport.js +183 -0
- package/dist/server/server/agent/providers/codex/app-server-transport.js.map +1 -0
- package/dist/server/server/agent/providers/codex-app-server-agent.d.ts +1 -21
- package/dist/server/server/agent/providers/codex-app-server-agent.d.ts.map +1 -1
- package/dist/server/server/agent/providers/codex-app-server-agent.js +1 -170
- package/dist/server/server/agent/providers/codex-app-server-agent.js.map +1 -1
- package/dist/server/server/agent/providers/opencode/runtime.d.ts +27 -0
- package/dist/server/server/agent/providers/opencode/runtime.d.ts.map +1 -0
- package/dist/server/server/agent/providers/opencode/runtime.js +5 -0
- package/dist/server/server/agent/providers/opencode/runtime.js.map +1 -0
- package/dist/server/server/agent/providers/opencode/server-manager.d.ts +55 -0
- package/dist/server/server/agent/providers/opencode/server-manager.d.ts.map +1 -0
- package/dist/server/server/agent/providers/opencode/server-manager.js +255 -0
- package/dist/server/server/agent/providers/opencode/server-manager.js.map +1 -0
- package/dist/server/server/agent/providers/opencode/test-server-manager.d.ts +22 -0
- package/dist/server/server/agent/providers/opencode/test-server-manager.d.ts.map +1 -0
- package/dist/server/server/agent/providers/opencode/test-server-manager.js +28 -0
- package/dist/server/server/agent/providers/opencode/test-server-manager.js.map +1 -0
- package/dist/server/server/agent/providers/opencode/test-utils/test-opencode-runtime.d.ts +75 -0
- package/dist/server/server/agent/providers/opencode/test-utils/test-opencode-runtime.d.ts.map +1 -0
- package/dist/server/server/agent/providers/opencode/test-utils/test-opencode-runtime.js +169 -0
- package/dist/server/server/agent/providers/opencode/test-utils/test-opencode-runtime.js.map +1 -0
- package/dist/server/server/agent/providers/opencode-agent.d.ts +5 -35
- package/dist/server/server/agent/providers/opencode-agent.d.ts.map +1 -1
- package/dist/server/server/agent/providers/opencode-agent.js +28 -258
- package/dist/server/server/agent/providers/opencode-agent.js.map +1 -1
- package/dist/server/server/agent/providers/pi-direct-agent.d.ts +8 -3
- package/dist/server/server/agent/providers/pi-direct-agent.d.ts.map +1 -1
- package/dist/server/server/agent/providers/pi-direct-agent.js +44 -34
- package/dist/server/server/agent/providers/pi-direct-agent.js.map +1 -1
- package/dist/server/server/checkout/status-projection.d.ts +19 -0
- package/dist/server/server/checkout/status-projection.d.ts.map +1 -0
- package/dist/server/server/checkout/status-projection.js +98 -0
- package/dist/server/server/checkout/status-projection.js.map +1 -0
- package/dist/server/server/paseo-worktree-service.d.ts +2 -1
- package/dist/server/server/paseo-worktree-service.d.ts.map +1 -1
- package/dist/server/server/paseo-worktree-service.js +30 -3
- package/dist/server/server/paseo-worktree-service.js.map +1 -1
- package/dist/server/server/session.d.ts +1 -17
- package/dist/server/server/session.d.ts.map +1 -1
- package/dist/server/server/session.js +24 -233
- package/dist/server/server/session.js.map +1 -1
- package/dist/server/server/workspace-directory.d.ts +0 -2
- package/dist/server/server/workspace-directory.d.ts.map +1 -1
- package/dist/server/server/workspace-directory.js +9 -26
- package/dist/server/server/workspace-directory.js.map +1 -1
- package/dist/server/shared/agent-state-bucket.d.ts +13 -0
- package/dist/server/shared/agent-state-bucket.d.ts.map +1 -0
- package/dist/server/shared/agent-state-bucket.js +41 -0
- package/dist/server/shared/agent-state-bucket.js.map +1 -0
- package/dist/server/shared/git-remote.d.ts +16 -0
- package/dist/server/shared/git-remote.d.ts.map +1 -0
- package/dist/server/shared/git-remote.js +72 -0
- package/dist/server/shared/git-remote.js.map +1 -0
- package/dist/server/utils/checkout-git.d.ts +1 -0
- package/dist/server/utils/checkout-git.d.ts.map +1 -1
- package/dist/server/utils/checkout-git.js +3 -0
- package/dist/server/utils/checkout-git.js.map +1 -1
- package/dist/server/utils/github-remote.d.ts +3 -7
- package/dist/server/utils/github-remote.d.ts.map +1 -1
- package/dist/server/utils/github-remote.js +4 -70
- package/dist/server/utils/github-remote.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
export class TestOpenCodeRuntime {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.acquisitions = [];
|
|
4
|
+
this.clientCreations = [];
|
|
5
|
+
this.clients = [];
|
|
6
|
+
this.server = { port: 1234, url: "http://127.0.0.1:1234" };
|
|
7
|
+
}
|
|
8
|
+
enqueueClient(client) {
|
|
9
|
+
this.clients.push(client);
|
|
10
|
+
}
|
|
11
|
+
async acquireServer(options) {
|
|
12
|
+
const acquisition = { force: options.force, releaseCount: 0 };
|
|
13
|
+
this.acquisitions.push(acquisition);
|
|
14
|
+
return {
|
|
15
|
+
server: this.server,
|
|
16
|
+
release: () => {
|
|
17
|
+
acquisition.releaseCount += 1;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async ensureServerRunning() {
|
|
22
|
+
return this.server;
|
|
23
|
+
}
|
|
24
|
+
createClient(options) {
|
|
25
|
+
this.clientCreations.push(options);
|
|
26
|
+
const client = this.clients.shift() ?? new TestOpenCodeClient();
|
|
27
|
+
return client.asSdkClient();
|
|
28
|
+
}
|
|
29
|
+
async shutdown() { }
|
|
30
|
+
}
|
|
31
|
+
export class TestOpenCodeClient {
|
|
32
|
+
constructor() {
|
|
33
|
+
this.calls = {
|
|
34
|
+
appAgents: [],
|
|
35
|
+
commandList: [],
|
|
36
|
+
eventSubscribe: [],
|
|
37
|
+
permissionReply: [],
|
|
38
|
+
providerList: [],
|
|
39
|
+
questionReject: [],
|
|
40
|
+
questionReply: [],
|
|
41
|
+
sessionAbort: [],
|
|
42
|
+
sessionCommand: [],
|
|
43
|
+
sessionCreate: [],
|
|
44
|
+
sessionDelete: [],
|
|
45
|
+
sessionMessages: [],
|
|
46
|
+
sessionPromptAsync: [],
|
|
47
|
+
sessionSummarize: [],
|
|
48
|
+
sessionUpdate: [],
|
|
49
|
+
};
|
|
50
|
+
this.appAgentsResponse = { data: [] };
|
|
51
|
+
this.commandListResponse = { data: [] };
|
|
52
|
+
this.eventStream = createEventStream([idleEvent()]);
|
|
53
|
+
this.permissionReplyResponse = {};
|
|
54
|
+
this.providerListResponse = { data: { connected: [], all: [] } };
|
|
55
|
+
this.providerListImplementation = null;
|
|
56
|
+
this.questionRejectResponse = {};
|
|
57
|
+
this.questionReplyResponse = {};
|
|
58
|
+
this.sessionAbortResponse = {};
|
|
59
|
+
this.sessionCommandError = null;
|
|
60
|
+
this.sessionCommandResponse = {};
|
|
61
|
+
this.sessionCreateResponse = { data: { id: "session-1" } };
|
|
62
|
+
this.sessionDeleteResponse = {};
|
|
63
|
+
this.sessionMessagesResponse = { data: [] };
|
|
64
|
+
this.sessionPromptAsyncResponse = {};
|
|
65
|
+
this.sessionSummarizeResponse = { data: {} };
|
|
66
|
+
this.sessionUpdateResponse = {};
|
|
67
|
+
}
|
|
68
|
+
asSdkClient() {
|
|
69
|
+
return {
|
|
70
|
+
app: {
|
|
71
|
+
agents: async (parameters) => {
|
|
72
|
+
this.calls.appAgents.push(parameters);
|
|
73
|
+
return this.appAgentsResponse;
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
command: {
|
|
77
|
+
list: async (parameters) => {
|
|
78
|
+
this.calls.commandList.push(parameters);
|
|
79
|
+
return this.commandListResponse;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
event: {
|
|
83
|
+
subscribe: async (parameters, options) => {
|
|
84
|
+
this.calls.eventSubscribe.push({ parameters, options });
|
|
85
|
+
return { stream: this.eventStream };
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
mcp: {
|
|
89
|
+
add: async () => ({}),
|
|
90
|
+
connect: async () => ({}),
|
|
91
|
+
},
|
|
92
|
+
permission: {
|
|
93
|
+
reply: async (parameters) => {
|
|
94
|
+
this.calls.permissionReply.push(parameters);
|
|
95
|
+
return this.permissionReplyResponse;
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
provider: {
|
|
99
|
+
list: async (parameters) => {
|
|
100
|
+
this.calls.providerList.push(parameters);
|
|
101
|
+
return this.providerListImplementation
|
|
102
|
+
? await this.providerListImplementation()
|
|
103
|
+
: this.providerListResponse;
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
question: {
|
|
107
|
+
reject: async (parameters) => {
|
|
108
|
+
this.calls.questionReject.push(parameters);
|
|
109
|
+
return this.questionRejectResponse;
|
|
110
|
+
},
|
|
111
|
+
reply: async (parameters) => {
|
|
112
|
+
this.calls.questionReply.push(parameters);
|
|
113
|
+
return this.questionReplyResponse;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
session: {
|
|
117
|
+
abort: async (parameters) => {
|
|
118
|
+
this.calls.sessionAbort.push(parameters);
|
|
119
|
+
return this.sessionAbortResponse;
|
|
120
|
+
},
|
|
121
|
+
command: async (parameters) => {
|
|
122
|
+
this.calls.sessionCommand.push(parameters);
|
|
123
|
+
if (this.sessionCommandError) {
|
|
124
|
+
throw this.sessionCommandError;
|
|
125
|
+
}
|
|
126
|
+
return this.sessionCommandResponse;
|
|
127
|
+
},
|
|
128
|
+
create: async (parameters) => {
|
|
129
|
+
this.calls.sessionCreate.push(parameters);
|
|
130
|
+
return this.sessionCreateResponse;
|
|
131
|
+
},
|
|
132
|
+
delete: async (parameters) => {
|
|
133
|
+
this.calls.sessionDelete.push(parameters);
|
|
134
|
+
return this.sessionDeleteResponse;
|
|
135
|
+
},
|
|
136
|
+
messages: async (parameters) => {
|
|
137
|
+
this.calls.sessionMessages.push(parameters);
|
|
138
|
+
return this.sessionMessagesResponse;
|
|
139
|
+
},
|
|
140
|
+
promptAsync: async (parameters) => {
|
|
141
|
+
this.calls.sessionPromptAsync.push(parameters);
|
|
142
|
+
return this.sessionPromptAsyncResponse;
|
|
143
|
+
},
|
|
144
|
+
summarize: async (parameters) => {
|
|
145
|
+
this.calls.sessionSummarize.push(parameters);
|
|
146
|
+
return this.sessionSummarizeResponse;
|
|
147
|
+
},
|
|
148
|
+
update: async (parameters) => {
|
|
149
|
+
this.calls.sessionUpdate.push(parameters);
|
|
150
|
+
return this.sessionUpdateResponse;
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export function createEventStream(events) {
|
|
157
|
+
return (async function* () {
|
|
158
|
+
for (const event of events) {
|
|
159
|
+
yield event;
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
162
|
+
}
|
|
163
|
+
export function idleEvent() {
|
|
164
|
+
return {
|
|
165
|
+
type: "session.idle",
|
|
166
|
+
properties: { sessionID: "session-1" },
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=test-opencode-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-opencode-runtime.js","sourceRoot":"","sources":["../../../../../../../src/server/agent/providers/opencode/test-utils/test-opencode-runtime.ts"],"names":[],"mappings":"AASA,MAAM,OAAO,mBAAmB;IAAhC;QACW,iBAAY,GAAoD,EAAE,CAAC;QACnE,oBAAe,GAAkD,EAAE,CAAC;QAC5D,YAAO,GA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AE,EAAE;oBACzC,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBAC/C,OAAO,IAAI,CAAC,0BAA0B,CAAC;gBACzC,CAAC;gBACD,SAAS,EAAE,KAAK,EAAE,UAAmB,EAAE,EAAE;oBACvC,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBAC7C,OAAO,IAAI,CAAC,wBAAwB,CAAC;gBACvC,CAAC;gBACD,MAAM,EAAE,KAAK,EAAE,UAAmB,EAAE,EAAE;oBACpC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;oBAC1C,OAAO,IAAI,CAAC,qBAAqB,CAAC;gBACpC,CAAC;aACF;SAC2B,CAAC;IACjC,CAAC;CACF;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAiB;IACjD,OAAO,CAAC,KAAK,SAAS,CAAC;QACrB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC,CAAC,EAAE,CAAC;AACP,CAAC;AAED,MAAM,UAAU,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,cAAc;QACpB,UAAU,EAAE,EAAE,SAAS,EAAE,WAAW,EAAE;KACvC,CAAC;AACJ,CAAC"}
|
|
@@ -2,6 +2,7 @@ import { type AssistantMessage as OpenCodeAssistantMessage, type Event as OpenCo
|
|
|
2
2
|
import type { Logger } from "pino";
|
|
3
3
|
import type { AgentCapabilityFlags, AgentClient, AgentCreateSessionOptions, AgentLaunchContext, AgentMode, AgentModelDefinition, AgentPermissionRequest, AgentPermissionResponse, AgentPersistenceHandle, AgentPromptInput, AgentRunOptions, AgentRunResult, AgentRuntimeInfo, AgentSession, AgentSessionConfig, AgentSlashCommand, AgentStreamEvent, AgentUsage, ListModelsOptions, ListModesOptions, ListPersistedAgentsOptions, PersistedAgentDescriptor, ToolCallTimelineItem } from "../agent-sdk-types.js";
|
|
4
4
|
import { type ProviderRuntimeSettings } from "../provider-launch-config.js";
|
|
5
|
+
import { type OpenCodeRuntime } from "./opencode/runtime.js";
|
|
5
6
|
type OpenCodeAgentConfig = AgentSessionConfig & {
|
|
6
7
|
provider: "opencode";
|
|
7
8
|
};
|
|
@@ -82,49 +83,18 @@ export declare const __openCodeInternals: {
|
|
|
82
83
|
isSelectableOpenCodeAgent: typeof isSelectableOpenCodeAgent;
|
|
83
84
|
readonly OpenCodeAgentSession: typeof OpenCodeAgentSession;
|
|
84
85
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
private static exitHandlerRegistered;
|
|
88
|
-
private currentServer;
|
|
89
|
-
private retiredServers;
|
|
90
|
-
private startPromise;
|
|
91
|
-
private forcedRefreshPromise;
|
|
92
|
-
private readonly logger;
|
|
93
|
-
private readonly runtimeSettings?;
|
|
94
|
-
private readonly runtimeSettingsKey;
|
|
95
|
-
private constructor();
|
|
96
|
-
static getInstance(logger: Logger, runtimeSettings?: ProviderRuntimeSettings): OpenCodeServerManager;
|
|
97
|
-
private static registerExitHandler;
|
|
98
|
-
ensureRunning(): Promise<{
|
|
99
|
-
port: number;
|
|
100
|
-
url: string;
|
|
101
|
-
}>;
|
|
102
|
-
acquire(options: {
|
|
103
|
-
force: boolean;
|
|
104
|
-
}): Promise<{
|
|
105
|
-
server: {
|
|
106
|
-
port: number;
|
|
107
|
-
url: string;
|
|
108
|
-
};
|
|
109
|
-
release: () => void;
|
|
110
|
-
}>;
|
|
111
|
-
private getForcedRefreshServer;
|
|
112
|
-
private getCurrentServer;
|
|
113
|
-
private rotateCurrentServer;
|
|
114
|
-
private startServer;
|
|
115
|
-
shutdown(): Promise<void>;
|
|
116
|
-
private cleanupRetiredServers;
|
|
117
|
-
private killServer;
|
|
86
|
+
interface OpenCodeAgentClientDeps {
|
|
87
|
+
runtime?: OpenCodeRuntime;
|
|
118
88
|
}
|
|
119
89
|
export declare class OpenCodeAgentClient implements AgentClient {
|
|
120
90
|
readonly provider: "opencode";
|
|
121
91
|
readonly capabilities: AgentCapabilityFlags;
|
|
122
|
-
private readonly
|
|
92
|
+
private readonly runtime;
|
|
123
93
|
private readonly logger;
|
|
124
94
|
private readonly runtimeSettings?;
|
|
125
95
|
private readonly modelContextWindows;
|
|
126
96
|
private readonly storageRoot;
|
|
127
|
-
constructor(logger: Logger, runtimeSettings?: ProviderRuntimeSettings, storageRoot?: string);
|
|
97
|
+
constructor(logger: Logger, runtimeSettings?: ProviderRuntimeSettings, storageRoot?: string, deps?: OpenCodeAgentClientDeps);
|
|
128
98
|
createSession(config: AgentSessionConfig, _launchContext?: AgentLaunchContext, options?: AgentCreateSessionOptions): Promise<AgentSession>;
|
|
129
99
|
resumeSession(handle: AgentPersistenceHandle, overrides?: Partial<AgentSessionConfig>, _launchContext?: AgentLaunchContext): Promise<AgentSession>;
|
|
130
100
|
listModels(options: ListModelsOptions): Promise<AgentModelDefinition[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"opencode-agent.d.ts","sourceRoot":"","sources":["../../../../../src/server/agent/providers/opencode-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"opencode-agent.d.ts","sourceRoot":"","sources":["../../../../../src/server/agent/providers/opencode-agent.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,gBAAgB,IAAI,wBAAwB,EACjD,KAAK,KAAK,IAAI,aAAa,EAC3B,KAAK,aAAa,IAAI,qBAAqB,EAC3C,KAAK,cAAc,EAEnB,KAAK,aAAa,IAAI,qBAAqB,EAC5C,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EACV,oBAAoB,EACpB,WAAW,EACX,yBAAyB,EACzB,kBAAkB,EAClB,SAAS,EACT,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,gBAAgB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 @@
|
|
|
1
1
|
import { readdir, readFile } from "node:fs/promises";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { createOpencodeClient, } from "@opencode-ai/sdk/v2/client";
|
|
5
|
-
import net from "node:net";
|
|
6
|
-
import { z } from "zod";
|
|
7
|
-
import { createProviderEnvSpec, resolveProviderCommandPrefix, } from "../provider-launch-config.js";
|
|
8
4
|
import { findExecutable, isCommandAvailable } from "../../../utils/executable.js";
|
|
9
|
-
import {
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { createProviderEnvSpec } from "../provider-launch-config.js";
|
|
10
7
|
import { withTimeout } from "../../../utils/promise-timeout.js";
|
|
11
|
-
import { execCommand
|
|
8
|
+
import { execCommand } from "../../../utils/spawn.js";
|
|
12
9
|
import { buildToolCallDisplayModel } from "../../../shared/tool-call-display.js";
|
|
13
10
|
import { mapOpencodeToolCall } from "./opencode/tool-call-mapper.js";
|
|
11
|
+
import { OpenCodeServerManager } from "./opencode/server-manager.js";
|
|
14
12
|
import { formatDiagnosticStatus, formatProviderDiagnostic, formatProviderDiagnosticError, resolveBinaryVersion, toDiagnosticErrorMessage, } from "./diagnostic-utils.js";
|
|
15
13
|
import { runProviderTurn } from "./provider-runner.js";
|
|
16
14
|
import { renderPromptAttachmentAsText } from "../prompt-attachments.js";
|
|
15
|
+
import { createSdkOpenCodeClient, } from "./opencode/runtime.js";
|
|
17
16
|
const OPENCODE_CAPABILITIES = {
|
|
18
17
|
supportsStreaming: true,
|
|
19
18
|
supportsSessionPersistence: true,
|
|
@@ -82,8 +81,6 @@ const OpenCodeStoredPartSchema = z
|
|
|
82
81
|
.passthrough();
|
|
83
82
|
const MCP_ALREADY_PRESENT_ERROR_TOKENS = ["already", "exists", "connected"];
|
|
84
83
|
const OPENCODE_PROVIDER_LIST_TIMEOUT_MS = 30000;
|
|
85
|
-
const OPENCODE_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
86
|
-
const OPENCODE_SERVER_FORCE_SHUTDOWN_TIMEOUT_MS = 1000;
|
|
87
84
|
const OPENCODE_HANDLED_BUILTIN_SLASH_COMMANDS = [
|
|
88
85
|
{ name: "compact", description: "Compact the current session", argumentHint: "" },
|
|
89
86
|
{ name: "summarize", description: "Compact the current session", argumentHint: "" },
|
|
@@ -162,13 +159,6 @@ const OpencodeToolPartToTimelineItemSchema = OpencodeToolPartTimelineEnvelopeSch
|
|
|
162
159
|
output: part.output,
|
|
163
160
|
error: part.error,
|
|
164
161
|
}));
|
|
165
|
-
async function resolveOpenCodeBinary() {
|
|
166
|
-
const found = await findExecutable("opencode");
|
|
167
|
-
if (found) {
|
|
168
|
-
return found;
|
|
169
|
-
}
|
|
170
|
-
throw new Error("OpenCode binary not found. Install OpenCode (https://github.com/opencode-ai/opencode) and ensure it is available in your shell PATH.");
|
|
171
|
-
}
|
|
172
162
|
function toOpenCodeMcpConfig(config) {
|
|
173
163
|
if (config.type === "stdio") {
|
|
174
164
|
return {
|
|
@@ -278,22 +268,6 @@ function isAlreadyPresentMcpError(error) {
|
|
|
278
268
|
const normalized = toDiagnosticErrorMessage(error).toLowerCase();
|
|
279
269
|
return MCP_ALREADY_PRESENT_ERROR_TOKENS.some((token) => normalized.includes(token));
|
|
280
270
|
}
|
|
281
|
-
async function findAvailablePort() {
|
|
282
|
-
return new Promise((resolve, reject) => {
|
|
283
|
-
const server = net.createServer();
|
|
284
|
-
server.listen(0, () => {
|
|
285
|
-
const address = server.address();
|
|
286
|
-
if (address && typeof address === "object") {
|
|
287
|
-
const port = address.port;
|
|
288
|
-
server.close(() => resolve(port));
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
server.close(() => reject(new Error("Failed to get port")));
|
|
292
|
-
}
|
|
293
|
-
});
|
|
294
|
-
server.on("error", reject);
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
271
|
function resolvePartDedupeKey(part, partType) {
|
|
298
272
|
if (part.id.trim().length > 0) {
|
|
299
273
|
return `${partType}:${part.id}`;
|
|
@@ -670,244 +644,40 @@ export const __openCodeInternals = {
|
|
|
670
644
|
return OpenCodeAgentSession;
|
|
671
645
|
},
|
|
672
646
|
};
|
|
673
|
-
|
|
674
|
-
constructor(
|
|
675
|
-
this.
|
|
676
|
-
this.retiredServers = new Set();
|
|
677
|
-
this.startPromise = null;
|
|
678
|
-
this.forcedRefreshPromise = null;
|
|
679
|
-
this.logger = logger;
|
|
680
|
-
this.runtimeSettings = runtimeSettings;
|
|
681
|
-
this.runtimeSettingsKey = JSON.stringify(runtimeSettings ?? {});
|
|
647
|
+
class ProductionOpenCodeRuntime {
|
|
648
|
+
constructor(serverManager) {
|
|
649
|
+
this.serverManager = serverManager;
|
|
682
650
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
if (!OpenCodeServerManager.instance) {
|
|
686
|
-
OpenCodeServerManager.instance = new OpenCodeServerManager(logger, runtimeSettings);
|
|
687
|
-
OpenCodeServerManager.registerExitHandler();
|
|
688
|
-
}
|
|
689
|
-
else if (OpenCodeServerManager.instance.runtimeSettingsKey !== nextSettingsKey) {
|
|
690
|
-
logger.warn({
|
|
691
|
-
existingRuntimeSettings: OpenCodeServerManager.instance.runtimeSettingsKey,
|
|
692
|
-
requestedRuntimeSettings: nextSettingsKey,
|
|
693
|
-
}, "OpenCode server manager already initialized with different runtime settings");
|
|
694
|
-
}
|
|
695
|
-
return OpenCodeServerManager.instance;
|
|
651
|
+
async acquireServer(options) {
|
|
652
|
+
return this.serverManager.acquire(options);
|
|
696
653
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
return;
|
|
700
|
-
}
|
|
701
|
-
OpenCodeServerManager.exitHandlerRegistered = true;
|
|
702
|
-
const cleanup = () => {
|
|
703
|
-
const instance = OpenCodeServerManager.instance;
|
|
704
|
-
void instance?.shutdown();
|
|
705
|
-
};
|
|
706
|
-
process.on("exit", cleanup);
|
|
707
|
-
process.on("SIGTERM", cleanup);
|
|
708
|
-
process.on("SIGINT", cleanup);
|
|
709
|
-
}
|
|
710
|
-
async ensureRunning() {
|
|
711
|
-
const acquisition = await this.acquire({ force: false });
|
|
712
|
-
acquisition.release();
|
|
713
|
-
return acquisition.server;
|
|
714
|
-
}
|
|
715
|
-
async acquire(options) {
|
|
716
|
-
const server = options.force
|
|
717
|
-
? await this.getForcedRefreshServer()
|
|
718
|
-
: await this.getCurrentServer();
|
|
719
|
-
server.refCount += 1;
|
|
720
|
-
let released = false;
|
|
721
|
-
return {
|
|
722
|
-
server: { port: server.port, url: server.url },
|
|
723
|
-
release: () => {
|
|
724
|
-
if (released) {
|
|
725
|
-
return;
|
|
726
|
-
}
|
|
727
|
-
released = true;
|
|
728
|
-
server.refCount -= 1;
|
|
729
|
-
this.cleanupRetiredServers();
|
|
730
|
-
},
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
async getForcedRefreshServer() {
|
|
734
|
-
if (this.forcedRefreshPromise) {
|
|
735
|
-
return this.forcedRefreshPromise;
|
|
736
|
-
}
|
|
737
|
-
this.forcedRefreshPromise = Promise.resolve()
|
|
738
|
-
.then(async () => {
|
|
739
|
-
await this.rotateCurrentServer();
|
|
740
|
-
return this.getCurrentServer();
|
|
741
|
-
})
|
|
742
|
-
.finally(() => {
|
|
743
|
-
this.forcedRefreshPromise = null;
|
|
744
|
-
});
|
|
745
|
-
return this.forcedRefreshPromise;
|
|
654
|
+
async ensureServerRunning() {
|
|
655
|
+
return this.serverManager.ensureRunning();
|
|
746
656
|
}
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
return this.startPromise;
|
|
750
|
-
}
|
|
751
|
-
if (this.currentServer && !this.currentServer.process.killed) {
|
|
752
|
-
return this.currentServer;
|
|
753
|
-
}
|
|
754
|
-
this.startPromise = this.startServer();
|
|
755
|
-
try {
|
|
756
|
-
const result = await this.startPromise;
|
|
757
|
-
if (!result.retired) {
|
|
758
|
-
this.currentServer = result;
|
|
759
|
-
}
|
|
760
|
-
return result;
|
|
761
|
-
}
|
|
762
|
-
finally {
|
|
763
|
-
this.startPromise = null;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
async rotateCurrentServer() {
|
|
767
|
-
const existing = this.currentServer;
|
|
768
|
-
if (existing) {
|
|
769
|
-
existing.retired = true;
|
|
770
|
-
this.retiredServers.add(existing);
|
|
771
|
-
this.currentServer = null;
|
|
772
|
-
this.cleanupRetiredServers();
|
|
773
|
-
}
|
|
774
|
-
if (this.startPromise) {
|
|
775
|
-
const pending = await this.startPromise;
|
|
776
|
-
pending.retired = true;
|
|
777
|
-
this.retiredServers.add(pending);
|
|
778
|
-
this.currentServer = null;
|
|
779
|
-
this.cleanupRetiredServers();
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
async startServer() {
|
|
783
|
-
const port = await findAvailablePort();
|
|
784
|
-
const url = `http://127.0.0.1:${port}`;
|
|
785
|
-
const launchPrefix = await resolveProviderCommandPrefix(this.runtimeSettings?.command, resolveOpenCodeBinary);
|
|
786
|
-
return new Promise((resolve, reject) => {
|
|
787
|
-
const serverProcess = spawnProcess(launchPrefix.command, [...launchPrefix.args, "serve", "--port", String(port)], {
|
|
788
|
-
detached: process.platform !== "win32",
|
|
789
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
790
|
-
...createProviderEnvSpec({ runtimeSettings: this.runtimeSettings }),
|
|
791
|
-
});
|
|
792
|
-
let started = false;
|
|
793
|
-
let stderrBuffer = "";
|
|
794
|
-
let stdoutBuffer = "";
|
|
795
|
-
const STARTUP_BUFFER_CAP = 8192;
|
|
796
|
-
const appendCapped = (current, chunk) => {
|
|
797
|
-
if (current.length >= STARTUP_BUFFER_CAP) {
|
|
798
|
-
return current;
|
|
799
|
-
}
|
|
800
|
-
const remaining = STARTUP_BUFFER_CAP - current.length;
|
|
801
|
-
return current + chunk.slice(0, remaining);
|
|
802
|
-
};
|
|
803
|
-
const buildStartupErrorMessage = (headline) => {
|
|
804
|
-
const sections = [headline];
|
|
805
|
-
const stderrTrimmed = stderrBuffer.trim();
|
|
806
|
-
if (stderrTrimmed.length > 0) {
|
|
807
|
-
sections.push(`stderr: ${stderrTrimmed}`);
|
|
808
|
-
}
|
|
809
|
-
const stdoutTrimmed = stdoutBuffer.trim();
|
|
810
|
-
if (stdoutTrimmed.length > 0) {
|
|
811
|
-
sections.push(`stdout: ${stdoutTrimmed}`);
|
|
812
|
-
}
|
|
813
|
-
return sections.join("\n");
|
|
814
|
-
};
|
|
815
|
-
const timeout = setTimeout(() => {
|
|
816
|
-
if (!started) {
|
|
817
|
-
reject(new Error(buildStartupErrorMessage("OpenCode server startup timeout")));
|
|
818
|
-
}
|
|
819
|
-
}, 30000);
|
|
820
|
-
serverProcess.stdout?.on("data", (data) => {
|
|
821
|
-
const output = data.toString();
|
|
822
|
-
stdoutBuffer = appendCapped(stdoutBuffer, output);
|
|
823
|
-
if (output.includes("listening on") && !started) {
|
|
824
|
-
started = true;
|
|
825
|
-
clearTimeout(timeout);
|
|
826
|
-
resolve({
|
|
827
|
-
process: serverProcess,
|
|
828
|
-
port,
|
|
829
|
-
url,
|
|
830
|
-
refCount: 0,
|
|
831
|
-
retired: false,
|
|
832
|
-
});
|
|
833
|
-
}
|
|
834
|
-
});
|
|
835
|
-
serverProcess.stderr?.on("data", (data) => {
|
|
836
|
-
const output = data.toString();
|
|
837
|
-
stderrBuffer = appendCapped(stderrBuffer, output);
|
|
838
|
-
this.logger.error({ stderr: output.trim() }, "OpenCode server stderr");
|
|
839
|
-
});
|
|
840
|
-
serverProcess.on("error", (error) => {
|
|
841
|
-
clearTimeout(timeout);
|
|
842
|
-
const headline = error instanceof Error ? error.message : String(error);
|
|
843
|
-
reject(new Error(buildStartupErrorMessage(headline)));
|
|
844
|
-
});
|
|
845
|
-
serverProcess.on("exit", (code) => {
|
|
846
|
-
if (!started) {
|
|
847
|
-
clearTimeout(timeout);
|
|
848
|
-
reject(new Error(buildStartupErrorMessage(`OpenCode server exited with code ${code}`)));
|
|
849
|
-
}
|
|
850
|
-
if (this.currentServer?.process === serverProcess) {
|
|
851
|
-
this.currentServer = null;
|
|
852
|
-
}
|
|
853
|
-
for (const retired of Array.from(this.retiredServers)) {
|
|
854
|
-
if (retired.process === serverProcess) {
|
|
855
|
-
this.retiredServers.delete(retired);
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
});
|
|
859
|
-
});
|
|
657
|
+
createClient(options) {
|
|
658
|
+
return createSdkOpenCodeClient(options);
|
|
860
659
|
}
|
|
861
660
|
async shutdown() {
|
|
862
|
-
|
|
863
|
-
...(this.currentServer ? [this.currentServer] : []),
|
|
864
|
-
...Array.from(this.retiredServers),
|
|
865
|
-
];
|
|
866
|
-
await Promise.all(servers.map((server) => this.killServer(server)));
|
|
867
|
-
this.currentServer = null;
|
|
868
|
-
this.retiredServers.clear();
|
|
869
|
-
}
|
|
870
|
-
cleanupRetiredServers() {
|
|
871
|
-
for (const server of Array.from(this.retiredServers)) {
|
|
872
|
-
if (server.refCount === 0) {
|
|
873
|
-
this.retiredServers.delete(server);
|
|
874
|
-
void this.killServer(server);
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
async killServer(server) {
|
|
879
|
-
if (server.process.killed) {
|
|
880
|
-
return;
|
|
881
|
-
}
|
|
882
|
-
const result = await terminateWithTreeKill(server.process, {
|
|
883
|
-
gracefulTimeoutMs: OPENCODE_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT_MS,
|
|
884
|
-
forceTimeoutMs: OPENCODE_SERVER_FORCE_SHUTDOWN_TIMEOUT_MS,
|
|
885
|
-
onForceSignal: () => {
|
|
886
|
-
this.logger.warn({ timeoutMs: OPENCODE_SERVER_GRACEFUL_SHUTDOWN_TIMEOUT_MS }, "OpenCode server did not exit after SIGTERM; sending SIGKILL");
|
|
887
|
-
},
|
|
888
|
-
});
|
|
889
|
-
if (result === "kill-timeout") {
|
|
890
|
-
this.logger.warn({ timeoutMs: OPENCODE_SERVER_FORCE_SHUTDOWN_TIMEOUT_MS }, "OpenCode server did not report exit after SIGKILL");
|
|
891
|
-
}
|
|
661
|
+
await this.serverManager.shutdown();
|
|
892
662
|
}
|
|
893
663
|
}
|
|
894
|
-
OpenCodeServerManager.instance = null;
|
|
895
|
-
OpenCodeServerManager.exitHandlerRegistered = false;
|
|
896
664
|
export class OpenCodeAgentClient {
|
|
897
|
-
constructor(logger, runtimeSettings, storageRoot) {
|
|
665
|
+
constructor(logger, runtimeSettings, storageRoot, deps = {}) {
|
|
898
666
|
this.provider = "opencode";
|
|
899
667
|
this.capabilities = OPENCODE_CAPABILITIES;
|
|
900
668
|
this.modelContextWindows = new Map();
|
|
901
669
|
this.logger = logger.child({ module: "agent", provider: "opencode" });
|
|
902
670
|
this.runtimeSettings = runtimeSettings;
|
|
903
671
|
this.storageRoot = storageRoot ?? resolveOpenCodeStorageRoot();
|
|
904
|
-
this.
|
|
672
|
+
this.runtime =
|
|
673
|
+
deps.runtime ??
|
|
674
|
+
new ProductionOpenCodeRuntime(OpenCodeServerManager.getInstance(this.logger, runtimeSettings));
|
|
905
675
|
}
|
|
906
676
|
async createSession(config, _launchContext, options) {
|
|
907
677
|
const openCodeConfig = this.assertConfig(config);
|
|
908
|
-
const acquisition = await this.
|
|
678
|
+
const acquisition = await this.runtime.acquireServer({ force: false });
|
|
909
679
|
const { url } = acquisition.server;
|
|
910
|
-
const client =
|
|
680
|
+
const client = this.runtime.createClient({
|
|
911
681
|
baseUrl: url,
|
|
912
682
|
directory: openCodeConfig.cwd,
|
|
913
683
|
});
|
|
@@ -939,9 +709,9 @@ export class OpenCodeAgentClient {
|
|
|
939
709
|
...overrides,
|
|
940
710
|
};
|
|
941
711
|
const openCodeConfig = this.assertConfig(config);
|
|
942
|
-
const acquisition = await this.
|
|
712
|
+
const acquisition = await this.runtime.acquireServer({ force: false });
|
|
943
713
|
const { url } = acquisition.server;
|
|
944
|
-
const client =
|
|
714
|
+
const client = this.runtime.createClient({
|
|
945
715
|
baseUrl: url,
|
|
946
716
|
directory: openCodeConfig.cwd,
|
|
947
717
|
});
|
|
@@ -955,9 +725,9 @@ export class OpenCodeAgentClient {
|
|
|
955
725
|
}
|
|
956
726
|
}
|
|
957
727
|
async listModels(options) {
|
|
958
|
-
const acquisition = await this.
|
|
728
|
+
const acquisition = await this.runtime.acquireServer({ force: options.force });
|
|
959
729
|
const { url } = acquisition.server;
|
|
960
|
-
const client =
|
|
730
|
+
const client = this.runtime.createClient({
|
|
961
731
|
baseUrl: url,
|
|
962
732
|
directory: options.cwd,
|
|
963
733
|
});
|
|
@@ -1001,10 +771,10 @@ export class OpenCodeAgentClient {
|
|
|
1001
771
|
}
|
|
1002
772
|
}
|
|
1003
773
|
async listModes(options) {
|
|
1004
|
-
const acquisition = await this.
|
|
774
|
+
const acquisition = await this.runtime.acquireServer({ force: options.force });
|
|
1005
775
|
const { url } = acquisition.server;
|
|
1006
776
|
const directory = options.cwd;
|
|
1007
|
-
const client =
|
|
777
|
+
const client = this.runtime.createClient({ baseUrl: url, directory });
|
|
1008
778
|
try {
|
|
1009
779
|
const response = await withTimeout(client.app.agents({ directory }), 10000, "OpenCode app.agents timed out after 10s");
|
|
1010
780
|
if (response.error || !response.data) {
|
|
@@ -1041,7 +811,7 @@ export class OpenCodeAgentClient {
|
|
|
1041
811
|
let modelsValue = "Not checked";
|
|
1042
812
|
let status = formatDiagnosticStatus(available);
|
|
1043
813
|
try {
|
|
1044
|
-
const { url } = await this.
|
|
814
|
+
const { url } = await this.runtime.ensureServerRunning();
|
|
1045
815
|
serverStatus = `Running (${url})`;
|
|
1046
816
|
}
|
|
1047
817
|
catch (error) {
|