@fro.bot/space-bus 0.0.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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ # The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Marcus R. Brown <contact@marcusrbrown.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # @fro.bot/space-bus
2
+
3
+ Workspace agent bus for OpenCode. A control agent — an ordinary OpenCode TUI running with this plugin installed — tasks dedicated agents in each project on your roster over a single `opencode serve`/`harness serve` instance, using per-request directory routing. A thin stdio MCP facade exposes the same tools to Claude Desktop.
4
+
5
+ ## Install
6
+
7
+ ```json
8
+ {
9
+ "plugin": ["@fro.bot/space-bus"]
10
+ }
11
+ ```
12
+
13
+ For local development, reference the checkout by file path instead:
14
+
15
+ ```json
16
+ {
17
+ "plugin": ["/absolute/path/to/space-bus"]
18
+ }
19
+ ```
20
+
21
+ ## Configure
22
+
23
+ Space Bus reads a `spacebus.json` roster from the workspace directory (the directory OpenCode was launched in):
24
+
25
+ ```json
26
+ {
27
+ "server": {
28
+ "baseUrl": "http://127.0.0.1:4096"
29
+ },
30
+ "projects": [
31
+ {
32
+ "name": "agent",
33
+ "path": "~/src/github.com/fro-bot/agent",
34
+ "description": "Fro Bot agent runtime + gateway + Discord integration"
35
+ }
36
+ ]
37
+ }
38
+ ```
39
+
40
+ `server.baseUrl` must point to localhost (`127.0.0.1`, `::1`, or `localhost`) — non-local hosts are refused so bus credentials never leave the machine. Project `path` entries support `~` expansion.
41
+
42
+ Set `SPACE_BUS_CONFIG` to an absolute or `~`-prefixed path to override roster discovery (URLs and bare-relative paths are rejected). The roster is read fresh on every tool call — no caching, so edits apply immediately.
43
+
44
+ ## Tools
45
+
46
+ - `bus_roster` — List the space-bus manifest projects with live session status per project.
47
+ - `bus_task` — Dispatch a prompt to an agent in the given space-bus manifest project, or steer an existing session by passing `sessionId` (answers its pending question, else sends a follow-up prompt). Returns immediately; does not wait for completion.
48
+ - `bus_status` — Report a space-bus session's status plus a summary of its latest todo and diff. Also reports when the session is blocked on an interactive question awaiting a reply.
49
+ - `bus_result` — Return a completed space-bus session's final assistant message and diff. Errors if the session is still running — use `bus_status` to check first.
50
+
51
+ ## Claude Desktop
52
+
53
+ ```json
54
+ {
55
+ "mcpServers": {
56
+ "space-bus": {
57
+ "command": "bunx",
58
+ "args": ["--package=@fro.bot/space-bus", "space-bus-mcp"],
59
+ "env": {
60
+ "SPACE_BUS_CONFIG": "/absolute/path/to/spacebus.json"
61
+ }
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ Requires `opencode serve`/`harness serve` already running on the roster's `baseUrl`.
68
+
69
+ ## Development
70
+
71
+ ```sh
72
+ bun install
73
+ bun run fixture # generates gitignored fixtures/dev-workspace/ (opencode.json + spacebus.json)
74
+ harness serve --port 4096 & # or: opencode serve --port 4096
75
+ opencode --dir fixtures/dev-workspace # or open that directory directly
76
+ bun run smoke # canary: directory-routing isolation against the live server
77
+ bun run test
78
+ bun run typecheck
79
+ bun run lint
80
+ bun run dev # watch build to dist/
81
+ ```
82
+
83
+ `@opencode-ai/*` versions are pinned lockstep with the OpenCode CLI (1.17.13). Upgrade both together. Set `OPENCODE_SERVER_PASSWORD` (and optionally `OPENCODE_SERVER_USERNAME`) to enable HTTP Basic auth on every bus request.
84
+
85
+ ## Notes from implementation
86
+
87
+ - The session store is global across directory headers: `GET /session/{id}` resolves regardless of which project directory is sent. The bus attributes a session to its owning project via the session's own `directory` field, not the probe header. `GET /session` (list) and `/session/status` are directory-scoped.
88
+ - Upstream opencode #30127 (v1.16.0) zeroes session-level diff summaries, so `GET /session/{id}/diff` always returns `[]`. Per-turn diffs on user messages (`GET /session/{id}/message`) stay intact and include untracked files, so `bus_status`/`bus_result` aggregate those instead (last turn wins per file, à la upstream PR #33444). Harness builds ≥`1.17.13+harness.ee55e157` carry #33444 directly, so `GET /session/{id}`'s `summary.diffs` field is populated and serves diffs without per-turn aggregation (still labeled `diffSource: "session"`); stock binaries leave it empty and fall through to per-turn aggregation. `GET /vcs/status` remains a last-ditch repo-wide fallback, labeled *working tree*.
89
+ - `/session/status` can report a session idle a beat before its final message is queryable; `scripts/smoke.ts` absorbs this with a bounded retry on the message fetch.
90
+ - Dogfooding surfaced a need for a steering path that isn't raw API — delegates block on interactive questions. That steering path ended up as an optional `sessionId` on `bus_task` rather than a fifth tool: passing it answers a pending question or sends a follow-up prompt on an existing session. `bus_status` also surfaces pending interactive questions (`pendingQuestion` / a `blocked:` line) so a blocked delegate isn't mistaken for one actively working.
91
+
92
+ ## Releasing
93
+
94
+ PRs land a changeset via `bunx changeset`. On merge to `main`, CI opens a version PR; merging that PR publishes to npm through trusted publishing (OIDC) — no `NPM_TOKEN` involved.
@@ -0,0 +1,64 @@
1
+ import { z } from "zod";
2
+ export declare const manifestSchema: z.ZodObject<{
3
+ server: z.ZodObject<{
4
+ baseUrl: z.ZodString;
5
+ }, "strip", z.ZodTypeAny, {
6
+ baseUrl: string;
7
+ }, {
8
+ baseUrl: string;
9
+ }>;
10
+ projects: z.ZodArray<z.ZodObject<{
11
+ name: z.ZodString;
12
+ path: z.ZodString;
13
+ description: z.ZodString;
14
+ }, "strip", z.ZodTypeAny, {
15
+ path: string;
16
+ name: string;
17
+ description: string;
18
+ }, {
19
+ path: string;
20
+ name: string;
21
+ description: string;
22
+ }>, "many">;
23
+ }, "strip", z.ZodTypeAny, {
24
+ server: {
25
+ baseUrl: string;
26
+ };
27
+ projects: {
28
+ path: string;
29
+ name: string;
30
+ description: string;
31
+ }[];
32
+ }, {
33
+ server: {
34
+ baseUrl: string;
35
+ };
36
+ projects: {
37
+ path: string;
38
+ name: string;
39
+ description: string;
40
+ }[];
41
+ }>;
42
+ export type Manifest = z.infer<typeof manifestSchema>;
43
+ export declare function expandHome(path: string): string;
44
+ /**
45
+ * Resolves the path to spacebus.json for a given workspace directory.
46
+ *
47
+ * Resolution order:
48
+ * 1. SPACE_BUS_CONFIG env var (must be absolute or start with ~; URLs and
49
+ * bare-relative paths are rejected with an actionable error).
50
+ * 2. `<directory>/spacebus.json`.
51
+ * 3. Throws, naming both mechanisms.
52
+ *
53
+ * Exact-path discovery only — no upward directory walk. When the resolved
54
+ * file exists, the path is canonicalized with realpathSync; when it's
55
+ * missing, the un-canonicalized (but expanded/joined) path is used in the
56
+ * error message.
57
+ */
58
+ export declare function resolveRosterPath(directory?: string): string;
59
+ /** Reads, validates, and expands the roster for a given workspace directory. No caching — reads per call. */
60
+ export declare function getRoster(directory?: string): Manifest;
61
+ export type Project = Manifest["projects"][number] & {
62
+ expandedPath: string;
63
+ };
64
+ export declare function getProjects(manifest: Manifest): Project[];
package/dist/core.d.ts ADDED
@@ -0,0 +1,81 @@
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 declare function authHeader(): Record<string, string>;
10
+ export type DiffSource = "session" | "turns" | "working-tree";
11
+ export type RosterProject = {
12
+ name: string;
13
+ path: string;
14
+ description: string;
15
+ pathExists: boolean;
16
+ busyCount?: number;
17
+ sessionCount?: number;
18
+ sessionCountCapped?: boolean;
19
+ statusError?: string;
20
+ };
21
+ export declare function roster(opts?: {
22
+ directory?: string;
23
+ }): Promise<Result<{
24
+ projects: RosterProject[];
25
+ }>>;
26
+ export type DispatchResult = {
27
+ sessionId: string;
28
+ project: string;
29
+ } & ({
30
+ mode: "new";
31
+ directory: string;
32
+ } | {
33
+ mode: "question-reply" | "follow-up";
34
+ });
35
+ export declare function dispatch(args: {
36
+ project?: string;
37
+ prompt: string;
38
+ title?: string;
39
+ sessionId?: string;
40
+ directory?: string;
41
+ }): Promise<Result<DispatchResult>>;
42
+ export type SessionStatusResult = {
43
+ sessionId: string;
44
+ project: string;
45
+ busy: boolean;
46
+ title?: string;
47
+ todos: {
48
+ content: string;
49
+ status: string;
50
+ priority: string;
51
+ }[];
52
+ diff: {
53
+ files: number;
54
+ additions: number;
55
+ deletions: number;
56
+ };
57
+ diffSource: DiffSource;
58
+ pendingQuestion?: {
59
+ preview: string;
60
+ options: string[];
61
+ };
62
+ };
63
+ export declare function status(sessionId: string, opts?: {
64
+ directory?: string;
65
+ }): Promise<Result<SessionStatusResult>>;
66
+ export type SessionResultResult = {
67
+ sessionId: string;
68
+ project: string;
69
+ text: string;
70
+ diff: {
71
+ file?: string;
72
+ additions: number;
73
+ deletions: number;
74
+ status?: string;
75
+ }[];
76
+ diffSource: DiffSource;
77
+ };
78
+ export declare function result(sessionId: string, opts?: {
79
+ directory?: string;
80
+ }): Promise<Result<SessionResultResult>>;
81
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { DispatchResult, RosterProject, SessionResultResult, SessionStatusResult } from "./core";
2
+ export declare function formatRoster(projects: RosterProject[]): string;
3
+ export declare function formatDispatch(r: DispatchResult): string;
4
+ export declare function formatStatus(r: SessionStatusResult): string;
5
+ export declare function formatResult(r: SessionResultResult): string;
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "@opencode-ai/plugin";
2
+ declare const SpaceBusPlugin: Plugin;
3
+ export default SpaceBusPlugin;