@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/fusion-card.ts
CHANGED
|
@@ -10,51 +10,32 @@ import type {
|
|
|
10
10
|
ExtensionContext,
|
|
11
11
|
ToolDefinition,
|
|
12
12
|
} from "@earendil-works/pi-coding-agent";
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
import {
|
|
14
|
+
createBashToolDefinition,
|
|
15
|
+
SettingsManager,
|
|
16
|
+
ToolExecutionComponent,
|
|
17
|
+
} from "@earendil-works/pi-coding-agent";
|
|
18
|
+
import {
|
|
19
|
+
Box,
|
|
20
|
+
Container,
|
|
21
|
+
Text,
|
|
22
|
+
type Component,
|
|
23
|
+
type TUI,
|
|
24
|
+
type TuiMouseEvent,
|
|
25
|
+
} from "@earendil-works/pi-tui";
|
|
26
|
+
import type { TSchema } from "typebox";
|
|
16
27
|
import { Value } from "typebox/value";
|
|
17
28
|
import { ACTION_FUSION_PROGRESS_SCHEMA } from "./report-schema.ts";
|
|
18
29
|
import type { ActionFusionProgress } from "./action-fusion.ts";
|
|
30
|
+
import { commandText } from "./mutation-result.ts";
|
|
19
31
|
import type { MutationRenderState } from "./render.ts";
|
|
20
32
|
|
|
21
33
|
const CARD_TYPE = "hashline-then-run";
|
|
22
34
|
const RESULT_TYPE = "hashline-then-run-result";
|
|
23
35
|
|
|
24
|
-
|
|
25
|
-
const COMMAND_CARD_SCHEMA =
|
|
26
|
-
|
|
27
|
-
toolCallId: CARD_PROPERTIES.toolCallId,
|
|
28
|
-
commandText: CARD_PROPERTIES.commandText,
|
|
29
|
-
command: CARD_PROPERTIES.command,
|
|
30
|
-
output: CARD_PROPERTIES.output,
|
|
31
|
-
timing: CARD_PROPERTIES.timing,
|
|
32
|
-
mutationCompleted: CARD_PROPERTIES.mutationCompleted,
|
|
33
|
-
freshness: CARD_PROPERTIES.freshness,
|
|
34
|
-
},
|
|
35
|
-
{ additionalProperties: false },
|
|
36
|
-
);
|
|
37
|
-
type CommandCardData = Static<typeof COMMAND_CARD_SCHEMA>;
|
|
38
|
-
|
|
39
|
-
function commandCardData({
|
|
40
|
-
toolCallId,
|
|
41
|
-
commandText,
|
|
42
|
-
command,
|
|
43
|
-
output,
|
|
44
|
-
timing,
|
|
45
|
-
mutationCompleted,
|
|
46
|
-
freshness,
|
|
47
|
-
}: ActionFusionProgress): CommandCardData {
|
|
48
|
-
return {
|
|
49
|
-
toolCallId,
|
|
50
|
-
commandText,
|
|
51
|
-
command,
|
|
52
|
-
output,
|
|
53
|
-
mutationCompleted,
|
|
54
|
-
freshness,
|
|
55
|
-
...(timing ? { timing } : {}),
|
|
56
|
-
};
|
|
57
|
-
}
|
|
36
|
+
/** A command card persists its progress as is; restored entries are checked against the same schema. */
|
|
37
|
+
const COMMAND_CARD_SCHEMA = ACTION_FUSION_PROGRESS_SCHEMA;
|
|
38
|
+
type CommandCardData = ActionFusionProgress;
|
|
58
39
|
|
|
59
40
|
const TARGET_STATE = {
|
|
60
41
|
changed: "the target changed after the mutation",
|
|
@@ -67,24 +48,57 @@ const TARGET_STATE = {
|
|
|
67
48
|
* states: whether the mutation completed and the target's freshness.
|
|
68
49
|
*/
|
|
69
50
|
function notRunReason(card: CommandCardData): string | undefined {
|
|
70
|
-
if (card.command === "cancelled" && !card.
|
|
51
|
+
if (card.command === "cancelled" && !(card.result && commandText(card.result.content)))
|
|
52
|
+
return "Not run: cancelled.";
|
|
71
53
|
if (card.command !== "skipped") return undefined;
|
|
72
54
|
const { mutationCompleted, freshness } = card;
|
|
73
55
|
if (!mutationCompleted) return "Not run: the mutation did not complete.";
|
|
74
56
|
return freshness === "unchanged" ? undefined : `Not run: ${TARGET_STATE[freshness]}.`;
|
|
75
57
|
}
|
|
76
58
|
|
|
59
|
+
/** Adapt Pi's tool row spacing to the spacer already owned by a custom entry. */
|
|
60
|
+
class CommandEntryComponent extends ToolExecutionComponent {
|
|
61
|
+
private globalExpanded?: boolean;
|
|
62
|
+
private readonly refresh: () => void;
|
|
63
|
+
|
|
64
|
+
constructor(
|
|
65
|
+
refresh: (card: ToolExecutionComponent) => void,
|
|
66
|
+
...args: ConstructorParameters<typeof ToolExecutionComponent>
|
|
67
|
+
) {
|
|
68
|
+
super(...args);
|
|
69
|
+
this.refresh = () => refresh(this);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setGlobalExpanded(expanded: boolean) {
|
|
73
|
+
if (this.globalExpanded === expanded) return;
|
|
74
|
+
this.globalExpanded = expanded;
|
|
75
|
+
this.setExpanded(expanded);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
override render(width: number) {
|
|
79
|
+
this.refresh();
|
|
80
|
+
return super.render(width).slice(1);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
override handleMouse(event: TuiMouseEvent) {
|
|
84
|
+
return super.handleMouse({ ...event, y: event.y + 1, height: event.height + 1 });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
77
88
|
/** Render one durable transcript card per fused command without adding model context. */
|
|
78
89
|
export function registerFusionCards(pi: ExtensionAPI) {
|
|
79
90
|
let currentCwd = process.cwd();
|
|
80
91
|
const bash = createBashToolDefinition(process.cwd());
|
|
81
92
|
const states = new Map<string, CommandCardData>();
|
|
82
93
|
const active = new Set<string>();
|
|
94
|
+
const cards = new Map<string, CommandEntryComponent>();
|
|
95
|
+
let tui: TUI | undefined;
|
|
83
96
|
|
|
84
97
|
const restore = (ctx: ExtensionContext) => {
|
|
85
98
|
if (ctx.cwd) currentCwd = ctx.cwd;
|
|
86
99
|
states.clear();
|
|
87
100
|
active.clear();
|
|
101
|
+
cards.clear();
|
|
88
102
|
for (const entry of ctx.sessionManager.getBranch()) {
|
|
89
103
|
if (
|
|
90
104
|
entry.type !== "custom" ||
|
|
@@ -95,98 +109,154 @@ export function registerFusionCards(pi: ExtensionAPI) {
|
|
|
95
109
|
if (Value.Check(COMMAND_CARD_SCHEMA, data)) states.set(data.toolCallId, data);
|
|
96
110
|
}
|
|
97
111
|
};
|
|
98
|
-
pi.on("session_start", (_event, ctx) =>
|
|
112
|
+
pi.on("session_start", (_event, ctx) => {
|
|
113
|
+
restore(ctx);
|
|
114
|
+
tui = undefined;
|
|
115
|
+
if (ctx.mode !== "tui") return;
|
|
116
|
+
// The public widget factory supplies the session TUI without changing its header or editor.
|
|
117
|
+
const bridge = "hashline-then-run-ui";
|
|
118
|
+
ctx.ui.setWidget(
|
|
119
|
+
bridge,
|
|
120
|
+
(sessionTui) => {
|
|
121
|
+
tui = sessionTui;
|
|
122
|
+
return new Container();
|
|
123
|
+
},
|
|
124
|
+
{ placement: "belowEditor" },
|
|
125
|
+
);
|
|
126
|
+
ctx.ui.setWidget(bridge, undefined);
|
|
127
|
+
});
|
|
99
128
|
pi.on("session_tree", (_event, ctx) => restore(ctx));
|
|
100
129
|
|
|
101
|
-
pi.registerEntryRenderer<CommandCardData>(CARD_TYPE, (entry, { expanded }
|
|
130
|
+
pi.registerEntryRenderer<CommandCardData>(CARD_TYPE, function renderCard(entry, { expanded }):
|
|
131
|
+
| Component
|
|
132
|
+
| undefined {
|
|
102
133
|
const initial = entry.data;
|
|
103
134
|
if (!Value.Check(COMMAND_CARD_SCHEMA, initial)) return undefined;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
call = bash.renderCall!(context.args, theme, { ...context, lastComponent: call });
|
|
160
|
-
box.clear();
|
|
161
|
-
box.addChild(statusText);
|
|
162
|
-
box.addChild(call);
|
|
163
|
-
const reason = notRunReason(current);
|
|
164
|
-
if (reason) box.addChild(new Text(theme.fg("dim", reason), 0, 0));
|
|
165
|
-
if (current.output || current.command === "succeeded" || failed) {
|
|
166
|
-
result = bash.renderResult!(
|
|
167
|
-
{ content: [{ type: "text", text: current.output }], details: undefined },
|
|
168
|
-
{ expanded, isPartial: context.isPartial },
|
|
169
|
-
theme,
|
|
170
|
-
{ ...context, lastComponent: result },
|
|
135
|
+
if (!tui) {
|
|
136
|
+
// Pi may rebuild history before session_start supplies its UI context.
|
|
137
|
+
let component: Component | undefined;
|
|
138
|
+
const ready = () => (component ??= tui ? renderCard(entry, { expanded }) : undefined);
|
|
139
|
+
return {
|
|
140
|
+
render: (width) => ready()?.render(width) ?? [],
|
|
141
|
+
invalidate: () => component?.invalidate(),
|
|
142
|
+
handleMouse: (event) => ready()?.handleMouse?.(event),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
let card = cards.get(initial.toolCallId);
|
|
146
|
+
const settings = SettingsManager.inMemory(pi.getSettings());
|
|
147
|
+
if (!card) {
|
|
148
|
+
const current = () => states.get(initial.toolCallId) ?? initial;
|
|
149
|
+
const statusText = new Text("", 0, 0);
|
|
150
|
+
let outputPadding = settings.getOutputPad();
|
|
151
|
+
let box = new Box(outputPadding, 1);
|
|
152
|
+
let call: Component | undefined;
|
|
153
|
+
let result: Component | undefined;
|
|
154
|
+
const renderers: Pick<typeof bash, "renderShell" | "renderCall" | "renderResult"> = {
|
|
155
|
+
renderShell: "self",
|
|
156
|
+
renderCall(args, theme, context) {
|
|
157
|
+
const padding = SettingsManager.inMemory(pi.getSettings()).getOutputPad();
|
|
158
|
+
if (padding !== outputPadding) {
|
|
159
|
+
outputPadding = padding;
|
|
160
|
+
box = new Box(outputPadding, 1);
|
|
161
|
+
}
|
|
162
|
+
const value = current();
|
|
163
|
+
const pending = value.command === "waiting" || value.command === "running";
|
|
164
|
+
const interrupted = pending && !active.has(value.toolCallId);
|
|
165
|
+
const status = interrupted ? "interrupted (final status unknown)" : value.command;
|
|
166
|
+
const countdown =
|
|
167
|
+
value.command === "running" && !interrupted && value.timing
|
|
168
|
+
? ` · ${value.timing.remainingSeconds}s remaining`
|
|
169
|
+
: "";
|
|
170
|
+
const failed = value.command === "failed" || value.command === "timeout";
|
|
171
|
+
const color =
|
|
172
|
+
pending || value.command === "cancelled"
|
|
173
|
+
? "warning"
|
|
174
|
+
: failed
|
|
175
|
+
? "error"
|
|
176
|
+
: value.command === "succeeded"
|
|
177
|
+
? "success"
|
|
178
|
+
: "dim";
|
|
179
|
+
const background =
|
|
180
|
+
pending && !interrupted
|
|
181
|
+
? "toolPendingBg"
|
|
182
|
+
: failed
|
|
183
|
+
? "toolErrorBg"
|
|
184
|
+
: value.command === "succeeded"
|
|
185
|
+
? "toolSuccessBg"
|
|
186
|
+
: "customMessageBg";
|
|
187
|
+
box.setBgFn((line) => theme.bg(background, line));
|
|
188
|
+
statusText.setText(
|
|
189
|
+
`${theme.fg("toolTitle", theme.bold("then_run"))} · ${theme.fg(color, status + countdown)}`,
|
|
171
190
|
);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
191
|
+
call = bash.renderCall!(args, theme, { ...context, lastComponent: call });
|
|
192
|
+
box.clear();
|
|
193
|
+
box.addChild(statusText);
|
|
194
|
+
box.addChild(call);
|
|
195
|
+
const reason = notRunReason(value);
|
|
196
|
+
if (reason) box.addChild(new Text(theme.fg("dim", reason), 0, 0));
|
|
197
|
+
return box;
|
|
198
|
+
},
|
|
199
|
+
renderResult(value, options, theme, context) {
|
|
200
|
+
// Every command that ran or failed to start has a result; waiting and skipped ones do not.
|
|
201
|
+
if (current().result) {
|
|
202
|
+
result = bash.renderResult!(value, options, theme, {
|
|
203
|
+
...context,
|
|
204
|
+
lastComponent: result,
|
|
205
|
+
});
|
|
206
|
+
box.addChild(result);
|
|
207
|
+
}
|
|
208
|
+
return new Container();
|
|
209
|
+
},
|
|
210
|
+
};
|
|
211
|
+
let rendered: CommandCardData | undefined;
|
|
212
|
+
card = new CommandEntryComponent(
|
|
213
|
+
(native) => {
|
|
214
|
+
const value = current();
|
|
215
|
+
if (rendered === value) return;
|
|
216
|
+
rendered = value;
|
|
217
|
+
native.updateArgs({
|
|
218
|
+
command: value.commandText,
|
|
219
|
+
...(value.timing ? { timeout: value.timing.timeoutSeconds } : {}),
|
|
220
|
+
});
|
|
221
|
+
native.updateResult(
|
|
222
|
+
{
|
|
223
|
+
...(value.result ?? { content: [] }),
|
|
224
|
+
isError: value.command === "failed" || value.command === "timeout",
|
|
225
|
+
},
|
|
226
|
+
(value.command === "waiting" || value.command === "running") &&
|
|
227
|
+
active.has(value.toolCallId),
|
|
228
|
+
);
|
|
229
|
+
},
|
|
230
|
+
"bash",
|
|
231
|
+
initial.toolCallId,
|
|
232
|
+
{ command: initial.commandText },
|
|
233
|
+
{
|
|
234
|
+
showImages: settings.getShowImages(),
|
|
235
|
+
imageWidthCells: settings.getImageWidthCells(),
|
|
236
|
+
},
|
|
237
|
+
renderers,
|
|
238
|
+
tui,
|
|
239
|
+
currentCwd,
|
|
240
|
+
);
|
|
241
|
+
card.setArgsComplete();
|
|
242
|
+
cards.set(initial.toolCallId, card);
|
|
243
|
+
}
|
|
244
|
+
card.setShowImages(settings.getShowImages());
|
|
245
|
+
card.setImageWidthCells(settings.getImageWidthCells());
|
|
246
|
+
card.setGlobalExpanded(expanded);
|
|
247
|
+
return card;
|
|
177
248
|
});
|
|
178
249
|
|
|
179
250
|
return (progress: ActionFusionProgress, ctx?: ExtensionContext) => {
|
|
180
251
|
if (ctx?.cwd) currentCwd = ctx.cwd;
|
|
181
252
|
const first = !states.has(progress.toolCallId);
|
|
182
|
-
|
|
183
|
-
states.set(progress.toolCallId, data);
|
|
253
|
+
states.set(progress.toolCallId, progress);
|
|
184
254
|
const pending = progress.command === "waiting" || progress.command === "running";
|
|
185
255
|
if (pending) active.add(progress.toolCallId);
|
|
186
256
|
else active.delete(progress.toolCallId);
|
|
187
257
|
// Only endpoints are persisted; streaming snapshots reuse Bash's bounded output.
|
|
188
|
-
if (first) pi.appendEntry(CARD_TYPE,
|
|
189
|
-
if (!pending) pi.appendEntry(RESULT_TYPE,
|
|
258
|
+
if (first) pi.appendEntry(CARD_TYPE, progress);
|
|
259
|
+
if (!pending) pi.appendEntry(RESULT_TYPE, progress);
|
|
190
260
|
};
|
|
191
261
|
}
|
|
192
262
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Candidate selection: rg lists candidate lines through the rg-regex translation, or candidate
|
|
3
3
|
* files through the prefilter's necessary literals, with conservative fallback and a
|
|
4
|
-
* whole-scope scan budget.
|
|
5
|
-
* which rg runs to make.
|
|
4
|
+
* whole-scope scan budget. This module deduplicates candidates before charging that budget.
|
|
5
|
+
* rg-process runs rg and parses its records; this module decides which rg runs to make.
|
|
6
6
|
*
|
|
7
7
|
* @module pi-hashline-edit/pi
|
|
8
8
|
*/
|
|
@@ -119,7 +119,7 @@ export async function runCandidatePaths(
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
/** How candidates were selected: rg's candidate lines, or whole files (see Prefilter). */
|
|
122
|
-
|
|
122
|
+
type CandidateSource = "lines" | "files" | "all";
|
|
123
123
|
|
|
124
124
|
/**
|
|
125
125
|
* Await each consumer for backpressure; false stops listing. The caller owns worker cleanup.
|
|
@@ -131,33 +131,38 @@ export async function listCandidates(options: {
|
|
|
131
131
|
readonly scope: SearchScope;
|
|
132
132
|
readonly query: GrepQuery;
|
|
133
133
|
readonly signal: AbortSignal;
|
|
134
|
+
readonly stopped: () => boolean;
|
|
134
135
|
readonly onCandidate: (candidate: Candidate) => Promise<boolean>;
|
|
135
136
|
}): Promise<{
|
|
136
137
|
readonly listing?: RgRunResult;
|
|
137
138
|
readonly candidates: CandidateSource;
|
|
138
139
|
readonly scanLimitReached: boolean;
|
|
139
140
|
}> {
|
|
140
|
-
const { backend, rgPath, scope, query, signal, onCandidate } = options;
|
|
141
|
+
const { backend, rgPath, scope, query, signal, stopped, onCandidate } = options;
|
|
141
142
|
if (scope.searchPaths.length === 0) return { candidates: "lines", scanLimitReached: false };
|
|
142
|
-
let listedAny = false;
|
|
143
|
-
const offer = (path: string, lines?: readonly number[]) => {
|
|
144
|
-
listedAny = true;
|
|
145
|
-
return onCandidate({ filePath: resolve(path), lines });
|
|
146
|
-
};
|
|
147
143
|
let candidates: CandidateSource = "lines";
|
|
144
|
+
let listedAny = false;
|
|
148
145
|
let scanned = 0;
|
|
149
146
|
let scanLimitReached = false;
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
147
|
+
const seen = new Set<string>();
|
|
148
|
+
const offer = async (path: string, lines?: readonly number[]) => {
|
|
149
|
+
listedAny = true;
|
|
150
|
+
if (stopped()) return false;
|
|
151
|
+
const filePath = resolve(path);
|
|
152
|
+
if (seen.has(filePath)) return true;
|
|
153
|
+
seen.add(filePath);
|
|
154
|
+
if (candidates === "all") {
|
|
155
|
+
if (scanned >= MAX_UNNARROWED_SCAN_BYTES) {
|
|
156
|
+
scanLimitReached = true;
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
scanned += await stat(filePath).then(
|
|
160
|
+
({ size }) => size,
|
|
161
|
+
// The search reports unreadable files; a failed size probe must not exclude them.
|
|
162
|
+
() => 0,
|
|
163
|
+
);
|
|
154
164
|
}
|
|
155
|
-
|
|
156
|
-
({ size }) => size,
|
|
157
|
-
// The search reports unreadable files; a failed size probe must not exclude them.
|
|
158
|
-
() => 0,
|
|
159
|
-
);
|
|
160
|
-
return offer(path);
|
|
165
|
+
return onCandidate({ filePath, lines });
|
|
161
166
|
};
|
|
162
167
|
const scoped = [...scopeArgs(scope), "--", ...scope.searchPaths];
|
|
163
168
|
const patterns = query.multiline ? undefined : lineCandidatePatterns(query);
|
|
@@ -180,14 +185,7 @@ export async function listCandidates(options: {
|
|
|
180
185
|
if (!listing || (listing.code === 2 && !listedAny)) {
|
|
181
186
|
const prefilter = extractPrefilter(query);
|
|
182
187
|
candidates = prefilter.kind === "all" ? "all" : "files";
|
|
183
|
-
listing = await runCandidatePaths(
|
|
184
|
-
backend.runRgPaths,
|
|
185
|
-
rgPath,
|
|
186
|
-
prefilter,
|
|
187
|
-
scoped,
|
|
188
|
-
signal,
|
|
189
|
-
candidates === "all" ? offerWithinBudget : (path) => offer(path),
|
|
190
|
-
);
|
|
188
|
+
listing = await runCandidatePaths(backend.runRgPaths, rgPath, prefilter, scoped, signal, offer);
|
|
191
189
|
}
|
|
192
190
|
return { listing, candidates, scanLimitReached };
|
|
193
191
|
}
|
|
@@ -66,7 +66,7 @@ test("Cartesian JS syntax × all flag combinations → tool entry agrees with V8
|
|
|
66
66
|
accepted++;
|
|
67
67
|
const value = await result;
|
|
68
68
|
assert.equal(value.isError, undefined, context);
|
|
69
|
-
assert.equal(reportOf(value)?.matches, 0, context);
|
|
69
|
+
assert.equal(reportOf(value, "grep")?.matches, 0, context);
|
|
70
70
|
assert.equal(discoveries, before + 1, context);
|
|
71
71
|
}
|
|
72
72
|
}
|