blun-king-cli 9.1.428 → 9.1.430

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.
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ function resolveCompactionModelAlias(configuredAlias, activeAlias) {
4
+ if (typeof configuredAlias === 'string' && configuredAlias.trim().length > 0) {
5
+ return configuredAlias.trim();
6
+ }
7
+ return activeAlias;
8
+ }
9
+
10
+ module.exports = {
11
+ resolveCompactionModelAlias,
12
+ };
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ const EXPLICIT_CMD_HANDOFF = /(?:^|[;&|]\s*)cmd(?:\.exe)?\s+(?:(?:\/[dqs])\s+)*\/c(?=\s|$)/iu;
4
+ const CMD_MARKERS = [
5
+ ['cd /d', /(?:^|[;&|]\s*)cd\s+\/d(?=\s|$)/iu],
6
+ ['dir /s /b', /(?:^|[;&|]\s*)dir\s+\/s\s+\/b(?=\s|$)/iu],
7
+ ['find /c /v', /(?:^|[;&|]\s*)find\s+\/c\s+\/v(?=\s|$)/iu],
8
+ ['2>nul', /(?:^|[\s;|&])(?:[012]?>|&>)\s*nul(?=$|[\s;|&])/iu],
9
+ ];
10
+
11
+ function windowsBashDialectRefusal({ command, isWindowsBash = false } = {}) {
12
+ if (!isWindowsBash) return undefined;
13
+ const source = String(command || '');
14
+ if (EXPLICIT_CMD_HANDOFF.test(source)) return undefined;
15
+
16
+ const found = CMD_MARKERS.filter(([, pattern]) => pattern.test(source)).map(([label]) => label);
17
+ if (found.length === 0) return undefined;
18
+
19
+ return `Refused Windows cmd.exe syntax in the Bash tool before execution (found: ${found.join(', ')}). `
20
+ + 'This tool runs POSIX Bash on Windows, including inside VS Code. Pass the directory with cwd, '
21
+ + 'use Bash paths and commands such as find or rg, and redirect to /dev/null. '
22
+ + 'If cmd semantics are intentional, invoke cmd.exe /d /s /c explicitly.';
23
+ }
24
+
25
+ module.exports = { windowsBashDialectRefusal };
package/blun.mjs CHANGED
@@ -9,6 +9,7 @@ import telegramConsoleStatusPolicy from "./bin/telegram-console-status-policy.cj
9
9
  import cognitiveGoalAutostartPolicy from "./bin/cognitive-goal-autostart-policy.cjs";
10
10
  import cognitiveGoalTimeTriggerController from "./bin/cognitive-goal-time-trigger-controller.cjs";
11
11
  import runtimeExitLedger from "./bin/runtime-exit-ledger.cjs";
12
+ import compactionModelPolicy from "./bin/compaction-model-policy.cjs";
12
13
  import crypto$1, { createHash, randomBytes, randomInt, randomUUID, timingSafeEqual } from "node:crypto";
13
14
  import * as fs$16 from "node:fs";
14
15
  import Kt, { accessSync, appendFileSync, chmodSync, closeSync, constants, copyFileSync, createReadStream, createWriteStream, existsSync, fsyncSync, linkSync, lstatSync, mkdirSync, openSync, promises, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
@@ -42,6 +43,7 @@ const { writeTelegramConsoleStatus } = telegramConsoleStatusPolicy;
42
43
  const { goalAutostartDecision, goalContinuationDecision } = cognitiveGoalAutostartPolicy;
43
44
  const { GoalTimeTriggerController } = cognitiveGoalTimeTriggerController;
44
45
  const { recordRuntimeExit } = runtimeExitLedger;
46
+ const { resolveCompactionModelAlias } = compactionModelPolicy;
45
47
  import { EventEmitter as EventEmitter$1 } from "node:events";
46
48
  import { StringDecoder } from "node:string_decoder";
47
49
  import co from "node:assert";
@@ -10048,7 +10050,8 @@ var init_schema = __esmMin((() => {
10048
10050
  maxRetriesPerStep: number$1().int().min(0).optional(),
10049
10051
  maxRalphIterations: number$1().int().min(-1).optional(),
10050
10052
  reservedContextSize: number$1().int().min(0).optional(),
10051
- compactionTriggerRatio: number$1().min(.5).max(.99).optional()
10053
+ compactionTriggerRatio: number$1().min(.5).max(.99).optional(),
10054
+ compactionModel: string().min(1).optional()
10052
10055
  });
10053
10056
  BackgroundConfigSchema = object({
10054
10057
  maxRunningTasks: number$1().int().min(1).optional(),
@@ -75620,11 +75623,11 @@ var init_full = __esmMin((() => {
75620
75623
  let retryCount = 0;
75621
75624
  try {
75622
75625
  await this.triggerPreCompactHook(data, tokensBefore, signal);
75623
- const model = this.agent.activeResponderModel ?? this.agent.config.model;
75626
+ const model = resolveCompactionModelAlias(this.agent.blunConfig?.loopControl?.compactionModel, this.agent.activeResponderModel ?? this.agent.config.model);
75624
75627
  const runtimeModel = this.agent.config.runtimeModel(model);
75625
75628
  const capability = runtimeModel.modelCapabilities;
75626
75629
  const buildCompactionProvider = (usedContextTokens) => {
75627
- const currentMaxContextTokens = this.getEffectiveMaxContextTokens();
75630
+ const currentMaxContextTokens = this.getEffectiveMaxContextTokens(model);
75628
75631
  const defaultCompactionCap = capCompactionCompletionTokens(currentMaxContextTokens);
75629
75632
  const requestCapability = currentMaxContextTokens > 0 ? {
75630
75633
  ...capability,
@@ -75666,7 +75669,7 @@ var init_full = __esmMin((() => {
75666
75669
  }), createUserMessage(requestInstruction)], capability));
75667
75670
  };
75668
75671
  while (true) {
75669
- const compactionRequestLimit = this.getEffectiveMaxContextTokens();
75672
+ const compactionRequestLimit = this.getEffectiveMaxContextTokens(model);
75670
75673
  const safeCompactionRequestLimit = compactionRequestLimit > 0 ? Math.max(1, Math.floor(compactionRequestLimit * (1 - COMPACTION_SUMMARY_RESERVE_RATIO))) : compactionRequestLimit;
75671
75674
  const targetCompactionRequestLimit = capCompactionStageTarget(safeCompactionRequestLimit);
75672
75675
  let messages = buildRequestMessages(historyForModel, instruction);
@@ -75764,7 +75767,7 @@ var init_full = __esmMin((() => {
75764
75767
  };
75765
75768
  armStallTimer();
75766
75769
  try {
75767
- const response = await this.agent.generate(provider, COMPACTION_SYSTEM_PROMPT, compactionTools, messages, { onMessagePart: observeProgress }, { signal: attemptController.signal });
75770
+ const response = await this.agent.generateForModel(model)(provider, COMPACTION_SYSTEM_PROMPT, compactionTools, messages, { onMessagePart: observeProgress }, { signal: attemptController.signal });
75768
75771
  if (stalled && !signal.aborted && stallPolicy !== void 0) throw new CompactionStallError(stallPolicy.timeoutMs, stallPolicy.measuredIdleMs);
75769
75772
  maxObservedIdleMs = Math.max(maxObservedIdleMs, Date.now() - lastProgressAt);
75770
75773
  if (response.finishReason === "truncated") throw new CompactionTruncatedError();
@@ -75803,10 +75806,10 @@ var init_full = __esmMin((() => {
75803
75806
  if (stalled && !signal.aborted && stallPolicy !== void 0) throw new CompactionStallError(stallPolicy.timeoutMs, stallPolicy.measuredIdleMs);
75804
75807
  if (isModelFallbackStatus(error)) throw error;
75805
75808
  const isContextOverflow = this.shouldRecoverFromContextOverflow(error);
75806
- if (isContextOverflow) this.observeContextOverflow(error);
75809
+ if (isContextOverflow) this.observeContextOverflow(error, model);
75807
75810
  if (isContextOverflow && historyForModel.length > 1) {
75808
75811
  if (data.source === "auto") {
75809
- const learnedMaxContextTokens = this.getEffectiveMaxContextTokens();
75812
+ const learnedMaxContextTokens = this.getEffectiveMaxContextTokens(model);
75810
75813
  if (learnedMaxContextTokens > 0 && learnedMaxContextTokens < compactionRequestLimit) {
75811
75814
  retryCount = 0;
75812
75815
  continue;
@@ -263222,7 +263225,7 @@ function windowsPathToPosixPath(path) {
263222
263225
  function rewriteWindowsNullRedirect(command) {
263223
263226
  return command.replace(WINDOWS_NUL_REDIRECT, "$1/dev/null");
263224
263227
  }
263225
- var MS_PER_SECOND, DEFAULT_TIMEOUT_S, MAX_TIMEOUT_S, DEFAULT_BACKGROUND_TIMEOUT_S, MAX_BACKGROUND_TIMEOUT_S, USER_INTERRUPT_REASON, BashInputSchema, SHELL_TIMEOUT_VARS, BashTool, WINDOWS_NUL_REDIRECT, broadRecursiveSearchRefusal;
263228
+ var MS_PER_SECOND, DEFAULT_TIMEOUT_S, MAX_TIMEOUT_S, DEFAULT_BACKGROUND_TIMEOUT_S, MAX_BACKGROUND_TIMEOUT_S, USER_INTERRUPT_REASON, BashInputSchema, SHELL_TIMEOUT_VARS, BashTool, WINDOWS_NUL_REDIRECT, broadRecursiveSearchRefusal, windowsBashDialectRefusal;
263226
263229
  var init_bash = __esmMin((() => {
263227
263230
  init_zod$1();
263228
263231
  init_background();
@@ -263232,6 +263235,7 @@ var init_bash = __esmMin((() => {
263232
263235
  init_result_builder();
263233
263236
  init_bash$1();
263234
263237
  ({ broadRecursiveSearchRefusal } = createRequire(import.meta.url)("./bin/bash-search-scope-policy.cjs"));
263238
+ ({ windowsBashDialectRefusal } = createRequire(import.meta.url)("./bin/windows-bash-dialect-policy.cjs"));
263235
263239
  MS_PER_SECOND = 1e3;
263236
263240
  DEFAULT_TIMEOUT_S = 60;
263237
263241
  MAX_TIMEOUT_S = 300;
@@ -263284,7 +263288,8 @@ var init_bash = __esmMin((() => {
263284
263288
  this.backgroundManager = backgroundManager;
263285
263289
  this.isWindowsBash = this.kaos.osEnv.osKind === "Windows";
263286
263290
  this.allowBackground = options?.allowBackground ?? true;
263287
- const rendered = renderBashDescription(this.kaos.osEnv.shellName);
263291
+ const windowsDialectNote = this.isWindowsBash ? "\n\nOn Windows this tool still runs POSIX Bash, including inside VS Code. Do not use cmd.exe syntax such as `cd /d`, `dir /s /b`, `find /c /v`, or `2>nul`; pass the directory with `cwd`, use Bash paths and commands, and redirect to `/dev/null`." : "";
263292
+ const rendered = `${renderBashDescription(this.kaos.osEnv.shellName)}${windowsDialectNote}`;
263288
263293
  this.description = this.allowBackground ? rendered : withoutBackgroundDescription(rendered);
263289
263294
  }
263290
263295
  resolveExecution(args) {
@@ -263401,6 +263406,14 @@ var init_bash = __esmMin((() => {
263401
263406
  isError: true,
263402
263407
  output: "Command cannot be empty."
263403
263408
  };
263409
+ const dialectRefusal = windowsBashDialectRefusal({
263410
+ command: args.command,
263411
+ isWindowsBash: this.isWindowsBash
263412
+ });
263413
+ if (dialectRefusal !== void 0) return {
263414
+ isError: true,
263415
+ output: dialectRefusal
263416
+ };
263404
263417
  const searchRefusal = broadRecursiveSearchRefusal({
263405
263418
  command: args.command,
263406
263419
  cwd: args.cwd ?? this.cwd,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.428",
3
+ "version": "9.1.430",
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": {