@fro.bot/space-bus 0.7.0 → 0.8.0

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/README.md CHANGED
@@ -107,12 +107,14 @@ Programmatic consumers (e.g. Mothership) that want to drive the lifecycle direct
107
107
 
108
108
  ## Library surface
109
109
 
110
- Experimental subpath exports expose the bus's semantics directly — the same functions the four tools run on — for renderers and other consumers that want structured state instead of formatted strings. Subpaths are experimental: shapes may change in minor releases; pin the version if you adopt them.
110
+ Experimental subpath exports expose the bus's internals directly — the functions the four tools run on, plus the managed-server lifecycle and the attach resolver — for renderers and other consumers that want structured state instead of formatted strings. Subpaths are experimental: shapes may change in minor releases; pin the version if you adopt them.
111
111
 
112
112
  - `@fro.bot/space-bus/core` — browser-safe; no Node builtins, no ambient env reads. Every exported function takes a `context: BusContext` (`{ roster, credentials? }`) that you build yourself and pass in — core never resolves it for you. Includes `snapshot()`, a one-call composite of roster + per-project status + pending questions with bounded fan-out.
113
113
  - `@fro.bot/space-bus/config` — Node-only. `loadContext(directory?)` reads `spacebus.json` (honoring `SPACE_BUS_CONFIG` the same as the plugin) and returns a ready-to-use `BusContext`, with per-project `exists` flags and env-derived credentials attached. Build a fresh context per call; it's per-call/short-lived by contract, not meant to be cached across filesystem changes.
114
114
  - `@fro.bot/space-bus/contract` — the zod schemas (and inferred types) behind the OpenCode API and `BusContext`, for consumers hitting the server directly and wanting the same shapes. Schemas are zod v4.
115
115
  - `@fro.bot/space-bus/format` — the pure formatters the tools use to render output, for tool-identical text.
116
+ - `@fro.bot/space-bus/server` — Node-only. The managed-server lifecycle (`ensureServer`/`serverStatus`/`stopServer`) for consumers driving spawn/attach/stop directly — see [Managed server](#managed-server).
117
+ - `@fro.bot/space-bus/attach` — browser-safe. `resolveManagedServer(workspaceDir, seams)` resolves a managed roster's running endpoint by reading the discovery file through injected filesystem/env/crypto seams — re-checking the localhost guard and probing liveness — so an external attacher such as a Tauri webview can attach without any `node:*` imports or reimplementing the discovery contract. Returns `{ baseUrl, credentials, alive }` or an actionable error.
116
118
 
117
119
  Node example (`/config` + `/core`):
118
120
 
@@ -129,7 +131,7 @@ if (result.ok) {
129
131
  }
130
132
  ```
131
133
 
132
- Browser consumers: `/core`, `/contract`, and `/format` are browser-safe (their module graphs are bundle-tested in CI to exclude `node:*` imports and never reach `/config`). `/config` is Node-only — browser code can't call `loadContext`, so credentials must be injected explicitly by whatever server-side process builds the `BusContext` (never read ambiently by core). The localhost guard travels with the context: it's re-checked at core's single validation gate on every call, so a context built from a non-local `baseUrl` is rejected there, not just at config's load time.
134
+ Browser consumers: `/core`, `/contract`, `/format`, and `/attach` are browser-safe (their module graphs are bundle-tested in CI to exclude `node:*` imports and never reach `/config`). `/config` is Node-only — browser code can't call `loadContext`, so credentials must be injected explicitly by whatever server-side process builds the `BusContext` (never read ambiently by core). The localhost guard travels with the context: it's re-checked at core's single validation gate on every call, so a context built from a non-local `baseUrl` is rejected there, not just at config's load time.
133
135
 
134
136
  ## Claude Desktop
135
137
 
package/dist/attach.js CHANGED
@@ -103,7 +103,7 @@ var managedSpawnConfigSchema = z.object({
103
103
  });
104
104
  var discoveryFileSchema = z.object({
105
105
  port: z.number().int().nonnegative(),
106
- pid: z.number().int().positive(),
106
+ pid: z.number().int().min(2),
107
107
  identity: z.string(),
108
108
  password: z.string(),
109
109
  spawnConfig: managedSpawnConfigSchema,
package/dist/cli.d.ts CHANGED
@@ -1 +1,26 @@
1
+ import { ensureServer, type ServerHandle, type SuperviseOutcome, stopServer } from "./server";
2
+ interface ParsedArgs {
3
+ command: string | undefined;
4
+ json: boolean;
5
+ foreground: boolean;
6
+ config: string | undefined;
7
+ help: boolean;
8
+ unknownFlags: string[];
9
+ /** --config was the last arg with no following value. */
10
+ configMissingValue: boolean;
11
+ }
12
+ /** Injectable dependencies for `runServe`'s foreground supervision — lets
13
+ * tests drive the signal/died/hung outcomes deterministically without a
14
+ * real daemon or real timers. Defaults to the real implementations. */
15
+ export interface RunServeDeps {
16
+ ensureServer?: typeof ensureServer;
17
+ stopServer?: typeof stopServer;
18
+ /** Receives a `shouldStop` seam wired to the process signal handlers —
19
+ * when a signal fires, `shouldStop()` starts returning true so the loop
20
+ * (real or injected) can break with `{ reason: "signal" }` — plus an
21
+ * `interrupt` promise that resolves immediately on signal, so the
22
+ * inter-tick sleep doesn't have to wait out the full interval. */
23
+ superviseServer?: (rosterPath: string, handle: ServerHandle, shouldStop: () => boolean, interrupt: Promise<void>) => Promise<SuperviseOutcome>;
24
+ }
25
+ export declare function runServe(args: ParsedArgs, deps?: RunServeDeps): Promise<number>;
1
26
  export {};
package/dist/cli.js CHANGED
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
3
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
4
+
2
5
  // src/contract.ts
3
6
  import { z } from "zod";
4
7
  var sessionSchema = z.looseObject({
@@ -104,7 +107,7 @@ var managedSpawnConfigSchema = z.object({
104
107
  });
105
108
  var discoveryFileSchema = z.object({
106
109
  port: z.number().int().nonnegative(),
107
- pid: z.number().int().positive(),
110
+ pid: z.number().int().min(2),
108
111
  identity: z.string(),
109
112
  password: z.string(),
110
113
  spawnConfig: managedSpawnConfigSchema,
@@ -189,14 +192,27 @@ function removeDiscovery(rosterPath) {
189
192
  throw err;
190
193
  }
191
194
  }
195
+ function removeDiscoveryIfMatches(rosterPath, expected) {
196
+ try {
197
+ const current = readDiscovery(rosterPath);
198
+ if (current && current.pid === expected.pid && current.identity === expected.identity) {
199
+ removeDiscovery(rosterPath);
200
+ }
201
+ } catch {}
202
+ }
192
203
  function attachLive(rosterPath) {
193
204
  const discovery = readDiscovery(rosterPath);
194
205
  if (!discovery)
195
206
  return null;
196
207
  if (!loopbackOk(discovery.baseUrl))
197
208
  return null;
198
- if (!verifyIdentity(discovery.pid, discovery.identity))
209
+ if (!verifyIdentity(discovery.pid, discovery.identity)) {
210
+ removeDiscoveryIfMatches(rosterPath, {
211
+ pid: discovery.pid,
212
+ identity: discovery.identity
213
+ });
199
214
  return null;
215
+ }
200
216
  return {
201
217
  baseUrl: discovery.baseUrl,
202
218
  credentials: { username: "opencode", password: discovery.password },
@@ -231,7 +247,7 @@ function verifyIdentity(pid, storedIdentity) {
231
247
  return current !== null && current === storedIdentity;
232
248
  }
233
249
  var lockFileSchema = z2.object({
234
- pid: z2.number().int().positive(),
250
+ pid: z2.number().int().min(2),
235
251
  startTime: z2.string(),
236
252
  since: z2.number()
237
253
  });
@@ -327,7 +343,7 @@ function provisionalFilePath(rosterPath) {
327
343
  return join(stateDirFor(rosterPath), "spawn.provisional.json");
328
344
  }
329
345
  var provisionalFileSchema = z2.object({
330
- pid: z2.number().int().positive(),
346
+ pid: z2.number().int().min(2),
331
347
  identity: z2.string(),
332
348
  password: z2.string(),
333
349
  since: z2.number()
@@ -496,6 +512,9 @@ var POLL_INTERVAL_MS = 50;
496
512
  var MIN_PROBE_PHASE_MS = 3000;
497
513
  var PROBE_FETCH_TIMEOUT_MS = 2000;
498
514
  var STOP_GRACE_MS = 2000;
515
+ var SUPERVISE_INTERVAL_MS = 5000;
516
+ var SUPERVISE_FAILURE_THRESHOLD = 3;
517
+ var SUPERVISE_UNHEALTHY_BUDGET_MS = 60000;
499
518
  function sleep(ms) {
500
519
  return new Promise((resolve) => setTimeout(resolve, ms));
501
520
  }
@@ -523,11 +542,34 @@ function redactedReadinessError(rosterPath, password, reason) {
523
542
  return new Error(`space-bus: managed server for roster ${rosterPath} ${reason}. Log tail:
524
543
  ${tail}`);
525
544
  }
545
+ function isEpermError(err) {
546
+ return typeof err === "object" && err !== null && "code" in err && err.code === "EPERM";
547
+ }
548
+ function signalGroup(pid, sig) {
549
+ if (pid <= 1) {
550
+ try {
551
+ process.kill(pid, sig);
552
+ } catch {}
553
+ return false;
554
+ }
555
+ try {
556
+ process.kill(-pid, sig);
557
+ return true;
558
+ } catch (err) {
559
+ if (err.code === "EPERM") {
560
+ throw err;
561
+ }
562
+ }
563
+ try {
564
+ process.kill(pid, sig);
565
+ } catch {}
566
+ return false;
567
+ }
526
568
  function killIdentifiedProcess(pid, identity) {
527
569
  try {
528
570
  if (identity !== null && identity !== undefined && identity !== "") {
529
571
  if (verifyIdentity(pid, identity))
530
- process.kill(pid, "SIGTERM");
572
+ signalGroup(pid, "SIGTERM");
531
573
  return;
532
574
  }
533
575
  process.kill(pid, "SIGTERM");
@@ -740,7 +782,14 @@ async function ensureServer(rosterPath, options = {}) {
740
782
  }
741
783
  function serverStatus(rosterPath) {
742
784
  const discovery = readDiscovery(rosterPath);
743
- if (!discovery || !verifyIdentity(discovery.pid, discovery.identity)) {
785
+ if (!discovery) {
786
+ return { running: false };
787
+ }
788
+ if (!verifyIdentity(discovery.pid, discovery.identity)) {
789
+ removeDiscoveryIfMatches(rosterPath, {
790
+ pid: discovery.pid,
791
+ identity: discovery.identity
792
+ });
744
793
  return { running: false };
745
794
  }
746
795
  let configDrift;
@@ -776,28 +825,105 @@ async function stopServer(rosterPath) {
776
825
  return { stopped: false };
777
826
  }
778
827
  const { pid } = discovery;
828
+ let groupSignaled;
829
+ const waitForCompletion = (budgetMs) => groupSignaled ? waitForGroupDeath(pid, budgetMs) : waitForDeath(pid, budgetMs);
779
830
  try {
780
- process.kill(pid, "SIGTERM");
781
- } catch {
831
+ groupSignaled = signalGroup(pid, "SIGTERM");
832
+ } catch (err) {
833
+ if (isEpermError(err)) {
834
+ return { stopped: false };
835
+ }
782
836
  removeDiscovery(rosterPath);
783
837
  return { stopped: true };
784
838
  }
785
- if (await waitForDeath(pid, STOP_GRACE_MS)) {
839
+ if (await waitForCompletion(STOP_GRACE_MS)) {
786
840
  removeDiscovery(rosterPath);
787
841
  return { stopped: true };
788
842
  }
789
843
  try {
790
- process.kill(pid, "SIGKILL");
791
- } catch {
844
+ groupSignaled = signalGroup(pid, "SIGKILL");
845
+ } catch (err) {
846
+ if (isEpermError(err)) {
847
+ return { stopped: false };
848
+ }
792
849
  removeDiscovery(rosterPath);
793
850
  return { stopped: true };
794
851
  }
795
- if (await waitForDeath(pid, STOP_GRACE_MS)) {
852
+ if (await waitForCompletion(STOP_GRACE_MS)) {
796
853
  removeDiscovery(rosterPath);
797
854
  return { stopped: true };
798
855
  }
799
856
  return { stopped: false };
800
857
  }
858
+ async function stopForHung(tick) {
859
+ try {
860
+ await tick.stop(tick.rosterPath);
861
+ } catch {}
862
+ return { kind: "outcome", outcome: { reason: "hung" } };
863
+ }
864
+ async function superviseTick(tick, state) {
865
+ const st = tick.status(tick.rosterPath);
866
+ if (!st.running) {
867
+ return { kind: "outcome", outcome: { reason: "died" } };
868
+ }
869
+ const probeOutcome = await tick.probe(tick.handle.baseUrl, tick.password);
870
+ const failures = probeOutcome === "retry" ? state.failures + 1 : 0;
871
+ const lastReadyAt = probeOutcome === "ready" ? tick.now() : state.lastReadyAt;
872
+ if (failures >= tick.threshold) {
873
+ return stopForHung(tick);
874
+ }
875
+ if (tick.now() - lastReadyAt >= tick.unhealthyBudgetMs) {
876
+ return stopForHung(tick);
877
+ }
878
+ return { kind: "tick", failures, lastReadyAt };
879
+ }
880
+ function makeSuperviseTick(rosterPath, handle, opts) {
881
+ return {
882
+ rosterPath,
883
+ handle,
884
+ password: handle.credentials.password ?? "",
885
+ threshold: opts.threshold ?? SUPERVISE_FAILURE_THRESHOLD,
886
+ unhealthyBudgetMs: opts.unhealthyBudgetMs ?? SUPERVISE_UNHEALTHY_BUDGET_MS,
887
+ now: opts.now ?? Date.now,
888
+ status: opts.status ?? serverStatus,
889
+ probe: opts.probe ?? probe,
890
+ stop: opts.stop ?? stopServer
891
+ };
892
+ }
893
+ async function interruptibleSleep(doSleep, intervalMs, interrupt) {
894
+ if (!interrupt) {
895
+ await doSleep(intervalMs);
896
+ return;
897
+ }
898
+ let timer;
899
+ const timed = new Promise((resolve) => {
900
+ timer = setTimeout(resolve, intervalMs);
901
+ });
902
+ try {
903
+ await Promise.race([timed, interrupt]);
904
+ } finally {
905
+ if (timer !== undefined)
906
+ clearTimeout(timer);
907
+ }
908
+ }
909
+ async function superviseServer(rosterPath, handle, opts = {}) {
910
+ const intervalMs = opts.intervalMs ?? SUPERVISE_INTERVAL_MS;
911
+ const tick = makeSuperviseTick(rosterPath, handle, opts);
912
+ const doSleep = opts.sleep ?? sleep;
913
+ const shouldStop = opts.shouldStop ?? (() => false);
914
+ let state = { failures: 0, lastReadyAt: tick.now() };
915
+ for (;; ) {
916
+ if (shouldStop())
917
+ return { reason: "signal" };
918
+ const result = await superviseTick(tick, state);
919
+ if (result.kind === "outcome")
920
+ return result.outcome;
921
+ state = { failures: result.failures, lastReadyAt: result.lastReadyAt };
922
+ if (shouldStop())
923
+ return { reason: "signal" };
924
+ await interruptibleSleep(doSleep, intervalMs, opts.interrupt);
925
+ }
926
+ }
801
927
  async function waitForDeath(pid, budgetMs) {
802
928
  const deadline = Date.now() + budgetMs;
803
929
  while (Date.now() < deadline) {
@@ -807,6 +933,23 @@ async function waitForDeath(pid, budgetMs) {
807
933
  }
808
934
  return !isAlive(pid);
809
935
  }
936
+ async function waitForGroupDeath(pid, budgetMs) {
937
+ const deadline = Date.now() + budgetMs;
938
+ const groupAlive = () => {
939
+ try {
940
+ process.kill(-pid, 0);
941
+ return true;
942
+ } catch {
943
+ return false;
944
+ }
945
+ };
946
+ while (Date.now() < deadline) {
947
+ if (!groupAlive())
948
+ return true;
949
+ await sleep(POLL_INTERVAL_MS);
950
+ }
951
+ return !groupAlive();
952
+ }
810
953
 
811
954
  // src/cli.ts
812
955
  var USAGE = `space-bus — thin CLI for the managed OpenCode bus server
@@ -872,9 +1015,12 @@ function printJson(json, data, plain) {
872
1015
  `);
873
1016
  }
874
1017
  }
875
- async function runServe(args) {
1018
+ async function runServe(args, deps = {}) {
1019
+ const doEnsureServer = deps.ensureServer ?? ensureServer;
1020
+ const doStopServer = deps.stopServer ?? stopServer;
1021
+ const doSuperviseServer = deps.superviseServer ?? ((rosterPath2, handle2, shouldStop, interrupt) => superviseServer(rosterPath2, handle2, { shouldStop, interrupt }));
876
1022
  const rosterPath = resolveRoster(args.config);
877
- const handle = await ensureServer(rosterPath);
1023
+ const handle = await doEnsureServer(rosterPath);
878
1024
  const data = {
879
1025
  running: true,
880
1026
  port: handle.port,
@@ -885,17 +1031,45 @@ async function runServe(args) {
885
1031
  if (!args.foreground)
886
1032
  return 0;
887
1033
  return await new Promise((resolve) => {
888
- let stopping = false;
889
- const shutdown = (signal) => {
890
- if (stopping)
1034
+ let stopRequested = false;
1035
+ let wake = () => {};
1036
+ const interrupt = new Promise((r) => {
1037
+ wake = r;
1038
+ });
1039
+ const sigintHandler = () => onSignal("SIGINT");
1040
+ const sigtermHandler = () => onSignal("SIGTERM");
1041
+ const removeSignalHandlers = () => {
1042
+ process.off("SIGINT", sigintHandler);
1043
+ process.off("SIGTERM", sigtermHandler);
1044
+ };
1045
+ const onSignal = (signal) => {
1046
+ if (stopRequested)
891
1047
  return;
892
- stopping = true;
1048
+ stopRequested = true;
893
1049
  process.stderr.write(`space-bus: received ${signal}, stopping...
894
1050
  `);
895
- stopServer(rosterPath).finally(() => resolve(0));
1051
+ wake();
896
1052
  };
897
- process.on("SIGINT", () => shutdown("SIGINT"));
898
- process.on("SIGTERM", () => shutdown("SIGTERM"));
1053
+ process.on("SIGINT", sigintHandler);
1054
+ process.on("SIGTERM", sigtermHandler);
1055
+ doSuperviseServer(rosterPath, handle, () => stopRequested, interrupt).then((outcome) => {
1056
+ if (outcome.reason === "signal") {
1057
+ doStopServer(rosterPath).finally(() => {
1058
+ removeSignalHandlers();
1059
+ resolve(0);
1060
+ });
1061
+ return;
1062
+ }
1063
+ removeSignalHandlers();
1064
+ process.stderr.write(`space-bus: managed daemon ${outcome.reason}; exiting for supervisor restart
1065
+ `);
1066
+ resolve(1);
1067
+ }).catch((err) => {
1068
+ removeSignalHandlers();
1069
+ process.stderr.write(`space-bus: supervision failed unexpectedly: ${err.message}
1070
+ `);
1071
+ resolve(1);
1072
+ });
899
1073
  });
900
1074
  }
901
1075
  function runStatus(args) {
@@ -951,10 +1125,15 @@ async function main() {
951
1125
  return 1;
952
1126
  }
953
1127
  }
954
- main().then((code) => {
955
- process.exitCode = code;
956
- }).catch((err) => {
957
- process.stderr.write(`space-bus: ${err.message}
1128
+ if (__require.main == __require.module) {
1129
+ main().then((code) => {
1130
+ process.exitCode = code;
1131
+ }).catch((err) => {
1132
+ process.stderr.write(`space-bus: ${err.message}
958
1133
  `);
959
- process.exitCode = 1;
960
- });
1134
+ process.exitCode = 1;
1135
+ });
1136
+ }
1137
+ export {
1138
+ runServe
1139
+ };
package/dist/config.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
1
4
  // src/contract.ts
2
5
  import { z } from "zod";
3
6
  var sessionSchema = z.looseObject({
@@ -103,7 +106,7 @@ var managedSpawnConfigSchema = z.object({
103
106
  });
104
107
  var discoveryFileSchema = z.object({
105
108
  port: z.number().int().nonnegative(),
106
- pid: z.number().int().positive(),
109
+ pid: z.number().int().min(2),
107
110
  identity: z.string(),
108
111
  password: z.string(),
109
112
  spawnConfig: managedSpawnConfigSchema,
@@ -188,14 +191,27 @@ function removeDiscovery(rosterPath) {
188
191
  throw err;
189
192
  }
190
193
  }
194
+ function removeDiscoveryIfMatches(rosterPath, expected) {
195
+ try {
196
+ const current = readDiscovery(rosterPath);
197
+ if (current && current.pid === expected.pid && current.identity === expected.identity) {
198
+ removeDiscovery(rosterPath);
199
+ }
200
+ } catch {}
201
+ }
191
202
  function attachLive(rosterPath) {
192
203
  const discovery = readDiscovery(rosterPath);
193
204
  if (!discovery)
194
205
  return null;
195
206
  if (!loopbackOk(discovery.baseUrl))
196
207
  return null;
197
- if (!verifyIdentity(discovery.pid, discovery.identity))
208
+ if (!verifyIdentity(discovery.pid, discovery.identity)) {
209
+ removeDiscoveryIfMatches(rosterPath, {
210
+ pid: discovery.pid,
211
+ identity: discovery.identity
212
+ });
198
213
  return null;
214
+ }
199
215
  return {
200
216
  baseUrl: discovery.baseUrl,
201
217
  credentials: { username: "opencode", password: discovery.password },
@@ -230,7 +246,7 @@ function verifyIdentity(pid, storedIdentity) {
230
246
  return current !== null && current === storedIdentity;
231
247
  }
232
248
  var lockFileSchema = z2.object({
233
- pid: z2.number().int().positive(),
249
+ pid: z2.number().int().min(2),
234
250
  startTime: z2.string(),
235
251
  since: z2.number()
236
252
  });
@@ -326,7 +342,7 @@ function provisionalFilePath(rosterPath) {
326
342
  return join(stateDirFor(rosterPath), "spawn.provisional.json");
327
343
  }
328
344
  var provisionalFileSchema = z2.object({
329
- pid: z2.number().int().positive(),
345
+ pid: z2.number().int().min(2),
330
346
  identity: z2.string(),
331
347
  password: z2.string(),
332
348
  since: z2.number()
package/dist/contract.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
1
4
  // src/contract.ts
2
5
  import { z } from "zod";
3
6
  var sessionSchema = z.looseObject({
@@ -103,7 +106,7 @@ var managedSpawnConfigSchema = z.object({
103
106
  });
104
107
  var discoveryFileSchema = z.object({
105
108
  port: z.number().int().nonnegative(),
106
- pid: z.number().int().positive(),
109
+ pid: z.number().int().min(2),
107
110
  identity: z.string(),
108
111
  password: z.string(),
109
112
  spawnConfig: managedSpawnConfigSchema,
package/dist/core.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
1
4
  // src/contract.ts
2
5
  import { z } from "zod";
3
6
  var sessionSchema = z.looseObject({
@@ -103,7 +106,7 @@ var managedSpawnConfigSchema = z.object({
103
106
  });
104
107
  var discoveryFileSchema = z.object({
105
108
  port: z.number().int().nonnegative(),
106
- pid: z.number().int().positive(),
109
+ pid: z.number().int().min(2),
107
110
  identity: z.string(),
108
111
  password: z.string(),
109
112
  spawnConfig: managedSpawnConfigSchema,
@@ -22,6 +22,20 @@ export declare function writeDiscovery(rosterPath: string, data: DiscoveryFile):
22
22
  /** Reads and validates the discovery file; returns null if absent or corrupt. */
23
23
  export declare function readDiscovery(rosterPath: string): DiscoveryFile | null;
24
24
  export declare function removeDiscovery(rosterPath: string): void;
25
+ /**
26
+ * Compare-and-delete: re-reads the record and unlinks only if the on-disk
27
+ * pid+identity still match the ones passed in, so a fresh record written
28
+ * by a concurrent respawn is (practically) preserved. A vanishingly small
29
+ * window remains between the re-read and the unlink; a respawn's atomic
30
+ * rename landing in that window could still be removed — accepted as
31
+ * best-effort, consistent with the discovery layer's other best-effort
32
+ * operations, and self-heals (the orphaned daemon is reaped on the next
33
+ * ensure).
34
+ */
35
+ export declare function removeDiscoveryIfMatches(rosterPath: string, expected: {
36
+ pid: number;
37
+ identity: string;
38
+ }): void;
25
39
  export { loopbackOk };
26
40
  export interface LiveEndpoint {
27
41
  baseUrl: string;
package/dist/format.js CHANGED
@@ -1,3 +1,6 @@
1
+ import { createRequire } from "node:module";
2
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
+
1
4
  // src/format.ts
2
5
  function formatRoster(projects) {
3
6
  return projects.map((p) => {