@davidvornholt/standards 0.16.0 → 0.17.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 +3 -3
- package/package.json +5 -2
- package/src/poller-acknowledgements.ts +2 -3
- package/src/poller-approval.ts +62 -5
- package/src/poller-claim.ts +6 -3
- package/src/poller-codex.ts +5 -11
- package/src/poller-commands.ts +20 -3
- package/src/poller-fix-run.ts +48 -30
- package/src/poller-github.ts +28 -19
- package/src/poller-job-shared.ts +47 -6
- package/src/poller-outcome.ts +60 -18
- package/src/poller-prompts.ts +35 -9
- package/src/poller-protocol.ts +19 -10
- package/src/poller-review-artifacts.ts +4 -30
- package/src/poller-review-execution.ts +7 -4
- package/src/poller-review-output.ts +14 -35
- package/src/poller-review-plan-parse.ts +94 -0
- package/src/poller-review-publication.ts +3 -3
- package/src/poller-review-run.ts +63 -11
- package/src/poller-review-state.ts +4 -1
- package/src/poller-review-thread-api.ts +166 -0
- package/src/poller-review-thread-write.ts +64 -0
- package/src/poller-review-threads.ts +119 -0
- package/src/poller-status.ts +3 -1
- package/src/poller-tick.ts +8 -6
- package/src/poller-github-publication.ts +0 -23
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ standards poller --print-units --config <path>
|
|
|
35
35
|
|
|
36
36
|
`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.
|
|
37
37
|
|
|
38
|
-
`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. A separate acknowledgement tick validates pending approvals and posts one deduplicated queued message per approval generation; it never claims or starts work, so it can keep giving maintainers prompt feedback while the worker is occupied. When a worker claims a request, it posts a concise start message. The exact approval and distributed claim records remain in hidden comment metadata, and losing claim contenders remove their duplicate comments. 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.
|
|
38
|
+
`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. A separate acknowledgement tick validates pending approvals and posts one deduplicated queued message per approval generation; it never claims or starts work, so it can keep giving maintainers prompt feedback while the worker is occupied. When a worker claims a request, it posts a concise start message. The exact approval and distributed claim records remain in hidden comment metadata, and losing claim contenders remove their duplicate comments. 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. Approved Codex runs inherit the poller's GitHub token and use authenticated `gh` for relevant reads and comments; review runs also maintain the PR review ledger, apply authorized title or body edits, post fix threads, and file deferred findings directly. The run works in a throwaway git worktree, grants Codex write access to that worktree and its exact Git common directory so commits can update the linked repository metadata, and hands results back through a structured outcome file. The poller then verifies the approved head, commits, and protected paths before pushing or publishing; it replies to and resolves agent-posted fix threads only after the reviewed head is pushed, and it alone changes protocol labels, posts the final report, and flips a reviewed draft ready, while required CI remains the quality gate. Sealed review plans from the earlier protocol are rejected and their output branches are ignored, so the review reruns on a fresh protocol-versioned branch rather than silently dropping legacy deferred work. Host mutation is declarative-only: `--print-units` emits four correctly escaped systemd units for the polling host's infrastructure repository to adapt and deploy: the worker service and timer plus an independent lightweight acknowledgement service and timer. That repository owns the service identity, writable HOME, PATH, authenticated `gh`, lingering, and deployment. The worker service's tick budget (`TimeoutStartSec`) is derived from `maxJobsPerTick` × `runTimeoutMinutes` plus overhead, so re-render and redeploy the units after changing either value.
|
|
39
39
|
|
|
40
40
|
`creds` is the credential broker: it mints scoped Cloudflare tokens, rotates and revokes those tokens, and places GitHub App credentials into SOPS-encrypted targets — secret values never touch stdout, argv, or an agent's context; commands print only metadata (token name, scopes, expiry, destination). Cloudflare reconciliation has exactly two sources of truth: the plaintext key structure of the SOPS files and the provider token list under the deterministic naming scheme `standards/<owner>/<repo>/<sops-target>/<dotted.key>`; there is no separate credential manifest. `plan` and `apply` reconcile Cloudflare only: each run uses the stored bootstrap credential to verify its current provider token ID, excludes that ID from reconciliation regardless of its current name, and aborts if the identity cannot be correlated with the complete account token list; a brokered token whose SOPS key was deleted is revoked, while one nearing expiry (30 days) is renewed by creating a fresh-expiry replacement with the live token's policy, durably writing and verifying the new value, and only then revoking the old token; secrets the broker did not mint are never touched. Without a manifest there is no desired-policy record, so live policy drift is not detected, and a repository rename or transfer changes the deterministic namespace and requires the visible old token to be re-minted under the new name and revoked. `add cloudflare` mints an account-owned API token (default TTL 90 days) scoped to the named permission groups (`permissions` lists the valid names) and writes it to `--dest <target>:<dotted.key>`, where `<target>` resolves like the canonical `just secrets` targets (`ci` → `secrets/ci.yaml`, `prod-1` → `infra/hosts/prod-1/secrets.yaml`); zone-scoped groups such as DNS Write are rejected because the current command supplies an account resource, not a zone resource. `--bucket <name>` switches the policy resource to a single R2 bucket; `--jurisdiction default|eu` selects the provider jurisdiction and defaults to `default`, producing `com.cloudflare.edge.r2.bucket.<account_id>_default_<bucket>` or `com.cloudflare.edge.r2.bucket.<account_id>_eu_<bucket>`. FedRAMP jurisdictions are not supported. Bucket destinations accept only bucket-scoped groups such as Workers R2 Storage Bucket Item Read/Write, and account-scoped groups are rejected. `--s3` requires `--bucket` and stores the S3-compatible credential pair Cloudflare derives from an API token — access key ID is the token ID, secret access key is the SHA-256 hex digest of the token value — as `<dotted.key>.access_key_id` and `<dotted.key>.secret_access_key` under the destination instead of the raw token value; the default endpoint is `https://<account_id>.r2.cloudflarestorage.com`, while EU uses `https://<account_id>.eu.r2.cloudflarestorage.com`. Reconciliation infers each destination's concrete write footprint from the plaintext SOPS key structure — a bearer owns the leaf at its key, while an S3 token owns both pair leaves — and aborts before mutation when managed footprints intersect. `plan` and `apply` renew and revoke S3 destinations like any other brokered token, but renewal first proves the stored access key ID matches the current provider token; an incomplete pair, unreadable value, or identity mismatch is surfaced as a finding and never mutated automatically. `add github` writes the broker GitHub App's `app_id` and `private_key` under the destination key; durable GitHub tokens cannot be created via API (PAT and OAuth-app creation are UI-only), so workflows mint short-lived installation tokens from the App at runtime (`actions/create-github-app-token`), scoped per repository and permission. The canonical weekly sync expects `bun standards creds add github --dest ci:ci.broker_app`, then mints a current-repository token with Contents read and Pull requests write; missing credentials or minting failures stop it without a fallback. Bootstrap is once per machine: `login github` runs the App manifest flow (a localhost page posts the pre-filled manifest; one "Create GitHub App" click; credentials return through the conversion endpoint — nothing is copied by hand) and opens the installation page, where the App must be bound to selected repositories rather than all repositories; `login cloudflare` guides the one dashboard paste Cloudflare requires for the first account token (named `standards-broker` to match the App, created from the "Create additional tokens" token template because its "Account API Tokens: Edit" permission is unavailable in the custom token builder, and holding that permission only), verifies that it is active, correlates its verified ID with the complete account token list and an active list record, and stores it; a bootstrap token named inside the minted `standards/` namespace is rejected before storage to keep its role unambiguous, while any other divergence from the recommended name only warns. `plan` and `apply` do not rotate GitHub App keys; create a replacement key on the App's settings page, atomically replace `github.private_key` in the protected machine-global broker store while preserving its `0600` mode, then update every intended SOPS destination, verify workflows can mint installation tokens, and revoke the old key manually. Root credentials live in the machine-global broker store (see Configuration); SOPS writes go through `sops edit` with a non-interactive editor, preserving comments and reusing the file's data key.
|
|
41
41
|
|
|
@@ -46,8 +46,8 @@ standards poller --print-units --config <path>
|
|
|
46
46
|
- **`.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.
|
|
47
47
|
- **`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; deliberate syncs then run locally because the secret-bearing workflow is schedule-only. 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.
|
|
48
48
|
- **`.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.
|
|
49
|
-
- **Poller config file** (required for `poller`, passed via `--config`) — host-level JSON, deliberately not repository state. Required: `"repos"` (1–12 unique `owner/repo` strings), `"model"` and `"reasoningEffort"` (passed to `codex exec`; the model choice is deliberate and has no default). The 12-repository maximum and five-minute acknowledgement cooldown keep supported mixed fix/review queues and persisted review-plan recovery below the 5,000-request/hour GitHub API budget with at least 1,400 requests/hour reserved for pagination, active jobs, writes, and other token users; the compound regression bound covers four acknowledged fixes plus four acknowledged reviews with persisted plans in every repository at no more than 3,312 requests/hour. Existing configs above the repository limit must be reduced or split across pollers with independent GitHub API budgets before upgrading. Optional: `"maxJobsPerTick"` (default 1 — the maximum number of new Codex runs the sequential worker may start in one tick), `"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.
|
|
49
|
+
- **Poller config file** (required for `poller`, passed via `--config`) — host-level JSON, deliberately not repository state. Required: `"repos"` (1–12 unique `owner/repo` strings), `"model"` and `"reasoningEffort"` (passed to `codex exec`; the model choice is deliberate and has no default). The 12-repository maximum and five-minute acknowledgement cooldown keep supported mixed fix/review queues and persisted review-plan recovery below the 5,000-request/hour GitHub API budget with at least 1,400 requests/hour reserved for pagination, active jobs, writes, and other token users; the compound regression bound covers four acknowledged fixes plus four acknowledged reviews with persisted plans in every repository at no more than 3,312 requests/hour. Existing configs above the repository limit must be reduced or split across pollers with independent GitHub API budgets before upgrading. Optional: `"maxJobsPerTick"` (default 1 — the maximum number of new Codex runs the sequential worker may start in one tick), `"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`, `gh`, `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.
|
|
50
50
|
- **Broker store** (created by `creds login`) — machine-global root credentials at `$XDG_CONFIG_HOME/standards/broker.yaml` (default `~/.config/standards/broker.yaml`; override with `STANDARDS_BROKER_FILE`), holding the GitHub App identity (id, slug, client id, private key) and one bootstrap token per Cloudflare account. The file is plaintext with `0600` permissions — deliberately the same local-account trust boundary as the plaintext personal age identity at `~/.config/sops/age/keys.txt`, which unlocks the same secrets; SOPS-encrypting the store to that adjacent identity would not improve custody. Writes use an owner-only temporary file and atomic replacement, and simultaneous provider logins merge rather than overwrite each other; `creds status` warns when the final mode is broader. The store lives outside every repository, is never synced or backed up, and losing it is cheap: re-run the two login commands and revoke the old App key and bootstrap token. On an additional machine, do not create a second App: generate an additional private key from the existing App's settings page (GitHub Apps support several active keys; key generation has no API) and add it to that machine's store, so retiring a machine revokes one key, not the setup.
|
|
51
|
-
- **`GH_TOKEN` / `GITHUB_TOKEN`** (optional) — GitHub API token for the `github` command and the GitHub portion of `check
|
|
51
|
+
- **`GH_TOKEN` / `GITHUB_TOKEN`** (optional generally; poller automation requires this or a logged-in `gh`) — GitHub API token for the `github` command and the GitHub portion of `check`; poller runs pass environment tokens through to Codex, while a local poller can share the service identity's authenticated `gh` state. When neither is available, other commands can still read public repositories anonymously, but poller writes and `github --apply` fail. 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.
|
|
52
52
|
|
|
53
53
|
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.17.1",
|
|
4
4
|
"description": "Bootstrap, synchronize, and validate davidvornholt/standards consumers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -90,7 +90,6 @@
|
|
|
90
90
|
"src/poller-fix-run.ts",
|
|
91
91
|
"src/poller-fix-validation.ts",
|
|
92
92
|
"src/poller-github-pulls.ts",
|
|
93
|
-
"src/poller-github-publication.ts",
|
|
94
93
|
"src/poller-github-write.ts",
|
|
95
94
|
"src/poller-github.ts",
|
|
96
95
|
"src/poller-job-shared.ts",
|
|
@@ -105,7 +104,11 @@
|
|
|
105
104
|
"src/poller-review-output.ts",
|
|
106
105
|
"src/poller-review-artifacts.ts",
|
|
107
106
|
"src/poller-review-execution.ts",
|
|
107
|
+
"src/poller-review-plan-parse.ts",
|
|
108
108
|
"src/poller-review-state.ts",
|
|
109
|
+
"src/poller-review-thread-api.ts",
|
|
110
|
+
"src/poller-review-thread-write.ts",
|
|
111
|
+
"src/poller-review-threads.ts",
|
|
109
112
|
"src/poller-review-validation.ts",
|
|
110
113
|
"src/poller-schedule.ts",
|
|
111
114
|
"src/poller-status.ts",
|
|
@@ -91,9 +91,8 @@ const acknowledgeItems = async (options: {
|
|
|
91
91
|
// biome-ignore lint/performance/noAwaitInLoops: acknowledgement writes are deliberately serialized to avoid GitHub secondary rate limits.
|
|
92
92
|
const approval = await approvalFor(deps, item, kind);
|
|
93
93
|
if (
|
|
94
|
-
approval
|
|
95
|
-
|
|
96
|
-
(await acknowledgeQueuedJob(deps, item.number, approval, kind))
|
|
94
|
+
approval?.kind === 'approved' &&
|
|
95
|
+
(await acknowledgeQueuedJob(deps, item.number, approval.approval, kind))
|
|
97
96
|
) {
|
|
98
97
|
lines.push(
|
|
99
98
|
`${deps.repo} ${kind === 'fix' ? `#${item.number}` : `PR #${item.number}`}: acknowledged as queued`,
|
package/src/poller-approval.ts
CHANGED
|
@@ -19,15 +19,45 @@ export type ApprovalBinding = {
|
|
|
19
19
|
readonly target: string;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
export type ApprovalBindingResult =
|
|
23
|
+
| {
|
|
24
|
+
readonly kind: 'approved';
|
|
25
|
+
readonly approval: ApprovalBinding;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
readonly kind: 'absent';
|
|
29
|
+
}
|
|
30
|
+
| {
|
|
31
|
+
readonly kind: 'rejected';
|
|
32
|
+
readonly generationId: string;
|
|
33
|
+
readonly reason: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
22
36
|
type ApprovalContext = {
|
|
23
37
|
readonly token: string | null;
|
|
24
38
|
readonly repo: string;
|
|
25
39
|
readonly issueNumber: number;
|
|
26
40
|
};
|
|
27
41
|
|
|
42
|
+
export type ApprovalTargetReader = () => Promise<string | null>;
|
|
43
|
+
|
|
28
44
|
const stableDigest = (value: unknown): string =>
|
|
29
45
|
createHash('sha256').update(JSON.stringify(value)).digest('hex');
|
|
30
46
|
|
|
47
|
+
const rejectionGenerationId = (
|
|
48
|
+
context: ApprovalContext,
|
|
49
|
+
label: string,
|
|
50
|
+
target: string,
|
|
51
|
+
event: Awaited<ReturnType<typeof lastLabelEvent>>,
|
|
52
|
+
): string =>
|
|
53
|
+
stableDigest({
|
|
54
|
+
repo: context.repo,
|
|
55
|
+
issueNumber: context.issueNumber,
|
|
56
|
+
label,
|
|
57
|
+
target,
|
|
58
|
+
event,
|
|
59
|
+
});
|
|
60
|
+
|
|
31
61
|
export const issueRevision = (issue: IssueItem): string =>
|
|
32
62
|
`issue:${stableDigest({ title: issue.title, body: issue.body })}`;
|
|
33
63
|
|
|
@@ -41,14 +71,14 @@ export const readApprovalBinding = async (
|
|
|
41
71
|
context: ApprovalContext,
|
|
42
72
|
label: string,
|
|
43
73
|
target: string,
|
|
44
|
-
): Promise<
|
|
74
|
+
): Promise<ApprovalBindingResult> => {
|
|
45
75
|
const issue = await getIssue(
|
|
46
76
|
context.token,
|
|
47
77
|
context.repo,
|
|
48
78
|
context.issueNumber,
|
|
49
79
|
);
|
|
50
80
|
if (!hasLabel(issue.labels, label)) {
|
|
51
|
-
return
|
|
81
|
+
return { kind: 'absent' };
|
|
52
82
|
}
|
|
53
83
|
const event = await lastLabelEvent(
|
|
54
84
|
context.token,
|
|
@@ -57,7 +87,11 @@ export const readApprovalBinding = async (
|
|
|
57
87
|
label,
|
|
58
88
|
);
|
|
59
89
|
if (event === null) {
|
|
60
|
-
return
|
|
90
|
+
return {
|
|
91
|
+
kind: 'rejected',
|
|
92
|
+
generationId: rejectionGenerationId(context, label, target, event),
|
|
93
|
+
reason: `no "${label}" label event found on ${context.repo}#${context.issueNumber}`,
|
|
94
|
+
};
|
|
61
95
|
}
|
|
62
96
|
const role = await collaboratorRole(
|
|
63
97
|
context.token,
|
|
@@ -65,7 +99,11 @@ export const readApprovalBinding = async (
|
|
|
65
99
|
event.actorLogin,
|
|
66
100
|
);
|
|
67
101
|
if (!isTrustedRole(role)) {
|
|
68
|
-
return
|
|
102
|
+
return {
|
|
103
|
+
kind: 'rejected',
|
|
104
|
+
generationId: rejectionGenerationId(context, label, target, event),
|
|
105
|
+
reason: `"${label}" on ${context.repo}#${context.issueNumber} was applied by ${event.actorLogin} (role: ${role}); only admin or maintain roles may approve automation`,
|
|
106
|
+
};
|
|
69
107
|
}
|
|
70
108
|
const fields = {
|
|
71
109
|
repo: context.repo,
|
|
@@ -76,5 +114,24 @@ export const readApprovalBinding = async (
|
|
|
76
114
|
approvedAt: event.createdAt,
|
|
77
115
|
target,
|
|
78
116
|
};
|
|
79
|
-
return {
|
|
117
|
+
return {
|
|
118
|
+
kind: 'approved',
|
|
119
|
+
approval: { id: stableDigest(fields), ...fields },
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const approvalIsCurrent = async (
|
|
124
|
+
context: ApprovalContext,
|
|
125
|
+
approval: ApprovalBinding,
|
|
126
|
+
readTarget: ApprovalTargetReader,
|
|
127
|
+
): Promise<boolean> => {
|
|
128
|
+
const current = await readApprovalBinding(
|
|
129
|
+
context,
|
|
130
|
+
approval.label,
|
|
131
|
+
approval.target,
|
|
132
|
+
);
|
|
133
|
+
if (current.kind !== 'approved' || current.approval.id !== approval.id) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
return (await readTarget()) === approval.target;
|
|
80
137
|
};
|
package/src/poller-claim.ts
CHANGED
|
@@ -165,10 +165,13 @@ export const validateClaim = async (
|
|
|
165
165
|
claim.approval.label,
|
|
166
166
|
currentTarget,
|
|
167
167
|
);
|
|
168
|
-
if (
|
|
169
|
-
return
|
|
168
|
+
if (current.kind === 'absent') {
|
|
169
|
+
return `"${claim.approval.label}" is not currently present`;
|
|
170
170
|
}
|
|
171
|
-
if (current.
|
|
171
|
+
if (current.kind === 'rejected') {
|
|
172
|
+
return current.reason;
|
|
173
|
+
}
|
|
174
|
+
if (current.approval.id !== claim.approval.id) {
|
|
172
175
|
return 'approval no longer matches the exact approved revision/head';
|
|
173
176
|
}
|
|
174
177
|
const issue = await getIssue(
|
package/src/poller-codex.ts
CHANGED
|
@@ -51,17 +51,11 @@ const exitCause = (details: Record<string, unknown>): string => {
|
|
|
51
51
|
return 'unknown exit cause';
|
|
52
52
|
};
|
|
53
53
|
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
const agentEnv = (): Record<string, string | undefined> => {
|
|
59
|
-
const env = { ...process.env };
|
|
60
|
-
env.GH_TOKEN = undefined;
|
|
61
|
-
env.GITHUB_TOKEN = undefined;
|
|
62
|
-
env.STANDARDS_POLLER_GIT_TOKEN = undefined;
|
|
63
|
-
return env;
|
|
64
|
-
};
|
|
54
|
+
// Codex deliberately inherits the poller's authenticated GitHub environment.
|
|
55
|
+
// The agent uses `gh` for review-fix ledger operations and PR metadata, while
|
|
56
|
+
// the poller still owns verified commit publication, labels, and ready/merge
|
|
57
|
+
// transitions.
|
|
58
|
+
const agentEnv = (): Record<string, string | undefined> => ({ ...process.env });
|
|
65
59
|
|
|
66
60
|
export const runCodex = (
|
|
67
61
|
options: CodexRunOptions,
|
package/src/poller-commands.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// it reports what it did and fails loudly when any repository could not be
|
|
3
3
|
// processed, so a red systemd unit is the durable signal that jobs stalled.
|
|
4
4
|
|
|
5
|
-
import { existsSync } from 'node:fs';
|
|
5
|
+
import { accessSync, constants, existsSync } from 'node:fs';
|
|
6
6
|
import { readFile } from 'node:fs/promises';
|
|
7
|
-
import { dirname, resolve } from 'node:path';
|
|
7
|
+
import { delimiter, dirname, join, resolve } from 'node:path';
|
|
8
|
+
import process from 'node:process';
|
|
8
9
|
import { resolveToken } from './github-api';
|
|
9
10
|
import { runPollerAcknowledgementTick } from './poller-acknowledgements';
|
|
10
11
|
import { type PollerConfig, parsePollerConfig } from './poller-config';
|
|
@@ -42,6 +43,16 @@ const loadConfig = async (configPath: string): Promise<PollerConfig> => {
|
|
|
42
43
|
return config;
|
|
43
44
|
};
|
|
44
45
|
|
|
46
|
+
const hasExecutableOnPath = (name: string): boolean =>
|
|
47
|
+
(process.env.PATH ?? '').split(delimiter).some((directory) => {
|
|
48
|
+
try {
|
|
49
|
+
accessSync(join(directory, name), constants.X_OK);
|
|
50
|
+
return true;
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
45
56
|
export const runPollerCommand = async (
|
|
46
57
|
options: PollerCommandOptions,
|
|
47
58
|
): Promise<boolean> => {
|
|
@@ -60,7 +71,13 @@ export const runPollerCommand = async (
|
|
|
60
71
|
const token = resolveToken();
|
|
61
72
|
if (token === null) {
|
|
62
73
|
console.error(
|
|
63
|
-
'standards poller: no GitHub token (GH_TOKEN, GITHUB_TOKEN, or gh auth); the poller
|
|
74
|
+
'standards poller: no GitHub token (GH_TOKEN, GITHUB_TOKEN, or gh auth); the poller and its Codex runs cannot collaborate on GitHub anonymously',
|
|
75
|
+
);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!(options.acknowledgeOnly || hasExecutableOnPath('gh'))) {
|
|
79
|
+
console.error(
|
|
80
|
+
'standards poller: gh is required on PATH for authenticated Codex GitHub access',
|
|
64
81
|
);
|
|
65
82
|
return false;
|
|
66
83
|
}
|
package/src/poller-fix-run.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
//
|
|
2
|
-
// precise question, or an explicit failure — never silence. Every transition
|
|
3
|
-
// is written back to GitHub so the next tick (or a human) resumes from there.
|
|
1
|
+
// A maintainer-approved issue becomes a verified draft PR, question, or failure.
|
|
4
2
|
|
|
5
3
|
import { join } from 'node:path';
|
|
6
|
-
import {
|
|
4
|
+
import { hasLabel } from './github-label-identity';
|
|
5
|
+
import { approvalIsCurrent, issueRevision } from './poller-approval';
|
|
7
6
|
import { acquireClaim } from './poller-claim';
|
|
8
7
|
import { runCodex } from './poller-codex';
|
|
9
8
|
import { handleNonFixedOutcome } from './poller-fix-outcome';
|
|
@@ -55,29 +54,49 @@ const hasInvalidLocalOutput = (
|
|
|
55
54
|
branch: string,
|
|
56
55
|
): boolean => sealed === null && localBranchExists(cloneDir, branch);
|
|
57
56
|
|
|
57
|
+
const result = (issueNumber: number, message: string): JobResult => ({
|
|
58
|
+
lines: [`#${issueNumber}: ${message}`],
|
|
59
|
+
ranCodex: false,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const assertSealedOwnership = (
|
|
63
|
+
sealed: NonNullable<ReturnType<typeof readSealedFixOutput>>,
|
|
64
|
+
issueNumber: number,
|
|
65
|
+
approvalId: string,
|
|
66
|
+
branch: string,
|
|
67
|
+
): void => {
|
|
68
|
+
if (sealed.issueNumber !== issueNumber || sealed.approvalId !== approvalId) {
|
|
69
|
+
throw new Error(`sealed output on ${branch} has invalid ownership`);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
58
73
|
export const runFixJob = async (
|
|
59
74
|
deps: JobDeps,
|
|
60
75
|
issue: IssueItem,
|
|
61
|
-
|
|
76
|
+
resolveDefaultBranch: () => Promise<string>,
|
|
62
77
|
allowCodex = true,
|
|
63
78
|
): Promise<JobResult> => {
|
|
64
79
|
const { config, token, repo } = deps;
|
|
65
80
|
const currentIssue = await getIssue(token, repo, issue.number);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
issueRevision(
|
|
71
|
-
|
|
81
|
+
if (!hasLabel(currentIssue.labels, APPROVED_FOR_FIX)) {
|
|
82
|
+
return result(issue.number, 'approval no longer present; skipped');
|
|
83
|
+
}
|
|
84
|
+
const readTarget = async (): Promise<string> =>
|
|
85
|
+
issueRevision(await getIssue(token, repo, issue.number));
|
|
86
|
+
const preamble = await jobPreamble(deps, currentIssue, FIX_LABELS, {
|
|
87
|
+
approved: issueRevision(currentIssue),
|
|
88
|
+
readCurrent: readTarget,
|
|
89
|
+
});
|
|
90
|
+
if (preamble.kind === 'stale') {
|
|
91
|
+
return result(issue.number, 'approval no longer present; skipped');
|
|
92
|
+
}
|
|
72
93
|
if (preamble.kind === 'rejected') {
|
|
73
|
-
return
|
|
94
|
+
return result(issue.number, 'approval rejected');
|
|
74
95
|
}
|
|
75
96
|
if (preamble.kind === 'waiting') {
|
|
76
|
-
return
|
|
77
|
-
lines: [`#${issue.number}: waiting on an answer`],
|
|
78
|
-
ranCodex: false,
|
|
79
|
-
};
|
|
97
|
+
return result(issue.number, 'waiting on an answer');
|
|
80
98
|
}
|
|
99
|
+
const defaultBranch = await resolveDefaultBranch();
|
|
81
100
|
const cacheClone = ensureCacheClone(config.cacheDir, repo, token);
|
|
82
101
|
const branch = branchNameForIssue(issue.number, preamble.approval.id);
|
|
83
102
|
const sealed = readSealedFixOutput(cacheClone, branch);
|
|
@@ -86,12 +105,18 @@ export const runFixJob = async (
|
|
|
86
105
|
`refusing to overwrite ${branch}: it is not valid sealed output for this approval`,
|
|
87
106
|
);
|
|
88
107
|
}
|
|
108
|
+
if (
|
|
109
|
+
!(await approvalIsCurrent(
|
|
110
|
+
{ token, repo, issueNumber: issue.number },
|
|
111
|
+
preamble.approval,
|
|
112
|
+
readTarget,
|
|
113
|
+
))
|
|
114
|
+
) {
|
|
115
|
+
return result(issue.number, 'approval generation changed; skipped');
|
|
116
|
+
}
|
|
89
117
|
if (sealed === null && !allowCodex) {
|
|
90
118
|
await acknowledgeQueuedJob(deps, issue.number, preamble.approval, 'fix');
|
|
91
|
-
return
|
|
92
|
-
lines: [`#${issue.number}: waiting for run capacity`],
|
|
93
|
-
ranCodex: false,
|
|
94
|
-
};
|
|
119
|
+
return result(issue.number, 'waiting for run capacity');
|
|
95
120
|
}
|
|
96
121
|
await addLabels(token, repo, issue.number, [FIX_IN_PROGRESS]);
|
|
97
122
|
const claim = await acquireClaim(
|
|
@@ -100,10 +125,7 @@ export const runFixJob = async (
|
|
|
100
125
|
FIX_IN_PROGRESS,
|
|
101
126
|
);
|
|
102
127
|
if (claim === null) {
|
|
103
|
-
return
|
|
104
|
-
lines: [`#${issue.number}: another poller owns the claim`],
|
|
105
|
-
ranCodex: false,
|
|
106
|
-
};
|
|
128
|
+
return result(issue.number, 'another poller owns the claim');
|
|
107
129
|
}
|
|
108
130
|
const resumableJob = {
|
|
109
131
|
deps,
|
|
@@ -114,12 +136,7 @@ export const runFixJob = async (
|
|
|
114
136
|
cloneDir: cacheClone,
|
|
115
137
|
};
|
|
116
138
|
if (sealed !== null) {
|
|
117
|
-
|
|
118
|
-
sealed.issueNumber !== issue.number ||
|
|
119
|
-
sealed.approvalId !== claim.approval.id
|
|
120
|
-
) {
|
|
121
|
-
throw new Error(`sealed output on ${branch} has invalid ownership`);
|
|
122
|
-
}
|
|
139
|
+
assertSealedOwnership(sealed, issue.number, claim.approval.id, branch);
|
|
123
140
|
return {
|
|
124
141
|
lines: [await publishFixedOutput(resumableJob, FIX_LABELS, sealed, null)],
|
|
125
142
|
ranCodex: false,
|
|
@@ -149,6 +166,7 @@ export const runFixJob = async (
|
|
|
149
166
|
issueNumber: issue.number,
|
|
150
167
|
title: currentIssue.title,
|
|
151
168
|
body: currentIssue.body,
|
|
169
|
+
approvalId: claim.approval.id,
|
|
152
170
|
answers: preamble.answers,
|
|
153
171
|
}),
|
|
154
172
|
config,
|
package/src/poller-github.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
// Read-side GitHub helpers
|
|
2
|
-
// narrow parsed shape or throws with the failing endpoint in the message; the
|
|
3
|
-
// tick converts per-job throws into reported problems. Lists are always read
|
|
4
|
-
// exhaustively (see github-paginate.ts) — the trust anchor is "the latest
|
|
5
|
-
// label event", which a truncated page would silently falsify.
|
|
1
|
+
// Read-side GitHub helpers return narrow parsed shapes or throw.
|
|
6
2
|
|
|
7
3
|
import { apiError, HTTP_OK, request } from './github-api';
|
|
8
|
-
import { labelIdentity } from './github-label-identity';
|
|
4
|
+
import { hasLabel, labelIdentity } from './github-label-identity';
|
|
9
5
|
import { listAllPages } from './github-paginate';
|
|
10
6
|
import { isNonEmptyString, isRecord } from './github-settings-parse';
|
|
11
7
|
|
|
@@ -34,23 +30,32 @@ export type LabelEvent = {
|
|
|
34
30
|
const asString = (value: unknown): string =>
|
|
35
31
|
typeof value === 'string' ? value : '';
|
|
36
32
|
|
|
37
|
-
const labelNames = (raw: unknown): ReadonlyArray<string> =>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
const labelNames = (raw: unknown): ReadonlyArray<string> | null => {
|
|
34
|
+
if (
|
|
35
|
+
!(
|
|
36
|
+
Array.isArray(raw) &&
|
|
37
|
+
raw.every((label) => isRecord(label) && isNonEmptyString(label.name))
|
|
38
|
+
)
|
|
39
|
+
) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return raw.map((label) => (label as { readonly name: string }).name);
|
|
43
|
+
};
|
|
43
44
|
|
|
44
45
|
export const parseIssue = (raw: unknown): IssueItem | null => {
|
|
45
46
|
if (!(isRecord(raw) && typeof raw.number === 'number')) {
|
|
46
47
|
return null;
|
|
47
48
|
}
|
|
49
|
+
const labels = labelNames(raw.labels);
|
|
50
|
+
if (labels === null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
48
53
|
return {
|
|
49
54
|
number: raw.number,
|
|
50
55
|
title: asString(raw.title),
|
|
51
56
|
body: asString(raw.body),
|
|
52
57
|
isPullRequest: isRecord(raw.pull_request),
|
|
53
|
-
labels
|
|
58
|
+
labels,
|
|
54
59
|
authorLogin: isRecord(raw.user) ? asString(raw.user.login) : '',
|
|
55
60
|
};
|
|
56
61
|
};
|
|
@@ -82,9 +87,15 @@ export const listOpenIssuesWithLabel = async (
|
|
|
82
87
|
`/repos/${repo}/issues?state=open&labels=${encodeURIComponent(label)}`,
|
|
83
88
|
`list ${repo} issues labeled ${label}`,
|
|
84
89
|
);
|
|
85
|
-
return items
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
return items.flatMap((raw, index) => {
|
|
91
|
+
const issue = parseIssue(raw);
|
|
92
|
+
if (issue === null) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`list ${repo} issues labeled ${label}: invalid issue at index ${index}`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return hasLabel(issue.labels, label) ? [issue] : [];
|
|
98
|
+
});
|
|
88
99
|
};
|
|
89
100
|
|
|
90
101
|
export const listIssueComments = async (
|
|
@@ -151,9 +162,7 @@ export const lastLabelEvent = async (
|
|
|
151
162
|
return latest;
|
|
152
163
|
};
|
|
153
164
|
|
|
154
|
-
// role_name
|
|
155
|
-
// collapses both to "write" and cannot express the trust boundary. A 404
|
|
156
|
-
// means "not a collaborator" — an untrusted answer, not an API failure.
|
|
165
|
+
// role_name preserves the maintain/write trust boundary. A 404 is untrusted.
|
|
157
166
|
export const collaboratorRole = async (
|
|
158
167
|
token: string | null,
|
|
159
168
|
repo: string,
|
package/src/poller-job-shared.ts
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
// approval/progress/failure labels the job family uses.
|
|
4
4
|
|
|
5
5
|
import { hasLabel } from './github-label-identity';
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
type ApprovalBinding,
|
|
8
|
+
type ApprovalTargetReader,
|
|
9
|
+
approvalIsCurrent,
|
|
10
|
+
readApprovalBinding,
|
|
11
|
+
} from './poller-approval';
|
|
7
12
|
import type { PollerConfig } from './poller-config';
|
|
8
13
|
import { addLabels, createComment, removeLabel } from './poller-github-write';
|
|
9
14
|
import {
|
|
@@ -31,11 +36,17 @@ export type JobLabels = {
|
|
|
31
36
|
readonly failed: string;
|
|
32
37
|
};
|
|
33
38
|
|
|
39
|
+
type JobTarget = {
|
|
40
|
+
readonly approved: string;
|
|
41
|
+
readonly readCurrent: ApprovalTargetReader;
|
|
42
|
+
};
|
|
43
|
+
|
|
34
44
|
// Must exceed runCodex's failure string at its longest (its stderr snippet
|
|
35
45
|
// plus the exit-cause prefix), so the diagnostic tail is never cut off.
|
|
36
46
|
const FAILURE_SNIPPET_LIMIT = 4000;
|
|
37
47
|
|
|
38
48
|
export type JobPreamble =
|
|
49
|
+
| { readonly kind: 'stale' }
|
|
39
50
|
| { readonly kind: 'rejected' }
|
|
40
51
|
| { readonly kind: 'waiting' }
|
|
41
52
|
| {
|
|
@@ -51,7 +62,7 @@ export const jobPreamble = async (
|
|
|
51
62
|
deps: JobDeps,
|
|
52
63
|
item: { readonly number: number; readonly labels: ReadonlyArray<string> },
|
|
53
64
|
labels: JobLabels,
|
|
54
|
-
target:
|
|
65
|
+
target: JobTarget,
|
|
55
66
|
): Promise<JobPreamble> => {
|
|
56
67
|
const trust = {
|
|
57
68
|
token: deps.token,
|
|
@@ -59,18 +70,44 @@ export const jobPreamble = async (
|
|
|
59
70
|
issueNumber: item.number,
|
|
60
71
|
roleCache: deps.roleCache,
|
|
61
72
|
};
|
|
62
|
-
const approval = await readApprovalBinding(
|
|
63
|
-
|
|
73
|
+
const approval = await readApprovalBinding(
|
|
74
|
+
trust,
|
|
75
|
+
labels.approved,
|
|
76
|
+
target.approved,
|
|
77
|
+
);
|
|
78
|
+
if (approval.kind === 'absent') {
|
|
79
|
+
return { kind: 'stale' };
|
|
80
|
+
}
|
|
81
|
+
if (approval.kind === 'rejected') {
|
|
82
|
+
const current = await readApprovalBinding(
|
|
83
|
+
trust,
|
|
84
|
+
labels.approved,
|
|
85
|
+
target.approved,
|
|
86
|
+
);
|
|
87
|
+
if (
|
|
88
|
+
current.kind !== 'rejected' ||
|
|
89
|
+
current.generationId !== approval.generationId
|
|
90
|
+
) {
|
|
91
|
+
return { kind: 'stale' };
|
|
92
|
+
}
|
|
93
|
+
if ((await target.readCurrent()) !== target.approved) {
|
|
94
|
+
return { kind: 'stale' };
|
|
95
|
+
}
|
|
64
96
|
await removeLabel(deps.token, deps.repo, item.number, labels.approved);
|
|
65
97
|
await createComment(
|
|
66
98
|
deps.token,
|
|
67
99
|
deps.repo,
|
|
68
100
|
item.number,
|
|
69
|
-
`${FAILURE_MARKER}\nApproval not honored: ${approval}`,
|
|
101
|
+
`${FAILURE_MARKER}\nApproval not honored: ${approval.reason}`,
|
|
70
102
|
);
|
|
71
103
|
return { kind: 'rejected' };
|
|
72
104
|
}
|
|
73
105
|
const answers = await answerState(trust);
|
|
106
|
+
if (
|
|
107
|
+
!(await approvalIsCurrent(trust, approval.approval, target.readCurrent))
|
|
108
|
+
) {
|
|
109
|
+
return { kind: 'stale' };
|
|
110
|
+
}
|
|
74
111
|
if (answers.waiting) {
|
|
75
112
|
if (!hasLabel(item.labels, NEEDS_CLARIFICATION)) {
|
|
76
113
|
await addLabels(deps.token, deps.repo, item.number, [
|
|
@@ -83,7 +120,11 @@ export const jobPreamble = async (
|
|
|
83
120
|
if (hasLabel(item.labels, NEEDS_CLARIFICATION)) {
|
|
84
121
|
await removeLabel(deps.token, deps.repo, item.number, NEEDS_CLARIFICATION);
|
|
85
122
|
}
|
|
86
|
-
return {
|
|
123
|
+
return {
|
|
124
|
+
kind: 'go',
|
|
125
|
+
answers: answers.answers,
|
|
126
|
+
approval: approval.approval,
|
|
127
|
+
};
|
|
87
128
|
};
|
|
88
129
|
|
|
89
130
|
export const failJob = async (
|