@kinqs/brainrouter-cli 0.3.4 → 0.3.5

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 CHANGED
@@ -1,185 +1,145 @@
1
- # 🧠 BrainRouter Terminal Agent CLI
1
+ # `@kinqs/brainrouter-cli`
2
2
 
3
- A premium, autonomous terminal-based AI coding assistant and REPL that acts as your local agent. It leverages **BrainRouter's memory engine** for cognitive persistence (System 1/2 loops) and provides standard filesystem/terminal tools to solve complex coding tasks autonomously.
3
+ A memory-native terminal agent. Edits files, runs shell commands,
4
+ spawns child agents, and talks to a BrainRouter MCP server for long-term
5
+ recall, skills, and capture.
6
+
7
+ Ships the `brainrouter` binary.
4
8
 
5
9
  ---
6
10
 
7
- ## Features
8
- - **Dual-Tier Connection**: Connects to local MCP servers via standard I/O (stdio) or hosted multi-tenant servers over Streamable HTTP/SSE.
9
- - **Double-Tier Memory Architecture**:
10
- - **System 1 (Heuristic Recall)**: Automatically retrieves active focus scenes, codebase facts, and skills *before* each LLM reasoning cycle.
11
- - **System 2 (Memory Consolidation)**: Autonomously extracts learning points, updates facts, and saves evidence via turn-by-turn memory capture.
12
- - **Local Execution Harness**: Autonomous execution of files editing, directory listing, regex/string grep, and terminal command invocation (safely prompted for user verification).
13
- - **Obsidian Dark / Midnight Ledger Aesthetics**: High-end command line styling, loader animations, and formatted terminal markdown output.
11
+ ## Install
14
12
 
15
- ---
13
+ ```bash
14
+ npm install -g @kinqs/brainrouter-cli
15
+ ```
16
16
 
17
- ## Installation & Setup
18
-
19
- 1. **Build the Monorepo**:
20
- From the repository root:
21
- ```bash
22
- npm install
23
- npm run build
24
- ```
25
-
26
- 2. **Configure Provider and Server Profiles**:
27
- Run the interactive configurator to set up your LLM settings (OpenAI, local endpoints like Ollama/LM Studio) and active server profile.
28
- From the repository root:
29
- ```bash
30
- npm run cli config
31
- ```
32
- Or from the `brainrouter` package subdirectory:
33
- ```bash
34
- node dist/index.js config
35
- ```
36
- This generates and modifies settings stored in `~/.config/brainrouter/config.json`.
17
+ **The `-g` flag is critical.** Without it, npm installs into the current
18
+ directory's `node_modules/` and the `brainrouter` binary ends up at
19
+ `./node_modules/.bin/brainrouter` — not on `$PATH`. Symptom: `brainrouter:
20
+ command not found`.
37
21
 
38
- ---
22
+ **Sudo caveat.** Whether you need `sudo` depends on your Node install:
23
+
24
+ | How Node is installed | Use `sudo`? |
25
+ |---|---|
26
+ | Homebrew (`brew install node`) | āŒ No — global prefix is user-writable |
27
+ | nvm / asdf / fnm | āŒ No — same reason |
28
+ | System Node on macOS / Linux | āœ… Yes — global prefix is `/usr/local/...` |
29
+
30
+ Check yours:
39
31
 
40
- ## CLI Usage
41
-
42
- ### Start Interactive Agent Session (REPL)
43
- Starts the agent loop. It will automatically load the active server connection and prime the agent with active codebase memories.
44
- From the repository root:
45
- ```bash
46
- npm run cli
47
- ```
48
- Or to run a specific command:
49
- ```bash
50
- npm run cli chat
51
- ```
52
- Or from the `brainrouter` package subdirectory:
53
- ```bash
54
- node dist/index.js chat
55
- ```
56
- *Tip: You can override the active LLM model via `--model <name>` or profile via `--profile <name>`.*
57
-
58
- Workspace detection:
59
- - By default, BrainRouter uses the nearest project root with `AGENT.md`, `AGENTS.md`, or `.git`.
60
- - If you run from this package directory during BrainRouter development, the CLI promotes the workspace to the monorepo root so tools see the whole project, not only `brainrouter/`.
61
- - Override manually with `--workspace /absolute/path/to/project` or `BRAINROUTER_WORKSPACE=/absolute/path/to/project`.
62
- - In the REPL, run `/workspace` to confirm the active root and session key.
63
-
64
- ### Host Login / Setup Connection
65
- Interactively log in to a hosted HTTP/SSE BrainRouter deployment and test latency/connectivity:
66
- From the repository root:
67
32
  ```bash
68
- npm run cli login
33
+ npm config get prefix
34
+ ```
35
+
36
+ If the path is under `/Users/...`, `/opt/homebrew/...`, or your home dir
37
+ → no sudo. If it's `/usr/local/...` → use sudo.
38
+
39
+ Verify the install:
40
+
41
+ ```bash
42
+ which brainrouter # prints the path to the binary
43
+ brainrouter --version # prints 0.3.5
69
44
  ```
70
45
 
71
46
  ---
72
47
 
73
- ## Interactive REPL Slash Commands
48
+ ## Configure
49
+
50
+ Two configuration surfaces, both one-time:
74
51
 
75
- Within the chat session, type `/` to access commands:
76
- - `/help` — List all available directive commands.
77
- - `/status` — Display active server profile details, LLM model, server latency check, and database size stats.
78
- - `/workspace` — Show active workspace root, launch directory, and BrainRouter session key.
79
- - `/tools` — Show local workspace tools and MCP tools exposed to the LLM.
80
- - `/doctor` — Check active profile, MCP connectivity, plan + session store health, and orchestration tool availability.
81
- - `/skills` — Visualize all loaded BrainRouter skills and categories.
82
- - `/plan` — Show the durable CLI task plan persisted under `.brainrouter/cli/tasks.json`.
83
- - `/transcript [main|sessionKey]` — Show recent persisted transcript entries.
84
- - `/roles` — List built-in agent roles (`explorer`, `architect`, `reviewer`, `worker`, `verifier`) with default access modes.
85
- - `/agents` — List child agent sessions with status, role, label, and elapsed time.
86
- - `/agent <id>` — Show child detail, prompt, final output, and recent transcript.
87
- - `/spawn <role> <prompt>` — Spawn a child agent (parent narrates via the LLM tool call).
88
- - `/wait <id> [timeoutMs]` — Wait for a child agent to finish.
89
- - `/spec <title>` — Runs the **spec-driven-skill** and writes a full `spec.md` to `<workspace>/.brainrouter/cli/workflows/<slug>/spec.md`. Stops for approval before generating tasks.
90
- - `/approve [slug]` — Approves the current (or named) workflow and kicks off the worker + verifier implementation phase, one task at a time, appending to `walkthrough.md`.
91
- - `/workflows` — List durable workflow folders with per-artifact status (`spec.md`, `tasks.md`, `walkthrough.md`).
92
- - `/feature-dev <feature>` — Runs the catalogued **agentic-engineering-workflow** skill with explorer + architect orchestration. Writes `spec.md` and `tasks.md` to the workflow folder, then stops for user approval before worker implementation.
93
- - `/review [scope]` — Runs the catalogued **code-review-and-quality** skill with 3 parallel reviewer agents (correctness, maintainability, conventions).
94
- - `/implement-plan` — Runs the catalogued **incremental-skill** with a worker + verifier loop on the next pending plan item.
95
- - `/skill <name> [input]` — Generic invoker for any skill in your `skills/` catalogue. The CLI fetches the skill body via the MCP `get_skill` tool, falls back to filesystem (`skills/**/SKILL.md`), and hands the agent a structured prompt that embeds the skill instructions plus orchestration affordances (`spawn_agent`, `update_plan`).
52
+ ### 1. The chat LLM and MCP server profile
96
53
 
97
- ### Skill-driven workflows
54
+ ```bash
55
+ brainrouter config # interactive — set LLM provider, model, key, endpoint
56
+ brainrouter login # interactive — set MCP server URL + API key
57
+ ```
98
58
 
99
- The CLI ships with a thin slash → skill mapping (see `brainrouter-cli/src/prompt/skillRunner.ts`). Slash commands do **not** carry monolithic hard-coded prompts; they delegate to the SKILL.md authored under `skills/`. This means improving a workflow is a documentation edit, not a code change. Add a new mapping in `SLASH_TO_SKILL` to expose a new slash command, or use `/skill <name>` to invoke any skill ad-hoc.
59
+ Both write to `~/.config/brainrouter/config.json`.
100
60
 
101
- #### How the skill catalogue is discovered
61
+ For local-model setups (LM Studio / Ollama), point the LLM endpoint at
62
+ `http://localhost:1234/v1/chat/completions` or `http://localhost:11434/v1/chat/completions`.
102
63
 
103
- The CLI resolves a skill body in this order:
64
+ ### 2. (Optional) Runtime knobs — `~/.config/brainrouter/cli.env` or `./brainrouter-cli.env`
104
65
 
105
- 1. **MCP `get_skill` tool** — the connected MCP server merges *global* skills (the canonical BrainRouter catalogue) with *local* skills the user authored under `<workspace>/skills/` or `<workspace>/projects/*/skills/`. Local skills shadow global ones on name conflict. This is the path used in normal operation.
106
- 2. **Filesystem fallback** (used only when MCP is unreachable) searches, in order:
107
- - `<workspace>/skills/**/SKILL.md`
108
- - `<workspace>/.brainrouter/skills/**/SKILL.md`
109
- - The installed `@kinqs/brainrouter-mcp-server` package directory (resolved via `require.resolve`). This works because the MCP package bundles the canonical catalogue at publish time (see below).
110
- 3. Otherwise the CLI hands the agent a benign placeholder and asks it to use general judgement.
66
+ Only needed if you want to tune sandbox, tool-loop limits, trace logging,
67
+ or web-search backend. See the [`.env.example`](.env.example) bundled with
68
+ this package for the full list. LLM credentials do **not** go here — they
69
+ live in `config.json`.
111
70
 
112
- #### Catalogue bundling at publish time
71
+ ---
113
72
 
114
- The `@kinqs/brainrouter-mcp-server` package ships with the full BrainRouter skill catalogue baked in, so a user who only runs `npm install @kinqs/brainrouter-mcp-server @kinqs/brainrouter-cli` in their own workspace gets all 70+ canonical skills out of the box — no monorepo checkout required.
73
+ ## Run
115
74
 
116
- This is done via two lifecycle scripts in `brainrouter/scripts/`:
75
+ ```bash
76
+ brainrouter # starts the interactive REPL
77
+ brainrouter chat # same — `chat` is the default subcommand
78
+ brainrouter run "summarize the changes in src/" # one-shot non-interactive
79
+ brainrouter agents # list child agent sessions in this workspace
80
+ ```
117
81
 
118
- - `prepack.mjs` — runs before `npm pack`/`npm publish`. Copies `skills/`, `agents/`, `references/`, and `docs/` from the monorepo root into the package directory and records what it copied in `.bundled-content.json`.
119
- - `postpack.mjs` — runs after pack. Reads the marker and removes exactly what `prepack` added, leaving the working tree clean.
82
+ Inside the REPL, type `/help` for the full slash-command list (60+
83
+ commands across session / memory / workflow / orchestration / observability
84
+ surfaces).
120
85
 
121
- The MCP server's resolver ([brainrouter/src/resolver.ts](../brainrouter/src/resolver.ts)) prefers the package's own `skills/` when present (installed-package mode) and otherwise walks up to the monorepo root (development mode). Both layouts work identically from the CLI's point of view.
86
+ ### Offline mode
122
87
 
123
- ### Durable workflow artifacts (one folder per workflow)
88
+ If the MCP server isn't reachable, the CLI still boots — but only local
89
+ tools (file edits, shell, web fetch, `spawn_agent`) work. Memory recall,
90
+ capture, and skills are disabled until the server is back. The startup
91
+ banner shows `āš ļø OFFLINE MODE` when this happens. Pass `--strict-mcp` to
92
+ make the CLI exit instead of degrading.
124
93
 
125
- All multi-step commands (`/spec`, `/feature-dev`, `/review`, `/implement-plan`) anchor to a workflow slug and write their outputs to:
94
+ ### Stdio mode
126
95
 
127
- ```
128
- <workspace>/.brainrouter/cli/workflows/<slug>/
129
- meta.json # { slug, title, kind, createdAt, updatedAt, status }
130
- spec.md # produced by /spec or /feature-dev phase 3
131
- tasks.md # produced by /feature-dev phase 3
132
- walkthrough.md # appended by /implement-plan as items ship
133
- review.md # produced by /review
134
- ```
96
+ If you'd rather have the CLI spawn the MCP server as a child process
97
+ instead of running it separately, use `brainrouter config` → "Set Active
98
+ Server Profile" → `default` (the bundled stdio profile). You don't need
99
+ to run anything else — the CLI manages the server's lifecycle.
135
100
 
136
- The orchestration prompts for these commands **require** the agent to call `write_file` with the exact workspace-relative path — no chat-only plans. Use `/workflows` to inspect what's on disk. `getCurrentWorkflow` tracks the most recent one so `/implement-plan` appends to it automatically.
101
+ ---
137
102
 
138
- The system prompt also directs the agent to redirect free-form spec/plan requests to `/spec` or `/feature-dev` instead of producing inline monoliths, so the "one place" rule survives even when you don't type a slash command.
103
+ ## Workspace detection
139
104
 
140
- ### Memory-native flow
105
+ By default, the CLI uses the nearest project root with `AGENT.md`,
106
+ `AGENTS.md`, or `.git`. Override with:
141
107
 
142
- Each parent turn runs three memory queries in parallel before the LLM sees the user prompt:
108
+ ```bash
109
+ brainrouter --workspace /absolute/path/to/project
110
+ # or
111
+ BRAINROUTER_WORKSPACE=/absolute/path/to/project brainrouter
112
+ ```
143
113
 
144
- 1. **`memory_recall`** — cognitive memory most relevant to the prompt.
145
- 2. **`memory_working_context`** — current working canvas, so resumed sessions don't reset.
146
- 3. **`memory_task_state`** — open tasks / handover notes for this workspace.
114
+ Inside the REPL, run `/workspace` to confirm the active root and session key.
147
115
 
148
- The merged briefing (secrets redacted via `redactText`) is injected as a system message and the recalled record IDs are tracked through the whole turn. At end-of-turn, `selectCitedRecordIds` heuristically picks the records that actually informed the answer (by ID mention or distinctive content match) and reports them via `memory_mark_cited` — replacing the previous always-empty citation list, so System-1 recall actually learns.
116
+ ---
149
117
 
150
- Child agents (`spawn_agent`) skip the full briefing for speed but accept a `seedRecordIds: string[]` parameter so the parent can hand over what it already recalled. Long child outputs (≄ 6,000 chars) are automatically offloaded to `memory_working_offload` and only a preview + ref handle is returned to the parent — the main context-saving win when synthesizing multiple child reports.
118
+ ## What you also probably want
151
119
 
152
- After every turn, the CLI also asks `memory_contradictions` and surfaces a one-line warning in the REPL when newly-captured beliefs disagree with prior ones, so drift gets caught instead of silently accumulating.
120
+ A BrainRouter MCP server for the cognitive memory. The CLI works without
121
+ it (offline mode) but you lose recall, capture, and skills:
153
122
 
154
- Inspection commands:
123
+ ```bash
124
+ npm install -g @kinqs/brainrouter-mcp-server
125
+ brainrouter-mcp init # one-time: scaffold ~/.config/brainrouter/server.env
126
+ $EDITOR ~/.config/brainrouter/server.env # set BRAINROUTER_LLM_API_KEY, embeddings, etc.
127
+ brainrouter-mcp --http --port 3747 # in a separate terminal
128
+ ```
155
129
 
156
- - `/memory <query>` — search long-term cognitive memory (`memory_search`).
157
- - `/recall <query>` — explicit `memory_recall`, no LLM turn.
158
- - `/briefing` — what was recalled before the most recent turn.
159
- - `/scenes` — list active focus scenes.
160
- - `/working` — current working-memory canvas.
161
- - `/forget <recordId>` — archive an obsolete memory.
130
+ Then `brainrouter login` and point at `http://localhost:3747/mcp`.
162
131
 
163
- The workflow commands `/feature-dev`, `/review`, and `/implement-plan` are now required to open with `memory_search` (plus `memory_graph_query` / `memory_file_history` / `memory_task_state` depending on the workflow) and pass `seedRecordIds` to children, so no exploration is ever duplicated across sessions.
132
+ ---
164
133
 
165
- ### Child agent permissions
134
+ ## Docs
166
135
 
167
- Child agents default to the safest mode for their role: `explorer`, `architect`, `reviewer` are `read`; `worker` is `write`; `verifier` is `shell`. Override with `access: "read" | "write" | "shell"` when calling `spawn_agent`. Shell execution from children runs unattended — only grant `shell` to trusted roles like `verifier`.
168
- - `/config` — Output active configuration details (with security sanitization for API keys).
169
- - `/compact` — Clear the active chat context while keeping the session identity.
170
- - `/clear` — Wipe the chat history of the active session.
171
- - `/exit` — Close connections and exit.
136
+ - **Repo**: <https://github.com/kinqsradiollc/BrainRouter>
137
+ - **Memory engine deep-dive**: [BRAINROUTER.md](https://github.com/kinqsradiollc/BrainRouter/blob/main/BRAINROUTER.md)
138
+ - **Maintainer runbook**: [SETUP.md](https://github.com/kinqsradiollc/BrainRouter/blob/main/SETUP.md)
139
+ - **Bugs / requests**: <https://github.com/kinqsradiollc/BrainRouter/issues>
172
140
 
173
141
  ---
174
142
 
175
- ## Autonomous Tool Execution
176
-
177
- The agent coordinates two scopes of tools:
178
- 1. **BrainRouter Memory Tools** (loaded dynamically via the MCP connection): `memory_recall`, `memory_capture_turn`, `list_skills`, etc.
179
- 2. **Local Workspace Tools**:
180
- - `read_file` — Reads content of a workspace file.
181
- - `write_file` — Overwrites or writes a new file.
182
- - `edit_file` — Performs safe single-match string search-and-replace.
183
- - `list_dir` — Lists directory paths.
184
- - `grep_search` — Platform-independent recursive search of code patterns.
185
- - `run_command` — Runs a shell command on your host (always requests manual confirmation first for safety).
143
+ ## License
144
+
145
+ MIT
@@ -984,7 +984,7 @@ export class Agent {
984
984
  try {
985
985
  const res = await fetch(url, {
986
986
  headers: {
987
- 'User-Agent': 'Mozilla/5.0 (compatible; BrainRouterCLI/0.3.4)'
987
+ 'User-Agent': 'Mozilla/5.0 (compatible; BrainRouterCLI/0.3.5)'
988
988
  }
989
989
  });
990
990
  if (!res.ok) {
@@ -1424,7 +1424,7 @@ async function runWebSearch(query, maxResults) {
1424
1424
  }
1425
1425
  try {
1426
1426
  const url = `https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&no_html=1&skip_disambig=1`;
1427
- const res = await fetch(url, { headers: { 'User-Agent': 'BrainRouterCLI/0.3.4' } });
1427
+ const res = await fetch(url, { headers: { 'User-Agent': 'BrainRouterCLI/0.3.5' } });
1428
1428
  if (!res.ok) {
1429
1429
  return `web_search failed: DuckDuckGo returned ${res.status} ${res.statusText}.`;
1430
1430
  }
package/dist/cli/repl.js CHANGED
@@ -50,7 +50,7 @@ const SLASH_COMMANDS = [
50
50
  '/experimental', '/memories', '/debug-config', '/mention', '/keymap', '/ide',
51
51
  ];
52
52
  export function startREPL(agent, mcpClient, config, workspace) {
53
- console.log(chalk.bold.hex('#CC9166')('\n🧠 BRAINROUTER TERMINAL AGENT CLIENT v0.3.4'));
53
+ console.log(chalk.bold.hex('#CC9166')('\n🧠 BRAINROUTER TERMINAL AGENT CLIENT v0.3.5'));
54
54
  console.log(chalk.gray('Midnight Ledger / Obsidian Surface theme active.'));
55
55
  console.log(chalk.gray(`Workspace root: ${workspace?.workspaceRoot || process.cwd()}`));
56
56
  // Surface offline mode prominently — easy to miss the warning that scrolled
package/dist/index.js CHANGED
@@ -165,7 +165,7 @@ const program = new Command();
165
165
  program
166
166
  .name('brainrouter')
167
167
  .description('BrainRouter CLI — Premium interactive terminal-based agent client.')
168
- .version('0.3.4');
168
+ .version('0.3.5');
169
169
  // Chat Command (default)
170
170
  program
171
171
  .command('chat', { isDefault: true })
@@ -14,7 +14,7 @@ export class McpClientWrapper {
14
14
  */
15
15
  connected = false;
16
16
  constructor() {
17
- this.client = new Client({ name: 'brainrouter-cli', version: '0.3.4' }, { capabilities: {} });
17
+ this.client = new Client({ name: 'brainrouter-cli', version: '0.3.5' }, { capabilities: {} });
18
18
  }
19
19
  /** Whether this wrapper has an active MCP transport. */
20
20
  isConnected() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kinqs/brainrouter-cli",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "Memory-native terminal coding agent. Talks to the BrainRouter MCP cognitive engine for recall, skills, capture, persona, focus scenes, and contradiction tracking.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,8 +21,8 @@
21
21
  "prepack": "npm run build && find dist -name '*.test.*' -delete"
22
22
  },
23
23
  "dependencies": {
24
- "@kinqs/brainrouter-sdk": "^0.3.4",
25
- "@kinqs/brainrouter-types": "^0.3.4",
24
+ "@kinqs/brainrouter-sdk": "^0.3.5",
25
+ "@kinqs/brainrouter-types": "^0.3.5",
26
26
  "@modelcontextprotocol/sdk": "^1.11.0",
27
27
  "chalk": "^5.3.0",
28
28
  "commander": "^12.1.0",