wachiman 1.12.0 → 1.14.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 +132 -101
- package/bin/wachiman.js +1 -1
- package/package.json +2 -3
- package/skills/wachiman-loop/SKILL.md +91 -0
- package/skills/wachiman-review/SKILL.md +2 -2
- package/src/call-message.ts +26 -3
- package/src/cli.ts +113 -18
- package/src/config.ts +99 -32
- package/src/connectors/local-git.ts +102 -14
- package/src/cost.ts +48 -1
- package/src/doctor/checks.ts +1 -1
- package/src/engine.ts +910 -89
- 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 +16 -3
- package/src/history/fingerprint.ts +1 -1
- package/src/history/store.ts +44 -6
- package/src/init/options.ts +1 -1
- package/src/ledger.ts +306 -0
- package/src/local.ts +23 -5
- 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 +48 -13
- package/src/providers/codex.ts +8 -7
- package/src/providers/index.ts +6 -3
- package/src/providers/types.ts +13 -3
- package/src/sinks/common.ts +3 -3
- package/src/sinks/json.ts +13 -2
- package/src/skills/install.ts +4 -4
- package/src/status/command.ts +1 -1
- 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/templates/caller-workflow.yml +84 -57
- package/templates/wachiman-review-caller.yml +13 -0
package/src/cli.ts
CHANGED
|
@@ -10,10 +10,14 @@
|
|
|
10
10
|
* when the head was already reviewed
|
|
11
11
|
* wachiman local [paths…] review the committed branch of a clone on the signed-in
|
|
12
12
|
* `claude`, and print it; no GitHub call (src/local.ts)
|
|
13
|
+
* wachiman loop [--base <ref>] one review round of a fix loop on the signed-in `claude`; exit 0
|
|
14
|
+
* converged, 10 findings open, 11 stopped (src/loop/command.ts)
|
|
13
15
|
* wachiman ask [question…] answer a question about the local change, or explain it; one
|
|
14
16
|
* call, no GitHub request, grounded in the stored review (src/local-ask.ts)
|
|
15
17
|
* wachiman history list and judge what `local --history` kept on this laptop
|
|
16
18
|
* wachiman status what the local history kept and its estimated cost; files only
|
|
19
|
+
* wachiman dashboard spend, findings and loops across every repository in the history, as one
|
|
20
|
+
* static HTML file or JSON, from a rebuildable index (src/store/)
|
|
17
21
|
* wachiman setup [--profile <name>] bind this repository to an account profile (home config only);
|
|
18
22
|
* on a terminal without --profile it asks
|
|
19
23
|
* wachiman init write the GitHub caller workflow, or hand over to `setup`
|
|
@@ -23,8 +27,10 @@
|
|
|
23
27
|
* wachiman skills install|uninstall copy the agent skills into place, or remove what was copied
|
|
24
28
|
* wachiman --setup-profile [name] sign in an isolated Claude Code profile under the Wachiman home
|
|
25
29
|
*
|
|
26
|
-
* Exit codes: 0 posted or nothing to do; 1 engine error (nothing posted); 2 usage error;
|
|
27
|
-
*
|
|
30
|
+
* Exit codes: 0 posted or nothing to do; 1 engine error (nothing posted); 2 usage error; 3 the spend
|
|
31
|
+
* ledger stopped the run before any model call (a limit with `limit_mode: fail`, a repository it does
|
|
32
|
+
* not know, a job without an OIDC token, or an unreachable ledger with `ledger_unavailable: stop`);
|
|
33
|
+
* 130 cancelled (`local`, `loop`, `setup`, `init`); `loop` also exits 10 and 11 (see its help).
|
|
28
34
|
* The settings are documented in docs/cli.md.
|
|
29
35
|
*/
|
|
30
36
|
import { existsSync, readFileSync, statSync, writeSync } from "node:fs";
|
|
@@ -33,8 +39,10 @@ import { writeStepSummary, type CallCost } from "./cost";
|
|
|
33
39
|
import { loadConfig, UsageError } from "./config";
|
|
34
40
|
import { historyUsage, parseHistoryArgs, runHistory } from "./history/command";
|
|
35
41
|
import { parseStatusArgs, runStatus, statusUsage } from "./status/command";
|
|
36
|
-
import {
|
|
42
|
+
import { dashboardUsage, parseDashboardArgs, runDashboard } from "./store/command";
|
|
43
|
+
import { LedgerStopped, SpendLimitReached, comment, defaultGh, isThreadQuestion, review, threadReplies, type Deps, type GhFn, type ReviewLineComment } from "./engine";
|
|
37
44
|
import { localUsage, parseLocalArgs, runLocal } from "./local";
|
|
45
|
+
import { loopUsage, parseLoopArgs, runLoop } from "./loop/command";
|
|
38
46
|
import { askUsage, parseAskArgs, runAsk } from "./local-ask";
|
|
39
47
|
import { parseProfileArgs, parseProjectArgs, profileUsage, projectUsage, runProfile, runProject, setupUsage } from "./accounts/commands";
|
|
40
48
|
import { wachimanHome } from "./accounts/config";
|
|
@@ -45,6 +53,7 @@ import { DEFAULT_WORKFLOW_REF } from "./init/options";
|
|
|
45
53
|
import { runInitCommand } from "./init/run";
|
|
46
54
|
import { projectCommands } from "./wizard/command";
|
|
47
55
|
import { DEFAULT_ISOLATED_NAME, setupProfile } from "./profiles";
|
|
56
|
+
import { resetConfidence } from "./fidelity/sink";
|
|
48
57
|
import { getProvider, PROVIDER_NAMES, UnknownProviderError } from "./providers";
|
|
49
58
|
import { parseSetupFlags } from "./setup/args";
|
|
50
59
|
import { runSetupCommand } from "./setup/run";
|
|
@@ -53,11 +62,20 @@ export const USAGE = `Usage:
|
|
|
53
62
|
wachiman review <pr> [paths…] [--repo-dir <dir>] Review a pull request (or only the given paths)
|
|
54
63
|
wachiman comment <pr> [--repo-dir <dir>] Handle the comment in $REQUEST (a review or an answer)
|
|
55
64
|
wachiman threads <pr> [--repo-dir <dir>] Answer the pending Wachiman threads (an automatic run)
|
|
65
|
+
wachiman reset-confidence <pr> [--commit <sha>] Write "cannot say" into the PR Confidence block (no model call;
|
|
66
|
+
the first step of a review run, with WACHIMAN_CONFIDENCE=1)
|
|
56
67
|
${localUsage}
|
|
57
68
|
Review the committed branch of a clone on your
|
|
58
69
|
signed-in claude, and print it; nothing is posted.
|
|
59
70
|
--commit: that one commit (<commit>^ → <commit>);
|
|
60
71
|
--from: that commit forward (<commit>^ → HEAD)
|
|
72
|
+
${loopUsage}
|
|
73
|
+
One round of a review loop on your signed-in claude:
|
|
74
|
+
--base starts it (round 1 reviews the whole range),
|
|
75
|
+
a call with a loop open continues it and reviews only
|
|
76
|
+
the commits since the last round. Fix, or judge a
|
|
77
|
+
finding wrong with a reason, between calls; the CLI
|
|
78
|
+
never edits code. Three rounds by default
|
|
61
79
|
${askUsage}
|
|
62
80
|
Answer a question about the change the scope flags
|
|
63
81
|
select, or explain it when no question is given. One
|
|
@@ -72,6 +90,17 @@ export const USAGE = `Usage:
|
|
|
72
90
|
What this laptop kept of its local runs and their
|
|
73
91
|
estimated cost, filterable; uses local history. GitHub
|
|
74
92
|
Actions runs are not counted
|
|
93
|
+
${dashboardUsage}
|
|
94
|
+
Write one static HTML page (or print JSON) with the
|
|
95
|
+
spend per day and repository, the findings by severity
|
|
96
|
+
and verdict and the loop rounds of every repository in
|
|
97
|
+
the local history. Built from an index under the
|
|
98
|
+
Wachiman home that is rebuilt whenever it is missing or
|
|
99
|
+
out of date. It writes only that index and, without
|
|
100
|
+
--json, the page, and, like \`wachiman history\`, moves
|
|
101
|
+
a damaged run file aside. No claude, no GitHub, no
|
|
102
|
+
network, no server, no browser. --repo-dir is accepted
|
|
103
|
+
and unused
|
|
75
104
|
${setupUsage}
|
|
76
105
|
Bind this repository to an account profile; written
|
|
77
106
|
in the Wachiman home, never in the repository. On a
|
|
@@ -92,7 +121,7 @@ export const USAGE = `Usage:
|
|
|
92
121
|
Claude configuration directory, used in place
|
|
93
122
|
${projectUsage.split("\n").join("\n ")}
|
|
94
123
|
${skillsUsage.split("\n").join("\n ")}
|
|
95
|
-
Copy the wachiman-review and wachiman-audit agent
|
|
124
|
+
Copy the wachiman-review, wachiman-loop and wachiman-audit agent
|
|
96
125
|
skills into ~/.agents/skills and each Claude Code
|
|
97
126
|
config directory; uninstall removes only the copies
|
|
98
127
|
it marked. Never touches ~/.wachiman
|
|
@@ -107,17 +136,23 @@ Options:
|
|
|
107
136
|
|
|
108
137
|
Environment:
|
|
109
138
|
GH_TOKEN, GITHUB_REPOSITORY required (not read by \`local\`, \`ask\` or \`--setup-profile\`)
|
|
110
|
-
ANTHROPIC_API_KEY
|
|
111
|
-
\`local\` and \`ask\` refuse to start when it is set
|
|
139
|
+
ANTHROPIC_API_KEY the claude-code provider needs this or CLAUDE_CODE_OAUTH_TOKEN
|
|
140
|
+
(not in a dry run); \`local\` and \`ask\` refuse to start when it is set
|
|
141
|
+
CLAUDE_CODE_OAUTH_TOKEN a Claude subscription token (\`claude setup-token\`); if set, it is
|
|
142
|
+
used and ANTHROPIC_API_KEY never reaches the agent
|
|
112
143
|
REQUEST the comment text, for \`comment\`
|
|
113
|
-
|
|
114
|
-
|
|
144
|
+
WACHIMAN_COMMENT_AUTHOR the login of the comment's author, for \`comment\` and \`threads\`
|
|
145
|
+
WACHIMAN_* optional settings; see docs/cli.md
|
|
115
146
|
|
|
116
|
-
Exit codes: 0 posted or nothing to do, 1 engine error, 2 usage error
|
|
147
|
+
Exit codes: 0 posted or nothing to do, 1 engine error, 2 usage error, 3 the spend ledger stopped the run
|
|
148
|
+
(a limit with \`limit_mode: fail\`, an unlinked repository, no OIDC token, or an unreachable ledger with
|
|
149
|
+
\`ledger_unavailable: stop\`); with \`limit_mode: notice\` a limit exits 0.
|
|
117
150
|
\`local\`: 0 a report was printed, 1 no call returned a review, 2 usage error, 130 interrupted.
|
|
151
|
+
\`loop\`: 0 converged, 10 findings still open, 11 stopped without converging (round cap or review failed), 2 usage error, 130 interrupted. A stop is never an approval.
|
|
118
152
|
\`ask\`: 0 an answer was printed (it may say what it could not answer), 1 no answer (the call failed or returned nothing usable), 2 usage error, 130 interrupted.
|
|
119
153
|
\`history\`: 0 listed (or nothing to list), 2 usage error, including an unknown finding id.
|
|
120
154
|
\`status\`: 0 printed (also with no run kept), 2 usage error.
|
|
155
|
+
\`dashboard\`: 0 written or printed (also with no run kept), 2 usage error, 1 the index or the page could not be written.
|
|
121
156
|
\`doctor\`: 0 every required check passed, 1 one failed. \`setup\`: 1 when its closing doctor summary failed.
|
|
122
157
|
\`setup\`, \`init\`: 130 cancelled (Escape, Ctrl-C, Ctrl-D); nothing pending is saved.
|
|
123
158
|
\`skills\`: 0 done (copies left in place are warned about), 1 a copy could not be written, 2 usage error or a refused target.
|
|
@@ -129,7 +164,7 @@ export function readVersion(dir = import.meta.dir) {
|
|
|
129
164
|
const path = join(dir, "..", "package.json");
|
|
130
165
|
if (!existsSync(path)) return "unknown";
|
|
131
166
|
const pkg = JSON.parse(readFileSync(path, "utf8"));
|
|
132
|
-
return pkg.name === "wachiman"
|
|
167
|
+
return pkg.name === "wachiman" ? String(pkg.version) : "unknown";
|
|
133
168
|
} catch {
|
|
134
169
|
return "unknown";
|
|
135
170
|
}
|
|
@@ -194,7 +229,7 @@ export function routeMode(mode: string, commentLine: ReviewLineComment | undefin
|
|
|
194
229
|
* comment's text is `REQUEST`.
|
|
195
230
|
*/
|
|
196
231
|
export function readCommentLine(env: Record<string, string | undefined>): ReviewLineComment | undefined {
|
|
197
|
-
const id = env.
|
|
232
|
+
const id = env.WACHIMAN_COMMENT_ID ?? "";
|
|
198
233
|
if (id === "") return undefined;
|
|
199
234
|
const number = (name: string) => {
|
|
200
235
|
const raw = env[name] ?? "";
|
|
@@ -202,12 +237,12 @@ export function readCommentLine(env: Record<string, string | undefined>): Review
|
|
|
202
237
|
if (!/^\d+$/.test(raw)) throw new UsageError(`${name} must be a comment id or a line number, got "${raw}".`);
|
|
203
238
|
return Number(raw);
|
|
204
239
|
};
|
|
205
|
-
if (!/^\d+$/.test(id)) throw new UsageError(`
|
|
240
|
+
if (!/^\d+$/.test(id)) throw new UsageError(`WACHIMAN_COMMENT_ID must be a comment id, got "${id}".`);
|
|
206
241
|
return {
|
|
207
242
|
id: Number(id),
|
|
208
|
-
replyTo: number("
|
|
209
|
-
path: env.
|
|
210
|
-
line: number("
|
|
243
|
+
replyTo: number("WACHIMAN_COMMENT_IN_REPLY_TO"),
|
|
244
|
+
path: env.WACHIMAN_COMMENT_PATH || null,
|
|
245
|
+
line: number("WACHIMAN_COMMENT_LINE"),
|
|
211
246
|
};
|
|
212
247
|
}
|
|
213
248
|
|
|
@@ -247,6 +282,37 @@ async function runWizard(mode: "setup" | "init", args: string[], repoDir: string
|
|
|
247
282
|
});
|
|
248
283
|
}
|
|
249
284
|
|
|
285
|
+
/**
|
|
286
|
+
* `wachiman reset-confidence <pr> [--commit <sha>]`: the first step of a review run (ADR 0033
|
|
287
|
+
* decision 14). It rewrites the PR Confidence block to `cannot say` for the commit under review
|
|
288
|
+
* before the push wait, so a run cancelled during it leaves no letter from an older commit. No
|
|
289
|
+
* model, no provider. A failure inside the reset itself (reading or writing the description) is a
|
|
290
|
+
* warning and the exit code stays 0. A usage or configuration error is not: a bad pull request
|
|
291
|
+
* number or flag, an invalid `WACHIMAN_*` value, or a missing `GH_TOKEN` or
|
|
292
|
+
* `GITHUB_REPOSITORY` exits non-zero. The workflow steps run it with `continue-on-error`.
|
|
293
|
+
*/
|
|
294
|
+
export function runResetConfidence(args: string[], env: Record<string, string | undefined>, gh: GhFn = defaultGh): number {
|
|
295
|
+
const [prArg, ...flags] = args;
|
|
296
|
+
const pr = Number(prArg);
|
|
297
|
+
if (!/^\d+$/.test(prArg ?? "") || pr <= 0) throw new UsageError("reset-confidence needs a pull request number.");
|
|
298
|
+
let commit: string | undefined;
|
|
299
|
+
for (let i = 0; i < flags.length; i++) {
|
|
300
|
+
if (flags[i] !== "--commit" || !flags[i + 1]) throw new UsageError(`reset-confidence: unexpected "${flags[i]}".`);
|
|
301
|
+
commit = flags[++i];
|
|
302
|
+
}
|
|
303
|
+
const config = loadConfig(env);
|
|
304
|
+
if (!config.confidence) return 0;
|
|
305
|
+
required(env, "GH_TOKEN");
|
|
306
|
+
const repo = required(env, "GITHUB_REPOSITORY");
|
|
307
|
+
resetConfidence(
|
|
308
|
+
{ gh, dryRun: config.dryRun, log: (line) => console.log(line), warn: (line) => console.error(line) },
|
|
309
|
+
repo,
|
|
310
|
+
pr,
|
|
311
|
+
commit,
|
|
312
|
+
);
|
|
313
|
+
return 0;
|
|
314
|
+
}
|
|
315
|
+
|
|
250
316
|
export async function main(argv: string[], env: Record<string, string | undefined>): Promise<number> {
|
|
251
317
|
const mode = argv[0];
|
|
252
318
|
if (mode === "--help" || mode === "-h") {
|
|
@@ -281,6 +347,14 @@ export async function main(argv: string[], env: Record<string, string | undefine
|
|
|
281
347
|
engineVersion: readVersion(),
|
|
282
348
|
});
|
|
283
349
|
}
|
|
350
|
+
if (mode === "loop") {
|
|
351
|
+
// Like `local`: no GitHub token, no `gh` function anywhere on this path.
|
|
352
|
+
return runLoop(parseLoopArgs(args.slice(1)), repoDir, env, {
|
|
353
|
+
stdout: (text) => writeAll(1, text),
|
|
354
|
+
stderr: (line) => console.error(line),
|
|
355
|
+
engineVersion: readVersion(),
|
|
356
|
+
});
|
|
357
|
+
}
|
|
284
358
|
if (mode === "ask") {
|
|
285
359
|
// Like `local`: no GitHub token, no `gh` function anywhere on this path.
|
|
286
360
|
return runAsk(parseAskArgs(args.slice(1)), repoDir, env, {
|
|
@@ -298,9 +372,15 @@ export async function main(argv: string[], env: Record<string, string | undefine
|
|
|
298
372
|
if ("help" in parsed) return (writeAll(1, `${statusUsage}\n`), 0);
|
|
299
373
|
return runStatus(parsed, repoDir, env, { stdout: (text) => writeAll(1, text), stderr: (line) => console.error(line), version: readVersion() });
|
|
300
374
|
}
|
|
375
|
+
if (mode === "dashboard") {
|
|
376
|
+
const parsed = parseDashboardArgs(args.slice(1));
|
|
377
|
+
if ("help" in parsed) return (writeAll(1, `${dashboardUsage}\n`), 0);
|
|
378
|
+
return runDashboard(parsed, env, { stdout: (text) => writeAll(1, text), stderr: (line) => console.error(line) });
|
|
379
|
+
}
|
|
301
380
|
if (mode === "history") {
|
|
302
381
|
return runHistory(parseHistoryArgs(args.slice(1)), repoDir, env, { stdout: (text) => writeAll(1, text), stderr: (line) => console.error(line) });
|
|
303
382
|
}
|
|
383
|
+
if (mode === "reset-confidence") return runResetConfidence(args.slice(1), env);
|
|
304
384
|
const [, prArg, ...rest] = args;
|
|
305
385
|
if (mode !== "review" && mode !== "comment" && mode !== "threads") {
|
|
306
386
|
throw new UsageError(mode ? `Unknown command "${mode}".` : "No command given.");
|
|
@@ -326,8 +406,10 @@ export async function main(argv: string[], env: Record<string, string | undefine
|
|
|
326
406
|
const repo = required(env, "GITHUB_REPOSITORY");
|
|
327
407
|
const request = effective === "comment" ? required(env, "REQUEST") : "";
|
|
328
408
|
const costs: CallCost[] = [];
|
|
409
|
+
const ledgerNotes: string[] = [];
|
|
329
410
|
const deps: Deps = {
|
|
330
411
|
costs,
|
|
412
|
+
ledgerNotes,
|
|
331
413
|
gh: defaultGh,
|
|
332
414
|
provider,
|
|
333
415
|
...(verifier ? { verifier } : {}),
|
|
@@ -347,11 +429,11 @@ export async function main(argv: string[], env: Record<string, string | undefine
|
|
|
347
429
|
}
|
|
348
430
|
try {
|
|
349
431
|
if (effective === "review") review(deps, repo, pr, rest);
|
|
350
|
-
else if (effective === "threads") threadReplies(deps, repo, pr, env.
|
|
351
|
-
else comment(deps, repo, pr, request, env.
|
|
432
|
+
else if (effective === "threads") threadReplies(deps, repo, pr, env.WACHIMAN_COMMENT_AUTHOR || undefined);
|
|
433
|
+
else comment(deps, repo, pr, request, env.WACHIMAN_COMMENT_AUTHOR || undefined, commentLine);
|
|
352
434
|
} finally {
|
|
353
435
|
// Also after a failed run: the calls it made were paid for.
|
|
354
|
-
writeStepSummary(costs, env);
|
|
436
|
+
writeStepSummary(costs, env, undefined, ledgerNotes);
|
|
355
437
|
}
|
|
356
438
|
return 0;
|
|
357
439
|
} catch (error) {
|
|
@@ -359,6 +441,19 @@ export async function main(argv: string[], env: Record<string, string | undefine
|
|
|
359
441
|
console.error(`wachiman: ${error.message}\n\n${USAGE}`);
|
|
360
442
|
return 2;
|
|
361
443
|
}
|
|
444
|
+
if (error instanceof SpendLimitReached) {
|
|
445
|
+
// The notice is already posted. `notice` mode keeps the job green.
|
|
446
|
+
if (error.mode === "notice") {
|
|
447
|
+
console.log(`wachiman: spend limit reached: ${error.message}`);
|
|
448
|
+
return 0;
|
|
449
|
+
}
|
|
450
|
+
console.error(`wachiman: spend limit reached: ${error.message}`);
|
|
451
|
+
return 3;
|
|
452
|
+
}
|
|
453
|
+
if (error instanceof LedgerStopped) {
|
|
454
|
+
console.error(`wachiman: ledger: ${error.message}`);
|
|
455
|
+
return 3;
|
|
456
|
+
}
|
|
362
457
|
console.error(`wachiman: ${error instanceof Error ? error.message : error}`);
|
|
363
458
|
return 1;
|
|
364
459
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** The `
|
|
1
|
+
/** The `WACHIMAN_*` settings, read once, with the old `CLAUDE_REVIEW_*` names as a fallback. */
|
|
2
2
|
import { DEFAULT_MODELS } from "./providers";
|
|
3
3
|
import { DEFAULT_CALL_TIMEOUT_S, DEFAULT_EFFORT, DEFAULT_MAX_TURNS, EFFORTS, type Effort } from "./providers/types";
|
|
4
4
|
|
|
@@ -14,19 +14,43 @@ export type Trigger = string;
|
|
|
14
14
|
/** Whether a run started by `trigger` spends from the pull request's automatic ceiling. */
|
|
15
15
|
export const isAutomatic = (trigger: Trigger | undefined) => trigger !== undefined && trigger !== "comment";
|
|
16
16
|
|
|
17
|
+
export type LimitMode = "fail" | "notice";
|
|
18
|
+
export type LedgerUnavailableMode = "run" | "stop";
|
|
19
|
+
|
|
17
20
|
export interface EngineConfig {
|
|
18
21
|
/** Total per review invocation, USD. */
|
|
19
22
|
budgetUsd: number;
|
|
20
23
|
/**
|
|
21
|
-
* `
|
|
24
|
+
* `WACHIMAN_AUTO_BUDGET_USD`: the most all automatic runs on one pull request may spend
|
|
22
25
|
* together (the first review, push reviews, thread runs), summed from the engine's own signed
|
|
23
26
|
* footers. The operator's `comment` is not limited by it.
|
|
24
27
|
*/
|
|
25
28
|
autoBudgetUsd: number;
|
|
26
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* `WACHIMAN_SIZE_GATE_USD`: the most a review's estimate may be before a GitHub run skips it
|
|
31
|
+
* and posts one comment instead. The effective gate is never below what the run may spend
|
|
32
|
+
* (`sizeGate` in estimate.ts), so raising the budgets lifts it. Local runs only warn.
|
|
33
|
+
*/
|
|
34
|
+
sizeGateUsd: number;
|
|
35
|
+
/**
|
|
36
|
+
* `WACHIMAN_LEDGER_URL`: the spend ledger service, trimmed, without a trailing slash. Unset
|
|
37
|
+
* means no ledger call of any kind. It is also the OIDC audience, as configured.
|
|
38
|
+
*/
|
|
39
|
+
ledgerUrl?: string;
|
|
40
|
+
/** `WACHIMAN_DAILY_BUDGET_USD`: a stricter daily number for this repository; it never raises the account's limit. */
|
|
41
|
+
dailyBudgetUsd?: number;
|
|
42
|
+
/** `WACHIMAN_WEEKLY_BUDGET_USD`: the same, per week. */
|
|
43
|
+
weeklyBudgetUsd?: number;
|
|
44
|
+
/** `WACHIMAN_LIMIT_MODE`: when a limit refuses a run, `fail` exits 3 (red job); `notice` posts the comment and passes. */
|
|
45
|
+
limitMode: LimitMode;
|
|
46
|
+
/** `WACHIMAN_LIMIT_BYPASS`: `1` or `true` skips the ledger for this run. */
|
|
47
|
+
limitBypass: boolean;
|
|
48
|
+
/** `WACHIMAN_LEDGER_UNAVAILABLE`: with an unreachable ledger, `run` reviews anyway (and says so); `stop` exits 3 before any model call. */
|
|
49
|
+
ledgerUnavailable: LedgerUnavailableMode;
|
|
50
|
+
/** `WACHIMAN_THREADS_BUDGET_USD`: the one provider call of a thread-only run. */
|
|
27
51
|
threadsBudgetUsd: number;
|
|
28
52
|
/**
|
|
29
|
-
* `
|
|
53
|
+
* `WACHIMAN_TRIGGER`: why this run started (see `Trigger`). Unset means a person ran the
|
|
30
54
|
* CLI by hand: not automatic, so the ceiling does not apply. `comment` mode ignores it.
|
|
31
55
|
*/
|
|
32
56
|
trigger?: Trigger;
|
|
@@ -36,32 +60,32 @@ export interface EngineConfig {
|
|
|
36
60
|
batchChars: number;
|
|
37
61
|
dryRun: boolean;
|
|
38
62
|
/**
|
|
39
|
-
* `
|
|
63
|
+
* `WACHIMAN_FULL_REVIEW`: a dry run reviews the whole pull request, as if it had never been
|
|
40
64
|
* reviewed, without reading the previous-review marker. Only together with `dryRun`.
|
|
41
65
|
*/
|
|
42
66
|
fullReview: boolean;
|
|
43
67
|
/** The provider's default (`DEFAULT_MODELS`) when unset. */
|
|
44
68
|
model: string;
|
|
45
69
|
provider: string;
|
|
46
|
-
/** `
|
|
70
|
+
/** `WACHIMAN_PRICE_PER_MTOK`: "input,cached_input,output" USD per million tokens, for a Codex model without a built-in price. */
|
|
47
71
|
pricePerMTok?: string;
|
|
48
72
|
/**
|
|
49
|
-
* `
|
|
73
|
+
* `WACHIMAN_EFFORT`: the reasoning effort, always explicit so a CLI default change cannot
|
|
50
74
|
* alter reviews. Passed as `--effort` (Claude Code) or `model_reasoning_effort` (Codex).
|
|
51
75
|
*/
|
|
52
76
|
effort: Effort;
|
|
53
77
|
/**
|
|
54
|
-
* `
|
|
78
|
+
* `WACHIMAN_MAX_TURNS`: the most agent turns one provider call may take. Passed as
|
|
55
79
|
* `--max-turns` (Claude Code); Codex has no equivalent and ignores it.
|
|
56
80
|
*/
|
|
57
81
|
maxTurns: number;
|
|
58
82
|
/**
|
|
59
|
-
* `
|
|
83
|
+
* `WACHIMAN_CALL_TIMEOUT_S`: wall-clock limit on one provider call, in seconds. The call is
|
|
60
84
|
* killed when it passes and ends as `timeout`.
|
|
61
85
|
*/
|
|
62
86
|
callTimeoutS: number;
|
|
63
87
|
/**
|
|
64
|
-
* `
|
|
88
|
+
* `WACHIMAN_ON_PROVIDER_UNAVAILABLE`: what a run does when the provider rejects every call
|
|
65
89
|
* because the reviewer's own account cannot pay or authenticate (or stays rate-limited). `warn`
|
|
66
90
|
* posts a notice and finishes green; `fail` posts it and fails the job.
|
|
67
91
|
*/
|
|
@@ -70,64 +94,71 @@ export interface EngineConfig {
|
|
|
70
94
|
/** Login allowed to command the tool. `comment` refuses to run when it is empty or a placeholder. */
|
|
71
95
|
operator: string;
|
|
72
96
|
/**
|
|
73
|
-
* `
|
|
97
|
+
* `WACHIMAN_ASKERS`: who may ask a question (ADR 0032 decision 5). `operator` (default): only
|
|
74
98
|
* the operator. `write`: also a collaborator whose permission on the repository is admin,
|
|
75
99
|
* maintain or write, checked by the engine on each question. Reviews stay operator-only.
|
|
76
100
|
*/
|
|
77
101
|
askers: "operator" | "write";
|
|
78
102
|
/**
|
|
79
|
-
* `
|
|
103
|
+
* `WACHIMAN_ASK_CEILING_USD`: the most the questions of everyone but the operator may spend
|
|
80
104
|
* on one pull request, summed from the engine's own footers. The operator's questions are not limited.
|
|
81
105
|
*/
|
|
82
106
|
askCeilingUsd: number;
|
|
83
107
|
/** Extra exclude globs on top of the built-in ones. */
|
|
84
108
|
exclude: string[];
|
|
85
109
|
/**
|
|
86
|
-
* `
|
|
110
|
+
* `WACHIMAN_VERIFY`: after the batches, one more call tries to refute every finding above
|
|
87
111
|
* `info` before it is posted (ADR 0027). Off by default; enabled only by `1` or `true`.
|
|
88
112
|
*/
|
|
89
113
|
verify: boolean;
|
|
90
|
-
/** `
|
|
114
|
+
/** `WACHIMAN_VERIFY_BUDGET_USD`: the verifier's reserve, taken out of `budgetUsd` (at most half of it). */
|
|
91
115
|
verifyBudgetUsd: number;
|
|
92
|
-
/** `
|
|
116
|
+
/** `WACHIMAN_VERIFIER_MODEL`: the verifier's model; it always runs at effort `high`. */
|
|
93
117
|
verifierModel: string;
|
|
118
|
+
/**
|
|
119
|
+
* `WACHIMAN_CONFIDENCE`: PR Confidence (ADR 0033). A full review of a pull request lists the
|
|
120
|
+
* claims in its title and body with one more small call, grades the change against them and
|
|
121
|
+
* writes the grade into the description. Off by default; enabled only by `1` or `true`. Read by
|
|
122
|
+
* the pull request review only: `wachiman local` never grades.
|
|
123
|
+
*/
|
|
124
|
+
confidence: boolean;
|
|
94
125
|
}
|
|
95
126
|
|
|
96
|
-
/** The verifier's model when `
|
|
127
|
+
/** The verifier's model when `WACHIMAN_VERIFIER_MODEL` is unset (Claude Code only). */
|
|
97
128
|
export const DEFAULT_VERIFIER_MODEL = "claude-opus-5-5";
|
|
98
129
|
|
|
99
130
|
type Env = Record<string, string | undefined>;
|
|
100
131
|
|
|
101
132
|
/**
|
|
102
|
-
* `
|
|
133
|
+
* `WACHIMAN_<name>`, else the deprecated `CLAUDE_REVIEW_<name>` (with a one-line notice on
|
|
103
134
|
* stderr), else undefined. An empty value counts as unset.
|
|
104
135
|
*/
|
|
105
136
|
export function readSetting(env: Env, name: string, warn: (line: string) => void) {
|
|
106
|
-
const current = env[`
|
|
137
|
+
const current = env[`WACHIMAN_${name}`];
|
|
107
138
|
if (current !== undefined && current !== "") return current;
|
|
108
139
|
const old = env[`CLAUDE_REVIEW_${name}`];
|
|
109
140
|
if (old !== undefined && old !== "") {
|
|
110
|
-
warn(`CLAUDE_REVIEW_${name} is deprecated; use
|
|
141
|
+
warn(`CLAUDE_REVIEW_${name} is deprecated; use WACHIMAN_${name}.`);
|
|
111
142
|
return old;
|
|
112
143
|
}
|
|
113
144
|
return undefined;
|
|
114
145
|
}
|
|
115
146
|
|
|
116
147
|
/**
|
|
117
|
-
* `
|
|
148
|
+
* `WACHIMAN_EFFORT`, else the deprecated `WACHIMAN_REASONING_EFFORT` (Codex only before),
|
|
118
149
|
* else the default. An unknown value is a configuration error: a silent fallback would run the
|
|
119
150
|
* review at an effort nobody chose.
|
|
120
151
|
*/
|
|
121
152
|
function readEffort(env: Env, warn: (line: string) => void): Effort {
|
|
122
153
|
const current = readSetting(env, "EFFORT", warn);
|
|
123
154
|
const old = readSetting(env, "REASONING_EFFORT", () => {});
|
|
124
|
-
let name = "
|
|
155
|
+
let name = "WACHIMAN_EFFORT";
|
|
125
156
|
let raw = current;
|
|
126
157
|
if (old !== undefined) {
|
|
127
|
-
warn("
|
|
158
|
+
warn("WACHIMAN_REASONING_EFFORT is deprecated; use WACHIMAN_EFFORT.");
|
|
128
159
|
if (raw === undefined) {
|
|
129
160
|
raw = old;
|
|
130
|
-
name = "
|
|
161
|
+
name = "WACHIMAN_REASONING_EFFORT";
|
|
131
162
|
}
|
|
132
163
|
}
|
|
133
164
|
if (raw === undefined) return DEFAULT_EFFORT;
|
|
@@ -144,44 +175,73 @@ export function loadConfig(env: Env, warn: (line: string) => void = console.erro
|
|
|
144
175
|
if (raw === undefined) return fallback;
|
|
145
176
|
const value = Number(raw);
|
|
146
177
|
if (!Number.isFinite(value) || value <= 0 || (integer && !Number.isInteger(value))) {
|
|
147
|
-
throw new UsageError(`
|
|
178
|
+
throw new UsageError(`WACHIMAN_${name} must be a positive ${integer ? "integer" : "number"}, got "${raw}".`);
|
|
148
179
|
}
|
|
149
180
|
return value;
|
|
150
181
|
};
|
|
151
182
|
const effort = readEffort(env, warn);
|
|
152
183
|
const onProviderUnavailable = get("ON_PROVIDER_UNAVAILABLE") ?? "warn";
|
|
153
184
|
if (onProviderUnavailable !== "warn" && onProviderUnavailable !== "fail") {
|
|
154
|
-
throw new UsageError(`
|
|
185
|
+
throw new UsageError(`WACHIMAN_ON_PROVIDER_UNAVAILABLE must be warn or fail, got "${onProviderUnavailable}".`);
|
|
155
186
|
}
|
|
156
187
|
const provider = get("PROVIDER") ?? "claude-code";
|
|
157
188
|
const dryRun = get("DRY_RUN") === "1";
|
|
158
189
|
const fullReview = get("FULL_REVIEW") === "1";
|
|
159
190
|
if (fullReview && !dryRun) {
|
|
160
191
|
throw new UsageError(
|
|
161
|
-
"
|
|
192
|
+
"WACHIMAN_FULL_REVIEW=1 works only with WACHIMAN_DRY_RUN=1: a full review ignores the previous-review marker, so it is printed, never posted.",
|
|
162
193
|
);
|
|
163
194
|
}
|
|
164
195
|
const verifyRaw = get("VERIFY");
|
|
165
196
|
if (verifyRaw !== undefined && verifyRaw !== "0" && verifyRaw !== "1" && verifyRaw !== "true" && verifyRaw !== "false") {
|
|
166
|
-
throw new UsageError(`
|
|
197
|
+
throw new UsageError(`WACHIMAN_VERIFY must be 1, true, 0 or false (unset means off), got "${verifyRaw}".`);
|
|
167
198
|
}
|
|
168
199
|
const verifierModel = get("VERIFIER_MODEL") ?? (provider === "claude-code" ? DEFAULT_VERIFIER_MODEL : undefined);
|
|
169
200
|
// Verification is opt-in, including when a verifier model is configured.
|
|
170
201
|
const verify = verifyRaw === "1" || verifyRaw === "true";
|
|
171
202
|
if (verify && verifierModel === undefined) {
|
|
172
|
-
throw new UsageError(`
|
|
203
|
+
throw new UsageError(`WACHIMAN_VERIFY needs WACHIMAN_VERIFIER_MODEL with the ${provider} provider: the default verifier is a Claude model.`);
|
|
204
|
+
}
|
|
205
|
+
const confidenceRaw = get("CONFIDENCE");
|
|
206
|
+
if (confidenceRaw !== undefined && !["0", "1", "true", "false"].includes(confidenceRaw)) {
|
|
207
|
+
throw new UsageError(`WACHIMAN_CONFIDENCE must be 1, true, 0 or false (unset means off), got "${confidenceRaw}".`);
|
|
173
208
|
}
|
|
174
209
|
const askers = get("ASKERS") ?? "operator";
|
|
175
210
|
if (askers !== "operator" && askers !== "write") {
|
|
176
|
-
throw new UsageError(`
|
|
211
|
+
throw new UsageError(`WACHIMAN_ASKERS must be operator or write, got "${askers}".`);
|
|
177
212
|
}
|
|
178
213
|
const trigger = get("TRIGGER")?.trim();
|
|
179
214
|
if (trigger !== undefined && !/^[a-z_]+$/.test(trigger)) {
|
|
180
|
-
throw new UsageError(`
|
|
215
|
+
throw new UsageError(`WACHIMAN_TRIGGER must be a lowercase event action such as synchronize, got "${trigger}".`);
|
|
216
|
+
}
|
|
217
|
+
const limitMode = get("LIMIT_MODE") ?? "fail";
|
|
218
|
+
if (limitMode !== "fail" && limitMode !== "notice") {
|
|
219
|
+
throw new UsageError(`WACHIMAN_LIMIT_MODE must be fail or notice, got "${limitMode}".`);
|
|
220
|
+
}
|
|
221
|
+
const ledgerUnavailable = get("LEDGER_UNAVAILABLE") ?? "run";
|
|
222
|
+
if (ledgerUnavailable !== "run" && ledgerUnavailable !== "stop") {
|
|
223
|
+
throw new UsageError(`WACHIMAN_LEDGER_UNAVAILABLE must be run or stop, got "${ledgerUnavailable}".`);
|
|
224
|
+
}
|
|
225
|
+
const bypass = get("LIMIT_BYPASS")?.trim();
|
|
226
|
+
const ledgerUrl = get("LEDGER_URL")?.trim().replace(/\/+$/, "") || undefined;
|
|
227
|
+
// The job's OIDC token is sent to this address: never over cleartext, except to the local machine for tests.
|
|
228
|
+
if (ledgerUrl !== undefined && !/^https:\/\/\S/i.test(ledgerUrl) && !/^http:\/\/(localhost|127\.0\.0\.1)(?=[:/]|$)/i.test(ledgerUrl)) {
|
|
229
|
+
throw new UsageError(
|
|
230
|
+
`WACHIMAN_LEDGER_URL must start with https:// (http://localhost and http://127.0.0.1 are allowed for tests), got "${ledgerUrl}".`,
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
// With a ledger, `review-platform.yml` grants `id-token: write`, so the request token is in the
|
|
234
|
+
// engine's environment; a Codex sandbox could read it from /proc and mint tokens as this job.
|
|
235
|
+
// Without `ledger_url` nothing uses the token and the guard does not apply.
|
|
236
|
+
if (ledgerUrl !== undefined && provider !== "claude-code" && env.ACTIONS_ID_TOKEN_REQUEST_TOKEN !== undefined) {
|
|
237
|
+
throw new UsageError(
|
|
238
|
+
`WACHIMAN_PROVIDER ${provider} cannot run in a job that holds an OIDC request token: its sandbox can read it from the engine's environment. Use claude-code, or call review.yml instead of review-platform.yml.`,
|
|
239
|
+
);
|
|
181
240
|
}
|
|
182
241
|
return {
|
|
183
242
|
budgetUsd: number("BUDGET_USD", 3),
|
|
184
243
|
autoBudgetUsd: number("AUTO_BUDGET_USD", 6),
|
|
244
|
+
sizeGateUsd: number("SIZE_GATE_USD", 6),
|
|
185
245
|
threadsBudgetUsd: number("THREADS_BUDGET_USD", 0.25),
|
|
186
246
|
trigger: trigger || undefined,
|
|
187
247
|
batchBudgetUsd: number("BATCH_BUDGET_USD", 0.75),
|
|
@@ -205,6 +265,13 @@ export function loadConfig(env: Env, warn: (line: string) => void = console.erro
|
|
|
205
265
|
verify,
|
|
206
266
|
verifyBudgetUsd: number("VERIFY_BUDGET_USD", 1),
|
|
207
267
|
verifierModel: verifierModel ?? DEFAULT_VERIFIER_MODEL,
|
|
268
|
+
confidence: confidenceRaw === "1" || confidenceRaw === "true",
|
|
269
|
+
ledgerUrl,
|
|
270
|
+
dailyBudgetUsd: get("DAILY_BUDGET_USD") === undefined ? undefined : number("DAILY_BUDGET_USD", 0),
|
|
271
|
+
weeklyBudgetUsd: get("WEEKLY_BUDGET_USD") === undefined ? undefined : number("WEEKLY_BUDGET_USD", 0),
|
|
272
|
+
limitMode,
|
|
273
|
+
limitBypass: bypass === "1" || bypass === "true",
|
|
274
|
+
ledgerUnavailable,
|
|
208
275
|
};
|
|
209
276
|
}
|
|
210
277
|
|
|
@@ -218,10 +285,10 @@ const PLACEHOLDER_OPERATORS = ["your-github-login"];
|
|
|
218
285
|
*/
|
|
219
286
|
export function operatorProblem(operator: string | undefined): string | undefined {
|
|
220
287
|
const login = (operator ?? "").trim();
|
|
221
|
-
if (login === "") return "The operator login is empty. Set `operator` (
|
|
288
|
+
if (login === "") return "The operator login is empty. Set `operator` (WACHIMAN_OPERATOR) to your GitHub login.";
|
|
222
289
|
const lower = login.toLowerCase();
|
|
223
290
|
if (lower.startsWith("edit") || PLACEHOLDER_OPERATORS.includes(lower)) {
|
|
224
|
-
return `The operator login is still the template placeholder "${login}". Set \`operator\` (
|
|
291
|
+
return `The operator login is still the template placeholder "${login}". Set \`operator\` (WACHIMAN_OPERATOR) to your GitHub login.`;
|
|
225
292
|
}
|
|
226
293
|
return undefined;
|
|
227
294
|
}
|