@kilocode/client 0.0.0-stage → 0.0.0-v2-9

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 (94) hide show
  1. package/README.md +26 -2
  2. package/dist/chunks/contract-15p82y03.js +62 -0
  3. package/dist/chunks/contract-1x65x4hv.js +1701 -0
  4. package/dist/chunks/contract-5bf0yjkp.js +111 -0
  5. package/dist/chunks/contract-6mptkzbc.js +0 -0
  6. package/dist/chunks/contract-8bbb028w.js +145 -0
  7. package/dist/chunks/contract-8s2anffy.js +11 -0
  8. package/dist/chunks/contract-8ye1ye6f.js +92 -0
  9. package/dist/chunks/contract-9rqn6x4v.js +16 -0
  10. package/dist/chunks/contract-c46qzyff.js +37 -0
  11. package/dist/chunks/contract-gne7h7mq.js +50 -0
  12. package/dist/chunks/contract-hjez4bfs.js +52 -0
  13. package/dist/chunks/contract-m2eywc8w.js +0 -0
  14. package/dist/chunks/contract-nwcpakzx.js +12 -0
  15. package/dist/chunks/contract-qav6mfdz.js +0 -0
  16. package/dist/chunks/contract-ryy6kscr.js +39 -0
  17. package/dist/chunks/contract-s2hya144.js +1524 -0
  18. package/dist/chunks/contract-skhp7hxc.js +81 -0
  19. package/dist/chunks/contract-sxt88q69.js +12 -0
  20. package/dist/chunks/contract-ve4aws36.js +103 -0
  21. package/dist/chunks/contract-vmytr4q8.js +4 -0
  22. package/dist/chunks/contract-vwtmm97t.js +30 -0
  23. package/dist/chunks/contract-vyas3vgt.js +0 -0
  24. package/dist/chunks/contract-w10x3kfx.js +658 -0
  25. package/dist/chunks/contract-xgnj2w4v.js +20 -0
  26. package/dist/chunks/contract-y2etg5bs.js +9 -0
  27. package/dist/chunks/contract-ydhz1zrh.js +238 -0
  28. package/dist/contract.d.ts +1 -0
  29. package/dist/contract.js +12 -0
  30. package/dist/effect/api/api.d.ts +2927 -0
  31. package/dist/effect/api/api.js +0 -0
  32. package/dist/effect/api.d.ts +4 -0
  33. package/dist/effect/api.js +0 -0
  34. package/dist/effect/client.d.ts +2569 -0
  35. package/dist/effect/client.js +15 -0
  36. package/dist/effect/generated/client-error.d.ts +7 -0
  37. package/dist/effect/generated/client-error.js +6 -0
  38. package/dist/effect/generated/client.d.ts +2568 -0
  39. package/dist/effect/generated/client.js +8 -0
  40. package/dist/effect/generated/index.d.ts +2 -0
  41. package/dist/effect/generated/index.js +12 -0
  42. package/dist/effect/index.d.ts +35 -0
  43. package/dist/effect/index.js +75 -0
  44. package/dist/effect/rpc.d.ts +20 -0
  45. package/dist/effect/rpc.js +11 -0
  46. package/dist/effect/service.d.ts +90 -0
  47. package/dist/effect/service.js +187 -0
  48. package/dist/mcp.d.ts +44 -0
  49. package/dist/mcp.js +110 -0
  50. package/dist/promise/api.d.ts +21 -0
  51. package/dist/promise/api.js +0 -0
  52. package/dist/promise/client.d.ts +270 -0
  53. package/dist/promise/client.js +14 -0
  54. package/dist/promise/generated/client-error.d.ts +8 -0
  55. package/dist/promise/generated/client-error.js +6 -0
  56. package/dist/promise/generated/client.d.ts +277 -0
  57. package/dist/promise/generated/client.js +7 -0
  58. package/dist/promise/generated/index.d.ts +3 -0
  59. package/dist/promise/generated/index.js +81 -0
  60. package/dist/promise/generated/types.d.ts +7877 -0
  61. package/dist/promise/generated/types.js +72 -0
  62. package/dist/promise/index.d.ts +6 -0
  63. package/dist/promise/index.js +85 -0
  64. package/dist/promise/rpc.d.ts +32 -0
  65. package/dist/promise/rpc.js +7 -0
  66. package/dist/promise/service.d.ts +24 -0
  67. package/dist/promise/service.js +187 -0
  68. package/dist/pty-handoff.d.ts +12 -0
  69. package/dist/pty-handoff.js +17 -0
  70. package/dist/rpc-runtime.d.ts +20 -0
  71. package/dist/rpc-runtime.js +14 -0
  72. package/dist/service-contender.d.ts +37 -0
  73. package/dist/service-contender.js +10 -0
  74. package/dist/service-probe.d.ts +70 -0
  75. package/dist/service-probe.js +16 -0
  76. package/dist/service-timing.d.ts +12 -0
  77. package/dist/service-timing.js +10 -0
  78. package/dist/service-version.d.ts +2 -0
  79. package/dist/service-version.js +6 -0
  80. package/dist/service.d.ts +52 -0
  81. package/dist/service.js +1 -0
  82. package/dist/shared-events.d.ts +11 -0
  83. package/dist/shared-events.js +8 -0
  84. package/dist/solid/connection.d.ts +37 -0
  85. package/dist/solid/connection.js +10 -0
  86. package/dist/solid/data.d.ts +211 -0
  87. package/dist/solid/data.js +18 -0
  88. package/dist/solid/index.d.ts +4 -0
  89. package/dist/solid/index.js +36 -0
  90. package/dist/solid/pty.d.ts +22 -0
  91. package/dist/solid/pty.js +8 -0
  92. package/dist/solid/usage.d.ts +9 -0
  93. package/dist/solid/usage.js +6 -0
  94. package/package.json +88 -4
@@ -0,0 +1,72 @@
1
+ import {
2
+ isInvalidRequestError2,
3
+ isUnauthorizedError2,
4
+ isLocationNotFoundError2,
5
+ isServiceUnavailableError2,
6
+ isAgentNotFoundError2,
7
+ isInvalidCursorError2,
8
+ isSessionNotFoundError2,
9
+ isConflictError2,
10
+ isUnknownError2,
11
+ isMessageNotFoundError2,
12
+ isCommandNotFoundError2,
13
+ isCommandExecutionError2,
14
+ isSkillNotFoundError2,
15
+ isSessionBusyError2,
16
+ isInstructionEntryValueTooLargeError2,
17
+ isFormNotFoundError2,
18
+ isFormInvalidAnswerError2,
19
+ isFormAlreadySettledError2,
20
+ isProviderNotFoundError2,
21
+ isIntegrationNotFoundError2,
22
+ isIntegrationAttemptNotFoundError2,
23
+ isIntegrationMethodNotFoundError2,
24
+ isMcpServerNotFoundError2,
25
+ isForbiddenError2,
26
+ isProjectNotFoundError2,
27
+ isPermissionSavedNotFoundError2,
28
+ isPermissionNotFoundError2,
29
+ isFileNotFoundError2,
30
+ isRpcError2,
31
+ isRpcInternalError2,
32
+ isPtyNotFoundError2,
33
+ isShellNotFoundError2,
34
+ isWorktreeError2,
35
+ isVcsInitNotSupportedError2
36
+ } from "../../chunks/contract-c46qzyff.js";
37
+ export {
38
+ isAgentNotFoundError2 as isAgentNotFoundError,
39
+ isCommandExecutionError2 as isCommandExecutionError,
40
+ isCommandNotFoundError2 as isCommandNotFoundError,
41
+ isConflictError2 as isConflictError,
42
+ isFileNotFoundError2 as isFileNotFoundError,
43
+ isForbiddenError2 as isForbiddenError,
44
+ isFormAlreadySettledError2 as isFormAlreadySettledError,
45
+ isFormInvalidAnswerError2 as isFormInvalidAnswerError,
46
+ isFormNotFoundError2 as isFormNotFoundError,
47
+ isInstructionEntryValueTooLargeError2 as isInstructionEntryValueTooLargeError,
48
+ isIntegrationAttemptNotFoundError2 as isIntegrationAttemptNotFoundError,
49
+ isIntegrationMethodNotFoundError2 as isIntegrationMethodNotFoundError,
50
+ isIntegrationNotFoundError2 as isIntegrationNotFoundError,
51
+ isInvalidCursorError2 as isInvalidCursorError,
52
+ isInvalidRequestError2 as isInvalidRequestError,
53
+ isLocationNotFoundError2 as isLocationNotFoundError,
54
+ isMcpServerNotFoundError2 as isMcpServerNotFoundError,
55
+ isMessageNotFoundError2 as isMessageNotFoundError,
56
+ isPermissionNotFoundError2 as isPermissionNotFoundError,
57
+ isPermissionSavedNotFoundError2 as isPermissionSavedNotFoundError,
58
+ isProjectNotFoundError2 as isProjectNotFoundError,
59
+ isProviderNotFoundError2 as isProviderNotFoundError,
60
+ isPtyNotFoundError2 as isPtyNotFoundError,
61
+ isRpcError2 as isRpcError,
62
+ isRpcInternalError2 as isRpcInternalError,
63
+ isServiceUnavailableError2 as isServiceUnavailableError,
64
+ isSessionBusyError2 as isSessionBusyError,
65
+ isSessionNotFoundError2 as isSessionNotFoundError,
66
+ isShellNotFoundError2 as isShellNotFoundError,
67
+ isSkillNotFoundError2 as isSkillNotFoundError,
68
+ isUnauthorizedError2 as isUnauthorizedError,
69
+ isUnknownError2 as isUnknownError,
70
+ isVcsInitNotSupportedError2 as isVcsInitNotSupportedError,
71
+ isWorktreeError2 as isWorktreeError
72
+ };
@@ -0,0 +1,6 @@
1
+ import type { OpenCode } from "./client.js";
2
+ export * from "./generated/index.js";
3
+ export { OpenCode } from "./client.js";
4
+ export type { AgentApi, CommandApi, ConfigApi, EventApi, IntegrationApi, ModelApi, PluginApi, ProviderApi, ReferenceApi, RpcApi, RpcCallOptions, RpcClient, RpcEventPayload, WebSearchApi, SessionApi, SkillApi, } from "./api.js";
5
+ export type { EventSubscribeOutput as OpenCodeEvent } from "./generated/types.js";
6
+ export type OpenCodeClient = ReturnType<typeof OpenCode.make>;
@@ -0,0 +1,85 @@
1
+ import"../chunks/contract-m2eywc8w.js";
2
+ import {
3
+ exports_client3
4
+ } from "../chunks/contract-vwtmm97t.js";
5
+ import"../chunks/contract-vyas3vgt.js";
6
+ import"../chunks/contract-s2hya144.js";
7
+ import {
8
+ ClientError3
9
+ } from "../chunks/contract-nwcpakzx.js";
10
+ import"../chunks/contract-skhp7hxc.js";
11
+ import {
12
+ isInvalidRequestError2,
13
+ isUnauthorizedError2,
14
+ isLocationNotFoundError2,
15
+ isServiceUnavailableError2,
16
+ isAgentNotFoundError2,
17
+ isInvalidCursorError2,
18
+ isSessionNotFoundError2,
19
+ isConflictError2,
20
+ isUnknownError2,
21
+ isMessageNotFoundError2,
22
+ isCommandNotFoundError2,
23
+ isCommandExecutionError2,
24
+ isSkillNotFoundError2,
25
+ isSessionBusyError2,
26
+ isInstructionEntryValueTooLargeError2,
27
+ isFormNotFoundError2,
28
+ isFormInvalidAnswerError2,
29
+ isFormAlreadySettledError2,
30
+ isProviderNotFoundError2,
31
+ isIntegrationNotFoundError2,
32
+ isIntegrationAttemptNotFoundError2,
33
+ isIntegrationMethodNotFoundError2,
34
+ isMcpServerNotFoundError2,
35
+ isForbiddenError2,
36
+ isProjectNotFoundError2,
37
+ isPermissionSavedNotFoundError2,
38
+ isPermissionNotFoundError2,
39
+ isFileNotFoundError2,
40
+ isRpcError2,
41
+ isRpcInternalError2,
42
+ isPtyNotFoundError2,
43
+ isShellNotFoundError2,
44
+ isWorktreeError2,
45
+ isVcsInitNotSupportedError2
46
+ } from "../chunks/contract-c46qzyff.js";
47
+ import"../chunks/contract-8bbb028w.js";
48
+ export {
49
+ ClientError3 as ClientError,
50
+ exports_client3 as OpenCode,
51
+ isAgentNotFoundError2 as isAgentNotFoundError,
52
+ isCommandExecutionError2 as isCommandExecutionError,
53
+ isCommandNotFoundError2 as isCommandNotFoundError,
54
+ isConflictError2 as isConflictError,
55
+ isFileNotFoundError2 as isFileNotFoundError,
56
+ isForbiddenError2 as isForbiddenError,
57
+ isFormAlreadySettledError2 as isFormAlreadySettledError,
58
+ isFormInvalidAnswerError2 as isFormInvalidAnswerError,
59
+ isFormNotFoundError2 as isFormNotFoundError,
60
+ isInstructionEntryValueTooLargeError2 as isInstructionEntryValueTooLargeError,
61
+ isIntegrationAttemptNotFoundError2 as isIntegrationAttemptNotFoundError,
62
+ isIntegrationMethodNotFoundError2 as isIntegrationMethodNotFoundError,
63
+ isIntegrationNotFoundError2 as isIntegrationNotFoundError,
64
+ isInvalidCursorError2 as isInvalidCursorError,
65
+ isInvalidRequestError2 as isInvalidRequestError,
66
+ isLocationNotFoundError2 as isLocationNotFoundError,
67
+ isMcpServerNotFoundError2 as isMcpServerNotFoundError,
68
+ isMessageNotFoundError2 as isMessageNotFoundError,
69
+ isPermissionNotFoundError2 as isPermissionNotFoundError,
70
+ isPermissionSavedNotFoundError2 as isPermissionSavedNotFoundError,
71
+ isProjectNotFoundError2 as isProjectNotFoundError,
72
+ isProviderNotFoundError2 as isProviderNotFoundError,
73
+ isPtyNotFoundError2 as isPtyNotFoundError,
74
+ isRpcError2 as isRpcError,
75
+ isRpcInternalError2 as isRpcInternalError,
76
+ isServiceUnavailableError2 as isServiceUnavailableError,
77
+ isSessionBusyError2 as isSessionBusyError,
78
+ isSessionNotFoundError2 as isSessionNotFoundError,
79
+ isShellNotFoundError2 as isShellNotFoundError,
80
+ isSkillNotFoundError2 as isSkillNotFoundError,
81
+ isUnauthorizedError2 as isUnauthorizedError,
82
+ isUnknownError2 as isUnknownError,
83
+ isVcsInitNotSupportedError2 as isVcsInitNotSupportedError,
84
+ isWorktreeError2 as isWorktreeError
85
+ };
@@ -0,0 +1,32 @@
1
+ import type { Rpc } from "@opencode/schema/rpc";
2
+ import type { make, RequestOptions } from "./generated/client.js";
3
+ import type { EventSubscribeOutput, LocationGetInput } from "./generated/types.js";
4
+ type RpcEvent = Extract<EventSubscribeOutput, {
5
+ type: `rpc.${string}`;
6
+ }>;
7
+ export interface RpcCallOptions extends RequestOptions {
8
+ readonly location?: LocationGetInput["location"];
9
+ }
10
+ export type RpcArguments<Input, Options> = unknown extends Input ? [input: Input, options?: Options] : undefined extends Input ? [input?: Input, options?: Options] : [input: Input, options?: Options];
11
+ export type RpcClient<D extends Rpc.PortableDefinition, Options = RpcCallOptions> = {
12
+ readonly [Name in keyof D["methods"]]: (...args: RpcArguments<Rpc.Input<D["methods"][Name]["input"]>, Options>) => Promise<Rpc.Output<D["methods"][Name]["output"]>>;
13
+ } & {
14
+ readonly events: {
15
+ readonly subscribe: <Name extends keyof D["events"] & string>(name: Name, options?: Pick<RequestOptions, "signal">) => AsyncIterable<RpcEventPayload<D, Name>>;
16
+ readonly on: <Name extends keyof D["events"] & string>(name: Name, handler: (event: RpcEventPayload<D, Name>) => Promise<void> | void, options?: Pick<RequestOptions, "signal">) => () => void;
17
+ };
18
+ };
19
+ type RpcEventPayloadFor<D extends Rpc.PortableDefinition, Name extends keyof D["events"] & string> = Omit<RpcEvent, "type" | "data"> & {
20
+ type: `rpc.${D["id"]}.${Name}`;
21
+ data: Rpc.EventData<D["events"][Name]["schema"]>;
22
+ };
23
+ export type RpcEventPayload<D extends Rpc.PortableDefinition, Name extends keyof D["events"] & string = keyof D["events"] & string> = {
24
+ [K in Name]: RpcEventPayloadFor<D, K>;
25
+ }[Name];
26
+ export interface RpcApi<Options = RpcCallOptions> {
27
+ <D extends Rpc.PortableDefinition>(definition: D): RpcClient<D, Options>;
28
+ }
29
+ export declare function makeRpc(raw: ReturnType<typeof make>, events: {
30
+ subscribe(options?: Pick<RequestOptions, "signal">): AsyncIterable<EventSubscribeOutput>;
31
+ }): RpcApi;
32
+ export {};
@@ -0,0 +1,7 @@
1
+ import {
2
+ makeRpc2
3
+ } from "../chunks/contract-skhp7hxc.js";
4
+ import"../chunks/contract-c46qzyff.js";
5
+ export {
6
+ makeRpc2 as makeRpc
7
+ };
@@ -0,0 +1,24 @@
1
+ import type { DiscoverOptions, Endpoint, EnsureOptions, StopOptions } from "../service.js";
2
+ import { headers } from "../service-probe.js";
3
+ export * from "../service.js";
4
+ export { headers };
5
+ /** Discover a healthy, compatible local service without starting one. */
6
+ export declare function discover(options?: DiscoverOptions): Promise<{
7
+ url: string;
8
+ auth: {
9
+ type: "basic";
10
+ username: string;
11
+ password: string;
12
+ } | undefined;
13
+ } | undefined>;
14
+ /** Ensure a healthy, compatible local service is running. */
15
+ export declare function ensure(options?: EnsureOptions): Promise<Endpoint>;
16
+ /** Stop the registered local service. */
17
+ export declare function stop(options?: StopOptions): Promise<void>;
18
+ /** Promise-based local service lifecycle operations. */
19
+ export declare const Service: {
20
+ discover: typeof discover;
21
+ ensure: typeof ensure;
22
+ stop: typeof stop;
23
+ headers: typeof headers;
24
+ };
@@ -0,0 +1,187 @@
1
+ import {
2
+ spawnServiceContender2,
3
+ contenderPool2
4
+ } from "../chunks/contract-ve4aws36.js";
5
+ import {
6
+ defaultEnsureTiming2,
7
+ ensureTiming2
8
+ } from "../chunks/contract-xgnj2w4v.js";
9
+ import {
10
+ matchesVersion2
11
+ } from "../chunks/contract-sxt88q69.js";
12
+ import {
13
+ decide2,
14
+ fallback2,
15
+ same2,
16
+ probeResult2,
17
+ headers2
18
+ } from "../chunks/contract-8ye1ye6f.js";
19
+ import {
20
+ prepare2,
21
+ environment2,
22
+ complete2,
23
+ clear2
24
+ } from "../chunks/contract-5bf0yjkp.js";
25
+ import"../chunks/contract-qav6mfdz.js";
26
+
27
+ // src/promise/service.ts
28
+ import { readFile, rm } from "node:fs/promises";
29
+ async function discover(options = {}) {
30
+ const found = (await registered(options.file)).service;
31
+ if (found?.state !== "ready")
32
+ return;
33
+ if (!found.compatible)
34
+ return;
35
+ if (!matchesVersion2(found.version, options))
36
+ return;
37
+ return found.endpoint;
38
+ }
39
+ async function ensure(options = {}) {
40
+ const timing = ensureTiming2(options);
41
+ const deadline = Date.now() + timing.promiseTimeout;
42
+ const pool = contenderPool2(timing);
43
+ let timeouts;
44
+ let announced = false;
45
+ const announce = (reason, previousVersion) => {
46
+ if (announced)
47
+ return;
48
+ announced = true;
49
+ options.onStart?.(reason, previousVersion);
50
+ };
51
+ const spawnContender = async () => {
52
+ const [command, ...args] = options.command ?? ["opencode", "serve", "--service"];
53
+ if (command === undefined)
54
+ throw new Error("Missing service command");
55
+ try {
56
+ return spawnServiceContender2(command, args, await environment2(options.file ?? fallback2(), options.env));
57
+ } catch (cause) {
58
+ throw new Error("Failed to start server", { cause });
59
+ }
60
+ };
61
+ try {
62
+ while (true) {
63
+ if (Date.now() >= deadline)
64
+ throw pool.failure() ?? new Error("Timed out waiting for the background service to start");
65
+ const registration = await registered(options.file, timing.requestTimeout);
66
+ if (registration.timedOut && registration.info !== undefined) {
67
+ timeouts = {
68
+ info: registration.info,
69
+ count: timeouts !== undefined && same2(timeouts.info, registration.info) ? timeouts.count + 1 : 1
70
+ };
71
+ if (timeouts.count >= 3) {
72
+ announce("missing");
73
+ console.warn("Background service is unresponsive; recovery cannot preserve persistent terminals");
74
+ await clear2(options.file ?? fallback2());
75
+ await terminate(registration.info, options, timing);
76
+ pool.evict(registration.info.pid);
77
+ pool.recruitNow();
78
+ timeouts = undefined;
79
+ }
80
+ } else
81
+ timeouts = undefined;
82
+ if (registration.service !== undefined) {
83
+ pool.serviceAnswered();
84
+ const service2 = registration.service;
85
+ const decision = decide2(service2, options);
86
+ if (decision._tag === "fail")
87
+ throw decision.error;
88
+ if (decision._tag === "reuse") {
89
+ await complete2(options.file ?? fallback2(), service2.info);
90
+ return service2.endpoint;
91
+ }
92
+ if (decision._tag === "replace") {
93
+ announce("version-mismatch", service2.version);
94
+ if (service2.state !== "ready")
95
+ console.warn("Background service is not ready; replacement cannot preserve persistent terminals");
96
+ await stop({ file: options.file, pty: decision.pty }).catch(() => {
97
+ return;
98
+ });
99
+ pool.evict(service2.info.pid);
100
+ }
101
+ } else {
102
+ const failed = pool.reap();
103
+ if (failed !== undefined)
104
+ throw failed;
105
+ if (pool.shouldRecruit(registration.info !== undefined)) {
106
+ announce("missing");
107
+ pool.add(await spawnContender());
108
+ }
109
+ }
110
+ await delay(timing.pollInterval);
111
+ }
112
+ } finally {
113
+ pool.releaseAll();
114
+ }
115
+ }
116
+ async function stop(options = {}) {
117
+ const info = await read(options.file);
118
+ await (options.pty === "handoff" && info !== undefined ? prepare2(options.file ?? fallback2(), info, defaultEnsureTiming2.requestTimeout) : clear2(options.file ?? fallback2())).catch((cause) => console.warn("Failed to prepare persistent terminals for replacement", cause));
119
+ if (info !== undefined)
120
+ await terminate(info, options, ensureTiming2(options));
121
+ }
122
+ async function read(file) {
123
+ const text = await readFile(file ?? fallback2(), "utf8").catch(() => {
124
+ return;
125
+ });
126
+ if (text === undefined)
127
+ return;
128
+ try {
129
+ return JSON.parse(text);
130
+ } catch {
131
+ return;
132
+ }
133
+ }
134
+ async function registered(file, timeout) {
135
+ const info = await read(file);
136
+ if (info === undefined)
137
+ return { info: undefined, service: undefined, timedOut: false };
138
+ return { info, ...await probeResult2(info, timeout) };
139
+ }
140
+ function signal(pid, name) {
141
+ try {
142
+ process.kill(pid, name);
143
+ } catch {}
144
+ }
145
+ function stopped(pid) {
146
+ try {
147
+ process.kill(pid, 0);
148
+ return false;
149
+ } catch {
150
+ return true;
151
+ }
152
+ }
153
+ async function waitUntilStopped(pid, timing) {
154
+ for (let attempt = 0;attempt <= timing.stopPollAttempts; attempt++) {
155
+ if (stopped(pid))
156
+ return true;
157
+ if (attempt < timing.stopPollAttempts)
158
+ await delay(timing.stopPollInterval);
159
+ }
160
+ return false;
161
+ }
162
+ async function terminate(info, options, timing) {
163
+ const current = await read(options.file);
164
+ if (current === undefined || !same2(current, info))
165
+ return;
166
+ signal(info.pid, "SIGTERM");
167
+ if (!await waitUntilStopped(info.pid, timing)) {
168
+ signal(info.pid, "SIGKILL");
169
+ if (!await waitUntilStopped(info.pid, timing))
170
+ throw new Error(`Server process ${info.pid} is still running`);
171
+ }
172
+ const latest = await read(options.file);
173
+ if (latest === undefined || !same2(latest, info))
174
+ return;
175
+ await rm(options.file ?? fallback2(), { force: true });
176
+ }
177
+ function delay(milliseconds) {
178
+ return new Promise((resolve) => setTimeout(resolve, milliseconds));
179
+ }
180
+ var Service = { discover, ensure, stop, headers: headers2 };
181
+ export {
182
+ Service,
183
+ discover,
184
+ ensure,
185
+ headers2 as headers,
186
+ stop
187
+ };
@@ -0,0 +1,12 @@
1
+ export * as PtyHandoff from "./pty-handoff.js";
2
+ import type { Info } from "./service.js";
3
+ /**
4
+ * Publish the ticket before stopping its owner so every replacement contender can adopt it.
5
+ * Never throws: terminals are best-effort, so any failure replaces the service without a handoff.
6
+ */
7
+ export declare function prepare(file: string, info: Info, timeout: number): Promise<void>;
8
+ export declare function environment(file: string, env?: Readonly<Record<string, string>>): Promise<{
9
+ OPENCODE_PTY_HANDOFF: string | undefined;
10
+ }>;
11
+ export declare function complete(file: string, info: Info): Promise<void>;
12
+ export declare function clear(file: string): Promise<void>;
@@ -0,0 +1,17 @@
1
+ import {
2
+ prepare2,
3
+ environment2,
4
+ complete2,
5
+ clear2,
6
+ exports_pty_handoff
7
+ } from "./chunks/contract-5bf0yjkp.js";
8
+ import"./chunks/contract-8ye1ye6f.js";
9
+ import"./chunks/contract-xgnj2w4v.js";
10
+ import"./chunks/contract-sxt88q69.js";
11
+ export {
12
+ exports_pty_handoff as PtyHandoff,
13
+ clear2 as clear,
14
+ complete2 as complete,
15
+ environment2 as environment,
16
+ prepare2 as prepare
17
+ };
@@ -0,0 +1,20 @@
1
+ export * as RpcRuntime from "./rpc-runtime.js";
2
+ import type { Rpc } from "@opencode/schema/rpc";
3
+ import { Effect, Schema } from "effect";
4
+ export declare function read(schema: Rpc.Method["output"], value: unknown): Effect.Effect<unknown, Schema.SchemaError, never>;
5
+ export declare function readError(method: Rpc.Method, error: unknown): Effect.Effect<never, unknown>;
6
+ export declare const event: <D extends Rpc.Definition, Name extends keyof D["events"] & string>(definition: D, name: Name, schema: Rpc.EventDefinition, event: {
7
+ readonly id: string & import("effect/Brand").Brand<"Event.ID">;
8
+ readonly created: number;
9
+ readonly metadata?: {
10
+ readonly [x: string]: unknown;
11
+ } | undefined;
12
+ readonly type: `rpc.${string}`;
13
+ readonly location: {
14
+ readonly directory: string & import("effect/Brand").Brand<"AbsolutePath">;
15
+ };
16
+ readonly data: {
17
+ readonly [x: string]: unknown;
18
+ };
19
+ }) => Effect.Effect<Rpc.EventPayload<D, Name>, unknown, never>;
20
+ export declare function eventType<const D extends Rpc.Definition, const Name extends keyof D["events"] & string>(definition: D, name: Name): `rpc.${D["id"]}.${Name}`;
@@ -0,0 +1,14 @@
1
+ import {
2
+ read2,
3
+ readError2,
4
+ event2,
5
+ eventType2,
6
+ exports_rpc_runtime
7
+ } from "./chunks/contract-ryy6kscr.js";
8
+ export {
9
+ exports_rpc_runtime as RpcRuntime,
10
+ event2 as event,
11
+ eventType2 as eventType,
12
+ read2 as read,
13
+ readError2 as readError
14
+ };
@@ -0,0 +1,37 @@
1
+ import { type ChildProcess } from "node:child_process";
2
+ import type { EnsureTiming } from "./service-timing.js";
3
+ export type ServiceContender = {
4
+ readonly child: ChildProcess;
5
+ readonly error: () => Error | undefined;
6
+ readonly closed: () => boolean;
7
+ readonly stderr: () => string;
8
+ readonly release: () => void;
9
+ };
10
+ export declare function spawnServiceContender(command: string, args: ReadonlyArray<string>, env?: Readonly<Record<string, string | undefined>>): ServiceContender;
11
+ /**
12
+ * The startup attempts of one `ensure()` call. It keeps at most two attempts alive, remembers
13
+ * the first startup failure, and backs off when attempts exit cleanly because another one won.
14
+ */
15
+ export declare function contenderPool(timing: EnsureTiming): {
16
+ /** The first startup failure seen since the last eviction. */
17
+ failure: () => Error | undefined;
18
+ /** A registered service answered, so the next attempt waits the base delay again. */
19
+ serviceAnswered(): void;
20
+ /**
21
+ * The owner `pid` was replaced. Drop its attempt and any finished ones, forget their
22
+ * failure, and restart the spawn clock.
23
+ */
24
+ evict(pid: number): void;
25
+ /** Let the next attempt start without waiting a spawn delay. */
26
+ recruitNow(): void;
27
+ /** Collect finished attempts. Returns the startup failure once no attempt is left alive. */
28
+ reap(): Error | undefined;
29
+ /**
30
+ * Whether to start another attempt now. A registration that has not answered yet gets one
31
+ * spawn delay before an attempt competes with it.
32
+ */
33
+ shouldRecruit(registered: boolean): boolean;
34
+ add(contender: ServiceContender): void;
35
+ releaseAll(): void;
36
+ };
37
+ export declare function contenderFinished(contender: ServiceContender): boolean;
@@ -0,0 +1,10 @@
1
+ import {
2
+ spawnServiceContender2,
3
+ contenderPool2,
4
+ contenderFinished2
5
+ } from "./chunks/contract-ve4aws36.js";
6
+ export {
7
+ contenderFinished2 as contenderFinished,
8
+ contenderPool2 as contenderPool,
9
+ spawnServiceContender2 as spawnServiceContender
10
+ };
@@ -0,0 +1,70 @@
1
+ import type { DiscoverOptions, Endpoint, Info } from "./service.js";
2
+ export type LocalService = {
3
+ readonly info: Info;
4
+ readonly endpoint: Endpoint;
5
+ readonly version?: string;
6
+ readonly state: "ready" | "waiting" | "failed";
7
+ readonly compatible: boolean;
8
+ };
9
+ /**
10
+ * What `ensure()` does with a registered service that answered: return it, keep polling while
11
+ * it starts, replace it because its version does not meet the requirement, or fail.
12
+ */
13
+ export declare function decide(service: LocalService, options: DiscoverOptions): {
14
+ readonly _tag: "replace";
15
+ readonly pty: "clear" | "handoff";
16
+ } | {
17
+ readonly pty?: undefined;
18
+ readonly _tag: "reuse";
19
+ } | {
20
+ readonly pty?: undefined;
21
+ readonly _tag: "wait";
22
+ } | {
23
+ _tag: "fail";
24
+ error: Error;
25
+ };
26
+ /** The default registration file. */
27
+ export declare function fallback(): string;
28
+ /** Whether two registrations describe the same service instance. */
29
+ export declare function same(left: Info, right: Info): boolean;
30
+ /** Ask a registered owner for its health and classify the answer. */
31
+ export declare function probeResult(info: Info, timeout?: number): Promise<{
32
+ service: undefined;
33
+ timedOut: boolean;
34
+ } | {
35
+ service: {
36
+ info: Info;
37
+ endpoint: {
38
+ url: string;
39
+ auth: {
40
+ type: "basic";
41
+ username: string;
42
+ password: string;
43
+ } | undefined;
44
+ };
45
+ version: string | undefined;
46
+ state: "ready";
47
+ compatible: false;
48
+ };
49
+ timedOut: boolean;
50
+ } | {
51
+ service: {
52
+ info: Info;
53
+ endpoint: {
54
+ url: string;
55
+ auth: {
56
+ type: "basic";
57
+ username: string;
58
+ password: string;
59
+ } | undefined;
60
+ };
61
+ version: string;
62
+ state: "failed" | "ready" | "waiting";
63
+ compatible: true;
64
+ };
65
+ timedOut: boolean;
66
+ }>;
67
+ /** Create HTTP authentication headers for a service endpoint. */
68
+ export declare function headers(endpoint: Endpoint): {
69
+ authorization: string;
70
+ } | undefined;
@@ -0,0 +1,16 @@
1
+ import {
2
+ decide2,
3
+ fallback2,
4
+ same2,
5
+ probeResult2,
6
+ headers2
7
+ } from "./chunks/contract-8ye1ye6f.js";
8
+ import"./chunks/contract-xgnj2w4v.js";
9
+ import"./chunks/contract-sxt88q69.js";
10
+ export {
11
+ decide2 as decide,
12
+ fallback2 as fallback,
13
+ headers2 as headers,
14
+ probeResult2 as probeResult,
15
+ same2 as same
16
+ };
@@ -0,0 +1,12 @@
1
+ export type EnsureTiming = {
2
+ readonly pollInterval: number;
3
+ readonly requestTimeout: number;
4
+ readonly spawnDelay: number;
5
+ readonly maxSpawnDelay: number;
6
+ readonly promiseTimeout: number;
7
+ readonly stopPollInterval: number;
8
+ readonly stopPollAttempts: number;
9
+ };
10
+ export declare const defaultEnsureTiming: EnsureTiming;
11
+ export declare function ensureTiming(options: object): EnsureTiming;
12
+ export declare function withEnsureTiming<A extends object>(options: A, overrides: Partial<EnsureTiming>): A;
@@ -0,0 +1,10 @@
1
+ import {
2
+ defaultEnsureTiming2,
3
+ ensureTiming2,
4
+ withEnsureTiming2
5
+ } from "./chunks/contract-xgnj2w4v.js";
6
+ export {
7
+ defaultEnsureTiming2 as defaultEnsureTiming,
8
+ ensureTiming2 as ensureTiming,
9
+ withEnsureTiming2 as withEnsureTiming
10
+ };
@@ -0,0 +1,2 @@
1
+ import type { DiscoverOptions } from "./service.js";
2
+ export declare function matchesVersion(version: string | undefined, options: DiscoverOptions): boolean;
@@ -0,0 +1,6 @@
1
+ import {
2
+ matchesVersion2
3
+ } from "./chunks/contract-sxt88q69.js";
4
+ export {
5
+ matchesVersion2 as matchesVersion
6
+ };