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