@criogaid/pi-hashline-edit 0.6.1 → 0.8.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.
- package/README.md +78 -369
- package/README.zh-CN.md +162 -0
- package/THIRD_PARTY_NOTICES.md +80 -0
- package/package.json +11 -6
- package/src/core/AGENTS.md +20 -0
- package/src/core/apply.test.ts +328 -161
- package/src/core/apply.ts +129 -95
- package/src/core/case-fold.test.ts +44 -0
- package/src/core/case-fold.ts +77 -0
- package/src/core/character-set.test.ts +103 -0
- package/src/core/character-set.ts +184 -0
- package/src/core/errors.test.ts +23 -0
- package/src/core/errors.ts +70 -4
- package/src/core/hash.test.ts +1 -25
- package/src/core/hash.ts +0 -5
- package/src/core/lines.ts +32 -7
- package/src/core/ranges.test.ts +41 -9
- package/src/core/ranges.ts +11 -4
- package/src/core/regex.ts +51 -0
- package/src/core/replace-schema.ts +41 -0
- package/src/core/replace.test.ts +90 -0
- package/src/core/replace.ts +40 -56
- package/src/core/search-analysis.test.ts +208 -0
- package/src/core/search-analysis.ts +379 -0
- package/src/core/search-matrix.test.ts +64 -0
- package/src/core/search-matrix.testing.ts +183 -0
- package/src/core/search-schema.ts +18 -0
- package/src/core/search.test.ts +145 -0
- package/src/core/search.ts +119 -0
- package/src/core/text.test.ts +16 -8
- package/src/core/text.ts +26 -6
- package/src/core/types.ts +20 -17
- package/src/index.ts +24 -16
- package/src/integration/config-registration.test.ts +42 -28
- package/src/integration/fusion-dispatch.test.ts +62 -127
- package/src/integration/grep-errors.test.ts +50 -0
- package/src/integration/grep-flags.test.ts +273 -0
- package/src/integration/grep-js-completeness.test.ts +218 -0
- package/src/integration/grep-line-candidates.test.ts +233 -0
- package/src/integration/grep-matrix.test.ts +121 -0
- package/src/integration/grep-order.test.ts +78 -0
- package/src/integration/grep-path-matrix.test.ts +133 -0
- package/src/integration/grep-prefilter-coverage.test.ts +189 -0
- package/src/integration/grep-regex.test.ts +407 -0
- package/src/integration/grep-rg.test.ts +294 -436
- package/src/integration/grep-scan-budget.test.ts +111 -0
- package/src/integration/grep-translation.test.ts +206 -0
- package/src/integration/large-text.test.ts +56 -1
- package/src/integration/model-budget-lifecycle.test.ts +137 -0
- package/src/integration/mutation-file-types.test.ts +12 -26
- package/src/integration/mutation-file-types.testing.ts +33 -0
- package/src/integration/npm-package.test.ts +17 -0
- package/src/integration/npm-package.testing.ts +97 -0
- package/src/integration/publication-read-changes.test.ts +376 -0
- package/src/integration/read-changes.test.ts +98 -0
- package/src/integration/replace-package.test.ts +17 -36
- package/src/integration/replace-package.testing.ts +36 -0
- package/src/integration/replace-worker-boundary.test.ts +117 -0
- package/src/integration/report-replay.test.ts +90 -0
- package/src/integration/utf8-errors.test.ts +46 -0
- package/src/pi/AGENTS.md +54 -0
- package/src/pi/action-fusion.test.ts +256 -251
- package/src/pi/action-fusion.ts +121 -332
- package/src/pi/anchor-format.test.ts +16 -0
- package/src/pi/anchor-format.ts +16 -3
- package/src/pi/argument-diagnostics.ts +478 -0
- package/src/pi/argument-error.testing.ts +46 -0
- package/src/pi/argument-error.ts +76 -0
- package/src/pi/argument-format.test.ts +197 -0
- package/src/pi/argument-validation.test.ts +780 -49
- package/src/pi/argument-validation.ts +55 -58
- package/src/pi/budgets.ts +48 -21
- package/src/pi/codemode.test.ts +96 -0
- package/src/pi/config.test.ts +29 -15
- package/src/pi/config.ts +27 -13
- package/src/pi/diagnostic-buffer.test.ts +51 -16
- package/src/pi/diagnostic-buffer.ts +13 -16
- package/src/pi/directory-sync.test.ts +4 -1
- package/src/pi/edit-tool.ts +103 -99
- package/src/pi/error-text.ts +39 -16
- package/src/pi/execute.test.ts +407 -429
- package/src/pi/extension-loading.test.ts +7 -27
- package/src/pi/extension-loading.testing.ts +2 -14
- package/src/pi/failure-context.test.ts +265 -88
- package/src/pi/failure-context.ts +165 -181
- package/src/pi/failure-path.test.ts +179 -117
- package/src/pi/file-commit.test.ts +90 -73
- package/src/pi/file-commit.ts +216 -178
- package/src/pi/file-read.test.ts +29 -0
- package/src/pi/file-read.ts +60 -0
- package/src/pi/file-revision.ts +25 -0
- package/src/pi/file-snapshot.test.ts +1 -1
- package/src/pi/fusion-card-interaction.test.ts +143 -0
- package/src/pi/fusion-card.test.ts +233 -51
- package/src/pi/fusion-card.ts +246 -142
- package/src/pi/grep-candidates.test.ts +127 -0
- package/src/pi/grep-candidates.ts +191 -0
- package/src/pi/grep-matrix.test.ts +83 -0
- package/src/pi/grep-order.test.ts +323 -0
- package/src/pi/grep-output.testing.ts +24 -0
- package/src/pi/grep-output.ts +187 -151
- package/src/pi/grep-render.ts +31 -25
- package/src/pi/grep-scope.ts +62 -54
- package/src/pi/grep-search.ts +327 -241
- package/src/pi/grep-tool.ts +126 -147
- package/src/pi/grep-worker.mjs +4 -0
- package/src/pi/grep-worker.ts +14 -0
- package/src/pi/grep.test.ts +813 -713
- package/src/pi/model-budgets.test.ts +43 -0
- package/src/pi/model-budgets.ts +44 -0
- package/src/pi/mutation-outcome.testing.ts +6 -7
- package/src/pi/mutation-result.test.ts +45 -91
- package/src/pi/mutation-result.ts +86 -114
- package/src/pi/mutation-runner.ts +81 -81
- package/src/pi/output-budgets.test.ts +175 -0
- package/src/pi/path.ts +10 -1
- package/src/pi/pi.test.ts +4 -5
- package/src/pi/read-tool.ts +108 -142
- package/src/pi/read.test.ts +155 -96
- package/src/pi/regex-worker-contract.ts +55 -0
- package/src/pi/regex-worker.ts +95 -0
- package/src/pi/registration.test.ts +148 -124
- package/src/pi/render.test.ts +361 -84
- package/src/pi/render.ts +150 -32
- package/src/pi/replace-regex.ts +13 -48
- package/src/pi/replace-tool.ts +52 -158
- package/src/pi/replace-worker-contract.ts +10 -0
- package/src/pi/replace-worker.ts +12 -8
- package/src/pi/replace.test.ts +191 -340
- package/src/pi/report-cause.ts +103 -0
- package/src/pi/report-failure.testing.ts +20 -0
- package/src/pi/report-schema.ts +524 -0
- package/src/pi/report.test.ts +343 -0
- package/src/pi/report.ts +285 -0
- package/src/pi/result-safety.test.ts +216 -481
- package/src/pi/rg-process.test.ts +101 -76
- package/src/pi/rg-process.ts +130 -177
- package/src/pi/rg-regex.test.ts +67 -0
- package/src/pi/rg-regex.ts +715 -0
- package/src/pi/text-stream.test.ts +97 -69
- package/src/pi/text-stream.ts +97 -76
- package/src/pi/tool-call.testing.ts +20 -46
- package/src/pi/write-tool.ts +50 -41
- package/src/pi/write.test.ts +71 -95
- package/src/testing/extension-loader.testing.ts +24 -0
- package/src/testing/installation.testing.ts +77 -0
- package/src/testing/process.testing.ts +33 -0
- package/src/testing/regex-host.testing.ts +20 -0
- package/src/testing/regex-translation-corpus.ts +324 -0
- package/src/testing/rg-line-listing.fixture.mjs +7 -0
- package/src/testing/run-tests.ts +47 -0
- package/src/testing/session.testing.ts +127 -0
- package/src/integration/forget-grep.test.ts +0 -98
- package/src/pi/forget-tool.ts +0 -268
- package/src/pi/forget.test.ts +0 -343
- package/src/pi/forget.testing.ts +0 -273
- package/src/pi/rg-line-ranges.test.ts +0 -66
- package/src/pi/rg-line-ranges.ts +0 -75
- package/src/pi/rg-match-bytes.ts +0 -95
- package/src/pi/rg-text-view.ts +0 -192
- package/src/pi/tool-prompts.ts +0 -15
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# @criogaid/pi-hashline-edit
|
|
2
|
+
|
|
3
|
+
[](https://github.com/Criogaid/pi-hashline-edit/actions/workflows/ci.yml) [](https://www.npmjs.com/package/@criogaid/pi-hashline-edit) [](https://www.npmjs.com/package/@criogaid/pi-hashline-edit) [](https://www.npmjs.com/package/@criogaid/pi-hashline-edit)
|
|
4
|
+
|
|
5
|
+
[English](README.md) · 简体中文
|
|
6
|
+
|
|
7
|
+
为 [Pi](https://github.com/earendil-works/pi-coding-agent) 提供基于行哈希锚点的文件编辑。模型引用 `read` 或 `grep` 输出中的锚点来修改行,写入前每个锚点都会与当前文件核对。过期或错误的修改会被拒绝,并附带足够的信息让模型自行纠正,而不是悄悄改错行。
|
|
8
|
+
|
|
9
|
+
## 优势
|
|
10
|
+
|
|
11
|
+
- **改到模型想改的位置。** 每一行都带一个简短的 `行号#哈希` 锚点。模型看过之后文件如果变了,修改会被拒绝,报告会指出这一行移到了哪里。
|
|
12
|
+
- **不靠文本匹配。** 模型不需要原样复述旧文本,空白差异、重复片段和大段代码不再导致修改失败或改错地方。
|
|
13
|
+
- **文件字节不走样。** 保留 BOM、CRLF/LF 换行、文件末尾换行和所有未改动的字节;非法 UTF-8 和 NUL 字节在写入前就被拒绝。
|
|
14
|
+
- **安全写入。** 先写临时文件,再通过 link 或 rename 原子发布;读改写调用绑定实际读取的字节,出错时明确告知文件是否已经发布。
|
|
15
|
+
- **减少来回。** 修改可以顺带一条后续命令,例如 `npm test`([Action Fusion](#action-fusion))。
|
|
16
|
+
- **统一使用 JavaScript 正则。** `grep` 和 `replace` 都采用模型熟悉的 JavaScript 正则语义,同时借助 ripgrep 快速筛选候选文件。
|
|
17
|
+
- **输出按模型调整。** 结果大小随所选模型的上下文窗口缩放:小模型不会被撑爆,大模型也不会信息不足。
|
|
18
|
+
|
|
19
|
+
## 安装
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pi install npm:@criogaid/pi-hashline-edit
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
需要 Pi 0.99.1 或更高版本。扩展只处理本地文件;如果使用远程或自定义存储,把 `hashlineEdit.enabled` 设为 `false` 并重新加载 Pi,即可恢复内置工具。
|
|
26
|
+
|
|
27
|
+
## 快速上手
|
|
28
|
+
|
|
29
|
+
Pi 的模型会自动使用这些工具。`read` 返回带锚点的行:
|
|
30
|
+
|
|
31
|
+
```text
|
|
32
|
+
greet.ts · 3 lines
|
|
33
|
+
1#ZR63│export function greet() {
|
|
34
|
+
2#GFYR│ return "hello";
|
|
35
|
+
3#FNSZ│}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
模型把锚点复制到 `edit` 中:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"path": "greet.ts",
|
|
43
|
+
"edits": [{ "op": "replace", "anchor": "2#GFYR", "body": [" return \"hello, hashline\";"] }]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
只有第 2 行内容仍然一致时修改才会成功。TUI 显示 diff,模型收到一份简短的 JSON 报告。
|
|
48
|
+
|
|
49
|
+
## 工具
|
|
50
|
+
|
|
51
|
+
扩展替换 Pi 的 `read`、`grep`、`edit`、`write`,并新增 `replace`。
|
|
52
|
+
|
|
53
|
+
| 工具 | 作用 |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `read` | 显示带锚点的 UTF-8 文本,按模型的输出预算分页。图片和含 NUL 字节的文件交给 Pi 内置的 read。 |
|
|
56
|
+
| `grep` | 用 JavaScript 正则或字面文本搜索文件和目录,按遍历顺序返回带锚点的匹配行、文件路径或计数,设了 limit 时保留该顺序下的前若干条匹配;遵守忽略规则。 |
|
|
57
|
+
| `edit` | 按锚点替换、插入、删除、复制或移动整行。一次调用中的所有操作基于同一份快照,要么全部生效,要么全部不生效。 |
|
|
58
|
+
| `replace` | 在单个文件内批量执行字面或正则替换。每条规则都必须有匹配,匹配区域重叠时整批拒绝。 |
|
|
59
|
+
| `write` | 新建文件(`mode: "create"`)或覆盖文件(`mode: "overwrite"`),内容原样写入。 |
|
|
60
|
+
|
|
61
|
+
Grep 按传入顺序访问各个搜索路径,在每个根路径内采用 ripgrep 的有序目录遍历。重复候选路径只在第一次出现时搜索。这不是对所有文件完整路径做全局字典序排序。
|
|
62
|
+
|
|
63
|
+
Grep 用原生 JavaScript 正则匹配 LF 视图。不设 `multiline` 时逐物理行搜索;设为 true 时搜索整个文件,返回匹配涉及的每一物理行。上下文行不计入 `limit`。content 输出会重读匹配文件,略过版本已变的文件;`files` 和 `count` 直接报告搜索时的快照,不做第二次读取。扫描不完整时,报告会给出诊断或扫描上限。
|
|
64
|
+
|
|
65
|
+
`edit` 的操作:
|
|
66
|
+
|
|
67
|
+
| `op` | 效果 |
|
|
68
|
+
| --- | --- |
|
|
69
|
+
| `replace` / `delete` | 替换或删除一行;配合 `end` 处理闭区间范围。 |
|
|
70
|
+
| `insert_before` / `insert_after` | 在锚点前或后插入行。 |
|
|
71
|
+
| `prepend` / `append` | 在文件开头或末尾插入行。 |
|
|
72
|
+
| `copy` / `move` | 把一段行复制或移动到另一个锚点之前或之后。 |
|
|
73
|
+
|
|
74
|
+
模型能看到每个工具完整的参数 schema,定义位于 [`src/pi/`](src/pi/) 下的各工具文件。
|
|
75
|
+
|
|
76
|
+
范围操作核对给出的 `anchor`、`end`,以及复制或移动的目标锚点,不逐行验证区间内部的内容。调用前其他位置的变化不会使未改变的锚点失效;发布前会复核修改操作实际读取的字节,检测到变化时拒绝发布。
|
|
77
|
+
|
|
78
|
+
## 修改被拒绝时
|
|
79
|
+
|
|
80
|
+
参数和锚点校验失败时不会改动文件。报告会给出错误码、相关字段和一条 `next` 指引。锚点过期时,报告还会给出这一行最可能的新位置、新锚点和附近几行,模型确认后即可重新提交,不必重读整个文件。恢复过程从不自动修改,每次重试都会重新核对。
|
|
81
|
+
|
|
82
|
+
发布期间或发布后的失败会明确标记 `NOT_PUBLISHED`、`PUBLISHED` 或 `UNKNOWN`。重试前应遵循报告的 `next`:发布后的错误可能意味着所需修改已经写入磁盘。
|
|
83
|
+
|
|
84
|
+
参数错误按字段逐条报告,说明字段的含义和修正方法,此时还不会碰任何文件。
|
|
85
|
+
|
|
86
|
+
## Action Fusion
|
|
87
|
+
|
|
88
|
+
`edit`、`replace`、`write` 可以带一个可选的 `then_run` 命令,在修改成功后立即运行:
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"path": "src/foo.ts",
|
|
93
|
+
"replacements": [{ "find": "oldName", "literal": true, "replace": "newName" }],
|
|
94
|
+
"then_run": { "command": "npm test", "timeout": 60 }
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
命令通过会话自己的 Bash 工具执行,审批、覆盖和钩子照常生效。只有修改成功且文件仍是刚写入的内容时才会启动。命令失败不会回滚文件。TUI 把修改和命令分成两张卡片显示,设置了超时时会显示实时倒计时。
|
|
99
|
+
|
|
100
|
+
命令卡片使用 Pi 原生工具组件处理鼠标点击和全局展开快捷键,输出更新或屏幕重绘时保留各自的展开状态。内置 Bash 渲染器直接显示命令的原始内容和 details,并将它们保存到会话中以供恢复;当前支持的 Pi API 无法取得其他扩展自定义的 Bash 渲染器。
|
|
101
|
+
|
|
102
|
+
## 配置
|
|
103
|
+
|
|
104
|
+
在 Pi 的全局设置(`~/.pi/agent/settings.json`)或项目的 `.pi/settings.json` 中添加 `hashlineEdit`:
|
|
105
|
+
|
|
106
|
+
```json
|
|
107
|
+
{
|
|
108
|
+
"hashlineEdit": {
|
|
109
|
+
"enabled": true,
|
|
110
|
+
"actionFusion": true,
|
|
111
|
+
"hashLen": 4,
|
|
112
|
+
"shiftRadius": 15,
|
|
113
|
+
"read": { "defaultLimit": 500 },
|
|
114
|
+
"grep": { "defaultLimit": 100, "defaultContext": 0, "regexTimeoutMs": 5000 },
|
|
115
|
+
"replace": { "regexTimeoutMs": 5000 }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
| 设置项 | 默认值 | 含义 |
|
|
121
|
+
| --- | --- | --- |
|
|
122
|
+
| `enabled` | `true` | 注册扩展的工具。 |
|
|
123
|
+
| `actionFusion` | `true` | 允许修改类工具使用 `then_run`。 |
|
|
124
|
+
| `hashLen` | `4` | 锚点哈希长度,2–8。 |
|
|
125
|
+
| `shiftRadius` | `15` | 锚点过期时先在附近多少行内查找,再查全文件,0–100;`0` 关闭恢复查找。 |
|
|
126
|
+
| `read.defaultLimit` | `500` | 调用未指定时返回的行数。 |
|
|
127
|
+
| `read.maxKiB` | 按模型 | read 输出的固定上限,1–4096 KiB。 |
|
|
128
|
+
| `grep.defaultLimit` | `100` | 调用未指定时返回的匹配行数。 |
|
|
129
|
+
| `grep.defaultContext` | `0` | 每个匹配前后的上下文行数,0–20。 |
|
|
130
|
+
| `grep.regexTimeoutMs` / `replace.regexTimeoutMs` | `5000` | 单次正则计算的时限,3000–300000 毫秒。 |
|
|
131
|
+
|
|
132
|
+
项目中的 `hashlineEdit` 会整体替换全局配置;非法值回退为默认值。修改设置后需重新加载 Pi。以 [配置 schema](src/pi/config.ts) 为准。
|
|
133
|
+
|
|
134
|
+
## 输出预算
|
|
135
|
+
|
|
136
|
+
输出预算根据所选模型声明的上下文容量计算,不使用剩余上下文。容量已知时,带锚点的 read 行和 grep 载荷各获得每上下文 token 一字节的预算,最高 4 MiB。诊断块获得其四分之一,至少 512 字节;自由文本字段获得诊断块预算的四分之一,至少 128 字节。Grep 预览每四字节字段预算保留一个 UTF-16 单元。定义和回退值位于 [`budgets.ts`](src/pi/budgets.ts)。
|
|
137
|
+
|
|
138
|
+
模型容量未知或非法时,默认上限为 read 行 256 KiB、grep 载荷 50 KiB、每个诊断块 16 KiB、每个自由文本字段 4 KiB、每条 grep 预览 500 个 UTF-16 单元。显式设置 `read.maxKiB` 只覆盖 read 上限。每次执行使用开始时取得的预算快照。
|
|
139
|
+
|
|
140
|
+
Read 因默认行数或字节预算截断窗口时会报告分页;只有调用方指定的 `limit` 生效时不额外报告分页。首行放不下时报告 `lineTooLong`。Grep 分别报告载荷和行预览的截断,非法 UTF-8 的普通预览不带编辑锚点。
|
|
141
|
+
|
|
142
|
+
## 限制
|
|
143
|
+
|
|
144
|
+
- 锚点是简短的校验和:能发现内容变化和行位移,但可能碰撞,也不能证明模型真的读过这一行。
|
|
145
|
+
- 只编辑 UTF-8 文本,不支持 UTF-16 和旧式代码页。
|
|
146
|
+
- 版本检查能发现大多数并发修改,但没有跨进程锁,也没有多文件事务。
|
|
147
|
+
- 覆盖写入时保留符号链接、改写其指向的文件;FIFO 等非普通文件和有多个硬链接的文件不会被覆盖。
|
|
148
|
+
- Grep 的[搜索限制](src/pi/grep-search.ts)允许 multiline 文件最多 64 MiB、单条物理行最多 64 × 1024² 个 UTF-16 单元。最多使用四个匹配 worker,每个 worker 的 V8 老生代堆上限为 512 MiB;单次正则计算受配置中的超时约束。
|
|
149
|
+
- 候选发现回退到作用域内所有文件时,累计排入队列的文件大小达到 [256 MiB 扫描预算](src/pi/grep-candidates.ts) 后停止继续加入文件;最后一个文件可以使总量超过该阈值。报告会指出预算是否阻止了后续文件的扫描。Ripgrep 协议记录的[上限为 16 MiB](src/pi/rg-process.ts)。候选分析不支持或超限时会扩大候选范围,最终匹配仍由 JavaScript 决定。
|
|
150
|
+
|
|
151
|
+
## 开发
|
|
152
|
+
|
|
153
|
+
| 命令 | 检查内容 |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| `npm run format:check` | 格式。 |
|
|
156
|
+
| `npm run typecheck` | 源码、测试和基准测试的类型。 |
|
|
157
|
+
| `npm test` | 核心与工具测试。 |
|
|
158
|
+
| `npm run test:integration` | 真实 ripgrep、大文件、已安装包和真实 Pi 会话。 |
|
|
159
|
+
| `npm run test:all` | 两套测试,与 CI 一致。 |
|
|
160
|
+
| `npm run test:cartesian` | 耗时较长的笛卡尔积正则矩阵;修改正则翻译或预筛后运行。 |
|
|
161
|
+
|
|
162
|
+
报告字段和错误码定义在 [`report-schema.ts`](src/pi/report-schema.ts)。模块职责见 [`src/core/AGENTS.md`](src/core/AGENTS.md) 与 [`src/pi/AGENTS.md`](src/pi/AGENTS.md)。[`THIRD_PARTY_NOTICES.md`](THIRD_PARTY_NOTICES.md) 列出了借鉴的技术和测试用例。
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Regex translation sources and notices
|
|
2
|
+
|
|
3
|
+
The JS-to-ripgrep candidate translator adapts the following analysis techniques to this project's byte-preserving reads and JavaScript final verification. These projects are references, not runtime dependencies. Unicode membership comes from the running JavaScript engine rather than copied Unicode tables.
|
|
4
|
+
|
|
5
|
+
| Project | Technique used here | Source license |
|
|
6
|
+
| --- | --- | --- |
|
|
7
|
+
| [regexpu-core](https://github.com/mathiasbynens/regexpu-core) | Separate scalar sets from class strings; apply scoped flags before lowering a set | MIT |
|
|
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
|
+
| [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
|
+
| [RE2](https://github.com/google/re2/blob/main/re2/prefilter.cc) | Necessary AND/OR literal conditions for file prefiltering | BSD-3-Clause |
|
|
13
|
+
| [Vectorscan](https://github.com/VectorCamp/vectorscan/blob/develop/src/parser/prefilter.cpp) | Widen unsupported assertions and backreferences while retaining regular constraints | BSD-3-Clause |
|
|
14
|
+
|
|
15
|
+
Production implementations live in `src/core/character-set.ts`, `src/core/search-analysis.ts`, `src/core/case-fold.ts`, `src/pi/rg-regex.ts`, and `src/pi/rg-process.ts`. In particular, this project does not copy an automaton engine, a Unicode version table, or upstream match semantics into its final verifier.
|
|
16
|
+
|
|
17
|
+
## MIT reference projects
|
|
18
|
+
|
|
19
|
+
regexpu-core: Copyright Mathias Bynens <https://mathiasbynens.be/>
|
|
20
|
+
|
|
21
|
+
refa: Copyright (c) 2020 Michael Schmidt
|
|
22
|
+
|
|
23
|
+
regexp-ast-analysis: Copyright (c) 2021 Michael Schmidt
|
|
24
|
+
|
|
25
|
+
eslint-plugin-regexp: Copyright (c) 2020 Yosuke Ota
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
29
|
+
in the Software without restriction, including without limitation the rights
|
|
30
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
31
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
32
|
+
furnished to do so, subject to the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be included in all
|
|
35
|
+
copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
38
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
39
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
40
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
41
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
42
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
|
+
SOFTWARE.
|
|
44
|
+
|
|
45
|
+
## Test262 regression witnesses
|
|
46
|
+
|
|
47
|
+
`src/testing/regex-translation-corpus.ts` adapts selected patterns and witnesses from [Test262](https://github.com/tc39/test262). Each fixture identifies its upstream test file. The local assertions check candidate-line inclusion and final JS results rather than reproducing the Test262 harness.
|
|
48
|
+
|
|
49
|
+
Copyright 2022 Igalia S.L. All rights reserved.
|
|
50
|
+
|
|
51
|
+
Copyright (C) 2017 the V8 project authors. All rights reserved.
|
|
52
|
+
|
|
53
|
+
Copyright 2025 Mathias Bynens. All rights reserved.
|
|
54
|
+
|
|
55
|
+
Test262: ECMAScript Test Suite ("Software") is protected by copyright and is being
|
|
56
|
+
made available under the "BSD License", included below. This Software may be subject to third party rights (rights
|
|
57
|
+
from parties other than Ecma International), including patent rights, and no licenses under such third party rights
|
|
58
|
+
are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA
|
|
59
|
+
CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://www.ecma-international.org/ipr FOR
|
|
60
|
+
INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS*.
|
|
61
|
+
|
|
62
|
+
Copyright (C) 2012 Ecma International
|
|
63
|
+
All rights reserved.
|
|
64
|
+
|
|
65
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
|
66
|
+
following conditions are met:
|
|
67
|
+
|
|
68
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
69
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
70
|
+
3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
71
|
+
|
|
72
|
+
THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
73
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
74
|
+
SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
75
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
76
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
77
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
78
|
+
DAMAGE.
|
|
79
|
+
|
|
80
|
+
* Ecma International Standards hereafter means Ecma International Standards as well as Ecma Technical Reports
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@criogaid/pi-hashline-edit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.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",
|
|
@@ -15,23 +15,28 @@
|
|
|
15
15
|
"files": [
|
|
16
16
|
"src",
|
|
17
17
|
"README.md",
|
|
18
|
-
"
|
|
18
|
+
"README.zh-CN.md",
|
|
19
|
+
"LICENSE",
|
|
20
|
+
"THIRD_PARTY_NOTICES.md"
|
|
19
21
|
],
|
|
20
22
|
"scripts": {
|
|
21
23
|
"format": "biome format --write src/ bench/",
|
|
22
24
|
"format:check": "biome format src/ bench/",
|
|
23
25
|
"typecheck": "tsc --noEmit",
|
|
24
|
-
"test": "node
|
|
25
|
-
"test:integration": "node
|
|
26
|
+
"test": "node src/testing/run-tests.ts unit",
|
|
27
|
+
"test:integration": "node src/testing/run-tests.ts integration",
|
|
26
28
|
"test:all": "npm test && npm run test:integration",
|
|
29
|
+
"test:cartesian": "node src/testing/run-tests.ts cartesian",
|
|
27
30
|
"bench": "node bench/throughput.bench.ts"
|
|
28
31
|
},
|
|
29
32
|
"dependencies": {
|
|
33
|
+
"@eslint-community/regexpp": "4.12.2",
|
|
30
34
|
"@vscode/ripgrep": "1.18.0",
|
|
31
35
|
"jiti": "2.7.0"
|
|
32
36
|
},
|
|
33
37
|
"peerDependencies": {
|
|
34
|
-
"@earendil-works/pi-coding-agent": ">=0.99.1"
|
|
38
|
+
"@earendil-works/pi-coding-agent": ">=0.99.1",
|
|
39
|
+
"typebox": "*"
|
|
35
40
|
},
|
|
36
41
|
"devDependencies": {
|
|
37
42
|
"@biomejs/biome": "2.5.14",
|
|
@@ -39,7 +44,7 @@
|
|
|
39
44
|
"@earendil-works/pi-ai": "0.99.1",
|
|
40
45
|
"@earendil-works/pi-coding-agent": "0.99.1",
|
|
41
46
|
"@earendil-works/pi-tui": "0.99.1",
|
|
42
|
-
"typebox": "
|
|
47
|
+
"typebox": "1.3.27",
|
|
43
48
|
"typescript": "^7.0.2"
|
|
44
49
|
},
|
|
45
50
|
"pi": {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# src/core
|
|
2
|
+
|
|
3
|
+
Internal pure engine: no Pi imports and no public API. It trusts input already filtered by the tool layer and does not re-validate it. Core's report references are type-only and erased at runtime.
|
|
4
|
+
|
|
5
|
+
## Modules
|
|
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.
|
|
9
|
+
- `regex.ts` builds JavaScript regexes on the LF view (`regexSource`, `buildRegex`) for both grep and replace; neither engine imports the other.
|
|
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
|
+
- `search.ts` evaluates native JavaScript queries on the LF view and returns bounded physical rows; `search-schema.ts` defines its result.
|
|
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
|
+
- `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.
|
|
15
|
+
|
|
16
|
+
## Constraints
|
|
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
|
+
- 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.
|