@open-cr-agent/core 0.20.0 → 0.22.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/model-call.js +5 -2
- package/dist/contracts.d.ts +17 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.js +31 -0
- package/dist/fix/propose.d.ts +2 -0
- package/dist/fix/propose.js +6 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2 -2
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +1 -0
- package/dist/mend/agent-lane.d.ts +26 -0
- package/dist/mend/agent-lane.js +138 -0
- package/dist/mend/checks.d.ts +11 -0
- package/dist/mend/checks.js +48 -0
- package/dist/mend/conflict.d.ts +36 -0
- package/dist/mend/conflict.js +204 -0
- package/dist/mend/outcomes.d.ts +7 -0
- package/dist/mend/outcomes.js +43 -0
- package/dist/mend/round.d.ts +25 -0
- package/dist/mend/round.js +20 -0
- package/dist/mend/workspace.d.ts +18 -0
- package/dist/mend/workspace.js +175 -0
- package/dist/pipeline/fix-finding.d.ts +3 -0
- package/dist/pipeline/fix-finding.js +6 -1
- package/dist/pipeline/mend-agent.d.ts +22 -0
- package/dist/pipeline/mend-agent.js +35 -0
- package/dist/pipeline/mend-attempt.d.ts +33 -0
- package/dist/pipeline/mend-attempt.js +103 -0
- package/dist/pipeline/mend-conflicts.d.ts +41 -0
- package/dist/pipeline/mend-conflicts.js +118 -0
- package/dist/pipeline/mend-merge.d.ts +24 -0
- package/dist/pipeline/mend-merge.js +110 -0
- package/dist/pipeline/mend.d.ts +8 -26
- package/dist/pipeline/mend.js +92 -125
- package/dist/plugin/registry.d.ts +2 -2
- package/dist/plugin/types.d.ts +1 -7
- package/dist/review/prompt-text.d.ts +1 -1
- package/dist/review/prompt-text.js +7 -0
- package/dist/runtime/failback.js +11 -3
- package/dist/runtime/text-tools.d.ts +1 -1
- package/dist/runtime/tools.d.ts +2 -1
- package/dist/runtime/tools.js +2 -0
- package/dist/vcs.d.ts +36 -0
- package/package.json +1 -1
package/dist/pipeline/mend.js
CHANGED
|
@@ -2,67 +2,26 @@ import { oneShot } from "../agent/model-call.js";
|
|
|
2
2
|
import { mapWithConcurrency } from "../agent/pool.js";
|
|
3
3
|
import { roleCall } from "../agent/settings.js";
|
|
4
4
|
import { spendLimit } from "../agent/spend-limit.js";
|
|
5
|
-
import { OcraError } from "../errors.js";
|
|
6
|
-
import { FIX_REJECTIONS } from "../fix/check.js";
|
|
5
|
+
import { errorMessage, OcraError } from "../errors.js";
|
|
7
6
|
import { headMode } from "../generate/targets.js";
|
|
8
|
-
import {
|
|
7
|
+
import { CHECK_LIMITS, checkItemId } from "../mend/checks.js";
|
|
8
|
+
import { mendScope } from "../mend/gate.js";
|
|
9
9
|
import { composePatches } from "../mend/patch.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { nextState } from "../mend/round.js";
|
|
11
|
+
import { closedAs, EMPTY_STATE, MEND_LIMITS, roundStop } from "../mend/state.js";
|
|
12
|
+
import { verifierStep } from "../mend/verify.js";
|
|
12
13
|
import { oneLine } from "../review/prompt-text.js";
|
|
13
14
|
import { reviewContext } from "./context.js";
|
|
14
|
-
import {
|
|
15
|
+
import { attempt } from "./mend-attempt.js";
|
|
16
|
+
import { changeConflicts, mergeRound } from "./mend-merge.js";
|
|
17
|
+
export { MEND_ITEM_OUTCOMES, MEND_ITEM_REASONS, MEND_LEVELS, MEND_OUTCOMES, } from "../mend/outcomes.js";
|
|
15
18
|
const CONCURRENCY = 3;
|
|
16
19
|
const SUBJECT_TITLE_CHARS = 100;
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
// deferred: not tried, or tried and not written; no attempt is counted.
|
|
23
|
-
// needs_human, gone: closed, for a person or because its code is gone.
|
|
24
|
-
export const MEND_ITEM_OUTCOMES = [
|
|
25
|
-
"fixed",
|
|
26
|
-
"proposed",
|
|
27
|
-
"rejected",
|
|
28
|
-
"deferred",
|
|
29
|
-
"needs_human",
|
|
30
|
-
"gone",
|
|
31
|
-
];
|
|
32
|
-
export const MEND_ITEM_REASONS = [
|
|
33
|
-
...new Set([
|
|
34
|
-
...FIX_REJECTIONS,
|
|
35
|
-
"not_candidate",
|
|
36
|
-
...GATE_REJECTIONS,
|
|
37
|
-
...VERIFICATION_REJECTIONS,
|
|
38
|
-
"overlap",
|
|
39
|
-
"no_room",
|
|
40
|
-
"attempts",
|
|
41
|
-
"head_moved",
|
|
42
|
-
"not_writable",
|
|
43
|
-
]),
|
|
44
|
-
];
|
|
45
|
-
export const MEND_OUTCOMES = [
|
|
46
|
-
"committed",
|
|
47
|
-
"proposed",
|
|
48
|
-
"nothing",
|
|
49
|
-
"stopped",
|
|
50
|
-
"head_moved",
|
|
51
|
-
"not_writable",
|
|
52
|
-
];
|
|
53
|
-
// A person decides these: no later round at this head answers differently.
|
|
54
|
-
const FOR_A_PERSON = new Set([
|
|
55
|
-
"not_candidate",
|
|
56
|
-
"no_parser",
|
|
57
|
-
"out_of_scope",
|
|
58
|
-
"protected",
|
|
59
|
-
"too_large",
|
|
60
|
-
"tamper",
|
|
61
|
-
]);
|
|
62
|
-
// One round of the fix loop (ADR-0078) over accepted findings: each open
|
|
63
|
-
// finding gets a patch from the fix stage's checked completion, the gate and
|
|
64
|
-
// the verifier decide what is kept, and the kept patches become one commit
|
|
65
|
-
// from the head they were made at. Nothing from the change runs.
|
|
20
|
+
// One round of the fix loop (ADR-0078) over accepted findings and, when
|
|
21
|
+
// asked, the checks that failed on the head: each open item gets a patch
|
|
22
|
+
// from its lane, the gate and the verifier decide what is kept, and the kept
|
|
23
|
+
// patches become one commit from the head they were made at. Nothing from
|
|
24
|
+
// the change runs.
|
|
66
25
|
export async function mendRound(options) {
|
|
67
26
|
const { vcs } = options;
|
|
68
27
|
const before = options.state ?? EMPTY_STATE;
|
|
@@ -86,24 +45,37 @@ export async function mendRound(options) {
|
|
|
86
45
|
const stopped = roundStop(before, options.maxCostUsd);
|
|
87
46
|
if (stopped)
|
|
88
47
|
return ended({ outcome: "stopped", stopped });
|
|
89
|
-
const
|
|
48
|
+
const conflicts = options.conflicts ? await changeConflicts(vcs, headSha, warnings) : undefined;
|
|
49
|
+
if (conflicts) {
|
|
50
|
+
const waiting = unique(options.findings)
|
|
51
|
+
.filter((f) => !closedAs(before.items[f.fingerprint]))
|
|
52
|
+
.map((f) => ({ id: f.fingerprint, outcome: "deferred", reason: "conflicts" }));
|
|
53
|
+
return mergeRound(options, conflicts, { headSha, before, warnings, waiting });
|
|
54
|
+
}
|
|
55
|
+
const checks = options.checks ? await failedChecks(vcs, headSha, warnings) : undefined;
|
|
56
|
+
const items = [
|
|
57
|
+
...unique(options.findings).map((finding) => ({ id: finding.fingerprint, finding })),
|
|
58
|
+
...(checks?.failed ?? []).map((check) => ({ id: checkItemId(check), check })),
|
|
59
|
+
];
|
|
60
|
+
const named = (item) => ("check" in item ? { check: item.check.name } : {});
|
|
90
61
|
const results = new Map();
|
|
91
62
|
const open = [];
|
|
92
|
-
for (const
|
|
93
|
-
const id =
|
|
63
|
+
for (const item of items) {
|
|
64
|
+
const { id } = item;
|
|
94
65
|
const closed = closedAs(before.items[id]);
|
|
95
66
|
if (closed) {
|
|
96
67
|
const used = before.items[id]?.closed === undefined;
|
|
97
68
|
results.set(id, { id, outcome: closed, ...(used ? { reason: "attempts" } : {}) });
|
|
98
69
|
}
|
|
99
70
|
else if (open.length < MEND_LIMITS.itemsPerRound)
|
|
100
|
-
open.push(
|
|
71
|
+
open.push(item);
|
|
101
72
|
else
|
|
102
73
|
results.set(id, { id, outcome: "deferred", reason: "no_room" });
|
|
103
74
|
}
|
|
104
|
-
const listed = () =>
|
|
105
|
-
if (open.length === 0)
|
|
106
|
-
return ended({ outcome: "nothing", items: listed() });
|
|
75
|
+
const listed = () => items.map((item) => ({ ...results.get(item.id), ...named(item) }));
|
|
76
|
+
if (open.length === 0) {
|
|
77
|
+
return ended({ outcome: checks?.pending ? "waiting" : "nothing", items: listed() });
|
|
78
|
+
}
|
|
107
79
|
const diffs = await vcs.getDiff();
|
|
108
80
|
const head = {
|
|
109
81
|
diffs,
|
|
@@ -126,10 +98,10 @@ export async function mendRound(options) {
|
|
|
126
98
|
const steps = [
|
|
127
99
|
verifierStep(ask, roleCall("verifier", options), (w) => warnings.push(w)),
|
|
128
100
|
];
|
|
129
|
-
const attempts = await mapWithConcurrency(open, CONCURRENCY, async (
|
|
101
|
+
const attempts = await mapWithConcurrency(open, CONCURRENCY, async (item) => {
|
|
130
102
|
if (!limit.mayCall())
|
|
131
103
|
return { outcome: "deferred", reason: "no_room" };
|
|
132
|
-
return attempt(
|
|
104
|
+
return attempt(item, head, steps, {
|
|
133
105
|
runtime: options.runtime,
|
|
134
106
|
syntax: options.syntax,
|
|
135
107
|
spendLimit: limit,
|
|
@@ -140,12 +112,12 @@ export async function mendRound(options) {
|
|
|
140
112
|
});
|
|
141
113
|
});
|
|
142
114
|
const patches = [];
|
|
143
|
-
open.forEach((
|
|
115
|
+
open.forEach(({ id }, i) => {
|
|
144
116
|
const tried = attempts[i];
|
|
145
117
|
if ("patch" in tried)
|
|
146
118
|
patches.push(tried.patch);
|
|
147
119
|
else
|
|
148
|
-
results.set(
|
|
120
|
+
results.set(id, { id, ...tried });
|
|
149
121
|
});
|
|
150
122
|
const composed = composePatches(patches, head.contents, MEND_LIMITS);
|
|
151
123
|
for (const { item, reason } of composed.left) {
|
|
@@ -156,7 +128,7 @@ export async function mendRound(options) {
|
|
|
156
128
|
round =
|
|
157
129
|
options.level === "propose"
|
|
158
130
|
? { outcome: "proposed" }
|
|
159
|
-
: await commit(vcs, headSha, composed.changes,
|
|
131
|
+
: await commit(vcs, headSha, composed.changes, items.filter((item) => composed.kept.includes(item.id)), diffs);
|
|
160
132
|
}
|
|
161
133
|
for (const patch of patches.filter((p) => composed.kept.includes(p.item))) {
|
|
162
134
|
const id = patch.item;
|
|
@@ -166,41 +138,31 @@ export async function mendRound(options) {
|
|
|
166
138
|
? { id, outcome: "proposed", edits: patch.hunks }
|
|
167
139
|
: { id, outcome: "deferred", reason: round.outcome });
|
|
168
140
|
}
|
|
169
|
-
|
|
141
|
+
if (round.outcome === "committed" && round.sha) {
|
|
142
|
+
await vcs
|
|
143
|
+
.note?.(roundNote(round.sha, items, results))
|
|
144
|
+
.catch((error) => warnings.push(`the round's note was not posted: ${errorMessage(error)}`));
|
|
145
|
+
}
|
|
146
|
+
return ended({ ...round, items: listed(), state: nextState(before, results.values(), spent) });
|
|
170
147
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
return refuse("stale");
|
|
188
|
-
head.contents.set(finding.file, content);
|
|
189
|
-
const patch = {
|
|
190
|
-
item: finding.fingerprint,
|
|
191
|
-
hunks: [{ path: finding.file, ...fixed.fix }],
|
|
192
|
-
};
|
|
193
|
-
const gated = await gate(patch, head.contents, head.scope, deps.syntax, MEND_LIMITS);
|
|
194
|
-
if (gated)
|
|
195
|
-
return refuse(gated);
|
|
196
|
-
for (const step of steps) {
|
|
197
|
-
if (!deps.spendLimit.mayCall())
|
|
198
|
-
return { outcome: "deferred", reason: "no_room" };
|
|
199
|
-
const refused = await step({ title: finding.title, body: finding.body, patch, heads: head.contents }, deps.signal);
|
|
200
|
-
if (refused)
|
|
201
|
-
return refuse(refused);
|
|
148
|
+
function roundNote(commitSha, items, results) {
|
|
149
|
+
const note = { commitSha, fixed: [], left: [] };
|
|
150
|
+
for (const item of items) {
|
|
151
|
+
const named = "check" in item
|
|
152
|
+
? { title: item.check.name, check: true }
|
|
153
|
+
: { title: item.finding.title, file: item.finding.file };
|
|
154
|
+
const result = results.get(item.id);
|
|
155
|
+
if (result?.outcome === "fixed")
|
|
156
|
+
note.fixed.push(named);
|
|
157
|
+
else if (result) {
|
|
158
|
+
note.left.push({
|
|
159
|
+
...named,
|
|
160
|
+
outcome: result.outcome,
|
|
161
|
+
...(result.reason ? { reason: result.reason } : {}),
|
|
162
|
+
});
|
|
163
|
+
}
|
|
202
164
|
}
|
|
203
|
-
return
|
|
165
|
+
return note;
|
|
204
166
|
}
|
|
205
167
|
async function commit(vcs, parent, changes, fixed, diffs) {
|
|
206
168
|
if (!vcs.commit)
|
|
@@ -222,41 +184,46 @@ function executable(path, diffs) {
|
|
|
222
184
|
const diff = diffs.find((d) => d.newPath === path);
|
|
223
185
|
return diff !== undefined && headMode(diff) === "100755";
|
|
224
186
|
}
|
|
225
|
-
// Titles and
|
|
226
|
-
// behind a list marker, so none can add a trailer or a
|
|
187
|
+
// Titles, paths and check names come from the change and its platform: one
|
|
188
|
+
// line each, cut, and behind a list marker, so none can add a trailer or a
|
|
189
|
+
// line of its own.
|
|
227
190
|
function commitMessage(fixed) {
|
|
228
191
|
const clean = (text) => oneLine(text).replace(/[\p{Cc}\p{Cf}\u2028\u2029]+/gu, " ");
|
|
192
|
+
const title = (text) => clean(text).slice(0, SUBJECT_TITLE_CHARS);
|
|
193
|
+
const count = (n, noun) => `${n} ${noun}${n === 1 ? "" : "s"}`;
|
|
194
|
+
const checks = fixed.filter((item) => "check" in item).length;
|
|
195
|
+
const findings = fixed.length - checks;
|
|
196
|
+
const what = [
|
|
197
|
+
...(findings > 0 ? [count(findings, "finding")] : []),
|
|
198
|
+
...(checks > 0 ? [count(checks, "failed check")] : []),
|
|
199
|
+
].join(" and ");
|
|
229
200
|
return [
|
|
230
|
-
`fix: apply ocra's fixes for ${
|
|
201
|
+
`fix: apply ocra's fixes for ${what}`,
|
|
231
202
|
"",
|
|
232
|
-
...fixed.map((
|
|
203
|
+
...fixed.map((item) => "check" in item
|
|
204
|
+
? `- check: ${title(item.check.name)}`
|
|
205
|
+
: `- ${clean(item.finding.file)}: ${title(item.finding.title)}`),
|
|
233
206
|
"",
|
|
234
207
|
"ocra ran nothing from the repository to check these edits: the change request's own checks do.",
|
|
235
208
|
].join("\n");
|
|
236
209
|
}
|
|
237
|
-
|
|
238
|
-
|
|
210
|
+
// What failed on the head, at most the checks a round reads. A platform that
|
|
211
|
+
// cannot be asked leaves the round to its findings, with a warning.
|
|
212
|
+
async function failedChecks(vcs, headSha, warnings) {
|
|
213
|
+
if (!vcs.checks) {
|
|
214
|
+
warnings.push(`the ${vcs.name} adapter reads no checks: none was worked on`);
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
const checks = await vcs.checks(headSha);
|
|
219
|
+
return { ...checks, failed: checks.failed.slice(0, CHECK_LIMITS.checks) };
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
warnings.push(`reading the change's checks failed: ${errorMessage(error)}`);
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
239
225
|
}
|
|
240
226
|
function unique(findings) {
|
|
241
227
|
const seen = new Set();
|
|
242
228
|
return findings.filter((f) => !seen.has(f.fingerprint) && seen.add(f.fingerprint));
|
|
243
229
|
}
|
|
244
|
-
// A deferred item was not tried, or its patch was not written: its attempt
|
|
245
|
-
// is not counted, so a person's push or a full round costs it nothing.
|
|
246
|
-
function nextState(before, results, spent) {
|
|
247
|
-
const items = { ...before.items };
|
|
248
|
-
for (const { id, outcome } of results.values()) {
|
|
249
|
-
const was = items[id] ?? { attempts: 0 };
|
|
250
|
-
if (outcome === "deferred" || was.closed)
|
|
251
|
-
continue;
|
|
252
|
-
const used = closedAs(was);
|
|
253
|
-
if (used)
|
|
254
|
-
items[id] = { ...was, closed: used };
|
|
255
|
-
else if (outcome === "needs_human" || outcome === "gone") {
|
|
256
|
-
items[id] = { attempts: was.attempts + 1, closed: outcome };
|
|
257
|
-
}
|
|
258
|
-
else
|
|
259
|
-
items[id] = { attempts: was.attempts + 1 };
|
|
260
|
-
}
|
|
261
|
-
return { rounds: before.rounds + 1, costUsd: before.costUsd + spent, items };
|
|
262
|
-
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { AgentRuntime } from "../contracts.js";
|
|
1
|
+
import type { AgentRuntime, ToolDefinition } from "../contracts.js";
|
|
2
2
|
import { OcraError } from "../errors.js";
|
|
3
3
|
import type { ReviewEvent } from "../report/report.js";
|
|
4
4
|
import type { ReviewerDefinition } from "../review/reviewer.js";
|
|
5
5
|
import type { RepoRule } from "../rules/repo-rules.js";
|
|
6
6
|
import type { VcsAdapter } from "../vcs.js";
|
|
7
|
-
import type { PluginSummary, RuntimeFactory, RuntimeOptions,
|
|
7
|
+
import type { PluginSummary, RuntimeFactory, RuntimeOptions, VcsFactory } from "./types.js";
|
|
8
8
|
export declare class PluginError extends OcraError {
|
|
9
9
|
constructor(message: string, options?: {
|
|
10
10
|
cause?: unknown;
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { z } from "zod";
|
|
2
|
-
import type { AgentRuntime, ModelChains,
|
|
2
|
+
import type { AgentRuntime, ModelChains, Sampling, ToolDefinition } from "../contracts.js";
|
|
3
3
|
import type { ReviewEvent } from "../report/report.js";
|
|
4
4
|
import type { ReviewerDefinition } from "../review/reviewer.js";
|
|
5
5
|
import type { RepoRule } from "../rules/repo-rules.js";
|
|
@@ -28,12 +28,6 @@ export interface ModelPrice {
|
|
|
28
28
|
}
|
|
29
29
|
export type VcsFactory = (options: unknown) => VcsAdapter;
|
|
30
30
|
export type RuntimeFactory = (options: RuntimeOptions) => AgentRuntime;
|
|
31
|
-
export interface ToolDefinition<Shape extends z.ZodRawShape = z.ZodRawShape> {
|
|
32
|
-
name: string;
|
|
33
|
-
description: string;
|
|
34
|
-
inputSchema: z.ZodObject<Shape>;
|
|
35
|
-
execute(args: z.infer<z.ZodObject<Shape>>, context: ReviewContext): Promise<string>;
|
|
36
|
-
}
|
|
37
31
|
export interface BootstrapContext<Settings = unknown> {
|
|
38
32
|
settings: Settings;
|
|
39
33
|
env: Env;
|
|
@@ -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", "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", "lines_to_replace", "replacement", "edit", "diff", "file_excerpt", "related_code", "callers", "analyzer_results", "review_plan", "reply", "thread", "question", "merge_checks", "check", "tool_result"];
|
|
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", "lines_to_replace", "replacement", "edit", "diff", "file_excerpt", "related_code", "callers", "analyzer_results", "review_plan", "reply", "thread", "question", "merge_checks", "check", "check_log", "conflict", "lines_before", "lines_after", "ancestor", "pull_request", "target", "tool_result"];
|
|
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;
|
|
@@ -50,6 +50,13 @@ const SECTIONS = [
|
|
|
50
50
|
"question",
|
|
51
51
|
"merge_checks",
|
|
52
52
|
"check",
|
|
53
|
+
"check_log",
|
|
54
|
+
"conflict",
|
|
55
|
+
"lines_before",
|
|
56
|
+
"lines_after",
|
|
57
|
+
"ancestor",
|
|
58
|
+
"pull_request",
|
|
59
|
+
"target",
|
|
53
60
|
"tool_result",
|
|
54
61
|
];
|
|
55
62
|
// Characters a tokenizer may drop or a model may read past: whitespace,
|
package/dist/runtime/failback.js
CHANGED
|
@@ -201,6 +201,7 @@ export async function completeWithFailback(options) {
|
|
|
201
201
|
const { health, signal } = options;
|
|
202
202
|
let usage = emptyUsage();
|
|
203
203
|
let lastError = "";
|
|
204
|
+
let failure = "unavailable";
|
|
204
205
|
for (const model of health.order(options.chain)) {
|
|
205
206
|
for (;;) {
|
|
206
207
|
await pauseOver(health, model, signal);
|
|
@@ -215,21 +216,28 @@ export async function completeWithFailback(options) {
|
|
|
215
216
|
return { text: outcome.text, usage };
|
|
216
217
|
}
|
|
217
218
|
if (!outcome.error.retryable) {
|
|
218
|
-
throw new CompletionError(`${model}: ${outcome.error.message}`, usage
|
|
219
|
+
throw new CompletionError(`${model}: ${outcome.error.message}`, usage, {
|
|
220
|
+
failure: "refused",
|
|
221
|
+
});
|
|
219
222
|
}
|
|
220
223
|
if (outcome.error.quota && health.recordQuota(model, outcome.error.quota) === "wait") {
|
|
221
224
|
continue;
|
|
222
225
|
}
|
|
223
226
|
if (!outcome.error.quota)
|
|
224
227
|
health.recordFailure(model);
|
|
228
|
+
failure = outcome.error.quota ? "quota" : "unavailable";
|
|
225
229
|
lastError = `${model}: ${outcome.error.message}`;
|
|
226
230
|
break;
|
|
227
231
|
}
|
|
228
232
|
}
|
|
229
233
|
if (!lastError) {
|
|
230
|
-
throw new CompletionError(`every ${chainName(options)} is out of quota for this run`, usage
|
|
234
|
+
throw new CompletionError(`every ${chainName(options)} is out of quota for this run`, usage, {
|
|
235
|
+
failure: "quota",
|
|
236
|
+
});
|
|
231
237
|
}
|
|
232
|
-
throw new CompletionError(`every ${chainName(options)} failed (${lastError})`, usage
|
|
238
|
+
throw new CompletionError(`every ${chainName(options)} failed (${lastError})`, usage, {
|
|
239
|
+
failure,
|
|
240
|
+
});
|
|
233
241
|
}
|
|
234
242
|
// Waits until the model's pause ends as it stands on waking, not as it stood
|
|
235
243
|
// on falling asleep: another task's limit may have lengthened it, and a
|
package/dist/runtime/tools.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ToolDefinition } from "../
|
|
1
|
+
import type { ToolDefinition } from "../contracts.js";
|
|
2
2
|
export declare const MAX_LINE_CHARS = 2000;
|
|
3
3
|
export declare const MAX_RESULT_CHARS = 50000;
|
|
4
|
+
export declare const readTools: readonly ToolDefinition[];
|
|
4
5
|
export declare const reviewTools: readonly ToolDefinition[];
|
package/dist/runtime/tools.js
CHANGED
|
@@ -117,6 +117,8 @@ const taskDone = {
|
|
|
117
117
|
inputSchema: z.object({}),
|
|
118
118
|
execute: async () => "Done.",
|
|
119
119
|
};
|
|
120
|
+
// What a task with its own toolset (TaskToolset) reads the change with.
|
|
121
|
+
export const readTools = [readFile, readDiff, codeSearch];
|
|
120
122
|
export const reviewTools = [
|
|
121
123
|
readFile,
|
|
122
124
|
readDiff,
|
package/dist/vcs.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ export type Mention = {
|
|
|
25
25
|
};
|
|
26
26
|
export interface ChangeCommit {
|
|
27
27
|
parent: string;
|
|
28
|
+
mergeParent?: string;
|
|
28
29
|
message: string;
|
|
29
30
|
files: readonly {
|
|
30
31
|
path: string;
|
|
@@ -41,6 +42,38 @@ export type CommitResult = {
|
|
|
41
42
|
outcome: "head_moved" | "not_writable";
|
|
42
43
|
reason: string;
|
|
43
44
|
};
|
|
45
|
+
export interface FailedCheck {
|
|
46
|
+
name: string;
|
|
47
|
+
log: string;
|
|
48
|
+
}
|
|
49
|
+
export interface ChangeChecks {
|
|
50
|
+
pending: boolean;
|
|
51
|
+
failed: FailedCheck[];
|
|
52
|
+
}
|
|
53
|
+
export interface ConflictedFile {
|
|
54
|
+
path: string;
|
|
55
|
+
merged: string;
|
|
56
|
+
markerSize: number;
|
|
57
|
+
executable: boolean;
|
|
58
|
+
}
|
|
59
|
+
export interface ChangeConflicts {
|
|
60
|
+
mergeParent: string;
|
|
61
|
+
files: ConflictedFile[];
|
|
62
|
+
other: string[];
|
|
63
|
+
}
|
|
64
|
+
export interface RoundNoteItem {
|
|
65
|
+
title: string;
|
|
66
|
+
file?: string;
|
|
67
|
+
check?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface RoundNote {
|
|
70
|
+
commitSha: string;
|
|
71
|
+
fixed: RoundNoteItem[];
|
|
72
|
+
left: (RoundNoteItem & {
|
|
73
|
+
outcome: string;
|
|
74
|
+
reason?: string;
|
|
75
|
+
})[];
|
|
76
|
+
}
|
|
44
77
|
export interface VcsAdapter {
|
|
45
78
|
readonly name: string;
|
|
46
79
|
getChangeRequest(): Promise<ChangeRequest>;
|
|
@@ -54,5 +87,8 @@ export interface VcsAdapter {
|
|
|
54
87
|
mention?(ref: MentionRef): Promise<Mention>;
|
|
55
88
|
listFiles?(dir: string): Promise<string[]>;
|
|
56
89
|
commit?(commit: ChangeCommit): Promise<CommitResult>;
|
|
90
|
+
conflicts?(headSha: string): Promise<ChangeConflicts | undefined>;
|
|
91
|
+
note?(round: RoundNote): Promise<void>;
|
|
92
|
+
checks?(headSha: string): Promise<ChangeChecks>;
|
|
57
93
|
linkedTasks?(): Promise<LinkedTask[]>;
|
|
58
94
|
}
|