@fro.bot/space-bus 0.5.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Per-roster state directory: `$XDG_STATE_HOME|~/.local/state`/
4
+ * `space-bus/<first 16 hex of sha256(absolute roster path)>/`. Keying by a
5
+ * hash of the roster path keeps concurrent workspaces from colliding
6
+ * without leaking the roster path itself into the filesystem layout.
7
+ */
8
+ export declare function stateDirFor(rosterPath: string): string;
9
+ export declare function discoveryFilePath(rosterPath: string): string;
10
+ export declare function lockFilePath(rosterPath: string): string;
11
+ export declare function logFilePath(rosterPath: string): string;
12
+ export declare const managedSpawnConfigSchema: z.ZodObject<{
13
+ command: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
+ cwd: z.ZodOptional<z.ZodString>;
15
+ port: z.ZodOptional<z.ZodNumber>;
16
+ }, z.core.$strip>;
17
+ export declare const discoveryFileSchema: z.ZodObject<{
18
+ port: z.ZodNumber;
19
+ pid: z.ZodNumber;
20
+ identity: z.ZodString;
21
+ password: z.ZodString;
22
+ spawnConfig: z.ZodObject<{
23
+ command: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
+ cwd: z.ZodOptional<z.ZodString>;
25
+ port: z.ZodOptional<z.ZodNumber>;
26
+ }, z.core.$strip>;
27
+ baseUrl: z.ZodURL;
28
+ }, z.core.$strip>;
29
+ export type DiscoveryFile = z.infer<typeof discoveryFileSchema>;
30
+ /**
31
+ * Writes the discovery file atomically: a temp file (0600) in the same
32
+ * directory, then rename over the target (rename is atomic within a
33
+ * filesystem). The state dir itself is created 0700. Mirrors the
34
+ * temp+rename+chmod mechanics used for copilot-delegate's port/pid files.
35
+ */
36
+ export declare function writeDiscovery(rosterPath: string, data: DiscoveryFile): void;
37
+ /** Reads and validates the discovery file; returns null if absent or corrupt. */
38
+ export declare function readDiscovery(rosterPath: string): DiscoveryFile | null;
39
+ export declare function removeDiscovery(rosterPath: string): void;
40
+ export declare function loopbackOk(baseUrl: string): boolean;
41
+ export interface LiveEndpoint {
42
+ baseUrl: string;
43
+ credentials: {
44
+ username?: string;
45
+ password?: string;
46
+ };
47
+ pid: number;
48
+ port: number;
49
+ }
50
+ /**
51
+ * Attach-only: reads the discovery file, verifies the recorded pid is alive
52
+ * with a matching identity, and that the discovered baseUrl passes the
53
+ * loopback guard. Never spawns. Lives here (not server.ts) so `config.ts`
54
+ * can attach to a managed roster without importing `server.ts` — server.ts
55
+ * already imports config.ts (for manifestSchema), so config->server would
56
+ * be a cycle. `config.ts` and `server.ts` both import this instead.
57
+ */
58
+ export declare function attachLive(rosterPath: string): LiveEndpoint | null;
59
+ /**
60
+ * Captures a locale-pinned `lstart,comm` identity string for a pid, used to
61
+ * distinguish a live process from a recycled pid reusing the same number.
62
+ * Best-effort within the same-user trust boundary: `lstart` is
63
+ * second-granularity, so a pid recycled by a different process within the
64
+ * same second and matching `comm` could in principle collide — not a
65
+ * "never" guarantee, just a strong practical deterrent. Returns null if
66
+ * the process cannot be inspected (e.g. already exited, or on a platform
67
+ * without `ps`).
68
+ */
69
+ export declare function captureIdentity(pid: number): string | null;
70
+ /** True if a process with the given pid currently exists (signal 0 probe). */
71
+ export declare function isAlive(pid: number): boolean;
72
+ /**
73
+ * A pid is verified only if it is BOTH alive and its captured identity
74
+ * matches the stored one — a recycled pid (alive, different start
75
+ * time/command) fails this check in practice. Best-effort, not a formal
76
+ * guarantee: `lstart` is second-granularity, so a pid recycled within the
77
+ * same second by a process sharing `comm` could theoretically pass. This
78
+ * is acceptable within the documented same-user trust boundary.
79
+ */
80
+ export declare function verifyIdentity(pid: number, storedIdentity: string): boolean;
81
+ export declare const lockFileSchema: z.ZodObject<{
82
+ pid: z.ZodNumber;
83
+ startTime: z.ZodString;
84
+ since: z.ZodNumber;
85
+ }, z.core.$strip>;
86
+ export type LockFile = z.infer<typeof lockFileSchema>;
87
+ export interface LockHandle {
88
+ rosterPath: string;
89
+ }
90
+ /**
91
+ * Acquires the per-roster spawn lock via O_EXCL create. Arbitration: a
92
+ * lock is stale ONLY when its owner is dead (identity-checked) — age never
93
+ * preempts a live owner. Returns a handle on success, or null if the lock
94
+ * is currently held by a verified-live owner.
95
+ */
96
+ export declare function acquireLock(rosterPath: string): LockHandle | null;
97
+ /**
98
+ * Releases the spawn lock. Swallows ALL unlink errors (not just ENOENT) —
99
+ * this typically runs in a `finally` after spawning/readiness work, and a
100
+ * failure here (e.g. permissions, race with an external cleanup) must
101
+ * never replace or mask a primary error already in flight.
102
+ */
103
+ export declare function releaseLock(handle: LockHandle): void;
104
+ /** Reads the current lock holder, or null if no lock file / it's corrupt. */
105
+ export declare function readLockFile(target: string): LockFile | null;
106
+ export declare function closeQuietly(fd: number): void;
107
+ export declare function provisionalFilePath(rosterPath: string): string;
108
+ export declare const provisionalFileSchema: z.ZodObject<{
109
+ pid: z.ZodNumber;
110
+ identity: z.ZodString;
111
+ password: z.ZodString;
112
+ since: z.ZodNumber;
113
+ }, z.core.$strip>;
114
+ export type ProvisionalFile = z.infer<typeof provisionalFileSchema>;
115
+ export declare function writeProvisional(rosterPath: string, data: ProvisionalFile): void;
116
+ /** Reads the provisional spawn record, or null if absent/corrupt. */
117
+ export declare function readProvisional(rosterPath: string): ProvisionalFile | null;
118
+ /**
119
+ * Removes the provisional spawn record. Swallows ALL unlink errors (not
120
+ * just ENOENT) — this runs in `spawnAndWaitReady`'s `finally`, after a
121
+ * readiness/spawn error may already be in flight, and a cleanup failure
122
+ * here (e.g. permissions, a race with external cleanup) must never replace
123
+ * or mask that primary error. Mirrors `releaseLock`'s swallow-all
124
+ * best-effort semantics.
125
+ */
126
+ export declare function removeProvisional(rosterPath: string): void;