@afaik-lab/weigh 0.0.0-stage → 0.6.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/.env.example +49 -0
- package/LICENSE +373 -0
- package/README.md +102 -2
- package/dist/agent.d.ts +83 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +204 -0
- package/dist/agent.js.map +1 -0
- package/dist/ceilings.d.ts +32 -0
- package/dist/ceilings.d.ts.map +1 -0
- package/dist/ceilings.js +61 -0
- package/dist/ceilings.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +530 -0
- package/dist/cli.js.map +1 -0
- package/dist/config-cli.d.ts +15 -0
- package/dist/config-cli.d.ts.map +1 -0
- package/dist/config-cli.js +132 -0
- package/dist/config-cli.js.map +1 -0
- package/dist/config.d.ts +198 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +373 -0
- package/dist/config.js.map +1 -0
- package/dist/context-cli.d.ts +35 -0
- package/dist/context-cli.d.ts.map +1 -0
- package/dist/context-cli.js +251 -0
- package/dist/context-cli.js.map +1 -0
- package/dist/context.d.ts +118 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +159 -0
- package/dist/context.js.map +1 -0
- package/dist/corrections/correction-set.d.ts +67 -0
- package/dist/corrections/correction-set.d.ts.map +1 -0
- package/dist/corrections/correction-set.js +104 -0
- package/dist/corrections/correction-set.js.map +1 -0
- package/dist/corrections/correction.d.ts +74 -0
- package/dist/corrections/correction.d.ts.map +1 -0
- package/dist/corrections/correction.js +154 -0
- package/dist/corrections/correction.js.map +1 -0
- package/dist/corrections/follow-up.d.ts +69 -0
- package/dist/corrections/follow-up.d.ts.map +1 -0
- package/dist/corrections/follow-up.js +217 -0
- package/dist/corrections/follow-up.js.map +1 -0
- package/dist/corrections/index.d.ts +31 -0
- package/dist/corrections/index.d.ts.map +1 -0
- package/dist/corrections/index.js +31 -0
- package/dist/corrections/index.js.map +1 -0
- package/dist/corrections/ledger.d.ts +78 -0
- package/dist/corrections/ledger.d.ts.map +1 -0
- package/dist/corrections/ledger.js +117 -0
- package/dist/corrections/ledger.js.map +1 -0
- package/dist/corrections/promotion.d.ts +119 -0
- package/dist/corrections/promotion.d.ts.map +1 -0
- package/dist/corrections/promotion.js +221 -0
- package/dist/corrections/promotion.js.map +1 -0
- package/dist/corrections/schema.d.ts +125 -0
- package/dist/corrections/schema.d.ts.map +1 -0
- package/dist/corrections/schema.js +100 -0
- package/dist/corrections/schema.js.map +1 -0
- package/dist/corrections-cli.d.ts +28 -0
- package/dist/corrections-cli.d.ts.map +1 -0
- package/dist/corrections-cli.js +157 -0
- package/dist/corrections-cli.js.map +1 -0
- package/dist/diff.d.ts +105 -0
- package/dist/diff.d.ts.map +1 -0
- package/dist/diff.js +202 -0
- package/dist/diff.js.map +1 -0
- package/dist/doctor.d.ts +38 -0
- package/dist/doctor.d.ts.map +1 -0
- package/dist/doctor.js +197 -0
- package/dist/doctor.js.map +1 -0
- package/dist/events.d.ts +21 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +5 -0
- package/dist/events.js.map +1 -0
- package/dist/findings.d.ts +510 -0
- package/dist/findings.d.ts.map +1 -0
- package/dist/findings.js +645 -0
- package/dist/findings.js.map +1 -0
- package/dist/follow-up-cli.d.ts +88 -0
- package/dist/follow-up-cli.d.ts.map +1 -0
- package/dist/follow-up-cli.js +208 -0
- package/dist/follow-up-cli.js.map +1 -0
- package/dist/harness.d.ts +64 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +71 -0
- package/dist/harness.js.map +1 -0
- package/dist/help/command-help.d.ts +9 -0
- package/dist/help/command-help.d.ts.map +1 -0
- package/dist/help/command-help.js +21 -0
- package/dist/help/command-help.js.map +1 -0
- package/dist/help/commands/answer.d.ts +3 -0
- package/dist/help/commands/answer.d.ts.map +1 -0
- package/dist/help/commands/answer.js +39 -0
- package/dist/help/commands/answer.js.map +1 -0
- package/dist/help/commands/config.d.ts +3 -0
- package/dist/help/commands/config.d.ts.map +1 -0
- package/dist/help/commands/config.js +25 -0
- package/dist/help/commands/config.js.map +1 -0
- package/dist/help/commands/context.d.ts +3 -0
- package/dist/help/commands/context.d.ts.map +1 -0
- package/dist/help/commands/context.js +44 -0
- package/dist/help/commands/context.js.map +1 -0
- package/dist/help/commands/corrections.d.ts +3 -0
- package/dist/help/commands/corrections.d.ts.map +1 -0
- package/dist/help/commands/corrections.js +30 -0
- package/dist/help/commands/corrections.js.map +1 -0
- package/dist/help/commands/doctor.d.ts +3 -0
- package/dist/help/commands/doctor.d.ts.map +1 -0
- package/dist/help/commands/doctor.js +12 -0
- package/dist/help/commands/doctor.js.map +1 -0
- package/dist/help/commands/index.d.ts +4 -0
- package/dist/help/commands/index.d.ts.map +1 -0
- package/dist/help/commands/index.js +27 -0
- package/dist/help/commands/index.js.map +1 -0
- package/dist/help/commands/memory.d.ts +3 -0
- package/dist/help/commands/memory.d.ts.map +1 -0
- package/dist/help/commands/memory.js +33 -0
- package/dist/help/commands/memory.js.map +1 -0
- package/dist/help/commands/models.d.ts +3 -0
- package/dist/help/commands/models.d.ts.map +1 -0
- package/dist/help/commands/models.js +17 -0
- package/dist/help/commands/models.js.map +1 -0
- package/dist/help/commands/options.d.ts +4 -0
- package/dist/help/commands/options.d.ts.map +1 -0
- package/dist/help/commands/options.js +13 -0
- package/dist/help/commands/options.js.map +1 -0
- package/dist/help/commands/review.d.ts +3 -0
- package/dist/help/commands/review.d.ts.map +1 -0
- package/dist/help/commands/review.js +50 -0
- package/dist/help/commands/review.js.map +1 -0
- package/dist/help/commands/sessions.d.ts +3 -0
- package/dist/help/commands/sessions.d.ts.map +1 -0
- package/dist/help/commands/sessions.js +23 -0
- package/dist/help/commands/sessions.js.map +1 -0
- package/dist/help/commands/show.d.ts +3 -0
- package/dist/help/commands/show.d.ts.map +1 -0
- package/dist/help/commands/show.js +18 -0
- package/dist/help/commands/show.js.map +1 -0
- package/dist/help/help.d.ts +16 -0
- package/dist/help/help.d.ts.map +1 -0
- package/dist/help/help.js +68 -0
- package/dist/help/help.js.map +1 -0
- package/dist/help/index.d.ts +4 -0
- package/dist/help/index.d.ts.map +1 -0
- package/dist/help/index.js +7 -0
- package/dist/help/index.js.map +1 -0
- package/dist/index.d.ts +80 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +51 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/block.d.ts +65 -0
- package/dist/knowledge/block.d.ts.map +1 -0
- package/dist/knowledge/block.js +89 -0
- package/dist/knowledge/block.js.map +1 -0
- package/dist/knowledge/claim.d.ts +143 -0
- package/dist/knowledge/claim.d.ts.map +1 -0
- package/dist/knowledge/claim.js +297 -0
- package/dist/knowledge/claim.js.map +1 -0
- package/dist/knowledge/index.d.ts +32 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +29 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/knowledge/novelty.d.ts +65 -0
- package/dist/knowledge/novelty.d.ts.map +1 -0
- package/dist/knowledge/novelty.js +94 -0
- package/dist/knowledge/novelty.js.map +1 -0
- package/dist/knowledge/recall.d.ts +134 -0
- package/dist/knowledge/recall.d.ts.map +1 -0
- package/dist/knowledge/recall.js +229 -0
- package/dist/knowledge/recall.js.map +1 -0
- package/dist/knowledge/recalled-claim.d.ts +35 -0
- package/dist/knowledge/recalled-claim.d.ts.map +1 -0
- package/dist/knowledge/recalled-claim.js +67 -0
- package/dist/knowledge/recalled-claim.js.map +1 -0
- package/dist/knowledge/recalled.d.ts +70 -0
- package/dist/knowledge/recalled.d.ts.map +1 -0
- package/dist/knowledge/recalled.js +149 -0
- package/dist/knowledge/recalled.js.map +1 -0
- package/dist/knowledge/schema.d.ts +83 -0
- package/dist/knowledge/schema.d.ts.map +1 -0
- package/dist/knowledge/schema.js +96 -0
- package/dist/knowledge/schema.js.map +1 -0
- package/dist/knowledge/staleness.d.ts +48 -0
- package/dist/knowledge/staleness.d.ts.map +1 -0
- package/dist/knowledge/staleness.js +85 -0
- package/dist/knowledge/staleness.js.map +1 -0
- package/dist/knowledge/store.d.ts +100 -0
- package/dist/knowledge/store.d.ts.map +1 -0
- package/dist/knowledge/store.js +184 -0
- package/dist/knowledge/store.js.map +1 -0
- package/dist/memory/compose-file.d.ts +14 -0
- package/dist/memory/compose-file.d.ts.map +1 -0
- package/dist/memory/compose-file.js +25 -0
- package/dist/memory/compose-file.js.map +1 -0
- package/dist/memory/index.d.ts +43 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +119 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/oss.d.ts +62 -0
- package/dist/memory/oss.d.ts.map +1 -0
- package/dist/memory/oss.js +230 -0
- package/dist/memory/oss.js.map +1 -0
- package/dist/memory/platform.d.ts +37 -0
- package/dist/memory/platform.d.ts.map +1 -0
- package/dist/memory/platform.js +131 -0
- package/dist/memory/platform.js.map +1 -0
- package/dist/memory/scope.d.ts +49 -0
- package/dist/memory/scope.d.ts.map +1 -0
- package/dist/memory/scope.js +70 -0
- package/dist/memory/scope.js.map +1 -0
- package/dist/memory/types.d.ts +113 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +18 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/memory-cli.d.ts +17 -0
- package/dist/memory-cli.d.ts.map +1 -0
- package/dist/memory-cli.js +107 -0
- package/dist/memory-cli.js.map +1 -0
- package/dist/models-cli.d.ts +12 -0
- package/dist/models-cli.d.ts.map +1 -0
- package/dist/models-cli.js +54 -0
- package/dist/models-cli.js.map +1 -0
- package/dist/models.d.ts +111 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +227 -0
- package/dist/models.js.map +1 -0
- package/dist/paths.d.ts +35 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +65 -0
- package/dist/paths.js.map +1 -0
- package/dist/profile.d.ts +28 -0
- package/dist/profile.d.ts.map +1 -0
- package/dist/profile.js +154 -0
- package/dist/profile.js.map +1 -0
- package/dist/progress.d.ts +70 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +132 -0
- package/dist/progress.js.map +1 -0
- package/dist/quiet.d.ts +2 -0
- package/dist/quiet.d.ts.map +1 -0
- package/dist/quiet.js +21 -0
- package/dist/quiet.js.map +1 -0
- package/dist/reconcile/continuation.d.ts +132 -0
- package/dist/reconcile/continuation.d.ts.map +1 -0
- package/dist/reconcile/continuation.js +306 -0
- package/dist/reconcile/continuation.js.map +1 -0
- package/dist/reconcile/index.d.ts +26 -0
- package/dist/reconcile/index.d.ts.map +1 -0
- package/dist/reconcile/index.js +28 -0
- package/dist/reconcile/index.js.map +1 -0
- package/dist/reconcile/outcome-set.d.ts +53 -0
- package/dist/reconcile/outcome-set.d.ts.map +1 -0
- package/dist/reconcile/outcome-set.js +124 -0
- package/dist/reconcile/outcome-set.js.map +1 -0
- package/dist/reconcile/outcome.d.ts +56 -0
- package/dist/reconcile/outcome.d.ts.map +1 -0
- package/dist/reconcile/outcome.js +60 -0
- package/dist/reconcile/outcome.js.map +1 -0
- package/dist/reconcile/reconciliation.d.ts +49 -0
- package/dist/reconcile/reconciliation.d.ts.map +1 -0
- package/dist/reconcile/reconciliation.js +88 -0
- package/dist/reconcile/reconciliation.js.map +1 -0
- package/dist/reconcile/schema.d.ts +157 -0
- package/dist/reconcile/schema.d.ts.map +1 -0
- package/dist/reconcile/schema.js +97 -0
- package/dist/reconcile/schema.js.map +1 -0
- package/dist/record/index.d.ts +23 -0
- package/dist/record/index.d.ts.map +1 -0
- package/dist/record/index.js +25 -0
- package/dist/record/index.js.map +1 -0
- package/dist/record/review-record.d.ts +28 -0
- package/dist/record/review-record.d.ts.map +1 -0
- package/dist/record/review-record.js +78 -0
- package/dist/record/review-record.js.map +1 -0
- package/dist/record/schema.d.ts +153 -0
- package/dist/record/schema.d.ts.map +1 -0
- package/dist/record/schema.js +87 -0
- package/dist/record/schema.js.map +1 -0
- package/dist/record/store.d.ts +83 -0
- package/dist/record/store.d.ts.map +1 -0
- package/dist/record/store.js +162 -0
- package/dist/record/store.js.map +1 -0
- package/dist/record/stored-review.d.ts +36 -0
- package/dist/record/stored-review.d.ts.map +1 -0
- package/dist/record/stored-review.js +90 -0
- package/dist/record/stored-review.js.map +1 -0
- package/dist/refute.d.ts +318 -0
- package/dist/refute.d.ts.map +1 -0
- package/dist/refute.js +513 -0
- package/dist/refute.js.map +1 -0
- package/dist/render.d.ts +212 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +544 -0
- package/dist/render.js.map +1 -0
- package/dist/review-cli.d.ts +181 -0
- package/dist/review-cli.d.ts.map +1 -0
- package/dist/review-cli.js +598 -0
- package/dist/review-cli.js.map +1 -0
- package/dist/reviewer.d.ts +297 -0
- package/dist/reviewer.d.ts.map +1 -0
- package/dist/reviewer.js +580 -0
- package/dist/reviewer.js.map +1 -0
- package/dist/session-cli.d.ts +17 -0
- package/dist/session-cli.d.ts.map +1 -0
- package/dist/session-cli.js +62 -0
- package/dist/session-cli.js.map +1 -0
- package/dist/session.d.ts +36 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +105 -0
- package/dist/session.js.map +1 -0
- package/dist/settings.d.ts +68 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +175 -0
- package/dist/settings.js.map +1 -0
- package/dist/show-cli.d.ts +39 -0
- package/dist/show-cli.d.ts.map +1 -0
- package/dist/show-cli.js +56 -0
- package/dist/show-cli.js.map +1 -0
- package/dist/stdout.d.ts +28 -0
- package/dist/stdout.d.ts.map +1 -0
- package/dist/stdout.js +44 -0
- package/dist/stdout.js.map +1 -0
- package/dist/target.d.ts +58 -0
- package/dist/target.d.ts.map +1 -0
- package/dist/target.js +96 -0
- package/dist/target.js.map +1 -0
- package/dist/tools/index.d.ts +93 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +146 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/root.d.ts +62 -0
- package/dist/tools/root.d.ts.map +1 -0
- package/dist/tools/root.js +51 -0
- package/dist/tools/root.js.map +1 -0
- package/dist/usage.d.ts +75 -0
- package/dist/usage.d.ts.map +1 -0
- package/dist/usage.js +100 -0
- package/dist/usage.js.map +1 -0
- package/dist/version.d.ts +14 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +26 -0
- package/dist/version.js.map +1 -0
- package/dist/workspace.d.ts +48 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +126 -0
- package/dist/workspace.js.map +1 -0
- package/docker-compose.yml +61 -0
- package/package.json +70 -4
package/dist/reviewer.js
ADDED
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4
|
+
import { query } from '@anthropic-ai/claude-agent-sdk';
|
|
5
|
+
import { looksGenerated, renderContext } from './context.js';
|
|
6
|
+
import { refreshCatalogue } from './models.js';
|
|
7
|
+
import { FindingSet, Verdict, WorkspaceFiles, reviewOutputSchema, strictJsonSchema, } from './findings.js';
|
|
8
|
+
import { harnessOptions } from './harness.js';
|
|
9
|
+
import { Ceilings } from './ceilings.js';
|
|
10
|
+
import { Spend } from './usage.js';
|
|
11
|
+
import { OutcomeSet, continuationOutputSchema, } from './reconcile/index.js';
|
|
12
|
+
import { CorrectionSet } from './corrections/index.js';
|
|
13
|
+
/**
|
|
14
|
+
* Which changed files the reviewer actually opened.
|
|
15
|
+
*
|
|
16
|
+
* One loop reading what it chooses is cheaper and reasons across files, but it
|
|
17
|
+
* gives up the guarantee that every changed file was looked at. This is the
|
|
18
|
+
* accounting taken in exchange: a number printed beside the review, rather than
|
|
19
|
+
* a promise nobody can check. A run that read four of forty files and said
|
|
20
|
+
* nothing is not a clean review, and without this it would read like one.
|
|
21
|
+
*/
|
|
22
|
+
export class CoverageLedger {
|
|
23
|
+
_sinceLastReview;
|
|
24
|
+
_changed;
|
|
25
|
+
_opened = new Set();
|
|
26
|
+
/**
|
|
27
|
+
* `sinceLastReview` says the changed files are those since the last review,
|
|
28
|
+
* not the whole branch. Said in the line rather than left implied: "3 of 3"
|
|
29
|
+
* on a fifty-file branch reads as a thorough review of all of it.
|
|
30
|
+
*/
|
|
31
|
+
constructor(changed, _sinceLastReview = false) {
|
|
32
|
+
this._sinceLastReview = _sinceLastReview;
|
|
33
|
+
this._changed = new Set(changed);
|
|
34
|
+
}
|
|
35
|
+
/** Records a path the reviewer asked for. Paths it invented are ignored. */
|
|
36
|
+
record(path) {
|
|
37
|
+
if (!path)
|
|
38
|
+
return;
|
|
39
|
+
const normalised = path.replace(/^\.\//, '');
|
|
40
|
+
if (this._changed.has(normalised))
|
|
41
|
+
this._opened.add(normalised);
|
|
42
|
+
}
|
|
43
|
+
get opened() {
|
|
44
|
+
return [...this._opened].sort();
|
|
45
|
+
}
|
|
46
|
+
get unopened() {
|
|
47
|
+
return [...this._changed].filter((p) => !this._opened.has(p)).sort();
|
|
48
|
+
}
|
|
49
|
+
get changedCount() {
|
|
50
|
+
return this._changed.size;
|
|
51
|
+
}
|
|
52
|
+
/** Nothing changed is full coverage, not a division by zero. */
|
|
53
|
+
get ratio() {
|
|
54
|
+
return this._changed.size === 0 ? 1 : this._opened.size / this._changed.size;
|
|
55
|
+
}
|
|
56
|
+
describe() {
|
|
57
|
+
if (this._changed.size === 0)
|
|
58
|
+
return 'no changed files';
|
|
59
|
+
const unopened = this.unopened;
|
|
60
|
+
const files = this._sinceLastReview ? 'files changed since the last review' : 'changed files';
|
|
61
|
+
const head = `read ${this._opened.size} of ${this._changed.size} ${files}`;
|
|
62
|
+
return unopened.length === 0 ? head : `${head} · unread: ${unopened.join(', ')}`;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* What the reviewer is held to, as opposed to what it was shown.
|
|
67
|
+
*
|
|
68
|
+
* A deleted file has nothing to open, a binary has nothing to read, and a
|
|
69
|
+
* lockfile is not what anyone means by "did you look at the change". Holding a
|
|
70
|
+
* run to those would send it back to fetch files that cannot inform it, and
|
|
71
|
+
* the nudge would name paths it is bound to fail on.
|
|
72
|
+
*
|
|
73
|
+
* Reported coverage still counts every changed file — that number is meant to
|
|
74
|
+
* be honest about the diff, not flattering about the run.
|
|
75
|
+
*/
|
|
76
|
+
export function readableFiles(files) {
|
|
77
|
+
return files.filter((f) => f.status !== 'deleted' && !f.binary && !looksGenerated(f.path)).map((f) => f.path);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Sends a review back when it reports on code it never opened.
|
|
81
|
+
*
|
|
82
|
+
* `hasToolCall('report_review')` used to make reporting the end of a review,
|
|
83
|
+
* and nothing in the Agent SDK replaces it: the model fills in the schema
|
|
84
|
+
* whenever it feels ready, and measured runs did so after four reads of a
|
|
85
|
+
* fifty-five file diff. A ceiling stops a run that reads too much; this is the
|
|
86
|
+
* floor that catches one that reads too little.
|
|
87
|
+
*
|
|
88
|
+
* It nudges rather than enforces. The floor is not reached by insisting — a
|
|
89
|
+
* run that has been sent back twice and is still short gets to report anyway,
|
|
90
|
+
* with its coverage stated beside the findings. The alternative is a review
|
|
91
|
+
* that never returns, which is worse than a shallow one that admits it.
|
|
92
|
+
*/
|
|
93
|
+
export class CoverageGate {
|
|
94
|
+
_ledger;
|
|
95
|
+
_expected;
|
|
96
|
+
_floor;
|
|
97
|
+
_maxNudges;
|
|
98
|
+
_onEvent;
|
|
99
|
+
_nudges = 0;
|
|
100
|
+
constructor(_ledger,
|
|
101
|
+
/** The files a run can fairly be held to. */
|
|
102
|
+
_expected, _floor,
|
|
103
|
+
/**
|
|
104
|
+
* Two, and fixed. Each nudge costs a round of reading, and a model that
|
|
105
|
+
* ignored the first two is not going to yield to a third — it is going to
|
|
106
|
+
* spend the budget that should have paid for the review.
|
|
107
|
+
*/
|
|
108
|
+
_maxNudges = 2, _onEvent) {
|
|
109
|
+
this._ledger = _ledger;
|
|
110
|
+
this._expected = _expected;
|
|
111
|
+
this._floor = _floor;
|
|
112
|
+
this._maxNudges = _maxNudges;
|
|
113
|
+
this._onEvent = _onEvent;
|
|
114
|
+
}
|
|
115
|
+
/** How many times the run was sent back. Reported beside the coverage. */
|
|
116
|
+
get nudges() {
|
|
117
|
+
return this._nudges;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The files still unopened, or undefined when the run may finish.
|
|
121
|
+
*
|
|
122
|
+
* Nothing to be held to, no floor asked for, or already sent back as often
|
|
123
|
+
* as it is worth. `stop_hook_active` is deliberately not the guard: it says
|
|
124
|
+
* only that some stop hook is mid-retry, which cannot express "twice".
|
|
125
|
+
*/
|
|
126
|
+
_shortfall() {
|
|
127
|
+
if (this._floor <= 0 || this._expected.length === 0 || this._nudges >= this._maxNudges)
|
|
128
|
+
return undefined;
|
|
129
|
+
const opened = new Set(this._ledger.opened);
|
|
130
|
+
const unread = this._expected.filter((path) => !opened.has(path));
|
|
131
|
+
const read = this._expected.length - unread.length;
|
|
132
|
+
if (read / this._expected.length >= this._floor)
|
|
133
|
+
return undefined;
|
|
134
|
+
return { read, unread };
|
|
135
|
+
}
|
|
136
|
+
_nudge(short) {
|
|
137
|
+
this._nudges++;
|
|
138
|
+
this._onEvent?.({ type: 'coverage_nudge', read: short.read, expected: this._expected.length });
|
|
139
|
+
return this._reason(short.read, short.unread);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Bound for `options.hooks.PreToolUse`, matched to the report tool.
|
|
143
|
+
*
|
|
144
|
+
* This is the half that works, and the reason both halves exist. With
|
|
145
|
+
* `outputFormat` set, submitting the review is an *end-turn* tool call: the
|
|
146
|
+
* turn is over the moment it succeeds. Measured — a Stop hook fires and
|
|
147
|
+
* blocks, and the run ends one second later anyway, because by then the
|
|
148
|
+
* output has committed and there is no turn left to send back. Refusing the
|
|
149
|
+
* call is early enough; blocking the stop is not.
|
|
150
|
+
*/
|
|
151
|
+
report = async (input) => {
|
|
152
|
+
const pre = input;
|
|
153
|
+
if (pre.hook_event_name !== 'PreToolUse')
|
|
154
|
+
return {};
|
|
155
|
+
const short = this._shortfall();
|
|
156
|
+
if (!short)
|
|
157
|
+
return {};
|
|
158
|
+
return {
|
|
159
|
+
hookSpecificOutput: {
|
|
160
|
+
hookEventName: 'PreToolUse',
|
|
161
|
+
permissionDecision: 'deny',
|
|
162
|
+
permissionDecisionReason: this._nudge(short),
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Bound for `options.hooks.Stop`.
|
|
168
|
+
*
|
|
169
|
+
* Kept for the exit the tool hook cannot see: a run that stops without
|
|
170
|
+
* submitting a review at all, having written its findings as prose. That
|
|
171
|
+
* turn has not ended on a tool, so blocking it still has somewhere to go.
|
|
172
|
+
*/
|
|
173
|
+
stop = async (input) => {
|
|
174
|
+
const stop = input;
|
|
175
|
+
if (stop.hook_event_name !== 'Stop')
|
|
176
|
+
return {};
|
|
177
|
+
const short = this._shortfall();
|
|
178
|
+
if (!short)
|
|
179
|
+
return {};
|
|
180
|
+
return { decision: 'block', reason: this._nudge(short) };
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* Why it is going back, and what would satisfy it.
|
|
184
|
+
*
|
|
185
|
+
* The last two sentences are load-bearing. Told only that it has not read
|
|
186
|
+
* enough, a model reads more and then justifies the trip with findings it
|
|
187
|
+
* would not otherwise have written — which converts a coverage problem into
|
|
188
|
+
* a false-positive problem, and the second is harder to notice.
|
|
189
|
+
*/
|
|
190
|
+
_reason(read, unread) {
|
|
191
|
+
const shown = unread.slice(0, 12);
|
|
192
|
+
const rest = unread.length - shown.length;
|
|
193
|
+
// A second nudge that reads identically to the first is a message the
|
|
194
|
+
// model has already declined to act on. Say that it is the second, and
|
|
195
|
+
// that it is the last — the wording is the only lever left.
|
|
196
|
+
const again = this._nudges > 1
|
|
197
|
+
? [
|
|
198
|
+
'You were asked this once already and reported again without reading. This is the',
|
|
199
|
+
'last time you will be sent back; the next report is accepted whatever it rests on.',
|
|
200
|
+
'',
|
|
201
|
+
]
|
|
202
|
+
: [];
|
|
203
|
+
return [
|
|
204
|
+
`You have opened ${read} of ${this._expected.length} changed files. A review that reports`,
|
|
205
|
+
'on code it has not read is a guess wearing the clothes of a judgement.',
|
|
206
|
+
'',
|
|
207
|
+
...again,
|
|
208
|
+
'',
|
|
209
|
+
'Open these with Read before reporting — a grep over a directory does not count,',
|
|
210
|
+
'because matching lines are not the code around them:',
|
|
211
|
+
...shown.map((path) => ` ${path}`),
|
|
212
|
+
...(rest > 0 ? [` …and ${rest} more`] : []),
|
|
213
|
+
'',
|
|
214
|
+
'Then submit the review. If they turn out to be correct, say nothing about them —',
|
|
215
|
+
'an empty review is a good review when the change is sound. Do not write findings',
|
|
216
|
+
'to justify the extra reading.',
|
|
217
|
+
].join('\n');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Reads a review out of whatever text is left when the structured channel
|
|
222
|
+
* produced nothing.
|
|
223
|
+
*
|
|
224
|
+
* It used to be the main path, back when the schema was a request a provider
|
|
225
|
+
* could decline. It is not any more — `outputFormat` returns the review as a
|
|
226
|
+
* parsed object, and a measured run wrote zero characters outside it. What
|
|
227
|
+
* keeps this here is the run that ends early: hit the turn ceiling or the
|
|
228
|
+
* budget and there is no structured output, only the prose the model had
|
|
229
|
+
* written by then. Recovering a review from that beats discarding one that was
|
|
230
|
+
* actually carried out.
|
|
231
|
+
*/
|
|
232
|
+
export class ReviewOutputParser {
|
|
233
|
+
parse(text) {
|
|
234
|
+
const data = this._extractJson(text);
|
|
235
|
+
if (data === undefined) {
|
|
236
|
+
throw new Error(`The model did not return a review. Expected JSON matching the review schema, got ${text.length ? `${text.length} characters starting "${text.slice(0, 80)}"` : 'nothing'}.`);
|
|
237
|
+
}
|
|
238
|
+
const parsed = reviewOutputSchema.safeParse(data);
|
|
239
|
+
if (!parsed.success) {
|
|
240
|
+
const issue = parsed.error.issues[0];
|
|
241
|
+
throw new Error(`The model's review did not match the schema: ${issue?.message}${issue?.path.length ? ` at ${issue.path.join('.')}` : ''}`);
|
|
242
|
+
}
|
|
243
|
+
return parsed.data;
|
|
244
|
+
}
|
|
245
|
+
/** The whole string, a fenced block, or the widest brace-delimited span. */
|
|
246
|
+
_extractJson(text) {
|
|
247
|
+
const candidates = [text.trim()];
|
|
248
|
+
const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/);
|
|
249
|
+
if (fenced?.[1])
|
|
250
|
+
candidates.push(fenced[1].trim());
|
|
251
|
+
const first = text.indexOf('{');
|
|
252
|
+
const last = text.lastIndexOf('}');
|
|
253
|
+
if (first !== -1 && last > first)
|
|
254
|
+
candidates.push(text.slice(first, last + 1));
|
|
255
|
+
for (const candidate of candidates) {
|
|
256
|
+
if (!candidate)
|
|
257
|
+
continue;
|
|
258
|
+
try {
|
|
259
|
+
return JSON.parse(candidate);
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Runs one review.
|
|
270
|
+
*
|
|
271
|
+
* A single model call over the assembled context, with the read-only tools and
|
|
272
|
+
* hard ceilings on steps and spend. The model decides what to open; the
|
|
273
|
+
* pipeline decides what it is looking at, what it may touch, and when to stop.
|
|
274
|
+
*/
|
|
275
|
+
export class Reviewer {
|
|
276
|
+
_config;
|
|
277
|
+
constructor(_config) {
|
|
278
|
+
this._config = _config;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The reviewer's standing instructions.
|
|
282
|
+
*
|
|
283
|
+
* Separate from the context so the two can be tuned independently: this says
|
|
284
|
+
* how to review, the context says what is being reviewed. Both are prompt,
|
|
285
|
+
* and this phase is where their wording actually decides quality.
|
|
286
|
+
*/
|
|
287
|
+
_instructions(context, options = {}) {
|
|
288
|
+
return [
|
|
289
|
+
'You are reviewing a specific set of changes in a repository you have read-only access to.',
|
|
290
|
+
'',
|
|
291
|
+
'Your job is to find defects a careful colleague would catch, and to say nothing otherwise.',
|
|
292
|
+
'An empty review is a good review when the change is sound — reviewers who always find',
|
|
293
|
+
'something train people to stop reading.',
|
|
294
|
+
'',
|
|
295
|
+
'Method:',
|
|
296
|
+
'- The diff tells you what changed. It does not tell you whether it is correct.',
|
|
297
|
+
' Open the surrounding code: the definition being called, the callers of what changed,',
|
|
298
|
+
' the tests that cover it.',
|
|
299
|
+
'- Judge the change against this repository as it is, not against a style you prefer.',
|
|
300
|
+
' The conventions above were read from the repository itself.',
|
|
301
|
+
'- Every finding must cite the code it rests on, by path and line, quoted exactly.',
|
|
302
|
+
' A claim you cannot cite is a claim you have not checked.',
|
|
303
|
+
'- Report what is wrong, not what is missing from your understanding. If you could not',
|
|
304
|
+
' read something you needed, say so in the summary rather than guessing.',
|
|
305
|
+
'',
|
|
306
|
+
'Severity means consequence, not effort:',
|
|
307
|
+
'- critical: data loss, a security hole, or a break in production.',
|
|
308
|
+
'- high: wrong behaviour a user or caller will hit.',
|
|
309
|
+
'- medium: wrong behaviour under conditions that are plausible but not routine.',
|
|
310
|
+
'- low: correct today, fragile tomorrow.',
|
|
311
|
+
'- nit: readability and consistency. Use sparingly; these are the findings people resent.',
|
|
312
|
+
'',
|
|
313
|
+
'Confidence is your own estimate that the finding is real and that you have understood',
|
|
314
|
+
'the code correctly. Below 0.5, you are guessing — investigate further or drop it.',
|
|
315
|
+
'',
|
|
316
|
+
'Finish with a recommendation on the change as a whole:',
|
|
317
|
+
'- block: something here will break, lose data, or open a hole. Do not merge as it stands.',
|
|
318
|
+
'- needs_work: wrong behaviour worth fixing before merge, none of it dangerous.',
|
|
319
|
+
'- approve: nothing to fix, or only low and nit findings. Code that is correct today does',
|
|
320
|
+
' not hold a change back; report those findings and approve.',
|
|
321
|
+
'Judge the change, not the count — a handful of low findings is an approve, and one critical',
|
|
322
|
+
'is a block however small the diff. If several low findings together amount to wrong',
|
|
323
|
+
'behaviour, say so by rating that finding medium, not by withholding the approval.',
|
|
324
|
+
'',
|
|
325
|
+
'Open the summary with the thing that matters most. Someone who reads one sentence and',
|
|
326
|
+
'stops should still know what it is.',
|
|
327
|
+
'',
|
|
328
|
+
'When you have finished investigating, fill in the review schema: every finding, plus a',
|
|
329
|
+
'short summary. That schema is the only way a review is returned — there is nothing to',
|
|
330
|
+
'call and no prose version. No findings is an empty list, not silence.',
|
|
331
|
+
'',
|
|
332
|
+
`Repository root: ${context.repo.root}`,
|
|
333
|
+
'Paths you pass to tools are relative to that root.',
|
|
334
|
+
// Appended rather than interleaved: the standing instructions are what a
|
|
335
|
+
// review is, and these are each one more thing to do within it. What is
|
|
336
|
+
// remembered comes first because it changes how the whole change is
|
|
337
|
+
// read; continuing a review is a task on top of that.
|
|
338
|
+
...(options.knowledge && !options.knowledge.isEmpty ? [options.knowledge.instructions()] : []),
|
|
339
|
+
// Empty for a continuation with nothing to rule on that was shown the
|
|
340
|
+
// whole branch: that is a fresh review, and adds nothing to say.
|
|
341
|
+
...[options.continuation?.instructions(context)].filter((text) => Boolean(text)),
|
|
342
|
+
].join('\n');
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* The message the review arrives in.
|
|
346
|
+
*
|
|
347
|
+
* What is remembered, then the change, then the findings being ruled on. All
|
|
348
|
+
* three are material to read rather than instructions about how to read it,
|
|
349
|
+
* which is why they are one message and not three — and the claims lead
|
|
350
|
+
* because a judgement is formed in the order it is given.
|
|
351
|
+
*/
|
|
352
|
+
_prompt(context, options) {
|
|
353
|
+
return [options.knowledge?.render(), renderContext(context), options.continuation?.render(context)]
|
|
354
|
+
.filter(Boolean)
|
|
355
|
+
.join('\n\n');
|
|
356
|
+
}
|
|
357
|
+
async review(context, options = {}) {
|
|
358
|
+
const startedAt = Date.now();
|
|
359
|
+
const model = options.model ?? this._config.model;
|
|
360
|
+
const coverage = new CoverageLedger(context.files.map((f) => f.path), Boolean(context.since));
|
|
361
|
+
const gate = new CoverageGate(coverage, readableFiles(context.files), this._config.coverageFloor, 2, options.onEvent);
|
|
362
|
+
const controller = new AbortController();
|
|
363
|
+
const onAbort = () => controller.abort();
|
|
364
|
+
options.signal?.addEventListener('abort', onAbort);
|
|
365
|
+
if (options.signal?.aborted)
|
|
366
|
+
controller.abort();
|
|
367
|
+
let result;
|
|
368
|
+
let text = '';
|
|
369
|
+
/**
|
|
370
|
+
* Usage as it accrues, keyed by message id.
|
|
371
|
+
*
|
|
372
|
+
* The result message carries the authoritative totals, and a run that hits
|
|
373
|
+
* a ceiling never produces one — the iterator throws instead. Keeping a
|
|
374
|
+
* running tally is what lets a truncated review still report what it
|
|
375
|
+
* spent. Keyed rather than summed because a streamed assistant message is
|
|
376
|
+
* re-sent as it grows, and adding each arrival would count it twice.
|
|
377
|
+
*/
|
|
378
|
+
const spent = new Map();
|
|
379
|
+
let ceiling;
|
|
380
|
+
const continuation = options.continuation;
|
|
381
|
+
const run = query({
|
|
382
|
+
prompt: this._prompt(context, options),
|
|
383
|
+
options: {
|
|
384
|
+
...harnessOptions({
|
|
385
|
+
root: context.repo.root,
|
|
386
|
+
instructions: this._instructions(context, options),
|
|
387
|
+
model,
|
|
388
|
+
effort: options.effort ?? this._config.effort,
|
|
389
|
+
maxSteps: this._config.maxSteps,
|
|
390
|
+
maxCost: this._config.maxCost,
|
|
391
|
+
hooks: {
|
|
392
|
+
recorder: coverage,
|
|
393
|
+
...(options.onEvent && {
|
|
394
|
+
onCall: (name, detail) => options.onEvent({ type: 'tool_call', name, ...(detail && { detail }) }),
|
|
395
|
+
}),
|
|
396
|
+
},
|
|
397
|
+
onStop: gate.stop,
|
|
398
|
+
onReport: gate.report,
|
|
399
|
+
}),
|
|
400
|
+
// The review comes back as a parsed object rather than as prose to
|
|
401
|
+
// be mined for one. The same schema the findings model defines, so
|
|
402
|
+
// there is no second description of a finding to drift from it — and
|
|
403
|
+
// when the run is a continuation, that schema with somewhere to put a
|
|
404
|
+
// ruling on each finding it was handed.
|
|
405
|
+
outputFormat: {
|
|
406
|
+
type: 'json_schema',
|
|
407
|
+
schema: strictJsonSchema(continuation?.rulesOn ? continuationOutputSchema : reviewOutputSchema),
|
|
408
|
+
},
|
|
409
|
+
abortController: controller,
|
|
410
|
+
},
|
|
411
|
+
});
|
|
412
|
+
// Costs nothing: the answer is ready before the stream is consumed, and
|
|
413
|
+
// this subprocess exists either way. It is what keeps `-m opus` pointing
|
|
414
|
+
// at the current Opus rather than the one this code was written against.
|
|
415
|
+
refreshCatalogue(run);
|
|
416
|
+
try {
|
|
417
|
+
for await (const message of run) {
|
|
418
|
+
if (message.type === 'assistant') {
|
|
419
|
+
for (const block of message.message.content) {
|
|
420
|
+
if (block.type === 'text')
|
|
421
|
+
text += block.text;
|
|
422
|
+
}
|
|
423
|
+
const usage = message.message.usage;
|
|
424
|
+
if (usage) {
|
|
425
|
+
spent.set(message.message.id, {
|
|
426
|
+
input: usage.input_tokens ?? 0,
|
|
427
|
+
output: usage.output_tokens ?? 0,
|
|
428
|
+
cacheRead: usage.cache_read_input_tokens ?? 0,
|
|
429
|
+
cacheWrite: usage.cache_creation_input_tokens ?? 0,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
else if (message.type === 'result') {
|
|
434
|
+
result = message;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
catch (err) {
|
|
439
|
+
// A ceiling is an outcome, not a failure: the run did the work, it just
|
|
440
|
+
// ran out of room. Anything else — no credentials, a broken workspace —
|
|
441
|
+
// is a failure, and dressing one up as an empty review would hide it.
|
|
442
|
+
ceiling = this._ceilings.fromError(err);
|
|
443
|
+
if (!ceiling)
|
|
444
|
+
throw err;
|
|
445
|
+
}
|
|
446
|
+
finally {
|
|
447
|
+
options.signal?.removeEventListener('abort', onAbort);
|
|
448
|
+
}
|
|
449
|
+
if (!result && !ceiling) {
|
|
450
|
+
throw new Error('The review ended without a result. This is a bug in the harness.');
|
|
451
|
+
}
|
|
452
|
+
// Everything below survives a run that stopped early, because everything
|
|
453
|
+
// below was already paid for. A review cut off by its budget has still
|
|
454
|
+
// read files, still spent tokens, and may still have written findings —
|
|
455
|
+
// throwing all of that away to report "exceeded max cost" tells the user
|
|
456
|
+
// the one thing they already know and none of the things they do not.
|
|
457
|
+
const stopped = ceiling ?? (result.subtype === 'success' ? undefined : this._describeStop(result));
|
|
458
|
+
const output = result ? this._readOutput(result, text, continuation) : this._recover(text);
|
|
459
|
+
// Deduped, then floored. The floor runs before the verdict is formed, so a
|
|
460
|
+
// finding too uncertain to report is also too uncertain to compel a
|
|
461
|
+
// recommendation — a `high` the model rated 0.3 should not be the reason a
|
|
462
|
+
// change is blocked while going unmentioned in the report.
|
|
463
|
+
const reported = FindingSet.from(output?.findings ?? [], new WorkspaceFiles(context.repo.root))
|
|
464
|
+
.deduped()
|
|
465
|
+
.atLeastConfident(this._config.confidenceFloor);
|
|
466
|
+
// A continuation was told not to restate what it was handed, so what it
|
|
467
|
+
// reported is not the whole review. Whatever it did not resolve goes back
|
|
468
|
+
// in before anything downstream counts findings — the verdict below is
|
|
469
|
+
// formed from this set, and a carried critical finding has to reach it.
|
|
470
|
+
const outcomes = continuation
|
|
471
|
+
? OutcomeSet.match(this._rulings(output), continuation, reported)
|
|
472
|
+
: undefined;
|
|
473
|
+
const reconciled = outcomes ? outcomes.applyTo(reported) : reported;
|
|
474
|
+
// Applied last, and before the verdict.
|
|
475
|
+
//
|
|
476
|
+
// Last, because the set of findings is not settled until what the
|
|
477
|
+
// continuation carried is back in it. A `wont-fix` has to catch the
|
|
478
|
+
// carried copy as well as a fresh report of the same thing.
|
|
479
|
+
//
|
|
480
|
+
// Before the verdict, because a defect someone deliberately deprioritised
|
|
481
|
+
// must not be the reason this change is blocked. Blocking on it would be
|
|
482
|
+
// the loudest possible way of reporting a finding the report itself is not
|
|
483
|
+
// allowed to mention.
|
|
484
|
+
const findings = (options.corrections ?? CorrectionSet.empty()).applyTo(reconciled);
|
|
485
|
+
options.onEvent?.({ type: 'done', findings: findings.size });
|
|
486
|
+
return {
|
|
487
|
+
findings,
|
|
488
|
+
summary: output?.summary ?? this._summarise(stopped, coverage),
|
|
489
|
+
// A run that did not finish cannot claim nothing else is wrong, however
|
|
490
|
+
// clean what it did read looked.
|
|
491
|
+
verdict: stopped ? Verdict.stopped(findings) : Verdict.from(output?.verdict, findings),
|
|
492
|
+
coverage,
|
|
493
|
+
nudges: gate.nudges,
|
|
494
|
+
...(outcomes && { reconciled: outcomes.reconciliation(context.since?.sha) }),
|
|
495
|
+
...(stopped && { stopped }),
|
|
496
|
+
usage: result ? Spend.fromResult(result) : Spend.fromMessages(spent),
|
|
497
|
+
durationMs: Date.now() - startedAt,
|
|
498
|
+
model,
|
|
499
|
+
effort: options.effort ?? this._config.effort,
|
|
500
|
+
channel: output === undefined ? 'none' : result ? this._channel(result) : 'recovered',
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
_channel(result) {
|
|
504
|
+
return result.subtype === 'success' && result.structured_output !== undefined ? 'structured' : 'recovered';
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* The review, from whichever channel has one — or nothing.
|
|
508
|
+
*
|
|
509
|
+
* Returning undefined rather than throwing is the point: a truncated run
|
|
510
|
+
* whose prose holds no parseable review is not an error to be raised, it is
|
|
511
|
+
* a review with no findings and a reason. The reason is reported; the
|
|
512
|
+
* coverage and the spend are reported with it.
|
|
513
|
+
*/
|
|
514
|
+
_readOutput(result, text, continuation) {
|
|
515
|
+
const structured = result.subtype === 'success' ? result.structured_output : undefined;
|
|
516
|
+
if (structured !== undefined)
|
|
517
|
+
return this._parseStructured(structured, continuation);
|
|
518
|
+
if (!text)
|
|
519
|
+
return undefined;
|
|
520
|
+
try {
|
|
521
|
+
return new ReviewOutputParser().parse(text);
|
|
522
|
+
}
|
|
523
|
+
catch {
|
|
524
|
+
return undefined;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
/** The ceilings this review was given, for reading back out of a run that hit one. */
|
|
528
|
+
get _ceilings() {
|
|
529
|
+
return new Ceilings(this._config.maxSteps, this._config.maxCost);
|
|
530
|
+
}
|
|
531
|
+
/** Whatever prose survived a run that threw before reporting. */
|
|
532
|
+
_recover(text) {
|
|
533
|
+
if (!text)
|
|
534
|
+
return undefined;
|
|
535
|
+
try {
|
|
536
|
+
return new ReviewOutputParser().parse(text);
|
|
537
|
+
}
|
|
538
|
+
catch {
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
/** Said in place of a summary the run never wrote. */
|
|
543
|
+
_summarise(stopped, coverage) {
|
|
544
|
+
if (!stopped)
|
|
545
|
+
return 'The model returned no summary.';
|
|
546
|
+
// Counts only. The unread list is already on the coverage line below, and
|
|
547
|
+
// repeating it here pushes the sentence that matters off the screen.
|
|
548
|
+
return [
|
|
549
|
+
`This review did not finish: ${stopped.detail}`,
|
|
550
|
+
`It opened ${coverage.opened.length} of ${coverage.changedCount} changed files and reported nothing before it stopped.`,
|
|
551
|
+
'Treat the absence of findings as unknown, not as approval.',
|
|
552
|
+
].join(' ');
|
|
553
|
+
}
|
|
554
|
+
_describeStop(result) {
|
|
555
|
+
return this._ceilings.fromResult({
|
|
556
|
+
subtype: result.subtype,
|
|
557
|
+
...('errors' in result && { errors: result.errors }),
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* The rulings a continuation returned, if it returned any.
|
|
562
|
+
*
|
|
563
|
+
* Absent whenever the answer came back as prose — a run recovered after a
|
|
564
|
+
* ceiling has findings but no outcomes, and `OutcomeSet` reads that as
|
|
565
|
+
* nothing having been ruled on, which carries everything.
|
|
566
|
+
*/
|
|
567
|
+
_rulings(output) {
|
|
568
|
+
return output && 'outcomes' in output ? output.outcomes : undefined;
|
|
569
|
+
}
|
|
570
|
+
/** The structured channel is schema-constrained, not schema-guaranteed. */
|
|
571
|
+
_parseStructured(data, continuation) {
|
|
572
|
+
const parsed = (continuation?.rulesOn ? continuationOutputSchema : reviewOutputSchema).safeParse(data);
|
|
573
|
+
if (!parsed.success) {
|
|
574
|
+
const issue = parsed.error.issues[0];
|
|
575
|
+
throw new Error(`The model's review did not match the schema: ${issue?.message}${issue?.path.length ? ` at ${issue.path.join('.')}` : ''}`);
|
|
576
|
+
}
|
|
577
|
+
return parsed.data;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
//# sourceMappingURL=reviewer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reviewer.js","sourceRoot":"","sources":["../src/reviewer.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,sEAAsE;AACtE,4DAA4D;AAE5D,OAAO,EAAE,KAAK,EAAuC,MAAM,gCAAgC,CAAC;AAE5F,OAAO,EAAE,cAAc,EAAE,aAAa,EAAwC,MAAM,cAAc,CAAC;AACnG,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EACL,UAAU,EACV,OAAO,EACP,cAAc,EACd,kBAAkB,EAClB,gBAAgB,GAEjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAuC,MAAM,YAAY,CAAC;AAExE,OAAO,EAEL,UAAU,EACV,wBAAwB,GAGzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAIvD;;;;;;;;GAQG;AACH,MAAM,OAAO,cAAc;IAWN,gBAAgB;IAVlB,QAAQ,CAAc;IACtB,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAE7C;;;;OAIG;IACH,YACE,OAA0B,EACT,gBAAgB,GAAG,KAAK;gCAAxB,gBAAgB;QAEjC,IAAI,CAA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,2EAA2E;IACnE,gBAAgB,CAAC,IAAa,EAAE,YAA2B;QACjE,MAAM,MAAM,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QACvG,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACrC,MAAM,IAAI,KAAK,CACb,gDAAgD,KAAK,EAAE,OAAO,GAC5D,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,EACvD,EAAE,CACH,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AgentConfig } from './config.js';
|
|
2
|
+
export declare const SESSION_VERBS: readonly ['list', 'prune'];
|
|
3
|
+
export type SessionVerb = (typeof SESSION_VERBS)[number];
|
|
4
|
+
export declare function isSessionVerb(value: string | undefined): value is SessionVerb;
|
|
5
|
+
export interface SessionCommandOptions {
|
|
6
|
+
json: boolean;
|
|
7
|
+
limit?: number;
|
|
8
|
+
keep?: number;
|
|
9
|
+
yes: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `weigh sessions <verb>` — inspect and prune local transcripts.
|
|
13
|
+
* The memory-side counterpart is `weigh memory <verb>`; the two are separate
|
|
14
|
+
* stores and are pruned separately.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runSessionCommand(verb: SessionVerb, config: AgentConfig, options: SessionCommandOptions): Promise<number>;
|
|
17
|
+
//# sourceMappingURL=session-cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-cli.d.ts","sourceRoot":"","sources":["../src/session-cli.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,eAAO,MAAM,aAAa,YAAI,MAAM,EAAE,OAAO,CAAU,CAAC;AACxD,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAEzD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,IAAI,WAAW,CAE7E;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,OAAO,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,MAAM,CAAC,CAkDjB"}
|