@davidvornholt/standards 0.10.2 → 0.11.1
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/README.md +9 -2
- package/package.json +38 -1
- package/src/cli.ts +98 -87
- package/src/github-api.ts +2 -0
- package/src/github-commands.ts +2 -0
- package/src/github-label-identity.ts +9 -0
- package/src/github-labels.ts +123 -0
- package/src/github-live-drift.ts +29 -0
- package/src/github-paginate.ts +49 -0
- package/src/github-settings-merge.ts +167 -0
- package/src/github-settings-parse.ts +82 -7
- package/src/github-settings.ts +5 -123
- package/src/managed-files.ts +64 -0
- package/src/poller-approval.ts +80 -0
- package/src/poller-claim.ts +154 -0
- package/src/poller-codex.ts +93 -0
- package/src/poller-commands.ts +78 -0
- package/src/poller-config.ts +188 -0
- package/src/poller-fix-outcome.ts +36 -0
- package/src/poller-fix-output.ts +135 -0
- package/src/poller-fix-publication.ts +187 -0
- package/src/poller-fix-run.ts +175 -0
- package/src/poller-fix-validation.ts +64 -0
- package/src/poller-github-publication.ts +23 -0
- package/src/poller-github-pulls.ts +189 -0
- package/src/poller-github-write.ts +87 -0
- package/src/poller-github.ts +190 -0
- package/src/poller-job-shared.ts +132 -0
- package/src/poller-outcome.ts +136 -0
- package/src/poller-output-integrity.ts +107 -0
- package/src/poller-prompts.ts +70 -0
- package/src/poller-protected-paths.ts +51 -0
- package/src/poller-protocol.ts +137 -0
- package/src/poller-review-artifacts.ts +119 -0
- package/src/poller-review-execution.ts +108 -0
- package/src/poller-review-output.ts +189 -0
- package/src/poller-review-publication.ts +153 -0
- package/src/poller-review-run.ts +160 -0
- package/src/poller-review-state.ts +126 -0
- package/src/poller-review-validation.ts +66 -0
- package/src/poller-schedule.ts +121 -0
- package/src/poller-tick.ts +144 -0
- package/src/poller-trust.ts +96 -0
- package/src/poller-units.ts +82 -0
- package/src/poller-workspace.ts +199 -0
package/README.md
CHANGED
|
@@ -12,14 +12,20 @@ standards dependabot --check
|
|
|
12
12
|
standards dependabot --write
|
|
13
13
|
standards github --check
|
|
14
14
|
standards github --apply
|
|
15
|
+
standards poller --config <path>
|
|
16
|
+
standards poller --print-units --config <path>
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
`dependabot --write` regenerates the composed `.github/dependabot.yml` from the canonical `.github/dependabot.base.yml` and the optional repo-owned `.github/dependabot.local.yml`; `init` and `sync` do the same automatically. `dependabot --check` verifies the generated file still matches its sources, and `doctor`/`check` include the same verification. The overlay is deliberately lean and additive only: new update blocks for repo-specific ecosystems, top-level private registry definitions, and `ignore` or `registries` entries appended by repeating a canonical block's normalized target. Matching blocks cannot add labels, groups, cooldowns, pull-request limits, or other policy.
|
|
18
20
|
|
|
19
|
-
`
|
|
21
|
+
`check` also rejects the raw token formed by `biome-` + `ignore` anywhere in lock-listed canonical files. The intentionally blunt policy keeps synced sources compatible with consumer Biome configurations without invoking Biome or maintaining language-aware comment parsing.
|
|
22
|
+
|
|
23
|
+
`github --check` compares the live GitHub repository (merge settings, rulesets, and declared labels) against the merged declaration in `.github/settings.json` + `.github/settings.local.json`; `github --apply` converges that declared state. Undeclared live labels remain untouched, while undeclared repository-owned rulesets are removed. `check` runs the same comparison whenever `.github/settings.json` is present, and fails closed: declared state the token cannot see fails the gate with a message naming the token fix instead of passing unverified. The canonical workflow sets `STANDARDS_SKIP_GITHUB_CHECK=true` only in its unprivileged quality step because its isolated `github-settings` job runs the live comparison with the settings-read token; this is a workflow-internal integration seam, not a general way to disable the local gate. The CLI prints an explicit diagnostic whenever that exact value skips either `check`'s live phase or `github --check`; `github --apply` is never skipped. `--apply` re-diffs the PATCH response, so a setting GitHub accepts with HTTP 200 but silently ignores (plan-unavailable features) is a reported failure, not a false success. A repository whose GitHub plan cannot enforce rulesets can declare that in the seam (see `rulesetEnforcement` below); both commands then skip rulesets and plan-gated repository settings, converge the rest, and print an unprotected-branch notice on every run.
|
|
20
24
|
|
|
21
25
|
`structure` enforces the canonical monorepo structure contract: workspace scripts (`check-types`, `lint`, `lint:fix`, `test`), root gate scripts, filtered Turbo convenience aliases, internal `0.0.0`/`workspace:*` versioning, package `exports`, shared tsconfig inheritance, and browser a11y wiring. Only a workspace containing an explicit `*.a11y.ts` suite must provide a `test:a11y` script and direct `@axe-core/playwright` and `@playwright/test` dependencies. `check` includes `structure`, so these rules gate every consumer PR.
|
|
22
26
|
|
|
27
|
+
`poller` runs one tick of the fix poller: host-level automation that turns maintainer-approved GitHub issues into verified draft PRs and maintainer-approved draft PRs into completed review-fix cycles, using headless Codex runs. All workflow state lives in GitHub labels, comments, and draft PRs (the labels are canonical declared settings — see `github --apply`), so ticks are stateless, re-runnable, and safe to schedule from any host. A tick claims work by label (`fix-in-progress` / `review-in-progress`), releases claims stale for longer than `staleClaimHours`, and fails loudly — a red tick means jobs stalled, never silence. Trust is verified per event, not per configuration: the approval labels (`approved-for-fix`, `approved-for-review`) only count when the applying user holds the `admin` or `maintain` role, bind to the exact approved issue revision or PR head, and are revalidated before publication; only admin/maintain comments are treated as answers to agent questions. The poller removes its direct GitHub token variables before launching Codex, but the approved run shares the host service identity and can read its other ambient credentials and logged-in tool state; that accepted visibility must not be treated as credential isolation. The run works in a throwaway git worktree, hands results back through a structured outcome file, and the poller verifies effects (commits exist, no protected paths touched) before pushing, opening the draft PR, or posting the review — the required CI checks on the resulting PR remain the quality gate. Host mutation is declarative-only: `--print-units` emits a correctly escaped systemd service and timer for the polling host's infrastructure repository to adapt and deploy. That repository owns the service identity, writable HOME, PATH, GitHub token environment, lingering, and deployment. The service's tick budget (`TimeoutStartSec`) is derived from `maxJobsPerTick` × `runTimeoutMinutes` plus overhead, so re-render and redeploy the units after changing either value.
|
|
28
|
+
|
|
23
29
|
`structure --profile source` validates the standards source repository itself, which is deliberately not a consumer. The profile pins its intentional exceptions so they cannot drift silently: exact, ordered root gate scripts that run this CLI from the local checkout (`structure --profile source`, `dependabot --check` or `dependabot --write`, `github --check`, and the Turbo gate) instead of a recursive `standards check`, and a non-private published bin-only CLI workspace that carries a stable release SemVer and exactly maps the `standards` bin to `src/cli.ts` without `exports`. Every other consumer rule still applies.
|
|
24
30
|
|
|
25
31
|
## Configuration
|
|
@@ -27,6 +33,7 @@ standards github --apply
|
|
|
27
33
|
- **`.github/dependabot.local.yml`** (optional) — repo-owned Dependabot extension composed with the canonical `.github/dependabot.base.yml` into the generated `.github/dependabot.yml`. May define `updates` and top-level `registries`; a block matching a canonical normalized target may only add `ignore` and/or `registries` entries. Other matching-block policy is rejected deliberately. A missing or comments-only file means no additions. CLI 0.10.1 requires the selected content ref to contain the canonical base and rejects older refs before mutation.
|
|
28
34
|
- **`sync-standards.local.json`** (optional) — consumer-owned sync policy at the repo root, validated by `doctor`/`check` and every `init`/`sync` even when an explicit ref or local source makes its `"ref"` irrelevant. All fields optional; a missing file means the defaults. `"ref"` is a non-empty single-line string that pins a tag, branch, or full commit sha to sync from instead of `main` (an explicit `--ref` overrides it; a local-path `--from` source is used as-is and ignores only the validated pin). `"autoSync": false` is read by the standards-sync workflow, not the CLI, and skips the weekly scheduled run. Version 0.7.0 removes the legacy `STANDARDS_AUTO_SYNC` and `STANDARDS_SYNC_REF` variable behavior; consumers must upgrade the package and lockfile before adopting a policy file.
|
|
29
35
|
- **`.github/settings.local.json` `"rulesetEnforcement": "unavailable-on-plan"`** (optional) — declares that the repository's GitHub plan cannot enforce rulesets (private repositories on GitHub Free, both personal accounts and organizations). `github --check` and `--apply` then skip rulesets instead of comparing them, because a comparison cannot be trusted there: personal accounts answer ruleset reads with HTTP 403, and free-plan organizations report declared rulesets as active while silently not enforcing them. Plan-gated repository settings that only function alongside branch protection (`allow_auto_merge`) are skipped for the same reason — GitHub accepts a PATCH for them with HTTP 200 and silently keeps the old value. The remaining repository merge settings are still checked and converged, and both commands print an unprotected-branch notice on every run. The only accepted value is `"unavailable-on-plan"` (enforcement is the default; omit the key on paid plans), and combining the opt-out with additional local rulesets is rejected. After upgrading the plan, remove the declaration and run `bun standards github --apply` to restore enforcement.
|
|
30
|
-
-
|
|
36
|
+
- **Poller config file** (required for `poller`, passed via `--config`) — host-level JSON, deliberately not repository state. Required: `"repos"` (unique `owner/repo` strings — one poller watches any number of repositories), `"model"` and `"reasoningEffort"` (passed to `codex exec`; the model choice is deliberate and has no default). Optional: `"maxJobsPerTick"` (default 1 — the concurrency and rate-limit guard; subscription-authenticated Codex runs share the interactive rate window), `"staleClaimHours"` (default 6; must exceed `runTimeoutMinutes` so a sweep can never release the claim of a job that is still running), `"runTimeoutMinutes"` (default 240 — the timeout catches wedged agents, not honest multi-hour review runs), `"cacheDir"` (default `~/.cache/standards-poller`; holds bare mirrors and job worktrees; relative paths resolve against the config file), `"extraCodexArgs"` (extra `codex exec` arguments, e.g. enabling the collaboration feature for subagent fan-out). Unknown keys are rejected. The poller needs `git`, `codex` (authenticated — its rotating auth state must live in a writable location), and a GitHub token per the bullet below; the token needs issues, pull-requests, and contents write on the watched repos, and nothing else.
|
|
37
|
+
- **`GH_TOKEN` / `GITHUB_TOKEN`** (optional) — GitHub API token for the `github` command and the GitHub portion of `check`. When neither is set, the token from the local `gh` CLI is used; with no token at all, reads still work on public repositories. `--apply` needs an admin token. GitHub's REST API reveals repo merge settings only to write-capable viewers — `check` retries REST-hidden keys over GraphQL, which serves them to read-only tokens — ruleset `bypass_actors` requires repository Administration read, and private-repository labels require Issues read (or Pull requests read); a token that still cannot see declared state fails the check rather than passing unverified. In CI, the canonical workflow decrypts `ci.github_settings_read_token` from the SOPS-encrypted `secrets/ci.yaml`: a repository-scoped fine-grained PAT with read-only "Administration" and "Issues" access.
|
|
31
38
|
|
|
32
39
|
See the standards repository README for the ownership model and adoption workflow.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@davidvornholt/standards",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
4
4
|
"description": "Bootstrap, synchronize, and validate davidvornholt/standards consumers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,9 +29,46 @@
|
|
|
29
29
|
"src/github-command-shared.ts",
|
|
30
30
|
"src/github-commands.ts",
|
|
31
31
|
"src/github-diff.ts",
|
|
32
|
+
"src/github-labels.ts",
|
|
33
|
+
"src/github-label-identity.ts",
|
|
32
34
|
"src/github-live-drift.ts",
|
|
35
|
+
"src/github-paginate.ts",
|
|
36
|
+
"src/github-settings-merge.ts",
|
|
33
37
|
"src/github-settings-parse.ts",
|
|
34
38
|
"src/github-settings.ts",
|
|
39
|
+
"src/managed-files.ts",
|
|
40
|
+
"src/poller-approval.ts",
|
|
41
|
+
"src/poller-claim.ts",
|
|
42
|
+
"src/poller-codex.ts",
|
|
43
|
+
"src/poller-commands.ts",
|
|
44
|
+
"src/poller-config.ts",
|
|
45
|
+
"src/poller-fix-outcome.ts",
|
|
46
|
+
"src/poller-fix-output.ts",
|
|
47
|
+
"src/poller-fix-publication.ts",
|
|
48
|
+
"src/poller-fix-run.ts",
|
|
49
|
+
"src/poller-fix-validation.ts",
|
|
50
|
+
"src/poller-github-pulls.ts",
|
|
51
|
+
"src/poller-github-publication.ts",
|
|
52
|
+
"src/poller-github-write.ts",
|
|
53
|
+
"src/poller-github.ts",
|
|
54
|
+
"src/poller-job-shared.ts",
|
|
55
|
+
"src/poller-outcome.ts",
|
|
56
|
+
"src/poller-output-integrity.ts",
|
|
57
|
+
"src/poller-prompts.ts",
|
|
58
|
+
"src/poller-protected-paths.ts",
|
|
59
|
+
"src/poller-protocol.ts",
|
|
60
|
+
"src/poller-review-publication.ts",
|
|
61
|
+
"src/poller-review-output.ts",
|
|
62
|
+
"src/poller-review-artifacts.ts",
|
|
63
|
+
"src/poller-review-execution.ts",
|
|
64
|
+
"src/poller-review-state.ts",
|
|
65
|
+
"src/poller-review-validation.ts",
|
|
66
|
+
"src/poller-schedule.ts",
|
|
67
|
+
"src/poller-review-run.ts",
|
|
68
|
+
"src/poller-tick.ts",
|
|
69
|
+
"src/poller-trust.ts",
|
|
70
|
+
"src/poller-units.ts",
|
|
71
|
+
"src/poller-workspace.ts",
|
|
35
72
|
"src/structure-check.ts",
|
|
36
73
|
"src/structure-profile.ts",
|
|
37
74
|
"src/structure-script.ts",
|
package/src/cli.ts
CHANGED
|
@@ -13,25 +13,9 @@
|
|
|
13
13
|
import { execFileSync } from 'node:child_process';
|
|
14
14
|
import { createHash } from 'node:crypto';
|
|
15
15
|
import { existsSync, mkdtempSync, rmSync } from 'node:fs';
|
|
16
|
-
import {
|
|
17
|
-
cp,
|
|
18
|
-
mkdir,
|
|
19
|
-
readdir,
|
|
20
|
-
readFile,
|
|
21
|
-
rm,
|
|
22
|
-
stat,
|
|
23
|
-
writeFile,
|
|
24
|
-
} from 'node:fs/promises';
|
|
16
|
+
import { cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
25
17
|
import { tmpdir } from 'node:os';
|
|
26
|
-
import {
|
|
27
|
-
dirname,
|
|
28
|
-
isAbsolute,
|
|
29
|
-
join,
|
|
30
|
-
posix,
|
|
31
|
-
relative,
|
|
32
|
-
resolve,
|
|
33
|
-
sep,
|
|
34
|
-
} from 'node:path';
|
|
18
|
+
import { dirname, isAbsolute, join, posix, resolve } from 'node:path';
|
|
35
19
|
import process from 'node:process';
|
|
36
20
|
import {
|
|
37
21
|
composeDependabot,
|
|
@@ -44,6 +28,11 @@ import { CANONICAL_SETTINGS_FILE, LOCAL_SETTINGS_FILE } from './github-api';
|
|
|
44
28
|
import { runGithubApply, runGithubCheck } from './github-commands';
|
|
45
29
|
import { loadGithubSettings } from './github-settings';
|
|
46
30
|
import { isNonEmptyString, isRecord } from './github-settings-parse';
|
|
31
|
+
import {
|
|
32
|
+
findManagedFilesContainingBiomeDirectiveToken,
|
|
33
|
+
listManagedFiles,
|
|
34
|
+
} from './managed-files';
|
|
35
|
+
import { runPollerCommand } from './poller-commands';
|
|
47
36
|
import { collectStructureProblems } from './structure-check';
|
|
48
37
|
import type { StructureProfile } from './structure-profile';
|
|
49
38
|
import { hasSafeCommand } from './structure-script';
|
|
@@ -56,17 +45,6 @@ const HASH_PREVIEW_LENGTH = 12;
|
|
|
56
45
|
const GITHUB_PREFIX = 'github:';
|
|
57
46
|
const SKIP_GITHUB_CHECK_ENV = 'STANDARDS_SKIP_GITHUB_CHECK';
|
|
58
47
|
|
|
59
|
-
// Never mirrored, even under a managed directory path: build output, VCS
|
|
60
|
-
// metadata, and installed dependencies would otherwise pollute the lock when
|
|
61
|
-
// syncing from a working tree that has them.
|
|
62
|
-
const IGNORED_DIRS = new Set([
|
|
63
|
-
'node_modules',
|
|
64
|
-
'.git',
|
|
65
|
-
'.turbo',
|
|
66
|
-
'dist',
|
|
67
|
-
'.next',
|
|
68
|
-
]);
|
|
69
|
-
|
|
70
48
|
type Manifest = {
|
|
71
49
|
readonly upstream: string;
|
|
72
50
|
readonly seedDir: string;
|
|
@@ -92,6 +70,7 @@ type Command =
|
|
|
92
70
|
| 'github'
|
|
93
71
|
| 'help'
|
|
94
72
|
| 'init'
|
|
73
|
+
| 'poller'
|
|
95
74
|
| 'structure'
|
|
96
75
|
| 'sync';
|
|
97
76
|
|
|
@@ -104,13 +83,13 @@ type CliOptions = {
|
|
|
104
83
|
readonly apply: boolean;
|
|
105
84
|
readonly write: boolean;
|
|
106
85
|
readonly profile: StructureProfile;
|
|
86
|
+
readonly config: string | undefined;
|
|
87
|
+
readonly printUnits: boolean;
|
|
107
88
|
};
|
|
108
89
|
|
|
109
90
|
const sha256 = (buf: Buffer): string =>
|
|
110
91
|
createHash('sha256').update(buf).digest('hex');
|
|
111
92
|
|
|
112
|
-
const toPosix = (p: string): string => p.split(sep).join('/');
|
|
113
|
-
|
|
114
93
|
const assertSafeRelativePath = (path: string, label: string): void => {
|
|
115
94
|
// POSIX semantics on every platform: managed paths are repository-relative
|
|
116
95
|
// POSIX paths, and win32 normalize would rewrite `/` to `\` and reject them.
|
|
@@ -240,38 +219,6 @@ const resolveSource = (src: string, ref: string | undefined): Source => {
|
|
|
240
219
|
return { dir, sha, cleanup };
|
|
241
220
|
};
|
|
242
221
|
|
|
243
|
-
// Recursively collect files under `abs`, keyed by their POSIX path relative to
|
|
244
|
-
// `base`. Missing paths are skipped so a manifest entry with no files is inert.
|
|
245
|
-
const walk = async (
|
|
246
|
-
abs: string,
|
|
247
|
-
base: string,
|
|
248
|
-
out: Map<string, string>,
|
|
249
|
-
): Promise<void> => {
|
|
250
|
-
const info = await stat(abs).catch(() => null);
|
|
251
|
-
if (info === null) {
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
if (info.isDirectory()) {
|
|
255
|
-
const entries = await readdir(abs);
|
|
256
|
-
await Promise.all(
|
|
257
|
-
entries
|
|
258
|
-
.filter((entry) => !IGNORED_DIRS.has(entry))
|
|
259
|
-
.map((entry) => walk(join(abs, entry), base, out)),
|
|
260
|
-
);
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
out.set(toPosix(relative(base, abs)), abs);
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
const listManaged = async (
|
|
267
|
-
dir: string,
|
|
268
|
-
paths: ReadonlyArray<string>,
|
|
269
|
-
): Promise<Map<string, string>> => {
|
|
270
|
-
const out = new Map<string, string>();
|
|
271
|
-
await Promise.all(paths.map((p) => walk(join(dir, p), dir, out)));
|
|
272
|
-
return out;
|
|
273
|
-
};
|
|
274
|
-
|
|
275
222
|
const isUnder = (a: string, b: string): boolean =>
|
|
276
223
|
a === b || a.startsWith(`${b}/`);
|
|
277
224
|
|
|
@@ -321,7 +268,7 @@ const mirror = async ({
|
|
|
321
268
|
for (const rel of Object.keys(previous)) {
|
|
322
269
|
assertSafeRelativePath(rel, 'sync-standards.lock file');
|
|
323
270
|
}
|
|
324
|
-
const upstream = await
|
|
271
|
+
const upstream = await listManagedFiles(srcDir, manifest.paths);
|
|
325
272
|
const next: Record<string, string> = {};
|
|
326
273
|
const created: Array<string> = [];
|
|
327
274
|
const updated: Array<string> = [];
|
|
@@ -396,14 +343,12 @@ const reportMirror = (result: MirrorResult, dryRun: boolean): void => {
|
|
|
396
343
|
}
|
|
397
344
|
};
|
|
398
345
|
|
|
399
|
-
const seedTargets =
|
|
346
|
+
const seedTargets = (
|
|
400
347
|
srcDir: string,
|
|
401
348
|
seedDir: string,
|
|
402
|
-
): Promise<
|
|
349
|
+
): Promise<ReadonlyMap<string, string>> => {
|
|
403
350
|
const root = join(srcDir, seedDir);
|
|
404
|
-
|
|
405
|
-
await walk(root, root, out);
|
|
406
|
-
return out;
|
|
351
|
+
return listManagedFiles(root, ['.']);
|
|
407
352
|
};
|
|
408
353
|
|
|
409
354
|
const runInit = async (
|
|
@@ -501,6 +446,7 @@ const runCheck = async (consumer: string): Promise<boolean> => {
|
|
|
501
446
|
for (const rel of Object.keys(lock.files)) {
|
|
502
447
|
assertSafeRelativePath(rel, 'sync-standards.lock file');
|
|
503
448
|
}
|
|
449
|
+
const lockedFiles = await listManagedFiles(consumer, Object.keys(lock.files));
|
|
504
450
|
const results = await Promise.all(
|
|
505
451
|
Object.entries(lock.files).map(async ([rel, hash]) => {
|
|
506
452
|
const dest = join(consumer, rel);
|
|
@@ -515,6 +461,8 @@ const runCheck = async (consumer: string): Promise<boolean> => {
|
|
|
515
461
|
}),
|
|
516
462
|
);
|
|
517
463
|
const problems = results.filter((p): p is string => p !== null);
|
|
464
|
+
const directiveFiles =
|
|
465
|
+
await findManagedFilesContainingBiomeDirectiveToken(lockedFiles);
|
|
518
466
|
if (problems.length > 0) {
|
|
519
467
|
console.error(
|
|
520
468
|
`standards: ${problems.length} canonical file(s) drifted from the last synced state:`,
|
|
@@ -523,12 +471,22 @@ const runCheck = async (consumer: string): Promise<boolean> => {
|
|
|
523
471
|
console.error(
|
|
524
472
|
'These files are read-only. Restore them with `bun standards sync`, or move your change upstream.',
|
|
525
473
|
);
|
|
526
|
-
return false;
|
|
527
474
|
}
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
475
|
+
if (directiveFiles.length > 0) {
|
|
476
|
+
console.error(
|
|
477
|
+
`standards: ${directiveFiles.length} canonical file(s) contain the forbidden inline Biome directive token:`,
|
|
478
|
+
);
|
|
479
|
+
console.error(directiveFiles.map((path) => ` - ${path}`).join('\n'));
|
|
480
|
+
console.error(
|
|
481
|
+
'Canonical synced files must remain compatible with consumer lint configurations.',
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
if (problems.length === 0) {
|
|
485
|
+
console.log(
|
|
486
|
+
`standards: ${Object.keys(lock.files).length} canonical file(s) match the last synced state`,
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
return problems.length === 0 && directiveFiles.length === 0;
|
|
532
490
|
};
|
|
533
491
|
|
|
534
492
|
const readTextIfPresent = async (path: string): Promise<string | null> =>
|
|
@@ -620,7 +578,7 @@ const prepareProspectiveDependabot = async (
|
|
|
620
578
|
consumer: string,
|
|
621
579
|
localSeed: string | null,
|
|
622
580
|
): Promise<ProspectiveDependabot> => {
|
|
623
|
-
const incoming = await
|
|
581
|
+
const incoming = await listManagedFiles(srcDir, manifest.paths);
|
|
624
582
|
const basePath = incoming.get(DEPENDABOT_BASE_FILE);
|
|
625
583
|
if (basePath === undefined) {
|
|
626
584
|
throw new Error(
|
|
@@ -779,17 +737,20 @@ Commands:
|
|
|
779
737
|
structure Validate monorepo structure rules only
|
|
780
738
|
dependabot Verify (--check) or regenerate (--write) the composed .github/dependabot.yml
|
|
781
739
|
github Compare (--check) or converge (--apply) live GitHub settings
|
|
740
|
+
poller Run one fix-poller tick over the configured repositories (host automation)
|
|
782
741
|
help Show this help
|
|
783
742
|
|
|
784
743
|
Options:
|
|
785
|
-
--dir <path>
|
|
786
|
-
--profile <p>
|
|
787
|
-
--from <src>
|
|
788
|
-
--ref <ref>
|
|
789
|
-
--dry-run
|
|
790
|
-
--check
|
|
791
|
-
--apply
|
|
792
|
-
--write
|
|
744
|
+
--dir <path> Consumer directory to operate on (default: current directory)
|
|
745
|
+
--profile <p> With structure: validate as a "consumer" (default) or as the standards "source" repository itself
|
|
746
|
+
--from <src> Upstream override for init/sync (GitHub repo or local path)
|
|
747
|
+
--ref <ref> Upstream tag, branch, or full commit sha for init/sync (remote Git/GitHub sources only; default: main)
|
|
748
|
+
--dry-run Preview a sync without writing anything
|
|
749
|
+
--check With github/dependabot: compare against the declared sources (default)
|
|
750
|
+
--apply With github: converge the live repository (needs admin auth)
|
|
751
|
+
--write With dependabot: regenerate the composed .github/dependabot.yml
|
|
752
|
+
--config <path> With poller: the host-level poller config file (required)
|
|
753
|
+
--print-units With poller: print declarative systemd unit content without touching the host`;
|
|
793
754
|
|
|
794
755
|
const commandFromArg = (arg: string): Command => {
|
|
795
756
|
if (
|
|
@@ -799,6 +760,7 @@ const commandFromArg = (arg: string): Command => {
|
|
|
799
760
|
arg === 'github' ||
|
|
800
761
|
arg === 'help' ||
|
|
801
762
|
arg === 'init' ||
|
|
763
|
+
arg === 'poller' ||
|
|
802
764
|
arg === 'structure' ||
|
|
803
765
|
arg === 'sync'
|
|
804
766
|
) {
|
|
@@ -841,12 +803,24 @@ type ParsedFlags = {
|
|
|
841
803
|
readonly write: boolean;
|
|
842
804
|
readonly ref: string | undefined;
|
|
843
805
|
readonly profile: StructureProfile | undefined;
|
|
806
|
+
readonly config: string | undefined;
|
|
807
|
+
readonly printUnits: boolean;
|
|
808
|
+
};
|
|
809
|
+
|
|
810
|
+
const assertPollerOptionUsage = (flags: ParsedFlags): void => {
|
|
811
|
+
if (flags.config !== undefined && flags.command !== 'poller') {
|
|
812
|
+
throw new Error('--config is only valid with the poller command');
|
|
813
|
+
}
|
|
814
|
+
if (flags.printUnits && flags.command !== 'poller') {
|
|
815
|
+
throw new Error('--print-units is only valid with the poller command');
|
|
816
|
+
}
|
|
844
817
|
};
|
|
845
818
|
|
|
846
819
|
// Every option is only meaningful with specific commands; reject the rest so a
|
|
847
820
|
// typo fails loudly instead of silently doing the default thing.
|
|
848
821
|
const assertOptionUsage = (flags: ParsedFlags): void => {
|
|
849
822
|
const { command, checkFlag, apply, write, ref, profile } = flags;
|
|
823
|
+
assertPollerOptionUsage(flags);
|
|
850
824
|
if (checkFlag && command !== 'github' && command !== 'dependabot') {
|
|
851
825
|
throw new Error(
|
|
852
826
|
'--check is only valid with the github and dependabot commands',
|
|
@@ -882,6 +856,8 @@ const parseArgs = (argv: ReadonlyArray<string>): CliOptions => {
|
|
|
882
856
|
let apply = false;
|
|
883
857
|
let write = false;
|
|
884
858
|
let profile: StructureProfile | undefined;
|
|
859
|
+
let config: string | undefined;
|
|
860
|
+
let printUnits = false;
|
|
885
861
|
|
|
886
862
|
for (let index = 0; index < argv.length; index += 1) {
|
|
887
863
|
const arg = argv[index];
|
|
@@ -889,6 +865,13 @@ const parseArgs = (argv: ReadonlyArray<string>): CliOptions => {
|
|
|
889
865
|
case '--apply':
|
|
890
866
|
apply = true;
|
|
891
867
|
break;
|
|
868
|
+
case '--config':
|
|
869
|
+
config = nextOptionValue(argv, index);
|
|
870
|
+
index += 1;
|
|
871
|
+
break;
|
|
872
|
+
case '--print-units':
|
|
873
|
+
printUnits = true;
|
|
874
|
+
break;
|
|
892
875
|
case '--check':
|
|
893
876
|
checkFlag = true;
|
|
894
877
|
break;
|
|
@@ -923,7 +906,16 @@ const parseArgs = (argv: ReadonlyArray<string>): CliOptions => {
|
|
|
923
906
|
}
|
|
924
907
|
}
|
|
925
908
|
|
|
926
|
-
assertOptionUsage({
|
|
909
|
+
assertOptionUsage({
|
|
910
|
+
command,
|
|
911
|
+
checkFlag,
|
|
912
|
+
apply,
|
|
913
|
+
write,
|
|
914
|
+
ref,
|
|
915
|
+
profile,
|
|
916
|
+
config,
|
|
917
|
+
printUnits,
|
|
918
|
+
});
|
|
927
919
|
|
|
928
920
|
return {
|
|
929
921
|
command,
|
|
@@ -934,6 +926,8 @@ const parseArgs = (argv: ReadonlyArray<string>): CliOptions => {
|
|
|
934
926
|
apply,
|
|
935
927
|
write,
|
|
936
928
|
profile: profile ?? 'consumer',
|
|
929
|
+
config,
|
|
930
|
+
printUnits,
|
|
937
931
|
};
|
|
938
932
|
};
|
|
939
933
|
|
|
@@ -973,7 +967,7 @@ const runCheckCommand = async (consumer: string): Promise<boolean> => {
|
|
|
973
967
|
};
|
|
974
968
|
|
|
975
969
|
// The canonical workflow sets this only for its unprivileged quality job,
|
|
976
|
-
// where a separate isolated job runs the same live check with the
|
|
970
|
+
// where a separate isolated job runs the same live check with the settings-read
|
|
977
971
|
// token. Absent that exact workflow seam, local and explicit checks remain
|
|
978
972
|
// fail-closed.
|
|
979
973
|
const runGithubCheckGate = (consumer: string): Promise<boolean> => {
|
|
@@ -1135,8 +1129,18 @@ const runGateCommand = (
|
|
|
1135
1129
|
};
|
|
1136
1130
|
|
|
1137
1131
|
const main = async (): Promise<void> => {
|
|
1138
|
-
const {
|
|
1139
|
-
|
|
1132
|
+
const {
|
|
1133
|
+
command,
|
|
1134
|
+
consumer,
|
|
1135
|
+
dryRun,
|
|
1136
|
+
from,
|
|
1137
|
+
ref,
|
|
1138
|
+
apply,
|
|
1139
|
+
write,
|
|
1140
|
+
profile,
|
|
1141
|
+
config,
|
|
1142
|
+
printUnits,
|
|
1143
|
+
} = parseArgs(process.argv.slice(2));
|
|
1140
1144
|
|
|
1141
1145
|
if (command === undefined) {
|
|
1142
1146
|
console.error('standards: a command is required\n');
|
|
@@ -1165,6 +1169,13 @@ const main = async (): Promise<void> => {
|
|
|
1165
1169
|
return;
|
|
1166
1170
|
}
|
|
1167
1171
|
|
|
1172
|
+
if (command === 'poller') {
|
|
1173
|
+
if (!(await runPollerCommand({ configPath: config, printUnits }))) {
|
|
1174
|
+
process.exitCode = 1;
|
|
1175
|
+
}
|
|
1176
|
+
return;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1168
1179
|
if (!(await runGateCommand(command, consumer, apply, profile))) {
|
|
1169
1180
|
process.exitCode = 1;
|
|
1170
1181
|
}
|
package/src/github-api.ts
CHANGED
|
@@ -21,6 +21,8 @@ const GITHUB_REMOTE_PATTERN =
|
|
|
21
21
|
export const HTTP_OK = 200;
|
|
22
22
|
export const HTTP_CREATED = 201;
|
|
23
23
|
export const HTTP_NO_CONTENT = 204;
|
|
24
|
+
export const HTTP_UNAUTHORIZED = 401;
|
|
25
|
+
export const HTTP_FORBIDDEN = 403;
|
|
24
26
|
|
|
25
27
|
export const CANONICAL_SETTINGS_FILE = '.github/settings.json';
|
|
26
28
|
export const LOCAL_SETTINGS_FILE = '.github/settings.local.json';
|
package/src/github-commands.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
enforceableRepositorySettings,
|
|
21
21
|
optOutEligibilityProblem,
|
|
22
22
|
} from './github-command-shared';
|
|
23
|
+
import { applyLabels } from './github-labels';
|
|
23
24
|
import { collectLiveDrift } from './github-live-drift';
|
|
24
25
|
import { isRecord } from './github-settings-parse';
|
|
25
26
|
|
|
@@ -108,6 +109,7 @@ export const runGithubApply = async (consumer: string): Promise<boolean> => {
|
|
|
108
109
|
if (!rulesetsSkipped) {
|
|
109
110
|
actions.push(...(await applyRulesets(token, repo, declared.merged)));
|
|
110
111
|
}
|
|
112
|
+
actions.push(...(await applyLabels(token, repo, declared.merged.labels)));
|
|
111
113
|
for (const action of actions) {
|
|
112
114
|
console.log(` ${action}`);
|
|
113
115
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const labelIdentity = (name: string): string => name.toLowerCase();
|
|
2
|
+
|
|
3
|
+
export const hasLabel = (
|
|
4
|
+
labels: ReadonlyArray<string>,
|
|
5
|
+
expected: string,
|
|
6
|
+
): boolean => {
|
|
7
|
+
const identity = labelIdentity(expected);
|
|
8
|
+
return labels.some((label) => labelIdentity(label) === identity);
|
|
9
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Live issue-label reading, drift, and convergence. Labels are an additive
|
|
2
|
+
// floor: every declared label must exist with the declared color and
|
|
3
|
+
// description; undeclared live labels (GitHub defaults, ad-hoc triage labels)
|
|
4
|
+
// are ignored. Private-repository reads require Issues read (or Pull requests
|
|
5
|
+
// read), and an API denial fails the settings check closed.
|
|
6
|
+
|
|
7
|
+
import { apiError, HTTP_CREATED, HTTP_OK, request } from './github-api';
|
|
8
|
+
import { labelIdentity } from './github-label-identity';
|
|
9
|
+
import { listAllPages } from './github-paginate';
|
|
10
|
+
import { isRecord, type LabelDeclaration } from './github-settings-parse';
|
|
11
|
+
|
|
12
|
+
type LiveLabel = {
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly color: string;
|
|
15
|
+
readonly description: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const fetchLiveLabels = async (
|
|
19
|
+
token: string | null,
|
|
20
|
+
repo: string,
|
|
21
|
+
): Promise<ReadonlyArray<LiveLabel>> => {
|
|
22
|
+
const items = await listAllPages(
|
|
23
|
+
token,
|
|
24
|
+
`/repos/${repo}/labels`,
|
|
25
|
+
`reading labels for ${repo}`,
|
|
26
|
+
);
|
|
27
|
+
return items.filter(isRecord).map((label) => ({
|
|
28
|
+
name: typeof label.name === 'string' ? label.name : '',
|
|
29
|
+
color: typeof label.color === 'string' ? label.color : '',
|
|
30
|
+
description: typeof label.description === 'string' ? label.description : '',
|
|
31
|
+
}));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const labelDrift = (
|
|
35
|
+
declared: LabelDeclaration,
|
|
36
|
+
live: LiveLabel | undefined,
|
|
37
|
+
): string | null => {
|
|
38
|
+
if (live === undefined) {
|
|
39
|
+
return `label "${declared.name}" is declared but missing on GitHub`;
|
|
40
|
+
}
|
|
41
|
+
// GitHub reports colors in varying case; declarations are lowercase.
|
|
42
|
+
const liveColor = live.color.toLowerCase();
|
|
43
|
+
if (liveColor !== declared.color) {
|
|
44
|
+
return `label "${declared.name}" has color "${liveColor}" on GitHub, declared "${declared.color}"`;
|
|
45
|
+
}
|
|
46
|
+
if (live.description !== declared.description) {
|
|
47
|
+
return `label "${declared.name}" has a different description on GitHub than declared`;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const diffLabels = (
|
|
53
|
+
declared: ReadonlyArray<LabelDeclaration>,
|
|
54
|
+
live: ReadonlyArray<LiveLabel>,
|
|
55
|
+
): ReadonlyArray<string> => {
|
|
56
|
+
const liveByName = new Map(
|
|
57
|
+
live.map((label) => [labelIdentity(label.name), label]),
|
|
58
|
+
);
|
|
59
|
+
return declared.flatMap((label) => {
|
|
60
|
+
const drift = labelDrift(label, liveByName.get(labelIdentity(label.name)));
|
|
61
|
+
return drift === null ? [] : [drift];
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const convergeLabel = async (
|
|
66
|
+
token: string,
|
|
67
|
+
repo: string,
|
|
68
|
+
declared: LabelDeclaration,
|
|
69
|
+
live: LiveLabel | undefined,
|
|
70
|
+
): Promise<string | null> => {
|
|
71
|
+
if (labelDrift(declared, live) === null) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
if (live === undefined) {
|
|
75
|
+
const created = await request(token, 'POST', `/repos/${repo}/labels`, {
|
|
76
|
+
name: declared.name,
|
|
77
|
+
color: declared.color,
|
|
78
|
+
description: declared.description,
|
|
79
|
+
});
|
|
80
|
+
if (created.status !== HTTP_CREATED) {
|
|
81
|
+
throw new Error(apiError(`creating label "${declared.name}"`, created));
|
|
82
|
+
}
|
|
83
|
+
return `created label "${declared.name}"`;
|
|
84
|
+
}
|
|
85
|
+
const updated = await request(
|
|
86
|
+
token,
|
|
87
|
+
'PATCH',
|
|
88
|
+
`/repos/${repo}/labels/${encodeURIComponent(live.name)}`,
|
|
89
|
+
{ color: declared.color, description: declared.description },
|
|
90
|
+
);
|
|
91
|
+
if (updated.status !== HTTP_OK) {
|
|
92
|
+
throw new Error(apiError(`updating label "${declared.name}"`, updated));
|
|
93
|
+
}
|
|
94
|
+
return `updated label "${declared.name}"`;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const applyLabels = async (
|
|
98
|
+
token: string,
|
|
99
|
+
repo: string,
|
|
100
|
+
declared: ReadonlyArray<LabelDeclaration>,
|
|
101
|
+
): Promise<ReadonlyArray<string>> => {
|
|
102
|
+
if (declared.length === 0) {
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
const live = await fetchLiveLabels(token, repo);
|
|
106
|
+
const liveByName = new Map(
|
|
107
|
+
live.map((label) => [labelIdentity(label.name), label]),
|
|
108
|
+
);
|
|
109
|
+
const actions: Array<string> = [];
|
|
110
|
+
for (const label of declared) {
|
|
111
|
+
// biome-ignore lint/performance/noAwaitInLoops: GitHub advises against concurrent write requests (secondary rate limits); mutations run sequentially on purpose.
|
|
112
|
+
const action = await convergeLabel(
|
|
113
|
+
token,
|
|
114
|
+
repo,
|
|
115
|
+
label,
|
|
116
|
+
liveByName.get(labelIdentity(label.name)),
|
|
117
|
+
);
|
|
118
|
+
if (action !== null) {
|
|
119
|
+
actions.push(action);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return actions;
|
|
123
|
+
};
|