@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
@@ -0,0 +1,43 @@
1
+ /**
2
+ * pr-preflight command (#1952): one gate before a branch is pushed and a PR
3
+ * is opened. Gathers facts from the local clone (read-only commands) and from
4
+ * GitHub (read-only API), then runs the pure checks in core/pr-preflight.ts:
5
+ * upstream drift, base branch, head branch, working tree, competing work on
6
+ * the issue, the per-repo open-PR cap, the repo policy and its commit rules.
7
+ *
8
+ * It only reads, so it runs in unattended mode. Without a GitHub token, or
9
+ * with `--local`, the local checks still run and the network checks come back
10
+ * `skipped`; a GitHub read that fails degrades its own check only. The one
11
+ * thing it can change is remote-tracking refs, and only when `--fetch` is
12
+ * passed; without it a stale `<remote>/<base>` is reported, not refreshed.
13
+ */
14
+ import { type PreflightCheck, type PreflightVerdict } from '../core/pr-preflight.js';
15
+ export interface PrPreflightOptions {
16
+ /** Local clone or worktree; defaults to the current directory. */
17
+ dir?: string;
18
+ /** Issue URL, or an issue number in the upstream repository. */
19
+ issue?: string;
20
+ /** Branch the PR will target; defaults to the upstream default branch. */
21
+ base?: string;
22
+ /** Run `git fetch <remote> <base>` before measuring drift. */
23
+ fetch: boolean;
24
+ /** Skip every GitHub read; for callers that only want the local numbers. */
25
+ local: boolean;
26
+ }
27
+ export interface PrPreflightOutput {
28
+ verdict: PreflightVerdict;
29
+ dir: string;
30
+ repo: string | null;
31
+ issueUrl: string | null;
32
+ branch: string | null;
33
+ remote: string | null;
34
+ base: string | null;
35
+ mergeBase: string | null;
36
+ ahead: number | null;
37
+ behind: number | null;
38
+ checks: PreflightCheck[];
39
+ }
40
+ /** Run every preflight check for the branch checked out in `options.dir`. */
41
+ export declare function runPrPreflight(options: PrPreflightOptions): Promise<PrPreflightOutput>;
42
+ /** Text mode: the verdict, then one line per check. */
43
+ export declare function printPrPreflight(data: PrPreflightOutput): void;
@@ -0,0 +1,294 @@
1
+ /**
2
+ * pr-preflight command (#1952): one gate before a branch is pushed and a PR
3
+ * is opened. Gathers facts from the local clone (read-only commands) and from
4
+ * GitHub (read-only API), then runs the pure checks in core/pr-preflight.ts:
5
+ * upstream drift, base branch, head branch, working tree, competing work on
6
+ * the issue, the per-repo open-PR cap, the repo policy and its commit rules.
7
+ *
8
+ * It only reads, so it runs in unattended mode. Without a GitHub token, or
9
+ * with `--local`, the local checks still run and the network checks come back
10
+ * `skipped`; a GitHub read that fails degrades its own check only. The one
11
+ * thing it can change is remote-tracking refs, and only when `--fetch` is
12
+ * passed; without it a stale `<remote>/<base>` is reported, not refreshed.
13
+ */
14
+ import { errorMessage, fetchIssueVerification, getGitHubTokenAsync, getHttpStatusCode, getOctokit, getStateManager, parseGitHubUrl, splitRepo, } from '../core/index.js';
15
+ import { ValidationError } from '../core/errors.js';
16
+ import { runPreflightChecks, } from '../core/pr-preflight.js';
17
+ import { git, parseRemoteOwner, parseRemotesOutput, resolvePushRemote } from './overnight-push-prep.js';
18
+ import { runRepoCap } from './repo-cap.js';
19
+ import { effectivePolicy } from '../core/repo-policy.js';
20
+ import { isFirstInRepo } from '../core/pick-snapshot.js';
21
+ import { ISSUE_URL_PATTERN, validateGitHubUrl, validateUrl } from './validation.js';
22
+ const BRANCH_NAME = /^[\w.][\w./-]*$/;
23
+ const ISSUE_NUMBER = /^#?(\d+)$/;
24
+ const MAX_OVERLAP_LINES = 20;
25
+ // ponytail: a branch with more commits than this has only its newest 200 checked against the commit rules.
26
+ const MAX_BRANCH_COMMITS = 200;
27
+ // ponytail: argv ceiling. A branch touching more files than this is checked on the first 500 only.
28
+ const MAX_PATHSPECS = 500;
29
+ /** Output of a command that may legitimately fail (missing ref, unborn HEAD); null when it does. */
30
+ function tryGit(dir, args) {
31
+ try {
32
+ return git(dir, args).trim();
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ }
38
+ function repoName(remote) {
39
+ const parsed = remote ? parseRemoteOwner(remote.url) : null;
40
+ return parsed ? `${parsed.owner}/${parsed.repo}` : null;
41
+ }
42
+ /** The remote for `repo` when one points at it, else `upstream`, else `origin`, else the first. */
43
+ function pickRemote(remotes, repo) {
44
+ // A remote named like an option would be read as one.
45
+ const usable = remotes.filter((r) => !r.name.startsWith('-'));
46
+ const wanted = repo?.toLowerCase();
47
+ const matching = usable.find((r) => wanted !== undefined && repoName(r)?.toLowerCase() === wanted);
48
+ const named = usable.find((r) => r.name === 'upstream') ?? usable.find((r) => r.name === 'origin');
49
+ return matching ?? named ?? usable.at(0) ?? null;
50
+ }
51
+ function issueRepo(issue) {
52
+ if (issue === undefined || ISSUE_NUMBER.test(issue))
53
+ return null;
54
+ validateUrl(issue);
55
+ validateGitHubUrl(issue, ISSUE_URL_PATTERN, 'issue');
56
+ const parsed = parseGitHubUrl(issue);
57
+ if (!parsed)
58
+ throw new ValidationError(`Not a parseable GitHub issue URL: ${issue}`);
59
+ return `${parsed.owner}/${parsed.repo}`;
60
+ }
61
+ function issueUrlFor(issue, repo) {
62
+ if (issue === undefined)
63
+ return null;
64
+ const numbered = ISSUE_NUMBER.exec(issue);
65
+ if (!numbered)
66
+ return issue;
67
+ if (!repo)
68
+ throw new ValidationError(`No GitHub remote to resolve issue ${issue} against; pass the issue URL`);
69
+ return `https://github.com/${repo}/issues/${numbered[1]}`;
70
+ }
71
+ async function branchHeadSha(octokit, repo, branch) {
72
+ try {
73
+ const { data } = await octokit.repos.getBranch({ ...splitRepo(repo), branch });
74
+ return data.commit.sha;
75
+ }
76
+ catch (err) {
77
+ if (getHttpStatusCode(err) === 404)
78
+ return null;
79
+ throw err;
80
+ }
81
+ }
82
+ async function fetchGitHubFacts(octokit, repo, base) {
83
+ const { data } = await octokit.repos.get(splitRepo(repo));
84
+ return {
85
+ defaultBranch: data.default_branch,
86
+ parent: data.parent?.full_name ?? null,
87
+ canPush: data.permissions?.push === true,
88
+ baseHeadSha: await branchHeadSha(octokit, repo, base ?? data.default_branch),
89
+ };
90
+ }
91
+ function offline(networkSkip) {
92
+ return { networkSkip, github: null, issue: null, cap: null, githubError: null, issueError: null, capError: null };
93
+ }
94
+ const NOT_RUN = { value: null, error: null };
95
+ /** One GitHub read. A failure is recorded for its check; bad input (an issue that does not exist) still throws. */
96
+ async function attempt(read) {
97
+ try {
98
+ return { value: await read(), error: null };
99
+ }
100
+ catch (err) {
101
+ if (err instanceof ValidationError)
102
+ throw err;
103
+ return { value: null, error: errorMessage(err).split('\n', 1)[0] };
104
+ }
105
+ }
106
+ async function gatherNetworkFacts(target, options, login) {
107
+ const { repo, issueUrl } = target;
108
+ if (options.local)
109
+ return offline('local mode (--local)');
110
+ if (!repo)
111
+ return offline('no remote points at a GitHub repository');
112
+ const token = await getGitHubTokenAsync();
113
+ if (!token)
114
+ return offline('no GitHub token (run gh auth login or set GITHUB_TOKEN)');
115
+ const octokit = getOctokit(token);
116
+ const parsed = issueUrl ? parseGitHubUrl(issueUrl) : null;
117
+ const github = await attempt(() => fetchGitHubFacts(octokit, repo, options.base));
118
+ const issue = parsed
119
+ ? await attempt(() => fetchIssueVerification(octokit, parsed))
120
+ : NOT_RUN;
121
+ // The cap gates a new PR, so it runs only for an issue; its search needs the username.
122
+ const cap = parsed && login ? await attempt(() => runRepoCap({ repo })) : NOT_RUN;
123
+ return {
124
+ networkSkip: null,
125
+ github: github.value,
126
+ githubError: github.error,
127
+ issue: issue.value,
128
+ issueError: issue.error,
129
+ cap: cap.value,
130
+ capError: cap.error,
131
+ };
132
+ }
133
+ /** `git log --oneline` lines for commits in `mergeBase..upstream` touching files changed in `mergeBase..HEAD`. */
134
+ function overlappingCommits(dir, mergeBase, upstream) {
135
+ const files = git(dir, ['diff', '--name-only', '-z', mergeBase, 'HEAD'])
136
+ .split('\0')
137
+ .filter((file) => file !== '');
138
+ if (files.length === 0)
139
+ return [];
140
+ const range = `${mergeBase}..${upstream}`;
141
+ const limit = `--max-count=${MAX_OVERLAP_LINES}`;
142
+ const log = git(dir, [
143
+ '--literal-pathspecs',
144
+ 'log',
145
+ '--oneline',
146
+ limit,
147
+ range,
148
+ '--',
149
+ ...files.slice(0, MAX_PATHSPECS),
150
+ ]);
151
+ return log.split('\n').filter((line) => line !== '');
152
+ }
153
+ /** Full messages of the branch's own non-merge commits since `mergeBase`, newest first. */
154
+ function branchCommits(dir, mergeBase) {
155
+ const log = git(dir, [
156
+ 'log',
157
+ '--no-merges',
158
+ `--max-count=${MAX_BRANCH_COMMITS}`,
159
+ '--format=%B%x00',
160
+ `${mergeBase}..HEAD`,
161
+ ]);
162
+ return log
163
+ .split('\0')
164
+ .map((message) => message.trim())
165
+ .filter((message) => message !== '');
166
+ }
167
+ /**
168
+ * Fetch the target branch into its remote-tracking ref, the only thing this command ever changes.
169
+ * The full refspec keeps a branch name from being read as an option. Returns the failure, or null.
170
+ */
171
+ function fetchBase(dir, remote, base) {
172
+ try {
173
+ git(dir, ['fetch', '--quiet', remote, `+refs/heads/${base}:refs/remotes/${remote}/${base}`]);
174
+ return null;
175
+ }
176
+ catch (err) {
177
+ return errorMessage(err).split('\n', 1)[0];
178
+ }
179
+ }
180
+ function gatherDriftFacts(dir, remote, base, mode) {
181
+ const none = {
182
+ remoteRefSha: null,
183
+ behind: null,
184
+ ahead: null,
185
+ mergeBase: null,
186
+ overlappingCommits: [],
187
+ branchCommits: null,
188
+ };
189
+ if (!remote || !base)
190
+ return { ...none, fetchError: null };
191
+ const fetchError = mode === 'fetch' ? fetchBase(dir, remote, base) : null;
192
+ const remoteRefSha = tryGit(dir, ['rev-parse', '--verify', '--quiet', `refs/remotes/${remote}/${base}`]);
193
+ const counts = remoteRefSha ? tryGit(dir, ['rev-list', '--left-right', '--count', `${remoteRefSha}...HEAD`]) : null;
194
+ if (!remoteRefSha || !counts)
195
+ return { ...none, remoteRefSha, fetchError };
196
+ const [behind, ahead] = counts.split(/\s+/).map(Number);
197
+ const mergeBase = tryGit(dir, ['merge-base', remoteRefSha, 'HEAD']);
198
+ return {
199
+ remoteRefSha,
200
+ behind,
201
+ ahead,
202
+ mergeBase,
203
+ fetchError,
204
+ overlappingCommits: mergeBase ? overlappingCommits(dir, mergeBase, remoteRefSha) : [],
205
+ branchCommits: mergeBase ? branchCommits(dir, mergeBase) : null,
206
+ };
207
+ }
208
+ /**
209
+ * The default branch the clone records for the remote. A remote added by hand has no `HEAD`, so
210
+ * `origin`'s is the fallback: a fork almost always keeps its parent's default branch name.
211
+ */
212
+ function localDefaultBranch(dir, remote) {
213
+ if (!remote)
214
+ return null;
215
+ const names = new Set([remote, 'origin']);
216
+ for (const name of names) {
217
+ const head = tryGit(dir, ['symbolic-ref', '--quiet', '--short', `refs/remotes/${name}/HEAD`]);
218
+ if (head)
219
+ return head.slice(name.length + 1);
220
+ }
221
+ return null;
222
+ }
223
+ function repoRoot(dir) {
224
+ const root = tryGit(dir, ['rev-parse', '--show-toplevel']);
225
+ if (!root)
226
+ throw new ValidationError(`Not a git working tree: ${dir}`);
227
+ return root;
228
+ }
229
+ /** Which repository the PR goes to and which remote stands for it. */
230
+ function resolveTarget(remotes, issue) {
231
+ const fromIssue = issueRepo(issue);
232
+ const remote = pickRemote(remotes, fromIssue);
233
+ const remoteRepo = repoName(remote);
234
+ const repo = fromIssue ?? remoteRepo;
235
+ return { repo, remoteRepo, remote: remote?.name ?? null, issueUrl: issueUrlFor(issue, repo) };
236
+ }
237
+ function gatherHeadFacts(dir, remotes, login) {
238
+ const pushTarget = login ? resolvePushRemote(remotes, login) : null;
239
+ const status = git(dir, ['status', '--porcelain']);
240
+ return {
241
+ login,
242
+ branch: tryGit(dir, ['branch', '--show-current']) || null,
243
+ dirtyCount: status.split('\n').filter((line) => line !== '').length,
244
+ pushRemote: pushTarget?.remote ?? null,
245
+ };
246
+ }
247
+ function repoScoreFor(state, repo) {
248
+ const lower = repo.toLowerCase();
249
+ return Object.entries(state.repoScores).find(([key]) => key.toLowerCase() === lower)?.[1];
250
+ }
251
+ /** The repo's contribution policy and whether this is the user's first PR there; read from local state only. */
252
+ function policyFacts(state, repo) {
253
+ if (!repo)
254
+ return { policy: null, isFirstContribution: false };
255
+ return {
256
+ policy: effectivePolicy(state, repo),
257
+ // State keys keep the casing of the URL they came from; the remote may differ.
258
+ isFirstContribution: isFirstInRepo(repo, repoScoreFor(state, repo), state.mergedPRs),
259
+ };
260
+ }
261
+ /** Run every preflight check for the branch checked out in `options.dir`. */
262
+ export async function runPrPreflight(options) {
263
+ if (options.base !== undefined && !BRANCH_NAME.test(options.base)) {
264
+ throw new ValidationError(`Invalid base branch name: ${options.base}`);
265
+ }
266
+ const dir = repoRoot(options.dir ?? process.cwd());
267
+ const remotes = parseRemotesOutput(git(dir, ['remote', '-v']));
268
+ const target = resolveTarget(remotes, options.issue);
269
+ const sm = getStateManager();
270
+ const login = sm.getState().config.githubUsername || null;
271
+ const network = await gatherNetworkFacts(target, options, login);
272
+ const localDefault = localDefaultBranch(dir, target.remote);
273
+ const base = options.base ?? network.github?.defaultBranch ?? localDefault;
274
+ const facts = {
275
+ ...target,
276
+ ...network,
277
+ ...gatherHeadFacts(dir, remotes, login),
278
+ ...gatherDriftFacts(dir, target.remote, base, options.fetch ? 'fetch' : 'no-fetch'),
279
+ base,
280
+ localDefault,
281
+ ...policyFacts(sm.getState(), target.repo),
282
+ };
283
+ const { repo, remote, issueUrl, branch, mergeBase, ahead, behind } = facts;
284
+ const result = runPreflightChecks(facts);
285
+ return { ...result, dir, repo, issueUrl, branch, remote, base, mergeBase, ahead, behind };
286
+ }
287
+ /** Text mode: the verdict, then one line per check. */
288
+ export function printPrPreflight(data) {
289
+ const target = `${data.branch ?? '(detached HEAD)'} -> ${data.repo ?? '(no GitHub remote)'}:${data.base ?? '?'}`;
290
+ console.log(`\nPR preflight: ${data.verdict.toUpperCase()} ${target}`);
291
+ for (const check of data.checks) {
292
+ console.log(` [${check.status}] ${check.id}: ${check.summary}`);
293
+ }
294
+ }
@@ -10,7 +10,16 @@
10
10
  * Same architectural shape as `compliance-score`: read-only API calls,
11
11
  * no state mutation, runs against a public `owner/repo` slug.
12
12
  */
13
+ import { getOctokit } from '../core/index.js';
13
14
  import type { RepoVetOutput } from '../formatters/json.js';
15
+ /**
16
+ * The file's text when the path exists ('' for a directory), null on 404.
17
+ * Re-throws everything else: auth/rate-limit failures must not silently
18
+ * scrub the `hasContributing` etc. flags to `false`, which would understate a
19
+ * repo's community health on a token that lacks scope or has been throttled
20
+ * mid-sequence.
21
+ */
22
+ export declare function probePath(octokit: ReturnType<typeof getOctokit>, owner: string, repo: string, path: string): Promise<string | null>;
14
23
  /**
15
24
  * Run the repo-vet evaluation against an `owner/repo` slug.
16
25
  *
@@ -15,6 +15,8 @@ import { errorMessage, getHttpStatusCode, isRateLimitOrAuthError } from '../core
15
15
  import { warn } from '../core/logger.js';
16
16
  import { validateRepoIdentifier } from './validation.js';
17
17
  import { computeRepoVet } from '../core/repo-vet.js';
18
+ import { derivePolicy, effectivePolicy, policyField } from '../core/repo-policy.js';
19
+ import { decodeBase64 } from '../core/pr-template.js';
18
20
  const MODULE = 'repo-vet';
19
21
  const DAY_MS = 86_400_000;
20
22
  const COMMUNITY_HEALTH_PATHS = [
@@ -30,22 +32,21 @@ const COMMUNITY_HEALTH_PATHS = [
30
32
  { key: 'hasCodeOfConduct', candidates: ['CODE_OF_CONDUCT.md', '.github/CODE_OF_CONDUCT.md'] },
31
33
  ];
32
34
  /**
33
- * Returns true when the path exists. Treats 404 as "absent" (the only
34
- * shape we care about for community-health flags). Re-throws everything
35
- * else — auth/rate-limit failures must not silently scrub the
36
- * `hasContributing` etc. flags to `false`, which would understate a
37
- * repo's community health on a token that lacks scope or has been
38
- * throttled mid-sequence.
35
+ * The file's text when the path exists ('' for a directory), null on 404.
36
+ * Re-throws everything else: auth/rate-limit failures must not silently
37
+ * scrub the `hasContributing` etc. flags to `false`, which would understate a
38
+ * repo's community health on a token that lacks scope or has been throttled
39
+ * mid-sequence.
39
40
  */
40
- async function probePath(octokit, owner, repo, path) {
41
+ export async function probePath(octokit, owner, repo, path) {
41
42
  try {
42
- await octokit.repos.getContent({ owner, repo, path });
43
- return true;
43
+ const { data } = await octokit.repos.getContent({ owner, repo, path });
44
+ return Array.isArray(data) || data.type !== 'file' || !('content' in data) ? '' : decodeBase64(data.content);
44
45
  }
45
46
  catch (err) {
46
47
  const status = err.status;
47
48
  if (status === 404)
48
- return false;
49
+ return null;
49
50
  throw err;
50
51
  }
51
52
  }
@@ -67,12 +68,15 @@ async function checkCommunityHealth(octokit, owner, repo) {
67
68
  hasCodeOfConduct: false,
68
69
  };
69
70
  let incomplete = false;
71
+ const found = {};
70
72
  await Promise.all(COMMUNITY_HEALTH_PATHS.map(async ({ key, candidates }) => {
71
73
  let sawError = false;
72
74
  for (const path of candidates) {
73
75
  try {
74
- if (await probePath(octokit, owner, repo, path)) {
76
+ const text = await probePath(octokit, owner, repo, path);
77
+ if (text !== null) {
75
78
  out[key] = true;
79
+ found[key] = { file: path, content: text };
76
80
  return;
77
81
  }
78
82
  }
@@ -99,6 +103,8 @@ async function checkCommunityHealth(octokit, owner, repo) {
99
103
  hasIssueTemplates: out.hasIssueTemplates,
100
104
  hasPRTemplate: out.hasPRTemplate,
101
105
  hasCodeOfConduct: out.hasCodeOfConduct,
106
+ // Fixed order, whichever probe finished first.
107
+ docs: [found.hasContributing, found.hasPRTemplate].filter((d) => d !== undefined && d.content !== ''),
102
108
  incomplete,
103
109
  };
104
110
  }
@@ -135,6 +141,23 @@ function lookupHistoryScore(repoSlug) {
135
141
  return undefined;
136
142
  }
137
143
  }
144
+ /**
145
+ * The contribution policy that applies (#1953): the user's record, else what
146
+ * this run read from CONTRIBUTING and the PR template, with the blocklist read
147
+ * as a ban. repo-vet stores nothing (its MCP tool is read-only): it has no
148
+ * README / CODE_OF_CONDUCT anti-LLM scan, so its AI reading is partial, and
149
+ * `vet` / `vet-list` record the policy instead.
150
+ */
151
+ function resolvePolicy(repoSlug, docs) {
152
+ const derived = docs.length > 0 ? derivePolicy(docs) : undefined;
153
+ try {
154
+ return effectivePolicy(getStateManager().getState(), repoSlug, derived);
155
+ }
156
+ catch (error) {
157
+ warn(MODULE, `Stored policy lookup skipped (state unavailable): ${errorMessage(error)}`);
158
+ return derived ?? null;
159
+ }
160
+ }
138
161
  function summarizePRMerges(prs, windowDays, now) {
139
162
  const cutoff = now.getTime() - windowDays * DAY_MS;
140
163
  const prMergeTimesDays = [];
@@ -264,6 +287,7 @@ export async function runRepoVet(options) {
264
287
  // relationship score when one exists. Optional so the output is unchanged
265
288
  // for repos the user has no history with (back-compat).
266
289
  const historyScore = lookupHistoryScore(options.repo);
290
+ const policy = resolvePolicy(options.repo, communityHealthSummary.docs);
267
291
  return {
268
292
  repoSlug: options.repo,
269
293
  fetchedAt: now.toISOString(),
@@ -272,5 +296,6 @@ export async function runRepoVet(options) {
272
296
  maintainerActivity: { ...maintainerActivity, releasesIncomplete },
273
297
  ...rest,
274
298
  ...(historyScore !== undefined && { historyScore }),
299
+ ...policyField(policy),
275
300
  };
276
301
  }
@@ -3,10 +3,12 @@
3
3
  * Maps state fields and creates scout instances for search/vet commands.
4
4
  */
5
5
  import { reposAtCap } from '../core/repo-cap.js';
6
+ import { bannedRepos } from '../core/repo-policy.js';
6
7
  import { createScout } from '@oss-scout/core';
7
- import { activeWorkClaims, getStateManager, isLinkedPRStalled, parseGitHubUrl, requireGitHubToken, } from '../core/index.js';
8
- import { SearchRotationSchema } from '../core/state-schema.js';
8
+ import { activeWorkClaims, getStateManager, isLinkedPRStalled, issueRefKey, parseGitHubUrl, requireGitHubToken, } from '../core/index.js';
9
+ import { IssueScopeSchema, isKnownValue, ProjectCategorySchema, SearchRotationSchema } from '../core/state-schema.js';
9
10
  import { computeStrategy } from '../core/strategy.js';
11
+ import { getMachinePath } from '../core/local-config.js';
10
12
  import { loadSkippedIssuesDetailed } from './skip-file-parser.js';
11
13
  import { ISSUE_URL_PATTERN } from './validation.js';
12
14
  /**
@@ -88,7 +90,7 @@ export function buildScoutState(diagnostics, excludeUrls = []) {
88
90
  // silently. The missing case is the common one: a relative skippedIssuesPath
89
91
  // resolves against the CWD, so running /oss outside the directory that holds
90
92
  // it found nothing and the skip list loaded empty without any warning.
91
- const skippedIssuesLoad = loadSkippedIssuesDetailed(config.skippedIssuesPath);
93
+ const skippedIssuesLoad = loadSkippedIssuesDetailed(getMachinePath('skippedIssuesPath', config));
92
94
  if ((skippedIssuesLoad.readError !== undefined || skippedIssuesLoad.notFound) && diagnostics) {
93
95
  diagnostics.skipListUnavailable = true;
94
96
  }
@@ -102,11 +104,16 @@ export function buildScoutState(diagnostics, excludeUrls = []) {
102
104
  // issues scout could surface, so only `/issues/` URLs are forwarded.
103
105
  const skippedIssues = [...skippedIssuesLoad.issues];
104
106
  const skippedUrls = new Set(skippedIssues.map((s) => s.url));
107
+ // One entry per issue (#2001): a dismiss key in another casing of a URL
108
+ // already forwarded is not sent again. Scout compares URLs itself.
109
+ const skippedRefs = new Set(skippedIssues.map((s) => issueRefKey(s.url) ?? s.url));
105
110
  for (const [url, dismissedAt] of Object.entries(config.dismissedIssues ?? {})) {
106
- if (skippedUrls.has(url) || !ISSUE_URL_PATTERN.test(url))
111
+ const ref = issueRefKey(url) ?? url;
112
+ if (skippedUrls.has(url) || skippedRefs.has(ref) || !ISSUE_URL_PATTERN.test(url))
107
113
  continue;
108
114
  const parsed = parseGitHubUrl(url);
109
115
  skippedUrls.add(url);
116
+ skippedRefs.add(ref);
110
117
  skippedIssues.push({
111
118
  url,
112
119
  repo: parsed ? `${parsed.owner}/${parsed.repo}` : '',
@@ -183,12 +190,15 @@ export function buildScoutState(diagnostics, excludeUrls = []) {
183
190
  githubUsername: config.githubUsername,
184
191
  languages: config.languages,
185
192
  labels: config.labels,
186
- scope: config.scope,
193
+ // Stored values a newer release added are not passed on (#2005).
194
+ scope: config.scope?.filter((s) => isKnownValue(IssueScopeSchema.options, s)),
187
195
  excludeRepos: [...config.excludeRepos, ...cappedRepos],
188
196
  excludeOrgs: config.excludeOrgs ?? [],
189
197
  preferredOrgs: config.preferredOrgs ?? [],
190
- aiPolicyBlocklist: config.aiPolicyBlocklist,
191
- projectCategories: config.projectCategories ?? [],
198
+ // The blocklist plus every `banned` policy the user confirmed (#1953).
199
+ // Bans vet read from the docs alone stay searchable; vet still says skip.
200
+ aiPolicyBlocklist: bannedRepos(state),
201
+ projectCategories: (config.projectCategories ?? []).filter((c) => isKnownValue(ProjectCategorySchema.options, c)),
192
202
  minStars: config.minStars,
193
203
  maxIssueAgeDays: config.maxIssueAgeDays,
194
204
  includeDocIssues: config.includeDocIssues,
@@ -204,7 +214,7 @@ export function buildScoutState(diagnostics, excludeUrls = []) {
204
214
  broadPhaseDelayMs: 0,
205
215
  skipBroadWhenSufficientResults: config.skipBroadWhenSufficientResults,
206
216
  complexIssues: config.complexIssues === 'warm' ? 'warm' : 'off',
207
- persistence: config.persistence,
217
+ persistence: config.persistence === 'gist' ? 'gist' : 'local',
208
218
  slmTriageModel: config.slmTriageModel,
209
219
  slmTriageHost: config.slmTriageHost,
210
220
  // Scout 0.9.0 made these required on `ScoutPreferences` (their schema
@@ -11,6 +11,7 @@ import { computeStrategy } from '../core/strategy.js';
11
11
  import { refreshStarredReposIfStale } from '../core/starred-repos.js';
12
12
  import { debug, warn } from '../core/logger.js';
13
13
  import { reposAtCap as findReposAtCap } from '../core/repo-cap.js';
14
+ import { policyField, storedBans, storedPolicy } from '../core/repo-policy.js';
14
15
  import { SCOUT_ROTATION_TTL_DAYS, SEARCH_SEEN_RETENTION_DAYS } from '../core/state-prune.js';
15
16
  const MODULE = 'search';
16
17
  /**
@@ -308,6 +309,7 @@ export async function runSearch(options) {
308
309
  ...(c.personalization?.kind === 'boosted' &&
309
310
  c.personalization.reasons.length > 0 && { boostReasons: c.personalization.reasons }),
310
311
  ...(c.personalization?.kind === 'diversity' && { diversitySlot: true }),
312
+ ...policyField(storedPolicy(stateManager.getState(), c.issue.repo)),
311
313
  };
312
314
  }),
313
315
  excludedRepos: result.excludedRepos,
@@ -318,6 +320,11 @@ export async function runSearch(options) {
318
320
  if (gistSyncWarning) {
319
321
  searchOutput.gistSyncWarning = gistSyncWarning;
320
322
  }
323
+ // Unreviewed bans stay searchable (#1953); list them so the agent sees them.
324
+ const policyBannedRepos = storedBans(stateManager.getState());
325
+ if (policyBannedRepos.length > 0) {
326
+ searchOutput.policyBannedRepos = policyBannedRepos;
327
+ }
321
328
  if (result.rateLimitWarning) {
322
329
  searchOutput.rateLimitWarning = result.rateLimitWarning;
323
330
  }
@@ -2,7 +2,6 @@
2
2
  * Setup command
3
3
  * Interactive setup / configuration
4
4
  */
5
- import { type ProjectCategory, type IssueScope } from '../core/types.js';
6
5
  interface SetupOptions {
7
6
  reset?: boolean;
8
7
  set?: string[];
@@ -23,9 +22,10 @@ export interface SetupCompleteOutput {
23
22
  approachingDormantDays: number;
24
23
  languages: string[];
25
24
  labels: string[];
26
- projectCategories: ProjectCategory[];
25
+ /** As stored: may hold values a newer release added (#2005). */
26
+ projectCategories: string[];
27
27
  preferredOrgs: string[];
28
- scope: IssueScope[];
28
+ scope: string[];
29
29
  persistence: 'local' | 'gist';
30
30
  };
31
31
  }