@mrclrchtr/supi-review 4.5.1 → 4.7.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 +30 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-code-runtime/README.md +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +49 -12
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-code-runtime/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +49 -12
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/README.md +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +49 -12
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-code-runtime/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +49 -12
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-lsp/package.json +4 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/README.md +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +49 -12
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-code-runtime/package.json +3 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +49 -12
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/package.json +4 -4
- package/node_modules/@mrclrchtr/supi-code-intelligence/node_modules/@mrclrchtr/supi-tree-sitter/src/tool/outline-html-sql.ts +1 -1
- package/node_modules/@mrclrchtr/supi-code-intelligence/package.json +6 -6
- package/node_modules/@mrclrchtr/supi-core/README.md +1 -3
- package/node_modules/@mrclrchtr/supi-core/package.json +2 -2
- package/node_modules/@mrclrchtr/supi-core/src/debug-registry.ts +49 -12
- package/package.json +4 -4
- package/src/git.ts +23 -11
- package/src/review-input.ts +53 -6
- package/src/review-limits.ts +6 -0
- package/src/review-result.ts +24 -3
- package/src/review.ts +29 -2
- package/src/target/packet.ts +59 -21
- package/src/target/resolve.ts +75 -0
- package/src/target/snapshot-match.ts +37 -0
- package/src/tool/agent-review-schemas.ts +46 -4
- package/src/tool/agent-review-tools.ts +33 -12
- package/src/tool/child-session-runner.ts +4 -0
- package/src/tool/criteria-only-scope.ts +31 -0
- package/src/tool/output-page.ts +13 -0
- package/src/tool/planner-runner.ts +3 -2
- package/src/tool/review-audit-tool.ts +2 -12
- package/src/tool/review-debug-summary.ts +64 -0
- package/src/tool/review-execution.ts +22 -0
- package/src/tool/review-format.ts +19 -11
- package/src/tool/review-output-tool.ts +8 -15
- package/src/tool/review-runner.ts +9 -1
- package/src/tool/review-system-prompt.ts +7 -3
- package/src/tool/review-workflow.ts +35 -32
- package/src/tool/schemas.ts +52 -2
- package/src/tool/session-lifecycle.ts +1 -0
- package/src/tui/common.ts +22 -0
- package/src/tui/prepare.ts +31 -12
- package/src/tui/run.ts +39 -11
- package/src/types.ts +35 -6
- package/src/workspace/review-workspace.ts +36 -7
|
@@ -64,6 +64,9 @@ export interface DebugEventQueryResult {
|
|
|
64
64
|
rawAccessDenied: boolean;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
/** Receives a sanitized event whenever the registry records one. */
|
|
68
|
+
export type DebugEventListener = (event: DebugEventView) => void;
|
|
69
|
+
|
|
67
70
|
export interface DebugSummary {
|
|
68
71
|
total: number;
|
|
69
72
|
byLevel: Partial<Record<DebugLevel, number>>;
|
|
@@ -73,6 +76,7 @@ export interface DebugSummary {
|
|
|
73
76
|
interface DebugRegistryState {
|
|
74
77
|
config: DebugRegistryConfig;
|
|
75
78
|
events: DebugEvent[];
|
|
79
|
+
listeners: Set<DebugEventListener>;
|
|
76
80
|
nextId: number;
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -97,10 +101,14 @@ function getState(): DebugRegistryState {
|
|
|
97
101
|
state = {
|
|
98
102
|
config: cloneConfig(DEBUG_REGISTRY_DEFAULTS),
|
|
99
103
|
events: [],
|
|
104
|
+
listeners: new Set(),
|
|
100
105
|
nextId: 1,
|
|
101
106
|
};
|
|
102
107
|
(globalThis as Record<symbol, unknown>)[REGISTRY_KEY] = state;
|
|
103
108
|
}
|
|
109
|
+
// Keep the shared registry compatible with extension reloads that reuse an
|
|
110
|
+
// instance created before listeners existed.
|
|
111
|
+
if (!state.listeners) state.listeners = new Set();
|
|
104
112
|
return state;
|
|
105
113
|
}
|
|
106
114
|
|
|
@@ -119,7 +127,16 @@ function trimToMaxEvents(state: DebugRegistryState): void {
|
|
|
119
127
|
state.events.splice(0, state.events.length - maxEvents);
|
|
120
128
|
}
|
|
121
129
|
|
|
122
|
-
|
|
130
|
+
/** Return whether a debug level is recognized by the registry. */
|
|
131
|
+
export function isDebugLevel(value: unknown): value is DebugLevel {
|
|
132
|
+
return value === "debug" || value === "info" || value === "warning" || value === "error";
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Match a debug event against the supported source, level, and category filters. */
|
|
136
|
+
export function matchesDebugEventQuery(
|
|
137
|
+
event: Pick<DebugEventView, "source" | "level" | "category">,
|
|
138
|
+
query: Pick<DebugEventQuery, "source" | "level" | "category">,
|
|
139
|
+
): boolean {
|
|
123
140
|
if (query.source && event.source !== query.source) return false;
|
|
124
141
|
if (query.level && event.level !== query.level) return false;
|
|
125
142
|
if (query.category && event.category !== query.category) return false;
|
|
@@ -168,6 +185,26 @@ export function redactDebugData<T>(value: T): T {
|
|
|
168
185
|
return redactValue(value, 8) as T;
|
|
169
186
|
}
|
|
170
187
|
|
|
188
|
+
function toSanitizedView(event: DebugEvent): DebugEventView {
|
|
189
|
+
return {
|
|
190
|
+
id: event.id,
|
|
191
|
+
timestamp: event.timestamp,
|
|
192
|
+
source: event.source,
|
|
193
|
+
level: event.level,
|
|
194
|
+
category: event.category,
|
|
195
|
+
message: event.message,
|
|
196
|
+
cwd: event.cwd,
|
|
197
|
+
data: event.data,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Subscribe to sanitized events. Listeners are isolated so diagnostics cannot disrupt producers. */
|
|
202
|
+
export function subscribeDebugEvents(listener: DebugEventListener): () => void {
|
|
203
|
+
const state = getState();
|
|
204
|
+
state.listeners.add(listener);
|
|
205
|
+
return () => state.listeners.delete(listener);
|
|
206
|
+
}
|
|
207
|
+
|
|
171
208
|
/** Record a session-local debug event if debugging is enabled. */
|
|
172
209
|
export function recordDebugEvent(input: DebugEventInput): DebugEvent | null {
|
|
173
210
|
const state = getState();
|
|
@@ -183,6 +220,14 @@ export function recordDebugEvent(input: DebugEventInput): DebugEvent | null {
|
|
|
183
220
|
};
|
|
184
221
|
state.events.push(event);
|
|
185
222
|
trimToMaxEvents(state);
|
|
223
|
+
const view = toSanitizedView(event);
|
|
224
|
+
for (const listener of state.listeners) {
|
|
225
|
+
try {
|
|
226
|
+
listener(view);
|
|
227
|
+
} catch {
|
|
228
|
+
// Debug-event consumers must not alter producer behavior.
|
|
229
|
+
}
|
|
230
|
+
}
|
|
186
231
|
return { ...event };
|
|
187
232
|
}
|
|
188
233
|
|
|
@@ -196,21 +241,12 @@ export function getDebugEvents(query: DebugEventQuery = {}): DebugEventQueryResu
|
|
|
196
241
|
const limit = query.limit && query.limit > 0 ? Math.floor(query.limit) : state.config.maxEvents;
|
|
197
242
|
|
|
198
243
|
const events = state.events
|
|
199
|
-
.filter((event) =>
|
|
244
|
+
.filter((event) => matchesDebugEventQuery(event, query))
|
|
200
245
|
.slice()
|
|
201
246
|
.reverse()
|
|
202
247
|
.slice(0, limit)
|
|
203
248
|
.map((event): DebugEventView => {
|
|
204
|
-
const view
|
|
205
|
-
id: event.id,
|
|
206
|
-
timestamp: event.timestamp,
|
|
207
|
-
source: event.source,
|
|
208
|
-
level: event.level,
|
|
209
|
-
category: event.category,
|
|
210
|
-
message: event.message,
|
|
211
|
-
cwd: event.cwd,
|
|
212
|
-
data: event.data,
|
|
213
|
-
};
|
|
249
|
+
const view = toSanitizedView(event);
|
|
214
250
|
if (allowRaw && event.rawData !== undefined) {
|
|
215
251
|
view.rawData = event.rawData;
|
|
216
252
|
}
|
|
@@ -246,5 +282,6 @@ export function resetDebugRegistry(): void {
|
|
|
246
282
|
const state = getState();
|
|
247
283
|
state.config = cloneConfig(DEBUG_REGISTRY_DEFAULTS);
|
|
248
284
|
state.events = [];
|
|
285
|
+
state.listeners.clear();
|
|
249
286
|
state.nextId = 1;
|
|
250
287
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-review",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.7.0",
|
|
4
|
+
"description": "Parallel isolated reviews of trees, comparisons, and commits",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"README.md"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@mrclrchtr/supi-
|
|
35
|
-
"@mrclrchtr/supi-
|
|
34
|
+
"@mrclrchtr/supi-core": "4.7.0",
|
|
35
|
+
"@mrclrchtr/supi-code-intelligence": "4.7.0"
|
|
36
36
|
},
|
|
37
37
|
"bundledDependencies": [
|
|
38
38
|
"@mrclrchtr/supi-code-intelligence",
|
package/src/git.ts
CHANGED
|
@@ -11,26 +11,33 @@ import type { ResolvedReviewTarget, ReviewSnapshot } from "./types.ts";
|
|
|
11
11
|
|
|
12
12
|
export { resolveReviewSnapshot, summarizeReviewSnapshot } from "./target/resolve.ts";
|
|
13
13
|
|
|
14
|
+
type FilesystemDiffTarget = Extract<
|
|
15
|
+
ResolvedReviewTarget,
|
|
16
|
+
{ kind: "working-tree" | "current-state" }
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
/** Pinned diff baseline for a filesystem target; current-state audits diff against HEAD. */
|
|
20
|
+
function baselineFor(target: FilesystemDiffTarget): string {
|
|
21
|
+
return "mergeBaseCommit" in target
|
|
22
|
+
? (target.mergeBaseCommit ?? target.headCommit)
|
|
23
|
+
: target.headCommit;
|
|
24
|
+
}
|
|
25
|
+
|
|
14
26
|
function withWorkingTreeIndex<T>(
|
|
15
27
|
cwd: string,
|
|
16
|
-
target:
|
|
28
|
+
target: FilesystemDiffTarget,
|
|
17
29
|
operation: (indexFile: string) => Promise<T>,
|
|
18
30
|
): Promise<T> {
|
|
19
|
-
return withReviewIndex(
|
|
20
|
-
cwd,
|
|
21
|
-
target.headCommit,
|
|
22
|
-
target.mergeBaseCommit ?? target.headCommit,
|
|
23
|
-
operation,
|
|
24
|
-
);
|
|
31
|
+
return withReviewIndex(cwd, target.headCommit, baselineFor(target), operation);
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
async function readWorkingTreeDiff(
|
|
28
35
|
root: string,
|
|
29
|
-
target:
|
|
36
|
+
target: FilesystemDiffTarget,
|
|
30
37
|
path?: string,
|
|
31
38
|
): Promise<string> {
|
|
32
39
|
return withWorkingTreeIndex(root, target, async (indexFile) => {
|
|
33
|
-
const baseline = target
|
|
40
|
+
const baseline = baselineFor(target);
|
|
34
41
|
const pathArgs = path ? ["--", path] : [];
|
|
35
42
|
const [tracked, untrackedText] = await Promise.all([
|
|
36
43
|
git(root, literalPathspec(["diff", ...DIFF_FLAGS, baseline, ...pathArgs]), indexFile),
|
|
@@ -60,11 +67,16 @@ export async function readReviewDiff(
|
|
|
60
67
|
): Promise<string> {
|
|
61
68
|
const root = snapshot.repositoryRoot;
|
|
62
69
|
const safe = path ? resolveReviewPath(root, path) : undefined;
|
|
63
|
-
|
|
70
|
+
// Current-State Audit has no change attribution; every state path is evidence.
|
|
71
|
+
if (
|
|
72
|
+
safe &&
|
|
73
|
+
snapshot.target.kind !== "current-state" &&
|
|
74
|
+
!snapshot.changes.some((change) => change.path === safe.path)
|
|
75
|
+
) {
|
|
64
76
|
throw new Error(`${safe.path} is not changed by this target.`);
|
|
65
77
|
}
|
|
66
78
|
const target = snapshot.target;
|
|
67
|
-
if (target.kind === "working-tree") {
|
|
79
|
+
if (target.kind === "working-tree" || target.kind === "current-state") {
|
|
68
80
|
return readWorkingTreeDiff(root, target, safe?.path);
|
|
69
81
|
}
|
|
70
82
|
const pathArgs = safe ? ["--", safe.path] : [];
|
package/src/review-input.ts
CHANGED
|
@@ -1,14 +1,61 @@
|
|
|
1
1
|
import { REVIEW_LIMITS } from "./review-limits.ts";
|
|
2
|
-
import type { ReviewInput } from "./types.ts";
|
|
2
|
+
import type { CriteriaSource, ReviewInput } from "./types.ts";
|
|
3
|
+
|
|
4
|
+
function normalizeCriteriaSources(
|
|
5
|
+
taskId: string,
|
|
6
|
+
sources?: CriteriaSource[],
|
|
7
|
+
): CriteriaSource[] | undefined {
|
|
8
|
+
if (sources === undefined) return undefined;
|
|
9
|
+
if (sources.length > REVIEW_LIMITS.criteriaSourcesPerTask) {
|
|
10
|
+
throw new Error(
|
|
11
|
+
`Review task ${taskId} may list at most ${REVIEW_LIMITS.criteriaSourcesPerTask} criteria sources.`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const normalized: CriteriaSource[] = [];
|
|
15
|
+
const summaries = new Map<string, string>();
|
|
16
|
+
for (const source of sources) {
|
|
17
|
+
const reference = source.reference.trim();
|
|
18
|
+
const summary = source.summary.trim();
|
|
19
|
+
if (!reference || !summary) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`Review task ${taskId} criteria source references and summaries must not be blank.`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
if (reference.length > REVIEW_LIMITS.criteriaReferenceCharacters) {
|
|
25
|
+
throw new Error(
|
|
26
|
+
`Review task ${taskId} criteria source reference must not exceed ${REVIEW_LIMITS.criteriaReferenceCharacters} characters.`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
if (summary.length > REVIEW_LIMITS.criteriaSummaryCharacters) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Review task ${taskId} criteria source summary must not exceed ${REVIEW_LIMITS.criteriaSummaryCharacters.toLocaleString("en-US")} characters.`,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const previous = summaries.get(reference);
|
|
35
|
+
if (previous !== undefined) {
|
|
36
|
+
if (previous !== summary) {
|
|
37
|
+
throw new Error(`Review task ${taskId} repeats criteria source ${reference}.`);
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
summaries.set(reference, summary);
|
|
42
|
+
normalized.push({ reference, summary });
|
|
43
|
+
}
|
|
44
|
+
return normalized;
|
|
45
|
+
}
|
|
3
46
|
|
|
4
47
|
/** Canonicalize and semantically validate review input for every adapter. */
|
|
5
48
|
export function normalizeReviewInput(review: ReviewInput): ReviewInput {
|
|
6
49
|
const sharedContext = review.sharedContext?.trim();
|
|
7
|
-
const tasks = review.tasks.map((task) =>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
50
|
+
const tasks = review.tasks.map((task) => {
|
|
51
|
+
const criteriaSources = normalizeCriteriaSources(task.id.trim(), task.criteriaSources);
|
|
52
|
+
return {
|
|
53
|
+
id: task.id.trim(),
|
|
54
|
+
instructions: task.instructions.trim(),
|
|
55
|
+
...(task.findingScope !== undefined ? { findingScope: task.findingScope } : {}),
|
|
56
|
+
...(criteriaSources ? { criteriaSources } : {}),
|
|
57
|
+
};
|
|
58
|
+
});
|
|
12
59
|
if (tasks.length < 1 || tasks.length > 4) {
|
|
13
60
|
throw new Error("Provide between one and four review tasks.");
|
|
14
61
|
}
|
package/src/review-limits.ts
CHANGED
|
@@ -8,4 +8,10 @@ export const REVIEW_LIMITS = {
|
|
|
8
8
|
findingTitleCharacters: 200,
|
|
9
9
|
findingDescriptionCharacters: 8_000,
|
|
10
10
|
locationPathCharacters: 4_096,
|
|
11
|
+
criteriaSourcesPerTask: 5,
|
|
12
|
+
criteriaReferenceCharacters: 256,
|
|
13
|
+
criteriaSummaryCharacters: 2_000,
|
|
14
|
+
criteriaCoverageReasonCharacters: 500,
|
|
15
|
+
reviewScopePathsPerTarget: 16,
|
|
16
|
+
reviewScopePathCharacters: 4_096,
|
|
11
17
|
} as const;
|
package/src/review-result.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { REVIEW_LIMITS } from "./review-limits.ts";
|
|
2
2
|
import { normalizeRepositoryRelativePath } from "./review-path.ts";
|
|
3
3
|
import type {
|
|
4
|
+
CriteriaCoverage,
|
|
4
5
|
FindingCounts,
|
|
5
6
|
NormalizedReviewSubmission,
|
|
6
7
|
ReviewFinding,
|
|
@@ -44,6 +45,22 @@ function countFindings(
|
|
|
44
45
|
return counts;
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
function normalizeCriteriaCoverage(coverage: CriteriaCoverage): CriteriaCoverage {
|
|
49
|
+
if (!coverage) throw new Error("Review submissions must include criteria coverage.");
|
|
50
|
+
const reason = ("reason" in coverage ? coverage.reason : undefined)?.trim();
|
|
51
|
+
if (coverage.status === "complete") {
|
|
52
|
+
if (reason) throw new Error("Complete criteria coverage must not include a reason.");
|
|
53
|
+
return { status: "complete" };
|
|
54
|
+
}
|
|
55
|
+
if (!reason) throw new Error("Incomplete criteria coverage needs a criteria coverage reason.");
|
|
56
|
+
if (reason.length > REVIEW_LIMITS.criteriaCoverageReasonCharacters) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Criteria coverage reason must not exceed ${REVIEW_LIMITS.criteriaCoverageReasonCharacters} characters.`,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return { status: "incomplete", reason };
|
|
62
|
+
}
|
|
63
|
+
|
|
47
64
|
/** Derive an acceptance verdict and structured finding counts without reordering findings. */
|
|
48
65
|
export function normalizeReviewSubmission(
|
|
49
66
|
submission: ReviewSubmissionInput,
|
|
@@ -52,8 +69,10 @@ export function normalizeReviewSubmission(
|
|
|
52
69
|
throw new Error(`A review task may submit at most ${REVIEW_LIMITS.findingsPerTask} findings.`);
|
|
53
70
|
}
|
|
54
71
|
const findingCounts = countFindings(submission.findings);
|
|
72
|
+
const criteriaCoverage = normalizeCriteriaCoverage(submission.criteriaCoverage);
|
|
55
73
|
return {
|
|
56
74
|
summary: requireText(submission.summary, "Review summary", REVIEW_LIMITS.summaryCharacters),
|
|
75
|
+
criteriaCoverage,
|
|
57
76
|
findings: submission.findings.map((finding, index) => {
|
|
58
77
|
if (
|
|
59
78
|
!Number.isFinite(finding.confidence) ||
|
|
@@ -104,8 +123,10 @@ export function normalizeReviewSubmission(
|
|
|
104
123
|
verdict:
|
|
105
124
|
findingCounts.blocking > 0
|
|
106
125
|
? "issues"
|
|
107
|
-
:
|
|
108
|
-
? "
|
|
109
|
-
:
|
|
126
|
+
: criteriaCoverage?.status === "incomplete"
|
|
127
|
+
? "incomplete"
|
|
128
|
+
: findingCounts.total > 0
|
|
129
|
+
? "pass_with_findings"
|
|
130
|
+
: "pass",
|
|
110
131
|
};
|
|
111
132
|
}
|
package/src/review.ts
CHANGED
|
@@ -32,15 +32,30 @@ const DEFAULT_REVIEW: ReviewInput = {
|
|
|
32
32
|
],
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
+
const CURRENT_STATE_DEFAULT_REVIEW: ReviewInput = {
|
|
36
|
+
tasks: [
|
|
37
|
+
{
|
|
38
|
+
id: "general",
|
|
39
|
+
instructions: "Review the current state against the requested criteria.",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function defaultReviewFor(target: ReviewTargetSpec): ReviewInput {
|
|
45
|
+
return target.kind === "current-state" ? CURRENT_STATE_DEFAULT_REVIEW : DEFAULT_REVIEW;
|
|
46
|
+
}
|
|
47
|
+
|
|
35
48
|
async function selectTarget(ctx: CommandContext): Promise<ReviewTargetSpec | undefined> {
|
|
36
49
|
const kind = await ctx.ui.select("Review target", [
|
|
37
50
|
"Uncommitted changes against HEAD",
|
|
38
51
|
"Current work against a base branch",
|
|
39
52
|
"Committed changes against a base branch",
|
|
40
53
|
"Single commit",
|
|
54
|
+
"Current state audit",
|
|
41
55
|
]);
|
|
42
56
|
if (!kind) return undefined;
|
|
43
57
|
if (kind === "Uncommitted changes against HEAD") return { kind: "working-tree" };
|
|
58
|
+
if (kind === "Current state audit") return { kind: "current-state" };
|
|
44
59
|
const choices =
|
|
45
60
|
kind === "Single commit" ? await listRecentCommits(ctx.cwd) : await listLocalBranches(ctx.cwd);
|
|
46
61
|
const label = await ctx.ui.select(
|
|
@@ -116,6 +131,7 @@ async function editReviewInteractive(
|
|
|
116
131
|
id,
|
|
117
132
|
instructions,
|
|
118
133
|
...(existing?.findingScope ? { findingScope: existing.findingScope } : {}),
|
|
134
|
+
...(existing?.criteriaSources?.length ? { criteriaSources: existing.criteriaSources } : {}),
|
|
119
135
|
});
|
|
120
136
|
}
|
|
121
137
|
|
|
@@ -197,7 +213,7 @@ async function prepareInteractiveReview(
|
|
|
197
213
|
ctx.ui.notify("Planner unavailable; edit replacement tasks to continue.", "warning");
|
|
198
214
|
}
|
|
199
215
|
return {
|
|
200
|
-
review: outcome.plan.plannerDraft ??
|
|
216
|
+
review: outcome.plan.plannerDraft ?? defaultReviewFor(target),
|
|
201
217
|
planId: outcome.plan.id,
|
|
202
218
|
};
|
|
203
219
|
}
|
|
@@ -268,9 +284,20 @@ async function runCommand(ctx: CommandContext, services: ReviewCommandServices):
|
|
|
268
284
|
? await prepareInteractiveReview(ctx, target, reviewerModel, planStore)
|
|
269
285
|
: undefined;
|
|
270
286
|
if (planning === "AI suggests tasks" && !prepared) return;
|
|
271
|
-
const
|
|
287
|
+
const baseReview = prepared?.review ?? defaultReviewFor(target);
|
|
272
288
|
const planId = prepared?.planId;
|
|
273
289
|
|
|
290
|
+
// Current-State Audit fixes criteria-only scope; strip planner-default findingScope
|
|
291
|
+
// before the editor copies it into user-facing tasks. Copy rather than mutate so the
|
|
292
|
+
// plan store's planner draft is never edited in place.
|
|
293
|
+
const review =
|
|
294
|
+
target.kind === "current-state"
|
|
295
|
+
? {
|
|
296
|
+
...baseReview,
|
|
297
|
+
tasks: baseReview.tasks.map(({ findingScope: _stripped, ...rest }) => rest),
|
|
298
|
+
}
|
|
299
|
+
: baseReview;
|
|
300
|
+
|
|
274
301
|
const edited = await editReviewInteractive(ctx, review, {
|
|
275
302
|
allowResize: planning === "Write my own tasks",
|
|
276
303
|
});
|
package/src/target/packet.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import type {
|
|
3
|
+
EffectiveFindingScope,
|
|
3
4
|
ResolvedReviewTarget,
|
|
4
5
|
ReviewInput,
|
|
5
6
|
ReviewModelSelection,
|
|
@@ -10,7 +11,7 @@ import type {
|
|
|
10
11
|
import { buildFileManifest } from "./file-manifest.ts";
|
|
11
12
|
|
|
12
13
|
/** Protocol version included in every canonical reviewer packet for future evolution. */
|
|
13
|
-
export const REVIEW_PACKET_PROTOCOL_VERSION = "
|
|
14
|
+
export const REVIEW_PACKET_PROTOCOL_VERSION = "6";
|
|
14
15
|
|
|
15
16
|
function sha256(value: string): string {
|
|
16
17
|
return createHash("sha256").update(value, "utf8").digest("hex");
|
|
@@ -33,11 +34,14 @@ function targetIdentity(target: ResolvedReviewTarget): string {
|
|
|
33
34
|
`head=${target.headCommit}`,
|
|
34
35
|
].join(" ");
|
|
35
36
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
if (target.kind === "commit") {
|
|
38
|
+
return [
|
|
39
|
+
"commit",
|
|
40
|
+
`commit=${target.commit}`,
|
|
41
|
+
`parent=${target.parentCommit ?? "empty-tree"}`,
|
|
42
|
+
].join(" ");
|
|
43
|
+
}
|
|
44
|
+
return ["current-state", `head=${target.headCommit}`].join(" ");
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
function inspectionGuidance(target: ResolvedReviewTarget): string[] {
|
|
@@ -46,6 +50,16 @@ function inspectionGuidance(target: ResolvedReviewTarget): string[] {
|
|
|
46
50
|
"Use the available inspection tools to inspect the repository.",
|
|
47
51
|
"Use Git to inspect the pinned before side; do not infer it from the caller's live worktree.",
|
|
48
52
|
];
|
|
53
|
+
if (target.kind === "current-state") {
|
|
54
|
+
return [
|
|
55
|
+
"The workspace materializes the complete current filesystem state, including uncommitted and untracked work.",
|
|
56
|
+
"Evaluate that one state against the Review Criteria; there is no before side and no Git-change attribution.",
|
|
57
|
+
"You may inspect unchanged related code as context and report criterion-relevant findings anywhere.",
|
|
58
|
+
"Ignore staged Git state in the workspace; it is a freeze mechanism, not review evidence.",
|
|
59
|
+
common[0],
|
|
60
|
+
common[1],
|
|
61
|
+
];
|
|
62
|
+
}
|
|
49
63
|
if (target.kind === "working-tree") {
|
|
50
64
|
const baseline = target.mergeBaseCommit ?? target.headCommit;
|
|
51
65
|
return [
|
|
@@ -75,6 +89,11 @@ function inspectionGuidance(target: ResolvedReviewTarget): string[] {
|
|
|
75
89
|
];
|
|
76
90
|
}
|
|
77
91
|
|
|
92
|
+
function reviewScopePaths(snapshot: ReviewSnapshot): string[] | undefined {
|
|
93
|
+
const requested = snapshot.requestedTarget;
|
|
94
|
+
return requested.kind === "current-state" ? requested.paths : undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
78
97
|
/** Build the canonical caller-policy/engine-mechanics reviewer packet. */
|
|
79
98
|
export function buildReviewPacket(
|
|
80
99
|
snapshot: ReviewSnapshot,
|
|
@@ -82,33 +101,52 @@ export function buildReviewPacket(
|
|
|
82
101
|
task: ReviewTask,
|
|
83
102
|
model: ReviewModelSelection,
|
|
84
103
|
): ReviewPacket {
|
|
104
|
+
const currentState = snapshot.target.kind === "current-state";
|
|
105
|
+
const findingScope: EffectiveFindingScope = currentState
|
|
106
|
+
? "criteria-only"
|
|
107
|
+
: (task.findingScope ?? "change-only");
|
|
85
108
|
const parts = [
|
|
86
109
|
"# Review Task",
|
|
87
110
|
"",
|
|
88
111
|
`Protocol version: ${REVIEW_PACKET_PROTOCOL_VERSION}`,
|
|
89
112
|
`Task id: ${task.id}`,
|
|
90
|
-
`Finding Scope: ${
|
|
113
|
+
`Finding Scope: ${findingScope}`,
|
|
91
114
|
`Target: ${snapshot.title}`,
|
|
92
115
|
`Target identity: ${targetIdentity(snapshot.target)}`,
|
|
93
|
-
`Target diff SHA-256: ${snapshot.diffHash}
|
|
116
|
+
...(currentState ? [] : [`Target diff SHA-256: ${snapshot.diffHash}`]),
|
|
94
117
|
`Reviewer model: ${model.canonicalId}`,
|
|
95
|
-
|
|
96
|
-
|
|
118
|
+
...(currentState
|
|
119
|
+
? []
|
|
120
|
+
: [
|
|
121
|
+
`Changed files: ${snapshot.changes.length}`,
|
|
122
|
+
`Diff stats: +${snapshot.stats.additions} / -${snapshot.stats.deletions}`,
|
|
123
|
+
]),
|
|
97
124
|
];
|
|
98
125
|
if (review.sharedContext?.trim()) {
|
|
99
126
|
parts.push("", "## Shared context", review.sharedContext.trim());
|
|
100
127
|
}
|
|
101
|
-
parts.push(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
)
|
|
128
|
+
parts.push("", "## Task instructions", task.instructions.trim());
|
|
129
|
+
if (task.criteriaSources?.length) {
|
|
130
|
+
parts.push(
|
|
131
|
+
"",
|
|
132
|
+
"## Review criteria sources",
|
|
133
|
+
"Use these summaries first; each identified source remains authoritative. Retrieve a source read-only only when its summary is insufficient. If required detail is unavailable, preserve concrete findings and mark Criteria Coverage incomplete with the reason.",
|
|
134
|
+
...task.criteriaSources.map((source) => `- ${source.reference}: ${source.summary}`),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
const scopePaths = reviewScopePaths(snapshot);
|
|
138
|
+
if (scopePaths?.length) {
|
|
139
|
+
parts.push(
|
|
140
|
+
"",
|
|
141
|
+
"## Review scope",
|
|
142
|
+
"Advisory focus paths; they do not restrict inspection or finding eligibility.",
|
|
143
|
+
...scopePaths.map((path) => `- ${JSON.stringify(path)}`),
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
if (!currentState) {
|
|
147
|
+
parts.push("", "## Changed files", ...buildFileManifest(snapshot.changes));
|
|
148
|
+
}
|
|
149
|
+
parts.push("", "## Inspection", ...inspectionGuidance(snapshot.target));
|
|
112
150
|
const prompt = parts.join("\n");
|
|
113
151
|
return { prompt, packetHash: sha256(prompt), taskId: task.id };
|
|
114
152
|
}
|
package/src/target/resolve.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { lstat } from "node:fs/promises";
|
|
1
2
|
import {
|
|
2
3
|
runGit as git,
|
|
3
4
|
runGitAllowExit as gitAllowExit,
|
|
4
5
|
resolveGitRepositoryRoot,
|
|
5
6
|
withReviewIndex,
|
|
6
7
|
} from "../git-command.ts";
|
|
8
|
+
import { resolveReviewPath } from "../review-path.ts";
|
|
7
9
|
import type { ReviewSnapshot, ReviewSnapshotSummary, ReviewTargetSpec } from "../types.ts";
|
|
8
10
|
import {
|
|
9
11
|
buildReviewChanges,
|
|
@@ -111,6 +113,77 @@ async function workingTreeSnapshot(
|
|
|
111
113
|
});
|
|
112
114
|
}
|
|
113
115
|
|
|
116
|
+
function isMissingPath(error: unknown): boolean {
|
|
117
|
+
return (
|
|
118
|
+
!!error &&
|
|
119
|
+
typeof error === "object" &&
|
|
120
|
+
"code" in error &&
|
|
121
|
+
((error as { code?: unknown }).code === "ENOENT" ||
|
|
122
|
+
(error as { code?: unknown }).code === "ENOTDIR")
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Validate advisory Review Scope paths against the frozen current filesystem. */
|
|
127
|
+
async function validateReviewScopePaths(
|
|
128
|
+
root: string,
|
|
129
|
+
paths: string[] | undefined,
|
|
130
|
+
): Promise<string[] | undefined> {
|
|
131
|
+
if (!paths?.length) return undefined;
|
|
132
|
+
const validated: string[] = [];
|
|
133
|
+
const seen = new Set<string>();
|
|
134
|
+
for (const path of paths) {
|
|
135
|
+
const safe = resolveReviewPath(root, path);
|
|
136
|
+
if (seen.has(safe.path)) continue;
|
|
137
|
+
try {
|
|
138
|
+
await lstat(safe.absolute);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
if (isMissingPath(error)) {
|
|
141
|
+
throw new Error(`Review Scope path does not exist in the current state: ${safe.path}`, {
|
|
142
|
+
cause: error,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
seen.add(safe.path);
|
|
148
|
+
validated.push(safe.path);
|
|
149
|
+
}
|
|
150
|
+
return validated;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function currentStateSnapshot(
|
|
154
|
+
cwd: string,
|
|
155
|
+
requested: Extract<ReviewTargetSpec, { kind: "current-state" }>,
|
|
156
|
+
): Promise<ReviewSnapshot> {
|
|
157
|
+
const head = await headCommit(cwd);
|
|
158
|
+
if (!head) throw new Error("Current-State Audit requires at least one commit.");
|
|
159
|
+
const paths = await validateReviewScopePaths(cwd, requested.paths);
|
|
160
|
+
return withReviewIndex(cwd, head, head, async (indexFile) => {
|
|
161
|
+
const [nameStatus, numstat, trackedDiff, untrackedText] = await Promise.all([
|
|
162
|
+
git(cwd, ["diff", ...DIFF_FLAGS, "--name-status", "-z", head], indexFile),
|
|
163
|
+
git(cwd, ["diff", ...DIFF_FLAGS, "--numstat", "-z", head], indexFile),
|
|
164
|
+
git(cwd, ["diff", ...DIFF_FLAGS, head], indexFile),
|
|
165
|
+
git(cwd, ["ls-files", "--others", "--exclude-standard", "-z"], indexFile),
|
|
166
|
+
]);
|
|
167
|
+
const changes = buildReviewChanges(nameStatus, numstat);
|
|
168
|
+
const diff = createDiffAccumulator();
|
|
169
|
+
diff.append(trackedDiff);
|
|
170
|
+
for (const path of parseNullList(untrackedText)) {
|
|
171
|
+
const patch = await diffUntrackedFile(cwd, path);
|
|
172
|
+
diff.append(patch);
|
|
173
|
+
changes.push(untrackedPatchChange(path, patch));
|
|
174
|
+
}
|
|
175
|
+
changes.sort((left, right) => left.path.localeCompare(right.path));
|
|
176
|
+
return {
|
|
177
|
+
repositoryRoot: cwd,
|
|
178
|
+
requestedTarget: { kind: "current-state", ...(paths ? { paths } : {}) },
|
|
179
|
+
target: { kind: "current-state", headCommit: head },
|
|
180
|
+
title: "Current state audit",
|
|
181
|
+
changes,
|
|
182
|
+
...diff.finish(changes.length),
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
114
187
|
async function comparisonSnapshot(
|
|
115
188
|
cwd: string,
|
|
116
189
|
requested: Extract<ReviewTargetSpec, { kind: "comparison" }>,
|
|
@@ -199,6 +272,8 @@ export async function resolveReviewSnapshot(
|
|
|
199
272
|
return comparisonSnapshot(root, target);
|
|
200
273
|
case "commit":
|
|
201
274
|
return commitSnapshot(root, target);
|
|
275
|
+
case "current-state":
|
|
276
|
+
return currentStateSnapshot(root, target);
|
|
202
277
|
}
|
|
203
278
|
}
|
|
204
279
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ReviewSnapshot } from "../types.ts";
|
|
2
|
+
|
|
3
|
+
/** Compare two resolved Review Target identities for drift detection. */
|
|
4
|
+
export function targetsMatch(
|
|
5
|
+
left: ReviewSnapshot["target"],
|
|
6
|
+
right: ReviewSnapshot["target"],
|
|
7
|
+
): boolean {
|
|
8
|
+
if (left.kind !== right.kind) return false;
|
|
9
|
+
if (left.kind === "working-tree" && right.kind === "working-tree") {
|
|
10
|
+
return (
|
|
11
|
+
left.headCommit === right.headCommit &&
|
|
12
|
+
left.requestedBaseCommit === right.requestedBaseCommit &&
|
|
13
|
+
left.mergeBaseCommit === right.mergeBaseCommit
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
if (left.kind === "comparison" && right.kind === "comparison") {
|
|
17
|
+
return (
|
|
18
|
+
left.requestedBaseCommit === right.requestedBaseCommit &&
|
|
19
|
+
left.mergeBaseCommit === right.mergeBaseCommit &&
|
|
20
|
+
left.headCommit === right.headCommit
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
if (left.kind === "current-state" && right.kind === "current-state") {
|
|
24
|
+
return left.headCommit === right.headCommit;
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
left.kind === "commit" &&
|
|
28
|
+
right.kind === "commit" &&
|
|
29
|
+
left.commit === right.commit &&
|
|
30
|
+
left.parentCommit === right.parentCommit
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Compare two Review Snapshots by patch identity and target identity. */
|
|
35
|
+
export function snapshotsMatch(left: ReviewSnapshot, right: ReviewSnapshot): boolean {
|
|
36
|
+
return left.diffHash === right.diffHash && targetsMatch(left.target, right.target);
|
|
37
|
+
}
|