@attalabs/vinaya 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +9 -9
  2. package/aeg-root/contracts/developer-reviewer.md +2 -2
  3. package/aeg-root/contracts/planner-developer.md +5 -5
  4. package/aeg-root/enforcement.md +22 -22
  5. package/aeg-root/process.md +4 -4
  6. package/aeg-root/roles/archivist.md +1 -1
  7. package/aeg-root/roles/developer/reference.md +7 -1
  8. package/aeg-root/roles/developer.md +1 -1
  9. package/aeg-root/roles/planner/reference.md +18 -5
  10. package/aeg-root/roles/principal.md +1 -1
  11. package/aeg-root/roles/reviewer.md +3 -3
  12. package/aeg-root/roles/security.md +4 -4
  13. package/aeg-root/roles/tranche-archivist.md +2 -2
  14. package/aeg-root/skills/aeg/SKILL.md +1 -1
  15. package/aeg-root/state-machine.md +10 -15
  16. package/aeg-root/templates/brief-template.md +5 -2
  17. package/aeg-root/templates/decision-record-template.md +38 -0
  18. package/aeg-root/templates/issue-rationale-template.md +1 -1
  19. package/aeg-root/tranche-model.md +1 -1
  20. package/dist/checks/bin/check-body-bare-digits.js +1974 -354
  21. package/dist/checks/bin/check-branch-topology.js +1296 -243
  22. package/dist/checks/bin/check-brief-shape.js +2038 -460
  23. package/dist/checks/bin/check-changeset-coverage.js +2411 -564
  24. package/dist/checks/bin/check-ci-shard-coverage.js +12391 -15
  25. package/dist/checks/bin/check-closes-n.js +1296 -243
  26. package/dist/checks/bin/check-coherence.js +1914 -1155
  27. package/dist/checks/bin/check-dead-branch-push.js +1242 -230
  28. package/dist/checks/bin/check-dispatch-readiness.js +2222 -460
  29. package/dist/checks/bin/check-doc-claims.js +2233 -260
  30. package/dist/checks/bin/check-doc-coverage-push.js +2436 -550
  31. package/dist/checks/bin/check-doc-coverage.js +2434 -552
  32. package/dist/checks/bin/check-doctrine-no-procedures.js +1776 -353
  33. package/dist/checks/bin/check-doctrine-portability.js +2408 -561
  34. package/dist/checks/bin/check-evidence-fresh.js +2370 -508
  35. package/dist/checks/bin/check-exec-bits.js +2407 -560
  36. package/dist/checks/bin/check-first-push-dispatch.js +1984 -380
  37. package/dist/checks/bin/check-issue-assignment.js +712 -170
  38. package/dist/checks/bin/check-issue-milestone-attach.js +1233 -230
  39. package/dist/checks/bin/check-issue-objectives-numbering.js +1769 -346
  40. package/dist/checks/bin/check-issue-parts-coverage.js +1233 -230
  41. package/dist/checks/bin/check-issue-surface-globs.js +1926 -378
  42. package/dist/checks/bin/check-issue-title-grammar.js +1233 -230
  43. package/dist/checks/bin/check-issue-tranche-label.js +702 -170
  44. package/dist/checks/bin/check-main-branch-refusal.js +1245 -232
  45. package/dist/checks/bin/check-no-disk-state.js +1233 -230
  46. package/dist/checks/bin/check-pr-premise-reassert.js +1769 -346
  47. package/dist/checks/bin/check-pr-report-density.js +1233 -230
  48. package/dist/checks/bin/check-principal-test-plan-wait.js +2489 -259
  49. package/dist/checks/bin/check-quoted-command.js +2391 -544
  50. package/dist/checks/bin/check-reader-resolvable-prose.js +2437 -564
  51. package/dist/checks/bin/check-registry-gates.js +1380 -296
  52. package/dist/checks/bin/check-retired-vocabulary.js +2416 -550
  53. package/dist/checks/bin/check-review-gate.js +2073 -371
  54. package/dist/checks/bin/check-single-plan-pr.js +1297 -235
  55. package/dist/checks/bin/check-surface-scope.js +1531 -252
  56. package/dist/checks/bin/check-test-plan.js +2487 -258
  57. package/dist/checks/bin/check-token-collection-wired.js +1233 -230
  58. package/dist/checks/bin/check-workspace-escape.js +2408 -561
  59. package/dist/checks/bin/verify-coherence.js +597 -97
  60. package/dist/checks/bin/verify-dispatch.js +632 -152
  61. package/dist/checks/bin/verify-docs.js +642 -132
  62. package/dist/index.js +25948 -16630
  63. package/dist/lib/pre-push-cache-test-run.js +1813 -297
  64. package/dist/lib/pre-push-changed-files.js +65 -19
  65. package/dist/lib/pre-push-mode.js +466 -0
  66. package/dist/lib/pre-push-progress-dir.js +4205 -0
  67. package/dist/lib/pre-push-record-tests.js +446 -0
  68. package/dist/lib/pre-push-select-tests.js +2353 -632
  69. package/dist/lib/push-progress-observer.js +4213 -0
  70. package/package.json +22 -5
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +17 -3
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +73 -30
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +3 -3
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/coherence-checks.ts +2 -2
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +88 -5
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +34 -2
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +26 -4
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +7 -2
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +7 -1
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +29 -3
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dispatch-gate.ts +35 -18
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +1 -1
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +70 -45
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -1
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/entry-point.ts +27 -0
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +3 -5
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +96 -9
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-assignment.ts +24 -54
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +809 -106
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/live-record.ts +179 -0
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +8 -2
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +1 -0
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/narration.ts +2 -0
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema-digest.ts +225 -0
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +7 -1
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/main-branch-refusal.ts +23 -1
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/pr-report-density.ts +6 -4
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/principals-config.ts +44 -0
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/prose-rules.ts +532 -0
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/protected-paths.ts +31 -0
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +157 -80
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +8 -12
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/retired-vocabulary.ts +53 -93
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +46 -17
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +85 -1
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +32 -13
  107. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +46 -0
  108. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-branch-identity.ts +2 -4
  109. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/test-plan-gate.ts +63 -8
  110. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +24 -0
  111. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/waiver-label.ts +0 -1
  112. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  113. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  114. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  117. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  122. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  123. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  124. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  125. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  127. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  128. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  129. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js +1 -1
  130. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  131. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js +1 -1
  134. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  145. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js +2 -2
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  156. 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
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +1 -1
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0sxadt2._.js +13 -0
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1a3j3n1._.js +57 -0
  161. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__1ug9syi._.js → [root-of-the-server]__1d4eth3._.js} +1 -1
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1snpgaw._.js +3 -3
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +2 -2
  166. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  167. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  168. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  169. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  170. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +3 -3
  171. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  172. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  173. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/node_modules_@clerk_nextjs_dist_esm_app-router_server-actions_1x7vfhn.js +2 -2
  174. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  175. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  176. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  177. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  178. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{33rszkngkuoko.js → 0x7u6si-ai179.js} +1 -1
  179. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{06_55xbp7rcbi.js → 2fu7mfsj4oima.js} +1 -1
  180. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{2brkwv169ygep.js → 34b4ruddunn3q.js} +1 -1
  181. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  182. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__04adkz-._.js +0 -57
  183. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__19jyp3m._.js +0 -13
  184. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_buildManifest.js +0 -0
  185. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_clientMiddlewareManifest.js +0 -0
  186. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{D3LiJNIq5FWZxen7CpOSJ → 2ZARxTwpuRew8-SvYsRdU}/_ssgManifest.js +0 -0
@@ -4,7 +4,7 @@
4
4
  import { execFileSync } from "node:child_process";
5
5
  import { join } from "node:path";
6
6
 
7
- // src/lib/changed-names.ts
7
+ // src/lib/verification/changed-names.ts
8
8
  var ALL_NAMES = "all";
9
9
  var PARSEABLE = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
10
10
  function namesForRanges(ts, fileName, source, ranges) {
@@ -29,6 +29,26 @@ function namesForRanges(ts, fileName, source, ranges) {
29
29
  }
30
30
  continue;
31
31
  }
32
+ if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {
33
+ const clause = statement.exportClause;
34
+ const local = statement.moduleSpecifier === undefined;
35
+ declarations.push({
36
+ name: null,
37
+ ...span,
38
+ node: statement,
39
+ exportList: {
40
+ open: lineOf(clause.getStart(sourceFile)),
41
+ close: lineOf(clause.getEnd()),
42
+ specifiers: clause.elements.map((element) => ({
43
+ exported: element.name.text,
44
+ local: local ? (element.propertyName ?? element.name).text : null,
45
+ start: lineOf(element.getStart(sourceFile)),
46
+ end: lineOf(element.getEnd())
47
+ }))
48
+ }
49
+ });
50
+ continue;
51
+ }
32
52
  const named = ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement) || ts.isInterfaceDeclaration(statement) || ts.isTypeAliasDeclaration(statement) || ts.isEnumDeclaration(statement) || ts.isModuleDeclaration(statement);
33
53
  const name = named && statement.name && ts.isIdentifier(statement.name) ? statement.name.text : null;
34
54
  declarations.push({ name, ...span, node: statement });
@@ -42,6 +62,19 @@ function namesForRanges(ts, fileName, source, ranges) {
42
62
  if (overlapping.length === 0)
43
63
  return null;
44
64
  for (const d of overlapping) {
65
+ if (d.exportList) {
66
+ const list = d.exportList;
67
+ for (let line = Math.max(range.start, d.start);line <= Math.min(range.end, d.end); line++) {
68
+ if (line <= list.open || line >= list.close)
69
+ return null;
70
+ const onLine = list.specifiers.filter((s) => s.start <= line && line <= s.end);
71
+ if (onLine.length === 0)
72
+ return null;
73
+ for (const s of onLine)
74
+ seeded.add(s.exported);
75
+ }
76
+ continue;
77
+ }
45
78
  if (d.name === null)
46
79
  return null;
47
80
  seeded.add(d.name);
@@ -60,6 +93,15 @@ function namesForRanges(ts, fileName, source, ranges) {
60
93
  ts.forEachChild(d.node, visit);
61
94
  references.set(d.name, used);
62
95
  }
96
+ for (const d of declarations) {
97
+ for (const s of d.exportList?.specifiers ?? []) {
98
+ if (s.local === null || s.local === s.exported || !topLevelNames.has(s.local))
99
+ continue;
100
+ const used = references.get(s.exported) ?? new Set;
101
+ used.add(s.local);
102
+ references.set(s.exported, used);
103
+ }
104
+ }
63
105
  const affected = new Set(seeded);
64
106
  for (let grew = true;grew; ) {
65
107
  grew = false;
@@ -123,7 +165,6 @@ function parseHunkRanges(patch) {
123
165
  }
124
166
  return { beforeRanges, afterRanges };
125
167
  }
126
-
127
168
  // src/lib/remote-base.ts
128
169
  function cleanGitEnv() {
129
170
  const env = { ...process.env };
@@ -133,7 +174,7 @@ function cleanGitEnv() {
133
174
  }
134
175
  return env;
135
176
  }
136
- function git(repoRoot, args) {
177
+ function git(repoRoot, args, failure) {
137
178
  try {
138
179
  return execFileSync("git", args, {
139
180
  cwd: repoRoot,
@@ -142,10 +183,15 @@ function git(repoRoot, args) {
142
183
  env: cleanGitEnv()
143
184
  }).trim();
144
185
  } catch {
186
+ if (failure)
187
+ failure.failed = true;
145
188
  return "";
146
189
  }
147
190
  }
148
191
  function resolveRemoteBase(repoRoot) {
192
+ const named = process.env.VINAYA_PUSH_MODE?.trim() === "ready" ? process.env.VINAYA_PUSH_BASE?.trim() : undefined;
193
+ if (named)
194
+ return named;
149
195
  const upstream = git(repoRoot, ["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]);
150
196
  if (upstream)
151
197
  return upstream;
@@ -154,35 +200,35 @@ function resolveRemoteBase(repoRoot) {
154
200
  return "origin/main";
155
201
  return "HEAD~1";
156
202
  }
157
- function changedFilesSinceRemoteBase(repoRoot, base = resolveRemoteBase(repoRoot)) {
158
- const out = git(repoRoot, ["diff", "--name-only", "--diff-filter=ACMR", `${base}...HEAD`]);
203
+ function changedFilesSinceRemoteBase(repoRoot, base = resolveRemoteBase(repoRoot), failure) {
204
+ const out = git(repoRoot, ["diff", "--name-only", "--diff-filter=ACMR", `${base}...HEAD`], failure);
159
205
  return out.split(`
160
206
  `).map((s) => s.trim()).filter(Boolean);
161
207
  }
162
- function changedFilesSinceRemoteBaseAbsolute(repoRoot, base = resolveRemoteBase(repoRoot)) {
163
- return changedFilesSinceRemoteBase(repoRoot, base).map((f) => join(repoRoot, f));
208
+ function changedFilesSinceRemoteBaseAbsolute(repoRoot, base = resolveRemoteBase(repoRoot), failure) {
209
+ return changedFilesSinceRemoteBase(repoRoot, base, failure).map((f) => join(repoRoot, f));
164
210
  }
165
- function addedOrRenamedFilesSinceRemoteBase(repoRoot, base = resolveRemoteBase(repoRoot)) {
166
- const out = git(repoRoot, ["diff", "--name-only", "--diff-filter=AR", `${base}...HEAD`]);
211
+ function addedOrRenamedFilesSinceRemoteBase(repoRoot, base = resolveRemoteBase(repoRoot), failure) {
212
+ const out = git(repoRoot, ["diff", "--name-only", "--diff-filter=AR", `${base}...HEAD`], failure);
167
213
  return out.split(`
168
214
  `).map((s) => s.trim()).filter(Boolean);
169
215
  }
170
- function addedOrRenamedFilesSinceRemoteBaseAbsolute(repoRoot, base = resolveRemoteBase(repoRoot)) {
171
- return addedOrRenamedFilesSinceRemoteBase(repoRoot, base).map((f) => join(repoRoot, f));
216
+ function addedOrRenamedFilesSinceRemoteBaseAbsolute(repoRoot, base = resolveRemoteBase(repoRoot), failure) {
217
+ return addedOrRenamedFilesSinceRemoteBase(repoRoot, base, failure).map((f) => join(repoRoot, f));
172
218
  }
173
- function removedFilesSinceRemoteBase(repoRoot, base = resolveRemoteBase(repoRoot)) {
174
- const out = git(repoRoot, ["diff", "--name-status", "--diff-filter=DR", `${base}...HEAD`]);
219
+ function removedFilesSinceRemoteBase(repoRoot, base = resolveRemoteBase(repoRoot), failure) {
220
+ const out = git(repoRoot, ["diff", "--name-status", "--diff-filter=DR", `${base}...HEAD`], failure);
175
221
  return out.split(`
176
222
  `).map((line) => line.split("\t")).filter((fields) => fields.length >= 2).map((fields) => fields[1].trim()).filter(Boolean);
177
223
  }
178
- function removedFilesSinceRemoteBaseAbsolute(repoRoot, base = resolveRemoteBase(repoRoot)) {
179
- return removedFilesSinceRemoteBase(repoRoot, base).map((f) => join(repoRoot, f));
224
+ function removedFilesSinceRemoteBaseAbsolute(repoRoot, base = resolveRemoteBase(repoRoot), failure) {
225
+ return removedFilesSinceRemoteBase(repoRoot, base, failure).map((f) => join(repoRoot, f));
180
226
  }
181
- function changedFileDiffsSinceRemoteBase(repoRoot, base = resolveRemoteBase(repoRoot)) {
182
- const mergeBase = git(repoRoot, ["merge-base", base, "HEAD"]) || base;
227
+ function changedFileDiffsSinceRemoteBase(repoRoot, base = resolveRemoteBase(repoRoot), failure) {
228
+ const mergeBase = git(repoRoot, ["merge-base", base, "HEAD"], failure) || base;
183
229
  const out = [];
184
- for (const relative of changedFilesSinceRemoteBase(repoRoot, base)) {
185
- const patch = git(repoRoot, ["diff", "-U0", `${mergeBase}..HEAD`, "--", relative]);
230
+ for (const relative of changedFilesSinceRemoteBase(repoRoot, base, failure)) {
231
+ const patch = git(repoRoot, ["diff", "-U0", `${mergeBase}..HEAD`, "--", relative], failure);
186
232
  const { beforeRanges, afterRanges } = parseHunkRanges(patch);
187
233
  out.push({
188
234
  file: join(repoRoot, relative),
@@ -0,0 +1,466 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/lib/pre-push-mode.ts
4
+ import { execFileSync as execFileSync2 } from "node:child_process";
5
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
6
+
7
+ // src/lib/pre-push-failed-tests.ts
8
+ import { execFileSync } from "node:child_process";
9
+ import { createHash } from "node:crypto";
10
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
11
+ import { dirname, isAbsolute, join } from "node:path";
12
+ var FAILED_TESTS_RECORD = "vinaya/pre-push-failed-tests.json";
13
+ var LAST_PUSH_RESULT = "vinaya/pre-push-last-result.json";
14
+ var SELECTION_NOTE = "vinaya/pre-push-selection.json";
15
+ var TEST_SELECTION_COMPLETE = "vinaya-test-selection-complete ";
16
+ function completedTestSelection(log, cwd, expected) {
17
+ const completed = new Set;
18
+ let batch = [];
19
+ let markers = 0;
20
+ const absolute = (path) => isAbsolute(path) ? path : join(cwd, path);
21
+ for (const line of log.split(`
22
+ `)) {
23
+ if (!line.startsWith(TEST_SELECTION_COMPLETE)) {
24
+ batch.push(line);
25
+ continue;
26
+ }
27
+ try {
28
+ const result = JSON.parse(line.slice(TEST_SELECTION_COMPLETE.length));
29
+ if (![0, 1].includes(result.exitCode) || !Array.isArray(result.files) || !result.files.every((file) => typeof file === "string"))
30
+ return false;
31
+ const text = batch.join(`
32
+ `);
33
+ const summary = [...text.matchAll(/^Ran \d+ tests? across (\d+) files?\.(?:.*)$/gm)].at(-1);
34
+ const headers = new Set([...text.matchAll(/^(\S.*\.test\.[a-zA-Z]+):$/gm)].map((match) => absolute(match[1])));
35
+ const files = new Set(result.files.map(absolute));
36
+ if (!summary || Number(summary[1]) !== files.size || headers.size !== files.size || [...files].some((file) => !headers.has(file)))
37
+ return false;
38
+ for (const file of files)
39
+ completed.add(file);
40
+ markers++;
41
+ batch = [];
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+ if (markers === 0 || batch.join(`
47
+ `).trim() !== "")
48
+ return false;
49
+ return expected === undefined || new Set(expected.map(absolute)).size === completed.size && expected.every((file) => completed.has(absolute(file)));
50
+ }
51
+ function parseFailedTestFiles(log, cwd, exitedNonZero, selected) {
52
+ if (exitedNonZero && !completedTestSelection(log, cwd, selected))
53
+ return "all";
54
+ const failed = new Set;
55
+ let current = null;
56
+ for (const raw of log.split(`
57
+ `)) {
58
+ const line = raw.trimEnd();
59
+ if (/^\d+ tests? failed:/.test(line)) {
60
+ current = null;
61
+ continue;
62
+ }
63
+ const header = /^(\S.*\.test\.[a-zA-Z]+):$/.exec(line);
64
+ if (header?.[1]) {
65
+ current = isAbsolute(header[1]) ? header[1] : join(cwd, header[1]);
66
+ continue;
67
+ }
68
+ if (current && (/^\(fail\) /.test(line) || line.startsWith("# Unhandled error")))
69
+ failed.add(current);
70
+ }
71
+ if (failed.size === 0)
72
+ return exitedNonZero ? "all" : [];
73
+ return [...failed].sort();
74
+ }
75
+ function chooseTests(inputs) {
76
+ const { record, head, branch, fullSelection } = inputs;
77
+ const full = {
78
+ version: 1,
79
+ mode: "full",
80
+ head,
81
+ fullCount: fullSelection.length,
82
+ selected: fullSelection
83
+ };
84
+ if (!record || record.failed === "all" || record.selectionCompleted !== true)
85
+ return full;
86
+ if (record.branch !== branch || !inputs.recordIsAncestor)
87
+ return full;
88
+ if (!record.failed.every(inputs.exists))
89
+ return full;
90
+ const rerunFailed = [...record.failed];
91
+ const affectedSince = inputs.affectedSince.filter(inputs.exists).sort();
92
+ const selected = [...new Set([...rerunFailed, ...affectedSince])].sort();
93
+ if (selected.length === 0)
94
+ return full;
95
+ return {
96
+ version: 1,
97
+ mode: "rerun",
98
+ head,
99
+ rerunOf: record.head,
100
+ recordedHead: record.head,
101
+ rerunFailed,
102
+ affectedSince,
103
+ fullCount: fullSelection.length,
104
+ selected
105
+ };
106
+ }
107
+ function recordFromRun(outcome, failed, head, branch, now) {
108
+ if (outcome === "passed")
109
+ return null;
110
+ return { version: 1, head, branch, failed, recordedAt: now.toISOString(), selectionCompleted: failed !== "all" };
111
+ }
112
+ function parseRecord(text) {
113
+ if (!text)
114
+ return null;
115
+ try {
116
+ const value = JSON.parse(text);
117
+ if (value.version !== 1 || typeof value.head !== "string" || typeof value.branch !== "string")
118
+ return null;
119
+ if (value.failed !== "all" && !Array.isArray(value.failed))
120
+ return null;
121
+ return value;
122
+ } catch {
123
+ return null;
124
+ }
125
+ }
126
+ var PASSING_RECORD_VERSION = 2;
127
+ var SELECTION_POLICY = {
128
+ name: "pre-push-since-green",
129
+ version: 1,
130
+ depth: "one",
131
+ testTimeoutMs: 30000,
132
+ rootConfigFile: "vinaya.config.json"
133
+ };
134
+ var VERIFICATION_LOCKFILES = ["bun.lock", "bun.lockb", "package-lock.json", "yarn.lock", "pnpm-lock.yaml"];
135
+ var VERIFICATION_INPUT_FILES = ["vinaya.config.json", "package.json", "bunfig.toml", ...VERIFICATION_LOCKFILES];
136
+ var VERIFICATION_ENV_KEYS = ["BUN_ENV", "CI", "NODE_ENV", "NODE_OPTIONS", "TZ"];
137
+ function parsePassingRecord(text) {
138
+ if (!text)
139
+ return null;
140
+ try {
141
+ const value = JSON.parse(text);
142
+ if (value.version !== PASSING_RECORD_VERSION || value.kind !== "passed")
143
+ return null;
144
+ if (typeof value.head !== "string" || typeof value.branch !== "string" || typeof value.context !== "string")
145
+ return null;
146
+ if (!Array.isArray(value.selection) || !value.selection.every((file) => typeof file === "string"))
147
+ return null;
148
+ return value;
149
+ } catch {
150
+ return null;
151
+ }
152
+ }
153
+ function parseSelectionNote(text, head) {
154
+ if (!text)
155
+ return null;
156
+ try {
157
+ const value = JSON.parse(text);
158
+ if (value.head !== head || !Array.isArray(value.selected))
159
+ return null;
160
+ if (!value.selected.every((file) => typeof file === "string"))
161
+ return null;
162
+ return { mode: "full", ...value };
163
+ } catch {
164
+ return null;
165
+ }
166
+ }
167
+ function passingRecordFromRun(inputs) {
168
+ const { selection, head, branch } = inputs;
169
+ if (inputs.outcome !== "passed" || !selection || selection.head !== head)
170
+ return null;
171
+ if (selection.selected.length === 0 || !head || !branch || branch === "HEAD")
172
+ return null;
173
+ if (!selection.context || inputs.context !== selection.context || inputs.inputsClean !== true)
174
+ return null;
175
+ if (!completedTestSelection(inputs.log, inputs.repoRoot, selection.selected))
176
+ return null;
177
+ return {
178
+ version: PASSING_RECORD_VERSION,
179
+ kind: "passed",
180
+ head,
181
+ branch,
182
+ selection: [...selection.selected],
183
+ selectionCompleted: true,
184
+ context: selection.context,
185
+ recordedAt: inputs.now.toISOString()
186
+ };
187
+ }
188
+ function decideSelection(deps) {
189
+ const context = deps.context !== null && deps.inputsClean === true ? deps.context : null;
190
+ const withContext = (note) => context === null ? note : { ...note, context };
191
+ const sinceGreen = deps.failed === null ? sinceGreenNote(deps, context) : null;
192
+ if (sinceGreen)
193
+ return { note: withContext(sinceGreen), full: null };
194
+ const full = deps.full();
195
+ const record = deps.failed;
196
+ const recordIsAncestor = record ? deps.isAncestor(record.head) : false;
197
+ let usable = record;
198
+ let affectedSince = [];
199
+ if (record && record.failed !== "all" && recordIsAncestor && record.branch === deps.branch) {
200
+ const changed = deps.changedBetween(record.head);
201
+ if (changed === null)
202
+ usable = null;
203
+ else
204
+ affectedSince = deps.affectedSince(changed);
205
+ }
206
+ const note = chooseTests({
207
+ record: usable,
208
+ head: deps.head,
209
+ branch: deps.branch,
210
+ recordIsAncestor,
211
+ fullSelection: full.selected,
212
+ affectedSince,
213
+ exists: deps.exists
214
+ });
215
+ return { note: withContext(note), full };
216
+ }
217
+ function sinceGreenNote(deps, context) {
218
+ const passing = deps.passing;
219
+ if (!passing || passing.selectionCompleted !== true || passing.selection.length === 0)
220
+ return null;
221
+ if (passing.branch !== deps.branch || context === null || passing.context !== context)
222
+ return null;
223
+ if (!deps.isAncestor(passing.head))
224
+ return null;
225
+ const changed = deps.changedBetween(passing.head);
226
+ if (changed === null || changed.includes(join(deps.repoRoot, SELECTION_POLICY.rootConfigFile)))
227
+ return null;
228
+ const read = deps.sinceGreen(passing.head);
229
+ if (read.readFailed)
230
+ return null;
231
+ const selected = [...new Set(read.selected)].filter(deps.exists).sort();
232
+ const affectedSince = selected.filter((file) => !deps.isAlwaysRun(file) || changed.includes(file));
233
+ if (changed.length > 0 && affectedSince.length === 0)
234
+ return null;
235
+ return {
236
+ version: 1,
237
+ mode: "since-green",
238
+ head: deps.head,
239
+ recordedHead: passing.head,
240
+ affectedSince,
241
+ fullCount: null,
242
+ selected
243
+ };
244
+ }
245
+ function cleanGitEnv() {
246
+ const env = { ...process.env };
247
+ for (const key of Object.keys(env))
248
+ if (key.startsWith("GIT_"))
249
+ delete env[key];
250
+ return env;
251
+ }
252
+ function git(repoRoot, args) {
253
+ try {
254
+ return execFileSync("git", args, {
255
+ cwd: repoRoot,
256
+ encoding: "utf8",
257
+ stdio: ["ignore", "pipe", "ignore"],
258
+ env: cleanGitEnv()
259
+ }).trim();
260
+ } catch {
261
+ return null;
262
+ }
263
+ }
264
+ function gitPath(repoRoot, name) {
265
+ const out = git(repoRoot, ["rev-parse", "--git-path", name]);
266
+ if (!out)
267
+ return null;
268
+ return isAbsolute(out) ? out : join(repoRoot, out);
269
+ }
270
+ function currentHead(repoRoot) {
271
+ return git(repoRoot, ["rev-parse", "HEAD"]) ?? "";
272
+ }
273
+ function currentBranch(repoRoot) {
274
+ return git(repoRoot, ["rev-parse", "--abbrev-ref", "HEAD"]) ?? "";
275
+ }
276
+ function isAncestor(repoRoot, ancestor, head) {
277
+ try {
278
+ execFileSync("git", ["merge-base", "--is-ancestor", ancestor, head], {
279
+ cwd: repoRoot,
280
+ stdio: "ignore",
281
+ env: cleanGitEnv()
282
+ });
283
+ return true;
284
+ } catch {
285
+ return false;
286
+ }
287
+ }
288
+ function changedBetween(repoRoot, from, to) {
289
+ const read = git(repoRoot, ["diff", "--name-only", "--diff-filter=ACMRD", from, to]);
290
+ if (read === null)
291
+ return null;
292
+ return read.split(`
293
+ `).map((s) => s.trim()).filter(Boolean).map((f) => join(repoRoot, f));
294
+ }
295
+ function readJsonUnderGit(repoRoot, name) {
296
+ const path = gitPath(repoRoot, name);
297
+ if (!path || !existsSync(path))
298
+ return null;
299
+ try {
300
+ return readFileSync(path, "utf8");
301
+ } catch {
302
+ return null;
303
+ }
304
+ }
305
+ function writeJsonUnderGit(repoRoot, name, value) {
306
+ const path = gitPath(repoRoot, name);
307
+ if (!path)
308
+ return;
309
+ mkdirSync(dirname(path), { recursive: true });
310
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}
311
+ `);
312
+ }
313
+ function removeUnderGit(repoRoot, name) {
314
+ const path = gitPath(repoRoot, name);
315
+ if (path)
316
+ rmSync(path, { force: true });
317
+ }
318
+ function readFailedTestsRecord(repoRoot) {
319
+ return parseRecord(readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD));
320
+ }
321
+ function readPassingRecord(repoRoot) {
322
+ return parsePassingRecord(readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD));
323
+ }
324
+ function clearRecordOfKind(repoRoot, kind) {
325
+ const text = readJsonUnderGit(repoRoot, FAILED_TESTS_RECORD);
326
+ const other = kind === "failed" ? parsePassingRecord(text) : parseRecord(text);
327
+ if (text !== null && other !== null)
328
+ return;
329
+ removeUnderGit(repoRoot, FAILED_TESTS_RECORD);
330
+ }
331
+ function computeVerificationContext(repoRoot, env = process.env) {
332
+ try {
333
+ const sha = (data) => createHash("sha256").update(data).digest("hex");
334
+ const read = (name) => {
335
+ const path = join(repoRoot, name);
336
+ return existsSync(path) ? readFileSync(path) : null;
337
+ };
338
+ const json = (name) => {
339
+ const bytes = read(name);
340
+ return bytes === null ? null : JSON.parse(bytes.toString("utf8"));
341
+ };
342
+ const config = json("vinaya.config.json");
343
+ const pkg = json("package.json");
344
+ const scripts = pkg?.scripts;
345
+ const bunfig = read("bunfig.toml");
346
+ const parts = {
347
+ policy: sha(JSON.stringify(SELECTION_POLICY)),
348
+ inputs: sha(JSON.stringify({ prePush: config?.prePush ?? null, workspaces: pkg?.workspaces ?? null })),
349
+ lockfile: sha(VERIFICATION_LOCKFILES.map((name) => {
350
+ const bytes = read(name);
351
+ return `${name}:${bytes === null ? "absent" : sha(bytes)}`;
352
+ }).join(`
353
+ `)),
354
+ runner: sha(JSON.stringify({
355
+ bunfig: bunfig === null ? null : sha(bunfig),
356
+ testScript: scripts?.test ?? null,
357
+ bun: process.versions.bun ?? null
358
+ })),
359
+ environment: sha(VERIFICATION_ENV_KEYS.map((key) => `${key}=${env[key] ?? "\x00unset"}`).join(`
360
+ `))
361
+ };
362
+ return { digest: sha(JSON.stringify(parts)), parts };
363
+ } catch {
364
+ return null;
365
+ }
366
+ }
367
+ function verificationInputsDirty(repoRoot) {
368
+ const out = git(repoRoot, ["status", "--porcelain", "--", ...VERIFICATION_INPUT_FILES]);
369
+ return out === null ? null : out !== "";
370
+ }
371
+
372
+ // src/lib/pre-push-mode-logic.ts
373
+ var PUSH_MODE_MARKER = "vinaya/push-mode";
374
+ function parseStorageMarker(text) {
375
+ if (!text)
376
+ return null;
377
+ try {
378
+ const value = JSON.parse(text);
379
+ if (value.version !== 1 || value.mode !== "storage")
380
+ return null;
381
+ if (typeof value.runId !== "string" || value.runId === "")
382
+ return null;
383
+ if (typeof value.branch !== "string" || value.branch === "")
384
+ return null;
385
+ if (typeof value.pid !== "number" || !Number.isInteger(value.pid) || value.pid <= 0)
386
+ return null;
387
+ return value;
388
+ } catch {
389
+ return null;
390
+ }
391
+ }
392
+ var isTaskBranch = (branch) => branch.startsWith("task/");
393
+ function resolvePushMode(input) {
394
+ const env = input.envMode?.trim();
395
+ if (env === "ready" || env === "default")
396
+ return { ok: true, mode: env };
397
+ const marker = parseStorageMarker(input.marker);
398
+ const live = marker !== null && isTaskBranch(input.branch) && marker.branch === input.branch && input.isPidAlive(marker.pid);
399
+ if (!live)
400
+ return { ok: true, mode: "default" };
401
+ let open;
402
+ try {
403
+ open = input.openPullRequests();
404
+ } catch (error) {
405
+ return {
406
+ ok: false,
407
+ reason: `a storage push runs no tests, so it must first confirm that no pull request is open for ${input.branch}, and that read failed: ${error instanceof Error ? error.message : String(error)}`
408
+ };
409
+ }
410
+ if (open > 0) {
411
+ return {
412
+ ok: false,
413
+ reason: `a pull request is open for ${input.branch}: storage pushes (no tests) are allowed only while none is open — push without the storage mode so the selected tests run`
414
+ };
415
+ }
416
+ return { ok: true, mode: "storage" };
417
+ }
418
+
419
+ // src/lib/pre-push-mode.ts
420
+ function liveOpenPullRequests(repoRoot, branch) {
421
+ const out = execFileSync2("gh", ["pr", "list", "--head", branch, "--state", "open", "--json", "number", "--jq", "length"], {
422
+ cwd: repoRoot,
423
+ encoding: "utf8",
424
+ stdio: ["ignore", "pipe", "pipe"],
425
+ timeout: 30000
426
+ });
427
+ const count = Number(out.trim());
428
+ if (!Number.isInteger(count))
429
+ throw new Error(`gh answered ${JSON.stringify(out.trim())}`);
430
+ return count;
431
+ }
432
+ function main() {
433
+ const repoRoot = process.cwd();
434
+ const markerPath = gitPath(repoRoot, PUSH_MODE_MARKER);
435
+ let marker = null;
436
+ if (markerPath && existsSync2(markerPath)) {
437
+ try {
438
+ marker = readFileSync2(markerPath, "utf8");
439
+ } catch {
440
+ marker = null;
441
+ }
442
+ }
443
+ const branch = currentBranch(repoRoot);
444
+ const resolved = resolvePushMode({
445
+ envMode: process.env.VINAYA_PUSH_MODE,
446
+ marker,
447
+ branch,
448
+ isPidAlive: (pid) => {
449
+ try {
450
+ process.kill(pid, 0);
451
+ return true;
452
+ } catch (error) {
453
+ return error.code === "EPERM";
454
+ }
455
+ },
456
+ openPullRequests: () => liveOpenPullRequests(repoRoot, branch)
457
+ });
458
+ if (!resolved.ok) {
459
+ process.stderr.write(`vinaya pre-push: refused — ${resolved.reason}
460
+ `);
461
+ process.exit(1);
462
+ }
463
+ process.stdout.write(`${resolved.mode}
464
+ `);
465
+ }
466
+ main();