@fro.bot/space-bus 0.15.0 → 0.15.2
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 +5 -2
- package/dist/attach.js +2 -2
- package/dist/cli.js +325 -33
- package/dist/config.js +14 -17
- package/dist/contract.js +30 -30
- package/dist/core.js +11 -11
- package/dist/format.js +6 -6
- package/dist/index.js +1052 -1055
- package/dist/launchd.d.ts +4 -2
- package/dist/mcp.js +1164 -1164
- package/dist/registry-entry.js +189 -190
- package/dist/server.js +18 -19
- package/dist/service-lock.d.ts +58 -0
- package/dist/service.d.ts +6 -0
- package/package.json +6 -6
package/dist/registry-entry.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/registry.ts
|
|
2
|
+
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
3
|
+
import {
|
|
4
|
+
closeSync as closeSync2,
|
|
5
|
+
constants as fsConstants2,
|
|
6
|
+
fstatSync,
|
|
7
|
+
lstatSync,
|
|
8
|
+
mkdirSync as mkdirSync2,
|
|
9
|
+
openSync as openSync2,
|
|
10
|
+
readFileSync as readFileSync3,
|
|
11
|
+
realpathSync as realpathSync2,
|
|
12
|
+
renameSync as renameSync2,
|
|
13
|
+
statSync as statSync2,
|
|
14
|
+
unlinkSync as unlinkSync2,
|
|
15
|
+
writeSync
|
|
16
|
+
} from "node:fs";
|
|
17
|
+
import { homedir as homedir3 } from "node:os";
|
|
18
|
+
import { isAbsolute, join as join3 } from "node:path";
|
|
3
19
|
|
|
4
20
|
// src/config.ts
|
|
5
|
-
import { existsSync, readFileSync as
|
|
6
|
-
import { homedir as
|
|
7
|
-
import { join as
|
|
21
|
+
import { existsSync, readFileSync as readFileSync2, realpathSync } from "node:fs";
|
|
22
|
+
import { homedir as homedir2 } from "node:os";
|
|
23
|
+
import { join as join2 } from "node:path";
|
|
8
24
|
import { z as z3 } from "zod";
|
|
9
25
|
|
|
10
26
|
// src/contract.ts
|
|
@@ -443,28 +459,158 @@ function removeProvisional(rosterPath) {
|
|
|
443
459
|
} catch {}
|
|
444
460
|
}
|
|
445
461
|
|
|
462
|
+
// src/config.ts
|
|
463
|
+
var managedServerConfigSchema = z3.object({
|
|
464
|
+
command: z3.array(z3.string()).optional(),
|
|
465
|
+
cwd: z3.string().optional(),
|
|
466
|
+
port: z3.number().int().nonnegative().optional()
|
|
467
|
+
});
|
|
468
|
+
var serverConfigSchema = z3.object({
|
|
469
|
+
baseUrl: z3.url().optional(),
|
|
470
|
+
managed: managedServerConfigSchema.optional()
|
|
471
|
+
}).superRefine((val, ctx) => {
|
|
472
|
+
const hasBaseUrl = val.baseUrl !== undefined;
|
|
473
|
+
const hasManaged = val.managed !== undefined;
|
|
474
|
+
if (hasBaseUrl && hasManaged) {
|
|
475
|
+
ctx.addIssue({
|
|
476
|
+
code: "custom",
|
|
477
|
+
message: "space-bus: roster's server block must specify exactly one of `baseUrl` or `managed`, not both"
|
|
478
|
+
});
|
|
479
|
+
} else if (!hasBaseUrl && !hasManaged) {
|
|
480
|
+
ctx.addIssue({
|
|
481
|
+
code: "custom",
|
|
482
|
+
message: "space-bus: roster's server block must specify one of `baseUrl` (externally-managed) or `managed` (plugin-spawned) — neither was present"
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
var manifestSchema = z3.object({
|
|
487
|
+
server: serverConfigSchema,
|
|
488
|
+
projects: z3.array(z3.object({
|
|
489
|
+
name: z3.string(),
|
|
490
|
+
path: z3.string(),
|
|
491
|
+
description: z3.string()
|
|
492
|
+
}))
|
|
493
|
+
});
|
|
494
|
+
function expandHome(path) {
|
|
495
|
+
return path.startsWith("~") ? join2(homedir2(), path.slice(1)) : path;
|
|
496
|
+
}
|
|
497
|
+
function resolveExplicitOverride(override, sourceLabel) {
|
|
498
|
+
if (override.includes("://")) {
|
|
499
|
+
throw new Error(`space-bus: ${sourceLabel} must be an absolute path or start with ~ (got a URL: ${override})`);
|
|
500
|
+
}
|
|
501
|
+
const expanded = expandHome(override);
|
|
502
|
+
if (!expanded.startsWith("/")) {
|
|
503
|
+
throw new Error(`space-bus: ${sourceLabel} must be an absolute path or start with ~ (got: ${override})`);
|
|
504
|
+
}
|
|
505
|
+
return existsSync(expanded) ? realpathSync(expanded) : expanded;
|
|
506
|
+
}
|
|
507
|
+
function resolveRosterPath(directory, explicitOverride) {
|
|
508
|
+
if (explicitOverride) {
|
|
509
|
+
return resolveExplicitOverride(explicitOverride, "--config");
|
|
510
|
+
}
|
|
511
|
+
const override = process.env["SPACE_BUS_CONFIG"];
|
|
512
|
+
if (override) {
|
|
513
|
+
return resolveExplicitOverride(override, "SPACE_BUS_CONFIG");
|
|
514
|
+
}
|
|
515
|
+
if (directory) {
|
|
516
|
+
const candidate = join2(directory, "spacebus.json");
|
|
517
|
+
return existsSync(candidate) ? realpathSync(candidate) : candidate;
|
|
518
|
+
}
|
|
519
|
+
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");
|
|
520
|
+
}
|
|
521
|
+
function getRosterAtPath(manifestPath) {
|
|
522
|
+
let raw;
|
|
523
|
+
try {
|
|
524
|
+
raw = readFileSync2(manifestPath, "utf8");
|
|
525
|
+
} catch (err) {
|
|
526
|
+
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)`);
|
|
527
|
+
}
|
|
528
|
+
let json;
|
|
529
|
+
try {
|
|
530
|
+
json = JSON.parse(raw);
|
|
531
|
+
} catch (err) {
|
|
532
|
+
throw new Error(`space-bus: roster at ${manifestPath} is not valid JSON: ${err.message}`);
|
|
533
|
+
}
|
|
534
|
+
const parsed = manifestSchema.safeParse(json);
|
|
535
|
+
if (!parsed.success) {
|
|
536
|
+
throw new Error(`space-bus: roster at ${manifestPath} failed schema validation: ${parsed.error.message}`);
|
|
537
|
+
}
|
|
538
|
+
if (parsed.data.server.baseUrl !== undefined) {
|
|
539
|
+
const url = new URL(parsed.data.server.baseUrl);
|
|
540
|
+
const hostname = url.hostname;
|
|
541
|
+
if (!LOOPBACK_HOSTS.has(hostname)) {
|
|
542
|
+
throw new Error(`space-bus: spacebus.json baseUrl must point to localhost (got ${hostname}) — refusing to send credentials off-machine`);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return parsed.data;
|
|
546
|
+
}
|
|
547
|
+
function getRoster(directory) {
|
|
548
|
+
const manifestPath = resolveRosterPath(directory);
|
|
549
|
+
return getRosterAtPath(manifestPath);
|
|
550
|
+
}
|
|
551
|
+
function getProjects(manifest) {
|
|
552
|
+
return manifest.projects.map((p) => {
|
|
553
|
+
const expandedPath = expandHome(p.path);
|
|
554
|
+
return { ...p, expandedPath, exists: existsSync(expandedPath) };
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
function getCredentials() {
|
|
558
|
+
const password = process.env["OPENCODE_SERVER_PASSWORD"];
|
|
559
|
+
if (!password)
|
|
560
|
+
return {};
|
|
561
|
+
const username = process.env["OPENCODE_SERVER_USERNAME"] ?? "opencode";
|
|
562
|
+
return { username, password };
|
|
563
|
+
}
|
|
564
|
+
function loadContextAtPath(rosterPath) {
|
|
565
|
+
const manifest = getRosterAtPath(rosterPath);
|
|
566
|
+
const projects = getProjects(manifest);
|
|
567
|
+
if (manifest.server.baseUrl === undefined) {
|
|
568
|
+
const live = attachLive(rosterPath);
|
|
569
|
+
if (!live) {
|
|
570
|
+
throw new Error(`space-bus: managed server not running for ${rosterPath} — call ensureServer() or run \`space-bus serve\``);
|
|
571
|
+
}
|
|
572
|
+
return {
|
|
573
|
+
roster: { server: { baseUrl: live.baseUrl }, projects },
|
|
574
|
+
credentials: live.credentials
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
return {
|
|
578
|
+
roster: { server: { baseUrl: manifest.server.baseUrl }, projects },
|
|
579
|
+
credentials: getCredentials()
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
function loadContext(directory) {
|
|
583
|
+
const rosterPath = resolveRosterPath(directory);
|
|
584
|
+
return loadContextAtPath(rosterPath);
|
|
585
|
+
}
|
|
586
|
+
function loadContextForRoster(rosterName) {
|
|
587
|
+
const resolved = resolveRosterByName(rosterName);
|
|
588
|
+
if (!resolved.ok) {
|
|
589
|
+
throw new Error(resolved.error);
|
|
590
|
+
}
|
|
591
|
+
return {
|
|
592
|
+
context: loadContextAtPath(resolved.path),
|
|
593
|
+
rosterPath: resolved.path,
|
|
594
|
+
rosterName: resolved.name
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function loadContextForRosterPath(rosterPath) {
|
|
598
|
+
return loadContextAtPath(rosterPath);
|
|
599
|
+
}
|
|
600
|
+
function isManagedRosterAtPath(rosterPath) {
|
|
601
|
+
const manifest = getRosterAtPath(rosterPath);
|
|
602
|
+
return manifest.server.managed !== undefined;
|
|
603
|
+
}
|
|
604
|
+
function isManagedRoster(directory) {
|
|
605
|
+
const manifest = getRoster(directory);
|
|
606
|
+
return manifest.server.managed !== undefined;
|
|
607
|
+
}
|
|
608
|
+
|
|
446
609
|
// src/registry.ts
|
|
447
|
-
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
448
|
-
import {
|
|
449
|
-
closeSync as closeSync2,
|
|
450
|
-
constants as fsConstants2,
|
|
451
|
-
fstatSync,
|
|
452
|
-
lstatSync,
|
|
453
|
-
mkdirSync as mkdirSync2,
|
|
454
|
-
openSync as openSync2,
|
|
455
|
-
readFileSync as readFileSync2,
|
|
456
|
-
realpathSync,
|
|
457
|
-
renameSync as renameSync2,
|
|
458
|
-
statSync as statSync2,
|
|
459
|
-
unlinkSync as unlinkSync2,
|
|
460
|
-
writeSync
|
|
461
|
-
} from "node:fs";
|
|
462
|
-
import { homedir as homedir2 } from "node:os";
|
|
463
|
-
import { isAbsolute, join as join2 } from "node:path";
|
|
464
610
|
var EMPTY_REGISTRY = { version: 1, rosters: [] };
|
|
465
611
|
function registryPath() {
|
|
466
|
-
const base = process.env["XDG_CONFIG_HOME"] ??
|
|
467
|
-
return
|
|
612
|
+
const base = process.env["XDG_CONFIG_HOME"] ?? join3(homedir3(), ".config");
|
|
613
|
+
return join3(base, "space-bus", "rosters.json");
|
|
468
614
|
}
|
|
469
615
|
function isEnoent2(err) {
|
|
470
616
|
return isErrnoCode2(err, "ENOENT");
|
|
@@ -481,7 +627,7 @@ function readRegistry() {
|
|
|
481
627
|
const target = registryPath();
|
|
482
628
|
let raw;
|
|
483
629
|
try {
|
|
484
|
-
raw =
|
|
630
|
+
raw = readFileSync3(target, "utf8");
|
|
485
631
|
} catch (err) {
|
|
486
632
|
if (isEnoent2(err)) {
|
|
487
633
|
return { ok: true, registry: EMPTY_REGISTRY };
|
|
@@ -518,7 +664,7 @@ function readRegistry() {
|
|
|
518
664
|
}
|
|
519
665
|
function writeRegistryAtomic(data) {
|
|
520
666
|
const target = registryPath();
|
|
521
|
-
const dir =
|
|
667
|
+
const dir = join3(target, "..");
|
|
522
668
|
try {
|
|
523
669
|
mkdirSync2(dir, { recursive: true, mode: 448 });
|
|
524
670
|
} catch (err) {
|
|
@@ -527,7 +673,7 @@ function writeRegistryAtomic(data) {
|
|
|
527
673
|
error: `space-bus: failed to create registry dir ${dir}: ${String(err)}`
|
|
528
674
|
};
|
|
529
675
|
}
|
|
530
|
-
const tempPath =
|
|
676
|
+
const tempPath = join3(dir, `.rosters.${randomBytes2(8).toString("hex")}.tmp`);
|
|
531
677
|
let fd;
|
|
532
678
|
try {
|
|
533
679
|
fd = openSync2(tempPath, fsConstants2.O_CREAT | fsConstants2.O_EXCL | fsConstants2.O_WRONLY, 384);
|
|
@@ -549,7 +695,7 @@ function writeRegistryAtomic(data) {
|
|
|
549
695
|
return { ok: true };
|
|
550
696
|
}
|
|
551
697
|
function registryLockPath() {
|
|
552
|
-
return
|
|
698
|
+
return join3(registryPath(), "..", "rosters.lock");
|
|
553
699
|
}
|
|
554
700
|
var LOCK_RETRY_COUNT = 10;
|
|
555
701
|
var LOCK_RETRY_DELAY_MS = 50;
|
|
@@ -593,7 +739,7 @@ function breakStaleAndRetry(target) {
|
|
|
593
739
|
return tryCreateRegistryLock(target);
|
|
594
740
|
}
|
|
595
741
|
function acquireRegistryLock() {
|
|
596
|
-
const dir =
|
|
742
|
+
const dir = join3(registryPath(), "..");
|
|
597
743
|
mkdirSync2(dir, { recursive: true, mode: 448 });
|
|
598
744
|
const target = registryLockPath();
|
|
599
745
|
for (let attempt = 0;attempt <= LOCK_RETRY_COUNT; attempt++) {
|
|
@@ -664,7 +810,7 @@ function openAndValidateRosterFile(rosterPath) {
|
|
|
664
810
|
}
|
|
665
811
|
let raw;
|
|
666
812
|
try {
|
|
667
|
-
raw =
|
|
813
|
+
raw = readFileSync3(fd, "utf8");
|
|
668
814
|
} catch (err) {
|
|
669
815
|
return {
|
|
670
816
|
ok: false,
|
|
@@ -705,7 +851,7 @@ function registerRoster(name, rosterPath) {
|
|
|
705
851
|
return validated;
|
|
706
852
|
let canonicalPath;
|
|
707
853
|
try {
|
|
708
|
-
canonicalPath =
|
|
854
|
+
canonicalPath = realpathSync2(rosterPath);
|
|
709
855
|
} catch (err) {
|
|
710
856
|
return {
|
|
711
857
|
ok: false,
|
|
@@ -717,7 +863,7 @@ function registerRoster(name, rosterPath) {
|
|
|
717
863
|
if (!readResult.ok)
|
|
718
864
|
return readResult;
|
|
719
865
|
const registry = readResult.registry;
|
|
720
|
-
const collision = registry.rosters.find((
|
|
866
|
+
const collision = registry.rosters.find((entry) => entry.name.toLowerCase() === name.toLowerCase());
|
|
721
867
|
if (collision) {
|
|
722
868
|
return {
|
|
723
869
|
ok: false,
|
|
@@ -807,7 +953,7 @@ function resolveRosterByName(name) {
|
|
|
807
953
|
}
|
|
808
954
|
let canonicalPath;
|
|
809
955
|
try {
|
|
810
|
-
canonicalPath =
|
|
956
|
+
canonicalPath = realpathSync2(entry.path);
|
|
811
957
|
} catch (err) {
|
|
812
958
|
return {
|
|
813
959
|
ok: false,
|
|
@@ -816,153 +962,6 @@ function resolveRosterByName(name) {
|
|
|
816
962
|
}
|
|
817
963
|
return { ok: true, path: canonicalPath, name: entry.name };
|
|
818
964
|
}
|
|
819
|
-
|
|
820
|
-
// src/config.ts
|
|
821
|
-
var managedServerConfigSchema = z3.object({
|
|
822
|
-
command: z3.array(z3.string()).optional(),
|
|
823
|
-
cwd: z3.string().optional(),
|
|
824
|
-
port: z3.number().int().nonnegative().optional()
|
|
825
|
-
});
|
|
826
|
-
var serverConfigSchema = z3.object({
|
|
827
|
-
baseUrl: z3.url().optional(),
|
|
828
|
-
managed: managedServerConfigSchema.optional()
|
|
829
|
-
}).superRefine((val, ctx) => {
|
|
830
|
-
const hasBaseUrl = val.baseUrl !== undefined;
|
|
831
|
-
const hasManaged = val.managed !== undefined;
|
|
832
|
-
if (hasBaseUrl && hasManaged) {
|
|
833
|
-
ctx.addIssue({
|
|
834
|
-
code: "custom",
|
|
835
|
-
message: "space-bus: roster's server block must specify exactly one of `baseUrl` or `managed`, not both"
|
|
836
|
-
});
|
|
837
|
-
} else if (!hasBaseUrl && !hasManaged) {
|
|
838
|
-
ctx.addIssue({
|
|
839
|
-
code: "custom",
|
|
840
|
-
message: "space-bus: roster's server block must specify one of `baseUrl` (externally-managed) or `managed` (plugin-spawned) — neither was present"
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
var manifestSchema = z3.object({
|
|
845
|
-
server: serverConfigSchema,
|
|
846
|
-
projects: z3.array(z3.object({
|
|
847
|
-
name: z3.string(),
|
|
848
|
-
path: z3.string(),
|
|
849
|
-
description: z3.string()
|
|
850
|
-
}))
|
|
851
|
-
});
|
|
852
|
-
function expandHome(path) {
|
|
853
|
-
return path.startsWith("~") ? join3(homedir3(), path.slice(1)) : path;
|
|
854
|
-
}
|
|
855
|
-
function resolveExplicitOverride(override, sourceLabel) {
|
|
856
|
-
if (override.includes("://")) {
|
|
857
|
-
throw new Error(`space-bus: ${sourceLabel} must be an absolute path or start with ~ (got a URL: ${override})`);
|
|
858
|
-
}
|
|
859
|
-
const expanded = expandHome(override);
|
|
860
|
-
if (!expanded.startsWith("/")) {
|
|
861
|
-
throw new Error(`space-bus: ${sourceLabel} must be an absolute path or start with ~ (got: ${override})`);
|
|
862
|
-
}
|
|
863
|
-
return existsSync(expanded) ? realpathSync2(expanded) : expanded;
|
|
864
|
-
}
|
|
865
|
-
function resolveRosterPath(directory, explicitOverride) {
|
|
866
|
-
if (explicitOverride) {
|
|
867
|
-
return resolveExplicitOverride(explicitOverride, "--config");
|
|
868
|
-
}
|
|
869
|
-
const override = process.env["SPACE_BUS_CONFIG"];
|
|
870
|
-
if (override) {
|
|
871
|
-
return resolveExplicitOverride(override, "SPACE_BUS_CONFIG");
|
|
872
|
-
}
|
|
873
|
-
if (directory) {
|
|
874
|
-
const candidate = join3(directory, "spacebus.json");
|
|
875
|
-
return existsSync(candidate) ? realpathSync2(candidate) : candidate;
|
|
876
|
-
}
|
|
877
|
-
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");
|
|
878
|
-
}
|
|
879
|
-
function getRosterAtPath(manifestPath) {
|
|
880
|
-
let raw;
|
|
881
|
-
try {
|
|
882
|
-
raw = readFileSync3(manifestPath, "utf8");
|
|
883
|
-
} catch (err) {
|
|
884
|
-
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)`);
|
|
885
|
-
}
|
|
886
|
-
let json;
|
|
887
|
-
try {
|
|
888
|
-
json = JSON.parse(raw);
|
|
889
|
-
} catch (err) {
|
|
890
|
-
throw new Error(`space-bus: roster at ${manifestPath} is not valid JSON: ${err.message}`);
|
|
891
|
-
}
|
|
892
|
-
const parsed = manifestSchema.safeParse(json);
|
|
893
|
-
if (!parsed.success) {
|
|
894
|
-
throw new Error(`space-bus: roster at ${manifestPath} failed schema validation: ${parsed.error.message}`);
|
|
895
|
-
}
|
|
896
|
-
if (parsed.data.server.baseUrl !== undefined) {
|
|
897
|
-
const url = new URL(parsed.data.server.baseUrl);
|
|
898
|
-
const hostname = url.hostname;
|
|
899
|
-
if (!LOOPBACK_HOSTS.has(hostname)) {
|
|
900
|
-
throw new Error(`space-bus: spacebus.json baseUrl must point to localhost (got ${hostname}) — refusing to send credentials off-machine`);
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
return parsed.data;
|
|
904
|
-
}
|
|
905
|
-
function getRoster(directory) {
|
|
906
|
-
const manifestPath = resolveRosterPath(directory);
|
|
907
|
-
return getRosterAtPath(manifestPath);
|
|
908
|
-
}
|
|
909
|
-
function getProjects(manifest) {
|
|
910
|
-
return manifest.projects.map((p) => {
|
|
911
|
-
const expandedPath = expandHome(p.path);
|
|
912
|
-
return { ...p, expandedPath, exists: existsSync(expandedPath) };
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
function getCredentials() {
|
|
916
|
-
const password = process.env["OPENCODE_SERVER_PASSWORD"];
|
|
917
|
-
if (!password)
|
|
918
|
-
return {};
|
|
919
|
-
const username = process.env["OPENCODE_SERVER_USERNAME"] ?? "opencode";
|
|
920
|
-
return { username, password };
|
|
921
|
-
}
|
|
922
|
-
function loadContextAtPath(rosterPath) {
|
|
923
|
-
const manifest = getRosterAtPath(rosterPath);
|
|
924
|
-
const projects = getProjects(manifest);
|
|
925
|
-
if (manifest.server.baseUrl === undefined) {
|
|
926
|
-
const live = attachLive(rosterPath);
|
|
927
|
-
if (!live) {
|
|
928
|
-
throw new Error(`space-bus: managed server not running for ${rosterPath} — call ensureServer() or run \`space-bus serve\``);
|
|
929
|
-
}
|
|
930
|
-
return {
|
|
931
|
-
roster: { server: { baseUrl: live.baseUrl }, projects },
|
|
932
|
-
credentials: live.credentials
|
|
933
|
-
};
|
|
934
|
-
}
|
|
935
|
-
return {
|
|
936
|
-
roster: { server: { baseUrl: manifest.server.baseUrl }, projects },
|
|
937
|
-
credentials: getCredentials()
|
|
938
|
-
};
|
|
939
|
-
}
|
|
940
|
-
function loadContext(directory) {
|
|
941
|
-
const rosterPath = resolveRosterPath(directory);
|
|
942
|
-
return loadContextAtPath(rosterPath);
|
|
943
|
-
}
|
|
944
|
-
function loadContextForRoster(rosterName) {
|
|
945
|
-
const resolved = resolveRosterByName(rosterName);
|
|
946
|
-
if (!resolved.ok) {
|
|
947
|
-
throw new Error(resolved.error);
|
|
948
|
-
}
|
|
949
|
-
return {
|
|
950
|
-
context: loadContextAtPath(resolved.path),
|
|
951
|
-
rosterPath: resolved.path,
|
|
952
|
-
rosterName: resolved.name
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
function loadContextForRosterPath(rosterPath) {
|
|
956
|
-
return loadContextAtPath(rosterPath);
|
|
957
|
-
}
|
|
958
|
-
function isManagedRosterAtPath(rosterPath) {
|
|
959
|
-
const manifest = getRosterAtPath(rosterPath);
|
|
960
|
-
return manifest.server.managed !== undefined;
|
|
961
|
-
}
|
|
962
|
-
function isManagedRoster(directory) {
|
|
963
|
-
const manifest = getRoster(directory);
|
|
964
|
-
return manifest.server.managed !== undefined;
|
|
965
|
-
}
|
|
966
965
|
// src/roster-edit.ts
|
|
967
966
|
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
968
967
|
import {
|
|
@@ -1244,15 +1243,15 @@ function editServer(rosterPath, server) {
|
|
|
1244
1243
|
return editManifest(rosterPath, (current) => ({ ...current, server }));
|
|
1245
1244
|
}
|
|
1246
1245
|
export {
|
|
1247
|
-
|
|
1248
|
-
unregisterRoster,
|
|
1249
|
-
setDefaultRoster,
|
|
1250
|
-
resolveRosterByName,
|
|
1251
|
-
removeProject,
|
|
1252
|
-
registryPath,
|
|
1253
|
-
registerRoster,
|
|
1254
|
-
readRegistry,
|
|
1255
|
-
editServer,
|
|
1246
|
+
addProject,
|
|
1256
1247
|
createRoster,
|
|
1257
|
-
|
|
1248
|
+
editServer,
|
|
1249
|
+
readRegistry,
|
|
1250
|
+
registerRoster,
|
|
1251
|
+
registryPath,
|
|
1252
|
+
removeProject,
|
|
1253
|
+
resolveRosterByName,
|
|
1254
|
+
setDefaultRoster,
|
|
1255
|
+
unregisterRoster,
|
|
1256
|
+
updateProject
|
|
1258
1257
|
};
|
package/dist/server.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
4
|
+
import { existsSync as existsSync2, openSync as openSync3, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
5
|
+
import { dirname } from "node:path";
|
|
3
6
|
|
|
4
7
|
// src/config.ts
|
|
5
8
|
import { existsSync, readFileSync as readFileSync3, realpathSync as realpathSync2 } from "node:fs";
|
|
@@ -717,7 +720,7 @@ function registerRoster(name, rosterPath) {
|
|
|
717
720
|
if (!readResult.ok)
|
|
718
721
|
return readResult;
|
|
719
722
|
const registry = readResult.registry;
|
|
720
|
-
const collision = registry.rosters.find((
|
|
723
|
+
const collision = registry.rosters.find((entry) => entry.name.toLowerCase() === name.toLowerCase());
|
|
721
724
|
if (collision) {
|
|
722
725
|
return {
|
|
723
726
|
ok: false,
|
|
@@ -965,10 +968,6 @@ function isManagedRoster(directory) {
|
|
|
965
968
|
}
|
|
966
969
|
|
|
967
970
|
// src/server.ts
|
|
968
|
-
import { spawn } from "node:child_process";
|
|
969
|
-
import { randomBytes as randomBytes3 } from "node:crypto";
|
|
970
|
-
import { existsSync as existsSync2, openSync as openSync3, readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
|
|
971
|
-
import { dirname } from "node:path";
|
|
972
971
|
var DEFAULT_READINESS_BUDGET_MS = 15000;
|
|
973
972
|
var DEFAULT_LOCK_WAIT_BUDGET_MS = 15000;
|
|
974
973
|
var POLL_INTERVAL_MS = 50;
|
|
@@ -1058,8 +1057,8 @@ async function waitForDiscoveryOrFail(rosterPath, budgetMs) {
|
|
|
1058
1057
|
const handle = attachServer(rosterPath);
|
|
1059
1058
|
if (handle)
|
|
1060
1059
|
return handle;
|
|
1061
|
-
const
|
|
1062
|
-
const winnerAlive =
|
|
1060
|
+
const lockInfo = readLockFile(lockPath);
|
|
1061
|
+
const winnerAlive = lockInfo !== null && verifyIdentity(lockInfo.pid, lockInfo.startTime);
|
|
1063
1062
|
if (!winnerAlive) {
|
|
1064
1063
|
throw new Error(`space-bus: the process starting the managed server for roster ${rosterPath} failed before it could finish (lock released without a discovery file) — check its log for details`);
|
|
1065
1064
|
}
|
|
@@ -1451,15 +1450,15 @@ async function waitForGroupDeath(pid, budgetMs) {
|
|
|
1451
1450
|
return !groupAlive();
|
|
1452
1451
|
}
|
|
1453
1452
|
export {
|
|
1454
|
-
|
|
1455
|
-
stopServer,
|
|
1456
|
-
serverStatus,
|
|
1457
|
-
redactSensitive,
|
|
1458
|
-
reapSurvivingGroup,
|
|
1459
|
-
probe,
|
|
1460
|
-
ensureServer,
|
|
1461
|
-
attachServer,
|
|
1462
|
-
SUPERVISE_UNHEALTHY_BUDGET_MS,
|
|
1453
|
+
SUPERVISE_FAILURE_THRESHOLD,
|
|
1463
1454
|
SUPERVISE_INTERVAL_MS,
|
|
1464
|
-
|
|
1455
|
+
SUPERVISE_UNHEALTHY_BUDGET_MS,
|
|
1456
|
+
attachServer,
|
|
1457
|
+
ensureServer,
|
|
1458
|
+
probe,
|
|
1459
|
+
reapSurvivingGroup,
|
|
1460
|
+
redactSensitive,
|
|
1461
|
+
serverStatus,
|
|
1462
|
+
stopServer,
|
|
1463
|
+
superviseServer
|
|
1465
1464
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @experimental
|
|
3
|
+
* Per-roster lifecycle lock for the `space-bus service` mutating verbs
|
|
4
|
+
* (install/start/stop/uninstall). Node-only lane, like `service.ts`.
|
|
5
|
+
*
|
|
6
|
+
* Distinct from `discovery.ts`'s daemon spawn lock (`spawn.lock`): that one
|
|
7
|
+
* serializes spawning the daemon; this one (`service.lock`) serializes the
|
|
8
|
+
* launchd lifecycle (print -> bootout -> plist write -> bootstrap -> verify).
|
|
9
|
+
*
|
|
10
|
+
* It deliberately does NOT reuse `acquireLock`/`releaseLock`:
|
|
11
|
+
* - `acquireLock` reclaims a dead owner's lock with read -> unlink -> create.
|
|
12
|
+
* Two contenders can both read the same dead lock; the slower one then
|
|
13
|
+
* unlinks the faster one's NEW, live lock. Here reclaim runs under a short
|
|
14
|
+
* mutex and re-reads the lock to confirm it is unchanged before unlinking.
|
|
15
|
+
* - `releaseLock` unlinks unconditionally. Here release only unlinks a lock
|
|
16
|
+
* whose token is still ours.
|
|
17
|
+
* - `acquireLock` records an empty start time when `ps` fails and then treats
|
|
18
|
+
* that live owner as dead, treats any `kill(pid, 0)` error (including EPERM)
|
|
19
|
+
* as "dead", keys identity on `comm` (which can change) and reclaims an
|
|
20
|
+
* unparsable lock by age. Here, an owner is dead only when its pid is
|
|
21
|
+
* provably gone (ESRCH) or provably a different process (its start time is
|
|
22
|
+
* readable and differs); anything uncertain counts as live. A malformed or
|
|
23
|
+
* incomplete lock is NEVER reclaimed automatically: age is not evidence of
|
|
24
|
+
* death (a writer paused between create and write can resume later).
|
|
25
|
+
*
|
|
26
|
+
* Semantics: fail-fast (never waits), cross-process (an O_EXCL file under the
|
|
27
|
+
* roster's state dir), and not re-entrant (a second acquire in the same
|
|
28
|
+
* process is refused like any other contender; the verbs take it exactly once).
|
|
29
|
+
*
|
|
30
|
+
* Limitations: same-user trust boundary only; liveness is `kill -0` plus the
|
|
31
|
+
* process start time from `ps` (second granularity). A malformed lock, or a
|
|
32
|
+
* `service.lock.reclaim` left by a process that crashed inside the reclaim
|
|
33
|
+
* window, makes acquisition fail closed until an operator removes the file;
|
|
34
|
+
* automatic cleanup of either would be racy.
|
|
35
|
+
*/
|
|
36
|
+
export type ServiceLock = {
|
|
37
|
+
release: () => void;
|
|
38
|
+
};
|
|
39
|
+
export type AcquireResult = {
|
|
40
|
+
ok: true;
|
|
41
|
+
lock: ServiceLock;
|
|
42
|
+
} | {
|
|
43
|
+
ok: false;
|
|
44
|
+
error: string;
|
|
45
|
+
};
|
|
46
|
+
export declare function serviceLockPath(stateDir: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Process start time (`ps lstart`, second granularity) or null if it cannot be
|
|
49
|
+
* read. Start time only: unlike `comm` it cannot change while the process runs.
|
|
50
|
+
*/
|
|
51
|
+
export declare function processStartTime(pid: number): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Takes the roster's service lock, or fails fast. `stateDir` must already
|
|
54
|
+
* exist at 0700 (the caller hardens it). Never blocks, never steals a lock
|
|
55
|
+
* whose owner may be live, never reclaims a malformed lock, and reports I/O
|
|
56
|
+
* failures as `ok:false` rather than throwing.
|
|
57
|
+
*/
|
|
58
|
+
export declare function acquireServiceLock(stateDir: string): AcquireResult;
|
package/dist/service.d.ts
CHANGED
|
@@ -29,6 +29,12 @@ export interface ServiceDeps {
|
|
|
29
29
|
* exercise the default against the real filesystem.
|
|
30
30
|
*/
|
|
31
31
|
launchAgentsDir?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The uid the written plist must be owned by. Defaults to the process uid.
|
|
34
|
+
* Test seam only: lets a test exercise the foreign-owner refusal without
|
|
35
|
+
* privilege. Production callers leave it unset.
|
|
36
|
+
*/
|
|
37
|
+
plistOwnerUid?: number;
|
|
32
38
|
}
|
|
33
39
|
export type PlatformGate = {
|
|
34
40
|
ok: true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fro.bot/space-bus",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.2",
|
|
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",
|
|
@@ -70,11 +70,11 @@
|
|
|
70
70
|
"fixture": "bun run scripts/make-fixture.ts",
|
|
71
71
|
"version-changesets": "changeset version && bun install --lockfile-only",
|
|
72
72
|
"publish-changesets": "bun run build && changeset publish",
|
|
73
|
-
"prepublishOnly": "bun run build"
|
|
73
|
+
"prepublishOnly": "bun run typecheck && bun test && bun run build"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@modelcontextprotocol/sdk": "1.
|
|
77
|
-
"zod": "^4.
|
|
76
|
+
"@modelcontextprotocol/sdk": "1.32.2",
|
|
77
|
+
"zod": "^4.6.7"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"@opencode-ai/plugin": ">=1.17.13 <2"
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"devDependencies": {
|
|
83
83
|
"@biomejs/biome": "2.5.2",
|
|
84
84
|
"@changesets/cli": "2.31.1",
|
|
85
|
-
"@opencode-ai/plugin": "1.
|
|
86
|
-
"@types/bun": "1.
|
|
85
|
+
"@opencode-ai/plugin": "1.19.5",
|
|
86
|
+
"@types/bun": "1.4.4",
|
|
87
87
|
"typescript": "5.9.3"
|
|
88
88
|
}
|
|
89
89
|
}
|