@opencode/client 2.0.22 → 2.0.23

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 (59) hide show
  1. package/dist/chunks/{service-contender-1kn39gq3.js → service-version-02j88w0z.js} +14 -21
  2. package/dist/chunks/{service-contender-1tbj6z39.js → service-version-1y4a697q.js} +1 -1
  3. package/dist/chunks/{service-contender-krgmp8b6.js → service-version-21favj1f.js} +5 -5
  4. package/dist/chunks/{service-contender-txckps9j.js → service-version-6f43cgzz.js} +1 -0
  5. package/dist/chunks/{service-contender-mxz277s4.js → service-version-7yt87z36.js} +5 -3
  6. package/dist/chunks/{service-contender-h11j9btw.js → service-version-e5ea35j7.js} +1 -1
  7. package/dist/chunks/{service-contender-frbwqjmf.js → service-version-frbwqjmf.js} +1 -1
  8. package/dist/chunks/{service-contender-992ffpa9.js → service-version-gah0fg5v.js} +4 -4
  9. package/dist/chunks/{service-contender-50fct660.js → service-version-nyqggzs9.js} +60 -46
  10. package/dist/chunks/{service-contender-t1xa31vm.js → service-version-t1xa31vm.js} +1 -1
  11. package/dist/chunks/{service-contender-4tveyqeh.js → service-version-vt9jbch8.js} +4 -2
  12. package/dist/chunks/{service-contender-z6qdwcsf.js → service-version-z6qdwcsf.js} +2 -2
  13. package/dist/contract.js +1 -1
  14. package/dist/effect/api/api.d.ts +12 -0
  15. package/dist/effect/client.d.ts +93 -92
  16. package/dist/effect/client.js +8 -8
  17. package/dist/effect/generated/client-error.js +1 -1
  18. package/dist/effect/generated/client.d.ts +93 -92
  19. package/dist/effect/generated/client.js +3 -3
  20. package/dist/effect/generated/index.js +4 -4
  21. package/dist/effect/index.js +8 -8
  22. package/dist/effect/rpc.js +2 -2
  23. package/dist/effect/service.js +29 -17
  24. package/dist/promise/client.d.ts +1 -0
  25. package/dist/promise/client.js +7 -7
  26. package/dist/promise/generated/client-error.js +1 -1
  27. package/dist/promise/generated/client.d.ts +2 -1
  28. package/dist/promise/generated/client.js +2 -2
  29. package/dist/promise/generated/index.js +9 -5
  30. package/dist/promise/generated/types.d.ts +33 -0
  31. package/dist/promise/generated/types.js +6 -2
  32. package/dist/promise/index.js +13 -9
  33. package/dist/promise/rpc.js +2 -2
  34. package/dist/promise/service.js +29 -17
  35. package/dist/pty-handoff.d.ts +4 -1
  36. package/dist/pty-handoff.js +1 -1
  37. package/dist/rpc-runtime.js +1 -1
  38. package/dist/service-contender.js +1 -1
  39. package/dist/service-timing.js +1 -1
  40. package/dist/service-version.js +1 -1
  41. package/dist/service.js +1 -1
  42. package/dist/shared-events.js +1 -1
  43. package/dist/solid/connection.js +1 -1
  44. package/dist/solid/data.js +9 -9
  45. package/dist/solid/index.js +11 -11
  46. package/dist/solid/pty.js +1 -1
  47. package/package.json +4 -4
  48. /package/dist/chunks/{service-contender-6mptkzbc.js → service-version-6mptkzbc.js} +0 -0
  49. /package/dist/chunks/{service-contender-9rqn6x4v.js → service-version-9rqn6x4v.js} +0 -0
  50. /package/dist/chunks/{service-contender-gne7h7mq.js → service-version-gne7h7mq.js} +0 -0
  51. /package/dist/chunks/{service-contender-m2eywc8w.js → service-version-m2eywc8w.js} +0 -0
  52. /package/dist/chunks/{service-contender-nwcpakzx.js → service-version-nwcpakzx.js} +0 -0
  53. /package/dist/chunks/{service-contender-qav6mfdz.js → service-version-qav6mfdz.js} +0 -0
  54. /package/dist/chunks/{service-contender-sxt88q69.js → service-version-sxt88q69.js} +0 -0
  55. /package/dist/chunks/{service-contender-vmytr4q8.js → service-version-vmytr4q8.js} +0 -0
  56. /package/dist/chunks/{service-contender-vyas3vgt.js → service-version-vyas3vgt.js} +0 -0
  57. /package/dist/chunks/{service-contender-xgnj2w4v.js → service-version-xgnj2w4v.js} +0 -0
  58. /package/dist/chunks/{service-contender-y2etg5bs.js → service-version-y2etg5bs.js} +0 -0
  59. /package/dist/chunks/{service-contender-ydhz1zrh.js → service-version-ydhz1zrh.js} +0 -0
@@ -2,21 +2,21 @@ import {
2
2
  spawnServiceContender2,
3
3
  contenderFailure2,
4
4
  contenderFinished2
5
- } from "../chunks/service-contender-txckps9j.js";
5
+ } from "../chunks/service-version-6f43cgzz.js";
6
6
  import {
7
7
  defaultEnsureTiming2,
8
8
  ensureTiming2
9
- } from "../chunks/service-contender-xgnj2w4v.js";
9
+ } from "../chunks/service-version-xgnj2w4v.js";
10
10
  import {
11
11
  matchesVersion2
12
- } from "../chunks/service-contender-sxt88q69.js";
12
+ } from "../chunks/service-version-sxt88q69.js";
13
13
  import {
14
14
  prepare2,
15
15
  environment2,
16
16
  complete2,
17
17
  clear2
18
- } from "../chunks/service-contender-1kn39gq3.js";
19
- import"../chunks/service-contender-qav6mfdz.js";
18
+ } from "../chunks/service-version-02j88w0z.js";
19
+ import"../chunks/service-version-qav6mfdz.js";
20
20
 
21
21
  // src/effect/service.ts
22
22
  import { Effect, FileSystem, Option, Schedule, Schema } from "effect";
@@ -50,6 +50,7 @@ var ensure = Effect.fn("service.ensure")(function* (options = {}) {
50
50
  let announced = false;
51
51
  let lastSpawn = 0;
52
52
  let spawnDelay = timing.spawnDelay;
53
+ let failure;
53
54
  const announce = (reason, previousVersion) => Effect.sync(() => {
54
55
  if (announced)
55
56
  return;
@@ -82,6 +83,13 @@ var ensure = Effect.fn("service.ensure")(function* (options = {}) {
82
83
  yield* Effect.logWarning("Background service is unresponsive; recovery cannot preserve persistent terminals");
83
84
  yield* Effect.tryPromise(() => clear2(options.file ?? fallback()));
84
85
  yield* terminate(info, options, timing);
86
+ for (const item of contenders) {
87
+ if (item.child.pid === info.pid || contenderFinished2(item)) {
88
+ item.release();
89
+ contenders.delete(item);
90
+ }
91
+ }
92
+ failure = undefined;
85
93
  timeouts = undefined;
86
94
  lastSpawn = Date.now() - spawnDelay;
87
95
  }
@@ -89,7 +97,10 @@ var ensure = Effect.fn("service.ensure")(function* (options = {}) {
89
97
  timeouts = undefined;
90
98
  if (service2 !== undefined) {
91
99
  spawnDelay = timing.spawnDelay;
92
- const compatible = service2.compatible && matchesVersion2(service2.version, options);
100
+ const versionMatches = matchesVersion2(service2.version, options);
101
+ const compatible = service2.compatible && versionMatches;
102
+ if (!service2.compatible && versionMatches)
103
+ return yield* Effect.fail(new Error("Background service uses an incompatible health protocol. Update this client or explicitly restart the service."));
93
104
  if (compatible && service2.state === "ready") {
94
105
  yield* Effect.tryPromise(() => complete2(options.file ?? fallback(), service2.info));
95
106
  return Option.some(service2);
@@ -105,19 +116,26 @@ var ensure = Effect.fn("service.ensure")(function* (options = {}) {
105
116
  file: options.file,
106
117
  pty: service2.state === "ready" ? "handoff" : "clear"
107
118
  }).pipe(Effect.ignore);
119
+ for (const item of contenders) {
120
+ if (item.child.pid === service2.info.pid || contenderFinished2(item)) {
121
+ item.release();
122
+ contenders.delete(item);
123
+ }
124
+ }
125
+ failure = undefined;
108
126
  lastSpawn = 0;
109
127
  return Option.none();
110
128
  } else if (lastSpawn === 0 && info !== undefined)
111
129
  lastSpawn = Date.now();
112
130
  const finished = [...contenders].filter(contenderFinished2);
113
- const failure = finished.map(contenderFailure2).find((error) => error !== undefined);
131
+ failure ??= finished.map(contenderFailure2).find((error) => error !== undefined);
114
132
  if (finished.some((item) => item.child.exitCode === 0)) {
115
133
  spawnDelay = Math.min(spawnDelay * 2, timing.maxSpawnDelay);
116
134
  }
117
135
  finished.forEach((item) => contenders.delete(item));
118
136
  if (failure !== undefined && contenders.size === 0)
119
137
  return yield* Effect.fail(failure);
120
- if (contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay) {
138
+ if (failure === undefined && contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay) {
121
139
  yield* announce("missing");
122
140
  contenders.add(yield* spawnContender);
123
141
  lastSpawn = Date.now();
@@ -128,17 +146,14 @@ var ensure = Effect.fn("service.ensure")(function* (options = {}) {
128
146
  schedule: Schedule.spaced(timing.pollInterval).pipe(Schedule.upTo({ duration: timing.promiseTimeout }))
129
147
  }), Effect.ensuring(Effect.sync(() => contenders.forEach((contender) => contender.release()))));
130
148
  if (Option.isNone(found))
131
- return yield* Effect.fail(new Error("Timed out waiting for the background service to start"));
149
+ return yield* Effect.fail(failure ?? new Error("Timed out waiting for the background service to start"));
132
150
  return found.value.endpoint;
133
151
  });
134
152
  var stop = Effect.fn("service.stop")(function* (options = {}) {
135
153
  const info = yield* read(options.file);
136
- if (options.pty === "handoff" && info !== undefined)
137
- yield* Effect.tryPromise(() => prepare2(options.file ?? fallback(), info, defaultEnsureTiming2.requestTimeout));
138
- else
139
- yield* Effect.tryPromise(() => clear2(options.file ?? fallback()));
154
+ yield* Effect.tryPromise(() => options.pty === "handoff" && info !== undefined ? prepare2(options.file ?? fallback(), info, defaultEnsureTiming2.requestTimeout) : clear2(options.file ?? fallback())).pipe(Effect.catch((cause) => Effect.logWarning("Failed to prepare persistent terminals for replacement", cause)));
140
155
  if (info !== undefined)
141
- yield* terminate(info, options, defaultEnsureTiming2);
156
+ yield* terminate(info, options, ensureTiming2(options));
142
157
  });
143
158
  function fallback() {
144
159
  const state = process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state");
@@ -239,9 +254,6 @@ var terminate = Effect.fnUntraced(function* (info, options, timing) {
239
254
  yield* signal(info.pid, "SIGTERM");
240
255
  const done = yield* stopped(info.pid).pipe(Effect.retry(poll(timing)), Effect.option);
241
256
  if (Option.isNone(done)) {
242
- const latest = yield* read(options.file);
243
- if (latest === undefined || !same(latest, info))
244
- return;
245
257
  yield* signal(info.pid, "SIGKILL");
246
258
  yield* stopped(info.pid).pipe(Effect.retry(poll(timing)));
247
259
  }
@@ -219,6 +219,7 @@ export declare function make(options: ClientOptions): {
219
219
  refresh: (input: import("./index.js").WorktreeRefreshInput, requestOptions?: OpenCode.RequestOptions) => Promise<void>;
220
220
  };
221
221
  vcs: {
222
+ init: (input?: import("./index.js").VcsInitInput, requestOptions?: OpenCode.RequestOptions) => Promise<void>;
222
223
  get: (input?: import("./index.js").VcsGetInput, requestOptions?: OpenCode.RequestOptions) => Promise<import("./index.js").VcsGetOutput>;
223
224
  base: (input?: import("./index.js").VcsBaseInput, requestOptions?: OpenCode.RequestOptions) => Promise<import("./index.js").VcsBaseOutput>;
224
225
  status: (input?: import("./index.js").VcsStatusInput, requestOptions?: OpenCode.RequestOptions) => Promise<import("./index.js").VcsStatusOutput>;
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  make5,
3
3
  exports_client3
4
- } from "../chunks/service-contender-992ffpa9.js";
5
- import"../chunks/service-contender-vyas3vgt.js";
6
- import"../chunks/service-contender-50fct660.js";
7
- import"../chunks/service-contender-nwcpakzx.js";
8
- import"../chunks/service-contender-1tbj6z39.js";
9
- import"../chunks/service-contender-4tveyqeh.js";
10
- import"../chunks/service-contender-frbwqjmf.js";
4
+ } from "../chunks/service-version-gah0fg5v.js";
5
+ import"../chunks/service-version-vyas3vgt.js";
6
+ import"../chunks/service-version-nyqggzs9.js";
7
+ import"../chunks/service-version-nwcpakzx.js";
8
+ import"../chunks/service-version-1y4a697q.js";
9
+ import"../chunks/service-version-vt9jbch8.js";
10
+ import"../chunks/service-version-frbwqjmf.js";
11
11
  export {
12
12
  exports_client3 as OpenCode,
13
13
  make5 as make
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ClientError3
3
- } from "../../chunks/service-contender-nwcpakzx.js";
3
+ } from "../../chunks/service-version-nwcpakzx.js";
4
4
  export {
5
5
  ClientError3 as ClientError
6
6
  };
@@ -1,4 +1,4 @@
1
- import type { ServerConnectInput, LocationGetInput, AgentListInput, AgentListOutput, AgentGetInput, AgentGetOutput, PluginListInput, PluginListOutput, PluginCheckInput, PluginCheckOutput, PluginUpdateInput, SessionListInput, SessionStatsInput, SessionCreateInput, SessionImportInput, SessionExportInput, SessionGetInput, SessionRemoveInput, SessionForkInput, SessionSwitchAgentInput, SessionSwitchModelInput, SessionUpdateInput, SessionMoveInput, SessionPromptInput, SessionCommandInput, SessionSkillInput, SessionSyntheticInput, SessionShellInput, SessionCompactInput, SessionWaitInput, SessionRevertStageInput, SessionRevertClearInput, SessionRevertCommitInput, SessionContextInput, SessionDiffInput, SessionInboxListInput, SessionInboxCancelInput, SessionInboxUpdateInput, SessionInstructionsEntryListInput, SessionInstructionsEntryPutInput, SessionInstructionsEntryRemoveInput, SessionGenerateInput, SessionLogInput, SessionLogOutput, SessionInterruptInput, SessionBackgroundInput, SessionMessageGetInput, SessionFormListInput, SessionFormCreateInput, SessionFormGetInput, SessionFormReplyInput, SessionFormCancelInput, SessionEnvironmentInput, SessionViewInput, MessageListInput, ModelListInput, ModelListOutput, ModelDefaultInput, ModelDefaultOutput, GenerateTextInput, ProviderListInput, ProviderListOutput, ProviderGetInput, ProviderGetOutput, IntegrationListInput, IntegrationListOutput, IntegrationGetInput, IntegrationGetOutput, IntegrationWellknownAddInput, IntegrationConnectKeyInput, IntegrationOauthConnectInput, IntegrationOauthConnectOutput, IntegrationOauthStatusInput, IntegrationOauthStatusOutput, IntegrationOauthCompleteInput, IntegrationOauthCancelInput, IntegrationCommandConnectInput, IntegrationCommandConnectOutput, IntegrationCommandStatusInput, IntegrationCommandStatusOutput, IntegrationCommandCancelInput, McpListInput, McpListOutput, McpAddInput, McpRemoveInput, McpConnectInput, McpDisconnectInput, McpResourceCatalogInput, McpResourceCatalogOutput, CredentialCreateInput, CredentialUpdateInput, CredentialActivateInput, CredentialRemoveInput, ProjectListOutput, ProjectUpdateInput, FormListInput, FormListOutput, PermissionRequestListInput, PermissionRequestListOutput, PermissionSavedListInput, PermissionSavedRemoveInput, PermissionCreateInput, PermissionListInput, PermissionGetInput, PermissionReplyInput, FileReadInput, FileReadOutput, FileListInput, FileListOutput, FileFindInput, FileFindOutput, FileWriteInput, FileWriteOutput, CommandListInput, CommandListOutput, SkillListInput, SkillListOutput, RpcCallInput, EventSubscribeOutput, PtyListInput, PtyListOutput, PtyCreateInput, PtyCreateOutput, PtyGetInput, PtyGetOutput, PtyUpdateInput, PtyUpdateOutput, PtyRemoveInput, PtyConnectTokenInput, PtyConnectTokenOutput, ExperimentalPersistentPtyReadInput, ExperimentalPersistentPtyListInput, ExperimentalPersistentPtyCreateInput, ExperimentalPersistentPtyHandoffOutput, ExperimentalPersistentPtyGetInput, ExperimentalPersistentPtyUpdateInput, ExperimentalPersistentPtySnapshotInput, ExperimentalPersistentPtyRemoveInput, ExperimentalPersistentPtyConnectTokenInput, ShellListInput, ShellListOutput, ShellCreateInput, ShellCreateOutput, ShellGetInput, ShellGetOutput, ShellOutputInput, ShellOutputOutput, ShellRemoveInput, ReferenceListInput, ReferenceListOutput, WorktreeListInput, WorktreeCreateInput, WorktreeRemoveInput, WorktreeRefreshInput, VcsGetInput, VcsGetOutput, VcsBaseInput, VcsBaseOutput, VcsStatusInput, VcsStatusOutput, VcsBranchListInput, VcsBranchListOutput, VcsDiffInput, VcsDiffOutput, DebugLocationListOutput, DebugLocationEvictInput, MigrationV1StatusOutput, WebsearchProvidersInput, WebsearchProvidersOutput, WebsearchQueryInput, WebsearchQueryOutput, ConfigGetInput, ConfigGetOutput, ConfigShellsOutput, ConfigUpdateInput } from "./types.js";
1
+ import type { ServerConnectInput, LocationGetInput, AgentListInput, AgentListOutput, AgentGetInput, AgentGetOutput, PluginListInput, PluginListOutput, PluginCheckInput, PluginCheckOutput, PluginUpdateInput, SessionListInput, SessionStatsInput, SessionCreateInput, SessionImportInput, SessionExportInput, SessionGetInput, SessionRemoveInput, SessionForkInput, SessionSwitchAgentInput, SessionSwitchModelInput, SessionUpdateInput, SessionMoveInput, SessionPromptInput, SessionCommandInput, SessionSkillInput, SessionSyntheticInput, SessionShellInput, SessionCompactInput, SessionWaitInput, SessionRevertStageInput, SessionRevertClearInput, SessionRevertCommitInput, SessionContextInput, SessionDiffInput, SessionInboxListInput, SessionInboxCancelInput, SessionInboxUpdateInput, SessionInstructionsEntryListInput, SessionInstructionsEntryPutInput, SessionInstructionsEntryRemoveInput, SessionGenerateInput, SessionLogInput, SessionLogOutput, SessionInterruptInput, SessionBackgroundInput, SessionMessageGetInput, SessionFormListInput, SessionFormCreateInput, SessionFormGetInput, SessionFormReplyInput, SessionFormCancelInput, SessionEnvironmentInput, SessionViewInput, MessageListInput, ModelListInput, ModelListOutput, ModelDefaultInput, ModelDefaultOutput, GenerateTextInput, ProviderListInput, ProviderListOutput, ProviderGetInput, ProviderGetOutput, IntegrationListInput, IntegrationListOutput, IntegrationGetInput, IntegrationGetOutput, IntegrationWellknownAddInput, IntegrationConnectKeyInput, IntegrationOauthConnectInput, IntegrationOauthConnectOutput, IntegrationOauthStatusInput, IntegrationOauthStatusOutput, IntegrationOauthCompleteInput, IntegrationOauthCancelInput, IntegrationCommandConnectInput, IntegrationCommandConnectOutput, IntegrationCommandStatusInput, IntegrationCommandStatusOutput, IntegrationCommandCancelInput, McpListInput, McpListOutput, McpAddInput, McpRemoveInput, McpConnectInput, McpDisconnectInput, McpResourceCatalogInput, McpResourceCatalogOutput, CredentialCreateInput, CredentialUpdateInput, CredentialActivateInput, CredentialRemoveInput, ProjectListOutput, ProjectUpdateInput, FormListInput, FormListOutput, PermissionRequestListInput, PermissionRequestListOutput, PermissionSavedListInput, PermissionSavedRemoveInput, PermissionCreateInput, PermissionListInput, PermissionGetInput, PermissionReplyInput, FileReadInput, FileReadOutput, FileListInput, FileListOutput, FileFindInput, FileFindOutput, FileWriteInput, FileWriteOutput, CommandListInput, CommandListOutput, SkillListInput, SkillListOutput, RpcCallInput, EventSubscribeOutput, PtyListInput, PtyListOutput, PtyCreateInput, PtyCreateOutput, PtyGetInput, PtyGetOutput, PtyUpdateInput, PtyUpdateOutput, PtyRemoveInput, PtyConnectTokenInput, PtyConnectTokenOutput, ExperimentalPersistentPtyReadInput, ExperimentalPersistentPtyListInput, ExperimentalPersistentPtyCreateInput, ExperimentalPersistentPtyHandoffOutput, ExperimentalPersistentPtyGetInput, ExperimentalPersistentPtyUpdateInput, ExperimentalPersistentPtySnapshotInput, ExperimentalPersistentPtyRemoveInput, ExperimentalPersistentPtyConnectTokenInput, ShellListInput, ShellListOutput, ShellCreateInput, ShellCreateOutput, ShellGetInput, ShellGetOutput, ShellOutputInput, ShellOutputOutput, ShellRemoveInput, ReferenceListInput, ReferenceListOutput, WorktreeListInput, WorktreeCreateInput, WorktreeRemoveInput, WorktreeRefreshInput, VcsInitInput, VcsGetInput, VcsGetOutput, VcsBaseInput, VcsBaseOutput, VcsStatusInput, VcsStatusOutput, VcsBranchListInput, VcsBranchListOutput, VcsDiffInput, VcsDiffOutput, DebugLocationListOutput, DebugLocationEvictInput, MigrationV1StatusOutput, WebsearchProvidersInput, WebsearchProvidersOutput, WebsearchQueryInput, WebsearchQueryOutput, ConfigGetInput, ConfigGetOutput, ConfigShellsOutput, ConfigUpdateInput } from "./types.js";
2
2
  export interface ClientOptions {
3
3
  readonly baseUrl: string;
4
4
  readonly fetch?: typeof globalThis.fetch;
@@ -226,6 +226,7 @@ export declare function make(options: ClientOptions): {
226
226
  refresh: (input: WorktreeRefreshInput, requestOptions?: RequestOptions) => Promise<void>;
227
227
  };
228
228
  vcs: {
229
+ init: (input?: VcsInitInput, requestOptions?: RequestOptions) => Promise<void>;
229
230
  get: (input?: VcsGetInput, requestOptions?: RequestOptions) => Promise<VcsGetOutput>;
230
231
  base: (input?: VcsBaseInput, requestOptions?: RequestOptions) => Promise<VcsBaseOutput>;
231
232
  status: (input?: VcsStatusInput, requestOptions?: RequestOptions) => Promise<VcsStatusOutput>;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  make6
3
- } from "../../chunks/service-contender-50fct660.js";
4
- import"../../chunks/service-contender-nwcpakzx.js";
3
+ } from "../../chunks/service-version-nyqggzs9.js";
4
+ import"../../chunks/service-version-nwcpakzx.js";
5
5
  export {
6
6
  make6 as make
7
7
  };
@@ -1,13 +1,14 @@
1
- import"../../chunks/service-contender-vyas3vgt.js";
1
+ import"../../chunks/service-version-vyas3vgt.js";
2
2
  import {
3
3
  exports_client4
4
- } from "../../chunks/service-contender-50fct660.js";
4
+ } from "../../chunks/service-version-nyqggzs9.js";
5
5
  import {
6
6
  ClientError3
7
- } from "../../chunks/service-contender-nwcpakzx.js";
7
+ } from "../../chunks/service-version-nwcpakzx.js";
8
8
  import {
9
9
  isInvalidRequestError2,
10
10
  isUnauthorizedError2,
11
+ isLocationNotFoundError2,
11
12
  isServiceUnavailableError2,
12
13
  isAgentNotFoundError2,
13
14
  isInvalidCursorError2,
@@ -36,8 +37,9 @@ import {
36
37
  isPtyNotFoundError2,
37
38
  isForbiddenError2,
38
39
  isShellNotFoundError2,
39
- isWorktreeError2
40
- } from "../../chunks/service-contender-4tveyqeh.js";
40
+ isWorktreeError2,
41
+ isVcsInitNotSupportedError2
42
+ } from "../../chunks/service-version-vt9jbch8.js";
41
43
  export {
42
44
  ClientError3 as ClientError,
43
45
  exports_client4 as OpenCode,
@@ -56,6 +58,7 @@ export {
56
58
  isIntegrationNotFoundError2 as isIntegrationNotFoundError,
57
59
  isInvalidCursorError2 as isInvalidCursorError,
58
60
  isInvalidRequestError2 as isInvalidRequestError,
61
+ isLocationNotFoundError2 as isLocationNotFoundError,
59
62
  isMcpServerNotFoundError2 as isMcpServerNotFoundError,
60
63
  isMessageNotFoundError2 as isMessageNotFoundError,
61
64
  isPermissionNotFoundError2 as isPermissionNotFoundError,
@@ -71,5 +74,6 @@ export {
71
74
  isSkillNotFoundError2 as isSkillNotFoundError,
72
75
  isUnauthorizedError2 as isUnauthorizedError,
73
76
  isUnknownError2 as isUnknownError,
77
+ isVcsInitNotSupportedError2 as isVcsInitNotSupportedError,
74
78
  isWorktreeError2 as isWorktreeError
75
79
  };
@@ -8,6 +8,9 @@ export type ServerInfo = {
8
8
  paths: {
9
9
  tmp: string;
10
10
  };
11
+ capabilities?: {
12
+ persistentPty?: boolean | undefined;
13
+ } | undefined;
11
14
  };
12
15
  export type PairingCode = {
13
16
  code: string;
@@ -3365,6 +3368,14 @@ export type UnauthorizedError = {
3365
3368
  readonly message: string;
3366
3369
  };
3367
3370
  export declare const isUnauthorizedError: (value: unknown) => value is UnauthorizedError;
3371
+ export type LocationNotFoundError = {
3372
+ readonly _tag: "LocationNotFoundError";
3373
+ readonly location: {
3374
+ readonly directory: string;
3375
+ };
3376
+ readonly message: string;
3377
+ };
3378
+ export declare const isLocationNotFoundError: (value: unknown) => value is LocationNotFoundError;
3368
3379
  export type ServiceUnavailableError = {
3369
3380
  readonly _tag: "ServiceUnavailableError";
3370
3381
  readonly message: string;
@@ -3538,6 +3549,7 @@ export type ShellNotFoundError = {
3538
3549
  };
3539
3550
  export declare const isShellNotFoundError: (value: unknown) => value is ShellNotFoundError;
3540
3551
  export type WorktreeError = {
3552
+ readonly _tag: "WorktreeError";
3541
3553
  readonly name: "WorktreeError";
3542
3554
  readonly data: {
3543
3555
  readonly message: string;
@@ -3545,6 +3557,12 @@ export type WorktreeError = {
3545
3557
  };
3546
3558
  };
3547
3559
  export declare const isWorktreeError: (value: unknown) => value is WorktreeError;
3560
+ export type VcsInitNotSupportedError = {
3561
+ readonly _tag: "VcsInitNotSupportedError";
3562
+ readonly providerID: string;
3563
+ readonly message: string;
3564
+ };
3565
+ export declare const isVcsInitNotSupportedError: (value: unknown) => value is VcsInitNotSupportedError;
3548
3566
  export type ServerInfoOutput = ServerInfo;
3549
3567
  export type ServerPairOutput = PairingCode;
3550
3568
  export type ServerConnectInput = {
@@ -8577,6 +8595,21 @@ export type WorktreeRefreshInput = {
8577
8595
  }["projectID"];
8578
8596
  };
8579
8597
  export type WorktreeRefreshOutput = void;
8598
+ export type VcsInitInput = {
8599
+ readonly location?: {
8600
+ readonly location?: {
8601
+ readonly directory?: string | undefined;
8602
+ } | undefined;
8603
+ readonly provider?: string | undefined;
8604
+ }["location"];
8605
+ readonly provider?: {
8606
+ readonly location?: {
8607
+ readonly directory?: string | undefined;
8608
+ } | undefined;
8609
+ readonly provider?: string | undefined;
8610
+ }["provider"];
8611
+ };
8612
+ export type VcsInitOutput = void;
8580
8613
  export type VcsGetInput = {
8581
8614
  readonly location?: {
8582
8615
  readonly location?: {
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  isInvalidRequestError2,
3
3
  isUnauthorizedError2,
4
+ isLocationNotFoundError2,
4
5
  isServiceUnavailableError2,
5
6
  isAgentNotFoundError2,
6
7
  isInvalidCursorError2,
@@ -29,8 +30,9 @@ import {
29
30
  isPtyNotFoundError2,
30
31
  isForbiddenError2,
31
32
  isShellNotFoundError2,
32
- isWorktreeError2
33
- } from "../../chunks/service-contender-4tveyqeh.js";
33
+ isWorktreeError2,
34
+ isVcsInitNotSupportedError2
35
+ } from "../../chunks/service-version-vt9jbch8.js";
34
36
  export {
35
37
  isAgentNotFoundError2 as isAgentNotFoundError,
36
38
  isCommandExecutionError2 as isCommandExecutionError,
@@ -47,6 +49,7 @@ export {
47
49
  isIntegrationNotFoundError2 as isIntegrationNotFoundError,
48
50
  isInvalidCursorError2 as isInvalidCursorError,
49
51
  isInvalidRequestError2 as isInvalidRequestError,
52
+ isLocationNotFoundError2 as isLocationNotFoundError,
50
53
  isMcpServerNotFoundError2 as isMcpServerNotFoundError,
51
54
  isMessageNotFoundError2 as isMessageNotFoundError,
52
55
  isPermissionNotFoundError2 as isPermissionNotFoundError,
@@ -62,5 +65,6 @@ export {
62
65
  isSkillNotFoundError2 as isSkillNotFoundError,
63
66
  isUnauthorizedError2 as isUnauthorizedError,
64
67
  isUnknownError2 as isUnknownError,
68
+ isVcsInitNotSupportedError2 as isVcsInitNotSupportedError,
65
69
  isWorktreeError2 as isWorktreeError
66
70
  };
@@ -1,16 +1,17 @@
1
- import"../chunks/service-contender-m2eywc8w.js";
1
+ import"../chunks/service-version-m2eywc8w.js";
2
2
  import {
3
3
  exports_client3
4
- } from "../chunks/service-contender-992ffpa9.js";
5
- import"../chunks/service-contender-vyas3vgt.js";
6
- import"../chunks/service-contender-50fct660.js";
4
+ } from "../chunks/service-version-gah0fg5v.js";
5
+ import"../chunks/service-version-vyas3vgt.js";
6
+ import"../chunks/service-version-nyqggzs9.js";
7
7
  import {
8
8
  ClientError3
9
- } from "../chunks/service-contender-nwcpakzx.js";
10
- import"../chunks/service-contender-1tbj6z39.js";
9
+ } from "../chunks/service-version-nwcpakzx.js";
10
+ import"../chunks/service-version-1y4a697q.js";
11
11
  import {
12
12
  isInvalidRequestError2,
13
13
  isUnauthorizedError2,
14
+ isLocationNotFoundError2,
14
15
  isServiceUnavailableError2,
15
16
  isAgentNotFoundError2,
16
17
  isInvalidCursorError2,
@@ -39,9 +40,10 @@ import {
39
40
  isPtyNotFoundError2,
40
41
  isForbiddenError2,
41
42
  isShellNotFoundError2,
42
- isWorktreeError2
43
- } from "../chunks/service-contender-4tveyqeh.js";
44
- import"../chunks/service-contender-frbwqjmf.js";
43
+ isWorktreeError2,
44
+ isVcsInitNotSupportedError2
45
+ } from "../chunks/service-version-vt9jbch8.js";
46
+ import"../chunks/service-version-frbwqjmf.js";
45
47
  export {
46
48
  ClientError3 as ClientError,
47
49
  exports_client3 as OpenCode,
@@ -60,6 +62,7 @@ export {
60
62
  isIntegrationNotFoundError2 as isIntegrationNotFoundError,
61
63
  isInvalidCursorError2 as isInvalidCursorError,
62
64
  isInvalidRequestError2 as isInvalidRequestError,
65
+ isLocationNotFoundError2 as isLocationNotFoundError,
63
66
  isMcpServerNotFoundError2 as isMcpServerNotFoundError,
64
67
  isMessageNotFoundError2 as isMessageNotFoundError,
65
68
  isPermissionNotFoundError2 as isPermissionNotFoundError,
@@ -75,5 +78,6 @@ export {
75
78
  isSkillNotFoundError2 as isSkillNotFoundError,
76
79
  isUnauthorizedError2 as isUnauthorizedError,
77
80
  isUnknownError2 as isUnknownError,
81
+ isVcsInitNotSupportedError2 as isVcsInitNotSupportedError,
78
82
  isWorktreeError2 as isWorktreeError
79
83
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  makeRpc2
3
- } from "../chunks/service-contender-1tbj6z39.js";
4
- import"../chunks/service-contender-4tveyqeh.js";
3
+ } from "../chunks/service-version-1y4a697q.js";
4
+ import"../chunks/service-version-vt9jbch8.js";
5
5
  export {
6
6
  makeRpc2 as makeRpc
7
7
  };
@@ -2,21 +2,21 @@ import {
2
2
  spawnServiceContender2,
3
3
  contenderFailure2,
4
4
  contenderFinished2
5
- } from "../chunks/service-contender-txckps9j.js";
5
+ } from "../chunks/service-version-6f43cgzz.js";
6
6
  import {
7
7
  defaultEnsureTiming2,
8
8
  ensureTiming2
9
- } from "../chunks/service-contender-xgnj2w4v.js";
9
+ } from "../chunks/service-version-xgnj2w4v.js";
10
10
  import {
11
11
  matchesVersion2
12
- } from "../chunks/service-contender-sxt88q69.js";
12
+ } from "../chunks/service-version-sxt88q69.js";
13
13
  import {
14
14
  prepare2,
15
15
  environment2,
16
16
  complete2,
17
17
  clear2
18
- } from "../chunks/service-contender-1kn39gq3.js";
19
- import"../chunks/service-contender-qav6mfdz.js";
18
+ } from "../chunks/service-version-02j88w0z.js";
19
+ import"../chunks/service-version-qav6mfdz.js";
20
20
 
21
21
  // src/promise/service.ts
22
22
  import { readFile, rm } from "node:fs/promises";
@@ -40,6 +40,7 @@ async function ensure(options = {}) {
40
40
  let announced = false;
41
41
  let lastSpawn = 0;
42
42
  let spawnDelay = timing.spawnDelay;
43
+ let failure;
43
44
  const announce = (reason, previousVersion) => {
44
45
  if (announced)
45
46
  return;
@@ -59,7 +60,7 @@ async function ensure(options = {}) {
59
60
  try {
60
61
  while (true) {
61
62
  if (Date.now() >= deadline)
62
- throw new Error("Timed out waiting for the background service to start");
63
+ throw failure ?? new Error("Timed out waiting for the background service to start");
63
64
  const registration = await registered(options.file, timing.requestTimeout);
64
65
  if (registration.timedOut && registration.info !== undefined) {
65
66
  timeouts = {
@@ -71,6 +72,13 @@ async function ensure(options = {}) {
71
72
  console.warn("Background service is unresponsive; recovery cannot preserve persistent terminals");
72
73
  await clear2(options.file ?? fallback());
73
74
  await terminate(registration.info, options, timing);
75
+ for (const item of contenders) {
76
+ if (item.child.pid === registration.info.pid || contenderFinished2(item)) {
77
+ item.release();
78
+ contenders.delete(item);
79
+ }
80
+ }
81
+ failure = undefined;
74
82
  timeouts = undefined;
75
83
  lastSpawn = Date.now() - spawnDelay;
76
84
  }
@@ -79,7 +87,10 @@ async function ensure(options = {}) {
79
87
  if (registration.service !== undefined) {
80
88
  spawnDelay = timing.spawnDelay;
81
89
  const service2 = registration.service;
82
- const compatible = service2.compatible && matchesVersion2(service2.version, options);
90
+ const versionMatches = matchesVersion2(service2.version, options);
91
+ const compatible = service2.compatible && versionMatches;
92
+ if (!service2.compatible && versionMatches)
93
+ throw new Error("Background service uses an incompatible health protocol. Update this client or explicitly restart the service.");
83
94
  if (compatible && service2.state === "ready") {
84
95
  await complete2(options.file ?? fallback(), service2.info);
85
96
  return service2.endpoint;
@@ -96,20 +107,27 @@ async function ensure(options = {}) {
96
107
  }).catch(() => {
97
108
  return;
98
109
  });
110
+ for (const item of contenders) {
111
+ if (item.child.pid === service2.info.pid || contenderFinished2(item)) {
112
+ item.release();
113
+ contenders.delete(item);
114
+ }
115
+ }
116
+ failure = undefined;
99
117
  lastSpawn = 0;
100
118
  }
101
119
  } else {
102
120
  if (lastSpawn === 0 && registration.info !== undefined)
103
121
  lastSpawn = Date.now();
104
122
  const finished = [...contenders].filter(contenderFinished2);
105
- const failure = finished.map(contenderFailure2).find((error) => error !== undefined);
123
+ failure ??= finished.map(contenderFailure2).find((error) => error !== undefined);
106
124
  if (finished.some((item) => item.child.exitCode === 0)) {
107
125
  spawnDelay = Math.min(spawnDelay * 2, timing.maxSpawnDelay);
108
126
  }
109
127
  finished.forEach((item) => contenders.delete(item));
110
128
  if (failure !== undefined && contenders.size === 0)
111
129
  throw failure;
112
- if (contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay) {
130
+ if (failure === undefined && contenders.size < 2 && Date.now() - lastSpawn >= spawnDelay) {
113
131
  announce("missing");
114
132
  contenders.add(await spawnContender());
115
133
  lastSpawn = Date.now();
@@ -123,12 +141,9 @@ async function ensure(options = {}) {
123
141
  }
124
142
  async function stop(options = {}) {
125
143
  const info = await read(options.file);
126
- if (options.pty === "handoff" && info !== undefined)
127
- await prepare2(options.file ?? fallback(), info, defaultEnsureTiming2.requestTimeout);
128
- else
129
- await clear2(options.file ?? fallback());
144
+ await (options.pty === "handoff" && info !== undefined ? prepare2(options.file ?? fallback(), info, defaultEnsureTiming2.requestTimeout) : clear2(options.file ?? fallback())).catch((cause) => console.warn("Failed to prepare persistent terminals for replacement", cause));
130
145
  if (info !== undefined)
131
- await terminate(info, options, defaultEnsureTiming2);
146
+ await terminate(info, options, ensureTiming2(options));
132
147
  }
133
148
  function fallback() {
134
149
  return join(process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state"), "opencode", "service.json");
@@ -241,9 +256,6 @@ async function terminate(info, options, timing) {
241
256
  return;
242
257
  signal(info.pid, "SIGTERM");
243
258
  if (!await waitUntilStopped(info.pid, timing)) {
244
- const latest = await read(options.file);
245
- if (latest === undefined || !same(latest, info))
246
- return;
247
259
  signal(info.pid, "SIGKILL");
248
260
  if (!await waitUntilStopped(info.pid, timing))
249
261
  throw new Error(`Server process ${info.pid} is still running`);
@@ -1,6 +1,9 @@
1
1
  export * as PtyHandoff from "./pty-handoff.js";
2
2
  import type { Info } from "./service.js";
3
- /** Publish the ticket before stopping its owner so every replacement contender can adopt it. */
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
+ */
4
7
  export declare function prepare(file: string, info: Info, timeout: number): Promise<void>;
5
8
  export declare function environment(file: string, env?: Readonly<Record<string, string>>): Promise<{
6
9
  OPENCODE_PTY_HANDOFF: string | undefined;
@@ -4,7 +4,7 @@ import {
4
4
  complete2,
5
5
  clear2,
6
6
  exports_pty_handoff
7
- } from "./chunks/service-contender-1kn39gq3.js";
7
+ } from "./chunks/service-version-02j88w0z.js";
8
8
  export {
9
9
  exports_pty_handoff as PtyHandoff,
10
10
  clear2 as clear,
@@ -4,7 +4,7 @@ import {
4
4
  event2,
5
5
  eventType2,
6
6
  exports_rpc_runtime
7
- } from "./chunks/service-contender-t1xa31vm.js";
7
+ } from "./chunks/service-version-t1xa31vm.js";
8
8
  export {
9
9
  exports_rpc_runtime as RpcRuntime,
10
10
  event2 as event,
@@ -2,7 +2,7 @@ import {
2
2
  spawnServiceContender2,
3
3
  contenderFailure2,
4
4
  contenderFinished2
5
- } from "./chunks/service-contender-txckps9j.js";
5
+ } from "./chunks/service-version-6f43cgzz.js";
6
6
  export {
7
7
  contenderFailure2 as contenderFailure,
8
8
  contenderFinished2 as contenderFinished,
@@ -2,7 +2,7 @@ import {
2
2
  defaultEnsureTiming2,
3
3
  ensureTiming2,
4
4
  withEnsureTiming2
5
- } from "./chunks/service-contender-xgnj2w4v.js";
5
+ } from "./chunks/service-version-xgnj2w4v.js";
6
6
  export {
7
7
  defaultEnsureTiming2 as defaultEnsureTiming,
8
8
  ensureTiming2 as ensureTiming,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  matchesVersion2
3
- } from "./chunks/service-contender-sxt88q69.js";
3
+ } from "./chunks/service-version-sxt88q69.js";
4
4
  export {
5
5
  matchesVersion2 as matchesVersion
6
6
  };
package/dist/service.js CHANGED
@@ -1 +1 @@
1
- import"./chunks/service-contender-qav6mfdz.js";
1
+ import"./chunks/service-version-qav6mfdz.js";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  make7,
3
3
  exports_shared_events
4
- } from "./chunks/service-contender-frbwqjmf.js";
4
+ } from "./chunks/service-version-frbwqjmf.js";
5
5
  export {
6
6
  exports_shared_events as SharedEvents,
7
7
  make7 as make
@@ -2,7 +2,7 @@ import {
2
2
  defaultIdleTimeout2,
3
3
  foregroundIdleThreshold2,
4
4
  createClientConnection2
5
- } from "../chunks/service-contender-ydhz1zrh.js";
5
+ } from "../chunks/service-version-ydhz1zrh.js";
6
6
  export {
7
7
  createClientConnection2 as createClientConnection,
8
8
  defaultIdleTimeout2 as defaultIdleTimeout,
@@ -2,15 +2,15 @@ import {
2
2
  settleMs2,
3
3
  locationKey2,
4
4
  createData2
5
- } from "../chunks/service-contender-h11j9btw.js";
6
- import"../chunks/service-contender-m2eywc8w.js";
7
- import"../chunks/service-contender-992ffpa9.js";
8
- import"../chunks/service-contender-vyas3vgt.js";
9
- import"../chunks/service-contender-50fct660.js";
10
- import"../chunks/service-contender-nwcpakzx.js";
11
- import"../chunks/service-contender-1tbj6z39.js";
12
- import"../chunks/service-contender-4tveyqeh.js";
13
- import"../chunks/service-contender-frbwqjmf.js";
5
+ } from "../chunks/service-version-e5ea35j7.js";
6
+ import"../chunks/service-version-m2eywc8w.js";
7
+ import"../chunks/service-version-gah0fg5v.js";
8
+ import"../chunks/service-version-vyas3vgt.js";
9
+ import"../chunks/service-version-nyqggzs9.js";
10
+ import"../chunks/service-version-nwcpakzx.js";
11
+ import"../chunks/service-version-1y4a697q.js";
12
+ import"../chunks/service-version-vt9jbch8.js";
13
+ import"../chunks/service-version-frbwqjmf.js";
14
14
  export {
15
15
  createData2 as createData,
16
16
  locationKey2 as locationKey,