wachiman 1.10.0 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +139 -79
- package/package.json +1 -1
- package/skills/wachiman-loop/SKILL.md +91 -0
- package/skills/wachiman-review/SKILL.md +23 -1
- package/src/accounts/commands.ts +6 -2
- package/src/ask.ts +240 -0
- package/src/call-message.ts +26 -3
- package/src/cli.ts +157 -13
- package/src/config.ts +40 -5
- package/src/connectors/local-git.ts +119 -21
- package/src/connectors/working-tree.ts +333 -0
- package/src/cost.ts +20 -0
- package/src/doctor/checks.ts +1 -1
- package/src/engine.ts +988 -104
- package/src/estimate.ts +64 -0
- package/src/fidelity/block.ts +263 -0
- package/src/fidelity/claims-call.ts +172 -0
- package/src/fidelity/claims.ts +69 -0
- package/src/fidelity/digest.ts +80 -0
- package/src/fidelity/grade.ts +242 -0
- package/src/fidelity/inert.ts +25 -0
- package/src/fidelity/rules.ts +166 -0
- package/src/fidelity/sink.ts +135 -0
- package/src/fidelity/summary.ts +16 -0
- package/src/fidelity/types.ts +93 -0
- package/src/formats.ts +36 -9
- package/src/history/fingerprint.ts +1 -1
- package/src/history/index.ts +3 -0
- package/src/history/store.ts +39 -1
- package/src/init/options.ts +1 -1
- package/src/init/prompt.ts +4 -1
- package/src/init/run.ts +38 -27
- package/src/local-ask.ts +231 -0
- package/src/local.ts +274 -74
- package/src/loop/command.ts +441 -0
- package/src/loop/state.ts +88 -0
- package/src/loop/stop-rule.ts +98 -0
- package/src/providers/claude-code.ts +47 -12
- package/src/providers/codex.ts +20 -1
- package/src/providers/index.ts +5 -2
- package/src/providers/types.ts +10 -0
- package/src/risk.ts +264 -0
- package/src/setup/prompt.ts +28 -15
- package/src/setup/run.ts +14 -2
- package/src/sinks/common.ts +5 -1
- package/src/sinks/json.ts +13 -2
- package/src/sinks/markdown.ts +2 -0
- package/src/sinks/terminal.ts +2 -0
- package/src/skills/install.ts +4 -4
- package/src/status/command.ts +202 -0
- package/src/store/command.ts +109 -0
- package/src/store/figures.ts +153 -0
- package/src/store/html.ts +138 -0
- package/src/store/index.ts +298 -0
- package/src/wizard/command.ts +23 -0
- package/src/wizard/prompt.ts +22 -9
- package/src/wizard/style.ts +19 -0
- package/templates/caller-workflow.yml +90 -25
- package/templates/wachiman-review-caller.yml +12 -1
package/src/local.ts
CHANGED
|
@@ -7,26 +7,31 @@
|
|
|
7
7
|
* Exit codes (plan decision 8): 0 when a report was produced (complete, partial, or stopped by a
|
|
8
8
|
* usage limit); 1 when no call produced a review (sign-in refused, an unclassified error, every
|
|
9
9
|
* batch failed); 2 for a usage error; 130 after Ctrl-C.
|
|
10
|
+
*
|
|
11
|
+
* The parts `wachiman ask` shares (`parseFlags`, `openLocalSession`, `localScopeInput`) live here, so
|
|
12
|
+
* both commands read the same flags, pick the same account and provider, and read the same change.
|
|
10
13
|
*/
|
|
11
14
|
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
12
15
|
import { resolve } from "node:path";
|
|
13
16
|
import { loadConfig, UsageError } from "./config";
|
|
14
|
-
import { buildLocalInput, DEFAULT_MAX_DEPTH, EMPTY_TREE_LABEL, type LocalRefs, removeSnapshot, snapshotHead, warnSnapshotDifferences } from "./connectors/local-git";
|
|
15
17
|
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
} from "./
|
|
18
|
+
buildLocalInput,
|
|
19
|
+
DEFAULT_MAX_DEPTH,
|
|
20
|
+
EMPTY_TREE_LABEL,
|
|
21
|
+
type LocalRefs,
|
|
22
|
+
removeSnapshot,
|
|
23
|
+
snapshotHead,
|
|
24
|
+
warnSnapshotDifferences,
|
|
25
|
+
} from "./connectors/local-git";
|
|
26
|
+
import { DEFAULT_EXCLUDE, estimateFor, filterFiles, planBatches, reviewChange, reviewOptionsOf, type ReviewInput, type ReviewResult } from "./engine";
|
|
27
|
+
import { sizeGate, type ReviewEstimate } from "./estimate";
|
|
24
28
|
import { spawnGit } from "./evidence";
|
|
25
|
-
import { assertReviewInputFormat } from "./formats";
|
|
29
|
+
import { assertReviewInputFormat, REVIEW_INPUT_V2 } from "./formats";
|
|
30
|
+
import { workingTreeInput, snapshotWorkingTree } from "./connectors/working-tree";
|
|
26
31
|
import { historyRoot, historySettings, saveRun } from "./history";
|
|
27
32
|
import { readConfig, wachimanHome } from "./accounts/config";
|
|
28
33
|
import { confirmProfile, type SpawnFn } from "./accounts/confirm";
|
|
29
|
-
import { failureText, profileLine, resolveProfile } from "./accounts/resolve";
|
|
34
|
+
import { failureText, profileLine, resolveProfile, type ResolvedProfile } from "./accounts/resolve";
|
|
30
35
|
import { repositoryKey } from "./history/store";
|
|
31
36
|
import { inspectIsolatedProfile, parseProfile, populatedProfileError, profileDir } from "./profiles";
|
|
32
37
|
import { getProvider as defaultGetProvider, type ProviderAdapter } from "./providers";
|
|
@@ -40,6 +45,7 @@ export const FORMATS = ["terminal", "markdown", "json"] as const;
|
|
|
40
45
|
export type LocalFormat = (typeof FORMATS)[number];
|
|
41
46
|
|
|
42
47
|
export interface LocalArgs {
|
|
48
|
+
workingTree?: "staged" | "all";
|
|
43
49
|
base?: string;
|
|
44
50
|
commit?: string;
|
|
45
51
|
from?: string;
|
|
@@ -51,7 +57,7 @@ export interface LocalArgs {
|
|
|
51
57
|
profile?: string;
|
|
52
58
|
agentPrompt: boolean;
|
|
53
59
|
history: boolean;
|
|
54
|
-
/** `--verify` forces the verifier on, `--no-verify` off; unset follows `AGENT_REVIEW_VERIFY` (
|
|
60
|
+
/** `--verify` forces the verifier on, `--no-verify` off; unset follows `AGENT_REVIEW_VERIFY` (off by default, ADR 0027). */
|
|
55
61
|
verify: boolean | undefined;
|
|
56
62
|
/** `--result-version`: with `--format json`, which result version to write (default 1 for a committed change). */
|
|
57
63
|
resultVersion?: 1 | 2;
|
|
@@ -61,11 +67,46 @@ export interface LocalArgs {
|
|
|
61
67
|
export const localUsage = `wachiman local [paths…] [--base <ref> | --from <commit> | --commit <commit>] [--max-depth <n>] [--repo-dir <dir>]
|
|
62
68
|
[--input <file>] [--format terminal|markdown|json] [--output <file>]
|
|
63
69
|
[--profile <name>] [--agent-prompt] [--history] [--verify | --no-verify]
|
|
64
|
-
[--result-version 1|2]`;
|
|
70
|
+
[--result-version 1|2] [--working-tree staged|all]`;
|
|
71
|
+
|
|
72
|
+
/** Every flag `local` takes. `ask` takes the subset it names in `ask-command`. */
|
|
73
|
+
export const LOCAL_FLAGS = [
|
|
74
|
+
"--agent-prompt",
|
|
75
|
+
"--history",
|
|
76
|
+
"--verify",
|
|
77
|
+
"--no-verify",
|
|
78
|
+
"--result-version",
|
|
79
|
+
"--working-tree",
|
|
80
|
+
"--base",
|
|
81
|
+
"--commit",
|
|
82
|
+
"--from",
|
|
83
|
+
"--max-depth",
|
|
84
|
+
"--output",
|
|
85
|
+
"--profile",
|
|
86
|
+
"--format",
|
|
87
|
+
"--input",
|
|
88
|
+
] as const;
|
|
65
89
|
|
|
66
90
|
/** The arguments after `local` (`--repo-dir` is already taken out). Both `--x v` and `--x=v`. */
|
|
67
91
|
export function parseLocalArgs(argv: string[]): LocalArgs {
|
|
68
|
-
|
|
92
|
+
return parseFlags(argv, "local", LOCAL_FLAGS);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The flags `local` and `ask` share, read by this one parser so both mean the same by each. A flag
|
|
97
|
+
* not in `accepted` is a usage error for `command`. Every argument that is not a flag goes to
|
|
98
|
+
* `paths`: the paths of `local`, the words of an `ask` question.
|
|
99
|
+
*/
|
|
100
|
+
export function parseFlags(argv: string[], command: string, accepted: readonly string[]): LocalArgs {
|
|
101
|
+
const args: LocalArgs = {
|
|
102
|
+
paths: [],
|
|
103
|
+
format: "terminal",
|
|
104
|
+
profile: undefined,
|
|
105
|
+
agentPrompt: false,
|
|
106
|
+
history: false,
|
|
107
|
+
verify: undefined,
|
|
108
|
+
input: undefined,
|
|
109
|
+
};
|
|
69
110
|
let base: string | undefined;
|
|
70
111
|
let sawVerify = false;
|
|
71
112
|
let sawNoVerify = false;
|
|
@@ -78,6 +119,7 @@ export function parseLocalArgs(argv: string[]): LocalArgs {
|
|
|
78
119
|
}
|
|
79
120
|
const eq = arg.indexOf("=");
|
|
80
121
|
const name = eq === -1 ? arg : arg.slice(0, eq);
|
|
122
|
+
if (!accepted.includes(name)) throw new UsageError(`Unknown option ${name} for ${command}.`);
|
|
81
123
|
const value = () => {
|
|
82
124
|
const v = eq === -1 ? argv[++i] : arg.slice(eq + 1);
|
|
83
125
|
if (v === undefined || v === "" || (eq === -1 && v.startsWith("--"))) throw new UsageError(`${name} needs a value.`);
|
|
@@ -91,22 +133,25 @@ export function parseLocalArgs(argv: string[]): LocalArgs {
|
|
|
91
133
|
} else if (name === "--no-verify" && eq === -1) {
|
|
92
134
|
args.verify = false;
|
|
93
135
|
sawNoVerify = true;
|
|
94
|
-
}
|
|
95
|
-
else if (name === "--result-version") {
|
|
136
|
+
} else if (name === "--result-version") {
|
|
96
137
|
const v = value();
|
|
97
138
|
if (v !== "1" && v !== "2") throw new UsageError(`--result-version must be 1 or 2, got "${v}".`);
|
|
98
139
|
args.resultVersion = v === "1" ? 1 : 2;
|
|
99
|
-
}
|
|
100
|
-
|
|
140
|
+
} else if (name === "--working-tree") {
|
|
141
|
+
const v = value();
|
|
142
|
+
if (v !== "staged" && v !== "all") throw new UsageError("--working-tree must be staged or all.");
|
|
143
|
+
args.workingTree = v;
|
|
144
|
+
picked.push(name);
|
|
145
|
+
} else if (name === "--base") {
|
|
101
146
|
base = value();
|
|
102
147
|
picked.push(name);
|
|
103
148
|
} else if (name === "--commit" || name === "--from") {
|
|
104
149
|
args[name === "--commit" ? "commit" : "from"] = value();
|
|
105
150
|
picked.push(name);
|
|
106
|
-
}
|
|
107
|
-
else if (name === "--max-depth") {
|
|
151
|
+
} else if (name === "--max-depth") {
|
|
108
152
|
const v = value();
|
|
109
|
-
if (!/^[1-9]\d*$/.test(v) || !Number.isSafeInteger(Number(v)))
|
|
153
|
+
if (!/^[1-9]\d*$/.test(v) || !Number.isSafeInteger(Number(v)))
|
|
154
|
+
throw new UsageError(`--max-depth must be a positive integer, got "${v}".`);
|
|
110
155
|
args.maxDepth = Number(v);
|
|
111
156
|
} else if (name === "--output") args.output = value();
|
|
112
157
|
else if (name === "--profile") args.profile = parseProfile(value());
|
|
@@ -118,7 +163,7 @@ export function parseLocalArgs(argv: string[]): LocalArgs {
|
|
|
118
163
|
const v = value();
|
|
119
164
|
if (!existsSync(v)) throw new UsageError(`--input ${v} does not exist.`);
|
|
120
165
|
args.input = v;
|
|
121
|
-
} else throw new UsageError(`Unknown option ${name} for
|
|
166
|
+
} else throw new UsageError(`Unknown option ${name} for ${command}.`);
|
|
122
167
|
}
|
|
123
168
|
if (sawVerify && sawNoVerify) throw new UsageError("--verify and --no-verify cannot be used together.");
|
|
124
169
|
if (args.resultVersion !== undefined && args.format !== "json") throw new UsageError("--result-version applies only with --format json.");
|
|
@@ -128,6 +173,7 @@ export function parseLocalArgs(argv: string[]): LocalArgs {
|
|
|
128
173
|
if (args.input !== undefined && (picked.length > 0 || args.paths.length > 0)) {
|
|
129
174
|
throw new UsageError("--input reviews the file's change as it is: it takes no --base, --from or --commit, and no paths.");
|
|
130
175
|
}
|
|
176
|
+
if (args.workingTree && args.resultVersion === 1) throw new UsageError("Working-tree reviews require --result-version 2.");
|
|
131
177
|
return args;
|
|
132
178
|
}
|
|
133
179
|
|
|
@@ -153,6 +199,18 @@ export function readInputFile(path: string): Omit<ReviewInput, "headDir"> {
|
|
|
153
199
|
const change = input.change;
|
|
154
200
|
if (!change || typeof change !== "object") problems.push("change");
|
|
155
201
|
else {
|
|
202
|
+
if (!["pull-request", "branch", "working-tree"].includes(change.kind)) problems.push("change.kind");
|
|
203
|
+
if (change.kind === "working-tree") {
|
|
204
|
+
const w = change.workingTree;
|
|
205
|
+
if (
|
|
206
|
+
input.format !== REVIEW_INPUT_V2 ||
|
|
207
|
+
!w ||
|
|
208
|
+
!["staged", "all"].includes(w.mode) ||
|
|
209
|
+
w.tree !== change.head?.sha ||
|
|
210
|
+
w.baseCommit !== change.base?.sha
|
|
211
|
+
)
|
|
212
|
+
problems.push("change.workingTree");
|
|
213
|
+
} else if (change.workingTree !== undefined) problems.push("change.workingTree");
|
|
156
214
|
if (!isString(change.describe)) problems.push("change.describe");
|
|
157
215
|
if (!isString(change.repository?.name)) problems.push("change.repository.name");
|
|
158
216
|
if (!isString(change.head?.sha) || !HEX_SHA.test(change.head.sha)) problems.push("change.head.sha");
|
|
@@ -183,9 +241,10 @@ export function exitCodeOf(result: ReviewResult) {
|
|
|
183
241
|
* The provider, with Ctrl-C turned into "stop the review": after an interrupted call every later
|
|
184
242
|
* call fails at once, without starting `claude`, so the core winds down in milliseconds.
|
|
185
243
|
*/
|
|
186
|
-
function interruptible(provider: ProviderAdapter, state: { interrupted: boolean }): ProviderAdapter {
|
|
244
|
+
export function interruptible(provider: ProviderAdapter, state: { interrupted: boolean }): ProviderAdapter {
|
|
187
245
|
return {
|
|
188
246
|
name: provider.name,
|
|
247
|
+
auth: provider.auth,
|
|
189
248
|
preflight: () => provider.preflight(),
|
|
190
249
|
modelLabel: () => provider.modelLabel(),
|
|
191
250
|
leaksSecret: (texts) => provider.leaksSecret(texts),
|
|
@@ -211,26 +270,43 @@ export interface LocalDeps {
|
|
|
211
270
|
getProvider?: typeof defaultGetProvider;
|
|
212
271
|
}
|
|
213
272
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
273
|
+
/** What a local command settles before any call: the settings, the account and the providers. */
|
|
274
|
+
export interface LocalSession {
|
|
275
|
+
config: ReturnType<typeof loadConfig>;
|
|
276
|
+
profile: ResolvedProfile["profile"];
|
|
277
|
+
profileNote?: string;
|
|
278
|
+
provider: ProviderAdapter;
|
|
279
|
+
verifier?: ProviderAdapter;
|
|
280
|
+
/** Set by Ctrl-C: every later call then fails at once. */
|
|
281
|
+
state: { interrupted: boolean };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* The settings, the account (ADR 0029), the subscription-mode provider and, with `--verify`, the
|
|
286
|
+
* verifier, all checked before any call. Nothing in the reviewed repository takes part: a corrupt
|
|
287
|
+
* store, a value that resolves to nothing, or a profile that does not confirm is a usage error.
|
|
288
|
+
*/
|
|
289
|
+
export function openLocalSession(p: {
|
|
290
|
+
profile?: string;
|
|
291
|
+
verify: boolean | undefined;
|
|
292
|
+
repoDir: string;
|
|
293
|
+
env: Record<string, string | undefined>;
|
|
294
|
+
stderr: (line: string) => void;
|
|
295
|
+
deps: LocalDeps;
|
|
296
|
+
}): LocalSession {
|
|
297
|
+
const { env, repoDir, deps } = p;
|
|
298
|
+
const loaded = loadConfig(env, p.stderr);
|
|
222
299
|
if (loaded.provider !== "claude-code") {
|
|
223
|
-
throw new UsageError(
|
|
224
|
-
`AGENT_REVIEW_PROVIDER=${loaded.provider}: the local review runs only on Claude Code, your signed-in \`claude\`.`,
|
|
225
|
-
);
|
|
300
|
+
throw new UsageError(`AGENT_REVIEW_PROVIDER=${loaded.provider}: the local review runs only on Claude Code, your signed-in \`claude\`.`);
|
|
226
301
|
}
|
|
227
302
|
// A person ran it: no automatic ceiling (decision 14).
|
|
228
|
-
const config = {
|
|
303
|
+
const config = {
|
|
304
|
+
...loaded,
|
|
305
|
+
trigger: undefined,
|
|
306
|
+
verify: p.verify ?? loaded.verify,
|
|
307
|
+
};
|
|
229
308
|
// Before the provider exists; the adapter's own check in preflight() is the second line.
|
|
230
309
|
if (env.ANTHROPIC_API_KEY) throw new UsageError(SUBSCRIPTION_KEY_REFUSAL);
|
|
231
|
-
// Off unless asked for (ADR 0020): without this, nothing below touches ~/.wachiman/history.
|
|
232
|
-
// A bad AGENT_REVIEW_HISTORY_DAYS stops here, before any call is paid for.
|
|
233
|
-
const history = historySettings(env, args.history);
|
|
234
310
|
|
|
235
311
|
// Which account (ADR 0029): nothing in the reviewed repository takes part. A corrupt store, a
|
|
236
312
|
// value that resolves to nothing, or a profile that does not confirm is exit 2 before any call.
|
|
@@ -240,7 +316,7 @@ export function runLocal(
|
|
|
240
316
|
const accounts = stored.kind === "ok" ? stored.config : undefined;
|
|
241
317
|
const bindingKey = accounts && Object.keys(accounts.projects).length > 0 ? repositoryKey(repoDir).key : undefined;
|
|
242
318
|
const resolution = resolveProfile({
|
|
243
|
-
flag:
|
|
319
|
+
flag: p.profile,
|
|
244
320
|
binding: bindingKey !== undefined && Object.hasOwn(accounts!.projects, bindingKey) ? accounts!.projects[bindingKey] : undefined,
|
|
245
321
|
env: { WACHIMAN_PROFILE: env.WACHIMAN_PROFILE },
|
|
246
322
|
config: accounts,
|
|
@@ -249,7 +325,7 @@ export function runLocal(
|
|
|
249
325
|
});
|
|
250
326
|
if (!resolution.ok) throw new UsageError(failureText(resolution.failure));
|
|
251
327
|
const { resolved } = resolution;
|
|
252
|
-
|
|
328
|
+
p.stderr(profileLine(resolved));
|
|
253
329
|
const { profile } = resolved;
|
|
254
330
|
|
|
255
331
|
let configDir: string | undefined;
|
|
@@ -294,8 +370,109 @@ export function runLocal(
|
|
|
294
370
|
)
|
|
295
371
|
: undefined;
|
|
296
372
|
verifier?.preflight();
|
|
373
|
+
return { config, profile, profileNote, provider, verifier, state };
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* The change the scope flags select (ADR 0019 decision 2): the tracked working tree with
|
|
378
|
+
* `--working-tree`, else the committed range. The input reads from a snapshot of the head; `release`
|
|
379
|
+
* removes it, and the caller runs it once the change is no longer read.
|
|
380
|
+
*/
|
|
381
|
+
export function localScopeInput(p: {
|
|
382
|
+
repoDir: string;
|
|
383
|
+
workingTree?: "staged" | "all";
|
|
384
|
+
base?: string;
|
|
385
|
+
commit?: string;
|
|
386
|
+
from?: string;
|
|
387
|
+
maxDepth?: number;
|
|
388
|
+
paths: string[];
|
|
389
|
+
log: (line: string) => void;
|
|
390
|
+
warn: (line: string) => void;
|
|
391
|
+
}): { input: ReviewInput; release: () => void } {
|
|
392
|
+
if (p.workingTree) {
|
|
393
|
+
const built = workingTreeInput({
|
|
394
|
+
repoDir: p.repoDir,
|
|
395
|
+
mode: p.workingTree,
|
|
396
|
+
paths: p.paths,
|
|
397
|
+
log: p.log,
|
|
398
|
+
warn: p.warn,
|
|
399
|
+
});
|
|
400
|
+
p.log(`mode: working tree (${p.workingTree})`);
|
|
401
|
+
p.log(`base: HEAD (${short(built.input.change.base.sha)})`);
|
|
402
|
+
p.log(`tree: ${short(built.input.change.head.sha)}`);
|
|
403
|
+
return { input: built.input, release: built.release };
|
|
404
|
+
}
|
|
405
|
+
const maxDepth = p.maxDepth ?? DEFAULT_MAX_DEPTH;
|
|
406
|
+
const built = buildLocalInput({
|
|
407
|
+
repoDir: p.repoDir,
|
|
408
|
+
base: p.base,
|
|
409
|
+
commit: p.commit,
|
|
410
|
+
from: p.from,
|
|
411
|
+
maxDepth,
|
|
412
|
+
paths: p.paths,
|
|
413
|
+
log: p.log,
|
|
414
|
+
warn: p.warn,
|
|
415
|
+
});
|
|
416
|
+
const { refs } = built;
|
|
417
|
+
const commits = `${refs.depth} commit${refs.depth === 1 ? "" : "s"}`;
|
|
418
|
+
const max = `(max ${maxDepth})`;
|
|
419
|
+
if (refs.mode?.kind === "commit") {
|
|
420
|
+
p.log(`mode: one commit (${short(refs.mode.rev)})${refs.mode.merge ? ", a merge commit: first parent" : ""}`);
|
|
421
|
+
p.log(`start: ${startText(refs)}`);
|
|
422
|
+
p.log(`depth: ${commits}`);
|
|
423
|
+
p.log(`head: ${short(refs.headSha)}`);
|
|
424
|
+
} else if (refs.mode?.kind === "from") {
|
|
425
|
+
p.log(`mode: from ${short(refs.mode.rev)} to HEAD`);
|
|
426
|
+
p.log(`start: ${startText(refs)}`);
|
|
427
|
+
p.log(`depth: ${commits} ${max}`);
|
|
428
|
+
p.log(`head: ${refs.headRef} (${short(refs.headSha)})`);
|
|
429
|
+
} else {
|
|
430
|
+
p.log(`base: ${refs.baseRef} (${short(refs.baseSha)})`);
|
|
431
|
+
p.log(`merge-base: ${short(refs.mergeBase)}`);
|
|
432
|
+
p.log(`depth: ${commits} ${max}`);
|
|
433
|
+
p.log(`head: ${refs.headRef} (${short(refs.headSha)})`);
|
|
434
|
+
}
|
|
435
|
+
return { input: built.input, release: () => removeSnapshot(built.snapshotDir) };
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* The one warning a local run prints when its estimate is above the size gate, or null. Local runs
|
|
440
|
+
* are never refused: the run continues and stops at its budget.
|
|
441
|
+
*/
|
|
442
|
+
export function sizeWarning(estimate: ReviewEstimate, gate: number, budgetUsd: number, model: string): string | null {
|
|
443
|
+
if (estimate.usd <= gate) return null;
|
|
444
|
+
return `warning: reviewing all of this would cost about $${estimate.usd.toFixed(2)} at API prices (${estimate.batches} batches × $${estimate.perBatchUsd.toFixed(2)} for ${model}), above the $${gate.toFixed(2)} size gate. Local runs are never refused; this one continues and stops at its budget, $${budgetUsd.toFixed(2)} (AGENT_REVIEW_BUDGET_USD).`;
|
|
445
|
+
}
|
|
297
446
|
|
|
298
|
-
|
|
447
|
+
export function runLocal(
|
|
448
|
+
args: LocalArgs,
|
|
449
|
+
repoDir: string,
|
|
450
|
+
env: Record<string, string | undefined>,
|
|
451
|
+
io: {
|
|
452
|
+
stdout: (text: string) => void;
|
|
453
|
+
stderr: (line: string) => void;
|
|
454
|
+
engineVersion: string;
|
|
455
|
+
},
|
|
456
|
+
deps: LocalDeps = {},
|
|
457
|
+
): number {
|
|
458
|
+
const fileInput = args.input === undefined ? undefined : readInputFile(args.input);
|
|
459
|
+
if ((args.workingTree || fileInput?.change.kind === "working-tree") && args.resultVersion === 1) {
|
|
460
|
+
throw new UsageError("Working-tree reviews require --result-version 2; a tree is not a commit.");
|
|
461
|
+
}
|
|
462
|
+
// Off unless asked for (ADR 0020): without this, nothing below touches ~/.wachiman/history.
|
|
463
|
+
// A bad AGENT_REVIEW_HISTORY_DAYS stops here, before any call is paid for.
|
|
464
|
+
const history = historySettings(env, args.history);
|
|
465
|
+
const home = wachimanHome(env);
|
|
466
|
+
const { config, profile, profileNote, provider, verifier, state } = openLocalSession({
|
|
467
|
+
profile: args.profile,
|
|
468
|
+
verify: args.verify,
|
|
469
|
+
repoDir,
|
|
470
|
+
env,
|
|
471
|
+
stderr: io.stderr,
|
|
472
|
+
deps,
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
let release: (() => void) | undefined;
|
|
299
476
|
const onSigint = () => {
|
|
300
477
|
state.interrupted = true;
|
|
301
478
|
};
|
|
@@ -303,45 +480,54 @@ export function runLocal(
|
|
|
303
480
|
try {
|
|
304
481
|
let input: ReviewInput;
|
|
305
482
|
if (args.input === undefined) {
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
io.stderr
|
|
315
|
-
io.stderr
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
io.stderr(`start: ${startText(refs)}`);
|
|
320
|
-
io.stderr(`depth: ${commits} ${max}`);
|
|
321
|
-
io.stderr(`head: ${refs.headRef} (${short(refs.headSha)})`);
|
|
322
|
-
} else {
|
|
323
|
-
io.stderr(`base: ${refs.baseRef} (${short(refs.baseSha)})`);
|
|
324
|
-
io.stderr(`merge-base: ${short(refs.mergeBase)}`);
|
|
325
|
-
io.stderr(`depth: ${commits} ${max}`);
|
|
326
|
-
io.stderr(`head: ${refs.headRef} (${short(refs.headSha)})`);
|
|
327
|
-
}
|
|
483
|
+
const scope = localScopeInput({
|
|
484
|
+
repoDir,
|
|
485
|
+
workingTree: args.workingTree,
|
|
486
|
+
base: args.base,
|
|
487
|
+
commit: args.commit,
|
|
488
|
+
from: args.from,
|
|
489
|
+
maxDepth: args.maxDepth,
|
|
490
|
+
paths: args.paths,
|
|
491
|
+
log: io.stderr,
|
|
492
|
+
warn: io.stderr,
|
|
493
|
+
});
|
|
494
|
+
input = scope.input;
|
|
495
|
+
release = scope.release;
|
|
328
496
|
} else {
|
|
329
|
-
const fromFile =
|
|
497
|
+
const fromFile = fileInput!;
|
|
330
498
|
const head = fromFile.change.head.sha;
|
|
331
|
-
if (
|
|
499
|
+
if (
|
|
500
|
+
fromFile.change.kind !== "working-tree" &&
|
|
501
|
+
spawnGit(["cat-file", "-e", `${head}^{commit}`], {
|
|
502
|
+
cwd: repoDir,
|
|
503
|
+
timeoutMs: 60_000,
|
|
504
|
+
}).status !== 0
|
|
505
|
+
) {
|
|
332
506
|
throw new UsageError(`The input's head ${short(head)} is not a commit in ${repoDir}; pass the clone that has it with --repo-dir.`);
|
|
333
507
|
}
|
|
334
|
-
const snapshot =
|
|
335
|
-
|
|
508
|
+
const snapshot =
|
|
509
|
+
fromFile.change.kind === "working-tree"
|
|
510
|
+
? { ...snapshotWorkingTree(repoDir, head), missing: [], extra: [] }
|
|
511
|
+
: snapshotHead(repoDir, head);
|
|
512
|
+
release = () => removeSnapshot(snapshot.dir);
|
|
336
513
|
warnSnapshotDifferences(snapshot, io.stderr);
|
|
337
514
|
input = { ...fromFile, headDir: snapshot.dir };
|
|
338
515
|
io.stderr(`head: ${short(head)}`);
|
|
339
516
|
}
|
|
340
517
|
const { kept, dropped } = filterFiles(input.files, [...DEFAULT_EXCLUDE, ...config.exclude], input.scope);
|
|
341
|
-
const batches = planBatches(kept, {
|
|
518
|
+
const batches = planBatches(kept, {
|
|
519
|
+
maxLines: config.batchLines,
|
|
520
|
+
maxChars: config.batchChars,
|
|
521
|
+
});
|
|
342
522
|
io.stderr(`files: ${kept.length} (${dropped.length} excluded)`);
|
|
343
523
|
io.stderr(`batches: ${batches.length}`);
|
|
344
|
-
|
|
524
|
+
const warning = sizeWarning(estimateFor(kept, config), sizeGate(config, false), config.budgetUsd, config.model);
|
|
525
|
+
if (warning) io.stderr(warning);
|
|
526
|
+
io.stderr(
|
|
527
|
+
config.verify
|
|
528
|
+
? `verify: on (${config.verifierModel}, reserve $${Math.min(config.verifyBudgetUsd, config.budgetUsd / 2).toFixed(2)})`
|
|
529
|
+
: "verify: off",
|
|
530
|
+
);
|
|
345
531
|
|
|
346
532
|
const result = reviewChange(input, reviewOptionsOf(config, config.budgetUsd, profile.kind === "managed" ? "isolated" : "default"), {
|
|
347
533
|
provider,
|
|
@@ -350,8 +536,13 @@ export function runLocal(
|
|
|
350
536
|
...(verifier
|
|
351
537
|
? {
|
|
352
538
|
baseSnapshot: () => {
|
|
353
|
-
const base =
|
|
354
|
-
|
|
539
|
+
const base = input.change.kind === "working-tree"
|
|
540
|
+
? snapshotWorkingTree(repoDir, `${input.change.base.sha}^{tree}`)
|
|
541
|
+
: snapshotHead(repoDir, input.change.base.sha);
|
|
542
|
+
return {
|
|
543
|
+
dir: base.dir,
|
|
544
|
+
release: () => removeSnapshot(base.dir),
|
|
545
|
+
};
|
|
355
546
|
},
|
|
356
547
|
}
|
|
357
548
|
: {}),
|
|
@@ -386,10 +577,19 @@ export function runLocal(
|
|
|
386
577
|
}
|
|
387
578
|
const text =
|
|
388
579
|
args.format === "json"
|
|
389
|
-
? renderJson(
|
|
580
|
+
? renderJson(
|
|
581
|
+
result,
|
|
582
|
+
args.resultVersion ?? (input.change.kind === "working-tree" ? 2 : 1),
|
|
583
|
+
// ADR 0034: with history on, a `/2` finding names itself by the id `history --verdict` takes.
|
|
584
|
+
annotation ? result.findings.map((_, i) => annotation!.byIndex.get(i)?.id) : undefined,
|
|
585
|
+
)
|
|
390
586
|
: args.format === "markdown"
|
|
391
587
|
? renderMarkdown(result, { profileNote, history: annotation })
|
|
392
|
-
: renderTerminal(result, {
|
|
588
|
+
: renderTerminal(result, {
|
|
589
|
+
profileNote,
|
|
590
|
+
agentPrompt: args.agentPrompt,
|
|
591
|
+
history: annotation,
|
|
592
|
+
});
|
|
393
593
|
if (args.output !== undefined) {
|
|
394
594
|
const path = resolve(args.output);
|
|
395
595
|
writeFileSync(path, text);
|
|
@@ -398,6 +598,6 @@ export function runLocal(
|
|
|
398
598
|
return exitCodeOf(result);
|
|
399
599
|
} finally {
|
|
400
600
|
process.off("SIGINT", onSigint);
|
|
401
|
-
|
|
601
|
+
release?.();
|
|
402
602
|
}
|
|
403
603
|
}
|