Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

This project follows [Semantic Versioning](https://semver.org/). Release notes describe user-visible behavior; implementation details remain in the technical specification and commit history.

## [1.0.3] - 2026-09-10

### Added

- **`/modelRank` interleaved ranking — manual entries merge into the base-score ordering** — the manual ranking no longer floats as a block on top of everything. The dialog (and `rank list`) now show one merged ordering sorted by effective capability, and a move (ctrl/alt+up/down or the per-model actions) acts on that merged list: the moved model gets an anchored manual score strictly between its new neighbors (tier from the neighbor below, raw at the midpoint of the same-tier gap or a ±0.001 decimal step at tier boundaries and tie groups), so nudging a model one spot no longer requires manually ranking every model above it — unranked models materialize an anchored entry on their first move. Anchored scores persist in `capability-rank.json` as an optional `scores` side-map (`{ key: { tier, raw } }`); entries without a stored score keep the legacy ladder semantics (linear percentile by array position), so hand-written and pre-existing files stay valid, and CLI `rank set/add/remove` preserve surviving anchored scores. Dispatch surfaces are unchanged in shape — a manual hit still overrides the base capability score, now via the anchored (tier, raw) pair.
- **Full-superset candidate lists for `/modelRank` & `/poolConfig`** — both config surfaces now list every conversable model of credentialed providers (the full superset) instead of the pruned injection face, so task pools can be configured with models that are not favorites/visible yet, and models already configured in a pool stay listed even when they drop out of the pruned face (force-keep). Actual chain candidacy is still decided at runtime by pool selection ∩ activation.

### Fixed

- **Runaway list scrolling in the `/modelRank` dialog** — moving the mouse up/down across the list could set off a wild, never-ending scroll: the plugin mirrored every hover-driven selection change back into the dialog's `current` prop, and the host dialog re-centered the scroll on `current` each time — the centering scroll slid fresh rows under the stationary cursor, each firing another hover → selection change → re-scroll: an unbounded self-sustaining loop. `current` is now driven only by explicit ctrl/alt+up/down hotkey moves, never mirrored from hover.

## [1.0.2] - 2026-09-07

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Two manual commands let your configuration beat system defaults. All state is pe

### /modelRank — model capability ranking (manual dialog; conversational: /modelRank-chat)

- **TUI (/modelRank)**: a dialog listing models by effective capability; select a model to pin it to top, move it up/down, or remove it from the ranking.
- **TUI (/modelRank)**: a dialog listing models by effective capability — manual entries interleave with base-score models in one merged ordering; moving a model up/down anchors it a manual score between its new neighbors (one-spot nudges, no need to rank everything above), plus pin-to-top / remove; effective immediately.
- **Non-TUI / in-session (/modelRank-chat)**: a conversational flow — it injects the current ranking and a reference ordering; reply "pin glm-5.3 to top" or "clear the ranking" and the agent translates that into `rank` CLI calls to persist.
- **Semantics**: manual ranking **takes priority over the base capability score** (realtime index → bundled snapshot → curated table all yield) — matched models (including their prefix variants) get a rank-position score and S/A/B/C tier: rankings with ≤4 entries map positions to S/A/B/C in order; ≥5 entries use quantile buckets (top 20% S / next 20% A / next 20% B / rest C, same semantics as the OpenRouter rank source); within a tier, the linear rank position breaks ties. Unranked models are unaffected. The ranking feeds every decision surface: lane chains, effort affinity, capability-level gates, and deny hints.
- **Config file**: `~/.config/opencode/opencode-switchman/capability-rank.json` (`models` array order = strongest first).
Expand Down
2 changes: 1 addition & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ TUI 插件没有目录自动发现机制,需要在 **`tui.jsonc`/`tui.json`**

### /modelRank —— 模型能力排名(手动弹窗;会话式用 /modelRank-chat)

- **TUI(/modelRank)**:弹出按有效能力排序的模型列表,选中模型后可「置顶 / 上移 / 下移 / 移出排名」,即时生效。
- **TUI(/modelRank)**:弹窗按有效能力给出单一合并排序——手动条目与基础分模型交错排列;上移/下移会给模型锚定一个介于新上下邻居之间的手动分(一次挪一格,无需把上面的模型全排一遍),另有置顶/移出排名,即时生效。
- **非 TUI / 会话内(/modelRank-chat)**:会话式流程——注入当前排名与参考排序,回复「把 glm-5.3 排到最前」「清空排名」由 agent 换算 `rank` 命令落盘。
- **语义**:手动排名**优先于基础能力分**(实时第三方指数 → 内置快照 → 策展表全部让位)——命中模型(含其前缀变体)按排名序位取能力分与 S/A/B/C 档:排名 ≤4 项时依次 S/A/B/C;≥5 项按分位口径(top20% S / 次20% A / 次20% B / 其余 C,与 OpenRouter 序位派生同口径);同档内按序位线性分细排。未排名模型不受影响。排名参与所有决策面:六档链排序、档位亲和、能力等级闸与 deny 改派建议。
- **配置文件**:`~/.config/opencode/opencode-switchman/capability-rank.json`(`models` 数组顺序=能力降序,#1 最强)。
Expand Down
2 changes: 1 addition & 1 deletion docs/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Not every model a provider offers needs to join the matrix. You decide the **act

By default, model capability comes from an automatic cascade (live third-party index → bundled snapshot → curated table). If you disagree — your workload, your ranking.

**TUI**: run `/modelRank` — a dialog lists every model by effective capability; select a model to pin it to top, move it up/down, or remove it from the ranking.
**TUI**: run `/modelRank` — a dialog listing every model by effective capability, manual entries interleaved with base-score models; move a model up/down to anchor it a manual score between its new neighbors (one-spot nudges), or pin it to top / remove it from the ranking.

![/modelRank — capability ranking with manual-rank vs base-score provenance](assets/tui-model-rank.png)

Expand Down
2 changes: 1 addition & 1 deletion docs/quick-start.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

默认模型能力来自自动级联(实时第三方指数 → 内置快照 → 策展表)。不同意?你的工作负载你说了算。

**TUI**:运行 `/modelRank`——弹窗按有效能力列出所有模型;选中模型可「置顶 / 上移 / 下移 / 移出排名」。
**TUI**:运行 `/modelRank`——弹窗按有效能力列出所有模型,手动条目与基础分模型交错;上移/下移会给模型锚定一个介于新上下邻居之间的手动分(一次挪一格),另有置顶/移出排名。

![/modelRank——模型能力排名:手动命中优先于基础能力分](assets/tui-model-rank.png)

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opencode-switchman",
"version": "1.0.2",
"version": "1.0.3",
"description": "OpenCode orchestration plugin: six-lane shell matrix dispatch (hard ROUTE_META validation / breaker self-healing / probes / three-pool quota awareness / cost-aware tiebreaker)",
"license": "MIT",
"repository": {
Expand Down
22 changes: 19 additions & 3 deletions src/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,19 +450,35 @@ function manualRankMatch(normKey: string): { rank: NonNullable<ReturnType<typeof
return best >= 0 ? { rank, index: best } : null
}

/** Manual rank hit -> DynamicBaseResult (source="manual"; miss=null, falls through the original fallback chain) */
/** Manual rank hit -> DynamicBaseResult (source="manual"; miss=null, falls through the original fallback chain).
* [2026-09-10]-[anchored-score entries (capability-rank.json `scores` side-map) take precedence: tier + rawScore come
* from the stored (tier, raw) pair so manual entries interleave with base-score models; entries without an anchored
* score keep the legacy ladder (linear percentile by array position + its tier table)] */
export function manualRankResult(modelId: string): DynamicBaseResult | null {
const norm = normalizeModelKey(modelId)
if (!norm) return null
const hit = manualRankMatch(norm)
if (!hit) return null
const entryKey = hit.rank.models[hit.index]!
const version = `manual-${hit.rank.updated_at || "unset"}`
const anchored = hit.rank.scores?.[entryKey]
if (anchored) {
return {
score: TIER_SCORE[anchored.tier],
rawScore: anchored.raw,
tier: anchored.tier,
source: "manual",
version,
matchedAs: entryKey,
}
}
const tier = manualTierAt(hit.index, hit.rank.models.length)
return {
score: TIER_SCORE[tier],
rawScore: manualLinearScore(hit.index, hit.rank.models.length),
tier,
source: "manual",
version: `manual-${hit.rank.updated_at || "unset"}`,
matchedAs: hit.rank.models[hit.index]!,
version,
matchedAs: entryKey,
}
}
86 changes: 58 additions & 28 deletions src/config-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,47 @@ import { loadSupersetShells, loadManifest, paths } from "./state"
import {
loadCapabilityRank, loadPoolConfig, poolAllowlist,
writeCapabilityRank, clearCapabilityRank, writePoolConfig, resetPoolConfig,
type RankScoreOverride,
} from "./user-overrides"
import { LANE_ORDER, type Lane } from "./types"
import { TIER_RANK } from "./model-ranks"

interface ModelRow { key: string; modelId: string; tier: string; source: string; raw: number | null }
interface ModelRow { key: string; modelId: string; tier: string; source: string; raw: number | null; manualIdx?: number }

// [2026-09-10]-[manual-first tie-break: on exact (tier, raw) ties manual entries sort above base entries, ordered by
// their models-array slot — lets anchored moves win ties without touching base-vs-base ordering]
function capabilityCompare(a: ModelRow, b: ModelRow): number {
return TIER_RANK[a.tier as "S"] - TIER_RANK[b.tier as "S"] ||
(b.raw ?? -Infinity) - (a.raw ?? -Infinity) ||
(a.manualIdx ?? Infinity) - (b.manualIdx ?? Infinity) ||
a.key.localeCompare(b.key)
}

function toRow(modelId: string): ModelRow {
const base = baseScoreDynamic(modelId)
return {
key: normalizeModelKey(modelId),
const key = normalizeModelKey(modelId)
const row: ModelRow = {
key,
modelId,
tier: base.tier,
source: base.source,
raw: base.rawScore ?? null,
}
// manual array slot (undefined for non-manual rows): the merged view uses it as the exact-tie tie-break
if (base.source === "manual" && base.matchedAs) {
const idx = loadCapabilityRank()?.models.indexOf(base.matchedAs) ?? -1
if (idx >= 0) row.manualIdx = idx
}
return row
}

/** All available models (superset manifest first, falling back to the bundled manifest; deduped by modelId across provider pools); sorted by effective capability descending */
/** All available models (full-superset candidates first — every conversable model of credentialed providers — falling back to
* the injection-face shells, then the bundled manifest; deduped by modelId across provider pools); sorted by effective capability descending
* [2026-09-10]-[candidate surface widened from the pruned injection face to the full superset: pools can now be configured
* with models that are not (yet) favorites/visible — actual chain candidacy is still decided at runtime by pool selection ∩ activation] */
export function allModelRows(): ModelRow[] {
const shells = loadSupersetShells()?.shells ?? loadManifest().shells
const sup = loadSupersetShells()
const shells = (sup?.candidates && sup.candidates.length > 0 ? sup.candidates : sup?.shells) ?? loadManifest().shells
const seen = new Set<string>()
const rows: ModelRow[] = []
for (const s of shells) {
Expand Down Expand Up @@ -133,21 +148,20 @@ function cmdPool(args: string[]): number {
throw new Error(`unknown subcommand pool ${sub} (list/add/remove/set/clear)`)
}

/** Merged view of the manual ranking + reference ordering of available models (indices are globally contiguous, referenced by rank set/add/remove) */
/** [2026-09-10]-[merged interleaved view: manual entries no longer float as a block on top — every model (manual + base)
* is sorted by effective capability (tier, raw; manual wins exact ties), so /modelRank moves and rank CLI indices act
* on one global ordering. Manual keys missing from the model universe keep a row (dead-key tolerance)] */
export function rankViewRows(): ModelRow[] {
const rank = loadCapabilityRank()
const rankedKeys = new Set(rank?.models ?? [])
const ranked: ModelRow[] = (rank?.models ?? []).map((k) => ({ ...toRow(k), source: "manual" }))
const flat = allModelRows()
const seen = new Set<string>(rankedKeys)
const rest: ModelRow[] = []
for (const r of flat) {
if (seen.has(r.key)) continue
seen.add(r.key)
rest.push(r)
const rows = allModelRows()
const seen = new Set(rows.map((r) => r.key))
for (const k of rank?.models ?? []) {
if (seen.has(k)) continue
seen.add(k)
rows.push(toRow(k))
}
rest.sort(capabilityCompare)
return [...ranked, ...rest]
rows.sort(capabilityCompare)
return rows
}

function cmdRank(args: string[]): number {
Expand All @@ -156,26 +170,42 @@ function cmdRank(args: string[]): number {
if (!sub || sub === "list") {
const view = rankViewRows()
const manualCount = rank?.models.length ?? 0
console.log(`Model capability ranking (config file ${paths().capabilityRank}; the manual ranking takes priority over the base capability score; higher up = stronger)`)
console.log(`== Manual ranking (${manualCount}${manualCount > 0 ? "" : "; unconfigured = all use the base capability score"}) ==`)
console.log(`Model capability ranking (config file ${paths().capabilityRank}; one merged ordering — manual entries interleave with base-score models by effective score; higher up = stronger)`)
console.log(`== Merged ordering (${manualCount} manual${manualCount > 0 ? "" : "; none = all use the base capability score"}; CLI set/add order entries by the legacy ladder, TUI moves anchor scores between neighbors) ==`)
view.forEach((row, i) => {
if (i < manualCount) console.log(` #${String(i + 1).padStart(2, "0")} ${row.modelId} (${row.tier}-tier·manual)`)
})
console.log("== Reference ordering of available models (base capability score) ==")
view.forEach((row, i) => {
if (i >= manualCount) console.log(` #${String(i + 1).padStart(2, "0")} ${row.modelId} (${row.tier}-tier)`)
const manualTag = row.source === "manual"
? `·manual${row.raw !== null ? ` ${row.raw}` : ""}`
: ""
console.log(` #${String(i + 1).padStart(2, "0")} ${row.modelId} (${row.tier}-tier${manualTag})`)
})
return 0
}
if (sub === "add" || sub === "remove" || sub === "set") {
if (rest.length === 0) throw new Error(`rank ${sub} requires an index or model name`)
const refs = resolveRefs(rest, rankViewRows())
const current = [...(rank?.models ?? [])]
// [2026-09-10]-[CLI writes must preserve anchored scores: add keeps every existing entry's score, remove/set drop
// only the keys leaving the list (ladder fallback covers the rest)]
const keepScores = (keep: string[]): Record<string, RankScoreOverride> | undefined => {
const next: Record<string, RankScoreOverride> = {}
for (const [k, v] of Object.entries(rank?.scores ?? {})) if (keep.includes(k)) next[k] = v
return Object.keys(next).length > 0 ? next : undefined
}
let next: string[]
if (sub === "add") next = [...current, ...refs.filter((k) => !current.includes(k))]
else if (sub === "remove") next = current.filter((k) => !refs.includes(k))
else next = refs
const file = writeCapabilityRank(next)
let nextScores: Record<string, RankScoreOverride> | undefined
if (sub === "add") {
next = [...current, ...refs.filter((k) => !current.includes(k))]
nextScores = keepScores([...current, ...refs])
}
else if (sub === "remove") {
next = current.filter((k) => !refs.includes(k))
nextScores = keepScores(next)
}
else {
next = refs
nextScores = keepScores(refs)
}
const file = writeCapabilityRank(next, nextScores)
console.log(`Updated the manual capability ranking (${file.models.length} models, effective immediately, sidebar refreshes in sync)`)
return cmdRank(["list"])
}
Expand Down
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,15 @@ export const SwitchmanPlugin: Plugin = async (input, rawOptions) => {
roAliases: true, degradedFamilyByProvider: true, markDegraded: true,
})
const fullShells = defs.length
const candidateEntries = defs.map(toManifestEntry)
// [2026-09-10]-[pool-config models join the force-keep set: task-pool selections must be injectable even when the
// model missed favorites/visible set (runtime chains still narrow to pool selection ∩ activation, gate 5.5 unchanged)]-
const poolConfiguredIds = new Set<string>()
for (const ids of Object.values(loadPoolConfig())) for (const id of ids) poolConfiguredIds.add(id)
defs = selectInjectableDefs(defs, {
customLanes: (options.lanes as Record<string, readonly string[]> | null) ?? null,
keepModels: options.injection!.mode === "all" ? new Set(supersetModels) : new Set(validConfiguredModels),
keepModelIds: poolConfiguredIds,
preferredModels: new Set(validConfiguredModels.map((m) => m.slice(m.indexOf("/") + 1))),
capabilityOf: (modelId) => baseScoreDynamic(modelId),
billingBoostOf, unknownOf: unknownOfModel,
Expand All @@ -622,8 +628,12 @@ export const SwitchmanPlugin: Plugin = async (input, rawOptions) => {
try {
writeJsonAtomic(paths().shellSuperset, {
generated_at: new Date().toISOString(),
counts: { superset_models: supersetModels.length, shells: defs.length, full_shells: fullShells, degraded: degradedModelCount },
counts: { superset_models: supersetModels.length, shells: defs.length, full_shells: fullShells, candidate_shells: candidateEntries.length, degraded: degradedModelCount },
mode: runMode,
// [2026-09-10]-[full-superset candidate surface for the /modelRank //poolConfig config lists: every conversable model
// of credentialed providers (readers dedupe by modelId, same rule as before) so pools can be configured beyond the
// pruned injection face; `shells` stays the injection face (dynamicManifest/banner/deny-candidate semantics unchanged)]-
candidates: candidateEntries,
shells: defs.map(toManifestEntry),
})
} catch { /* fail-open */ }
Expand Down
2 changes: 1 addition & 1 deletion src/shells.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_note": "opencode-switchman full matrix: authoritative enabled surface (models enabled in model management, scripts/visible-models.txt) × all declared thinking efforts (models.dev reasoning_options, toggle→off). Generated by scripts/gen-shells.ts — do not edit by hand; after model on/off changes, sync the pin file and re-run bun run gen:shells. The six lane chains are computed from capability score × lane affinity × structural gate × billing factor (api billing 0.85, unknown group 0.75, sunk by coefficient; no vendor-reserved seats).",
"generated_at": "2026-09-07T08:09:07.964Z",
"generated_at": "2026-09-10T03:30:20.019Z",
"counts": {
"shells": 104,
"visible_models": 13
Expand Down
Loading