@humain/humain-code-contracts 0.4.14 → 0.4.15

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.
@@ -6,11 +6,20 @@ export { FlowProfileRefSchema, type FlowProfileRefV1 } from "./flow-common.ts";
6
6
  * semantic content, though: a path-like string can match an Id or model pattern. Producers must put only catalog
7
7
  * provider/model identifiers in those fields (see docs/flow-contracts.md, trust boundaries).
8
8
  */
9
- export declare const FLOW_EVENT_KINDS: readonly ["run_started", "size_decided", "escalated", "route_bound", "fallback", "attempt", "request_usage", "verdict", "budget", "control", "message", "run_settled", "warning"];
9
+ export declare const FLOW_EVENT_KINDS: readonly ["run_started", "size_decided", "escalated", "route_bound", "fallback", "attempt", "request_usage", "verdict", "budget", "control", "message", "run_settled", "warning", "implementation_ready", "verification_started", "repair_proposed", "repair_started", "repair_finished", "repair_skipped", "verification_settled"];
10
10
  export type FlowEventKind = (typeof FLOW_EVENT_KINDS)[number];
11
11
  /** Content-free warning reasons. `preexisting_check_failures`: checks already failed identically before the run changed anything. */
12
12
  export declare const FLOW_WARNING_REASONS: readonly ["preexisting_check_failures"];
13
13
  export type FlowWarningReason = (typeof FLOW_WARNING_REASONS)[number];
14
+ /** Per-check attribution of a verify-after check result (emitted only for runs admitted with `verification: "after"`). */
15
+ export declare const FLOW_CHECK_ATTRIBUTIONS: readonly ["passed", "real", "pre_existing", "flaky", "deadline_limited", "unavailable"];
16
+ export type FlowCheckAttribution = (typeof FLOW_CHECK_ATTRIBUTIONS)[number];
17
+ export declare const FLOW_VERIFICATION_VERDICTS: readonly ["verified", "verified_with_preexisting", "checks_failing", "verification_unavailable"];
18
+ export type FlowVerificationVerdict = (typeof FLOW_VERIFICATION_VERDICTS)[number];
19
+ export declare const FLOW_VERIFICATION_REASONS: readonly ["no_checks", "could_not_run", "deadline", "workspace_changed", "superseded", "cancelled", "crash"];
20
+ export type FlowVerificationReason = (typeof FLOW_VERIFICATION_REASONS)[number];
21
+ export declare const FLOW_REPAIR_SKIP_REASONS: readonly ["user_edited", "host_denied", "grant_timeout", "no_progress", "deadline", "exhausted", "not_repairable"];
22
+ export type FlowRepairSkipReason = (typeof FLOW_REPAIR_SKIP_REASONS)[number];
14
23
  export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
15
24
  readonly schema: Type.TLiteral<"humain-flow-event">;
16
25
  readonly schemaVersion: Type.TLiteral<1>;
@@ -48,7 +57,8 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
48
57
  readonly kind: Type.TLiteral<"size_decided">;
49
58
  readonly payload: Type.TObject<{
50
59
  readonly size: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
51
- readonly source: Type.TUnion<[Type.TLiteral<"rules">, Type.TLiteral<"triage">, Type.TLiteral<"override">]>;
60
+ readonly source: Type.TUnion<[Type.TLiteral<"rules">, Type.TLiteral<"signals">, Type.TLiteral<"triage">, Type.TLiteral<"override">]>;
61
+ readonly basis: Type.TOptional<Type.TUnion<[Type.TLiteral<"prompt">, Type.TLiteral<"original_request">]>>;
52
62
  readonly ruleScore: Type.TNumber;
53
63
  readonly thresholds: Type.TObject<{
54
64
  readonly mediumAt: Type.TNumber;
@@ -72,7 +82,7 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
72
82
  readonly payload: Type.TObject<{
73
83
  readonly from: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
74
84
  readonly to: Type.TUnion<[Type.TLiteral<"small">, Type.TLiteral<"medium">, Type.TLiteral<"large">]>;
75
- readonly reasonClass: Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">]>, Type.TLiteral<"size_underestimated">]>;
85
+ readonly reasonClass: Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">, Type.TLiteral<"review_findings">]>, Type.TLiteral<"size_underestimated">]>;
76
86
  }>;
77
87
  }>, Type.TObject<{
78
88
  readonly schema: Type.TLiteral<"humain-flow-event">;
@@ -124,7 +134,7 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
124
134
  readonly provider: Type.TString;
125
135
  readonly model: Type.TString;
126
136
  }>;
127
- readonly reasonClass: Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">]>, Type.TLiteral<"size_underestimated">]>;
137
+ readonly reasonClass: Type.TUnion<[Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">, Type.TLiteral<"review_findings">]>, Type.TLiteral<"size_underestimated">]>;
128
138
  }>;
129
139
  }>, Type.TObject<{
130
140
  readonly schema: Type.TLiteral<"humain-flow-event">;
@@ -145,7 +155,7 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
145
155
  readonly role: Type.TUnion<[Type.TLiteral<"scout">, Type.TLiteral<"worker">, Type.TLiteral<"implementer">, Type.TLiteral<"lead">, Type.TLiteral<"lead_large">, Type.TLiteral<"architect">, Type.TLiteral<"reviewer">, Type.TLiteral<"security_reviewer">, Type.TLiteral<"qa">, Type.TLiteral<"triage">]>;
146
156
  readonly attempt: Type.TInteger;
147
157
  readonly state: Type.TUnion<[Type.TLiteral<"started">, Type.TLiteral<"succeeded">, Type.TLiteral<"failed">, Type.TLiteral<"retried">, Type.TLiteral<"cancelled">]>;
148
- readonly failureClass: Type.TOptional<Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">]>>;
158
+ readonly failureClass: Type.TOptional<Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">, Type.TLiteral<"review_findings">]>>;
149
159
  }>;
150
160
  }>, Type.TObject<{
151
161
  readonly schema: Type.TLiteral<"humain-flow-event">;
@@ -197,6 +207,8 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
197
207
  readonly verdict: Type.TUnion<[Type.TLiteral<"pass">, Type.TLiteral<"fail">, Type.TLiteral<"blocked">]>;
198
208
  readonly findingsCount: Type.TInteger;
199
209
  readonly checkId: Type.TOptional<Type.TString>;
210
+ readonly round: Type.TOptional<Type.TInteger>;
211
+ readonly attribution: Type.TOptional<Type.TUnion<[Type.TLiteral<"passed">, Type.TLiteral<"real">, Type.TLiteral<"pre_existing">, Type.TLiteral<"flaky">, Type.TLiteral<"deadline_limited">, Type.TLiteral<"unavailable">]>>;
200
212
  }>;
201
213
  }>, Type.TObject<{
202
214
  readonly schema: Type.TLiteral<"humain-flow-event">;
@@ -275,7 +287,7 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
275
287
  readonly kind: Type.TLiteral<"run_settled">;
276
288
  readonly payload: Type.TObject<{
277
289
  readonly outcome: Type.TUnion<[Type.TLiteral<"succeeded">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">, Type.TLiteral<"budget_stopped">, Type.TLiteral<"interrupted">]>;
278
- readonly failureClass: Type.TOptional<Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">]>>;
290
+ readonly failureClass: Type.TOptional<Type.TUnion<[Type.TLiteral<"provider_error">, Type.TLiteral<"provider_unreachable">, Type.TLiteral<"rate_limit">, Type.TLiteral<"timeout">, Type.TLiteral<"check_failed">, Type.TLiteral<"review_rejected">, Type.TLiteral<"qa_failed">, Type.TLiteral<"budget_stop">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">, Type.TLiteral<"unsafe_scope">, Type.TLiteral<"stalled">, Type.TLiteral<"config_invalid">, Type.TLiteral<"internal">, Type.TLiteral<"review_verdict_missing">, Type.TLiteral<"verification_unavailable">, Type.TLiteral<"blocked">, Type.TLiteral<"review_findings">]>>;
279
291
  readonly settledCleanly: Type.TBoolean;
280
292
  readonly retryOffer: Type.TArray<Type.TUnion<[Type.TLiteral<"flow">, Type.TLiteral<"direct">]>>;
281
293
  readonly totals: Type.TObject<{
@@ -340,6 +352,11 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
340
352
  readonly requests: Type.TInteger;
341
353
  }>>;
342
354
  }>;
355
+ readonly checkCache: Type.TOptional<Type.TObject<{
356
+ readonly hits: Type.TInteger;
357
+ readonly misses: Type.TInteger;
358
+ readonly savedMs: Type.TInteger;
359
+ }>>;
343
360
  }>;
344
361
  }>, Type.TObject<{
345
362
  readonly schema: Type.TLiteral<"humain-flow-event">;
@@ -359,6 +376,150 @@ export declare const FlowEventV1Schema: Type.TUnion<[Type.TObject<{
359
376
  readonly reason: Type.TUnion<[Type.TLiteral<"preexisting_check_failures">]>;
360
377
  readonly checkIds: Type.TArray<Type.TString>;
361
378
  }>;
379
+ }>, Type.TObject<{
380
+ readonly schema: Type.TLiteral<"humain-flow-event">;
381
+ readonly schemaVersion: Type.TLiteral<1>;
382
+ readonly eventId: Type.TString;
383
+ readonly runId: Type.TString;
384
+ readonly seq: Type.TInteger;
385
+ readonly ts: Type.TRefine<Type.TString>;
386
+ readonly profile: Type.TObject<{
387
+ readonly id: Type.TString;
388
+ readonly version: Type.TInteger;
389
+ readonly digest: Type.TString;
390
+ }>;
391
+ readonly causes: Type.TArray<Type.TString>;
392
+ readonly kind: Type.TLiteral<"implementation_ready">;
393
+ readonly payload: Type.TObject<{
394
+ readonly taskId: Type.TString;
395
+ readonly round: Type.TInteger;
396
+ readonly treeDigest: Type.TString;
397
+ readonly filesChangedCount: Type.TInteger;
398
+ }>;
399
+ }>, Type.TObject<{
400
+ readonly schema: Type.TLiteral<"humain-flow-event">;
401
+ readonly schemaVersion: Type.TLiteral<1>;
402
+ readonly eventId: Type.TString;
403
+ readonly runId: Type.TString;
404
+ readonly seq: Type.TInteger;
405
+ readonly ts: Type.TRefine<Type.TString>;
406
+ readonly profile: Type.TObject<{
407
+ readonly id: Type.TString;
408
+ readonly version: Type.TInteger;
409
+ readonly digest: Type.TString;
410
+ }>;
411
+ readonly causes: Type.TArray<Type.TString>;
412
+ readonly kind: Type.TLiteral<"verification_started">;
413
+ readonly payload: Type.TObject<{
414
+ readonly round: Type.TInteger;
415
+ readonly checksCount: Type.TInteger;
416
+ readonly scope: Type.TUnion<[Type.TLiteral<"scoped">, Type.TLiteral<"full">]>;
417
+ readonly budgetMs: Type.TInteger;
418
+ readonly cachedBaselines: Type.TInteger;
419
+ }>;
420
+ }>, Type.TObject<{
421
+ readonly schema: Type.TLiteral<"humain-flow-event">;
422
+ readonly schemaVersion: Type.TLiteral<1>;
423
+ readonly eventId: Type.TString;
424
+ readonly runId: Type.TString;
425
+ readonly seq: Type.TInteger;
426
+ readonly ts: Type.TRefine<Type.TString>;
427
+ readonly profile: Type.TObject<{
428
+ readonly id: Type.TString;
429
+ readonly version: Type.TInteger;
430
+ readonly digest: Type.TString;
431
+ }>;
432
+ readonly causes: Type.TArray<Type.TString>;
433
+ readonly kind: Type.TLiteral<"repair_proposed">;
434
+ readonly payload: Type.TObject<{
435
+ readonly round: Type.TInteger;
436
+ readonly checkIds: Type.TArray<Type.TString>;
437
+ readonly treeDigest: Type.TString;
438
+ }>;
439
+ }>, Type.TObject<{
440
+ readonly schema: Type.TLiteral<"humain-flow-event">;
441
+ readonly schemaVersion: Type.TLiteral<1>;
442
+ readonly eventId: Type.TString;
443
+ readonly runId: Type.TString;
444
+ readonly seq: Type.TInteger;
445
+ readonly ts: Type.TRefine<Type.TString>;
446
+ readonly profile: Type.TObject<{
447
+ readonly id: Type.TString;
448
+ readonly version: Type.TInteger;
449
+ readonly digest: Type.TString;
450
+ }>;
451
+ readonly causes: Type.TArray<Type.TString>;
452
+ readonly kind: Type.TLiteral<"repair_started">;
453
+ readonly payload: Type.TObject<{
454
+ readonly round: Type.TInteger;
455
+ readonly taskId: Type.TString;
456
+ readonly trigger: Type.TUnion<[Type.TLiteral<"auto">]>;
457
+ }>;
458
+ }>, Type.TObject<{
459
+ readonly schema: Type.TLiteral<"humain-flow-event">;
460
+ readonly schemaVersion: Type.TLiteral<1>;
461
+ readonly eventId: Type.TString;
462
+ readonly runId: Type.TString;
463
+ readonly seq: Type.TInteger;
464
+ readonly ts: Type.TRefine<Type.TString>;
465
+ readonly profile: Type.TObject<{
466
+ readonly id: Type.TString;
467
+ readonly version: Type.TInteger;
468
+ readonly digest: Type.TString;
469
+ }>;
470
+ readonly causes: Type.TArray<Type.TString>;
471
+ readonly kind: Type.TLiteral<"repair_finished">;
472
+ readonly payload: Type.TObject<{
473
+ readonly round: Type.TInteger;
474
+ readonly state: Type.TUnion<[Type.TLiteral<"kept">, Type.TLiteral<"reverted">, Type.TLiteral<"failed">, Type.TLiteral<"cancelled">]>;
475
+ readonly treeDigest: Type.TString;
476
+ }>;
477
+ }>, Type.TObject<{
478
+ readonly schema: Type.TLiteral<"humain-flow-event">;
479
+ readonly schemaVersion: Type.TLiteral<1>;
480
+ readonly eventId: Type.TString;
481
+ readonly runId: Type.TString;
482
+ readonly seq: Type.TInteger;
483
+ readonly ts: Type.TRefine<Type.TString>;
484
+ readonly profile: Type.TObject<{
485
+ readonly id: Type.TString;
486
+ readonly version: Type.TInteger;
487
+ readonly digest: Type.TString;
488
+ }>;
489
+ readonly causes: Type.TArray<Type.TString>;
490
+ readonly kind: Type.TLiteral<"repair_skipped">;
491
+ readonly payload: Type.TObject<{
492
+ readonly round: Type.TInteger;
493
+ readonly reason: Type.TUnion<[Type.TLiteral<"user_edited">, Type.TLiteral<"host_denied">, Type.TLiteral<"grant_timeout">, Type.TLiteral<"no_progress">, Type.TLiteral<"deadline">, Type.TLiteral<"exhausted">, Type.TLiteral<"not_repairable">]>;
494
+ }>;
495
+ }>, Type.TObject<{
496
+ readonly schema: Type.TLiteral<"humain-flow-event">;
497
+ readonly schemaVersion: Type.TLiteral<1>;
498
+ readonly eventId: Type.TString;
499
+ readonly runId: Type.TString;
500
+ readonly seq: Type.TInteger;
501
+ readonly ts: Type.TRefine<Type.TString>;
502
+ readonly profile: Type.TObject<{
503
+ readonly id: Type.TString;
504
+ readonly version: Type.TInteger;
505
+ readonly digest: Type.TString;
506
+ }>;
507
+ readonly causes: Type.TArray<Type.TString>;
508
+ readonly kind: Type.TLiteral<"verification_settled">;
509
+ readonly payload: Type.TObject<{
510
+ readonly verdict: Type.TUnion<[Type.TLiteral<"verified">, Type.TLiteral<"verified_with_preexisting">, Type.TLiteral<"checks_failing">, Type.TLiteral<"verification_unavailable">]>;
511
+ readonly reason: Type.TOptional<Type.TUnion<[Type.TLiteral<"no_checks">, Type.TLiteral<"could_not_run">, Type.TLiteral<"deadline">, Type.TLiteral<"workspace_changed">, Type.TLiteral<"superseded">, Type.TLiteral<"cancelled">, Type.TLiteral<"crash">]>>;
512
+ readonly counts: Type.TObject<{
513
+ readonly passed: Type.TInteger;
514
+ readonly real: Type.TInteger;
515
+ readonly preExisting: Type.TInteger;
516
+ readonly flaky: Type.TInteger;
517
+ readonly deadlineLimited: Type.TInteger;
518
+ readonly unavailable: Type.TInteger;
519
+ }>;
520
+ readonly repairRounds: Type.TInteger;
521
+ readonly readyToVerdictMs: Type.TInteger;
522
+ }>;
362
523
  }>]>;
363
524
  export type FlowEventV1 = Static<typeof FlowEventV1Schema>;
364
525
  /** Validates a plain-data snapshot of `input` and returns the snapshot (never the caller's object). */
@@ -1 +1 @@
1
- {"version":3,"file":"flow-events.d.ts","sourceRoot":"","sources":["../src/flow-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,IAAI,EAAE,MAAM,SAAS,CAAC;AAqB1D,OAAO,EAAE,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/E;;;;;GAKG;AAEH,eAAO,MAAM,gBAAgB,YAC5B,aAAa,EACb,cAAc,EACd,WAAW,EACX,aAAa,EACb,UAAU,EACV,SAAS,EACT,eAAe,EACf,SAAS,EACT,QAAQ,EACR,SAAS,EACT,SAAS,EACT,aAAa,EACb,SAAS,CACA,CAAC;AACX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9D,qIAAqI;AACrI,eAAO,MAAM,oBAAoB,YAAI,4BAA4B,CAAU,CAAC;AAC5E,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AA2BtE,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgM5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAe3D,uGAAuG;AACvG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAE5D"}
@@ -21,10 +21,52 @@ export const FLOW_EVENT_KINDS = [
21
21
  "message",
22
22
  "run_settled",
23
23
  "warning",
24
+ "implementation_ready",
25
+ "verification_started",
26
+ "repair_proposed",
27
+ "repair_started",
28
+ "repair_finished",
29
+ "repair_skipped",
30
+ "verification_settled",
24
31
  ];
25
32
  /** Content-free warning reasons. `preexisting_check_failures`: checks already failed identically before the run changed anything. */
26
33
  export const FLOW_WARNING_REASONS = ["preexisting_check_failures"];
34
+ /** Per-check attribution of a verify-after check result (emitted only for runs admitted with `verification: "after"`). */
35
+ export const FLOW_CHECK_ATTRIBUTIONS = [
36
+ "passed",
37
+ "real",
38
+ "pre_existing",
39
+ "flaky",
40
+ "deadline_limited",
41
+ "unavailable",
42
+ ];
43
+ export const FLOW_VERIFICATION_VERDICTS = [
44
+ "verified",
45
+ "verified_with_preexisting",
46
+ "checks_failing",
47
+ "verification_unavailable",
48
+ ];
49
+ export const FLOW_VERIFICATION_REASONS = [
50
+ "no_checks",
51
+ "could_not_run",
52
+ "deadline",
53
+ "workspace_changed",
54
+ "superseded",
55
+ "cancelled",
56
+ "crash",
57
+ ];
58
+ export const FLOW_REPAIR_SKIP_REASONS = [
59
+ "user_edited",
60
+ "host_denied",
61
+ "grant_timeout",
62
+ "no_progress",
63
+ "deadline",
64
+ "exhausted",
65
+ "not_repairable",
66
+ ];
27
67
  const Mode = lit("auto", "direct");
68
+ const Round = Type.Integer({ minimum: 0, maximum: 4 });
69
+ const RepairRound = Type.Integer({ minimum: 1, maximum: 4 });
28
70
  const Effort = lit("low", "medium", "high");
29
71
  const EventModelRefSchema = StrictObject({ provider: FlowIdSchema, model: Type.String({ pattern: FLOW_ID_PATTERN }) });
30
72
  const event = (kind, payload) => StrictObject({
@@ -55,7 +97,8 @@ export const FlowEventV1Schema = Type.Union([
55
97
  })),
56
98
  event("size_decided", StrictObject({
57
99
  size: FlowSizeSchema,
58
- source: lit("rules", "triage", "override"),
100
+ source: lit("rules", "signals", "triage", "override"),
101
+ basis: Type.Optional(lit("prompt", "original_request")),
59
102
  ruleScore: Type.Number({ minimum: 0, maximum: 1_000_000 }),
60
103
  thresholds: StrictObject({
61
104
  mediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),
@@ -104,6 +147,9 @@ export const FlowEventV1Schema = Type.Union([
104
147
  verdict: lit("pass", "fail", "blocked"),
105
148
  findingsCount: FlowCountSchema,
106
149
  checkId: Type.Optional(FlowIdSchema),
150
+ // verify-after only: the check round and its attribution, emitted once the check is attributed.
151
+ round: Type.Optional(Round),
152
+ attribution: Type.Optional(lit(...FLOW_CHECK_ATTRIBUTIONS)),
107
153
  })),
108
154
  event("budget", StrictObject({
109
155
  spentMicrousd: FlowMicrousdSchema,
@@ -131,12 +177,55 @@ export const FlowEventV1Schema = Type.Union([
131
177
  // Subset of the two retry modes offered to the user; unique, order-free (full offer = both).
132
178
  retryOffer: Type.Array(lit("flow", "direct"), { maxItems: 2, uniqueItems: true }),
133
179
  totals: partialByRole(RoleTotals),
180
+ // Baseline check cache counts (pristine-tree results reused across runs); counts only, never check identities.
181
+ checkCache: Type.Optional(StrictObject({ hits: FlowCountSchema, misses: FlowCountSchema, savedMs: FlowCountSchema })),
134
182
  })),
135
183
  event("warning", StrictObject({
136
184
  reason: lit(...FLOW_WARNING_REASONS),
137
185
  // Opaque check ids (the same ids `verdict.checkId` uses), never check names or commands.
138
186
  checkIds: Type.Array(FlowIdSchema, { minItems: 1, maxItems: 16, uniqueItems: true }),
139
187
  })),
188
+ // verify-after kinds: emitted only for runs whose admission or profile requests `verification: "after"`.
189
+ // `treeDigest` is sha256 of the candidate tree identity, never a path.
190
+ event("implementation_ready", StrictObject({
191
+ taskId: FlowIdSchema,
192
+ round: Round,
193
+ treeDigest: FlowDigestSchema,
194
+ filesChangedCount: FlowCountSchema,
195
+ })),
196
+ event("verification_started", StrictObject({
197
+ round: Round,
198
+ checksCount: FlowCountSchema,
199
+ scope: lit("scoped", "full"),
200
+ budgetMs: FlowCountSchema,
201
+ cachedBaselines: FlowCountSchema,
202
+ })),
203
+ event("repair_proposed", StrictObject({
204
+ round: RepairRound,
205
+ checkIds: Type.Array(FlowIdSchema, { minItems: 1, maxItems: 16, uniqueItems: true }),
206
+ treeDigest: FlowDigestSchema,
207
+ })),
208
+ event("repair_started", StrictObject({ round: RepairRound, taskId: FlowIdSchema, trigger: lit("auto") })),
209
+ event("repair_finished", StrictObject({
210
+ round: RepairRound,
211
+ state: lit("kept", "reverted", "failed", "cancelled"),
212
+ treeDigest: FlowDigestSchema,
213
+ })),
214
+ event("repair_skipped", StrictObject({ round: RepairRound, reason: lit(...FLOW_REPAIR_SKIP_REASONS) })),
215
+ event("verification_settled", StrictObject({
216
+ verdict: lit(...FLOW_VERIFICATION_VERDICTS),
217
+ reason: Type.Optional(lit(...FLOW_VERIFICATION_REASONS)),
218
+ counts: StrictObject({
219
+ passed: FlowCountSchema,
220
+ real: FlowCountSchema,
221
+ preExisting: FlowCountSchema,
222
+ flaky: FlowCountSchema,
223
+ deadlineLimited: FlowCountSchema,
224
+ unavailable: FlowCountSchema,
225
+ }),
226
+ repairRounds: Round,
227
+ readyToVerdictMs: FlowCountSchema,
228
+ })),
140
229
  ]);
141
230
  const Validator = compileFlow(FlowEventV1Schema);
142
231
  /** `request_usage.costMicrousd` is null exactly when `costBasis` is "unknown"; never 0 for unknown. */
@@ -1 +1 @@
1
- {"version":3,"file":"flow-events.js","sourceRoot":"","sources":["../src/flow-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,SAAS,CAAC;AAC1D,OA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CAAC","sourcesContent":["import { type Static, type TSchema, Type } from \"typebox\";\nimport {\n\tcompileFlow,\n\tFLOW_ID_PATTERN,\n\tFlowCountSchema,\n\tFlowDigestSchema,\n\tFlowFailureClassSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\tFlowPositiveIntSchema,\n\tFlowProfileRefSchema,\n\tFlowReasonClassSchema,\n\tFlowRoleSchema,\n\tFlowSizeSchema,\n\tFlowTimestampSchema,\n\tlit,\n\tparseFlowData,\n\tpartialByRole,\n\tStrictObject,\n} from \"./flow-common.ts\";\n\nexport { FlowProfileRefSchema, type FlowProfileRefV1 } from \"./flow-common.ts\";\n\n/**\n * Privacy rule: every string in an event is an Id, a Digest, an enum literal, or an ISO timestamp.\n * There is no free-text field, so prompts, messages and model output have no place to go. Syntax checks cannot tell\n * semantic content, though: a path-like string can match an Id or model pattern. Producers must put only catalog\n * provider/model identifiers in those fields (see docs/flow-contracts.md, trust boundaries).\n */\n\nexport const FLOW_EVENT_KINDS = [\n\t\"run_started\",\n\t\"size_decided\",\n\t\"escalated\",\n\t\"route_bound\",\n\t\"fallback\",\n\t\"attempt\",\n\t\"request_usage\",\n\t\"verdict\",\n\t\"budget\",\n\t\"control\",\n\t\"message\",\n\t\"run_settled\",\n\t\"warning\",\n] as const;\nexport type FlowEventKind = (typeof FLOW_EVENT_KINDS)[number];\n\n/** Content-free warning reasons. `preexisting_check_failures`: checks already failed identically before the run changed anything. */\nexport const FLOW_WARNING_REASONS = [\"preexisting_check_failures\"] as const;\nexport type FlowWarningReason = (typeof FLOW_WARNING_REASONS)[number];\n\nconst Mode = lit(\"auto\", \"direct\");\nconst Effort = lit(\"low\", \"medium\", \"high\");\nconst EventModelRefSchema = StrictObject({ provider: FlowIdSchema, model: Type.String({ pattern: FLOW_ID_PATTERN }) });\n\nconst event = <const K extends string, P extends TSchema>(kind: K, payload: P) =>\n\tStrictObject({\n\t\tschema: Type.Literal(\"humain-flow-event\"),\n\t\tschemaVersion: Type.Literal(1),\n\t\teventId: FlowIdSchema,\n\t\trunId: FlowIdSchema,\n\t\tseq: FlowPositiveIntSchema,\n\t\tts: FlowTimestampSchema,\n\t\tprofile: FlowProfileRefSchema,\n\t\tcauses: Type.Array(FlowIdSchema, { maxItems: 16 }),\n\t\tkind: Type.Literal(kind),\n\t\tpayload,\n\t});\n\nconst RoleTotals = StrictObject({\n\ttokens: FlowCountSchema,\n\tcostMicrousd: FlowMicrousdSchema,\n\tdurationMs: FlowCountSchema,\n\trequests: FlowCountSchema,\n});\n\nexport const FlowEventV1Schema = Type.Union([\n\tevent(\n\t\t\"run_started\",\n\t\tStrictObject({\n\t\t\tmode: Mode,\n\t\t\tsurface: lit(\"cli\", \"web\"),\n\t\t\tadmissionDigest: FlowDigestSchema,\n\t\t\tinputsCount: FlowCountSchema,\n\t\t\tgoalSha256: FlowDigestSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"size_decided\",\n\t\tStrictObject({\n\t\t\tsize: FlowSizeSchema,\n\t\t\tsource: lit(\"rules\", \"triage\", \"override\"),\n\t\t\truleScore: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\tthresholds: StrictObject({\n\t\t\t\tmediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t\tlargeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t}),\n\t\t}),\n\t),\n\tevent(\"escalated\", StrictObject({ from: FlowSizeSchema, to: FlowSizeSchema, reasonClass: FlowReasonClassSchema })),\n\tevent(\n\t\t\"route_bound\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tmodel: EventModelRefSchema,\n\t\t\teffort: Effort,\n\t\t\tbinding: lit(\"primary\", \"backup\", \"lead_selected\"),\n\t\t\tbackupIndex: Type.Integer({ minimum: 0, maximum: 7 }),\n\t\t}),\n\t),\n\tevent(\n\t\t\"fallback\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tfrom: EventModelRefSchema,\n\t\t\tto: EventModelRefSchema,\n\t\t\treasonClass: FlowReasonClassSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"attempt\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tattempt: FlowPositiveIntSchema,\n\t\t\tstate: lit(\"started\", \"succeeded\", \"failed\", \"retried\", \"cancelled\"),\n\t\t\tfailureClass: Type.Optional(FlowFailureClassSchema),\n\t\t}),\n\t),\n\tevent(\n\t\t\"request_usage\",\n\t\tStrictObject({\n\t\t\trequestId: FlowIdSchema,\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tmodel: EventModelRefSchema,\n\t\t\tinputTokens: FlowCountSchema,\n\t\t\toutputTokens: FlowCountSchema,\n\t\t\tcacheReadTokens: FlowCountSchema,\n\t\t\tcacheWriteTokens: FlowCountSchema,\n\t\t\tcostMicrousd: Type.Union([FlowMicrousdSchema, Type.Null()]),\n\t\t\tcostBasis: lit(\"reported\", \"estimated\", \"unknown\"),\n\t\t\tdurationMs: FlowCountSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"verdict\",\n\t\tStrictObject({\n\t\t\tstage: lit(\"check\", \"review\", \"qa\"),\n\t\t\ttaskId: FlowIdSchema,\n\t\t\tverdict: lit(\"pass\", \"fail\", \"blocked\"),\n\t\t\tfindingsCount: FlowCountSchema,\n\t\t\tcheckId: Type.Optional(FlowIdSchema),\n\t\t}),\n\t),\n\tevent(\n\t\t\"budget\",\n\t\tStrictObject({\n\t\t\tspentMicrousd: FlowMicrousdSchema,\n\t\t\tcapMicrousd: FlowMicrousdSchema,\n\t\t\tpct: Type.Number({ minimum: 0, maximum: 100 }),\n\t\t\tstate: lit(\"ok\", \"warn\", \"stop\"),\n\t\t}),\n\t),\n\tevent(\n\t\t\"control\",\n\t\tStrictObject({\n\t\t\taction: lit(\"pause\", \"resume\", \"cancel\", \"message\", \"status\"),\n\t\t\tcommandId: FlowIdSchema,\n\t\t\tstate: lit(\"accepted\", \"applied\", \"rejected\"),\n\t\t\tlatencyMs: FlowCountSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"message\",\n\t\tStrictObject({\n\t\t\tmessageId: FlowIdSchema,\n\t\t\tdisposition: lit(\"live\", \"queued\", \"rejected\"),\n\t\t\ttargetRole: FlowRoleSchema,\n\t\t\ttextSha256: FlowDigestSchema,\n\t\t\ttextLength: Type.Integer({ minimum: 1, maximum: 16_000 }),\n\t\t}),\n\t),\n\tevent(\n\t\t\"run_settled\",\n\t\tStrictObject({\n\t\t\toutcome: lit(\"succeeded\", \"failed\", \"cancelled\", \"budget_stopped\", \"interrupted\"),\n\t\t\tfailureClass: Type.Optional(FlowFailureClassSchema),\n\t\t\tsettledCleanly: Type.Boolean(),\n\t\t\t// Subset of the two retry modes offered to the user; unique, order-free (full offer = both).\n\t\t\tretryOffer: Type.Array(lit(\"flow\", \"direct\"), { maxItems: 2, uniqueItems: true }),\n\t\t\ttotals: partialByRole(RoleTotals),\n\t\t}),\n\t),\n\tevent(\n\t\t\"warning\",\n\t\tStrictObject({\n\t\t\treason: lit(...FLOW_WARNING_REASONS),\n\t\t\t// Opaque check ids (the same ids `verdict.checkId` uses), never check names or commands.\n\t\t\tcheckIds: Type.Array(FlowIdSchema, { minItems: 1, maxItems: 16, uniqueItems: true }),\n\t\t}),\n\t),\n]);\nexport type FlowEventV1 = Static<typeof FlowEventV1Schema>;\n\nconst Validator = compileFlow(FlowEventV1Schema);\n\n/** `request_usage.costMicrousd` is null exactly when `costBasis` is \"unknown\"; never 0 for unknown. */\nfunction crossFieldsValid(doc: FlowEventV1): boolean {\n\tif (doc.kind === \"request_usage\")\n\t\treturn (doc.payload.costMicrousd === null) === (doc.payload.costBasis === \"unknown\");\n\treturn true;\n}\n\nfunction isEvent(value: unknown): value is FlowEventV1 {\n\treturn Validator.Check(value) && crossFieldsValid(value);\n}\n\n/** Validates a plain-data snapshot of `input` and returns the snapshot (never the caller's object). */\nexport function parseFlowEventV1(input: unknown): FlowEventV1 {\n\treturn parseFlowData(\"event_invalid\", input, isEvent);\n}\n"]}
1
+ {"version":3,"file":"flow-events.js","sourceRoot":"","sources":["../src/flow-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,IAAI,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EACN,WAAW,EACX,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,GAAG,EACH,aAAa,EACb,aAAa,EACb,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAyB,MAAM,kBAAkB,CAAC;AAE/E;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,aAAa;IACb,cAAc;IACd,WAAW;IACX,aAAa;IACb,UAAU;IACV,SAAS;IACT,eAAe;IACf,SAAS;IACT,QAAQ;IACR,SAAS;IACT,SAAS;IACT,aAAa;IACb,SAAS;IACT,sBAAsB;IACtB,sBAAsB;IACtB,iBAAiB;IACjB,gBAAgB;IAChB,iBAAiB;IACjB,gBAAgB;IAChB,sBAAsB;CACb,CAAC;AAGX,qIAAqI;AACrI,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,4BAA4B,CAAU,CAAC;AAG5E,0HAA0H;AAC1H,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACtC,QAAQ;IACR,MAAM;IACN,cAAc;IACd,OAAO;IACP,kBAAkB;IAClB,aAAa;CACJ,CAAC;AAEX,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACzC,UAAU;IACV,2BAA2B;IAC3B,gBAAgB;IAChB,0BAA0B;CACjB,CAAC;AAEX,MAAM,CAAC,MAAM,yBAAyB,GA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AAgB,EAAE,eAAe;KACjC,CAAC,CACF;CACD,CAAC,CAAC;AAGH,MAAM,SAAS,GAAG,WAAW,CAAC,iBAAiB,CAAC,CAAC;AAEjD,uGAAuG;AACvG,SAAS,gBAAgB,CAAC,GAAgB;IACzC,IAAI,GAAG,CAAC,IAAI,KAAK,eAAe;QAC/B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC;AACb,CAAC;AAED,SAAS,OAAO,CAAC,KAAc;IAC9B,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC9C,OAAO,aAAa,CAAC,eAAe,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;AACvD,CAAC","sourcesContent":["import { type Static, type TSchema, Type } from \"typebox\";\nimport {\n\tcompileFlow,\n\tFLOW_ID_PATTERN,\n\tFlowCountSchema,\n\tFlowDigestSchema,\n\tFlowFailureClassSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\tFlowPositiveIntSchema,\n\tFlowProfileRefSchema,\n\tFlowReasonClassSchema,\n\tFlowRoleSchema,\n\tFlowSizeSchema,\n\tFlowTimestampSchema,\n\tlit,\n\tparseFlowData,\n\tpartialByRole,\n\tStrictObject,\n} from \"./flow-common.ts\";\n\nexport { FlowProfileRefSchema, type FlowProfileRefV1 } from \"./flow-common.ts\";\n\n/**\n * Privacy rule: every string in an event is an Id, a Digest, an enum literal, or an ISO timestamp.\n * There is no free-text field, so prompts, messages and model output have no place to go. Syntax checks cannot tell\n * semantic content, though: a path-like string can match an Id or model pattern. Producers must put only catalog\n * provider/model identifiers in those fields (see docs/flow-contracts.md, trust boundaries).\n */\n\nexport const FLOW_EVENT_KINDS = [\n\t\"run_started\",\n\t\"size_decided\",\n\t\"escalated\",\n\t\"route_bound\",\n\t\"fallback\",\n\t\"attempt\",\n\t\"request_usage\",\n\t\"verdict\",\n\t\"budget\",\n\t\"control\",\n\t\"message\",\n\t\"run_settled\",\n\t\"warning\",\n\t\"implementation_ready\",\n\t\"verification_started\",\n\t\"repair_proposed\",\n\t\"repair_started\",\n\t\"repair_finished\",\n\t\"repair_skipped\",\n\t\"verification_settled\",\n] as const;\nexport type FlowEventKind = (typeof FLOW_EVENT_KINDS)[number];\n\n/** Content-free warning reasons. `preexisting_check_failures`: checks already failed identically before the run changed anything. */\nexport const FLOW_WARNING_REASONS = [\"preexisting_check_failures\"] as const;\nexport type FlowWarningReason = (typeof FLOW_WARNING_REASONS)[number];\n\n/** Per-check attribution of a verify-after check result (emitted only for runs admitted with `verification: \"after\"`). */\nexport const FLOW_CHECK_ATTRIBUTIONS = [\n\t\"passed\",\n\t\"real\",\n\t\"pre_existing\",\n\t\"flaky\",\n\t\"deadline_limited\",\n\t\"unavailable\",\n] as const;\nexport type FlowCheckAttribution = (typeof FLOW_CHECK_ATTRIBUTIONS)[number];\nexport const FLOW_VERIFICATION_VERDICTS = [\n\t\"verified\",\n\t\"verified_with_preexisting\",\n\t\"checks_failing\",\n\t\"verification_unavailable\",\n] as const;\nexport type FlowVerificationVerdict = (typeof FLOW_VERIFICATION_VERDICTS)[number];\nexport const FLOW_VERIFICATION_REASONS = [\n\t\"no_checks\",\n\t\"could_not_run\",\n\t\"deadline\",\n\t\"workspace_changed\",\n\t\"superseded\",\n\t\"cancelled\",\n\t\"crash\",\n] as const;\nexport type FlowVerificationReason = (typeof FLOW_VERIFICATION_REASONS)[number];\nexport const FLOW_REPAIR_SKIP_REASONS = [\n\t\"user_edited\",\n\t\"host_denied\",\n\t\"grant_timeout\",\n\t\"no_progress\",\n\t\"deadline\",\n\t\"exhausted\",\n\t\"not_repairable\",\n] as const;\nexport type FlowRepairSkipReason = (typeof FLOW_REPAIR_SKIP_REASONS)[number];\n\nconst Mode = lit(\"auto\", \"direct\");\nconst Round = Type.Integer({ minimum: 0, maximum: 4 });\nconst RepairRound = Type.Integer({ minimum: 1, maximum: 4 });\nconst Effort = lit(\"low\", \"medium\", \"high\");\nconst EventModelRefSchema = StrictObject({ provider: FlowIdSchema, model: Type.String({ pattern: FLOW_ID_PATTERN }) });\n\nconst event = <const K extends string, P extends TSchema>(kind: K, payload: P) =>\n\tStrictObject({\n\t\tschema: Type.Literal(\"humain-flow-event\"),\n\t\tschemaVersion: Type.Literal(1),\n\t\teventId: FlowIdSchema,\n\t\trunId: FlowIdSchema,\n\t\tseq: FlowPositiveIntSchema,\n\t\tts: FlowTimestampSchema,\n\t\tprofile: FlowProfileRefSchema,\n\t\tcauses: Type.Array(FlowIdSchema, { maxItems: 16 }),\n\t\tkind: Type.Literal(kind),\n\t\tpayload,\n\t});\n\nconst RoleTotals = StrictObject({\n\ttokens: FlowCountSchema,\n\tcostMicrousd: FlowMicrousdSchema,\n\tdurationMs: FlowCountSchema,\n\trequests: FlowCountSchema,\n});\n\nexport const FlowEventV1Schema = Type.Union([\n\tevent(\n\t\t\"run_started\",\n\t\tStrictObject({\n\t\t\tmode: Mode,\n\t\t\tsurface: lit(\"cli\", \"web\"),\n\t\t\tadmissionDigest: FlowDigestSchema,\n\t\t\tinputsCount: FlowCountSchema,\n\t\t\tgoalSha256: FlowDigestSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"size_decided\",\n\t\tStrictObject({\n\t\t\tsize: FlowSizeSchema,\n\t\t\tsource: lit(\"rules\", \"signals\", \"triage\", \"override\"),\n\t\t\tbasis: Type.Optional(lit(\"prompt\", \"original_request\")),\n\t\t\truleScore: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\tthresholds: StrictObject({\n\t\t\t\tmediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t\tlargeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t}),\n\t\t}),\n\t),\n\tevent(\"escalated\", StrictObject({ from: FlowSizeSchema, to: FlowSizeSchema, reasonClass: FlowReasonClassSchema })),\n\tevent(\n\t\t\"route_bound\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tmodel: EventModelRefSchema,\n\t\t\teffort: Effort,\n\t\t\tbinding: lit(\"primary\", \"backup\", \"lead_selected\"),\n\t\t\tbackupIndex: Type.Integer({ minimum: 0, maximum: 7 }),\n\t\t}),\n\t),\n\tevent(\n\t\t\"fallback\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tfrom: EventModelRefSchema,\n\t\t\tto: EventModelRefSchema,\n\t\t\treasonClass: FlowReasonClassSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"attempt\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tattempt: FlowPositiveIntSchema,\n\t\t\tstate: lit(\"started\", \"succeeded\", \"failed\", \"retried\", \"cancelled\"),\n\t\t\tfailureClass: Type.Optional(FlowFailureClassSchema),\n\t\t}),\n\t),\n\tevent(\n\t\t\"request_usage\",\n\t\tStrictObject({\n\t\t\trequestId: FlowIdSchema,\n\t\t\ttaskId: FlowIdSchema,\n\t\t\trole: FlowRoleSchema,\n\t\t\tmodel: EventModelRefSchema,\n\t\t\tinputTokens: FlowCountSchema,\n\t\t\toutputTokens: FlowCountSchema,\n\t\t\tcacheReadTokens: FlowCountSchema,\n\t\t\tcacheWriteTokens: FlowCountSchema,\n\t\t\tcostMicrousd: Type.Union([FlowMicrousdSchema, Type.Null()]),\n\t\t\tcostBasis: lit(\"reported\", \"estimated\", \"unknown\"),\n\t\t\tdurationMs: FlowCountSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"verdict\",\n\t\tStrictObject({\n\t\t\tstage: lit(\"check\", \"review\", \"qa\"),\n\t\t\ttaskId: FlowIdSchema,\n\t\t\tverdict: lit(\"pass\", \"fail\", \"blocked\"),\n\t\t\tfindingsCount: FlowCountSchema,\n\t\t\tcheckId: Type.Optional(FlowIdSchema),\n\t\t\t// verify-after only: the check round and its attribution, emitted once the check is attributed.\n\t\t\tround: Type.Optional(Round),\n\t\t\tattribution: Type.Optional(lit(...FLOW_CHECK_ATTRIBUTIONS)),\n\t\t}),\n\t),\n\tevent(\n\t\t\"budget\",\n\t\tStrictObject({\n\t\t\tspentMicrousd: FlowMicrousdSchema,\n\t\t\tcapMicrousd: FlowMicrousdSchema,\n\t\t\tpct: Type.Number({ minimum: 0, maximum: 100 }),\n\t\t\tstate: lit(\"ok\", \"warn\", \"stop\"),\n\t\t}),\n\t),\n\tevent(\n\t\t\"control\",\n\t\tStrictObject({\n\t\t\taction: lit(\"pause\", \"resume\", \"cancel\", \"message\", \"status\"),\n\t\t\tcommandId: FlowIdSchema,\n\t\t\tstate: lit(\"accepted\", \"applied\", \"rejected\"),\n\t\t\tlatencyMs: FlowCountSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"message\",\n\t\tStrictObject({\n\t\t\tmessageId: FlowIdSchema,\n\t\t\tdisposition: lit(\"live\", \"queued\", \"rejected\"),\n\t\t\ttargetRole: FlowRoleSchema,\n\t\t\ttextSha256: FlowDigestSchema,\n\t\t\ttextLength: Type.Integer({ minimum: 1, maximum: 16_000 }),\n\t\t}),\n\t),\n\tevent(\n\t\t\"run_settled\",\n\t\tStrictObject({\n\t\t\toutcome: lit(\"succeeded\", \"failed\", \"cancelled\", \"budget_stopped\", \"interrupted\"),\n\t\t\tfailureClass: Type.Optional(FlowFailureClassSchema),\n\t\t\tsettledCleanly: Type.Boolean(),\n\t\t\t// Subset of the two retry modes offered to the user; unique, order-free (full offer = both).\n\t\t\tretryOffer: Type.Array(lit(\"flow\", \"direct\"), { maxItems: 2, uniqueItems: true }),\n\t\t\ttotals: partialByRole(RoleTotals),\n\t\t\t// Baseline check cache counts (pristine-tree results reused across runs); counts only, never check identities.\n\t\t\tcheckCache: Type.Optional(\n\t\t\t\tStrictObject({ hits: FlowCountSchema, misses: FlowCountSchema, savedMs: FlowCountSchema }),\n\t\t\t),\n\t\t}),\n\t),\n\tevent(\n\t\t\"warning\",\n\t\tStrictObject({\n\t\t\treason: lit(...FLOW_WARNING_REASONS),\n\t\t\t// Opaque check ids (the same ids `verdict.checkId` uses), never check names or commands.\n\t\t\tcheckIds: Type.Array(FlowIdSchema, { minItems: 1, maxItems: 16, uniqueItems: true }),\n\t\t}),\n\t),\n\t// verify-after kinds: emitted only for runs whose admission or profile requests `verification: \"after\"`.\n\t// `treeDigest` is sha256 of the candidate tree identity, never a path.\n\tevent(\n\t\t\"implementation_ready\",\n\t\tStrictObject({\n\t\t\ttaskId: FlowIdSchema,\n\t\t\tround: Round,\n\t\t\ttreeDigest: FlowDigestSchema,\n\t\t\tfilesChangedCount: FlowCountSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"verification_started\",\n\t\tStrictObject({\n\t\t\tround: Round,\n\t\t\tchecksCount: FlowCountSchema,\n\t\t\tscope: lit(\"scoped\", \"full\"),\n\t\t\tbudgetMs: FlowCountSchema,\n\t\t\tcachedBaselines: FlowCountSchema,\n\t\t}),\n\t),\n\tevent(\n\t\t\"repair_proposed\",\n\t\tStrictObject({\n\t\t\tround: RepairRound,\n\t\t\tcheckIds: Type.Array(FlowIdSchema, { minItems: 1, maxItems: 16, uniqueItems: true }),\n\t\t\ttreeDigest: FlowDigestSchema,\n\t\t}),\n\t),\n\tevent(\"repair_started\", StrictObject({ round: RepairRound, taskId: FlowIdSchema, trigger: lit(\"auto\") })),\n\tevent(\n\t\t\"repair_finished\",\n\t\tStrictObject({\n\t\t\tround: RepairRound,\n\t\t\tstate: lit(\"kept\", \"reverted\", \"failed\", \"cancelled\"),\n\t\t\ttreeDigest: FlowDigestSchema,\n\t\t}),\n\t),\n\tevent(\"repair_skipped\", StrictObject({ round: RepairRound, reason: lit(...FLOW_REPAIR_SKIP_REASONS) })),\n\tevent(\n\t\t\"verification_settled\",\n\t\tStrictObject({\n\t\t\tverdict: lit(...FLOW_VERIFICATION_VERDICTS),\n\t\t\treason: Type.Optional(lit(...FLOW_VERIFICATION_REASONS)),\n\t\t\tcounts: StrictObject({\n\t\t\t\tpassed: FlowCountSchema,\n\t\t\t\treal: FlowCountSchema,\n\t\t\t\tpreExisting: FlowCountSchema,\n\t\t\t\tflaky: FlowCountSchema,\n\t\t\t\tdeadlineLimited: FlowCountSchema,\n\t\t\t\tunavailable: FlowCountSchema,\n\t\t\t}),\n\t\t\trepairRounds: Round,\n\t\t\treadyToVerdictMs: FlowCountSchema,\n\t\t}),\n\t),\n]);\nexport type FlowEventV1 = Static<typeof FlowEventV1Schema>;\n\nconst Validator = compileFlow(FlowEventV1Schema);\n\n/** `request_usage.costMicrousd` is null exactly when `costBasis` is \"unknown\"; never 0 for unknown. */\nfunction crossFieldsValid(doc: FlowEventV1): boolean {\n\tif (doc.kind === \"request_usage\")\n\t\treturn (doc.payload.costMicrousd === null) === (doc.payload.costBasis === \"unknown\");\n\treturn true;\n}\n\nfunction isEvent(value: unknown): value is FlowEventV1 {\n\treturn Validator.Check(value) && crossFieldsValid(value);\n}\n\n/** Validates a plain-data snapshot of `input` and returns the snapshot (never the caller's object). */\nexport function parseFlowEventV1(input: unknown): FlowEventV1 {\n\treturn parseFlowData(\"event_invalid\", input, isEvent);\n}\n"]}
@@ -207,6 +207,8 @@ export declare const FlowProfileV1Schema: TObject<{
207
207
  readonly largeAt: Type.TNumber;
208
208
  }>;
209
209
  readonly triageRole: Type.TLiteral<"triage">;
210
+ /** Opt in to the LLM triage call for rules-large runs. Default off: size comes from rules and repo signals. */
211
+ readonly triage: TOptional<Type.TBoolean>;
210
212
  readonly maxEscalations: Type.TUnion<[Type.TLiteral<0>, Type.TLiteral<1>]>;
211
213
  }>>;
212
214
  readonly limits: TObject<{
@@ -216,7 +218,17 @@ export declare const FlowProfileV1Schema: TObject<{
216
218
  readonly maxRetries: Type.TInteger;
217
219
  readonly inactivityMs: Type.TInteger;
218
220
  readonly ciWaitMs: Type.TInteger;
221
+ /** Wall-clock budget for the whole run; checks are capped by what remains and the run settles at it. */
222
+ readonly runDeadlineMs: TOptional<Type.TInteger>;
223
+ /** Repair rounds a SMALL/MEDIUM run may spend on real deterministic check failures (default 2). */
224
+ readonly repairRounds: TOptional<Type.TInteger>;
225
+ /** verify-after: wall-clock budget for verification and repair, measured from `implementation_ready` (default 15 min). */
226
+ readonly verifyBudgetMs: TOptional<Type.TInteger>;
219
227
  }>;
228
+ /** `after` publishes the result before verification finishes (verify-after); default `inline`. */
229
+ readonly verification: TOptional<TObject<{
230
+ readonly mode: Type.TUnion<[Type.TLiteral<"inline">, Type.TLiteral<"after">]>;
231
+ }>>;
220
232
  readonly spend: TObject<{
221
233
  readonly runCapMicrousd: Type.TInteger;
222
234
  readonly warnAtPct: Type.TInteger;
@@ -1 +1 @@
1
- {"version":3,"file":"flow-profile.d.ts","sourceRoot":"","sources":["../src/flow-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,KAAK,SAAS,EAAgB,IAAI,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EAIN,KAAK,gBAAgB,EAcrB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,eAAO,MAAM,gBAAgB,qFAAkF,CAAC;AAEhH,eAAO,MAAM,qBAAqB;;;;;;;;;;EAIhC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,CAAC,OAAO,qBAAqB,CAAC,CAAC;AAErE,kEAAkE;AAClE,eAAO,MAAM,0BAA0B,YAAI,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAU,CAAC;AAC3F,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,0BAA0B,C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rictObject({
66
66
  largeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),
67
67
  }),
68
68
  triageRole: Type.Literal("triage"),
69
+ /** Opt in to the LLM triage call for rules-large runs. Default off: size comes from rules and repo signals. */
70
+ triage: Type.Optional(Type.Boolean()),
69
71
  maxEscalations: Type.Union([Type.Literal(0), Type.Literal(1)]),
70
72
  })),
71
73
  limits: StrictObject({
@@ -75,7 +77,15 @@ export const FlowProfileV1Schema = StrictObject({
75
77
  maxRetries: Type.Integer({ minimum: 0, maximum: 16 }),
76
78
  inactivityMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),
77
79
  ciWaitMs: Type.Integer({ minimum: 0, maximum: 86_400_000 }),
80
+ /** Wall-clock budget for the whole run; checks are capped by what remains and the run settles at it. */
81
+ runDeadlineMs: Type.Optional(Type.Integer({ minimum: 60_000, maximum: 86_400_000 })),
82
+ /** Repair rounds a SMALL/MEDIUM run may spend on real deterministic check failures (default 2). */
83
+ repairRounds: Type.Optional(Type.Integer({ minimum: 0, maximum: 4 })),
84
+ /** verify-after: wall-clock budget for verification and repair, measured from `implementation_ready` (default 15 min). */
85
+ verifyBudgetMs: Type.Optional(Type.Integer({ minimum: 60_000, maximum: 7_200_000 })),
78
86
  }),
87
+ /** `after` publishes the result before verification finishes (verify-after); default `inline`. */
88
+ verification: Type.Optional(StrictObject({ mode: Type.Union([Type.Literal("inline"), Type.Literal("after")]) })),
79
89
  spend: StrictObject({
80
90
  runCapMicrousd: FlowMicrousdSchema,
81
91
  warnAtPct: Type.Integer({ minimum: 1, maximum: 99 }),
@@ -1 +1 @@
1
- {"version":3,"file":"flow-profile.js","sourceRoot":"","sources":["../src/flow-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2D,IAAI,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EACN,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EAEjB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAElB,kBAAkB,EAClB,qBAAqB,EACr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wB;IAC1E,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAChF,MAAM,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import { type Static, type TObject, type TOptional, type TSchema, Type } from \"typebox\";\nimport {\n\tcanonicalWithout,\n\tcompileFlow,\n\tFlowContractError,\n\ttype FlowDigestHasher,\n\tFlowDigestSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\ttype FlowModelRef,\n\tFlowModelRefSchema,\n\tFlowPositiveIntSchema,\n\tFlowTimestampSchema,\n\thasDuplicateModels,\n\tlit,\n\tparseFlowData,\n\tpartialByRole,\n\tStrictObject,\n\tverifyFlowDigest,\n} from \"./flow-common.ts\";\n\nexport { FlowProfileRefSchema, type FlowProfileRefV1 } from \"./flow-common.ts\";\n\nexport const FlowEffortSchema = Type.Union([Type.Literal(\"low\"), Type.Literal(\"medium\"), Type.Literal(\"high\")]);\n\nexport const FlowRoleBindingSchema = StrictObject({\n\tprimary: FlowModelRefSchema,\n\tbackups: Type.Array(FlowModelRefSchema, { maxItems: 8 }),\n\teffort: FlowEffortSchema,\n});\nexport type FlowRoleBindingV1 = Static<typeof FlowRoleBindingSchema>;\n\n/** Cost tiers a selection may declare (matches Flow's `Tier`). */\nexport const FLOW_MODEL_SELECTION_TIERS = [\"cheap\", \"mid\", \"premium\", \"frontier\"] as const;\nexport type FlowSelectionTier = (typeof FLOW_MODEL_SELECTION_TIERS)[number];\n\n/** Flow's `ALL_CAPABILITIES` (method.json) plus the runtime `triage` capability; parity is pinned in the flow tests. */\nexport const FLOW_MODEL_SELECTION_CAPABILITIES = [\n\t\"scout\",\n\t\"scope_scout\",\n\t\"worker\",\n\t\"implementation_fast\",\n\t\"analysis_mid\",\n\t\"technical_lead\",\n\t\"lead_small\",\n\t\"lead\",\n\t\"lead_large\",\n\t\"implementation_strong\",\n\t\"technical_review\",\n\t\"integration_review\",\n\t\"migration_review\",\n\t\"performance_review\",\n\t\"api_contract_review\",\n\t\"qa_agent\",\n\t\"analysis_strong\",\n\t\"architect\",\n\t\"security_review\",\n\t\"triage\",\n] as const;\nexport type FlowSelectionCapability = (typeof FLOW_MODEL_SELECTION_CAPABILITIES)[number];\n\nexport const FlowSelectionEffortSchema = lit(\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\");\n\n/** Omitted `backups` inherits; an explicit `[]` means no fallbacks. Both must survive round-trips. */\nexport const FlowTierSelectionSchema = StrictObject({\n\tprimary: Type.Optional(FlowModelRefSchema),\n\tbackups: Type.Optional(Type.Array(FlowModelRefSchema, { maxItems: 8 })),\n});\nexport type FlowTierSelectionV1 = Static<typeof FlowTierSelectionSchema>;\n\nexport const FlowCapabilitySelectionSchema = StrictObject({\n\tprimary: Type.Optional(FlowModelRefSchema),\n\tbackups: Type.Optional(Type.Array(FlowModelRefSchema, { maxItems: 8 })),\n\teffort: Type.Optional(FlowSelectionEffortSchema),\n});\nexport type FlowCapabilitySelectionV1 = Static<typeof FlowCapabilitySelectionSchema>;\n\nconst optionalEach = <T extends TSchema>(keys: readonly string[], schema: T) =>\n\tStrictObject(Object.fromEntries(keys.map((key) => [key, Type.Optional(schema)])));\n\nexport const FlowModelSelectionSchema = StrictObject({\n\ttiers: Type.Optional(\n\t\toptionalEach(FLOW_MODEL_SELECTION_TIERS, FlowTierSelectionSchema) as TObject<\n\t\t\tRecord<FlowSelectionTier, TOptional<typeof FlowTierSelectionSchema>>\n\t\t>,\n\t),\n\tcapabilities: Type.Optional(\n\t\toptionalEach(FLOW_MODEL_SELECTION_CAPABILITIES, FlowCapabilitySelectionSchema) as TObject<\n\t\t\tRecord<FlowSelectionCapability, TOptional<typeof FlowCapabilitySelectionSchema>>\n\t\t>,\n\t),\n});\nexport type FlowModelSelectionV1 = Static<typeof FlowModelSelectionSchema>;\n\nexport const FlowProfileV1Schema = StrictObject({\n\tschema: Type.Literal(\"humain-flow-profile\"),\n\tschemaVersion: Type.Literal(1),\n\tid: FlowIdSchema,\n\tversion: FlowPositiveIntSchema,\n\tdigest: FlowDigestSchema,\n\tkind: Type.Union([Type.Literal(\"direct\"), Type.Literal(\"flow\")]),\n\tlabel: Type.String({ minLength: 1, maxLength: 80 }),\n\tdescription: Type.Optional(Type.String({ maxLength: 500 })),\n\tdirect: Type.Optional(\n\t\tStrictObject({ model: FlowModelRefSchema, fallbacks: Type.Array(FlowModelRefSchema, { maxItems: 8 }) }),\n\t),\n\troles: Type.Optional(partialByRole(FlowRoleBindingSchema)),\n\tsizing: Type.Optional(\n\t\tStrictObject({\n\t\t\tclassifierPolicyId: FlowIdSchema,\n\t\t\tthresholds: StrictObject({\n\t\t\t\tmediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t\tlargeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t}),\n\t\t\ttriageRole: Type.Literal(\"triage\"),\n\t\t\tmaxEscalations: Type.Union([Type.Literal(0), Type.Literal(1)]),\n\t\t}),\n\t),\n\tlimits: StrictObject({\n\t\tmaxAgents: Type.Integer({ minimum: 1, maximum: 256 }),\n\t\tmaxConcurrent: Type.Integer({ minimum: 1, maximum: 64 }),\n\t\tmaxDepth: Type.Integer({ minimum: 0, maximum: 3 }),\n\t\tmaxRetries: Type.Integer({ minimum: 0, maximum: 16 }),\n\t\tinactivityMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),\n\t\tciWaitMs: Type.Integer({ minimum: 0, maximum: 86_400_000 }),\n\t}),\n\tspend: StrictObject({\n\t\trunCapMicrousd: FlowMicrousdSchema,\n\t\twarnAtPct: Type.Integer({ minimum: 1, maximum: 99 }),\n\t\tperRoleCapMicrousd: Type.Optional(partialByRole(FlowMicrousdSchema)),\n\t}),\n\tmodelSelection: Type.Optional(FlowModelSelectionSchema),\n\tproviders: Type.Optional(StrictObject({ preference: Type.Array(FlowIdSchema, { maxItems: 16 }) })),\n\tapproval: Type.Optional(StrictObject({ approvedBy: FlowIdSchema, approvedAt: FlowTimestampSchema })),\n\tbuiltIn: Type.Optional(Type.Literal(true)),\n});\nexport type FlowProfileV1 = Static<typeof FlowProfileV1Schema>;\n\nconst Validator = compileFlow(FlowProfileV1Schema);\nconst REQUIRED_FLOW_ROLES = [\"lead\", \"worker\", \"reviewer\", \"qa\"] as const;\n\n/** Canonical text hashed (sha256 hex) to produce `digest`: the document without `digest`. */\nexport function flowProfileDigestInput(doc: FlowProfileV1): string {\n\treturn canonicalWithout(doc, \"digest\");\n}\n\nfunction selectionLayerValid(layer: FlowTierSelectionV1 | FlowCapabilitySelectionV1): boolean {\n\tconst refs = [...(layer.primary === undefined ? [] : [layer.primary]), ...(layer.backups ?? [])];\n\treturn !hasDuplicateModels(refs);\n}\n\nfunction modelSelectionValid(selection: FlowModelSelectionV1): boolean {\n\tconst layers = [...Object.values(selection.tiers ?? {}), ...Object.values(selection.capabilities ?? {})];\n\treturn layers.every(selectionLayerValid);\n}\n\nfunction crossFieldsValid(doc: FlowProfileV1): boolean {\n\tif (doc.modelSelection !== undefined && (doc.kind === \"direct\" || !modelSelectionValid(doc.modelSelection))) {\n\t\treturn false;\n\t}\n\tif (doc.kind === \"direct\") {\n\t\tif (doc.direct === undefined || doc.roles !== undefined || doc.sizing !== undefined) return false;\n\t\treturn !hasDuplicateModels([doc.direct.model, ...doc.direct.fallbacks]);\n\t}\n\tif (doc.direct !== undefined || doc.roles === undefined) return false;\n\tfor (const role of REQUIRED_FLOW_ROLES) if (doc.roles[role] === undefined) return false;\n\tfor (const binding of Object.values(doc.roles)) {\n\t\tconst refs: FlowModelRef[] = [binding.primary, ...binding.backups];\n\t\tif (hasDuplicateModels(refs)) return false;\n\t}\n\treturn doc.sizing === undefined || doc.sizing.thresholds.mediumAt <= doc.sizing.thresholds.largeAt;\n}\n\nfunction isProfile(value: unknown): value is FlowProfileV1 {\n\treturn Validator.Check(value) && crossFieldsValid(value);\n}\n\n/**\n * SHAPE ONLY: validates structure and cross-field rules but does NOT verify `digest`. Use only for documents whose\n * integrity is established elsewhere (e.g. authored drafts); prefer {@link parseFlowProfileV1}.\n */\nexport function parseFlowProfileV1Shape(input: unknown): FlowProfileV1 {\n\treturn parseFlowData(\"profile_invalid\", input, isProfile);\n}\n\n/** Shape validation plus digest verification with the injected hasher (digests are integrity, not authentication). */\nexport function parseFlowProfileV1(input: unknown, hasher: FlowDigestHasher): FlowProfileV1 {\n\tconst profile = parseFlowProfileV1Shape(input);\n\tif (!verifyFlowDigest(hasher, flowProfileDigestInput(profile), profile.digest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\treturn profile;\n}\n"]}
1
+ {"version":3,"file":"flow-profile.js","sourceRoot":"","sources":["../src/flow-profile.ts"],"names":[],"mappings":"AAAA,OAAO,EAA2D,IAAI,EAAE,MAAM,SAAS,CAAC;AACxF,OAAO,EACN,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EAEjB,gBAAgB,EAChB,YAAY,EACZ,kBAAkB,EAElB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,GAAG,EACH,aAAa,EACb,aAAa,EACb,YAAY,EACZ,gBAAgB,GAChB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,oBAAoB,EAAyB,MAAM,kBAAkB,CAAC;AAE/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAEhH,MAAM,CAAC,MAAM,qBAAqB,GAAG,YAAY,CAAC;IACjD,OAAO,EAAE,kBAAkB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AS,CAAC,KAAc;IAChC,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,gBAAgB,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAc;IACrD,OAAO,aAAa,CAAC,iBAAiB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAC3D,CAAC;AAED,sHAAsH;AACtH,MAAM,UAAU,kBAAkB,CAAC,KAAc,EAAE,MAAwB;IAC1E,MAAM,OAAO,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAChF,MAAM,IAAI,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import { type Static, type TObject, type TOptional, type TSchema, Type } from \"typebox\";\nimport {\n\tcanonicalWithout,\n\tcompileFlow,\n\tFlowContractError,\n\ttype FlowDigestHasher,\n\tFlowDigestSchema,\n\tFlowIdSchema,\n\tFlowMicrousdSchema,\n\ttype FlowModelRef,\n\tFlowModelRefSchema,\n\tFlowPositiveIntSchema,\n\tFlowTimestampSchema,\n\thasDuplicateModels,\n\tlit,\n\tparseFlowData,\n\tpartialByRole,\n\tStrictObject,\n\tverifyFlowDigest,\n} from \"./flow-common.ts\";\n\nexport { FlowProfileRefSchema, type FlowProfileRefV1 } from \"./flow-common.ts\";\n\nexport const FlowEffortSchema = Type.Union([Type.Literal(\"low\"), Type.Literal(\"medium\"), Type.Literal(\"high\")]);\n\nexport const FlowRoleBindingSchema = StrictObject({\n\tprimary: FlowModelRefSchema,\n\tbackups: Type.Array(FlowModelRefSchema, { maxItems: 8 }),\n\teffort: FlowEffortSchema,\n});\nexport type FlowRoleBindingV1 = Static<typeof FlowRoleBindingSchema>;\n\n/** Cost tiers a selection may declare (matches Flow's `Tier`). */\nexport const FLOW_MODEL_SELECTION_TIERS = [\"cheap\", \"mid\", \"premium\", \"frontier\"] as const;\nexport type FlowSelectionTier = (typeof FLOW_MODEL_SELECTION_TIERS)[number];\n\n/** Flow's `ALL_CAPABILITIES` (method.json) plus the runtime `triage` capability; parity is pinned in the flow tests. */\nexport const FLOW_MODEL_SELECTION_CAPABILITIES = [\n\t\"scout\",\n\t\"scope_scout\",\n\t\"worker\",\n\t\"implementation_fast\",\n\t\"analysis_mid\",\n\t\"technical_lead\",\n\t\"lead_small\",\n\t\"lead\",\n\t\"lead_large\",\n\t\"implementation_strong\",\n\t\"technical_review\",\n\t\"integration_review\",\n\t\"migration_review\",\n\t\"performance_review\",\n\t\"api_contract_review\",\n\t\"qa_agent\",\n\t\"analysis_strong\",\n\t\"architect\",\n\t\"security_review\",\n\t\"triage\",\n] as const;\nexport type FlowSelectionCapability = (typeof FLOW_MODEL_SELECTION_CAPABILITIES)[number];\n\nexport const FlowSelectionEffortSchema = lit(\"off\", \"minimal\", \"low\", \"medium\", \"high\", \"xhigh\", \"max\");\n\n/** Omitted `backups` inherits; an explicit `[]` means no fallbacks. Both must survive round-trips. */\nexport const FlowTierSelectionSchema = StrictObject({\n\tprimary: Type.Optional(FlowModelRefSchema),\n\tbackups: Type.Optional(Type.Array(FlowModelRefSchema, { maxItems: 8 })),\n});\nexport type FlowTierSelectionV1 = Static<typeof FlowTierSelectionSchema>;\n\nexport const FlowCapabilitySelectionSchema = StrictObject({\n\tprimary: Type.Optional(FlowModelRefSchema),\n\tbackups: Type.Optional(Type.Array(FlowModelRefSchema, { maxItems: 8 })),\n\teffort: Type.Optional(FlowSelectionEffortSchema),\n});\nexport type FlowCapabilitySelectionV1 = Static<typeof FlowCapabilitySelectionSchema>;\n\nconst optionalEach = <T extends TSchema>(keys: readonly string[], schema: T) =>\n\tStrictObject(Object.fromEntries(keys.map((key) => [key, Type.Optional(schema)])));\n\nexport const FlowModelSelectionSchema = StrictObject({\n\ttiers: Type.Optional(\n\t\toptionalEach(FLOW_MODEL_SELECTION_TIERS, FlowTierSelectionSchema) as TObject<\n\t\t\tRecord<FlowSelectionTier, TOptional<typeof FlowTierSelectionSchema>>\n\t\t>,\n\t),\n\tcapabilities: Type.Optional(\n\t\toptionalEach(FLOW_MODEL_SELECTION_CAPABILITIES, FlowCapabilitySelectionSchema) as TObject<\n\t\t\tRecord<FlowSelectionCapability, TOptional<typeof FlowCapabilitySelectionSchema>>\n\t\t>,\n\t),\n});\nexport type FlowModelSelectionV1 = Static<typeof FlowModelSelectionSchema>;\n\nexport const FlowProfileV1Schema = StrictObject({\n\tschema: Type.Literal(\"humain-flow-profile\"),\n\tschemaVersion: Type.Literal(1),\n\tid: FlowIdSchema,\n\tversion: FlowPositiveIntSchema,\n\tdigest: FlowDigestSchema,\n\tkind: Type.Union([Type.Literal(\"direct\"), Type.Literal(\"flow\")]),\n\tlabel: Type.String({ minLength: 1, maxLength: 80 }),\n\tdescription: Type.Optional(Type.String({ maxLength: 500 })),\n\tdirect: Type.Optional(\n\t\tStrictObject({ model: FlowModelRefSchema, fallbacks: Type.Array(FlowModelRefSchema, { maxItems: 8 }) }),\n\t),\n\troles: Type.Optional(partialByRole(FlowRoleBindingSchema)),\n\tsizing: Type.Optional(\n\t\tStrictObject({\n\t\t\tclassifierPolicyId: FlowIdSchema,\n\t\t\tthresholds: StrictObject({\n\t\t\t\tmediumAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t\tlargeAt: Type.Number({ minimum: 0, maximum: 1_000_000 }),\n\t\t\t}),\n\t\t\ttriageRole: Type.Literal(\"triage\"),\n\t\t\t/** Opt in to the LLM triage call for rules-large runs. Default off: size comes from rules and repo signals. */\n\t\t\ttriage: Type.Optional(Type.Boolean()),\n\t\t\tmaxEscalations: Type.Union([Type.Literal(0), Type.Literal(1)]),\n\t\t}),\n\t),\n\tlimits: StrictObject({\n\t\tmaxAgents: Type.Integer({ minimum: 1, maximum: 256 }),\n\t\tmaxConcurrent: Type.Integer({ minimum: 1, maximum: 64 }),\n\t\tmaxDepth: Type.Integer({ minimum: 0, maximum: 3 }),\n\t\tmaxRetries: Type.Integer({ minimum: 0, maximum: 16 }),\n\t\tinactivityMs: Type.Integer({ minimum: 1, maximum: 86_400_000 }),\n\t\tciWaitMs: Type.Integer({ minimum: 0, maximum: 86_400_000 }),\n\t\t/** Wall-clock budget for the whole run; checks are capped by what remains and the run settles at it. */\n\t\trunDeadlineMs: Type.Optional(Type.Integer({ minimum: 60_000, maximum: 86_400_000 })),\n\t\t/** Repair rounds a SMALL/MEDIUM run may spend on real deterministic check failures (default 2). */\n\t\trepairRounds: Type.Optional(Type.Integer({ minimum: 0, maximum: 4 })),\n\t\t/** verify-after: wall-clock budget for verification and repair, measured from `implementation_ready` (default 15 min). */\n\t\tverifyBudgetMs: Type.Optional(Type.Integer({ minimum: 60_000, maximum: 7_200_000 })),\n\t}),\n\t/** `after` publishes the result before verification finishes (verify-after); default `inline`. */\n\tverification: Type.Optional(StrictObject({ mode: Type.Union([Type.Literal(\"inline\"), Type.Literal(\"after\")]) })),\n\tspend: StrictObject({\n\t\trunCapMicrousd: FlowMicrousdSchema,\n\t\twarnAtPct: Type.Integer({ minimum: 1, maximum: 99 }),\n\t\tperRoleCapMicrousd: Type.Optional(partialByRole(FlowMicrousdSchema)),\n\t}),\n\tmodelSelection: Type.Optional(FlowModelSelectionSchema),\n\tproviders: Type.Optional(StrictObject({ preference: Type.Array(FlowIdSchema, { maxItems: 16 }) })),\n\tapproval: Type.Optional(StrictObject({ approvedBy: FlowIdSchema, approvedAt: FlowTimestampSchema })),\n\tbuiltIn: Type.Optional(Type.Literal(true)),\n});\nexport type FlowProfileV1 = Static<typeof FlowProfileV1Schema>;\n\nconst Validator = compileFlow(FlowProfileV1Schema);\nconst REQUIRED_FLOW_ROLES = [\"lead\", \"worker\", \"reviewer\", \"qa\"] as const;\n\n/** Canonical text hashed (sha256 hex) to produce `digest`: the document without `digest`. */\nexport function flowProfileDigestInput(doc: FlowProfileV1): string {\n\treturn canonicalWithout(doc, \"digest\");\n}\n\nfunction selectionLayerValid(layer: FlowTierSelectionV1 | FlowCapabilitySelectionV1): boolean {\n\tconst refs = [...(layer.primary === undefined ? [] : [layer.primary]), ...(layer.backups ?? [])];\n\treturn !hasDuplicateModels(refs);\n}\n\nfunction modelSelectionValid(selection: FlowModelSelectionV1): boolean {\n\tconst layers = [...Object.values(selection.tiers ?? {}), ...Object.values(selection.capabilities ?? {})];\n\treturn layers.every(selectionLayerValid);\n}\n\nfunction crossFieldsValid(doc: FlowProfileV1): boolean {\n\tif (doc.modelSelection !== undefined && (doc.kind === \"direct\" || !modelSelectionValid(doc.modelSelection))) {\n\t\treturn false;\n\t}\n\tif (doc.kind === \"direct\") {\n\t\tif (doc.direct === undefined || doc.roles !== undefined || doc.sizing !== undefined) return false;\n\t\treturn !hasDuplicateModels([doc.direct.model, ...doc.direct.fallbacks]);\n\t}\n\tif (doc.direct !== undefined || doc.roles === undefined) return false;\n\tfor (const role of REQUIRED_FLOW_ROLES) if (doc.roles[role] === undefined) return false;\n\tfor (const binding of Object.values(doc.roles)) {\n\t\tconst refs: FlowModelRef[] = [binding.primary, ...binding.backups];\n\t\tif (hasDuplicateModels(refs)) return false;\n\t}\n\treturn doc.sizing === undefined || doc.sizing.thresholds.mediumAt <= doc.sizing.thresholds.largeAt;\n}\n\nfunction isProfile(value: unknown): value is FlowProfileV1 {\n\treturn Validator.Check(value) && crossFieldsValid(value);\n}\n\n/**\n * SHAPE ONLY: validates structure and cross-field rules but does NOT verify `digest`. Use only for documents whose\n * integrity is established elsewhere (e.g. authored drafts); prefer {@link parseFlowProfileV1}.\n */\nexport function parseFlowProfileV1Shape(input: unknown): FlowProfileV1 {\n\treturn parseFlowData(\"profile_invalid\", input, isProfile);\n}\n\n/** Shape validation plus digest verification with the injected hasher (digests are integrity, not authentication). */\nexport function parseFlowProfileV1(input: unknown, hasher: FlowDigestHasher): FlowProfileV1 {\n\tconst profile = parseFlowProfileV1Shape(input);\n\tif (!verifyFlowDigest(hasher, flowProfileDigestInput(profile), profile.digest)) {\n\t\tthrow new FlowContractError(\"digest_mismatch\");\n\t}\n\treturn profile;\n}\n"]}
package/dist/rpc.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare const MAX_RPC_FRAME_LENGTH: number;
4
4
  export declare const MAX_GET_STATE_RESPONSE_UTF8_BYTES: number;
5
5
  export declare const MAX_GET_STATE_RESPONSE_CODE_UNITS: number;
6
6
  export declare const SUBAGENT_PROGRESS_FIELD: "subagentProgress";
7
- declare const FLOW_COMMAND_TYPES: readonly ["flow_status", "flow_pause", "flow_resume", "flow_cancel", "flow_message"];
7
+ declare const FLOW_COMMAND_TYPES: readonly ["flow_status", "flow_pause", "flow_resume", "flow_cancel", "flow_message", "flow_repair"];
8
8
  type FlowCommandType = (typeof FLOW_COMMAND_TYPES)[number];
9
9
  export type RpcWireCommand = {
10
10
  id: string;