opencode-model-router 2.2.0 → 2.4.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 (83) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/README.md +90 -12
  3. package/package.json +4 -1
  4. package/src/commands/output.ts +24 -1
  5. package/src/compat/child-session.ts +43 -0
  6. package/src/compat/v2-client.ts +107 -7
  7. package/src/compat/v2-hooks.ts +1435 -44
  8. package/src/escalate/attempt-recorder.ts +263 -0
  9. package/src/escalate/ladder.ts +496 -10
  10. package/src/escalate/resume.ts +208 -0
  11. package/src/escalate/variants.ts +391 -0
  12. package/src/guard/enforce.ts +186 -22
  13. package/src/guard/guards.ts +132 -6
  14. package/src/guard/store.ts +5 -0
  15. package/src/index.ts +1193 -56
  16. package/src/router/build-info.ts +151 -0
  17. package/src/router/config.ts +1611 -19
  18. package/src/router/dispatch-header.ts +46 -4
  19. package/src/router/git-tools.ts +1152 -0
  20. package/src/router/guard-profile.ts +100 -0
  21. package/src/router/plugin-agents.ts +433 -0
  22. package/src/router/prompts.ts +26 -1
  23. package/src/router/protocol.ts +180 -0
  24. package/src/router/read-only.ts +149 -0
  25. package/src/router/role-agents.ts +409 -0
  26. package/src/router/roles-config.ts +429 -0
  27. package/src/router/roles.ts +600 -0
  28. package/src/router/run-tools.ts +913 -0
  29. package/src/router/sensitive-paths.ts +101 -0
  30. package/src/router/sessions.ts +533 -9
  31. package/src/router/subagents.ts +28 -1
  32. package/src/routing/advisor/findings.ts +898 -0
  33. package/src/routing/advisor/index.ts +614 -0
  34. package/src/routing/classify/backends/host.ts +163 -0
  35. package/src/routing/classify/backends/openai-compatible.ts +275 -0
  36. package/src/routing/classify/backends/shared.ts +741 -0
  37. package/src/routing/classify/backends/typesafe.ts +315 -0
  38. package/src/routing/classify/fences.ts +96 -0
  39. package/src/routing/classify/index.ts +594 -0
  40. package/src/routing/classify/route-line.ts +362 -0
  41. package/src/routing/classify/rules.ts +667 -0
  42. package/src/routing/classify/scrub.ts +214 -0
  43. package/src/routing/classify/state.ts +148 -0
  44. package/src/routing/classify/text.ts +20 -0
  45. package/src/routing/classify/types.ts +1310 -0
  46. package/src/routing/commands/annotate-plan.ts +652 -0
  47. package/src/routing/commands/stats.ts +134 -0
  48. package/src/routing/commands/v1-roles.ts +64 -0
  49. package/src/routing/engine/index.ts +32 -0
  50. package/src/routing/engine/kernel.ts +760 -0
  51. package/src/routing/engine/ladders.ts +802 -0
  52. package/src/routing/engine/plan.ts +404 -0
  53. package/src/routing/engine/protocol-line.ts +150 -0
  54. package/src/routing/engine/roles-taxonomy.ts +52 -0
  55. package/src/routing/engine/simulate.ts +167 -0
  56. package/src/routing/engine/types.ts +368 -0
  57. package/src/routing/file-lock.ts +53 -0
  58. package/src/routing/outcomes/beta.ts +147 -0
  59. package/src/routing/outcomes/cost.ts +313 -0
  60. package/src/routing/outcomes/index.ts +215 -0
  61. package/src/routing/outcomes/ingest.ts +960 -0
  62. package/src/routing/outcomes/persist.ts +1080 -0
  63. package/src/routing/outcomes/signals.ts +650 -0
  64. package/src/routing/outcomes/stats.ts +873 -0
  65. package/src/routing/outcomes/store.ts +673 -0
  66. package/src/routing/outcomes/types.ts +1093 -0
  67. package/src/routing/roles/authority.ts +495 -0
  68. package/src/routing/roles/binding.ts +543 -0
  69. package/src/routing/roles/policy.ts +416 -0
  70. package/src/routing/roles/work-root.ts +132 -0
  71. package/src/routing/wire/dispatch.ts +2088 -0
  72. package/src/routing/wire/hint.ts +222 -0
  73. package/src/routing/wire/host-info.ts +256 -0
  74. package/src/routing/wire/runtime.ts +348 -0
  75. package/src/v2.ts +40 -1
  76. package/src/verify/checker.ts +249 -7
  77. package/src/verify/deterministic.ts +10 -1
  78. package/src/verify/dispatch.ts +63 -6
  79. package/src/verify/dod.ts +127 -10
  80. package/src/verify/gate.ts +75 -7
  81. package/src/verify/types.ts +12 -0
  82. package/src/verify/wiring.ts +55 -10
  83. package/tiers.json +13 -5
@@ -1,3 +1,14 @@
1
+ import { parseRouteLine } from "../routing/classify/route-line";
2
+
3
+ /** First characters of every router dispatch header (index.ts never adds a second one). */
4
+ export const DISPATCH_HEADER_PREFIX = "[router] You are @";
5
+
6
+ /** What index.ts puts between the header and the orchestrator's prompt. */
7
+ export const DISPATCH_HEADER_SEPARATOR = "\n\n---\n\n";
8
+
9
+ /** The header's last paragraph: the end of a header whose separator is missing. */
10
+ const FALSE_REFUSAL_PARAGRAPH = "A hand-back with zero tool calls is recorded as a false refusal.";
11
+
1
12
  /**
2
13
  * Mechanical dispatch guidance, independent of provider tool vocabulary.
3
14
  * Tier identity prevents delegates routing their assignment back to another tier.
@@ -10,17 +21,23 @@
10
21
  * The budget paragraph makes the cap explicit and prevents halting when the
11
22
  * redundancy detector flags a legitimate non-overlapping second read of a file.
12
23
  * The final notice calls out the zero-tool-call false refusals directly.
24
+ *
25
+ * `root` (plan §2.2, T1.5.3a): the dispatch's work root — the route line's `root=`
26
+ * (`routeLineRoot`) — named by the working-directory paragraph instead of the
27
+ * project directory. Absent or empty: the header is byte-identical to before.
13
28
  */
14
29
  export function buildDispatchHeader(input: {
15
30
  tier: string;
16
31
  cap: number | "none";
17
32
  projectDirectory: string | undefined;
33
+ root?: string | null;
18
34
  }): string {
19
35
  const paragraphs = [
20
- `[router] You are @${input.tier}. Execute this dispatch yourself; do not route it to another tier, and do not ask to be re-dispatched.`,
36
+ `${DISPATCH_HEADER_PREFIX}${input.tier}. Execute this dispatch yourself; do not route it to another tier, and do not ask to be re-dispatched.`,
21
37
  ];
22
- if (input.projectDirectory) {
23
- paragraphs.push(`Working directory: ${input.projectDirectory}. You are already there — do not ask permission to read or write inside it.`);
38
+ const directory = input.root || input.projectDirectory;
39
+ if (directory) {
40
+ paragraphs.push(`Working directory: ${directory}. You are already there — do not ask permission to read or write inside it.`);
24
41
  }
25
42
  paragraphs.push(
26
43
  'Tool names mentioned in this dispatch are descriptive and vary by provider; your own tool schema is the authority on what you can do. Never refuse or hand back work because a named tool looks unfamiliar or missing — attempt it, and if you cannot finish, name the specific step that failed.',
@@ -30,7 +47,32 @@ export function buildDispatchHeader(input: {
30
47
  // instructional CAP:none example, which must not override the real dispatch.
31
48
  `CAP:${input.cap}`,
32
49
  'To change the budget, put CAP:N or CAP:none accompanied by a reason: line in the dispatch.',
33
- 'A hand-back with zero tool calls is recorded as a false refusal.',
50
+ FALSE_REFUSAL_PARAGRAPH,
34
51
  );
35
52
  return paragraphs.join("\n\n");
36
53
  }
54
+
55
+ /**
56
+ * The work root a dispatch prompt names on its first-line route line (`root=`,
57
+ * an absolute path validated by the parser), or undefined. The caller passes it
58
+ * to buildDispatchHeader as `root`.
59
+ */
60
+ export function routeLineRoot(prompt: string): string | undefined {
61
+ return parseRouteLine(prompt, { positions: "first" }).line?.root;
62
+ }
63
+
64
+ /**
65
+ * The orchestrator's prompt without the router dispatch header (R6/P-15): when
66
+ * the text starts with DISPATCH_HEADER_PREFIX, everything up to and including the
67
+ * first DISPATCH_HEADER_SEPARATOR is dropped. The prefix and the separator carry
68
+ * no v1 tool vocabulary, so the v2-translated header (v2Instructions) strips the
69
+ * same way. Without a separator, the header ends at its last paragraph; a text
70
+ * with neither is returned unchanged.
71
+ */
72
+ export function stripDispatchHeader(prompt: string): string {
73
+ if (!prompt.startsWith(DISPATCH_HEADER_PREFIX)) return prompt;
74
+ const separator = prompt.indexOf(DISPATCH_HEADER_SEPARATOR);
75
+ if (separator !== -1) return prompt.slice(separator + DISPATCH_HEADER_SEPARATOR.length);
76
+ const last = prompt.indexOf(FALSE_REFUSAL_PARAGRAPH);
77
+ return last === -1 ? prompt : prompt.slice(last + FALSE_REFUSAL_PARAGRAPH.length).replace(/^\s+/, "");
78
+ }