@attalabs/vinaya 0.31.0 → 0.33.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/README.md +2 -3
- package/aeg-root/contracts/principal-operator.md +18 -5
- package/aeg-root/roles/developer/reference.md +3 -3
- package/aeg-root/roles/operator.md +69 -16
- package/aeg-root/roles/planner/reference.md +1 -1
- package/aeg-root/roles/tranche-archivist.md +1 -0
- package/aeg-root/skills/aeg-context-packets/SKILL.md +1 -1
- package/aeg-root/skills/aeg-context-packets/examples/operator-start.md +1 -1
- package/aeg-root/templates/pr-report-template.md +7 -2
- package/dist/checks/bin/check-body-bare-digits.js +340 -101
- package/dist/checks/bin/check-branch-topology.js +184 -105
- package/dist/checks/bin/check-brief-shape.js +333 -94
- package/dist/checks/bin/check-changeset-coverage.js +1028 -248
- package/dist/checks/bin/check-ci-shard-coverage.js +82 -0
- package/dist/checks/bin/check-closes-n.js +184 -105
- package/dist/checks/bin/check-coherence.js +345 -145
- package/dist/checks/bin/check-dead-branch-push.js +179 -59
- package/dist/checks/bin/check-dispatch-readiness.js +350 -150
- package/dist/checks/bin/check-doc-coverage-push.js +1011 -231
- package/dist/checks/bin/check-doc-coverage.js +1015 -235
- package/dist/checks/bin/check-doctrine-no-procedures.js +333 -94
- package/dist/checks/bin/check-doctrine-portability.js +1013 -233
- package/dist/checks/bin/check-evidence-fresh.js +1010 -222
- package/dist/checks/bin/check-exec-bits.js +1009 -229
- package/dist/checks/bin/check-first-push-dispatch.js +343 -145
- package/dist/checks/bin/check-issue-assignment.js +186 -107
- package/dist/checks/bin/check-issue-milestone-attach.js +176 -56
- package/dist/checks/bin/check-issue-objectives-numbering.js +176 -56
- package/dist/checks/bin/check-issue-parts-coverage.js +176 -56
- package/dist/checks/bin/check-issue-surface-globs.js +363 -143
- package/dist/checks/bin/check-issue-title-grammar.js +176 -56
- package/dist/checks/bin/check-issue-tranche-label.js +176 -56
- package/dist/checks/bin/check-main-branch-refusal.js +176 -56
- package/dist/checks/bin/check-no-disk-state.js +176 -56
- package/dist/checks/bin/check-pr-premise-reassert.js +333 -92
- package/dist/checks/bin/check-pr-report-density.js +176 -56
- package/dist/checks/bin/check-principal-test-plan-wait.js +176 -54
- package/dist/checks/bin/check-quoted-command.js +999 -217
- package/dist/checks/bin/check-reader-resolvable-prose.js +1011 -229
- package/dist/checks/bin/check-registry-gates.js +186 -56
- package/dist/checks/bin/check-retired-vocabulary.js +997 -215
- package/dist/checks/bin/check-review-gate.js +403 -203
- package/dist/checks/bin/check-single-plan-pr.js +176 -56
- package/dist/checks/bin/check-surface-scope.js +184 -105
- package/dist/checks/bin/check-test-plan.js +176 -54
- package/dist/checks/bin/check-token-collection-wired.js +182 -57
- package/dist/checks/bin/check-token-report.js +178 -58
- package/dist/checks/bin/check-workspace-escape.js +1011 -229
- package/dist/index.js +5971 -3489
- package/dist/lib/pre-push-cache-test-run.js +4431 -0
- package/dist/lib/pre-push-select-tests.js +799 -110
- package/package.json +3 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/actions.ts +10 -12
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +5 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/archive-task.ts +42 -17
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/baseline-capture.ts +1 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/branch-topology-gate.ts +3 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +554 -95
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +264 -44
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/claude-code-transcript.ts +9 -9
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +211 -30
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/consumer-enumeration.ts +2 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +75 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +961 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/migration.ts +212 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/outcomes.ts +135 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +394 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-audit.ts +1 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dead-branch-push-guard.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/derive-section7.ts +2 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +514 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +110 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +27 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +123 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +27 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +240 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/diagram-model.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/direct-main-push.ts +1 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +65 -22
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-claim.ts +238 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doc-owners.ts +14 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/docs-coherence.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/legacy-anchors.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/node-route.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/surfaced-manifest.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-no-procedures.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +5 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ensure-label.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/first-push-dispatch-gate.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +14 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +379 -11
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +3 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +1450 -33
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +1 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/local-anchor-coverage.ts +2 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +119 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +75 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/redact.ts +87 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +801 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +373 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +2 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/metering-io-guard.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/milestone-validation.ts +2 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/no-disk-state.ts +2 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/objectives.ts +288 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-token-report.ts +3 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/parse-tranche.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +30 -16
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-tier.ts +17 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/premise-check.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/quoted-command.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +267 -19
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +91 -24
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-scaffold.ts +6 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/report-tokens.ts +4 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +239 -110
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +384 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +184 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +65 -18
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +76 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/single-plan-pr.ts +4 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/state-machine-model.ts +40 -27
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/symbol-collisions.ts +2 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +38 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +488 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +7 -9
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-section.ts +5 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/types.ts +4 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +314 -56
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +2 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/workspace-escape.ts +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/{[externals]__1agj1ww._.js → [externals]__0cki-x_._.js} +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +6 -6
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/1q96_modules_@clerk_nextjs_dist_esm_app-router_client_keyless-creator-reader_0lom2js.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +3 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__0r7e54g._.js → [root-of-the-server]__18paley._.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1r47dr7._.js → _08onyya._.js} +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0y1jv16._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_15gdg48._.js +5 -5
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/node_modules_@clerk_nextjs_dist_esm_app-router_server-actions_1x7vfhn.js +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bjnj-5fy4e7l.js +1 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1dc2_-c_gavj1.js → 1ce2dj27_cgbj.js} +4 -4
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3xg6-flovrcx-.js → 22s44f5k3ecmj.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/34hhdtbp20krb.js +1 -0
- package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0hstap0._.js +0 -3
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/2t_rfsztmwu6y.js +0 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3ua4rm5f-a9k6.js +0 -1
- /package/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/{aeg-core → vinaya/studio-standalone/_node_modules/@attalabs/aeg-core}/bin/verify-coherence.ts +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_buildManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_clientMiddlewareManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{e8XbZ2vlVz40KzHmlqhwP → vl7QVqELe1AQ-9kaOd9mR}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,4431 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/lib/pre-push-cache-test-run.ts
|
|
4
|
+
import { readFileSync as readFileSync8 } from "node:fs";
|
|
5
|
+
|
|
6
|
+
// src/lib/pr-report-engine.ts
|
|
7
|
+
import { execFile as execFile6 } from "node:child_process";
|
|
8
|
+
import { createHash as createHash2, randomUUID as randomUUID3 } from "node:crypto";
|
|
9
|
+
import {
|
|
10
|
+
closeSync as closeSync5,
|
|
11
|
+
constants as fsConstants5,
|
|
12
|
+
existsSync as existsSync8,
|
|
13
|
+
fsyncSync as fsyncSync2,
|
|
14
|
+
lstatSync as lstatSync3,
|
|
15
|
+
mkdtempSync,
|
|
16
|
+
openSync as openSync5,
|
|
17
|
+
readFileSync as readFileSync7,
|
|
18
|
+
renameSync as renameSync4,
|
|
19
|
+
rmSync,
|
|
20
|
+
writeFileSync as writeFileSync3,
|
|
21
|
+
writeSync as writeSync4
|
|
22
|
+
} from "node:fs";
|
|
23
|
+
import { hostname, tmpdir } from "node:os";
|
|
24
|
+
import { dirname as dirname7, join as join9, resolve as resolvePath2 } from "node:path";
|
|
25
|
+
import { promisify as promisify6 } from "node:util";
|
|
26
|
+
// ../../packages/aeg-forge-state/src/gh.ts
|
|
27
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
28
|
+
import { promisify } from "node:util";
|
|
29
|
+
var execFileAsync = promisify(execFile);
|
|
30
|
+
var systemEnv = {
|
|
31
|
+
...process.env,
|
|
32
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// ../../packages/aeg-forge-state/src/labels.ts
|
|
36
|
+
var LABELS = [
|
|
37
|
+
{
|
|
38
|
+
key: "blocked",
|
|
39
|
+
id: "vinaya/blocked",
|
|
40
|
+
category: "state",
|
|
41
|
+
form: "literal",
|
|
42
|
+
carries: "Execution is halted pending an external unblock; wins over every other derived status."
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
key: "backlog",
|
|
46
|
+
id: "vinaya/backlog",
|
|
47
|
+
category: "state",
|
|
48
|
+
form: "literal",
|
|
49
|
+
carries: "The Issue is deliberately unplanned — belongs to no tranche and is excluded from dispatch, until a Planner promotes it."
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
key: "tier-0",
|
|
53
|
+
id: "vinaya/tier:0",
|
|
54
|
+
category: "tier",
|
|
55
|
+
form: "literal",
|
|
56
|
+
carries: "Lowest governance weight — typecheck, lint, tests, and a conforming PR body."
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
key: "tier-1",
|
|
60
|
+
id: "vinaya/tier:1",
|
|
61
|
+
category: "tier",
|
|
62
|
+
form: "literal",
|
|
63
|
+
carries: "Tier 0 plus spec/skill coverage and a passing verify-docs run."
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: "tier-3",
|
|
67
|
+
id: "vinaya/tier:3",
|
|
68
|
+
category: "tier",
|
|
69
|
+
form: "literal",
|
|
70
|
+
carries: "Tier 1 plus the reasoning for the change, stated in the pull request that makes it."
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
key: "tranche",
|
|
74
|
+
id: "vinaya/tranche:",
|
|
75
|
+
category: "tranche",
|
|
76
|
+
form: "prefix",
|
|
77
|
+
carries: "The tranche slug this task Issue belongs to — the forge's grouping key, matched by prefix."
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
key: "needs-execution-input",
|
|
81
|
+
id: "vinaya/needs:execution-input",
|
|
82
|
+
category: "needs",
|
|
83
|
+
form: "literal",
|
|
84
|
+
carries: "Waiting on a missing execution detail — a flag, a dependency, a value the brief did not carry."
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
key: "needs-strategy-input",
|
|
88
|
+
id: "vinaya/needs:strategy-input",
|
|
89
|
+
category: "needs",
|
|
90
|
+
form: "literal",
|
|
91
|
+
carries: "Waiting on a strategy call — the brief assumes an approach the codebase has moved away from."
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: "needs-principal-input",
|
|
95
|
+
id: "vinaya/needs:principal-input",
|
|
96
|
+
category: "needs",
|
|
97
|
+
form: "literal",
|
|
98
|
+
carries: "Waiting on the Principal — a product-level call no agent may make."
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
key: "needs-brief-correction",
|
|
102
|
+
id: "vinaya/needs:brief-correction",
|
|
103
|
+
category: "needs",
|
|
104
|
+
form: "literal",
|
|
105
|
+
carries: "Waiting on the Planner — the brief contradicts the surface it describes."
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
key: "waiver-docs",
|
|
109
|
+
id: "vinaya/waiver:docs",
|
|
110
|
+
category: "waiver",
|
|
111
|
+
form: "literal",
|
|
112
|
+
carries: "Doc-coverage gate excused for this PR — honored only when a principal applied it."
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
key: "waiver-review",
|
|
116
|
+
id: "vinaya/waiver:review",
|
|
117
|
+
category: "waiver",
|
|
118
|
+
form: "literal",
|
|
119
|
+
carries: "Review gate excused for this PR — honored only when a principal applied it."
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
key: "override-docs",
|
|
123
|
+
id: "vinaya/override:docs",
|
|
124
|
+
category: "waiver",
|
|
125
|
+
form: "literal",
|
|
126
|
+
carries: "The whole verify-docs gate suppressed for this PR — a Principal-only blunt override, wider than a waiver."
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
key: "incoherent",
|
|
130
|
+
id: "vinaya/incoherent",
|
|
131
|
+
category: "flag",
|
|
132
|
+
form: "literal",
|
|
133
|
+
carries: "Closed COMPLETED with no merged-PR link — done-but-unprovable, surfaced for a human."
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
key: "direct-main-push",
|
|
137
|
+
id: "vinaya/direct-main-push",
|
|
138
|
+
category: "flag",
|
|
139
|
+
form: "literal",
|
|
140
|
+
carries: "A commit reached main with no associated merged PR — ring-2 detection, never a mutation."
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
key: "dead-branch-push",
|
|
144
|
+
id: "vinaya/dead-branch-push",
|
|
145
|
+
category: "flag",
|
|
146
|
+
form: "literal",
|
|
147
|
+
carries: "Commits landed on a branch after its PR had already resolved — daily-drift detection."
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
key: "state-object",
|
|
151
|
+
id: "vinaya/state-object",
|
|
152
|
+
category: "kind",
|
|
153
|
+
form: "literal",
|
|
154
|
+
carries: "A permanent forge-native storage object, never actionable work — excluded from every backlog."
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
key: "type-build",
|
|
158
|
+
id: "vinaya/type:build",
|
|
159
|
+
category: "type",
|
|
160
|
+
form: "literal",
|
|
161
|
+
carries: "The task changes the build system, packaging, or an external dependency rather than product behavior."
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
key: "type-chore",
|
|
165
|
+
id: "vinaya/type:chore",
|
|
166
|
+
category: "type",
|
|
167
|
+
form: "literal",
|
|
168
|
+
carries: "The task is maintenance or repo housekeeping with no functional, user-facing change."
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
key: "type-docs",
|
|
172
|
+
id: "vinaya/type:docs",
|
|
173
|
+
category: "type",
|
|
174
|
+
form: "literal",
|
|
175
|
+
carries: "The task changes documentation only, with no code behavior affected."
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
key: "type-feat",
|
|
179
|
+
id: "vinaya/type:feat",
|
|
180
|
+
category: "type",
|
|
181
|
+
form: "literal",
|
|
182
|
+
carries: "The task adds a capability that did not exist before."
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
key: "type-fix",
|
|
186
|
+
id: "vinaya/type:fix",
|
|
187
|
+
category: "type",
|
|
188
|
+
form: "literal",
|
|
189
|
+
carries: "The task corrects incorrect behavior — a bug, not a missing capability."
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
key: "type-perf",
|
|
193
|
+
id: "vinaya/type:perf",
|
|
194
|
+
category: "type",
|
|
195
|
+
form: "literal",
|
|
196
|
+
carries: "The task improves performance or resource use without changing observable behavior."
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
key: "type-refactor",
|
|
200
|
+
id: "vinaya/type:refactor",
|
|
201
|
+
category: "type",
|
|
202
|
+
form: "literal",
|
|
203
|
+
carries: "The task restructures existing code without changing its external behavior."
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
key: "type-revert",
|
|
207
|
+
id: "vinaya/type:revert",
|
|
208
|
+
category: "type",
|
|
209
|
+
form: "literal",
|
|
210
|
+
carries: "The task undoes a previous change that shipped in error or is no longer wanted."
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
key: "type-style",
|
|
214
|
+
id: "vinaya/type:style",
|
|
215
|
+
category: "type",
|
|
216
|
+
form: "literal",
|
|
217
|
+
carries: "The task changes formatting, naming, or non-semantic code shape with no logic change."
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
key: "type-test",
|
|
221
|
+
id: "vinaya/type:test",
|
|
222
|
+
category: "type",
|
|
223
|
+
form: "literal",
|
|
224
|
+
carries: "The task adds or corrects test coverage with no production-code behavior change."
|
|
225
|
+
}
|
|
226
|
+
];
|
|
227
|
+
var BY_KEY = new Map(LABELS.map((l) => [l.key, l]));
|
|
228
|
+
function entry(key) {
|
|
229
|
+
const found = BY_KEY.get(key);
|
|
230
|
+
if (!found)
|
|
231
|
+
throw new Error(`labels.ts: no LABELS entry for key '${key}'`);
|
|
232
|
+
return found;
|
|
233
|
+
}
|
|
234
|
+
function label(key) {
|
|
235
|
+
return entry(key).id;
|
|
236
|
+
}
|
|
237
|
+
// ../../packages/aeg-forge-state/src/github-token.ts
|
|
238
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
239
|
+
import { promisify as promisify2 } from "node:util";
|
|
240
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
241
|
+
var systemEnv2 = {
|
|
242
|
+
...process.env,
|
|
243
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
244
|
+
};
|
|
245
|
+
// ../../packages/aeg-forge-state/src/resolve-repo.ts
|
|
246
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
247
|
+
import { promisify as promisify3 } from "node:util";
|
|
248
|
+
var execFileAsync3 = promisify3(execFile3);
|
|
249
|
+
var systemEnv3 = {
|
|
250
|
+
...process.env,
|
|
251
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
252
|
+
};
|
|
253
|
+
var defaultExec = () => execFileAsync3("git", ["remote", "get-url", "origin"], { env: systemEnv3, timeout: 5000 });
|
|
254
|
+
var cached;
|
|
255
|
+
var inflight;
|
|
256
|
+
async function resolveRepo(exec = defaultExec) {
|
|
257
|
+
if (cached !== undefined)
|
|
258
|
+
return cached;
|
|
259
|
+
const fromEnv = process.env.AEG_REPO;
|
|
260
|
+
if (fromEnv) {
|
|
261
|
+
const parsed = parseOwnerRepo(fromEnv);
|
|
262
|
+
if (parsed) {
|
|
263
|
+
cached = parsed;
|
|
264
|
+
return cached;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
if (inflight)
|
|
268
|
+
return inflight;
|
|
269
|
+
inflight = (async () => {
|
|
270
|
+
try {
|
|
271
|
+
const { stdout } = await exec();
|
|
272
|
+
cached = parseGitRemoteUrl(stdout.trim());
|
|
273
|
+
return cached;
|
|
274
|
+
} catch (err) {
|
|
275
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
276
|
+
console.warn(`[aeg-forge-state] resolveRepo: git remote lookup failed (will retry): ${message}`);
|
|
277
|
+
return null;
|
|
278
|
+
} finally {
|
|
279
|
+
inflight = undefined;
|
|
280
|
+
}
|
|
281
|
+
})();
|
|
282
|
+
return inflight;
|
|
283
|
+
}
|
|
284
|
+
function parseGitRemoteUrl(url) {
|
|
285
|
+
const ssh = url.match(/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/);
|
|
286
|
+
if (ssh?.[1] && ssh[2])
|
|
287
|
+
return { owner: ssh[1], repo: ssh[2] };
|
|
288
|
+
const https = url.match(/^https?:\/\/(?:[^@]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
289
|
+
if (https?.[1] && https[2])
|
|
290
|
+
return { owner: https[1], repo: https[2] };
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
function parseOwnerRepo(value) {
|
|
294
|
+
const match = value.match(/^([^/]+)\/(.+)$/);
|
|
295
|
+
if (!match?.[1] || !match[2])
|
|
296
|
+
return null;
|
|
297
|
+
return { owner: match[1], repo: match[2] };
|
|
298
|
+
}
|
|
299
|
+
// ../../packages/aeg-core/src/state-machine-model.ts
|
|
300
|
+
var FORGE_FACT_INPUTS = [
|
|
301
|
+
{
|
|
302
|
+
fact: "issueState",
|
|
303
|
+
readsFrom: "Issue.state (OPEN | CLOSED)",
|
|
304
|
+
meaning: "Whether the task Issue is still open — the anchor for the honest terminal statuses."
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
fact: "assigned",
|
|
308
|
+
readsFrom: "Issue.assignees (count > 0)",
|
|
309
|
+
meaning: "An assignee exists. No longer affects derivation: assigned and unassigned are both todo."
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
fact: "branchExists",
|
|
313
|
+
readsFrom: "Ref refs/heads/task/<tranche>/<id>",
|
|
314
|
+
meaning: "A task branch has been published — the todo → in-flight transition, written by git push, not by hand."
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
fact: "prState",
|
|
318
|
+
readsFrom: "PullRequest.state (OPEN | CLOSED | MERGED)",
|
|
319
|
+
meaning: "Whether work is proposed or landed. CLOSED-without-merge collapses to none — AEG models open/merged/none."
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
fact: "reviewDecision",
|
|
323
|
+
readsFrom: "PullRequest.reviewDecision",
|
|
324
|
+
meaning: "Only 'changes_requested' flips status; approved-but-unmerged stays in-review."
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
fact: "blockedLabel",
|
|
328
|
+
readsFrom: `Issue.labels contains '${label("blocked")}'`,
|
|
329
|
+
meaning: "Execution halted pending an external unblock. Wins over every other rule."
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
fact: "stateReason",
|
|
333
|
+
readsFrom: "Issue.stateReason (COMPLETED | NOT_PLANNED | REOPENED | null)",
|
|
334
|
+
meaning: "Separates a legitimate drop from an incoherent close on a closed, never-merged Issue."
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
fact: "closedAt",
|
|
338
|
+
readsFrom: "Issue.closedAt",
|
|
339
|
+
meaning: "Timestamp for the coherence oracle grandfather cutoff. No derivation rule reads it."
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
fact: "mergedAt",
|
|
343
|
+
readsFrom: "PullRequest.mergedAt",
|
|
344
|
+
meaning: "Timestamp for the coherence oracle grandfather cutoff. No derivation rule reads it."
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
fact: "closedByActor",
|
|
348
|
+
readsFrom: "ClosedEvent.actor.login (most recent timeline CLOSED_EVENT)",
|
|
349
|
+
meaning: "GitHub login that hand-closed the Issue. No task-status derivation rule reads it — it is consumed by dispatch-gate.ts/coherence-checks.ts A1 to recognize a hand-closed dependency as resolved (task vinaya-engine-v1 21, #99), not by this status model."
|
|
350
|
+
}
|
|
351
|
+
];
|
|
352
|
+
var DERIVED_STATUSES = [
|
|
353
|
+
"backlog",
|
|
354
|
+
"todo",
|
|
355
|
+
"in-flight",
|
|
356
|
+
"in-review",
|
|
357
|
+
"changes-requested",
|
|
358
|
+
"merged",
|
|
359
|
+
"blocked",
|
|
360
|
+
"dropped",
|
|
361
|
+
"incoherent"
|
|
362
|
+
];
|
|
363
|
+
var DERIVABLE_STATUSES = DERIVED_STATUSES.filter((s) => s !== "backlog");
|
|
364
|
+
// ../../packages/aeg-core/src/waiver-label.ts
|
|
365
|
+
var WAIVER_LABEL = label("waiver-docs");
|
|
366
|
+
var WAIVER_LABEL_REVIEW = label("waiver-review");
|
|
367
|
+
// ../../packages/aeg-core/src/report-tokens.ts
|
|
368
|
+
var DASH_LOOKALIKES = {
|
|
369
|
+
"-": "‑",
|
|
370
|
+
"–": "‒",
|
|
371
|
+
"—": "―"
|
|
372
|
+
};
|
|
373
|
+
var DASH_CHARS = new Set(Object.keys(DASH_LOOKALIKES));
|
|
374
|
+
// ../../packages/aeg-core/src/metering-io-guard.ts
|
|
375
|
+
import { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync } from "node:fs";
|
|
376
|
+
var GUARD_OPEN_FLAGS = fsConstants.O_RDONLY | fsConstants.O_NONBLOCK | fsConstants.O_NOFOLLOW;
|
|
377
|
+
// ../../packages/aeg-core/src/doc-owners.ts
|
|
378
|
+
function globToRegex(pat) {
|
|
379
|
+
let re = "^";
|
|
380
|
+
let i = 0;
|
|
381
|
+
while (i < pat.length) {
|
|
382
|
+
const c = pat[i];
|
|
383
|
+
if (c === "*") {
|
|
384
|
+
if (pat[i + 1] === "*") {
|
|
385
|
+
re += ".*";
|
|
386
|
+
i += 2;
|
|
387
|
+
} else {
|
|
388
|
+
re += "[^/]*";
|
|
389
|
+
i += 1;
|
|
390
|
+
}
|
|
391
|
+
} else if (/[.+^$|(){}[\]\\?]/.test(c)) {
|
|
392
|
+
re += `\\${c}`;
|
|
393
|
+
i += 1;
|
|
394
|
+
} else {
|
|
395
|
+
re += c;
|
|
396
|
+
i += 1;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
re += "$";
|
|
400
|
+
return new RegExp(re);
|
|
401
|
+
}
|
|
402
|
+
var SEPARATOR = /(?:[ \t]*[—–][ \t]*|[ \t]+-[ \t]+)/.source;
|
|
403
|
+
// ../../packages/aeg-core/src/pr-tier.ts
|
|
404
|
+
var OVERRIDE_BODY_TOKEN = `[${label("override-docs")}]`;
|
|
405
|
+
// ../../packages/aeg-core/src/premise-check.ts
|
|
406
|
+
var ASSERTION_KINDS = new Set(["contains", "absent", "sha256"]);
|
|
407
|
+
|
|
408
|
+
// ../../packages/aeg-core/src/brief-validation.ts
|
|
409
|
+
var COMMIT_TYPES = [
|
|
410
|
+
"Build",
|
|
411
|
+
"Chore",
|
|
412
|
+
"Docs",
|
|
413
|
+
"Feat",
|
|
414
|
+
"Fix",
|
|
415
|
+
"Perf",
|
|
416
|
+
"Plan",
|
|
417
|
+
"Refactor",
|
|
418
|
+
"Revert",
|
|
419
|
+
"Style",
|
|
420
|
+
"Test"
|
|
421
|
+
];
|
|
422
|
+
var COMMIT_TYPE_STYLE = new RegExp(`^(${COMMIT_TYPES.join("|")})(\\([a-z0-9-]+\\))?: \\S`);
|
|
423
|
+
// ../../packages/aeg-core/src/doctrine-portability.ts
|
|
424
|
+
var EXEMPT_LITERALS = new Set([
|
|
425
|
+
"path/inside/the/shipped/diff.ts",
|
|
426
|
+
"path/inside/the/surface.ts",
|
|
427
|
+
"apps/x/specs/..."
|
|
428
|
+
]);
|
|
429
|
+
var NON_PATH_TOP_SEGMENTS = new Set(["origin", "refs", "HEAD", "vinaya", "fix"]);
|
|
430
|
+
|
|
431
|
+
// ../../packages/aeg-core/src/doctrine-no-procedures.ts
|
|
432
|
+
var SHELL_LANGS = new Set(["", "sh", "bash", "shell", "console"]);
|
|
433
|
+
// ../../packages/aeg-core/src/issue-validation.ts
|
|
434
|
+
var TYPE_LABEL_IDS = LABELS.filter((l) => l.category === "type").map((l) => l.id);
|
|
435
|
+
var DOC_PATH_RE = /(?:(?:aeg-root|apps|packages|specs|docs|tools|\.claude|\.github)\/[\w./@-]*\.(?:md|mdx)|\.claude\/(?:skills|rules)\/[\w./-]+|\b(?:docs-index|decisions|projects|state-machine|enforcement|process|README|CLAUDE)\.md\b|\b[\w-]+-(?:spec|decisions|backlog)\.md\b)/i;
|
|
436
|
+
var DOC_PATH_RE_GLOBAL = new RegExp(DOC_PATH_RE.source, "gi");
|
|
437
|
+
|
|
438
|
+
// ../../packages/aeg-core/src/coherence-checks.ts
|
|
439
|
+
var R1_GRANDFATHERED_ISSUES = new Set([279, 280, 281, 282]);
|
|
440
|
+
// ../../packages/aeg-core/src/diagram-model.ts
|
|
441
|
+
import matter from "gray-matter";
|
|
442
|
+
// ../../packages/aeg-core/src/reader-resolvable-prose.ts
|
|
443
|
+
var SWEPT_CLASSES = new Set(["ships", "reader-facing"]);
|
|
444
|
+
|
|
445
|
+
// ../../packages/aeg-core/src/quoted-command.ts
|
|
446
|
+
var QUOTED_COMMAND_SWEPT_CLASSES = new Set(["ships", "reader-facing"]);
|
|
447
|
+
// ../../packages/aeg-core/src/retired-vocabulary.ts
|
|
448
|
+
var RETIRED_PATTERNS = [
|
|
449
|
+
String.raw`\bD-[0-9]{3}\b`,
|
|
450
|
+
"D-(###|NNN|nnn|xxx)",
|
|
451
|
+
"decision (entry|logged)",
|
|
452
|
+
"decision-log entry",
|
|
453
|
+
"decision log entry",
|
|
454
|
+
"decision log(s|ged|ging)?([^a-z]|$)",
|
|
455
|
+
"decision-log",
|
|
456
|
+
"decision entr",
|
|
457
|
+
"decisions? (are |is )?logged",
|
|
458
|
+
"log entries",
|
|
459
|
+
String.raw`decisions\.md`,
|
|
460
|
+
"decisions-legacy",
|
|
461
|
+
"CONTRADICTION",
|
|
462
|
+
"assumes Tier 3",
|
|
463
|
+
"Lock: ?YES",
|
|
464
|
+
"Lock: ?NO",
|
|
465
|
+
"lock approvals?",
|
|
466
|
+
"approves locks",
|
|
467
|
+
"Conforms to lock",
|
|
468
|
+
"Challenges lock",
|
|
469
|
+
"checkDecisionNumbersFresh",
|
|
470
|
+
String.raw`roles/team-leader\.md`,
|
|
471
|
+
String.raw`\(,`,
|
|
472
|
+
String.raw`,\)`,
|
|
473
|
+
String.raw`\(\.\)`
|
|
474
|
+
];
|
|
475
|
+
var PATTERN_EXEMPT = {
|
|
476
|
+
[String.raw`\bD-[0-9]{3}\b`]: ["./CLAUDE.md"],
|
|
477
|
+
[String.raw`decisions\.md`]: [
|
|
478
|
+
"docs-index.md",
|
|
479
|
+
"apps/vada-ai/specs/legacy/README.md",
|
|
480
|
+
"apps/vada-ai/specs/vada-product-spec.md",
|
|
481
|
+
"apps/vada-ai/web/CLAUDE.md",
|
|
482
|
+
"apps/vada-ai/CLAUDE.md"
|
|
483
|
+
],
|
|
484
|
+
"decisions-legacy": [
|
|
485
|
+
"packages/aeg-core/src/file-classify.ts",
|
|
486
|
+
"packages/aeg-core/src/file-classify.test.ts",
|
|
487
|
+
"packages/aeg-core/src/pr-tier.test.ts",
|
|
488
|
+
"docs-index.md",
|
|
489
|
+
".claude/skills/database/SKILL.md",
|
|
490
|
+
".claude/skills/vada-architecture/SKILL.md",
|
|
491
|
+
"apps/vada-ai/specs/vada-byok-principles.md",
|
|
492
|
+
"apps/vada-ai/web/CLAUDE.md",
|
|
493
|
+
"apps/vada-ai/CLAUDE.md"
|
|
494
|
+
],
|
|
495
|
+
CONTRADICTION: ["apps/vada-ai/specs/vada-reviewers-spec.md"]
|
|
496
|
+
};
|
|
497
|
+
// ../../packages/aeg-core/src/task-tools.ts
|
|
498
|
+
import { z } from "zod";
|
|
499
|
+
var TASK_TOOL_ERROR_KINDS = [
|
|
500
|
+
"validation",
|
|
501
|
+
"authority",
|
|
502
|
+
"precondition",
|
|
503
|
+
"capability",
|
|
504
|
+
"infrastructure",
|
|
505
|
+
"cancellation",
|
|
506
|
+
"timeout",
|
|
507
|
+
"uncertain_effect"
|
|
508
|
+
];
|
|
509
|
+
var TaskToolErrorSchema = z.object({
|
|
510
|
+
kind: z.enum(TASK_TOOL_ERROR_KINDS),
|
|
511
|
+
message: z.string().min(1),
|
|
512
|
+
detail: z.string().optional()
|
|
513
|
+
});
|
|
514
|
+
var TaskToolRefSchema = z.union([
|
|
515
|
+
z.object({ tranche: z.string().min(1), id: z.string().min(1) }).strict(),
|
|
516
|
+
z.object({ issue: z.number().int().positive() }).strict()
|
|
517
|
+
]);
|
|
518
|
+
var MAX_PAGE_LIMIT = 100;
|
|
519
|
+
var PageRequestSchema = z.object({
|
|
520
|
+
cursor: z.string().optional(),
|
|
521
|
+
limit: z.number().int().positive().max(MAX_PAGE_LIMIT).optional()
|
|
522
|
+
});
|
|
523
|
+
var FreshnessSchema = z.enum(["fresh", "stale", "unknown"]);
|
|
524
|
+
var ObservedSchema = z.object({
|
|
525
|
+
observedAt: z.string(),
|
|
526
|
+
freshness: FreshnessSchema
|
|
527
|
+
});
|
|
528
|
+
var TaskStatusInputSchema = z.object({
|
|
529
|
+
task: TaskToolRefSchema.optional()
|
|
530
|
+
}).merge(PageRequestSchema).strict();
|
|
531
|
+
var TaskConfidenceSchema = z.object({
|
|
532
|
+
round: z.number().int().positive(),
|
|
533
|
+
percent: z.number().int().min(0).max(100).nullable(),
|
|
534
|
+
source: z.enum(["stated", "published-summary"])
|
|
535
|
+
}).strict();
|
|
536
|
+
var TaskPhaseHistorySchema = z.object({
|
|
537
|
+
typicalPhaseMinutes: z.number().nonnegative(),
|
|
538
|
+
typicalPhaseSamples: z.number().int().positive()
|
|
539
|
+
}).strict();
|
|
540
|
+
var TaskStatusItemSchema = z.object({
|
|
541
|
+
task: TaskToolRefSchema,
|
|
542
|
+
issue: z.number().int().positive(),
|
|
543
|
+
pr: z.number().int().positive().nullable(),
|
|
544
|
+
state: z.string(),
|
|
545
|
+
round: z.number().int().positive().nullable().optional(),
|
|
546
|
+
phase: z.string().min(1).nullable().optional(),
|
|
547
|
+
minutesInPhase: z.number().nonnegative().nullable().optional(),
|
|
548
|
+
phaseIsCurrent: z.boolean().nullable().optional(),
|
|
549
|
+
lastConfidence: TaskConfidenceSchema.nullable().optional(),
|
|
550
|
+
lastConfidenceUnread: z.boolean().optional(),
|
|
551
|
+
phaseHistory: TaskPhaseHistorySchema.nullable().optional()
|
|
552
|
+
}).merge(ObservedSchema);
|
|
553
|
+
var TaskStatusResultSchema = z.object({
|
|
554
|
+
items: z.array(TaskStatusItemSchema),
|
|
555
|
+
nextCursor: z.string().nullable()
|
|
556
|
+
});
|
|
557
|
+
var RequestedAuthoritySchema = z.enum(["planner", "principal", "operator", "self"]);
|
|
558
|
+
var EscalationInputsSchema = z.object({
|
|
559
|
+
task: z.number().int().positive(),
|
|
560
|
+
round: z.number().int().nonnegative(),
|
|
561
|
+
head: z.string(),
|
|
562
|
+
branch: z.string(),
|
|
563
|
+
prNumber: z.number().int().positive().nullable()
|
|
564
|
+
});
|
|
565
|
+
var EscalationEvidenceSchema = z.object({
|
|
566
|
+
round: z.number().int().nonnegative(),
|
|
567
|
+
reviewer: z.string().nullable(),
|
|
568
|
+
security: z.string().nullable()
|
|
569
|
+
});
|
|
570
|
+
var EscalationRunIdentitySchema = z.object({
|
|
571
|
+
runId: z.string(),
|
|
572
|
+
pid: z.number().int().positive(),
|
|
573
|
+
host: z.string()
|
|
574
|
+
});
|
|
575
|
+
var EscalationInputVersionsSchema = z.object({
|
|
576
|
+
briefHash: z.string().nullable(),
|
|
577
|
+
objectivesVersion: z.string().nullable(),
|
|
578
|
+
rulingOrdinal: z.number().int().nonnegative(),
|
|
579
|
+
policyDigest: z.string()
|
|
580
|
+
});
|
|
581
|
+
var TaskEscalationReadInputSchema = z.object({
|
|
582
|
+
task: TaskToolRefSchema
|
|
583
|
+
}).merge(PageRequestSchema).strict();
|
|
584
|
+
var TaskEscalationPacketSchema = z.object({
|
|
585
|
+
reason: z.string(),
|
|
586
|
+
detail: z.string().nullable(),
|
|
587
|
+
inputs: EscalationInputsSchema.nullable(),
|
|
588
|
+
evidence: EscalationEvidenceSchema.nullable(),
|
|
589
|
+
attemptedRecovery: z.string(),
|
|
590
|
+
requestedAuthority: RequestedAuthoritySchema,
|
|
591
|
+
permittedNextActions: z.array(z.string()),
|
|
592
|
+
runIdentity: EscalationRunIdentitySchema.nullable(),
|
|
593
|
+
inputVersions: EscalationInputVersionsSchema.nullable()
|
|
594
|
+
}).merge(ObservedSchema);
|
|
595
|
+
var TaskEscalationReadResultSchema = z.object({
|
|
596
|
+
items: z.array(TaskEscalationPacketSchema),
|
|
597
|
+
nextCursor: z.string().nullable()
|
|
598
|
+
}).merge(ObservedSchema);
|
|
599
|
+
var TaskPrCheckSchema = z.object({
|
|
600
|
+
name: z.string(),
|
|
601
|
+
required: z.boolean(),
|
|
602
|
+
status: z.string(),
|
|
603
|
+
conclusion: z.string().nullable(),
|
|
604
|
+
detailsUrl: z.string().nullable(),
|
|
605
|
+
failureSummary: z.string().nullable()
|
|
606
|
+
});
|
|
607
|
+
var TaskPrVerdictSchema = z.object({
|
|
608
|
+
role: z.enum(["code-review", "security"]),
|
|
609
|
+
value: z.string(),
|
|
610
|
+
judgedHead: z.string().nullable(),
|
|
611
|
+
objectivesVersion: z.string().nullable()
|
|
612
|
+
});
|
|
613
|
+
var TaskPrPauseSchema = z.object({
|
|
614
|
+
reason: z.string(),
|
|
615
|
+
body: z.string()
|
|
616
|
+
});
|
|
617
|
+
var TaskPrReviewRecordSchema = z.object({
|
|
618
|
+
verdicts: z.array(TaskPrVerdictSchema),
|
|
619
|
+
roundMarkers: z.array(z.number().int().nonnegative()),
|
|
620
|
+
summaryTable: z.string().nullable(),
|
|
621
|
+
pause: TaskPrPauseSchema.nullable()
|
|
622
|
+
});
|
|
623
|
+
var TaskPrReadInputSchema = z.object({
|
|
624
|
+
task: TaskToolRefSchema,
|
|
625
|
+
pr: z.number().int().positive().optional()
|
|
626
|
+
}).strict();
|
|
627
|
+
var TaskPrReadResultSchema = z.object({
|
|
628
|
+
task: TaskToolRefSchema,
|
|
629
|
+
issue: z.number().int().positive(),
|
|
630
|
+
pr: z.number().int().positive(),
|
|
631
|
+
head: z.string().nullable(),
|
|
632
|
+
checks: z.array(TaskPrCheckSchema),
|
|
633
|
+
review: TaskPrReviewRecordSchema
|
|
634
|
+
}).merge(ObservedSchema);
|
|
635
|
+
var TaskStartResultSchema = z.object({
|
|
636
|
+
requestId: z.string().min(1),
|
|
637
|
+
run: TaskToolRefSchema,
|
|
638
|
+
started: z.boolean(),
|
|
639
|
+
startedAt: z.string(),
|
|
640
|
+
mode: z.literal("attended")
|
|
641
|
+
});
|
|
642
|
+
var TaskResumeInputSchema = z.object({
|
|
643
|
+
task: TaskToolRefSchema
|
|
644
|
+
}).strict();
|
|
645
|
+
var TaskCancelInputSchema = z.object({
|
|
646
|
+
task: TaskToolRefSchema,
|
|
647
|
+
reason: z.string().min(1)
|
|
648
|
+
}).strict();
|
|
649
|
+
var TaskResumeResultSchema = z.object({
|
|
650
|
+
task: z.number().int().positive(),
|
|
651
|
+
pr: z.number().int().positive().nullable(),
|
|
652
|
+
escalationId: z.string().min(1),
|
|
653
|
+
outcome: z.enum(["started", "already_resumed"]),
|
|
654
|
+
authenticatedBy: z.string().min(1),
|
|
655
|
+
authenticatedFrom: z.string().min(1)
|
|
656
|
+
});
|
|
657
|
+
var TaskCancelOutcomeSchema = z.enum(["confirmed", "pending", "uncertain"]);
|
|
658
|
+
var TaskCancelResultSchema = z.object({
|
|
659
|
+
task: z.number().int().positive(),
|
|
660
|
+
pr: z.number().int().positive().nullable(),
|
|
661
|
+
escalationId: z.string().min(1),
|
|
662
|
+
outcome: TaskCancelOutcomeSchema,
|
|
663
|
+
authenticatedBy: z.string().min(1),
|
|
664
|
+
authenticatedFrom: z.string().min(1),
|
|
665
|
+
fencedEffectKeys: z.array(z.string())
|
|
666
|
+
});
|
|
667
|
+
var TASK_TOOL_NAMES = [
|
|
668
|
+
"task_start",
|
|
669
|
+
"task_status",
|
|
670
|
+
"task_escalation_read",
|
|
671
|
+
"task_pr_read",
|
|
672
|
+
"task_resume",
|
|
673
|
+
"task_cancel"
|
|
674
|
+
];
|
|
675
|
+
var OPERATOR_STATUS_FOLLOW = "task_status_follow";
|
|
676
|
+
var OPERATOR_TOOL_GRANT = [...TASK_TOOL_NAMES, OPERATOR_STATUS_FOLLOW];
|
|
677
|
+
// ../../packages/aeg-core/src/dev-review-loop/types.ts
|
|
678
|
+
var SEVERITY_COLUMNS = ["blocker", "major", "minor", "critical", "high", "medium", "low"];
|
|
679
|
+
// ../../packages/aeg-core/src/dev-review-loop/journal-reconstruction.ts
|
|
680
|
+
var SUMMARY_TABLE_HEADER = `| round | ${SEVERITY_COLUMNS.join(" | ")} | confidence | outcome |`;
|
|
681
|
+
// ../../packages/aeg-core/src/log/envelope.ts
|
|
682
|
+
import { createHash } from "node:crypto";
|
|
683
|
+
|
|
684
|
+
// ../../packages/aeg-core/src/log/schema.ts
|
|
685
|
+
import { z as z2 } from "zod";
|
|
686
|
+
var CONFIDENCE_REASON_MAX_LENGTH = 280;
|
|
687
|
+
var ROLE_VALUES = [
|
|
688
|
+
"planner",
|
|
689
|
+
"developer",
|
|
690
|
+
"code-reviewer",
|
|
691
|
+
"security",
|
|
692
|
+
"principal",
|
|
693
|
+
"archivist",
|
|
694
|
+
"architect"
|
|
695
|
+
];
|
|
696
|
+
var RoleSchema = z2.enum(ROLE_VALUES);
|
|
697
|
+
var HOST_VALUES = ["hook", "ci", "cli", "loop"];
|
|
698
|
+
var HostSchema = z2.enum(HOST_VALUES);
|
|
699
|
+
var RUN_ID_PATTERN = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
700
|
+
var headerMetaCore = {
|
|
701
|
+
ts: z2.string(),
|
|
702
|
+
run_id: z2.string().regex(RUN_ID_PATTERN),
|
|
703
|
+
seq: z2.number().int().nonnegative(),
|
|
704
|
+
repo: z2.string().nullable(),
|
|
705
|
+
vinaya: z2.string(),
|
|
706
|
+
doctrine: z2.string(),
|
|
707
|
+
host: HostSchema,
|
|
708
|
+
machine: z2.string()
|
|
709
|
+
};
|
|
710
|
+
var HeaderMetaV1Schema = z2.object({
|
|
711
|
+
schema: z2.literal(1),
|
|
712
|
+
...headerMetaCore
|
|
713
|
+
}).strict();
|
|
714
|
+
var LineageSchema = z2.object({
|
|
715
|
+
run: z2.string().nullable(),
|
|
716
|
+
attempt: z2.number().int().nullable(),
|
|
717
|
+
parent: z2.string().nullable()
|
|
718
|
+
}).strict();
|
|
719
|
+
var InputVersionsSchema = z2.object({
|
|
720
|
+
objectives_version: z2.string().nullable(),
|
|
721
|
+
brief_hash: z2.string().nullable(),
|
|
722
|
+
ruling_ordinal: z2.number().int().nullable(),
|
|
723
|
+
policy_digest: z2.string().nullable()
|
|
724
|
+
}).strict();
|
|
725
|
+
var ProvenanceSchema = z2.enum(["parent_attributed", "env_correlated", "self_reported", "unavailable"]);
|
|
726
|
+
var HeaderMetaV2Schema = z2.object({
|
|
727
|
+
schema: z2.literal(2),
|
|
728
|
+
...headerMetaCore,
|
|
729
|
+
event_id: z2.string().min(1),
|
|
730
|
+
process_id: z2.string().min(1),
|
|
731
|
+
actor_id: z2.string().nullable(),
|
|
732
|
+
lineage: LineageSchema,
|
|
733
|
+
input_versions: InputVersionsSchema,
|
|
734
|
+
provenance: ProvenanceSchema
|
|
735
|
+
}).strict();
|
|
736
|
+
var HeaderMetaSchema = z2.discriminatedUnion("schema", [HeaderMetaV1Schema, HeaderMetaV2Schema]);
|
|
737
|
+
var SubjectSchema = z2.object({
|
|
738
|
+
issue: z2.number().int().nullable(),
|
|
739
|
+
pr: z2.number().int().optional(),
|
|
740
|
+
sha: z2.string().optional(),
|
|
741
|
+
role: z2.union([RoleSchema, z2.literal("unattributed")]),
|
|
742
|
+
round: z2.number().int().optional(),
|
|
743
|
+
objectives_version: z2.string().optional()
|
|
744
|
+
}).strict();
|
|
745
|
+
var HeaderSchema = z2.object({
|
|
746
|
+
meta: HeaderMetaSchema,
|
|
747
|
+
subject: SubjectSchema
|
|
748
|
+
}).strict();
|
|
749
|
+
var envelopeTail = {
|
|
750
|
+
duration_ms: z2.number().nonnegative().optional(),
|
|
751
|
+
payload: z2.object({}).strict()
|
|
752
|
+
};
|
|
753
|
+
var ReviewFindingSchema = z2.object({
|
|
754
|
+
id: z2.string(),
|
|
755
|
+
severity: z2.string(),
|
|
756
|
+
state: z2.string().optional(),
|
|
757
|
+
severity_scale: z2.string().optional(),
|
|
758
|
+
policy_treatment: z2.enum(["blocking", "non_blocking", "unavailable"]).optional(),
|
|
759
|
+
confidence: z2.number().min(0).max(1).optional(),
|
|
760
|
+
confidence_scale: z2.string().optional(),
|
|
761
|
+
confidence_source: z2.string().optional()
|
|
762
|
+
}).strict();
|
|
763
|
+
var DispatchOutcomeSchema = z2.discriminatedUnion("type", [
|
|
764
|
+
z2.object({ type: z2.literal("pr_opened"), pr: z2.number().int(), head: z2.string() }).strict(),
|
|
765
|
+
z2.object({
|
|
766
|
+
type: z2.literal("round_pushed"),
|
|
767
|
+
pr: z2.number().int(),
|
|
768
|
+
head: z2.string(),
|
|
769
|
+
comment_id: z2.number().int()
|
|
770
|
+
}).strict(),
|
|
771
|
+
z2.object({
|
|
772
|
+
type: z2.literal("verdict"),
|
|
773
|
+
verdict: z2.enum(["APPROVE", "REQUEST CHANGES", "PASS", "FAIL"]),
|
|
774
|
+
head: z2.string(),
|
|
775
|
+
comment_id: z2.number().int(),
|
|
776
|
+
objectives: z2.array(z2.object({ id: z2.string(), met: z2.boolean() }).strict()),
|
|
777
|
+
findings: z2.array(ReviewFindingSchema)
|
|
778
|
+
}).strict(),
|
|
779
|
+
z2.object({
|
|
780
|
+
type: z2.literal("escalation"),
|
|
781
|
+
class: z2.enum(["authority", "strategy", "product"]),
|
|
782
|
+
comment_id: z2.number().int()
|
|
783
|
+
}).strict(),
|
|
784
|
+
z2.object({ type: z2.literal("brief"), comment_id: z2.number().int(), hash: z2.string() }).strict(),
|
|
785
|
+
z2.object({ type: z2.literal("plan"), issues: z2.array(z2.number().int()) }).strict(),
|
|
786
|
+
z2.object({ type: z2.literal("archive"), provenance_comment_id: z2.number().int() }).strict(),
|
|
787
|
+
z2.object({ type: z2.literal("completed") }).strict()
|
|
788
|
+
]);
|
|
789
|
+
var dispatchShared = {
|
|
790
|
+
meta: HeaderMetaSchema,
|
|
791
|
+
subject: SubjectSchema,
|
|
792
|
+
kind: z2.literal("dispatch"),
|
|
793
|
+
...envelopeTail,
|
|
794
|
+
target_role: RoleSchema,
|
|
795
|
+
model: z2.string(),
|
|
796
|
+
round: z2.number().int().optional(),
|
|
797
|
+
effect_id: z2.string()
|
|
798
|
+
};
|
|
799
|
+
var dispatchUsageField = z2.object({ input: z2.number().nonnegative(), output: z2.number().nonnegative() }).strict().nullable();
|
|
800
|
+
var DispatchEventSchema = z2.discriminatedUnion("event", [
|
|
801
|
+
z2.object({ ...dispatchShared, event: z2.literal("dispatched"), prompt_hash: z2.string() }).strict(),
|
|
802
|
+
z2.object({
|
|
803
|
+
...dispatchShared,
|
|
804
|
+
event: z2.literal("outcome_received"),
|
|
805
|
+
outcome: DispatchOutcomeSchema,
|
|
806
|
+
usage: dispatchUsageField
|
|
807
|
+
}).strict(),
|
|
808
|
+
z2.object({
|
|
809
|
+
...dispatchShared,
|
|
810
|
+
event: z2.literal("dispatch_failed"),
|
|
811
|
+
reason: z2.enum(["timeout", "crash", "refused", "unattributed_write"]),
|
|
812
|
+
usage: dispatchUsageField
|
|
813
|
+
}).strict()
|
|
814
|
+
]);
|
|
815
|
+
var loopShared = {
|
|
816
|
+
meta: HeaderMetaSchema,
|
|
817
|
+
subject: SubjectSchema,
|
|
818
|
+
kind: z2.literal("dev_review_loop"),
|
|
819
|
+
...envelopeTail,
|
|
820
|
+
loop_id: z2.string()
|
|
821
|
+
};
|
|
822
|
+
var DevReviewLoopEventSchema = z2.discriminatedUnion("event", [
|
|
823
|
+
z2.object({
|
|
824
|
+
...loopShared,
|
|
825
|
+
event: z2.literal("loop_started"),
|
|
826
|
+
task: z2.number().int(),
|
|
827
|
+
policy: z2.object({
|
|
828
|
+
max_rounds: z2.number().int().nonnegative(),
|
|
829
|
+
reviewers: z2.array(RoleSchema),
|
|
830
|
+
models: z2.record(RoleSchema, z2.string())
|
|
831
|
+
}).strict()
|
|
832
|
+
}).strict(),
|
|
833
|
+
z2.object({ ...loopShared, event: z2.literal("round_started"), round: z2.number().int(), base_head: z2.string() }).strict(),
|
|
834
|
+
z2.object({
|
|
835
|
+
...loopShared,
|
|
836
|
+
event: z2.literal("gate_result_read"),
|
|
837
|
+
round: z2.number().int(),
|
|
838
|
+
head: z2.string(),
|
|
839
|
+
green: z2.boolean(),
|
|
840
|
+
confidence_value: z2.number().int().min(0).max(100).optional(),
|
|
841
|
+
confidence_reason: z2.string().max(CONFIDENCE_REASON_MAX_LENGTH).optional(),
|
|
842
|
+
confidence_unavailable: z2.boolean().optional(),
|
|
843
|
+
extra_turn_spent: z2.boolean().optional()
|
|
844
|
+
}).strict(),
|
|
845
|
+
z2.object({
|
|
846
|
+
...loopShared,
|
|
847
|
+
event: z2.literal("verdicts_read"),
|
|
848
|
+
round: z2.number().int(),
|
|
849
|
+
head: z2.string(),
|
|
850
|
+
all_approve: z2.boolean(),
|
|
851
|
+
blockers: z2.number().int().nonnegative(),
|
|
852
|
+
findings: z2.array(ReviewFindingSchema).optional()
|
|
853
|
+
}).strict(),
|
|
854
|
+
z2.object({
|
|
855
|
+
...loopShared,
|
|
856
|
+
event: z2.literal("findings_compared"),
|
|
857
|
+
round: z2.number().int(),
|
|
858
|
+
open: z2.array(z2.string()),
|
|
859
|
+
resolved: z2.array(z2.string()),
|
|
860
|
+
new: z2.array(z2.string()),
|
|
861
|
+
recurring: z2.array(z2.string())
|
|
862
|
+
}).strict(),
|
|
863
|
+
z2.object({
|
|
864
|
+
...loopShared,
|
|
865
|
+
event: z2.literal("stop_condition_met"),
|
|
866
|
+
round: z2.number().int(),
|
|
867
|
+
condition: z2.enum([
|
|
868
|
+
"green",
|
|
869
|
+
"max_rounds",
|
|
870
|
+
"no_progress",
|
|
871
|
+
"escalated",
|
|
872
|
+
"principal_stop",
|
|
873
|
+
"confidence",
|
|
874
|
+
"reappearance"
|
|
875
|
+
])
|
|
876
|
+
}).strict(),
|
|
877
|
+
z2.object({
|
|
878
|
+
...loopShared,
|
|
879
|
+
event: z2.literal("paused"),
|
|
880
|
+
round: z2.number().int(),
|
|
881
|
+
reason: z2.enum(["escalation", "principal_item", "refreeze_needed"])
|
|
882
|
+
}).strict(),
|
|
883
|
+
z2.object({
|
|
884
|
+
...loopShared,
|
|
885
|
+
event: z2.literal("resumed"),
|
|
886
|
+
round: z2.number().int(),
|
|
887
|
+
by: z2.enum(["principal", "driver"])
|
|
888
|
+
}).strict(),
|
|
889
|
+
z2.object({
|
|
890
|
+
...loopShared,
|
|
891
|
+
event: z2.literal("cancelled"),
|
|
892
|
+
round: z2.number().int(),
|
|
893
|
+
by: z2.literal("principal")
|
|
894
|
+
}).strict(),
|
|
895
|
+
z2.object({
|
|
896
|
+
...loopShared,
|
|
897
|
+
event: z2.literal("unpushed_work_resume"),
|
|
898
|
+
round: z2.number().int(),
|
|
899
|
+
branch: z2.string(),
|
|
900
|
+
detail: z2.string()
|
|
901
|
+
}).strict(),
|
|
902
|
+
z2.object({
|
|
903
|
+
...loopShared,
|
|
904
|
+
event: z2.literal("round_ended"),
|
|
905
|
+
round: z2.number().int(),
|
|
906
|
+
base_head: z2.string(),
|
|
907
|
+
head: z2.string(),
|
|
908
|
+
files_changed: z2.number().int().nonnegative(),
|
|
909
|
+
insertions: z2.number().int().nonnegative(),
|
|
910
|
+
deletions: z2.number().int().nonnegative(),
|
|
911
|
+
wall_ms: z2.number().nonnegative(),
|
|
912
|
+
outcome: z2.enum(["green", "changes_requested", "escalated"])
|
|
913
|
+
}).strict(),
|
|
914
|
+
z2.object({
|
|
915
|
+
...loopShared,
|
|
916
|
+
event: z2.literal("journal_finalized"),
|
|
917
|
+
rounds: z2.number().int().nonnegative(),
|
|
918
|
+
total_wall_ms: z2.number().nonnegative(),
|
|
919
|
+
time_to_green_ms: z2.number().nonnegative().nullable(),
|
|
920
|
+
files_changed_total: z2.number().int().nonnegative(),
|
|
921
|
+
final_head: z2.string(),
|
|
922
|
+
result: z2.enum(["merged_ready", "stopped"])
|
|
923
|
+
}).strict(),
|
|
924
|
+
z2.object({
|
|
925
|
+
...loopShared,
|
|
926
|
+
event: z2.literal("infrastructure_retry"),
|
|
927
|
+
round: z2.number().int(),
|
|
928
|
+
failure_kind: z2.enum(["pause_comment_post", "developer_connection"]),
|
|
929
|
+
attempts: z2.number().int().positive(),
|
|
930
|
+
outcome: z2.enum(["recovered", "exhausted"])
|
|
931
|
+
}).strict()
|
|
932
|
+
]);
|
|
933
|
+
var ForgeOpSchema = z2.enum([
|
|
934
|
+
"pr.create",
|
|
935
|
+
"pr.comment",
|
|
936
|
+
"pr.body.replace",
|
|
937
|
+
"pr.refreeze",
|
|
938
|
+
"issue.create",
|
|
939
|
+
"issue.edit",
|
|
940
|
+
"issue.comment",
|
|
941
|
+
"milestone.create",
|
|
942
|
+
"milestone.edit",
|
|
943
|
+
"milestone.close",
|
|
944
|
+
"label.add",
|
|
945
|
+
"label.remove"
|
|
946
|
+
]);
|
|
947
|
+
var ForgeWriteTargetSchema = z2.object({
|
|
948
|
+
issue: z2.number().int().optional(),
|
|
949
|
+
pr: z2.number().int().optional()
|
|
950
|
+
}).strict();
|
|
951
|
+
var forgeWriteShared = {
|
|
952
|
+
meta: HeaderMetaSchema,
|
|
953
|
+
subject: SubjectSchema,
|
|
954
|
+
kind: z2.literal("forge_write"),
|
|
955
|
+
...envelopeTail,
|
|
956
|
+
op: ForgeOpSchema,
|
|
957
|
+
target: ForgeWriteTargetSchema
|
|
958
|
+
};
|
|
959
|
+
var ForgeWriteEventSchema = z2.discriminatedUnion("event", [
|
|
960
|
+
z2.object({ ...forgeWriteShared, event: z2.literal("validated") }).strict(),
|
|
961
|
+
z2.object({ ...forgeWriteShared, event: z2.literal("refused"), reason: z2.string() }).strict(),
|
|
962
|
+
z2.object({ ...forgeWriteShared, event: z2.literal("written"), comment_ids: z2.array(z2.string()) }).strict()
|
|
963
|
+
]);
|
|
964
|
+
var GateOutcomeSchema = z2.enum([
|
|
965
|
+
"pass",
|
|
966
|
+
"fail",
|
|
967
|
+
"wait",
|
|
968
|
+
"skip",
|
|
969
|
+
"invalid_input",
|
|
970
|
+
"unavailable_dependency",
|
|
971
|
+
"timeout",
|
|
972
|
+
"cancelled"
|
|
973
|
+
]);
|
|
974
|
+
var gateShared = {
|
|
975
|
+
meta: HeaderMetaSchema,
|
|
976
|
+
subject: SubjectSchema,
|
|
977
|
+
kind: z2.literal("gate"),
|
|
978
|
+
...envelopeTail,
|
|
979
|
+
check: z2.string(),
|
|
980
|
+
check_version: z2.string().nullable(),
|
|
981
|
+
policy_version: z2.string().nullable(),
|
|
982
|
+
input_fingerprint: z2.string().nullable()
|
|
983
|
+
};
|
|
984
|
+
var GateEventSchema = z2.discriminatedUnion("event", [
|
|
985
|
+
z2.object({
|
|
986
|
+
...gateShared,
|
|
987
|
+
event: z2.literal("checked"),
|
|
988
|
+
outcome: GateOutcomeSchema,
|
|
989
|
+
reason: z2.string().optional()
|
|
990
|
+
}).strict()
|
|
991
|
+
]);
|
|
992
|
+
var OperationResultSchema = z2.enum(["ok", "error", "refused", "timeout", "cancelled", "unavailable"]);
|
|
993
|
+
var operationShared = {
|
|
994
|
+
meta: HeaderMetaSchema,
|
|
995
|
+
subject: SubjectSchema,
|
|
996
|
+
kind: z2.literal("operation"),
|
|
997
|
+
...envelopeTail,
|
|
998
|
+
operation: z2.string(),
|
|
999
|
+
target: z2.string().nullable()
|
|
1000
|
+
};
|
|
1001
|
+
var OperationEventSchema = z2.discriminatedUnion("event", [
|
|
1002
|
+
z2.object({
|
|
1003
|
+
...operationShared,
|
|
1004
|
+
event: z2.literal("completed"),
|
|
1005
|
+
result: OperationResultSchema,
|
|
1006
|
+
error_class: z2.string().nullable()
|
|
1007
|
+
}).strict()
|
|
1008
|
+
]);
|
|
1009
|
+
var UsageUnitsSchema = z2.object({
|
|
1010
|
+
input: z2.number().nonnegative().nullable(),
|
|
1011
|
+
output: z2.number().nonnegative().nullable(),
|
|
1012
|
+
cache: z2.number().nonnegative().nullable()
|
|
1013
|
+
}).strict();
|
|
1014
|
+
var usageShared = {
|
|
1015
|
+
meta: HeaderMetaSchema,
|
|
1016
|
+
subject: SubjectSchema,
|
|
1017
|
+
kind: z2.literal("usage"),
|
|
1018
|
+
...envelopeTail,
|
|
1019
|
+
model: z2.string().nullable(),
|
|
1020
|
+
source: z2.string(),
|
|
1021
|
+
semantics: z2.enum(["cumulative", "delta"])
|
|
1022
|
+
};
|
|
1023
|
+
var UsageEventSchema = z2.discriminatedUnion("event", [
|
|
1024
|
+
z2.object({
|
|
1025
|
+
...usageShared,
|
|
1026
|
+
event: z2.literal("observed"),
|
|
1027
|
+
units: UsageUnitsSchema,
|
|
1028
|
+
unknown_reason: z2.string().nullable()
|
|
1029
|
+
}).strict()
|
|
1030
|
+
]);
|
|
1031
|
+
var RoleAttemptOutcomeSchema = z2.enum([
|
|
1032
|
+
"completed",
|
|
1033
|
+
"incomplete",
|
|
1034
|
+
"infrastructure_failed",
|
|
1035
|
+
"cancelled",
|
|
1036
|
+
"timed_out",
|
|
1037
|
+
"capability_refused"
|
|
1038
|
+
]);
|
|
1039
|
+
var roleAttemptShared = {
|
|
1040
|
+
meta: HeaderMetaSchema,
|
|
1041
|
+
subject: SubjectSchema,
|
|
1042
|
+
kind: z2.literal("role_attempt"),
|
|
1043
|
+
...envelopeTail,
|
|
1044
|
+
actor: z2.string().nullable(),
|
|
1045
|
+
attempt: z2.number().int().nullable(),
|
|
1046
|
+
effect_id: z2.string(),
|
|
1047
|
+
model: z2.string().nullable()
|
|
1048
|
+
};
|
|
1049
|
+
var RoleAttemptEventSchema = z2.discriminatedUnion("event", [
|
|
1050
|
+
z2.object({
|
|
1051
|
+
...roleAttemptShared,
|
|
1052
|
+
event: z2.literal("attempted"),
|
|
1053
|
+
outcome: RoleAttemptOutcomeSchema,
|
|
1054
|
+
usage: dispatchUsageField
|
|
1055
|
+
}).strict()
|
|
1056
|
+
]);
|
|
1057
|
+
var handoffShared = {
|
|
1058
|
+
meta: HeaderMetaSchema,
|
|
1059
|
+
subject: SubjectSchema,
|
|
1060
|
+
kind: z2.literal("handoff"),
|
|
1061
|
+
...envelopeTail,
|
|
1062
|
+
class: z2.enum(["authority", "strategy", "product"]),
|
|
1063
|
+
reason: z2.string()
|
|
1064
|
+
};
|
|
1065
|
+
var HandoffEventSchema = z2.discriminatedUnion("event", [
|
|
1066
|
+
z2.object({
|
|
1067
|
+
...handoffShared,
|
|
1068
|
+
event: z2.literal("raised"),
|
|
1069
|
+
requested_decision: z2.string().nullable()
|
|
1070
|
+
}).strict(),
|
|
1071
|
+
z2.object({
|
|
1072
|
+
...handoffShared,
|
|
1073
|
+
event: z2.literal("resolved"),
|
|
1074
|
+
resolution: z2.string().nullable(),
|
|
1075
|
+
resolved_by: z2.string().nullable()
|
|
1076
|
+
}).strict()
|
|
1077
|
+
]);
|
|
1078
|
+
var EffectTargetSchema = z2.object({
|
|
1079
|
+
kind: z2.string(),
|
|
1080
|
+
ref: z2.string()
|
|
1081
|
+
}).strict();
|
|
1082
|
+
var effectShared = {
|
|
1083
|
+
meta: HeaderMetaSchema,
|
|
1084
|
+
subject: SubjectSchema,
|
|
1085
|
+
kind: z2.literal("effect"),
|
|
1086
|
+
...envelopeTail,
|
|
1087
|
+
effect_id: z2.string(),
|
|
1088
|
+
target: EffectTargetSchema
|
|
1089
|
+
};
|
|
1090
|
+
var EffectEventSchema = z2.discriminatedUnion("event", [
|
|
1091
|
+
z2.object({ ...effectShared, event: z2.literal("attempted") }).strict(),
|
|
1092
|
+
z2.object({ ...effectShared, event: z2.literal("observed"), outcome: z2.enum(["success", "failure", "uncertain"]) }).strict(),
|
|
1093
|
+
z2.object({ ...effectShared, event: z2.literal("verified"), outcome: z2.enum(["success", "failure", "uncertain"]) }).strict()
|
|
1094
|
+
]);
|
|
1095
|
+
var LogEventSchema = z2.union([
|
|
1096
|
+
DispatchEventSchema,
|
|
1097
|
+
DevReviewLoopEventSchema,
|
|
1098
|
+
ForgeWriteEventSchema,
|
|
1099
|
+
GateEventSchema,
|
|
1100
|
+
OperationEventSchema,
|
|
1101
|
+
UsageEventSchema,
|
|
1102
|
+
RoleAttemptEventSchema,
|
|
1103
|
+
HandoffEventSchema,
|
|
1104
|
+
EffectEventSchema
|
|
1105
|
+
]);
|
|
1106
|
+
|
|
1107
|
+
// ../../packages/aeg-core/src/log/envelope.ts
|
|
1108
|
+
function isRole(value) {
|
|
1109
|
+
return value !== undefined && ROLE_VALUES.includes(value);
|
|
1110
|
+
}
|
|
1111
|
+
function actorIdFromEnv(role) {
|
|
1112
|
+
return role === undefined || role === "" ? null : role;
|
|
1113
|
+
}
|
|
1114
|
+
function lineageFieldFromEnv(value) {
|
|
1115
|
+
return value === undefined || value === "" ? null : value;
|
|
1116
|
+
}
|
|
1117
|
+
function attemptFromEnv(value) {
|
|
1118
|
+
if (value === undefined || value === "")
|
|
1119
|
+
return null;
|
|
1120
|
+
const n = Number(value);
|
|
1121
|
+
return Number.isInteger(n) ? n : null;
|
|
1122
|
+
}
|
|
1123
|
+
function provenanceFor(input) {
|
|
1124
|
+
if (input.provenance)
|
|
1125
|
+
return input.provenance;
|
|
1126
|
+
if (input.env.role || input.env.task)
|
|
1127
|
+
return "env_correlated";
|
|
1128
|
+
return "unavailable";
|
|
1129
|
+
}
|
|
1130
|
+
function issueFromTask(task) {
|
|
1131
|
+
if (task === undefined || task === "")
|
|
1132
|
+
return null;
|
|
1133
|
+
const n = Number(task);
|
|
1134
|
+
return Number.isInteger(n) ? n : null;
|
|
1135
|
+
}
|
|
1136
|
+
function roundFromEnv(round) {
|
|
1137
|
+
if (round === undefined || round === "")
|
|
1138
|
+
return;
|
|
1139
|
+
const n = Number(round);
|
|
1140
|
+
return Number.isInteger(n) ? n : undefined;
|
|
1141
|
+
}
|
|
1142
|
+
function buildHeader(input) {
|
|
1143
|
+
const role = isRole(input.env.role) ? input.env.role : "unattributed";
|
|
1144
|
+
const round = roundFromEnv(input.env.round);
|
|
1145
|
+
const subject = {
|
|
1146
|
+
issue: issueFromTask(input.env.task),
|
|
1147
|
+
role,
|
|
1148
|
+
...round !== undefined ? { round } : {},
|
|
1149
|
+
...input.subject ?? {}
|
|
1150
|
+
};
|
|
1151
|
+
return {
|
|
1152
|
+
meta: {
|
|
1153
|
+
schema: 2,
|
|
1154
|
+
ts: input.now.toISOString(),
|
|
1155
|
+
run_id: input.runId,
|
|
1156
|
+
seq: input.seq,
|
|
1157
|
+
repo: input.repo,
|
|
1158
|
+
vinaya: input.vinaya,
|
|
1159
|
+
doctrine: input.doctrine,
|
|
1160
|
+
host: input.host,
|
|
1161
|
+
machine: createHash("sha256").update(input.hostname).digest("hex"),
|
|
1162
|
+
event_id: input.eventId,
|
|
1163
|
+
process_id: input.processId,
|
|
1164
|
+
actor_id: actorIdFromEnv(input.env.role),
|
|
1165
|
+
lineage: {
|
|
1166
|
+
run: lineageFieldFromEnv(input.env.run),
|
|
1167
|
+
attempt: attemptFromEnv(input.env.attempt),
|
|
1168
|
+
parent: lineageFieldFromEnv(input.env.parent)
|
|
1169
|
+
},
|
|
1170
|
+
input_versions: {
|
|
1171
|
+
objectives_version: input.inputVersions?.objectivesVersion ?? null,
|
|
1172
|
+
brief_hash: input.inputVersions?.briefHash ?? null,
|
|
1173
|
+
ruling_ordinal: input.inputVersions?.rulingOrdinal ?? null,
|
|
1174
|
+
policy_digest: input.inputVersions?.policyDigest ?? null
|
|
1175
|
+
},
|
|
1176
|
+
provenance: provenanceFor(input)
|
|
1177
|
+
},
|
|
1178
|
+
subject
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
// ../../packages/aeg-core/src/log/redact.ts
|
|
1182
|
+
var GITHUB_TOKEN_PATTERN = /\b(?:gho_|ghp_|ghs_|ghu_|ghr_|github_pat_)[A-Za-z0-9_]+\b/g;
|
|
1183
|
+
var CLASSIC_GITHUB_PAT_PATTERN = /\b((?:token|GITHUB_TOKEN|PAT|api[_-]?key|api[_-]?token)\s*[:=]\s*)[a-f0-9]{40}\b/gi;
|
|
1184
|
+
var BEARER_TOKEN_PATTERN = /\bBearer\s+\S+/g;
|
|
1185
|
+
var AWS_ACCESS_KEY_PATTERN = /\bAKIA[0-9A-Z]{16}\b/g;
|
|
1186
|
+
var SLACK_TOKEN_PATTERN = /\bxox[baprs]-[0-9A-Za-z-]+\b/g;
|
|
1187
|
+
var STRIPE_KEY_PATTERN = /\b(?:sk|pk|rk)_(?:live|test)_[0-9A-Za-z]{10,}\b/g;
|
|
1188
|
+
var ANTHROPIC_KEY_PATTERN = /\bsk-ant-[A-Za-z0-9_-]{20,}\b/g;
|
|
1189
|
+
var OPENAI_KEY_PATTERN = /\bsk-(?!ant-)[A-Za-z0-9]{20,}\b/g;
|
|
1190
|
+
var NPM_TOKEN_PATTERN = /\bnpm_[A-Za-z0-9]{36}\b/g;
|
|
1191
|
+
var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g;
|
|
1192
|
+
var PEM_BLOCK_PATTERN = /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g;
|
|
1193
|
+
var BASIC_AUTH_URL_PATTERN = /(https?:\/\/)[^/\s:@]+:[^/\s@]+@/g;
|
|
1194
|
+
var GENERIC_SECRET_ASSIGNMENT_PATTERN = /\b((?:secret|password|passwd|api[_-]?key|access[_-]?key|client[_-]?secret|private[_-]?key)\s*[:=]\s*)[A-Za-z0-9+/_=-]{16,}\b/gi;
|
|
1195
|
+
function redactString(value, home) {
|
|
1196
|
+
let out = value.replace(GITHUB_TOKEN_PATTERN, "<redacted>").replace(CLASSIC_GITHUB_PAT_PATTERN, "$1<redacted>").replace(BEARER_TOKEN_PATTERN, "<redacted>").replace(AWS_ACCESS_KEY_PATTERN, "<redacted>").replace(SLACK_TOKEN_PATTERN, "<redacted>").replace(STRIPE_KEY_PATTERN, "<redacted>").replace(ANTHROPIC_KEY_PATTERN, "<redacted>").replace(OPENAI_KEY_PATTERN, "<redacted>").replace(NPM_TOKEN_PATTERN, "<redacted>").replace(JWT_PATTERN, "<redacted>").replace(PEM_BLOCK_PATTERN, "<redacted>").replace(BASIC_AUTH_URL_PATTERN, "$1<redacted>@").replace(GENERIC_SECRET_ASSIGNMENT_PATTERN, "$1<redacted>");
|
|
1197
|
+
if (home.length > 0 && out.startsWith(home)) {
|
|
1198
|
+
const rest = out.slice(home.length);
|
|
1199
|
+
if (rest === "" || rest.startsWith("/"))
|
|
1200
|
+
out = `~${rest}`;
|
|
1201
|
+
}
|
|
1202
|
+
return out;
|
|
1203
|
+
}
|
|
1204
|
+
function redact(value, home) {
|
|
1205
|
+
if (typeof value === "string")
|
|
1206
|
+
return redactString(value, home);
|
|
1207
|
+
if (Array.isArray(value))
|
|
1208
|
+
return value.map((v) => redact(v, home));
|
|
1209
|
+
if (value !== null && typeof value === "object") {
|
|
1210
|
+
const out = {};
|
|
1211
|
+
for (const [k, v] of Object.entries(value)) {
|
|
1212
|
+
out[k] = redact(v, home);
|
|
1213
|
+
}
|
|
1214
|
+
return out;
|
|
1215
|
+
}
|
|
1216
|
+
return value;
|
|
1217
|
+
}
|
|
1218
|
+
// ../../packages/aeg-core/src/log/store.ts
|
|
1219
|
+
var KNOWN_SCHEMA_VERSIONS = [1, 2];
|
|
1220
|
+
function metaOf(obj) {
|
|
1221
|
+
if (obj === null || typeof obj !== "object")
|
|
1222
|
+
return null;
|
|
1223
|
+
const meta = obj.meta;
|
|
1224
|
+
if (meta === null || typeof meta !== "object")
|
|
1225
|
+
return null;
|
|
1226
|
+
return meta;
|
|
1227
|
+
}
|
|
1228
|
+
function recordIdentity(obj) {
|
|
1229
|
+
const meta = metaOf(obj);
|
|
1230
|
+
if (meta === null)
|
|
1231
|
+
return null;
|
|
1232
|
+
const eventId = meta.event_id;
|
|
1233
|
+
if (typeof eventId === "string" && eventId.length > 0)
|
|
1234
|
+
return eventId;
|
|
1235
|
+
const runId = meta.run_id;
|
|
1236
|
+
const seq = meta.seq;
|
|
1237
|
+
if (typeof runId === "string" && runId.length > 0 && typeof seq === "number" && Number.isInteger(seq)) {
|
|
1238
|
+
return `${runId}:${seq}`;
|
|
1239
|
+
}
|
|
1240
|
+
return null;
|
|
1241
|
+
}
|
|
1242
|
+
function schemaVersionOf(obj) {
|
|
1243
|
+
const meta = metaOf(obj);
|
|
1244
|
+
const schema = meta?.schema;
|
|
1245
|
+
return typeof schema === "number" ? schema : null;
|
|
1246
|
+
}
|
|
1247
|
+
function isKnownSchema(version) {
|
|
1248
|
+
return version !== null && KNOWN_SCHEMA_VERSIONS.includes(version);
|
|
1249
|
+
}
|
|
1250
|
+
function classifyStoredLine(raw, home) {
|
|
1251
|
+
let obj;
|
|
1252
|
+
try {
|
|
1253
|
+
obj = JSON.parse(raw);
|
|
1254
|
+
} catch {
|
|
1255
|
+
return { status: "invalid", identity: null, raw, reason: "not valid JSON" };
|
|
1256
|
+
}
|
|
1257
|
+
const version = schemaVersionOf(obj);
|
|
1258
|
+
if (version === null) {
|
|
1259
|
+
return { status: "invalid", identity: recordIdentity(obj), raw, reason: "no readable meta.schema" };
|
|
1260
|
+
}
|
|
1261
|
+
if (!isKnownSchema(version)) {
|
|
1262
|
+
return {
|
|
1263
|
+
status: "unknown_version",
|
|
1264
|
+
identity: recordIdentity(obj),
|
|
1265
|
+
schema: version,
|
|
1266
|
+
raw,
|
|
1267
|
+
reason: `schema version ${version} is not one this build validates (${KNOWN_SCHEMA_VERSIONS.join(", ")}) — kept for diagnosis`
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
const result = LogEventSchema.safeParse(obj);
|
|
1271
|
+
if (!result.success) {
|
|
1272
|
+
return {
|
|
1273
|
+
status: "invalid",
|
|
1274
|
+
identity: recordIdentity(obj),
|
|
1275
|
+
raw,
|
|
1276
|
+
reason: result.error.issues[0]?.message ?? "schema violation"
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
const event = result.data;
|
|
1280
|
+
const identity = recordIdentity(event);
|
|
1281
|
+
if (identity === null) {
|
|
1282
|
+
return { status: "invalid", identity: null, raw, reason: "valid event with no derivable identity" };
|
|
1283
|
+
}
|
|
1284
|
+
const redacted = redact(event, home);
|
|
1285
|
+
const provenance = version === 2 ? event.meta.provenance ?? null : null;
|
|
1286
|
+
return {
|
|
1287
|
+
status: "ok",
|
|
1288
|
+
identity,
|
|
1289
|
+
runId: event.meta.run_id,
|
|
1290
|
+
seq: event.meta.seq,
|
|
1291
|
+
schema: version,
|
|
1292
|
+
provenance,
|
|
1293
|
+
event,
|
|
1294
|
+
postLine: JSON.stringify(redacted)
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
// ../../packages/aeg-core/src/control-store/records.ts
|
|
1298
|
+
import { z as z3 } from "zod";
|
|
1299
|
+
var isoTimestamp = z3.string().min(1);
|
|
1300
|
+
var taskId = z3.number().int().positive();
|
|
1301
|
+
var epochNumber = z3.number().int().nonnegative();
|
|
1302
|
+
var RunRecordSchema = z3.object({
|
|
1303
|
+
version: z3.literal(1),
|
|
1304
|
+
kind: z3.literal("run"),
|
|
1305
|
+
task: taskId,
|
|
1306
|
+
runId: z3.string().min(1),
|
|
1307
|
+
pid: z3.number().int().positive(),
|
|
1308
|
+
host: z3.string().min(1),
|
|
1309
|
+
startedAt: isoTimestamp,
|
|
1310
|
+
childStartedAt: z3.string().min(1).nullable().optional(),
|
|
1311
|
+
childCommand: z3.string().min(1).nullable().optional()
|
|
1312
|
+
}).strict();
|
|
1313
|
+
var InputRecordSchema = z3.object({
|
|
1314
|
+
version: z3.literal(1),
|
|
1315
|
+
kind: z3.literal("input"),
|
|
1316
|
+
task: taskId,
|
|
1317
|
+
runId: z3.string().min(1),
|
|
1318
|
+
source: z3.union([z3.literal("fresh"), z3.literal("resume")]),
|
|
1319
|
+
pr: z3.number().int().positive().nullable(),
|
|
1320
|
+
round: z3.number().int().nonnegative(),
|
|
1321
|
+
recordedAt: isoTimestamp
|
|
1322
|
+
}).strict();
|
|
1323
|
+
var OwnershipRecordSchema = z3.object({
|
|
1324
|
+
version: z3.literal(1),
|
|
1325
|
+
kind: z3.literal("ownership"),
|
|
1326
|
+
task: taskId,
|
|
1327
|
+
epoch: epochNumber,
|
|
1328
|
+
ownerId: z3.string().min(1),
|
|
1329
|
+
pid: z3.number().int().positive(),
|
|
1330
|
+
host: z3.string().min(1),
|
|
1331
|
+
acquiredAt: isoTimestamp
|
|
1332
|
+
}).strict();
|
|
1333
|
+
var TransitionRecordSchema = z3.object({
|
|
1334
|
+
version: z3.literal(1),
|
|
1335
|
+
kind: z3.literal("transition"),
|
|
1336
|
+
task: taskId,
|
|
1337
|
+
epoch: epochNumber,
|
|
1338
|
+
seq: z3.number().int().nonnegative(),
|
|
1339
|
+
from: z3.string().min(1),
|
|
1340
|
+
to: z3.string().min(1),
|
|
1341
|
+
detail: z3.string().optional(),
|
|
1342
|
+
at: isoTimestamp
|
|
1343
|
+
}).strict();
|
|
1344
|
+
var ManifestRecordSchema = z3.object({
|
|
1345
|
+
version: z3.literal(1),
|
|
1346
|
+
kind: z3.literal("manifest"),
|
|
1347
|
+
task: taskId,
|
|
1348
|
+
round: epochNumber,
|
|
1349
|
+
repository: z3.string().min(1),
|
|
1350
|
+
pr: z3.number().int().positive(),
|
|
1351
|
+
branch: z3.string().min(1),
|
|
1352
|
+
baseSha: z3.string().min(1).nullable(),
|
|
1353
|
+
headSha: z3.string().min(1),
|
|
1354
|
+
briefHash: z3.string().min(1).nullable(),
|
|
1355
|
+
objectivesVersion: z3.string().min(1).nullable(),
|
|
1356
|
+
rulingOrdinal: epochNumber,
|
|
1357
|
+
policyDigest: z3.string().min(1),
|
|
1358
|
+
recordedAt: isoTimestamp
|
|
1359
|
+
}).strict();
|
|
1360
|
+
var roundHeadIdentity = z3.object({ round: z3.number().int().positive(), head: z3.string().min(1) }).strict();
|
|
1361
|
+
var LoopBudgetsSchema = z3.object({
|
|
1362
|
+
mechanicalRetries: z3.number().int().nonnegative(),
|
|
1363
|
+
reviewRounds: z3.number().int().nonnegative(),
|
|
1364
|
+
infrastructureRetries: z3.number().int().nonnegative()
|
|
1365
|
+
}).strict();
|
|
1366
|
+
var LoopStateRecordSchema = z3.object({
|
|
1367
|
+
version: z3.literal(1),
|
|
1368
|
+
kind: z3.literal("loop_state"),
|
|
1369
|
+
task: taskId,
|
|
1370
|
+
round: z3.number().int().positive(),
|
|
1371
|
+
phase: z3.string().min(1),
|
|
1372
|
+
pauseReason: z3.string().min(1).nullable(),
|
|
1373
|
+
budgets: LoopBudgetsSchema,
|
|
1374
|
+
heldResult: roundHeadIdentity.nullable(),
|
|
1375
|
+
deliveredFindings: roundHeadIdentity.nullable(),
|
|
1376
|
+
recordedAt: isoTimestamp
|
|
1377
|
+
}).strict();
|
|
1378
|
+
var EffectRecordSchema = z3.object({
|
|
1379
|
+
version: z3.literal(1),
|
|
1380
|
+
kind: z3.literal("effect"),
|
|
1381
|
+
task: taskId,
|
|
1382
|
+
key: z3.string().min(1),
|
|
1383
|
+
operation: z3.string().min(1),
|
|
1384
|
+
target: z3.string().min(1),
|
|
1385
|
+
inputVersion: z3.number().int().nonnegative(),
|
|
1386
|
+
payloadDigest: z3.string().min(1),
|
|
1387
|
+
status: z3.union([z3.literal("started"), z3.literal("verified"), z3.literal("uncertain")]),
|
|
1388
|
+
url: z3.string().optional(),
|
|
1389
|
+
recordedAt: isoTimestamp
|
|
1390
|
+
}).strict();
|
|
1391
|
+
var EscalationRecordSchema = z3.object({
|
|
1392
|
+
version: z3.literal(1),
|
|
1393
|
+
kind: z3.literal("escalation"),
|
|
1394
|
+
task: taskId,
|
|
1395
|
+
escalationId: z3.string().min(1),
|
|
1396
|
+
round: epochNumber,
|
|
1397
|
+
head: z3.string().min(1),
|
|
1398
|
+
branch: z3.string().min(1),
|
|
1399
|
+
pr: z3.number().int().positive().nullable(),
|
|
1400
|
+
runId: z3.string().min(1),
|
|
1401
|
+
pid: z3.number().int().positive(),
|
|
1402
|
+
host: z3.string().min(1),
|
|
1403
|
+
agent: z3.string().min(1).optional(),
|
|
1404
|
+
reason: z3.string().min(1),
|
|
1405
|
+
detail: z3.string().optional(),
|
|
1406
|
+
evidence: z3.string().optional(),
|
|
1407
|
+
attemptedRecovery: z3.string().min(1),
|
|
1408
|
+
requestedDecision: z3.string().min(1),
|
|
1409
|
+
recipient: z3.string().min(1),
|
|
1410
|
+
briefHash: z3.string().min(1).nullable(),
|
|
1411
|
+
objectivesVersion: z3.string().min(1).nullable(),
|
|
1412
|
+
rulingOrdinal: epochNumber,
|
|
1413
|
+
policyDigest: z3.string().min(1),
|
|
1414
|
+
recordedAt: isoTimestamp
|
|
1415
|
+
}).strict();
|
|
1416
|
+
var ResolutionRecordSchema = z3.object({
|
|
1417
|
+
version: z3.literal(1),
|
|
1418
|
+
kind: z3.literal("resolution"),
|
|
1419
|
+
task: taskId,
|
|
1420
|
+
escalationId: z3.string().min(1),
|
|
1421
|
+
decision: z3.union([z3.literal("resume"), z3.literal("cancel")]),
|
|
1422
|
+
authenticatedBy: z3.string().min(1),
|
|
1423
|
+
authenticatedFrom: z3.string().min(1),
|
|
1424
|
+
consumedAt: isoTimestamp
|
|
1425
|
+
}).strict();
|
|
1426
|
+
// ../../packages/aeg-core/src/control-store/local.ts
|
|
1427
|
+
import {
|
|
1428
|
+
closeSync as closeSync2,
|
|
1429
|
+
constants as fsConstants2,
|
|
1430
|
+
existsSync,
|
|
1431
|
+
fsyncSync,
|
|
1432
|
+
linkSync,
|
|
1433
|
+
lstatSync,
|
|
1434
|
+
mkdirSync,
|
|
1435
|
+
openSync as openSync2,
|
|
1436
|
+
readdirSync,
|
|
1437
|
+
readFileSync as readFileSync2,
|
|
1438
|
+
renameSync,
|
|
1439
|
+
statSync,
|
|
1440
|
+
unlinkSync,
|
|
1441
|
+
writeSync
|
|
1442
|
+
} from "node:fs";
|
|
1443
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
1444
|
+
function isErrnoException(err, code) {
|
|
1445
|
+
return typeof err === "object" && err !== null && err.code === code;
|
|
1446
|
+
}
|
|
1447
|
+
function isTrustedDirStat(stat, ownUid) {
|
|
1448
|
+
if (typeof ownUid !== "number")
|
|
1449
|
+
return true;
|
|
1450
|
+
if (stat.uid !== ownUid && stat.uid !== 0)
|
|
1451
|
+
return false;
|
|
1452
|
+
const worldWritable = (stat.mode & 2) !== 0;
|
|
1453
|
+
const sticky = (stat.mode & 512) !== 0;
|
|
1454
|
+
return !worldWritable || sticky;
|
|
1455
|
+
}
|
|
1456
|
+
function currentUid() {
|
|
1457
|
+
return typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
1458
|
+
}
|
|
1459
|
+
function mkdirNoSymlinks(dir, mode, trustedRoot) {
|
|
1460
|
+
const absolute = resolve(dir);
|
|
1461
|
+
const rootSegments = resolve(trustedRoot).split(sep).filter((s) => s.length > 0);
|
|
1462
|
+
const segments = absolute.split(sep).filter((s) => s.length > 0);
|
|
1463
|
+
const ownUid = currentUid();
|
|
1464
|
+
let current = absolute.startsWith(sep) ? sep : "";
|
|
1465
|
+
segments.forEach((segment, index) => {
|
|
1466
|
+
current = current === "" || current === sep ? `${current}${segment}` : `${current}${sep}${segment}`;
|
|
1467
|
+
const atOrBelowTrustedRoot = index >= rootSegments.length - 1;
|
|
1468
|
+
try {
|
|
1469
|
+
mkdirSync(current, { mode });
|
|
1470
|
+
} catch (err) {
|
|
1471
|
+
if (!isErrnoException(err, "EEXIST"))
|
|
1472
|
+
throw err;
|
|
1473
|
+
}
|
|
1474
|
+
const stat = lstatSync(current);
|
|
1475
|
+
if (stat.isSymbolicLink()) {
|
|
1476
|
+
if (atOrBelowTrustedRoot) {
|
|
1477
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it already exists and is not a real directory (a symlink or a file)`);
|
|
1478
|
+
}
|
|
1479
|
+
let real;
|
|
1480
|
+
try {
|
|
1481
|
+
real = statSync(current);
|
|
1482
|
+
} catch (err) {
|
|
1483
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it is a symlink whose target could not be resolved: ${err instanceof Error ? err.message : String(err)}`);
|
|
1484
|
+
}
|
|
1485
|
+
if (!real.isDirectory()) {
|
|
1486
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it is a symlink that does not resolve to a real directory`);
|
|
1487
|
+
}
|
|
1488
|
+
if (!isTrustedDirStat(real, ownUid)) {
|
|
1489
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — its symlink target is owned by uid ${real.uid} with mode ${(real.mode & 4095).toString(8)}, neither this process's own user nor a safe shared mode`);
|
|
1490
|
+
}
|
|
1491
|
+
return;
|
|
1492
|
+
}
|
|
1493
|
+
if (!stat.isDirectory()) {
|
|
1494
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it already exists and is not a real directory (a symlink or a file)`);
|
|
1495
|
+
}
|
|
1496
|
+
if (!isTrustedDirStat(stat, ownUid)) {
|
|
1497
|
+
throw new Error(`control-store: refusing to create a run directory through ${current} — it already exists, owned by uid ${stat.uid} with mode ${(stat.mode & 4095).toString(8)}, neither this process's own user nor a safe shared mode`);
|
|
1498
|
+
}
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
var CONTROL_AREA_DIRNAME = "control";
|
|
1502
|
+
// src/checks/registry.ts
|
|
1503
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
1504
|
+
import { join as join3 } from "node:path";
|
|
1505
|
+
|
|
1506
|
+
// src/lib/package-root.ts
|
|
1507
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
1508
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
1509
|
+
import { fileURLToPath } from "node:url";
|
|
1510
|
+
function packageRoot(moduleUrl) {
|
|
1511
|
+
let dir = dirname2(fileURLToPath(moduleUrl));
|
|
1512
|
+
while (!existsSync2(join2(dir, "package.json"))) {
|
|
1513
|
+
if (existsSync2(join2(dir, ".git")))
|
|
1514
|
+
break;
|
|
1515
|
+
const parent = dirname2(dir);
|
|
1516
|
+
if (parent === dir)
|
|
1517
|
+
break;
|
|
1518
|
+
dir = parent;
|
|
1519
|
+
}
|
|
1520
|
+
return dir;
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
// src/checks/registry.ts
|
|
1524
|
+
var DIST_BIN_DIR = join3(packageRoot(import.meta.url), "dist", "checks", "bin");
|
|
1525
|
+
var SRC_BIN_DIR = join3(packageRoot(import.meta.url), "src", "checks", "bin");
|
|
1526
|
+
var BIN_DIR = existsSync3(DIST_BIN_DIR) ? DIST_BIN_DIR : SRC_BIN_DIR;
|
|
1527
|
+
var BIN_EXT = BIN_DIR === DIST_BIN_DIR ? ".js" : ".ts";
|
|
1528
|
+
function bin(name) {
|
|
1529
|
+
return join3(BIN_DIR, `${name}${BIN_EXT}`);
|
|
1530
|
+
}
|
|
1531
|
+
var REGISTRY = [
|
|
1532
|
+
[
|
|
1533
|
+
{
|
|
1534
|
+
name: "brief-shape",
|
|
1535
|
+
validates: "body",
|
|
1536
|
+
run: bin("check-brief-shape"),
|
|
1537
|
+
scope: "diff",
|
|
1538
|
+
timeoutMs: 15000,
|
|
1539
|
+
env: {
|
|
1540
|
+
PR_BODY: { optional: true },
|
|
1541
|
+
BRANCH: { optional: true },
|
|
1542
|
+
PR_NUMBER: { optional: true },
|
|
1543
|
+
GITHUB_TOKEN: { optional: true },
|
|
1544
|
+
GH_TOKEN: { optional: true }
|
|
1545
|
+
}
|
|
1546
|
+
},
|
|
1547
|
+
0
|
|
1548
|
+
],
|
|
1549
|
+
[
|
|
1550
|
+
{
|
|
1551
|
+
name: "pr-report-density",
|
|
1552
|
+
validates: "body",
|
|
1553
|
+
run: bin("check-pr-report-density"),
|
|
1554
|
+
scope: "diff",
|
|
1555
|
+
timeoutMs: 15000,
|
|
1556
|
+
env: {
|
|
1557
|
+
PR_BODY: { optional: true }
|
|
1558
|
+
}
|
|
1559
|
+
},
|
|
1560
|
+
0
|
|
1561
|
+
],
|
|
1562
|
+
[
|
|
1563
|
+
{
|
|
1564
|
+
name: "doc-coverage",
|
|
1565
|
+
validates: "body",
|
|
1566
|
+
run: bin("check-doc-coverage"),
|
|
1567
|
+
scope: "diff",
|
|
1568
|
+
timeoutMs: 15000,
|
|
1569
|
+
env: {
|
|
1570
|
+
BASE_SHA: { optional: true },
|
|
1571
|
+
PR_BODY: { optional: true },
|
|
1572
|
+
PR_BODY_FILE: { optional: true },
|
|
1573
|
+
PR_NUMBER: { optional: true },
|
|
1574
|
+
GITHUB_REPOSITORY: { optional: true },
|
|
1575
|
+
GITHUB_TOKEN: { optional: true },
|
|
1576
|
+
GH_TOKEN: { optional: true }
|
|
1577
|
+
}
|
|
1578
|
+
},
|
|
1579
|
+
0
|
|
1580
|
+
],
|
|
1581
|
+
[
|
|
1582
|
+
{
|
|
1583
|
+
name: "coherence",
|
|
1584
|
+
run: bin("check-coherence"),
|
|
1585
|
+
scope: "full",
|
|
1586
|
+
timeoutMs: 30000,
|
|
1587
|
+
env: {
|
|
1588
|
+
AEG_REPO: { optional: true },
|
|
1589
|
+
BRANCH: { optional: true },
|
|
1590
|
+
GITHUB_TOKEN: { optional: true },
|
|
1591
|
+
GH_TOKEN: { optional: true }
|
|
1592
|
+
}
|
|
1593
|
+
},
|
|
1594
|
+
0
|
|
1595
|
+
],
|
|
1596
|
+
[
|
|
1597
|
+
{
|
|
1598
|
+
name: "pr-premise-reassert",
|
|
1599
|
+
validates: "body",
|
|
1600
|
+
run: bin("check-pr-premise-reassert"),
|
|
1601
|
+
scope: "diff",
|
|
1602
|
+
timeoutMs: 15000,
|
|
1603
|
+
env: {
|
|
1604
|
+
PR_BODY: { optional: true }
|
|
1605
|
+
}
|
|
1606
|
+
},
|
|
1607
|
+
0
|
|
1608
|
+
],
|
|
1609
|
+
[
|
|
1610
|
+
{
|
|
1611
|
+
name: "dispatch-readiness",
|
|
1612
|
+
run: bin("check-dispatch-readiness"),
|
|
1613
|
+
scope: "full",
|
|
1614
|
+
timeoutMs: 30000,
|
|
1615
|
+
env: {
|
|
1616
|
+
AEG_REPO: { optional: true },
|
|
1617
|
+
BRANCH: { optional: true },
|
|
1618
|
+
GITHUB_TOKEN: { optional: true },
|
|
1619
|
+
GH_TOKEN: { optional: true },
|
|
1620
|
+
PREMISE_FILE: { optional: true }
|
|
1621
|
+
}
|
|
1622
|
+
},
|
|
1623
|
+
0
|
|
1624
|
+
],
|
|
1625
|
+
[
|
|
1626
|
+
{
|
|
1627
|
+
name: "closes-n",
|
|
1628
|
+
validates: "body",
|
|
1629
|
+
run: bin("check-closes-n"),
|
|
1630
|
+
scope: "diff",
|
|
1631
|
+
timeoutMs: 15000,
|
|
1632
|
+
requiresOpenPr: true,
|
|
1633
|
+
env: {
|
|
1634
|
+
BRANCH: { optional: true },
|
|
1635
|
+
PR_BODY: { optional: true },
|
|
1636
|
+
AEG_REPO: { optional: true },
|
|
1637
|
+
GITHUB_TOKEN: { optional: true },
|
|
1638
|
+
GH_TOKEN: { optional: true }
|
|
1639
|
+
}
|
|
1640
|
+
},
|
|
1641
|
+
1
|
|
1642
|
+
],
|
|
1643
|
+
[
|
|
1644
|
+
{
|
|
1645
|
+
name: "single-plan-pr",
|
|
1646
|
+
run: bin("check-single-plan-pr"),
|
|
1647
|
+
scope: "diff",
|
|
1648
|
+
timeoutMs: 15000,
|
|
1649
|
+
env: {
|
|
1650
|
+
BASE_SHA: { optional: true },
|
|
1651
|
+
PR_NUMBER: { optional: true },
|
|
1652
|
+
GITHUB_TOKEN: { optional: true },
|
|
1653
|
+
GH_TOKEN: { optional: true }
|
|
1654
|
+
}
|
|
1655
|
+
},
|
|
1656
|
+
0
|
|
1657
|
+
],
|
|
1658
|
+
[
|
|
1659
|
+
{
|
|
1660
|
+
name: "surface-scope",
|
|
1661
|
+
run: bin("check-surface-scope"),
|
|
1662
|
+
scope: "diff",
|
|
1663
|
+
timeoutMs: 15000,
|
|
1664
|
+
env: {
|
|
1665
|
+
AEG_REPO: { optional: true },
|
|
1666
|
+
BASE_SHA: { optional: true },
|
|
1667
|
+
BRANCH: { optional: true },
|
|
1668
|
+
GITHUB_TOKEN: { optional: true },
|
|
1669
|
+
GH_TOKEN: { optional: true }
|
|
1670
|
+
}
|
|
1671
|
+
},
|
|
1672
|
+
0
|
|
1673
|
+
],
|
|
1674
|
+
[
|
|
1675
|
+
{
|
|
1676
|
+
name: "test-plan",
|
|
1677
|
+
validates: "body",
|
|
1678
|
+
run: bin("check-test-plan"),
|
|
1679
|
+
scope: "diff",
|
|
1680
|
+
timeoutMs: 15000,
|
|
1681
|
+
requiresOpenPr: true,
|
|
1682
|
+
principalOwed: true,
|
|
1683
|
+
env: {
|
|
1684
|
+
PR_BODY: { optional: true },
|
|
1685
|
+
BRANCH: { optional: true }
|
|
1686
|
+
}
|
|
1687
|
+
},
|
|
1688
|
+
1
|
|
1689
|
+
],
|
|
1690
|
+
[
|
|
1691
|
+
{
|
|
1692
|
+
name: "principal-test-plan-wait",
|
|
1693
|
+
validates: "body",
|
|
1694
|
+
run: bin("check-principal-test-plan-wait"),
|
|
1695
|
+
scope: "diff",
|
|
1696
|
+
timeoutMs: 15000,
|
|
1697
|
+
requiresOpenPr: true,
|
|
1698
|
+
ownWorkflow: true,
|
|
1699
|
+
env: {
|
|
1700
|
+
PR_BODY: { optional: true },
|
|
1701
|
+
BRANCH: { optional: true }
|
|
1702
|
+
}
|
|
1703
|
+
},
|
|
1704
|
+
1
|
|
1705
|
+
],
|
|
1706
|
+
[
|
|
1707
|
+
{
|
|
1708
|
+
name: "body-bare-digits",
|
|
1709
|
+
validates: "body",
|
|
1710
|
+
run: bin("check-body-bare-digits"),
|
|
1711
|
+
scope: "diff",
|
|
1712
|
+
timeoutMs: 15000,
|
|
1713
|
+
requiresOpenPr: true,
|
|
1714
|
+
ownWorkflow: true,
|
|
1715
|
+
env: {
|
|
1716
|
+
PR_BODY: { optional: true },
|
|
1717
|
+
PR_NUMBER: { optional: true },
|
|
1718
|
+
GITHUB_REPOSITORY: { optional: true },
|
|
1719
|
+
GITHUB_TOKEN: { optional: true },
|
|
1720
|
+
GH_TOKEN: { optional: true }
|
|
1721
|
+
}
|
|
1722
|
+
},
|
|
1723
|
+
1
|
|
1724
|
+
],
|
|
1725
|
+
[
|
|
1726
|
+
{
|
|
1727
|
+
name: "token-report",
|
|
1728
|
+
validates: "body",
|
|
1729
|
+
run: bin("check-token-report"),
|
|
1730
|
+
scope: "diff",
|
|
1731
|
+
timeoutMs: 15000,
|
|
1732
|
+
requiresOpenPr: true,
|
|
1733
|
+
env: {
|
|
1734
|
+
PR_BODY: { optional: true },
|
|
1735
|
+
BRANCH: { optional: true },
|
|
1736
|
+
CLAUDE_PROJECT_DIR: { optional: true },
|
|
1737
|
+
CLAUDE_CODE_SESSION_ID: { optional: true }
|
|
1738
|
+
}
|
|
1739
|
+
},
|
|
1740
|
+
1
|
|
1741
|
+
],
|
|
1742
|
+
[
|
|
1743
|
+
{
|
|
1744
|
+
name: "no-disk-state",
|
|
1745
|
+
run: bin("check-no-disk-state"),
|
|
1746
|
+
scope: "diff",
|
|
1747
|
+
timeoutMs: 15000,
|
|
1748
|
+
env: { BASE_SHA: { optional: true } }
|
|
1749
|
+
},
|
|
1750
|
+
0
|
|
1751
|
+
],
|
|
1752
|
+
[
|
|
1753
|
+
{
|
|
1754
|
+
name: "registry-gates",
|
|
1755
|
+
run: bin("check-registry-gates"),
|
|
1756
|
+
scope: "full",
|
|
1757
|
+
timeoutMs: 30000,
|
|
1758
|
+
env: {
|
|
1759
|
+
AEG_REPO: { optional: true },
|
|
1760
|
+
GITHUB_TOKEN: { optional: true },
|
|
1761
|
+
GH_TOKEN: { optional: true }
|
|
1762
|
+
}
|
|
1763
|
+
},
|
|
1764
|
+
0
|
|
1765
|
+
],
|
|
1766
|
+
[
|
|
1767
|
+
{
|
|
1768
|
+
name: "review-gate",
|
|
1769
|
+
run: bin("check-review-gate"),
|
|
1770
|
+
scope: "full",
|
|
1771
|
+
timeoutMs: 30000,
|
|
1772
|
+
ownWorkflow: true,
|
|
1773
|
+
env: {
|
|
1774
|
+
PR_NUMBER: { optional: true },
|
|
1775
|
+
GITHUB_REPOSITORY: { optional: true },
|
|
1776
|
+
GITHUB_TOKEN: { optional: true },
|
|
1777
|
+
GH_TOKEN: { optional: true }
|
|
1778
|
+
}
|
|
1779
|
+
},
|
|
1780
|
+
1
|
|
1781
|
+
],
|
|
1782
|
+
[
|
|
1783
|
+
{
|
|
1784
|
+
name: "branch-topology",
|
|
1785
|
+
run: bin("check-branch-topology"),
|
|
1786
|
+
scope: "full",
|
|
1787
|
+
timeoutMs: 30000,
|
|
1788
|
+
env: {
|
|
1789
|
+
BRANCH: { optional: true },
|
|
1790
|
+
AEG_REPO: { optional: true },
|
|
1791
|
+
GITHUB_TOKEN: { optional: true },
|
|
1792
|
+
GH_TOKEN: { optional: true }
|
|
1793
|
+
}
|
|
1794
|
+
},
|
|
1795
|
+
0
|
|
1796
|
+
],
|
|
1797
|
+
[
|
|
1798
|
+
{
|
|
1799
|
+
name: "dead-branch-push",
|
|
1800
|
+
run: bin("check-dead-branch-push"),
|
|
1801
|
+
scope: "full",
|
|
1802
|
+
timeoutMs: 30000,
|
|
1803
|
+
env: {
|
|
1804
|
+
BRANCH: { optional: true },
|
|
1805
|
+
GITHUB_TOKEN: { optional: true },
|
|
1806
|
+
GH_TOKEN: { optional: true }
|
|
1807
|
+
}
|
|
1808
|
+
},
|
|
1809
|
+
0
|
|
1810
|
+
],
|
|
1811
|
+
[
|
|
1812
|
+
{
|
|
1813
|
+
name: "first-push-dispatch",
|
|
1814
|
+
run: bin("check-first-push-dispatch"),
|
|
1815
|
+
scope: "full",
|
|
1816
|
+
timeoutMs: 30000,
|
|
1817
|
+
env: {
|
|
1818
|
+
BRANCH: { optional: true },
|
|
1819
|
+
AEG_REPO: { optional: true },
|
|
1820
|
+
GITHUB_TOKEN: { optional: true },
|
|
1821
|
+
GH_TOKEN: { optional: true }
|
|
1822
|
+
}
|
|
1823
|
+
},
|
|
1824
|
+
0
|
|
1825
|
+
],
|
|
1826
|
+
[
|
|
1827
|
+
{
|
|
1828
|
+
name: "doc-coverage-push",
|
|
1829
|
+
validates: "body",
|
|
1830
|
+
run: bin("check-doc-coverage-push"),
|
|
1831
|
+
scope: "diff",
|
|
1832
|
+
timeoutMs: 15000,
|
|
1833
|
+
env: {
|
|
1834
|
+
OVERRIDE_DOCS: { optional: true },
|
|
1835
|
+
BASE_SHA: { optional: true },
|
|
1836
|
+
PR_BODY: { optional: true },
|
|
1837
|
+
PR_BODY_FILE: { optional: true },
|
|
1838
|
+
PR_LABELS: { optional: true },
|
|
1839
|
+
WAIVER_LABEL_ACTOR: { optional: true },
|
|
1840
|
+
GITHUB_REPOSITORY: { optional: true },
|
|
1841
|
+
GITHUB_TOKEN: { optional: true },
|
|
1842
|
+
GH_TOKEN: { optional: true }
|
|
1843
|
+
}
|
|
1844
|
+
},
|
|
1845
|
+
0
|
|
1846
|
+
],
|
|
1847
|
+
[
|
|
1848
|
+
{
|
|
1849
|
+
name: "issue-assignment",
|
|
1850
|
+
run: bin("check-issue-assignment"),
|
|
1851
|
+
scope: "full",
|
|
1852
|
+
timeoutMs: 30000,
|
|
1853
|
+
env: {
|
|
1854
|
+
AEG_REPO: { optional: true },
|
|
1855
|
+
BRANCH: { optional: true },
|
|
1856
|
+
GITHUB_TOKEN: { optional: true },
|
|
1857
|
+
GH_TOKEN: { optional: true }
|
|
1858
|
+
}
|
|
1859
|
+
},
|
|
1860
|
+
0
|
|
1861
|
+
],
|
|
1862
|
+
[
|
|
1863
|
+
{
|
|
1864
|
+
name: "evidence-fresh",
|
|
1865
|
+
validates: "body",
|
|
1866
|
+
run: bin("check-evidence-fresh"),
|
|
1867
|
+
scope: "diff",
|
|
1868
|
+
timeoutMs: 15000,
|
|
1869
|
+
requiresOpenPr: true,
|
|
1870
|
+
env: {
|
|
1871
|
+
PR_NUMBER: { optional: true },
|
|
1872
|
+
PR_BODY: { optional: true },
|
|
1873
|
+
BASE_SHA: { optional: true },
|
|
1874
|
+
GITHUB_TOKEN: { optional: true },
|
|
1875
|
+
GH_TOKEN: { optional: true }
|
|
1876
|
+
}
|
|
1877
|
+
},
|
|
1878
|
+
1
|
|
1879
|
+
],
|
|
1880
|
+
[
|
|
1881
|
+
{
|
|
1882
|
+
name: "reader-resolvable-prose",
|
|
1883
|
+
run: bin("check-reader-resolvable-prose"),
|
|
1884
|
+
scope: "full",
|
|
1885
|
+
timeoutMs: 30000,
|
|
1886
|
+
env: {},
|
|
1887
|
+
include: [
|
|
1888
|
+
"aeg-root/**/*.md",
|
|
1889
|
+
"apps/cli/src/**",
|
|
1890
|
+
".github/workflows/**",
|
|
1891
|
+
".vinaya/**",
|
|
1892
|
+
"apps/cli/README.md",
|
|
1893
|
+
"packages/sources/README.md"
|
|
1894
|
+
]
|
|
1895
|
+
},
|
|
1896
|
+
0
|
|
1897
|
+
],
|
|
1898
|
+
[
|
|
1899
|
+
{
|
|
1900
|
+
name: "retired-vocabulary",
|
|
1901
|
+
run: bin("check-retired-vocabulary"),
|
|
1902
|
+
scope: "full",
|
|
1903
|
+
timeoutMs: 30000,
|
|
1904
|
+
env: {},
|
|
1905
|
+
include: ["aeg-root/**/*.md"]
|
|
1906
|
+
},
|
|
1907
|
+
0
|
|
1908
|
+
],
|
|
1909
|
+
[
|
|
1910
|
+
{
|
|
1911
|
+
name: "doctrine-portability",
|
|
1912
|
+
run: bin("check-doctrine-portability"),
|
|
1913
|
+
scope: "full",
|
|
1914
|
+
timeoutMs: 30000,
|
|
1915
|
+
env: { BASE_SHA: { optional: true } },
|
|
1916
|
+
include: ["aeg-root/**/*.md"]
|
|
1917
|
+
},
|
|
1918
|
+
0
|
|
1919
|
+
],
|
|
1920
|
+
[
|
|
1921
|
+
{
|
|
1922
|
+
name: "doctrine-no-procedures",
|
|
1923
|
+
run: bin("check-doctrine-no-procedures"),
|
|
1924
|
+
scope: "full",
|
|
1925
|
+
timeoutMs: 30000,
|
|
1926
|
+
env: {},
|
|
1927
|
+
include: ["aeg-root/**/*.md"]
|
|
1928
|
+
},
|
|
1929
|
+
0
|
|
1930
|
+
],
|
|
1931
|
+
[
|
|
1932
|
+
{
|
|
1933
|
+
name: "exec-bits",
|
|
1934
|
+
run: bin("check-exec-bits"),
|
|
1935
|
+
scope: "diff",
|
|
1936
|
+
timeoutMs: 30000,
|
|
1937
|
+
env: {}
|
|
1938
|
+
},
|
|
1939
|
+
0
|
|
1940
|
+
],
|
|
1941
|
+
[
|
|
1942
|
+
{
|
|
1943
|
+
name: "ci-shard-coverage",
|
|
1944
|
+
run: bin("check-ci-shard-coverage"),
|
|
1945
|
+
scope: "diff",
|
|
1946
|
+
timeoutMs: 15000,
|
|
1947
|
+
env: {}
|
|
1948
|
+
},
|
|
1949
|
+
0
|
|
1950
|
+
],
|
|
1951
|
+
[
|
|
1952
|
+
{
|
|
1953
|
+
name: "workspace-escape",
|
|
1954
|
+
run: bin("check-workspace-escape"),
|
|
1955
|
+
scope: "full",
|
|
1956
|
+
timeoutMs: 30000,
|
|
1957
|
+
env: {},
|
|
1958
|
+
include: ["aeg-root/**/*.md"]
|
|
1959
|
+
},
|
|
1960
|
+
0
|
|
1961
|
+
],
|
|
1962
|
+
[
|
|
1963
|
+
{
|
|
1964
|
+
name: "changeset-coverage",
|
|
1965
|
+
run: bin("check-changeset-coverage"),
|
|
1966
|
+
scope: "diff",
|
|
1967
|
+
timeoutMs: 15000,
|
|
1968
|
+
env: {}
|
|
1969
|
+
},
|
|
1970
|
+
0
|
|
1971
|
+
],
|
|
1972
|
+
[
|
|
1973
|
+
{
|
|
1974
|
+
name: "quoted-command",
|
|
1975
|
+
run: bin("check-quoted-command"),
|
|
1976
|
+
scope: "diff",
|
|
1977
|
+
timeoutMs: 15000,
|
|
1978
|
+
env: {}
|
|
1979
|
+
},
|
|
1980
|
+
0
|
|
1981
|
+
],
|
|
1982
|
+
[
|
|
1983
|
+
{
|
|
1984
|
+
name: "main-branch-refusal",
|
|
1985
|
+
run: bin("check-main-branch-refusal"),
|
|
1986
|
+
scope: "full",
|
|
1987
|
+
timeoutMs: 15000,
|
|
1988
|
+
env: { VINAYA_PUSH_REFS: { optional: true } }
|
|
1989
|
+
},
|
|
1990
|
+
0
|
|
1991
|
+
],
|
|
1992
|
+
[
|
|
1993
|
+
{
|
|
1994
|
+
name: "token-collection-wired",
|
|
1995
|
+
run: bin("check-token-collection-wired"),
|
|
1996
|
+
scope: "full",
|
|
1997
|
+
timeoutMs: 15000,
|
|
1998
|
+
env: {
|
|
1999
|
+
CLAUDE_PROJECT_DIR: { optional: true },
|
|
2000
|
+
CLAUDE_CODE_SESSION_ID: { optional: true }
|
|
2001
|
+
}
|
|
2002
|
+
},
|
|
2003
|
+
0
|
|
2004
|
+
],
|
|
2005
|
+
[
|
|
2006
|
+
{
|
|
2007
|
+
name: "issue-title-grammar",
|
|
2008
|
+
run: bin("check-issue-title-grammar"),
|
|
2009
|
+
validates: "issue",
|
|
2010
|
+
scope: "full",
|
|
2011
|
+
ownWorkflow: true,
|
|
2012
|
+
timeoutMs: 15000,
|
|
2013
|
+
env: { ISSUE_TITLE: { optional: true } }
|
|
2014
|
+
},
|
|
2015
|
+
1
|
|
2016
|
+
],
|
|
2017
|
+
[
|
|
2018
|
+
{
|
|
2019
|
+
name: "issue-objectives-numbering",
|
|
2020
|
+
run: bin("check-issue-objectives-numbering"),
|
|
2021
|
+
validates: "issue",
|
|
2022
|
+
scope: "full",
|
|
2023
|
+
ownWorkflow: true,
|
|
2024
|
+
timeoutMs: 15000,
|
|
2025
|
+
env: { ISSUE_BODY: { optional: true }, ISSUE_NUMBER: { optional: true } }
|
|
2026
|
+
},
|
|
2027
|
+
1
|
|
2028
|
+
],
|
|
2029
|
+
[
|
|
2030
|
+
{
|
|
2031
|
+
name: "issue-parts-coverage",
|
|
2032
|
+
run: bin("check-issue-parts-coverage"),
|
|
2033
|
+
validates: "issue",
|
|
2034
|
+
scope: "full",
|
|
2035
|
+
ownWorkflow: true,
|
|
2036
|
+
timeoutMs: 15000,
|
|
2037
|
+
env: { ISSUE_BODY: { optional: true } }
|
|
2038
|
+
},
|
|
2039
|
+
1
|
|
2040
|
+
],
|
|
2041
|
+
[
|
|
2042
|
+
{
|
|
2043
|
+
name: "issue-surface-globs",
|
|
2044
|
+
run: bin("check-issue-surface-globs"),
|
|
2045
|
+
validates: "issue",
|
|
2046
|
+
scope: "full",
|
|
2047
|
+
ownWorkflow: true,
|
|
2048
|
+
timeoutMs: 15000,
|
|
2049
|
+
env: { ISSUE_BODY: { optional: true } }
|
|
2050
|
+
},
|
|
2051
|
+
1
|
|
2052
|
+
],
|
|
2053
|
+
[
|
|
2054
|
+
{
|
|
2055
|
+
name: "issue-tranche-label",
|
|
2056
|
+
run: bin("check-issue-tranche-label"),
|
|
2057
|
+
validates: "issue",
|
|
2058
|
+
scope: "full",
|
|
2059
|
+
ownWorkflow: true,
|
|
2060
|
+
timeoutMs: 15000,
|
|
2061
|
+
env: { ISSUE_BODY: { optional: true }, ISSUE_LABELS: { optional: true } }
|
|
2062
|
+
},
|
|
2063
|
+
1
|
|
2064
|
+
],
|
|
2065
|
+
[
|
|
2066
|
+
{
|
|
2067
|
+
name: "issue-milestone-attach",
|
|
2068
|
+
run: bin("check-issue-milestone-attach"),
|
|
2069
|
+
validates: "issue",
|
|
2070
|
+
scope: "full",
|
|
2071
|
+
ownWorkflow: true,
|
|
2072
|
+
timeoutMs: 15000,
|
|
2073
|
+
env: {
|
|
2074
|
+
ISSUE_LABELS: { optional: true },
|
|
2075
|
+
CURRENT_MILESTONE_TITLE: { optional: true },
|
|
2076
|
+
RESOLVED_MILESTONE_TITLE: { optional: true }
|
|
2077
|
+
}
|
|
2078
|
+
},
|
|
2079
|
+
1
|
|
2080
|
+
]
|
|
2081
|
+
];
|
|
2082
|
+
function coreCheckRegistry() {
|
|
2083
|
+
return REGISTRY.map(([spec]) => spec);
|
|
2084
|
+
}
|
|
2085
|
+
var CORE_CHECK_RING = Object.fromEntries(REGISTRY.map(([spec, ring]) => [spec.name, ring]));
|
|
2086
|
+
|
|
2087
|
+
// src/lib/log-sink.ts
|
|
2088
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
2089
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
2090
|
+
import {
|
|
2091
|
+
closeSync as closeSync4,
|
|
2092
|
+
constants as fsConstants4,
|
|
2093
|
+
existsSync as existsSync6,
|
|
2094
|
+
fstatSync as fstatSync2,
|
|
2095
|
+
mkdirSync as mkdirSync4,
|
|
2096
|
+
openSync as openSync4,
|
|
2097
|
+
readFileSync as readFileSync5,
|
|
2098
|
+
renameSync as renameSync3,
|
|
2099
|
+
writeSync as writeSync3
|
|
2100
|
+
} from "node:fs";
|
|
2101
|
+
import { hostname as osHostname, homedir as homedir3 } from "node:os";
|
|
2102
|
+
import { dirname as dirname6, join as join7 } from "node:path";
|
|
2103
|
+
import { promisify as promisify5 } from "node:util";
|
|
2104
|
+
|
|
2105
|
+
// src/lib/config.ts
|
|
2106
|
+
import { execFile as execFile4, execFileSync as execFileSync2 } from "node:child_process";
|
|
2107
|
+
import { promisify as promisify4 } from "node:util";
|
|
2108
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync3, realpathSync, writeFileSync } from "node:fs";
|
|
2109
|
+
import { homedir } from "node:os";
|
|
2110
|
+
import { dirname as dirname3, isAbsolute, join as join4, resolve as resolve2 } from "node:path";
|
|
2111
|
+
import { z as z4 } from "zod";
|
|
2112
|
+
|
|
2113
|
+
// src/lib/agent-vendors.ts
|
|
2114
|
+
var AGENT_VENDORS = ["skills", "claude", "gemini"];
|
|
2115
|
+
|
|
2116
|
+
// src/lib/config.ts
|
|
2117
|
+
var EnvEntrySchema = z4.union([
|
|
2118
|
+
z4.literal(true),
|
|
2119
|
+
z4.object({ optional: z4.literal(true) }),
|
|
2120
|
+
z4.object({ anyOf: z4.array(z4.string()).min(2) }),
|
|
2121
|
+
z4.string()
|
|
2122
|
+
]);
|
|
2123
|
+
var CheckEntrySchema = z4.object({
|
|
2124
|
+
run: z4.string(),
|
|
2125
|
+
scope: z4.enum(["diff", "full"]),
|
|
2126
|
+
include: z4.array(z4.string()).optional(),
|
|
2127
|
+
args: z4.array(z4.string()).optional(),
|
|
2128
|
+
timeoutMs: z4.number().optional(),
|
|
2129
|
+
env: z4.record(z4.string(), EnvEntrySchema).optional(),
|
|
2130
|
+
requiresOpenPr: z4.boolean().optional(),
|
|
2131
|
+
ownWorkflow: z4.boolean().optional(),
|
|
2132
|
+
principalOwed: z4.literal(true).optional(),
|
|
2133
|
+
validates: z4.enum(["body", "issue"]).optional()
|
|
2134
|
+
}).superRefine((entry, ctx) => {
|
|
2135
|
+
if (!entry.env)
|
|
2136
|
+
return;
|
|
2137
|
+
for (const [key, value] of Object.entries(entry.env)) {
|
|
2138
|
+
if (typeof value !== "object" || value === null || !("anyOf" in value))
|
|
2139
|
+
continue;
|
|
2140
|
+
const members = value.anyOf;
|
|
2141
|
+
if (new Set(members).size !== members.length) {
|
|
2142
|
+
ctx.addIssue({
|
|
2143
|
+
code: z4.ZodIssueCode.custom,
|
|
2144
|
+
message: `env.${key}.anyOf has duplicate members`,
|
|
2145
|
+
path: ["env", key, "anyOf"]
|
|
2146
|
+
});
|
|
2147
|
+
}
|
|
2148
|
+
if (!members.includes(key)) {
|
|
2149
|
+
ctx.addIssue({
|
|
2150
|
+
code: z4.ZodIssueCode.custom,
|
|
2151
|
+
message: `env.${key}.anyOf must include "${key}" itself as a member`,
|
|
2152
|
+
path: ["env", key, "anyOf"]
|
|
2153
|
+
});
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
});
|
|
2157
|
+
var RoleEntrySchema = z4.object({
|
|
2158
|
+
contract: z4.string().refine((p) => p.includes("/"), {
|
|
2159
|
+
message: 'must be a path (contain at least one "/"), not a bare filename'
|
|
2160
|
+
})
|
|
2161
|
+
});
|
|
2162
|
+
var MAX_REPORT_COMMAND_TIMEOUT_MS = 3600000;
|
|
2163
|
+
var BRIEF_BUILTINS = [
|
|
2164
|
+
"tier",
|
|
2165
|
+
"testPlan",
|
|
2166
|
+
"testPlanExclusivity",
|
|
2167
|
+
"principalPlaceholder",
|
|
2168
|
+
"surfaceMap",
|
|
2169
|
+
"docUpdateList",
|
|
2170
|
+
"worktreeStep0",
|
|
2171
|
+
"stopConditions",
|
|
2172
|
+
"autonomyClause",
|
|
2173
|
+
"project",
|
|
2174
|
+
"for",
|
|
2175
|
+
"closesN",
|
|
2176
|
+
"premiseCoverage",
|
|
2177
|
+
"issueRationale",
|
|
2178
|
+
"objectives",
|
|
2179
|
+
"briefSections",
|
|
2180
|
+
"milestoneShape"
|
|
2181
|
+
];
|
|
2182
|
+
var BriefSectionSchema = z4.union([
|
|
2183
|
+
z4.object({ builtin: z4.enum(BRIEF_BUILTINS) }),
|
|
2184
|
+
z4.object({ heading: z4.string().min(1), name: z4.string().optional() }),
|
|
2185
|
+
z4.object({ field: z4.string().min(1), name: z4.string().optional() }),
|
|
2186
|
+
z4.object({ phrase: z4.string().min(1), name: z4.string().optional() })
|
|
2187
|
+
]);
|
|
2188
|
+
var BriefSchemaSchema = z4.object({
|
|
2189
|
+
pr: z4.object({ sections: z4.array(BriefSectionSchema) }).optional(),
|
|
2190
|
+
issue: z4.object({ sections: z4.array(BriefSectionSchema) }).optional(),
|
|
2191
|
+
milestone: z4.object({ sections: z4.array(BriefSectionSchema) }).optional(),
|
|
2192
|
+
ack: z4.array(z4.enum(BRIEF_BUILTINS)).optional()
|
|
2193
|
+
});
|
|
2194
|
+
function isSafeRepoRelPath(p) {
|
|
2195
|
+
if (p.length === 0)
|
|
2196
|
+
return false;
|
|
2197
|
+
if (p.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(p))
|
|
2198
|
+
return false;
|
|
2199
|
+
return p.split(/[\\/]/).every((seg) => seg !== ".." && seg !== "");
|
|
2200
|
+
}
|
|
2201
|
+
var SafeRepoRelPath = z4.string().refine(isSafeRepoRelPath, {
|
|
2202
|
+
message: "must be a repo-root-relative path with no `..` segment or absolute root"
|
|
2203
|
+
});
|
|
2204
|
+
var CANONICAL_HOOK_BLOCK_PREFIXES = [".git/", ".husky/", ".vinaya/hooks/", ".claude/hooks/"];
|
|
2205
|
+
function isCanonicalHookBlockPath(p) {
|
|
2206
|
+
return CANONICAL_HOOK_BLOCK_PREFIXES.some((prefix) => p.startsWith(prefix) && p.length > prefix.length);
|
|
2207
|
+
}
|
|
2208
|
+
var ManagedHookBlockPath = SafeRepoRelPath.refine(isCanonicalHookBlockPath, {
|
|
2209
|
+
message: `must start with one of ${CANONICAL_HOOK_BLOCK_PREFIXES.join(", ")} (byte-exact, case-sensitive)`
|
|
2210
|
+
});
|
|
2211
|
+
var ManagedBlockRecordSchema = z4.object({
|
|
2212
|
+
path: ManagedHookBlockPath,
|
|
2213
|
+
marker: z4.string(),
|
|
2214
|
+
comment: z4.enum(["hash", "html"])
|
|
2215
|
+
});
|
|
2216
|
+
var ManagedManifestSchema = z4.object({
|
|
2217
|
+
version: z4.number().int().positive(),
|
|
2218
|
+
files: z4.array(SafeRepoRelPath),
|
|
2219
|
+
blocks: z4.array(ManagedBlockRecordSchema),
|
|
2220
|
+
labels: z4.array(z4.string()),
|
|
2221
|
+
agents: z4.array(z4.enum(AGENT_VENDORS)).optional()
|
|
2222
|
+
});
|
|
2223
|
+
var ProjectEntrySchema = z4.object({
|
|
2224
|
+
name: z4.string().min(1),
|
|
2225
|
+
description: z4.string().min(1).optional(),
|
|
2226
|
+
path: z4.string().min(1).optional()
|
|
2227
|
+
});
|
|
2228
|
+
function parseTokensCollectDeclaration(value) {
|
|
2229
|
+
const m = value.trim().match(/^(\S+)\s+(\S+)$/);
|
|
2230
|
+
if (!m)
|
|
2231
|
+
return null;
|
|
2232
|
+
const [, interpreter, script] = m;
|
|
2233
|
+
if (!isSafeRepoRelPath(script))
|
|
2234
|
+
return null;
|
|
2235
|
+
return { interpreter, script };
|
|
2236
|
+
}
|
|
2237
|
+
var VinayaConfigSchema = z4.object({
|
|
2238
|
+
rings: z4.object({
|
|
2239
|
+
ring1_forgeWriteInterception: z4.boolean(),
|
|
2240
|
+
ring2_asyncAudits: z4.boolean()
|
|
2241
|
+
}).optional(),
|
|
2242
|
+
checks: z4.record(z4.string(), CheckEntrySchema).optional(),
|
|
2243
|
+
roles: z4.record(z4.string(), RoleEntrySchema).optional(),
|
|
2244
|
+
briefSchema: BriefSchemaSchema.optional(),
|
|
2245
|
+
managed: ManagedManifestSchema.optional(),
|
|
2246
|
+
principals: z4.array(z4.string()).min(1).optional(),
|
|
2247
|
+
releaseActor: z4.string().min(1).optional(),
|
|
2248
|
+
ci: z4.object({ setup: z4.string().min(1) }).optional(),
|
|
2249
|
+
tokens: z4.object({
|
|
2250
|
+
collect: z4.string().min(1).refine((v) => parseTokensCollectDeclaration(v) !== null, {
|
|
2251
|
+
message: 'tokens.collect must be exactly "<interpreter> <repo-relative-script-path>" — two whitespace-separated tokens, no flags, no shell syntax, no quoting'
|
|
2252
|
+
})
|
|
2253
|
+
}).optional(),
|
|
2254
|
+
blastRadius: z4.object({ extraDomains: z4.array(z4.string()).optional() }).optional(),
|
|
2255
|
+
proseGates: z4.object({
|
|
2256
|
+
doctrineRoot: z4.string().min(1).optional(),
|
|
2257
|
+
readerFacingPrefix: z4.string().min(1).optional(),
|
|
2258
|
+
readerFacingSuffix: z4.string().min(1).optional(),
|
|
2259
|
+
legacySlugDir: z4.string().min(1).optional(),
|
|
2260
|
+
sourceComments: z4.object({
|
|
2261
|
+
globs: z4.array(z4.string().min(1)).optional(),
|
|
2262
|
+
allowlist: z4.array(z4.string().min(1)).optional(),
|
|
2263
|
+
severity: z4.enum(["warning", "error"]).optional()
|
|
2264
|
+
}).optional(),
|
|
2265
|
+
specGrandfather: z4.array(z4.string().min(1)).optional()
|
|
2266
|
+
}).optional(),
|
|
2267
|
+
projects: z4.array(ProjectEntrySchema).optional(),
|
|
2268
|
+
dispatch: z4.object({
|
|
2269
|
+
timeoutMs: z4.number().int().positive().optional(),
|
|
2270
|
+
killGraceMs: z4.number().int().positive().optional(),
|
|
2271
|
+
agent: z4.enum(["claude", "codex", "gemini"]).optional(),
|
|
2272
|
+
requireWorkerIsolation: z4.boolean().optional()
|
|
2273
|
+
}).optional(),
|
|
2274
|
+
reviewPolicy: z4.object({
|
|
2275
|
+
codeReviewThreshold: z4.string().min(1).optional(),
|
|
2276
|
+
securityThreshold: z4.string().min(1).optional(),
|
|
2277
|
+
maxRounds: z4.number().optional()
|
|
2278
|
+
}).optional(),
|
|
2279
|
+
prePush: z4.object({
|
|
2280
|
+
alwaysRun: z4.array(z4.string()).optional()
|
|
2281
|
+
}).optional(),
|
|
2282
|
+
report: z4.object({
|
|
2283
|
+
commandTimeoutMs: z4.number().int().positive().optional()
|
|
2284
|
+
}).superRefine((report, ctx) => {
|
|
2285
|
+
const commandTimeoutMs = report.commandTimeoutMs;
|
|
2286
|
+
if (commandTimeoutMs !== undefined && commandTimeoutMs > MAX_REPORT_COMMAND_TIMEOUT_MS) {
|
|
2287
|
+
ctx.addIssue({
|
|
2288
|
+
code: z4.ZodIssueCode.custom,
|
|
2289
|
+
path: ["commandTimeoutMs"],
|
|
2290
|
+
message: "must be at most 3600000 (1 hour)"
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
}).optional(),
|
|
2294
|
+
logPublish: z4.unknown().refine((v) => v === undefined, {
|
|
2295
|
+
message: "logPublish is removed — telemetry is never posted to a tracker or a code host; configure `logs` instead (a folder or a server destination)"
|
|
2296
|
+
}),
|
|
2297
|
+
runtimeDir: z4.string().min(1).refine((v) => isAbsolute(v), { message: "runtimeDir: must be an absolute path" }).optional(),
|
|
2298
|
+
logs: z4.object({
|
|
2299
|
+
folder: z4.string().min(1).refine((v) => isAbsolute(v), { message: "logs.folder: must be an absolute path" }).optional(),
|
|
2300
|
+
url: z4.string().url().optional(),
|
|
2301
|
+
headers: z4.record(z4.string()).optional()
|
|
2302
|
+
}).refine((v) => [v.folder, v.url].filter((x) => x !== undefined).length <= 1, {
|
|
2303
|
+
message: "logs: set at most one of folder/url"
|
|
2304
|
+
}).refine((v) => v.headers === undefined || v.url !== undefined, {
|
|
2305
|
+
message: "logs: headers requires url"
|
|
2306
|
+
}).optional()
|
|
2307
|
+
});
|
|
2308
|
+
var GLOBAL_VINAYA_HOME = join4(homedir(), ".vinaya");
|
|
2309
|
+
var GLOBAL_CONFIG_PATH = join4(GLOBAL_VINAYA_HOME, "config.json");
|
|
2310
|
+
var LOCAL_CONFIG_FILENAME = "vinaya.config.json";
|
|
2311
|
+
function findLocalConfig() {
|
|
2312
|
+
let dir = process.cwd();
|
|
2313
|
+
while (true) {
|
|
2314
|
+
const candidate = join4(dir, LOCAL_CONFIG_FILENAME);
|
|
2315
|
+
if (existsSync4(candidate))
|
|
2316
|
+
return candidate;
|
|
2317
|
+
if (existsSync4(join4(dir, ".git")))
|
|
2318
|
+
return null;
|
|
2319
|
+
const parent = dirname3(dir);
|
|
2320
|
+
if (parent === dir)
|
|
2321
|
+
return null;
|
|
2322
|
+
dir = parent;
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
function configPath() {
|
|
2326
|
+
const local = findLocalConfig();
|
|
2327
|
+
if (local)
|
|
2328
|
+
return local;
|
|
2329
|
+
if (existsSync4(GLOBAL_CONFIG_PATH))
|
|
2330
|
+
return GLOBAL_CONFIG_PATH;
|
|
2331
|
+
return null;
|
|
2332
|
+
}
|
|
2333
|
+
function globalChecksIgnoredWarning(path) {
|
|
2334
|
+
return `${path}: "checks" registration in the global config is ignored — checks may only be registered from a repo-local vinaya.config.json.`;
|
|
2335
|
+
}
|
|
2336
|
+
function globalPrincipalsIgnoredWarning(path) {
|
|
2337
|
+
return `${path}: "principals" in the global config is ignored — principals may only be declared from a repo-local vinaya.config.json.`;
|
|
2338
|
+
}
|
|
2339
|
+
function globalRolesIgnoredWarning(path) {
|
|
2340
|
+
return `${path}: "roles" registration in the global config is ignored — roles may only be registered from a repo-local vinaya.config.json.`;
|
|
2341
|
+
}
|
|
2342
|
+
function globalReleaseActorIgnoredWarning(path) {
|
|
2343
|
+
return `${path}: "releaseActor" in the global config is ignored — releaseActor may only be declared from a repo-local vinaya.config.json.`;
|
|
2344
|
+
}
|
|
2345
|
+
function globalTokensCollectIgnoredWarning(path) {
|
|
2346
|
+
return `${path}: "tokens" in the global config is ignored — tokens.collect may only be declared from a repo-local vinaya.config.json.`;
|
|
2347
|
+
}
|
|
2348
|
+
function globalRuntimeDirIgnoredWarning(path) {
|
|
2349
|
+
return `${path}: "runtimeDir" in the global config is ignored — it carries no repository segment, so a machine-wide value would collapse every repository's task folders into one tree. Declare it from a repo-local vinaya.config.json.`;
|
|
2350
|
+
}
|
|
2351
|
+
var emittedGlobalKeyWarnings = new Set;
|
|
2352
|
+
function warnGlobalKeyIgnoredOnce(message) {
|
|
2353
|
+
if (emittedGlobalKeyWarnings.has(message))
|
|
2354
|
+
return;
|
|
2355
|
+
emittedGlobalKeyWarnings.add(message);
|
|
2356
|
+
console.error(`⚠ ${message}`);
|
|
2357
|
+
}
|
|
2358
|
+
function stripGlobalOnlyKeys(config, path) {
|
|
2359
|
+
if (path !== GLOBAL_CONFIG_PATH)
|
|
2360
|
+
return config;
|
|
2361
|
+
let result = config;
|
|
2362
|
+
if (result.checks && Object.keys(result.checks).length > 0) {
|
|
2363
|
+
warnGlobalKeyIgnoredOnce(globalChecksIgnoredWarning(path));
|
|
2364
|
+
result = { ...result, checks: undefined };
|
|
2365
|
+
}
|
|
2366
|
+
if (result.roles && Object.keys(result.roles).length > 0) {
|
|
2367
|
+
warnGlobalKeyIgnoredOnce(globalRolesIgnoredWarning(path));
|
|
2368
|
+
result = { ...result, roles: undefined };
|
|
2369
|
+
}
|
|
2370
|
+
if (result.principals && result.principals.length > 0) {
|
|
2371
|
+
warnGlobalKeyIgnoredOnce(globalPrincipalsIgnoredWarning(path));
|
|
2372
|
+
result = { ...result, principals: undefined };
|
|
2373
|
+
}
|
|
2374
|
+
if (result.releaseActor) {
|
|
2375
|
+
warnGlobalKeyIgnoredOnce(globalReleaseActorIgnoredWarning(path));
|
|
2376
|
+
result = { ...result, releaseActor: undefined };
|
|
2377
|
+
}
|
|
2378
|
+
if (result.tokens) {
|
|
2379
|
+
warnGlobalKeyIgnoredOnce(globalTokensCollectIgnoredWarning(path));
|
|
2380
|
+
result = { ...result, tokens: undefined };
|
|
2381
|
+
}
|
|
2382
|
+
if (result.runtimeDir) {
|
|
2383
|
+
warnGlobalKeyIgnoredOnce(globalRuntimeDirIgnoredWarning(path));
|
|
2384
|
+
result = { ...result, runtimeDir: undefined };
|
|
2385
|
+
}
|
|
2386
|
+
return result;
|
|
2387
|
+
}
|
|
2388
|
+
function resolveRuntimeDirSetting(config) {
|
|
2389
|
+
return config?.runtimeDir ?? null;
|
|
2390
|
+
}
|
|
2391
|
+
function resolveTrustAnchorRuntimeDir(localRuntimeDir, trustAnchorConfig) {
|
|
2392
|
+
const anchored = resolveRuntimeDirSetting(trustAnchorConfig);
|
|
2393
|
+
return anchored !== null && anchored === localRuntimeDir ? anchored : null;
|
|
2394
|
+
}
|
|
2395
|
+
function resolveLogsSetting(config) {
|
|
2396
|
+
const raw = config?.logs;
|
|
2397
|
+
if (!raw)
|
|
2398
|
+
return null;
|
|
2399
|
+
if (raw.url !== undefined)
|
|
2400
|
+
return { url: raw.url, headers: raw.headers };
|
|
2401
|
+
if (raw.folder !== undefined)
|
|
2402
|
+
return { folder: raw.folder };
|
|
2403
|
+
return null;
|
|
2404
|
+
}
|
|
2405
|
+
function resolveTrustAnchorLogsDestination(local, trustAnchorConfig) {
|
|
2406
|
+
const anchored = resolveLogsSetting(trustAnchorConfig);
|
|
2407
|
+
if (!anchored)
|
|
2408
|
+
return null;
|
|
2409
|
+
if ("url" in local)
|
|
2410
|
+
return "url" in anchored && anchored.url === local.url ? anchored : null;
|
|
2411
|
+
return "folder" in anchored && anchored.folder === local.folder ? anchored : null;
|
|
2412
|
+
}
|
|
2413
|
+
function resolveLogsHeaderValues(headers, env) {
|
|
2414
|
+
if (!headers)
|
|
2415
|
+
return;
|
|
2416
|
+
const resolved = {};
|
|
2417
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
2418
|
+
resolved[key] = value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_match, name) => env[name] ?? "");
|
|
2419
|
+
}
|
|
2420
|
+
return resolved;
|
|
2421
|
+
}
|
|
2422
|
+
function trustAnchorRepo() {
|
|
2423
|
+
const fromRunner = trustAnchorRepoFromRunner();
|
|
2424
|
+
if (fromRunner)
|
|
2425
|
+
return fromRunner;
|
|
2426
|
+
try {
|
|
2427
|
+
const url = execFileSync2("git", ["remote", "get-url", "origin"], {
|
|
2428
|
+
encoding: "utf-8",
|
|
2429
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2430
|
+
});
|
|
2431
|
+
return trustAnchorRepoFromRemoteUrl(url);
|
|
2432
|
+
} catch {
|
|
2433
|
+
return null;
|
|
2434
|
+
}
|
|
2435
|
+
}
|
|
2436
|
+
async function trustAnchorRepoAsync() {
|
|
2437
|
+
const fromRunner = trustAnchorRepoFromRunner();
|
|
2438
|
+
if (fromRunner)
|
|
2439
|
+
return fromRunner;
|
|
2440
|
+
try {
|
|
2441
|
+
const { stdout } = await execFileAsync4("git", ["remote", "get-url", "origin"], {
|
|
2442
|
+
encoding: "utf-8",
|
|
2443
|
+
timeout: 1e4
|
|
2444
|
+
});
|
|
2445
|
+
return trustAnchorRepoFromRemoteUrl(stdout);
|
|
2446
|
+
} catch {
|
|
2447
|
+
return null;
|
|
2448
|
+
}
|
|
2449
|
+
}
|
|
2450
|
+
function wellFormedRepoSlug(slug) {
|
|
2451
|
+
return /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
2452
|
+
}
|
|
2453
|
+
function trustAnchorRepoFromRunner() {
|
|
2454
|
+
const fromRunner = process.env.GITHUB_REPOSITORY?.trim();
|
|
2455
|
+
return fromRunner ? wellFormedRepoSlug(fromRunner) : null;
|
|
2456
|
+
}
|
|
2457
|
+
function trustAnchorRepoFromRemoteUrl(url) {
|
|
2458
|
+
const m = url.trim().match(/github\.com[:/]([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
2459
|
+
return m?.[1] && m[2] ? wellFormedRepoSlug(`${m[1]}/${m[2]}`) : null;
|
|
2460
|
+
}
|
|
2461
|
+
var execFileAsync4 = promisify4(execFile4);
|
|
2462
|
+
function resolveCiTrustAnchorProbeRef(env = process.env) {
|
|
2463
|
+
const ref = env.VINAYA_CI_CONFIG_PROBE_REF?.trim();
|
|
2464
|
+
if (!ref)
|
|
2465
|
+
return null;
|
|
2466
|
+
if (env.GITHUB_ACTIONS !== "true")
|
|
2467
|
+
return null;
|
|
2468
|
+
if ((env.GH_TOKEN ?? "").length > 0 || (env.GITHUB_TOKEN ?? "").length > 0)
|
|
2469
|
+
return null;
|
|
2470
|
+
return ref;
|
|
2471
|
+
}
|
|
2472
|
+
function readTrustAnchorConfigAtRef(ref) {
|
|
2473
|
+
const raw = execFileSync2("git", ["show", `${ref}:${LOCAL_CONFIG_FILENAME}`], {
|
|
2474
|
+
encoding: "utf-8",
|
|
2475
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
2476
|
+
timeout: 1e4
|
|
2477
|
+
});
|
|
2478
|
+
return Buffer.from(raw, "utf-8").toString("base64");
|
|
2479
|
+
}
|
|
2480
|
+
function ghFetchTrustAnchorConfig() {
|
|
2481
|
+
const probeRef = resolveCiTrustAnchorProbeRef();
|
|
2482
|
+
if (probeRef)
|
|
2483
|
+
return readTrustAnchorConfigAtRef(probeRef);
|
|
2484
|
+
const repo = trustAnchorRepo();
|
|
2485
|
+
if (!repo)
|
|
2486
|
+
throw new Error("could not resolve repo identity for the trust-anchor read");
|
|
2487
|
+
return execFileSync2("gh", ["api", `repos/${repo}/contents/${LOCAL_CONFIG_FILENAME}`, "--jq", ".content"], {
|
|
2488
|
+
encoding: "utf-8",
|
|
2489
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2490
|
+
});
|
|
2491
|
+
}
|
|
2492
|
+
async function ghFetchTrustAnchorConfigAsync() {
|
|
2493
|
+
const probeRef = resolveCiTrustAnchorProbeRef();
|
|
2494
|
+
if (probeRef) {
|
|
2495
|
+
const { stdout } = await execFileAsync4("git", ["show", `${probeRef}:${LOCAL_CONFIG_FILENAME}`], {
|
|
2496
|
+
encoding: "utf-8",
|
|
2497
|
+
timeout: 1e4
|
|
2498
|
+
});
|
|
2499
|
+
return Buffer.from(stdout, "utf-8").toString("base64");
|
|
2500
|
+
}
|
|
2501
|
+
const repo = await trustAnchorRepoAsync();
|
|
2502
|
+
if (!repo)
|
|
2503
|
+
throw new Error("could not resolve repo identity for the trust-anchor read");
|
|
2504
|
+
const { stdout } = await execFileAsync4("gh", ["api", `repos/${repo}/contents/${LOCAL_CONFIG_FILENAME}`, "--jq", ".content"], { encoding: "utf-8", timeout: 1e4 });
|
|
2505
|
+
return stdout;
|
|
2506
|
+
}
|
|
2507
|
+
function firstLine(err) {
|
|
2508
|
+
return err?.message?.split(`
|
|
2509
|
+
`)[0] ?? "unknown error";
|
|
2510
|
+
}
|
|
2511
|
+
function isMissingFileError(err) {
|
|
2512
|
+
const stderr = err?.stderr;
|
|
2513
|
+
const haystack = [
|
|
2514
|
+
err?.message ?? "",
|
|
2515
|
+
typeof stderr === "string" ? stderr : stderr?.toString() ?? ""
|
|
2516
|
+
].join(`
|
|
2517
|
+
`);
|
|
2518
|
+
return /\b404\b|not found/i.test(haystack);
|
|
2519
|
+
}
|
|
2520
|
+
function loadTrustAnchorConfig(fetcher = ghFetchTrustAnchorConfig) {
|
|
2521
|
+
let base64;
|
|
2522
|
+
try {
|
|
2523
|
+
base64 = fetcher();
|
|
2524
|
+
} catch (err) {
|
|
2525
|
+
return trustAnchorFetchFailed(err);
|
|
2526
|
+
}
|
|
2527
|
+
return parseTrustAnchorContent(base64);
|
|
2528
|
+
}
|
|
2529
|
+
async function loadTrustAnchorConfigAsync(fetcher = ghFetchTrustAnchorConfigAsync, options = {}) {
|
|
2530
|
+
const warn = options.quiet ? () => {} : warnTrustAnchorFallback;
|
|
2531
|
+
let base64;
|
|
2532
|
+
try {
|
|
2533
|
+
base64 = await fetcher();
|
|
2534
|
+
} catch (err) {
|
|
2535
|
+
return trustAnchorFetchFailed(err, warn);
|
|
2536
|
+
}
|
|
2537
|
+
return parseTrustAnchorContent(base64, warn);
|
|
2538
|
+
}
|
|
2539
|
+
function warnTrustAnchorFallback(why) {
|
|
2540
|
+
process.stdout.write(`⚠ could not read the trust-anchor config (\`principals\`/\`releaseActor\`) from the default branch (${why}) — falling back to vinaya's built-in defaults.
|
|
2541
|
+
`);
|
|
2542
|
+
}
|
|
2543
|
+
function trustAnchorFetchFailed(err, warn = warnTrustAnchorFallback) {
|
|
2544
|
+
if (!isMissingFileError(err))
|
|
2545
|
+
warn(firstLine(err));
|
|
2546
|
+
return null;
|
|
2547
|
+
}
|
|
2548
|
+
function parseTrustAnchorContent(content, warn = warnTrustAnchorFallback) {
|
|
2549
|
+
const base64 = content.trim();
|
|
2550
|
+
if (!base64)
|
|
2551
|
+
return null;
|
|
2552
|
+
try {
|
|
2553
|
+
const raw = Buffer.from(base64, "base64").toString("utf-8");
|
|
2554
|
+
const parsed = VinayaConfigSchema.safeParse(JSON.parse(raw));
|
|
2555
|
+
if (parsed.success)
|
|
2556
|
+
return parsed.data;
|
|
2557
|
+
warn("it did not satisfy the config schema");
|
|
2558
|
+
return null;
|
|
2559
|
+
} catch {
|
|
2560
|
+
warn("it was not readable as JSON");
|
|
2561
|
+
return null;
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
function loadConfig() {
|
|
2565
|
+
const path = configPath();
|
|
2566
|
+
if (!path)
|
|
2567
|
+
return null;
|
|
2568
|
+
try {
|
|
2569
|
+
const raw = JSON.parse(readFileSync3(path, "utf-8"));
|
|
2570
|
+
return stripGlobalOnlyKeys(VinayaConfigSchema.parse(raw), path);
|
|
2571
|
+
} catch {
|
|
2572
|
+
return null;
|
|
2573
|
+
}
|
|
2574
|
+
}
|
|
2575
|
+
var TOKENS_COLLECT_TRUST_PATH = join4(GLOBAL_VINAYA_HOME, "tokens-collect-trust.json");
|
|
2576
|
+
|
|
2577
|
+
// src/lib/run-paths.ts
|
|
2578
|
+
import { execFileSync as execFileSync3 } from "node:child_process";
|
|
2579
|
+
import { chmodSync, existsSync as existsSync5, realpathSync as realpathSync2 } from "node:fs";
|
|
2580
|
+
import { dirname as dirname4, join as join5, resolve as resolvePath } from "node:path";
|
|
2581
|
+
var TASKS_EXECUTION_DIRNAME = "tasks-execution";
|
|
2582
|
+
var RUN_AREA_DIRNAMES = {
|
|
2583
|
+
control: CONTROL_AREA_DIRNAME,
|
|
2584
|
+
sessions: "sessions",
|
|
2585
|
+
hooks: "hooks",
|
|
2586
|
+
output: "output",
|
|
2587
|
+
rounds: "rounds"
|
|
2588
|
+
};
|
|
2589
|
+
var SAFE_PATH_SEGMENT = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;
|
|
2590
|
+
function isSafeRepoSegment(segment) {
|
|
2591
|
+
return SAFE_PATH_SEGMENT.test(segment) && !segment.includes("..");
|
|
2592
|
+
}
|
|
2593
|
+
function repoSegment(repo) {
|
|
2594
|
+
if (!repo || !isSafeRepoSegment(repo.owner) || !isSafeRepoSegment(repo.repo))
|
|
2595
|
+
return "unresolved";
|
|
2596
|
+
return `${repo.owner}-${repo.repo}`;
|
|
2597
|
+
}
|
|
2598
|
+
function defaultRuntimeDir(repo, home = GLOBAL_VINAYA_HOME) {
|
|
2599
|
+
return join5(home, "runtime", repoSegment(repo));
|
|
2600
|
+
}
|
|
2601
|
+
function resolveRuntimeDir(input) {
|
|
2602
|
+
const local = resolveRuntimeDirSetting(input.localConfig);
|
|
2603
|
+
if (local === null)
|
|
2604
|
+
return defaultRuntimeDir(input.repo, input.home);
|
|
2605
|
+
if (isInsideRepo(local, input.repoRoot))
|
|
2606
|
+
return defaultRuntimeDir(input.repo, input.home);
|
|
2607
|
+
if (!input.unattended)
|
|
2608
|
+
return local;
|
|
2609
|
+
const anchored = resolveTrustAnchorRuntimeDir(local, input.trustAnchorConfig ?? null);
|
|
2610
|
+
return anchored ?? defaultRuntimeDir(input.repo, input.home);
|
|
2611
|
+
}
|
|
2612
|
+
function isInsideRepo(candidate, repoRoot) {
|
|
2613
|
+
if (!repoRoot)
|
|
2614
|
+
return false;
|
|
2615
|
+
const root = resolvePath(repoRoot);
|
|
2616
|
+
const target = resolvePath(candidate);
|
|
2617
|
+
return target === root || target.startsWith(`${root}/`);
|
|
2618
|
+
}
|
|
2619
|
+
function runPath(runtimeDir, scope, location) {
|
|
2620
|
+
const dir = join5(runtimeDir, TASKS_EXECUTION_DIRNAME, scopeSegment(scope));
|
|
2621
|
+
switch (location.area) {
|
|
2622
|
+
case "task":
|
|
2623
|
+
return location.file ? join5(dir, location.file) : dir;
|
|
2624
|
+
case "control": {
|
|
2625
|
+
const controlDir = join5(dir, RUN_AREA_DIRNAMES.control);
|
|
2626
|
+
return location.file ? join5(controlDir, location.file) : controlDir;
|
|
2627
|
+
}
|
|
2628
|
+
case "rounds":
|
|
2629
|
+
return join5(dir, RUN_AREA_DIRNAMES.rounds);
|
|
2630
|
+
case "round": {
|
|
2631
|
+
const roundDir = join5(dir, RUN_AREA_DIRNAMES.rounds, String(location.round));
|
|
2632
|
+
return location.file ? join5(roundDir, location.file) : roundDir;
|
|
2633
|
+
}
|
|
2634
|
+
case "developer": {
|
|
2635
|
+
const developerDir = join5(dir, RUN_AREA_DIRNAMES.rounds, String(location.round), "developer");
|
|
2636
|
+
return location.file ? join5(developerDir, location.file) : developerDir;
|
|
2637
|
+
}
|
|
2638
|
+
default: {
|
|
2639
|
+
const areaDir = join5(dir, RUN_AREA_DIRNAMES[location.area]);
|
|
2640
|
+
return location.file ? join5(areaDir, location.file) : areaDir;
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
function scopeSegment(scope) {
|
|
2645
|
+
if (scope === "unscoped")
|
|
2646
|
+
return "unscoped";
|
|
2647
|
+
if (typeof scope === "number")
|
|
2648
|
+
return String(scope);
|
|
2649
|
+
return `pr-${scope.pr}`;
|
|
2650
|
+
}
|
|
2651
|
+
var UNATTENDED_ENV_KEY = "VINAYA_UNATTENDED";
|
|
2652
|
+
var RUNTIME_DIR_ENV_KEY = "VINAYA_RUNTIME_DIR";
|
|
2653
|
+
function isUnattendedProcess(env = process.env) {
|
|
2654
|
+
return env[UNATTENDED_ENV_KEY] === "1" || (env.VINAYA_ROLE ?? "") !== "";
|
|
2655
|
+
}
|
|
2656
|
+
var memoized = null;
|
|
2657
|
+
function runtimeDirForRepo(repo) {
|
|
2658
|
+
const key = repoSegment(repo);
|
|
2659
|
+
if (memoized?.key === key)
|
|
2660
|
+
return memoized.value;
|
|
2661
|
+
const value = resolveRuntimeDirUncached(repo);
|
|
2662
|
+
memoized = { key, value };
|
|
2663
|
+
return value;
|
|
2664
|
+
}
|
|
2665
|
+
async function runtimeDirForRepoAsync(repo) {
|
|
2666
|
+
const key = repoSegment(repo);
|
|
2667
|
+
if (memoized?.key === key)
|
|
2668
|
+
return memoized.value;
|
|
2669
|
+
const inputs = runtimeDirInputs();
|
|
2670
|
+
if (typeof inputs === "string")
|
|
2671
|
+
return inputs;
|
|
2672
|
+
const value = resolveRuntimeDir({
|
|
2673
|
+
repo,
|
|
2674
|
+
...inputs.base,
|
|
2675
|
+
trustAnchorConfig: inputs.needsAnchor ? await loadTrustAnchorConfigAsync() : null
|
|
2676
|
+
});
|
|
2677
|
+
memoized = { key, value };
|
|
2678
|
+
return value;
|
|
2679
|
+
}
|
|
2680
|
+
function resolveRuntimeDirUncached(repo) {
|
|
2681
|
+
const inputs = runtimeDirInputs();
|
|
2682
|
+
if (typeof inputs === "string")
|
|
2683
|
+
return inputs;
|
|
2684
|
+
return resolveRuntimeDir({
|
|
2685
|
+
repo,
|
|
2686
|
+
...inputs.base,
|
|
2687
|
+
trustAnchorConfig: inputs.needsAnchor ? loadTrustAnchorConfig() : null
|
|
2688
|
+
});
|
|
2689
|
+
}
|
|
2690
|
+
function runtimeDirInputs() {
|
|
2691
|
+
const handedDown = process.env[RUNTIME_DIR_ENV_KEY];
|
|
2692
|
+
if (handedDown)
|
|
2693
|
+
return handedDown;
|
|
2694
|
+
const localConfig = loadConfig();
|
|
2695
|
+
const unattended = isUnattendedProcess();
|
|
2696
|
+
return {
|
|
2697
|
+
base: { localConfig, unattended, repoRoot: repoRootSync() },
|
|
2698
|
+
needsAnchor: unattended && resolveRuntimeDirSetting(localConfig) !== null
|
|
2699
|
+
};
|
|
2700
|
+
}
|
|
2701
|
+
function repoRootSync(start = process.cwd()) {
|
|
2702
|
+
let dir;
|
|
2703
|
+
try {
|
|
2704
|
+
dir = realpathSync2(start);
|
|
2705
|
+
} catch {
|
|
2706
|
+
return null;
|
|
2707
|
+
}
|
|
2708
|
+
for (;; ) {
|
|
2709
|
+
if (existsSync5(join5(dir, ".git")))
|
|
2710
|
+
return dir;
|
|
2711
|
+
const parent = dirname4(dir);
|
|
2712
|
+
if (parent === dir)
|
|
2713
|
+
return null;
|
|
2714
|
+
dir = parent;
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
function resolveRepoSync() {
|
|
2718
|
+
const fromEnv = process.env.AEG_REPO;
|
|
2719
|
+
if (fromEnv) {
|
|
2720
|
+
const m = /^([^/]+)\/(.+)$/.exec(fromEnv);
|
|
2721
|
+
if (m?.[1] && m[2])
|
|
2722
|
+
return { owner: m[1], repo: m[2] };
|
|
2723
|
+
}
|
|
2724
|
+
let url;
|
|
2725
|
+
try {
|
|
2726
|
+
url = execFileSync3("git", ["remote", "get-url", "origin"], {
|
|
2727
|
+
encoding: "utf-8",
|
|
2728
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
2729
|
+
}).trim();
|
|
2730
|
+
} catch {
|
|
2731
|
+
return null;
|
|
2732
|
+
}
|
|
2733
|
+
const ssh = /^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/.exec(url);
|
|
2734
|
+
if (ssh?.[1] && ssh[2])
|
|
2735
|
+
return { owner: ssh[1], repo: ssh[2] };
|
|
2736
|
+
const https = /^https?:\/\/(?:[^@]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(url);
|
|
2737
|
+
if (https?.[1] && https[2])
|
|
2738
|
+
return { owner: https[1], repo: https[2] };
|
|
2739
|
+
return null;
|
|
2740
|
+
}
|
|
2741
|
+
var memoizedThisRepo = null;
|
|
2742
|
+
function runtimeDirForThisRepo() {
|
|
2743
|
+
if (memoizedThisRepo !== null)
|
|
2744
|
+
return memoizedThisRepo;
|
|
2745
|
+
memoizedThisRepo = runtimeDirForRepo(resolveRepoSync());
|
|
2746
|
+
return memoizedThisRepo;
|
|
2747
|
+
}
|
|
2748
|
+
function ensureRunDir(dir, runtimeDir) {
|
|
2749
|
+
mkdirNoSymlinks(dir, 448, runtimeDir);
|
|
2750
|
+
chmodSync(dir, 448);
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
// src/lib/log-webhook-drain.ts
|
|
2754
|
+
import {
|
|
2755
|
+
closeSync as closeSync3,
|
|
2756
|
+
constants as fsConstants3,
|
|
2757
|
+
lstatSync as lstatSync2,
|
|
2758
|
+
mkdirSync as mkdirSync3,
|
|
2759
|
+
openSync as openSync3,
|
|
2760
|
+
linkSync as linkSync2,
|
|
2761
|
+
readFileSync as readFileSync4,
|
|
2762
|
+
renameSync as renameSync2,
|
|
2763
|
+
statSync as statSync2,
|
|
2764
|
+
unlinkSync as unlinkSync2,
|
|
2765
|
+
utimesSync,
|
|
2766
|
+
writeFileSync as writeFileSync2,
|
|
2767
|
+
writeSync as writeSync2
|
|
2768
|
+
} from "node:fs";
|
|
2769
|
+
import { randomUUID } from "node:crypto";
|
|
2770
|
+
import { homedir as homedir2 } from "node:os";
|
|
2771
|
+
import { dirname as dirname5, join as join6 } from "node:path";
|
|
2772
|
+
var MAX_WEBHOOK_BODY_BYTES = 5 * 1024 * 1024;
|
|
2773
|
+
var WEBHOOK_FETCH_TIMEOUT_MS = 30000;
|
|
2774
|
+
var SAFE_PATH_SEGMENT2 = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;
|
|
2775
|
+
function isSafeRepoSegment2(segment) {
|
|
2776
|
+
return SAFE_PATH_SEGMENT2.test(segment) && !segment.includes("..");
|
|
2777
|
+
}
|
|
2778
|
+
function isErrnoCode(err, code) {
|
|
2779
|
+
return typeof err === "object" && err !== null && err.code === code;
|
|
2780
|
+
}
|
|
2781
|
+
function isEnoent(err) {
|
|
2782
|
+
return isErrnoCode(err, "ENOENT");
|
|
2783
|
+
}
|
|
2784
|
+
var WEBHOOK_DRAIN_LOCK_STALE_MS = 4 * WEBHOOK_FETCH_TIMEOUT_MS;
|
|
2785
|
+
function tryCreateLock(lockPath, token) {
|
|
2786
|
+
try {
|
|
2787
|
+
mkdirSync3(dirname5(lockPath), { recursive: true, mode: 448 });
|
|
2788
|
+
const fd = openSync3(lockPath, fsConstants3.O_WRONLY | fsConstants3.O_CREAT | fsConstants3.O_EXCL, 384);
|
|
2789
|
+
try {
|
|
2790
|
+
writeSync2(fd, `${token}
|
|
2791
|
+
`);
|
|
2792
|
+
} finally {
|
|
2793
|
+
closeSync3(fd);
|
|
2794
|
+
}
|
|
2795
|
+
return true;
|
|
2796
|
+
} catch (err) {
|
|
2797
|
+
if (isErrnoCode(err, "EEXIST"))
|
|
2798
|
+
return false;
|
|
2799
|
+
throw err;
|
|
2800
|
+
}
|
|
2801
|
+
}
|
|
2802
|
+
function acquireDrainLock(lockPath) {
|
|
2803
|
+
const token = `${process.pid}:${randomUUID()}`;
|
|
2804
|
+
if (tryCreateLock(lockPath, token))
|
|
2805
|
+
return token;
|
|
2806
|
+
let observedMtimeMs;
|
|
2807
|
+
try {
|
|
2808
|
+
observedMtimeMs = statSync2(lockPath).mtimeMs;
|
|
2809
|
+
} catch (err) {
|
|
2810
|
+
if (!isEnoent(err))
|
|
2811
|
+
throw err;
|
|
2812
|
+
return tryCreateLock(lockPath, token) ? token : null;
|
|
2813
|
+
}
|
|
2814
|
+
if (Date.now() - observedMtimeMs <= WEBHOOK_DRAIN_LOCK_STALE_MS)
|
|
2815
|
+
return null;
|
|
2816
|
+
const claimed = `${lockPath}.claimed-${randomUUID()}`;
|
|
2817
|
+
try {
|
|
2818
|
+
renameSync2(lockPath, claimed);
|
|
2819
|
+
} catch (err) {
|
|
2820
|
+
if (isEnoent(err))
|
|
2821
|
+
return null;
|
|
2822
|
+
throw err;
|
|
2823
|
+
}
|
|
2824
|
+
let claimedMtimeMs = null;
|
|
2825
|
+
try {
|
|
2826
|
+
claimedMtimeMs = statSync2(claimed).mtimeMs;
|
|
2827
|
+
} catch (err) {
|
|
2828
|
+
if (!isEnoent(err))
|
|
2829
|
+
throw err;
|
|
2830
|
+
}
|
|
2831
|
+
if (claimedMtimeMs !== observedMtimeMs) {
|
|
2832
|
+
try {
|
|
2833
|
+
linkSync2(claimed, lockPath);
|
|
2834
|
+
} catch (err) {
|
|
2835
|
+
if (!isErrnoCode(err, "EEXIST"))
|
|
2836
|
+
throw err;
|
|
2837
|
+
}
|
|
2838
|
+
try {
|
|
2839
|
+
unlinkSync2(claimed);
|
|
2840
|
+
} catch (err) {
|
|
2841
|
+
if (!isEnoent(err))
|
|
2842
|
+
throw err;
|
|
2843
|
+
}
|
|
2844
|
+
return null;
|
|
2845
|
+
}
|
|
2846
|
+
unlinkSync2(claimed);
|
|
2847
|
+
return tryCreateLock(lockPath, token) ? token : null;
|
|
2848
|
+
}
|
|
2849
|
+
function renewDrainLock(lockPath, token) {
|
|
2850
|
+
let holder;
|
|
2851
|
+
try {
|
|
2852
|
+
holder = readFileSync4(lockPath, "utf8").trim();
|
|
2853
|
+
} catch (err) {
|
|
2854
|
+
if (!isEnoent(err))
|
|
2855
|
+
throw err;
|
|
2856
|
+
return false;
|
|
2857
|
+
}
|
|
2858
|
+
if (holder !== token)
|
|
2859
|
+
return false;
|
|
2860
|
+
const now = new Date;
|
|
2861
|
+
try {
|
|
2862
|
+
utimesSync(lockPath, now, now);
|
|
2863
|
+
} catch (err) {
|
|
2864
|
+
if (!isEnoent(err))
|
|
2865
|
+
throw err;
|
|
2866
|
+
return false;
|
|
2867
|
+
}
|
|
2868
|
+
return true;
|
|
2869
|
+
}
|
|
2870
|
+
function releaseDrainLock(lockPath, token) {
|
|
2871
|
+
try {
|
|
2872
|
+
const holder = readFileSync4(lockPath, "utf8").trim();
|
|
2873
|
+
if (holder !== token)
|
|
2874
|
+
return;
|
|
2875
|
+
unlinkSync2(lockPath);
|
|
2876
|
+
} catch (err) {
|
|
2877
|
+
if (!isEnoent(err))
|
|
2878
|
+
throw err;
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
class WebhookDrainError extends Error {
|
|
2883
|
+
code;
|
|
2884
|
+
constructor(code, message) {
|
|
2885
|
+
super(message);
|
|
2886
|
+
this.code = code;
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
function backupPathFor(queuePath) {
|
|
2890
|
+
return queuePath.replace(/\.ndjson$/, ".1.ndjson");
|
|
2891
|
+
}
|
|
2892
|
+
function drainingPathFor(queuePath) {
|
|
2893
|
+
return queuePath.replace(/\.ndjson$/, ".draining.ndjson");
|
|
2894
|
+
}
|
|
2895
|
+
function rejectedPathFor(queuePath) {
|
|
2896
|
+
return queuePath.replace(/\.ndjson$/, ".rejected.ndjson");
|
|
2897
|
+
}
|
|
2898
|
+
var rejectionWarnedThisProcess = false;
|
|
2899
|
+
function warnRejectionOnce(message) {
|
|
2900
|
+
if (rejectionWarnedThisProcess)
|
|
2901
|
+
return;
|
|
2902
|
+
rejectionWarnedThisProcess = true;
|
|
2903
|
+
try {
|
|
2904
|
+
process.stderr.write(message);
|
|
2905
|
+
} catch {}
|
|
2906
|
+
}
|
|
2907
|
+
function queueLines(buf) {
|
|
2908
|
+
const lines = [];
|
|
2909
|
+
let start = 0;
|
|
2910
|
+
for (let i = 0;i < buf.byteLength; i++) {
|
|
2911
|
+
if (buf[i] !== 10)
|
|
2912
|
+
continue;
|
|
2913
|
+
if (i > start)
|
|
2914
|
+
lines.push({ raw: buf.toString("utf8", start, i), end: i + 1 });
|
|
2915
|
+
start = i + 1;
|
|
2916
|
+
}
|
|
2917
|
+
if (start < buf.byteLength)
|
|
2918
|
+
lines.push({ raw: buf.toString("utf8", start), end: buf.byteLength });
|
|
2919
|
+
return lines;
|
|
2920
|
+
}
|
|
2921
|
+
function removeQueueHead(path, cut) {
|
|
2922
|
+
const remaining = readFileSync4(path);
|
|
2923
|
+
writeFileSync2(path, remaining.subarray(Math.min(cut, remaining.byteLength)));
|
|
2924
|
+
}
|
|
2925
|
+
function queueBucketSize(path) {
|
|
2926
|
+
let lstat;
|
|
2927
|
+
try {
|
|
2928
|
+
lstat = lstatSync2(path);
|
|
2929
|
+
} catch (err) {
|
|
2930
|
+
if (!isEnoent(err))
|
|
2931
|
+
throw err;
|
|
2932
|
+
}
|
|
2933
|
+
if (lstat === undefined)
|
|
2934
|
+
return null;
|
|
2935
|
+
if (!lstat.isFile()) {
|
|
2936
|
+
throw new WebhookDrainError("log-webhook-drain-symlink", `log webhook drain: outbox target is not a regular file (symlink, FIFO, or similar) — refusing to read: ${path}`);
|
|
2937
|
+
}
|
|
2938
|
+
return Number(lstat.size);
|
|
2939
|
+
}
|
|
2940
|
+
function readQueueFile(path) {
|
|
2941
|
+
if (queueBucketSize(path) === null)
|
|
2942
|
+
return null;
|
|
2943
|
+
return readFileSync4(path);
|
|
2944
|
+
}
|
|
2945
|
+
function rejectLine(rejectedPath, reason, status, identity, raw) {
|
|
2946
|
+
const record = JSON.stringify({
|
|
2947
|
+
rejected_at: new Date().toISOString(),
|
|
2948
|
+
status,
|
|
2949
|
+
reason,
|
|
2950
|
+
identity,
|
|
2951
|
+
bytes: Buffer.byteLength(raw, "utf8"),
|
|
2952
|
+
raw
|
|
2953
|
+
});
|
|
2954
|
+
const failure = appendHardenedLine(rejectedPath, `${record}
|
|
2955
|
+
`);
|
|
2956
|
+
if (failure !== null) {
|
|
2957
|
+
throw new WebhookDrainError("log-webhook-drain-rejected-write", `log webhook drain: a queued line failed re-validation (${reason}) and could not be set aside in ${rejectedPath} — ${failure}; the line stays queued`);
|
|
2958
|
+
}
|
|
2959
|
+
warnRejectionOnce(`vinaya: log delivery set a queued line aside in ${rejectedPath} — ${reason}; later lines keep delivering
|
|
2960
|
+
`);
|
|
2961
|
+
}
|
|
2962
|
+
async function postChunk(webhookUrl, headers, body, fetchTimeoutMs, chunksAlreadyDelivered) {
|
|
2963
|
+
const delivered = chunksAlreadyDelivered > 0 ? ` after delivering ${chunksAlreadyDelivered} chunk(s)` : "";
|
|
2964
|
+
let response;
|
|
2965
|
+
try {
|
|
2966
|
+
response = await fetch(webhookUrl, {
|
|
2967
|
+
method: "POST",
|
|
2968
|
+
headers: { "content-type": "application/x-ndjson", ...headers },
|
|
2969
|
+
body,
|
|
2970
|
+
signal: AbortSignal.timeout(fetchTimeoutMs)
|
|
2971
|
+
});
|
|
2972
|
+
} catch (err) {
|
|
2973
|
+
const reason = err instanceof Error && err.name === "TimeoutError" ? `timed out after ${fetchTimeoutMs}ms` : err instanceof Error ? err.message : String(err);
|
|
2974
|
+
throw new WebhookDrainError("log-webhook-drain-failed", `log webhook drain: POST to ${webhookUrl} failed${delivered}: ${reason}`);
|
|
2975
|
+
}
|
|
2976
|
+
if (!response.ok) {
|
|
2977
|
+
throw new WebhookDrainError("log-webhook-drain-failed", `log webhook drain: POST to ${webhookUrl} returned ${response.status} ${response.statusText}${delivered}`);
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
async function drainQueueFile(args) {
|
|
2981
|
+
const { path, rejectedPath, webhookUrl, headers, fetchTimeoutMs, totals } = args;
|
|
2982
|
+
const buf = readQueueFile(path);
|
|
2983
|
+
if (buf === null || buf.byteLength === 0)
|
|
2984
|
+
return;
|
|
2985
|
+
const lines = queueLines(buf);
|
|
2986
|
+
if (lines.length === 0) {
|
|
2987
|
+
removeQueueHead(path, buf.byteLength);
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
let removed = 0;
|
|
2991
|
+
let pendingEnd = 0;
|
|
2992
|
+
let chunk = [];
|
|
2993
|
+
let chunkBytes = 0;
|
|
2994
|
+
const deliverChunk = async () => {
|
|
2995
|
+
const body = `${chunk.join(`
|
|
2996
|
+
`)}
|
|
2997
|
+
`;
|
|
2998
|
+
args.keepLock();
|
|
2999
|
+
await postChunk(webhookUrl, headers, body, fetchTimeoutMs, totals.chunks);
|
|
3000
|
+
totals.chunks += 1;
|
|
3001
|
+
totals.lineCount += chunk.length;
|
|
3002
|
+
totals.bytes += Buffer.byteLength(body, "utf8");
|
|
3003
|
+
removeQueueHead(path, pendingEnd - removed);
|
|
3004
|
+
removed = pendingEnd;
|
|
3005
|
+
chunk = [];
|
|
3006
|
+
chunkBytes = 0;
|
|
3007
|
+
};
|
|
3008
|
+
const setAside = async (reason, status, identity, line) => {
|
|
3009
|
+
if (chunk.length > 0)
|
|
3010
|
+
await deliverChunk();
|
|
3011
|
+
rejectLine(rejectedPath, reason, status, identity, line.raw);
|
|
3012
|
+
totals.rejected += 1;
|
|
3013
|
+
pendingEnd = line.end;
|
|
3014
|
+
removeQueueHead(path, pendingEnd - removed);
|
|
3015
|
+
removed = pendingEnd;
|
|
3016
|
+
};
|
|
3017
|
+
for (const line of lines) {
|
|
3018
|
+
const record = classifyStoredLine(line.raw, homedir2());
|
|
3019
|
+
if (record.status !== "ok") {
|
|
3020
|
+
await setAside(record.reason, record.status, record.identity, line);
|
|
3021
|
+
continue;
|
|
3022
|
+
}
|
|
3023
|
+
const lineBytes = Buffer.byteLength(record.postLine, "utf8") + 1;
|
|
3024
|
+
if (lineBytes > MAX_WEBHOOK_BODY_BYTES) {
|
|
3025
|
+
await setAside(`one line is ${lineBytes} byte(s), over the ${MAX_WEBHOOK_BODY_BYTES}-byte per-POST cap — no chunking can carry it`, "too_large", record.identity, line);
|
|
3026
|
+
continue;
|
|
3027
|
+
}
|
|
3028
|
+
if (chunk.length > 0 && chunkBytes + lineBytes > MAX_WEBHOOK_BODY_BYTES)
|
|
3029
|
+
await deliverChunk();
|
|
3030
|
+
chunk.push(record.postLine);
|
|
3031
|
+
chunkBytes += lineBytes;
|
|
3032
|
+
pendingEnd = line.end;
|
|
3033
|
+
}
|
|
3034
|
+
pendingEnd = buf.byteLength;
|
|
3035
|
+
if (chunk.length > 0) {
|
|
3036
|
+
await deliverChunk();
|
|
3037
|
+
return;
|
|
3038
|
+
}
|
|
3039
|
+
if (pendingEnd > removed)
|
|
3040
|
+
removeQueueHead(path, pendingEnd - removed);
|
|
3041
|
+
}
|
|
3042
|
+
async function drainRenamedAside(args, livePath, source) {
|
|
3043
|
+
args.keepLock();
|
|
3044
|
+
const draining = drainingPathFor(livePath);
|
|
3045
|
+
try {
|
|
3046
|
+
renameSync2(source, draining);
|
|
3047
|
+
} catch (err) {
|
|
3048
|
+
if (isEnoent(err))
|
|
3049
|
+
return;
|
|
3050
|
+
throw err;
|
|
3051
|
+
}
|
|
3052
|
+
await drainQueueFile({ ...args, path: draining });
|
|
3053
|
+
unlinkSync2(draining);
|
|
3054
|
+
}
|
|
3055
|
+
async function drainOutboxToWebhook(outboxTask, webhookUrl, headers, fetchTimeoutMs = WEBHOOK_FETCH_TIMEOUT_MS) {
|
|
3056
|
+
const resolved = await resolveRepo();
|
|
3057
|
+
const repo = resolved && isSafeRepoSegment2(resolved.owner) && isSafeRepoSegment2(resolved.repo) ? resolved : null;
|
|
3058
|
+
const outboxRoot = () => join6(GLOBAL_VINAYA_HOME, "outbox");
|
|
3059
|
+
const path = outboxPathFor({ outboxRoot }, repo, outboxTask);
|
|
3060
|
+
const lockPath = `${path}.flush-lock`;
|
|
3061
|
+
const lockToken = acquireDrainLock(lockPath);
|
|
3062
|
+
const totals = { lineCount: 0, bytes: 0, chunks: 0, rejected: 0 };
|
|
3063
|
+
if (lockToken === null)
|
|
3064
|
+
return { flushed: false, ...totals };
|
|
3065
|
+
try {
|
|
3066
|
+
const keepLock = () => {
|
|
3067
|
+
if (renewDrainLock(lockPath, lockToken))
|
|
3068
|
+
return;
|
|
3069
|
+
throw new WebhookDrainError("log-webhook-drain-lock-lost", `log webhook drain: this drain's lock on ${lockPath} was taken over by another process — stopping here; that process delivers the rest`);
|
|
3070
|
+
};
|
|
3071
|
+
const shared = {
|
|
3072
|
+
rejectedPath: rejectedPathFor(path),
|
|
3073
|
+
webhookUrl,
|
|
3074
|
+
headers,
|
|
3075
|
+
fetchTimeoutMs,
|
|
3076
|
+
totals,
|
|
3077
|
+
keepLock
|
|
3078
|
+
};
|
|
3079
|
+
const draining = drainingPathFor(path);
|
|
3080
|
+
if (queueBucketSize(draining) !== null) {
|
|
3081
|
+
keepLock();
|
|
3082
|
+
await drainQueueFile({ ...shared, path: draining });
|
|
3083
|
+
unlinkSync2(draining);
|
|
3084
|
+
}
|
|
3085
|
+
await drainRenamedAside(shared, path, backupPathFor(path));
|
|
3086
|
+
await drainRenamedAside(shared, path, path);
|
|
3087
|
+
return { flushed: totals.chunks > 0 || totals.rejected > 0, ...totals };
|
|
3088
|
+
} finally {
|
|
3089
|
+
releaseDrainLock(lockPath, lockToken);
|
|
3090
|
+
}
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
// src/lib/log-sink.ts
|
|
3094
|
+
var OUTBOX_MAX_BYTES = 8 * 1024 * 1024;
|
|
3095
|
+
var LOG_CONTEXT_LOOKUP_DEADLINE_MS = 3000;
|
|
3096
|
+
function withDeadline(work, ms, fallback) {
|
|
3097
|
+
return new Promise((resolve) => {
|
|
3098
|
+
const timer = setTimeout(() => resolve(fallback), ms);
|
|
3099
|
+
timer.unref?.();
|
|
3100
|
+
work.then((value) => {
|
|
3101
|
+
clearTimeout(timer);
|
|
3102
|
+
resolve(value);
|
|
3103
|
+
}, () => {
|
|
3104
|
+
clearTimeout(timer);
|
|
3105
|
+
resolve(fallback);
|
|
3106
|
+
});
|
|
3107
|
+
});
|
|
3108
|
+
}
|
|
3109
|
+
async function safeLoadTrustAnchorConfig() {
|
|
3110
|
+
return withDeadline(loadTrustAnchorConfigAsync(undefined, { quiet: true }), LOG_CONTEXT_LOOKUP_DEADLINE_MS, null);
|
|
3111
|
+
}
|
|
3112
|
+
function logsCredentialMissing(headers, env) {
|
|
3113
|
+
if (!headers)
|
|
3114
|
+
return false;
|
|
3115
|
+
const varPattern = /\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g;
|
|
3116
|
+
for (const value of Object.values(headers)) {
|
|
3117
|
+
for (const match of value.matchAll(varPattern)) {
|
|
3118
|
+
if (!env[match[1]])
|
|
3119
|
+
return true;
|
|
3120
|
+
}
|
|
3121
|
+
}
|
|
3122
|
+
return false;
|
|
3123
|
+
}
|
|
3124
|
+
function resolveLogDestinationFrom(input) {
|
|
3125
|
+
const local = resolveLogsSetting(input.localConfig);
|
|
3126
|
+
let effective = null;
|
|
3127
|
+
if (input.unattended) {
|
|
3128
|
+
effective = local ? resolveTrustAnchorLogsDestination(local, input.trustAnchorConfig) : resolveLogsSetting(input.trustAnchorConfig);
|
|
3129
|
+
} else {
|
|
3130
|
+
effective = local;
|
|
3131
|
+
}
|
|
3132
|
+
if (hostFromEnv(input.env) === "ci") {
|
|
3133
|
+
if (effective && "url" in effective) {
|
|
3134
|
+
if (logsCredentialMissing(effective.headers, input.env)) {
|
|
3135
|
+
return {
|
|
3136
|
+
kind: "none",
|
|
3137
|
+
reason: "a logs.url server destination is configured, but this job holds no delivery credential (a fork pull request, or a missing repository secret)"
|
|
3138
|
+
};
|
|
3139
|
+
}
|
|
3140
|
+
return { kind: "server", url: effective.url, headers: resolveLogsHeaderValues(effective.headers, input.env) };
|
|
3141
|
+
}
|
|
3142
|
+
return {
|
|
3143
|
+
kind: "none",
|
|
3144
|
+
reason: "no server destination is configured for CI delivery (vinaya.config.json logs.url)"
|
|
3145
|
+
};
|
|
3146
|
+
}
|
|
3147
|
+
if (effective && "url" in effective) {
|
|
3148
|
+
return { kind: "server", url: effective.url, headers: resolveLogsHeaderValues(effective.headers, input.env) };
|
|
3149
|
+
}
|
|
3150
|
+
if (effective && "folder" in effective && isInsideRepo(effective.folder, input.repoRoot)) {
|
|
3151
|
+
effective = null;
|
|
3152
|
+
}
|
|
3153
|
+
const folder = effective && "folder" in effective ? effective.folder : input.defaultFolder;
|
|
3154
|
+
return { kind: "folder", folder };
|
|
3155
|
+
}
|
|
3156
|
+
var processTrustAnchorOnce;
|
|
3157
|
+
function processTrustAnchor() {
|
|
3158
|
+
if (processTrustAnchorOnce === undefined)
|
|
3159
|
+
processTrustAnchorOnce = safeLoadTrustAnchorConfig();
|
|
3160
|
+
return processTrustAnchorOnce;
|
|
3161
|
+
}
|
|
3162
|
+
async function defaultResolveLogDestination(repo, env) {
|
|
3163
|
+
const localConfig = loadConfig();
|
|
3164
|
+
const unattended = isUnattendedProcess(process.env);
|
|
3165
|
+
return resolveLogDestinationFrom({
|
|
3166
|
+
localConfig,
|
|
3167
|
+
trustAnchorConfig: unattended ? await processTrustAnchor() : null,
|
|
3168
|
+
unattended,
|
|
3169
|
+
env,
|
|
3170
|
+
defaultFolder: join7(await runtimeDirForRepoAsync(repo), "logs"),
|
|
3171
|
+
repoRoot: repoRootSync()
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
function isEnoent2(err) {
|
|
3175
|
+
return typeof err === "object" && err !== null && err.code === "ENOENT";
|
|
3176
|
+
}
|
|
3177
|
+
var execFileAsync5 = promisify5(execFile5);
|
|
3178
|
+
async function resolveDoctrine(cwd, vinayaVersion) {
|
|
3179
|
+
let toplevel;
|
|
3180
|
+
try {
|
|
3181
|
+
toplevel = (await execFileAsync5("git", ["-C", cwd, "rev-parse", "--show-toplevel"], { encoding: "utf8" })).stdout.trim();
|
|
3182
|
+
} catch (err) {
|
|
3183
|
+
return isEnoent2(err) ? "unknown" : vinayaVersion;
|
|
3184
|
+
}
|
|
3185
|
+
if (!existsSync6(join7(toplevel, "aeg-root", "roles")))
|
|
3186
|
+
return vinayaVersion;
|
|
3187
|
+
try {
|
|
3188
|
+
const sha = (await execFileAsync5("git", ["-C", toplevel, "rev-parse", "HEAD:aeg-root"], { encoding: "utf8" })).stdout.trim();
|
|
3189
|
+
return `aeg-root@${sha}`;
|
|
3190
|
+
} catch {
|
|
3191
|
+
return vinayaVersion;
|
|
3192
|
+
}
|
|
3193
|
+
}
|
|
3194
|
+
function readVinayaVersion() {
|
|
3195
|
+
try {
|
|
3196
|
+
const pkg = JSON.parse(readFileSync5(join7(packageRoot(import.meta.url), "package.json"), "utf8"));
|
|
3197
|
+
return pkg.version ?? "unknown";
|
|
3198
|
+
} catch {
|
|
3199
|
+
return "unknown";
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
var SAFE_PATH_SEGMENT3 = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;
|
|
3203
|
+
function isSafeRepoSegment3(segment) {
|
|
3204
|
+
return SAFE_PATH_SEGMENT3.test(segment) && !segment.includes("..");
|
|
3205
|
+
}
|
|
3206
|
+
function outboxPathFor(deps, repo, issue) {
|
|
3207
|
+
const dirName = repo ? `${repo.owner}-${repo.repo}` : "unresolved";
|
|
3208
|
+
const fileName = `${issue ?? "none"}.ndjson`;
|
|
3209
|
+
return join7(deps.outboxRoot(), dirName, fileName);
|
|
3210
|
+
}
|
|
3211
|
+
function hostFromEnv(env) {
|
|
3212
|
+
if (env.GITHUB_ACTIONS)
|
|
3213
|
+
return "ci";
|
|
3214
|
+
if (env.VINAYA_HOST === "hook")
|
|
3215
|
+
return "hook";
|
|
3216
|
+
if (env.VINAYA_HOST === "loop")
|
|
3217
|
+
return "loop";
|
|
3218
|
+
return "cli";
|
|
3219
|
+
}
|
|
3220
|
+
var warnedThisProcess = false;
|
|
3221
|
+
function defaultStderr(message) {
|
|
3222
|
+
if (warnedThisProcess)
|
|
3223
|
+
return;
|
|
3224
|
+
warnedThisProcess = true;
|
|
3225
|
+
process.stderr.write(message);
|
|
3226
|
+
}
|
|
3227
|
+
function defaultDeps() {
|
|
3228
|
+
return {
|
|
3229
|
+
outboxRoot: () => join7(GLOBAL_VINAYA_HOME, "outbox"),
|
|
3230
|
+
home: () => homedir3(),
|
|
3231
|
+
hostname: () => osHostname(),
|
|
3232
|
+
cwd: () => process.cwd(),
|
|
3233
|
+
now: () => new Date,
|
|
3234
|
+
env: () => process.env,
|
|
3235
|
+
resolveRepo: () => resolveRepo(),
|
|
3236
|
+
vinayaVersion: () => readVinayaVersion(),
|
|
3237
|
+
stderr: defaultStderr,
|
|
3238
|
+
inputVersions: () => {
|
|
3239
|
+
return;
|
|
3240
|
+
},
|
|
3241
|
+
resolveLogDestination: defaultResolveLogDestination
|
|
3242
|
+
};
|
|
3243
|
+
}
|
|
3244
|
+
var APPEND_OPEN_FLAGS = fsConstants4.O_WRONLY | fsConstants4.O_APPEND | fsConstants4.O_CREAT | fsConstants4.O_NOFOLLOW | fsConstants4.O_NONBLOCK;
|
|
3245
|
+
function guardedAppendOpen(path) {
|
|
3246
|
+
try {
|
|
3247
|
+
return openSync4(path, APPEND_OPEN_FLAGS, 384);
|
|
3248
|
+
} catch {
|
|
3249
|
+
return;
|
|
3250
|
+
}
|
|
3251
|
+
}
|
|
3252
|
+
function appendHardenedLine(path, line) {
|
|
3253
|
+
try {
|
|
3254
|
+
mkdirSync4(dirname6(path), { recursive: true, mode: 448 });
|
|
3255
|
+
const fd = guardedAppendOpen(path);
|
|
3256
|
+
if (fd === undefined)
|
|
3257
|
+
return `target could not be opened (symlink, FIFO, or unwritable): ${path}`;
|
|
3258
|
+
try {
|
|
3259
|
+
if (!fstatSync2(fd).isFile())
|
|
3260
|
+
return `target is not a regular file: ${path}`;
|
|
3261
|
+
writeSync3(fd, line);
|
|
3262
|
+
} finally {
|
|
3263
|
+
closeSync4(fd);
|
|
3264
|
+
}
|
|
3265
|
+
return null;
|
|
3266
|
+
} catch (err) {
|
|
3267
|
+
return err instanceof Error ? err.message : String(err);
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
function reportRotationOverflow(backupPath, warn) {
|
|
3271
|
+
let raw;
|
|
3272
|
+
try {
|
|
3273
|
+
raw = readFileSync5(backupPath, "utf8");
|
|
3274
|
+
} catch {
|
|
3275
|
+
return;
|
|
3276
|
+
}
|
|
3277
|
+
const lines = raw.split(`
|
|
3278
|
+
`).filter((l) => l.length > 0);
|
|
3279
|
+
if (lines.length === 0)
|
|
3280
|
+
return;
|
|
3281
|
+
const droppedIdentities = lines.map((line, i) => {
|
|
3282
|
+
try {
|
|
3283
|
+
return recordIdentity(JSON.parse(line)) ?? `unreadable:${i}`;
|
|
3284
|
+
} catch {
|
|
3285
|
+
return `unreadable:${i}`;
|
|
3286
|
+
}
|
|
3287
|
+
});
|
|
3288
|
+
const diagnostic = { reason: "capacity", dropped: droppedIdentities.length, droppedIdentities };
|
|
3289
|
+
const shown = diagnostic.droppedIdentities.slice(0, 20);
|
|
3290
|
+
const more = diagnostic.dropped > shown.length ? `, +${diagnostic.dropped - shown.length} more` : "";
|
|
3291
|
+
warn(`vinaya: log outbox rotation is overwriting ${backupPath} — ${diagnostic.dropped} record(s) permanently lost: ${shown.join(", ")}${more}
|
|
3292
|
+
`);
|
|
3293
|
+
}
|
|
3294
|
+
function appendLine(path, line, warn) {
|
|
3295
|
+
try {
|
|
3296
|
+
mkdirSync4(dirname6(path), { recursive: true, mode: 448 });
|
|
3297
|
+
let fd = guardedAppendOpen(path);
|
|
3298
|
+
if (fd === undefined) {
|
|
3299
|
+
warn(`vinaya: log outbox target could not be opened (symlink, FIFO, or unwritable) — refusing: ${path}
|
|
3300
|
+
`);
|
|
3301
|
+
return;
|
|
3302
|
+
}
|
|
3303
|
+
let closed = false;
|
|
3304
|
+
try {
|
|
3305
|
+
const stat = fstatSync2(fd);
|
|
3306
|
+
if (!stat.isFile()) {
|
|
3307
|
+
warn(`vinaya: log outbox target is not a regular file — refusing to write: ${path}
|
|
3308
|
+
`);
|
|
3309
|
+
return;
|
|
3310
|
+
}
|
|
3311
|
+
if (stat.size > OUTBOX_MAX_BYTES) {
|
|
3312
|
+
closeSync4(fd);
|
|
3313
|
+
closed = true;
|
|
3314
|
+
const backupPath = path.replace(/\.ndjson$/, ".1.ndjson");
|
|
3315
|
+
reportRotationOverflow(backupPath, warn);
|
|
3316
|
+
renameSync3(path, backupPath);
|
|
3317
|
+
const rotated = guardedAppendOpen(path);
|
|
3318
|
+
if (rotated === undefined) {
|
|
3319
|
+
warn(`vinaya: log outbox target could not be reopened after rotation — refusing: ${path}
|
|
3320
|
+
`);
|
|
3321
|
+
return;
|
|
3322
|
+
}
|
|
3323
|
+
fd = rotated;
|
|
3324
|
+
closed = false;
|
|
3325
|
+
}
|
|
3326
|
+
writeSync3(fd, line);
|
|
3327
|
+
} finally {
|
|
3328
|
+
if (!closed)
|
|
3329
|
+
closeSync4(fd);
|
|
3330
|
+
}
|
|
3331
|
+
} catch (err) {
|
|
3332
|
+
warn(`vinaya: log outbox write failed — ${err instanceof Error ? err.message : String(err)}
|
|
3333
|
+
`);
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
function createLogSink(overrides = {}) {
|
|
3337
|
+
const deps = { ...defaultDeps(), ...overrides };
|
|
3338
|
+
const runId = deps.env().VINAYA_RUN_ID || randomUUID2();
|
|
3339
|
+
const processId = randomUUID2();
|
|
3340
|
+
let seq = 0;
|
|
3341
|
+
let warned = false;
|
|
3342
|
+
const warnOnce = (message) => {
|
|
3343
|
+
if (warned)
|
|
3344
|
+
return;
|
|
3345
|
+
warned = true;
|
|
3346
|
+
try {
|
|
3347
|
+
deps.stderr(message);
|
|
3348
|
+
} catch {}
|
|
3349
|
+
};
|
|
3350
|
+
let doctrineCache;
|
|
3351
|
+
const doctrine = () => {
|
|
3352
|
+
if (doctrineCache === undefined) {
|
|
3353
|
+
doctrineCache = withDeadline(resolveDoctrine(deps.cwd(), deps.vinayaVersion()), LOG_CONTEXT_LOOKUP_DEADLINE_MS, deps.vinayaVersion());
|
|
3354
|
+
}
|
|
3355
|
+
return doctrineCache;
|
|
3356
|
+
};
|
|
3357
|
+
let resolveRepoCache;
|
|
3358
|
+
const resolveRepoOnce = () => {
|
|
3359
|
+
if (resolveRepoCache === undefined)
|
|
3360
|
+
resolveRepoCache = deps.resolveRepo();
|
|
3361
|
+
return resolveRepoCache;
|
|
3362
|
+
};
|
|
3363
|
+
let contextCache;
|
|
3364
|
+
const context = () => {
|
|
3365
|
+
if (contextCache === undefined) {
|
|
3366
|
+
const env = deps.env();
|
|
3367
|
+
contextCache = Promise.all([
|
|
3368
|
+
withDeadline(resolveRepoOnce(), LOG_CONTEXT_LOOKUP_DEADLINE_MS, null),
|
|
3369
|
+
doctrine()
|
|
3370
|
+
]).then(async ([resolved, doctrineValue]) => {
|
|
3371
|
+
const repo = resolved && isSafeRepoSegment3(resolved.owner) && isSafeRepoSegment3(resolved.repo) ? resolved : null;
|
|
3372
|
+
return { repo, doctrine: doctrineValue, destination: await deps.resolveLogDestination(repo, env) };
|
|
3373
|
+
});
|
|
3374
|
+
}
|
|
3375
|
+
return contextCache;
|
|
3376
|
+
};
|
|
3377
|
+
let drainChain = Promise.resolve();
|
|
3378
|
+
const pendingWrites = new Set;
|
|
3379
|
+
const scheduleWebhookDrain = (issue, url, headers) => {
|
|
3380
|
+
drainChain = drainChain.then(() => drainOutboxToWebhook(issue, url, headers)).then(() => {
|
|
3381
|
+
return;
|
|
3382
|
+
}).catch((err) => {
|
|
3383
|
+
warnOnce(`vinaya: log delivery to ${url} failed — queued in the local outbox, retried on the next event: ${err instanceof Error ? err.message : String(err)}
|
|
3384
|
+
`);
|
|
3385
|
+
});
|
|
3386
|
+
};
|
|
3387
|
+
function log(e) {
|
|
3388
|
+
try {
|
|
3389
|
+
const env = deps.env();
|
|
3390
|
+
const host = hostFromEnv(env);
|
|
3391
|
+
const now = deps.now();
|
|
3392
|
+
const mySeq = seq++;
|
|
3393
|
+
const envFields = {
|
|
3394
|
+
role: env.VINAYA_ROLE,
|
|
3395
|
+
task: env.VINAYA_TASK,
|
|
3396
|
+
round: env.VINAYA_ROUND,
|
|
3397
|
+
run: env.VINAYA_RUN || runId,
|
|
3398
|
+
attempt: env.VINAYA_ATTEMPT,
|
|
3399
|
+
parent: env.VINAYA_PARENT_EVENT
|
|
3400
|
+
};
|
|
3401
|
+
const written = context().then(({ repo, doctrine: doctrineValue, destination: resolvedDestination }) => {
|
|
3402
|
+
const header = buildHeader({
|
|
3403
|
+
now,
|
|
3404
|
+
runId,
|
|
3405
|
+
seq: mySeq,
|
|
3406
|
+
repo: repo ? `${repo.owner}/${repo.repo}` : null,
|
|
3407
|
+
vinaya: deps.vinayaVersion(),
|
|
3408
|
+
doctrine: doctrineValue,
|
|
3409
|
+
host,
|
|
3410
|
+
hostname: deps.hostname(),
|
|
3411
|
+
env: envFields,
|
|
3412
|
+
eventId: randomUUID2(),
|
|
3413
|
+
processId,
|
|
3414
|
+
inputVersions: deps.inputVersions()
|
|
3415
|
+
});
|
|
3416
|
+
if (resolvedDestination.kind === "none") {
|
|
3417
|
+
warnOnce(`vinaya: not recording — ${resolvedDestination.reason}
|
|
3418
|
+
`);
|
|
3419
|
+
return;
|
|
3420
|
+
}
|
|
3421
|
+
const full = { ...e, ...header };
|
|
3422
|
+
const parsed = LogEventSchema.safeParse(full);
|
|
3423
|
+
if (!parsed.success) {
|
|
3424
|
+
warnOnce(`vinaya: log() refused an invalid payload — ${parsed.error.issues[0]?.message ?? "schema violation"}
|
|
3425
|
+
`);
|
|
3426
|
+
return;
|
|
3427
|
+
}
|
|
3428
|
+
const line = `${JSON.stringify(redact(parsed.data, deps.home()))}
|
|
3429
|
+
`;
|
|
3430
|
+
const destination = resolvedDestination;
|
|
3431
|
+
if (destination.kind === "server") {
|
|
3432
|
+
appendLine(outboxPathFor(deps, repo, header.subject.issue), line, warnOnce);
|
|
3433
|
+
scheduleWebhookDrain(header.subject.issue, destination.url, destination.headers);
|
|
3434
|
+
} else {
|
|
3435
|
+
appendLine(outboxPathFor({ outboxRoot: () => destination.folder }, repo, header.subject.issue), line, warnOnce);
|
|
3436
|
+
}
|
|
3437
|
+
}).catch((err) => {
|
|
3438
|
+
warnOnce(`vinaya: log() failed — ${err instanceof Error ? err.message : String(err)}
|
|
3439
|
+
`);
|
|
3440
|
+
});
|
|
3441
|
+
pendingWrites.add(written);
|
|
3442
|
+
written.finally(() => pendingWrites.delete(written));
|
|
3443
|
+
} catch (err) {
|
|
3444
|
+
warnOnce(`vinaya: log() failed — ${err instanceof Error ? err.message : String(err)}
|
|
3445
|
+
`);
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
const warmup = () => {
|
|
3449
|
+
const originalWarn = console.warn;
|
|
3450
|
+
console.warn = () => {};
|
|
3451
|
+
resolveRepoOnce().finally(() => {
|
|
3452
|
+
console.warn = originalWarn;
|
|
3453
|
+
});
|
|
3454
|
+
context().catch(() => {
|
|
3455
|
+
return;
|
|
3456
|
+
});
|
|
3457
|
+
};
|
|
3458
|
+
const drain = async () => {
|
|
3459
|
+
if (pendingWrites.size > 0)
|
|
3460
|
+
await Promise.allSettled(Array.from(pendingWrites));
|
|
3461
|
+
await drainChain.catch(() => {
|
|
3462
|
+
return;
|
|
3463
|
+
});
|
|
3464
|
+
};
|
|
3465
|
+
return { log, runId, warmup, drain };
|
|
3466
|
+
}
|
|
3467
|
+
var defaultSink = createLogSink();
|
|
3468
|
+
|
|
3469
|
+
// src/checks/runner.ts
|
|
3470
|
+
var activeChecks = new Map;
|
|
3471
|
+
|
|
3472
|
+
// src/lib/loop-log.ts
|
|
3473
|
+
var LOOP_LOG_MAX_BYTES = 8 * 1024 * 1024;
|
|
3474
|
+
|
|
3475
|
+
// src/lib/brief-assembly.ts
|
|
3476
|
+
import { existsSync as existsSync7, readFileSync as readFileSync6, readdirSync as readdirSync2 } from "node:fs";
|
|
3477
|
+
import { join as join8 } from "node:path";
|
|
3478
|
+
|
|
3479
|
+
// ../../packages/sources/src/commands.ts
|
|
3480
|
+
var COMMANDS = [
|
|
3481
|
+
{
|
|
3482
|
+
name: "help",
|
|
3483
|
+
description: "Show this help text",
|
|
3484
|
+
status: "shipped"
|
|
3485
|
+
},
|
|
3486
|
+
{
|
|
3487
|
+
name: "version",
|
|
3488
|
+
description: "Print the CLI version",
|
|
3489
|
+
flags: [{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }],
|
|
3490
|
+
status: "shipped"
|
|
3491
|
+
},
|
|
3492
|
+
{
|
|
3493
|
+
name: "init",
|
|
3494
|
+
description: "Install Vinaya's git hooks, CI workflow, and starter config (diff-and-confirm, non-destructive)",
|
|
3495
|
+
flags: [
|
|
3496
|
+
{ flag: "--dry-run", description: "Print the full diff without installing anything" },
|
|
3497
|
+
{ flag: "--yes", description: "Skip the confirmation prompt" }
|
|
3498
|
+
],
|
|
3499
|
+
details: [
|
|
3500
|
+
"It detects your repo, prints the complete diff of every intended change, and waits for your confirmation before installing anything. `--dry-run` prints that same diff and installs nothing. Nothing ever runs automatically on package install.",
|
|
3501
|
+
"It installs one CI workflow that runs `vinaya check --all --diff-only`, alongside your existing workflows — refusing to overwrite rather than touching foreign content already at that path. Git hook stubs invoke the `vinaya` binary directly; if a hook already exists, it appends a delimited managed block, shown verbatim in the diff first, rather than overwriting it.",
|
|
3502
|
+
"`vinaya.config.json` is seeded with a starter ruleset extracted from Vinaya's own battle-tested gates, not invented defaults. Issue and PR templates carrying the brief schema are added alongside your own; tier and `needs:*-input` labels are created only if they don't already exist — your existing labels are never modified.",
|
|
3503
|
+
"Two empty folders — `vinaya/checks/` and `vinaya/roles/` — are scaffolded alongside the config, each held open by a placeholder file (git does not track empty directories). `vinaya new noop-check` and `vinaya new role` write their real output into these folders later; both placeholders are recorded in the ownership manifest, so `eject` removes them exactly like everything else `init` created.",
|
|
3504
|
+
"The generated workflows reach the `vinaya` binary through `npx @attalabs/vinaya`, with no build step — unless your repo vendors the CLI itself (a workspace member declaring the name `@attalabs/vinaya`), in which case `npx` would resolve to that unbuilt local member instead of the registry. `init` detects that at generation time and writes workflows that build and run your own copy by path instead, so your CI exercises the code in the pull request. `upgrade` and `doctor` make the same determination, so regenerating is stable.",
|
|
3505
|
+
"The recommended branch-protection command is printed for you to run yourself — it is never applied, and your PATH is never touched. `eject` removes exactly the managed block it owns, or a whole file only if `init` created it."
|
|
3506
|
+
],
|
|
3507
|
+
status: "shipped"
|
|
3508
|
+
},
|
|
3509
|
+
{
|
|
3510
|
+
name: "init product",
|
|
3511
|
+
description: "Register a project in .vinaya/projects.md in an already-initialized repo",
|
|
3512
|
+
flags: [
|
|
3513
|
+
{
|
|
3514
|
+
flag: "--path <path>",
|
|
3515
|
+
description: "The project's home folder — declared, not derived. Defaults to the repo root."
|
|
3516
|
+
}
|
|
3517
|
+
],
|
|
3518
|
+
details: [
|
|
3519
|
+
"Writes (or appends to) `.vinaya/projects.md` — the registry Vinaya Studio's tranche board resolves a project's board link against. Idempotent: re-running with the same name updates nothing.",
|
|
3520
|
+
"Reaches no forge and needs no GitHub remote or credentials: the registry row is a pure local file write, and it is deliberately NOT recorded in the ownership manifest, so `eject` does not reverse adopter-declared data.",
|
|
3521
|
+
"Creates no label. Project is a field, not a label: a task Issue declares its project in the body's `**Project:**` field, and a `project:*` label is ignored wherever one still exists."
|
|
3522
|
+
],
|
|
3523
|
+
status: "shipped"
|
|
3524
|
+
},
|
|
3525
|
+
{
|
|
3526
|
+
name: "check",
|
|
3527
|
+
description: "Run one check, or every registered check",
|
|
3528
|
+
flags: [
|
|
3529
|
+
{ flag: "--all", description: "Run every registered check instead of one named check" },
|
|
3530
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" },
|
|
3531
|
+
{ flag: "--diff-only", description: "Scope diff-declared checks to changed files" },
|
|
3532
|
+
{
|
|
3533
|
+
flag: "--local",
|
|
3534
|
+
description: "Skip every requiresOpenPr check (closes-n, test-plan) — set by the generated hooks, never by CI"
|
|
3535
|
+
},
|
|
3536
|
+
{ flag: "--parallel[=n]", description: "Concurrency cap (default: cpu-derived)" },
|
|
3537
|
+
{
|
|
3538
|
+
flag: "--plan",
|
|
3539
|
+
description: "Print the resolved check registry and the resolved `roles` registry (default/overridden/additive) without running anything"
|
|
3540
|
+
}
|
|
3541
|
+
],
|
|
3542
|
+
details: [
|
|
3543
|
+
"Each spawned check's child process sees only a fixed baseline (`PATH`, `LANG`, `HOME`, `HTTPS_PROXY`, `HTTP_PROXY`, `NO_PROXY`, `TMPDIR`) plus whatever its `CheckSpec['env']` declaration explicitly forwards — never the full parent environment. A required (`true`) or unsatisfied `anyOf` declaration missing from the caller's environment synthesizes a `CheckError` before the check ever spawns. Declare `env` (a core check's own registration, or `vinaya.config.json`'s `checks.<name>.env` for a custom one) for any check that reads `process.env`/`Bun.env`/`Deno.env` directly — `vinaya doctor` carries the permanent diagnostic for one that doesn't.",
|
|
3544
|
+
"The resolved registry IS what runs. A `checks` key that exactly matches a core check id REPLACES that core check (the core one does not run); any other key must be namespaced `<yourname>/<id>`. Anything the resolver cannot classify — a malformed entry, a bare un-namespaced key matching no core id, a duplicate id — makes `vinaya check` refuse the ENTIRE run: exit 1, nothing executes, never a partial ruleset and never a core-only fallback. `vinaya doctor` carries the permanent diagnostic for each rejected entry, so a refused config is still diagnosable.",
|
|
3545
|
+
"`--plan` composes with `--json`. It requires zero env vars and never prints an env value — only how each one resolves (passthrough, optional, literal, or anyOf). A `FAIL_CLOSED` entry always renders inline rather than being dropped, and exits non-zero. `--plan` and execution read the same resolution, so what the plan prints is what runs.",
|
|
3546
|
+
"`--local` exists because a `requiresOpenPr` check (the core `closes-n`/`test-plan`, or a custom check declaring the same field) can only evaluate for real once a pull request exists — the generated `pre-commit`/`pre-push` hooks pass it so the first commit on a fresh task branch is never asked to satisfy a PR-body field before a PR can possibly exist. CI's `vinaya-checks.yml` omits it, so these checks always run for real once a PR is open.",
|
|
3547
|
+
"`--plan`'s `roles` half resolves `vinaya.config.json`'s `roles` block against bundled doctrine — same override/additive shape as `checks`, with its own RENDERS AS column (the registry key and the role's own `role_id` differ for an additive entry) and a GATING column (`core` vs. `inert` — an additive role carries no core `ACTIONS` wiring). `roles.available` is `false` only when no bundled doctrine can be found next to this CLI install."
|
|
3548
|
+
],
|
|
3549
|
+
status: "shipped"
|
|
3550
|
+
},
|
|
3551
|
+
{
|
|
3552
|
+
name: "commit-msg",
|
|
3553
|
+
description: "The generated `commit-msg` hook's invocation target — validates a commit message's first line",
|
|
3554
|
+
details: [
|
|
3555
|
+
"Not meant to be run by hand day-to-day: the managed `commit-msg` hook calls `vinaya commit-msg <message-file> [source]` with the two arguments git itself passes a commit-msg hook (githooks(5)) — the message file path and, when known, the commit's source keyword.",
|
|
3556
|
+
"Validates the message file's first line against the same `Type(scope): Description` vocabulary `check`'s `forge-title`-shaped gates enforce on PR/Issue titles (`@attalabs/aeg-core`'s `COMMIT_TYPES` — the commitlint type set plus `Plan`). Exits 0 with no output on a conforming message; a `source` of `merge` is skipped outright, since a merge commit's message is written by git, not the person committing."
|
|
3557
|
+
],
|
|
3558
|
+
status: "shipped"
|
|
3559
|
+
},
|
|
3560
|
+
{
|
|
3561
|
+
name: "new check",
|
|
3562
|
+
description: "Scaffold a custom check into ./scripts/vinaya-checks/",
|
|
3563
|
+
details: [
|
|
3564
|
+
"Takes the REGISTRATION KEY, not a bare name: `vinaya new check <yourname>/<id>` writes `./scripts/vinaya-checks/<id>.ts` and prints the namespaced `checks` entry to paste. It refuses a bare, un-namespaced name — `vinaya check` refuses its entire run over a key it cannot resolve, so scaffolding one would brick every check invocation in the repo — and refuses a core check id, since registering one REPLACES that core gate and a scaffolded stub is never what an adopter means by that."
|
|
3565
|
+
],
|
|
3566
|
+
status: "shipped"
|
|
3567
|
+
},
|
|
3568
|
+
{
|
|
3569
|
+
name: "new noop-check",
|
|
3570
|
+
description: "Scaffold an explicit no-op into vinaya/checks/ that silences a core check",
|
|
3571
|
+
details: [
|
|
3572
|
+
"Takes a CORE check id — the opposite of what `new check` accepts, which refuses one. `vinaya new noop-check <core-check-id>` writes `vinaya/checks/<id>.ts`, an explicit, contract-satisfying no-op (always exits `0`, emits no findings, carries a comment marking the silencing as intentional) and prints the `checks` entry that REPLACES the named core check with it. This is the only sanctioned way to silence a core check."
|
|
3573
|
+
],
|
|
3574
|
+
status: "shipped"
|
|
3575
|
+
},
|
|
3576
|
+
{
|
|
3577
|
+
name: "new role",
|
|
3578
|
+
description: "Scaffold an additive role contract into vinaya/roles/",
|
|
3579
|
+
details: [
|
|
3580
|
+
'Takes the REGISTRATION KEY: `vinaya new role <yourname>/<id>` writes `vinaya/roles/<id>.md` — a structurally-valid role contract stub (the six frontmatter keys plus `title`/`order`, and a non-empty "## The short version" section) whose own `role_id` is set to `<id>` — and prints the `roles` entry to paste. It refuses a bare, un-namespaced key: that shape resolves as an OVERRIDE of a core role, a complete replacement of that role\'s contract and a real governance decision this scaffolder does not make for you.'
|
|
3581
|
+
],
|
|
3582
|
+
status: "shipped"
|
|
3583
|
+
},
|
|
3584
|
+
{
|
|
3585
|
+
name: "brief render",
|
|
3586
|
+
description: "Emit the twelve-section brief skeleton from the forge and the tree, every derivable section filled",
|
|
3587
|
+
flags: [
|
|
3588
|
+
{ flag: "--surfaces <glob1,glob2,...>", description: "Intended surface globs, expanded against tracked files" },
|
|
3589
|
+
{ flag: "--out <path>", description: "Write the rendered brief to a file instead of stdout" }
|
|
3590
|
+
],
|
|
3591
|
+
details: [
|
|
3592
|
+
"Reads the task Issue (`vinaya/tranche:<tranche>`-labeled, id `<n>`) and the tree, and fills every section a program can derive: the header `Project:`/`Tier:`/`Closes #N`, the Step 0 worktree line, the dispatch-gate status as the pre-flight line, §4's file list (with consumer packages and a `sha256` premise pin per file, and Out of surface from the Issue's own `## Surface` `out:` list), §6 from the Issue's `## Parts`, §7 from the `.vinaya/doc-owners` derivation, §9 from the Issue's `## Test plan`, §10 from the Issue's `## Stop conditions` plus the rationale's Stop-and-escalate field, and every remaining section from the Issue's eight-field Planner rationale. Refuses — naming the missing section — when it cannot be derived: no Issue, the dispatch gate not clear, a `--surfaces` glob matching no tracked file, or the Issue missing/malformed `## Surface`/`## Parts`/`## Test plan`/`## Stop conditions` — never a bracketed placeholder.",
|
|
3593
|
+
"Never writes under `aeg-root/` or to the Issue — a brief is pasted to the Developer, never committed. Reads `aeg-root/templates/brief-template.md` at run time for its one fixed sentence and the standing autonomy clause; every other byte is generated from the forge/tree facts."
|
|
3594
|
+
],
|
|
3595
|
+
status: "shipped"
|
|
3596
|
+
},
|
|
3597
|
+
{
|
|
3598
|
+
name: "task dispatch",
|
|
3599
|
+
description: "Deprecated — render, pin, and post the brief on the Issue as the frozen original; start the developer",
|
|
3600
|
+
flags: [
|
|
3601
|
+
{ flag: "--agent <claude|codex|gemini>", description: "Start the developer through dispatchRole once posted" }
|
|
3602
|
+
],
|
|
3603
|
+
details: [
|
|
3604
|
+
"Renders the brief from the Issue and the tree (the same assembly `brief render` uses) and posts it once as an Issue comment whose first line is `<!-- aeg:brief:v1 -->` and whose second line is `Brief hash: <sha256>` — the hash covers only the body below those two lines, so any reader recomputes it. Refuses outright, naming the existing comment's URL, when a `v1` comment already exists on the Issue — the brief is frozen by design, never overwritten or silently reissued.",
|
|
3605
|
+
"With `--agent`, starts the Developer through `dispatchRole` when `apps/cli/src/lib/dispatch.ts` exports it; otherwise prints the rendered brief and the manual dispatch instruction and exits `0` — a soft dependency, never a hard block.",
|
|
3606
|
+
"Principal-only, with or without `--agent`: refuses before any render, forge read, or post when the authenticated `gh` identity is not on the Principal allowlist (or cannot be resolved at all) — dispatching is the `todo → in-flight` transition, not a general-purpose comment poster.",
|
|
3607
|
+
"Deprecated in favor of `task brief` (preparation only) and `task run` (the full unattended loop) — kept for a documented compatibility window while callers migrate."
|
|
3608
|
+
],
|
|
3609
|
+
status: "shipped"
|
|
3610
|
+
},
|
|
3611
|
+
{
|
|
3612
|
+
name: "task brief",
|
|
3613
|
+
description: "Render and freeze the brief as the Issue's original comment — preparation only, starts nobody",
|
|
3614
|
+
details: [
|
|
3615
|
+
"The preparation half of `task dispatch`, extracted so it is callable on its own: resolves the task's Issue, renders the brief, refuses on any gap, refuses when a frozen brief already exists, and posts it once as the same `aeg:brief:v1` Issue comment `task dispatch` posts. Starts no agent under any circumstances — there is no `--agent` flag here at all.",
|
|
3616
|
+
"Successor to `task dispatch` for the preparation step; the full unattended run (preparation, then the developer, then the review loop) is `task run`."
|
|
3617
|
+
],
|
|
3618
|
+
status: "shipped"
|
|
3619
|
+
},
|
|
3620
|
+
{
|
|
3621
|
+
name: "task run",
|
|
3622
|
+
description: "One command from a planned Issue to a reviewed pull request — exactly one developer started",
|
|
3623
|
+
flags: [
|
|
3624
|
+
{
|
|
3625
|
+
flag: "--agent <claude|codex|gemini>",
|
|
3626
|
+
description: "Vendor for the developer and both reviewers this run dispatches"
|
|
3627
|
+
}
|
|
3628
|
+
],
|
|
3629
|
+
details: [
|
|
3630
|
+
"Composes `task brief`'s own preparation (`prepareTask`) with the watching driver (`runDriverLoop`, `dev-review-loop.ts`) — nothing else. Preparation starts no agent; the loop's own round 1 reads the frozen brief off the Issue and is the only place a developer is ever dispatched from a fresh task, so exactly one developer is started by construction.",
|
|
3631
|
+
"A brief already frozen on the Issue is reused, never re-posted — the second `task dispatch`/`task brief` call this composes around does not fail the whole run, it just skips straight to running the loop. A task whose Issue refuses preparation (a missing brief section, an unmet dispatch gate) is refused before any agent starts, with nothing posted.",
|
|
3632
|
+
"Refuses when the frozen brief's developer branch already has an open pull request AND a driver is still live for it — a driver that crashed or was killed leaves its PR behind, and this command is the one that revives it, in any state, pause held or not.",
|
|
3633
|
+
"issue-711 O4: a pause never ends this process — it keeps running and watches the pull request, continuing on its own once a newer Principal ruling appears (or, for an `'infrastructure'`/`'stale_driver'` pause, after a bounded backoff), with no `--resume` command needed for the ordinary case. Exit and printed summary distinguish a published pull request OR a watched pause's own genuine end — merged, closed, or an operator's own `--cancel` (exit `0` either way, the PR URL) — from the one pause this process can never watch (no pull request exists yet — exit `1`, with the exact `vinaya task run <tranche> <n>` command to continue by hand), a usage/argv error (exit `2`), and any other failure (exit `3`)."
|
|
3634
|
+
],
|
|
3635
|
+
status: "shipped"
|
|
3636
|
+
},
|
|
3637
|
+
{
|
|
3638
|
+
name: "task status",
|
|
3639
|
+
description: "Every open task with a frozen brief, its pull request, and whether its loop is running, paused, or published",
|
|
3640
|
+
flags: [{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }],
|
|
3641
|
+
details: [
|
|
3642
|
+
"Read-only: one `gh issue list` for every open task Issue across every tranche (title/label resolved through the same `resolveTaskIssueRef` `list-tasks.ts` already uses), the open pull request per branch, and the driver pid record / pause record / publish effect markers under `<outboxRoot>/dev-review-loop/<task>/` — never a `ps` scan, never a re-parse of posted verdict comments to decide `published`.",
|
|
3643
|
+
"`running` names the driver's pid (`review-validity-v1` task 7's pid record); `paused` names the reason from the pause record; `published` means the newest round's reviewer and security verdict effect markers both read `posted`; `no driver` is the fallback when none of the above holds.",
|
|
3644
|
+
"`vinaya task status <tranche> <n>` narrows to one task and adds the last round's held or published verdict lines (`round-<n>-reviewer.md`/`round-<n>-security.md`, whichever their outbox carries) plus the exact `vinaya dev-review-loop --resume <pr>` command when paused."
|
|
3645
|
+
],
|
|
3646
|
+
status: "shipped"
|
|
3647
|
+
},
|
|
3648
|
+
{
|
|
3649
|
+
name: "task sweep",
|
|
3650
|
+
description: "Remove a finished task's folder — its Issue closed, or its pull request merged or closed — printing each folder removed or kept with the reason",
|
|
3651
|
+
flags: [
|
|
3652
|
+
{
|
|
3653
|
+
flag: "--include-legacy",
|
|
3654
|
+
description: "Also remove whatever the earlier, pre-`tasks-execution` layout left behind that this pass can attribute to a finished task of this repository"
|
|
3655
|
+
},
|
|
3656
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3657
|
+
],
|
|
3658
|
+
details: [
|
|
3659
|
+
"Keeps a folder with an open pull request, a live driver, or a pause — every reason printed alongside the folder it names. Removes nothing when the forge cannot be read for a folder: a read failure or an unresolvable task is kept and reported, never guessed as finished.",
|
|
3660
|
+
"Always lists the eight top-level folders an earlier, pre-`tasks-execution` layout (or an operator's own hand) left under the Vinaya home, plus the even-older per-task tree nested inside the telemetry outbox root itself (see the README's command table for their names), each attributed to this repository only through its own path or its own record content naming it — never a bare, repository-less task number. `--include-legacy` removes only what it can both attribute this way AND classify finished; every unattributable entry is only ever reported, never deleted.",
|
|
3661
|
+
"Never touches the telemetry outbox or the machine-wide files under the Vinaya home (the configuration and the token trust file) — no sweep removes either.",
|
|
3662
|
+
"The driver (`dev-review-loop`/`task run`) calls the same function at the start of every run, before it dispatches anyone; a sweep failure there is reported and ignored rather than blocking the run."
|
|
3663
|
+
],
|
|
3664
|
+
status: "shipped"
|
|
3665
|
+
},
|
|
3666
|
+
{
|
|
3667
|
+
name: "task-tools serve",
|
|
3668
|
+
description: "Run the task-operator MCP tool server over stdio — the command both runtime adapters register",
|
|
3669
|
+
details: [
|
|
3670
|
+
"Exposes the task-operator tool catalog (`packages/aeg-core/src/task-tools.ts`) to an agent runtime as one MCP server speaking newline-delimited JSON-RPC 2.0 (`initialize`/`tools/list`/`tools/call`). Claude registers it through the generated `.mcp.json`; Codex through its documented `~/.codex/config.toml` `[mcp_servers]` table — both point at this same command.",
|
|
3671
|
+
"stdout carries JSON-RPC and nothing else: any stray write from the CLI (a forge-read warning) is redirected to stderr, so the protocol stream is never corrupted.",
|
|
3672
|
+
"`task_status`/`task_escalation_read`/`task_pr_read` read; `task_pr_read` returns the selected task's OWN pull request — every required and reported check with its state, conclusion and failure summary, plus the principal-authored review record (newest verdicts and their judged head, round markers, published summary table, pause comment) — and refuses any other pull request; `task_start` starts a run in attended mode only, requiring an authenticated caller from the invocation context (`VINAYA_MCP_CALLER`) and refusing without one — MCP is a transport, not authorization. `task_resume`/`task_cancel` require the same authenticated caller, plus a current Principal ruling read fresh from the run's own PR — never a caller-supplied approval; `task_resume` triggers the existing `dev-review-loop --resume` continuation exactly once per escalation, and `task_cancel` reports a truthful `confirmed`/`pending`/`uncertain` outcome, idempotently, across repeated calls. No unattended start until the worker-isolation boundary and a capability flag land."
|
|
3673
|
+
],
|
|
3674
|
+
status: "shipped"
|
|
3675
|
+
},
|
|
3676
|
+
{
|
|
3677
|
+
name: "pr create",
|
|
3678
|
+
description: "Open a pull request after full brief-schema validation",
|
|
3679
|
+
flags: [
|
|
3680
|
+
{ flag: "--title", description: "PR title (validated against the forge-title grammar)" },
|
|
3681
|
+
{ flag: "--body-file", description: "Path to the PR body (stream-safe; the same bytes are validated and sent)" },
|
|
3682
|
+
{ flag: "--label", description: "Label(s) to apply (repeatable, comma-separated)" },
|
|
3683
|
+
{ flag: "--validate-only", description: "Run every gate and report PASS without opening the PR" },
|
|
3684
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3685
|
+
],
|
|
3686
|
+
details: [
|
|
3687
|
+
"Runs the config-defined brief-schema gate (`briefSchema.pr` in `vinaya.config.json`) LOCALLY before any `gh` write — prevention, not detection. On any failure it refuses with the versioned CheckError contract (one JSON line per finding on stderr, exit 1) whose `agent_recovery_prompt` names the exact corrective command.",
|
|
3688
|
+
"Which sections bind depends on the branch, matching the `brief-shape` check that runs the same grammar in CI. On a `task/<tranche>/<n>` branch every configured section binds, `closesN` included. On any other branch a body that is not brief-shaped is exempt entirely — an ordinary one-line dependency bump is not made to grow a brief — while a brief-shaped body is still graded on every other section, since a standalone fix brief is a brief; only `closesN` is dropped, because such a branch has no task Issue to close. The title grammar sits outside all of this and binds on every branch.",
|
|
3689
|
+
"A branch counts as resolvable only when HEAD is a symbolic ref that also resolves to a commit. Neither git query answers that alone: `rev-parse --abbrev-ref HEAD` reports the literal string `HEAD` on a detached HEAD, and `symbolic-ref` reports the not-yet-created branch name when HEAD is unborn. Reading either as an ordinary branch would take the relaxed path, so both states — plus running outside a repo — resolve to nothing and the gate is fail-closed: every configured section is enforced."
|
|
3690
|
+
],
|
|
3691
|
+
status: "shipped"
|
|
3692
|
+
},
|
|
3693
|
+
{
|
|
3694
|
+
name: "pr edit",
|
|
3695
|
+
description: "Edit an existing pull request (<n>) after full brief-schema validation",
|
|
3696
|
+
flags: [
|
|
3697
|
+
{ flag: "--title", description: "New PR title (validated against the forge-title grammar)" },
|
|
3698
|
+
{ flag: "--body-file", description: "Path to the new PR body (stream-safe; same bytes validated and sent)" },
|
|
3699
|
+
{ flag: "--validate-only", description: "Run every gate and report PASS without editing the PR" },
|
|
3700
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3701
|
+
],
|
|
3702
|
+
details: [
|
|
3703
|
+
"The target PR's real head branch and changed files are fetched from the forge to build the validation context — a failed fetch is a hard refusal, never a fall-back to the local checkout.",
|
|
3704
|
+
"That fetched head branch is what selects the section set, by the same branch grammar `pr create` uses — a property of the target PR, never of whatever the local checkout happens to have checked out."
|
|
3705
|
+
],
|
|
3706
|
+
status: "shipped"
|
|
3707
|
+
},
|
|
3708
|
+
{
|
|
3709
|
+
name: "pr report",
|
|
3710
|
+
description: "Emit the AEG:EVIDENCE block — a PR body's factual claims, from commands, never typed",
|
|
3711
|
+
flags: [
|
|
3712
|
+
{
|
|
3713
|
+
flag: "--write",
|
|
3714
|
+
description: "Path to the PR body file; replaces the content between the AEG:EVIDENCE anchors in place"
|
|
3715
|
+
},
|
|
3716
|
+
{
|
|
3717
|
+
flag: "--push",
|
|
3718
|
+
description: "PR number; splices the same content into that PR's LIVE body (fetched from the forge) and pushes it via `gh pr edit`, self-verifying nothing outside the AEG:EVIDENCE/AEG:TOKENS regions changed. Mutually exclusive with --write."
|
|
3719
|
+
}
|
|
3720
|
+
],
|
|
3721
|
+
details: [
|
|
3722
|
+
"Two groups: Group A (recomputable) is the head sha and a width-invariant `git diff --numstat` against the merge-base with `BASE_SHA` (else `origin/main`, then `main`) — `check-evidence-fresh` recomputes and byte-compares this exactly. Group B (attested) is the result of `vinaya check --all --diff-only`, this CLI's own portable gate suite — `check-evidence-fresh` can only check it for staleness (the block's recorded head still matches the PR's real head), never re-run it.",
|
|
3723
|
+
"With no `--write`/`--push`, prints the block to stdout instead of writing a file. Exits non-zero whenever the gate run failed, whether or not `--write`/`--push` was given — the block records a failing result rather than hiding one, and a non-zero exit stops a scripted `--write && open-pr` (or `--push`) from carrying a failing suite onto the forge.",
|
|
3724
|
+
"`--push` refuses before writing anything when the live body carries no real `AEG:EVIDENCE` pair (it never appends one, unlike `--write`), when the anchor resolves differently before and after normalisation, or when `<pr>` isn't a bare number. When the live body has no real `AEG:TOKENS` pair, the token splice is skipped (same reasoning, softer outcome) rather than creating one. After pushing, it re-reads the live body and restores the pre-edit body — exiting non-zero — if anything outside the two anchored regions changed."
|
|
3725
|
+
],
|
|
3726
|
+
status: "shipped"
|
|
3727
|
+
},
|
|
3728
|
+
{
|
|
3729
|
+
name: "pr rule",
|
|
3730
|
+
description: "Post a Principal ruling on a PR, marked and versioned — never mistaken for a review verdict",
|
|
3731
|
+
flags: [
|
|
3732
|
+
{ flag: "--file", description: "Path to the ruling file to post as a PR comment" },
|
|
3733
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3734
|
+
],
|
|
3735
|
+
details: [
|
|
3736
|
+
"Refuses before posting when the file's first line reads as an escalation (`ESCALATE:`), or when the file carries verdict grammar anywhere `extractCodeReviewVerdict`/`extractSecurityReviewVerdict` would treat as a candidate — a `VERDICT:` line past the extractor's own first-five-line window still counts, since the whole-body candidate test is what disqualifies the file, not merely a clean read.",
|
|
3737
|
+
"Marker numbers (`<!-- aeg:principal:ruling:<pr>-<k> -->`) are counted on the forge at post time from `gh pr view --json comments`, never derived from a local file — two rulings racing to the same number are a known, undocumented-lock case."
|
|
3738
|
+
],
|
|
3739
|
+
status: "shipped"
|
|
3740
|
+
},
|
|
3741
|
+
{
|
|
3742
|
+
name: "pr verify-evidence",
|
|
3743
|
+
description: "Prove a pull request's AEG:EVIDENCE region was machine-generated — regenerate it and compare",
|
|
3744
|
+
flags: [],
|
|
3745
|
+
details: [
|
|
3746
|
+
"Deliberately a command, not a check: `evidence-fresh` runs inside `vinaya check --all`, and `pr report` runs `vinaya check --all --diff-only`, so a check that regenerated the block would run the suite containing itself. That recursion is why `evidence-fresh` verifies Group A only and leaves Group B attested.",
|
|
3747
|
+
"Must be run from the repository ROOT of a CLEAN checkout at the pull request's head, and refuses otherwise. The regeneration inherits the working directory and several gates resolve their scan root from it, so a subdirectory silently narrows what the fresh run inspects. On cleanliness: Group B is regenerated by diff-scoped checks, so uncommitted or untracked files change which files are scanned and can produce a MATCH a clean checkout would not. Ignored paths are deliberately NOT inspected — `git diff` never reports one, so they cannot change the scope, and including them would refuse in every real checkout since `node_modules` is ignored and always present. The head is read from the forge and both a mismatch AND an unreadable head refuse — the verdict is bound to a commit, never merely attested. `BASE_SHA` is refused as well, since it steers the regeneration's merge-base.",
|
|
3748
|
+
"Exits 0 on MATCH; 1 on DIFFERS, HIDDEN, or no block; 2 on a refusal (dirty worktree, wrong head, usage error). HIDDEN means the anchor pair sits inside a collapsed `<details>` block, where `body-bare-digits` blanks every digit and nothing can verify what it claims.",
|
|
3749
|
+
"Comparison is a multiset of repo-relative, control-stripped lines: absolute paths (local AND foreign, so a block generated in CI compares against one generated on a laptop) and line order are ignored — a reorder is not a fabrication. Only the AEG:EVIDENCE region is read, since AEG:TOKENS appends by design. A moved merge-base is reported ALONGSIDE the differing lines, never instead of them."
|
|
3750
|
+
],
|
|
3751
|
+
status: "shipped"
|
|
3752
|
+
},
|
|
3753
|
+
{
|
|
3754
|
+
name: "issue create",
|
|
3755
|
+
description: "Open an issue after full brief-schema validation",
|
|
3756
|
+
flags: [
|
|
3757
|
+
{ flag: "--title", description: "Issue title (validated on task Issues)" },
|
|
3758
|
+
{ flag: "--body-file", description: "Path to the Issue body (stream-safe; same bytes validated and sent)" },
|
|
3759
|
+
{ flag: "--label", description: "Label(s) to apply; a `vinaya/tranche:*` label marks a task Issue" },
|
|
3760
|
+
{ flag: "--validate-only", description: "Run every gate and report PASS without opening the Issue" },
|
|
3761
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3762
|
+
],
|
|
3763
|
+
details: [
|
|
3764
|
+
"A task Issue (any `vinaya/tranche:*` label) must carry the full Planner rationale (`briefSchema.issue`); non-task Issues pass through unvalidated."
|
|
3765
|
+
],
|
|
3766
|
+
status: "shipped"
|
|
3767
|
+
},
|
|
3768
|
+
{
|
|
3769
|
+
name: "issue edit",
|
|
3770
|
+
description: "Edit an existing issue (<n>) after full brief-schema validation",
|
|
3771
|
+
flags: [
|
|
3772
|
+
{ flag: "--title", description: "New Issue title (validated on task Issues)" },
|
|
3773
|
+
{ flag: "--body-file", description: "Path to the new Issue body (stream-safe; same bytes validated and sent)" },
|
|
3774
|
+
{ flag: "--validate-only", description: "Run every gate and report PASS without editing the Issue" },
|
|
3775
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3776
|
+
],
|
|
3777
|
+
details: [
|
|
3778
|
+
"The target Issue's actual labels are fetched from the forge and unioned with argv to decide task-Issue applicability — a failed fetch is a hard refusal."
|
|
3779
|
+
],
|
|
3780
|
+
status: "shipped"
|
|
3781
|
+
},
|
|
3782
|
+
{
|
|
3783
|
+
name: "issue objectives edit",
|
|
3784
|
+
description: "Rewrite a task Issue's `## Objectives` section by command — versioned, findable on the forge",
|
|
3785
|
+
flags: [
|
|
3786
|
+
{ flag: "--add", description: "Append a new objective as `O<max+1>` with the given sentence" },
|
|
3787
|
+
{ flag: "--drop", description: "Remove an objective by id (`O<k>`) — never renumbers the survivors" },
|
|
3788
|
+
{
|
|
3789
|
+
flag: "--replace",
|
|
3790
|
+
description: 'Replace an objective\'s sentence in place, keeping its id (`O<k>` "<sentence>")'
|
|
3791
|
+
},
|
|
3792
|
+
{ flag: "--reason", description: "Required, non-empty: why this change is being made" },
|
|
3793
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3794
|
+
],
|
|
3795
|
+
details: [
|
|
3796
|
+
"Exactly one of `--add`/`--drop`/`--replace` is required. Every edit goes through the same validated `issue edit` write path (`writeValidatedIssueEdit`) as `vinaya issue edit` itself — no second, unvalidated write path.",
|
|
3797
|
+
"A `--drop` that leaves the surviving objectives non-contiguous from `O1` is refused with `objectivesOf`'s own parser message: dropping never renumbers survivors, and task 1's contiguous-from-O1 grammar is the one parser everything else reads, so a live contradiction between the two stops here for a Principal ruling rather than silently renumbering.",
|
|
3798
|
+
"Splices the rendered section back in place (`## Objectives` heading through the next `##` heading, or end of body) — every other byte of the Issue body is untouched. Posts one comment marked `<!-- aeg:objectives:v<k> -->` carrying the previous list, the new list, the reason, and the new `objectivesVersion`; `k` is counted on the forge at post time, never derived from a local file."
|
|
3799
|
+
],
|
|
3800
|
+
status: "shipped"
|
|
3801
|
+
},
|
|
3802
|
+
{
|
|
3803
|
+
name: "milestone create",
|
|
3804
|
+
description: "Create a GitHub Milestone from a validated body",
|
|
3805
|
+
flags: [
|
|
3806
|
+
{ flag: "--title", description: "Milestone title — free text, never parsed for a version" },
|
|
3807
|
+
{
|
|
3808
|
+
flag: "--body-file",
|
|
3809
|
+
description: "Path to the Milestone description (stream-safe; same bytes validated and sent)"
|
|
3810
|
+
},
|
|
3811
|
+
{ flag: "--validate-only", description: "Run every gate and report PASS without creating the Milestone" },
|
|
3812
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3813
|
+
],
|
|
3814
|
+
details: [
|
|
3815
|
+
"Refuses before any `gh` call when the goal is absent, an optional `Release:` field is present but not a version, or an optional `### Tranche intents` section (`- <slug>: <intent text>`) doesn't parse. `Release:` is the sole authority for the milestone's version — the title is never parsed for one."
|
|
3816
|
+
],
|
|
3817
|
+
status: "shipped"
|
|
3818
|
+
},
|
|
3819
|
+
{
|
|
3820
|
+
name: "milestone adopt",
|
|
3821
|
+
description: "Move one or more existing tranches into a target Milestone",
|
|
3822
|
+
flags: [
|
|
3823
|
+
{ flag: "--target", description: "The Milestone every named slug is adopted into" },
|
|
3824
|
+
{ flag: "--slug", description: "A tranche slug to adopt — repeatable for a multi-slug move" },
|
|
3825
|
+
{ flag: "--validate-only", description: "Run every gate and report PASS without writing anything" },
|
|
3826
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3827
|
+
],
|
|
3828
|
+
details: [
|
|
3829
|
+
"Reattaches every Issue carrying each named `vinaya/tranche:<slug>` label to `--target`, then closes (never deletes) each slug's old tranche-Milestone. Every fact for every named slug is gathered and checked in ONE call before any write, so a single unsafe slug — an unknown slug, a slug whose label carries no Issues, a target that does not exist or is closed, or a slug already adopted into a different Milestone — refuses the whole invocation, not just its own slug."
|
|
3830
|
+
],
|
|
3831
|
+
status: "shipped"
|
|
3832
|
+
},
|
|
3833
|
+
{
|
|
3834
|
+
name: "milestone edit",
|
|
3835
|
+
description: "Edit an existing Milestone (<n>) after full brief-schema validation",
|
|
3836
|
+
flags: [
|
|
3837
|
+
{
|
|
3838
|
+
flag: "--body-file",
|
|
3839
|
+
description: "Path to the new Milestone description (stream-safe; same bytes validated and sent)"
|
|
3840
|
+
},
|
|
3841
|
+
{ flag: "--validate-only", description: "Run every gate and report PASS without editing the Milestone" },
|
|
3842
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3843
|
+
],
|
|
3844
|
+
details: [
|
|
3845
|
+
"Same `checkMilestoneShape` refusal `create` runs, before any `gh` call — the gated replacement for a raw `gh api PATCH` against a Milestone. Only the description changes; the title is untouched."
|
|
3846
|
+
],
|
|
3847
|
+
status: "shipped"
|
|
3848
|
+
},
|
|
3849
|
+
{
|
|
3850
|
+
name: "milestone close",
|
|
3851
|
+
description: "Close a tranche's Milestone after verifying every labeled Issue is actually attached",
|
|
3852
|
+
flags: [
|
|
3853
|
+
{ flag: "--slug", description: "The tranche whose Milestone is being closed" },
|
|
3854
|
+
{ flag: "--validate-only", description: "Run every gate and report PASS without closing the Milestone" },
|
|
3855
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3856
|
+
],
|
|
3857
|
+
details: [
|
|
3858
|
+
"Resolves the target Milestone the same legacy-or-intent-declared way Issue create auto-attach does, then refuses to close on any mismatch between the label's Issues and the Milestone's natively attached Issues — naming each unattached or foreign Issue and its repair path (`gh issue edit <n> --milestone <title>`, or `vinaya milestone adopt`) — before the PATCH ever reaches the forge."
|
|
3859
|
+
],
|
|
3860
|
+
status: "shipped"
|
|
3861
|
+
},
|
|
3862
|
+
{
|
|
3863
|
+
name: "milestone status",
|
|
3864
|
+
description: "Print each of a Milestone's declared tranche intents with its derived lifecycle and issue counts",
|
|
3865
|
+
flags: [{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }],
|
|
3866
|
+
details: [
|
|
3867
|
+
"Read-only — writes nothing. For each `- <slug>: …` line in the Milestone's `### Tranche intents` section, prints the tranche's lifecycle (`planned`/`active`/`complete`) and its labeled Issues' counts (merged, open, not planned), all derived from the forge. Refuses if `<n>` isn't a real Milestone in this repo, or if the forge is unreachable."
|
|
3868
|
+
],
|
|
3869
|
+
status: "shipped"
|
|
3870
|
+
},
|
|
3871
|
+
{
|
|
3872
|
+
name: "review status",
|
|
3873
|
+
description: "Print the review loop's own state for a PR, and its branch's distance from the base",
|
|
3874
|
+
details: [
|
|
3875
|
+
"Two lines at most. The first is `CONTINUE`, `PAUSE: <reason>[ <id>]` for `reappearance`, `zero-deaths` or `max-rounds` — or, for `stale`, the actionable fact itself: `push after verdict — re-review required`. The second reads `behind main by <n> — merge first` when the branch is behind its base, or `behind main: unknown — fetch origin/<base> first` when git cannot measure the distance; it is absent only when the branch is measurably not behind.",
|
|
3876
|
+
"Rounds are derived from the PR's own verdict comments — one round per `Judged head:` value, read through the same extractors the merge gate blocks on, and only from comments an allowlisted principal authored. A Developer round comment is recognised by its `<!-- aeg:developer:round-<n> -->` marker, at that fixed position, never by scanning its prose.",
|
|
3877
|
+
"Exit `0` only when the state is `CONTINUE` and the branch is not behind; `1` otherwise, so a script can gate on the exit code without parsing the text."
|
|
3878
|
+
],
|
|
3879
|
+
status: "shipped"
|
|
3880
|
+
},
|
|
3881
|
+
{
|
|
3882
|
+
name: "review post",
|
|
3883
|
+
description: "Render, post, and self-verify a code-reviewer or security-review verdict comment on a PR",
|
|
3884
|
+
flags: [
|
|
3885
|
+
{ flag: "--role", description: "`code-reviewer` or `security` — selects which role template is rendered" },
|
|
3886
|
+
{
|
|
3887
|
+
flag: "--pr",
|
|
3888
|
+
description: "Target PR number — its real head is resolved via `gh pr view`, never caller-supplied"
|
|
3889
|
+
},
|
|
3890
|
+
{
|
|
3891
|
+
flag: "--verdict",
|
|
3892
|
+
description: "Optional — derived from the findings file (code-reviewer: `APPROVE`/`REQUEST_CHANGES`; security: `PASS`/`FAIL`). Refused before posting if it disagrees with the derivation."
|
|
3893
|
+
},
|
|
3894
|
+
{
|
|
3895
|
+
flag: "--escalate",
|
|
3896
|
+
description: "`authority` | `strategy` | `product` — posts an `ESCALATE:` comment instead of a verdict. Refused together with `--verdict` or a blocking finding."
|
|
3897
|
+
},
|
|
3898
|
+
{ flag: "--summary", description: "Required with `--escalate` — the escalation body text" },
|
|
3899
|
+
{
|
|
3900
|
+
flag: "--findings-file",
|
|
3901
|
+
description: "One finding per line: `SEVERITY|file:line|description` (`|`-delimited). A re-review names a prior id in the description as `F<n> <class> <state>:`. Omit for zero findings."
|
|
3902
|
+
},
|
|
3903
|
+
{
|
|
3904
|
+
flag: "--objectives-file",
|
|
3905
|
+
description: "One line per objective: `O<n>|MET|<evidence>` or `O<n>|NOT MET|<evidence>` (`|`-delimited; evidence is the rest of the line). Required whenever the closed Issue (or the PR body's own `## Objectives`) has an objectives list to judge; its ids must cover that list exactly, and a re-review must restate every prior objective. Never together with `--escalate`."
|
|
3906
|
+
},
|
|
3907
|
+
{ flag: "--brief-conformance", description: "code-reviewer only: the BRIEF CONFORMANCE line" },
|
|
3908
|
+
{ flag: "--spec-conformance", description: "code-reviewer only: the SPEC CONFORMANCE line" },
|
|
3909
|
+
{ flag: "--scope", description: "code-reviewer only: the SCOPE line" },
|
|
3910
|
+
{
|
|
3911
|
+
flag: "--scope-evidence-file",
|
|
3912
|
+
description: "code-reviewer only: pasted diff-stat output, rendered as a fence directly below the verdict block"
|
|
3913
|
+
},
|
|
3914
|
+
{ flag: "--tests", description: "code-reviewer only: the TESTS line" },
|
|
3915
|
+
{ flag: "--docs", description: "code-reviewer only: the DOCS line" },
|
|
3916
|
+
{ flag: "--config-scan", description: "security only: the CONFIG SCAN line" },
|
|
3917
|
+
{ flag: "--secrets", description: "security only: the SECRETS line" },
|
|
3918
|
+
{
|
|
3919
|
+
flag: "--secrets-evidence-file",
|
|
3920
|
+
description: 'security only: required whenever `--secrets` claims "none found" — the pasted scanner output backing that claim'
|
|
3921
|
+
},
|
|
3922
|
+
{ flag: "--task-id", description: "the closing `Tokens:` line's task id" },
|
|
3923
|
+
{ flag: "--model", description: "the closing `Tokens:` line's model name" },
|
|
3924
|
+
{ flag: "--tokens-in", description: "a non-negative integer, or `-` if unknown" },
|
|
3925
|
+
{ flag: "--tokens-out", description: "a non-negative integer, or `-` if unknown" },
|
|
3926
|
+
{ flag: "--cost", description: "free text, or `-` if unknown" },
|
|
3927
|
+
{
|
|
3928
|
+
flag: "--print-only",
|
|
3929
|
+
description: "Render and self-check the comment, print it, and exit — never calls `gh pr comment`"
|
|
3930
|
+
},
|
|
3931
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
3932
|
+
],
|
|
3933
|
+
details: [
|
|
3934
|
+
"`--print-only` runs the exact same render-then-self-check path as a real post, then returns before `gh pr comment` — closes atta-labs/vinaya#184, where the old command silently posted a verdict anyway after a reviewer guessed this flag existed.",
|
|
3935
|
+
"Every structural line (`VERDICT:`, `Judged head:`) is rendered from this command's own validated enum/sha inputs — never from a caller-supplied string — so a Reviewer's free-typed prose can no longer produce a shape the merge gate's line-anchored regex fails to see.",
|
|
3936
|
+
"The verdict is derived, not typed: a BLOCKER (or CRITICAL/HIGH) finding forces REQUEST_CHANGES/FAIL and its absence forces APPROVE/PASS, before posting anything — an explicit `--verdict` that disagrees is refused naming the derived value. When a same-role verdict comment already exists on the PR, a new findings file must carry every prior id with a state and no non-blocking finding outside the diff since that comment's judged head, or the post is refused.",
|
|
3937
|
+
"Renders an `OBJECTIVES:` block (one `O<n>: MET | NOT MET — <evidence>` line per objective) after `SPEC CONFORMANCE:`/before `CONFIG SCAN:`, and an `Objectives version:` line at line 5 — resolved from the closed Issue's `## Objectives` list, or the PR body's own section when it closes none. A clean verdict (`APPROVE`/`PASS`) is refused alongside any `NOT MET`; an Issue below the objectives cutover renders neither line at all, matching the merge gate's own skip.",
|
|
3938
|
+
"Before the post ever reaches the forge, runs the exact `extractCodeReviewVerdict`/`extractSecurityReviewVerdict` functions `checkReviewGate` calls over its own rendered text and refuses (exit 2) unless exactly the intended verdict extracts and the other role extracts none — an escalation requires both to extract none. Both extractors read only a comment's first five lines; a code-review or security render's caller-supplied fields never open one of those lines, but an escalation's `--summary` can (pre-cutover, it becomes line 5 unprefixed) — this pre-post re-parse, not the render's construction, is what catches that case before it ever reaches the forge.",
|
|
3939
|
+
"After posting, re-fetches the PR's comments and runs them through the same extractors `checkReviewGate` calls — the same functions, not a second implementation — and exits non-zero naming precisely what failed to re-parse if the post does not come back clean, bound to the resolved head and objectives version, and free of the other role's verdict. There is no `--skip-verify` escape."
|
|
3940
|
+
],
|
|
3941
|
+
status: "shipped"
|
|
3942
|
+
},
|
|
3943
|
+
{
|
|
3944
|
+
name: "doctor",
|
|
3945
|
+
description: "Diagnose hook, workflow, and config health — report only, never mutates",
|
|
3946
|
+
flags: [{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }],
|
|
3947
|
+
details: [
|
|
3948
|
+
'Carries the same env-declaration diagnostic `vinaya check` warns with — permanently, at `info` severity, not just ahead of the spawn-default flip — plus a `warn`-severity lint over suspicious `env` literal forms (a stray `"true"`/`"false"` string, or a high-entropy literal that reads like a leaked secret committed to config).',
|
|
3949
|
+
"Also carries the two permanent `checks`-classification diagnostics: a config key that REPLACES a core check (`warn`), and a bare un-namespaced key that is REJECTED (`error`, naming the rename requirement). These are the reason a config `vinaya check` now refuses outright is still diagnosable — the refusal runs nothing, so `doctor` is the surface that explains why."
|
|
3950
|
+
],
|
|
3951
|
+
status: "shipped"
|
|
3952
|
+
},
|
|
3953
|
+
{
|
|
3954
|
+
name: "tokens",
|
|
3955
|
+
description: "Print a role's `Tokens: …` report line — the portable front door over the collection adapter",
|
|
3956
|
+
flags: [
|
|
3957
|
+
{ flag: "--phase", description: 'e.g. `"<task-id>: develop"` — required' },
|
|
3958
|
+
{ flag: "--role", description: "e.g. `Developer` — required" },
|
|
3959
|
+
{ flag: "--model", description: "Overrides the model id the adapter derived, if given" },
|
|
3960
|
+
{
|
|
3961
|
+
flag: "--transcript",
|
|
3962
|
+
description: "Read this transcript directly. Supported primary route — use it whenever you know which transcript " + "is yours, and always in a repo with no track-transcript.sh hook. Omitted resolves via the Stop-hook " + "pointer file, if this repo installs that hook."
|
|
3963
|
+
},
|
|
3964
|
+
{
|
|
3965
|
+
flag: "--in / --out",
|
|
3966
|
+
description: "Manual entry: the exact token figures, for a host whose usage arrives by some other means than a " + "Claude Code transcript. Both required together; skips transcript resolution entirely."
|
|
3967
|
+
}
|
|
3968
|
+
],
|
|
3969
|
+
details: [
|
|
3970
|
+
"Resolves the Claude Code collection adapter (`resolveMeteringCapability`, `summarizeTranscript`, `formatTokensLine`) from the INSTALLED `@attalabs/aeg-core` package, never by a repo-relative path — the fix for `packages/aeg-core/bin/report-tokens.ts` not existing in an adopter repo with no local `packages/`.",
|
|
3971
|
+
"Refuses — never emits a `0/0/—` line — when no transcript resolves, a resolved transcript can't be read, or it summarizes to zero usage records (empty, unparseable, or not yet flushed to disk). Capability is probed by actually attempting resolution, never declared from the host being Claude Code."
|
|
3972
|
+
],
|
|
3973
|
+
status: "shipped"
|
|
3974
|
+
},
|
|
3975
|
+
{
|
|
3976
|
+
name: "doctrine",
|
|
3977
|
+
description: "Print the absolute path of the bundled doctrine's front door (aeg-root/skills/aeg/SKILL.md) on this machine",
|
|
3978
|
+
flags: [
|
|
3979
|
+
{
|
|
3980
|
+
flag: "--role <name>",
|
|
3981
|
+
description: "Resolve to a specific role file (roles/<name>.md) instead of the front door"
|
|
3982
|
+
},
|
|
3983
|
+
{
|
|
3984
|
+
flag: "--print",
|
|
3985
|
+
description: "Emit the resolved file's body (frontmatter stripped) instead of its path — the one-hop mode every generated skill and slash command invokes. A role file whose frontmatter carries an `ack-token` emits that token as the output's own first line."
|
|
3986
|
+
},
|
|
3987
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1) — `{ root, entry }`" }
|
|
3988
|
+
],
|
|
3989
|
+
details: [
|
|
3990
|
+
"The committed root `VINAYA.md` pointer names the `@attalabs/vinaya` package, never a filesystem path — where the package sits is a property of each machine, not of the repo, and the pointer is committed for every clone. This command is the read-time resolution step the pointer hands the reader: it resolves the installed package's own bundled `aeg-root/` wherever the CLI physically sits and prints the front door's absolute path, so `cat \"$(vinaya doctrine)\"` opens the doctrine on any machine at any version.",
|
|
3991
|
+
"In a repo that vendors the CLI, the bundled copy is a gitignored pack-time artifact, so the command falls back to the monorepo root's own `aeg-root/` — the same directory `bundle-doctrine` copies from. Exits 1 with a corrective message when neither location holds a doctrine."
|
|
3992
|
+
],
|
|
3993
|
+
status: "shipped"
|
|
3994
|
+
},
|
|
3995
|
+
{
|
|
3996
|
+
name: "upgrade",
|
|
3997
|
+
description: "Regenerate hooks, workflow, and config to the current contract version (diff-and-confirm)",
|
|
3998
|
+
flags: [
|
|
3999
|
+
{ flag: "--dry-run", description: "Print the full diff without regenerating anything" },
|
|
4000
|
+
{ flag: "--yes", description: "Skip the confirmation prompt" }
|
|
4001
|
+
],
|
|
4002
|
+
details: [
|
|
4003
|
+
"When `claude` is a selected agent vendor, also retrofits the Claude Code `Stop` hook (`.claude/hooks/track-transcript.sh`, `.claude/settings.json`) the same way `init` installs it on a fresh repo — for a repo that ran `init` before this hook existed, closing the gap that left token rows reading `—/—/—` with no operator ever told to re-run `init`. Never overwrites a foreign `.claude/settings.json` (refuse-if-foreign, same as `init`); appends to a foreign Stop-hook script rather than replacing it (managed-block, same discipline as the git hooks)."
|
|
4004
|
+
],
|
|
4005
|
+
status: "shipped"
|
|
4006
|
+
},
|
|
4007
|
+
{
|
|
4008
|
+
name: "archive",
|
|
4009
|
+
description: "Run the post-merge Archivist directly: provenance + Issue close-out for a merged task PR",
|
|
4010
|
+
flags: [{ flag: "--merge-sha", description: "The merge commit to resolve (defaults to the current HEAD)" }],
|
|
4011
|
+
details: [
|
|
4012
|
+
"Resolves the merge commit's associated PR via `gh`, and — if it's a task PR without a provenance comment yet — posts the provenance block and closes the linked Issue. Idempotent: re-running against an already-archived PR is a no-op.",
|
|
4013
|
+
"The same logic the generated `vinaya-archivist.yml` workflow's `post-merge` job runs on every push to `main` — callable directly for a one-off run or local verification.",
|
|
4014
|
+
"All progress output writes through `process.stdout.write`/`process.stderr.write` (never bare `console.*`), so piping this command into a log file or a CI step captures every line in order."
|
|
4015
|
+
],
|
|
4016
|
+
status: "shipped"
|
|
4017
|
+
},
|
|
4018
|
+
{
|
|
4019
|
+
name: "archive tranche",
|
|
4020
|
+
description: "Close a tranche — the tranche-level bookend to `init product`, closing the Milestone via the CLI",
|
|
4021
|
+
flags: [{ flag: "--yes", description: "Skip the confirmation prompt" }],
|
|
4022
|
+
details: [
|
|
4023
|
+
"Refuses if any task Issue attached to the named tranche is still open, naming each one — closing a tranche with unresolved work is never silently allowed.",
|
|
4024
|
+
"Once every task Issue is closed, prompts for confirmation (unless `--yes`) and closes the GitHub Milestone."
|
|
4025
|
+
],
|
|
4026
|
+
status: "shipped"
|
|
4027
|
+
},
|
|
4028
|
+
{
|
|
4029
|
+
name: "audit",
|
|
4030
|
+
description: "Run the ring-2 dead-branch-push and direct-main-push detection checks directly",
|
|
4031
|
+
flags: [
|
|
4032
|
+
{ flag: "--only", description: "Scope to one check: 'dead-branches' or 'direct-push'" },
|
|
4033
|
+
{ flag: "--sha", description: "The commit to check for direct-main-push (defaults to the current HEAD)" },
|
|
4034
|
+
{ flag: "--json", description: "Enveloped JSON output" }
|
|
4035
|
+
],
|
|
4036
|
+
details: [
|
|
4037
|
+
"Dead-branch-push is never-red — a notification channel that flags (label + PR comment) any `task/*` branch whose tip commit lands after its own PR already resolved. Direct-main-push is a real pass/fail — it polls the merge-association API for up to ~100s before deciding, then opens an incident Issue and exits 1 if a commit on `main` genuinely has no associated merged PR.",
|
|
4038
|
+
"The same logic the generated `vinaya-archivist.yml` workflow's `daily-drift` and `direct-main-push-detection` jobs run on schedule / on every push to `main` — callable directly for a one-off run or local verification.",
|
|
4039
|
+
"All progress output writes through `process.stdout.write`/`process.stderr.write` (never bare `console.*`), so piping this command into a log file or a CI step captures every line in order."
|
|
4040
|
+
],
|
|
4041
|
+
status: "shipped"
|
|
4042
|
+
},
|
|
4043
|
+
{
|
|
4044
|
+
name: "eject",
|
|
4045
|
+
description: "Remove every Vinaya-installed artifact, restoring the repo to stock",
|
|
4046
|
+
flags: [
|
|
4047
|
+
{ flag: "--dry-run", description: "Print the full removal diff without removing anything" },
|
|
4048
|
+
{ flag: "--yes", description: "Skip the confirmation prompt" }
|
|
4049
|
+
],
|
|
4050
|
+
status: "shipped"
|
|
4051
|
+
},
|
|
4052
|
+
{
|
|
4053
|
+
name: "demo break",
|
|
4054
|
+
description: "Run a guided refusal-then-fix demo on an isolated, discardable branch",
|
|
4055
|
+
flags: [{ flag: "--keep", description: "Skip cleanup and leave the demo branch checked out to inspect" }],
|
|
4056
|
+
details: [
|
|
4057
|
+
"Creates a collision-safe `vinaya/demo-break-<id>` branch off the current one, stages a deliberately incomplete draft brief, and attempts a real `git commit` — the repo's actually-installed pre-commit hook refuses it with its real output, not a scripted string. Applies the minimal fix, commits again, then switches back and deletes the demo branch.",
|
|
4058
|
+
"Safe to run twice: refuses on a dirty working tree, refuses from a detached HEAD, and recovers automatically from a prior crashed run before starting a fresh one — never leaves the original branch touched or a stray demo branch behind."
|
|
4059
|
+
],
|
|
4060
|
+
status: "shipped"
|
|
4061
|
+
},
|
|
4062
|
+
{
|
|
4063
|
+
name: "waiver",
|
|
4064
|
+
description: "Apply the actor-verified 'vinaya/waiver:docs' or 'vinaya/waiver:review' label after prompting for a reason",
|
|
4065
|
+
flags: [
|
|
4066
|
+
{ flag: "--reason", description: "The waiver rationale, posted as a PR comment (prompted for if omitted)" },
|
|
4067
|
+
{ flag: "--print-only", description: "Print the exact `gh` commands instead of running them" }
|
|
4068
|
+
],
|
|
4069
|
+
details: [
|
|
4070
|
+
"Applies the label via `gh pr edit --add-label`, under the invoking human's own authenticated `gh` identity — this command never fabricates an actor. A waiver is never an agent-emittable string: not a PR body field, not a commit trailer, not a comment — the label plus its own labeling-timeline actor is the only mechanism ring 1 honors.",
|
|
4071
|
+
"`--print-only` prints the exact `gh pr edit`/`gh pr comment` commands and runs nothing — for a human who wants to run them itself, or a CI/non-interactive context where an agent session should never be the one applying its own waiver."
|
|
4072
|
+
],
|
|
4073
|
+
status: "shipped"
|
|
4074
|
+
},
|
|
4075
|
+
{
|
|
4076
|
+
name: "studio",
|
|
4077
|
+
description: "Launch Vinaya Studio — runs the Studio dev app when its source (apps/vinaya-studio/web) is in a checkout above the current directory; a published install launches its bundled standalone server instead",
|
|
4078
|
+
flags: [
|
|
4079
|
+
{
|
|
4080
|
+
flag: "--port <n>",
|
|
4081
|
+
description: "Bind this exact port. Without the flag the default is unchanged — 3008, falling back to 3108 when it is taken. With it there is no fallback: a taken port is refused, so you always know which server answered. Accepts `--port 3208` and `--port=3208`. Applies to a published install; in a workspace checkout Studio's own dev script owns the port and the flag is refused."
|
|
4082
|
+
}
|
|
4083
|
+
],
|
|
4084
|
+
details: [
|
|
4085
|
+
"Resolution happens in this order: a workspace checkout carrying `apps/vinaya-studio/web` (Studio's source, which lives in the attalabs monorepo — not this repository) runs the dev app directly; a published install's `studio-standalone/` bundle (fetched from attalabs' release artifact at publish time, see `scripts/bundle-studio.ts`) runs that bundled server; anything else — a publish that shipped without the bundle — gets an explicit refusal and exit 1 rather than a silent no-op.",
|
|
4086
|
+
"Every published `@attalabs/vinaya` build ships the `studio-standalone/` bundle: `prepack` fetches attalabs’ latest CI-built standalone Studio artifact and assembles it into the tarball before publish."
|
|
4087
|
+
],
|
|
4088
|
+
status: "shipped"
|
|
4089
|
+
},
|
|
4090
|
+
{
|
|
4091
|
+
name: "quickstart",
|
|
4092
|
+
description: "Guided wizard: init, doc-owners, project, commit, demo break, doctor, push — one command",
|
|
4093
|
+
details: [
|
|
4094
|
+
"Calls `init`'s own diff-and-confirm flow unchanged (pausing on Enter before the diff prints, so its own step header isn't scrolled off by a long diff), then Y/n-prompts through the workarounds a guest used to run by hand: binding `.vinaya/doc-owners` pairs (bad input offers a retry instead of silently skipping, and a pointer that doesn't exist on disk is refused outright — both loop across as many pairs as the guest wants, not just one), registering tracked projects (`init product`, same retry/loop shape), committing the install, running `demo break` as proof the gates actually work (default yes — the one step this wizard makes hardest to skip), running `doctor`, and pushing. Each declined prompt skips only that step; the install commit itself is never prompt-gated — it just no-ops when there is genuinely nothing to commit.",
|
|
4095
|
+
"Never reimplements or edits `init`/`init product`/`demo break`/`doctor` — it only calls their existing, unmodified entry points in sequence."
|
|
4096
|
+
],
|
|
4097
|
+
status: "shipped"
|
|
4098
|
+
},
|
|
4099
|
+
{
|
|
4100
|
+
name: "release",
|
|
4101
|
+
description: "Run this repo's own publish sequence in one command, refusing to start unless every precondition holds",
|
|
4102
|
+
flags: [
|
|
4103
|
+
{
|
|
4104
|
+
flag: "--dry-run",
|
|
4105
|
+
description: "Run the preconditions only and print the plan; publishes nothing"
|
|
4106
|
+
},
|
|
4107
|
+
{
|
|
4108
|
+
flag: "--allow-any-commit",
|
|
4109
|
+
description: "Skip the check that HEAD's commit is a Version Packages commit"
|
|
4110
|
+
}
|
|
4111
|
+
],
|
|
4112
|
+
details: [
|
|
4113
|
+
"Refuses unless HEAD is the default branch, the working tree is clean, HEAD equals `origin/<default>` (after `git fetch origin`), HEAD's commit subject starts with `Chore(release): Version packages` (unless `--allow-any-commit`), and `npm whoami` exits `0` — each its own refusal naming the fix.",
|
|
4114
|
+
"Then streams `bun install --frozen-lockfile`, `bun run build`, `bun run changeset:publish`, and `git push origin --tags` — a real push, so the repo's own generated pre-push hook sees it exactly as any other push would. After it, prints `npm view <pkg> version` for every tag now on HEAD, noting registry lag on `@attalabs/vinaya` (observed ~20 minutes) when it still shows the previous version.",
|
|
4115
|
+
'This is the one procedure named in `apps/cli/specs/self-hosting.md`, "How the published version is produced" — publishing itself stays manual and human-triggered; this command only removes the hand-typed four-step recipe.'
|
|
4116
|
+
],
|
|
4117
|
+
status: "shipped"
|
|
4118
|
+
},
|
|
4119
|
+
{
|
|
4120
|
+
name: "dispatch",
|
|
4121
|
+
description: "Start a role's headless agent session (claude/codex/gemini) with attribution set on its environment, recording the outcome through the Vinaya Log",
|
|
4122
|
+
flags: [
|
|
4123
|
+
{
|
|
4124
|
+
flag: "--agent",
|
|
4125
|
+
description: "Vendor to start: `claude`, `codex`, or `gemini` (falls back to `dispatch.agent` in config)"
|
|
4126
|
+
},
|
|
4127
|
+
{ flag: "--prompt-file", description: "Path to the prompt text sent to the agent (never on argv)" },
|
|
4128
|
+
{ flag: "--task", description: "This dispatch's task Issue number — mutually exclusive with `--pr`" },
|
|
4129
|
+
{
|
|
4130
|
+
flag: "--pr",
|
|
4131
|
+
description: "This dispatch's pull request number, for attribution — mutually exclusive with `--task`"
|
|
4132
|
+
},
|
|
4133
|
+
{ flag: "--round", description: "Round number, for a dispatch inside a review loop" },
|
|
4134
|
+
{
|
|
4135
|
+
flag: "--resume <id>",
|
|
4136
|
+
description: "Resume the vendor's own session/thread from a prior dispatch's returned `resumeId`, instead of starting a fresh one"
|
|
4137
|
+
},
|
|
4138
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
4139
|
+
],
|
|
4140
|
+
details: [
|
|
4141
|
+
"Sets `VINAYA_RUN_ID`/`VINAYA_ROLE`/`VINAYA_TASK`/`VINAYA_ROUND` on the child only — never on this process's own environment — and refuses by name, before any spawn attempt, when the named vendor binary is absent from `PATH` or present but not executable.",
|
|
4142
|
+
"Records `dispatched` (with the prompt's sha256), `outcome_received` (duration, the vendor's own usage when its stdout prints a recognizable shape), or `dispatch_failed` (`timeout`, `crash`, or `refused`) through the Vinaya Log's one `dispatch` family writer, `dispatchRole`. A wall-time ceiling (`dispatch.timeoutMs` in config, default one hour) sends `SIGTERM` then, after a grace window, `SIGKILL`.",
|
|
4143
|
+
"Runs no flush of its own after the dispatch returns: every log line `dispatchRole` emits reaches its configured `logs` destination live, as it is emitted, so there is nothing left to ship in a trailing step. `--task`/`--pr` are attribution only, and remain mutually exclusive.",
|
|
4144
|
+
"A successful dispatch's `DispatchHandle` carries `resumeId` — the vendor's own session/thread identifier (claude/gemini: `session_id`; codex: `thread_id`), parsed from its stdout, `null` on any failure. Passing that value as `--resume <id>` on a later call swaps in that vendor's own resume invocation (`claude -p -r <id> ...`; `codex exec resume <id> ...`; `gemini ... --resume <id> ...`) in place of its first-dispatch args."
|
|
4145
|
+
],
|
|
4146
|
+
status: "shipped"
|
|
4147
|
+
},
|
|
4148
|
+
{
|
|
4149
|
+
name: "dev-review-loop",
|
|
4150
|
+
description: "Dispatch the developer, run review rounds against the forge, resume the same developer session every round, and hold every verdict until the policy says publish",
|
|
4151
|
+
flags: [
|
|
4152
|
+
{ flag: "--task <n>", description: "This task's Issue number — its frozen `aeg:brief:v1` comment is the brief" },
|
|
4153
|
+
{
|
|
4154
|
+
flag: "--agent <claude|codex|gemini>",
|
|
4155
|
+
description: "Vendor for every dispatch this loop makes (falls back to `dispatch.agent` in config)"
|
|
4156
|
+
},
|
|
4157
|
+
{ flag: "--json", description: "Enveloped JSON output (schema: 1)" }
|
|
4158
|
+
],
|
|
4159
|
+
details: [
|
|
4160
|
+
"Dispatches the developer through `dispatchRole` with the brief read from the Issue, waits for the PR it opens, then runs `assessRound` (`@attalabs/aeg-core`) — the entire policy — against observations this command reads from the forge: the head via `git ls-remote` only (never `gh pr view headRefOid`, which can lag a push), CI conclusion via the check-runs API (never run locally), and ruling comments matching `<!-- aeg:principal:ruling:<pr>-<k> -->`.",
|
|
4161
|
+
"Nothing is posted to the PR before the policy decides `publish`: each round's reviewer and security verdicts are dispatched fresh (never a resumed session) through `dispatchRole`, rendered through `review post`'s own render functions, and written to a local file under the outbox — never `gh pr comment`/`gh pr review`. Posting the held verdicts is a separate, later task.",
|
|
4162
|
+
"The developer's session is resumed every round via `dispatchRole`'s `resumeId` — never a fresh session — for every vendor; a round whose resume fails for a vendor that resumed successfully the round before stops the loop rather than silently falling back to a fresh developer session.",
|
|
4163
|
+
"Every dispatch and round transition is a log line through the Vinaya Log, delivered live to its configured `logs` destination as it is emitted — never a tracker comment.",
|
|
4164
|
+
"issue-711 O4: this command — `--task <n>`, `--resume <pr>`, `--cancel <pr>` alike — stays `task run`'s own one-shot debug/direct entry; the watching driver that survives a pause and continues on its own is `task run`'s (see that command's own entry)."
|
|
4165
|
+
],
|
|
4166
|
+
status: "shipped"
|
|
4167
|
+
}
|
|
4168
|
+
];
|
|
4169
|
+
// ../../packages/sources/src/select-source.ts
|
|
4170
|
+
import { z as z5 } from "zod";
|
|
4171
|
+
var StateSourceConfigSchema = z5.discriminatedUnion("kind", [
|
|
4172
|
+
z5.object({ kind: z5.literal("forge"), owner: z5.string(), repo: z5.string() }),
|
|
4173
|
+
z5.object({ kind: z5.literal("file"), root: z5.string().optional() })
|
|
4174
|
+
]);
|
|
4175
|
+
// src/checks/edge-resolve.ts
|
|
4176
|
+
var issueCache = new Map;
|
|
4177
|
+
var siblingTrancheCache = new Map;
|
|
4178
|
+
|
|
4179
|
+
// src/lib/brief-assembly.ts
|
|
4180
|
+
var PACKAGE_ROOT = packageRoot(import.meta.url);
|
|
4181
|
+
var PACKAGED_TEMPLATE_PATH = join8(PACKAGE_ROOT, "aeg-root", "templates", "brief-template.md");
|
|
4182
|
+
var TEMPLATE_PATH = existsSync7(PACKAGED_TEMPLATE_PATH) ? PACKAGED_TEMPLATE_PATH : join8(PACKAGE_ROOT, "..", "..", "aeg-root", "templates", "brief-template.md");
|
|
4183
|
+
var DRAFT_ISSUE_SENTINEL = Number.MAX_SAFE_INTEGER;
|
|
4184
|
+
|
|
4185
|
+
// src/lib/forge-write.ts
|
|
4186
|
+
var INFORMATIONAL_DISPATCH_BLOCKER_CLASSES = new Set([
|
|
4187
|
+
"depends-on-not-merged",
|
|
4188
|
+
"conflicts-with"
|
|
4189
|
+
]);
|
|
4190
|
+
|
|
4191
|
+
// src/lib/dispatch.ts
|
|
4192
|
+
var MAX_TEE_BYTES = 8 * 1024 * 1024;
|
|
4193
|
+
var CLAUDE_MODEL_ALIASES = new Set(["fable", "opus", "sonnet", "haiku"]);
|
|
4194
|
+
var NO_SUBSCRIPTION_LOGIN_REASON = "this agent has no subscription login in Vinaya yet, and no agent authenticates with an API key — " + "dispatch a vendor whose subscription login Vinaya can stage (claude, codex)";
|
|
4195
|
+
|
|
4196
|
+
// src/commands/tokens.ts
|
|
4197
|
+
var USAGE = [
|
|
4198
|
+
'Usage: vinaya tokens --phase "<task-id>: develop" --role Developer',
|
|
4199
|
+
" [--model <id>] [--transcript <path>] [--in <tokens-in> --out <tokens-out>]",
|
|
4200
|
+
"",
|
|
4201
|
+
" --transcript Read this transcript directly. Supported primary route — use it whenever you know",
|
|
4202
|
+
" which transcript is yours, and always in a repo with no track-transcript.sh hook.",
|
|
4203
|
+
" (omitted) Resolve via the Stop-hook pointer file, if this repo installs that hook.",
|
|
4204
|
+
" --in/--out Manual entry: the exact token figures, for a host whose usage arrives by some other",
|
|
4205
|
+
" means than a Claude Code transcript. Both required together; skips transcript",
|
|
4206
|
+
" resolution entirely.",
|
|
4207
|
+
"",
|
|
4208
|
+
"Usage: vinaya tokens --trust-collect",
|
|
4209
|
+
" Approves this repo's declared tokens.collect command, pinned to the script's exact current",
|
|
4210
|
+
" content, on this machine. Run this once before tokens.collect will ever execute — a changed",
|
|
4211
|
+
" interpreter, script path, or script CONTENT needs its own fresh approval. Does not take",
|
|
4212
|
+
" --phase/--role and never emits a Tokens: line."
|
|
4213
|
+
].join(`
|
|
4214
|
+
`);
|
|
4215
|
+
|
|
4216
|
+
// src/lib/pr-report-engine.ts
|
|
4217
|
+
var execFileAsync6 = promisify6(execFile6);
|
|
4218
|
+
var BODY_READING_CHECK_NAMES = new Set(coreCheckRegistry().filter((spec) => {
|
|
4219
|
+
const decl = spec.env?.PR_BODY;
|
|
4220
|
+
return decl === true || typeof decl === "object" && decl !== null && "optional" in decl;
|
|
4221
|
+
}).map((spec) => spec.name));
|
|
4222
|
+
var FAILING_STATUSES = new Set(["fail", "error", "timeout"]);
|
|
4223
|
+
function readTestRunCacheFile(path) {
|
|
4224
|
+
try {
|
|
4225
|
+
if (!lstatSync3(path).isFile())
|
|
4226
|
+
return {};
|
|
4227
|
+
return JSON.parse(readFileSync7(path, "utf8"));
|
|
4228
|
+
} catch {
|
|
4229
|
+
return {};
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
function writeTestRunCacheFile(path, all) {
|
|
4233
|
+
const tmp = `${path}.tmp-${process.pid}-${randomUUID3()}`;
|
|
4234
|
+
const fd = openSync5(tmp, fsConstants5.O_WRONLY | fsConstants5.O_CREAT | fsConstants5.O_EXCL, 384);
|
|
4235
|
+
try {
|
|
4236
|
+
writeSync4(fd, JSON.stringify(all, null, 2), null, "utf8");
|
|
4237
|
+
fsyncSync2(fd);
|
|
4238
|
+
} finally {
|
|
4239
|
+
closeSync5(fd);
|
|
4240
|
+
}
|
|
4241
|
+
renameSync4(tmp, path);
|
|
4242
|
+
}
|
|
4243
|
+
function fileBackedTestRunCache(path, runtimeDir) {
|
|
4244
|
+
return {
|
|
4245
|
+
get: (key) => readTestRunCacheFile(path)[key],
|
|
4246
|
+
set: (key, record) => {
|
|
4247
|
+
const all = readTestRunCacheFile(path);
|
|
4248
|
+
all[key] = record;
|
|
4249
|
+
ensureRunDir(dirname7(path), runtimeDir);
|
|
4250
|
+
writeTestRunCacheFile(path, all);
|
|
4251
|
+
}
|
|
4252
|
+
};
|
|
4253
|
+
}
|
|
4254
|
+
function defaultTestRunCache() {
|
|
4255
|
+
const runtimeDir = runtimeDirForThisRepo();
|
|
4256
|
+
const path = runPath(runtimeDir, "unscoped", { area: "output", file: "test-run-cache.json" });
|
|
4257
|
+
return fileBackedTestRunCache(path, runtimeDir);
|
|
4258
|
+
}
|
|
4259
|
+
async function gitOrNull(args, cwd) {
|
|
4260
|
+
try {
|
|
4261
|
+
const { stdout } = await execFileAsync6("git", args, { encoding: "utf8", env: process.env, cwd });
|
|
4262
|
+
return stdout.trim();
|
|
4263
|
+
} catch {
|
|
4264
|
+
return null;
|
|
4265
|
+
}
|
|
4266
|
+
}
|
|
4267
|
+
var NUL = String.fromCharCode(0);
|
|
4268
|
+
function hashField(hash, value) {
|
|
4269
|
+
const buf = typeof value === "string" ? Buffer.from(value, "utf8") : value;
|
|
4270
|
+
const length = Buffer.alloc(4);
|
|
4271
|
+
length.writeUInt32BE(buf.length, 0);
|
|
4272
|
+
hash.update(length);
|
|
4273
|
+
hash.update(buf);
|
|
4274
|
+
}
|
|
4275
|
+
async function collectStateFields(cwd) {
|
|
4276
|
+
const head = await gitOrNull(["rev-parse", "HEAD"], cwd);
|
|
4277
|
+
if (!head)
|
|
4278
|
+
return null;
|
|
4279
|
+
const status = await gitOrNull(["status", "--porcelain=v1", "-uall", "--ignored", "-z"], cwd);
|
|
4280
|
+
if (status === null)
|
|
4281
|
+
return null;
|
|
4282
|
+
const diff = await gitOrNull(["diff", "HEAD"], cwd);
|
|
4283
|
+
if (diff === null)
|
|
4284
|
+
return null;
|
|
4285
|
+
const fields = [hostname(), head, status, diff];
|
|
4286
|
+
const uncommitted = status.split(NUL).filter((entry) => entry.startsWith("?? ") || entry.startsWith("!! ")).map((entry) => entry.slice(3)).sort();
|
|
4287
|
+
const base = cwd ?? process.cwd();
|
|
4288
|
+
for (const f of uncommitted) {
|
|
4289
|
+
fields.push(f);
|
|
4290
|
+
try {
|
|
4291
|
+
fields.push(readFileSync7(join9(base, f)));
|
|
4292
|
+
} catch {
|
|
4293
|
+
fields.push("MISSING");
|
|
4294
|
+
}
|
|
4295
|
+
}
|
|
4296
|
+
return fields;
|
|
4297
|
+
}
|
|
4298
|
+
function digestFields(fields) {
|
|
4299
|
+
const hash = createHash2("sha256");
|
|
4300
|
+
for (const f of fields)
|
|
4301
|
+
hashField(hash, f);
|
|
4302
|
+
return hash.digest("hex");
|
|
4303
|
+
}
|
|
4304
|
+
async function testRunCacheKey(command, cwd) {
|
|
4305
|
+
const fields = await collectStateFields(cwd);
|
|
4306
|
+
if (!fields)
|
|
4307
|
+
return null;
|
|
4308
|
+
return digestFields([...fields, command]);
|
|
4309
|
+
}
|
|
4310
|
+
async function testRunStateKey(cwd) {
|
|
4311
|
+
const fields = await collectStateFields(cwd);
|
|
4312
|
+
if (!fields)
|
|
4313
|
+
return null;
|
|
4314
|
+
return digestFields(fields);
|
|
4315
|
+
}
|
|
4316
|
+
var FILE_COVERAGE_PREFIX = "files:";
|
|
4317
|
+
function bunTestFileArgs(command) {
|
|
4318
|
+
const tokens = command.trim().split(/\s+/);
|
|
4319
|
+
let i = 0;
|
|
4320
|
+
if (tokens[i] === "bun")
|
|
4321
|
+
i++;
|
|
4322
|
+
if (tokens[i] !== "test")
|
|
4323
|
+
return null;
|
|
4324
|
+
i++;
|
|
4325
|
+
const files = [];
|
|
4326
|
+
for (;i < tokens.length; i++) {
|
|
4327
|
+
const t = tokens[i];
|
|
4328
|
+
if (t === "" || t === "--" || t.startsWith("-"))
|
|
4329
|
+
continue;
|
|
4330
|
+
files.push(t);
|
|
4331
|
+
}
|
|
4332
|
+
return files.length > 0 ? files : null;
|
|
4333
|
+
}
|
|
4334
|
+
function resolveFileSet(files, cwd) {
|
|
4335
|
+
const base = cwd ?? process.cwd();
|
|
4336
|
+
return [...new Set(files.map((f) => resolvePath2(base, f)))].sort();
|
|
4337
|
+
}
|
|
4338
|
+
function coverageRuns(record) {
|
|
4339
|
+
if (!record)
|
|
4340
|
+
return [];
|
|
4341
|
+
if (record.runs)
|
|
4342
|
+
return record.runs;
|
|
4343
|
+
return record.files ? [{ files: record.files, output: record.output, recordedAt: record.recordedAt, source: record.source }] : [];
|
|
4344
|
+
}
|
|
4345
|
+
function mergeFileCoverageRecord(existing, newRun) {
|
|
4346
|
+
return {
|
|
4347
|
+
output: newRun.output,
|
|
4348
|
+
exitCode: 0,
|
|
4349
|
+
timedOut: false,
|
|
4350
|
+
overflowed: false,
|
|
4351
|
+
recordedAt: newRun.recordedAt,
|
|
4352
|
+
source: newRun.source,
|
|
4353
|
+
files: newRun.files,
|
|
4354
|
+
runs: [...coverageRuns(existing), newRun]
|
|
4355
|
+
};
|
|
4356
|
+
}
|
|
4357
|
+
var AGENT_COMMAND_OUTPUT_MAX_CHARS = 600;
|
|
4358
|
+
function truncateAgentOutput(output) {
|
|
4359
|
+
if (output.length <= AGENT_COMMAND_OUTPUT_MAX_CHARS)
|
|
4360
|
+
return output;
|
|
4361
|
+
const cut = output.length - AGENT_COMMAND_OUTPUT_MAX_CHARS;
|
|
4362
|
+
return `[... ${cut} earlier characters truncated ...]
|
|
4363
|
+
${output.slice(-AGENT_COMMAND_OUTPUT_MAX_CHARS)}`;
|
|
4364
|
+
}
|
|
4365
|
+
var AGENT_COMMAND_MAX_BUFFER_BYTES = 32 * 1024 * 1024;
|
|
4366
|
+
async function recordGreenTestRun(command, output, cwd, source, cache = defaultTestRunCache()) {
|
|
4367
|
+
const key = await testRunCacheKey(command, cwd);
|
|
4368
|
+
if (!key)
|
|
4369
|
+
return false;
|
|
4370
|
+
const truncated = truncateAgentOutput(output);
|
|
4371
|
+
const recordedAt = new Date().toISOString();
|
|
4372
|
+
cache.set(key, { output: truncated, exitCode: 0, timedOut: false, overflowed: false, recordedAt, source });
|
|
4373
|
+
const files = bunTestFileArgs(command);
|
|
4374
|
+
if (files) {
|
|
4375
|
+
const stateKey = await testRunStateKey(cwd);
|
|
4376
|
+
if (stateKey) {
|
|
4377
|
+
const coverageKey = `${FILE_COVERAGE_PREFIX}${stateKey}`;
|
|
4378
|
+
const merged = mergeFileCoverageRecord(cache.get(coverageKey), {
|
|
4379
|
+
files: resolveFileSet(files, cwd),
|
|
4380
|
+
output: truncated,
|
|
4381
|
+
recordedAt,
|
|
4382
|
+
source
|
|
4383
|
+
});
|
|
4384
|
+
cache.set(coverageKey, merged);
|
|
4385
|
+
}
|
|
4386
|
+
}
|
|
4387
|
+
return true;
|
|
4388
|
+
}
|
|
4389
|
+
var TOKEN_ROW_REMEDY = [
|
|
4390
|
+
"Nothing here established that this host cannot meter — only that this session resolved no",
|
|
4391
|
+
"transcript of its own. Report real figures by naming your own transcript:",
|
|
4392
|
+
"",
|
|
4393
|
+
" vinaya pr report --write <body-file> --transcript <path>",
|
|
4394
|
+
"",
|
|
4395
|
+
"or, on a host whose usage arrives by some other means, format figures you already hold with:",
|
|
4396
|
+
"",
|
|
4397
|
+
' vinaya tokens --phase "<task-id>: develop" --role Developer --in <tokens-in> --out <tokens-out>',
|
|
4398
|
+
"",
|
|
4399
|
+
"and transcribe them into the `## Token report` table. That command prints a `Tokens:` line, not",
|
|
4400
|
+
"a table row — the table takes | Phase | Role | Agent/Model | Tokens in | Tokens out | Cost | Date |,",
|
|
4401
|
+
"and a line inside the block that does not start with `|` truncates the table for every row after it."
|
|
4402
|
+
].join(`
|
|
4403
|
+
`);
|
|
4404
|
+
|
|
4405
|
+
// src/lib/pre-push-cache-test-run.ts
|
|
4406
|
+
async function main() {
|
|
4407
|
+
const command = process.argv[2];
|
|
4408
|
+
const logPath = process.argv[3];
|
|
4409
|
+
if (!command || !logPath) {
|
|
4410
|
+
process.stderr.write(`vinaya pre-push: cache-test-run given no command/log path — nothing recorded.
|
|
4411
|
+
`);
|
|
4412
|
+
return;
|
|
4413
|
+
}
|
|
4414
|
+
let output;
|
|
4415
|
+
try {
|
|
4416
|
+
output = readFileSync8(logPath, "utf8");
|
|
4417
|
+
} catch (err) {
|
|
4418
|
+
process.stderr.write(`vinaya pre-push: could not read ${logPath} to cache this run — nothing recorded (${err instanceof Error ? err.message : String(err)}).
|
|
4419
|
+
`);
|
|
4420
|
+
return;
|
|
4421
|
+
}
|
|
4422
|
+
try {
|
|
4423
|
+
const recorded = await recordGreenTestRun(command, output, process.cwd(), "pre-push");
|
|
4424
|
+
process.stderr.write(recorded ? "vinaya pre-push: this run is cached for reuse by a later `pr report`.\n" : `vinaya pre-push: working tree/head could not be resolved — this run was not cached.
|
|
4425
|
+
`);
|
|
4426
|
+
} catch (err) {
|
|
4427
|
+
process.stderr.write(`vinaya pre-push: failed to cache this run — nothing recorded (${err instanceof Error ? err.message : String(err)}).
|
|
4428
|
+
`);
|
|
4429
|
+
}
|
|
4430
|
+
}
|
|
4431
|
+
main();
|