opencode-model-router 2.6.0 → 2.7.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.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.7.0] - 2026-10-10
11
+
12
+ ### Added
13
+
14
+ - README: 90-second demo video below the title.
15
+
16
+ ### Removed
17
+
18
+ - **Breaking (requirement): Node.js 20 is no longer supported.** Node.js 20 reached end-of-life in April 2026; the
19
+ minimum is now Node.js 22 (`engines.node` is `>=22`, and the CI matrix runs Node 22 and 24).
20
+
21
+ ### Fixed
22
+
23
+ - A file edited by another writer during verification (for example LF lines appended to a CRLF file) could be
24
+ misreported as a checkout line-ending conversion, which made the reference approximate and turned a provable
25
+ rejection into an unverifiable result. The drift diff is now re-taken, limited to those paths, before they are
26
+ flagged. A re-diffed path gets the dependency and workspace-link drift checks and is then judged like any file
27
+ edited after dispatch: it is flagged only when the reference's checkout converted it (still the case under
28
+ `* text=auto` with native CRLF), and a failed re-diff keeps the flag (#88).
29
+
30
+ ## [2.6.1] - 2026-10-09
31
+
32
+ ### Fixed
33
+
34
+ - **OpenCode v1 no longer drops `agent.<tier>.permission` and `.tools` for `@medium` and `@heavy`.** The v1 `config`
35
+ hook replaced the user's `opencode.json` entry wholesale for every non-read-only tier except `fast`; it now keeps
36
+ the user's `permission` and `tools` for every non-read-only tier (#97). Output without user entries is unchanged,
37
+ and v2 was already correct.
38
+
10
39
  ## [2.6.0] - 2026-10-09
11
40
 
12
41
  ### Changed
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/opencode-model-router)](https://www.npmjs.com/package/opencode-model-router)
4
4
 
5
+ https://github.com/user-attachments/assets/ad521e3b-a978-475c-a07f-7a5908253057
6
+
5
7
  > **Use the cheapest model that can do the job. Automatically.**
6
8
 
7
9
  An [OpenCode](https://opencode.ai) plugin that routes every coding task to the right-priced AI tier — automatically, on every message, with 3,249–6,357 characters of system-prompt overhead depending on the orchestrator and enforcement mode.
@@ -617,6 +619,82 @@ permissions: `readOnly: true` reuses the read-only policy, or give an explicit `
617
619
  Project overrides cannot define `agents`. `opencode.json` wins for the fields it sets when it defines the same
618
620
  name. `subagentTiers` no longer creates agents that do not exist (host built-ins such as `explore` still map). `allowTools` never grants edit, delegation, Code Mode or shell. See
619
621
  [CONFIG_REFERENCE.md](docs/CONFIG_REFERENCE.md#agents--router-defined-subagents-81).
622
+
623
+ #### Focused helpers with an MCP allowlist
624
+
625
+ To give a subagent only the tools for one job, define it in the **global** overrides file,
626
+ `~/.config/opencode/opencode-model-router.overrides.jsonc`. Project overrides cannot define `agents`, on purpose:
627
+ a cloned repository must not be able to register agents with permissions.
628
+
629
+ ```jsonc
630
+ {
631
+ "agents": {
632
+ "browser-tester": {
633
+ "tier": "fast",
634
+ "description": "Tests the app in a real browser with Playwright. Use for UI and end-to-end checks.",
635
+ "readOnly": true,
636
+ "allowTools": ["playwright_*"]
637
+ },
638
+ "docs-checker": {
639
+ "tier": "fast",
640
+ "description": "Looks up library docs and compares versions with Context7.",
641
+ "readOnly": true,
642
+ "allowTools": ["context7_*"]
643
+ },
644
+ "deep-thinker": {
645
+ "tier": "heavy",
646
+ "description": "Thinks through hard problems step by step before answering.",
647
+ "readOnly": true,
648
+ "allowTools": ["sequential-thinking_*"]
649
+ }
650
+ }
651
+ }
652
+ ```
653
+
654
+ - `tier`: a tier of the active preset. The model follows the preset, so it changes with `/preset`.
655
+ - `description`: what the orchestrator reads to pick the helper. Be specific about the task and when to use it.
656
+ - `readOnly: true` or a `permission` block is required: a router agent never inherits the host's allow-all defaults.
657
+ - `allowTools`: extra tools allowed on top of that policy. MCP tools are named `<server>_<tool>`; use the server
658
+ names from your `opencode.json`. A wildcard is allowed only after a literal first character (`playwright_*`, not
659
+ `*_click`). `allowTools` cannot grant edit, shell, `read` or delegation; put those in `permission`.
660
+
661
+ Restart OpenCode after adding agents so they are registered. Reserved names (`fast`, `medium`, `heavy`, every
662
+ tier of the active preset) cannot be used as agent names.
663
+
664
+ #### Restricting the built-in tiers
665
+
666
+ `@medium` and `@heavy` otherwise see every installed tool, including MCP servers meant for a helper. Restrict them
667
+ with host permission rules in `opencode.json`. The router keeps these rules when it registers the tiers.
668
+
669
+ OpenCode 2:
670
+
671
+ ```json
672
+ {
673
+ "agents": {
674
+ "heavy": {
675
+ "permissions": [
676
+ { "action": "playwright_*", "resource": "*", "effect": "deny" }
677
+ ]
678
+ }
679
+ }
680
+ }
681
+ ```
682
+
683
+ OpenCode 1:
684
+
685
+ ```json
686
+ {
687
+ "agent": {
688
+ "heavy": {
689
+ "permission": { "playwright_*": "deny" }
690
+ }
691
+ }
692
+ }
693
+ ```
694
+
695
+ Prefer permission rules over the legacy `"tools": { "playwright_*": false }`, which is deprecated on OpenCode 1
696
+ and absent on OpenCode 2.
697
+
620
698
  ### Read-only call caps
621
699
 
622
700
  Subagents carry a cap on their own read-only tool calls (grep/read/glob/ls) per dispatch. Enforcement is **two-layered**: prompt-level stop rules + runtime banners injected into tool results. Baselines (configurable via `tierCaps` — see below):
@@ -1233,7 +1311,7 @@ These are character counts of the prompts the shipped config actually produces,
1233
1311
  ## Requirements
1234
1312
 
1235
1313
  - [OpenCode](https://opencode.ai) v1 (`>=1.0.0 <2.0.0`) or v2 **2.0.20+** (TUI status: 2.0.24+)
1236
- - Node.js 20+
1314
+ - Node.js 22+
1237
1315
  - Provider API keys configured in OpenCode
1238
1316
 
1239
1317
  ## License
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-model-router",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "description": "OpenCode plugin that routes tasks to tiered subagents (fast/medium/heavy) based on complexity",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "license": "GPL-3.0-only",
22
22
  "engines": {
23
- "node": ">=20"
23
+ "node": ">=22"
24
24
  },
25
25
  "repository": {
26
26
  "type": "git",
package/src/index.ts CHANGED
@@ -2781,8 +2781,9 @@ const ModelRouterPlugin: Plugin = async (ctx: RouterPluginInput) => {
2781
2781
  && opencodeConfig.mcp.context7.enabled !== false), opencodeConfig.agent[name]?.permission);
2782
2782
  agentDef.permission = permission;
2783
2783
  agentDef.tools = { ...legacyReadOnlyTools(permission), ...opencodeConfig.agent[name]?.tools };
2784
- } else if (name === "fast" || tier.readOnly === false) {
2785
- // Opt-out removes OUR policy, not restrictions the user supplied.
2784
+ } else {
2785
+ // Opt-out removes OUR policy, not restrictions the user supplied; they are kept
2786
+ // for every non-read-only tier, not just fast (#97).
2786
2787
  for (const key of ["permission", "tools"]) {
2787
2788
  if (opencodeConfig.agent[name]?.[key] !== undefined) agentDef[key] = opencodeConfig.agent[name][key];
2788
2789
  }
@@ -101,7 +101,16 @@
101
101
  // "a0\r\n" while exact stayed true. LF files under text=auto are common
102
102
  // on win32 (e.g. Prettier's default endOfLine: lf). Each differing path
103
103
  // adds "checkout-conversion" for it, up to MAX_CONVERSION_REASONS, then
104
- // one "" reason.
104
+ // one "" reason. A file another writer edits between the drift diff
105
+ // and the live listing is in neither set, so when the listing finds a
106
+ // live-vs-reference `w/` difference the diff is taken again, limited
107
+ // to those paths, and the paths it reports join the changed set
108
+ // before flagging (#88). They get checks (c) and (d) and are then
109
+ // judged like any file edited after dispatch (the QA-1.5-16 rule
110
+ // above: flagged only when the reference's `w/` differs from its
111
+ // `i/`; under `* text=auto` with native CRLF still flagged,
112
+ // QA-1.5-19). A failed or unaffordable re-diff (budget spent, more
113
+ // than MAX_REDIFF_PATHS paths) keeps every flag.
105
114
  // (f) No index entry is assume-unchanged or skip-worktree at capture
106
115
  // (QA-1.5-6b). Git skips such entries, so neither stash create nor the
107
116
  // drift diff sees a local edit to them (live "v2-local" became "v1" at
@@ -312,11 +321,22 @@
312
321
  // "checkout-conversion" for it. A path in the drift set but not in
313
322
  // ref.tracked (edited after capture, QA-1.5-16) has unknown dispatch
314
323
  // bytes, so it adds "checkout-conversion" when the reference's own `w/`
315
- // class differs from its `i/` class (the checkout converted it). This is
316
- // the last step, so these calls get the
317
- // remaining budget with the caller's signal only: a budget that runs out
318
- // here, or a failing call, adds "" instead of failing materialize; a
319
- // caller abort returns ok:false "aborted".
324
+ // class differs from its `i/` class (the checkout converted it). When
325
+ // the lists show a path with a live-vs-reference `w/` difference that is
326
+ // in neither set (#88: edited by another writer after the step-7 diff),
327
+ // the step-7 diff (private index, `--literal-pathspecs`, limited to
328
+ // those paths, at most MAX_REDIFF_PATHS) is taken again. The paths it
329
+ // reports join the drift set, get the (c)/(d) checks of step 7, and are
330
+ // then judged by the QA-1.5-16 rule above (a re-diffed path whose
331
+ // checkout converted it, w/ != i/, stays flagged, QA-1.5-19). A failed
332
+ // re-diff (logged), a spent budget or too many paths keeps every flag.
333
+ // This is the last step, so the two listings get the remaining budget
334
+ // with the caller's signal only: a budget that runs out here, or a
335
+ // failing call, adds "" instead of failing materialize; a caller abort
336
+ // returns ok:false "aborted". The re-diff is the exception: like step 7
337
+ // it runs under the budget's signal (its private-index copy), so a
338
+ // spent budget there skips it and keeps the flags, while a caller abort
339
+ // returns "aborted" and an UnsafeReferencePathError "unsafe-path".
320
340
  // 8. Return { ok: true, reference: { dir, exact, inexactReasons,
321
341
  // unreproduced, links, toRefPath, dispose } }. toRefPath(p) maps an
322
342
  // absolute live path under root, or under realpath(root), to the same
@@ -386,7 +406,7 @@
386
406
  // so a junction created after the sweep costs nothing (QA-1.5-3 repro:
387
407
  // `git worktree remove` in this slot deleted the late junction's target
388
408
  // contents; fs.rm left them intact). The sweep stays, because fs.rm's
389
- // non-following is proven only on Node v24.21.0 and engines is >=20. If
409
+ // non-following is proven only on Node v24.21.0 and engines is >=22. If
390
410
  // dir still exists afterwards (EBUSY from a process whose cwd is inside),
391
411
  // warn and leave it for GC; git is not run.
392
412
  // 4. Only once dir is gone, and while the admin entry is still registered:
@@ -661,6 +681,12 @@
661
681
  // reference inexact. Avoiding it needs each path's `w/` class at capture,
662
682
  // i.e. a full `ls-files --eol` inside the capture budget; not done, since
663
683
  // the error only yields "unverifiable", never a wrong excuse.
684
+ // - The QA-1.5-16 rule cannot see a legacy-checkout conversion (QA-1.5-18
685
+ // class: old core.autocrlf, `crlf` attribute) in a file edited after
686
+ // dispatch, because the reference's `i/` equals its `w/` there. That was
687
+ // already true for edits before the step-7 diff; the step-7b re-diff
688
+ // (#88) extends it to edits in the window between the diff and the live
689
+ // listing.
664
690
  // - Output cap (QA-1.5-24, owner 2.1): the seam caps each stream (p12
665
691
  // runArgv default 10 M chars) and a cut listing is a failed call. Capture's
666
692
  // `ls-files --stage` hits the cap first, at ~95-150k tracked paths (path
@@ -889,6 +915,8 @@ export const MAX_UNTRACKED_BYTES = 64 * 1024 * 1024;
889
915
  export const MAX_SWEEP_ENTRIES = 500_000;
890
916
  /** Per-path "checkout-conversion" reasons from the eol comparison (section 2e); beyond it, one "" reason. */
891
917
  export const MAX_CONVERSION_REASONS = 100;
918
+ /** Most paths the step-7b re-diff (#88) is limited to; more than this keeps every conversion flag. */
919
+ const MAX_REDIFF_PATHS = 64;
892
920
  /** Marker value for an untracked symbolic link (not a sha256, so it never matches a file hash). */
893
921
  export const UNTRACKED_SYMLINK = "symlink";
894
922
  /** Basenames whose drift between commit and the live tree makes a linked node_modules stale (section 2c). */
@@ -1802,10 +1830,17 @@ export async function materialize(
1802
1830
  const scratchEnv: PrivateIndexEnv = {
1803
1831
  argv: deps.argv, fs, root, tmpdir: tmp, platform, pid: deps.pid ?? process.pid, logger: deps.logger,
1804
1832
  };
1805
- const diff = await withPrivateIndex(scratchEnv, budget, (copy) =>
1806
- runGit(deps.argv, ["-c", "core.splitIndex=false", "diff", "--name-only", "-z", "--no-renames", "--no-ext-diff", ref.commit, "--"], {
1807
- cwd: root, timeoutMs: budget.remaining(), signal: budget.signal, env: { GIT_INDEX_FILE: copy },
1808
- }));
1833
+ // `only`: the step-7b re-diff (#88) is limited to the paths it must classify, as literal
1834
+ // pathspecs whatever GIT_LITERAL_PATHSPECS says.
1835
+ const driftDiff = (only: readonly string[] = []) =>
1836
+ withPrivateIndex(scratchEnv, budget, (copy) =>
1837
+ runGit(deps.argv, [
1838
+ ...(only.length > 0 ? ["--literal-pathspecs"] : []),
1839
+ "-c", "core.splitIndex=false", "diff", "--name-only", "-z", "--no-renames", "--no-ext-diff", ref.commit, "--", ...only,
1840
+ ], {
1841
+ cwd: root, timeoutMs: budget.remaining(), signal: budget.signal, env: { GIT_INDEX_FILE: copy },
1842
+ }));
1843
+ const diff = await driftDiff();
1809
1844
  const nowUntracked = await git(["ls-files", "--others", "--exclude-standard", "-z"]);
1810
1845
  if (budget.spent()) return await abandon("aborted", "aborted during drift checks");
1811
1846
  if (!diff || diff.code !== 0 || !nowUntracked || nowUntracked.code !== 0) {
@@ -1813,10 +1848,6 @@ export async function materialize(
1813
1848
  }
1814
1849
  for (const rel of splitZ(diff.stdout)) changed.add(rel);
1815
1850
  for (const rel of splitZ(nowUntracked.stdout)) if (!ref.untracked.has(rel)) changed.add(rel);
1816
- const changedSorted = [...changed].sort(byCodeUnit);
1817
- for (const rel of changedSorted) {
1818
- if (DEPENDENCY_FILES.has(rel.split("/").at(-1) ?? "")) reasons.push({ cause: "dependency-drift", path: rel });
1819
- }
1820
1851
  const realRoot = p.resolve(await fs.realpath(root));
1821
1852
  const workspaceDirs = new Set<string>();
1822
1853
  for (const target of linkTargets) {
@@ -1837,12 +1868,22 @@ export async function materialize(
1837
1868
  }
1838
1869
  }
1839
1870
  const fold = (s: string) => (platform === "win32" ? s.toLowerCase() : s);
1840
- for (const rel of [...workspaceDirs].sort(byCodeUnit)) {
1841
- const prefix = fold(rel) + "/";
1842
- if (changedSorted.some((c) => fold(c) === fold(rel) || fold(c).startsWith(prefix))) {
1843
- reasons.push({ cause: "workspace-link-drift", path: rel });
1871
+ // Section 2 (c) and (d) over a set of drifted paths; run on the step-7 set and, in step 7b, on
1872
+ // the paths its re-diff adds (#88), so a late edit is judged like any other drift.
1873
+ const driftReasons = (paths: readonly string[]) => {
1874
+ const sorted = [...paths].sort(byCodeUnit);
1875
+ for (const rel of sorted) {
1876
+ if (DEPENDENCY_FILES.has(rel.split("/").at(-1) ?? "")) reasons.push({ cause: "dependency-drift", path: rel });
1844
1877
  }
1845
- }
1878
+ for (const rel of [...workspaceDirs].sort(byCodeUnit)) {
1879
+ const prefix = fold(rel) + "/";
1880
+ if (reasons.some((r) => r.cause === "workspace-link-drift" && r.path === rel)) continue;
1881
+ if (sorted.some((c) => fold(c) === fold(rel) || fold(c).startsWith(prefix))) {
1882
+ reasons.push({ cause: "workspace-link-drift", path: rel });
1883
+ }
1884
+ }
1885
+ };
1886
+ driftReasons([...changed]);
1846
1887
 
1847
1888
  // 7b. Clean-file checkout conversion (section 2e, QA-1.5-13): the working-tree eol class
1848
1889
  // of every tracked path that is neither hashed above (ref.tracked) nor changed since
@@ -1872,14 +1913,41 @@ export async function materialize(
1872
1913
  if (!liveEol || !refEol) {
1873
1914
  conversion(""); // not compared: budget spent or git failed
1874
1915
  } else {
1916
+ // #88: a writer that edits a file between the step-7 diff and the live listing leaves it
1917
+ // in neither set; its live `w/` then differs from the reference's with no checkout
1918
+ // conversion behind it. Take the diff again, limited to those paths (at most
1919
+ // MAX_REDIFF_PATHS; beyond that the flags stay), before flagging them. A failed or
1920
+ // unaffordable re-diff changes nothing, so every flag stays (fail safe). Paths it adds go
1921
+ // through the (c)/(d) drift checks and then the QA-1.5-16 rule below.
1922
+ const unexplained = (rel: string, w: string) => {
1923
+ if (ref.tracked.has(rel) || changed.has(rel)) return false;
1924
+ const live = liveEol.get(rel);
1925
+ return live !== undefined && live.w !== w;
1926
+ };
1927
+ const suspects = [...refEol].filter(([rel, { w }]) => unexplained(rel, w)).map(([rel]) => rel).sort(byCodeUnit);
1928
+ if (suspects.length > 0 && suspects.length <= MAX_REDIFF_PATHS && !budget.spent()) {
1929
+ let again: ExecResult | undefined;
1930
+ try {
1931
+ again = await driftDiff(suspects);
1932
+ } catch (error) {
1933
+ if (signal.aborted || error instanceof UnsafeReferencePathError) throw error;
1934
+ deps.logger?.warn("reference eol re-diff failed: flags kept", { error: describeError(error) });
1935
+ }
1936
+ if (signal.aborted) return await abandon("aborted", "aborted during the eol comparison");
1937
+ if (again && again.code === 0) {
1938
+ const added = splitZ(again.stdout).filter((rel) => !changed.has(rel));
1939
+ for (const rel of added) changed.add(rel);
1940
+ driftReasons(added);
1941
+ } else if (again) {
1942
+ deps.logger?.warn("reference eol re-diff failed: flags kept", { code: again.code, stderr: again.stderr.trim() });
1943
+ }
1944
+ }
1875
1945
  // QA-1.5-16: a path edited since capture (in changed, not in ref.tracked) has unknown
1876
1946
  // dispatch bytes; it is flagged when the reference's checkout converted it (w/ != i/).
1877
1947
  const differing = [...refEol]
1878
1948
  .filter(([rel, { i, w }]) => {
1879
- if (ref.tracked.has(rel)) return false;
1880
- if (changed.has(rel)) return i !== "" && w !== "" && i !== w;
1881
- const live = liveEol.get(rel);
1882
- return live !== undefined && live.w !== w;
1949
+ if (changed.has(rel) && !ref.tracked.has(rel)) return i !== "" && w !== "" && i !== w;
1950
+ return unexplained(rel, w);
1883
1951
  })
1884
1952
  .map(([rel]) => rel)
1885
1953
  .sort(byCodeUnit);