@oss-autopilot/core 3.42.5 → 3.43.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 (168) hide show
  1. package/dist/cli-pre-action.js +8 -3
  2. package/dist/cli-registry.js +272 -25
  3. package/dist/cli.bundle.cjs +183 -154
  4. package/dist/commands/check-integration.js +1 -0
  5. package/dist/commands/cleanup.d.ts +76 -0
  6. package/dist/commands/cleanup.js +269 -0
  7. package/dist/commands/comments.d.ts +6 -0
  8. package/dist/commands/comments.js +6 -2
  9. package/dist/commands/config.js +37 -5
  10. package/dist/commands/daily-dismiss-filter.d.ts +7 -0
  11. package/dist/commands/daily-dismiss-filter.js +17 -1
  12. package/dist/commands/daily-ledger.d.ts +122 -0
  13. package/dist/commands/daily-ledger.js +225 -0
  14. package/dist/commands/daily-recent-prs.d.ts +26 -0
  15. package/dist/commands/daily-recent-prs.js +55 -0
  16. package/dist/commands/daily.d.ts +2 -1
  17. package/dist/commands/daily.js +59 -89
  18. package/dist/commands/dashboard-cache.d.ts +2 -0
  19. package/dist/commands/dashboard-cache.js +33 -8
  20. package/dist/commands/dashboard-data.js +71 -36
  21. package/dist/commands/dashboard-gist-sync.js +3 -1
  22. package/dist/commands/dashboard-lifecycle.js +1 -1
  23. package/dist/commands/dashboard-process.d.ts +14 -1
  24. package/dist/commands/dashboard-process.js +46 -7
  25. package/dist/commands/dashboard-server.js +89 -23
  26. package/dist/commands/detect-formatters.js +1 -0
  27. package/dist/commands/dismiss.js +5 -2
  28. package/dist/commands/doctor.d.ts +15 -1
  29. package/dist/commands/doctor.js +73 -5
  30. package/dist/commands/draft.d.ts +77 -0
  31. package/dist/commands/draft.js +218 -0
  32. package/dist/commands/eval.js +1 -0
  33. package/dist/commands/guidelines.d.ts +23 -1
  34. package/dist/commands/guidelines.js +49 -4
  35. package/dist/commands/index.d.ts +24 -4
  36. package/dist/commands/index.js +15 -3
  37. package/dist/commands/issue-thread.d.ts +46 -0
  38. package/dist/commands/issue-thread.js +123 -0
  39. package/dist/commands/ledger-backfill.d.ts +9 -0
  40. package/dist/commands/ledger-backfill.js +44 -1
  41. package/dist/commands/list-mark-done.d.ts +2 -1
  42. package/dist/commands/list-mark-done.js +3 -1
  43. package/dist/commands/list-move-tier.d.ts +2 -1
  44. package/dist/commands/list-move-tier.js +3 -1
  45. package/dist/commands/local-repos.js +10 -5
  46. package/dist/commands/locate-issue-list.d.ts +40 -17
  47. package/dist/commands/locate-issue-list.js +148 -88
  48. package/dist/commands/move.js +7 -1
  49. package/dist/commands/overnight-handoff.d.ts +17 -7
  50. package/dist/commands/overnight-handoff.js +36 -14
  51. package/dist/commands/overnight-push-prep.d.ts +13 -8
  52. package/dist/commands/overnight-push-prep.js +106 -34
  53. package/dist/commands/overnight-tool-rules.d.ts +54 -0
  54. package/dist/commands/overnight-tool-rules.js +217 -0
  55. package/dist/commands/overnight.d.ts +5 -6
  56. package/dist/commands/overnight.js +61 -140
  57. package/dist/commands/parse-list.js +7 -1
  58. package/dist/commands/policy.d.ts +86 -0
  59. package/dist/commands/policy.js +263 -0
  60. package/dist/commands/pr-preflight.d.ts +43 -0
  61. package/dist/commands/pr-preflight.js +294 -0
  62. package/dist/commands/repo-vet.d.ts +9 -0
  63. package/dist/commands/repo-vet.js +36 -11
  64. package/dist/commands/scout-bridge.js +18 -8
  65. package/dist/commands/search.js +7 -0
  66. package/dist/commands/setup.d.ts +3 -3
  67. package/dist/commands/setup.js +46 -18
  68. package/dist/commands/skip-add.js +10 -1
  69. package/dist/commands/startup.d.ts +5 -3
  70. package/dist/commands/startup.js +65 -49
  71. package/dist/commands/state-cmd.d.ts +2 -0
  72. package/dist/commands/state-cmd.js +5 -1
  73. package/dist/commands/stats.js +1 -0
  74. package/dist/commands/status.js +1 -0
  75. package/dist/commands/strategy.js +1 -0
  76. package/dist/commands/vet-list.d.ts +6 -0
  77. package/dist/commands/vet-list.js +25 -0
  78. package/dist/commands/vet.d.ts +12 -0
  79. package/dist/commands/vet.js +118 -1
  80. package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
  81. package/dist/core/anti-llm-policy.d.ts +3 -0
  82. package/dist/core/anti-llm-policy.js +3 -0
  83. package/dist/core/auth.js +2 -0
  84. package/dist/core/ci-analysis.d.ts +7 -2
  85. package/dist/core/ci-analysis.js +76 -21
  86. package/dist/core/commit-date.d.ts +19 -0
  87. package/dist/core/commit-date.js +17 -0
  88. package/dist/core/config-registry.js +11 -5
  89. package/dist/core/contributing.d.ts +2 -3
  90. package/dist/core/contributing.js +2 -3
  91. package/dist/core/daily-logic.d.ts +27 -5
  92. package/dist/core/daily-logic.js +57 -19
  93. package/dist/core/errors.d.ts +37 -3
  94. package/dist/core/errors.js +54 -5
  95. package/dist/core/gist-health.d.ts +15 -3
  96. package/dist/core/gist-health.js +8 -0
  97. package/dist/core/gist-state-store.d.ts +24 -4
  98. package/dist/core/gist-state-store.js +97 -46
  99. package/dist/core/github-stats.d.ts +104 -16
  100. package/dist/core/github-stats.js +282 -97
  101. package/dist/core/http-cache.d.ts +0 -10
  102. package/dist/core/http-cache.js +0 -19
  103. package/dist/core/index.d.ts +12 -5
  104. package/dist/core/index.js +15 -5
  105. package/dist/core/issue-conversation.d.ts +8 -2
  106. package/dist/core/issue-conversation.js +31 -12
  107. package/dist/core/local-config.d.ts +95 -0
  108. package/dist/core/local-config.js +271 -0
  109. package/dist/core/merged-pr-notes.d.ts +2 -2
  110. package/dist/core/pagination.d.ts +55 -0
  111. package/dist/core/pagination.js +59 -0
  112. package/dist/core/paths.d.ts +7 -0
  113. package/dist/core/paths.js +9 -0
  114. package/dist/core/pr-assembly.js +6 -2
  115. package/dist/core/pr-graphql.d.ts +37 -3
  116. package/dist/core/pr-graphql.js +73 -12
  117. package/dist/core/pr-monitor.d.ts +29 -12
  118. package/dist/core/pr-monitor.js +71 -23
  119. package/dist/core/pr-preflight.d.ts +113 -0
  120. package/dist/core/pr-preflight.js +364 -0
  121. package/dist/core/pr-quality-rubric.d.ts +0 -6
  122. package/dist/core/pr-quality-rubric.js +0 -8
  123. package/dist/core/pr-template.d.ts +2 -0
  124. package/dist/core/pr-template.js +5 -1
  125. package/dist/core/repo-policy.d.ts +105 -0
  126. package/dist/core/repo-policy.js +400 -0
  127. package/dist/core/repo-score-manager.d.ts +48 -0
  128. package/dist/core/repo-score-manager.js +111 -1
  129. package/dist/core/review-analysis.d.ts +34 -19
  130. package/dist/core/review-analysis.js +67 -10
  131. package/dist/core/reviewed-prs-fetch.js +11 -29
  132. package/dist/core/reviewed-prs.js +8 -15
  133. package/dist/core/stale-data.d.ts +41 -0
  134. package/dist/core/stale-data.js +115 -0
  135. package/dist/core/state-persistence.d.ts +62 -27
  136. package/dist/core/state-persistence.js +338 -117
  137. package/dist/core/state-schema.d.ts +113 -210
  138. package/dist/core/state-schema.js +165 -80
  139. package/dist/core/state.d.ts +60 -8
  140. package/dist/core/state.js +192 -46
  141. package/dist/core/status-determination.js +26 -8
  142. package/dist/core/strategy.js +3 -1
  143. package/dist/core/types.d.ts +22 -1
  144. package/dist/core/types.js +1 -0
  145. package/dist/core/untrusted-content.d.ts +30 -11
  146. package/dist/core/untrusted-content.js +77 -42
  147. package/dist/core/urls.d.ts +9 -0
  148. package/dist/core/urls.js +18 -0
  149. package/dist/dashboard/assets/{chart-panel-DPKNBUts.js → chart-panel-C_C1lFTI.js} +1 -1
  150. package/dist/dashboard/assets/{index-B25bZOYX.js → index-B--H66Jk.js} +1 -1
  151. package/dist/dashboard/index.html +1 -1
  152. package/dist/formatters/json.d.ts +262 -6
  153. package/dist/formatters/json.js +77 -1
  154. package/package.json +1 -1
  155. package/dist/core/ci-enforced-tools.d.ts +0 -35
  156. package/dist/core/ci-enforced-tools.js +0 -109
  157. package/dist/core/comment-decision.d.ts +0 -79
  158. package/dist/core/comment-decision.js +0 -82
  159. package/dist/core/extraction-categories.d.ts +0 -55
  160. package/dist/core/extraction-categories.js +0 -108
  161. package/dist/core/follow-up-history.d.ts +0 -40
  162. package/dist/core/follow-up-history.js +0 -71
  163. package/dist/core/issue-effort.d.ts +0 -29
  164. package/dist/core/issue-effort.js +0 -47
  165. package/dist/core/maintainer-hints.d.ts +0 -23
  166. package/dist/core/maintainer-hints.js +0 -36
  167. package/dist/core/workflow-state.d.ts +0 -56
  168. package/dist/core/workflow-state.js +0 -101
@@ -81,14 +81,19 @@ export function installPreAction(program, localOnlySet) {
81
81
  // when Gist mode is the configured persistence (#1000). Hard errors
82
82
  // still throw (#1202); the resolving degraded modes are surfaced in the
83
83
  // JSON envelope so --json consumers see them too (#1433).
84
- const { ensureGistPersistence, renderGistWarning } = await import('./core/index.js');
84
+ const { ensureGistPersistence, renderGistWarning, unknownPersistenceModeWarning } = await import('./core/index.js');
85
85
  const status = await ensureGistPersistence(token);
86
+ // A mode a newer release added runs local-only here (#2005).
87
+ let envelopeWarning = status === 'local-mode' ? unknownPersistenceModeWarning() : null;
86
88
  if (status === 'degraded' || status === 'state-unreadable') {
87
- const { setEnvelopeGistWarning } = await import('./formatters/json.js');
88
89
  // Shared renderer (#1444). 'degraded' is ensureGistPersistence's
89
90
  // deliberate conflation of the transient init fallback and a #1443
90
91
  // degraded bootstrap — rendered as the init-fallback cause, as before.
91
- setEnvelopeGistWarning(renderGistWarning(status === 'degraded' ? 'init-fallback' : 'state-unreadable'));
92
+ envelopeWarning = renderGistWarning(status === 'degraded' ? 'init-fallback' : 'state-unreadable');
93
+ }
94
+ if (envelopeWarning) {
95
+ const { setEnvelopeGistWarning } = await import('./formatters/json.js');
96
+ setEnvelopeGistWarning(envelopeWarning);
92
97
  }
93
98
  }
94
99
  });
@@ -45,20 +45,22 @@ export function handleCommandError(err, json) {
45
45
  * calls `outputJsonValidated` directly — so a drifted shape throws at
46
46
  * the `--json` boundary instead of silently shipping (#1105).
47
47
  * Commands: manifest, daily, status, strategy, search, features,
48
- * verify-issue, skip-add, list-move-tier, list-mark-done,
48
+ * verify-issue, issue-thread, skip-add, list-move-tier, list-mark-done,
49
49
  * compliance-score, post, claim, config, init, setup, checkSetup,
50
50
  * parse-issue-list, orphan-files, doctor, local-repos, move,
51
- * pr-template, repo-cap, repo-vet, detect-formatters, work (claim/finish/release/list).
51
+ * pr-template, repo-cap, pr-preflight, repo-vet, detect-formatters, work (claim/finish/release/list),
52
+ * policy (get/set).
52
53
  *
53
54
  * 2. **Goldens-only**: no Zod schema exists; the command returns a TS
54
55
  * interface and its `*.contract.test.ts` golden snapshot is the only
55
56
  * shape gate. Nothing fires at runtime if the producer drifts after
56
57
  * the goldens were last updated.
57
58
  * Commands: state (show/sync/unlink), vet, vet-list, ledger-backfill, eval, track, comments,
58
- * startup, dismiss, undismiss, stats, and the five
59
+ * startup, dismiss, undismiss, stats, policy reset, and the five
59
60
  * guidelines subcommands (list/view/store/reset/fetch-corpus/mark-extracted).
60
61
  *
61
62
  * (`dashboard serve` is exempt: it has no `--json` mode.)
63
+ * (`draft path` / `draft show` have neither: their shapes are pinned by `commands/draft.test.ts`.)
62
64
  *
63
65
  * To promote a command to tier 1: export a Zod schema from
64
66
  * `formatters/json.ts`, assert it in the command's contract test alongside
@@ -102,6 +104,10 @@ function printRepos(repos) {
102
104
  console.log(` ${info.path}`);
103
105
  }
104
106
  }
107
+ /** Print a deprecation note on stderr for commands kept only for semver (#1948); stdout and `--json` are untouched. */
108
+ function warnDeprecatedCommand(name) {
109
+ console.error(`Warning: \`${name}\` is deprecated and will be removed in the next major version.`);
110
+ }
105
111
  export const commands = [
106
112
  // ── Manifest (#1190) ───────────────────────────────────────────────────
107
113
  // Exposes the registered commands for CLI/plugin contract checks —
@@ -292,7 +298,10 @@ export const commands = [
292
298
  else {
293
299
  // Default: --show
294
300
  await executeAction(options, async () => (await import('./commands/state-cmd.js')).runStateShow({ validate: !!options.validate }), (data) => {
295
- console.log(`\nPersistence: ${data.persistence}`);
301
+ console.log(`\nPersistence: ${data.persistence}` +
302
+ (data.storedPersistence
303
+ ? ` (stored mode '${data.storedPersistence}' is from a newer release; upgrade oss-autopilot to sync)`
304
+ : ''));
296
305
  if (data.gistId)
297
306
  console.log(`Gist ID: ${data.gistId}`);
298
307
  if (data.gistDegraded)
@@ -530,6 +539,34 @@ export const commands = [
530
539
  });
531
540
  },
532
541
  },
542
+ // ── Issue Thread ───────────────────────────────────────────────────────
543
+ {
544
+ name: 'issue-thread',
545
+ register(program) {
546
+ program
547
+ .command('issue-thread <issue-url>')
548
+ .description('Read an issue title, body and comments, each fenced as untrusted content (#1932)')
549
+ .option('--json', 'Output as JSON')
550
+ .action(async (issueUrl, options) => {
551
+ const { IssueThreadOutputSchema } = await import('./formatters/json.js');
552
+ const { runIssueThread, fenceIssueThreadTitle } = await import('./commands/issue-thread.js');
553
+ await executeAction(options, async () => fenceIssueThreadTitle(await runIssueThread({ issueUrl })), (data) => {
554
+ // Fences stay on in text mode: an agent that drops --json must
555
+ // still get stranger-written text inside its fence.
556
+ console.log(`\n${data.owner}/${data.repo}#${data.number} [${data.state}]: ${data.title}`);
557
+ console.log(`\n${data.body}`);
558
+ for (const comment of data.comments) {
559
+ console.log(`\n${comment.createdAt}\n${comment.body}`);
560
+ }
561
+ if (!data.warnings)
562
+ return;
563
+ for (const warning of data.warnings) {
564
+ console.log(`\nWarning: ${warning.message}`);
565
+ }
566
+ }, IssueThreadOutputSchema);
567
+ });
568
+ },
569
+ },
533
570
  // ── Vet List ──────────────────────────────────────────────────────────
534
571
  {
535
572
  name: 'vet-list',
@@ -654,7 +691,7 @@ export const commands = [
654
691
  .command('list-move-tier <issue-url>')
655
692
  .description('Move an issue between Pursue / Maybe / Skip sections of a curated list (#1107)')
656
693
  .requiredOption('--tier <tier>', 'Target tier: pursue, maybe, or skip')
657
- .requiredOption('--list-path <file>', 'Path to the markdown issue list')
694
+ .option('--list-path <file>', 'Path to the markdown issue list (defaults to the configured issueListPath)')
658
695
  .option('--json', 'Output as JSON')
659
696
  .action(async (issueUrl, options) => {
660
697
  const { ListMoveTierOutputSchema } = await import('./formatters/json.js');
@@ -693,7 +730,7 @@ export const commands = [
693
730
  .description('Mark an issue line in a curated list as done with strikethrough + Done sub-bullet (#1299)')
694
731
  .requiredOption('--pr-url <url>', 'PR URL to record on the Done sub-bullet')
695
732
  .requiredOption('--pr-status <text>', 'Trailing status, e.g. "merged" or "CI passing"')
696
- .requiredOption('--list-path <file>', 'Path to the markdown issue list')
733
+ .option('--list-path <file>', 'Path to the markdown issue list (defaults to the configured issueListPath)')
697
734
  .option('--json', 'Output as JSON')
698
735
  .action(async (issueUrl, options) => {
699
736
  const { ListMarkDoneOutputSchema } = await import('./formatters/json.js');
@@ -831,23 +868,15 @@ export const commands = [
831
868
  .command('post <url> [message...]')
832
869
  .description('Post a comment to a PR or issue')
833
870
  .option('--stdin', 'Read message from stdin')
871
+ .option('--body-file <path>', BODY_FILE_HELP)
872
+ .option('--expect-sha256 <hex>', EXPECT_SHA256_HELP)
834
873
  .option('--json', 'Output as JSON')
835
874
  .action(async (url, messageParts, options) => {
836
875
  const { PostOutputSchema } = await import('./formatters/json.js');
837
876
  await executeAction(options, async () => {
838
- let message;
839
- if (options.stdin) {
840
- const chunks = [];
841
- for await (const chunk of process.stdin) {
842
- chunks.push(chunk);
843
- }
844
- message = Buffer.concat(chunks).toString('utf8').trim();
845
- }
846
- else {
847
- message = messageParts.join(' ');
848
- }
877
+ const message = await readMessage(options, messageParts);
849
878
  const { runPost } = await import('./commands/comments.js');
850
- return runPost({ url, message });
879
+ return runPost({ url, message, expectSha256: options.expectSha256 });
851
880
  }, (data) => {
852
881
  console.log(`Comment posted: ${data.commentUrl}`);
853
882
  }, PostOutputSchema);
@@ -861,13 +890,16 @@ export const commands = [
861
890
  program
862
891
  .command('claim <issue-url> [message...]')
863
892
  .description('Claim an issue by posting a comment')
893
+ .option('--body-file <path>', BODY_FILE_HELP)
894
+ .option('--expect-sha256 <hex>', EXPECT_SHA256_HELP)
864
895
  .option('--json', 'Output as JSON')
865
896
  .action(async (issueUrl, messageParts, options) => {
866
897
  const { ClaimOutputSchema } = await import('./formatters/json.js');
867
898
  await executeAction(options, async () => {
868
899
  const { runClaim } = await import('./commands/comments.js');
869
- const message = messageParts.length > 0 ? messageParts.join(' ') : undefined;
870
- return runClaim({ issueUrl, message });
900
+ // No words and no file means the default claim message.
901
+ const message = (await readMessage(options, messageParts)) || undefined;
902
+ return runClaim({ issueUrl, message, expectSha256: options.expectSha256 });
871
903
  }, (data) => {
872
904
  console.log(`Issue claimed: ${data.commentUrl}`);
873
905
  }, ClaimOutputSchema);
@@ -1090,10 +1122,11 @@ export const commands = [
1090
1122
  program
1091
1123
  .command('orphan-files')
1092
1124
  .alias('check-integration')
1093
- .description('Detect new files on this branch that no other file references')
1125
+ .description('(deprecated) Detect new files on this branch that no other file references')
1094
1126
  .option('--base <branch>', 'Base branch to compare against', 'main')
1095
1127
  .option('--json', 'Output as JSON')
1096
1128
  .action(async (options) => {
1129
+ warnDeprecatedCommand('orphan-files');
1097
1130
  const { CheckIntegrationOutputSchema } = await import('./formatters/json.js');
1098
1131
  await executeAction(options, async () => (await import('./commands/check-integration.js')).runCheckIntegration({ base: options.base }), (data) => {
1099
1132
  if (data.newFiles.length === 0) {
@@ -1144,6 +1177,29 @@ export const commands = [
1144
1177
  });
1145
1178
  },
1146
1179
  },
1180
+ // ── Cleanup (#1956) ────────────────────────────────────────────────────
1181
+ {
1182
+ name: 'cleanup',
1183
+ localOnly: true,
1184
+ register(program) {
1185
+ program
1186
+ .command('cleanup')
1187
+ .description('List stale overnight worktrees and rejected state copies; --apply removes the safe ones')
1188
+ .option('--apply', 'Remove what the dry run lists (clean, pushed, idle worktrees only)')
1189
+ .option('--json', 'Output as JSON')
1190
+ .action(async (options) => {
1191
+ const { runCleanup, printCleanup } = await import('./commands/cleanup.js');
1192
+ const run = () => {
1193
+ const data = runCleanup({ apply: options.apply === true });
1194
+ // A scheduler or a script only sees the exit code; the output still prints in full.
1195
+ if (data.errors.length > 0)
1196
+ process.exitCode = 1;
1197
+ return Promise.resolve(data);
1198
+ };
1199
+ await executeAction(options, run, printCleanup);
1200
+ });
1201
+ },
1202
+ },
1147
1203
  // ── Local Repos ────────────────────────────────────────────────────────
1148
1204
  {
1149
1205
  name: 'local-repos',
@@ -1435,6 +1491,40 @@ export const commands = [
1435
1491
  });
1436
1492
  },
1437
1493
  },
1494
+ // ── PR Preflight (#1952) ─────────────────────────────────────────────
1495
+ {
1496
+ name: 'pr-preflight',
1497
+ // Skips the auth gate, not GitHub: without a token the network checks come back `skipped`.
1498
+ localOnly: true,
1499
+ register(program) {
1500
+ program
1501
+ .command('pr-preflight [issue]')
1502
+ .description('Gate before opening a PR: upstream drift, base and head branch, working tree, competing work on the issue, repo cap')
1503
+ .option('--dir <path>', 'Local clone or worktree to check (default: current directory)')
1504
+ .option('--base <branch>', 'Branch the PR will target (default: the upstream default branch)')
1505
+ .option('--fetch', 'Fetch the upstream target branch first instead of reporting a stale ref')
1506
+ .option('--local', 'Skip every GitHub read: local checks and numbers only')
1507
+ .option('--json', 'Output as JSON')
1508
+ .action(async (issue, options) => {
1509
+ const { PrPreflightOutputSchema } = await import('./formatters/json.js');
1510
+ const { runPrPreflight, printPrPreflight } = await import('./commands/pr-preflight.js');
1511
+ const run = async () => {
1512
+ const data = await runPrPreflight({
1513
+ issue,
1514
+ dir: options.dir,
1515
+ base: options.base,
1516
+ fetch: options.fetch === true,
1517
+ local: options.local === true,
1518
+ });
1519
+ // A caller that only sees the exit code still stops on a failed gate; the output prints in full.
1520
+ if (data.verdict === 'fail')
1521
+ process.exitCode = 1;
1522
+ return data;
1523
+ };
1524
+ await executeAction(options, run, printPrPreflight, PrPreflightOutputSchema);
1525
+ });
1526
+ },
1527
+ },
1438
1528
  // ── Repo Vet (#1271) ────────────────────────────────────────────────
1439
1529
  {
1440
1530
  name: 'repo-vet',
@@ -1475,10 +1565,11 @@ export const commands = [
1475
1565
  register(program) {
1476
1566
  program
1477
1567
  .command('detect-formatters [repo-path]')
1478
- .description('Detect formatters and linters configured in a repository')
1568
+ .description('(deprecated) Detect formatters and linters configured in a repository')
1479
1569
  .option('--ci-log <path>', 'Analyze CI log file for formatting failures')
1480
1570
  .option('--json', 'Output as JSON')
1481
1571
  .action(async (repoPath, options) => {
1572
+ warnDeprecatedCommand('detect-formatters');
1482
1573
  const { DetectFormattersOutputSchema } = await import('./formatters/json.js');
1483
1574
  await executeAction(options, async () => (await import('./commands/detect-formatters.js')).runDetectFormatters({
1484
1575
  repoPath,
@@ -1699,6 +1790,44 @@ Load it with:
1699
1790
  });
1700
1791
  },
1701
1792
  },
1793
+ // ── Draft files (#1930) ────────────────────────────────────────────────
1794
+ // Local-only and read-only: where to stage text for the user's approval,
1795
+ // and one read that yields both the text to show and the hash to pass back.
1796
+ {
1797
+ name: 'draft',
1798
+ localOnly: true,
1799
+ register(program) {
1800
+ const group = program
1801
+ .command('draft')
1802
+ .description('Stage text for approval in the owner-only draft directory (~/.oss-autopilot/tmp)');
1803
+ group
1804
+ .command('path <name>')
1805
+ .description('Print the path for a draft file name, creating the draft directory (mode 0700) if needed')
1806
+ .option('--json', 'Output as JSON')
1807
+ .action(async (name, options) => {
1808
+ await executeAction(options, async () => {
1809
+ const { runDraftPath } = await import('./commands/draft.js');
1810
+ return runDraftPath({ name });
1811
+ }, (data) => {
1812
+ console.log(data.path);
1813
+ });
1814
+ });
1815
+ group
1816
+ .command('show <file>')
1817
+ .description('Read a draft once and return its text with the SHA-256 to pass back as --expect-sha256')
1818
+ .option('--untrusted', "Wrap the text in the untrusted-content fence (text distilled from other people's writing)")
1819
+ .option('--json', 'Output as JSON')
1820
+ .action(async (file, options) => {
1821
+ await executeAction(options, async () => {
1822
+ const { runDraftShow } = await import('./commands/draft.js');
1823
+ return runDraftShow({ file, untrusted: options.untrusted === true });
1824
+ }, (data) => {
1825
+ console.log(data.content);
1826
+ console.log(`\nsha256: ${data.sha256}`);
1827
+ });
1828
+ });
1829
+ },
1830
+ },
1702
1831
  // ── Guidelines (#867) ──────────────────────────────────────────────────
1703
1832
  {
1704
1833
  name: 'guidelines',
@@ -1746,14 +1875,19 @@ Load it with:
1746
1875
  });
1747
1876
  group
1748
1877
  .command('store')
1749
- .description('Persist per-repo guidelines (overwrites). Reads markdown content from --content or stdin.')
1878
+ .description('Persist per-repo guidelines (overwrites). Reads markdown content from --from-file, --content or stdin.')
1750
1879
  .requiredOption('--repo <owner/repo>', 'Repository identifier')
1880
+ .option('--from-file <path>', 'Read the markdown from a draft file (see `draft path`). Needs --expect-sha256; not with --content.')
1751
1881
  .option('--content <markdown>', 'Markdown content. If omitted, reads from stdin.')
1882
+ .option('--expect-sha256 <hex>', EXPECT_SHA256_HELP)
1883
+ .option('--reviewed', 'Assert the user saw this exact text and approved it. Required; refused when unattended.')
1752
1884
  .option('--json', 'Output as JSON')
1753
1885
  .action(async (options) => {
1754
1886
  await executeAction(options, async () => {
1755
- const content = options.content ?? (await readStdin());
1756
- return (await import('./commands/guidelines.js')).runGuidelinesStore({ repo: options.repo, content });
1887
+ const content = await readGuidelinesContent(options);
1888
+ const { repo, reviewed = false, expectSha256 } = options;
1889
+ const { runGuidelinesStore } = await import('./commands/guidelines.js');
1890
+ return runGuidelinesStore({ repo, content, reviewed, expectSha256 });
1757
1891
  }, (data) => {
1758
1892
  console.log(`Stored ${data.byteSize} bytes of guidelines for ${data.repo}.`);
1759
1893
  });
@@ -1801,7 +1935,120 @@ Load it with:
1801
1935
  });
1802
1936
  },
1803
1937
  },
1938
+ // ── Repo contribution policy (#1953) ─────────────────────────────────
1939
+ {
1940
+ name: 'policy',
1941
+ // State only: no GitHub call.
1942
+ localOnly: true,
1943
+ register(program) {
1944
+ const group = program
1945
+ .command('policy')
1946
+ .description('Per-repo contribution policy: AI policy, disclosure, CLA, commit rules, PR gate (#1953)');
1947
+ group
1948
+ .command('get')
1949
+ .description('Show the policy that applies to a repo (aiPolicyBlocklist read as a ban; quoted repo text fenced)')
1950
+ .requiredOption('--repo <owner/repo>', 'Repository identifier')
1951
+ .option('--json', 'Output as JSON')
1952
+ .action(async (options) => {
1953
+ const { PolicyGetOutputSchema } = await import('./formatters/json.js');
1954
+ const { runPolicyGet } = await import('./commands/policy.js');
1955
+ await executeAction(options, () => runPolicyGet({ repo: options.repo }), printPolicy, PolicyGetOutputSchema);
1956
+ });
1957
+ group
1958
+ .command('set')
1959
+ .description('Record the policy you confirmed for a repo (merged over what is stored; refused when unattended)')
1960
+ .requiredOption('--repo <owner/repo>', 'Repository identifier')
1961
+ .option('--ai-policy <value>', 'allowed | disclosure-required | banned | unknown')
1962
+ .option('--disclosure-text <text>', 'The disclosure line the repo asks for')
1963
+ .option('--cla <value>', 'none | required | unknown')
1964
+ .option('--pr-gate <value>', 'none | claim-first | maintainer-label | collaborators-only | unknown')
1965
+ .option('--commit-rules <ids>', 'Comma-separated: conventional-commits, dco-signoff, no-closing-keyword-in-commit ("" clears)')
1966
+ .option('--max-open-ai-prs <n>', 'Open AI-assisted PRs the repo allows at once (0 clears)', Number)
1967
+ .option('--source <text>', 'Where the rule came from, e.g. a maintainer comment (stored as a short quote)')
1968
+ .option('--json', 'Output as JSON')
1969
+ .action(async (options) => {
1970
+ const { PolicyGetOutputSchema } = await import('./formatters/json.js');
1971
+ const { runPolicySet } = await import('./commands/policy.js');
1972
+ // Commander camel-cases --max-open-ai-prs as maxOpenAiPrs.
1973
+ const { maxOpenAiPrs, ...rest } = options;
1974
+ await executeAction(options, () => runPolicySet({ ...rest, maxOpenAiPRs: maxOpenAiPrs }), (data) => {
1975
+ printPolicy(data);
1976
+ const change = { added: ` Added ${data.repo} to`, removed: ` Removed ${data.repo} from` };
1977
+ if (data.blocklistChange)
1978
+ console.log(`${change[data.blocklistChange]} aiPolicyBlocklist.`);
1979
+ if (data.policy?.blocklisted && data.blocklistChange === undefined) {
1980
+ console.log(' Banned by aiPolicyBlocklist; set --ai-policy to another value to take it off the list.');
1981
+ }
1982
+ }, PolicyGetOutputSchema);
1983
+ });
1984
+ group
1985
+ .command('reset')
1986
+ .description('Delete the stored policy for a repo (refused when unattended)')
1987
+ .requiredOption('--repo <owner/repo>', 'Repository identifier')
1988
+ .option('--json', 'Output as JSON')
1989
+ .action(async (options) => {
1990
+ const { runPolicyReset } = await import('./commands/policy.js');
1991
+ await executeAction(options, () => runPolicyReset({ repo: options.repo }), (data) => {
1992
+ console.log(data.deleted ? `Deleted the policy for ${data.repo}.` : `No policy stored for ${data.repo}.`);
1993
+ });
1994
+ });
1995
+ },
1996
+ },
1804
1997
  ];
1998
+ const BODY_FILE_HELP = 'Read the message from a draft file (see `draft path`). Needs --expect-sha256; not with --stdin or positional words.';
1999
+ const EXPECT_SHA256_HELP = 'Fail before doing anything unless the text hashes to this SHA-256 (from `draft show`)';
2000
+ /** The message for `post` / `claim`: an approved draft file, stdin (trimmed), or the positional words. */
2001
+ async function readMessage(options, parts) {
2002
+ if (options.bodyFile !== undefined) {
2003
+ const { readApprovedDraft } = await import('./commands/draft.js');
2004
+ return readApprovedDraft({
2005
+ file: options.bodyFile,
2006
+ flag: '--body-file',
2007
+ expectSha256: options.expectSha256,
2008
+ hasOtherInput: options.stdin === true || parts.length > 0,
2009
+ });
2010
+ }
2011
+ if (options.stdin) {
2012
+ const chunks = [];
2013
+ for await (const chunk of process.stdin) {
2014
+ chunks.push(chunk);
2015
+ }
2016
+ return Buffer.concat(chunks).toString('utf8').trim();
2017
+ }
2018
+ return parts.join(' ');
2019
+ }
2020
+ async function readGuidelinesContent(options) {
2021
+ if (options.fromFile !== undefined) {
2022
+ const { readApprovedDraft } = await import('./commands/draft.js');
2023
+ return readApprovedDraft({
2024
+ file: options.fromFile,
2025
+ flag: '--from-file',
2026
+ expectSha256: options.expectSha256,
2027
+ hasOtherInput: options.content !== undefined,
2028
+ });
2029
+ }
2030
+ return options.content ?? readStdin();
2031
+ }
2032
+ /** Text mode for `policy get` / `policy set`. Quoted repo text stays fenced. */
2033
+ function printPolicy(data) {
2034
+ const { policy } = data;
2035
+ if (!policy) {
2036
+ console.log(`No contribution policy recorded for ${data.repo}.`);
2037
+ return;
2038
+ }
2039
+ const reviewed = policy.reviewedByUser ? 'set by you' : 'read from repo docs, not reviewed';
2040
+ console.log(`\n${data.repo} (${reviewed}, ${policy.updatedAt.slice(0, 10)})`);
2041
+ console.log(` AI policy: ${policy.aiPolicy}${policy.blocklisted ? ' (aiPolicyBlocklist)' : ''}`);
2042
+ console.log(` CLA: ${policy.cla} PR gate: ${policy.prGate}`);
2043
+ if (policy.commitRules.length > 0)
2044
+ console.log(` Commit rules: ${policy.commitRules.join(', ')}`);
2045
+ if (policy.maxOpenAiPRs !== undefined)
2046
+ console.log(` Max open AI-assisted PRs: ${policy.maxOpenAiPRs}`);
2047
+ if (policy.disclosureText)
2048
+ console.log(` Disclosure: ${policy.disclosureText}`);
2049
+ if (policy.sources)
2050
+ console.log(` Sources: ${policy.sources}`);
2051
+ }
1805
2052
  /** Read full stdin content. Used when `guidelines store` content isn't passed inline. */
1806
2053
  async function readStdin() {
1807
2054
  if (process.stdin.isTTY) {