@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.
Files changed (51) hide show
  1. package/README.md +86 -4
  2. package/bin/bike4mind-cli.mjs +249 -40
  3. package/bin/envFlags.d.mts +17 -0
  4. package/bin/envFlags.mjs +89 -0
  5. package/dist/{AgentHistoryStore-DgqmcVLN.mjs → AgentHistoryStore--J3sgO_-.mjs} +3794 -1368
  6. package/dist/{ApiClient-_JrM_xWw.mjs → ApiClient-CdO4Gamg.mjs} +22 -3
  7. package/dist/BubblewrapRuntime-3jAbC60G.mjs +157 -0
  8. package/dist/ConfigStore-CausUCzY.mjs +2 -0
  9. package/dist/ConfigStore-Dusy6glb.mjs +3364 -0
  10. package/dist/{ConfigStore-BwqsQ0U9.mjs → Logger-C1Wj6xla.mjs} +32672 -21643
  11. package/dist/{ProxyManager-B0-RuR2w.mjs → ProxyManager-TxEKlgdO.mjs} +88 -3
  12. package/dist/{SandboxOrchestrator-BcUv9fQ3.mjs → SandboxOrchestrator-CQwYq_uy.mjs} +26 -7
  13. package/dist/SandboxRuntimeAdapter-BsT2iLky.mjs +190 -0
  14. package/dist/SandboxRuntimeAdapter-Zg_0th7V.mjs +2 -0
  15. package/dist/SeatbeltRuntime-C2DEkrjy.mjs +194 -0
  16. package/dist/{WorkItemsClient-CERTDrhT.mjs → WorkItemsClient-CxNZaOmc.mjs} +1 -1
  17. package/dist/agents/defaults/review.md +8 -1
  18. package/dist/agents/defaults/test.md +8 -1
  19. package/dist/buildToolSearch-DOb7mx6F.mjs +417 -0
  20. package/dist/commands/acpCommand.mjs +25 -19
  21. package/dist/commands/apiCommand.mjs +3 -5
  22. package/dist/commands/doctorCommand.mjs +2 -2
  23. package/dist/commands/envCommand.mjs +1 -1
  24. package/dist/commands/headlessCommand.mjs +117 -36
  25. package/dist/commands/hostCommand.mjs +2344 -0
  26. package/dist/commands/mcpCommand.mjs +45 -30
  27. package/dist/commands/mirrorCommand.mjs +279 -0
  28. package/dist/commands/modelsCommand.mjs +1117 -0
  29. package/dist/commands/pluginCommand.mjs +9 -9
  30. package/dist/commands/skillsCommand.mjs +174 -29
  31. package/dist/commands/updateCommand.mjs +2 -2
  32. package/dist/curated-build.json +1 -0
  33. package/dist/dist-CbViwiS9.mjs +4739 -0
  34. package/dist/dist-Citbv0y0.mjs +7864 -0
  35. package/dist/fit-CVWDiavv.mjs +200 -0
  36. package/dist/index.mjs +853 -417
  37. package/dist/modelHub-BSB6qRFP.mjs +1963 -0
  38. package/dist/modelServers-BaegigV-.mjs +2465 -0
  39. package/dist/{package-CQaam4Dq.mjs → package-C9pfAdGF.mjs} +1 -1
  40. package/dist/{serve-CFxUhjml.mjs → serve-8wyGb8of.mjs} +595 -26
  41. package/dist/types-BFIvwByC.mjs +2 -0
  42. package/dist/{types-F61_hxmG.mjs → types-CxrzVXel.mjs} +9 -5
  43. package/dist/{updateChecker-CCLVVdH0.mjs → updateChecker-BAKb8KWP.mjs} +7 -29
  44. package/package.json +16 -13
  45. package/dist/BubblewrapRuntime-5bLPTwEC.mjs +0 -72
  46. package/dist/SandboxRuntimeAdapter-BgLUVTJL.mjs +0 -57
  47. package/dist/SandboxRuntimeAdapter-Bt1wPpld.mjs +0 -2
  48. package/dist/SeatbeltRuntime-C_Y8q8Mr.mjs +0 -124
  49. package/dist/buildToolSearch-D9GEK91u.mjs +0 -2351
  50. package/dist/dist-Ul2qwn5x.mjs +0 -624
  51. package/dist/types-I45lMh7Q.mjs +0 -2
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env node
2
+ import "./Logger-C1Wj6xla.mjs";
3
+ import { S as vramNeedsLlamaServer, b as ollamaNumCtx, v as estimateFitFromSize } from "./modelHub-BSB6qRFP.mjs";
4
+ import { t as version } from "./package-C9pfAdGF.mjs";
5
+ import { D as PRODUCTION_CURATED_KEYS, U as loadCuratedManifest, _ as resolveCuratedUrl, h as probeHardware, n as CuratedStore, t as CuratedListSource, u as curatedStoreRoot, w as BUNDLED_CURATED_JSON_TEXT } from "./dist-Citbv0y0.mjs";
6
+ import { Q as formatBytes, it as largestProjectorBytes } from "./modelServers-BaegigV-.mjs";
7
+ import path from "node:path";
8
+ import { homedir } from "node:os";
9
+ //#region src/models/curatedList.ts
10
+ const CHECK_TIMEOUT_MS = 8e3;
11
+ const CHECK_BUDGET_MS = 3e3;
12
+ /**
13
+ * The CLI's curated list: the bundled one, or a newer signed one fetched from the URL baked at build time and cached.
14
+ * tsdown replaces the two B4M_CURATED build variables, so a published CLI ignores the environment for them. The store
15
+ * opens on first use, so commands that never read the list never touch it.
16
+ */
17
+ function createCliCuratedList(options) {
18
+ const env = options.env ?? process.env;
19
+ const log = options.log ?? ((message) => console.error(message));
20
+ const dev = false;
21
+ const keys = [...options.keys ?? PRODUCTION_CURATED_KEYS, ...[]];
22
+ const url = resolveCuratedUrl("", dev);
23
+ const offline = options.offline || env.B4M_CURATED === "off";
24
+ const offered = url !== null && keys.length > 0;
25
+ const dataDir = options.dataDir ?? path.join(homedir(), ".bike4mind");
26
+ let opened;
27
+ const open = () => opened ??= new CuratedListSource({
28
+ url,
29
+ keys,
30
+ store: new CuratedStore(curatedStoreRoot(dataDir, dev)),
31
+ bundledText: BUNDLED_CURATED_JSON_TEXT,
32
+ load: (json) => loadCuratedManifest(log, json, { cliVersion: version }),
33
+ allowLoopbackHttp: dev,
34
+ network: !offline,
35
+ userAgent: "Bike4Mind-CLI",
36
+ timeoutMs: CHECK_TIMEOUT_MS,
37
+ now: options.now,
38
+ fetch: options.fetch,
39
+ log,
40
+ onChange: () => {}
41
+ });
42
+ return {
43
+ async manifest() {
44
+ const source = open();
45
+ await source.loaded();
46
+ const budget = new AbortController();
47
+ const timer = setTimeout(() => budget.abort(), CHECK_BUDGET_MS);
48
+ timer.unref();
49
+ try {
50
+ await source.checkIfDue(budget.signal);
51
+ } finally {
52
+ clearTimeout(timer);
53
+ }
54
+ return source.current();
55
+ },
56
+ async refresh() {
57
+ const source = open();
58
+ await source.loaded();
59
+ await source.checkNow();
60
+ },
61
+ origin() {
62
+ if (!offered) return null;
63
+ const view = open().view();
64
+ const from = view.origin === "updated" ? `Updated online, sequence ${view.sequence}` : "Bundled with this CLI";
65
+ const notes = [offline ? "updates are off" : view.check === "failed" && "the last update check failed", view.stale && "this list is old"].filter(Boolean);
66
+ return {
67
+ text: notes.length > 0 ? `${from} (${notes.join("; ")})` : from,
68
+ origin: view.origin,
69
+ sequence: view.sequence,
70
+ check: offline ? "off" : view.check,
71
+ stale: view.stale,
72
+ checkedAt: view.checkedAt
73
+ };
74
+ }
75
+ };
76
+ }
77
+ //#endregion
78
+ //#region src/models/fit.ts
79
+ /**
80
+ * Fit verdicts for `b4m models` and the MCP model tools: the shared size-only estimate (estimateFitFromSize in
81
+ * @bike4mind/common) against this machine's hardware probe.
82
+ */
83
+ /** What makes an Intel card's memory readable on Linux, for hardware where vramNeedsLlamaServer holds. */
84
+ const LLAMA_SERVER_VRAM_HELP = "Linux does not report it; put a llama.cpp SYCL or Vulkan build of llama-server first on PATH, with its ggml-sycl or ggml-vulkan library beside it, and b4m reads it from there.";
85
+ const FIT_LABELS = {
86
+ fits: "fits",
87
+ tight: "tight",
88
+ "too-large": "too large",
89
+ unknown: "unknown"
90
+ };
91
+ function isLoopbackUrl(baseUrl) {
92
+ let host;
93
+ try {
94
+ host = new URL(baseUrl).hostname.toLowerCase().replace(/^\[|\]$/g, "");
95
+ } catch {
96
+ return false;
97
+ }
98
+ return host === "localhost" || host.endsWith(".localhost") || host === "::1" || host === "0.0.0.0" || /^127\./.test(host);
99
+ }
100
+ /** Probes this machine once per reader; a remote runtime or a failed probe reads as unknown. */
101
+ function machineReader(probe = () => probeHardware()) {
102
+ let probed;
103
+ return async (baseUrl) => {
104
+ if (baseUrl && !isLoopbackUrl(baseUrl)) return { unknown: `Ollama at ${baseUrl} runs on another machine, whose memory this one cannot read` };
105
+ probed ??= probe().catch(() => null);
106
+ const hardware = await probed;
107
+ return hardware?.totalMemoryBytes ? { hardware } : { unknown: "This machine's memory could not be read" };
108
+ };
109
+ }
110
+ function machineLabel({ hardware }) {
111
+ const ram = `${formatBytes(hardware.totalMemoryBytes)} RAM`;
112
+ if (hardware.memoryKind === "unified") {
113
+ const label = `${hardware.chip ?? hardware.gpuName ?? "unified memory"}, ${formatBytes(hardware.totalMemoryBytes)}`;
114
+ return hardware.gpuVendor === "intel" ? `${label}, rated on the CPU` : label;
115
+ }
116
+ if (hardware.memoryKind === "discrete" && hardware.gpuMemoryBytes) return `${hardware.gpuName ?? "GPU"} with ${formatBytes(hardware.gpuMemoryBytes)}, ${ram}`;
117
+ if (vramNeedsLlamaServer(hardware)) return `Intel GPU of unknown memory (a SYCL or Vulkan llama-server on PATH reads it), rated on the CPU, ${ram}`;
118
+ return hardware.memoryKind === "discrete" ? `GPU of unknown memory, rated on the CPU, ${ram}` : `no GPU, ${ram}`;
119
+ }
120
+ const TIGHT_NOTE = "Close other apps first, or this computer may slow down.";
121
+ const contextLabel = (tokens) => tokens >= 1024 ? `${Math.round(tokens / 1024)}K` : String(tokens);
122
+ /**
123
+ * Rates a download of `sizeBytes` at the num_ctx the CLI's Ollama backend requests for it: the trained length
124
+ * capped by ollamaNumCtx, or the cap itself when the length is unknown.
125
+ */
126
+ function rateDownload(sizeBytes, reading, trainedContext) {
127
+ if ("unknown" in reading) return {
128
+ verdict: "unknown",
129
+ detail: `${reading.unknown}.`
130
+ };
131
+ if (!(sizeBytes > 0)) return {
132
+ verdict: "unknown",
133
+ detail: "The download size is unknown."
134
+ };
135
+ const rated = rateOnHardware(sizeBytes, reading.hardware, trainedContext);
136
+ return reading.hardware.confidence === "low" ? {
137
+ ...rated,
138
+ gpuUnread: true
139
+ } : rated;
140
+ }
141
+ /**
142
+ * A need past its limit and that limit as shown, with more decimals while they would read the same, then rounded
143
+ * apart to whole MB.
144
+ */
145
+ function needAndLimit(needBytes, limitBytes) {
146
+ const shown = [formatBytes(needBytes), formatBytes(limitBytes)];
147
+ for (let digits = 2; digits <= 3 && shown[0] === shown[1]; digits++) {
148
+ const fine = (bytes) => `${(bytes / 1e9).toFixed(digits)} GB`;
149
+ shown.splice(0, 2, fine(needBytes), fine(limitBytes));
150
+ }
151
+ if (shown[0] === shown[1]) return [`${Math.ceil(needBytes / 1e6)} MB`, `${Math.floor(limitBytes / 1e6)} MB`];
152
+ return shown;
153
+ }
154
+ function rateOnHardware(sizeBytes, hardware, trainedContext) {
155
+ const known = trainedContext !== null && trainedContext > 0;
156
+ const context = ollamaNumCtx(known ? trainedContext : Infinity);
157
+ const fit = estimateFitFromSize(sizeBytes, hardware, context);
158
+ const usable = fit.budgetBytes - fit.marginBytes;
159
+ const machine = fit.budgetBytes + fit.ramPoolBytes - fit.marginBytes;
160
+ const at = `before context memory, at ${known ? "" : "up to "}the ${contextLabel(context)} context the CLI requests`;
161
+ const need = (shown) => `about ${shown} ${at}`;
162
+ const budget = `the ${formatBytes(usable)} a model can use ${fit.cpuOnly ? "in RAM" : "in GPU memory"} here`;
163
+ const rough = "Rough estimate from the file size";
164
+ if (fit.level === "too-large") {
165
+ const overMachine = fit.needBytes > machine;
166
+ if (!overMachine && fit.offloadBytes <= sizeBytes) return {
167
+ verdict: fit.level,
168
+ detail: `${rough}: ${need(formatBytes(fit.needBytes))}, too much of the ${formatBytes(machine)} this computer can hold for a model to leave room for that.`
169
+ };
170
+ const [shown, limit] = needAndLimit(fit.needBytes, overMachine ? machine : usable);
171
+ const past = overMachine ? `the ${limit} this computer can hold for a model` : `the ${limit} of GPU memory a model can use here`;
172
+ return {
173
+ verdict: fit.level,
174
+ detail: `${rough}: ${need(shown)}, more than ${past}.`
175
+ };
176
+ }
177
+ const about = `${rough}: ${need(formatBytes(fit.needBytes))}`;
178
+ if (fit.level === "tight") {
179
+ const why = fit.offloadBytes > sizeBytes / 2 ? `more than ${budget}, so most of it runs on the CPU from system RAM and replies will be slow` : fit.offloadBytes > 0 ? `more than ${budget}, so part of it runs from system RAM and replies are slower` : `close to ${budget}`;
180
+ return {
181
+ verdict: fit.level,
182
+ detail: `${about}, ${why}. ${TIGHT_NOTE}`
183
+ };
184
+ }
185
+ return {
186
+ verdict: fit.level,
187
+ detail: `${about}, of ${budget}.`
188
+ };
189
+ }
190
+ function fitForHubBuild(build, detail, reading) {
191
+ return rateDownload(build.sizeBytes > 0 && build.files.every((file) => file.sizeBytes > 0) && detail.projectors.every((projector) => projector.sizeBytes > 0) ? build.sizeBytes + largestProjectorBytes(detail) : 0, reading, detail.gguf?.contextLength ?? null);
192
+ }
193
+ /** The verdict for what a pull plan downloads, projector included. */
194
+ async function fitForPlan(plan, read) {
195
+ const reading = plan.target.server ? { unknown: "A saved model server's memory cannot be read from this machine" } : await read(plan.target.runtime.baseUrl);
196
+ if (plan.kind === "ollama") return rateDownload(plan.manifest.sizeBytes, reading, null);
197
+ return fitForHubBuild(plan.build, plan.detail, reading);
198
+ }
199
+ //#endregion
200
+ export { machineLabel as a, fitForPlan as i, LLAMA_SERVER_VRAM_HELP as n, machineReader as o, fitForHubBuild as r, createCliCuratedList as s, FIT_LABELS as t };