@bike4mind/cli 0.2.11-fix-cli-edit-file.17320 → 0.2.11-fix-cli-socket-hangup-error-handling.17320
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/dist/{artifactExtractor-BZNU5FMW.js → artifactExtractor-3KB44W7B.js} +1 -1
- package/dist/{chunk-WCYNJOOX.js → chunk-3OX632TE.js} +0 -1
- package/dist/{chunk-DGAIF2QC.js → chunk-7JR6VASX.js} +2 -2
- package/dist/{chunk-RBZRTCAY.js → chunk-7ORA6KGN.js} +2 -2
- package/dist/{chunk-RA3CZOUX.js → chunk-HPYQM2B7.js} +2 -2
- package/dist/{chunk-SQBLLN7K.js → chunk-JYH72REB.js} +1 -1
- package/dist/{create-4KCG4N2U.js → create-MSSVWSVO.js} +3 -3
- package/dist/index.js +172 -223
- package/dist/{llmMarkdownGenerator-TUFLBYA3.js → llmMarkdownGenerator-LCCZ76BQ.js} +1 -1
- package/dist/{markdownGenerator-2WSEU4QD.js → markdownGenerator-4OF7GEBT.js} +1 -1
- package/dist/{mementoService-75KFGFQT.js → mementoService-A6UR5AZY.js} +3 -3
- package/dist/{src-UHKJ3EHY.js → src-7UYCXFTE.js} +1 -1
- package/dist/{src-JZRDAJFC.js → src-GFWGZLJE.js} +2 -2
- package/dist/{subtractCredits-MOVABDWW.js → subtractCredits-L52DZ3SP.js} +3 -3
- package/package.json +6 -6
|
@@ -6,12 +6,12 @@ import {
|
|
|
6
6
|
getSettingsByNames,
|
|
7
7
|
obfuscateApiKey,
|
|
8
8
|
secureParameters
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-JYH72REB.js";
|
|
10
10
|
import {
|
|
11
11
|
ApiKeyType,
|
|
12
12
|
MementoTier,
|
|
13
13
|
isSupportedEmbeddingModel
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-3OX632TE.js";
|
|
15
15
|
|
|
16
16
|
// ../../b4m-core/packages/services/dist/src/apiKeyService/get.js
|
|
17
17
|
import { z } from "zod";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
BadRequestError,
|
|
4
4
|
secureParameters
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-JYH72REB.js";
|
|
6
6
|
import {
|
|
7
7
|
GenericCreditDeductTransaction,
|
|
8
8
|
ImageEditUsageTransaction,
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
RealtimeVoiceUsageTransaction,
|
|
11
11
|
TextGenerationUsageTransaction,
|
|
12
12
|
TransferCreditTransaction
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-3OX632TE.js";
|
|
14
14
|
|
|
15
15
|
// ../../b4m-core/packages/services/dist/src/creditService/subtractCredits.js
|
|
16
16
|
import { z } from "zod";
|
|
@@ -7,11 +7,11 @@ import {
|
|
|
7
7
|
getSettingsMap,
|
|
8
8
|
getSettingsValue,
|
|
9
9
|
secureParameters
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-JYH72REB.js";
|
|
11
11
|
import {
|
|
12
12
|
KnowledgeType,
|
|
13
13
|
SupportedFabFileMimeTypes
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-3OX632TE.js";
|
|
15
15
|
|
|
16
16
|
// ../../b4m-core/packages/services/dist/src/fabFileService/create.js
|
|
17
17
|
import { z } from "zod";
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
dayjsConfig_default,
|
|
17
17
|
extractSnippetMeta,
|
|
18
18
|
settingsMap
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-3OX632TE.js";
|
|
20
20
|
|
|
21
21
|
// ../../b4m-core/packages/utils/dist/src/storage/S3Storage.js
|
|
22
22
|
import { S3Client, PutObjectCommand, DeleteObjectCommand, GetObjectCommand, HeadObjectCommand } from "@aws-sdk/client-s3";
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
createFabFile,
|
|
4
4
|
createFabFileSchema
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-HPYQM2B7.js";
|
|
6
|
+
import "./chunk-JYH72REB.js";
|
|
7
7
|
import "./chunk-AMDXHL6S.js";
|
|
8
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-3OX632TE.js";
|
|
9
9
|
import "./chunk-PDX44BCA.js";
|
|
10
10
|
export {
|
|
11
11
|
createFabFile,
|
package/dist/index.js
CHANGED
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
getEffectiveApiKey,
|
|
5
5
|
getOpenWeatherKey,
|
|
6
6
|
getSerperKey
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-7JR6VASX.js";
|
|
8
|
+
import "./chunk-7ORA6KGN.js";
|
|
9
|
+
import "./chunk-HPYQM2B7.js";
|
|
10
10
|
import {
|
|
11
11
|
BFLImageService,
|
|
12
12
|
BaseStorage,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
OpenAIBackend,
|
|
16
16
|
OpenAIImageService,
|
|
17
17
|
XAIImageService
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-JYH72REB.js";
|
|
19
19
|
import {
|
|
20
20
|
Logger
|
|
21
21
|
} from "./chunk-AMDXHL6S.js";
|
|
@@ -73,7 +73,7 @@ import {
|
|
|
73
73
|
XAI_IMAGE_MODELS,
|
|
74
74
|
b4mLLMTools,
|
|
75
75
|
getMcpProviderMetadata
|
|
76
|
-
} from "./chunk-
|
|
76
|
+
} from "./chunk-3OX632TE.js";
|
|
77
77
|
import {
|
|
78
78
|
__require
|
|
79
79
|
} from "./chunk-PDX44BCA.js";
|
|
@@ -988,8 +988,8 @@ import { Box as Box6 } from "ink";
|
|
|
988
988
|
import React6 from "react";
|
|
989
989
|
import { Box as Box5, Text as Text6 } from "ink";
|
|
990
990
|
import Spinner from "ink-spinner";
|
|
991
|
-
var ThoughtStream = React6.memo(function ThoughtStream2({
|
|
992
|
-
return /* @__PURE__ */ React6.createElement(Box5, { flexDirection: "column", gap: 1 },
|
|
991
|
+
var ThoughtStream = React6.memo(function ThoughtStream2({ steps }) {
|
|
992
|
+
return /* @__PURE__ */ React6.createElement(Box5, { flexDirection: "column", gap: 1 }, steps.map((step, index) => /* @__PURE__ */ React6.createElement(Box5, { key: index, flexDirection: "column" }, step.type === "thought" && /* @__PURE__ */ React6.createElement(Box5, null, /* @__PURE__ */ React6.createElement(Text6, { color: "magenta" }, "\u{1F914} Thought: "), /* @__PURE__ */ React6.createElement(Text6, null, step.content)), step.type === "action" && /* @__PURE__ */ React6.createElement(Box5, { flexDirection: "column" }, /* @__PURE__ */ React6.createElement(Box5, null, /* @__PURE__ */ React6.createElement(Text6, { color: "yellow" }, "\u26A1 Action: "), /* @__PURE__ */ React6.createElement(Text6, { bold: true }, step.metadata?.toolName || "unknown")), step.metadata?.toolInput && /* @__PURE__ */ React6.createElement(Box5, { paddingLeft: 2 }, /* @__PURE__ */ React6.createElement(Text6, { dimColor: true }, JSON.stringify(step.metadata.toolInput, null, 2)))), step.type === "observation" && /* @__PURE__ */ React6.createElement(Box5, { flexDirection: "column" }, /* @__PURE__ */ React6.createElement(Box5, null, /* @__PURE__ */ React6.createElement(Text6, { color: "blue" }, "\u{1F4CA} Observation: ")), /* @__PURE__ */ React6.createElement(Box5, { paddingLeft: 2 }, /* @__PURE__ */ React6.createElement(Text6, null, step.content))), step.type === "final_answer" && /* @__PURE__ */ React6.createElement(Box5, { flexDirection: "column" }, /* @__PURE__ */ React6.createElement(Box5, null, /* @__PURE__ */ React6.createElement(Text6, { color: "green", bold: true }, "\u2705 Final Answer:", " ")), /* @__PURE__ */ React6.createElement(Box5, { paddingLeft: 2 }, /* @__PURE__ */ React6.createElement(Text6, null, step.content)), step.metadata?.tokenUsage && /* @__PURE__ */ React6.createElement(Box5, { paddingLeft: 2 }, /* @__PURE__ */ React6.createElement(Text6, { dimColor: true }, "(", step.metadata.tokenUsage.total, " tokens)"))))), !steps.some((s) => s.type === "final_answer") && /* @__PURE__ */ React6.createElement(Box5, null, /* @__PURE__ */ React6.createElement(Text6, { color: "yellow" }, /* @__PURE__ */ React6.createElement(Spinner, { type: "dots" })), /* @__PURE__ */ React6.createElement(Text6, null, " ", steps.length === 0 ? "Thinking..." : "Processing...")));
|
|
993
993
|
});
|
|
994
994
|
|
|
995
995
|
// src/store/index.ts
|
|
@@ -1034,6 +1034,12 @@ var useCliStore = create((set) => ({
|
|
|
1034
1034
|
// UI state
|
|
1035
1035
|
isThinking: false,
|
|
1036
1036
|
setIsThinking: (thinking) => set({ isThinking: thinking }),
|
|
1037
|
+
agentSteps: [],
|
|
1038
|
+
addAgentStep: (step) => set((state) => ({
|
|
1039
|
+
agentSteps: [...state.agentSteps, step]
|
|
1040
|
+
})),
|
|
1041
|
+
setAgentSteps: (steps) => set({ agentSteps: steps }),
|
|
1042
|
+
clearAgentSteps: () => set({ agentSteps: [] }),
|
|
1037
1043
|
// Permission prompt
|
|
1038
1044
|
permissionPrompt: null,
|
|
1039
1045
|
setPermissionPrompt: (prompt) => set({ permissionPrompt: prompt }),
|
|
@@ -1048,10 +1054,11 @@ var useCliStore = create((set) => ({
|
|
|
1048
1054
|
// src/components/AgentThinking.tsx
|
|
1049
1055
|
var AgentThinking = React7.memo(function AgentThinking2() {
|
|
1050
1056
|
const isThinking = useCliStore((state) => state.isThinking);
|
|
1057
|
+
const agentSteps = useCliStore((state) => state.agentSteps);
|
|
1051
1058
|
if (!isThinking) {
|
|
1052
1059
|
return null;
|
|
1053
1060
|
}
|
|
1054
|
-
return /* @__PURE__ */ React7.createElement(Box6, { paddingX: 1, marginBottom: 1 }, /* @__PURE__ */ React7.createElement(ThoughtStream, {
|
|
1061
|
+
return /* @__PURE__ */ React7.createElement(Box6, { paddingX: 1, marginBottom: 1 }, /* @__PURE__ */ React7.createElement(ThoughtStream, { steps: agentSteps }));
|
|
1055
1062
|
});
|
|
1056
1063
|
|
|
1057
1064
|
// src/components/PermissionPrompt.tsx
|
|
@@ -1089,10 +1096,7 @@ function PermissionPrompt({
|
|
|
1089
1096
|
{ label: "\u2713 Allow once", value: "allow-once" },
|
|
1090
1097
|
{ label: "\u2717 Deny", value: "deny" }
|
|
1091
1098
|
];
|
|
1092
|
-
const
|
|
1093
|
-
const rawArgsString = typeof args === "string" ? args : JSON.stringify(args, null, 2);
|
|
1094
|
-
const argsString = rawArgsString.length > MAX_ARGS_LENGTH ? rawArgsString.slice(0, MAX_ARGS_LENGTH) + `
|
|
1095
|
-
... (${rawArgsString.length - MAX_ARGS_LENGTH} more chars)` : rawArgsString;
|
|
1099
|
+
const argsString = typeof args === "string" ? args : JSON.stringify(args, null, 2);
|
|
1096
1100
|
return /* @__PURE__ */ React8.createElement(Box7, { flexDirection: "column", borderStyle: "bold", borderColor: "yellow", padding: 1, marginY: 1 }, /* @__PURE__ */ React8.createElement(Box7, null, /* @__PURE__ */ React8.createElement(Text7, { bold: true, color: "yellow" }, "\u26A0\uFE0F Permission Required")), /* @__PURE__ */ React8.createElement(Box7, { marginTop: 1 }, /* @__PURE__ */ React8.createElement(Text7, { dimColor: true }, "Tool: "), /* @__PURE__ */ React8.createElement(Text7, { bold: true, color: "cyan" }, toolName)), toolDescription && /* @__PURE__ */ React8.createElement(Box7, null, /* @__PURE__ */ React8.createElement(Text7, { dimColor: true }, "Action: "), /* @__PURE__ */ React8.createElement(Text7, null, toolDescription)), /* @__PURE__ */ React8.createElement(Box7, { marginTop: 1, flexDirection: "column" }, /* @__PURE__ */ React8.createElement(Text7, { bold: true }, "Arguments:"), /* @__PURE__ */ React8.createElement(Box7, { paddingLeft: 2, flexDirection: "column" }, /* @__PURE__ */ React8.createElement(Text7, { dimColor: true }, argsString))), preview && /* @__PURE__ */ React8.createElement(Box7, { marginTop: 1, flexDirection: "column" }, /* @__PURE__ */ React8.createElement(Text7, { bold: true }, "Preview:"), /* @__PURE__ */ React8.createElement(Box7, { borderStyle: "single", borderColor: "gray", paddingX: 1, flexDirection: "column" }, renderDiffPreview(preview))), !canBeTrusted && /* @__PURE__ */ React8.createElement(Box7, { marginTop: 1 }, /* @__PURE__ */ React8.createElement(Text7, { color: "red", dimColor: true }, "Note: This tool cannot be trusted due to its dangerous nature.")), /* @__PURE__ */ React8.createElement(Box7, { marginTop: 1 }, /* @__PURE__ */ React8.createElement(SelectInput, { items, onSelect: (item) => onResponse(item.value) })));
|
|
1097
1101
|
}
|
|
1098
1102
|
|
|
@@ -5485,8 +5489,8 @@ async function processAndStoreImages(images, context) {
|
|
|
5485
5489
|
const buffer = await downloadImage(image);
|
|
5486
5490
|
const fileType = await fileTypeFromBuffer2(buffer);
|
|
5487
5491
|
const filename = `${uuidv46()}.${fileType?.ext}`;
|
|
5488
|
-
const
|
|
5489
|
-
return
|
|
5492
|
+
const path16 = await context.imageGenerateStorage.upload(buffer, filename, {});
|
|
5493
|
+
return path16;
|
|
5490
5494
|
}));
|
|
5491
5495
|
}
|
|
5492
5496
|
async function updateQuestAndReturnMarkdown(storedImageUrls, context) {
|
|
@@ -6698,8 +6702,8 @@ async function processAndStoreImage(imageUrl, context) {
|
|
|
6698
6702
|
const buffer = await downloadImage2(imageUrl);
|
|
6699
6703
|
const fileType = await fileTypeFromBuffer3(buffer);
|
|
6700
6704
|
const filename = `${uuidv47()}.${fileType?.ext}`;
|
|
6701
|
-
const
|
|
6702
|
-
return
|
|
6705
|
+
const path16 = await context.imageGenerateStorage.upload(buffer, filename, {});
|
|
6706
|
+
return path16;
|
|
6703
6707
|
}
|
|
6704
6708
|
async function updateQuestAndReturnMarkdown2(storedImagePath, context) {
|
|
6705
6709
|
await context.onFinish?.("edit_image", storedImagePath);
|
|
@@ -9487,104 +9491,6 @@ BLOCKED OPERATIONS:
|
|
|
9487
9491
|
})
|
|
9488
9492
|
};
|
|
9489
9493
|
|
|
9490
|
-
// ../../b4m-core/packages/services/dist/src/llm/tools/implementation/editLocalFile/index.js
|
|
9491
|
-
import { promises as fs11 } from "fs";
|
|
9492
|
-
import { existsSync as existsSync7 } from "fs";
|
|
9493
|
-
import path13 from "path";
|
|
9494
|
-
import { diffLines as diffLines3 } from "diff";
|
|
9495
|
-
function generateDiff(original, modified) {
|
|
9496
|
-
const differences = diffLines3(original, modified);
|
|
9497
|
-
let diffString = "";
|
|
9498
|
-
let additions = 0;
|
|
9499
|
-
let deletions = 0;
|
|
9500
|
-
differences.forEach((part) => {
|
|
9501
|
-
if (part.added) {
|
|
9502
|
-
additions += part.count || 0;
|
|
9503
|
-
diffString += part.value.split("\n").filter((line) => line).map((line) => `+ ${line}`).join("\n");
|
|
9504
|
-
if (diffString && !diffString.endsWith("\n"))
|
|
9505
|
-
diffString += "\n";
|
|
9506
|
-
} else if (part.removed) {
|
|
9507
|
-
deletions += part.count || 0;
|
|
9508
|
-
diffString += part.value.split("\n").filter((line) => line).map((line) => `- ${line}`).join("\n");
|
|
9509
|
-
if (diffString && !diffString.endsWith("\n"))
|
|
9510
|
-
diffString += "\n";
|
|
9511
|
-
}
|
|
9512
|
-
});
|
|
9513
|
-
return { additions, deletions, diff: diffString.trim() };
|
|
9514
|
-
}
|
|
9515
|
-
async function editLocalFile(params) {
|
|
9516
|
-
const { path: filePath, old_string, new_string } = params;
|
|
9517
|
-
const normalizedPath = path13.normalize(filePath);
|
|
9518
|
-
const resolvedPath = path13.resolve(process.cwd(), normalizedPath);
|
|
9519
|
-
const cwd = path13.resolve(process.cwd());
|
|
9520
|
-
if (!resolvedPath.startsWith(cwd)) {
|
|
9521
|
-
throw new Error(`Access denied: Cannot edit files outside of current working directory`);
|
|
9522
|
-
}
|
|
9523
|
-
if (!existsSync7(resolvedPath)) {
|
|
9524
|
-
throw new Error(`File not found: ${filePath}`);
|
|
9525
|
-
}
|
|
9526
|
-
const currentContent = await fs11.readFile(resolvedPath, "utf-8");
|
|
9527
|
-
if (!currentContent.includes(old_string)) {
|
|
9528
|
-
const preview = old_string.length > 100 ? old_string.substring(0, 100) + "..." : old_string;
|
|
9529
|
-
throw new Error(`String to replace not found in file. Make sure the old_string matches exactly (including whitespace and line endings). Searched for: "${preview}"`);
|
|
9530
|
-
}
|
|
9531
|
-
const occurrences = currentContent.split(old_string).length - 1;
|
|
9532
|
-
if (occurrences > 1) {
|
|
9533
|
-
throw new Error(`Found ${occurrences} occurrences of the string to replace. Please provide a more specific old_string that matches exactly one location.`);
|
|
9534
|
-
}
|
|
9535
|
-
const newContent = currentContent.replace(old_string, new_string);
|
|
9536
|
-
await fs11.writeFile(resolvedPath, newContent, "utf-8");
|
|
9537
|
-
const diffResult = generateDiff(old_string, new_string);
|
|
9538
|
-
return `File edited successfully: ${filePath}
|
|
9539
|
-
Changes: +${diffResult.additions} lines, -${diffResult.deletions} lines
|
|
9540
|
-
|
|
9541
|
-
Diff:
|
|
9542
|
-
${diffResult.diff}`;
|
|
9543
|
-
}
|
|
9544
|
-
var editLocalFileTool = {
|
|
9545
|
-
name: "edit_file",
|
|
9546
|
-
implementation: (context) => ({
|
|
9547
|
-
toolFn: async (value) => {
|
|
9548
|
-
const params = value;
|
|
9549
|
-
context.logger.info(`\u{1F4DD} EditLocalFile: Editing file`, {
|
|
9550
|
-
path: params.path,
|
|
9551
|
-
oldStringLength: params.old_string.length,
|
|
9552
|
-
newStringLength: params.new_string.length
|
|
9553
|
-
});
|
|
9554
|
-
try {
|
|
9555
|
-
const result = await editLocalFile(params);
|
|
9556
|
-
context.logger.info("\u2705 EditLocalFile: Success", { path: params.path });
|
|
9557
|
-
return result;
|
|
9558
|
-
} catch (error) {
|
|
9559
|
-
context.logger.error("\u274C EditLocalFile: Failed", error);
|
|
9560
|
-
throw error;
|
|
9561
|
-
}
|
|
9562
|
-
},
|
|
9563
|
-
toolSchema: {
|
|
9564
|
-
name: "edit_file",
|
|
9565
|
-
description: "Edit a file by replacing a specific string with new content. The old_string must match exactly one location in the file (including whitespace). Use this for precise edits to existing files. For creating new files or complete rewrites, use create_file instead.",
|
|
9566
|
-
parameters: {
|
|
9567
|
-
type: "object",
|
|
9568
|
-
properties: {
|
|
9569
|
-
path: {
|
|
9570
|
-
type: "string",
|
|
9571
|
-
description: "Path to the file to edit (relative to current working directory)"
|
|
9572
|
-
},
|
|
9573
|
-
old_string: {
|
|
9574
|
-
type: "string",
|
|
9575
|
-
description: "The exact string to find and replace. Must match exactly one location in the file, including all whitespace and line endings."
|
|
9576
|
-
},
|
|
9577
|
-
new_string: {
|
|
9578
|
-
type: "string",
|
|
9579
|
-
description: "The string to replace old_string with. Can be empty to delete the old_string."
|
|
9580
|
-
}
|
|
9581
|
-
},
|
|
9582
|
-
required: ["path", "old_string", "new_string"]
|
|
9583
|
-
}
|
|
9584
|
-
}
|
|
9585
|
-
})
|
|
9586
|
-
};
|
|
9587
|
-
|
|
9588
9494
|
// ../../b4m-core/packages/services/dist/src/llm/tools/index.js
|
|
9589
9495
|
var tools = {
|
|
9590
9496
|
dice_roll: diceRollTool,
|
|
@@ -9610,7 +9516,6 @@ var tools = {
|
|
|
9610
9516
|
planet_visibility: planetVisibilityTool,
|
|
9611
9517
|
file_read: fileReadTool,
|
|
9612
9518
|
create_file: createFileTool,
|
|
9613
|
-
edit_local_file: editLocalFileTool,
|
|
9614
9519
|
glob_files: globFilesTool,
|
|
9615
9520
|
grep_search: grepSearchTool,
|
|
9616
9521
|
delete_file: deleteFileTool,
|
|
@@ -9854,10 +9759,10 @@ var ToolErrorType;
|
|
|
9854
9759
|
// src/utils/diffPreview.ts
|
|
9855
9760
|
import * as Diff from "diff";
|
|
9856
9761
|
import { readFile } from "fs/promises";
|
|
9857
|
-
import { existsSync as
|
|
9762
|
+
import { existsSync as existsSync7 } from "fs";
|
|
9858
9763
|
async function generateFileDiffPreview(args) {
|
|
9859
9764
|
try {
|
|
9860
|
-
if (!
|
|
9765
|
+
if (!existsSync7(args.path)) {
|
|
9861
9766
|
const lines2 = args.content.split("\n");
|
|
9862
9767
|
const preview = lines2.slice(0, 20).join("\n");
|
|
9863
9768
|
const hasMore = lines2.length > 20;
|
|
@@ -9879,26 +9784,18 @@ ${preview}${hasMore ? `
|
|
|
9879
9784
|
// Show 3 lines of context around changes
|
|
9880
9785
|
);
|
|
9881
9786
|
const lines = patch.split("\n");
|
|
9882
|
-
const
|
|
9883
|
-
return
|
|
9787
|
+
const diffLines3 = lines.slice(4);
|
|
9788
|
+
return diffLines3.join("\n");
|
|
9884
9789
|
} catch (error) {
|
|
9885
9790
|
return `[Error generating diff preview: ${error instanceof Error ? error.message : "Unknown error"}]`;
|
|
9886
9791
|
}
|
|
9887
9792
|
}
|
|
9888
|
-
function generateEditLocalFilePreview(args) {
|
|
9889
|
-
const patch = Diff.createPatch(args.path, args.old_string, args.new_string, "Current", "Proposed", { context: 3 });
|
|
9890
|
-
const lines = patch.split("\n");
|
|
9891
|
-
const diffLines4 = lines.slice(4);
|
|
9892
|
-
return `[Edit in: ${args.path}]
|
|
9893
|
-
|
|
9894
|
-
${diffLines4.join("\n")}`;
|
|
9895
|
-
}
|
|
9896
9793
|
async function generateFileDeletePreview(args) {
|
|
9897
9794
|
try {
|
|
9898
|
-
if (!
|
|
9795
|
+
if (!existsSync7(args.path)) {
|
|
9899
9796
|
return `[File does not exist: ${args.path}]`;
|
|
9900
9797
|
}
|
|
9901
|
-
const stats = await import("fs/promises").then((
|
|
9798
|
+
const stats = await import("fs/promises").then((fs13) => fs13.stat(args.path));
|
|
9902
9799
|
return `[File will be deleted]
|
|
9903
9800
|
|
|
9904
9801
|
Path: ${args.path}
|
|
@@ -9910,8 +9807,8 @@ Last modified: ${stats.mtime.toLocaleString()}`;
|
|
|
9910
9807
|
}
|
|
9911
9808
|
|
|
9912
9809
|
// src/utils/Logger.ts
|
|
9913
|
-
import
|
|
9914
|
-
import
|
|
9810
|
+
import fs11 from "fs/promises";
|
|
9811
|
+
import path13 from "path";
|
|
9915
9812
|
import os2 from "os";
|
|
9916
9813
|
var Logger2 = class _Logger {
|
|
9917
9814
|
constructor() {
|
|
@@ -9934,9 +9831,9 @@ var Logger2 = class _Logger {
|
|
|
9934
9831
|
*/
|
|
9935
9832
|
async initialize(sessionId) {
|
|
9936
9833
|
this.sessionId = sessionId;
|
|
9937
|
-
const debugDir =
|
|
9938
|
-
await
|
|
9939
|
-
this.logFilePath =
|
|
9834
|
+
const debugDir = path13.join(os2.homedir(), ".bike4mind", "debug");
|
|
9835
|
+
await fs11.mkdir(debugDir, { recursive: true });
|
|
9836
|
+
this.logFilePath = path13.join(debugDir, `${sessionId}.txt`);
|
|
9940
9837
|
await this.writeToFile("INFO", "=== CLI SESSION START ===");
|
|
9941
9838
|
}
|
|
9942
9839
|
/**
|
|
@@ -10000,7 +9897,7 @@ var Logger2 = class _Logger {
|
|
|
10000
9897
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").substring(0, 19);
|
|
10001
9898
|
const logEntry = `[${timestamp}] [${level}] ${message}
|
|
10002
9899
|
`;
|
|
10003
|
-
await
|
|
9900
|
+
await fs11.appendFile(this.logFilePath, logEntry, "utf-8");
|
|
10004
9901
|
} catch (error) {
|
|
10005
9902
|
console.error("File logging failed:", error);
|
|
10006
9903
|
}
|
|
@@ -10146,15 +10043,15 @@ var Logger2 = class _Logger {
|
|
|
10146
10043
|
async cleanupOldLogs() {
|
|
10147
10044
|
if (!this.fileLoggingEnabled) return;
|
|
10148
10045
|
try {
|
|
10149
|
-
const debugDir =
|
|
10150
|
-
const files = await
|
|
10046
|
+
const debugDir = path13.join(os2.homedir(), ".bike4mind", "debug");
|
|
10047
|
+
const files = await fs11.readdir(debugDir);
|
|
10151
10048
|
const now = Date.now();
|
|
10152
10049
|
const thirtyDaysAgo = now - 30 * 24 * 60 * 60 * 1e3;
|
|
10153
10050
|
for (const file of files) {
|
|
10154
|
-
const filePath =
|
|
10155
|
-
const stats = await
|
|
10051
|
+
const filePath = path13.join(debugDir, file);
|
|
10052
|
+
const stats = await fs11.stat(filePath);
|
|
10156
10053
|
if (stats.mtime.getTime() < thirtyDaysAgo) {
|
|
10157
|
-
await
|
|
10054
|
+
await fs11.unlink(filePath);
|
|
10158
10055
|
}
|
|
10159
10056
|
}
|
|
10160
10057
|
} catch (error) {
|
|
@@ -10248,21 +10145,21 @@ var NoOpStorage = class extends BaseStorage {
|
|
|
10248
10145
|
async upload(input, destination, options) {
|
|
10249
10146
|
return `/tmp/${destination}`;
|
|
10250
10147
|
}
|
|
10251
|
-
async download(
|
|
10148
|
+
async download(path16) {
|
|
10252
10149
|
throw new Error("Download not supported in CLI");
|
|
10253
10150
|
}
|
|
10254
|
-
async delete(
|
|
10151
|
+
async delete(path16) {
|
|
10255
10152
|
}
|
|
10256
|
-
async getSignedUrl(
|
|
10257
|
-
return `/tmp/${
|
|
10153
|
+
async getSignedUrl(path16) {
|
|
10154
|
+
return `/tmp/${path16}`;
|
|
10258
10155
|
}
|
|
10259
|
-
getPublicUrl(
|
|
10260
|
-
return `/tmp/${
|
|
10156
|
+
getPublicUrl(path16) {
|
|
10157
|
+
return `/tmp/${path16}`;
|
|
10261
10158
|
}
|
|
10262
|
-
async getPreview(
|
|
10263
|
-
return `/tmp/${
|
|
10159
|
+
async getPreview(path16) {
|
|
10160
|
+
return `/tmp/${path16}`;
|
|
10264
10161
|
}
|
|
10265
|
-
async getMetadata(
|
|
10162
|
+
async getMetadata(path16) {
|
|
10266
10163
|
return { size: 0, contentType: "application/octet-stream" };
|
|
10267
10164
|
}
|
|
10268
10165
|
};
|
|
@@ -10294,12 +10191,11 @@ function wrapToolWithPermission(tool, permissionManager, showPermissionPrompt, a
|
|
|
10294
10191
|
return result2;
|
|
10295
10192
|
}
|
|
10296
10193
|
let preview;
|
|
10297
|
-
if (toolName === "edit_file" && args?.path && args?.
|
|
10194
|
+
if (toolName === "edit_file" && args?.path && args?.content) {
|
|
10298
10195
|
try {
|
|
10299
|
-
preview =
|
|
10196
|
+
preview = await generateFileDiffPreview({
|
|
10300
10197
|
path: args.path,
|
|
10301
|
-
|
|
10302
|
-
new_string: args.new_string
|
|
10198
|
+
content: args.content
|
|
10303
10199
|
});
|
|
10304
10200
|
} catch (error) {
|
|
10305
10201
|
preview = `[Could not generate preview: ${error instanceof Error ? error.message : "Unknown error"}]`;
|
|
@@ -10416,7 +10312,6 @@ function generateCliTools(userId, llm, model, permissionManager, showPermissionP
|
|
|
10416
10312
|
// File operation tools (CLI-specific, local execution)
|
|
10417
10313
|
file_read: {},
|
|
10418
10314
|
create_file: {},
|
|
10419
|
-
edit_local_file: {},
|
|
10420
10315
|
glob_files: {},
|
|
10421
10316
|
grep_search: {},
|
|
10422
10317
|
delete_file: {},
|
|
@@ -10499,7 +10394,6 @@ var DEFAULT_TOOL_CATEGORIES = {
|
|
|
10499
10394
|
// These tools can modify files, execute code, or have other dangerous side effects
|
|
10500
10395
|
// They ALWAYS require permission and cannot be trusted automatically
|
|
10501
10396
|
edit_file: "prompt_always",
|
|
10502
|
-
edit_local_file: "prompt_always",
|
|
10503
10397
|
create_file: "prompt_always",
|
|
10504
10398
|
delete_file: "prompt_always",
|
|
10505
10399
|
shell_execute: "prompt_always",
|
|
@@ -10666,8 +10560,8 @@ function getEnvironmentName(configApiConfig) {
|
|
|
10666
10560
|
}
|
|
10667
10561
|
|
|
10668
10562
|
// src/utils/contextLoader.ts
|
|
10669
|
-
import * as
|
|
10670
|
-
import * as
|
|
10563
|
+
import * as fs12 from "fs";
|
|
10564
|
+
import * as path14 from "path";
|
|
10671
10565
|
import { homedir as homedir4 } from "os";
|
|
10672
10566
|
var CONTEXT_FILE_SIZE_LIMIT = 100 * 1024;
|
|
10673
10567
|
var PROJECT_CONTEXT_FILES = [
|
|
@@ -10688,9 +10582,9 @@ function formatFileSize2(bytes) {
|
|
|
10688
10582
|
return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
|
|
10689
10583
|
}
|
|
10690
10584
|
function tryReadContextFile(dir, filename, source) {
|
|
10691
|
-
const filePath =
|
|
10585
|
+
const filePath = path14.join(dir, filename);
|
|
10692
10586
|
try {
|
|
10693
|
-
const stats =
|
|
10587
|
+
const stats = fs12.lstatSync(filePath);
|
|
10694
10588
|
if (stats.isDirectory()) {
|
|
10695
10589
|
return null;
|
|
10696
10590
|
}
|
|
@@ -10704,7 +10598,7 @@ function tryReadContextFile(dir, filename, source) {
|
|
|
10704
10598
|
error: `${source === "global" ? "Global" : "Project"} ${filename} exceeds 100KB limit (${formatFileSize2(stats.size)})`
|
|
10705
10599
|
};
|
|
10706
10600
|
}
|
|
10707
|
-
const content =
|
|
10601
|
+
const content = fs12.readFileSync(filePath, "utf-8");
|
|
10708
10602
|
return {
|
|
10709
10603
|
filename,
|
|
10710
10604
|
content,
|
|
@@ -10756,7 +10650,7 @@ ${project.content}`;
|
|
|
10756
10650
|
}
|
|
10757
10651
|
async function loadContextFiles(projectDir) {
|
|
10758
10652
|
const errors = [];
|
|
10759
|
-
const globalDir =
|
|
10653
|
+
const globalDir = path14.join(homedir4(), ".bike4mind");
|
|
10760
10654
|
const projectDirectory = projectDir || process.cwd();
|
|
10761
10655
|
const [globalResult, projectResult] = await Promise.all([
|
|
10762
10656
|
Promise.resolve(findContextFile(globalDir, GLOBAL_CONTEXT_FILES, "global")),
|
|
@@ -10792,8 +10686,8 @@ function substituteArguments(template, args) {
|
|
|
10792
10686
|
// ../../b4m-core/packages/mcp/dist/src/client.js
|
|
10793
10687
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
10794
10688
|
import { Client as Client2 } from "@modelcontextprotocol/sdk/client/index.js";
|
|
10795
|
-
import
|
|
10796
|
-
import { existsSync as
|
|
10689
|
+
import path15 from "path";
|
|
10690
|
+
import { existsSync as existsSync8, readdirSync as readdirSync3 } from "fs";
|
|
10797
10691
|
var MCPClient = class {
|
|
10798
10692
|
// Note: This class handles MCP server communication with repository filtering
|
|
10799
10693
|
mcp;
|
|
@@ -10833,18 +10727,18 @@ var MCPClient = class {
|
|
|
10833
10727
|
const root = process.env.INIT_CWD || process.cwd();
|
|
10834
10728
|
const candidatePaths = [
|
|
10835
10729
|
// When running from SST Lambda with node_modules structure (copyFiles)
|
|
10836
|
-
|
|
10730
|
+
path15.join(root, `node_modules/@bike4mind/mcp/dist/src/${this.serverName}/index.js`),
|
|
10837
10731
|
// When running from SST Lambda deployed environment (/var/task)
|
|
10838
|
-
|
|
10732
|
+
path15.join(root, `b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
|
|
10839
10733
|
// When running from SST Lambda (.sst/artifacts/mcpHandler-dev), navigate to monorepo root (3 levels up)
|
|
10840
|
-
|
|
10734
|
+
path15.join(root, `../../../b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
|
|
10841
10735
|
// When running from packages/client (Next.js app), navigate to monorepo root (2 levels up)
|
|
10842
|
-
|
|
10736
|
+
path15.join(root, `../../b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
|
|
10843
10737
|
// Original paths (backward compatibility)
|
|
10844
|
-
|
|
10845
|
-
|
|
10738
|
+
path15.join(root, `/b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
|
|
10739
|
+
path15.join(root, "core", "mcp", "servers", this.serverName, "dist", "index.js")
|
|
10846
10740
|
];
|
|
10847
|
-
const serverScriptPath = candidatePaths.find((p) =>
|
|
10741
|
+
const serverScriptPath = candidatePaths.find((p) => existsSync8(p));
|
|
10848
10742
|
if (!serverScriptPath) {
|
|
10849
10743
|
const getDirectories = (source) => readdirSync3(source, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
|
|
10850
10744
|
console.error(`[MCP] Server script not found. Tried paths:`, candidatePaths);
|
|
@@ -11359,7 +11253,7 @@ var ServerLlmBackend = class {
|
|
|
11359
11253
|
reject(error);
|
|
11360
11254
|
});
|
|
11361
11255
|
} catch (error) {
|
|
11362
|
-
logger.
|
|
11256
|
+
logger.debug(`LLM completion failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
11363
11257
|
if (isAxiosError(error)) {
|
|
11364
11258
|
logger.debug(
|
|
11365
11259
|
`[ServerLlmBackend] Axios error details: ${JSON.stringify({
|
|
@@ -11422,6 +11316,12 @@ var ServerLlmBackend = class {
|
|
|
11422
11316
|
reject(new Error("Cannot connect to Bike4Mind server. Please check your internet connection."));
|
|
11423
11317
|
} else if (error.message.includes("Rate limit exceeded")) {
|
|
11424
11318
|
reject(error);
|
|
11319
|
+
} else if (error.message.includes("socket hang up")) {
|
|
11320
|
+
reject(
|
|
11321
|
+
new Error(
|
|
11322
|
+
"Connection to server was interrupted (socket hang up). This can happen due to server timeouts or network issues. Please try again."
|
|
11323
|
+
)
|
|
11324
|
+
);
|
|
11425
11325
|
} else {
|
|
11426
11326
|
reject(new Error(`Failed to complete LLM request: ${error.message}`));
|
|
11427
11327
|
}
|
|
@@ -11654,7 +11554,7 @@ import { isAxiosError as isAxiosError2 } from "axios";
|
|
|
11654
11554
|
// package.json
|
|
11655
11555
|
var package_default = {
|
|
11656
11556
|
name: "@bike4mind/cli",
|
|
11657
|
-
version: "0.2.11-fix-cli-
|
|
11557
|
+
version: "0.2.11-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
11658
11558
|
type: "module",
|
|
11659
11559
|
description: "Interactive CLI tool for Bike4Mind with ReAct agents",
|
|
11660
11560
|
license: "UNLICENSED",
|
|
@@ -11758,10 +11658,10 @@ var package_default = {
|
|
|
11758
11658
|
},
|
|
11759
11659
|
devDependencies: {
|
|
11760
11660
|
"@bike4mind/agents": "0.1.0",
|
|
11761
|
-
"@bike4mind/common": "2.40.1-fix-cli-
|
|
11762
|
-
"@bike4mind/mcp": "1.20.5-fix-cli-
|
|
11763
|
-
"@bike4mind/services": "2.35.1-fix-cli-
|
|
11764
|
-
"@bike4mind/utils": "2.1.5-fix-cli-
|
|
11661
|
+
"@bike4mind/common": "2.40.1-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
11662
|
+
"@bike4mind/mcp": "1.20.5-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
11663
|
+
"@bike4mind/services": "2.35.1-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
11664
|
+
"@bike4mind/utils": "2.1.5-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
11765
11665
|
"@types/better-sqlite3": "^7.6.13",
|
|
11766
11666
|
"@types/diff": "^5.0.9",
|
|
11767
11667
|
"@types/jsonwebtoken": "^9.0.4",
|
|
@@ -11774,7 +11674,7 @@ var package_default = {
|
|
|
11774
11674
|
typescript: "^5.9.3",
|
|
11775
11675
|
vitest: "^3.2.4"
|
|
11776
11676
|
},
|
|
11777
|
-
gitHead: "
|
|
11677
|
+
gitHead: "0e857a50868cd4445d961180d5cd490d87585138"
|
|
11778
11678
|
};
|
|
11779
11679
|
|
|
11780
11680
|
// src/config/constants.ts
|
|
@@ -11856,9 +11756,21 @@ var SubagentOrchestrator = class {
|
|
|
11856
11756
|
this.beforeRunCallback(subagent, type);
|
|
11857
11757
|
}
|
|
11858
11758
|
const startTime = Date.now();
|
|
11859
|
-
|
|
11860
|
-
|
|
11861
|
-
|
|
11759
|
+
let result;
|
|
11760
|
+
try {
|
|
11761
|
+
result = await subagent.run(task, {
|
|
11762
|
+
maxIterations
|
|
11763
|
+
});
|
|
11764
|
+
} catch (error) {
|
|
11765
|
+
const duration2 = Date.now() - startTime;
|
|
11766
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
11767
|
+
this.deps.logger.error(`Subagent failed after ${duration2}ms: ${errorMessage}`);
|
|
11768
|
+
throw new Error(
|
|
11769
|
+
`Subagent execution failed: ${errorMessage}
|
|
11770
|
+
|
|
11771
|
+
This error occurred while running a ${type} subagent. The main conversation has been preserved, and you can retry or continue with other tasks.`
|
|
11772
|
+
);
|
|
11773
|
+
}
|
|
11862
11774
|
const duration = Date.now() - startTime;
|
|
11863
11775
|
if (this.afterRunCallback) {
|
|
11864
11776
|
this.afterRunCallback(subagent, type);
|
|
@@ -12016,7 +11928,6 @@ Focus on:
|
|
|
12016
11928
|
- Creating logical sequence of steps
|
|
12017
11929
|
- Estimating scope and priorities
|
|
12018
11930
|
|
|
12019
|
-
You have read-only access to analyze code.
|
|
12020
11931
|
You can explore the codebase to understand the current architecture before planning.
|
|
12021
11932
|
|
|
12022
11933
|
Provide a structured plan that the main agent can execute.`,
|
|
@@ -12073,13 +11984,18 @@ function createSubagentDelegateTool(orchestrator, parentSessionId) {
|
|
|
12073
11984
|
}
|
|
12074
11985
|
const thoroughness = params.thoroughness || "medium";
|
|
12075
11986
|
const type = params.type;
|
|
12076
|
-
|
|
12077
|
-
|
|
12078
|
-
|
|
12079
|
-
|
|
12080
|
-
|
|
12081
|
-
|
|
12082
|
-
|
|
11987
|
+
try {
|
|
11988
|
+
const result = await orchestrator.delegateToSubagent({
|
|
11989
|
+
task: params.task,
|
|
11990
|
+
type,
|
|
11991
|
+
thoroughness,
|
|
11992
|
+
parentSessionId
|
|
11993
|
+
});
|
|
11994
|
+
return result.summary;
|
|
11995
|
+
} catch (error) {
|
|
11996
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
11997
|
+
throw new Error(`Failed to execute ${type} subagent: ${errorMessage}`);
|
|
11998
|
+
}
|
|
12083
11999
|
},
|
|
12084
12000
|
toolSchema: {
|
|
12085
12001
|
name: "subagent_delegate",
|
|
@@ -12483,38 +12399,20 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12483
12399
|
const lastIdx = pendingMessages.length - 1;
|
|
12484
12400
|
if (lastIdx >= 0 && pendingMessages[lastIdx].role === "assistant") {
|
|
12485
12401
|
const existingSteps = pendingMessages[lastIdx].metadata?.steps || [];
|
|
12486
|
-
const MAX_INPUT_LENGTH = 500;
|
|
12487
|
-
let truncatedStep = step;
|
|
12488
|
-
if (step.type === "action" && step.metadata?.toolInput) {
|
|
12489
|
-
const inputStr = typeof step.metadata.toolInput === "string" ? step.metadata.toolInput : JSON.stringify(step.metadata.toolInput);
|
|
12490
|
-
if (inputStr.length > MAX_INPUT_LENGTH) {
|
|
12491
|
-
const truncatedInput = inputStr.slice(0, MAX_INPUT_LENGTH) + `... (${inputStr.length - MAX_INPUT_LENGTH} more chars)`;
|
|
12492
|
-
truncatedStep = {
|
|
12493
|
-
...step,
|
|
12494
|
-
metadata: {
|
|
12495
|
-
...step.metadata,
|
|
12496
|
-
toolInput: truncatedInput
|
|
12497
|
-
}
|
|
12498
|
-
};
|
|
12499
|
-
}
|
|
12500
|
-
}
|
|
12501
12402
|
updatePendingMessage(lastIdx, {
|
|
12502
12403
|
...pendingMessages[lastIdx],
|
|
12503
12404
|
metadata: {
|
|
12504
12405
|
...pendingMessages[lastIdx].metadata,
|
|
12505
|
-
steps: [...existingSteps,
|
|
12406
|
+
steps: [...existingSteps, step]
|
|
12506
12407
|
}
|
|
12507
12408
|
});
|
|
12508
12409
|
}
|
|
12509
12410
|
};
|
|
12510
|
-
agent.on("thought", stepHandler);
|
|
12511
12411
|
agent.on("action", stepHandler);
|
|
12512
12412
|
orchestrator.setBeforeRunCallback((subagent, _subagentType) => {
|
|
12513
|
-
subagent.on("thought", stepHandler);
|
|
12514
12413
|
subagent.on("action", stepHandler);
|
|
12515
12414
|
});
|
|
12516
12415
|
orchestrator.setAfterRunCallback((subagent, _subagentType) => {
|
|
12517
|
-
subagent.off("thought", stepHandler);
|
|
12518
12416
|
subagent.off("action", stepHandler);
|
|
12519
12417
|
});
|
|
12520
12418
|
setState((prev) => ({
|
|
@@ -12583,7 +12481,6 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12583
12481
|
}
|
|
12584
12482
|
}
|
|
12585
12483
|
};
|
|
12586
|
-
state.agent.on("thought", stepHandler);
|
|
12587
12484
|
state.agent.on("action", stepHandler);
|
|
12588
12485
|
try {
|
|
12589
12486
|
let messageContent = fullTemplate;
|
|
@@ -12705,7 +12602,6 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12705
12602
|
setState((prev) => ({ ...prev, session: sessionWithError }));
|
|
12706
12603
|
setStoreSession(sessionWithError);
|
|
12707
12604
|
} finally {
|
|
12708
|
-
state.agent.off("thought", stepHandler);
|
|
12709
12605
|
state.agent.off("action", stepHandler);
|
|
12710
12606
|
}
|
|
12711
12607
|
};
|
|
@@ -12724,6 +12620,31 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12724
12620
|
return;
|
|
12725
12621
|
}
|
|
12726
12622
|
useCliStore.getState().setIsThinking(true);
|
|
12623
|
+
const currentSteps = [];
|
|
12624
|
+
const pendingAssistantMessage = {
|
|
12625
|
+
id: uuidv410(),
|
|
12626
|
+
role: "assistant",
|
|
12627
|
+
content: "...",
|
|
12628
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12629
|
+
metadata: {
|
|
12630
|
+
steps: []
|
|
12631
|
+
}
|
|
12632
|
+
};
|
|
12633
|
+
const stepHandler = (step) => {
|
|
12634
|
+
currentSteps.push(step);
|
|
12635
|
+
const { pendingMessages, updatePendingMessage } = useCliStore.getState();
|
|
12636
|
+
const lastIdx = pendingMessages.length - 1;
|
|
12637
|
+
if (lastIdx >= 0 && pendingMessages[lastIdx].role === "assistant") {
|
|
12638
|
+
updatePendingMessage(lastIdx, {
|
|
12639
|
+
...pendingMessages[lastIdx],
|
|
12640
|
+
metadata: {
|
|
12641
|
+
...pendingMessages[lastIdx].metadata,
|
|
12642
|
+
steps: [...currentSteps]
|
|
12643
|
+
}
|
|
12644
|
+
});
|
|
12645
|
+
}
|
|
12646
|
+
};
|
|
12647
|
+
state.agent.on("action", stepHandler);
|
|
12727
12648
|
try {
|
|
12728
12649
|
let messageContent = message;
|
|
12729
12650
|
let userMessageContent = message;
|
|
@@ -12738,15 +12659,6 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12738
12659
|
content: userMessageContent,
|
|
12739
12660
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
12740
12661
|
};
|
|
12741
|
-
const pendingAssistantMessage = {
|
|
12742
|
-
id: uuidv410(),
|
|
12743
|
-
role: "assistant",
|
|
12744
|
-
content: "...",
|
|
12745
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
12746
|
-
metadata: {
|
|
12747
|
-
steps: []
|
|
12748
|
-
}
|
|
12749
|
-
};
|
|
12750
12662
|
const sessionWithUserMessage = {
|
|
12751
12663
|
...state.session,
|
|
12752
12664
|
messages: [...state.session.messages, userMessage],
|
|
@@ -12800,15 +12712,50 @@ Remember: Use context from previous messages to understand follow-up questions.$
|
|
|
12800
12712
|
setStoreSession(updatedSession);
|
|
12801
12713
|
await state.sessionStore.save(updatedSession);
|
|
12802
12714
|
} catch (error) {
|
|
12803
|
-
|
|
12715
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
12716
|
+
let displayMessage;
|
|
12804
12717
|
if (error instanceof Error) {
|
|
12805
12718
|
if (error.message.includes("Authentication failed") || error.message.includes("Authentication expired")) {
|
|
12806
|
-
|
|
12807
|
-
|
|
12808
|
-
|
|
12719
|
+
displayMessage = "\u274C Authentication failed\n\n\u{1F4A1} Run /login to authenticate with your API environment.";
|
|
12720
|
+
} else if (error.message.includes("socket hang up")) {
|
|
12721
|
+
displayMessage = `\u26A0\uFE0F Connection Error
|
|
12722
|
+
|
|
12723
|
+
${errorMessage}
|
|
12724
|
+
|
|
12725
|
+
\u{1F4A1} This is usually a temporary issue. Please try your request again.`;
|
|
12726
|
+
} else {
|
|
12727
|
+
displayMessage = `\u274C Error
|
|
12728
|
+
|
|
12729
|
+
${errorMessage}`;
|
|
12730
|
+
}
|
|
12731
|
+
} else {
|
|
12732
|
+
displayMessage = `\u274C Error
|
|
12733
|
+
|
|
12734
|
+
${errorMessage}`;
|
|
12735
|
+
}
|
|
12736
|
+
const errorAssistantMessage = {
|
|
12737
|
+
id: pendingAssistantMessage.id,
|
|
12738
|
+
role: "assistant",
|
|
12739
|
+
content: displayMessage,
|
|
12740
|
+
timestamp: pendingAssistantMessage.timestamp,
|
|
12741
|
+
metadata: {
|
|
12742
|
+
steps: currentSteps
|
|
12743
|
+
// Include any steps that were completed before error
|
|
12809
12744
|
}
|
|
12745
|
+
};
|
|
12746
|
+
useCliStore.getState().completePendingMessage(0, errorAssistantMessage);
|
|
12747
|
+
const currentSession = useCliStore.getState().session;
|
|
12748
|
+
if (currentSession) {
|
|
12749
|
+
const updatedSession = {
|
|
12750
|
+
...currentSession,
|
|
12751
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
12752
|
+
};
|
|
12753
|
+
setState((prev) => ({ ...prev, session: updatedSession }));
|
|
12754
|
+
setStoreSession(updatedSession);
|
|
12755
|
+
await state.sessionStore.save(updatedSession);
|
|
12810
12756
|
}
|
|
12811
|
-
|
|
12757
|
+
} finally {
|
|
12758
|
+
state.agent.off("action", stepHandler);
|
|
12812
12759
|
}
|
|
12813
12760
|
};
|
|
12814
12761
|
const handleBashCommand = useCallback(
|
|
@@ -13027,6 +12974,7 @@ Custom Commands:
|
|
|
13027
12974
|
logger.debug("=== Session Resumed ===");
|
|
13028
12975
|
setState((prev) => ({ ...prev, session: loadedSession }));
|
|
13029
12976
|
setStoreSession(loadedSession);
|
|
12977
|
+
useCliStore.getState().clearAgentSteps();
|
|
13030
12978
|
useCliStore.getState().clearPendingMessages();
|
|
13031
12979
|
usageCache = null;
|
|
13032
12980
|
console.log(`
|
|
@@ -13262,6 +13210,7 @@ Custom Commands:
|
|
|
13262
13210
|
logger.debug("=== New Session Started via /clear ===");
|
|
13263
13211
|
setState((prev) => ({ ...prev, session: newSession }));
|
|
13264
13212
|
setStoreSession(newSession);
|
|
13213
|
+
useCliStore.getState().clearAgentSteps();
|
|
13265
13214
|
useCliStore.getState().clearPendingMessages();
|
|
13266
13215
|
usageCache = null;
|
|
13267
13216
|
console.log("New session started.");
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
findMostSimilarMemento,
|
|
4
4
|
getRelevantMementos
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-7JR6VASX.js";
|
|
6
|
+
import "./chunk-JYH72REB.js";
|
|
7
7
|
import "./chunk-AMDXHL6S.js";
|
|
8
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-3OX632TE.js";
|
|
9
9
|
import "./chunk-PDX44BCA.js";
|
|
10
10
|
export {
|
|
11
11
|
findMostSimilarMemento,
|
|
@@ -120,7 +120,7 @@ import {
|
|
|
120
120
|
validateMermaidSyntax,
|
|
121
121
|
warmUpSettingsCache,
|
|
122
122
|
withRetry
|
|
123
|
-
} from "./chunk-
|
|
123
|
+
} from "./chunk-JYH72REB.js";
|
|
124
124
|
import {
|
|
125
125
|
Logger,
|
|
126
126
|
NotificationDeduplicator,
|
|
@@ -129,7 +129,7 @@ import {
|
|
|
129
129
|
postLowCreditsNotificationToSlack,
|
|
130
130
|
postMessageToSlack
|
|
131
131
|
} from "./chunk-AMDXHL6S.js";
|
|
132
|
-
import "./chunk-
|
|
132
|
+
import "./chunk-3OX632TE.js";
|
|
133
133
|
import "./chunk-PDX44BCA.js";
|
|
134
134
|
export {
|
|
135
135
|
AWSBackend,
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import {
|
|
3
3
|
SubtractCreditsSchema,
|
|
4
4
|
subtractCredits
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
5
|
+
} from "./chunk-7ORA6KGN.js";
|
|
6
|
+
import "./chunk-JYH72REB.js";
|
|
7
7
|
import "./chunk-AMDXHL6S.js";
|
|
8
|
-
import "./chunk-
|
|
8
|
+
import "./chunk-3OX632TE.js";
|
|
9
9
|
import "./chunk-PDX44BCA.js";
|
|
10
10
|
export {
|
|
11
11
|
SubtractCreditsSchema,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bike4mind/cli",
|
|
3
|
-
"version": "0.2.11-fix-cli-
|
|
3
|
+
"version": "0.2.11-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Interactive CLI tool for Bike4Mind with ReAct agents",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -104,10 +104,10 @@
|
|
|
104
104
|
},
|
|
105
105
|
"devDependencies": {
|
|
106
106
|
"@bike4mind/agents": "0.1.0",
|
|
107
|
-
"@bike4mind/common": "2.40.1-fix-cli-
|
|
108
|
-
"@bike4mind/mcp": "1.20.5-fix-cli-
|
|
109
|
-
"@bike4mind/services": "2.35.1-fix-cli-
|
|
110
|
-
"@bike4mind/utils": "2.1.5-fix-cli-
|
|
107
|
+
"@bike4mind/common": "2.40.1-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
108
|
+
"@bike4mind/mcp": "1.20.5-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
109
|
+
"@bike4mind/services": "2.35.1-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
110
|
+
"@bike4mind/utils": "2.1.5-fix-cli-socket-hangup-error-handling.17320+0e857a508",
|
|
111
111
|
"@types/better-sqlite3": "^7.6.13",
|
|
112
112
|
"@types/diff": "^5.0.9",
|
|
113
113
|
"@types/jsonwebtoken": "^9.0.4",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"typescript": "^5.9.3",
|
|
121
121
|
"vitest": "^3.2.4"
|
|
122
122
|
},
|
|
123
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "0e857a50868cd4445d961180d5cd490d87585138"
|
|
124
124
|
}
|