@wildorder/nightshift 0.16.0 → 0.18.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 (109) hide show
  1. package/README.md +289 -1
  2. package/dist/agent-runner.d.ts +95 -5
  3. package/dist/agent-runner.d.ts.map +1 -1
  4. package/dist/agent-runner.js +442 -32
  5. package/dist/agent-runner.js.map +1 -1
  6. package/dist/agent-session.d.ts +123 -0
  7. package/dist/agent-session.d.ts.map +1 -0
  8. package/dist/agent-session.js +114 -0
  9. package/dist/agent-session.js.map +1 -0
  10. package/dist/atomic-write.d.ts +18 -0
  11. package/dist/atomic-write.d.ts.map +1 -0
  12. package/dist/atomic-write.js +74 -0
  13. package/dist/atomic-write.js.map +1 -0
  14. package/dist/author.d.ts +118 -4
  15. package/dist/author.d.ts.map +1 -1
  16. package/dist/author.js +650 -163
  17. package/dist/author.js.map +1 -1
  18. package/dist/causal-analysis.d.ts +216 -0
  19. package/dist/causal-analysis.d.ts.map +1 -0
  20. package/dist/causal-analysis.js +786 -0
  21. package/dist/causal-analysis.js.map +1 -0
  22. package/dist/cli.js +22 -2
  23. package/dist/cli.js.map +1 -1
  24. package/dist/concurrency.d.ts +24 -0
  25. package/dist/concurrency.d.ts.map +1 -0
  26. package/dist/concurrency.js +28 -0
  27. package/dist/concurrency.js.map +1 -0
  28. package/dist/decider-review.d.ts +13 -1
  29. package/dist/decider-review.d.ts.map +1 -1
  30. package/dist/decider-review.js +21 -7
  31. package/dist/decider-review.js.map +1 -1
  32. package/dist/decision-ledger.d.ts +7 -0
  33. package/dist/decision-ledger.d.ts.map +1 -1
  34. package/dist/decision-ledger.js +25 -10
  35. package/dist/decision-ledger.js.map +1 -1
  36. package/dist/detect-package-manager.d.ts +10 -0
  37. package/dist/detect-package-manager.d.ts.map +1 -1
  38. package/dist/detect-package-manager.js +12 -0
  39. package/dist/detect-package-manager.js.map +1 -1
  40. package/dist/index.d.ts +8 -1
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +8 -1
  43. package/dist/index.js.map +1 -1
  44. package/dist/manifest.d.ts +24 -5
  45. package/dist/manifest.d.ts.map +1 -1
  46. package/dist/manifest.js +254 -108
  47. package/dist/manifest.js.map +1 -1
  48. package/dist/permits.d.ts +18 -0
  49. package/dist/permits.d.ts.map +1 -1
  50. package/dist/permits.js +155 -0
  51. package/dist/permits.js.map +1 -1
  52. package/dist/preflight.d.ts +3 -0
  53. package/dist/preflight.d.ts.map +1 -1
  54. package/dist/preflight.js +73 -57
  55. package/dist/preflight.js.map +1 -1
  56. package/dist/prompt-telemetry.d.ts +64 -0
  57. package/dist/prompt-telemetry.d.ts.map +1 -0
  58. package/dist/prompt-telemetry.js +112 -0
  59. package/dist/prompt-telemetry.js.map +1 -0
  60. package/dist/provider-telemetry.d.ts +106 -0
  61. package/dist/provider-telemetry.d.ts.map +1 -0
  62. package/dist/provider-telemetry.js +423 -0
  63. package/dist/provider-telemetry.js.map +1 -0
  64. package/dist/review-pass.d.ts +52 -10
  65. package/dist/review-pass.d.ts.map +1 -1
  66. package/dist/review-pass.js +114 -30
  67. package/dist/review-pass.js.map +1 -1
  68. package/dist/run-analytics-report.d.ts +286 -0
  69. package/dist/run-analytics-report.d.ts.map +1 -0
  70. package/dist/run-analytics-report.js +1242 -0
  71. package/dist/run-analytics-report.js.map +1 -0
  72. package/dist/run-analytics.d.ts +844 -0
  73. package/dist/run-analytics.d.ts.map +1 -0
  74. package/dist/run-analytics.js +777 -0
  75. package/dist/run-analytics.js.map +1 -0
  76. package/dist/run-log.d.ts +16 -0
  77. package/dist/run-log.d.ts.map +1 -0
  78. package/dist/run-log.js +32 -0
  79. package/dist/run-log.js.map +1 -0
  80. package/dist/run-program.d.ts +268 -4
  81. package/dist/run-program.d.ts.map +1 -1
  82. package/dist/run-program.js +2508 -762
  83. package/dist/run-program.js.map +1 -1
  84. package/dist/scheduler.d.ts +75 -0
  85. package/dist/scheduler.d.ts.map +1 -0
  86. package/dist/scheduler.js +126 -0
  87. package/dist/scheduler.js.map +1 -0
  88. package/dist/verify-cache.d.ts +64 -0
  89. package/dist/verify-cache.d.ts.map +1 -0
  90. package/dist/verify-cache.js +56 -0
  91. package/dist/verify-cache.js.map +1 -0
  92. package/dist/whole-program-review.d.ts +3 -0
  93. package/dist/whole-program-review.d.ts.map +1 -1
  94. package/dist/whole-program-review.js +8 -1
  95. package/dist/whole-program-review.js.map +1 -1
  96. package/dist/worktree.d.ts +124 -0
  97. package/dist/worktree.d.ts.map +1 -0
  98. package/dist/worktree.js +397 -0
  99. package/dist/worktree.js.map +1 -0
  100. package/dist/write-queue.d.ts +25 -0
  101. package/dist/write-queue.d.ts.map +1 -0
  102. package/dist/write-queue.js +52 -0
  103. package/dist/write-queue.js.map +1 -0
  104. package/package.json +2 -2
  105. package/skills/plan-program/SKILL.md +37 -5
  106. package/dist/worktree-guard.d.ts +0 -40
  107. package/dist/worktree-guard.d.ts.map +0 -1
  108. package/dist/worktree-guard.js +0 -91
  109. package/dist/worktree-guard.js.map +0 -1
@@ -0,0 +1,844 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * The versioned, provider-neutral run-observation contract (WS-01). This
4
+ * module defines the schema, the stage-to-bucket mapping, the injectable
5
+ * clock, the recorder, and the atomic persistence boundary — it emits no
6
+ * per-stage spans of its own beyond a handful of reference spans proving the
7
+ * API end-to-end (see the WS-01/WS-02 emission-boundary decision). WS-02
8
+ * instruments the full run lifecycle against this contract; WS-03 attaches
9
+ * provider/prompt facts; WS-04 aggregates; WS-05 interprets.
10
+ */
11
+ /** Bumped only when the shape of the finalized artifact changes incompatibly. */
12
+ export declare const RUN_ANALYTICS_SCHEMA_VERSION = 1;
13
+ /** The closed top-level attribution taxonomy — a new bucket is a plan change. */
14
+ export declare const BUCKETS: readonly ["preflight", "authoring", "implementation", "verification", "review-and-decisions", "recovery-and-fixes", "git-and-persistence", "whole-program-review", "reporting", "unattributed"];
15
+ export declare const bucketSchema: z.ZodEnum<{
16
+ preflight: "preflight";
17
+ authoring: "authoring";
18
+ implementation: "implementation";
19
+ verification: "verification";
20
+ "review-and-decisions": "review-and-decisions";
21
+ "recovery-and-fixes": "recovery-and-fixes";
22
+ "git-and-persistence": "git-and-persistence";
23
+ "whole-program-review": "whole-program-review";
24
+ reporting: "reporting";
25
+ unattributed: "unattributed";
26
+ }>;
27
+ export type Bucket = z.infer<typeof bucketSchema>;
28
+ /**
29
+ * The closed set of concrete operations, each mapping to exactly one bucket.
30
+ * WS-02 emits stages; WS-04 reads buckets; both import this exact table so
31
+ * they cannot drift ("same stage, different bucket" is closed by
32
+ * construction). Bar one exception, there is no `unattributed` stage:
33
+ * `unattributed` is normally a residual WS-04 computes as elapsed time minus
34
+ * the union of known top-level spans, never emitted by an instrumentation
35
+ * site. The exception is `"run"` itself (below) — a single, WS-01-owned span
36
+ * opened once per run, never an ad hoc WS-02 filler, whose entire purpose is
37
+ * to prove full temporal coverage from run start onward by parenting every
38
+ * other span; once WS-04 subtracts the union of its children, what remains
39
+ * of its own duration is, by construction, exactly the residual its bucket
40
+ * already names.
41
+ */
42
+ export declare const STAGE_BUCKET: {
43
+ readonly run: "unattributed";
44
+ readonly "prerequisite-check": "preflight";
45
+ readonly "baseline-verification": "preflight";
46
+ readonly author: "authoring";
47
+ readonly "re-author": "authoring";
48
+ readonly "spec-critique": "authoring";
49
+ readonly implementer: "implementation";
50
+ readonly recovery: "implementation";
51
+ readonly "informed-retry": "implementation";
52
+ readonly "verification-command": "verification";
53
+ readonly "test-critique": "review-and-decisions";
54
+ readonly "decision-review": "review-and-decisions";
55
+ readonly "finding-triage": "review-and-decisions";
56
+ readonly "causal-analysis": "review-and-decisions";
57
+ readonly "failure-diagnosis": "recovery-and-fixes";
58
+ readonly "fix-now": "recovery-and-fixes";
59
+ readonly "test-critique-fix": "recovery-and-fixes";
60
+ readonly "manifest-persist": "git-and-persistence";
61
+ readonly "ledger-persist": "git-and-persistence";
62
+ readonly "analytics-persist": "git-and-persistence";
63
+ readonly "git-diff": "git-and-persistence";
64
+ readonly "git-commit": "git-and-persistence";
65
+ readonly "worktree-setup": "git-and-persistence";
66
+ readonly integration: "git-and-persistence";
67
+ readonly "whole-program-review": "whole-program-review";
68
+ readonly "as-built-snapshot": "whole-program-review";
69
+ readonly "report-assembly": "reporting";
70
+ readonly "report-commit": "reporting";
71
+ };
72
+ export type Stage = keyof typeof STAGE_BUCKET;
73
+ export declare const stageSchema: z.ZodEnum<{
74
+ "whole-program-review": "whole-program-review";
75
+ run: "run";
76
+ "prerequisite-check": "prerequisite-check";
77
+ "baseline-verification": "baseline-verification";
78
+ author: "author";
79
+ "re-author": "re-author";
80
+ "spec-critique": "spec-critique";
81
+ implementer: "implementer";
82
+ recovery: "recovery";
83
+ "informed-retry": "informed-retry";
84
+ "verification-command": "verification-command";
85
+ "test-critique": "test-critique";
86
+ "decision-review": "decision-review";
87
+ "finding-triage": "finding-triage";
88
+ "causal-analysis": "causal-analysis";
89
+ "failure-diagnosis": "failure-diagnosis";
90
+ "fix-now": "fix-now";
91
+ "test-critique-fix": "test-critique-fix";
92
+ "manifest-persist": "manifest-persist";
93
+ "ledger-persist": "ledger-persist";
94
+ "analytics-persist": "analytics-persist";
95
+ "git-diff": "git-diff";
96
+ "git-commit": "git-commit";
97
+ "worktree-setup": "worktree-setup";
98
+ integration: "integration";
99
+ "as-built-snapshot": "as-built-snapshot";
100
+ "report-assembly": "report-assembly";
101
+ "report-commit": "report-commit";
102
+ }>;
103
+ /** The observability label every measurement carries; absent telemetry is `unavailable`, never a measured zero. */
104
+ export declare const COVERAGE_VALUES: readonly ["observed", "estimated", "unavailable", "incomplete"];
105
+ export declare const coverageSchema: z.ZodEnum<{
106
+ observed: "observed";
107
+ estimated: "estimated";
108
+ unavailable: "unavailable";
109
+ incomplete: "incomplete";
110
+ }>;
111
+ export type Coverage = z.infer<typeof coverageSchema>;
112
+ /**
113
+ * Documented, non-exhaustive outcome vocabulary (SC-04): `outcome` is an open
114
+ * `z.string()` so a future outcome (e.g. a timeout) can be added without a
115
+ * schema version bump. This is documentation and a lint target, never a gate
116
+ * — an unknown outcome string still validates and round-trips.
117
+ */
118
+ export declare const KNOWN_OUTCOMES: readonly ["success", "failed", "discarded", "no-op", "skipped", "interrupted"];
119
+ /**
120
+ * The fixed scheduling-observation vocabulary (WS-01 SC-10): a workstream
121
+ * becomes ready, is scheduled, or waits, and why. `workstream-ready` and
122
+ * `workstream-scheduled` are instants, emitted at most once per workstream
123
+ * per run; `workstream-waiting` is emitted once per (workstream, cause)
124
+ * pair, when the wait ends, carrying `value` = milliseconds waited. No
125
+ * emitter runs yet in this workstream — WS-04 is the first caller — but the
126
+ * vocabulary, the schema support, and the typed emitters below are final.
127
+ */
128
+ export declare const SCHEDULING_POINT_KINDS: readonly ["workstream-ready", "workstream-scheduled", "workstream-waiting"];
129
+ /** Open vocabulary, exactly like KNOWN_OUTCOMES: documentation and a lint
130
+ * target, never a gate. A future wait cause is not a schema change. */
131
+ export declare const KNOWN_WAIT_CAUSES: readonly ["dependency", "concurrency-cap", "integration-mutex", "spec-pending", "author-concurrency-cap"];
132
+ /** The only evidence locality WS-01 defines: a build-logs reference resolves only on the machine that ran. */
133
+ export declare const evidenceReferenceSchema: z.ZodObject<{
134
+ kind: z.ZodEnum<{
135
+ transcript: "transcript";
136
+ "ledger-event": "ledger-event";
137
+ commit: "commit";
138
+ diagnosis: "diagnosis";
139
+ }>;
140
+ locality: z.ZodLiteral<"local">;
141
+ ref: z.ZodString;
142
+ note: z.ZodOptional<z.ZodString>;
143
+ }, z.core.$strip>;
144
+ export type EvidenceReference = z.infer<typeof evidenceReferenceSchema>;
145
+ /** The stable facts attached to an interval or point. Provider/model identity is deliberately absent — WS-03's sole home. */
146
+ export declare const dimensionsSchema: z.ZodObject<{
147
+ stage: z.ZodEnum<{
148
+ "whole-program-review": "whole-program-review";
149
+ run: "run";
150
+ "prerequisite-check": "prerequisite-check";
151
+ "baseline-verification": "baseline-verification";
152
+ author: "author";
153
+ "re-author": "re-author";
154
+ "spec-critique": "spec-critique";
155
+ implementer: "implementer";
156
+ recovery: "recovery";
157
+ "informed-retry": "informed-retry";
158
+ "verification-command": "verification-command";
159
+ "test-critique": "test-critique";
160
+ "decision-review": "decision-review";
161
+ "finding-triage": "finding-triage";
162
+ "causal-analysis": "causal-analysis";
163
+ "failure-diagnosis": "failure-diagnosis";
164
+ "fix-now": "fix-now";
165
+ "test-critique-fix": "test-critique-fix";
166
+ "manifest-persist": "manifest-persist";
167
+ "ledger-persist": "ledger-persist";
168
+ "analytics-persist": "analytics-persist";
169
+ "git-diff": "git-diff";
170
+ "git-commit": "git-commit";
171
+ "worktree-setup": "worktree-setup";
172
+ integration: "integration";
173
+ "as-built-snapshot": "as-built-snapshot";
174
+ "report-assembly": "report-assembly";
175
+ "report-commit": "report-commit";
176
+ }>;
177
+ workstream: z.ZodOptional<z.ZodString>;
178
+ role: z.ZodOptional<z.ZodEnum<{
179
+ agent: "agent";
180
+ authorAgent: "authorAgent";
181
+ deciderAgent: "deciderAgent";
182
+ reviewerAgent: "reviewerAgent";
183
+ recoveryAgent: "recoveryAgent";
184
+ }>>;
185
+ attemptSeat: z.ZodOptional<z.ZodString>;
186
+ attemptIndex: z.ZodOptional<z.ZodNumber>;
187
+ attemptReason: z.ZodOptional<z.ZodString>;
188
+ verifyCommand: z.ZodOptional<z.ZodString>;
189
+ outcome: z.ZodOptional<z.ZodString>;
190
+ evidence: z.ZodOptional<z.ZodArray<z.ZodObject<{
191
+ kind: z.ZodEnum<{
192
+ transcript: "transcript";
193
+ "ledger-event": "ledger-event";
194
+ commit: "commit";
195
+ diagnosis: "diagnosis";
196
+ }>;
197
+ locality: z.ZodLiteral<"local">;
198
+ ref: z.ZodString;
199
+ note: z.ZodOptional<z.ZodString>;
200
+ }, z.core.$strip>>>;
201
+ waitCause: z.ZodOptional<z.ZodString>;
202
+ }, z.core.$strip>;
203
+ export type Dimensions = z.infer<typeof dimensionsSchema>;
204
+ /**
205
+ * An interval observation — the unit that carries wall-clock time. The
206
+ * schema permits overlapping spans (a parent and its children overlap by
207
+ * construction); WS-01 validates only the local invariants (bucket matches
208
+ * stage, end >= start when present, parentId resolves within the artifact).
209
+ * WS-04 owns interval-union conservation and rejecting double-counted
210
+ * overlaps at the top level.
211
+ */
212
+ export declare const spanSchema: z.ZodObject<{
213
+ id: z.ZodString;
214
+ parentId: z.ZodOptional<z.ZodString>;
215
+ stage: z.ZodEnum<{
216
+ "whole-program-review": "whole-program-review";
217
+ run: "run";
218
+ "prerequisite-check": "prerequisite-check";
219
+ "baseline-verification": "baseline-verification";
220
+ author: "author";
221
+ "re-author": "re-author";
222
+ "spec-critique": "spec-critique";
223
+ implementer: "implementer";
224
+ recovery: "recovery";
225
+ "informed-retry": "informed-retry";
226
+ "verification-command": "verification-command";
227
+ "test-critique": "test-critique";
228
+ "decision-review": "decision-review";
229
+ "finding-triage": "finding-triage";
230
+ "causal-analysis": "causal-analysis";
231
+ "failure-diagnosis": "failure-diagnosis";
232
+ "fix-now": "fix-now";
233
+ "test-critique-fix": "test-critique-fix";
234
+ "manifest-persist": "manifest-persist";
235
+ "ledger-persist": "ledger-persist";
236
+ "analytics-persist": "analytics-persist";
237
+ "git-diff": "git-diff";
238
+ "git-commit": "git-commit";
239
+ "worktree-setup": "worktree-setup";
240
+ integration: "integration";
241
+ "as-built-snapshot": "as-built-snapshot";
242
+ "report-assembly": "report-assembly";
243
+ "report-commit": "report-commit";
244
+ }>;
245
+ bucket: z.ZodEnum<{
246
+ preflight: "preflight";
247
+ authoring: "authoring";
248
+ implementation: "implementation";
249
+ verification: "verification";
250
+ "review-and-decisions": "review-and-decisions";
251
+ "recovery-and-fixes": "recovery-and-fixes";
252
+ "git-and-persistence": "git-and-persistence";
253
+ "whole-program-review": "whole-program-review";
254
+ reporting: "reporting";
255
+ unattributed: "unattributed";
256
+ }>;
257
+ startOffsetMs: z.ZodNumber;
258
+ endOffsetMs: z.ZodOptional<z.ZodNumber>;
259
+ dimensions: z.ZodObject<{
260
+ stage: z.ZodEnum<{
261
+ "whole-program-review": "whole-program-review";
262
+ run: "run";
263
+ "prerequisite-check": "prerequisite-check";
264
+ "baseline-verification": "baseline-verification";
265
+ author: "author";
266
+ "re-author": "re-author";
267
+ "spec-critique": "spec-critique";
268
+ implementer: "implementer";
269
+ recovery: "recovery";
270
+ "informed-retry": "informed-retry";
271
+ "verification-command": "verification-command";
272
+ "test-critique": "test-critique";
273
+ "decision-review": "decision-review";
274
+ "finding-triage": "finding-triage";
275
+ "causal-analysis": "causal-analysis";
276
+ "failure-diagnosis": "failure-diagnosis";
277
+ "fix-now": "fix-now";
278
+ "test-critique-fix": "test-critique-fix";
279
+ "manifest-persist": "manifest-persist";
280
+ "ledger-persist": "ledger-persist";
281
+ "analytics-persist": "analytics-persist";
282
+ "git-diff": "git-diff";
283
+ "git-commit": "git-commit";
284
+ "worktree-setup": "worktree-setup";
285
+ integration: "integration";
286
+ "as-built-snapshot": "as-built-snapshot";
287
+ "report-assembly": "report-assembly";
288
+ "report-commit": "report-commit";
289
+ }>;
290
+ workstream: z.ZodOptional<z.ZodString>;
291
+ role: z.ZodOptional<z.ZodEnum<{
292
+ agent: "agent";
293
+ authorAgent: "authorAgent";
294
+ deciderAgent: "deciderAgent";
295
+ reviewerAgent: "reviewerAgent";
296
+ recoveryAgent: "recoveryAgent";
297
+ }>>;
298
+ attemptSeat: z.ZodOptional<z.ZodString>;
299
+ attemptIndex: z.ZodOptional<z.ZodNumber>;
300
+ attemptReason: z.ZodOptional<z.ZodString>;
301
+ verifyCommand: z.ZodOptional<z.ZodString>;
302
+ outcome: z.ZodOptional<z.ZodString>;
303
+ evidence: z.ZodOptional<z.ZodArray<z.ZodObject<{
304
+ kind: z.ZodEnum<{
305
+ transcript: "transcript";
306
+ "ledger-event": "ledger-event";
307
+ commit: "commit";
308
+ diagnosis: "diagnosis";
309
+ }>;
310
+ locality: z.ZodLiteral<"local">;
311
+ ref: z.ZodString;
312
+ note: z.ZodOptional<z.ZodString>;
313
+ }, z.core.$strip>>>;
314
+ waitCause: z.ZodOptional<z.ZodString>;
315
+ }, z.core.$strip>;
316
+ }, z.core.$strip>;
317
+ export type Span = z.infer<typeof spanSchema>;
318
+ /**
319
+ * A fact measured at an instant, not an interval. `kind` is an open string
320
+ * for the same forward-compatibility reason as `outcome`.
321
+ *
322
+ * `label` and `detail` are WS-03's sole, additive amendment to this schema
323
+ * (see the `scalar-points-plus-additive-fields` decision): `label` names the
324
+ * specific metric or prompt component a point measures (e.g.
325
+ * `"input-tokens"`, `"model"`, `"roster"`), and `detail` carries a
326
+ * string-valued fact — an exact model identity, a provider label, a
327
+ * comma-joined demoted-dependency id list — when the measurement is not
328
+ * numeric. Both are optional and unconstrained by an enum, so every existing
329
+ * point (and every WS-01 fixture) round-trips unchanged.
330
+ */
331
+ export declare const pointObservationSchema: z.ZodObject<{
332
+ id: z.ZodString;
333
+ atOffsetMs: z.ZodNumber;
334
+ kind: z.ZodString;
335
+ coverage: z.ZodEnum<{
336
+ observed: "observed";
337
+ estimated: "estimated";
338
+ unavailable: "unavailable";
339
+ incomplete: "incomplete";
340
+ }>;
341
+ value: z.ZodOptional<z.ZodNumber>;
342
+ unit: z.ZodOptional<z.ZodString>;
343
+ label: z.ZodOptional<z.ZodString>;
344
+ detail: z.ZodOptional<z.ZodString>;
345
+ dimensions: z.ZodOptional<z.ZodObject<{
346
+ stage: z.ZodOptional<z.ZodEnum<{
347
+ "whole-program-review": "whole-program-review";
348
+ run: "run";
349
+ "prerequisite-check": "prerequisite-check";
350
+ "baseline-verification": "baseline-verification";
351
+ author: "author";
352
+ "re-author": "re-author";
353
+ "spec-critique": "spec-critique";
354
+ implementer: "implementer";
355
+ recovery: "recovery";
356
+ "informed-retry": "informed-retry";
357
+ "verification-command": "verification-command";
358
+ "test-critique": "test-critique";
359
+ "decision-review": "decision-review";
360
+ "finding-triage": "finding-triage";
361
+ "causal-analysis": "causal-analysis";
362
+ "failure-diagnosis": "failure-diagnosis";
363
+ "fix-now": "fix-now";
364
+ "test-critique-fix": "test-critique-fix";
365
+ "manifest-persist": "manifest-persist";
366
+ "ledger-persist": "ledger-persist";
367
+ "analytics-persist": "analytics-persist";
368
+ "git-diff": "git-diff";
369
+ "git-commit": "git-commit";
370
+ "worktree-setup": "worktree-setup";
371
+ integration: "integration";
372
+ "as-built-snapshot": "as-built-snapshot";
373
+ "report-assembly": "report-assembly";
374
+ "report-commit": "report-commit";
375
+ }>>;
376
+ workstream: z.ZodOptional<z.ZodOptional<z.ZodString>>;
377
+ role: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
378
+ agent: "agent";
379
+ authorAgent: "authorAgent";
380
+ deciderAgent: "deciderAgent";
381
+ reviewerAgent: "reviewerAgent";
382
+ recoveryAgent: "recoveryAgent";
383
+ }>>>;
384
+ attemptSeat: z.ZodOptional<z.ZodOptional<z.ZodString>>;
385
+ attemptIndex: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
386
+ attemptReason: z.ZodOptional<z.ZodOptional<z.ZodString>>;
387
+ verifyCommand: z.ZodOptional<z.ZodOptional<z.ZodString>>;
388
+ outcome: z.ZodOptional<z.ZodOptional<z.ZodString>>;
389
+ evidence: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
390
+ kind: z.ZodEnum<{
391
+ transcript: "transcript";
392
+ "ledger-event": "ledger-event";
393
+ commit: "commit";
394
+ diagnosis: "diagnosis";
395
+ }>;
396
+ locality: z.ZodLiteral<"local">;
397
+ ref: z.ZodString;
398
+ note: z.ZodOptional<z.ZodString>;
399
+ }, z.core.$strip>>>>;
400
+ waitCause: z.ZodOptional<z.ZodOptional<z.ZodString>>;
401
+ }, z.core.$strip>>;
402
+ evidence: z.ZodOptional<z.ZodArray<z.ZodObject<{
403
+ kind: z.ZodEnum<{
404
+ transcript: "transcript";
405
+ "ledger-event": "ledger-event";
406
+ commit: "commit";
407
+ diagnosis: "diagnosis";
408
+ }>;
409
+ locality: z.ZodLiteral<"local">;
410
+ ref: z.ZodString;
411
+ note: z.ZodOptional<z.ZodString>;
412
+ }, z.core.$strip>>>;
413
+ }, z.core.$strip>;
414
+ export type PointObservation = z.infer<typeof pointObservationSchema>;
415
+ /**
416
+ * States the window the reconciled numbers cover: run start through the
417
+ * pre-render analytics snapshot taken just before `finalize()` persists this
418
+ * artifact and the report is written and committed (SC-03, SC-14). The
419
+ * report-write/commit tail is unobservable from inside the artifact — the
420
+ * `run` and `report-commit` spans stay open and the tail lands as a sidecar
421
+ * point — and publish runs after the CLI's run call returns. Adopted by
422
+ * human ruling (decisions 062f9cc308fe22fa, 987817d69c457259).
423
+ */
424
+ export declare const AGGREGATION_BOUNDARY: "run-start-to-pre-render-snapshot";
425
+ export declare const runAnalyticsSchema: z.ZodObject<{
426
+ schemaVersion: z.ZodLiteral<1>;
427
+ identity: z.ZodObject<{
428
+ runId: z.ZodString;
429
+ parentRunId: z.ZodOptional<z.ZodString>;
430
+ programId: z.ZodString;
431
+ }, z.core.$strip>;
432
+ anchors: z.ZodObject<{
433
+ startedAt: z.ZodString;
434
+ monotonicAnchorMs: z.ZodNumber;
435
+ finalizedAt: z.ZodOptional<z.ZodString>;
436
+ finalizedOffsetMs: z.ZodOptional<z.ZodNumber>;
437
+ }, z.core.$strip>;
438
+ aggregationBoundary: z.ZodLiteral<"run-start-to-pre-render-snapshot">;
439
+ spans: z.ZodArray<z.ZodObject<{
440
+ id: z.ZodString;
441
+ parentId: z.ZodOptional<z.ZodString>;
442
+ stage: z.ZodEnum<{
443
+ "whole-program-review": "whole-program-review";
444
+ run: "run";
445
+ "prerequisite-check": "prerequisite-check";
446
+ "baseline-verification": "baseline-verification";
447
+ author: "author";
448
+ "re-author": "re-author";
449
+ "spec-critique": "spec-critique";
450
+ implementer: "implementer";
451
+ recovery: "recovery";
452
+ "informed-retry": "informed-retry";
453
+ "verification-command": "verification-command";
454
+ "test-critique": "test-critique";
455
+ "decision-review": "decision-review";
456
+ "finding-triage": "finding-triage";
457
+ "causal-analysis": "causal-analysis";
458
+ "failure-diagnosis": "failure-diagnosis";
459
+ "fix-now": "fix-now";
460
+ "test-critique-fix": "test-critique-fix";
461
+ "manifest-persist": "manifest-persist";
462
+ "ledger-persist": "ledger-persist";
463
+ "analytics-persist": "analytics-persist";
464
+ "git-diff": "git-diff";
465
+ "git-commit": "git-commit";
466
+ "worktree-setup": "worktree-setup";
467
+ integration: "integration";
468
+ "as-built-snapshot": "as-built-snapshot";
469
+ "report-assembly": "report-assembly";
470
+ "report-commit": "report-commit";
471
+ }>;
472
+ bucket: z.ZodEnum<{
473
+ preflight: "preflight";
474
+ authoring: "authoring";
475
+ implementation: "implementation";
476
+ verification: "verification";
477
+ "review-and-decisions": "review-and-decisions";
478
+ "recovery-and-fixes": "recovery-and-fixes";
479
+ "git-and-persistence": "git-and-persistence";
480
+ "whole-program-review": "whole-program-review";
481
+ reporting: "reporting";
482
+ unattributed: "unattributed";
483
+ }>;
484
+ startOffsetMs: z.ZodNumber;
485
+ endOffsetMs: z.ZodOptional<z.ZodNumber>;
486
+ dimensions: z.ZodObject<{
487
+ stage: z.ZodEnum<{
488
+ "whole-program-review": "whole-program-review";
489
+ run: "run";
490
+ "prerequisite-check": "prerequisite-check";
491
+ "baseline-verification": "baseline-verification";
492
+ author: "author";
493
+ "re-author": "re-author";
494
+ "spec-critique": "spec-critique";
495
+ implementer: "implementer";
496
+ recovery: "recovery";
497
+ "informed-retry": "informed-retry";
498
+ "verification-command": "verification-command";
499
+ "test-critique": "test-critique";
500
+ "decision-review": "decision-review";
501
+ "finding-triage": "finding-triage";
502
+ "causal-analysis": "causal-analysis";
503
+ "failure-diagnosis": "failure-diagnosis";
504
+ "fix-now": "fix-now";
505
+ "test-critique-fix": "test-critique-fix";
506
+ "manifest-persist": "manifest-persist";
507
+ "ledger-persist": "ledger-persist";
508
+ "analytics-persist": "analytics-persist";
509
+ "git-diff": "git-diff";
510
+ "git-commit": "git-commit";
511
+ "worktree-setup": "worktree-setup";
512
+ integration: "integration";
513
+ "as-built-snapshot": "as-built-snapshot";
514
+ "report-assembly": "report-assembly";
515
+ "report-commit": "report-commit";
516
+ }>;
517
+ workstream: z.ZodOptional<z.ZodString>;
518
+ role: z.ZodOptional<z.ZodEnum<{
519
+ agent: "agent";
520
+ authorAgent: "authorAgent";
521
+ deciderAgent: "deciderAgent";
522
+ reviewerAgent: "reviewerAgent";
523
+ recoveryAgent: "recoveryAgent";
524
+ }>>;
525
+ attemptSeat: z.ZodOptional<z.ZodString>;
526
+ attemptIndex: z.ZodOptional<z.ZodNumber>;
527
+ attemptReason: z.ZodOptional<z.ZodString>;
528
+ verifyCommand: z.ZodOptional<z.ZodString>;
529
+ outcome: z.ZodOptional<z.ZodString>;
530
+ evidence: z.ZodOptional<z.ZodArray<z.ZodObject<{
531
+ kind: z.ZodEnum<{
532
+ transcript: "transcript";
533
+ "ledger-event": "ledger-event";
534
+ commit: "commit";
535
+ diagnosis: "diagnosis";
536
+ }>;
537
+ locality: z.ZodLiteral<"local">;
538
+ ref: z.ZodString;
539
+ note: z.ZodOptional<z.ZodString>;
540
+ }, z.core.$strip>>>;
541
+ waitCause: z.ZodOptional<z.ZodString>;
542
+ }, z.core.$strip>;
543
+ }, z.core.$strip>>;
544
+ points: z.ZodArray<z.ZodObject<{
545
+ id: z.ZodString;
546
+ atOffsetMs: z.ZodNumber;
547
+ kind: z.ZodString;
548
+ coverage: z.ZodEnum<{
549
+ observed: "observed";
550
+ estimated: "estimated";
551
+ unavailable: "unavailable";
552
+ incomplete: "incomplete";
553
+ }>;
554
+ value: z.ZodOptional<z.ZodNumber>;
555
+ unit: z.ZodOptional<z.ZodString>;
556
+ label: z.ZodOptional<z.ZodString>;
557
+ detail: z.ZodOptional<z.ZodString>;
558
+ dimensions: z.ZodOptional<z.ZodObject<{
559
+ stage: z.ZodOptional<z.ZodEnum<{
560
+ "whole-program-review": "whole-program-review";
561
+ run: "run";
562
+ "prerequisite-check": "prerequisite-check";
563
+ "baseline-verification": "baseline-verification";
564
+ author: "author";
565
+ "re-author": "re-author";
566
+ "spec-critique": "spec-critique";
567
+ implementer: "implementer";
568
+ recovery: "recovery";
569
+ "informed-retry": "informed-retry";
570
+ "verification-command": "verification-command";
571
+ "test-critique": "test-critique";
572
+ "decision-review": "decision-review";
573
+ "finding-triage": "finding-triage";
574
+ "causal-analysis": "causal-analysis";
575
+ "failure-diagnosis": "failure-diagnosis";
576
+ "fix-now": "fix-now";
577
+ "test-critique-fix": "test-critique-fix";
578
+ "manifest-persist": "manifest-persist";
579
+ "ledger-persist": "ledger-persist";
580
+ "analytics-persist": "analytics-persist";
581
+ "git-diff": "git-diff";
582
+ "git-commit": "git-commit";
583
+ "worktree-setup": "worktree-setup";
584
+ integration: "integration";
585
+ "as-built-snapshot": "as-built-snapshot";
586
+ "report-assembly": "report-assembly";
587
+ "report-commit": "report-commit";
588
+ }>>;
589
+ workstream: z.ZodOptional<z.ZodOptional<z.ZodString>>;
590
+ role: z.ZodOptional<z.ZodOptional<z.ZodEnum<{
591
+ agent: "agent";
592
+ authorAgent: "authorAgent";
593
+ deciderAgent: "deciderAgent";
594
+ reviewerAgent: "reviewerAgent";
595
+ recoveryAgent: "recoveryAgent";
596
+ }>>>;
597
+ attemptSeat: z.ZodOptional<z.ZodOptional<z.ZodString>>;
598
+ attemptIndex: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
599
+ attemptReason: z.ZodOptional<z.ZodOptional<z.ZodString>>;
600
+ verifyCommand: z.ZodOptional<z.ZodOptional<z.ZodString>>;
601
+ outcome: z.ZodOptional<z.ZodOptional<z.ZodString>>;
602
+ evidence: z.ZodOptional<z.ZodOptional<z.ZodArray<z.ZodObject<{
603
+ kind: z.ZodEnum<{
604
+ transcript: "transcript";
605
+ "ledger-event": "ledger-event";
606
+ commit: "commit";
607
+ diagnosis: "diagnosis";
608
+ }>;
609
+ locality: z.ZodLiteral<"local">;
610
+ ref: z.ZodString;
611
+ note: z.ZodOptional<z.ZodString>;
612
+ }, z.core.$strip>>>>;
613
+ waitCause: z.ZodOptional<z.ZodOptional<z.ZodString>>;
614
+ }, z.core.$strip>>;
615
+ evidence: z.ZodOptional<z.ZodArray<z.ZodObject<{
616
+ kind: z.ZodEnum<{
617
+ transcript: "transcript";
618
+ "ledger-event": "ledger-event";
619
+ commit: "commit";
620
+ diagnosis: "diagnosis";
621
+ }>;
622
+ locality: z.ZodLiteral<"local">;
623
+ ref: z.ZodString;
624
+ note: z.ZodOptional<z.ZodString>;
625
+ }, z.core.$strip>>>;
626
+ }, z.core.$strip>>;
627
+ }, z.core.$strip>;
628
+ export type RunAnalytics = z.infer<typeof runAnalyticsSchema>;
629
+ /** Mirrors `runReportPath` — the one canonical location for a program's analytics artifact. */
630
+ export declare function runAnalyticsPath(root: string, programId: string): string;
631
+ /**
632
+ * Reads any prior finalized artifact for `programId` purely to source
633
+ * `parentRunId` — a plain read with no durable effect, safe before the
634
+ * could-not-start gate. Absent, unreadable, or invalid prior artifacts all
635
+ * resolve to `undefined` (fail open): a missing lineage is not a reason to
636
+ * fail a run.
637
+ */
638
+ export declare function readPriorRunId(root: string, programId: string): Promise<string | undefined>;
639
+ /**
640
+ * Wall time (`now`) anchors the artifact to a human timeline; monotonic time
641
+ * drives every span offset, because wall-clock is not monotonic and an NTP
642
+ * step mid-run must never make a span appear negative-length.
643
+ */
644
+ export interface RunClock {
645
+ now(): Date;
646
+ monotonic(): number;
647
+ }
648
+ export interface SpanHandle {
649
+ close(result?: {
650
+ outcome?: string;
651
+ evidence?: EvidenceReference[];
652
+ }): void;
653
+ /** Explicit nesting when the implicit open-span stack doesn't fit (e.g. a span opened and closed across an `await` boundary). */
654
+ child(dims: Dimensions): SpanHandle;
655
+ /**
656
+ * A scope whose spans parent to this span — the explicit alternative to
657
+ * the implicit open-span stack. `options.workstream`, when given, is
658
+ * stamped onto every span/point this scope opens whose own dimensions
659
+ * omit `workstream`; a call site's explicit dimension is never
660
+ * overridden.
661
+ */
662
+ scope(options?: {
663
+ workstream?: string;
664
+ }): SpanScope;
665
+ }
666
+ /**
667
+ * A fixed parent span, plus an optional workstream to stamp. The explicit
668
+ * alternative to attaching a new span to whatever happens to be open on the
669
+ * recorder's implicit stack at that microsecond — which is correct only
670
+ * serially. `RunRecorder` itself is a valid (degenerate) `SpanScope`: its
671
+ * `span()` keeps the implicit-stack behaviour and its `workstream` is
672
+ * always `undefined`, so `NOOP_RUN_RECORDER` and every no-scope call site
673
+ * are unaffected.
674
+ */
675
+ export interface SpanScope {
676
+ /** Opens a span parented to this scope's span — never to the open-span stack. */
677
+ span(dims: Dimensions): SpanHandle;
678
+ point(obs: PointObservationInput): void;
679
+ /** The workstream this scope attributes to, when it has one. */
680
+ readonly workstream: string | undefined;
681
+ }
682
+ export interface PointObservationInput {
683
+ kind: string;
684
+ coverage: Coverage;
685
+ value?: number;
686
+ unit?: string;
687
+ label?: string;
688
+ detail?: string;
689
+ dimensions?: Partial<Dimensions>;
690
+ evidence?: EvidenceReference[];
691
+ }
692
+ export interface RunRecorderCreateOptions {
693
+ clock: RunClock;
694
+ root: string;
695
+ programId: string;
696
+ parentRunId?: string;
697
+ log: (line: string) => void;
698
+ /**
699
+ * Set only by {@link NOOP_RUN_RECORDER}'s own construction (WS-02): makes
700
+ * `arm()` a permanent no-op, so a caller that injects the shared singleton
701
+ * as a test seam (`RunProgramOptions.recorder`) can never accidentally arm
702
+ * — and thereby make durably writing — the one shared instance every other
703
+ * caller with no run-scoped recorder also relies on staying inert.
704
+ */
705
+ permanentlyDisarmed?: boolean;
706
+ }
707
+ /**
708
+ * Records a run's spans and point observations and persists them
709
+ * fail-open. Created at run start so pre-gate stages (preflight, baseline
710
+ * verification) can be buffered in memory; stays disarmed — writing nothing
711
+ * durable — until `arm()` is called immediately after the could-not-start
712
+ * gate. Every method is non-throwing: a malformed observation is diagnosed
713
+ * and dropped, a persistence failure is diagnosed and swallowed, and nothing
714
+ * here can change a run's outcome, exit code, status, or report.
715
+ */
716
+ export declare class RunRecorder implements SpanScope {
717
+ readonly runId: string;
718
+ /** `RunRecorder` is a degenerate, unscoped `SpanScope` — always `undefined`; see the interface doc comment. */
719
+ readonly workstream: string | undefined;
720
+ private readonly clock;
721
+ private readonly root;
722
+ private readonly programId;
723
+ private readonly parentRunIdValue;
724
+ private readonly log;
725
+ private readonly monotonicAnchorMs;
726
+ private readonly startedAt;
727
+ private readonly permanentlyDisarmed;
728
+ private armed;
729
+ private finalized;
730
+ private readonly spans;
731
+ private readonly points;
732
+ private readonly openStack;
733
+ private sidecarQueue;
734
+ private readonly spanMeta;
735
+ private constructor();
736
+ static create(opts: RunRecorderCreateOptions): RunRecorder;
737
+ /**
738
+ * Enables durable writes. Idempotent; intended to be called once,
739
+ * immediately after the could-not-start gate. A no-op on a
740
+ * permanently-disarmed instance ({@link NOOP_RUN_RECORDER}) — WS-02's
741
+ * `RunProgramOptions.recorder` test seam lets a caller inject that shared
742
+ * singleton straight into a real run, and `runProgramWith` calls `arm()`
743
+ * unconditionally on whatever recorder it holds, so this guard is what
744
+ * keeps that injection from durably arming — and thereby writing through
745
+ * — the one instance every other no-recorder caller also depends on
746
+ * staying inert.
747
+ */
748
+ arm(): void;
749
+ /** Opens a span; the currently open span (if any) becomes its parent automatically. */
750
+ span(dims: Dimensions): SpanHandle;
751
+ point(obs: PointObservationInput): void;
752
+ /**
753
+ * Builds the in-memory buffer (including any span still open — a
754
+ * crashed/interrupted span composes with no `endOffsetMs`) into a
755
+ * `RunAnalytics` shape at the given wall/monotonic instant. Shared by
756
+ * `finalize()` (which persists the result) and `snapshot()` (which does
757
+ * not), so the two can never independently drift on what "the observed
758
+ * artifact so far" means.
759
+ */
760
+ private compose;
761
+ /**
762
+ * Composes the in-memory buffer into a `RunAnalytics` object, validates
763
+ * it, and atomically persists it. Fail-open: never throws. A no-op when
764
+ * not armed, or when already finalized once.
765
+ */
766
+ finalize(): Promise<void>;
767
+ /**
768
+ * A validated in-memory view of everything observed so far, for the run
769
+ * report's "Where the time went" section (WS-04) — which renders before
770
+ * `finalize()` runs, so it cannot read the file `finalize()` writes.
771
+ * Read-only: composes and validates exactly as `finalize()` does but
772
+ * writes nothing, to the canonical artifact or the sidecar, and is safe to
773
+ * call before `arm()`, after `finalize()`, or any number of times.
774
+ * Non-throwing; returns `undefined` on any failure (fail open).
775
+ */
776
+ snapshot(): RunAnalytics | undefined;
777
+ private elapsedMs;
778
+ /**
779
+ * Resolves the parent for a new span, explicit or implicit (§3.3). Starts
780
+ * from `requestedParentId` (a scope's own anchor span, or — for the
781
+ * implicit path — whatever is currently open on the stack). While the new
782
+ * span's `workstream` is defined, the candidate's *effective* workstream
783
+ * (walking through unattributed intermediaries) is defined, and the two
784
+ * differ, walks to the candidate's own parent. The first compatible
785
+ * ancestor is the parent; if the walk runs out, the span has none. A walk
786
+ * that actually moves the parent emits one diagnostic naming both stages
787
+ * and both workstreams.
788
+ */
789
+ private resolveParent;
790
+ private openSpan;
791
+ private inertHandle;
792
+ /**
793
+ * Builds a `SpanScope` anchored to `anchorSpanId` (a specific span's id,
794
+ * or `undefined` for the recorder's own top-level scope), stamping
795
+ * `workstream` onto every span/point it opens whose own dimensions omit
796
+ * it — never overriding a dimension the call site supplied.
797
+ */
798
+ private makeScope;
799
+ private inertScope;
800
+ private closeSpan;
801
+ private openSpanSnapshots;
802
+ /**
803
+ * Appends one JSON line to the gitignored `build-logs/` sidecar — the
804
+ * crash-durability layer for a hard kill that never reaches the flush
805
+ * seam. Queued so concurrent closes/points never interleave partial
806
+ * writes; a failing append is diagnosed and never breaks the queue for
807
+ * subsequent appends.
808
+ */
809
+ private appendSidecar;
810
+ private diagnose;
811
+ }
812
+ /**
813
+ * A shared, permanently disarmed recorder — the default for callers that
814
+ * have no run-scoped recorder to hand (a standalone test, the doctor probe,
815
+ * a fix/critique path WS-02 has not yet wired), and a valid injection
816
+ * straight into `RunProgramOptions.recorder` (WS-02, SC-13) for a test that
817
+ * wants to prove fail-open by equivalence. Buffers harmlessly in memory and
818
+ * never performs I/O: `permanentlyDisarmed` makes `arm()` a no-op even when
819
+ * a real run calls it unconditionally, so this one shared instance can never
820
+ * be armed by any caller, ever.
821
+ */
822
+ export declare const NOOP_RUN_RECORDER: RunRecorder;
823
+ /**
824
+ * Typed emitters for the scheduling-observation vocabulary (§3.4). They
825
+ * take the workstream id explicitly rather than reading it off `scope`: a
826
+ * workstream becomes ready, and waits, *before* its own flow scope exists —
827
+ * these are called from the run-level scope with the subject named. No
828
+ * emitter runs yet in this workstream; WS-04 is the first caller.
829
+ */
830
+ /** Emitted once per workstream per run, the instant its dependencies are integrated, its spec is complete, and it is not blocked. */
831
+ export declare function recordWorkstreamReady(scope: SpanScope, workstream: string): void;
832
+ /** Emitted once per workstream per run, the instant its flow actually launches. */
833
+ export declare function recordWorkstreamScheduled(scope: SpanScope, workstream: string): void;
834
+ /**
835
+ * Emitted when a wait *ends*, once per (workstream, cause) pair —
836
+ * `wait.waitedMs` is the milliseconds spent waiting on that cause. A
837
+ * workstream that waited on two causes emits two points; their sum should
838
+ * approximate `scheduled − ready`.
839
+ */
840
+ export declare function recordWorkstreamWaiting(scope: SpanScope, workstream: string, wait: {
841
+ cause: string;
842
+ waitedMs: number;
843
+ }): void;
844
+ //# sourceMappingURL=run-analytics.d.ts.map