@fro.bot/space-bus 0.12.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/README.md +7 -1
- package/dist/cli.js +457 -59
- package/dist/config.d.ts +53 -0
- package/dist/config.js +415 -13
- package/dist/format.d.ts +13 -0
- package/dist/format.js +4 -0
- package/dist/index.js +1201 -195
- package/dist/mcp.js +1226 -113
- package/dist/registry-entry.js +159 -135
- package/dist/registry.d.ts +1 -0
- package/dist/server.js +418 -20
- package/dist/tools/bus_registry.d.ts +123 -0
- package/dist/tools/shared.d.ts +31 -1
- package/package.json +2 -2
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
|
|
6
|
-
import { homedir as
|
|
7
|
-
import { join as
|
|
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
|
|
@@ -433,6 +433,380 @@ function removeProvisional(rosterPath) {
|
|
|
433
433
|
} catch {}
|
|
434
434
|
}
|
|
435
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
|
+
|
|
436
810
|
// src/config.ts
|
|
437
811
|
var managedServerConfigSchema = z3.object({
|
|
438
812
|
command: z3.array(z3.string()).optional(),
|
|
@@ -466,7 +840,7 @@ var manifestSchema = z3.object({
|
|
|
466
840
|
}))
|
|
467
841
|
});
|
|
468
842
|
function expandHome(path) {
|
|
469
|
-
return path.startsWith("~") ?
|
|
843
|
+
return path.startsWith("~") ? join3(homedir3(), path.slice(1)) : path;
|
|
470
844
|
}
|
|
471
845
|
function resolveRosterPath(directory) {
|
|
472
846
|
const override = process.env["SPACE_BUS_CONFIG"];
|
|
@@ -478,19 +852,18 @@ function resolveRosterPath(directory) {
|
|
|
478
852
|
if (!expanded.startsWith("/")) {
|
|
479
853
|
throw new Error(`space-bus: SPACE_BUS_CONFIG must be an absolute path or start with ~ (got: ${override})`);
|
|
480
854
|
}
|
|
481
|
-
return existsSync(expanded) ?
|
|
855
|
+
return existsSync(expanded) ? realpathSync2(expanded) : expanded;
|
|
482
856
|
}
|
|
483
857
|
if (directory) {
|
|
484
|
-
const candidate =
|
|
485
|
-
return existsSync(candidate) ?
|
|
858
|
+
const candidate = join3(directory, "spacebus.json");
|
|
859
|
+
return existsSync(candidate) ? realpathSync2(candidate) : candidate;
|
|
486
860
|
}
|
|
487
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");
|
|
488
862
|
}
|
|
489
|
-
function
|
|
490
|
-
const manifestPath = resolveRosterPath(directory);
|
|
863
|
+
function getRosterAtPath(manifestPath) {
|
|
491
864
|
let raw;
|
|
492
865
|
try {
|
|
493
|
-
raw =
|
|
866
|
+
raw = readFileSync3(manifestPath, "utf8");
|
|
494
867
|
} catch (err) {
|
|
495
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)`);
|
|
496
869
|
}
|
|
@@ -513,6 +886,10 @@ function getRoster(directory) {
|
|
|
513
886
|
}
|
|
514
887
|
return parsed.data;
|
|
515
888
|
}
|
|
889
|
+
function getRoster(directory) {
|
|
890
|
+
const manifestPath = resolveRosterPath(directory);
|
|
891
|
+
return getRosterAtPath(manifestPath);
|
|
892
|
+
}
|
|
516
893
|
function getProjects(manifest) {
|
|
517
894
|
return manifest.projects.map((p) => {
|
|
518
895
|
const expandedPath = expandHome(p.path);
|
|
@@ -526,9 +903,8 @@ function getCredentials() {
|
|
|
526
903
|
const username = process.env["OPENCODE_SERVER_USERNAME"] ?? "opencode";
|
|
527
904
|
return { username, password };
|
|
528
905
|
}
|
|
529
|
-
function
|
|
530
|
-
const
|
|
531
|
-
const manifest = getRoster(directory);
|
|
906
|
+
function loadContextAtPath(rosterPath) {
|
|
907
|
+
const manifest = getRosterAtPath(rosterPath);
|
|
532
908
|
const projects = getProjects(manifest);
|
|
533
909
|
if (manifest.server.baseUrl === undefined) {
|
|
534
910
|
const live = attachLive(rosterPath);
|
|
@@ -545,6 +921,28 @@ function loadContext(directory) {
|
|
|
545
921
|
credentials: getCredentials()
|
|
546
922
|
};
|
|
547
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
|
+
}
|
|
548
946
|
function isManagedRoster(directory) {
|
|
549
947
|
const manifest = getRoster(directory);
|
|
550
948
|
return manifest.server.managed !== undefined;
|
|
@@ -554,8 +952,12 @@ export {
|
|
|
554
952
|
resolveRosterPath,
|
|
555
953
|
manifestSchema,
|
|
556
954
|
managedServerConfigSchema,
|
|
955
|
+
loadContextForRosterPath,
|
|
956
|
+
loadContextForRoster,
|
|
557
957
|
loadContext,
|
|
958
|
+
isManagedRosterAtPath,
|
|
558
959
|
isManagedRoster,
|
|
960
|
+
getRosterAtPath,
|
|
559
961
|
getRoster,
|
|
560
962
|
getProjects,
|
|
561
963
|
getCredentials,
|
package/dist/format.d.ts
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
* Experimental — shapes may change in minor releases.
|
|
4
4
|
*/
|
|
5
5
|
import type { DispatchResult, RosterProject, SessionResultResult, SessionStatusResult, WaitResult } from "./core";
|
|
6
|
+
/**
|
|
7
|
+
* Shared roster-echo header (R9): every bus tool result names the roster
|
|
8
|
+
* it resolved against — the split-brain/confused-deputy mitigation from
|
|
9
|
+
* document review. `source.name` is the registry name when the call
|
|
10
|
+
* resolved via a registry name (`roster: personal`); otherwise `source.path`
|
|
11
|
+
* (the ambient spacebus.json path) is used (`roster: /path/to/spacebus.json`).
|
|
12
|
+
* Both surfaces (plugin tools, MCP) prepend this line to result TEXT only —
|
|
13
|
+
* structured metadata (e.g. bus_task's sessionId/project/mode) is untouched.
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatRosterHeader(source: {
|
|
16
|
+
name?: string;
|
|
17
|
+
path: string;
|
|
18
|
+
}): string;
|
|
6
19
|
export declare function formatRoster(projects: RosterProject[]): string;
|
|
7
20
|
export declare function formatDispatch(r: DispatchResult): string;
|
|
8
21
|
/** Machine-readable dispatch metadata, shared verbatim by both surfaces
|
package/dist/format.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
// src/format.ts
|
|
2
|
+
function formatRosterHeader(source) {
|
|
3
|
+
return `roster: ${source.name ?? source.path}`;
|
|
4
|
+
}
|
|
2
5
|
function formatRoster(projects) {
|
|
3
6
|
return projects.map((p) => {
|
|
4
7
|
if (!p.pathExists)
|
|
@@ -76,6 +79,7 @@ function formatResult(r) {
|
|
|
76
79
|
export {
|
|
77
80
|
formatWait,
|
|
78
81
|
formatStatus,
|
|
82
|
+
formatRosterHeader,
|
|
79
83
|
formatRoster,
|
|
80
84
|
formatResult,
|
|
81
85
|
formatDispatch,
|