co-maintainer 0.5.2 → 0.5.4

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 (50) hide show
  1. package/dist/package.json +2 -4
  2. package/dist/src/cli/args.js +1 -0
  3. package/dist/src/cli/commands/clear.d.ts +1 -0
  4. package/dist/src/cli/commands/clear.js +152 -0
  5. package/dist/src/cli/commands/registry.d.ts +4 -0
  6. package/dist/src/cli/commands/registry.js +81 -0
  7. package/dist/src/cli/commands/set.js +102 -1
  8. package/dist/src/cli/commands/uninstall.d.ts +1 -0
  9. package/dist/src/cli/commands/uninstall.js +43 -0
  10. package/dist/src/cli/main.js +10 -0
  11. package/dist/src/cli/review_args.d.ts +15 -0
  12. package/dist/src/cli/review_args.js +41 -1
  13. package/dist/src/config.d.ts +21 -0
  14. package/dist/src/config.js +38 -1
  15. package/dist/src/local/review_local.js +4 -1
  16. package/dist/src/local/review_lock.js +2 -2
  17. package/dist/src/pr/reviewer.js +3 -2
  18. package/dist/src/remote/client.js +14 -1
  19. package/dist/src/remote/schema.d.ts +3 -0
  20. package/dist/src/remote/schema.js +3 -0
  21. package/dist/src/remote/validate.js +12 -1
  22. package/dist/src/review/system_prompt.d.ts +19 -0
  23. package/dist/src/review/system_prompt.js +34 -0
  24. package/dist/src/server/api/knowledge.d.ts +7 -0
  25. package/dist/src/server/api/knowledge.js +68 -0
  26. package/dist/src/server/api/repos.js +61 -2
  27. package/dist/src/server/app.js +4 -0
  28. package/dist/src/server/pages/client.d.ts +1 -1
  29. package/dist/src/server/pages/client.js +1 -1
  30. package/dist/src/server/pages/knowledge.js +20 -1
  31. package/dist/src/server/pages/repo_settings.js +31 -0
  32. package/dist/src/server/pages/settings.js +18 -0
  33. package/dist/src/services/clear.d.ts +70 -0
  34. package/dist/src/services/clear.js +310 -0
  35. package/dist/src/services/remote_review.js +30 -1
  36. package/dist/src/services/review.js +1 -0
  37. package/dist/src/store/app_db.d.ts +3 -0
  38. package/dist/src/store/app_db.js +5 -0
  39. package/dist/src/store/cache_db.d.ts +11 -0
  40. package/dist/src/store/cache_db.js +60 -1
  41. package/dist/src/store/migrations.js +7 -0
  42. package/dist/src/store/remote_review_inputs.d.ts +2 -0
  43. package/dist/src/store/remote_review_inputs.js +3 -3
  44. package/dist/src/store/repos.d.ts +3 -0
  45. package/dist/src/store/repos.js +8 -0
  46. package/dist/src/store/rows.d.ts +3 -0
  47. package/dist/src/types.d.ts +11 -0
  48. package/dist/src/util/runtime.d.ts +3 -0
  49. package/dist/src/util/runtime.js +6 -1
  50. package/package.json +2 -4
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "co-maintainer",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "An imitator of yours, A PR review tool like co-maintainer.",
5
5
  "keywords": [
6
6
  "ai",
@@ -59,11 +59,9 @@
59
59
  "dx:scenario": "node scripts/dx_scenario.ts",
60
60
  "dashboard:smoke": "node scripts/dashboard_smoke.ts"
61
61
  },
62
- "dependencies": {
63
- "marked": "^15.0.7"
64
- },
65
62
  "devDependencies": {
66
63
  "@types/node": "^24.0.0",
64
+ "marked": "^15.0.7",
67
65
  "oxfmt": "^0.68.0",
68
66
  "oxlint": "^1.83.0",
69
67
  "playwright": "^1.63.0",
@@ -282,5 +282,6 @@ export async function parseArgs(args) {
282
282
  configDefault.maxPullRequestChangeLines,
283
283
  maxComments: value("max-comment") ?? repoConfig.maxComments,
284
284
  reviewBlocking,
285
+ reviewSystemPrompt: repoConfig.reviewSystemPrompt,
285
286
  };
286
287
  }
@@ -0,0 +1 @@
1
+ export declare function runClear(args: string[]): Promise<void>;
@@ -0,0 +1,152 @@
1
+ /** `co-maintainer clear`: delete what `init` produced.
2
+ *
3
+ * A repository goes back to "never inited": guides, the knowledge stamp, the
4
+ * skill state and the settings `init` remembered are gone, so the next build
5
+ * is `init`, not `sync`. `--include-cache` reaches further and takes the
6
+ * fetched evidence too, which makes that next init a cold build.
7
+ *
8
+ * `all` touches every repository on the machine, so it asks first. Pending
9
+ * jobs are asked about separately because they would otherwise rebuild the
10
+ * knowledge after it was cleared. */
11
+ import { CliError, EXIT_USAGE } from "../error.js";
12
+ import { askConfirm } from "../prompt.js";
13
+ import { canPrompt } from "../../tools/codegraph.js";
14
+ import { liveLockPid } from "../../store/app_db.js";
15
+ import { unknownOptionMessage } from "./registry.js";
16
+ import { cancelOrphanedJobs, cancelQueuedJobs, clearRepos, clearRepo, isSafeRepoName, listStoredRepos, repoJobs, withAppDbIfPresent, } from "../../services/clear.js";
17
+ /** "3 guides, 1 cache row, saved settings" without a trailing separator. */
18
+ function joinParts(parts) {
19
+ return parts.join(", ");
20
+ }
21
+ function repoParts(result) {
22
+ const parts = [];
23
+ if (result.guides > 0)
24
+ parts.push(`${result.guides} guide file(s)`);
25
+ if (result.cacheRows > 0)
26
+ parts.push(`${result.cacheRows} cache row(s)`);
27
+ if (result.clones)
28
+ parts.push("the clone");
29
+ if (result.worktrees)
30
+ parts.push("the worktrees");
31
+ if (result.settings)
32
+ parts.push("saved settings");
33
+ return parts;
34
+ }
35
+ function printRepo(result) {
36
+ const parts = repoParts(result);
37
+ if (parts.length === 0) {
38
+ console.log(`Nothing to clear for ${result.repo}.`);
39
+ return;
40
+ }
41
+ console.log(`Cleared ${result.repo}: ${joinParts(parts)}.`);
42
+ }
43
+ function printAll(result) {
44
+ if (result.repos.length === 0) {
45
+ console.log("Nothing to clear.");
46
+ return;
47
+ }
48
+ for (const repo of result.repos) {
49
+ const parts = repoParts(repo);
50
+ if (parts.length > 0) {
51
+ console.log(`Cleared ${repo.repo}: ${joinParts(parts)}.`);
52
+ }
53
+ }
54
+ const extra = [];
55
+ if (result.cacheFile)
56
+ extra.push("cache.db");
57
+ if (result.clones)
58
+ extra.push("every clone");
59
+ if (result.worktrees)
60
+ extra.push("every worktree");
61
+ if (result.settings)
62
+ extra.push("saved settings");
63
+ const tail = extra.length > 0 ? ` Also cleared ${joinParts(extra)}.` : "";
64
+ console.log(`Cleared ${result.repos.length} repositories.${tail}`);
65
+ }
66
+ /** What the pending-job question should say. */
67
+ function jobSummary(repos) {
68
+ const jobs = repoJobs(repos);
69
+ const parts = [];
70
+ if (jobs.queued.length > 0)
71
+ parts.push(`${jobs.queued.length} queued`);
72
+ if (jobs.running.length > 0)
73
+ parts.push(`${jobs.running.length} unfinished`);
74
+ if (parts.length === 0)
75
+ return undefined;
76
+ return `This target has ${joinParts(parts)} job(s).`;
77
+ }
78
+ /** Pending jobs would rebuild the knowledge this command is deleting. The
79
+ * question is asked once for the whole target. Without a terminal (or with
80
+ * `--yes`) they are canceled: keeping them would contradict the clear. */
81
+ async function handlePendingJobs(repos, assumeYes) {
82
+ await withAppDbIfPresent(async () => {
83
+ const summary = jobSummary(repos);
84
+ if (summary === undefined)
85
+ return;
86
+ const cancelThem = !canPrompt()
87
+ ? true
88
+ : assumeYes || (await askConfirm(`${summary} Cancel them?`));
89
+ if (!cancelThem) {
90
+ console.log("Pending jobs were kept. They can rebuild the knowledge later.");
91
+ return;
92
+ }
93
+ const canceled = cancelQueuedJobs(repos) + cancelOrphanedJobs(repos);
94
+ if (canceled > 0)
95
+ console.log(`Canceled ${canceled} job(s).`);
96
+ });
97
+ }
98
+ export async function runClear(args) {
99
+ let includeCache = false;
100
+ let yes = false;
101
+ const positionals = [];
102
+ for (const arg of args) {
103
+ if (arg === "--include-cache") {
104
+ includeCache = true;
105
+ continue;
106
+ }
107
+ if (arg === "--yes") {
108
+ yes = true;
109
+ continue;
110
+ }
111
+ if (arg.startsWith("-")) {
112
+ throw new CliError("usage", unknownOptionMessage(arg, "clear"));
113
+ }
114
+ positionals.push(arg);
115
+ }
116
+ const target = positionals[0];
117
+ if (positionals.length !== 1 || !target) {
118
+ throw new CliError("usage", "clear needs one target: owner/repo or all.", "Usage: co-maintainer clear <owner/repo|all> [--include-cache] [--yes]");
119
+ }
120
+ const all = target === "all";
121
+ if (!all && !isSafeRepoName(target)) {
122
+ throw new CliError("usage", "Repository must look like owner/repo");
123
+ }
124
+ // A live serve owns guides and caches: clearing underneath it would confuse
125
+ // webhooks and remote clients mid-flight. The same guard rollback uses.
126
+ const pid = await liveLockPid();
127
+ if (pid !== undefined) {
128
+ throw new CliError("serve_already_running", `A co-maintainer serve process (pid ${pid}) is using this data directory.`, "Stop it, then run clear again.", EXIT_USAGE);
129
+ }
130
+ const repos = all ? await listStoredRepos() : [target];
131
+ if (all && !yes) {
132
+ if (!canPrompt()) {
133
+ throw new CliError("confirmation_required", "clear all needs your confirmation.", "Run it in a terminal, or pass --yes.", EXIT_USAGE);
134
+ }
135
+ const scope = includeCache
136
+ ? "guides, settings, cached evidence, clones and worktrees"
137
+ : "guides and saved settings";
138
+ console.log(`This deletes the ${scope} of ${repos.length} repositories on this machine.`);
139
+ if (!(await askConfirm("Clear them?"))) {
140
+ console.log("Nothing changed.");
141
+ return;
142
+ }
143
+ }
144
+ await handlePendingJobs(repos, yes);
145
+ // The snapshot the jobs were negotiated against is the one that gets
146
+ // cleared, so the printed count matches what actually went.
147
+ if (all)
148
+ printAll(await clearRepos(repos, { includeCache }));
149
+ else
150
+ printRepo(await clearRepo(target, { includeCache }));
151
+ console.log(`Run co-maintainer init ${all ? "owner/repo" : target} to build the guides again.`);
152
+ }
@@ -30,6 +30,10 @@ export declare function findCommand(name: string): CommandSpec | undefined;
30
30
  /** Commands listed in the global help. A hidden alias or command is resolvable
31
31
  * but invisible. */
32
32
  export declare function visibleCommands(): CommandSpec[];
33
+ /** The visible command names in help order. Tests and scripts iterate this
34
+ * instead of repeating the list, so a new command cannot be forgotten in one
35
+ * place and present in another. */
36
+ export declare function visibleCommandNames(): string[];
33
37
  /** Levenshtein distance, iterative and allocation-light: the help path runs it
34
38
  * on every unknown token, and the strings are short. */
35
39
  export declare function levenshtein(a: string, b: string): number;
@@ -355,6 +355,21 @@ export const COMMANDS = [
355
355
  },
356
356
  ],
357
357
  },
358
+ {
359
+ title: "Custom instructions",
360
+ flags: [
361
+ {
362
+ name: "system-prompt-file",
363
+ value: "PATH",
364
+ description: "Append this file's contents to the review instructions for this run only.",
365
+ },
366
+ {
367
+ name: "system-prompt-override-file",
368
+ value: "PATH",
369
+ description: "Replace the repository's review instructions with this file for this run only. The built-in instructions are kept.",
370
+ },
371
+ ],
372
+ },
358
373
  AI_FLAGS,
359
374
  GITHUB_FLAGS,
360
375
  REVIEW_OUTPUT_FLAGS,
@@ -366,6 +381,8 @@ export const COMMANDS = [
366
381
  "co-maintainer review --remote --remote-host=https://review.example.com --remote-token=cmr_...",
367
382
  "co-maintainer review --remote --remote-byok --json",
368
383
  "co-maintainer review --remote --output=github",
384
+ "co-maintainer review owner/repo 42 --system-prompt-file=extra.md",
385
+ "co-maintainer review --system-prompt-override-file=strict.md",
369
386
  ],
370
387
  },
371
388
  {
@@ -430,6 +447,48 @@ export const COMMANDS = [
430
447
  "co-maintainer view owner/repo --remote",
431
448
  ],
432
449
  },
450
+ {
451
+ name: "clear",
452
+ summary: "Delete the generated guides and saved settings for a repository, or for every repository.",
453
+ usage: ["co-maintainer clear <owner/repo|all> [options]"],
454
+ groups: [
455
+ {
456
+ title: "Clear",
457
+ flags: [
458
+ {
459
+ name: "include-cache",
460
+ description: "Also delete the fetched evidence: pull request listings, AI job cache, costs, local review carry-over, clones and worktrees. The next init is then a cold build.",
461
+ },
462
+ {
463
+ name: "yes",
464
+ description: "Skip the confirmation `all` asks. Needed when there is no terminal.",
465
+ },
466
+ ],
467
+ },
468
+ ],
469
+ examples: [
470
+ "co-maintainer clear owner/repo",
471
+ "co-maintainer clear owner/repo --include-cache",
472
+ "co-maintainer clear all --include-cache --yes",
473
+ ],
474
+ },
475
+ {
476
+ name: "uninstall",
477
+ summary: "Delete every co-maintainer data file on this machine.",
478
+ usage: ["co-maintainer uninstall [--yes]"],
479
+ groups: [
480
+ {
481
+ title: "Uninstall",
482
+ flags: [
483
+ {
484
+ name: "yes",
485
+ description: "Skip the confirmation. Needed when there is no terminal.",
486
+ },
487
+ ],
488
+ },
489
+ ],
490
+ examples: ["co-maintainer uninstall", "co-maintainer uninstall --yes"],
491
+ },
433
492
  {
434
493
  name: "set",
435
494
  summary: "Persist defaults and secrets to the user config file.",
@@ -517,6 +576,21 @@ export const COMMANDS = [
517
576
  value: "PATH",
518
577
  description: "Read a custom review policy from a JSON file and use it as that default.",
519
578
  },
579
+ {
580
+ name: "repo",
581
+ value: "owner/repo",
582
+ description: "Write the repository-scoped settings below to this repository instead of the global config.",
583
+ },
584
+ {
585
+ name: "review-system-prompt",
586
+ value: "TEXT",
587
+ description: "A repository's own review instructions. Needs --repo. Empty clears it.",
588
+ },
589
+ {
590
+ name: "review-system-prompt-max-chars",
591
+ value: "N",
592
+ description: "Cap the repository's review instructions in characters. Needs --repo. 0 or -1 means no limit.",
593
+ },
520
594
  {
521
595
  name: "review-blocking",
522
596
  value: "model|severity",
@@ -553,6 +627,7 @@ export const COMMANDS = [
553
627
  examples: [
554
628
  "co-maintainer set --ai=openrouter --ai-key=... --low-model=... --high-model=...",
555
629
  "co-maintainer set --remote-host=https://review.example.com --remote-token=...",
630
+ "co-maintainer set --repo=owner/repo --review-system-prompt='Focus on the parser.'",
556
631
  "co-maintainer set --unset=token",
557
632
  ],
558
633
  },
@@ -644,6 +719,12 @@ export function findCommand(name) {
644
719
  export function visibleCommands() {
645
720
  return COMMANDS.filter((command) => !command.hidden);
646
721
  }
722
+ /** The visible command names in help order. Tests and scripts iterate this
723
+ * instead of repeating the list, so a new command cannot be forgotten in one
724
+ * place and present in another. */
725
+ export function visibleCommandNames() {
726
+ return visibleCommands().map((command) => command.name);
727
+ }
647
728
  /** Levenshtein distance, iterative and allocation-light: the help path runs it
648
729
  * on every unknown token, and the strings are short. */
649
730
  export function levenshtein(a, b) {
@@ -1,4 +1,5 @@
1
- import { readConfig, configPath, savedKeyProvider, writeUserConfig, } from "../../config.js";
1
+ import { readConfig, configPath, savedKeyProvider, writeRepoConfig, writeUserConfig, } from "../../config.js";
2
+ import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../../review/system_prompt.js";
2
3
  import { hashPassword, passwordProblem } from "../../util/password.js";
3
4
  import { readTextFile } from "../../util/runtime.js";
4
5
  import { verifyAnthropic, verifyOpenAi, verifyOpenRouter, } from "../../ai/verify.js";
@@ -60,6 +61,9 @@ export async function runSet(args) {
60
61
  "review-policy",
61
62
  "review-policy-file",
62
63
  "review-blocking",
64
+ "repo",
65
+ "review-system-prompt",
66
+ "review-system-prompt-max-chars",
63
67
  "password",
64
68
  "unset",
65
69
  ];
@@ -72,6 +76,13 @@ export async function runSet(args) {
72
76
  die(`Unknown option: ${arg}`);
73
77
  }
74
78
  }
79
+ // `--repo` turns `set` into a write to `repos[owner/repo]` in config.json.
80
+ // Only the repository-scoped settings are accepted alongside it.
81
+ const repoArg = text(args, "repo");
82
+ if (repoArg !== undefined) {
83
+ await runSetRepo(repoArg, args);
84
+ return;
85
+ }
75
86
  const ai = text(args, "ai");
76
87
  rejectRetiredProvider(ai);
77
88
  if (ai && !AI_PROVIDERS.includes(ai)) {
@@ -299,3 +310,93 @@ export async function runSet(args) {
299
310
  console.log(`[set] updated: ${summary.join(", ")}`);
300
311
  console.log(`Saved to ${configPath()}`);
301
312
  }
313
+ /** Flag names that make sense together with `--repo`. Anything else is a
314
+ * global setting and is refused rather than silently written to the wrong
315
+ * place. */
316
+ const REPO_SCOPED_FLAGS = new Set([
317
+ "repo",
318
+ "review-system-prompt",
319
+ "review-system-prompt-max-chars",
320
+ "unset",
321
+ "no-verify",
322
+ ]);
323
+ /** The `--unset=name` values that address a repository-scoped field. */
324
+ const REPO_SCOPED_UNSET = new Set([
325
+ "review-system-prompt",
326
+ "reviewSystemPrompt",
327
+ "review-system-prompt-max-chars",
328
+ "reviewSystemPromptMaxChars",
329
+ ]);
330
+ /** `set --repo=owner/repo [--review-system-prompt=... | --review-system-prompt-max-chars=N | --unset=name]`
331
+ * writes the repository-scoped settings to `repos[owner/repo]` in config.json
332
+ * instead of the global config. */
333
+ async function runSetRepo(repo, args) {
334
+ if (!/^[^/]+\/[^/]+$/.test(repo))
335
+ die("--repo must look like owner/repo");
336
+ for (const arg of args) {
337
+ if (!arg.startsWith("--"))
338
+ continue;
339
+ const name = arg.slice(2).split("=")[0];
340
+ if (!REPO_SCOPED_FLAGS.has(name)) {
341
+ die(`--${name} cannot be used with --repo`);
342
+ }
343
+ if (name === "unset") {
344
+ const value = arg.slice("--unset=".length);
345
+ if (!REPO_SCOPED_UNSET.has(value)) {
346
+ die(`--unset=${value} cannot be used with --repo`);
347
+ }
348
+ }
349
+ }
350
+ const unset = new Set(args
351
+ .filter((arg) => arg.startsWith("--unset="))
352
+ .map((arg) => arg.slice("--unset=".length)));
353
+ const existing = readConfig().repos?.[repo] ?? {};
354
+ const patch = {};
355
+ // Unset first, then explicit values win, so `--unset=x --x=...` sets.
356
+ if (unset.has("review-system-prompt") || unset.has("reviewSystemPrompt")) {
357
+ patch.reviewSystemPrompt = undefined;
358
+ }
359
+ if (unset.has("review-system-prompt-max-chars") ||
360
+ unset.has("reviewSystemPromptMaxChars")) {
361
+ patch.reviewSystemPromptMaxChars = undefined;
362
+ }
363
+ const maxRaw = text(args, "review-system-prompt-max-chars");
364
+ if (maxRaw !== undefined) {
365
+ // Blank clears it, the same as an empty value on the dashboard form.
366
+ if (maxRaw.trim() === "") {
367
+ patch.reviewSystemPromptMaxChars = undefined;
368
+ }
369
+ else {
370
+ const value = Number(maxRaw);
371
+ if (!Number.isInteger(value)) {
372
+ die("--review-system-prompt-max-chars must be an integer (0 or -1 for no limit)");
373
+ }
374
+ patch.reviewSystemPromptMaxChars = value;
375
+ }
376
+ }
377
+ const prompt = text(args, "review-system-prompt");
378
+ if (prompt !== undefined) {
379
+ patch.reviewSystemPrompt = prompt.trim() === "" ? undefined : prompt;
380
+ }
381
+ if (Object.keys(patch).length === 0) {
382
+ die("Nothing to set. Pass --review-system-prompt=, --review-system-prompt-max-chars=N, or --unset=name with --repo.");
383
+ }
384
+ // The values after this write are the ones given here, or the stored ones.
385
+ // Lowering the cap re-checks the stored prompt too, so it cannot end up over
386
+ // the cap it is measured against.
387
+ const effectiveMax = "reviewSystemPromptMaxChars" in patch
388
+ ? patch.reviewSystemPromptMaxChars
389
+ : existing.reviewSystemPromptMaxChars;
390
+ const effectivePrompt = "reviewSystemPrompt" in patch
391
+ ? patch.reviewSystemPrompt
392
+ : existing.reviewSystemPrompt;
393
+ if (effectivePrompt !== undefined) {
394
+ const problem = checkReviewSystemPrompt(effectivePrompt, reviewSystemPromptLimit({ reviewSystemPromptMaxChars: effectiveMax }));
395
+ if (problem)
396
+ die(`--review-system-prompt: ${problem}`);
397
+ }
398
+ await writeRepoConfig(repo, patch);
399
+ const summary = Object.entries(patch).map(([key, value]) => value === undefined ? `${key} (unset)` : `${key}=${value}`);
400
+ console.log(`[set] updated ${repo}: ${summary.join(", ")}`);
401
+ console.log(`Saved to ${configPath()}`);
402
+ }
@@ -0,0 +1 @@
1
+ export declare function runUninstall(args: string[]): Promise<void>;
@@ -0,0 +1,43 @@
1
+ /** `co-maintainer uninstall`: delete every data file this machine holds.
2
+ *
3
+ * The npm package cannot remove itself while the CLI runs from it, so the
4
+ * command deletes the config, databases, guides, clones, worktrees and tools
5
+ * and then prints the npm command that finishes the job. */
6
+ import { CliError, EXIT_USAGE } from "../error.js";
7
+ import { askConfirm } from "../prompt.js";
8
+ import { canPrompt } from "../../tools/codegraph.js";
9
+ import { liveLockPid } from "../../store/app_db.js";
10
+ import { unknownOptionMessage } from "./registry.js";
11
+ import { uninstallData } from "../../services/clear.js";
12
+ export async function runUninstall(args) {
13
+ for (const arg of args) {
14
+ if (arg !== "--yes") {
15
+ throw new CliError("usage", unknownOptionMessage(arg, "uninstall"));
16
+ }
17
+ }
18
+ const pid = await liveLockPid();
19
+ if (pid !== undefined) {
20
+ throw new CliError("serve_already_running", `A co-maintainer serve process (pid ${pid}) is using this data directory.`, "Stop it, then run uninstall again.", EXIT_USAGE);
21
+ }
22
+ if (!args.includes("--yes")) {
23
+ if (!canPrompt()) {
24
+ throw new CliError("confirmation_required", "Uninstall needs your confirmation.", "Run it in a terminal, or pass --yes.", EXIT_USAGE);
25
+ }
26
+ console.log("This deletes every co-maintainer data file: config.json, the databases, guides, clones, worktrees and tools.");
27
+ if (!(await askConfirm("Uninstall?"))) {
28
+ console.log("Nothing changed.");
29
+ return;
30
+ }
31
+ }
32
+ const removed = await uninstallData();
33
+ if (removed.paths.length === 0) {
34
+ console.log("Nothing to remove.");
35
+ }
36
+ else {
37
+ console.log("Removed:");
38
+ for (const path of removed.paths)
39
+ console.log(` ${path}`);
40
+ }
41
+ console.log("The CLI itself is still installed. Remove it with:");
42
+ console.log(" npm uninstall -g co-maintainer");
43
+ }
@@ -6,6 +6,8 @@ import { runRollback } from "./commands/rollback.js";
6
6
  import { runSet } from "./commands/set.js";
7
7
  import { runConfig } from "./commands/config.js";
8
8
  import { runView } from "./commands/view.js";
9
+ import { runClear } from "./commands/clear.js";
10
+ import { runUninstall } from "./commands/uninstall.js";
9
11
  import { runProbe } from "./commands/probe.js";
10
12
  import { runReviewFromCli } from "./commands/review.js";
11
13
  import { runInitOrRemake } from "../services/setup.js";
@@ -68,6 +70,14 @@ export async function run(args) {
68
70
  await runView(args.slice(1));
69
71
  return;
70
72
  }
73
+ if (args[0] === "clear") {
74
+ await runClear(args.slice(1));
75
+ return;
76
+ }
77
+ if (args[0] === "uninstall") {
78
+ await runUninstall(args.slice(1));
79
+ return;
80
+ }
71
81
  if (args[0] === "serve") {
72
82
  await runServe(args.slice(1));
73
83
  return;
@@ -20,6 +20,12 @@ type ReviewFlags = {
20
20
  /** `--output=github`: workflow commands and a job summary instead of prose.
21
21
  */
22
22
  output?: "github";
23
+ /** `--system-prompt-file`: a file whose contents are appended to the
24
+ * custom review section for this run only. */
25
+ systemPromptFile?: string;
26
+ /** `--system-prompt-override-file`: a file whose contents replace the
27
+ * repository's custom review section for this run only. */
28
+ systemPromptOverrideFile?: string;
23
29
  };
24
30
  export type ReviewCliArgs = ({
25
31
  mode: "pr";
@@ -33,6 +39,15 @@ export type ReviewCliArgs = ({
33
39
  } & ReviewFlags);
34
40
  /** Strip local-only flags before `parseArgs` for PR-style options. */
35
41
  export declare function filterReviewConfigArgs(raw: string[]): string[];
42
+ /** The repository's custom-prompt cap, read from config.json. */
43
+ export declare function reviewSystemPromptLimitFor(repo: string): number | null;
44
+ /** Reads the per-run system-prompt files and checks each against the
45
+ * repository's cap. `die`s naming the flag when a file cannot be read or is
46
+ * over the cap. */
47
+ export declare function loadReviewSystemPromptFlags(cli: Pick<ReviewFlags, "systemPromptFile" | "systemPromptOverrideFile">, limit: number | null): Promise<{
48
+ add?: string;
49
+ override?: string;
50
+ }>;
36
51
  /** Parses `co-maintainer review` after the `review` token. */
37
52
  export declare function parseReviewArgs(args: string[]): Promise<ReviewCliArgs>;
38
53
  export {};
@@ -1,5 +1,8 @@
1
1
  import { parseArgs, setCliInteractive } from "./args.js";
2
2
  import { die } from "./error.js";
3
+ import { readConfig } from "../config.js";
4
+ import { readTextFile } from "../util/runtime.js";
5
+ import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../review/system_prompt.js";
3
6
  function reviewFlags(rest) {
4
7
  const text = (name) => rest.find((item) => item.startsWith(`--${name}=`))?.slice(name.length + 3);
5
8
  // `--remake-before-review` is the 0.4.13 spelling; both names mean the same
@@ -39,6 +42,8 @@ function reviewFlags(rest) {
39
42
  remoteToken: text("remote-token"),
40
43
  remoteByok: remoteByokOn ? true : remoteByokOff ? false : undefined,
41
44
  output,
45
+ systemPromptFile: text("system-prompt-file"),
46
+ systemPromptOverrideFile: text("system-prompt-override-file"),
42
47
  };
43
48
  }
44
49
  const LOCAL_ONLY_FLAGS = new Set([
@@ -62,12 +67,44 @@ export function filterReviewConfigArgs(raw) {
62
67
  arg.startsWith("--repo=") ||
63
68
  arg.startsWith("--remote-host=") ||
64
69
  arg.startsWith("--remote-token=") ||
65
- arg.startsWith("--output=")) {
70
+ arg.startsWith("--output=") ||
71
+ arg.startsWith("--system-prompt-file=") ||
72
+ arg.startsWith("--system-prompt-override-file=")) {
66
73
  return false;
67
74
  }
68
75
  return true;
69
76
  });
70
77
  }
78
+ /** The repository's custom-prompt cap, read from config.json. */
79
+ export function reviewSystemPromptLimitFor(repo) {
80
+ return reviewSystemPromptLimit(readConfig().repos?.[repo]);
81
+ }
82
+ /** Reads the per-run system-prompt files and checks each against the
83
+ * repository's cap. `die`s naming the flag when a file cannot be read or is
84
+ * over the cap. */
85
+ export async function loadReviewSystemPromptFlags(cli, limit) {
86
+ const load = async (flag, path) => {
87
+ let text;
88
+ try {
89
+ text = await readTextFile(path);
90
+ }
91
+ catch (error) {
92
+ die(`${flag}: could not read ${path}: ${String(error)}`);
93
+ }
94
+ const problem = checkReviewSystemPrompt(text, limit);
95
+ if (problem)
96
+ die(`${flag}: ${problem}`);
97
+ return text;
98
+ };
99
+ const result = {};
100
+ if (cli.systemPromptFile) {
101
+ result.add = await load("--system-prompt-file", cli.systemPromptFile);
102
+ }
103
+ if (cli.systemPromptOverrideFile) {
104
+ result.override = await load("--system-prompt-override-file", cli.systemPromptOverrideFile);
105
+ }
106
+ return result;
107
+ }
71
108
  /** Parses `co-maintainer review` after the `review` token. */
72
109
  export async function parseReviewArgs(args) {
73
110
  const positional = args.filter((a) => !a.startsWith("--"));
@@ -105,11 +142,14 @@ export async function parseReviewArgs(args) {
105
142
  if (flags.remakeBeforeReview) {
106
143
  die("--sync-before-review is not supported for PR review");
107
144
  }
145
+ const promptFlags = await loadReviewSystemPromptFlags(flags, reviewSystemPromptLimitFor(options.repo));
108
146
  return {
109
147
  mode: "pr",
110
148
  options: {
111
149
  ...options,
112
150
  useCodegraph: flags.disableCodegraph ? false : true,
151
+ reviewSystemPromptAdd: promptFlags.add,
152
+ reviewSystemPromptOverride: promptFlags.override,
113
153
  },
114
154
  ...flags,
115
155
  };
@@ -21,6 +21,13 @@ export type RepoConfig = {
21
21
  prState?: ("open" | "closed" | "merged")[];
22
22
  /** Five field cron in UTC, checked by `serve` to queue a remake. */
23
23
  remakeCron?: string;
24
+ /** A repository's own review instructions, appended to the built-in
25
+ * reviewer prompt as a `CUSTOM REVIEW INSTRUCTIONS` section. Unset or blank
26
+ * means none. */
27
+ reviewSystemPrompt?: string;
28
+ /** Cap on `reviewSystemPrompt` in characters for this repository. Unset
29
+ * means the default; `0` or a negative number means no limit. */
30
+ reviewSystemPromptMaxChars?: number;
24
31
  };
25
32
  export type UserConfig = {
26
33
  auth?: "gh" | "pat";
@@ -142,8 +149,16 @@ export declare function repoSlug(repo: string): string;
142
149
  * Windows is the roaming profile and gets synced across machines. */
143
150
  export declare function clonesDir(): string;
144
151
  export declare function cloneDir(repo: string): string;
152
+ /** The directory holding one repository's PR worktrees. `clear` removes it
153
+ * whole, so the layout lives in one place instead of at each call site. */
154
+ export declare function repoWorktreesDir(repo: string): string;
155
+ /** Every repository's worktrees, for `clear all` and `uninstall`. */
156
+ export declare function worktreesDir(): string;
145
157
  export declare function worktreeDir(repo: string, pr: number): string;
146
158
  export declare function cacheDbPath(): string;
159
+ /** Transient pid files that keep one local review per repository root.
160
+ * `uninstall` still takes them: they are co-maintainer data too. */
161
+ export declare function locksDir(): string;
147
162
  export declare function loadEnvFile(path: string): void;
148
163
  export declare function readConfig(): UserConfig;
149
164
  /** The App private key to sign with. An inline `githubAppPrivateKey` wins,
@@ -158,6 +173,12 @@ export declare function appPrivateKeyFileMissing(config: Pick<UserConfig, "githu
158
173
  /** Merges `patch` into `repos[repo]` in config.json, dropping undefined
159
174
  * fields. Never call this with a token or other secret. */
160
175
  export declare function writeRepoConfig(repo: string, patch: RepoConfig): Promise<void>;
176
+ /** Drops `repos[repo]` from config.json. `clear` uses this so the repository
177
+ * goes back to "never inited": the next run resolves its flags again. Returns
178
+ * whether there was an entry to drop. */
179
+ export declare function removeRepoConfig(repo: string): Promise<boolean>;
180
+ /** Drops every per-repo entry. `clear all` forgets every repository it knows. */
181
+ export declare function removeAllRepoConfig(): Promise<boolean>;
161
182
  /** Merges `patch` into the top-level (global, cross-repo) config —
162
183
  * used by `co-maintainer set`. This is the only path allowed to persist
163
184
  * a token. */