@fro.bot/space-bus 0.4.0 → 0.6.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 +39 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +961 -0
- package/dist/config.d.ts +37 -34
- package/dist/config.js +425 -17
- package/dist/contract.d.ts +72 -1671
- package/dist/contract.js +49 -32
- package/dist/core.js +48 -33
- package/dist/discovery.d.ts +126 -0
- package/dist/index.js +817 -155
- package/dist/mcp.js +839 -170
- package/dist/server.d.ts +65 -0
- package/dist/server.js +816 -0
- package/dist/tools/shared.d.ts +2 -0
- package/package.json +9 -4
package/dist/config.d.ts
CHANGED
|
@@ -1,45 +1,42 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { BusContext } from "./contract";
|
|
3
|
+
export declare const managedServerConfigSchema: z.ZodObject<{
|
|
4
|
+
command: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
5
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
6
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
}, z.core.$strip>;
|
|
8
|
+
export type ManagedServerConfig = z.infer<typeof managedServerConfigSchema>;
|
|
9
|
+
/**
|
|
10
|
+
* Roster `server` block: exactly one of `baseUrl` (externally-managed,
|
|
11
|
+
* today's behavior) or `managed` (plugin-spawned lifecycle) must be
|
|
12
|
+
* present. Modeled as both-optional plus a superRefine (rather than a
|
|
13
|
+
* z.union of strict variants) so both/neither present yields one clear,
|
|
14
|
+
* actionable message instead of zod's generic union-mismatch error.
|
|
15
|
+
*/
|
|
16
|
+
export declare const serverConfigSchema: z.ZodObject<{
|
|
17
|
+
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
18
|
+
managed: z.ZodOptional<z.ZodObject<{
|
|
19
|
+
command: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
20
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
21
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
22
|
+
}, z.core.$strip>>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type ServerConfig = z.infer<typeof serverConfigSchema>;
|
|
3
25
|
export declare const manifestSchema: z.ZodObject<{
|
|
4
26
|
server: z.ZodObject<{
|
|
5
|
-
baseUrl: z.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
27
|
+
baseUrl: z.ZodOptional<z.ZodURL>;
|
|
28
|
+
managed: z.ZodOptional<z.ZodObject<{
|
|
29
|
+
command: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
30
|
+
cwd: z.ZodOptional<z.ZodString>;
|
|
31
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
32
|
+
}, z.core.$strip>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
11
34
|
projects: z.ZodArray<z.ZodObject<{
|
|
12
35
|
name: z.ZodString;
|
|
13
36
|
path: z.ZodString;
|
|
14
37
|
description: z.ZodString;
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
name: string;
|
|
18
|
-
description: string;
|
|
19
|
-
}, {
|
|
20
|
-
path: string;
|
|
21
|
-
name: string;
|
|
22
|
-
description: string;
|
|
23
|
-
}>, "many">;
|
|
24
|
-
}, "strip", z.ZodTypeAny, {
|
|
25
|
-
server: {
|
|
26
|
-
baseUrl: string;
|
|
27
|
-
};
|
|
28
|
-
projects: {
|
|
29
|
-
path: string;
|
|
30
|
-
name: string;
|
|
31
|
-
description: string;
|
|
32
|
-
}[];
|
|
33
|
-
}, {
|
|
34
|
-
server: {
|
|
35
|
-
baseUrl: string;
|
|
36
|
-
};
|
|
37
|
-
projects: {
|
|
38
|
-
path: string;
|
|
39
|
-
name: string;
|
|
40
|
-
description: string;
|
|
41
|
-
}[];
|
|
42
|
-
}>;
|
|
38
|
+
}, z.core.$strip>>;
|
|
39
|
+
}, z.core.$strip>;
|
|
43
40
|
export type Manifest = z.infer<typeof manifestSchema>;
|
|
44
41
|
export declare function expandHome(path: string): string;
|
|
45
42
|
/**
|
|
@@ -81,3 +78,9 @@ export declare function getCredentials(): {
|
|
|
81
78
|
* discriminated-union Result at the core boundary.
|
|
82
79
|
*/
|
|
83
80
|
export declare function loadContext(directory?: string): BusContext;
|
|
81
|
+
/**
|
|
82
|
+
* Cheap check for whether a roster is managed (spawn-eligible) vs.
|
|
83
|
+
* externally-managed (baseUrl) — reads the manifest once. Adapters use this
|
|
84
|
+
* to decide whether to call `ensureServer()` before `loadContext()`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function isManagedRoster(directory?: string): boolean;
|
package/dist/config.js
CHANGED
|
@@ -1,18 +1,407 @@
|
|
|
1
|
+
// src/contract.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var sessionSchema = z.looseObject({
|
|
4
|
+
id: z.string(),
|
|
5
|
+
directory: z.string().optional(),
|
|
6
|
+
title: z.string().optional()
|
|
7
|
+
});
|
|
8
|
+
var sessionListSchema = z.array(sessionSchema);
|
|
9
|
+
var sessionStatusMapSchema = z.record(z.string(), z.looseObject({ type: z.string() }));
|
|
10
|
+
var todoSchema = z.array(z.looseObject({
|
|
11
|
+
content: z.string(),
|
|
12
|
+
status: z.string(),
|
|
13
|
+
priority: z.string()
|
|
14
|
+
})).default([]);
|
|
15
|
+
var diffEntrySchema = z.looseObject({
|
|
16
|
+
file: z.string().optional(),
|
|
17
|
+
additions: z.number(),
|
|
18
|
+
deletions: z.number(),
|
|
19
|
+
status: z.string().optional()
|
|
20
|
+
});
|
|
21
|
+
var diffSchema = z.array(diffEntrySchema).default([]);
|
|
22
|
+
var vcsStatusEntrySchema = z.looseObject({
|
|
23
|
+
file: z.string(),
|
|
24
|
+
additions: z.number(),
|
|
25
|
+
deletions: z.number(),
|
|
26
|
+
status: z.string().optional()
|
|
27
|
+
});
|
|
28
|
+
var vcsStatusSchema = z.array(vcsStatusEntrySchema).default([]);
|
|
29
|
+
var turnDiffEntrySchema = diffEntrySchema;
|
|
30
|
+
var turnMessageSchema = z.looseObject({
|
|
31
|
+
info: z.looseObject({
|
|
32
|
+
role: z.string(),
|
|
33
|
+
summary: z.looseObject({
|
|
34
|
+
diffs: z.array(turnDiffEntrySchema).optional()
|
|
35
|
+
}).optional()
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
var turnMessageListSchema = z.array(turnMessageSchema);
|
|
39
|
+
var sessionSummarySchema = z.looseObject({
|
|
40
|
+
summary: z.looseObject({
|
|
41
|
+
diffs: z.array(turnDiffEntrySchema).optional()
|
|
42
|
+
}).optional()
|
|
43
|
+
});
|
|
44
|
+
var messagePartSchema = z.looseObject({
|
|
45
|
+
type: z.string(),
|
|
46
|
+
text: z.string().optional()
|
|
47
|
+
});
|
|
48
|
+
var messageEnvelopeSchema = z.looseObject({
|
|
49
|
+
info: z.looseObject({ role: z.string() }),
|
|
50
|
+
parts: z.array(messagePartSchema)
|
|
51
|
+
});
|
|
52
|
+
var messageListSchema = z.array(messageEnvelopeSchema);
|
|
53
|
+
var pendingQuestionEntrySchema = z.looseObject({
|
|
54
|
+
id: z.string(),
|
|
55
|
+
sessionID: z.string(),
|
|
56
|
+
questions: z.array(z.looseObject({
|
|
57
|
+
question: z.string().optional(),
|
|
58
|
+
options: z.array(z.looseObject({ label: z.string().optional() })).optional()
|
|
59
|
+
})).optional()
|
|
60
|
+
});
|
|
61
|
+
var pendingQuestionListSchema = z.array(pendingQuestionEntrySchema);
|
|
62
|
+
var questionEntrySchema = z.looseObject({
|
|
63
|
+
id: z.string(),
|
|
64
|
+
sessionID: z.string()
|
|
65
|
+
});
|
|
66
|
+
var questionListSchema = z.array(questionEntrySchema);
|
|
67
|
+
var LOOPBACK_HOSTS = new Set([
|
|
68
|
+
"127.0.0.1",
|
|
69
|
+
"::1",
|
|
70
|
+
"[::1]",
|
|
71
|
+
"localhost"
|
|
72
|
+
]);
|
|
73
|
+
var projectSchema = z.looseObject({
|
|
74
|
+
name: z.string(),
|
|
75
|
+
path: z.string(),
|
|
76
|
+
description: z.string(),
|
|
77
|
+
expandedPath: z.string(),
|
|
78
|
+
exists: z.boolean()
|
|
79
|
+
});
|
|
80
|
+
var rosterSchema = z.object({
|
|
81
|
+
server: z.object({ baseUrl: z.url() }),
|
|
82
|
+
projects: z.array(projectSchema)
|
|
83
|
+
});
|
|
84
|
+
var credentialsSchema = z.object({
|
|
85
|
+
username: z.string().optional(),
|
|
86
|
+
password: z.string().optional()
|
|
87
|
+
});
|
|
88
|
+
var busContextSchema = z.object({
|
|
89
|
+
roster: rosterSchema,
|
|
90
|
+
credentials: credentialsSchema.optional()
|
|
91
|
+
});
|
|
92
|
+
|
|
1
93
|
// src/config.ts
|
|
2
|
-
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
94
|
+
import { existsSync, readFileSync as readFileSync2, realpathSync } from "node:fs";
|
|
95
|
+
import { homedir as homedir2 } from "node:os";
|
|
96
|
+
import { join as join2 } from "node:path";
|
|
97
|
+
import { z as z3 } from "zod";
|
|
98
|
+
|
|
99
|
+
// src/discovery.ts
|
|
100
|
+
import { execFileSync } from "node:child_process";
|
|
101
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
102
|
+
import {
|
|
103
|
+
chmodSync,
|
|
104
|
+
closeSync,
|
|
105
|
+
constants as fsConstants,
|
|
106
|
+
mkdirSync,
|
|
107
|
+
openSync,
|
|
108
|
+
readFileSync,
|
|
109
|
+
renameSync,
|
|
110
|
+
statSync,
|
|
111
|
+
unlinkSync,
|
|
112
|
+
writeFileSync
|
|
113
|
+
} from "node:fs";
|
|
3
114
|
import { homedir } from "node:os";
|
|
4
115
|
import { join } from "node:path";
|
|
5
|
-
import { z } from "zod";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
116
|
+
import { z as z2 } from "zod";
|
|
117
|
+
function stateDirFor(rosterPath) {
|
|
118
|
+
const base = process.env["XDG_STATE_HOME"] ?? join(homedir(), ".local", "state");
|
|
119
|
+
const hash = createHash("sha256").update(rosterPath).digest("hex").slice(0, 16);
|
|
120
|
+
return join(base, "space-bus", hash);
|
|
121
|
+
}
|
|
122
|
+
function discoveryFilePath(rosterPath) {
|
|
123
|
+
return join(stateDirFor(rosterPath), "discovery.json");
|
|
124
|
+
}
|
|
125
|
+
function lockFilePath(rosterPath) {
|
|
126
|
+
return join(stateDirFor(rosterPath), "spawn.lock");
|
|
127
|
+
}
|
|
128
|
+
function logFilePath(rosterPath) {
|
|
129
|
+
return join(stateDirFor(rosterPath), "server.log");
|
|
130
|
+
}
|
|
131
|
+
var managedSpawnConfigSchema = z2.object({
|
|
132
|
+
command: z2.array(z2.string()).optional(),
|
|
133
|
+
cwd: z2.string().optional(),
|
|
134
|
+
port: z2.number().int().nonnegative().optional()
|
|
135
|
+
});
|
|
136
|
+
var discoveryFileSchema = z2.object({
|
|
137
|
+
port: z2.number().int().nonnegative(),
|
|
138
|
+
pid: z2.number().int().positive(),
|
|
139
|
+
identity: z2.string(),
|
|
140
|
+
password: z2.string(),
|
|
141
|
+
spawnConfig: managedSpawnConfigSchema,
|
|
142
|
+
baseUrl: z2.url()
|
|
143
|
+
});
|
|
144
|
+
function writeDiscovery(rosterPath, data) {
|
|
145
|
+
const dir = stateDirFor(rosterPath);
|
|
146
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
147
|
+
chmodSync(dir, 448);
|
|
148
|
+
const target = discoveryFilePath(rosterPath);
|
|
149
|
+
const tempPath = `${target}.tmp.${randomBytes(8).toString("hex")}`;
|
|
150
|
+
const fd = openSync(tempPath, fsConstants.O_EXCL | fsConstants.O_CREAT | fsConstants.O_WRONLY, 384);
|
|
151
|
+
try {
|
|
152
|
+
writeFileSync(fd, JSON.stringify(data));
|
|
153
|
+
} finally {
|
|
154
|
+
closeQuietly(fd);
|
|
155
|
+
}
|
|
156
|
+
renameSync(tempPath, target);
|
|
157
|
+
chmodSync(target, 384);
|
|
158
|
+
}
|
|
159
|
+
function readDiscovery(rosterPath) {
|
|
160
|
+
const target = discoveryFilePath(rosterPath);
|
|
161
|
+
let raw;
|
|
162
|
+
try {
|
|
163
|
+
raw = readFileSync(target, "utf8");
|
|
164
|
+
} catch {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
let json;
|
|
168
|
+
try {
|
|
169
|
+
json = JSON.parse(raw);
|
|
170
|
+
} catch {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
const parsed = discoveryFileSchema.safeParse(json);
|
|
174
|
+
return parsed.success ? parsed.data : null;
|
|
175
|
+
}
|
|
176
|
+
function removeDiscovery(rosterPath) {
|
|
177
|
+
try {
|
|
178
|
+
unlinkSync(discoveryFilePath(rosterPath));
|
|
179
|
+
} catch (err) {
|
|
180
|
+
if (!isEnoent(err))
|
|
181
|
+
throw err;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function loopbackOk(baseUrl) {
|
|
185
|
+
try {
|
|
186
|
+
const url = new URL(baseUrl);
|
|
187
|
+
return LOOPBACK_HOSTS.has(url.hostname);
|
|
188
|
+
} catch {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function attachLive(rosterPath) {
|
|
193
|
+
const discovery = readDiscovery(rosterPath);
|
|
194
|
+
if (!discovery)
|
|
195
|
+
return null;
|
|
196
|
+
if (!loopbackOk(discovery.baseUrl))
|
|
197
|
+
return null;
|
|
198
|
+
if (!verifyIdentity(discovery.pid, discovery.identity))
|
|
199
|
+
return null;
|
|
200
|
+
return {
|
|
201
|
+
baseUrl: discovery.baseUrl,
|
|
202
|
+
credentials: { username: "opencode", password: discovery.password },
|
|
203
|
+
pid: discovery.pid,
|
|
204
|
+
port: discovery.port
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
function captureIdentity(pid) {
|
|
208
|
+
try {
|
|
209
|
+
const out = execFileSync("ps", ["-p", String(pid), "-o", "lstart=,comm="], {
|
|
210
|
+
env: { ...process.env, LC_ALL: "C" },
|
|
211
|
+
encoding: "utf8"
|
|
212
|
+
});
|
|
213
|
+
const trimmed = out.trim();
|
|
214
|
+
return trimmed.length > 0 ? trimmed : null;
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
function isAlive(pid) {
|
|
220
|
+
try {
|
|
221
|
+
process.kill(pid, 0);
|
|
222
|
+
return true;
|
|
223
|
+
} catch {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function verifyIdentity(pid, storedIdentity) {
|
|
228
|
+
if (!isAlive(pid))
|
|
229
|
+
return false;
|
|
230
|
+
const current = captureIdentity(pid);
|
|
231
|
+
return current !== null && current === storedIdentity;
|
|
232
|
+
}
|
|
233
|
+
var lockFileSchema = z2.object({
|
|
234
|
+
pid: z2.number().int().positive(),
|
|
235
|
+
startTime: z2.string(),
|
|
236
|
+
since: z2.number()
|
|
237
|
+
});
|
|
238
|
+
var CORRUPT_LOCK_GRACE_MS = 2000;
|
|
239
|
+
function acquireLock(rosterPath) {
|
|
240
|
+
const dir = stateDirFor(rosterPath);
|
|
241
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
242
|
+
chmodSync(dir, 448);
|
|
243
|
+
const target = lockFilePath(rosterPath);
|
|
244
|
+
const identity = captureIdentity(process.pid) ?? "";
|
|
245
|
+
const lock = {
|
|
246
|
+
pid: process.pid,
|
|
247
|
+
startTime: identity,
|
|
248
|
+
since: Date.now()
|
|
249
|
+
};
|
|
250
|
+
if (tryCreateLockFile(target, lock)) {
|
|
251
|
+
return { rosterPath };
|
|
252
|
+
}
|
|
253
|
+
const existing = readLockFile(target);
|
|
254
|
+
if (existing) {
|
|
255
|
+
if (verifyIdentity(existing.pid, existing.startTime))
|
|
256
|
+
return null;
|
|
257
|
+
} else if (!isOlderThan(target, CORRUPT_LOCK_GRACE_MS)) {
|
|
258
|
+
return null;
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
unlinkSync(target);
|
|
262
|
+
} catch (err) {
|
|
263
|
+
if (!isEnoent(err))
|
|
264
|
+
throw err;
|
|
265
|
+
}
|
|
266
|
+
if (tryCreateLockFile(target, lock)) {
|
|
267
|
+
return { rosterPath };
|
|
268
|
+
}
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
function isOlderThan(path, ageMs) {
|
|
272
|
+
try {
|
|
273
|
+
return Date.now() - statSync(path).mtimeMs > ageMs;
|
|
274
|
+
} catch {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function releaseLock(handle) {
|
|
279
|
+
try {
|
|
280
|
+
unlinkSync(lockFilePath(handle.rosterPath));
|
|
281
|
+
} catch {}
|
|
282
|
+
}
|
|
283
|
+
function readLockFile(target) {
|
|
284
|
+
let raw;
|
|
285
|
+
try {
|
|
286
|
+
raw = readFileSync(target, "utf8");
|
|
287
|
+
} catch {
|
|
288
|
+
return null;
|
|
289
|
+
}
|
|
290
|
+
let json;
|
|
291
|
+
try {
|
|
292
|
+
json = JSON.parse(raw);
|
|
293
|
+
} catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
const parsed = lockFileSchema.safeParse(json);
|
|
297
|
+
return parsed.success ? parsed.data : null;
|
|
298
|
+
}
|
|
299
|
+
function tryCreateLockFile(target, lock) {
|
|
300
|
+
let fd;
|
|
301
|
+
try {
|
|
302
|
+
fd = openSync(target, fsConstants.O_EXCL | fsConstants.O_CREAT | fsConstants.O_WRONLY, 384);
|
|
303
|
+
} catch (err) {
|
|
304
|
+
if (isErrnoCode(err, "EEXIST"))
|
|
305
|
+
return false;
|
|
306
|
+
throw err;
|
|
307
|
+
}
|
|
308
|
+
try {
|
|
309
|
+
writeFileSync(fd, JSON.stringify(lock));
|
|
310
|
+
} finally {
|
|
311
|
+
closeQuietly(fd);
|
|
312
|
+
}
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
function isEnoent(err) {
|
|
316
|
+
return isErrnoCode(err, "ENOENT");
|
|
317
|
+
}
|
|
318
|
+
function isErrnoCode(err, code) {
|
|
319
|
+
return typeof err === "object" && err !== null && "code" in err && err.code === code;
|
|
320
|
+
}
|
|
321
|
+
function closeQuietly(fd) {
|
|
322
|
+
try {
|
|
323
|
+
closeSync(fd);
|
|
324
|
+
} catch {}
|
|
325
|
+
}
|
|
326
|
+
function provisionalFilePath(rosterPath) {
|
|
327
|
+
return join(stateDirFor(rosterPath), "spawn.provisional.json");
|
|
328
|
+
}
|
|
329
|
+
var provisionalFileSchema = z2.object({
|
|
330
|
+
pid: z2.number().int().positive(),
|
|
331
|
+
identity: z2.string(),
|
|
332
|
+
password: z2.string(),
|
|
333
|
+
since: z2.number()
|
|
334
|
+
});
|
|
335
|
+
function writeProvisional(rosterPath, data) {
|
|
336
|
+
const dir = stateDirFor(rosterPath);
|
|
337
|
+
mkdirSync(dir, { recursive: true, mode: 448 });
|
|
338
|
+
chmodSync(dir, 448);
|
|
339
|
+
const target = provisionalFilePath(rosterPath);
|
|
340
|
+
const fd = openSync(target, fsConstants.O_CREAT | fsConstants.O_WRONLY | fsConstants.O_TRUNC, 384);
|
|
341
|
+
try {
|
|
342
|
+
writeFileSync(fd, JSON.stringify(data));
|
|
343
|
+
} finally {
|
|
344
|
+
closeQuietly(fd);
|
|
345
|
+
}
|
|
346
|
+
chmodSync(target, 384);
|
|
347
|
+
}
|
|
348
|
+
function readProvisional(rosterPath) {
|
|
349
|
+
const target = provisionalFilePath(rosterPath);
|
|
350
|
+
let raw;
|
|
351
|
+
try {
|
|
352
|
+
raw = readFileSync(target, "utf8");
|
|
353
|
+
} catch {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
let json;
|
|
357
|
+
try {
|
|
358
|
+
json = JSON.parse(raw);
|
|
359
|
+
} catch {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
const parsed = provisionalFileSchema.safeParse(json);
|
|
363
|
+
return parsed.success ? parsed.data : null;
|
|
364
|
+
}
|
|
365
|
+
function removeProvisional(rosterPath) {
|
|
366
|
+
try {
|
|
367
|
+
unlinkSync(provisionalFilePath(rosterPath));
|
|
368
|
+
} catch {}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/config.ts
|
|
372
|
+
var managedServerConfigSchema = z3.object({
|
|
373
|
+
command: z3.array(z3.string()).optional(),
|
|
374
|
+
cwd: z3.string().optional(),
|
|
375
|
+
port: z3.number().int().nonnegative().optional()
|
|
376
|
+
});
|
|
377
|
+
var serverConfigSchema = z3.object({
|
|
378
|
+
baseUrl: z3.url().optional(),
|
|
379
|
+
managed: managedServerConfigSchema.optional()
|
|
380
|
+
}).superRefine((val, ctx) => {
|
|
381
|
+
const hasBaseUrl = val.baseUrl !== undefined;
|
|
382
|
+
const hasManaged = val.managed !== undefined;
|
|
383
|
+
if (hasBaseUrl && hasManaged) {
|
|
384
|
+
ctx.addIssue({
|
|
385
|
+
code: "custom",
|
|
386
|
+
message: "space-bus: roster's server block must specify exactly one of `baseUrl` or `managed`, not both"
|
|
387
|
+
});
|
|
388
|
+
} else if (!hasBaseUrl && !hasManaged) {
|
|
389
|
+
ctx.addIssue({
|
|
390
|
+
code: "custom",
|
|
391
|
+
message: "space-bus: roster's server block must specify one of `baseUrl` (externally-managed) or `managed` (plugin-spawned) — neither was present"
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
var manifestSchema = z3.object({
|
|
396
|
+
server: serverConfigSchema,
|
|
397
|
+
projects: z3.array(z3.object({
|
|
398
|
+
name: z3.string(),
|
|
399
|
+
path: z3.string(),
|
|
400
|
+
description: z3.string()
|
|
12
401
|
}))
|
|
13
402
|
});
|
|
14
403
|
function expandHome(path) {
|
|
15
|
-
return path.startsWith("~") ?
|
|
404
|
+
return path.startsWith("~") ? join2(homedir2(), path.slice(1)) : path;
|
|
16
405
|
}
|
|
17
406
|
function resolveRosterPath(directory) {
|
|
18
407
|
const override = process.env["SPACE_BUS_CONFIG"];
|
|
@@ -27,7 +416,7 @@ function resolveRosterPath(directory) {
|
|
|
27
416
|
return existsSync(expanded) ? realpathSync(expanded) : expanded;
|
|
28
417
|
}
|
|
29
418
|
if (directory) {
|
|
30
|
-
const candidate =
|
|
419
|
+
const candidate = join2(directory, "spacebus.json");
|
|
31
420
|
return existsSync(candidate) ? realpathSync(candidate) : candidate;
|
|
32
421
|
}
|
|
33
422
|
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");
|
|
@@ -36,7 +425,7 @@ function getRoster(directory) {
|
|
|
36
425
|
const manifestPath = resolveRosterPath(directory);
|
|
37
426
|
let raw;
|
|
38
427
|
try {
|
|
39
|
-
raw =
|
|
428
|
+
raw = readFileSync2(manifestPath, "utf8");
|
|
40
429
|
} catch (err) {
|
|
41
430
|
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)`);
|
|
42
431
|
}
|
|
@@ -50,11 +439,12 @@ function getRoster(directory) {
|
|
|
50
439
|
if (!parsed.success) {
|
|
51
440
|
throw new Error(`space-bus: roster at ${manifestPath} failed schema validation: ${parsed.error.message}`);
|
|
52
441
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
442
|
+
if (parsed.data.server.baseUrl !== undefined) {
|
|
443
|
+
const url = new URL(parsed.data.server.baseUrl);
|
|
444
|
+
const hostname = url.hostname;
|
|
445
|
+
if (!LOOPBACK_HOSTS.has(hostname)) {
|
|
446
|
+
throw new Error(`space-bus: spacebus.json baseUrl must point to localhost (got ${hostname}) — refusing to send credentials off-machine`);
|
|
447
|
+
}
|
|
58
448
|
}
|
|
59
449
|
return parsed.data;
|
|
60
450
|
}
|
|
@@ -72,17 +462,35 @@ function getCredentials() {
|
|
|
72
462
|
return { username, password };
|
|
73
463
|
}
|
|
74
464
|
function loadContext(directory) {
|
|
465
|
+
const rosterPath = resolveRosterPath(directory);
|
|
75
466
|
const manifest = getRoster(directory);
|
|
76
467
|
const projects = getProjects(manifest);
|
|
468
|
+
if (manifest.server.baseUrl === undefined) {
|
|
469
|
+
const live = attachLive(rosterPath);
|
|
470
|
+
if (!live) {
|
|
471
|
+
throw new Error(`space-bus: managed server not running for ${rosterPath} — call ensureServer() or run \`space-bus serve\``);
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
roster: { server: { baseUrl: live.baseUrl }, projects },
|
|
475
|
+
credentials: live.credentials
|
|
476
|
+
};
|
|
477
|
+
}
|
|
77
478
|
return {
|
|
78
|
-
roster: { server: manifest.server, projects },
|
|
479
|
+
roster: { server: { baseUrl: manifest.server.baseUrl }, projects },
|
|
79
480
|
credentials: getCredentials()
|
|
80
481
|
};
|
|
81
482
|
}
|
|
483
|
+
function isManagedRoster(directory) {
|
|
484
|
+
const manifest = getRoster(directory);
|
|
485
|
+
return manifest.server.managed !== undefined;
|
|
486
|
+
}
|
|
82
487
|
export {
|
|
488
|
+
serverConfigSchema,
|
|
83
489
|
resolveRosterPath,
|
|
84
490
|
manifestSchema,
|
|
491
|
+
managedServerConfigSchema,
|
|
85
492
|
loadContext,
|
|
493
|
+
isManagedRoster,
|
|
86
494
|
getRoster,
|
|
87
495
|
getProjects,
|
|
88
496
|
getCredentials,
|