@bike4mind/cli 4.0.0 → 4.6.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/README.md +86 -4
- package/bin/bike4mind-cli.mjs +249 -40
- package/bin/envFlags.d.mts +17 -0
- package/bin/envFlags.mjs +89 -0
- package/dist/{AgentHistoryStore-DgqmcVLN.mjs → AgentHistoryStore--J3sgO_-.mjs} +3794 -1368
- package/dist/{ApiClient-_JrM_xWw.mjs → ApiClient-CdO4Gamg.mjs} +22 -3
- package/dist/BubblewrapRuntime-3jAbC60G.mjs +157 -0
- package/dist/ConfigStore-CausUCzY.mjs +2 -0
- package/dist/ConfigStore-Dusy6glb.mjs +3364 -0
- package/dist/{ConfigStore-BwqsQ0U9.mjs → Logger-C1Wj6xla.mjs} +32672 -21643
- package/dist/{ProxyManager-B0-RuR2w.mjs → ProxyManager-TxEKlgdO.mjs} +88 -3
- package/dist/{SandboxOrchestrator-BcUv9fQ3.mjs → SandboxOrchestrator-CQwYq_uy.mjs} +26 -7
- package/dist/SandboxRuntimeAdapter-BsT2iLky.mjs +190 -0
- package/dist/SandboxRuntimeAdapter-Zg_0th7V.mjs +2 -0
- package/dist/SeatbeltRuntime-C2DEkrjy.mjs +194 -0
- package/dist/{WorkItemsClient-CERTDrhT.mjs → WorkItemsClient-CxNZaOmc.mjs} +1 -1
- package/dist/agents/defaults/review.md +8 -1
- package/dist/agents/defaults/test.md +8 -1
- package/dist/buildToolSearch-DOb7mx6F.mjs +417 -0
- package/dist/commands/acpCommand.mjs +25 -19
- package/dist/commands/apiCommand.mjs +3 -5
- package/dist/commands/doctorCommand.mjs +2 -2
- package/dist/commands/envCommand.mjs +1 -1
- package/dist/commands/headlessCommand.mjs +117 -36
- package/dist/commands/hostCommand.mjs +2344 -0
- package/dist/commands/mcpCommand.mjs +45 -30
- package/dist/commands/mirrorCommand.mjs +279 -0
- package/dist/commands/modelsCommand.mjs +1117 -0
- package/dist/commands/pluginCommand.mjs +9 -9
- package/dist/commands/skillsCommand.mjs +174 -29
- package/dist/commands/updateCommand.mjs +2 -2
- package/dist/curated-build.json +1 -0
- package/dist/dist-CbViwiS9.mjs +4739 -0
- package/dist/dist-Citbv0y0.mjs +7864 -0
- package/dist/fit-CVWDiavv.mjs +200 -0
- package/dist/index.mjs +853 -417
- package/dist/modelHub-BSB6qRFP.mjs +1963 -0
- package/dist/modelServers-BaegigV-.mjs +2465 -0
- package/dist/{package-CQaam4Dq.mjs → package-C9pfAdGF.mjs} +1 -1
- package/dist/{serve-CFxUhjml.mjs → serve-8wyGb8of.mjs} +595 -26
- package/dist/types-BFIvwByC.mjs +2 -0
- package/dist/{types-F61_hxmG.mjs → types-CxrzVXel.mjs} +9 -5
- package/dist/{updateChecker-CCLVVdH0.mjs → updateChecker-BAKb8KWP.mjs} +7 -29
- package/package.json +16 -13
- package/dist/BubblewrapRuntime-5bLPTwEC.mjs +0 -72
- package/dist/SandboxRuntimeAdapter-BgLUVTJL.mjs +0 -57
- package/dist/SandboxRuntimeAdapter-Bt1wPpld.mjs +0 -2
- package/dist/SeatbeltRuntime-C_Y8q8Mr.mjs +0 -124
- package/dist/buildToolSearch-D9GEK91u.mjs +0 -2351
- package/dist/dist-Ul2qwn5x.mjs +0 -624
- package/dist/types-I45lMh7Q.mjs +0 -2
package/README.md
CHANGED
|
@@ -67,7 +67,31 @@ pnpm rebuild
|
|
|
67
67
|
b4m
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
When you are signed out, the CLI starts on a local model from Ollama or a model server saved in Desktop. With no local model available, it offers Bike4Mind sign-in.
|
|
71
|
+
|
|
72
|
+
### Chat without signing in
|
|
73
|
+
|
|
74
|
+
Start Ollama and pull a model, then open the CLI:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
ollama serve
|
|
78
|
+
# In another terminal:
|
|
79
|
+
ollama pull qwen3.5
|
|
80
|
+
b4m
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The signed-out session lists only local models. Run `/login` to use Bike4Mind cloud models; finish or stop the current reply with Esc before signing in. From a local session, cancelling sign-in returns you to that session.
|
|
84
|
+
|
|
85
|
+
For headless prompts, save a local default first:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
b4m models use qwen3.5
|
|
89
|
+
b4m -p "say hello" </dev/null
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
A signed-out headless run uses the selected local model or your saved local default. With a cloud default and no saved local default, it exits with an error instead of choosing an arbitrary model. ACP sessions also support local models while signed out.
|
|
93
|
+
|
|
94
|
+
If no local model is found, start Ollama, pull a model, or check the saved model server's address and credentials. A server login hint uses `b4m models servers login <name>`. An expired Bike4Mind sign-in is refreshed at startup; a temporary refresh failure keeps the saved sign-in and uses local models for that run, so restart the CLI to retry.
|
|
71
95
|
|
|
72
96
|
### CLI Flags
|
|
73
97
|
|
|
@@ -81,7 +105,7 @@ A bare positional argument seeds **and** submits the first turn while keeping th
|
|
|
81
105
|
|
|
82
106
|
| Flag | Effect |
|
|
83
107
|
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
84
|
-
| `--dev` | Point the CLI at the local dev server (`http://localhost:3001`) and remember it. Aliases: `--local
|
|
108
|
+
| `--dev` | Point the CLI at the local dev server (`http://localhost:3001`) and remember it. Aliases: `--local` (except after `b4m mcp serve`), single-dash forms. |
|
|
85
109
|
| `--prod` | Point the CLI at Bike4Mind production and remember it. Alias: `--production`. |
|
|
86
110
|
| `--api-url <url>` | Point the CLI at **any** instance — a self-hosted stack, an AWS deployment, `http://localhost:3000`, etc. Clears cached auth (bound to the old origin) and exits; run `b4m` again to sign in. |
|
|
87
111
|
| `--reset-api` | Reset the API URL to the built-in default and clear auth, then exit. |
|
|
@@ -143,8 +167,43 @@ b4m update # Check for and install CLI updates
|
|
|
143
167
|
b4m doctor # Diagnose the CLI installation (Node, registry, ripgrep, native modules)
|
|
144
168
|
b4m skills push <path> # Create a skill from a folder, SKILL.md, or commands/*.md
|
|
145
169
|
b4m skills push <path> --update # Update your skill with the same name without a prompt
|
|
170
|
+
b4m models ls | search | show | curated | pull | rm | use # Find, download and use local models (see below)
|
|
146
171
|
```
|
|
147
172
|
|
|
173
|
+
### Local models
|
|
174
|
+
|
|
175
|
+
`b4m models` manages models on a local Ollama and finds GGUF builds on Hugging Face.
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
b4m models ls --ollama-host http://127.0.0.1:11434 # list installed models; a host that answers is saved
|
|
179
|
+
b4m models search qwen2.5 0.5b # Hugging Face GGUF repos: downloads, likes, license, gated
|
|
180
|
+
b4m models show Qwen/Qwen2.5-0.5B-Instruct-GGUF # builds with size, fit, quant and Ollama ref, license, gating
|
|
181
|
+
b4m models curated # Bike4Mind's picks for this computer, then every curated build
|
|
182
|
+
b4m models pull Qwen/Qwen2.5-0.5B-Instruct-GGUF:Q4_K_M
|
|
183
|
+
b4m models pull qwen2.5:0.5b # Ollama registry names (model[:tag], ollama.com/owner/model)
|
|
184
|
+
b4m models pull <ref> --force # pull even when the fit check rates it too large
|
|
185
|
+
b4m models use hf.co/Qwen/Qwen2.5-0.5B-Instruct-GGUF:Q4_K_M # default model for chat
|
|
186
|
+
b4m models rm qwen2.5:0.5b
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`search` hides abliterated and uncensored builds and prints how many it hid; `--include-abliterated` lists them last, labelled as not recommended.
|
|
190
|
+
|
|
191
|
+
`show` rates each build `fits`, `tight` or `too large` for this machine, and `pull` prints the verdict with its reasoning before asking anything. It is a rough estimate using the shared memory-budget and compute-buffer calculations: the file size (plus any vision projector) and compute buffers against the memory a model can use here, at the context the CLI asks Ollama for (the model's trained length capped at 32K, or at `OLLAMA_MAX_NUM_CTX`). `pull` refuses a too-large build unless `--force`. The fit is `unknown`, and never blocks, when download sizes are unavailable, the hardware cannot be read, or the Ollama host is another machine. An Ollama reached through an SSH tunnel on localhost is rated as this machine, so use `--force` when the far host has the memory.
|
|
192
|
+
|
|
193
|
+
`curated` prints the curated list Desktop uses: the list bundled with the CLI, or a newer signed one when this build has a list URL and a trusted key (the published CLI bakes both in once they are configured; otherwise it only has the bundled list). A newer list is checked for at most every 6 hours, for up to 3 seconds, verified against the shipped keys and cached under `~/.bike4mind/model-hub/curated/`; a list that fails verification is ignored and the last good one stays. `--refresh` checks now. `--offline` or `B4M_CURATED=off` uses the last verified cached list (else the bundled one) and makes no request; `pull` accepts `--offline` too. The output names where the list came from. It lists the picks for this computer's memory first, then every build with the ref to pull, its size, license and tags (including the Ollama version a build needs). It contacts no runtime and downloads nothing; pull a row with `b4m models pull <ref>`, which asks for the license as below but does not check the build against the reviewed one. Abliterated builds are never on it, and a license that is not permissive, the model's own or its base model's, is shown as `restricted: <license>` (with `(base: <license>)`) and must be accepted before `pull`. With a saved Ollama host on another machine, the picks still describe this computer.
|
|
194
|
+
|
|
195
|
+
Nothing downloads without confirmation: `pull` prints the size and license first and asks (`--yes` skips the question). A license that is not a permissive open-source one (Apache-2.0, MIT, BSD and similar), or no declared license, is named with a link and must be accepted at a prompt or with `--accept-license`. For Ollama registry models the license is read from the model's own license texts, and only unmodified Apache-2.0 or MIT texts count as permissive. Refs naming any other registry are refused. A gated repo needs access granted on Hugging Face first, `HF_TOKEN` set to that account's token, and your Ollama public key added at https://huggingface.co/settings/keys. Ctrl-C cancels a pull without installing anything; pulling again resumes, and says how much was already downloaded. Without a saved host, `b4m models` uses the first local runtime it detects; a scheme-less host without a port uses 11434, and `--ollama-host ''` clears the saved host. `--output-format json` prints `ls`, `search`, `show` and `curated` as JSON. With a saved host, `b4m -p` fails instead of switching to another model when the model picked with `b4m models use` is not available, or Ollama does not answer.
|
|
196
|
+
|
|
197
|
+
`b4m models servers` also lists saved SSH servers with an invalid port or destination as
|
|
198
|
+
refused and explains what to fix. Remove the server in Desktop and add it again; the CLI
|
|
199
|
+
never edits Desktop's list. You can still clear its CLI credential by name with
|
|
200
|
+
`b4m models servers logout <name>`. During `b4m models servers login`, Ctrl-C ends the
|
|
201
|
+
credential check, prints "Cancelled." and exits with code 130 without saving the credential.
|
|
202
|
+
|
|
203
|
+
`b4m mcp serve` (stdio only) offers the same operations to MCP clients as `models_list`, `models_search`, `models_pull` and `models_remove`, with the same checks. Pull and remove act only on the user's own approval. A client that supports elicitation asks the user directly, showing the size and every license, with a separate tick for a license that is not all permissive. With any other client nothing changes: the tool returns the preview and the `b4m models pull` or `b4m models rm` command for the user to run in a terminal, where the CLI asks them. `models_pull` reports the same fit verdict in its preview and prompt, and refuses a too-large model before asking unless the caller passes `force: true`, which still leaves the download to the user's approval. `models_search` leaves abliterated and uncensored builds out unless `includeAbliterated` is true, and then lists them last, labelled `notRecommended`, as `b4m models search --include-abliterated` does. The host comes from `B4M_OLLAMA_HOST`, the saved host, or detection, as for `b4m models`. `b4m mcp serve --local` serves these four tools alone and needs no Bike4Mind backend.
|
|
204
|
+
|
|
205
|
+
A chat with a model on this computer's Ollama (`http://127.0.0.1:11434`) or on an Ollama model server saved in Desktop uses that model's settings from Desktop's Models screen: a fixed context size, keep-alive, draft tokens, sampling (in place of the CLI's `temperature` preference), max output and, on a model with effort levels such as gpt-oss, its effort. Under Auto the CLI keeps its own context size (the trained length capped at 32K or `OLLAMA_MAX_NUM_CTX`) and only applies the model's cap. The CLI reads `model-settings.json` on every turn and never writes it, but the context size is the one it listed at startup, so a context change takes effect after a CLI restart. The file comes from the same Desktop userData folder as the saved model servers: `B4M_DESKTOP_USER_DATA` when set, else the first of `@bike4mind/desktop` and `Bike4Mind` under the app-data folder that holds `model-servers.json` or `model-settings.json`, or failing that the first that exists (a source run of Desktop uses `Bike4Mind Dev`, so point `B4M_DESKTOP_USER_DATA` at it). From WSL with mirrored networking, set `B4M_DESKTOP_USER_DATA=/mnt/c/Users/<you>/AppData/Roaming/@bike4mind/desktop` to use the Windows Desktop's settings. No file means no settings and values this CLI does not know are ignored; a broken file, or a broken entry for the model in use, fails that model's turns with a message naming the file, the model and the field. `B4M_DESKTOP_MODEL_SETTINGS=<path>` reads another file, which must exist, and `off`, `0`, `false`, `no` or `none` ignores Desktop's settings.
|
|
206
|
+
|
|
148
207
|
### Pushing a local skill
|
|
149
208
|
|
|
150
209
|
Log in with `b4m /login`, then run `b4m skills push ~/.claude/skills/my-skill`.
|
|
@@ -276,7 +335,7 @@ Configuration is stored in `~/.bike4mind/config.json`
|
|
|
276
335
|
|
|
277
336
|
### Authentication
|
|
278
337
|
|
|
279
|
-
|
|
338
|
+
Bike4Mind cloud models use OAuth authentication. You can chat with local models while signed out; run `/login` when you want to use your Bike4Mind account:
|
|
280
339
|
|
|
281
340
|
1. Run `b4m` or use the `/login` command
|
|
282
341
|
2. Visit the verification URL shown in the terminal
|
|
@@ -302,6 +361,11 @@ Because that default is injected only at build time, the endpoint is resolved li
|
|
|
302
361
|
4. Otherwise (a published, unbranded fork with no baked default), the first `b4m` **prompts you
|
|
303
362
|
to choose a backend**.
|
|
304
363
|
|
|
364
|
+
A build with a baked default also shows this picker on a fresh install, listing the default
|
|
365
|
+
first and preselected, then the local dev server and a custom URL. Any choice (the picker,
|
|
366
|
+
`--prod`, `--dev`, `--api-url`, `--reset-api`, `/set-api`, `/reset-api`) is remembered, so
|
|
367
|
+
later launches go straight to sign-in.
|
|
368
|
+
|
|
305
369
|
**Quick switch between local dev and production:** use the `b4m --dev` / `b4m --prod`
|
|
306
370
|
launch flags (see [Switching environments](#switching-environments---dev----prod)).
|
|
307
371
|
They persist your choice and cache auth per-environment. The `/set-api`, `/reset-api`,
|
|
@@ -445,7 +509,9 @@ You can also run any MCP server via npx or custom executables:
|
|
|
445
509
|
|
|
446
510
|
#### Serve Bike4Mind itself as an MCP server (`b4m mcp serve`)
|
|
447
511
|
|
|
448
|
-
The reverse of adding a server: `b4m mcp serve` exposes your Bike4Mind backend to any MCP client (Claude Desktop, editors, other agents). It advertises twenty-
|
|
512
|
+
The reverse of adding a server: `b4m mcp serve` exposes your Bike4Mind backend to any MCP client (Claude Desktop, editors, other agents). It advertises twenty-seven tools (`list_notebooks`, `get_notebook`, `create_notebook`, `rename_notebook`, `clone_notebook`, `delete_notebook`, `list_projects`, `get_project`, `create_project`, `send_message`, `search_knowledge_base`, `list_lakes`, `list_files`, `get_file`, `upload_file`, `generate_sound_effect`, `text_to_speech`, `generate_image`, `create_artifact`, `publish_artifact`, `bob_read_site`, `bob_compare_sites`, `bob_recheck`, `get_bob_report`, `get_bob_comparison`, `list_bob_reports`, `bob_runs_left`) plus four resource templates (`b4m://notebook/{id}`, `b4m://file/{id}`, `b4m://project/{id}`, `b4m://artifact/{id}`), each listable and readable as JSON, and `b4m://agent-quest` - the credential-free manifest for The Open Door, the onboarding quest for agents.
|
|
513
|
+
|
|
514
|
+
Use `upload_file { path: "/path/to/report.pdf", projectId: "project-id" }` to upload a local regular file, or `upload_file { base64: "YWJj", name: "note.txt" }` to send bytes. Choose exactly one source; base64 requires a name. Local files and decoded base64 have a 100 MiB limit, and local dotfiles, hidden directories and links into them are refused. The tool requires `files:write`; an optional `projectId` also requires `projects:write`. Success returns a `fileId` with pending ingestion. If project association fails, the error includes the retained file ID so you can retry association without uploading again.
|
|
449
515
|
|
|
450
516
|
To get answers grounded in a data lake, call `list_lakes`, then `create_notebook { dataLakeId }` with a lake's id, then `send_message { notebookId }` on that notebook: the result carries the `reply` plus the `citables` it was grounded in. `list_lakes` needs a key with `datalake:read` (and data lakes enabled on the instance).
|
|
451
517
|
|
|
@@ -454,8 +520,11 @@ The seven Bob tools read websites with Bob on an instance that serves it. `bob_r
|
|
|
454
520
|
```bash
|
|
455
521
|
b4m mcp serve # stdio (default) - for local clients that spawn the process
|
|
456
522
|
b4m mcp serve --http --port 7000 # stateless streamable HTTP at http://127.0.0.1:7000/mcp
|
|
523
|
+
b4m mcp serve --local # stdio, local model tools only; no backend needed
|
|
457
524
|
```
|
|
458
525
|
|
|
526
|
+
`--local` serves only `models_list`, `models_search`, `models_pull` and `models_remove`, ignores any configured endpoint, and notes this in one stderr line. It is stdio only (`--http` with it is an error, as are `--dev` and `--prod`). Only after `b4m mcp serve` is `--local` serve's own flag and leaves the saved backend alone; before it, as in `b4m --local mcp serve`, it is the `--dev` alias. Without it, `mcp serve` exits with `No API endpoint configured` when no backend is set.
|
|
527
|
+
|
|
459
528
|
Over stdio only, when the caller is entitled to OptiHashi and the key carries `optihashi:read` and `optihashi:compute`, the server also offers `optihashi_solvers` and `optihashi_solve` (a free, bounded classical solver race). With an API key, the CLI first checks the key's own scopes and offers them only when it holds both. The solve input schema comes from the server at startup, with a 5 second discovery budget; restart the session to pick up changed family ids, solver ids or limits. `optihashi_solvers` fetches the current roster on every call. With no entitlement, scopes or feature, they are simply not listed. No paid compute is exposed, and HTTP mode never offers them.
|
|
460
529
|
|
|
461
530
|
Auth precedence is `--api-key` > `B4M_API_KEY` > the stored login; the endpoint is `B4M_API_URL` > `--api-url` > the configured backend. Tool _listing_ needs no credentials, apart from the optional stdio-only tools above, which are fetched once at startup; tool _calls_ authenticate. Prefer `B4M_API_KEY` over `--api-key` (a flag value shows up in process listings). HTTP mode binds loopback only (`127.0.0.1`, `/mcp` path) and requires an `Authorization: Bearer <token>` header on every request. The token is `--token`, else `B4M_MCP_TOKEN`, else a random one generated at startup and printed to stderr (a token you set yourself is printed masked). Prefer `B4M_MCP_TOKEN` over `--token`, which shows up in process listings. The advertised scopes are the recommended key configuration, not per-route hard gates, apart from Bob's, which its routes enforce. See [Serve Bike4Mind as an MCP server](../../BIKE4MIND_CLI.md#serve-bike4mind-as-an-mcp-server-b4m-mcp-serve) for the Claude Desktop config and details. Point an HTTP client at it like this:
|
|
@@ -906,6 +975,19 @@ interactive permission prompt blocks; `PostToolUse` / `Stop` / `UserPromptSubmit
|
|
|
906
975
|
commands remove it. Each hook command runs via a real shell with its stdin piped
|
|
907
976
|
then closed (EOF), so a blocking `cat > <file>` hook returns immediately.
|
|
908
977
|
|
|
978
|
+
### Folder trust on a host launch
|
|
979
|
+
|
|
980
|
+
A launch with a positional prompt **and** at least one host flag (`--mcp-config`,
|
|
981
|
+
`--append-system-prompt`, `--allowedTools`, `--settings`, `--session-id` or
|
|
982
|
+
`--resume`) does not show the folder-trust prompt or the repo MCP-approval prompt,
|
|
983
|
+
since no hook fires for either and the auto-fired turn would wait behind it. An
|
|
984
|
+
untrusted folder's repo config (`CLAUDE.md`, `AGENTS.md`, `.mcp.json`, `.claude/`,
|
|
985
|
+
`.bike4mind/`) stays inert for that session, exactly as if "Not now" had been
|
|
986
|
+
chosen, and nothing is persisted. A one-line notice says so; run `/trust folder`
|
|
987
|
+
to trust it. Pending repo MCP servers stay off with the usual warning. Context the
|
|
988
|
+
host needs should reach the session through `--append-system-prompt` and
|
|
989
|
+
`--mcp-config`.
|
|
990
|
+
|
|
909
991
|
## License
|
|
910
992
|
|
|
911
993
|
Private - Bike4Mind
|
package/bin/bike4mind-cli.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import { dirname, join, resolve } from 'path';
|
|
|
19
19
|
import { existsSync } from 'fs';
|
|
20
20
|
import yargs from 'yargs';
|
|
21
21
|
import { hideBin } from 'yargs/helpers';
|
|
22
|
+
import { splitEnvFlags } from './envFlags.mjs';
|
|
22
23
|
|
|
23
24
|
const __filename = fileURLToPath(import.meta.url);
|
|
24
25
|
const __dirname = dirname(__filename);
|
|
@@ -29,30 +30,43 @@ const require = createRequire(import.meta.url);
|
|
|
29
30
|
// whichever package.json it discovers first, which is not necessarily ours.
|
|
30
31
|
const { version: cliVersion } = require('../package.json');
|
|
31
32
|
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
33
|
+
// Auto-detect environment: prefer production mode when dist exists
|
|
34
|
+
const distPath = join(__dirname, '../dist/index.mjs');
|
|
35
|
+
const srcPath = join(__dirname, '../src/index.tsx');
|
|
36
|
+
const hasSource = existsSync(srcPath);
|
|
37
|
+
const hasDist = existsSync(distPath);
|
|
38
|
+
|
|
39
|
+
// Development mode ONLY when:
|
|
40
|
+
// 1. NODE_ENV is explicitly 'development', OR
|
|
41
|
+
// 2. dist doesn't exist but source does (fallback)
|
|
42
|
+
// Otherwise: use production mode (this is what npm users will run)
|
|
43
|
+
const isDev = process.env.NODE_ENV === 'development' ||
|
|
44
|
+
(!hasDist && hasSource);
|
|
45
|
+
|
|
46
|
+
// `b4m host ...` is b4m-host: its arguments go through untouched, before yargs or the env flags see them,
|
|
47
|
+
// and dial-stdio's stdout must carry nothing but the bridged bytes.
|
|
48
|
+
if (process.argv[2] === 'host') {
|
|
49
|
+
let handleHostCommand;
|
|
50
|
+
if (isDev) {
|
|
51
|
+
const { register } = require('tsx/esm/api');
|
|
52
|
+
register();
|
|
53
|
+
({ handleHostCommand } = await import('../src/commands/hostCommand.ts'));
|
|
54
|
+
} else {
|
|
55
|
+
({ handleHostCommand } = await import('../dist/commands/hostCommand.mjs'));
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
process.argv = [process.argv[0], process.argv[1], ...cleaned];
|
|
57
|
+
process.exit(await handleHostCommand(process.argv.slice(3)));
|
|
54
58
|
}
|
|
55
59
|
|
|
60
|
+
// --- API environment flags (--dev / --prod) ---
|
|
61
|
+
// Intercept these BEFORE yargs parses argv (see envFlags.mjs) and strip them so
|
|
62
|
+
// yargs sees a clean argv.
|
|
63
|
+
const { cleaned: cleanedArgs, envTarget, envFlags, mcpServe, serveLocal } = splitEnvFlags(process.argv.slice(2));
|
|
64
|
+
if (serveLocal && envTarget) {
|
|
65
|
+
process.stderr.write(`Error: mcp serve --local ignores the backend; drop ${envFlags.join(' ')}.\n`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
process.argv = [process.argv[0], process.argv[1], ...cleanedArgs];
|
|
69
|
+
|
|
56
70
|
const argv = await yargs(hideBin(process.argv))
|
|
57
71
|
// --dev / --prod are declared here ONLY so they appear in `--help`. The actual
|
|
58
72
|
// handling is the pre-yargs argv interception above - these yargs-side values
|
|
@@ -93,7 +107,7 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
93
107
|
})
|
|
94
108
|
.option('output-format', {
|
|
95
109
|
type: 'string',
|
|
96
|
-
description: 'Output format when using -p: text (default), json, stream-json (NDJSON)',
|
|
110
|
+
description: 'Output format when using -p: text (default), json, stream-json (NDJSON); json also applies to b4m models ls/search/show/curated',
|
|
97
111
|
choices: ['text', 'json', 'stream-json'],
|
|
98
112
|
default: 'text',
|
|
99
113
|
})
|
|
@@ -108,7 +122,7 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
108
122
|
})
|
|
109
123
|
.option('ollama-host', {
|
|
110
124
|
type: 'string',
|
|
111
|
-
description: 'Add local Ollama models to the model picker (e.g. http://localhost:11434)',
|
|
125
|
+
description: 'Add local Ollama models to the model picker (e.g. http://localhost:11434); `b4m models` remembers it',
|
|
112
126
|
})
|
|
113
127
|
// claude-compatible flags (host drop-in masquerade). Declared so a host's
|
|
114
128
|
// claude launch flags parse into named options instead of leaking into the
|
|
@@ -204,6 +218,11 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
204
218
|
description: 'Serve over streamable HTTP instead of stdio',
|
|
205
219
|
default: false,
|
|
206
220
|
})
|
|
221
|
+
.option('local', {
|
|
222
|
+
type: 'boolean',
|
|
223
|
+
description: 'Serve only the local model tools (models_*), with no Bike4Mind backend. Stdio only',
|
|
224
|
+
default: false,
|
|
225
|
+
})
|
|
207
226
|
.option('port', {
|
|
208
227
|
type: 'number',
|
|
209
228
|
description: 'Port for --http mode',
|
|
@@ -222,6 +241,7 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
222
241
|
description: 'Bearer token required by --http mode (overrides B4M_MCP_TOKEN; generated and printed when unset). Visible in process listings; prefer B4M_MCP_TOKEN',
|
|
223
242
|
})
|
|
224
243
|
.example('b4m mcp serve', 'Serve over stdio for Claude Desktop and other local clients')
|
|
244
|
+
.example('b4m mcp serve --local', 'Serve only the local model tools, without a backend')
|
|
225
245
|
.example('b4m mcp serve --http --port 7000', 'Serve over streamable HTTP on port 7000');
|
|
226
246
|
}, async () => {
|
|
227
247
|
// Handled by external command handler
|
|
@@ -256,7 +276,7 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
256
276
|
})
|
|
257
277
|
.command('skills', 'Manage your Bike4Mind skills', (yargs) => {
|
|
258
278
|
return yargs
|
|
259
|
-
.command('push <path>', 'Create or update a skill from a Claude Code SKILL.md', (yargs) => {
|
|
279
|
+
.command('push <path>', 'Create or update a skill from a Claude Code SKILL.md, and optionally publish it', (yargs) => {
|
|
260
280
|
return yargs
|
|
261
281
|
.positional('path', {
|
|
262
282
|
type: 'string',
|
|
@@ -272,15 +292,164 @@ const argv = await yargs(hideBin(process.argv))
|
|
|
272
292
|
description: "Push another author's Skill Market skill as your own without asking",
|
|
273
293
|
default: false,
|
|
274
294
|
})
|
|
295
|
+
.option('publish', {
|
|
296
|
+
type: 'boolean',
|
|
297
|
+
description: 'Also list it on the Skill Market: a new listing, or a new version of its live listing',
|
|
298
|
+
default: false,
|
|
299
|
+
})
|
|
300
|
+
.option('visibility', {
|
|
301
|
+
type: 'string',
|
|
302
|
+
choices: ['organization', 'public', 'unlisted'],
|
|
303
|
+
description: 'Who can see a new listing (with --publish)',
|
|
304
|
+
default: 'organization',
|
|
305
|
+
})
|
|
306
|
+
.option('org', {
|
|
307
|
+
type: 'string',
|
|
308
|
+
description: 'Organization id for an organization listing; optional when you belong to exactly one',
|
|
309
|
+
})
|
|
310
|
+
.option('tags', {
|
|
311
|
+
type: 'string',
|
|
312
|
+
description: 'Comma-separated listing tags (with --publish)',
|
|
313
|
+
})
|
|
314
|
+
.option('api-key', {
|
|
315
|
+
type: 'string',
|
|
316
|
+
description:
|
|
317
|
+
'Bike4Mind API key with the skills:write and me:read scopes (overrides B4M_API_KEY and the stored login). Visible in process listings; prefer B4M_API_KEY, which also takes precedence over the stored login when set, even without --publish',
|
|
318
|
+
})
|
|
275
319
|
.example('b4m skills push ~/.claude/skills/my-skill', 'Create a skill from a Claude Code skill folder')
|
|
276
|
-
.example('b4m skills push ./SKILL.md --update', 'Update the existing skill of the same name')
|
|
320
|
+
.example('b4m skills push ./SKILL.md --update', 'Update the existing skill of the same name')
|
|
321
|
+
.example('b4m skills push ./my-skill --publish --update', 'Update the skill and publish it to the Skill Market');
|
|
277
322
|
}, async () => {
|
|
278
323
|
// Handled by external command handler
|
|
279
324
|
})
|
|
280
325
|
.demandCommand(1, 'You must provide a subcommand (push)');
|
|
281
326
|
})
|
|
327
|
+
.command('host', 'Run b4m-host, which reports this machine\'s hardware and Ollama to Bike4Mind (see: b4m host --help)', {}, () => {
|
|
328
|
+
// `host` as the first argument is handled at the top of this file; reaching here means a flag came before it.
|
|
329
|
+
process.stderr.write('b4m host must be the first argument: b4m host <command> (see: b4m host --help)\n');
|
|
330
|
+
process.exit(2);
|
|
331
|
+
})
|
|
332
|
+
.command('models', 'Find, download and use local models (Ollama, Hugging Face GGUF)', (yargs) => {
|
|
333
|
+
return yargs
|
|
334
|
+
.option('server', {
|
|
335
|
+
type: 'string',
|
|
336
|
+
description: "Run ls, use, pull or rm against one of Desktop's saved model servers (see: b4m models servers)",
|
|
337
|
+
})
|
|
338
|
+
.command(['ls', 'list'], 'List models installed on the local runtime', {}, async () => {
|
|
339
|
+
// Handled by external command handler
|
|
340
|
+
})
|
|
341
|
+
.command('servers [action] [name]', "List Desktop's saved model servers, find the ones on a machine over SSH, or log in or out of one", (yargs) => {
|
|
342
|
+
return yargs
|
|
343
|
+
.positional('action', { type: 'string', choices: ['discover', 'login', 'logout'], describe: 'Find servers over SSH, or keep or remove the CLI\'s credential for a server' })
|
|
344
|
+
.positional('name', { type: 'string', describe: 'Server name, as `b4m models servers` shows it; for discover, an SSH destination' })
|
|
345
|
+
.option('port', {
|
|
346
|
+
type: 'string',
|
|
347
|
+
description: 'discover: look only at this port on that machine, instead of the usual ones',
|
|
348
|
+
})
|
|
349
|
+
.option('check-tools', {
|
|
350
|
+
type: 'boolean',
|
|
351
|
+
description: 'servers: send each OpenAI-compatible server a one-token request to see whether it accepts tool calls',
|
|
352
|
+
default: false,
|
|
353
|
+
})
|
|
354
|
+
.option('token-stdin', {
|
|
355
|
+
type: 'boolean',
|
|
356
|
+
description: 'login: read the credential from stdin instead of prompting',
|
|
357
|
+
default: false,
|
|
358
|
+
})
|
|
359
|
+
.example('b4m models servers', 'List the servers with their status')
|
|
360
|
+
.example('b4m models servers discover me@gpu-box', 'Find Ollama, LM Studio, llama-server and vLLM on gpu-box over SSH')
|
|
361
|
+
.example('b4m models servers login gpu-box', 'Enter the CLI\'s credential for gpu-box (hidden)');
|
|
362
|
+
}, async () => {
|
|
363
|
+
// Handled by external command handler
|
|
364
|
+
})
|
|
365
|
+
.command('search <query..>', 'Search Hugging Face for GGUF models', (yargs) => {
|
|
366
|
+
return yargs
|
|
367
|
+
.positional('query', { type: 'string', describe: 'Search terms' })
|
|
368
|
+
.option('include-abliterated', {
|
|
369
|
+
type: 'boolean',
|
|
370
|
+
description: 'Also list abliterated and uncensored builds, labelled and last',
|
|
371
|
+
default: false,
|
|
372
|
+
});
|
|
373
|
+
}, async () => {
|
|
374
|
+
// Handled by external command handler
|
|
375
|
+
})
|
|
376
|
+
.command('show <repo>', "Show a Hugging Face repo's GGUF builds, license and gating", (yargs) => {
|
|
377
|
+
return yargs.positional('repo', { type: 'string', describe: 'owner/repo' });
|
|
378
|
+
}, async () => {
|
|
379
|
+
// Handled by external command handler
|
|
380
|
+
})
|
|
381
|
+
.command('curated', 'List the models Bike4Mind picked, with picks for this computer first', (yargs) => {
|
|
382
|
+
return yargs
|
|
383
|
+
.option('refresh', {
|
|
384
|
+
type: 'boolean',
|
|
385
|
+
description: 'Check for a newer signed list now instead of when the last check is 6 hours old',
|
|
386
|
+
default: false,
|
|
387
|
+
})
|
|
388
|
+
.option('offline', {
|
|
389
|
+
type: 'boolean',
|
|
390
|
+
description: 'Use the last verified list on this computer (else the bundled one) with no update check (also: B4M_CURATED=off)',
|
|
391
|
+
default: false,
|
|
392
|
+
});
|
|
393
|
+
}, async () => {
|
|
394
|
+
// Handled by external command handler
|
|
395
|
+
})
|
|
396
|
+
.command('pull <ref>', 'Download a model after showing its size and license', (yargs) => {
|
|
397
|
+
return yargs
|
|
398
|
+
.positional('ref', {
|
|
399
|
+
type: 'string',
|
|
400
|
+
describe: 'owner/repo[:quant] or hf.co/owner/repo:quant (Hugging Face), or an Ollama name like qwen2.5:0.5b',
|
|
401
|
+
})
|
|
402
|
+
.option('yes', {
|
|
403
|
+
type: 'boolean',
|
|
404
|
+
description: 'Download without asking for confirmation',
|
|
405
|
+
default: false,
|
|
406
|
+
})
|
|
407
|
+
.option('accept-license', {
|
|
408
|
+
type: 'boolean',
|
|
409
|
+
description: 'Accept a non-permissive model license without a prompt',
|
|
410
|
+
default: false,
|
|
411
|
+
})
|
|
412
|
+
.option('force', {
|
|
413
|
+
type: 'boolean',
|
|
414
|
+
description: 'Download even when the fit check rates the model too large for this machine',
|
|
415
|
+
default: false,
|
|
416
|
+
})
|
|
417
|
+
.option('offline', {
|
|
418
|
+
type: 'boolean',
|
|
419
|
+
description: 'Use the last verified curated list on this computer with no update check (also: B4M_CURATED=off)',
|
|
420
|
+
default: false,
|
|
421
|
+
})
|
|
422
|
+
.example('b4m models pull Qwen/Qwen2.5-0.5B-Instruct-GGUF:Q4_K_M', 'Pull a Hugging Face GGUF build')
|
|
423
|
+
.example('b4m models pull qwen2.5:0.5b', 'Pull from the Ollama library');
|
|
424
|
+
}, async () => {
|
|
425
|
+
// Handled by external command handler
|
|
426
|
+
})
|
|
427
|
+
.command(['rm <name>', 'remove <name>'], 'Remove an installed model', (yargs) => {
|
|
428
|
+
return yargs
|
|
429
|
+
.positional('name', { type: 'string', describe: 'Installed model name' })
|
|
430
|
+
.option('yes', {
|
|
431
|
+
type: 'boolean',
|
|
432
|
+
description: 'Remove without asking for confirmation',
|
|
433
|
+
default: false,
|
|
434
|
+
});
|
|
435
|
+
}, async () => {
|
|
436
|
+
// Handled by external command handler
|
|
437
|
+
})
|
|
438
|
+
.command('use <name>', 'Make an installed model the default the CLI chats with', (yargs) => {
|
|
439
|
+
return yargs.positional('name', { type: 'string', describe: 'Installed model name' });
|
|
440
|
+
}, async () => {
|
|
441
|
+
// Handled by external command handler
|
|
442
|
+
})
|
|
443
|
+
.example('b4m models ls --ollama-host http://127.0.0.1:11434', 'Use and remember an Ollama host')
|
|
444
|
+
.demandCommand(1, 'You must provide a subcommand (ls, search, show, curated, servers, pull, rm, use)');
|
|
445
|
+
})
|
|
282
446
|
.command('update', 'Check for and install CLI updates')
|
|
283
447
|
.command('doctor', 'Run diagnostic checks on CLI installation')
|
|
448
|
+
.command('mirror <dir>', 'Mirror your notebooks into a local v2 bundle and keep it current', y =>
|
|
449
|
+
y
|
|
450
|
+
.positional('dir', { type: 'string', describe: 'Directory that holds the mirror state and bundle' })
|
|
451
|
+
.option('watch', { type: 'number', describe: 'Keep syncing, pausing this many seconds between passes' })
|
|
452
|
+
)
|
|
284
453
|
.command('acp', 'Run as an Agent Client Protocol (ACP) stdio server for editors like Zed')
|
|
285
454
|
.help()
|
|
286
455
|
.alias('help', 'h')
|
|
@@ -314,6 +483,7 @@ if (argv['no-remote-skills']) {
|
|
|
314
483
|
}
|
|
315
484
|
|
|
316
485
|
// claude-compatible flags -> B4M_* env (read by src/index.tsx init).
|
|
486
|
+
// Host-launch signal: keep in sync with HOST_FLAG_ENV_KEYS in src/bootstrap/startupTrustGates.ts.
|
|
317
487
|
// Mirrors the established bin->env->init channel (cf. --add-dir -> B4M_ADDITIONAL_DIRS).
|
|
318
488
|
if (argv['mcp-config']) {
|
|
319
489
|
process.env.B4M_MCP_CONFIG_FILE = resolve(argv['mcp-config']);
|
|
@@ -341,24 +511,11 @@ if (argv.resume) {
|
|
|
341
511
|
}
|
|
342
512
|
// Positional task (claude `<prompt>` form): seeds AND submits turn 1, stays interactive.
|
|
343
513
|
// Only when it's not a known subcommand and headless -p wasn't used.
|
|
344
|
-
const KNOWN_SUBCOMMANDS = new Set(['mcp', 'plugin', 'skills', 'update', 'doctor', 'acp']);
|
|
514
|
+
const KNOWN_SUBCOMMANDS = new Set(['mcp', 'plugin', 'skills', 'models', 'update', 'doctor', 'mirror', 'acp', 'host']);
|
|
345
515
|
if (argv.prompt === undefined && argv._.length > 0 && !KNOWN_SUBCOMMANDS.has(String(argv._[0]))) {
|
|
346
516
|
process.env.B4M_INITIAL_PROMPT = String(argv._[0]);
|
|
347
517
|
}
|
|
348
518
|
|
|
349
|
-
// Auto-detect environment: prefer production mode when dist exists
|
|
350
|
-
const distPath = join(__dirname, '../dist/index.mjs');
|
|
351
|
-
const srcPath = join(__dirname, '../src/index.tsx');
|
|
352
|
-
const hasSource = existsSync(srcPath);
|
|
353
|
-
const hasDist = existsSync(distPath);
|
|
354
|
-
|
|
355
|
-
// Development mode ONLY when:
|
|
356
|
-
// 1. NODE_ENV is explicitly 'development', OR
|
|
357
|
-
// 2. dist doesn't exist but source does (fallback)
|
|
358
|
-
// Otherwise: use production mode (this is what npm users will run)
|
|
359
|
-
const isDev = process.env.NODE_ENV === 'development' ||
|
|
360
|
-
(!hasDist && hasSource);
|
|
361
|
-
|
|
362
519
|
// Signal source mode to the app so endpoint resolution can default an
|
|
363
520
|
// otherwise-unconfigured run to the local dev server (build-time brand
|
|
364
521
|
// defaults are never injected into a source run). Set before any command
|
|
@@ -414,7 +571,14 @@ if (envTarget) {
|
|
|
414
571
|
({ applyEnvironmentFlag } = await import('../dist/commands/envCommand.mjs'));
|
|
415
572
|
}
|
|
416
573
|
|
|
417
|
-
|
|
574
|
+
// On `mcp serve` stdout is the JSON-RPC stream, so the banner goes to stderr.
|
|
575
|
+
const log = console.log;
|
|
576
|
+
if (mcpServe) console.log = console.error;
|
|
577
|
+
try {
|
|
578
|
+
await applyEnvironmentFlag(envTarget);
|
|
579
|
+
} finally {
|
|
580
|
+
console.log = log;
|
|
581
|
+
}
|
|
418
582
|
} catch (error) {
|
|
419
583
|
console.error('Failed to switch API environment:', error.message);
|
|
420
584
|
process.exit(1);
|
|
@@ -534,6 +698,30 @@ if (argv._[0] === 'skills') {
|
|
|
534
698
|
}
|
|
535
699
|
}
|
|
536
700
|
|
|
701
|
+
// Handle models subcommands (external commands)
|
|
702
|
+
if (argv._[0] === 'models') {
|
|
703
|
+
const modelsSubcommand = argv._[1];
|
|
704
|
+
|
|
705
|
+
try {
|
|
706
|
+
let handleModelsCommand;
|
|
707
|
+
|
|
708
|
+
if (isDev) {
|
|
709
|
+
const { register } = require('tsx/esm/api');
|
|
710
|
+
register();
|
|
711
|
+
const module = await import('../src/commands/modelsCommand.ts');
|
|
712
|
+
handleModelsCommand = module.handleModelsCommand;
|
|
713
|
+
} else {
|
|
714
|
+
const module = await import('../dist/commands/modelsCommand.mjs');
|
|
715
|
+
handleModelsCommand = module.handleModelsCommand;
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
process.exit(await handleModelsCommand(modelsSubcommand, argv));
|
|
719
|
+
} catch (error) {
|
|
720
|
+
console.error('Error:', error.message);
|
|
721
|
+
process.exit(1);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
|
|
537
725
|
// Handle update command (external command)
|
|
538
726
|
if (argv._[0] === 'update') {
|
|
539
727
|
try {
|
|
@@ -605,6 +793,27 @@ if (argv._[0] === 'doctor') {
|
|
|
605
793
|
}
|
|
606
794
|
}
|
|
607
795
|
|
|
796
|
+
// Handle mirror command (external command)
|
|
797
|
+
if (argv._[0] === 'mirror') {
|
|
798
|
+
try {
|
|
799
|
+
let handleMirrorCommand;
|
|
800
|
+
|
|
801
|
+
if (isDev) {
|
|
802
|
+
const { register } = require('tsx/esm/api');
|
|
803
|
+
register();
|
|
804
|
+
handleMirrorCommand = (await import('../src/commands/mirrorCommand.ts')).handleMirrorCommand;
|
|
805
|
+
} else {
|
|
806
|
+
handleMirrorCommand = (await import('../dist/commands/mirrorCommand.mjs')).handleMirrorCommand;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
await handleMirrorCommand(argv.dir, { watchSeconds: argv.watch });
|
|
810
|
+
process.exit(0);
|
|
811
|
+
} catch (error) {
|
|
812
|
+
console.error('Error:', error.message);
|
|
813
|
+
process.exit(1);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
|
|
608
817
|
if (isDev) {
|
|
609
818
|
// Note: this is about *how the CLI runs* (unbuilt TypeScript source), which is
|
|
610
819
|
// distinct from the `--dev` flag (which selects the local dev *backend*).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type EnvTarget = 'dev' | 'prod';
|
|
2
|
+
|
|
3
|
+
export declare const ENV_FLAG_MAP: Record<string, EnvTarget>;
|
|
4
|
+
|
|
5
|
+
export declare const VALUE_OPTIONS: ReadonlySet<string>;
|
|
6
|
+
|
|
7
|
+
export declare const ARRAY_OPTIONS: ReadonlySet<string>;
|
|
8
|
+
|
|
9
|
+
export interface SplitEnvFlags {
|
|
10
|
+
cleaned: string[];
|
|
11
|
+
envTarget: EnvTarget | null;
|
|
12
|
+
envFlags: string[];
|
|
13
|
+
mcpServe: boolean;
|
|
14
|
+
serveLocal: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export declare function splitEnvFlags(args: string[]): SplitEnvFlags;
|