@bike4mind/cli 0.2.11-fix-cli-socket-hangup-error-handling.17321 → 0.2.11-ja-fix-confluence-table-data-5752.17351

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.
@@ -36,16 +36,24 @@ const argv = yargs(hideBin(process.argv))
36
36
  description: 'Show debug logs in console',
37
37
  default: false,
38
38
  })
39
+ .option('no-project-config', {
40
+ type: 'boolean',
41
+ description: 'Disable loading project-specific configuration (.bike4mind/)',
42
+ default: false,
43
+ })
39
44
  .help()
40
45
  .alias('help', 'h')
41
46
  .version()
42
47
  .alias('version', 'V')
43
48
  .parse();
44
49
 
45
- // Set environment variable for verbose mode
50
+ // Set environment variables from CLI flags
46
51
  if (argv.verbose) {
47
52
  process.env.B4M_VERBOSE = '1';
48
53
  }
54
+ if (argv['no-project-config']) {
55
+ process.env.B4M_NO_PROJECT_CONFIG = '1';
56
+ }
49
57
 
50
58
  // Auto-detect environment: prefer production mode when dist exists
51
59
  const distPath = join(__dirname, '../dist/index.js');
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-3OX632TE.js";
4
+ } from "./chunk-ZJUZR27P.js";
5
5
  import "./chunk-PDX44BCA.js";
6
6
 
7
7
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/artifactExtractor.js
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  BadRequestError,
4
4
  secureParameters
5
- } from "./chunk-JYH72REB.js";
5
+ } from "./chunk-PUL75ZDO.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-3OX632TE.js";
13
+ } from "./chunk-ZJUZR27P.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-JYH72REB.js";
10
+ } from "./chunk-PUL75ZDO.js";
11
11
  import {
12
12
  KnowledgeType,
13
13
  SupportedFabFileMimeTypes
14
- } from "./chunk-3OX632TE.js";
14
+ } from "./chunk-ZJUZR27P.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/fabFileService/create.js
17
17
  import { z } from "zod";
@@ -6,12 +6,12 @@ import {
6
6
  getSettingsByNames,
7
7
  obfuscateApiKey,
8
8
  secureParameters
9
- } from "./chunk-JYH72REB.js";
9
+ } from "./chunk-PUL75ZDO.js";
10
10
  import {
11
11
  ApiKeyType,
12
12
  MementoTier,
13
13
  isSupportedEmbeddingModel
14
- } from "./chunk-3OX632TE.js";
14
+ } from "./chunk-ZJUZR27P.js";
15
15
 
16
16
  // ../../b4m-core/packages/services/dist/src/apiKeyService/get.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-3OX632TE.js";
19
+ } from "./chunk-ZJUZR27P.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";
@@ -228,6 +228,7 @@ var b4mLLMTools = z3.enum([
228
228
  // File operation tools
229
229
  "file_read",
230
230
  "create_file",
231
+ "edit_local_file",
231
232
  "glob_files",
232
233
  "grep_search",
233
234
  "delete_file",
@@ -5052,6 +5053,74 @@ function formatUserList(users) {
5052
5053
  }
5053
5054
 
5054
5055
  // ../../b4m-core/packages/common/dist/src/jira/api.js
5056
+ function wikiMarkupToAdf(text) {
5057
+ const lines = text.split("\n");
5058
+ const content = [];
5059
+ let currentTableRows = [];
5060
+ let inTable = false;
5061
+ for (const line of lines) {
5062
+ const trimmedLine = line.trim();
5063
+ if (trimmedLine.startsWith("||") && trimmedLine.endsWith("||")) {
5064
+ inTable = true;
5065
+ const cells = trimmedLine.slice(2, -2).split("||").map((cell) => cell.trim());
5066
+ const headerRow = {
5067
+ type: "tableRow",
5068
+ content: cells.map((cell) => ({
5069
+ type: "tableHeader",
5070
+ attrs: {},
5071
+ content: [{ type: "paragraph", content: [{ type: "text", text: cell || " " }] }]
5072
+ }))
5073
+ };
5074
+ currentTableRows.push(headerRow);
5075
+ continue;
5076
+ }
5077
+ if (trimmedLine.startsWith("|") && trimmedLine.endsWith("|") && !trimmedLine.startsWith("||")) {
5078
+ inTable = true;
5079
+ const cells = trimmedLine.slice(1, -1).split("|").map((cell) => cell.trim());
5080
+ const dataRow = {
5081
+ type: "tableRow",
5082
+ content: cells.map((cell) => ({
5083
+ type: "tableCell",
5084
+ attrs: {},
5085
+ content: [{ type: "paragraph", content: [{ type: "text", text: cell || " " }] }]
5086
+ }))
5087
+ };
5088
+ currentTableRows.push(dataRow);
5089
+ continue;
5090
+ }
5091
+ if (inTable && currentTableRows.length > 0) {
5092
+ const table = {
5093
+ type: "table",
5094
+ attrs: { isNumberColumnEnabled: false, layout: "default" },
5095
+ content: currentTableRows
5096
+ };
5097
+ content.push(table);
5098
+ currentTableRows = [];
5099
+ inTable = false;
5100
+ }
5101
+ if (trimmedLine) {
5102
+ content.push({
5103
+ type: "paragraph",
5104
+ content: [{ type: "text", text: trimmedLine }]
5105
+ });
5106
+ }
5107
+ }
5108
+ if (currentTableRows.length > 0) {
5109
+ const table = {
5110
+ type: "table",
5111
+ attrs: { isNumberColumnEnabled: false, layout: "default" },
5112
+ content: currentTableRows
5113
+ };
5114
+ content.push(table);
5115
+ }
5116
+ if (content.length === 0) {
5117
+ content.push({ type: "paragraph", content: [{ type: "text", text: " " }] });
5118
+ }
5119
+ return { type: "doc", version: 1, content };
5120
+ }
5121
+ function containsWikiTable(text) {
5122
+ return /^\|\|.+\|\|$/m.test(text) || /^\|(?!\|).+\|$/m.test(text);
5123
+ }
5055
5124
  var JiraApi = class {
5056
5125
  config;
5057
5126
  constructor(config) {
@@ -5131,16 +5200,21 @@ var JiraApi = class {
5131
5200
  ...customFields
5132
5201
  };
5133
5202
  if (description) {
5134
- fields.description = {
5135
- type: "doc",
5136
- version: 1,
5137
- content: [
5138
- {
5139
- type: "paragraph",
5140
- content: [{ type: "text", text: description }]
5141
- }
5142
- ]
5143
- };
5203
+ if (containsWikiTable(description)) {
5204
+ console.log("[JIRA-ADF] Converting wiki table to ADF", { length: description.length });
5205
+ fields.description = wikiMarkupToAdf(description);
5206
+ } else {
5207
+ fields.description = {
5208
+ type: "doc",
5209
+ version: 1,
5210
+ content: [
5211
+ {
5212
+ type: "paragraph",
5213
+ content: [{ type: "text", text: description }]
5214
+ }
5215
+ ]
5216
+ };
5217
+ }
5144
5218
  }
5145
5219
  if (assignee) {
5146
5220
  fields.assignee = { id: assignee };
@@ -5166,16 +5240,21 @@ var JiraApi = class {
5166
5240
  fields.summary = summary;
5167
5241
  }
5168
5242
  if (description) {
5169
- fields.description = {
5170
- type: "doc",
5171
- version: 1,
5172
- content: [
5173
- {
5174
- type: "paragraph",
5175
- content: [{ type: "text", text: description }]
5176
- }
5177
- ]
5178
- };
5243
+ if (containsWikiTable(description)) {
5244
+ console.log("[JIRA-ADF] Converting wiki table to ADF (update)", { length: description.length });
5245
+ fields.description = wikiMarkupToAdf(description);
5246
+ } else {
5247
+ fields.description = {
5248
+ type: "doc",
5249
+ version: 1,
5250
+ content: [
5251
+ {
5252
+ type: "paragraph",
5253
+ content: [{ type: "text", text: description }]
5254
+ }
5255
+ ]
5256
+ };
5257
+ }
5179
5258
  }
5180
5259
  if (labels) {
5181
5260
  fields.labels = labels;
@@ -5335,16 +5414,21 @@ var JiraApi = class {
5335
5414
  issuetype: { name: issueTypeName }
5336
5415
  };
5337
5416
  if (description) {
5338
- fields.description = {
5339
- type: "doc",
5340
- version: 1,
5341
- content: [
5342
- {
5343
- type: "paragraph",
5344
- content: [{ type: "text", text: description }]
5345
- }
5346
- ]
5347
- };
5417
+ if (containsWikiTable(description)) {
5418
+ console.log("[JIRA-ADF] Converting wiki table to ADF (bulk)", { length: description.length });
5419
+ fields.description = wikiMarkupToAdf(description);
5420
+ } else {
5421
+ fields.description = {
5422
+ type: "doc",
5423
+ version: 1,
5424
+ content: [
5425
+ {
5426
+ type: "paragraph",
5427
+ content: [{ type: "text", text: description }]
5428
+ }
5429
+ ]
5430
+ };
5431
+ }
5348
5432
  }
5349
5433
  if (assignee) {
5350
5434
  fields.assignee = { id: assignee };
@@ -6164,6 +6248,8 @@ export {
6164
6248
  formatUser,
6165
6249
  formatTransitionResult,
6166
6250
  formatUserList,
6251
+ wikiMarkupToAdf,
6252
+ containsWikiTable,
6167
6253
  JiraApi,
6168
6254
  getErrorMessage,
6169
6255
  getAtlassianConfig,
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  createFabFile,
4
4
  createFabFileSchema
5
- } from "./chunk-HPYQM2B7.js";
6
- import "./chunk-JYH72REB.js";
5
+ } from "./chunk-AHDZ7ASB.js";
6
+ import "./chunk-PUL75ZDO.js";
7
7
  import "./chunk-AMDXHL6S.js";
8
- import "./chunk-3OX632TE.js";
8
+ import "./chunk-ZJUZR27P.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-7JR6VASX.js";
8
- import "./chunk-7ORA6KGN.js";
9
- import "./chunk-HPYQM2B7.js";
7
+ } from "./chunk-F6ZKDGCA.js";
8
+ import "./chunk-2OWNLDU2.js";
9
+ import "./chunk-AHDZ7ASB.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-JYH72REB.js";
18
+ } from "./chunk-PUL75ZDO.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-3OX632TE.js";
76
+ } from "./chunk-ZJUZR27P.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({ 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...")));
991
+ var ThoughtStream = React6.memo(function ThoughtStream2({ isThinking }) {
992
+ return /* @__PURE__ */ React6.createElement(Box5, { flexDirection: "column", gap: 1 }, isThinking && /* @__PURE__ */ React6.createElement(Box5, null, /* @__PURE__ */ React6.createElement(Text6, { color: "yellow" }, /* @__PURE__ */ React6.createElement(Spinner, { type: "dots" })), /* @__PURE__ */ React6.createElement(Text6, null, " Thinking...")));
993
993
  });
994
994
 
995
995
  // src/store/index.ts
@@ -1034,12 +1034,6 @@ 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: [] }),
1043
1037
  // Permission prompt
1044
1038
  permissionPrompt: null,
1045
1039
  setPermissionPrompt: (prompt) => set({ permissionPrompt: prompt }),
@@ -1054,11 +1048,10 @@ var useCliStore = create((set) => ({
1054
1048
  // src/components/AgentThinking.tsx
1055
1049
  var AgentThinking = React7.memo(function AgentThinking2() {
1056
1050
  const isThinking = useCliStore((state) => state.isThinking);
1057
- const agentSteps = useCliStore((state) => state.agentSteps);
1058
1051
  if (!isThinking) {
1059
1052
  return null;
1060
1053
  }
1061
- return /* @__PURE__ */ React7.createElement(Box6, { paddingX: 1, marginBottom: 1 }, /* @__PURE__ */ React7.createElement(ThoughtStream, { steps: agentSteps }));
1054
+ return /* @__PURE__ */ React7.createElement(Box6, { paddingX: 1, marginBottom: 1 }, /* @__PURE__ */ React7.createElement(ThoughtStream, { isThinking }));
1062
1055
  });
1063
1056
 
1064
1057
  // src/components/PermissionPrompt.tsx
@@ -1096,7 +1089,10 @@ function PermissionPrompt({
1096
1089
  { label: "\u2713 Allow once", value: "allow-once" },
1097
1090
  { label: "\u2717 Deny", value: "deny" }
1098
1091
  ];
1099
- const argsString = typeof args === "string" ? args : JSON.stringify(args, null, 2);
1092
+ const MAX_ARGS_LENGTH = 500;
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;
1100
1096
  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) })));
1101
1097
  }
1102
1098
 
@@ -2381,15 +2377,19 @@ var ConfigStore = class {
2381
2377
  throw error;
2382
2378
  }
2383
2379
  }
2384
- this.projectConfigDir = findProjectConfigDir();
2385
2380
  let projectConfig = null;
2386
2381
  let projectLocalConfig = null;
2387
- if (this.projectConfigDir) {
2388
- projectConfig = await loadProjectConfig(this.projectConfigDir);
2389
- projectLocalConfig = await loadProjectLocalConfig(this.projectConfigDir);
2390
- if (projectConfig) {
2391
- console.log(`\u{1F4C1} Project config loaded from: ${this.projectConfigDir}/.bike4mind/`);
2382
+ if (process.env.B4M_NO_PROJECT_CONFIG !== "1") {
2383
+ this.projectConfigDir = findProjectConfigDir();
2384
+ if (this.projectConfigDir) {
2385
+ projectConfig = await loadProjectConfig(this.projectConfigDir);
2386
+ projectLocalConfig = await loadProjectLocalConfig(this.projectConfigDir);
2387
+ if (projectConfig) {
2388
+ console.log(`\u{1F4C1} Project config loaded from: ${this.projectConfigDir}/.bike4mind/`);
2389
+ }
2392
2390
  }
2391
+ } else {
2392
+ this.projectConfigDir = null;
2393
2393
  }
2394
2394
  this.config = mergeConfigs(globalConfig, projectConfig, projectLocalConfig);
2395
2395
  return this.config;
@@ -5489,8 +5489,8 @@ async function processAndStoreImages(images, context) {
5489
5489
  const buffer = await downloadImage(image);
5490
5490
  const fileType = await fileTypeFromBuffer2(buffer);
5491
5491
  const filename = `${uuidv46()}.${fileType?.ext}`;
5492
- const path16 = await context.imageGenerateStorage.upload(buffer, filename, {});
5493
- return path16;
5492
+ const path17 = await context.imageGenerateStorage.upload(buffer, filename, {});
5493
+ return path17;
5494
5494
  }));
5495
5495
  }
5496
5496
  async function updateQuestAndReturnMarkdown(storedImageUrls, context) {
@@ -6702,8 +6702,8 @@ async function processAndStoreImage(imageUrl, context) {
6702
6702
  const buffer = await downloadImage2(imageUrl);
6703
6703
  const fileType = await fileTypeFromBuffer3(buffer);
6704
6704
  const filename = `${uuidv47()}.${fileType?.ext}`;
6705
- const path16 = await context.imageGenerateStorage.upload(buffer, filename, {});
6706
- return path16;
6705
+ const path17 = await context.imageGenerateStorage.upload(buffer, filename, {});
6706
+ return path17;
6707
6707
  }
6708
6708
  async function updateQuestAndReturnMarkdown2(storedImagePath, context) {
6709
6709
  await context.onFinish?.("edit_image", storedImagePath);
@@ -9491,6 +9491,104 @@ BLOCKED OPERATIONS:
9491
9491
  })
9492
9492
  };
9493
9493
 
9494
+ // ../../b4m-core/packages/services/dist/src/llm/tools/implementation/editLocalFile/index.js
9495
+ import { promises as fs11 } from "fs";
9496
+ import { existsSync as existsSync7 } from "fs";
9497
+ import path13 from "path";
9498
+ import { diffLines as diffLines3 } from "diff";
9499
+ function generateDiff(original, modified) {
9500
+ const differences = diffLines3(original, modified);
9501
+ let diffString = "";
9502
+ let additions = 0;
9503
+ let deletions = 0;
9504
+ differences.forEach((part) => {
9505
+ if (part.added) {
9506
+ additions += part.count || 0;
9507
+ diffString += part.value.split("\n").filter((line) => line).map((line) => `+ ${line}`).join("\n");
9508
+ if (diffString && !diffString.endsWith("\n"))
9509
+ diffString += "\n";
9510
+ } else if (part.removed) {
9511
+ deletions += part.count || 0;
9512
+ diffString += part.value.split("\n").filter((line) => line).map((line) => `- ${line}`).join("\n");
9513
+ if (diffString && !diffString.endsWith("\n"))
9514
+ diffString += "\n";
9515
+ }
9516
+ });
9517
+ return { additions, deletions, diff: diffString.trim() };
9518
+ }
9519
+ async function editLocalFile(params) {
9520
+ const { path: filePath, old_string, new_string } = params;
9521
+ const normalizedPath = path13.normalize(filePath);
9522
+ const resolvedPath = path13.resolve(process.cwd(), normalizedPath);
9523
+ const cwd = path13.resolve(process.cwd());
9524
+ if (!resolvedPath.startsWith(cwd)) {
9525
+ throw new Error(`Access denied: Cannot edit files outside of current working directory`);
9526
+ }
9527
+ if (!existsSync7(resolvedPath)) {
9528
+ throw new Error(`File not found: ${filePath}`);
9529
+ }
9530
+ const currentContent = await fs11.readFile(resolvedPath, "utf-8");
9531
+ if (!currentContent.includes(old_string)) {
9532
+ const preview = old_string.length > 100 ? old_string.substring(0, 100) + "..." : old_string;
9533
+ 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}"`);
9534
+ }
9535
+ const occurrences = currentContent.split(old_string).length - 1;
9536
+ if (occurrences > 1) {
9537
+ throw new Error(`Found ${occurrences} occurrences of the string to replace. Please provide a more specific old_string that matches exactly one location.`);
9538
+ }
9539
+ const newContent = currentContent.replace(old_string, new_string);
9540
+ await fs11.writeFile(resolvedPath, newContent, "utf-8");
9541
+ const diffResult = generateDiff(old_string, new_string);
9542
+ return `File edited successfully: ${filePath}
9543
+ Changes: +${diffResult.additions} lines, -${diffResult.deletions} lines
9544
+
9545
+ Diff:
9546
+ ${diffResult.diff}`;
9547
+ }
9548
+ var editLocalFileTool = {
9549
+ name: "edit_local_file",
9550
+ implementation: (context) => ({
9551
+ toolFn: async (value) => {
9552
+ const params = value;
9553
+ context.logger.info(`\u{1F4DD} EditLocalFile: Editing file`, {
9554
+ path: params.path,
9555
+ oldStringLength: params.old_string.length,
9556
+ newStringLength: params.new_string.length
9557
+ });
9558
+ try {
9559
+ const result = await editLocalFile(params);
9560
+ context.logger.info("\u2705 EditLocalFile: Success", { path: params.path });
9561
+ return result;
9562
+ } catch (error) {
9563
+ context.logger.error("\u274C EditLocalFile: Failed", error);
9564
+ throw error;
9565
+ }
9566
+ },
9567
+ toolSchema: {
9568
+ name: "edit_local_file",
9569
+ 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.",
9570
+ parameters: {
9571
+ type: "object",
9572
+ properties: {
9573
+ path: {
9574
+ type: "string",
9575
+ description: "Path to the file to edit (relative to current working directory)"
9576
+ },
9577
+ old_string: {
9578
+ type: "string",
9579
+ description: "The exact string to find and replace. Must match exactly one location in the file, including all whitespace and line endings."
9580
+ },
9581
+ new_string: {
9582
+ type: "string",
9583
+ description: "The string to replace old_string with. Can be empty to delete the old_string."
9584
+ }
9585
+ },
9586
+ required: ["path", "old_string", "new_string"]
9587
+ }
9588
+ }
9589
+ })
9590
+ };
9591
+
9494
9592
  // ../../b4m-core/packages/services/dist/src/llm/tools/index.js
9495
9593
  var tools = {
9496
9594
  dice_roll: diceRollTool,
@@ -9516,6 +9614,7 @@ var tools = {
9516
9614
  planet_visibility: planetVisibilityTool,
9517
9615
  file_read: fileReadTool,
9518
9616
  create_file: createFileTool,
9617
+ edit_local_file: editLocalFileTool,
9519
9618
  glob_files: globFilesTool,
9520
9619
  grep_search: grepSearchTool,
9521
9620
  delete_file: deleteFileTool,
@@ -9759,10 +9858,10 @@ var ToolErrorType;
9759
9858
  // src/utils/diffPreview.ts
9760
9859
  import * as Diff from "diff";
9761
9860
  import { readFile } from "fs/promises";
9762
- import { existsSync as existsSync7 } from "fs";
9861
+ import { existsSync as existsSync8 } from "fs";
9763
9862
  async function generateFileDiffPreview(args) {
9764
9863
  try {
9765
- if (!existsSync7(args.path)) {
9864
+ if (!existsSync8(args.path)) {
9766
9865
  const lines2 = args.content.split("\n");
9767
9866
  const preview = lines2.slice(0, 20).join("\n");
9768
9867
  const hasMore = lines2.length > 20;
@@ -9784,18 +9883,26 @@ ${preview}${hasMore ? `
9784
9883
  // Show 3 lines of context around changes
9785
9884
  );
9786
9885
  const lines = patch.split("\n");
9787
- const diffLines3 = lines.slice(4);
9788
- return diffLines3.join("\n");
9886
+ const diffLines4 = lines.slice(4);
9887
+ return diffLines4.join("\n");
9789
9888
  } catch (error) {
9790
9889
  return `[Error generating diff preview: ${error instanceof Error ? error.message : "Unknown error"}]`;
9791
9890
  }
9792
9891
  }
9892
+ function generateEditLocalFilePreview(args) {
9893
+ const patch = Diff.createPatch(args.path, args.old_string, args.new_string, "Current", "Proposed", { context: 3 });
9894
+ const lines = patch.split("\n");
9895
+ const diffLines4 = lines.slice(4);
9896
+ return `[Edit in: ${args.path}]
9897
+
9898
+ ${diffLines4.join("\n")}`;
9899
+ }
9793
9900
  async function generateFileDeletePreview(args) {
9794
9901
  try {
9795
- if (!existsSync7(args.path)) {
9902
+ if (!existsSync8(args.path)) {
9796
9903
  return `[File does not exist: ${args.path}]`;
9797
9904
  }
9798
- const stats = await import("fs/promises").then((fs13) => fs13.stat(args.path));
9905
+ const stats = await import("fs/promises").then((fs14) => fs14.stat(args.path));
9799
9906
  return `[File will be deleted]
9800
9907
 
9801
9908
  Path: ${args.path}
@@ -9807,8 +9914,8 @@ Last modified: ${stats.mtime.toLocaleString()}`;
9807
9914
  }
9808
9915
 
9809
9916
  // src/utils/Logger.ts
9810
- import fs11 from "fs/promises";
9811
- import path13 from "path";
9917
+ import fs12 from "fs/promises";
9918
+ import path14 from "path";
9812
9919
  import os2 from "os";
9813
9920
  var Logger2 = class _Logger {
9814
9921
  constructor() {
@@ -9831,9 +9938,9 @@ var Logger2 = class _Logger {
9831
9938
  */
9832
9939
  async initialize(sessionId) {
9833
9940
  this.sessionId = sessionId;
9834
- const debugDir = path13.join(os2.homedir(), ".bike4mind", "debug");
9835
- await fs11.mkdir(debugDir, { recursive: true });
9836
- this.logFilePath = path13.join(debugDir, `${sessionId}.txt`);
9941
+ const debugDir = path14.join(os2.homedir(), ".bike4mind", "debug");
9942
+ await fs12.mkdir(debugDir, { recursive: true });
9943
+ this.logFilePath = path14.join(debugDir, `${sessionId}.txt`);
9837
9944
  await this.writeToFile("INFO", "=== CLI SESSION START ===");
9838
9945
  }
9839
9946
  /**
@@ -9897,7 +10004,7 @@ var Logger2 = class _Logger {
9897
10004
  const timestamp = (/* @__PURE__ */ new Date()).toISOString().replace("T", " ").substring(0, 19);
9898
10005
  const logEntry = `[${timestamp}] [${level}] ${message}
9899
10006
  `;
9900
- await fs11.appendFile(this.logFilePath, logEntry, "utf-8");
10007
+ await fs12.appendFile(this.logFilePath, logEntry, "utf-8");
9901
10008
  } catch (error) {
9902
10009
  console.error("File logging failed:", error);
9903
10010
  }
@@ -10043,15 +10150,15 @@ var Logger2 = class _Logger {
10043
10150
  async cleanupOldLogs() {
10044
10151
  if (!this.fileLoggingEnabled) return;
10045
10152
  try {
10046
- const debugDir = path13.join(os2.homedir(), ".bike4mind", "debug");
10047
- const files = await fs11.readdir(debugDir);
10153
+ const debugDir = path14.join(os2.homedir(), ".bike4mind", "debug");
10154
+ const files = await fs12.readdir(debugDir);
10048
10155
  const now = Date.now();
10049
10156
  const thirtyDaysAgo = now - 30 * 24 * 60 * 60 * 1e3;
10050
10157
  for (const file of files) {
10051
- const filePath = path13.join(debugDir, file);
10052
- const stats = await fs11.stat(filePath);
10158
+ const filePath = path14.join(debugDir, file);
10159
+ const stats = await fs12.stat(filePath);
10053
10160
  if (stats.mtime.getTime() < thirtyDaysAgo) {
10054
- await fs11.unlink(filePath);
10161
+ await fs12.unlink(filePath);
10055
10162
  }
10056
10163
  }
10057
10164
  } catch (error) {
@@ -10108,10 +10215,10 @@ var SERVER_TOOLS = ["weather_info", "web_search"];
10108
10215
  var LOCAL_TOOLS = [
10109
10216
  "file_read",
10110
10217
  "create_file",
10218
+ "edit_local_file",
10111
10219
  "glob_files",
10112
10220
  "grep_search",
10113
10221
  "delete_file",
10114
- "edit_file",
10115
10222
  "dice_roll",
10116
10223
  "math_evaluate",
10117
10224
  "current_datetime",
@@ -10145,21 +10252,21 @@ var NoOpStorage = class extends BaseStorage {
10145
10252
  async upload(input, destination, options) {
10146
10253
  return `/tmp/${destination}`;
10147
10254
  }
10148
- async download(path16) {
10255
+ async download(path17) {
10149
10256
  throw new Error("Download not supported in CLI");
10150
10257
  }
10151
- async delete(path16) {
10258
+ async delete(path17) {
10152
10259
  }
10153
- async getSignedUrl(path16) {
10154
- return `/tmp/${path16}`;
10260
+ async getSignedUrl(path17) {
10261
+ return `/tmp/${path17}`;
10155
10262
  }
10156
- getPublicUrl(path16) {
10157
- return `/tmp/${path16}`;
10263
+ getPublicUrl(path17) {
10264
+ return `/tmp/${path17}`;
10158
10265
  }
10159
- async getPreview(path16) {
10160
- return `/tmp/${path16}`;
10266
+ async getPreview(path17) {
10267
+ return `/tmp/${path17}`;
10161
10268
  }
10162
- async getMetadata(path16) {
10269
+ async getMetadata(path17) {
10163
10270
  return { size: 0, contentType: "application/octet-stream" };
10164
10271
  }
10165
10272
  };
@@ -10191,11 +10298,12 @@ function wrapToolWithPermission(tool, permissionManager, showPermissionPrompt, a
10191
10298
  return result2;
10192
10299
  }
10193
10300
  let preview;
10194
- if (toolName === "edit_file" && args?.path && args?.content) {
10301
+ if (toolName === "edit_local_file" && args?.path && args?.old_string && typeof args?.new_string === "string") {
10195
10302
  try {
10196
- preview = await generateFileDiffPreview({
10303
+ preview = generateEditLocalFilePreview({
10197
10304
  path: args.path,
10198
- content: args.content
10305
+ old_string: args.old_string,
10306
+ new_string: args.new_string
10199
10307
  });
10200
10308
  } catch (error) {
10201
10309
  preview = `[Could not generate preview: ${error instanceof Error ? error.message : "Unknown error"}]`;
@@ -10312,6 +10420,7 @@ function generateCliTools(userId, llm, model, permissionManager, showPermissionP
10312
10420
  // File operation tools (CLI-specific, local execution)
10313
10421
  file_read: {},
10314
10422
  create_file: {},
10423
+ edit_local_file: {},
10315
10424
  glob_files: {},
10316
10425
  grep_search: {},
10317
10426
  delete_file: {},
@@ -10394,6 +10503,7 @@ var DEFAULT_TOOL_CATEGORIES = {
10394
10503
  // These tools can modify files, execute code, or have other dangerous side effects
10395
10504
  // They ALWAYS require permission and cannot be trusted automatically
10396
10505
  edit_file: "prompt_always",
10506
+ edit_local_file: "prompt_always",
10397
10507
  create_file: "prompt_always",
10398
10508
  delete_file: "prompt_always",
10399
10509
  shell_execute: "prompt_always",
@@ -10560,8 +10670,8 @@ function getEnvironmentName(configApiConfig) {
10560
10670
  }
10561
10671
 
10562
10672
  // src/utils/contextLoader.ts
10563
- import * as fs12 from "fs";
10564
- import * as path14 from "path";
10673
+ import * as fs13 from "fs";
10674
+ import * as path15 from "path";
10565
10675
  import { homedir as homedir4 } from "os";
10566
10676
  var CONTEXT_FILE_SIZE_LIMIT = 100 * 1024;
10567
10677
  var PROJECT_CONTEXT_FILES = [
@@ -10582,9 +10692,9 @@ function formatFileSize2(bytes) {
10582
10692
  return `${(bytes / (1024 * 1024)).toFixed(1)}MB`;
10583
10693
  }
10584
10694
  function tryReadContextFile(dir, filename, source) {
10585
- const filePath = path14.join(dir, filename);
10695
+ const filePath = path15.join(dir, filename);
10586
10696
  try {
10587
- const stats = fs12.lstatSync(filePath);
10697
+ const stats = fs13.lstatSync(filePath);
10588
10698
  if (stats.isDirectory()) {
10589
10699
  return null;
10590
10700
  }
@@ -10598,7 +10708,7 @@ function tryReadContextFile(dir, filename, source) {
10598
10708
  error: `${source === "global" ? "Global" : "Project"} ${filename} exceeds 100KB limit (${formatFileSize2(stats.size)})`
10599
10709
  };
10600
10710
  }
10601
- const content = fs12.readFileSync(filePath, "utf-8");
10711
+ const content = fs13.readFileSync(filePath, "utf-8");
10602
10712
  return {
10603
10713
  filename,
10604
10714
  content,
@@ -10650,7 +10760,7 @@ ${project.content}`;
10650
10760
  }
10651
10761
  async function loadContextFiles(projectDir) {
10652
10762
  const errors = [];
10653
- const globalDir = path14.join(homedir4(), ".bike4mind");
10763
+ const globalDir = path15.join(homedir4(), ".bike4mind");
10654
10764
  const projectDirectory = projectDir || process.cwd();
10655
10765
  const [globalResult, projectResult] = await Promise.all([
10656
10766
  Promise.resolve(findContextFile(globalDir, GLOBAL_CONTEXT_FILES, "global")),
@@ -10686,8 +10796,8 @@ function substituteArguments(template, args) {
10686
10796
  // ../../b4m-core/packages/mcp/dist/src/client.js
10687
10797
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
10688
10798
  import { Client as Client2 } from "@modelcontextprotocol/sdk/client/index.js";
10689
- import path15 from "path";
10690
- import { existsSync as existsSync8, readdirSync as readdirSync3 } from "fs";
10799
+ import path16 from "path";
10800
+ import { existsSync as existsSync9, readdirSync as readdirSync3 } from "fs";
10691
10801
  var MCPClient = class {
10692
10802
  // Note: This class handles MCP server communication with repository filtering
10693
10803
  mcp;
@@ -10727,18 +10837,18 @@ var MCPClient = class {
10727
10837
  const root = process.env.INIT_CWD || process.cwd();
10728
10838
  const candidatePaths = [
10729
10839
  // When running from SST Lambda with node_modules structure (copyFiles)
10730
- path15.join(root, `node_modules/@bike4mind/mcp/dist/src/${this.serverName}/index.js`),
10840
+ path16.join(root, `node_modules/@bike4mind/mcp/dist/src/${this.serverName}/index.js`),
10731
10841
  // When running from SST Lambda deployed environment (/var/task)
10732
- path15.join(root, `b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
10842
+ path16.join(root, `b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
10733
10843
  // When running from SST Lambda (.sst/artifacts/mcpHandler-dev), navigate to monorepo root (3 levels up)
10734
- path15.join(root, `../../../b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
10844
+ path16.join(root, `../../../b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
10735
10845
  // When running from packages/client (Next.js app), navigate to monorepo root (2 levels up)
10736
- path15.join(root, `../../b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
10846
+ path16.join(root, `../../b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
10737
10847
  // Original paths (backward compatibility)
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")
10848
+ path16.join(root, `/b4m-core/packages/mcp/dist/src/${this.serverName}/index.js`),
10849
+ path16.join(root, "core", "mcp", "servers", this.serverName, "dist", "index.js")
10740
10850
  ];
10741
- const serverScriptPath = candidatePaths.find((p) => existsSync8(p));
10851
+ const serverScriptPath = candidatePaths.find((p) => existsSync9(p));
10742
10852
  if (!serverScriptPath) {
10743
10853
  const getDirectories = (source) => readdirSync3(source, { withFileTypes: true }).filter((dirent) => dirent.isDirectory()).map((dirent) => dirent.name);
10744
10854
  console.error(`[MCP] Server script not found. Tried paths:`, candidatePaths);
@@ -11253,8 +11363,7 @@ var ServerLlmBackend = class {
11253
11363
  reject(error);
11254
11364
  });
11255
11365
  } catch (error) {
11256
- const errorMsg = error instanceof Error ? error.message : String(error);
11257
- logger.error(`LLM completion failed: ${errorMsg}`);
11366
+ logger.error("LLM completion failed", error);
11258
11367
  if (isAxiosError(error)) {
11259
11368
  logger.debug(
11260
11369
  `[ServerLlmBackend] Axios error details: ${JSON.stringify({
@@ -11297,8 +11406,8 @@ var ServerLlmBackend = class {
11297
11406
  } catch (extractError) {
11298
11407
  logger.error("[ServerLlmBackend] Error extracting response:", extractError);
11299
11408
  }
11300
- const errorMsg2 = errorDetails ? `403 Forbidden: ${errorDetails}` : "403 Forbidden - Request blocked by server. Check debug logs at ~/.bike4mind/debug/";
11301
- reject(new Error(errorMsg2));
11409
+ const errorMsg = errorDetails ? `403 Forbidden: ${errorDetails}` : "403 Forbidden - Request blocked by server. Check debug logs at ~/.bike4mind/debug/";
11410
+ reject(new Error(errorMsg));
11302
11411
  return;
11303
11412
  }
11304
11413
  if (error.response) {
@@ -11317,12 +11426,6 @@ var ServerLlmBackend = class {
11317
11426
  reject(new Error("Cannot connect to Bike4Mind server. Please check your internet connection."));
11318
11427
  } else if (error.message.includes("Rate limit exceeded")) {
11319
11428
  reject(error);
11320
- } else if (error.message.includes("socket hang up")) {
11321
- reject(
11322
- new Error(
11323
- "Connection to server was interrupted (socket hang up). This can happen due to server timeouts or network issues. Please try again."
11324
- )
11325
- );
11326
11429
  } else {
11327
11430
  reject(new Error(`Failed to complete LLM request: ${error.message}`));
11328
11431
  }
@@ -11555,7 +11658,7 @@ import { isAxiosError as isAxiosError2 } from "axios";
11555
11658
  // package.json
11556
11659
  var package_default = {
11557
11660
  name: "@bike4mind/cli",
11558
- version: "0.2.11-fix-cli-socket-hangup-error-handling.17321+491f73515",
11661
+ version: "0.2.11-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
11559
11662
  type: "module",
11560
11663
  description: "Interactive CLI tool for Bike4Mind with ReAct agents",
11561
11664
  license: "UNLICENSED",
@@ -11659,10 +11762,10 @@ var package_default = {
11659
11762
  },
11660
11763
  devDependencies: {
11661
11764
  "@bike4mind/agents": "0.1.0",
11662
- "@bike4mind/common": "2.40.1-fix-cli-socket-hangup-error-handling.17321+491f73515",
11663
- "@bike4mind/mcp": "1.20.5-fix-cli-socket-hangup-error-handling.17321+491f73515",
11664
- "@bike4mind/services": "2.35.1-fix-cli-socket-hangup-error-handling.17321+491f73515",
11665
- "@bike4mind/utils": "2.1.5-fix-cli-socket-hangup-error-handling.17321+491f73515",
11765
+ "@bike4mind/common": "2.40.1-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
11766
+ "@bike4mind/mcp": "1.20.5-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
11767
+ "@bike4mind/services": "2.35.1-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
11768
+ "@bike4mind/utils": "2.1.5-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
11666
11769
  "@types/better-sqlite3": "^7.6.13",
11667
11770
  "@types/diff": "^5.0.9",
11668
11771
  "@types/jsonwebtoken": "^9.0.4",
@@ -11675,7 +11778,7 @@ var package_default = {
11675
11778
  typescript: "^5.9.3",
11676
11779
  vitest: "^3.2.4"
11677
11780
  },
11678
- gitHead: "491f7351545d881122b4f774bf1bd92ac6439c2a"
11781
+ gitHead: "d0f7a31b8292d28c6d873bf34f9119e6fa48d8b0"
11679
11782
  };
11680
11783
 
11681
11784
  // src/config/constants.ts
@@ -11757,21 +11860,9 @@ var SubagentOrchestrator = class {
11757
11860
  this.beforeRunCallback(subagent, type);
11758
11861
  }
11759
11862
  const startTime = Date.now();
11760
- let result;
11761
- try {
11762
- result = await subagent.run(task, {
11763
- maxIterations
11764
- });
11765
- } catch (error) {
11766
- const duration2 = Date.now() - startTime;
11767
- const errorMessage = error instanceof Error ? error.message : String(error);
11768
- this.deps.logger.error(`Subagent failed after ${duration2}ms: ${errorMessage}`);
11769
- throw new Error(
11770
- `Subagent execution failed: ${errorMessage}
11771
-
11772
- This error occurred while running a ${type} subagent. The main conversation has been preserved, and you can retry or continue with other tasks.`
11773
- );
11774
- }
11863
+ const result = await subagent.run(task, {
11864
+ maxIterations
11865
+ });
11775
11866
  const duration = Date.now() - startTime;
11776
11867
  if (this.afterRunCallback) {
11777
11868
  this.afterRunCallback(subagent, type);
@@ -11929,6 +12020,7 @@ Focus on:
11929
12020
  - Creating logical sequence of steps
11930
12021
  - Estimating scope and priorities
11931
12022
 
12023
+ You have read-only access to analyze code.
11932
12024
  You can explore the codebase to understand the current architecture before planning.
11933
12025
 
11934
12026
  Provide a structured plan that the main agent can execute.`,
@@ -11985,18 +12077,13 @@ function createSubagentDelegateTool(orchestrator, parentSessionId) {
11985
12077
  }
11986
12078
  const thoroughness = params.thoroughness || "medium";
11987
12079
  const type = params.type;
11988
- try {
11989
- const result = await orchestrator.delegateToSubagent({
11990
- task: params.task,
11991
- type,
11992
- thoroughness,
11993
- parentSessionId
11994
- });
11995
- return result.summary;
11996
- } catch (error) {
11997
- const errorMessage = error instanceof Error ? error.message : String(error);
11998
- throw new Error(`Failed to execute ${type} subagent: ${errorMessage}`);
11999
- }
12080
+ const result = await orchestrator.delegateToSubagent({
12081
+ task: params.task,
12082
+ type,
12083
+ thoroughness,
12084
+ parentSessionId
12085
+ });
12086
+ return result.summary;
12000
12087
  },
12001
12088
  toolSchema: {
12002
12089
  name: "subagent_delegate",
@@ -12400,20 +12487,38 @@ Remember: Use context from previous messages to understand follow-up questions.$
12400
12487
  const lastIdx = pendingMessages.length - 1;
12401
12488
  if (lastIdx >= 0 && pendingMessages[lastIdx].role === "assistant") {
12402
12489
  const existingSteps = pendingMessages[lastIdx].metadata?.steps || [];
12490
+ const MAX_INPUT_LENGTH = 500;
12491
+ let truncatedStep = step;
12492
+ if (step.type === "action" && step.metadata?.toolInput) {
12493
+ const inputStr = typeof step.metadata.toolInput === "string" ? step.metadata.toolInput : JSON.stringify(step.metadata.toolInput);
12494
+ if (inputStr.length > MAX_INPUT_LENGTH) {
12495
+ const truncatedInput = inputStr.slice(0, MAX_INPUT_LENGTH) + `... (${inputStr.length - MAX_INPUT_LENGTH} more chars)`;
12496
+ truncatedStep = {
12497
+ ...step,
12498
+ metadata: {
12499
+ ...step.metadata,
12500
+ toolInput: truncatedInput
12501
+ }
12502
+ };
12503
+ }
12504
+ }
12403
12505
  updatePendingMessage(lastIdx, {
12404
12506
  ...pendingMessages[lastIdx],
12405
12507
  metadata: {
12406
12508
  ...pendingMessages[lastIdx].metadata,
12407
- steps: [...existingSteps, step]
12509
+ steps: [...existingSteps, truncatedStep]
12408
12510
  }
12409
12511
  });
12410
12512
  }
12411
12513
  };
12514
+ agent.on("thought", stepHandler);
12412
12515
  agent.on("action", stepHandler);
12413
12516
  orchestrator.setBeforeRunCallback((subagent, _subagentType) => {
12517
+ subagent.on("thought", stepHandler);
12414
12518
  subagent.on("action", stepHandler);
12415
12519
  });
12416
12520
  orchestrator.setAfterRunCallback((subagent, _subagentType) => {
12521
+ subagent.off("thought", stepHandler);
12417
12522
  subagent.off("action", stepHandler);
12418
12523
  });
12419
12524
  setState((prev) => ({
@@ -12482,6 +12587,7 @@ Remember: Use context from previous messages to understand follow-up questions.$
12482
12587
  }
12483
12588
  }
12484
12589
  };
12590
+ state.agent.on("thought", stepHandler);
12485
12591
  state.agent.on("action", stepHandler);
12486
12592
  try {
12487
12593
  let messageContent = fullTemplate;
@@ -12603,6 +12709,7 @@ Remember: Use context from previous messages to understand follow-up questions.$
12603
12709
  setState((prev) => ({ ...prev, session: sessionWithError }));
12604
12710
  setStoreSession(sessionWithError);
12605
12711
  } finally {
12712
+ state.agent.off("thought", stepHandler);
12606
12713
  state.agent.off("action", stepHandler);
12607
12714
  }
12608
12715
  };
@@ -12635,13 +12742,6 @@ Remember: Use context from previous messages to understand follow-up questions.$
12635
12742
  content: userMessageContent,
12636
12743
  timestamp: (/* @__PURE__ */ new Date()).toISOString()
12637
12744
  };
12638
- const sessionWithUserMessage = {
12639
- ...state.session,
12640
- messages: [...state.session.messages, userMessage],
12641
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
12642
- };
12643
- setState((prev) => ({ ...prev, session: sessionWithUserMessage }));
12644
- setStoreSession(sessionWithUserMessage);
12645
12745
  const pendingAssistantMessage = {
12646
12746
  id: uuidv410(),
12647
12747
  role: "assistant",
@@ -12649,9 +12749,15 @@ Remember: Use context from previous messages to understand follow-up questions.$
12649
12749
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
12650
12750
  metadata: {
12651
12751
  steps: []
12652
- // Steps will be populated by the init handler's stepHandler
12653
12752
  }
12654
12753
  };
12754
+ const sessionWithUserMessage = {
12755
+ ...state.session,
12756
+ messages: [...state.session.messages, userMessage],
12757
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
12758
+ };
12759
+ setState((prev) => ({ ...prev, session: sessionWithUserMessage }));
12760
+ setStoreSession(sessionWithUserMessage);
12655
12761
  useCliStore.getState().addPendingMessage(pendingAssistantMessage);
12656
12762
  const recentMessages = state.session.messages.slice(-20);
12657
12763
  const previousMessages = recentMessages.filter((msg) => msg.role === "user" || msg.role === "assistant").map((msg) => ({
@@ -12698,51 +12804,15 @@ Remember: Use context from previous messages to understand follow-up questions.$
12698
12804
  setStoreSession(updatedSession);
12699
12805
  await state.sessionStore.save(updatedSession);
12700
12806
  } catch (error) {
12701
- const errorMessage = error instanceof Error ? error.message : String(error);
12702
- let displayMessage;
12807
+ useCliStore.getState().clearPendingMessages();
12703
12808
  if (error instanceof Error) {
12704
12809
  if (error.message.includes("Authentication failed") || error.message.includes("Authentication expired")) {
12705
- displayMessage = "\u274C Authentication failed\n\n\u{1F4A1} Run /login to authenticate with your API environment.";
12706
- } else if (error.message.includes("socket hang up")) {
12707
- displayMessage = `\u26A0\uFE0F Connection Error
12708
-
12709
- ${errorMessage}
12710
-
12711
- \u{1F4A1} This is usually a temporary issue. Please try your request again.`;
12712
- } else {
12713
- displayMessage = `\u274C Error
12714
-
12715
- ${errorMessage}`;
12716
- }
12717
- } else {
12718
- displayMessage = `\u274C Error
12719
-
12720
- ${errorMessage}`;
12721
- }
12722
- const { pendingMessages } = useCliStore.getState();
12723
- const pendingMessage = pendingMessages[0];
12724
- const capturedSteps = pendingMessage?.metadata?.steps || [];
12725
- const errorAssistantMessage = {
12726
- id: pendingMessage?.id || uuidv410(),
12727
- role: "assistant",
12728
- content: displayMessage,
12729
- timestamp: pendingMessage?.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
12730
- metadata: {
12731
- steps: capturedSteps
12732
- // Include any steps that were completed before error
12810
+ console.log("\n\u274C Authentication failed");
12811
+ console.log("\u{1F4A1} Run /login to authenticate with your API environment.\n");
12812
+ return;
12733
12813
  }
12734
- };
12735
- useCliStore.getState().completePendingMessage(0, errorAssistantMessage);
12736
- const currentSession = useCliStore.getState().session;
12737
- if (currentSession) {
12738
- const updatedSession = {
12739
- ...currentSession,
12740
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
12741
- };
12742
- setState((prev) => ({ ...prev, session: updatedSession }));
12743
- setStoreSession(updatedSession);
12744
- await state.sessionStore.save(updatedSession);
12745
12814
  }
12815
+ console.error("Error processing message:", error);
12746
12816
  }
12747
12817
  };
12748
12818
  const handleBashCommand = useCallback(
@@ -12961,7 +13031,6 @@ Custom Commands:
12961
13031
  logger.debug("=== Session Resumed ===");
12962
13032
  setState((prev) => ({ ...prev, session: loadedSession }));
12963
13033
  setStoreSession(loadedSession);
12964
- useCliStore.getState().clearAgentSteps();
12965
13034
  useCliStore.getState().clearPendingMessages();
12966
13035
  usageCache = null;
12967
13036
  console.log(`
@@ -13197,7 +13266,6 @@ Custom Commands:
13197
13266
  logger.debug("=== New Session Started via /clear ===");
13198
13267
  setState((prev) => ({ ...prev, session: newSession }));
13199
13268
  setStoreSession(newSession);
13200
- useCliStore.getState().clearAgentSteps();
13201
13269
  useCliStore.getState().clearPendingMessages();
13202
13270
  usageCache = null;
13203
13271
  console.log("New session started.");
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-3OX632TE.js";
4
+ } from "./chunk-ZJUZR27P.js";
5
5
  import "./chunk-PDX44BCA.js";
6
6
 
7
7
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/llmMarkdownGenerator.js
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CurationArtifactType
4
- } from "./chunk-3OX632TE.js";
4
+ } from "./chunk-ZJUZR27P.js";
5
5
  import "./chunk-PDX44BCA.js";
6
6
 
7
7
  // ../../b4m-core/packages/services/dist/src/notebookCurationService/markdownGenerator.js
@@ -2,10 +2,10 @@
2
2
  import {
3
3
  findMostSimilarMemento,
4
4
  getRelevantMementos
5
- } from "./chunk-7JR6VASX.js";
6
- import "./chunk-JYH72REB.js";
5
+ } from "./chunk-F6ZKDGCA.js";
6
+ import "./chunk-PUL75ZDO.js";
7
7
  import "./chunk-AMDXHL6S.js";
8
- import "./chunk-3OX632TE.js";
8
+ import "./chunk-ZJUZR27P.js";
9
9
  import "./chunk-PDX44BCA.js";
10
10
  export {
11
11
  findMostSimilarMemento,
@@ -229,6 +229,7 @@ import {
229
229
  canUserDeleteArtifact,
230
230
  canUserReadArtifact,
231
231
  canUserWriteArtifact,
232
+ containsWikiTable,
232
233
  createArtifactId,
233
234
  createDefaultPermissions,
234
235
  dayjsConfig_default,
@@ -292,8 +293,9 @@ import {
292
293
  validateQuest,
293
294
  validateQuestMasterArtifactV2,
294
295
  validateReactArtifactV2,
295
- validateSvgArtifactV2
296
- } from "./chunk-3OX632TE.js";
296
+ validateSvgArtifactV2,
297
+ wikiMarkupToAdf
298
+ } from "./chunk-ZJUZR27P.js";
297
299
  import "./chunk-PDX44BCA.js";
298
300
  export {
299
301
  ALL_IMAGE_MODELS,
@@ -525,6 +527,7 @@ export {
525
527
  canUserDeleteArtifact,
526
528
  canUserReadArtifact,
527
529
  canUserWriteArtifact,
530
+ containsWikiTable,
528
531
  createArtifactId,
529
532
  createDefaultPermissions,
530
533
  dayjsConfig_default as dayjs,
@@ -588,5 +591,6 @@ export {
588
591
  validateQuest,
589
592
  validateQuestMasterArtifactV2,
590
593
  validateReactArtifactV2,
591
- validateSvgArtifactV2
594
+ validateSvgArtifactV2,
595
+ wikiMarkupToAdf
592
596
  };
@@ -120,7 +120,7 @@ import {
120
120
  validateMermaidSyntax,
121
121
  warmUpSettingsCache,
122
122
  withRetry
123
- } from "./chunk-JYH72REB.js";
123
+ } from "./chunk-PUL75ZDO.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-3OX632TE.js";
132
+ import "./chunk-ZJUZR27P.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-7ORA6KGN.js";
6
- import "./chunk-JYH72REB.js";
5
+ } from "./chunk-2OWNLDU2.js";
6
+ import "./chunk-PUL75ZDO.js";
7
7
  import "./chunk-AMDXHL6S.js";
8
- import "./chunk-3OX632TE.js";
8
+ import "./chunk-ZJUZR27P.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-socket-hangup-error-handling.17321+491f73515",
3
+ "version": "0.2.11-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
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-socket-hangup-error-handling.17321+491f73515",
108
- "@bike4mind/mcp": "1.20.5-fix-cli-socket-hangup-error-handling.17321+491f73515",
109
- "@bike4mind/services": "2.35.1-fix-cli-socket-hangup-error-handling.17321+491f73515",
110
- "@bike4mind/utils": "2.1.5-fix-cli-socket-hangup-error-handling.17321+491f73515",
107
+ "@bike4mind/common": "2.40.1-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
108
+ "@bike4mind/mcp": "1.20.5-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
109
+ "@bike4mind/services": "2.35.1-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
110
+ "@bike4mind/utils": "2.1.5-ja-fix-confluence-table-data-5752.17351+d0f7a31b8",
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": "491f7351545d881122b4f774bf1bd92ac6439c2a"
123
+ "gitHead": "d0f7a31b8292d28c6d873bf34f9119e6fa48d8b0"
124
124
  }