@open-cr-agent/core 0.10.0 → 0.12.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/dist/agent/settings.d.ts +1 -1
- package/dist/agent/settings.js +2 -1
- package/dist/{rereview → anchor}/quote.js +1 -1
- package/dist/chat/prompt.js +1 -1
- package/dist/contracts.d.ts +3 -0
- package/dist/docs/project-docs.d.ts +30 -0
- package/dist/docs/project-docs.js +103 -0
- package/dist/domain.d.ts +1 -0
- package/dist/fix/check.d.ts +13 -0
- package/dist/fix/check.js +62 -0
- package/dist/fix/prompt.d.ts +11 -0
- package/dist/fix/prompt.js +42 -0
- package/dist/fix/propose.d.ts +31 -0
- package/dist/fix/propose.js +96 -0
- package/dist/fix/select.d.ts +7 -0
- package/dist/fix/select.js +22 -0
- package/dist/generate/edits.d.ts +32 -0
- package/dist/generate/edits.js +87 -0
- package/dist/generate/generate.d.ts +13 -0
- package/dist/generate/generate.js +62 -0
- package/dist/generate/languages.d.ts +20 -0
- package/dist/generate/languages.js +105 -0
- package/dist/generate/prompt.d.ts +39 -0
- package/dist/generate/prompt.js +72 -0
- package/dist/generate/targets.d.ts +17 -0
- package/dist/generate/targets.js +35 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +5 -0
- package/dist/internal.d.ts +5 -1
- package/dist/internal.js +4 -1
- package/dist/matrix/matrix.js +14 -3
- package/dist/merge-checks/merge-check.d.ts +10 -0
- package/dist/merge-checks/merge-check.js +1 -0
- package/dist/merge-checks/merge-checks.d.ts +21 -0
- package/dist/merge-checks/merge-checks.js +65 -0
- package/dist/merge-checks/prompt.d.ts +19 -0
- package/dist/merge-checks/prompt.js +39 -0
- package/dist/pipeline/assemble-report.d.ts +4 -0
- package/dist/pipeline/assemble-report.js +22 -3
- package/dist/pipeline/check-stage.js +1 -2
- package/dist/pipeline/context-footprint.d.ts +10 -0
- package/dist/pipeline/context-footprint.js +36 -0
- package/dist/pipeline/execute-stage.d.ts +1 -1
- package/dist/pipeline/execute-stage.js +3 -1
- package/dist/pipeline/execute.d.ts +2 -0
- package/dist/pipeline/execute.js +5 -1
- package/dist/pipeline/findings.js +1 -1
- package/dist/pipeline/fix-stage.d.ts +12 -0
- package/dist/pipeline/fix-stage.js +34 -0
- package/dist/pipeline/generate.d.ts +22 -0
- package/dist/pipeline/generate.js +154 -0
- package/dist/pipeline/linked-tasks.d.ts +11 -0
- package/dist/pipeline/linked-tasks.js +43 -0
- package/dist/pipeline/merge-checks-stage.d.ts +9 -0
- package/dist/pipeline/merge-checks-stage.js +24 -0
- package/dist/pipeline/options.d.ts +15 -1
- package/dist/pipeline/options.js +14 -0
- package/dist/pipeline/plan-output.d.ts +21 -0
- package/dist/pipeline/plan-output.js +11 -0
- package/dist/pipeline/plan.d.ts +5 -1
- package/dist/pipeline/plan.js +15 -2
- package/dist/pipeline/preview.d.ts +2 -0
- package/dist/pipeline/preview.js +11 -4
- package/dist/pipeline/run.js +16 -4
- package/dist/pipeline/task-prompt.d.ts +3 -1
- package/dist/pipeline/task-prompt.js +11 -3
- package/dist/report/output-schema.d.ts +49 -0
- package/dist/report/output-schema.js +32 -0
- package/dist/report/output.js +22 -0
- package/dist/report/report.d.ts +9 -1
- package/dist/report/report.js +1 -0
- package/dist/report/serialize.d.ts +0 -1
- package/dist/report/serialize.js +1 -15
- package/dist/rereview/presence.js +1 -1
- package/dist/review/change-text.d.ts +4 -0
- package/dist/review/change-text.js +26 -0
- package/dist/review/context-sources.d.ts +5 -0
- package/dist/review/context-sources.js +37 -0
- package/dist/review/prompt-text.d.ts +1 -1
- package/dist/review/prompt-text.js +11 -0
- package/dist/review/prompt.d.ts +13 -1
- package/dist/review/prompt.js +140 -36
- package/dist/task/linked-task.d.ts +50 -0
- package/dist/task/linked-task.js +37 -0
- package/dist/triage.d.ts +1 -0
- package/dist/triage.js +5 -2
- package/dist/unsafe-text.d.ts +1 -0
- package/dist/unsafe-text.js +15 -0
- package/dist/vcs.d.ts +22 -0
- package/dist/walkthrough/prompt.d.ts +0 -3
- package/dist/walkthrough/prompt.js +2 -26
- package/package.json +1 -1
- /package/dist/{rereview → anchor}/quote.d.ts +0 -0
package/dist/pipeline/options.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { OcraError } from "../errors.js";
|
|
3
|
+
import { isOptionalContext, OPTIONAL_CONTEXT, } from "../review/context-sources.js";
|
|
3
4
|
export const REVIEW_DEFAULTS = {
|
|
4
5
|
concurrency: 4,
|
|
5
6
|
taskTimeoutMs: 10 * 60_000,
|
|
@@ -36,5 +37,18 @@ export function runSettings(options) {
|
|
|
36
37
|
judge: options.stages?.judge !== false,
|
|
37
38
|
showPreExisting: options.stages?.showPreExisting !== false,
|
|
38
39
|
walkthrough: options.stages?.walkthrough === true,
|
|
40
|
+
without: withoutContext(options.mode?.without ?? []),
|
|
41
|
+
fixes: options.stages?.fixes === true,
|
|
39
42
|
};
|
|
40
43
|
}
|
|
44
|
+
function withoutContext(names) {
|
|
45
|
+
const unknown = names.filter((n) => !isOptionalContext(n));
|
|
46
|
+
if (unknown.length > 0) {
|
|
47
|
+
throw new OcraError("CONFIG_INVALID", `ReviewOptions.mode.without names unknown context: ${unknown.join(", ")} (known: ${OPTIONAL_CONTEXT.join(", ")})`);
|
|
48
|
+
}
|
|
49
|
+
return new Set(names);
|
|
50
|
+
}
|
|
51
|
+
// A reviewer that needs the guidelines does not run when they are left out.
|
|
52
|
+
export function guidelinesShown(guidelines, settings) {
|
|
53
|
+
return Boolean(guidelines?.trim()) && !settings.without.has("guidelines");
|
|
54
|
+
}
|
|
@@ -59,6 +59,27 @@ export declare const planOutputSchema: z.ZodObject<{
|
|
|
59
59
|
}>>;
|
|
60
60
|
models: z.ZodExactOptional<z.ZodArray<z.ZodString>>;
|
|
61
61
|
planPromptTokens: z.ZodExactOptional<z.ZodInt>;
|
|
62
|
+
context: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
|
|
63
|
+
source: z.ZodEnum<{
|
|
64
|
+
accepted: "accepted";
|
|
65
|
+
analyzer: "analyzer";
|
|
66
|
+
callers: "callers";
|
|
67
|
+
change_request: "change_request";
|
|
68
|
+
changed_files: "changed_files";
|
|
69
|
+
diff: "diff";
|
|
70
|
+
guidelines: "guidelines";
|
|
71
|
+
instructions: "instructions";
|
|
72
|
+
learnings: "learnings";
|
|
73
|
+
linked_tasks: "linked_tasks";
|
|
74
|
+
plan: "plan";
|
|
75
|
+
project_docs: "project_docs";
|
|
76
|
+
rules: "rules";
|
|
77
|
+
system: "system";
|
|
78
|
+
}>;
|
|
79
|
+
tokens: z.ZodInt;
|
|
80
|
+
cut: z.ZodExactOptional<z.ZodInt>;
|
|
81
|
+
duplicateTokens: z.ZodExactOptional<z.ZodInt>;
|
|
82
|
+
}, z.core.$strict>>>;
|
|
62
83
|
inputCost: z.ZodExactOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
63
84
|
model: z.ZodString;
|
|
64
85
|
status: z.ZodLiteral<"priced">;
|
|
@@ -2,6 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import { EFFORT_LEVELS } from "../agent/settings.js";
|
|
3
3
|
import { riskTierSchema } from "../domain.js";
|
|
4
4
|
import { changeRequestSchema, scopeSchema, skippedCellSchema } from "../report/output-schema.js";
|
|
5
|
+
import { CONTEXT_SOURCES } from "../review/context-sources.js";
|
|
5
6
|
import { exclusionReasonSchema } from "../select/select.js";
|
|
6
7
|
// The published shape of `ocra review --plan --format json` without what
|
|
7
8
|
// the CLI adds (where each setting came from), versioned like the report: a
|
|
@@ -22,6 +23,15 @@ const planTaskSchema = z.strictObject({
|
|
|
22
23
|
effort: z.enum(EFFORT_LEVELS).exactOptional(),
|
|
23
24
|
models: z.array(z.string()).exactOptional(),
|
|
24
25
|
planPromptTokens: z.int().nonnegative().exactOptional(),
|
|
26
|
+
// Added in version 1 without a bump: the first prompt by source (ADR-0057).
|
|
27
|
+
context: z
|
|
28
|
+
.array(z.strictObject({
|
|
29
|
+
source: z.enum(CONTEXT_SOURCES),
|
|
30
|
+
tokens: z.int().nonnegative(),
|
|
31
|
+
cut: z.int().positive().exactOptional(),
|
|
32
|
+
duplicateTokens: z.int().positive().exactOptional(),
|
|
33
|
+
}))
|
|
34
|
+
.exactOptional(),
|
|
25
35
|
inputCost: inputCostSchema.exactOptional(),
|
|
26
36
|
});
|
|
27
37
|
export const planOutputSchema = z.strictObject({
|
|
@@ -97,6 +107,7 @@ function planTask(t) {
|
|
|
97
107
|
bundle: t.bundle,
|
|
98
108
|
files: [...t.files],
|
|
99
109
|
promptTokens: t.promptTokens,
|
|
110
|
+
context: t.context.map((c) => ({ ...c })),
|
|
100
111
|
...(t.effort === undefined ? {} : { effort: t.effort }),
|
|
101
112
|
...(t.models ? { models: [...t.models] } : {}),
|
|
102
113
|
...(t.planPromptTokens === undefined ? {} : { planPromptTokens: t.planPromptTokens }),
|
package/dist/pipeline/plan.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Bundle } from "../bundle/bundle.js";
|
|
2
2
|
import type { AgentRuntime, ReviewContext, Usage } from "../contracts.js";
|
|
3
|
+
import { type DocSection } from "../docs/project-docs.js";
|
|
3
4
|
import type { ChangeRequest, FileDiff, PriorReview, RiskTier } from "../domain.js";
|
|
4
5
|
import type { SelectLearnings } from "../knowledge/select.js";
|
|
5
6
|
import { type RememberedEntry } from "../memory/memory.js";
|
|
@@ -7,6 +8,7 @@ import type { ReviewEvent, ReviewReport } from "../report/report.js";
|
|
|
7
8
|
import { type SourcedRule } from "../rules/repo-rules.js";
|
|
8
9
|
import { type AnalyzerEvidence } from "../sarif/evidence.js";
|
|
9
10
|
import { type FileDecision } from "../select/select.js";
|
|
11
|
+
import type { BoundLinkedTasks } from "../task/linked-task.js";
|
|
10
12
|
import type { ReviewHooks, ReviewOptions } from "./options.js";
|
|
11
13
|
export interface ReviewPlan {
|
|
12
14
|
changeRequest: ChangeRequest;
|
|
@@ -25,11 +27,13 @@ export interface ReviewPlan {
|
|
|
25
27
|
repoRules: SourcedRule[];
|
|
26
28
|
memory: RememberedEntry[];
|
|
27
29
|
learnings: SelectLearnings;
|
|
30
|
+
linkedTasks?: BoundLinkedTasks;
|
|
31
|
+
docSections: DocSection[];
|
|
28
32
|
evidence: AnalyzerEvidence;
|
|
29
33
|
usage: Usage[];
|
|
30
34
|
warnings: string[];
|
|
31
35
|
}
|
|
32
|
-
export type PlanOptions = Pick<ReviewOptions & ReviewHooks, "vcs" | "rules" | "readTrusted" | "accountMemory" | "learnings" | "symbols" | "sarifEvidence" | "selection" | "bundling" | "grouper" | "effort" | "roles" | "resume"> & {
|
|
36
|
+
export type PlanOptions = Pick<ReviewOptions & ReviewHooks, "vcs" | "rules" | "readTrusted" | "accountMemory" | "learnings" | "linkedTasks" | "taskSources" | "projectDocs" | "symbols" | "sarifEvidence" | "selection" | "bundling" | "grouper" | "effort" | "roles" | "resume"> & {
|
|
33
37
|
runId?: string;
|
|
34
38
|
runtime?: AgentRuntime;
|
|
35
39
|
full?: boolean;
|
package/dist/pipeline/plan.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { roleCall } from "../agent/settings.js";
|
|
2
2
|
import { bundleFiles, defaultBundlePolicy } from "../bundle/bundle.js";
|
|
3
3
|
import { runtimeGrouper } from "../bundle/runtime-grouper.js";
|
|
4
|
+
import { docSections } from "../docs/project-docs.js";
|
|
4
5
|
import { errorMessage } from "../errors.js";
|
|
5
6
|
import { rank } from "../matrix/matrix.js";
|
|
6
7
|
import { MEMORY_PATH, mergeMemory, parseMemory } from "../memory/memory.js";
|
|
@@ -10,6 +11,7 @@ import { binaryTextWarning, defaultSelectionPolicy, selectFiles, } from "../sele
|
|
|
10
11
|
import { triage } from "../triage.js";
|
|
11
12
|
import { reviewContext } from "./context.js";
|
|
12
13
|
import { bundleLearnings } from "./learnings.js";
|
|
14
|
+
import { loadLinkedTasks } from "./linked-tasks.js";
|
|
13
15
|
import { resumedBundles } from "./resume.js";
|
|
14
16
|
import { newRunId } from "./run-id.js";
|
|
15
17
|
const GUIDELINES_PATH = "AGENTS.md";
|
|
@@ -31,10 +33,14 @@ export async function planReview(options, emit, signal) {
|
|
|
31
33
|
excluded: diffs.length - selected.length,
|
|
32
34
|
tier,
|
|
33
35
|
});
|
|
34
|
-
const [guidelines, fileRules, memoryText] = await Promise.all([
|
|
36
|
+
const [guidelines, fileRules, memoryText, linked] = await Promise.all([
|
|
35
37
|
readTrusted(GUIDELINES_PATH),
|
|
36
38
|
loadRepoRules(readTrusted),
|
|
37
39
|
readTrusted(MEMORY_PATH),
|
|
40
|
+
loadLinkedTasks(vcs, changeRequest, options.taskSources ?? [], {
|
|
41
|
+
enabled: options.linkedTasks !== false,
|
|
42
|
+
signal,
|
|
43
|
+
}),
|
|
38
44
|
]);
|
|
39
45
|
const usage = [];
|
|
40
46
|
const grouper = options.grouper ??
|
|
@@ -94,9 +100,16 @@ export async function planReview(options, emit, signal) {
|
|
|
94
100
|
],
|
|
95
101
|
memory: mergeMemory(memoryText === undefined ? [] : parseMemory(memoryText), options.accountMemory ?? []),
|
|
96
102
|
learnings,
|
|
103
|
+
...(linked.tasks ? { linkedTasks: linked.tasks } : {}),
|
|
104
|
+
docSections: docSections(options.projectDocs ?? []),
|
|
97
105
|
evidence,
|
|
98
106
|
usage,
|
|
99
|
-
warnings: [
|
|
107
|
+
warnings: [
|
|
108
|
+
...(binaryText ? [binaryText] : []),
|
|
109
|
+
...linked.warnings,
|
|
110
|
+
...bundled.warnings,
|
|
111
|
+
...evidence.warnings,
|
|
112
|
+
],
|
|
100
113
|
};
|
|
101
114
|
}
|
|
102
115
|
async function loadRepoRules(read) {
|
|
@@ -2,6 +2,7 @@ import type { Effort } from "../contracts.js";
|
|
|
2
2
|
import type { ChangeRequest, RiskTier } from "../domain.js";
|
|
3
3
|
import { type SkippedCell } from "../matrix/matrix.js";
|
|
4
4
|
import type { FileDecision } from "../select/select.js";
|
|
5
|
+
import { type SourceFootprint } from "./context-footprint.js";
|
|
5
6
|
import { type ReviewOptions } from "./options.js";
|
|
6
7
|
import { type PlanOptions, type ReviewPlan } from "./plan.js";
|
|
7
8
|
export interface PreviewTask {
|
|
@@ -10,6 +11,7 @@ export interface PreviewTask {
|
|
|
10
11
|
bundle: string;
|
|
11
12
|
files: string[];
|
|
12
13
|
promptTokens: number;
|
|
14
|
+
context: SourceFootprint[];
|
|
13
15
|
planPromptTokens?: number;
|
|
14
16
|
effort?: Effort;
|
|
15
17
|
models?: string[];
|
package/dist/pipeline/preview.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { chainOf, reviewerCall } from "../agent/settings.js";
|
|
2
2
|
import { defaultBundlePolicy } from "../bundle/bundle.js";
|
|
3
3
|
import { planTasks } from "../matrix/matrix.js";
|
|
4
|
+
import { reviewPromptParts } from "../review/prompt.js";
|
|
4
5
|
import { correctnessReviewer } from "../review/reviewers/correctness.js";
|
|
5
6
|
import { securityReviewed } from "../sarif/evidence.js";
|
|
6
|
-
import {
|
|
7
|
+
import { contextFootprint, estimateTokens } from "./context-footprint.js";
|
|
8
|
+
import { guidelinesShown, runSettings } from "./options.js";
|
|
7
9
|
import { planReview } from "./plan.js";
|
|
8
10
|
import { taskPrompt } from "./task-prompt.js";
|
|
9
11
|
// Everything a review would do before its first model call, for free: which
|
|
@@ -15,19 +17,24 @@ export async function previewReview(options) {
|
|
|
15
17
|
const planned = planTasks(plan.bundles, reviewers, plan.tier, options.reviewerOverrides, {
|
|
16
18
|
ultra: settings.ultra,
|
|
17
19
|
...(settings.maxTasks !== undefined ? { maxTasks: settings.maxTasks } : {}),
|
|
18
|
-
hasGuidelines:
|
|
20
|
+
hasGuidelines: guidelinesShown(plan.guidelines, settings),
|
|
19
21
|
});
|
|
20
22
|
const { cells } = planned;
|
|
21
23
|
const plannedBundles = new Set();
|
|
22
24
|
const securityFiles = securityReviewed(cells);
|
|
23
25
|
const tasks = cells.map((cell) => {
|
|
24
|
-
const prepared = taskPrompt(cell, plan, {
|
|
26
|
+
const prepared = taskPrompt(cell, plan, {
|
|
27
|
+
ultra: settings.ultra,
|
|
28
|
+
securityFiles,
|
|
29
|
+
without: settings.without,
|
|
30
|
+
});
|
|
25
31
|
const task = {
|
|
26
32
|
taskId: cell.taskId,
|
|
27
33
|
reviewer: cell.reviewer.id,
|
|
28
34
|
bundle: cell.bundle.label,
|
|
29
35
|
files: cell.bundle.files.map((f) => f.newPath),
|
|
30
36
|
promptTokens: tokens(prepared.prompt),
|
|
37
|
+
context: contextFootprint(reviewPromptParts(prepared.input)),
|
|
31
38
|
};
|
|
32
39
|
const call = reviewerCall(cell.reviewer, options);
|
|
33
40
|
if (call.effort !== undefined)
|
|
@@ -89,5 +96,5 @@ function totalInputCost(tasks) {
|
|
|
89
96
|
}
|
|
90
97
|
// Four characters per token: an estimate, not a tokenizer.
|
|
91
98
|
function tokens(prompt) {
|
|
92
|
-
return
|
|
99
|
+
return estimateTokens(prompt.system.length + prompt.user.length);
|
|
93
100
|
}
|
package/dist/pipeline/run.js
CHANGED
|
@@ -5,14 +5,17 @@ import { assembleReport } from "./assemble-report.js";
|
|
|
5
5
|
import { checkStage } from "./check-stage.js";
|
|
6
6
|
import { executeStage } from "./execute-stage.js";
|
|
7
7
|
import { filterStage } from "./filter-stage.js";
|
|
8
|
+
import { fixStage } from "./fix-stage.js";
|
|
9
|
+
import { mergeChecksStage } from "./merge-checks-stage.js";
|
|
8
10
|
import { runSettings } from "./options.js";
|
|
9
11
|
import { planReview } from "./plan.js";
|
|
10
12
|
import { newRunId } from "./run-id.js";
|
|
11
13
|
import { walkthroughStage } from "./walkthrough-stage.js";
|
|
12
14
|
// The library entry: plan (deterministic stages) → execute (one agent task
|
|
13
|
-
// per cell, beside the walkthrough
|
|
14
|
-
// → check (verify, judge) → report. The `ocra`
|
|
15
|
-
// manual's Embedding page says which options are
|
|
15
|
+
// per cell, beside the walkthrough and the pre-merge checks) → filter
|
|
16
|
+
// (memory, the previous review) → check (verify, judge) → fix → report. The `ocra`
|
|
17
|
+
// command is one caller. The manual's Embedding page says which options are
|
|
18
|
+
// a contract.
|
|
16
19
|
export function review(options) {
|
|
17
20
|
return reviewWithHooks(options);
|
|
18
21
|
}
|
|
@@ -37,10 +40,19 @@ export async function reviewWithHooks(options) {
|
|
|
37
40
|
emit,
|
|
38
41
|
};
|
|
39
42
|
const walkthrough = walkthroughStage(context);
|
|
43
|
+
const mergeChecks = mergeChecksStage(context);
|
|
40
44
|
const executed = await executeStage(reviewers, context);
|
|
41
45
|
const filtered = await filterStage(executed, plan.prior.review, context);
|
|
42
46
|
const checked = await checkStage(filtered, context);
|
|
43
|
-
const
|
|
47
|
+
const fixed = await fixStage(checked, context);
|
|
48
|
+
const report = assembleReport({ runId, reviewers }, {
|
|
49
|
+
executed,
|
|
50
|
+
filtered,
|
|
51
|
+
checked,
|
|
52
|
+
fixed,
|
|
53
|
+
walkthrough: await walkthrough,
|
|
54
|
+
mergeChecks: await mergeChecks,
|
|
55
|
+
}, context);
|
|
44
56
|
emit({ type: "run_finished", report });
|
|
45
57
|
return report;
|
|
46
58
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { MatrixCell } from "../matrix/matrix.js";
|
|
2
|
+
import type { OptionalContext } from "../review/context-sources.js";
|
|
2
3
|
import { type ReviewPrompt, type ReviewPromptInput } from "../review/prompt.js";
|
|
3
4
|
import type { ReviewPlan } from "./plan.js";
|
|
4
5
|
export interface TaskPrompt {
|
|
@@ -12,6 +13,7 @@ export interface TaskPrompt {
|
|
|
12
13
|
}
|
|
13
14
|
export interface TaskSettings {
|
|
14
15
|
ultra: boolean;
|
|
16
|
+
without?: ReadonlySet<OptionalContext>;
|
|
15
17
|
securityFiles: ReadonlySet<string>;
|
|
16
18
|
}
|
|
17
|
-
export declare function taskPrompt(cell: MatrixCell, plan: ReviewPlan, { ultra, securityFiles }: TaskSettings): TaskPrompt;
|
|
19
|
+
export declare function taskPrompt(cell: MatrixCell, plan: ReviewPlan, { ultra, securityFiles, without }: TaskSettings): TaskPrompt;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { sectionsFor } from "../docs/project-docs.js";
|
|
1
2
|
import { memoryFor } from "../memory/memory.js";
|
|
2
3
|
import { buildReviewPrompt } from "../review/prompt.js";
|
|
3
4
|
import { resolveRules } from "../rules/resolve.js";
|
|
@@ -8,24 +9,31 @@ const PLAN_MIN_FILES = 5;
|
|
|
8
9
|
const PLAN_MIN_PATCH_CHARS = 40_000;
|
|
9
10
|
// What one task of the matrix sends: the run builds its prompt from this and
|
|
10
11
|
// --plan previews it, so the preview cannot drift from the run.
|
|
11
|
-
export function taskPrompt(cell, plan, { ultra, securityFiles }) {
|
|
12
|
+
export function taskPrompt(cell, plan, { ultra, securityFiles, without }) {
|
|
12
13
|
const files = cell.bundle.files.map((f) => f.newPath);
|
|
13
14
|
const learnings = plan.learnings(cell.bundle.files);
|
|
15
|
+
const docs = sectionsFor(plan.docSections, files);
|
|
14
16
|
const analyzerResults = evidenceForReviewer(plan.evidence.forBundle(cell.bundle), cell.reviewer.category, securityFiles);
|
|
15
17
|
const input = {
|
|
16
18
|
reviewer: cell.reviewer,
|
|
17
19
|
changeRequest: plan.changeRequest,
|
|
18
20
|
changedFiles: plan.selected,
|
|
19
21
|
bundle: cell.bundle.files,
|
|
20
|
-
rules: resolveRules(files,
|
|
22
|
+
rules: resolveRules(files, [], cell.reviewer.rules),
|
|
23
|
+
repoRules: resolveRules(files, plan.repoRules),
|
|
21
24
|
guidelines: plan.guidelines,
|
|
25
|
+
...(plan.linkedTasks && plan.linkedTasks.given.length > 0
|
|
26
|
+
? { linkedTasks: plan.linkedTasks.given }
|
|
27
|
+
: {}),
|
|
22
28
|
accepted: memoryFor(files, plan.memory),
|
|
23
29
|
learnings: learnings.selected,
|
|
24
30
|
moreLearnings: learnings.left,
|
|
31
|
+
...(docs.given.length > 0 ? { projectDocs: docs } : {}),
|
|
25
32
|
...(analyzerResults.length > 0 ? { analyzerResults } : {}),
|
|
33
|
+
...(without && without.size > 0 ? { without } : {}),
|
|
26
34
|
};
|
|
27
35
|
const prompt = buildReviewPrompt(input);
|
|
28
|
-
const callers = ultra || plan.tier === "full";
|
|
36
|
+
const callers = (ultra || plan.tier === "full") && !without?.has("callers");
|
|
29
37
|
if (!ultra && !isLargeBundle(cell.bundle))
|
|
30
38
|
return { input, prompt, callers };
|
|
31
39
|
return {
|
|
@@ -189,6 +189,28 @@ export declare const reportOutputSchema: z.ZodObject<{
|
|
|
189
189
|
}, z.core.$strict>>;
|
|
190
190
|
bundles: z.ZodArray<z.ZodString>;
|
|
191
191
|
}, z.core.$strict>>>;
|
|
192
|
+
projectDocs: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
|
|
193
|
+
path: z.ZodString;
|
|
194
|
+
heading: z.ZodString;
|
|
195
|
+
bundles: z.ZodArray<z.ZodString>;
|
|
196
|
+
}, z.core.$strict>>>;
|
|
197
|
+
linkedTasks: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
|
|
198
|
+
tracker: z.ZodEnum<{
|
|
199
|
+
github: "github";
|
|
200
|
+
gitlab: "gitlab";
|
|
201
|
+
jira: "jira";
|
|
202
|
+
tapd: "tapd";
|
|
203
|
+
}>;
|
|
204
|
+
key: z.ZodString;
|
|
205
|
+
url: z.ZodExactOptional<z.ZodString>;
|
|
206
|
+
title: z.ZodString;
|
|
207
|
+
state: z.ZodExactOptional<z.ZodEnum<{
|
|
208
|
+
closed: "closed";
|
|
209
|
+
open: "open";
|
|
210
|
+
}>>;
|
|
211
|
+
labels: z.ZodArray<z.ZodString>;
|
|
212
|
+
cut: z.ZodBoolean;
|
|
213
|
+
}, z.core.$strict>>>;
|
|
192
214
|
analyzerEvidence: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
|
|
193
215
|
tool: z.ZodString;
|
|
194
216
|
version: z.ZodExactOptional<z.ZodString>;
|
|
@@ -221,6 +243,23 @@ export declare const reportOutputSchema: z.ZodObject<{
|
|
|
221
243
|
reason: z.ZodString;
|
|
222
244
|
}, z.core.$strict>>;
|
|
223
245
|
}, z.core.$strict>>;
|
|
246
|
+
fixes: z.ZodExactOptional<z.ZodObject<{
|
|
247
|
+
asked: z.ZodInt;
|
|
248
|
+
proposed: z.ZodInt;
|
|
249
|
+
rejected: z.ZodArray<z.ZodObject<{
|
|
250
|
+
fingerprint: z.ZodString;
|
|
251
|
+
reason: z.ZodEnum<{
|
|
252
|
+
declined: "declined";
|
|
253
|
+
failed: "failed";
|
|
254
|
+
no_parser: "no_parser";
|
|
255
|
+
stale: "stale";
|
|
256
|
+
syntax: "syntax";
|
|
257
|
+
too_large: "too_large";
|
|
258
|
+
unchanged: "unchanged";
|
|
259
|
+
unsafe: "unsafe";
|
|
260
|
+
}>;
|
|
261
|
+
}, z.core.$strict>>;
|
|
262
|
+
}, z.core.$strict>>;
|
|
224
263
|
walkthrough: z.ZodExactOptional<z.ZodObject<{
|
|
225
264
|
overview: z.ZodString;
|
|
226
265
|
groups: z.ZodArray<z.ZodObject<{
|
|
@@ -230,6 +269,16 @@ export declare const reportOutputSchema: z.ZodObject<{
|
|
|
230
269
|
}, z.core.$strict>>;
|
|
231
270
|
diagram: z.ZodExactOptional<z.ZodString>;
|
|
232
271
|
}, z.core.$strict>>;
|
|
272
|
+
mergeChecks: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
|
|
273
|
+
id: z.ZodString;
|
|
274
|
+
instruction: z.ZodString;
|
|
275
|
+
outcome: z.ZodEnum<{
|
|
276
|
+
failed: "failed";
|
|
277
|
+
inconclusive: "inconclusive";
|
|
278
|
+
passed: "passed";
|
|
279
|
+
}>;
|
|
280
|
+
reason: z.ZodString;
|
|
281
|
+
}, z.core.$strict>>>;
|
|
233
282
|
rereview: z.ZodExactOptional<z.ZodObject<{
|
|
234
283
|
fixed: z.ZodArray<z.ZodObject<{
|
|
235
284
|
fingerprint: z.ZodString;
|
|
@@ -2,9 +2,12 @@ import { z } from "zod";
|
|
|
2
2
|
import { EFFORT_LEVELS } from "../agent/settings.js";
|
|
3
3
|
import { INCOMPLETE_ENDINGS, MODEL_TIERS } from "../contracts.js";
|
|
4
4
|
import { anchorMethodSchema, riskTierSchema, severitySchema, verdictSchema, verificationSchema, } from "../domain.js";
|
|
5
|
+
import { FIX_REJECTIONS } from "../fix/check.js";
|
|
5
6
|
import { skipReasonSchema } from "../matrix/matrix.js";
|
|
6
7
|
import { memoryEntrySchema } from "../memory/memory.js";
|
|
8
|
+
import { MERGE_CHECK_OUTCOMES } from "../merge-checks/merge-check.js";
|
|
7
9
|
import { exclusionReasonSchema } from "../select/select.js";
|
|
10
|
+
import { TASK_TRACKERS } from "../task/linked-task.js";
|
|
8
11
|
import { taskStatusSchema } from "./report.js";
|
|
9
12
|
// The published shape of a review: `--format json` and a session's
|
|
10
13
|
// report.json. It is a contract with scripts and CI, so it carries a version
|
|
@@ -189,6 +192,20 @@ export const reportOutputSchema = z.strictObject({
|
|
|
189
192
|
bundles: z.array(z.string()),
|
|
190
193
|
}))
|
|
191
194
|
.exactOptional(),
|
|
195
|
+
projectDocs: z
|
|
196
|
+
.array(z.strictObject({ path: z.string(), heading: z.string(), bundles: z.array(z.string()) }))
|
|
197
|
+
.exactOptional(),
|
|
198
|
+
linkedTasks: z
|
|
199
|
+
.array(z.strictObject({
|
|
200
|
+
tracker: z.enum(TASK_TRACKERS),
|
|
201
|
+
key: z.string(),
|
|
202
|
+
url: z.string().exactOptional(),
|
|
203
|
+
title: z.string(),
|
|
204
|
+
state: z.enum(["open", "closed"]).exactOptional(),
|
|
205
|
+
labels: z.array(z.string()),
|
|
206
|
+
cut: z.boolean(),
|
|
207
|
+
}))
|
|
208
|
+
.exactOptional(),
|
|
192
209
|
analyzerEvidence: z
|
|
193
210
|
.array(z.strictObject({
|
|
194
211
|
tool: z.string(),
|
|
@@ -198,6 +215,13 @@ export const reportOutputSchema = z.strictObject({
|
|
|
198
215
|
}))
|
|
199
216
|
.exactOptional(),
|
|
200
217
|
judgement: judgeDecisionsSchema.exactOptional(),
|
|
218
|
+
fixes: z
|
|
219
|
+
.strictObject({
|
|
220
|
+
asked: z.int().nonnegative(),
|
|
221
|
+
proposed: z.int().nonnegative(),
|
|
222
|
+
rejected: z.array(z.strictObject({ fingerprint: z.string(), reason: z.enum(FIX_REJECTIONS) })),
|
|
223
|
+
})
|
|
224
|
+
.exactOptional(),
|
|
201
225
|
walkthrough: z
|
|
202
226
|
.strictObject({
|
|
203
227
|
overview: z.string(),
|
|
@@ -205,6 +229,14 @@ export const reportOutputSchema = z.strictObject({
|
|
|
205
229
|
diagram: z.string().exactOptional(),
|
|
206
230
|
})
|
|
207
231
|
.exactOptional(),
|
|
232
|
+
mergeChecks: z
|
|
233
|
+
.array(z.strictObject({
|
|
234
|
+
id: z.string(),
|
|
235
|
+
instruction: z.string(),
|
|
236
|
+
outcome: z.enum(MERGE_CHECK_OUTCOMES),
|
|
237
|
+
reason: z.string(),
|
|
238
|
+
}))
|
|
239
|
+
.exactOptional(),
|
|
208
240
|
rereview: z
|
|
209
241
|
.strictObject({
|
|
210
242
|
fixed: priorList,
|
package/dist/report/output.js
CHANGED
|
@@ -22,6 +22,12 @@ export function toReportOutput(report) {
|
|
|
22
22
|
output.scope = outputScope(report.scope);
|
|
23
23
|
if (report.learnings)
|
|
24
24
|
output.learnings = report.learnings.map(outputLearning);
|
|
25
|
+
if (report.projectDocs) {
|
|
26
|
+
output.projectDocs = report.projectDocs.map((d) => ({ ...d, bundles: [...d.bundles] }));
|
|
27
|
+
}
|
|
28
|
+
if (report.linkedTasks) {
|
|
29
|
+
output.linkedTasks = report.linkedTasks.map((t) => ({ ...t, labels: [...t.labels] }));
|
|
30
|
+
}
|
|
25
31
|
if (report.analyzerEvidence) {
|
|
26
32
|
output.analyzerEvidence = report.analyzerEvidence.map((e) => ({
|
|
27
33
|
tool: e.tool,
|
|
@@ -32,8 +38,24 @@ export function toReportOutput(report) {
|
|
|
32
38
|
}
|
|
33
39
|
if (report.judgement)
|
|
34
40
|
output.judgement = outputJudgement(report.judgement);
|
|
41
|
+
if (report.fixes) {
|
|
42
|
+
const { asked, proposed, rejected } = report.fixes;
|
|
43
|
+
output.fixes = {
|
|
44
|
+
asked,
|
|
45
|
+
proposed,
|
|
46
|
+
rejected: rejected.map(({ fingerprint, reason }) => ({ fingerprint, reason })),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
35
49
|
if (report.walkthrough)
|
|
36
50
|
output.walkthrough = outputWalkthrough(report.walkthrough);
|
|
51
|
+
if (report.mergeChecks) {
|
|
52
|
+
output.mergeChecks = report.mergeChecks.map(({ id, instruction, outcome, reason }) => ({
|
|
53
|
+
id,
|
|
54
|
+
instruction,
|
|
55
|
+
outcome,
|
|
56
|
+
reason,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
37
59
|
if (report.anchoring)
|
|
38
60
|
output.anchoring = outputAnchoring(report.anchoring);
|
|
39
61
|
if (report.spendLimit)
|
package/dist/report/report.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import type { AttemptRecord, IncompleteEnding, Usage } from "../contracts.js";
|
|
3
|
+
import type { ProjectDocUse } from "../docs/project-docs.js";
|
|
3
4
|
import type { AnchorMethod, ChangeRequest, Finding, PriorFinding, RiskTier, TaskFinding, Verdict } from "../domain.js";
|
|
5
|
+
import type { FixSummary } from "../fix/propose.js";
|
|
4
6
|
import type { JudgeDecisions } from "../judge/judge.js";
|
|
5
7
|
import type { LearningUse } from "../knowledge/learning.js";
|
|
6
8
|
import type { SkippedCell } from "../matrix/matrix.js";
|
|
7
9
|
import type { RememberedEntry } from "../memory/memory.js";
|
|
10
|
+
import type { MergeCheckResult } from "../merge-checks/merge-check.js";
|
|
8
11
|
import type { AnalyzerEvidenceUse } from "../sarif/evidence.js";
|
|
9
12
|
import type { ExclusionReason } from "../select/select.js";
|
|
13
|
+
import type { LinkedTaskUse } from "../task/linked-task.js";
|
|
10
14
|
import type { RefutedFinding } from "../verify/verify.js";
|
|
11
15
|
import type { Walkthrough } from "../walkthrough/walkthrough.js";
|
|
12
16
|
import type { RunProvenance } from "./provenance.js";
|
|
@@ -84,9 +88,13 @@ export interface ReviewReport {
|
|
|
84
88
|
refuted: RefutedFinding[];
|
|
85
89
|
remembered: RememberedEntry[];
|
|
86
90
|
learnings?: LearningUse[];
|
|
91
|
+
linkedTasks?: LinkedTaskUse[];
|
|
92
|
+
projectDocs?: ProjectDocUse[];
|
|
87
93
|
analyzerEvidence?: AnalyzerEvidenceUse[];
|
|
88
94
|
judgement?: JudgeDecisions;
|
|
95
|
+
fixes?: FixSummary;
|
|
89
96
|
walkthrough?: Walkthrough;
|
|
97
|
+
mergeChecks?: MergeCheckResult[];
|
|
90
98
|
scope?: {
|
|
91
99
|
mode: "incremental";
|
|
92
100
|
since: string;
|
|
@@ -110,7 +118,7 @@ export interface ReviewReport {
|
|
|
110
118
|
usage: Usage;
|
|
111
119
|
warnings: string[];
|
|
112
120
|
}
|
|
113
|
-
export declare const REVIEW_STAGES: readonly ["select", "bundle", "plan", "review", "filter", "verify", "judge"];
|
|
121
|
+
export declare const REVIEW_STAGES: readonly ["select", "bundle", "plan", "review", "filter", "verify", "judge", "fix"];
|
|
114
122
|
export type ReviewStage = (typeof REVIEW_STAGES)[number];
|
|
115
123
|
export type ReviewEvent = {
|
|
116
124
|
type: "run_started";
|
package/dist/report/report.js
CHANGED
package/dist/report/serialize.js
CHANGED
|
@@ -1,18 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
// newline, DEL and C1 controls (ANSI and OSC escapes), line and paragraph
|
|
3
|
-
// separators, and bidirectional marks and overrides ("Trojan Source"). One
|
|
4
|
-
// definition for every output: terminal text replaces them, JSON escapes them.
|
|
5
|
-
export function isUnsafeCodePoint(code) {
|
|
6
|
-
return ((code <= 0x1f && code !== 0x09 && code !== 0x0a) ||
|
|
7
|
-
(code >= 0x7f && code <= 0x9f) ||
|
|
8
|
-
code === 0x061c ||
|
|
9
|
-
code === 0x200e ||
|
|
10
|
-
code === 0x200f ||
|
|
11
|
-
code === 0x2028 ||
|
|
12
|
-
code === 0x2029 ||
|
|
13
|
-
(code >= 0x202a && code <= 0x202e) ||
|
|
14
|
-
(code >= 0x2066 && code <= 0x2069));
|
|
15
|
-
}
|
|
1
|
+
import { isUnsafeCodePoint } from "../unsafe-text.js";
|
|
16
2
|
// JSON for files and stdout. JSON.stringify escapes C0 controls but not the
|
|
17
3
|
// rest; model and pull request text reaches these files.
|
|
18
4
|
export function serializeOutput(value, indent = 2) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mapWithConcurrency } from "../agent/pool.js";
|
|
2
|
-
import { containsQuote } from "
|
|
2
|
+
import { containsQuote } from "../anchor/quote.js";
|
|
3
3
|
const READ_CONCURRENCY = 8;
|
|
4
4
|
// For each earlier finding not reported again: is its code still at head?
|
|
5
5
|
// A deleted file is a definite no; a failed read or a finding without a
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { data, join, ocraText, oneLine, section } from "./prompt-text.js";
|
|
2
|
+
// The change as one call reads it at a skim: every file's name and size, and
|
|
3
|
+
// as much of each patch as fits, smallest first, so one generated or
|
|
4
|
+
// vendored file cannot crowd out the rest of the change.
|
|
5
|
+
const MAX_FILE_PATCH_CHARS = 4_000;
|
|
6
|
+
export function changedFile(f) {
|
|
7
|
+
const path = f.kind === "renamed" ? `${f.oldPath} -> ${f.newPath}` : f.newPath;
|
|
8
|
+
return join([ocraText(`${f.kind} `), data(oneLine(path)), ocraText(` (+${f.additions} -${f.deletions})`)], "");
|
|
9
|
+
}
|
|
10
|
+
export function smallestPatchesFirst(files, maxChars) {
|
|
11
|
+
let room = maxChars;
|
|
12
|
+
const shown = [];
|
|
13
|
+
const bySize = [...files]
|
|
14
|
+
.filter((f) => !f.isBinary && f.patch !== "")
|
|
15
|
+
.sort((a, b) => a.patch.length - b.patch.length);
|
|
16
|
+
for (const f of bySize) {
|
|
17
|
+
const patch = f.patch.length > MAX_FILE_PATCH_CHARS
|
|
18
|
+
? join([data(f.patch.slice(0, MAX_FILE_PATCH_CHARS)), ocraText("[patch truncated]")])
|
|
19
|
+
: data(f.patch);
|
|
20
|
+
if (patch.length > room)
|
|
21
|
+
continue;
|
|
22
|
+
room -= patch.length;
|
|
23
|
+
shown.push(section("diff", patch, { path: f.newPath }));
|
|
24
|
+
}
|
|
25
|
+
return shown;
|
|
26
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const CONTEXT_SOURCES: readonly ["system", "change_request", "changed_files", "linked_tasks", "guidelines", "rules", "accepted", "learnings", "project_docs", "diff", "callers", "analyzer", "plan", "instructions"];
|
|
2
|
+
export type ContextSource = (typeof CONTEXT_SOURCES)[number];
|
|
3
|
+
export declare const OPTIONAL_CONTEXT: readonly ["description", "changed_files", "linked_tasks", "guidelines", "rules", "accepted", "learnings", "project_docs", "callers", "analyzer"];
|
|
4
|
+
export type OptionalContext = (typeof OPTIONAL_CONTEXT)[number];
|
|
5
|
+
export declare function isOptionalContext(value: string): value is OptionalContext;
|