@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.
- package/README.md +223 -39
- package/bin/bike4mind-cli.mjs +301 -38
- package/bin/envFlags.d.mts +17 -0
- package/bin/envFlags.mjs +89 -0
- package/bin/hearth-hook.mjs +53 -7
- package/dist/{AgentHistoryStore-ClO2zOn6.mjs → AgentHistoryStore--J3sgO_-.mjs} +9011 -6699
- package/dist/ApiClient-CdO4Gamg.mjs +152 -0
- package/dist/BubblewrapRuntime-3jAbC60G.mjs +157 -0
- package/dist/ConfigStore-CausUCzY.mjs +2 -0
- package/dist/ConfigStore-Dusy6glb.mjs +3364 -0
- package/dist/{ConfigStore-CbVFLXMH.mjs → Logger-C1Wj6xla.mjs} +32880 -20779
- package/dist/{ProxyManager-B0-RuR2w.mjs → ProxyManager-TxEKlgdO.mjs} +88 -3
- package/dist/RemoteSkillSource-qTvRkaNA.mjs +455 -0
- 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-SeNbzvEw.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 +33 -27
- 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 +118 -36
- package/dist/commands/hostCommand.mjs +2344 -0
- package/dist/commands/mcpCommand.mjs +46 -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 +404 -0
- 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 +1001 -442
- package/dist/modelHub-BSB6qRFP.mjs +1963 -0
- package/dist/modelServers-BaegigV-.mjs +2465 -0
- package/dist/{package-MoDZ9cGj.mjs → package-C9pfAdGF.mjs} +1 -1
- package/dist/{serve-zi-B2iUT.mjs → serve-8wyGb8of.mjs} +1243 -44
- package/dist/store-BYeE0shc.mjs +2 -0
- package/dist/{store-BxmPEI3v.mjs → store-BbvSi3KK.mjs} +26 -2
- 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 +17 -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/buildAgent-BeaVbpzH.mjs +0 -1992
- package/dist/dist-DlBq3wHu.mjs +0 -739
- package/dist/store-BkMur6uk.mjs +0 -2
- package/dist/types-I45lMh7Q.mjs +0 -2
|
@@ -1,11 +1,65 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { A as createTodoStore, D as createGetFileStructureTool, Et as SessionStore, F as createResumeAgentTool, H as buildCliToolList, I as createBackgroundAgentTools, L as createAgentDelegateTool, M as createSkillTool, O as createWorkItemTools, P as createCoordinateTaskTool, R as FallbackLlmBackend, U as generateCliTools, V as PermissionManager, _ as createSseBackend, a as loadProjectContext, at as signInUncheckedHeadlessMessage, c as checkSavedSignIn, d as attachLocalModels, g as withSignedOutLocalDefault, gt as wrapTools, h as resolveSignedOutHeadlessModel, i as buildProjectAgentStore, j as createWriteTodosTool, k as createFindDefinitionTool, l as settleSignInRefresh, m as resolveHeadlessModel, n as BackgroundAgentManager, o as McpManager, p as defaultLlmBackendDeps, pt as ReActAgent, r as SubagentOrchestrator, rt as SignedOutCloudBackend, s as buildSandbox, t as AgentHistoryStore, tt as SIGN_IN_EXPIRED_HEADLESS, ut as buildSystemPrompt, vt as setWebSocketToolExecutor, wt as CheckpointStore, xt as CustomCommandStore, yt as classifyCommandRisk } from "../AgentHistoryStore--J3sgO_-.mjs";
|
|
3
|
+
import { D as sanitizeTerminalText, c as ToolCatalog, f as toolCategory, l as commandTextOf, t as ConfigStore, v as requireApiUrl } from "../ConfigStore-Dusy6glb.mjs";
|
|
4
|
+
import { l as OllamaBackend, u as OpenAICompatibleBackend } from "../dist-CbViwiS9.mjs";
|
|
5
|
+
import { t as logger } from "../Logger-C1Wj6xla.mjs";
|
|
6
|
+
import { t as RemoteSkillSource } from "../RemoteSkillSource-qTvRkaNA.mjs";
|
|
7
|
+
import { r as reconstructTurnBlocks, t as WorkItemsClient } from "../WorkItemsClient-CxNZaOmc.mjs";
|
|
8
|
+
import { t as ApiClient } from "../ApiClient-CdO4Gamg.mjs";
|
|
6
9
|
import { randomBytes } from "crypto";
|
|
7
10
|
import { v4 } from "uuid";
|
|
8
11
|
import { readFile } from "fs/promises";
|
|
12
|
+
//#region src/commands/headlessOllama.ts
|
|
13
|
+
/** Per argument, so one large object (a verbose models list) cannot flood stderr. */
|
|
14
|
+
const MAX_DIAGNOSTIC_ARG_CHARS = 4096;
|
|
15
|
+
function capped(text) {
|
|
16
|
+
if (text.length <= 4096) return text;
|
|
17
|
+
return `${text.slice(0, MAX_DIAGNOSTIC_ARG_CHARS)}... [${text.length - MAX_DIAGNOSTIC_ARG_CHARS} more chars]`;
|
|
18
|
+
}
|
|
19
|
+
function renderDiagnostic(value) {
|
|
20
|
+
if (typeof value !== "object" || value === null || value instanceof Error) return String(value);
|
|
21
|
+
const ancestors = [];
|
|
22
|
+
try {
|
|
23
|
+
return JSON.stringify(value, function(_key, inner) {
|
|
24
|
+
if (inner instanceof Error) return String(inner);
|
|
25
|
+
if (typeof inner !== "object" || inner === null) return inner;
|
|
26
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this) ancestors.pop();
|
|
27
|
+
if (ancestors.includes(inner)) return "[Circular]";
|
|
28
|
+
ancestors.push(inner);
|
|
29
|
+
return inner;
|
|
30
|
+
}) ?? String(value);
|
|
31
|
+
} catch {
|
|
32
|
+
return String(value);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Local model diagnostics must leave stdout available for the headless result protocol. */
|
|
36
|
+
function createHeadlessLlmBackendDeps(verbose) {
|
|
37
|
+
const loggerWith = (redact = (text) => text) => {
|
|
38
|
+
const writeDiagnostic = (...args) => {
|
|
39
|
+
process.stderr.write(`${sanitizeTerminalText(args.map((arg) => capped(redact(renderDiagnostic(arg)))).join(" "))}\n`);
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
debug: (...args) => {
|
|
43
|
+
if (verbose) writeDiagnostic(...args);
|
|
44
|
+
},
|
|
45
|
+
info: writeDiagnostic,
|
|
46
|
+
warn: writeDiagnostic,
|
|
47
|
+
error: writeDiagnostic
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
createMultiBackend: defaultLlmBackendDeps.createMultiBackend,
|
|
52
|
+
createOllamaBackend: (host, options) => new OllamaBackend(host, loggerWith(options?.redact), {
|
|
53
|
+
fetch: options?.fetch,
|
|
54
|
+
requestSettings: options?.requestSettings
|
|
55
|
+
}),
|
|
56
|
+
createOpenAICompatibleBackend: (options) => new OpenAICompatibleBackend({
|
|
57
|
+
...options,
|
|
58
|
+
logger: loggerWith()
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
9
63
|
//#region src/commands/headlessProtocol.ts
|
|
10
64
|
/**
|
|
11
65
|
* Headless stream-JSON protocol contract.
|
|
@@ -272,14 +326,27 @@ const headlessSandboxLog = {
|
|
|
272
326
|
info: (line) => void process.stderr.write(`${line}\n`),
|
|
273
327
|
warn: (line) => void process.stderr.write(`${line}\n`)
|
|
274
328
|
};
|
|
329
|
+
const STDIN_HINT_DELAY_MS = 3e3;
|
|
330
|
+
const STDIN_HINT = "Waiting for input on stdin. If you are not piping anything in, add </dev/null.\n";
|
|
275
331
|
/** Read all data from stdin if it's being piped (non-TTY). Returns empty string if no piped data. */
|
|
276
332
|
async function readStdin() {
|
|
277
333
|
if (process.stdin.isTTY) return "";
|
|
278
334
|
return new Promise((resolve, reject) => {
|
|
279
335
|
const chunks = [];
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
process.stdin.on("
|
|
336
|
+
const hintTimer = setTimeout(() => process.stderr.write(STDIN_HINT), STDIN_HINT_DELAY_MS);
|
|
337
|
+
hintTimer.unref();
|
|
338
|
+
process.stdin.on("data", (chunk) => {
|
|
339
|
+
clearTimeout(hintTimer);
|
|
340
|
+
chunks.push(chunk);
|
|
341
|
+
});
|
|
342
|
+
process.stdin.on("end", () => {
|
|
343
|
+
clearTimeout(hintTimer);
|
|
344
|
+
resolve(Buffer.concat(chunks).toString("utf-8").trim());
|
|
345
|
+
});
|
|
346
|
+
process.stdin.on("error", (err) => {
|
|
347
|
+
clearTimeout(hintTimer);
|
|
348
|
+
reject(err);
|
|
349
|
+
});
|
|
283
350
|
});
|
|
284
351
|
}
|
|
285
352
|
const silentLogger = {
|
|
@@ -322,38 +389,51 @@ async function handleHeadlessCommand(options) {
|
|
|
322
389
|
try {
|
|
323
390
|
await customCommandStore.loadCommands();
|
|
324
391
|
} catch {}
|
|
325
|
-
const
|
|
326
|
-
if (
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
process.exit(1);
|
|
392
|
+
const signIn = await checkSavedSignIn(configStore, (rejected) => new ApiClient(requireApiUrl(config.apiConfig), configStore).refreshSession(rejected));
|
|
393
|
+
if (signIn.status === "expired") process.stderr.write(`${SIGN_IN_EXPIRED_HEADLESS}\n`);
|
|
394
|
+
if (signIn.status === "unchecked") process.stderr.write(`${signInUncheckedHeadlessMessage(signIn.reason)}\n`);
|
|
395
|
+
const signedOut = signIn.status !== "signed-in";
|
|
396
|
+
let apiClient;
|
|
397
|
+
if (signedOut) apiClient = ApiClient.whileSignedOut(configStore);
|
|
398
|
+
else {
|
|
399
|
+
let apiBaseURL;
|
|
400
|
+
try {
|
|
401
|
+
apiBaseURL = requireApiUrl(config.apiConfig);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
process.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
404
|
+
process.exit(1);
|
|
405
|
+
}
|
|
406
|
+
apiClient = new ApiClient(apiBaseURL, configStore);
|
|
341
407
|
}
|
|
342
|
-
|
|
343
|
-
if (process.env.B4M_NO_REMOTE_SKILLS !== "1" && config.preferences.enableRemoteSkills !== false) try {
|
|
408
|
+
if (!signedOut && process.env.B4M_NO_REMOTE_SKILLS !== "1" && config.preferences.enableRemoteSkills !== false) try {
|
|
344
409
|
customCommandStore.setRemoteSource(new RemoteSkillSource(apiClient));
|
|
345
410
|
await customCommandStore.mergeRemoteCommands();
|
|
346
411
|
} catch {}
|
|
347
|
-
|
|
412
|
+
let serverLlm;
|
|
413
|
+
if (signedOut) {
|
|
414
|
+
setWebSocketToolExecutor(null);
|
|
415
|
+
serverLlm = new SignedOutCloudBackend(config.defaultModel);
|
|
416
|
+
} else serverLlm = (await createSseBackend({
|
|
348
417
|
apiClient,
|
|
349
|
-
model: config.defaultModel
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
418
|
+
model: config.defaultModel,
|
|
419
|
+
getSessionId: () => session.id
|
|
420
|
+
})).llm;
|
|
421
|
+
const attached = await attachLocalModels(serverLlm, config, {
|
|
422
|
+
servers: signedOut ? "all" : "default",
|
|
423
|
+
onNotice: (text) => process.stderr.write(`Notice: ${sanitizeTerminalText(text)}\n`),
|
|
424
|
+
...signedOut && {
|
|
425
|
+
signedOut,
|
|
426
|
+
detectOllama: defaultLlmBackendDeps.detectOllama
|
|
427
|
+
}
|
|
428
|
+
}, createHeadlessLlmBackendDeps(options.verbose));
|
|
429
|
+
const { llm } = attached;
|
|
430
|
+
const models = signedOut ? await withSignedOutLocalDefault(attached, config) : attached.models;
|
|
431
|
+
for (const warning of attached.warnings) process.stderr.write(`${sanitizeTerminalText(warning)}\n`);
|
|
432
|
+
const { modelInfo, warning } = signedOut ? resolveSignedOutHeadlessModel(models, config, attached) : resolveHeadlessModel(models, config, attached);
|
|
433
|
+
if (warning) process.stderr.write(`Warning: ${sanitizeTerminalText(warning)}\n`);
|
|
354
434
|
llm.currentModel = modelInfo.id;
|
|
355
435
|
const effectiveLlm = config.fallbackModels && config.fallbackModels.length > 0 ? new FallbackLlmBackend(llm, config.fallbackModels, (fromModel, toModel, error) => {
|
|
356
|
-
process.stderr.write(
|
|
436
|
+
process.stderr.write(`\u26A0\uFE0F Model "${fromModel}" failed (${sanitizeTerminalText(error.message)}). Falling back to "${toModel}"...\n`);
|
|
357
437
|
}) : llm;
|
|
358
438
|
const session = {
|
|
359
439
|
id: v4(),
|
|
@@ -436,7 +516,7 @@ async function handleHeadlessCommand(options) {
|
|
|
436
516
|
const resumeAgentTool = createResumeAgentTool(orchestrator, historyStore, backgroundManager);
|
|
437
517
|
const todoStore = createTodoStore();
|
|
438
518
|
const writeTodosTool = createWriteTodosTool(todoStore);
|
|
439
|
-
const workItemTools = config.preferences.enableWorkItemTools ? createWorkItemTools(new WorkItemsClient(apiClient)) : [];
|
|
519
|
+
const workItemTools = config.preferences.enableWorkItemTools && !signedOut ? createWorkItemTools(new WorkItemsClient(apiClient)) : [];
|
|
440
520
|
const enableSkillTool = config.preferences.enableSkillTool !== false;
|
|
441
521
|
const skillTool = enableSkillTool ? createSkillTool({
|
|
442
522
|
customCommandStore,
|
|
@@ -545,7 +625,7 @@ async function handleHeadlessCommand(options) {
|
|
|
545
625
|
await sessionStore.save(finalSession);
|
|
546
626
|
switch (outputFormat) {
|
|
547
627
|
case "text":
|
|
548
|
-
process.stdout.write(result.finalAnswer + "\n");
|
|
628
|
+
process.stdout.write((process.stdout.isTTY ? sanitizeTerminalText(result.finalAnswer) : result.finalAnswer) + "\n");
|
|
549
629
|
break;
|
|
550
630
|
case "json": {
|
|
551
631
|
const jsonResult = {
|
|
@@ -584,6 +664,7 @@ async function handleHeadlessCommand(options) {
|
|
|
584
664
|
await mcpManager.disconnect().catch(() => {});
|
|
585
665
|
setWebSocketToolExecutor(null);
|
|
586
666
|
agent.removeAllListeners();
|
|
667
|
+
await settleSignInRefresh();
|
|
587
668
|
process.exit(0);
|
|
588
669
|
} catch (error) {
|
|
589
670
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -596,9 +677,10 @@ async function handleHeadlessCommand(options) {
|
|
|
596
677
|
type: "error",
|
|
597
678
|
error: message
|
|
598
679
|
});
|
|
599
|
-
else process.stderr.write(`Error: ${message}\n`);
|
|
680
|
+
else process.stderr.write(`Error: ${sanitizeTerminalText(message)}\n`);
|
|
681
|
+
await settleSignInRefresh();
|
|
600
682
|
process.exit(1);
|
|
601
683
|
}
|
|
602
684
|
}
|
|
603
685
|
//#endregion
|
|
604
|
-
export { handleHeadlessCommand, headlessSandboxLog };
|
|
686
|
+
export { STDIN_HINT, STDIN_HINT_DELAY_MS, handleHeadlessCommand, headlessSandboxLog, readStdin };
|