@attalabs/vinaya 0.44.1 → 0.47.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.
Files changed (143) hide show
  1. package/README.md +6 -4
  2. package/dist/checks/bin/check-body-bare-digits.js +233 -195
  3. package/dist/checks/bin/check-branch-topology.js +70 -23
  4. package/dist/checks/bin/check-brief-shape.js +233 -195
  5. package/dist/checks/bin/check-changeset-coverage.js +94 -16
  6. package/dist/checks/bin/check-ci-shard-coverage.js +3 -0
  7. package/dist/checks/bin/check-closes-n.js +128 -34
  8. package/dist/checks/bin/check-coherence.js +336 -245
  9. package/dist/checks/bin/check-dispatch-readiness.js +3623 -463
  10. package/dist/checks/bin/check-doc-claims.js +233 -195
  11. package/dist/checks/bin/check-doc-coverage-push.js +243 -196
  12. package/dist/checks/bin/check-doc-coverage.js +243 -196
  13. package/dist/checks/bin/check-doctrine-no-procedures.js +233 -195
  14. package/dist/checks/bin/check-doctrine-portability.js +233 -195
  15. package/dist/checks/bin/check-evidence-fresh.js +9983 -1995
  16. package/dist/checks/bin/check-exec-bits.js +3 -0
  17. package/dist/checks/bin/check-first-push-dispatch.js +301 -224
  18. package/dist/checks/bin/check-issue-milestone-attach.js +65 -10
  19. package/dist/checks/bin/check-issue-objectives-numbering.js +233 -195
  20. package/dist/checks/bin/check-issue-parts-coverage.js +65 -10
  21. package/dist/checks/bin/check-issue-surface-globs.js +1032 -236
  22. package/dist/checks/bin/check-issue-title-grammar.js +5 -1
  23. package/dist/checks/bin/check-no-disk-state.js +5 -1
  24. package/dist/checks/bin/check-pr-premise-reassert.js +10 -1
  25. package/dist/checks/bin/check-pr-report-density.js +5 -1
  26. package/dist/checks/bin/check-principal-test-plan-wait.js +253 -201
  27. package/dist/checks/bin/check-quoted-command.js +233 -195
  28. package/dist/checks/bin/check-reader-resolvable-prose.js +233 -195
  29. package/dist/checks/bin/check-registry-gates.js +131 -34
  30. package/dist/checks/bin/check-retired-vocabulary.js +233 -195
  31. package/dist/checks/bin/check-review-gate.js +233 -195
  32. package/dist/checks/bin/check-single-plan-pr.js +5 -1
  33. package/dist/checks/bin/check-surface-scope.js +107 -32
  34. package/dist/checks/bin/check-test-plan.js +253 -201
  35. package/dist/checks/bin/check-token-collection-wired.js +3 -0
  36. package/dist/checks/bin/check-workspace-escape.js +3 -0
  37. package/dist/checks/bin/verify-coherence.js +237 -148
  38. package/dist/checks/bin/verify-dispatch.js +870 -66
  39. package/dist/checks/bin/verify-docs.js +13 -6
  40. package/dist/harness.js +57 -10
  41. package/dist/index.js +16617 -7187
  42. package/dist/lib/pre-push-cache-test-run.js +4487 -2170
  43. package/dist/lib/pre-push-changed-files.js +251 -12
  44. package/dist/lib/pre-push-mode.js +69 -19
  45. package/dist/lib/pre-push-progress-dir.js +10265 -2853
  46. package/dist/lib/pre-push-record-tests.js +67 -19
  47. package/dist/lib/pre-push-select-tests.js +520 -222
  48. package/dist/lib/push-progress-observer.js +9176 -1757
  49. package/dist/process.js +2 -0
  50. package/dist/programs/archive.js +8948 -1547
  51. package/dist/programs/audit.js +9176 -1772
  52. package/dist/programs/check.js +9248 -1845
  53. package/dist/programs/commit-msg.js +8984 -1583
  54. package/dist/programs/dev-review-loop.js +15612 -7634
  55. package/dist/programs/dispatch.js +9977 -2726
  56. package/dist/programs/log-emit.js +9011 -1660
  57. package/dist/programs/log-selftest.js +8908 -1507
  58. package/dist/programs/log-send.js +9081 -1594
  59. package/dist/programs/pr-report.js +9476 -1820
  60. package/dist/programs/pr-snapshot.js +8916 -1515
  61. package/dist/programs/pr-verify-evidence.js +9481 -1825
  62. package/dist/programs/pr.js +11709 -4033
  63. package/dist/programs/review-post.js +11140 -3496
  64. package/dist/programs/review-status.js +8996 -1533
  65. package/dist/programs/run-engine.js +22031 -18759
  66. package/dist/programs/sync.js +9030 -1629
  67. package/dist/programs/task-brief.js +10185 -1821
  68. package/dist/programs/task-sweep.js +9266 -1621
  69. package/dist/programs/task-tools-serve.js +77118 -16678
  70. package/dist/programs/tokens.js +8966 -1565
  71. package/dist/programs/waiver.js +8983 -1582
  72. package/dist/types/harness/kernel/dev-process-socket/loader/load-process.d.ts +1 -1
  73. package/dist/types/harness/processes/vinaya-strict/tools/legacy-markers.d.ts +8 -0
  74. package/dist/types/harness/processes/vinaya-strict/tools/task-contract/brief-validation.d.ts +3 -3
  75. package/dist/types/harness/processes/vinaya-strict/tools/task-contract/objectives.d.ts +5 -6
  76. package/dist/vinaya-strict/checks/registry.ts +2 -2
  77. package/dist/vinaya-strict/executing/developer/developer-doctrine-shape.test.ts +8 -0
  78. package/dist/vinaya-strict/executing/developer/developer-turn-result.ts +1 -1
  79. package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.test.ts +2 -2
  80. package/dist/vinaya-strict/executing/developer/evals/developer-capability-suite.ts +30 -20
  81. package/dist/vinaya-strict/executing/developer/reference.md +5 -3
  82. package/dist/vinaya-strict/integration/config/vinaya-config-section.ts +29 -7
  83. package/dist/vinaya-strict/integration/policies/vinaya-policies.ts +4 -4
  84. package/dist/vinaya-strict/integration/process/process-integration.ts +5 -1
  85. package/dist/vinaya-strict/process.yaml +6 -1
  86. package/dist/vinaya-strict/thinking/plan-reviewer/doctrine.md +68 -0
  87. package/dist/vinaya-strict/thinking/plan-reviewer/grants.yaml +19 -0
  88. package/dist/vinaya-strict/thinking/plan-reviewer/output.schema.json +388 -0
  89. package/dist/vinaya-strict/thinking/planner/doctrine.md +4 -1
  90. package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.test.ts +10 -2
  91. package/dist/vinaya-strict/thinking/planner/tools/amend-rationale-deps.ts +5 -1
  92. package/dist/vinaya-strict/thinking/planner/tools/open-issue.test.ts +198 -34
  93. package/dist/vinaya-strict/thinking/planner/tools/open-issue.ts +120 -193
  94. package/dist/vinaya-strict/thinking/planner/tools/planner-operations.test.ts +629 -15
  95. package/dist/vinaya-strict/thinking/planner/tools/planner-operations.ts +726 -62
  96. package/dist/vinaya-strict/thinking/planner/tools/planner-tools.test.ts +505 -5
  97. package/dist/vinaya-strict/thinking/planner/tools/planner-tools.ts +636 -21
  98. package/package.json +3 -2
  99. package/studio-standalone/apps/vinaya-studio/.next/BUILD_ID +1 -1
  100. package/studio-standalone/apps/vinaya-studio/.next/build-manifest.json +2 -2
  101. package/studio-standalone/apps/vinaya-studio/.next/prerender-manifest.json +3 -3
  102. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  103. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.html +1 -1
  104. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.rsc +1 -1
  105. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  106. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  107. package/studio-standalone/apps/vinaya-studio/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  108. package/studio-standalone/apps/vinaya-studio/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  109. package/studio-standalone/apps/vinaya-studio/.next/server/app/milestones/page_client-reference-manifest.js +1 -1
  110. package/studio-standalone/apps/vinaya-studio/.next/server/app/page_client-reference-manifest.js +1 -1
  111. package/studio-standalone/apps/vinaya-studio/.next/server/app/tasks/page_client-reference-manifest.js +1 -1
  112. package/studio-standalone/apps/vinaya-studio/.next/server/chunks/209.js +2 -2
  113. package/studio-standalone/apps/vinaya-studio/.next/server/chunks/951.js +1 -1
  114. package/studio-standalone/apps/vinaya-studio/.next/server/middleware-build-manifest.js +1 -1
  115. package/studio-standalone/apps/vinaya-studio/.next/server/pages/500.html +1 -1
  116. package/studio-standalone/apps/vinaya-studio/.next/server/preview-props.json +3 -3
  117. package/studio-standalone/apps/vinaya-studio/.next/server/server-reference-manifest.json +1 -1
  118. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/151-c365f0ef8268ad13.js +1 -0
  119. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/19-aa314f13784dcc58.js +4 -0
  120. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/{layout-dfa2186095e797bd.js → layout-f038e8deecb2bf5f.js} +1 -1
  121. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/milestones/{page-2fffb49104860a15.js → page-12314f4deb06a414.js} +1 -1
  122. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/{page-6ae258f663623b2a.js → page-7a06aa3cdd046fa8.js} +1 -1
  123. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/app/tasks/{page-2fffb49104860a15.js → page-12314f4deb06a414.js} +1 -1
  124. package/studio-standalone/apps/vinaya-studio/.next/static/css/8eb5ed5b65b9692e.css +1 -0
  125. package/studio-standalone/apps/vinaya-studio/log-follow.mjs +708 -93
  126. package/studio-standalone/apps/vinaya-studio/log-sync-folder-source.mjs +699 -84
  127. package/studio-standalone/apps/vinaya-studio/studio-server.mjs +4692 -3116
  128. package/vinaya-strict/artifacts/templates/brief-template.md +4 -0
  129. package/vinaya-strict/artifacts/templates/issue-rationale-template.md +7 -3
  130. package/vinaya-strict/artifacts/templates/pr-report-template.md +1 -1
  131. package/vinaya-strict/doctrine/contracts/planner-developer.md +2 -1
  132. package/vinaya-strict/doctrine/enforcement.md +4 -4
  133. package/vinaya-strict/doctrine/roles/principal.md +1 -1
  134. package/vinaya-strict/doctrine/state-machine.md +7 -2
  135. package/vinaya-strict/executing/developer/reference.md +5 -3
  136. package/vinaya-strict/thinking/plan-reviewer/doctrine.md +68 -0
  137. package/vinaya-strict/thinking/planner/doctrine.md +4 -1
  138. package/vinaya-strict/thinking/planner/reference.md +29 -8
  139. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/151-23bea4cac9687151.js +0 -1
  140. package/studio-standalone/apps/vinaya-studio/.next/static/chunks/853-1d5548ff3a55a75f.js +0 -4
  141. package/studio-standalone/apps/vinaya-studio/.next/static/css/fb16828fc3128d4c.css +0 -1
  142. /package/studio-standalone/apps/vinaya-studio/.next/static/{3URbt6IPajL5OOhijN1-x → bJrgAp9Kl4JsCUYkeAYez}/_buildManifest.js +0 -0
  143. /package/studio-standalone/apps/vinaya-studio/.next/static/{3URbt6IPajL5OOhijN1-x → bJrgAp9Kl4JsCUYkeAYez}/_ssgManifest.js +0 -0
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -23,6 +24,7 @@ var __toCommonJS = (from) => {
23
24
  return entry;
24
25
  };
25
26
  var __moduleCache;
27
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
26
28
  var __returnValue = (v) => v;
27
29
  function __exportSetter(name, newValue) {
28
30
  this[name] = __returnValue.bind(null, newValue);
@@ -47,6 +49,7 @@ var __esm = (fn, res, err) => () => {
47
49
  throw err[0];
48
50
  return res;
49
51
  };
52
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
50
53
 
51
54
  // ../../harness/kernel/adapters/agents/claude-code/claude-code-transcript.ts
52
55
  function isTokenCollectionWiringBroken(capability) {
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ import { createRequire } from "node:module";
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -23,6 +24,7 @@ var __toCommonJS = (from) => {
23
24
  return entry;
24
25
  };
25
26
  var __moduleCache;
27
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
26
28
  var __returnValue = (v) => v;
27
29
  function __exportSetter(name, newValue) {
28
30
  this[name] = __returnValue.bind(null, newValue);
@@ -47,6 +49,7 @@ var __esm = (fn, res, err) => () => {
47
49
  throw err[0];
48
50
  return res;
49
51
  };
52
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
50
53
 
51
54
  // ../../harness/kernel/connectors/git/changed-line-ranges.ts
52
55
  function parseChangedLineRanges(diffOutput) {
@@ -1,4 +1,70 @@
1
1
  #!/usr/bin/env node
2
+ var __esm = (fn, res, err) => () => {
3
+ if (fn)
4
+ try {
5
+ res = fn(fn = 0);
6
+ } catch (e) {
7
+ err = [e];
8
+ }
9
+ if (err)
10
+ throw err[0];
11
+ return res;
12
+ };
13
+
14
+ // ../../harness/kernel/adapters/code-host/github/resolve-repo.ts
15
+ import { execFile as execFile3 } from "node:child_process";
16
+ import { promisify as promisify3 } from "node:util";
17
+ async function resolveRepo(exec = defaultExec) {
18
+ if (cached !== undefined)
19
+ return cached;
20
+ const fromEnv = process.env.VINAYA_REPO;
21
+ if (fromEnv) {
22
+ const parsed = parseOwnerRepo(fromEnv);
23
+ if (parsed) {
24
+ cached = parsed;
25
+ return cached;
26
+ }
27
+ }
28
+ if (inflight)
29
+ return inflight;
30
+ inflight = (async () => {
31
+ try {
32
+ const { stdout } = await exec();
33
+ cached = parseGitRemoteUrl(stdout.trim());
34
+ return cached;
35
+ } catch (err) {
36
+ const message = err instanceof Error ? err.message : String(err);
37
+ console.warn(`[resolve-repo] resolveRepo: git remote lookup failed (will retry): ${message}`);
38
+ return null;
39
+ } finally {
40
+ inflight = undefined;
41
+ }
42
+ })();
43
+ return inflight;
44
+ }
45
+ function parseGitRemoteUrl(url) {
46
+ const ssh = url.match(/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/);
47
+ if (ssh?.[1] && ssh[2])
48
+ return { owner: ssh[1], repo: ssh[2] };
49
+ const https = url.match(/^https?:\/\/(?:[^@]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/);
50
+ if (https?.[1] && https[2])
51
+ return { owner: https[1], repo: https[2] };
52
+ return null;
53
+ }
54
+ function parseOwnerRepo(value) {
55
+ const match = value.match(/^([^/]+)\/(.+)$/);
56
+ if (!match?.[1] || !match[2])
57
+ return null;
58
+ return { owner: match[1], repo: match[2] };
59
+ }
60
+ var execFileAsync3, systemEnv3, defaultExec = () => execFileAsync3("git", ["remote", "get-url", "origin"], { env: systemEnv3, timeout: 5000 }), cached, inflight;
61
+ var init_resolve_repo = __esm(() => {
62
+ execFileAsync3 = promisify3(execFile3);
63
+ systemEnv3 = {
64
+ ...process.env,
65
+ PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
66
+ };
67
+ });
2
68
 
3
69
  // ../../harness/processes/vinaya-strict/checks/standalone/verify-coherence.ts
4
70
  import { execFileSync as execFileSync2 } from "node:child_process";
@@ -674,6 +740,7 @@ var LOOP_PAUSED_MARKER = commentMarkerFamily("loop:paused");
674
740
  var LOOP_UNPUSHED_WORK_RESUME_MARKER = commentMarkerFamily("loop:unpushed-work-resume");
675
741
  var PRINCIPAL_RULING_MARKER = commentMarkerFamily("principal:ruling");
676
742
  var OBJECTIVES_VERSION_MARKER = commentMarkerFamily("objectives");
743
+ var DOCUMENTATION_EDIT_MARKER = commentMarkerFamily("documentation");
677
744
  var DEFERRED_FINDINGS_MARKER = commentMarkerFamily("deferred-findings");
678
745
  var COMMENT_MARKER_PREFIX_CURRENT = COMMENT_MARKER_PREFIX.current;
679
746
  var COMMENT_MARKER_PREFIXES = [COMMENT_MARKER_PREFIX.current, COMMENT_MARKER_PREFIX.old];
@@ -872,6 +939,31 @@ async function ghApiGetAllPagesAsync(pathWithoutPage, opts) {
872
939
  }
873
940
  throw new Error(`ghApiGetAllPagesAsync: "${pathWithoutPage}" did not terminate within ${MAX_PAGES} pages (${MAX_PAGES * MAX_PER_PAGE} items) — refusing to keep walking.`);
874
941
  }
942
+ var LABEL_ISSUE_COUNTS_QUERY = `query($owner: String!, $name: String!, $endCursor: String) {
943
+ repository(owner: $owner, name: $name) {
944
+ labels(first: 100, after: $endCursor, query: $labelQuery) {
945
+ pageInfo { hasNextPage endCursor }
946
+ nodes { name open: issues(states: OPEN) { totalCount } all: issues { totalCount } }
947
+ }
948
+ }
949
+ }`;
950
+ async function ghLabelIssueCountsAsync(owner, repo, labelQuery) {
951
+ const stdout = await runAsync([
952
+ "api",
953
+ "graphql",
954
+ "--paginate",
955
+ "-f",
956
+ `query=${LABEL_ISSUE_COUNTS_QUERY.replace("$labelQuery", JSON.stringify(labelQuery))}`,
957
+ "-f",
958
+ `owner=${owner}`,
959
+ "-f",
960
+ `name=${repo}`,
961
+ "--jq",
962
+ ".data.repository.labels.nodes[] | {name, open: .open.totalCount, total: .all.totalCount}"
963
+ ]);
964
+ return stdout.split(`
965
+ `).filter((line) => line.trim() !== "").map((line) => JSON.parse(line));
966
+ }
875
967
  function issueListByLabelArgs(owner, repo, label) {
876
968
  return [
877
969
  "issue",
@@ -1441,6 +1533,33 @@ function tasksFromIssues(issues) {
1441
1533
  }
1442
1534
  return tasks.sort((a, b) => compareTaskIds(a.id, b.id));
1443
1535
  }
1536
+ function resolveDuplicateTasks(tasks, isOpen) {
1537
+ const byId = new Map;
1538
+ for (const t of tasks)
1539
+ byId.set(t.id, [...byId.get(t.id) ?? [], t]);
1540
+ const resolved = [];
1541
+ const conflicts = [];
1542
+ for (const [id, group] of byId) {
1543
+ const first = group[0];
1544
+ if (!first)
1545
+ continue;
1546
+ if (group.length === 1) {
1547
+ resolved.push(first);
1548
+ continue;
1549
+ }
1550
+ const number = (t) => t.issue ?? 0;
1551
+ const open = group.filter((t) => t.issue !== null && isOpen(t.issue)).sort((a, b) => number(a) - number(b));
1552
+ if (open.length > 1) {
1553
+ conflicts.push({ id, issues: open.map(number) });
1554
+ resolved.push(open[0]);
1555
+ } else if (open.length === 1) {
1556
+ resolved.push(open[0]);
1557
+ } else {
1558
+ resolved.push([...group].sort((a, b) => number(b) - number(a))[0]);
1559
+ }
1560
+ }
1561
+ return { tasks: resolved.sort((a, b) => compareTaskIds(a.id, b.id)), conflicts };
1562
+ }
1444
1563
  async function fetchTrancheIssuesAsync(owner, repo, slug) {
1445
1564
  return ghIssueListByAnyLabelAsync(owner, repo, [trancheLabel(slug)]);
1446
1565
  }
@@ -1550,6 +1669,19 @@ function lifecycleFromIssues(issues) {
1550
1669
  return "planned";
1551
1670
  return issues.some((i) => i.state === "OPEN") ? "active" : "complete";
1552
1671
  }
1672
+ function lifecycleFromCounts(open, total) {
1673
+ if (total === 0)
1674
+ return "planned";
1675
+ return open > 0 ? "active" : "complete";
1676
+ }
1677
+ function resolveLegacyFactsFromCounts(milestone, open, total) {
1678
+ if (milestone.state === "closed" && total > 0) {
1679
+ return { goal: milestone.description ?? "", lifecycle: lifecycleFromCounts(open, total) };
1680
+ }
1681
+ return factsFromLegacyMilestone(milestone);
1682
+ }
1683
+ var TRANCHE_LABEL_QUERY = "vinaya/tranche:";
1684
+ var ACTIVE_ISSUE_READ_CONCURRENCY = 4;
1553
1685
  function goalFromMilestones(milestones, slug) {
1554
1686
  for (const m of milestones) {
1555
1687
  const goal = intentGoalForSlug(m.description ?? "", slug);
@@ -1577,10 +1709,20 @@ function trancheSlugsFromLabels(labels) {
1577
1709
  }
1578
1710
  async function indexTrancheMilestonesAsync(owner, repo, options = {}) {
1579
1711
  const read = (fetch) => options.retryFailedReads ? retryOnce(fetch) : fetch();
1580
- const [milestones, labels] = await Promise.all([
1712
+ const [milestones, labels, counts] = await Promise.all([
1581
1713
  read(() => ghApiGetAllPagesAsync(`repos/${owner}/${repo}/milestones?state=all&per_page=100`)),
1582
- read(() => ghApiGetAllPagesAsync(`repos/${owner}/${repo}/labels?per_page=100`))
1714
+ read(() => ghApiGetAllPagesAsync(`repos/${owner}/${repo}/labels?per_page=100`)),
1715
+ read(() => ghLabelIssueCountsAsync(owner, repo, TRANCHE_LABEL_QUERY))
1583
1716
  ]);
1717
+ const countsByLabel = new Map(counts.map((c) => [c.name, c]));
1718
+ const uncounted = trancheSlugsFromLabels(labels).map((slug) => trancheLabel(slug)).filter((label) => !countsByLabel.has(label));
1719
+ if (uncounted.length > 0) {
1720
+ throw new Error(`the label Issue-count query returned no count for ${uncounted.join(", ")}`);
1721
+ }
1722
+ const lifecycleOf = (slug) => {
1723
+ const c = countsByLabel.get(trancheLabel(slug));
1724
+ return lifecycleFromCounts(c?.open ?? 0, c?.total ?? 0);
1725
+ };
1584
1726
  const active = [];
1585
1727
  const archived = [];
1586
1728
  const facts = new Map;
@@ -1588,33 +1730,21 @@ async function indexTrancheMilestonesAsync(owner, repo, options = {}) {
1588
1730
  const legacyMilestoneBySlug = new Map(milestones.filter((m) => legacySlugs.has(m.title)).map((m) => [m.title, m]));
1589
1731
  const newPathSlugs = trancheSlugsFromLabels(labels).filter((slug) => !legacySlugs.has(slug));
1590
1732
  const uniqueNewPathSlugs = [...new Set(newPathSlugs)];
1591
- const uniqueLegacySlugs = [...legacySlugs];
1592
- const [legacyIssuesBySlug, newPathIssuesBySlug] = await Promise.all([
1593
- Promise.all(uniqueLegacySlugs.map((slug) => read(() => ghIssueListByLabelAsync(owner, repo, trancheLabel(slug))))),
1594
- Promise.all(uniqueNewPathSlugs.map((slug) => read(() => ghIssueListByLabelAsync(owner, repo, trancheLabel(slug)))))
1595
- ]);
1596
- const issuesBySlug = new Map;
1597
- uniqueLegacySlugs.forEach((slug, i) => {
1598
- issuesBySlug.set(slug, legacyIssuesBySlug[i] ?? []);
1599
- });
1600
- uniqueNewPathSlugs.forEach((slug, i) => {
1601
- issuesBySlug.set(slug, newPathIssuesBySlug[i] ?? []);
1602
- });
1603
- uniqueLegacySlugs.forEach((slug, i) => {
1733
+ for (const slug of legacySlugs) {
1604
1734
  const m = legacyMilestoneBySlug.get(slug);
1605
1735
  if (!m)
1606
- return;
1736
+ continue;
1607
1737
  const ref = { slug, goal: m.description ?? "" };
1608
- const f = resolveLegacyFacts(m, legacyIssuesBySlug[i] ?? []);
1738
+ const c = countsByLabel.get(trancheLabel(slug));
1739
+ const f = resolveLegacyFactsFromCounts(m, c?.open ?? 0, c?.total ?? 0);
1609
1740
  if (f.lifecycle === "complete")
1610
1741
  archived.push(ref);
1611
1742
  else if (f.lifecycle === "active")
1612
1743
  active.push(ref);
1613
1744
  facts.set(slug, f);
1614
- });
1615
- uniqueNewPathSlugs.forEach((slug, i) => {
1616
- const issues = newPathIssuesBySlug[i] ?? [];
1617
- const lifecycle = lifecycleFromIssues(issues);
1745
+ }
1746
+ for (const slug of uniqueNewPathSlugs) {
1747
+ const lifecycle = lifecycleOf(slug);
1618
1748
  const goal = goalFromMilestones(milestones, slug);
1619
1749
  const f = { goal, lifecycle };
1620
1750
  facts.set(slug, f);
@@ -1622,7 +1752,16 @@ async function indexTrancheMilestonesAsync(owner, repo, options = {}) {
1622
1752
  active.push({ slug, goal });
1623
1753
  else if (lifecycle === "complete")
1624
1754
  archived.push({ slug, goal });
1625
- });
1755
+ }
1756
+ const issuesBySlug = new Map;
1757
+ const activeSlugs = active.map((r) => r.slug);
1758
+ for (let i = 0;i < activeSlugs.length; i += ACTIVE_ISSUE_READ_CONCURRENCY) {
1759
+ const batch = activeSlugs.slice(i, i + ACTIVE_ISSUE_READ_CONCURRENCY);
1760
+ const lists = await Promise.all(batch.map((slug) => read(() => ghIssueListByLabelAsync(owner, repo, trancheLabel(slug)))));
1761
+ batch.forEach((slug, j) => {
1762
+ issuesBySlug.set(slug, lists[j] ?? []);
1763
+ });
1764
+ }
1626
1765
  return { active, archived, facts, legacySlugs, issuesBySlug };
1627
1766
  }
1628
1767
  async function retryOnce(fetch) {
@@ -1649,60 +1788,8 @@ function trancheFromIssues(slug, issues, known) {
1649
1788
  };
1650
1789
  }
1651
1790
 
1652
- // ../../harness/kernel/adapters/code-host/github/resolve-repo.ts
1653
- import { execFile as execFile3 } from "node:child_process";
1654
- import { promisify as promisify3 } from "node:util";
1655
- var execFileAsync3 = promisify3(execFile3);
1656
- var systemEnv3 = {
1657
- ...process.env,
1658
- PATH: [process.env.PATH, "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin"].filter(Boolean).join(":")
1659
- };
1660
- var defaultExec = () => execFileAsync3("git", ["remote", "get-url", "origin"], { env: systemEnv3, timeout: 5000 });
1661
- var cached;
1662
- var inflight;
1663
- async function resolveRepo(exec = defaultExec) {
1664
- if (cached !== undefined)
1665
- return cached;
1666
- const fromEnv = process.env.VINAYA_REPO;
1667
- if (fromEnv) {
1668
- const parsed = parseOwnerRepo(fromEnv);
1669
- if (parsed) {
1670
- cached = parsed;
1671
- return cached;
1672
- }
1673
- }
1674
- if (inflight)
1675
- return inflight;
1676
- inflight = (async () => {
1677
- try {
1678
- const { stdout } = await exec();
1679
- cached = parseGitRemoteUrl(stdout.trim());
1680
- return cached;
1681
- } catch (err) {
1682
- const message = err instanceof Error ? err.message : String(err);
1683
- console.warn(`[resolve-repo] resolveRepo: git remote lookup failed (will retry): ${message}`);
1684
- return null;
1685
- } finally {
1686
- inflight = undefined;
1687
- }
1688
- })();
1689
- return inflight;
1690
- }
1691
- function parseGitRemoteUrl(url) {
1692
- const ssh = url.match(/^git@github\.com:([^/]+)\/(.+?)(?:\.git)?$/);
1693
- if (ssh?.[1] && ssh[2])
1694
- return { owner: ssh[1], repo: ssh[2] };
1695
- const https = url.match(/^https?:\/\/(?:[^@]+@)?github\.com\/([^/]+)\/(.+?)(?:\.git)?\/?$/);
1696
- if (https?.[1] && https[2])
1697
- return { owner: https[1], repo: https[2] };
1698
- return null;
1699
- }
1700
- function parseOwnerRepo(value) {
1701
- const match = value.match(/^([^/]+)\/(.+)$/);
1702
- if (!match?.[1] || !match[2])
1703
- return null;
1704
- return { owner: match[1], repo: match[2] };
1705
- }
1791
+ // ../../harness/processes/vinaya-strict/checks/standalone/verify-coherence.ts
1792
+ init_resolve_repo();
1706
1793
 
1707
1794
  // ../../harness/processes/vinaya-strict/tools/task-contract/forge/map-forge-facts.ts
1708
1795
  function mapForgeFacts(raw) {
@@ -1802,38 +1889,6 @@ async function fetchForgeFactsByIssue(input) {
1802
1889
  }
1803
1890
  return { facts, prRefs, unavailable: false };
1804
1891
  }
1805
- async function fetchForgeFacts(input) {
1806
- const byIssue = await fetchForgeFactsByIssue(input);
1807
- if (byIssue.unavailable) {
1808
- return { facts: new Map, prRefs: new Map, unavailable: true, reason: byIssue.reason };
1809
- }
1810
- const facts = new Map;
1811
- const prRefs = new Map;
1812
- const winner = new Map;
1813
- for (const task of input.tasks) {
1814
- if (task.issue === null)
1815
- continue;
1816
- const current = winner.get(task.id);
1817
- if (current === undefined || outranks(byIssue.facts, task.issue, current))
1818
- winner.set(task.id, task.issue);
1819
- }
1820
- for (const [taskId, issue] of winner) {
1821
- const f = byIssue.facts.get(issue);
1822
- if (f)
1823
- facts.set(taskId, f);
1824
- const pr = byIssue.prRefs.get(issue);
1825
- if (pr)
1826
- prRefs.set(taskId, pr);
1827
- }
1828
- return { facts, prRefs, unavailable: false };
1829
- }
1830
- function outranks(facts, candidate, current) {
1831
- const candidateOpen = facts.get(candidate)?.issueState === "open";
1832
- const currentOpen = facts.get(current)?.issueState === "open";
1833
- if (candidateOpen !== currentOpen)
1834
- return candidateOpen;
1835
- return candidate > current;
1836
- }
1837
1892
  function buildBatchQuery(tranche, tasks) {
1838
1893
  const perTask = tasks.map((task) => {
1839
1894
  const a = aliasFor2(task.issue);
@@ -1911,10 +1966,23 @@ function describeError(err) {
1911
1966
  }
1912
1967
 
1913
1968
  // ../../harness/processes/vinaya-strict/tools/task-contract/forge/fetch-open-issues.ts
1914
- async function fetchOpenIssuesByLabel(slugs, owner, repo, token) {
1969
+ function failureReason(err, token) {
1970
+ const message = err instanceof Error ? err.message : String(err);
1971
+ if (token.length > 0 && message.includes(token))
1972
+ return null;
1973
+ return message;
1974
+ }
1975
+ async function fetchOpenIssuesByLabel(slugs, owner, repo, token, onFailedRead) {
1976
+ const read = await readOpenIssuesByLabel(slugs, owner, repo, token);
1977
+ if (read.ok)
1978
+ return read.issues;
1979
+ onFailedRead?.(read.reason);
1980
+ return new Map;
1981
+ }
1982
+ async function readOpenIssuesByLabel(slugs, owner, repo, token) {
1915
1983
  const result = new Map;
1916
1984
  if (slugs.length === 0)
1917
- return result;
1985
+ return { ok: true, issues: result };
1918
1986
  const client = graphql2.defaults({ headers: { authorization: `bearer ${token}` } });
1919
1987
  const toAlias = (slug) => `tranche_${slug.replace(/-/g, "_")}`;
1920
1988
  const perSlug = slugs.map((slug) => `
@@ -1928,11 +1996,12 @@ async function fetchOpenIssuesByLabel(slugs, owner, repo, token) {
1928
1996
  let response;
1929
1997
  try {
1930
1998
  response = await client(query, { owner, repo });
1931
- } catch {
1932
- return result;
1999
+ } catch (err) {
2000
+ return { ok: false, reason: failureReason(err, token) };
2001
+ }
2002
+ if (!response.repository) {
2003
+ return { ok: false, reason: `the repository ${owner}/${repo} is not visible to the token` };
1933
2004
  }
1934
- if (!response.repository)
1935
- return result;
1936
2005
  for (const slug of slugs) {
1937
2006
  const conn = response.repository[toAlias(slug)];
1938
2007
  const issues = (conn?.nodes ?? []).map((n) => ({
@@ -1942,7 +2011,7 @@ async function fetchOpenIssuesByLabel(slugs, owner, repo, token) {
1942
2011
  }));
1943
2012
  result.set(slug, issues);
1944
2013
  }
1945
- return result;
2014
+ return { ok: true, issues: result };
1946
2015
  }
1947
2016
 
1948
2017
  // ../../harness/processes/vinaya-strict/tools/task-contract/parse-registry.ts
@@ -2352,6 +2421,7 @@ var DOCTRINE_MAP = [
2352
2421
  { key: "roles/developer.md", source: "executing/developer/doctrine.md", role: "developer", ships: true },
2353
2422
  { key: "roles/developer/reference.md", source: "executing/developer/reference.md", ships: true },
2354
2423
  { key: "roles/operator.md", source: "executing/operator/doctrine.md", role: "operator", ships: true },
2424
+ { key: "roles/plan-reviewer.md", source: "thinking/plan-reviewer/doctrine.md", role: "plan-reviewer", ships: true },
2355
2425
  { key: "roles/planner.md", source: "thinking/planner/doctrine.md", role: "planner", ships: true },
2356
2426
  { key: "roles/planner/reference.md", source: "thinking/planner/reference.md", ships: true },
2357
2427
  { key: "roles/principal.md", source: "doctrine/roles/principal.md", role: "principal", ships: true },
@@ -3043,7 +3113,8 @@ function isMechanicallyNeutralDiff(diffText, path) {
3043
3113
  }
3044
3114
  return sawChange;
3045
3115
  }
3046
- function evaluateC5(changed, docOwnersContent, prBody, fileExists, waiverActive, getDiff) {
3116
+ var DOC_NEUTRAL_OWED_PREFIX = "C5 doc-neutral-owed:";
3117
+ function evaluateC5(changed, docOwnersContent, prBody, fileExists, waiverActive, getDiff, bodyGiven = true) {
3047
3118
  const out = { errors: [], notes: [] };
3048
3119
  if (docOwnersContent === null)
3049
3120
  return out;
@@ -3083,19 +3154,23 @@ function evaluateC5(changed, docOwnersContent, prBody, fileExists, waiverActive,
3083
3154
  }
3084
3155
  if (changed.includes(pointerPath))
3085
3156
  continue;
3157
+ const evidenced = () => getDiff !== undefined && matchedFiles.every((f) => {
3158
+ const diff = getDiff(f);
3159
+ return diff !== null && isMechanicallyNeutralDiff(diff, f);
3160
+ });
3086
3161
  const declared = neutrals.find((n) => n.surface === b.pointer);
3087
3162
  if (declared) {
3088
- const evidenced = getDiff !== undefined && matchedFiles.every((f) => {
3089
- const diff = getDiff(f);
3090
- return diff !== null && isMechanicallyNeutralDiff(diff, f);
3091
- });
3092
- if (evidenced) {
3163
+ if (evidenced()) {
3093
3164
  out.notes.push(`C5 doc-neutral: ${b.pointer} not required for ${DOC_OWNERS_PATH}:${b.lineNum} (glob \`${b.glob}\`) — declared neutral ("${declared.note}"), diff of ${matchedFiles.join(", ")} confirmed comment/whitespace-only.`);
3094
3165
  continue;
3095
3166
  }
3096
3167
  out.errors.push(`C5 doc-neutral-unverified: ${DOC_OWNERS_PATH}:${b.lineNum} (glob \`${b.glob}\` → ${b.pointer}) declared \`Doc-neutral: ${b.pointer} — ${declared.note}\`, but the diff of ${matchedFiles.join(", ")} contains changes beyond comments/whitespace. Update ${pointerPath}, or have a principal apply the \`${WAIVER_LABEL}\` label.`);
3097
3168
  continue;
3098
3169
  }
3170
+ if (!bodyGiven && evidenced()) {
3171
+ out.notes.push(`${DOC_NEUTRAL_OWED_PREFIX} ${b.pointer} not required in this run for ${DOC_OWNERS_PATH}:${b.lineNum} (glob \`${b.glob}\`) — no pull request body was given, and the diff of ${matchedFiles.join(", ")} is comment/whitespace-only. The pull request body owes \`Doc-neutral: ${b.pointer} — <why>\`.`);
3172
+ continue;
3173
+ }
3099
3174
  out.errors.push(`C5 doc-coverage: code change matched ${DOC_OWNERS_PATH}:${b.lineNum} (glob \`${b.glob}\` → ${b.pointer}), but ${pointerPath} is not in the PR diff. Update it, declare \`Doc-neutral: ${b.pointer} — <why>\` if the change is genuinely mechanically-neutral, or have a principal apply the \`${WAIVER_LABEL}\` label.`);
3100
3175
  }
3101
3176
  return out;
@@ -3146,6 +3221,11 @@ var PROTECTED_ADMIN_PATHS = [
3146
3221
  ...DOCTRINE_REPO_PATHS
3147
3222
  ];
3148
3223
 
3224
+ // ../../harness/processes/vinaya-strict/tools/task-contract/test-plan-proof.ts
3225
+ var ID_LIST = String.raw`O\d+(?:\s*,\s*O\d+)*`;
3226
+ var LINE_IDS_RE = new RegExp(String.raw`\(\s*(${ID_LIST})\s*\)\s*$`);
3227
+ var ITEM_IDS_SPAN_RE = new RegExp(String.raw`(?<!\`)(\`+)\s*\(?\s*(${ID_LIST})\s*\)?\s*\1(?!\`)`, "g");
3228
+
3149
3229
  // ../../harness/processes/vinaya-strict/tools/task-contract/issue-validation.ts
3150
3230
  function hasRationaleField(body, labelPattern) {
3151
3231
  const re = new RegExp(`(?:\\*\\*|^#{1,4}\\s+)\\s*(?:${labelPattern})`, "im");
@@ -3512,6 +3592,21 @@ function isGrandfathered(isoDate) {
3512
3592
  return isoDate.slice(0, 10) < COHERENCE_ENFORCED_FROM;
3513
3593
  }
3514
3594
  var R1_GRANDFATHERED_ISSUES = new Set([279, 280, 281, 282]);
3595
+ function buildIssueEntries(trancheSlug, archived, tasks, factsByIssue) {
3596
+ return tasks.map((task) => ({
3597
+ trancheSlug,
3598
+ archived,
3599
+ task,
3600
+ facts: task.issue === null ? undefined : factsByIssue?.get(task.issue)
3601
+ }));
3602
+ }
3603
+ function buildTaskEntries(trancheSlug, archived, tasks, factsByIssue) {
3604
+ const { tasks: standing } = resolveDuplicateTasks(tasks, (n) => factsByIssue?.get(n)?.issueState === "open");
3605
+ return buildIssueEntries(trancheSlug, archived, standing, factsByIssue);
3606
+ }
3607
+ function provenanceKey(issue) {
3608
+ return String(issue);
3609
+ }
3515
3610
  function checkA1(entries, principalAllowlist) {
3516
3611
  const failures = [];
3517
3612
  for (const e of entries) {
@@ -3547,10 +3642,13 @@ function checkA2(entries, hasProvenanceByKey) {
3547
3642
  for (const e of entries) {
3548
3643
  if (!e.facts)
3549
3644
  continue;
3645
+ if (e.task.issue === null)
3646
+ continue;
3647
+ if (e.facts.stateReason === "not_planned")
3648
+ continue;
3550
3649
  if (e.facts.issueState !== "closed" || e.facts.prState !== "merged")
3551
3650
  continue;
3552
- const key = `${e.trancheSlug}/${e.task.id}`;
3553
- const hasProvenance = hasProvenanceByKey.get(key);
3651
+ const hasProvenance = hasProvenanceByKey.get(provenanceKey(e.task.issue));
3554
3652
  if (hasProvenance === undefined)
3555
3653
  continue;
3556
3654
  if (!hasProvenance) {
@@ -4375,6 +4473,14 @@ async function loadTrancheSweep(prContext = null, onlySlug, baseRef = "origin/ma
4375
4473
  async function loadTrancheFiles(prContext = null, onlySlug) {
4376
4474
  return (await loadTrancheSweep(prContext, onlySlug)).files;
4377
4475
  }
4476
+ async function evaluateA2ByIssue(entries, readProvenance) {
4477
+ const candidates = entries.filter((e) => e.facts?.issueState === "closed" && e.facts.prState === "merged" && e.facts.stateReason !== "not_planned" && e.task.issue !== null);
4478
+ const byIssue = await readProvenance(candidates.map((e) => e.task.issue));
4479
+ const provenanceByKey = new Map;
4480
+ for (const [issue, has] of byIssue)
4481
+ provenanceByKey.set(provenanceKey(issue), has);
4482
+ return checkA2(entries, provenanceByKey);
4483
+ }
4378
4484
  async function runCoherenceChecks(options = {}) {
4379
4485
  const { prContext = null, isPlanPr = false } = options;
4380
4486
  const principals = readConfigPrincipals();
@@ -4439,7 +4545,7 @@ async function runCoherenceChecks(options = {}) {
4439
4545
  })).filter(({ tasks }) => tasks.length > 0);
4440
4546
  const snapshotResults = await Promise.all(eligible.map(async ({ f, tasks }) => ({
4441
4547
  f,
4442
- snapshot: await fetchForgeFacts({ owner, repo: repoName, tranche: f.slug, tasks })
4548
+ snapshot: await fetchForgeFactsByIssue({ owner, repo: repoName, tranche: f.slug, tasks })
4443
4549
  })));
4444
4550
  for (const { f, snapshot } of snapshotResults) {
4445
4551
  if (snapshot.unavailable) {
@@ -4449,38 +4555,20 @@ async function runCoherenceChecks(options = {}) {
4449
4555
  }
4450
4556
  }
4451
4557
  const forgeUnavailableSlugs = new Set(files.map((f) => f.slug).filter((slug) => !snapshotsBySlug.has(slug)));
4452
- const enrichedEntries = files.flatMap((f) => {
4453
- const factsMap = snapshotsBySlug.get(f.slug);
4454
- return f.tranche.tasks.map((t) => ({
4455
- trancheSlug: f.slug,
4456
- archived: f.archived,
4457
- task: t,
4458
- facts: factsMap?.get(t.id)
4459
- }));
4460
- });
4558
+ const enrichedEntries = files.flatMap((f) => buildTaskEntries(f.slug, f.archived, f.tranche.tasks, snapshotsBySlug.get(f.slug)));
4559
+ const allIssueEntries = files.flatMap((f) => buildIssueEntries(f.slug, f.archived, f.tranche.tasks, snapshotsBySlug.get(f.slug)));
4560
+ const issueEntries = allIssueEntries.filter((e) => snapshotsBySlug.has(e.trancheSlug));
4461
4561
  const issueToEntry = new Map;
4462
4562
  const taskToEntry = new Map;
4463
- for (const e of enrichedEntries) {
4563
+ for (const e of allIssueEntries)
4464
4564
  if (e.task.issue !== null)
4465
4565
  issueToEntry.set(e.task.issue, e);
4566
+ for (const e of enrichedEntries)
4466
4567
  taskToEntry.set(`${e.trancheSlug}/${e.task.id}`, e);
4467
- }
4468
4568
  const availableEntries = enrichedEntries.filter((e) => snapshotsBySlug.has(e.trancheSlug));
4469
4569
  results.push(checkA1(availableEntries, principals.principals));
4470
4570
  results.push(checkA3(availableEntries));
4471
- const a2Candidates = availableEntries.filter((e) => e.facts?.issueState === "closed" && e.facts.prState === "merged" && e.task.issue !== null);
4472
- const a2IssueNums = a2Candidates.map((e) => e.task.issue);
4473
- const provenanceByIssueNum = await fetchProvenance(a2IssueNums, owner, repoName, token);
4474
- const provenanceByKey = new Map;
4475
- for (const e of a2Candidates) {
4476
- if (e.task.issue === null)
4477
- continue;
4478
- const hasProvenance = provenanceByIssueNum.get(e.task.issue);
4479
- if (hasProvenance !== undefined) {
4480
- provenanceByKey.set(`${e.trancheSlug}/${e.task.id}`, hasProvenance);
4481
- }
4482
- }
4483
- results.push(checkA2(availableEntries, provenanceByKey));
4571
+ results.push(await evaluateA2ByIssue(issueEntries, (nums) => fetchProvenance(nums, owner, repoName, token)));
4484
4572
  results.push(checkT1(availableEntries));
4485
4573
  results.push(checkT3(allEntries, ciTrancheSlug, enrichedEntries, forgeUnavailableSlugs));
4486
4574
  const activeSlugs = files.filter((f) => !f.archived).map((f) => f.slug);
@@ -4656,6 +4744,7 @@ if (isEntryPoint(import.meta.url, "verify-coherence")) {
4656
4744
  process.exit(failed.length > 0 ? 1 : 0);
4657
4745
  }
4658
4746
  export {
4747
+ evaluateA2ByIssue,
4659
4748
  fetchProvenance,
4660
4749
  loadTrancheFiles,
4661
4750
  loadTrancheSweep,