@bike4mind/cli 3.4.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 (56) hide show
  1. package/README.md +223 -39
  2. package/bin/bike4mind-cli.mjs +301 -38
  3. package/bin/envFlags.d.mts +17 -0
  4. package/bin/envFlags.mjs +89 -0
  5. package/bin/hearth-hook.mjs +53 -7
  6. package/dist/{AgentHistoryStore-ClO2zOn6.mjs → AgentHistoryStore--J3sgO_-.mjs} +9011 -6699
  7. package/dist/ApiClient-CdO4Gamg.mjs +152 -0
  8. package/dist/BubblewrapRuntime-3jAbC60G.mjs +157 -0
  9. package/dist/ConfigStore-CausUCzY.mjs +2 -0
  10. package/dist/ConfigStore-Dusy6glb.mjs +3364 -0
  11. package/dist/{ConfigStore-CbVFLXMH.mjs → Logger-C1Wj6xla.mjs} +32880 -20779
  12. package/dist/{ProxyManager-B0-RuR2w.mjs → ProxyManager-TxEKlgdO.mjs} +88 -3
  13. package/dist/RemoteSkillSource-qTvRkaNA.mjs +455 -0
  14. package/dist/{SandboxOrchestrator-BcUv9fQ3.mjs → SandboxOrchestrator-CQwYq_uy.mjs} +26 -7
  15. package/dist/SandboxRuntimeAdapter-BsT2iLky.mjs +190 -0
  16. package/dist/SandboxRuntimeAdapter-Zg_0th7V.mjs +2 -0
  17. package/dist/SeatbeltRuntime-C2DEkrjy.mjs +194 -0
  18. package/dist/{WorkItemsClient-SeNbzvEw.mjs → WorkItemsClient-CxNZaOmc.mjs} +1 -1
  19. package/dist/agents/defaults/review.md +8 -1
  20. package/dist/agents/defaults/test.md +8 -1
  21. package/dist/buildToolSearch-DOb7mx6F.mjs +417 -0
  22. package/dist/commands/acpCommand.mjs +33 -27
  23. package/dist/commands/apiCommand.mjs +3 -5
  24. package/dist/commands/doctorCommand.mjs +2 -2
  25. package/dist/commands/envCommand.mjs +1 -1
  26. package/dist/commands/headlessCommand.mjs +118 -36
  27. package/dist/commands/hostCommand.mjs +2344 -0
  28. package/dist/commands/mcpCommand.mjs +46 -30
  29. package/dist/commands/mirrorCommand.mjs +279 -0
  30. package/dist/commands/modelsCommand.mjs +1117 -0
  31. package/dist/commands/pluginCommand.mjs +9 -9
  32. package/dist/commands/skillsCommand.mjs +404 -0
  33. package/dist/commands/updateCommand.mjs +2 -2
  34. package/dist/curated-build.json +1 -0
  35. package/dist/dist-CbViwiS9.mjs +4739 -0
  36. package/dist/dist-Citbv0y0.mjs +7864 -0
  37. package/dist/fit-CVWDiavv.mjs +200 -0
  38. package/dist/index.mjs +1001 -442
  39. package/dist/modelHub-BSB6qRFP.mjs +1963 -0
  40. package/dist/modelServers-BaegigV-.mjs +2465 -0
  41. package/dist/{package-MoDZ9cGj.mjs → package-C9pfAdGF.mjs} +1 -1
  42. package/dist/{serve-zi-B2iUT.mjs → serve-8wyGb8of.mjs} +1243 -44
  43. package/dist/store-BYeE0shc.mjs +2 -0
  44. package/dist/{store-BxmPEI3v.mjs → store-BbvSi3KK.mjs} +26 -2
  45. package/dist/types-BFIvwByC.mjs +2 -0
  46. package/dist/{types-F61_hxmG.mjs → types-CxrzVXel.mjs} +9 -5
  47. package/dist/{updateChecker-CCLVVdH0.mjs → updateChecker-BAKb8KWP.mjs} +7 -29
  48. package/package.json +17 -13
  49. package/dist/BubblewrapRuntime-5bLPTwEC.mjs +0 -72
  50. package/dist/SandboxRuntimeAdapter-BgLUVTJL.mjs +0 -57
  51. package/dist/SandboxRuntimeAdapter-Bt1wPpld.mjs +0 -2
  52. package/dist/SeatbeltRuntime-C_Y8q8Mr.mjs +0 -124
  53. package/dist/buildAgent-BeaVbpzH.mjs +0 -1992
  54. package/dist/dist-DlBq3wHu.mjs +0 -739
  55. package/dist/store-BkMur6uk.mjs +0 -2
  56. package/dist/types-I45lMh7Q.mjs +0 -2
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env node
2
+ import { b as AuthenticatedApiClient, t as ConfigStore, x as DeviceFlowClient } from "./ConfigStore-Dusy6glb.mjs";
3
+ import { t as logger } from "./Logger-C1Wj6xla.mjs";
4
+ import { t as version } from "./package-C9pfAdGF.mjs";
5
+ import { isAxiosError } from "axios";
6
+ import { Readable } from "node:stream";
7
+ //#region src/auth/OAuthClient.ts
8
+ /**
9
+ * The CLI's RFC 8628 `client_id`; the desktop app registers under its own. Typed against the
10
+ * server allowlist so dropping this id there fails this build rather than this client's logins
11
+ * (see OAUTH_DEVICE_CLIENT_IDS).
12
+ */
13
+ const CLI_OAUTH_CLIENT_ID = "b4m-cli";
14
+ /**
15
+ * The shared device-flow client, pinned to the CLI's registration.
16
+ */
17
+ var OAuthClient = class extends DeviceFlowClient {
18
+ constructor(baseURL = "http://localhost:3000") {
19
+ super({
20
+ baseUrl: baseURL,
21
+ clientId: CLI_OAUTH_CLIENT_ID
22
+ });
23
+ }
24
+ };
25
+ //#endregion
26
+ //#region src/auth/providerKeyFailure.ts
27
+ const PROVIDER_KEY_ERROR_CODES = /* @__PURE__ */ new Set(["provider_not_configured", "provider_rejected"]);
28
+ /**
29
+ * A 401 whose body names a missing or rejected AI-provider key (e.g. /api/ai/tts). The
30
+ * Bike4Mind credential was accepted, so refreshing or re-authenticating cannot fix it.
31
+ * Shared by the ApiClient refresh interceptor and mapApiError in mcp/b4mApiClient.ts.
32
+ */
33
+ function isProviderKeyFailure(data) {
34
+ const body = decodeBinaryBody(data);
35
+ if (!body || typeof body !== "object") return false;
36
+ const { errorCode } = body;
37
+ return typeof errorCode === "string" && PROVIDER_KEY_ERROR_CODES.has(errorCode);
38
+ }
39
+ /**
40
+ * An arraybuffer-typed request (every @bike4mind/sdk call, through ApiClient.fetch) gets its
41
+ * error body as raw bytes, and the refresh interceptor sees it before any caller can decode it.
42
+ */
43
+ function decodeBinaryBody(data) {
44
+ const bytes = data instanceof ArrayBuffer ? Buffer.from(data) : ArrayBuffer.isView(data) ? Buffer.from(data.buffer, data.byteOffset, data.byteLength) : void 0;
45
+ if (!bytes) return data;
46
+ try {
47
+ return JSON.parse(bytes.toString("utf8"));
48
+ } catch {
49
+ return;
50
+ }
51
+ }
52
+ //#endregion
53
+ //#region src/auth/ApiClient.ts
54
+ const USER_AGENT = `b4m-cli/${version}`;
55
+ const SIGNED_OUT_BASE_URL = "http://signed-out.invalid";
56
+ /**
57
+ * Per-request timeout. Generous by design: a waited chat (POST /api/chat with wait:true)
58
+ * runs a full server-side quest, so the bound only exists to stop a hung backend from
59
+ * wedging a caller forever, not to cap a normal long quest. Override with B4M_API_TIMEOUT_MS
60
+ * (0 disables the timeout entirely).
61
+ */
62
+ const DEFAULT_API_TIMEOUT_MS = 6e5;
63
+ function resolveTimeoutMs() {
64
+ const raw = process.env.B4M_API_TIMEOUT_MS;
65
+ if (raw === void 0 || raw.trim() === "") return DEFAULT_API_TIMEOUT_MS;
66
+ const parsed = Number(raw);
67
+ return Number.isFinite(parsed) && parsed >= 0 ? parsed : DEFAULT_API_TIMEOUT_MS;
68
+ }
69
+ /**
70
+ * The shared authenticated client, wired to the CLI's storage, logger and branding.
71
+ */
72
+ var ApiClient = class ApiClient extends AuthenticatedApiClient {
73
+ /**
74
+ * @param apiKey - When set, requests authenticate with this instance API key via
75
+ * the `x-api-key` header and the OAuth-JWT path (Bearer injection + refresh-on-401)
76
+ * is bypassed entirely. Omit to keep the default stored-JWT behavior unchanged.
77
+ */
78
+ constructor(baseURL = "http://localhost:3000", configStore, apiKey) {
79
+ super({
80
+ baseUrl: baseURL,
81
+ tokenStore: configStore || new ConfigStore(),
82
+ oauthClient: new OAuthClient(baseURL),
83
+ logger,
84
+ apiKey,
85
+ timeoutMs: resolveTimeoutMs(),
86
+ headers: {
87
+ "User-Agent": USER_AGENT,
88
+ "X-B4M-Client": USER_AGENT
89
+ },
90
+ reauthMessages: {
91
+ refreshFailed: "Authentication expired. Please run `b4m login` again.",
92
+ stillUnauthorized: "Authentication failed. Please run /login to authenticate.",
93
+ notLoggedIn: "Authentication failed: not logged in. Please run `b4m login` to authenticate."
94
+ },
95
+ isPassThrough401: isProviderKeyFailure
96
+ });
97
+ this.signedOutClient = false;
98
+ this.fetch = async (input, init = {}) => {
99
+ const headers = Object.fromEntries(new Headers(init.headers));
100
+ try {
101
+ return toFetchResponse(await this.getAxiosInstance().request({
102
+ url: input instanceof Request ? input.url : String(input),
103
+ method: init.method ?? "GET",
104
+ headers,
105
+ data: init.body ?? void 0,
106
+ signal: init.signal ?? void 0,
107
+ responseType: /text\/event-stream/i.test(headers.accept ?? "") ? "stream" : "arraybuffer",
108
+ ...init.redirect && init.redirect !== "follow" ? { maxRedirects: 0 } : {}
109
+ }));
110
+ } catch (error) {
111
+ if (isAxiosError(error) && error.response) return toFetchResponse(error.response);
112
+ throw error;
113
+ }
114
+ };
115
+ }
116
+ /** True for a client made by `ApiClient.whileSignedOut`. */
117
+ get signedOut() {
118
+ return this.signedOutClient;
119
+ }
120
+ /**
121
+ * A client for a signed-out session: every request rejects before it leaves the process, so a
122
+ * cloud call that a signed-out path failed to skip surfaces as a sign-in message, never traffic.
123
+ */
124
+ static whileSignedOut(configStore) {
125
+ const client = new ApiClient(SIGNED_OUT_BASE_URL, configStore);
126
+ client.signedOutClient = true;
127
+ client.getAxiosInstance().defaults.adapter = async (config) => {
128
+ throw new Error(`Not signed in, so ${config.url ?? "the request"} was not sent to Bike4Mind. Run /login to sign in.`);
129
+ };
130
+ return client;
131
+ }
132
+ get baseURL() {
133
+ return this.getAxiosInstance().defaults.baseURL ?? "";
134
+ }
135
+ };
136
+ function toFetchResponse(response) {
137
+ const headers = new Headers();
138
+ for (const [name, value] of Object.entries(response.headers)) if (value !== void 0 && value !== null) headers.set(name, Array.isArray(value) ? value.join(", ") : String(value));
139
+ const body = [
140
+ 101,
141
+ 204,
142
+ 205,
143
+ 304
144
+ ].includes(response.status) ? null : response.data instanceof Readable ? Readable.toWeb(response.data) : response.data;
145
+ return new Response(body, {
146
+ status: response.status,
147
+ statusText: response.statusText,
148
+ headers
149
+ });
150
+ }
151
+ //#endregion
152
+ export { isProviderKeyFailure as n, OAuthClient as r, ApiClient as t };
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env node
2
+ import { t as logger } from "./Logger-C1Wj6xla.mjs";
3
+ import { a as getContainerSocketPaths, c as resolveSandboxPath, o as getProtectedWorkspacePaths, s as isBinaryAvailable, t as assertProxyPort } from "./SandboxRuntimeAdapter-BsT2iLky.mjs";
4
+ import { lstatSync, mkdirSync, statSync } from "fs";
5
+ import os from "os";
6
+ import path from "path";
7
+ //#region src/sandbox/runtime/BubblewrapRuntime.ts
8
+ /**
9
+ * Linux Bubblewrap (bwrap) runtime implementation.
10
+ *
11
+ * Uses bubblewrap to create a sandboxed environment with:
12
+ * - Read-only system paths (/usr, /lib, /bin, etc.)
13
+ * - Read-write access only to the working directory
14
+ * - Denied paths mounted as empty tmpfs
15
+ * - Process and network namespace isolation; egress only through the filtering proxy
16
+ */
17
+ /** System paths to bind read-only into the sandbox */
18
+ const SYSTEM_RO_BINDS = [
19
+ "/usr",
20
+ "/bin",
21
+ "/lib",
22
+ "/lib64",
23
+ "/sbin",
24
+ "/etc"
25
+ ];
26
+ /** Paths that need special handling (dev, proc, tmp) */
27
+ const SPECIAL_MOUNTS = {
28
+ dev: "/dev",
29
+ proc: "/proc",
30
+ tmp: "/tmp"
31
+ };
32
+ /** Where the proxy's host unix socket is mounted; /run is never bound from the host, so nothing shadows it. */
33
+ const SANDBOX_PROXY_SOCKET = "/run/b4m/proxy.sock";
34
+ /** Readiness probes for the in-sandbox relay, 50ms apart. */
35
+ const RELAY_READY_ATTEMPTS = 100;
36
+ /**
37
+ * Listen on the sandbox's own loopback at the proxy port, so the proxy env vars work unchanged, and
38
+ * forward to the mounted socket. The command runs as "$1" once the relay accepts connections.
39
+ */
40
+ function relayScript(proxyPort) {
41
+ return [
42
+ `socat TCP-LISTEN:${proxyPort},bind=127.0.0.1,fork,reuseaddr UNIX-CONNECT:${SANDBOX_PROXY_SOCKET} </dev/null >/dev/null 2>&1 &`,
43
+ "attempts=0",
44
+ `until (: </dev/tcp/127.0.0.1/${proxyPort}) 2>/dev/null; do`,
45
+ " attempts=$((attempts + 1))",
46
+ ` if [ "$attempts" -ge ${RELAY_READY_ATTEMPTS} ]; then echo 'sandbox: network relay failed to start' >&2; exit 1; fi`,
47
+ " sleep 0.05",
48
+ "done",
49
+ "exec bash -c \"$1\""
50
+ ].join("\n");
51
+ }
52
+ var BubblewrapRuntime = class {
53
+ constructor() {
54
+ this.platform = "linux";
55
+ this.name = "bubblewrap";
56
+ }
57
+ isAvailable() {
58
+ return isBinaryAvailable("bwrap");
59
+ }
60
+ wrapCommand(options) {
61
+ const { command, cwd, filesystemConfig, env } = options;
62
+ const expandedDenied = filesystemConfig.deniedPaths.map(resolveSandboxPath);
63
+ const expandedAllowed = filesystemConfig.allowedReadPaths.map(resolveSandboxPath);
64
+ const args = [];
65
+ for (const sysPath of SYSTEM_RO_BINDS) args.push("--ro-bind-try", sysPath, sysPath);
66
+ args.push("--dev", SPECIAL_MOUNTS.dev);
67
+ args.push("--proc", SPECIAL_MOUNTS.proc);
68
+ args.push("--tmpfs", SPECIAL_MOUNTS.tmp);
69
+ const homeDir = os.homedir();
70
+ args.push("--ro-bind", homeDir, homeDir);
71
+ for (const allowedPath of expandedAllowed) if (allowedPath !== homeDir && !allowedPath.startsWith(`${homeDir}${path.sep}`)) args.push("--ro-bind-try", allowedPath, allowedPath);
72
+ args.push("--bind", cwd, cwd);
73
+ const protectedPaths = getProtectedWorkspacePaths(cwd);
74
+ const resolvedCwd = resolveSandboxPath(cwd);
75
+ for (const protectedPath of protectedPaths) {
76
+ const resolvedPath = resolveSandboxPath(protectedPath);
77
+ if (resolvedCwd === resolvedPath || resolvedCwd.startsWith(`${resolvedPath}${path.sep}`)) throw new Error(`Cannot use protected metadata as sandbox cwd: ${cwd}`);
78
+ }
79
+ const projectDir = path.join(cwd, ".bike4mind");
80
+ mkdirSync(projectDir, { recursive: true });
81
+ for (const protectedPath of protectedPaths) {
82
+ try {
83
+ if (lstatSync(protectedPath).isSymbolicLink()) throw new Error(`Cannot protect sandbox metadata symlink: ${protectedPath}`);
84
+ } catch (error) {
85
+ if (!(error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR"].includes(String(error.code)))) throw error;
86
+ }
87
+ const resolvedPath = resolveSandboxPath(protectedPath);
88
+ if (protectedPath === projectDir || pathKind(resolvedPath) !== "missing") args.push("--ro-bind", resolvedPath, resolvedPath);
89
+ }
90
+ for (const deniedPath of expandedDenied) {
91
+ const kind = pathKind(deniedPath);
92
+ if (kind === "dir") args.push("--tmpfs", deniedPath);
93
+ else if (kind === "file") args.push("--ro-bind", "/dev/null", deniedPath);
94
+ }
95
+ if (!options.allowContainerSockets) {
96
+ const isDenied = (p) => expandedDenied.some((d) => p === d || p.startsWith(`${d}${path.sep}`));
97
+ for (const entry of getContainerSocketPaths()) {
98
+ let socketPath;
99
+ let kind;
100
+ try {
101
+ socketPath = resolveSandboxPath(entry.path);
102
+ kind = pathKind(socketPath);
103
+ } catch (error) {
104
+ if (error instanceof Error && "code" in error && ["EACCES", "ELOOP"].includes(String(error.code))) {
105
+ logger.debug(`Sandbox: skipping unreadable container socket path ${entry.path}: ${error.code}`);
106
+ continue;
107
+ }
108
+ throw error;
109
+ }
110
+ if (isDenied(socketPath)) continue;
111
+ if (resolvedCwd === socketPath || resolvedCwd.startsWith(`${socketPath}${path.sep}`)) {
112
+ logger.debug(`Sandbox: not masking container socket path ${socketPath}, it contains the working directory`);
113
+ continue;
114
+ }
115
+ if (kind === "dir") args.push("--tmpfs", socketPath);
116
+ else if (kind === "file") args.push("--ro-bind", "/dev/null", socketPath);
117
+ }
118
+ }
119
+ let relayPort = null;
120
+ if (options.networkEnabled) {
121
+ if (options.proxyPort === void 0 || !options.proxySocketPath) throw new Error("Sandbox network on Linux requires a running filtering proxy with a unix socket");
122
+ assertProxyPort(options.proxyPort);
123
+ if (!isBinaryAvailable("socat")) throw new Error("Sandbox network on Linux requires socat; install it or turn sandbox network off");
124
+ relayPort = options.proxyPort;
125
+ args.push("--ro-bind", options.proxySocketPath, SANDBOX_PROXY_SOCKET);
126
+ }
127
+ args.push("--unshare-all");
128
+ args.push("--unshare-net");
129
+ args.push("--die-with-parent");
130
+ if (options.seccompProfile) args.push("--seccomp", options.seccompProfile);
131
+ for (const [key, value] of Object.entries(env ?? {})) args.push("--setenv", key, value);
132
+ args.push("--chdir", cwd);
133
+ if (relayPort === null) args.push("bash", "-c", command);
134
+ else args.push("bash", "-c", relayScript(relayPort), "b4m-sandbox", command);
135
+ const commandString = ["bwrap", ...args.map(shellEscape)].join(" ");
136
+ return {
137
+ executable: "bwrap",
138
+ args,
139
+ env: env ?? {},
140
+ commandString
141
+ };
142
+ }
143
+ };
144
+ function pathKind(p) {
145
+ try {
146
+ return statSync(p).isDirectory() ? "dir" : "file";
147
+ } catch (error) {
148
+ if (error instanceof Error && "code" in error && ["ENOENT", "ENOTDIR"].includes(String(error.code))) return "missing";
149
+ throw error;
150
+ }
151
+ }
152
+ function shellEscape(str) {
153
+ if (/^[a-zA-Z0-9._/=:-]+$/.test(str)) return str;
154
+ return `'${str.replace(/'/g, "'\\''")}'`;
155
+ }
156
+ //#endregion
157
+ export { BubblewrapRuntime };
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export { t as ConfigStore } from "./ConfigStore-Dusy6glb.mjs";