blun-king-cli 9.1.640 → 9.1.641

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 9.1.641 – MCP-Originaltextretention (Prüfkandidat)
2
+
3
+ - Große MCP-Textausgaben vor der Kontextkürzung privat speichern und mit Read seitenweise nachlesen.
4
+ - Bestehende generische Spillverzeichnisse bleiben kompatibel; keine automatische Rechteänderung.
5
+ - Selektive Portierung auf Registry640, keine native Gesamtfreigabe.
6
+
1
7
  ## 9.1.640
2
8
 
3
9
  - Konfigurationsschreiben und gelernte Anfragegrenzen teilen eine Sperre mit Besitzertoken.
package/blun.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // BLUN_BUILD_INPUT_SHA256:4ddd869ff27cd786caab65fef2e4a43ddeb636eb25fdea7ff03b52a5a716faab
2
+ // BLUN_BUILD_INPUT_SHA256:d4df2815be55011d12f15cf3f9b01e9c4c1ba80d84ef9322ad9e8fd20b13e018
3
3
  /*! wasm-webp 0.1.0
4
4
  MIT License
5
5
 
@@ -256655,6 +256655,43 @@ function convertMCPContentBlock(block) {
256655
256655
  * `mcp__github__create_pr`) — embedded into the `<mcp_tool_result name="…">`
256656
256656
  * wrap when the result is media-only, so the model can attribute binary parts.
256657
256657
  */
256658
+ async function retainOriginalText(parts, toolName, homedir) {
256659
+ const textParts = parts.flatMap((part) => {
256660
+ if (part.type !== "text") return [];
256661
+ const chunks = [];
256662
+ for (let offset = 0; offset < part.text.length; offset += 256) chunks.push(part.text.slice(offset, offset + 256));
256663
+ return [chunks];
256664
+ });
256665
+ const archive = JSON.stringify({
256666
+ version: 1,
256667
+ textParts
256668
+ }, null, 2);
256669
+ const outputPath = homedir === void 0 ? void 0 : await saveToolResult({
256670
+ homedir,
256671
+ toolName,
256672
+ toolCallId: "mcp-original",
256673
+ directoryPolicy: "private-retention"
256674
+ }, archive);
256675
+ if (outputPath === void 0) return "\n\n[Originaltext nicht gespeichert: Sitzungsverzeichnis fehlt oder Schreiben fehlgeschlagen. Die Ausgabe bleibt begrenzt.]";
256676
+ return [
256677
+ "",
256678
+ "",
256679
+ "MCP-Originaltext vor Kürzung gespeichert (JSON, version: 1, textParts: Zeichenabschnitte je Textblock; ohne Binärdaten).",
256680
+ `output_path: ${outputPath}`,
256681
+ "Mit Read seitenweise nachlesen. Zeichenabschnitte je Block ohne Trennzeichen verbinden; Blockreihenfolge erhalten."
256682
+ ].join("\n");
256683
+ }
256684
+ function appendTextNotice(parts, text) {
256685
+ const last = parts.at(-1);
256686
+ if (last?.type === "text") parts[parts.length - 1] = {
256687
+ ...last,
256688
+ text: last.text + text
256689
+ };
256690
+ else parts.push({
256691
+ type: "text",
256692
+ text
256693
+ });
256694
+ }
256658
256695
  async function mcpResultToExecutableOutput(result, qualifiedToolName, options = {}) {
256659
256696
  const converted = [];
256660
256697
  for (const block of result.content) {
@@ -256662,8 +256699,10 @@ async function mcpResultToExecutableOutput(result, qualifiedToolName, options =
256662
256699
  if (part !== null) converted.push(part);
256663
256700
  }
256664
256701
  const budgeted = applyTextBudget(wrapMediaOnly(converted, qualifiedToolName));
256702
+ const retentionNotice = budgeted.truncated ? await retainOriginalText(converted, qualifiedToolName, options.homedir) : void 0;
256665
256703
  const capped = applyBinaryPartCap(await compressImageContentParts(budgeted.parts, { annotate: { persistOriginal: (bytes, mimeType) => persistOriginalImage(bytes, mimeType, options.originalsDir === void 0 ? {} : { dir: options.originalsDir }) } }));
256666
256704
  const truncated = budgeted.truncated || capped.truncated;
256705
+ if (retentionNotice !== void 0) appendTextNotice(capped.parts, retentionNotice);
256667
256706
  const output = collapseSingleText(capped.parts);
256668
256707
  return truncated ? {
256669
256708
  output,
@@ -256809,6 +256848,7 @@ function collapseSingleText(parts) {
256809
256848
  }
256810
256849
  var MCP_MAX_OUTPUT_CHARS, MCP_OUTPUT_TRUNCATED_TEXT, MCP_MAX_BINARY_PART_BYTES, MCP_MAX_BINARY_PART_CHARS;
256811
256850
  var init_output = __esmMin((() => {
256851
+ init_tool_result_budget();
256812
256852
  init_image_compress();
256813
256853
  init_image_originals();
256814
256854
  MCP_MAX_OUTPUT_CHARS = 1e5;
@@ -265065,7 +265105,8 @@ async function budgetToolResultForModel(options) {
265065
265105
  const outputPath = await saveToolResult({
265066
265106
  homedir: options.homedir,
265067
265107
  toolName: options.toolName,
265068
- toolCallId: options.toolCallId
265108
+ toolCallId: options.toolCallId,
265109
+ directoryPolicy: "compatible-spill"
265069
265110
  }, text);
265070
265111
  if (outputPath === void 0) return options.result;
265071
265112
  const output = renderPersistedToolResult(options.toolName, options.toolCallId, text, outputPath);
@@ -265084,19 +265125,33 @@ function persistableToolResultText(output) {
265084
265125
  return output.map((part) => part.text).join("");
265085
265126
  }
265086
265127
  async function saveToolResult(options, text) {
265128
+ if (!isAbsolute$2(options.homedir)) return void 0;
265129
+ let createdPath;
265087
265130
  try {
265088
265131
  const dir = join$4(options.homedir, "tool-results");
265089
265132
  await mkdir(dir, {
265090
265133
  recursive: true,
265091
265134
  mode: 448
265092
265135
  });
265136
+ const info = await lstat(dir);
265137
+ if (info.isSymbolicLink()) return void 0;
265138
+ if (process.platform !== "win32") {
265139
+ if (info.uid !== process.getuid?.()) return void 0;
265140
+ if (options.directoryPolicy === "private-retention" && (info.mode & 63) !== 0) return;
265141
+ }
265142
+ const home = await realpath(options.homedir);
265143
+ if (normalize$4(await realpath(dir)) !== join$4(home, "tool-results")) return void 0;
265093
265144
  const outputPath = join$4(dir, `${safeToolResultFileStem(options.toolName, options.toolCallId)}-${randomUUID()}.txt`);
265094
- await writeFile(outputPath, text, {
265095
- encoding: "utf8",
265096
- flag: "wx"
265097
- });
265145
+ const file = await open(outputPath, "wx", 384);
265146
+ createdPath = outputPath;
265147
+ try {
265148
+ await file.writeFile(text, { encoding: "utf8" });
265149
+ } finally {
265150
+ await file.close();
265151
+ }
265098
265152
  return outputPath;
265099
265153
  } catch {
265154
+ if (createdPath !== void 0) await unlink(createdPath).catch(() => void 0);
265100
265155
  return;
265101
265156
  }
265102
265157
  }
@@ -269342,63 +269397,66 @@ var init_tool$1 = __esmMin((() => {
269342
269397
  }
269343
269398
  }
269344
269399
  registerMcpServer(serverName, client, tools, enabledTools) {
269345
- this.unregisterMcpServer(serverName);
269346
- const qualifiedNames = [];
269347
- const collisions = [];
269348
- const seenInThisCall = /* @__PURE__ */ new Map();
269349
- for (const tool of tools) {
269350
- if (enabledTools !== void 0 && !enabledTools.has(tool.name)) continue;
269351
- const qualified = qualifyMcpToolName(serverName, tool.name);
269352
- const firstInThisCall = seenInThisCall.get(qualified);
269353
- if (firstInThisCall !== void 0) {
269354
- collisions.push({
269355
- qualified,
269356
- toolName: tool.name,
269357
- collidesWith: {
269358
- kind: "same_server",
269359
- toolName: firstInThisCall
269360
- }
269361
- });
269362
- continue;
269363
- }
269364
- const existingEntry = this.mcpTools.get(qualified);
269365
- if (existingEntry !== void 0) {
269366
- collisions.push({
269367
- qualified,
269368
- toolName: tool.name,
269369
- collidesWith: {
269370
- kind: "other_server",
269371
- serverName: existingEntry.serverName
269372
- }
269373
- });
269374
- continue;
269375
- }
269376
- seenInThisCall.set(qualified, tool.name);
269377
- const wrapped = {
269378
- name: qualified,
269379
- description: tool.description,
269380
- parameters: tool.parameters,
269381
- resolveExecution: (args) => {
269382
- return {
269383
- approvalRule: qualified,
269384
- execute: async (context) => {
269385
- return mcpResultToExecutableOutput(await client.callTool(tool.name, args ?? {}, context.signal), qualified, { originalsDir: this.agent.mediaOriginalsDir });
269386
- }
269387
- };
269400
+ this.unregisterMcpServer(serverName);
269401
+ const qualifiedNames = [];
269402
+ const collisions = [];
269403
+ const seenInThisCall = /* @__PURE__ */ new Map();
269404
+ for (const tool of tools) {
269405
+ if (enabledTools !== void 0 && !enabledTools.has(tool.name)) continue;
269406
+ const qualified = qualifyMcpToolName(serverName, tool.name);
269407
+ const firstInThisCall = seenInThisCall.get(qualified);
269408
+ if (firstInThisCall !== void 0) {
269409
+ collisions.push({
269410
+ qualified,
269411
+ toolName: tool.name,
269412
+ collidesWith: {
269413
+ kind: "same_server",
269414
+ toolName: firstInThisCall
269388
269415
  }
269389
- };
269390
- this.mcpTools.set(qualified, {
269391
- tool: wrapped,
269392
- serverName
269393
269416
  });
269394
- qualifiedNames.push(qualified);
269417
+ continue;
269395
269418
  }
269396
- this.mcpToolsByServer.set(serverName, qualifiedNames);
269397
- return {
269398
- registered: qualifiedNames,
269399
- collisions
269419
+ const existingEntry = this.mcpTools.get(qualified);
269420
+ if (existingEntry !== void 0) {
269421
+ collisions.push({
269422
+ qualified,
269423
+ toolName: tool.name,
269424
+ collidesWith: {
269425
+ kind: "other_server",
269426
+ serverName: existingEntry.serverName
269427
+ }
269428
+ });
269429
+ continue;
269430
+ }
269431
+ seenInThisCall.set(qualified, tool.name);
269432
+ const wrapped = {
269433
+ name: qualified,
269434
+ description: tool.description,
269435
+ parameters: tool.parameters,
269436
+ resolveExecution: (args) => {
269437
+ return {
269438
+ approvalRule: qualified,
269439
+ execute: async (context) => {
269440
+ return mcpResultToExecutableOutput(await client.callTool(tool.name, args ?? {}, context.signal), qualified, {
269441
+ originalsDir: this.agent.mediaOriginalsDir,
269442
+ homedir: this.agent.homedir
269443
+ });
269444
+ }
269445
+ };
269446
+ }
269400
269447
  };
269448
+ this.mcpTools.set(qualified, {
269449
+ tool: wrapped,
269450
+ serverName
269451
+ });
269452
+ qualifiedNames.push(qualified);
269401
269453
  }
269454
+ this.mcpToolsByServer.set(serverName, qualifiedNames);
269455
+ return {
269456
+ registered: qualifiedNames,
269457
+ collisions
269458
+ };
269459
+ }
269402
269460
  unregisterMcpServer(serverName) {
269403
269461
  const existing = this.mcpToolsByServer.get(serverName);
269404
269462
  if (existing === void 0) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.640",
3
+ "version": "9.1.641",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {
package/worker-host.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- // BLUN_BUILD_INPUT_SHA256:0b1614e40c5a323438b4f9cd742ea9a101c55f926d094603efc957fad265637a
2
+ // BLUN_BUILD_INPUT_SHA256:d4df2815be55011d12f15cf3f9b01e9c4c1ba80d84ef9322ad9e8fd20b13e018
3
3
  /*! wasm-webp 0.1.0
4
4
  MIT License
5
5
 
@@ -256401,6 +256401,43 @@ function convertMCPContentBlock(block) {
256401
256401
  * `mcp__github__create_pr`) — embedded into the `<mcp_tool_result name="…">`
256402
256402
  * wrap when the result is media-only, so the model can attribute binary parts.
256403
256403
  */
256404
+ async function retainOriginalText(parts, toolName, homedir) {
256405
+ const textParts = parts.flatMap((part) => {
256406
+ if (part.type !== "text") return [];
256407
+ const chunks = [];
256408
+ for (let offset = 0; offset < part.text.length; offset += 256) chunks.push(part.text.slice(offset, offset + 256));
256409
+ return [chunks];
256410
+ });
256411
+ const archive = JSON.stringify({
256412
+ version: 1,
256413
+ textParts
256414
+ }, null, 2);
256415
+ const outputPath = homedir === void 0 ? void 0 : await saveToolResult({
256416
+ homedir,
256417
+ toolName,
256418
+ toolCallId: "mcp-original",
256419
+ directoryPolicy: "private-retention"
256420
+ }, archive);
256421
+ if (outputPath === void 0) return "\n\n[Originaltext nicht gespeichert: Sitzungsverzeichnis fehlt oder Schreiben fehlgeschlagen. Die Ausgabe bleibt begrenzt.]";
256422
+ return [
256423
+ "",
256424
+ "",
256425
+ "MCP-Originaltext vor Kürzung gespeichert (JSON, version: 1, textParts: Zeichenabschnitte je Textblock; ohne Binärdaten).",
256426
+ `output_path: ${outputPath}`,
256427
+ "Mit Read seitenweise nachlesen. Zeichenabschnitte je Block ohne Trennzeichen verbinden; Blockreihenfolge erhalten."
256428
+ ].join("\n");
256429
+ }
256430
+ function appendTextNotice(parts, text) {
256431
+ const last = parts.at(-1);
256432
+ if (last?.type === "text") parts[parts.length - 1] = {
256433
+ ...last,
256434
+ text: last.text + text
256435
+ };
256436
+ else parts.push({
256437
+ type: "text",
256438
+ text
256439
+ });
256440
+ }
256404
256441
  async function mcpResultToExecutableOutput(result, qualifiedToolName, options = {}) {
256405
256442
  const converted = [];
256406
256443
  for (const block of result.content) {
@@ -256408,8 +256445,10 @@ async function mcpResultToExecutableOutput(result, qualifiedToolName, options =
256408
256445
  if (part !== null) converted.push(part);
256409
256446
  }
256410
256447
  const budgeted = applyTextBudget(wrapMediaOnly(converted, qualifiedToolName));
256448
+ const retentionNotice = budgeted.truncated ? await retainOriginalText(converted, qualifiedToolName, options.homedir) : void 0;
256411
256449
  const capped = applyBinaryPartCap(await compressImageContentParts(budgeted.parts, { annotate: { persistOriginal: (bytes, mimeType) => persistOriginalImage(bytes, mimeType, options.originalsDir === void 0 ? {} : { dir: options.originalsDir }) } }));
256412
256450
  const truncated = budgeted.truncated || capped.truncated;
256451
+ if (retentionNotice !== void 0) appendTextNotice(capped.parts, retentionNotice);
256413
256452
  const output = collapseSingleText(capped.parts);
256414
256453
  return truncated ? {
256415
256454
  output,
@@ -264596,7 +264635,8 @@ async function budgetToolResultForModel(options) {
264596
264635
  const outputPath = await saveToolResult({
264597
264636
  homedir: options.homedir,
264598
264637
  toolName: options.toolName,
264599
- toolCallId: options.toolCallId
264638
+ toolCallId: options.toolCallId,
264639
+ directoryPolicy: "compatible-spill"
264600
264640
  }, text);
264601
264641
  if (outputPath === void 0) return options.result;
264602
264642
  const output = renderPersistedToolResult(options.toolName, options.toolCallId, text, outputPath);
@@ -264615,19 +264655,33 @@ function persistableToolResultText(output) {
264615
264655
  return output.map((part) => part.text).join("");
264616
264656
  }
264617
264657
  async function saveToolResult(options, text) {
264658
+ if (!isAbsolute$1(options.homedir)) return void 0;
264659
+ let createdPath;
264618
264660
  try {
264619
264661
  const dir = join$1(options.homedir, "tool-results");
264620
264662
  await mkdir(dir, {
264621
264663
  recursive: true,
264622
264664
  mode: 448
264623
264665
  });
264666
+ const info = await lstat(dir);
264667
+ if (info.isSymbolicLink()) return void 0;
264668
+ if (process.platform !== "win32") {
264669
+ if (info.uid !== process.getuid?.()) return void 0;
264670
+ if (options.directoryPolicy === "private-retention" && (info.mode & 63) !== 0) return;
264671
+ }
264672
+ const home = await realpath(options.homedir);
264673
+ if (normalize$3(await realpath(dir)) !== join$1(home, "tool-results")) return void 0;
264624
264674
  const outputPath = join$1(dir, `${safeToolResultFileStem(options.toolName, options.toolCallId)}-${randomUUID()}.txt`);
264625
- await writeFile(outputPath, text, {
264626
- encoding: "utf8",
264627
- flag: "wx"
264628
- });
264675
+ const file = await open(outputPath, "wx", 384);
264676
+ createdPath = outputPath;
264677
+ try {
264678
+ await file.writeFile(text, { encoding: "utf8" });
264679
+ } finally {
264680
+ await file.close();
264681
+ }
264629
264682
  return outputPath;
264630
264683
  } catch {
264684
+ if (createdPath !== void 0) await unlink(createdPath).catch(() => void 0);
264631
264685
  return;
264632
264686
  }
264633
264687
  }
@@ -268730,7 +268784,10 @@ var ToolManager = class {
268730
268784
  return {
268731
268785
  approvalRule: qualified,
268732
268786
  execute: async (context) => {
268733
- return mcpResultToExecutableOutput(await client.callTool(tool.name, args ?? {}, context.signal), qualified, { originalsDir: this.agent.mediaOriginalsDir });
268787
+ return mcpResultToExecutableOutput(await client.callTool(tool.name, args ?? {}, context.signal), qualified, {
268788
+ originalsDir: this.agent.mediaOriginalsDir,
268789
+ homedir: this.agent.homedir
268790
+ });
268734
268791
  }
268735
268792
  };
268736
268793
  }