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/call-message.ts
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* scripts parse. The JSON stays the contract; this line is for the person reading the log.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { isEstimate } from "./cost";
|
|
6
7
|
import type { ProviderErrorClass } from "./providers/errors";
|
|
8
|
+
import type { ProviderAuth } from "./providers/types";
|
|
7
9
|
|
|
8
10
|
export interface CallSummary {
|
|
9
11
|
/** Which call: `batch 1/2`, `threads`, `question`. */
|
|
@@ -15,6 +17,8 @@ export interface CallSummary {
|
|
|
15
17
|
durationMs: number;
|
|
16
18
|
providerError?: ProviderErrorClass;
|
|
17
19
|
errorText?: string;
|
|
20
|
+
/** What paid for the call; absent means `api-key`. */
|
|
21
|
+
credential?: ProviderAuth;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
const MAX_TEXT = 300;
|
|
@@ -29,18 +33,37 @@ const turnsText = (n: number) => `${n} turn${n === 1 ? "" : "s"}`;
|
|
|
29
33
|
const seconds = (ms: number) => `${(ms / 1000).toFixed(1)} s`;
|
|
30
34
|
const dollars = (usd: number) => `$${usd.toFixed(2)}`;
|
|
31
35
|
|
|
36
|
+
/** The messages for a call refused on a subscription token: its credential is not an API key, so nothing here names one. */
|
|
37
|
+
function describeTokenRefusal(head: string, providerError: ProviderErrorClass | undefined, api: string): string | undefined {
|
|
38
|
+
switch (providerError) {
|
|
39
|
+
case "auth":
|
|
40
|
+
return `❌ ${head}: Claude refused the call: the subscription token was rejected. Check the CLAUDE_CODE_OAUTH_TOKEN secret (a token lasts a year; make a new one with \`claude setup-token\`).${api}`;
|
|
41
|
+
case "billing":
|
|
42
|
+
return `❌ ${head}: Claude refused the call: the subscription's usage limit or plan access stopped it. Wait for the limit to reset, then re-run this job; the review does not fall back to an API key.${api}`;
|
|
43
|
+
case "rate_limit":
|
|
44
|
+
return `⏳ ${head}: Claude rate-limited the call. This is usually temporary.${api}`;
|
|
45
|
+
default:
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
32
50
|
export function describeCall(call: CallSummary): string {
|
|
33
51
|
const head = call.label;
|
|
52
|
+
const estimate = isEstimate(call.credential);
|
|
34
53
|
if (!call.isError && call.terminalReason === "success")
|
|
35
|
-
return `✅ ${head}: finished in ${turnsText(call.turns)}, ${seconds(call.durationMs)}, ${dollars(call.costUsd)}.`;
|
|
54
|
+
return `✅ ${head}: finished in ${turnsText(call.turns)}, ${seconds(call.durationMs)}, ${dollars(call.costUsd)}${estimate ? " (API-price estimate)" : ""}.`;
|
|
36
55
|
if (call.terminalReason === "budget")
|
|
37
|
-
return `💸 ${head}: stopped at its budget after ${turnsText(call.turns)}, ${dollars(call.costUsd)}.`;
|
|
56
|
+
return `💸 ${head}: stopped at its budget after ${turnsText(call.turns)}, ${dollars(call.costUsd)}${estimate ? " (API-price estimate)" : ""}.`;
|
|
38
57
|
if (call.terminalReason === "turns")
|
|
39
|
-
return `⏹️ ${head}: hit the turn limit after ${turnsText(call.turns)}, ${dollars(call.costUsd)}.`;
|
|
58
|
+
return `⏹️ ${head}: hit the turn limit after ${turnsText(call.turns)}, ${dollars(call.costUsd)}${estimate ? " (API-price estimate)" : ""}.`;
|
|
40
59
|
if (call.terminalReason === "timeout") return `⏱️ ${head}: killed at the time limit after ${seconds(call.durationMs)}.`;
|
|
41
60
|
|
|
42
61
|
const said = quoted(call.errorText);
|
|
43
62
|
const api = said ? ` API said: ${said}` : "";
|
|
63
|
+
if (call.credential === "oauth-token") {
|
|
64
|
+
const line = describeTokenRefusal(head, call.providerError, api);
|
|
65
|
+
if (line) return line;
|
|
66
|
+
}
|
|
44
67
|
switch (call.providerError) {
|
|
45
68
|
case "billing":
|
|
46
69
|
return `❌ ${head}: the Anthropic API refused the call: the account has no credit. Top up, then re-run this job.${api}`;
|
package/src/cli.ts
CHANGED
|
@@ -10,7 +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)
|
|
15
|
+
* wachiman ask [question…] answer a question about the local change, or explain it; one
|
|
16
|
+
* call, no GitHub request, grounded in the stored review (src/local-ask.ts)
|
|
13
17
|
* wachiman history list and judge what `local --history` kept on this laptop
|
|
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/)
|
|
14
21
|
* wachiman setup [--profile <name>] bind this repository to an account profile (home config only);
|
|
15
22
|
* on a terminal without --profile it asks
|
|
16
23
|
* wachiman init write the GitHub caller workflow, or hand over to `setup`
|
|
@@ -21,7 +28,7 @@
|
|
|
21
28
|
* wachiman --setup-profile [name] sign in an isolated Claude Code profile under the Wachiman home
|
|
22
29
|
*
|
|
23
30
|
* Exit codes: 0 posted or nothing to do; 1 engine error (nothing posted); 2 usage error;
|
|
24
|
-
* 130 cancelled (`local`, `setup`, `init`).
|
|
31
|
+
* 130 cancelled (`local`, `loop`, `setup`, `init`); `loop` also exits 10 and 11 (see its help).
|
|
25
32
|
* The settings are documented in docs/cli.md.
|
|
26
33
|
*/
|
|
27
34
|
import { existsSync, readFileSync, statSync, writeSync } from "node:fs";
|
|
@@ -29,8 +36,12 @@ import { join, resolve } from "node:path";
|
|
|
29
36
|
import { writeStepSummary, type CallCost } from "./cost";
|
|
30
37
|
import { loadConfig, UsageError } from "./config";
|
|
31
38
|
import { historyUsage, parseHistoryArgs, runHistory } from "./history/command";
|
|
32
|
-
import {
|
|
39
|
+
import { parseStatusArgs, runStatus, statusUsage } from "./status/command";
|
|
40
|
+
import { dashboardUsage, parseDashboardArgs, runDashboard } from "./store/command";
|
|
41
|
+
import { comment, defaultGh, isThreadQuestion, review, threadReplies, type Deps, type GhFn, type ReviewLineComment } from "./engine";
|
|
33
42
|
import { localUsage, parseLocalArgs, runLocal } from "./local";
|
|
43
|
+
import { loopUsage, parseLoopArgs, runLoop } from "./loop/command";
|
|
44
|
+
import { askUsage, parseAskArgs, runAsk } from "./local-ask";
|
|
34
45
|
import { parseProfileArgs, parseProjectArgs, profileUsage, projectUsage, runProfile, runProject, setupUsage } from "./accounts/commands";
|
|
35
46
|
import { wachimanHome } from "./accounts/config";
|
|
36
47
|
import { parseSkillsArgs, runSkills, skillsUsage } from "./skills/install";
|
|
@@ -38,7 +49,9 @@ import { doctorUsage, parseDoctorArgs, runDoctor } from "./doctor/run";
|
|
|
38
49
|
import { initUsage, parseInitFlags } from "./init/args";
|
|
39
50
|
import { DEFAULT_WORKFLOW_REF } from "./init/options";
|
|
40
51
|
import { runInitCommand } from "./init/run";
|
|
52
|
+
import { projectCommands } from "./wizard/command";
|
|
41
53
|
import { DEFAULT_ISOLATED_NAME, setupProfile } from "./profiles";
|
|
54
|
+
import { resetConfidence } from "./fidelity/sink";
|
|
42
55
|
import { getProvider, PROVIDER_NAMES, UnknownProviderError } from "./providers";
|
|
43
56
|
import { parseSetupFlags } from "./setup/args";
|
|
44
57
|
import { runSetupCommand } from "./setup/run";
|
|
@@ -47,15 +60,45 @@ export const USAGE = `Usage:
|
|
|
47
60
|
wachiman review <pr> [paths…] [--repo-dir <dir>] Review a pull request (or only the given paths)
|
|
48
61
|
wachiman comment <pr> [--repo-dir <dir>] Handle the comment in $REQUEST (a review or an answer)
|
|
49
62
|
wachiman threads <pr> [--repo-dir <dir>] Answer the pending Wachiman threads (an automatic run)
|
|
63
|
+
wachiman reset-confidence <pr> [--commit <sha>] Write "cannot say" into the PR Confidence block (no model call;
|
|
64
|
+
the first step of a review run, with AGENT_REVIEW_CONFIDENCE=1)
|
|
50
65
|
${localUsage}
|
|
51
66
|
Review the committed branch of a clone on your
|
|
52
67
|
signed-in claude, and print it; nothing is posted.
|
|
53
68
|
--commit: that one commit (<commit>^ → <commit>);
|
|
54
69
|
--from: that commit forward (<commit>^ → HEAD)
|
|
70
|
+
${loopUsage}
|
|
71
|
+
One round of a review loop on your signed-in claude:
|
|
72
|
+
--base starts it (round 1 reviews the whole range),
|
|
73
|
+
a call with a loop open continues it and reviews only
|
|
74
|
+
the commits since the last round. Fix, or judge a
|
|
75
|
+
finding wrong with a reason, between calls; the CLI
|
|
76
|
+
never edits code. Three rounds by default
|
|
77
|
+
${askUsage}
|
|
78
|
+
Answer a question about the change the scope flags
|
|
79
|
+
select, or explain it when no question is given. One
|
|
80
|
+
call on your signed-in claude; no GitHub request.
|
|
81
|
+
Grounded in the stored review of this change when
|
|
82
|
+
\`local --history\` kept one; never runs a review
|
|
55
83
|
${historyUsage}
|
|
56
84
|
List, judge and forget the findings kept by
|
|
57
85
|
\`local --history\`; reads files and local git
|
|
58
86
|
metadata only: no claude, no GitHub
|
|
87
|
+
${statusUsage}
|
|
88
|
+
What this laptop kept of its local runs and their
|
|
89
|
+
estimated cost, filterable; uses local history. GitHub
|
|
90
|
+
Actions runs are not counted
|
|
91
|
+
${dashboardUsage}
|
|
92
|
+
Write one static HTML page (or print JSON) with the
|
|
93
|
+
spend per day and repository, the findings by severity
|
|
94
|
+
and verdict and the loop rounds of every repository in
|
|
95
|
+
the local history. Built from an index under the
|
|
96
|
+
Wachiman home that is rebuilt whenever it is missing or
|
|
97
|
+
out of date. It writes only that index and, without
|
|
98
|
+
--json, the page, and, like \`wachiman history\`, moves
|
|
99
|
+
a damaged run file aside. No claude, no GitHub, no
|
|
100
|
+
network, no server, no browser. --repo-dir is accepted
|
|
101
|
+
and unused
|
|
59
102
|
${setupUsage}
|
|
60
103
|
Bind this repository to an account profile; written
|
|
61
104
|
in the Wachiman home, never in the repository. On a
|
|
@@ -76,7 +119,7 @@ export const USAGE = `Usage:
|
|
|
76
119
|
Claude configuration directory, used in place
|
|
77
120
|
${projectUsage.split("\n").join("\n ")}
|
|
78
121
|
${skillsUsage.split("\n").join("\n ")}
|
|
79
|
-
Copy the wachiman-review and wachiman-audit agent
|
|
122
|
+
Copy the wachiman-review, wachiman-loop and wachiman-audit agent
|
|
80
123
|
skills into ~/.agents/skills and each Claude Code
|
|
81
124
|
config directory; uninstall removes only the copies
|
|
82
125
|
it marked. Never touches ~/.wachiman
|
|
@@ -90,16 +133,22 @@ Options:
|
|
|
90
133
|
For \`local\`: the clone whose branch is reviewed.
|
|
91
134
|
|
|
92
135
|
Environment:
|
|
93
|
-
GH_TOKEN, GITHUB_REPOSITORY required (not read by \`local\` or \`--setup-profile\`)
|
|
94
|
-
ANTHROPIC_API_KEY
|
|
95
|
-
\`local\`
|
|
136
|
+
GH_TOKEN, GITHUB_REPOSITORY required (not read by \`local\`, \`ask\` or \`--setup-profile\`)
|
|
137
|
+
ANTHROPIC_API_KEY the claude-code provider needs this or CLAUDE_CODE_OAUTH_TOKEN
|
|
138
|
+
(not in a dry run); \`local\` and \`ask\` refuse to start when it is set
|
|
139
|
+
CLAUDE_CODE_OAUTH_TOKEN a Claude subscription token (\`claude setup-token\`); if set, it is
|
|
140
|
+
used and ANTHROPIC_API_KEY never reaches the agent
|
|
96
141
|
REQUEST the comment text, for \`comment\`
|
|
97
142
|
AGENT_REVIEW_COMMENT_AUTHOR the login of the comment's author, for \`comment\` and \`threads\`
|
|
98
143
|
AGENT_REVIEW_* optional settings; see docs/cli.md
|
|
99
144
|
|
|
100
145
|
Exit codes: 0 posted or nothing to do, 1 engine error, 2 usage error.
|
|
101
146
|
\`local\`: 0 a report was printed, 1 no call returned a review, 2 usage error, 130 interrupted.
|
|
147
|
+
\`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.
|
|
148
|
+
\`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.
|
|
102
149
|
\`history\`: 0 listed (or nothing to list), 2 usage error, including an unknown finding id.
|
|
150
|
+
\`status\`: 0 printed (also with no run kept), 2 usage error.
|
|
151
|
+
\`dashboard\`: 0 written or printed (also with no run kept), 2 usage error, 1 the index or the page could not be written.
|
|
103
152
|
\`doctor\`: 0 every required check passed, 1 one failed. \`setup\`: 1 when its closing doctor summary failed.
|
|
104
153
|
\`setup\`, \`init\`: 130 cancelled (Escape, Ctrl-C, Ctrl-D); nothing pending is saved.
|
|
105
154
|
\`skills\`: 0 done (copies left in place are warned about), 1 a copy could not be written, 2 usage error or a refused target.
|
|
@@ -161,6 +210,38 @@ export function writeAll(fd: number, text: string) {
|
|
|
161
210
|
}
|
|
162
211
|
}
|
|
163
212
|
|
|
213
|
+
/**
|
|
214
|
+
* The command a run executes. A `threads` run whose trigger is a review comment and whose request asks
|
|
215
|
+
* a question is `comment`: it is answered in the thread (ADR 0032 decision 4). Everything else keeps
|
|
216
|
+
* its command.
|
|
217
|
+
*/
|
|
218
|
+
export function routeMode(mode: string, commentLine: ReviewLineComment | undefined, request: string, keyword: string) {
|
|
219
|
+
return mode === "threads" && commentLine !== undefined && isThreadQuestion(request, keyword) ? "comment" : mode;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The review comment a question was written on, from the workflow's environment (ADR 0032 decision 4).
|
|
224
|
+
* Unset when the run is not about a review comment. Only the numbers and the path are read; the
|
|
225
|
+
* comment's text is `REQUEST`.
|
|
226
|
+
*/
|
|
227
|
+
export function readCommentLine(env: Record<string, string | undefined>): ReviewLineComment | undefined {
|
|
228
|
+
const id = env.AGENT_REVIEW_COMMENT_ID ?? "";
|
|
229
|
+
if (id === "") return undefined;
|
|
230
|
+
const number = (name: string) => {
|
|
231
|
+
const raw = env[name] ?? "";
|
|
232
|
+
if (raw === "") return null;
|
|
233
|
+
if (!/^\d+$/.test(raw)) throw new UsageError(`${name} must be a comment id or a line number, got "${raw}".`);
|
|
234
|
+
return Number(raw);
|
|
235
|
+
};
|
|
236
|
+
if (!/^\d+$/.test(id)) throw new UsageError(`AGENT_REVIEW_COMMENT_ID must be a comment id, got "${id}".`);
|
|
237
|
+
return {
|
|
238
|
+
id: Number(id),
|
|
239
|
+
replyTo: number("AGENT_REVIEW_COMMENT_IN_REPLY_TO"),
|
|
240
|
+
path: env.AGENT_REVIEW_COMMENT_PATH || null,
|
|
241
|
+
line: number("AGENT_REVIEW_COMMENT_LINE"),
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
164
245
|
function required(env: Record<string, string | undefined>, name: string) {
|
|
165
246
|
const value = env[name];
|
|
166
247
|
if (value === undefined || value === "") throw new UsageError(`${name} is not set`);
|
|
@@ -192,11 +273,42 @@ async function runWizard(mode: "setup" | "init", args: string[], repoDir: string
|
|
|
192
273
|
return runInitCommand(flags, env, io, {
|
|
193
274
|
version,
|
|
194
275
|
defaultWorkflowRef: DEFAULT_WORKFLOW_REF,
|
|
195
|
-
//
|
|
196
|
-
bindNow: (prompter) => runSetupCommand({ repoDir }, env, io, { doctor: { version }, interactive: true, prompter }),
|
|
276
|
+
// Choosing local/both already requests setup; keep its final write confirmation.
|
|
277
|
+
bindNow: (prompter, mode) => runSetupCommand({ repoDir }, env, io, { doctor: { version }, interactive: true, prompter, fromInit: true, initMode: mode, unboundHints: projectCommands("setup", repoDir, process.cwd()) }),
|
|
197
278
|
});
|
|
198
279
|
}
|
|
199
280
|
|
|
281
|
+
/**
|
|
282
|
+
* `wachiman reset-confidence <pr> [--commit <sha>]`: the first step of a review run (ADR 0033
|
|
283
|
+
* decision 14). It rewrites the PR Confidence block to `cannot say` for the commit under review
|
|
284
|
+
* before the push wait, so a run cancelled during it leaves no letter from an older commit. No
|
|
285
|
+
* model, no provider. A failure inside the reset itself (reading or writing the description) is a
|
|
286
|
+
* warning and the exit code stays 0. A usage or configuration error is not: a bad pull request
|
|
287
|
+
* number or flag, an invalid `AGENT_REVIEW_*` value, or a missing `GH_TOKEN` or
|
|
288
|
+
* `GITHUB_REPOSITORY` exits non-zero. The workflow steps run it with `continue-on-error`.
|
|
289
|
+
*/
|
|
290
|
+
export function runResetConfidence(args: string[], env: Record<string, string | undefined>, gh: GhFn = defaultGh): number {
|
|
291
|
+
const [prArg, ...flags] = args;
|
|
292
|
+
const pr = Number(prArg);
|
|
293
|
+
if (!/^\d+$/.test(prArg ?? "") || pr <= 0) throw new UsageError("reset-confidence needs a pull request number.");
|
|
294
|
+
let commit: string | undefined;
|
|
295
|
+
for (let i = 0; i < flags.length; i++) {
|
|
296
|
+
if (flags[i] !== "--commit" || !flags[i + 1]) throw new UsageError(`reset-confidence: unexpected "${flags[i]}".`);
|
|
297
|
+
commit = flags[++i];
|
|
298
|
+
}
|
|
299
|
+
const config = loadConfig(env);
|
|
300
|
+
if (!config.confidence) return 0;
|
|
301
|
+
required(env, "GH_TOKEN");
|
|
302
|
+
const repo = required(env, "GITHUB_REPOSITORY");
|
|
303
|
+
resetConfidence(
|
|
304
|
+
{ gh, dryRun: config.dryRun, log: (line) => console.log(line), warn: (line) => console.error(line) },
|
|
305
|
+
repo,
|
|
306
|
+
pr,
|
|
307
|
+
commit,
|
|
308
|
+
);
|
|
309
|
+
return 0;
|
|
310
|
+
}
|
|
311
|
+
|
|
200
312
|
export async function main(argv: string[], env: Record<string, string | undefined>): Promise<number> {
|
|
201
313
|
const mode = argv[0];
|
|
202
314
|
if (mode === "--help" || mode === "-h") {
|
|
@@ -231,13 +343,40 @@ export async function main(argv: string[], env: Record<string, string | undefine
|
|
|
231
343
|
engineVersion: readVersion(),
|
|
232
344
|
});
|
|
233
345
|
}
|
|
346
|
+
if (mode === "loop") {
|
|
347
|
+
// Like `local`: no GitHub token, no `gh` function anywhere on this path.
|
|
348
|
+
return runLoop(parseLoopArgs(args.slice(1)), repoDir, env, {
|
|
349
|
+
stdout: (text) => writeAll(1, text),
|
|
350
|
+
stderr: (line) => console.error(line),
|
|
351
|
+
engineVersion: readVersion(),
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
if (mode === "ask") {
|
|
355
|
+
// Like `local`: no GitHub token, no `gh` function anywhere on this path.
|
|
356
|
+
return runAsk(parseAskArgs(args.slice(1)), repoDir, env, {
|
|
357
|
+
stdout: (text) => writeAll(1, text),
|
|
358
|
+
stderr: (line) => console.error(line),
|
|
359
|
+
engineVersion: readVersion(),
|
|
360
|
+
});
|
|
361
|
+
}
|
|
234
362
|
if (mode === "doctor" || mode === "profile" || mode === "project") {
|
|
235
363
|
return runAccountCommand(mode, args.slice(1), repoDir, env);
|
|
236
364
|
}
|
|
237
365
|
if (mode === "setup" || mode === "init") return await runWizard(mode, args.slice(1), repoDir, env);
|
|
366
|
+
if (mode === "status") {
|
|
367
|
+
const parsed = parseStatusArgs(args.slice(1));
|
|
368
|
+
if ("help" in parsed) return (writeAll(1, `${statusUsage}\n`), 0);
|
|
369
|
+
return runStatus(parsed, repoDir, env, { stdout: (text) => writeAll(1, text), stderr: (line) => console.error(line), version: readVersion() });
|
|
370
|
+
}
|
|
371
|
+
if (mode === "dashboard") {
|
|
372
|
+
const parsed = parseDashboardArgs(args.slice(1));
|
|
373
|
+
if ("help" in parsed) return (writeAll(1, `${dashboardUsage}\n`), 0);
|
|
374
|
+
return runDashboard(parsed, env, { stdout: (text) => writeAll(1, text), stderr: (line) => console.error(line) });
|
|
375
|
+
}
|
|
238
376
|
if (mode === "history") {
|
|
239
377
|
return runHistory(parseHistoryArgs(args.slice(1)), repoDir, env, { stdout: (text) => writeAll(1, text), stderr: (line) => console.error(line) });
|
|
240
378
|
}
|
|
379
|
+
if (mode === "reset-confidence") return runResetConfidence(args.slice(1), env);
|
|
241
380
|
const [, prArg, ...rest] = args;
|
|
242
381
|
if (mode !== "review" && mode !== "comment" && mode !== "threads") {
|
|
243
382
|
throw new UsageError(mode ? `Unknown command "${mode}".` : "No command given.");
|
|
@@ -250,13 +389,18 @@ export async function main(argv: string[], env: Record<string, string | undefine
|
|
|
250
389
|
// The mode decides who started the run, whatever the environment says: the operator's
|
|
251
390
|
// command is never held to the automatic ceiling, and a thread run always is (ADR 0012).
|
|
252
391
|
const loaded = loadConfig(env);
|
|
253
|
-
const
|
|
392
|
+
const commentLine = mode === "review" ? undefined : readCommentLine(env);
|
|
393
|
+
// A thread reply that asks a question is answered in its thread, as a line question (ADR 0032
|
|
394
|
+
// decision 4); the rest of the thread-only run is unchanged. Its trigger is the question's, not
|
|
395
|
+
// an automatic run's, so it does not spend from the automatic ceiling.
|
|
396
|
+
const effective = routeMode(mode, commentLine, env.REQUEST ?? "", loaded.mention);
|
|
397
|
+
const config = effective === "comment" ? { ...loaded, trigger: "comment" } : effective === "threads" ? { ...loaded, trigger: "thread" } : loaded;
|
|
254
398
|
const provider = getProvider(config.provider, config);
|
|
255
399
|
// The verifier is its own adapter on its own model, always at effort high (ADR 0027).
|
|
256
400
|
const verifier = config.verify && mode !== "threads" ? getProvider(config.provider, { ...config, model: config.verifierModel, effort: "high" }) : undefined;
|
|
257
401
|
required(env, "GH_TOKEN");
|
|
258
402
|
const repo = required(env, "GITHUB_REPOSITORY");
|
|
259
|
-
const request =
|
|
403
|
+
const request = effective === "comment" ? required(env, "REQUEST") : "";
|
|
260
404
|
const costs: CallCost[] = [];
|
|
261
405
|
const deps: Deps = {
|
|
262
406
|
costs,
|
|
@@ -278,9 +422,9 @@ export async function main(argv: string[], env: Record<string, string | undefine
|
|
|
278
422
|
return 1;
|
|
279
423
|
}
|
|
280
424
|
try {
|
|
281
|
-
if (
|
|
282
|
-
else if (
|
|
283
|
-
else comment(deps, repo, pr, request, env.AGENT_REVIEW_COMMENT_AUTHOR || undefined);
|
|
425
|
+
if (effective === "review") review(deps, repo, pr, rest);
|
|
426
|
+
else if (effective === "threads") threadReplies(deps, repo, pr, env.AGENT_REVIEW_COMMENT_AUTHOR || undefined);
|
|
427
|
+
else comment(deps, repo, pr, request, env.AGENT_REVIEW_COMMENT_AUTHOR || undefined, commentLine);
|
|
284
428
|
} finally {
|
|
285
429
|
// Also after a failed run: the calls it made were paid for.
|
|
286
430
|
writeStepSummary(costs, env);
|
package/src/config.ts
CHANGED
|
@@ -23,6 +23,12 @@ export interface EngineConfig {
|
|
|
23
23
|
* footers. The operator's `comment` is not limited by it.
|
|
24
24
|
*/
|
|
25
25
|
autoBudgetUsd: number;
|
|
26
|
+
/**
|
|
27
|
+
* `AGENT_REVIEW_SIZE_GATE_USD`: the most a review's estimate may be before a GitHub run skips it
|
|
28
|
+
* and posts one comment instead. The effective gate is never below what the run may spend
|
|
29
|
+
* (`sizeGate` in estimate.ts), so raising the budgets lifts it. Local runs only warn.
|
|
30
|
+
*/
|
|
31
|
+
sizeGateUsd: number;
|
|
26
32
|
/** `AGENT_REVIEW_THREADS_BUDGET_USD`: the one provider call of a thread-only run. */
|
|
27
33
|
threadsBudgetUsd: number;
|
|
28
34
|
/**
|
|
@@ -69,18 +75,35 @@ export interface EngineConfig {
|
|
|
69
75
|
mention: string;
|
|
70
76
|
/** Login allowed to command the tool. `comment` refuses to run when it is empty or a placeholder. */
|
|
71
77
|
operator: string;
|
|
78
|
+
/**
|
|
79
|
+
* `AGENT_REVIEW_ASKERS`: who may ask a question (ADR 0032 decision 5). `operator` (default): only
|
|
80
|
+
* the operator. `write`: also a collaborator whose permission on the repository is admin,
|
|
81
|
+
* maintain or write, checked by the engine on each question. Reviews stay operator-only.
|
|
82
|
+
*/
|
|
83
|
+
askers: "operator" | "write";
|
|
84
|
+
/**
|
|
85
|
+
* `AGENT_REVIEW_ASK_CEILING_USD`: the most the questions of everyone but the operator may spend
|
|
86
|
+
* on one pull request, summed from the engine's own footers. The operator's questions are not limited.
|
|
87
|
+
*/
|
|
88
|
+
askCeilingUsd: number;
|
|
72
89
|
/** Extra exclude globs on top of the built-in ones. */
|
|
73
90
|
exclude: string[];
|
|
74
91
|
/**
|
|
75
92
|
* `AGENT_REVIEW_VERIFY`: after the batches, one more call tries to refute every finding above
|
|
76
|
-
* `info` before it is posted (ADR 0027).
|
|
77
|
-
* codex with no `AGENT_REVIEW_VERIFIER_MODEL`.
|
|
93
|
+
* `info` before it is posted (ADR 0027). Off by default; enabled only by `1` or `true`.
|
|
78
94
|
*/
|
|
79
95
|
verify: boolean;
|
|
80
96
|
/** `AGENT_REVIEW_VERIFY_BUDGET_USD`: the verifier's reserve, taken out of `budgetUsd` (at most half of it). */
|
|
81
97
|
verifyBudgetUsd: number;
|
|
82
98
|
/** `AGENT_REVIEW_VERIFIER_MODEL`: the verifier's model; it always runs at effort `high`. */
|
|
83
99
|
verifierModel: string;
|
|
100
|
+
/**
|
|
101
|
+
* `AGENT_REVIEW_CONFIDENCE`: PR Confidence (ADR 0033). A full review of a pull request lists the
|
|
102
|
+
* claims in its title and body with one more small call, grades the change against them and
|
|
103
|
+
* writes the grade into the description. Off by default; enabled only by `1` or `true`. Read by
|
|
104
|
+
* the pull request review only: `wachiman local` never grades.
|
|
105
|
+
*/
|
|
106
|
+
confidence: boolean;
|
|
84
107
|
}
|
|
85
108
|
|
|
86
109
|
/** The verifier's model when `AGENT_REVIEW_VERIFIER_MODEL` is unset (Claude Code only). */
|
|
@@ -153,14 +176,22 @@ export function loadConfig(env: Env, warn: (line: string) => void = console.erro
|
|
|
153
176
|
}
|
|
154
177
|
const verifyRaw = get("VERIFY");
|
|
155
178
|
if (verifyRaw !== undefined && verifyRaw !== "0" && verifyRaw !== "1" && verifyRaw !== "true" && verifyRaw !== "false") {
|
|
156
|
-
throw new UsageError(`AGENT_REVIEW_VERIFY must be 1, true, 0 or false (unset means
|
|
179
|
+
throw new UsageError(`AGENT_REVIEW_VERIFY must be 1, true, 0 or false (unset means off), got "${verifyRaw}".`);
|
|
157
180
|
}
|
|
158
181
|
const verifierModel = get("VERIFIER_MODEL") ?? (provider === "claude-code" ? DEFAULT_VERIFIER_MODEL : undefined);
|
|
159
|
-
//
|
|
160
|
-
const verify = verifyRaw ===
|
|
182
|
+
// Verification is opt-in, including when a verifier model is configured.
|
|
183
|
+
const verify = verifyRaw === "1" || verifyRaw === "true";
|
|
161
184
|
if (verify && verifierModel === undefined) {
|
|
162
185
|
throw new UsageError(`AGENT_REVIEW_VERIFY needs AGENT_REVIEW_VERIFIER_MODEL with the ${provider} provider: the default verifier is a Claude model.`);
|
|
163
186
|
}
|
|
187
|
+
const confidenceRaw = get("CONFIDENCE");
|
|
188
|
+
if (confidenceRaw !== undefined && !["0", "1", "true", "false"].includes(confidenceRaw)) {
|
|
189
|
+
throw new UsageError(`AGENT_REVIEW_CONFIDENCE must be 1, true, 0 or false (unset means off), got "${confidenceRaw}".`);
|
|
190
|
+
}
|
|
191
|
+
const askers = get("ASKERS") ?? "operator";
|
|
192
|
+
if (askers !== "operator" && askers !== "write") {
|
|
193
|
+
throw new UsageError(`AGENT_REVIEW_ASKERS must be operator or write, got "${askers}".`);
|
|
194
|
+
}
|
|
164
195
|
const trigger = get("TRIGGER")?.trim();
|
|
165
196
|
if (trigger !== undefined && !/^[a-z_]+$/.test(trigger)) {
|
|
166
197
|
throw new UsageError(`AGENT_REVIEW_TRIGGER must be a lowercase event action such as synchronize, got "${trigger}".`);
|
|
@@ -168,6 +199,7 @@ export function loadConfig(env: Env, warn: (line: string) => void = console.erro
|
|
|
168
199
|
return {
|
|
169
200
|
budgetUsd: number("BUDGET_USD", 3),
|
|
170
201
|
autoBudgetUsd: number("AUTO_BUDGET_USD", 6),
|
|
202
|
+
sizeGateUsd: number("SIZE_GATE_USD", 6),
|
|
171
203
|
threadsBudgetUsd: number("THREADS_BUDGET_USD", 0.25),
|
|
172
204
|
trigger: trigger || undefined,
|
|
173
205
|
batchBudgetUsd: number("BATCH_BUDGET_USD", 0.75),
|
|
@@ -185,10 +217,13 @@ export function loadConfig(env: Env, warn: (line: string) => void = console.erro
|
|
|
185
217
|
onProviderUnavailable,
|
|
186
218
|
mention: get("MENTION") ?? "/wachiman",
|
|
187
219
|
operator: get("OPERATOR") ?? "",
|
|
220
|
+
askers,
|
|
221
|
+
askCeilingUsd: number("ASK_CEILING_USD", 3),
|
|
188
222
|
exclude: (get("EXCLUDE") ?? "").split(",").filter(Boolean),
|
|
189
223
|
verify,
|
|
190
224
|
verifyBudgetUsd: number("VERIFY_BUDGET_USD", 1),
|
|
191
225
|
verifierModel: verifierModel ?? DEFAULT_VERIFIER_MODEL,
|
|
226
|
+
confidence: confidenceRaw === "1" || confidenceRaw === "true",
|
|
192
227
|
};
|
|
193
228
|
}
|
|
194
229
|
|