@kinqs/brainrouter-cli 0.3.6 → 0.3.8
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 +29 -52
- package/agents/architect.json +18 -0
- package/agents/explorer.json +18 -0
- package/agents/reviewer.json +18 -0
- package/agents/verifier.json +18 -0
- package/agents/worker.json +18 -0
- package/changelog/0.2.0.md +15 -0
- package/changelog/0.3.0.md +20 -0
- package/changelog/0.3.1.md +22 -0
- package/changelog/0.3.2.md +15 -0
- package/changelog/0.3.3.md +19 -0
- package/changelog/0.3.4.md +20 -0
- package/changelog/0.3.5.md +9 -0
- package/changelog/0.3.6.md +9 -0
- package/changelog/0.3.7.md +20 -0
- package/changelog/0.3.8.md +30 -0
- package/changelog/README.md +41 -0
- package/dist/agent/agent.d.ts +34 -1
- package/dist/agent/agent.js +372 -79
- package/dist/agent/toolCallRecovery.d.ts +57 -0
- package/dist/agent/toolCallRecovery.js +130 -0
- package/dist/agent/toolSafety.d.ts +17 -0
- package/dist/agent/toolSafety.js +102 -0
- package/dist/cli/banner.d.ts +20 -0
- package/dist/cli/banner.js +47 -14
- package/dist/cli/cliPrompt.d.ts +40 -3
- package/dist/cli/cliPrompt.js +117 -25
- package/dist/cli/commands/_context.d.ts +3 -1
- package/dist/cli/commands/_helpers.d.ts +1 -1
- package/dist/cli/commands/config.d.ts +46 -0
- package/dist/cli/commands/config.js +1042 -0
- package/dist/cli/commands/init.d.ts +20 -0
- package/dist/cli/commands/init.js +64 -0
- package/dist/cli/commands/login.d.ts +13 -0
- package/dist/cli/commands/login.js +179 -0
- package/dist/cli/commands/mcp.d.ts +13 -11
- package/dist/cli/commands/mcp.js +261 -74
- package/dist/cli/commands/mcpInstall.d.ts +20 -0
- package/dist/cli/commands/mcpInstall.js +87 -0
- package/dist/cli/commands/orchestration.js +51 -0
- package/dist/cli/commands/releaseNotes.d.ts +24 -0
- package/dist/cli/commands/releaseNotes.js +109 -0
- package/dist/cli/commands/schedule.d.ts +18 -0
- package/dist/cli/commands/schedule.js +189 -0
- package/dist/cli/commands/ui.js +119 -60
- package/dist/cli/commands/workflow.d.ts +2 -0
- package/dist/cli/commands/workflow.js +54 -8
- package/dist/cli/ink/ChatApp.d.ts +206 -0
- package/dist/cli/ink/ChatApp.js +493 -0
- package/dist/cli/ink/Frame.d.ts +26 -0
- package/dist/cli/ink/Frame.js +5 -0
- package/dist/cli/ink/Picker.d.ts +71 -0
- package/dist/cli/ink/Picker.js +168 -0
- package/dist/cli/ink/SlashPalette.d.ts +51 -0
- package/dist/cli/ink/SlashPalette.js +136 -0
- package/dist/cli/ink/TextField.d.ts +34 -0
- package/dist/cli/ink/TextField.js +47 -0
- package/dist/cli/ink/WizardApp.d.ts +7 -0
- package/dist/cli/ink/WizardApp.js +422 -0
- package/dist/cli/ink/ambientChat.d.ts +34 -0
- package/dist/cli/ink/ambientChat.js +7 -0
- package/dist/cli/ink/consoleCapture.d.ts +11 -0
- package/dist/cli/ink/consoleCapture.js +33 -0
- package/dist/cli/ink/markdownRender.d.ts +41 -0
- package/dist/cli/ink/markdownRender.js +278 -0
- package/dist/cli/ink/renderWithResizeClear.d.ts +14 -0
- package/dist/cli/ink/renderWithResizeClear.js +33 -0
- package/dist/cli/ink/runChat.d.ts +34 -0
- package/dist/cli/ink/runChat.js +682 -0
- package/dist/cli/ink/runPicker.d.ts +31 -0
- package/dist/cli/ink/runPicker.js +139 -0
- package/dist/cli/ink/runSlashPalette.d.ts +23 -0
- package/dist/cli/ink/runSlashPalette.js +33 -0
- package/dist/cli/ink/runWizard.d.ts +22 -0
- package/dist/cli/ink/runWizard.js +133 -0
- package/dist/cli/ink/stdinHandoff.d.ts +51 -0
- package/dist/cli/ink/stdinHandoff.js +78 -0
- package/dist/cli/ink/toolFormat.d.ts +75 -0
- package/dist/cli/ink/toolFormat.js +206 -0
- package/dist/cli/ink/useTerminalSize.d.ts +35 -0
- package/dist/cli/ink/useTerminalSize.js +26 -0
- package/dist/cli/repl.d.ts +25 -3
- package/dist/cli/repl.js +52 -714
- package/dist/cli/slashSuggest.d.ts +32 -0
- package/dist/cli/slashSuggest.js +146 -0
- package/dist/cli/wizard/modelsApi.d.ts +72 -0
- package/dist/cli/wizard/modelsApi.js +166 -0
- package/dist/cli/wizard/picker.d.ts +202 -0
- package/dist/cli/wizard/picker.js +547 -0
- package/dist/cli/wizard/providers.d.ts +86 -0
- package/dist/cli/wizard/providers.js +190 -0
- package/dist/cli/wizard/runner.d.ts +13 -0
- package/dist/cli/wizard/runner.js +488 -0
- package/dist/cli/wizard/types.d.ts +122 -0
- package/dist/cli/wizard/types.js +109 -0
- package/dist/config/config.d.ts +13 -1
- package/dist/config/config.js +45 -3
- package/dist/index.js +157 -206
- package/dist/memory/briefing.d.ts +1 -1
- package/dist/memory/briefing.js +4 -4
- package/dist/memory/consolidation.d.ts +1 -1
- package/dist/orchestration/agentRegistry.d.ts +36 -0
- package/dist/orchestration/agentRegistry.js +64 -0
- package/dist/orchestration/orchestrator.d.ts +7 -0
- package/dist/orchestration/orchestrator.js +2 -0
- package/dist/orchestration/tools.d.ts +105 -3
- package/dist/orchestration/tools.js +167 -8
- package/dist/prompt/skillCatalog.d.ts +11 -0
- package/dist/prompt/skillCatalog.js +134 -0
- package/dist/prompt/skillRunner.d.ts +2 -2
- package/dist/prompt/skillRunner.js +2 -31
- package/dist/prompt/systemPrompt.js +7 -2
- package/dist/runtime/anthropicAdapter.d.ts +100 -0
- package/dist/runtime/anthropicAdapter.js +293 -0
- package/dist/runtime/cronParser.d.ts +23 -0
- package/dist/runtime/cronParser.js +122 -0
- package/dist/runtime/mcpClient.js +14 -11
- package/dist/runtime/mcpPool.d.ts +170 -0
- package/dist/runtime/mcpPool.js +442 -0
- package/dist/runtime/mcpUtils.d.ts +17 -1
- package/dist/runtime/mcpUtils.js +23 -0
- package/dist/runtime/scheduleTicker.d.ts +33 -0
- package/dist/runtime/scheduleTicker.js +99 -0
- package/dist/runtime/vendorSnippets.d.ts +45 -0
- package/dist/runtime/vendorSnippets.js +153 -0
- package/dist/state/scheduleStore.d.ts +37 -0
- package/dist/state/scheduleStore.js +64 -0
- package/package.json +14 -5
- package/.env.example +0 -116
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal 5-field cron parser — `minute hour dom month dow`.
|
|
3
|
+
*
|
|
4
|
+
* Vendored intentionally (no node-cron) to keep the dependency surface
|
|
5
|
+
* small and the semantics predictable. Supports `*`, comma lists,
|
|
6
|
+
* ranges (`1-5`), and steps (`15`, `0-30/10`). No seconds, no Quartz
|
|
7
|
+
* extensions, no `@reboot` macros.
|
|
8
|
+
*/
|
|
9
|
+
const FIELD_RANGES = [
|
|
10
|
+
{ min: 0, max: 59 }, // minute
|
|
11
|
+
{ min: 0, max: 23 }, // hour
|
|
12
|
+
{ min: 1, max: 31 }, // day of month
|
|
13
|
+
{ min: 1, max: 12 }, // month
|
|
14
|
+
{ min: 0, max: 7 }, // day of week (0 or 7 = Sunday)
|
|
15
|
+
];
|
|
16
|
+
function parseField(raw, min, max) {
|
|
17
|
+
if (raw.length === 0)
|
|
18
|
+
return undefined;
|
|
19
|
+
const out = new Set();
|
|
20
|
+
for (const part of raw.split(',')) {
|
|
21
|
+
if (!part)
|
|
22
|
+
return undefined;
|
|
23
|
+
let step = 1;
|
|
24
|
+
let range = part;
|
|
25
|
+
const slash = part.indexOf('/');
|
|
26
|
+
if (slash >= 0) {
|
|
27
|
+
const s = Number(part.slice(slash + 1));
|
|
28
|
+
if (!Number.isInteger(s) || s < 1)
|
|
29
|
+
return undefined;
|
|
30
|
+
step = s;
|
|
31
|
+
range = part.slice(0, slash);
|
|
32
|
+
}
|
|
33
|
+
let lo;
|
|
34
|
+
let hi;
|
|
35
|
+
if (range === '*' || range === '') {
|
|
36
|
+
lo = min;
|
|
37
|
+
hi = max;
|
|
38
|
+
}
|
|
39
|
+
else if (range.includes('-')) {
|
|
40
|
+
const [a, b] = range.split('-');
|
|
41
|
+
lo = Number(a);
|
|
42
|
+
hi = Number(b);
|
|
43
|
+
if (!Number.isInteger(lo) || !Number.isInteger(hi))
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const v = Number(range);
|
|
48
|
+
if (!Number.isInteger(v))
|
|
49
|
+
return undefined;
|
|
50
|
+
lo = v;
|
|
51
|
+
hi = v;
|
|
52
|
+
}
|
|
53
|
+
if (lo < min || hi > max || lo > hi)
|
|
54
|
+
return undefined;
|
|
55
|
+
for (let i = lo; i <= hi; i += step)
|
|
56
|
+
out.add(i);
|
|
57
|
+
}
|
|
58
|
+
return out.size > 0 ? out : undefined;
|
|
59
|
+
}
|
|
60
|
+
export function parseCron(expr) {
|
|
61
|
+
if (typeof expr !== 'string')
|
|
62
|
+
return undefined;
|
|
63
|
+
const trimmed = expr.trim();
|
|
64
|
+
if (!trimmed)
|
|
65
|
+
return undefined;
|
|
66
|
+
const fields = trimmed.split(/\s+/);
|
|
67
|
+
if (fields.length !== 5)
|
|
68
|
+
return undefined;
|
|
69
|
+
const parsed = fields.map((f, i) => parseField(f, FIELD_RANGES[i].min, FIELD_RANGES[i].max));
|
|
70
|
+
if (parsed.some((p) => !p))
|
|
71
|
+
return undefined;
|
|
72
|
+
const [minute, hour, dom, month, dowRaw] = parsed;
|
|
73
|
+
// Normalize dow: 7 → 0 so Sunday has one representation.
|
|
74
|
+
const dow = new Set();
|
|
75
|
+
for (const v of dowRaw)
|
|
76
|
+
dow.add(v === 7 ? 0 : v);
|
|
77
|
+
return { minute, hour, dom, month, dow, raw: trimmed };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* First firing instant strictly AFTER `after`. Walks the calendar
|
|
81
|
+
* forward, jumping months/days when fields don't match instead of
|
|
82
|
+
* scanning minute-by-minute.
|
|
83
|
+
*/
|
|
84
|
+
export function nextCronFire(cron, after) {
|
|
85
|
+
const d = new Date(after.getTime());
|
|
86
|
+
d.setSeconds(0, 0);
|
|
87
|
+
d.setMinutes(d.getMinutes() + 1);
|
|
88
|
+
const domRestricted = cron.dom.size !== 31;
|
|
89
|
+
const dowRestricted = cron.dow.size !== 7;
|
|
90
|
+
// Safety cap — 8 years of day-level iterations is plenty; if we exhaust
|
|
91
|
+
// it the expression is effectively impossible (e.g. Feb 30).
|
|
92
|
+
for (let i = 0; i < 366 * 8; i++) {
|
|
93
|
+
if (!cron.month.has(d.getMonth() + 1)) {
|
|
94
|
+
d.setDate(1);
|
|
95
|
+
d.setMonth(d.getMonth() + 1);
|
|
96
|
+
d.setHours(0, 0, 0, 0);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const domOk = cron.dom.has(d.getDate());
|
|
100
|
+
const dowOk = cron.dow.has(d.getDay());
|
|
101
|
+
// Vixie-cron semantics: when both dom and dow are restricted, EITHER
|
|
102
|
+
// match counts. Otherwise both must match (the unrestricted field is
|
|
103
|
+
// effectively `*` and always matches).
|
|
104
|
+
const dateMatches = domRestricted && dowRestricted ? (domOk || dowOk) : (domOk && dowOk);
|
|
105
|
+
if (!dateMatches) {
|
|
106
|
+
d.setDate(d.getDate() + 1);
|
|
107
|
+
d.setHours(0, 0, 0, 0);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
if (!cron.hour.has(d.getHours())) {
|
|
111
|
+
d.setHours(d.getHours() + 1);
|
|
112
|
+
d.setMinutes(0, 0, 0);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (!cron.minute.has(d.getMinutes())) {
|
|
116
|
+
d.setMinutes(d.getMinutes() + 1, 0, 0);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
return d;
|
|
120
|
+
}
|
|
121
|
+
throw new Error(`cron next-fire search exhausted for "${cron.raw}"`);
|
|
122
|
+
}
|
|
@@ -23,7 +23,7 @@ export class McpClientWrapper {
|
|
|
23
23
|
identity = 'unknown';
|
|
24
24
|
serverName;
|
|
25
25
|
constructor() {
|
|
26
|
-
this.client = new Client({ name: 'brainrouter-cli', version: '0.3.
|
|
26
|
+
this.client = new Client({ name: 'brainrouter-cli', version: '0.3.8' }, { capabilities: {} });
|
|
27
27
|
}
|
|
28
28
|
/** Whether this wrapper has an active MCP transport. */
|
|
29
29
|
isConnected() {
|
|
@@ -139,16 +139,11 @@ export class McpClientWrapper {
|
|
|
139
139
|
if (llmConfig?.model && !mergedEnv.BRAINROUTER_LLM_MODEL) {
|
|
140
140
|
mergedEnv.BRAINROUTER_LLM_MODEL = llmConfig.model;
|
|
141
141
|
}
|
|
142
|
-
//
|
|
143
|
-
//
|
|
144
|
-
//
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
console.warn('\n⚠️ No LLM API key reached the MCP child. Sensory turns will be ' +
|
|
148
|
-
'captured but cognitive extraction (the thing that makes them ' +
|
|
149
|
-
'searchable) will fail silently. Set OPENAI_API_KEY or ' +
|
|
150
|
-
'BRAINROUTER_LLM_API_KEY before starting brainrouter.\n');
|
|
151
|
-
}
|
|
142
|
+
// (Previously: a loud console.warn here if no LLM API key reached the
|
|
143
|
+
// MCP child. That message landed above the Ink banner and looked like a
|
|
144
|
+
// CLI error even though it was a server-side concern. Server-side
|
|
145
|
+
// extraction failures should surface through MCP's own status channel —
|
|
146
|
+
// not by the CLI second-guessing what the server needs.)
|
|
152
147
|
// Spawn the MCP child with cwd set to the MCP package directory if we
|
|
153
148
|
// can find it from the first arg (typically
|
|
154
149
|
// `node /path/to/BrainRouter/brainrouter/dist/index.js`). The child
|
|
@@ -179,6 +174,14 @@ export class McpClientWrapper {
|
|
|
179
174
|
args: serverConfig.args ?? [],
|
|
180
175
|
env: mergedEnv,
|
|
181
176
|
cwd: childCwd,
|
|
177
|
+
// The MCP child is a separate process with its own concerns (its own
|
|
178
|
+
// dotenv, its own auth failures, its own platform warnings). Inheriting
|
|
179
|
+
// its stderr meant every `[BrainRouter] FATAL …`, every dotenv banner,
|
|
180
|
+
// every SQLite ExperimentalWarning leaked above our Ink chat banner
|
|
181
|
+
// and looked like the CLI was crashing. Pipe it so the SDK owns the
|
|
182
|
+
// stream; the CLI can surface a single graceful "MCP unreachable" line
|
|
183
|
+
// through its own offline-mode flow instead.
|
|
184
|
+
stderr: 'pipe',
|
|
182
185
|
});
|
|
183
186
|
await this.client.connect(this.transport);
|
|
184
187
|
this.connected = true;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { McpClientWrapper } from './mcpClient.js';
|
|
2
|
+
import type { LLMConfig, ServerConfig } from '../config/config.js';
|
|
3
|
+
/**
|
|
4
|
+
* 0.3.7 — Multi-MCP support. Wraps a `Map<serverId, McpClientWrapper>`
|
|
5
|
+
* and exposes the same public API as a single wrapper (`isConnected`,
|
|
6
|
+
* `getIdentity`, `getServerName`, `listTools`, `callTool`, `close`),
|
|
7
|
+
* so existing call-sites that hold an `mcpClient` reference keep
|
|
8
|
+
* working unchanged.
|
|
9
|
+
*
|
|
10
|
+
* Pattern lifted from Claude Code's `.mcp.json` model (see
|
|
11
|
+
* `openSrc/claude-code/CHANGELOG.md` — concurrent startup at line 688,
|
|
12
|
+
* tool prefixing at line 1515, graceful degradation at line 189). Our
|
|
13
|
+
* shape:
|
|
14
|
+
*
|
|
15
|
+
* - All configured servers attempt connection concurrently on boot,
|
|
16
|
+
* each with a 5s timeout. Offline ones do NOT block others.
|
|
17
|
+
* - Tools surface to the agent with `mcp_<serverId>_<toolName>`
|
|
18
|
+
* prefix (Claude Code style).
|
|
19
|
+
* - `callTool` accepts BOTH the prefixed form (the canonical name
|
|
20
|
+
* the LLM sees in the tool inventory) AND the raw form (back-compat
|
|
21
|
+
* for the existing system prompt and skills that hardcode
|
|
22
|
+
* `memory_recall` etc.). Raw form routes to the unique server
|
|
23
|
+
* providing that tool name; collision (two servers expose the same
|
|
24
|
+
* unprefixed name) returns a helpful error pointing at the
|
|
25
|
+
* prefixed form.
|
|
26
|
+
*
|
|
27
|
+
* Future versions may drop the raw-name fallback once skills and
|
|
28
|
+
* prompts are migrated to prefixed names; the pool then becomes the
|
|
29
|
+
* pure Claude Code shape. Until then the dual-name resolution is a
|
|
30
|
+
* transition aid documented in CHANGELOG `[0.3.7]`.
|
|
31
|
+
*/
|
|
32
|
+
export type McpServerStatus = {
|
|
33
|
+
serverId: string;
|
|
34
|
+
identity: 'brainrouter' | 'third-party' | 'unknown';
|
|
35
|
+
/** 'connected' once the underlying wrapper reports isConnected. */
|
|
36
|
+
status: 'connected' | 'connecting' | 'offline' | 'failed';
|
|
37
|
+
/** Filled after the first successful listTools (used by /mcp list). */
|
|
38
|
+
toolCount?: number;
|
|
39
|
+
/** Per-server error message when status === 'failed'. */
|
|
40
|
+
error?: string;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Choose which configured MCP profiles should connect for a normal CLI run.
|
|
44
|
+
*
|
|
45
|
+
* BrainRouter profiles are special: users may store several BrainRouter MCPs
|
|
46
|
+
* (local, staging, remote, self-hosted), but only one should be active at a
|
|
47
|
+
* time because the BrainRouter MCP is the memory/brain plane. Third-party MCPs
|
|
48
|
+
* are additive tools, so they all connect concurrently.
|
|
49
|
+
*
|
|
50
|
+
* `requestedProfile` is the explicit escape hatch (`--profile <name>`): it
|
|
51
|
+
* scopes the run to exactly that profile, matching the existing single-server
|
|
52
|
+
* mode.
|
|
53
|
+
*/
|
|
54
|
+
export declare function selectMcpServerIds(servers: Record<string, ServerConfig>, activeServer?: string, requestedProfile?: string): string[];
|
|
55
|
+
/**
|
|
56
|
+
* 0.3.8-R5 — Single-underscore `mcp_<server>_<tool>` is the canonical
|
|
57
|
+
* tool-name shape across the CLI. Any legacy double-underscore
|
|
58
|
+
* `mcp__<server>__<tool>` form that arrives at the pool boundary
|
|
59
|
+
* (e.g. through an external surface or older skill) is collapsed here
|
|
60
|
+
* so downstream code can assume one convention.
|
|
61
|
+
*/
|
|
62
|
+
export declare function normalizeMcpToolName(name: string): string;
|
|
63
|
+
export declare class McpClientPool {
|
|
64
|
+
/** serverId → connected wrapper. */
|
|
65
|
+
private clients;
|
|
66
|
+
/** serverId → status entry (kept even for failed/offline servers so /mcp can render them). */
|
|
67
|
+
private statuses;
|
|
68
|
+
/**
|
|
69
|
+
* Unprefixed tool name → owning serverId. Sentinel `__COLLISION__`
|
|
70
|
+
* marks tool names exposed by multiple servers (must be addressed
|
|
71
|
+
* via the prefixed form).
|
|
72
|
+
*/
|
|
73
|
+
private toolToServer;
|
|
74
|
+
/** Prefixed form (`mcp_<serverId>_<tool>`) → `{serverId, tool}` for fast dispatch. */
|
|
75
|
+
private prefixedToServer;
|
|
76
|
+
/** LLM config from the last connectAll — needed for reconnect calls. */
|
|
77
|
+
private currentLlmConfig?;
|
|
78
|
+
/** Raw server configs from the last connectAll — needed for /mcp reconnect <id>. */
|
|
79
|
+
private serverConfigs;
|
|
80
|
+
/** serverId → prefix used in tool names. Brainrouter servers get "brainrouter"; others keep their config key. */
|
|
81
|
+
private prefixIds;
|
|
82
|
+
/** Reverse: prefixId → serverId (needed to dispatch `mcp_brainrouter_X` back to the real key). */
|
|
83
|
+
private prefixToServerId;
|
|
84
|
+
private getPrefixId;
|
|
85
|
+
private assignPrefixId;
|
|
86
|
+
/**
|
|
87
|
+
* Connect to every entry in `servers` concurrently. Each connect
|
|
88
|
+
* gets its own timeout; offline servers don't block the others.
|
|
89
|
+
* Returns the status array after all connects settle.
|
|
90
|
+
*/
|
|
91
|
+
connectAll(servers: Record<string, ServerConfig>, llmConfig?: LLMConfig, options?: {
|
|
92
|
+
timeoutMs?: number;
|
|
93
|
+
onStatusChange?: (s: McpServerStatus) => void;
|
|
94
|
+
}): Promise<McpServerStatus[]>;
|
|
95
|
+
/**
|
|
96
|
+
* Connect a single server. Used both by `connectAll` and by
|
|
97
|
+
* `/mcp connect <id>` for late-joining servers. Idempotent — if
|
|
98
|
+
* the server is already connected, closes the previous wrapper first.
|
|
99
|
+
*/
|
|
100
|
+
connectOne(serverId: string, config: ServerConfig, llmConfig?: LLMConfig, timeoutMs?: number): Promise<void>;
|
|
101
|
+
/** Tear down a single server. Removes it from the pool and rebuilds the tool index. */
|
|
102
|
+
disconnectOne(serverId: string): Promise<void>;
|
|
103
|
+
/** Reconnect: close + connect again using the stashed config. */
|
|
104
|
+
reconnectOne(serverId: string): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Walk every connected client and rebuild the tool→server indices.
|
|
107
|
+
* Called after every connect / disconnect / reconnect so the
|
|
108
|
+
* dispatch path stays correct without re-fetching tools on every
|
|
109
|
+
* `callTool`.
|
|
110
|
+
*/
|
|
111
|
+
private refreshToolIndex;
|
|
112
|
+
/**
|
|
113
|
+
* Concatenated tool list across every connected server, with names
|
|
114
|
+
* prefixed `mcp_<serverId>_<toolName>` (Claude Code style). The
|
|
115
|
+
* agent calls this once per turn and hands it to the LLM.
|
|
116
|
+
*/
|
|
117
|
+
listTools(): Promise<{
|
|
118
|
+
tools: any[];
|
|
119
|
+
}>;
|
|
120
|
+
/**
|
|
121
|
+
* Route a tool call to the right server. Accepts both name forms:
|
|
122
|
+
*
|
|
123
|
+
* - `mcp_<serverId>_<tool>` — the canonical form the LLM sees
|
|
124
|
+
* in the inventory. Stripped + dispatched directly.
|
|
125
|
+
* - `<tool>` raw form — back-compat for prompts/skills that
|
|
126
|
+
* hardcode `memory_recall`-style names. Routed to the unique
|
|
127
|
+
* server providing that tool. Returns a helpful error if two
|
|
128
|
+
* servers expose the same name (caller must use the prefix).
|
|
129
|
+
*/
|
|
130
|
+
callTool(name: string, args: Record<string, any>): Promise<any>;
|
|
131
|
+
/** Internal — map a name (prefixed OR raw) to a concrete server + tool. */
|
|
132
|
+
private resolveToolCall;
|
|
133
|
+
/** True iff at least one server is connected. */
|
|
134
|
+
isConnected(): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Identity precedence: any connected `brainrouter` > any connected
|
|
137
|
+
* `third-party` > `unknown`. The CLI banner + offline prompt swap
|
|
138
|
+
* branch on this — "BrainRouter is offline" makes sense only when
|
|
139
|
+
* we expected one and didn't get one.
|
|
140
|
+
*/
|
|
141
|
+
getIdentity(): 'brainrouter' | 'third-party' | 'unknown';
|
|
142
|
+
/**
|
|
143
|
+
* Human-readable summary for the banner/statusline. Single-server
|
|
144
|
+
* pools render just the server name; multi-server pools render
|
|
145
|
+
* a count + the first few names.
|
|
146
|
+
*/
|
|
147
|
+
getServerName(): string | undefined;
|
|
148
|
+
/**
|
|
149
|
+
* Look up a wrapper by serverId. Used by `/mcp tools <server>` and
|
|
150
|
+
* similar commands that want to talk to one specific server.
|
|
151
|
+
*/
|
|
152
|
+
getClient(serverId: string): McpClientWrapper | undefined;
|
|
153
|
+
/**
|
|
154
|
+
* Find the connected wrapper whose identity is 'brainrouter'. Some
|
|
155
|
+
* code paths (memory capture, working-memory offload) specifically
|
|
156
|
+
* need the canonical brain regardless of how many third-party MCPs
|
|
157
|
+
* the user added.
|
|
158
|
+
*/
|
|
159
|
+
getBrainrouterClient(): McpClientWrapper | undefined;
|
|
160
|
+
/** Server id for the currently connected BrainRouter MCP, if one is active. */
|
|
161
|
+
getActiveBrainrouterServerId(): string | undefined;
|
|
162
|
+
/** Status snapshot for every server the pool has tried to connect to. */
|
|
163
|
+
getStatuses(): McpServerStatus[];
|
|
164
|
+
/** Status for one server (returns undefined if the pool has never seen it). */
|
|
165
|
+
getStatus(serverId: string): McpServerStatus | undefined;
|
|
166
|
+
/** List of serverIds currently held by the pool (connected or not). */
|
|
167
|
+
getServerIds(): string[];
|
|
168
|
+
/** Close every wrapper. Used on CLI exit. */
|
|
169
|
+
close(): Promise<void>;
|
|
170
|
+
}
|