@fro.bot/space-bus 0.11.0 → 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.
@@ -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
@@ -522,7 +553,7 @@ function isManagedRoster(directory) {
522
553
  // src/server.ts
523
554
  import { spawn } from "node:child_process";
524
555
  import { randomBytes as randomBytes2 } from "node:crypto";
525
- 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";
526
557
  import { dirname } from "node:path";
527
558
  var DEFAULT_READINESS_BUDGET_MS = 15000;
528
559
  var DEFAULT_LOCK_WAIT_BUDGET_MS = 15000;
@@ -776,7 +807,8 @@ async function spawnAndWaitReady(rosterPath, managedConfig, readinessBudgetMs) {
776
807
  identity: finalIdentity,
777
808
  password,
778
809
  spawnConfig: { command, cwd, port: requestedPort },
779
- baseUrl
810
+ baseUrl,
811
+ rosterPath
780
812
  });
781
813
  return {
782
814
  baseUrl,
@@ -786,6 +818,9 @@ async function spawnAndWaitReady(rosterPath, managedConfig, readinessBudgetMs) {
786
818
  };
787
819
  }
788
820
  async function ensureServer(rosterPath, options = {}) {
821
+ if (existsSync2(rosterPath)) {
822
+ rosterPath = realpathSync2(rosterPath);
823
+ }
789
824
  const readinessBudgetMs = options.readinessBudgetMs ?? DEFAULT_READINESS_BUDGET_MS;
790
825
  const lockWaitBudgetMs = options.lockWaitBudgetMs ?? DEFAULT_LOCK_WAIT_BUDGET_MS;
791
826
  const fastPath = attachServer(rosterPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fro.bot/space-bus",
3
- "version": "0.11.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": {