@fro.bot/space-bus 0.11.0 → 0.13.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/dist/config.d.ts CHANGED
@@ -54,6 +54,14 @@ export declare function expandHome(path: string): string;
54
54
  * error message.
55
55
  */
56
56
  export declare function resolveRosterPath(directory?: string): string;
57
+ /**
58
+ * Reads, validates, and expands the roster manifest at an already-resolved
59
+ * path. Extracted from `getRoster` so both directory-based resolution and
60
+ * registry-name-based resolution (`loadContextForRoster`) share the exact
61
+ * same read/parse/validate/localhost-guard pipeline — no parallel
62
+ * resolution path.
63
+ */
64
+ export declare function getRosterAtPath(manifestPath: string): Manifest;
57
65
  /** Reads, validates, and expands the roster for a given workspace directory. No caching — reads per call. */
58
66
  export declare function getRoster(directory?: string): Manifest;
59
67
  export type Project = Manifest["projects"][number] & {
@@ -78,6 +86,51 @@ export declare function getCredentials(): {
78
86
  * discriminated-union Result at the core boundary.
79
87
  */
80
88
  export declare function loadContext(directory?: string): BusContext;
89
+ /**
90
+ * Registry-name-based loader: resolves `rosterName` via
91
+ * `registry.resolveRosterByName` (Node-only import; config.ts is already
92
+ * Node-only), then loads that roster through the exact same
93
+ * `loadContextAtPath` pipeline `loadContext` uses for directory resolution
94
+ * — the localhost guard and schema validation apply identically, no
95
+ * parallel resolution path. Unknown name (or a registry with zero
96
+ * rosters) throws an Error whose message lists the known roster names,
97
+ * matching `resolveRosterByName`'s error shape and `loadContext`'s
98
+ * throw-on-missing behavior; adapters convert to a discriminated-union
99
+ * Result / MCP `isError` at the boundary, same as `loadContext`.
100
+ *
101
+ * Returns the CANONICAL registered name (not necessarily the caller's
102
+ * spelling — resolution is case-insensitive) so callers echo the name as
103
+ * actually registered.
104
+ *
105
+ * TOCTOU note: this resolves the name a SECOND time. Callers that already
106
+ * resolved the name once (e.g. to decide whether to `ensureServer()`) must
107
+ * use `loadContextForRosterPath` instead, passing the already-resolved
108
+ * path, so the name is only ever resolved once per call.
109
+ */
110
+ export declare function loadContextForRoster(rosterName: string): {
111
+ context: BusContext;
112
+ rosterPath: string;
113
+ rosterName: string;
114
+ };
115
+ /**
116
+ * @experimental
117
+ * Path-based loader: loads a `BusContext` from an ALREADY-RESOLVED roster
118
+ * path, skipping name resolution entirely. Exists so callers that resolve
119
+ * a registry name once (e.g. `ensureAndLoadContext` in tools/shared.ts,
120
+ * `mcpLoadContext` in mcp.ts) can ensureServer() against the resolved path
121
+ * and then load context from that SAME path — never re-resolving the
122
+ * (mutable) registry name a second time, which would be a TOCTOU window
123
+ * where the name could have been re-registered to a different path
124
+ * in between.
125
+ */
126
+ export declare function loadContextForRosterPath(rosterPath: string): BusContext;
127
+ /**
128
+ * Cheap check for whether the roster at an already-resolved path is managed
129
+ * (spawn-eligible) vs. externally-managed (baseUrl). Extracted so both
130
+ * directory-based (`isManagedRoster`) and registry-name-based
131
+ * (`ensureAndLoadContext` in tools/shared.ts) callers share the same check.
132
+ */
133
+ export declare function isManagedRosterAtPath(rosterPath: string): boolean;
81
134
  /**
82
135
  * Cheap check for whether a roster is managed (spawn-eligible) vs.
83
136
  * externally-managed (baseUrl) — reads the manifest once. Adapters use this
package/dist/config.js CHANGED
@@ -2,9 +2,9 @@ import { createRequire } from "node:module";
2
2
  var __require = /* @__PURE__ */ createRequire(import.meta.url);
3
3
 
4
4
  // src/config.ts
5
- import { existsSync, readFileSync as readFileSync2, realpathSync } from "node:fs";
6
- import { homedir as homedir2 } from "node:os";
7
- import { join as join2 } from "node:path";
5
+ import { existsSync, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
6
+ import { homedir as homedir3 } from "node:os";
7
+ import { join as join3 } from "node:path";
8
8
  import { z as z3 } from "zod";
9
9
 
10
10
  // src/contract.ts
@@ -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
@@ -402,6 +433,380 @@ function removeProvisional(rosterPath) {
402
433
  } catch {}
403
434
  }
404
435
 
436
+ // src/registry.ts
437
+ import { randomBytes as randomBytes2 } from "node:crypto";
438
+ import {
439
+ closeSync as closeSync2,
440
+ constants as fsConstants2,
441
+ fstatSync,
442
+ lstatSync,
443
+ mkdirSync as mkdirSync2,
444
+ openSync as openSync2,
445
+ readFileSync as readFileSync2,
446
+ realpathSync,
447
+ renameSync as renameSync2,
448
+ statSync as statSync2,
449
+ unlinkSync as unlinkSync2,
450
+ writeSync
451
+ } from "node:fs";
452
+ import { homedir as homedir2 } from "node:os";
453
+ import { isAbsolute, join as join2 } from "node:path";
454
+ var EMPTY_REGISTRY = { version: 1, rosters: [] };
455
+ function registryPath() {
456
+ const base = process.env["XDG_CONFIG_HOME"] ?? join2(homedir2(), ".config");
457
+ return join2(base, "space-bus", "rosters.json");
458
+ }
459
+ function isEnoent2(err) {
460
+ return isErrnoCode2(err, "ENOENT");
461
+ }
462
+ function isErrnoCode2(err, code) {
463
+ return typeof err === "object" && err !== null && "code" in err && err.code === code;
464
+ }
465
+ function closeQuietly2(fd) {
466
+ try {
467
+ closeSync2(fd);
468
+ } catch {}
469
+ }
470
+ function readRegistry() {
471
+ const target = registryPath();
472
+ let raw;
473
+ try {
474
+ raw = readFileSync2(target, "utf8");
475
+ } catch (err) {
476
+ if (isEnoent2(err)) {
477
+ return { ok: true, registry: EMPTY_REGISTRY };
478
+ }
479
+ return {
480
+ ok: false,
481
+ error: `space-bus: cannot read registry at ${target}: ${String(err)}`
482
+ };
483
+ }
484
+ let json;
485
+ try {
486
+ json = JSON.parse(raw);
487
+ } catch (err) {
488
+ return {
489
+ ok: false,
490
+ error: `space-bus: registry at ${target} is not valid JSON: ${String(err)}`
491
+ };
492
+ }
493
+ const parsed = registryFileSchema.safeParse(json);
494
+ if (!parsed.success) {
495
+ return {
496
+ ok: false,
497
+ error: `space-bus: registry at ${target} failed schema validation: ${parsed.error.message}`
498
+ };
499
+ }
500
+ const nonAbsolute = parsed.data.rosters.find((entry) => !isAbsolute(entry.path));
501
+ if (nonAbsolute) {
502
+ return {
503
+ ok: false,
504
+ error: `space-bus: registry at ${target} contains a non-absolute path for roster "${nonAbsolute.name}": ${nonAbsolute.path}`
505
+ };
506
+ }
507
+ return { ok: true, registry: parsed.data };
508
+ }
509
+ function writeRegistryAtomic(data) {
510
+ const target = registryPath();
511
+ const dir = join2(target, "..");
512
+ try {
513
+ mkdirSync2(dir, { recursive: true, mode: 448 });
514
+ } catch (err) {
515
+ return {
516
+ ok: false,
517
+ error: `space-bus: failed to create registry dir ${dir}: ${String(err)}`
518
+ };
519
+ }
520
+ const tempPath = join2(dir, `.rosters.${randomBytes2(8).toString("hex")}.tmp`);
521
+ let fd;
522
+ try {
523
+ fd = openSync2(tempPath, fsConstants2.O_CREAT | fsConstants2.O_EXCL | fsConstants2.O_WRONLY, 384);
524
+ writeSync(fd, JSON.stringify(data, null, 2));
525
+ closeSync2(fd);
526
+ fd = undefined;
527
+ renameSync2(tempPath, target);
528
+ } catch (err) {
529
+ if (fd !== undefined)
530
+ closeQuietly2(fd);
531
+ try {
532
+ unlinkSync2(tempPath);
533
+ } catch {}
534
+ return {
535
+ ok: false,
536
+ error: `space-bus: failed to write registry at ${target}: ${String(err)}`
537
+ };
538
+ }
539
+ return { ok: true };
540
+ }
541
+ function registryLockPath() {
542
+ return join2(registryPath(), "..", "rosters.lock");
543
+ }
544
+ var LOCK_RETRY_COUNT = 10;
545
+ var LOCK_RETRY_DELAY_MS = 50;
546
+ var LOCK_STALE_MS = 1e4;
547
+ function sleepSync(ms) {
548
+ const buf = new Int32Array(new SharedArrayBuffer(4));
549
+ Atomics.wait(buf, 0, 0, ms);
550
+ }
551
+ function tryCreateRegistryLock(target) {
552
+ let fd;
553
+ try {
554
+ fd = openSync2(target, fsConstants2.O_CREAT | fsConstants2.O_EXCL | fsConstants2.O_WRONLY, 384);
555
+ } catch (err) {
556
+ if (isErrnoCode2(err, "EEXIST"))
557
+ return false;
558
+ throw err;
559
+ }
560
+ try {
561
+ writeSync(fd, String(process.pid));
562
+ } finally {
563
+ closeQuietly2(fd);
564
+ }
565
+ return true;
566
+ }
567
+ function isRegistryLockStale(target) {
568
+ try {
569
+ return Date.now() - statSync2(target).mtimeMs > LOCK_STALE_MS;
570
+ } catch {
571
+ return false;
572
+ }
573
+ }
574
+ function breakStaleAndRetry(target) {
575
+ if (!isRegistryLockStale(target))
576
+ return false;
577
+ try {
578
+ unlinkSync2(target);
579
+ } catch (err) {
580
+ if (!isEnoent2(err))
581
+ throw err;
582
+ }
583
+ return tryCreateRegistryLock(target);
584
+ }
585
+ function acquireRegistryLock() {
586
+ const dir = join2(registryPath(), "..");
587
+ mkdirSync2(dir, { recursive: true, mode: 448 });
588
+ const target = registryLockPath();
589
+ for (let attempt = 0;attempt <= LOCK_RETRY_COUNT; attempt++) {
590
+ if (tryCreateRegistryLock(target))
591
+ return true;
592
+ if (breakStaleAndRetry(target))
593
+ return true;
594
+ if (attempt < LOCK_RETRY_COUNT)
595
+ sleepSync(LOCK_RETRY_DELAY_MS);
596
+ }
597
+ return false;
598
+ }
599
+ function releaseRegistryLock() {
600
+ try {
601
+ unlinkSync2(registryLockPath());
602
+ } catch {}
603
+ }
604
+ function withRegistryLock(mutate) {
605
+ if (!acquireRegistryLock()) {
606
+ return {
607
+ ok: false,
608
+ error: "space-bus: timed out waiting for the registry lock (another process is mutating rosters.json) — try again"
609
+ };
610
+ }
611
+ try {
612
+ return mutate();
613
+ } finally {
614
+ releaseRegistryLock();
615
+ }
616
+ }
617
+ function openAndValidateRosterFile(rosterPath) {
618
+ let fd;
619
+ try {
620
+ fd = openSync2(rosterPath, fsConstants2.O_RDONLY | fsConstants2.O_NOFOLLOW);
621
+ } catch (err) {
622
+ if (isErrnoCode2(err, "ELOOP")) {
623
+ return {
624
+ ok: false,
625
+ error: `space-bus: roster path ${rosterPath} is a symlink — refusing to register a symlinked roster file`
626
+ };
627
+ }
628
+ if (isEnoent2(err)) {
629
+ return {
630
+ ok: false,
631
+ error: `space-bus: roster path ${rosterPath} does not exist: ${String(err)}`
632
+ };
633
+ }
634
+ return {
635
+ ok: false,
636
+ error: `space-bus: failed to open roster path ${rosterPath}: ${String(err)}`
637
+ };
638
+ }
639
+ try {
640
+ let stat;
641
+ try {
642
+ stat = fstatSync(fd);
643
+ } catch (err) {
644
+ return {
645
+ ok: false,
646
+ error: `space-bus: failed to stat roster path ${rosterPath}: ${String(err)}`
647
+ };
648
+ }
649
+ if (!stat.isFile()) {
650
+ return {
651
+ ok: false,
652
+ error: `space-bus: roster path ${rosterPath} is not a regular file — refusing to register`
653
+ };
654
+ }
655
+ let raw;
656
+ try {
657
+ raw = readFileSync2(fd, "utf8");
658
+ } catch (err) {
659
+ return {
660
+ ok: false,
661
+ error: `space-bus: failed to read roster path ${rosterPath}: ${String(err)}`
662
+ };
663
+ }
664
+ let json;
665
+ try {
666
+ json = JSON.parse(raw);
667
+ } catch (err) {
668
+ return {
669
+ ok: false,
670
+ error: `space-bus: roster path ${rosterPath} is not valid JSON: ${String(err)}`
671
+ };
672
+ }
673
+ const parsed = manifestSchema.safeParse(json);
674
+ if (!parsed.success) {
675
+ return {
676
+ ok: false,
677
+ error: `space-bus: roster path ${rosterPath} is not a valid spacebus.json — refusing to register: ${parsed.error.message}`
678
+ };
679
+ }
680
+ } finally {
681
+ closeQuietly2(fd);
682
+ }
683
+ return { ok: true };
684
+ }
685
+ function registerRoster(name, rosterPath) {
686
+ const nameCheck = registryEntrySchema.shape.name.safeParse(name);
687
+ if (!nameCheck.success) {
688
+ return {
689
+ ok: false,
690
+ error: `space-bus: invalid roster name "${name}": ${nameCheck.error.issues[0]?.message ?? "must be 1-64 lowercase letters, digits, or hyphens"}`
691
+ };
692
+ }
693
+ const validated = openAndValidateRosterFile(rosterPath);
694
+ if (!validated.ok)
695
+ return validated;
696
+ let canonicalPath;
697
+ try {
698
+ canonicalPath = realpathSync(rosterPath);
699
+ } catch (err) {
700
+ return {
701
+ ok: false,
702
+ error: `space-bus: failed to canonicalize roster path ${rosterPath}: ${String(err)}`
703
+ };
704
+ }
705
+ return withRegistryLock(() => {
706
+ const readResult = readRegistry();
707
+ if (!readResult.ok)
708
+ return readResult;
709
+ const registry = readResult.registry;
710
+ const collision = registry.rosters.find((entry2) => entry2.name.toLowerCase() === name.toLowerCase());
711
+ if (collision) {
712
+ return {
713
+ ok: false,
714
+ error: `space-bus: a roster named "${collision.name}" is already registered`
715
+ };
716
+ }
717
+ const entry = { name, path: canonicalPath };
718
+ const next = {
719
+ ...registry,
720
+ rosters: [...registry.rosters, entry]
721
+ };
722
+ return writeRegistryAtomic(next);
723
+ });
724
+ }
725
+ function unregisterRoster(name) {
726
+ return withRegistryLock(() => {
727
+ const readResult = readRegistry();
728
+ if (!readResult.ok)
729
+ return readResult;
730
+ const registry = readResult.registry;
731
+ const exists = registry.rosters.some((entry) => entry.name.toLowerCase() === name.toLowerCase());
732
+ if (!exists) {
733
+ return {
734
+ ok: false,
735
+ error: `space-bus: no roster named "${name}" is registered`
736
+ };
737
+ }
738
+ const rosters = registry.rosters.filter((entry) => entry.name.toLowerCase() !== name.toLowerCase());
739
+ const next = {
740
+ ...registry,
741
+ rosters,
742
+ default: registry.default !== undefined && registry.default.toLowerCase() === name.toLowerCase() ? undefined : registry.default
743
+ };
744
+ return writeRegistryAtomic(next);
745
+ });
746
+ }
747
+ function setDefaultRoster(name) {
748
+ return withRegistryLock(() => {
749
+ const readResult = readRegistry();
750
+ if (!readResult.ok)
751
+ return readResult;
752
+ const registry = readResult.registry;
753
+ const entry = registry.rosters.find((r) => r.name.toLowerCase() === name.toLowerCase());
754
+ if (!entry) {
755
+ return {
756
+ ok: false,
757
+ error: `space-bus: no roster named "${name}" is registered`
758
+ };
759
+ }
760
+ const next = { ...registry, default: entry.name };
761
+ return writeRegistryAtomic(next);
762
+ });
763
+ }
764
+ function resolveRosterByName(name) {
765
+ const readResult = readRegistry();
766
+ if (!readResult.ok)
767
+ return readResult;
768
+ const registry = readResult.registry;
769
+ const entry = registry.rosters.find((r) => r.name.toLowerCase() === name.toLowerCase());
770
+ if (!entry) {
771
+ const known = registry.rosters.map((r) => r.name);
772
+ return {
773
+ ok: false,
774
+ error: known.length > 0 ? `space-bus: no roster named "${name}" is registered (known: ${known.join(", ")})` : `space-bus: no roster named "${name}" is registered (no rosters are registered)`
775
+ };
776
+ }
777
+ let stat;
778
+ try {
779
+ stat = lstatSync(entry.path);
780
+ } catch {
781
+ return {
782
+ ok: false,
783
+ error: `space-bus: registered roster file no longer exists at ${entry.path} (name "${entry.name}") — was it moved or deleted?`
784
+ };
785
+ }
786
+ if (stat.isSymbolicLink()) {
787
+ return {
788
+ ok: false,
789
+ error: `space-bus: registered roster path ${entry.path} (name "${entry.name}") is now a symlink — refusing to resolve a symlinked roster file`
790
+ };
791
+ }
792
+ if (!stat.isFile()) {
793
+ return {
794
+ ok: false,
795
+ error: `space-bus: registered roster path ${entry.path} (name "${entry.name}") is no longer a regular file`
796
+ };
797
+ }
798
+ let canonicalPath;
799
+ try {
800
+ canonicalPath = realpathSync(entry.path);
801
+ } catch (err) {
802
+ return {
803
+ ok: false,
804
+ error: `space-bus: failed to canonicalize registered roster path ${entry.path} (name "${entry.name}"): ${String(err)}`
805
+ };
806
+ }
807
+ return { ok: true, path: canonicalPath, name: entry.name };
808
+ }
809
+
405
810
  // src/config.ts
406
811
  var managedServerConfigSchema = z3.object({
407
812
  command: z3.array(z3.string()).optional(),
@@ -435,7 +840,7 @@ var manifestSchema = z3.object({
435
840
  }))
436
841
  });
437
842
  function expandHome(path) {
438
- return path.startsWith("~") ? join2(homedir2(), path.slice(1)) : path;
843
+ return path.startsWith("~") ? join3(homedir3(), path.slice(1)) : path;
439
844
  }
440
845
  function resolveRosterPath(directory) {
441
846
  const override = process.env["SPACE_BUS_CONFIG"];
@@ -447,19 +852,18 @@ function resolveRosterPath(directory) {
447
852
  if (!expanded.startsWith("/")) {
448
853
  throw new Error(`space-bus: SPACE_BUS_CONFIG must be an absolute path or start with ~ (got: ${override})`);
449
854
  }
450
- return existsSync(expanded) ? realpathSync(expanded) : expanded;
855
+ return existsSync(expanded) ? realpathSync2(expanded) : expanded;
451
856
  }
452
857
  if (directory) {
453
- const candidate = join2(directory, "spacebus.json");
454
- return existsSync(candidate) ? realpathSync(candidate) : candidate;
858
+ const candidate = join3(directory, "spacebus.json");
859
+ return existsSync(candidate) ? realpathSync2(candidate) : candidate;
455
860
  }
456
861
  throw new Error("space-bus: cannot locate spacebus.json — pass a directory containing spacebus.json, or set SPACE_BUS_CONFIG to an absolute path (or ~-prefixed path) to the roster file");
457
862
  }
458
- function getRoster(directory) {
459
- const manifestPath = resolveRosterPath(directory);
863
+ function getRosterAtPath(manifestPath) {
460
864
  let raw;
461
865
  try {
462
- raw = readFileSync2(manifestPath, "utf8");
866
+ raw = readFileSync3(manifestPath, "utf8");
463
867
  } catch (err) {
464
868
  throw new Error(`space-bus: cannot read roster at ${manifestPath}: ${err.message} (set SPACE_BUS_CONFIG or ensure spacebus.json exists in the workspace directory)`);
465
869
  }
@@ -482,6 +886,10 @@ function getRoster(directory) {
482
886
  }
483
887
  return parsed.data;
484
888
  }
889
+ function getRoster(directory) {
890
+ const manifestPath = resolveRosterPath(directory);
891
+ return getRosterAtPath(manifestPath);
892
+ }
485
893
  function getProjects(manifest) {
486
894
  return manifest.projects.map((p) => {
487
895
  const expandedPath = expandHome(p.path);
@@ -495,9 +903,8 @@ function getCredentials() {
495
903
  const username = process.env["OPENCODE_SERVER_USERNAME"] ?? "opencode";
496
904
  return { username, password };
497
905
  }
498
- function loadContext(directory) {
499
- const rosterPath = resolveRosterPath(directory);
500
- const manifest = getRoster(directory);
906
+ function loadContextAtPath(rosterPath) {
907
+ const manifest = getRosterAtPath(rosterPath);
501
908
  const projects = getProjects(manifest);
502
909
  if (manifest.server.baseUrl === undefined) {
503
910
  const live = attachLive(rosterPath);
@@ -514,6 +921,28 @@ function loadContext(directory) {
514
921
  credentials: getCredentials()
515
922
  };
516
923
  }
924
+ function loadContext(directory) {
925
+ const rosterPath = resolveRosterPath(directory);
926
+ return loadContextAtPath(rosterPath);
927
+ }
928
+ function loadContextForRoster(rosterName) {
929
+ const resolved = resolveRosterByName(rosterName);
930
+ if (!resolved.ok) {
931
+ throw new Error(resolved.error);
932
+ }
933
+ return {
934
+ context: loadContextAtPath(resolved.path),
935
+ rosterPath: resolved.path,
936
+ rosterName: resolved.name
937
+ };
938
+ }
939
+ function loadContextForRosterPath(rosterPath) {
940
+ return loadContextAtPath(rosterPath);
941
+ }
942
+ function isManagedRosterAtPath(rosterPath) {
943
+ const manifest = getRosterAtPath(rosterPath);
944
+ return manifest.server.managed !== undefined;
945
+ }
517
946
  function isManagedRoster(directory) {
518
947
  const manifest = getRoster(directory);
519
948
  return manifest.server.managed !== undefined;
@@ -523,8 +952,12 @@ export {
523
952
  resolveRosterPath,
524
953
  manifestSchema,
525
954
  managedServerConfigSchema,
955
+ loadContextForRosterPath,
956
+ loadContextForRoster,
526
957
  loadContext,
958
+ isManagedRosterAtPath,
527
959
  isManagedRoster,
960
+ getRosterAtPath,
528
961
  getRoster,
529
962
  getProjects,
530
963
  getCredentials,
@@ -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,