@attalabs/vinaya 0.37.0 → 0.38.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 (174) hide show
  1. package/aeg-root/enforcement.md +5 -4
  2. package/aeg-root/roles/developer/reference.md +24 -22
  3. package/aeg-root/roles/developer.md +4 -4
  4. package/aeg-root/roles/planner/reference.md +11 -0
  5. package/aeg-root/roles/reviewer.md +5 -3
  6. package/aeg-root/roles/security.md +3 -2
  7. package/aeg-root/state-machine.md +1 -1
  8. package/aeg-root/templates/brief-template.md +4 -4
  9. package/aeg-root/tranche-model.md +6 -0
  10. package/dist/checks/bin/check-body-bare-digits.js +139 -12
  11. package/dist/checks/bin/check-branch-topology.js +171 -13
  12. package/dist/checks/bin/check-brief-shape.js +139 -12
  13. package/dist/checks/bin/check-changeset-coverage.js +177 -17
  14. package/dist/checks/bin/check-closes-n.js +171 -13
  15. package/dist/checks/bin/check-coherence.js +171 -13
  16. package/dist/checks/bin/check-dead-branch-push.js +139 -12
  17. package/dist/checks/bin/check-dispatch-readiness.js +195 -23
  18. package/dist/checks/bin/check-doc-coverage-push.js +173 -13
  19. package/dist/checks/bin/check-doc-coverage.js +180 -13
  20. package/dist/checks/bin/check-doctrine-no-procedures.js +139 -12
  21. package/dist/checks/bin/check-doctrine-portability.js +173 -13
  22. package/dist/checks/bin/check-evidence-fresh.js +173 -13
  23. package/dist/checks/bin/check-exec-bits.js +173 -13
  24. package/dist/checks/bin/check-first-push-dispatch.js +171 -13
  25. package/dist/checks/bin/check-issue-assignment.js +171 -13
  26. package/dist/checks/bin/check-issue-milestone-attach.js +139 -12
  27. package/dist/checks/bin/check-issue-objectives-numbering.js +139 -12
  28. package/dist/checks/bin/check-issue-parts-coverage.js +139 -12
  29. package/dist/checks/bin/check-issue-surface-globs.js +171 -13
  30. package/dist/checks/bin/check-issue-title-grammar.js +139 -12
  31. package/dist/checks/bin/check-issue-tranche-label.js +139 -12
  32. package/dist/checks/bin/check-main-branch-refusal.js +139 -12
  33. package/dist/checks/bin/check-no-disk-state.js +139 -12
  34. package/dist/checks/bin/check-pr-premise-reassert.js +139 -12
  35. package/dist/checks/bin/check-pr-report-density.js +139 -12
  36. package/dist/checks/bin/check-principal-test-plan-wait.js +139 -12
  37. package/dist/checks/bin/check-quoted-command.js +173 -13
  38. package/dist/checks/bin/check-reader-resolvable-prose.js +173 -13
  39. package/dist/checks/bin/check-registry-gates.js +406 -68
  40. package/dist/checks/bin/check-retired-vocabulary.js +173 -13
  41. package/dist/checks/bin/check-review-gate.js +139 -12
  42. package/dist/checks/bin/check-single-plan-pr.js +139 -12
  43. package/dist/checks/bin/check-surface-scope.js +171 -13
  44. package/dist/checks/bin/check-test-plan.js +139 -12
  45. package/dist/checks/bin/check-token-collection-wired.js +139 -12
  46. package/dist/checks/bin/check-workspace-escape.js +173 -13
  47. package/dist/checks/bin/verify-dispatch.js +3849 -0
  48. package/dist/index.js +7348 -2095
  49. package/dist/lib/pre-push-cache-test-run.js +42 -2
  50. package/dist/lib/pre-push-changed-files.js +16 -11
  51. package/dist/lib/pre-push-select-tests.js +177 -21
  52. package/package.json +1 -1
  53. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/anchored-region.ts +7 -6
  54. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-render.ts +33 -15
  55. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/brief-validation.ts +51 -12
  56. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/index.ts +1 -0
  57. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/local.ts +31 -0
  58. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/control-store/records.ts +31 -2
  59. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/assess-round.ts +214 -24
  60. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/fakes.ts +11 -3
  61. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/index.ts +5 -4
  62. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/journal-reconstruction.ts +13 -13
  63. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/render-summary.ts +46 -145
  64. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/dev-review-loop/types.ts +63 -14
  65. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/index.ts +3 -1
  66. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/docs/published-prose.ts +30 -0
  67. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/doctrine-portability.ts +6 -2
  68. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/gate-audience.ts +0 -1
  69. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/index.ts +56 -7
  70. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/issue-validation.ts +7 -7
  71. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/leftover-detection.ts +24 -6
  72. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/custom.ts +157 -0
  73. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/envelope.ts +44 -6
  74. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/executions.ts +493 -0
  75. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/fact-sheets.ts +111 -0
  76. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/generator.ts +155 -0
  77. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/fixtures/index.ts +12 -0
  78. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/index.ts +128 -0
  79. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/catches.ts +63 -0
  80. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/checks.ts +146 -0
  81. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/common.ts +137 -0
  82. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/completion.ts +137 -0
  83. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/convergence.ts +420 -0
  84. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/determinism.ts +65 -0
  85. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/index.ts +69 -0
  86. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/judgment.ts +132 -0
  87. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/labels.ts +21 -0
  88. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/time.ts +167 -0
  89. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/questions/usage.ts +139 -0
  90. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/schema.ts +219 -15
  91. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/store.ts +7 -7
  92. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/cache-contract.ts +207 -0
  93. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/contracts.ts +105 -0
  94. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/engine.ts +308 -0
  95. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/index.ts +34 -0
  96. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/measured.ts +20 -0
  97. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/memory-cache.ts +78 -0
  98. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/normalize.ts +156 -0
  99. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/log/sync/row.ts +103 -0
  100. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/reader-resolvable-prose.ts +34 -6
  101. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/registry-checks.ts +70 -6
  102. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-input-manifest.ts +19 -14
  103. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-policy.ts +38 -3
  104. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/review-status.ts +5 -2
  105. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-phase-history.ts +46 -0
  106. package/studio-standalone/_node_modules/@attalabs/aeg-core/src/task-tools.ts +15 -28
  107. package/studio-standalone/apps/vinaya-studio/web/.next/BUILD_ID +1 -1
  108. package/studio-standalone/apps/vinaya-studio/web/.next/build-manifest.json +3 -3
  109. package/studio-standalone/apps/vinaya-studio/web/.next/prerender-manifest.json +3 -3
  110. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  111. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.html +1 -1
  112. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.rsc +1 -1
  113. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  114. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  115. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  116. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  117. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  118. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page/server-reference-manifest.json +2 -2
  119. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page.js.nft.json +1 -1
  120. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  121. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page/server-reference-manifest.json +2 -2
  122. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page.js.nft.json +1 -1
  123. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/page_client-reference-manifest.js +1 -1
  124. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page/server-reference-manifest.json +2 -2
  125. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page.js.nft.json +1 -1
  126. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/backlog/page_client-reference-manifest.js +1 -1
  127. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page/server-reference-manifest.json +2 -2
  128. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page.js.nft.json +1 -1
  129. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/page_client-reference-manifest.js +1 -1
  130. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page/server-reference-manifest.json +2 -2
  131. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page.js.nft.json +1 -1
  132. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/page_client-reference-manifest.js +1 -1
  133. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page/server-reference-manifest.json +3 -3
  134. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page.js.nft.json +1 -1
  135. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/page_client-reference-manifest.js +1 -1
  136. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page/server-reference-manifest.json +2 -2
  137. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page.js.nft.json +1 -1
  138. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/[name]/tranches/[slug]/tasks/[taskId]/page_client-reference-manifest.js +1 -1
  139. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page/server-reference-manifest.json +2 -2
  140. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page.js.nft.json +1 -1
  141. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/projects/page_client-reference-manifest.js +1 -1
  142. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page/server-reference-manifest.json +2 -2
  143. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page.js.nft.json +1 -1
  144. package/studio-standalone/apps/vinaya-studio/web/.next/server/app/studio/tranches/page_client-reference-manifest.js +1 -1
  145. 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
  146. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__04adkz-._.js +1 -1
  147. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__08e39jo._.js +1 -1
  148. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0h9yhwx._.js +1 -1
  149. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/{[root-of-the-server]__14ui9sz._.js → [root-of-the-server]__0jdjsxe._.js} +1 -1
  150. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__0ls23oh._.js +1 -1
  151. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1gjqmhq._.js +1 -1
  152. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/[root-of-the-server]__1wc4-ip._.js +1 -1
  153. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_08onyya._.js +1 -1
  154. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_096f46i._.js +1 -1
  155. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0af2one._.js +1 -1
  156. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0e5tkdd._.js +1 -1
  157. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0kf2g72._.js +1 -1
  158. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_0zf4d27._.js +1 -1
  159. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1-wo68i._.js +1 -1
  160. package/studio-standalone/apps/vinaya-studio/web/.next/server/chunks/ssr/_1achbh9._.js +1 -1
  161. 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
  162. package/studio-standalone/apps/vinaya-studio/web/.next/server/middleware-build-manifest.js +3 -3
  163. package/studio-standalone/apps/vinaya-studio/web/.next/server/pages/500.html +1 -1
  164. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.js +1 -1
  165. package/studio-standalone/apps/vinaya-studio/web/.next/server/server-reference-manifest.json +4 -4
  166. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/1-acpmtfmrc35.js +1 -0
  167. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3qtt1v3ya-ofe.js → 2f2y8xxok8zph.js} +1 -1
  168. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/{3l56x8wjdzvaw.js → 2xevgia1h8g0y.js} +4 -4
  169. package/studio-standalone/apps/vinaya-studio/web/package.json +2 -2
  170. package/dist/checks/bin/check-token-report.js +0 -6526
  171. package/studio-standalone/apps/vinaya-studio/web/.next/static/chunks/0vtfb0g813gki.js +0 -1
  172. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_buildManifest.js +0 -0
  173. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_clientMiddlewareManifest.js +0 -0
  174. /package/studio-standalone/apps/vinaya-studio/web/.next/static/{yR5RsCxb1OGnYggiaO09S → yNZEFRSjP9BLUfdf96Eol}/_ssgManifest.js +0 -0
@@ -0,0 +1,493 @@
1
+ /**
2
+ * Named fixture executions — realistic, hand-checkable streams of typed log
3
+ * events, each built to exercise one behaviour a reader of the log must get
4
+ * right. They are generated, never committed as data: every valid line is made
5
+ * by the real header builder (`../envelope`), and the test beside this file
6
+ * parses each one with the real event schema, so a schema change that would
7
+ * invalidate a fixture fails there first. A line that is deliberately not
8
+ * valid (an unknown version, a failing line, a repeat) is raw text kept beside
9
+ * the valid ones and marked with how a reader should classify it.
10
+ *
11
+ * The hand-written answer key for each execution is in `./fact-sheets`.
12
+ */
13
+
14
+ import {
15
+ createRecorder,
16
+ FIXTURE_REPO,
17
+ FIXTURE_SEED,
18
+ LOW_TRUST_VINAYA_VERSION,
19
+ type EmitOptions,
20
+ type FixtureLine,
21
+ type Recorder
22
+ } from './generator'
23
+ import type { HeaderMetaV1, HeaderMetaV2, Role } from '../schema'
24
+
25
+ export const EXECUTION_NAMES = [
26
+ 'green-one-round',
27
+ 'three-rounds-recurring-finding',
28
+ 'paused-and-resumed',
29
+ 'escalated-handoff',
30
+ 'gate-two-commits',
31
+ 'gate-no-commit',
32
+ 'gate-same-commit-twice',
33
+ 'usage-and-models',
34
+ 'historical-and-hostile-lines'
35
+ ] as const
36
+ export type ExecutionName = (typeof EXECUTION_NAMES)[number]
37
+
38
+ export type FixtureExecution = {
39
+ name: ExecutionName
40
+ description: string
41
+ /** The execution's lines, in the order they were stored. */
42
+ lines: readonly FixtureLine[]
43
+ }
44
+
45
+ type Finding = {
46
+ id: string
47
+ severity: string
48
+ severity_scale: string
49
+ policy_treatment: 'blocking' | 'non_blocking'
50
+ }
51
+
52
+ function finding(id: string, severity: string, blocking: boolean): Finding {
53
+ return {
54
+ id,
55
+ severity,
56
+ severity_scale: 'code-review',
57
+ policy_treatment: blocking ? 'blocking' : 'non_blocking'
58
+ }
59
+ }
60
+
61
+ type LoopEmit = (event: string, fields: Record<string, unknown>, options?: EmitOptions) => Record<string, unknown>
62
+
63
+ function openLoop(rec: Recorder): LoopEmit {
64
+ const loopId = `loop-${rec.hex(8)}`
65
+ const emit: LoopEmit = (event, fields, options) =>
66
+ rec.emit(
67
+ { kind: 'dev_review_loop', event, loop_id: loopId, ...fields },
68
+ { host: 'loop', ...(typeof fields.round === 'number' ? { round: fields.round } : {}), ...options }
69
+ )
70
+ emit('loop_started', {
71
+ task: rec.issue,
72
+ policy: {
73
+ max_rounds: 5,
74
+ reviewers: ['code-reviewer'],
75
+ models: { developer: 'sonnet', 'code-reviewer': 'opus' }
76
+ }
77
+ })
78
+ return emit
79
+ }
80
+
81
+ /** One dispatch of a role: the `dispatched` line now, the `outcome_received` line when the returned function is called. */
82
+ function dispatch(rec: Recorder, target: Role, model: string, round: number) {
83
+ const effectId = `eff-${rec.hex(8)}`
84
+ const shared = { kind: 'dispatch', target_role: target, model, round, effect_id: effectId }
85
+ const options = { round, provenance: 'parent_attributed' as const }
86
+ rec.emit({ ...shared, event: 'dispatched', prompt_hash: `fixture-prompt-${rec.hex(8)}` }, options)
87
+ return (outcome: Record<string, unknown>) =>
88
+ rec.emit(
89
+ {
90
+ ...shared,
91
+ event: 'outcome_received',
92
+ outcome,
93
+ usage: { input: rec.int(2000, 9000), output: rec.int(300, 1500) }
94
+ },
95
+ options
96
+ )
97
+ }
98
+
99
+ type RoundSpec = {
100
+ n: number
101
+ base: string
102
+ head: string
103
+ /** What this round's reviewer reports. */
104
+ findings: Finding[]
105
+ /** The loop's own comparison with the round before — absent in round 1. */
106
+ compared?: { open: string[]; resolved: string[]; new: string[]; recurring: string[] }
107
+ /** The developer's stated confidence, as `gate_result_read` records it. */
108
+ confidence?: Record<string, unknown>
109
+ }
110
+
111
+ /** One full review round on a green gate: developer turn, typecheck, gate read, reviewer turn, verdicts, comparison, end. Returns the files it changed. */
112
+ function runRound(rec: Recorder, loop: LoopEmit, spec: RoundSpec): number {
113
+ const { n, base, head, findings } = spec
114
+ const blockers = findings.filter((f) => f.policy_treatment === 'blocking').length
115
+ const approved = blockers === 0
116
+ loop('round_started', { round: n, base_head: base })
117
+ const developer = dispatch(rec, 'developer', 'sonnet', n)
118
+ developer(
119
+ n === 1
120
+ ? { type: 'pr_opened', pr: rec.pr, head }
121
+ : { type: 'round_pushed', pr: rec.pr, head, comment_id: rec.commentId() }
122
+ )
123
+ rec.emit(
124
+ {
125
+ kind: 'gate',
126
+ event: 'checked',
127
+ check: 'typecheck',
128
+ check_version: '1',
129
+ policy_version: null,
130
+ input_fingerprint: `fp-${rec.hex(8)}`,
131
+ outcome: 'pass'
132
+ },
133
+ { round: n, sha: head, host: 'ci' }
134
+ )
135
+ loop('gate_result_read', { round: n, head, green: true, ...spec.confidence })
136
+ const reviewer = dispatch(rec, 'code-reviewer', 'opus', n)
137
+ reviewer({
138
+ type: 'verdict',
139
+ verdict: approved ? 'APPROVE' : 'REQUEST CHANGES',
140
+ head,
141
+ comment_id: rec.commentId(),
142
+ objectives: [{ id: 'O1', met: approved }],
143
+ findings
144
+ })
145
+ loop('verdicts_read', { round: n, head, all_approve: approved, blockers, findings })
146
+ if (spec.compared) loop('findings_compared', { round: n, ...spec.compared })
147
+ const filesChanged = rec.int(2, 9)
148
+ loop('round_ended', {
149
+ round: n,
150
+ base_head: base,
151
+ head,
152
+ files_changed: filesChanged,
153
+ insertions: rec.int(20, 200),
154
+ deletions: rec.int(0, 60),
155
+ wall_ms: rec.int(60_000, 600_000),
156
+ outcome: approved ? 'green' : 'changes_requested'
157
+ })
158
+ return filesChanged
159
+ }
160
+
161
+ /** The loop's green ending: the stop condition, then the journal. */
162
+ function finishGreen(rec: Recorder, loop: LoopEmit, rounds: number, finalHead: string, filesTotal: number): void {
163
+ loop('stop_condition_met', { round: rounds, condition: 'green' })
164
+ const elapsed = rec.elapsedMs()
165
+ loop('journal_finalized', {
166
+ rounds,
167
+ total_wall_ms: elapsed,
168
+ time_to_green_ms: elapsed,
169
+ files_changed_total: filesTotal,
170
+ final_head: finalHead,
171
+ result: 'merged_ready'
172
+ })
173
+ }
174
+
175
+ /** One run of a check. `sha` absent records no commit at all. */
176
+ function gateRun(rec: Recorder, check: string, fingerprint: string, outcome: string, sha?: string): void {
177
+ rec.emit(
178
+ {
179
+ kind: 'gate',
180
+ event: 'checked',
181
+ check,
182
+ check_version: '1',
183
+ policy_version: null,
184
+ input_fingerprint: fingerprint,
185
+ outcome
186
+ },
187
+ { host: 'ci', ...(sha ? { sha } : {}) }
188
+ )
189
+ }
190
+
191
+ function usage(
192
+ rec: Recorder,
193
+ model: string | null,
194
+ semantics: 'cumulative' | 'delta',
195
+ units: { input: number | null; output: number | null; cache: number | null },
196
+ unknownReason: string | null = null
197
+ ): void {
198
+ rec.emit(
199
+ { kind: 'usage', event: 'observed', model, source: 'claude', semantics, units, unknown_reason: unknownReason },
200
+ { host: 'cli' }
201
+ )
202
+ }
203
+
204
+ function roleAttempt(rec: Recorder, role: Role, model: string, attempt: number, outcome: string): void {
205
+ rec.emit(
206
+ {
207
+ kind: 'role_attempt',
208
+ event: 'attempted',
209
+ actor: 'claude',
210
+ attempt,
211
+ effect_id: `eff-${rec.hex(8)}`,
212
+ model,
213
+ outcome,
214
+ usage: null
215
+ },
216
+ { role, host: 'loop' }
217
+ )
218
+ }
219
+
220
+ /** A completed operation — the smallest event, so a line's header is all that differs between the historical lines below. */
221
+ const operationFields = {
222
+ kind: 'operation',
223
+ event: 'completed',
224
+ payload: {},
225
+ operation: 'authenticate-invocation',
226
+ target: null,
227
+ result: 'ok',
228
+ error_class: null
229
+ }
230
+
231
+ type Scenario = { description: string; issue: number; build: (rec: Recorder) => void }
232
+
233
+ const SCENARIOS: Record<ExecutionName, Scenario> = {
234
+ 'green-one-round': {
235
+ description: 'A unit of work that finishes green in a single round, with no findings.',
236
+ issue: 101,
237
+ build(rec) {
238
+ const loop = openLoop(rec)
239
+ const head = rec.sha()
240
+ const files = runRound(rec, loop, { n: 1, base: rec.sha(), head, findings: [] })
241
+ finishGreen(rec, loop, 1, head, files)
242
+ }
243
+ },
244
+ 'three-rounds-recurring-finding': {
245
+ description:
246
+ 'Three rounds: one finding recurs in round 2 beside a new one, and both are resolved in round 3. The developer states confidence from round 2 on — once straight away, once after the one extra turn.',
247
+ issue: 102,
248
+ build(rec) {
249
+ const loop = openLoop(rec)
250
+ const [h0, h1, h2, h3] = [rec.sha(), rec.sha(), rec.sha(), rec.sha()] as [string, string, string, string]
251
+ const auth = finding('fnd-auth-1', 'MAJOR', true)
252
+ const docs = finding('fnd-docs-2', 'MINOR', false)
253
+ let files = runRound(rec, loop, { n: 1, base: h0, head: h1, findings: [auth] })
254
+ files += runRound(rec, loop, {
255
+ n: 2,
256
+ base: h1,
257
+ head: h2,
258
+ findings: [auth, docs],
259
+ compared: { open: ['fnd-auth-1', 'fnd-docs-2'], resolved: [], new: ['fnd-docs-2'], recurring: ['fnd-auth-1'] },
260
+ confidence: {
261
+ confidence_value: 70,
262
+ confidence_reason: 'the auth path is covered, the docs are not',
263
+ extra_turn_spent: false
264
+ }
265
+ })
266
+ files += runRound(rec, loop, {
267
+ n: 3,
268
+ base: h2,
269
+ head: h3,
270
+ findings: [],
271
+ compared: { open: [], resolved: ['fnd-auth-1', 'fnd-docs-2'], new: [], recurring: [] },
272
+ confidence: {
273
+ confidence_value: 92,
274
+ confidence_reason: 'every finding is addressed and covered by a test',
275
+ extra_turn_spent: true
276
+ }
277
+ })
278
+ finishGreen(rec, loop, 3, h3, files)
279
+ }
280
+ },
281
+ 'paused-and-resumed': {
282
+ description:
283
+ 'Round 1 asks for changes and the loop pauses for a principal item; the principal resumes it, and round 2 finishes green.',
284
+ issue: 103,
285
+ build(rec) {
286
+ const loop = openLoop(rec)
287
+ const [h0, h1, h2] = [rec.sha(), rec.sha(), rec.sha()] as [string, string, string]
288
+ const queue = finding('fnd-q-1', 'MAJOR', true)
289
+ let files = runRound(rec, loop, { n: 1, base: h0, head: h1, findings: [queue] })
290
+ loop('paused', { round: 1, reason: 'principal_item' })
291
+ loop('resumed', { round: 1, by: 'principal' })
292
+ files += runRound(rec, loop, {
293
+ n: 2,
294
+ base: h1,
295
+ head: h2,
296
+ findings: [],
297
+ compared: { open: [], resolved: ['fnd-q-1'], new: [], recurring: [] }
298
+ })
299
+ finishGreen(rec, loop, 2, h2, files)
300
+ }
301
+ },
302
+ 'escalated-handoff': {
303
+ description:
304
+ 'The developer escalates a strategy question in round 1; it becomes a handoff to a human, and the loop stops unresolved.',
305
+ issue: 104,
306
+ build(rec) {
307
+ const loop = openLoop(rec)
308
+ const base = rec.sha()
309
+ loop('round_started', { round: 1, base_head: base })
310
+ const developer = dispatch(rec, 'developer', 'sonnet', 1)
311
+ developer({ type: 'escalation', class: 'strategy', comment_id: rec.commentId() })
312
+ rec.emit(
313
+ {
314
+ kind: 'handoff',
315
+ event: 'raised',
316
+ class: 'strategy',
317
+ reason: 'the brief assumes an approach the codebase no longer takes',
318
+ requested_decision: 'keep the brief as written, or re-plan the task'
319
+ },
320
+ { round: 1, role: 'developer', host: 'loop' }
321
+ )
322
+ loop('stop_condition_met', { round: 1, condition: 'escalated' })
323
+ loop('round_ended', {
324
+ round: 1,
325
+ base_head: base,
326
+ head: base,
327
+ files_changed: 0,
328
+ insertions: 0,
329
+ deletions: 0,
330
+ wall_ms: rec.int(60_000, 600_000),
331
+ outcome: 'escalated'
332
+ })
333
+ loop('journal_finalized', {
334
+ rounds: 1,
335
+ total_wall_ms: rec.elapsedMs(),
336
+ time_to_green_ms: null,
337
+ files_changed_total: 0,
338
+ final_head: base,
339
+ result: 'stopped'
340
+ })
341
+ }
342
+ },
343
+ 'gate-two-commits': {
344
+ description:
345
+ 'The same check on the same input fingerprint at two different commits, failing at the first and passing at the second.',
346
+ issue: 105,
347
+ build(rec) {
348
+ const fingerprint = `fp-${rec.hex(8)}`
349
+ gateRun(rec, 'test', fingerprint, 'fail', rec.sha())
350
+ gateRun(rec, 'test', fingerprint, 'pass', rec.sha())
351
+ }
352
+ },
353
+ 'gate-no-commit': {
354
+ description:
355
+ 'The same check on the same input fingerprint twice with no commit recorded, passing and then failing.',
356
+ issue: 106,
357
+ build(rec) {
358
+ const fingerprint = `fp-${rec.hex(8)}`
359
+ gateRun(rec, 'lint', fingerprint, 'pass')
360
+ gateRun(rec, 'lint', fingerprint, 'fail')
361
+ }
362
+ },
363
+ 'gate-same-commit-twice': {
364
+ description: 'A check that passes at one commit twice, on the same input fingerprint.',
365
+ issue: 107,
366
+ build(rec) {
367
+ const fingerprint = `fp-${rec.hex(8)}`
368
+ const sha = rec.sha()
369
+ gateRun(rec, 'build', fingerprint, 'pass', sha)
370
+ gateRun(rec, 'build', fingerprint, 'pass', sha)
371
+ }
372
+ },
373
+ 'usage-and-models': {
374
+ description:
375
+ 'Two cumulative and three delta usage observations across two models, one of them with every unit unknown, and a role attempt retried with its usage unknown both times.',
376
+ issue: 108,
377
+ build(rec) {
378
+ usage(rec, 'opus', 'cumulative', { input: 1000, output: 200, cache: 500 })
379
+ usage(rec, 'opus', 'cumulative', { input: 2500, output: 600, cache: 1200 })
380
+ usage(rec, 'sonnet', 'delta', { input: 300, output: 80, cache: 0 })
381
+ usage(rec, 'sonnet', 'delta', { input: 150, output: 40, cache: null })
382
+ usage(rec, 'sonnet', 'delta', { input: null, output: null, cache: null }, 'the vendor reported no usage')
383
+ roleAttempt(rec, 'developer', 'sonnet', 1, 'infrastructure_failed')
384
+ roleAttempt(rec, 'developer', 'sonnet', 2, 'completed')
385
+ }
386
+ },
387
+ 'historical-and-hostile-lines': {
388
+ description:
389
+ 'Lines a reader meets in an old or damaged store: schema 1, schema 2, a low-trust line from a CLI older than 0.33.0 with no attribution, a current line, a line of a schema version no build knows, a line that fails validation, and one event delivered twice.',
390
+ issue: 109,
391
+ build(rec) {
392
+ const common = { repo: FIXTURE_REPO, doctrine: 'fixture-doctrine-old', host: 'cli' as const }
393
+ const v1: HeaderMetaV1 = {
394
+ schema: 1,
395
+ ts: rec.tick().toISOString(),
396
+ run_id: `run-legacy-${rec.hex(6)}`,
397
+ seq: 0,
398
+ vinaya: '0.24.0',
399
+ machine: rec.hex(64),
400
+ ...common
401
+ }
402
+ rec.push({ meta: v1, subject: { issue: rec.issue, role: 'developer' }, ...operationFields })
403
+
404
+ const v2Base: Omit<HeaderMetaV2, 'run_id' | 'ts' | 'machine' | 'event_id' | 'process_id'> = {
405
+ schema: 2,
406
+ seq: 3,
407
+ vinaya: '0.31.0',
408
+ actor_id: 'developer',
409
+ lineage: { run: null, attempt: null, parent: null },
410
+ input_versions: { objectives_version: null, brief_hash: null, ruling_ordinal: null, policy_digest: null },
411
+ provenance: 'env_correlated',
412
+ ...common
413
+ }
414
+ const v2: HeaderMetaV2 = {
415
+ ...v2Base,
416
+ ts: rec.tick().toISOString(),
417
+ run_id: `run-legacy-${rec.hex(6)}`,
418
+ machine: rec.hex(64),
419
+ event_id: `evt-${rec.hex(12)}`,
420
+ process_id: `proc-${rec.hex(8)}`
421
+ }
422
+ rec.push({ meta: v2, subject: { issue: rec.issue, role: 'developer' }, ...operationFields })
423
+
424
+ const lowTrust: HeaderMetaV2 = {
425
+ ...v2,
426
+ ts: rec.tick().toISOString(),
427
+ run_id: `run-legacy-${rec.hex(6)}`,
428
+ seq: 0,
429
+ vinaya: LOW_TRUST_VINAYA_VERSION,
430
+ machine: rec.hex(64),
431
+ event_id: `evt-${rec.hex(12)}`,
432
+ process_id: `proc-${rec.hex(8)}`,
433
+ actor_id: null,
434
+ provenance: 'unavailable'
435
+ }
436
+ rec.push({ meta: lowTrust, subject: { issue: null, role: 'unattributed' }, ...operationFields })
437
+
438
+ const current = rec.emit(
439
+ {
440
+ kind: 'operation',
441
+ event: 'completed',
442
+ operation: 'authenticate-invocation',
443
+ target: null,
444
+ result: 'ok',
445
+ error_class: null
446
+ },
447
+ { host: 'cli' }
448
+ )
449
+
450
+ const future = rec.build(
451
+ {
452
+ kind: 'operation',
453
+ event: 'completed',
454
+ operation: 'authenticate-invocation',
455
+ target: null,
456
+ result: 'ok',
457
+ error_class: null
458
+ },
459
+ { host: 'cli' }
460
+ )
461
+ rec.push({ ...future, meta: { ...(future.meta as object), schema: 9, telepathy: true } }, 'unknown_version')
462
+
463
+ const failing = rec.build(
464
+ {
465
+ kind: 'gate',
466
+ event: 'checked',
467
+ check: 'lint',
468
+ check_version: '1',
469
+ policy_version: null,
470
+ input_fingerprint: null,
471
+ outcome: 'bogus'
472
+ },
473
+ { host: 'ci' }
474
+ )
475
+ rec.push(failing, 'invalid')
476
+
477
+ rec.pushRaw(JSON.stringify(current), 'valid')
478
+ }
479
+ }
480
+ }
481
+
482
+ /** One named execution, built from a seed. The same name and seed always give the same lines, byte for byte. */
483
+ export function buildExecution(name: ExecutionName, seed: string = FIXTURE_SEED): FixtureExecution {
484
+ const scenario = SCENARIOS[name]
485
+ const rec = createRecorder(seed, name, EXECUTION_NAMES.indexOf(name), scenario.issue)
486
+ scenario.build(rec)
487
+ return { name, description: scenario.description, lines: rec.lines }
488
+ }
489
+
490
+ /** Every named execution, in `EXECUTION_NAMES` order. */
491
+ export function buildExecutions(seed: string = FIXTURE_SEED): FixtureExecution[] {
492
+ return EXECUTION_NAMES.map((name) => buildExecution(name, seed))
493
+ }
@@ -0,0 +1,111 @@
1
+ /**
2
+ * The answer key for each fixture execution, written by hand from the
3
+ * scenario in `./executions` — never computed from the lines. A later task's
4
+ * expected result is worked out from these sheets by a person; the test beside
5
+ * this file compares each sheet with the lines, so a sheet and its scenario can
6
+ * never drift apart unnoticed.
7
+ *
8
+ * What each fact counts:
9
+ * - `lines` — every stored line, valid or not, repeats included.
10
+ * - `schemas` — lines per declared `meta.schema`.
11
+ * - `rounds` — the review rounds the execution started (`round_started` events).
12
+ * - `eventsByKind` — lines per event family (`kind`), repeats and invalid lines included.
13
+ * - `findingIdentities` — the distinct finding identities the execution names, sorted.
14
+ * - `models` — the distinct `model` values events carry, sorted; a null model is none.
15
+ */
16
+
17
+ import type { ExecutionName } from './executions'
18
+
19
+ export type FactSheet = {
20
+ lines: number
21
+ schemas: Record<string, number>
22
+ rounds: number
23
+ eventsByKind: Record<string, number>
24
+ findingIdentities: string[]
25
+ models: string[]
26
+ }
27
+
28
+ export const FACT_SHEETS: Record<ExecutionName, FactSheet> = {
29
+ // loop_started, one round of four events, stop condition and journal; one developer and one reviewer dispatch pair; one typecheck.
30
+ 'green-one-round': {
31
+ lines: 12,
32
+ schemas: { '3': 12 },
33
+ rounds: 1,
34
+ eventsByKind: { dev_review_loop: 7, dispatch: 4, gate: 1 },
35
+ findingIdentities: [],
36
+ models: ['opus', 'sonnet']
37
+ },
38
+ // Round 1 reports the authentication finding; round 2 reports it again (recurring) beside the documentation finding; round 3 resolves both.
39
+ // Rounds 2 and 3 carry a findings comparison and a stated confidence, round 3 after the extra turn.
40
+ 'three-rounds-recurring-finding': {
41
+ lines: 32,
42
+ schemas: { '3': 32 },
43
+ rounds: 3,
44
+ eventsByKind: { dev_review_loop: 17, dispatch: 12, gate: 3 },
45
+ findingIdentities: ['fnd-auth-1', 'fnd-docs-2'],
46
+ models: ['opus', 'sonnet']
47
+ },
48
+ // Round 1 reports one finding and ends changes requested; a pause and a resume follow; round 2 resolves it.
49
+ 'paused-and-resumed': {
50
+ lines: 24,
51
+ schemas: { '3': 24 },
52
+ rounds: 2,
53
+ eventsByKind: { dev_review_loop: 14, dispatch: 8, gate: 2 },
54
+ findingIdentities: ['fnd-q-1'],
55
+ models: ['opus', 'sonnet']
56
+ },
57
+ // loop_started, round_started, stop condition, round_ended and journal; the developer dispatch pair; one handoff. No reviewer is ever dispatched.
58
+ 'escalated-handoff': {
59
+ lines: 8,
60
+ schemas: { '3': 8 },
61
+ rounds: 1,
62
+ eventsByKind: { dev_review_loop: 5, dispatch: 2, handoff: 1 },
63
+ findingIdentities: [],
64
+ models: ['sonnet']
65
+ },
66
+ // One check and one fingerprint: fail at the first commit, pass at the second.
67
+ 'gate-two-commits': {
68
+ lines: 2,
69
+ schemas: { '3': 2 },
70
+ rounds: 0,
71
+ eventsByKind: { gate: 2 },
72
+ findingIdentities: [],
73
+ models: []
74
+ },
75
+ // One check and one fingerprint, no commit on either line: pass, then fail.
76
+ 'gate-no-commit': {
77
+ lines: 2,
78
+ schemas: { '3': 2 },
79
+ rounds: 0,
80
+ eventsByKind: { gate: 2 },
81
+ findingIdentities: [],
82
+ models: []
83
+ },
84
+ // One check, one fingerprint, one commit: pass, pass.
85
+ 'gate-same-commit-twice': {
86
+ lines: 2,
87
+ schemas: { '3': 2 },
88
+ rounds: 0,
89
+ eventsByKind: { gate: 2 },
90
+ findingIdentities: [],
91
+ models: []
92
+ },
93
+ // Five usage observations (two cumulative opus, three delta sonnet, the last with every unit unknown) and two sonnet role attempts with null usage.
94
+ 'usage-and-models': {
95
+ lines: 7,
96
+ schemas: { '3': 7 },
97
+ rounds: 0,
98
+ eventsByKind: { usage: 5, role_attempt: 2 },
99
+ findingIdentities: [],
100
+ models: ['opus', 'sonnet']
101
+ },
102
+ // In order: schema 1, schema 2, schema 2 low-trust (0.30.1), schema 3, schema 9 (unknown), schema 3 failing validation (a gate line), the schema 3 line again.
103
+ 'historical-and-hostile-lines': {
104
+ lines: 7,
105
+ schemas: { '1': 1, '2': 2, '3': 3, '9': 1 },
106
+ rounds: 0,
107
+ eventsByKind: { operation: 6, gate: 1 },
108
+ findingIdentities: [],
109
+ models: []
110
+ }
111
+ }