wachiman 1.15.0 → 1.16.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.
Files changed (54) hide show
  1. package/README.md +1 -0
  2. package/package.json +1 -1
  3. package/src/accounts/commands.ts +3 -2
  4. package/src/accounts/confirm.ts +1 -1
  5. package/src/accounts/profile-list.ts +24 -0
  6. package/src/cli.ts +54 -20
  7. package/src/config.ts +19 -6
  8. package/src/connectors/local-git.ts +47 -0
  9. package/src/doctor/checks.ts +106 -1
  10. package/src/doctor/run.ts +9 -1
  11. package/src/engine.ts +280 -97
  12. package/src/help.ts +85 -3
  13. package/src/init/args.ts +5 -2
  14. package/src/init/github-login.ts +13 -0
  15. package/src/init/options.ts +31 -3
  16. package/src/init/prompt.ts +46 -15
  17. package/src/init/run.ts +204 -24
  18. package/src/init/settings.ts +127 -0
  19. package/src/init/write.ts +16 -102
  20. package/src/local-ask.ts +5 -4
  21. package/src/local.ts +55 -10
  22. package/src/loop/command.ts +5 -5
  23. package/src/pr-template/adopt.ts +434 -0
  24. package/src/pr-template/catalog.ts +429 -0
  25. package/src/pr-template/check-run.ts +328 -0
  26. package/src/pr-template/check.ts +338 -0
  27. package/src/pr-template/describe.ts +368 -0
  28. package/src/pr-template/format.ts +399 -0
  29. package/src/pr-template/gh.ts +159 -0
  30. package/src/pr-template/install.ts +288 -0
  31. package/src/pr-template/legacy-guides.ts +50 -0
  32. package/src/pr-template/pr-risk.ts +426 -0
  33. package/src/pr-template/render.ts +302 -0
  34. package/src/pr-template/resolve.ts +65 -0
  35. package/src/pr-template/run.ts +88 -0
  36. package/src/pr-template/strip.ts +171 -0
  37. package/src/pr-template/write.ts +139 -0
  38. package/src/providers/claude-code.ts +7 -8
  39. package/src/providers/codex.ts +4 -4
  40. package/src/providers/spawn.ts +95 -0
  41. package/src/providers/types.ts +5 -2
  42. package/src/repo-settings.ts +159 -0
  43. package/src/setup/prompt.ts +49 -33
  44. package/src/setup/run.ts +31 -6
  45. package/src/sinks/common.ts +10 -3
  46. package/src/sinks/markdown.ts +3 -2
  47. package/src/sinks/terminal.ts +3 -2
  48. package/src/upgrade/command.ts +286 -0
  49. package/src/upgrade/pin.ts +112 -0
  50. package/src/wizard/mascot.ts +56 -51
  51. package/src/wizard/prompt-fancy.ts +10 -2
  52. package/src/wizard/prompt.ts +17 -4
  53. package/src/wizard/ui.ts +2 -0
  54. package/templates/pr/sections.json +163 -0
package/src/help.ts CHANGED
@@ -15,7 +15,11 @@ import { localUsage } from "./local";
15
15
  import { loopUsage } from "./loop/command";
16
16
  import { profileUsage, projectUsage, setupUsage } from "./accounts/commands";
17
17
  import { skillsUsage } from "./skills/install";
18
+ import { checkUsage, riskUsage, stripUsage } from "./pr-template/check-run";
19
+ import { formatUsage } from "./pr-template/format";
20
+ import { installUsage, showUsage, statusUsage as prTemplateStatusUsage } from "./pr-template/install";
18
21
  import { statusUsage } from "./status/command";
22
+ import { upgradeUsage } from "./upgrade/command";
19
23
 
20
24
  export const DOCS = "https://github.com/niway-dev/wachiman/blob/main/docs";
21
25
 
@@ -291,14 +295,17 @@ const setupPage: Page = {
291
295
 
292
296
  const initPage: Page = {
293
297
  usage: initUsage,
294
- summary: "Write the GitHub Actions caller workflow (.github/workflows/wachiman-review.yml), or, with --mode local, write nothing and hand over to setup.",
298
+ summary: "Write the GitHub Actions caller workflow (.github/workflows/wachiman-review.yml), or, with --mode local, write no workflow and hand over to setup. With a repository kind, also write .wachiman.yml. It can also install the PR description template.",
295
299
  options: [
296
300
  ["--mode github|local|both", "What to set up. Required without a terminal"],
297
301
  ["--operator <login>", "The GitHub login allowed to command the reviewer. Required for github and both without a terminal"],
298
302
  ["--version <tag>", "vX.Y.Z or a 40-character commit SHA written after review.yml@. Default: the release bundled in this build"],
299
303
  ["--path <file>", "Default: .github/workflows/wachiman-review.yml; a .yml or .yaml file directly in .github/workflows/"],
300
- ["--force", "Replace an existing file after copying it to <file>.bak-<timestamp>"],
304
+ ["--project-kind monorepo|single", "The kind of repository, recorded in .wachiman.yml (metadata only). Asked on a terminal; without one, the file is left alone"],
305
+ ["--force", "Replace an existing workflow after copying it to <file>.bak-<timestamp>; with --project-kind, also change a different kind"],
301
306
  ["--dry-run", "Print the file to stdout and write nothing"],
307
+ ["--pr-template", "Also install the PR description template (`wachiman pr-template install`, files only, never a commit). A refusal is reported and does not fail init"],
308
+ ["--no-pr-template", "Do not install it and do not ask. Without either flag a terminal asks (default yes) and a script gets none"],
302
309
  ["--yes", "No prompts"],
303
310
  REPO_DIR,
304
311
  ],
@@ -324,6 +331,21 @@ const doctorPage: Page = {
324
331
  docs: `${DOCS}/cli.md#setup-doctor-profile-and-project`,
325
332
  };
326
333
 
334
+ const upgradePage: Page = {
335
+ usage: upgradeUsage,
336
+ summary: "Update the CLI to the latest release, then move the Wachiman workflow pin in this repository to it. Rewrites the files and prints the git commands; it never commits. A clone or a wachiman-dev build is not upgraded.",
337
+ options: [
338
+ ["--check", "Print the installed and the latest version and change nothing"],
339
+ ["--repo-only", "Rewrite the pins to the installed version (or --to) and leave the CLI alone"],
340
+ ["--to <version>", "Install this release (v1.2.3) and pin it. It never downgrades the CLI: when the CLI is already on that version or newer, nothing is installed and the pins move. If the install fails the pins stay and the exit is 1; with --repo-only no install is attempted"],
341
+ REPO_DIR,
342
+ ],
343
+ env: [HOME_ENV],
344
+ exit: [["0", "Done, nothing to do, or the CLI is a clone or a dev build and was not upgraded"], ["1", "The package manager failed, a version could not be read, or a workflow file could not be read or written"], ["2", "Usage error"]],
345
+ examples: ["wachiman upgrade --check", "wachiman upgrade", "wachiman upgrade --repo-only"],
346
+ docs: `${DOCS}/cli.md#upgrade`,
347
+ };
348
+
327
349
  const ACCOUNT_ENV: readonly Row[] = [HOME_ENV, ["CI", "true or 1 means no terminal: confirmations need --yes"]];
328
350
  const accountPage = (usage: string, summary: string, options: readonly Row[], examples: string[]): Page => ({
329
351
  usage, summary, options, env: ACCOUNT_ENV, exit: CONFIRMATION_EXIT, examples, docs: `${DOCS}/cli.md#setup-doctor-profile-and-project`,
@@ -392,13 +414,71 @@ const skillsPage: Page = {
392
414
  },
393
415
  };
394
416
 
417
+ const PR_TEMPLATE_DOCS = `${DOCS}/pr-template.md`;
418
+ const PR_TEMPLATE_EXIT: readonly Row[] = [
419
+ ["0", "Done, the description passes, or the template is current"],
420
+ ["1", "check found a problem; status is anything but current; a git commit made by install --commit failed"],
421
+ ["2", "Usage or configuration error: an unknown flag or section, an invalid .github/pr-template.json, a refused install, a missing tool"],
422
+ ];
423
+ const prTemplatePage = (usage: string, summary: string, options: readonly Row[], examples: string[]): Page => ({
424
+ usage, summary, options, exit: PR_TEMPLATE_EXIT, examples, docs: PR_TEMPLATE_DOCS,
425
+ });
426
+
427
+ const prTemplatePageRoot: Page = {
428
+ usage: "wachiman pr-template <show|install|status|check|format|risk|strip> [options]",
429
+ summary: "Install the PR description template, report its state, and check, reorder and strip a description. The template is generated from a section catalog plus an optional .github/pr-template.json; no model is called. Run `wachiman pr-template <subcommand> --help` for one of them.",
430
+ options: [REPO_DIR],
431
+ exit: PR_TEMPLATE_EXIT,
432
+ examples: ["wachiman pr-template install", "wachiman pr-template check --pr 42"],
433
+ docs: PR_TEMPLATE_DOCS,
434
+ subs: {
435
+ show: prTemplatePage(showUsage, "Print the template this repository would get: the default, or the one .github/pr-template.json describes. Writes nothing.", [
436
+ ["--from <json>", "Preview a definition from this file instead of .github/pr-template.json"],
437
+ REPO_DIR,
438
+ ], ["wachiman pr-template show", "wachiman pr-template show --from ./pr-template.json"]),
439
+ install: prTemplatePage(installUsage, "Write .github/pull_request_template.md, generated from the catalog and .github/pr-template.json. Files only: it never pushes. An existing template without the Wachiman stamp is adopted and backed up; a hand-edited one is refused.", [
440
+ ["--from <json>", "Copy this definition into .github/pr-template.json before generating"],
441
+ ["--force", "Replace a hand-edited template, or an existing, different .github/pr-template.json, after a backup in the git directory (wachiman/backups)"],
442
+ ["--commit", "Make one commit with only the files written; hooks run, nothing is pushed"],
443
+ REPO_DIR,
444
+ ], ["wachiman pr-template install", "wachiman pr-template install --commit"]),
445
+ status: prTemplatePage(prTemplateStatusUsage, "Print the state of the installed template: missing, current, outdated, edited by hand, unmanaged or invalid. Exits 0 only for current.", [
446
+ ["--json", "Print {state, version, installedVersion}"],
447
+ REPO_DIR,
448
+ ], ["wachiman pr-template status", "wachiman pr-template status --json"]),
449
+ check: prTemplatePage(checkUsage, "Check a PR description against the template: headings and their order, the status rows, Needs you, the Risk floor, the footer commit, and the breaking-change marker. Findings go to stderr.", [
450
+ ["<file>", "A description on disk; needs --title. The template is read from the working tree"],
451
+ ["--pr <n>", "Read title, body, head, commits and files through gh; the template is read at the PR's head commit"],
452
+ ["--repo <owner/name>", "With --pr: the repository on GitHub. Default: the one gh finds in the directory"],
453
+ ["--title <t>", "With a file: the pull request title"],
454
+ ["--head <sha>", "With a file: the commit the footer must name. Default: HEAD"],
455
+ ["--base <ref>", "With a file: compare with this branch for the Risk floor. Default: origin/main"],
456
+ ["--allow-breaking", "Allow a breaking-change marker or a `!` title"],
457
+ REPO_DIR,
458
+ ], ["wachiman pr-template check body.md --title 'feat: add x'", "wachiman pr-template check --pr 42"]),
459
+ format: prTemplatePage(formatUsage, "Print a description reordered to the template: sections and status rows in template order, missing required headings added empty, unknown sections moved into Notes. No text is deleted. It never edits a pull request on GitHub.", [
460
+ ["[<file>]", "The description. Default: standard input"],
461
+ ["--write", "Rewrite the file instead of printing"],
462
+ REPO_DIR,
463
+ ], ["wachiman pr-template format body.md", "wachiman pr-template format body.md --write"]),
464
+ risk: prTemplatePage(riskUsage, "Compute the risk floor of this branch from the files it changed, as 🟢 Low, 🟡 Medium or 🔴 High. A .github/pr-risk.toml on the base can only raise it.", [
465
+ ["--base <ref>", "Compare with this branch. Default: origin/main"],
466
+ REPO_DIR,
467
+ ], ["wachiman pr-template risk", "wachiman pr-template risk --base origin/develop"]),
468
+ strip: prTemplatePage(stripUsage, "Print a description without its guide comments and the stamp, keeping the Wachiman block markers. Run it before posting.", [
469
+ ["<file>", "The description to clean"],
470
+ REPO_DIR,
471
+ ], ["wachiman pr-template strip body.md"]),
472
+ },
473
+ };
474
+
395
475
  /** The commands a GitHub Actions run uses; they are not in the root help. */
396
476
  export const CI_COMMANDS = ["review", "comment", "threads", "reset-confidence"] as const;
397
477
 
398
478
  const PAGES: Readonly<Record<string, Page>> = {
399
479
  local: localPage, loop: loopPage, ask: askPage,
400
480
  history: historyPage, status: statusPage, dashboard: dashboardPage, ledger: ledgerPageWithSubs,
401
- setup: setupPage, init: initPage, doctor: doctorPage, profile: profilePage, project: projectPage, skills: skillsPage,
481
+ setup: setupPage, init: initPage, doctor: doctorPage, profile: profilePage, project: projectPage, skills: skillsPage, upgrade: upgradePage, "pr-template": prTemplatePageRoot,
402
482
  review: reviewPage, comment: commentPage, threads: threadsPage, "reset-confidence": resetConfidencePage,
403
483
  };
404
484
 
@@ -478,6 +558,8 @@ export function rootHelp(paint: Paint = plain): string {
478
558
  ["profile", "List, create, add, log in, remove and default profiles"],
479
559
  ["project", "Show or remove this repository's binding"],
480
560
  ["skills", "Install or remove the agent skills"],
561
+ ["pr-template", "Install and check the PR description template"],
562
+ ["upgrade", "Update the CLI and the workflow pin in this repository"],
481
563
  ]),
482
564
  "",
483
565
  `Help: wachiman <command> --help · wachiman help ci · docs: ${DOCS}/cli.md`,
package/src/init/args.ts CHANGED
@@ -3,25 +3,28 @@ import { parseFlags } from "../flags";
3
3
  import type { RawInitFlags } from "./options";
4
4
 
5
5
  export const initUsage =
6
- "wachiman init [--mode github|local|both] [--operator <login>] [--version <tag>] [--path <file>] [--force] [--dry-run] [--yes] [--repo-dir <dir>]";
6
+ "wachiman init [--mode github|local|both] [--project-kind monorepo|single] [--operator <login>] [--version <tag>] [--path <file>] [--force] [--dry-run] [--pr-template | --no-pr-template] [--yes] [--repo-dir <dir>]";
7
7
 
8
8
  /** The arguments after `init` (`--repo-dir` is already taken out and arrives as `repoDir`). Pure; an unknown flag is a usage error. */
9
9
  export function parseInitFlags(argv: string[], repoDir: string): RawInitFlags {
10
10
  if (argv.includes("--help") || argv.includes("-h")) return { help: true, repoDir };
11
11
  const { positionals, values, booleans } = parseFlags(
12
12
  argv,
13
- { values: ["--mode", "--operator", "--version", "--path"], booleans: ["--force", "--dry-run", "--yes"] },
13
+ { values: ["--mode", "--project-kind", "--operator", "--version", "--path"], booleans: ["--force", "--dry-run", "--yes", "--pr-template", "--no-pr-template"] },
14
14
  "init",
15
15
  );
16
16
  if (positionals.length > 0) throw new UsageError(`init takes no argument "${positionals[0]}".`);
17
+ if (booleans["--pr-template"] && booleans["--no-pr-template"]) throw new UsageError("--pr-template and --no-pr-template contradict each other; give one.");
17
18
  return {
18
19
  ...(values["--mode"] !== undefined ? { mode: values["--mode"] } : {}),
20
+ ...(values["--project-kind"] !== undefined ? { projectKind: values["--project-kind"] } : {}),
19
21
  ...(values["--operator"] !== undefined ? { operator: values["--operator"] } : {}),
20
22
  ...(values["--version"] !== undefined ? { version: values["--version"] } : {}),
21
23
  ...(values["--path"] !== undefined ? { path: values["--path"] } : {}),
22
24
  ...(booleans["--force"] ? { force: true } : {}),
23
25
  ...(booleans["--dry-run"] ? { dryRun: true } : {}),
24
26
  ...(booleans["--yes"] ? { yes: true } : {}),
27
+ ...(booleans["--pr-template"] ? { prTemplate: true } : booleans["--no-pr-template"] ? { prTemplate: false } : {}),
25
28
  repoDir,
26
29
  };
27
30
  }
@@ -0,0 +1,13 @@
1
+ import { spawnSync } from "node:child_process";
2
+
3
+ /** The login of the account `gh` is signed in as, or undefined when `gh` is missing, signed out or fails. Only ever a suggestion. */
4
+ export function ghLogin(): string | undefined {
5
+ try {
6
+ const run = spawnSync("gh", ["api", "user", "--jq", ".login"], { encoding: "utf8", timeout: 10_000, stdio: ["ignore", "pipe", "ignore"] });
7
+ if (run.error || run.status !== 0) return undefined;
8
+ const login = run.stdout.trim();
9
+ return login === "" ? undefined : login;
10
+ } catch {
11
+ return undefined;
12
+ }
13
+ }
@@ -6,14 +6,28 @@ import { posix } from "node:path";
6
6
 
7
7
  export type InitMode = "github" | "local" | "both";
8
8
 
9
+ /** The shape of the repository. Metadata only for now: nothing else in Wachiman reads it. */
10
+ export type ProjectKind = "monorepo" | "single";
11
+ export const projectKinds: readonly ProjectKind[] = ["monorepo", "single"];
12
+
13
+ /** Why `kind` cannot be recorded, or undefined when it can. */
14
+ export function projectKindProblem(kind: string): string | undefined {
15
+ if (projectKinds.includes(kind as ProjectKind)) return undefined;
16
+ if (kind === "distributed") return '--project-kind distributed is not available yet; use monorepo or single.';
17
+ return `--project-kind must be monorepo or single, got "${kind}".`;
18
+ }
19
+
9
20
  export interface RawInitFlags {
10
21
  mode?: string;
11
22
  operator?: string;
12
23
  version?: string;
13
24
  path?: string;
25
+ projectKind?: string;
14
26
  force?: boolean;
15
27
  dryRun?: boolean;
16
28
  yes?: boolean;
29
+ /** `--pr-template` is true, `--no-pr-template` is false; absent means not given. */
30
+ prTemplate?: boolean;
17
31
  repoDir?: string;
18
32
  help?: boolean;
19
33
  }
@@ -22,6 +36,10 @@ export interface InitOptions {
22
36
  mode: InitMode;
23
37
  /** Present iff mode !== "local". */
24
38
  github?: { operator: string; tag: string; path: string; force: boolean; dryRun: boolean };
39
+ /** Install the PR description template after the workflow work. Absent means no: a script that did not ask gets no new file. */
40
+ prTemplate?: boolean;
41
+ /** Present iff the kind was given (flag or answer); then `.wachiman.yml` is written or checked. `force` allows changing a different `kind:` without asking. */
42
+ settings?: { kind: ProjectKind; force: boolean };
25
43
  repoDir: string;
26
44
  interactive: boolean;
27
45
  }
@@ -34,7 +52,7 @@ export type ResolveResult<T> = { ok: true; options: T } | { ok: false; error: st
34
52
  * docs/releasing.md); the CLI's own version is never a substitute,
35
53
  * because an unreleased or unrelated version would pin a workflow that does not exist.
36
54
  */
37
- export const DEFAULT_WORKFLOW_REF: string | undefined = "v1.15.0"; // x-release-please-version
55
+ export const DEFAULT_WORKFLOW_REF: string | undefined = "v1.16.0"; // x-release-please-version
38
56
 
39
57
  export const DEFAULT_WORKFLOW_PATH = ".github/workflows/wachiman-review.yml";
40
58
  const WORKFLOWS_DIR = ".github/workflows/";
@@ -86,11 +104,19 @@ export function resolveInitOptions(
86
104
  if (!initModes.includes(flags.mode as InitMode)) return fail(`--mode must be github, local or both, got "${flags.mode}".`);
87
105
  const mode = flags.mode as InitMode;
88
106
  const repoDir = flags.repoDir ?? ".";
107
+ const templateOption = flags.prTemplate === true ? { prTemplate: true } : {};
108
+ if (flags.projectKind !== undefined) {
109
+ const kindError = projectKindProblem(flags.projectKind);
110
+ if (kindError) return fail(kindError);
111
+ }
112
+ const settings = flags.projectKind === undefined ? undefined : { kind: flags.projectKind as ProjectKind, force: flags.force === true };
89
113
 
90
114
  if (mode === "local") {
91
- const given = GITHUB_ONLY_FLAGS.filter(([key]) => flags[key] !== undefined && flags[key] !== false).map(([, name]) => name);
115
+ // With a kind, --force means "change a different kind in the settings file", which local mode does write.
116
+ const given = GITHUB_ONLY_FLAGS.filter(([key]) => flags[key] !== undefined && flags[key] !== false && !(key === "force" && settings))
117
+ .map(([, name]) => name);
92
118
  if (given.length > 0) return fail(`${given.join(", ")} only apply to a workflow; --mode local writes none. Drop them, or use --mode github or both.`);
93
- return { ok: true, options: { mode, repoDir, interactive: ctx.interactive } };
119
+ return { ok: true, options: { mode, ...templateOption, ...(settings ? { settings } : {}), repoDir, interactive: ctx.interactive } };
94
120
  }
95
121
 
96
122
  if (flags.operator === undefined) return fail(`init --mode ${mode} needs --operator <github login> when it cannot ask: the one person whose /wachiman comments start a run.`);
@@ -117,6 +143,8 @@ export function resolveInitOptions(
117
143
  options: {
118
144
  mode,
119
145
  github: { operator: flags.operator, tag, path: path.path, force: flags.force === true, dryRun: flags.dryRun === true },
146
+ ...templateOption,
147
+ ...(settings ? { settings } : {}),
120
148
  repoDir,
121
149
  interactive: ctx.interactive,
122
150
  },
@@ -1,11 +1,12 @@
1
1
  import { UsageError } from "../config";
2
2
  import type { Prompter } from "../wizard/prompt";
3
- import { DEFAULT_WORKFLOW_PATH, initModes, normaliseWorkflowPath, operatorProblem, tagProblem, type InitMode, type RawInitFlags } from "./options";
3
+ import { DEFAULT_WORKFLOW_PATH, initModes, normaliseWorkflowPath, operatorProblem, projectKindProblem, tagProblem, type InitMode, type ProjectKind, type RawInitFlags } from "./options";
4
4
 
5
5
  /** The values given on the command line are held to the same rules as answers: a bad one is exit 2, never silently asked again. */
6
6
  export function checkSupplied(flags: RawInitFlags) {
7
7
  if (flags.mode !== undefined && !initModes.includes(flags.mode as InitMode)) throw new UsageError(`--mode must be github, local or both, got "${flags.mode}".`);
8
8
  const problem =
9
+ (flags.projectKind !== undefined ? projectKindProblem(flags.projectKind) : undefined) ??
9
10
  (flags.operator !== undefined ? operatorProblem(flags.operator) : undefined) ??
10
11
  (flags.version !== undefined ? tagProblem(flags.version) : undefined) ??
11
12
  (flags.path !== undefined ? (() => { const p = normaliseWorkflowPath(flags.path!); return p.ok ? undefined : p.problem; })() : undefined);
@@ -17,9 +18,26 @@ export function checkSupplied(flags: RawInitFlags) {
17
18
  * (`null`: the person cancelled). Answers are validated as they are typed; the pure resolver
18
19
  * validates everything again.
19
20
  */
20
- export async function promptForInit(flags: RawInitFlags, ctx: { defaultWorkflowRef?: string }, prompter: Prompter): Promise<RawInitFlags | null> {
21
+ export async function promptForInit(flags: RawInitFlags, ctx: { defaultWorkflowRef?: string; githubLogin?: () => string | undefined }, prompter: Prompter): Promise<RawInitFlags | null> {
21
22
  checkSupplied(flags);
22
- prompter.step("Review mode", 2);
23
+ prompter.step("Project type", 2);
24
+ let projectKind = flags.projectKind as ProjectKind | undefined;
25
+ if (projectKind === undefined) {
26
+ const picked = await prompter.select<ProjectKind | "distributed">(
27
+ "What kind of repository is this?",
28
+ [
29
+ { label: "Monorepo", value: "monorepo" },
30
+ { label: "Single project", value: "single" },
31
+ { label: "Distributed repository", value: "distributed", disabled: true },
32
+ ],
33
+ 0,
34
+ );
35
+ if (picked === null) return null;
36
+ projectKind = picked as ProjectKind;
37
+ }
38
+ flags = { ...flags, projectKind };
39
+
40
+ prompter.step("Review mode", 3);
23
41
  let mode = flags.mode as InitMode | undefined;
24
42
  if (mode === undefined) {
25
43
  const picked = await prompter.select<InitMode>(
@@ -34,21 +52,34 @@ export async function promptForInit(flags: RawInitFlags, ctx: { defaultWorkflowR
34
52
  if (picked === null) return null;
35
53
  mode = picked;
36
54
  }
37
- if (mode === "local") return { ...flags, mode };
55
+ if (mode === "local") {
56
+ const prTemplate = await askPrTemplate(flags, prompter);
57
+ return prTemplate === null ? null : { ...flags, mode, prTemplate };
58
+ }
38
59
 
39
- prompter.step("GitHub workflow", 3, mode === "both" ? 6 : 4);
60
+ prompter.step("GitHub workflow", 4, mode === "both" ? 6 : 5);
40
61
 
62
+ // The signed-in `gh` user is the likely answer; a login that fails the same rule is not offered.
63
+ // `gh` is only spawned when the operator is going to be asked: `--operator` makes the guess useless.
64
+ const guess = flags.operator === undefined ? ctx.githubLogin?.() : undefined;
65
+ const suggested = guess !== undefined && operatorProblem(guess) === undefined ? guess : undefined;
66
+ if (suggested !== undefined) prompter.say(`Signed in to GitHub as https://github.com/${suggested}; press Enter to use it.`, "muted");
41
67
  const operator =
42
- flags.operator ?? (await prompter.text("GitHub login of the operator (the one person whose /wachiman comments start a run)", undefined, (v) => operatorProblem(v)));
68
+ flags.operator ??
69
+ (await prompter.text("Your GitHub username, as in https://github.com/<username>: only this person's /wachiman comments start a paid run", suggested, (v) => operatorProblem(v)));
43
70
  if (operator === null) return null;
44
- const version = flags.version ?? (await prompter.text("Release tag to pin", ctx.defaultWorkflowRef, (v) => tagProblem(v)));
71
+ // The release this CLI was published as, and the standard workflow path: neither is asked. `--version` and `--path` still override them.
72
+ const version = flags.version ?? ctx.defaultWorkflowRef ?? (await prompter.text("Release tag to pin", undefined, (v) => tagProblem(v)));
45
73
  if (version === null) return null;
46
- const path =
47
- flags.path ??
48
- (await prompter.text("Workflow file", DEFAULT_WORKFLOW_PATH, (v) => {
49
- const p = normaliseWorkflowPath(v);
50
- return p.ok ? undefined : p.problem;
51
- }));
52
- if (path === null) return null;
53
- return { ...flags, mode, operator, version, path };
74
+ const path = flags.path ?? DEFAULT_WORKFLOW_PATH;
75
+ const prTemplate = await askPrTemplate(flags, prompter);
76
+ return prTemplate === null ? null : { ...flags, mode, operator, version, path, prTemplate };
77
+ }
78
+
79
+ /** The flag when it was given; otherwise the question (`null`: cancelled). Asked once, in every mode, because the template belongs to the repository, not to a review mode. */
80
+ async function askPrTemplate(flags: RawInitFlags, prompter: Prompter): Promise<boolean | null> {
81
+ if (flags.prTemplate !== undefined) return flags.prTemplate;
82
+ // A dry run writes nothing, so it asks nothing about a file.
83
+ if (flags.dryRun) return false;
84
+ return prompter.confirm("Also install the PR description template? An existing .github/pull_request_template.md is adopted and replaced (a backup is kept); nothing is committed.", true);
54
85
  }