@mrclrchtr/supi-review 3.1.0 → 4.0.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 +41 -20
- package/node_modules/@mrclrchtr/supi-core/package.json +2 -4
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +0 -4
- package/node_modules/@mrclrchtr/supi-core/src/evidence-badge.ts +3 -2
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +0 -4
- package/node_modules/@mrclrchtr/supi-core/src/llm.ts +0 -10
- package/node_modules/@mrclrchtr/supi-core/src/path-utils.ts +19 -15
- package/package.json +2 -2
- package/src/git-choices.ts +42 -0
- package/src/git-command.ts +172 -2
- package/src/git.ts +126 -294
- package/src/history/collect.ts +15 -6
- package/src/review-input.ts +36 -0
- package/src/review-limits.ts +12 -0
- package/src/review-path.ts +18 -12
- package/src/review-result.ts +26 -5
- package/src/review.ts +150 -62
- package/src/session/review-artifact-store.ts +97 -0
- package/src/session/review-plan-store.ts +93 -12
- package/src/target/change-metadata.ts +125 -0
- package/src/target/diff.ts +43 -0
- package/src/target/file-manifest.ts +40 -0
- package/src/target/packet.ts +17 -6
- package/src/target/resolve.ts +209 -0
- package/src/tool/agent-review-schemas.ts +9 -4
- package/src/tool/agent-review-tools.ts +46 -14
- package/src/tool/child-failure-diagnostics.ts +26 -49
- package/src/tool/child-lifecycle-trace.ts +3 -16
- package/src/tool/child-session-runner.ts +28 -11
- package/src/tool/child-usage.ts +73 -0
- package/src/tool/diagnostic-sanitizer.ts +35 -0
- package/src/tool/output-page.ts +26 -0
- package/src/tool/planner-runner.ts +28 -10
- package/src/tool/review-output-tool.ts +93 -0
- package/src/tool/review-runner.ts +9 -7
- package/src/tool/review-tools.ts +90 -12
- package/src/tool/review-workflow.ts +146 -82
- package/src/tool/schemas.ts +24 -5
- package/src/tool/session-lifecycle.ts +44 -54
- package/src/tool/usage-format.ts +15 -0
- package/src/tui/common.ts +8 -13
- package/src/tui/prepare.ts +57 -31
- package/src/tui/run.ts +13 -3
- package/src/types.ts +60 -21
- package/node_modules/@mrclrchtr/supi-core/src/abort-utils.ts +0 -31
- package/node_modules/@mrclrchtr/supi-core/src/substrate-types.ts +0 -11
- package/node_modules/@mrclrchtr/supi-core/src/types.ts +0 -2
package/src/tool/review-tools.ts
CHANGED
|
@@ -2,9 +2,17 @@ import { StringEnum } from "@earendil-works/pi-ai";
|
|
|
2
2
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
4
|
import { listReviewFiles, readReviewDiff, readReviewFile, searchReviewFiles } from "../git.ts";
|
|
5
|
+
import { REVIEW_LIMITS } from "../review-limits.ts";
|
|
5
6
|
import { normalizeReviewSubmission } from "../review-result.ts";
|
|
7
|
+
import { formatReviewChange } from "../target/file-manifest.ts";
|
|
6
8
|
import type { ReviewSnapshot, ReviewSubmission } from "../types.ts";
|
|
7
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_PAGE_CHARACTERS,
|
|
11
|
+
MAX_PAGE_CHARACTERS,
|
|
12
|
+
MAX_PAGE_LINES,
|
|
13
|
+
pageText,
|
|
14
|
+
selectLineRange,
|
|
15
|
+
} from "./output-page.ts";
|
|
8
16
|
import { reviewSubmissionSchema } from "./schemas.ts";
|
|
9
17
|
|
|
10
18
|
const paginationProperties = {
|
|
@@ -21,7 +29,12 @@ const paginationProperties = {
|
|
|
21
29
|
),
|
|
22
30
|
};
|
|
23
31
|
|
|
24
|
-
function pagedResult(
|
|
32
|
+
function pagedResult(
|
|
33
|
+
text: string,
|
|
34
|
+
offset?: number,
|
|
35
|
+
limit?: number,
|
|
36
|
+
extraDetails: Record<string, unknown> = {},
|
|
37
|
+
) {
|
|
25
38
|
const page = pageText(text, offset, limit);
|
|
26
39
|
return {
|
|
27
40
|
content: [{ type: "text" as const, text: page.text }],
|
|
@@ -29,6 +42,7 @@ function pagedResult(text: string, offset?: number, limit?: number) {
|
|
|
29
42
|
offset: page.offset,
|
|
30
43
|
nextOffset: page.nextOffset,
|
|
31
44
|
totalCharacters: page.totalCharacters,
|
|
45
|
+
...extraDetails,
|
|
32
46
|
},
|
|
33
47
|
};
|
|
34
48
|
}
|
|
@@ -40,6 +54,18 @@ export function createReviewTools(
|
|
|
40
54
|
submission: { value?: ReviewSubmission },
|
|
41
55
|
) {
|
|
42
56
|
return [
|
|
57
|
+
defineTool({
|
|
58
|
+
name: "list_review_changes",
|
|
59
|
+
label: "List Review Changes",
|
|
60
|
+
description: "List every changed path with Git status and per-file +/- statistics.",
|
|
61
|
+
parameters: Type.Object(paginationProperties, { additionalProperties: false }),
|
|
62
|
+
execute: async (_id, args) =>
|
|
63
|
+
pagedResult(
|
|
64
|
+
snapshot.changes.map((change) => formatReviewChange(change)).join("\n"),
|
|
65
|
+
args.offset,
|
|
66
|
+
args.limit,
|
|
67
|
+
),
|
|
68
|
+
}),
|
|
43
69
|
defineTool({
|
|
44
70
|
name: "list_review_files",
|
|
45
71
|
label: "List Review Files",
|
|
@@ -51,9 +77,15 @@ export function createReviewTools(
|
|
|
51
77
|
defineTool({
|
|
52
78
|
name: "read_review_diff",
|
|
53
79
|
label: "Read Review Diff",
|
|
54
|
-
description:
|
|
80
|
+
description:
|
|
81
|
+
"Read the exact target diff. Omit path for the bounded paged full diff, or provide one changed path; oversized full diffs require per-path reads.",
|
|
55
82
|
parameters: Type.Object(
|
|
56
|
-
{
|
|
83
|
+
{
|
|
84
|
+
path: Type.Optional(
|
|
85
|
+
Type.String({ minLength: 1, maxLength: REVIEW_LIMITS.locationPathCharacters }),
|
|
86
|
+
),
|
|
87
|
+
...paginationProperties,
|
|
88
|
+
},
|
|
57
89
|
{ additionalProperties: false },
|
|
58
90
|
),
|
|
59
91
|
execute: async (_id, args) =>
|
|
@@ -62,40 +94,86 @@ export function createReviewTools(
|
|
|
62
94
|
defineTool({
|
|
63
95
|
name: "read_review_file",
|
|
64
96
|
label: "Read Review File",
|
|
65
|
-
description:
|
|
97
|
+
description:
|
|
98
|
+
"Read a before/after target file. startLine/lineCount select a range; offset pages within that selection.",
|
|
66
99
|
parameters: Type.Object(
|
|
67
100
|
{
|
|
68
|
-
path: Type.String({ minLength: 1 }),
|
|
101
|
+
path: Type.String({ minLength: 1, maxLength: REVIEW_LIMITS.locationPathCharacters }),
|
|
69
102
|
side: Type.Optional(
|
|
70
103
|
StringEnum(["before", "after"] as const, {
|
|
71
104
|
default: "after",
|
|
72
105
|
description: "Target side to read; defaults to after.",
|
|
73
106
|
}),
|
|
74
107
|
),
|
|
108
|
+
startLine: Type.Optional(
|
|
109
|
+
Type.Integer({ minimum: 1, description: "1-based first line to select." }),
|
|
110
|
+
),
|
|
111
|
+
lineCount: Type.Optional(
|
|
112
|
+
Type.Integer({
|
|
113
|
+
minimum: 1,
|
|
114
|
+
maximum: MAX_PAGE_LINES,
|
|
115
|
+
description: "Lines to select; requires startLine and defaults to 200.",
|
|
116
|
+
}),
|
|
117
|
+
),
|
|
75
118
|
...paginationProperties,
|
|
76
119
|
},
|
|
77
120
|
{ additionalProperties: false },
|
|
78
121
|
),
|
|
79
122
|
execute: async (_id, args) => {
|
|
80
|
-
|
|
81
|
-
|
|
123
|
+
if (args.lineCount !== undefined && args.startLine === undefined) {
|
|
124
|
+
throw new Error("lineCount requires startLine.");
|
|
125
|
+
}
|
|
126
|
+
const content =
|
|
127
|
+
(await readReviewFile(cwd, snapshot, args.path, args.side ?? "after")) ??
|
|
128
|
+
"[file unavailable on this side]";
|
|
129
|
+
if (args.startLine === undefined) {
|
|
130
|
+
return pagedResult(content, args.offset, args.limit);
|
|
131
|
+
}
|
|
132
|
+
const selected = selectLineRange(content, args.startLine, args.lineCount);
|
|
133
|
+
return pagedResult(selected.text, args.offset, args.limit, {
|
|
134
|
+
startLine: selected.startLine,
|
|
135
|
+
endLine: selected.endLine,
|
|
136
|
+
totalLines: selected.totalLines,
|
|
137
|
+
});
|
|
82
138
|
},
|
|
83
139
|
}),
|
|
84
140
|
defineTool({
|
|
85
141
|
name: "search_review_files",
|
|
86
142
|
label: "Search Review Files",
|
|
87
|
-
description:
|
|
143
|
+
description:
|
|
144
|
+
"Search before/after target text using literal or extended-regex mode. Use offset to continue.",
|
|
88
145
|
parameters: Type.Object(
|
|
89
146
|
{
|
|
90
|
-
query: Type.String({
|
|
91
|
-
|
|
147
|
+
query: Type.String({
|
|
148
|
+
minLength: 1,
|
|
149
|
+
maxLength: REVIEW_LIMITS.searchQueryCharacters,
|
|
150
|
+
}),
|
|
151
|
+
path: Type.Optional(
|
|
152
|
+
Type.String({ minLength: 1, maxLength: REVIEW_LIMITS.locationPathCharacters }),
|
|
153
|
+
),
|
|
154
|
+
side: Type.Optional(
|
|
155
|
+
StringEnum(["before", "after"] as const, {
|
|
156
|
+
default: "after",
|
|
157
|
+
description: "Target side to search; defaults to after.",
|
|
158
|
+
}),
|
|
159
|
+
),
|
|
160
|
+
mode: Type.Optional(
|
|
161
|
+
StringEnum(["literal", "regex"] as const, {
|
|
162
|
+
default: "literal",
|
|
163
|
+
description: "Literal or extended regular expression search.",
|
|
164
|
+
}),
|
|
165
|
+
),
|
|
92
166
|
...paginationProperties,
|
|
93
167
|
},
|
|
94
168
|
{ additionalProperties: false },
|
|
95
169
|
),
|
|
96
170
|
execute: async (_id, args) =>
|
|
97
171
|
pagedResult(
|
|
98
|
-
(await searchReviewFiles(cwd, snapshot, args.query,
|
|
172
|
+
(await searchReviewFiles(cwd, snapshot, args.query, {
|
|
173
|
+
path: args.path,
|
|
174
|
+
side: args.side ?? "after",
|
|
175
|
+
mode: args.mode ?? "literal",
|
|
176
|
+
})) || "No matches.",
|
|
99
177
|
args.offset,
|
|
100
178
|
args.limit,
|
|
101
179
|
),
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { resolveReviewSnapshot, summarizeReviewSnapshot } from "../git.ts";
|
|
2
|
+
import { normalizeReviewInput } from "../review-input.ts";
|
|
2
3
|
import { normalizeReviewSubmission } from "../review-result.ts";
|
|
3
|
-
import type { ReviewPlanStore } from "../session/review-plan-store.ts";
|
|
4
|
+
import type { ReviewPlanLease, ReviewPlanStore } from "../session/review-plan-store.ts";
|
|
5
|
+
import { buildFileManifest } from "../target/file-manifest.ts";
|
|
4
6
|
import { buildReviewPacket } from "../target/packet.ts";
|
|
5
7
|
import type {
|
|
6
8
|
PlannerDraft,
|
|
9
|
+
PlannerRunResult,
|
|
7
10
|
PlanningRecord,
|
|
8
11
|
ReviewBatchDetails,
|
|
9
12
|
ReviewInput,
|
|
@@ -12,7 +15,11 @@ import type {
|
|
|
12
15
|
ReviewTargetSpec,
|
|
13
16
|
ReviewTaskResult,
|
|
14
17
|
} from "../types.ts";
|
|
15
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
createEarlyCancellationDiagnostics,
|
|
20
|
+
createUnobservedChildFailureDiagnostics,
|
|
21
|
+
} from "./child-failure-diagnostics.ts";
|
|
22
|
+
import { combineUsage } from "./child-usage.ts";
|
|
16
23
|
import { PLANNER_PROMPT_VERSION, runPlanner } from "./planner-runner.ts";
|
|
17
24
|
import { runReviewer } from "./review-runner.ts";
|
|
18
25
|
|
|
@@ -60,59 +67,16 @@ export interface PreparedRunInput {
|
|
|
60
67
|
/** Discriminated union accepted by `runReview` for both Direct and Prepared paths. */
|
|
61
68
|
export type RunReviewInput = DirectRunInput | PreparedRunInput;
|
|
62
69
|
|
|
63
|
-
const MAX_PLANNER_FILE_COUNT = 200;
|
|
64
|
-
const MAX_PLANNER_FILE_CHARS = 8_000;
|
|
65
|
-
|
|
66
|
-
/** Canonicalize and semantically validate review input for every adapter. */
|
|
67
|
-
export function normalizeReviewInput(review: ReviewInput): ReviewInput {
|
|
68
|
-
const sharedContext = review.sharedContext?.trim();
|
|
69
|
-
const tasks = review.tasks.map((task) => ({
|
|
70
|
-
id: task.id.trim(),
|
|
71
|
-
instructions: task.instructions.trim(),
|
|
72
|
-
}));
|
|
73
|
-
if (tasks.length < 1 || tasks.length > 4)
|
|
74
|
-
throw new Error("Provide between one and four review tasks.");
|
|
75
|
-
if (tasks.some((task) => !task.id || !task.instructions)) {
|
|
76
|
-
throw new Error("Review task ids and instructions must not be blank.");
|
|
77
|
-
}
|
|
78
|
-
if (tasks.some((task) => task.id.length > 64)) {
|
|
79
|
-
throw new Error("Review task ids must not exceed 64 characters.");
|
|
80
|
-
}
|
|
81
|
-
if (new Set(tasks.map((task) => task.id)).size !== tasks.length) {
|
|
82
|
-
throw new Error("Review task ids must be unique.");
|
|
83
|
-
}
|
|
84
|
-
return { ...(sharedContext ? { sharedContext } : {}), tasks };
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function plannerFileManifest(files: string[]): string[] {
|
|
88
|
-
const lines: string[] = [];
|
|
89
|
-
let size = 0;
|
|
90
|
-
for (const file of files) {
|
|
91
|
-
const line = `- ${JSON.stringify(file)}`;
|
|
92
|
-
if (
|
|
93
|
-
lines.length >= MAX_PLANNER_FILE_COUNT ||
|
|
94
|
-
size + line.length + 1 > MAX_PLANNER_FILE_CHARS - 100
|
|
95
|
-
) {
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
lines.push(line);
|
|
99
|
-
size += line.length + 1;
|
|
100
|
-
}
|
|
101
|
-
const omitted = files.length - lines.length;
|
|
102
|
-
if (omitted > 0) lines.push(`- … ${omitted} additional file(s) omitted`);
|
|
103
|
-
return lines;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
70
|
function plannerPrompt(snapshot: ReviewSnapshot, context: string): string {
|
|
107
71
|
return [
|
|
108
72
|
"# Review Planning Input",
|
|
109
73
|
"",
|
|
110
74
|
`Target: ${snapshot.title}`,
|
|
111
|
-
`Changed files: ${snapshot.
|
|
75
|
+
`Changed files: ${snapshot.changes.length}`,
|
|
112
76
|
`Diff stats: +${snapshot.stats.additions} / -${snapshot.stats.deletions}`,
|
|
113
77
|
"",
|
|
114
|
-
"## Changed
|
|
115
|
-
...
|
|
78
|
+
"## Changed-path inventory",
|
|
79
|
+
...buildFileManifest(snapshot.changes),
|
|
116
80
|
"",
|
|
117
81
|
"## Bounded session conversation",
|
|
118
82
|
context || "No session conversation was available.",
|
|
@@ -125,6 +89,67 @@ function snapshotErrorReason(error: unknown): string {
|
|
|
125
89
|
return "No reviewable changes found.";
|
|
126
90
|
}
|
|
127
91
|
|
|
92
|
+
interface PlannerPreparation {
|
|
93
|
+
draft?: PlannerDraft;
|
|
94
|
+
failure?: Exclude<PlannerRunResult, { kind: "success" }>;
|
|
95
|
+
canceled?: Extract<PlannerRunResult, { kind: "canceled" }>;
|
|
96
|
+
usage?: PlannerRunResult["usage"];
|
|
97
|
+
modelId?: string;
|
|
98
|
+
promptVersion?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function preparePlanner(
|
|
102
|
+
input: PrepareReviewInput,
|
|
103
|
+
snapshot: ReviewSnapshot,
|
|
104
|
+
): Promise<PlannerPreparation> {
|
|
105
|
+
if (input.planning === "none") return {};
|
|
106
|
+
if (!input.plannerModel) {
|
|
107
|
+
return { failure: { kind: "failed", failureCode: "session-creation-failed" } };
|
|
108
|
+
}
|
|
109
|
+
input.onUpdate?.({
|
|
110
|
+
content: [{ type: "text", text: "Running planner…" }],
|
|
111
|
+
details: {},
|
|
112
|
+
});
|
|
113
|
+
const modelId = input.plannerModel.canonicalId;
|
|
114
|
+
const promptVersion = PLANNER_PROMPT_VERSION;
|
|
115
|
+
let result: PlannerRunResult;
|
|
116
|
+
try {
|
|
117
|
+
result = await runPlanner({
|
|
118
|
+
cwd: snapshot.repositoryRoot,
|
|
119
|
+
model: input.plannerModel.model,
|
|
120
|
+
prompt: plannerPrompt(snapshot, input.plannerContext),
|
|
121
|
+
signal: input.signal,
|
|
122
|
+
});
|
|
123
|
+
} catch {
|
|
124
|
+
if (input.signal?.aborted) {
|
|
125
|
+
return {
|
|
126
|
+
canceled: { kind: "canceled", diagnostics: createEarlyCancellationDiagnostics() },
|
|
127
|
+
modelId,
|
|
128
|
+
promptVersion,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
132
|
+
failure: {
|
|
133
|
+
kind: "failed",
|
|
134
|
+
failureCode: "unexpected-runner-failure",
|
|
135
|
+
diagnostics: createUnobservedChildFailureDiagnostics(),
|
|
136
|
+
},
|
|
137
|
+
modelId,
|
|
138
|
+
promptVersion,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
const identity = {
|
|
142
|
+
...(result.usage ? { usage: result.usage } : {}),
|
|
143
|
+
modelId,
|
|
144
|
+
promptVersion,
|
|
145
|
+
};
|
|
146
|
+
if (result.kind === "canceled") return { canceled: result, ...identity };
|
|
147
|
+
if (result.kind === "success") {
|
|
148
|
+
return { draft: normalizeReviewInput(result.draft), ...identity };
|
|
149
|
+
}
|
|
150
|
+
return { failure: result, ...identity };
|
|
151
|
+
}
|
|
152
|
+
|
|
128
153
|
/** Resolve and store a one-shot plan, optionally asking the advisory Planner for tasks. */
|
|
129
154
|
export async function prepareReview(input: PrepareReviewInput) {
|
|
130
155
|
input.onUpdate?.({
|
|
@@ -138,30 +163,18 @@ export async function prepareReview(input: PrepareReviewInput) {
|
|
|
138
163
|
return { kind: "no-target" as const, reason: snapshotErrorReason(error) };
|
|
139
164
|
}
|
|
140
165
|
if (!snapshot) return { kind: "no-target" as const, reason: "No reviewable changes found." };
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
if (!input.plannerModel) throw new Error("A configured Planner model is required.");
|
|
144
|
-
input.onUpdate?.({
|
|
145
|
-
content: [{ type: "text", text: "Running planner…" }],
|
|
146
|
-
details: {},
|
|
147
|
-
});
|
|
148
|
-
const result = await runPlanner({
|
|
149
|
-
cwd: input.cwd,
|
|
150
|
-
model: input.plannerModel.model,
|
|
151
|
-
prompt: plannerPrompt(snapshot, input.plannerContext),
|
|
152
|
-
signal: input.signal,
|
|
153
|
-
});
|
|
154
|
-
if (result.kind !== "success") return { kind: "planner-failed" as const, result };
|
|
155
|
-
plannerDraft = normalizeReviewInput(result.draft);
|
|
156
|
-
}
|
|
166
|
+
const planning = await preparePlanner(input, snapshot);
|
|
167
|
+
if (planning.canceled) return { kind: "canceled" as const, result: planning.canceled };
|
|
157
168
|
const plan = input.planStore.create({
|
|
158
169
|
snapshot,
|
|
159
170
|
reviewerModel: input.reviewerModel,
|
|
160
|
-
...(
|
|
161
|
-
...(
|
|
162
|
-
...(
|
|
171
|
+
...(planning.draft ? { plannerDraft: planning.draft } : {}),
|
|
172
|
+
...(planning.failure ? { plannerFailure: planning.failure } : {}),
|
|
173
|
+
...(planning.usage ? { plannerUsage: planning.usage } : {}),
|
|
174
|
+
...(planning.modelId ? { plannerModelId: planning.modelId } : {}),
|
|
175
|
+
...(planning.promptVersion ? { plannerPromptVersion: planning.promptVersion } : {}),
|
|
163
176
|
});
|
|
164
|
-
return { kind: "prepared" as const, plan };
|
|
177
|
+
return { kind: "prepared" as const, plan, ...(planning.usage ? { usage: planning.usage } : {}) };
|
|
165
178
|
}
|
|
166
179
|
|
|
167
180
|
function toTaskResult(
|
|
@@ -169,7 +182,12 @@ function toTaskResult(
|
|
|
169
182
|
packetHash: string,
|
|
170
183
|
result: Awaited<ReturnType<typeof runReviewer>>,
|
|
171
184
|
): ReviewTaskResult {
|
|
172
|
-
const identity = {
|
|
185
|
+
const identity = {
|
|
186
|
+
taskId,
|
|
187
|
+
packetHash,
|
|
188
|
+
modelId: result.modelId,
|
|
189
|
+
...(result.usage ? { usage: result.usage } : {}),
|
|
190
|
+
};
|
|
173
191
|
if (result.kind === "success") {
|
|
174
192
|
const normalized = normalizeReviewSubmission(result.submission);
|
|
175
193
|
return {
|
|
@@ -199,6 +217,14 @@ function toTaskResult(
|
|
|
199
217
|
};
|
|
200
218
|
}
|
|
201
219
|
|
|
220
|
+
function emitUpdate(onUpdate: OnUpdate | undefined, result: Parameters<OnUpdate>[0]): void {
|
|
221
|
+
try {
|
|
222
|
+
onUpdate?.(result);
|
|
223
|
+
} catch {
|
|
224
|
+
// Progress presentation cannot change review execution semantics.
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
202
228
|
// biome-ignore lint/complexity/useMaxParams: compact internal fan-out helper
|
|
203
229
|
async function execute(
|
|
204
230
|
cwd: string,
|
|
@@ -223,11 +249,21 @@ async function execute(
|
|
|
223
249
|
prompt: packet.prompt,
|
|
224
250
|
model,
|
|
225
251
|
signal,
|
|
252
|
+
onProgress: (progress) =>
|
|
253
|
+
emitUpdate(onUpdate, {
|
|
254
|
+
content: [
|
|
255
|
+
{
|
|
256
|
+
type: "text",
|
|
257
|
+
text: `Task ${task.id}: ${progress.turns} turns, ${progress.toolUses} tool uses${progress.tokens ? `, ${progress.tokens.total} tokens` : ""}`,
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
details: { taskId: task.id, progress, completedCount, totalCount },
|
|
261
|
+
}),
|
|
226
262
|
});
|
|
227
263
|
const taskResult = toTaskResult(task.id, packet.packetHash, result);
|
|
228
264
|
completedCount++;
|
|
229
265
|
const verb = taskResult.status === "completed" ? "complete" : taskResult.status;
|
|
230
|
-
onUpdate
|
|
266
|
+
emitUpdate(onUpdate, {
|
|
231
267
|
content: [
|
|
232
268
|
{ type: "text", text: `Task ${task.id} ${verb} (${completedCount} of ${totalCount})` },
|
|
233
269
|
],
|
|
@@ -244,7 +280,7 @@ async function execute(
|
|
|
244
280
|
diagnostics: createUnobservedChildFailureDiagnostics(),
|
|
245
281
|
};
|
|
246
282
|
completedCount++;
|
|
247
|
-
onUpdate
|
|
283
|
+
emitUpdate(onUpdate, {
|
|
248
284
|
content: [
|
|
249
285
|
{
|
|
250
286
|
type: "text",
|
|
@@ -266,6 +302,7 @@ export async function runReview(input: RunReviewInput) {
|
|
|
266
302
|
let review: ReviewInput;
|
|
267
303
|
let model: ReviewModelSelection;
|
|
268
304
|
let planning: PlanningRecord | undefined;
|
|
305
|
+
let lease: ReviewPlanLease | undefined;
|
|
269
306
|
let provenance: ReviewBatchDetails["provenance"] = "caller-supplied";
|
|
270
307
|
|
|
271
308
|
if (input.mode === "direct") {
|
|
@@ -280,11 +317,11 @@ export async function runReview(input: RunReviewInput) {
|
|
|
280
317
|
review = normalizeReviewInput(input.review);
|
|
281
318
|
model = input.reviewerModel;
|
|
282
319
|
} else {
|
|
283
|
-
const plan = input.planStore.
|
|
320
|
+
const plan = input.planStore.peek(input.planId);
|
|
284
321
|
if (!plan) {
|
|
285
322
|
return {
|
|
286
323
|
kind: "invalid" as const,
|
|
287
|
-
reason: `Review Plan ${input.planId} was not found or was
|
|
324
|
+
reason: `Review Plan ${input.planId} was not found, is already running, or was consumed.`,
|
|
288
325
|
};
|
|
289
326
|
}
|
|
290
327
|
if (input.decision.kind === "accept-draft" && !plan.plannerDraft) {
|
|
@@ -297,21 +334,47 @@ export async function runReview(input: RunReviewInput) {
|
|
|
297
334
|
if (!selectedReview) {
|
|
298
335
|
return { kind: "invalid" as const, reason: "This plan has no Planner Draft." };
|
|
299
336
|
}
|
|
300
|
-
|
|
337
|
+
lease = input.planStore.acquire(input.planId);
|
|
338
|
+
if (!lease) {
|
|
339
|
+
return {
|
|
340
|
+
kind: "invalid" as const,
|
|
341
|
+
reason: `Review Plan ${input.planId} is already running.`,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
snapshot = lease.plan.snapshot;
|
|
301
345
|
review = selectedReview;
|
|
302
|
-
model = plan.reviewerModel;
|
|
303
|
-
|
|
304
|
-
if (plan.plannerDraft && plan.plannerModelId && plan.plannerPromptVersion) {
|
|
346
|
+
model = lease.plan.reviewerModel;
|
|
347
|
+
provenance = input.decision.kind === "accept-draft" ? "planner-assisted" : "caller-supplied";
|
|
348
|
+
if (lease.plan.plannerDraft && lease.plan.plannerModelId && lease.plan.plannerPromptVersion) {
|
|
305
349
|
planning = {
|
|
306
|
-
promptVersion: plan.plannerPromptVersion,
|
|
307
|
-
modelId: plan.plannerModelId,
|
|
308
|
-
|
|
350
|
+
promptVersion: lease.plan.plannerPromptVersion,
|
|
351
|
+
modelId: lease.plan.plannerModelId,
|
|
352
|
+
...(lease.plan.plannerUsage ? { usage: lease.plan.plannerUsage } : {}),
|
|
353
|
+
draft: lease.plan.plannerDraft,
|
|
309
354
|
effectiveReview: review,
|
|
310
355
|
decision: input.decision.kind,
|
|
311
356
|
};
|
|
312
357
|
}
|
|
313
358
|
}
|
|
314
359
|
|
|
360
|
+
let results: ReviewTaskResult[];
|
|
361
|
+
try {
|
|
362
|
+
results = await execute(
|
|
363
|
+
snapshot.repositoryRoot,
|
|
364
|
+
snapshot,
|
|
365
|
+
review,
|
|
366
|
+
model,
|
|
367
|
+
input.signal,
|
|
368
|
+
input.onUpdate,
|
|
369
|
+
);
|
|
370
|
+
} catch (error) {
|
|
371
|
+
if (lease && input.mode === "prepared") input.planStore.release(lease);
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
if (lease && input.mode === "prepared") {
|
|
375
|
+
if (results.some((result) => result.status === "completed")) input.planStore.consume(lease);
|
|
376
|
+
else input.planStore.release(lease);
|
|
377
|
+
}
|
|
315
378
|
const details: ReviewBatchDetails = {
|
|
316
379
|
kind: "review-batch",
|
|
317
380
|
mode: input.mode,
|
|
@@ -319,7 +382,8 @@ export async function runReview(input: RunReviewInput) {
|
|
|
319
382
|
snapshot: summarizeReviewSnapshot(snapshot),
|
|
320
383
|
review,
|
|
321
384
|
...(planning ? { planning } : {}),
|
|
322
|
-
results
|
|
385
|
+
results,
|
|
323
386
|
};
|
|
324
|
-
|
|
387
|
+
const usage = combineUsage(results.map((result) => result.usage));
|
|
388
|
+
return { kind: "completed" as const, details, ...(usage ? { usage } : {}) };
|
|
325
389
|
}
|
package/src/tool/schemas.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { StringEnum } from "@earendil-works/pi-ai";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
+
import { REVIEW_LIMITS } from "../review-limits.ts";
|
|
3
4
|
|
|
4
5
|
/** TypeBox schema for one caller-defined review task (provider-visible). */
|
|
5
6
|
export const reviewTaskSchema = Type.Object(
|
|
6
7
|
{
|
|
7
8
|
id: Type.String({
|
|
8
9
|
minLength: 1,
|
|
9
|
-
maxLength:
|
|
10
|
+
maxLength: REVIEW_LIMITS.taskIdCharacters,
|
|
10
11
|
description: "Stable caller-defined task id, such as standards or spec.",
|
|
11
12
|
}),
|
|
12
13
|
instructions: Type.String({
|
|
13
14
|
minLength: 1,
|
|
15
|
+
maxLength: REVIEW_LIMITS.taskInstructionCharacters,
|
|
14
16
|
description: "Complete freeform methodology and acceptance instructions for this task.",
|
|
15
17
|
}),
|
|
16
18
|
},
|
|
@@ -21,7 +23,10 @@ export const reviewTaskSchema = Type.Object(
|
|
|
21
23
|
export const reviewInputSchema = Type.Object(
|
|
22
24
|
{
|
|
23
25
|
sharedContext: Type.Optional(
|
|
24
|
-
Type.String({
|
|
26
|
+
Type.String({
|
|
27
|
+
maxLength: REVIEW_LIMITS.sharedContextCharacters,
|
|
28
|
+
description: "Optional context shared unchanged with every task.",
|
|
29
|
+
}),
|
|
25
30
|
),
|
|
26
31
|
tasks: Type.Array(reviewTaskSchema, {
|
|
27
32
|
minItems: 1,
|
|
@@ -35,9 +40,14 @@ export const reviewInputSchema = Type.Object(
|
|
|
35
40
|
/** TypeBox schema for a single structured finding (provider-visible). */
|
|
36
41
|
export const reviewFindingSchema = Type.Object(
|
|
37
42
|
{
|
|
38
|
-
title: Type.String({
|
|
43
|
+
title: Type.String({
|
|
44
|
+
minLength: 1,
|
|
45
|
+
maxLength: REVIEW_LIMITS.findingTitleCharacters,
|
|
46
|
+
description: "Concise finding title.",
|
|
47
|
+
}),
|
|
39
48
|
description: Type.String({
|
|
40
49
|
minLength: 1,
|
|
50
|
+
maxLength: REVIEW_LIMITS.findingDescriptionCharacters,
|
|
41
51
|
description: "Concrete evidence-backed explanation of the issue.",
|
|
42
52
|
}),
|
|
43
53
|
blocksAcceptance: Type.Boolean({
|
|
@@ -57,7 +67,11 @@ export const reviewFindingSchema = Type.Object(
|
|
|
57
67
|
location: Type.Optional(
|
|
58
68
|
Type.Object(
|
|
59
69
|
{
|
|
60
|
-
path: Type.String({
|
|
70
|
+
path: Type.String({
|
|
71
|
+
minLength: 1,
|
|
72
|
+
maxLength: REVIEW_LIMITS.locationPathCharacters,
|
|
73
|
+
description: "Repository-relative target path.",
|
|
74
|
+
}),
|
|
61
75
|
startLine: Type.Integer({ minimum: 1 }),
|
|
62
76
|
endLine: Type.Integer({ minimum: 1 }),
|
|
63
77
|
},
|
|
@@ -71,8 +85,13 @@ export const reviewFindingSchema = Type.Object(
|
|
|
71
85
|
/** TypeBox schema for the submit_review tool parameters (provider-visible). */
|
|
72
86
|
export const reviewSubmissionSchema = Type.Object(
|
|
73
87
|
{
|
|
74
|
-
summary: Type.String({
|
|
88
|
+
summary: Type.String({
|
|
89
|
+
minLength: 1,
|
|
90
|
+
maxLength: REVIEW_LIMITS.summaryCharacters,
|
|
91
|
+
description: "Task-level review summary.",
|
|
92
|
+
}),
|
|
75
93
|
findings: Type.Array(reviewFindingSchema, {
|
|
94
|
+
maxItems: REVIEW_LIMITS.findingsPerTask,
|
|
76
95
|
description: "Findings in the reviewer's intended order; use an empty array when none exist.",
|
|
77
96
|
}),
|
|
78
97
|
},
|