@attalabs/vinaya 0.33.0 → 0.34.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 (131) hide show
  1. package/aeg-root/enforcement.md +1 -1
  2. package/aeg-root/glossary.md +4 -0
  3. package/aeg-root/roles/developer.md +3 -0
  4. package/aeg-root/roles/operator.md +30 -10
  5. package/aeg-root/roles/planner/reference.md +2 -1
  6. package/aeg-root/roles/planner.md +3 -1
  7. package/aeg-root/templates/brief-template.md +9 -7
  8. package/aeg-root/templates/pr-report-template.md +3 -1
  9. package/dist/checks/bin/check-body-bare-digits.js +102 -26
  10. package/dist/checks/bin/check-branch-topology.js +81 -25
  11. package/dist/checks/bin/check-brief-shape.js +108 -31
  12. package/dist/checks/bin/check-changeset-coverage.js +331 -87
  13. package/dist/checks/bin/check-closes-n.js +81 -25
  14. package/dist/checks/bin/check-coherence.js +108 -27
  15. package/dist/checks/bin/check-dead-branch-push.js +77 -25
  16. package/dist/checks/bin/check-dispatch-readiness.js +106 -26
  17. package/dist/checks/bin/check-doc-coverage-push.js +327 -83
  18. package/dist/checks/bin/check-doc-coverage.js +329 -85
  19. package/dist/checks/bin/check-doctrine-no-procedures.js +102 -26
  20. package/dist/checks/bin/check-doctrine-portability.js +328 -84
  21. package/dist/checks/bin/check-evidence-fresh.js +300 -56
  22. package/dist/checks/bin/check-exec-bits.js +325 -81
  23. package/dist/checks/bin/check-first-push-dispatch.js +106 -26
  24. package/dist/checks/bin/check-issue-assignment.js +81 -25
  25. package/dist/checks/bin/check-issue-milestone-attach.js +77 -25
  26. package/dist/checks/bin/check-issue-objectives-numbering.js +603 -26
  27. package/dist/checks/bin/check-issue-parts-coverage.js +77 -25
  28. package/dist/checks/bin/check-issue-surface-globs.js +146 -32
  29. package/dist/checks/bin/check-issue-title-grammar.js +77 -25
  30. package/dist/checks/bin/check-issue-tranche-label.js +77 -25
  31. package/dist/checks/bin/check-main-branch-refusal.js +77 -25
  32. package/dist/checks/bin/check-no-disk-state.js +77 -25
  33. package/dist/checks/bin/check-pr-premise-reassert.js +102 -26
  34. package/dist/checks/bin/check-pr-report-density.js +77 -25
  35. package/dist/checks/bin/check-principal-test-plan-wait.js +77 -25
  36. package/dist/checks/bin/check-quoted-command.js +244 -34
  37. package/dist/checks/bin/check-reader-resolvable-prose.js +295 -42
  38. package/dist/checks/bin/check-registry-gates.js +77 -25
  39. package/dist/checks/bin/check-retired-vocabulary.js +244 -34
  40. package/dist/checks/bin/check-review-gate.js +106 -29
  41. package/dist/checks/bin/check-single-plan-pr.js +77 -25
  42. package/dist/checks/bin/check-surface-scope.js +81 -25
  43. package/dist/checks/bin/check-test-plan.js +77 -25
  44. package/dist/checks/bin/check-token-collection-wired.js +77 -25
  45. package/dist/checks/bin/check-token-report.js +77 -25
  46. package/dist/checks/bin/check-workspace-escape.js +326 -82
  47. package/dist/index.js +2862 -1953
  48. package/dist/lib/pre-push-cache-test-run.js +190 -11
  49. package/dist/lib/pre-push-select-tests.js +45 -3
  50. package/package.json +1 -1
  51. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/migration.ts +13 -3
  52. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +5 -2
  53. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +116 -20
  54. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +72 -2
  55. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +48 -2
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-gate.ts +18 -3
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +24 -0
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +15 -10
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/ruling-ordinal.ts +16 -0
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +194 -0
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +276 -52
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/verdict-extraction.ts +62 -8
  63. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  64. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  65. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  66. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  67. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  68. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  69. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  70. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  71. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  72. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  73. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  74. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  75. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  76. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/api/coherence/route.js.nft.json +1 -1
  77. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  78. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  79. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  80. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  81. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  82. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  83. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  84. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  85. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  86. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  87. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  88. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  89. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  90. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  91. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  92. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  93. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  94. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  95. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  96. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  97. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  98. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  99. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  100. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  101. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/[root-of-the-server]__02a-3g8._.js +4 -4
  102. 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
  103. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__074w9nf._.js +1 -1
  104. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__18paley._.js → [root-of-the-server]__07uhu5z._.js} +1 -1
  105. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  106. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  107. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  108. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
  109. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  110. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  111. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  112. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  113. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  114. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_15gdg48._.js +1 -1
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  117. 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
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  122. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0ko698wh8xx2g.css +1 -0
  123. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{1ce2dj27_cgbj.js → 0q9p7c6vn-x2w.js} +1 -1
  124. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{22s44f5k3ecmj.js → 2174nz5he_oc4.js} +1 -1
  125. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{34hhdtbp20krb.js → 3xnma0-359j17.js} +1 -1
  126. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  127. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0bm4nrrzwc7zi.css +0 -1
  128. /package/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/vinaya/studio-standalone/_node_modules/@attalabs/{aeg-core → vinaya/studio-standalone/_node_modules/@attalabs/aeg-core}/bin/verify-coherence.ts +0 -0
  129. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → HmoeqXdX1E4drt7GReFOO}/_buildManifest.js +0 -0
  130. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → HmoeqXdX1E4drt7GReFOO}/_clientMiddlewareManifest.js +0 -0
  131. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{vl7QVqELe1AQ-9kaOd9mR → HmoeqXdX1E4drt7GReFOO}/_ssgManifest.js +0 -0
@@ -234,6 +234,33 @@ function entry(key) {
234
234
  function label(key) {
235
235
  return entry(key).id;
236
236
  }
237
+ function trancheSlugOf(name) {
238
+ const prefix = entry("tranche").id;
239
+ return name.startsWith(prefix) ? name.slice(prefix.length) : null;
240
+ }
241
+ function findTrancheSlug(names) {
242
+ for (const n of names) {
243
+ const slug = trancheSlugOf(n);
244
+ if (slug !== null)
245
+ return slug;
246
+ }
247
+ return null;
248
+ }
249
+
250
+ // ../../packages/aeg-forge-state/src/list-tasks.ts
251
+ var TITLE_PATTERN = /^\[([^\]]+)]\s*(\S+)\s*—\s*(.+)$/;
252
+ function resolveTaskIssueRef(title, labels) {
253
+ const m = title.match(TITLE_PATTERN);
254
+ if (!m)
255
+ return null;
256
+ const taskId = (m[2] ?? "").trim();
257
+ if (!taskId)
258
+ return null;
259
+ const trancheSlug = findTrancheSlug(labels);
260
+ if (!trancheSlug)
261
+ return null;
262
+ return { trancheSlug, taskId };
263
+ }
237
264
  // ../../packages/aeg-forge-state/src/github-token.ts
238
265
  import { execFile as execFile2 } from "node:child_process";
239
266
  import { promisify as promisify2 } from "node:util";
@@ -552,7 +579,8 @@ var TaskStatusItemSchema = z.object({
552
579
  }).merge(ObservedSchema);
553
580
  var TaskStatusResultSchema = z.object({
554
581
  items: z.array(TaskStatusItemSchema),
555
- nextCursor: z.string().nullable()
582
+ nextCursor: z.string().nullable(),
583
+ table: z.string()
556
584
  });
557
585
  var RequestedAuthoritySchema = z.enum(["planner", "principal", "operator", "self"]);
558
586
  var EscalationInputsSchema = z.object({
@@ -1123,6 +1151,8 @@ function attemptFromEnv(value) {
1123
1151
  function provenanceFor(input) {
1124
1152
  if (input.provenance)
1125
1153
  return input.provenance;
1154
+ if (issueFromTask(input.env.task) === null && (input.branchIssue ?? null) !== null)
1155
+ return "unavailable";
1126
1156
  if (input.env.role || input.env.task)
1127
1157
  return "env_correlated";
1128
1158
  return "unavailable";
@@ -1143,7 +1173,7 @@ function buildHeader(input) {
1143
1173
  const role = isRole(input.env.role) ? input.env.role : "unattributed";
1144
1174
  const round = roundFromEnv(input.env.round);
1145
1175
  const subject = {
1146
- issue: issueFromTask(input.env.task),
1176
+ issue: issueFromTask(input.env.task) ?? input.branchIssue ?? null,
1147
1177
  role,
1148
1178
  ...round !== undefined ? { round } : {},
1149
1179
  ...input.subject ?? {}
@@ -2262,7 +2292,12 @@ var VinayaConfigSchema = z4.object({
2262
2292
  allowlist: z4.array(z4.string().min(1)).optional(),
2263
2293
  severity: z4.enum(["warning", "error"]).optional()
2264
2294
  }).optional(),
2265
- specGrandfather: z4.array(z4.string().min(1)).optional()
2295
+ specGrandfather: z4.array(z4.string().min(1)).optional(),
2296
+ specPaths: z4.array(z4.string().min(1).refine((entry) => !entry.startsWith("/") && !/^[A-Za-z]:/.test(entry), {
2297
+ message: "must be a repository-relative path, not an absolute one"
2298
+ }).refine((entry) => !entry.split(/[\\/]/).includes(".."), {
2299
+ message: "must stay inside the repository — no `..` segment"
2300
+ })).optional()
2266
2301
  }).optional(),
2267
2302
  projects: z4.array(ProjectEntrySchema).optional(),
2268
2303
  dispatch: z4.object({
@@ -2276,6 +2311,13 @@ var VinayaConfigSchema = z4.object({
2276
2311
  securityThreshold: z4.string().min(1).optional(),
2277
2312
  maxRounds: z4.number().optional()
2278
2313
  }).optional(),
2314
+ gateCutovers: z4.object({
2315
+ objectivesSinceIssue: z4.number().int().nonnegative().optional(),
2316
+ briefSectionsSinceIssue: z4.number().int().nonnegative().optional(),
2317
+ documentationSinceIssue: z4.number().int().nonnegative().optional(),
2318
+ briefRulesSincePr: z4.number().int().nonnegative().optional(),
2319
+ agentBoxesRefusedSincePr: z4.number().int().nonnegative().optional()
2320
+ }).optional(),
2279
2321
  prePush: z4.object({
2280
2322
  alwaysRun: z4.array(z4.string()).optional()
2281
2323
  }).optional(),
@@ -3191,6 +3233,96 @@ async function resolveDoctrine(cwd, vinayaVersion) {
3191
3233
  return vinayaVersion;
3192
3234
  }
3193
3235
  }
3236
+ var TRANCHE_SLUG_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
3237
+ function taskRefFromBranch2(branch) {
3238
+ const backlog = /^task\/issue-(\d+)$/.exec(branch);
3239
+ if (backlog) {
3240
+ const issue = Number(backlog[1]);
3241
+ return Number.isSafeInteger(issue) && issue > 0 ? { kind: "issue", issue } : null;
3242
+ }
3243
+ const tranche = /^task\/([^/]+)\/([^/]+)$/.exec(branch);
3244
+ if (tranche && TRANCHE_SLUG_PATTERN.test(tranche[1] ?? "")) {
3245
+ return { kind: "tranche", tranche: tranche[1], taskId: tranche[2] };
3246
+ }
3247
+ return null;
3248
+ }
3249
+ var TRANCHE_ISSUE_LIST_LIMIT = 200;
3250
+ async function issueForTrancheTask(tranche, taskId, cwd, repo) {
3251
+ let stdout;
3252
+ try {
3253
+ ({ stdout } = await execFileAsync5("gh", [
3254
+ "issue",
3255
+ "list",
3256
+ "--state",
3257
+ "all",
3258
+ "--label",
3259
+ `vinaya/tranche:${tranche}`,
3260
+ "--json",
3261
+ "number,title,labels",
3262
+ "--limit",
3263
+ String(TRANCHE_ISSUE_LIST_LIMIT),
3264
+ ...repo === null ? [] : ["--repo", repo]
3265
+ ], {
3266
+ cwd,
3267
+ encoding: "utf8",
3268
+ maxBuffer: 8 * 1024 * 1024,
3269
+ timeout: LOG_CONTEXT_LOOKUP_DEADLINE_MS,
3270
+ killSignal: "SIGKILL"
3271
+ }));
3272
+ } catch {
3273
+ return null;
3274
+ }
3275
+ let issues;
3276
+ try {
3277
+ issues = JSON.parse(stdout);
3278
+ } catch {
3279
+ return null;
3280
+ }
3281
+ for (const issue of issues) {
3282
+ const ref = resolveTaskIssueRef(issue.title, issue.labels.map((l) => l.name));
3283
+ if (ref && ref.trancheSlug === tranche && ref.taskId === taskId)
3284
+ return issue.number;
3285
+ }
3286
+ return null;
3287
+ }
3288
+ async function confirmBacklogIssue(issue, cwd, repo) {
3289
+ let stdout;
3290
+ try {
3291
+ ({ stdout } = await execFileAsync5("gh", ["issue", "view", String(issue), "--json", "number", ...repo === null ? [] : ["--repo", repo]], {
3292
+ cwd,
3293
+ encoding: "utf8",
3294
+ timeout: LOG_CONTEXT_LOOKUP_DEADLINE_MS,
3295
+ killSignal: "SIGKILL"
3296
+ }));
3297
+ } catch (err) {
3298
+ const stderr = typeof err.stderr === "string" ? err.stderr : "";
3299
+ return /could not resolve|not found|no such|does not exist/i.test(stderr) ? "denied" : "unknown";
3300
+ }
3301
+ try {
3302
+ return JSON.parse(stdout).number === issue ? "confirmed" : "denied";
3303
+ } catch {
3304
+ return "unknown";
3305
+ }
3306
+ }
3307
+ async function resolveBranchIssue(cwd, env = process.env, repo = null) {
3308
+ let branch;
3309
+ try {
3310
+ branch = (await execFileAsync5("git", ["-C", cwd, "rev-parse", "--abbrev-ref", "HEAD"], {
3311
+ encoding: "utf8",
3312
+ timeout: LOG_CONTEXT_LOOKUP_DEADLINE_MS,
3313
+ killSignal: "SIGKILL"
3314
+ })).stdout.trim();
3315
+ } catch {
3316
+ return null;
3317
+ }
3318
+ const named = branch === "HEAD" ? env.GITHUB_HEAD_REF ?? "" : branch;
3319
+ const ref = taskRefFromBranch2(named);
3320
+ if (ref === null)
3321
+ return null;
3322
+ if (ref.kind === "tranche")
3323
+ return await issueForTrancheTask(ref.tranche, ref.taskId, cwd, repo);
3324
+ return await confirmBacklogIssue(ref.issue, cwd, repo) === "denied" ? null : ref.issue;
3325
+ }
3194
3326
  function readVinayaVersion() {
3195
3327
  try {
3196
3328
  const pkg = JSON.parse(readFileSync5(join7(packageRoot(import.meta.url), "package.json"), "utf8"));
@@ -3203,6 +3335,11 @@ var SAFE_PATH_SEGMENT3 = /^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/;
3203
3335
  function isSafeRepoSegment3(segment) {
3204
3336
  return SAFE_PATH_SEGMENT3.test(segment) && !segment.includes("..");
3205
3337
  }
3338
+ function safeRepoSlug(repo) {
3339
+ if (repo === null)
3340
+ return null;
3341
+ return isSafeRepoSegment3(repo.owner) && isSafeRepoSegment3(repo.repo) ? `${repo.owner}/${repo.repo}` : null;
3342
+ }
3206
3343
  function outboxPathFor(deps, repo, issue) {
3207
3344
  const dirName = repo ? `${repo.owner}-${repo.repo}` : "unresolved";
3208
3345
  const fileName = `${issue ?? "none"}.ndjson`;
@@ -3224,6 +3361,18 @@ function defaultStderr(message) {
3224
3361
  warnedThisProcess = true;
3225
3362
  process.stderr.write(message);
3226
3363
  }
3364
+ var branchIssueFallbackEnabled = true;
3365
+ var branchIssueByCwd = new Map;
3366
+ function branchIssueRead(key, read, shared) {
3367
+ if (!shared)
3368
+ return withDeadline(Promise.resolve().then(read), LOG_CONTEXT_LOOKUP_DEADLINE_MS, null);
3369
+ const cached = branchIssueByCwd.get(key);
3370
+ if (cached !== undefined)
3371
+ return cached;
3372
+ const reading = withDeadline(Promise.resolve().then(read), LOG_CONTEXT_LOOKUP_DEADLINE_MS, null);
3373
+ branchIssueByCwd.set(key, reading);
3374
+ return reading;
3375
+ }
3227
3376
  function defaultDeps() {
3228
3377
  return {
3229
3378
  outboxRoot: () => join7(GLOBAL_VINAYA_HOME, "outbox"),
@@ -3334,7 +3483,11 @@ function appendLine(path, line, warn) {
3334
3483
  }
3335
3484
  }
3336
3485
  function createLogSink(overrides = {}) {
3337
- const deps = { ...defaultDeps(), ...overrides };
3486
+ const deps = {
3487
+ ...defaultDeps(),
3488
+ resolveBranchIssue: (repo) => resolveBranchIssue(deps.cwd(), deps.env(), repo),
3489
+ ...overrides
3490
+ };
3338
3491
  const runId = deps.env().VINAYA_RUN_ID || randomUUID2();
3339
3492
  const processId = randomUUID2();
3340
3493
  let seq = 0;
@@ -3354,6 +3507,19 @@ function createLogSink(overrides = {}) {
3354
3507
  }
3355
3508
  return doctrineCache;
3356
3509
  };
3510
+ const readerIsReal = overrides.resolveBranchIssue === undefined;
3511
+ let ownBranchIssue;
3512
+ const branchIssueOnce = (repo) => {
3513
+ if (!branchIssueFallbackEnabled)
3514
+ return Promise.resolve(null);
3515
+ const slug = safeRepoSlug(repo);
3516
+ const read = () => deps.resolveBranchIssue(slug);
3517
+ if (readerIsReal)
3518
+ return branchIssueRead(`${deps.cwd()}\x00${slug ?? ""}`, read, true);
3519
+ if (ownBranchIssue === undefined)
3520
+ ownBranchIssue = branchIssueRead(deps.cwd(), read, false);
3521
+ return ownBranchIssue;
3522
+ };
3357
3523
  let resolveRepoCache;
3358
3524
  const resolveRepoOnce = () => {
3359
3525
  if (resolveRepoCache === undefined)
@@ -3376,6 +3542,7 @@ function createLogSink(overrides = {}) {
3376
3542
  };
3377
3543
  let drainChain = Promise.resolve();
3378
3544
  const pendingWrites = new Set;
3545
+ let writeChain = Promise.resolve();
3379
3546
  const scheduleWebhookDrain = (issue, url, headers) => {
3380
3547
  drainChain = drainChain.then(() => drainOutboxToWebhook(issue, url, headers)).then(() => {
3381
3548
  return;
@@ -3398,7 +3565,14 @@ function createLogSink(overrides = {}) {
3398
3565
  attempt: env.VINAYA_ATTEMPT,
3399
3566
  parent: env.VINAYA_PARENT_EVENT
3400
3567
  };
3401
- const written = context().then(({ repo, doctrine: doctrineValue, destination: resolvedDestination }) => {
3568
+ const write = async () => {
3569
+ const { repo, doctrine: doctrineValue, destination: resolvedDestination } = await context();
3570
+ if (resolvedDestination.kind === "none") {
3571
+ warnOnce(`vinaya: not recording — ${resolvedDestination.reason}
3572
+ `);
3573
+ return;
3574
+ }
3575
+ const branchIssue = envFields.task ? null : await branchIssueOnce(repo);
3402
3576
  const header = buildHeader({
3403
3577
  now,
3404
3578
  runId,
@@ -3409,15 +3583,11 @@ function createLogSink(overrides = {}) {
3409
3583
  host,
3410
3584
  hostname: deps.hostname(),
3411
3585
  env: envFields,
3586
+ branchIssue,
3412
3587
  eventId: randomUUID2(),
3413
3588
  processId,
3414
3589
  inputVersions: deps.inputVersions()
3415
3590
  });
3416
- if (resolvedDestination.kind === "none") {
3417
- warnOnce(`vinaya: not recording — ${resolvedDestination.reason}
3418
- `);
3419
- return;
3420
- }
3421
3591
  const full = { ...e, ...header };
3422
3592
  const parsed = LogEventSchema.safeParse(full);
3423
3593
  if (!parsed.success) {
@@ -3434,10 +3604,12 @@ function createLogSink(overrides = {}) {
3434
3604
  } else {
3435
3605
  appendLine(outboxPathFor({ outboxRoot: () => destination.folder }, repo, header.subject.issue), line, warnOnce);
3436
3606
  }
3437
- }).catch((err) => {
3607
+ };
3608
+ const written = writeChain.then(write).catch((err) => {
3438
3609
  warnOnce(`vinaya: log() failed — ${err instanceof Error ? err.message : String(err)}
3439
3610
  `);
3440
3611
  });
3612
+ writeChain = written;
3441
3613
  pendingWrites.add(written);
3442
3614
  written.finally(() => pendingWrites.delete(written));
3443
3615
  } catch (err) {
@@ -3980,6 +4152,10 @@ var COMMANDS = [
3980
4152
  flag: "--role <name>",
3981
4153
  description: "Resolve to a specific role file (roles/<name>.md) instead of the front door"
3982
4154
  },
4155
+ {
4156
+ flag: "--template <name>",
4157
+ description: "Print a template the package ships (templates/<name>-template.md) instead of the front door"
4158
+ },
3983
4159
  {
3984
4160
  flag: "--print",
3985
4161
  description: "Emit the resolved file's body (frontmatter stripped) instead of its path — the one-hop mode every generated skill and slash command invokes. A role file whose frontmatter carries an `ack-token` emits that token as the output's own first line."
@@ -4176,6 +4352,9 @@ var StateSourceConfigSchema = z5.discriminatedUnion("kind", [
4176
4352
  var issueCache = new Map;
4177
4353
  var siblingTrancheCache = new Map;
4178
4354
 
4355
+ // src/commands/doctrine.ts
4356
+ import matter2 from "gray-matter";
4357
+
4179
4358
  // src/lib/brief-assembly.ts
4180
4359
  var PACKAGE_ROOT = packageRoot(import.meta.url);
4181
4360
  var PACKAGED_TEMPLATE_PATH = join8(PACKAGE_ROOT, "aeg-root", "templates", "brief-template.md");
@@ -338,6 +338,33 @@ function entry(key) {
338
338
  function label(key) {
339
339
  return entry(key).id;
340
340
  }
341
+ function trancheSlugOf(name) {
342
+ const prefix = entry("tranche").id;
343
+ return name.startsWith(prefix) ? name.slice(prefix.length) : null;
344
+ }
345
+ function findTrancheSlug(names) {
346
+ for (const n of names) {
347
+ const slug = trancheSlugOf(n);
348
+ if (slug !== null)
349
+ return slug;
350
+ }
351
+ return null;
352
+ }
353
+
354
+ // ../../packages/aeg-forge-state/src/list-tasks.ts
355
+ var TITLE_PATTERN = /^\[([^\]]+)]\s*(\S+)\s*—\s*(.+)$/;
356
+ function resolveTaskIssueRef(title, labels) {
357
+ const m = title.match(TITLE_PATTERN);
358
+ if (!m)
359
+ return null;
360
+ const taskId = (m[2] ?? "").trim();
361
+ if (!taskId)
362
+ return null;
363
+ const trancheSlug = findTrancheSlug(labels);
364
+ if (!trancheSlug)
365
+ return null;
366
+ return { trancheSlug, taskId };
367
+ }
341
368
  // ../../packages/aeg-forge-state/src/github-token.ts
342
369
  import { execFile as execFile2 } from "node:child_process";
343
370
  import { promisify as promisify2 } from "node:util";
@@ -656,7 +683,8 @@ var TaskStatusItemSchema = z.object({
656
683
  }).merge(ObservedSchema);
657
684
  var TaskStatusResultSchema = z.object({
658
685
  items: z.array(TaskStatusItemSchema),
659
- nextCursor: z.string().nullable()
686
+ nextCursor: z.string().nullable(),
687
+ table: z.string()
660
688
  });
661
689
  var RequestedAuthoritySchema = z.enum(["planner", "principal", "operator", "self"]);
662
690
  var EscalationInputsSchema = z.object({
@@ -1227,6 +1255,8 @@ function attemptFromEnv(value) {
1227
1255
  function provenanceFor(input) {
1228
1256
  if (input.provenance)
1229
1257
  return input.provenance;
1258
+ if (issueFromTask(input.env.task) === null && (input.branchIssue ?? null) !== null)
1259
+ return "unavailable";
1230
1260
  if (input.env.role || input.env.task)
1231
1261
  return "env_correlated";
1232
1262
  return "unavailable";
@@ -1247,7 +1277,7 @@ function buildHeader(input) {
1247
1277
  const role = isRole(input.env.role) ? input.env.role : "unattributed";
1248
1278
  const round = roundFromEnv(input.env.round);
1249
1279
  const subject = {
1250
- issue: issueFromTask(input.env.task),
1280
+ issue: issueFromTask(input.env.task) ?? input.branchIssue ?? null,
1251
1281
  role,
1252
1282
  ...round !== undefined ? { round } : {},
1253
1283
  ...input.subject ?? {}
@@ -1755,7 +1785,12 @@ var VinayaConfigSchema = z4.object({
1755
1785
  allowlist: z4.array(z4.string().min(1)).optional(),
1756
1786
  severity: z4.enum(["warning", "error"]).optional()
1757
1787
  }).optional(),
1758
- specGrandfather: z4.array(z4.string().min(1)).optional()
1788
+ specGrandfather: z4.array(z4.string().min(1)).optional(),
1789
+ specPaths: z4.array(z4.string().min(1).refine((entry) => !entry.startsWith("/") && !/^[A-Za-z]:/.test(entry), {
1790
+ message: "must be a repository-relative path, not an absolute one"
1791
+ }).refine((entry) => !entry.split(/[\\/]/).includes(".."), {
1792
+ message: "must stay inside the repository — no `..` segment"
1793
+ })).optional()
1759
1794
  }).optional(),
1760
1795
  projects: z4.array(ProjectEntrySchema).optional(),
1761
1796
  dispatch: z4.object({
@@ -1769,6 +1804,13 @@ var VinayaConfigSchema = z4.object({
1769
1804
  securityThreshold: z4.string().min(1).optional(),
1770
1805
  maxRounds: z4.number().optional()
1771
1806
  }).optional(),
1807
+ gateCutovers: z4.object({
1808
+ objectivesSinceIssue: z4.number().int().nonnegative().optional(),
1809
+ briefSectionsSinceIssue: z4.number().int().nonnegative().optional(),
1810
+ documentationSinceIssue: z4.number().int().nonnegative().optional(),
1811
+ briefRulesSincePr: z4.number().int().nonnegative().optional(),
1812
+ agentBoxesRefusedSincePr: z4.number().int().nonnegative().optional()
1813
+ }).optional(),
1772
1814
  prePush: z4.object({
1773
1815
  alwaysRun: z4.array(z4.string()).optional()
1774
1816
  }).optional(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attalabs/vinaya",
3
- "version": "0.33.0",
3
+ "version": "0.34.0",
4
4
  "description": "Vinaya — Agentic Engineering Harness. Deterministic checks every AI coding agent must satisfy before merge.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -65,7 +65,8 @@ type LegacyPauseState = {
65
65
  round: number
66
66
  reason: string
67
67
  detail?: string
68
- prNumber: number
68
+ /** `null` for a pause recorded before any pull request existed — the same shape the live pause record now writes. */
69
+ prNumber: number | null
69
70
  pausedAt: string
70
71
  }
71
72
  function isLegacyPauseState(json: unknown): json is LegacyPauseState {
@@ -75,7 +76,12 @@ function isLegacyPauseState(json: unknown): json is LegacyPauseState {
75
76
  json !== null &&
76
77
  typeof rec.round === 'number' &&
77
78
  typeof rec.reason === 'string' &&
78
- typeof rec.prNumber === 'number' &&
79
+ // A `null` here is a real pause with no pull request, not a malformed
80
+ // record. Requiring a number made exactly that pause fail this guard, so
81
+ // the migration recorded it as `source: 'fresh'` at round `0` and appended
82
+ // no `paused` transition — silently losing the one pause shape that is
83
+ // hardest to recover by hand.
84
+ (typeof rec.prNumber === 'number' || rec.prNumber === null) &&
79
85
  typeof rec.pausedAt === 'string' &&
80
86
  (rec.detail === undefined || typeof rec.detail === 'string')
81
87
  )
@@ -183,7 +189,11 @@ export function migrateLegacyTask(
183
189
  writeInput(deps, task, epoch, {
184
190
  runId: ownerId,
185
191
  source: pauseState.status === 'ok' ? 'resume' : 'fresh',
186
- pr: pauseState.status === 'ok' ? pauseState.value.prNumber : null,
192
+ // A non-positive legacy sentinel (`-1`, written before the record could
193
+ // say "no pull request") is normalized here the same way the live reader
194
+ // normalizes it, so no migrated input carries a number the forge would
195
+ // reject.
196
+ pr: pauseState.status === 'ok' && (pauseState.value.prNumber ?? 0) > 0 ? pauseState.value.prNumber : null,
187
197
  round: pauseState.status === 'ok' ? pauseState.value.round : 0,
188
198
  recordedAt: now
189
199
  })
@@ -1,13 +1,16 @@
1
1
  export { assessRound } from './assess-round'
2
- export { renderSummary } from './render-summary'
2
+ export { parseSummaryConfidenceRows, renderSummary } from './render-summary'
3
+ export type { SummaryConfidenceRow } from './render-summary'
3
4
  export { initialLoopState } from './types'
4
5
  export {
6
+ concludedLoopRefusal,
7
+ isConcludedJournal,
5
8
  isPublishedSummaryComment,
6
9
  nextRoundNumber,
7
10
  reconstructRounds,
8
11
  SUMMARY_TABLE_HEADER
9
12
  } from './journal-reconstruction'
10
- export type { ReconstructedJournal, ReconstructionInput } from './journal-reconstruction'
13
+ export type { ReconstructedJournal, ReconstructionInput, ReviewGateFact } from './journal-reconstruction'
11
14
  export type {
12
15
  Confidence,
13
16
  Decision,
@@ -10,14 +10,18 @@
10
10
  * those events stopped going to the tracker.
11
11
  *
12
12
  * This module is the PURE half of the rebuild: given the round numbers the
13
- * forge's own principal-authored developer round markers carry, and whether a
14
- * ready-for-merge summary was actually published to the forge, hand back one
13
+ * forge's own principal-authored developer round markers carry, whether a
14
+ * ready-for-merge summary was actually published to the forge, and the review
15
+ * gate's verdict on the pull request's current state, hand back one
15
16
  * `RoundRecord` per round plus where the next round should start numbering.
16
17
  * The impure caller (`journal-history.ts`, `@attalabs/vinaya`) gathers those
17
- * two facts: it reads the pull request's principal-authored comments and the
18
- * control store, never a log line. The control store's own authoritative
19
- * round is recovered separately by the driver (`recoverLoopState`), and is
20
- * deliberately NOT folded into the numbering here — see `reconstructRounds`.
18
+ * facts: it reads the pull request's principal-authored comments and evaluates
19
+ * the gate, never a log line. Nothing here performs a forge read or a gate
20
+ * evaluation of its own — the gate's verdict arrives as an input fact, which is
21
+ * what keeps this half pure and testable in every combination. The control
22
+ * store's own authoritative round is recovered separately by the driver
23
+ * (`recoverLoopState`), and is deliberately NOT folded into the numbering here
24
+ * — see `reconstructRounds`.
21
25
  *
22
26
  * Honest about what the forge markers carry: a developer round marker
23
27
  * (`<!-- aeg:developer:round-<n> -->`) names only the round's own number and
@@ -51,32 +55,85 @@ export function isPublishedSummaryComment(body: string): boolean {
51
55
  }
52
56
 
53
57
  /**
54
- * The two forge-derived facts a rebuild is handed. `roundMarkers` are the
55
- * round numbers read off every principal-authored developer round marker on
56
- * the pull request (order and duplicates irrelevant — deduplicated here).
57
- * `summaryPublished` is whether a principal-authored summary comment exists.
58
+ * The forge-derived facts a rebuild is handed. `roundMarkers` are the round
59
+ * numbers read off every principal-authored developer round marker on the
60
+ * pull request (order and duplicates irrelevant — deduplicated here).
61
+ * `summaryPublished` is whether a principal-authored summary comment exists,
62
+ * and `summaryUrl` is that comment's own address when one does.
63
+ * `reviewGate` is the review gate's verdict on the pull request's CURRENT
64
+ * state.
58
65
  */
59
66
  export type ReconstructionInput = {
60
67
  roundMarkers: readonly number[]
61
68
  summaryPublished: boolean
69
+ /** The published summary comment's own url, or `null` when none is on the forge (or the caller could not resolve one). */
70
+ summaryUrl?: string | null
71
+ /**
72
+ * The review gate's verdict on the pull request's CURRENT head, objectives
73
+ * version, newest ruling, frozen brief and policy — the second half of
74
+ * "concluded" (see `journalFinalized`). The caller evaluates it
75
+ * (`checkReviewGate`; nothing here ever reads the forge) and hands the
76
+ * answer in.
77
+ */
78
+ reviewGate: ReviewGateFact
62
79
  }
63
80
 
81
+ /**
82
+ * What the caller could learn about the review gate.
83
+ *
84
+ * - `'pass'`/`'fail'` — the gate genuinely evaluated, against the pull
85
+ * request's current state.
86
+ * - `'unknown'` — nobody asked (no summary is on the forge, so the answer
87
+ * could not change the outcome), or the evaluation could not be made at all
88
+ * (a failed forge read, an unresolvable head, a thrown evaluation).
89
+ *
90
+ * `'unknown'` deliberately does NOT reopen a published review: it is the
91
+ * absence of evidence, not evidence the review moved on, and the two failure
92
+ * directions are not symmetric. Reading it as "reopened" makes one transient
93
+ * `gh` hiccup dispatch a whole extra review round against a task that was
94
+ * genuinely finished, and post its comments — the "a rerun posts nothing
95
+ * twice" invariant, lost for a fact nobody could check. Reading it as "no new
96
+ * information" costs at most one refusal that names the unevaluable gate
97
+ * (`concludedLoopRefusal`) and clears itself on the next attempt. The merge
98
+ * gate is unaffected either way: the `review-gate` check fails CLOSED on every
99
+ * one of these same unresolvable facts, so nothing merges on an unknown here.
100
+ */
101
+ export type ReviewGateFact = 'pass' | 'fail' | 'unknown'
102
+
64
103
  export type ReconstructedJournal = {
65
104
  rounds: RoundRecord[]
66
105
  /** Deliberately `0`: per-round wall time has no control-record or forge source, so it is reported unavailable rather than a fabricated sum (O3). */
67
106
  totalWallMs: number
68
107
  /** Deliberately `0`: per-round files-changed has no control-record or forge source, so it is reported unavailable rather than a fabricated sum (O3). */
69
108
  totalFilesChanged: number
109
+ /** The published summary comment's own url, or `null` when no summary is on the forge (or the caller could not resolve one). Carried even when the gate is red, so a refusal can name where the summary was posted. */
110
+ summaryUrl: string | null
111
+ /** The gate verdict this journal was reconstructed against, carried so a refusal can say the gate could not be evaluated rather than implying it passed. */
112
+ reviewGate: ReviewGateFact
70
113
  /**
71
- * `{ result: 'merged_ready' }` ONLY when a principal-authored ready-for-
72
- * merge summary comment is actually on the forge — the one honest signal a
73
- * run reached publication. A round that decided `publish` but crashed before
74
- * the summary landed (a `gh` failure mid-publish) leaves NO summary comment,
75
- * so this reads `null` and the caller never mistakes that crash for a
76
- * completion — the exact distinction the old log-derived `journal_finalized`
77
- * deferral drew, now drawn from the forge instead. Consumers only ever test
78
- * `=== 'merged_ready'`; `'stopped'` is retained in the type for parity with
79
- * the shape this replaces but is never produced here.
114
+ * `{ result: 'merged_ready' }` while a principal-authored ready-for-merge
115
+ * summary comment is actually on the forge AND the review gate has not
116
+ * FAILED against the pull request's CURRENT state (`ReviewGateFact`, whose
117
+ * own doc explains why an `'unknown'` gate is not a reopen). Concluded is a
118
+ * property of the pull request now, not a one-way latch it once passed
119
+ * through.
120
+ *
121
+ * The summary alone was the old signal, and it is sticky in a way the forge
122
+ * is not: the summary table records no head, so a summary posted for an
123
+ * older head keeps reading "done forever" after a red gate, a newer
124
+ * Principal ruling, a superseded brief or a moved head — observed on an
125
+ * adopter pull request whose every `--resume` was refused while the gate was
126
+ * red and a ruling sat unaddressed. The gate is the one evaluation already
127
+ * bound to all of those, so asking it about the current state is what makes
128
+ * this reopen when any of them moves.
129
+ *
130
+ * A round that decided `publish` but crashed before the summary landed (a
131
+ * `gh` failure mid-publish) still leaves NO summary comment, so this still
132
+ * reads `null` and no caller mistakes that crash for a completion — the
133
+ * distinction the old log-derived `journal_finalized` deferral drew is
134
+ * unchanged, now with a second condition in front of it. Consumers test this
135
+ * through `isConcludedJournal` below; `'stopped'` is retained in the type
136
+ * for parity with the shape this replaces but is never produced here.
80
137
  */
81
138
  journalFinalized: { result: 'merged_ready' | 'stopped' } | null
82
139
  }
@@ -108,14 +165,53 @@ export function reconstructRounds(input: ReconstructionInput): ReconstructedJour
108
165
  confidence: null,
109
166
  outcome: 'changes_requested'
110
167
  }))
168
+ const concluded = input.summaryPublished && input.reviewGate !== 'fail'
111
169
  return {
112
170
  rounds,
113
171
  totalWallMs: 0,
114
172
  totalFilesChanged: 0,
115
- journalFinalized: input.summaryPublished ? { result: 'merged_ready' } : null
173
+ summaryUrl: input.summaryUrl ?? null,
174
+ reviewGate: input.reviewGate,
175
+ journalFinalized: concluded ? { result: 'merged_ready' } : null
116
176
  }
117
177
  }
118
178
 
179
+ /**
180
+ * The ONE predicate every reader of "is this task's review concluded?" calls
181
+ * — the `--resume` replayed-resolution refusal, the attach's round-history
182
+ * seeding, and the held-clean carry path's "already published?" check alike.
183
+ * A second hand-written `=== 'merged_ready'` test at any of those sites is how
184
+ * they drifted apart before: two of them treated a posted summary as final
185
+ * while the pull request's own gate said otherwise.
186
+ */
187
+ export function isConcludedJournal(journal: ReconstructedJournal): boolean {
188
+ return journal.journalFinalized?.result === 'merged_ready'
189
+ }
190
+
191
+ /**
192
+ * The refusal text for a resume against a genuinely concluded review — `null`
193
+ * when the journal is not concluded, so a caller reads "no refusal owed" from
194
+ * the same call that renders one. Names the round the summary concluded at and
195
+ * where that summary is, rather than the storage layer's own
196
+ * consumed-resolution wording, which describes a mechanism the reader did not
197
+ * ask about and hid the real reason the loop would not continue.
198
+ *
199
+ * Degrades rather than inventing: a journal with no round markers at all (a
200
+ * summary posted on a pull request whose round comments were deleted) names no
201
+ * round, an unresolvable summary url says so, and a gate that could not be
202
+ * evaluated at all is named as such rather than left to read as though the gate
203
+ * had been asked and passed.
204
+ */
205
+ export function concludedLoopRefusal(journal: ReconstructedJournal): string | null {
206
+ if (!isConcludedJournal(journal)) return null
207
+ const newest = journal.rounds[journal.rounds.length - 1]
208
+ const at = newest === undefined ? '' : ` at round ${newest.round}`
209
+ const where =
210
+ journal.summaryUrl === null ? 'summary posted, comment url unavailable' : `summary posted ${journal.summaryUrl}`
211
+ const gateNote = journal.reviewGate === 'unknown' ? '; review gate could not be evaluated' : ''
212
+ return `loop already concluded${at} (${where}${gateNote})`
213
+ }
214
+
119
215
  /** Where a fresh round should start numbering after reconstruction — `1` when there is no prior history at all. */
120
216
  export function nextRoundNumber(rounds: readonly RoundRecord[]): number {
121
217
  if (rounds.length === 0) return 1