@lmzhen/dsh-evolution-core 0.1.0-rc.40 → 0.1.0-rc.41

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 +16 -8
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1662,7 +1662,7 @@ function validateSupportPath(filePath) {
1662
1662
  * so a patch can replace exactly the matched span and keep every other byte
1663
1663
  * intact. Returns null when no fuzzy match exists.
1664
1664
  */
1665
- function fuzzyIndexOf(content, pattern) {
1665
+ function fuzzyIndexOf(content, pattern, from = 0) {
1666
1666
  const isSpace = (char) => char !== void 0 && /[ \t]/.test(char);
1667
1667
  const escaped = (char) => {
1668
1668
  if (char === "n") return "\n";
@@ -1670,7 +1670,7 @@ function fuzzyIndexOf(content, pattern) {
1670
1670
  if (char === "r") return "\r";
1671
1671
  return null;
1672
1672
  };
1673
- for (let start = 0; start < content.length; start += 1) {
1673
+ for (let start = from; start < content.length; start += 1) {
1674
1674
  let contentIndex = start;
1675
1675
  let patternIndex = 0;
1676
1676
  while (patternIndex < pattern.length && contentIndex < content.length) {
@@ -1707,15 +1707,23 @@ function trimPatternBoundaries(pattern) {
1707
1707
  }
1708
1708
  /** Replace only the fuzzy-matched span, preserving all surrounding bytes. */
1709
1709
  function fuzzyReplace(content, oldString, newString, replaceAll) {
1710
- const match = fuzzyIndexOf(content, oldString);
1711
- if (match === null) return content;
1712
- const [start, end] = match;
1713
- const patched = content.slice(0, start) + newString + content.slice(end);
1714
- return replaceAll ? fuzzyReplace(patched, oldString, newString, true) : patched;
1710
+ let current = content;
1711
+ let scanFrom = 0;
1712
+ for (;;) {
1713
+ const match = fuzzyIndexOf(current, oldString, scanFrom);
1714
+ if (match === null) return current;
1715
+ const [start, end] = match;
1716
+ const next = current.slice(0, start) + newString + current.slice(end);
1717
+ if (!replaceAll) return next;
1718
+ current = next;
1719
+ scanFrom = start + newString.length;
1720
+ }
1715
1721
  }
1716
1722
  function fuzzyPatch(content, oldString, newString, replaceAll = false) {
1723
+ if (oldString === "") return null;
1717
1724
  if (content.includes(oldString)) return replaceAll ? content.split(oldString).join(newString) : content.replace(oldString, newString);
1718
1725
  const boundary = trimPatternBoundaries(oldString);
1726
+ if (boundary === "") return null;
1719
1727
  if (boundary !== oldString) {
1720
1728
  if (fuzzyIndexOf(content, boundary) !== null) {
1721
1729
  const patched = fuzzyReplace(content, boundary, newString, replaceAll);
@@ -1976,7 +1984,7 @@ var SkillLibrary = class {
1976
1984
  message: `File not found: ${patchLabel}`
1977
1985
  };
1978
1986
  const patched = fuzzyPatch(md, oldString, newString, replaceAll);
1979
- if (!patched) return {
1987
+ if (patched === null) return {
1980
1988
  ok: false,
1981
1989
  message: `Could not find old_string in "${name}/${patchLabel}". Use update for a full rewrite.`
1982
1990
  };
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.1.0-rc.40",
4
+ "version": "0.1.0-rc.41",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },