@trim21/personal-pi-extensions 0.1.571 → 0.1.572

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/README.md CHANGED
@@ -121,7 +121,7 @@ bwrap 已集成进 bash 工具实现(opencode 风格 `bash` 位于 `src/openco
121
121
 
122
122
  ## opencode-edit
123
123
 
124
- 替换内置 `edit` 工具,使用 [opencode](https://github.com/anomalyco/opencode) 的 schema 和模糊匹配引擎。核心 replacer 和 `replace()` 函数直接复制自 opencode,行为与原版完全一致。匹配引擎位于 `src/opencode/edit-engine.ts`,与写保护审批弹窗(`src/lib/write-guard.ts`)的 diff 预览共享。
124
+ 替换内置 `edit` 工具,使用 [opencode](https://github.com/anomalyco/opencode) 的 schema 和模糊匹配引擎。核心 replacer 和 `replace()` 函数复制自 opencode,匹配引擎位于 `src/opencode/edit-engine.ts`,与写保护审批弹窗(`src/lib/write-guard.ts`)的 diff 预览共享。唯一的有意差异是去掉了原版的转义规范化(EscapeNormalizedReplacer):它会把源码里合法的 `\n`、`\t` 等转义序列当成模型多转义的产物做启发式反转义,可能改坏内容。
125
125
 
126
126
  支持的匹配策略:
127
127
 
@@ -130,7 +130,6 @@ bwrap 已集成进 bash 工具实现(opencode 风格 `bash` 位于 `src/openco
130
130
  - 块首尾锚定(BlockAnchorReplacer)
131
131
  - 空白规范化(WhitespaceNormalizedReplacer)
132
132
  - 缩进灵活匹配(IndentationFlexibleReplacer)
133
- - 转义规范化(EscapeNormalizedReplacer)
134
133
  - 首尾空白修剪(TrimmedBoundaryReplacer)
135
134
  - 上下文感知匹配(ContextAwareReplacer)
136
135
  - 多次出现替换(MultiOccurrenceReplacer)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trim21/personal-pi-extensions",
3
- "version": "0.1.571",
3
+ "version": "0.1.572",
4
4
  "type": "module",
5
5
  "description": "Custom pi coding-agent extensions: bwrap sandbox, workspace guard, opencode edit, and more",
6
6
  "keywords": [
@@ -1,7 +1,9 @@
1
1
  /**
2
2
  * Opencode v1 edit matching engine.
3
3
  *
4
- * Replacers and replace() follow packages/opencode/src/tool/edit.ts.
4
+ * Replacers and replace() follow packages/opencode/src/tool/edit.ts, except
5
+ * EscapeNormalizedReplacer is intentionally omitted: unescaping \n, \t and
6
+ * friends heuristically rewrites escape sequences that are legitimate content.
5
7
  * applyEdit() matches the official preprocessing: convert oldString/newString
6
8
  * to the file's line endings, then replace on the original file content.
7
9
  *
@@ -317,59 +319,6 @@ const IndentationFlexibleReplacer: Replacer = function* (content, find) {
317
319
  }
318
320
  };
319
321
 
320
- function unescapeString(str: string): string {
321
- return str.replaceAll(/\\(n|t|r|'|"|`|\\|\n|\$)/g, (_match, capturedChar) => {
322
- switch (capturedChar) {
323
- case "n": {
324
- return "\n";
325
- }
326
- case "t": {
327
- return "\t";
328
- }
329
- case "r": {
330
- return "\r";
331
- }
332
- case "'": {
333
- return "'";
334
- }
335
- case '"': {
336
- return '"';
337
- }
338
- case "`": {
339
- return "`";
340
- }
341
- case "\\": {
342
- return "\\";
343
- }
344
- case "\n": {
345
- return "\n";
346
- }
347
- case "$": {
348
- return "$";
349
- }
350
- default: {
351
- return _match;
352
- }
353
- }
354
- });
355
- }
356
-
357
- const EscapeNormalizedReplacer: Replacer = function* (content, find) {
358
- const unescapedFind = unescapeString(find);
359
- if (content.includes(unescapedFind)) {
360
- yield unescapedFind;
361
- }
362
- const lines = content.split("\n");
363
- const findLines = unescapedFind.split("\n");
364
- for (let i = 0; i <= lines.length - findLines.length; i++) {
365
- const block = lines.slice(i, i + findLines.length).join("\n");
366
- const unescapedBlock = unescapeString(block);
367
- if (unescapedBlock === unescapedFind) {
368
- yield block;
369
- }
370
- }
371
- };
372
-
373
322
  const MultiOccurrenceReplacer: Replacer = function* (content, find) {
374
323
  let startIndex = 0;
375
324
  for (;;) {
@@ -477,7 +426,6 @@ export function replace(
477
426
  BlockAnchorReplacer,
478
427
  WhitespaceNormalizedReplacer,
479
428
  IndentationFlexibleReplacer,
480
- EscapeNormalizedReplacer,
481
429
  TrimmedBoundaryReplacer,
482
430
  ContextAwareReplacer,
483
431
  MultiOccurrenceReplacer,