@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-tool.ts
DELETED
|
@@ -1,367 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* forget: the model drops tagged inspection output it no longer needs from context.
|
|
3
|
-
*
|
|
4
|
-
* Direct read/grep results and codemode outputs containing successful inspections
|
|
5
|
-
* are tagged when they meet the output budget. Nested read/grep results lose their
|
|
6
|
-
* tags before reaching the script: Pi persists only the script's final output,
|
|
7
|
-
* which is forgotten as one result even when the script transforms or mixes data.
|
|
8
|
-
* A tag is the `resultId` fact of the result's report (report.ts), owned by
|
|
9
|
-
* forget alone. Before each request, the `context` handler records the tagged results
|
|
10
|
-
* of the previous response, the only ones forget may name. Other named ids are reported
|
|
11
|
-
* without blocking the rest, since no later response can forget them either. At
|
|
12
|
-
* `turn_end` of a completed response, branch-local context edits replace each named
|
|
13
|
-
* result with a receipt report.
|
|
14
|
-
* The tool call and any facts saved in forget's note remain in context.
|
|
15
|
-
*
|
|
16
|
-
* Restricting forget to the previous response bounds how much of the next request
|
|
17
|
-
* changes, and how often: it differs from the earliest replaced result on, which covers
|
|
18
|
-
* later results of the same batch, the response that requested the edit, and its tool
|
|
19
|
-
* results. Messages before that result are unchanged. Editing an older result would
|
|
20
|
-
* change every later message, and forgetting one batch across several responses would
|
|
21
|
-
* change the request once per response. Raw session entries stay intact; navigating
|
|
22
|
-
* before the edit shows the original result again.
|
|
23
|
-
*
|
|
24
|
-
* @module pi-hashline-edit/pi
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import { createHash } from "node:crypto";
|
|
28
|
-
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
29
|
-
import type {
|
|
30
|
-
ContextEditEntryDraft,
|
|
31
|
-
ExtensionAPI,
|
|
32
|
-
Theme,
|
|
33
|
-
ToolDefinition,
|
|
34
|
-
} from "@earendil-works/pi-coding-agent";
|
|
35
|
-
import { Text } from "@earendil-works/pi-tui";
|
|
36
|
-
import { Type, type Static } from "typebox";
|
|
37
|
-
import {
|
|
38
|
-
defaultOutputBudgets,
|
|
39
|
-
FORGET_MIN_BYTES,
|
|
40
|
-
formatKiB,
|
|
41
|
-
type OutputBudgetProvider,
|
|
42
|
-
} from "./budgets.ts";
|
|
43
|
-
import { renderToolError } from "./render.ts";
|
|
44
|
-
import {
|
|
45
|
-
decodeReport,
|
|
46
|
-
reportOf,
|
|
47
|
-
reportResult,
|
|
48
|
-
runTool,
|
|
49
|
-
type Report,
|
|
50
|
-
type ReportDetails,
|
|
51
|
-
} from "./report.ts";
|
|
52
|
-
import type { SuccessReport } from "./report-schema.ts";
|
|
53
|
-
import { HashlineError } from "../core/errors.ts";
|
|
54
|
-
import { createArgumentPreparer } from "./argument-validation.ts";
|
|
55
|
-
|
|
56
|
-
const RESULT_ID = "r[0-9a-f]{5}";
|
|
57
|
-
const CODEMODE_FORGET_SCOPE = "entire codemode output, including all text and images";
|
|
58
|
-
const CODEMODE_FORGET_RECEIPT = "codemode · entire output";
|
|
59
|
-
|
|
60
|
-
/** Short id shown to the model; it only has to be unique within one tool batch. */
|
|
61
|
-
function resultId(toolCallId: string): string {
|
|
62
|
-
return `r${createHash("sha256").update(toolCallId).digest("hex").slice(0, 5)}`;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
type ResultContent = AgentToolResult<unknown>["content"];
|
|
66
|
-
|
|
67
|
-
/** A success report of a tool whose results can be tagged. */
|
|
68
|
-
type TaggedReport = Extract<SuccessReport, { tool: "read" | "grep" | "codemode" }>;
|
|
69
|
-
|
|
70
|
-
/** The report if it carries the call's id; the wire schema admits resultId only on taggable successes. */
|
|
71
|
-
function tagOf(report: Report | undefined, toolCallId: string): TaggedReport | undefined {
|
|
72
|
-
return report?.resultId === resultId(toolCallId) ? (report as TaggedReport) : undefined;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** The report the model saw tagged: the result's last block, naming the call's id. */
|
|
76
|
-
function taggedReport(
|
|
77
|
-
content: ResultContent,
|
|
78
|
-
toolCallId: string,
|
|
79
|
-
toolName: string,
|
|
80
|
-
): TaggedReport | undefined {
|
|
81
|
-
const last = content.at(-1);
|
|
82
|
-
return last?.type === "text" ? tagOf(decodeReport(last.text, toolName), toolCallId) : undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Text results below the threshold save too little to be worth forgetting; images always qualify. */
|
|
86
|
-
function worthForgetting(content: ResultContent): boolean {
|
|
87
|
-
const bytes = content.reduce(
|
|
88
|
-
(sum, block) => sum + (block.type === "text" ? Buffer.byteLength(block.text) : 0),
|
|
89
|
-
0,
|
|
90
|
-
);
|
|
91
|
-
return content.some((block) => block.type === "image") || bytes >= FORGET_MIN_BYTES;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/** Pattern text shown in a grep receipt before it is cut with an ellipsis. */
|
|
95
|
-
const MAX_RECEIPT_PATTERN_CHARS = 60;
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Display-only receipt for a tagged result, kept in its details. Pi does not send details
|
|
99
|
-
* to the model, so the forget card can name what was forgotten without adding context.
|
|
100
|
-
*/
|
|
101
|
-
export interface ForgetReceiptDetails {
|
|
102
|
-
readonly forgetReceipt?: string;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function plural(count: number, noun: string, pluralForm = `${noun}s`): string {
|
|
106
|
-
return `${count} ${count === 1 ? noun : pluralForm}`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** `path · lines A–B` for anchored text, `path · image` for images, `path` otherwise. */
|
|
110
|
-
export function readReceipt(
|
|
111
|
-
path: string,
|
|
112
|
-
shown: { image: true } | { start: number; end: number; truncated: boolean } | undefined,
|
|
113
|
-
): string {
|
|
114
|
-
if (!shown) return path;
|
|
115
|
-
if ("image" in shown) return `${path} · image`;
|
|
116
|
-
return `${path} · lines ${shown.start}–${shown.end}${shown.truncated ? " · truncated" : ""}`;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/** `grep /pattern/ · N matches in M files`, with limit and incomplete-search notes. */
|
|
120
|
-
export function grepReceipt(
|
|
121
|
-
patterns: readonly string[],
|
|
122
|
-
matches: number,
|
|
123
|
-
files: number,
|
|
124
|
-
notes: { limitReached: boolean; incomplete: boolean },
|
|
125
|
-
): string {
|
|
126
|
-
const joined = patterns.join(" | ");
|
|
127
|
-
const pattern =
|
|
128
|
-
joined.length > MAX_RECEIPT_PATTERN_CHARS
|
|
129
|
-
? `${joined.slice(0, MAX_RECEIPT_PATTERN_CHARS)}…`
|
|
130
|
-
: joined;
|
|
131
|
-
let receipt = `grep /${pattern}/ · ${plural(matches, "match", "matches")} in ${plural(files, "file")}`;
|
|
132
|
-
if (notes.limitReached) receipt += " · limit reached";
|
|
133
|
-
if (notes.incomplete) receipt += " · incomplete";
|
|
134
|
-
return receipt;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Build a successful read/grep result, tagged when forgetting is enabled and the
|
|
139
|
-
* result is eligible. Only then evaluate createReceipt and keep its display text in details.
|
|
140
|
-
*/
|
|
141
|
-
export function withResultTag<TDetails extends object | undefined>(
|
|
142
|
-
toolCallId: string,
|
|
143
|
-
parts: {
|
|
144
|
-
report: Extract<TaggedReport, { tool: "read" | "grep" }>;
|
|
145
|
-
payload: ResultContent;
|
|
146
|
-
details?: TDetails;
|
|
147
|
-
},
|
|
148
|
-
enabled: boolean,
|
|
149
|
-
createReceipt: () => string,
|
|
150
|
-
): AgentToolResult<TDetails & ReportDetails & ForgetReceiptDetails> {
|
|
151
|
-
const { report, payload, details } = parts;
|
|
152
|
-
const untagged = reportResult(report, payload, details);
|
|
153
|
-
if (!enabled || !worthForgetting(untagged.content)) return untagged;
|
|
154
|
-
return reportResult({ ...report, resultId: resultId(toolCallId) }, payload, {
|
|
155
|
-
...details,
|
|
156
|
-
forgetReceipt: createReceipt(),
|
|
157
|
-
} as TDetails & ForgetReceiptDetails);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/** Every tagged result carries its receipt; optional chaining only keeps foreign details from throwing. */
|
|
161
|
-
function receiptOf(details: unknown): string {
|
|
162
|
-
return (details as ForgetReceiptDetails | undefined)?.forgetReceipt as string;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const forgetSchema = Type.Object(
|
|
166
|
-
{
|
|
167
|
-
ids: Type.Array(Type.String({ pattern: `^${RESULT_ID}$` }), {
|
|
168
|
-
minItems: 1,
|
|
169
|
-
uniqueItems: true,
|
|
170
|
-
description: "resultId values to forget.",
|
|
171
|
-
}),
|
|
172
|
-
note: Type.Optional(
|
|
173
|
-
Type.String({
|
|
174
|
-
minLength: 1,
|
|
175
|
-
description:
|
|
176
|
-
"Conclusions needed for subsequent work, kept in context. Omit when none; do not restate the read or forget action.",
|
|
177
|
-
}),
|
|
178
|
-
),
|
|
179
|
-
},
|
|
180
|
-
{ additionalProperties: false },
|
|
181
|
-
);
|
|
182
|
-
type ForgetParams = Static<typeof forgetSchema>;
|
|
183
|
-
/** One line per forgotten result. */
|
|
184
|
-
type ForgetDetails = { forgotten?: { id: string; receipt: string }[] } & Partial<ReportDetails>;
|
|
185
|
-
|
|
186
|
-
/** Register the forget tool and the context hooks that apply it. */
|
|
187
|
-
export function registerForgetTool(
|
|
188
|
-
pi: ExtensionAPI,
|
|
189
|
-
budgets: OutputBudgetProvider = defaultOutputBudgets,
|
|
190
|
-
): void {
|
|
191
|
-
// Tagged results of the batch the current response is the first to see, by id.
|
|
192
|
-
let forgettable = new Map<string, { toolCallId: string; receipt: string }>();
|
|
193
|
-
// Results named by forget during the current response, applied at its turn_end.
|
|
194
|
-
let pending = new Set<string>();
|
|
195
|
-
|
|
196
|
-
pi.on("tool_result", (event) => {
|
|
197
|
-
if (
|
|
198
|
-
!event.parentToolCallId ||
|
|
199
|
-
(event.toolName !== "read" && event.toolName !== "grep") ||
|
|
200
|
-
!taggedReport(event.content, event.toolCallId, event.toolName)
|
|
201
|
-
)
|
|
202
|
-
return;
|
|
203
|
-
// A nested id cannot identify a transcript entry: rebuild the report without it.
|
|
204
|
-
const report = tagOf(reportOf(event), event.toolCallId);
|
|
205
|
-
if (!report) return;
|
|
206
|
-
const { forgetReceipt: _receipt, ...details } = (event.details ?? {}) as ForgetReceiptDetails;
|
|
207
|
-
const result = reportResult(
|
|
208
|
-
{ ...report, resultId: undefined },
|
|
209
|
-
event.content.slice(0, -1),
|
|
210
|
-
details,
|
|
211
|
-
);
|
|
212
|
-
// Preserve structured results while removing the tag.
|
|
213
|
-
return { ...result, structuredContent: event.structuredContent };
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
pi.on("message_end", (event) => {
|
|
217
|
-
const message = event.message;
|
|
218
|
-
if (
|
|
219
|
-
message.role !== "toolResult" ||
|
|
220
|
-
message.toolName !== "codemode" ||
|
|
221
|
-
message.isError ||
|
|
222
|
-
!message.nestedCalls?.calls.some(
|
|
223
|
-
(call) =>
|
|
224
|
-
call.status === "ok" &&
|
|
225
|
-
(call.name === "read" ||
|
|
226
|
-
(call.name === "grep" &&
|
|
227
|
-
call.arguments !== undefined &&
|
|
228
|
-
(call.arguments.outputMode == null || call.arguments.outputMode === "content"))),
|
|
229
|
-
)
|
|
230
|
-
)
|
|
231
|
-
return;
|
|
232
|
-
if (!worthForgetting(message.content)) return;
|
|
233
|
-
// The codemode output is not ours: its tag is a report of forget facts alone.
|
|
234
|
-
const tag = reportResult(
|
|
235
|
-
{
|
|
236
|
-
tool: "codemode",
|
|
237
|
-
resultId: resultId(message.toolCallId),
|
|
238
|
-
forgetScope: CODEMODE_FORGET_SCOPE,
|
|
239
|
-
},
|
|
240
|
-
message.content,
|
|
241
|
-
);
|
|
242
|
-
return {
|
|
243
|
-
message: {
|
|
244
|
-
...message,
|
|
245
|
-
content: tag.content,
|
|
246
|
-
details: {
|
|
247
|
-
...(message.details as object | undefined),
|
|
248
|
-
forgetReceipt: CODEMODE_FORGET_RECEIPT,
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
pi.on("context", (event) => {
|
|
255
|
-
forgettable = new Map();
|
|
256
|
-
const lastAssistant = event.messages.findLastIndex((message) => message.role === "assistant");
|
|
257
|
-
// Every tag still visible, older batches included: an id the model can see on more
|
|
258
|
-
// than one result cannot name a single one, so none of them is forgettable.
|
|
259
|
-
const visible = new Map<string, number>();
|
|
260
|
-
event.messages.forEach((message, index) => {
|
|
261
|
-
if (
|
|
262
|
-
message.role !== "toolResult" ||
|
|
263
|
-
message.isError ||
|
|
264
|
-
!taggedReport(message.content, message.toolCallId, message.toolName)
|
|
265
|
-
)
|
|
266
|
-
return;
|
|
267
|
-
const id = resultId(message.toolCallId);
|
|
268
|
-
visible.set(id, (visible.get(id) ?? 0) + 1);
|
|
269
|
-
if (index > lastAssistant)
|
|
270
|
-
forgettable.set(id, {
|
|
271
|
-
toolCallId: message.toolCallId,
|
|
272
|
-
receipt: receiptOf(message.details),
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
for (const [id, count] of visible) if (count > 1) forgettable.delete(id);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
pi.on("turn_end", (event) => {
|
|
279
|
-
const targets = pending;
|
|
280
|
-
pending = new Set();
|
|
281
|
-
if (event.outcome !== "completed" || targets.size === 0) return;
|
|
282
|
-
const entries: ContextEditEntryDraft[] = [];
|
|
283
|
-
for (const { sourceEntry, messages } of event.context.contextEntries) {
|
|
284
|
-
if (sourceEntry.type !== "message") continue;
|
|
285
|
-
// Edit what the model saw: the projected message, which carries the tag.
|
|
286
|
-
const message = messages.find(
|
|
287
|
-
(candidate) => candidate.role === "toolResult" && targets.has(candidate.toolCallId),
|
|
288
|
-
);
|
|
289
|
-
if (message?.role !== "toolResult") continue;
|
|
290
|
-
const tagged = taggedReport(message.content, message.toolCallId, message.toolName);
|
|
291
|
-
if (!tagged) continue;
|
|
292
|
-
entries.push({
|
|
293
|
-
type: "context_edit",
|
|
294
|
-
targetId: sourceEntry.id,
|
|
295
|
-
replacement: {
|
|
296
|
-
content: reportResult({
|
|
297
|
-
tool: tagged.tool,
|
|
298
|
-
resultId: tagged.resultId,
|
|
299
|
-
contentForgotten: true,
|
|
300
|
-
}).content,
|
|
301
|
-
},
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
if (entries.length > 0) return { entries };
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
pi.registerTool({
|
|
308
|
-
name: "forget",
|
|
309
|
-
label: "forget",
|
|
310
|
-
description: `Remove tagged inspection output from your context. Only results of your previous response whose report has a resultId (${formatKiB(FORGET_MIN_BYTES)} or larger, or images) can be forgotten; later responses cannot forget them. After this response each selected result's entire content, including its report, is replaced with a forgotten receipt. A codemode resultId covers its entire output, including other results printed by the script. Files and session history are unchanged.`,
|
|
311
|
-
promptSnippet: "Forget tagged inspection output you no longer need",
|
|
312
|
-
promptGuidelines: [
|
|
313
|
-
"In the response right after results with a resultId, forget each one unless you will need its text after that response's tool results return; anchors you pass to edit in that same response are already in the edit call, so using them is no reason to keep it. First copy any facts you still need into note.",
|
|
314
|
-
"Make that one forget call alongside the response's other tool calls, naming every result to forget; when the response makes no other tool call, skip forget.",
|
|
315
|
-
],
|
|
316
|
-
parameters: forgetSchema,
|
|
317
|
-
prepareArguments: createArgumentPreparer("forget", forgetSchema, undefined, budgets),
|
|
318
|
-
renderShell: "default" as const,
|
|
319
|
-
renderCall(args: ForgetParams, theme: Theme) {
|
|
320
|
-
let text =
|
|
321
|
-
theme.fg("toolTitle", theme.bold("forget")) +
|
|
322
|
-
(Array.isArray(args?.ids)
|
|
323
|
-
? theme.fg("dim", ` · ${plural(args.ids.length, "result")}`)
|
|
324
|
-
: "");
|
|
325
|
-
if (typeof args?.note === "string") text += `\n${theme.fg("dim", args.note)}`;
|
|
326
|
-
return new Text(text, 0, 0);
|
|
327
|
-
},
|
|
328
|
-
renderResult(result, { expanded }, theme, context) {
|
|
329
|
-
if (context?.isError) return renderToolError(result, theme, expanded);
|
|
330
|
-
const lines = (result.details?.forgotten ?? []).map(
|
|
331
|
-
({ id, receipt }) =>
|
|
332
|
-
(expanded ? theme.fg("dim", `${id} · `) : "") + theme.fg("toolOutput", receipt),
|
|
333
|
-
);
|
|
334
|
-
const notForgettable = result.details?.report?.notForgettable ?? [];
|
|
335
|
-
if (notForgettable.length > 0)
|
|
336
|
-
lines.push(theme.fg("warning", `not forgettable: ${notForgettable.join(", ")}`));
|
|
337
|
-
return new Text(lines.join("\n"), 0, 0);
|
|
338
|
-
},
|
|
339
|
-
async execute(_toolCallId: string, params: ForgetParams) {
|
|
340
|
-
return runTool("forget", { budget: budgets() }, async () => {
|
|
341
|
-
// Forget what can be forgotten: no later response could retry the rest.
|
|
342
|
-
const named = params.ids.filter((id) => forgettable.has(id));
|
|
343
|
-
const notForgettable = params.ids.filter((id) => !forgettable.has(id));
|
|
344
|
-
if (named.length === 0)
|
|
345
|
-
throw new HashlineError(
|
|
346
|
-
"NOT_FORGETTABLE",
|
|
347
|
-
"No id names a tagged result of the previous response.",
|
|
348
|
-
{ facts: { notForgettable } },
|
|
349
|
-
);
|
|
350
|
-
const forgotten = named.map((id) => {
|
|
351
|
-
const { toolCallId, receipt } = forgettable.get(id)!;
|
|
352
|
-
pending.add(toolCallId);
|
|
353
|
-
return { id, receipt };
|
|
354
|
-
});
|
|
355
|
-
return reportResult(
|
|
356
|
-
{
|
|
357
|
-
tool: "forget",
|
|
358
|
-
forgotten: named,
|
|
359
|
-
...(notForgettable.length > 0 ? { notForgettable } : {}),
|
|
360
|
-
},
|
|
361
|
-
[],
|
|
362
|
-
{ forgotten },
|
|
363
|
-
);
|
|
364
|
-
});
|
|
365
|
-
},
|
|
366
|
-
} satisfies ToolDefinition<typeof forgetSchema, ForgetDetails>);
|
|
367
|
-
}
|