@lmzhen/dsh-evolution-core 0.3.43 → 0.3.45

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.
Files changed (2) hide show
  1. package/lib/index.js +13 -4
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -2805,8 +2805,9 @@ function observeEvent(signal, event) {
2805
2805
  return;
2806
2806
  }
2807
2807
  if (event.type === "assistant/message") {
2808
- if (!Array.isArray(event.data.message.content)) return;
2809
- const text = event.data.message.content.map((block) => block.type === "text" ? block.text : "").join(" ");
2808
+ const message = event.data.message;
2809
+ if (!message || !Array.isArray(message.content)) return;
2810
+ const text = message.content.map((block) => block.type === "text" ? block.text ?? "" : "").join(" ");
2810
2811
  signal.assistantChars += text.length;
2811
2812
  return;
2812
2813
  }
@@ -3389,11 +3390,19 @@ function trimPatternBoundaries(pattern) {
3389
3390
  const trailing = trimmed.search(/\s+$/);
3390
3391
  return trailing < 0 ? trimmed : trimmed.slice(0, trailing);
3391
3392
  }
3392
- /** Replace only the fuzzy-matched span, preserving all surrounding bytes. */
3393
+ /** Replace only the fuzzy-matched span, preserving all surrounding bytes.
3394
+ * V7-11 (0.3.44): the replaceAll loop accumulates the per-scan cost — the
3395
+ * single-scan budget at the caller only bounded ONE fuzzyIndexOf, while an
3396
+ * unbounded number of matches × O(n·m) each could still stall the loop.
3397
+ * When the accumulated cost exceeds the budget the whole replace fails
3398
+ * (null) instead of partially applying an arbitrary prefix. */
3393
3399
  function fuzzyReplace(content, oldString, newString, replaceAll) {
3394
3400
  let current = content;
3395
3401
  let scanFrom = 0;
3402
+ let totalWork = 0;
3396
3403
  for (;;) {
3404
+ totalWork += current.length * oldString.length;
3405
+ if (totalWork > FUZZY_MAX_WORK) return null;
3397
3406
  const match = fuzzyIndexOf(current, oldString, scanFrom);
3398
3407
  if (match === null) return current;
3399
3408
  const [start, end] = match;
@@ -3933,7 +3942,7 @@ var SkillLibrary = class {
3933
3942
  if (patched === null) return {
3934
3943
  result: {
3935
3944
  ok: false,
3936
- message: `Could not find old_string in "${name}/${patchLabel}". Use update for a full rewrite.`
3945
+ message: `Could not find old_string in "${name}/${patchLabel}" (or the replaceAll fuzzy budget was exceeded). Use update for a full rewrite.`
3937
3946
  },
3938
3947
  write: null
3939
3948
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-core",
3
3
  "description": "Shared stores, prompts, signals and lifecycle logic for the dsh-evolution plugin family (community build)",
4
- "version": "0.3.43",
4
+ "version": "0.3.45",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },