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
@@ -0,0 +1,109 @@
1
+ /**
2
+ * src/verify/pin.ts
3
+ *
4
+ * Cross-repo P2d.2 (docs/design/cross-repo.md, OD3 = fail closed): the pin of a linked repository. At dispatch each admitted
5
+ * link target of W is snapshotted together with a bounded digest of its ignored files (`node_modules` excluded). At
6
+ * materialize the link counts as exact when both are unchanged; it is `external-link` when the target changed, the digest is
7
+ * over its bounds, the target is not admitted, or the target is not a git repository. A target's own external links are
8
+ * followed one level; a link one level deeper makes the target's pin unusable.
9
+ *
10
+ * Pure apart from the injected deps: nothing here runs git.
11
+ */
12
+ import type { TreeSnapshot } from "./dispatch";
13
+ import { perimeterKey } from "./git-top";
14
+ import { linkedTargets } from "./perimeter";
15
+
16
+ export type PinWhy = "not-observed" | "not-admitted" | "not-git" | "over-bounds" | "deep-link";
17
+
18
+ export type LinkPin =
19
+ | {
20
+ readonly kind: "pinned";
21
+ readonly root: string;
22
+ readonly head: string;
23
+ readonly fingerprint: string;
24
+ readonly ignored: string;
25
+ readonly nested: readonly LinkPin[];
26
+ }
27
+ | { readonly kind: "unpinnable"; readonly root: string; readonly why: PinWhy };
28
+
29
+ /** What `pinTarget` needs; all injected so no git is run here. */
30
+ export interface PinDeps {
31
+ snapshot(dir: string): Promise<TreeSnapshot | undefined>;
32
+ admitted(dir: string): boolean;
33
+ externalLinks(dir: string): string[];
34
+ }
35
+
36
+ /** The default link discovery: the external package links of `dir` (perimeter.ts linkedTargets). */
37
+ export const defaultExternalLinks: (dir: string) => string[] = linkedTargets;
38
+
39
+ function unpinnable(root: string, why: PinWhy): LinkPin {
40
+ return { kind: "unpinnable", root, why };
41
+ }
42
+
43
+ /** The pin of one root from its dispatch-time snapshot (no links followed). */
44
+ export function pinOf(root: string, snapshot: TreeSnapshot | undefined, admitted: boolean): LinkPin {
45
+ if (!admitted) return unpinnable(root, "not-admitted");
46
+ if (snapshot === undefined) return unpinnable(root, "not-observed");
47
+ if (snapshot.root === undefined) return unpinnable(root, "not-git");
48
+ if (snapshot.ignored === "over-bounds") return unpinnable(root, "over-bounds");
49
+ if (snapshot.ignored === undefined) return unpinnable(root, "not-observed");
50
+ return { kind: "pinned", root, head: snapshot.head, fingerprint: snapshot.fingerprint, ignored: snapshot.ignored, nested: [] };
51
+ }
52
+
53
+ /** UNC and device paths (`\\host\share`, `//host/share`, `\\?\`, `\\.\`): never touched, decided by text alone. */
54
+ function isUncOrDevice(dir: string): boolean {
55
+ return /^[\\/]{2}/.test(dir);
56
+ }
57
+
58
+ /** True only for a non-UNC directory that is admitted; checked before any snapshot or link discovery on it. */
59
+ function mayTouch(dir: string, deps: PinDeps): boolean {
60
+ return !isUncOrDevice(dir) && deps.admitted(dir);
61
+ }
62
+
63
+ /** True only when both pins are pinned and identical, nested pins included (order-independent by root key). */
64
+ export function samePin(a: LinkPin, b: LinkPin): boolean {
65
+ if (a.kind !== "pinned" || b.kind !== "pinned") return false;
66
+ if (perimeterKey(a.root) !== perimeterKey(b.root)) return false;
67
+ if (a.head !== b.head || a.fingerprint !== b.fingerprint || a.ignored !== b.ignored) return false;
68
+ if (a.nested.length !== b.nested.length) return false;
69
+ const byKey = new Map<string, LinkPin>();
70
+ for (const pin of b.nested) {
71
+ const key = perimeterKey(pin.root);
72
+ if (byKey.has(key)) return false;
73
+ byKey.set(key, pin);
74
+ }
75
+ const seen = new Set<string>();
76
+ for (const pin of a.nested) {
77
+ const key = perimeterKey(pin.root);
78
+ const other = byKey.get(key);
79
+ if (other === undefined || seen.has(key) || !samePin(pin, other)) return false;
80
+ seen.add(key);
81
+ }
82
+ return true;
83
+ }
84
+
85
+ /**
86
+ * Pins `root` and, one level deep, the targets of its own external links. A target that itself has external links makes the
87
+ * whole root unpinnable (`deep-link`, OD3); an unpinnable nested pin makes the root unpinnable with its reason. A UNC or
88
+ * device path, or a directory that is not admitted, is `not-admitted` before any snapshot or link discovery on it (I11/I12).
89
+ * Never throws.
90
+ */
91
+ export async function pinTarget(root: string, deps: PinDeps): Promise<LinkPin> {
92
+ try {
93
+ // I11/I12: refuse UNC/device paths by text and non-admitted directories before any fs or git call on them.
94
+ if (!mayTouch(root, deps)) return unpinnable(root, "not-admitted");
95
+ const own = pinOf(root, await deps.snapshot(root), true);
96
+ if (own.kind !== "pinned") return own;
97
+ const nested: LinkPin[] = [];
98
+ for (const target of deps.externalLinks(root)) {
99
+ if (!mayTouch(target, deps)) return unpinnable(root, "not-admitted");
100
+ if (deps.externalLinks(target).length > 0) return unpinnable(root, "deep-link");
101
+ const pin = pinOf(target, await deps.snapshot(target), true);
102
+ if (pin.kind !== "pinned") return unpinnable(root, pin.why);
103
+ nested.push(pin);
104
+ }
105
+ return { ...own, nested };
106
+ } catch {
107
+ return unpinnable(root, "not-observed");
108
+ }
109
+ }