opencode-model-router 2.7.0 → 2.9.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 (111) hide show
  1. package/CHANGELOG.md +583 -0
  2. package/README.md +20 -0
  3. package/package.json +5 -1
  4. package/src/commands/approvals.ts +354 -0
  5. package/src/commands/output.ts +34 -1
  6. package/src/compat/background.ts +2439 -0
  7. package/src/compat/child-session.ts +6 -0
  8. package/src/compat/turn-state.ts +215 -0
  9. package/src/compat/v2-client.ts +136 -17
  10. package/src/compat/v2-hooks.ts +2853 -109
  11. package/src/compat/v2-observations.ts +328 -0
  12. package/src/executor/capacity.ts +362 -0
  13. package/src/executor/child-guards.ts +40 -0
  14. package/src/executor/command.ts +265 -0
  15. package/src/executor/compile/edges.ts +809 -0
  16. package/src/executor/compile/estimate.ts +158 -0
  17. package/src/executor/compile/footprint.ts +829 -0
  18. package/src/executor/compile/index.ts +1080 -0
  19. package/src/executor/compile/parse.ts +1492 -0
  20. package/src/executor/compile/residue.ts +706 -0
  21. package/src/executor/compile/validate.ts +280 -0
  22. package/src/executor/create.ts +672 -0
  23. package/src/executor/expand.ts +551 -0
  24. package/src/executor/git.ts +1214 -0
  25. package/src/executor/host-preamble.ts +17 -0
  26. package/src/executor/instructions.ts +35 -0
  27. package/src/executor/integrate/bisect.ts +73 -0
  28. package/src/executor/integrate/checks.ts +1086 -0
  29. package/src/executor/integrate/land.ts +177 -0
  30. package/src/executor/integrate/phase-suite.ts +407 -0
  31. package/src/executor/integrate/queue.ts +3083 -0
  32. package/src/executor/integrate/run-resolver.ts +19 -0
  33. package/src/executor/launch.ts +652 -0
  34. package/src/executor/ledger.ts +2208 -0
  35. package/src/executor/observations.ts +212 -0
  36. package/src/executor/paths.ts +159 -0
  37. package/src/executor/platform.ts +39 -0
  38. package/src/executor/process-identity.ts +19 -0
  39. package/src/executor/qa-loop.ts +470 -0
  40. package/src/executor/recovery.ts +403 -0
  41. package/src/executor/runtime.ts +6233 -0
  42. package/src/executor/schedule.ts +246 -0
  43. package/src/executor/slots/env.ts +145 -0
  44. package/src/executor/slots/pool.ts +1564 -0
  45. package/src/executor/slots/provision.ts +853 -0
  46. package/src/executor/tool.ts +534 -0
  47. package/src/executor/types.ts +2064 -0
  48. package/src/executor/unattended.ts +488 -0
  49. package/src/guard/store.ts +3 -1
  50. package/src/index.ts +1789 -288
  51. package/src/router/config.ts +823 -26
  52. package/src/router/dispatch-header.ts +95 -2
  53. package/src/router/git-tools.ts +266 -19
  54. package/src/router/leases.ts +1469 -0
  55. package/src/router/logger.ts +44 -32
  56. package/src/router/protocol.ts +44 -10
  57. package/src/router/role-agents.ts +334 -20
  58. package/src/router/roles-config.ts +93 -1
  59. package/src/router/roles.ts +1 -1
  60. package/src/router/run-tools.ts +56 -4
  61. package/src/router/sessions.ts +11 -0
  62. package/src/router/tool-paths.ts +308 -0
  63. package/src/router/work-roots.ts +86 -0
  64. package/src/routing/advisor/findings.ts +25 -5
  65. package/src/routing/classify/index.ts +7 -1
  66. package/src/routing/classify/route-line.ts +96 -5
  67. package/src/routing/classify/rules.ts +11 -0
  68. package/src/routing/classify/types.ts +26 -0
  69. package/src/routing/commands/stats.ts +2 -2
  70. package/src/routing/outcomes/durations.ts +225 -0
  71. package/src/routing/outcomes/index.ts +59 -2
  72. package/src/routing/outcomes/persist.ts +409 -0
  73. package/src/routing/outcomes/signals.ts +17 -0
  74. package/src/routing/outcomes/stats.ts +170 -11
  75. package/src/routing/outcomes/timings.ts +836 -0
  76. package/src/routing/outcomes/types.ts +98 -0
  77. package/src/routing/roles/admission.ts +1028 -0
  78. package/src/routing/roles/approvals.ts +957 -0
  79. package/src/routing/roles/binding.ts +116 -13
  80. package/src/routing/roles/check-placement.ts +112 -0
  81. package/src/routing/roles/git-root.ts +500 -0
  82. package/src/routing/roles/orphans.ts +68 -0
  83. package/src/routing/roles/policy.ts +30 -3
  84. package/src/routing/roles/read-set.ts +325 -0
  85. package/src/routing/roles/work-root.ts +12 -2
  86. package/src/routing/wire/dispatch.ts +697 -30
  87. package/src/routing/wire/hint.ts +56 -8
  88. package/src/routing/wire/working-set.ts +58 -0
  89. package/src/util/linear-trim.ts +32 -0
  90. package/src/v2.ts +94 -49
  91. package/src/verify/batch.ts +7 -2
  92. package/src/verify/branch.ts +141 -0
  93. package/src/verify/canonical-path.ts +35 -0
  94. package/src/verify/deterministic.ts +268 -17
  95. package/src/verify/dispatch.ts +348 -37
  96. package/src/verify/dod.ts +46 -0
  97. package/src/verify/edges.ts +817 -0
  98. package/src/verify/exec.ts +52 -9
  99. package/src/verify/gate.ts +349 -16
  100. package/src/verify/git-top.ts +43 -0
  101. package/src/verify/head.ts +107 -0
  102. package/src/verify/pending.ts +1846 -18
  103. package/src/verify/perimeter.ts +1186 -0
  104. package/src/verify/pin.ts +109 -0
  105. package/src/verify/plan-task.ts +729 -0
  106. package/src/verify/reference.ts +297 -8
  107. package/src/verify/risk.ts +16 -3
  108. package/src/verify/runner.ts +706 -32
  109. package/src/verify/tree.ts +372 -16
  110. package/src/verify/types.ts +66 -2
  111. package/src/verify/wiring.ts +1594 -46
@@ -10,6 +10,7 @@
10
10
  // ---------------------------------------------------------------------------
11
11
 
12
12
  import type { Verdict as VerificationVerdict } from "../../verify/types";
13
+ import type { Risk } from "../classify/types";
13
14
 
14
15
  // ---------------------------------------------------------------------------
15
16
  // Primitives
@@ -570,6 +571,21 @@ export interface DecisionTrace {
570
571
  * `<need>:resumed-dispatch`. Before any narrowing: `facts.needs` is what was decided.
571
572
  */
572
573
  readonly needTerms?: readonly string[];
574
+ /**
575
+ * Role dispatches only: risk proposals before the raise-only merge. `base` is the rules class's base risk;
576
+ * `facts` includes any accepted backend raise, and `resumedDispatch` is the inherited risk, when present.
577
+ * Every proposal equal to `effective` is a joint winner (there is no risk tie-break). Older rows omit this field.
578
+ */
579
+ readonly riskSources?: {
580
+ readonly base: Risk;
581
+ readonly rules: Risk | null;
582
+ readonly routeLine: Risk | null;
583
+ readonly facts: Risk;
584
+ readonly resumedDispatch?: Risk;
585
+ readonly effective: Risk;
586
+ /** A bounded vocabulary label, never surrounding prompt text. */
587
+ readonly term?: string;
588
+ };
573
589
  }
574
590
 
575
591
  /**
@@ -579,6 +595,9 @@ export interface DecisionTrace {
579
595
  */
580
596
  export const NEED_TERM_RE = /^[a-z_]+:[a-z0-9=_ -]{1,48}$/;
581
597
 
598
+ /** A single bounded high-risk vocabulary word, or its table id for a match that could contain private text. */
599
+ export const RISK_TERM_RE = /^(?:[a-z-]{1,40}|term-[0-9]{1,3})$/;
600
+
582
601
  /** One routed dispatch (2.2) or one ladder attempt (2.3). Fields of §0.11 plus kind/v/decisionID/step/resume. */
583
602
  export interface DecisionRow extends LogRowBase {
584
603
  readonly kind: "decision";
@@ -703,6 +722,57 @@ export interface RefusalRow extends LogRowBase {
703
722
 
704
723
  export type LogRow = DecisionRow | VerdictRow | RefusalRow;
705
724
 
725
+ // ---------------------------------------------------------------------------
726
+ // Side logs: dispatch timings and orchestrator turns (timings.jsonl, turns.jsonl). Counters and labels only:
727
+ // no prompt, output or tool text is ever stored. They are NOT part of `LogRow` (decisions.jsonl is unchanged).
728
+ // ---------------------------------------------------------------------------
729
+
730
+ /** Schema version of both side-log rows; a reader skips rows with a greater `v`. */
731
+ export const SIDE_ROW_VERSION = 1;
732
+
733
+ export type DispatchTimingOutcome = "succeeded" | "failed" | "interrupted" | "unknown";
734
+ export type DispatchCapacity = "rate-limit" | "overload" | "usage-limit";
735
+
736
+ /** One finished (or abandoned) child dispatch: how long it took and how it ended. */
737
+ export interface DispatchTimingRow {
738
+ readonly kind: "dispatch-timing";
739
+ readonly v: typeof SIDE_ROW_VERSION;
740
+ /** ISO-8601 UTC time the row was written. */
741
+ readonly ts: string;
742
+ readonly parentSessionID: string;
743
+ readonly childSessionID: string;
744
+ readonly callID: string;
745
+ readonly role: string;
746
+ readonly class: string;
747
+ readonly scope: string;
748
+ readonly tier: string;
749
+ readonly model: string;
750
+ readonly background: boolean;
751
+ /** Epoch ms. */
752
+ readonly startedAt: number;
753
+ /** Epoch ms. */
754
+ readonly endedAt: number;
755
+ readonly durationMs: number;
756
+ readonly outcome: DispatchTimingOutcome;
757
+ /** Provider capacity condition that ended the dispatch, if any. */
758
+ readonly capacity: DispatchCapacity | null;
759
+ }
760
+
761
+ /** Token counters of one orchestrator turn (the steps between two prompt events of a root session). */
762
+ export interface OrchestratorTurnRow {
763
+ readonly kind: "orchestrator-turn";
764
+ readonly v: typeof SIDE_ROW_VERSION;
765
+ /** ISO-8601 UTC time the row was written. */
766
+ readonly ts: string;
767
+ readonly sessionID: string;
768
+ /** 1-based (or as numbered by the writer) turn index within the session. */
769
+ readonly turn: number;
770
+ readonly steps: number;
771
+ readonly input: number;
772
+ readonly cacheRead: number;
773
+ readonly cacheWrite: number;
774
+ }
775
+
706
776
  // ---------------------------------------------------------------------------
707
777
  // Persistence (persist.ts) — D15, A3
708
778
  // ---------------------------------------------------------------------------
@@ -725,6 +795,12 @@ export const DECISIONS_ROTATED_RE = /^decisions\.(\d{8}T\d{9}Z)-(\d+)\.jsonl$/;
725
795
  /** D15: rotate before the live log would exceed 5 MiB. */
726
796
  export const DECISIONS_MAX_BYTES = 5 * 1024 * 1024;
727
797
  export const DECISIONS_MAX_GENERATIONS = 3;
798
+ /** Side logs next to `decisions.jsonl`; same append path, size limit and generation count as the decision log. */
799
+ export const TIMINGS_FILE = "timings.jsonl";
800
+ export const TURNS_FILE = "turns.jsonl";
801
+ /** Rotated generations: `timings.<YYYYMMDDTHHMMSSmmmZ>-<pid>.jsonl` / `turns.<...>-<pid>.jsonl`. */
802
+ export const TIMINGS_ROTATED_RE = /^timings\.(\d{8}T\d{9}Z)-(\d+)\.jsonl$/;
803
+ export const TURNS_ROTATED_RE = /^turns\.(\d{8}T\d{9}Z)-(\d+)\.jsonl$/;
728
804
  /** D15: at most one flush per 30 s. */
729
805
  export const FLUSH_MIN_INTERVAL_MS = 30_000;
730
806
  export const FLUSH_BATCH_ROWS = 1_000;
@@ -828,6 +904,28 @@ export interface ReadRowsResult {
828
904
  readonly generations: number;
829
905
  }
830
906
 
907
+ /** Result of reading one side log (`timings.jsonl` or `turns.jsonl`), oldest generation first. */
908
+ export interface ReadSideRowsResult<Row> {
909
+ readonly rows: Row[];
910
+ /** Lines that failed JSON parsing or validation (a torn last line after a crash is expected); one warning per read. */
911
+ readonly skipped: number;
912
+ /** Rows written by a newer schema (`v` above {@link SIDE_ROW_VERSION}); skipped without a warning. */
913
+ readonly newer: number;
914
+ readonly files: string[];
915
+ }
916
+
917
+ /** Append/read access to `timings.jsonl` and `turns.jsonl` of one outcomes directory. Neither ever throws. */
918
+ export interface SideLogs {
919
+ readonly dir: string;
920
+ readonly timingsPath: string;
921
+ readonly turnsPath: string;
922
+ /** One append per call; rotates first when the live file would pass `maxBytes`. */
923
+ appendTimings(rows: readonly DispatchTimingRow[]): Promise<WriteResult>;
924
+ appendTurns(rows: readonly OrchestratorTurnRow[]): Promise<WriteResult>;
925
+ readTimings(): Promise<ReadSideRowsResult<DispatchTimingRow>>;
926
+ readTurns(): Promise<ReadSideRowsResult<OrchestratorTurnRow>>;
927
+ }
928
+
831
929
  /**
832
930
  * Result of checking `outcomes.json` for another writer (QA-1.3-4, QA-1.3-18):
833
931
  * - `unchanged`: nothing to merge (file untouched, removed, not ours, or unparseable and already moved aside);