@criogaid/pi-hashline-edit 0.7.0 → 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 +74 -222
- package/README.zh-CN.md +162 -0
- package/package.json +2 -1
- package/src/core/AGENTS.md +1 -1
- package/src/core/apply.test.ts +172 -134
- package/src/core/apply.ts +28 -30
- package/src/core/case-fold.test.ts +11 -7
- package/src/core/case-fold.ts +2 -6
- package/src/core/character-set.ts +14 -0
- package/src/core/hash.test.ts +1 -25
- package/src/core/hash.ts +0 -5
- package/src/core/lines.ts +25 -7
- package/src/core/ranges.test.ts +41 -9
- package/src/core/ranges.ts +11 -4
- package/src/core/regex.ts +36 -6
- package/src/core/replace-schema.ts +18 -11
- package/src/core/replace.test.ts +90 -0
- package/src/core/replace.ts +6 -5
- package/src/core/search-analysis.test.ts +9 -0
- package/src/core/search-analysis.ts +35 -31
- package/src/core/search.ts +1 -1
- package/src/core/types.ts +5 -7
- package/src/index.ts +2 -4
- package/src/integration/config-registration.test.ts +16 -8
- package/src/integration/fusion-dispatch.test.ts +41 -22
- package/src/integration/grep-flags.test.ts +6 -13
- package/src/integration/grep-js-completeness.test.ts +41 -31
- package/src/integration/grep-order.test.ts +78 -0
- package/src/integration/grep-path-matrix.test.ts +4 -3
- package/src/integration/grep-regex.test.ts +13 -16
- package/src/integration/grep-rg.test.ts +127 -87
- package/src/integration/grep-scan-budget.test.ts +27 -5
- package/src/integration/large-text.test.ts +3 -4
- package/src/integration/model-budget-lifecycle.test.ts +15 -6
- package/src/integration/mutation-file-types.test.ts +0 -1
- package/src/integration/mutation-file-types.testing.ts +1 -1
- package/src/integration/npm-package.testing.ts +6 -32
- package/src/integration/publication-read-changes.test.ts +58 -26
- package/src/integration/replace-package.testing.ts +4 -1
- package/src/integration/replace-worker-boundary.test.ts +34 -24
- package/src/integration/report-replay.test.ts +2 -2
- package/src/integration/utf8-errors.test.ts +2 -2
- package/src/pi/AGENTS.md +12 -13
- package/src/pi/action-fusion.test.ts +71 -216
- package/src/pi/action-fusion.ts +37 -74
- package/src/pi/anchor-format.test.ts +16 -0
- package/src/pi/anchor-format.ts +7 -3
- package/src/pi/argument-diagnostics.ts +1 -1
- package/src/pi/argument-error.testing.ts +7 -4
- package/src/pi/argument-error.ts +5 -7
- package/src/pi/argument-format.test.ts +5 -16
- package/src/pi/argument-validation.test.ts +59 -25
- package/src/pi/argument-validation.ts +4 -5
- package/src/pi/budgets.ts +5 -7
- package/src/pi/config.test.ts +15 -5
- package/src/pi/config.ts +6 -6
- package/src/pi/diagnostic-buffer.test.ts +2 -3
- package/src/pi/diagnostic-buffer.ts +2 -2
- package/src/pi/edit-tool.ts +9 -12
- package/src/pi/execute.test.ts +80 -149
- package/src/pi/failure-context.test.ts +61 -16
- package/src/pi/failure-context.ts +12 -9
- package/src/pi/failure-path.test.ts +115 -50
- package/src/pi/file-commit.test.ts +30 -46
- package/src/pi/file-commit.ts +11 -40
- package/src/pi/file-revision.ts +25 -0
- package/src/pi/fusion-card-interaction.test.ts +143 -0
- package/src/pi/fusion-card.test.ts +193 -37
- package/src/pi/fusion-card.ts +186 -116
- package/src/pi/grep-candidates.ts +25 -27
- package/src/pi/grep-matrix.test.ts +1 -1
- package/src/pi/grep-order.test.ts +323 -0
- package/src/pi/grep-output.testing.ts +24 -0
- package/src/pi/grep-output.ts +62 -69
- package/src/pi/grep-render.ts +4 -1
- package/src/pi/grep-scope.ts +1 -1
- package/src/pi/grep-search.ts +85 -56
- package/src/pi/grep-tool.ts +17 -48
- package/src/pi/grep.test.ts +270 -169
- package/src/pi/mutation-outcome.testing.ts +2 -3
- package/src/pi/mutation-result.test.ts +26 -19
- package/src/pi/mutation-result.ts +25 -40
- package/src/pi/mutation-runner.ts +9 -17
- package/src/pi/output-budgets.test.ts +25 -16
- package/src/pi/path.ts +3 -1
- package/src/pi/pi.test.ts +4 -5
- package/src/pi/read-tool.ts +32 -80
- package/src/pi/read.test.ts +145 -92
- package/src/pi/regex-worker-contract.ts +5 -23
- package/src/pi/regex-worker.ts +4 -10
- package/src/pi/registration.test.ts +54 -49
- package/src/pi/render.test.ts +196 -93
- package/src/pi/render.ts +32 -22
- package/src/pi/replace-regex.ts +3 -5
- package/src/pi/replace-tool.ts +27 -26
- package/src/pi/replace-worker-contract.ts +3 -12
- package/src/pi/replace.test.ts +144 -226
- package/src/pi/report-cause.ts +23 -19
- package/src/pi/report-failure.testing.ts +2 -2
- package/src/pi/report-schema.ts +55 -43
- package/src/pi/report.test.ts +138 -71
- package/src/pi/report.ts +40 -43
- package/src/pi/result-safety.test.ts +157 -117
- package/src/pi/rg-process.test.ts +36 -10
- package/src/pi/rg-process.ts +9 -3
- package/src/pi/rg-regex.test.ts +17 -0
- package/src/pi/rg-regex.ts +28 -22
- package/src/pi/text-stream.test.ts +35 -36
- package/src/pi/text-stream.ts +14 -14
- package/src/pi/tool-call.testing.ts +17 -7
- package/src/pi/write-tool.ts +9 -11
- package/src/pi/write.test.ts +43 -75
- package/src/testing/regex-translation-corpus.ts +16 -0
- package/src/testing/rg-line-listing.fixture.mjs +1 -1
- package/src/integration/forget-grep.test.ts +0 -148
- package/src/pi/forget-tool.ts +0 -367
- package/src/pi/forget.test.ts +0 -630
- package/src/pi/forget.testing.ts +0 -201
package/src/pi/replace-tool.ts
CHANGED
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* lines belongs to `edit`.
|
|
10
10
|
*
|
|
11
11
|
* - Both modes match the shared LF view and restore original line separators.
|
|
12
|
-
* -
|
|
12
|
+
* - Each rule states `literal`: literal mode keeps `$` verbatim; regex mode expands
|
|
13
|
+
* JavaScript replacement tokens.
|
|
13
14
|
* - `flags` adds regex flags in either mode; `g` is always forced so every
|
|
14
15
|
* occurrence is replaced. `i` (case-insensitive), `m` (per-line ^/$),
|
|
15
16
|
* `s` (dotall), `u` (unicode) all work.
|
|
@@ -32,8 +33,8 @@ import {
|
|
|
32
33
|
import type { AgentToolUpdateCallback } from "@earendil-works/pi-agent-core";
|
|
33
34
|
import { Type, type Static } from "typebox";
|
|
34
35
|
import { applyReplacements } from "../core/replace.ts";
|
|
35
|
-
import {
|
|
36
|
-
import { REPLACEMENTS_SCHEMA
|
|
36
|
+
import { checkRegexArguments } from "../core/regex.ts";
|
|
37
|
+
import { REPLACEMENTS_SCHEMA } from "../core/replace-schema.ts";
|
|
37
38
|
import { runRegexReplacements } from "./replace-regex.ts";
|
|
38
39
|
import { unwritableTextError } from "../core/text.ts";
|
|
39
40
|
import {
|
|
@@ -57,7 +58,6 @@ import {
|
|
|
57
58
|
type TextMutationDetails,
|
|
58
59
|
} from "./mutation-runner.ts";
|
|
59
60
|
import type { MutationResultDetails } from "./mutation-result.ts";
|
|
60
|
-
import { errorMessage } from "../core/errors.ts";
|
|
61
61
|
import { defaultOutputBudgets, type OutputBudgetProvider } from "./budgets.ts";
|
|
62
62
|
import {
|
|
63
63
|
argumentItems,
|
|
@@ -80,9 +80,6 @@ const replaceSchema = Type.Object(
|
|
|
80
80
|
{ additionalProperties: false },
|
|
81
81
|
);
|
|
82
82
|
|
|
83
|
-
function createReplaceSchema(actionFusion: boolean) {
|
|
84
|
-
return withThenRunSchema(replaceSchema, "replace", actionFusion);
|
|
85
|
-
}
|
|
86
83
|
type ReplaceParams = Static<typeof replaceSchema> & { then_run?: ThenRunInput };
|
|
87
84
|
|
|
88
85
|
/** Call-header line: `replace path — N rules`, plus `+N -N` once diff counts are known. */
|
|
@@ -95,26 +92,22 @@ function replaceHeader(args: ReplaceParams, theme: Theme, counts?: DiffCounts):
|
|
|
95
92
|
return t;
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
/** Report unwritable replacement text and regex compile errors; Pi checks field shapes. */
|
|
95
|
+
/** Report unwritable replacement text, flags V8 rejects, and regex compile errors; Pi checks field shapes. */
|
|
99
96
|
function checkReplaceArguments(args: unknown, report: ReportArgumentIssue): void {
|
|
100
97
|
const rules = argumentItems((args as { replacements?: unknown } | null)?.replacements);
|
|
101
|
-
const validFlags = new RegExp(REGEX_FLAGS_PATTERN);
|
|
102
98
|
rules.forEach((rule, index) => {
|
|
103
|
-
const { find, replace,
|
|
99
|
+
const { find, replace, literal, flags } = (rule ?? {}) as Record<string, unknown>;
|
|
104
100
|
const unwritable = typeof replace === "string" ? unwritableTextError(replace) : undefined;
|
|
105
101
|
if (unwritable) report(`replacements[${index}].replace`, unwritable.message);
|
|
106
|
-
if (
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
report(`replacements[${index}].find`, errorMessage(error));
|
|
116
|
-
}
|
|
117
|
-
}
|
|
102
|
+
if (flags !== undefined && typeof flags !== "string") return;
|
|
103
|
+
const item = `replacements[${index}]`;
|
|
104
|
+
checkRegexArguments(
|
|
105
|
+
`${item}.flags`,
|
|
106
|
+
flags,
|
|
107
|
+
literal !== false,
|
|
108
|
+
[[`${item}.find`, find]],
|
|
109
|
+
report,
|
|
110
|
+
);
|
|
118
111
|
});
|
|
119
112
|
}
|
|
120
113
|
|
|
@@ -124,12 +117,12 @@ export function makeReplaceTool(
|
|
|
124
117
|
fusion?: ActionFusionExecutor,
|
|
125
118
|
budgets: OutputBudgetProvider = defaultOutputBudgets,
|
|
126
119
|
) {
|
|
127
|
-
const parameters =
|
|
120
|
+
const parameters = withThenRunSchema(replaceSchema, "replace", fusion !== undefined);
|
|
128
121
|
return {
|
|
129
122
|
name: "replace" as const,
|
|
130
123
|
label: "replace",
|
|
131
124
|
description: withThenRunDescription(
|
|
132
|
-
"Replace every match of one or more literal or JavaScript-regex rules in a file. Rules swap only their matched fragments in one call, without line anchors. Use edit instead for inserting, deleting, or rewriting whole lines. Overlapping matches or a rule with no match reject the whole call.
|
|
125
|
+
"Replace every match of one or more literal or JavaScript-regex rules in a file. Rules swap only their matched fragments in one call, without line anchors. Use edit instead for inserting, deleting, or rewriting whole lines. Overlapping matches or a rule with no match reject the whole call.",
|
|
133
126
|
fusion !== undefined,
|
|
134
127
|
),
|
|
135
128
|
promptSnippet: "Replace matching text across a file",
|
|
@@ -148,7 +141,15 @@ export function makeReplaceTool(
|
|
|
148
141
|
theme: Theme,
|
|
149
142
|
context: ReplaceRenderContext,
|
|
150
143
|
) {
|
|
151
|
-
return renderMutationResult(
|
|
144
|
+
return renderMutationResult(
|
|
145
|
+
result,
|
|
146
|
+
options,
|
|
147
|
+
theme,
|
|
148
|
+
context,
|
|
149
|
+
"Replacing…",
|
|
150
|
+
replaceHeader,
|
|
151
|
+
"replace",
|
|
152
|
+
);
|
|
152
153
|
},
|
|
153
154
|
|
|
154
155
|
async execute(
|
|
@@ -179,7 +180,7 @@ function runReplace(
|
|
|
179
180
|
) {
|
|
180
181
|
return runTextMutation<"replace">(target, async (currentText) => {
|
|
181
182
|
// The regex worker reports its own cancellation; a literal batch runs synchronously.
|
|
182
|
-
const { text, count } = rules.some((rule) => rule.
|
|
183
|
+
const { text, count } = rules.some((rule) => !rule.literal)
|
|
183
184
|
? await runRegexReplacements(currentText, rules, config.replace.regexTimeoutMs, target.signal)
|
|
184
185
|
: applyReplacements(currentText, rules);
|
|
185
186
|
return { text, facts: { matches: count } };
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
/** Replacement
|
|
2
|
-
import { Type } from "typebox";
|
|
1
|
+
/** Replacement worker request and reply decoder; shared worker errors are checked by the host. */
|
|
3
2
|
import { workerReplyDecoder } from "./regex-worker-contract.ts";
|
|
4
|
-
import type
|
|
3
|
+
import { REPLACEMENT_RESULT_SCHEMA, type Replacement } from "../core/replace-schema.ts";
|
|
5
4
|
|
|
6
5
|
export interface ReplacementRequest {
|
|
7
6
|
readonly source: string;
|
|
8
7
|
readonly rules: readonly Replacement[];
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
export const decodeWorkerReply = workerReplyDecoder(
|
|
12
|
-
Type.Object(
|
|
13
|
-
{
|
|
14
|
-
text: Type.String(),
|
|
15
|
-
count: Type.Integer({ minimum: 1 }),
|
|
16
|
-
},
|
|
17
|
-
{ additionalProperties: false },
|
|
18
|
-
),
|
|
19
|
-
);
|
|
10
|
+
export const decodeWorkerReply = workerReplyDecoder(REPLACEMENT_RESULT_SCHEMA);
|