@fro.bot/space-bus 0.11.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @experimental
3
+ * Experimental — shapes may change in minor releases.
4
+ *
5
+ * The sixth bus tool: roster registry management (list/use/create/register/
6
+ * unregister/set-default/add-project/remove-project/update-project) behind
7
+ * ONE action-discriminated tool, mirroring the other five tools' shared
8
+ * factory/description-constant parity pattern. Node-only (imports
9
+ * registry.ts + roster-edit.ts), same lane as config.ts/server.ts.
10
+ *
11
+ * `use` is an MCP-only concept (R10): the plugin surface resolves ambient
12
+ * roster from `ctx.directory`, so there is no session to select a default
13
+ * for. The factory takes an optional `session` seam — when absent (the
14
+ * plugin surface), `use` returns an actionable error explaining why;
15
+ * when present (MCP, wired to an in-memory module-level variable — see
16
+ * mcp.ts), `use` mutates it after revalidating the name resolves.
17
+ */
18
+ import { type ToolDefinition } from "@opencode-ai/plugin";
19
+ import { z } from "zod";
20
+ import { type ServerConfig } from "../config";
21
+ import { type ProjectPatch, type RosterProjectInput } from "../roster-edit";
22
+ export declare const BUS_REGISTRY_DESCRIPTION = "Manage the roster registry: list registered rosters, create/register/unregister rosters, set the default, select an active roster for this connector session (MCP only), and add/remove/update projects on a registered roster.";
23
+ /** Session seam (R10): ephemeral, connector-side "active roster" state.
24
+ * Only the MCP surface wires this (mcp.ts's module-level `activeRoster`
25
+ * variable) — the plugin surface omits it, so `use` fails actionably. */
26
+ export interface RegistrySession {
27
+ getActive(): string | undefined;
28
+ setActive(name: string): void;
29
+ clearActive(): void;
30
+ }
31
+ export type BusRegistryAction = "list" | "use" | "create" | "register" | "unregister" | "set-default" | "add-project" | "remove-project" | "update-project";
32
+ export type BusRegistryArgs = {
33
+ action: BusRegistryAction;
34
+ roster?: string;
35
+ name?: string;
36
+ path?: string;
37
+ server?: ServerConfig;
38
+ project?: RosterProjectInput;
39
+ projectName?: string;
40
+ patch?: ProjectPatch;
41
+ };
42
+ export declare const ACTION_SCHEMA: z.ZodDiscriminatedUnion<[z.ZodObject<{
43
+ action: z.ZodLiteral<"list">;
44
+ }, z.core.$strict>, z.ZodObject<{
45
+ action: z.ZodLiteral<"use">;
46
+ roster: z.ZodString;
47
+ }, z.core.$strict>, z.ZodObject<{
48
+ action: z.ZodLiteral<"create">;
49
+ name: z.ZodString;
50
+ path: z.ZodString;
51
+ server: z.ZodOptional<z.ZodObject<{
52
+ baseUrl: z.ZodOptional<z.ZodURL>;
53
+ managed: z.ZodOptional<z.ZodObject<{
54
+ command: z.ZodOptional<z.ZodArray<z.ZodString>>;
55
+ cwd: z.ZodOptional<z.ZodString>;
56
+ port: z.ZodOptional<z.ZodNumber>;
57
+ }, z.core.$strip>>;
58
+ }, z.core.$strip>>;
59
+ }, z.core.$strict>, z.ZodObject<{
60
+ action: z.ZodLiteral<"register">;
61
+ name: z.ZodString;
62
+ path: z.ZodString;
63
+ }, z.core.$strict>, z.ZodObject<{
64
+ action: z.ZodLiteral<"unregister">;
65
+ name: z.ZodString;
66
+ }, z.core.$strict>, z.ZodObject<{
67
+ action: z.ZodLiteral<"set-default">;
68
+ name: z.ZodString;
69
+ }, z.core.$strict>, z.ZodObject<{
70
+ action: z.ZodLiteral<"add-project">;
71
+ roster: z.ZodString;
72
+ project: z.ZodObject<{
73
+ name: z.ZodString;
74
+ path: z.ZodString;
75
+ description: z.ZodString;
76
+ }, z.core.$strip>;
77
+ }, z.core.$strict>, z.ZodObject<{
78
+ action: z.ZodLiteral<"remove-project">;
79
+ roster: z.ZodString;
80
+ projectName: z.ZodString;
81
+ }, z.core.$strict>, z.ZodObject<{
82
+ action: z.ZodLiteral<"update-project">;
83
+ roster: z.ZodString;
84
+ projectName: z.ZodString;
85
+ patch: z.ZodObject<{
86
+ name: z.ZodOptional<z.ZodString>;
87
+ path: z.ZodOptional<z.ZodString>;
88
+ description: z.ZodOptional<z.ZodString>;
89
+ }, z.core.$strip>;
90
+ }, z.core.$strict>], "action">;
91
+ export type RegistryListEntry = {
92
+ name: string;
93
+ path: string;
94
+ default: boolean;
95
+ active: boolean;
96
+ };
97
+ /** Machine-readable list metadata, shared verbatim by both surfaces
98
+ * (plugin ToolResult.metadata and MCP structuredContent), same pattern as
99
+ * bus_task's dispatchMetadata. Only `list` gets structured output — every
100
+ * other action is a one-line mutation confirmation, not worth a shape. */
101
+ export declare function registryListMetadata(session?: RegistrySession): {
102
+ ok: true;
103
+ rosters: RegistryListEntry[];
104
+ } | {
105
+ ok: false;
106
+ error: string;
107
+ };
108
+ type ActionResult = {
109
+ text: string;
110
+ listMetadata?: RegistryListEntry[];
111
+ };
112
+ /**
113
+ * Runs one bus_registry action and returns its formatted text result.
114
+ * Throws on any invalid input or `ok:false` underneath — every message
115
+ * names the action, per the plan's per-action-error contract. Shared by
116
+ * both the plugin tool's execute() and mcp.ts's registerTool handler so
117
+ * the two surfaces can't drift. Dispatch is a thin switch over
118
+ * per-action helper functions (kept small individually to stay under the
119
+ * lint complexity ceiling).
120
+ */
121
+ export declare function runBusRegistryAction(rawArgs: BusRegistryArgs, session?: RegistrySession): Promise<ActionResult>;
122
+ export declare function makeBusRegistry(session?: RegistrySession): ToolDefinition;
123
+ export {};
@@ -1,2 +1,32 @@
1
1
  import type { BusContext } from "../contract";
2
- export declare function ensureAndLoadContext(directory?: string): Promise<BusContext>;
2
+ /** Result of context resolution, carrying the roster name/path needed for
3
+ * the result-echo header (formatRosterHeader in format.ts). */
4
+ export type ResolvedContext = {
5
+ context: BusContext;
6
+ /** Registry name, when resolution went through an explicit `roster` param. */
7
+ rosterName?: string;
8
+ /** The roster file path actually resolved (ambient or registry-resolved). */
9
+ rosterPath: string;
10
+ };
11
+ /** Injectable `ensureServer` seam — defaults to the real implementation.
12
+ * Exists so tests can prove the registry name is resolved exactly ONCE
13
+ * per call: a test can rebind the registry mid-call (inside this
14
+ * function) and assert the loaded context still matches the path
15
+ * resolved BEFORE the rebind, not a re-resolution after it. */
16
+ export declare function ensureAndLoadContext(directory?: string, rosterName?: string, ensure?: (rosterPath: string) => Promise<unknown>): Promise<ResolvedContext>;
17
+ /**
18
+ * Prepends the resolved-roster header to any post-resolution result text —
19
+ * success OR error. Centralizing this closes the gap where a bare `throw
20
+ * new Error(r.error)` (plugin adapters) or a bare `content:[{text: r.error}]`
21
+ * (MCP handlers) would otherwise omit the header on core `ok:false` error
22
+ * paths (Fix 1): once context resolution has succeeded, EVERY result must
23
+ * carry the header, since the header is the split-brain/confused-deputy
24
+ * mitigation — the caller needs to know which roster produced this error
25
+ * just as much as which roster produced a success. Pre-resolution errors
26
+ * (unknown roster name, missing spacebus.json, etc.) never reach this
27
+ * helper — there's no resolved roster to report yet.
28
+ */
29
+ export declare function withRosterHeader(source: {
30
+ name?: string;
31
+ path: string;
32
+ }, text: string): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fro.bot/space-bus",
3
- "version": "0.11.0",
3
+ "version": "0.13.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",
@@ -39,6 +39,10 @@
39
39
  "./attach": {
40
40
  "types": "./dist/attach.d.ts",
41
41
  "import": "./dist/attach.js"
42
+ },
43
+ "./registry": {
44
+ "types": "./dist/registry-entry.d.ts",
45
+ "import": "./dist/registry-entry.js"
42
46
  }
43
47
  },
44
48
  "bin": {
@@ -78,7 +82,7 @@
78
82
  "devDependencies": {
79
83
  "@biomejs/biome": "2.5.2",
80
84
  "@changesets/cli": "2.31.0",
81
- "@opencode-ai/plugin": "1.17.15",
85
+ "@opencode-ai/plugin": "1.17.18",
82
86
  "@types/bun": "1.3.14",
83
87
  "typescript": "5.9.3"
84
88
  }