@criogaid/pi-hashline-edit 0.9.0 → 0.11.0

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 (131) hide show
  1. package/README.md +12 -12
  2. package/README.zh-CN.md +12 -12
  3. package/THIRD_PARTY_NOTICES.md +0 -6
  4. package/package.json +1 -1
  5. package/src/core/AGENTS.md +4 -5
  6. package/src/core/apply.test.ts +96 -271
  7. package/src/core/apply.ts +62 -169
  8. package/src/core/case-fold.ts +8 -67
  9. package/src/core/character-set.test.ts +2 -3
  10. package/src/core/character-set.ts +5 -5
  11. package/src/core/errors.test.ts +23 -7
  12. package/src/core/errors.ts +32 -5
  13. package/src/core/hash.test.ts +8 -16
  14. package/src/core/hash.ts +3 -23
  15. package/src/core/lines.ts +2 -4
  16. package/src/core/ranges.test.ts +2 -1
  17. package/src/core/ranges.ts +1 -1
  18. package/src/core/regex.ts +3 -4
  19. package/src/core/replace.test.ts +47 -1
  20. package/src/core/replace.ts +19 -13
  21. package/src/core/search-analysis.test.ts +24 -27
  22. package/src/core/search-analysis.ts +34 -65
  23. package/src/core/search-matrix.testing.ts +0 -2
  24. package/src/core/search.ts +1 -1
  25. package/src/core/text.test.ts +5 -5
  26. package/src/core/text.ts +5 -12
  27. package/src/core/types.ts +8 -44
  28. package/src/index.ts +8 -8
  29. package/src/integration/config-registration.test.ts +8 -10
  30. package/src/integration/fusion-dispatch.test.ts +4 -7
  31. package/src/integration/grep-errors.test.ts +3 -3
  32. package/src/integration/grep-flags.test.ts +5 -19
  33. package/src/integration/grep-js-completeness.test.ts +45 -18
  34. package/src/integration/grep-line-candidates.test.ts +7 -10
  35. package/src/integration/grep-matrix.test.ts +6 -9
  36. package/src/integration/grep-order.test.ts +4 -4
  37. package/src/integration/grep-path-matrix.test.ts +10 -9
  38. package/src/integration/grep-prefilter-coverage.test.ts +5 -8
  39. package/src/integration/grep-process-limits.test.ts +76 -0
  40. package/src/integration/grep-regex.test.ts +10 -10
  41. package/src/integration/grep-rg.test.ts +166 -66
  42. package/src/integration/grep-scan-budget.test.ts +9 -9
  43. package/src/integration/grep-translation.test.ts +18 -32
  44. package/src/integration/large-text.test.ts +6 -52
  45. package/src/integration/model-budget-lifecycle.test.ts +10 -9
  46. package/src/integration/mutation-file-types.testing.ts +4 -4
  47. package/src/integration/npm-package.testing.ts +3 -3
  48. package/src/integration/publication-read-changes.test.ts +161 -83
  49. package/src/integration/read-changes.test.ts +4 -4
  50. package/src/integration/replace-worker-boundary.test.ts +22 -12
  51. package/src/integration/report-replay.test.ts +23 -26
  52. package/src/integration/utf8-errors.test.ts +4 -4
  53. package/src/pi/AGENTS.md +18 -17
  54. package/src/pi/action-fusion.test.ts +241 -353
  55. package/src/pi/action-fusion.testing.ts +38 -0
  56. package/src/pi/action-fusion.ts +150 -125
  57. package/src/pi/anchor-format.test.ts +9 -9
  58. package/src/pi/anchor-format.ts +6 -8
  59. package/src/pi/argument-diagnostics.ts +25 -28
  60. package/src/pi/argument-error.ts +2 -1
  61. package/src/pi/argument-format.test.ts +19 -18
  62. package/src/pi/argument-validation.test.ts +334 -283
  63. package/src/pi/argument-validation.ts +5 -8
  64. package/src/pi/budgets.ts +6 -8
  65. package/src/pi/codemode.test.ts +7 -2
  66. package/src/pi/config.test.ts +7 -3
  67. package/src/pi/config.ts +12 -9
  68. package/src/pi/diagnostic-buffer.test.ts +34 -13
  69. package/src/pi/diagnostic-buffer.ts +1 -2
  70. package/src/pi/directory-sync.test.ts +0 -1
  71. package/src/pi/edit-tool.ts +86 -211
  72. package/src/pi/error-text.ts +10 -9
  73. package/src/pi/execute.test.ts +249 -345
  74. package/src/pi/failure-context.test.ts +146 -127
  75. package/src/pi/failure-context.ts +45 -94
  76. package/src/pi/failure-path.test.ts +182 -155
  77. package/src/pi/file-commit.test.ts +156 -71
  78. package/src/pi/file-commit.ts +126 -146
  79. package/src/pi/file-snapshot.test.ts +3 -5
  80. package/src/pi/fusion-card.test.ts +26 -22
  81. package/src/pi/fusion-card.ts +16 -24
  82. package/src/pi/grep-candidates.test.ts +19 -120
  83. package/src/pi/grep-candidates.ts +25 -76
  84. package/src/pi/grep-matrix.test.ts +5 -5
  85. package/src/pi/grep-order.test.ts +16 -15
  86. package/src/pi/grep-output.ts +94 -107
  87. package/src/pi/grep-render.ts +1 -1
  88. package/src/pi/grep-reread.ts +97 -0
  89. package/src/pi/grep-rg.testing.ts +70 -0
  90. package/src/pi/grep-scope.ts +41 -43
  91. package/src/pi/grep-search.ts +27 -39
  92. package/src/pi/grep-tool.ts +63 -106
  93. package/src/pi/grep.test.ts +177 -156
  94. package/src/pi/model-budgets.test.ts +27 -24
  95. package/src/pi/model-budgets.ts +6 -38
  96. package/src/pi/mutation-outcome.testing.ts +0 -1
  97. package/src/pi/mutation-result.test.ts +44 -35
  98. package/src/pi/mutation-result.ts +52 -21
  99. package/src/pi/mutation-runner.ts +134 -74
  100. package/src/pi/output-budgets.test.ts +86 -42
  101. package/src/pi/path.ts +1 -1
  102. package/src/pi/pi.test.ts +18 -13
  103. package/src/pi/read-tool.ts +18 -23
  104. package/src/pi/read.test.ts +22 -41
  105. package/src/pi/regex-worker-contract.ts +3 -13
  106. package/src/pi/regex-worker.ts +1 -10
  107. package/src/pi/registration.test.ts +85 -51
  108. package/src/pi/render.test.ts +88 -59
  109. package/src/pi/render.ts +64 -65
  110. package/src/pi/replace-regex.ts +14 -2
  111. package/src/pi/replace-tool.ts +22 -94
  112. package/src/pi/replace-worker.ts +1 -1
  113. package/src/pi/replace.test.ts +53 -38
  114. package/src/pi/report-cause.ts +3 -8
  115. package/src/pi/report-failure.testing.ts +10 -3
  116. package/src/pi/report-schema.ts +251 -148
  117. package/src/pi/report.test.ts +215 -67
  118. package/src/pi/report.ts +50 -98
  119. package/src/pi/result-safety.test.ts +241 -247
  120. package/src/pi/rg-process.test.ts +77 -63
  121. package/src/pi/rg-process.ts +53 -75
  122. package/src/pi/rg-regex.ts +40 -400
  123. package/src/pi/schema.ts +35 -0
  124. package/src/pi/text-stream.test.ts +0 -21
  125. package/src/pi/text-stream.ts +14 -21
  126. package/src/pi/tool-factories.testing.ts +59 -0
  127. package/src/pi/write-tool.ts +36 -71
  128. package/src/pi/write.test.ts +31 -34
  129. package/src/testing/regex-translation-corpus.ts +12 -12
  130. package/src/testing/run-tests.ts +1 -1
  131. package/src/pi/replace-worker-contract.ts +0 -10
package/README.md CHANGED
@@ -40,7 +40,7 @@ The model copies an anchor into `edit`:
40
40
  ```json
41
41
  {
42
42
  "path": "greet.ts",
43
- "edits": [{ "action": "replace", "anchor": "2#GFYR", "body": [" return \"hello, hashline\";"] }]
43
+ "steps": [{ "action": "replace", "anchor": "2#GFYR", "lines": [" return \"hello, hashline\";"] }]
44
44
  }
45
45
  ```
46
46
 
@@ -53,8 +53,8 @@ The extension replaces Pi's `read`, `grep`, `edit`, and `write`, and adds `repla
53
53
  | Tool | What it does |
54
54
  | --- | --- |
55
55
  | `read` | Shows UTF-8 text with anchors, paginated within the model's output budget. Images and files containing NUL bytes go to Pi's built-in read. |
56
- | `grep` | Searches files and directories with JavaScript regex or literal text; returns anchored matches, file paths, or counts in traversal order; a limit keeps the first matches in that order. Respects ignore rules. |
57
- | `edit` | Replaces, inserts, deletes, copies, or moves whole lines by anchor. All operations in one call apply to the same snapshot, or none apply. |
56
+ | `grep` | Searches files and directories with JavaScript regex or literal text; returns anchored matches, file paths, or counts in traversal order; a limit keeps the first matches in that order. Directory searches respect ignore rules and skip `.git` and linked directories, even beneath a directory named in `path`; naming an ignored file or one of those directories itself searches it. |
57
+ | `edit` | Replaces, inserts, or deletes whole lines by anchor. All operations in one call apply to the same snapshot, or none apply. |
58
58
  | `replace` | Applies literal or regex substitutions across one file. Every rule must match, and overlapping matches reject the batch. |
59
59
  | `write` | Creates a file (`mode: "create"`) or overwrites one (`mode: "overwrite"`), using the content exactly as given. |
60
60
 
@@ -62,6 +62,7 @@ Grep visits input paths in the order supplied and uses ripgrep's sorted director
62
62
 
63
63
  Grep matches the LF view with native JavaScript regexes. Without `multiline`, each physical line is searched separately; with it, the whole file is searched and every physical line touched by a match is returned. Context rows do not count toward `limit`. Content output re-reads matched files and omits any whose revision changed; `files` and `count` report the searched snapshot without a second read. Incomplete scans state their diagnostics or scan limit in the report.
64
64
 
65
+ An `edit` call puts its small locator first: `path`, `steps`, then optional `then_run`. Each step puts the operation and range before the replacement payload: `action`, `anchor`, optional `end`, then `lines`. This keeps the file and target range visible while arguments stream.
65
66
  Edit operations:
66
67
 
67
68
  | `action` | Effect |
@@ -69,23 +70,22 @@ Edit operations:
69
70
  | `replace` / `delete` | Replace or remove a line, or an inclusive range with `end`. |
70
71
  | `insert_before` / `insert_after` | Insert lines next to an anchor. |
71
72
  | `prepend` / `append` | Insert lines at the start or end of the file. |
72
- | `copy` / `move` | Copy or move a line range to before or after another anchor. |
73
73
 
74
- One call takes at most [64 operations](src/pi/edit-tool.ts). Ranges in one call must not overlap, and each gap between lines takes at most one insertion, copy and move destinations included. An insertion at the start of a replaced or deleted range goes before it.
74
+ One call takes at most [64 operations](src/pi/edit-tool.ts). Ranges in one call must not overlap, and each gap between lines takes at most one insertion. An insertion at the start of a replaced or deleted range goes before it.
75
75
 
76
- `edit` asks for constrained sampling (Pi's `constrainedSampling`, a strict JSON schema) where the provider supports it, so the model cannot exceed the operation limit or emit fields the schema does not declare. Each operation is then written with every field, `null` for those its `action` does not take.
76
+ Every tool asks for constrained sampling (Pi's `constrainedSampling`, a strict JSON schema) where the provider supports it, so the model cannot emit fields or values the schema does not declare, or exceed edit's operation limit. Optional fields the call does not use are then written as `null`, including each edit operation's fields that its `action` does not take. For the same reason, grep's `pattern`, `path`, and `glob` take arrays only; on other providers Pi wraps a single string into an array.
77
77
 
78
78
  The model sees each tool's full parameter schema; the definitions live in the tool files under [`src/pi/`](src/pi/).
79
79
 
80
- Range operations verify the cited `anchor` and `end`, plus the destination for copy/move. Interior lines have no individual anchor check. Changes elsewhere before the call do not invalidate unchanged anchors; publication rechecks the bytes read while applying the call and rejects a detected change.
80
+ Range operations verify the cited `anchor` and `end`. Interior lines have no individual anchor check. Changes elsewhere before the call do not invalidate unchanged anchors; publication rechecks the bytes read while applying the call and rejects a detected change.
81
81
 
82
82
  ## When an edit is rejected
83
83
 
84
- Argument and anchor validation failures leave the file untouched. The report names the error, the fields involved, and a `next` instruction. For a stale anchor it also shows where the line most likely moved, with its new anchor and nearby lines, so the model can confirm and resubmit without re-reading the whole file. Recovery never edits on its own; every retry is verified again.
84
+ Argument and anchor validation failures leave the file untouched. The report names the error and the fields involved; argument issues carry a per-field `fix`, while anchor failures carry a `next` recovery instruction. For a stale anchor it also shows where the line most likely moved, with its new anchor and nearby lines, so the model can confirm and resubmit without re-reading the whole file. Recovery never edits on its own; every retry is verified again.
85
85
 
86
86
  A failure during or after publication states `NOT_PUBLISHED`, `PUBLISHED`, or `UNKNOWN`. Follow the report's `next` before retrying: an error after publication can leave the requested change on disk.
87
87
 
88
- Argument mistakes are reported per field, with what the field means and how to fix it, before any file is touched.
88
+ Argument mistakes, including a reversed range, are reported per field, with what the field means and how to fix it, before any file is touched.
89
89
 
90
90
  ## Action Fusion
91
91
 
@@ -114,7 +114,7 @@ Add `hashlineEdit` to Pi's global settings (`~/.pi/agent/settings.json`) or a pr
114
114
  "actionFusion": true,
115
115
  "hashLen": 4,
116
116
  "shiftRadius": 15,
117
- "read": { "defaultLimit": 500 },
117
+ "read": { "defaultLimit": 2000 },
118
118
  "grep": { "defaultLimit": 100, "defaultContext": 0, "regexTimeoutMs": 5000 },
119
119
  "replace": { "regexTimeoutMs": 5000 }
120
120
  }
@@ -127,7 +127,7 @@ Add `hashlineEdit` to Pi's global settings (`~/.pi/agent/settings.json`) or a pr
127
127
  | `actionFusion` | `true` | Allow `then_run` on mutation tools. |
128
128
  | `hashLen` | `4` | Anchor hash length, 2–8. |
129
129
  | `shiftRadius` | `15` | Lines searched around a stale anchor before the whole file, 0–100; `0` disables recovery search. |
130
- | `read.defaultLimit` | `500` | Lines returned when the call gives no limit. |
130
+ | `read.defaultLimit` | `2000` | Lines returned when the call gives no limit, matching Pi's built-in read. |
131
131
  | `read.maxKiB` | Model-based | Fixed cap on read output, 1–4096 KiB. |
132
132
  | `grep.defaultLimit` | `100` | Matching lines returned when the call gives no limit. |
133
133
  | `grep.defaultContext` | `0` | Context lines around each match, 0–20. |
@@ -141,7 +141,7 @@ The selected model's declared context capacity sets the output budgets; remainin
141
141
 
142
142
  When model capacity is unknown or invalid, the defaults are 256 KiB for read rows, 50 KiB for grep payloads, 16 KiB per diagnostic block, 4 KiB per free-text field, and 500 UTF-16 code units per grep preview. An explicit `read.maxKiB` overrides only the read cap. Each execution keeps the budget snapshot it started with.
143
143
 
144
- Read reports pagination when the extension cuts a window or its byte budget; a caller-supplied `limit` alone does not add a pagination report. A first row that cannot fit gets a `lineTooLong` fact. Grep reports payload and preview truncation separately, and plain previews for invalid UTF-8 never carry edit anchors.
144
+ Read reports `nextOffset` when its default line limit or byte budget cuts a window; a caller-supplied `limit` alone does not add a `nextOffset` report. A first row that cannot fit gets a `lineTooLong` byte-limit fact. Grep reports payload and preview truncation separately, and plain previews for invalid UTF-8 never carry edit anchors.
145
145
 
146
146
  ## Limits
147
147
 
package/README.zh-CN.md CHANGED
@@ -40,7 +40,7 @@ greet.ts · 3 lines
40
40
  ```json
41
41
  {
42
42
  "path": "greet.ts",
43
- "edits": [{ "action": "replace", "anchor": "2#GFYR", "body": [" return \"hello, hashline\";"] }]
43
+ "steps": [{ "action": "replace", "anchor": "2#GFYR", "lines": [" return \"hello, hashline\";"] }]
44
44
  }
45
45
  ```
46
46
 
@@ -53,8 +53,8 @@ greet.ts · 3 lines
53
53
  | 工具 | 作用 |
54
54
  | --- | --- |
55
55
  | `read` | 显示带锚点的 UTF-8 文本,按模型的输出预算分页。图片和含 NUL 字节的文件交给 Pi 内置的 read。 |
56
- | `grep` | 用 JavaScript 正则或字面文本搜索文件和目录,按遍历顺序返回带锚点的匹配行、文件路径或计数,设了 limit 时保留该顺序下的前若干条匹配;遵守忽略规则。 |
57
- | `edit` | 按锚点替换、插入、删除、复制或移动整行。一次调用中的所有操作基于同一份快照,要么全部生效,要么全部不生效。 |
56
+ | `grep` | 用 JavaScript 正则或字面文本搜索文件和目录,按遍历顺序返回带锚点的匹配行、文件路径或计数,设了 limit 时保留该顺序下的前若干条匹配。搜索目录时遵守忽略规则,并跳过 `.git` 和链接目录,在 `path` 指定的目录之下也是如此;在 `path` 中直接指定被忽略的文件或这些目录本身才会搜索。 |
57
+ | `edit` | 按锚点替换、插入或删除整行。一次调用中的所有操作基于同一份快照,要么全部生效,要么全部不生效。 |
58
58
  | `replace` | 在单个文件内批量执行字面或正则替换。每条规则都必须有匹配,匹配区域重叠时整批拒绝。 |
59
59
  | `write` | 新建文件(`mode: "create"`)或覆盖文件(`mode: "overwrite"`),内容原样写入。 |
60
60
 
@@ -62,6 +62,7 @@ Grep 按传入顺序访问各个搜索路径,在每个根路径内采用 ripgr
62
62
 
63
63
  Grep 用原生 JavaScript 正则匹配 LF 视图。不设 `multiline` 时逐物理行搜索;设为 true 时搜索整个文件,返回匹配涉及的每一物理行。上下文行不计入 `limit`。content 输出会重读匹配文件,略过版本已变的文件;`files` 和 `count` 直接报告搜索时的快照,不做第二次读取。扫描不完整时,报告会给出诊断或扫描上限。
64
64
 
65
+ `edit` 调用先给出定位信息:`path`、`steps`,再是可选的 `then_run`。每个操作先给出动作和范围,再给出替换内容:`action`、`anchor`、可选的 `end`,最后是 `lines`。参数流式输出时,TUI 可以先显示文件和目标范围。
65
66
  `edit` 的操作:
66
67
 
67
68
  | `action` | 效果 |
@@ -69,23 +70,22 @@ Grep 用原生 JavaScript 正则匹配 LF 视图。不设 `multiline` 时逐物
69
70
  | `replace` / `delete` | 替换或删除一行;配合 `end` 处理闭区间范围。 |
70
71
  | `insert_before` / `insert_after` | 在锚点前或后插入行。 |
71
72
  | `prepend` / `append` | 在文件开头或末尾插入行。 |
72
- | `copy` / `move` | 把一段行复制或移动到另一个锚点之前或之后。 |
73
73
 
74
- 一次调用最多 [64 个操作](src/pi/edit-tool.ts)。一次调用中的范围不能重叠,相邻两行之间的每个位置最多一次插入,复制或移动的目标位置也算在内。位于替换或删除区间起点的插入放在该区间之前。
74
+ 一次调用最多 [64 个操作](src/pi/edit-tool.ts)。一次调用中的范围不能重叠,相邻两行之间的每个位置最多一次插入。位于替换或删除区间起点的插入放在该区间之前。
75
75
 
76
- 在提供方支持时,`edit` 请求约束采样(Pi 的 `constrainedSampling`,即 strict JSON schema),模型因此无法超出操作数上限,也无法写出 schema 未声明的字段。这时每个操作都会写出全部字段,其 `action` 用不到的字段写 `null`。
76
+ 在提供方支持时,所有工具都请求约束采样(Pi 的 `constrainedSampling`,即 strict JSON schema),模型因此无法写出 schema 未声明的字段或取值,也无法超出 edit 的操作数上限。这时调用中没用到的可选字段都写 `null`,edit 每个操作里其 `action` 用不到的字段也一样。出于同一原因,grep 的 `pattern`、`path` 和 `glob` 只接受数组;在其他提供方上,Pi 会把单个字符串包成数组。
77
77
 
78
78
  模型能看到每个工具完整的参数 schema,定义位于 [`src/pi/`](src/pi/) 下的各工具文件。
79
79
 
80
- 范围操作核对给出的 `anchor`、`end`,以及复制或移动的目标锚点,不逐行验证区间内部的内容。调用前其他位置的变化不会使未改变的锚点失效;发布前会复核修改操作实际读取的字节,检测到变化时拒绝发布。
80
+ 范围操作核对给出的 `anchor`、`end`,不逐行验证区间内部的内容。调用前其他位置的变化不会使未改变的锚点失效;发布前会复核修改操作实际读取的字节,检测到变化时拒绝发布。
81
81
 
82
82
  ## 修改被拒绝时
83
83
 
84
- 参数和锚点校验失败时不会改动文件。报告会给出错误码、相关字段和一条 `next` 指引。锚点过期时,报告还会给出这一行最可能的新位置、新锚点和附近几行,模型确认后即可重新提交,不必重读整个文件。恢复过程从不自动修改,每次重试都会重新核对。
84
+ 参数和锚点校验失败时不会改动文件。报告会给出错误码和相关字段;参数问题按字段给出 `fix`,锚点失败给出一条 `next` 恢复指引。锚点过期时,报告还会给出这一行最可能的新位置、新锚点和附近几行,模型确认后即可重新提交,不必重读整个文件。恢复过程从不自动修改,每次重试都会重新核对。
85
85
 
86
86
  发布期间或发布后的失败会明确标记 `NOT_PUBLISHED`、`PUBLISHED` 或 `UNKNOWN`。重试前应遵循报告的 `next`:发布后的错误可能意味着所需修改已经写入磁盘。
87
87
 
88
- 参数错误按字段逐条报告,说明字段的含义和修正方法,此时还不会碰任何文件。
88
+ 参数错误(包括反向范围)按字段逐条报告,说明字段的含义和修正方法,此时还不会碰任何文件。
89
89
 
90
90
  ## Action Fusion
91
91
 
@@ -114,7 +114,7 @@ Grep 用原生 JavaScript 正则匹配 LF 视图。不设 `multiline` 时逐物
114
114
  "actionFusion": true,
115
115
  "hashLen": 4,
116
116
  "shiftRadius": 15,
117
- "read": { "defaultLimit": 500 },
117
+ "read": { "defaultLimit": 2000 },
118
118
  "grep": { "defaultLimit": 100, "defaultContext": 0, "regexTimeoutMs": 5000 },
119
119
  "replace": { "regexTimeoutMs": 5000 }
120
120
  }
@@ -127,7 +127,7 @@ Grep 用原生 JavaScript 正则匹配 LF 视图。不设 `multiline` 时逐物
127
127
  | `actionFusion` | `true` | 允许修改类工具使用 `then_run`。 |
128
128
  | `hashLen` | `4` | 锚点哈希长度,2–8。 |
129
129
  | `shiftRadius` | `15` | 锚点过期时先在附近多少行内查找,再查全文件,0–100;`0` 关闭恢复查找。 |
130
- | `read.defaultLimit` | `500` | 调用未指定时返回的行数。 |
130
+ | `read.defaultLimit` | `2000` | 调用未指定时返回的行数,与 Pi 内置 read 一致。 |
131
131
  | `read.maxKiB` | 按模型 | read 输出的固定上限,1–4096 KiB。 |
132
132
  | `grep.defaultLimit` | `100` | 调用未指定时返回的匹配行数。 |
133
133
  | `grep.defaultContext` | `0` | 每个匹配前后的上下文行数,0–20。 |
@@ -141,7 +141,7 @@ Grep 用原生 JavaScript 正则匹配 LF 视图。不设 `multiline` 时逐物
141
141
 
142
142
  模型容量未知或非法时,默认上限为 read 行 256 KiB、grep 载荷 50 KiB、每个诊断块 16 KiB、每个自由文本字段 4 KiB、每条 grep 预览 500 个 UTF-16 单元。显式设置 `read.maxKiB` 只覆盖 read 上限。每次执行使用开始时取得的预算快照。
143
143
 
144
- Read 因默认行数或字节预算截断窗口时会报告分页;只有调用方指定的 `limit` 生效时不额外报告分页。首行放不下时报告 `lineTooLong`。Grep 分别报告载荷和行预览的截断,非法 UTF-8 的普通预览不带编辑锚点。
144
+ Read 因默认行数或字节预算截断窗口时会报告 `nextOffset`;只有调用方指定的 `limit` 生效时不额外报告 `nextOffset`。首行放不下时报告 `lineTooLong`,其值为字节上限。Grep 分别报告载荷和行预览的截断,非法 UTF-8 的普通预览不带编辑锚点。
145
145
 
146
146
  ## 限制
147
147
 
@@ -6,8 +6,6 @@ The JS-to-ripgrep candidate translator adapts the following analysis techniques
6
6
  | --- | --- | --- |
7
7
  | [regexpu-core](https://github.com/mathiasbynens/regexpu-core) | Separate scalar sets from class strings; apply scoped flags before lowering a set | MIT |
8
8
  | [refa](https://github.com/RunDevelopment/refa/tree/8d20d94232b1adb043c29810046c060ca1664bf1) | Normalized character intervals and bounded finite languages | MIT |
9
- | [regexp-ast-analysis](https://github.com/RunDevelopment/regexp-ast-analysis/tree/6f0dbfc42ccc4a3fd22da6e3917f4e8cef07bee8) | Track exactness and fixed-width neighbouring characters across assertions | MIT |
10
- | [eslint-plugin-regexp](https://github.com/ota-meshi/eslint-plugin-regexp/tree/4700804dba99bed531e727f09c72a69a1dc939a4) | Character constraints for lookarounds and word boundaries | MIT |
11
9
  | [regex-syntax](https://github.com/rust-lang/regex/blob/master/regex-syntax/src/hir/literal.rs) | Budget literal expansion; retain necessary prefixes and suffixes without dropping alternatives | MIT OR Apache-2.0 |
12
10
  | [RE2](https://github.com/google/re2/blob/main/re2/prefilter.cc) | Necessary AND/OR literal conditions for file prefiltering | BSD-3-Clause |
13
11
  | [Vectorscan](https://github.com/VectorCamp/vectorscan/blob/develop/src/parser/prefilter.cpp) | Widen unsupported assertions and backreferences while retaining regular constraints | BSD-3-Clause |
@@ -20,10 +18,6 @@ regexpu-core: Copyright Mathias Bynens <https://mathiasbynens.be/>
20
18
 
21
19
  refa: Copyright (c) 2020 Michael Schmidt
22
20
 
23
- regexp-ast-analysis: Copyright (c) 2021 Michael Schmidt
24
-
25
- eslint-plugin-regexp: Copyright (c) 2020 Yosuke Ota
26
-
27
21
  Permission is hereby granted, free of charge, to any person obtaining a copy
28
22
  of this software and associated documentation files (the "Software"), to deal
29
23
  in the Software without restriction, including without limitation the rights
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@criogaid/pi-hashline-edit",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "description": "Hashline-style file editing for pi — line-anchored edits verified by content hash, replacing oldText/newText matching",
6
6
  "homepage": "https://github.com/Criogaid/pi-hashline-edit#readme",
@@ -4,17 +4,16 @@ Internal pure engine: no Pi imports and no public API. It trusts input already f
4
4
 
5
5
  ## Modules
6
6
 
7
- - `hash.ts` computes position-dependent line checksums (line number + content → `LINE#HASH`). `lines.ts` handles splitting, line-ending detection, and physical line counts. `text.ts` does strict UTF-8 decoding.
8
- - `apply.ts` `applyEdits` validates a whole batch of `Edit` ops (see `types.ts`) against a single snapshot: anchor checks, overlap and conflict detection, and shifted-anchor recovery (`AnchorRecovery`: local `shiftRadius` search, then full file). It returns new text or structured failures and never touches the filesystem.
7
+ - `hash.ts` computes position-dependent line checksums (line number + content → `LINE#HASH`). `lines.ts` handles splitting, line-ending detection, and physical line counts. `text.ts` does strict and lossy UTF-8 decoding and decides which text cannot be written.
8
+ - `apply.ts` `applyEdits` validates a whole batch of `Edit` ops (see `types.ts`) against a single snapshot: anchor checks, overlap and conflict detection, and shifted-anchor recovery (`AnchorRecovery`: local `shiftRadius` search, then full file). It returns new text or structured anchor failures, throws `OVERLAPPING_EDITS` for an overlap, and never touches the filesystem.
9
9
  - `regex.ts` builds JavaScript regexes on the LF view (`regexSource`, `buildRegex`) for both grep and replace; neither engine imports the other.
10
10
  - `replace.ts` is replace's engine: literal and JavaScript-regex matching on the LF view, separator restoration, and overlap rejection. `replace-schema.ts` defines the tool's replacement schema and the engine's result schema, with their derived types.
11
11
  - `search.ts` evaluates native JavaScript queries on the LF view and returns bounded physical rows; `search-schema.ts` defines its result.
12
12
  - `search-analysis.ts` parses patterns with regexpp (V8 has already accepted them at tool entry), decides smart case, and derives the literals every match must contain; `case-fold.ts` supplies JavaScript's case equivalence; `character-set.ts` owns character-class sets and shared AST surrogate-pair decoding for both candidate strategies.
13
13
  - `errors.ts` holds the classified `HashlineError`, typed by code so its facts and `next` alternative must match the code's schema, and errno classification.
14
- - `ranges.ts` provides overlap detection for both engines and range merging for grep and failure neighborhoods.
14
+ - `ranges.ts` provides overlap detection for both engines and range merging for failure neighborhoods.
15
15
 
16
16
  ## Constraints
17
17
 
18
- - Plan `copy/move` in `apply.ts` against original line ranges; capture text and separators without moving or duplicating the file-header BOM. Treat source reads separately from mutation conflicts, keep destinations in original coordinates, reject interior move destinations, and make adjacent moves no-ops. Reuse the shared commit and Fusion pipeline.
19
18
  - Own interval algebra, bounded membership caching, and explicit class-string enumeration in `character-set.ts`; derive Unicode properties, `v` sets, and case closure from the running V8 rather than separate Unicode tables. Intersections may enumerate either string operand, subtractions only the left, and unions require every operand. Keep original scoped case flags for membership even when translating a backreference; apply repetition case widening afterward through the existing byte translator. Unknown string properties remain widened.
20
- - Derive necessary file conditions in `search-analysis.ts` as bounded AND/OR literal clauses. Preserve every OR alternative, retain necessary prefixes or suffixes when expansion is too large, and cut literals where bytes can differ from the LF view. Unknown constructs widen candidates, never narrow them.
19
+ - Derive one necessary file condition in `search-analysis.ts`: an AND keeps its most selective side, because extra rg passes cost more than they save. Preserve every OR alternative, retain necessary prefixes or suffixes when expansion is too large, and cut literals where bytes can differ from the LF view. Unknown constructs widen candidates, never narrow them.