@criogaid/pi-hashline-edit 0.10.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.
- package/README.md +4 -3
- package/README.zh-CN.md +4 -3
- package/package.json +1 -1
- package/src/core/apply.test.ts +2 -2
- package/src/core/apply.ts +2 -2
- package/src/core/character-set.test.ts +2 -3
- package/src/core/character-set.ts +1 -1
- package/src/core/ranges.test.ts +2 -1
- package/src/core/ranges.ts +1 -1
- package/src/core/types.ts +1 -1
- package/src/index.ts +8 -8
- package/src/integration/config-registration.test.ts +8 -10
- package/src/integration/fusion-dispatch.test.ts +2 -2
- package/src/integration/grep-errors.test.ts +3 -3
- package/src/integration/grep-flags.test.ts +5 -5
- package/src/integration/grep-js-completeness.test.ts +12 -11
- package/src/integration/grep-line-candidates.test.ts +3 -2
- package/src/integration/grep-matrix.test.ts +5 -4
- package/src/integration/grep-order.test.ts +4 -4
- package/src/integration/grep-path-matrix.test.ts +5 -4
- package/src/integration/grep-prefilter-coverage.test.ts +4 -3
- package/src/integration/grep-process-limits.test.ts +2 -4
- package/src/integration/grep-regex.test.ts +10 -10
- package/src/integration/grep-rg.test.ts +50 -48
- package/src/integration/grep-scan-budget.test.ts +8 -8
- package/src/integration/grep-translation.test.ts +8 -7
- package/src/integration/large-text.test.ts +5 -5
- package/src/integration/model-budget-lifecycle.test.ts +9 -9
- package/src/integration/mutation-file-types.testing.ts +4 -4
- package/src/integration/npm-package.testing.ts +3 -3
- package/src/integration/publication-read-changes.test.ts +54 -54
- package/src/integration/read-changes.test.ts +4 -4
- package/src/integration/replace-worker-boundary.test.ts +1 -1
- package/src/integration/report-replay.test.ts +5 -6
- package/src/integration/utf8-errors.test.ts +4 -4
- package/src/pi/AGENTS.md +6 -5
- package/src/pi/action-fusion.test.ts +125 -105
- package/src/pi/action-fusion.testing.ts +38 -0
- package/src/pi/action-fusion.ts +9 -21
- package/src/pi/argument-diagnostics.ts +4 -3
- package/src/pi/argument-format.test.ts +19 -18
- package/src/pi/argument-validation.test.ts +218 -139
- package/src/pi/budgets.ts +1 -4
- package/src/pi/codemode.test.ts +7 -2
- package/src/pi/config.test.ts +2 -1
- package/src/pi/config.ts +8 -3
- package/src/pi/diagnostic-buffer.test.ts +23 -13
- package/src/pi/edit-tool.ts +47 -62
- package/src/pi/error-text.ts +7 -2
- package/src/pi/execute.test.ts +174 -157
- package/src/pi/failure-context.test.ts +4 -3
- package/src/pi/failure-context.ts +1 -1
- package/src/pi/failure-path.test.ts +37 -37
- package/src/pi/file-commit.test.ts +47 -19
- package/src/pi/file-commit.ts +36 -9
- package/src/pi/fusion-card.test.ts +22 -21
- package/src/pi/grep-candidates.test.ts +18 -20
- package/src/pi/grep-candidates.ts +8 -13
- package/src/pi/grep-matrix.test.ts +3 -3
- package/src/pi/grep-order.test.ts +12 -11
- package/src/pi/grep-output.ts +36 -15
- package/src/pi/grep-reread.ts +7 -2
- package/src/pi/grep-rg.testing.ts +70 -0
- package/src/pi/grep-scope.ts +4 -4
- package/src/pi/grep-search.ts +8 -11
- package/src/pi/grep-tool.ts +23 -39
- package/src/pi/grep.test.ts +102 -116
- package/src/pi/model-budgets.test.ts +2 -1
- package/src/pi/mutation-outcome.testing.ts +0 -1
- package/src/pi/mutation-result.test.ts +8 -8
- package/src/pi/mutation-result.ts +1 -1
- package/src/pi/mutation-runner.ts +9 -5
- package/src/pi/output-budgets.test.ts +53 -31
- package/src/pi/pi.test.ts +18 -13
- package/src/pi/read-tool.ts +13 -18
- package/src/pi/read.test.ts +22 -41
- package/src/pi/registration.test.ts +25 -19
- package/src/pi/render.test.ts +51 -32
- package/src/pi/render.ts +7 -4
- package/src/pi/replace-regex.ts +1 -1
- package/src/pi/replace-tool.ts +6 -16
- package/src/pi/replace.test.ts +45 -34
- package/src/pi/report-failure.testing.ts +9 -1
- package/src/pi/report-schema.ts +205 -83
- package/src/pi/report.test.ts +66 -64
- package/src/pi/report.ts +23 -17
- package/src/pi/result-safety.test.ts +121 -100
- package/src/pi/rg-process.test.ts +2 -2
- package/src/pi/rg-process.ts +9 -15
- package/src/pi/schema.ts +23 -0
- package/src/pi/tool-factories.testing.ts +59 -0
- package/src/pi/write-tool.ts +9 -15
- package/src/pi/write.test.ts +30 -31
- package/src/testing/run-tests.ts +1 -1
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
|
-
"
|
|
43
|
+
"steps": [{ "action": "replace", "anchor": "2#GFYR", "lines": [" return \"hello, hashline\";"] }]
|
|
44
44
|
}
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -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 |
|
|
@@ -80,7 +81,7 @@ Range operations verify the cited `anchor` and `end`. Interior lines have no ind
|
|
|
80
81
|
|
|
81
82
|
## When an edit is rejected
|
|
82
83
|
|
|
83
|
-
Argument and anchor validation failures leave the file untouched. The report names the error
|
|
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.
|
|
84
85
|
|
|
85
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.
|
|
86
87
|
|
|
@@ -140,7 +141,7 @@ The selected model's declared context capacity sets the output budgets; remainin
|
|
|
140
141
|
|
|
141
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.
|
|
142
143
|
|
|
143
|
-
Read reports
|
|
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.
|
|
144
145
|
|
|
145
146
|
## Limits
|
|
146
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
|
-
"
|
|
43
|
+
"steps": [{ "action": "replace", "anchor": "2#GFYR", "lines": [" return \"hello, hashline\";"] }]
|
|
44
44
|
}
|
|
45
45
|
```
|
|
46
46
|
|
|
@@ -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` | 效果 |
|
|
@@ -80,7 +81,7 @@ Grep 用原生 JavaScript 正则匹配 LF 视图。不设 `multiline` 时逐物
|
|
|
80
81
|
|
|
81
82
|
## 修改被拒绝时
|
|
82
83
|
|
|
83
|
-
|
|
84
|
+
参数和锚点校验失败时不会改动文件。报告会给出错误码和相关字段;参数问题按字段给出 `fix`,锚点失败给出一条 `next` 恢复指引。锚点过期时,报告还会给出这一行最可能的新位置、新锚点和附近几行,模型确认后即可重新提交,不必重读整个文件。恢复过程从不自动修改,每次重试都会重新核对。
|
|
84
85
|
|
|
85
86
|
发布期间或发布后的失败会明确标记 `NOT_PUBLISHED`、`PUBLISHED` 或 `UNKNOWN`。重试前应遵循报告的 `next`:发布后的错误可能意味着所需修改已经写入磁盘。
|
|
86
87
|
|
|
@@ -140,7 +141,7 @@ Grep 用原生 JavaScript 正则匹配 LF 视图。不设 `multiline` 时逐物
|
|
|
140
141
|
|
|
141
142
|
模型容量未知或非法时,默认上限为 read 行 256 KiB、grep 载荷 50 KiB、每个诊断块 16 KiB、每个自由文本字段 4 KiB、每条 grep 预览 500 个 UTF-16 单元。显式设置 `read.maxKiB` 只覆盖 read 上限。每次执行使用开始时取得的预算快照。
|
|
142
143
|
|
|
143
|
-
Read
|
|
144
|
+
Read 因默认行数或字节预算截断窗口时会报告 `nextOffset`;只有调用方指定的 `limit` 生效时不额外报告 `nextOffset`。首行放不下时报告 `lineTooLong`,其值为字节上限。Grep 分别报告载荷和行预览的截断,非法 UTF-8 的普通预览不带编辑锚点。
|
|
144
145
|
|
|
145
146
|
## 限制
|
|
146
147
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@criogaid/pi-hashline-edit",
|
|
3
|
-
"version": "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",
|
package/src/core/apply.test.ts
CHANGED
|
@@ -134,7 +134,7 @@ test("overlapping edit spans → report conflicting operations in input order",
|
|
|
134
134
|
assert(error instanceof HashlineError);
|
|
135
135
|
assert.equal(error.errorCode, "OVERLAPPING_EDITS");
|
|
136
136
|
assert.equal(error.message, "Two edits overlap.");
|
|
137
|
-
assert.deepEqual(error.facts?.conflict, ["
|
|
137
|
+
assert.deepEqual(error.facts?.conflict, ["steps[1]", "steps[2]"]);
|
|
138
138
|
return true;
|
|
139
139
|
},
|
|
140
140
|
);
|
|
@@ -188,7 +188,7 @@ test("insertions sharing a gap → reject the batch", () => {
|
|
|
188
188
|
assert(error instanceof HashlineError);
|
|
189
189
|
assert.equal(error.errorCode, "OVERLAPPING_EDITS");
|
|
190
190
|
assert.equal(error.message, "Two edits insert at one position.");
|
|
191
|
-
assert.deepEqual(error.facts?.conflict, ["
|
|
191
|
+
assert.deepEqual(error.facts?.conflict, ["steps[0]", "steps[1]"]);
|
|
192
192
|
return true;
|
|
193
193
|
},
|
|
194
194
|
);
|
package/src/core/apply.ts
CHANGED
|
@@ -215,8 +215,8 @@ export function applyEdits(
|
|
|
215
215
|
// The first conflicting pair found, ascending.
|
|
216
216
|
facts: {
|
|
217
217
|
conflict: [
|
|
218
|
-
`
|
|
219
|
-
`
|
|
218
|
+
`steps[${Math.min(previous.opIndex, current.opIndex)}]`,
|
|
219
|
+
`steps[${Math.max(previous.opIndex, current.opIndex)}]`,
|
|
220
220
|
],
|
|
221
221
|
},
|
|
222
222
|
},
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
contains,
|
|
6
6
|
intersect,
|
|
7
7
|
subtract,
|
|
8
|
-
membership,
|
|
9
8
|
nativeCharacterRanges,
|
|
10
9
|
surrogatePair,
|
|
11
10
|
} from "./character-set.ts";
|
|
@@ -25,7 +24,7 @@ for (const [source, flags] of [
|
|
|
25
24
|
skip: unsupportedByHost([source], flags),
|
|
26
25
|
}, () => {
|
|
27
26
|
const ranges = nativeCharacterRanges(source, flags);
|
|
28
|
-
const native =
|
|
27
|
+
const native = new RegExp(`^(?:${source})`, flags);
|
|
29
28
|
for (const char of [
|
|
30
29
|
"a",
|
|
31
30
|
"A",
|
|
@@ -47,7 +46,7 @@ for (const [source, flags] of [
|
|
|
47
46
|
const isUnit = flags.includes("u") || flags.includes("v") || char.length === 1;
|
|
48
47
|
assert.equal(
|
|
49
48
|
contains(ranges, char.codePointAt(0)!),
|
|
50
|
-
isUnit && native.
|
|
49
|
+
isUnit && native.exec(char)?.[0] === char,
|
|
51
50
|
`${source}: ${JSON.stringify(char)}`,
|
|
52
51
|
);
|
|
53
52
|
}
|
|
@@ -94,7 +94,7 @@ export const contains = (ranges: Ranges, point: number): boolean =>
|
|
|
94
94
|
ranges.some(([low, high]) => low <= point && point <= high);
|
|
95
95
|
|
|
96
96
|
/** Full-string membership, including empty alternatives without the final-newline exception of $. */
|
|
97
|
-
|
|
97
|
+
const membership = (source: string, flags: string): RegExp =>
|
|
98
98
|
new RegExp(`^(?:${source})(?![\\s\\S])`, flags);
|
|
99
99
|
|
|
100
100
|
/** The exact single-character part of a validated expression; flags contain only i, s, u or v. */
|
package/src/core/ranges.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import { test } from "node:test";
|
|
3
|
-
import { findSortedRangeConflict, mergeRanges
|
|
3
|
+
import { findSortedRangeConflict, mergeRanges } from "./ranges.ts";
|
|
4
|
+
type HalfOpenRange = Parameters<typeof findSortedRangeConflict>[0][number];
|
|
4
5
|
|
|
5
6
|
test("sorted ranges sharing or crossing boundaries → report conflicts according to insertion policy", () => {
|
|
6
7
|
const cases: [HalfOpenRange[], number | undefined, number | undefined][] = [
|
package/src/core/ranges.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Half-open bounds in a caller-selected unit (line indices or string offsets). */
|
|
2
|
-
|
|
2
|
+
type HalfOpenRange = readonly [start: number, end: number];
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Find the first conflicting pair's second index. Input must be sorted by start, then end.
|
package/src/core/types.ts
CHANGED
|
@@ -61,7 +61,7 @@ export type AnchorRecovery =
|
|
|
61
61
|
/**
|
|
62
62
|
* A single anchor that failed verification, with its recovery attempt.
|
|
63
63
|
*
|
|
64
|
-
* `opIndex` is the 0-based position in the input `
|
|
64
|
+
* `opIndex` is the 0-based position in the input `steps[]`; `which` names the
|
|
65
65
|
* op's target or insertion anchor, or its range end; `op` is the op kind.
|
|
66
66
|
*/
|
|
67
67
|
export interface AnchorFailure {
|
package/src/index.ts
CHANGED
|
@@ -35,9 +35,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
35
35
|
const budgets = registerModelBudgets(pi);
|
|
36
36
|
// Saved then_run cards render even when Action Fusion is now off.
|
|
37
37
|
const reportProgress = registerFusionCards(pi);
|
|
38
|
-
const fusion = config.actionFusion
|
|
39
|
-
? createActionFusionExecutor(undefined, reportProgress)
|
|
40
|
-
: undefined;
|
|
38
|
+
const fusion = config.actionFusion ? createActionFusionExecutor(reportProgress) : undefined;
|
|
41
39
|
// Every tool returns a report; Pi prints this shared guideline once.
|
|
42
40
|
const register = <TParams extends TSchema, TDetails, TState>(
|
|
43
41
|
tool: ToolDefinition<TParams, TDetails, TState>,
|
|
@@ -49,11 +47,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
49
47
|
const registerMutation = <TParams extends TSchema, TDetails>(
|
|
50
48
|
tool: ToolDefinition<TParams, TDetails>,
|
|
51
49
|
) => register(fusion ? withMutationStatus(tool) : tool);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
registerMutation(
|
|
50
|
+
const env = { cwd, config, budgets };
|
|
51
|
+
const mutationEnv = { ...env, fusion };
|
|
52
|
+
registerMutation(makeWriteOverride(mutationEnv));
|
|
53
|
+
registerMutation(makeEditOverride(mutationEnv));
|
|
54
|
+
registerMutation(makeReplaceTool(mutationEnv));
|
|
55
55
|
|
|
56
|
-
register(makeReadOverride(
|
|
57
|
-
register(makeGrepOverride(
|
|
56
|
+
register(makeReadOverride(env));
|
|
57
|
+
register(makeGrepOverride(env));
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -7,7 +7,8 @@ import type { ExtensionAPI, ToolDefinition } from "@earendil-works/pi-coding-age
|
|
|
7
7
|
import registerHashline from "../index.ts";
|
|
8
8
|
import { computeLineHash } from "../core/hash.ts";
|
|
9
9
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
10
|
-
import {
|
|
10
|
+
import { type HashlineEditConfig } from "../pi/config.ts";
|
|
11
|
+
import { DEFAULT_CONFIG } from "../pi/tool-factories.testing.ts";
|
|
11
12
|
import { reportOf } from "../pi/report.ts";
|
|
12
13
|
import { formatByteSize } from "../pi/budgets.ts";
|
|
13
14
|
import { expectToolFailure } from "../pi/report-failure.testing.ts";
|
|
@@ -73,11 +74,11 @@ test("registered tools retain their configuration when another tool set is regis
|
|
|
73
74
|
grep: { path, pattern: "before", literal: true },
|
|
74
75
|
edit: {
|
|
75
76
|
path,
|
|
76
|
-
|
|
77
|
+
steps: [
|
|
77
78
|
{
|
|
78
79
|
action: "replace",
|
|
79
80
|
anchor: `1#${computeLineHash(1, "before", hashLen)}`,
|
|
80
|
-
|
|
81
|
+
lines: ["after"],
|
|
81
82
|
},
|
|
82
83
|
],
|
|
83
84
|
},
|
|
@@ -104,7 +105,7 @@ test("registered tools retain their configuration when another tool set is regis
|
|
|
104
105
|
await expectToolFailure(
|
|
105
106
|
callTool(tool, {
|
|
106
107
|
path,
|
|
107
|
-
|
|
108
|
+
steps: [{ action: "delete", anchor: `1#${computeLineHash(1, "target", hashLen)}` }],
|
|
108
109
|
}),
|
|
109
110
|
"ANCHOR_MISMATCH",
|
|
110
111
|
(report) => {
|
|
@@ -134,7 +135,7 @@ test("registered tools retain their configuration when another tool set is regis
|
|
|
134
135
|
`${index + 1}#${computeLineHash(index + 1, content, hashLen)}│${content}`,
|
|
135
136
|
),
|
|
136
137
|
);
|
|
137
|
-
assert.equal(reportOf(result, "read")?.
|
|
138
|
+
assert.equal(reportOf(result, "read")?.nextOffset, read.defaultLimit + 1);
|
|
138
139
|
|
|
139
140
|
const wide = "界".repeat(500);
|
|
140
141
|
await writeFile(join(directory, path), `${wide}\n`);
|
|
@@ -142,17 +143,14 @@ test("registered tools retain their configuration when another tool set is regis
|
|
|
142
143
|
assert.equal(bounded.content[0].type, "text");
|
|
143
144
|
if (read.maxKiB === 1) {
|
|
144
145
|
const maxBytes = read.maxKiB * 1024;
|
|
145
|
-
assert.
|
|
146
|
-
line: 1,
|
|
147
|
-
limit: formatByteSize(maxBytes),
|
|
148
|
-
});
|
|
146
|
+
assert.equal(reportOf(bounded, "read")?.lineTooLong, formatByteSize(maxBytes));
|
|
149
147
|
assert.doesNotMatch(bounded.content[0].text, /^\d+#/m);
|
|
150
148
|
} else {
|
|
151
149
|
assert.ok(
|
|
152
150
|
bounded.content[0].text.includes(`1#${computeLineHash(1, wide, hashLen)}│${wide}`),
|
|
153
151
|
);
|
|
154
152
|
assert.equal(reportOf(bounded, "read")?.outputLimit, undefined);
|
|
155
|
-
assert.equal(reportOf(bounded, "read")?.
|
|
153
|
+
assert.equal(reportOf(bounded, "read")?.nextOffset, undefined);
|
|
156
154
|
}
|
|
157
155
|
},
|
|
158
156
|
);
|
|
@@ -8,7 +8,7 @@ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
|
8
8
|
import { openTestSession, responseStream } from "../testing/session.testing.ts";
|
|
9
9
|
import type { ActionFusionProgress } from "../pi/report-schema.ts";
|
|
10
10
|
import { createActionFusionExecutor, type ThenRunInput } from "../pi/action-fusion.ts";
|
|
11
|
-
import { makeWriteOverride } from "../pi/
|
|
11
|
+
import { makeWriteOverride } from "../pi/tool-factories.testing.ts";
|
|
12
12
|
import { commandText } from "../pi/mutation-result.ts";
|
|
13
13
|
import { reportOf } from "../pi/report.ts";
|
|
14
14
|
import type { CommandStatus } from "../pi/report-schema.ts";
|
|
@@ -31,7 +31,7 @@ async function openSession(
|
|
|
31
31
|
pi.registerTool(
|
|
32
32
|
makeWriteOverride(
|
|
33
33
|
cwd,
|
|
34
|
-
createActionFusionExecutor(
|
|
34
|
+
createActionFusionExecutor((event) => {
|
|
35
35
|
progress.push(event);
|
|
36
36
|
onProgress?.(event);
|
|
37
37
|
}),
|
|
@@ -3,8 +3,8 @@ import { chmod, mkdir, mkdtemp, rm, stat, symlink, writeFile } from "node:fs/pro
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { test } from "node:test";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
|
|
7
|
+
|
|
8
8
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
9
9
|
import { expectToolFailure } from "../pi/report-failure.testing.ts";
|
|
10
10
|
|
|
@@ -36,7 +36,7 @@ for (const condition of ["permission denied", "symlink loop"] as const) {
|
|
|
36
36
|
code = "ELOOP";
|
|
37
37
|
}
|
|
38
38
|
await assert.rejects(stat(path), { code });
|
|
39
|
-
const tool =
|
|
39
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
40
40
|
await expectToolFailure(
|
|
41
41
|
callTool(tool, { path, pattern: "needle", literal: true, ignoreCase: false }),
|
|
42
42
|
"FILESYSTEM_ERROR",
|
|
@@ -3,10 +3,10 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { test } from "node:test";
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
|
|
7
|
+
|
|
8
8
|
import { reportOf } from "../pi/report.ts";
|
|
9
|
-
|
|
9
|
+
const { grepCounts } = await import("../pi/grep-output.testing.ts");
|
|
10
10
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
11
11
|
|
|
12
12
|
const cases = [
|
|
@@ -216,7 +216,7 @@ test("grep flags: JavaScript modes preserve native matching through the real sea
|
|
|
216
216
|
const directory = await mkdtemp(join(tmpdir(), "hl-grep-flags-"));
|
|
217
217
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
218
218
|
const path = join(directory, "input.txt");
|
|
219
|
-
const tool =
|
|
219
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
220
220
|
for (const scenario of cases) {
|
|
221
221
|
await t.test(scenario.name, async () => {
|
|
222
222
|
await writeFile(path, scenario.source);
|
|
@@ -245,7 +245,7 @@ test("grep flags: valid V8 patterns exceeding translator parser depth still exec
|
|
|
245
245
|
await writeFile(path, "A\na\n");
|
|
246
246
|
const pattern = `${"(?:".repeat(3_000)}A${")".repeat(3_000)}`;
|
|
247
247
|
assert.equal(new RegExp(pattern).test("A"), true);
|
|
248
|
-
const tool =
|
|
248
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
249
249
|
for (const flags of [undefined, "m"]) {
|
|
250
250
|
const result = await callTool(tool, {
|
|
251
251
|
path,
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { makeMockGrep } from "../pi/grep-rg.testing.ts";
|
|
1
2
|
import assert from "node:assert/strict";
|
|
2
3
|
import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
4
|
import { tmpdir } from "node:os";
|
|
4
5
|
import { join } from "node:path";
|
|
5
6
|
import { test } from "node:test";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
|
|
8
|
+
const MAX_MULTILINE_SEARCH_BYTES = 64 * 1024 * 1024;
|
|
9
|
+
|
|
9
10
|
import { reportOf } from "../pi/report.ts";
|
|
10
|
-
|
|
11
|
+
const { grepCounts } = await import("../pi/grep-output.testing.ts");
|
|
11
12
|
import { COMMON_RG_ARGS, runRgLines, runRgPaths } from "../pi/rg-process.ts";
|
|
12
13
|
import { searchText } from "../core/search.ts";
|
|
13
14
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
@@ -28,7 +29,7 @@ test("JS grep: rg discovery retains ignore, hidden, glob, and binary rules", asy
|
|
|
28
29
|
await writeFile(join(directory, name), "😀\n");
|
|
29
30
|
await writeFile(join(directory, ".ignore"), "ignored.txt\n");
|
|
30
31
|
await writeFile(join(directory, "binary.txt"), "😀\n\0");
|
|
31
|
-
const tool =
|
|
32
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
32
33
|
const result = await callTool(tool, {
|
|
33
34
|
...query,
|
|
34
35
|
path: directory,
|
|
@@ -55,7 +56,7 @@ test("JS grep: physical rows, context, and limits agree across output modes", as
|
|
|
55
56
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
56
57
|
const path = join(directory, "input.txt");
|
|
57
58
|
await writeFile(path, "head\r\n😀\r\nab\ntail\n");
|
|
58
|
-
const tool =
|
|
59
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
59
60
|
for (const outputMode of ["content", "files", "count"] as const) {
|
|
60
61
|
const result = await callTool(tool, { ...query, path, outputMode, limit: 1, context: 1 });
|
|
61
62
|
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
@@ -79,7 +80,7 @@ test("JS grep: malformed UTF-8 matches the preview text without editable anchors
|
|
|
79
80
|
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
80
81
|
const path = join(directory, "invalid.txt");
|
|
81
82
|
await writeFile(path, Buffer.from([0x61, 0xff, 0x62, 0x0a]));
|
|
82
|
-
const tool =
|
|
83
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
83
84
|
const result = await callTool(tool, { path, pattern: "a.b", literal: false });
|
|
84
85
|
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
85
86
|
assert.equal(grepCounts(result).matches, 1);
|
|
@@ -97,7 +98,7 @@ test("oversized line or multiline input → explicit incomplete-search diagnosti
|
|
|
97
98
|
const good = join(directory, "good.txt");
|
|
98
99
|
const oversized = Buffer.alloc(MAX_MULTILINE_SEARCH_BYTES + 1, 0x61);
|
|
99
100
|
await writeFile(good, "a\n");
|
|
100
|
-
const tool =
|
|
101
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
101
102
|
for (const finalNewline of [false, true]) {
|
|
102
103
|
await writeFile(path, finalNewline ? Buffer.concat([oversized, Buffer.from("\n")]) : oversized);
|
|
103
104
|
for (const multiline of [false, true]) {
|
|
@@ -147,7 +148,7 @@ test("real rg candidates → include every JS row and preserve confirmed output
|
|
|
147
148
|
] as const) {
|
|
148
149
|
await t.test(`${pattern} /${flags} → identical confirmed results`, async () => {
|
|
149
150
|
const candidates = new Map<string, readonly number[] | undefined>();
|
|
150
|
-
const filtered =
|
|
151
|
+
const filtered = makeMockGrep(directory, DEFAULT_CONFIG, {
|
|
151
152
|
runRgPaths(args, signal, onPath) {
|
|
152
153
|
return runRgPaths(args, signal, (path) => {
|
|
153
154
|
candidates.set(path, undefined);
|
|
@@ -161,7 +162,7 @@ test("real rg candidates → include every JS row and preserve confirmed output
|
|
|
161
162
|
});
|
|
162
163
|
},
|
|
163
164
|
});
|
|
164
|
-
const full =
|
|
165
|
+
const full = makeMockGrep(directory, DEFAULT_CONFIG, {
|
|
165
166
|
runRgPaths(args, signal, onPath) {
|
|
166
167
|
const scopeStart = args.indexOf("--null");
|
|
167
168
|
assert.ok(scopeStart >= 0);
|
|
@@ -221,7 +222,7 @@ test("NUL past a search limit → skips oversized line and multiline files witho
|
|
|
221
222
|
const path = join(directory, "large-nul.txt");
|
|
222
223
|
// Place NUL beyond the chunk that first exceeds the search limit.
|
|
223
224
|
const bytes = Buffer.alloc(MAX_MULTILINE_SEARCH_BYTES + 1024 * 1024, 0x61);
|
|
224
|
-
const tool =
|
|
225
|
+
const tool = makeGrepOverride(directory, DEFAULT_CONFIG);
|
|
225
226
|
for (const hasNul of [true, false]) {
|
|
226
227
|
bytes[bytes.length - 1] = hasNul ? 0 : 0x61;
|
|
227
228
|
await writeFile(path, bytes);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { searchWithMockRg } from "../pi/grep-rg.testing.ts";
|
|
1
2
|
import assert from "node:assert/strict";
|
|
2
3
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
3
4
|
import { tmpdir } from "node:os";
|
|
@@ -5,7 +6,7 @@ import { join } from "node:path";
|
|
|
5
6
|
import { test } from "node:test";
|
|
6
7
|
import { acceptsNative } from "../core/search-matrix.testing.ts";
|
|
7
8
|
import { searchText, type GrepQuery } from "../core/search.ts";
|
|
8
|
-
import {
|
|
9
|
+
import type { GrepFileMatch } from "../pi/grep-search.ts";
|
|
9
10
|
import { lineCandidatePatterns } from "../pi/rg-regex.ts";
|
|
10
11
|
import { runRgLines } from "../pi/rg-process.ts";
|
|
11
12
|
import { REGEX_TRANSLATION_CORPUS } from "../testing/regex-translation-corpus.ts";
|
|
@@ -182,7 +183,7 @@ test("Cartesian adversarial bytes × syntax × flags × assertion positions →
|
|
|
182
183
|
const translated = lineCandidatePatterns(query);
|
|
183
184
|
assert.ok(translated, JSON.stringify(query));
|
|
184
185
|
const candidates = new Map<string, readonly number[] | undefined>();
|
|
185
|
-
const actual = await
|
|
186
|
+
const actual = await searchWithMockRg({
|
|
186
187
|
backend: {
|
|
187
188
|
async runRgPaths() {
|
|
188
189
|
assert.fail(`unexpected file fallback: ${JSON.stringify(query)}`);
|
|
@@ -12,10 +12,11 @@ import {
|
|
|
12
12
|
MATRIX_INPUTS,
|
|
13
13
|
} from "../core/search-matrix.testing.ts";
|
|
14
14
|
import { runRgPaths } from "../pi/rg-process.ts";
|
|
15
|
-
import {
|
|
15
|
+
import { fileCandidateArgs } from "../pi/grep-rg.testing.ts";
|
|
16
16
|
|
|
17
17
|
interface CandidateCase {
|
|
18
18
|
readonly prefilter: Prefilter;
|
|
19
|
+
readonly query: GrepQuery;
|
|
19
20
|
readonly required: Map<string, GrepQuery>;
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -43,7 +44,7 @@ async function checkCandidates(t: TestContext, queries: Iterable<{ readonly quer
|
|
|
43
44
|
const key = JSON.stringify(prefilter);
|
|
44
45
|
let group = groups.get(key);
|
|
45
46
|
if (!group) {
|
|
46
|
-
group = { prefilter, required: new Map() };
|
|
47
|
+
group = { prefilter, query, required: new Map() };
|
|
47
48
|
groups.set(key, group);
|
|
48
49
|
}
|
|
49
50
|
for (const input of inputs) {
|
|
@@ -63,10 +64,10 @@ async function checkCandidates(t: TestContext, queries: Iterable<{ readonly quer
|
|
|
63
64
|
const workers = await Promise.allSettled(
|
|
64
65
|
Array.from({ length: concurrency }, async () => {
|
|
65
66
|
while (next < cases.length) {
|
|
66
|
-
const { prefilter, required } = cases[next++];
|
|
67
|
+
const { prefilter, query, required } = cases[next++];
|
|
67
68
|
const actual = new Set<string>();
|
|
68
69
|
const result = await runRgPaths(
|
|
69
|
-
[...
|
|
70
|
+
[...(await fileCandidateArgs(query)), "--null", "--", directory],
|
|
70
71
|
AbortSignal.timeout(processTimeoutMs),
|
|
71
72
|
(path) => {
|
|
72
73
|
actual.add(basename(path));
|
|
@@ -4,9 +4,9 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { test } from "node:test";
|
|
6
6
|
import { computeLineHash } from "../core/hash.ts";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
const { DEFAULT_CONFIG, makeGrepOverride } = await import("../pi/tool-factories.testing.ts");
|
|
8
|
+
const { parseFileHeader } = await import("../pi/grep-output.ts");
|
|
9
|
+
|
|
10
10
|
import { reportOf } from "../pi/report.ts";
|
|
11
11
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
12
12
|
|
|
@@ -20,7 +20,7 @@ test("repeated real-rg query with increasing limits → stable traversal order a
|
|
|
20
20
|
for (const name of names) {
|
|
21
21
|
await writeFile(join(dir, name), `${sourceLine(name, 1)}\n${sourceLine(name, 2)}\n`);
|
|
22
22
|
}
|
|
23
|
-
const tool =
|
|
23
|
+
const tool = makeGrepOverride(dir, DEFAULT_CONFIG);
|
|
24
24
|
for (const [roots, expectedNames] of [
|
|
25
25
|
[["."], ["a.txt", "sub/b.txt", "sub.txt", "z.txt"]],
|
|
26
26
|
[
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { makeMockGrep } from "../pi/grep-rg.testing.ts";
|
|
1
2
|
import assert from "node:assert/strict";
|
|
2
3
|
import { test } from "node:test";
|
|
3
4
|
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
4
5
|
import { tmpdir } from "node:os";
|
|
5
6
|
import { basename, join } from "node:path";
|
|
6
7
|
import { DEFAULT_GREP_FLAGS, searchText } from "../core/search.ts";
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const { DEFAULT_CONFIG } = await import("../pi/tool-factories.testing.ts");
|
|
9
|
+
|
|
9
10
|
import { reportOf } from "../pi/report.ts";
|
|
10
|
-
|
|
11
|
+
const { grepCounts } = await import("../pi/grep-output.testing.ts");
|
|
11
12
|
import { runRgLines, runRgPaths } from "../pi/rg-process.ts";
|
|
12
13
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
13
14
|
import { acceptsNative } from "../core/search-matrix.testing.ts";
|
|
@@ -28,7 +29,7 @@ test("Cartesian literal mode × flags × case override × line mode × bytes →
|
|
|
28
29
|
for (const input of inputs) await writeFile(join(directory, input.name), input.bytes);
|
|
29
30
|
const limit = inputs.reduce((sum, input) => sum + input.bytes.length, 0);
|
|
30
31
|
const candidates = new Map<string, readonly number[] | undefined>();
|
|
31
|
-
const tool =
|
|
32
|
+
const tool = makeMockGrep(directory, DEFAULT_CONFIG, {
|
|
32
33
|
runRgPaths(args, signal, onPath) {
|
|
33
34
|
return runRgPaths(args, signal, (path) => {
|
|
34
35
|
candidates.set(basename(path), undefined);
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "../core/search-matrix.testing.ts";
|
|
13
13
|
import { searchText, type GrepQuery } from "../core/search.ts";
|
|
14
14
|
import { runRgPaths } from "../pi/rg-process.ts";
|
|
15
|
-
import {
|
|
15
|
+
import { fileCandidateArgs } from "../pi/grep-rg.testing.ts";
|
|
16
16
|
|
|
17
17
|
const syntaxCases = [
|
|
18
18
|
...MATRIX_SYNTAX,
|
|
@@ -53,6 +53,7 @@ function emptyCoverage(): Coverage {
|
|
|
53
53
|
|
|
54
54
|
interface CandidateCase {
|
|
55
55
|
readonly prefilter: Prefilter;
|
|
56
|
+
readonly query: GrepQuery;
|
|
56
57
|
readonly required: Map<string, GrepQuery>;
|
|
57
58
|
readonly contributions: Map<Coverage, number>;
|
|
58
59
|
}
|
|
@@ -109,7 +110,7 @@ test("Cartesian prefilter coverage × composition × flags × bytes → real rg
|
|
|
109
110
|
const key = JSON.stringify(prefilter);
|
|
110
111
|
let group = groups.get(key);
|
|
111
112
|
if (!group) {
|
|
112
|
-
group = { prefilter, required: new Map(), contributions: new Map() };
|
|
113
|
+
group = { prefilter, query, required: new Map(), contributions: new Map() };
|
|
113
114
|
groups.set(key, group);
|
|
114
115
|
}
|
|
115
116
|
let hits = 0;
|
|
@@ -140,7 +141,7 @@ test("Cartesian prefilter coverage × composition × flags × bytes → real rg
|
|
|
140
141
|
const group = cases[next++];
|
|
141
142
|
const actual = new Set<string>();
|
|
142
143
|
const result = await runRgPaths(
|
|
143
|
-
[...
|
|
144
|
+
[...(await fileCandidateArgs(group.query)), "--null", "--", directory],
|
|
144
145
|
AbortSignal.timeout(processTimeoutMs),
|
|
145
146
|
(path) => {
|
|
146
147
|
actual.add(basename(path));
|
|
@@ -3,9 +3,9 @@ import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { test } from "node:test";
|
|
6
|
-
import { DEFAULT_CONFIG } from "../pi/
|
|
6
|
+
import { DEFAULT_CONFIG } from "../pi/tool-factories.testing.ts";
|
|
7
7
|
import { grepCounts } from "../pi/grep-output.testing.ts";
|
|
8
|
-
import { makeGrepOverride } from "../pi/
|
|
8
|
+
import { makeGrepOverride } from "../pi/tool-factories.testing.ts";
|
|
9
9
|
import { expectToolFailure } from "../pi/report-failure.testing.ts";
|
|
10
10
|
import { reportOf } from "../pi/report.ts";
|
|
11
11
|
import { callTool } from "../pi/tool-call.testing.ts";
|
|
@@ -62,7 +62,6 @@ test("multiline prefilter exceeds the rg pattern budget → scan all files and r
|
|
|
62
62
|
});
|
|
63
63
|
assert.equal(result.isError, undefined, JSON.stringify(reportOf(result, "grep")));
|
|
64
64
|
assert.deepEqual(grepCounts(result), { matches: count, files: count });
|
|
65
|
-
assert.equal(reportOf(result, "grep")?.scanned, "all");
|
|
66
65
|
},
|
|
67
66
|
);
|
|
68
67
|
}
|
|
@@ -74,5 +73,4 @@ test("multiline prefilter exceeds the rg pattern budget → scan all files and r
|
|
|
74
73
|
});
|
|
75
74
|
assert.equal(literal.isError, undefined);
|
|
76
75
|
assert.deepEqual(grepCounts(literal), { matches: 1, files: 1 });
|
|
77
|
-
assert.equal(reportOf(literal, "grep")?.scanned, "files");
|
|
78
76
|
});
|