shuvcode 2.0.23-shuv.1 → 2.0.24-shuv.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.
- package/client/generated/types.d.ts +28 -2
- package/client/service.d.ts +2 -4
- package/client/service.js +15 -113
- package/package.json +13 -13
|
@@ -1288,6 +1288,32 @@ export type SessionToolInputEnded = {
|
|
|
1288
1288
|
text: string;
|
|
1289
1289
|
};
|
|
1290
1290
|
};
|
|
1291
|
+
export type SessionToolSubagentPrepared = {
|
|
1292
|
+
id: string;
|
|
1293
|
+
created: number;
|
|
1294
|
+
metadata?: {
|
|
1295
|
+
[x: string]: any;
|
|
1296
|
+
};
|
|
1297
|
+
type: "session.tool.subagent.prepared";
|
|
1298
|
+
durable: {
|
|
1299
|
+
aggregateID: string;
|
|
1300
|
+
seq: number;
|
|
1301
|
+
version: 1;
|
|
1302
|
+
};
|
|
1303
|
+
location?: LocationRef;
|
|
1304
|
+
data: {
|
|
1305
|
+
sessionID: string;
|
|
1306
|
+
assistantMessageID: string;
|
|
1307
|
+
id: string;
|
|
1308
|
+
recovery: {
|
|
1309
|
+
childSessionID: string;
|
|
1310
|
+
inboxID: string;
|
|
1311
|
+
inputDigest: string;
|
|
1312
|
+
agent: string;
|
|
1313
|
+
model?: ModelRef;
|
|
1314
|
+
};
|
|
1315
|
+
};
|
|
1316
|
+
};
|
|
1291
1317
|
export type SessionRetryScheduled = {
|
|
1292
1318
|
id: string;
|
|
1293
1319
|
created: number;
|
|
@@ -3358,7 +3384,7 @@ export type SessionMessagesResponse = {
|
|
|
3358
3384
|
next?: string | null;
|
|
3359
3385
|
};
|
|
3360
3386
|
};
|
|
3361
|
-
export type SessionEventDurable = SessionCreated | SessionAgentSelected | SessionModelSelected | SessionMoved | SessionRenamed | SessionMetadataUpdated | SessionPermissions | SessionViewed | SessionDeleted | SessionForked | SessionInboxDelivered | SessionInboxEnqueued | SessionInboxCancelled | SessionInboxDeliveryChanged | SessionExecutionStarted | SessionExecutionSucceeded | SessionExecutionFailed | SessionExecutionInterrupted | SessionInstructionsUpdated | SessionSynthetic | SessionSkillActivated | SessionShellStarted | SessionShellEnded | SessionStepStarted | SessionStepStreamed | SessionStepEnded | SessionStepFailed | SessionTextStarted | SessionTextEnded | SessionReasoningStarted | SessionReasoningEnded | SessionToolInputStarted | SessionToolInputEnded | SessionToolCalled | SessionToolSuccess | SessionToolFailed | SessionRetryScheduled | SessionCompactionStarted | SessionCompactionEnded | SessionCompactionFailed | SessionRevertStaged | SessionRevertCleared | SessionRevertCommitted | SessionUsageRecorded | SessionMessageContentUpdated;
|
|
3387
|
+
export type SessionEventDurable = SessionCreated | SessionAgentSelected | SessionModelSelected | SessionMoved | SessionRenamed | SessionMetadataUpdated | SessionPermissions | SessionViewed | SessionDeleted | SessionForked | SessionInboxDelivered | SessionInboxEnqueued | SessionInboxCancelled | SessionInboxDeliveryChanged | SessionExecutionStarted | SessionExecutionSucceeded | SessionExecutionFailed | SessionExecutionInterrupted | SessionInstructionsUpdated | SessionSynthetic | SessionSkillActivated | SessionShellStarted | SessionShellEnded | SessionStepStarted | SessionStepStreamed | SessionStepEnded | SessionStepFailed | SessionTextStarted | SessionTextEnded | SessionReasoningStarted | SessionReasoningEnded | SessionToolInputStarted | SessionToolInputEnded | SessionToolCalled | SessionToolSubagentPrepared | SessionToolSuccess | SessionToolFailed | SessionRetryScheduled | SessionCompactionStarted | SessionCompactionEnded | SessionCompactionFailed | SessionRevertStaged | SessionRevertCleared | SessionRevertCommitted | SessionUsageRecorded | SessionMessageContentUpdated;
|
|
3362
3388
|
export type IntegrationInfo = {
|
|
3363
3389
|
id: string;
|
|
3364
3390
|
name: string;
|
|
@@ -3368,7 +3394,7 @@ export type IntegrationInfo = {
|
|
|
3368
3394
|
methods: Array<IntegrationMethod>;
|
|
3369
3395
|
connections: Array<ConnectionInfo>;
|
|
3370
3396
|
};
|
|
3371
|
-
export type V2Event = LocationShutdown | ModelsDevRefreshed | CredentialUpdated | CredentialSwitched | IntegrationUpdated | ProviderUpdated | ModelUpdated | AgentUpdated | SessionCreated | SessionAgentSelected | SessionModelSelected | SessionMoved | SessionRenamed | SessionMetadataUpdated | SessionPermissions | SessionViewed | SessionUsageUpdated | SessionDeleted | SessionForked | SessionInboxDelivered | SessionInboxEnqueued | SessionInboxCancelled | SessionInboxDeliveryChanged | SessionExecutionStarted | SessionExecutionSucceeded | SessionExecutionFailed | SessionExecutionInterrupted | SessionInstructionsUpdated | SessionSynthetic | SessionSkillActivated | SessionShellStarted | SessionShellEnded | SessionStepStarted | SessionStepStreamed | SessionStepEnded | SessionStepFailed | SessionTextStarted | SessionTextDelta | SessionTextEnded | SessionReasoningStarted | SessionReasoningDelta | SessionReasoningEnded | SessionToolInputStarted | SessionToolInputDelta | SessionToolInputEnded | SessionToolCalled | SessionToolProgress | SessionToolSuccess | SessionToolFailed | SessionRetryScheduled | SessionCompactionStarted | SessionCompactionDelta | SessionCompactionEnded | SessionCompactionFailed | SessionRevertStaged | SessionRevertCleared | SessionRevertCommitted | FilesystemChanged | ReferenceUpdated | PermissionAsked | PermissionReplied | PermissionCancelled | PluginUpdated | ProjectUpdated | WorktreeUpdated | WorktreeResolved | CommandUpdated | ConfigUpdated | SkillUpdated | PtyCreated | PtyUpdated | PtyExited | PtyDeleted | PersistentPtyAdded | PersistentPtyRemoved | ShellCreated | ShellExited | ShellDeleted | FormCreated | FormReplied | FormCancelled | WebsearchUpdated | SessionStatusUpdated | SessionIdle | TuiPromptAppend | TuiCommandExecute | TuiToastShow | TuiSessionSelect | InstallationUpdated | InstallationUpdateAvailable | VcsBranchUpdated | McpStatusChanged | McpResourcesChanged | V2EventRpc | V2EventServerConnected;
|
|
3397
|
+
export type V2Event = LocationShutdown | ModelsDevRefreshed | CredentialUpdated | CredentialSwitched | IntegrationUpdated | ProviderUpdated | ModelUpdated | AgentUpdated | SessionCreated | SessionAgentSelected | SessionModelSelected | SessionMoved | SessionRenamed | SessionMetadataUpdated | SessionPermissions | SessionViewed | SessionUsageUpdated | SessionDeleted | SessionForked | SessionInboxDelivered | SessionInboxEnqueued | SessionInboxCancelled | SessionInboxDeliveryChanged | SessionExecutionStarted | SessionExecutionSucceeded | SessionExecutionFailed | SessionExecutionInterrupted | SessionInstructionsUpdated | SessionSynthetic | SessionSkillActivated | SessionShellStarted | SessionShellEnded | SessionStepStarted | SessionStepStreamed | SessionStepEnded | SessionStepFailed | SessionTextStarted | SessionTextDelta | SessionTextEnded | SessionReasoningStarted | SessionReasoningDelta | SessionReasoningEnded | SessionToolInputStarted | SessionToolInputDelta | SessionToolInputEnded | SessionToolCalled | SessionToolSubagentPrepared | SessionToolProgress | SessionToolSuccess | SessionToolFailed | SessionRetryScheduled | SessionCompactionStarted | SessionCompactionDelta | SessionCompactionEnded | SessionCompactionFailed | SessionRevertStaged | SessionRevertCleared | SessionRevertCommitted | FilesystemChanged | ReferenceUpdated | PermissionAsked | PermissionReplied | PermissionCancelled | PluginUpdated | ProjectUpdated | WorktreeUpdated | WorktreeResolved | CommandUpdated | ConfigUpdated | SkillUpdated | PtyCreated | PtyUpdated | PtyExited | PtyDeleted | PersistentPtyAdded | PersistentPtyRemoved | ShellCreated | ShellExited | ShellDeleted | FormCreated | FormReplied | FormCancelled | WebsearchUpdated | SessionStatusUpdated | SessionIdle | TuiPromptAppend | TuiCommandExecute | TuiToastShow | TuiSessionSelect | InstallationUpdated | InstallationUpdateAvailable | VcsBranchUpdated | McpStatusChanged | McpResourcesChanged | V2EventRpc | V2EventServerConnected;
|
|
3372
3398
|
export type SessionLogItem = SessionEventDurable | EventLogSynced;
|
|
3373
3399
|
export type InvalidRequestError = {
|
|
3374
3400
|
readonly _tag: "InvalidRequestError";
|
package/client/service.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { DiscoverOptions, Endpoint, EnsureOptions, StopOptions } from "../service.js";
|
|
2
|
+
import { headers } from "../service-probe.js";
|
|
2
3
|
export * from "../service.js";
|
|
4
|
+
export { headers };
|
|
3
5
|
/** Discover a healthy, compatible local service without starting one. */
|
|
4
6
|
export declare function discover(options?: DiscoverOptions): Promise<{
|
|
5
7
|
url: string;
|
|
@@ -13,10 +15,6 @@ export declare function discover(options?: DiscoverOptions): Promise<{
|
|
|
13
15
|
export declare function ensure(options?: EnsureOptions): Promise<Endpoint>;
|
|
14
16
|
/** Stop the registered local service. */
|
|
15
17
|
export declare function stop(options?: StopOptions): Promise<void>;
|
|
16
|
-
/** Create HTTP authentication headers for a service endpoint. */
|
|
17
|
-
export declare function headers(endpoint: Endpoint): {
|
|
18
|
-
authorization: string;
|
|
19
|
-
} | undefined;
|
|
20
18
|
/** Promise-based local service lifecycle operations. */
|
|
21
19
|
export declare const Service: {
|
|
22
20
|
discover: typeof discover;
|
package/client/service.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { readFile, rm } from "node:fs/promises";
|
|
2
|
-
import {
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { contenderFailure, contenderFinished, spawnServiceContender, } from "../service-contender.js";
|
|
2
|
+
import { contenderPool, spawnServiceContender } from "../service-contender.js";
|
|
5
3
|
import { defaultEnsureTiming, ensureTiming } from "../service-timing.js";
|
|
6
4
|
import { matchesVersion } from "../service-version.js";
|
|
7
5
|
import { PtyHandoff } from "../pty-handoff.js";
|
|
6
|
+
import { fallback, headers, probeResult, same } from "../service-probe.js";
|
|
8
7
|
export * from "../service.js";
|
|
8
|
+
export { headers };
|
|
9
9
|
// Find, start, and stop the local opencode background service.
|
|
10
10
|
//
|
|
11
11
|
// The registration file is the complete discovery contract. This module is
|
|
@@ -26,12 +26,9 @@ export async function discover(options = {}) {
|
|
|
26
26
|
export async function ensure(options = {}) {
|
|
27
27
|
const timing = ensureTiming(options);
|
|
28
28
|
const deadline = Date.now() + timing.promiseTimeout;
|
|
29
|
-
const
|
|
29
|
+
const pool = contenderPool(timing);
|
|
30
30
|
let timeouts;
|
|
31
31
|
let announced = false;
|
|
32
|
-
let lastSpawn = 0;
|
|
33
|
-
let spawnDelay = timing.spawnDelay;
|
|
34
|
-
let failure;
|
|
35
32
|
const announce = (reason, previousVersion) => {
|
|
36
33
|
if (announced)
|
|
37
34
|
return;
|
|
@@ -52,7 +49,7 @@ export async function ensure(options = {}) {
|
|
|
52
49
|
try {
|
|
53
50
|
while (true) {
|
|
54
51
|
if (Date.now() >= deadline)
|
|
55
|
-
throw failure ?? new Error("Timed out waiting for the background service to start");
|
|
52
|
+
throw pool.failure() ?? new Error("Timed out waiting for the background service to start");
|
|
56
53
|
const registration = await registered(options.file, timing.requestTimeout);
|
|
57
54
|
if (registration.timedOut && registration.info !== undefined) {
|
|
58
55
|
timeouts = {
|
|
@@ -64,21 +61,15 @@ export async function ensure(options = {}) {
|
|
|
64
61
|
console.warn("Background service is unresponsive; recovery cannot preserve persistent terminals");
|
|
65
62
|
await PtyHandoff.clear(options.file ?? fallback());
|
|
66
63
|
await terminate(registration.info, options, timing);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
item.release();
|
|
70
|
-
contenders.delete(item);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
failure = undefined;
|
|
64
|
+
pool.evict(registration.info.pid);
|
|
65
|
+
pool.recruitNow();
|
|
74
66
|
timeouts = undefined;
|
|
75
|
-
lastSpawn = Date.now() - spawnDelay;
|
|
76
67
|
}
|
|
77
68
|
}
|
|
78
69
|
else
|
|
79
70
|
timeouts = undefined;
|
|
80
71
|
if (registration.service !== undefined) {
|
|
81
|
-
|
|
72
|
+
pool.serviceAnswered();
|
|
82
73
|
const service = registration.service;
|
|
83
74
|
const versionMatches = matchesVersion(service.version, options);
|
|
84
75
|
const compatible = service.compatible && versionMatches;
|
|
@@ -98,40 +89,23 @@ export async function ensure(options = {}) {
|
|
|
98
89
|
file: options.file,
|
|
99
90
|
pty: service.state === "ready" ? "handoff" : "clear",
|
|
100
91
|
}).catch(() => undefined);
|
|
101
|
-
|
|
102
|
-
if (item.child.pid === service.info.pid || contenderFinished(item)) {
|
|
103
|
-
item.release();
|
|
104
|
-
contenders.delete(item);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
failure = undefined;
|
|
108
|
-
lastSpawn = 0;
|
|
92
|
+
pool.evict(service.info.pid);
|
|
109
93
|
}
|
|
110
94
|
}
|
|
111
95
|
else {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (finished.some((item) => item.child.exitCode === 0)) {
|
|
117
|
-
spawnDelay = Math.min(spawnDelay * 2, timing.maxSpawnDelay);
|
|
118
|
-
}
|
|
119
|
-
finished.forEach((item) => contenders.delete(item));
|
|
120
|
-
if (failure !== undefined && contenders.size === 0)
|
|
121
|
-
throw failure;
|
|
122
|
-
// Keep one candidate plus one lock probe for pre-lock stalls. After a failure, let the
|
|
123
|
-
// survivors finish without recruiting replacements that could hide the error indefinitely.
|
|
124
|
-
if (failure === undefined && contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay) {
|
|
96
|
+
const failed = pool.reap();
|
|
97
|
+
if (failed !== undefined)
|
|
98
|
+
throw failed;
|
|
99
|
+
if (pool.shouldRecruit(registration.info !== undefined)) {
|
|
125
100
|
announce("missing");
|
|
126
|
-
|
|
127
|
-
lastSpawn = Date.now();
|
|
101
|
+
pool.add(await spawnContender());
|
|
128
102
|
}
|
|
129
103
|
}
|
|
130
104
|
await delay(timing.pollInterval);
|
|
131
105
|
}
|
|
132
106
|
}
|
|
133
107
|
finally {
|
|
134
|
-
|
|
108
|
+
pool.releaseAll();
|
|
135
109
|
}
|
|
136
110
|
}
|
|
137
111
|
/** Stop the registered local service. */
|
|
@@ -144,17 +118,6 @@ export async function stop(options = {}) {
|
|
|
144
118
|
if (info !== undefined)
|
|
145
119
|
await terminate(info, options, ensureTiming(options));
|
|
146
120
|
}
|
|
147
|
-
function fallback() {
|
|
148
|
-
return join(process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state"), "shuvcode", "service.json");
|
|
149
|
-
}
|
|
150
|
-
/** Create HTTP authentication headers for a service endpoint. */
|
|
151
|
-
export function headers(endpoint) {
|
|
152
|
-
if (endpoint.auth === undefined)
|
|
153
|
-
return undefined;
|
|
154
|
-
return {
|
|
155
|
-
authorization: "Basic " + Buffer.from(endpoint.auth.username + ":" + endpoint.auth.password).toString("base64"),
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
121
|
async function read(file) {
|
|
159
122
|
const text = await readFile(file ?? fallback(), "utf8").catch(() => undefined);
|
|
160
123
|
if (text === undefined)
|
|
@@ -166,64 +129,6 @@ async function read(file) {
|
|
|
166
129
|
return undefined;
|
|
167
130
|
}
|
|
168
131
|
}
|
|
169
|
-
async function probeResult(info, timeout = defaultEnsureTiming.requestTimeout) {
|
|
170
|
-
const endpoint = {
|
|
171
|
-
url: info.url,
|
|
172
|
-
auth: info.password === undefined
|
|
173
|
-
? undefined
|
|
174
|
-
: { type: "basic", username: "opencode", password: info.password },
|
|
175
|
-
};
|
|
176
|
-
const signal = AbortSignal.timeout(timeout);
|
|
177
|
-
const result = await fetch(new URL("/api/info", info.url), { headers: headers(endpoint), signal })
|
|
178
|
-
.then(async (response) => ({
|
|
179
|
-
response,
|
|
180
|
-
body: response.status === 404 ? undefined : (await response.json()),
|
|
181
|
-
}))
|
|
182
|
-
.then((value) => ({ value }), (cause) => ({ cause }));
|
|
183
|
-
if ("cause" in result)
|
|
184
|
-
return { service: undefined, timedOut: signal.aborted };
|
|
185
|
-
const response = result.value.response;
|
|
186
|
-
// A missing health endpoint identifies protocol incompatibility, not an older
|
|
187
|
-
// version. Only an unmet version requirement lets ensure replace this owner.
|
|
188
|
-
if (response.status === 404)
|
|
189
|
-
return {
|
|
190
|
-
service: {
|
|
191
|
-
info,
|
|
192
|
-
endpoint,
|
|
193
|
-
version: info.version,
|
|
194
|
-
state: "ready",
|
|
195
|
-
compatible: false,
|
|
196
|
-
},
|
|
197
|
-
timedOut: false,
|
|
198
|
-
};
|
|
199
|
-
const serverInfo = decodeInfo(result.value.body);
|
|
200
|
-
if (serverInfo !== undefined) {
|
|
201
|
-
if (serverInfo.pid !== info.pid)
|
|
202
|
-
return { service: undefined, timedOut: false };
|
|
203
|
-
if (info.version !== undefined && serverInfo.version !== info.version)
|
|
204
|
-
return { service: undefined, timedOut: false };
|
|
205
|
-
return {
|
|
206
|
-
service: {
|
|
207
|
-
info,
|
|
208
|
-
endpoint,
|
|
209
|
-
version: serverInfo.version,
|
|
210
|
-
state: response.ok ? "ready" : response.status === 500 ? "failed" : "waiting",
|
|
211
|
-
compatible: true,
|
|
212
|
-
},
|
|
213
|
-
timedOut: false,
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
return { service: undefined, timedOut: false };
|
|
217
|
-
}
|
|
218
|
-
function decodeInfo(input) {
|
|
219
|
-
if (typeof input !== "object" || input === null)
|
|
220
|
-
return;
|
|
221
|
-
if (!("version" in input) || typeof input.version !== "string")
|
|
222
|
-
return;
|
|
223
|
-
if (!("pid" in input) || typeof input.pid !== "number" || !Number.isInteger(input.pid) || input.pid < 0)
|
|
224
|
-
return;
|
|
225
|
-
return { version: input.version, pid: input.pid };
|
|
226
|
-
}
|
|
227
132
|
async function registered(file, timeout) {
|
|
228
133
|
const info = await read(file);
|
|
229
134
|
if (info === undefined)
|
|
@@ -254,9 +159,6 @@ async function waitUntilStopped(pid, timing) {
|
|
|
254
159
|
}
|
|
255
160
|
return false;
|
|
256
161
|
}
|
|
257
|
-
function same(left, right) {
|
|
258
|
-
return left.id === right.id && left.version === right.version && left.url === right.url && left.pid === right.pid;
|
|
259
|
-
}
|
|
260
162
|
async function terminate(info, options, timing) {
|
|
261
163
|
const current = await read(options.file);
|
|
262
164
|
if (current === undefined || !same(current, info))
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"import": "./client/index.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
"version": "2.0.
|
|
17
|
+
"version": "2.0.24-shuv.1",
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -30,17 +30,17 @@
|
|
|
30
30
|
"x64"
|
|
31
31
|
],
|
|
32
32
|
"optionalDependencies": {
|
|
33
|
-
"shuvcode-windows-x64": "2.0.
|
|
34
|
-
"shuvcode-linux-arm64-musl": "2.0.
|
|
35
|
-
"shuvcode-linux-x64-baseline-musl": "2.0.
|
|
36
|
-
"shuvcode-darwin-arm64": "2.0.
|
|
37
|
-
"shuvcode-linux-x64-musl": "2.0.
|
|
38
|
-
"shuvcode-darwin-x64": "2.0.
|
|
39
|
-
"shuvcode-linux-x64-baseline": "2.0.
|
|
40
|
-
"shuvcode-windows-arm64": "2.0.
|
|
41
|
-
"shuvcode-linux-arm64": "2.0.
|
|
42
|
-
"shuvcode-darwin-x64-baseline": "2.0.
|
|
43
|
-
"shuvcode-windows-x64-baseline": "2.0.
|
|
44
|
-
"shuvcode-linux-x64": "2.0.
|
|
33
|
+
"shuvcode-windows-x64": "2.0.24-shuv.1",
|
|
34
|
+
"shuvcode-linux-arm64-musl": "2.0.24-shuv.1",
|
|
35
|
+
"shuvcode-linux-x64-baseline-musl": "2.0.24-shuv.1",
|
|
36
|
+
"shuvcode-darwin-arm64": "2.0.24-shuv.1",
|
|
37
|
+
"shuvcode-linux-x64-musl": "2.0.24-shuv.1",
|
|
38
|
+
"shuvcode-darwin-x64": "2.0.24-shuv.1",
|
|
39
|
+
"shuvcode-linux-x64-baseline": "2.0.24-shuv.1",
|
|
40
|
+
"shuvcode-windows-arm64": "2.0.24-shuv.1",
|
|
41
|
+
"shuvcode-linux-arm64": "2.0.24-shuv.1",
|
|
42
|
+
"shuvcode-darwin-x64-baseline": "2.0.24-shuv.1",
|
|
43
|
+
"shuvcode-windows-x64-baseline": "2.0.24-shuv.1",
|
|
44
|
+
"shuvcode-linux-x64": "2.0.24-shuv.1"
|
|
45
45
|
}
|
|
46
46
|
}
|