@aiwayds/dsh-model-sync 0.12.1 → 0.13.1

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 (88) hide show
  1. package/README.md +18 -17
  2. package/README.zh-CN.md +18 -17
  3. package/lib/index.d.ts +54 -384
  4. package/lib/index.js +306 -1107
  5. package/lib/index.js.map +1 -1
  6. package/lib/official-adapter.d.ts +80 -0
  7. package/lib/official-adapter.js +34 -0
  8. package/lib/official-adapter.js.map +1 -0
  9. package/lib/official-migrate.d.ts +122 -0
  10. package/lib/official-migrate.js +653 -0
  11. package/lib/official-migrate.js.map +1 -0
  12. package/lib/official-scheduler.d.ts +72 -0
  13. package/lib/official-scheduler.js +195 -0
  14. package/lib/official-scheduler.js.map +1 -0
  15. package/lib/official-store.d.ts +41 -0
  16. package/lib/official-store.js +84 -0
  17. package/lib/official-store.js.map +1 -0
  18. package/lib/official-sync.d.ts +68 -0
  19. package/lib/official-sync.js +274 -0
  20. package/lib/official-sync.js.map +1 -0
  21. package/lib/opencode-go-adapter.d.ts +56 -0
  22. package/lib/opencode-go-adapter.js +455 -0
  23. package/lib/opencode-go-adapter.js.map +1 -0
  24. package/lib/opencode-go-patch-file.d.ts +11 -0
  25. package/lib/opencode-go-patch-file.js +175 -11
  26. package/lib/opencode-go-patch-file.js.map +1 -1
  27. package/lib/opencode-go-source.d.ts +1 -1
  28. package/lib/opencode-go-source.js +1 -1
  29. package/locale/en.json +1 -1
  30. package/locale/zh.json +1 -1
  31. package/package.json +3 -3
  32. package/src/index.ts +352 -1281
  33. package/src/official-adapter.ts +111 -0
  34. package/src/official-migrate.ts +863 -0
  35. package/src/official-scheduler.ts +235 -0
  36. package/src/official-store.ts +122 -0
  37. package/src/official-sync.ts +371 -0
  38. package/src/opencode-go-adapter.ts +494 -0
  39. package/src/opencode-go-patch-file.ts +175 -9
  40. package/src/opencode-go-source.ts +1 -1
  41. package/lib/opencode-go-diagnose.d.ts +0 -96
  42. package/lib/opencode-go-diagnose.js +0 -177
  43. package/lib/opencode-go-diagnose.js.map +0 -1
  44. package/lib/opencode-go-grouping.d.ts +0 -7
  45. package/lib/opencode-go-grouping.js +0 -21
  46. package/lib/opencode-go-grouping.js.map +0 -1
  47. package/lib/opencode-go-host-catalog.d.ts +0 -42
  48. package/lib/opencode-go-host-catalog.js +0 -98
  49. package/lib/opencode-go-host-catalog.js.map +0 -1
  50. package/lib/opencode-go-journal.d.ts +0 -114
  51. package/lib/opencode-go-journal.js +0 -406
  52. package/lib/opencode-go-journal.js.map +0 -1
  53. package/lib/opencode-go-migrate.d.ts +0 -378
  54. package/lib/opencode-go-migrate.js +0 -1529
  55. package/lib/opencode-go-migrate.js.map +0 -1
  56. package/lib/opencode-go-migration.d.ts +0 -270
  57. package/lib/opencode-go-migration.js +0 -473
  58. package/lib/opencode-go-migration.js.map +0 -1
  59. package/lib/opencode-go-one-shot.d.ts +0 -282
  60. package/lib/opencode-go-one-shot.js +0 -1131
  61. package/lib/opencode-go-one-shot.js.map +0 -1
  62. package/lib/opencode-go-planner.d.ts +0 -168
  63. package/lib/opencode-go-planner.js +0 -407
  64. package/lib/opencode-go-planner.js.map +0 -1
  65. package/lib/opencode-go-scheduler.d.ts +0 -128
  66. package/lib/opencode-go-scheduler.js +0 -241
  67. package/lib/opencode-go-scheduler.js.map +0 -1
  68. package/lib/opencode-go-store.d.ts +0 -18
  69. package/lib/opencode-go-store.js +0 -68
  70. package/lib/opencode-go-store.js.map +0 -1
  71. package/lib/opencode-go-sync.d.ts +0 -107
  72. package/lib/opencode-go-sync.js +0 -388
  73. package/lib/opencode-go-sync.js.map +0 -1
  74. package/lib/opencode-go-writer.d.ts +0 -148
  75. package/lib/opencode-go-writer.js +0 -1061
  76. package/lib/opencode-go-writer.js.map +0 -1
  77. package/src/opencode-go-diagnose.ts +0 -276
  78. package/src/opencode-go-grouping.ts +0 -26
  79. package/src/opencode-go-host-catalog.ts +0 -125
  80. package/src/opencode-go-journal.ts +0 -460
  81. package/src/opencode-go-migrate.ts +0 -1951
  82. package/src/opencode-go-migration.ts +0 -666
  83. package/src/opencode-go-one-shot.ts +0 -1399
  84. package/src/opencode-go-planner.ts +0 -582
  85. package/src/opencode-go-scheduler.ts +0 -315
  86. package/src/opencode-go-store.ts +0 -73
  87. package/src/opencode-go-sync.ts +0 -541
  88. package/src/opencode-go-writer.ts +0 -1301
package/README.md CHANGED
@@ -30,9 +30,12 @@ Model lists drift: providers ship new models, retire old ones, and adjust capabi
30
30
  - **Scheduled refresh.** `intervalMinutes` auto rounds (default 240 / 4h) plus a `startupDelaySeconds` initial delay (default 5); each round logs the same report a manual refresh produces. `0` disarms the interval (startup-only). The interval re-arms live when the config changes (`src/index.ts`).
31
31
  - **Change reporting / diff.** Every round reports added/removed model ids (`diffModelIds`), and in `settings` mode added/removed/changed entries against the current raw settings (`diffEntries`, `diff.ts`). Dropped and degraded entries are reported with their reasons.
32
32
  - **`modelSync` service.** Exposes a `modelSync` service (`syncNow()`) that a UI can call to force one refresh round and read the report.
33
- - **`/model-sync` command.** The plugin registers a `/model-sync` slash command itself through the shared dsh command registry (`@deepseek-ai/dsh-commands`), so every interactive UI lists it automatically — no UI-side wiring. Running it forces one sync round on the spot and prints the same report the scheduled rounds log; the sync scope is decided by `managedRoutes` (arguments are ignored). The registry is an optional peer: hosts without a command registry still get the scheduled rounds and the `modelSync` service. Its subcommands are `go`/`status` (one full opencode-go round), `adopt go` (the same round with adoption), `migrate plan|apply|rollback|status` (the only writer gated by the explicit token triple; `plan` is read-only, `apply` requires a plan hash, a 6-digit confirm code and `--ack-managed`), and `migrate-go` (one-shot full migration: plan + file backups + one in-command confirmation + apply, per profile — see below). `eject` is retired — `migrate rollback` is the only rollback entry.
34
- - **opencode-go sync (opt-in).** With `opencode.go.enabled: true`, three routes — `opencode-go` (chat-completions), `opencode-go-msg` (messages), `opencode-go-resp` (responses) — sync from the official public `/v1/models` listing instead of pi.dev. It is off by default, so existing handwritten opencode-go lists are frozen until you opt in. These go routes are separate from the default pi.dev `managedRoutes` above.
35
- - **`/opencode-status` read-only diagnostic.** Compares the official opencode-go `/v1/models` listing with the current profile's routes (no writes, no settings mutation).
33
+ - **`/model-sync` command.** The plugin registers a `/model-sync` slash command itself through the shared dsh command registry (`@deepseek-ai/dsh-commands`), so every interactive UI lists it automatically — no UI-side wiring. Bare `/model-sync` forces one `pi.dev` sync round for Builtin Providers (automatically skipping providers already migrated to Official Sync). Subcommands:
34
+ - `/model-sync <provider>` (e.g. `/model-sync go` or `/model-sync opencode-go`): manually sync an Official Sync provider from its vendor models API; unsupported providers explicitly report unsupported.
35
+ - `/model-sync migrate <provider> [--all-profiles] [--confirm]` (alias: `migrate-go`): detach an existing Builtin Provider into per-protocol Managed Custom Providers behind a single confirmation + backups (`cordis.patch.yml.bak.*` & `models-store.json.bak.*`), rewrite `agent-default-model`, and enable hourly auto-sync.
36
+ - `/model-sync rollback <provider> [--confirm]`: revert to the original Builtin Provider and `agent-default-model`, remove Managed Custom Providers, and disarm Official Sync.
37
+ - `/model-sync status [provider]` (and `/opencode-status`): read-only diagnostic comparing official API models with current profile providers.
38
+ - **Official Sync (`officialSync.opencode-go`, first supported adapter).** Once migrated via `/model-sync migrate go`, `opencode-go` is deleted and replaced by independent per-protocol Managed Custom Providers (`opencode-go-chat`, `opencode-go-msg`, `opencode-go-resp`, `opencode-go-google`) synced from `https://opencode.ai/inference/go/v1/models` every `60` minutes by default (configurable; `0` = manual only). Official models are never filtered by the host's bundled `pi-ai` catalog; `sessionHeader: 'auto'` probes the running host's `pi-ai` and adds a static `x-opencode-session` header only when needed (e.g. older Desktop builds).
36
39
  - **Translation rules.** pi.dev entries are translated into settings-writable model profiles (`translate.ts`): base-matching vs base-less classification, `reasoningEfforts` derivation (S2 gate), `compat` gating to `openai-completions` (S5 gate), `maxTokens` handling, and drop logic for mixed-protocol routes. Capacity values get a sanity gate: a `contextWindow` that is not a positive integer, or a `maxTokens` that is not a positive integer strictly below the context window (listings sometimes echo the context window into `maxTokens`), is skipped with a degrade warning instead of written.
37
40
  - **Your overrides are durable.** `modelOverrides` is your own per-model channel (think levels, narrowed context windows). dsh refuses a models list beside non-empty overrides, so the sync folds your fields into the written models, clears the key in the same write, and re-applies the values from its store (`~/.dsh/models-store.json`) on every round — they keep winning over the synced values for as long as the route is managed.
38
41
  - **Safe-by-default options:**
@@ -84,7 +87,10 @@ Configure the plugin under the `dsh-model-sync` settings entry — on dsh 0.1.7+
84
87
  | `forceMaxReasoningEffort` | `false` | Force max reasoning effort on models with a non-empty `thinkingFormat` |
85
88
  | `providerNativeFetch` | `true` | Union each mapped provider's first-party `/models` listing into the pi.dev result (additions only) |
86
89
  | `keepDeprecatedBuiltin` | `false` | Opt back into emitting builtin ids the official default model list dropped (dsh 0.1.7 removed `deepseek-v4-flash` / `deepseek-v4-flash-vision-exp`; dsh 0.2.0 removed `omen-alpha` on opencode-go and `glm-4.7` / `glm-5-turbo` / `glm-5.1` / `glm-5.2` / `glm-5.2-highspeed` / `glm-5v-turbo` on zai-coding-cn; the snapshot keeps the data but no longer syncs them by default) |
87
- | `opencode.go.enabled` | `false` | Opt in to official-listing sync for the three `opencode-go*` routes; default off keeps existing handwritten opencode-go lists frozen (need sync → set `true` explicitly) |
90
+ | `officialSync.opencode-go.intervalMinutes` | `60` | Auto-sync interval in minutes after migration (`0` = manual `/model-sync go` only) |
91
+ | `officialSync.opencode-go.modelsUrl` | `https://opencode.ai/inference/go/v1/models` | Official OpenCode Go `/v1/models` endpoint |
92
+ | `officialSync.opencode-go.sessionHeader` | `'auto'` | `'auto'` (inject static `x-opencode-session` only on hosts without `pi-ai >= 1.6.0` native injection), `'static'`, or `'none'` |
93
+ | `officialSync.opencode-go.routes` | `opencode-go-{chat,msg,resp,google}` | Custom Provider route IDs per Protocol Slot |
88
94
 
89
95
  Example (settings section `dsh-model-sync`; a legacy `settings.yaml` `model-sync:` section is not auto-imported by the dsh 0.1.7 host itself — the plugin recovers it once at boot, see above):
90
96
 
@@ -115,23 +121,18 @@ providers:
115
121
 
116
122
  Note that listing data itself can be noisy: values are sanity-gated (positive integers; `maxTokens` strictly below `contextWindow`), and stripped values show up in the sync report as `DEGRADED` lines with reasons.
117
123
 
118
- ### Manual refresh: `/model-sync` and `/opencode-status`
124
+ ### Manual refresh & Official Sync: `/model-sync`, `/model-sync migrate`, `/model-sync rollback`
119
125
 
120
- Type `/model-sync` in any interactive UI to force one sync round on the spot. The plugin registers the command in the shared command registry (`@deepseek-ai/dsh-commands`), and UIs discover it automatically. It returns the same report the scheduled rounds log. The sync scope is decided by `managedRoutes`; extra arguments to a bare `/model-sync` are ignored. Hosts without a command registry degrade gracefully — the scheduled rounds and the `modelSync` service keep working.
126
+ Type `/model-sync` in any interactive UI to force one `pi.dev` sync round for Builtin Providers (automatically skipping any provider migrated to Official Sync).
121
127
 
122
- opencode-go adds subcommands: `/model-sync go` (or `status`) runs one full go round, `/model-sync adopt go` runs it with adoption, and `/model-sync migrate plan|apply|rollback|status` is the only writer gated by the explicit token triple — `plan` is read-only and `apply` requires a plan hash, a 6-digit confirm code and `--ack-managed`. `eject` is retired; use `migrate rollback` to revert. `/opencode-status` is a separate read-only diagnostic that compares the official listing with the current profile's routes; it never writes settings or credentials. Desktop/web GUI clients forward free-form arguments only to a command that declares an `input` descriptor — `/model-sync` declares one in this version, so the subcommands above work there too (the hint is discoverability only; parsing stays in the handler).
128
+ For Official Sync providers (starting with OpenCode Go; unsupported providers return an explicit unsupported notice):
123
129
 
124
- ### One-shot migration: `/model-sync migrate-go`
130
+ - `/model-sync migrate go [--all-profiles] [--confirm]` (alias: `migrate-go`) — requires an existing `providers.opencode-go` section in the profile, extracts its `apiKeyEnv`, fetches the official `/v1/models` catalog, creates backups (`cordis.patch.yml.bak.*`, `models-store.json.bak.*`), asks for a single confirmation (`userQuestions`, or `--confirm` non-interactively), writes per-protocol Managed Custom Providers (`opencode-go-chat`, `opencode-go-msg`, `opencode-go-resp`, `opencode-go-google`), removes `providers.opencode-go`, rewrites `agent-default-model` if needed, warns on any other references in `cordis.patch.yml`, and arms the 60-minute auto-sync timer.
131
+ - `/model-sync go` — manually triggers one Official Sync round from the official `/v1/models` endpoint (all official models included regardless of host `pi-ai` catalog lag; empty protocol slots automatically unset).
132
+ - `/model-sync rollback go [--confirm]` — backs up, confirms, restores the original `providers.opencode-go` and `agent-default-model`, removes the Managed Custom Providers, and stops Official Sync.
133
+ - `/model-sync status [go]` (or `/opencode-status`) — read-only status & live official listing check.
125
134
 
126
- `/model-sync migrate-go` runs the full migration pipeline in one command, for the current profile by default or `--all-profiles` (every profile whose patch still carries a legacy opencode-go stub — a models-only section without `api`/`baseURL`):
127
-
128
- ```bash
129
- /model-sync migrate-go [--all-profiles] [--adopt] [--prune-user-extra] [--rewrite-refs=default-model|config]
130
- ```
131
-
132
- Fixed pipeline: plan (the same read-only builder `migrate plan` prints) → file backups BEFORE any write (`cordis.patch.yml.bak.<YYYYMMDD-HHMMSS>` per target profile plus one `models-store.json.bak.<same-stamp>`; 3 newest kept per category; created under an exclusive O_EXCL claim with an atomic tmp+rename write) → ONE interactive confirmation (via the host ask-user channel; its question names the legacy stubs, the per-id add/move/delete rows — every id deleted via `--adopt`/`--prune-user-extra` listed individually — the per-profile summary, the plan's managed-after notice quoted verbatim, the slots being created and the backup paths) → apply through the unchanged `migrate apply` consent gate (the hash/code are derived caller-side; there is no `--yes`/`--auto`). Right before apply every file is re-hashed and a file changed since its backup aborts that target (or the run for the shared store) with zero writes — rerun the command. Missing credential → fail-closed before any fetch, write, or backup. A missing or unanswered confirmation channel → fail-closed with the manual `migrate plan`/`apply` path and the computed hashes (config untouched; the already-created backups stay); an aborted invocation or an ambiguous answer (both labels selected) after the ask is treated as cancel — zero writes. Any apply failure stops the batch and restores every file the run changed — but only while its content still matches what this run last wrote there: a file a concurrent process touched is reported as `concurrent modification detected, not restored` with the backup path for manual handling instead of being overwritten (patch restores go through the atomic io the apply used; the models-store restore goes through the same cross-process lock accessor as every other store writer). On success `opencode.go.enabled` flips to `true` in the current profile and the detail log lands at `~/.dsh/storages/dsh-model-sync/migrate-go-<stamp>.log`. Rollback per profile: `/model-sync migrate rollback --plan <planHash>`.
133
-
134
- Slots come from the resolved top-level `opencode.go.routes` config — no google slot is created unless the configuration (or an existing section) calls for one, and no other provider is ever touched. Design rationale, alternatives, and revocation path: [ADR 0001 — in-command single confirmation for migrate-go](docs/adr/0001-in-command-single-confirmation-for-migrate-go.md).
135
+ Design rationale: [ADR 0002 — Detach official-API providers into per-protocol Managed Custom Providers](docs/adr/0002-detach-to-per-protocol-custom-providers.md).
135
136
 
136
137
  ## Development
137
138
 
package/README.zh-CN.md CHANGED
@@ -30,9 +30,12 @@ https://github.com/user-attachments/assets/c3f9c8b1-ea5e-470c-b8a8-60a81fc5c20a
30
30
  - **定时刷新。** `intervalMinutes` 周期轮(默认 240,即 4 小时)加 `startupDelaySeconds` 启动延迟(默认 5 秒);每轮自动刷新输出的报告与手动刷新完全相同。`0` 表示关闭周期(仅启动时刷一次)。配置变更时周期会实时重新挂载(`src/index.ts`)。
31
31
  - **变更报告 / diff。** 每轮报告新增/移除的模型 id(`diffModelIds`);`settings` 模式下还会对照当前原始 settings 报告新增/移除/变更的条目(`diffEntries`,`diff.ts`)。被丢弃(dropped)与降级(degraded)的条目连同原因一并报告。
32
32
  - **`modelSync` 服务。** 对外暴露 `modelSync` 服务(`syncNow()`),UI 调用它即可强制跑一轮刷新并读取报告。
33
- - **`/model-sync` 命令。** 插件自行通过共享的 dsh 命令注册表(`@deepseek-ai/dsh-commands`)注册 `/model-sync` 斜杠命令,所有交互式 UI 自动发现并列出——UI 侧零配合。执行它当场强制跑一轮刷新,输出的报告与定时轮完全相同;同步范围由 `managedRoutes` 决定(裸命令后附带的额外参数会被忽略)。命令注册表是可选 peer:没有命令注册服务的宿主照常降级,定时刷新与 `modelSync` 服务不受影响。其子命令为 `go`/`status`(跑一整轮 opencode-go 同步)、`adopt go`(带采纳跑同一轮)、`migrate plan|apply|rollback|status`(唯一经显式令牌三重门把守的写入路径;`plan` 只读,`apply` 需要 plan hash、6 位确认码与 `--ack-managed`)以及 `migrate-go`(一键完成整段迁移:plan + 文件备份 + 一次命令内确认 + apply,见下文)。`eject` 已下线——回退只用 `migrate rollback`。
34
- - **opencode-go 同步(需显式开启)。** 设 `opencode.go.enabled: true` 后,三条路由——`opencode-go`(chat-completions)、`opencode-go-msg`(messages)、`opencode-go-resp`(responses)——改为从官方公开 `/v1/models` 清单同步,而非 pi.dev。默认关闭,因此现存手写的 opencode-go 列表在开启前保持冻结。这三条 go 路由与上文的默认 pi.dev `managedRoutes` 相互独立。
35
- - **`/opencode-status` 只读诊断。** 对照官方 opencode-go `/v1/models` 清单与当前 profile 的路由(零写入、不改 settings)。
33
+ - **`/model-sync` 命令。** 插件自行通过共享的 dsh 命令注册表(`@deepseek-ai/dsh-commands`)注册 `/model-sync` 斜杠命令,所有交互式 UI 自动发现。裸 `/model-sync` 对 Builtin Provider 执行 `pi.dev` 同步(自动跳过已迁移到官方同步轨道的 provider)。子命令:
34
+ - `/model-sync <provider>`(如 `/model-sync go` 或 `/model-sync opencode-go`):手动从厂商官方 models API 同步最新模型;未适配的 provider 显式返回「不支持」。
35
+ - `/model-sync migrate <provider> [--all-profiles] [--confirm]`(兼容 `migrate-go`):从已有 Builtin Provider 提取 Key,单次确认与备份后创建按协议拆分的独立 Managed Custom Provider、删除旧 Builtin Provider、自动改写 `agent-default-model`,并启用默认 60 分钟自动更新。
36
+ - `/model-sync rollback <provider> [--confirm]`:还原旧 Builtin Provider 与 `agent-default-model`、删除新建 Custom Provider、停止定时同步。
37
+ - `/model-sync status [provider]`(兼容 `/opencode-status`):只读诊断状态与官方模型清单。
38
+ - **官方独立托管同步(`officialSync.opencode-go`,首个支持)。** 迁移后彻底脱离 `pi-ai` 内置 `opencode-go` 目录,拆分为独立的 `opencode-go-chat` / `opencode-go-msg` / `opencode-go-resp` / `opencode-go-google`,100% 以官方 `/v1/models` 为真源(绝不因宿主内置目录滞后而丢模型);默认每 60 分钟自动同步一次(可配,`0` = 仅手动);`sessionHeader: 'auto'` 会探测当前运行宿主的 `pi-ai` 能力,仅在缺少原生 `getOpenCodeSessionHeaders` 的旧版宿主(如 Desktop `0.2.2-rc.5`)上自动补静态 `x-opencode-session` 头防止 400。
36
39
  - **翻译规则。** pi.dev 条目被翻译成 settings 可写的模型 profile(`translate.ts`):base-matching 与 base-less 分类、`reasoningEfforts` 推导(S2 gate)、`compat` 门控到 `openai-completions`(S5 gate)、`maxTokens` 处理,以及混合协议路由的丢弃逻辑。容量值另有卫生门:非正整数的 `contextWindow`,或不是「严格小于 contextWindow 的正整数」的 `maxTokens`(有的列表会把 context window 回声填进 maxTokens),一律跳过不写,并在报告中以降级警告说明。
37
40
  - **你的覆盖不会被吃掉。** `modelOverrides` 是你自己的按模型调整通道(think level、收窄 context window 等)。dsh 拒绝 models 列表与非空 modelOverrides 并存,因此同步会把覆盖字段折叠进写入的 models、在同一次写入中清掉该键,并把原值存进 `~/.dsh/models-store.json` 逐轮回放——只要路由仍被托管,覆盖就持续压过同步值。
38
41
  - **默认安全的开关:**
@@ -84,7 +87,10 @@ dsh plugin remove @aiwayds/dsh-model-sync
84
87
  | `forceMaxReasoningEffort` | `false` | 对 `thinkingFormat` 非空的模型强制 max reasoning effort |
85
88
  | `providerNativeFetch` | `true` | 把各厂商自家的 `/models` 列表并入 pi.dev 结果(只增不减) |
86
89
  | `keepDeprecatedBuiltin` | `false` | 重新同步官方默认列表已移除的内置 id(dsh 0.1.7 移除了 `deepseek-v4-flash` / `deepseek-v4-flash-vision-exp`;dsh 0.2.0 移除了 opencode-go 的 `omen-alpha` 与 zai-coding-cn 的 `glm-4.7` / `glm-5-turbo` / `glm-5.1` / `glm-5.2` / `glm-5.2-highspeed` / `glm-5v-turbo`;快照保留数据但默认不再同步) |
87
- | `opencode.go.enabled` | `false` | 开启则对三条 `opencode-go*` 路由改用官方清单同步;默认关闭使现存手写 opencode-go 列表保持冻结(需要同步时显式设 `true`) |
90
+ | `officialSync.opencode-go.intervalMinutes` | `60` | 迁移后自动同步间隔(分钟);`0` = 仅手动 `/model-sync go` |
91
+ | `officialSync.opencode-go.modelsUrl` | `https://opencode.ai/inference/go/v1/models` | OpenCode Go 官方 `/v1/models` 接口 |
92
+ | `officialSync.opencode-go.sessionHeader` | `'auto'` | `'auto'`(仅在缺少原生注入的旧宿主上写静态 `x-opencode-session` 头)、`'static'` 或 `'none'` |
93
+ | `officialSync.opencode-go.routes` | `opencode-go-{chat,msg,resp,google}` | 各协议槽位对应的 Custom Provider 名称 |
88
94
 
89
95
  示例:
90
96
 
@@ -117,23 +123,18 @@ providers:
117
123
 
118
124
  另外列表数据本身可能有噪声:容量值有卫生门(正整数;`maxTokens` 必须严格小于 `contextWindow`),被剥离的值会在同步报告里以 `DEGRADED` 行连同原因出现。
119
125
 
120
- ### 手动刷新:`/model-sync` 与 `/opencode-status`
126
+ ### 手动刷新与官方同步:`/model-sync`、`/model-sync migrate`、`/model-sync rollback`
121
127
 
122
- 在任意交互式 UI 里输入 `/model-sync` 即可当场强制跑一轮同步。命令由插件自己注册进共享命令注册表(`@deepseek-ai/dsh-commands`),UI 自动发现。它返回与定时轮相同的报告;同步范围由 `managedRoutes` 决定,裸命令后附带的额外参数会被忽略。没有命令注册服务的宿主会平滑降级——定时刷新与 `modelSync` 服务照常工作。
128
+ 在任意交互式 UI 里输入裸 `/model-sync` 即可对 Builtin Provider 跑一轮 `pi.dev` 同步(已迁移到官方轨道的 provider 会自动跳过)。
123
129
 
124
- opencode-go 增加了子命令:`/model-sync go`(或 `status`)跑一整轮 go 同步,`/model-sync adopt go` 带采纳跑同一轮,`/model-sync migrate plan|apply|rollback|status` 是唯一经显式令牌三重门把守的写入路径——`plan` 只读,`apply` 需要 plan hash、6 位确认码与 `--ack-managed`。`eject` 已下线,回退请用 `migrate rollback`。`/opencode-status` 是另一条只读诊断命令,对照官方清单与当前 profile 路由,从不写入 settings 或凭据。desktop/web GUI 客户端只会把自由文本参数回传给声明了 `input` 描述符的命令——`/model-sync` 本版已声明,因此上述子命令在 GUI 里同样可用(hint 仅用于提示,参数解析仍在 handler 内)。
130
+ 针对官方独立托管轨道(目前支持 OpenCode Go;未适配的 provider 一律显式提示不支持):
125
131
 
126
- ### 一键迁移:`/model-sync migrate-go`
132
+ - `/model-sync migrate go [--all-profiles] [--confirm]`(兼容 `migrate-go`):要求当前 profile 存在旧 `providers.opencode-go`(空白 profile 不可用 migrate 初始化);提取其 `apiKeyEnv` 并拉通官方 `/v1/models`;备份 `cordis.patch.yml` 与 `models-store.json`;单次交互确认(无交互通道时需显式传 `--confirm`);创建按协议拆分的 Managed Custom Provider(`opencode-go-chat` / `opencode-go-msg` / `opencode-go-resp` / `opencode-go-google`),删掉旧 `opencode-go`,自动改写 `agent-default-model` 并提示其他引用,随即启用每 60 分钟自动同步。
133
+ - `/model-sync go`:手动立即从官方 `/v1/models` 同步最新模型(全量纳入官方模型,不再受宿主内置目录滞后限制;变空的协议槽位自动移除)。
134
+ - `/model-sync rollback go [--confirm]`:备份并单次确认后还原旧 `opencode-go` 与 `agent-default-model`、删除新建的 Custom Provider、停止定时同步。
135
+ - `/model-sync status [go]`(或 `/opencode-status`):只读诊断当前迁移状态、sessionHeader 探测结果与官方模型数。
127
136
 
128
- `/model-sync migrate-go` 一条命令跑完整段迁移流水线;默认只处理当前 profile,`--all-profiles` 处理全部 patch 里仍带 opencode-go 旧残桩(只有 `models`、无 `api`/`baseURL` 的段)的 profile:
129
-
130
- ```bash
131
- /model-sync migrate-go [--all-profiles] [--adopt] [--prune-user-extra] [--rewrite-refs=default-model|config]
132
- ```
133
-
134
- 固定流水线:生成计划(与 `migrate plan` 打印的同一只读构建)→ 写入前先做文件备份(每个目标 profile 一份 `cordis.patch.yml.bak.<YYYYMMDD-HHMMSS>`,全局一份 `models-store.json.bak.<同一时间戳>`;每类按文件名时间戳保留最新 3 份;备份以 O_EXCL 独占声明创建,经原子 tmp+rename 落盘)→ 仅弹一次交互确认(走宿主 ask-user 通道;题干列出将替换的旧残桩、逐 id 的增/移/删动作行——经 `--adopt`/`--prune-user-extra` 删除的每个 id 单独列出——每个 profile 的摘要、计划「迁移后转为托管」提示的原文(官方清单下架即自动移除)、将新建的槽位与备份路径)→ 经原封不动的 `migrate apply` 同意门执行(hash/确认码由调用侧算出;不存在 `--yes`/`--auto`)。apply 前一刻对所有文件全量重算 sha256,任一文件自备份后被改动即中止该目标(共享 store 则中止整轮),零写入——重跑命令即可。缺凭证 → 在任何外呼、写入、备份之前 fail-closed。确认通道缺失或未应答 → fail-closed,改走手动 `migrate plan`/`apply` 流程并给出已算出的 hash(配置零写入;已生成的备份保留);ask 之后用户中断(abort)或答案同时勾选两个选项(歧义)一律按取消处理——零写入。任一 apply 失败则中止整批并还原本轮改动的所有文件——但仅当文件内容仍与本轮最后写入的一致:被并发进程改过的文件按 `concurrent modification detected, not restored` 报告并给出备份路径,交由人工处理而不是被覆盖(patch 还原走 apply 同款的原子 io;models-store 还原走与其他 store 写入相同的跨进程锁访问器,绝不裸覆盖;本轮新建的 store 会在同一守卫下移除)。成功后当前 profile 的 `opencode.go.enabled` 置为 `true`,明细日志落在 `~/.dsh/storages/dsh-model-sync/migrate-go-<时间戳>.log`。逐 profile 回退:`/model-sync migrate rollback --plan <planHash>`。
135
-
136
- 槽位来自顶层 `opencode.go.routes` 配置的解析结果——除非配置(或现存段)要求,不会创建 google 槽,也从不触碰其他 provider。设计取舍与撤销路径见 [ADR 0001:migrate-go 的命令内单次确认](docs/adr/0001-in-command-single-confirmation-for-migrate-go.md)。
137
+ 设计取舍与背景见 [ADR 0002:Detach official-API providers into per-protocol Managed Custom Providers](docs/adr/0002-detach-to-per-protocol-custom-providers.md)。
137
138
 
138
139
  ## 开发
139
140