@attalabs/vinaya 0.20.1 → 0.22.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 (152) hide show
  1. package/README.md +76 -1
  2. package/aeg-root/enforcement.md +15 -7
  3. package/aeg-root/milestone-model.md +3 -1
  4. package/aeg-root/roles/architect.md +2 -2
  5. package/aeg-root/roles/archivist.md +2 -2
  6. package/aeg-root/roles/developer.md +3 -2
  7. package/aeg-root/roles/planner.md +2 -2
  8. package/aeg-root/roles/principal.md +1 -0
  9. package/aeg-root/roles/tranche-archivist.md +2 -2
  10. package/aeg-root/templates/issue-rationale-template.md +4 -4
  11. package/aeg-root/templates/pr-report-template.md +2 -0
  12. package/aeg-root/tranche-model.md +4 -4
  13. package/dist/checks/bin/check-body-bare-digits.js +392 -10
  14. package/dist/checks/bin/check-branch-topology.js +382 -2
  15. package/dist/checks/bin/check-brief-shape.js +357 -2
  16. package/dist/checks/bin/check-changeset-coverage.js +4262 -0
  17. package/dist/checks/bin/check-closes-n.js +382 -2
  18. package/dist/checks/bin/check-coherence.js +416 -8
  19. package/dist/checks/bin/check-dead-branch-push.js +357 -2
  20. package/dist/checks/bin/check-dispatch-readiness.js +492 -25
  21. package/dist/checks/bin/check-doc-coverage-push.js +392 -9
  22. package/dist/checks/bin/check-doc-coverage.js +392 -9
  23. package/dist/checks/bin/check-doctrine-portability.js +391 -8
  24. package/dist/checks/bin/check-evidence-fresh.js +357 -2
  25. package/dist/checks/bin/check-first-push-dispatch.js +481 -17
  26. package/dist/checks/bin/check-issue-assignment.js +382 -2
  27. package/dist/checks/bin/check-main-branch-refusal.js +357 -2
  28. package/dist/checks/bin/check-no-disk-state.js +357 -2
  29. package/dist/checks/bin/check-quoted-command.js +4514 -0
  30. package/dist/checks/bin/check-reader-resolvable-prose.js +430 -21
  31. package/dist/checks/bin/check-registry-gates.js +410 -7
  32. package/dist/checks/bin/check-retired-vocabulary.js +422 -13
  33. package/dist/checks/bin/check-review-gate.js +389 -6
  34. package/dist/checks/bin/check-single-plan-pr.js +357 -2
  35. package/dist/checks/bin/check-test-plan.js +357 -2
  36. package/dist/checks/bin/check-token-collection-wired.js +4081 -0
  37. package/dist/checks/bin/check-token-report.js +4096 -0
  38. package/dist/checks/bin/check-workspace-escape.js +359 -4
  39. package/dist/index.js +1607 -641
  40. package/package.json +1 -1
  41. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  42. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  43. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  44. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  45. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  46. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  47. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  48. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  49. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  50. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  51. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  52. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js +2 -2
  53. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  54. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  55. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
  56. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  57. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js +2 -2
  58. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  59. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  60. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  61. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +2 -2
  62. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  63. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  64. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  65. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +3 -3
  66. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  67. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  68. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  69. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +3 -3
  70. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  71. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  72. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +2 -2
  73. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +3 -3
  74. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  75. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  76. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  77. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +3 -3
  78. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  79. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  80. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  81. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +3 -3
  82. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  83. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  84. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  85. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +2 -2
  86. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  87. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  88. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +1 -1
  89. 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
  90. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0053k9k._.js +1 -1
  91. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0112h-k._.js +1 -1
  92. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__02c71kv._.js +1 -1
  93. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__040smoa._.js +1 -1
  94. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__16cuydh._.js → [root-of-the-server]__069-_41._.js} +1 -1
  95. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0cxtq46._.js +25 -18
  96. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0o771t1._.js +1 -1
  97. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0puovz5._.js +1 -1
  98. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__0ykun-j._.js → [root-of-the-server]__0z6dav-._.js} +3 -3
  99. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__18kqy4q._.js +1 -1
  100. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__19jyp3m._.js +1 -1
  101. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1hs0dcu._.js +1 -1
  102. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  103. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1widio3._.js +1 -1
  104. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1yoa8tx._.js +3 -0
  105. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_03x_w6q._.js +1 -1
  106. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0gvm3og._.js +1 -1
  107. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0lwxg63._.js +1 -1
  108. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0o54suy._.js +1 -1
  109. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0wxycau._.js +1 -1
  110. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0x999pb._.js +1 -1
  111. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-6rzip._.js +1 -1
  112. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1fqw88f._.js +2 -2
  113. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{_0zys35s._.js → _1mqrlbl._.js} +2 -2
  114. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{_1c9b9j-._.js → _1mrtj0f._.js} +2 -2
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1n0cnq-._.js +1 -1
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{apps_vinaya-studio_web_src_app_studio_18kqbvs._.js → apps_vinaya-studio_web_src_app_studio_06it6s-._.js} +2 -2
  117. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/apps_vinaya-studio_web_src_app_studio_projects_[name]_tranches_[slug]_05ufo8i._.js +1 -1
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/node_modules_1vo08dj._.js +2 -2
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_animate_components_index_ts_186fje1._.js +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_brutal_components_index_ts_0n_lcc4._.js +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_retro_components_index_ts_0wvpm_z._.js +1 -1
  122. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/packages_ui_libraries_retro_components_index_ts_1_cfi48._.js +1 -1
  123. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  124. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  125. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +3 -3
  127. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/00pi8vhg8w6gi.js +1 -0
  128. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/03q0q9n6-xah8.js +1 -0
  129. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0vc2u252q5q6o.js +1 -0
  130. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/13g16cu00g570.js +1 -0
  131. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1lk7h-0buf4ab.js → 1hufpuody6vjv.js} +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1sfxfunirkcr6.js +1 -0
  133. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{29-foak16tjfu.js → 206ajg8f1a-_h.js} +1 -1
  134. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{0ea8-8nopz29h.js → 267o-tsrnuwnv.js} +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{0msr2a1i-x-br.js → 279qq4twinc97.js} +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{112g08xpx3kro.js → 2ka8dg687auhj.js} +1 -1
  137. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{0up5x3jg-cwov.js → 2rn89uwtf2lwc.js} +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{2twnwe77d4n-m.js → 37hnluhzj9bei.js} +4 -4
  139. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3qc67qhcvbg0o.css +1 -0
  140. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{30ojnsx3p4lp4.js → 3zugx9esh2x51.js} +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1rku4gz._.js +0 -3
  143. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0_jnwbarv-cqk.js +0 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0la0hhmjprdxm.css +0 -1
  145. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/25j-y57ng11hl.js +0 -1
  146. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/30lyvn0yzwdiz.js +0 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/35u8inxa732is.js +0 -1
  148. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/3r5efmleneaco.js +0 -1
  149. /package/studio-standalone/_node_modules/@attalabs/{aeg-core → vinaya/studio-standalone/_node_modules/@attalabs/aeg-core}/bin/verify-coherence.ts +0 -0
  150. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{b2VfZK2AItZwlghK_pUN0 → Fmyc42qzLwFcWWHLLNy-G}/_buildManifest.js +0 -0
  151. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{b2VfZK2AItZwlghK_pUN0 → Fmyc42qzLwFcWWHLLNy-G}/_clientMiddlewareManifest.js +0 -0
  152. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{b2VfZK2AItZwlghK_pUN0 → Fmyc42qzLwFcWWHLLNy-G}/_ssgManifest.js +0 -0
@@ -189,6 +189,12 @@ var NEXT_HEADER = /\*\*[A-Z][^*]*\*\*/;
189
189
  var FIELD_LABEL = /^(Depends-on|Conflicts-with)\s*:\s*(.*)$/i;
190
190
  var ID_TOKEN = /^(?:[\w.-]+\s+)?#?\d+[a-z]?$/i;
191
191
  var SLUG_QUALIFIED_ID = /^([\w.-]+)\s+(#?\d+[a-z]?)$/i;
192
+ function splitSlugQualifiedEdge(edge) {
193
+ const m = edge.trim().match(SLUG_QUALIFIED_ID);
194
+ if (!m)
195
+ return null;
196
+ return { slug: m[1], bareId: m[2] };
197
+ }
192
198
  function isEmptyMarker(s) {
193
199
  const t = s.trim();
194
200
  return t === "" || t === "—" || t === "-" || t === "–";
@@ -1785,6 +1791,257 @@ var DERIVED_STATUSES = [
1785
1791
  "incoherent"
1786
1792
  ];
1787
1793
  var DERIVABLE_STATUSES = DERIVED_STATUSES.filter((s) => s !== "backlog");
1794
+ // ../../packages/aeg-core/src/parse-ledger.ts
1795
+ function rowFromCells(cells) {
1796
+ if (cells.length < 7)
1797
+ return null;
1798
+ const phase = (cells[0] ?? "").trim();
1799
+ if (!phase)
1800
+ return null;
1801
+ return {
1802
+ phase,
1803
+ role: (cells[1] ?? "").trim(),
1804
+ agentModel: (cells[2] ?? "").trim(),
1805
+ tokensIn: parseIntCell(cells[3] ?? ""),
1806
+ tokensOut: parseIntCell(cells[4] ?? ""),
1807
+ cost: parseCostCell(cells[5] ?? ""),
1808
+ date: (cells[6] ?? "").trim()
1809
+ };
1810
+ }
1811
+ function parseIntCell(cell) {
1812
+ const trimmed = cell.replace(/`/g, "").trim();
1813
+ if (!trimmed || isEmDashOrDash(trimmed))
1814
+ return null;
1815
+ const normalized = trimmed.replace(/[,_\s]/g, "");
1816
+ if (!/^-?\d+$/.test(normalized))
1817
+ return null;
1818
+ return Number(normalized);
1819
+ }
1820
+ function parseCostCell(cell) {
1821
+ const trimmed = cell.replace(/`/g, "").trim();
1822
+ if (!trimmed || isEmDashOrDash(trimmed))
1823
+ return null;
1824
+ const normalized = trimmed.replace(/^\$/, "").replace(/[,_\s]/g, "");
1825
+ if (!/^-?\d+(\.\d+)?$/.test(normalized))
1826
+ return null;
1827
+ return Number(normalized);
1828
+ }
1829
+ function isEmDashOrDash(s) {
1830
+ const t = s.trim();
1831
+ return t === "—" || t === "-" || t === "–";
1832
+ }
1833
+ // ../../packages/aeg-core/src/parse-token-report.ts
1834
+ var TOKEN_REPORT_HEADING = /^\s*(?:#{1,6}\s*Token report\s*|\*\*Token report\*\*)\s*$/i;
1835
+ var INLINE_FIELD_LIST = /Phase:\s*([^|]+?)\s*\|\s*Role:\s*([^|]+?)\s*\|\s*Agent\/Model:\s*([^|]+?)\s*\|\s*Tokens in:\s*([^|]+?)\s*\|\s*Tokens out:\s*([^|]+?)\s*\|\s*Cost:\s*([^|]+?)\s*\|\s*Date:\s*(.+?)\s*$/im;
1836
+ function parseTokenReportEntries(body) {
1837
+ const lines = body.split(/\r?\n/);
1838
+ const headingIdxs = [];
1839
+ lines.forEach((line, i) => {
1840
+ if (TOKEN_REPORT_HEADING.test(line))
1841
+ headingIdxs.push(i);
1842
+ });
1843
+ const out = [];
1844
+ for (let h = 0;h < headingIdxs.length; h++) {
1845
+ const start = headingIdxs[h] + 1;
1846
+ const end = h + 1 < headingIdxs.length ? headingIdxs[h + 1] : lines.length;
1847
+ const section = lines.slice(start, end).join(`
1848
+ `);
1849
+ const tableRows = parseTableSection(section);
1850
+ if (tableRows.length > 0) {
1851
+ out.push(...tableRows);
1852
+ continue;
1853
+ }
1854
+ const inlineRow = parseInlineFieldList(section);
1855
+ if (inlineRow)
1856
+ out.push(inlineRow);
1857
+ }
1858
+ return out;
1859
+ }
1860
+ function parseTableSection(section) {
1861
+ const lines = section.split(/\r?\n/);
1862
+ let i = 0;
1863
+ for (;i < lines.length; i++) {
1864
+ if ((lines[i] ?? "").trim().startsWith("|"))
1865
+ break;
1866
+ }
1867
+ if (i + 1 >= lines.length)
1868
+ return [];
1869
+ i += 2;
1870
+ const out = [];
1871
+ for (;i < lines.length; i++) {
1872
+ const trimmed = (lines[i] ?? "").trim();
1873
+ if (!trimmed.startsWith("|"))
1874
+ break;
1875
+ const row = rowFromCells(splitTableRow(trimmed));
1876
+ if (row)
1877
+ out.push(row);
1878
+ }
1879
+ return out;
1880
+ }
1881
+ function parseInlineFieldList(section) {
1882
+ const m = section.match(INLINE_FIELD_LIST);
1883
+ if (!m)
1884
+ return null;
1885
+ return rowFromCells([m[1], m[2], m[3], m[4], m[5], m[6], m[7]]);
1886
+ }
1887
+ // ../../packages/aeg-core/src/report-tokens.ts
1888
+ var DASH_LOOKALIKES = {
1889
+ "-": "‑",
1890
+ "–": "‒",
1891
+ "—": "―"
1892
+ };
1893
+ var DASH_CHARS = new Set(Object.keys(DASH_LOOKALIKES));
1894
+ // ../../packages/aeg-core/src/claude-code-transcript.ts
1895
+ import { createHash } from "node:crypto";
1896
+ function summarizeTranscript(jsonl) {
1897
+ const seen = new Set;
1898
+ const components = {
1899
+ inputTokens: 0,
1900
+ outputTokens: 0,
1901
+ cacheCreationInputTokens: 0,
1902
+ cacheReadInputTokens: 0
1903
+ };
1904
+ let model = null;
1905
+ let messageCount = 0;
1906
+ for (const rawLine of jsonl.split(/\r?\n/)) {
1907
+ const line = rawLine.trim();
1908
+ if (!line)
1909
+ continue;
1910
+ let entry2;
1911
+ try {
1912
+ entry2 = JSON.parse(line);
1913
+ } catch {
1914
+ continue;
1915
+ }
1916
+ if (!entry2 || typeof entry2 !== "object")
1917
+ continue;
1918
+ const obj = entry2;
1919
+ if (obj.type !== "assistant")
1920
+ continue;
1921
+ const message = obj.message;
1922
+ const id = message?.id;
1923
+ const usage = message?.usage;
1924
+ if (typeof id !== "string" || !id || !usage || seen.has(id))
1925
+ continue;
1926
+ seen.add(id);
1927
+ messageCount++;
1928
+ components.inputTokens += numberOr(usage.input_tokens, 0);
1929
+ components.outputTokens += numberOr(usage.output_tokens, 0);
1930
+ components.cacheCreationInputTokens += numberOr(usage.cache_creation_input_tokens, 0);
1931
+ components.cacheReadInputTokens += numberOr(usage.cache_read_input_tokens, 0);
1932
+ const messageModel = message?.model;
1933
+ if (typeof messageModel === "string" && messageModel)
1934
+ model = messageModel;
1935
+ }
1936
+ return { components, model, messageCount };
1937
+ }
1938
+ function numberOr(value, fallback) {
1939
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
1940
+ }
1941
+ function sanitizeKey(value) {
1942
+ return value.replace(/[^A-Za-z0-9]+/g, "-");
1943
+ }
1944
+ function collisionResistantKey(value) {
1945
+ const digest = createHash("sha256").update(value).digest("hex");
1946
+ return `${sanitizeKey(value)}-${digest}`;
1947
+ }
1948
+ function transcriptPointerPath(projectDir, tmpDir) {
1949
+ return `${tmpDir}/claude-transcript-${collisionResistantKey(projectDir)}.txt`;
1950
+ }
1951
+ function legacyTranscriptPointerPath(projectDir, tmpDir) {
1952
+ return `${tmpDir}/claude-transcript-${sanitizeKey(projectDir)}.txt`;
1953
+ }
1954
+ function resolvePointer(explicitTranscriptPath, deps) {
1955
+ if (explicitTranscriptPath)
1956
+ return { path: explicitTranscriptPath, corroborated: true };
1957
+ const projectDir = deps.env.CLAUDE_PROJECT_DIR ?? deps.cwd;
1958
+ const tmpDir = deps.env.TMPDIR ?? "/tmp";
1959
+ const primaryPointerPath = transcriptPointerPath(projectDir, tmpDir);
1960
+ const legacyPointerPath = legacyTranscriptPointerPath(projectDir, tmpDir);
1961
+ const currentSessionId = deps.env.CLAUDE_CODE_SESSION_ID;
1962
+ const pointerPath = deps.exists(primaryPointerPath) ? primaryPointerPath : deps.exists(legacyPointerPath) ? legacyPointerPath : undefined;
1963
+ if (!pointerPath) {
1964
+ return {
1965
+ pointerExisted: false,
1966
+ corroborated: false,
1967
+ error: `No transcript pointer at ${primaryPointerPath} (nor its pre-migration name ${legacyPointerPath}) ` + "and no --transcript given. Either this repo installs no track-transcript.sh Stop hook (lacking one " + "is not a defect — name the transcript directly instead), or no session has completed a turn yet."
1968
+ };
1969
+ }
1970
+ let contents;
1971
+ try {
1972
+ contents = deps.readFile(pointerPath).replace(/\r?\n+$/, "");
1973
+ } catch (err) {
1974
+ return {
1975
+ pointerExisted: true,
1976
+ oursByLocation: true,
1977
+ error: `Transcript pointer at ${pointerPath} could not be read: ${err.message}. ` + "Remove that file to clear this — the Stop hook rewrites it on the next turn."
1978
+ };
1979
+ }
1980
+ const [pointerSessionId, transcriptPath] = contents.split("\t");
1981
+ if (!transcriptPath) {
1982
+ return {
1983
+ pointerExisted: true,
1984
+ oursByLocation: true,
1985
+ error: `Transcript pointer file ${pointerPath} is malformed: "${contents.slice(0, 120)}${contents.length > 120 ? "…" : ""}". ` + "Remove that file to clear this — the Stop hook rewrites it on the next turn."
1986
+ };
1987
+ }
1988
+ if (currentSessionId && pointerSessionId && currentSessionId !== pointerSessionId) {
1989
+ return {
1990
+ pointerExisted: true,
1991
+ corroborated: false,
1992
+ error: `Transcript pointer at ${pointerPath} is stale: written for session ${pointerSessionId}, ` + `but this session is ${currentSessionId}. Name your own transcript with --transcript instead of ` + "reporting another session's figures as yours."
1993
+ };
1994
+ }
1995
+ return { path: transcriptPath, corroborated: Boolean(currentSessionId && pointerSessionId) };
1996
+ }
1997
+ function resolveMeteringCapability(deps, explicitTranscriptPath) {
1998
+ const resolved = resolvePointer(explicitTranscriptPath, deps);
1999
+ if ("error" in resolved) {
2000
+ const ours = resolved.pointerExisted && (resolved.corroborated || resolved.oursByLocation);
2001
+ if (ours)
2002
+ return { capable: false, reason: "pointer-unusable", detail: resolved.error };
2003
+ return {
2004
+ capable: false,
2005
+ reason: "no-transcript-resolved",
2006
+ detail: resolved.pointerExisted ? `A transcript pointer exists but belongs to another session, so this session has no wiring of its own to use. (Underlying condition, for diagnosis only: ${resolved.error})` : resolved.error
2007
+ };
2008
+ }
2009
+ const downstream = (r, detail) => resolved.corroborated ? { reason: r, detail } : {
2010
+ reason: "no-transcript-resolved",
2011
+ detail: `A transcript pointer was found but could not be shown to belong to this session, so it is not treated as this session's wiring. (Underlying condition, for diagnosis only: ${detail})`
2012
+ };
2013
+ if (!deps.exists(resolved.path)) {
2014
+ return {
2015
+ capable: false,
2016
+ ...downstream("transcript-unreadable", `Resolved transcript path ${resolved.path} is not readable as a regular file owned by this user.`)
2017
+ };
2018
+ }
2019
+ let jsonl;
2020
+ try {
2021
+ jsonl = deps.readFile(resolved.path);
2022
+ } catch (err) {
2023
+ return {
2024
+ capable: false,
2025
+ ...downstream("transcript-unreadable", `Transcript at ${resolved.path} could not be read: ${err.message}`)
2026
+ };
2027
+ }
2028
+ const summary = summarizeTranscript(jsonl);
2029
+ if (summary.messageCount === 0) {
2030
+ return {
2031
+ capable: false,
2032
+ ...downstream("transcript-empty", `Transcript at ${resolved.path} yielded zero assistant messages with usage data — ` + "it's empty, unparseable, or not yet flushed to disk.")
2033
+ };
2034
+ }
2035
+ return { capable: true, transcriptPath: resolved.path, summary };
2036
+ }
2037
+ function isTokenCollectionWiringBroken(capability) {
2038
+ if (capability.capable)
2039
+ return false;
2040
+ return capability.reason !== "no-transcript-resolved";
2041
+ }
2042
+ // ../../packages/aeg-core/src/metering-io-guard.ts
2043
+ import { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync } from "node:fs";
2044
+ var GUARD_OPEN_FLAGS = fsConstants.O_RDONLY | fsConstants.O_NONBLOCK | fsConstants.O_NOFOLLOW;
1788
2045
  // ../../packages/aeg-core/src/file-classify.ts
1789
2046
  function isCodeFile(p) {
1790
2047
  if (p.endsWith(".md"))
@@ -1991,7 +2248,7 @@ function overrideActive(opts) {
1991
2248
  return false;
1992
2249
  }
1993
2250
  // ../../packages/aeg-core/src/premise-check.ts
1994
- import { createHash } from "node:crypto";
2251
+ import { createHash as createHash2 } from "node:crypto";
1995
2252
  var ASSERTION_KINDS = new Set(["contains", "absent", "sha256"]);
1996
2253
  function isPremiseHeader(line) {
1997
2254
  const stripped = line.replace(/[*#]/g, "").trim();
@@ -2036,7 +2293,7 @@ function checkPremises(assertions, fileReader) {
2036
2293
  } else if (a.kind === "absent" && content.includes(a.value)) {
2037
2294
  failures.push(`premise-check: ${a.path} now contains "${a.value}", but the brief pinned it absent — the premise has moved; re-dig before proceeding.`);
2038
2295
  } else if (a.kind === "sha256") {
2039
- const actual = createHash("sha256").update(content).digest("hex");
2296
+ const actual = createHash2("sha256").update(content).digest("hex");
2040
2297
  if (actual !== a.value.toLowerCase()) {
2041
2298
  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.`);
2042
2299
  }
@@ -3216,6 +3473,100 @@ function parseGlossaryTerms(glossaryContent) {
3216
3473
  }
3217
3474
  return terms;
3218
3475
  }
3476
+ // ../../packages/aeg-core/src/quoted-command.ts
3477
+ var QUOTED_COMMAND_SHIPS_PREFIX = "aeg-root/";
3478
+ var QUOTED_COMMAND_SWEPT_CLASSES = new Set(["ships", "reader-facing"]);
3479
+ var START_PATTERN = /<!--\s*AEG:QUOTES-FILE:START:(\S+?)\s*-->/g;
3480
+ var END_PATTERN = /<!--\s*AEG:QUOTES-FILE:END\s*-->/;
3481
+ function isValidCitedFilePath(path) {
3482
+ if (path.length === 0)
3483
+ return false;
3484
+ if (path.startsWith("/") || path.startsWith("\\"))
3485
+ return false;
3486
+ if (/^[A-Za-z]:[\\/]/.test(path))
3487
+ return false;
3488
+ return !path.split(/[\\/]+/).includes("..");
3489
+ }
3490
+ function quotedCommandLineAt(content, index) {
3491
+ let line = 1;
3492
+ for (let i = 0;i < index; i++) {
3493
+ if (content.charCodeAt(i) === 10)
3494
+ line++;
3495
+ }
3496
+ return line;
3497
+ }
3498
+ function extractQuotedText(raw) {
3499
+ const trimmed = raw.trim();
3500
+ const fenced = /^(?:`{3,}|~{3,})[^\n]*\n([\s\S]*?)\n?(?:`{3,}|~{3,})$/.exec(trimmed);
3501
+ if (fenced)
3502
+ return (fenced[1] ?? "").trim();
3503
+ const inline = /^`([^`]+)`$/.exec(trimmed);
3504
+ if (inline)
3505
+ return (inline[1] ?? "").trim();
3506
+ return trimmed;
3507
+ }
3508
+ function findQuotesInFile(path, content) {
3509
+ const masked = maskCode(content);
3510
+ const quotes = [];
3511
+ START_PATTERN.lastIndex = 0;
3512
+ let start = START_PATTERN.exec(masked);
3513
+ while (start !== null) {
3514
+ const citedFile = start[1];
3515
+ const innerStart = start.index + start[0].length;
3516
+ const end = END_PATTERN.exec(masked.slice(innerStart));
3517
+ if (end === null) {
3518
+ START_PATTERN.lastIndex = innerStart;
3519
+ start = START_PATTERN.exec(masked);
3520
+ continue;
3521
+ }
3522
+ const innerEnd = innerStart + end.index;
3523
+ if (isValidCitedFilePath(citedFile)) {
3524
+ const quotedText = extractQuotedText(content.slice(innerStart, innerEnd));
3525
+ if (quotedText.length > 0) {
3526
+ quotes.push({ file: path, line: quotedCommandLineAt(content, innerStart), quotedText, citedFile });
3527
+ }
3528
+ }
3529
+ START_PATTERN.lastIndex = innerEnd + end[0].length;
3530
+ start = START_PATTERN.exec(masked);
3531
+ }
3532
+ return quotes;
3533
+ }
3534
+ function findCitedQuotes(files, readerFacingPrefix, readerFacingSuffix, shipsPrefix = QUOTED_COMMAND_SHIPS_PREFIX) {
3535
+ const quotes = [];
3536
+ for (const file of files) {
3537
+ const cls = classifyProseFile(file.path, readerFacingPrefix, readerFacingSuffix, shipsPrefix);
3538
+ if (!cls || !QUOTED_COMMAND_SWEPT_CLASSES.has(cls))
3539
+ continue;
3540
+ quotes.push(...findQuotesInFile(file.path, file.content));
3541
+ }
3542
+ return quotes;
3543
+ }
3544
+ function evaluateCitedQuotes(citedQuotes, citedFileContents) {
3545
+ const findings = [];
3546
+ for (const quote of citedQuotes) {
3547
+ const content = citedFileContents.get(quote.citedFile);
3548
+ if (content === undefined) {
3549
+ findings.push({
3550
+ file: quote.file,
3551
+ line: quote.line,
3552
+ citedFile: quote.citedFile,
3553
+ quotedText: quote.quotedText,
3554
+ message: `${quote.file}:${quote.line} quotes "${quote.quotedText}" as citing \`${quote.citedFile}\`, but that file could not be read`
3555
+ });
3556
+ continue;
3557
+ }
3558
+ if (!content.includes(quote.quotedText)) {
3559
+ findings.push({
3560
+ file: quote.file,
3561
+ line: quote.line,
3562
+ citedFile: quote.citedFile,
3563
+ quotedText: quote.quotedText,
3564
+ message: `${quote.file}:${quote.line} quotes "${quote.quotedText}" as citing \`${quote.citedFile}\`, but \`${quote.citedFile}\` no longer contains that text verbatim`
3565
+ });
3566
+ }
3567
+ }
3568
+ return findings;
3569
+ }
3219
3570
  // ../../packages/aeg-core/src/retired-vocabulary.ts
3220
3571
  var RETIRED_PATTERNS = [
3221
3572
  String.raw`\bD-[0-9]{3}\b`,
@@ -3329,6 +3680,10 @@ function checkDispatchReadiness(input) {
3329
3680
  blockers.push(`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.`);
3330
3681
  }
3331
3682
  for (const dep of input.dependsOn) {
3683
+ if (dep.resolved === false) {
3684
+ blockers.push(`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.`);
3685
+ continue;
3686
+ }
3332
3687
  if (!dep.merged && !isHandClosedByRecognizedPrincipal(dep, principalAllowlist)) {
3333
3688
  const issueStr = dep.issue !== null ? ` (#${dep.issue})` : "";
3334
3689
  blockers.push(`dispatch-gate depends-on: ${taskLabel} depends on ${dep.id}${issueStr}, whose PR is not merged yet — not dispatchable, it serializes behind it.`);
@@ -3673,9 +4028,9 @@ function emitCheckError(error) {
3673
4028
 
3674
4029
  // src/lib/config.ts
3675
4030
  import { execFileSync as execFileSync2 } from "node:child_process";
3676
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4031
+ import { existsSync, mkdirSync, readFileSync as readFileSync2, realpathSync, writeFileSync } from "node:fs";
3677
4032
  import { homedir } from "node:os";
3678
- import { dirname, join } from "node:path";
4033
+ import { dirname, join, resolve } from "node:path";
3679
4034
  import { z } from "zod";
3680
4035
 
3681
4036
  // src/lib/agent-vendors.ts
@@ -3783,6 +4138,20 @@ var ManagedManifestSchema = z.object({
3783
4138
  labels: z.array(z.string()),
3784
4139
  agents: z.array(z.enum(AGENT_VENDORS)).optional()
3785
4140
  });
4141
+ var ProjectEntrySchema = z.object({
4142
+ name: z.string().min(1),
4143
+ description: z.string().min(1).optional(),
4144
+ path: z.string().min(1).optional()
4145
+ });
4146
+ function parseTokensCollectDeclaration(value) {
4147
+ const m = value.trim().match(/^(\S+)\s+(\S+)$/);
4148
+ if (!m)
4149
+ return null;
4150
+ const [, interpreter, script] = m;
4151
+ if (!isSafeRepoRelPath(script))
4152
+ return null;
4153
+ return { interpreter, script };
4154
+ }
3786
4155
  var VinayaConfigSchema = z.object({
3787
4156
  rings: z.object({
3788
4157
  ring1_forgeWriteInterception: z.boolean(),
@@ -3795,13 +4164,19 @@ var VinayaConfigSchema = z.object({
3795
4164
  principals: z.array(z.string()).min(1).optional(),
3796
4165
  releaseActor: z.string().min(1).optional(),
3797
4166
  ci: z.object({ setup: z.string().min(1) }).optional(),
4167
+ tokens: z.object({
4168
+ collect: z.string().min(1).refine((v) => parseTokensCollectDeclaration(v) !== null, {
4169
+ message: 'tokens.collect must be exactly "<interpreter> <repo-relative-script-path>" — two whitespace-separated tokens, no flags, no shell syntax, no quoting'
4170
+ })
4171
+ }).optional(),
3798
4172
  blastRadius: z.object({ extraDomains: z.array(z.string()).optional() }).optional(),
3799
4173
  proseGates: z.object({
3800
4174
  doctrineRoot: z.string().min(1).optional(),
3801
4175
  readerFacingPrefix: z.string().min(1).optional(),
3802
4176
  readerFacingSuffix: z.string().min(1).optional(),
3803
4177
  legacySlugDir: z.string().min(1).optional()
3804
- }).optional()
4178
+ }).optional(),
4179
+ projects: z.array(ProjectEntrySchema).optional()
3805
4180
  });
3806
4181
  var GLOBAL_VINAYA_HOME = join(homedir(), ".vinaya");
3807
4182
  var GLOBAL_CONFIG_PATH = join(GLOBAL_VINAYA_HOME, "config.json");
@@ -3840,6 +4215,9 @@ function globalRolesIgnoredWarning(path) {
3840
4215
  function globalReleaseActorIgnoredWarning(path) {
3841
4216
  return `${path}: "releaseActor" in the global config is ignored — releaseActor may only be declared from a repo-local vinaya.config.json.`;
3842
4217
  }
4218
+ function globalTokensCollectIgnoredWarning(path) {
4219
+ return `${path}: "tokens" in the global config is ignored — tokens.collect may only be declared from a repo-local vinaya.config.json.`;
4220
+ }
3843
4221
  function stripGlobalOnlyKeys(config, path) {
3844
4222
  if (path !== GLOBAL_CONFIG_PATH)
3845
4223
  return config;
@@ -3860,6 +4238,10 @@ function stripGlobalOnlyKeys(config, path) {
3860
4238
  console.error(`⚠ ${globalReleaseActorIgnoredWarning(path)}`);
3861
4239
  result = { ...result, releaseActor: undefined };
3862
4240
  }
4241
+ if (result.tokens) {
4242
+ console.error(`⚠ ${globalTokensCollectIgnoredWarning(path)}`);
4243
+ result = { ...result, tokens: undefined };
4244
+ }
3863
4245
  return result;
3864
4246
  }
3865
4247
  function resolvePrincipalAllowlist(config) {
@@ -3939,12 +4321,13 @@ function loadConfig() {
3939
4321
  if (!path)
3940
4322
  return null;
3941
4323
  try {
3942
- const raw = JSON.parse(readFileSync(path, "utf-8"));
4324
+ const raw = JSON.parse(readFileSync2(path, "utf-8"));
3943
4325
  return stripGlobalOnlyKeys(VinayaConfigSchema.parse(raw), path);
3944
4326
  } catch {
3945
4327
  return null;
3946
4328
  }
3947
4329
  }
4330
+ var TOKENS_COLLECT_TRUST_PATH = join(GLOBAL_VINAYA_HOME, "tokens-collect-trust.json");
3948
4331
 
3949
4332
  // src/checks/bin/check-review-gate.ts
3950
4333
  var CHECK_NAME = "review-gate";