@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/forget.testing.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
/** Real Pi sessions with scripted model responses; no provider requests leave the process. */
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { stripVTControlCharacters } from "node:util";
|
|
5
|
-
import type { TestContext } from "node:test";
|
|
6
|
-
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
7
|
-
import type { Message, ToolCall } from "@earendil-works/pi-ai";
|
|
8
|
-
import { normalizeContext } from "@earendil-works/pi-ai/utils/transcript";
|
|
9
|
-
import { stream as streamCompletions } from "@earendil-works/pi-ai/api/openai-completions";
|
|
10
|
-
import { initTheme } from "@earendil-works/pi-coding-agent";
|
|
11
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
12
|
-
import { decodeReport, reportOf } from "./report.ts";
|
|
13
|
-
import { openTestSession, responseStream, type TestResponse } from "../testing/session.testing.ts";
|
|
14
|
-
import { DEFAULT_CONFIG } from "./config.ts";
|
|
15
|
-
import { registerForgetTool } from "./forget-tool.ts";
|
|
16
|
-
import { makeGrepOverride } from "./grep-tool.ts";
|
|
17
|
-
import { makeReadOverride } from "./read-tool.ts";
|
|
18
|
-
import { theme } from "../../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
|
|
19
|
-
import { createCodemodeToolDefinition } from "../../node_modules/@earendil-works/pi-coding-agent/dist/extensions/codemode/tool.js";
|
|
20
|
-
|
|
21
|
-
export { SESSION_TIMEOUT_MS } from "../testing/session.testing.ts";
|
|
22
|
-
type Response = TestResponse;
|
|
23
|
-
type Script = Response | ((messages: readonly Message[]) => Response);
|
|
24
|
-
export const finish: Response = {
|
|
25
|
-
content: [{ type: "text", text: "Processed." }],
|
|
26
|
-
stopReason: "stop",
|
|
27
|
-
};
|
|
28
|
-
export const toolResponse = (...content: ToolCall[]): Response => ({
|
|
29
|
-
content,
|
|
30
|
-
stopReason: "toolUse",
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/** Extract a public id from JSON inspection reports, excluding forgotten receipts. */
|
|
34
|
-
export function taggedResultId(
|
|
35
|
-
result: Pick<AgentToolResult<unknown>, "content"> & {
|
|
36
|
-
readonly toolName?: string;
|
|
37
|
-
readonly details?: unknown;
|
|
38
|
-
},
|
|
39
|
-
) {
|
|
40
|
-
const toolName = result.toolName ?? reportOf(result)?.tool;
|
|
41
|
-
const ids = result.content.flatMap((block) => {
|
|
42
|
-
if (block.type !== "text") return [];
|
|
43
|
-
const report = decodeReport(block.text, toolName);
|
|
44
|
-
const id = report?.contentForgotten ? undefined : report?.resultId;
|
|
45
|
-
return id ? [id] : [];
|
|
46
|
-
});
|
|
47
|
-
return ids.length === 1 ? ids[0] : undefined;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function toolResult(messages: readonly Message[], id: string) {
|
|
51
|
-
const result = messages.find(
|
|
52
|
-
(message) => message.role === "toolResult" && message.toolCallId === id,
|
|
53
|
-
);
|
|
54
|
-
assert.ok(result?.role === "toolResult", `Missing result for ${id}`);
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function forgetCall(messages: readonly Message[], ...sourceIds: string[]): ToolCall {
|
|
59
|
-
const ids = sourceIds.map((sourceId) => {
|
|
60
|
-
const result = toolResult(messages, sourceId);
|
|
61
|
-
assert.equal(result.isError, false);
|
|
62
|
-
const id = taggedResultId(result);
|
|
63
|
-
assert.ok(id, `Result ${sourceId} must be eligible for forgetting`);
|
|
64
|
-
return id;
|
|
65
|
-
});
|
|
66
|
-
return { type: "toolCall", id: "forget-call", name: "forget", arguments: { ids } };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export async function openForgetSession(
|
|
70
|
-
t: TestContext,
|
|
71
|
-
configure?: (pi: ExtensionAPI, cwd: string) => void,
|
|
72
|
-
) {
|
|
73
|
-
const { cwd, session, model, sessionManager } = await openTestSession(t, {
|
|
74
|
-
tools: ["read", "grep", "forget", "codemode"],
|
|
75
|
-
configure(pi, cwd) {
|
|
76
|
-
const config = { ...DEFAULT_CONFIG, forget: true };
|
|
77
|
-
pi.registerTool(makeReadOverride(cwd, config));
|
|
78
|
-
pi.registerTool(makeGrepOverride(cwd, config));
|
|
79
|
-
registerForgetTool(pi);
|
|
80
|
-
pi.registerTool(createCodemodeToolDefinition());
|
|
81
|
-
configure?.(pi, cwd);
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
const requests: Message[][] = [];
|
|
85
|
-
const scripts: Script[] = [];
|
|
86
|
-
session.agent.streamFunction = (_model, context) => {
|
|
87
|
-
requests.push(structuredClone(context.messages));
|
|
88
|
-
const script = scripts.shift();
|
|
89
|
-
assert.ok(script, "Unexpected model request after the scripted responses");
|
|
90
|
-
const response = typeof script === "function" ? script(context.messages) : script;
|
|
91
|
-
return responseStream(model, response);
|
|
92
|
-
};
|
|
93
|
-
const rawResult = (id: string) => {
|
|
94
|
-
const entry = sessionManager
|
|
95
|
-
.getEntries()
|
|
96
|
-
.find(
|
|
97
|
-
(entry) =>
|
|
98
|
-
entry.type === "message" &&
|
|
99
|
-
entry.message.role === "toolResult" &&
|
|
100
|
-
entry.message.toolCallId === id,
|
|
101
|
-
);
|
|
102
|
-
assert.ok(entry?.type === "message" && entry.message.role === "toolResult");
|
|
103
|
-
return entry.message;
|
|
104
|
-
};
|
|
105
|
-
return {
|
|
106
|
-
cwd,
|
|
107
|
-
requests,
|
|
108
|
-
sessionManager,
|
|
109
|
-
rawResult,
|
|
110
|
-
renderForgetCard(expanded = false) {
|
|
111
|
-
const id = "forget-call";
|
|
112
|
-
const tool = session.getToolDefinition("forget");
|
|
113
|
-
assert.ok(tool?.renderResult);
|
|
114
|
-
const call = session.agent.state.messages
|
|
115
|
-
.flatMap((message) =>
|
|
116
|
-
message.role === "assistant"
|
|
117
|
-
? message.content.filter((block) => block.type === "toolCall")
|
|
118
|
-
: [],
|
|
119
|
-
)
|
|
120
|
-
.find((call) => call.id === id);
|
|
121
|
-
assert.ok(call);
|
|
122
|
-
const result = rawResult(id);
|
|
123
|
-
const context: Parameters<typeof tool.renderResult>[3] = {
|
|
124
|
-
args: call.arguments,
|
|
125
|
-
toolCallId: id,
|
|
126
|
-
cwd,
|
|
127
|
-
state: {},
|
|
128
|
-
invalidate() {},
|
|
129
|
-
lastComponent: undefined,
|
|
130
|
-
executionStarted: true,
|
|
131
|
-
argsComplete: true,
|
|
132
|
-
isPartial: false,
|
|
133
|
-
expanded,
|
|
134
|
-
showImages: false,
|
|
135
|
-
isError: result.isError,
|
|
136
|
-
};
|
|
137
|
-
initTheme("dark");
|
|
138
|
-
const header = tool.renderCall?.(call.arguments, theme, context);
|
|
139
|
-
const component = tool.renderResult(
|
|
140
|
-
{ ...result, details: result.details },
|
|
141
|
-
{ expanded, isPartial: false },
|
|
142
|
-
theme,
|
|
143
|
-
context,
|
|
144
|
-
);
|
|
145
|
-
return stripVTControlCharacters(
|
|
146
|
-
[...(header?.render(240) ?? []), ...component.render(240)].join("\n"),
|
|
147
|
-
);
|
|
148
|
-
},
|
|
149
|
-
async requestPayload(index: number) {
|
|
150
|
-
assert.equal(model.api, "openai-completions");
|
|
151
|
-
const messages = requests[index];
|
|
152
|
-
assert.ok(messages);
|
|
153
|
-
let payload: unknown;
|
|
154
|
-
let networkCalls = 0;
|
|
155
|
-
await streamCompletions(
|
|
156
|
-
{ ...model, api: "openai-completions" },
|
|
157
|
-
normalizeContext({ messages }),
|
|
158
|
-
{
|
|
159
|
-
apiKey: "local-test-placeholder",
|
|
160
|
-
maxRetries: 0,
|
|
161
|
-
onPayload(value) {
|
|
162
|
-
payload = value;
|
|
163
|
-
throw new Error("Payload captured before sending.");
|
|
164
|
-
},
|
|
165
|
-
async fetch() {
|
|
166
|
-
networkCalls++;
|
|
167
|
-
throw new Error("Provider requests are forbidden in this fixture.");
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
).result();
|
|
171
|
-
assert.ok(payload !== undefined, "Pi must construct the provider payload");
|
|
172
|
-
assert.equal(networkCalls, 0);
|
|
173
|
-
return payload;
|
|
174
|
-
},
|
|
175
|
-
read(id: string, name = "build.log"): ToolCall {
|
|
176
|
-
return { type: "toolCall", id, name: "read", arguments: { path: join(cwd, name) } };
|
|
177
|
-
},
|
|
178
|
-
async prompt(...responses: Script[]) {
|
|
179
|
-
scripts.push(...responses);
|
|
180
|
-
await session.prompt("Continue.");
|
|
181
|
-
assert.equal(
|
|
182
|
-
scripts.length,
|
|
183
|
-
0,
|
|
184
|
-
session.agent.state.errorMessage ?? "Unused scripted responses",
|
|
185
|
-
);
|
|
186
|
-
assert.equal(session.agent.state.errorMessage, undefined);
|
|
187
|
-
},
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/** The entire model-facing result becomes one receipt, including for image reads. */
|
|
192
|
-
export function assertForgotten(result: ReturnType<typeof toolResult>, id: string) {
|
|
193
|
-
assert.equal(result.isError, false);
|
|
194
|
-
assert.equal(result.content.length, 1);
|
|
195
|
-
const receipt = result.content[0];
|
|
196
|
-
assert.equal(receipt.type, "text");
|
|
197
|
-
const report = receipt.type === "text" ? decodeReport(receipt.text, result.toolName) : undefined;
|
|
198
|
-
assert.equal(report?.resultId, id);
|
|
199
|
-
assert.equal(report?.contentForgotten, true);
|
|
200
|
-
assert.equal(taggedResultId(result), undefined);
|
|
201
|
-
}
|