@criogaid/pi-hashline-edit 0.8.0 → 0.10.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 +13 -10
- package/README.zh-CN.md +12 -9
- package/THIRD_PARTY_NOTICES.md +0 -6
- package/package.json +1 -1
- package/src/core/AGENTS.md +4 -5
- package/src/core/apply.test.ts +118 -293
- package/src/core/apply.ts +63 -165
- package/src/core/case-fold.ts +8 -67
- package/src/core/character-set.ts +4 -4
- package/src/core/errors.test.ts +23 -7
- package/src/core/errors.ts +32 -5
- package/src/core/hash.test.ts +8 -16
- package/src/core/hash.ts +3 -23
- package/src/core/lines.ts +2 -4
- package/src/core/ranges.test.ts +16 -8
- package/src/core/ranges.ts +10 -6
- package/src/core/regex.ts +3 -4
- package/src/core/replace.test.ts +47 -1
- package/src/core/replace.ts +19 -13
- package/src/core/search-analysis.test.ts +24 -27
- package/src/core/search-analysis.ts +34 -65
- package/src/core/search-matrix.testing.ts +0 -2
- package/src/core/search.ts +1 -1
- package/src/core/text.test.ts +5 -5
- package/src/core/text.ts +5 -12
- package/src/core/types.ts +7 -43
- package/src/integration/config-registration.test.ts +2 -2
- package/src/integration/fusion-dispatch.test.ts +2 -5
- package/src/integration/grep-flags.test.ts +0 -14
- package/src/integration/grep-js-completeness.test.ts +34 -8
- package/src/integration/grep-line-candidates.test.ts +4 -8
- package/src/integration/grep-matrix.test.ts +3 -7
- package/src/integration/grep-path-matrix.test.ts +5 -5
- package/src/integration/grep-prefilter-coverage.test.ts +3 -7
- package/src/integration/grep-process-limits.test.ts +78 -0
- package/src/integration/grep-rg.test.ts +123 -25
- package/src/integration/grep-scan-budget.test.ts +2 -2
- package/src/integration/grep-translation.test.ts +12 -27
- package/src/integration/large-text.test.ts +1 -47
- package/src/integration/model-budget-lifecycle.test.ts +13 -3
- package/src/integration/mutation-file-types.testing.ts +1 -1
- package/src/integration/npm-package.testing.ts +1 -1
- package/src/integration/publication-read-changes.test.ts +125 -47
- package/src/integration/replace-worker-boundary.test.ts +21 -11
- package/src/integration/report-replay.test.ts +21 -23
- package/src/integration/utf8-errors.test.ts +1 -1
- package/src/pi/AGENTS.md +16 -16
- package/src/pi/action-fusion.test.ts +168 -300
- package/src/pi/action-fusion.ts +148 -111
- package/src/pi/anchor-format.test.ts +9 -9
- package/src/pi/anchor-format.ts +6 -8
- package/src/pi/argument-diagnostics.ts +52 -207
- package/src/pi/argument-error.ts +2 -1
- package/src/pi/argument-format.test.ts +20 -22
- package/src/pi/argument-validation.test.ts +382 -418
- package/src/pi/argument-validation.ts +5 -8
- package/src/pi/budgets.ts +5 -4
- package/src/pi/config.test.ts +5 -2
- package/src/pi/config.ts +4 -6
- package/src/pi/diagnostic-buffer.test.ts +12 -1
- package/src/pi/diagnostic-buffer.ts +1 -2
- package/src/pi/directory-sync.test.ts +0 -1
- package/src/pi/edit-tool.ts +173 -226
- package/src/pi/error-text.ts +4 -8
- package/src/pi/execute.test.ts +165 -266
- package/src/pi/failure-context.test.ts +144 -126
- package/src/pi/failure-context.ts +45 -94
- package/src/pi/failure-path.test.ts +168 -141
- package/src/pi/file-commit.test.ts +110 -53
- package/src/pi/file-commit.ts +90 -137
- package/src/pi/file-snapshot.test.ts +3 -5
- package/src/pi/fusion-card.test.ts +4 -1
- package/src/pi/fusion-card.ts +16 -24
- package/src/pi/grep-candidates.test.ts +2 -101
- package/src/pi/grep-candidates.ts +23 -69
- package/src/pi/grep-matrix.test.ts +2 -2
- package/src/pi/grep-order.test.ts +4 -4
- package/src/pi/grep-output.ts +62 -96
- package/src/pi/grep-render.ts +1 -1
- package/src/pi/grep-reread.ts +92 -0
- package/src/pi/grep-scope.ts +40 -42
- package/src/pi/grep-search.ts +22 -31
- package/src/pi/grep-tool.ts +55 -82
- package/src/pi/grep.test.ts +81 -46
- package/src/pi/model-budgets.test.ts +25 -23
- package/src/pi/model-budgets.ts +6 -38
- package/src/pi/mutation-result.test.ts +44 -35
- package/src/pi/mutation-result.ts +51 -20
- package/src/pi/mutation-runner.ts +126 -70
- package/src/pi/output-budgets.test.ts +38 -16
- package/src/pi/path.ts +1 -1
- package/src/pi/pi.test.ts +3 -1
- package/src/pi/read-tool.ts +5 -5
- package/src/pi/regex-worker-contract.ts +3 -13
- package/src/pi/regex-worker.ts +1 -10
- package/src/pi/registration.test.ts +82 -20
- package/src/pi/render.test.ts +79 -42
- package/src/pi/render.ts +69 -63
- package/src/pi/replace-regex.ts +14 -2
- package/src/pi/replace-tool.ts +22 -83
- package/src/pi/replace-worker.ts +1 -1
- package/src/pi/replace.test.ts +9 -5
- package/src/pi/report-cause.ts +3 -8
- package/src/pi/report-failure.testing.ts +1 -2
- package/src/pi/report-schema.ts +65 -81
- package/src/pi/report.test.ts +171 -25
- package/src/pi/report.ts +33 -87
- package/src/pi/result-safety.test.ts +177 -189
- package/src/pi/rg-process.test.ts +77 -63
- package/src/pi/rg-process.ts +48 -64
- package/src/pi/rg-regex.ts +40 -400
- package/src/pi/schema.ts +12 -0
- package/src/pi/text-stream.test.ts +0 -21
- package/src/pi/text-stream.ts +14 -21
- package/src/pi/write-tool.ts +33 -62
- package/src/pi/write.test.ts +1 -3
- package/src/testing/regex-translation-corpus.ts +12 -12
- package/src/pi/replace-worker-contract.ts +0 -10
package/src/pi/write-tool.ts
CHANGED
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import { Type, type Static } from "typebox";
|
|
2
|
-
import type { AgentToolResult
|
|
2
|
+
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
3
3
|
import { Text } from "@earendil-works/pi-tui";
|
|
4
4
|
import {
|
|
5
5
|
createWriteToolDefinition,
|
|
6
|
-
type ExtensionToolContext,
|
|
7
6
|
type Theme,
|
|
8
7
|
type ToolRenderResultOptions,
|
|
9
8
|
} from "@earendil-works/pi-coding-agent";
|
|
10
|
-
import {
|
|
11
|
-
ACTION_FUSION_GUIDELINES,
|
|
12
|
-
withThenRunDescription,
|
|
13
|
-
withThenRunSchema,
|
|
14
|
-
type ThenRunInput,
|
|
15
|
-
} from "./action-fusion.ts";
|
|
16
9
|
import { commitFile } from "./file-commit.ts";
|
|
17
|
-
import {
|
|
10
|
+
import { mutationToolBase, type ActionFusionExecutor } from "./mutation-runner.ts";
|
|
18
11
|
import { throwIfCancelled } from "./error-text.ts";
|
|
19
|
-
import { createArgumentPreparer } from "./argument-validation.ts";
|
|
20
12
|
import { defaultOutputBudgets, type OutputBudgetProvider } from "./budgets.ts";
|
|
21
13
|
import { unwritableTextError } from "../core/text.ts";
|
|
22
|
-
import { reportLines, renderToolError, splitReport } from "./render.ts";
|
|
23
|
-
import type {
|
|
14
|
+
import { MUTATION_CARD_SHOWN, reportLines, renderToolError, splitReport } from "./render.ts";
|
|
15
|
+
import type { MutationOutcome } from "./mutation-result.ts";
|
|
24
16
|
import type { ReportDetails } from "./report.ts";
|
|
25
17
|
|
|
26
18
|
const writeSchema = Type.Object(
|
|
@@ -37,12 +29,11 @@ const writeSchema = Type.Object(
|
|
|
37
29
|
{ additionalProperties: false },
|
|
38
30
|
);
|
|
39
31
|
|
|
40
|
-
type WriteParams = Static<typeof writeSchema
|
|
32
|
+
type WriteParams = Static<typeof writeSchema>;
|
|
41
33
|
/** write shows the built-in card; its report states every fact. */
|
|
42
34
|
type WriteMutationDetails = object;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const WRITE_CARD_SHOWN = new Set(["publication", "created", "then_run", "progressError"]);
|
|
35
|
+
/** The write card's call line shows the content. */
|
|
36
|
+
const WRITE_CARD_SHOWN = new Set([...MUTATION_CARD_SHOWN, "publication", "created"]);
|
|
46
37
|
type WriteRenderContext = Parameters<
|
|
47
38
|
NonNullable<ReturnType<typeof createWriteToolDefinition>["renderCall"]>
|
|
48
39
|
>[2];
|
|
@@ -52,29 +43,38 @@ export function makeWriteOverride(
|
|
|
52
43
|
fusion?: ActionFusionExecutor,
|
|
53
44
|
budgets: OutputBudgetProvider = defaultOutputBudgets,
|
|
54
45
|
) {
|
|
55
|
-
const parameters = withThenRunSchema(writeSchema, "write", fusion !== undefined);
|
|
56
46
|
const builtin = createWriteToolDefinition(cwd);
|
|
57
47
|
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"write",
|
|
69
|
-
parameters,
|
|
70
|
-
(args, report) => {
|
|
48
|
+
...mutationToolBase({
|
|
49
|
+
tool: "write",
|
|
50
|
+
cwd,
|
|
51
|
+
fusion,
|
|
52
|
+
budgets,
|
|
53
|
+
schema: writeSchema,
|
|
54
|
+
description:
|
|
55
|
+
"Write a whole file exactly as supplied, including its line endings. Do not use write for partial changes to an existing file; use edit or replace. Choose create for a new file or overwrite for an existing file. Creates missing parent directories.",
|
|
56
|
+
promptSnippet: "Write complete file content to a path",
|
|
57
|
+
check: (args, report) => {
|
|
71
58
|
const content = (args as { content?: unknown } | null)?.content;
|
|
72
59
|
const unwritable = typeof content === "string" ? unwritableTextError(content) : undefined;
|
|
73
60
|
if (unwritable) report("content", unwritable.message);
|
|
74
61
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
async run(
|
|
63
|
+
params,
|
|
64
|
+
{ absolutePath, signal },
|
|
65
|
+
): Promise<MutationOutcome<WriteMutationDetails, "write">> {
|
|
66
|
+
throwIfCancelled(signal);
|
|
67
|
+
const commit = await commitFile(absolutePath, params.content, {
|
|
68
|
+
mode: params.mode,
|
|
69
|
+
signal,
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
commit,
|
|
73
|
+
details: {},
|
|
74
|
+
facts: commit.created ? { created: true } : {},
|
|
75
|
+
};
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
78
|
renderCall(args: WriteParams, theme: Theme, context: WriteRenderContext) {
|
|
79
79
|
return builtin.renderCall!(args, theme, context);
|
|
80
80
|
},
|
|
@@ -90,34 +90,5 @@ export function makeWriteOverride(
|
|
|
90
90
|
if (facts.length) return new Text(facts.join("\n"), 0, 0);
|
|
91
91
|
return builtin.renderResult!({ ...result, details: undefined }, options, theme, context);
|
|
92
92
|
},
|
|
93
|
-
async execute(
|
|
94
|
-
toolCallId: string,
|
|
95
|
-
params: WriteParams,
|
|
96
|
-
signal: AbortSignal | undefined,
|
|
97
|
-
onUpdate: AgentToolUpdateCallback<WriteDetails> | undefined,
|
|
98
|
-
ctx: ExtensionToolContext,
|
|
99
|
-
) {
|
|
100
|
-
return executeMutation<WriteParams, WriteMutationDetails, "write">(
|
|
101
|
-
{
|
|
102
|
-
tool: "write",
|
|
103
|
-
cwd,
|
|
104
|
-
fusion,
|
|
105
|
-
budgets,
|
|
106
|
-
async run(mutationParams, { absolutePath, signal }) {
|
|
107
|
-
throwIfCancelled(signal);
|
|
108
|
-
const commit = await commitFile(absolutePath, mutationParams.content, {
|
|
109
|
-
mode: mutationParams.mode,
|
|
110
|
-
signal,
|
|
111
|
-
});
|
|
112
|
-
return {
|
|
113
|
-
commit,
|
|
114
|
-
details: {},
|
|
115
|
-
facts: commit.created ? { created: true } : {},
|
|
116
|
-
};
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
{ toolCallId, params, signal, onUpdate, ctx },
|
|
120
|
-
);
|
|
121
|
-
},
|
|
122
93
|
};
|
|
123
94
|
}
|
package/src/pi/write.test.ts
CHANGED
|
@@ -43,8 +43,6 @@ test("write rejects unwritable content before accessing a missing target", async
|
|
|
43
43
|
withTemp(async (dir) => {
|
|
44
44
|
const file = join(dir, "missing.txt");
|
|
45
45
|
const tool = makeWriteOverride(dir);
|
|
46
|
-
const valid = { path: file, content: "ready\n", mode: "create" };
|
|
47
|
-
assert.equal(tool.prepareArguments(valid), valid);
|
|
48
46
|
for (const [content, expected] of [
|
|
49
47
|
["bad\0", rejectsArgument("content", /NUL/)],
|
|
50
48
|
["\ud800", rejectsArgument("content", /encoded losslessly/)],
|
|
@@ -236,7 +234,7 @@ test("write reports missing freshness when then_run removes the target", async (
|
|
|
236
234
|
context(dir),
|
|
237
235
|
);
|
|
238
236
|
assert.equal(reportOf(result, "write")?.freshness, "missing");
|
|
239
|
-
assert.equal(reportOf(result, "write")?.next,
|
|
237
|
+
assert.equal(reportOf(result, "write")?.next, undefined);
|
|
240
238
|
}));
|
|
241
239
|
|
|
242
240
|
test("write preserves command failure and changed freshness", async () =>
|
|
@@ -29,7 +29,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
29
29
|
flags: "",
|
|
30
30
|
hits: ["b", "z"],
|
|
31
31
|
misses: ["a", "A"],
|
|
32
|
-
rejectCandidates:
|
|
32
|
+
rejectCandidates: false,
|
|
33
33
|
source: local,
|
|
34
34
|
},
|
|
35
35
|
{
|
|
@@ -37,7 +37,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
37
37
|
flags: "",
|
|
38
38
|
hits: ["ab"],
|
|
39
39
|
misses: ["ac", "ad"],
|
|
40
|
-
rejectCandidates:
|
|
40
|
+
rejectCandidates: false,
|
|
41
41
|
source: local,
|
|
42
42
|
},
|
|
43
43
|
{
|
|
@@ -45,7 +45,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
45
45
|
flags: "",
|
|
46
46
|
hits: ["b"],
|
|
47
47
|
misses: ["a", "c"],
|
|
48
|
-
rejectCandidates:
|
|
48
|
+
rejectCandidates: false,
|
|
49
49
|
source: local,
|
|
50
50
|
},
|
|
51
51
|
{
|
|
@@ -53,7 +53,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
53
53
|
flags: "",
|
|
54
54
|
hits: ["ac", "ba"],
|
|
55
55
|
misses: ["ab"],
|
|
56
|
-
rejectCandidates:
|
|
56
|
+
rejectCandidates: false,
|
|
57
57
|
source: local,
|
|
58
58
|
},
|
|
59
59
|
{
|
|
@@ -61,7 +61,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
61
61
|
flags: "",
|
|
62
62
|
hits: ["ac", "ba"],
|
|
63
63
|
misses: ["ab"],
|
|
64
|
-
rejectCandidates:
|
|
64
|
+
rejectCandidates: false,
|
|
65
65
|
source: local,
|
|
66
66
|
},
|
|
67
67
|
{
|
|
@@ -69,7 +69,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
69
69
|
flags: "u",
|
|
70
70
|
hits: ["a", "ſ"],
|
|
71
71
|
misses: ["k", "K", "K"],
|
|
72
|
-
rejectCandidates:
|
|
72
|
+
rejectCandidates: false,
|
|
73
73
|
source: local,
|
|
74
74
|
},
|
|
75
75
|
{
|
|
@@ -85,7 +85,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
85
85
|
flags: "iu",
|
|
86
86
|
hits: ["k ", "K "],
|
|
87
87
|
misses: ["kk", "Kk"],
|
|
88
|
-
rejectCandidates:
|
|
88
|
+
rejectCandidates: false,
|
|
89
89
|
source: local,
|
|
90
90
|
},
|
|
91
91
|
{
|
|
@@ -93,7 +93,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
93
93
|
flags: "",
|
|
94
94
|
hits: ["\rb"],
|
|
95
95
|
misses: ["ab"],
|
|
96
|
-
rejectCandidates:
|
|
96
|
+
rejectCandidates: false,
|
|
97
97
|
source: local,
|
|
98
98
|
},
|
|
99
99
|
{
|
|
@@ -141,7 +141,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
141
141
|
flags: "",
|
|
142
142
|
hits: ["catcat", "dogdog"],
|
|
143
143
|
misses: ["catdog", "dogcat"],
|
|
144
|
-
rejectCandidates:
|
|
144
|
+
rejectCandidates: false,
|
|
145
145
|
source: local,
|
|
146
146
|
},
|
|
147
147
|
{
|
|
@@ -149,7 +149,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
149
149
|
flags: "",
|
|
150
150
|
hits: ["aa", "bcbc"],
|
|
151
151
|
misses: ["abc", "bca"],
|
|
152
|
-
rejectCandidates:
|
|
152
|
+
rejectCandidates: false,
|
|
153
153
|
source: local,
|
|
154
154
|
},
|
|
155
155
|
{
|
|
@@ -165,7 +165,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
165
165
|
flags: "v",
|
|
166
166
|
hits: ["KsKs", "abab"],
|
|
167
167
|
misses: ["Ksks", "abAB"],
|
|
168
|
-
rejectCandidates:
|
|
168
|
+
rejectCandidates: false,
|
|
169
169
|
source: local,
|
|
170
170
|
},
|
|
171
171
|
{
|
|
@@ -214,7 +214,7 @@ export const REGEX_TRANSLATION_CORPUS: readonly RegexWitness[] = [
|
|
|
214
214
|
flags: "v",
|
|
215
215
|
hits: [`prefix${"a".repeat(300)}suffix`, `prefix${"b".repeat(300)}suffix`],
|
|
216
216
|
misses: ["wrong", "prefixwrong", "wrongsuffix"],
|
|
217
|
-
rejectCandidates:
|
|
217
|
+
rejectCandidates: false,
|
|
218
218
|
source: local,
|
|
219
219
|
},
|
|
220
220
|
{
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/** Replacement worker request and reply decoder; shared worker errors are checked by the host. */
|
|
2
|
-
import { workerReplyDecoder } from "./regex-worker-contract.ts";
|
|
3
|
-
import { REPLACEMENT_RESULT_SCHEMA, type Replacement } from "../core/replace-schema.ts";
|
|
4
|
-
|
|
5
|
-
export interface ReplacementRequest {
|
|
6
|
-
readonly source: string;
|
|
7
|
-
readonly rules: readonly Replacement[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const decodeWorkerReply = workerReplyDecoder(REPLACEMENT_RESULT_SCHEMA);
|