@criogaid/pi-hashline-edit 0.10.0 → 0.11.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 +4 -3
- package/README.zh-CN.md +4 -3
- package/package.json +1 -1
- package/src/core/apply.test.ts +2 -2
- package/src/core/apply.ts +2 -2
- package/src/core/character-set.test.ts +2 -3
- package/src/core/character-set.ts +1 -1
- package/src/core/ranges.test.ts +2 -1
- package/src/core/ranges.ts +1 -1
- package/src/core/types.ts +1 -1
- package/src/index.ts +8 -8
- package/src/integration/config-registration.test.ts +8 -10
- package/src/integration/fusion-dispatch.test.ts +2 -2
- package/src/integration/grep-errors.test.ts +3 -3
- package/src/integration/grep-flags.test.ts +5 -5
- package/src/integration/grep-js-completeness.test.ts +12 -11
- package/src/integration/grep-line-candidates.test.ts +3 -2
- package/src/integration/grep-matrix.test.ts +5 -4
- package/src/integration/grep-order.test.ts +4 -4
- package/src/integration/grep-path-matrix.test.ts +5 -4
- package/src/integration/grep-prefilter-coverage.test.ts +4 -3
- package/src/integration/grep-process-limits.test.ts +2 -4
- package/src/integration/grep-regex.test.ts +10 -10
- package/src/integration/grep-rg.test.ts +50 -48
- package/src/integration/grep-scan-budget.test.ts +8 -8
- package/src/integration/grep-translation.test.ts +8 -7
- package/src/integration/large-text.test.ts +5 -5
- package/src/integration/model-budget-lifecycle.test.ts +9 -9
- package/src/integration/mutation-file-types.testing.ts +4 -4
- package/src/integration/npm-package.testing.ts +3 -3
- package/src/integration/publication-read-changes.test.ts +54 -54
- package/src/integration/read-changes.test.ts +4 -4
- package/src/integration/replace-worker-boundary.test.ts +1 -1
- package/src/integration/report-replay.test.ts +5 -6
- package/src/integration/utf8-errors.test.ts +4 -4
- package/src/pi/AGENTS.md +6 -5
- package/src/pi/action-fusion.test.ts +125 -105
- package/src/pi/action-fusion.testing.ts +38 -0
- package/src/pi/action-fusion.ts +9 -21
- package/src/pi/argument-diagnostics.ts +4 -3
- package/src/pi/argument-format.test.ts +19 -18
- package/src/pi/argument-validation.test.ts +218 -139
- package/src/pi/budgets.ts +1 -4
- package/src/pi/codemode.test.ts +7 -2
- package/src/pi/config.test.ts +2 -1
- package/src/pi/config.ts +8 -3
- package/src/pi/diagnostic-buffer.test.ts +23 -13
- package/src/pi/edit-tool.ts +47 -62
- package/src/pi/error-text.ts +7 -2
- package/src/pi/execute.test.ts +174 -157
- package/src/pi/failure-context.test.ts +4 -3
- package/src/pi/failure-context.ts +1 -1
- package/src/pi/failure-path.test.ts +37 -37
- package/src/pi/file-commit.test.ts +47 -19
- package/src/pi/file-commit.ts +36 -9
- package/src/pi/fusion-card.test.ts +22 -21
- package/src/pi/grep-candidates.test.ts +18 -20
- package/src/pi/grep-candidates.ts +8 -13
- package/src/pi/grep-matrix.test.ts +3 -3
- package/src/pi/grep-order.test.ts +12 -11
- package/src/pi/grep-output.ts +36 -15
- package/src/pi/grep-reread.ts +7 -2
- package/src/pi/grep-rg.testing.ts +70 -0
- package/src/pi/grep-scope.ts +4 -4
- package/src/pi/grep-search.ts +8 -11
- package/src/pi/grep-tool.ts +23 -39
- package/src/pi/grep.test.ts +102 -116
- package/src/pi/model-budgets.test.ts +2 -1
- package/src/pi/mutation-outcome.testing.ts +0 -1
- package/src/pi/mutation-result.test.ts +8 -8
- package/src/pi/mutation-result.ts +1 -1
- package/src/pi/mutation-runner.ts +9 -5
- package/src/pi/output-budgets.test.ts +53 -31
- package/src/pi/pi.test.ts +18 -13
- package/src/pi/read-tool.ts +13 -18
- package/src/pi/read.test.ts +22 -41
- package/src/pi/registration.test.ts +25 -19
- package/src/pi/render.test.ts +51 -32
- package/src/pi/render.ts +7 -4
- package/src/pi/replace-regex.ts +1 -1
- package/src/pi/replace-tool.ts +6 -16
- package/src/pi/replace.test.ts +45 -34
- package/src/pi/report-failure.testing.ts +9 -1
- package/src/pi/report-schema.ts +205 -83
- package/src/pi/report.test.ts +66 -64
- package/src/pi/report.ts +23 -17
- package/src/pi/result-safety.test.ts +121 -100
- package/src/pi/rg-process.test.ts +2 -2
- package/src/pi/rg-process.ts +9 -15
- package/src/pi/schema.ts +23 -0
- package/src/pi/tool-factories.testing.ts +59 -0
- package/src/pi/write-tool.ts +9 -15
- package/src/pi/write.test.ts +30 -31
- package/src/testing/run-tests.ts +1 -1
package/src/pi/report-schema.ts
CHANGED
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
* @module pi-hashline-edit/pi
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { Type, type Static, type TObject, type TProperties } from "typebox";
|
|
18
|
+
import { Type, type Static, type TObject, type TProperties, type TSchema } from "typebox";
|
|
19
|
+
import { literalUnion } from "./schema.ts";
|
|
19
20
|
|
|
20
21
|
const count = (description: string) => Type.Integer({ minimum: 1, description });
|
|
21
22
|
const opt = Type.Optional;
|
|
@@ -147,89 +148,191 @@ const ARGUMENT_ISSUE_SCHEMA = Type.Object(
|
|
|
147
148
|
);
|
|
148
149
|
export type ArgumentIssue = Static<typeof ARGUMENT_ISSUE_SCHEMA>;
|
|
149
150
|
|
|
151
|
+
/**
|
|
152
|
+
* Every fact carries its schema and its audience contract here. Model-visible
|
|
153
|
+
* facts must also state the decision their value changes; TUI-only facts omit it.
|
|
154
|
+
*/
|
|
155
|
+
type FactAudience = "model" | "tui";
|
|
156
|
+
type FactDefinition<T extends TSchema = TSchema> = {
|
|
157
|
+
schema: T;
|
|
158
|
+
audience: FactAudience;
|
|
159
|
+
decision?: string;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
function modelFact<T extends TSchema, const D extends string>(
|
|
163
|
+
schema: T,
|
|
164
|
+
decision: D extends "" ? never : D,
|
|
165
|
+
): FactDefinition<T> {
|
|
166
|
+
return { schema, audience: "model", decision };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function tuiFact<T extends TSchema>(schema: T): FactDefinition<T> {
|
|
170
|
+
return { schema, audience: "tui" };
|
|
171
|
+
}
|
|
172
|
+
|
|
150
173
|
/**
|
|
151
174
|
* Every fact a report can carry beside the envelope, in output order: failure
|
|
152
175
|
* facts first, then each tool's outcome, freshness, and the command.
|
|
153
176
|
*/
|
|
154
177
|
const FACT_FIELDS = {
|
|
155
178
|
// Argument rejection (argument-error.ts).
|
|
156
|
-
issues:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
179
|
+
issues: modelFact(
|
|
180
|
+
Type.Array(ARGUMENT_ISSUE_SCHEMA),
|
|
181
|
+
"Correct the reported argument issues before retrying.",
|
|
182
|
+
),
|
|
183
|
+
omittedIssues: modelFact(
|
|
184
|
+
count("Issues omitted from the byte budget."),
|
|
185
|
+
"Know that the bounded argument report is incomplete.",
|
|
186
|
+
),
|
|
187
|
+
schemaLimited: modelFact(
|
|
188
|
+
Type.Literal(true, {
|
|
189
|
+
description: "A native diagnostic allowance was reached; more issues may exist.",
|
|
190
|
+
}),
|
|
191
|
+
"Know that native validation may have omitted additional issues.",
|
|
192
|
+
),
|
|
193
|
+
missing: modelFact(
|
|
194
|
+
Type.Array(Type.String(), {
|
|
195
|
+
description: "Resolved paths that do not exist; shows where a relative path led.",
|
|
196
|
+
}),
|
|
197
|
+
"Use the resolved missing paths to correct the target or choose create mode.",
|
|
198
|
+
),
|
|
199
|
+
|
|
164
200
|
// Anchor verification (failure-context.ts).
|
|
165
|
-
failures:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
201
|
+
failures: modelFact(
|
|
202
|
+
Type.Array(ANCHOR_FAILURE_SCHEMA),
|
|
203
|
+
"Choose a verified anchor or reread before retrying.",
|
|
204
|
+
),
|
|
205
|
+
omittedFailures: modelFact(
|
|
206
|
+
count("Failures omitted from the byte budget."),
|
|
207
|
+
"Know that anchor evidence is incomplete.",
|
|
208
|
+
),
|
|
209
|
+
candidateNeighborhoods: modelFact(
|
|
210
|
+
Type.Array(
|
|
211
|
+
Type.Object(
|
|
212
|
+
{ lines: Type.String(), rows: Type.Array(Type.String()) },
|
|
213
|
+
{ additionalProperties: false },
|
|
214
|
+
),
|
|
171
215
|
),
|
|
216
|
+
"Inspect the observed neighborhoods before selecting an ambiguous anchor.",
|
|
172
217
|
),
|
|
173
|
-
omittedNeighborhoodRows:
|
|
218
|
+
omittedNeighborhoodRows: modelFact(
|
|
219
|
+
count("Neighborhood rows omitted from the byte budget."),
|
|
220
|
+
"Know that candidate context is incomplete.",
|
|
221
|
+
),
|
|
222
|
+
|
|
174
223
|
// Overlap (core/apply.ts, core/replace.ts).
|
|
175
|
-
conflict:
|
|
176
|
-
|
|
177
|
-
|
|
224
|
+
conflict: modelFact(
|
|
225
|
+
Type.Array(Type.String(), {
|
|
226
|
+
description: "The first conflicting pair of inputs found; more conflicts may exist.",
|
|
227
|
+
}),
|
|
228
|
+
"Merge or separate the conflicting edits or rules before retrying.",
|
|
229
|
+
),
|
|
230
|
+
|
|
178
231
|
// Replacement rules (core/replace.ts).
|
|
179
|
-
unmatched:
|
|
180
|
-
|
|
232
|
+
unmatched: modelFact(
|
|
233
|
+
Type.Array(Type.String(), { description: "Rules that match nothing." }),
|
|
234
|
+
"Correct the target rules using read or grep before retrying.",
|
|
235
|
+
),
|
|
236
|
+
line: modelFact(
|
|
237
|
+
Type.Integer({ minimum: 1, description: "Line where the conflicting match starts." }),
|
|
238
|
+
"Locate the first conflicting match when correcting the request.",
|
|
239
|
+
),
|
|
240
|
+
|
|
181
241
|
// Regex workers (regex-worker.ts).
|
|
182
|
-
timeoutMs:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
pagination: Type.Object(
|
|
186
|
-
{
|
|
187
|
-
start: Type.Integer(),
|
|
188
|
-
end: Type.Integer(),
|
|
189
|
-
totalLines: Type.Integer(),
|
|
190
|
-
nextOffset: Type.Integer(),
|
|
191
|
-
},
|
|
192
|
-
{ additionalProperties: false },
|
|
242
|
+
timeoutMs: modelFact(
|
|
243
|
+
Type.Integer({ minimum: 1 }),
|
|
244
|
+
"Narrow or simplify the timed-out pattern before retrying.",
|
|
193
245
|
),
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
246
|
+
exitCode: tuiFact(Type.Union([Type.Integer(), Type.Null()])),
|
|
247
|
+
|
|
248
|
+
// read outcome; outputLimit below is shared with grep.
|
|
249
|
+
nextOffset: modelFact(Type.Integer({ minimum: 1 }), "Use nextOffset to continue reading."),
|
|
250
|
+
lineTooLong: modelFact(
|
|
251
|
+
Type.String({ description: "Byte limit that prevented the first selected line from fitting." }),
|
|
252
|
+
"Inspect the oversized line with an appropriate tool before editing it.",
|
|
253
|
+
),
|
|
254
|
+
|
|
255
|
+
// grep outcome; matches is also replace's match count.
|
|
256
|
+
matches: modelFact(
|
|
257
|
+
Type.Integer({ minimum: 0 }),
|
|
258
|
+
"Change the pattern or scope when zero; otherwise check the total against the rows shown or the replacements intended.",
|
|
259
|
+
),
|
|
260
|
+
files: modelFact(
|
|
261
|
+
Type.Integer({ minimum: 0 }),
|
|
262
|
+
"Know how many files matched when the payload does not show every file.",
|
|
263
|
+
),
|
|
264
|
+
matchLimit: modelFact(
|
|
265
|
+
Type.Integer({ minimum: 1, description: "The match limit that stopped the search." }),
|
|
266
|
+
"Raise the limit when more matches are needed.",
|
|
267
|
+
),
|
|
268
|
+
scanLimit: modelFact(
|
|
269
|
+
Type.String({
|
|
270
|
+
description:
|
|
271
|
+
"Bytes of files read when every file was a candidate; later files were not searched.",
|
|
272
|
+
}),
|
|
273
|
+
"Narrow the search or add text every match must contain to search the remaining files.",
|
|
274
|
+
),
|
|
275
|
+
outputLimit: modelFact(
|
|
276
|
+
Type.String({ description: "The output byte budget that cut the result." }),
|
|
277
|
+
"Narrow the scope to see omitted output.",
|
|
278
|
+
),
|
|
279
|
+
linePreviewLimit: modelFact(
|
|
280
|
+
Type.Integer({ description: "UTF-16 units kept in a cut line preview." }),
|
|
281
|
+
"Read the full line before rewriting it from a partial preview.",
|
|
282
|
+
),
|
|
283
|
+
invalidUtf8: modelFact(
|
|
284
|
+
Type.Array(Type.String(), {
|
|
285
|
+
description: "Files shown as plain previews; their rows are not edit anchors.",
|
|
286
|
+
}),
|
|
287
|
+
"Do not use malformed preview rows as edit anchors.",
|
|
288
|
+
),
|
|
289
|
+
diagnostics: modelFact(
|
|
290
|
+
Type.String({ description: "Search diagnostics; results cover confirmed matches." }),
|
|
291
|
+
"Treat the result as confirmed matches only; remove the stated cause or narrow the scope to search what was missed.",
|
|
292
|
+
),
|
|
293
|
+
literalPipe: modelFact(
|
|
294
|
+
Type.Literal(true, {
|
|
295
|
+
description: "A literal pattern contains |, which matches only the | character.",
|
|
296
|
+
}),
|
|
297
|
+
"Separate pattern alternatives or keep the pattern literal.",
|
|
197
298
|
),
|
|
198
|
-
|
|
199
|
-
matches: Type.Integer({ minimum: 0 }),
|
|
200
|
-
files: Type.Integer({ minimum: 0 }),
|
|
201
|
-
scanned: Type.Union([Type.Literal("files"), Type.Literal("all")], {
|
|
202
|
-
description:
|
|
203
|
-
"Without line candidates, the files searched whole: those containing text every match needs, or every file in scope.",
|
|
204
|
-
}),
|
|
205
|
-
matchLimit: Type.Integer({ minimum: 1, description: "The match limit that stopped the search." }),
|
|
206
|
-
scanLimit: Type.String({
|
|
207
|
-
description:
|
|
208
|
-
"Bytes of files read when every file was a candidate; later files were not searched.",
|
|
209
|
-
}),
|
|
210
|
-
outputLimit: Type.String({ description: "The output byte budget that cut the result." }),
|
|
211
|
-
linePreviewLimit: Type.Integer({ description: "UTF-16 units kept in a cut line preview." }),
|
|
212
|
-
invalidUtf8: Type.Array(Type.String(), {
|
|
213
|
-
description: "Files shown as plain previews; their rows are not edit anchors.",
|
|
214
|
-
}),
|
|
215
|
-
diagnostics: Type.String({ description: "Search diagnostics; results cover confirmed matches." }),
|
|
216
|
-
literalPipe: Type.Literal(true, {
|
|
217
|
-
description: "A literal pattern contains |, which matches only the | character.",
|
|
218
|
-
}),
|
|
219
|
-
// Mutation outcome.
|
|
220
|
-
created: Type.Literal(true),
|
|
299
|
+
|
|
221
300
|
// Commit-layer observation after publication.
|
|
222
|
-
freshness:
|
|
223
|
-
|
|
301
|
+
freshness: modelFact(
|
|
302
|
+
FRESHNESS_SCHEMA,
|
|
303
|
+
"Read the file before further edits when the current content is not known to be unchanged.",
|
|
304
|
+
),
|
|
305
|
+
freshnessError: modelFact(
|
|
306
|
+
CAUSE_SCHEMA,
|
|
307
|
+
"Use the freshness recovery instruction when the post-commit observation failed.",
|
|
308
|
+
),
|
|
309
|
+
|
|
224
310
|
// Action Fusion.
|
|
225
|
-
then_run:
|
|
226
|
-
|
|
227
|
-
|
|
311
|
+
then_run: modelFact(
|
|
312
|
+
Type.Object(
|
|
313
|
+
{ status: COMMAND_STATUS_SCHEMA, output: opt(Type.String()) },
|
|
314
|
+
{ additionalProperties: false },
|
|
315
|
+
),
|
|
316
|
+
"Act on the failure the output shows, and run the command separately when it did not run.",
|
|
228
317
|
),
|
|
229
|
-
progressError: CAUSE_SCHEMA,
|
|
230
|
-
} satisfies
|
|
318
|
+
progressError: tuiFact(CAUSE_SCHEMA),
|
|
319
|
+
} as const satisfies Record<string, FactDefinition>;
|
|
231
320
|
|
|
232
321
|
type FactName = keyof typeof FACT_FIELDS;
|
|
322
|
+
type FactSchema<Name extends FactName> = (typeof FACT_FIELDS)[Name]["schema"];
|
|
323
|
+
type TuiOnlyFactName = {
|
|
324
|
+
[Name in FactName]: (typeof FACT_FIELDS)[Name]["audience"] extends "tui" ? Name : never;
|
|
325
|
+
}[FactName];
|
|
326
|
+
export type ModelOmittedField = "tool" | "path" | TuiOnlyFactName;
|
|
327
|
+
|
|
328
|
+
/** Fields whose values are kept for TUI/host but omitted from model text. */
|
|
329
|
+
export const MODEL_OMITTED_FIELDS: ReadonlySet<ModelOmittedField> = new Set<ModelOmittedField>([
|
|
330
|
+
"tool",
|
|
331
|
+
"path",
|
|
332
|
+
...Object.entries(FACT_FIELDS)
|
|
333
|
+
.filter(([, definition]) => definition.audience === "tui")
|
|
334
|
+
.map(([name]) => name as TuiOnlyFactName),
|
|
335
|
+
]);
|
|
233
336
|
|
|
234
337
|
/** Facts of one code: the named fields, each optional unless listed as required. */
|
|
235
338
|
function facts<const R extends readonly FactName[], const O extends readonly FactName[] = []>(
|
|
@@ -237,14 +340,14 @@ function facts<const R extends readonly FactName[], const O extends readonly Fac
|
|
|
237
340
|
optional?: O,
|
|
238
341
|
) {
|
|
239
342
|
const properties: TProperties = {};
|
|
240
|
-
for (const name of required) properties[name] = FACT_FIELDS[name];
|
|
241
|
-
for (const name of optional ?? []) properties[name] = opt(FACT_FIELDS[name]);
|
|
343
|
+
for (const name of required) properties[name] = FACT_FIELDS[name].schema;
|
|
344
|
+
for (const name of optional ?? []) properties[name] = opt(FACT_FIELDS[name].schema);
|
|
242
345
|
// A single mapped property set preserves required keys in TypeBox's static inference.
|
|
243
346
|
return Type.Object(
|
|
244
347
|
properties as {
|
|
245
348
|
[K in R[number] | O[number]]: K extends R[number]
|
|
246
|
-
?
|
|
247
|
-
: ReturnType<typeof Type.Optional<
|
|
349
|
+
? FactSchema<K>
|
|
350
|
+
: ReturnType<typeof Type.Optional<FactSchema<K>>>;
|
|
248
351
|
},
|
|
249
352
|
{ additionalProperties: false },
|
|
250
353
|
);
|
|
@@ -322,7 +425,7 @@ export const ERROR_DEFINITIONS = {
|
|
|
322
425
|
SYMLINK_UNRESOLVED: { facts: NONE },
|
|
323
426
|
PUBLISH_FAILED: { facts: NONE },
|
|
324
427
|
POST_PROCESS_FAILED: { facts: NONE },
|
|
325
|
-
SEARCH_INCOMPLETE: { facts: facts(["diagnostics"], ["
|
|
428
|
+
SEARCH_INCOMPLETE: { facts: facts(["diagnostics"], ["scanLimit"]) },
|
|
326
429
|
RIPGREP_FAILED: { facts: NONE },
|
|
327
430
|
UNSUPPORTED_PATH: { facts: NONE },
|
|
328
431
|
UNCLASSIFIED: { facts: NONE },
|
|
@@ -352,7 +455,7 @@ export const NEXT_GUIDELINE =
|
|
|
352
455
|
"When a tool report includes next, follow it for that result; it takes precedence over these guidelines.";
|
|
353
456
|
|
|
354
457
|
/** Text shared by success and failure: a file whose current anchors are unknown must be read first. */
|
|
355
|
-
|
|
458
|
+
const REREAD = "Read the file before further edits.";
|
|
356
459
|
|
|
357
460
|
/** Once a mutation reached or may have reached the file, a retry could apply it twice. */
|
|
358
461
|
export const PUBLICATION_NEXT = {
|
|
@@ -362,9 +465,11 @@ export const PUBLICATION_NEXT = {
|
|
|
362
465
|
} as const satisfies Record<Exclude<PublicationStatus, "NOT_PUBLISHED">, string>;
|
|
363
466
|
|
|
364
467
|
/** One fact's recovery; `except` is a value of that fact which needs none. */
|
|
365
|
-
type OutcomeRule =
|
|
366
|
-
|
|
367
|
-
|
|
468
|
+
type OutcomeRule =
|
|
469
|
+
| {
|
|
470
|
+
[F in FactName]: readonly [fact: F, next: string, except?: Static<FactSchema<F>>];
|
|
471
|
+
}[FactName]
|
|
472
|
+
| readonly [fact: "publication", next: string, except?: PublicationStatus];
|
|
368
473
|
|
|
369
474
|
/**
|
|
370
475
|
* Recovery after a successful result, by the first fact present in this order.
|
|
@@ -373,11 +478,16 @@ type OutcomeRule = {
|
|
|
373
478
|
export const OUTCOME_NEXT: readonly OutcomeRule[] = [
|
|
374
479
|
// A file that no longer exists has no anchors to refresh.
|
|
375
480
|
["freshness", REREAD, "missing"],
|
|
481
|
+
[
|
|
482
|
+
"publication",
|
|
483
|
+
"The file already has this content; nothing was written, so do not repeat the call.",
|
|
484
|
+
"PUBLISHED",
|
|
485
|
+
],
|
|
376
486
|
[
|
|
377
487
|
"lineTooLong",
|
|
378
488
|
"Inspect the line in chunks with bash, or use replace for a known literal or regex change; a smaller limit cannot split a line.",
|
|
379
489
|
],
|
|
380
|
-
["
|
|
490
|
+
["nextOffset", "If you need more lines, set offset to nextOffset."],
|
|
381
491
|
// Ahead of matchLimit: once the byte budget cuts the output, raising limit shows nothing more.
|
|
382
492
|
["outputLimit", "Narrow path, glob, or pattern to see the omitted output."],
|
|
383
493
|
["matchLimit", "If you need more matches, raise limit to include rows after the last one shown."],
|
|
@@ -394,27 +504,26 @@ export const OUTCOME_NEXT: readonly OutcomeRule[] = [
|
|
|
394
504
|
|
|
395
505
|
/** The report envelope and facts, in output order; `next` is always last. */
|
|
396
506
|
export const REPORT_SCHEMA = Type.Object({
|
|
397
|
-
error: opt(
|
|
507
|
+
error: opt(literalUnion(ERROR_CODES)),
|
|
398
508
|
tool: Type.String(),
|
|
399
509
|
path: opt(Type.Union([Type.String(), Type.Array(Type.String())])),
|
|
400
510
|
publication: opt(PUBLICATION_SCHEMA),
|
|
401
511
|
message: opt(Type.String()),
|
|
402
512
|
cause: opt(CAUSE_SCHEMA),
|
|
403
513
|
...(Object.fromEntries(
|
|
404
|
-
Object.entries(FACT_FIELDS).map(([name,
|
|
405
|
-
) as { [K in FactName]: ReturnType<typeof Type.Optional<
|
|
514
|
+
Object.entries(FACT_FIELDS).map(([name, definition]) => [name, opt(definition.schema)]),
|
|
515
|
+
) as { [K in FactName]: ReturnType<typeof Type.Optional<FactSchema<K>>> }),
|
|
406
516
|
next: opt(Type.String()),
|
|
407
517
|
});
|
|
408
|
-
type ReportFields =
|
|
518
|
+
type ReportFields = Static<typeof REPORT_SCHEMA>;
|
|
409
519
|
|
|
410
520
|
const SUCCESS_DEFINITIONS = {
|
|
411
|
-
read: facts([], ["
|
|
521
|
+
read: facts([], ["nextOffset", "outputLimit", "lineTooLong"]),
|
|
412
522
|
grep: facts(
|
|
413
523
|
[],
|
|
414
524
|
[
|
|
415
525
|
"matches",
|
|
416
526
|
"files",
|
|
417
|
-
"scanned",
|
|
418
527
|
"matchLimit",
|
|
419
528
|
"scanLimit",
|
|
420
529
|
"outputLimit",
|
|
@@ -426,7 +535,7 @@ const SUCCESS_DEFINITIONS = {
|
|
|
426
535
|
),
|
|
427
536
|
edit: facts([]),
|
|
428
537
|
replace: facts([], ["matches"]),
|
|
429
|
-
write: facts([]
|
|
538
|
+
write: facts([]),
|
|
430
539
|
} as const;
|
|
431
540
|
export type ReportTool = keyof typeof SUCCESS_DEFINITIONS;
|
|
432
541
|
/** Tools whose reports carry publication, freshness, and the then_run outcome. */
|
|
@@ -435,7 +544,7 @@ export type MutationToolName = (typeof MUTATION_TOOLS)[number];
|
|
|
435
544
|
/** Argument rejections may omit message; Pi supplies none for them. */
|
|
436
545
|
const MESSAGE_OPTIONAL = "INVALID_ARGUMENTS" satisfies ErrorCode;
|
|
437
546
|
|
|
438
|
-
const TOOL_SCHEMA =
|
|
547
|
+
const TOOL_SCHEMA = literalUnion(Object.keys(SUCCESS_DEFINITIONS) as ReportTool[]);
|
|
439
548
|
const COMMON_WIRE_FIELDS = {
|
|
440
549
|
tool: TOOL_SCHEMA,
|
|
441
550
|
path: REPORT_SCHEMA.properties.path,
|
|
@@ -475,6 +584,19 @@ const SUCCESS_SCHEMAS = Object.entries(SUCCESS_DEFINITIONS).map(([tool, schema])
|
|
|
475
584
|
/** Closed records after the originating call supplies the tool; failure facts remain code-specific. */
|
|
476
585
|
export const WIRE_REPORT_SCHEMA = Type.Union([...FAILURE_SCHEMAS, ...SUCCESS_SCHEMAS]);
|
|
477
586
|
|
|
587
|
+
type SuccessFactNames = {
|
|
588
|
+
[Tool in ReportTool]: keyof Static<(typeof SUCCESS_DEFINITIONS)[Tool]>;
|
|
589
|
+
}[ReportTool] &
|
|
590
|
+
string;
|
|
591
|
+
type ErrorFactNames = {
|
|
592
|
+
[Code in ErrorCode]: keyof Static<(typeof ERROR_DEFINITIONS)[Code]["facts"]>;
|
|
593
|
+
}[ErrorCode] &
|
|
594
|
+
string;
|
|
595
|
+
type MutationWireFactNames = keyof Fields<typeof MUTATION_WIRE_FIELDS> & string;
|
|
596
|
+
type UnusedFactNames = Exclude<FactName, SuccessFactNames | ErrorFactNames | MutationWireFactNames>;
|
|
597
|
+
// Compilation fails here, naming the fact, when no tool, code, or mutation field carries it.
|
|
598
|
+
({}) satisfies Record<UnusedFactNames, never>;
|
|
599
|
+
|
|
478
600
|
// Static counterparts of the per-tool and per-code wire schemas above, built from the same fields.
|
|
479
601
|
type Fields<P extends TProperties> = Static<TObject<P>>;
|
|
480
602
|
type Envelope = Omit<Fields<typeof COMMON_WIRE_FIELDS>, "tool">;
|