@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.
- package/dist/cli-pre-action.js +8 -3
- package/dist/cli-registry.js +428 -27
- package/dist/cli.bundle.cjs +212 -156
- package/dist/commands/check-integration.js +5 -1
- package/dist/commands/cleanup.d.ts +80 -0
- package/dist/commands/cleanup.js +334 -0
- package/dist/commands/comments.d.ts +14 -1
- package/dist/commands/comments.js +17 -5
- package/dist/commands/config.d.ts +2 -0
- package/dist/commands/config.js +63 -6
- package/dist/commands/daily-dismiss-filter.d.ts +7 -0
- package/dist/commands/daily-dismiss-filter.js +17 -1
- package/dist/commands/daily-ledger.d.ts +150 -0
- package/dist/commands/daily-ledger.js +248 -0
- package/dist/commands/daily-recent-prs.d.ts +26 -0
- package/dist/commands/daily-recent-prs.js +55 -0
- package/dist/commands/daily-render.d.ts +2 -1
- package/dist/commands/daily-render.js +4 -1
- package/dist/commands/daily.d.ts +5 -1
- package/dist/commands/daily.js +83 -93
- package/dist/commands/dashboard-cache.d.ts +2 -0
- package/dist/commands/dashboard-cache.js +33 -8
- package/dist/commands/dashboard-data.js +113 -69
- package/dist/commands/dashboard-gist-sync.js +3 -1
- package/dist/commands/dashboard-lifecycle.d.ts +36 -8
- package/dist/commands/dashboard-lifecycle.js +132 -39
- package/dist/commands/dashboard-process.d.ts +49 -1
- package/dist/commands/dashboard-process.js +111 -12
- package/dist/commands/dashboard-server.js +89 -23
- package/dist/commands/detect-formatters.js +1 -0
- package/dist/commands/dismiss.js +11 -7
- package/dist/commands/doctor.d.ts +15 -1
- package/dist/commands/doctor.js +66 -5
- package/dist/commands/draft.d.ts +77 -0
- package/dist/commands/draft.js +218 -0
- package/dist/commands/eval.js +1 -0
- package/dist/commands/fork-prune.d.ts +58 -0
- package/dist/commands/fork-prune.js +247 -0
- package/dist/commands/guidelines.d.ts +69 -2
- package/dist/commands/guidelines.js +158 -14
- package/dist/commands/index.d.ts +29 -4
- package/dist/commands/index.js +20 -3
- package/dist/commands/issue-thread.d.ts +46 -0
- package/dist/commands/issue-thread.js +123 -0
- package/dist/commands/ledger-backfill.d.ts +9 -0
- package/dist/commands/ledger-backfill.js +44 -1
- package/dist/commands/list-mark-done.d.ts +2 -1
- package/dist/commands/list-mark-done.js +3 -1
- package/dist/commands/list-move-tier.d.ts +2 -1
- package/dist/commands/list-move-tier.js +3 -1
- package/dist/commands/local-repos.js +10 -5
- package/dist/commands/locate-issue-list.d.ts +40 -17
- package/dist/commands/locate-issue-list.js +148 -88
- package/dist/commands/move.js +7 -1
- package/dist/commands/overnight-handoff.d.ts +17 -7
- package/dist/commands/overnight-handoff.js +36 -14
- package/dist/commands/overnight-push-prep.d.ts +14 -8
- package/dist/commands/overnight-push-prep.js +107 -35
- package/dist/commands/overnight-tool-rules.d.ts +54 -0
- package/dist/commands/overnight-tool-rules.js +217 -0
- package/dist/commands/overnight.d.ts +5 -6
- package/dist/commands/overnight.js +61 -140
- package/dist/commands/parse-list.js +7 -1
- package/dist/commands/policy.d.ts +90 -0
- package/dist/commands/policy.js +276 -0
- package/dist/commands/pr-create.d.ts +48 -0
- package/dist/commands/pr-create.js +200 -0
- package/dist/commands/pr-preflight.d.ts +69 -0
- package/dist/commands/pr-preflight.js +348 -0
- package/dist/commands/repo-vet.d.ts +9 -0
- package/dist/commands/repo-vet.js +36 -11
- package/dist/commands/scout-bridge.js +18 -8
- package/dist/commands/search.js +7 -0
- package/dist/commands/setup.d.ts +3 -3
- package/dist/commands/setup.js +160 -48
- package/dist/commands/skip-add.js +10 -1
- package/dist/commands/startup.d.ts +12 -3
- package/dist/commands/startup.js +82 -49
- package/dist/commands/state-cmd.d.ts +2 -0
- package/dist/commands/state-cmd.js +5 -1
- package/dist/commands/stats.js +1 -0
- package/dist/commands/status.js +6 -0
- package/dist/commands/strategy.js +1 -0
- package/dist/commands/validation.d.ts +5 -0
- package/dist/commands/validation.js +5 -0
- package/dist/commands/vet-list.d.ts +6 -0
- package/dist/commands/vet-list.js +26 -1
- package/dist/commands/vet.d.ts +20 -0
- package/dist/commands/vet.js +133 -2
- package/dist/commands/work.d.ts +4 -0
- package/dist/commands/work.js +34 -11
- package/dist/core/__fixtures__/prompt-injection-payloads.js +31 -0
- package/dist/core/anti-llm-policy.d.ts +3 -0
- package/dist/core/anti-llm-policy.js +3 -0
- package/dist/core/auth.js +2 -0
- package/dist/core/ci-analysis.d.ts +7 -2
- package/dist/core/ci-analysis.js +76 -21
- package/dist/core/commit-date.d.ts +45 -0
- package/dist/core/commit-date.js +45 -0
- package/dist/core/compliance-score.d.ts +3 -0
- package/dist/core/compliance-score.js +13 -9
- package/dist/core/config-registry.d.ts +27 -2
- package/dist/core/config-registry.js +94 -7
- package/dist/core/contributing.d.ts +2 -3
- package/dist/core/contributing.js +2 -3
- package/dist/core/daily-logic.d.ts +30 -5
- package/dist/core/daily-logic.js +68 -19
- package/dist/core/errors.d.ts +37 -3
- package/dist/core/errors.js +54 -5
- package/dist/core/fork-prune.d.ts +149 -0
- package/dist/core/fork-prune.js +333 -0
- package/dist/core/gist-health.d.ts +15 -3
- package/dist/core/gist-health.js +8 -0
- package/dist/core/gist-state-store.d.ts +24 -4
- package/dist/core/gist-state-store.js +98 -51
- package/dist/core/github-stats.d.ts +110 -16
- package/dist/core/github-stats.js +295 -110
- package/dist/core/http-cache.d.ts +0 -10
- package/dist/core/http-cache.js +0 -19
- package/dist/core/index.d.ts +13 -6
- package/dist/core/index.js +16 -6
- package/dist/core/issue-conversation.d.ts +8 -2
- package/dist/core/issue-conversation.js +31 -12
- package/dist/core/local-config.d.ts +95 -0
- package/dist/core/local-config.js +270 -0
- package/dist/core/merged-pr-notes.d.ts +2 -2
- package/dist/core/pacing.d.ts +41 -0
- package/dist/core/pacing.js +115 -0
- package/dist/core/pagination.d.ts +55 -0
- package/dist/core/pagination.js +59 -0
- package/dist/core/paths.d.ts +7 -0
- package/dist/core/paths.js +9 -0
- package/dist/core/pr-assembly.d.ts +2 -0
- package/dist/core/pr-assembly.js +6 -2
- package/dist/core/pr-graphql.d.ts +53 -4
- package/dist/core/pr-graphql.js +87 -14
- package/dist/core/pr-monitor.d.ts +35 -12
- package/dist/core/pr-monitor.js +110 -26
- package/dist/core/pr-preflight.d.ts +154 -0
- package/dist/core/pr-preflight.js +753 -0
- package/dist/core/pr-quality-rubric.d.ts +0 -6
- package/dist/core/pr-quality-rubric.js +0 -8
- package/dist/core/pr-template.d.ts +2 -0
- package/dist/core/pr-template.js +5 -1
- package/dist/core/prose-script.d.ts +72 -0
- package/dist/core/prose-script.js +223 -0
- package/dist/core/repo-policy.d.ts +111 -0
- package/dist/core/repo-policy.js +428 -0
- package/dist/core/repo-score-manager.d.ts +66 -0
- package/dist/core/repo-score-manager.js +140 -1
- package/dist/core/review-analysis.d.ts +49 -21
- package/dist/core/review-analysis.js +89 -15
- package/dist/core/reviewed-prs-fetch.js +11 -29
- package/dist/core/reviewed-prs.js +8 -15
- package/dist/core/stale-data.d.ts +78 -0
- package/dist/core/stale-data.js +153 -0
- package/dist/core/state-persistence.d.ts +62 -27
- package/dist/core/state-persistence.js +338 -119
- package/dist/core/state-schema.d.ts +152 -210
- package/dist/core/state-schema.js +232 -80
- package/dist/core/state.d.ts +81 -8
- package/dist/core/state.js +239 -46
- package/dist/core/status-determination.js +32 -12
- package/dist/core/strategy.js +3 -1
- package/dist/core/types.d.ts +22 -1
- package/dist/core/types.js +1 -0
- package/dist/core/untrusted-content.d.ts +30 -11
- package/dist/core/untrusted-content.js +95 -42
- package/dist/core/urls.d.ts +33 -0
- package/dist/core/urls.js +94 -0
- package/dist/dashboard/assets/chart-panel-B-nLVgzQ.js +3 -0
- package/dist/dashboard/assets/index-5IvMGokL.js +55 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/formatters/json.d.ts +432 -10
- package/dist/formatters/json.js +156 -1
- package/package.json +6 -6
- package/dist/core/ci-enforced-tools.d.ts +0 -35
- package/dist/core/ci-enforced-tools.js +0 -109
- package/dist/core/comment-decision.d.ts +0 -79
- package/dist/core/comment-decision.js +0 -82
- package/dist/core/extraction-categories.d.ts +0 -55
- package/dist/core/extraction-categories.js +0 -108
- package/dist/core/follow-up-history.d.ts +0 -40
- package/dist/core/follow-up-history.js +0 -71
- package/dist/core/issue-effort.d.ts +0 -29
- package/dist/core/issue-effort.js +0 -47
- package/dist/core/maintainer-hints.d.ts +0 -23
- package/dist/core/maintainer-hints.js +0 -36
- package/dist/core/workflow-state.d.ts +0 -56
- package/dist/core/workflow-state.js +0 -101
- package/dist/dashboard/assets/chart-panel-DPKNBUts.js +0 -3
- package/dist/dashboard/assets/index-B25bZOYX.js +0 -55
|
@@ -24,11 +24,13 @@ import * as path from 'node:path';
|
|
|
24
24
|
import { errorMessage, getStateManager, maybeCheckpoint, parseGitHubUrl, requireGitHubToken } from '../core/index.js';
|
|
25
25
|
import { UNATTENDED_ENV, ValidationError } from '../core/errors.js';
|
|
26
26
|
import { warn } from '../core/logger.js';
|
|
27
|
-
import { getReportsDir } from '../core/paths.js';
|
|
27
|
+
import { getReportsDir, resolveDataDir } from '../core/paths.js';
|
|
28
|
+
import { pruneRejectedCopies } from '../core/stale-data.js';
|
|
28
29
|
import { detectIssueListPath } from './locate-issue-list.js';
|
|
29
30
|
import { parseIssueList } from './parse-list.js';
|
|
30
31
|
import { executeDailyCheck } from './daily.js';
|
|
31
32
|
import { exportHandoff, handoffDir, pruneHandoffBundles, writeHandoffBundle } from './overnight-handoff.js';
|
|
33
|
+
import { OVERNIGHT_ALLOWED_TOOLS, OVERNIGHT_DISALLOWED_TOOLS, OVERNIGHT_GIT_ENV } from './overnight-tool-rules.js';
|
|
32
34
|
const MODULE = 'overnight';
|
|
33
35
|
// ponytail: static table, not a classifier. Every ActionableIssueType is
|
|
34
36
|
// listed: the Record key type makes a new variant fail typecheck here.
|
|
@@ -94,11 +96,21 @@ export function pickImplementCandidate(items, openPRs, attempts, listPath, langu
|
|
|
94
96
|
}
|
|
95
97
|
return null;
|
|
96
98
|
}
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
+
/**
|
|
100
|
+
* The curated list's available items, or null when there is no readable list.
|
|
101
|
+
* With no list configured, says so in `warnings` (#1933): a probed file is
|
|
102
|
+
* never used here, so a machine that relied on one needs the path set.
|
|
103
|
+
*/
|
|
104
|
+
function loadListItems(warnings) {
|
|
99
105
|
const located = detectIssueListPath();
|
|
100
|
-
if (!located)
|
|
106
|
+
if (!located) {
|
|
107
|
+
warnings.push({
|
|
108
|
+
phase: 'issue-list',
|
|
109
|
+
operation: 'find curated issue list',
|
|
110
|
+
message: 'no curated issue list configured on this machine; run setup --set issueListPath=<abs path>',
|
|
111
|
+
});
|
|
101
112
|
return null;
|
|
113
|
+
}
|
|
102
114
|
try {
|
|
103
115
|
return { items: parseIssueList(fs.readFileSync(located.path, 'utf8')).available, path: located.path };
|
|
104
116
|
}
|
|
@@ -221,12 +233,15 @@ function reportPathFor(d) {
|
|
|
221
233
|
export async function runOvernight() {
|
|
222
234
|
const sm = getStateManager();
|
|
223
235
|
const daily = await executeDailyCheck(requireGitHubToken());
|
|
236
|
+
// The nightly sweep for rejected state copies past retention (#1956); never throws.
|
|
237
|
+
pruneRejectedCopies(resolveDataDir());
|
|
224
238
|
const now = new Date();
|
|
225
239
|
const runAt = now.toISOString();
|
|
226
240
|
const languageOf = (repo) => sm.getRepoScore(repo)?.language;
|
|
227
241
|
const { prepare, judgment } = bucketize(daily, languageOf);
|
|
228
242
|
const previous = sm.getLastOvernight();
|
|
229
|
-
const
|
|
243
|
+
const warnings = [...daily.warnings];
|
|
244
|
+
const list = loadListItems(warnings);
|
|
230
245
|
// Attempts survive across runs; the ones whose issue left the list are
|
|
231
246
|
// dropped so a re-added issue can be tried again.
|
|
232
247
|
const attempts = (previous?.implementAttempts ?? []).filter((a) => !list || list.items.some((i) => i.url === a.url));
|
|
@@ -238,9 +253,9 @@ export async function runOvernight() {
|
|
|
238
253
|
prepare,
|
|
239
254
|
judgment,
|
|
240
255
|
implement,
|
|
256
|
+
warnings,
|
|
241
257
|
attention: daily.attention,
|
|
242
258
|
failures: daily.failures,
|
|
243
|
-
warnings: daily.warnings,
|
|
244
259
|
};
|
|
245
260
|
const reportPath = reportPathFor(now);
|
|
246
261
|
// A re-run on the same date (launchd retry, manual) must not drop branches
|
|
@@ -345,6 +360,11 @@ export async function runOvernightRecord(options) {
|
|
|
345
360
|
const last = sm.getLastOvernight();
|
|
346
361
|
if (!last)
|
|
347
362
|
throw new Error('No overnight run recorded yet; run `overnight` first.');
|
|
363
|
+
// The URL lands in the morning report and in commands built from it (#1933).
|
|
364
|
+
const parsed = parseGitHubUrl(options.url);
|
|
365
|
+
if (!parsed || options.url !== `https://github.com/${parsed.owner}/${parsed.repo}/${parsed.type}/${parsed.number}`) {
|
|
366
|
+
throw new ValidationError(`Refusing to record an unusual URL: ${options.url}`);
|
|
367
|
+
}
|
|
348
368
|
const report = options.fromReport ? readPreparerReport(options.fromReport) : {};
|
|
349
369
|
const branch = options.branch ?? report.branch;
|
|
350
370
|
if (!branch)
|
|
@@ -465,138 +485,41 @@ export function overnightFreshness(now = new Date()) {
|
|
|
465
485
|
: { ...base, ageHours: Math.max(0, Math.round(ageMs / 36e5)) };
|
|
466
486
|
}
|
|
467
487
|
export const LAUNCHD_LABEL = 'com.oss-autopilot.overnight';
|
|
488
|
+
export { OVERNIGHT_ALLOWED_TOOLS, OVERNIGHT_DISALLOWED_TOOLS, OVERNIGHT_GIT_ENV, PUSH_DISABLED_URL, } from './overnight-tool-rules.js';
|
|
489
|
+
function xmlEscape(s) {
|
|
490
|
+
return s.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
491
|
+
}
|
|
468
492
|
/**
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
* because it can POST), and no `bash`/`sh`/`npx` shell escapes. `node`, `pnpm`
|
|
475
|
-
* and `npm` stay because the CLI bundle and a repo's test suite are already
|
|
476
|
-
* arbitrary code; the credential-bearing writes are what the list keeps out.
|
|
477
|
-
* Stronger isolation (a dedicated user with no push credentials, or a
|
|
478
|
-
* container) is the upgrade path if that trust level is not acceptable.
|
|
493
|
+
* The flags that make the rule lists the only permissions in force. An empty
|
|
494
|
+
* `--setting-sources` is what drops the user's own settings, and Claude Code
|
|
495
|
+
* does not document the empty value: the run depends on behaviour that could
|
|
496
|
+
* change. `--restricted` (managed settings and `--settings` only, file tools
|
|
497
|
+
* confined to working directories) is the documented flag to evaluate instead.
|
|
479
498
|
*/
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
'diff',
|
|
491
|
-
'log',
|
|
492
|
-
'show',
|
|
493
|
-
'add',
|
|
494
|
-
'commit',
|
|
495
|
-
'rev-parse',
|
|
496
|
-
'remote',
|
|
497
|
-
];
|
|
498
|
-
const GH_READ_SUBCOMMANDS = [
|
|
499
|
-
'pr view',
|
|
500
|
-
'pr checks',
|
|
501
|
-
'pr diff',
|
|
502
|
-
'pr list',
|
|
503
|
-
'run view',
|
|
504
|
-
'run list',
|
|
505
|
-
'issue view',
|
|
506
|
-
'repo view',
|
|
507
|
-
'auth status',
|
|
508
|
-
];
|
|
499
|
+
const PERMISSION_FLAGS = ['--permission-mode', 'dontAsk', '--setting-sources', ''];
|
|
500
|
+
function plistArg(value) {
|
|
501
|
+
return ` <string>${xmlEscape(value)}</string>`;
|
|
502
|
+
}
|
|
503
|
+
function plistEnvLine(key, value) {
|
|
504
|
+
return ` <key>${key}</key><string>${xmlEscape(value)}</string>`;
|
|
505
|
+
}
|
|
506
|
+
function gitEnvLines() {
|
|
507
|
+
return Object.entries(OVERNIGHT_GIT_ENV).map(([key, value]) => plistEnvLine(key, value));
|
|
508
|
+
}
|
|
509
509
|
/**
|
|
510
|
-
*
|
|
511
|
-
*
|
|
512
|
-
*
|
|
510
|
+
* Pure: whether an installed plist carries the rules and environment this
|
|
511
|
+
* version renders. The lists are baked in when the plist is written, so a
|
|
512
|
+
* schedule installed before an upgrade keeps the old ones (`doctor` warns).
|
|
513
513
|
*/
|
|
514
|
-
export
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
'Bash(gh pr merge *)',
|
|
524
|
-
'Bash(gh pr close *)',
|
|
525
|
-
'Bash(gh pr edit *)',
|
|
526
|
-
'Bash(gh pr ready *)',
|
|
527
|
-
'Bash(gh issue create *)',
|
|
528
|
-
'Bash(gh issue comment *)',
|
|
529
|
-
'Bash(gh issue close *)',
|
|
530
|
-
'Bash(gh run rerun *)',
|
|
531
|
-
'Bash(gh api *)',
|
|
532
|
-
// `npm`/`pnpm` are allowed for builds and tests, but a token in ~/.npmrc
|
|
533
|
-
// would let their registry writes ship a release unattended — exactly the
|
|
534
|
-
// credential-bearing writes the gate exists to keep out.
|
|
535
|
-
'Bash(npm publish)',
|
|
536
|
-
'Bash(npm publish *)',
|
|
537
|
-
'Bash(npm unpublish *)',
|
|
538
|
-
'Bash(npm deprecate *)',
|
|
539
|
-
'Bash(pnpm publish)',
|
|
540
|
-
'Bash(pnpm publish *)',
|
|
541
|
-
// Direct shell escapes inside the allowed programs (#1728): `npm exec` IS
|
|
542
|
-
// npx, `pnpm dlx`/`pnpm exec` run arbitrary packages, and `node -e` runs
|
|
543
|
-
// arbitrary JS — each can spawn `git push` and void the push denies above.
|
|
544
|
-
// The residual (a repo's own test scripts run arbitrary code) is documented
|
|
545
|
-
// in commands/oss-overnight.md and cannot be closed by tool rules.
|
|
546
|
-
'Bash(npm exec)',
|
|
547
|
-
'Bash(npm exec *)',
|
|
548
|
-
'Bash(npm x)',
|
|
549
|
-
'Bash(npm x *)',
|
|
550
|
-
'Bash(npm * exec *)',
|
|
551
|
-
'Bash(pnpm dlx *)',
|
|
552
|
-
'Bash(pnpm * dlx *)',
|
|
553
|
-
'Bash(pnpm exec)',
|
|
554
|
-
'Bash(pnpm exec *)',
|
|
555
|
-
'Bash(pnpm * exec *)',
|
|
556
|
-
'Bash(node -e *)',
|
|
557
|
-
'Bash(node --eval *)',
|
|
558
|
-
'Bash(node -p *)',
|
|
559
|
-
'Bash(node -pe *)',
|
|
560
|
-
'Bash(node --print *)',
|
|
561
|
-
// The same escapes after a leading flag (`node --no-warnings -e`,
|
|
562
|
-
// `pnpm --dir x exec`), mirroring the `git * push` deny.
|
|
563
|
-
'Bash(node * -e *)',
|
|
564
|
-
'Bash(node * --eval *)',
|
|
565
|
-
'Bash(node * -p *)',
|
|
566
|
-
'Bash(node * -pe *)',
|
|
567
|
-
'Bash(node * --print *)',
|
|
568
|
-
'Bash(npm * x *)',
|
|
569
|
-
// The `=` forms take no space, so the space-delimited denies above miss
|
|
570
|
-
// them: `node --eval=<js>` runs exactly like `node --eval <js>`.
|
|
571
|
-
'Bash(node --eval=*)',
|
|
572
|
-
'Bash(node * --eval=*)',
|
|
573
|
-
'Bash(node --print=*)',
|
|
574
|
-
'Bash(node * --print=*)',
|
|
575
|
-
'AskUserQuestion',
|
|
576
|
-
].join(',');
|
|
577
|
-
export const OVERNIGHT_ALLOWED_TOOLS = [
|
|
578
|
-
'Read',
|
|
579
|
-
'Edit',
|
|
580
|
-
'Write',
|
|
581
|
-
'Glob',
|
|
582
|
-
'Grep',
|
|
583
|
-
'Task',
|
|
584
|
-
// Both the bare and the `-C <dir>` forms: a preparer's worktree is never its
|
|
585
|
-
// cwd, and `cd <dir> && git ...` is denied under dontAsk, so without `-C`
|
|
586
|
-
// every preparer blocks (#1697).
|
|
587
|
-
...GIT_SUBCOMMANDS.flatMap((sub) => [
|
|
588
|
-
`Bash(git ${sub})`,
|
|
589
|
-
`Bash(git ${sub} *)`,
|
|
590
|
-
`Bash(git -C * ${sub})`,
|
|
591
|
-
`Bash(git -C * ${sub} *)`,
|
|
592
|
-
]),
|
|
593
|
-
...GH_READ_SUBCOMMANDS.map((sub) => `Bash(gh ${sub} *)`),
|
|
594
|
-
'Bash(node *)',
|
|
595
|
-
'Bash(pnpm *)',
|
|
596
|
-
'Bash(npm *)',
|
|
597
|
-
].join(',');
|
|
598
|
-
function xmlEscape(s) {
|
|
599
|
-
return s.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>');
|
|
514
|
+
export function isScheduleCurrent(plist) {
|
|
515
|
+
const required = [
|
|
516
|
+
PERMISSION_FLAGS.map((flag) => plistArg(flag)).join('\n'),
|
|
517
|
+
plistArg(OVERNIGHT_ALLOWED_TOOLS),
|
|
518
|
+
plistArg(OVERNIGHT_DISALLOWED_TOOLS),
|
|
519
|
+
plistEnvLine(UNATTENDED_ENV, '1'),
|
|
520
|
+
...gitEnvLines(),
|
|
521
|
+
];
|
|
522
|
+
return required.every((part) => plist.includes(part));
|
|
600
523
|
}
|
|
601
524
|
/**
|
|
602
525
|
* The settings layer the scheduled job runs with instead of the user's own
|
|
@@ -620,10 +543,7 @@ export function renderLaunchdPlist(options, logPath, settingsPath) {
|
|
|
620
543
|
options.claudePath,
|
|
621
544
|
'-p',
|
|
622
545
|
'/oss-overnight',
|
|
623
|
-
|
|
624
|
-
'dontAsk',
|
|
625
|
-
'--setting-sources',
|
|
626
|
-
'',
|
|
546
|
+
...PERMISSION_FLAGS,
|
|
627
547
|
'--settings',
|
|
628
548
|
settingsPath,
|
|
629
549
|
'--allowedTools',
|
|
@@ -641,7 +561,7 @@ export function renderLaunchdPlist(options, logPath, settingsPath) {
|
|
|
641
561
|
` <key>Label</key><string>${LAUNCHD_LABEL}</string>`,
|
|
642
562
|
' <key>ProgramArguments</key>',
|
|
643
563
|
' <array>',
|
|
644
|
-
...args.map((a) =>
|
|
564
|
+
...args.map((a) => plistArg(a)),
|
|
645
565
|
' </array>',
|
|
646
566
|
' <key>StartCalendarInterval</key>',
|
|
647
567
|
` <dict><key>Hour</key><integer>${options.hour}</integer><key>Minute</key><integer>0</integer></dict>`,
|
|
@@ -654,7 +574,8 @@ export function renderLaunchdPlist(options, logPath, settingsPath) {
|
|
|
654
574
|
` <key>PATH</key><string>${xmlEscape(`${path.dirname(process.execPath)}:/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin`)}</string>`,
|
|
655
575
|
// The CLI's own GitHub-writing commands refuse while this is set (see
|
|
656
576
|
// assertAttended): `Bash(node *)` has to stay allowed, so the gate is in code.
|
|
657
|
-
|
|
577
|
+
plistEnvLine(UNATTENDED_ENV, '1'),
|
|
578
|
+
...gitEnvLines(),
|
|
658
579
|
' </dict>',
|
|
659
580
|
'</dict>',
|
|
660
581
|
'</plist>',
|
|
@@ -5,16 +5,21 @@
|
|
|
5
5
|
import * as fs from 'node:fs';
|
|
6
6
|
import * as path from 'node:path';
|
|
7
7
|
import { errorMessage } from '../core/errors.js';
|
|
8
|
+
import { parseGitHubUrl } from '../core/urls.js';
|
|
8
9
|
/**
|
|
9
10
|
* Extract a GitHub issue URL from a markdown line.
|
|
10
11
|
*
|
|
11
12
|
* Guard 1: PR URLs (/pull/) are intentionally excluded. A pull-request URL is
|
|
12
13
|
* never a valid issue candidate — collecting them inflates `availableCount` and
|
|
13
14
|
* causes `vet-list` to spend API calls on URLs that cannot resolve as issues.
|
|
15
|
+
*
|
|
16
|
+
* Guard 2: the owner/repo must pass `parseGitHubUrl` (#1933). List URLs reach
|
|
17
|
+
* the overnight dispatch line and quoted shell arguments, so a line whose URL
|
|
18
|
+
* carries quotes, spaces or other characters GitHub never uses is dropped.
|
|
14
19
|
*/
|
|
15
20
|
function extractGitHubUrl(line) {
|
|
16
21
|
const match = line.match(/https:\/\/github\.com\/([^/]+\/[^/]+)\/issues\/(\d+)/);
|
|
17
|
-
if (match) {
|
|
22
|
+
if (match && parseGitHubUrl(match[0])) {
|
|
18
23
|
return { repo: match[1], number: parseInt(match[2], 10), url: match[0] };
|
|
19
24
|
}
|
|
20
25
|
return null;
|
|
@@ -399,6 +404,7 @@ export function pruneIssueList(content, minScore = 6) {
|
|
|
399
404
|
}
|
|
400
405
|
return { pruned: collapsed.join('\n') + '\n', removedCount };
|
|
401
406
|
}
|
|
407
|
+
// eslint-disable-next-line @typescript-eslint/require-await -- async keeps the Promise-returning contract callers rely on; the body has no await yet
|
|
402
408
|
export async function runParseList(options) {
|
|
403
409
|
const filePath = path.resolve(options.filePath);
|
|
404
410
|
if (!fs.existsSync(filePath)) {
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `policy get|set|reset --repo owner/repo` (#1953): the per-repo contribution
|
|
3
|
+
* policy record, and the vet-time write that fills it in.
|
|
4
|
+
*
|
|
5
|
+
* `get` only reads. `set` and `reset` refuse unattended runs: a record the
|
|
6
|
+
* user sets is trusted over vet's reading of the repo docs, so nobody but the
|
|
7
|
+
* user writes one. There is no MCP setter on purpose.
|
|
8
|
+
*/
|
|
9
|
+
import { type RepoPolicy, type RepoPolicySummary } from '../core/repo-policy.js';
|
|
10
|
+
export interface PolicyGetOutput {
|
|
11
|
+
repo: string;
|
|
12
|
+
/** The policy that applies: the stored record with `config.aiPolicyBlocklist` read as a ban. Null when nothing is known. */
|
|
13
|
+
policy: (RepoPolicySummary & {
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
/** True when the repo is in `config.aiPolicyBlocklist`; `policy set` cannot lift that ban. */
|
|
16
|
+
blocklisted: boolean;
|
|
17
|
+
/** The disclosure line the user recorded, inside a `<github-content>` fence; the repo's rule is in `sources`. */
|
|
18
|
+
disclosureText?: string;
|
|
19
|
+
/** The issue label the user recorded as the maintainer-label gate, inside a `<github-content>` fence. */
|
|
20
|
+
gateLabel?: string;
|
|
21
|
+
/** `file: quoted line` per rule, inside a `<github-content>` fence. */
|
|
22
|
+
sources?: string;
|
|
23
|
+
}) | null;
|
|
24
|
+
}
|
|
25
|
+
export interface PolicySetOptions {
|
|
26
|
+
repo: string;
|
|
27
|
+
aiPolicy?: string;
|
|
28
|
+
disclosureText?: string;
|
|
29
|
+
/** The issue label a maintainer-label gate waits for; an empty string clears it. */
|
|
30
|
+
gateLabel?: string;
|
|
31
|
+
cla?: string;
|
|
32
|
+
prGate?: string;
|
|
33
|
+
/** Replaces the list; an empty string clears it. */
|
|
34
|
+
commitRules?: string;
|
|
35
|
+
/** 0 clears it. */
|
|
36
|
+
maxOpenAiPRs?: number;
|
|
37
|
+
/** Where the rule came from, e.g. a maintainer's comment; stored as a short quoted line. */
|
|
38
|
+
source?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface PolicyWriteOutput extends PolicyGetOutput {
|
|
41
|
+
/**
|
|
42
|
+
* How `--ai-policy` changed `config.aiPolicyBlocklist`: `added` for banned
|
|
43
|
+
* (clients that predate policy records read only the blocklist), `removed`
|
|
44
|
+
* for any other value (the blocklist always bans, so it would override the
|
|
45
|
+
* record). Absent when the list did not change.
|
|
46
|
+
*/
|
|
47
|
+
blocklistChange?: 'added' | 'removed';
|
|
48
|
+
/** Set when the post-mutation Gist checkpoint failed; the local mutation succeeded (#1370). */
|
|
49
|
+
gistSyncWarning?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface PolicyResetOutput {
|
|
52
|
+
repo: string;
|
|
53
|
+
deleted: boolean;
|
|
54
|
+
gistSyncWarning?: string;
|
|
55
|
+
}
|
|
56
|
+
/** Read the policy that applies to `repo`. Untrusted text comes back fenced. */
|
|
57
|
+
export declare function runPolicyGet(options: {
|
|
58
|
+
repo: string;
|
|
59
|
+
}): Promise<PolicyGetOutput>;
|
|
60
|
+
/**
|
|
61
|
+
* Record the user's policy for `repo`, merged over what is stored. Refused
|
|
62
|
+
* unattended, and the result is `reviewedByUser: true`, so vet never
|
|
63
|
+
* overwrites it. It cannot lift a `config.aiPolicyBlocklist` ban.
|
|
64
|
+
*/
|
|
65
|
+
export declare function runPolicySet(options: PolicySetOptions): Promise<PolicyWriteOutput>;
|
|
66
|
+
/**
|
|
67
|
+
* Delete the stored record for `repo`. Refused unattended: deleting a ban the
|
|
68
|
+
* user recorded relaxes it. `config.aiPolicyBlocklist` is left as is.
|
|
69
|
+
*/
|
|
70
|
+
export declare function runPolicyReset(options: {
|
|
71
|
+
repo: string;
|
|
72
|
+
}): Promise<PolicyResetOutput>;
|
|
73
|
+
/**
|
|
74
|
+
* Store what vet read from the repo docs, unreviewed. Never replaces a record
|
|
75
|
+
* the user set, and skips the write when nothing changed. A failure is logged,
|
|
76
|
+
* never thrown: recording the policy must not fail the vet.
|
|
77
|
+
*/
|
|
78
|
+
export declare function recordVetPolicy(repo: string, derived: RepoPolicy): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* {@link recordVetPolicy} for several repos, with one Gist checkpoint. With
|
|
81
|
+
* `fillOnly` (vet-list, which reads only scout's CONTRIBUTING text) a stored
|
|
82
|
+
* record is replaced only by a ban: a narrower reading must not overwrite one
|
|
83
|
+
* vet took from more docs.
|
|
84
|
+
*/
|
|
85
|
+
export declare function recordVetPolicies(readings: ReadonlyArray<{
|
|
86
|
+
repo: string;
|
|
87
|
+
policy: RepoPolicy;
|
|
88
|
+
}>, options?: {
|
|
89
|
+
fillOnly?: boolean;
|
|
90
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `policy get|set|reset --repo owner/repo` (#1953): the per-repo contribution
|
|
3
|
+
* policy record, and the vet-time write that fills it in.
|
|
4
|
+
*
|
|
5
|
+
* `get` only reads. `set` and `reset` refuse unattended runs: a record the
|
|
6
|
+
* user sets is trusted over vet's reading of the repo docs, so nobody but the
|
|
7
|
+
* user writes one. There is no MCP setter on purpose.
|
|
8
|
+
*/
|
|
9
|
+
import { getStateManager, maybeCheckpoint, warn, errorMessage } from '../core/index.js';
|
|
10
|
+
import { ValidationError, assertAttended } from '../core/errors.js';
|
|
11
|
+
import { AI_POLICIES, CLA_POLICIES, COMMIT_RULES, PR_GATES, effectivePolicy, fencePolicyText, isBlocklisted, isUnreadable, isUserReviewed, quote, isSamePolicy, storedPolicy, unknownFields, summarizePolicy, } from '../core/repo-policy.js';
|
|
12
|
+
import { GATE_LABEL_MAX } from '../core/state-schema.js';
|
|
13
|
+
import { validateRepoIdentifier } from './validation.js';
|
|
14
|
+
const MODULE = 'policy';
|
|
15
|
+
function oneOf(value, allowed, flag) {
|
|
16
|
+
if (value === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
if (!allowed.includes(value)) {
|
|
19
|
+
throw new ValidationError(`Invalid ${flag} "${value}". Expected one of: ${allowed.join(', ')}.`);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function parseCommitRules(value) {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return undefined;
|
|
26
|
+
const rules = value
|
|
27
|
+
.split(',')
|
|
28
|
+
.map((r) => r.trim())
|
|
29
|
+
.filter((r) => r !== '');
|
|
30
|
+
for (const rule of rules)
|
|
31
|
+
oneOf(rule, COMMIT_RULES, '--commit-rules entry');
|
|
32
|
+
return [...new Set(rules)];
|
|
33
|
+
}
|
|
34
|
+
function getOutput(repo) {
|
|
35
|
+
const state = getStateManager().getState();
|
|
36
|
+
const policy = effectivePolicy(state, repo);
|
|
37
|
+
if (!policy)
|
|
38
|
+
return { repo, policy: null };
|
|
39
|
+
return {
|
|
40
|
+
repo,
|
|
41
|
+
policy: {
|
|
42
|
+
...summarizePolicy(policy),
|
|
43
|
+
updatedAt: policy.updatedAt,
|
|
44
|
+
blocklisted: isBlocklisted(state, repo),
|
|
45
|
+
...fencePolicyText(repo, policy),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Read the policy that applies to `repo`. Untrusted text comes back fenced. */
|
|
50
|
+
export function runPolicyGet(options) {
|
|
51
|
+
validateRepoIdentifier(options.repo);
|
|
52
|
+
return Promise.resolve(getOutput(options.repo));
|
|
53
|
+
}
|
|
54
|
+
function parseMax(value) {
|
|
55
|
+
if (value === undefined)
|
|
56
|
+
return undefined;
|
|
57
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
58
|
+
throw new ValidationError(`Invalid --max-open-ai-prs "${value}". Expected a whole number (0 clears it).`);
|
|
59
|
+
}
|
|
60
|
+
return value;
|
|
61
|
+
}
|
|
62
|
+
/** The label name, trimmed; '' clears it. Refuses a name GitHub could not have. */
|
|
63
|
+
function parseGateLabel(value) {
|
|
64
|
+
if (value === undefined)
|
|
65
|
+
return undefined;
|
|
66
|
+
const name = value.trim();
|
|
67
|
+
if (name.length > GATE_LABEL_MAX || /\p{Cc}/u.test(name)) {
|
|
68
|
+
throw new ValidationError(`Invalid --gate-label "${quote(value)}". Expected an issue label name of at most ${GATE_LABEL_MAX} characters ("" clears it).`);
|
|
69
|
+
}
|
|
70
|
+
return name;
|
|
71
|
+
}
|
|
72
|
+
/** The fields `options` sets; an absent flag leaves the stored value. */
|
|
73
|
+
function changes(options) {
|
|
74
|
+
const fields = {
|
|
75
|
+
aiPolicy: oneOf(options.aiPolicy, AI_POLICIES, '--ai-policy'),
|
|
76
|
+
cla: oneOf(options.cla, CLA_POLICIES, '--cla'),
|
|
77
|
+
prGate: oneOf(options.prGate, PR_GATES, '--pr-gate'),
|
|
78
|
+
commitRules: parseCommitRules(options.commitRules),
|
|
79
|
+
maxOpenAiPRs: parseMax(options.maxOpenAiPRs),
|
|
80
|
+
disclosureText: options.disclosureText === undefined ? undefined : quote(options.disclosureText),
|
|
81
|
+
gateLabel: parseGateLabel(options.gateLabel),
|
|
82
|
+
};
|
|
83
|
+
const entries = Object.entries(fields);
|
|
84
|
+
return Object.fromEntries(entries.filter(([, v]) => v !== undefined));
|
|
85
|
+
}
|
|
86
|
+
function applySet(current, options, now) {
|
|
87
|
+
const merged = { ...current, ...changes(options) };
|
|
88
|
+
const source = options.source === undefined ? [] : [{ file: 'user', quotedLine: quote(options.source) }];
|
|
89
|
+
const { maxOpenAiPRs, disclosureText, gateLabel, ...rest } = merged;
|
|
90
|
+
return {
|
|
91
|
+
...rest,
|
|
92
|
+
// 0 and '' clear these.
|
|
93
|
+
...(maxOpenAiPRs !== undefined && maxOpenAiPRs > 0 && { maxOpenAiPRs }),
|
|
94
|
+
...(disclosureText && { disclosureText }),
|
|
95
|
+
...(gateLabel && { gateLabel }),
|
|
96
|
+
source: [...source, ...current.source].slice(0, 10),
|
|
97
|
+
reviewedByUser: true,
|
|
98
|
+
updatedAt: now,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The stored record `set` merges over, or null. Refuses two cases where a merge
|
|
103
|
+
* would record something the user never looked at: an entry this release
|
|
104
|
+
* cannot parse (a newer release wrote it; merging would replace it with
|
|
105
|
+
* defaults), and an unreviewed vet reading edited without `--ai-policy` (one
|
|
106
|
+
* field edited would mark the heuristic's AI reading as reviewed).
|
|
107
|
+
*/
|
|
108
|
+
function storedRecordToEdit(state, options) {
|
|
109
|
+
if (isUnreadable(state, options.repo)) {
|
|
110
|
+
throw new ValidationError(`The stored policy for ${options.repo} was written by a newer oss-autopilot release and cannot be edited here. ` +
|
|
111
|
+
`Update, or delete it with policy reset --repo ${options.repo} and set it again.`);
|
|
112
|
+
}
|
|
113
|
+
const stored = storedPolicy(state, options.repo);
|
|
114
|
+
if (stored && !stored.reviewedByUser && options.aiPolicy === undefined) {
|
|
115
|
+
throw new ValidationError(`The stored policy for ${options.repo} was read from the repo docs (aiPolicy: ${stored.aiPolicy}) and nobody has ` +
|
|
116
|
+
'reviewed it. Pass --ai-policy with the value you confirmed, so setting another field does not approve that reading.');
|
|
117
|
+
}
|
|
118
|
+
return stored;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* An unreviewed stored record without the derived commit rules, AI-PR limit
|
|
122
|
+
* and PR gate (reset to unknown) the user did not pass: confirming `--ai-policy` must not mark those as
|
|
123
|
+
* reviewed. A record the user set is returned as is.
|
|
124
|
+
*/
|
|
125
|
+
function withoutUnseenFields(stored, options) {
|
|
126
|
+
if (stored.reviewedByUser)
|
|
127
|
+
return stored;
|
|
128
|
+
const { maxOpenAiPRs, commitRules, ...rest } = stored;
|
|
129
|
+
return {
|
|
130
|
+
...rest,
|
|
131
|
+
commitRules: options.commitRules === undefined ? [] : commitRules,
|
|
132
|
+
prGate: options.prGate === undefined ? 'unknown' : rest.prGate,
|
|
133
|
+
...(options.maxOpenAiPRs !== undefined && maxOpenAiPRs !== undefined && { maxOpenAiPRs }),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Record the user's policy for `repo`, merged over what is stored. Refused
|
|
138
|
+
* unattended, and the result is `reviewedByUser: true`, so vet never
|
|
139
|
+
* overwrites it. It cannot lift a `config.aiPolicyBlocklist` ban.
|
|
140
|
+
*/
|
|
141
|
+
export async function runPolicySet(options) {
|
|
142
|
+
validateRepoIdentifier(options.repo);
|
|
143
|
+
assertAttended('set a repo contribution policy');
|
|
144
|
+
const sm = getStateManager();
|
|
145
|
+
const stored = storedRecordToEdit(sm.getState(), options);
|
|
146
|
+
const date = new Date();
|
|
147
|
+
const now = date.toISOString();
|
|
148
|
+
const current = (stored && withoutUnseenFields(stored, options)) ?? {
|
|
149
|
+
aiPolicy: 'unknown',
|
|
150
|
+
cla: 'unknown',
|
|
151
|
+
commitRules: [],
|
|
152
|
+
prGate: 'unknown',
|
|
153
|
+
source: [],
|
|
154
|
+
reviewedByUser: true,
|
|
155
|
+
updatedAt: now,
|
|
156
|
+
};
|
|
157
|
+
// Keep fields a newer release added; the known ones come from the merge.
|
|
158
|
+
const next = { ...unknownFields(sm.getState(), options.repo), ...applySet(current, options, now) };
|
|
159
|
+
const blocklist = blocklistUpdate(sm.getState().config.aiPolicyBlocklist ?? [], options);
|
|
160
|
+
const persist = () => {
|
|
161
|
+
sm.setRepoPolicy(options.repo, next);
|
|
162
|
+
if (blocklist)
|
|
163
|
+
sm.updateConfig({ aiPolicyBlocklist: blocklist.list });
|
|
164
|
+
};
|
|
165
|
+
persist();
|
|
166
|
+
const gistSyncWarning = await maybeCheckpoint(sm, MODULE, persist);
|
|
167
|
+
return {
|
|
168
|
+
...getOutput(options.repo),
|
|
169
|
+
...(blocklist && { blocklistChange: blocklist.change }),
|
|
170
|
+
...(gistSyncWarning && { gistSyncWarning }),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The blocklist after `--ai-policy`, or null when it does not change. Appends
|
|
175
|
+
* to the stored list (never replaces it); removal is case-insensitive. Without
|
|
176
|
+
* `--ai-policy` the list is left alone, and so does `policy reset`.
|
|
177
|
+
*/
|
|
178
|
+
function blocklistUpdate(current, options) {
|
|
179
|
+
if (options.aiPolicy === undefined)
|
|
180
|
+
return null;
|
|
181
|
+
const lower = options.repo.toLowerCase();
|
|
182
|
+
const isListed = current.some((r) => r.toLowerCase() === lower);
|
|
183
|
+
if (options.aiPolicy === 'banned')
|
|
184
|
+
return isListed ? null : { list: [...current, options.repo], change: 'added' };
|
|
185
|
+
if (!isListed)
|
|
186
|
+
return null;
|
|
187
|
+
return { list: current.filter((r) => r.toLowerCase() !== lower), change: 'removed' };
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Delete the stored record for `repo`. Refused unattended: deleting a ban the
|
|
191
|
+
* user recorded relaxes it. `config.aiPolicyBlocklist` is left as is.
|
|
192
|
+
*/
|
|
193
|
+
export async function runPolicyReset(options) {
|
|
194
|
+
validateRepoIdentifier(options.repo);
|
|
195
|
+
assertAttended('reset a repo contribution policy');
|
|
196
|
+
const sm = getStateManager();
|
|
197
|
+
const hasRecord = sm.getState().repoPolicies?.[options.repo.toLowerCase()] !== undefined;
|
|
198
|
+
if (!hasRecord)
|
|
199
|
+
return { repo: options.repo, deleted: false };
|
|
200
|
+
sm.setRepoPolicy(options.repo, null);
|
|
201
|
+
const gistSyncWarning = await maybeCheckpoint(sm, MODULE, () => sm.setRepoPolicy(options.repo, null));
|
|
202
|
+
return { repo: options.repo, deleted: true, ...(gistSyncWarning && { gistSyncWarning }) };
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Store what vet read from the repo docs, unreviewed. Never replaces a record
|
|
206
|
+
* the user set, and skips the write when nothing changed. A failure is logged,
|
|
207
|
+
* never thrown: recording the policy must not fail the vet.
|
|
208
|
+
*/
|
|
209
|
+
export async function recordVetPolicy(repo, derived) {
|
|
210
|
+
await recordVetPolicies([{ repo, policy: derived }]);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* {@link recordVetPolicy} for several repos, with one Gist checkpoint. With
|
|
214
|
+
* `fillOnly` (vet-list, which reads only scout's CONTRIBUTING text) a stored
|
|
215
|
+
* record is replaced only by a ban: a narrower reading must not overwrite one
|
|
216
|
+
* vet took from more docs.
|
|
217
|
+
*/
|
|
218
|
+
export async function recordVetPolicies(readings, options = {}) {
|
|
219
|
+
try {
|
|
220
|
+
await writeVetPolicies(readings, options.fillOnly === true);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
const repos = readings.map((r) => r.repo).join(', ');
|
|
224
|
+
warn(MODULE, `Could not record the contribution policy for ${repos}: ${errorMessage(error)}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async function writeVetPolicies(readings, isFillOnly) {
|
|
228
|
+
const sm = getStateManager();
|
|
229
|
+
sm.reloadIfChanged();
|
|
230
|
+
const perRepo = onePerRepo(readings);
|
|
231
|
+
// Re-checked on every run, so a Gist conflict replay judges against the fresh baseline.
|
|
232
|
+
let written = 0;
|
|
233
|
+
const write = () => {
|
|
234
|
+
written = 0;
|
|
235
|
+
for (const { repo, policy } of perRepo) {
|
|
236
|
+
if (!shouldWrite(repo, policy, isFillOnly))
|
|
237
|
+
continue;
|
|
238
|
+
sm.setRepoPolicy(repo, policy);
|
|
239
|
+
written++;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
write();
|
|
243
|
+
if (written > 0)
|
|
244
|
+
await maybeCheckpoint(sm, MODULE, write);
|
|
245
|
+
}
|
|
246
|
+
/** One reading per repo (case-insensitive); a ban wins over any other reading of the same repo. */
|
|
247
|
+
function onePerRepo(readings) {
|
|
248
|
+
const kept = [];
|
|
249
|
+
const indexByRepo = new Map();
|
|
250
|
+
for (const reading of readings) {
|
|
251
|
+
const index = indexByRepo.get(reading.repo.toLowerCase());
|
|
252
|
+
if (index === undefined) {
|
|
253
|
+
indexByRepo.set(reading.repo.toLowerCase(), kept.length);
|
|
254
|
+
kept.push(reading);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
if (reading.policy.aiPolicy === 'banned')
|
|
258
|
+
kept[index] = reading;
|
|
259
|
+
}
|
|
260
|
+
return kept;
|
|
261
|
+
}
|
|
262
|
+
function shouldWrite(repo, derived, isFillOnly) {
|
|
263
|
+
const state = getStateManager().getState();
|
|
264
|
+
// Never replace the user's record or one a newer release wrote.
|
|
265
|
+
if (isUserReviewed(state, repo) || isUnreadable(state, repo))
|
|
266
|
+
return false;
|
|
267
|
+
const stored = storedPolicy(state, repo);
|
|
268
|
+
if (!stored)
|
|
269
|
+
return true;
|
|
270
|
+
if (isSamePolicy(stored, derived))
|
|
271
|
+
return false;
|
|
272
|
+
// A recorded ban stays until the user says otherwise: a later reading that misses it does not lift it.
|
|
273
|
+
if (stored.aiPolicy === 'banned')
|
|
274
|
+
return derived.aiPolicy === 'banned';
|
|
275
|
+
return !isFillOnly || derived.aiPolicy === 'banned';
|
|
276
|
+
}
|