@fro.bot/space-bus 0.10.1 → 0.12.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 +22 -0
- package/dist/attach.js +32 -1
- package/dist/cli.d.ts +14 -0
- package/dist/cli.js +797 -5
- package/dist/config.js +36 -3
- package/dist/contract.d.ts +15 -0
- package/dist/contract.js +34 -1
- package/dist/core.js +32 -1
- package/dist/discovery.d.ts +7 -0
- package/dist/index.js +42 -5
- package/dist/launchd.d.ts +108 -0
- package/dist/mcp.js +43 -6
- package/dist/registry-entry.d.ts +21 -0
- package/dist/registry-entry.js +1218 -0
- package/dist/registry.d.ts +57 -0
- package/dist/roster-edit.d.ts +62 -0
- package/dist/server.js +42 -5
- package/dist/service.d.ts +105 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -106,6 +106,28 @@ Security posture: each spawn gets a freshly generated password (never reused, ne
|
|
|
106
106
|
|
|
107
107
|
Programmatic consumers (e.g. Mothership) that want to drive the lifecycle directly without the CLI can import `@fro.bot/space-bus/managed-server` (Node-only; `ensureServer`/`serverStatus`/`stopServer`).
|
|
108
108
|
|
|
109
|
+
## `space-bus service` (macOS, launchd v1)
|
|
110
|
+
|
|
111
|
+
Reboot-persistent daemon on top of the managed server: registers a per-user launchd agent that wraps `serve --foreground`, so the roster's server survives host reboots and crashes without a live operator noticing it died.
|
|
112
|
+
|
|
113
|
+
```sh
|
|
114
|
+
space-bus service install [--json] [--config <path>] install the launchd agent, start it now
|
|
115
|
+
space-bus service uninstall [--json] [--config <path>] bootout the job and remove the plist
|
|
116
|
+
space-bus service status [--json] [--config <path>] installed / loaded / running, with pid
|
|
117
|
+
space-bus service stop [--json] [--config <path>] bootout the loaded job (plist stays)
|
|
118
|
+
space-bus service start [--json] [--config <path>] bootstrap + kickstart the job
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Semantics:
|
|
122
|
+
|
|
123
|
+
- Starts at **login**, not boot — it's a `gui/$UID` launchd agent, not a system daemon.
|
|
124
|
+
- Restarts only on abnormal exit (`KeepAlive.SuccessfulExit=false`), consuming the existing `serve --foreground` exit-code contract (0 = deliberate stop, no restart; 1 = death, restart). Restarts are throttled to once per 10s to avoid a crash loop.
|
|
125
|
+
- `service stop` deregisters the job (`bootout`) but leaves the plist in place; `service start` re-registers it (`bootstrap` + `kickstart`). A stopped service comes back automatically at the next login (`RunAtLoad`) unless you `service start` it back sooner — there's no persistent "disabled" latch in v1.
|
|
126
|
+
- Logs land at the roster's state dir: `service.log` (stdout) / `service.err.log` (stderr), created 0600.
|
|
127
|
+
- Upgrades: the plist pins absolute paths to the runtime and CLI entry resolved at install time. After a version bump (or if you moved/reinstalled the runtime), re-run `space-bus service install` — it's idempotent and refreshes the pinned paths.
|
|
128
|
+
- macOS only in v1; every verb fails fast with an explicit error on other platforms.
|
|
129
|
+
- `install`/`uninstall` are explicit operator actions only — nothing auto-installs the service on your behalf.
|
|
130
|
+
|
|
109
131
|
## Library surface
|
|
110
132
|
|
|
111
133
|
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.
|
package/dist/attach.js
CHANGED
|
@@ -118,13 +118,44 @@ var managedSpawnConfigSchema = z.object({
|
|
|
118
118
|
cwd: z.string().optional(),
|
|
119
119
|
port: z.number().int().nonnegative().optional()
|
|
120
120
|
});
|
|
121
|
+
var registryEntrySchema = z.object({
|
|
122
|
+
name: z.string().regex(/^[a-z0-9-]{1,64}$/, "roster name must be 1-64 lowercase letters, digits, or hyphens"),
|
|
123
|
+
path: z.string().min(1, "roster path must not be empty")
|
|
124
|
+
});
|
|
125
|
+
var registryFileSchema = z.object({
|
|
126
|
+
version: z.literal(1),
|
|
127
|
+
default: z.string().optional(),
|
|
128
|
+
rosters: z.array(registryEntrySchema)
|
|
129
|
+
}).superRefine((val, ctx) => {
|
|
130
|
+
const seen = new Set;
|
|
131
|
+
for (const entry of val.rosters) {
|
|
132
|
+
const key = entry.name.toLowerCase();
|
|
133
|
+
if (seen.has(key)) {
|
|
134
|
+
ctx.addIssue({
|
|
135
|
+
code: "custom",
|
|
136
|
+
message: `space-bus: duplicate roster name "${entry.name}" (case-insensitive) in registry`
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
seen.add(key);
|
|
140
|
+
}
|
|
141
|
+
if (val.default !== undefined) {
|
|
142
|
+
const matches = val.rosters.filter((entry) => entry.name === val.default);
|
|
143
|
+
if (matches.length !== 1) {
|
|
144
|
+
ctx.addIssue({
|
|
145
|
+
code: "custom",
|
|
146
|
+
message: `space-bus: registry's default "${val.default}" must match exactly one roster entry's name (matched ${matches.length})`
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
121
151
|
var discoveryFileSchema = z.object({
|
|
122
152
|
port: z.number().int().nonnegative(),
|
|
123
153
|
pid: z.number().int().min(2),
|
|
124
154
|
identity: z.string(),
|
|
125
155
|
password: z.string(),
|
|
126
156
|
spawnConfig: managedSpawnConfigSchema,
|
|
127
|
-
baseUrl: z.url()
|
|
157
|
+
baseUrl: z.url(),
|
|
158
|
+
rosterPath: z.string().optional()
|
|
128
159
|
});
|
|
129
160
|
|
|
130
161
|
// src/attach.ts
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ensureServer, type ServerHandle, type SuperviseOutcome, stopServer } from "./server";
|
|
2
|
+
import { installService, serviceStatus, startService, stopService, uninstallService } from "./service";
|
|
2
3
|
interface ParsedArgs {
|
|
3
4
|
command: string | undefined;
|
|
5
|
+
/** Second positional arg — only meaningful when command === "service". */
|
|
6
|
+
subcommand?: string | undefined;
|
|
4
7
|
json: boolean;
|
|
5
8
|
foreground: boolean;
|
|
6
9
|
config: string | undefined;
|
|
@@ -23,4 +26,15 @@ export interface RunServeDeps {
|
|
|
23
26
|
superviseServer?: (rosterPath: string, handle: ServerHandle, shouldStop: () => boolean, interrupt: Promise<void>) => Promise<SuperviseOutcome>;
|
|
24
27
|
}
|
|
25
28
|
export declare function runServe(args: ParsedArgs, deps?: RunServeDeps): Promise<number>;
|
|
29
|
+
/** Injectable dependencies for `runService` — lets tests swap in fake
|
|
30
|
+
* verb implementations so they never touch the real launchd / LaunchAgents
|
|
31
|
+
* directory. Defaults to the real implementations from service.ts. */
|
|
32
|
+
export interface RunServiceDeps {
|
|
33
|
+
installService?: typeof installService;
|
|
34
|
+
uninstallService?: typeof uninstallService;
|
|
35
|
+
serviceStatus?: typeof serviceStatus;
|
|
36
|
+
stopService?: typeof stopService;
|
|
37
|
+
startService?: typeof startService;
|
|
38
|
+
}
|
|
39
|
+
export declare function runService(args: ParsedArgs, deps?: RunServiceDeps): Promise<number>;
|
|
26
40
|
export {};
|