wachiman 1.10.0 → 1.12.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.
@@ -0,0 +1,23 @@
1
+ import { resolve } from "node:path";
2
+
3
+ export type CommandShell = "posix" | "powershell";
4
+
5
+ /** Shell text is a suggestion only. Never pass this string to a subprocess. */
6
+ export function quoteArgument(value: string, shell: CommandShell): string {
7
+ if (/^[a-zA-Z0-9_./:-]+$/.test(value)) return value;
8
+ // PowerShell treats these typographic apostrophes as single-quote delimiters too.
9
+ return shell === "powershell" ? `'${value.replace(/['\u2018\u2019\u201a\u201b]/g, "$&$&")}'` : `'${value.replaceAll("'", "'\\''")}'`;
10
+ }
11
+
12
+ export function projectCommand(command: "setup" | "local" | "doctor", repoDir: string, cwd = process.cwd(), shell: CommandShell = "posix"): string {
13
+ const target = resolve(cwd, repoDir);
14
+ const args = ["wachiman", command, ...(target === resolve(cwd) ? [] : ["--repo-dir", target])];
15
+ return args.map((arg) => quoteArgument(arg, shell)).join(" ");
16
+ }
17
+
18
+ /** Windows users may be in either shell; name both rather than guess from PATH. */
19
+ export function projectCommands(command: "setup" | "local" | "doctor", repoDir: string, cwd = process.cwd(), platform = process.platform): string[] {
20
+ return platform === "win32"
21
+ ? [`PowerShell: ${projectCommand(command, repoDir, cwd, "powershell")}`, `Git Bash: ${projectCommand(command, repoDir, cwd)}`]
22
+ : [projectCommand(command, repoDir, cwd)];
23
+ }
@@ -9,6 +9,7 @@
9
9
  * script says it.
10
10
  */
11
11
  import { createInterface, emitKeypressEvents, type Interface } from "node:readline";
12
+ import { terminalStyle, type Tone } from "./style";
12
13
 
13
14
  export interface PromptIO {
14
15
  input: NodeJS.ReadableStream;
@@ -19,6 +20,7 @@ export interface PromptIO {
19
20
  export interface Choice<T> {
20
21
  label: string;
21
22
  value: T;
23
+ description?: string;
22
24
  }
23
25
 
24
26
  export interface Prompter {
@@ -28,7 +30,9 @@ export interface Prompter {
28
30
  text(label: string, defaultValue: string | undefined, validate?: (value: string) => string | undefined): Promise<string | null>;
29
31
  confirm(label: string, defaultYes: boolean): Promise<boolean | null>;
30
32
  /** Prints a line to the prompt output (a preview, a summary, an error). */
31
- say(line: string): void;
33
+ say(line: string, tone?: Tone): void;
34
+ /** A stage can start before the route (and therefore the total) is known. */
35
+ step(label: string, index: number, total?: number): void;
32
36
  /** Gives the terminal back (raw mode off, input paused) so a child process can use it; the next question takes it again. Typed-ahead answers are kept. */
33
37
  suspend(): void;
34
38
  close(): void;
@@ -36,8 +40,11 @@ export interface Prompter {
36
40
 
37
41
  const CANCEL_LINES = new Set(["\u001b", "\u0003", "\u0004"]);
38
42
 
39
- export function createPrompter(io: PromptIO): Prompter {
40
- const terminal = (io.input as { isTTY?: boolean }).isTTY === true;
43
+ export function createPrompter(io: PromptIO, env: Record<string, string | undefined> = process.env): Prompter {
44
+ const paint = terminalStyle(io.output as { isTTY?: boolean }, env);
45
+ // readline's cursor editing also emits ANSI; a redirected prompt output must
46
+ // stay plain even when stdin itself is still a terminal.
47
+ const terminal = (io.input as { isTTY?: boolean }).isTTY === true && (io.output as { isTTY?: boolean }).isTTY === true;
41
48
  const queue: string[] = [];
42
49
  let rl: Interface | undefined;
43
50
  let onKey: ((text: string, key?: { name?: string }) => void) | undefined;
@@ -123,7 +130,7 @@ export function createPrompter(io: PromptIO): Prompter {
123
130
  };
124
131
  });
125
132
  };
126
- const say = (line: string) => void io.output.write(`${line}\n`);
133
+ const say = (line: string, tone?: Tone) => void io.output.write(`${tone ? paint(line, tone) : line}\n`);
127
134
  const ask = (question: string) => {
128
135
  open();
129
136
  // On a terminal readline owns the prompt, so its line refresh (Backspace, cursor keys) redraws the question too.
@@ -136,11 +143,17 @@ export function createPrompter(io: PromptIO): Prompter {
136
143
 
137
144
  return {
138
145
  say,
146
+ step(label, index, total) {
147
+ say(`\nStep ${index}${total === undefined ? "" : `/${total}`} ${label}`, "accent");
148
+ },
139
149
  suspend,
140
150
  close: suspend,
141
151
  async select(label, choices, defaultIndex) {
142
- say(label);
143
- choices.forEach((c, i) => say(` ${i + 1}. ${c.label}${i === defaultIndex ? " (default)" : ""}`));
152
+ say(label, "accent");
153
+ choices.forEach((c, i) => {
154
+ say(` ${i + 1}. ${c.label}${i === defaultIndex ? " (default)" : ""}`, i === defaultIndex ? "accent" : undefined);
155
+ if (c.description) say(` ${c.description}`, "muted");
156
+ });
144
157
  for (;;) {
145
158
  const line = await ask(`Choice [${defaultIndex + 1}]: `);
146
159
  if (line === null) return null;
@@ -148,7 +161,7 @@ export function createPrompter(io: PromptIO): Prompter {
148
161
  if (answer === "") return choices[defaultIndex].value;
149
162
  const n = Number(answer);
150
163
  if (/^\d+$/.test(answer) && n >= 1 && n <= choices.length) return choices[n - 1].value;
151
- say(`Enter a number from 1 to ${choices.length}, or press Enter for ${defaultIndex + 1}.`);
164
+ say(`Enter a number from 1 to ${choices.length}, or press Enter for ${defaultIndex + 1}.`, "error");
152
165
  }
153
166
  },
154
167
  async text(label, defaultValue, validate) {
@@ -158,7 +171,7 @@ export function createPrompter(io: PromptIO): Prompter {
158
171
  const answer = line.trim() === "" && defaultValue !== undefined ? defaultValue : line.trim();
159
172
  const problem = validate?.(answer);
160
173
  if (problem === undefined) return answer;
161
- say(problem);
174
+ say(problem, "error");
162
175
  }
163
176
  },
164
177
  async confirm(label, defaultYes) {
@@ -169,7 +182,7 @@ export function createPrompter(io: PromptIO): Prompter {
169
182
  if (answer === "") return defaultYes;
170
183
  if (answer === "y" || answer === "yes") return true;
171
184
  if (answer === "n" || answer === "no") return false;
172
- say("Answer y or n.");
185
+ say("Answer y or n.", "error");
173
186
  }
174
187
  },
175
188
  };
@@ -0,0 +1,19 @@
1
+ /** Terminal colors are an enhancement: labels carry the meaning in plain output. */
2
+ export type Tone = "accent" | "muted" | "success" | "warning" | "error";
3
+
4
+ const CODES: Record<Tone, number> = { accent: 36, muted: 2, success: 32, warning: 33, error: 31 };
5
+
6
+ export function terminalStyle(output: { isTTY?: boolean }, env: Record<string, string | undefined>) {
7
+ const color = output.isTTY === true && !env.NO_COLOR && env.TERM !== "dumb";
8
+ return (text: string, tone: Tone) => color ? `\x1b[${CODES[tone]}m${text}\x1b[0m` : text;
9
+ }
10
+
11
+ /** Only human-facing stderr is decorated; stdout remains byte-for-byte data. */
12
+ export function wizardIo<T extends { stderr: (line: string) => void }>(io: T, output: { isTTY?: boolean }, env: Record<string, string | undefined>): T {
13
+ const paint = terminalStyle(output, env);
14
+ return { ...io, stderr: (line: string) => {
15
+ const tone = /^(bound:|wrote |account: signed in|All required checks passed|local: ready)/.test(line) ? "success"
16
+ : /^(warning:|cancelled:|not written|nothing saved|These already happened|local: not ready|github: pending)/.test(line) ? "warning" : undefined;
17
+ io.stderr(tone ? paint(line, tone) : line);
18
+ } };
19
+ }
@@ -20,7 +20,8 @@ name: Wachiman review
20
20
  # - `threads`: when the repository owner replies in a review thread (a
21
21
  # `pull_request_review_comment`), Wachiman answers every thread that waits for an answer,
22
22
  # with no review and no resolve, but only once the pull request's head was already reviewed
23
- # (otherwise the review of the push reads the replies). Remove the
23
+ # (otherwise the review of the push reads the replies). A new line comment in the review panel
24
+ # that asks a question after the command word is answered under itself. Remove the
24
25
  # `pull_request_review_comment` trigger below to turn it off.
25
26
  # - `on-demand`: when the repository owner comments on a pull request:
26
27
  # `/wachiman review` re-reviews what changed since the last complete, unscoped review and,
@@ -101,6 +102,13 @@ env:
101
102
  AGENT_REVIEW_AUTO_BUDGET_USD: 2
102
103
  AGENT_REVIEW_THREADS_BUDGET_USD: 0.25
103
104
  AGENT_REVIEW_ANSWER_BUDGET_USD: 1
105
+ # Who may ask a question by comment: `operator` (only the operator) or `write` (also a collaborator
106
+ # with admin, maintain or write permission). Set it to `write` together with the literal
107
+ # `'operator' == 'write'` in the `threads` and `on-demand` `if:` below (EDIT THIS), since a job
108
+ # `if:` cannot read this variable.
109
+ AGENT_REVIEW_ASKERS: operator
110
+ # The most all questions from people other than the operator may spend on one pull request.
111
+ AGENT_REVIEW_ASK_CEILING_USD: 3
104
112
  # The login allowed to command the tool (EDIT THIS). The `on-demand` job `if:` checks the same
105
113
  # login, and the CLI checks it again against the comment's author.
106
114
  AGENT_REVIEW_OPERATOR: your-github-login
@@ -180,14 +188,22 @@ jobs:
180
188
  threads:
181
189
  name: Wachiman thread replies
182
190
  # EDIT THIS: replace 'your-github-login' below with the operator's login, and keep it equal to
183
- # AGENT_REVIEW_OPERATOR above. Only a reply by the operator (not a bot), on a head in this
184
- # repository, starts the job; the engine checks the login again and acts only when the head
185
- # was already reviewed.
191
+ # AGENT_REVIEW_OPERATOR above. A comment in the review panel starts the job when the operator wrote
192
+ # it and it is a reply, or when it starts with the mention and the operator or (only when
193
+ # `askers` is `write`, see above) an OWNER, MEMBER or COLLABORATOR wrote it, on a head in this
194
+ # repository. The collaborator case is a cheap pre-filter: the engine checks the login again,
195
+ # answers a collaborator only under GitHub's write permission, and acts only when the head was
196
+ # already reviewed.
186
197
  if: |
187
198
  github.event_name == 'pull_request_review_comment' &&
188
- github.event.comment.in_reply_to_id &&
189
- github.event.comment.user.login == 'your-github-login' &&
190
199
  github.event.comment.user.type != 'Bot' &&
200
+ ((github.event.comment.user.login == 'your-github-login' && github.event.comment.in_reply_to_id) ||
201
+ ((startsWith(github.event.comment.body, '/wachi') ||
202
+ startsWith(github.event.comment.body, '@agent-review') ||
203
+ startsWith(github.event.comment.body, '@claude')) &&
204
+ (github.event.comment.user.login == 'your-github-login' ||
205
+ ('operator' == 'write' &&
206
+ contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association))))) &&
191
207
  github.event.pull_request.head.repo.full_name == github.repository
192
208
  runs-on: ubuntu-latest
193
209
  timeout-minutes: 30
@@ -227,6 +243,12 @@ jobs:
227
243
  GH_TOKEN: ${{ github.token }}
228
244
  PR: ${{ github.event.pull_request.number }}
229
245
  AGENT_REVIEW_COMMENT_AUTHOR: ${{ github.event.comment.user.login }}
246
+ # The reply's text and place, for a question in a thread (environment only, never interpolated).
247
+ REQUEST: ${{ github.event.comment.body }}
248
+ AGENT_REVIEW_COMMENT_ID: ${{ github.event.comment.id }}
249
+ AGENT_REVIEW_COMMENT_IN_REPLY_TO: ${{ github.event.comment.in_reply_to_id }}
250
+ AGENT_REVIEW_COMMENT_PATH: ${{ github.event.comment.path }}
251
+ AGENT_REVIEW_COMMENT_LINE: ${{ github.event.comment.line || github.event.comment.original_line }}
230
252
  run: bun --no-env-file --config=scripts/agent-review/bunfig.toml scripts/agent-review/cli.ts threads "$PR" --repo-dir .
231
253
 
232
254
  on-demand:
@@ -235,19 +257,32 @@ jobs:
235
257
  # to AGENT_REVIEW_OPERATOR above (a job `if:` cannot read `env`). Matching by login works
236
258
  # for user-owned and organisation-owned repositories alike (`author_association` is `OWNER`
237
259
  # in the first and `MEMBER` in the second). `@agent-review` and `@claude` are accepted as aliases
238
- # while installed copies migrate.
260
+ # while installed copies migrate. A comment that starts with the mention from an OWNER, MEMBER
261
+ # or COLLABORATOR also starts the job, but only when `askers` is `write` (the `'operator' == 'write'`
262
+ # literal in the threads job, changed with AGENT_REVIEW_ASKERS at the top), as a pre-filter only:
263
+ # the engine refuses it unless GitHub confirms write access.
239
264
  if: |
240
265
  github.event_name == 'issue_comment' &&
241
266
  github.event.issue.pull_request &&
242
- github.event.comment.user.login == 'your-github-login' &&
267
+ (github.event.comment.user.login == 'your-github-login' ||
268
+ (github.event.comment.user.type != 'Bot' &&
269
+ 'operator' == 'write' &&
270
+ contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association) &&
271
+ (startsWith(github.event.comment.body, '/wachi') ||
272
+ startsWith(github.event.comment.body, '@agent-review') ||
273
+ startsWith(github.event.comment.body, '@claude')))) &&
243
274
  (contains(github.event.comment.body, '/wachi') ||
244
275
  contains(github.event.comment.body, '@agent-review') ||
245
276
  contains(github.event.comment.body, '@claude'))
246
277
  runs-on: ubuntu-latest
247
278
  timeout-minutes: 30 # batches run one after another
279
+ # The operator's runs keep their group and cancel one another. A collaborator's question has its
280
+ # own group that never cancels, so it cannot cancel the operator's review of the pull request.
281
+ # The login is a literal here because a concurrency block cannot read env: keep it equal to
282
+ # AGENT_REVIEW_OPERATOR.
248
283
  concurrency:
249
- group: agent-on-demand-${{ github.event.issue.number }}
250
- cancel-in-progress: true
284
+ group: agent-on-demand-${{ github.event.issue.number }}${{ github.event.comment.user.login != 'your-github-login' && '-ask' || '' }}
285
+ cancel-in-progress: ${{ github.event.comment.user.login == 'your-github-login' }}
251
286
  permissions:
252
287
  contents: read
253
288
  pull-requests: write
@@ -9,7 +9,8 @@ name: Wachiman review
9
9
  # First install: the installing pull request can get the automatic review. `/wachiman review` works once
10
10
  # this file is on the default branch, because `issue_comment` runs from there. A reply you write in a
11
11
  # review thread (`pull_request_review_comment`) gets an answer without a push, once the head has been
12
- # reviewed; replies from anyone else start nothing.
12
+ # reviewed; a new line comment that asks after the command word is answered under itself. Replies from
13
+ # anyone else start nothing, unless `askers: write` is set below.
13
14
  # `synchronize` reviews every push to an open pull request, only the commits that are new since the
14
15
  # last review (a rebase with no change in content only moves the marker and costs no model call).
15
16
  # Each push can spend up to `budget_usd`, and all automatic runs on one pull request together up to
@@ -30,5 +31,7 @@ jobs:
30
31
  # review_on_push: false # review only on open, ready for review and `/wachiman review`
31
32
  # push_debounce_seconds: 180 # a push waits this long first; a newer push cancels it unspent (0 = no wait)
32
33
  # auto_budget_usd: 2 # most all automatic runs on one pull request may spend together
34
+ # askers: write # collaborators with admin, maintain or write permission may ask questions too (default: operator)
35
+ # ask_ceiling_usd: 3 # most all questions from people other than the operator may spend on one pull request
33
36
  secrets:
34
37
  ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}