@fro.bot/space-bus 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ type Ok<T> = {
2
+ ok: true;
3
+ } & T;
4
+ type Err = {
5
+ ok: false;
6
+ error: string;
7
+ };
8
+ export type Result<T> = Ok<T> | Err;
9
+ export interface AttachSeams {
10
+ /** Canonicalize an absolute path (realpath); null if it doesn't exist. */
11
+ realpath(path: string): Promise<string | null>;
12
+ /** Read a file as utf8; null if absent/unreadable. */
13
+ readTextFile(path: string): Promise<string | null>;
14
+ /** Read an env var; null if unset/empty. */
15
+ env(name: string): Promise<string | null>;
16
+ /** Absolute home dir (for the ~/.local/state default). */
17
+ homeDir(): Promise<string>;
18
+ }
19
+ export interface ResolvedManagedServer {
20
+ baseUrl: string;
21
+ credentials: {
22
+ username: "opencode";
23
+ password: string;
24
+ };
25
+ alive: true;
26
+ }
27
+ /** Pure posix path join — avoids node:path in a browser-safe module. */
28
+ export declare function posixJoin(...parts: string[]): string;
29
+ export declare function resolveManagedServer(workspaceDir: string, seams: AttachSeams): Promise<Result<ResolvedManagedServer>>;
30
+ export {};
package/dist/attach.js ADDED
@@ -0,0 +1,235 @@
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
+ function loopbackOk(baseUrl) {
74
+ try {
75
+ return LOOPBACK_HOSTS.has(new URL(baseUrl).hostname);
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
80
+ var projectSchema = z.looseObject({
81
+ name: z.string(),
82
+ path: z.string(),
83
+ description: z.string(),
84
+ expandedPath: z.string(),
85
+ exists: z.boolean()
86
+ });
87
+ var rosterSchema = z.object({
88
+ server: z.object({ baseUrl: z.url() }),
89
+ projects: z.array(projectSchema)
90
+ });
91
+ var credentialsSchema = z.object({
92
+ username: z.string().optional(),
93
+ password: z.string().optional()
94
+ });
95
+ var busContextSchema = z.object({
96
+ roster: rosterSchema,
97
+ credentials: credentialsSchema.optional()
98
+ });
99
+ var managedSpawnConfigSchema = z.object({
100
+ command: z.array(z.string()).optional(),
101
+ cwd: z.string().optional(),
102
+ port: z.number().int().nonnegative().optional()
103
+ });
104
+ var discoveryFileSchema = z.object({
105
+ port: z.number().int().nonnegative(),
106
+ pid: z.number().int().positive(),
107
+ identity: z.string(),
108
+ password: z.string(),
109
+ spawnConfig: managedSpawnConfigSchema,
110
+ baseUrl: z.url()
111
+ });
112
+
113
+ // src/attach.ts
114
+ function err(error) {
115
+ return { ok: false, error };
116
+ }
117
+ function posixJoin(...parts) {
118
+ const isAbsolute = (parts[0] ?? "").startsWith("/");
119
+ const segments = [];
120
+ for (const part of parts) {
121
+ for (const segment of part.split("/")) {
122
+ if (segment.length > 0)
123
+ segments.push(segment);
124
+ }
125
+ }
126
+ const joined = segments.join("/");
127
+ return isAbsolute ? `/${joined}` : joined;
128
+ }
129
+ async function sha256Hex16(input) {
130
+ const bytes = new TextEncoder().encode(input);
131
+ const digest = await crypto.subtle.digest("SHA-256", bytes);
132
+ const hex = Array.from(new Uint8Array(digest)).map((b) => b.toString(16).padStart(2, "0")).join("");
133
+ return hex.slice(0, 16);
134
+ }
135
+ function toBase64(s) {
136
+ const bytes = new TextEncoder().encode(s);
137
+ let bin = "";
138
+ for (const b of bytes)
139
+ bin += String.fromCharCode(b);
140
+ return btoa(bin);
141
+ }
142
+ function authHeader(password) {
143
+ const token = toBase64(`opencode:${password}`);
144
+ return { Authorization: `Basic ${token}` };
145
+ }
146
+ async function resolveRosterPath(workspaceDir, seams) {
147
+ const override = await seams.env("SPACE_BUS_CONFIG");
148
+ let candidate;
149
+ if (override) {
150
+ if (override.includes("://")) {
151
+ return err(`space-bus: SPACE_BUS_CONFIG needs an absolute filesystem path or a ~-prefixed path, not a URL (got: ${override})`);
152
+ }
153
+ const expanded = override.startsWith("~/") ? posixJoin(await seams.homeDir(), override.slice(2)) : override;
154
+ if (!expanded.startsWith("/")) {
155
+ return err(`space-bus: SPACE_BUS_CONFIG needs an absolute filesystem path or a ~-prefixed path (got: ${override})`);
156
+ }
157
+ candidate = expanded;
158
+ } else {
159
+ candidate = posixJoin(workspaceDir, "spacebus.json");
160
+ }
161
+ const canonical = await seams.realpath(candidate);
162
+ if (canonical === null) {
163
+ return err(`space-bus: no spacebus.json at ${candidate}`);
164
+ }
165
+ return { ok: true, rosterPath: canonical };
166
+ }
167
+ async function discoveryPathFor(rosterPath, seams) {
168
+ const xdgStateHome = await seams.env("XDG_STATE_HOME");
169
+ const base = xdgStateHome ?? posixJoin(await seams.homeDir(), ".local", "state");
170
+ const hash = await sha256Hex16(rosterPath);
171
+ return posixJoin(base, "space-bus", hash, "discovery.json");
172
+ }
173
+ async function resolveManagedServer(workspaceDir, seams) {
174
+ const rosterResult = await resolveRosterPath(workspaceDir, seams);
175
+ if (!rosterResult.ok)
176
+ return rosterResult;
177
+ const { rosterPath } = rosterResult;
178
+ const discoveryPath = await discoveryPathFor(rosterPath, seams);
179
+ const raw = await seams.readTextFile(discoveryPath);
180
+ if (raw === null) {
181
+ return err("space-bus: managed space-bus server is not running for this workspace (no discovery file) — run `space-bus serve` in the workspace (or use a space-bus tool in an opencode session)");
182
+ }
183
+ let json;
184
+ try {
185
+ json = JSON.parse(raw);
186
+ } catch (e) {
187
+ return err(`space-bus: discovery file at ${discoveryPath} is not valid JSON: ${e.message}`);
188
+ }
189
+ const parsed = discoveryFileSchema.safeParse(json);
190
+ if (!parsed.success) {
191
+ return err(`space-bus: discovery file at ${discoveryPath} failed schema validation: ${parsed.error.message}`);
192
+ }
193
+ const discovery = parsed.data;
194
+ if (!loopbackOk(discovery.baseUrl)) {
195
+ const host = (() => {
196
+ try {
197
+ return new URL(discovery.baseUrl).hostname;
198
+ } catch {
199
+ return discovery.baseUrl;
200
+ }
201
+ })();
202
+ return err(`space-bus: refusing to send credentials off-machine (got ${host})`);
203
+ }
204
+ const probe = await probeLiveness(discovery.baseUrl, discovery.password);
205
+ if (!probe.ok)
206
+ return probe;
207
+ return {
208
+ ok: true,
209
+ baseUrl: discovery.baseUrl,
210
+ credentials: { username: "opencode", password: discovery.password },
211
+ alive: true
212
+ };
213
+ }
214
+ async function probeLiveness(baseUrl, password) {
215
+ let res;
216
+ try {
217
+ res = await fetch(`${baseUrl}/session?limit=1`, {
218
+ headers: authHeader(password),
219
+ signal: AbortSignal.timeout(3000)
220
+ });
221
+ } catch {
222
+ return err(`space-bus: managed daemon not answering at ${baseUrl} — it may have exited; run \`space-bus serve\` in the workspace to restart it`);
223
+ }
224
+ if (res.status === 401) {
225
+ return err("space-bus: managed server rejected credentials (stale discovery?) — restart the workspace daemon");
226
+ }
227
+ if (!res.ok) {
228
+ return err(`space-bus: managed daemon not answering at ${baseUrl} — it may have exited; run \`space-bus serve\` in the workspace to restart it`);
229
+ }
230
+ return { ok: true };
231
+ }
232
+ export {
233
+ resolveManagedServer,
234
+ posixJoin
235
+ };
package/dist/cli.js CHANGED
@@ -71,6 +71,13 @@ var LOOPBACK_HOSTS = new Set([
71
71
  "[::1]",
72
72
  "localhost"
73
73
  ]);
74
+ function loopbackOk(baseUrl) {
75
+ try {
76
+ return LOOPBACK_HOSTS.has(new URL(baseUrl).hostname);
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
74
81
  var projectSchema = z.looseObject({
75
82
  name: z.string(),
76
83
  path: z.string(),
@@ -90,6 +97,19 @@ var busContextSchema = z.object({
90
97
  roster: rosterSchema,
91
98
  credentials: credentialsSchema.optional()
92
99
  });
100
+ var managedSpawnConfigSchema = z.object({
101
+ command: z.array(z.string()).optional(),
102
+ cwd: z.string().optional(),
103
+ port: z.number().int().nonnegative().optional()
104
+ });
105
+ var discoveryFileSchema = z.object({
106
+ port: z.number().int().nonnegative(),
107
+ pid: z.number().int().positive(),
108
+ identity: z.string(),
109
+ password: z.string(),
110
+ spawnConfig: managedSpawnConfigSchema,
111
+ baseUrl: z.url()
112
+ });
93
113
 
94
114
  // src/config.ts
95
115
  import { existsSync, readFileSync as readFileSync2, realpathSync } from "node:fs";
@@ -129,19 +149,6 @@ function lockFilePath(rosterPath) {
129
149
  function logFilePath(rosterPath) {
130
150
  return join(stateDirFor(rosterPath), "server.log");
131
151
  }
132
- var managedSpawnConfigSchema = z2.object({
133
- command: z2.array(z2.string()).optional(),
134
- cwd: z2.string().optional(),
135
- port: z2.number().int().nonnegative().optional()
136
- });
137
- var discoveryFileSchema = z2.object({
138
- port: z2.number().int().nonnegative(),
139
- pid: z2.number().int().positive(),
140
- identity: z2.string(),
141
- password: z2.string(),
142
- spawnConfig: managedSpawnConfigSchema,
143
- baseUrl: z2.url()
144
- });
145
152
  function writeDiscovery(rosterPath, data) {
146
153
  const dir = stateDirFor(rosterPath);
147
154
  mkdirSync(dir, { recursive: true, mode: 448 });
@@ -182,14 +189,6 @@ function removeDiscovery(rosterPath) {
182
189
  throw err;
183
190
  }
184
191
  }
185
- function loopbackOk(baseUrl) {
186
- try {
187
- const url = new URL(baseUrl);
188
- return LOOPBACK_HOSTS.has(url.hostname);
189
- } catch {
190
- return false;
191
- }
192
- }
193
192
  function attachLive(rosterPath) {
194
193
  const discovery = readDiscovery(rosterPath);
195
194
  if (!discovery)
package/dist/config.js CHANGED
@@ -70,6 +70,13 @@ var LOOPBACK_HOSTS = new Set([
70
70
  "[::1]",
71
71
  "localhost"
72
72
  ]);
73
+ function loopbackOk(baseUrl) {
74
+ try {
75
+ return LOOPBACK_HOSTS.has(new URL(baseUrl).hostname);
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
73
80
  var projectSchema = z.looseObject({
74
81
  name: z.string(),
75
82
  path: z.string(),
@@ -89,6 +96,19 @@ var busContextSchema = z.object({
89
96
  roster: rosterSchema,
90
97
  credentials: credentialsSchema.optional()
91
98
  });
99
+ var managedSpawnConfigSchema = z.object({
100
+ command: z.array(z.string()).optional(),
101
+ cwd: z.string().optional(),
102
+ port: z.number().int().nonnegative().optional()
103
+ });
104
+ var discoveryFileSchema = z.object({
105
+ port: z.number().int().nonnegative(),
106
+ pid: z.number().int().positive(),
107
+ identity: z.string(),
108
+ password: z.string(),
109
+ spawnConfig: managedSpawnConfigSchema,
110
+ baseUrl: z.url()
111
+ });
92
112
 
93
113
  // src/config.ts
94
114
  import { existsSync, readFileSync as readFileSync2, realpathSync } from "node:fs";
@@ -128,19 +148,6 @@ function lockFilePath(rosterPath) {
128
148
  function logFilePath(rosterPath) {
129
149
  return join(stateDirFor(rosterPath), "server.log");
130
150
  }
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
151
  function writeDiscovery(rosterPath, data) {
145
152
  const dir = stateDirFor(rosterPath);
146
153
  mkdirSync(dir, { recursive: true, mode: 448 });
@@ -181,14 +188,6 @@ function removeDiscovery(rosterPath) {
181
188
  throw err;
182
189
  }
183
190
  }
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
191
  function attachLive(rosterPath) {
193
192
  const discovery = readDiscovery(rosterPath);
194
193
  if (!discovery)
@@ -159,6 +159,13 @@ export declare const questionListSchema: z.ZodArray<z.ZodObject<{
159
159
  }, z.core.$loose>>;
160
160
  export type QuestionListSchema = z.infer<typeof questionListSchema>;
161
161
  export declare const LOOPBACK_HOSTS: Set<string>;
162
+ /**
163
+ * Shared loopback-hostname check, used identically by attach.ts (browser-safe
164
+ * reader) and discovery.ts (Node-only writer/re-validator) — both need the
165
+ * exact same `new URL(baseUrl).hostname` + LOOPBACK_HOSTS membership check,
166
+ * so it lives here once rather than duplicated in each.
167
+ */
168
+ export declare function loopbackOk(baseUrl: string): boolean;
162
169
  export declare const projectSchema: z.ZodObject<{
163
170
  name: z.ZodString;
164
171
  path: z.ZodString;
@@ -213,3 +220,20 @@ export declare const busContextSchema: z.ZodObject<{
213
220
  }, z.core.$strip>>;
214
221
  }, z.core.$strip>;
215
222
  export type BusContext = z.infer<typeof busContextSchema>;
223
+ export declare const managedSpawnConfigSchema: z.ZodObject<{
224
+ command: z.ZodOptional<z.ZodArray<z.ZodString>>;
225
+ cwd: z.ZodOptional<z.ZodString>;
226
+ port: z.ZodOptional<z.ZodNumber>;
227
+ }, z.core.$strip>;
228
+ export declare const discoveryFileSchema: z.ZodObject<{
229
+ port: z.ZodNumber;
230
+ pid: z.ZodNumber;
231
+ identity: z.ZodString;
232
+ password: z.ZodString;
233
+ spawnConfig: z.ZodObject<{
234
+ command: z.ZodOptional<z.ZodArray<z.ZodString>>;
235
+ cwd: z.ZodOptional<z.ZodString>;
236
+ port: z.ZodOptional<z.ZodNumber>;
237
+ }, z.core.$strip>;
238
+ baseUrl: z.ZodURL;
239
+ }, z.core.$strip>;
package/dist/contract.js CHANGED
@@ -70,6 +70,13 @@ var LOOPBACK_HOSTS = new Set([
70
70
  "[::1]",
71
71
  "localhost"
72
72
  ]);
73
+ function loopbackOk(baseUrl) {
74
+ try {
75
+ return LOOPBACK_HOSTS.has(new URL(baseUrl).hostname);
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
73
80
  var projectSchema = z.looseObject({
74
81
  name: z.string(),
75
82
  path: z.string(),
@@ -89,6 +96,19 @@ var busContextSchema = z.object({
89
96
  roster: rosterSchema,
90
97
  credentials: credentialsSchema.optional()
91
98
  });
99
+ var managedSpawnConfigSchema = z.object({
100
+ command: z.array(z.string()).optional(),
101
+ cwd: z.string().optional(),
102
+ port: z.number().int().nonnegative().optional()
103
+ });
104
+ var discoveryFileSchema = z.object({
105
+ port: z.number().int().nonnegative(),
106
+ pid: z.number().int().positive(),
107
+ identity: z.string(),
108
+ password: z.string(),
109
+ spawnConfig: managedSpawnConfigSchema,
110
+ baseUrl: z.url()
111
+ });
92
112
  export {
93
113
  vcsStatusSchema,
94
114
  vcsStatusEntrySchema,
@@ -109,6 +129,9 @@ export {
109
129
  messagePartSchema,
110
130
  messageListSchema,
111
131
  messageEnvelopeSchema,
132
+ managedSpawnConfigSchema,
133
+ loopbackOk,
134
+ discoveryFileSchema,
112
135
  diffSchema,
113
136
  diffEntrySchema,
114
137
  credentialsSchema,
package/dist/core.js CHANGED
@@ -70,6 +70,13 @@ var LOOPBACK_HOSTS = new Set([
70
70
  "[::1]",
71
71
  "localhost"
72
72
  ]);
73
+ function loopbackOk(baseUrl) {
74
+ try {
75
+ return LOOPBACK_HOSTS.has(new URL(baseUrl).hostname);
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
73
80
  var projectSchema = z.looseObject({
74
81
  name: z.string(),
75
82
  path: z.string(),
@@ -89,6 +96,19 @@ var busContextSchema = z.object({
89
96
  roster: rosterSchema,
90
97
  credentials: credentialsSchema.optional()
91
98
  });
99
+ var managedSpawnConfigSchema = z.object({
100
+ command: z.array(z.string()).optional(),
101
+ cwd: z.string().optional(),
102
+ port: z.number().int().nonnegative().optional()
103
+ });
104
+ var discoveryFileSchema = z.object({
105
+ port: z.number().int().nonnegative(),
106
+ pid: z.number().int().positive(),
107
+ identity: z.string(),
108
+ password: z.string(),
109
+ spawnConfig: managedSpawnConfigSchema,
110
+ baseUrl: z.url()
111
+ });
92
112
 
93
113
  // src/core.ts
94
114
  function findProject(projects, name) {
@@ -1,4 +1,6 @@
1
1
  import { z } from "zod";
2
+ import { discoveryFileSchema, loopbackOk, managedSpawnConfigSchema } from "./contract";
3
+ export { discoveryFileSchema, managedSpawnConfigSchema };
2
4
  /**
3
5
  * Per-roster state directory: `$XDG_STATE_HOME|~/.local/state`/
4
6
  * `space-bus/<first 16 hex of sha256(absolute roster path)>/`. Keying by a
@@ -9,23 +11,6 @@ export declare function stateDirFor(rosterPath: string): string;
9
11
  export declare function discoveryFilePath(rosterPath: string): string;
10
12
  export declare function lockFilePath(rosterPath: string): string;
11
13
  export declare function logFilePath(rosterPath: string): string;
12
- export declare const managedSpawnConfigSchema: z.ZodObject<{
13
- command: z.ZodOptional<z.ZodArray<z.ZodString>>;
14
- cwd: z.ZodOptional<z.ZodString>;
15
- port: z.ZodOptional<z.ZodNumber>;
16
- }, z.core.$strip>;
17
- export declare const discoveryFileSchema: z.ZodObject<{
18
- port: z.ZodNumber;
19
- pid: z.ZodNumber;
20
- identity: z.ZodString;
21
- password: z.ZodString;
22
- spawnConfig: z.ZodObject<{
23
- command: z.ZodOptional<z.ZodArray<z.ZodString>>;
24
- cwd: z.ZodOptional<z.ZodString>;
25
- port: z.ZodOptional<z.ZodNumber>;
26
- }, z.core.$strip>;
27
- baseUrl: z.ZodURL;
28
- }, z.core.$strip>;
29
14
  export type DiscoveryFile = z.infer<typeof discoveryFileSchema>;
30
15
  /**
31
16
  * Writes the discovery file atomically: a temp file (0600) in the same
@@ -37,7 +22,7 @@ export declare function writeDiscovery(rosterPath: string, data: DiscoveryFile):
37
22
  /** Reads and validates the discovery file; returns null if absent or corrupt. */
38
23
  export declare function readDiscovery(rosterPath: string): DiscoveryFile | null;
39
24
  export declare function removeDiscovery(rosterPath: string): void;
40
- export declare function loopbackOk(baseUrl: string): boolean;
25
+ export { loopbackOk };
41
26
  export interface LiveEndpoint {
42
27
  baseUrl: string;
43
28
  credentials: {
package/dist/index.js CHANGED
@@ -70,6 +70,13 @@ var LOOPBACK_HOSTS = new Set([
70
70
  "[::1]",
71
71
  "localhost"
72
72
  ]);
73
+ function loopbackOk(baseUrl) {
74
+ try {
75
+ return LOOPBACK_HOSTS.has(new URL(baseUrl).hostname);
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
73
80
  var projectSchema = z.looseObject({
74
81
  name: z.string(),
75
82
  path: z.string(),
@@ -89,6 +96,19 @@ var busContextSchema = z.object({
89
96
  roster: rosterSchema,
90
97
  credentials: credentialsSchema.optional()
91
98
  });
99
+ var managedSpawnConfigSchema = z.object({
100
+ command: z.array(z.string()).optional(),
101
+ cwd: z.string().optional(),
102
+ port: z.number().int().nonnegative().optional()
103
+ });
104
+ var discoveryFileSchema = z.object({
105
+ port: z.number().int().nonnegative(),
106
+ pid: z.number().int().positive(),
107
+ identity: z.string(),
108
+ password: z.string(),
109
+ spawnConfig: managedSpawnConfigSchema,
110
+ baseUrl: z.url()
111
+ });
92
112
 
93
113
  // src/core.ts
94
114
  function findProject(projects, name) {
@@ -713,19 +733,6 @@ function lockFilePath(rosterPath) {
713
733
  function logFilePath(rosterPath) {
714
734
  return join(stateDirFor(rosterPath), "server.log");
715
735
  }
716
- var managedSpawnConfigSchema = z2.object({
717
- command: z2.array(z2.string()).optional(),
718
- cwd: z2.string().optional(),
719
- port: z2.number().int().nonnegative().optional()
720
- });
721
- var discoveryFileSchema = z2.object({
722
- port: z2.number().int().nonnegative(),
723
- pid: z2.number().int().positive(),
724
- identity: z2.string(),
725
- password: z2.string(),
726
- spawnConfig: managedSpawnConfigSchema,
727
- baseUrl: z2.url()
728
- });
729
736
  function writeDiscovery(rosterPath, data) {
730
737
  const dir = stateDirFor(rosterPath);
731
738
  mkdirSync(dir, { recursive: true, mode: 448 });
@@ -766,14 +773,6 @@ function removeDiscovery(rosterPath) {
766
773
  throw err2;
767
774
  }
768
775
  }
769
- function loopbackOk(baseUrl) {
770
- try {
771
- const url = new URL(baseUrl);
772
- return LOOPBACK_HOSTS.has(url.hostname);
773
- } catch {
774
- return false;
775
- }
776
- }
777
776
  function attachLive(rosterPath) {
778
777
  const discovery = readDiscovery(rosterPath);
779
778
  if (!discovery)
package/dist/mcp.js CHANGED
@@ -71,6 +71,13 @@ var LOOPBACK_HOSTS = new Set([
71
71
  "[::1]",
72
72
  "localhost"
73
73
  ]);
74
+ function loopbackOk(baseUrl) {
75
+ try {
76
+ return LOOPBACK_HOSTS.has(new URL(baseUrl).hostname);
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
74
81
  var projectSchema = z.looseObject({
75
82
  name: z.string(),
76
83
  path: z.string(),
@@ -90,6 +97,19 @@ var busContextSchema = z.object({
90
97
  roster: rosterSchema,
91
98
  credentials: credentialsSchema.optional()
92
99
  });
100
+ var managedSpawnConfigSchema = z.object({
101
+ command: z.array(z.string()).optional(),
102
+ cwd: z.string().optional(),
103
+ port: z.number().int().nonnegative().optional()
104
+ });
105
+ var discoveryFileSchema = z.object({
106
+ port: z.number().int().nonnegative(),
107
+ pid: z.number().int().positive(),
108
+ identity: z.string(),
109
+ password: z.string(),
110
+ spawnConfig: managedSpawnConfigSchema,
111
+ baseUrl: z.url()
112
+ });
93
113
 
94
114
  // src/core.ts
95
115
  function findProject(projects, name) {
@@ -714,19 +734,6 @@ function lockFilePath(rosterPath) {
714
734
  function logFilePath(rosterPath) {
715
735
  return join(stateDirFor(rosterPath), "server.log");
716
736
  }
717
- var managedSpawnConfigSchema = z2.object({
718
- command: z2.array(z2.string()).optional(),
719
- cwd: z2.string().optional(),
720
- port: z2.number().int().nonnegative().optional()
721
- });
722
- var discoveryFileSchema = z2.object({
723
- port: z2.number().int().nonnegative(),
724
- pid: z2.number().int().positive(),
725
- identity: z2.string(),
726
- password: z2.string(),
727
- spawnConfig: managedSpawnConfigSchema,
728
- baseUrl: z2.url()
729
- });
730
737
  function writeDiscovery(rosterPath, data) {
731
738
  const dir = stateDirFor(rosterPath);
732
739
  mkdirSync(dir, { recursive: true, mode: 448 });
@@ -767,14 +774,6 @@ function removeDiscovery(rosterPath) {
767
774
  throw err2;
768
775
  }
769
776
  }
770
- function loopbackOk(baseUrl) {
771
- try {
772
- const url = new URL(baseUrl);
773
- return LOOPBACK_HOSTS.has(url.hostname);
774
- } catch {
775
- return false;
776
- }
777
- }
778
777
  function attachLive(rosterPath) {
779
778
  const discovery = readDiscovery(rosterPath);
780
779
  if (!discovery)
@@ -1522,7 +1521,7 @@ async function mcpLoadContext() {
1522
1521
  }
1523
1522
  return loadContext();
1524
1523
  }
1525
- var version = "0.6.0";
1524
+ var version = "0.7.0";
1526
1525
  var server = new McpServer({
1527
1526
  name: "space-bus",
1528
1527
  version
package/dist/server.js CHANGED
@@ -70,6 +70,13 @@ var LOOPBACK_HOSTS = new Set([
70
70
  "[::1]",
71
71
  "localhost"
72
72
  ]);
73
+ function loopbackOk(baseUrl) {
74
+ try {
75
+ return LOOPBACK_HOSTS.has(new URL(baseUrl).hostname);
76
+ } catch {
77
+ return false;
78
+ }
79
+ }
73
80
  var projectSchema = z.looseObject({
74
81
  name: z.string(),
75
82
  path: z.string(),
@@ -89,6 +96,19 @@ var busContextSchema = z.object({
89
96
  roster: rosterSchema,
90
97
  credentials: credentialsSchema.optional()
91
98
  });
99
+ var managedSpawnConfigSchema = z.object({
100
+ command: z.array(z.string()).optional(),
101
+ cwd: z.string().optional(),
102
+ port: z.number().int().nonnegative().optional()
103
+ });
104
+ var discoveryFileSchema = z.object({
105
+ port: z.number().int().nonnegative(),
106
+ pid: z.number().int().positive(),
107
+ identity: z.string(),
108
+ password: z.string(),
109
+ spawnConfig: managedSpawnConfigSchema,
110
+ baseUrl: z.url()
111
+ });
92
112
 
93
113
  // src/config.ts
94
114
  import { existsSync, readFileSync as readFileSync2, realpathSync } from "node:fs";
@@ -128,19 +148,6 @@ function lockFilePath(rosterPath) {
128
148
  function logFilePath(rosterPath) {
129
149
  return join(stateDirFor(rosterPath), "server.log");
130
150
  }
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
151
  function writeDiscovery(rosterPath, data) {
145
152
  const dir = stateDirFor(rosterPath);
146
153
  mkdirSync(dir, { recursive: true, mode: 448 });
@@ -181,14 +188,6 @@ function removeDiscovery(rosterPath) {
181
188
  throw err;
182
189
  }
183
190
  }
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
191
  function attachLive(rosterPath) {
193
192
  const discovery = readDiscovery(rosterPath);
194
193
  if (!discovery)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fro.bot/space-bus",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Space Bus — workspace agent bus for OpenCode. One control agent tasking per-project agents over the OpenCode server API, with an MCP facade for Claude Desktop.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -31,6 +31,10 @@
31
31
  "./server": {
32
32
  "types": "./dist/server.d.ts",
33
33
  "import": "./dist/server.js"
34
+ },
35
+ "./attach": {
36
+ "types": "./dist/attach.d.ts",
37
+ "import": "./dist/attach.js"
34
38
  }
35
39
  },
36
40
  "bin": {
@@ -48,7 +52,7 @@
48
52
  "scripts": {
49
53
  "clean": "rm -rf dist",
50
54
  "build": "bun run clean && bun run build.ts && tsc -p tsconfig.build.json --emitDeclarationOnly",
51
- "dev": "bun build ./src/index.ts ./src/mcp.ts ./src/cli.ts ./src/core.ts ./src/config.ts ./src/contract.ts ./src/format.ts ./src/server.ts --outdir dist --target node --external @opencode-ai/plugin --external @modelcontextprotocol/sdk --external zod --watch",
55
+ "dev": "bun build ./src/index.ts ./src/mcp.ts ./src/cli.ts ./src/core.ts ./src/config.ts ./src/contract.ts ./src/format.ts ./src/server.ts --outdir dist --target node --external @opencode-ai/plugin --external @modelcontextprotocol/sdk --external zod --watch & bun build ./src/attach.ts --outdir dist --target node --external @opencode-ai/plugin --external @modelcontextprotocol/sdk --external zod --watch & wait",
52
56
  "typecheck": "tsc --noEmit",
53
57
  "lint": "biome check .",
54
58
  "fix": "biome check --write .",