@attalabs/vinaya 0.37.0 → 0.38.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/aeg-root/enforcement.md +5 -4
- package/aeg-root/roles/developer/reference.md +24 -22
- package/aeg-root/roles/developer.md +4 -4
- package/aeg-root/roles/planner/reference.md +11 -0
- package/aeg-root/roles/reviewer.md +5 -3
- package/aeg-root/roles/security.md +3 -2
- package/aeg-root/state-machine.md +1 -1
- package/aeg-root/templates/brief-template.md +4 -4
- package/aeg-root/tranche-model.md +6 -0
- package/dist/checks/bin/check-body-bare-digits.js +139 -12
- package/dist/checks/bin/check-branch-topology.js +171 -13
- package/dist/checks/bin/check-brief-shape.js +139 -12
- package/dist/checks/bin/check-changeset-coverage.js +177 -17
- package/dist/checks/bin/check-closes-n.js +171 -13
- package/dist/checks/bin/check-coherence.js +171 -13
- package/dist/checks/bin/check-dead-branch-push.js +139 -12
- package/dist/checks/bin/check-dispatch-readiness.js +195 -23
- package/dist/checks/bin/check-doc-coverage-push.js +173 -13
- package/dist/checks/bin/check-doc-coverage.js +180 -13
- package/dist/checks/bin/check-doctrine-no-procedures.js +139 -12
- package/dist/checks/bin/check-doctrine-portability.js +173 -13
- package/dist/checks/bin/check-evidence-fresh.js +173 -13
- package/dist/checks/bin/check-exec-bits.js +173 -13
- package/dist/checks/bin/check-first-push-dispatch.js +171 -13
- package/dist/checks/bin/check-issue-assignment.js +171 -13
- package/dist/checks/bin/check-issue-milestone-attach.js +139 -12
- package/dist/checks/bin/check-issue-objectives-numbering.js +139 -12
- package/dist/checks/bin/check-issue-parts-coverage.js +139 -12
- package/dist/checks/bin/check-issue-surface-globs.js +171 -13
- package/dist/checks/bin/check-issue-title-grammar.js +139 -12
- package/dist/checks/bin/check-issue-tranche-label.js +139 -12
- package/dist/checks/bin/check-main-branch-refusal.js +139 -12
- package/dist/checks/bin/check-no-disk-state.js +139 -12
- package/dist/checks/bin/check-pr-premise-reassert.js +139 -12
- package/dist/checks/bin/check-pr-report-density.js +139 -12
- package/dist/checks/bin/check-principal-test-plan-wait.js +139 -12
- package/dist/checks/bin/check-quoted-command.js +173 -13
- package/dist/checks/bin/check-reader-resolvable-prose.js +173 -13
- package/dist/checks/bin/check-registry-gates.js +406 -68
- package/dist/checks/bin/check-retired-vocabulary.js +173 -13
- package/dist/checks/bin/check-review-gate.js +139 -12
- package/dist/checks/bin/check-single-plan-pr.js +139 -12
- package/dist/checks/bin/check-surface-scope.js +171 -13
- package/dist/checks/bin/check-test-plan.js +139 -12
- package/dist/checks/bin/check-token-collection-wired.js +139 -12
- package/dist/checks/bin/check-workspace-escape.js +173 -13
- package/dist/checks/bin/verify-dispatch.js +3849 -0
- package/dist/index.js +7348 -2095
- package/dist/lib/pre-push-cache-test-run.js +42 -2
- package/dist/lib/pre-push-changed-files.js +16 -11
- package/dist/lib/pre-push-select-tests.js +177 -21
- package/package.json +1 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +7 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +33 -15
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +51 -12
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +1 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +31 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +31 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +214 -24
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +11 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +5 -4
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +13 -13
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +46 -145
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +63 -14
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +3 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +30 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +0 -1
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +56 -7
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +7 -7
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +24 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/custom.ts +157 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +44 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/executions.ts +493 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/fact-sheets.ts +111 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/generator.ts +155 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/index.ts +12 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +128 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/catches.ts +63 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/checks.ts +146 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/common.ts +137 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/completion.ts +137 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/convergence.ts +420 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/determinism.ts +65 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/index.ts +69 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/judgment.ts +132 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/labels.ts +21 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/time.ts +167 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/usage.ts +139 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +219 -15
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +7 -7
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/cache-contract.ts +207 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/contracts.ts +105 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/engine.ts +308 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/index.ts +34 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/measured.ts +20 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/memory-cache.ts +78 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/normalize.ts +156 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/row.ts +103 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +34 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +70 -6
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +19 -14
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +38 -3
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +5 -2
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +46 -0
- package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +15 -28
- 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/page_client-reference-manifest.js +1 -1
- 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.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.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.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.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.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.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.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]__04adkz-._.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]__0h9yhwx._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__14ui9sz._.js → [root-of-the-server]__0jdjsxe._.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]__1gjqmhq._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
- 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 +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_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/1-acpmtfmrc35.js +1 -0
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3qtt1v3ya-ofe.js → 2f2y8xxok8zph.js} +1 -1
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3l56x8wjdzvaw.js → 2xevgia1h8g0y.js} +4 -4
- package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
- package/dist/checks/bin/check-token-report.js +0 -6526
- package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0vtfb0g813gki.js +0 -1
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_buildManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_clientMiddlewareManifest.js +0 -0
- /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,3849 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @bun
|
|
3
|
+
|
|
4
|
+
// ../../packages/aeg-core/bin/verify-dispatch.ts
|
|
5
|
+
import { execFile as execFile4, execFileSync as execFileSync2, spawnSync } from "child_process";
|
|
6
|
+
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { promisify as promisify4 } from "util";
|
|
9
|
+
|
|
10
|
+
// ../../packages/aeg-forge-state/src/parse-rationale-deps.ts
|
|
11
|
+
var SECTION_HEADER = /\*\*Dependency rationale\*\*/i;
|
|
12
|
+
var NEXT_HEADER = /\*\*[A-Z][^*]*\*\*/;
|
|
13
|
+
var FIELD_LABEL = /^(Depends-on|Conflicts-with)\s*:\s*(.*)$/i;
|
|
14
|
+
var ID_TOKEN = /^(?:[\w.-]+\s+)?#?\d+$/i;
|
|
15
|
+
var SLUG_QUALIFIED_ID = /^([\w.-]+)\s+(#?\d+)$/i;
|
|
16
|
+
function splitSlugQualifiedEdge(edge) {
|
|
17
|
+
const m = edge.trim().match(SLUG_QUALIFIED_ID);
|
|
18
|
+
if (!m)
|
|
19
|
+
return null;
|
|
20
|
+
return { slug: m[1], bareId: m[2] };
|
|
21
|
+
}
|
|
22
|
+
function isEmptyMarker(s) {
|
|
23
|
+
const t = s.trim();
|
|
24
|
+
return t === "" || t === "—" || t === "-" || t === "–";
|
|
25
|
+
}
|
|
26
|
+
function pushUnique(arr, ids) {
|
|
27
|
+
for (const id of ids) {
|
|
28
|
+
if (!arr.includes(id))
|
|
29
|
+
arr.push(id);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function splitIds(raw) {
|
|
33
|
+
if (isEmptyMarker(raw))
|
|
34
|
+
return [];
|
|
35
|
+
return raw.split(",").map((s) => s.trim()).filter((s) => s.length > 0 && !isEmptyMarker(s) && ID_TOKEN.test(s));
|
|
36
|
+
}
|
|
37
|
+
function resolveIds(raw) {
|
|
38
|
+
const ids = splitIds(raw);
|
|
39
|
+
const resolved = [];
|
|
40
|
+
let lastSlug = null;
|
|
41
|
+
for (const id of ids) {
|
|
42
|
+
const qualified = id.match(SLUG_QUALIFIED_ID);
|
|
43
|
+
if (qualified) {
|
|
44
|
+
lastSlug = qualified[1] ?? null;
|
|
45
|
+
resolved.push(id);
|
|
46
|
+
} else if (lastSlug) {
|
|
47
|
+
resolved.push(`${lastSlug} ${id}`);
|
|
48
|
+
lastSlug = null;
|
|
49
|
+
} else {
|
|
50
|
+
resolved.push(id);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return resolved;
|
|
54
|
+
}
|
|
55
|
+
function extractSection(body) {
|
|
56
|
+
const start = body.match(SECTION_HEADER);
|
|
57
|
+
if (!start || start.index === undefined)
|
|
58
|
+
return "";
|
|
59
|
+
const rest = body.slice(start.index + start[0].length);
|
|
60
|
+
const next = rest.match(NEXT_HEADER);
|
|
61
|
+
const end = next && next.index !== undefined ? next.index : rest.length;
|
|
62
|
+
return rest.slice(0, end);
|
|
63
|
+
}
|
|
64
|
+
function parseRationaleDeps(body) {
|
|
65
|
+
const section = extractSection(body);
|
|
66
|
+
const dependsOn = [];
|
|
67
|
+
const conflictsWith = [];
|
|
68
|
+
const assignedFields = new Set;
|
|
69
|
+
const spanPattern = /`([^`]*)`/g;
|
|
70
|
+
let match = spanPattern.exec(section);
|
|
71
|
+
while (match !== null) {
|
|
72
|
+
const content = (match[1] ?? "").trim();
|
|
73
|
+
const labelMatch = content.match(FIELD_LABEL);
|
|
74
|
+
if (labelMatch) {
|
|
75
|
+
const field = labelMatch[1]?.toLowerCase() === "conflicts-with" ? "conflictsWith" : "dependsOn";
|
|
76
|
+
if (!assignedFields.has(field)) {
|
|
77
|
+
assignedFields.add(field);
|
|
78
|
+
const ids = resolveIds(labelMatch[2] ?? "");
|
|
79
|
+
pushUnique(field === "dependsOn" ? dependsOn : conflictsWith, ids);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
match = spanPattern.exec(section);
|
|
83
|
+
}
|
|
84
|
+
return { dependsOn, conflictsWith };
|
|
85
|
+
}
|
|
86
|
+
class AmbiguousBareEdgeError extends Error {
|
|
87
|
+
token;
|
|
88
|
+
tranches;
|
|
89
|
+
constructor(token, tranches) {
|
|
90
|
+
super(`Edge \`${token}\` is a bare id, but its Milestone holds ${tranches.length} tranches ` + `(${tranches.join(", ")}) — a bare id is ambiguous here. Qualify it as \`<slug> ${token}\`, ` + "naming which one.");
|
|
91
|
+
this.name = "AmbiguousBareEdgeError";
|
|
92
|
+
this.token = token;
|
|
93
|
+
this.tranches = tranches;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function requireTrancheQualifiedEdges(ids, milestoneTranches) {
|
|
97
|
+
if (milestoneTranches.length < 2)
|
|
98
|
+
return;
|
|
99
|
+
for (const id of ids) {
|
|
100
|
+
if (id.trim().startsWith("#"))
|
|
101
|
+
continue;
|
|
102
|
+
if (splitSlugQualifiedEdge(id) === null) {
|
|
103
|
+
throw new AmbiguousBareEdgeError(id, [...milestoneTranches]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// ../../packages/aeg-forge-state/src/gh.ts
|
|
108
|
+
import { execFile, execFileSync } from "node:child_process";
|
|
109
|
+
import { promisify } from "node:util";
|
|
110
|
+
var execFileAsync = promisify(execFile);
|
|
111
|
+
var systemEnv = {
|
|
112
|
+
...process.env,
|
|
113
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
114
|
+
};
|
|
115
|
+
function run(args) {
|
|
116
|
+
return execFileSync("gh", args, { encoding: "utf8", env: systemEnv });
|
|
117
|
+
}
|
|
118
|
+
async function runAsync(args) {
|
|
119
|
+
const { stdout } = await execFileAsync("gh", args, {
|
|
120
|
+
encoding: "utf8",
|
|
121
|
+
env: systemEnv,
|
|
122
|
+
maxBuffer: 16 * 1024 * 1024
|
|
123
|
+
});
|
|
124
|
+
return stdout;
|
|
125
|
+
}
|
|
126
|
+
function ghApiGet(path) {
|
|
127
|
+
return JSON.parse(run(["api", path]));
|
|
128
|
+
}
|
|
129
|
+
var MAX_PER_PAGE = 100;
|
|
130
|
+
var MAX_PAGES = 100;
|
|
131
|
+
async function ghApiGetAllPagesAsync(pathWithoutPage, opts) {
|
|
132
|
+
const [base = pathWithoutPage, query = ""] = pathWithoutPage.split("?");
|
|
133
|
+
const params = new URLSearchParams(query);
|
|
134
|
+
params.set("per_page", String(MAX_PER_PAGE));
|
|
135
|
+
const all = [];
|
|
136
|
+
for (let page = 1;page <= MAX_PAGES; page++) {
|
|
137
|
+
params.set("page", String(page));
|
|
138
|
+
const args = ["api", `${base}?${params.toString()}`];
|
|
139
|
+
if (opts?.jq)
|
|
140
|
+
args.push("-q", opts.jq);
|
|
141
|
+
const batch = JSON.parse(await runAsync(args));
|
|
142
|
+
all.push(...batch);
|
|
143
|
+
if (batch.length < MAX_PER_PAGE)
|
|
144
|
+
return all;
|
|
145
|
+
}
|
|
146
|
+
throw new Error(`ghApiGetAllPagesAsync: "${pathWithoutPage}" did not terminate within ${MAX_PAGES} pages (${MAX_PAGES * MAX_PER_PAGE} items) — refusing to keep walking.`);
|
|
147
|
+
}
|
|
148
|
+
function issueListByLabelArgs(owner, repo, label) {
|
|
149
|
+
return [
|
|
150
|
+
"issue",
|
|
151
|
+
"list",
|
|
152
|
+
"--repo",
|
|
153
|
+
`${owner}/${repo}`,
|
|
154
|
+
"--label",
|
|
155
|
+
label,
|
|
156
|
+
"--state",
|
|
157
|
+
"all",
|
|
158
|
+
"--json",
|
|
159
|
+
"number,title,body,state,labels,milestone,stateReason",
|
|
160
|
+
"--limit",
|
|
161
|
+
"200"
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
function ghIssueListByLabel(owner, repo, label) {
|
|
165
|
+
return JSON.parse(run(issueListByLabelArgs(owner, repo, label)));
|
|
166
|
+
}
|
|
167
|
+
async function ghIssueListByLabelAsync(owner, repo, label) {
|
|
168
|
+
return JSON.parse(await runAsync(issueListByLabelArgs(owner, repo, label)));
|
|
169
|
+
}
|
|
170
|
+
function dedupeByNumber(issues) {
|
|
171
|
+
const byNumber = new Map;
|
|
172
|
+
for (const issue of issues)
|
|
173
|
+
if (!byNumber.has(issue.number))
|
|
174
|
+
byNumber.set(issue.number, issue);
|
|
175
|
+
return [...byNumber.values()];
|
|
176
|
+
}
|
|
177
|
+
async function ghIssueListByAnyLabelAsync(owner, repo, labels) {
|
|
178
|
+
const perLabel = await Promise.all(labels.map((l) => ghIssueListByLabelAsync(owner, repo, l)));
|
|
179
|
+
return dedupeByNumber(perLabel.flat());
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ../../packages/aeg-forge-state/src/labels.ts
|
|
183
|
+
var LABELS = [
|
|
184
|
+
{
|
|
185
|
+
key: "blocked",
|
|
186
|
+
id: "vinaya/blocked",
|
|
187
|
+
category: "state",
|
|
188
|
+
form: "literal",
|
|
189
|
+
carries: "Execution is halted pending an external unblock; wins over every other derived status."
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
key: "backlog",
|
|
193
|
+
id: "vinaya/backlog",
|
|
194
|
+
category: "state",
|
|
195
|
+
form: "literal",
|
|
196
|
+
carries: "The Issue is deliberately unplanned — belongs to no tranche and is excluded from dispatch, until a Planner promotes it."
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
key: "tier-0",
|
|
200
|
+
id: "vinaya/tier:0",
|
|
201
|
+
category: "tier",
|
|
202
|
+
form: "literal",
|
|
203
|
+
carries: "Lowest governance weight — typecheck, lint, tests, and a conforming PR body."
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
key: "tier-1",
|
|
207
|
+
id: "vinaya/tier:1",
|
|
208
|
+
category: "tier",
|
|
209
|
+
form: "literal",
|
|
210
|
+
carries: "Tier 0 plus spec/skill coverage and a passing verify-docs run."
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
key: "tier-3",
|
|
214
|
+
id: "vinaya/tier:3",
|
|
215
|
+
category: "tier",
|
|
216
|
+
form: "literal",
|
|
217
|
+
carries: "Tier 1 plus the reasoning for the change, stated in the pull request that makes it."
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
key: "tranche",
|
|
221
|
+
id: "vinaya/tranche:",
|
|
222
|
+
category: "tranche",
|
|
223
|
+
form: "prefix",
|
|
224
|
+
carries: "The tranche slug this task Issue belongs to — the forge's grouping key, matched by prefix."
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
key: "needs-execution-input",
|
|
228
|
+
id: "vinaya/needs:execution-input",
|
|
229
|
+
category: "needs",
|
|
230
|
+
form: "literal",
|
|
231
|
+
carries: "Waiting on a missing execution detail — a flag, a dependency, a value the brief did not carry."
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
key: "needs-strategy-input",
|
|
235
|
+
id: "vinaya/needs:strategy-input",
|
|
236
|
+
category: "needs",
|
|
237
|
+
form: "literal",
|
|
238
|
+
carries: "Waiting on a strategy call — the brief assumes an approach the codebase has moved away from."
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
key: "needs-principal-input",
|
|
242
|
+
id: "vinaya/needs:principal-input",
|
|
243
|
+
category: "needs",
|
|
244
|
+
form: "literal",
|
|
245
|
+
carries: "Waiting on the Principal — a product-level call no agent may make."
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
key: "needs-brief-correction",
|
|
249
|
+
id: "vinaya/needs:brief-correction",
|
|
250
|
+
category: "needs",
|
|
251
|
+
form: "literal",
|
|
252
|
+
carries: "Waiting on the Planner — the brief contradicts the surface it describes."
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
key: "waiver-docs",
|
|
256
|
+
id: "vinaya/waiver:docs",
|
|
257
|
+
category: "waiver",
|
|
258
|
+
form: "literal",
|
|
259
|
+
carries: "Doc-coverage gate excused for this PR — honored only when a principal applied it."
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
key: "waiver-review",
|
|
263
|
+
id: "vinaya/waiver:review",
|
|
264
|
+
category: "waiver",
|
|
265
|
+
form: "literal",
|
|
266
|
+
carries: "Review gate excused for this PR — honored only when a principal applied it."
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
key: "override-docs",
|
|
270
|
+
id: "vinaya/override:docs",
|
|
271
|
+
category: "waiver",
|
|
272
|
+
form: "literal",
|
|
273
|
+
carries: "The whole verify-docs gate suppressed for this PR — a Principal-only blunt override, wider than a waiver."
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
key: "incoherent",
|
|
277
|
+
id: "vinaya/incoherent",
|
|
278
|
+
category: "flag",
|
|
279
|
+
form: "literal",
|
|
280
|
+
carries: "Closed COMPLETED with no merged-PR link — done-but-unprovable, surfaced for a human."
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
key: "direct-main-push",
|
|
284
|
+
id: "vinaya/direct-main-push",
|
|
285
|
+
category: "flag",
|
|
286
|
+
form: "literal",
|
|
287
|
+
carries: "A commit reached main with no associated merged PR — ring-2 detection, never a mutation."
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
key: "dead-branch-push",
|
|
291
|
+
id: "vinaya/dead-branch-push",
|
|
292
|
+
category: "flag",
|
|
293
|
+
form: "literal",
|
|
294
|
+
carries: "Commits landed on a branch after its PR had already resolved — daily-drift detection."
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
key: "state-object",
|
|
298
|
+
id: "vinaya/state-object",
|
|
299
|
+
category: "kind",
|
|
300
|
+
form: "literal",
|
|
301
|
+
carries: "A permanent forge-native storage object, never actionable work — excluded from every backlog."
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
key: "type-build",
|
|
305
|
+
id: "vinaya/type:build",
|
|
306
|
+
category: "type",
|
|
307
|
+
form: "literal",
|
|
308
|
+
carries: "The task changes the build system, packaging, or an external dependency rather than product behavior."
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
key: "type-chore",
|
|
312
|
+
id: "vinaya/type:chore",
|
|
313
|
+
category: "type",
|
|
314
|
+
form: "literal",
|
|
315
|
+
carries: "The task is maintenance or repo housekeeping with no functional, user-facing change."
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
key: "type-docs",
|
|
319
|
+
id: "vinaya/type:docs",
|
|
320
|
+
category: "type",
|
|
321
|
+
form: "literal",
|
|
322
|
+
carries: "The task changes documentation only, with no code behavior affected."
|
|
323
|
+
},
|
|
324
|
+
{
|
|
325
|
+
key: "type-feat",
|
|
326
|
+
id: "vinaya/type:feat",
|
|
327
|
+
category: "type",
|
|
328
|
+
form: "literal",
|
|
329
|
+
carries: "The task adds a capability that did not exist before."
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
key: "type-fix",
|
|
333
|
+
id: "vinaya/type:fix",
|
|
334
|
+
category: "type",
|
|
335
|
+
form: "literal",
|
|
336
|
+
carries: "The task corrects incorrect behavior — a bug, not a missing capability."
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
key: "type-perf",
|
|
340
|
+
id: "vinaya/type:perf",
|
|
341
|
+
category: "type",
|
|
342
|
+
form: "literal",
|
|
343
|
+
carries: "The task improves performance or resource use without changing observable behavior."
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
key: "type-refactor",
|
|
347
|
+
id: "vinaya/type:refactor",
|
|
348
|
+
category: "type",
|
|
349
|
+
form: "literal",
|
|
350
|
+
carries: "The task restructures existing code without changing its external behavior."
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
key: "type-revert",
|
|
354
|
+
id: "vinaya/type:revert",
|
|
355
|
+
category: "type",
|
|
356
|
+
form: "literal",
|
|
357
|
+
carries: "The task undoes a previous change that shipped in error or is no longer wanted."
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
key: "type-style",
|
|
361
|
+
id: "vinaya/type:style",
|
|
362
|
+
category: "type",
|
|
363
|
+
form: "literal",
|
|
364
|
+
carries: "The task changes formatting, naming, or non-semantic code shape with no logic change."
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
key: "type-test",
|
|
368
|
+
id: "vinaya/type:test",
|
|
369
|
+
category: "type",
|
|
370
|
+
form: "literal",
|
|
371
|
+
carries: "The task adds or corrects test coverage with no production-code behavior change."
|
|
372
|
+
}
|
|
373
|
+
];
|
|
374
|
+
var BY_KEY = new Map(LABELS.map((l) => [l.key, l]));
|
|
375
|
+
function entry(key) {
|
|
376
|
+
const found = BY_KEY.get(key);
|
|
377
|
+
if (!found)
|
|
378
|
+
throw new Error(`labels.ts: no LABELS entry for key '${key}'`);
|
|
379
|
+
return found;
|
|
380
|
+
}
|
|
381
|
+
function label(key) {
|
|
382
|
+
return entry(key).id;
|
|
383
|
+
}
|
|
384
|
+
function trancheLabel(slug) {
|
|
385
|
+
return `${label("tranche")}${slug}`;
|
|
386
|
+
}
|
|
387
|
+
function trancheSlugOf(name) {
|
|
388
|
+
const prefix = entry("tranche").id;
|
|
389
|
+
return name.startsWith(prefix) ? name.slice(prefix.length) : null;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// ../../packages/aeg-forge-state/src/strip-code.ts
|
|
393
|
+
function maskCode(body) {
|
|
394
|
+
const fill = (line) => " ".repeat(line.length);
|
|
395
|
+
const blocksMasked = maskIndentedCode(maskFencedCode(body, fill), fill);
|
|
396
|
+
return blocksMasked.split(`
|
|
397
|
+
`).map((line) => replaceInlineSpans(line, (span) => " ".repeat(span.length))).join(`
|
|
398
|
+
`);
|
|
399
|
+
}
|
|
400
|
+
function stripCode(body, options = {}) {
|
|
401
|
+
const normalised = body.replace(/\r\n?/g, `
|
|
402
|
+
`);
|
|
403
|
+
const blank = () => "";
|
|
404
|
+
const blocksStripped = maskIndentedCode(maskFencedCode(normalised, blank), blank);
|
|
405
|
+
if (options.inlineSpans === "keep")
|
|
406
|
+
return blocksStripped;
|
|
407
|
+
return blocksStripped.split(`
|
|
408
|
+
`).map((line) => replaceInlineSpans(line, () => "")).join(`
|
|
409
|
+
`);
|
|
410
|
+
}
|
|
411
|
+
function replaceInlineSpans(line, replace) {
|
|
412
|
+
let result = "";
|
|
413
|
+
let i = 0;
|
|
414
|
+
const runLengthAt = (at) => {
|
|
415
|
+
let j = at;
|
|
416
|
+
while (j < line.length && line[j] === "`")
|
|
417
|
+
j++;
|
|
418
|
+
return j - at;
|
|
419
|
+
};
|
|
420
|
+
while (i < line.length) {
|
|
421
|
+
if (line[i] !== "`") {
|
|
422
|
+
result += line[i];
|
|
423
|
+
i++;
|
|
424
|
+
continue;
|
|
425
|
+
}
|
|
426
|
+
const openLen = runLengthAt(i);
|
|
427
|
+
const openEnd = i + openLen;
|
|
428
|
+
let j = openEnd;
|
|
429
|
+
let closeEnd = -1;
|
|
430
|
+
while (j < line.length) {
|
|
431
|
+
if (line[j] !== "`") {
|
|
432
|
+
j++;
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
const runLen = runLengthAt(j);
|
|
436
|
+
if (runLen === openLen) {
|
|
437
|
+
closeEnd = j + runLen;
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
j += runLen;
|
|
441
|
+
}
|
|
442
|
+
if (closeEnd === -1) {
|
|
443
|
+
result += line.slice(i, openEnd);
|
|
444
|
+
i = openEnd;
|
|
445
|
+
} else {
|
|
446
|
+
result += replace(line.slice(i, closeEnd));
|
|
447
|
+
i = closeEnd;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return result;
|
|
451
|
+
}
|
|
452
|
+
var FENCE_OPEN = /^ {0,3}(`{3,}|~{3,})([^\r\n]*)\r?$/;
|
|
453
|
+
var FENCE_CLOSE = /^ {0,3}(`+|~+)[ \t]*\r?$/;
|
|
454
|
+
function maskFencedCode(body, fill) {
|
|
455
|
+
const { lines } = scanFencedCode(body);
|
|
456
|
+
return lines.map(({ line, inCode }) => inCode ? fill(line) : line).join(`
|
|
457
|
+
`);
|
|
458
|
+
}
|
|
459
|
+
function scanFencedCode(body) {
|
|
460
|
+
let fenceChar = null;
|
|
461
|
+
let fenceLen = 0;
|
|
462
|
+
const lines = body.split(`
|
|
463
|
+
`).map((line) => {
|
|
464
|
+
if (fenceChar === null) {
|
|
465
|
+
const open = line.match(FENCE_OPEN);
|
|
466
|
+
if (!open)
|
|
467
|
+
return { line, inCode: false };
|
|
468
|
+
const marker = open[1];
|
|
469
|
+
if (marker[0] === "`" && open[2].includes("`"))
|
|
470
|
+
return { line, inCode: false };
|
|
471
|
+
fenceChar = marker[0];
|
|
472
|
+
fenceLen = marker.length;
|
|
473
|
+
return { line, inCode: true };
|
|
474
|
+
}
|
|
475
|
+
const close = line.match(FENCE_CLOSE);
|
|
476
|
+
if (close && close[1][0] === fenceChar && close[1].length >= fenceLen) {
|
|
477
|
+
fenceChar = null;
|
|
478
|
+
fenceLen = 0;
|
|
479
|
+
}
|
|
480
|
+
return { line, inCode: true };
|
|
481
|
+
});
|
|
482
|
+
return { lines, unterminated: fenceChar !== null };
|
|
483
|
+
}
|
|
484
|
+
function hasUnterminatedFence(body) {
|
|
485
|
+
return scanFencedCode(body.replace(/\r\n?/g, `
|
|
486
|
+
`)).unterminated;
|
|
487
|
+
}
|
|
488
|
+
var LIST_MARKER = /^ {0,3}(?:[-*+]|\d{1,9}[.)])(?:\s|$)/;
|
|
489
|
+
function indentWidth(line) {
|
|
490
|
+
let width = 0;
|
|
491
|
+
for (const ch of line) {
|
|
492
|
+
if (ch === " ")
|
|
493
|
+
width += 1;
|
|
494
|
+
else if (ch === "\t")
|
|
495
|
+
width += 4;
|
|
496
|
+
else
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
return width;
|
|
500
|
+
}
|
|
501
|
+
function maskIndentedCode(body, fill) {
|
|
502
|
+
const lines = body.split(`
|
|
503
|
+
`);
|
|
504
|
+
let inList = false;
|
|
505
|
+
let inCode = false;
|
|
506
|
+
let prevBlank = true;
|
|
507
|
+
const out = lines.map((line) => {
|
|
508
|
+
if (line.trim() === "") {
|
|
509
|
+
prevBlank = true;
|
|
510
|
+
return line;
|
|
511
|
+
}
|
|
512
|
+
const indent = indentWidth(line);
|
|
513
|
+
if (indent >= 4 && (inCode || prevBlank && !inList)) {
|
|
514
|
+
inCode = true;
|
|
515
|
+
prevBlank = false;
|
|
516
|
+
return fill(line);
|
|
517
|
+
}
|
|
518
|
+
inCode = false;
|
|
519
|
+
if (indent < 4 && LIST_MARKER.test(line))
|
|
520
|
+
inList = true;
|
|
521
|
+
else if (indent === 0)
|
|
522
|
+
inList = false;
|
|
523
|
+
prevBlank = false;
|
|
524
|
+
return line;
|
|
525
|
+
});
|
|
526
|
+
return out.join(`
|
|
527
|
+
`);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// ../../packages/aeg-forge-state/src/list-tasks.ts
|
|
531
|
+
var TITLE_PATTERN = /^\[([^\]]+)]\s*(\S+)\s*—\s*(.+)$/;
|
|
532
|
+
var PROJECT_SLUG = /^[a-z0-9][a-z0-9-]*$/i;
|
|
533
|
+
var PROJECT_FIELD = /^\s*(?:\*\*)?Project(?:\(s\))?(?:\*\*)?\s*:\s*(?:\*\*)?\s*(.+)$/im;
|
|
534
|
+
var VALUE_EDGE_MARKUP = /^[`.;\s]+|[`.;\s]+$/g;
|
|
535
|
+
function unwrapValue(raw) {
|
|
536
|
+
return raw.replace(/\*\*/g, "").replace(VALUE_EDGE_MARKUP, "");
|
|
537
|
+
}
|
|
538
|
+
function projectFieldFromBody(body) {
|
|
539
|
+
const m = stripCode(body, { inlineSpans: "keep" }).match(PROJECT_FIELD);
|
|
540
|
+
if (m)
|
|
541
|
+
return parseFieldValue(m[1] ?? "");
|
|
542
|
+
if (hasUnterminatedFence(body)) {
|
|
543
|
+
const raw = body.match(PROJECT_FIELD);
|
|
544
|
+
if (raw)
|
|
545
|
+
return { declared: true, names: [], unparsed: [(raw[1] ?? "").trim()], unreadable: true };
|
|
546
|
+
}
|
|
547
|
+
return { declared: false, names: [], unparsed: [], unreadable: false };
|
|
548
|
+
}
|
|
549
|
+
function parseFieldValue(value) {
|
|
550
|
+
const names = [];
|
|
551
|
+
const unparsed = [];
|
|
552
|
+
for (const raw of value.split(",")) {
|
|
553
|
+
const name = unwrapValue(raw);
|
|
554
|
+
if (name.length === 0)
|
|
555
|
+
continue;
|
|
556
|
+
if (PROJECT_SLUG.test(name))
|
|
557
|
+
names.push(name);
|
|
558
|
+
else
|
|
559
|
+
unparsed.push(raw.trim());
|
|
560
|
+
}
|
|
561
|
+
return { declared: true, names: [...new Set(names)], unparsed, unreadable: false };
|
|
562
|
+
}
|
|
563
|
+
function projectsFromBody(body) {
|
|
564
|
+
return projectFieldFromBody(body).names;
|
|
565
|
+
}
|
|
566
|
+
function taskFromIssue(issue) {
|
|
567
|
+
const m = issue.title.match(TITLE_PATTERN);
|
|
568
|
+
if (!m)
|
|
569
|
+
return null;
|
|
570
|
+
const id = (m[2] ?? "").trim();
|
|
571
|
+
const title = (m[3] ?? "").trim();
|
|
572
|
+
if (!id || !title)
|
|
573
|
+
return null;
|
|
574
|
+
const body = issue.body ?? "";
|
|
575
|
+
const { dependsOn, conflictsWith } = parseRationaleDeps(body);
|
|
576
|
+
return {
|
|
577
|
+
id,
|
|
578
|
+
title,
|
|
579
|
+
issue: issue.number,
|
|
580
|
+
projects: projectsFromBody(body),
|
|
581
|
+
dependsOn,
|
|
582
|
+
conflictsWith,
|
|
583
|
+
rationaleMarkdown: body
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
function compareTaskIds(a, b) {
|
|
587
|
+
const numA = a.match(/^(\d+)(.*)$/);
|
|
588
|
+
const numB = b.match(/^(\d+)(.*)$/);
|
|
589
|
+
if (numA && numB) {
|
|
590
|
+
const diff = Number(numA[1]) - Number(numB[1]);
|
|
591
|
+
if (diff !== 0)
|
|
592
|
+
return diff;
|
|
593
|
+
return (numA[2] ?? "").localeCompare(numB[2] ?? "");
|
|
594
|
+
}
|
|
595
|
+
return a.localeCompare(b);
|
|
596
|
+
}
|
|
597
|
+
function tasksFromIssues(issues) {
|
|
598
|
+
const tasks = [];
|
|
599
|
+
for (const issue of issues) {
|
|
600
|
+
const task = taskFromIssue(issue);
|
|
601
|
+
if (task)
|
|
602
|
+
tasks.push(task);
|
|
603
|
+
}
|
|
604
|
+
return tasks.sort((a, b) => compareTaskIds(a.id, b.id));
|
|
605
|
+
}
|
|
606
|
+
async function fetchTrancheIssuesAsync(owner, repo, slug) {
|
|
607
|
+
return ghIssueListByAnyLabelAsync(owner, repo, [trancheLabel(slug)]);
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
// ../../packages/aeg-forge-state/src/fetch-milestone.ts
|
|
611
|
+
var INTENTS_HEADING = /^#{1,6}\s*Tranche intents\s*$/im;
|
|
612
|
+
var NEXT_HEADING = /^#{1,6}\s+\S/m;
|
|
613
|
+
var INTENT_BULLET = /^-\s+([a-z0-9][a-z0-9-]*)\s*:\s*(.+)$/i;
|
|
614
|
+
function intentsSection(text) {
|
|
615
|
+
const start = text.match(INTENTS_HEADING);
|
|
616
|
+
if (!start || start.index === undefined)
|
|
617
|
+
return null;
|
|
618
|
+
const rest = text.slice(start.index + start[0].length);
|
|
619
|
+
const next = rest.match(NEXT_HEADING);
|
|
620
|
+
return rest.slice(0, next && next.index !== undefined ? next.index : rest.length);
|
|
621
|
+
}
|
|
622
|
+
function intentGoalForSlug(description, slug) {
|
|
623
|
+
const text = stripCode(description, { inlineSpans: "keep" });
|
|
624
|
+
const section = intentsSection(text);
|
|
625
|
+
if (section === null)
|
|
626
|
+
return "";
|
|
627
|
+
for (const line of section.split(`
|
|
628
|
+
`)) {
|
|
629
|
+
const trimmed = line.trim();
|
|
630
|
+
if (trimmed.length === 0)
|
|
631
|
+
continue;
|
|
632
|
+
const m = trimmed.match(INTENT_BULLET);
|
|
633
|
+
if (m && (m[1] ?? "").toLowerCase() === slug.toLowerCase())
|
|
634
|
+
return (m[2] ?? "").trim();
|
|
635
|
+
}
|
|
636
|
+
return "";
|
|
637
|
+
}
|
|
638
|
+
function matchesLegacyMilestone(milestones, slug) {
|
|
639
|
+
return milestones.find((m) => m.title === slug) ?? null;
|
|
640
|
+
}
|
|
641
|
+
var TRANCHE_SLUG_SHAPE = /^[a-z0-9]+(?:-[a-z0-9]+)*-v\d+$/;
|
|
642
|
+
function slugShapedTitles(milestones) {
|
|
643
|
+
return milestones.map((m) => m.title).filter((t) => TRANCHE_SLUG_SHAPE.test(t));
|
|
644
|
+
}
|
|
645
|
+
function factsFromLegacyMilestone(milestone) {
|
|
646
|
+
return {
|
|
647
|
+
goal: milestone.description ?? "",
|
|
648
|
+
lifecycle: milestone.state === "closed" ? "complete" : "active"
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
function resolveLegacyFacts(milestone, labelIssues) {
|
|
652
|
+
if (milestone.state === "closed" && labelIssues.length > 0) {
|
|
653
|
+
return { goal: milestone.description ?? "", lifecycle: lifecycleFromIssues(labelIssues) };
|
|
654
|
+
}
|
|
655
|
+
return factsFromLegacyMilestone(milestone);
|
|
656
|
+
}
|
|
657
|
+
function lifecycleFromIssues(issues) {
|
|
658
|
+
if (issues.length === 0)
|
|
659
|
+
return "planned";
|
|
660
|
+
return issues.some((i) => i.state === "OPEN") ? "active" : "complete";
|
|
661
|
+
}
|
|
662
|
+
function goalFromMilestones(milestones, slug) {
|
|
663
|
+
for (const m of milestones) {
|
|
664
|
+
const goal = intentGoalForSlug(m.description ?? "", slug);
|
|
665
|
+
if (goal)
|
|
666
|
+
return goal;
|
|
667
|
+
}
|
|
668
|
+
return "";
|
|
669
|
+
}
|
|
670
|
+
function findMilestoneForSlug(owner, repo, slug) {
|
|
671
|
+
const milestones = ghApiGet(`repos/${owner}/${repo}/milestones?state=all&per_page=100`);
|
|
672
|
+
const legacy = matchesLegacyMilestone(milestones, slug);
|
|
673
|
+
const issues = ghIssueListByLabel(owner, repo, trancheLabel(slug));
|
|
674
|
+
if (legacy)
|
|
675
|
+
return resolveLegacyFacts(legacy, issues);
|
|
676
|
+
return { goal: goalFromMilestones(milestones, slug), lifecycle: lifecycleFromIssues(issues) };
|
|
677
|
+
}
|
|
678
|
+
function trancheSlugsFromLabels(labels) {
|
|
679
|
+
const slugs = [];
|
|
680
|
+
for (const l of labels) {
|
|
681
|
+
const slug = trancheSlugOf(l.name);
|
|
682
|
+
if (slug !== null)
|
|
683
|
+
slugs.push(slug);
|
|
684
|
+
}
|
|
685
|
+
return slugs;
|
|
686
|
+
}
|
|
687
|
+
function listActiveTrancheSlugs(owner, repo) {
|
|
688
|
+
const milestones = ghApiGet(`repos/${owner}/${repo}/milestones?state=all&per_page=100`);
|
|
689
|
+
const labels = ghApiGet(`repos/${owner}/${repo}/labels?per_page=100`);
|
|
690
|
+
const slugs = new Set([...slugShapedTitles(milestones), ...trancheSlugsFromLabels(labels)]);
|
|
691
|
+
const active = [];
|
|
692
|
+
for (const slug of slugs) {
|
|
693
|
+
const legacy = matchesLegacyMilestone(milestones, slug);
|
|
694
|
+
const issues = ghIssueListByLabel(owner, repo, trancheLabel(slug));
|
|
695
|
+
if (legacy) {
|
|
696
|
+
const facts = resolveLegacyFacts(legacy, issues);
|
|
697
|
+
if (facts.lifecycle === "active")
|
|
698
|
+
active.push({ slug, goal: facts.goal });
|
|
699
|
+
continue;
|
|
700
|
+
}
|
|
701
|
+
if (lifecycleFromIssues(issues) === "active")
|
|
702
|
+
active.push({ slug, goal: goalFromMilestones(milestones, slug) });
|
|
703
|
+
}
|
|
704
|
+
return active;
|
|
705
|
+
}
|
|
706
|
+
async function tranchesAttachedToMilestone(owner, repo, milestoneNumber) {
|
|
707
|
+
const issues = await ghApiGetAllPagesAsync(`repos/${owner}/${repo}/issues?milestone=${milestoneNumber}&state=all`, { jq: "[.[] | {labels: .labels}]" });
|
|
708
|
+
const slugs = new Set;
|
|
709
|
+
for (const issue of issues) {
|
|
710
|
+
for (const label of issue.labels) {
|
|
711
|
+
const name = typeof label === "string" ? label : label.name;
|
|
712
|
+
const slug = trancheSlugOf(name);
|
|
713
|
+
if (slug !== null)
|
|
714
|
+
slugs.add(slug);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return [...slugs];
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// ../../packages/aeg-forge-state/src/derive-from-forge.ts
|
|
721
|
+
function trancheFromIssues(slug, issues, known) {
|
|
722
|
+
return {
|
|
723
|
+
name: slug,
|
|
724
|
+
lifecycle: known?.lifecycle ?? "active",
|
|
725
|
+
goal: known?.goal ?? "",
|
|
726
|
+
tasks: tasksFromIssues(issues),
|
|
727
|
+
backlog: []
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
async function deriveTrancheFromForge(owner, repo, slug, known) {
|
|
731
|
+
const milestone = known ?? findMilestoneForSlug(owner, repo, slug);
|
|
732
|
+
const issues = await fetchTrancheIssuesAsync(owner, repo, slug);
|
|
733
|
+
return trancheFromIssues(slug, issues, milestone);
|
|
734
|
+
}
|
|
735
|
+
// ../../node_modules/universal-user-agent/index.js
|
|
736
|
+
function getUserAgent() {
|
|
737
|
+
if (typeof navigator === "object" && "userAgent" in navigator) {
|
|
738
|
+
return navigator.userAgent;
|
|
739
|
+
}
|
|
740
|
+
if (typeof process === "object" && process.version !== undefined) {
|
|
741
|
+
return `Node.js/${process.version.substr(1)} (${process.platform}; ${process.arch})`;
|
|
742
|
+
}
|
|
743
|
+
return "<environment undetectable>";
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// ../../node_modules/@octokit/endpoint/dist-bundle/index.js
|
|
747
|
+
var VERSION = "0.0.0-development";
|
|
748
|
+
var userAgent = `octokit-endpoint.js/${VERSION} ${getUserAgent()}`;
|
|
749
|
+
var DEFAULTS = {
|
|
750
|
+
method: "GET",
|
|
751
|
+
baseUrl: "https://api.github.com",
|
|
752
|
+
headers: {
|
|
753
|
+
accept: "application/vnd.github.v3+json",
|
|
754
|
+
"user-agent": userAgent
|
|
755
|
+
},
|
|
756
|
+
mediaType: {
|
|
757
|
+
format: ""
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
function lowercaseKeys(object) {
|
|
761
|
+
if (!object) {
|
|
762
|
+
return {};
|
|
763
|
+
}
|
|
764
|
+
return Object.keys(object).reduce((newObj, key) => {
|
|
765
|
+
newObj[key.toLowerCase()] = object[key];
|
|
766
|
+
return newObj;
|
|
767
|
+
}, {});
|
|
768
|
+
}
|
|
769
|
+
function isPlainObject(value) {
|
|
770
|
+
if (typeof value !== "object" || value === null)
|
|
771
|
+
return false;
|
|
772
|
+
if (Object.prototype.toString.call(value) !== "[object Object]")
|
|
773
|
+
return false;
|
|
774
|
+
const proto = Object.getPrototypeOf(value);
|
|
775
|
+
if (proto === null)
|
|
776
|
+
return true;
|
|
777
|
+
const Ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
778
|
+
return typeof Ctor === "function" && Ctor instanceof Ctor && Function.prototype.call(Ctor) === Function.prototype.call(value);
|
|
779
|
+
}
|
|
780
|
+
function mergeDeep(defaults, options) {
|
|
781
|
+
const result = Object.assign({}, defaults);
|
|
782
|
+
Object.keys(options).forEach((key) => {
|
|
783
|
+
if (isPlainObject(options[key])) {
|
|
784
|
+
if (!(key in defaults))
|
|
785
|
+
Object.assign(result, { [key]: options[key] });
|
|
786
|
+
else
|
|
787
|
+
result[key] = mergeDeep(defaults[key], options[key]);
|
|
788
|
+
} else {
|
|
789
|
+
Object.assign(result, { [key]: options[key] });
|
|
790
|
+
}
|
|
791
|
+
});
|
|
792
|
+
return result;
|
|
793
|
+
}
|
|
794
|
+
function removeUndefinedProperties(obj) {
|
|
795
|
+
for (const key in obj) {
|
|
796
|
+
if (obj[key] === undefined) {
|
|
797
|
+
delete obj[key];
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
return obj;
|
|
801
|
+
}
|
|
802
|
+
function merge(defaults, route, options) {
|
|
803
|
+
if (typeof route === "string") {
|
|
804
|
+
let [method, url] = route.split(" ");
|
|
805
|
+
options = Object.assign(url ? { method, url } : { url: method }, options);
|
|
806
|
+
} else {
|
|
807
|
+
options = Object.assign({}, route);
|
|
808
|
+
}
|
|
809
|
+
options.headers = lowercaseKeys(options.headers);
|
|
810
|
+
removeUndefinedProperties(options);
|
|
811
|
+
removeUndefinedProperties(options.headers);
|
|
812
|
+
const mergedOptions = mergeDeep(defaults || {}, options);
|
|
813
|
+
if (options.url === "/graphql") {
|
|
814
|
+
if (defaults && defaults.mediaType.previews?.length) {
|
|
815
|
+
mergedOptions.mediaType.previews = defaults.mediaType.previews.filter((preview) => !mergedOptions.mediaType.previews.includes(preview)).concat(mergedOptions.mediaType.previews);
|
|
816
|
+
}
|
|
817
|
+
mergedOptions.mediaType.previews = (mergedOptions.mediaType.previews || []).map((preview) => preview.replace(/-preview/, ""));
|
|
818
|
+
}
|
|
819
|
+
return mergedOptions;
|
|
820
|
+
}
|
|
821
|
+
function addQueryParameters(url, parameters) {
|
|
822
|
+
const separator = /\?/.test(url) ? "&" : "?";
|
|
823
|
+
const names = Object.keys(parameters);
|
|
824
|
+
if (names.length === 0) {
|
|
825
|
+
return url;
|
|
826
|
+
}
|
|
827
|
+
return url + separator + names.map((name) => {
|
|
828
|
+
if (name === "q") {
|
|
829
|
+
return "q=" + parameters.q.split("+").map(encodeURIComponent).join("+");
|
|
830
|
+
}
|
|
831
|
+
return `${name}=${encodeURIComponent(parameters[name])}`;
|
|
832
|
+
}).join("&");
|
|
833
|
+
}
|
|
834
|
+
var urlVariableRegex = /\{[^{}}]+\}/g;
|
|
835
|
+
function removeNonChars(variableName) {
|
|
836
|
+
return variableName.replace(/(?:^\W+)|(?:(?<!\W)\W+$)/g, "").split(/,/);
|
|
837
|
+
}
|
|
838
|
+
function extractUrlVariableNames(url) {
|
|
839
|
+
const matches = url.match(urlVariableRegex);
|
|
840
|
+
if (!matches) {
|
|
841
|
+
return [];
|
|
842
|
+
}
|
|
843
|
+
return matches.map(removeNonChars).reduce((a, b) => a.concat(b), []);
|
|
844
|
+
}
|
|
845
|
+
function omit(object, keysToOmit) {
|
|
846
|
+
const result = { __proto__: null };
|
|
847
|
+
for (const key of Object.keys(object)) {
|
|
848
|
+
if (keysToOmit.indexOf(key) === -1) {
|
|
849
|
+
result[key] = object[key];
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return result;
|
|
853
|
+
}
|
|
854
|
+
function encodeReserved(str) {
|
|
855
|
+
return str.split(/(%[0-9A-Fa-f]{2})/g).map(function(part) {
|
|
856
|
+
if (!/%[0-9A-Fa-f]/.test(part)) {
|
|
857
|
+
part = encodeURI(part).replace(/%5B/g, "[").replace(/%5D/g, "]");
|
|
858
|
+
}
|
|
859
|
+
return part;
|
|
860
|
+
}).join("");
|
|
861
|
+
}
|
|
862
|
+
function encodeUnreserved(str) {
|
|
863
|
+
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
|
|
864
|
+
return "%" + c.charCodeAt(0).toString(16).toUpperCase();
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
function encodeValue(operator, value, key) {
|
|
868
|
+
value = operator === "+" || operator === "#" ? encodeReserved(value) : encodeUnreserved(value);
|
|
869
|
+
if (key) {
|
|
870
|
+
return encodeUnreserved(key) + "=" + value;
|
|
871
|
+
} else {
|
|
872
|
+
return value;
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
function isDefined(value) {
|
|
876
|
+
return value !== undefined && value !== null;
|
|
877
|
+
}
|
|
878
|
+
function isKeyOperator(operator) {
|
|
879
|
+
return operator === ";" || operator === "&" || operator === "?";
|
|
880
|
+
}
|
|
881
|
+
function getValues(context, operator, key, modifier) {
|
|
882
|
+
var value = context[key], result = [];
|
|
883
|
+
if (isDefined(value) && value !== "") {
|
|
884
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
885
|
+
value = value.toString();
|
|
886
|
+
if (modifier && modifier !== "*") {
|
|
887
|
+
value = value.substring(0, parseInt(modifier, 10));
|
|
888
|
+
}
|
|
889
|
+
result.push(encodeValue(operator, value, isKeyOperator(operator) ? key : ""));
|
|
890
|
+
} else {
|
|
891
|
+
if (modifier === "*") {
|
|
892
|
+
if (Array.isArray(value)) {
|
|
893
|
+
value.filter(isDefined).forEach(function(value2) {
|
|
894
|
+
result.push(encodeValue(operator, value2, isKeyOperator(operator) ? key : ""));
|
|
895
|
+
});
|
|
896
|
+
} else {
|
|
897
|
+
Object.keys(value).forEach(function(k) {
|
|
898
|
+
if (isDefined(value[k])) {
|
|
899
|
+
result.push(encodeValue(operator, value[k], k));
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
} else {
|
|
904
|
+
const tmp = [];
|
|
905
|
+
if (Array.isArray(value)) {
|
|
906
|
+
value.filter(isDefined).forEach(function(value2) {
|
|
907
|
+
tmp.push(encodeValue(operator, value2));
|
|
908
|
+
});
|
|
909
|
+
} else {
|
|
910
|
+
Object.keys(value).forEach(function(k) {
|
|
911
|
+
if (isDefined(value[k])) {
|
|
912
|
+
tmp.push(encodeUnreserved(k));
|
|
913
|
+
tmp.push(encodeValue(operator, value[k].toString()));
|
|
914
|
+
}
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
if (isKeyOperator(operator)) {
|
|
918
|
+
result.push(encodeUnreserved(key) + "=" + tmp.join(","));
|
|
919
|
+
} else if (tmp.length !== 0) {
|
|
920
|
+
result.push(tmp.join(","));
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
} else {
|
|
925
|
+
if (operator === ";") {
|
|
926
|
+
if (isDefined(value)) {
|
|
927
|
+
result.push(encodeUnreserved(key));
|
|
928
|
+
}
|
|
929
|
+
} else if (value === "" && (operator === "&" || operator === "?")) {
|
|
930
|
+
result.push(encodeUnreserved(key) + "=");
|
|
931
|
+
} else if (value === "") {
|
|
932
|
+
result.push("");
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
return result;
|
|
936
|
+
}
|
|
937
|
+
function parseUrl(template) {
|
|
938
|
+
return {
|
|
939
|
+
expand: expand.bind(null, template)
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
function expand(template, context) {
|
|
943
|
+
var operators = ["+", "#", ".", "/", ";", "?", "&"];
|
|
944
|
+
template = template.replace(/\{([^\{\}]+)\}|([^\{\}]+)/g, function(_, expression, literal) {
|
|
945
|
+
if (expression) {
|
|
946
|
+
let operator = "";
|
|
947
|
+
const values = [];
|
|
948
|
+
if (operators.indexOf(expression.charAt(0)) !== -1) {
|
|
949
|
+
operator = expression.charAt(0);
|
|
950
|
+
expression = expression.substr(1);
|
|
951
|
+
}
|
|
952
|
+
expression.split(/,/g).forEach(function(variable) {
|
|
953
|
+
var tmp = /([^:\*]*)(?::(\d+)|(\*))?/.exec(variable);
|
|
954
|
+
values.push(getValues(context, operator, tmp[1], tmp[2] || tmp[3]));
|
|
955
|
+
});
|
|
956
|
+
if (operator && operator !== "+") {
|
|
957
|
+
var separator = ",";
|
|
958
|
+
if (operator === "?") {
|
|
959
|
+
separator = "&";
|
|
960
|
+
} else if (operator !== "#") {
|
|
961
|
+
separator = operator;
|
|
962
|
+
}
|
|
963
|
+
return (values.length !== 0 ? operator : "") + values.join(separator);
|
|
964
|
+
} else {
|
|
965
|
+
return values.join(",");
|
|
966
|
+
}
|
|
967
|
+
} else {
|
|
968
|
+
return encodeReserved(literal);
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
if (template === "/") {
|
|
972
|
+
return template;
|
|
973
|
+
} else {
|
|
974
|
+
return template.replace(/\/$/, "");
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
function parse(options) {
|
|
978
|
+
let method = options.method.toUpperCase();
|
|
979
|
+
let url = (options.url || "/").replace(/:([a-z]\w+)/g, "{$1}");
|
|
980
|
+
let headers = Object.assign({}, options.headers);
|
|
981
|
+
let body;
|
|
982
|
+
let parameters = omit(options, [
|
|
983
|
+
"method",
|
|
984
|
+
"baseUrl",
|
|
985
|
+
"url",
|
|
986
|
+
"headers",
|
|
987
|
+
"request",
|
|
988
|
+
"mediaType"
|
|
989
|
+
]);
|
|
990
|
+
const urlVariableNames = extractUrlVariableNames(url);
|
|
991
|
+
url = parseUrl(url).expand(parameters);
|
|
992
|
+
if (!/^http/.test(url)) {
|
|
993
|
+
url = options.baseUrl + url;
|
|
994
|
+
}
|
|
995
|
+
const omittedParameters = Object.keys(options).filter((option) => urlVariableNames.includes(option)).concat("baseUrl");
|
|
996
|
+
const remainingParameters = omit(parameters, omittedParameters);
|
|
997
|
+
const isBinaryRequest = /application\/octet-stream/i.test(headers.accept);
|
|
998
|
+
if (!isBinaryRequest) {
|
|
999
|
+
if (options.mediaType.format) {
|
|
1000
|
+
headers.accept = headers.accept.split(/,/).map((format) => format.replace(/application\/vnd(\.\w+)(\.v3)?(\.\w+)?(\+json)?$/, `application/vnd$1$2.${options.mediaType.format}`)).join(",");
|
|
1001
|
+
}
|
|
1002
|
+
if (url.endsWith("/graphql")) {
|
|
1003
|
+
if (options.mediaType.previews?.length) {
|
|
1004
|
+
const previewsFromAcceptHeader = headers.accept.match(/(?<![\w-])[\w-]+(?=-preview)/g) || [];
|
|
1005
|
+
headers.accept = previewsFromAcceptHeader.concat(options.mediaType.previews).map((preview) => {
|
|
1006
|
+
const format = options.mediaType.format ? `.${options.mediaType.format}` : "+json";
|
|
1007
|
+
return `application/vnd.github.${preview}-preview${format}`;
|
|
1008
|
+
}).join(",");
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
if (["GET", "HEAD"].includes(method)) {
|
|
1013
|
+
url = addQueryParameters(url, remainingParameters);
|
|
1014
|
+
} else {
|
|
1015
|
+
if ("data" in remainingParameters) {
|
|
1016
|
+
body = remainingParameters.data;
|
|
1017
|
+
} else {
|
|
1018
|
+
if (Object.keys(remainingParameters).length) {
|
|
1019
|
+
body = remainingParameters;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
if (!headers["content-type"] && typeof body !== "undefined") {
|
|
1024
|
+
headers["content-type"] = "application/json; charset=utf-8";
|
|
1025
|
+
}
|
|
1026
|
+
if (["PATCH", "PUT"].includes(method) && typeof body === "undefined") {
|
|
1027
|
+
body = "";
|
|
1028
|
+
}
|
|
1029
|
+
return Object.assign({ method, url, headers }, typeof body !== "undefined" ? { body } : null, options.request ? { request: options.request } : null);
|
|
1030
|
+
}
|
|
1031
|
+
function endpointWithDefaults(defaults, route, options) {
|
|
1032
|
+
return parse(merge(defaults, route, options));
|
|
1033
|
+
}
|
|
1034
|
+
function withDefaults(oldDefaults, newDefaults) {
|
|
1035
|
+
const DEFAULTS2 = merge(oldDefaults, newDefaults);
|
|
1036
|
+
const endpoint2 = endpointWithDefaults.bind(null, DEFAULTS2);
|
|
1037
|
+
return Object.assign(endpoint2, {
|
|
1038
|
+
DEFAULTS: DEFAULTS2,
|
|
1039
|
+
defaults: withDefaults.bind(null, DEFAULTS2),
|
|
1040
|
+
merge: merge.bind(null, DEFAULTS2),
|
|
1041
|
+
parse
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
var endpoint = withDefaults(null, DEFAULTS);
|
|
1045
|
+
|
|
1046
|
+
// ../../node_modules/fast-content-type-parse/index.js
|
|
1047
|
+
var NullObject = function NullObject() {};
|
|
1048
|
+
NullObject.prototype = Object.create(null);
|
|
1049
|
+
var paramRE = /; *([!#$%&'*+.^\w`|~-]+)=("(?:[\v\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\v\u0020-\u00ff])*"|[!#$%&'*+.^\w`|~-]+) */gu;
|
|
1050
|
+
var quotedPairRE = /\\([\v\u0020-\u00ff])/gu;
|
|
1051
|
+
var mediaTypeRE = /^[!#$%&'*+.^\w|~-]+\/[!#$%&'*+.^\w|~-]+$/u;
|
|
1052
|
+
var defaultContentType = { type: "", parameters: new NullObject };
|
|
1053
|
+
Object.freeze(defaultContentType.parameters);
|
|
1054
|
+
Object.freeze(defaultContentType);
|
|
1055
|
+
function safeParse(header) {
|
|
1056
|
+
if (typeof header !== "string") {
|
|
1057
|
+
return defaultContentType;
|
|
1058
|
+
}
|
|
1059
|
+
let index = header.indexOf(";");
|
|
1060
|
+
const type = index !== -1 ? header.slice(0, index).trim() : header.trim();
|
|
1061
|
+
if (mediaTypeRE.test(type) === false) {
|
|
1062
|
+
return defaultContentType;
|
|
1063
|
+
}
|
|
1064
|
+
const result = {
|
|
1065
|
+
type: type.toLowerCase(),
|
|
1066
|
+
parameters: new NullObject
|
|
1067
|
+
};
|
|
1068
|
+
if (index === -1) {
|
|
1069
|
+
return result;
|
|
1070
|
+
}
|
|
1071
|
+
let key;
|
|
1072
|
+
let match;
|
|
1073
|
+
let value;
|
|
1074
|
+
paramRE.lastIndex = index;
|
|
1075
|
+
while (match = paramRE.exec(header)) {
|
|
1076
|
+
if (match.index !== index) {
|
|
1077
|
+
return defaultContentType;
|
|
1078
|
+
}
|
|
1079
|
+
index += match[0].length;
|
|
1080
|
+
key = match[1].toLowerCase();
|
|
1081
|
+
value = match[2];
|
|
1082
|
+
if (value[0] === '"') {
|
|
1083
|
+
value = value.slice(1, value.length - 1);
|
|
1084
|
+
quotedPairRE.test(value) && (value = value.replace(quotedPairRE, "$1"));
|
|
1085
|
+
}
|
|
1086
|
+
result.parameters[key] = value;
|
|
1087
|
+
}
|
|
1088
|
+
if (index !== header.length) {
|
|
1089
|
+
return defaultContentType;
|
|
1090
|
+
}
|
|
1091
|
+
return result;
|
|
1092
|
+
}
|
|
1093
|
+
var $safeParse = safeParse;
|
|
1094
|
+
|
|
1095
|
+
// ../../node_modules/@octokit/request-error/dist-src/index.js
|
|
1096
|
+
class RequestError extends Error {
|
|
1097
|
+
name;
|
|
1098
|
+
status;
|
|
1099
|
+
request;
|
|
1100
|
+
response;
|
|
1101
|
+
constructor(message, statusCode, options) {
|
|
1102
|
+
super(message);
|
|
1103
|
+
this.name = "HttpError";
|
|
1104
|
+
this.status = Number.parseInt(statusCode);
|
|
1105
|
+
if (Number.isNaN(this.status)) {
|
|
1106
|
+
this.status = 0;
|
|
1107
|
+
}
|
|
1108
|
+
if ("response" in options) {
|
|
1109
|
+
this.response = options.response;
|
|
1110
|
+
}
|
|
1111
|
+
const requestCopy = Object.assign({}, options.request);
|
|
1112
|
+
if (options.request.headers.authorization) {
|
|
1113
|
+
requestCopy.headers = Object.assign({}, options.request.headers, {
|
|
1114
|
+
authorization: options.request.headers.authorization.replace(/(?<! ) .*$/, " [REDACTED]")
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
requestCopy.url = requestCopy.url.replace(/\bclient_secret=\w+/g, "client_secret=[REDACTED]").replace(/\baccess_token=\w+/g, "access_token=[REDACTED]");
|
|
1118
|
+
this.request = requestCopy;
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
// ../../node_modules/@octokit/request/dist-bundle/index.js
|
|
1123
|
+
var VERSION2 = "9.2.4";
|
|
1124
|
+
var defaults_default = {
|
|
1125
|
+
headers: {
|
|
1126
|
+
"user-agent": `octokit-request.js/${VERSION2} ${getUserAgent()}`
|
|
1127
|
+
}
|
|
1128
|
+
};
|
|
1129
|
+
function isPlainObject2(value) {
|
|
1130
|
+
if (typeof value !== "object" || value === null)
|
|
1131
|
+
return false;
|
|
1132
|
+
if (Object.prototype.toString.call(value) !== "[object Object]")
|
|
1133
|
+
return false;
|
|
1134
|
+
const proto = Object.getPrototypeOf(value);
|
|
1135
|
+
if (proto === null)
|
|
1136
|
+
return true;
|
|
1137
|
+
const Ctor = Object.prototype.hasOwnProperty.call(proto, "constructor") && proto.constructor;
|
|
1138
|
+
return typeof Ctor === "function" && Ctor instanceof Ctor && Function.prototype.call(Ctor) === Function.prototype.call(value);
|
|
1139
|
+
}
|
|
1140
|
+
async function fetchWrapper(requestOptions) {
|
|
1141
|
+
const fetch = requestOptions.request?.fetch || globalThis.fetch;
|
|
1142
|
+
if (!fetch) {
|
|
1143
|
+
throw new Error("fetch is not set. Please pass a fetch implementation as new Octokit({ request: { fetch }}). Learn more at https://github.com/octokit/octokit.js/#fetch-missing");
|
|
1144
|
+
}
|
|
1145
|
+
const log = requestOptions.request?.log || console;
|
|
1146
|
+
const parseSuccessResponseBody = requestOptions.request?.parseSuccessResponseBody !== false;
|
|
1147
|
+
const body = isPlainObject2(requestOptions.body) || Array.isArray(requestOptions.body) ? JSON.stringify(requestOptions.body) : requestOptions.body;
|
|
1148
|
+
const requestHeaders = Object.fromEntries(Object.entries(requestOptions.headers).map(([name, value]) => [
|
|
1149
|
+
name,
|
|
1150
|
+
String(value)
|
|
1151
|
+
]));
|
|
1152
|
+
let fetchResponse;
|
|
1153
|
+
try {
|
|
1154
|
+
fetchResponse = await fetch(requestOptions.url, {
|
|
1155
|
+
method: requestOptions.method,
|
|
1156
|
+
body,
|
|
1157
|
+
redirect: requestOptions.request?.redirect,
|
|
1158
|
+
headers: requestHeaders,
|
|
1159
|
+
signal: requestOptions.request?.signal,
|
|
1160
|
+
...requestOptions.body && { duplex: "half" }
|
|
1161
|
+
});
|
|
1162
|
+
} catch (error) {
|
|
1163
|
+
let message = "Unknown Error";
|
|
1164
|
+
if (error instanceof Error) {
|
|
1165
|
+
if (error.name === "AbortError") {
|
|
1166
|
+
error.status = 500;
|
|
1167
|
+
throw error;
|
|
1168
|
+
}
|
|
1169
|
+
message = error.message;
|
|
1170
|
+
if (error.name === "TypeError" && "cause" in error) {
|
|
1171
|
+
if (error.cause instanceof Error) {
|
|
1172
|
+
message = error.cause.message;
|
|
1173
|
+
} else if (typeof error.cause === "string") {
|
|
1174
|
+
message = error.cause;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
const requestError = new RequestError(message, 500, {
|
|
1179
|
+
request: requestOptions
|
|
1180
|
+
});
|
|
1181
|
+
requestError.cause = error;
|
|
1182
|
+
throw requestError;
|
|
1183
|
+
}
|
|
1184
|
+
const status = fetchResponse.status;
|
|
1185
|
+
const url = fetchResponse.url;
|
|
1186
|
+
const responseHeaders = {};
|
|
1187
|
+
for (const [key, value] of fetchResponse.headers) {
|
|
1188
|
+
responseHeaders[key] = value;
|
|
1189
|
+
}
|
|
1190
|
+
const octokitResponse = {
|
|
1191
|
+
url,
|
|
1192
|
+
status,
|
|
1193
|
+
headers: responseHeaders,
|
|
1194
|
+
data: ""
|
|
1195
|
+
};
|
|
1196
|
+
if ("deprecation" in responseHeaders) {
|
|
1197
|
+
const matches = responseHeaders.link && responseHeaders.link.match(/<([^<>]+)>; rel="deprecation"/);
|
|
1198
|
+
const deprecationLink = matches && matches.pop();
|
|
1199
|
+
log.warn(`[@octokit/request] "${requestOptions.method} ${requestOptions.url}" is deprecated. It is scheduled to be removed on ${responseHeaders.sunset}${deprecationLink ? `. See ${deprecationLink}` : ""}`);
|
|
1200
|
+
}
|
|
1201
|
+
if (status === 204 || status === 205) {
|
|
1202
|
+
return octokitResponse;
|
|
1203
|
+
}
|
|
1204
|
+
if (requestOptions.method === "HEAD") {
|
|
1205
|
+
if (status < 400) {
|
|
1206
|
+
return octokitResponse;
|
|
1207
|
+
}
|
|
1208
|
+
throw new RequestError(fetchResponse.statusText, status, {
|
|
1209
|
+
response: octokitResponse,
|
|
1210
|
+
request: requestOptions
|
|
1211
|
+
});
|
|
1212
|
+
}
|
|
1213
|
+
if (status === 304) {
|
|
1214
|
+
octokitResponse.data = await getResponseData(fetchResponse);
|
|
1215
|
+
throw new RequestError("Not modified", status, {
|
|
1216
|
+
response: octokitResponse,
|
|
1217
|
+
request: requestOptions
|
|
1218
|
+
});
|
|
1219
|
+
}
|
|
1220
|
+
if (status >= 400) {
|
|
1221
|
+
octokitResponse.data = await getResponseData(fetchResponse);
|
|
1222
|
+
throw new RequestError(toErrorMessage(octokitResponse.data), status, {
|
|
1223
|
+
response: octokitResponse,
|
|
1224
|
+
request: requestOptions
|
|
1225
|
+
});
|
|
1226
|
+
}
|
|
1227
|
+
octokitResponse.data = parseSuccessResponseBody ? await getResponseData(fetchResponse) : fetchResponse.body;
|
|
1228
|
+
return octokitResponse;
|
|
1229
|
+
}
|
|
1230
|
+
async function getResponseData(response) {
|
|
1231
|
+
const contentType = response.headers.get("content-type");
|
|
1232
|
+
if (!contentType) {
|
|
1233
|
+
return response.text().catch(() => "");
|
|
1234
|
+
}
|
|
1235
|
+
const mimetype = $safeParse(contentType);
|
|
1236
|
+
if (isJSONResponse(mimetype)) {
|
|
1237
|
+
let text = "";
|
|
1238
|
+
try {
|
|
1239
|
+
text = await response.text();
|
|
1240
|
+
return JSON.parse(text);
|
|
1241
|
+
} catch (err) {
|
|
1242
|
+
return text;
|
|
1243
|
+
}
|
|
1244
|
+
} else if (mimetype.type.startsWith("text/") || mimetype.parameters.charset?.toLowerCase() === "utf-8") {
|
|
1245
|
+
return response.text().catch(() => "");
|
|
1246
|
+
} else {
|
|
1247
|
+
return response.arrayBuffer().catch(() => new ArrayBuffer(0));
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
function isJSONResponse(mimetype) {
|
|
1251
|
+
return mimetype.type === "application/json" || mimetype.type === "application/scim+json";
|
|
1252
|
+
}
|
|
1253
|
+
function toErrorMessage(data) {
|
|
1254
|
+
if (typeof data === "string") {
|
|
1255
|
+
return data;
|
|
1256
|
+
}
|
|
1257
|
+
if (data instanceof ArrayBuffer) {
|
|
1258
|
+
return "Unknown error";
|
|
1259
|
+
}
|
|
1260
|
+
if ("message" in data) {
|
|
1261
|
+
const suffix = "documentation_url" in data ? ` - ${data.documentation_url}` : "";
|
|
1262
|
+
return Array.isArray(data.errors) ? `${data.message}: ${data.errors.map((v) => JSON.stringify(v)).join(", ")}${suffix}` : `${data.message}${suffix}`;
|
|
1263
|
+
}
|
|
1264
|
+
return `Unknown error: ${JSON.stringify(data)}`;
|
|
1265
|
+
}
|
|
1266
|
+
function withDefaults2(oldEndpoint, newDefaults) {
|
|
1267
|
+
const endpoint2 = oldEndpoint.defaults(newDefaults);
|
|
1268
|
+
const newApi = function(route, parameters) {
|
|
1269
|
+
const endpointOptions = endpoint2.merge(route, parameters);
|
|
1270
|
+
if (!endpointOptions.request || !endpointOptions.request.hook) {
|
|
1271
|
+
return fetchWrapper(endpoint2.parse(endpointOptions));
|
|
1272
|
+
}
|
|
1273
|
+
const request2 = (route2, parameters2) => {
|
|
1274
|
+
return fetchWrapper(endpoint2.parse(endpoint2.merge(route2, parameters2)));
|
|
1275
|
+
};
|
|
1276
|
+
Object.assign(request2, {
|
|
1277
|
+
endpoint: endpoint2,
|
|
1278
|
+
defaults: withDefaults2.bind(null, endpoint2)
|
|
1279
|
+
});
|
|
1280
|
+
return endpointOptions.request.hook(request2, endpointOptions);
|
|
1281
|
+
};
|
|
1282
|
+
return Object.assign(newApi, {
|
|
1283
|
+
endpoint: endpoint2,
|
|
1284
|
+
defaults: withDefaults2.bind(null, endpoint2)
|
|
1285
|
+
});
|
|
1286
|
+
}
|
|
1287
|
+
var request = withDefaults2(endpoint, defaults_default);
|
|
1288
|
+
|
|
1289
|
+
// ../../node_modules/@octokit/graphql/dist-bundle/index.js
|
|
1290
|
+
var VERSION3 = "0.0.0-development";
|
|
1291
|
+
function _buildMessageForResponseErrors(data) {
|
|
1292
|
+
return `Request failed due to following response errors:
|
|
1293
|
+
` + data.errors.map((e) => ` - ${e.message}`).join(`
|
|
1294
|
+
`);
|
|
1295
|
+
}
|
|
1296
|
+
var GraphqlResponseError = class extends Error {
|
|
1297
|
+
constructor(request2, headers, response) {
|
|
1298
|
+
super(_buildMessageForResponseErrors(response));
|
|
1299
|
+
this.request = request2;
|
|
1300
|
+
this.headers = headers;
|
|
1301
|
+
this.response = response;
|
|
1302
|
+
this.errors = response.errors;
|
|
1303
|
+
this.data = response.data;
|
|
1304
|
+
if (Error.captureStackTrace) {
|
|
1305
|
+
Error.captureStackTrace(this, this.constructor);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
name = "GraphqlResponseError";
|
|
1309
|
+
errors;
|
|
1310
|
+
data;
|
|
1311
|
+
};
|
|
1312
|
+
var NON_VARIABLE_OPTIONS = [
|
|
1313
|
+
"method",
|
|
1314
|
+
"baseUrl",
|
|
1315
|
+
"url",
|
|
1316
|
+
"headers",
|
|
1317
|
+
"request",
|
|
1318
|
+
"query",
|
|
1319
|
+
"mediaType",
|
|
1320
|
+
"operationName"
|
|
1321
|
+
];
|
|
1322
|
+
var FORBIDDEN_VARIABLE_OPTIONS = ["query", "method", "url"];
|
|
1323
|
+
var GHES_V3_SUFFIX_REGEX = /\/api\/v3\/?$/;
|
|
1324
|
+
function graphql(request2, query, options) {
|
|
1325
|
+
if (options) {
|
|
1326
|
+
if (typeof query === "string" && "query" in options) {
|
|
1327
|
+
return Promise.reject(new Error(`[@octokit/graphql] "query" cannot be used as variable name`));
|
|
1328
|
+
}
|
|
1329
|
+
for (const key in options) {
|
|
1330
|
+
if (!FORBIDDEN_VARIABLE_OPTIONS.includes(key))
|
|
1331
|
+
continue;
|
|
1332
|
+
return Promise.reject(new Error(`[@octokit/graphql] "${key}" cannot be used as variable name`));
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
const parsedOptions = typeof query === "string" ? Object.assign({ query }, options) : query;
|
|
1336
|
+
const requestOptions = Object.keys(parsedOptions).reduce((result, key) => {
|
|
1337
|
+
if (NON_VARIABLE_OPTIONS.includes(key)) {
|
|
1338
|
+
result[key] = parsedOptions[key];
|
|
1339
|
+
return result;
|
|
1340
|
+
}
|
|
1341
|
+
if (!result.variables) {
|
|
1342
|
+
result.variables = {};
|
|
1343
|
+
}
|
|
1344
|
+
result.variables[key] = parsedOptions[key];
|
|
1345
|
+
return result;
|
|
1346
|
+
}, {});
|
|
1347
|
+
const baseUrl = parsedOptions.baseUrl || request2.endpoint.DEFAULTS.baseUrl;
|
|
1348
|
+
if (GHES_V3_SUFFIX_REGEX.test(baseUrl)) {
|
|
1349
|
+
requestOptions.url = baseUrl.replace(GHES_V3_SUFFIX_REGEX, "/api/graphql");
|
|
1350
|
+
}
|
|
1351
|
+
return request2(requestOptions).then((response) => {
|
|
1352
|
+
if (response.data.errors) {
|
|
1353
|
+
const headers = {};
|
|
1354
|
+
for (const key of Object.keys(response.headers)) {
|
|
1355
|
+
headers[key] = response.headers[key];
|
|
1356
|
+
}
|
|
1357
|
+
throw new GraphqlResponseError(requestOptions, headers, response.data);
|
|
1358
|
+
}
|
|
1359
|
+
return response.data.data;
|
|
1360
|
+
});
|
|
1361
|
+
}
|
|
1362
|
+
function withDefaults3(request2, newDefaults) {
|
|
1363
|
+
const newRequest = request2.defaults(newDefaults);
|
|
1364
|
+
const newApi = (query, options) => {
|
|
1365
|
+
return graphql(newRequest, query, options);
|
|
1366
|
+
};
|
|
1367
|
+
return Object.assign(newApi, {
|
|
1368
|
+
defaults: withDefaults3.bind(null, newRequest),
|
|
1369
|
+
endpoint: newRequest.endpoint
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
var graphql2 = withDefaults3(request, {
|
|
1373
|
+
headers: {
|
|
1374
|
+
"user-agent": `octokit-graphql.js/${VERSION3} ${getUserAgent()}`
|
|
1375
|
+
},
|
|
1376
|
+
method: "POST",
|
|
1377
|
+
url: "/graphql"
|
|
1378
|
+
});
|
|
1379
|
+
|
|
1380
|
+
// ../../packages/aeg-forge-state/src/fetch-provenance.ts
|
|
1381
|
+
var PROVENANCE_PATTERN = /^###\s+AEG provenance\b/im;
|
|
1382
|
+
function provenanceMatchesIssue(text, issueNum) {
|
|
1383
|
+
if (!PROVENANCE_PATTERN.test(text))
|
|
1384
|
+
return false;
|
|
1385
|
+
const m = text.match(/^-\s*Issue:\s*#(\d+)/im);
|
|
1386
|
+
return m !== null && Number(m[1]) === issueNum;
|
|
1387
|
+
}
|
|
1388
|
+
function isPrCloser(closer) {
|
|
1389
|
+
return closer !== null && typeof closer.number === "number";
|
|
1390
|
+
}
|
|
1391
|
+
async function fetchProvenanceViaCrossReferences(issueNums, owner, repo, token) {
|
|
1392
|
+
const result = new Map;
|
|
1393
|
+
if (issueNums.length === 0)
|
|
1394
|
+
return result;
|
|
1395
|
+
const client = graphql2.defaults({ headers: { authorization: `bearer ${token}` } });
|
|
1396
|
+
const perIssue = issueNums.map((n) => `
|
|
1397
|
+
i_${n}: issue(number: ${n}) {
|
|
1398
|
+
timelineItems(first: 50, itemTypes: [CROSS_REFERENCED_EVENT]) {
|
|
1399
|
+
nodes {
|
|
1400
|
+
... on CrossReferencedEvent {
|
|
1401
|
+
source {
|
|
1402
|
+
... on PullRequest {
|
|
1403
|
+
number
|
|
1404
|
+
body
|
|
1405
|
+
comments(first: 50) { nodes { body } }
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
}`).join("");
|
|
1412
|
+
const query = `query ProvenanceCrossRef($owner: String!, $repo: String!) {
|
|
1413
|
+
repository(owner: $owner, name: $repo) {${perIssue}
|
|
1414
|
+
}
|
|
1415
|
+
}`;
|
|
1416
|
+
let response;
|
|
1417
|
+
try {
|
|
1418
|
+
response = await client(query, { owner, repo });
|
|
1419
|
+
} catch {
|
|
1420
|
+
return result;
|
|
1421
|
+
}
|
|
1422
|
+
if (!response.repository)
|
|
1423
|
+
return result;
|
|
1424
|
+
for (const n of issueNums) {
|
|
1425
|
+
const raw = response.repository[`i_${n}`];
|
|
1426
|
+
const nodes = raw?.timelineItems?.nodes ?? [];
|
|
1427
|
+
const found = nodes.some(({ source }) => {
|
|
1428
|
+
if (!source || typeof source.number !== "number")
|
|
1429
|
+
return false;
|
|
1430
|
+
const pr = source;
|
|
1431
|
+
if (provenanceMatchesIssue(pr.body ?? "", n))
|
|
1432
|
+
return true;
|
|
1433
|
+
return pr.comments.nodes.some((c) => provenanceMatchesIssue(c.body, n));
|
|
1434
|
+
});
|
|
1435
|
+
result.set(n, found);
|
|
1436
|
+
}
|
|
1437
|
+
return result;
|
|
1438
|
+
}
|
|
1439
|
+
async function fetchProvenance(issueNums, owner, repo, token) {
|
|
1440
|
+
const result = new Map;
|
|
1441
|
+
if (issueNums.length === 0)
|
|
1442
|
+
return result;
|
|
1443
|
+
const client = graphql2.defaults({ headers: { authorization: `bearer ${token}` } });
|
|
1444
|
+
const perIssue = issueNums.map((n) => `
|
|
1445
|
+
i_${n}: issue(number: ${n}) {
|
|
1446
|
+
timelineItems(last: 1, itemTypes: [CLOSED_EVENT]) {
|
|
1447
|
+
nodes {
|
|
1448
|
+
... on ClosedEvent {
|
|
1449
|
+
closer {
|
|
1450
|
+
... on PullRequest {
|
|
1451
|
+
number
|
|
1452
|
+
body
|
|
1453
|
+
comments(first: 50) {
|
|
1454
|
+
nodes { body }
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
}
|
|
1461
|
+
}`).join("");
|
|
1462
|
+
const query = `query Provenance($owner: String!, $repo: String!) {
|
|
1463
|
+
repository(owner: $owner, name: $repo) {${perIssue}
|
|
1464
|
+
}
|
|
1465
|
+
}`;
|
|
1466
|
+
let response;
|
|
1467
|
+
try {
|
|
1468
|
+
response = await client(query, { owner, repo });
|
|
1469
|
+
} catch {
|
|
1470
|
+
return result;
|
|
1471
|
+
}
|
|
1472
|
+
if (!response.repository)
|
|
1473
|
+
return result;
|
|
1474
|
+
const needsFallback = [];
|
|
1475
|
+
for (const n of issueNums) {
|
|
1476
|
+
const raw = response.repository[`i_${n}`];
|
|
1477
|
+
if (!raw) {
|
|
1478
|
+
result.set(n, false);
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1481
|
+
const closer = raw.timelineItems?.nodes?.[0]?.closer;
|
|
1482
|
+
const c = closer ?? null;
|
|
1483
|
+
if (!isPrCloser(c)) {
|
|
1484
|
+
needsFallback.push(n);
|
|
1485
|
+
continue;
|
|
1486
|
+
}
|
|
1487
|
+
const bodyHas = PROVENANCE_PATTERN.test(c.body ?? "");
|
|
1488
|
+
const commentHas = c.comments.nodes.some((x) => PROVENANCE_PATTERN.test(x.body));
|
|
1489
|
+
result.set(n, bodyHas || commentHas);
|
|
1490
|
+
}
|
|
1491
|
+
if (needsFallback.length > 0) {
|
|
1492
|
+
const fallback = await fetchProvenanceViaCrossReferences(needsFallback, owner, repo, token);
|
|
1493
|
+
for (const [n, found] of fallback)
|
|
1494
|
+
result.set(n, found);
|
|
1495
|
+
}
|
|
1496
|
+
return result;
|
|
1497
|
+
}
|
|
1498
|
+
// ../../packages/aeg-forge-state/src/github-token.ts
|
|
1499
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
1500
|
+
import { promisify as promisify2 } from "node:util";
|
|
1501
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
1502
|
+
var systemEnv2 = {
|
|
1503
|
+
...process.env,
|
|
1504
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
1505
|
+
};
|
|
1506
|
+
async function resolveGithubToken(explicit) {
|
|
1507
|
+
if (explicit && explicit.length > 0)
|
|
1508
|
+
return explicit;
|
|
1509
|
+
if (process.env.GITHUB_TOKEN)
|
|
1510
|
+
return process.env.GITHUB_TOKEN;
|
|
1511
|
+
if (process.env.GH_TOKEN)
|
|
1512
|
+
return process.env.GH_TOKEN;
|
|
1513
|
+
try {
|
|
1514
|
+
const { stdout } = await execFileAsync2("gh", ["auth", "token"], { env: systemEnv2, timeout: 5000 });
|
|
1515
|
+
const token = stdout.trim();
|
|
1516
|
+
return token.length > 0 ? token : null;
|
|
1517
|
+
} catch {
|
|
1518
|
+
return null;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
// ../../packages/aeg-forge-state/src/resolve-repo.ts
|
|
1522
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
1523
|
+
import { promisify as promisify3 } from "node:util";
|
|
1524
|
+
var execFileAsync3 = promisify3(execFile3);
|
|
1525
|
+
var systemEnv3 = {
|
|
1526
|
+
...process.env,
|
|
1527
|
+
PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
|
|
1528
|
+
};
|
|
1529
|
+
var defaultExec = () => execFileAsync3("git", ["remote", "get-url", "origin"], { env: systemEnv3, timeout: 5000 });
|
|
1530
|
+
var cached;
|
|
1531
|
+
var inflight;
|
|
1532
|
+
async function resolveRepo(exec = defaultExec) {
|
|
1533
|
+
if (cached !== undefined)
|
|
1534
|
+
return cached;
|
|
1535
|
+
const fromEnv = process.env.AEG_REPO;
|
|
1536
|
+
if (fromEnv) {
|
|
1537
|
+
const parsed = parseOwnerRepo(fromEnv);
|
|
1538
|
+
if (parsed) {
|
|
1539
|
+
cached = parsed;
|
|
1540
|
+
return cached;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
if (inflight)
|
|
1544
|
+
return inflight;
|
|
1545
|
+
inflight = (async () => {
|
|
1546
|
+
try {
|
|
1547
|
+
const { stdout } = await exec();
|
|
1548
|
+
cached = parseGitRemoteUrl(stdout.trim());
|
|
1549
|
+
return cached;
|
|
1550
|
+
} catch (err) {
|
|
1551
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1552
|
+
console.warn(`[aeg-forge-state] resolveRepo: git remote lookup failed (will retry): ${message}`);
|
|
1553
|
+
return null;
|
|
1554
|
+
} finally {
|
|
1555
|
+
inflight = undefined;
|
|
1556
|
+
}
|
|
1557
|
+
})();
|
|
1558
|
+
return inflight;
|
|
1559
|
+
}
|
|
1560
|
+
function parseGitRemoteUrl(url) {
|
|
1561
|
+
const ssh = url.match(/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/);
|
|
1562
|
+
if (ssh?.[1] && ssh[2])
|
|
1563
|
+
return { owner: ssh[1], repo: ssh[2] };
|
|
1564
|
+
const https = url.match(/^https?:\/\/(?:[^@]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/);
|
|
1565
|
+
if (https?.[1] && https[2])
|
|
1566
|
+
return { owner: https[1], repo: https[2] };
|
|
1567
|
+
return null;
|
|
1568
|
+
}
|
|
1569
|
+
function parseOwnerRepo(value) {
|
|
1570
|
+
const match = value.match(/^([^/]+)\/(.+)$/);
|
|
1571
|
+
if (!match?.[1] || !match[2])
|
|
1572
|
+
return null;
|
|
1573
|
+
return { owner: match[1], repo: match[2] };
|
|
1574
|
+
}
|
|
1575
|
+
// ../../packages/aeg-core/src/anchored-region.ts
|
|
1576
|
+
function anchoredRegionBounds(body, field) {
|
|
1577
|
+
const masked = maskCode(body);
|
|
1578
|
+
const start = new RegExp(`<!--\\s*AEG:${field}:START\\s*-->`).exec(masked);
|
|
1579
|
+
if (!start)
|
|
1580
|
+
return null;
|
|
1581
|
+
const innerStart = start.index + start[0].length;
|
|
1582
|
+
const end = new RegExp(`<!--\\s*AEG:${field}:END\\s*-->`).exec(masked.slice(innerStart));
|
|
1583
|
+
if (!end)
|
|
1584
|
+
return null;
|
|
1585
|
+
const innerEnd = innerStart + end.index;
|
|
1586
|
+
return { outerStart: start.index, outerEnd: innerEnd + end[0].length, innerStart, innerEnd };
|
|
1587
|
+
}
|
|
1588
|
+
function anchoredRegion(body, field) {
|
|
1589
|
+
const bounds = anchoredRegionBounds(body, field);
|
|
1590
|
+
if (!bounds)
|
|
1591
|
+
return null;
|
|
1592
|
+
return body.slice(bounds.innerStart, bounds.innerEnd);
|
|
1593
|
+
}
|
|
1594
|
+
// ../../packages/aeg-core/src/state-machine-model.ts
|
|
1595
|
+
var FORGE_FACT_INPUTS = [
|
|
1596
|
+
{
|
|
1597
|
+
fact: "issueState",
|
|
1598
|
+
readsFrom: "Issue.state (OPEN | CLOSED)",
|
|
1599
|
+
meaning: "Whether the task Issue is still open — the anchor for the honest terminal statuses."
|
|
1600
|
+
},
|
|
1601
|
+
{
|
|
1602
|
+
fact: "assigned",
|
|
1603
|
+
readsFrom: "Issue.assignees (count > 0)",
|
|
1604
|
+
meaning: "An assignee exists. No longer affects derivation: assigned and unassigned are both todo."
|
|
1605
|
+
},
|
|
1606
|
+
{
|
|
1607
|
+
fact: "branchExists",
|
|
1608
|
+
readsFrom: "Ref refs/heads/task/<tranche>/<id>",
|
|
1609
|
+
meaning: "A task branch has been published — the todo → in-flight transition, written by git push, not by hand."
|
|
1610
|
+
},
|
|
1611
|
+
{
|
|
1612
|
+
fact: "prState",
|
|
1613
|
+
readsFrom: "PullRequest.state (OPEN | CLOSED | MERGED)",
|
|
1614
|
+
meaning: "Whether work is proposed or landed. CLOSED-without-merge collapses to none — AEG models open/merged/none."
|
|
1615
|
+
},
|
|
1616
|
+
{
|
|
1617
|
+
fact: "reviewDecision",
|
|
1618
|
+
readsFrom: "PullRequest.reviewDecision",
|
|
1619
|
+
meaning: "Only 'changes_requested' flips status; approved-but-unmerged stays in-review."
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
fact: "blockedLabel",
|
|
1623
|
+
readsFrom: `Issue.labels contains '${label("blocked")}'`,
|
|
1624
|
+
meaning: "Execution halted pending an external unblock. Wins over every other rule."
|
|
1625
|
+
},
|
|
1626
|
+
{
|
|
1627
|
+
fact: "stateReason",
|
|
1628
|
+
readsFrom: "Issue.stateReason (COMPLETED | NOT_PLANNED | REOPENED | null)",
|
|
1629
|
+
meaning: "Separates a legitimate drop from an incoherent close on a closed, never-merged Issue."
|
|
1630
|
+
},
|
|
1631
|
+
{
|
|
1632
|
+
fact: "closedAt",
|
|
1633
|
+
readsFrom: "Issue.closedAt",
|
|
1634
|
+
meaning: "Timestamp for the coherence oracle grandfather cutoff. No derivation rule reads it."
|
|
1635
|
+
},
|
|
1636
|
+
{
|
|
1637
|
+
fact: "mergedAt",
|
|
1638
|
+
readsFrom: "PullRequest.mergedAt",
|
|
1639
|
+
meaning: "Timestamp for the coherence oracle grandfather cutoff. No derivation rule reads it."
|
|
1640
|
+
},
|
|
1641
|
+
{
|
|
1642
|
+
fact: "closedByActor",
|
|
1643
|
+
readsFrom: "ClosedEvent.actor.login (most recent timeline CLOSED_EVENT)",
|
|
1644
|
+
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."
|
|
1645
|
+
}
|
|
1646
|
+
];
|
|
1647
|
+
var DERIVED_STATUSES = [
|
|
1648
|
+
"backlog",
|
|
1649
|
+
"todo",
|
|
1650
|
+
"in-flight",
|
|
1651
|
+
"in-review",
|
|
1652
|
+
"changes-requested",
|
|
1653
|
+
"merged",
|
|
1654
|
+
"blocked",
|
|
1655
|
+
"dropped",
|
|
1656
|
+
"incoherent"
|
|
1657
|
+
];
|
|
1658
|
+
var DERIVABLE_STATUSES = DERIVED_STATUSES.filter((s) => s !== "backlog");
|
|
1659
|
+
// ../../packages/aeg-core/src/waiver-label.ts
|
|
1660
|
+
var WAIVER_LABEL = label("waiver-docs");
|
|
1661
|
+
var WAIVER_LABEL_REVIEW = label("waiver-review");
|
|
1662
|
+
var PRINCIPAL_ALLOWLIST = ["daniboomerang"];
|
|
1663
|
+
function isPrincipal(login, principalAllowlist) {
|
|
1664
|
+
if (login === null)
|
|
1665
|
+
return false;
|
|
1666
|
+
const normalized = login.toLowerCase();
|
|
1667
|
+
return principalAllowlist.some((p) => p.toLowerCase() === normalized);
|
|
1668
|
+
}
|
|
1669
|
+
// ../../packages/aeg-core/src/report-tokens.ts
|
|
1670
|
+
var DASH_LOOKALIKES = {
|
|
1671
|
+
"-": "‑",
|
|
1672
|
+
"–": "‒",
|
|
1673
|
+
"—": "―"
|
|
1674
|
+
};
|
|
1675
|
+
var DASH_CHARS = new Set(Object.keys(DASH_LOOKALIKES));
|
|
1676
|
+
// ../../packages/aeg-core/src/metering-io-guard.ts
|
|
1677
|
+
import { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync } from "node:fs";
|
|
1678
|
+
var GUARD_OPEN_FLAGS = fsConstants.O_RDONLY | fsConstants.O_NONBLOCK | fsConstants.O_NOFOLLOW;
|
|
1679
|
+
// ../../packages/aeg-core/src/doc-owners.ts
|
|
1680
|
+
var DOC_OWNERS_PATH = ".vinaya/doc-owners";
|
|
1681
|
+
function classifyDocOwnersManifest(content) {
|
|
1682
|
+
if (content === null)
|
|
1683
|
+
return "absent";
|
|
1684
|
+
return content.trim() === "" ? "empty" : "present";
|
|
1685
|
+
}
|
|
1686
|
+
function parseDocOwners(content) {
|
|
1687
|
+
const bindings = [];
|
|
1688
|
+
const errors = [];
|
|
1689
|
+
const lines = content.split(`
|
|
1690
|
+
`);
|
|
1691
|
+
for (let i = 0;i < lines.length; i++) {
|
|
1692
|
+
const raw = lines[i] ?? "";
|
|
1693
|
+
const stripped = raw.replace(/#.*$/, "").trim();
|
|
1694
|
+
if (!stripped)
|
|
1695
|
+
continue;
|
|
1696
|
+
const parts = stripped.split(/\s+/);
|
|
1697
|
+
if (parts.length < 2) {
|
|
1698
|
+
errors.push(`C5 doc-owners-parse: ${DOC_OWNERS_PATH}:${i + 1} — malformed binding (expected "<glob> <pointer>", got "${raw.trim()}").`);
|
|
1699
|
+
continue;
|
|
1700
|
+
}
|
|
1701
|
+
const [glob, ...pointerParts] = parts;
|
|
1702
|
+
bindings.push({ glob: glob ?? "", pointer: pointerParts.join(" "), lineNum: i + 1 });
|
|
1703
|
+
}
|
|
1704
|
+
return { bindings, errors };
|
|
1705
|
+
}
|
|
1706
|
+
var SEPARATOR = /(?:[ \t]*[—–][ \t]*|[ \t]+-[ \t]+)/.source;
|
|
1707
|
+
// ../../packages/aeg-core/src/review-policy.ts
|
|
1708
|
+
var SECURITY_SEVERITY_ORDER = ["CRITICAL", "HIGH", "MEDIUM", "LOW"];
|
|
1709
|
+
function blockingSeverities(scale, threshold) {
|
|
1710
|
+
const idx = scale.indexOf(threshold);
|
|
1711
|
+
if (idx === -1) {
|
|
1712
|
+
throw new Error(`blockingSeverities: threshold "${threshold}" is not one of ${scale.join(" > ")}`);
|
|
1713
|
+
}
|
|
1714
|
+
return scale.slice(0, idx + 1);
|
|
1715
|
+
}
|
|
1716
|
+
var SECURITY_HIGH_AND_ABOVE = blockingSeverities(SECURITY_SEVERITY_ORDER, "HIGH");
|
|
1717
|
+
// ../../packages/aeg-core/src/derive-section7.ts
|
|
1718
|
+
function deriveSection7(intendedSurfaces, docOwnersContent) {
|
|
1719
|
+
const { bindings, errors } = parseDocOwners(docOwnersContent);
|
|
1720
|
+
const matches = [];
|
|
1721
|
+
for (const surface of intendedSurfaces) {
|
|
1722
|
+
for (const binding of bindings) {
|
|
1723
|
+
if (globsOverlap(binding.glob, surface)) {
|
|
1724
|
+
matches.push({ surface, glob: binding.glob, pointer: binding.pointer, lineNum: binding.lineNum });
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
const pointers = [];
|
|
1729
|
+
for (const m of matches) {
|
|
1730
|
+
if (!pointers.includes(m.pointer))
|
|
1731
|
+
pointers.push(m.pointer);
|
|
1732
|
+
}
|
|
1733
|
+
return { pointers, matches, errors };
|
|
1734
|
+
}
|
|
1735
|
+
function globsOverlap(a, b) {
|
|
1736
|
+
const segsA = a.split("/");
|
|
1737
|
+
const segsB = b.split("/");
|
|
1738
|
+
let i = 0;
|
|
1739
|
+
let j = 0;
|
|
1740
|
+
while (i < segsA.length || j < segsB.length) {
|
|
1741
|
+
const sa = i < segsA.length ? segsA[i] : undefined;
|
|
1742
|
+
const sb = j < segsB.length ? segsB[j] : undefined;
|
|
1743
|
+
if (sa === "**" || sb === "**")
|
|
1744
|
+
return true;
|
|
1745
|
+
if (sa === undefined || sb === undefined)
|
|
1746
|
+
return false;
|
|
1747
|
+
if (sa === "*" || sb === "*") {
|
|
1748
|
+
i++;
|
|
1749
|
+
j++;
|
|
1750
|
+
continue;
|
|
1751
|
+
}
|
|
1752
|
+
if (sa !== sb)
|
|
1753
|
+
return false;
|
|
1754
|
+
i++;
|
|
1755
|
+
j++;
|
|
1756
|
+
}
|
|
1757
|
+
return true;
|
|
1758
|
+
}
|
|
1759
|
+
// ../../packages/aeg-core/src/pr-tier.ts
|
|
1760
|
+
var OVERRIDE_BODY_TOKEN = `[${label("override-docs")}]`;
|
|
1761
|
+
// ../../packages/aeg-core/src/premise-check.ts
|
|
1762
|
+
import { createHash } from "node:crypto";
|
|
1763
|
+
var ASSERTION_KINDS = new Set(["contains", "absent", "sha256"]);
|
|
1764
|
+
function isPremiseHeader(line) {
|
|
1765
|
+
const stripped = line.replace(/[*#]/g, "").trim();
|
|
1766
|
+
return /^premise\s*:?$/i.test(stripped);
|
|
1767
|
+
}
|
|
1768
|
+
var PREMISE_LINE = /^[-*]\s*(\S+)\s+(contains|absent|sha256)\s*:\s*(.+)$/i;
|
|
1769
|
+
function parsePremiseBlock(prBody) {
|
|
1770
|
+
const searchIn = anchoredRegion(prBody, "PREMISE") ?? prBody;
|
|
1771
|
+
const lines = searchIn.split(/\r?\n/);
|
|
1772
|
+
const assertions = [];
|
|
1773
|
+
let inBlock = false;
|
|
1774
|
+
for (const raw of lines) {
|
|
1775
|
+
const line = raw.trim();
|
|
1776
|
+
if (!inBlock) {
|
|
1777
|
+
if (isPremiseHeader(line))
|
|
1778
|
+
inBlock = true;
|
|
1779
|
+
continue;
|
|
1780
|
+
}
|
|
1781
|
+
if (line === "")
|
|
1782
|
+
break;
|
|
1783
|
+
const m = line.match(PREMISE_LINE);
|
|
1784
|
+
if (!m)
|
|
1785
|
+
break;
|
|
1786
|
+
const [, path, kindRaw, value] = m;
|
|
1787
|
+
const kind = kindRaw.toLowerCase();
|
|
1788
|
+
if (!ASSERTION_KINDS.has(kind))
|
|
1789
|
+
continue;
|
|
1790
|
+
assertions.push({ kind, path, value: value.trim() });
|
|
1791
|
+
}
|
|
1792
|
+
return assertions;
|
|
1793
|
+
}
|
|
1794
|
+
function checkPremises(assertions, fileReader) {
|
|
1795
|
+
const failures = [];
|
|
1796
|
+
for (const a of assertions) {
|
|
1797
|
+
const content = fileReader(a.path);
|
|
1798
|
+
if (content === null) {
|
|
1799
|
+
failures.push(`premise-check: ${a.path} does not exist on disk (premise asserted \`${a.kind}: ${a.value}\`) — the surface moved since this brief was authored; re-dig before proceeding.`);
|
|
1800
|
+
continue;
|
|
1801
|
+
}
|
|
1802
|
+
if (a.kind === "contains" && !content.includes(a.value)) {
|
|
1803
|
+
failures.push(`premise-check: ${a.path} no longer contains "${a.value}" — the premise this brief pinned has moved; re-dig before proceeding.`);
|
|
1804
|
+
} else if (a.kind === "absent" && content.includes(a.value)) {
|
|
1805
|
+
failures.push(`premise-check: ${a.path} now contains "${a.value}", but the brief pinned it absent — the premise has moved; re-dig before proceeding.`);
|
|
1806
|
+
} else if (a.kind === "sha256") {
|
|
1807
|
+
const actual = createHash("sha256").update(content).digest("hex");
|
|
1808
|
+
if (actual !== a.value.toLowerCase()) {
|
|
1809
|
+
failures.push(`premise-check: ${a.path} sha256 mismatch (brief pinned ${a.value}, file is now ${actual}) — the file changed since this brief was authored; re-dig before proceeding.`);
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
return { pass: failures.length === 0, failures };
|
|
1814
|
+
}
|
|
1815
|
+
|
|
1816
|
+
// ../../packages/aeg-core/src/brief-validation.ts
|
|
1817
|
+
var COMMIT_TYPES = [
|
|
1818
|
+
"Build",
|
|
1819
|
+
"Chore",
|
|
1820
|
+
"Docs",
|
|
1821
|
+
"Feat",
|
|
1822
|
+
"Fix",
|
|
1823
|
+
"Perf",
|
|
1824
|
+
"Plan",
|
|
1825
|
+
"Refactor",
|
|
1826
|
+
"Revert",
|
|
1827
|
+
"Style",
|
|
1828
|
+
"Test"
|
|
1829
|
+
];
|
|
1830
|
+
var COMMIT_TYPE_STYLE = new RegExp(`^(${COMMIT_TYPES.join("|")})(\\([a-z0-9-]+\\))?: \\S`);
|
|
1831
|
+
function contentAfterNLines(body, n) {
|
|
1832
|
+
let idx = -1;
|
|
1833
|
+
for (let i = 0;i < n; i++) {
|
|
1834
|
+
idx = body.indexOf(`
|
|
1835
|
+
`, idx + 1);
|
|
1836
|
+
if (idx === -1)
|
|
1837
|
+
return "";
|
|
1838
|
+
}
|
|
1839
|
+
return body.slice(idx + 1);
|
|
1840
|
+
}
|
|
1841
|
+
var BRIEF_MARKER_LINE_RE = /^<!-- aeg:brief:v(\d+) -->$/;
|
|
1842
|
+
function parseBriefMarkerVersion(firstLine) {
|
|
1843
|
+
const m = BRIEF_MARKER_LINE_RE.exec(firstLine.trim());
|
|
1844
|
+
if (!m)
|
|
1845
|
+
return null;
|
|
1846
|
+
const version = Number.parseInt(m[1], 10);
|
|
1847
|
+
return Number.isInteger(version) && version >= 1 ? version : null;
|
|
1848
|
+
}
|
|
1849
|
+
function frozenBriefContent(body, version) {
|
|
1850
|
+
return contentAfterNLines(body, version === 1 ? 2 : 3);
|
|
1851
|
+
}
|
|
1852
|
+
function resolveNewestFrozenBrief(comments, allowlist) {
|
|
1853
|
+
let best = null;
|
|
1854
|
+
for (const c of comments) {
|
|
1855
|
+
if (!isPrincipal(c.author, allowlist))
|
|
1856
|
+
continue;
|
|
1857
|
+
const version = parseBriefMarkerVersion(c.body.split(`
|
|
1858
|
+
`)[0] ?? "");
|
|
1859
|
+
if (version === null)
|
|
1860
|
+
continue;
|
|
1861
|
+
if (best === null || version > best.version)
|
|
1862
|
+
best = { ...c, version };
|
|
1863
|
+
}
|
|
1864
|
+
return best === null ? null : { ...best, content: frozenBriefContent(best.body, best.version) };
|
|
1865
|
+
}
|
|
1866
|
+
// ../../packages/aeg-core/src/doctrine-portability.ts
|
|
1867
|
+
var EXEMPT_LITERALS = new Set([
|
|
1868
|
+
"path/inside/the/shipped/diff.ts",
|
|
1869
|
+
"path/inside/the/surface.ts",
|
|
1870
|
+
"apps/x/specs/..."
|
|
1871
|
+
]);
|
|
1872
|
+
var NON_PATH_TOP_SEGMENTS = new Set(["origin", "refs", "HEAD", "vinaya", "fix"]);
|
|
1873
|
+
|
|
1874
|
+
// ../../packages/aeg-core/src/doctrine-no-procedures.ts
|
|
1875
|
+
var SHELL_LANGS = new Set(["", "sh", "bash", "shell", "console"]);
|
|
1876
|
+
// ../../packages/aeg-core/src/reader-resolvable-prose.ts
|
|
1877
|
+
var SWEPT_CLASSES = new Set(["ships", "reader-facing"]);
|
|
1878
|
+
|
|
1879
|
+
// ../../packages/aeg-core/src/quoted-command.ts
|
|
1880
|
+
var QUOTED_COMMAND_SWEPT_CLASSES = new Set(["ships", "reader-facing"]);
|
|
1881
|
+
|
|
1882
|
+
// ../../packages/aeg-core/src/issue-validation.ts
|
|
1883
|
+
function hasRationaleField(body, labelPattern) {
|
|
1884
|
+
const re = new RegExp(`(?:\\*\\*|^#{1,4}\\s+)\\s*(?:${labelPattern})`, "im");
|
|
1885
|
+
return re.test(body);
|
|
1886
|
+
}
|
|
1887
|
+
var RATIONALE_FIELDS = [
|
|
1888
|
+
{ name: "Boundary", pattern: "Boundary" },
|
|
1889
|
+
{ name: "Sizing", pattern: "Sizing" },
|
|
1890
|
+
{ name: "Project(s) + blast radius", pattern: "Project\\(s\\)|Project(?:s)?\\s*\\+|blast radius" },
|
|
1891
|
+
{ name: "Dependency rationale", pattern: "Dependency rationale|Depends[- ]on" },
|
|
1892
|
+
{ name: "Traps to avoid", pattern: "Traps" },
|
|
1893
|
+
{ name: "Suggested agent-class", pattern: "(?:Suggested\\s+)?agent-class" },
|
|
1894
|
+
{ name: "Stop-and-escalate", pattern: "Stop-and-escalate" },
|
|
1895
|
+
{ name: "Docs to keep coherent", pattern: "Docs to keep coherent|§7" }
|
|
1896
|
+
];
|
|
1897
|
+
var DEPENDENCY_RATIONALE_FIELD_NAME = "Dependency rationale";
|
|
1898
|
+
function checkIssueRationale(body) {
|
|
1899
|
+
const errors = [];
|
|
1900
|
+
for (const f of RATIONALE_FIELDS) {
|
|
1901
|
+
if (!hasRationaleField(body, f.pattern)) {
|
|
1902
|
+
errors.push(`issue-validation ${f.name}: rationale field not found in the Issue body — every task Issue carries the full Planner's rationale (aeg-root/contracts/planner-brief.md).`);
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
if (f.name === DEPENDENCY_RATIONALE_FIELD_NAME && !SECTION_HEADER.test(body)) {
|
|
1906
|
+
errors.push(`issue-validation ${f.name}: rationale field found, but not in the form amend-deps requires — ` + "write `**Dependency rationale** — …`, not `**Dependency rationale:** …`. " + "`amendRationaleDeps` (the only sanctioned way to edit Depends-on/Conflicts-with) locates this " + "section by the exact anchor `**Dependency rationale**`; a colon inside the bold breaks that match " + "and the Issue becomes unamendable.");
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
return { status: errors.length > 0 ? "fail" : "pass", errors };
|
|
1910
|
+
}
|
|
1911
|
+
var TYPE_LABEL_IDS = LABELS.filter((l) => l.category === "type").map((l) => l.id);
|
|
1912
|
+
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;
|
|
1913
|
+
var DOC_PATH_RE_GLOBAL = new RegExp(DOC_PATH_RE.source, "gi");
|
|
1914
|
+
var FILE_EXTENSIONS = new Set([
|
|
1915
|
+
"ts",
|
|
1916
|
+
"tsx",
|
|
1917
|
+
"js",
|
|
1918
|
+
"jsx",
|
|
1919
|
+
"mjs",
|
|
1920
|
+
"cjs",
|
|
1921
|
+
"json",
|
|
1922
|
+
"jsonc",
|
|
1923
|
+
"md",
|
|
1924
|
+
"mdx",
|
|
1925
|
+
"yml",
|
|
1926
|
+
"yaml",
|
|
1927
|
+
"txt",
|
|
1928
|
+
"sh",
|
|
1929
|
+
"lock",
|
|
1930
|
+
"toml",
|
|
1931
|
+
"ndjson",
|
|
1932
|
+
"html",
|
|
1933
|
+
"css"
|
|
1934
|
+
]);
|
|
1935
|
+
var CI_SHARD_DIR = "apps/cli/tests/ci-shards";
|
|
1936
|
+
var CI_SHARD_PROBE = `${CI_SHARD_DIR}/shard-1.txt`;
|
|
1937
|
+
|
|
1938
|
+
// ../../packages/aeg-core/src/task-branch-identity.ts
|
|
1939
|
+
function issueBranchName(issueNumber) {
|
|
1940
|
+
return `task/issue-${issueNumber}`;
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
// ../../packages/aeg-core/src/coherence-checks.ts
|
|
1944
|
+
var R1_GRANDFATHERED_ISSUES = new Set([279, 280, 281, 282]);
|
|
1945
|
+
// ../../packages/aeg-core/src/diagram-model.ts
|
|
1946
|
+
import matter from "gray-matter";
|
|
1947
|
+
// ../../packages/aeg-core/src/leftover-detection.ts
|
|
1948
|
+
function classifyLeftover(input) {
|
|
1949
|
+
const { branchExistsRemote, worktreeExistsLocal, commitsAheadOfMain, openPrNumber } = input;
|
|
1950
|
+
const prSuffix = openPrNumber ? ` PR #${openPrNumber} is already open for this task.` : "";
|
|
1951
|
+
if (commitsAheadOfMain > 0) {
|
|
1952
|
+
return {
|
|
1953
|
+
verdict: "stop",
|
|
1954
|
+
reason: `${commitsAheadOfMain} commit(s) already ahead of origin/main on this task branch — real work exists.${prSuffix} Do not re-run Step 0 (which would branch fresh from origin/main and orphan that work); resume in the existing worktree instead.`
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
if (branchExistsRemote || worktreeExistsLocal) {
|
|
1958
|
+
return {
|
|
1959
|
+
verdict: "resume",
|
|
1960
|
+
reason: `A ${branchExistsRemote ? "remote branch" : ""}${branchExistsRemote && worktreeExistsLocal ? " and a " : ""}${worktreeExistsLocal ? "local worktree" : ""} already exist for this task, with zero commits ahead of main — reuse it rather than recreating (\`git worktree add\` on an existing branch/dir will fail anyway).`
|
|
1961
|
+
};
|
|
1962
|
+
}
|
|
1963
|
+
return {
|
|
1964
|
+
verdict: "clean",
|
|
1965
|
+
reason: "No branch, no worktree, no commits ahead of main — safe to run Step 0 fresh."
|
|
1966
|
+
};
|
|
1967
|
+
}
|
|
1968
|
+
function leftoverBlocksDispatch(verdict, opts) {
|
|
1969
|
+
return verdict === "stop" && !opts.existingWork;
|
|
1970
|
+
}
|
|
1971
|
+
// ../../packages/aeg-core/src/baseline-capture.ts
|
|
1972
|
+
function captureBaseline(counts, capturedAt) {
|
|
1973
|
+
return counts.map((c) => ({ tool: c.tool, findingCount: c.findingCount, capturedAt }));
|
|
1974
|
+
}
|
|
1975
|
+
function compareToBaseline(current, baseline) {
|
|
1976
|
+
const perTool = current.map((c) => {
|
|
1977
|
+
const baselineEntry = baseline.find((b) => b.tool === c.tool);
|
|
1978
|
+
const baselineCount = baselineEntry ? baselineEntry.findingCount : c.findingCount;
|
|
1979
|
+
return { tool: c.tool, baseline: baselineCount, current: c.findingCount, delta: c.findingCount - baselineCount };
|
|
1980
|
+
});
|
|
1981
|
+
return {
|
|
1982
|
+
withinBudget: perTool.every((t) => t.delta <= 0),
|
|
1983
|
+
delta: perTool.reduce((sum, t) => sum + t.delta, 0),
|
|
1984
|
+
perTool
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
// ../../packages/aeg-core/src/retired-vocabulary.ts
|
|
1988
|
+
var RETIRED_PATTERNS = [
|
|
1989
|
+
String.raw`\bD-[0-9]{3}\b`,
|
|
1990
|
+
"D-(###|NNN|nnn|xxx)",
|
|
1991
|
+
"decision (entry|logged)",
|
|
1992
|
+
"decision-log entry",
|
|
1993
|
+
"decision log entry",
|
|
1994
|
+
"decision log(s|ged|ging)?([^a-z]|$)",
|
|
1995
|
+
"decision-log",
|
|
1996
|
+
"decision entr",
|
|
1997
|
+
"decisions? (are |is )?logged",
|
|
1998
|
+
"log entries",
|
|
1999
|
+
String.raw`decisions\.md`,
|
|
2000
|
+
"decisions-legacy",
|
|
2001
|
+
"CONTRADICTION",
|
|
2002
|
+
"assumes Tier 3",
|
|
2003
|
+
"Lock: ?YES",
|
|
2004
|
+
"Lock: ?NO",
|
|
2005
|
+
"lock approvals?",
|
|
2006
|
+
"approves locks",
|
|
2007
|
+
"Conforms to lock",
|
|
2008
|
+
"Challenges lock",
|
|
2009
|
+
"checkDecisionNumbersFresh",
|
|
2010
|
+
String.raw`roles/team-leader\.md`,
|
|
2011
|
+
String.raw`\(,`,
|
|
2012
|
+
String.raw`,\)`,
|
|
2013
|
+
String.raw`\(\.\)`
|
|
2014
|
+
];
|
|
2015
|
+
var PATTERN_EXEMPT = {
|
|
2016
|
+
[String.raw`\bD-[0-9]{3}\b`]: ["./CLAUDE.md"],
|
|
2017
|
+
[String.raw`decisions\.md`]: [
|
|
2018
|
+
"docs-index.md",
|
|
2019
|
+
"apps/vada-ai/specs/legacy/README.md",
|
|
2020
|
+
"apps/vada-ai/specs/vada-product-spec.md",
|
|
2021
|
+
"apps/vada-ai/web/CLAUDE.md",
|
|
2022
|
+
"apps/vada-ai/CLAUDE.md"
|
|
2023
|
+
],
|
|
2024
|
+
"decisions-legacy": [
|
|
2025
|
+
"packages/aeg-core/src/file-classify.ts",
|
|
2026
|
+
"packages/aeg-core/src/file-classify.test.ts",
|
|
2027
|
+
"packages/aeg-core/src/pr-tier.test.ts",
|
|
2028
|
+
"docs-index.md",
|
|
2029
|
+
".claude/skills/database/SKILL.md",
|
|
2030
|
+
".claude/skills/vada-architecture/SKILL.md",
|
|
2031
|
+
"apps/vada-ai/specs/vada-byok-principles.md",
|
|
2032
|
+
"apps/vada-ai/web/CLAUDE.md",
|
|
2033
|
+
"apps/vada-ai/CLAUDE.md"
|
|
2034
|
+
],
|
|
2035
|
+
CONTRADICTION: ["apps/vada-ai/specs/vada-reviewers-spec.md"]
|
|
2036
|
+
};
|
|
2037
|
+
// ../../packages/aeg-core/src/dispatch-gate.ts
|
|
2038
|
+
function isHandClosedByRecognizedPrincipal(dep, principalAllowlist) {
|
|
2039
|
+
return dep.issueState === "closed" && dep.stateReason === "completed" && isPrincipal(dep.closedByActor ?? null, principalAllowlist);
|
|
2040
|
+
}
|
|
2041
|
+
function isSelfDependency(dep, task, issue) {
|
|
2042
|
+
if (dep.issue !== null && issue !== null && dep.issue === issue.number)
|
|
2043
|
+
return true;
|
|
2044
|
+
const bare = dep.id.trim().replace(/^#/, "");
|
|
2045
|
+
return bare.toLowerCase() === task.id.trim().toLowerCase();
|
|
2046
|
+
}
|
|
2047
|
+
function checkDispatchReadiness(input) {
|
|
2048
|
+
const { trancheSlug, task } = input;
|
|
2049
|
+
const taskLabel = `task ${task.id} (tranche ${trancheSlug})`;
|
|
2050
|
+
const principalAllowlist = input.principalAllowlist ?? PRINCIPAL_ALLOWLIST;
|
|
2051
|
+
const blockerDetails = [];
|
|
2052
|
+
const push = (blockerClass, message) => {
|
|
2053
|
+
blockerDetails.push({ class: blockerClass, message });
|
|
2054
|
+
};
|
|
2055
|
+
if (task.issue === null) {
|
|
2056
|
+
push("issue-existence", `dispatch-gate issue-existence: ${taskLabel} has no Issue (#TBD or blank) in the topology — not dispatchable until the Planner cuts the Issue.`);
|
|
2057
|
+
} else if (input.issue === null) {
|
|
2058
|
+
push("issue-existence", `dispatch-gate issue-existence: ${taskLabel} names Issue #${task.issue}, but it does not resolve to a real GitHub Issue (phantom reference).`);
|
|
2059
|
+
}
|
|
2060
|
+
if (input.issue !== null && !input.issueRationalePass) {
|
|
2061
|
+
push("rationale", `dispatch-gate rationale: Issue #${input.issue.number} for ${taskLabel} fails the rationale gate (checkIssueRationale) — the Planner must complete the eight-field rationale before this task is dispatchable.`);
|
|
2062
|
+
}
|
|
2063
|
+
for (const dep of input.dependsOn) {
|
|
2064
|
+
if (isSelfDependency(dep, task, input.issue)) {
|
|
2065
|
+
const issueStr = input.issue !== null ? `#${input.issue.number}` : "?";
|
|
2066
|
+
push("internal-self-dependency", `dispatch-gate INTERNAL: parsed a self-dependency for task ${task.id} (${issueStr}) — this is a parser bug in parseRationaleDeps, not a real dependency. Please report it upstream. Re-run once the rationale is corrected or the fix ships.`);
|
|
2067
|
+
continue;
|
|
2068
|
+
}
|
|
2069
|
+
if (dep.resolved === false) {
|
|
2070
|
+
push("depends-on-unresolvable", `dispatch-gate depends-on: ${taskLabel} depends on "${dep.id}", which is UNRESOLVABLE — the resolver could not find a matching tranche/task/Issue for this edge (not a claim about merge status). Not dispatchable until the edge is corrected.`);
|
|
2071
|
+
continue;
|
|
2072
|
+
}
|
|
2073
|
+
if (dep.readFailed === true) {
|
|
2074
|
+
const issueStr = dep.issue !== null ? ` (#${dep.issue})` : "";
|
|
2075
|
+
push("depends-on-read-failed", `dispatch-gate depends-on: ${taskLabel} depends on ${dep.id}${issueStr}, but the forge could not be read for that dependency — not a claim about its merge status. Retry the check.`);
|
|
2076
|
+
continue;
|
|
2077
|
+
}
|
|
2078
|
+
if (!dep.merged && !isHandClosedByRecognizedPrincipal(dep, principalAllowlist)) {
|
|
2079
|
+
const issueStr = dep.issue !== null ? ` (#${dep.issue})` : "";
|
|
2080
|
+
push("depends-on-not-merged", `dispatch-gate depends-on: ${taskLabel} depends on ${dep.id}${issueStr}, whose PR is not merged yet — not dispatchable, it serializes behind it.`);
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
for (const c of input.conflictsWith) {
|
|
2084
|
+
if (c.openOrInFlight) {
|
|
2085
|
+
const issueStr = c.issue !== null ? ` (#${c.issue})` : "";
|
|
2086
|
+
push("conflicts-with", `dispatch-gate conflicts-with: ${taskLabel} conflicts with ${c.id}${issueStr}, whose PR is open or in-flight — not dispatchable until it merges.`);
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
for (const proj of input.priorTrancheArchival) {
|
|
2090
|
+
if (proj.priorTrancheSlug !== null && !proj.archived) {
|
|
2091
|
+
push("prior-tranche-archival", `dispatch-gate prior-tranche-archival: project \`${proj.project}\`'s previous tranche \`${proj.priorTrancheSlug}\` is not archived — the Tranche Archivist must run before new work on this product.`);
|
|
2092
|
+
}
|
|
2093
|
+
}
|
|
2094
|
+
return { ready: blockerDetails.length === 0, blockers: blockerDetails.map((b) => b.message), blockerDetails };
|
|
2095
|
+
}
|
|
2096
|
+
// ../../packages/aeg-core/src/task-tools.ts
|
|
2097
|
+
import { z } from "zod";
|
|
2098
|
+
var TASK_TOOL_ERROR_KINDS = [
|
|
2099
|
+
"validation",
|
|
2100
|
+
"authority",
|
|
2101
|
+
"precondition",
|
|
2102
|
+
"capability",
|
|
2103
|
+
"infrastructure",
|
|
2104
|
+
"cancellation",
|
|
2105
|
+
"timeout",
|
|
2106
|
+
"uncertain_effect"
|
|
2107
|
+
];
|
|
2108
|
+
var TaskToolErrorSchema = z.object({
|
|
2109
|
+
kind: z.enum(TASK_TOOL_ERROR_KINDS),
|
|
2110
|
+
message: z.string().min(1),
|
|
2111
|
+
detail: z.string().optional()
|
|
2112
|
+
});
|
|
2113
|
+
var TaskToolRefSchema = z.union([
|
|
2114
|
+
z.object({ tranche: z.string().min(1), id: z.string().min(1) }).strict(),
|
|
2115
|
+
z.object({ issue: z.number().int().positive() }).strict()
|
|
2116
|
+
]);
|
|
2117
|
+
var MAX_PAGE_LIMIT = 100;
|
|
2118
|
+
var PageRequestSchema = z.object({
|
|
2119
|
+
cursor: z.string().optional(),
|
|
2120
|
+
limit: z.number().int().positive().max(MAX_PAGE_LIMIT).optional()
|
|
2121
|
+
});
|
|
2122
|
+
var FreshnessSchema = z.enum(["fresh", "stale", "unknown"]);
|
|
2123
|
+
var ObservedSchema = z.object({
|
|
2124
|
+
observedAt: z.string(),
|
|
2125
|
+
freshness: FreshnessSchema
|
|
2126
|
+
});
|
|
2127
|
+
var TaskStatusInputSchema = z.object({
|
|
2128
|
+
task: TaskToolRefSchema.optional()
|
|
2129
|
+
}).merge(PageRequestSchema).strict();
|
|
2130
|
+
var TaskConfidenceSchema = z.object({
|
|
2131
|
+
round: z.number().int().positive(),
|
|
2132
|
+
percent: z.number().int().min(0).max(100).nullable(),
|
|
2133
|
+
source: z.enum(["stated", "published-summary"])
|
|
2134
|
+
}).strict();
|
|
2135
|
+
var TaskPhaseHistorySchema = z.object({
|
|
2136
|
+
typicalPhaseMinutes: z.number().nonnegative(),
|
|
2137
|
+
typicalPhaseSamples: z.number().int().positive()
|
|
2138
|
+
}).strict();
|
|
2139
|
+
var TaskStatusItemSchema = z.object({
|
|
2140
|
+
task: TaskToolRefSchema,
|
|
2141
|
+
issue: z.number().int().positive(),
|
|
2142
|
+
pr: z.number().int().positive().nullable(),
|
|
2143
|
+
state: z.string(),
|
|
2144
|
+
round: z.number().int().positive().nullable().optional(),
|
|
2145
|
+
phase: z.string().min(1).nullable().optional(),
|
|
2146
|
+
minutesInPhase: z.number().nonnegative().nullable().optional(),
|
|
2147
|
+
phaseIsCurrent: z.boolean().nullable().optional(),
|
|
2148
|
+
lastConfidence: TaskConfidenceSchema.nullable().optional(),
|
|
2149
|
+
lastConfidenceUnread: z.boolean().optional(),
|
|
2150
|
+
phaseHistory: TaskPhaseHistorySchema.nullable().optional()
|
|
2151
|
+
}).merge(ObservedSchema);
|
|
2152
|
+
var TaskStatusResultSchema = z.object({
|
|
2153
|
+
items: z.array(TaskStatusItemSchema),
|
|
2154
|
+
nextCursor: z.string().nullable(),
|
|
2155
|
+
table: z.string()
|
|
2156
|
+
});
|
|
2157
|
+
var RequestedAuthoritySchema = z.enum(["planner", "principal", "operator", "self"]);
|
|
2158
|
+
var EscalationInputsSchema = z.object({
|
|
2159
|
+
task: z.number().int().positive(),
|
|
2160
|
+
round: z.number().int().nonnegative(),
|
|
2161
|
+
head: z.string(),
|
|
2162
|
+
branch: z.string(),
|
|
2163
|
+
prNumber: z.number().int().positive().nullable()
|
|
2164
|
+
});
|
|
2165
|
+
var EscalationEvidenceSchema = z.object({
|
|
2166
|
+
round: z.number().int().nonnegative(),
|
|
2167
|
+
reviewer: z.string().nullable(),
|
|
2168
|
+
security: z.string().nullable()
|
|
2169
|
+
});
|
|
2170
|
+
var EscalationRunIdentitySchema = z.object({
|
|
2171
|
+
runId: z.string(),
|
|
2172
|
+
pid: z.number().int().positive(),
|
|
2173
|
+
host: z.string()
|
|
2174
|
+
});
|
|
2175
|
+
var EscalationInputVersionsSchema = z.object({
|
|
2176
|
+
briefHash: z.string().nullable(),
|
|
2177
|
+
objectivesVersion: z.string().nullable(),
|
|
2178
|
+
rulingOrdinal: z.number().int().nonnegative(),
|
|
2179
|
+
policyDigest: z.string()
|
|
2180
|
+
});
|
|
2181
|
+
var TaskEscalationReadInputSchema = z.object({
|
|
2182
|
+
task: TaskToolRefSchema
|
|
2183
|
+
}).merge(PageRequestSchema).strict();
|
|
2184
|
+
var TaskEscalationPacketSchema = z.object({
|
|
2185
|
+
reason: z.string(),
|
|
2186
|
+
detail: z.string().nullable(),
|
|
2187
|
+
inputs: EscalationInputsSchema.nullable(),
|
|
2188
|
+
evidence: EscalationEvidenceSchema.nullable(),
|
|
2189
|
+
attemptedRecovery: z.string(),
|
|
2190
|
+
requestedAuthority: RequestedAuthoritySchema,
|
|
2191
|
+
permittedNextActions: z.array(z.string()),
|
|
2192
|
+
runIdentity: EscalationRunIdentitySchema.nullable(),
|
|
2193
|
+
inputVersions: EscalationInputVersionsSchema.nullable()
|
|
2194
|
+
}).merge(ObservedSchema);
|
|
2195
|
+
var TaskEscalationReadResultSchema = z.object({
|
|
2196
|
+
items: z.array(TaskEscalationPacketSchema),
|
|
2197
|
+
nextCursor: z.string().nullable()
|
|
2198
|
+
}).merge(ObservedSchema);
|
|
2199
|
+
var TaskPrCheckSchema = z.object({
|
|
2200
|
+
name: z.string(),
|
|
2201
|
+
required: z.boolean(),
|
|
2202
|
+
status: z.string(),
|
|
2203
|
+
conclusion: z.string().nullable(),
|
|
2204
|
+
detailsUrl: z.string().nullable(),
|
|
2205
|
+
failureSummary: z.string().nullable()
|
|
2206
|
+
});
|
|
2207
|
+
var TaskPrVerdictSchema = z.object({
|
|
2208
|
+
role: z.enum(["code-review", "security"]),
|
|
2209
|
+
value: z.string(),
|
|
2210
|
+
judgedHead: z.string().nullable(),
|
|
2211
|
+
objectivesVersion: z.string().nullable()
|
|
2212
|
+
});
|
|
2213
|
+
var TaskPrPauseSchema = z.object({
|
|
2214
|
+
reason: z.string(),
|
|
2215
|
+
body: z.string()
|
|
2216
|
+
});
|
|
2217
|
+
var TaskPrReviewRecordSchema = z.object({
|
|
2218
|
+
verdicts: z.array(TaskPrVerdictSchema),
|
|
2219
|
+
roundMarkers: z.array(z.number().int().nonnegative()),
|
|
2220
|
+
pause: TaskPrPauseSchema.nullable()
|
|
2221
|
+
});
|
|
2222
|
+
var TaskPrReadInputSchema = z.object({
|
|
2223
|
+
task: TaskToolRefSchema,
|
|
2224
|
+
pr: z.number().int().positive().optional()
|
|
2225
|
+
}).strict();
|
|
2226
|
+
var TaskPrReadResultSchema = z.object({
|
|
2227
|
+
task: TaskToolRefSchema,
|
|
2228
|
+
issue: z.number().int().positive(),
|
|
2229
|
+
pr: z.number().int().positive(),
|
|
2230
|
+
head: z.string().nullable(),
|
|
2231
|
+
checks: z.array(TaskPrCheckSchema),
|
|
2232
|
+
review: TaskPrReviewRecordSchema
|
|
2233
|
+
}).merge(ObservedSchema);
|
|
2234
|
+
var TaskStartResultSchema = z.object({
|
|
2235
|
+
requestId: z.string().min(1),
|
|
2236
|
+
run: TaskToolRefSchema,
|
|
2237
|
+
started: z.boolean(),
|
|
2238
|
+
startedAt: z.string(),
|
|
2239
|
+
mode: z.literal("attended")
|
|
2240
|
+
});
|
|
2241
|
+
var TaskResumeInputSchema = z.object({
|
|
2242
|
+
task: TaskToolRefSchema
|
|
2243
|
+
}).strict();
|
|
2244
|
+
var TaskCancelInputSchema = z.object({
|
|
2245
|
+
task: TaskToolRefSchema,
|
|
2246
|
+
reason: z.string().min(1)
|
|
2247
|
+
}).strict();
|
|
2248
|
+
var TaskResumeResultSchema = z.object({
|
|
2249
|
+
task: z.number().int().positive(),
|
|
2250
|
+
pr: z.number().int().positive().nullable(),
|
|
2251
|
+
escalationId: z.string().min(1),
|
|
2252
|
+
outcome: z.enum(["started", "already_resumed"]),
|
|
2253
|
+
authenticatedBy: z.string().min(1),
|
|
2254
|
+
authenticatedFrom: z.string().min(1)
|
|
2255
|
+
});
|
|
2256
|
+
var TaskCancelOutcomeSchema = z.enum(["confirmed", "pending", "uncertain"]);
|
|
2257
|
+
var TaskCancelResultSchema = z.object({
|
|
2258
|
+
task: z.number().int().positive(),
|
|
2259
|
+
pr: z.number().int().positive().nullable(),
|
|
2260
|
+
escalationId: z.string().min(1),
|
|
2261
|
+
outcome: TaskCancelOutcomeSchema,
|
|
2262
|
+
authenticatedBy: z.string().min(1),
|
|
2263
|
+
authenticatedFrom: z.string().min(1),
|
|
2264
|
+
fencedEffectKeys: z.array(z.string())
|
|
2265
|
+
});
|
|
2266
|
+
// ../../packages/aeg-core/src/log/schema.ts
|
|
2267
|
+
import { z as z3 } from "zod";
|
|
2268
|
+
|
|
2269
|
+
// ../../packages/aeg-core/src/log/custom.ts
|
|
2270
|
+
import { z as z2 } from "zod";
|
|
2271
|
+
var CUSTOM_EVENT_NAME_PATTERN = /^[a-z][a-z0-9_]*\.[a-z][a-z0-9_.]*$/;
|
|
2272
|
+
var CUSTOM_EVENT_NAME_MAX_LENGTH = 64;
|
|
2273
|
+
var CUSTOM_EVENT_RESERVED_NAMESPACE = "vinaya";
|
|
2274
|
+
var CUSTOM_EVENT_MAX_FIELDS = 20;
|
|
2275
|
+
var CUSTOM_FIELD_NAME_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
2276
|
+
var CUSTOM_FIELD_NAME_MAX_LENGTH = 64;
|
|
2277
|
+
var CUSTOM_TEXT_MAX_LENGTH = 500;
|
|
2278
|
+
var CUSTOM_WORD_PATTERN = /^[a-z0-9][a-z0-9_-]*$/;
|
|
2279
|
+
var CUSTOM_WORD_MAX_LENGTH = 64;
|
|
2280
|
+
var CUSTOM_FIELD_MAX_WORDS = 50;
|
|
2281
|
+
var CustomFieldTypeSchema = z2.union([z2.enum(["text", "number", "boolean"]), z2.array(z2.string())]);
|
|
2282
|
+
var CustomEventDeclarationsSchema = z2.record(z2.string(), z2.object({
|
|
2283
|
+
fields: z2.record(z2.string(), CustomFieldTypeSchema)
|
|
2284
|
+
}).strict()).superRefine((events, ctx) => {
|
|
2285
|
+
for (const [name, declaration] of Object.entries(events)) {
|
|
2286
|
+
const refuse = (message, path = []) => {
|
|
2287
|
+
ctx.addIssue({
|
|
2288
|
+
code: z2.ZodIssueCode.custom,
|
|
2289
|
+
path: [name, ...path],
|
|
2290
|
+
message: `logs.events "${name}": ${message}`
|
|
2291
|
+
});
|
|
2292
|
+
};
|
|
2293
|
+
if (name.length > CUSTOM_EVENT_NAME_MAX_LENGTH) {
|
|
2294
|
+
refuse(`the name must be at most ${CUSTOM_EVENT_NAME_MAX_LENGTH} characters`);
|
|
2295
|
+
}
|
|
2296
|
+
if (!CUSTOM_EVENT_NAME_PATTERN.test(name)) {
|
|
2297
|
+
refuse("the name must be `<namespace>.<event>` — lowercase letters, digits and `_`, a dot between them");
|
|
2298
|
+
} else if (name.split(".")[0] === CUSTOM_EVENT_RESERVED_NAMESPACE) {
|
|
2299
|
+
refuse(`the \`${CUSTOM_EVENT_RESERVED_NAMESPACE}.\` namespace is reserved for Vinaya's own events`);
|
|
2300
|
+
}
|
|
2301
|
+
const fieldEntries = Object.entries(declaration.fields);
|
|
2302
|
+
if (fieldEntries.length > CUSTOM_EVENT_MAX_FIELDS) {
|
|
2303
|
+
refuse(`at most ${CUSTOM_EVENT_MAX_FIELDS} fields may be declared (found ${fieldEntries.length})`, ["fields"]);
|
|
2304
|
+
}
|
|
2305
|
+
for (const [field, type] of fieldEntries) {
|
|
2306
|
+
if (field.length > CUSTOM_FIELD_NAME_MAX_LENGTH || !CUSTOM_FIELD_NAME_PATTERN.test(field)) {
|
|
2307
|
+
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]);
|
|
2308
|
+
}
|
|
2309
|
+
if (typeof type === "string")
|
|
2310
|
+
continue;
|
|
2311
|
+
if (type.length === 0) {
|
|
2312
|
+
refuse(`field "${field}": a list of words must name at least one word`, ["fields", field]);
|
|
2313
|
+
}
|
|
2314
|
+
if (type.length > CUSTOM_FIELD_MAX_WORDS) {
|
|
2315
|
+
refuse(`field "${field}": a list of words may name at most ${CUSTOM_FIELD_MAX_WORDS}`, ["fields", field]);
|
|
2316
|
+
}
|
|
2317
|
+
const bad = type.filter((w) => w.length > CUSTOM_WORD_MAX_LENGTH || !CUSTOM_WORD_PATTERN.test(w));
|
|
2318
|
+
if (bad.length > 0) {
|
|
2319
|
+
refuse(`field "${field}": a listed word is lowercase letters, digits, \`_\` and \`-\`, at most ${CUSTOM_WORD_MAX_LENGTH} characters`, ["fields", field]);
|
|
2320
|
+
}
|
|
2321
|
+
if (new Set(type).size !== type.length) {
|
|
2322
|
+
refuse(`field "${field}": a list of words names a word twice`, ["fields", field]);
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
});
|
|
2327
|
+
|
|
2328
|
+
// ../../packages/aeg-core/src/log/schema.ts
|
|
2329
|
+
var CONFIDENCE_REASON_MAX_LENGTH = 280;
|
|
2330
|
+
var REVIEW_FINDING_DESCRIPTION_MAX_LENGTH = 1000;
|
|
2331
|
+
var ROLE_VALUES = [
|
|
2332
|
+
"planner",
|
|
2333
|
+
"developer",
|
|
2334
|
+
"code-reviewer",
|
|
2335
|
+
"security",
|
|
2336
|
+
"principal",
|
|
2337
|
+
"archivist",
|
|
2338
|
+
"architect"
|
|
2339
|
+
];
|
|
2340
|
+
var RoleSchema = z3.enum(ROLE_VALUES);
|
|
2341
|
+
var HOST_VALUES = ["hook", "ci", "cli", "loop"];
|
|
2342
|
+
var HostSchema = z3.enum(HOST_VALUES);
|
|
2343
|
+
var RUN_ID_PATTERN = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
2344
|
+
var headerMetaCore = {
|
|
2345
|
+
ts: z3.string(),
|
|
2346
|
+
run_id: z3.string().regex(RUN_ID_PATTERN),
|
|
2347
|
+
seq: z3.number().int().nonnegative(),
|
|
2348
|
+
repo: z3.string().nullable(),
|
|
2349
|
+
vinaya: z3.string(),
|
|
2350
|
+
doctrine: z3.string(),
|
|
2351
|
+
host: HostSchema,
|
|
2352
|
+
machine: z3.string()
|
|
2353
|
+
};
|
|
2354
|
+
var HeaderMetaV1Schema = z3.object({
|
|
2355
|
+
schema: z3.literal(1),
|
|
2356
|
+
...headerMetaCore
|
|
2357
|
+
}).strict();
|
|
2358
|
+
var LineageSchema = z3.object({
|
|
2359
|
+
run: z3.string().nullable(),
|
|
2360
|
+
attempt: z3.number().int().nullable(),
|
|
2361
|
+
parent: z3.string().nullable()
|
|
2362
|
+
}).strict();
|
|
2363
|
+
var InputVersionsSchema = z3.object({
|
|
2364
|
+
objectives_version: z3.string().nullable(),
|
|
2365
|
+
brief_hash: z3.string().nullable(),
|
|
2366
|
+
ruling_ordinal: z3.number().int().nullable(),
|
|
2367
|
+
policy_digest: z3.string().nullable()
|
|
2368
|
+
}).strict();
|
|
2369
|
+
var ProvenanceSchema = z3.enum(["parent_attributed", "env_correlated", "self_reported", "unavailable"]);
|
|
2370
|
+
var HeaderMetaV2Schema = z3.object({
|
|
2371
|
+
schema: z3.literal(2),
|
|
2372
|
+
...headerMetaCore,
|
|
2373
|
+
event_id: z3.string().min(1),
|
|
2374
|
+
process_id: z3.string().min(1),
|
|
2375
|
+
actor_id: z3.string().nullable(),
|
|
2376
|
+
lineage: LineageSchema,
|
|
2377
|
+
input_versions: InputVersionsSchema,
|
|
2378
|
+
provenance: ProvenanceSchema
|
|
2379
|
+
}).strict();
|
|
2380
|
+
var WorkSchema = z3.object({
|
|
2381
|
+
ref: z3.string().nullable(),
|
|
2382
|
+
repo: z3.string().nullable(),
|
|
2383
|
+
change: z3.string().nullable(),
|
|
2384
|
+
revision: z3.string().nullable()
|
|
2385
|
+
}).strict();
|
|
2386
|
+
var FlowSchema = z3.object({
|
|
2387
|
+
id: z3.string().nullable(),
|
|
2388
|
+
version: z3.string().nullable()
|
|
2389
|
+
}).strict();
|
|
2390
|
+
var HeaderMetaV3Schema = z3.object({
|
|
2391
|
+
schema: z3.literal(3),
|
|
2392
|
+
...headerMetaCore,
|
|
2393
|
+
event_id: z3.string().min(1),
|
|
2394
|
+
process_id: z3.string().min(1),
|
|
2395
|
+
actor_id: z3.string().nullable(),
|
|
2396
|
+
lineage: LineageSchema,
|
|
2397
|
+
input_versions: InputVersionsSchema,
|
|
2398
|
+
provenance: ProvenanceSchema,
|
|
2399
|
+
work: WorkSchema,
|
|
2400
|
+
flow: FlowSchema,
|
|
2401
|
+
runtime: z3.string().nullable(),
|
|
2402
|
+
source: z3.string().nullable()
|
|
2403
|
+
}).strict();
|
|
2404
|
+
var HeaderMetaSchema = z3.discriminatedUnion("schema", [HeaderMetaV1Schema, HeaderMetaV2Schema, HeaderMetaV3Schema]);
|
|
2405
|
+
var SubjectSchema = z3.object({
|
|
2406
|
+
issue: z3.number().int().nullable(),
|
|
2407
|
+
pr: z3.number().int().optional(),
|
|
2408
|
+
sha: z3.string().optional(),
|
|
2409
|
+
role: z3.union([RoleSchema, z3.literal("unattributed")]),
|
|
2410
|
+
round: z3.number().int().optional(),
|
|
2411
|
+
objectives_version: z3.string().optional()
|
|
2412
|
+
}).strict();
|
|
2413
|
+
var HeaderSchema = z3.object({
|
|
2414
|
+
meta: HeaderMetaSchema,
|
|
2415
|
+
subject: SubjectSchema
|
|
2416
|
+
}).strict();
|
|
2417
|
+
var envelopeTail = {
|
|
2418
|
+
duration_ms: z3.number().nonnegative().optional(),
|
|
2419
|
+
payload: z3.object({}).strict()
|
|
2420
|
+
};
|
|
2421
|
+
var ReviewFindingSchema = z3.object({
|
|
2422
|
+
id: z3.string(),
|
|
2423
|
+
severity: z3.string(),
|
|
2424
|
+
location: z3.string().optional(),
|
|
2425
|
+
deferral_reason: z3.enum(["outside-surface", "unchanged-line"]).optional(),
|
|
2426
|
+
description: z3.string().max(REVIEW_FINDING_DESCRIPTION_MAX_LENGTH).optional(),
|
|
2427
|
+
state: z3.string().optional(),
|
|
2428
|
+
severity_scale: z3.string().optional(),
|
|
2429
|
+
policy_treatment: z3.enum(["blocking", "non_blocking", "unavailable"]).optional(),
|
|
2430
|
+
confidence: z3.number().min(0).max(1).optional(),
|
|
2431
|
+
confidence_scale: z3.string().optional(),
|
|
2432
|
+
confidence_source: z3.string().optional()
|
|
2433
|
+
}).strict();
|
|
2434
|
+
var DispatchOutcomeSchema = z3.discriminatedUnion("type", [
|
|
2435
|
+
z3.object({ type: z3.literal("pr_opened"), pr: z3.number().int(), head: z3.string() }).strict(),
|
|
2436
|
+
z3.object({
|
|
2437
|
+
type: z3.literal("round_pushed"),
|
|
2438
|
+
pr: z3.number().int(),
|
|
2439
|
+
head: z3.string(),
|
|
2440
|
+
comment_id: z3.number().int()
|
|
2441
|
+
}).strict(),
|
|
2442
|
+
z3.object({
|
|
2443
|
+
type: z3.literal("verdict"),
|
|
2444
|
+
verdict: z3.enum(["APPROVE", "REQUEST CHANGES", "PASS", "FAIL"]),
|
|
2445
|
+
head: z3.string(),
|
|
2446
|
+
comment_id: z3.number().int(),
|
|
2447
|
+
objectives: z3.array(z3.object({ id: z3.string(), met: z3.boolean() }).strict()),
|
|
2448
|
+
findings: z3.array(ReviewFindingSchema)
|
|
2449
|
+
}).strict(),
|
|
2450
|
+
z3.object({
|
|
2451
|
+
type: z3.literal("escalation"),
|
|
2452
|
+
class: z3.enum(["authority", "strategy", "product"]),
|
|
2453
|
+
comment_id: z3.number().int()
|
|
2454
|
+
}).strict(),
|
|
2455
|
+
z3.object({ type: z3.literal("brief"), comment_id: z3.number().int(), hash: z3.string() }).strict(),
|
|
2456
|
+
z3.object({ type: z3.literal("plan"), issues: z3.array(z3.number().int()) }).strict(),
|
|
2457
|
+
z3.object({ type: z3.literal("archive"), provenance_comment_id: z3.number().int() }).strict(),
|
|
2458
|
+
z3.object({ type: z3.literal("completed") }).strict()
|
|
2459
|
+
]);
|
|
2460
|
+
var dispatchShared = {
|
|
2461
|
+
meta: HeaderMetaSchema,
|
|
2462
|
+
subject: SubjectSchema,
|
|
2463
|
+
kind: z3.literal("dispatch"),
|
|
2464
|
+
...envelopeTail,
|
|
2465
|
+
target_role: RoleSchema,
|
|
2466
|
+
model: z3.string(),
|
|
2467
|
+
round: z3.number().int().optional(),
|
|
2468
|
+
effect_id: z3.string()
|
|
2469
|
+
};
|
|
2470
|
+
var dispatchUsageField = z3.object({ input: z3.number().nonnegative(), output: z3.number().nonnegative() }).strict().nullable();
|
|
2471
|
+
var DispatchEventSchema = z3.discriminatedUnion("event", [
|
|
2472
|
+
z3.object({ ...dispatchShared, event: z3.literal("dispatched"), prompt_hash: z3.string() }).strict(),
|
|
2473
|
+
z3.object({
|
|
2474
|
+
...dispatchShared,
|
|
2475
|
+
event: z3.literal("outcome_received"),
|
|
2476
|
+
outcome: DispatchOutcomeSchema,
|
|
2477
|
+
usage: dispatchUsageField
|
|
2478
|
+
}).strict(),
|
|
2479
|
+
z3.object({
|
|
2480
|
+
...dispatchShared,
|
|
2481
|
+
event: z3.literal("dispatch_failed"),
|
|
2482
|
+
reason: z3.enum(["timeout", "crash", "refused", "unattributed_write", "usage_limit"]),
|
|
2483
|
+
usage_limit: z3.object({ agent: z3.string().min(1), reset_at: z3.string().nullable() }).strict().optional(),
|
|
2484
|
+
usage: dispatchUsageField
|
|
2485
|
+
}).strict()
|
|
2486
|
+
]);
|
|
2487
|
+
var CODE_TOKEN_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
|
|
2488
|
+
var CodeTokenSchema = z3.string().regex(CODE_TOKEN_PATTERN);
|
|
2489
|
+
var ReviewerVerdictSchema = z3.object({
|
|
2490
|
+
role: RoleSchema,
|
|
2491
|
+
outcome: z3.enum(["approve", "changes_requested", "not_reviewed"]),
|
|
2492
|
+
blockers: z3.number().int().nonnegative()
|
|
2493
|
+
}).strict();
|
|
2494
|
+
var loopShared = {
|
|
2495
|
+
meta: HeaderMetaSchema,
|
|
2496
|
+
subject: SubjectSchema,
|
|
2497
|
+
kind: z3.literal("dev_review_loop"),
|
|
2498
|
+
...envelopeTail,
|
|
2499
|
+
loop_id: z3.string()
|
|
2500
|
+
};
|
|
2501
|
+
var DevReviewLoopEventSchema = z3.discriminatedUnion("event", [
|
|
2502
|
+
z3.object({
|
|
2503
|
+
...loopShared,
|
|
2504
|
+
event: z3.literal("loop_started"),
|
|
2505
|
+
task: z3.number().int(),
|
|
2506
|
+
policy: z3.object({
|
|
2507
|
+
max_rounds: z3.number().int().nonnegative(),
|
|
2508
|
+
reviewers: z3.array(RoleSchema),
|
|
2509
|
+
models: z3.record(RoleSchema, z3.string())
|
|
2510
|
+
}).strict()
|
|
2511
|
+
}).strict(),
|
|
2512
|
+
z3.object({ ...loopShared, event: z3.literal("round_started"), round: z3.number().int(), base_head: z3.string() }).strict(),
|
|
2513
|
+
z3.object({
|
|
2514
|
+
...loopShared,
|
|
2515
|
+
event: z3.literal("gate_result_read"),
|
|
2516
|
+
round: z3.number().int(),
|
|
2517
|
+
head: z3.string(),
|
|
2518
|
+
green: z3.boolean(),
|
|
2519
|
+
confidence_value: z3.number().int().min(0).max(100).optional(),
|
|
2520
|
+
confidence_reason: z3.string().max(CONFIDENCE_REASON_MAX_LENGTH).optional(),
|
|
2521
|
+
confidence_unavailable: z3.boolean().optional(),
|
|
2522
|
+
extra_turn_spent: z3.boolean().optional()
|
|
2523
|
+
}).strict(),
|
|
2524
|
+
z3.object({
|
|
2525
|
+
...loopShared,
|
|
2526
|
+
event: z3.literal("verdicts_read"),
|
|
2527
|
+
round: z3.number().int(),
|
|
2528
|
+
head: z3.string(),
|
|
2529
|
+
all_approve: z3.boolean(),
|
|
2530
|
+
blockers: z3.number().int().nonnegative(),
|
|
2531
|
+
findings: z3.array(ReviewFindingSchema).optional(),
|
|
2532
|
+
reviewers: z3.array(ReviewerVerdictSchema).optional()
|
|
2533
|
+
}).strict(),
|
|
2534
|
+
z3.object({
|
|
2535
|
+
...loopShared,
|
|
2536
|
+
event: z3.literal("findings_compared"),
|
|
2537
|
+
round: z3.number().int(),
|
|
2538
|
+
open: z3.array(z3.string()),
|
|
2539
|
+
resolved: z3.array(z3.string()),
|
|
2540
|
+
new: z3.array(z3.string()),
|
|
2541
|
+
recurring: z3.array(z3.string())
|
|
2542
|
+
}).strict(),
|
|
2543
|
+
z3.object({
|
|
2544
|
+
...loopShared,
|
|
2545
|
+
event: z3.literal("stop_condition_met"),
|
|
2546
|
+
round: z3.number().int(),
|
|
2547
|
+
condition: z3.enum([
|
|
2548
|
+
"green",
|
|
2549
|
+
"max_rounds",
|
|
2550
|
+
"no_progress",
|
|
2551
|
+
"escalated",
|
|
2552
|
+
"principal_stop",
|
|
2553
|
+
"confidence",
|
|
2554
|
+
"reappearance",
|
|
2555
|
+
"repeat_finding",
|
|
2556
|
+
"repeat_failure",
|
|
2557
|
+
"time_budget"
|
|
2558
|
+
])
|
|
2559
|
+
}).strict(),
|
|
2560
|
+
z3.object({
|
|
2561
|
+
...loopShared,
|
|
2562
|
+
event: z3.literal("paused"),
|
|
2563
|
+
round: z3.number().int(),
|
|
2564
|
+
reason: z3.enum(["escalation", "principal_item", "refreeze_needed"]),
|
|
2565
|
+
reason_code: CodeTokenSchema.optional()
|
|
2566
|
+
}).strict(),
|
|
2567
|
+
z3.object({
|
|
2568
|
+
...loopShared,
|
|
2569
|
+
event: z3.literal("resumed"),
|
|
2570
|
+
round: z3.number().int(),
|
|
2571
|
+
by: z3.enum(["principal", "driver"])
|
|
2572
|
+
}).strict(),
|
|
2573
|
+
z3.object({
|
|
2574
|
+
...loopShared,
|
|
2575
|
+
event: z3.literal("cancelled"),
|
|
2576
|
+
round: z3.number().int(),
|
|
2577
|
+
by: z3.literal("principal")
|
|
2578
|
+
}).strict(),
|
|
2579
|
+
z3.object({
|
|
2580
|
+
...loopShared,
|
|
2581
|
+
event: z3.literal("unpushed_work_resume"),
|
|
2582
|
+
round: z3.number().int(),
|
|
2583
|
+
branch: z3.string(),
|
|
2584
|
+
detail: z3.string()
|
|
2585
|
+
}).strict(),
|
|
2586
|
+
z3.object({
|
|
2587
|
+
...loopShared,
|
|
2588
|
+
event: z3.literal("round_ended"),
|
|
2589
|
+
round: z3.number().int(),
|
|
2590
|
+
base_head: z3.string(),
|
|
2591
|
+
head: z3.string(),
|
|
2592
|
+
files_changed: z3.number().int().nonnegative(),
|
|
2593
|
+
insertions: z3.number().int().nonnegative(),
|
|
2594
|
+
deletions: z3.number().int().nonnegative(),
|
|
2595
|
+
wall_ms: z3.number().nonnegative(),
|
|
2596
|
+
outcome: z3.enum(["green", "changes_requested", "escalated"])
|
|
2597
|
+
}).strict(),
|
|
2598
|
+
z3.object({
|
|
2599
|
+
...loopShared,
|
|
2600
|
+
event: z3.literal("journal_finalized"),
|
|
2601
|
+
rounds: z3.number().int().nonnegative(),
|
|
2602
|
+
total_wall_ms: z3.number().nonnegative(),
|
|
2603
|
+
time_to_green_ms: z3.number().nonnegative().nullable(),
|
|
2604
|
+
files_changed_total: z3.number().int().nonnegative(),
|
|
2605
|
+
final_head: z3.string(),
|
|
2606
|
+
result: z3.enum(["merged_ready", "stopped"])
|
|
2607
|
+
}).strict(),
|
|
2608
|
+
z3.object({
|
|
2609
|
+
...loopShared,
|
|
2610
|
+
event: z3.literal("infrastructure_retry"),
|
|
2611
|
+
round: z3.number().int(),
|
|
2612
|
+
failure_kind: z3.enum(["pause_comment_post", "developer_connection"]),
|
|
2613
|
+
attempts: z3.number().int().positive(),
|
|
2614
|
+
outcome: z3.enum(["recovered", "exhausted"])
|
|
2615
|
+
}).strict(),
|
|
2616
|
+
z3.object({
|
|
2617
|
+
...loopShared,
|
|
2618
|
+
event: z3.literal("driver_heartbeat"),
|
|
2619
|
+
task: z3.number().int(),
|
|
2620
|
+
pr: z3.number().int().positive().optional(),
|
|
2621
|
+
round: z3.number().int(),
|
|
2622
|
+
phase: z3.string()
|
|
2623
|
+
}).strict(),
|
|
2624
|
+
z3.object({
|
|
2625
|
+
...loopShared,
|
|
2626
|
+
event: z3.literal("driver_exited"),
|
|
2627
|
+
task: z3.number().int(),
|
|
2628
|
+
reason: z3.enum(["finished", "paused", "reexec", "error", "signal"]),
|
|
2629
|
+
last_decision: z3.string(),
|
|
2630
|
+
exit_code: z3.number().int().optional(),
|
|
2631
|
+
error_class: CodeTokenSchema.optional()
|
|
2632
|
+
}).strict()
|
|
2633
|
+
]);
|
|
2634
|
+
var ForgeOpSchema = z3.enum([
|
|
2635
|
+
"pr.create",
|
|
2636
|
+
"pr.comment",
|
|
2637
|
+
"pr.body.replace",
|
|
2638
|
+
"pr.refreeze",
|
|
2639
|
+
"issue.create",
|
|
2640
|
+
"issue.edit",
|
|
2641
|
+
"issue.comment",
|
|
2642
|
+
"milestone.create",
|
|
2643
|
+
"milestone.edit",
|
|
2644
|
+
"milestone.close",
|
|
2645
|
+
"label.add",
|
|
2646
|
+
"label.remove"
|
|
2647
|
+
]);
|
|
2648
|
+
var ForgeWriteTargetSchema = z3.object({
|
|
2649
|
+
issue: z3.number().int().optional(),
|
|
2650
|
+
pr: z3.number().int().optional()
|
|
2651
|
+
}).strict();
|
|
2652
|
+
var forgeWriteShared = {
|
|
2653
|
+
meta: HeaderMetaSchema,
|
|
2654
|
+
subject: SubjectSchema,
|
|
2655
|
+
kind: z3.literal("forge_write"),
|
|
2656
|
+
...envelopeTail,
|
|
2657
|
+
op: ForgeOpSchema,
|
|
2658
|
+
target: ForgeWriteTargetSchema
|
|
2659
|
+
};
|
|
2660
|
+
var ForgeWriteEventSchema = z3.discriminatedUnion("event", [
|
|
2661
|
+
z3.object({ ...forgeWriteShared, event: z3.literal("validated") }).strict(),
|
|
2662
|
+
z3.object({ ...forgeWriteShared, event: z3.literal("refused"), reason: z3.string() }).strict(),
|
|
2663
|
+
z3.object({ ...forgeWriteShared, event: z3.literal("written"), comment_ids: z3.array(z3.string()) }).strict()
|
|
2664
|
+
]);
|
|
2665
|
+
var GateOutcomeSchema = z3.enum([
|
|
2666
|
+
"pass",
|
|
2667
|
+
"fail",
|
|
2668
|
+
"wait",
|
|
2669
|
+
"skip",
|
|
2670
|
+
"invalid_input",
|
|
2671
|
+
"unavailable_dependency",
|
|
2672
|
+
"timeout",
|
|
2673
|
+
"cancelled"
|
|
2674
|
+
]);
|
|
2675
|
+
var gateShared = {
|
|
2676
|
+
meta: HeaderMetaSchema,
|
|
2677
|
+
subject: SubjectSchema,
|
|
2678
|
+
kind: z3.literal("gate"),
|
|
2679
|
+
...envelopeTail,
|
|
2680
|
+
check: z3.string(),
|
|
2681
|
+
check_version: z3.string().nullable(),
|
|
2682
|
+
policy_version: z3.string().nullable(),
|
|
2683
|
+
input_fingerprint: z3.string().nullable()
|
|
2684
|
+
};
|
|
2685
|
+
var GateEventSchema = z3.discriminatedUnion("event", [
|
|
2686
|
+
z3.object({
|
|
2687
|
+
...gateShared,
|
|
2688
|
+
event: z3.literal("checked"),
|
|
2689
|
+
outcome: GateOutcomeSchema,
|
|
2690
|
+
reason: z3.string().optional()
|
|
2691
|
+
}).strict(),
|
|
2692
|
+
z3.object({
|
|
2693
|
+
meta: HeaderMetaSchema,
|
|
2694
|
+
subject: SubjectSchema,
|
|
2695
|
+
kind: z3.literal("gate"),
|
|
2696
|
+
...envelopeTail,
|
|
2697
|
+
event: z3.literal("summary"),
|
|
2698
|
+
ran: z3.number().int().nonnegative(),
|
|
2699
|
+
passed: z3.number().int().nonnegative(),
|
|
2700
|
+
failed: z3.number().int().nonnegative(),
|
|
2701
|
+
skipped: z3.number().int().nonnegative(),
|
|
2702
|
+
failed_checks: z3.array(z3.string())
|
|
2703
|
+
}).strict()
|
|
2704
|
+
]);
|
|
2705
|
+
var OperationResultSchema = z3.enum(["ok", "error", "refused", "timeout", "cancelled", "unavailable"]);
|
|
2706
|
+
var operationShared = {
|
|
2707
|
+
meta: HeaderMetaSchema,
|
|
2708
|
+
subject: SubjectSchema,
|
|
2709
|
+
kind: z3.literal("operation"),
|
|
2710
|
+
...envelopeTail,
|
|
2711
|
+
operation: z3.string(),
|
|
2712
|
+
target: z3.string().nullable()
|
|
2713
|
+
};
|
|
2714
|
+
var OperationEventSchema = z3.discriminatedUnion("event", [
|
|
2715
|
+
z3.object({
|
|
2716
|
+
...operationShared,
|
|
2717
|
+
event: z3.literal("completed"),
|
|
2718
|
+
result: OperationResultSchema,
|
|
2719
|
+
error_class: z3.string().nullable(),
|
|
2720
|
+
field_names: z3.array(z3.string().max(CUSTOM_FIELD_NAME_MAX_LENGTH)).max(CUSTOM_EVENT_MAX_FIELDS).optional()
|
|
2721
|
+
}).strict()
|
|
2722
|
+
]);
|
|
2723
|
+
var UsageUnitsSchema = z3.object({
|
|
2724
|
+
input: z3.number().nonnegative().nullable(),
|
|
2725
|
+
output: z3.number().nonnegative().nullable(),
|
|
2726
|
+
cache: z3.number().nonnegative().nullable()
|
|
2727
|
+
}).strict();
|
|
2728
|
+
var usageShared = {
|
|
2729
|
+
meta: HeaderMetaSchema,
|
|
2730
|
+
subject: SubjectSchema,
|
|
2731
|
+
kind: z3.literal("usage"),
|
|
2732
|
+
...envelopeTail,
|
|
2733
|
+
model: z3.string().nullable(),
|
|
2734
|
+
source: z3.string(),
|
|
2735
|
+
semantics: z3.enum(["cumulative", "delta"])
|
|
2736
|
+
};
|
|
2737
|
+
var UsageEventSchema = z3.discriminatedUnion("event", [
|
|
2738
|
+
z3.object({
|
|
2739
|
+
...usageShared,
|
|
2740
|
+
event: z3.literal("observed"),
|
|
2741
|
+
units: UsageUnitsSchema,
|
|
2742
|
+
unknown_reason: z3.string().nullable()
|
|
2743
|
+
}).strict()
|
|
2744
|
+
]);
|
|
2745
|
+
var RoleAttemptOutcomeSchema = z3.enum([
|
|
2746
|
+
"completed",
|
|
2747
|
+
"incomplete",
|
|
2748
|
+
"infrastructure_failed",
|
|
2749
|
+
"cancelled",
|
|
2750
|
+
"timed_out",
|
|
2751
|
+
"capability_refused"
|
|
2752
|
+
]);
|
|
2753
|
+
var roleAttemptShared = {
|
|
2754
|
+
meta: HeaderMetaSchema,
|
|
2755
|
+
subject: SubjectSchema,
|
|
2756
|
+
kind: z3.literal("role_attempt"),
|
|
2757
|
+
...envelopeTail,
|
|
2758
|
+
actor: z3.string().nullable(),
|
|
2759
|
+
attempt: z3.number().int().nullable(),
|
|
2760
|
+
effect_id: z3.string(),
|
|
2761
|
+
model: z3.string().nullable()
|
|
2762
|
+
};
|
|
2763
|
+
var RoleAttemptEventSchema = z3.discriminatedUnion("event", [
|
|
2764
|
+
z3.object({
|
|
2765
|
+
...roleAttemptShared,
|
|
2766
|
+
event: z3.literal("attempted"),
|
|
2767
|
+
outcome: RoleAttemptOutcomeSchema,
|
|
2768
|
+
usage: dispatchUsageField
|
|
2769
|
+
}).strict()
|
|
2770
|
+
]);
|
|
2771
|
+
var handoffShared = {
|
|
2772
|
+
meta: HeaderMetaSchema,
|
|
2773
|
+
subject: SubjectSchema,
|
|
2774
|
+
kind: z3.literal("handoff"),
|
|
2775
|
+
...envelopeTail,
|
|
2776
|
+
class: z3.enum(["authority", "strategy", "product"]),
|
|
2777
|
+
reason: z3.string()
|
|
2778
|
+
};
|
|
2779
|
+
var HandoffEventSchema = z3.discriminatedUnion("event", [
|
|
2780
|
+
z3.object({
|
|
2781
|
+
...handoffShared,
|
|
2782
|
+
event: z3.literal("raised"),
|
|
2783
|
+
requested_decision: z3.string().nullable()
|
|
2784
|
+
}).strict(),
|
|
2785
|
+
z3.object({
|
|
2786
|
+
...handoffShared,
|
|
2787
|
+
event: z3.literal("resolved"),
|
|
2788
|
+
resolution: z3.string().nullable(),
|
|
2789
|
+
resolved_by: z3.string().nullable()
|
|
2790
|
+
}).strict()
|
|
2791
|
+
]);
|
|
2792
|
+
var EffectTargetSchema = z3.object({
|
|
2793
|
+
kind: z3.string(),
|
|
2794
|
+
ref: z3.string()
|
|
2795
|
+
}).strict();
|
|
2796
|
+
var effectShared = {
|
|
2797
|
+
meta: HeaderMetaSchema,
|
|
2798
|
+
subject: SubjectSchema,
|
|
2799
|
+
kind: z3.literal("effect"),
|
|
2800
|
+
...envelopeTail,
|
|
2801
|
+
effect_id: z3.string(),
|
|
2802
|
+
target: EffectTargetSchema
|
|
2803
|
+
};
|
|
2804
|
+
var EffectEventSchema = z3.discriminatedUnion("event", [
|
|
2805
|
+
z3.object({ ...effectShared, event: z3.literal("attempted") }).strict(),
|
|
2806
|
+
z3.object({ ...effectShared, event: z3.literal("observed"), outcome: z3.enum(["success", "failure", "uncertain"]) }).strict(),
|
|
2807
|
+
z3.object({ ...effectShared, event: z3.literal("verified"), outcome: z3.enum(["success", "failure", "uncertain"]) }).strict()
|
|
2808
|
+
]);
|
|
2809
|
+
var CustomFieldValueSchema = z3.union([z3.string().max(CUSTOM_TEXT_MAX_LENGTH), z3.number().finite(), z3.boolean()]);
|
|
2810
|
+
var customShared = {
|
|
2811
|
+
meta: HeaderMetaV3Schema,
|
|
2812
|
+
subject: SubjectSchema,
|
|
2813
|
+
kind: z3.literal("custom"),
|
|
2814
|
+
...envelopeTail
|
|
2815
|
+
};
|
|
2816
|
+
var CustomEventSchema = z3.discriminatedUnion("event", [
|
|
2817
|
+
z3.object({
|
|
2818
|
+
...customShared,
|
|
2819
|
+
event: z3.literal("recorded"),
|
|
2820
|
+
name: z3.string().max(CUSTOM_EVENT_NAME_MAX_LENGTH).regex(CUSTOM_EVENT_NAME_PATTERN),
|
|
2821
|
+
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, {
|
|
2822
|
+
message: `custom: at most ${CUSTOM_EVENT_MAX_FIELDS} fields`
|
|
2823
|
+
})
|
|
2824
|
+
}).strict()
|
|
2825
|
+
]);
|
|
2826
|
+
var LogEventSchema = z3.union([
|
|
2827
|
+
DispatchEventSchema,
|
|
2828
|
+
DevReviewLoopEventSchema,
|
|
2829
|
+
ForgeWriteEventSchema,
|
|
2830
|
+
GateEventSchema,
|
|
2831
|
+
OperationEventSchema,
|
|
2832
|
+
UsageEventSchema,
|
|
2833
|
+
RoleAttemptEventSchema,
|
|
2834
|
+
HandoffEventSchema,
|
|
2835
|
+
EffectEventSchema,
|
|
2836
|
+
CustomEventSchema
|
|
2837
|
+
]);
|
|
2838
|
+
// ../../packages/aeg-core/src/control-store/records.ts
|
|
2839
|
+
import { z as z4 } from "zod";
|
|
2840
|
+
var isoTimestamp = z4.string().min(1);
|
|
2841
|
+
var taskId = z4.number().int().positive();
|
|
2842
|
+
var epochNumber = z4.number().int().nonnegative();
|
|
2843
|
+
var RunRecordSchema = z4.object({
|
|
2844
|
+
version: z4.literal(1),
|
|
2845
|
+
kind: z4.literal("run"),
|
|
2846
|
+
task: taskId,
|
|
2847
|
+
runId: z4.string().min(1),
|
|
2848
|
+
pid: z4.number().int().positive(),
|
|
2849
|
+
host: z4.string().min(1),
|
|
2850
|
+
startedAt: isoTimestamp,
|
|
2851
|
+
childStartedAt: z4.string().min(1).nullable().optional(),
|
|
2852
|
+
childCommand: z4.string().min(1).nullable().optional()
|
|
2853
|
+
}).strict();
|
|
2854
|
+
var InputRecordSchema = z4.object({
|
|
2855
|
+
version: z4.literal(1),
|
|
2856
|
+
kind: z4.literal("input"),
|
|
2857
|
+
task: taskId,
|
|
2858
|
+
runId: z4.string().min(1),
|
|
2859
|
+
source: z4.union([z4.literal("fresh"), z4.literal("resume")]),
|
|
2860
|
+
pr: z4.number().int().positive().nullable(),
|
|
2861
|
+
round: z4.number().int().nonnegative(),
|
|
2862
|
+
recordedAt: isoTimestamp
|
|
2863
|
+
}).strict();
|
|
2864
|
+
var OwnershipRecordSchema = z4.object({
|
|
2865
|
+
version: z4.literal(1),
|
|
2866
|
+
kind: z4.literal("ownership"),
|
|
2867
|
+
task: taskId,
|
|
2868
|
+
epoch: epochNumber,
|
|
2869
|
+
ownerId: z4.string().min(1),
|
|
2870
|
+
pid: z4.number().int().positive(),
|
|
2871
|
+
host: z4.string().min(1),
|
|
2872
|
+
acquiredAt: isoTimestamp
|
|
2873
|
+
}).strict();
|
|
2874
|
+
var TransitionRecordSchema = z4.object({
|
|
2875
|
+
version: z4.literal(1),
|
|
2876
|
+
kind: z4.literal("transition"),
|
|
2877
|
+
task: taskId,
|
|
2878
|
+
epoch: epochNumber,
|
|
2879
|
+
seq: z4.number().int().nonnegative(),
|
|
2880
|
+
from: z4.string().min(1),
|
|
2881
|
+
to: z4.string().min(1),
|
|
2882
|
+
detail: z4.string().optional(),
|
|
2883
|
+
at: isoTimestamp
|
|
2884
|
+
}).strict();
|
|
2885
|
+
var ManifestRecordSchema = z4.object({
|
|
2886
|
+
version: z4.literal(1),
|
|
2887
|
+
kind: z4.literal("manifest"),
|
|
2888
|
+
task: taskId,
|
|
2889
|
+
round: epochNumber,
|
|
2890
|
+
repository: z4.string().min(1),
|
|
2891
|
+
pr: z4.number().int().positive(),
|
|
2892
|
+
branch: z4.string().min(1),
|
|
2893
|
+
baseSha: z4.string().min(1).nullable(),
|
|
2894
|
+
headSha: z4.string().min(1),
|
|
2895
|
+
briefHash: z4.string().min(1).nullable(),
|
|
2896
|
+
objectivesVersion: z4.string().min(1).nullable(),
|
|
2897
|
+
rulingOrdinal: epochNumber,
|
|
2898
|
+
policyDigest: z4.string().min(1),
|
|
2899
|
+
recordedAt: isoTimestamp
|
|
2900
|
+
}).strict();
|
|
2901
|
+
var roundHeadIdentity = z4.object({ round: z4.number().int().positive(), head: z4.string().min(1) }).strict();
|
|
2902
|
+
var LoopBudgetsSchema = z4.object({
|
|
2903
|
+
mechanicalRetries: z4.number().int().nonnegative(),
|
|
2904
|
+
reviewRounds: z4.number().int().nonnegative(),
|
|
2905
|
+
infrastructureRetries: z4.number().int().nonnegative()
|
|
2906
|
+
}).strict();
|
|
2907
|
+
var LoopStateRecordSchema = z4.object({
|
|
2908
|
+
version: z4.literal(1),
|
|
2909
|
+
kind: z4.literal("loop_state"),
|
|
2910
|
+
task: taskId,
|
|
2911
|
+
round: z4.number().int().positive(),
|
|
2912
|
+
phase: z4.string().min(1),
|
|
2913
|
+
pauseReason: z4.string().min(1).nullable(),
|
|
2914
|
+
budgets: LoopBudgetsSchema,
|
|
2915
|
+
heldResult: roundHeadIdentity.nullable(),
|
|
2916
|
+
deliveredFindings: roundHeadIdentity.nullable(),
|
|
2917
|
+
repeatMemory: z4.object({
|
|
2918
|
+
blockingFindings: z4.array(z4.string()),
|
|
2919
|
+
lastFailure: z4.object({ signature: z4.string(), message: z4.string() }).nullable()
|
|
2920
|
+
}).strict().optional(),
|
|
2921
|
+
publicationExpectedBase: z4.string().regex(/^[0-9a-f]{40}$/).nullable().optional(),
|
|
2922
|
+
taskStartedAt: isoTimestamp.optional(),
|
|
2923
|
+
phaseMs: z4.record(z4.string(), z4.number().nonnegative()).optional(),
|
|
2924
|
+
recordedAt: isoTimestamp
|
|
2925
|
+
}).strict();
|
|
2926
|
+
var EffectRecordSchema = z4.object({
|
|
2927
|
+
version: z4.literal(1),
|
|
2928
|
+
kind: z4.literal("effect"),
|
|
2929
|
+
task: taskId,
|
|
2930
|
+
key: z4.string().min(1),
|
|
2931
|
+
operation: z4.string().min(1),
|
|
2932
|
+
target: z4.string().min(1),
|
|
2933
|
+
inputVersion: z4.number().int().nonnegative(),
|
|
2934
|
+
payloadDigest: z4.string().min(1),
|
|
2935
|
+
status: z4.union([z4.literal("started"), z4.literal("verified"), z4.literal("uncertain")]),
|
|
2936
|
+
url: z4.string().optional(),
|
|
2937
|
+
recordedAt: isoTimestamp
|
|
2938
|
+
}).strict();
|
|
2939
|
+
var EscalationRecordSchema = z4.object({
|
|
2940
|
+
version: z4.literal(1),
|
|
2941
|
+
kind: z4.literal("escalation"),
|
|
2942
|
+
task: taskId,
|
|
2943
|
+
escalationId: z4.string().min(1),
|
|
2944
|
+
round: epochNumber,
|
|
2945
|
+
head: z4.string().min(1),
|
|
2946
|
+
branch: z4.string().min(1),
|
|
2947
|
+
pr: z4.number().int().positive().nullable(),
|
|
2948
|
+
runId: z4.string().min(1),
|
|
2949
|
+
pid: z4.number().int().positive(),
|
|
2950
|
+
host: z4.string().min(1),
|
|
2951
|
+
agent: z4.string().min(1).optional(),
|
|
2952
|
+
reason: z4.string().min(1),
|
|
2953
|
+
detail: z4.string().optional(),
|
|
2954
|
+
evidence: z4.string().optional(),
|
|
2955
|
+
attemptedRecovery: z4.string().min(1),
|
|
2956
|
+
requestedDecision: z4.string().min(1),
|
|
2957
|
+
recipient: z4.string().min(1),
|
|
2958
|
+
briefHash: z4.string().min(1).nullable(),
|
|
2959
|
+
objectivesVersion: z4.string().min(1).nullable(),
|
|
2960
|
+
rulingOrdinal: epochNumber,
|
|
2961
|
+
policyDigest: z4.string().min(1),
|
|
2962
|
+
recordedAt: isoTimestamp
|
|
2963
|
+
}).strict();
|
|
2964
|
+
var ResolutionRecordSchema = z4.object({
|
|
2965
|
+
version: z4.literal(1),
|
|
2966
|
+
kind: z4.literal("resolution"),
|
|
2967
|
+
task: taskId,
|
|
2968
|
+
escalationId: z4.string().min(1),
|
|
2969
|
+
decision: z4.union([z4.literal("resume"), z4.literal("cancel")]),
|
|
2970
|
+
authenticatedBy: z4.string().min(1),
|
|
2971
|
+
authenticatedFrom: z4.string().min(1),
|
|
2972
|
+
consumedAt: isoTimestamp
|
|
2973
|
+
}).strict();
|
|
2974
|
+
// ../../packages/aeg-core/bin/verify-dispatch.ts
|
|
2975
|
+
var REPO_ROOT = join(import.meta.dirname, "../../..");
|
|
2976
|
+
process.chdir(REPO_ROOT);
|
|
2977
|
+
function sh(cmd, args) {
|
|
2978
|
+
try {
|
|
2979
|
+
return execFileSync2(cmd, args, { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }).trim();
|
|
2980
|
+
} catch {
|
|
2981
|
+
return "";
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
function shJson(cmd, args) {
|
|
2985
|
+
const out = sh(cmd, args);
|
|
2986
|
+
if (!out)
|
|
2987
|
+
return null;
|
|
2988
|
+
try {
|
|
2989
|
+
return JSON.parse(out);
|
|
2990
|
+
} catch {
|
|
2991
|
+
return null;
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
var execFileAsync4 = promisify4(execFile4);
|
|
2995
|
+
async function shJsonAsync(cmd, args) {
|
|
2996
|
+
try {
|
|
2997
|
+
const { stdout } = await execFileAsync4(cmd, args, { encoding: "utf8", maxBuffer: 16 * 1024 * 1024 });
|
|
2998
|
+
return JSON.parse(stdout);
|
|
2999
|
+
} catch {
|
|
3000
|
+
return null;
|
|
3001
|
+
}
|
|
3002
|
+
}
|
|
3003
|
+
var issueCache = new Map;
|
|
3004
|
+
function ghIssueView(num, repo) {
|
|
3005
|
+
if (issueCache.has(num))
|
|
3006
|
+
return issueCache.get(num) ?? null;
|
|
3007
|
+
const result = shJson("gh", [
|
|
3008
|
+
"issue",
|
|
3009
|
+
"view",
|
|
3010
|
+
String(num),
|
|
3011
|
+
"-R",
|
|
3012
|
+
`${repo.owner}/${repo.repo}`,
|
|
3013
|
+
"--json",
|
|
3014
|
+
"number,state,body,labels,milestone"
|
|
3015
|
+
]);
|
|
3016
|
+
issueCache.set(num, result);
|
|
3017
|
+
return result;
|
|
3018
|
+
}
|
|
3019
|
+
async function checkBareEdgeQualification(dependsOnIds, conflictsWithIds, milestone, repo) {
|
|
3020
|
+
if (!milestone)
|
|
3021
|
+
return null;
|
|
3022
|
+
try {
|
|
3023
|
+
const tranches = await tranchesAttachedToMilestone(repo.owner, repo.repo, milestone.number);
|
|
3024
|
+
if (tranches.length < 2)
|
|
3025
|
+
return null;
|
|
3026
|
+
requireTrancheQualifiedEdges([...dependsOnIds, ...conflictsWithIds], tranches);
|
|
3027
|
+
return null;
|
|
3028
|
+
} catch (e) {
|
|
3029
|
+
if (e instanceof AmbiguousBareEdgeError)
|
|
3030
|
+
return e.message;
|
|
3031
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
3032
|
+
return `verify-dispatch severity:infra \u2014 could not determine whether a bare edge id is ambiguous against Milestone #${milestone.number} (${message}).`;
|
|
3033
|
+
}
|
|
3034
|
+
}
|
|
3035
|
+
function fetchTrancheBranchPrs(trancheSlug, repo) {
|
|
3036
|
+
const all = shJson("gh", [
|
|
3037
|
+
"pr",
|
|
3038
|
+
"list",
|
|
3039
|
+
"-R",
|
|
3040
|
+
`${repo.owner}/${repo.repo}`,
|
|
3041
|
+
"--state",
|
|
3042
|
+
"all",
|
|
3043
|
+
"--json",
|
|
3044
|
+
"number,headRefName,state,mergedAt",
|
|
3045
|
+
"--limit",
|
|
3046
|
+
"300"
|
|
3047
|
+
]) ?? [];
|
|
3048
|
+
const prefix = `task/${trancheSlug}/`;
|
|
3049
|
+
const map = new Map;
|
|
3050
|
+
for (const pr of all) {
|
|
3051
|
+
if (!pr.headRefName.startsWith(prefix))
|
|
3052
|
+
continue;
|
|
3053
|
+
const taskId = pr.headRefName.slice(prefix.length);
|
|
3054
|
+
map.set(taskId, pr);
|
|
3055
|
+
}
|
|
3056
|
+
return map;
|
|
3057
|
+
}
|
|
3058
|
+
async function fetchBacklogIssuePrsBatch(numbers, repo) {
|
|
3059
|
+
const unique = [...new Set(numbers)];
|
|
3060
|
+
const result = new Map;
|
|
3061
|
+
if (unique.length === 0)
|
|
3062
|
+
return result;
|
|
3063
|
+
const batch = await readBacklogPrs(unique, repo);
|
|
3064
|
+
if (batch)
|
|
3065
|
+
return batch;
|
|
3066
|
+
const failed = [];
|
|
3067
|
+
if (unique.length > 1) {
|
|
3068
|
+
for (const n of unique) {
|
|
3069
|
+
const one = await readBacklogPrs([n], repo);
|
|
3070
|
+
if (one)
|
|
3071
|
+
for (const [k, v] of one)
|
|
3072
|
+
result.set(k, v);
|
|
3073
|
+
else
|
|
3074
|
+
failed.push(n);
|
|
3075
|
+
}
|
|
3076
|
+
} else
|
|
3077
|
+
failed.push(...unique);
|
|
3078
|
+
throw new BacklogReadError(failed, result);
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3081
|
+
class BacklogReadError extends Error {
|
|
3082
|
+
failed;
|
|
3083
|
+
found;
|
|
3084
|
+
constructor(failed, found) {
|
|
3085
|
+
super(`could not read pull requests for ${failed.map((n) => `#${n}`).join(", ")} from the forge`);
|
|
3086
|
+
this.failed = failed;
|
|
3087
|
+
this.found = found;
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
async function readBacklogPrs(numbers, repo) {
|
|
3091
|
+
const parsed = await shJsonAsync("gh", [
|
|
3092
|
+
"api",
|
|
3093
|
+
"graphql",
|
|
3094
|
+
"-f",
|
|
3095
|
+
`query=${buildBacklogPrQuery(numbers)}`,
|
|
3096
|
+
"-F",
|
|
3097
|
+
`owner=${repo.owner}`,
|
|
3098
|
+
"-F",
|
|
3099
|
+
`repo=${repo.repo}`
|
|
3100
|
+
]);
|
|
3101
|
+
const repository = parsed?.data?.repository;
|
|
3102
|
+
if (!repository)
|
|
3103
|
+
return null;
|
|
3104
|
+
const result = new Map;
|
|
3105
|
+
const pick = (prs) => prs.find((pr) => pr.state === "MERGED") ?? prs[0];
|
|
3106
|
+
for (const n of numbers) {
|
|
3107
|
+
const found = pick(repository[`b_${n}`]?.nodes ?? []) ?? pick(repository[`c_${n}`]?.closedByPullRequestsReferences?.nodes ?? []);
|
|
3108
|
+
if (found)
|
|
3109
|
+
result.set(n, found);
|
|
3110
|
+
}
|
|
3111
|
+
return result;
|
|
3112
|
+
}
|
|
3113
|
+
function buildBacklogPrQuery(numbers) {
|
|
3114
|
+
const fields = "number headRefName state mergedAt";
|
|
3115
|
+
const perIssue = numbers.map((n) => `b_${n}: pullRequests(headRefName: "${issueBranchName(n)}", first: 5, orderBy: {field: CREATED_AT, direction: DESC}) { nodes { ${fields} } }
|
|
3116
|
+
` + `c_${n}: issue(number: ${n}) { closedByPullRequestsReferences(first: 10, includeClosedPrs: true) { nodes { ${fields} } } }`).join(`
|
|
3117
|
+
`);
|
|
3118
|
+
return `query($owner: String!, $repo: String!) { repository(owner: $owner, name: $repo) {
|
|
3119
|
+
${perIssue}
|
|
3120
|
+
} }`;
|
|
3121
|
+
}
|
|
3122
|
+
async function readTrancheFromOrigin(trancheSlug, repo) {
|
|
3123
|
+
try {
|
|
3124
|
+
return await deriveTrancheFromForge(repo.owner, repo.repo, trancheSlug);
|
|
3125
|
+
} catch {
|
|
3126
|
+
return null;
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
function directIssueNumFromEdge(edge) {
|
|
3130
|
+
const m = edge.match(/#(\d+)/);
|
|
3131
|
+
return m ? Number(m[1]) : null;
|
|
3132
|
+
}
|
|
3133
|
+
function resolveSameTrancheTask(edge, tranche) {
|
|
3134
|
+
return tranche.tasks.find((t) => t.id === edge.trim());
|
|
3135
|
+
}
|
|
3136
|
+
var defaultResolveSiblingTranche = async (slug, repo) => {
|
|
3137
|
+
try {
|
|
3138
|
+
const tranche = await deriveTrancheFromForge(repo.owner, repo.repo, slug);
|
|
3139
|
+
return { tranche, branchPrs: fetchTrancheBranchPrs(slug, repo) };
|
|
3140
|
+
} catch {
|
|
3141
|
+
return null;
|
|
3142
|
+
}
|
|
3143
|
+
};
|
|
3144
|
+
function fetchIssueStatesBatch(numbers, repo) {
|
|
3145
|
+
const result = new Map;
|
|
3146
|
+
const unique = [...new Set(numbers)];
|
|
3147
|
+
if (unique.length === 0)
|
|
3148
|
+
return result;
|
|
3149
|
+
const raw = sh("gh", [
|
|
3150
|
+
"api",
|
|
3151
|
+
"graphql",
|
|
3152
|
+
"-f",
|
|
3153
|
+
`query=${buildBatchIssueStateQuery(unique)}`,
|
|
3154
|
+
"-F",
|
|
3155
|
+
`owner=${repo.owner}`,
|
|
3156
|
+
"-F",
|
|
3157
|
+
`repo=${repo.repo}`
|
|
3158
|
+
]);
|
|
3159
|
+
if (!raw)
|
|
3160
|
+
return result;
|
|
3161
|
+
const parsed = shJsonParse(raw);
|
|
3162
|
+
const repository = parsed?.data?.repository;
|
|
3163
|
+
if (!repository)
|
|
3164
|
+
return result;
|
|
3165
|
+
for (const n of unique) {
|
|
3166
|
+
const state = repository[`i_${n}`]?.state;
|
|
3167
|
+
if (state === "OPEN" || state === "CLOSED")
|
|
3168
|
+
result.set(n, state);
|
|
3169
|
+
}
|
|
3170
|
+
return result;
|
|
3171
|
+
}
|
|
3172
|
+
function buildBatchIssueStateQuery(numbers) {
|
|
3173
|
+
const perIssue = numbers.map((n) => `i_${n}: issue(number: ${n}) { state }`).join(`
|
|
3174
|
+
`);
|
|
3175
|
+
return `query($owner: String!, $repo: String!) { repository(owner: $owner, name: $repo) {
|
|
3176
|
+
${perIssue}
|
|
3177
|
+
} }`;
|
|
3178
|
+
}
|
|
3179
|
+
function shJsonParse(text) {
|
|
3180
|
+
try {
|
|
3181
|
+
return JSON.parse(text);
|
|
3182
|
+
} catch {
|
|
3183
|
+
return null;
|
|
3184
|
+
}
|
|
3185
|
+
}
|
|
3186
|
+
async function resolveDependsOn(edges, tranche, branchPrs, repo, resolveSibling = defaultResolveSiblingTranche, fetchIssueStates = fetchIssueStatesBatch, fetchBacklogPrs = fetchBacklogIssuePrsBatch) {
|
|
3187
|
+
const siblingCache = new Map;
|
|
3188
|
+
const siblingByEdge = new Map;
|
|
3189
|
+
const needed = new Set;
|
|
3190
|
+
const neededBacklog = new Set;
|
|
3191
|
+
for (const edge of edges) {
|
|
3192
|
+
const sameTask = resolveSameTrancheTask(edge, tranche);
|
|
3193
|
+
if (sameTask) {
|
|
3194
|
+
if (sameTask.issue !== null && !branchPrs.has(sameTask.id))
|
|
3195
|
+
needed.add(sameTask.issue);
|
|
3196
|
+
continue;
|
|
3197
|
+
}
|
|
3198
|
+
const directIssue = directIssueNumFromEdge(edge);
|
|
3199
|
+
if (directIssue !== null) {
|
|
3200
|
+
needed.add(directIssue);
|
|
3201
|
+
neededBacklog.add(directIssue);
|
|
3202
|
+
continue;
|
|
3203
|
+
}
|
|
3204
|
+
const qualified = splitSlugQualifiedEdge(edge);
|
|
3205
|
+
if (qualified) {
|
|
3206
|
+
let sibling = siblingCache.get(qualified.slug);
|
|
3207
|
+
if (sibling === undefined) {
|
|
3208
|
+
sibling = await resolveSibling(qualified.slug, repo);
|
|
3209
|
+
siblingCache.set(qualified.slug, sibling);
|
|
3210
|
+
}
|
|
3211
|
+
siblingByEdge.set(edge, sibling);
|
|
3212
|
+
const siblingTask = sibling ? resolveSameTrancheTask(qualified.bareId, sibling.tranche) : undefined;
|
|
3213
|
+
if (sibling && siblingTask && siblingTask.issue !== null && !sibling.branchPrs.has(siblingTask.id)) {
|
|
3214
|
+
needed.add(siblingTask.issue);
|
|
3215
|
+
}
|
|
3216
|
+
}
|
|
3217
|
+
}
|
|
3218
|
+
const issueStates = fetchIssueStates([...needed], repo);
|
|
3219
|
+
let backlogPrs = new Map;
|
|
3220
|
+
const backlogFailed = new Set;
|
|
3221
|
+
try {
|
|
3222
|
+
backlogPrs = await fetchBacklogPrs([...neededBacklog], repo);
|
|
3223
|
+
} catch (e) {
|
|
3224
|
+
if (e instanceof BacklogReadError) {
|
|
3225
|
+
backlogPrs = e.found;
|
|
3226
|
+
for (const n of e.failed)
|
|
3227
|
+
backlogFailed.add(n);
|
|
3228
|
+
} else {
|
|
3229
|
+
for (const n of neededBacklog)
|
|
3230
|
+
backlogFailed.add(n);
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
const facts = [];
|
|
3234
|
+
for (const edge of edges) {
|
|
3235
|
+
const sameTask = resolveSameTrancheTask(edge, tranche);
|
|
3236
|
+
if (sameTask) {
|
|
3237
|
+
const pr = branchPrs.get(sameTask.id);
|
|
3238
|
+
if (pr) {
|
|
3239
|
+
facts.push({ id: edge, issue: sameTask.issue, merged: pr.state === "MERGED" });
|
|
3240
|
+
} else if (sameTask.issue !== null) {
|
|
3241
|
+
facts.push({ id: edge, issue: sameTask.issue, merged: issueStates.get(sameTask.issue) === "CLOSED" });
|
|
3242
|
+
} else {
|
|
3243
|
+
facts.push({ id: edge, issue: null, merged: false });
|
|
3244
|
+
}
|
|
3245
|
+
continue;
|
|
3246
|
+
}
|
|
3247
|
+
const directIssue = directIssueNumFromEdge(edge);
|
|
3248
|
+
if (directIssue !== null) {
|
|
3249
|
+
const backlogPr = backlogPrs.get(directIssue);
|
|
3250
|
+
if (backlogFailed.has(directIssue) || !backlogPr && !issueStates.has(directIssue)) {
|
|
3251
|
+
facts.push({ id: edge, issue: directIssue, merged: false, readFailed: true });
|
|
3252
|
+
continue;
|
|
3253
|
+
}
|
|
3254
|
+
const merged = backlogPr ? backlogPr.state === "MERGED" : issueStates.get(directIssue) === "CLOSED";
|
|
3255
|
+
facts.push({ id: edge, issue: directIssue, merged });
|
|
3256
|
+
continue;
|
|
3257
|
+
}
|
|
3258
|
+
const qualified = splitSlugQualifiedEdge(edge);
|
|
3259
|
+
if (qualified) {
|
|
3260
|
+
const sibling = siblingByEdge.get(edge);
|
|
3261
|
+
const siblingTask = sibling ? resolveSameTrancheTask(qualified.bareId, sibling.tranche) : undefined;
|
|
3262
|
+
if (sibling && siblingTask) {
|
|
3263
|
+
const pr = sibling.branchPrs.get(siblingTask.id);
|
|
3264
|
+
if (pr) {
|
|
3265
|
+
facts.push({ id: edge, issue: siblingTask.issue, merged: pr.state === "MERGED" });
|
|
3266
|
+
} else if (siblingTask.issue !== null) {
|
|
3267
|
+
facts.push({ id: edge, issue: siblingTask.issue, merged: issueStates.get(siblingTask.issue) === "CLOSED" });
|
|
3268
|
+
} else {
|
|
3269
|
+
facts.push({ id: edge, issue: null, merged: false });
|
|
3270
|
+
}
|
|
3271
|
+
continue;
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
facts.push({ id: edge, issue: null, merged: false, resolved: false });
|
|
3275
|
+
}
|
|
3276
|
+
return facts;
|
|
3277
|
+
}
|
|
3278
|
+
async function resolveConflictsWith(edges, tranche, branchPrs, repo, resolveSibling = defaultResolveSiblingTranche) {
|
|
3279
|
+
const siblingCache = new Map;
|
|
3280
|
+
const facts = [];
|
|
3281
|
+
for (const edge of edges) {
|
|
3282
|
+
const sameTask = resolveSameTrancheTask(edge, tranche);
|
|
3283
|
+
if (sameTask) {
|
|
3284
|
+
const pr = branchPrs.get(sameTask.id);
|
|
3285
|
+
facts.push({ id: edge, issue: sameTask.issue, openOrInFlight: pr ? pr.state === "OPEN" : false });
|
|
3286
|
+
continue;
|
|
3287
|
+
}
|
|
3288
|
+
const directIssue = directIssueNumFromEdge(edge);
|
|
3289
|
+
if (directIssue !== null) {
|
|
3290
|
+
facts.push({ id: edge, issue: directIssue, openOrInFlight: false });
|
|
3291
|
+
continue;
|
|
3292
|
+
}
|
|
3293
|
+
const qualified = splitSlugQualifiedEdge(edge);
|
|
3294
|
+
if (qualified) {
|
|
3295
|
+
let sibling = siblingCache.get(qualified.slug);
|
|
3296
|
+
if (sibling === undefined) {
|
|
3297
|
+
sibling = await resolveSibling(qualified.slug, repo);
|
|
3298
|
+
siblingCache.set(qualified.slug, sibling);
|
|
3299
|
+
}
|
|
3300
|
+
const siblingTask = sibling ? resolveSameTrancheTask(qualified.bareId, sibling.tranche) : undefined;
|
|
3301
|
+
if (sibling && siblingTask) {
|
|
3302
|
+
const pr = sibling.branchPrs.get(siblingTask.id);
|
|
3303
|
+
facts.push({ id: edge, issue: siblingTask.issue, openOrInFlight: pr ? pr.state === "OPEN" : false });
|
|
3304
|
+
continue;
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
facts.push({ id: edge, issue: null, openOrInFlight: false });
|
|
3308
|
+
}
|
|
3309
|
+
return facts;
|
|
3310
|
+
}
|
|
3311
|
+
function resolvePriorTask(tranche, taskId, branchPrs, provenanceByIssue, repo) {
|
|
3312
|
+
const idx = tranche.tasks.findIndex((t) => t.id === taskId);
|
|
3313
|
+
if (idx <= 0)
|
|
3314
|
+
return null;
|
|
3315
|
+
const prior = tranche.tasks[idx - 1];
|
|
3316
|
+
const pr = branchPrs.get(prior.id);
|
|
3317
|
+
const issueJson = prior.issue !== null ? ghIssueView(prior.issue, repo) : null;
|
|
3318
|
+
return {
|
|
3319
|
+
id: prior.id,
|
|
3320
|
+
issue: prior.issue,
|
|
3321
|
+
issueClosed: issueJson?.state === "CLOSED",
|
|
3322
|
+
prMerged: pr?.state === "MERGED",
|
|
3323
|
+
hasProvenance: prior.issue !== null ? provenanceByIssue.get(prior.issue) ?? false : false
|
|
3324
|
+
};
|
|
3325
|
+
}
|
|
3326
|
+
function otherActiveTrancheSlugs(excludeSlug, repo) {
|
|
3327
|
+
return listActiveTrancheSlugs(repo.owner, repo.repo).map((m) => m.slug).filter((slug) => slug !== excludeSlug);
|
|
3328
|
+
}
|
|
3329
|
+
async function resolvePriorTrancheArchival(projects, excludeSlug, repo) {
|
|
3330
|
+
const candidates = otherActiveTrancheSlugs(excludeSlug, repo);
|
|
3331
|
+
const facts = [];
|
|
3332
|
+
for (const project of projects) {
|
|
3333
|
+
let found = null;
|
|
3334
|
+
for (const slug of candidates) {
|
|
3335
|
+
const candidateTranche = await deriveTrancheFromForge(repo.owner, repo.repo, slug);
|
|
3336
|
+
const touchesProject = candidateTranche.tasks.some((t) => t.projects.includes(project));
|
|
3337
|
+
if (!touchesProject)
|
|
3338
|
+
continue;
|
|
3339
|
+
const openIssues = shJson("gh", [
|
|
3340
|
+
"issue",
|
|
3341
|
+
"list",
|
|
3342
|
+
"-R",
|
|
3343
|
+
`${repo.owner}/${repo.repo}`,
|
|
3344
|
+
"--label",
|
|
3345
|
+
trancheLabel(slug),
|
|
3346
|
+
"--state",
|
|
3347
|
+
"open",
|
|
3348
|
+
"--json",
|
|
3349
|
+
"number",
|
|
3350
|
+
"--limit",
|
|
3351
|
+
"100"
|
|
3352
|
+
]) ?? [];
|
|
3353
|
+
if (openIssues.length === 0) {
|
|
3354
|
+
found = { project, priorTrancheSlug: slug, archived: false };
|
|
3355
|
+
break;
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
facts.push(found ?? { project, priorTrancheSlug: null, archived: false });
|
|
3359
|
+
}
|
|
3360
|
+
return facts;
|
|
3361
|
+
}
|
|
3362
|
+
function computeLeftoverForBranch(branch, worktreeDir) {
|
|
3363
|
+
const branchExistsRemote = sh("git", ["ls-remote", "--heads", "origin", branch]).length > 0;
|
|
3364
|
+
const worktreeExistsLocal = existsSync(worktreeDir);
|
|
3365
|
+
let commitsAheadOfMain = 0;
|
|
3366
|
+
if (branchExistsRemote) {
|
|
3367
|
+
sh("git", ["fetch", "origin", branch, "--quiet"]);
|
|
3368
|
+
const count = sh("git", ["rev-list", "--count", `origin/main..origin/${branch}`]);
|
|
3369
|
+
commitsAheadOfMain = count && !Number.isNaN(Number(count)) ? Number(count) : 0;
|
|
3370
|
+
} else if (worktreeExistsLocal) {
|
|
3371
|
+
const count = sh("git", ["-C", worktreeDir, "rev-list", "--count", "origin/main..HEAD"]);
|
|
3372
|
+
commitsAheadOfMain = count && !Number.isNaN(Number(count)) ? Number(count) : 0;
|
|
3373
|
+
}
|
|
3374
|
+
return classifyLeftover({ branchExistsRemote, worktreeExistsLocal, commitsAheadOfMain });
|
|
3375
|
+
}
|
|
3376
|
+
function computeLeftover(trancheSlug, taskId) {
|
|
3377
|
+
return computeLeftoverForBranch(`task/${trancheSlug}/${taskId}`, join(REPO_ROOT, ".worktrees", "task", trancheSlug, taskId));
|
|
3378
|
+
}
|
|
3379
|
+
function computeLeftoverForIssue(issueNumber) {
|
|
3380
|
+
const branch = `task/issue-${issueNumber}`;
|
|
3381
|
+
return computeLeftoverForBranch(branch, join(REPO_ROOT, ".worktrees", branch));
|
|
3382
|
+
}
|
|
3383
|
+
function captureStreams(cmd, args) {
|
|
3384
|
+
const result = spawnSync(cmd, args, { encoding: "utf8" });
|
|
3385
|
+
if (result.error)
|
|
3386
|
+
return { stdout: "", stderr: "", exitCode: -1, ranAtAll: false };
|
|
3387
|
+
return {
|
|
3388
|
+
stdout: result.stdout ?? "",
|
|
3389
|
+
stderr: result.stderr ?? "",
|
|
3390
|
+
exitCode: result.status ?? 1,
|
|
3391
|
+
ranAtAll: true
|
|
3392
|
+
};
|
|
3393
|
+
}
|
|
3394
|
+
function coherenceFailedCount(stdout) {
|
|
3395
|
+
const parsed = parseJsonSafe(stdout);
|
|
3396
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
3397
|
+
return null;
|
|
3398
|
+
if (parsed.forgeUnavailable === true)
|
|
3399
|
+
return "forge-unavailable";
|
|
3400
|
+
const summary = parsed.summary;
|
|
3401
|
+
if (typeof summary !== "object" || summary === null)
|
|
3402
|
+
return null;
|
|
3403
|
+
const failed = summary.failed;
|
|
3404
|
+
if (typeof failed !== "number" || !Number.isFinite(failed) || failed < 0)
|
|
3405
|
+
return null;
|
|
3406
|
+
return failed;
|
|
3407
|
+
}
|
|
3408
|
+
function parseJsonSafe(text) {
|
|
3409
|
+
try {
|
|
3410
|
+
return JSON.parse(text);
|
|
3411
|
+
} catch {
|
|
3412
|
+
return null;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
function firstStderrLine(stderr) {
|
|
3416
|
+
const line = stderr.split(`
|
|
3417
|
+
`).map((l) => l.trim()).find((l) => l !== "");
|
|
3418
|
+
if (line === undefined)
|
|
3419
|
+
return;
|
|
3420
|
+
const LIMIT = 300;
|
|
3421
|
+
return line.length <= LIMIT ? line : `${line.slice(0, LIMIT)}\u2026 (truncated)`;
|
|
3422
|
+
}
|
|
3423
|
+
function currentFindingCounts() {
|
|
3424
|
+
const docs = captureStreams("bun", ["packages/aeg-core/bin/verify-docs.ts"]);
|
|
3425
|
+
const docsFindingCount = docs.ranAtAll ? countErrorLines(`${docs.stdout}${docs.stderr}`) : 0;
|
|
3426
|
+
const docsUnavailable = !docs.ranAtAll || docs.exitCode !== 0 && docsFindingCount === 0;
|
|
3427
|
+
const coherence = captureStreams("bun", ["packages/aeg-core/bin/verify-coherence.ts", "--json"]);
|
|
3428
|
+
const coherenceRead = coherence.ranAtAll ? coherenceFailedCount(coherence.stdout) : null;
|
|
3429
|
+
const coherenceFailed = typeof coherenceRead === "number" ? coherenceRead : null;
|
|
3430
|
+
const coherenceUnavailable = !coherence.ranAtAll || coherenceFailed === null;
|
|
3431
|
+
const coherenceReason = coherenceRead === "forge-unavailable" ? "ran, but could not reach the forge \u2014 its finding count is incomplete, not clean" : undefined;
|
|
3432
|
+
const coherenceFindingCount = coherenceFailed ?? 0;
|
|
3433
|
+
const docsDiagnostic = firstStderrLine(docs.stderr);
|
|
3434
|
+
const coherenceDiagnostic = firstStderrLine(coherence.stderr);
|
|
3435
|
+
return [
|
|
3436
|
+
{
|
|
3437
|
+
tool: "verify-docs-full",
|
|
3438
|
+
findingCount: docsFindingCount,
|
|
3439
|
+
unavailable: docsUnavailable,
|
|
3440
|
+
...docsUnavailable && docsDiagnostic ? { diagnostic: docsDiagnostic } : {}
|
|
3441
|
+
},
|
|
3442
|
+
{
|
|
3443
|
+
tool: "verify-coherence",
|
|
3444
|
+
findingCount: coherenceFindingCount,
|
|
3445
|
+
...coherenceReason ?? coherenceDiagnostic ? { diagnostic: coherenceReason ?? coherenceDiagnostic } : {},
|
|
3446
|
+
unavailable: coherenceUnavailable
|
|
3447
|
+
}
|
|
3448
|
+
];
|
|
3449
|
+
}
|
|
3450
|
+
function countErrorLines(output) {
|
|
3451
|
+
return output.split(`
|
|
3452
|
+
`).filter((l) => l.trim().startsWith("\u2717")).length;
|
|
3453
|
+
}
|
|
3454
|
+
function resolvePremiseBriefText(comments, issueNumber) {
|
|
3455
|
+
const normalized = comments.map((c) => ({ body: c.body, author: c.author?.login ?? null }));
|
|
3456
|
+
const briefComment = resolveNewestFrozenBrief(normalized, PRINCIPAL_ALLOWLIST);
|
|
3457
|
+
if (!briefComment) {
|
|
3458
|
+
return { ok: false, message: `not dispatched \u2014 no \`aeg:brief:v<k>\` comment on Issue #${issueNumber}.` };
|
|
3459
|
+
}
|
|
3460
|
+
return { ok: true, text: briefComment.content };
|
|
3461
|
+
}
|
|
3462
|
+
async function runPremiseModeFromIssue(trancheSlug, taskId) {
|
|
3463
|
+
const repo = await resolveRepo();
|
|
3464
|
+
if (!repo) {
|
|
3465
|
+
console.error("verify-dispatch --premise: could not resolve a GitHub repo (set AEG_REPO=owner/repo, or confirm `gh auth login`).");
|
|
3466
|
+
process.exit(1);
|
|
3467
|
+
}
|
|
3468
|
+
let tranche;
|
|
3469
|
+
try {
|
|
3470
|
+
tranche = await deriveTrancheFromForge(repo.owner, repo.repo, trancheSlug);
|
|
3471
|
+
} catch (err) {
|
|
3472
|
+
console.error(`verify-dispatch --premise: could not derive tranche \`${trancheSlug}\` from the forge: ${err instanceof Error ? err.message : String(err)}`);
|
|
3473
|
+
process.exit(1);
|
|
3474
|
+
}
|
|
3475
|
+
const task = tranche.tasks.find((t) => t.id === taskId);
|
|
3476
|
+
if (!task || task.issue === null) {
|
|
3477
|
+
console.error(`verify-dispatch --premise: not dispatched \u2014 task "${taskId}" in tranche \`${trancheSlug}\` has no Issue.`);
|
|
3478
|
+
process.exit(1);
|
|
3479
|
+
}
|
|
3480
|
+
const commentsJson = shJson("gh", [
|
|
3481
|
+
"issue",
|
|
3482
|
+
"view",
|
|
3483
|
+
String(task.issue),
|
|
3484
|
+
"-R",
|
|
3485
|
+
`${repo.owner}/${repo.repo}`,
|
|
3486
|
+
"--json",
|
|
3487
|
+
"comments"
|
|
3488
|
+
]);
|
|
3489
|
+
const resolved = resolvePremiseBriefText(commentsJson?.comments ?? [], task.issue);
|
|
3490
|
+
if (!resolved.ok) {
|
|
3491
|
+
console.error(`verify-dispatch --premise: ${resolved.message}`);
|
|
3492
|
+
process.exit(1);
|
|
3493
|
+
}
|
|
3494
|
+
const brief = resolved.text;
|
|
3495
|
+
const assertions = parsePremiseBlock(brief);
|
|
3496
|
+
if (assertions.length === 0) {
|
|
3497
|
+
console.log("verify-dispatch --premise: no `Premise:` assertions found in the dispatched brief \u2014 nothing to re-assert.");
|
|
3498
|
+
process.exit(0);
|
|
3499
|
+
}
|
|
3500
|
+
const result = checkPremises(assertions, (p) => existsSync(p) ? readFileSync2(p, "utf8") : null);
|
|
3501
|
+
if (!result.pass) {
|
|
3502
|
+
console.error(`
|
|
3503
|
+
verify-dispatch --premise FAILED \u2014 ${result.failures.length} premise(s) no longer hold:
|
|
3504
|
+
`);
|
|
3505
|
+
for (const f of result.failures)
|
|
3506
|
+
console.error(` \u2717 ${f}`);
|
|
3507
|
+
process.exit(1);
|
|
3508
|
+
}
|
|
3509
|
+
console.log(`verify-dispatch --premise: all ${assertions.length} premise(s) re-asserted successfully.`);
|
|
3510
|
+
process.exit(0);
|
|
3511
|
+
}
|
|
3512
|
+
function runPremiseMode(bodyFile) {
|
|
3513
|
+
const body = readFileSync2(bodyFile, "utf8");
|
|
3514
|
+
const assertions = parsePremiseBlock(body);
|
|
3515
|
+
if (assertions.length === 0) {
|
|
3516
|
+
console.log("verify-dispatch --premise: no `Premise:` assertions found in the body file \u2014 nothing to re-assert.");
|
|
3517
|
+
process.exit(0);
|
|
3518
|
+
}
|
|
3519
|
+
const result = checkPremises(assertions, (p) => existsSync(p) ? readFileSync2(p, "utf8") : null);
|
|
3520
|
+
if (!result.pass) {
|
|
3521
|
+
console.error(`
|
|
3522
|
+
verify-dispatch --premise FAILED \u2014 ${result.failures.length} premise(s) no longer hold:
|
|
3523
|
+
`);
|
|
3524
|
+
for (const f of result.failures)
|
|
3525
|
+
console.error(` \u2717 ${f}`);
|
|
3526
|
+
process.exit(1);
|
|
3527
|
+
}
|
|
3528
|
+
console.log(`verify-dispatch --premise: all ${assertions.length} premise(s) re-asserted successfully.`);
|
|
3529
|
+
process.exit(0);
|
|
3530
|
+
}
|
|
3531
|
+
function runSimulateMode(trancheSlug, taskId, bodyFile) {
|
|
3532
|
+
const branch = `task/${trancheSlug}/${taskId}`;
|
|
3533
|
+
const body = readFileSync2(bodyFile, "utf8");
|
|
3534
|
+
const assertions = parsePremiseBlock(body);
|
|
3535
|
+
console.log(assertions.length > 0 ? `verify-dispatch --simulate: Premise: block present (${assertions.length} assertion(s)).` : "verify-dispatch --simulate: WARNING \u2014 no `Premise:` block found in the body file (checkPremiseCoverage will fail at PR time if this task has a code surface).");
|
|
3536
|
+
let failed = false;
|
|
3537
|
+
const gates = [
|
|
3538
|
+
[
|
|
3539
|
+
"verify-brief",
|
|
3540
|
+
() => execFileSync2("bun", ["packages/aeg-core/bin/verify-brief.ts"], {
|
|
3541
|
+
env: { ...process.env, BRANCH: branch, PR_BODY: body },
|
|
3542
|
+
stdio: "inherit"
|
|
3543
|
+
})
|
|
3544
|
+
],
|
|
3545
|
+
[
|
|
3546
|
+
"verify-docs --pr",
|
|
3547
|
+
() => execFileSync2("bun", ["packages/aeg-core/bin/verify-docs.ts", "--pr"], {
|
|
3548
|
+
env: { ...process.env, PR_BODY: body },
|
|
3549
|
+
stdio: "inherit"
|
|
3550
|
+
})
|
|
3551
|
+
],
|
|
3552
|
+
[
|
|
3553
|
+
"verify-docs --push (C5, via PR_BODY_FILE)",
|
|
3554
|
+
() => execFileSync2("bun", ["packages/aeg-core/bin/verify-docs.ts", "--push"], {
|
|
3555
|
+
env: { ...process.env, PR_BODY_FILE: bodyFile },
|
|
3556
|
+
stdio: "inherit"
|
|
3557
|
+
})
|
|
3558
|
+
]
|
|
3559
|
+
];
|
|
3560
|
+
for (const [label, run] of gates) {
|
|
3561
|
+
try {
|
|
3562
|
+
run();
|
|
3563
|
+
console.log(`verify-dispatch --simulate: ${label} PASS.`);
|
|
3564
|
+
} catch {
|
|
3565
|
+
console.error(`verify-dispatch --simulate: ${label} FAILED (output above).`);
|
|
3566
|
+
failed = true;
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
process.exit(failed ? 1 : 0);
|
|
3570
|
+
}
|
|
3571
|
+
function runSurfacesMode(surfacesArg) {
|
|
3572
|
+
const surfaces = surfacesArg.split(",").map((s) => s.trim()).filter(Boolean);
|
|
3573
|
+
if (surfaces.length === 0) {
|
|
3574
|
+
console.log("verify-dispatch --surfaces: no surface globs given \u2014 nothing to check.");
|
|
3575
|
+
process.exit(0);
|
|
3576
|
+
}
|
|
3577
|
+
const docOwnersContent = existsSync(DOC_OWNERS_PATH) ? readFileSync2(DOC_OWNERS_PATH, "utf8") : null;
|
|
3578
|
+
const manifestState = classifyDocOwnersManifest(docOwnersContent);
|
|
3579
|
+
if (manifestState === "absent") {
|
|
3580
|
+
console.log(`verify-dispatch --surfaces: no doc-ownership manifest at ${DOC_OWNERS_PATH} \u2014 dormant, no bindings to check.`);
|
|
3581
|
+
process.exit(0);
|
|
3582
|
+
}
|
|
3583
|
+
if (manifestState === "empty") {
|
|
3584
|
+
console.error(`verify-dispatch --surfaces: ${DOC_OWNERS_PATH} is empty \u2014 refusing to report an empty derivation as success.`);
|
|
3585
|
+
process.exit(1);
|
|
3586
|
+
}
|
|
3587
|
+
const { pointers, matches, errors } = deriveSection7(surfaces, docOwnersContent);
|
|
3588
|
+
if (errors.length > 0) {
|
|
3589
|
+
console.error(`verify-dispatch --surfaces: ${DOC_OWNERS_PATH} parse error(s):`);
|
|
3590
|
+
for (const e of errors)
|
|
3591
|
+
console.error(` \u2717 ${e}`);
|
|
3592
|
+
process.exit(1);
|
|
3593
|
+
}
|
|
3594
|
+
if (pointers.length === 0) {
|
|
3595
|
+
console.log("verify-dispatch --surfaces: 0 doc-owners binding(s) match the given surface(s) \u2014 \xA77 has no mechanical floor.");
|
|
3596
|
+
process.exit(0);
|
|
3597
|
+
}
|
|
3598
|
+
console.log(`verify-dispatch --surfaces: ${pointers.length} doc-owners binding(s) will fire for this surface at PR-open (C5) \u2014 plan \xA77 (or a vinaya/waiver:docs/vinaya/override:docs) for these now:
|
|
3599
|
+
`);
|
|
3600
|
+
for (const m of matches) {
|
|
3601
|
+
console.log(` ${m.surface} matches ${DOC_OWNERS_PATH}:${m.lineNum} (glob \`${m.glob}\`) \u2192 ${m.pointer}`);
|
|
3602
|
+
}
|
|
3603
|
+
process.exit(0);
|
|
3604
|
+
}
|
|
3605
|
+
function runCheckBaselineMode(baselineFile) {
|
|
3606
|
+
const baseline = JSON.parse(readFileSync2(baselineFile, "utf8"));
|
|
3607
|
+
const current = currentFindingCounts();
|
|
3608
|
+
const unavailable = current.filter((c) => c.unavailable);
|
|
3609
|
+
if (unavailable.length > 0) {
|
|
3610
|
+
console.error(`
|
|
3611
|
+
verify-dispatch --check-baseline FAILED \u2014 tool(s) produced no honest count to compare:`);
|
|
3612
|
+
for (const u of unavailable) {
|
|
3613
|
+
console.error(` \u2717 ${u.tool}: UNAVAILABLE (no usable finding count)`);
|
|
3614
|
+
if (u.diagnostic)
|
|
3615
|
+
console.error(` \u21B3 ${u.diagnostic}`);
|
|
3616
|
+
}
|
|
3617
|
+
console.error(`
|
|
3618
|
+
An unavailable tool is never compared as if it scored 0. Fix the tool, then re-run --check-baseline.`);
|
|
3619
|
+
process.exit(1);
|
|
3620
|
+
}
|
|
3621
|
+
const comparison = compareToBaseline(current.map(({ tool, findingCount }) => ({ tool, findingCount })), baseline);
|
|
3622
|
+
console.log(JSON.stringify(comparison, null, 2));
|
|
3623
|
+
if (!comparison.withinBudget) {
|
|
3624
|
+
console.error(`
|
|
3625
|
+
verify-dispatch --check-baseline FAILED \u2014 one or more tools regressed past their baseline.`);
|
|
3626
|
+
process.exit(1);
|
|
3627
|
+
}
|
|
3628
|
+
console.log(`
|
|
3629
|
+
verify-dispatch --check-baseline: within budget.`);
|
|
3630
|
+
process.exit(0);
|
|
3631
|
+
}
|
|
3632
|
+
async function runGateMode(trancheSlug, taskId) {
|
|
3633
|
+
sh("git", ["fetch", "origin", "main", "--quiet"]);
|
|
3634
|
+
const repo = await resolveRepo();
|
|
3635
|
+
const token = await resolveGithubToken();
|
|
3636
|
+
if (!repo || !token) {
|
|
3637
|
+
console.error("verify-dispatch severity:infra \u2014 could not resolve a GitHub repo/token (set AEG_REPO / GITHUB_TOKEN, or `gh auth login`). Cannot evaluate forge-dependent predicates.");
|
|
3638
|
+
process.exit(1);
|
|
3639
|
+
}
|
|
3640
|
+
const tranche = await readTrancheFromOrigin(trancheSlug, repo);
|
|
3641
|
+
if (!tranche) {
|
|
3642
|
+
console.error(`verify-dispatch row-existence: could not derive tranche \`${trancheSlug}\` from the forge (no reachable Milestone/Issues, or the forge call failed).`);
|
|
3643
|
+
process.exit(1);
|
|
3644
|
+
}
|
|
3645
|
+
const task = tranche.tasks.find((t) => t.id === taskId);
|
|
3646
|
+
if (!task) {
|
|
3647
|
+
console.error(`verify-dispatch row-existence: task "${taskId}" is not present in tranche \`${trancheSlug}\`'s forge-derived task list (no \`${trancheLabel(trancheSlug)}\`-labeled Issue with this task id yet) \u2014 the plan/Issue for this task hasn't merged/opened. Not dispatchable until it does.`);
|
|
3648
|
+
process.exit(1);
|
|
3649
|
+
}
|
|
3650
|
+
const issueJson = task.issue !== null ? ghIssueView(task.issue, repo) : null;
|
|
3651
|
+
const issueRationalePass = issueJson ? checkIssueRationale(issueJson.body).status === "pass" : true;
|
|
3652
|
+
const branchPrs = fetchTrancheBranchPrs(trancheSlug, repo);
|
|
3653
|
+
const dependsOn = await resolveDependsOn(task.dependsOn, tranche, branchPrs, repo);
|
|
3654
|
+
const conflictsWith = await resolveConflictsWith(task.conflictsWith, tranche, branchPrs, repo);
|
|
3655
|
+
const priorTaskRaw = resolvePriorTaskRaw(tranche, taskId);
|
|
3656
|
+
let provenanceByIssue = new Map;
|
|
3657
|
+
if (priorTaskRaw?.issue !== null && priorTaskRaw !== null) {
|
|
3658
|
+
provenanceByIssue = await fetchProvenance([priorTaskRaw.issue], repo.owner, repo.repo, token);
|
|
3659
|
+
}
|
|
3660
|
+
const priorTask = resolvePriorTask(tranche, taskId, branchPrs, provenanceByIssue, repo);
|
|
3661
|
+
const priorTrancheArchival = await resolvePriorTrancheArchival(task.projects, trancheSlug, repo);
|
|
3662
|
+
const gateResult = checkDispatchReadiness({
|
|
3663
|
+
trancheSlug,
|
|
3664
|
+
task,
|
|
3665
|
+
issue: task.issue !== null && issueJson ? { number: task.issue, state: issueJson.state === "OPEN" ? "open" : "closed" } : null,
|
|
3666
|
+
issueRationalePass,
|
|
3667
|
+
dependsOn,
|
|
3668
|
+
conflictsWith,
|
|
3669
|
+
priorTask,
|
|
3670
|
+
priorTrancheArchival
|
|
3671
|
+
});
|
|
3672
|
+
const ambiguousEdge = await checkBareEdgeQualification(task.dependsOn, task.conflictsWith, issueJson?.milestone ?? null, repo);
|
|
3673
|
+
const leftover = computeLeftover(trancheSlug, taskId);
|
|
3674
|
+
const rawCounts = currentFindingCounts();
|
|
3675
|
+
const nowIso = sh("git", ["log", "-1", "--format=%cI"]) || new Date(0).toISOString();
|
|
3676
|
+
const capturedBaseline = captureBaseline(rawCounts.map(({ tool, findingCount }) => ({ tool, findingCount })), nowIso);
|
|
3677
|
+
console.log(`
|
|
3678
|
+
verify-dispatch: ${trancheSlug} task ${taskId}
|
|
3679
|
+
`);
|
|
3680
|
+
console.log(`dispatch-readiness: ${gateResult.ready ? "READY" : "NOT READY"}`);
|
|
3681
|
+
for (const b of gateResult.blockers)
|
|
3682
|
+
console.log(` \u2717 ${b}`);
|
|
3683
|
+
if (ambiguousEdge)
|
|
3684
|
+
console.log(` \u2717 ${ambiguousEdge}`);
|
|
3685
|
+
console.log(`
|
|
3686
|
+
leftover-detection: ${leftover.verdict}${EXISTING_WORK && leftover.verdict === "stop" ? " (expected: --existing-work, the caller resumes this work)" : ""}`);
|
|
3687
|
+
console.log(` ${leftover.reason}`);
|
|
3688
|
+
console.log(`
|
|
3689
|
+
baseline (informational \u2014 captured this run, not a committed file):`);
|
|
3690
|
+
for (const raw of rawCounts) {
|
|
3691
|
+
const captured = capturedBaseline.find((b) => b.tool === raw.tool);
|
|
3692
|
+
const capturedAt = captured?.capturedAt ?? nowIso;
|
|
3693
|
+
console.log(raw.unavailable ? ` ${raw.tool}: UNAVAILABLE (no usable finding count) at ${capturedAt}` : ` ${raw.tool}: ${raw.findingCount} finding(s) at ${capturedAt}`);
|
|
3694
|
+
if (raw.diagnostic)
|
|
3695
|
+
console.log(` \u21B3 ${raw.diagnostic}`);
|
|
3696
|
+
}
|
|
3697
|
+
const overallReady = gateResult.ready && !leftoverBlocksDispatch(leftover.verdict, { existingWork: EXISTING_WORK }) && !ambiguousEdge;
|
|
3698
|
+
console.log(`
|
|
3699
|
+
verify-dispatch: ${overallReady ? "READY TO DISPATCH" : "NOT READY"}`);
|
|
3700
|
+
process.exit(overallReady ? 0 : 1);
|
|
3701
|
+
}
|
|
3702
|
+
async function runGateModeForIssue(issueNumber) {
|
|
3703
|
+
sh("git", ["fetch", "origin", "main", "--quiet"]);
|
|
3704
|
+
const repo = await resolveRepo();
|
|
3705
|
+
const token = await resolveGithubToken();
|
|
3706
|
+
if (!repo || !token) {
|
|
3707
|
+
console.error("verify-dispatch severity:infra \u2014 could not resolve a GitHub repo/token (set AEG_REPO / GITHUB_TOKEN, or `gh auth login`). Cannot evaluate forge-dependent predicates.");
|
|
3708
|
+
process.exit(1);
|
|
3709
|
+
}
|
|
3710
|
+
const issueJson = ghIssueView(issueNumber, repo);
|
|
3711
|
+
if (!issueJson) {
|
|
3712
|
+
console.error(`verify-dispatch issue-existence: Issue #${issueNumber} does not resolve on the forge.`);
|
|
3713
|
+
process.exit(1);
|
|
3714
|
+
}
|
|
3715
|
+
if (issueJson.labels.some((l) => l.name.startsWith("vinaya/tranche:"))) {
|
|
3716
|
+
console.error(`verify-dispatch: Issue #${issueNumber} carries a vinaya/tranche:* label \u2014 it belongs to a tranche; use \`verify-dispatch <tranche> <n>\` instead of --issue.`);
|
|
3717
|
+
process.exit(1);
|
|
3718
|
+
}
|
|
3719
|
+
const issueRationalePass = checkIssueRationale(issueJson.body).status === "pass";
|
|
3720
|
+
const { dependsOn: dependsOnIds, conflictsWith: conflictsWithIds } = parseRationaleDeps(issueJson.body);
|
|
3721
|
+
const emptyTranche = { name: "", lifecycle: "active", goal: "", tasks: [], backlog: [] };
|
|
3722
|
+
const noBranchPrs = new Map;
|
|
3723
|
+
const dependsOn = await resolveDependsOn(dependsOnIds, emptyTranche, noBranchPrs, repo);
|
|
3724
|
+
const conflictsWith = await resolveConflictsWith(conflictsWithIds, emptyTranche, noBranchPrs, repo);
|
|
3725
|
+
const task = {
|
|
3726
|
+
id: String(issueNumber),
|
|
3727
|
+
title: "",
|
|
3728
|
+
issue: issueNumber,
|
|
3729
|
+
projects: [],
|
|
3730
|
+
dependsOn: dependsOnIds,
|
|
3731
|
+
conflictsWith: conflictsWithIds,
|
|
3732
|
+
rationaleMarkdown: ""
|
|
3733
|
+
};
|
|
3734
|
+
const gateResult = checkDispatchReadiness({
|
|
3735
|
+
trancheSlug: `issue-${issueNumber}`,
|
|
3736
|
+
task,
|
|
3737
|
+
issue: { number: issueNumber, state: issueJson.state === "OPEN" ? "open" : "closed" },
|
|
3738
|
+
issueRationalePass,
|
|
3739
|
+
dependsOn,
|
|
3740
|
+
conflictsWith,
|
|
3741
|
+
priorTask: null,
|
|
3742
|
+
priorTrancheArchival: []
|
|
3743
|
+
});
|
|
3744
|
+
const ambiguousEdge = await checkBareEdgeQualification(dependsOnIds, conflictsWithIds, issueJson.milestone, repo);
|
|
3745
|
+
const leftover = computeLeftoverForIssue(issueNumber);
|
|
3746
|
+
const rawCounts = currentFindingCounts();
|
|
3747
|
+
const nowIso = sh("git", ["log", "-1", "--format=%cI"]) || new Date(0).toISOString();
|
|
3748
|
+
const capturedBaseline = captureBaseline(rawCounts.map(({ tool, findingCount }) => ({ tool, findingCount })), nowIso);
|
|
3749
|
+
console.log(`
|
|
3750
|
+
verify-dispatch: Issue #${issueNumber} (backlog, no tranche)
|
|
3751
|
+
`);
|
|
3752
|
+
console.log(`dispatch-readiness: ${gateResult.ready ? "READY" : "NOT READY"}`);
|
|
3753
|
+
for (const b of gateResult.blockers)
|
|
3754
|
+
console.log(` \u2717 ${b}`);
|
|
3755
|
+
if (ambiguousEdge)
|
|
3756
|
+
console.log(` \u2717 ${ambiguousEdge}`);
|
|
3757
|
+
console.log(`
|
|
3758
|
+
leftover-detection: ${leftover.verdict}${EXISTING_WORK && leftover.verdict === "stop" ? " (expected: --existing-work, the caller resumes this work)" : ""}`);
|
|
3759
|
+
console.log(` ${leftover.reason}`);
|
|
3760
|
+
console.log(`
|
|
3761
|
+
baseline (informational \u2014 captured this run, not a committed file):`);
|
|
3762
|
+
for (const raw of rawCounts) {
|
|
3763
|
+
const captured = capturedBaseline.find((b) => b.tool === raw.tool);
|
|
3764
|
+
const capturedAt = captured?.capturedAt ?? nowIso;
|
|
3765
|
+
console.log(raw.unavailable ? ` ${raw.tool}: UNAVAILABLE (no usable finding count) at ${capturedAt}` : ` ${raw.tool}: ${raw.findingCount} finding(s) at ${capturedAt}`);
|
|
3766
|
+
if (raw.diagnostic)
|
|
3767
|
+
console.log(` \u21B3 ${raw.diagnostic}`);
|
|
3768
|
+
}
|
|
3769
|
+
const overallReady = gateResult.ready && !leftoverBlocksDispatch(leftover.verdict, { existingWork: EXISTING_WORK }) && !ambiguousEdge;
|
|
3770
|
+
console.log(`
|
|
3771
|
+
verify-dispatch: ${overallReady ? "READY TO DISPATCH" : "NOT READY"}`);
|
|
3772
|
+
process.exit(overallReady ? 0 : 1);
|
|
3773
|
+
}
|
|
3774
|
+
function resolvePriorTaskRaw(tranche, taskId) {
|
|
3775
|
+
const idx = tranche.tasks.findIndex((t) => t.id === taskId);
|
|
3776
|
+
if (idx <= 0)
|
|
3777
|
+
return null;
|
|
3778
|
+
return tranche.tasks[idx - 1] ?? null;
|
|
3779
|
+
}
|
|
3780
|
+
var EXISTING_WORK = process.argv.includes("--existing-work");
|
|
3781
|
+
if (__require.main == __require.module) {
|
|
3782
|
+
const argv = process.argv.slice(2);
|
|
3783
|
+
const issueIdx = argv.indexOf("--issue");
|
|
3784
|
+
if (issueIdx !== -1) {
|
|
3785
|
+
const issueArg = argv[issueIdx + 1];
|
|
3786
|
+
const issueNumber = issueArg !== undefined ? Number.parseInt(issueArg, 10) : Number.NaN;
|
|
3787
|
+
if (!issueArg || !Number.isInteger(issueNumber) || String(issueNumber) !== issueArg) {
|
|
3788
|
+
console.error("Usage: verify-dispatch --issue <n> [--existing-work]");
|
|
3789
|
+
process.exit(1);
|
|
3790
|
+
}
|
|
3791
|
+
await runGateModeForIssue(issueNumber);
|
|
3792
|
+
} else {
|
|
3793
|
+
const trancheSlug = argv[0];
|
|
3794
|
+
const taskId = argv[1];
|
|
3795
|
+
if (!trancheSlug || !taskId || trancheSlug.startsWith("--")) {
|
|
3796
|
+
console.error(`Usage: verify-dispatch <tranche> <n> [--existing-work] [--premise [file]] [--simulate <file>] [--check-baseline <file>] [--surfaces <glob1,glob2,...>]
|
|
3797
|
+
` + " or: verify-dispatch --issue <n> [--existing-work]");
|
|
3798
|
+
process.exit(1);
|
|
3799
|
+
}
|
|
3800
|
+
await runGateModeOrCompanion(trancheSlug, taskId, argv);
|
|
3801
|
+
}
|
|
3802
|
+
}
|
|
3803
|
+
async function runGateModeOrCompanion(trancheSlug, taskId, argv) {
|
|
3804
|
+
const premiseIdx = argv.indexOf("--premise");
|
|
3805
|
+
const simulateIdx = argv.indexOf("--simulate");
|
|
3806
|
+
const checkBaselineIdx = argv.indexOf("--check-baseline");
|
|
3807
|
+
const surfacesIdx = argv.indexOf("--surfaces");
|
|
3808
|
+
if (surfacesIdx !== -1) {
|
|
3809
|
+
const globs = argv[surfacesIdx + 1];
|
|
3810
|
+
if (!globs) {
|
|
3811
|
+
console.error("--surfaces requires a comma-separated list of globs.");
|
|
3812
|
+
process.exit(1);
|
|
3813
|
+
}
|
|
3814
|
+
runSurfacesMode(globs);
|
|
3815
|
+
} else if (premiseIdx !== -1) {
|
|
3816
|
+
const file = argv[premiseIdx + 1];
|
|
3817
|
+
if (!file || file.startsWith("--")) {
|
|
3818
|
+
await runPremiseModeFromIssue(trancheSlug, taskId);
|
|
3819
|
+
} else {
|
|
3820
|
+
runPremiseMode(file);
|
|
3821
|
+
}
|
|
3822
|
+
} else if (simulateIdx !== -1) {
|
|
3823
|
+
const file = argv[simulateIdx + 1];
|
|
3824
|
+
if (!file) {
|
|
3825
|
+
console.error("--simulate requires a body-file path.");
|
|
3826
|
+
process.exit(1);
|
|
3827
|
+
}
|
|
3828
|
+
runSimulateMode(trancheSlug, taskId, file);
|
|
3829
|
+
} else if (checkBaselineIdx !== -1) {
|
|
3830
|
+
const file = argv[checkBaselineIdx + 1];
|
|
3831
|
+
if (!file) {
|
|
3832
|
+
console.error("--check-baseline requires a baseline-file path.");
|
|
3833
|
+
process.exit(1);
|
|
3834
|
+
}
|
|
3835
|
+
runCheckBaselineMode(file);
|
|
3836
|
+
} else {
|
|
3837
|
+
await runGateMode(trancheSlug, taskId);
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
export {
|
|
3841
|
+
BacklogReadError,
|
|
3842
|
+
checkBareEdgeQualification,
|
|
3843
|
+
currentFindingCounts,
|
|
3844
|
+
fetchBacklogIssuePrsBatch,
|
|
3845
|
+
fetchIssueStatesBatch,
|
|
3846
|
+
resolveConflictsWith,
|
|
3847
|
+
resolveDependsOn,
|
|
3848
|
+
resolvePremiseBriefText
|
|
3849
|
+
};
|