@attalabs/vinaya 0.39.0 → 0.41.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 +9 -9
- package/aeg-root/contracts/developer-reviewer.md +2 -2
- package/aeg-root/contracts/planner-developer.md +5 -5
- package/aeg-root/enforcement.md +22 -22
- package/aeg-root/process.md +4 -4
- package/aeg-root/roles/archivist.md +1 -1
- package/aeg-root/roles/developer/reference.md +7 -1
- package/aeg-root/roles/developer.md +1 -1
- package/aeg-root/roles/planner/reference.md +18 -5
- package/aeg-root/roles/principal.md +1 -1
- package/aeg-root/roles/reviewer.md +3 -3
- package/aeg-root/roles/security.md +4 -4
- package/aeg-root/roles/tranche-archivist.md +2 -2
- package/aeg-root/skills/aeg/SKILL.md +1 -1
- package/aeg-root/state-machine.md +10 -15
- package/aeg-root/templates/brief-template.md +5 -2
- package/aeg-root/templates/decision-record-template.md +38 -0
- package/aeg-root/templates/issue-rationale-template.md +1 -1
- package/aeg-root/tranche-model.md +1 -1
- package/dist/checks/bin/check-body-bare-digits.js +1974 -354
- package/dist/checks/bin/check-branch-topology.js +1296 -243
- package/dist/checks/bin/check-brief-shape.js +2038 -460
- package/dist/checks/bin/check-changeset-coverage.js +2411 -564
- package/dist/checks/bin/check-ci-shard-coverage.js +12391 -15
- package/dist/checks/bin/check-closes-n.js +1296 -243
- package/dist/checks/bin/check-coherence.js +1914 -1155
- package/dist/checks/bin/check-dead-branch-push.js +1242 -230
- package/dist/checks/bin/check-dispatch-readiness.js +2222 -460
- package/dist/checks/bin/check-doc-claims.js +2233 -260
- package/dist/checks/bin/check-doc-coverage-push.js +2436 -550
- package/dist/checks/bin/check-doc-coverage.js +2434 -552
- package/dist/checks/bin/check-doctrine-no-procedures.js +1776 -353
- package/dist/checks/bin/check-doctrine-portability.js +2408 -561
- package/dist/checks/bin/check-evidence-fresh.js +2370 -508
- package/dist/checks/bin/check-exec-bits.js +2407 -560
- package/dist/checks/bin/check-first-push-dispatch.js +1984 -380
- package/dist/checks/bin/check-issue-assignment.js +712 -170
- package/dist/checks/bin/check-issue-milestone-attach.js +1233 -230
- package/dist/checks/bin/check-issue-objectives-numbering.js +1769 -346
- package/dist/checks/bin/check-issue-parts-coverage.js +1233 -230
- package/dist/checks/bin/check-issue-surface-globs.js +1926 -378
- package/dist/checks/bin/check-issue-title-grammar.js +1233 -230
- package/dist/checks/bin/check-issue-tranche-label.js +702 -170
- package/dist/checks/bin/check-main-branch-refusal.js +1245 -232
- package/dist/checks/bin/check-no-disk-state.js +1233 -230
- package/dist/checks/bin/check-pr-premise-reassert.js +1769 -346
- package/dist/checks/bin/check-pr-report-density.js +1233 -230
- package/dist/checks/bin/check-principal-test-plan-wait.js +2489 -259
- package/dist/checks/bin/check-quoted-command.js +2391 -544
- package/dist/checks/bin/check-reader-resolvable-prose.js +2437 -564
- package/dist/checks/bin/check-registry-gates.js +1380 -296
- package/dist/checks/bin/check-retired-vocabulary.js +2416 -550
- package/dist/checks/bin/check-review-gate.js +2073 -371
- package/dist/checks/bin/check-single-plan-pr.js +1297 -235
- package/dist/checks/bin/check-surface-scope.js +1531 -252
- package/dist/checks/bin/check-test-plan.js +2487 -258
- package/dist/checks/bin/check-token-collection-wired.js +1233 -230
- package/dist/checks/bin/check-workspace-escape.js +2408 -561
- package/dist/checks/bin/verify-coherence.js +597 -97
- package/dist/checks/bin/verify-dispatch.js +632 -152
- package/dist/checks/bin/verify-docs.js +642 -132
- package/dist/index.js +25948 -16630
- package/dist/lib/pre-push-cache-test-run.js +1813 -297
- package/dist/lib/pre-push-changed-files.js +65 -19
- package/dist/lib/pre-push-mode.js +466 -0
- package/dist/lib/pre-push-progress-dir.js +4205 -0
- package/dist/lib/pre-push-record-tests.js +446 -0
- package/dist/lib/pre-push-select-tests.js +2353 -632
- package/dist/lib/push-progress-observer.js +4213 -0
- package/package.json +22 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +17 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +73 -30
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +3 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +2 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +88 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +34 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +26 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +7 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +7 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +29 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +35 -18
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +70 -45
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/entry-point.ts +27 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +3 -5
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +96 -9
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +24 -54
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +809 -106
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/live-record.ts +179 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +8 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +1 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/narration.ts +2 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema-digest.ts +225 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +7 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +23 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +6 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/principals-config.ts +44 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/prose-rules.ts +532 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/protected-paths.ts +31 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +157 -80
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +8 -12
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/retired-vocabulary.ts +53 -93
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +46 -17
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +85 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +32 -13
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +46 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +2 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +63 -8
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +24 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +0 -1
- 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/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 +1 -1
- 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 +2 -2
- 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/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]__08e39jo._.js +1 -1
- 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]__0sxadt2._.js +13 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1a3j3n1._.js +57 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1ug9syi._.js → [root-of-the-server]__1d4eth3._.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]__1snpgaw._.js +3 -3
- 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/_08onyya._.js +2 -2
- 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/_0zf4d27._.js +3 -3
- 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/_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/{33rszkngkuoko.js → 0x7u6si-ai179.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{06_55xbp7rcbi.js → 2fu7mfsj4oima.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{2brkwv169ygep.js → 34b4ruddunn3q.js} +1 -1
- 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]__04adkz-._.js +0 -57
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__19jyp3m._.js +0 -13
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_buildManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_clientMiddlewareManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,4205 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/lib/push-progress.ts
|
|
4
|
+
import {
|
|
5
|
+
closeSync as closeSync4,
|
|
6
|
+
constants as fsConstants3,
|
|
7
|
+
existsSync as existsSync6,
|
|
8
|
+
fstatSync as fstatSync2,
|
|
9
|
+
lstatSync as lstatSync3,
|
|
10
|
+
mkdirSync as mkdirSync5,
|
|
11
|
+
openSync as openSync4,
|
|
12
|
+
readdirSync as readdirSync3,
|
|
13
|
+
readFileSync as readFileSync6,
|
|
14
|
+
readSync,
|
|
15
|
+
realpathSync as realpathSync3,
|
|
16
|
+
rmSync as rmSync3,
|
|
17
|
+
statSync as statSync2,
|
|
18
|
+
writeFileSync as writeFileSync3,
|
|
19
|
+
writeSync as writeSync3
|
|
20
|
+
} from "node:fs";
|
|
21
|
+
import { dirname as dirname6, join as join6 } from "node:path";
|
|
22
|
+
|
|
23
|
+
// src/lib/package-root.ts
|
|
24
|
+
import { existsSync } from "node:fs";
|
|
25
|
+
import { dirname, join } from "node:path";
|
|
26
|
+
import { fileURLToPath } from "node:url";
|
|
27
|
+
function packageRoot(moduleUrl) {
|
|
28
|
+
let dir = dirname(fileURLToPath(moduleUrl));
|
|
29
|
+
while (!existsSync(join(dir, "package.json"))) {
|
|
30
|
+
if (existsSync(join(dir, ".git")))
|
|
31
|
+
break;
|
|
32
|
+
const parent = dirname(dir);
|
|
33
|
+
if (parent === dir)
|
|
34
|
+
break;
|
|
35
|
+
dir = parent;
|
|
36
|
+
}
|
|
37
|
+
return dir;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/lib/pre-push-failed-tests.ts
|
|
41
|
+
import { execFileSync } from "node:child_process";
|
|
42
|
+
import { createHash } from "node:crypto";
|
|
43
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
44
|
+
import { dirname as dirname2, isAbsolute, join as join2 } from "node:path";
|
|
45
|
+
var FAILED_TESTS_RECORD = "vinaya/pre-push-failed-tests.json";
|
|
46
|
+
var LAST_PUSH_RESULT = "vinaya/pre-push-last-result.json";
|
|
47
|
+
var SELECTION_NOTE = "vinaya/pre-push-selection.json";
|
|
48
|
+
var TEST_SELECTION_COMPLETE = "vinaya-test-selection-complete ";
|
|
49
|
+
function completedTestSelection(log, cwd, expected) {
|
|
50
|
+
const completed = new Set;
|
|
51
|
+
let batch = [];
|
|
52
|
+
let markers = 0;
|
|
53
|
+
const absolute = (path) => isAbsolute(path) ? path : join2(cwd, path);
|
|
54
|
+
for (const line of log.split(`
|
|
55
|
+
`)) {
|
|
56
|
+
if (!line.startsWith(TEST_SELECTION_COMPLETE)) {
|
|
57
|
+
batch.push(line);
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const result = JSON.parse(line.slice(TEST_SELECTION_COMPLETE.length));
|
|
62
|
+
if (![0, 1].includes(result.exitCode) || !Array.isArray(result.files) || !result.files.every((file) => typeof file === "string"))
|
|
63
|
+
return false;
|
|
64
|
+
const text = batch.join(`
|
|
65
|
+
`);
|
|
66
|
+
const summary = [...text.matchAll(/^Ran \d+ tests? across (\d+) files?\.(?:.*)$/gm)].at(-1);
|
|
67
|
+
const headers = new Set([...text.matchAll(/^(\S.*\.test\.[a-zA-Z]+):$/gm)].map((match) => absolute(match[1])));
|
|
68
|
+
const files = new Set(result.files.map(absolute));
|
|
69
|
+
if (!summary || Number(summary[1]) !== files.size || headers.size !== files.size || [...files].some((file) => !headers.has(file)))
|
|
70
|
+
return false;
|
|
71
|
+
for (const file of files)
|
|
72
|
+
completed.add(file);
|
|
73
|
+
markers++;
|
|
74
|
+
batch = [];
|
|
75
|
+
} catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (markers === 0 || batch.join(`
|
|
80
|
+
`).trim() !== "")
|
|
81
|
+
return false;
|
|
82
|
+
return expected === undefined || new Set(expected.map(absolute)).size === completed.size && expected.every((file) => completed.has(absolute(file)));
|
|
83
|
+
}
|
|
84
|
+
function parseFailedTestFiles(log, cwd, exitedNonZero, selected) {
|
|
85
|
+
if (exitedNonZero && !completedTestSelection(log, cwd, selected))
|
|
86
|
+
return "all";
|
|
87
|
+
const failed = new Set;
|
|
88
|
+
let current = null;
|
|
89
|
+
for (const raw of log.split(`
|
|
90
|
+
`)) {
|
|
91
|
+
const line = raw.trimEnd();
|
|
92
|
+
if (/^\d+ tests? failed:/.test(line)) {
|
|
93
|
+
current = null;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const header = /^(\S.*\.test\.[a-zA-Z]+):$/.exec(line);
|
|
97
|
+
if (header?.[1]) {
|
|
98
|
+
current = isAbsolute(header[1]) ? header[1] : join2(cwd, header[1]);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (current && (/^\(fail\) /.test(line) || line.startsWith("# Unhandled error")))
|
|
102
|
+
failed.add(current);
|
|
103
|
+
}
|
|
104
|
+
if (failed.size === 0)
|
|
105
|
+
return exitedNonZero ? "all" : [];
|
|
106
|
+
return [...failed].sort();
|
|
107
|
+
}
|
|
108
|
+
function chooseTests(inputs) {
|
|
109
|
+
const { record, head, branch, fullSelection } = inputs;
|
|
110
|
+
const full = {
|
|
111
|
+
version: 1,
|
|
112
|
+
mode: "full",
|
|
113
|
+
head,
|
|
114
|
+
fullCount: fullSelection.length,
|
|
115
|
+
selected: fullSelection
|
|
116
|
+
};
|
|
117
|
+
if (!record || record.failed === "all" || record.selectionCompleted !== true)
|
|
118
|
+
return full;
|
|
119
|
+
if (record.branch !== branch || !inputs.recordIsAncestor)
|
|
120
|
+
return full;
|
|
121
|
+
if (!record.failed.every(inputs.exists))
|
|
122
|
+
return full;
|
|
123
|
+
const rerunFailed = [...record.failed];
|
|
124
|
+
const affectedSince = inputs.affectedSince.filter(inputs.exists).sort();
|
|
125
|
+
const selected = [...new Set([...rerunFailed, ...affectedSince])].sort();
|
|
126
|
+
if (selected.length === 0)
|
|
127
|
+
return full;
|
|
128
|
+
return {
|
|
129
|
+
version: 1,
|
|
130
|
+
mode: "rerun",
|
|
131
|
+
head,
|
|
132
|
+
rerunOf: record.head,
|
|
133
|
+
recordedHead: record.head,
|
|
134
|
+
rerunFailed,
|
|
135
|
+
affectedSince,
|
|
136
|
+
fullCount: fullSelection.length,
|
|
137
|
+
selected
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function recordFromRun(outcome, failed, head, branch, now) {
|
|
141
|
+
if (outcome === "passed")
|
|
142
|
+
return null;
|
|
143
|
+
return { version: 1, head, branch, failed, recordedAt: now.toISOString(), selectionCompleted: failed !== "all" };
|
|
144
|
+
}
|
|
145
|
+
function parseRecord(text) {
|
|
146
|
+
if (!text)
|
|
147
|
+
return null;
|
|
148
|
+
try {
|
|
149
|
+
const value = JSON.parse(text);
|
|
150
|
+
if (value.version !== 1 || typeof value.head !== "string" || typeof value.branch !== "string")
|
|
151
|
+
return null;
|
|
152
|
+
if (value.failed !== "all" && !Array.isArray(value.failed))
|
|
153
|
+
return null;
|
|
154
|
+
return value;
|
|
155
|
+
} catch {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
var PASSING_RECORD_VERSION = 2;
|
|
160
|
+
var SELECTION_POLICY = {
|
|
161
|
+
name: "pre-push-since-green",
|
|
162
|
+
version: 1,
|
|
163
|
+
depth: "one",
|
|
164
|
+
testTimeoutMs: 30000,
|
|
165
|
+
rootConfigFile: "vinaya.config.json"
|
|
166
|
+
};
|
|
167
|
+
var VERIFICATION_LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
|
|
168
|
+
var VERIFICATION_INPUT_FILES = ["vinaya.config.json", "package.json", "bunfig.toml", ...VERIFICATION_LOCKFILES];
|
|
169
|
+
var VERIFICATION_ENV_KEYS = ["BUN_ENV", "CI", "NODE_ENV", "NODE_OPTIONS", "TZ"];
|
|
170
|
+
function parsePassingRecord(text) {
|
|
171
|
+
if (!text)
|
|
172
|
+
return null;
|
|
173
|
+
try {
|
|
174
|
+
const value = JSON.parse(text);
|
|
175
|
+
if (value.version !== PASSING_RECORD_VERSION || value.kind !== "passed")
|
|
176
|
+
return null;
|
|
177
|
+
if (typeof value.head !== "string" || typeof value.branch !== "string" || typeof value.context !== "string")
|
|
178
|
+
return null;
|
|
179
|
+
if (!Array.isArray(value.selection) || !value.selection.every((file) => typeof file === "string"))
|
|
180
|
+
return null;
|
|
181
|
+
return value;
|
|
182
|
+
} catch {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
function parseSelectionNote(text, head) {
|
|
187
|
+
if (!text)
|
|
188
|
+
return null;
|
|
189
|
+
try {
|
|
190
|
+
const value = JSON.parse(text);
|
|
191
|
+
if (value.head !== head || !Array.isArray(value.selected))
|
|
192
|
+
return null;
|
|
193
|
+
if (!value.selected.every((file) => typeof file === "string"))
|
|
194
|
+
return null;
|
|
195
|
+
return { mode: "full", ...value };
|
|
196
|
+
} catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function passingRecordFromRun(inputs) {
|
|
201
|
+
const { selection, head, branch } = inputs;
|
|
202
|
+
if (inputs.outcome !== "passed" || !selection || selection.head !== head)
|
|
203
|
+
return null;
|
|
204
|
+
if (selection.selected.length === 0 || !head || !branch || branch === "HEAD")
|
|
205
|
+
return null;
|
|
206
|
+
if (!selection.context || inputs.context !== selection.context || inputs.inputsClean !== true)
|
|
207
|
+
return null;
|
|
208
|
+
if (!completedTestSelection(inputs.log, inputs.repoRoot, selection.selected))
|
|
209
|
+
return null;
|
|
210
|
+
return {
|
|
211
|
+
version: PASSING_RECORD_VERSION,
|
|
212
|
+
kind: "passed",
|
|
213
|
+
head,
|
|
214
|
+
branch,
|
|
215
|
+
selection: [...selection.selected],
|
|
216
|
+
selectionCompleted: true,
|
|
217
|
+
context: selection.context,
|
|
218
|
+
recordedAt: inputs.now.toISOString()
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
function decideSelection(deps) {
|
|
222
|
+
const context = deps.context !== null && deps.inputsClean === true ? deps.context : null;
|
|
223
|
+
const withContext = (note) => context === null ? note : { ...note, context };
|
|
224
|
+
const sinceGreen = deps.failed === null ? sinceGreenNote(deps, context) : null;
|
|
225
|
+
if (sinceGreen)
|
|
226
|
+
return { note: withContext(sinceGreen), full: null };
|
|
227
|
+
const full = deps.full();
|
|
228
|
+
const record = deps.failed;
|
|
229
|
+
const recordIsAncestor = record ? deps.isAncestor(record.head) : false;
|
|
230
|
+
let usable = record;
|
|
231
|
+
let affectedSince = [];
|
|
232
|
+
if (record && record.failed !== "all" && recordIsAncestor && record.branch === deps.branch) {
|
|
233
|
+
const changed = deps.changedBetween(record.head);
|
|
234
|
+
if (changed === null)
|
|
235
|
+
usable = null;
|
|
236
|
+
else
|
|
237
|
+
affectedSince = deps.affectedSince(changed);
|
|
238
|
+
}
|
|
239
|
+
const note = chooseTests({
|
|
240
|
+
record: usable,
|
|
241
|
+
head: deps.head,
|
|
242
|
+
branch: deps.branch,
|
|
243
|
+
recordIsAncestor,
|
|
244
|
+
fullSelection: full.selected,
|
|
245
|
+
affectedSince,
|
|
246
|
+
exists: deps.exists
|
|
247
|
+
});
|
|
248
|
+
return { note: withContext(note), full };
|
|
249
|
+
}
|
|
250
|
+
function sinceGreenNote(deps, context) {
|
|
251
|
+
const passing = deps.passing;
|
|
252
|
+
if (!passing || passing.selectionCompleted !== true || passing.selection.length === 0)
|
|
253
|
+
return null;
|
|
254
|
+
if (passing.branch !== deps.branch || context === null || passing.context !== context)
|
|
255
|
+
return null;
|
|
256
|
+
if (!deps.isAncestor(passing.head))
|
|
257
|
+
return null;
|
|
258
|
+
const changed = deps.changedBetween(passing.head);
|
|
259
|
+
if (changed === null || changed.includes(join2(deps.repoRoot, SELECTION_POLICY.rootConfigFile)))
|
|
260
|
+
return null;
|
|
261
|
+
const read = deps.sinceGreen(passing.head);
|
|
262
|
+
if (read.readFailed)
|
|
263
|
+
return null;
|
|
264
|
+
const selected = [...new Set(read.selected)].filter(deps.exists).sort();
|
|
265
|
+
const affectedSince = selected.filter((file) => !deps.isAlwaysRun(file) || changed.includes(file));
|
|
266
|
+
if (changed.length > 0 && affectedSince.length === 0)
|
|
267
|
+
return null;
|
|
268
|
+
return {
|
|
269
|
+
version: 1,
|
|
270
|
+
mode: "since-green",
|
|
271
|
+
head: deps.head,
|
|
272
|
+
recordedHead: passing.head,
|
|
273
|
+
affectedSince,
|
|
274
|
+
fullCount: null,
|
|
275
|
+
selected
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function cleanGitEnv() {
|
|
279
|
+
const env = { ...process.env };
|
|
280
|
+
for (const key of Object.keys(env))
|
|
281
|
+
if (key.startsWith("GIT_"))
|
|
282
|
+
delete env[key];
|
|
283
|
+
return env;
|
|
284
|
+
}
|
|
285
|
+
function git(repoRoot, args) {
|
|
286
|
+
try {
|
|
287
|
+
return execFileSync("git", args, {
|
|
288
|
+
cwd: repoRoot,
|
|
289
|
+
encoding: "utf8",
|
|
290
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
291
|
+
env: cleanGitEnv()
|
|
292
|
+
}).trim();
|
|
293
|
+
} catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function gitPath(repoRoot, name) {
|
|
298
|
+
const out = git(repoRoot, ["rev-parse", "--git-path", name]);
|
|
299
|
+
if (!out)
|
|
300
|
+
return null;
|
|
301
|
+
return isAbsolute(out) ? out : join2(repoRoot, out);
|
|
302
|
+
}
|
|
303
|
+
function currentHead(repoRoot) {
|
|
304
|
+
return git(repoRoot, ["rev-parse", "HEAD"]) ?? "";
|
|
305
|
+
}
|
|
306
|
+
function currentBranch(repoRoot) {
|
|
307
|
+
return git(repoRoot, ["rev-parse", "--abbrev-ref", "HEAD"]) ?? "";
|
|
308
|
+
}
|
|
309
|
+
function isAncestor(repoRoot, ancestor, head) {
|
|
310
|
+
try {
|
|
311
|
+
execFileSync("git", ["merge-base", "--is-ancestor", ancestor, head], {
|
|
312
|
+
cwd: repoRoot,
|
|
313
|
+
stdio: "ignore",
|
|
314
|
+
env: cleanGitEnv()
|
|
315
|
+
});
|
|
316
|
+
return true;
|
|
317
|
+
} catch {
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function changedBetween(repoRoot, from, to) {
|
|
322
|
+
const read = git(repoRoot, ["diff", "--name-only", "--diff-filter=ACMRD", from, to]);
|
|
323
|
+
if (read === null)
|
|
324
|
+
return null;
|
|
325
|
+
return read.split(`
|
|
326
|
+
`).map((s) => s.trim()).filter(Boolean).map((f) => join2(repoRoot, f));
|
|
327
|
+
}
|
|
328
|
+
function readJsonUnderGit(repoRoot, name) {
|
|
329
|
+
const path = gitPath(repoRoot, name);
|
|
330
|
+
if (!path || !existsSync2(path))
|
|
331
|
+
return null;
|
|
332
|
+
try {
|
|
333
|
+
return readFileSync(path, "utf8");
|
|
334
|
+
} catch {
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function writeJsonUnderGit(repoRoot, name, value) {
|
|
339
|
+
const path = gitPath(repoRoot, name);
|
|
340
|
+
if (!path)
|
|
341
|
+
return;
|
|
342
|
+
mkdirSync(dirname2(path), { recursive: true });
|
|
343
|
+
writeFileSync(path, `${JSON.stringify(value, null, 2)}
|
|
344
|
+
`);
|
|
345
|
+
}
|
|
346
|
+
function removeUnderGit(repoRoot, name) {
|
|
347
|
+
const path = gitPath(repoRoot, name);
|
|
348
|
+
if (path)
|
|
349
|
+
rmSync(path, { force: true });
|
|
350
|
+
}
|
|
351
|
+
function readFailedTestsRecord(repoRoot) {
|
|
352
|
+
return parseRecord(readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD));
|
|
353
|
+
}
|
|
354
|
+
function readPassingRecord(repoRoot) {
|
|
355
|
+
return parsePassingRecord(readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD));
|
|
356
|
+
}
|
|
357
|
+
function clearRecordOfKind(repoRoot, kind) {
|
|
358
|
+
const text = readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD);
|
|
359
|
+
const other = kind === "failed" ? parsePassingRecord(text) : parseRecord(text);
|
|
360
|
+
if (text !== null && other !== null)
|
|
361
|
+
return;
|
|
362
|
+
removeUnderGit(repoRoot, FAILED_TESTS_RECORD);
|
|
363
|
+
}
|
|
364
|
+
function computeVerificationContext(repoRoot, env = process.env) {
|
|
365
|
+
try {
|
|
366
|
+
const sha = (data) => createHash("sha256").update(data).digest("hex");
|
|
367
|
+
const read = (name) => {
|
|
368
|
+
const path = join2(repoRoot, name);
|
|
369
|
+
return existsSync2(path) ? readFileSync(path) : null;
|
|
370
|
+
};
|
|
371
|
+
const json = (name) => {
|
|
372
|
+
const bytes = read(name);
|
|
373
|
+
return bytes === null ? null : JSON.parse(bytes.toString("utf8"));
|
|
374
|
+
};
|
|
375
|
+
const config = json("vinaya.config.json");
|
|
376
|
+
const pkg = json("package.json");
|
|
377
|
+
const scripts = pkg?.scripts;
|
|
378
|
+
const bunfig = read("bunfig.toml");
|
|
379
|
+
const parts = {
|
|
380
|
+
policy: sha(JSON.stringify(SELECTION_POLICY)),
|
|
381
|
+
inputs: sha(JSON.stringify({ prePush: config?.prePush ?? null, workspaces: pkg?.workspaces ?? null })),
|
|
382
|
+
lockfile: sha(VERIFICATION_LOCKFILES.map((name) => {
|
|
383
|
+
const bytes = read(name);
|
|
384
|
+
return `${name}:${bytes === null ? "absent" : sha(bytes)}`;
|
|
385
|
+
}).join(`
|
|
386
|
+
`)),
|
|
387
|
+
runner: sha(JSON.stringify({
|
|
388
|
+
bunfig: bunfig === null ? null : sha(bunfig),
|
|
389
|
+
testScript: scripts?.test ?? null,
|
|
390
|
+
bun: process.versions.bun ?? null
|
|
391
|
+
})),
|
|
392
|
+
environment: sha(VERIFICATION_ENV_KEYS.map((key) => `${key}=${env[key] ?? "\x00unset"}`).join(`
|
|
393
|
+
`))
|
|
394
|
+
};
|
|
395
|
+
return { digest: sha(JSON.stringify(parts)), parts };
|
|
396
|
+
} catch {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function verificationInputsDirty(repoRoot) {
|
|
401
|
+
const out = git(repoRoot, ["status", "--porcelain", "--", ...VERIFICATION_INPUT_FILES]);
|
|
402
|
+
return out === null ? null : out !== "";
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// src/lib/process-registry.ts
|
|
406
|
+
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
407
|
+
import {
|
|
408
|
+
closeSync,
|
|
409
|
+
fsyncSync,
|
|
410
|
+
mkdirSync as mkdirSync2,
|
|
411
|
+
openSync,
|
|
412
|
+
readdirSync,
|
|
413
|
+
readFileSync as readFileSync2,
|
|
414
|
+
renameSync,
|
|
415
|
+
rmSync as rmSync2,
|
|
416
|
+
writeSync
|
|
417
|
+
} from "node:fs";
|
|
418
|
+
function linuxStartTime(pid) {
|
|
419
|
+
try {
|
|
420
|
+
const stat = readFileSync2(`/proc/${pid}/stat`, "utf8");
|
|
421
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
422
|
+
return fields[19] ?? null;
|
|
423
|
+
} catch {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function psStartTime(pid) {
|
|
428
|
+
try {
|
|
429
|
+
const out = execFileSync2("ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
430
|
+
encoding: "utf8",
|
|
431
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
432
|
+
}).trim();
|
|
433
|
+
return out === "" ? null : out;
|
|
434
|
+
} catch {
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function identityOf(pid) {
|
|
439
|
+
if (!Number.isInteger(pid) || pid <= 0)
|
|
440
|
+
return null;
|
|
441
|
+
const startTime = process.platform === "linux" ? linuxStartTime(pid) : psStartTime(pid);
|
|
442
|
+
return startTime === null ? null : { pid, startTime };
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// src/lib/run-paths.ts
|
|
446
|
+
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
447
|
+
import { chmodSync, existsSync as existsSync5, realpathSync as realpathSync2 } from "node:fs";
|
|
448
|
+
import { dirname as dirname5, join as join5, resolve as resolvePath } from "node:path";
|
|
449
|
+
// ../../packages/aeg-forge-state/src/gh.ts
|
|
450
|
+
import { execFile, execFileSync as execFileSync3 } from "node:child_process";
|
|
451
|
+
import { promisify } from "node:util";
|
|
452
|
+
var execFileAsync = promisify(execFile);
|
|
453
|
+
var systemEnv = {
|
|
454
|
+
...process.env,
|
|
455
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
// ../../packages/aeg-forge-state/src/labels.ts
|
|
459
|
+
var LABELS = [
|
|
460
|
+
{
|
|
461
|
+
key: "blocked",
|
|
462
|
+
id: "vinaya/blocked",
|
|
463
|
+
category: "state",
|
|
464
|
+
form: "literal",
|
|
465
|
+
carries: "Execution is halted pending an external unblock; wins over every other derived status."
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
key: "backlog",
|
|
469
|
+
id: "vinaya/backlog",
|
|
470
|
+
category: "state",
|
|
471
|
+
form: "literal",
|
|
472
|
+
carries: "The Issue is deliberately unplanned — belongs to no tranche and is excluded from dispatch, until a Planner promotes it."
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
key: "tier-0",
|
|
476
|
+
id: "vinaya/tier:0",
|
|
477
|
+
category: "tier",
|
|
478
|
+
form: "literal",
|
|
479
|
+
carries: "Lowest governance weight — typecheck, lint, tests, and a conforming PR body."
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
key: "tier-1",
|
|
483
|
+
id: "vinaya/tier:1",
|
|
484
|
+
category: "tier",
|
|
485
|
+
form: "literal",
|
|
486
|
+
carries: "Tier 0 plus spec/skill coverage and a passing verify-docs run."
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
key: "tier-3",
|
|
490
|
+
id: "vinaya/tier:3",
|
|
491
|
+
category: "tier",
|
|
492
|
+
form: "literal",
|
|
493
|
+
carries: "Tier 1 plus the reasoning for the change, stated in the pull request that makes it."
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
key: "tranche",
|
|
497
|
+
id: "vinaya/tranche:",
|
|
498
|
+
category: "tranche",
|
|
499
|
+
form: "prefix",
|
|
500
|
+
carries: "The tranche slug this task Issue belongs to — the forge's grouping key, matched by prefix."
|
|
501
|
+
},
|
|
502
|
+
{
|
|
503
|
+
key: "needs-execution-input",
|
|
504
|
+
id: "vinaya/needs:execution-input",
|
|
505
|
+
category: "needs",
|
|
506
|
+
form: "literal",
|
|
507
|
+
carries: "Waiting on a missing execution detail — a flag, a dependency, a value the brief did not carry."
|
|
508
|
+
},
|
|
509
|
+
{
|
|
510
|
+
key: "needs-strategy-input",
|
|
511
|
+
id: "vinaya/needs:strategy-input",
|
|
512
|
+
category: "needs",
|
|
513
|
+
form: "literal",
|
|
514
|
+
carries: "Waiting on a strategy call — the brief assumes an approach the codebase has moved away from."
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
key: "needs-principal-input",
|
|
518
|
+
id: "vinaya/needs:principal-input",
|
|
519
|
+
category: "needs",
|
|
520
|
+
form: "literal",
|
|
521
|
+
carries: "Waiting on the Principal — a product-level call no agent may make."
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
key: "needs-brief-correction",
|
|
525
|
+
id: "vinaya/needs:brief-correction",
|
|
526
|
+
category: "needs",
|
|
527
|
+
form: "literal",
|
|
528
|
+
carries: "Waiting on the Planner — the brief contradicts the surface it describes."
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
key: "waiver-docs",
|
|
532
|
+
id: "vinaya/waiver:docs",
|
|
533
|
+
category: "waiver",
|
|
534
|
+
form: "literal",
|
|
535
|
+
carries: "Doc-coverage gate excused for this PR — honored only when a principal applied it."
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
key: "waiver-review",
|
|
539
|
+
id: "vinaya/waiver:review",
|
|
540
|
+
category: "waiver",
|
|
541
|
+
form: "literal",
|
|
542
|
+
carries: "Review gate excused for this PR — honored only when a principal applied it."
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
key: "override-docs",
|
|
546
|
+
id: "vinaya/override:docs",
|
|
547
|
+
category: "waiver",
|
|
548
|
+
form: "literal",
|
|
549
|
+
carries: "The whole verify-docs gate suppressed for this PR — a Principal-only blunt override, wider than a waiver."
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
key: "incoherent",
|
|
553
|
+
id: "vinaya/incoherent",
|
|
554
|
+
category: "flag",
|
|
555
|
+
form: "literal",
|
|
556
|
+
carries: "Closed COMPLETED with no merged-PR link — done-but-unprovable, surfaced for a human."
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
key: "direct-main-push",
|
|
560
|
+
id: "vinaya/direct-main-push",
|
|
561
|
+
category: "flag",
|
|
562
|
+
form: "literal",
|
|
563
|
+
carries: "A commit reached main with no associated merged PR — ring-2 detection, never a mutation."
|
|
564
|
+
},
|
|
565
|
+
{
|
|
566
|
+
key: "dead-branch-push",
|
|
567
|
+
id: "vinaya/dead-branch-push",
|
|
568
|
+
category: "flag",
|
|
569
|
+
form: "literal",
|
|
570
|
+
carries: "Commits landed on a branch after its PR had already resolved — daily-drift detection."
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
key: "state-object",
|
|
574
|
+
id: "vinaya/state-object",
|
|
575
|
+
category: "kind",
|
|
576
|
+
form: "literal",
|
|
577
|
+
carries: "A permanent forge-native storage object, never actionable work — excluded from every backlog."
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
key: "type-build",
|
|
581
|
+
id: "vinaya/type:build",
|
|
582
|
+
category: "type",
|
|
583
|
+
form: "literal",
|
|
584
|
+
carries: "The task changes the build system, packaging, or an external dependency rather than product behavior."
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
key: "type-chore",
|
|
588
|
+
id: "vinaya/type:chore",
|
|
589
|
+
category: "type",
|
|
590
|
+
form: "literal",
|
|
591
|
+
carries: "The task is maintenance or repo housekeeping with no functional, user-facing change."
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
key: "type-docs",
|
|
595
|
+
id: "vinaya/type:docs",
|
|
596
|
+
category: "type",
|
|
597
|
+
form: "literal",
|
|
598
|
+
carries: "The task changes documentation only, with no code behavior affected."
|
|
599
|
+
},
|
|
600
|
+
{
|
|
601
|
+
key: "type-feat",
|
|
602
|
+
id: "vinaya/type:feat",
|
|
603
|
+
category: "type",
|
|
604
|
+
form: "literal",
|
|
605
|
+
carries: "The task adds a capability that did not exist before."
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
key: "type-fix",
|
|
609
|
+
id: "vinaya/type:fix",
|
|
610
|
+
category: "type",
|
|
611
|
+
form: "literal",
|
|
612
|
+
carries: "The task corrects incorrect behavior — a bug, not a missing capability."
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
key: "type-perf",
|
|
616
|
+
id: "vinaya/type:perf",
|
|
617
|
+
category: "type",
|
|
618
|
+
form: "literal",
|
|
619
|
+
carries: "The task improves performance or resource use without changing observable behavior."
|
|
620
|
+
},
|
|
621
|
+
{
|
|
622
|
+
key: "type-refactor",
|
|
623
|
+
id: "vinaya/type:refactor",
|
|
624
|
+
category: "type",
|
|
625
|
+
form: "literal",
|
|
626
|
+
carries: "The task restructures existing code without changing its external behavior."
|
|
627
|
+
},
|
|
628
|
+
{
|
|
629
|
+
key: "type-revert",
|
|
630
|
+
id: "vinaya/type:revert",
|
|
631
|
+
category: "type",
|
|
632
|
+
form: "literal",
|
|
633
|
+
carries: "The task undoes a previous change that shipped in error or is no longer wanted."
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
key: "type-style",
|
|
637
|
+
id: "vinaya/type:style",
|
|
638
|
+
category: "type",
|
|
639
|
+
form: "literal",
|
|
640
|
+
carries: "The task changes formatting, naming, or non-semantic code shape with no logic change."
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
key: "type-test",
|
|
644
|
+
id: "vinaya/type:test",
|
|
645
|
+
category: "type",
|
|
646
|
+
form: "literal",
|
|
647
|
+
carries: "The task adds or corrects test coverage with no production-code behavior change."
|
|
648
|
+
}
|
|
649
|
+
];
|
|
650
|
+
var BY_KEY = new Map(LABELS.map((l) => [l.key, l]));
|
|
651
|
+
function entry(key) {
|
|
652
|
+
const found = BY_KEY.get(key);
|
|
653
|
+
if (!found)
|
|
654
|
+
throw new Error(`labels.ts: no LABELS entry for key '${key}'`);
|
|
655
|
+
return found;
|
|
656
|
+
}
|
|
657
|
+
function label(key) {
|
|
658
|
+
return entry(key).id;
|
|
659
|
+
}
|
|
660
|
+
function trancheSlugOf(name) {
|
|
661
|
+
const prefix = entry("tranche").id;
|
|
662
|
+
return name.startsWith(prefix) ? name.slice(prefix.length) : null;
|
|
663
|
+
}
|
|
664
|
+
function findTrancheSlug(names) {
|
|
665
|
+
for (const n of names) {
|
|
666
|
+
const slug = trancheSlugOf(n);
|
|
667
|
+
if (slug !== null)
|
|
668
|
+
return slug;
|
|
669
|
+
}
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
// ../../packages/aeg-forge-state/src/list-tasks.ts
|
|
674
|
+
var TITLE_PATTERN = /^\[([^\]]+)]\s*(\S+)\s*—\s*(.+)$/;
|
|
675
|
+
function resolveTaskIssueRef(title, labels) {
|
|
676
|
+
const m = title.match(TITLE_PATTERN);
|
|
677
|
+
if (!m)
|
|
678
|
+
return null;
|
|
679
|
+
const taskId = (m[2] ?? "").trim();
|
|
680
|
+
if (!taskId)
|
|
681
|
+
return null;
|
|
682
|
+
const trancheSlug = findTrancheSlug(labels);
|
|
683
|
+
if (!trancheSlug)
|
|
684
|
+
return null;
|
|
685
|
+
return { trancheSlug, taskId };
|
|
686
|
+
}
|
|
687
|
+
// ../../packages/aeg-forge-state/src/github-token.ts
|
|
688
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
689
|
+
import { promisify as promisify2 } from "node:util";
|
|
690
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
691
|
+
var systemEnv2 = {
|
|
692
|
+
...process.env,
|
|
693
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
694
|
+
};
|
|
695
|
+
// ../../packages/aeg-forge-state/src/resolve-repo.ts
|
|
696
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
697
|
+
import { promisify as promisify3 } from "node:util";
|
|
698
|
+
var execFileAsync3 = promisify3(execFile3);
|
|
699
|
+
var systemEnv3 = {
|
|
700
|
+
...process.env,
|
|
701
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
702
|
+
};
|
|
703
|
+
var defaultExec = () => execFileAsync3("git", ["remote", "get-url", "origin"], { env: systemEnv3, timeout: 5000 });
|
|
704
|
+
var cached;
|
|
705
|
+
var inflight;
|
|
706
|
+
async function resolveRepo(exec = defaultExec) {
|
|
707
|
+
if (cached !== undefined)
|
|
708
|
+
return cached;
|
|
709
|
+
const fromEnv = process.env.AEG_REPO;
|
|
710
|
+
if (fromEnv) {
|
|
711
|
+
const parsed = parseOwnerRepo(fromEnv);
|
|
712
|
+
if (parsed) {
|
|
713
|
+
cached = parsed;
|
|
714
|
+
return cached;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
if (inflight)
|
|
718
|
+
return inflight;
|
|
719
|
+
inflight = (async () => {
|
|
720
|
+
try {
|
|
721
|
+
const { stdout } = await exec();
|
|
722
|
+
cached = parseGitRemoteUrl(stdout.trim());
|
|
723
|
+
return cached;
|
|
724
|
+
} catch (err) {
|
|
725
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
726
|
+
console.warn(`[aeg-forge-state] resolveRepo: git remote lookup failed (will retry): ${message}`);
|
|
727
|
+
return null;
|
|
728
|
+
} finally {
|
|
729
|
+
inflight = undefined;
|
|
730
|
+
}
|
|
731
|
+
})();
|
|
732
|
+
return inflight;
|
|
733
|
+
}
|
|
734
|
+
function parseGitRemoteUrl(url) {
|
|
735
|
+
const ssh = url.match(/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/);
|
|
736
|
+
if (ssh?.[1] && ssh[2])
|
|
737
|
+
return { owner: ssh[1], repo: ssh[2] };
|
|
738
|
+
const https = url.match(/^https?:\/\/(?:[^@]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
739
|
+
if (https?.[1] && https[2])
|
|
740
|
+
return { owner: https[1], repo: https[2] };
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
743
|
+
function parseOwnerRepo(value) {
|
|
744
|
+
const match = value.match(/^([^/]+)\/(.+)$/);
|
|
745
|
+
if (!match?.[1] || !match[2])
|
|
746
|
+
return null;
|
|
747
|
+
return { owner: match[1], repo: match[2] };
|
|
748
|
+
}
|
|
749
|
+
// ../../packages/aeg-core/src/state-machine-model.ts
|
|
750
|
+
var FORGE_FACT_INPUTS = [
|
|
751
|
+
{
|
|
752
|
+
fact: "issueState",
|
|
753
|
+
readsFrom: "Issue.state (OPEN | CLOSED)",
|
|
754
|
+
meaning: "Whether the task Issue is still open — the anchor for the honest terminal statuses."
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
fact: "assigned",
|
|
758
|
+
readsFrom: "Issue.assignees (count > 0)",
|
|
759
|
+
meaning: "An assignee exists. No longer affects derivation: assigned and unassigned are both todo."
|
|
760
|
+
},
|
|
761
|
+
{
|
|
762
|
+
fact: "branchExists",
|
|
763
|
+
readsFrom: "Ref refs/heads/task/<tranche>/<id>",
|
|
764
|
+
meaning: "A task branch has been published — the todo → in-flight transition, written by git push, not by hand."
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
fact: "prState",
|
|
768
|
+
readsFrom: "PullRequest.state (OPEN | CLOSED | MERGED)",
|
|
769
|
+
meaning: "Whether work is proposed or landed. CLOSED-without-merge collapses to none — AEG models open/merged/none."
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
fact: "reviewDecision",
|
|
773
|
+
readsFrom: "PullRequest.reviewDecision",
|
|
774
|
+
meaning: "Only 'changes_requested' flips status; approved-but-unmerged stays in-review."
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
fact: "blockedLabel",
|
|
778
|
+
readsFrom: `Issue.labels contains '${label("blocked")}'`,
|
|
779
|
+
meaning: "Execution halted pending an external unblock. Wins over every other rule."
|
|
780
|
+
},
|
|
781
|
+
{
|
|
782
|
+
fact: "stateReason",
|
|
783
|
+
readsFrom: "Issue.stateReason (COMPLETED | NOT_PLANNED | REOPENED | null)",
|
|
784
|
+
meaning: "Separates a legitimate drop from an incoherent close on a closed, never-merged Issue."
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
fact: "closedAt",
|
|
788
|
+
readsFrom: "Issue.closedAt",
|
|
789
|
+
meaning: "Timestamp for the coherence oracle grandfather cutoff. No derivation rule reads it."
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
fact: "mergedAt",
|
|
793
|
+
readsFrom: "PullRequest.mergedAt",
|
|
794
|
+
meaning: "Timestamp for the coherence oracle grandfather cutoff. No derivation rule reads it."
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
fact: "closedByActor",
|
|
798
|
+
readsFrom: "ClosedEvent.actor.login (most recent timeline CLOSED_EVENT)",
|
|
799
|
+
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."
|
|
800
|
+
}
|
|
801
|
+
];
|
|
802
|
+
var DERIVED_STATUSES = [
|
|
803
|
+
"backlog",
|
|
804
|
+
"todo",
|
|
805
|
+
"in-flight",
|
|
806
|
+
"in-review",
|
|
807
|
+
"changes-requested",
|
|
808
|
+
"merged",
|
|
809
|
+
"blocked",
|
|
810
|
+
"dropped",
|
|
811
|
+
"incoherent"
|
|
812
|
+
];
|
|
813
|
+
var DERIVABLE_STATUSES = DERIVED_STATUSES.filter((s) => s !== "backlog");
|
|
814
|
+
// ../../packages/aeg-core/src/waiver-label.ts
|
|
815
|
+
var WAIVER_LABEL = label("waiver-docs");
|
|
816
|
+
var WAIVER_LABEL_REVIEW = label("waiver-review");
|
|
817
|
+
// ../../packages/aeg-core/src/report-tokens.ts
|
|
818
|
+
var DASH_LOOKALIKES = {
|
|
819
|
+
"-": "‑",
|
|
820
|
+
"–": "‒",
|
|
821
|
+
"—": "―"
|
|
822
|
+
};
|
|
823
|
+
var DASH_CHARS = new Set(Object.keys(DASH_LOOKALIKES));
|
|
824
|
+
// ../../packages/aeg-core/src/metering-io-guard.ts
|
|
825
|
+
import { closeSync as closeSync2, constants as fsConstants, fstatSync, openSync as openSync2, readFileSync as readFileSync3 } from "node:fs";
|
|
826
|
+
var GUARD_OPEN_FLAGS = fsConstants.O_RDONLY | fsConstants.O_NONBLOCK | fsConstants.O_NOFOLLOW;
|
|
827
|
+
// ../../packages/aeg-core/src/doc-owners.ts
|
|
828
|
+
function globToRegex(pat) {
|
|
829
|
+
let re = "^";
|
|
830
|
+
let i = 0;
|
|
831
|
+
while (i < pat.length) {
|
|
832
|
+
const c = pat[i];
|
|
833
|
+
if (c === "*") {
|
|
834
|
+
if (pat[i + 1] === "*") {
|
|
835
|
+
re += ".*";
|
|
836
|
+
i += 2;
|
|
837
|
+
} else {
|
|
838
|
+
re += "[^/]*";
|
|
839
|
+
i += 1;
|
|
840
|
+
}
|
|
841
|
+
} else if (/[.+^$|(){}[\]\\?]/.test(c)) {
|
|
842
|
+
re += `\\${c}`;
|
|
843
|
+
i += 1;
|
|
844
|
+
} else {
|
|
845
|
+
re += c;
|
|
846
|
+
i += 1;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
re += "$";
|
|
850
|
+
return new RegExp(re);
|
|
851
|
+
}
|
|
852
|
+
var SEPARATOR = /(?:[ \t]*[—–][ \t]*|[ \t]+-[ \t]+)/.source;
|
|
853
|
+
// ../../packages/aeg-core/src/review-policy.ts
|
|
854
|
+
var SECURITY_SEVERITY_ORDER = ["CRITICAL", "HIGH", "MEDIUM", "LOW"];
|
|
855
|
+
function blockingSeverities(scale, threshold) {
|
|
856
|
+
const idx = scale.indexOf(threshold);
|
|
857
|
+
if (idx === -1) {
|
|
858
|
+
throw new Error(`blockingSeverities: threshold "${threshold}" is not one of ${scale.join(" > ")}`);
|
|
859
|
+
}
|
|
860
|
+
return scale.slice(0, idx + 1);
|
|
861
|
+
}
|
|
862
|
+
var SECURITY_HIGH_AND_ABOVE = blockingSeverities(SECURITY_SEVERITY_ORDER, "HIGH");
|
|
863
|
+
// ../../packages/aeg-core/src/pr-tier.ts
|
|
864
|
+
var OVERRIDE_BODY_TOKEN = `[${label("override-docs")}]`;
|
|
865
|
+
// ../../packages/aeg-core/src/premise-check.ts
|
|
866
|
+
var ASSERTION_KINDS = new Set(["contains", "absent", "sha256"]);
|
|
867
|
+
|
|
868
|
+
// ../../packages/aeg-core/src/brief-validation.ts
|
|
869
|
+
var COMMIT_TYPES = [
|
|
870
|
+
"Build",
|
|
871
|
+
"Chore",
|
|
872
|
+
"Docs",
|
|
873
|
+
"Feat",
|
|
874
|
+
"Fix",
|
|
875
|
+
"Perf",
|
|
876
|
+
"Plan",
|
|
877
|
+
"Refactor",
|
|
878
|
+
"Revert",
|
|
879
|
+
"Style",
|
|
880
|
+
"Test"
|
|
881
|
+
];
|
|
882
|
+
var COMMIT_TYPE_STYLE = new RegExp(`^(${COMMIT_TYPES.join("|")})(\\([a-z0-9-]+\\))?: \\S`);
|
|
883
|
+
// ../../packages/aeg-core/src/doctrine-portability.ts
|
|
884
|
+
var EXEMPT_LITERALS = new Set([
|
|
885
|
+
"path/inside/the/shipped/diff.ts",
|
|
886
|
+
"path/inside/the/surface.ts",
|
|
887
|
+
"apps/x/specs/..."
|
|
888
|
+
]);
|
|
889
|
+
var NON_PATH_TOP_SEGMENTS = new Set(["origin", "refs", "HEAD", "vinaya", "fix"]);
|
|
890
|
+
|
|
891
|
+
// ../../packages/aeg-core/src/doctrine-no-procedures.ts
|
|
892
|
+
var SHELL_LANGS = new Set(["", "sh", "bash", "shell", "console"]);
|
|
893
|
+
// ../../packages/aeg-core/src/prose-rules.ts
|
|
894
|
+
var RETIRED_GLOBAL_EXEMPTIONS = [
|
|
895
|
+
"docs/decisions-legacy.md",
|
|
896
|
+
"apps/herald-ai/docs/",
|
|
897
|
+
"apps/vada-ai/docs/",
|
|
898
|
+
"aeg-root/tranches/completed/",
|
|
899
|
+
"packages/aeg-core/src/docs/published-prose",
|
|
900
|
+
"packages/aeg-core/src/retired-vocabulary.test.ts",
|
|
901
|
+
"packages/aeg-core/src/retired-vocabulary.ts",
|
|
902
|
+
"/fixtures/",
|
|
903
|
+
"/node_modules/",
|
|
904
|
+
"/.next/",
|
|
905
|
+
"/.turbo/"
|
|
906
|
+
];
|
|
907
|
+
var PLAN_ON_DISK_PATTERNS = ["[Tt]opology files?", "aeg-root/tranches/", "aeg-project/"];
|
|
908
|
+
var TRANCHE_MODEL_FILE = "/tranche-model.md";
|
|
909
|
+
var RETIRED_PATTERN_EXEMPTIONS = {
|
|
910
|
+
[String.raw`\bD-[0-9]{3}\b`]: ["./CLAUDE.md"],
|
|
911
|
+
[String.raw`(^|[^-_a-zA-Z0-9])decisions\.md`]: [
|
|
912
|
+
"docs-index.md",
|
|
913
|
+
"apps/vada-ai/specs/legacy/README.md",
|
|
914
|
+
"apps/vada-ai/specs/vada-product-spec.md",
|
|
915
|
+
"apps/vada-ai/web/CLAUDE.md",
|
|
916
|
+
"apps/vada-ai/CLAUDE.md"
|
|
917
|
+
],
|
|
918
|
+
"decisions-legacy": [
|
|
919
|
+
"packages/aeg-core/src/file-classify.ts",
|
|
920
|
+
"packages/aeg-core/src/file-classify.test.ts",
|
|
921
|
+
"packages/aeg-core/src/pr-tier.test.ts",
|
|
922
|
+
"docs-index.md",
|
|
923
|
+
".claude/skills/database/SKILL.md",
|
|
924
|
+
".claude/skills/vada-architecture/SKILL.md",
|
|
925
|
+
"apps/vada-ai/specs/vada-byok-principles.md",
|
|
926
|
+
"apps/vada-ai/web/CLAUDE.md",
|
|
927
|
+
"apps/vada-ai/CLAUDE.md"
|
|
928
|
+
],
|
|
929
|
+
CONTRADICTION: ["apps/vada-ai/specs/vada-reviewers-spec.md"],
|
|
930
|
+
...Object.fromEntries(PLAN_ON_DISK_PATTERNS.map((pattern) => [pattern, [TRANCHE_MODEL_FILE]]))
|
|
931
|
+
};
|
|
932
|
+
var retiredPatterns = [
|
|
933
|
+
String.raw`\bD-[0-9]{3}\b`,
|
|
934
|
+
"D-(###|NNN|nnn|xxx)",
|
|
935
|
+
"decision (entry|logged)",
|
|
936
|
+
"decision-log entry",
|
|
937
|
+
"decision log entry",
|
|
938
|
+
"decision log(s|ged|ging)?([^a-z]|$)",
|
|
939
|
+
"decision-log",
|
|
940
|
+
"decision entr",
|
|
941
|
+
"decisions? (are |is )?logged",
|
|
942
|
+
"log entries",
|
|
943
|
+
String.raw`(^|[^-_a-zA-Z0-9])decisions\.md`,
|
|
944
|
+
"decisions-legacy",
|
|
945
|
+
"CONTRADICTION",
|
|
946
|
+
"assumes Tier 3",
|
|
947
|
+
"Lock: ?YES",
|
|
948
|
+
"Lock: ?NO",
|
|
949
|
+
"lock approvals?",
|
|
950
|
+
"approves locks",
|
|
951
|
+
"Conforms to lock",
|
|
952
|
+
"Challenges lock",
|
|
953
|
+
"checkDecisionNumbersFresh",
|
|
954
|
+
String.raw`roles/team-leader\.md`,
|
|
955
|
+
String.raw`\(,`,
|
|
956
|
+
String.raw`,\)`,
|
|
957
|
+
String.raw`\(\.\)`,
|
|
958
|
+
...PLAN_ON_DISK_PATTERNS
|
|
959
|
+
];
|
|
960
|
+
var published = [
|
|
961
|
+
["decision-id", "a decision id", /\bD-\d{3,}\b/],
|
|
962
|
+
["section-ref", "a section reference", /§/],
|
|
963
|
+
["forge-number", "a forge number", /#\d+/],
|
|
964
|
+
["retired-name", "the retired public name", /\bAEG\b/],
|
|
965
|
+
["tranche-slug", "a tranche slug", /\b[a-z][a-z0-9]*(?:-[a-z0-9]+)+-v\d+\b/],
|
|
966
|
+
[
|
|
967
|
+
"label-vocabulary",
|
|
968
|
+
"forge label vocabulary",
|
|
969
|
+
/(?:vinaya\/)?\b(?:tranche|iteration|tier|needs|waiver|project|aeg):(?![/\s]|$)/
|
|
970
|
+
],
|
|
971
|
+
["internal-path", "a repo-internal path", /\b(?:packages|apps|aeg-root|tools|scripts)\//],
|
|
972
|
+
["internal-path", "a repo-internal path", /\.(?:claude|husky|github)\//],
|
|
973
|
+
[
|
|
974
|
+
"internal-path",
|
|
975
|
+
"a repo-internal file",
|
|
976
|
+
/(?:^|[\s(`"'[])[\w.-]+(?:\/[\w.-]+)*\.(?:ts|tsx|js|jsx|mjs|cjs|sh|ya?ml|json|md)\b/
|
|
977
|
+
]
|
|
978
|
+
];
|
|
979
|
+
var DEFAULT_PROSE_RULES = [
|
|
980
|
+
{
|
|
981
|
+
id: "forge-number",
|
|
982
|
+
group: "reader-resolvable",
|
|
983
|
+
scopes: ["ships", "reader-facing", "spec"],
|
|
984
|
+
patterns: { prose: /#[0-9]{2,4}/g },
|
|
985
|
+
flags: ["global"],
|
|
986
|
+
message: "a forge number",
|
|
987
|
+
severity: { ships: "warning", "reader-facing": "warning", spec: "error" },
|
|
988
|
+
exemptions: []
|
|
989
|
+
},
|
|
990
|
+
{
|
|
991
|
+
id: "tranche-slug",
|
|
992
|
+
group: "reader-resolvable",
|
|
993
|
+
scopes: ["ships", "reader-facing", "product", "spec"],
|
|
994
|
+
patterns: { prose: /[a-z][a-z-]+-v[0-9]/g },
|
|
995
|
+
flags: ["global"],
|
|
996
|
+
message: "an internal tranche slug",
|
|
997
|
+
severity: { ships: "warning", "reader-facing": "warning", product: "error", spec: "error" },
|
|
998
|
+
exemptions: []
|
|
999
|
+
},
|
|
1000
|
+
{
|
|
1001
|
+
id: "task-number",
|
|
1002
|
+
group: "reader-resolvable",
|
|
1003
|
+
scopes: ["spec"],
|
|
1004
|
+
patterns: { prose: /(^|[^a-z0-9-])(tasks?[ \t]+#?[0-9]+)/gi },
|
|
1005
|
+
flags: ["global", "ignore-case"],
|
|
1006
|
+
message: "a task number",
|
|
1007
|
+
severity: { spec: "error" },
|
|
1008
|
+
exemptions: []
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
id: "source-comment-tranche-slug",
|
|
1012
|
+
group: "reader-resolvable",
|
|
1013
|
+
scopes: ["source-comment"],
|
|
1014
|
+
patterns: { comment: /[a-z0-9]+(?:-[a-z0-9]+)*-v[0-9]+/g },
|
|
1015
|
+
flags: ["global"],
|
|
1016
|
+
message: "a tranche-slug citation",
|
|
1017
|
+
severity: { "source-comment": "warning" },
|
|
1018
|
+
exemptions: []
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
id: "source-comment-forge-number",
|
|
1022
|
+
group: "reader-resolvable",
|
|
1023
|
+
scopes: ["source-comment"],
|
|
1024
|
+
patterns: { comment: /#[0-9]{2,}/g },
|
|
1025
|
+
flags: ["global"],
|
|
1026
|
+
message: "a forge-number citation",
|
|
1027
|
+
severity: { "source-comment": "warning" },
|
|
1028
|
+
exemptions: []
|
|
1029
|
+
},
|
|
1030
|
+
{
|
|
1031
|
+
id: "legacy-batch-name",
|
|
1032
|
+
group: "reader-resolvable",
|
|
1033
|
+
scopes: ["ships", "reader-facing", "spec"],
|
|
1034
|
+
patterns: {},
|
|
1035
|
+
flags: ["built-in"],
|
|
1036
|
+
message: "an internal tranche slug",
|
|
1037
|
+
severity: { ships: "warning", "reader-facing": "warning", spec: "error" },
|
|
1038
|
+
exemptions: [],
|
|
1039
|
+
builtIn: true
|
|
1040
|
+
},
|
|
1041
|
+
{
|
|
1042
|
+
id: "coined-term",
|
|
1043
|
+
group: "reader-resolvable",
|
|
1044
|
+
scopes: ["ships", "reader-facing"],
|
|
1045
|
+
patterns: {},
|
|
1046
|
+
flags: ["built-in"],
|
|
1047
|
+
message: "uses coined term without defining it inline or linking the glossary",
|
|
1048
|
+
severity: { ships: "warning", "reader-facing": "warning" },
|
|
1049
|
+
exemptions: [],
|
|
1050
|
+
builtIn: true
|
|
1051
|
+
},
|
|
1052
|
+
...retiredPatterns.map((pattern, index) => ({
|
|
1053
|
+
id: `retired-vocabulary-${index + 1}`,
|
|
1054
|
+
group: "retired-vocabulary",
|
|
1055
|
+
scopes: ["repository"],
|
|
1056
|
+
patterns: { repository: pattern },
|
|
1057
|
+
flags: [],
|
|
1058
|
+
message: "retired vocabulary",
|
|
1059
|
+
severity: { repository: "error" },
|
|
1060
|
+
exemptions: RETIRED_GLOBAL_EXEMPTIONS,
|
|
1061
|
+
patternExemptions: RETIRED_PATTERN_EXEMPTIONS
|
|
1062
|
+
})),
|
|
1063
|
+
...published.map(([id, message, pattern]) => ({
|
|
1064
|
+
id,
|
|
1065
|
+
group: "published-prose",
|
|
1066
|
+
scopes: ["published"],
|
|
1067
|
+
patterns: { published: pattern },
|
|
1068
|
+
flags: [],
|
|
1069
|
+
message,
|
|
1070
|
+
severity: { published: "error" },
|
|
1071
|
+
exemptions: [".worktrees/task/<tranche>/<n>", "task/<tranche>/<n>", ".worktrees/"]
|
|
1072
|
+
}))
|
|
1073
|
+
];
|
|
1074
|
+
var rulesForGroup = (group) => DEFAULT_PROSE_RULES.filter((rule) => rule.group === group);
|
|
1075
|
+
var RESOLVABLE_SCOPES = ["ships", "reader-facing", "product", "spec", "source-comment"];
|
|
1076
|
+
var RETIRED_SCOPES = ["repository"];
|
|
1077
|
+
var CONFIGURABLE_PROSE_SCOPES = [...RESOLVABLE_SCOPES, ...RETIRED_SCOPES];
|
|
1078
|
+
function groupOfScope(scope) {
|
|
1079
|
+
if (RESOLVABLE_SCOPES.includes(scope))
|
|
1080
|
+
return "reader-resolvable";
|
|
1081
|
+
if (RETIRED_SCOPES.includes(scope))
|
|
1082
|
+
return "retired-vocabulary";
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
var CONFIGURED_PROSE_FLAGS = ["i", "u"];
|
|
1086
|
+
var CONFIGURED_PATTERN_MAX_LENGTH = 200;
|
|
1087
|
+
var CONFIGURABLE_DEFAULT_RULES = DEFAULT_PROSE_RULES.filter((rule) => rule.group !== "published-prose");
|
|
1088
|
+
function allowedScopesFor(rule) {
|
|
1089
|
+
if (rule.builtIn)
|
|
1090
|
+
return rule.scopes;
|
|
1091
|
+
return rule.group === "retired-vocabulary" ? RETIRED_SCOPES : RESOLVABLE_SCOPES;
|
|
1092
|
+
}
|
|
1093
|
+
function normalizeRepoPath(entry) {
|
|
1094
|
+
let out = entry.replace(/\\/g, "/");
|
|
1095
|
+
while (out.startsWith("./"))
|
|
1096
|
+
out = out.slice(2);
|
|
1097
|
+
out = out.replace(/\/{2,}/g, "/");
|
|
1098
|
+
while (out.endsWith("/"))
|
|
1099
|
+
out = out.slice(0, -1);
|
|
1100
|
+
return out;
|
|
1101
|
+
}
|
|
1102
|
+
var RESOLVABLE_RUN_ORDER = [
|
|
1103
|
+
"forge-number",
|
|
1104
|
+
"tranche-slug",
|
|
1105
|
+
"legacy-batch-name",
|
|
1106
|
+
"task-number",
|
|
1107
|
+
"source-comment-tranche-slug",
|
|
1108
|
+
"source-comment-forge-number",
|
|
1109
|
+
"coined-term"
|
|
1110
|
+
];
|
|
1111
|
+
var REPORT_GROUPS = { "task-number": 2, "legacy-batch-name": 2 };
|
|
1112
|
+
function scopeDefaultSeverity(scope, sourceCommentSeverity) {
|
|
1113
|
+
if (scope === "source-comment")
|
|
1114
|
+
return sourceCommentSeverity ?? "warning";
|
|
1115
|
+
if (scope === "repository")
|
|
1116
|
+
return "error";
|
|
1117
|
+
return "warning";
|
|
1118
|
+
}
|
|
1119
|
+
function applySeverity(scopes, base, setting) {
|
|
1120
|
+
const out = {};
|
|
1121
|
+
for (const scope of scopes) {
|
|
1122
|
+
const configured = typeof setting === "string" ? setting : setting?.[scope];
|
|
1123
|
+
const value = configured ?? base[scope];
|
|
1124
|
+
if (value !== undefined)
|
|
1125
|
+
out[scope] = value;
|
|
1126
|
+
}
|
|
1127
|
+
return out;
|
|
1128
|
+
}
|
|
1129
|
+
function defaultPatternFor(rule) {
|
|
1130
|
+
const cache = new Map;
|
|
1131
|
+
return (scope) => {
|
|
1132
|
+
if (cache.has(scope))
|
|
1133
|
+
return cache.get(scope) ?? null;
|
|
1134
|
+
const own = rule.patterns[scope] ?? (scope === "source-comment" ? rule.patterns.comment : rule.patterns.prose) ?? Object.values(rule.patterns)[0];
|
|
1135
|
+
const compiled = own === undefined ? null : own instanceof RegExp ? own : new RegExp(own);
|
|
1136
|
+
cache.set(scope, compiled);
|
|
1137
|
+
return compiled;
|
|
1138
|
+
};
|
|
1139
|
+
}
|
|
1140
|
+
function customPatternFor(rule, global) {
|
|
1141
|
+
const cache = new Map;
|
|
1142
|
+
return (scope) => {
|
|
1143
|
+
if (cache.has(scope))
|
|
1144
|
+
return cache.get(scope) ?? null;
|
|
1145
|
+
const source = rule.patterns?.[scope] ?? rule.pattern;
|
|
1146
|
+
const compiled = source === undefined ? null : new RegExp(source, `${rule.flags ?? ""}${global ? "g" : ""}`);
|
|
1147
|
+
cache.set(scope, compiled);
|
|
1148
|
+
return compiled;
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
function resolveProseRules(config = undefined, options = {}) {
|
|
1152
|
+
const rules = [];
|
|
1153
|
+
const defaults = config?.defaults ?? {};
|
|
1154
|
+
for (const rule of CONFIGURABLE_DEFAULT_RULES) {
|
|
1155
|
+
const override = defaults[rule.id];
|
|
1156
|
+
if (override === "off")
|
|
1157
|
+
continue;
|
|
1158
|
+
const group = rule.group;
|
|
1159
|
+
const scopes = override?.scopes ?? rule.scopes;
|
|
1160
|
+
const base = {};
|
|
1161
|
+
for (const scope of scopes) {
|
|
1162
|
+
base[scope] = scope === "source-comment" ? options.sourceCommentSeverity ?? rule.severity[scope] ?? "warning" : rule.severity[scope] ?? scopeDefaultSeverity(scope, options.sourceCommentSeverity);
|
|
1163
|
+
}
|
|
1164
|
+
rules.push({
|
|
1165
|
+
id: rule.id,
|
|
1166
|
+
group,
|
|
1167
|
+
custom: false,
|
|
1168
|
+
builtIn: rule.builtIn === true,
|
|
1169
|
+
scopes,
|
|
1170
|
+
message: rule.message,
|
|
1171
|
+
severity: applySeverity(scopes, base, override?.severity),
|
|
1172
|
+
exempt: override?.exempt ?? [],
|
|
1173
|
+
substringExempt: rule.exemptions,
|
|
1174
|
+
reportGroup: REPORT_GROUPS[rule.id],
|
|
1175
|
+
patternFor: defaultPatternFor(rule)
|
|
1176
|
+
});
|
|
1177
|
+
}
|
|
1178
|
+
for (const rule of config?.custom ?? []) {
|
|
1179
|
+
const group = groupOfScope(rule.scopes[0] ?? "") ?? "reader-resolvable";
|
|
1180
|
+
const base = {};
|
|
1181
|
+
for (const scope of rule.scopes)
|
|
1182
|
+
base[scope] = scopeDefaultSeverity(scope, options.sourceCommentSeverity);
|
|
1183
|
+
rules.push({
|
|
1184
|
+
id: rule.id,
|
|
1185
|
+
group,
|
|
1186
|
+
custom: true,
|
|
1187
|
+
builtIn: false,
|
|
1188
|
+
scopes: rule.scopes,
|
|
1189
|
+
message: rule.means,
|
|
1190
|
+
severity: applySeverity(rule.scopes, base, rule.severity),
|
|
1191
|
+
exempt: rule.exempt ?? [],
|
|
1192
|
+
substringExempt: [],
|
|
1193
|
+
patternFor: customPatternFor(rule, group === "reader-resolvable")
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
if (options.decisionRecordsPath !== undefined)
|
|
1197
|
+
rules.push(decisionRecordCitationRule(options.decisionRecordsPath));
|
|
1198
|
+
const order = (rule) => {
|
|
1199
|
+
const at = RESOLVABLE_RUN_ORDER.indexOf(rule.id);
|
|
1200
|
+
return rule.custom || at === -1 ? RESOLVABLE_RUN_ORDER.length : at;
|
|
1201
|
+
};
|
|
1202
|
+
const resolvable = rules.filter((rule) => rule.group === "reader-resolvable");
|
|
1203
|
+
const sorted = resolvable.map((rule, index) => ({ rule, index })).sort((a, b) => order(a.rule) - order(b.rule) || a.index - b.index).map(({ rule }) => rule);
|
|
1204
|
+
return {
|
|
1205
|
+
rules: [...sorted, ...rules.filter((rule) => rule.group === "retired-vocabulary")],
|
|
1206
|
+
exempt: config?.exempt ?? [],
|
|
1207
|
+
repoRoot: options.repoRoot
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
var DEFAULT_PROSE_RULE_SET = resolveProseRules();
|
|
1211
|
+
var DECISION_RECORD_CITATION_ID = "decision-record-citation";
|
|
1212
|
+
var DECISION_RECORD_CITATION_SCOPES = ["ships", "product", "spec", "source-comment"];
|
|
1213
|
+
var DECISION_RECORD_CITATION_MESSAGE = "a decision-record number";
|
|
1214
|
+
function escapeRegExp(text) {
|
|
1215
|
+
return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1216
|
+
}
|
|
1217
|
+
function decisionRecordCitationPattern(decisionRecordsPath) {
|
|
1218
|
+
const folder = escapeRegExp(normalizeRepoPath(decisionRecordsPath));
|
|
1219
|
+
return new RegExp(String.raw`\bADR[- ]?[0-9]+\b|(?<![A-Za-z0-9_-])${folder}/[0-9]+[A-Za-z0-9._-]*`, "g");
|
|
1220
|
+
}
|
|
1221
|
+
function decisionRecordCitationRule(decisionRecordsPath) {
|
|
1222
|
+
const folder = normalizeRepoPath(decisionRecordsPath);
|
|
1223
|
+
const pattern = decisionRecordCitationPattern(folder);
|
|
1224
|
+
const severity = {};
|
|
1225
|
+
for (const scope of DECISION_RECORD_CITATION_SCOPES)
|
|
1226
|
+
severity[scope] = "error";
|
|
1227
|
+
return {
|
|
1228
|
+
id: DECISION_RECORD_CITATION_ID,
|
|
1229
|
+
group: "reader-resolvable",
|
|
1230
|
+
custom: false,
|
|
1231
|
+
builtIn: false,
|
|
1232
|
+
scopes: DECISION_RECORD_CITATION_SCOPES,
|
|
1233
|
+
message: DECISION_RECORD_CITATION_MESSAGE,
|
|
1234
|
+
severity,
|
|
1235
|
+
exempt: [folder],
|
|
1236
|
+
substringExempt: [],
|
|
1237
|
+
patternFor: () => pattern
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
// ../../packages/aeg-core/src/reader-resolvable-prose.ts
|
|
1242
|
+
function normalizeSpecPath(entry) {
|
|
1243
|
+
return normalizeRepoPath(entry);
|
|
1244
|
+
}
|
|
1245
|
+
var SWEPT_CLASSES = new Set(["ships", "reader-facing"]);
|
|
1246
|
+
var readerRules = rulesForGroup("reader-resolvable");
|
|
1247
|
+
var readerPattern = (id, scope = "prose") => {
|
|
1248
|
+
const pattern = readerRules.find((rule) => rule.id === id)?.patterns[scope];
|
|
1249
|
+
if (!(pattern instanceof RegExp))
|
|
1250
|
+
throw new Error(`default prose rule ${id} has no ${scope} pattern`);
|
|
1251
|
+
return pattern;
|
|
1252
|
+
};
|
|
1253
|
+
var FORGE_NUMBER_PATTERN = readerPattern("forge-number");
|
|
1254
|
+
var TRANCHE_SLUG_VN_PATTERN = readerPattern("tranche-slug");
|
|
1255
|
+
var TASK_NUMBER_PATTERN = readerPattern("task-number");
|
|
1256
|
+
var REFERENCE_CLASSES = new Set(["ships", "reader-facing", "product", "spec"]);
|
|
1257
|
+
var SOURCE_COMMENT_TRANCHE_SLUG_PATTERN = readerPattern("source-comment-tranche-slug", "comment");
|
|
1258
|
+
var SOURCE_COMMENT_FORGE_NUMBER_PATTERN = readerPattern("source-comment-forge-number", "comment");
|
|
1259
|
+
|
|
1260
|
+
// ../../packages/aeg-core/src/quoted-command.ts
|
|
1261
|
+
var QUOTED_COMMAND_SWEPT_CLASSES = new Set(["ships", "reader-facing"]);
|
|
1262
|
+
|
|
1263
|
+
// ../../packages/aeg-core/src/issue-validation.ts
|
|
1264
|
+
var DEPENDENCY_RATIONALE_FIELD_NAME = "Dependency rationale";
|
|
1265
|
+
var SINGLE_FIX_OPTIONAL_FIELDS = new Set([
|
|
1266
|
+
"Sizing",
|
|
1267
|
+
"Project(s) + blast radius",
|
|
1268
|
+
DEPENDENCY_RATIONALE_FIELD_NAME
|
|
1269
|
+
]);
|
|
1270
|
+
var TYPE_LABEL_IDS = LABELS.filter((l) => l.category === "type").map((l) => l.id);
|
|
1271
|
+
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;
|
|
1272
|
+
var DOC_PATH_RE_GLOBAL = new RegExp(DOC_PATH_RE.source, "gi");
|
|
1273
|
+
var FILE_EXTENSIONS = new Set([
|
|
1274
|
+
"ts",
|
|
1275
|
+
"tsx",
|
|
1276
|
+
"js",
|
|
1277
|
+
"jsx",
|
|
1278
|
+
"mjs",
|
|
1279
|
+
"cjs",
|
|
1280
|
+
"json",
|
|
1281
|
+
"jsonc",
|
|
1282
|
+
"md",
|
|
1283
|
+
"mdx",
|
|
1284
|
+
"yml",
|
|
1285
|
+
"yaml",
|
|
1286
|
+
"txt",
|
|
1287
|
+
"sh",
|
|
1288
|
+
"lock",
|
|
1289
|
+
"toml",
|
|
1290
|
+
"ndjson",
|
|
1291
|
+
"html",
|
|
1292
|
+
"css"
|
|
1293
|
+
]);
|
|
1294
|
+
var CI_SHARD_DIR = "apps/cli/tests/ci-shards";
|
|
1295
|
+
var CI_SHARD_PROBE = `${CI_SHARD_DIR}/shard-1.txt`;
|
|
1296
|
+
|
|
1297
|
+
// ../../packages/aeg-core/src/coherence-checks.ts
|
|
1298
|
+
var R1_GRANDFATHERED_ISSUES = new Set([279, 280, 281, 282]);
|
|
1299
|
+
// ../../packages/aeg-core/src/diagram-model.ts
|
|
1300
|
+
import matter from "gray-matter";
|
|
1301
|
+
// ../../packages/aeg-core/src/retired-vocabulary.ts
|
|
1302
|
+
var retiredRules = rulesForGroup("retired-vocabulary");
|
|
1303
|
+
var RETIRED_PATTERNS = retiredRules.map((rule) => rule.patterns.repository);
|
|
1304
|
+
var DEFAULT_PATTERN_OF = new Map(retiredRules.map((rule) => [rule.id, rule.patterns.repository]));
|
|
1305
|
+
// ../../packages/aeg-core/src/task-tools.ts
|
|
1306
|
+
import { z } from "zod";
|
|
1307
|
+
var TASK_TOOL_ERROR_KINDS = [
|
|
1308
|
+
"validation",
|
|
1309
|
+
"authority",
|
|
1310
|
+
"precondition",
|
|
1311
|
+
"capability",
|
|
1312
|
+
"infrastructure",
|
|
1313
|
+
"cancellation",
|
|
1314
|
+
"timeout",
|
|
1315
|
+
"uncertain_effect"
|
|
1316
|
+
];
|
|
1317
|
+
var TaskToolErrorSchema = z.object({
|
|
1318
|
+
kind: z.enum(TASK_TOOL_ERROR_KINDS),
|
|
1319
|
+
message: z.string().min(1),
|
|
1320
|
+
detail: z.string().optional()
|
|
1321
|
+
});
|
|
1322
|
+
var TaskToolRefSchema = z.union([
|
|
1323
|
+
z.object({ tranche: z.string().min(1), id: z.string().min(1) }).strict(),
|
|
1324
|
+
z.object({ issue: z.number().int().positive() }).strict()
|
|
1325
|
+
]);
|
|
1326
|
+
var MAX_PAGE_LIMIT = 100;
|
|
1327
|
+
var PageRequestSchema = z.object({
|
|
1328
|
+
cursor: z.string().optional(),
|
|
1329
|
+
limit: z.number().int().positive().max(MAX_PAGE_LIMIT).optional()
|
|
1330
|
+
});
|
|
1331
|
+
var FreshnessSchema = z.enum(["fresh", "stale", "unknown"]);
|
|
1332
|
+
var ObservedSchema = z.object({
|
|
1333
|
+
observedAt: z.string(),
|
|
1334
|
+
freshness: FreshnessSchema
|
|
1335
|
+
});
|
|
1336
|
+
var TaskStatusInputSchema = z.object({
|
|
1337
|
+
task: TaskToolRefSchema.optional()
|
|
1338
|
+
}).merge(PageRequestSchema).strict();
|
|
1339
|
+
var TaskConfidenceSchema = z.object({
|
|
1340
|
+
round: z.number().int().positive(),
|
|
1341
|
+
percent: z.number().int().min(0).max(100).nullable(),
|
|
1342
|
+
source: z.enum(["stated", "published-summary"])
|
|
1343
|
+
}).strict();
|
|
1344
|
+
var TaskPhaseHistorySchema = z.object({
|
|
1345
|
+
typicalPhaseMinutes: z.number().nonnegative(),
|
|
1346
|
+
typicalPhaseSamples: z.number().int().positive()
|
|
1347
|
+
}).strict();
|
|
1348
|
+
var TaskStatusItemSchema = z.object({
|
|
1349
|
+
task: TaskToolRefSchema,
|
|
1350
|
+
issue: z.number().int().positive(),
|
|
1351
|
+
pr: z.number().int().positive().nullable(),
|
|
1352
|
+
state: z.string(),
|
|
1353
|
+
round: z.number().int().positive().nullable().optional(),
|
|
1354
|
+
phase: z.string().min(1).nullable().optional(),
|
|
1355
|
+
minutesInPhase: z.number().nonnegative().nullable().optional(),
|
|
1356
|
+
phaseIsCurrent: z.boolean().nullable().optional(),
|
|
1357
|
+
lastConfidence: TaskConfidenceSchema.nullable().optional(),
|
|
1358
|
+
lastConfidenceUnread: z.boolean().optional(),
|
|
1359
|
+
phaseHistory: TaskPhaseHistorySchema.nullable().optional()
|
|
1360
|
+
}).merge(ObservedSchema);
|
|
1361
|
+
var TaskStatusResultSchema = z.object({
|
|
1362
|
+
items: z.array(TaskStatusItemSchema),
|
|
1363
|
+
nextCursor: z.string().nullable(),
|
|
1364
|
+
table: z.string()
|
|
1365
|
+
});
|
|
1366
|
+
var RequestedAuthoritySchema = z.enum(["planner", "principal", "operator", "self"]);
|
|
1367
|
+
var EscalationInputsSchema = z.object({
|
|
1368
|
+
task: z.number().int().positive(),
|
|
1369
|
+
round: z.number().int().nonnegative(),
|
|
1370
|
+
head: z.string(),
|
|
1371
|
+
branch: z.string(),
|
|
1372
|
+
prNumber: z.number().int().positive().nullable()
|
|
1373
|
+
});
|
|
1374
|
+
var EscalationEvidenceSchema = z.object({
|
|
1375
|
+
round: z.number().int().nonnegative(),
|
|
1376
|
+
reviewer: z.string().nullable(),
|
|
1377
|
+
security: z.string().nullable()
|
|
1378
|
+
});
|
|
1379
|
+
var EscalationRunIdentitySchema = z.object({
|
|
1380
|
+
runId: z.string(),
|
|
1381
|
+
pid: z.number().int().positive(),
|
|
1382
|
+
host: z.string()
|
|
1383
|
+
});
|
|
1384
|
+
var EscalationInputVersionsSchema = z.object({
|
|
1385
|
+
briefHash: z.string().nullable(),
|
|
1386
|
+
objectivesVersion: z.string().nullable(),
|
|
1387
|
+
rulingOrdinal: z.number().int().nonnegative(),
|
|
1388
|
+
policyDigest: z.string()
|
|
1389
|
+
});
|
|
1390
|
+
var TaskEscalationReadInputSchema = z.object({
|
|
1391
|
+
task: TaskToolRefSchema
|
|
1392
|
+
}).merge(PageRequestSchema).strict();
|
|
1393
|
+
var TaskEscalationPacketSchema = z.object({
|
|
1394
|
+
reason: z.string(),
|
|
1395
|
+
detail: z.string().nullable(),
|
|
1396
|
+
inputs: EscalationInputsSchema.nullable(),
|
|
1397
|
+
evidence: EscalationEvidenceSchema.nullable(),
|
|
1398
|
+
attemptedRecovery: z.string(),
|
|
1399
|
+
requestedAuthority: RequestedAuthoritySchema,
|
|
1400
|
+
permittedNextActions: z.array(z.string()),
|
|
1401
|
+
runIdentity: EscalationRunIdentitySchema.nullable(),
|
|
1402
|
+
inputVersions: EscalationInputVersionsSchema.nullable()
|
|
1403
|
+
}).merge(ObservedSchema);
|
|
1404
|
+
var TaskEscalationReadResultSchema = z.object({
|
|
1405
|
+
items: z.array(TaskEscalationPacketSchema),
|
|
1406
|
+
nextCursor: z.string().nullable()
|
|
1407
|
+
}).merge(ObservedSchema);
|
|
1408
|
+
var TaskPrCheckSchema = z.object({
|
|
1409
|
+
name: z.string(),
|
|
1410
|
+
required: z.boolean(),
|
|
1411
|
+
status: z.string(),
|
|
1412
|
+
conclusion: z.string().nullable(),
|
|
1413
|
+
detailsUrl: z.string().nullable(),
|
|
1414
|
+
failureSummary: z.string().nullable()
|
|
1415
|
+
});
|
|
1416
|
+
var TaskPrVerdictSchema = z.object({
|
|
1417
|
+
role: z.enum(["code-review", "security"]),
|
|
1418
|
+
value: z.string(),
|
|
1419
|
+
judgedHead: z.string().nullable(),
|
|
1420
|
+
objectivesVersion: z.string().nullable()
|
|
1421
|
+
});
|
|
1422
|
+
var TaskPrPauseSchema = z.object({
|
|
1423
|
+
reason: z.string(),
|
|
1424
|
+
body: z.string()
|
|
1425
|
+
});
|
|
1426
|
+
var TaskPrReviewRecordSchema = z.object({
|
|
1427
|
+
verdicts: z.array(TaskPrVerdictSchema),
|
|
1428
|
+
roundMarkers: z.array(z.number().int().nonnegative()),
|
|
1429
|
+
pause: TaskPrPauseSchema.nullable()
|
|
1430
|
+
});
|
|
1431
|
+
var TaskPrReadInputSchema = z.object({
|
|
1432
|
+
task: TaskToolRefSchema,
|
|
1433
|
+
pr: z.number().int().positive().optional()
|
|
1434
|
+
}).strict();
|
|
1435
|
+
var TaskPrReadResultSchema = z.object({
|
|
1436
|
+
task: TaskToolRefSchema,
|
|
1437
|
+
issue: z.number().int().positive(),
|
|
1438
|
+
pr: z.number().int().positive(),
|
|
1439
|
+
head: z.string().nullable(),
|
|
1440
|
+
checks: z.array(TaskPrCheckSchema),
|
|
1441
|
+
review: TaskPrReviewRecordSchema
|
|
1442
|
+
}).merge(ObservedSchema);
|
|
1443
|
+
var TaskStartResultSchema = z.object({
|
|
1444
|
+
requestId: z.string().min(1),
|
|
1445
|
+
run: TaskToolRefSchema,
|
|
1446
|
+
started: z.boolean(),
|
|
1447
|
+
startedAt: z.string(),
|
|
1448
|
+
mode: z.literal("attended")
|
|
1449
|
+
});
|
|
1450
|
+
var TaskResumeInputSchema = z.object({
|
|
1451
|
+
task: TaskToolRefSchema
|
|
1452
|
+
}).strict();
|
|
1453
|
+
var TaskCancelInputSchema = z.object({
|
|
1454
|
+
task: TaskToolRefSchema,
|
|
1455
|
+
reason: z.string().min(1)
|
|
1456
|
+
}).strict();
|
|
1457
|
+
var TaskResumeResultSchema = z.object({
|
|
1458
|
+
task: z.number().int().positive(),
|
|
1459
|
+
pr: z.number().int().positive().nullable(),
|
|
1460
|
+
escalationId: z.string().min(1),
|
|
1461
|
+
outcome: z.enum(["started", "already_resumed"]),
|
|
1462
|
+
authenticatedBy: z.string().min(1),
|
|
1463
|
+
authenticatedFrom: z.string().min(1)
|
|
1464
|
+
});
|
|
1465
|
+
var TaskCancelOutcomeSchema = z.enum(["confirmed", "pending", "uncertain"]);
|
|
1466
|
+
var TaskCancelResultSchema = z.object({
|
|
1467
|
+
task: z.number().int().positive(),
|
|
1468
|
+
pr: z.number().int().positive().nullable(),
|
|
1469
|
+
escalationId: z.string().min(1),
|
|
1470
|
+
outcome: TaskCancelOutcomeSchema,
|
|
1471
|
+
authenticatedBy: z.string().min(1),
|
|
1472
|
+
authenticatedFrom: z.string().min(1),
|
|
1473
|
+
fencedEffectKeys: z.array(z.string())
|
|
1474
|
+
});
|
|
1475
|
+
// ../../packages/aeg-core/src/log/schema.ts
|
|
1476
|
+
import { z as z3 } from "zod";
|
|
1477
|
+
|
|
1478
|
+
// ../../packages/aeg-core/src/log/custom.ts
|
|
1479
|
+
import { z as z2 } from "zod";
|
|
1480
|
+
var CUSTOM_EVENT_NAME_PATTERN = /^[a-z][a-z0-9_]*\.[a-z][a-z0-9_.]*$/;
|
|
1481
|
+
var CUSTOM_EVENT_NAME_MAX_LENGTH = 64;
|
|
1482
|
+
var CUSTOM_EVENT_RESERVED_NAMESPACE = "vinaya";
|
|
1483
|
+
var CUSTOM_EVENT_MAX_FIELDS = 20;
|
|
1484
|
+
var CUSTOM_FIELD_NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
1485
|
+
var CUSTOM_FIELD_NAME_MAX_LENGTH = 64;
|
|
1486
|
+
var CUSTOM_TEXT_MAX_LENGTH = 500;
|
|
1487
|
+
var CUSTOM_WORD_PATTERN = /^[a-z0-9][a-z0-9_-]*$/;
|
|
1488
|
+
var CUSTOM_WORD_MAX_LENGTH = 64;
|
|
1489
|
+
var CUSTOM_FIELD_MAX_WORDS = 50;
|
|
1490
|
+
var CustomFieldTypeSchema = z2.union([z2.enum(["text", "number", "boolean"]), z2.array(z2.string())]);
|
|
1491
|
+
var CustomEventDeclarationsSchema = z2.record(z2.string(), z2.object({
|
|
1492
|
+
fields: z2.record(z2.string(), CustomFieldTypeSchema)
|
|
1493
|
+
}).strict()).superRefine((events, ctx) => {
|
|
1494
|
+
for (const [name, declaration] of Object.entries(events)) {
|
|
1495
|
+
const refuse = (message, path = []) => {
|
|
1496
|
+
ctx.addIssue({
|
|
1497
|
+
code: z2.ZodIssueCode.custom,
|
|
1498
|
+
path: [name, ...path],
|
|
1499
|
+
message: `logs.events "${name}": ${message}`
|
|
1500
|
+
});
|
|
1501
|
+
};
|
|
1502
|
+
if (name.length > CUSTOM_EVENT_NAME_MAX_LENGTH) {
|
|
1503
|
+
refuse(`the name must be at most ${CUSTOM_EVENT_NAME_MAX_LENGTH} characters`);
|
|
1504
|
+
}
|
|
1505
|
+
if (!CUSTOM_EVENT_NAME_PATTERN.test(name)) {
|
|
1506
|
+
refuse("the name must be `<namespace>.<event>` — lowercase letters, digits and `_`, a dot between them");
|
|
1507
|
+
} else if (name.split(".")[0] === CUSTOM_EVENT_RESERVED_NAMESPACE) {
|
|
1508
|
+
refuse(`the \`${CUSTOM_EVENT_RESERVED_NAMESPACE}.\` namespace is reserved for Vinaya's own events`);
|
|
1509
|
+
}
|
|
1510
|
+
const fieldEntries = Object.entries(declaration.fields);
|
|
1511
|
+
if (fieldEntries.length > CUSTOM_EVENT_MAX_FIELDS) {
|
|
1512
|
+
refuse(`at most ${CUSTOM_EVENT_MAX_FIELDS} fields may be declared (found ${fieldEntries.length})`, ["fields"]);
|
|
1513
|
+
}
|
|
1514
|
+
for (const [field, type] of fieldEntries) {
|
|
1515
|
+
if (field.length > CUSTOM_FIELD_NAME_MAX_LENGTH || !CUSTOM_FIELD_NAME_PATTERN.test(field)) {
|
|
1516
|
+
refuse(`field "${field}": a field name is lowercase letters, digits and \`_\`, starting with a letter, at most ${CUSTOM_FIELD_NAME_MAX_LENGTH} characters`, ["fields", field]);
|
|
1517
|
+
}
|
|
1518
|
+
if (typeof type === "string")
|
|
1519
|
+
continue;
|
|
1520
|
+
if (type.length === 0) {
|
|
1521
|
+
refuse(`field "${field}": a list of words must name at least one word`, ["fields", field]);
|
|
1522
|
+
}
|
|
1523
|
+
if (type.length > CUSTOM_FIELD_MAX_WORDS) {
|
|
1524
|
+
refuse(`field "${field}": a list of words may name at most ${CUSTOM_FIELD_MAX_WORDS}`, ["fields", field]);
|
|
1525
|
+
}
|
|
1526
|
+
const bad = type.filter((w) => w.length > CUSTOM_WORD_MAX_LENGTH || !CUSTOM_WORD_PATTERN.test(w));
|
|
1527
|
+
if (bad.length > 0) {
|
|
1528
|
+
refuse(`field "${field}": a listed word is lowercase letters, digits, \`_\` and \`-\`, at most ${CUSTOM_WORD_MAX_LENGTH} characters`, ["fields", field]);
|
|
1529
|
+
}
|
|
1530
|
+
if (new Set(type).size !== type.length) {
|
|
1531
|
+
refuse(`field "${field}": a list of words names a word twice`, ["fields", field]);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
|
|
1537
|
+
// ../../packages/aeg-core/src/log/schema.ts
|
|
1538
|
+
var CONFIDENCE_REASON_MAX_LENGTH = 280;
|
|
1539
|
+
var REVIEW_FINDING_DESCRIPTION_MAX_LENGTH = 1000;
|
|
1540
|
+
var ROLE_VALUES = [
|
|
1541
|
+
"planner",
|
|
1542
|
+
"developer",
|
|
1543
|
+
"code-reviewer",
|
|
1544
|
+
"security",
|
|
1545
|
+
"principal",
|
|
1546
|
+
"archivist",
|
|
1547
|
+
"architect"
|
|
1548
|
+
];
|
|
1549
|
+
var RoleSchema = z3.enum(ROLE_VALUES);
|
|
1550
|
+
var HOST_VALUES = ["hook", "ci", "cli", "loop"];
|
|
1551
|
+
var HostSchema = z3.enum(HOST_VALUES);
|
|
1552
|
+
var RUN_ID_PATTERN = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
1553
|
+
var headerMetaCore = {
|
|
1554
|
+
ts: z3.string(),
|
|
1555
|
+
run_id: z3.string().regex(RUN_ID_PATTERN),
|
|
1556
|
+
seq: z3.number().int().nonnegative(),
|
|
1557
|
+
repo: z3.string().nullable(),
|
|
1558
|
+
vinaya: z3.string(),
|
|
1559
|
+
doctrine: z3.string(),
|
|
1560
|
+
host: HostSchema,
|
|
1561
|
+
machine: z3.string()
|
|
1562
|
+
};
|
|
1563
|
+
var HeaderMetaV1Schema = z3.object({
|
|
1564
|
+
schema: z3.literal(1),
|
|
1565
|
+
...headerMetaCore
|
|
1566
|
+
}).strict();
|
|
1567
|
+
var LineageSchema = z3.object({
|
|
1568
|
+
run: z3.string().nullable(),
|
|
1569
|
+
attempt: z3.number().int().nullable(),
|
|
1570
|
+
parent: z3.string().nullable()
|
|
1571
|
+
}).strict();
|
|
1572
|
+
var InputVersionsSchema = z3.object({
|
|
1573
|
+
manifest_version: z3.literal(2).nullable().optional(),
|
|
1574
|
+
objectives_version: z3.string().nullable(),
|
|
1575
|
+
brief_hash: z3.string().nullable(),
|
|
1576
|
+
ruling_ordinal: z3.number().int().nullable(),
|
|
1577
|
+
pause_bound_ruling: z3.object({ rulingId: z3.string().min(1), pauseId: z3.string().min(1), contentDigest: z3.string().min(1) }).strict().nullable().optional(),
|
|
1578
|
+
policy_digest: z3.string().nullable()
|
|
1579
|
+
}).strict();
|
|
1580
|
+
var ProvenanceSchema = z3.enum(["parent_attributed", "env_correlated", "self_reported", "unavailable"]);
|
|
1581
|
+
var HeaderMetaV2Schema = z3.object({
|
|
1582
|
+
schema: z3.literal(2),
|
|
1583
|
+
...headerMetaCore,
|
|
1584
|
+
event_id: z3.string().min(1),
|
|
1585
|
+
process_id: z3.string().min(1),
|
|
1586
|
+
actor_id: z3.string().nullable(),
|
|
1587
|
+
lineage: LineageSchema,
|
|
1588
|
+
input_versions: InputVersionsSchema,
|
|
1589
|
+
provenance: ProvenanceSchema
|
|
1590
|
+
}).strict();
|
|
1591
|
+
var WorkSchema = z3.object({
|
|
1592
|
+
ref: z3.string().nullable(),
|
|
1593
|
+
repo: z3.string().nullable(),
|
|
1594
|
+
change: z3.string().nullable(),
|
|
1595
|
+
revision: z3.string().nullable()
|
|
1596
|
+
}).strict();
|
|
1597
|
+
var FlowSchema = z3.object({
|
|
1598
|
+
id: z3.string().nullable(),
|
|
1599
|
+
version: z3.string().nullable()
|
|
1600
|
+
}).strict();
|
|
1601
|
+
var HeaderMetaV3Schema = z3.object({
|
|
1602
|
+
schema: z3.literal(3),
|
|
1603
|
+
...headerMetaCore,
|
|
1604
|
+
event_id: z3.string().min(1),
|
|
1605
|
+
process_id: z3.string().min(1),
|
|
1606
|
+
actor_id: z3.string().nullable(),
|
|
1607
|
+
lineage: LineageSchema,
|
|
1608
|
+
input_versions: InputVersionsSchema,
|
|
1609
|
+
provenance: ProvenanceSchema,
|
|
1610
|
+
work: WorkSchema,
|
|
1611
|
+
flow: FlowSchema,
|
|
1612
|
+
runtime: z3.string().nullable(),
|
|
1613
|
+
source: z3.string().nullable()
|
|
1614
|
+
}).strict();
|
|
1615
|
+
var HeaderMetaV4Schema = HeaderMetaV3Schema.extend({
|
|
1616
|
+
schema: z3.literal(4),
|
|
1617
|
+
process: z3.object({ id: z3.string(), version: z3.string().nullable(), digest: z3.string().nullable() }).strict(),
|
|
1618
|
+
runner: z3.object({ id: z3.string(), version: z3.string().nullable() }).strict()
|
|
1619
|
+
}).strict();
|
|
1620
|
+
var HeaderMetaSchema = z3.discriminatedUnion("schema", [
|
|
1621
|
+
HeaderMetaV1Schema,
|
|
1622
|
+
HeaderMetaV2Schema,
|
|
1623
|
+
HeaderMetaV3Schema,
|
|
1624
|
+
HeaderMetaV4Schema
|
|
1625
|
+
]);
|
|
1626
|
+
var SubjectSchema = z3.object({
|
|
1627
|
+
issue: z3.number().int().nullable(),
|
|
1628
|
+
pr: z3.number().int().optional(),
|
|
1629
|
+
sha: z3.string().optional(),
|
|
1630
|
+
role: z3.union([RoleSchema, z3.literal("unattributed")]),
|
|
1631
|
+
round: z3.number().int().optional(),
|
|
1632
|
+
objectives_version: z3.string().optional()
|
|
1633
|
+
}).strict();
|
|
1634
|
+
var HeaderSchema = z3.object({
|
|
1635
|
+
meta: HeaderMetaSchema,
|
|
1636
|
+
subject: SubjectSchema
|
|
1637
|
+
}).strict();
|
|
1638
|
+
var envelopeTail = {
|
|
1639
|
+
duration_ms: z3.number().nonnegative().optional(),
|
|
1640
|
+
payload: z3.object({}).strict()
|
|
1641
|
+
};
|
|
1642
|
+
var ReviewFindingSchema = z3.object({
|
|
1643
|
+
id: z3.string(),
|
|
1644
|
+
severity: z3.string(),
|
|
1645
|
+
location: z3.string().optional(),
|
|
1646
|
+
deferral_reason: z3.enum(["outside-surface", "unchanged-line"]).optional(),
|
|
1647
|
+
description: z3.string().max(REVIEW_FINDING_DESCRIPTION_MAX_LENGTH).optional(),
|
|
1648
|
+
state: z3.string().optional(),
|
|
1649
|
+
severity_scale: z3.string().optional(),
|
|
1650
|
+
policy_treatment: z3.enum(["blocking", "non_blocking", "unavailable"]).optional(),
|
|
1651
|
+
confidence: z3.number().min(0).max(1).optional(),
|
|
1652
|
+
confidence_scale: z3.string().optional(),
|
|
1653
|
+
confidence_source: z3.string().optional()
|
|
1654
|
+
}).strict();
|
|
1655
|
+
var DispatchOutcomeSchema = z3.discriminatedUnion("type", [
|
|
1656
|
+
z3.object({ type: z3.literal("pr_opened"), pr: z3.number().int(), head: z3.string() }).strict(),
|
|
1657
|
+
z3.object({
|
|
1658
|
+
type: z3.literal("round_pushed"),
|
|
1659
|
+
pr: z3.number().int(),
|
|
1660
|
+
head: z3.string(),
|
|
1661
|
+
comment_id: z3.number().int()
|
|
1662
|
+
}).strict(),
|
|
1663
|
+
z3.object({
|
|
1664
|
+
type: z3.literal("verdict"),
|
|
1665
|
+
verdict: z3.enum(["APPROVE", "REQUEST CHANGES", "PASS", "FAIL"]),
|
|
1666
|
+
head: z3.string(),
|
|
1667
|
+
comment_id: z3.number().int(),
|
|
1668
|
+
objectives: z3.array(z3.object({ id: z3.string(), met: z3.boolean() }).strict()),
|
|
1669
|
+
findings: z3.array(ReviewFindingSchema)
|
|
1670
|
+
}).strict(),
|
|
1671
|
+
z3.object({
|
|
1672
|
+
type: z3.literal("escalation"),
|
|
1673
|
+
class: z3.enum(["authority", "strategy", "product"]),
|
|
1674
|
+
comment_id: z3.number().int()
|
|
1675
|
+
}).strict(),
|
|
1676
|
+
z3.object({ type: z3.literal("brief"), comment_id: z3.number().int(), hash: z3.string() }).strict(),
|
|
1677
|
+
z3.object({ type: z3.literal("plan"), issues: z3.array(z3.number().int()) }).strict(),
|
|
1678
|
+
z3.object({ type: z3.literal("archive"), provenance_comment_id: z3.number().int() }).strict(),
|
|
1679
|
+
z3.object({ type: z3.literal("completed") }).strict()
|
|
1680
|
+
]);
|
|
1681
|
+
var dispatchShared = {
|
|
1682
|
+
meta: HeaderMetaSchema,
|
|
1683
|
+
subject: SubjectSchema,
|
|
1684
|
+
kind: z3.literal("dispatch"),
|
|
1685
|
+
...envelopeTail,
|
|
1686
|
+
target_role: RoleSchema,
|
|
1687
|
+
model: z3.string(),
|
|
1688
|
+
round: z3.number().int().optional(),
|
|
1689
|
+
effect_id: z3.string()
|
|
1690
|
+
};
|
|
1691
|
+
var dispatchUsageField = z3.object({ input: z3.number().nonnegative(), output: z3.number().nonnegative() }).strict().nullable();
|
|
1692
|
+
var DispatchEventSchema = z3.discriminatedUnion("event", [
|
|
1693
|
+
z3.object({ ...dispatchShared, event: z3.literal("dispatched"), prompt_hash: z3.string() }).strict(),
|
|
1694
|
+
z3.object({
|
|
1695
|
+
...dispatchShared,
|
|
1696
|
+
event: z3.literal("outcome_received"),
|
|
1697
|
+
outcome: DispatchOutcomeSchema,
|
|
1698
|
+
usage: dispatchUsageField
|
|
1699
|
+
}).strict(),
|
|
1700
|
+
z3.object({
|
|
1701
|
+
...dispatchShared,
|
|
1702
|
+
event: z3.literal("dispatch_failed"),
|
|
1703
|
+
reason: z3.enum(["timeout", "crash", "refused", "unattributed_write", "usage_limit"]),
|
|
1704
|
+
usage_limit: z3.object({ agent: z3.string().min(1), reset_at: z3.string().nullable() }).strict().optional(),
|
|
1705
|
+
usage: dispatchUsageField
|
|
1706
|
+
}).strict()
|
|
1707
|
+
]);
|
|
1708
|
+
var CODE_TOKEN_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
|
|
1709
|
+
var CodeTokenSchema = z3.string().regex(CODE_TOKEN_PATTERN);
|
|
1710
|
+
var ReviewerVerdictSchema = z3.object({
|
|
1711
|
+
role: RoleSchema,
|
|
1712
|
+
outcome: z3.enum(["approve", "changes_requested", "not_reviewed"]),
|
|
1713
|
+
blockers: z3.number().int().nonnegative()
|
|
1714
|
+
}).strict();
|
|
1715
|
+
var loopShared = {
|
|
1716
|
+
meta: HeaderMetaSchema,
|
|
1717
|
+
subject: SubjectSchema,
|
|
1718
|
+
kind: z3.literal("dev_review_loop"),
|
|
1719
|
+
...envelopeTail,
|
|
1720
|
+
loop_id: z3.string()
|
|
1721
|
+
};
|
|
1722
|
+
var DevReviewLoopEventSchema = z3.discriminatedUnion("event", [
|
|
1723
|
+
z3.object({
|
|
1724
|
+
...loopShared,
|
|
1725
|
+
event: z3.literal("loop_started"),
|
|
1726
|
+
task: z3.number().int(),
|
|
1727
|
+
policy: z3.object({
|
|
1728
|
+
max_rounds: z3.number().int().nonnegative(),
|
|
1729
|
+
reviewers: z3.array(RoleSchema),
|
|
1730
|
+
models: z3.record(RoleSchema, z3.string())
|
|
1731
|
+
}).strict()
|
|
1732
|
+
}).strict(),
|
|
1733
|
+
z3.object({ ...loopShared, event: z3.literal("round_started"), round: z3.number().int(), base_head: z3.string() }).strict(),
|
|
1734
|
+
z3.object({
|
|
1735
|
+
...loopShared,
|
|
1736
|
+
event: z3.literal("gate_result_read"),
|
|
1737
|
+
round: z3.number().int(),
|
|
1738
|
+
head: z3.string(),
|
|
1739
|
+
green: z3.boolean(),
|
|
1740
|
+
confidence_value: z3.number().int().min(0).max(100).optional(),
|
|
1741
|
+
confidence_reason: z3.string().max(CONFIDENCE_REASON_MAX_LENGTH).optional(),
|
|
1742
|
+
confidence_unavailable: z3.boolean().optional(),
|
|
1743
|
+
extra_turn_spent: z3.boolean().optional()
|
|
1744
|
+
}).strict(),
|
|
1745
|
+
z3.object({
|
|
1746
|
+
...loopShared,
|
|
1747
|
+
event: z3.literal("verdicts_read"),
|
|
1748
|
+
round: z3.number().int(),
|
|
1749
|
+
head: z3.string(),
|
|
1750
|
+
all_approve: z3.boolean(),
|
|
1751
|
+
blockers: z3.number().int().nonnegative(),
|
|
1752
|
+
findings: z3.array(ReviewFindingSchema).optional(),
|
|
1753
|
+
reviewers: z3.array(ReviewerVerdictSchema).optional()
|
|
1754
|
+
}).strict(),
|
|
1755
|
+
z3.object({
|
|
1756
|
+
...loopShared,
|
|
1757
|
+
event: z3.literal("findings_compared"),
|
|
1758
|
+
round: z3.number().int(),
|
|
1759
|
+
open: z3.array(z3.string()),
|
|
1760
|
+
resolved: z3.array(z3.string()),
|
|
1761
|
+
new: z3.array(z3.string()),
|
|
1762
|
+
recurring: z3.array(z3.string())
|
|
1763
|
+
}).strict(),
|
|
1764
|
+
z3.object({
|
|
1765
|
+
...loopShared,
|
|
1766
|
+
event: z3.literal("stop_condition_met"),
|
|
1767
|
+
round: z3.number().int(),
|
|
1768
|
+
condition: z3.enum([
|
|
1769
|
+
"green",
|
|
1770
|
+
"max_rounds",
|
|
1771
|
+
"no_progress",
|
|
1772
|
+
"escalated",
|
|
1773
|
+
"principal_stop",
|
|
1774
|
+
"confidence",
|
|
1775
|
+
"reappearance",
|
|
1776
|
+
"repeat_finding",
|
|
1777
|
+
"repeat_failure",
|
|
1778
|
+
"time_budget"
|
|
1779
|
+
])
|
|
1780
|
+
}).strict(),
|
|
1781
|
+
z3.object({
|
|
1782
|
+
...loopShared,
|
|
1783
|
+
event: z3.literal("paused"),
|
|
1784
|
+
round: z3.number().int(),
|
|
1785
|
+
reason: z3.enum(["escalation", "principal_item", "refreeze_needed"]),
|
|
1786
|
+
reason_code: CodeTokenSchema.optional()
|
|
1787
|
+
}).strict(),
|
|
1788
|
+
z3.object({
|
|
1789
|
+
...loopShared,
|
|
1790
|
+
event: z3.literal("resumed"),
|
|
1791
|
+
round: z3.number().int(),
|
|
1792
|
+
by: z3.enum(["principal", "driver"])
|
|
1793
|
+
}).strict(),
|
|
1794
|
+
z3.object({
|
|
1795
|
+
...loopShared,
|
|
1796
|
+
event: z3.literal("cancelled"),
|
|
1797
|
+
round: z3.number().int(),
|
|
1798
|
+
by: z3.literal("principal")
|
|
1799
|
+
}).strict(),
|
|
1800
|
+
z3.object({
|
|
1801
|
+
...loopShared,
|
|
1802
|
+
event: z3.literal("unpushed_work_resume"),
|
|
1803
|
+
round: z3.number().int(),
|
|
1804
|
+
branch: z3.string(),
|
|
1805
|
+
detail: z3.string()
|
|
1806
|
+
}).strict(),
|
|
1807
|
+
z3.object({
|
|
1808
|
+
...loopShared,
|
|
1809
|
+
event: z3.literal("round_ended"),
|
|
1810
|
+
round: z3.number().int(),
|
|
1811
|
+
base_head: z3.string(),
|
|
1812
|
+
head: z3.string(),
|
|
1813
|
+
files_changed: z3.number().int().nonnegative(),
|
|
1814
|
+
insertions: z3.number().int().nonnegative(),
|
|
1815
|
+
deletions: z3.number().int().nonnegative(),
|
|
1816
|
+
wall_ms: z3.number().nonnegative(),
|
|
1817
|
+
outcome: z3.enum(["green", "changes_requested", "escalated"])
|
|
1818
|
+
}).strict(),
|
|
1819
|
+
z3.object({
|
|
1820
|
+
...loopShared,
|
|
1821
|
+
event: z3.literal("journal_finalized"),
|
|
1822
|
+
rounds: z3.number().int().nonnegative(),
|
|
1823
|
+
total_wall_ms: z3.number().nonnegative(),
|
|
1824
|
+
time_to_green_ms: z3.number().nonnegative().nullable(),
|
|
1825
|
+
files_changed_total: z3.number().int().nonnegative(),
|
|
1826
|
+
final_head: z3.string(),
|
|
1827
|
+
result: z3.enum(["merged_ready", "stopped"])
|
|
1828
|
+
}).strict(),
|
|
1829
|
+
z3.object({
|
|
1830
|
+
...loopShared,
|
|
1831
|
+
event: z3.literal("infrastructure_retry"),
|
|
1832
|
+
round: z3.number().int(),
|
|
1833
|
+
failure_kind: z3.enum(["pause_comment_post", "developer_connection"]),
|
|
1834
|
+
attempts: z3.number().int().positive(),
|
|
1835
|
+
outcome: z3.enum(["recovered", "exhausted"])
|
|
1836
|
+
}).strict(),
|
|
1837
|
+
z3.object({
|
|
1838
|
+
...loopShared,
|
|
1839
|
+
event: z3.literal("driver_heartbeat"),
|
|
1840
|
+
task: z3.number().int(),
|
|
1841
|
+
pr: z3.number().int().positive().optional(),
|
|
1842
|
+
round: z3.number().int(),
|
|
1843
|
+
phase: z3.string()
|
|
1844
|
+
}).strict(),
|
|
1845
|
+
z3.object({
|
|
1846
|
+
...loopShared,
|
|
1847
|
+
event: z3.literal("conflict_reentry"),
|
|
1848
|
+
task: z3.number().int(),
|
|
1849
|
+
pr: z3.number().int().positive(),
|
|
1850
|
+
attempt: z3.number().int().positive(),
|
|
1851
|
+
bound: z3.number().int().positive()
|
|
1852
|
+
}).strict(),
|
|
1853
|
+
z3.object({
|
|
1854
|
+
...loopShared,
|
|
1855
|
+
event: z3.literal("storage_push"),
|
|
1856
|
+
round: z3.number().int(),
|
|
1857
|
+
branch: z3.string(),
|
|
1858
|
+
head: z3.string()
|
|
1859
|
+
}).strict(),
|
|
1860
|
+
z3.object({
|
|
1861
|
+
...loopShared,
|
|
1862
|
+
event: z3.literal("local_checks_run"),
|
|
1863
|
+
round: z3.number().int(),
|
|
1864
|
+
head: z3.string().nullable(),
|
|
1865
|
+
passed: z3.boolean(),
|
|
1866
|
+
wall_ms: z3.number().nonnegative()
|
|
1867
|
+
}).strict(),
|
|
1868
|
+
z3.object({
|
|
1869
|
+
...loopShared,
|
|
1870
|
+
event: z3.literal("ready_push"),
|
|
1871
|
+
round: z3.number().int(),
|
|
1872
|
+
head: z3.string(),
|
|
1873
|
+
outcome: z3.enum(["passed", "refused"]),
|
|
1874
|
+
selected: z3.number().int().nonnegative(),
|
|
1875
|
+
failed: z3.number().int().nonnegative(),
|
|
1876
|
+
rerun: z3.boolean(),
|
|
1877
|
+
wall_ms: z3.number().nonnegative()
|
|
1878
|
+
}).strict(),
|
|
1879
|
+
z3.object({
|
|
1880
|
+
...loopShared,
|
|
1881
|
+
event: z3.literal("failed_tests_rerun"),
|
|
1882
|
+
round: z3.number().int(),
|
|
1883
|
+
head: z3.string(),
|
|
1884
|
+
rerun_of: z3.string(),
|
|
1885
|
+
failed_files: z3.number().int().nonnegative(),
|
|
1886
|
+
affected_files: z3.number().int().nonnegative(),
|
|
1887
|
+
full_count: z3.number().int().nonnegative()
|
|
1888
|
+
}).strict(),
|
|
1889
|
+
z3.object({
|
|
1890
|
+
...loopShared,
|
|
1891
|
+
event: z3.literal("pr_opened"),
|
|
1892
|
+
round: z3.number().int(),
|
|
1893
|
+
pr: z3.number().int().positive(),
|
|
1894
|
+
head: z3.string()
|
|
1895
|
+
}).strict(),
|
|
1896
|
+
z3.object({
|
|
1897
|
+
...loopShared,
|
|
1898
|
+
event: z3.literal("ci_result_read"),
|
|
1899
|
+
round: z3.number().int(),
|
|
1900
|
+
pr: z3.number().int().positive(),
|
|
1901
|
+
head: z3.string(),
|
|
1902
|
+
conclusion: z3.enum(["green", "red", "pending", "skipped"]),
|
|
1903
|
+
failing_checks: z3.array(z3.string()),
|
|
1904
|
+
wait_ms: z3.number().nonnegative()
|
|
1905
|
+
}).strict(),
|
|
1906
|
+
z3.object({
|
|
1907
|
+
...loopShared,
|
|
1908
|
+
event: z3.literal("phase_time"),
|
|
1909
|
+
round: z3.number().int(),
|
|
1910
|
+
phase: z3.enum(["developer", "local_checks", "review", "push", "ci", "other"]),
|
|
1911
|
+
step: z3.string(),
|
|
1912
|
+
wall_ms: z3.number().nonnegative()
|
|
1913
|
+
}).strict(),
|
|
1914
|
+
z3.object({
|
|
1915
|
+
...loopShared,
|
|
1916
|
+
event: z3.literal("driver_exited"),
|
|
1917
|
+
task: z3.number().int(),
|
|
1918
|
+
reason: z3.enum(["finished", "paused", "reexec", "error", "signal"]),
|
|
1919
|
+
last_decision: z3.string(),
|
|
1920
|
+
exit_code: z3.number().int().optional(),
|
|
1921
|
+
error_class: CodeTokenSchema.optional()
|
|
1922
|
+
}).strict()
|
|
1923
|
+
]);
|
|
1924
|
+
var ForgeOpSchema = z3.enum([
|
|
1925
|
+
"pr.create",
|
|
1926
|
+
"pr.comment",
|
|
1927
|
+
"pr.body.replace",
|
|
1928
|
+
"pr.refreeze",
|
|
1929
|
+
"issue.create",
|
|
1930
|
+
"issue.edit",
|
|
1931
|
+
"issue.comment",
|
|
1932
|
+
"milestone.create",
|
|
1933
|
+
"milestone.edit",
|
|
1934
|
+
"milestone.close",
|
|
1935
|
+
"label.add",
|
|
1936
|
+
"label.remove"
|
|
1937
|
+
]);
|
|
1938
|
+
var ForgeWriteTargetSchema = z3.object({
|
|
1939
|
+
issue: z3.number().int().optional(),
|
|
1940
|
+
pr: z3.number().int().optional()
|
|
1941
|
+
}).strict();
|
|
1942
|
+
var forgeWriteShared = {
|
|
1943
|
+
meta: HeaderMetaSchema,
|
|
1944
|
+
subject: SubjectSchema,
|
|
1945
|
+
kind: z3.literal("forge_write"),
|
|
1946
|
+
...envelopeTail,
|
|
1947
|
+
op: ForgeOpSchema,
|
|
1948
|
+
target: ForgeWriteTargetSchema
|
|
1949
|
+
};
|
|
1950
|
+
var ForgeWriteEventSchema = z3.discriminatedUnion("event", [
|
|
1951
|
+
z3.object({ ...forgeWriteShared, event: z3.literal("validated") }).strict(),
|
|
1952
|
+
z3.object({ ...forgeWriteShared, event: z3.literal("refused"), reason: z3.string() }).strict(),
|
|
1953
|
+
z3.object({ ...forgeWriteShared, event: z3.literal("written"), comment_ids: z3.array(z3.string()) }).strict()
|
|
1954
|
+
]);
|
|
1955
|
+
var GateOutcomeSchema = z3.enum([
|
|
1956
|
+
"pass",
|
|
1957
|
+
"fail",
|
|
1958
|
+
"wait",
|
|
1959
|
+
"skip",
|
|
1960
|
+
"invalid_input",
|
|
1961
|
+
"unavailable_dependency",
|
|
1962
|
+
"timeout",
|
|
1963
|
+
"cancelled"
|
|
1964
|
+
]);
|
|
1965
|
+
var gateShared = {
|
|
1966
|
+
meta: HeaderMetaSchema,
|
|
1967
|
+
subject: SubjectSchema,
|
|
1968
|
+
kind: z3.literal("gate"),
|
|
1969
|
+
...envelopeTail,
|
|
1970
|
+
check: z3.string(),
|
|
1971
|
+
check_version: z3.string().nullable(),
|
|
1972
|
+
policy_version: z3.string().nullable(),
|
|
1973
|
+
input_fingerprint: z3.string().nullable()
|
|
1974
|
+
};
|
|
1975
|
+
var GateEventSchema = z3.discriminatedUnion("event", [
|
|
1976
|
+
z3.object({
|
|
1977
|
+
...gateShared,
|
|
1978
|
+
event: z3.literal("checked"),
|
|
1979
|
+
outcome: GateOutcomeSchema,
|
|
1980
|
+
reason: z3.string().optional()
|
|
1981
|
+
}).strict(),
|
|
1982
|
+
z3.object({
|
|
1983
|
+
meta: HeaderMetaSchema,
|
|
1984
|
+
subject: SubjectSchema,
|
|
1985
|
+
kind: z3.literal("gate"),
|
|
1986
|
+
...envelopeTail,
|
|
1987
|
+
event: z3.literal("summary"),
|
|
1988
|
+
ran: z3.number().int().nonnegative(),
|
|
1989
|
+
passed: z3.number().int().nonnegative(),
|
|
1990
|
+
failed: z3.number().int().nonnegative(),
|
|
1991
|
+
skipped: z3.number().int().nonnegative(),
|
|
1992
|
+
failed_checks: z3.array(z3.string())
|
|
1993
|
+
}).strict()
|
|
1994
|
+
]);
|
|
1995
|
+
var OperationResultSchema = z3.enum(["ok", "error", "refused", "timeout", "cancelled", "unavailable"]);
|
|
1996
|
+
var operationShared = {
|
|
1997
|
+
meta: HeaderMetaSchema,
|
|
1998
|
+
subject: SubjectSchema,
|
|
1999
|
+
kind: z3.literal("operation"),
|
|
2000
|
+
...envelopeTail,
|
|
2001
|
+
operation: z3.string(),
|
|
2002
|
+
target: z3.string().nullable()
|
|
2003
|
+
};
|
|
2004
|
+
var OperationEventSchema = z3.discriminatedUnion("event", [
|
|
2005
|
+
z3.object({
|
|
2006
|
+
...operationShared,
|
|
2007
|
+
event: z3.literal("completed"),
|
|
2008
|
+
result: OperationResultSchema,
|
|
2009
|
+
error_class: z3.string().nullable(),
|
|
2010
|
+
field_names: z3.array(z3.string().max(CUSTOM_FIELD_NAME_MAX_LENGTH)).max(CUSTOM_EVENT_MAX_FIELDS).optional()
|
|
2011
|
+
}).strict()
|
|
2012
|
+
]);
|
|
2013
|
+
var UsageUnitsSchema = z3.object({
|
|
2014
|
+
input: z3.number().nonnegative().nullable(),
|
|
2015
|
+
output: z3.number().nonnegative().nullable(),
|
|
2016
|
+
cache: z3.number().nonnegative().nullable()
|
|
2017
|
+
}).strict();
|
|
2018
|
+
var usageShared = {
|
|
2019
|
+
meta: HeaderMetaSchema,
|
|
2020
|
+
subject: SubjectSchema,
|
|
2021
|
+
kind: z3.literal("usage"),
|
|
2022
|
+
...envelopeTail,
|
|
2023
|
+
model: z3.string().nullable(),
|
|
2024
|
+
source: z3.string(),
|
|
2025
|
+
semantics: z3.enum(["cumulative", "delta"])
|
|
2026
|
+
};
|
|
2027
|
+
var UsageEventSchema = z3.discriminatedUnion("event", [
|
|
2028
|
+
z3.object({
|
|
2029
|
+
...usageShared,
|
|
2030
|
+
event: z3.literal("observed"),
|
|
2031
|
+
units: UsageUnitsSchema,
|
|
2032
|
+
unknown_reason: z3.string().nullable()
|
|
2033
|
+
}).strict()
|
|
2034
|
+
]);
|
|
2035
|
+
var RoleAttemptOutcomeSchema = z3.enum([
|
|
2036
|
+
"completed",
|
|
2037
|
+
"incomplete",
|
|
2038
|
+
"infrastructure_failed",
|
|
2039
|
+
"cancelled",
|
|
2040
|
+
"timed_out",
|
|
2041
|
+
"capability_refused"
|
|
2042
|
+
]);
|
|
2043
|
+
var roleAttemptShared = {
|
|
2044
|
+
meta: HeaderMetaSchema,
|
|
2045
|
+
subject: SubjectSchema,
|
|
2046
|
+
kind: z3.literal("role_attempt"),
|
|
2047
|
+
...envelopeTail,
|
|
2048
|
+
actor: z3.string().nullable(),
|
|
2049
|
+
attempt: z3.number().int().nullable(),
|
|
2050
|
+
effect_id: z3.string(),
|
|
2051
|
+
model: z3.string().nullable()
|
|
2052
|
+
};
|
|
2053
|
+
var RoleAttemptEventSchema = z3.discriminatedUnion("event", [
|
|
2054
|
+
z3.object({
|
|
2055
|
+
...roleAttemptShared,
|
|
2056
|
+
event: z3.literal("attempted"),
|
|
2057
|
+
outcome: RoleAttemptOutcomeSchema,
|
|
2058
|
+
usage: dispatchUsageField
|
|
2059
|
+
}).strict()
|
|
2060
|
+
]);
|
|
2061
|
+
var handoffShared = {
|
|
2062
|
+
meta: HeaderMetaSchema,
|
|
2063
|
+
subject: SubjectSchema,
|
|
2064
|
+
kind: z3.literal("handoff"),
|
|
2065
|
+
...envelopeTail,
|
|
2066
|
+
class: z3.enum(["authority", "strategy", "product"]),
|
|
2067
|
+
reason: z3.string()
|
|
2068
|
+
};
|
|
2069
|
+
var HandoffEventSchema = z3.discriminatedUnion("event", [
|
|
2070
|
+
z3.object({
|
|
2071
|
+
...handoffShared,
|
|
2072
|
+
event: z3.literal("raised"),
|
|
2073
|
+
requested_decision: z3.string().nullable()
|
|
2074
|
+
}).strict(),
|
|
2075
|
+
z3.object({
|
|
2076
|
+
...handoffShared,
|
|
2077
|
+
event: z3.literal("resolved"),
|
|
2078
|
+
resolution: z3.string().nullable(),
|
|
2079
|
+
resolved_by: z3.string().nullable()
|
|
2080
|
+
}).strict()
|
|
2081
|
+
]);
|
|
2082
|
+
var EffectTargetSchema = z3.object({
|
|
2083
|
+
kind: z3.string(),
|
|
2084
|
+
ref: z3.string()
|
|
2085
|
+
}).strict();
|
|
2086
|
+
var effectShared = {
|
|
2087
|
+
meta: HeaderMetaSchema,
|
|
2088
|
+
subject: SubjectSchema,
|
|
2089
|
+
kind: z3.literal("effect"),
|
|
2090
|
+
...envelopeTail,
|
|
2091
|
+
effect_id: z3.string(),
|
|
2092
|
+
target: EffectTargetSchema
|
|
2093
|
+
};
|
|
2094
|
+
var EffectEventSchema = z3.discriminatedUnion("event", [
|
|
2095
|
+
z3.object({ ...effectShared, event: z3.literal("attempted") }).strict(),
|
|
2096
|
+
z3.object({ ...effectShared, event: z3.literal("observed"), outcome: z3.enum(["success", "failure", "uncertain"]) }).strict(),
|
|
2097
|
+
z3.object({ ...effectShared, event: z3.literal("verified"), outcome: z3.enum(["success", "failure", "uncertain"]) }).strict()
|
|
2098
|
+
]);
|
|
2099
|
+
var CustomFieldValueSchema = z3.union([z3.string().max(CUSTOM_TEXT_MAX_LENGTH), z3.number().finite(), z3.boolean()]);
|
|
2100
|
+
var customShared = {
|
|
2101
|
+
meta: HeaderMetaSchema,
|
|
2102
|
+
subject: SubjectSchema,
|
|
2103
|
+
kind: z3.literal("custom"),
|
|
2104
|
+
...envelopeTail
|
|
2105
|
+
};
|
|
2106
|
+
var CustomEventSchema = z3.discriminatedUnion("event", [
|
|
2107
|
+
z3.object({
|
|
2108
|
+
...customShared,
|
|
2109
|
+
event: z3.literal("recorded"),
|
|
2110
|
+
name: z3.string().max(CUSTOM_EVENT_NAME_MAX_LENGTH).regex(CUSTOM_EVENT_NAME_PATTERN),
|
|
2111
|
+
fields: z3.record(z3.string().max(CUSTOM_FIELD_NAME_MAX_LENGTH).regex(CUSTOM_FIELD_NAME_PATTERN), CustomFieldValueSchema).refine((f) => Object.keys(f).length <= CUSTOM_EVENT_MAX_FIELDS, {
|
|
2112
|
+
message: `custom: at most ${CUSTOM_EVENT_MAX_FIELDS} fields`
|
|
2113
|
+
})
|
|
2114
|
+
}).strict()
|
|
2115
|
+
]);
|
|
2116
|
+
var LogEventSchema = z3.union([
|
|
2117
|
+
DispatchEventSchema,
|
|
2118
|
+
DevReviewLoopEventSchema,
|
|
2119
|
+
ForgeWriteEventSchema,
|
|
2120
|
+
GateEventSchema,
|
|
2121
|
+
OperationEventSchema,
|
|
2122
|
+
UsageEventSchema,
|
|
2123
|
+
RoleAttemptEventSchema,
|
|
2124
|
+
HandoffEventSchema,
|
|
2125
|
+
EffectEventSchema,
|
|
2126
|
+
CustomEventSchema
|
|
2127
|
+
]);
|
|
2128
|
+
// ../../packages/aeg-core/src/log/envelope.ts
|
|
2129
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
2130
|
+
function isRole(value) {
|
|
2131
|
+
return value !== undefined && ROLE_VALUES.includes(value);
|
|
2132
|
+
}
|
|
2133
|
+
function actorIdFromEnv(role) {
|
|
2134
|
+
return role === undefined || role === "" ? null : role;
|
|
2135
|
+
}
|
|
2136
|
+
function lineageFieldFromEnv(value) {
|
|
2137
|
+
return value === undefined || value === "" ? null : value;
|
|
2138
|
+
}
|
|
2139
|
+
function attemptFromEnv(value) {
|
|
2140
|
+
if (value === undefined || value === "")
|
|
2141
|
+
return null;
|
|
2142
|
+
const n = Number(value);
|
|
2143
|
+
return Number.isInteger(n) ? n : null;
|
|
2144
|
+
}
|
|
2145
|
+
function provenanceFor(input) {
|
|
2146
|
+
if (input.provenance)
|
|
2147
|
+
return input.provenance;
|
|
2148
|
+
if (issueFromTask(input.env.task) === null && (input.branchIssue ?? null) !== null)
|
|
2149
|
+
return "unavailable";
|
|
2150
|
+
if (input.env.role || input.env.task)
|
|
2151
|
+
return "env_correlated";
|
|
2152
|
+
return "unavailable";
|
|
2153
|
+
}
|
|
2154
|
+
function issueFromTask(task) {
|
|
2155
|
+
if (task === undefined || task === "")
|
|
2156
|
+
return null;
|
|
2157
|
+
const n = Number(task);
|
|
2158
|
+
return Number.isInteger(n) ? n : null;
|
|
2159
|
+
}
|
|
2160
|
+
function roundFromEnv(round) {
|
|
2161
|
+
if (round === undefined || round === "")
|
|
2162
|
+
return;
|
|
2163
|
+
const n = Number(round);
|
|
2164
|
+
return Number.isInteger(n) ? n : undefined;
|
|
2165
|
+
}
|
|
2166
|
+
function prFromEnv(pr) {
|
|
2167
|
+
if (pr === undefined || pr === "")
|
|
2168
|
+
return;
|
|
2169
|
+
const n = Number(pr);
|
|
2170
|
+
return Number.isInteger(n) && n > 0 ? n : undefined;
|
|
2171
|
+
}
|
|
2172
|
+
function buildHeader(input) {
|
|
2173
|
+
const role = isRole(input.env.role) ? input.env.role : "unattributed";
|
|
2174
|
+
const round = roundFromEnv(input.env.round);
|
|
2175
|
+
const pr = prFromEnv(input.env.pr);
|
|
2176
|
+
const subject = {
|
|
2177
|
+
issue: issueFromTask(input.env.task) ?? input.branchIssue ?? null,
|
|
2178
|
+
role,
|
|
2179
|
+
...round !== undefined ? { round } : {},
|
|
2180
|
+
...pr !== undefined ? { pr } : {},
|
|
2181
|
+
...input.subject ?? {}
|
|
2182
|
+
};
|
|
2183
|
+
const issue = subject.issue;
|
|
2184
|
+
return {
|
|
2185
|
+
meta: {
|
|
2186
|
+
schema: 4,
|
|
2187
|
+
ts: input.now.toISOString(),
|
|
2188
|
+
run_id: input.runId,
|
|
2189
|
+
seq: input.seq,
|
|
2190
|
+
repo: input.repo,
|
|
2191
|
+
vinaya: input.vinaya,
|
|
2192
|
+
doctrine: input.doctrine,
|
|
2193
|
+
host: input.host,
|
|
2194
|
+
machine: createHash2("sha256").update(input.hostname).digest("hex"),
|
|
2195
|
+
event_id: input.eventId,
|
|
2196
|
+
process_id: input.processId,
|
|
2197
|
+
actor_id: actorIdFromEnv(input.env.role),
|
|
2198
|
+
lineage: {
|
|
2199
|
+
run: lineageFieldFromEnv(input.env.run),
|
|
2200
|
+
attempt: attemptFromEnv(input.env.attempt),
|
|
2201
|
+
parent: lineageFieldFromEnv(input.env.parent)
|
|
2202
|
+
},
|
|
2203
|
+
input_versions: {
|
|
2204
|
+
manifest_version: input.inputVersions?.manifestVersion ?? null,
|
|
2205
|
+
objectives_version: input.inputVersions?.objectivesVersion ?? null,
|
|
2206
|
+
brief_hash: input.inputVersions?.briefHash ?? null,
|
|
2207
|
+
ruling_ordinal: input.inputVersions?.rulingOrdinal ?? null,
|
|
2208
|
+
pause_bound_ruling: input.inputVersions?.pauseBoundRuling ?? null,
|
|
2209
|
+
policy_digest: input.inputVersions?.policyDigest ?? null
|
|
2210
|
+
},
|
|
2211
|
+
provenance: provenanceFor(input),
|
|
2212
|
+
work: {
|
|
2213
|
+
ref: lineageFieldFromEnv(input.env.workRef) ?? (issue === null ? null : String(issue)),
|
|
2214
|
+
repo: input.repo,
|
|
2215
|
+
change: pr === undefined ? null : String(pr),
|
|
2216
|
+
revision: input.revision ?? null
|
|
2217
|
+
},
|
|
2218
|
+
flow: {
|
|
2219
|
+
id: lineageFieldFromEnv(input.env.flow) ?? "vinaya",
|
|
2220
|
+
version: lineageFieldFromEnv(input.env.flowVersion)
|
|
2221
|
+
},
|
|
2222
|
+
runtime: lineageFieldFromEnv(input.env.runtime),
|
|
2223
|
+
process: {
|
|
2224
|
+
id: lineageFieldFromEnv(input.env.processId) ?? "vinaya",
|
|
2225
|
+
version: lineageFieldFromEnv(input.env.processVersion),
|
|
2226
|
+
digest: lineageFieldFromEnv(input.env.processDigest)
|
|
2227
|
+
},
|
|
2228
|
+
runner: {
|
|
2229
|
+
id: lineageFieldFromEnv(input.env.runnerId) ?? "standalone",
|
|
2230
|
+
version: lineageFieldFromEnv(input.env.runnerVersion)
|
|
2231
|
+
},
|
|
2232
|
+
source: lineageFieldFromEnv(input.env.source)
|
|
2233
|
+
},
|
|
2234
|
+
subject
|
|
2235
|
+
};
|
|
2236
|
+
}
|
|
2237
|
+
// ../../packages/aeg-core/src/log/redact.ts
|
|
2238
|
+
var GITHUB_TOKEN_PATTERN = /\b(?:gho_|ghp_|ghs_|ghu_|ghr_|github_pat_)[A-Za-z0-9_]+\b/g;
|
|
2239
|
+
var CLASSIC_GITHUB_PAT_PATTERN = /\b((?:token|GITHUB_TOKEN|PAT|api[_-]?key|api[_-]?token)\s*[:=]\s*)[a-f0-9]{40}\b/gi;
|
|
2240
|
+
var BEARER_TOKEN_PATTERN = /\bBearer\s+\S+/g;
|
|
2241
|
+
var AWS_ACCESS_KEY_PATTERN = /\bAKIA[0-9A-Z]{16}\b/g;
|
|
2242
|
+
var SLACK_TOKEN_PATTERN = /\bxox[baprs]-[0-9A-Za-z-]+\b/g;
|
|
2243
|
+
var STRIPE_KEY_PATTERN = /\b(?:sk|pk|rk)_(?:live|test)_[0-9A-Za-z]{10,}\b/g;
|
|
2244
|
+
var ANTHROPIC_KEY_PATTERN = /\bsk-ant-[A-Za-z0-9_-]{20,}\b/g;
|
|
2245
|
+
var OPENAI_KEY_PATTERN = /\bsk-(?!ant-)[A-Za-z0-9]{20,}\b/g;
|
|
2246
|
+
var NPM_TOKEN_PATTERN = /\bnpm_[A-Za-z0-9]{36}\b/g;
|
|
2247
|
+
var JWT_PATTERN = /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\b/g;
|
|
2248
|
+
var PEM_BLOCK_PATTERN = /-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?-----END [A-Z ]*PRIVATE KEY-----/g;
|
|
2249
|
+
var BASIC_AUTH_URL_PATTERN = /(https?:\/\/)[^/\s:@]+:[^/\s@]+@/g;
|
|
2250
|
+
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;
|
|
2251
|
+
function redactString(value, home) {
|
|
2252
|
+
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>");
|
|
2253
|
+
if (home.length > 0 && out.startsWith(home)) {
|
|
2254
|
+
const rest = out.slice(home.length);
|
|
2255
|
+
if (rest === "" || rest.startsWith("/"))
|
|
2256
|
+
out = `~${rest}`;
|
|
2257
|
+
}
|
|
2258
|
+
return out;
|
|
2259
|
+
}
|
|
2260
|
+
function redact(value, home) {
|
|
2261
|
+
if (typeof value === "string")
|
|
2262
|
+
return redactString(value, home);
|
|
2263
|
+
if (Array.isArray(value))
|
|
2264
|
+
return value.map((v) => redact(v, home));
|
|
2265
|
+
if (value !== null && typeof value === "object") {
|
|
2266
|
+
const out = {};
|
|
2267
|
+
for (const [k, v] of Object.entries(value)) {
|
|
2268
|
+
out[k] = redact(v, home);
|
|
2269
|
+
}
|
|
2270
|
+
return out;
|
|
2271
|
+
}
|
|
2272
|
+
return value;
|
|
2273
|
+
}
|
|
2274
|
+
// ../../packages/aeg-core/src/log/store.ts
|
|
2275
|
+
var KNOWN_SCHEMA_VERSIONS = [1, 2, 3, 4];
|
|
2276
|
+
function metaOf(obj) {
|
|
2277
|
+
if (obj === null || typeof obj !== "object")
|
|
2278
|
+
return null;
|
|
2279
|
+
const meta = obj.meta;
|
|
2280
|
+
if (meta === null || typeof meta !== "object")
|
|
2281
|
+
return null;
|
|
2282
|
+
return meta;
|
|
2283
|
+
}
|
|
2284
|
+
function recordIdentity(obj) {
|
|
2285
|
+
const meta = metaOf(obj);
|
|
2286
|
+
if (meta === null)
|
|
2287
|
+
return null;
|
|
2288
|
+
const eventId = meta.event_id;
|
|
2289
|
+
if (typeof eventId === "string" && eventId.length > 0)
|
|
2290
|
+
return eventId;
|
|
2291
|
+
const runId = meta.run_id;
|
|
2292
|
+
const seq = meta.seq;
|
|
2293
|
+
if (typeof runId === "string" && runId.length > 0 && typeof seq === "number" && Number.isInteger(seq)) {
|
|
2294
|
+
return `${runId}:${seq}`;
|
|
2295
|
+
}
|
|
2296
|
+
return null;
|
|
2297
|
+
}
|
|
2298
|
+
function schemaVersionOf(obj) {
|
|
2299
|
+
const meta = metaOf(obj);
|
|
2300
|
+
const schema = meta?.schema;
|
|
2301
|
+
return typeof schema === "number" ? schema : null;
|
|
2302
|
+
}
|
|
2303
|
+
function isKnownSchema(version) {
|
|
2304
|
+
return version !== null && KNOWN_SCHEMA_VERSIONS.includes(version);
|
|
2305
|
+
}
|
|
2306
|
+
function classifyStoredLine(raw, home) {
|
|
2307
|
+
let obj;
|
|
2308
|
+
try {
|
|
2309
|
+
obj = JSON.parse(raw);
|
|
2310
|
+
} catch {
|
|
2311
|
+
return { status: "invalid", identity: null, raw, reason: "not valid JSON" };
|
|
2312
|
+
}
|
|
2313
|
+
const version = schemaVersionOf(obj);
|
|
2314
|
+
if (version === null) {
|
|
2315
|
+
return { status: "invalid", identity: recordIdentity(obj), raw, reason: "no readable meta.schema" };
|
|
2316
|
+
}
|
|
2317
|
+
if (!isKnownSchema(version)) {
|
|
2318
|
+
return {
|
|
2319
|
+
status: "unknown_version",
|
|
2320
|
+
identity: recordIdentity(obj),
|
|
2321
|
+
schema: version,
|
|
2322
|
+
raw,
|
|
2323
|
+
reason: `schema version ${version} is not one this build validates (${KNOWN_SCHEMA_VERSIONS.join(", ")}) — kept for diagnosis`
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
const result = LogEventSchema.safeParse(obj);
|
|
2327
|
+
if (!result.success) {
|
|
2328
|
+
return {
|
|
2329
|
+
status: "invalid",
|
|
2330
|
+
identity: recordIdentity(obj),
|
|
2331
|
+
raw,
|
|
2332
|
+
reason: result.error.issues[0]?.message ?? "schema violation"
|
|
2333
|
+
};
|
|
2334
|
+
}
|
|
2335
|
+
const event = result.data;
|
|
2336
|
+
const identity = recordIdentity(event);
|
|
2337
|
+
if (identity === null) {
|
|
2338
|
+
return { status: "invalid", identity: null, raw, reason: "valid event with no derivable identity" };
|
|
2339
|
+
}
|
|
2340
|
+
const redacted = redact(event, home);
|
|
2341
|
+
const provenance = version >= 2 ? event.meta.provenance ?? null : null;
|
|
2342
|
+
return {
|
|
2343
|
+
status: "ok",
|
|
2344
|
+
identity,
|
|
2345
|
+
runId: event.meta.run_id,
|
|
2346
|
+
seq: event.meta.seq,
|
|
2347
|
+
schema: version,
|
|
2348
|
+
provenance,
|
|
2349
|
+
event,
|
|
2350
|
+
postLine: JSON.stringify(redacted)
|
|
2351
|
+
};
|
|
2352
|
+
}
|
|
2353
|
+
// ../../packages/aeg-core/src/control-store/records.ts
|
|
2354
|
+
import { z as z4 } from "zod";
|
|
2355
|
+
var isoTimestamp = z4.string().min(1);
|
|
2356
|
+
var taskId = z4.number().int().positive();
|
|
2357
|
+
var epochNumber = z4.number().int().nonnegative();
|
|
2358
|
+
var RunRecordSchema = z4.object({
|
|
2359
|
+
version: z4.literal(1),
|
|
2360
|
+
kind: z4.literal("run"),
|
|
2361
|
+
task: taskId,
|
|
2362
|
+
runId: z4.string().min(1),
|
|
2363
|
+
pid: z4.number().int().positive(),
|
|
2364
|
+
host: z4.string().min(1),
|
|
2365
|
+
startedAt: isoTimestamp,
|
|
2366
|
+
childStartedAt: z4.string().min(1).nullable().optional(),
|
|
2367
|
+
childCommand: z4.string().min(1).nullable().optional()
|
|
2368
|
+
}).strict();
|
|
2369
|
+
var InputRecordSchema = z4.object({
|
|
2370
|
+
version: z4.literal(1),
|
|
2371
|
+
kind: z4.literal("input"),
|
|
2372
|
+
task: taskId,
|
|
2373
|
+
runId: z4.string().min(1),
|
|
2374
|
+
source: z4.union([z4.literal("fresh"), z4.literal("resume")]),
|
|
2375
|
+
pr: z4.number().int().positive().nullable(),
|
|
2376
|
+
round: z4.number().int().nonnegative(),
|
|
2377
|
+
recordedAt: isoTimestamp
|
|
2378
|
+
}).strict();
|
|
2379
|
+
var OwnershipRecordSchema = z4.object({
|
|
2380
|
+
version: z4.literal(1),
|
|
2381
|
+
kind: z4.literal("ownership"),
|
|
2382
|
+
task: taskId,
|
|
2383
|
+
epoch: epochNumber,
|
|
2384
|
+
ownerId: z4.string().min(1),
|
|
2385
|
+
pid: z4.number().int().positive(),
|
|
2386
|
+
host: z4.string().min(1),
|
|
2387
|
+
acquiredAt: isoTimestamp
|
|
2388
|
+
}).strict();
|
|
2389
|
+
var TransitionRecordSchema = z4.object({
|
|
2390
|
+
version: z4.literal(1),
|
|
2391
|
+
kind: z4.literal("transition"),
|
|
2392
|
+
task: taskId,
|
|
2393
|
+
epoch: epochNumber,
|
|
2394
|
+
seq: z4.number().int().nonnegative(),
|
|
2395
|
+
from: z4.string().min(1),
|
|
2396
|
+
to: z4.string().min(1),
|
|
2397
|
+
detail: z4.string().optional(),
|
|
2398
|
+
at: isoTimestamp
|
|
2399
|
+
}).strict();
|
|
2400
|
+
var ManifestRecordSchema = z4.object({
|
|
2401
|
+
version: z4.literal(1),
|
|
2402
|
+
kind: z4.literal("manifest"),
|
|
2403
|
+
task: taskId,
|
|
2404
|
+
round: epochNumber,
|
|
2405
|
+
repository: z4.string().min(1),
|
|
2406
|
+
pr: z4.number().int().positive(),
|
|
2407
|
+
branch: z4.string().min(1),
|
|
2408
|
+
baseSha: z4.string().min(1).nullable(),
|
|
2409
|
+
headSha: z4.string().min(1),
|
|
2410
|
+
briefHash: z4.string().min(1).nullable(),
|
|
2411
|
+
objectivesVersion: z4.string().min(1).nullable(),
|
|
2412
|
+
rulingOrdinal: epochNumber,
|
|
2413
|
+
manifestVersion: z4.literal(2).optional(),
|
|
2414
|
+
pauseBoundRuling: z4.object({
|
|
2415
|
+
rulingId: z4.string().min(1),
|
|
2416
|
+
pauseId: z4.string().min(1),
|
|
2417
|
+
contentDigest: z4.string().min(1)
|
|
2418
|
+
}).strict().nullable().optional(),
|
|
2419
|
+
policyDigest: z4.string().min(1),
|
|
2420
|
+
recordedAt: isoTimestamp
|
|
2421
|
+
}).strict();
|
|
2422
|
+
var roundHeadIdentity = z4.object({ round: z4.number().int().positive(), head: z4.string().min(1) }).strict();
|
|
2423
|
+
var LoopBudgetsSchema = z4.object({
|
|
2424
|
+
mechanicalRetries: z4.number().int().nonnegative(),
|
|
2425
|
+
reviewRounds: z4.number().int().nonnegative(),
|
|
2426
|
+
infrastructureRetries: z4.number().int().nonnegative()
|
|
2427
|
+
}).strict();
|
|
2428
|
+
var LoopStateRecordSchema = z4.object({
|
|
2429
|
+
version: z4.literal(1),
|
|
2430
|
+
kind: z4.literal("loop_state"),
|
|
2431
|
+
task: taskId,
|
|
2432
|
+
round: z4.number().int().positive(),
|
|
2433
|
+
phase: z4.string().min(1),
|
|
2434
|
+
pauseReason: z4.string().min(1).nullable(),
|
|
2435
|
+
budgets: LoopBudgetsSchema,
|
|
2436
|
+
heldResult: roundHeadIdentity.nullable(),
|
|
2437
|
+
deliveredFindings: roundHeadIdentity.nullable(),
|
|
2438
|
+
repeatMemory: z4.object({
|
|
2439
|
+
blockingFindings: z4.array(z4.string()),
|
|
2440
|
+
lastFailure: z4.object({ signature: z4.string(), message: z4.string(), developerAttemptedSince: z4.boolean().optional() }).nullable()
|
|
2441
|
+
}).strict().optional(),
|
|
2442
|
+
developerHandoff: z4.object({
|
|
2443
|
+
findings: z4.array(z4.object({ id: z4.string().min(1), description: z4.string().min(1) }).strict()),
|
|
2444
|
+
failingChecks: z4.array(z4.string().min(1))
|
|
2445
|
+
}).strict().optional(),
|
|
2446
|
+
publicationExpectedBase: z4.string().regex(/^[0-9a-f]{40}$/).nullable().optional(),
|
|
2447
|
+
taskStartedAt: isoTimestamp.optional(),
|
|
2448
|
+
phaseMs: z4.record(z4.string(), z4.number().nonnegative()).optional(),
|
|
2449
|
+
recordedAt: isoTimestamp
|
|
2450
|
+
}).strict();
|
|
2451
|
+
var EffectRecordSchema = z4.object({
|
|
2452
|
+
version: z4.literal(1),
|
|
2453
|
+
kind: z4.literal("effect"),
|
|
2454
|
+
task: taskId,
|
|
2455
|
+
key: z4.string().min(1),
|
|
2456
|
+
operation: z4.string().min(1),
|
|
2457
|
+
target: z4.string().min(1),
|
|
2458
|
+
inputVersion: z4.number().int().nonnegative(),
|
|
2459
|
+
payloadDigest: z4.string().min(1),
|
|
2460
|
+
status: z4.union([z4.literal("started"), z4.literal("verified"), z4.literal("uncertain")]),
|
|
2461
|
+
url: z4.string().optional(),
|
|
2462
|
+
recordedAt: isoTimestamp
|
|
2463
|
+
}).strict();
|
|
2464
|
+
var EscalationRecordSchema = z4.object({
|
|
2465
|
+
version: z4.literal(1),
|
|
2466
|
+
kind: z4.literal("escalation"),
|
|
2467
|
+
task: taskId,
|
|
2468
|
+
escalationId: z4.string().min(1),
|
|
2469
|
+
round: epochNumber,
|
|
2470
|
+
head: z4.string().min(1),
|
|
2471
|
+
branch: z4.string().min(1),
|
|
2472
|
+
pr: z4.number().int().positive().nullable(),
|
|
2473
|
+
runId: z4.string().min(1),
|
|
2474
|
+
pid: z4.number().int().positive(),
|
|
2475
|
+
host: z4.string().min(1),
|
|
2476
|
+
agent: z4.string().min(1).optional(),
|
|
2477
|
+
reason: z4.string().min(1),
|
|
2478
|
+
detail: z4.string().optional(),
|
|
2479
|
+
evidence: z4.string().optional(),
|
|
2480
|
+
attemptedRecovery: z4.string().min(1),
|
|
2481
|
+
requestedDecision: z4.string().min(1),
|
|
2482
|
+
recipient: z4.string().min(1),
|
|
2483
|
+
briefHash: z4.string().min(1).nullable(),
|
|
2484
|
+
objectivesVersion: z4.string().min(1).nullable(),
|
|
2485
|
+
rulingOrdinal: epochNumber,
|
|
2486
|
+
policyDigest: z4.string().min(1),
|
|
2487
|
+
recordedAt: isoTimestamp
|
|
2488
|
+
}).strict();
|
|
2489
|
+
var ResolutionRecordSchema = z4.object({
|
|
2490
|
+
version: z4.literal(1),
|
|
2491
|
+
kind: z4.literal("resolution"),
|
|
2492
|
+
task: taskId,
|
|
2493
|
+
escalationId: z4.string().min(1),
|
|
2494
|
+
decision: z4.union([z4.literal("resume"), z4.literal("cancel")]),
|
|
2495
|
+
authenticatedBy: z4.string().min(1),
|
|
2496
|
+
authenticatedFrom: z4.string().min(1),
|
|
2497
|
+
consumedAt: isoTimestamp
|
|
2498
|
+
}).strict();
|
|
2499
|
+
var ExecutionRoundMirrorRecordSchema = z4.object({
|
|
2500
|
+
version: z4.literal(1),
|
|
2501
|
+
kind: z4.literal("execution_round"),
|
|
2502
|
+
task: taskId,
|
|
2503
|
+
repository: z4.string().min(1),
|
|
2504
|
+
threadId: z4.string().min(1),
|
|
2505
|
+
checkpointId: z4.string().min(1),
|
|
2506
|
+
round: z4.number().int().positive(),
|
|
2507
|
+
recordedAt: isoTimestamp
|
|
2508
|
+
}).strict();
|
|
2509
|
+
// ../../packages/aeg-core/src/control-store/local.ts
|
|
2510
|
+
import {
|
|
2511
|
+
closeSync as closeSync3,
|
|
2512
|
+
constants as fsConstants2,
|
|
2513
|
+
existsSync as existsSync3,
|
|
2514
|
+
fsyncSync as fsyncSync2,
|
|
2515
|
+
linkSync,
|
|
2516
|
+
lstatSync,
|
|
2517
|
+
mkdirSync as mkdirSync3,
|
|
2518
|
+
openSync as openSync3,
|
|
2519
|
+
readdirSync as readdirSync2,
|
|
2520
|
+
readFileSync as readFileSync4,
|
|
2521
|
+
renameSync as renameSync2,
|
|
2522
|
+
statSync,
|
|
2523
|
+
unlinkSync,
|
|
2524
|
+
writeSync as writeSync2
|
|
2525
|
+
} from "node:fs";
|
|
2526
|
+
import { dirname as dirname3, join as join3, resolve, sep } from "node:path";
|
|
2527
|
+
function isErrnoException(err, code) {
|
|
2528
|
+
return typeof err === "object" && err !== null && err.code === code;
|
|
2529
|
+
}
|
|
2530
|
+
function isTrustedDirStat(stat, ownUid, trustedOverflowUid) {
|
|
2531
|
+
if (typeof ownUid !== "number")
|
|
2532
|
+
return true;
|
|
2533
|
+
if (stat.uid !== ownUid && stat.uid !== 0 && stat.uid !== trustedOverflowUid)
|
|
2534
|
+
return false;
|
|
2535
|
+
const worldWritable = (stat.mode & 2) !== 0;
|
|
2536
|
+
const sticky = (stat.mode & 512) !== 0;
|
|
2537
|
+
return !worldWritable || sticky;
|
|
2538
|
+
}
|
|
2539
|
+
function currentUid() {
|
|
2540
|
+
return typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
2541
|
+
}
|
|
2542
|
+
function uidMapLeavesRootUnmapped(uidMap) {
|
|
2543
|
+
const lines = uidMap.split(`
|
|
2544
|
+
`).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
2545
|
+
if (lines.length === 0)
|
|
2546
|
+
return false;
|
|
2547
|
+
for (const line of lines) {
|
|
2548
|
+
const fields = line.split(/\s+/);
|
|
2549
|
+
if (fields.length !== 3 || !fields.every((field) => /^\d+$/.test(field)))
|
|
2550
|
+
return false;
|
|
2551
|
+
const inside = Number(fields[0]);
|
|
2552
|
+
const count = Number(fields[2]);
|
|
2553
|
+
if (inside === 0 && count > 0)
|
|
2554
|
+
return false;
|
|
2555
|
+
}
|
|
2556
|
+
return true;
|
|
2557
|
+
}
|
|
2558
|
+
function readTrustedOverflowUid(readFile) {
|
|
2559
|
+
try {
|
|
2560
|
+
if (!uidMapLeavesRootUnmapped(readFile("/proc/self/uid_map")))
|
|
2561
|
+
return;
|
|
2562
|
+
const overflow = readFile("/proc/sys/kernel/overflowuid").trim();
|
|
2563
|
+
return /^\d+$/.test(overflow) ? Number(overflow) : undefined;
|
|
2564
|
+
} catch {
|
|
2565
|
+
return;
|
|
2566
|
+
}
|
|
2567
|
+
}
|
|
2568
|
+
var cachedTrustedOverflowUid;
|
|
2569
|
+
function processTrustedOverflowUid() {
|
|
2570
|
+
cachedTrustedOverflowUid ??= { value: readTrustedOverflowUid((path) => readFileSync4(path, "utf8")) };
|
|
2571
|
+
return cachedTrustedOverflowUid.value;
|
|
2572
|
+
}
|
|
2573
|
+
function isAtOrBelowTrustedRoot(index, rootSegmentCount) {
|
|
2574
|
+
return index >= rootSegmentCount - 1;
|
|
2575
|
+
}
|
|
2576
|
+
function segmentTrustedOverflowUid(index, rootSegmentCount, trustedOverflowUid) {
|
|
2577
|
+
return isAtOrBelowTrustedRoot(index, rootSegmentCount) ? undefined : trustedOverflowUid;
|
|
2578
|
+
}
|
|
2579
|
+
function mkdirNoSymlinks(dir, mode, trustedRoot) {
|
|
2580
|
+
const absolute = resolve(dir);
|
|
2581
|
+
const rootSegments = resolve(trustedRoot).split(sep).filter((s) => s.length > 0);
|
|
2582
|
+
const segments = absolute.split(sep).filter((s) => s.length > 0);
|
|
2583
|
+
const ownUid = currentUid();
|
|
2584
|
+
const trustedOverflowUid = typeof ownUid === "number" ? processTrustedOverflowUid() : undefined;
|
|
2585
|
+
let current = absolute.startsWith(sep) ? sep : "";
|
|
2586
|
+
segments.forEach((segment, index) => {
|
|
2587
|
+
current = current === "" || current === sep ? `${current}${segment}` : `${current}${sep}${segment}`;
|
|
2588
|
+
const atOrBelowTrustedRoot = isAtOrBelowTrustedRoot(index, rootSegments.length);
|
|
2589
|
+
const overflowUid = segmentTrustedOverflowUid(index, rootSegments.length, trustedOverflowUid);
|
|
2590
|
+
try {
|
|
2591
|
+
mkdirSync3(current, { mode });
|
|
2592
|
+
} catch (err) {
|
|
2593
|
+
if (!isErrnoException(err, "EEXIST"))
|
|
2594
|
+
throw err;
|
|
2595
|
+
}
|
|
2596
|
+
const stat = lstatSync(current);
|
|
2597
|
+
if (stat.isSymbolicLink()) {
|
|
2598
|
+
if (atOrBelowTrustedRoot) {
|
|
2599
|
+
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)`);
|
|
2600
|
+
}
|
|
2601
|
+
let real;
|
|
2602
|
+
try {
|
|
2603
|
+
real = statSync(current);
|
|
2604
|
+
} catch (err) {
|
|
2605
|
+
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)}`);
|
|
2606
|
+
}
|
|
2607
|
+
if (!real.isDirectory()) {
|
|
2608
|
+
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`);
|
|
2609
|
+
}
|
|
2610
|
+
if (!isTrustedDirStat(real, ownUid, overflowUid)) {
|
|
2611
|
+
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`);
|
|
2612
|
+
}
|
|
2613
|
+
return;
|
|
2614
|
+
}
|
|
2615
|
+
if (!stat.isDirectory()) {
|
|
2616
|
+
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)`);
|
|
2617
|
+
}
|
|
2618
|
+
if (!isTrustedDirStat(stat, ownUid, overflowUid)) {
|
|
2619
|
+
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`);
|
|
2620
|
+
}
|
|
2621
|
+
});
|
|
2622
|
+
}
|
|
2623
|
+
var CONTROL_AREA_DIRNAME = "control";
|
|
2624
|
+
// src/lib/config.ts
|
|
2625
|
+
import { execFile as execFile4, execFileSync as execFileSync4 } from "node:child_process";
|
|
2626
|
+
import { promisify as promisify4 } from "node:util";
|
|
2627
|
+
import { existsSync as existsSync4, lstatSync as lstatSync2, mkdirSync as mkdirSync4, readFileSync as readFileSync5, realpathSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2628
|
+
import { homedir } from "node:os";
|
|
2629
|
+
import { basename, dirname as dirname4, isAbsolute as isAbsolute2, join as join4, resolve as resolve2 } from "node:path";
|
|
2630
|
+
import { z as z6 } from "zod";
|
|
2631
|
+
|
|
2632
|
+
// src/checks/contract.ts
|
|
2633
|
+
var CHECK_SCHEMA_VERSION = 1;
|
|
2634
|
+
function emitCheckError(error) {
|
|
2635
|
+
process.stderr.write(`${JSON.stringify(error)}
|
|
2636
|
+
`);
|
|
2637
|
+
}
|
|
2638
|
+
|
|
2639
|
+
// src/lib/agent-vendors.ts
|
|
2640
|
+
var AGENT_VENDORS = ["skills", "claude", "gemini"];
|
|
2641
|
+
|
|
2642
|
+
// src/lib/prose-rules-config.ts
|
|
2643
|
+
import safeRegex from "safe-regex2";
|
|
2644
|
+
import { z as z5 } from "zod";
|
|
2645
|
+
var SEVERITIES = ["error", "warning"];
|
|
2646
|
+
var OVERRIDE_KEYS = ["scopes", "severity", "exempt"];
|
|
2647
|
+
var FIXED_DEFAULT_KEYS = ["pattern", "patterns", "flags", "means", "message", "id"];
|
|
2648
|
+
var CUSTOM_KEYS = ["id", "pattern", "patterns", "flags", "means", "scopes", "severity", "exempt"];
|
|
2649
|
+
var DEFAULT_IDS = new Set([...DEFAULT_PROSE_RULES.map((rule) => rule.id), DECISION_RECORD_CITATION_ID]);
|
|
2650
|
+
function isPlainObject(value) {
|
|
2651
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2652
|
+
}
|
|
2653
|
+
function outsideRepositoryReason(entry) {
|
|
2654
|
+
if (entry.startsWith("/") || /^[A-Za-z]:/.test(entry))
|
|
2655
|
+
return "must be a repository-relative path, not an absolute one";
|
|
2656
|
+
if (entry.split(/[\\/]/).includes(".."))
|
|
2657
|
+
return "must stay inside the repository — no `..` segment";
|
|
2658
|
+
return null;
|
|
2659
|
+
}
|
|
2660
|
+
var RepoRelativePathSchema = z5.string().min(1).superRefine((entry, ctx) => {
|
|
2661
|
+
const reason = outsideRepositoryReason(entry);
|
|
2662
|
+
if (reason)
|
|
2663
|
+
ctx.addIssue({ code: z5.ZodIssueCode.custom, message: reason });
|
|
2664
|
+
});
|
|
2665
|
+
function pathListIssues(value, path, issues) {
|
|
2666
|
+
if (!Array.isArray(value)) {
|
|
2667
|
+
issues.push({ path, message: "must be a list of repository-relative paths" });
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
value.forEach((entry, index) => {
|
|
2671
|
+
if (typeof entry !== "string" || entry.length === 0) {
|
|
2672
|
+
issues.push({ path: [...path, index], message: "must be a non-empty repository-relative path" });
|
|
2673
|
+
return;
|
|
2674
|
+
}
|
|
2675
|
+
const reason = outsideRepositoryReason(entry);
|
|
2676
|
+
if (reason)
|
|
2677
|
+
issues.push({ path: [...path, index], message: reason });
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
function scopeListIssues(value, path, allowed, issues) {
|
|
2681
|
+
if (!Array.isArray(value) || value.length === 0) {
|
|
2682
|
+
issues.push({ path, message: "must name at least one scope" });
|
|
2683
|
+
return null;
|
|
2684
|
+
}
|
|
2685
|
+
const scopes = [];
|
|
2686
|
+
value.forEach((scope, index) => {
|
|
2687
|
+
if (typeof scope !== "string" || !CONFIGURABLE_PROSE_SCOPES.includes(scope)) {
|
|
2688
|
+
issues.push({
|
|
2689
|
+
path: [...path, index],
|
|
2690
|
+
message: scope === "published" ? 'scope "published" is not configurable here — the published pass is configured by proseGates.published.allow' : `unknown scope ${JSON.stringify(scope)} — the scopes are: ${CONFIGURABLE_PROSE_SCOPES.join(", ")}`
|
|
2691
|
+
});
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
if (!allowed.includes(scope)) {
|
|
2695
|
+
issues.push({
|
|
2696
|
+
path: [...path, index],
|
|
2697
|
+
message: `scope "${scope}" is not one this rule can run in — it can run in: ${allowed.join(", ")}`
|
|
2698
|
+
});
|
|
2699
|
+
return;
|
|
2700
|
+
}
|
|
2701
|
+
scopes.push(scope);
|
|
2702
|
+
});
|
|
2703
|
+
return scopes;
|
|
2704
|
+
}
|
|
2705
|
+
function severityIssues(value, path, scopes, issues) {
|
|
2706
|
+
if (typeof value === "string") {
|
|
2707
|
+
if (!SEVERITIES.includes(value)) {
|
|
2708
|
+
issues.push({ path, message: `unknown severity ${JSON.stringify(value)} — use "error" or "warning"` });
|
|
2709
|
+
}
|
|
2710
|
+
return;
|
|
2711
|
+
}
|
|
2712
|
+
if (!isPlainObject(value)) {
|
|
2713
|
+
issues.push({ path, message: 'must be "error", "warning", or a map from scope to one of them' });
|
|
2714
|
+
return;
|
|
2715
|
+
}
|
|
2716
|
+
for (const [scope, severity] of Object.entries(value)) {
|
|
2717
|
+
if (!scopes.includes(scope)) {
|
|
2718
|
+
issues.push({ path: [...path, scope], message: `names scope "${scope}", which this rule's scopes do not cover` });
|
|
2719
|
+
}
|
|
2720
|
+
if (typeof severity !== "string" || !SEVERITIES.includes(severity)) {
|
|
2721
|
+
issues.push({
|
|
2722
|
+
path: [...path, scope],
|
|
2723
|
+
message: `unknown severity ${JSON.stringify(severity)} — use "error" or "warning"`
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
}
|
|
2728
|
+
function patternIssues(source, flags, path, issues) {
|
|
2729
|
+
if (typeof source !== "string" || source.length === 0) {
|
|
2730
|
+
issues.push({ path, message: "must be a non-empty regular expression" });
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
if (source.length > CONFIGURED_PATTERN_MAX_LENGTH) {
|
|
2734
|
+
issues.push({
|
|
2735
|
+
path,
|
|
2736
|
+
message: `is ${source.length} characters, over the ${CONFIGURED_PATTERN_MAX_LENGTH}-character limit for a configured pattern`
|
|
2737
|
+
});
|
|
2738
|
+
return;
|
|
2739
|
+
}
|
|
2740
|
+
try {
|
|
2741
|
+
new RegExp(source, flags);
|
|
2742
|
+
} catch (err) {
|
|
2743
|
+
issues.push({ path, message: `does not compile: ${err.message}` });
|
|
2744
|
+
return;
|
|
2745
|
+
}
|
|
2746
|
+
if (!safeRegex(source, { limit: Number.MAX_SAFE_INTEGER })) {
|
|
2747
|
+
issues.push({
|
|
2748
|
+
path,
|
|
2749
|
+
message: "has star height above one (a repeated group that itself repeats), which can take exponential time — " + "safe-regex2 refuses it. The shipped defaults are not held to this limit, so a pattern copied from one of " + "them can still be refused here; rewrite it without the nested repetition."
|
|
2750
|
+
});
|
|
2751
|
+
}
|
|
2752
|
+
}
|
|
2753
|
+
function flagIssues(value, path, issues) {
|
|
2754
|
+
if (value === undefined)
|
|
2755
|
+
return "";
|
|
2756
|
+
if (typeof value !== "string") {
|
|
2757
|
+
issues.push({ path, message: 'must be a string of flags, e.g. "i"' });
|
|
2758
|
+
return "";
|
|
2759
|
+
}
|
|
2760
|
+
const seen = new Set;
|
|
2761
|
+
for (const flag of value) {
|
|
2762
|
+
if (!CONFIGURED_PROSE_FLAGS.includes(flag)) {
|
|
2763
|
+
issues.push({
|
|
2764
|
+
path,
|
|
2765
|
+
message: `unknown flag ${JSON.stringify(flag)} — only ${CONFIGURED_PROSE_FLAGS.map((f) => `"${f}"`).join(" and ")} are allowed`
|
|
2766
|
+
});
|
|
2767
|
+
return "";
|
|
2768
|
+
}
|
|
2769
|
+
if (seen.has(flag)) {
|
|
2770
|
+
issues.push({ path, message: `repeats the flag "${flag}"` });
|
|
2771
|
+
return "";
|
|
2772
|
+
}
|
|
2773
|
+
seen.add(flag);
|
|
2774
|
+
}
|
|
2775
|
+
return value;
|
|
2776
|
+
}
|
|
2777
|
+
function defaultsIssues(value, issues) {
|
|
2778
|
+
const base = ["defaults"];
|
|
2779
|
+
if (!isPlainObject(value)) {
|
|
2780
|
+
issues.push({ path: base, message: 'must map a default rule id to "off" or an override' });
|
|
2781
|
+
return;
|
|
2782
|
+
}
|
|
2783
|
+
for (const [id, override] of Object.entries(value)) {
|
|
2784
|
+
const path = [...base, id];
|
|
2785
|
+
const rule = CONFIGURABLE_DEFAULT_RULES.find((candidate) => candidate.id === id);
|
|
2786
|
+
if (!rule) {
|
|
2787
|
+
issues.push({
|
|
2788
|
+
path,
|
|
2789
|
+
message: `unknown default rule id "${id}" — \`vinaya check --plan\` lists the rules each prose check runs`
|
|
2790
|
+
});
|
|
2791
|
+
continue;
|
|
2792
|
+
}
|
|
2793
|
+
if (override === "off")
|
|
2794
|
+
continue;
|
|
2795
|
+
if (!isPlainObject(override)) {
|
|
2796
|
+
issues.push({ path, message: 'must be "off" or an object with any of scopes, severity, exempt' });
|
|
2797
|
+
continue;
|
|
2798
|
+
}
|
|
2799
|
+
for (const key of Object.keys(override)) {
|
|
2800
|
+
if (OVERRIDE_KEYS.includes(key))
|
|
2801
|
+
continue;
|
|
2802
|
+
issues.push({
|
|
2803
|
+
path: [...path, key],
|
|
2804
|
+
message: FIXED_DEFAULT_KEYS.includes(key) ? `a default rule's ${key} is fixed — add a custom rule under proseGates.rules.custom instead` : `unknown key "${key}" — a default rule takes only scopes, severity and exempt`
|
|
2805
|
+
});
|
|
2806
|
+
}
|
|
2807
|
+
const scopes = override.scopes === undefined ? [...rule.scopes] : scopeListIssues(override.scopes, [...path, "scopes"], allowedScopesFor(rule), issues);
|
|
2808
|
+
if (override.severity !== undefined && scopes)
|
|
2809
|
+
severityIssues(override.severity, [...path, "severity"], scopes, issues);
|
|
2810
|
+
if (override.exempt !== undefined)
|
|
2811
|
+
pathListIssues(override.exempt, [...path, "exempt"], issues);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
function customIssues(value, issues) {
|
|
2815
|
+
if (!Array.isArray(value)) {
|
|
2816
|
+
issues.push({ path: ["custom"], message: "must be a list of rules" });
|
|
2817
|
+
return;
|
|
2818
|
+
}
|
|
2819
|
+
const ids = new Set;
|
|
2820
|
+
value.forEach((rule, index) => {
|
|
2821
|
+
const path = ["custom", index];
|
|
2822
|
+
if (!isPlainObject(rule)) {
|
|
2823
|
+
issues.push({ path, message: "must be a rule object" });
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2826
|
+
for (const key of Object.keys(rule)) {
|
|
2827
|
+
if (!CUSTOM_KEYS.includes(key)) {
|
|
2828
|
+
issues.push({ path: [...path, key], message: `unknown key "${key}" — a rule takes ${CUSTOM_KEYS.join(", ")}` });
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
if (typeof rule.id !== "string" || rule.id.length === 0) {
|
|
2832
|
+
issues.push({ path: [...path, "id"], message: "a custom rule needs an id" });
|
|
2833
|
+
} else if (DEFAULT_IDS.has(rule.id)) {
|
|
2834
|
+
issues.push({
|
|
2835
|
+
path: [...path, "id"],
|
|
2836
|
+
message: `"${rule.id}" is a default rule id — a custom rule needs its own id; retune the default under proseGates.rules.defaults instead`
|
|
2837
|
+
});
|
|
2838
|
+
} else if (ids.has(rule.id)) {
|
|
2839
|
+
issues.push({ path: [...path, "id"], message: `"${rule.id}" is used by an earlier custom rule` });
|
|
2840
|
+
} else {
|
|
2841
|
+
ids.add(rule.id);
|
|
2842
|
+
}
|
|
2843
|
+
if (typeof rule.means !== "string" || rule.means.trim().length === 0) {
|
|
2844
|
+
issues.push({ path: [...path, "means"], message: "a custom rule needs a message (`means`)" });
|
|
2845
|
+
}
|
|
2846
|
+
let scopes = null;
|
|
2847
|
+
if (rule.scopes === undefined) {
|
|
2848
|
+
issues.push({ path: [...path, "scopes"], message: "a custom rule needs at least one scope (`scopes`)" });
|
|
2849
|
+
} else {
|
|
2850
|
+
scopes = scopeListIssues(rule.scopes, [...path, "scopes"], CONFIGURABLE_PROSE_SCOPES, issues);
|
|
2851
|
+
}
|
|
2852
|
+
if (scopes && new Set(scopes.map(groupOfScope)).size > 1) {
|
|
2853
|
+
issues.push({
|
|
2854
|
+
path: [...path, "scopes"],
|
|
2855
|
+
message: 'mixes scopes of both prose checks — "repository" belongs to retired-vocabulary and every other scope to reader-resolvable-prose; write one rule per check'
|
|
2856
|
+
});
|
|
2857
|
+
}
|
|
2858
|
+
const flags = flagIssues(rule.flags, [...path, "flags"], issues);
|
|
2859
|
+
if (rule.pattern === undefined && rule.patterns === undefined) {
|
|
2860
|
+
issues.push({
|
|
2861
|
+
path: [...path, "pattern"],
|
|
2862
|
+
message: "a custom rule needs a `pattern` or a per-scope `patterns` map"
|
|
2863
|
+
});
|
|
2864
|
+
}
|
|
2865
|
+
if (rule.pattern !== undefined)
|
|
2866
|
+
patternIssues(rule.pattern, flags, [...path, "pattern"], issues);
|
|
2867
|
+
if (rule.patterns !== undefined) {
|
|
2868
|
+
if (!isPlainObject(rule.patterns)) {
|
|
2869
|
+
issues.push({ path: [...path, "patterns"], message: "must map a scope to a regular expression" });
|
|
2870
|
+
} else {
|
|
2871
|
+
for (const [scope, source] of Object.entries(rule.patterns)) {
|
|
2872
|
+
if (scopes && !scopes.includes(scope)) {
|
|
2873
|
+
issues.push({
|
|
2874
|
+
path: [...path, "patterns", scope],
|
|
2875
|
+
message: `names scope "${scope}", which this rule's scopes do not cover`
|
|
2876
|
+
});
|
|
2877
|
+
continue;
|
|
2878
|
+
}
|
|
2879
|
+
patternIssues(source, flags, [...path, "patterns", scope], issues);
|
|
2880
|
+
}
|
|
2881
|
+
if (rule.pattern === undefined && scopes) {
|
|
2882
|
+
for (const scope of scopes) {
|
|
2883
|
+
if (!(scope in rule.patterns)) {
|
|
2884
|
+
issues.push({
|
|
2885
|
+
path: [...path, "patterns"],
|
|
2886
|
+
message: `has no pattern for scope "${scope}" — add one, or a \`pattern\` every other scope uses`
|
|
2887
|
+
});
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
}
|
|
2892
|
+
}
|
|
2893
|
+
if (rule.severity !== undefined && scopes)
|
|
2894
|
+
severityIssues(rule.severity, [...path, "severity"], scopes, issues);
|
|
2895
|
+
if (rule.exempt !== undefined)
|
|
2896
|
+
pathListIssues(rule.exempt, [...path, "exempt"], issues);
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
function proseRulesIssues(value) {
|
|
2900
|
+
const issues = [];
|
|
2901
|
+
if (!isPlainObject(value))
|
|
2902
|
+
return [{ path: [], message: "must be an object with any of exempt, defaults, custom" }];
|
|
2903
|
+
for (const key of Object.keys(value)) {
|
|
2904
|
+
if (!["exempt", "defaults", "custom"].includes(key)) {
|
|
2905
|
+
issues.push({ path: [key], message: `unknown key "${key}" — proseGates.rules takes exempt, defaults and custom` });
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
if (value.exempt !== undefined)
|
|
2909
|
+
pathListIssues(value.exempt, ["exempt"], issues);
|
|
2910
|
+
if (value.defaults !== undefined)
|
|
2911
|
+
defaultsIssues(value.defaults, issues);
|
|
2912
|
+
if (value.custom !== undefined)
|
|
2913
|
+
customIssues(value.custom, issues);
|
|
2914
|
+
return issues;
|
|
2915
|
+
}
|
|
2916
|
+
var ProseRulesSchema = z5.unknown().superRefine((value, ctx) => {
|
|
2917
|
+
for (const issue of proseRulesIssues(value)) {
|
|
2918
|
+
ctx.addIssue({ code: z5.ZodIssueCode.custom, path: issue.path, message: issue.message });
|
|
2919
|
+
}
|
|
2920
|
+
}).transform((value) => value);
|
|
2921
|
+
var PublishedProseSchema = z5.object({
|
|
2922
|
+
allow: z5.array(z5.string().min(1)).optional()
|
|
2923
|
+
}).strict();
|
|
2924
|
+
|
|
2925
|
+
// src/lib/config.ts
|
|
2926
|
+
var EnvEntrySchema = z6.union([
|
|
2927
|
+
z6.literal(true),
|
|
2928
|
+
z6.object({ optional: z6.literal(true) }),
|
|
2929
|
+
z6.object({ anyOf: z6.array(z6.string()).min(2) }),
|
|
2930
|
+
z6.string()
|
|
2931
|
+
]);
|
|
2932
|
+
var CheckEntrySchema = z6.object({
|
|
2933
|
+
run: z6.string(),
|
|
2934
|
+
scope: z6.enum(["diff", "full"]),
|
|
2935
|
+
include: z6.array(z6.string()).optional(),
|
|
2936
|
+
args: z6.array(z6.string()).optional(),
|
|
2937
|
+
timeoutMs: z6.number().optional(),
|
|
2938
|
+
env: z6.record(z6.string(), EnvEntrySchema).optional(),
|
|
2939
|
+
requiresOpenPr: z6.boolean().optional(),
|
|
2940
|
+
ownWorkflow: z6.boolean().optional(),
|
|
2941
|
+
principalOwed: z6.literal(true).optional(),
|
|
2942
|
+
validates: z6.enum(["body", "issue"]).optional(),
|
|
2943
|
+
advisory: z6.literal(true).optional()
|
|
2944
|
+
}).superRefine((entry, ctx) => {
|
|
2945
|
+
if (!entry.env)
|
|
2946
|
+
return;
|
|
2947
|
+
for (const [key, value] of Object.entries(entry.env)) {
|
|
2948
|
+
if (typeof value !== "object" || value === null || !("anyOf" in value))
|
|
2949
|
+
continue;
|
|
2950
|
+
const members = value.anyOf;
|
|
2951
|
+
if (new Set(members).size !== members.length) {
|
|
2952
|
+
ctx.addIssue({
|
|
2953
|
+
code: z6.ZodIssueCode.custom,
|
|
2954
|
+
message: `env.${key}.anyOf has duplicate members`,
|
|
2955
|
+
path: ["env", key, "anyOf"]
|
|
2956
|
+
});
|
|
2957
|
+
}
|
|
2958
|
+
if (!members.includes(key)) {
|
|
2959
|
+
ctx.addIssue({
|
|
2960
|
+
code: z6.ZodIssueCode.custom,
|
|
2961
|
+
message: `env.${key}.anyOf must include "${key}" itself as a member`,
|
|
2962
|
+
path: ["env", key, "anyOf"]
|
|
2963
|
+
});
|
|
2964
|
+
}
|
|
2965
|
+
}
|
|
2966
|
+
});
|
|
2967
|
+
var RoleEntrySchema = z6.object({
|
|
2968
|
+
contract: z6.string().refine((p) => p.includes("/"), {
|
|
2969
|
+
message: 'must be a path (contain at least one "/"), not a bare filename'
|
|
2970
|
+
})
|
|
2971
|
+
});
|
|
2972
|
+
var MAX_REPORT_COMMAND_TIMEOUT_MS = 3600000;
|
|
2973
|
+
var BRIEF_BUILTINS = [
|
|
2974
|
+
"tier",
|
|
2975
|
+
"testPlan",
|
|
2976
|
+
"testPlanExclusivity",
|
|
2977
|
+
"principalPlaceholder",
|
|
2978
|
+
"surfaceMap",
|
|
2979
|
+
"docUpdateList",
|
|
2980
|
+
"worktreeStep0",
|
|
2981
|
+
"stopConditions",
|
|
2982
|
+
"autonomyClause",
|
|
2983
|
+
"project",
|
|
2984
|
+
"for",
|
|
2985
|
+
"closesN",
|
|
2986
|
+
"premiseCoverage",
|
|
2987
|
+
"issueRationale",
|
|
2988
|
+
"objectives",
|
|
2989
|
+
"briefSections",
|
|
2990
|
+
"milestoneShape"
|
|
2991
|
+
];
|
|
2992
|
+
var BriefSectionSchema = z6.union([
|
|
2993
|
+
z6.object({ builtin: z6.enum(BRIEF_BUILTINS) }),
|
|
2994
|
+
z6.object({ heading: z6.string().min(1), name: z6.string().optional() }),
|
|
2995
|
+
z6.object({ field: z6.string().min(1), name: z6.string().optional() }),
|
|
2996
|
+
z6.object({ phrase: z6.string().min(1), name: z6.string().optional() })
|
|
2997
|
+
]);
|
|
2998
|
+
var BriefSchemaSchema = z6.object({
|
|
2999
|
+
pr: z6.object({ sections: z6.array(BriefSectionSchema) }).optional(),
|
|
3000
|
+
issue: z6.object({ sections: z6.array(BriefSectionSchema) }).optional(),
|
|
3001
|
+
milestone: z6.object({ sections: z6.array(BriefSectionSchema) }).optional(),
|
|
3002
|
+
ack: z6.array(z6.enum(BRIEF_BUILTINS)).optional()
|
|
3003
|
+
});
|
|
3004
|
+
function isSafeRepoRelPath(p) {
|
|
3005
|
+
if (p.length === 0)
|
|
3006
|
+
return false;
|
|
3007
|
+
if (p.startsWith("/") || /^[a-zA-Z]:[\\/]/.test(p))
|
|
3008
|
+
return false;
|
|
3009
|
+
return p.split(/[\\/]/).every((seg) => seg !== ".." && seg !== "");
|
|
3010
|
+
}
|
|
3011
|
+
var SafeRepoRelPath = z6.string().refine(isSafeRepoRelPath, {
|
|
3012
|
+
message: "must be a repo-root-relative path with no `..` segment or absolute root"
|
|
3013
|
+
});
|
|
3014
|
+
var CANONICAL_HOOK_BLOCK_PREFIXES = [".git/", ".husky/", ".vinaya/hooks/", ".claude/hooks/"];
|
|
3015
|
+
function isCanonicalHookBlockPath(p) {
|
|
3016
|
+
return CANONICAL_HOOK_BLOCK_PREFIXES.some((prefix) => p.startsWith(prefix) && p.length > prefix.length);
|
|
3017
|
+
}
|
|
3018
|
+
var ManagedHookBlockPath = SafeRepoRelPath.refine(isCanonicalHookBlockPath, {
|
|
3019
|
+
message: `must start with one of ${CANONICAL_HOOK_BLOCK_PREFIXES.join(", ")} (byte-exact, case-sensitive)`
|
|
3020
|
+
});
|
|
3021
|
+
var ManagedBlockRecordSchema = z6.object({
|
|
3022
|
+
path: ManagedHookBlockPath,
|
|
3023
|
+
marker: z6.string(),
|
|
3024
|
+
comment: z6.enum(["hash", "html"])
|
|
3025
|
+
});
|
|
3026
|
+
var ManagedManifestSchema = z6.object({
|
|
3027
|
+
version: z6.number().int().positive(),
|
|
3028
|
+
files: z6.array(SafeRepoRelPath),
|
|
3029
|
+
blocks: z6.array(ManagedBlockRecordSchema),
|
|
3030
|
+
labels: z6.array(z6.string()),
|
|
3031
|
+
agents: z6.array(z6.enum(AGENT_VENDORS)).optional()
|
|
3032
|
+
});
|
|
3033
|
+
var ProjectEntrySchema = z6.object({
|
|
3034
|
+
name: z6.string().min(1),
|
|
3035
|
+
description: z6.string().min(1).optional(),
|
|
3036
|
+
path: z6.string().min(1).optional()
|
|
3037
|
+
});
|
|
3038
|
+
function parseTokensCollectDeclaration(value) {
|
|
3039
|
+
const m = value.trim().match(/^(\S+)\s+(\S+)$/);
|
|
3040
|
+
if (!m)
|
|
3041
|
+
return null;
|
|
3042
|
+
const [, interpreter, script] = m;
|
|
3043
|
+
if (!isSafeRepoRelPath(script))
|
|
3044
|
+
return null;
|
|
3045
|
+
return { interpreter, script };
|
|
3046
|
+
}
|
|
3047
|
+
var VinayaConfigObjectSchema = z6.object({
|
|
3048
|
+
rings: z6.object({
|
|
3049
|
+
ring1_forgeWriteInterception: z6.boolean(),
|
|
3050
|
+
ring2_asyncAudits: z6.boolean()
|
|
3051
|
+
}).optional(),
|
|
3052
|
+
checks: z6.record(z6.string(), CheckEntrySchema).optional(),
|
|
3053
|
+
roles: z6.record(z6.string(), RoleEntrySchema).optional(),
|
|
3054
|
+
briefSchema: BriefSchemaSchema.optional(),
|
|
3055
|
+
managed: ManagedManifestSchema.optional(),
|
|
3056
|
+
principals: z6.array(z6.string()).min(1).optional(),
|
|
3057
|
+
releaseActor: z6.string().min(1).optional(),
|
|
3058
|
+
ci: z6.object({ setup: z6.string().min(1) }).optional(),
|
|
3059
|
+
tokens: z6.object({
|
|
3060
|
+
collect: z6.string().min(1).refine((v) => parseTokensCollectDeclaration(v) !== null, {
|
|
3061
|
+
message: 'tokens.collect must be exactly "<interpreter> <repo-relative-script-path>" — two whitespace-separated tokens, no flags, no shell syntax, no quoting'
|
|
3062
|
+
})
|
|
3063
|
+
}).optional(),
|
|
3064
|
+
blastRadius: z6.object({ extraDomains: z6.array(z6.string()).optional() }).optional(),
|
|
3065
|
+
proseGates: z6.object({
|
|
3066
|
+
doctrineRoot: z6.string().min(1).optional(),
|
|
3067
|
+
readerFacingPrefix: z6.string().min(1).optional(),
|
|
3068
|
+
readerFacingSuffix: z6.string().min(1).optional(),
|
|
3069
|
+
legacySlugDir: z6.string().min(1).optional(),
|
|
3070
|
+
sourceComments: z6.object({
|
|
3071
|
+
globs: z6.array(z6.string().min(1)).optional(),
|
|
3072
|
+
allowlist: z6.array(z6.string().min(1)).optional(),
|
|
3073
|
+
severity: z6.enum(["warning", "error"]).optional()
|
|
3074
|
+
}).optional(),
|
|
3075
|
+
specGrandfather: z6.union([z6.array(z6.string().min(1)), z6.record(z6.string().min(1), z6.number().int().min(0))]).optional(),
|
|
3076
|
+
specPaths: z6.array(RepoRelativePathSchema).optional(),
|
|
3077
|
+
productPaths: z6.array(RepoRelativePathSchema).optional(),
|
|
3078
|
+
published: PublishedProseSchema.optional(),
|
|
3079
|
+
rules: ProseRulesSchema.optional()
|
|
3080
|
+
}).optional(),
|
|
3081
|
+
projects: z6.array(ProjectEntrySchema).optional(),
|
|
3082
|
+
dispatch: z6.object({
|
|
3083
|
+
timeoutMs: z6.number().int().positive().optional(),
|
|
3084
|
+
reviewerTimeoutMs: z6.number().int().positive().optional(),
|
|
3085
|
+
killGraceMs: z6.number().int().positive().optional(),
|
|
3086
|
+
agent: z6.enum(["claude", "codex"]).optional()
|
|
3087
|
+
}).optional(),
|
|
3088
|
+
reviewPolicy: z6.object({
|
|
3089
|
+
codeReviewThreshold: z6.string().min(1).optional(),
|
|
3090
|
+
securityThreshold: z6.string().min(1).optional(),
|
|
3091
|
+
maxRounds: z6.number().optional(),
|
|
3092
|
+
maxTaskMinutes: z6.number().optional(),
|
|
3093
|
+
readyPushTimeoutMinutes: z6.number().optional()
|
|
3094
|
+
}).optional(),
|
|
3095
|
+
securityScan: z6.object({
|
|
3096
|
+
command: z6.array(z6.string().min(1)).min(1)
|
|
3097
|
+
}).optional(),
|
|
3098
|
+
gateCutovers: z6.object({
|
|
3099
|
+
objectivesSinceIssue: z6.number().int().nonnegative().optional(),
|
|
3100
|
+
briefSectionsSinceIssue: z6.number().int().nonnegative().optional(),
|
|
3101
|
+
documentationSinceIssue: z6.number().int().nonnegative().optional(),
|
|
3102
|
+
briefRulesSincePr: z6.number().int().nonnegative().optional(),
|
|
3103
|
+
agentBoxesRefusedSincePr: z6.number().int().nonnegative().optional()
|
|
3104
|
+
}).optional(),
|
|
3105
|
+
planning: z6.object({
|
|
3106
|
+
collisionThreshold: z6.number().int().nonnegative().optional()
|
|
3107
|
+
}).optional(),
|
|
3108
|
+
prePush: z6.object({
|
|
3109
|
+
alwaysRun: z6.array(z6.string()).optional(),
|
|
3110
|
+
readyTests: z6.object({
|
|
3111
|
+
mode: z6.literal("ci"),
|
|
3112
|
+
workflow: z6.literal(".github/workflows/ci.yml"),
|
|
3113
|
+
check: z6.literal("Vinaya CI")
|
|
3114
|
+
}).strict().optional(),
|
|
3115
|
+
requiredCi: z6.object({
|
|
3116
|
+
workflow: z6.literal(".github/workflows/ci.yml"),
|
|
3117
|
+
check: z6.literal("Vinaya CI")
|
|
3118
|
+
}).strict().optional()
|
|
3119
|
+
}).optional(),
|
|
3120
|
+
report: z6.object({
|
|
3121
|
+
commandTimeoutMs: z6.number().int().positive().optional()
|
|
3122
|
+
}).superRefine((report, ctx) => {
|
|
3123
|
+
const commandTimeoutMs = report.commandTimeoutMs;
|
|
3124
|
+
if (commandTimeoutMs !== undefined && commandTimeoutMs > MAX_REPORT_COMMAND_TIMEOUT_MS) {
|
|
3125
|
+
ctx.addIssue({
|
|
3126
|
+
code: z6.ZodIssueCode.custom,
|
|
3127
|
+
path: ["commandTimeoutMs"],
|
|
3128
|
+
message: "must be at most 3600000 (1 hour)"
|
|
3129
|
+
});
|
|
3130
|
+
}
|
|
3131
|
+
}).optional(),
|
|
3132
|
+
logPublish: z6.unknown().refine((v) => v === undefined, {
|
|
3133
|
+
message: "logPublish is removed — telemetry is never posted to a tracker or a code host; configure `logs` instead (a folder or a server destination)"
|
|
3134
|
+
}),
|
|
3135
|
+
runtimeDir: z6.string().min(1).refine((v) => isAbsolute2(v), { message: "runtimeDir: must be an absolute path" }).optional(),
|
|
3136
|
+
runner: z6.enum(["standalone", "atta-engine"]).optional(),
|
|
3137
|
+
logs: z6.object({
|
|
3138
|
+
folder: z6.string().min(1).refine((v) => isAbsolute2(v), { message: "logs.folder: must be an absolute path" }).optional(),
|
|
3139
|
+
url: z6.string().url().optional(),
|
|
3140
|
+
headers: z6.record(z6.string()).optional(),
|
|
3141
|
+
readHeaders: z6.record(z6.string()).optional(),
|
|
3142
|
+
events: CustomEventDeclarationsSchema.optional()
|
|
3143
|
+
}).refine((v) => [v.folder, v.url].filter((x) => x !== undefined).length <= 1, {
|
|
3144
|
+
message: "logs: set at most one of folder/url"
|
|
3145
|
+
}).refine((v) => v.headers === undefined || v.url !== undefined, {
|
|
3146
|
+
message: "logs: headers requires url"
|
|
3147
|
+
}).refine((v) => v.readHeaders === undefined || v.url !== undefined, {
|
|
3148
|
+
message: "logs: readHeaders requires url"
|
|
3149
|
+
}).or(z6.literal(false)).optional(),
|
|
3150
|
+
decisionRecords: z6.object({
|
|
3151
|
+
path: RepoRelativePathSchema
|
|
3152
|
+
}).strict().optional()
|
|
3153
|
+
});
|
|
3154
|
+
function decisionRecordsPathIssue(path, doctrineRoot) {
|
|
3155
|
+
const reason = outsideRepositoryReason(path);
|
|
3156
|
+
if (reason)
|
|
3157
|
+
return reason;
|
|
3158
|
+
const folder = normalizeSpecPath(path);
|
|
3159
|
+
if (folder === "" || folder === ".")
|
|
3160
|
+
return "must name a folder, not the repository root";
|
|
3161
|
+
const root = normalizeSpecPath(doctrineRoot ?? "aeg-root");
|
|
3162
|
+
if (folder === root || folder.startsWith(`${root}/`)) {
|
|
3163
|
+
return `must be outside the doctrine tree "${root}" — decision records belong to this repository, not to the doctrine it ships`;
|
|
3164
|
+
}
|
|
3165
|
+
return null;
|
|
3166
|
+
}
|
|
3167
|
+
var VinayaConfigSchema = VinayaConfigObjectSchema.superRefine((config, ctx) => {
|
|
3168
|
+
const path = config.decisionRecords?.path;
|
|
3169
|
+
if (path === undefined || outsideRepositoryReason(path))
|
|
3170
|
+
return;
|
|
3171
|
+
const issue = decisionRecordsPathIssue(path, config.proseGates?.doctrineRoot);
|
|
3172
|
+
if (issue)
|
|
3173
|
+
ctx.addIssue({ code: z6.ZodIssueCode.custom, path: ["decisionRecords", "path"], message: issue });
|
|
3174
|
+
});
|
|
3175
|
+
var VinayaConfigShape = VinayaConfigObjectSchema.shape;
|
|
3176
|
+
var GLOBAL_VINAYA_HOME = join4(homedir(), ".vinaya");
|
|
3177
|
+
var GLOBAL_CONFIG_PATH = join4(GLOBAL_VINAYA_HOME, "config.json");
|
|
3178
|
+
var LOCAL_CONFIG_FILENAME = "vinaya.config.json";
|
|
3179
|
+
function findLocalConfig() {
|
|
3180
|
+
let dir = process.cwd();
|
|
3181
|
+
while (true) {
|
|
3182
|
+
const candidate = join4(dir, LOCAL_CONFIG_FILENAME);
|
|
3183
|
+
if (existsSync4(candidate))
|
|
3184
|
+
return candidate;
|
|
3185
|
+
if (existsSync4(join4(dir, ".git")))
|
|
3186
|
+
return null;
|
|
3187
|
+
const parent = dirname4(dir);
|
|
3188
|
+
if (parent === dir)
|
|
3189
|
+
return null;
|
|
3190
|
+
dir = parent;
|
|
3191
|
+
}
|
|
3192
|
+
}
|
|
3193
|
+
function configPath() {
|
|
3194
|
+
const local = findLocalConfig();
|
|
3195
|
+
if (local)
|
|
3196
|
+
return local;
|
|
3197
|
+
if (existsSync4(GLOBAL_CONFIG_PATH))
|
|
3198
|
+
return GLOBAL_CONFIG_PATH;
|
|
3199
|
+
return null;
|
|
3200
|
+
}
|
|
3201
|
+
function globalChecksIgnoredWarning(path) {
|
|
3202
|
+
return `${path}: "checks" registration in the global config is ignored — checks may only be registered from a repo-local vinaya.config.json.`;
|
|
3203
|
+
}
|
|
3204
|
+
function globalPrincipalsIgnoredWarning(path) {
|
|
3205
|
+
return `${path}: "principals" in the global config is ignored — principals may only be declared from a repo-local vinaya.config.json.`;
|
|
3206
|
+
}
|
|
3207
|
+
function globalRolesIgnoredWarning(path) {
|
|
3208
|
+
return `${path}: "roles" registration in the global config is ignored — roles may only be registered from a repo-local vinaya.config.json.`;
|
|
3209
|
+
}
|
|
3210
|
+
function globalReleaseActorIgnoredWarning(path) {
|
|
3211
|
+
return `${path}: "releaseActor" in the global config is ignored — releaseActor may only be declared from a repo-local vinaya.config.json.`;
|
|
3212
|
+
}
|
|
3213
|
+
function globalTokensCollectIgnoredWarning(path) {
|
|
3214
|
+
return `${path}: "tokens" in the global config is ignored — tokens.collect may only be declared from a repo-local vinaya.config.json.`;
|
|
3215
|
+
}
|
|
3216
|
+
function globalRuntimeDirIgnoredWarning(path) {
|
|
3217
|
+
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.`;
|
|
3218
|
+
}
|
|
3219
|
+
var emittedGlobalKeyWarnings = new Set;
|
|
3220
|
+
function warnGlobalKeyIgnoredOnce(message) {
|
|
3221
|
+
if (emittedGlobalKeyWarnings.has(message))
|
|
3222
|
+
return;
|
|
3223
|
+
emittedGlobalKeyWarnings.add(message);
|
|
3224
|
+
console.error(`⚠ ${message}`);
|
|
3225
|
+
}
|
|
3226
|
+
function stripGlobalOnlyKeys(config, path) {
|
|
3227
|
+
if (path !== GLOBAL_CONFIG_PATH)
|
|
3228
|
+
return config;
|
|
3229
|
+
let result = config;
|
|
3230
|
+
if (result.checks && Object.keys(result.checks).length > 0) {
|
|
3231
|
+
warnGlobalKeyIgnoredOnce(globalChecksIgnoredWarning(path));
|
|
3232
|
+
result = { ...result, checks: undefined };
|
|
3233
|
+
}
|
|
3234
|
+
if (result.roles && Object.keys(result.roles).length > 0) {
|
|
3235
|
+
warnGlobalKeyIgnoredOnce(globalRolesIgnoredWarning(path));
|
|
3236
|
+
result = { ...result, roles: undefined };
|
|
3237
|
+
}
|
|
3238
|
+
if (result.principals && result.principals.length > 0) {
|
|
3239
|
+
warnGlobalKeyIgnoredOnce(globalPrincipalsIgnoredWarning(path));
|
|
3240
|
+
result = { ...result, principals: undefined };
|
|
3241
|
+
}
|
|
3242
|
+
if (result.releaseActor) {
|
|
3243
|
+
warnGlobalKeyIgnoredOnce(globalReleaseActorIgnoredWarning(path));
|
|
3244
|
+
result = { ...result, releaseActor: undefined };
|
|
3245
|
+
}
|
|
3246
|
+
if (result.tokens) {
|
|
3247
|
+
warnGlobalKeyIgnoredOnce(globalTokensCollectIgnoredWarning(path));
|
|
3248
|
+
result = { ...result, tokens: undefined };
|
|
3249
|
+
}
|
|
3250
|
+
if (result.runtimeDir) {
|
|
3251
|
+
warnGlobalKeyIgnoredOnce(globalRuntimeDirIgnoredWarning(path));
|
|
3252
|
+
result = { ...result, runtimeDir: undefined };
|
|
3253
|
+
}
|
|
3254
|
+
return result;
|
|
3255
|
+
}
|
|
3256
|
+
var emittedLocalOverrideWarnings = new Set;
|
|
3257
|
+
function resolveRuntimeDirSetting(config) {
|
|
3258
|
+
return config?.runtimeDir ?? null;
|
|
3259
|
+
}
|
|
3260
|
+
function resolveTrustAnchorRuntimeDir(localRuntimeDir, trustAnchorConfig) {
|
|
3261
|
+
const anchored = resolveRuntimeDirSetting(trustAnchorConfig);
|
|
3262
|
+
return anchored !== null && anchored === localRuntimeDir ? anchored : null;
|
|
3263
|
+
}
|
|
3264
|
+
function resolveLogsSetting(config) {
|
|
3265
|
+
const raw = config?.logs;
|
|
3266
|
+
if (!raw)
|
|
3267
|
+
return null;
|
|
3268
|
+
if (raw.url !== undefined)
|
|
3269
|
+
return { url: raw.url, headers: raw.headers };
|
|
3270
|
+
if (raw.folder !== undefined)
|
|
3271
|
+
return { folder: raw.folder };
|
|
3272
|
+
return null;
|
|
3273
|
+
}
|
|
3274
|
+
function resolveTrustAnchorLogsDestination(local, trustAnchorConfig) {
|
|
3275
|
+
const anchored = resolveLogsSetting(trustAnchorConfig);
|
|
3276
|
+
if (!anchored)
|
|
3277
|
+
return null;
|
|
3278
|
+
if ("url" in local)
|
|
3279
|
+
return "url" in anchored && anchored.url === local.url ? anchored : null;
|
|
3280
|
+
return "folder" in anchored && anchored.folder === local.folder ? anchored : null;
|
|
3281
|
+
}
|
|
3282
|
+
function resolveLogsHeaderValues(headers, env) {
|
|
3283
|
+
if (!headers)
|
|
3284
|
+
return;
|
|
3285
|
+
const resolved = {};
|
|
3286
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
3287
|
+
resolved[key] = value.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (_match, name) => env[name] ?? "");
|
|
3288
|
+
}
|
|
3289
|
+
return resolved;
|
|
3290
|
+
}
|
|
3291
|
+
function trustAnchorRepo() {
|
|
3292
|
+
const fromRunner = trustAnchorRepoFromRunner();
|
|
3293
|
+
if (fromRunner)
|
|
3294
|
+
return fromRunner;
|
|
3295
|
+
try {
|
|
3296
|
+
const url = execFileSync4("git", ["remote", "get-url", "origin"], {
|
|
3297
|
+
encoding: "utf-8",
|
|
3298
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
3299
|
+
});
|
|
3300
|
+
return trustAnchorRepoFromRemoteUrl(url);
|
|
3301
|
+
} catch {
|
|
3302
|
+
return null;
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
async function trustAnchorRepoAsync() {
|
|
3306
|
+
const fromRunner = trustAnchorRepoFromRunner();
|
|
3307
|
+
if (fromRunner)
|
|
3308
|
+
return fromRunner;
|
|
3309
|
+
try {
|
|
3310
|
+
const { stdout } = await execFileAsync4("git", ["remote", "get-url", "origin"], {
|
|
3311
|
+
encoding: "utf-8",
|
|
3312
|
+
timeout: 1e4,
|
|
3313
|
+
killSignal: "SIGKILL"
|
|
3314
|
+
});
|
|
3315
|
+
return trustAnchorRepoFromRemoteUrl(stdout);
|
|
3316
|
+
} catch {
|
|
3317
|
+
return null;
|
|
3318
|
+
}
|
|
3319
|
+
}
|
|
3320
|
+
function wellFormedRepoSlug(slug) {
|
|
3321
|
+
return /^[^/\s]+\/[^/\s]+$/.test(slug) ? slug : null;
|
|
3322
|
+
}
|
|
3323
|
+
function trustAnchorRepoFromRunner() {
|
|
3324
|
+
const fromRunner = process.env.GITHUB_REPOSITORY?.trim();
|
|
3325
|
+
return fromRunner ? wellFormedRepoSlug(fromRunner) : null;
|
|
3326
|
+
}
|
|
3327
|
+
function trustAnchorRepoFromRemoteUrl(url) {
|
|
3328
|
+
const m = url.trim().match(/github\.com[:/]([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
3329
|
+
return m?.[1] && m[2] ? wellFormedRepoSlug(`${m[1]}/${m[2]}`) : null;
|
|
3330
|
+
}
|
|
3331
|
+
var execFileAsync4 = promisify4(execFile4);
|
|
3332
|
+
function resolveCiTrustAnchorProbeRef(env = process.env) {
|
|
3333
|
+
const ref = env.VINAYA_CI_CONFIG_PROBE_REF?.trim();
|
|
3334
|
+
if (!ref)
|
|
3335
|
+
return null;
|
|
3336
|
+
if (env.GITHUB_ACTIONS !== "true")
|
|
3337
|
+
return null;
|
|
3338
|
+
if ((env.GH_TOKEN ?? "").length > 0 || (env.GITHUB_TOKEN ?? "").length > 0)
|
|
3339
|
+
return null;
|
|
3340
|
+
return ref;
|
|
3341
|
+
}
|
|
3342
|
+
function readTrustAnchorConfigAtRef(ref) {
|
|
3343
|
+
const raw = execFileSync4("git", ["show", `${ref}:${LOCAL_CONFIG_FILENAME}`], {
|
|
3344
|
+
encoding: "utf-8",
|
|
3345
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
3346
|
+
timeout: 1e4
|
|
3347
|
+
});
|
|
3348
|
+
return Buffer.from(raw, "utf-8").toString("base64");
|
|
3349
|
+
}
|
|
3350
|
+
var NO_TRUST_ANCHOR_REPO_MESSAGE = "could not resolve repo identity for the trust-anchor read";
|
|
3351
|
+
function ghFetchTrustAnchorConfig() {
|
|
3352
|
+
const probeRef = resolveCiTrustAnchorProbeRef();
|
|
3353
|
+
if (probeRef)
|
|
3354
|
+
return readTrustAnchorConfigAtRef(probeRef);
|
|
3355
|
+
const repo = trustAnchorRepo();
|
|
3356
|
+
if (!repo)
|
|
3357
|
+
throw new Error(NO_TRUST_ANCHOR_REPO_MESSAGE);
|
|
3358
|
+
return execFileSync4("gh", ["api", `repos/${repo}/contents/${LOCAL_CONFIG_FILENAME}`, "--jq", ".content"], {
|
|
3359
|
+
encoding: "utf-8",
|
|
3360
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
3361
|
+
});
|
|
3362
|
+
}
|
|
3363
|
+
async function ghFetchTrustAnchorConfigAsync() {
|
|
3364
|
+
const probeRef = resolveCiTrustAnchorProbeRef();
|
|
3365
|
+
if (probeRef) {
|
|
3366
|
+
const { stdout } = await execFileAsync4("git", ["show", `${probeRef}:${LOCAL_CONFIG_FILENAME}`], {
|
|
3367
|
+
encoding: "utf-8",
|
|
3368
|
+
timeout: 1e4
|
|
3369
|
+
});
|
|
3370
|
+
return Buffer.from(stdout, "utf-8").toString("base64");
|
|
3371
|
+
}
|
|
3372
|
+
const repo = await trustAnchorRepoAsync();
|
|
3373
|
+
if (!repo)
|
|
3374
|
+
throw new Error(NO_TRUST_ANCHOR_REPO_MESSAGE);
|
|
3375
|
+
const { stdout } = await execFileAsync4("gh", ["api", `repos/${repo}/contents/${LOCAL_CONFIG_FILENAME}`, "--jq", ".content"], { encoding: "utf-8", timeout: 1e4, killSignal: "SIGKILL" });
|
|
3376
|
+
return stdout;
|
|
3377
|
+
}
|
|
3378
|
+
function firstLine(err) {
|
|
3379
|
+
return err?.message?.split(`
|
|
3380
|
+
`)[0] ?? "unknown error";
|
|
3381
|
+
}
|
|
3382
|
+
function isMissingFileError(err) {
|
|
3383
|
+
const stderr = err?.stderr;
|
|
3384
|
+
const haystack = [
|
|
3385
|
+
err?.message ?? "",
|
|
3386
|
+
typeof stderr === "string" ? stderr : stderr?.toString() ?? ""
|
|
3387
|
+
].join(`
|
|
3388
|
+
`);
|
|
3389
|
+
return /\b404\b|not found/i.test(haystack);
|
|
3390
|
+
}
|
|
3391
|
+
function loadTrustAnchorConfig(fetcher = ghFetchTrustAnchorConfig) {
|
|
3392
|
+
let base64;
|
|
3393
|
+
try {
|
|
3394
|
+
base64 = fetcher();
|
|
3395
|
+
} catch (err) {
|
|
3396
|
+
return trustAnchorFetchFailed(err);
|
|
3397
|
+
}
|
|
3398
|
+
return parseTrustAnchorContent(base64);
|
|
3399
|
+
}
|
|
3400
|
+
async function loadTrustAnchorConfigAsync(fetcher = ghFetchTrustAnchorConfigAsync, options = {}) {
|
|
3401
|
+
const warn = options.quiet ? () => {} : warnTrustAnchorFallback;
|
|
3402
|
+
let base64;
|
|
3403
|
+
try {
|
|
3404
|
+
base64 = await fetcher();
|
|
3405
|
+
} catch (err) {
|
|
3406
|
+
return trustAnchorFetchFailed(err, warn);
|
|
3407
|
+
}
|
|
3408
|
+
return parseTrustAnchorContent(base64, warn);
|
|
3409
|
+
}
|
|
3410
|
+
function warnTrustAnchorFallback(why) {
|
|
3411
|
+
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.
|
|
3412
|
+
`);
|
|
3413
|
+
}
|
|
3414
|
+
function trustAnchorFetchFailed(err, warn = warnTrustAnchorFallback) {
|
|
3415
|
+
if (!isMissingFileError(err))
|
|
3416
|
+
warn(firstLine(err));
|
|
3417
|
+
return null;
|
|
3418
|
+
}
|
|
3419
|
+
function parseTrustAnchorContent(content, warn = warnTrustAnchorFallback) {
|
|
3420
|
+
const base64 = content.trim();
|
|
3421
|
+
if (!base64)
|
|
3422
|
+
return null;
|
|
3423
|
+
try {
|
|
3424
|
+
const raw = Buffer.from(base64, "base64").toString("utf-8");
|
|
3425
|
+
const parsed = VinayaConfigSchema.safeParse(JSON.parse(raw));
|
|
3426
|
+
if (parsed.success)
|
|
3427
|
+
return parsed.data;
|
|
3428
|
+
warn("it did not satisfy the config schema");
|
|
3429
|
+
return null;
|
|
3430
|
+
} catch {
|
|
3431
|
+
warn("it was not readable as JSON");
|
|
3432
|
+
return null;
|
|
3433
|
+
}
|
|
3434
|
+
}
|
|
3435
|
+
function loadConfig() {
|
|
3436
|
+
const path = configPath();
|
|
3437
|
+
if (!path)
|
|
3438
|
+
return null;
|
|
3439
|
+
let text;
|
|
3440
|
+
try {
|
|
3441
|
+
text = readFileSync5(path, "utf-8");
|
|
3442
|
+
} catch (err) {
|
|
3443
|
+
reportInvalidConfigOnce(path, `unreadable: ${err.message}`);
|
|
3444
|
+
return null;
|
|
3445
|
+
}
|
|
3446
|
+
let raw;
|
|
3447
|
+
try {
|
|
3448
|
+
raw = JSON.parse(text);
|
|
3449
|
+
} catch (err) {
|
|
3450
|
+
reportInvalidConfigOnce(path, `invalid JSON: ${err.message}`);
|
|
3451
|
+
return null;
|
|
3452
|
+
}
|
|
3453
|
+
const parsed = VinayaConfigSchema.safeParse(raw);
|
|
3454
|
+
if (!parsed.success) {
|
|
3455
|
+
reportInvalidConfigOnce(path, schemaIssueDetail(parsed.error));
|
|
3456
|
+
return null;
|
|
3457
|
+
}
|
|
3458
|
+
return stripGlobalOnlyKeys(parsed.data, path);
|
|
3459
|
+
}
|
|
3460
|
+
function schemaIssueDetail(error) {
|
|
3461
|
+
return error.issues.map((i) => `${i.path.join(".") || "(root)"}: ${i.message}`).join("; ");
|
|
3462
|
+
}
|
|
3463
|
+
var emittedInvalidConfigReports = new Set;
|
|
3464
|
+
function reportInvalidConfigOnce(path, detail) {
|
|
3465
|
+
const key = `${path}
|
|
3466
|
+
${detail}`;
|
|
3467
|
+
if (emittedInvalidConfigReports.has(key))
|
|
3468
|
+
return;
|
|
3469
|
+
emittedInvalidConfigReports.add(key);
|
|
3470
|
+
const message = `${path} is not a valid Vinaya configuration (${detail}) — falling back to built-in defaults.`;
|
|
3471
|
+
const checkName = process.env.VINAYA_CHECK_NAME;
|
|
3472
|
+
if (checkName) {
|
|
3473
|
+
emitCheckError({
|
|
3474
|
+
schema: CHECK_SCHEMA_VERSION,
|
|
3475
|
+
check: checkName,
|
|
3476
|
+
severity: "warning",
|
|
3477
|
+
message,
|
|
3478
|
+
agent_recovery_prompt: `Fix the failing keys in ${path} (${detail}) so the file parses and satisfies the configuration schema, then re-run.`,
|
|
3479
|
+
file: path
|
|
3480
|
+
});
|
|
3481
|
+
return;
|
|
3482
|
+
}
|
|
3483
|
+
console.error(`⚠ ${message}`);
|
|
3484
|
+
}
|
|
3485
|
+
var TOKENS_COLLECT_TRUST_PATH = join4(GLOBAL_VINAYA_HOME, "tokens-collect-trust.json");
|
|
3486
|
+
|
|
3487
|
+
// src/lib/run-paths.ts
|
|
3488
|
+
var TASKS_EXECUTION_DIRNAME = "tasks-execution";
|
|
3489
|
+
var RUN_AREA_DIRNAMES = {
|
|
3490
|
+
control: CONTROL_AREA_DIRNAME,
|
|
3491
|
+
sessions: "sessions",
|
|
3492
|
+
hooks: "hooks",
|
|
3493
|
+
output: "output",
|
|
3494
|
+
rounds: "rounds"
|
|
3495
|
+
};
|
|
3496
|
+
var SAFE_PATH_SEGMENT = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;
|
|
3497
|
+
function isSafeRepoSegment(segment) {
|
|
3498
|
+
return SAFE_PATH_SEGMENT.test(segment) && !segment.includes("..");
|
|
3499
|
+
}
|
|
3500
|
+
function repoSegment(repo) {
|
|
3501
|
+
if (!repo || !isSafeRepoSegment(repo.owner) || !isSafeRepoSegment(repo.repo))
|
|
3502
|
+
return "unresolved";
|
|
3503
|
+
return `${repo.owner}-${repo.repo}`;
|
|
3504
|
+
}
|
|
3505
|
+
function defaultRuntimeDir(repo, home = GLOBAL_VINAYA_HOME) {
|
|
3506
|
+
return join5(home, "runtime", repoSegment(repo));
|
|
3507
|
+
}
|
|
3508
|
+
function resolveRuntimeDir(input) {
|
|
3509
|
+
const local = resolveRuntimeDirSetting(input.localConfig);
|
|
3510
|
+
if (local === null)
|
|
3511
|
+
return defaultRuntimeDir(input.repo, input.home);
|
|
3512
|
+
if (isInsideRepo(local, input.repoRoot))
|
|
3513
|
+
return defaultRuntimeDir(input.repo, input.home);
|
|
3514
|
+
if (!input.unattended)
|
|
3515
|
+
return local;
|
|
3516
|
+
const anchored = resolveTrustAnchorRuntimeDir(local, input.trustAnchorConfig ?? null);
|
|
3517
|
+
return anchored ?? defaultRuntimeDir(input.repo, input.home);
|
|
3518
|
+
}
|
|
3519
|
+
function isInsideRepo(candidate, repoRoot) {
|
|
3520
|
+
if (!repoRoot)
|
|
3521
|
+
return false;
|
|
3522
|
+
const root = resolvePath(repoRoot);
|
|
3523
|
+
const target = resolvePath(candidate);
|
|
3524
|
+
return target === root || target.startsWith(`${root}/`);
|
|
3525
|
+
}
|
|
3526
|
+
function runPath(runtimeDir, scope, location) {
|
|
3527
|
+
const dir = join5(runtimeDir, TASKS_EXECUTION_DIRNAME, scopeSegment(scope));
|
|
3528
|
+
switch (location.area) {
|
|
3529
|
+
case "task":
|
|
3530
|
+
return location.file ? join5(dir, location.file) : dir;
|
|
3531
|
+
case "control": {
|
|
3532
|
+
const controlDir = join5(dir, RUN_AREA_DIRNAMES.control);
|
|
3533
|
+
return location.file ? join5(controlDir, location.file) : controlDir;
|
|
3534
|
+
}
|
|
3535
|
+
case "rounds":
|
|
3536
|
+
return join5(dir, RUN_AREA_DIRNAMES.rounds);
|
|
3537
|
+
case "round": {
|
|
3538
|
+
const roundDir = join5(dir, RUN_AREA_DIRNAMES.rounds, String(location.round));
|
|
3539
|
+
return location.file ? join5(roundDir, location.file) : roundDir;
|
|
3540
|
+
}
|
|
3541
|
+
case "developer": {
|
|
3542
|
+
const developerDir = join5(dir, RUN_AREA_DIRNAMES.rounds, String(location.round), "developer");
|
|
3543
|
+
return location.file ? join5(developerDir, location.file) : developerDir;
|
|
3544
|
+
}
|
|
3545
|
+
default: {
|
|
3546
|
+
const areaDir = join5(dir, RUN_AREA_DIRNAMES[location.area]);
|
|
3547
|
+
return location.file ? join5(areaDir, location.file) : areaDir;
|
|
3548
|
+
}
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
function scopeSegment(scope) {
|
|
3552
|
+
if (scope === "unscoped")
|
|
3553
|
+
return "unscoped";
|
|
3554
|
+
if (typeof scope === "number")
|
|
3555
|
+
return String(scope);
|
|
3556
|
+
return `pr-${scope.pr}`;
|
|
3557
|
+
}
|
|
3558
|
+
var UNATTENDED_ENV_KEY = "VINAYA_UNATTENDED";
|
|
3559
|
+
var RUNTIME_DIR_ENV_KEY = "VINAYA_RUNTIME_DIR";
|
|
3560
|
+
function isUnattendedProcess(env = process.env) {
|
|
3561
|
+
return env[UNATTENDED_ENV_KEY] === "1" || (env.VINAYA_ROLE ?? "") !== "";
|
|
3562
|
+
}
|
|
3563
|
+
var memoized = null;
|
|
3564
|
+
function runtimeDirForRepo(repo) {
|
|
3565
|
+
const key = repoSegment(repo);
|
|
3566
|
+
if (memoized?.key === key)
|
|
3567
|
+
return memoized.value;
|
|
3568
|
+
const value = resolveRuntimeDirUncached(repo);
|
|
3569
|
+
memoized = { key, value };
|
|
3570
|
+
return value;
|
|
3571
|
+
}
|
|
3572
|
+
async function runtimeDirForRepoAsync(repo) {
|
|
3573
|
+
const key = repoSegment(repo);
|
|
3574
|
+
if (memoized?.key === key)
|
|
3575
|
+
return memoized.value;
|
|
3576
|
+
const inputs = runtimeDirInputs();
|
|
3577
|
+
if (typeof inputs === "string")
|
|
3578
|
+
return inputs;
|
|
3579
|
+
const value = resolveRuntimeDir({
|
|
3580
|
+
repo,
|
|
3581
|
+
...inputs.base,
|
|
3582
|
+
trustAnchorConfig: inputs.needsAnchor ? await loadTrustAnchorConfigAsync() : null
|
|
3583
|
+
});
|
|
3584
|
+
memoized = { key, value };
|
|
3585
|
+
return value;
|
|
3586
|
+
}
|
|
3587
|
+
function resolveRuntimeDirUncached(repo) {
|
|
3588
|
+
const inputs = runtimeDirInputs();
|
|
3589
|
+
if (typeof inputs === "string")
|
|
3590
|
+
return inputs;
|
|
3591
|
+
return resolveRuntimeDir({
|
|
3592
|
+
repo,
|
|
3593
|
+
...inputs.base,
|
|
3594
|
+
trustAnchorConfig: inputs.needsAnchor ? loadTrustAnchorConfig() : null
|
|
3595
|
+
});
|
|
3596
|
+
}
|
|
3597
|
+
function runtimeDirInputs() {
|
|
3598
|
+
const handedDown = process.env[RUNTIME_DIR_ENV_KEY];
|
|
3599
|
+
if (handedDown)
|
|
3600
|
+
return handedDown;
|
|
3601
|
+
const localConfig = loadConfig();
|
|
3602
|
+
const unattended = isUnattendedProcess();
|
|
3603
|
+
return {
|
|
3604
|
+
base: { localConfig, unattended, repoRoot: repoRootSync() },
|
|
3605
|
+
needsAnchor: unattended && resolveRuntimeDirSetting(localConfig) !== null
|
|
3606
|
+
};
|
|
3607
|
+
}
|
|
3608
|
+
function repoRootSync(start = process.cwd()) {
|
|
3609
|
+
let dir;
|
|
3610
|
+
try {
|
|
3611
|
+
dir = realpathSync2(start);
|
|
3612
|
+
} catch {
|
|
3613
|
+
return null;
|
|
3614
|
+
}
|
|
3615
|
+
for (;; ) {
|
|
3616
|
+
if (existsSync5(join5(dir, ".git")))
|
|
3617
|
+
return dir;
|
|
3618
|
+
const parent = dirname5(dir);
|
|
3619
|
+
if (parent === dir)
|
|
3620
|
+
return null;
|
|
3621
|
+
dir = parent;
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
function resolveRepoSync() {
|
|
3625
|
+
const fromEnv = process.env.AEG_REPO;
|
|
3626
|
+
if (fromEnv) {
|
|
3627
|
+
const m = /^([^/]+)\/(.+)$/.exec(fromEnv);
|
|
3628
|
+
if (m?.[1] && m[2])
|
|
3629
|
+
return { owner: m[1], repo: m[2] };
|
|
3630
|
+
}
|
|
3631
|
+
let url;
|
|
3632
|
+
try {
|
|
3633
|
+
url = execFileSync5("git", ["remote", "get-url", "origin"], {
|
|
3634
|
+
encoding: "utf-8",
|
|
3635
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
3636
|
+
}).trim();
|
|
3637
|
+
} catch {
|
|
3638
|
+
return null;
|
|
3639
|
+
}
|
|
3640
|
+
const ssh = /^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/.exec(url);
|
|
3641
|
+
if (ssh?.[1] && ssh[2])
|
|
3642
|
+
return { owner: ssh[1], repo: ssh[2] };
|
|
3643
|
+
const https = /^https?:\/\/(?:[^@]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(url);
|
|
3644
|
+
if (https?.[1] && https[2])
|
|
3645
|
+
return { owner: https[1], repo: https[2] };
|
|
3646
|
+
return null;
|
|
3647
|
+
}
|
|
3648
|
+
var memoizedThisRepo = null;
|
|
3649
|
+
function runtimeDirForThisRepo() {
|
|
3650
|
+
if (memoizedThisRepo !== null)
|
|
3651
|
+
return memoizedThisRepo;
|
|
3652
|
+
memoizedThisRepo = runtimeDirForRepo(resolveRepoSync());
|
|
3653
|
+
return memoizedThisRepo;
|
|
3654
|
+
}
|
|
3655
|
+
function ensureRunDir(dir, runtimeDir) {
|
|
3656
|
+
mkdirNoSymlinks(dir, 448, runtimeDir);
|
|
3657
|
+
chmodSync(dir, 448);
|
|
3658
|
+
}
|
|
3659
|
+
|
|
3660
|
+
// src/lib/push-progress.ts
|
|
3661
|
+
var PROGRESS_DIRNAME = "progress";
|
|
3662
|
+
var ENGINE_RUNS_DIRNAME = "engine-runs";
|
|
3663
|
+
var PROGRESS_MARKER = "vinaya/push-progress";
|
|
3664
|
+
var PROGRESS_MARKER_TTL_MS = 60 * 60 * 1000;
|
|
3665
|
+
var PROGRESS_SUMMARY_INTERVAL_MS = 60000;
|
|
3666
|
+
function parseProgressMarker(text) {
|
|
3667
|
+
if (!text)
|
|
3668
|
+
return null;
|
|
3669
|
+
try {
|
|
3670
|
+
const value = JSON.parse(text);
|
|
3671
|
+
if (value.version !== 1 || !Number.isInteger(value.task) || value.task <= 0)
|
|
3672
|
+
return null;
|
|
3673
|
+
const driver = value.driver;
|
|
3674
|
+
if (!driver || !Number.isInteger(driver.pid) || driver.pid <= 0 || typeof driver.startTime !== "string")
|
|
3675
|
+
return null;
|
|
3676
|
+
if (typeof value.expiresAt !== "string" || !Number.isFinite(Date.parse(value.expiresAt)))
|
|
3677
|
+
return null;
|
|
3678
|
+
return value;
|
|
3679
|
+
} catch {
|
|
3680
|
+
return null;
|
|
3681
|
+
}
|
|
3682
|
+
}
|
|
3683
|
+
function isPlainOwnDirectory(path) {
|
|
3684
|
+
try {
|
|
3685
|
+
const stat = lstatSync3(path);
|
|
3686
|
+
if (stat.isSymbolicLink() || !stat.isDirectory())
|
|
3687
|
+
return false;
|
|
3688
|
+
return typeof process.getuid !== "function" || stat.uid === process.getuid();
|
|
3689
|
+
} catch {
|
|
3690
|
+
return false;
|
|
3691
|
+
}
|
|
3692
|
+
}
|
|
3693
|
+
function containedProgressDir(runtimeDir, task) {
|
|
3694
|
+
if (!Number.isInteger(task) || task <= 0)
|
|
3695
|
+
return null;
|
|
3696
|
+
let root;
|
|
3697
|
+
try {
|
|
3698
|
+
root = realpathSync3(runtimeDir);
|
|
3699
|
+
} catch {
|
|
3700
|
+
return null;
|
|
3701
|
+
}
|
|
3702
|
+
const runs = join6(root, ENGINE_RUNS_DIRNAME);
|
|
3703
|
+
const run = join6(runs, String(task));
|
|
3704
|
+
const dir = join6(run, PROGRESS_DIRNAME);
|
|
3705
|
+
return [runs, run, dir].every(isPlainOwnDirectory) ? dir : null;
|
|
3706
|
+
}
|
|
3707
|
+
function resolveProgressDir(deps) {
|
|
3708
|
+
try {
|
|
3709
|
+
const marker = parseProgressMarker(deps.readMarker());
|
|
3710
|
+
if (marker === null)
|
|
3711
|
+
return null;
|
|
3712
|
+
if (Date.parse(marker.expiresAt) <= deps.now())
|
|
3713
|
+
return null;
|
|
3714
|
+
if (!deps.isDriverAlive(marker.driver))
|
|
3715
|
+
return null;
|
|
3716
|
+
return containedProgressDir(deps.runtimeDir(), marker.task);
|
|
3717
|
+
} catch {
|
|
3718
|
+
return null;
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
function resolveProgressDirLive(cwd) {
|
|
3722
|
+
try {
|
|
3723
|
+
const markerPath = gitPath(cwd, PROGRESS_MARKER);
|
|
3724
|
+
if (!markerPath || !existsSync6(markerPath))
|
|
3725
|
+
return null;
|
|
3726
|
+
return resolveProgressDir({
|
|
3727
|
+
readMarker: () => readFileSync6(markerPath, "utf8"),
|
|
3728
|
+
runtimeDir: () => runtimeDirForThisRepo(),
|
|
3729
|
+
isDriverAlive: (driver) => identityOf(driver.pid)?.startTime === driver.startTime,
|
|
3730
|
+
now: () => Date.now()
|
|
3731
|
+
});
|
|
3732
|
+
} catch {
|
|
3733
|
+
return null;
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
function openForAppend(dir, name) {
|
|
3737
|
+
if (name.includes("/") || name.startsWith("."))
|
|
3738
|
+
return null;
|
|
3739
|
+
try {
|
|
3740
|
+
const fd = openSync4(join6(dir, name), fsConstants3.O_WRONLY | fsConstants3.O_APPEND | fsConstants3.O_CREAT | fsConstants3.O_NOFOLLOW, 384);
|
|
3741
|
+
if (!fstatSync2(fd).isFile()) {
|
|
3742
|
+
closeSync4(fd);
|
|
3743
|
+
return null;
|
|
3744
|
+
}
|
|
3745
|
+
return fd;
|
|
3746
|
+
} catch {
|
|
3747
|
+
return null;
|
|
3748
|
+
}
|
|
3749
|
+
}
|
|
3750
|
+
function appendProgressBytes(dir, name, bytes) {
|
|
3751
|
+
const fd = openForAppend(dir, name);
|
|
3752
|
+
if (fd === null)
|
|
3753
|
+
return false;
|
|
3754
|
+
try {
|
|
3755
|
+
writeSync3(fd, typeof bytes === "string" ? Buffer.from(bytes, "utf8") : bytes);
|
|
3756
|
+
return true;
|
|
3757
|
+
} catch {
|
|
3758
|
+
return false;
|
|
3759
|
+
} finally {
|
|
3760
|
+
closeSync4(fd);
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
function appendProgressRecord(dir, name, record) {
|
|
3764
|
+
return appendProgressBytes(dir, name, `${JSON.stringify(record)}
|
|
3765
|
+
`);
|
|
3766
|
+
}
|
|
3767
|
+
var FINAL_DRAIN_BOUND_MS = 5000;
|
|
3768
|
+
var isProgressStreamName = (stream) => /^[a-z0-9][a-z0-9-]{0,63}$/.test(stream);
|
|
3769
|
+
function copyCaptureTail(input) {
|
|
3770
|
+
if (!isProgressStreamName(input.stream))
|
|
3771
|
+
return false;
|
|
3772
|
+
const now = input.now ?? (() => Date.now());
|
|
3773
|
+
let fd;
|
|
3774
|
+
try {
|
|
3775
|
+
fd = openSync4(input.capture, "r");
|
|
3776
|
+
} catch {
|
|
3777
|
+
return false;
|
|
3778
|
+
}
|
|
3779
|
+
try {
|
|
3780
|
+
const end = fstatSync2(fd).size;
|
|
3781
|
+
let offset = 0;
|
|
3782
|
+
try {
|
|
3783
|
+
offset = statSync2(join6(input.dir, `${input.stream}.out`)).size;
|
|
3784
|
+
} catch {
|
|
3785
|
+
offset = 0;
|
|
3786
|
+
}
|
|
3787
|
+
const chunk = Buffer.alloc(64 * 1024);
|
|
3788
|
+
while (offset < end && now() < input.deadline) {
|
|
3789
|
+
const read = readSync(fd, chunk, 0, Math.min(chunk.length, end - offset), offset);
|
|
3790
|
+
if (read <= 0)
|
|
3791
|
+
break;
|
|
3792
|
+
if (!appendProgressBytes(input.dir, `${input.stream}.out`, chunk.subarray(0, read)))
|
|
3793
|
+
return false;
|
|
3794
|
+
offset += read;
|
|
3795
|
+
}
|
|
3796
|
+
return true;
|
|
3797
|
+
} catch {
|
|
3798
|
+
return false;
|
|
3799
|
+
} finally {
|
|
3800
|
+
closeSync4(fd);
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
function parseProgressRecord(line) {
|
|
3804
|
+
try {
|
|
3805
|
+
const value = JSON.parse(line);
|
|
3806
|
+
if (value.v !== 1)
|
|
3807
|
+
return null;
|
|
3808
|
+
switch (value.kind) {
|
|
3809
|
+
case "check":
|
|
3810
|
+
return typeof value.name === "string" && typeof value.outcome === "string" && typeof value.ms === "number" ? value : null;
|
|
3811
|
+
case "tests-start":
|
|
3812
|
+
return typeof value.stream === "string" && (value.total === null || typeof value.total === "number") ? value : null;
|
|
3813
|
+
case "tests-end":
|
|
3814
|
+
return typeof value.stream === "string" ? value : null;
|
|
3815
|
+
case "commands-start":
|
|
3816
|
+
return typeof value.count === "number" ? value : null;
|
|
3817
|
+
case "command":
|
|
3818
|
+
return typeof value.command === "string" && typeof value.outcome === "string" && typeof value.ms === "number" ? value : null;
|
|
3819
|
+
default:
|
|
3820
|
+
return null;
|
|
3821
|
+
}
|
|
3822
|
+
} catch {
|
|
3823
|
+
return null;
|
|
3824
|
+
}
|
|
3825
|
+
}
|
|
3826
|
+
var FILE_HEADER = /^(\S.*\.test\.[a-zA-Z]+):$/;
|
|
3827
|
+
var SUMMARY_LINE = /^(?:\s*\d+ (?:pass|fail|skip|todo|snapshots?|expect\(\) calls?)\b|Ran \d+ tests? across \d+ files?\.)/;
|
|
3828
|
+
var FAILURE_RECAP = /^\s*\d+ tests? failed:/;
|
|
3829
|
+
var RESULT_LINE = /^\((pass|fail|skip|todo)\) (.*?)(?: \[(\d+(?:\.\d+)?)(ms|s)\])?$/;
|
|
3830
|
+
|
|
3831
|
+
class BunProgressParser {
|
|
3832
|
+
buffered = "";
|
|
3833
|
+
open = null;
|
|
3834
|
+
inRecap = false;
|
|
3835
|
+
feed(chunk) {
|
|
3836
|
+
this.buffered += chunk;
|
|
3837
|
+
const lines = this.buffered.split(`
|
|
3838
|
+
`);
|
|
3839
|
+
this.buffered = lines.pop() ?? "";
|
|
3840
|
+
const closed = [];
|
|
3841
|
+
for (const raw of lines)
|
|
3842
|
+
this.line(raw.replace(/\r$/, ""), closed);
|
|
3843
|
+
return closed;
|
|
3844
|
+
}
|
|
3845
|
+
end() {
|
|
3846
|
+
const closed = [];
|
|
3847
|
+
if (this.buffered !== "")
|
|
3848
|
+
this.line(this.buffered, closed);
|
|
3849
|
+
this.buffered = "";
|
|
3850
|
+
if (this.open)
|
|
3851
|
+
closed.push({ file: this.open.file, outcome: "interrupted" });
|
|
3852
|
+
this.open = null;
|
|
3853
|
+
return closed;
|
|
3854
|
+
}
|
|
3855
|
+
line(line, closed) {
|
|
3856
|
+
const header = FILE_HEADER.exec(line);
|
|
3857
|
+
if (header?.[1]) {
|
|
3858
|
+
this.close(closed);
|
|
3859
|
+
this.inRecap = false;
|
|
3860
|
+
this.open = { file: header[1], failures: [], ms: 0, unhandled: false };
|
|
3861
|
+
return;
|
|
3862
|
+
}
|
|
3863
|
+
if (FAILURE_RECAP.test(line)) {
|
|
3864
|
+
this.close(closed);
|
|
3865
|
+
this.inRecap = true;
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
if (SUMMARY_LINE.test(line)) {
|
|
3869
|
+
this.close(closed);
|
|
3870
|
+
this.inRecap = false;
|
|
3871
|
+
return;
|
|
3872
|
+
}
|
|
3873
|
+
if (!this.open || this.inRecap)
|
|
3874
|
+
return;
|
|
3875
|
+
const result = RESULT_LINE.exec(line);
|
|
3876
|
+
if (result) {
|
|
3877
|
+
if (result[1] === "fail")
|
|
3878
|
+
this.open.failures.push(result[2] ?? "");
|
|
3879
|
+
if (result[3])
|
|
3880
|
+
this.open.ms += Number(result[3]) * (result[4] === "s" ? 1000 : 1);
|
|
3881
|
+
return;
|
|
3882
|
+
}
|
|
3883
|
+
if (/^# Unhandled error between tests/.test(line))
|
|
3884
|
+
this.open.unhandled = true;
|
|
3885
|
+
}
|
|
3886
|
+
close(closed) {
|
|
3887
|
+
if (!this.open)
|
|
3888
|
+
return;
|
|
3889
|
+
const failed = this.open.failures.length > 0 || this.open.unhandled;
|
|
3890
|
+
closed.push({
|
|
3891
|
+
file: this.open.file,
|
|
3892
|
+
outcome: failed ? "fail" : "pass",
|
|
3893
|
+
firstFailure: this.open.failures[0] ?? (this.open.unhandled ? "an unhandled error between tests" : null),
|
|
3894
|
+
ms: Math.round(this.open.ms)
|
|
3895
|
+
});
|
|
3896
|
+
this.open = null;
|
|
3897
|
+
}
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
class TestRunTally {
|
|
3901
|
+
total;
|
|
3902
|
+
done = 0;
|
|
3903
|
+
failed = 0;
|
|
3904
|
+
msSum = 0;
|
|
3905
|
+
constructor(total) {
|
|
3906
|
+
this.total = total;
|
|
3907
|
+
}
|
|
3908
|
+
add(file) {
|
|
3909
|
+
if (file.outcome === "interrupted")
|
|
3910
|
+
return;
|
|
3911
|
+
this.done += 1;
|
|
3912
|
+
if (file.outcome === "fail")
|
|
3913
|
+
this.failed += 1;
|
|
3914
|
+
this.msSum += file.ms;
|
|
3915
|
+
}
|
|
3916
|
+
get position() {
|
|
3917
|
+
return this.total !== null ? `${this.done}/${this.total}` : `${this.done}`;
|
|
3918
|
+
}
|
|
3919
|
+
get averageMs() {
|
|
3920
|
+
return this.done === 0 ? null : this.msSum / this.done;
|
|
3921
|
+
}
|
|
3922
|
+
}
|
|
3923
|
+
function plainText(text) {
|
|
3924
|
+
let out = "";
|
|
3925
|
+
for (const char of text) {
|
|
3926
|
+
const code = char.codePointAt(0) ?? 0;
|
|
3927
|
+
out += code < 32 || code >= 127 && code <= 159 ? " " : char;
|
|
3928
|
+
}
|
|
3929
|
+
return out;
|
|
3930
|
+
}
|
|
3931
|
+
function formatDuration(ms) {
|
|
3932
|
+
if (!Number.isFinite(ms) || ms < 0)
|
|
3933
|
+
return "?";
|
|
3934
|
+
if (ms < 1000)
|
|
3935
|
+
return `${Math.round(ms)} ms`;
|
|
3936
|
+
if (ms < 60000)
|
|
3937
|
+
return `${(ms / 1000).toFixed(1)} s`;
|
|
3938
|
+
const total = Math.round(ms / 1000);
|
|
3939
|
+
return `${Math.floor(total / 60)} min ${String(total % 60).padStart(2, "0")} s`;
|
|
3940
|
+
}
|
|
3941
|
+
var CHECK_MARK = {
|
|
3942
|
+
pass: "✓",
|
|
3943
|
+
fail: "✗",
|
|
3944
|
+
skip: "skipped",
|
|
3945
|
+
error: "✗ error",
|
|
3946
|
+
timeout: "✗ timed out"
|
|
3947
|
+
};
|
|
3948
|
+
function checkLine(name, outcome, ms) {
|
|
3949
|
+
return `push progress: check ${plainText(name)} ${CHECK_MARK[outcome] ?? plainText(outcome)}, ${formatDuration(ms)}`;
|
|
3950
|
+
}
|
|
3951
|
+
function testFileLine(file, position) {
|
|
3952
|
+
const name = plainText(file.file);
|
|
3953
|
+
if (file.outcome === "interrupted")
|
|
3954
|
+
return `test progress: ${name} interrupted — outcome unknown`;
|
|
3955
|
+
const at = position !== null ? `${position} ` : "";
|
|
3956
|
+
const failure = file.outcome === "fail" && file.firstFailure ? ` — first failing test: ${plainText(file.firstFailure)}` : "";
|
|
3957
|
+
return `test progress: ${at}${name} ${file.outcome === "pass" ? "✓" : "✗"}, ${formatDuration(file.ms)}${failure}`;
|
|
3958
|
+
}
|
|
3959
|
+
function testSummaryLine(tally) {
|
|
3960
|
+
const done = tally.total !== null ? `${tally.done}/${tally.total} files done` : `${tally.done} files done`;
|
|
3961
|
+
const average = tally.averageMs;
|
|
3962
|
+
const avg = average === null ? "no file finished yet" : `${(average / 1000).toFixed(1)} s per file`;
|
|
3963
|
+
let left = "";
|
|
3964
|
+
if (tally.total !== null) {
|
|
3965
|
+
const remaining = Math.max(0, tally.total - tally.done);
|
|
3966
|
+
left = average === null ? `, ${remaining} files left` : `, about ${formatDuration(average * remaining)} left for ${remaining} files`;
|
|
3967
|
+
}
|
|
3968
|
+
return `test progress: ${done}, ${tally.failed} failing, ${avg}${left}`;
|
|
3969
|
+
}
|
|
3970
|
+
function commandsStartLine(count) {
|
|
3971
|
+
return `ready push: running ${count} explicit Test Plan command${count === 1 ? "" : "s"}`;
|
|
3972
|
+
}
|
|
3973
|
+
var COMMAND_MARK = {
|
|
3974
|
+
pass: "✓",
|
|
3975
|
+
fail: "✗",
|
|
3976
|
+
timeout: "✗ timed out",
|
|
3977
|
+
reused: "✓ receipt reused"
|
|
3978
|
+
};
|
|
3979
|
+
function commandLine(command, outcome, ms) {
|
|
3980
|
+
return `command progress: ${COMMAND_MARK[outcome] ?? plainText(outcome)}, ${formatDuration(ms)}: ${plainText(command)}`;
|
|
3981
|
+
}
|
|
3982
|
+
class ProgressReader {
|
|
3983
|
+
dir;
|
|
3984
|
+
write;
|
|
3985
|
+
now;
|
|
3986
|
+
offsets = new Map;
|
|
3987
|
+
partial = new Map;
|
|
3988
|
+
streams = new Map;
|
|
3989
|
+
constructor(dir, write, now = () => Date.now()) {
|
|
3990
|
+
this.dir = dir;
|
|
3991
|
+
this.write = write;
|
|
3992
|
+
this.now = now;
|
|
3993
|
+
}
|
|
3994
|
+
scan() {
|
|
3995
|
+
let names;
|
|
3996
|
+
try {
|
|
3997
|
+
names = readdirSync3(this.dir).sort();
|
|
3998
|
+
} catch {
|
|
3999
|
+
return;
|
|
4000
|
+
}
|
|
4001
|
+
for (const name of names)
|
|
4002
|
+
if (name.endsWith(".ndjson"))
|
|
4003
|
+
this.readRecords(name);
|
|
4004
|
+
for (const name of names)
|
|
4005
|
+
if (name.endsWith(".out"))
|
|
4006
|
+
this.readCopy(name.slice(0, -".out".length));
|
|
4007
|
+
}
|
|
4008
|
+
tick() {
|
|
4009
|
+
const now = this.now();
|
|
4010
|
+
for (const state of this.streams.values()) {
|
|
4011
|
+
if (state.ended || now - state.lastSummaryAt < PROGRESS_SUMMARY_INTERVAL_MS)
|
|
4012
|
+
continue;
|
|
4013
|
+
state.lastSummaryAt = now;
|
|
4014
|
+
this.emit(testSummaryLine(state.tally));
|
|
4015
|
+
}
|
|
4016
|
+
}
|
|
4017
|
+
close() {
|
|
4018
|
+
this.scan();
|
|
4019
|
+
for (const stream of this.streams.keys())
|
|
4020
|
+
this.endStream(stream);
|
|
4021
|
+
}
|
|
4022
|
+
emit(line) {
|
|
4023
|
+
try {
|
|
4024
|
+
this.write(line);
|
|
4025
|
+
} catch {}
|
|
4026
|
+
}
|
|
4027
|
+
stream(stream, total = null) {
|
|
4028
|
+
let state = this.streams.get(stream);
|
|
4029
|
+
if (!state) {
|
|
4030
|
+
state = {
|
|
4031
|
+
parser: new BunProgressParser,
|
|
4032
|
+
tally: new TestRunTally(total),
|
|
4033
|
+
ended: false,
|
|
4034
|
+
lastSummaryAt: this.now()
|
|
4035
|
+
};
|
|
4036
|
+
this.streams.set(stream, state);
|
|
4037
|
+
}
|
|
4038
|
+
return state;
|
|
4039
|
+
}
|
|
4040
|
+
readNew(name) {
|
|
4041
|
+
const offset = this.offsets.get(name) ?? 0;
|
|
4042
|
+
let fd;
|
|
4043
|
+
try {
|
|
4044
|
+
fd = openSync4(join6(this.dir, name), fsConstants3.O_RDONLY | fsConstants3.O_NOFOLLOW);
|
|
4045
|
+
} catch {
|
|
4046
|
+
return "";
|
|
4047
|
+
}
|
|
4048
|
+
try {
|
|
4049
|
+
if (!fstatSync2(fd).isFile())
|
|
4050
|
+
return "";
|
|
4051
|
+
const size = fstatSync2(fd).size;
|
|
4052
|
+
if (size <= offset)
|
|
4053
|
+
return "";
|
|
4054
|
+
const buffer = Buffer.alloc(size - offset);
|
|
4055
|
+
const read = readSync(fd, buffer, 0, buffer.length, offset);
|
|
4056
|
+
this.offsets.set(name, offset + read);
|
|
4057
|
+
return buffer.subarray(0, read).toString("utf8");
|
|
4058
|
+
} catch {
|
|
4059
|
+
return "";
|
|
4060
|
+
} finally {
|
|
4061
|
+
closeSync4(fd);
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
readCopy(stream) {
|
|
4065
|
+
if (!isProgressStreamName(stream))
|
|
4066
|
+
return;
|
|
4067
|
+
const state = this.stream(stream);
|
|
4068
|
+
if (state.ended)
|
|
4069
|
+
return;
|
|
4070
|
+
const text = this.readNew(`${stream}.out`);
|
|
4071
|
+
if (text === "")
|
|
4072
|
+
return;
|
|
4073
|
+
for (const file of state.parser.feed(text))
|
|
4074
|
+
this.fileClosed(state, file);
|
|
4075
|
+
}
|
|
4076
|
+
fileClosed(state, file) {
|
|
4077
|
+
state.tally.add(file);
|
|
4078
|
+
this.emit(testFileLine(file, file.outcome === "interrupted" ? null : state.tally.position));
|
|
4079
|
+
}
|
|
4080
|
+
endStream(stream) {
|
|
4081
|
+
const state = this.stream(stream);
|
|
4082
|
+
if (state.ended)
|
|
4083
|
+
return;
|
|
4084
|
+
this.readCopy(stream);
|
|
4085
|
+
for (const file of state.parser.end())
|
|
4086
|
+
this.fileClosed(state, file);
|
|
4087
|
+
state.ended = true;
|
|
4088
|
+
}
|
|
4089
|
+
readRecords(name) {
|
|
4090
|
+
const text = (this.partial.get(name) ?? "") + this.readNew(name);
|
|
4091
|
+
const lines = text.split(`
|
|
4092
|
+
`);
|
|
4093
|
+
this.partial.set(name, lines.pop() ?? "");
|
|
4094
|
+
for (const line of lines) {
|
|
4095
|
+
const record = line.trim() === "" ? null : parseProgressRecord(line);
|
|
4096
|
+
if (record)
|
|
4097
|
+
this.record(record);
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4100
|
+
record(record) {
|
|
4101
|
+
switch (record.kind) {
|
|
4102
|
+
case "check":
|
|
4103
|
+
this.emit(checkLine(record.name, record.outcome, record.ms));
|
|
4104
|
+
return;
|
|
4105
|
+
case "tests-start": {
|
|
4106
|
+
if (!isProgressStreamName(record.stream))
|
|
4107
|
+
return;
|
|
4108
|
+
const state = this.stream(record.stream, record.total);
|
|
4109
|
+
if (state.tally.total === null)
|
|
4110
|
+
state.tally.total = record.total;
|
|
4111
|
+
return;
|
|
4112
|
+
}
|
|
4113
|
+
case "tests-end":
|
|
4114
|
+
if (isProgressStreamName(record.stream))
|
|
4115
|
+
this.endStream(record.stream);
|
|
4116
|
+
return;
|
|
4117
|
+
case "commands-start":
|
|
4118
|
+
this.emit(commandsStartLine(record.count));
|
|
4119
|
+
return;
|
|
4120
|
+
case "command":
|
|
4121
|
+
this.emit(commandLine(record.command, record.outcome, record.ms));
|
|
4122
|
+
return;
|
|
4123
|
+
}
|
|
4124
|
+
}
|
|
4125
|
+
}
|
|
4126
|
+
|
|
4127
|
+
// src/lib/pre-push-progress-dir.ts
|
|
4128
|
+
var FOLLOW_INTERVAL_MS = 250;
|
|
4129
|
+
var parentAlive = (parent) => {
|
|
4130
|
+
if (process.ppid !== parent)
|
|
4131
|
+
return false;
|
|
4132
|
+
try {
|
|
4133
|
+
process.kill(parent, 0);
|
|
4134
|
+
return true;
|
|
4135
|
+
} catch {
|
|
4136
|
+
return false;
|
|
4137
|
+
}
|
|
4138
|
+
};
|
|
4139
|
+
async function follow(dir, capture, stream) {
|
|
4140
|
+
const parent = process.ppid;
|
|
4141
|
+
for (;; ) {
|
|
4142
|
+
copyCaptureTail({ capture, dir, stream, deadline: Date.now() + FOLLOW_INTERVAL_MS });
|
|
4143
|
+
if (!parentAlive(parent))
|
|
4144
|
+
return;
|
|
4145
|
+
await new Promise((resolve) => setTimeout(resolve, FOLLOW_INTERVAL_MS));
|
|
4146
|
+
}
|
|
4147
|
+
}
|
|
4148
|
+
function testsStart(stream, total) {
|
|
4149
|
+
const count = Number(total);
|
|
4150
|
+
return {
|
|
4151
|
+
v: 1,
|
|
4152
|
+
kind: "tests-start",
|
|
4153
|
+
stream,
|
|
4154
|
+
total: Number.isInteger(count) && count > 0 ? count : null,
|
|
4155
|
+
label: "selected tests"
|
|
4156
|
+
};
|
|
4157
|
+
}
|
|
4158
|
+
async function main(argv) {
|
|
4159
|
+
const [command, ...args] = argv;
|
|
4160
|
+
if (command === "follow")
|
|
4161
|
+
process.on("SIGTERM", () => process.exit(0));
|
|
4162
|
+
const dir = resolveProgressDirLive(process.cwd());
|
|
4163
|
+
if (dir === null)
|
|
4164
|
+
return;
|
|
4165
|
+
switch (command) {
|
|
4166
|
+
case "dir":
|
|
4167
|
+
process.stdout.write(`on
|
|
4168
|
+
`);
|
|
4169
|
+
return;
|
|
4170
|
+
case "check": {
|
|
4171
|
+
const [name, status, started] = args;
|
|
4172
|
+
if (!name || !/^[a-z][a-z0-9-]{0,40}$/.test(name))
|
|
4173
|
+
return;
|
|
4174
|
+
const startedMs = Number(started) * 1000;
|
|
4175
|
+
appendProgressRecord(dir, `steps-${process.ppid}.ndjson`, {
|
|
4176
|
+
v: 1,
|
|
4177
|
+
kind: "check",
|
|
4178
|
+
name,
|
|
4179
|
+
outcome: status === "pass" ? "pass" : "fail",
|
|
4180
|
+
ms: Number.isFinite(startedMs) && startedMs > 0 ? Math.max(0, Date.now() - startedMs) : 0
|
|
4181
|
+
});
|
|
4182
|
+
return;
|
|
4183
|
+
}
|
|
4184
|
+
case "follow": {
|
|
4185
|
+
const [capture, stream, total] = args;
|
|
4186
|
+
if (!capture || !stream || !isProgressStreamName(stream))
|
|
4187
|
+
return;
|
|
4188
|
+
appendProgressRecord(dir, `${stream}.ndjson`, testsStart(stream, total));
|
|
4189
|
+
await follow(dir, capture, stream);
|
|
4190
|
+
return;
|
|
4191
|
+
}
|
|
4192
|
+
case "finish": {
|
|
4193
|
+
const [capture, stream, total] = args;
|
|
4194
|
+
if (!capture || !stream || !isProgressStreamName(stream))
|
|
4195
|
+
return;
|
|
4196
|
+
appendProgressRecord(dir, `${stream}.ndjson`, testsStart(stream, total));
|
|
4197
|
+
copyCaptureTail({ capture, dir, stream, deadline: Date.now() + FINAL_DRAIN_BOUND_MS });
|
|
4198
|
+
appendProgressRecord(dir, `${stream}.ndjson`, { v: 1, kind: "tests-end", stream });
|
|
4199
|
+
return;
|
|
4200
|
+
}
|
|
4201
|
+
default:
|
|
4202
|
+
return;
|
|
4203
|
+
}
|
|
4204
|
+
}
|
|
4205
|
+
main(process.argv.slice(2)).then(() => process.exit(0), () => process.exit(0));
|