@criogaid/pi-hashline-edit 0.3.1 → 0.5.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 +166 -61
- package/package.json +8 -3
- package/src/core/apply.test.ts +459 -313
- package/src/core/apply.ts +251 -215
- package/src/core/errors.ts +9 -0
- package/src/core/hash.test.ts +61 -23
- package/src/core/hash.ts +49 -20
- package/src/core/lines.test.ts +46 -27
- package/src/core/lines.ts +36 -28
- package/src/core/ranges.test.ts +73 -19
- package/src/core/ranges.ts +15 -15
- package/src/core/replace.ts +109 -0
- package/src/core/text.test.ts +3 -3
- package/src/core/text.ts +26 -9
- package/src/core/types.ts +56 -41
- package/src/index.ts +23 -19
- package/src/integration/config-registration.test.ts +206 -0
- package/src/integration/grep-rg.test.ts +879 -251
- package/src/integration/large-text.test.ts +63 -0
- package/src/integration/replace-package.test.ts +41 -0
- package/src/pi/action-fusion.test.ts +612 -207
- package/src/pi/action-fusion.ts +442 -254
- package/src/pi/anchor-format.test.ts +53 -21
- package/src/pi/anchor-format.ts +48 -20
- package/src/pi/budgets.ts +25 -0
- package/src/pi/config.test.ts +178 -35
- package/src/pi/config.ts +96 -37
- package/src/pi/directory-sync.test.ts +55 -0
- package/src/pi/e2e-scenarios.test.ts +360 -0
- package/src/pi/edit-tool.ts +307 -279
- package/src/pi/error-text.ts +26 -0
- package/src/pi/execute.test.ts +1718 -713
- package/src/pi/failure-context.test.ts +110 -83
- package/src/pi/failure-context.ts +232 -73
- package/src/pi/failure-path.test.ts +180 -66
- package/src/pi/file-commit.test.ts +446 -233
- package/src/pi/file-commit.ts +348 -203
- package/src/pi/fusion-card.test.ts +118 -83
- package/src/pi/fusion-card.ts +203 -87
- package/src/pi/grep-output.ts +225 -0
- package/src/pi/grep-render.ts +59 -0
- package/src/pi/grep-scope.ts +139 -0
- package/src/pi/grep-search.ts +231 -0
- package/src/pi/grep-tool.ts +215 -774
- package/src/pi/grep.test.ts +825 -376
- package/src/pi/mutation-outcome.testing.ts +22 -0
- package/src/pi/mutation-result.test.ts +86 -0
- package/src/pi/mutation-result.ts +118 -63
- package/src/pi/mutation-runner.ts +151 -0
- package/src/pi/path.ts +20 -12
- package/src/pi/pi.test.ts +100 -52
- package/src/pi/read-tool.ts +245 -134
- package/src/pi/registration.test.ts +271 -114
- package/src/pi/render.test.ts +227 -84
- package/src/pi/render.ts +86 -116
- package/src/pi/replace-regex.ts +54 -0
- package/src/pi/replace-tool.ts +247 -241
- package/src/pi/replace-worker.mjs +4 -0
- package/src/pi/replace-worker.ts +10 -0
- package/src/pi/replace.test.ts +778 -390
- package/src/pi/result-safety.test.ts +821 -344
- package/src/pi/rg-line-ranges.test.ts +57 -31
- package/src/pi/rg-line-ranges.ts +45 -82
- package/src/pi/rg-process.test.ts +113 -0
- package/src/pi/{rg-line-filter.ts → rg-process.ts} +72 -125
- package/src/pi/rg-text-view.ts +102 -48
- package/src/pi/schema.ts +19 -0
- package/src/pi/text-stream.test.ts +118 -0
- package/src/pi/text-stream.ts +136 -0
- package/src/pi/tool-call.testing.ts +37 -0
- package/src/pi/write-tool.ts +114 -52
- package/src/pi/write.test.ts +250 -97
- package/src/core/index.ts +0 -14
- package/src/pi/rg-line-filter.test.ts +0 -85
- package/src/pi/state.ts +0 -26
|
@@ -3,79 +3,193 @@ import { tmpdir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import assert from "node:assert/strict";
|
|
5
5
|
import { test } from "node:test";
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
createActionFusionExecutor,
|
|
8
|
+
ActionFusionError,
|
|
9
|
+
THEN_RUN_STALE,
|
|
10
|
+
THEN_RUN_SUCCEEDED,
|
|
11
|
+
} from "./action-fusion.ts";
|
|
12
|
+
import { FileMutationError } from "./file-commit.ts";
|
|
13
|
+
import { staleTargetNotice } from "./mutation-result.ts";
|
|
14
|
+
import { publishedMutation } from "./mutation-outcome.testing.ts";
|
|
8
15
|
|
|
9
16
|
async function withTemp<T>(run: (dir: string) => Promise<T>): Promise<T> {
|
|
10
|
-
|
|
11
|
-
|
|
17
|
+
const dir = await mkdtemp(join(tmpdir(), "hashline-failure-"));
|
|
18
|
+
try {
|
|
19
|
+
return await run(dir);
|
|
20
|
+
} finally {
|
|
21
|
+
await rm(dir, { recursive: true, force: true });
|
|
22
|
+
}
|
|
12
23
|
}
|
|
13
24
|
|
|
14
25
|
const context = (cwd: string) => ({ cwd }) as any;
|
|
15
|
-
const result = (content: string) =>
|
|
26
|
+
const result = (content: string) =>
|
|
27
|
+
publishedMutation(content, {
|
|
28
|
+
content: [{ type: "text", text: "mutation" }],
|
|
29
|
+
details: undefined,
|
|
30
|
+
});
|
|
16
31
|
|
|
17
|
-
test("published post-processing failure skips command and preserves publication state", async () =>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
test("published post-processing failure skips command and preserves publication state", async () =>
|
|
33
|
+
withTemp(async (dir) => {
|
|
34
|
+
const target = join(dir, "published.txt");
|
|
35
|
+
await writeFile(target, "content\n");
|
|
36
|
+
let commanded = false;
|
|
37
|
+
const updates: any[] = [];
|
|
38
|
+
const fusion = createActionFusionExecutor(async () => {
|
|
39
|
+
commanded = true;
|
|
40
|
+
return "never";
|
|
41
|
+
});
|
|
42
|
+
await assert.rejects(
|
|
43
|
+
fusion({
|
|
44
|
+
toolCallId: "published",
|
|
45
|
+
absolutePath: target,
|
|
46
|
+
thenRun: { command: "check" },
|
|
47
|
+
mutate: async () => {
|
|
48
|
+
throw new FileMutationError(
|
|
49
|
+
"post_process",
|
|
50
|
+
"PUBLISHED",
|
|
51
|
+
"file was published but result generation failed",
|
|
52
|
+
);
|
|
53
|
+
},
|
|
54
|
+
signal: undefined,
|
|
55
|
+
ctx: context(dir),
|
|
56
|
+
onUpdate: (update) => updates.push(update),
|
|
57
|
+
}),
|
|
58
|
+
(error: unknown) =>
|
|
59
|
+
error instanceof ActionFusionError &&
|
|
60
|
+
error.publication === "PUBLISHED" &&
|
|
61
|
+
error.command === "skipped" &&
|
|
62
|
+
!commanded &&
|
|
63
|
+
/Re-read before retrying/.test(error.message),
|
|
64
|
+
);
|
|
65
|
+
assert.ok(updates.every((update) => update.details.actionFusion.mutationCompleted === false));
|
|
66
|
+
assert.equal(updates.at(-1).details.actionFusion.publication, "PUBLISHED");
|
|
67
|
+
}));
|
|
30
68
|
|
|
31
|
-
test("command failure still reports final changed freshness", async () =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
69
|
+
test("command failure still reports final changed freshness", async () =>
|
|
70
|
+
withTemp(async (dir) => {
|
|
71
|
+
const target = join(dir, "failed.txt");
|
|
72
|
+
await writeFile(target, "before\n");
|
|
73
|
+
const fusion = createActionFusionExecutor(async () => {
|
|
74
|
+
await writeFile(target, "command changed\n");
|
|
75
|
+
throw new Error("command failed");
|
|
76
|
+
});
|
|
77
|
+
const outcome: any = await fusion({
|
|
78
|
+
toolCallId: "failed",
|
|
79
|
+
absolutePath: target,
|
|
80
|
+
thenRun: { command: "check" },
|
|
81
|
+
mutate: async () => {
|
|
82
|
+
await writeFile(target, "mutation\n");
|
|
83
|
+
return result("mutation\n");
|
|
84
|
+
},
|
|
85
|
+
signal: undefined,
|
|
86
|
+
ctx: context(dir),
|
|
87
|
+
});
|
|
88
|
+
assert.deepEqual(outcome.details.actionFusion, {
|
|
89
|
+
publication: "PUBLISHED",
|
|
90
|
+
command: "failed",
|
|
91
|
+
freshness: "changed",
|
|
92
|
+
});
|
|
93
|
+
assert.deepEqual(outcome.content[1], { type: "text", text: staleTargetNotice(THEN_RUN_STALE) });
|
|
94
|
+
assert.equal(outcome.content.length, 3);
|
|
95
|
+
assert.match(outcome.content[2].text, /command failed/);
|
|
96
|
+
}));
|
|
40
97
|
|
|
41
|
-
test("timeout and cancellation do not rerun mutation and still inspect freshness", async () =>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
98
|
+
test("timeout and cancellation do not rerun mutation and still inspect freshness", async () =>
|
|
99
|
+
withTemp(async (dir) => {
|
|
100
|
+
const target = join(dir, "cancelled.txt");
|
|
101
|
+
await writeFile(target, "before\n");
|
|
102
|
+
let mutations = 0;
|
|
103
|
+
const controller = new AbortController();
|
|
104
|
+
const fusion = createActionFusionExecutor(async () => {
|
|
105
|
+
controller.abort();
|
|
106
|
+
throw new Error("timed out");
|
|
107
|
+
});
|
|
108
|
+
const outcome: any = await fusion({
|
|
109
|
+
toolCallId: "cancelled",
|
|
110
|
+
absolutePath: target,
|
|
111
|
+
thenRun: { command: "check" },
|
|
112
|
+
mutate: async () => {
|
|
113
|
+
mutations++;
|
|
114
|
+
await writeFile(target, "mutation\n");
|
|
115
|
+
return result("mutation\n");
|
|
116
|
+
},
|
|
117
|
+
signal: controller.signal,
|
|
118
|
+
ctx: context(dir),
|
|
119
|
+
});
|
|
120
|
+
assert.equal(outcome.details.actionFusion.command, "cancelled");
|
|
121
|
+
assert.equal(outcome.details.actionFusion.freshness, "unchanged");
|
|
122
|
+
assert.equal(mutations, 1);
|
|
123
|
+
}));
|
|
52
124
|
|
|
53
|
-
test("queue is released after a failed command", async () =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
125
|
+
test("queue is released after a failed command", async () =>
|
|
126
|
+
withTemp(async (dir) => {
|
|
127
|
+
const target = join(dir, "queue.txt");
|
|
128
|
+
await writeFile(target, "before\n");
|
|
129
|
+
let calls = 0;
|
|
130
|
+
const fusion = createActionFusionExecutor(async () => {
|
|
131
|
+
calls++;
|
|
132
|
+
if (calls === 1) throw new Error("first command failed");
|
|
133
|
+
return "ok";
|
|
134
|
+
});
|
|
135
|
+
const first = fusion({
|
|
136
|
+
toolCallId: "first",
|
|
137
|
+
absolutePath: target,
|
|
138
|
+
thenRun: { command: "fail" },
|
|
139
|
+
mutate: async () => {
|
|
140
|
+
await writeFile(target, "first\n");
|
|
141
|
+
return result("first\n");
|
|
142
|
+
},
|
|
143
|
+
signal: undefined,
|
|
144
|
+
ctx: context(dir),
|
|
145
|
+
});
|
|
146
|
+
const failed: any = await first;
|
|
147
|
+
assert.equal(failed.details.actionFusion.command, "failed");
|
|
148
|
+
const second = await fusion({
|
|
149
|
+
toolCallId: "second",
|
|
150
|
+
absolutePath: target,
|
|
151
|
+
thenRun: { command: "ok" },
|
|
152
|
+
mutate: async () => {
|
|
153
|
+
await writeFile(target, "second\n");
|
|
154
|
+
return result("second\n");
|
|
155
|
+
},
|
|
156
|
+
signal: undefined,
|
|
157
|
+
ctx: context(dir),
|
|
158
|
+
});
|
|
159
|
+
assert.equal(calls, 2);
|
|
160
|
+
assert.match(
|
|
161
|
+
second.content[1].type === "text" ? second.content[1].text : "",
|
|
162
|
+
/then_run:succeeded/,
|
|
163
|
+
);
|
|
164
|
+
}));
|
|
65
165
|
|
|
66
|
-
test("
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
166
|
+
test("successful command finalizes anchors and retains completed progress", async () =>
|
|
167
|
+
withTemp(async (dir) => {
|
|
168
|
+
const target = join(dir, "finalize.txt");
|
|
169
|
+
const progress: any[] = [];
|
|
170
|
+
const fusion = createActionFusionExecutor(
|
|
171
|
+
async () => "command finished",
|
|
172
|
+
(event) => progress.push(event),
|
|
173
|
+
);
|
|
174
|
+
const completed = await fusion({
|
|
175
|
+
toolCallId: "finalize",
|
|
176
|
+
absolutePath: target,
|
|
177
|
+
thenRun: { command: "check" },
|
|
178
|
+
signal: undefined,
|
|
179
|
+
ctx: context(dir),
|
|
180
|
+
mutate: async () => {
|
|
181
|
+
await writeFile(target, "saved\n");
|
|
182
|
+
return { ...result("saved\n"), anchors: " ANCHOR" };
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
assert.deepEqual(completed.content, [
|
|
186
|
+
{ type: "text", text: "mutation ANCHOR" },
|
|
187
|
+
{ type: "text", text: `${THEN_RUN_SUCCEEDED}\ncommand finished` },
|
|
188
|
+
]);
|
|
189
|
+
assert.equal(progress.filter((event) => event.command === "succeeded").length, 1);
|
|
190
|
+
assert.equal(progress.at(-1).publication, "PUBLISHED");
|
|
191
|
+
assert.equal(progress.at(-1).freshness, "unchanged");
|
|
192
|
+
assert.equal(progress.at(-1).command, "succeeded");
|
|
193
|
+
assert.equal(progress.at(-1).output, "command finished");
|
|
194
|
+
assert.equal(progress.at(-1).reason, undefined);
|
|
195
|
+
}));
|