@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/dist/config.js
CHANGED
|
@@ -127,13 +127,44 @@ var managedSpawnConfigSchema = z.object({
|
|
|
127
127
|
cwd: z.string().optional(),
|
|
128
128
|
port: z.number().int().nonnegative().optional()
|
|
129
129
|
});
|
|
130
|
+
var registryEntrySchema = z.object({
|
|
131
|
+
name: z.string().regex(/^[a-z0-9-]{1,64}$/, "roster name must be 1-64 lowercase letters, digits, or hyphens"),
|
|
132
|
+
path: z.string().min(1, "roster path must not be empty")
|
|
133
|
+
});
|
|
134
|
+
var registryFileSchema = z.object({
|
|
135
|
+
version: z.literal(1),
|
|
136
|
+
default: z.string().optional(),
|
|
137
|
+
rosters: z.array(registryEntrySchema)
|
|
138
|
+
}).superRefine((val, ctx) => {
|
|
139
|
+
const seen = new Set;
|
|
140
|
+
for (const entry of val.rosters) {
|
|
141
|
+
const key = entry.name.toLowerCase();
|
|
142
|
+
if (seen.has(key)) {
|
|
143
|
+
ctx.addIssue({
|
|
144
|
+
code: "custom",
|
|
145
|
+
message: `space-bus: duplicate roster name "${entry.name}" (case-insensitive) in registry`
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
seen.add(key);
|
|
149
|
+
}
|
|
150
|
+
if (val.default !== undefined) {
|
|
151
|
+
const matches = val.rosters.filter((entry) => entry.name === val.default);
|
|
152
|
+
if (matches.length !== 1) {
|
|
153
|
+
ctx.addIssue({
|
|
154
|
+
code: "custom",
|
|
155
|
+
message: `space-bus: registry's default "${val.default}" must match exactly one roster entry's name (matched ${matches.length})`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
130
160
|
var discoveryFileSchema = z.object({
|
|
131
161
|
port: z.number().int().nonnegative(),
|
|
132
162
|
pid: z.number().int().min(2),
|
|
133
163
|
identity: z.string(),
|
|
134
164
|
password: z.string(),
|
|
135
165
|
spawnConfig: managedSpawnConfigSchema,
|
|
136
|
-
baseUrl: z.url()
|
|
166
|
+
baseUrl: z.url(),
|
|
167
|
+
rosterPath: z.string().optional()
|
|
137
168
|
});
|
|
138
169
|
|
|
139
170
|
// src/discovery.ts
|
|
@@ -154,10 +185,12 @@ import {
|
|
|
154
185
|
import { homedir } from "node:os";
|
|
155
186
|
import { join } from "node:path";
|
|
156
187
|
import { z as z2 } from "zod";
|
|
188
|
+
function rosterKey(rosterPath) {
|
|
189
|
+
return createHash("sha256").update(rosterPath).digest("hex").slice(0, 16);
|
|
190
|
+
}
|
|
157
191
|
function stateDirFor(rosterPath) {
|
|
158
192
|
const base = process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state");
|
|
159
|
-
|
|
160
|
-
return join(base, "space-bus", hash);
|
|
193
|
+
return join(base, "space-bus", rosterKey(rosterPath));
|
|
161
194
|
}
|
|
162
195
|
function discoveryFilePath(rosterPath) {
|
|
163
196
|
return join(stateDirFor(rosterPath), "discovery.json");
|
package/dist/contract.d.ts
CHANGED
|
@@ -250,6 +250,20 @@ export declare const managedSpawnConfigSchema: z.ZodObject<{
|
|
|
250
250
|
cwd: z.ZodOptional<z.ZodString>;
|
|
251
251
|
port: z.ZodOptional<z.ZodNumber>;
|
|
252
252
|
}, z.core.$strip>;
|
|
253
|
+
export declare const registryEntrySchema: z.ZodObject<{
|
|
254
|
+
name: z.ZodString;
|
|
255
|
+
path: z.ZodString;
|
|
256
|
+
}, z.core.$strip>;
|
|
257
|
+
export type RegistryEntry = z.infer<typeof registryEntrySchema>;
|
|
258
|
+
export declare const registryFileSchema: z.ZodObject<{
|
|
259
|
+
version: z.ZodLiteral<1>;
|
|
260
|
+
default: z.ZodOptional<z.ZodString>;
|
|
261
|
+
rosters: z.ZodArray<z.ZodObject<{
|
|
262
|
+
name: z.ZodString;
|
|
263
|
+
path: z.ZodString;
|
|
264
|
+
}, z.core.$strip>>;
|
|
265
|
+
}, z.core.$strip>;
|
|
266
|
+
export type RegistryFile = z.infer<typeof registryFileSchema>;
|
|
253
267
|
export declare const discoveryFileSchema: z.ZodObject<{
|
|
254
268
|
port: z.ZodNumber;
|
|
255
269
|
pid: z.ZodNumber;
|
|
@@ -261,4 +275,5 @@ export declare const discoveryFileSchema: z.ZodObject<{
|
|
|
261
275
|
port: z.ZodOptional<z.ZodNumber>;
|
|
262
276
|
}, z.core.$strip>;
|
|
263
277
|
baseUrl: z.ZodURL;
|
|
278
|
+
rosterPath: z.ZodOptional<z.ZodString>;
|
|
264
279
|
}, z.core.$strip>;
|
package/dist/contract.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
|
export {
|
|
130
161
|
vcsStatusSchema,
|
|
@@ -140,6 +171,8 @@ export {
|
|
|
140
171
|
sessionSchema,
|
|
141
172
|
sessionListSchema,
|
|
142
173
|
rosterSchema,
|
|
174
|
+
registryFileSchema,
|
|
175
|
+
registryEntrySchema,
|
|
143
176
|
questionListSchema,
|
|
144
177
|
questionEntrySchema,
|
|
145
178
|
projectSchema,
|
package/dist/core.js
CHANGED
|
@@ -111,13 +111,44 @@ var managedSpawnConfigSchema = z.object({
|
|
|
111
111
|
cwd: z.string().optional(),
|
|
112
112
|
port: z.number().int().nonnegative().optional()
|
|
113
113
|
});
|
|
114
|
+
var registryEntrySchema = z.object({
|
|
115
|
+
name: z.string().regex(/^[a-z0-9-]{1,64}$/, "roster name must be 1-64 lowercase letters, digits, or hyphens"),
|
|
116
|
+
path: z.string().min(1, "roster path must not be empty")
|
|
117
|
+
});
|
|
118
|
+
var registryFileSchema = z.object({
|
|
119
|
+
version: z.literal(1),
|
|
120
|
+
default: z.string().optional(),
|
|
121
|
+
rosters: z.array(registryEntrySchema)
|
|
122
|
+
}).superRefine((val, ctx) => {
|
|
123
|
+
const seen = new Set;
|
|
124
|
+
for (const entry of val.rosters) {
|
|
125
|
+
const key = entry.name.toLowerCase();
|
|
126
|
+
if (seen.has(key)) {
|
|
127
|
+
ctx.addIssue({
|
|
128
|
+
code: "custom",
|
|
129
|
+
message: `space-bus: duplicate roster name "${entry.name}" (case-insensitive) in registry`
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
seen.add(key);
|
|
133
|
+
}
|
|
134
|
+
if (val.default !== undefined) {
|
|
135
|
+
const matches = val.rosters.filter((entry) => entry.name === val.default);
|
|
136
|
+
if (matches.length !== 1) {
|
|
137
|
+
ctx.addIssue({
|
|
138
|
+
code: "custom",
|
|
139
|
+
message: `space-bus: registry's default "${val.default}" must match exactly one roster entry's name (matched ${matches.length})`
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
114
144
|
var discoveryFileSchema = z.object({
|
|
115
145
|
port: z.number().int().nonnegative(),
|
|
116
146
|
pid: z.number().int().min(2),
|
|
117
147
|
identity: z.string(),
|
|
118
148
|
password: z.string(),
|
|
119
149
|
spawnConfig: managedSpawnConfigSchema,
|
|
120
|
-
baseUrl: z.url()
|
|
150
|
+
baseUrl: z.url(),
|
|
151
|
+
rosterPath: z.string().optional()
|
|
121
152
|
});
|
|
122
153
|
|
|
123
154
|
// src/core.ts
|
package/dist/discovery.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { discoveryFileSchema, loopbackOk, managedSpawnConfigSchema } from "./contract";
|
|
3
3
|
export { discoveryFileSchema, managedSpawnConfigSchema };
|
|
4
|
+
/**
|
|
5
|
+
* First 16 hex chars of sha256(roster path) — the shared per-roster
|
|
6
|
+
* identity key used by both `stateDirFor` (filesystem layout) and
|
|
7
|
+
* `launchd.ts`'s `serviceLabel` (launchd label/plist filename), so the two
|
|
8
|
+
* stay in lockstep without duplicating the hash derivation.
|
|
9
|
+
*/
|
|
10
|
+
export declare function rosterKey(rosterPath: string): string;
|
|
4
11
|
/**
|
|
5
12
|
* Per-roster state directory: `$XDG_STATE_HOME|~/.local/state`/
|
|
6
13
|
* `space-bus/<first 16 hex of sha256(absolute roster path)>/`. Keying by a
|
package/dist/index.js
CHANGED
|
@@ -127,13 +127,44 @@ var managedSpawnConfigSchema = z.object({
|
|
|
127
127
|
cwd: z.string().optional(),
|
|
128
128
|
port: z.number().int().nonnegative().optional()
|
|
129
129
|
});
|
|
130
|
+
var registryEntrySchema = z.object({
|
|
131
|
+
name: z.string().regex(/^[a-z0-9-]{1,64}$/, "roster name must be 1-64 lowercase letters, digits, or hyphens"),
|
|
132
|
+
path: z.string().min(1, "roster path must not be empty")
|
|
133
|
+
});
|
|
134
|
+
var registryFileSchema = z.object({
|
|
135
|
+
version: z.literal(1),
|
|
136
|
+
default: z.string().optional(),
|
|
137
|
+
rosters: z.array(registryEntrySchema)
|
|
138
|
+
}).superRefine((val, ctx) => {
|
|
139
|
+
const seen = new Set;
|
|
140
|
+
for (const entry of val.rosters) {
|
|
141
|
+
const key = entry.name.toLowerCase();
|
|
142
|
+
if (seen.has(key)) {
|
|
143
|
+
ctx.addIssue({
|
|
144
|
+
code: "custom",
|
|
145
|
+
message: `space-bus: duplicate roster name "${entry.name}" (case-insensitive) in registry`
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
seen.add(key);
|
|
149
|
+
}
|
|
150
|
+
if (val.default !== undefined) {
|
|
151
|
+
const matches = val.rosters.filter((entry) => entry.name === val.default);
|
|
152
|
+
if (matches.length !== 1) {
|
|
153
|
+
ctx.addIssue({
|
|
154
|
+
code: "custom",
|
|
155
|
+
message: `space-bus: registry's default "${val.default}" must match exactly one roster entry's name (matched ${matches.length})`
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
});
|
|
130
160
|
var discoveryFileSchema = z.object({
|
|
131
161
|
port: z.number().int().nonnegative(),
|
|
132
162
|
pid: z.number().int().min(2),
|
|
133
163
|
identity: z.string(),
|
|
134
164
|
password: z.string(),
|
|
135
165
|
spawnConfig: managedSpawnConfigSchema,
|
|
136
|
-
baseUrl: z.url()
|
|
166
|
+
baseUrl: z.url(),
|
|
167
|
+
rosterPath: z.string().optional()
|
|
137
168
|
});
|
|
138
169
|
|
|
139
170
|
// src/discovery.ts
|
|
@@ -154,10 +185,12 @@ import {
|
|
|
154
185
|
import { homedir } from "node:os";
|
|
155
186
|
import { join } from "node:path";
|
|
156
187
|
import { z as z2 } from "zod";
|
|
188
|
+
function rosterKey(rosterPath) {
|
|
189
|
+
return createHash("sha256").update(rosterPath).digest("hex").slice(0, 16);
|
|
190
|
+
}
|
|
157
191
|
function stateDirFor(rosterPath) {
|
|
158
192
|
const base = process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state");
|
|
159
|
-
|
|
160
|
-
return join(base, "space-bus", hash);
|
|
193
|
+
return join(base, "space-bus", rosterKey(rosterPath));
|
|
161
194
|
}
|
|
162
195
|
function discoveryFilePath(rosterPath) {
|
|
163
196
|
return join(stateDirFor(rosterPath), "discovery.json");
|
|
@@ -520,7 +553,7 @@ function isManagedRoster(directory) {
|
|
|
520
553
|
// src/server.ts
|
|
521
554
|
import { spawn } from "node:child_process";
|
|
522
555
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
523
|
-
import { openSync as openSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
556
|
+
import { existsSync as existsSync2, openSync as openSync2, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
524
557
|
import { dirname } from "node:path";
|
|
525
558
|
var DEFAULT_READINESS_BUDGET_MS = 15000;
|
|
526
559
|
var DEFAULT_LOCK_WAIT_BUDGET_MS = 15000;
|
|
@@ -774,7 +807,8 @@ async function spawnAndWaitReady(rosterPath, managedConfig, readinessBudgetMs) {
|
|
|
774
807
|
identity: finalIdentity,
|
|
775
808
|
password,
|
|
776
809
|
spawnConfig: { command, cwd, port: requestedPort },
|
|
777
|
-
baseUrl
|
|
810
|
+
baseUrl,
|
|
811
|
+
rosterPath
|
|
778
812
|
});
|
|
779
813
|
return {
|
|
780
814
|
baseUrl,
|
|
@@ -784,6 +818,9 @@ async function spawnAndWaitReady(rosterPath, managedConfig, readinessBudgetMs) {
|
|
|
784
818
|
};
|
|
785
819
|
}
|
|
786
820
|
async function ensureServer(rosterPath, options = {}) {
|
|
821
|
+
if (existsSync2(rosterPath)) {
|
|
822
|
+
rosterPath = realpathSync2(rosterPath);
|
|
823
|
+
}
|
|
787
824
|
const readinessBudgetMs = options.readinessBudgetMs ?? DEFAULT_READINESS_BUDGET_MS;
|
|
788
825
|
const lockWaitBudgetMs = options.lockWaitBudgetMs ?? DEFAULT_LOCK_WAIT_BUDGET_MS;
|
|
789
826
|
const fastPath = attachServer(rosterPath);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** `bot.fro.space-bus.<rosterKey>` — one label per roster identity (R7). */
|
|
2
|
+
export declare function serviceLabel(rosterPath: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* `<baseDir>/<label>.plist`. Defaults to `~/Library/LaunchAgents` when
|
|
5
|
+
* `baseDir` is omitted — tests MUST pass an injected temp directory so
|
|
6
|
+
* writes never land in the operator's real LaunchAgents folder.
|
|
7
|
+
*/
|
|
8
|
+
export declare function plistPath(label: string, baseDir?: string): string;
|
|
9
|
+
export interface RenderPlistOpts {
|
|
10
|
+
runtime: string;
|
|
11
|
+
cliEntry: string;
|
|
12
|
+
rosterPath: string;
|
|
13
|
+
stateDir: string;
|
|
14
|
+
label: string;
|
|
15
|
+
/**
|
|
16
|
+
* Absolute `PATH` to pin into the launched process's sparse launchd
|
|
17
|
+
* environment. launchd agents don't inherit the login shell's PATH, so
|
|
18
|
+
* without this a mise/asdf-shim-resolved `runtime`/`cliEntry` absolute
|
|
19
|
+
* path is fine, but any subprocess *it* shells out to (or a future
|
|
20
|
+
* change resolving a bare command name) would silently resolve
|
|
21
|
+
* differently than at install time. Optional — omitted entirely from
|
|
22
|
+
* the plist when not supplied, since not every caller can safely derive
|
|
23
|
+
* a sane absolute PATH (tests, callers targeting an older contract).
|
|
24
|
+
*/
|
|
25
|
+
path?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Absolute `XDG_STATE_HOME` to pin into the launched environment when
|
|
28
|
+
* the installer resolved `stateDir` using an `XDG_STATE_HOME` override.
|
|
29
|
+
* Without this, `stateDirFor` inside the launchd-launched process (which
|
|
30
|
+
* runs under launchd's own sparse env, NOT the installer's shell env)
|
|
31
|
+
* falls back to `~/.local/state`, diverging from the installer's view of
|
|
32
|
+
* `stateDir` — the exact split this option exists to prevent. Caller
|
|
33
|
+
* (installService) is responsible for validating this is absolute
|
|
34
|
+
* before passing it in.
|
|
35
|
+
*/
|
|
36
|
+
xdgStateHome?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Renders the launchd agent plist XML for a roster. Pins absolute
|
|
40
|
+
* ProgramArguments (`[runtime, cliEntry, "serve", "--foreground"]`),
|
|
41
|
+
* restarts only on abnormal exit (`KeepAlive.SuccessfulExit=false`,
|
|
42
|
+
* consuming the existing 0/1 exit contract — R6), throttles restarts
|
|
43
|
+
* (R8), and routes stdout/stderr into the roster's state dir (R10). The
|
|
44
|
+
* environment carries `SPACE_BUS_CONFIG` plus, when supplied, `PATH` and
|
|
45
|
+
* `XDG_STATE_HOME` — never credentials (R12). All interpolated strings
|
|
46
|
+
* are XML-escaped.
|
|
47
|
+
*/
|
|
48
|
+
export declare function renderPlist(opts: RenderPlistOpts): string;
|
|
49
|
+
export type WriteResult = {
|
|
50
|
+
ok: true;
|
|
51
|
+
} | {
|
|
52
|
+
ok: false;
|
|
53
|
+
error: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Writes the plist atomically: a temp file (0644, since launchd — not just
|
|
57
|
+
* the owner — must be able to read it) in the same directory as the
|
|
58
|
+
* target, then rename over it. Mirrors `writeDiscovery`'s temp+rename
|
|
59
|
+
* pattern; final mode is 0644 (owner read/write, group/world read-only —
|
|
60
|
+
* never writable, per R15).
|
|
61
|
+
*/
|
|
62
|
+
export declare function writePlistAtomic(path: string, content: string): WriteResult;
|
|
63
|
+
export type PlistSafety = {
|
|
64
|
+
safe: true;
|
|
65
|
+
} | {
|
|
66
|
+
safe: false;
|
|
67
|
+
reason: string;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Refuses a plist that isn't owned by the current user or is
|
|
71
|
+
* group/world-writable — a tampered plist must never become login-time
|
|
72
|
+
* code execution (R15).
|
|
73
|
+
*/
|
|
74
|
+
export declare function verifyPlistSafe(path: string): PlistSafety;
|
|
75
|
+
export interface ExecResult {
|
|
76
|
+
code: number;
|
|
77
|
+
stdout: string;
|
|
78
|
+
stderr: string;
|
|
79
|
+
}
|
|
80
|
+
export type ExecSeam = (args: string[]) => Promise<ExecResult>;
|
|
81
|
+
/** Default `ExecSeam`: spawns the real `launchctl` binary. Never rejects —
|
|
82
|
+
* a spawn error or a timeout both resolve a `{code:-1,...}` ExecResult with
|
|
83
|
+
* an actionable stderr, so callers' no-throw-across-the-boundary contract
|
|
84
|
+
* holds even when the exec primitive itself misbehaves. */
|
|
85
|
+
export declare const defaultLaunchctl: ExecSeam;
|
|
86
|
+
export declare function bootstrap(uid: number, plist: string, exec: ExecSeam): Promise<ExecResult>;
|
|
87
|
+
export declare function bootout(uid: number, label: string, exec: ExecSeam): Promise<ExecResult>;
|
|
88
|
+
export declare function kickstart(uid: number, label: string, exec: ExecSeam): Promise<ExecResult>;
|
|
89
|
+
export type PrintJobResult = {
|
|
90
|
+
ok: true;
|
|
91
|
+
loaded: boolean;
|
|
92
|
+
pid?: number;
|
|
93
|
+
} | {
|
|
94
|
+
ok: false;
|
|
95
|
+
error: string;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Probes a launchd job by label. A zero exit is authoritative "loaded";
|
|
99
|
+
* a permissive `pid = (\d+)` match against stdout is best-effort only —
|
|
100
|
+
* an unparsable but zero-exit response is still `loaded: true` with
|
|
101
|
+
* `pid: undefined`, since `print`'s exact line format drifts across macOS
|
|
102
|
+
* versions. A non-zero exit is `loaded: false` ONLY when launchd's own
|
|
103
|
+
* "job not found" wording is present in the combined output; any other
|
|
104
|
+
* non-zero exit (permission denied, IO error, our own timeout/spawn-error
|
|
105
|
+
* synthetic result) is reported as `ok:false` so callers can fail honestly
|
|
106
|
+
* instead of silently treating a probe failure as "not loaded".
|
|
107
|
+
*/
|
|
108
|
+
export declare function printJob(uid: number, label: string, exec: ExecSeam): Promise<PrintJobResult>;
|
package/dist/mcp.js
CHANGED
|
@@ -128,13 +128,44 @@ var managedSpawnConfigSchema = z.object({
|
|
|
128
128
|
cwd: z.string().optional(),
|
|
129
129
|
port: z.number().int().nonnegative().optional()
|
|
130
130
|
});
|
|
131
|
+
var registryEntrySchema = z.object({
|
|
132
|
+
name: z.string().regex(/^[a-z0-9-]{1,64}$/, "roster name must be 1-64 lowercase letters, digits, or hyphens"),
|
|
133
|
+
path: z.string().min(1, "roster path must not be empty")
|
|
134
|
+
});
|
|
135
|
+
var registryFileSchema = z.object({
|
|
136
|
+
version: z.literal(1),
|
|
137
|
+
default: z.string().optional(),
|
|
138
|
+
rosters: z.array(registryEntrySchema)
|
|
139
|
+
}).superRefine((val, ctx) => {
|
|
140
|
+
const seen = new Set;
|
|
141
|
+
for (const entry of val.rosters) {
|
|
142
|
+
const key = entry.name.toLowerCase();
|
|
143
|
+
if (seen.has(key)) {
|
|
144
|
+
ctx.addIssue({
|
|
145
|
+
code: "custom",
|
|
146
|
+
message: `space-bus: duplicate roster name "${entry.name}" (case-insensitive) in registry`
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
seen.add(key);
|
|
150
|
+
}
|
|
151
|
+
if (val.default !== undefined) {
|
|
152
|
+
const matches = val.rosters.filter((entry) => entry.name === val.default);
|
|
153
|
+
if (matches.length !== 1) {
|
|
154
|
+
ctx.addIssue({
|
|
155
|
+
code: "custom",
|
|
156
|
+
message: `space-bus: registry's default "${val.default}" must match exactly one roster entry's name (matched ${matches.length})`
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
});
|
|
131
161
|
var discoveryFileSchema = z.object({
|
|
132
162
|
port: z.number().int().nonnegative(),
|
|
133
163
|
pid: z.number().int().min(2),
|
|
134
164
|
identity: z.string(),
|
|
135
165
|
password: z.string(),
|
|
136
166
|
spawnConfig: managedSpawnConfigSchema,
|
|
137
|
-
baseUrl: z.url()
|
|
167
|
+
baseUrl: z.url(),
|
|
168
|
+
rosterPath: z.string().optional()
|
|
138
169
|
});
|
|
139
170
|
|
|
140
171
|
// src/discovery.ts
|
|
@@ -155,10 +186,12 @@ import {
|
|
|
155
186
|
import { homedir } from "node:os";
|
|
156
187
|
import { join } from "node:path";
|
|
157
188
|
import { z as z2 } from "zod";
|
|
189
|
+
function rosterKey(rosterPath) {
|
|
190
|
+
return createHash("sha256").update(rosterPath).digest("hex").slice(0, 16);
|
|
191
|
+
}
|
|
158
192
|
function stateDirFor(rosterPath) {
|
|
159
193
|
const base = process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state");
|
|
160
|
-
|
|
161
|
-
return join(base, "space-bus", hash);
|
|
194
|
+
return join(base, "space-bus", rosterKey(rosterPath));
|
|
162
195
|
}
|
|
163
196
|
function discoveryFilePath(rosterPath) {
|
|
164
197
|
return join(stateDirFor(rosterPath), "discovery.json");
|
|
@@ -521,7 +554,7 @@ function isManagedRoster(directory) {
|
|
|
521
554
|
// src/server.ts
|
|
522
555
|
import { spawn } from "node:child_process";
|
|
523
556
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
524
|
-
import { openSync as openSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
557
|
+
import { existsSync as existsSync2, openSync as openSync2, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
525
558
|
import { dirname } from "node:path";
|
|
526
559
|
var DEFAULT_READINESS_BUDGET_MS = 15000;
|
|
527
560
|
var DEFAULT_LOCK_WAIT_BUDGET_MS = 15000;
|
|
@@ -775,7 +808,8 @@ async function spawnAndWaitReady(rosterPath, managedConfig, readinessBudgetMs) {
|
|
|
775
808
|
identity: finalIdentity,
|
|
776
809
|
password,
|
|
777
810
|
spawnConfig: { command, cwd, port: requestedPort },
|
|
778
|
-
baseUrl
|
|
811
|
+
baseUrl,
|
|
812
|
+
rosterPath
|
|
779
813
|
});
|
|
780
814
|
return {
|
|
781
815
|
baseUrl,
|
|
@@ -785,6 +819,9 @@ async function spawnAndWaitReady(rosterPath, managedConfig, readinessBudgetMs) {
|
|
|
785
819
|
};
|
|
786
820
|
}
|
|
787
821
|
async function ensureServer(rosterPath, options = {}) {
|
|
822
|
+
if (existsSync2(rosterPath)) {
|
|
823
|
+
rosterPath = realpathSync2(rosterPath);
|
|
824
|
+
}
|
|
788
825
|
const readinessBudgetMs = options.readinessBudgetMs ?? DEFAULT_READINESS_BUDGET_MS;
|
|
789
826
|
const lockWaitBudgetMs = options.lockWaitBudgetMs ?? DEFAULT_LOCK_WAIT_BUDGET_MS;
|
|
790
827
|
const fastPath = attachServer(rosterPath);
|
|
@@ -1826,7 +1863,7 @@ async function mcpLoadContext() {
|
|
|
1826
1863
|
}
|
|
1827
1864
|
return loadContext();
|
|
1828
1865
|
}
|
|
1829
|
-
var version = "0.
|
|
1866
|
+
var version = "0.12.0";
|
|
1830
1867
|
var server = new McpServer({
|
|
1831
1868
|
name: "space-bus",
|
|
1832
1869
|
version
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @experimental
|
|
3
|
+
* Experimental — shapes may change in minor releases.
|
|
4
|
+
*
|
|
5
|
+
* `/registry` library subpath barrel: re-exports the registry
|
|
6
|
+
* (list/register/unregister/set-default/resolve-name) and roster-edit
|
|
7
|
+
* (createRoster/add/remove/update project, edit server block) modules for
|
|
8
|
+
* external consumers (e.g. a Mothership webview or CLI) that want the
|
|
9
|
+
* mutation substrate without pulling in the tool/plugin/MCP surfaces.
|
|
10
|
+
* Node-only — joins config.ts's/discovery.ts's/server.ts's lane; MUST NOT
|
|
11
|
+
* be imported by core.ts, contract.ts, format.ts, or attach.ts.
|
|
12
|
+
*
|
|
13
|
+
* Both source modules independently declare a same-shaped `Result` type
|
|
14
|
+
* (`{ ok: true } | { ok: false; error: string }`); re-exporting both under
|
|
15
|
+
* one barrel would be an ambiguous-export collision, so each is re-exported
|
|
16
|
+
* here under a module-qualified alias instead of colliding on `Result`.
|
|
17
|
+
*/
|
|
18
|
+
export type { Result as RegistryResult } from "./registry";
|
|
19
|
+
export { readRegistry, registerRoster, registryPath, resolveRosterByName, setDefaultRoster, unregisterRoster, } from "./registry";
|
|
20
|
+
export type { CreateRosterOpts, ProjectPatch, Result as RosterEditResult, RosterProjectInput, } from "./roster-edit";
|
|
21
|
+
export { addProject, createRoster, editServer, removeProject, updateProject, } from "./roster-edit";
|