@oss-autopilot/core 3.42.5 → 3.44.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 (192) hide show
  1. package/dist/cli-pre-action.js +8 -3
  2. package/dist/cli-registry.js +428 -27
  3. package/dist/cli.bundle.cjs +212 -156
  4. package/dist/commands/check-integration.js +5 -1
  5. package/dist/commands/cleanup.d.ts +80 -0
  6. package/dist/commands/cleanup.js +334 -0
  7. package/dist/commands/comments.d.ts +14 -1
  8. package/dist/commands/comments.js +17 -5
  9. package/dist/commands/config.d.ts +2 -0
  10. package/dist/commands/config.js +63 -6
  11. package/dist/commands/daily-dismiss-filter.d.ts +7 -0
  12. package/dist/commands/daily-dismiss-filter.js +17 -1
  13. package/dist/commands/daily-ledger.d.ts +150 -0
  14. package/dist/commands/daily-ledger.js +248 -0
  15. package/dist/commands/daily-recent-prs.d.ts +26 -0
  16. package/dist/commands/daily-recent-prs.js +55 -0
  17. package/dist/commands/daily-render.d.ts +2 -1
  18. package/dist/commands/daily-render.js +4 -1
  19. package/dist/commands/daily.d.ts +5 -1
  20. package/dist/commands/daily.js +83 -93
  21. package/dist/commands/dashboard-cache.d.ts +2 -0
  22. package/dist/commands/dashboard-cache.js +33 -8
  23. package/dist/commands/dashboard-data.js +113 -69
  24. package/dist/commands/dashboard-gist-sync.js +3 -1
  25. package/dist/commands/dashboard-lifecycle.d.ts +36 -8
  26. package/dist/commands/dashboard-lifecycle.js +132 -39
  27. package/dist/commands/dashboard-process.d.ts +49 -1
  28. package/dist/commands/dashboard-process.js +111 -12
  29. package/dist/commands/dashboard-server.js +89 -23
  30. package/dist/commands/detect-formatters.js +1 -0
  31. package/dist/commands/dismiss.js +11 -7
  32. package/dist/commands/doctor.d.ts +15 -1
  33. package/dist/commands/doctor.js +66 -5
  34. package/dist/commands/draft.d.ts +77 -0
  35. package/dist/commands/draft.js +218 -0
  36. package/dist/commands/eval.js +1 -0
  37. package/dist/commands/fork-prune.d.ts +58 -0
  38. package/dist/commands/fork-prune.js +247 -0
  39. package/dist/commands/guidelines.d.ts +69 -2
  40. package/dist/commands/guidelines.js +158 -14
  41. package/dist/commands/index.d.ts +29 -4
  42. package/dist/commands/index.js +20 -3
  43. package/dist/commands/issue-thread.d.ts +46 -0
  44. package/dist/commands/issue-thread.js +123 -0
  45. package/dist/commands/ledger-backfill.d.ts +9 -0
  46. package/dist/commands/ledger-backfill.js +44 -1
  47. package/dist/commands/list-mark-done.d.ts +2 -1
  48. package/dist/commands/list-mark-done.js +3 -1
  49. package/dist/commands/list-move-tier.d.ts +2 -1
  50. package/dist/commands/list-move-tier.js +3 -1
  51. package/dist/commands/local-repos.js +10 -5
  52. package/dist/commands/locate-issue-list.d.ts +40 -17
  53. package/dist/commands/locate-issue-list.js +148 -88
  54. package/dist/commands/move.js +7 -1
  55. package/dist/commands/overnight-handoff.d.ts +17 -7
  56. package/dist/commands/overnight-handoff.js +36 -14
  57. package/dist/commands/overnight-push-prep.d.ts +14 -8
  58. package/dist/commands/overnight-push-prep.js +107 -35
  59. package/dist/commands/overnight-tool-rules.d.ts +54 -0
  60. package/dist/commands/overnight-tool-rules.js +217 -0
  61. package/dist/commands/overnight.d.ts +5 -6
  62. package/dist/commands/overnight.js +61 -140
  63. package/dist/commands/parse-list.js +7 -1
  64. package/dist/commands/policy.d.ts +90 -0
  65. package/dist/commands/policy.js +276 -0
  66. package/dist/commands/pr-create.d.ts +48 -0
  67. package/dist/commands/pr-create.js +200 -0
  68. package/dist/commands/pr-preflight.d.ts +69 -0
  69. package/dist/commands/pr-preflight.js +348 -0
  70. package/dist/commands/repo-vet.d.ts +9 -0
  71. package/dist/commands/repo-vet.js +36 -11
  72. package/dist/commands/scout-bridge.js +18 -8
  73. package/dist/commands/search.js +7 -0
  74. package/dist/commands/setup.d.ts +3 -3
  75. package/dist/commands/setup.js +160 -48
  76. package/dist/commands/skip-add.js +10 -1
  77. package/dist/commands/startup.d.ts +12 -3
  78. package/dist/commands/startup.js +82 -49
  79. package/dist/commands/state-cmd.d.ts +2 -0
  80. package/dist/commands/state-cmd.js +5 -1
  81. package/dist/commands/stats.js +1 -0
  82. package/dist/commands/status.js +6 -0
  83. package/dist/commands/strategy.js +1 -0
  84. package/dist/commands/validation.d.ts +5 -0
  85. package/dist/commands/validation.js +5 -0
  86. package/dist/commands/vet-list.d.ts +6 -0
  87. package/dist/commands/vet-list.js +26 -1
  88. package/dist/commands/vet.d.ts +20 -0
  89. package/dist/commands/vet.js +133 -2
  90. package/dist/commands/work.d.ts +4 -0
  91. package/dist/commands/work.js +34 -11
  92. package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
  93. package/dist/core/anti-llm-policy.d.ts +3 -0
  94. package/dist/core/anti-llm-policy.js +3 -0
  95. package/dist/core/auth.js +2 -0
  96. package/dist/core/ci-analysis.d.ts +7 -2
  97. package/dist/core/ci-analysis.js +76 -21
  98. package/dist/core/commit-date.d.ts +45 -0
  99. package/dist/core/commit-date.js +45 -0
  100. package/dist/core/compliance-score.d.ts +3 -0
  101. package/dist/core/compliance-score.js +13 -9
  102. package/dist/core/config-registry.d.ts +27 -2
  103. package/dist/core/config-registry.js +94 -7
  104. package/dist/core/contributing.d.ts +2 -3
  105. package/dist/core/contributing.js +2 -3
  106. package/dist/core/daily-logic.d.ts +30 -5
  107. package/dist/core/daily-logic.js +68 -19
  108. package/dist/core/errors.d.ts +37 -3
  109. package/dist/core/errors.js +54 -5
  110. package/dist/core/fork-prune.d.ts +149 -0
  111. package/dist/core/fork-prune.js +333 -0
  112. package/dist/core/gist-health.d.ts +15 -3
  113. package/dist/core/gist-health.js +8 -0
  114. package/dist/core/gist-state-store.d.ts +24 -4
  115. package/dist/core/gist-state-store.js +98 -51
  116. package/dist/core/github-stats.d.ts +110 -16
  117. package/dist/core/github-stats.js +295 -110
  118. package/dist/core/http-cache.d.ts +0 -10
  119. package/dist/core/http-cache.js +0 -19
  120. package/dist/core/index.d.ts +13 -6
  121. package/dist/core/index.js +16 -6
  122. package/dist/core/issue-conversation.d.ts +8 -2
  123. package/dist/core/issue-conversation.js +31 -12
  124. package/dist/core/local-config.d.ts +95 -0
  125. package/dist/core/local-config.js +270 -0
  126. package/dist/core/merged-pr-notes.d.ts +2 -2
  127. package/dist/core/pacing.d.ts +41 -0
  128. package/dist/core/pacing.js +115 -0
  129. package/dist/core/pagination.d.ts +55 -0
  130. package/dist/core/pagination.js +59 -0
  131. package/dist/core/paths.d.ts +7 -0
  132. package/dist/core/paths.js +9 -0
  133. package/dist/core/pr-assembly.d.ts +2 -0
  134. package/dist/core/pr-assembly.js +6 -2
  135. package/dist/core/pr-graphql.d.ts +53 -4
  136. package/dist/core/pr-graphql.js +87 -14
  137. package/dist/core/pr-monitor.d.ts +35 -12
  138. package/dist/core/pr-monitor.js +110 -26
  139. package/dist/core/pr-preflight.d.ts +154 -0
  140. package/dist/core/pr-preflight.js +753 -0
  141. package/dist/core/pr-quality-rubric.d.ts +0 -6
  142. package/dist/core/pr-quality-rubric.js +0 -8
  143. package/dist/core/pr-template.d.ts +2 -0
  144. package/dist/core/pr-template.js +5 -1
  145. package/dist/core/prose-script.d.ts +72 -0
  146. package/dist/core/prose-script.js +223 -0
  147. package/dist/core/repo-policy.d.ts +111 -0
  148. package/dist/core/repo-policy.js +428 -0
  149. package/dist/core/repo-score-manager.d.ts +66 -0
  150. package/dist/core/repo-score-manager.js +140 -1
  151. package/dist/core/review-analysis.d.ts +49 -21
  152. package/dist/core/review-analysis.js +89 -15
  153. package/dist/core/reviewed-prs-fetch.js +11 -29
  154. package/dist/core/reviewed-prs.js +8 -15
  155. package/dist/core/stale-data.d.ts +78 -0
  156. package/dist/core/stale-data.js +153 -0
  157. package/dist/core/state-persistence.d.ts +62 -27
  158. package/dist/core/state-persistence.js +338 -119
  159. package/dist/core/state-schema.d.ts +152 -210
  160. package/dist/core/state-schema.js +232 -80
  161. package/dist/core/state.d.ts +81 -8
  162. package/dist/core/state.js +239 -46
  163. package/dist/core/status-determination.js +32 -12
  164. package/dist/core/strategy.js +3 -1
  165. package/dist/core/types.d.ts +22 -1
  166. package/dist/core/types.js +1 -0
  167. package/dist/core/untrusted-content.d.ts +30 -11
  168. package/dist/core/untrusted-content.js +95 -42
  169. package/dist/core/urls.d.ts +33 -0
  170. package/dist/core/urls.js +94 -0
  171. package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
  172. package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
  173. package/dist/dashboard/index.html +1 -1
  174. package/dist/formatters/json.d.ts +432 -10
  175. package/dist/formatters/json.js +156 -1
  176. package/package.json +6 -6
  177. package/dist/core/ci-enforced-tools.d.ts +0 -35
  178. package/dist/core/ci-enforced-tools.js +0 -109
  179. package/dist/core/comment-decision.d.ts +0 -79
  180. package/dist/core/comment-decision.js +0 -82
  181. package/dist/core/extraction-categories.d.ts +0 -55
  182. package/dist/core/extraction-categories.js +0 -108
  183. package/dist/core/follow-up-history.d.ts +0 -40
  184. package/dist/core/follow-up-history.js +0 -71
  185. package/dist/core/issue-effort.d.ts +0 -29
  186. package/dist/core/issue-effort.js +0 -47
  187. package/dist/core/maintainer-hints.d.ts +0 -23
  188. package/dist/core/maintainer-hints.js +0 -36
  189. package/dist/core/workflow-state.d.ts +0 -56
  190. package/dist/core/workflow-state.js +0 -101
  191. package/dist/dashboard/assets/chart-panel-DPKNBUts.js +0 -3
  192. package/dist/dashboard/assets/index-B25bZOYX.js +0 -55
@@ -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
  }
@@ -3,7 +3,8 @@
3
3
  * Interactive setup / configuration
4
4
  */
5
5
  import { getStateManager, DEFAULT_CONFIG, formatUnknownKeyError, getSetupKeys, maybeCheckpoint, } from '../core/index.js';
6
- import { ValidationError } from '../core/errors.js';
6
+ import { ValidationError, assertAttended } from '../core/errors.js';
7
+ import { MACHINE_PATH_KEYS, assertSafeMachinePath, setMachinePath, setMachineScanPaths } from '../core/local-config.js';
7
8
  import { validateGitHubUsername } from './validation.js';
8
9
  import { PROJECT_CATEGORIES, ISSUE_SCOPES, DIFF_TOOLS, } from '../core/types.js';
9
10
  const MODULE = 'setup';
@@ -28,6 +29,137 @@ function parseComplexIssues(value) {
28
29
  }
29
30
  return value;
30
31
  }
32
+ /** Settings kept in this machine's local file, never synced (#1950, #2010). */
33
+ const MACHINE_LOCAL_KEYS = new Set([...MACHINE_PATH_KEYS, 'localRepoScanPaths']);
34
+ /**
35
+ * Refuse unknown keys, path values with a shell metacharacter (#1934), and
36
+ * an unattended run shrinking aiPolicyBlocklist (#2036), before any pair is
37
+ * applied.
38
+ */
39
+ function prevalidateSettings(settings, config) {
40
+ const knownKeys = new Set(getSetupKeys());
41
+ // Each safeguard pair is checked against the list the pairs before it
42
+ // leave, so a repeated key cannot shrink the list in two steps.
43
+ const lists = {
44
+ aiPolicyBlocklist: config.aiPolicyBlocklist ?? [],
45
+ keepForks: config.keepForks ?? [],
46
+ };
47
+ for (const setting of settings) {
48
+ const [key] = setting.split('=', 1);
49
+ if (!knownKeys.has(key)) {
50
+ throw new ValidationError(formatUnknownKeyError(key, 'setup'));
51
+ }
52
+ if (MACHINE_LOCAL_KEYS.has(key)) {
53
+ assertSafeMachinePath(key, setting.slice(key.length + 1));
54
+ }
55
+ if (isSafeguardList(key)) {
56
+ const parsed = parseBlocklist(setting.slice(key.length + 1));
57
+ assertBlocklistKept(key, lists[key], parsed);
58
+ lists[key] = parsed.stored ?? lists[key];
59
+ }
60
+ if (isPacingKey(key)) {
61
+ assertPacingKept(key, config[key], parsePacingCap(setting.slice(key.length + 1), key));
62
+ }
63
+ }
64
+ }
65
+ /** The owner/repo lists that protect something; an unattended run may add to them, never remove (#2036, #1912). */
66
+ const SAFEGUARD_LISTS = ['aiPolicyBlocklist', 'keepForks'];
67
+ function isSafeguardList(key) {
68
+ return SAFEGUARD_LISTS.includes(key);
69
+ }
70
+ /** Split an `aiPolicyBlocklist` or `keepForks` value the way the setting stores it. */
71
+ function parseBlocklist(value) {
72
+ const entries = value
73
+ .split(',')
74
+ .map((r) => r.trim())
75
+ .filter(Boolean);
76
+ const valid = [];
77
+ const invalid = [];
78
+ for (const entry of entries) {
79
+ const normalized = entry.replaceAll(/\s+/g, '');
80
+ if (/^[\w.-]+\/[\w.-]+$/.test(normalized)) {
81
+ valid.push(normalized);
82
+ }
83
+ else {
84
+ invalid.push(entry);
85
+ }
86
+ }
87
+ return { valid, invalid, stored: valid.length === 0 && entries.length > 0 ? undefined : valid };
88
+ }
89
+ /**
90
+ * Refuse, during an unattended run, an `aiPolicyBlocklist` or `keepForks`
91
+ * value whose stored list leaves out a repo now on the list (#2036, #1912).
92
+ * Each repo on the blocklist is a ban and each on keepForks is a fork
93
+ * fork-prune must not delete, and the list is replaced whole, so `key=`
94
+ * lifts them all. `policy set` and `policy reset` refuse unattended runs for
95
+ * the same reason. Adding repos is still allowed. Entries compare
96
+ * case-insensitively, the way both lists are matched.
97
+ */
98
+ function assertBlocklistKept(key, current, parsed) {
99
+ if (parsed.stored === undefined)
100
+ return;
101
+ const next = new Set(parsed.stored.map((repo) => repo.toLowerCase()));
102
+ if (current.some((repo) => !next.has(repo.toLowerCase()))) {
103
+ assertAttended(`remove repos from ${key}`);
104
+ }
105
+ }
106
+ /**
107
+ * Store an `aiPolicyBlocklist` or `keepForks` value. Invalid entries are
108
+ * skipped with a warning; when every entry is invalid the list is left as is
109
+ * (#1887). Checked again here, not only before the loop: a Gist conflict
110
+ * re-applies on a refreshed list that may hold repos another machine added (#2036).
111
+ */
112
+ function applySafeguardList(stateManager, key, value, results, warnings) {
113
+ const parsed = parseBlocklist(value);
114
+ assertBlocklistKept(key, stateManager.getState().config[key] ?? [], parsed);
115
+ if (parsed.invalid.length > 0) {
116
+ warnings.push(`Warning: Skipping invalid entries (expected "owner/repo" format): ${parsed.invalid.join(', ')}`);
117
+ results[`${key}_invalidEntries`] = parsed.invalid.join(', ');
118
+ }
119
+ if (parsed.stored === undefined) {
120
+ const what = key === 'aiPolicyBlocklist' ? 'Blocklist' : key;
121
+ warnings.push(`Warning: All entries were invalid. ${what} not updated.`);
122
+ // No results entry: nothing was stored (#1887).
123
+ return;
124
+ }
125
+ stateManager.updateConfig({ [key]: parsed.valid });
126
+ results[key] = parsed.valid.length > 0 ? parsed.valid.join(', ') : '(empty)';
127
+ }
128
+ const PACING_KEYS = ['maxNewPrsPerDay', 'maxNewForksPerDay'];
129
+ function isPacingKey(key) {
130
+ return PACING_KEYS.includes(key);
131
+ }
132
+ /** A pacing cap value: empty or 0 clears it (undefined), else a positive integer. */
133
+ function parsePacingCap(value, key) {
134
+ return value === '' ? undefined : parseNonNegativeInt(value, key) || undefined;
135
+ }
136
+ /**
137
+ * Refuse, during an unattended run, raising or clearing a pacing cap that is
138
+ * set (#1911): the cap limits how many PRs and forks the tool opens, so only
139
+ * the user lifts it, as with the AI-policy ban list (#2036). Lowering or
140
+ * setting a first cap is allowed.
141
+ */
142
+ function assertPacingKept(key, current, next) {
143
+ if (current && (next === undefined || next > current)) {
144
+ assertAttended(`raise or clear ${key}`);
145
+ }
146
+ }
147
+ /** Set or clear a pacing cap; returns what was stored, for the output. */
148
+ function applyPacingCap(stateManager, key, value) {
149
+ const cap = parsePacingCap(value, key);
150
+ // Again here: a Gist conflict re-applies on a refreshed config.
151
+ assertPacingKept(key, stateManager.getState().config[key], cap);
152
+ stateManager.updateConfig({ [key]: cap });
153
+ return cap === undefined ? '(no cap)' : String(cap);
154
+ }
155
+ /** True when every `key=value` names a path kept in this machine's local file. */
156
+ function isMachineLocalOnly(settings) {
157
+ return settings.every((setting) => MACHINE_LOCAL_KEYS.has(setting.split('=', 1)[0]));
158
+ }
159
+ /** Warning for the config keys retired in #1948: still accepted and stored, never read. */
160
+ function retiredKeyWarning(key) {
161
+ return `${key} is retired and not read by oss-autopilot; it is kept for compatibility`;
162
+ }
31
163
  /**
32
164
  * Interactive setup wizard or direct setting application.
33
165
  *
@@ -53,13 +185,7 @@ export async function runSetup(options) {
53
185
  // mid-loop would leave earlier successful updates applied in memory (a real
54
186
  // issue for long-running consumers like the MCP server and dashboard that
55
187
  // share the StateManager singleton across requests).
56
- const knownKeys = new Set(getSetupKeys());
57
- for (const setting of options.set) {
58
- const [key] = setting.split('=', 1);
59
- if (!knownKeys.has(key)) {
60
- throw new ValidationError(formatUnknownKeyError(key, 'setup'));
61
- }
62
- }
188
+ prevalidateSettings(options.set, config);
63
189
  // Named so the Gist conflict path can re-apply the same settings on a
64
190
  // refreshed baseline (maybeCheckpoint below).
65
191
  const applySettings = () => {
@@ -67,6 +193,14 @@ export async function runSetup(options) {
67
193
  for (const setting of options.set) {
68
194
  const [key, ...valueParts] = setting.split('=');
69
195
  const value = valueParts.join('=');
196
+ if (isSafeguardList(key)) {
197
+ applySafeguardList(stateManager, key, value, results, warnings);
198
+ continue;
199
+ }
200
+ if (isPacingKey(key)) {
201
+ results[key] = applyPacingCap(stateManager, key, value);
202
+ continue;
203
+ }
70
204
  switch (key) {
71
205
  case 'username': {
72
206
  validateGitHubUsername(value);
@@ -140,11 +274,6 @@ export async function runSetup(options) {
140
274
  results[key] = String(threshold);
141
275
  break;
142
276
  }
143
- case 'skippedIssuesPath': {
144
- stateManager.updateConfig({ skippedIssuesPath: value || undefined });
145
- results[key] = value || '(cleared)';
146
- break;
147
- }
148
277
  case 'autoExtractLearnings': {
149
278
  if (value !== 'true' && value !== 'false') {
150
279
  throw new ValidationError(`Invalid value for autoExtractLearnings: "${value}". Must be "true" or "false".`);
@@ -161,6 +290,7 @@ export async function runSetup(options) {
161
290
  const enabled = value === 'true';
162
291
  stateManager.updateConfig({ autoFormatBeforePush: enabled });
163
292
  results[key] = String(enabled);
293
+ warnings.push(retiredKeyWarning(key));
164
294
  break;
165
295
  }
166
296
  case 'trustOwnRepoWrites': {
@@ -170,6 +300,7 @@ export async function runSetup(options) {
170
300
  const trusted = value === 'true';
171
301
  stateManager.updateConfig({ trustOwnRepoWrites: trusted });
172
302
  results[key] = String(trusted);
303
+ warnings.push(retiredKeyWarning(key));
173
304
  break;
174
305
  }
175
306
  case 'includeDocIssues': {
@@ -177,35 +308,6 @@ export async function runSetup(options) {
177
308
  results[key] = value === 'true' ? 'true' : 'false';
178
309
  break;
179
310
  }
180
- case 'aiPolicyBlocklist': {
181
- const entries = value
182
- .split(',')
183
- .map((r) => r.trim())
184
- .filter(Boolean);
185
- const valid = [];
186
- const invalid = [];
187
- for (const entry of entries) {
188
- const normalized = entry.replaceAll(/\s+/g, '');
189
- if (/^[\w.-]+\/[\w.-]+$/.test(normalized)) {
190
- valid.push(normalized);
191
- }
192
- else {
193
- invalid.push(entry);
194
- }
195
- }
196
- if (invalid.length > 0) {
197
- warnings.push(`Warning: Skipping invalid entries (expected "owner/repo" format): ${invalid.join(', ')}`);
198
- results['aiPolicyBlocklist_invalidEntries'] = invalid.join(', ');
199
- }
200
- if (valid.length === 0 && entries.length > 0) {
201
- warnings.push('Warning: All entries were invalid. Blocklist not updated.');
202
- results[key] = '(all entries invalid)';
203
- break;
204
- }
205
- stateManager.updateConfig({ aiPolicyBlocklist: valid });
206
- results[key] = valid.length > 0 ? valid.join(', ') : '(empty)';
207
- break;
208
- }
209
311
  case 'avoidRepos': {
210
312
  // Same owner/repo validation as aiPolicyBlocklist: skip (and warn
211
313
  // about) malformed entries instead of failing the whole set.
@@ -229,7 +331,7 @@ export async function runSetup(options) {
229
331
  }
230
332
  if (valid.length === 0 && entries.length > 0) {
231
333
  warnings.push('Warning: All entries were invalid. avoidRepos not updated.');
232
- results[key] = '(all entries invalid)';
334
+ // No results entry: nothing was stored (#1887).
233
335
  break;
234
336
  }
235
337
  const dedupedRepos = [...new Set(valid)];
@@ -327,9 +429,13 @@ export async function runSetup(options) {
327
429
  results[key] = value;
328
430
  break;
329
431
  }
330
- case 'issueListPath': {
331
- stateManager.updateConfig({ issueListPath: value || undefined });
332
- results[key] = value || '(cleared)';
432
+ case 'issueListPath':
433
+ case 'skippedIssuesPath': {
434
+ results[key] = setMachinePath(key, value || undefined) || '(cleared)';
435
+ break;
436
+ }
437
+ case 'localRepoScanPaths': {
438
+ results[key] = setMachineScanPaths(value).join(', ') || '(cleared, using defaults)';
333
439
  break;
334
440
  }
335
441
  case 'diffTool': {
@@ -364,6 +470,7 @@ export async function runSetup(options) {
364
470
  const minutes = parsePositiveInt(value, 'healthCheckFreshnessMinutes');
365
471
  stateManager.updateConfig({ healthCheckFreshnessMinutes: minutes });
366
472
  results[key] = String(minutes);
473
+ warnings.push(retiredKeyWarning(key));
367
474
  break;
368
475
  }
369
476
  case 'reviewMaxPasses': {
@@ -389,7 +496,11 @@ export async function runSetup(options) {
389
496
  // Push the settings mutation to the Gist in gist mode (no-op locally).
390
497
  // Without this the change only hits the local cache and the next
391
498
  // bootstrap reverts it from the Gist (#1440).
392
- const gistSyncWarning = await maybeCheckpoint(stateManager, MODULE, () => stateManager.batch(applySettings));
499
+ // Path settings are written to this machine's local file only (#1950), so
500
+ // a call that sets nothing else has nothing to push.
501
+ const gistSyncWarning = isMachineLocalOnly(options.set)
502
+ ? null
503
+ : await maybeCheckpoint(stateManager, MODULE, () => stateManager.batch(applySettings));
393
504
  return {
394
505
  success: true,
395
506
  settings: results,
@@ -411,7 +522,7 @@ export async function runSetup(options) {
411
522
  projectCategories: config.projectCategories ?? [],
412
523
  preferredOrgs: config.preferredOrgs ?? [],
413
524
  scope: config.scope ?? [],
414
- persistence: config.persistence ?? 'local',
525
+ persistence: config.persistence === 'gist' ? 'gist' : 'local',
415
526
  },
416
527
  };
417
528
  }
@@ -503,6 +614,7 @@ export async function runSetup(options) {
503
614
  * Check whether initial setup has been completed.
504
615
  * @returns Setup status and configured username
505
616
  */
617
+ // eslint-disable-next-line @typescript-eslint/require-await -- async keeps the Promise-returning contract callers rely on; the body has no await yet
506
618
  export async function runCheckSetup() {
507
619
  const stateManager = getStateManager();
508
620
  return {
@@ -1,6 +1,8 @@
1
1
  import * as fs from 'node:fs';
2
+ import path from 'node:path';
2
3
  import { loadSkippedIssues } from './skip-file-parser.js';
3
4
  import { getStateManager } from '../core/index.js';
5
+ import { getMachinePath } from '../core/local-config.js';
4
6
  // Keep in sync with GITHUB_URL_RE in skip-file-parser.ts. Captures are kept
5
7
  // (despite being unused here) so the regex stays byte-identical to the parser
6
8
  // version where the captures are needed.
@@ -20,7 +22,7 @@ function formatUtcDate(d) {
20
22
  * @throws when no path can be resolved or the URL isn't a GitHub issue/PR URL.
21
23
  */
22
24
  export function runSkipAdd(options) {
23
- const skipFilePath = options.skipFilePath ?? getStateManager().getState().config.skippedIssuesPath;
25
+ const skipFilePath = options.skipFilePath ?? getMachinePath('skippedIssuesPath', getStateManager().getState().config);
24
26
  if (!skipFilePath) {
25
27
  throw new Error('No skipped-issues path configured. Set one via `oss-autopilot setup --set skippedIssuesPath=<path>` or pass --path.');
26
28
  }
@@ -37,6 +39,13 @@ export function runSkipAdd(options) {
37
39
  };
38
40
  }
39
41
  if (!fs.existsSync(skipFilePath)) {
42
+ // A path whose directory is missing is usually another machine's synced
43
+ // value (#1950): say so instead of failing with a bare ENOENT, and never
44
+ // create directories for it.
45
+ if (!fs.existsSync(path.dirname(path.resolve(skipFilePath)))) {
46
+ throw new Error(`Skipped-issues file ${skipFilePath} cannot be created: its directory does not exist on this machine. ` +
47
+ 'Set the path for this machine via `oss-autopilot setup --set skippedIssuesPath=<path>` or pass --path.');
48
+ }
40
49
  fs.writeFileSync(skipFilePath, FILE_HEADER);
41
50
  }
42
51
  const date = formatUtcDate(options.now ?? new Date());
@@ -7,7 +7,7 @@
7
7
  * `node cli.bundle.cjs startup --json` call, reducing UI noise in Claude Code.
8
8
  */
9
9
  import { type StartupOutput, type IssueListInfo } from '../formatters/json.js';
10
- export { parseIssueListPathFromConfig } from './locate-issue-list.js';
10
+ import { type StaleDataCounts } from '../core/stale-data.js';
11
11
  /**
12
12
  * Count available and completed items in an issue list file.
13
13
  * Available items exclude any vetting status that moves an item out of the
@@ -23,15 +23,24 @@ export declare function countIssueListItems(content: string): {
23
23
  blockedCount: number;
24
24
  };
25
25
  /**
26
- * Detect an issue list file from config or known paths.
26
+ * Detect the configured issue list file.
27
+ * @param shouldSuggest - With no configured list, return a list found in
28
+ * the current directory as `source: 'auto-detected'` for the user to confirm
29
+ * (#1933). Only `/oss` startup asks; nothing about it is saved.
27
30
  * @returns Issue list info with path and item counts, or undefined if not found
28
31
  */
29
- export declare function detectIssueList(): IssueListInfo | undefined;
32
+ export declare function detectIssueList(shouldSuggest?: boolean): IssueListInfo | undefined;
30
33
  /**
31
34
  * Open a URL in the default system browser.
32
35
  * @param url - URL to open
33
36
  */
34
37
  export declare function openInBrowser(url: string): void;
38
+ /**
39
+ * Stale-data counts for the `/oss` summary (#2049), from directory listings
40
+ * only (no Git in the worktrees). Any error leaves the field out: this must
41
+ * never fail startup.
42
+ */
43
+ export declare function staleDataForStartup(): StaleDataCounts | undefined;
35
44
  /**
36
45
  * Run startup checks and return structured output.
37
46
  * Returns StartupOutput with one of three shapes: