@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
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type RegistryFile } from "./contract";
|
|
2
|
+
export type Result = {
|
|
3
|
+
ok: true;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* `$XDG_CONFIG_HOME/space-bus/rosters.json`, falling back to
|
|
10
|
+
* `~/.config/space-bus/rosters.json`. Config lane (durable, user-editable),
|
|
11
|
+
* distinct from the daemon-owned state lane (`~/.local/state/space-bus`,
|
|
12
|
+
* see discovery.ts's `stateDirFor`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function registryPath(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Reads and validates the registry file. An absent file (ENOENT) is a
|
|
17
|
+
* valid, empty registry (not an error) — nothing has been registered yet.
|
|
18
|
+
* Every OTHER read failure (permission denied, target is a directory,
|
|
19
|
+
* etc.) is reported as `ok:false` rather than silently treated as empty —
|
|
20
|
+
* a masked read failure could otherwise cause a registration to appear to
|
|
21
|
+
* "lose" existing entries. Unparseable JSON or a schema-invalid document
|
|
22
|
+
* is likewise `ok:false` with an actionable message. After schema parse,
|
|
23
|
+
* every entry's `path` must be absolute — the schema itself stays
|
|
24
|
+
* platform-agnostic (just non-empty); absolute-path enforcement is a
|
|
25
|
+
* Node-boundary concern. This function never throws.
|
|
26
|
+
*/
|
|
27
|
+
export declare function readRegistry(): {
|
|
28
|
+
ok: true;
|
|
29
|
+
registry: RegistryFile;
|
|
30
|
+
} | {
|
|
31
|
+
ok: false;
|
|
32
|
+
error: string;
|
|
33
|
+
};
|
|
34
|
+
export declare function registerRoster(name: string, rosterPath: string): Result;
|
|
35
|
+
/**
|
|
36
|
+
* Removes the named entry (and clears the default pointer if it pointed to
|
|
37
|
+
* that name). Never touches the roster file itself on disk.
|
|
38
|
+
*/
|
|
39
|
+
export declare function unregisterRoster(name: string): Result;
|
|
40
|
+
/** Sets the default roster by name; the name must already be registered. */
|
|
41
|
+
export declare function setDefaultRoster(name: string): Result;
|
|
42
|
+
/**
|
|
43
|
+
* Resolves a registered roster name to its canonical path, revalidating
|
|
44
|
+
* the target at resolution time rather than trusting the stored path
|
|
45
|
+
* blindly: the roster file must still exist, its final path component
|
|
46
|
+
* must not be a symlink, and it must be a regular file — then it is
|
|
47
|
+
* realpathSync'd fresh (not just returned from storage) so a moved/
|
|
48
|
+
* replaced target is caught rather than silently trusted. On a name miss,
|
|
49
|
+
* the error lists all known names.
|
|
50
|
+
*/
|
|
51
|
+
export declare function resolveRosterByName(name: string): {
|
|
52
|
+
ok: true;
|
|
53
|
+
path: string;
|
|
54
|
+
} | {
|
|
55
|
+
ok: false;
|
|
56
|
+
error: string;
|
|
57
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type ServerConfig } from "./config";
|
|
2
|
+
export type Result = {
|
|
3
|
+
ok: true;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: string;
|
|
7
|
+
fileCreated?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export interface RosterProjectInput {
|
|
10
|
+
name: string;
|
|
11
|
+
path: string;
|
|
12
|
+
description: string;
|
|
13
|
+
}
|
|
14
|
+
export type ProjectPatch = Partial<RosterProjectInput>;
|
|
15
|
+
export interface CreateRosterOpts {
|
|
16
|
+
name: string;
|
|
17
|
+
rosterPath: string;
|
|
18
|
+
server?: ServerConfig;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Writes a schema-valid spacebus.json at `rosterPath` (default server mode
|
|
22
|
+
* `{ managed: {} }`; empty projects array unless `opts.server` overrides
|
|
23
|
+
* the server block) and registers it under `opts.name` via
|
|
24
|
+
* `registry.registerRoster`.
|
|
25
|
+
*
|
|
26
|
+
* Preflight (before any write): name charset validity, registry
|
|
27
|
+
* readability, and no name collision — every preflight failure returns
|
|
28
|
+
* `ok:false` with NO file created. The write itself is an exclusive
|
|
29
|
+
* create (`writeRosterExclusive`) so two concurrent `createRoster` calls
|
|
30
|
+
* targeting the same path can't silently clobber each other — exactly one
|
|
31
|
+
* wins.
|
|
32
|
+
*
|
|
33
|
+
* If the file write succeeds but registration fails (a rare race: the
|
|
34
|
+
* registry write lost a concurrent contention window or is corrupt), the
|
|
35
|
+
* file is NOT deleted — the returned error names both facts and sets
|
|
36
|
+
* `fileCreated: true` so a caller can recover programmatically (retrying
|
|
37
|
+
* `registerRoster` directly is the recovery op).
|
|
38
|
+
*/
|
|
39
|
+
export declare function createRoster(opts: CreateRosterOpts): Result;
|
|
40
|
+
/** Adds a project. Duplicate `project.name` (exact match) is rejected. */
|
|
41
|
+
export declare function addProject(rosterPath: string, project: RosterProjectInput): Result;
|
|
42
|
+
/** Removes a project by name. Unknown name → ok:false listing known
|
|
43
|
+
* project names (an empty resulting `projects` array is still valid). */
|
|
44
|
+
export declare function removeProject(rosterPath: string, projectName: string): Result;
|
|
45
|
+
/** Patches an existing project's fields. Unknown name → ok:false listing
|
|
46
|
+
* known project names. A `patch.name` that collides with another existing
|
|
47
|
+
* project (exact match, mirroring addProject) is rejected without
|
|
48
|
+
* mutating the file. */
|
|
49
|
+
export declare function updateProject(rosterPath: string, projectName: string, patch: ProjectPatch): Result;
|
|
50
|
+
/**
|
|
51
|
+
* Replaces the roster's `server` block wholesale (`baseUrl` XOR `managed`,
|
|
52
|
+
* enforced by re-validation). A non-loopback `baseUrl` is rejected and the
|
|
53
|
+
* file is left byte-identical (AE4).
|
|
54
|
+
*
|
|
55
|
+
* Live-daemon guard: if a managed daemon is currently live for this
|
|
56
|
+
* roster (per `discovery.ts`'s `attachLive`), server-block edits are
|
|
57
|
+
* rejected — changing `server` out from under a running daemon would
|
|
58
|
+
* leave the on-disk roster and the live discovery record pointing at
|
|
59
|
+
* different worlds (split-brain). Project edits are unaffected; only
|
|
60
|
+
* `editServer` carries this guard.
|
|
61
|
+
*/
|
|
62
|
+
export declare function editServer(rosterPath: string, server: ServerConfig): Result;
|
package/dist/server.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,105 @@
|
|
|
1
|
+
import { type ExecSeam } from "./launchd";
|
|
2
|
+
import { serverStatus as defaultServerStatus } from "./server";
|
|
3
|
+
declare const NOT_SUPPORTED_ERROR = "space-bus service is not supported on this platform (v1 supports macOS/launchd)";
|
|
4
|
+
/** Injectable seams for the service verbs — mirrors `RunServeDeps`'s
|
|
5
|
+
* pattern in cli.ts. All fields are optional and default to the real
|
|
6
|
+
* implementations. */
|
|
7
|
+
export interface ServiceDeps {
|
|
8
|
+
exec?: ExecSeam;
|
|
9
|
+
platform?: NodeJS.Platform;
|
|
10
|
+
uid?: number;
|
|
11
|
+
execPath?: string;
|
|
12
|
+
/** Absolute path of the CLI entry module. Defaults to `process.argv[1]`
|
|
13
|
+
* resolved to absolute — Unit 3 is responsible for wiring a durable
|
|
14
|
+
* resolution (e.g. `fileURLToPath(import.meta.url)`) when invoking these
|
|
15
|
+
* verbs from the running CLI. */
|
|
16
|
+
cliEntryPath?: string;
|
|
17
|
+
serverStatus?: typeof defaultServerStatus;
|
|
18
|
+
/** Injectable sleep, for deterministic tests. */
|
|
19
|
+
sleep?: (ms: number) => Promise<void>;
|
|
20
|
+
/** Injectable clock, for deterministic tests. */
|
|
21
|
+
now?: () => number;
|
|
22
|
+
/** Bounds the install verification poll loop. Default 10s. */
|
|
23
|
+
verifyBudgetMs?: number;
|
|
24
|
+
/** Poll interval for the install verification loop. Default 200ms. */
|
|
25
|
+
verifyPollMs?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Base directory for the launchd agent plist. Defaults to
|
|
28
|
+
* `~/Library/LaunchAgents`. Tests MUST inject a mkdtemp dir here — never
|
|
29
|
+
* exercise the default against the real filesystem.
|
|
30
|
+
*/
|
|
31
|
+
launchAgentsDir?: string;
|
|
32
|
+
}
|
|
33
|
+
export type PlatformGate = {
|
|
34
|
+
ok: true;
|
|
35
|
+
} | {
|
|
36
|
+
ok: false;
|
|
37
|
+
error: string;
|
|
38
|
+
};
|
|
39
|
+
interface ServiceIdentity {
|
|
40
|
+
label: string;
|
|
41
|
+
plistFilePath: string;
|
|
42
|
+
stateDir: string;
|
|
43
|
+
}
|
|
44
|
+
declare function identityFor(rosterPath: string, launchAgentsDir: string): ServiceIdentity;
|
|
45
|
+
export type PreCreateLogResult = {
|
|
46
|
+
ok: true;
|
|
47
|
+
} | {
|
|
48
|
+
ok: false;
|
|
49
|
+
error: string;
|
|
50
|
+
};
|
|
51
|
+
export type InstallResult = {
|
|
52
|
+
ok: true;
|
|
53
|
+
label: string;
|
|
54
|
+
plistPath: string;
|
|
55
|
+
pid?: number;
|
|
56
|
+
warning?: string;
|
|
57
|
+
} | {
|
|
58
|
+
ok: false;
|
|
59
|
+
error: string;
|
|
60
|
+
};
|
|
61
|
+
export declare function installService(rosterPath: string, deps?: ServiceDeps): Promise<InstallResult>;
|
|
62
|
+
export type UninstallResult = {
|
|
63
|
+
ok: true;
|
|
64
|
+
removed: {
|
|
65
|
+
job: boolean;
|
|
66
|
+
plist: boolean;
|
|
67
|
+
};
|
|
68
|
+
label: string;
|
|
69
|
+
} | {
|
|
70
|
+
ok: false;
|
|
71
|
+
error: string;
|
|
72
|
+
};
|
|
73
|
+
export declare function uninstallService(rosterPath: string, deps?: ServiceDeps): Promise<UninstallResult>;
|
|
74
|
+
export type StatusResult = {
|
|
75
|
+
ok: true;
|
|
76
|
+
installed: boolean;
|
|
77
|
+
loaded: boolean;
|
|
78
|
+
running: boolean;
|
|
79
|
+
pid?: number;
|
|
80
|
+
label: string;
|
|
81
|
+
plistPath: string;
|
|
82
|
+
} | {
|
|
83
|
+
ok: false;
|
|
84
|
+
error: string;
|
|
85
|
+
};
|
|
86
|
+
export declare function serviceStatus(rosterPath: string, deps?: ServiceDeps): Promise<StatusResult>;
|
|
87
|
+
export type StopResult = {
|
|
88
|
+
ok: true;
|
|
89
|
+
label: string;
|
|
90
|
+
wasLoaded: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
ok: false;
|
|
93
|
+
error: string;
|
|
94
|
+
};
|
|
95
|
+
export declare function stopService(rosterPath: string, deps?: ServiceDeps): Promise<StopResult>;
|
|
96
|
+
export type StartResult = {
|
|
97
|
+
ok: true;
|
|
98
|
+
label: string;
|
|
99
|
+
pid?: number;
|
|
100
|
+
} | {
|
|
101
|
+
ok: false;
|
|
102
|
+
error: string;
|
|
103
|
+
};
|
|
104
|
+
export declare function startService(rosterPath: string, deps?: ServiceDeps): Promise<StartResult>;
|
|
105
|
+
export { identityFor as serviceIdentity, NOT_SUPPORTED_ERROR as SERVICE_NOT_SUPPORTED_ERROR, };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fro.bot/space-bus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Space Bus — workspace agent bus for OpenCode. One control agent tasking per-project agents over the OpenCode server API, with an MCP facade for Claude Desktop.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,6 +39,10 @@
|
|
|
39
39
|
"./attach": {
|
|
40
40
|
"types": "./dist/attach.d.ts",
|
|
41
41
|
"import": "./dist/attach.js"
|
|
42
|
+
},
|
|
43
|
+
"./registry": {
|
|
44
|
+
"types": "./dist/registry-entry.d.ts",
|
|
45
|
+
"import": "./dist/registry-entry.js"
|
|
42
46
|
}
|
|
43
47
|
},
|
|
44
48
|
"bin": {
|