@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
@@ -186,6 +186,12 @@ var NEXT_HEADER = /\*\*[A-Z][^*]*\*\*/;
186
186
  var FIELD_LABEL = /^(Depends-on|Conflicts-with)\s*:\s*(.*)$/i;
187
187
  var ID_TOKEN = /^(?:[\w.-]+\s+)?#?\d+[a-z]?$/i;
188
188
  var SLUG_QUALIFIED_ID = /^([\w.-]+)\s+(#?\d+[a-z]?)$/i;
189
+ function splitSlugQualifiedEdge(edge) {
190
+ const m = edge.trim().match(SLUG_QUALIFIED_ID);
191
+ if (!m)
192
+ return null;
193
+ return { slug: m[1], bareId: m[2] };
194
+ }
189
195
  function isEmptyMarker(s) {
190
196
  const t = s.trim();
191
197
  return t === "" || t === "—" || t === "-" || t === "–";
@@ -1782,6 +1788,257 @@ var DERIVED_STATUSES = [
1782
1788
  "incoherent"
1783
1789
  ];
1784
1790
  var DERIVABLE_STATUSES = DERIVED_STATUSES.filter((s) => s !== "backlog");
1791
+ // ../../packages/aeg-core/src/parse-ledger.ts
1792
+ function rowFromCells(cells) {
1793
+ if (cells.length < 7)
1794
+ return null;
1795
+ const phase = (cells[0] ?? "").trim();
1796
+ if (!phase)
1797
+ return null;
1798
+ return {
1799
+ phase,
1800
+ role: (cells[1] ?? "").trim(),
1801
+ agentModel: (cells[2] ?? "").trim(),
1802
+ tokensIn: parseIntCell(cells[3] ?? ""),
1803
+ tokensOut: parseIntCell(cells[4] ?? ""),
1804
+ cost: parseCostCell(cells[5] ?? ""),
1805
+ date: (cells[6] ?? "").trim()
1806
+ };
1807
+ }
1808
+ function parseIntCell(cell) {
1809
+ const trimmed = cell.replace(/`/g, "").trim();
1810
+ if (!trimmed || isEmDashOrDash(trimmed))
1811
+ return null;
1812
+ const normalized = trimmed.replace(/[,_\s]/g, "");
1813
+ if (!/^-?\d+$/.test(normalized))
1814
+ return null;
1815
+ return Number(normalized);
1816
+ }
1817
+ function parseCostCell(cell) {
1818
+ const trimmed = cell.replace(/`/g, "").trim();
1819
+ if (!trimmed || isEmDashOrDash(trimmed))
1820
+ return null;
1821
+ const normalized = trimmed.replace(/^\$/, "").replace(/[,_\s]/g, "");
1822
+ if (!/^-?\d+(\.\d+)?$/.test(normalized))
1823
+ return null;
1824
+ return Number(normalized);
1825
+ }
1826
+ function isEmDashOrDash(s) {
1827
+ const t = s.trim();
1828
+ return t === "—" || t === "-" || t === "–";
1829
+ }
1830
+ // ../../packages/aeg-core/src/parse-token-report.ts
1831
+ var TOKEN_REPORT_HEADING = /^\s*(?:#{1,6}\s*Token report\s*|\*\*Token report\*\*)\s*$/i;
1832
+ 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;
1833
+ function parseTokenReportEntries(body) {
1834
+ const lines = body.split(/\r?\n/);
1835
+ const headingIdxs = [];
1836
+ lines.forEach((line, i) => {
1837
+ if (TOKEN_REPORT_HEADING.test(line))
1838
+ headingIdxs.push(i);
1839
+ });
1840
+ const out = [];
1841
+ for (let h = 0;h < headingIdxs.length; h++) {
1842
+ const start = headingIdxs[h] + 1;
1843
+ const end = h + 1 < headingIdxs.length ? headingIdxs[h + 1] : lines.length;
1844
+ const section = lines.slice(start, end).join(`
1845
+ `);
1846
+ const tableRows = parseTableSection(section);
1847
+ if (tableRows.length > 0) {
1848
+ out.push(...tableRows);
1849
+ continue;
1850
+ }
1851
+ const inlineRow = parseInlineFieldList(section);
1852
+ if (inlineRow)
1853
+ out.push(inlineRow);
1854
+ }
1855
+ return out;
1856
+ }
1857
+ function parseTableSection(section) {
1858
+ const lines = section.split(/\r?\n/);
1859
+ let i = 0;
1860
+ for (;i < lines.length; i++) {
1861
+ if ((lines[i] ?? "").trim().startsWith("|"))
1862
+ break;
1863
+ }
1864
+ if (i + 1 >= lines.length)
1865
+ return [];
1866
+ i += 2;
1867
+ const out = [];
1868
+ for (;i < lines.length; i++) {
1869
+ const trimmed = (lines[i] ?? "").trim();
1870
+ if (!trimmed.startsWith("|"))
1871
+ break;
1872
+ const row = rowFromCells(splitTableRow(trimmed));
1873
+ if (row)
1874
+ out.push(row);
1875
+ }
1876
+ return out;
1877
+ }
1878
+ function parseInlineFieldList(section) {
1879
+ const m = section.match(INLINE_FIELD_LIST);
1880
+ if (!m)
1881
+ return null;
1882
+ return rowFromCells([m[1], m[2], m[3], m[4], m[5], m[6], m[7]]);
1883
+ }
1884
+ // ../../packages/aeg-core/src/report-tokens.ts
1885
+ var DASH_LOOKALIKES = {
1886
+ "-": "‑",
1887
+ "–": "‒",
1888
+ "—": "―"
1889
+ };
1890
+ var DASH_CHARS = new Set(Object.keys(DASH_LOOKALIKES));
1891
+ // ../../packages/aeg-core/src/claude-code-transcript.ts
1892
+ import { createHash } from "node:crypto";
1893
+ function summarizeTranscript(jsonl) {
1894
+ const seen = new Set;
1895
+ const components = {
1896
+ inputTokens: 0,
1897
+ outputTokens: 0,
1898
+ cacheCreationInputTokens: 0,
1899
+ cacheReadInputTokens: 0
1900
+ };
1901
+ let model = null;
1902
+ let messageCount = 0;
1903
+ for (const rawLine of jsonl.split(/\r?\n/)) {
1904
+ const line = rawLine.trim();
1905
+ if (!line)
1906
+ continue;
1907
+ let entry2;
1908
+ try {
1909
+ entry2 = JSON.parse(line);
1910
+ } catch {
1911
+ continue;
1912
+ }
1913
+ if (!entry2 || typeof entry2 !== "object")
1914
+ continue;
1915
+ const obj = entry2;
1916
+ if (obj.type !== "assistant")
1917
+ continue;
1918
+ const message = obj.message;
1919
+ const id = message?.id;
1920
+ const usage = message?.usage;
1921
+ if (typeof id !== "string" || !id || !usage || seen.has(id))
1922
+ continue;
1923
+ seen.add(id);
1924
+ messageCount++;
1925
+ components.inputTokens += numberOr(usage.input_tokens, 0);
1926
+ components.outputTokens += numberOr(usage.output_tokens, 0);
1927
+ components.cacheCreationInputTokens += numberOr(usage.cache_creation_input_tokens, 0);
1928
+ components.cacheReadInputTokens += numberOr(usage.cache_read_input_tokens, 0);
1929
+ const messageModel = message?.model;
1930
+ if (typeof messageModel === "string" && messageModel)
1931
+ model = messageModel;
1932
+ }
1933
+ return { components, model, messageCount };
1934
+ }
1935
+ function numberOr(value, fallback) {
1936
+ return typeof value === "number" && Number.isFinite(value) ? value : fallback;
1937
+ }
1938
+ function sanitizeKey(value) {
1939
+ return value.replace(/[^A-Za-z0-9]+/g, "-");
1940
+ }
1941
+ function collisionResistantKey(value) {
1942
+ const digest = createHash("sha256").update(value).digest("hex");
1943
+ return `${sanitizeKey(value)}-${digest}`;
1944
+ }
1945
+ function transcriptPointerPath(projectDir, tmpDir) {
1946
+ return `${tmpDir}/claude-transcript-${collisionResistantKey(projectDir)}.txt`;
1947
+ }
1948
+ function legacyTranscriptPointerPath(projectDir, tmpDir) {
1949
+ return `${tmpDir}/claude-transcript-${sanitizeKey(projectDir)}.txt`;
1950
+ }
1951
+ function resolvePointer(explicitTranscriptPath, deps) {
1952
+ if (explicitTranscriptPath)
1953
+ return { path: explicitTranscriptPath, corroborated: true };
1954
+ const projectDir = deps.env.CLAUDE_PROJECT_DIR ?? deps.cwd;
1955
+ const tmpDir = deps.env.TMPDIR ?? "/tmp";
1956
+ const primaryPointerPath = transcriptPointerPath(projectDir, tmpDir);
1957
+ const legacyPointerPath = legacyTranscriptPointerPath(projectDir, tmpDir);
1958
+ const currentSessionId = deps.env.CLAUDE_CODE_SESSION_ID;
1959
+ const pointerPath = deps.exists(primaryPointerPath) ? primaryPointerPath : deps.exists(legacyPointerPath) ? legacyPointerPath : undefined;
1960
+ if (!pointerPath) {
1961
+ return {
1962
+ pointerExisted: false,
1963
+ corroborated: false,
1964
+ 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."
1965
+ };
1966
+ }
1967
+ let contents;
1968
+ try {
1969
+ contents = deps.readFile(pointerPath).replace(/\r?\n+$/, "");
1970
+ } catch (err) {
1971
+ return {
1972
+ pointerExisted: true,
1973
+ oursByLocation: true,
1974
+ 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."
1975
+ };
1976
+ }
1977
+ const [pointerSessionId, transcriptPath] = contents.split("\t");
1978
+ if (!transcriptPath) {
1979
+ return {
1980
+ pointerExisted: true,
1981
+ oursByLocation: true,
1982
+ 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."
1983
+ };
1984
+ }
1985
+ if (currentSessionId && pointerSessionId && currentSessionId !== pointerSessionId) {
1986
+ return {
1987
+ pointerExisted: true,
1988
+ corroborated: false,
1989
+ 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."
1990
+ };
1991
+ }
1992
+ return { path: transcriptPath, corroborated: Boolean(currentSessionId && pointerSessionId) };
1993
+ }
1994
+ function resolveMeteringCapability(deps, explicitTranscriptPath) {
1995
+ const resolved = resolvePointer(explicitTranscriptPath, deps);
1996
+ if ("error" in resolved) {
1997
+ const ours = resolved.pointerExisted && (resolved.corroborated || resolved.oursByLocation);
1998
+ if (ours)
1999
+ return { capable: false, reason: "pointer-unusable", detail: resolved.error };
2000
+ return {
2001
+ capable: false,
2002
+ reason: "no-transcript-resolved",
2003
+ 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
2004
+ };
2005
+ }
2006
+ const downstream = (r, detail) => resolved.corroborated ? { reason: r, detail } : {
2007
+ reason: "no-transcript-resolved",
2008
+ 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})`
2009
+ };
2010
+ if (!deps.exists(resolved.path)) {
2011
+ return {
2012
+ capable: false,
2013
+ ...downstream("transcript-unreadable", `Resolved transcript path ${resolved.path} is not readable as a regular file owned by this user.`)
2014
+ };
2015
+ }
2016
+ let jsonl;
2017
+ try {
2018
+ jsonl = deps.readFile(resolved.path);
2019
+ } catch (err) {
2020
+ return {
2021
+ capable: false,
2022
+ ...downstream("transcript-unreadable", `Transcript at ${resolved.path} could not be read: ${err.message}`)
2023
+ };
2024
+ }
2025
+ const summary = summarizeTranscript(jsonl);
2026
+ if (summary.messageCount === 0) {
2027
+ return {
2028
+ capable: false,
2029
+ ...downstream("transcript-empty", `Transcript at ${resolved.path} yielded zero assistant messages with usage data — ` + "it's empty, unparseable, or not yet flushed to disk.")
2030
+ };
2031
+ }
2032
+ return { capable: true, transcriptPath: resolved.path, summary };
2033
+ }
2034
+ function isTokenCollectionWiringBroken(capability) {
2035
+ if (capability.capable)
2036
+ return false;
2037
+ return capability.reason !== "no-transcript-resolved";
2038
+ }
2039
+ // ../../packages/aeg-core/src/metering-io-guard.ts
2040
+ import { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync } from "node:fs";
2041
+ var GUARD_OPEN_FLAGS = fsConstants.O_RDONLY | fsConstants.O_NONBLOCK | fsConstants.O_NOFOLLOW;
1785
2042
  // ../../packages/aeg-core/src/file-classify.ts
1786
2043
  function isCodeFile(p) {
1787
2044
  if (p.endsWith(".md"))
@@ -1988,7 +2245,7 @@ function overrideActive(opts) {
1988
2245
  return false;
1989
2246
  }
1990
2247
  // ../../packages/aeg-core/src/premise-check.ts
1991
- import { createHash } from "node:crypto";
2248
+ import { createHash as createHash2 } from "node:crypto";
1992
2249
  var ASSERTION_KINDS = new Set(["contains", "absent", "sha256"]);
1993
2250
  function isPremiseHeader(line) {
1994
2251
  const stripped = line.replace(/[*#]/g, "").trim();
@@ -2033,7 +2290,7 @@ function checkPremises(assertions, fileReader) {
2033
2290
  } else if (a.kind === "absent" && content.includes(a.value)) {
2034
2291
  failures.push(`premise-check: ${a.path} now contains "${a.value}", but the brief pinned it absent — the premise has moved; re-dig before proceeding.`);
2035
2292
  } else if (a.kind === "sha256") {
2036
- const actual = createHash("sha256").update(content).digest("hex");
2293
+ const actual = createHash2("sha256").update(content).digest("hex");
2037
2294
  if (actual !== a.value.toLowerCase()) {
2038
2295
  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.`);
2039
2296
  }
@@ -3213,6 +3470,100 @@ function parseGlossaryTerms(glossaryContent) {
3213
3470
  }
3214
3471
  return terms;
3215
3472
  }
3473
+ // ../../packages/aeg-core/src/quoted-command.ts
3474
+ var QUOTED_COMMAND_SHIPS_PREFIX = "aeg-root/";
3475
+ var QUOTED_COMMAND_SWEPT_CLASSES = new Set(["ships", "reader-facing"]);
3476
+ var START_PATTERN = /<!--\s*AEG:QUOTES-FILE:START:(\S+?)\s*-->/g;
3477
+ var END_PATTERN = /<!--\s*AEG:QUOTES-FILE:END\s*-->/;
3478
+ function isValidCitedFilePath(path) {
3479
+ if (path.length === 0)
3480
+ return false;
3481
+ if (path.startsWith("/") || path.startsWith("\\"))
3482
+ return false;
3483
+ if (/^[A-Za-z]:[\\/]/.test(path))
3484
+ return false;
3485
+ return !path.split(/[\\/]+/).includes("..");
3486
+ }
3487
+ function quotedCommandLineAt(content, index) {
3488
+ let line = 1;
3489
+ for (let i = 0;i < index; i++) {
3490
+ if (content.charCodeAt(i) === 10)
3491
+ line++;
3492
+ }
3493
+ return line;
3494
+ }
3495
+ function extractQuotedText(raw) {
3496
+ const trimmed = raw.trim();
3497
+ const fenced = /^(?:`{3,}|~{3,})[^\n]*\n([\s\S]*?)\n?(?:`{3,}|~{3,})$/.exec(trimmed);
3498
+ if (fenced)
3499
+ return (fenced[1] ?? "").trim();
3500
+ const inline = /^`([^`]+)`$/.exec(trimmed);
3501
+ if (inline)
3502
+ return (inline[1] ?? "").trim();
3503
+ return trimmed;
3504
+ }
3505
+ function findQuotesInFile(path, content) {
3506
+ const masked = maskCode(content);
3507
+ const quotes = [];
3508
+ START_PATTERN.lastIndex = 0;
3509
+ let start = START_PATTERN.exec(masked);
3510
+ while (start !== null) {
3511
+ const citedFile = start[1];
3512
+ const innerStart = start.index + start[0].length;
3513
+ const end = END_PATTERN.exec(masked.slice(innerStart));
3514
+ if (end === null) {
3515
+ START_PATTERN.lastIndex = innerStart;
3516
+ start = START_PATTERN.exec(masked);
3517
+ continue;
3518
+ }
3519
+ const innerEnd = innerStart + end.index;
3520
+ if (isValidCitedFilePath(citedFile)) {
3521
+ const quotedText = extractQuotedText(content.slice(innerStart, innerEnd));
3522
+ if (quotedText.length > 0) {
3523
+ quotes.push({ file: path, line: quotedCommandLineAt(content, innerStart), quotedText, citedFile });
3524
+ }
3525
+ }
3526
+ START_PATTERN.lastIndex = innerEnd + end[0].length;
3527
+ start = START_PATTERN.exec(masked);
3528
+ }
3529
+ return quotes;
3530
+ }
3531
+ function findCitedQuotes(files, readerFacingPrefix, readerFacingSuffix, shipsPrefix = QUOTED_COMMAND_SHIPS_PREFIX) {
3532
+ const quotes = [];
3533
+ for (const file of files) {
3534
+ const cls = classifyProseFile(file.path, readerFacingPrefix, readerFacingSuffix, shipsPrefix);
3535
+ if (!cls || !QUOTED_COMMAND_SWEPT_CLASSES.has(cls))
3536
+ continue;
3537
+ quotes.push(...findQuotesInFile(file.path, file.content));
3538
+ }
3539
+ return quotes;
3540
+ }
3541
+ function evaluateCitedQuotes(citedQuotes, citedFileContents) {
3542
+ const findings = [];
3543
+ for (const quote of citedQuotes) {
3544
+ const content = citedFileContents.get(quote.citedFile);
3545
+ if (content === undefined) {
3546
+ findings.push({
3547
+ file: quote.file,
3548
+ line: quote.line,
3549
+ citedFile: quote.citedFile,
3550
+ quotedText: quote.quotedText,
3551
+ message: `${quote.file}:${quote.line} quotes "${quote.quotedText}" as citing \`${quote.citedFile}\`, but that file could not be read`
3552
+ });
3553
+ continue;
3554
+ }
3555
+ if (!content.includes(quote.quotedText)) {
3556
+ findings.push({
3557
+ file: quote.file,
3558
+ line: quote.line,
3559
+ citedFile: quote.citedFile,
3560
+ quotedText: quote.quotedText,
3561
+ message: `${quote.file}:${quote.line} quotes "${quote.quotedText}" as citing \`${quote.citedFile}\`, but \`${quote.citedFile}\` no longer contains that text verbatim`
3562
+ });
3563
+ }
3564
+ }
3565
+ return findings;
3566
+ }
3216
3567
  // ../../packages/aeg-core/src/retired-vocabulary.ts
3217
3568
  var RETIRED_PATTERNS = [
3218
3569
  String.raw`\bD-[0-9]{3}\b`,
@@ -3326,6 +3677,10 @@ function checkDispatchReadiness(input) {
3326
3677
  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.`);
3327
3678
  }
3328
3679
  for (const dep of input.dependsOn) {
3680
+ if (dep.resolved === false) {
3681
+ 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.`);
3682
+ continue;
3683
+ }
3329
3684
  if (!dep.merged && !isHandClosedByRecognizedPrincipal(dep, principalAllowlist)) {
3330
3685
  const issueStr = dep.issue !== null ? ` (#${dep.issue})` : "";
3331
3686
  blockers.push(`dispatch-gate depends-on: ${taskLabel} depends on ${dep.id}${issueStr}, whose PR is not merged yet — not dispatchable, it serializes behind it.`);