@aperant/framework 0.17.0 → 0.20.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 (242) hide show
  1. package/CHANGELOG.md +261 -0
  2. package/agents/apt-executor.md +6 -0
  3. package/agents/apt-planner.md +3 -2
  4. package/bin/features-reconcile-check.mjs +77 -0
  5. package/dist/cli/artifacts/self-stage.d.mts.map +1 -1
  6. package/dist/cli/artifacts/self-stage.mjs +2 -1
  7. package/dist/cli/artifacts/self-stage.mjs.map +1 -1
  8. package/dist/cli/cli-wrappers/features-reconcile.d.mts +2 -0
  9. package/dist/cli/cli-wrappers/features-reconcile.d.mts.map +1 -0
  10. package/dist/cli/cli-wrappers/features-reconcile.mjs +9 -0
  11. package/dist/cli/cli-wrappers/features-reconcile.mjs.map +1 -0
  12. package/dist/cli/commands/ci-watch.mjs +49 -2
  13. package/dist/cli/commands/ci-watch.mjs.map +1 -1
  14. package/dist/cli/commands/commit.mjs +3 -3
  15. package/dist/cli/commands/commit.mjs.map +1 -1
  16. package/dist/cli/commands/event.mjs +16 -16
  17. package/dist/cli/commands/event.mjs.map +1 -1
  18. package/dist/cli/commands/features-reconcile.d.mts +2 -0
  19. package/dist/cli/commands/features-reconcile.d.mts.map +1 -0
  20. package/dist/cli/commands/features-reconcile.mjs +143 -0
  21. package/dist/cli/commands/features-reconcile.mjs.map +1 -0
  22. package/dist/cli/commands/health-check.d.mts +2 -2
  23. package/dist/cli/commands/health-check.mjs +2 -2
  24. package/dist/cli/commands/merge-integrate.mjs +3 -3
  25. package/dist/cli/commands/merge-integrate.mjs.map +1 -1
  26. package/dist/cli/commands/produce.d.mts +9 -0
  27. package/dist/cli/commands/produce.d.mts.map +1 -0
  28. package/dist/cli/commands/produce.mjs +1345 -0
  29. package/dist/cli/commands/produce.mjs.map +1 -0
  30. package/dist/cli/commands/task.d.mts +16 -1
  31. package/dist/cli/commands/task.d.mts.map +1 -1
  32. package/dist/cli/commands/task.mjs +434 -266
  33. package/dist/cli/commands/task.mjs.map +1 -1
  34. package/dist/cli/coordination/auto-emit-artifact-ready.mjs +5 -5
  35. package/dist/cli/coordination/auto-emit-artifact-ready.mjs.map +1 -1
  36. package/dist/cli/coordination/event-schema.d.mts +5 -3
  37. package/dist/cli/coordination/event-schema.d.mts.map +1 -1
  38. package/dist/cli/coordination/event-schema.mjs +245 -21
  39. package/dist/cli/coordination/event-schema.mjs.map +1 -1
  40. package/dist/cli/coordination/store.d.mts +2 -2
  41. package/dist/cli/coordination/store.mjs +4 -4
  42. package/dist/cli/coordination/store.mjs.map +1 -1
  43. package/dist/cli/dispatch.d.mts.map +1 -1
  44. package/dist/cli/dispatch.mjs +4 -2
  45. package/dist/cli/dispatch.mjs.map +1 -1
  46. package/dist/cli/features/area-shape.d.mts +11 -0
  47. package/dist/cli/features/area-shape.d.mts.map +1 -0
  48. package/dist/cli/features/area-shape.mjs +141 -0
  49. package/dist/cli/features/area-shape.mjs.map +1 -0
  50. package/dist/cli/features/delta.d.mts +78 -0
  51. package/dist/cli/features/delta.d.mts.map +1 -0
  52. package/dist/cli/features/delta.mjs +591 -0
  53. package/dist/cli/features/delta.mjs.map +1 -0
  54. package/dist/cli/features/reconcile.d.mts +236 -0
  55. package/dist/cli/features/reconcile.d.mts.map +1 -0
  56. package/dist/cli/features/reconcile.mjs +1126 -0
  57. package/dist/cli/features/reconcile.mjs.map +1 -0
  58. package/dist/cli/features/surface-map.d.mts +63 -0
  59. package/dist/cli/features/surface-map.d.mts.map +1 -0
  60. package/dist/cli/features/surface-map.mjs +191 -0
  61. package/dist/cli/features/surface-map.mjs.map +1 -0
  62. package/dist/cli/{commands/features-audit.d.mts → features/write-root.d.mts} +4 -3
  63. package/dist/cli/features/write-root.d.mts.map +1 -0
  64. package/dist/cli/features/write-root.mjs +137 -0
  65. package/dist/cli/features/write-root.mjs.map +1 -0
  66. package/dist/cli/gate/gates/features-reconciled.d.mts +36 -0
  67. package/dist/cli/gate/gates/features-reconciled.d.mts.map +1 -0
  68. package/dist/cli/gate/gates/features-reconciled.mjs +67 -0
  69. package/dist/cli/gate/gates/features-reconciled.mjs.map +1 -0
  70. package/dist/cli/gate/gates/index.mjs +1 -0
  71. package/dist/cli/gate/gates/index.mjs.map +1 -1
  72. package/dist/cli/help.d.mts.map +1 -1
  73. package/dist/cli/help.mjs +31 -1
  74. package/dist/cli/help.mjs.map +1 -1
  75. package/dist/cli/install/legacy-paths.d.mts.map +1 -1
  76. package/dist/cli/install/legacy-paths.mjs +2 -0
  77. package/dist/cli/install/legacy-paths.mjs.map +1 -1
  78. package/dist/cli/produce/blind-probe.d.mts +85 -0
  79. package/dist/cli/produce/blind-probe.d.mts.map +1 -0
  80. package/dist/cli/produce/blind-probe.mjs +217 -0
  81. package/dist/cli/produce/blind-probe.mjs.map +1 -0
  82. package/dist/cli/produce/claim.d.mts +188 -0
  83. package/dist/cli/produce/claim.d.mts.map +1 -0
  84. package/dist/cli/produce/claim.mjs +518 -0
  85. package/dist/cli/produce/claim.mjs.map +1 -0
  86. package/dist/cli/produce/done-gate.d.mts +87 -0
  87. package/dist/cli/produce/done-gate.d.mts.map +1 -0
  88. package/dist/cli/produce/done-gate.mjs +200 -0
  89. package/dist/cli/produce/done-gate.mjs.map +1 -0
  90. package/dist/cli/produce/events.d.mts +77 -0
  91. package/dist/cli/produce/events.d.mts.map +1 -0
  92. package/dist/cli/produce/events.mjs +126 -0
  93. package/dist/cli/produce/events.mjs.map +1 -0
  94. package/dist/cli/produce/evidence-oracle.d.mts +63 -0
  95. package/dist/cli/produce/evidence-oracle.d.mts.map +1 -0
  96. package/dist/cli/produce/evidence-oracle.mjs +122 -0
  97. package/dist/cli/produce/evidence-oracle.mjs.map +1 -0
  98. package/dist/cli/produce/ledger.d.mts +140 -0
  99. package/dist/cli/produce/ledger.d.mts.map +1 -0
  100. package/dist/cli/produce/ledger.mjs +272 -0
  101. package/dist/cli/produce/ledger.mjs.map +1 -0
  102. package/dist/cli/produce/probe-family.d.mts +53 -0
  103. package/dist/cli/produce/probe-family.d.mts.map +1 -0
  104. package/dist/cli/produce/probe-family.mjs +160 -0
  105. package/dist/cli/produce/probe-family.mjs.map +1 -0
  106. package/dist/cli/produce/projection.d.mts +55 -0
  107. package/dist/cli/produce/projection.d.mts.map +1 -0
  108. package/dist/cli/produce/projection.mjs +97 -0
  109. package/dist/cli/produce/projection.mjs.map +1 -0
  110. package/dist/cli/produce/run-id.d.mts +42 -0
  111. package/dist/cli/produce/run-id.d.mts.map +1 -0
  112. package/dist/cli/produce/run-id.mjs +79 -0
  113. package/dist/cli/produce/run-id.mjs.map +1 -0
  114. package/dist/cli/produce/saga.d.mts +180 -0
  115. package/dist/cli/produce/saga.d.mts.map +1 -0
  116. package/dist/cli/produce/saga.mjs +290 -0
  117. package/dist/cli/produce/saga.mjs.map +1 -0
  118. package/dist/cli/produce/scheduler.d.mts +165 -0
  119. package/dist/cli/produce/scheduler.d.mts.map +1 -0
  120. package/dist/cli/produce/scheduler.mjs +399 -0
  121. package/dist/cli/produce/scheduler.mjs.map +1 -0
  122. package/dist/cli/produce/setpoint.d.mts +52 -0
  123. package/dist/cli/produce/setpoint.d.mts.map +1 -0
  124. package/dist/cli/produce/setpoint.mjs +113 -0
  125. package/dist/cli/produce/setpoint.mjs.map +1 -0
  126. package/dist/cli/produce/verification-ttl.d.mts +75 -0
  127. package/dist/cli/produce/verification-ttl.d.mts.map +1 -0
  128. package/dist/cli/produce/verification-ttl.mjs +169 -0
  129. package/dist/cli/produce/verification-ttl.mjs.map +1 -0
  130. package/dist/cli/release-notes/ship-autodraft.mjs +2 -2
  131. package/dist/cli/roadmap/{conductor-view.d.mts → showrunner-view.d.mts} +3 -3
  132. package/dist/cli/roadmap/showrunner-view.d.mts.map +1 -0
  133. package/dist/cli/roadmap/{conductor-view.mjs → showrunner-view.mjs} +7 -7
  134. package/dist/cli/roadmap/showrunner-view.mjs.map +1 -0
  135. package/dist/cli/variant/gallery.d.mts.map +1 -1
  136. package/dist/cli/variant/gallery.mjs +7 -3
  137. package/dist/cli/variant/gallery.mjs.map +1 -1
  138. package/dist/plugin/.claude-plugin/plugin.json +2 -1
  139. package/dist/plugin/agents/apt-executor.md +6 -0
  140. package/dist/plugin/agents/apt-planner.md +3 -2
  141. package/dist/plugin/skills/apt/SKILL.md +112 -38
  142. package/dist/plugin/skills/apt-close-task/SKILL.md +2 -2
  143. package/dist/plugin/skills/apt-debug/SKILL.md +22 -24
  144. package/dist/plugin/skills/apt-execute/SKILL.md +35 -26
  145. package/dist/plugin/skills/apt-fan-out/SKILL.md +4 -4
  146. package/dist/plugin/skills/apt-handoff/SKILL.md +1 -1
  147. package/dist/plugin/skills/apt-mockup/SKILL.md +1 -1
  148. package/dist/plugin/skills/apt-plan/SKILL.md +5 -5
  149. package/dist/plugin/skills/apt-plan/adapters/{conductor.md → showrunner.md} +16 -16
  150. package/dist/plugin/skills/apt-produce/SKILL.md +606 -0
  151. package/dist/plugin/skills/apt-quick/SKILL.md +27 -33
  152. package/dist/plugin/skills/apt-review/SKILL.md +14 -11
  153. package/dist/plugin/skills/apt-run/SKILL.md +132 -3
  154. package/dist/plugin/skills/apt-ship/SKILL.md +29 -5
  155. package/dist/plugin/skills/apt-spar/SKILL.md +5 -3
  156. package/dist/plugin/skills/apt-watch-ci/SKILL.md +6 -4
  157. package/dist/schemas/feature-registry.d.ts.map +1 -1
  158. package/dist/schemas/feature-registry.js +34 -3
  159. package/dist/schemas/feature-registry.js.map +1 -1
  160. package/dist/types/config.d.ts +8 -5
  161. package/dist/types/config.d.ts.map +1 -1
  162. package/package.json +4 -4
  163. package/prompts/{conductor-framework-context.md → showrunner-framework-context.md} +1 -1
  164. package/prompts/{conductor-status-check.md → showrunner-status-check.md} +1 -1
  165. package/prompts/{conductor-sub-agent.md → showrunner-sub-agent.md} +6 -6
  166. package/prompts/{conductor-system.md → showrunner-system.md} +8 -8
  167. package/skills/apt/SKILL.md +112 -38
  168. package/skills/apt-close-task/SKILL.md +2 -2
  169. package/skills/apt-debug/SKILL.md +22 -24
  170. package/skills/apt-execute/SKILL.md +35 -26
  171. package/skills/apt-fan-out/SKILL.md +4 -4
  172. package/skills/apt-handoff/SKILL.md +1 -1
  173. package/skills/apt-mockup/SKILL.md +1 -1
  174. package/skills/apt-plan/SKILL.md +5 -5
  175. package/skills/apt-plan/adapters/{conductor.md → showrunner.md} +16 -16
  176. package/skills/apt-produce/SKILL.md +606 -0
  177. package/skills/apt-quick/SKILL.md +27 -33
  178. package/skills/apt-review/SKILL.md +14 -11
  179. package/skills/apt-run/SKILL.md +132 -3
  180. package/skills/apt-ship/SKILL.md +29 -5
  181. package/skills/apt-spar/SKILL.md +5 -3
  182. package/skills/apt-watch-ci/SKILL.md +6 -4
  183. package/src/cli/artifacts/self-stage.mjs +2 -1
  184. package/src/cli/cli-wrappers/features-reconcile.mjs +9 -0
  185. package/src/cli/commands/ci-watch.mjs +51 -2
  186. package/src/cli/commands/commit.mjs +3 -3
  187. package/src/cli/commands/event.mjs +16 -16
  188. package/src/cli/commands/features-reconcile.mjs +157 -0
  189. package/src/cli/commands/health-check.mjs +2 -2
  190. package/src/cli/commands/merge-integrate.mjs +3 -3
  191. package/src/cli/commands/produce.mjs +1466 -0
  192. package/src/cli/commands/task.mjs +482 -285
  193. package/src/cli/coordination/auto-emit-artifact-ready.mjs +5 -5
  194. package/src/cli/coordination/event-schema.d.ts +4 -2
  195. package/src/cli/coordination/event-schema.mjs +276 -21
  196. package/src/cli/coordination/store.mjs +4 -4
  197. package/src/cli/dispatch.mjs +4 -2
  198. package/src/cli/features/area-shape.mjs +140 -0
  199. package/src/cli/features/delta.mjs +625 -0
  200. package/src/cli/features/reconcile.mjs +1169 -0
  201. package/src/cli/features/surface-map.mjs +192 -0
  202. package/src/cli/features/write-root.mjs +140 -0
  203. package/src/cli/gate/gates/features-reconciled.mjs +70 -0
  204. package/src/cli/gate/gates/index.mjs +1 -0
  205. package/src/cli/help.mjs +31 -1
  206. package/src/cli/install/legacy-paths.mjs +2 -0
  207. package/src/cli/produce/blind-probe.mjs +245 -0
  208. package/src/cli/produce/claim.mjs +543 -0
  209. package/src/cli/produce/done-gate.mjs +238 -0
  210. package/src/cli/produce/events.mjs +131 -0
  211. package/src/cli/produce/evidence-oracle.mjs +133 -0
  212. package/src/cli/produce/ledger.mjs +284 -0
  213. package/src/cli/produce/probe-family.mjs +168 -0
  214. package/src/cli/produce/projection.mjs +105 -0
  215. package/src/cli/produce/run-id.mjs +84 -0
  216. package/src/cli/produce/saga.mjs +303 -0
  217. package/src/cli/produce/scheduler.mjs +423 -0
  218. package/src/cli/produce/setpoint.mjs +122 -0
  219. package/src/cli/produce/verification-ttl.mjs +191 -0
  220. package/src/cli/release-notes/ship-autodraft.mjs +2 -2
  221. package/src/cli/roadmap/showrunner-view.d.ts +10 -0
  222. package/src/cli/roadmap/{conductor-view.mjs → showrunner-view.mjs} +6 -6
  223. package/src/cli/variant/gallery.mjs +7 -3
  224. package/templates/aperant-claude-md-appendix.md +2 -2
  225. package/workflows/scan-features.md +17 -11
  226. package/dist/cli/cli-wrappers/features-audit.d.mts +0 -2
  227. package/dist/cli/cli-wrappers/features-audit.d.mts.map +0 -1
  228. package/dist/cli/cli-wrappers/features-audit.mjs +0 -8
  229. package/dist/cli/cli-wrappers/features-audit.mjs.map +0 -1
  230. package/dist/cli/commands/features-audit.d.mts.map +0 -1
  231. package/dist/cli/commands/features-audit.mjs +0 -293
  232. package/dist/cli/commands/features-audit.mjs.map +0 -1
  233. package/dist/cli/features/registry-audit.d.mts +0 -56
  234. package/dist/cli/features/registry-audit.d.mts.map +0 -1
  235. package/dist/cli/features/registry-audit.mjs +0 -264
  236. package/dist/cli/features/registry-audit.mjs.map +0 -1
  237. package/dist/cli/roadmap/conductor-view.d.mts.map +0 -1
  238. package/dist/cli/roadmap/conductor-view.mjs.map +0 -1
  239. package/src/cli/cli-wrappers/features-audit.mjs +0 -8
  240. package/src/cli/commands/features-audit.mjs +0 -302
  241. package/src/cli/features/registry-audit.mjs +0 -254
  242. package/src/cli/roadmap/conductor-view.d.ts +0 -10
@@ -0,0 +1,518 @@
1
+ /**
2
+ * @internal
3
+ * produce/claim.mjs — the Claim Envelope: a provider-neutral interop SHAPE +
4
+ * a data-driven profile registry + an event-sourced claim ledger (M6).
5
+ *
6
+ * A Claim Envelope captures a durable, bounded, expiring claim (the `lesson`
7
+ * profile is the only one M6 ships). It is NOT a 4th persistence store (parent
8
+ * D-02/D-03, ID-M6-01): the ledger reuses the EXACT substrate M1/M2 already use —
9
+ * a per-record immutable content file at `.aperant/produce/<run-id>/claims/<id>.json`
10
+ * written ONCE via `openSync(path, 'wx')` (mirrors setpoint.mjs / blind-probe.mjs),
11
+ * referenced by `content_hash` from an append-only `produce.claim.declared` event,
12
+ * and PROJECTED by a `projectClaims` fold parallel to `ledger.mjs::projectLedger`.
13
+ * The roadmap projection still folds `produce.roadmap.*` ONLY, so claim ops never
14
+ * enter the roadmap the Showrunner re-reads (blindness preserved).
15
+ *
16
+ * Generalization is REGISTRY DATA, never a code fork (ID-M6-02): `CLAIM_PROFILES`
17
+ * maps a profile id → `{ requiredFields, validate }`, and `validateClaimEnvelope`
18
+ * dispatches on `envelope.profile` via the registry — there is NO hardcoded
19
+ * `if (profile === 'lesson')` branch, so a 2nd profile is one map entry and an
20
+ * unknown profile fails closed.
21
+ *
22
+ * Deterministic, node-only, ZERO model id — it is pure fold/validation math over
23
+ * the log + per-record files, like ledger.mjs / scheduler.mjs (ID-M6-08).
24
+ */
25
+ import { createHash } from 'node:crypto';
26
+ import { closeSync, existsSync, fsyncSync, mkdirSync, openSync, readFileSync, writeSync, } from 'node:fs';
27
+ import { dirname, join } from 'node:path';
28
+ import { appendProduceEvent, readProduceRunEventsMatching } from './events.mjs';
29
+ import { resolveRunDir, slugFromOutcome } from './run-id.mjs';
30
+ /** Plain (non-array, non-null) object guard. */
31
+ function isPlainObject(v) {
32
+ return v != null && typeof v === 'object' && !Array.isArray(v);
33
+ }
34
+ /** Plain object carrying at least one own key. */
35
+ function isNonEmptyObject(v) {
36
+ return isPlainObject(v) && Object.keys(v).length > 0;
37
+ }
38
+ /** A bound is a non-empty string / non-empty array / non-empty object. */
39
+ function isNonEmptyBound(v) {
40
+ if (typeof v === 'string')
41
+ return v.trim().length > 0;
42
+ if (Array.isArray(v))
43
+ return v.length > 0;
44
+ if (isPlainObject(v))
45
+ return Object.keys(v).length > 0;
46
+ return false;
47
+ }
48
+ /**
49
+ * A scope is BOUNDED iff it is a plain object, `global !== true`, and carries at
50
+ * least one non-`global` key with a non-empty bound (anti-windup, ID-M6-05). A
51
+ * `{ global: true }` scope or a scope with no actual bound is REJECTED.
52
+ */
53
+ function isBoundedScope(scope) {
54
+ if (!isPlainObject(scope))
55
+ return false;
56
+ if (scope.global === true)
57
+ return false;
58
+ return Object.keys(scope).some((k) => k !== 'global' && isNonEmptyBound(scope[k]));
59
+ }
60
+ /**
61
+ * An expiry object carries a decay path: `expires_at` (non-empty string) OR
62
+ * `revalidate_against_head` (any truthy value). A lesson with no expiry/decay
63
+ * path is REJECTED (anti-corrosion, ID-M6-04).
64
+ */
65
+ function hasExpiry(expiry) {
66
+ if (!isPlainObject(expiry))
67
+ return false;
68
+ const hasExpiresAt = typeof expiry.expires_at === 'string' && expiry.expires_at.trim().length > 0;
69
+ const hasRevalidate = expiry.revalidate_against_head != null && expiry.revalidate_against_head !== false;
70
+ return hasExpiresAt || hasRevalidate;
71
+ }
72
+ /** The verifiable plan requirement — a non-empty string / array / object. */
73
+ function isNonEmptyVerifier(rv) {
74
+ if (typeof rv === 'string')
75
+ return rv.trim().length > 0;
76
+ if (Array.isArray(rv))
77
+ return rv.length > 0;
78
+ if (isPlainObject(rv))
79
+ return Object.keys(rv).length > 0;
80
+ return false;
81
+ }
82
+ /**
83
+ * The `lesson` profile validator (ID-M6-03). REQUIRES all 6 AC15 fields and
84
+ * REJECTS fail-closed (never throws): missing provenance; empty preconditions
85
+ * (unconditional rule — bounded-critic clamp); global/unbounded scope
86
+ * (anti-windup); missing expiry (anti-corrosion); missing negative_evidence
87
+ * field; empty resolution_verifier. Returns `{ ok:false, reason }`.
88
+ *
89
+ * @param {Record<string, unknown>} env
90
+ * @returns {{ ok: true } | { ok: false, reason: string }}
91
+ */
92
+ function validateLessonEnvelope(env) {
93
+ if (!isNonEmptyObject(env.provenance))
94
+ return { ok: false, reason: 'missing_provenance' };
95
+ if (!Array.isArray(env.preconditions) || env.preconditions.length === 0)
96
+ return { ok: false, reason: 'empty_preconditions' };
97
+ if (!isBoundedScope(env.scope))
98
+ return { ok: false, reason: 'unbounded_scope' };
99
+ if (!hasExpiry(env.expiry))
100
+ return { ok: false, reason: 'missing_expiry' };
101
+ if (!Array.isArray(env.negative_evidence))
102
+ return { ok: false, reason: 'missing_negative_evidence' };
103
+ if (!isNonEmptyVerifier(env.resolution_verifier))
104
+ return { ok: false, reason: 'empty_resolution_verifier' };
105
+ return { ok: true };
106
+ }
107
+ /**
108
+ * The data-driven profile registry (ID-M6-02). A profile is one map entry
109
+ * (`{ requiredFields, validate }`) — adding a 2nd is data, not a code fork. M6
110
+ * SHIPS only `lesson`; the generalization is PROVEN by a test that injects a
111
+ * trivial second profile via `validateClaimEnvelope`'s `profiles` arg.
112
+ */
113
+ export const CLAIM_PROFILES = {
114
+ lesson: {
115
+ requiredFields: [
116
+ 'provenance',
117
+ 'preconditions',
118
+ 'scope',
119
+ 'expiry',
120
+ 'negative_evidence',
121
+ 'resolution_verifier',
122
+ ],
123
+ validate: validateLessonEnvelope,
124
+ },
125
+ };
126
+ /**
127
+ * Validate a Claim Envelope by dispatching on `envelope.profile` through the
128
+ * REGISTRY (never a hardcoded profile branch — ID-M6-02). An unknown/absent
129
+ * profile fails closed (`{ ok:false, reason:'unknown_profile' }`). Never throws.
130
+ *
131
+ * @param {Record<string, unknown>} envelope
132
+ * @param {{ profiles?: Record<string, { validate: (env: Record<string, unknown>) => { ok: boolean, reason?: string } }> }} [opts]
133
+ * @returns {{ ok: true } | { ok: false, reason: string }}
134
+ */
135
+ export function validateClaimEnvelope(envelope, { profiles = CLAIM_PROFILES } = {}) {
136
+ const env = isPlainObject(envelope) ? envelope : {};
137
+ const profileId = typeof env.profile === 'string' ? env.profile : '';
138
+ const spec = profiles[profileId];
139
+ if (!spec || typeof spec.validate !== 'function')
140
+ return { ok: false, reason: 'unknown_profile' };
141
+ return spec.validate(env);
142
+ }
143
+ /**
144
+ * Mint a claim id: `<slug-of-text>-<rand>`. Reuses `slugFromOutcome` + a short
145
+ * random suffix (mirrors ledger.mjs::mintCriterionId) so two claims minted from
146
+ * the same text never collide. Falls back to the profile when text is empty.
147
+ *
148
+ * @param {string} profile
149
+ * @param {string} text
150
+ * @returns {string}
151
+ */
152
+ export function mintClaimId(profile, text) {
153
+ const slug = slugFromOutcome(text || profile || 'claim');
154
+ return `${slug}-${Math.random().toString(36).slice(2, 8)}`;
155
+ }
156
+ /** sha256 of the canonical JSON of the claim content (the immutable hash stamp). */
157
+ function computeClaimContentHash(content) {
158
+ return createHash('sha256')
159
+ .update(JSON.stringify(content ?? null))
160
+ .digest('hex');
161
+ }
162
+ /** The claims/<claim-id>.json path for a run + claim. */
163
+ export function claimPathFor(projectDir, runId, claimId) {
164
+ return join(resolveRunDir(projectDir, runId), 'claims', `${claimId}.json`);
165
+ }
166
+ /** Read + parse a frozen claim record. Returns null when absent or malformed. */
167
+ export function readClaim(projectDir, runId, claimId) {
168
+ const p = claimPathFor(projectDir, runId, claimId);
169
+ if (!existsSync(p))
170
+ return null;
171
+ try {
172
+ return JSON.parse(readFileSync(p, 'utf-8'));
173
+ }
174
+ catch {
175
+ return null;
176
+ }
177
+ }
178
+ /**
179
+ * Exclusive-create write of the frozen claim record on the FINAL path (NOT
180
+ * tmp+rename), so a SECOND write throws EEXIST — the claim content is immutable
181
+ * (mirrors setpoint.mjs::writeSetpointExclusive / blind-probe.mjs).
182
+ */
183
+ function writeClaimExclusive(claimPath, record) {
184
+ mkdirSync(dirname(claimPath), { recursive: true });
185
+ const payload = `${JSON.stringify(record, null, 2)}\n`;
186
+ const fd = openSync(claimPath, 'wx'); // throws EEXIST when already frozen
187
+ try {
188
+ writeSync(fd, payload, 0, 'utf-8');
189
+ fsyncSync(fd);
190
+ }
191
+ finally {
192
+ closeSync(fd);
193
+ }
194
+ }
195
+ /**
196
+ * Freeze a Claim Envelope, idempotently. VALIDATES first (refuses to freeze an
197
+ * invalid envelope — fail-closed), computes `content_hash = sha256(envelope)`,
198
+ * writes `claims/<claim-id>.json` exclusive-create, and on a FRESH freeze appends
199
+ * `produce.claim.declared {run_id, profile, claim_id, content_hash}` (content_hash
200
+ * only — the full envelope lives in the frozen file, ID-M6-07). A second freeze
201
+ * of the same claim id returns the byte-identical stored record (`reused: true`)
202
+ * and never re-logs. The resolved `profile` (explicit arg or `envelope.profile`)
203
+ * is authoritative for validation dispatch + the stored/logged profile.
204
+ *
205
+ * @param {string} projectDir
206
+ * @param {string} runId
207
+ * @param {{ profile?: string, envelope: Record<string, unknown>, claimId?: string }} args
208
+ * @param {{ profiles?: object, now?: Date }} [opts]
209
+ * @returns {{ ok: true, reused: boolean, claim_id: string, profile: string | null, content_hash: string }
210
+ * | { ok: false, reason: string }}
211
+ */
212
+ export function freezeClaim(projectDir, runId, { profile, envelope, claimId } = {}, { profiles = CLAIM_PROFILES, now = new Date() } = {}) {
213
+ const env = isPlainObject(envelope) ? envelope : {};
214
+ const resolvedProfile = typeof profile === 'string' && profile
215
+ ? profile
216
+ : typeof env.profile === 'string'
217
+ ? env.profile
218
+ : null;
219
+ // The resolved profile is authoritative — validate + store + log agree.
220
+ const envelopeForValidation = resolvedProfile ? { ...env, profile: resolvedProfile } : env;
221
+ const verdict = validateClaimEnvelope(envelopeForValidation, { profiles });
222
+ if (!verdict.ok)
223
+ return { ok: false, reason: verdict.reason };
224
+ const resolvedClaimId = typeof claimId === 'string' && claimId
225
+ ? claimId
226
+ : typeof env.id === 'string' && env.id
227
+ ? env.id
228
+ : mintClaimId(resolvedProfile ?? 'claim', typeof env.resolution_verifier === 'string' ? env.resolution_verifier : resolvedProfile);
229
+ const existing = readClaim(projectDir, runId, resolvedClaimId);
230
+ if (existing)
231
+ return {
232
+ ok: true,
233
+ reused: true,
234
+ claim_id: resolvedClaimId,
235
+ profile: existing.profile ?? resolvedProfile,
236
+ content_hash: existing.content_hash,
237
+ };
238
+ const contentHash = computeClaimContentHash(envelopeForValidation);
239
+ const record = {
240
+ run_id: runId,
241
+ claim_id: resolvedClaimId,
242
+ profile: resolvedProfile,
243
+ frozen_at: now.toISOString(),
244
+ content_hash: contentHash,
245
+ // The full claim content lives HERE — blind to the event log (ID-M6-07).
246
+ envelope: envelopeForValidation,
247
+ };
248
+ try {
249
+ writeClaimExclusive(claimPathFor(projectDir, runId, resolvedClaimId), record);
250
+ }
251
+ catch (e) {
252
+ // Lost a concurrent race — the winner's file is authoritative; re-read it
253
+ // byte-identically rather than overwriting (mirrors freezeSetpoint).
254
+ if (e && e.code === 'EEXIST') {
255
+ const winner = readClaim(projectDir, runId, resolvedClaimId);
256
+ if (winner)
257
+ return {
258
+ ok: true,
259
+ reused: true,
260
+ claim_id: resolvedClaimId,
261
+ profile: winner.profile ?? resolvedProfile,
262
+ content_hash: winner.content_hash,
263
+ };
264
+ }
265
+ throw e;
266
+ }
267
+ // Announce by hash + profile ONLY — never the content (ID-M6-07).
268
+ appendProduceEvent(projectDir, 'produce.claim.declared', {
269
+ run_id: runId,
270
+ profile: resolvedProfile,
271
+ claim_id: resolvedClaimId,
272
+ content_hash: contentHash,
273
+ });
274
+ return {
275
+ ok: true,
276
+ reused: false,
277
+ claim_id: resolvedClaimId,
278
+ profile: resolvedProfile,
279
+ content_hash: contentHash,
280
+ };
281
+ }
282
+ /** The closed set of consumption-delta target kinds (mirrors ALLOWED_CLAIM_TARGET_KINDS). */
283
+ export const CLAIM_TARGET_KINDS = ['acceptance_criterion', 'subtask', 'proof_obligation'];
284
+ /**
285
+ * Fold the run's claim ledger from the append-only log — a SEPARATE fold parallel
286
+ * to `ledger.mjs::projectLedger` / `saga.mjs::projectSaga` (the roadmap projection
287
+ * still folds `produce.roadmap.*` ONLY, so claim ops never enter the roadmap the
288
+ * Showrunner re-reads). A `produce.claim.declared` seeds an ACTIVE claim (in
289
+ * first-seen order); a `produce.claim.expired` advances it to `expired`;
290
+ * `produce.claim.consumed` is a forensic-only event that does NOT change status.
291
+ * Deterministic — two folds of the same log yield the identical ledger.
292
+ *
293
+ * @param {string} projectDir
294
+ * @param {string} runId
295
+ * @returns {{
296
+ * run_id: string,
297
+ * claims: Array<{ claim_id: string, profile: string | null, content_hash: string | null, status: 'active' | 'expired' }>,
298
+ * active_count: number,
299
+ * expired_count: number,
300
+ * updated_at: string | null,
301
+ * }}
302
+ */
303
+ export function projectClaims(projectDir, runId) {
304
+ const events = readProduceRunEventsMatching(projectDir, runId, (op) => op.startsWith('produce.claim.'));
305
+ const byId = new Map();
306
+ const order = [];
307
+ let updatedAt = null;
308
+ for (const e of events) {
309
+ const d = e.data || {};
310
+ const cid = typeof d.claim_id === 'string' ? d.claim_id : null;
311
+ if (e.op === 'produce.claim.declared') {
312
+ if (cid && !byId.has(cid)) {
313
+ byId.set(cid, {
314
+ claim_id: cid,
315
+ profile: typeof d.profile === 'string' ? d.profile : null,
316
+ content_hash: typeof d.content_hash === 'string' ? d.content_hash : null,
317
+ status: 'active',
318
+ });
319
+ order.push(cid);
320
+ }
321
+ }
322
+ else if (e.op === 'produce.claim.expired') {
323
+ if (cid && byId.has(cid))
324
+ byId.get(cid).status = 'expired';
325
+ }
326
+ if (typeof e.t === 'string')
327
+ updatedAt = e.t;
328
+ }
329
+ const claims = order.map((cid) => byId.get(cid));
330
+ return {
331
+ run_id: runId,
332
+ claims,
333
+ active_count: claims.filter((c) => c.status === 'active').length,
334
+ expired_count: claims.filter((c) => c.status === 'expired').length,
335
+ updated_at: updatedAt,
336
+ };
337
+ }
338
+ /**
339
+ * The DEFAULT HEAD re-validation predicate (ID-M6-04) — a deterministic
340
+ * path-exists / grep against the working tree, NEVER an LLM judgment (mirrors the
341
+ * injected `codexDeps` in probe-family.mjs / the injected existence predicate in
342
+ * resolveResumeCwd). `check` is `{ path?, pattern? }` (or a bare path string).
343
+ * Returns false when the referenced file/pattern no longer matches HEAD.
344
+ *
345
+ * @param {unknown} check
346
+ * @returns {boolean}
347
+ */
348
+ function defaultHeadCheck(check) {
349
+ const spec = typeof check === 'string' ? { path: check } : isPlainObject(check) ? check : {};
350
+ if (typeof spec.path === 'string' && spec.path) {
351
+ if (!existsSync(spec.path))
352
+ return false;
353
+ if (typeof spec.pattern === 'string' && spec.pattern) {
354
+ try {
355
+ return readFileSync(spec.path, 'utf-8').includes(spec.pattern);
356
+ }
357
+ catch {
358
+ return false;
359
+ }
360
+ }
361
+ return true;
362
+ }
363
+ // No actionable check descriptor → nothing to invalidate (still valid).
364
+ return true;
365
+ }
366
+ /** One precondition matches ctx iff every key equals (or set-includes) the ctx value. */
367
+ function matchOne(cond, ctx) {
368
+ if (!isPlainObject(cond))
369
+ return false;
370
+ return Object.keys(cond).every((k) => {
371
+ const expected = cond[k];
372
+ const actual = ctx[k];
373
+ if (Array.isArray(expected))
374
+ return expected.includes(actual);
375
+ if (Array.isArray(actual))
376
+ return actual.includes(expected);
377
+ return actual === expected;
378
+ });
379
+ }
380
+ /**
381
+ * The claim FIRES (its trigger matches) iff EVERY precondition matches ctx
382
+ * (conjunction — a narrow gate, bounded-critic ID-M6-05). An absent/empty
383
+ * preconditions list is vacuously matched (a validated lesson always has ≥1).
384
+ */
385
+ function preconditionsMatch(preconditions, ctx) {
386
+ if (!Array.isArray(preconditions) || preconditions.length === 0)
387
+ return true;
388
+ const c = isPlainObject(ctx) ? ctx : {};
389
+ return preconditions.every((cond) => matchOne(cond, c));
390
+ }
391
+ /**
392
+ * Decide whether a claim may be consumed against a ctx (ID-M6-04, anti-corrosion).
393
+ * DETERMINISTIC (no LLM). SKIPS with a reason when: the claim is time-expired
394
+ * (`now() > expiry.expires_at` → `expired`); the claim's `revalidate_against_head`
395
+ * check no longer matches HEAD (`headCheck(check) === false` → `head_invalidated`);
396
+ * or the preconditions don't match ctx (`precondition_unmatched`). Otherwise
397
+ * `{ consume: true }`. `now` + `headCheck` are INJECTED (default now = new Date,
398
+ * default headCheck = the working-tree path-exists/grep).
399
+ *
400
+ * @param {Record<string, unknown>} claim — the claim ENVELOPE (carries expiry + preconditions).
401
+ * @param {Record<string, unknown>} [ctx]
402
+ * @param {{ now?: () => Date, headCheck?: (check: unknown) => boolean }} [deps]
403
+ * @returns {{ consume: true } | { consume: false, reason: string }}
404
+ */
405
+ export function evaluateClaimForConsumption(claim, ctx = {}, deps = {}) {
406
+ const now = typeof deps.now === 'function' ? deps.now : () => new Date();
407
+ const headCheck = typeof deps.headCheck === 'function' ? deps.headCheck : defaultHeadCheck;
408
+ const env = isPlainObject(claim) ? claim : {};
409
+ const expiry = isPlainObject(env.expiry) ? env.expiry : {};
410
+ // (1) Time expiry.
411
+ if (typeof expiry.expires_at === 'string' && expiry.expires_at) {
412
+ const expiresAt = new Date(expiry.expires_at).getTime();
413
+ if (Number.isFinite(expiresAt) && now().getTime() > expiresAt) {
414
+ return { consume: false, reason: 'expired' };
415
+ }
416
+ }
417
+ // (2) HEAD re-validation (anti-corrosion) — deterministic, never an LLM.
418
+ if (expiry.revalidate_against_head != null && expiry.revalidate_against_head !== false) {
419
+ if (!headCheck(expiry.revalidate_against_head)) {
420
+ return { consume: false, reason: 'head_invalidated' };
421
+ }
422
+ }
423
+ // (3) Precondition match against ctx (the trigger).
424
+ if (!preconditionsMatch(env.preconditions, ctx)) {
425
+ return { consume: false, reason: 'precondition_unmatched' };
426
+ }
427
+ return { consume: true };
428
+ }
429
+ /** Read the frozen claim ENVELOPE (the `.envelope` payload), null when absent/malformed. */
430
+ function readClaimEnvelope(projectDir, runId, claimId) {
431
+ const record = readClaim(projectDir, runId, claimId);
432
+ if (!record)
433
+ return null;
434
+ return isPlainObject(record.envelope) ? record.envelope : null;
435
+ }
436
+ /**
437
+ * Derive the bounded consumption DELTA from a claim envelope's
438
+ * `resolution_verifier` ONLY (ID-M6-06 — the down-projection). Returns
439
+ * `[{ kind, requirement, ref? }]` where `kind` is clamped to the closed
440
+ * CLAIM_TARGET_KINDS set (fail-closed default `acceptance_criterion`) and
441
+ * `requirement` is a bounded string taken FROM `resolution_verifier`. This
442
+ * function reads NOTHING ELSE off the envelope — never `provenance`,
443
+ * `negative_evidence`, `preconditions`, or a raw body — so a sentinel placed in
444
+ * those fields can never reach the consume output (the sentinel-non-leak
445
+ * invariant). NO raw-lesson-text → prompt concatenation sink lives here.
446
+ *
447
+ * @param {Record<string, unknown>} envelope
448
+ * @returns {Array<{ kind: string, requirement: string, ref?: string }>}
449
+ */
450
+ function deriveTargets(envelope) {
451
+ const rv = isPlainObject(envelope) ? envelope.resolution_verifier : undefined;
452
+ const raw = Array.isArray(rv) ? rv : [rv];
453
+ const targets = [];
454
+ for (const item of raw) {
455
+ if (typeof item === 'string' && item.length > 0) {
456
+ targets.push({ kind: 'acceptance_criterion', requirement: item });
457
+ }
458
+ else if (isPlainObject(item)) {
459
+ const kind = CLAIM_TARGET_KINDS.includes(item.kind) ? item.kind : 'acceptance_criterion';
460
+ const requirement = typeof item.requirement === 'string' && item.requirement
461
+ ? item.requirement
462
+ : typeof item.text === 'string'
463
+ ? item.text
464
+ : '';
465
+ const target = { kind, requirement };
466
+ if (typeof item.ref === 'string' && item.ref)
467
+ target.ref = item.ref;
468
+ targets.push(target);
469
+ }
470
+ }
471
+ return targets;
472
+ }
473
+ /**
474
+ * Consume the run's ACTIVE claims against a ctx (ID-M6-06 — THE M6 invariant).
475
+ * For each active claim, evaluate it; a consumable claim emits ONE bounded delta
476
+ * `{ claim_id, profile, targets: [{ kind, requirement, ref? }] }` where every
477
+ * `targets[].kind ∈ CLAIM_TARGET_KINDS` and `requirement` is derived FROM
478
+ * `resolution_verifier` — a projection DOWN. The output MUST NOT carry the claim's
479
+ * `provenance` / `negative_evidence` / `preconditions` / body (never a context
480
+ * paste). Skipped claims (expired / head_invalidated / precondition_unmatched /
481
+ * unreadable) surface under `skipped[]` with a reason. PURE — appends no event
482
+ * (the CLI records `produce.claim.consumed` per target for the forensic trail).
483
+ *
484
+ * @param {string} projectDir
485
+ * @param {string} runId
486
+ * @param {Record<string, unknown>} [ctx]
487
+ * @param {{ now?: () => Date, headCheck?: (check: unknown) => boolean }} [deps]
488
+ * @returns {{
489
+ * consumed: Array<{ claim_id: string, profile: string | null, targets: Array<{ kind: string, requirement: string, ref?: string }> }>,
490
+ * skipped: Array<{ claim_id: string, reason: string }>,
491
+ * }}
492
+ */
493
+ export function consumeClaims(projectDir, runId, ctx = {}, deps = {}) {
494
+ const ledger = projectClaims(projectDir, runId);
495
+ const consumed = [];
496
+ const skipped = [];
497
+ for (const summary of ledger.claims) {
498
+ if (summary.status !== 'active')
499
+ continue; // expired claims never consume
500
+ const envelope = readClaimEnvelope(projectDir, runId, summary.claim_id);
501
+ if (!envelope) {
502
+ skipped.push({ claim_id: summary.claim_id, reason: 'unreadable_claim' });
503
+ continue;
504
+ }
505
+ const verdict = evaluateClaimForConsumption(envelope, ctx, deps);
506
+ if (!verdict.consume) {
507
+ skipped.push({ claim_id: summary.claim_id, reason: verdict.reason });
508
+ continue;
509
+ }
510
+ consumed.push({
511
+ claim_id: summary.claim_id,
512
+ profile: summary.profile ?? (typeof envelope.profile === 'string' ? envelope.profile : null),
513
+ targets: deriveTargets(envelope),
514
+ });
515
+ }
516
+ return { consumed, skipped };
517
+ }
518
+ //# sourceMappingURL=claim.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claim.mjs","sourceRoot":"","sources":["../../../src/cli/produce/claim.mjs"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EACN,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,SAAS,GACT,MAAM,SAAS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tB,OAAO,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAA;YACpE,SAAQ;QACT,CAAC;QACD,QAAQ,CAAC,IAAI,CAAC;YACb,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,CAAC,OAAO,QAAQ,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YAC5F,OAAO,EAAE,aAAa,CAAC,QAAQ,CAAC;SAChC,CAAC,CAAA;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Evaluate the RECORDED gate seals for a milestone (no verify-proof file read —
3
+ * that live half is added by `adjudicateDone`). Pure read.
4
+ *
5
+ * @param {string} projectDir
6
+ * @param {string} runId
7
+ * @param {string} milestoneId
8
+ * @returns {{
9
+ * implementer_family: string | null,
10
+ * oracle_pass_cross_family: boolean,
11
+ * probe_pass_cross_family: boolean,
12
+ * frozen_cross_family: boolean,
13
+ * blind_gate: boolean,
14
+ * }}
15
+ */
16
+ export function evaluateRecordedGates(projectDir: string, runId: string, milestoneId: string): {
17
+ implementer_family: string | null;
18
+ oracle_pass_cross_family: boolean;
19
+ probe_pass_cross_family: boolean;
20
+ frozen_cross_family: boolean;
21
+ blind_gate: boolean;
22
+ };
23
+ /**
24
+ * Adjudicate a milestone `done` (ID-M2-04). `done` accepted iff:
25
+ * visible_gate = verify-proof verdict === 'approved' AND recorded
26
+ * produce.oracle.judged.verdict === 'pass' with oracle_family !== implementer;
27
+ * blind_gate = recorded produce.probe.run.result === 'pass' with
28
+ * probe_family !== implementer AND a produce.probe.frozen exists with
29
+ * author_family !== implementer.
30
+ * visible && blind → append produce.oracle.verdict{done} +
31
+ * produce.roadmap.milestone_status_changed{done} + refresh the cache → ok.
32
+ * visible && !blind → append produce.oracle.probe_gap → err (stays open).
33
+ * !visible → err not-adjudicable. Absent implementer → err fail-closed.
34
+ *
35
+ * @param {{ projectDir: string, runId: string, milestoneId: string, verdictPath: string }} args
36
+ * @returns {{ ok: true, milestone_id: string, roadmap: object }
37
+ * | { ok: false, reason: string, visible_gate: boolean, blind_gate: boolean, detail?: object }}
38
+ */
39
+ export function adjudicateDone({ projectDir, runId, milestoneId, verdictPath }: {
40
+ projectDir: string;
41
+ runId: string;
42
+ milestoneId: string;
43
+ verdictPath: string;
44
+ }): {
45
+ ok: true;
46
+ milestone_id: string;
47
+ roadmap: object;
48
+ } | {
49
+ ok: false;
50
+ reason: string;
51
+ visible_gate: boolean;
52
+ blind_gate: boolean;
53
+ detail?: object;
54
+ };
55
+ /**
56
+ * The reward-hacking canary (ID-M2-06 / AC10): green-on-visible MINUS
57
+ * green-on-blind over the run's milestones, from RECORDED seals. Each
58
+ * `produce.oracle.probe_gap` is one visible-pass + blind-fail near-miss. The
59
+ * metric surfaces the divergence — it does not average it away.
60
+ *
61
+ * @param {string} projectDir
62
+ * @param {string} runId
63
+ * @returns {{
64
+ * run_id: string,
65
+ * green_on_visible: number,
66
+ * green_on_blind: number,
67
+ * gap: number,
68
+ * probe_gap_events: number,
69
+ * per_milestone: Array<{ milestone_id: string, title: string, status: string, visible: boolean, blind: boolean, probe_gaps: number }>,
70
+ * }}
71
+ */
72
+ export function computeCanary(projectDir: string, runId: string): {
73
+ run_id: string;
74
+ green_on_visible: number;
75
+ green_on_blind: number;
76
+ gap: number;
77
+ probe_gap_events: number;
78
+ per_milestone: Array<{
79
+ milestone_id: string;
80
+ title: string;
81
+ status: string;
82
+ visible: boolean;
83
+ blind: boolean;
84
+ probe_gaps: number;
85
+ }>;
86
+ };
87
+ //# sourceMappingURL=done-gate.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"done-gate.d.mts","sourceRoot":"","s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