@open-cr-agent/core 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/settings.d.ts +1 -1
- package/dist/agent/settings.js +2 -1
- package/dist/chat/answer.d.ts +10 -0
- package/dist/chat/answer.js +26 -0
- package/dist/chat/prompt.d.ts +22 -0
- package/dist/chat/prompt.js +65 -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/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 +5 -1
- package/dist/index.js +3 -0
- package/dist/internal.d.ts +3 -0
- package/dist/internal.js +2 -0
- package/dist/knowledge/paths.d.ts +1 -0
- package/dist/knowledge/paths.js +18 -0
- package/dist/knowledge/select.d.ts +1 -1
- package/dist/knowledge/select.js +46 -105
- package/dist/knowledge/terms.d.ts +21 -0
- package/dist/knowledge/terms.js +153 -0
- package/dist/learn/draft.js +5 -2
- 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/answer.d.ts +16 -0
- package/dist/pipeline/answer.js +29 -0
- package/dist/pipeline/assemble-report.d.ts +4 -0
- package/dist/pipeline/assemble-report.js +20 -2
- package/dist/pipeline/execute-stage.js +6 -4
- package/dist/pipeline/execute.d.ts +8 -2
- package/dist/pipeline/execute.js +7 -6
- package/dist/pipeline/generate.d.ts +22 -0
- package/dist/pipeline/generate.js +154 -0
- package/dist/pipeline/learnings.d.ts +7 -0
- package/dist/pipeline/learnings.js +20 -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 +9 -0
- package/dist/pipeline/options.js +1 -0
- package/dist/pipeline/plan.d.ts +6 -2
- package/dist/pipeline/plan.js +20 -5
- package/dist/pipeline/preview.js +3 -1
- package/dist/pipeline/run.js +15 -4
- package/dist/pipeline/task-prompt.d.ts +5 -1
- package/dist/pipeline/task-prompt.js +9 -2
- package/dist/pipeline/walkthrough-stage.d.ts +9 -0
- package/dist/pipeline/walkthrough-stage.js +20 -0
- package/dist/report/output-schema.d.ts +41 -0
- package/dist/report/output-schema.js +31 -0
- package/dist/report/output.js +23 -0
- package/dist/report/report.d.ts +8 -0
- package/dist/review/change-text.d.ts +4 -0
- package/dist/review/change-text.js +26 -0
- package/dist/review/impact.d.ts +1 -0
- package/dist/review/impact.js +33 -0
- package/dist/review/prompt-text.d.ts +1 -1
- package/dist/review/prompt-text.js +12 -0
- package/dist/review/prompt.d.ts +4 -0
- package/dist/review/prompt.js +60 -0
- package/dist/sarif/evidence.d.ts +7 -0
- package/dist/sarif/evidence.js +14 -0
- package/dist/task/linked-task.d.ts +48 -0
- package/dist/task/linked-task.js +35 -0
- package/dist/triage.d.ts +1 -0
- package/dist/triage.js +5 -2
- package/dist/vcs.d.ts +44 -0
- package/dist/walkthrough/diagram.d.ts +1 -0
- package/dist/walkthrough/diagram.js +49 -0
- package/dist/walkthrough/prompt.d.ts +16 -0
- package/dist/walkthrough/prompt.js +38 -0
- package/dist/walkthrough/walkthrough.d.ts +27 -0
- package/dist/walkthrough/walkthrough.js +71 -0
- package/package.json +2 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { roleCall } from "../agent/settings.js";
|
|
2
|
+
import { judgeMergeChecks, notJudged } from "../merge-checks/merge-checks.js";
|
|
3
|
+
// Runs beside the review tasks: it reads only the plan, and never rejects.
|
|
4
|
+
export async function mergeChecksStage({ options, plan, spendLimit, signal, }) {
|
|
5
|
+
const checks = options.mergeChecks ?? [];
|
|
6
|
+
if (checks.length === 0)
|
|
7
|
+
return { results: [], usage: [], warnings: [] };
|
|
8
|
+
if (!spendLimit.mayCall())
|
|
9
|
+
return { ...notJudged(checks, "the spend limit was reached"), usage: [] };
|
|
10
|
+
const usage = [];
|
|
11
|
+
const result = await judgeMergeChecks({
|
|
12
|
+
runtime: options.runtime,
|
|
13
|
+
changeRequest: plan.changeRequest,
|
|
14
|
+
files: plan.selected,
|
|
15
|
+
checks,
|
|
16
|
+
signal,
|
|
17
|
+
onUsage: (u) => {
|
|
18
|
+
usage.push(u);
|
|
19
|
+
spendLimit.charge(u);
|
|
20
|
+
},
|
|
21
|
+
call: roleCall("judge", options),
|
|
22
|
+
});
|
|
23
|
+
return { ...result, usage };
|
|
24
|
+
}
|
|
@@ -3,13 +3,16 @@ import type { AnchorContext } from "../anchor/anchor.js";
|
|
|
3
3
|
import type { BundlePolicy } from "../bundle/bundle.js";
|
|
4
4
|
import type { FileGrouper } from "../bundle/grouping.js";
|
|
5
5
|
import type { AgentRuntime, ModelChains, ReferenceIndex, SymbolExtractor } from "../contracts.js";
|
|
6
|
+
import type { ProjectDoc } from "../docs/project-docs.js";
|
|
6
7
|
import type { Learning } from "../knowledge/learning.js";
|
|
7
8
|
import type { MemoryEntry } from "../memory/memory.js";
|
|
9
|
+
import type { MergeCheck } from "../merge-checks/merge-check.js";
|
|
8
10
|
import type { ReviewEvent } from "../report/report.js";
|
|
9
11
|
import type { ReviewerDefinition } from "../review/reviewer.js";
|
|
10
12
|
import type { SourcedRule } from "../rules/repo-rules.js";
|
|
11
13
|
import type { SarifLog } from "../sarif/schema.js";
|
|
12
14
|
import type { SelectionPolicy } from "../select/select.js";
|
|
15
|
+
import type { TaskSource } from "../task/linked-task.js";
|
|
13
16
|
import type { VcsAdapter } from "../vcs.js";
|
|
14
17
|
import type { ProvenanceInput } from "./provenance.js";
|
|
15
18
|
import type { ResumedRun } from "./resume.js";
|
|
@@ -25,6 +28,10 @@ export interface ReviewOptions {
|
|
|
25
28
|
readTrusted?: (path: string) => Promise<string | undefined>;
|
|
26
29
|
accountMemory?: readonly MemoryEntry[];
|
|
27
30
|
learnings?: readonly Learning[];
|
|
31
|
+
linkedTasks?: boolean;
|
|
32
|
+
taskSources?: readonly TaskSource[];
|
|
33
|
+
projectDocs?: readonly ProjectDoc[];
|
|
34
|
+
mergeChecks?: readonly MergeCheck[];
|
|
28
35
|
selection?: Partial<SelectionPolicy>;
|
|
29
36
|
limits?: ReviewLimits;
|
|
30
37
|
stages?: ReviewStages;
|
|
@@ -49,6 +56,7 @@ export interface ReviewStages {
|
|
|
49
56
|
verify?: boolean;
|
|
50
57
|
judge?: boolean;
|
|
51
58
|
showPreExisting?: boolean;
|
|
59
|
+
walkthrough?: boolean;
|
|
52
60
|
}
|
|
53
61
|
export interface ReviewMode {
|
|
54
62
|
full?: boolean;
|
|
@@ -81,5 +89,6 @@ export interface RunSettings {
|
|
|
81
89
|
verify: boolean;
|
|
82
90
|
judge: boolean;
|
|
83
91
|
showPreExisting: boolean;
|
|
92
|
+
walkthrough: boolean;
|
|
84
93
|
}
|
|
85
94
|
export declare function runSettings(options: Pick<ReviewOptions, "limits" | "mode" | "stages">): RunSettings;
|
package/dist/pipeline/options.js
CHANGED
package/dist/pipeline/plan.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
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
|
-
import {
|
|
5
|
+
import type { SelectLearnings } from "../knowledge/select.js";
|
|
5
6
|
import { type RememberedEntry } from "../memory/memory.js";
|
|
6
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" | "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,8 +1,8 @@
|
|
|
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
|
-
import { learningSelector } from "../knowledge/select.js";
|
|
6
6
|
import { rank } from "../matrix/matrix.js";
|
|
7
7
|
import { MEMORY_PATH, mergeMemory, parseMemory } from "../memory/memory.js";
|
|
8
8
|
import { parseRepoRules, REPO_RULES_PATH, } from "../rules/repo-rules.js";
|
|
@@ -10,6 +10,8 @@ import { analyzerEvidence } from "../sarif/evidence.js";
|
|
|
10
10
|
import { binaryTextWarning, defaultSelectionPolicy, selectFiles, } from "../select/select.js";
|
|
11
11
|
import { triage } from "../triage.js";
|
|
12
12
|
import { reviewContext } from "./context.js";
|
|
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 ??
|
|
@@ -66,6 +72,8 @@ export async function planReview(options, emit, signal) {
|
|
|
66
72
|
});
|
|
67
73
|
const binaryText = binaryTextWarning(decisions);
|
|
68
74
|
const evidence = analyzerEvidence(options.sarifEvidence ?? [], bundled.bundles);
|
|
75
|
+
const context = reviewContext(vcs, diffs, options.learnings);
|
|
76
|
+
const learnings = await bundleLearnings(options.learnings ?? [], bundled.bundles, context, options.symbols);
|
|
69
77
|
return {
|
|
70
78
|
changeRequest,
|
|
71
79
|
decisions,
|
|
@@ -84,17 +92,24 @@ export async function planReview(options, emit, signal) {
|
|
|
84
92
|
: scope.note
|
|
85
93
|
? { scope: scope.note }
|
|
86
94
|
: {}),
|
|
87
|
-
context
|
|
95
|
+
context,
|
|
88
96
|
guidelines,
|
|
89
97
|
repoRules: [
|
|
90
98
|
...(options.rules ?? []),
|
|
91
99
|
...fileRules.map((rule) => ({ ...rule, source: "repository" })),
|
|
92
100
|
],
|
|
93
101
|
memory: mergeMemory(memoryText === undefined ? [] : parseMemory(memoryText), options.accountMemory ?? []),
|
|
94
|
-
learnings
|
|
102
|
+
learnings,
|
|
103
|
+
...(linked.tasks ? { linkedTasks: linked.tasks } : {}),
|
|
104
|
+
docSections: docSections(options.projectDocs ?? []),
|
|
95
105
|
evidence,
|
|
96
106
|
usage,
|
|
97
|
-
warnings: [
|
|
107
|
+
warnings: [
|
|
108
|
+
...(binaryText ? [binaryText] : []),
|
|
109
|
+
...linked.warnings,
|
|
110
|
+
...bundled.warnings,
|
|
111
|
+
...evidence.warnings,
|
|
112
|
+
],
|
|
98
113
|
};
|
|
99
114
|
}
|
|
100
115
|
async function loadRepoRules(read) {
|
package/dist/pipeline/preview.js
CHANGED
|
@@ -2,6 +2,7 @@ import { chainOf, reviewerCall } from "../agent/settings.js";
|
|
|
2
2
|
import { defaultBundlePolicy } from "../bundle/bundle.js";
|
|
3
3
|
import { planTasks } from "../matrix/matrix.js";
|
|
4
4
|
import { correctnessReviewer } from "../review/reviewers/correctness.js";
|
|
5
|
+
import { securityReviewed } from "../sarif/evidence.js";
|
|
5
6
|
import { runSettings } from "./options.js";
|
|
6
7
|
import { planReview } from "./plan.js";
|
|
7
8
|
import { taskPrompt } from "./task-prompt.js";
|
|
@@ -18,8 +19,9 @@ export async function previewReview(options) {
|
|
|
18
19
|
});
|
|
19
20
|
const { cells } = planned;
|
|
20
21
|
const plannedBundles = new Set();
|
|
22
|
+
const securityFiles = securityReviewed(cells);
|
|
21
23
|
const tasks = cells.map((cell) => {
|
|
22
|
-
const prepared = taskPrompt(cell, plan, settings.ultra);
|
|
24
|
+
const prepared = taskPrompt(cell, plan, { ultra: settings.ultra, securityFiles });
|
|
23
25
|
const task = {
|
|
24
26
|
taskId: cell.taskId,
|
|
25
27
|
reviewer: cell.reviewer.id,
|
package/dist/pipeline/run.js
CHANGED
|
@@ -5,13 +5,16 @@ 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 { mergeChecksStage } from "./merge-checks-stage.js";
|
|
8
9
|
import { runSettings } from "./options.js";
|
|
9
10
|
import { planReview } from "./plan.js";
|
|
10
11
|
import { newRunId } from "./run-id.js";
|
|
12
|
+
import { walkthroughStage } from "./walkthrough-stage.js";
|
|
11
13
|
// The library entry: plan (deterministic stages) → execute (one agent task
|
|
12
|
-
// per cell
|
|
13
|
-
//
|
|
14
|
-
// says which options are
|
|
14
|
+
// per cell, beside the walkthrough and the pre-merge checks) → filter
|
|
15
|
+
// (memory, the previous review) → check (verify, judge) → report. The `ocra`
|
|
16
|
+
// command is one caller. The manual's Embedding page says which options are
|
|
17
|
+
// a contract.
|
|
15
18
|
export function review(options) {
|
|
16
19
|
return reviewWithHooks(options);
|
|
17
20
|
}
|
|
@@ -35,10 +38,18 @@ export async function reviewWithHooks(options) {
|
|
|
35
38
|
signal,
|
|
36
39
|
emit,
|
|
37
40
|
};
|
|
41
|
+
const walkthrough = walkthroughStage(context);
|
|
42
|
+
const mergeChecks = mergeChecksStage(context);
|
|
38
43
|
const executed = await executeStage(reviewers, context);
|
|
39
44
|
const filtered = await filterStage(executed, plan.prior.review, context);
|
|
40
45
|
const checked = await checkStage(filtered, context);
|
|
41
|
-
const report = assembleReport({ runId, reviewers }, {
|
|
46
|
+
const report = assembleReport({ runId, reviewers }, {
|
|
47
|
+
executed,
|
|
48
|
+
filtered,
|
|
49
|
+
checked,
|
|
50
|
+
walkthrough: await walkthrough,
|
|
51
|
+
mergeChecks: await mergeChecks,
|
|
52
|
+
}, context);
|
|
42
53
|
emit({ type: "run_finished", report });
|
|
43
54
|
return report;
|
|
44
55
|
}
|
|
@@ -10,4 +10,8 @@ export interface TaskPrompt {
|
|
|
10
10
|
prompt: () => ReviewPrompt;
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export interface TaskSettings {
|
|
14
|
+
ultra: boolean;
|
|
15
|
+
securityFiles: ReadonlySet<string>;
|
|
16
|
+
}
|
|
17
|
+
export declare function taskPrompt(cell: MatrixCell, plan: ReviewPlan, { ultra, securityFiles }: TaskSettings): TaskPrompt;
|
|
@@ -1,16 +1,19 @@
|
|
|
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";
|
|
5
|
+
import { evidenceForReviewer } from "../sarif/evidence.js";
|
|
4
6
|
// In default mode only bundles large enough that a reviewer's 30 steps may
|
|
5
7
|
// not cover them get a plan phase; --ultra plans every task.
|
|
6
8
|
const PLAN_MIN_FILES = 5;
|
|
7
9
|
const PLAN_MIN_PATCH_CHARS = 40_000;
|
|
8
10
|
// What one task of the matrix sends: the run builds its prompt from this and
|
|
9
11
|
// --plan previews it, so the preview cannot drift from the run.
|
|
10
|
-
export function taskPrompt(cell, plan, ultra) {
|
|
12
|
+
export function taskPrompt(cell, plan, { ultra, securityFiles }) {
|
|
11
13
|
const files = cell.bundle.files.map((f) => f.newPath);
|
|
12
14
|
const learnings = plan.learnings(cell.bundle.files);
|
|
13
|
-
const
|
|
15
|
+
const docs = sectionsFor(plan.docSections, files);
|
|
16
|
+
const analyzerResults = evidenceForReviewer(plan.evidence.forBundle(cell.bundle), cell.reviewer.category, securityFiles);
|
|
14
17
|
const input = {
|
|
15
18
|
reviewer: cell.reviewer,
|
|
16
19
|
changeRequest: plan.changeRequest,
|
|
@@ -18,9 +21,13 @@ export function taskPrompt(cell, plan, ultra) {
|
|
|
18
21
|
bundle: cell.bundle.files,
|
|
19
22
|
rules: resolveRules(files, plan.repoRules, cell.reviewer.rules),
|
|
20
23
|
guidelines: plan.guidelines,
|
|
24
|
+
...(plan.linkedTasks && plan.linkedTasks.given.length > 0
|
|
25
|
+
? { linkedTasks: plan.linkedTasks.given }
|
|
26
|
+
: {}),
|
|
21
27
|
accepted: memoryFor(files, plan.memory),
|
|
22
28
|
learnings: learnings.selected,
|
|
23
29
|
moreLearnings: learnings.left,
|
|
30
|
+
...(docs.given.length > 0 ? { projectDocs: docs } : {}),
|
|
24
31
|
...(analyzerResults.length > 0 ? { analyzerResults } : {}),
|
|
25
32
|
};
|
|
26
33
|
const prompt = buildReviewPrompt(input);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Usage } from "../contracts.js";
|
|
2
|
+
import { type Walkthrough } from "../walkthrough/walkthrough.js";
|
|
3
|
+
import type { StageContext } from "./execute-stage.js";
|
|
4
|
+
export interface WalkthroughStage {
|
|
5
|
+
walkthrough?: Walkthrough;
|
|
6
|
+
usage: Usage[];
|
|
7
|
+
warnings: string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function walkthroughStage({ options, settings, plan, spendLimit, signal, }: StageContext): Promise<WalkthroughStage>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { roleCall } from "../agent/settings.js";
|
|
2
|
+
import { writeWalkthrough } from "../walkthrough/walkthrough.js";
|
|
3
|
+
// Runs beside the review tasks: it reads only the plan, and never rejects.
|
|
4
|
+
export async function walkthroughStage({ options, settings, plan, spendLimit, signal, }) {
|
|
5
|
+
if (!settings.walkthrough || !spendLimit.mayCall())
|
|
6
|
+
return { usage: [], warnings: [] };
|
|
7
|
+
const usage = [];
|
|
8
|
+
const result = await writeWalkthrough({
|
|
9
|
+
runtime: options.runtime,
|
|
10
|
+
changeRequest: plan.changeRequest,
|
|
11
|
+
files: plan.selected,
|
|
12
|
+
signal,
|
|
13
|
+
onUsage: (u) => {
|
|
14
|
+
usage.push(u);
|
|
15
|
+
spendLimit.charge(u);
|
|
16
|
+
},
|
|
17
|
+
call: roleCall("writer", options),
|
|
18
|
+
});
|
|
19
|
+
return { ...result, usage };
|
|
20
|
+
}
|
|
@@ -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,25 @@ export declare const reportOutputSchema: z.ZodObject<{
|
|
|
221
243
|
reason: z.ZodString;
|
|
222
244
|
}, z.core.$strict>>;
|
|
223
245
|
}, z.core.$strict>>;
|
|
246
|
+
walkthrough: z.ZodExactOptional<z.ZodObject<{
|
|
247
|
+
overview: z.ZodString;
|
|
248
|
+
groups: z.ZodArray<z.ZodObject<{
|
|
249
|
+
title: z.ZodString;
|
|
250
|
+
files: z.ZodArray<z.ZodString>;
|
|
251
|
+
note: z.ZodString;
|
|
252
|
+
}, z.core.$strict>>;
|
|
253
|
+
diagram: z.ZodExactOptional<z.ZodString>;
|
|
254
|
+
}, z.core.$strict>>;
|
|
255
|
+
mergeChecks: z.ZodExactOptional<z.ZodArray<z.ZodObject<{
|
|
256
|
+
id: z.ZodString;
|
|
257
|
+
instruction: z.ZodString;
|
|
258
|
+
outcome: z.ZodEnum<{
|
|
259
|
+
failed: "failed";
|
|
260
|
+
inconclusive: "inconclusive";
|
|
261
|
+
passed: "passed";
|
|
262
|
+
}>;
|
|
263
|
+
reason: z.ZodString;
|
|
264
|
+
}, z.core.$strict>>>;
|
|
224
265
|
rereview: z.ZodExactOptional<z.ZodObject<{
|
|
225
266
|
fixed: z.ZodArray<z.ZodObject<{
|
|
226
267
|
fingerprint: z.ZodString;
|
|
@@ -4,7 +4,9 @@ import { INCOMPLETE_ENDINGS, MODEL_TIERS } from "../contracts.js";
|
|
|
4
4
|
import { anchorMethodSchema, riskTierSchema, severitySchema, verdictSchema, verificationSchema, } from "../domain.js";
|
|
5
5
|
import { skipReasonSchema } from "../matrix/matrix.js";
|
|
6
6
|
import { memoryEntrySchema } from "../memory/memory.js";
|
|
7
|
+
import { MERGE_CHECK_OUTCOMES } from "../merge-checks/merge-check.js";
|
|
7
8
|
import { exclusionReasonSchema } from "../select/select.js";
|
|
9
|
+
import { TASK_TRACKERS } from "../task/linked-task.js";
|
|
8
10
|
import { taskStatusSchema } from "./report.js";
|
|
9
11
|
// The published shape of a review: `--format json` and a session's
|
|
10
12
|
// report.json. It is a contract with scripts and CI, so it carries a version
|
|
@@ -189,6 +191,20 @@ export const reportOutputSchema = z.strictObject({
|
|
|
189
191
|
bundles: z.array(z.string()),
|
|
190
192
|
}))
|
|
191
193
|
.exactOptional(),
|
|
194
|
+
projectDocs: z
|
|
195
|
+
.array(z.strictObject({ path: z.string(), heading: z.string(), bundles: z.array(z.string()) }))
|
|
196
|
+
.exactOptional(),
|
|
197
|
+
linkedTasks: z
|
|
198
|
+
.array(z.strictObject({
|
|
199
|
+
tracker: z.enum(TASK_TRACKERS),
|
|
200
|
+
key: z.string(),
|
|
201
|
+
url: z.string().exactOptional(),
|
|
202
|
+
title: z.string(),
|
|
203
|
+
state: z.enum(["open", "closed"]).exactOptional(),
|
|
204
|
+
labels: z.array(z.string()),
|
|
205
|
+
cut: z.boolean(),
|
|
206
|
+
}))
|
|
207
|
+
.exactOptional(),
|
|
192
208
|
analyzerEvidence: z
|
|
193
209
|
.array(z.strictObject({
|
|
194
210
|
tool: z.string(),
|
|
@@ -198,6 +214,21 @@ export const reportOutputSchema = z.strictObject({
|
|
|
198
214
|
}))
|
|
199
215
|
.exactOptional(),
|
|
200
216
|
judgement: judgeDecisionsSchema.exactOptional(),
|
|
217
|
+
walkthrough: z
|
|
218
|
+
.strictObject({
|
|
219
|
+
overview: z.string(),
|
|
220
|
+
groups: z.array(z.strictObject({ title: z.string(), files: z.array(z.string()), note: z.string() })),
|
|
221
|
+
diagram: z.string().exactOptional(),
|
|
222
|
+
})
|
|
223
|
+
.exactOptional(),
|
|
224
|
+
mergeChecks: z
|
|
225
|
+
.array(z.strictObject({
|
|
226
|
+
id: z.string(),
|
|
227
|
+
instruction: z.string(),
|
|
228
|
+
outcome: z.enum(MERGE_CHECK_OUTCOMES),
|
|
229
|
+
reason: z.string(),
|
|
230
|
+
}))
|
|
231
|
+
.exactOptional(),
|
|
201
232
|
rereview: z
|
|
202
233
|
.strictObject({
|
|
203
234
|
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,6 +38,16 @@ export function toReportOutput(report) {
|
|
|
32
38
|
}
|
|
33
39
|
if (report.judgement)
|
|
34
40
|
output.judgement = outputJudgement(report.judgement);
|
|
41
|
+
if (report.walkthrough)
|
|
42
|
+
output.walkthrough = outputWalkthrough(report.walkthrough);
|
|
43
|
+
if (report.mergeChecks) {
|
|
44
|
+
output.mergeChecks = report.mergeChecks.map(({ id, instruction, outcome, reason }) => ({
|
|
45
|
+
id,
|
|
46
|
+
instruction,
|
|
47
|
+
outcome,
|
|
48
|
+
reason,
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
35
51
|
if (report.anchoring)
|
|
36
52
|
output.anchoring = outputAnchoring(report.anchoring);
|
|
37
53
|
if (report.spendLimit)
|
|
@@ -50,6 +66,13 @@ export function toReportOutput(report) {
|
|
|
50
66
|
}
|
|
51
67
|
return output;
|
|
52
68
|
}
|
|
69
|
+
function outputWalkthrough(w) {
|
|
70
|
+
return {
|
|
71
|
+
overview: w.overview,
|
|
72
|
+
groups: w.groups.map((g) => ({ title: g.title, files: [...g.files], note: g.note })),
|
|
73
|
+
...(w.diagram ? { diagram: w.diagram } : {}),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
53
76
|
function outputLearning(l) {
|
|
54
77
|
return {
|
|
55
78
|
id: l.id,
|
package/dist/report/report.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
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";
|
|
4
5
|
import type { JudgeDecisions } from "../judge/judge.js";
|
|
5
6
|
import type { LearningUse } from "../knowledge/learning.js";
|
|
6
7
|
import type { SkippedCell } from "../matrix/matrix.js";
|
|
7
8
|
import type { RememberedEntry } from "../memory/memory.js";
|
|
9
|
+
import type { MergeCheckResult } from "../merge-checks/merge-check.js";
|
|
8
10
|
import type { AnalyzerEvidenceUse } from "../sarif/evidence.js";
|
|
9
11
|
import type { ExclusionReason } from "../select/select.js";
|
|
12
|
+
import type { LinkedTaskUse } from "../task/linked-task.js";
|
|
10
13
|
import type { RefutedFinding } from "../verify/verify.js";
|
|
14
|
+
import type { Walkthrough } from "../walkthrough/walkthrough.js";
|
|
11
15
|
import type { RunProvenance } from "./provenance.js";
|
|
12
16
|
export type CoverageEntry = {
|
|
13
17
|
path: string;
|
|
@@ -83,8 +87,12 @@ export interface ReviewReport {
|
|
|
83
87
|
refuted: RefutedFinding[];
|
|
84
88
|
remembered: RememberedEntry[];
|
|
85
89
|
learnings?: LearningUse[];
|
|
90
|
+
linkedTasks?: LinkedTaskUse[];
|
|
91
|
+
projectDocs?: ProjectDocUse[];
|
|
86
92
|
analyzerEvidence?: AnalyzerEvidenceUse[];
|
|
87
93
|
judgement?: JudgeDecisions;
|
|
94
|
+
walkthrough?: Walkthrough;
|
|
95
|
+
mergeChecks?: MergeCheckResult[];
|
|
88
96
|
scope?: {
|
|
89
97
|
mode: "incremental";
|
|
90
98
|
since: string;
|
|
@@ -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
|
+
}
|
package/dist/review/impact.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ interface ChangedSymbol {
|
|
|
16
16
|
path: string;
|
|
17
17
|
}
|
|
18
18
|
export declare function changedSymbols(files: readonly FileDiff[], context: ImpactContext, extractor?: SymbolExtractor): Promise<ChangedSymbol[]>;
|
|
19
|
+
export declare function changedCode(files: readonly FileDiff[], context: ImpactContext, extractor: SymbolExtractor, maxChars: number): Promise<string>;
|
|
19
20
|
export interface CallerSources {
|
|
20
21
|
symbols?: SymbolExtractor | undefined;
|
|
21
22
|
references?: ReferenceIndex | undefined;
|
package/dist/review/impact.js
CHANGED
|
@@ -60,6 +60,39 @@ export async function changedSymbols(files, context, extractor) {
|
|
|
60
60
|
})
|
|
61
61
|
.slice(0, MAX_SYMBOLS);
|
|
62
62
|
}
|
|
63
|
+
// The text of the definitions a change touches, from the new revision, for
|
|
64
|
+
// learning selection: a symbol the changed function calls on a line the
|
|
65
|
+
// patch does not show. Bounded, since a touched class can be a whole file.
|
|
66
|
+
export async function changedCode(files, context, extractor, maxChars) {
|
|
67
|
+
const parts = [];
|
|
68
|
+
let chars = 0;
|
|
69
|
+
for (const file of files) {
|
|
70
|
+
if (file.kind === "deleted" || file.isBinary || chars >= maxChars)
|
|
71
|
+
continue;
|
|
72
|
+
const content = await context.readFile(file.newPath).catch(() => undefined);
|
|
73
|
+
if (content === undefined)
|
|
74
|
+
continue;
|
|
75
|
+
const symbols = await extractor.symbols(file.newPath, content).catch(() => undefined);
|
|
76
|
+
if (!symbols)
|
|
77
|
+
continue;
|
|
78
|
+
const lines = content.split("\n");
|
|
79
|
+
const touched = new Set();
|
|
80
|
+
for (const line of touchedLines(file)) {
|
|
81
|
+
const definition = innermost(symbols.definitions, line);
|
|
82
|
+
if (definition)
|
|
83
|
+
touched.add(definition);
|
|
84
|
+
}
|
|
85
|
+
for (const d of touched) {
|
|
86
|
+
const text = lines
|
|
87
|
+
.slice(d.startLine - 1, d.endLine)
|
|
88
|
+
.join("\n")
|
|
89
|
+
.slice(0, maxChars - chars);
|
|
90
|
+
parts.push(text);
|
|
91
|
+
chars += text.length;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return parts.join("\n");
|
|
95
|
+
}
|
|
63
96
|
// Uses outside the bundle's own files: inside them the reviewer already sees
|
|
64
97
|
// the code. The reference index answers first where it knows the symbol;
|
|
65
98
|
// a use it lists whose line no longer names the symbol is from a file
|
|
@@ -2,7 +2,7 @@ declare const brand: unique symbol;
|
|
|
2
2
|
export type PromptText = string & {
|
|
3
3
|
readonly [brand]: "PromptText";
|
|
4
4
|
};
|
|
5
|
-
declare const SECTIONS: readonly ["change_request", "title", "description", "changed_files", "repository_guidelines", "review_rules", "accepted_findings", "team_learnings", "learning", "learning_index", "review_files", "file", "findings", "finding", "diff", "file_excerpt", "related_code", "callers", "analyzer_results", "review_plan", "reply"];
|
|
5
|
+
declare const SECTIONS: readonly ["change_request", "title", "description", "changed_files", "linked_tasks", "task", "body", "parent", "subtasks", "project_docs", "doc", "doc_index", "repository_guidelines", "review_rules", "accepted_findings", "team_learnings", "learning", "learning_index", "review_files", "file", "findings", "finding", "diff", "file_excerpt", "related_code", "callers", "analyzer_results", "review_plan", "reply", "thread", "question", "merge_checks", "check"];
|
|
6
6
|
export type SectionName = (typeof SECTIONS)[number];
|
|
7
7
|
export declare function data(text: string): PromptText;
|
|
8
8
|
export declare function ocraText(text: string): PromptText;
|
|
@@ -18,6 +18,14 @@ const SECTIONS = [
|
|
|
18
18
|
"title",
|
|
19
19
|
"description",
|
|
20
20
|
"changed_files",
|
|
21
|
+
"linked_tasks",
|
|
22
|
+
"task",
|
|
23
|
+
"body",
|
|
24
|
+
"parent",
|
|
25
|
+
"subtasks",
|
|
26
|
+
"project_docs",
|
|
27
|
+
"doc",
|
|
28
|
+
"doc_index",
|
|
21
29
|
"repository_guidelines",
|
|
22
30
|
"review_rules",
|
|
23
31
|
"accepted_findings",
|
|
@@ -35,6 +43,10 @@ const SECTIONS = [
|
|
|
35
43
|
"analyzer_results",
|
|
36
44
|
"review_plan",
|
|
37
45
|
"reply",
|
|
46
|
+
"thread",
|
|
47
|
+
"question",
|
|
48
|
+
"merge_checks",
|
|
49
|
+
"check",
|
|
38
50
|
];
|
|
39
51
|
// Characters a tokenizer may drop or a model may read past: whitespace,
|
|
40
52
|
// every default-ignorable code point (joiners, direction marks, variation
|
package/dist/review/prompt.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { type BundleSections } from "../docs/project-docs.js";
|
|
1
2
|
import type { ChangeRequest, FileDiff } from "../domain.js";
|
|
2
3
|
import type { Learning } from "../knowledge/learning.js";
|
|
3
4
|
import type { MemoryEntry } from "../memory/memory.js";
|
|
4
5
|
import type { AnalyzerResult } from "../sarif/evidence.js";
|
|
6
|
+
import { type LinkedTask } from "../task/linked-task.js";
|
|
5
7
|
import type { SymbolUse } from "./impact.js";
|
|
6
8
|
import { type PromptText } from "./prompt-text.js";
|
|
7
9
|
import type { ReviewerDefinition } from "./reviewer.js";
|
|
@@ -13,9 +15,11 @@ export interface ReviewPromptInput {
|
|
|
13
15
|
bundle: readonly FileDiff[];
|
|
14
16
|
rules: string;
|
|
15
17
|
guidelines?: string | undefined;
|
|
18
|
+
linkedTasks?: readonly LinkedTask[];
|
|
16
19
|
accepted?: readonly MemoryEntry[];
|
|
17
20
|
learnings?: readonly Learning[];
|
|
18
21
|
moreLearnings?: readonly Learning[];
|
|
22
|
+
projectDocs?: BundleSections;
|
|
19
23
|
callers?: readonly SymbolUse[];
|
|
20
24
|
analyzerResults?: readonly AnalyzerResult[];
|
|
21
25
|
plan?: string | undefined;
|