omnicell-router 0.7.0 → 0.8.2

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 (246) hide show
  1. package/backend/dist/cli/clients/activity.d.ts +35 -0
  2. package/backend/dist/cli/clients/activity.js +67 -0
  3. package/backend/dist/cli/clients/base.d.ts +13 -2
  4. package/backend/dist/cli/clients/claude.d.ts +2 -2
  5. package/backend/dist/cli/clients/codex.d.ts +2 -2
  6. package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
  7. package/backend/dist/cli/clients/core-adapters.js +3 -4
  8. package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
  9. package/backend/dist/cli/clients/cursor-proxy.js +421 -0
  10. package/backend/dist/cli/clients/dsh.d.ts +2 -2
  11. package/backend/dist/cli/clients/grok.d.ts +2 -2
  12. package/backend/dist/cli/clients/index.d.ts +8 -1
  13. package/backend/dist/cli/clients/index.js +55 -21
  14. package/backend/dist/cli/clients/kimi.d.ts +2 -2
  15. package/backend/dist/cli/clients/launcher.d.ts +8 -0
  16. package/backend/dist/cli/clients/model-meta.js +1 -1
  17. package/backend/dist/cli/clients/omp.d.ts +2 -2
  18. package/backend/dist/cli/clients/openclaw.d.ts +2 -2
  19. package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
  20. package/backend/dist/cli/clients/opencode-proxy.js +351 -0
  21. package/backend/dist/cli/clients/opencode.d.ts +2 -2
  22. package/backend/dist/cli/clients/pi.d.ts +2 -2
  23. package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
  24. package/backend/dist/cli/clients/plugin-adapters.js +6 -29
  25. package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
  26. package/backend/dist/cli/clients/qoder-proxy.js +497 -0
  27. package/backend/dist/cli/clients/reserved.d.ts +2 -6
  28. package/backend/dist/cli/clients/reserved.js +2 -0
  29. package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
  30. package/backend/dist/cli/index.js +60 -9
  31. package/backend/dist/cli/types.d.ts +29 -8
  32. package/backend/dist/compression/caveman-prompts.d.ts +1 -1
  33. package/backend/dist/config/comments-en.js +6 -12
  34. package/backend/dist/config/comments-zh.js +6 -12
  35. package/backend/dist/config/defaults.d.ts +56 -1
  36. package/backend/dist/config/defaults.js +68 -0
  37. package/backend/dist/config/index.d.ts +9 -2
  38. package/backend/dist/config/index.js +26 -3
  39. package/backend/dist/config/types.d.ts +55 -43
  40. package/backend/dist/forward-proxy/egress.d.ts +10 -2
  41. package/backend/dist/forward-proxy/egress.js +42 -4
  42. package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
  43. package/backend/dist/forward-proxy/ordered-relay.js +46 -0
  44. package/backend/dist/forward-proxy/rules.d.ts +66 -19
  45. package/backend/dist/forward-proxy/rules.js +61 -14
  46. package/backend/dist/forward-proxy/server.js +226 -77
  47. package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
  48. package/backend/dist/forward-proxy/system-proxy.js +199 -22
  49. package/backend/dist/harness/common/market.d.ts +3 -3
  50. package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
  51. package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
  52. package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
  53. package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
  54. package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
  55. package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
  56. package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
  57. package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
  58. package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
  59. package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
  60. package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
  61. package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
  62. package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
  63. package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
  64. package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
  65. package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
  66. package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
  67. package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
  68. package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
  69. package/backend/dist/harness/translation.js +64 -21
  70. package/backend/dist/harness/types.d.ts +1 -1
  71. package/backend/dist/harness/types.js +1 -1
  72. package/backend/dist/index.js +31 -18
  73. package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
  74. package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
  75. package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
  76. package/backend/dist/ir/adapters/anthropic.js +788 -0
  77. package/backend/dist/ir/adapters/chat.d.ts +15 -0
  78. package/backend/dist/ir/adapters/chat.js +602 -0
  79. package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
  80. package/backend/dist/ir/adapters/google-stream.js +242 -0
  81. package/backend/dist/ir/adapters/google.d.ts +9 -0
  82. package/backend/dist/ir/adapters/google.js +317 -0
  83. package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
  84. package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
  85. package/backend/dist/ir/adapters/openai-responses.js +26 -1
  86. package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
  87. package/backend/dist/ir/adapters/responses-output.js +348 -0
  88. package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
  89. package/backend/dist/ir/adapters/responses-stream.js +178 -0
  90. package/backend/dist/ir/adapters/responses.d.ts +14 -0
  91. package/backend/dist/ir/adapters/responses.js +646 -0
  92. package/backend/dist/ir/errors.d.ts +2 -2
  93. package/backend/dist/ir/types.d.ts +2 -1
  94. package/backend/dist/metrics/request-cost.d.ts +11 -2
  95. package/backend/dist/metrics/request-cost.js +12 -3
  96. package/backend/dist/observability/request-identity.d.ts +1 -1
  97. package/backend/dist/observability/trace-id.d.ts +40 -0
  98. package/backend/dist/observability/trace-id.js +134 -0
  99. package/backend/dist/observability/upstream-events.d.ts +82 -60
  100. package/backend/dist/observability/upstream-events.js +142 -67
  101. package/backend/dist/opencode/catalog/types.d.ts +9 -0
  102. package/backend/dist/opencode/credentials/types.d.ts +2 -2
  103. package/backend/dist/opencode/probe.d.ts +24 -1
  104. package/backend/dist/opencode/probe.js +28 -4
  105. package/backend/dist/opencode/user-config.d.ts +5 -0
  106. package/backend/dist/pipeline/directives.d.ts +6 -2
  107. package/backend/dist/pipeline/directives.js +7 -3
  108. package/backend/dist/pipeline/orchestrator.d.ts +28 -27
  109. package/backend/dist/pipeline/orchestrator.js +220 -194
  110. package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
  111. package/backend/dist/pipeline/unresolved-model.js +43 -0
  112. package/backend/dist/plugins/catalog-def.d.ts +143 -0
  113. package/backend/dist/plugins/catalog-def.js +177 -0
  114. package/backend/dist/plugins/gateways.d.ts +62 -3
  115. package/backend/dist/plugins/gateways.js +139 -2
  116. package/backend/dist/plugins/host.d.ts +42 -5
  117. package/backend/dist/plugins/host.js +454 -38
  118. package/backend/dist/plugins/manifest.d.ts +119 -10
  119. package/backend/dist/plugins/manifest.js +265 -14
  120. package/backend/dist/plugins/pack.js +26 -0
  121. package/backend/dist/plugins/types.d.ts +187 -21
  122. package/backend/dist/protocols/systemone/convert.d.ts +1 -0
  123. package/backend/dist/protocols/systemone/convert.js +6 -1
  124. package/backend/dist/protocols/systemone/decide.js +18 -8
  125. package/backend/dist/providers/anthropic-messages.d.ts +12 -0
  126. package/backend/dist/providers/anthropic-messages.js +53 -0
  127. package/backend/dist/providers/anthropic.d.ts +7 -8
  128. package/backend/dist/providers/anthropic.js +36 -324
  129. package/backend/dist/providers/base.d.ts +14 -2
  130. package/backend/dist/providers/boot-direct.js +68 -38
  131. package/backend/dist/providers/dispatch.d.ts +5 -19
  132. package/backend/dist/providers/dispatch.js +46 -58
  133. package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
  134. package/backend/dist/providers/executors/anthropic-messages.js +3 -0
  135. package/backend/dist/providers/executors/dispatch.d.ts +16 -2
  136. package/backend/dist/providers/executors/dispatch.js +39 -9
  137. package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
  138. package/backend/dist/providers/executors/google-gemini.js +3 -0
  139. package/backend/dist/providers/executors/http-stream.js +16 -3
  140. package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
  141. package/backend/dist/providers/executors/openai-chat.js +3 -0
  142. package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
  143. package/backend/dist/providers/executors/openai-responses.js +3 -0
  144. package/backend/dist/providers/executors/plugin-adapter.js +4 -4
  145. package/backend/dist/providers/google-gemini.d.ts +12 -0
  146. package/backend/dist/providers/google-gemini.js +50 -0
  147. package/backend/dist/providers/google.d.ts +7 -8
  148. package/backend/dist/providers/google.js +35 -308
  149. package/backend/dist/providers/http-json.d.ts +19 -0
  150. package/backend/dist/providers/http-json.js +104 -0
  151. package/backend/dist/providers/http-stream.d.ts +52 -0
  152. package/backend/dist/providers/http-stream.js +423 -0
  153. package/backend/dist/providers/member-match.d.ts +4 -5
  154. package/backend/dist/providers/member-match.js +4 -5
  155. package/backend/dist/providers/openai-chat.d.ts +13 -0
  156. package/backend/dist/providers/openai-chat.js +99 -0
  157. package/backend/dist/providers/openai-compatible.d.ts +7 -4
  158. package/backend/dist/providers/openai-compatible.js +71 -368
  159. package/backend/dist/providers/openai-responses.d.ts +12 -0
  160. package/backend/dist/providers/openai-responses.js +68 -0
  161. package/backend/dist/providers/opencode-proxy.d.ts +5 -5
  162. package/backend/dist/providers/opencode-proxy.js +49 -125
  163. package/backend/dist/providers/plugin-adapter.d.ts +9 -0
  164. package/backend/dist/providers/plugin-adapter.js +31 -0
  165. package/backend/dist/providers/registry.d.ts +49 -24
  166. package/backend/dist/providers/registry.js +97 -55
  167. package/backend/dist/providers/responses.d.ts +7 -28
  168. package/backend/dist/providers/responses.js +45 -253
  169. package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
  170. package/backend/dist/providers/tool-markup-leak.js +57 -0
  171. package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
  172. package/backend/dist/providers/tool-markup-recovery.js +786 -0
  173. package/backend/dist/providers/virtual-meta.d.ts +21 -2
  174. package/backend/dist/providers/virtual-meta.js +49 -9
  175. package/backend/dist/proxy/asset-download.d.ts +54 -0
  176. package/backend/dist/proxy/asset-download.js +420 -0
  177. package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
  178. package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
  179. package/backend/dist/proxy/mihomo-binary.js +62 -51
  180. package/backend/dist/proxy/mihomo-client.js +15 -1
  181. package/backend/dist/proxy/mihomo-config.js +11 -2
  182. package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
  183. package/backend/dist/proxy/mihomo-geo.js +213 -0
  184. package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
  185. package/backend/dist/proxy/mihomo-logs.js +70 -0
  186. package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
  187. package/backend/dist/proxy/mihomo-pac.js +15 -0
  188. package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
  189. package/backend/dist/proxy/mihomo-rules-import.js +7 -7
  190. package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
  191. package/backend/dist/proxy/mihomo-sidecar.js +148 -26
  192. package/backend/dist/quota/adapters/minimax.js +36 -13
  193. package/backend/dist/quota/cli-login.d.ts +8 -0
  194. package/backend/dist/quota/cli-login.js +18 -0
  195. package/backend/dist/quota/declarations.js +10 -0
  196. package/backend/dist/quota/dsl.js +18 -5
  197. package/backend/dist/quota/engine.d.ts +22 -1
  198. package/backend/dist/quota/engine.js +170 -29
  199. package/backend/dist/quota/prober.d.ts +5 -0
  200. package/backend/dist/quota/prober.js +11 -2
  201. package/backend/dist/quota/types.d.ts +87 -8
  202. package/backend/dist/quota/verdict.d.ts +35 -0
  203. package/backend/dist/quota/verdict.js +135 -0
  204. package/backend/dist/ratelimit/admission.d.ts +131 -0
  205. package/backend/dist/ratelimit/admission.js +233 -0
  206. package/backend/dist/ratelimit/rate-limiter.js +6 -0
  207. package/backend/dist/resilience/types.d.ts +2 -2
  208. package/backend/dist/router/layer2-decision.d.ts +1 -1
  209. package/backend/dist/router/layer2-decision.js +5 -8
  210. package/backend/dist/routes/console.js +248 -52
  211. package/backend/dist/routes/mihomo.d.ts +2 -0
  212. package/backend/dist/routes/mihomo.js +334 -29
  213. package/backend/dist/routes/responses.d.ts +87 -8
  214. package/backend/dist/routes/responses.js +314 -33
  215. package/backend/dist/server.js +34 -6
  216. package/backend/dist/session/session-manager.d.ts +6 -0
  217. package/backend/dist/session/session-manager.js +20 -9
  218. package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
  219. package/backend/dist/surfaces/chat-pipeline.js +17 -7
  220. package/backend/dist/surfaces/chat.js +15 -0
  221. package/backend/dist/surfaces/decision-pipeline.js +7 -10
  222. package/backend/dist/surfaces/direct-forward.d.ts +3 -0
  223. package/backend/dist/surfaces/direct-forward.js +206 -0
  224. package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
  225. package/backend/dist/surfaces/rate-limit-response.js +57 -0
  226. package/backend/dist/surfaces/types.d.ts +11 -0
  227. package/backend/dist/trace/tracker.d.ts +32 -1
  228. package/backend/dist/trace/tracker.js +29 -4
  229. package/backend/dist/types/router.d.ts +34 -12
  230. package/backend/dist/types/router.js +35 -6
  231. package/backend/dist/utils/chat-stream.d.ts +21 -8
  232. package/backend/dist/utils/chat-stream.js +46 -9
  233. package/backend/dist/utils/event-ring.d.ts +4 -0
  234. package/backend/dist/utils/event-ring.js +4 -0
  235. package/backend/dist/utils/popularity.js +29 -4
  236. package/backend/dist/utils/proxy.d.ts +7 -0
  237. package/backend/dist/utils/proxy.js +35 -10
  238. package/backend/dist/utils/retry-after.d.ts +21 -0
  239. package/backend/dist/utils/retry-after.js +36 -0
  240. package/bin/ocr.js +2 -2
  241. package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
  242. package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
  243. package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
  244. package/frontend/dist/index.html +2 -2
  245. package/package.json +1 -1
  246. package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
@@ -9,10 +9,10 @@ import { DEFAULT_PROVIDER_TIMEOUT_MS } from '../config/defaults.js';
9
9
  import { getRuntimeConfigRef } from '../config/runtime.js';
10
10
  import { emitUpstreamRequestOnce, emitUpstreamResponseOnce, emitUpstreamFailureOnce, withUpstreamFailureGuard, } from '../observability/upstream-events.js';
11
11
  import { beginPluginClientAdapterRebuild, commitPluginClientAdapterRebuild, registerPluginClientAdapter } from '../cli/clients/plugin-adapters.js';
12
- import { commitGateways, removeGateway, retainStagedGateways, stageGateway, getGatewayById, WILDCARD_HOST_CLAIM } from './gateways.js';
12
+ import { commitGateways, removeGateway, retainStagedGateways, setGatewayOperatorEgress, stageGateway, getGatewayById, WILDCARD_HOST_CLAIM } from './gateways.js';
13
13
  import { getGatewayChatServices } from '../surfaces/gateway-chat.js';
14
14
  import { invalidatePluginConfigCache, mergedPluginConfig, pluginConfigPath, writePluginConfig } from './config.js';
15
- import { assertSupportedPluginApi, isValidPluginId, normalizePluginParts, validatePluginManifest } from './manifest.js';
15
+ import { assertSupportedPluginApi, isValidPluginId, normalizePluginParts, operatorEgressChoice, pluginEngineRefusal, validatePluginManifest, withGatewayEgressField, } from './manifest.js';
16
16
  import { compareVersions } from '../utils/semver.js';
17
17
  import { seedBundledPlugins } from './seed.js';
18
18
  import { forwardH2 } from '../forward-proxy/h2-forward.js';
@@ -20,8 +20,10 @@ import { getProxyCaller } from '../forward-proxy/caller-context.js';
20
20
  import { forwardTo, proxyFail, RULE_REJECTED_MESSAGE } from '../forward-proxy/server.js';
21
21
  import { resolveUpstreamTls } from '../forward-proxy/upstream-tls.js';
22
22
  import { isRuleRejected } from '../forward-proxy/egress.js';
23
- import { claimPluginWires, isCoreWire } from '../providers/plugin-wires.js';
23
+ import { claimPluginWires, isCoreWire, isPluginWire } from '../providers/plugin-wires.js';
24
24
  import { currentProtocol } from '../providers/protocol.js';
25
+ import { wireFor } from '../providers/wire.js';
26
+ import { proxiedFetch, resolveProxyUrl } from '../utils/proxy.js';
25
27
  /**
26
28
  * Plugin host: discovers, unpacks and loads plugins. Two types today
27
29
  * (ADR-0017): 'model-service' (outbound executors, registry below) and
@@ -88,7 +90,15 @@ let rebuildInFlight = Promise.resolve([]);
88
90
  /** Set by the tail of a completed `loadInstalledPlugins()`. */
89
91
  let hostInitialized = false;
90
92
  /** The backend capabilities handed to every model-service plugin at load time.
91
- * `dir` is the plugin's load root — the only asset root a packaged plugin has. */
93
+ * `dir` is the plugin's load root — the only asset root a packaged plugin has.
94
+ *
95
+ * Exported as a test seam: the egress seam (`fetch` / `resolveProxy`) is the
96
+ * ONE way a plugin reaches its upstream, and it has no other side effects —
97
+ * the registry-filled ``pull`` block is wired separately by
98
+ * ``pluginPullServices()``. */
99
+ export function buildHostSdkForTests(manifest, dir) {
100
+ return buildHostSdk(manifest, dir);
101
+ }
92
102
  function buildHostSdk(manifest, dir) {
93
103
  return {
94
104
  UpstreamError: UpstreamError,
@@ -100,7 +110,14 @@ function buildHostSdk(manifest, dir) {
100
110
  },
101
111
  constants: { providerTimeoutMs: DEFAULT_PROVIDER_TIMEOUT_MS },
102
112
  config: () => mergedPluginConfig(manifest.id, manifest.configSchema),
113
+ ocrHome: () => getOcrHomeDir(),
103
114
  pluginDir: () => dir,
115
+ // Egress policy is CORE-owned (ADR-0022): a plugin wire reaches its upstream
116
+ // through this seam, never the global `fetch`, so `proxy.includes` /
117
+ // `proxy.excludes` govern plugin traffic exactly as they govern the four
118
+ // built-in transports. `match` carries the logical caller for the lists.
119
+ fetch: (url, init, match) => proxiedFetch(url, init, match),
120
+ resolveProxy: (url, match) => resolveProxyUrl(url, match),
104
121
  // Filled by pluginPullServices() BEFORE createPlugin is invoked.
105
122
  pull: {
106
123
  getProviderNode: () => undefined,
@@ -283,7 +300,27 @@ function asEntryResult(raw) {
283
300
  function readManifest(dir) {
284
301
  const raw = JSON.parse(readFileSync(join(dir, 'plugin.json'), 'utf8'));
285
302
  validatePluginManifest(raw, 'invalid plugin.json');
286
- return raw;
303
+ // The operator's outbound-leg switch is injected HERE, at the single point a
304
+ // manifest becomes runtime data: the validator above has already refused a
305
+ // package that declares the key itself, and every reader downstream — the
306
+ // console drawer, the config merge, and a plugin's own `config()` closure —
307
+ // then sees the SAME schema. Injected later, the drawer would offer a control
308
+ // the merge drops.
309
+ return withGatewayEgressField(raw);
310
+ }
311
+ /** `readManifest`, with an unreadable/invalid manifest answered as `undefined`
312
+ * instead of thrown. The engine gate (ADR-0036) only needs the DECLARATION — a
313
+ * package whose manifest cannot be read is not a compatibility question at all,
314
+ * and it must keep falling through to the loader, which reports the real
315
+ * reason.
316
+ */
317
+ function readManifestOrUndefined(dir) {
318
+ try {
319
+ return readManifest(dir);
320
+ }
321
+ catch {
322
+ return undefined;
323
+ }
287
324
  }
288
325
  /** Extract one packaged zip when the unpacked copy is missing or stale. */
289
326
  function ensureUnpacked(packagedPath, id) {
@@ -341,7 +378,7 @@ export function pluginEntrySpecifier(entry, mtimeMs, bun) {
341
378
  * for a part the package actually returned), plus the console row. */
342
379
  async function importPlugin(dir, source) {
343
380
  const manifest = readManifest(dir);
344
- assertSupportedPluginApi(manifest.apiVersion);
381
+ assertSupportedPluginApi(manifest);
345
382
  // Dev tree is source-first; a package carries the BUNDLED entry. A package
346
383
  // without one is source-only and cannot load in a compiled sidecar, so fail
347
384
  // with the actionable fix instead of the resolver's bare-specifier error.
@@ -385,6 +422,8 @@ async function importPlugin(dir, source) {
385
422
  wires: modelPart?.wires ?? manifest.wires ?? [],
386
423
  description: manifest.description,
387
424
  warningLabels: manifest.warningLabels,
425
+ clientText: manifest.clientText,
426
+ changelog: manifest.changelog,
388
427
  presets: manifest.presets,
389
428
  logo: manifest.logo,
390
429
  source,
@@ -457,9 +496,19 @@ async function importPlugin(dir, source) {
457
496
  // gateway before it would leave a package that failed to load still owning
458
497
  // its hosts — "broken row, traffic still intercepted", the worst of both.
459
498
  if (loaded.clientAdapter)
460
- registerPluginClientAdapter(manifest.id, loaded.clientAdapter);
461
- if (loaded.gateway)
462
- stageGateway(manifest.id, loaded.gateway);
499
+ registerPluginClientAdapter(manifest.id, loaded.clientAdapter, manifest.clientRank);
500
+ // The claim's outbound-leg tiers (ADR-0018 Revision 5) travel with the registration,
501
+ // not with the module object: `plugin.json` is the manifest truth, the stored
502
+ // config is the operator's word, and the gateway's own `egressFor()` is the
503
+ // third voice the registry asks between them. An untouched switch merges back
504
+ // as `inherit`, which is not a choice — so it never reaches the registry and
505
+ // never silences the plugin's per-host answer.
506
+ if (loaded.gateway) {
507
+ stageGateway(manifest.id, loaded.gateway, {
508
+ manifest: gatewayPart?.egress,
509
+ operator: operatorEgressChoice(mergedPluginConfig(manifest.id, manifest.configSchema)),
510
+ });
511
+ }
463
512
  manifestsById.set(manifest.id, manifest);
464
513
  return { ...loaded, view };
465
514
  }
@@ -478,12 +527,60 @@ function failedView(id, source, path, err, declared) {
478
527
  type: parts[0]?.type ?? 'model-service',
479
528
  types: parts.map((p) => p.type),
480
529
  wires: [],
530
+ // Identity for a row that failed to load: the console can still tell the
531
+ // operator what the package claims to change.
532
+ changelog: declared?.changelog,
481
533
  source,
482
534
  path,
483
535
  loaded: false,
484
536
  error: err instanceof Error ? err.message : String(err),
485
537
  };
486
538
  }
539
+ /**
540
+ * The row for a package this host REFUSES on engine-compatibility grounds
541
+ * (ADR-0036). Distinct from `failedView` on purpose: a failed load is a BROKEN
542
+ * package the operator can only report, while this one is a compatible-ish
543
+ * install that is one upgrade away from working — either of the plugin or of
544
+ * the gateway. So it renders as DISABLED (no traffic, no wire, no preset) with
545
+ * the refusal sentence as its reason, it is not an error the console offers to
546
+ * "fix", and it clears itself the moment the mismatch is resolved: the gate is
547
+ * re-evaluated on every load from the manifest on disk, and nothing about this
548
+ * state is persisted.
549
+ *
550
+ * The disabled LEDGER is not written: writing it would outlive the mismatch and
551
+ * switch off a package that has become compatible.
552
+ */
553
+ function incompatibleView(id, source, path, declared, reason) {
554
+ const parts = normalizePluginParts(declared);
555
+ // The manifest IS registered even though the code never loads: the console's
556
+ // settings drawer reads the schema from `manifestsById`, and a refused row
557
+ // whose drawer 404s looks broken rather than refused. Reading a schema runs
558
+ // no plugin code (ADR-0036), so this costs a map entry and nothing else.
559
+ manifestsById.set(declared.id || id, declared);
560
+ return {
561
+ id: declared.id || id,
562
+ name: declared.name,
563
+ version: declared.version,
564
+ type: parts[0]?.type ?? 'model-service',
565
+ types: parts.map((p) => p.type),
566
+ // No wire: an incompatible package answers nothing, and the console's wire
567
+ // column must not promise a protocol this host never registered.
568
+ wires: [],
569
+ description: declared.description,
570
+ changelog: declared.changelog,
571
+ presets: declared.presets,
572
+ logo: declared.logo,
573
+ source,
574
+ path,
575
+ disabled: true,
576
+ loaded: false,
577
+ // The console needs to tell this apart from an operator-disabled row: the
578
+ // reason is a compatibility statement, and toggling the plugin is not the
579
+ // remedy (upgrading one of the two sides is).
580
+ incompatible: true,
581
+ error: reason,
582
+ };
583
+ }
487
584
  /** Scan both discovery roots and (re)build the registry. Serialized: the
488
585
  * swap into `registry` is atomic (built in `nextRegistry` first), so
489
586
  * in-flight dispatch/probe never see an empty plugin set mid-rebuild. */
@@ -512,6 +609,10 @@ async function doLoadInstalledPlugins() {
512
609
  beginPluginClientAdapterRebuild();
513
610
  invalidatePluginConfigCache();
514
611
  const views = [];
612
+ // Rows refused by the engine gate (ADR-0036). Kept in their own list because
613
+ // they are part of THIS load's view set (the console lists them, and they
614
+ // claim their id) but they are not "installed" in the disabled ledger.
615
+ const incompatibleViews = [];
515
616
  const devRoot = devSourceRoot();
516
617
  const disabled = readDisabled();
517
618
  disabledViews = [];
@@ -521,6 +622,21 @@ async function doLoadInstalledPlugins() {
521
622
  const dir = join(devRoot, name);
522
623
  if (!existsSync(join(dir, 'plugin.json')))
523
624
  continue;
625
+ // ENGINE-COMPATIBILITY gate (ADR-0036) FIRST — ahead of the disabled
626
+ // check AND ahead of the import: code that cannot run here is never
627
+ // imported, so a mismatch costs one manifest read instead of a thrown
628
+ // module, and a package that is both incompatibly old and operator-
629
+ // disabled reports the reason that toggling cannot fix (the remedy is an
630
+ // upgrade, not a switch). The READABLE manifest is what makes the
631
+ // refusal actionable, so an unreadable one falls through to
632
+ // `importPlugin` / `failedView` and gets the failure wording instead.
633
+ const devDeclared = readManifestOrUndefined(dir);
634
+ const devRefusal = devDeclared ? pluginEngineRefusal(devDeclared) : undefined;
635
+ if (devDeclared && devRefusal) {
636
+ seenIds.add(name);
637
+ incompatibleViews.push(incompatibleView(name, 'dev', dir, devDeclared, devRefusal));
638
+ continue;
639
+ }
524
640
  if (disabled.has(name)) {
525
641
  seenIds.add(name);
526
642
  disabledViews.push(stubDisabledView(name, dir, 'dev'));
@@ -588,6 +704,21 @@ async function doLoadInstalledPlugins() {
588
704
  console.warn(`[OCR] plugins: duplicate id '${id}' — ${packagedPath} ignored (a higher-precedence copy already loaded)`);
589
705
  continue;
590
706
  }
707
+ // ENGINE-COMPATIBILITY gate (ADR-0036) FIRST — ahead of the disabled
708
+ // check and before `ensureUnpacked`: an unloadable package must not
709
+ // leave an extracted tree behind, its code must never reach the module
710
+ // cache, and a package that is both incompatibly old and operator-
711
+ // disabled must report the reason a switch cannot fix. The package FILE
712
+ // stays — an upgrade is installed over it, and the gate re-runs on every
713
+ // load.
714
+ if (packagedManifest) {
715
+ const refusal = pluginEngineRefusal(packagedManifest);
716
+ if (refusal) {
717
+ seenIds.add(id);
718
+ incompatibleViews.push(incompatibleView(id, 'packaged', packagedPath, packagedManifest, refusal));
719
+ continue;
720
+ }
721
+ }
591
722
  if (disabled.has(id)) {
592
723
  // No ensureUnpacked for disabled packages: their code stays dormant.
593
724
  disabledViews.push(stubDisabledView(id, join(packRoot, 'unpacked', id), 'packaged', packagedManifest));
@@ -616,7 +747,16 @@ async function doLoadInstalledPlugins() {
616
747
  // Anything else staged is a half-registration from a load that threw after
617
748
  // staging (or a future path that forgets to unstage) — a gateway that
618
749
  // answers with no row to disable is unreachable state, so it is dropped.
750
+ // Engine-refused rows join the view set HERE, after every other gate has run,
751
+ // so they can never shadow a same-id package that does load.
619
752
  retainStagedGateways(new Set(views.filter((v) => v.loaded).map((v) => v.id)));
753
+ // `views` is the LIVE load result (which package owns an id, what loaded);
754
+ // `lastViews` is what the console lists, and a package refused by the engine
755
+ // gate is exactly a row the operator has to SEE — it is silently dead
756
+ // otherwise, with no clue that an upgrade would fix it.
757
+ lastViews = [...views, ...incompatibleViews];
758
+ for (const view of incompatibleViews)
759
+ console.warn(`[OCR] plugins: ${view.error}`);
620
760
  // Atomic swap: in-flight dispatch/probe never observe an empty registry —
621
761
  // and the gateway registry rides the same commit point.
622
762
  registry.clear();
@@ -630,7 +770,6 @@ async function doLoadInstalledPlugins() {
630
770
  claimPluginWires([...registry.values()].flatMap((entry) => entry.view.wires));
631
771
  commitGateways();
632
772
  commitPluginClientAdapterRebuild();
633
- lastViews = views;
634
773
  hostInitialized = true;
635
774
  return views;
636
775
  }
@@ -691,8 +830,13 @@ function stubDisabledView(id, dir, source, packaged) {
691
830
  version: m.version,
692
831
  type: parts[0]?.type ?? 'model-service',
693
832
  types: parts.map((p) => p.type),
694
- wires: parts.find((p) => p.type === 'model-service')?.wires ?? m.wires ?? [],
833
+ // `wires` stays EMPTY on a dormant row, exactly like a refused one: the
834
+ // package answers no protocol here (its code is never imported), so the
835
+ // console's wire column must not promise one. The manifest still declares
836
+ // them — that is a fact about the package, not about this host.
837
+ wires: [],
695
838
  description: m.description,
839
+ changelog: m.changelog,
696
840
  presets: m.presets,
697
841
  logo: m.logo,
698
842
  source,
@@ -749,6 +893,21 @@ export function getModelServicePluginEntry(wire) {
749
893
  export function getModelServicePlugin(wire) {
750
894
  return getModelServicePluginEntry(wire)?.plugin;
751
895
  }
896
+ /** True when the declared methods are only `none` (no key, no web login).
897
+ * Absent stays the legacy key form. */
898
+ export function pluginDeclinesCredentials(plugin) {
899
+ const types = plugin?.authTypes;
900
+ return Array.isArray(types) && types.includes('none') && !types.some((t) => t === 'key' || t === 'webLogin');
901
+ }
902
+ /** True when `providerId` is a preset of a plugin that owns its own login. */
903
+ export function providerDeclinesCredentials(providerId) {
904
+ for (const { plugin, view } of registry.values()) {
905
+ if ((view.presets ?? []).some((preset) => preset.providerId === providerId)) {
906
+ return pluginDeclinesCredentials(plugin);
907
+ }
908
+ }
909
+ return false;
910
+ }
752
911
  /** Manifest id of an uploaded package, read WITHOUT touching disk. The install
753
912
  * route needs it up front to snapshot the version it is about to replace, so a
754
913
  * failed upgrade can be rolled back instead of deleting a working install. */
@@ -801,7 +960,7 @@ export function installPluginPackage(bytes, opts = {}) {
801
960
  // produced "invalid plugin.json: invalid plugin.json: ..." in the console.
802
961
  throw new Error(err instanceof Error ? err.message : String(err));
803
962
  }
804
- assertSupportedPluginApi(manifest.apiVersion);
963
+ assertSupportedPluginApi(manifest);
805
964
  // Ownership refusals come FIRST: a rejected install must not touch a single
806
965
  // plugin artifact. (Clearing the disabled ledger before this point used to
807
966
  // resurrect a tombstoned app-owned package on the next reload.) Both answers
@@ -1019,6 +1178,9 @@ function readRegistrations() {
1019
1178
  ...(entry.written && typeof entry.written === 'object' && !Array.isArray(entry.written)
1020
1179
  ? { written: entry.written }
1021
1180
  : {}),
1181
+ ...(Array.isArray(entry.deleted)
1182
+ ? { deleted: entry.deleted.filter((v) => typeof v === 'string') }
1183
+ : {}),
1022
1184
  };
1023
1185
  }
1024
1186
  return out;
@@ -1042,8 +1204,85 @@ export function pluginProviderOrigins() {
1042
1204
  for (const id of entry.providers)
1043
1205
  out[id] = pluginId;
1044
1206
  }
1207
+ // A deleted preset leaves the ledger, but the connect catalog still lists it.
1208
+ // Keep the plugin id on that row so the origin filter can find it. Only a
1209
+ // package still on disk may claim an origin: uninstall drops the ledger and
1210
+ // artifacts at once while the registry keeps the last views until the
1211
+ // caller's reload, so projecting from the registry alone would tag rows with
1212
+ // a plugin the operator already removed.
1213
+ for (const { view } of registry.values()) {
1214
+ if (!packageStillInstalled(view))
1215
+ continue;
1216
+ for (const preset of view.presets ?? []) {
1217
+ if (!out[preset.providerId])
1218
+ out[preset.providerId] = view.id;
1219
+ }
1220
+ }
1045
1221
  return out;
1046
1222
  }
1223
+ /** Disk truth behind a plugin view: a dev-tree package is operator-owned and
1224
+ * always "installed"; a packaged one counts only while a package artifact or
1225
+ * its unpacked tree is still present. */
1226
+ function packageStillInstalled(view) {
1227
+ if (view.source === 'dev')
1228
+ return true;
1229
+ if (bundledPackagePath(view.id))
1230
+ return true;
1231
+ if (packagePathsIn(pluginsRoot(), view.id).length > 0)
1232
+ return true;
1233
+ return existsSync(join(pluginsRoot(), 'unpacked', view.id));
1234
+ }
1235
+ /** Forget ONE provider id in every preset ledger entry and tombstone it. Called
1236
+ * when the operator DELETES a provider: that is intent, so a later boot/reload
1237
+ * (any plugin's install re-runs registration for ALL plugins) must not
1238
+ * resurrect the preset's def. Clearing the tombstone is an explicit connect —
1239
+ * see `ensurePresetProvider`. A credential still in the store keeps the
1240
+ * provider alive through the boot bind sweep — that is credential truth;
1241
+ * disconnecting is the purge path, not the delete path. */
1242
+ export function forgetProviderRegistration(providerId) {
1243
+ const ledger = readRegistrations();
1244
+ let changed = false;
1245
+ for (const [id, entry] of Object.entries(ledger)) {
1246
+ if (!entry.providers.includes(providerId) && !entry.written?.[providerId])
1247
+ continue;
1248
+ const providers = entry.providers.filter((p) => p !== providerId);
1249
+ const written = entry.written ? { ...entry.written } : undefined;
1250
+ if (written)
1251
+ delete written[providerId];
1252
+ const deleted = [...new Set([...(entry.deleted ?? []), providerId])];
1253
+ ledger[id] = {
1254
+ providers,
1255
+ ...(written && Object.keys(written).length > 0 ? { written } : {}),
1256
+ deleted,
1257
+ };
1258
+ changed = true;
1259
+ }
1260
+ if (changed)
1261
+ writeRegistrations(ledger);
1262
+ }
1263
+ /** Lift every deletion tombstone for one provider id (explicit connect intent). */
1264
+ function clearProviderDeletion(providerId) {
1265
+ const ledger = readRegistrations();
1266
+ let changed = false;
1267
+ for (const [id, entry] of Object.entries(ledger)) {
1268
+ if (!entry.deleted?.includes(providerId))
1269
+ continue;
1270
+ const deleted = entry.deleted.filter((p) => p !== providerId);
1271
+ if (entry.providers.length === 0 && Object.keys(entry.written ?? {}).length === 0 && deleted.length === 0) {
1272
+ delete ledger[id];
1273
+ }
1274
+ else {
1275
+ ledger[id] = {
1276
+ providers: entry.providers,
1277
+ ...(entry.written && Object.keys(entry.written).length > 0 ? { written: entry.written } : {}),
1278
+ ...(deleted.length > 0 ? { deleted } : {}),
1279
+ };
1280
+ }
1281
+ changed = true;
1282
+ }
1283
+ if (changed)
1284
+ writeRegistrations(ledger);
1285
+ }
1047
1286
  /** True when the def currently on disk is byte-for-byte what the plugin wrote
1048
1287
  * (no operator edit since). `snapshot === undefined` means the ledger predates
1049
1288
  * snapshots, so the caller falls back to the heuristic below. */
@@ -1068,16 +1307,64 @@ function isMeaningfulDef(raw) {
1068
1307
  return value !== undefined && value !== null && value !== '' && !(typeof value === 'object' && Object.keys(value).length === 0);
1069
1308
  }));
1070
1309
  }
1310
+ /** The wire a RAW defs-file node currently resolves to — the same precedence
1311
+ * the console probe and the web-login resolver use (`wireFor(npm)` first,
1312
+ * baseURL fingerprint only when no package is declared). */
1313
+ function defWireOf(raw) {
1314
+ const pkg = typeof raw.package === 'string' ? raw.package : typeof raw.npm === 'string' ? raw.npm : '';
1315
+ if (pkg)
1316
+ return wireFor(pkg);
1317
+ const settings = raw.settings && typeof raw.settings === 'object' ? raw.settings : {};
1318
+ const options = raw.options && typeof raw.options === 'object' ? raw.options : {};
1319
+ const base = (settings.baseURL ?? options.baseURL ?? raw.baseURL ?? '');
1320
+ return base ? wireFor(undefined, base) : 'unroutable';
1321
+ }
1322
+ /** A preset def that exists but can never reach ANY executor: the current
1323
+ * spelling resolves to `unroutable` (wireFor refuses it rather than guessing —
1324
+ * e.g. an older plugin generation's `@opencode/ai/providers/<vendor>`). That
1325
+ * is unreachable state, not operator intent, so the preset's declared wire
1326
+ * wins. A def on a routable wire is left alone (an operator may deliberately
1327
+ * point the preset id at a compatible endpoint), and a retired NODE shape
1328
+ * belongs to the defs import, not here. */
1329
+ function presetWireIsBroken(raw) {
1330
+ if (raw.npm !== undefined || raw.options !== undefined)
1331
+ return false; // v1 node shape: the import owns it
1332
+ return defWireOf(raw) === 'unroutable';
1333
+ }
1334
+ /** Rewrite ONLY the routing slot of a broken preset def. Every other slot the
1335
+ * operator owns (name, baseURL/settings, headers, env, body, models) rides
1336
+ * through untouched — the def could not have routed anywhere before, so no
1337
+ * working configuration is lost. */
1338
+ function repairPresetWire(raw, presetWire) {
1339
+ const next = { ...raw, package: presetWire };
1340
+ delete next.npm;
1341
+ return next;
1342
+ }
1343
+ /** Def name a preset registers: the manifest's `displayName` (plain string) or
1344
+ * its en-US entry, first-locale as the last resort. ONE spelling for every
1345
+ * writer of a preset def (sync, ensure-on-connect). */
1346
+ function presetDefName(preset) {
1347
+ const dn = preset.displayName;
1348
+ return typeof dn === 'string' ? dn : (dn['en-US'] ?? Object.values(dn)[0] ?? preset.providerId);
1349
+ }
1071
1350
  /** Register every not-yet-defined preset of every loaded plugin, and RETIRE the
1072
1351
  * ones the plugin no longer declares. A preset is skipped whenever the defs
1073
- * file already holds ANY node with that id — even a bare New-custom stub — so
1074
- * presets never take over operator file state. Retirement uses the same drift
1075
- * rule as uninstall: a def still identical to what the plugin wrote is ours to
1076
- * delete; one the operator edited stays, it just stops being claimed.
1077
- * Returns the created provider ids (for boot/reload logging). */
1352
+ * file already holds a MEANINGFUL node with that id, so presets never take
1353
+ * over operator file state; a bare package-only stub (the New-custom form or
1354
+ * the boot bind sweep's node — machine-written, no operator content) is fair
1355
+ * game and the preset overwrites it. The ONE exception is an unroutable wire
1356
+ * spelling (an older plugin generation's SDK package, e.g.
1357
+ * `@opencode/ai/providers/<vendor>`): that def can never execute, so the
1358
+ * preset rewrites the routing slot alone and keeps the rest — otherwise a
1359
+ * reload would report success while the provider stays dead
1360
+ * (`provider '…' is not on a plugin wire with a web-login capability`).
1361
+ * Retirement uses the same drift rule as uninstall: a def still identical to
1362
+ * what the plugin wrote is ours to delete; one the operator edited stays, it
1363
+ * just stops being claimed.
1364
+ * Returns the provider ids registered or wire-repaired (boot/reload logging). */
1078
1365
  export async function syncPluginPresets() {
1079
1366
  const { upsertProviderDef, deleteProviderDef } = await import('../opencode/user-config.js');
1080
- const { readProviderDefsFile } = await import('../opencode/provider-defs.js');
1367
+ const { readProviderDefsFile, writeProviderDefs } = await import('../opencode/provider-defs.js');
1081
1368
  const created = [];
1082
1369
  const ledger = readRegistrations();
1083
1370
  for (const { view } of registry.values()) {
@@ -1098,27 +1385,62 @@ export async function syncPluginPresets() {
1098
1385
  }
1099
1386
  const mine = new Set();
1100
1387
  const written = {};
1388
+ // Tombstones this entry keeps after the pass (an id whose def reappeared is
1389
+ // connect intent and loses its tombstone below).
1390
+ const deleted = new Set(entry.deleted ?? []);
1101
1391
  for (const preset of view.presets ?? []) {
1392
+ const presetWire = currentProtocol(preset.protocol || preset.npm);
1393
+ // A manifest protocol must be an OCR protocol id (ADR-0033: one protocol
1394
+ // vocabulary, never an SDK package): a core wire, or a wire some LOADED
1395
+ // plugin claims. Anything else — an SDK package from an older plugin
1396
+ // build, a typo — would be written as a def that can never
1397
+ // route (`wireFor` → `unroutable`), so refuse it at the write boundary and
1398
+ // name the offender instead of poisoning providers.json.
1399
+ if (!isCoreWire(presetWire) && !isPluginWire(presetWire)) {
1400
+ console.warn(`[OCR] plugins: preset '${preset.providerId}' of ${view.id} declares protocol '${preset.protocol ?? preset.npm}' which is not an OCR protocol id — skipped`);
1401
+ continue;
1402
+ }
1102
1403
  const raw = readProviderDefsFile()?.providers?.[preset.providerId];
1404
+ if (deleted.has(preset.providerId)) {
1405
+ // The operator deleted this provider: never resurrect it. A def that is
1406
+ // BACK on disk means the operator connected it again (or re-created it
1407
+ // by hand) — that clears the tombstone and the normal rules apply.
1408
+ if (!raw)
1409
+ continue;
1410
+ deleted.delete(preset.providerId);
1411
+ }
1103
1412
  if (raw) {
1104
- // Pre-existing def with the same id: never overwritten (ADR-0010).
1105
- // A def WE wrote earlier keeps its snapshot (so uninstall can still
1106
- // tell it apart from an operator edit); any other def only joins the
1107
- // ledger when MEANINGFUL, and then has no snapshot — so uninstall
1108
- // leaves it alone (isMeaningfulDef fallback).
1413
+ // Pre-existing def with the same id: a def WE wrote earlier keeps its
1414
+ // snapshot (so uninstall can still tell it apart from an operator
1415
+ // edit); a MEANINGFUL def is operator-owned and never overwritten —
1416
+ // it only joins the ledger, so uninstall leaves it alone. A BARE
1417
+ // stub (isMeaningfulDef === false) is machine residue, not operator
1418
+ // state: fall through and let the preset take the id over.
1419
+ if (presetWireIsBroken(raw)) {
1420
+ const repaired = repairPresetWire(raw, presetWire);
1421
+ const providers = { ...(readProviderDefsFile()?.providers ?? {}) };
1422
+ providers[preset.providerId] = repaired;
1423
+ writeProviderDefs(providers);
1424
+ mine.add(preset.providerId);
1425
+ written[preset.providerId] = repaired;
1426
+ created.push(preset.providerId);
1427
+ console.warn(`[OCR] plugins: repaired provider '${preset.providerId}' (plugin ${view.id}) — wire '${defWireOf(raw)}' -> '${presetWire}'`);
1428
+ continue;
1429
+ }
1109
1430
  if (entry.written?.[preset.providerId] !== undefined) {
1110
1431
  mine.add(preset.providerId);
1111
1432
  written[preset.providerId] = entry.written[preset.providerId];
1433
+ continue;
1112
1434
  }
1113
- else if (isMeaningfulDef(raw)) {
1435
+ if (isMeaningfulDef(raw)) {
1114
1436
  mine.add(preset.providerId);
1437
+ continue;
1115
1438
  }
1116
- continue;
1117
1439
  }
1118
1440
  const result = upsertProviderDef({
1119
1441
  id: preset.providerId,
1120
- name: typeof preset.displayName === 'string' ? preset.displayName : (preset.displayName['en-US'] ?? Object.values(preset.displayName)[0]),
1121
- npm: currentProtocol(preset.protocol || preset.npm),
1442
+ name: presetDefName(preset),
1443
+ npm: presetWire,
1122
1444
  baseURL: preset.baseUrl,
1123
1445
  });
1124
1446
  if (result.success) {
@@ -1134,12 +1456,73 @@ export async function syncPluginPresets() {
1134
1456
  console.warn(`[OCR] plugins: preset '${preset.providerId}' of ${view.id} failed to register: ${result.error}`);
1135
1457
  }
1136
1458
  }
1137
- if (mine.size > 0)
1138
- ledger[view.id] = { providers: [...mine], ...(Object.keys(written).length > 0 ? { written } : {}) };
1459
+ if (mine.size > 0 || deleted.size > 0) {
1460
+ ledger[view.id] = {
1461
+ providers: [...mine],
1462
+ ...(Object.keys(written).length > 0 ? { written } : {}),
1463
+ ...(deleted.size > 0 ? { deleted: [...deleted] } : {}),
1464
+ };
1465
+ }
1466
+ }
1467
+ // Orphan ledger rows: a package RENAMED between releases leaves its old id's
1468
+ // entry behind (this loop only iterates loaded ids, uninstall only deletes its
1469
+ // own key), so that row could never be read again — drop it. A DISABLED or
1470
+ // failed package keeps its row: uninstall still needs it to remove the defs.
1471
+ // Gated on a load that SAW plugins: an unreadable/empty root is not proof that
1472
+ // every ledger row is stale.
1473
+ if (hostInitialized && lastViews.length + disabledViews.length > 0) {
1474
+ const known = new Set([...lastViews, ...disabledViews].map((v) => v.id));
1475
+ for (const id of Object.keys(ledger))
1476
+ if (!known.has(id))
1477
+ delete ledger[id];
1139
1478
  }
1140
1479
  writeRegistrations(ledger);
1141
1480
  return created;
1142
1481
  }
1482
+ /** Operator CONNECT INTENT for a preset provider (the console's web-login
1483
+ * button): lift the deletion tombstone and materialize the def when it is
1484
+ * missing. Without this a provider the operator once deleted keeps advertising
1485
+ * its login button (the row comes from the manifest) while every route answers
1486
+ * `provider '…' not found`. Returns true when a def is on disk afterwards. */
1487
+ export async function ensurePresetProvider(providerId) {
1488
+ for (const { view } of registry.values()) {
1489
+ const preset = (view.presets ?? []).find((p) => p.providerId === providerId);
1490
+ if (!preset)
1491
+ continue;
1492
+ // Same write-boundary rule as registration: a manifest that still declares
1493
+ // an SDK package must never materialize a def the core cannot route.
1494
+ const presetWire = currentProtocol(preset.protocol || preset.npm);
1495
+ if (!isCoreWire(presetWire) && !isPluginWire(presetWire)) {
1496
+ console.warn(`[OCR] plugins: preset '${preset.providerId}' of ${view.id} cannot be materialized — protocol '${preset.protocol ?? preset.npm}' is not an OCR protocol id`);
1497
+ return false;
1498
+ }
1499
+ clearProviderDeletion(providerId);
1500
+ const { readProviderDefsFile } = await import('../opencode/provider-defs.js');
1501
+ if (readProviderDefsFile()?.providers?.[providerId])
1502
+ return true;
1503
+ const { upsertProviderDef } = await import('../opencode/user-config.js');
1504
+ return upsertProviderDef({
1505
+ id: preset.providerId,
1506
+ name: presetDefName(preset),
1507
+ npm: presetWire,
1508
+ baseURL: preset.baseUrl,
1509
+ }).success;
1510
+ }
1511
+ return false;
1512
+ }
1513
+ /** True when `wire` still has an executor once plugin `excludeId` is gone:
1514
+ * core wires execute in-process, every other wire needs a loaded plugin that
1515
+ * claims it (the OCR-native identity floor does NOT count — an absent plugin
1516
+ * has no executor either way). */
1517
+ function wireSurvivesWithout(wire, excludeId) {
1518
+ if (isCoreWire(wire))
1519
+ return true;
1520
+ for (const { view } of registry.values()) {
1521
+ if (view.id !== excludeId && view.wires.includes(wire))
1522
+ return true;
1523
+ }
1524
+ return false;
1525
+ }
1143
1526
  /** Remove the provider defs a plugin auto-registered (hot-unplug half). */
1144
1527
  async function removePluginRegistrations(id) {
1145
1528
  const { deleteProviderDef } = await import('../opencode/user-config.js');
@@ -1149,13 +1532,24 @@ async function removePluginRegistrations(id) {
1149
1532
  const removed = [];
1150
1533
  for (const pid of entry?.providers ?? []) {
1151
1534
  const current = readProviderDefsFile()?.providers?.[pid];
1152
- // Operator-owned now (keyed models, rename, own baseURL) — uninstall must
1153
- // not destroy it. Decided by DRIFT from what the plugin wrote: an exact
1154
- // match is ours to remove. A def with no snapshot predates this ledger
1155
- // (legacy `string[]`), so the old heuristic decides for it.
1156
- const ours = entry?.written?.[pid] !== undefined ? matchesRegistration(entry.written[pid], current) : !isMeaningfulDef(current);
1157
- if (!ours)
1535
+ if (!current)
1158
1536
  continue;
1537
+ // A def whose wire has NO executor once this plugin is gone is dead state,
1538
+ // not operator content: delete it even when the node drifted (auto-pulled
1539
+ // models, headers) — otherwise every connected preset provider outlives the
1540
+ // plugin and lingers on the Connected surface forever. A def the operator
1541
+ // repointed to a routable wire still works without this plugin and stays.
1542
+ const currentWire = defWireOf(current);
1543
+ const dead = currentWire === 'unroutable' || !wireSurvivesWithout(currentWire, id);
1544
+ if (!dead) {
1545
+ // Operator-owned now (keyed models, rename, own baseURL) — uninstall must
1546
+ // not destroy it. Decided by DRIFT from what the plugin wrote: an exact
1547
+ // match is ours to remove. A def with no snapshot predates this ledger
1548
+ // (legacy `string[]`), so the old heuristic decides for it.
1549
+ const ours = entry?.written?.[pid] !== undefined ? matchesRegistration(entry.written[pid], current) : !isMeaningfulDef(current);
1550
+ if (!ours)
1551
+ continue;
1552
+ }
1159
1553
  const result = deleteProviderDef(pid);
1160
1554
  if (result.success)
1161
1555
  removed.push(pid);
@@ -1186,7 +1580,9 @@ const LANG_TO_BCP47 = {
1186
1580
  * fallback. */
1187
1581
  export async function pluginPresetCatalogEntries(lang) {
1188
1582
  const { getCredentialStore } = await import('../opencode/credentials/index.js');
1583
+ const { readProviderDefsFile } = await import('../opencode/provider-defs.js');
1189
1584
  const store = await getCredentialStore();
1585
+ const defs = readProviderDefsFile()?.providers ?? {};
1190
1586
  const out = [];
1191
1587
  for (const { plugin, view } of registry.values()) {
1192
1588
  const logoUrl = view.logo ? `/api/admin/plugins/${view.id}/logo` : undefined;
@@ -1208,7 +1604,12 @@ export async function pluginPresetCatalogEntries(lang) {
1208
1604
  npm: currentProtocol(preset.protocol || preset.npm),
1209
1605
  baseURL: preset.baseUrl,
1210
1606
  custom: true,
1211
- connected: Boolean(store.resolveKey(preset.providerId)?.key),
1607
+ // A plugin that owns login is connected when its def exists. A stored
1608
+ // key is not an account for it, and a missing key must not keep the
1609
+ // card on the connect form.
1610
+ connected: pluginDeclinesCredentials(plugin)
1611
+ ? Boolean(defs[preset.providerId])
1612
+ : Boolean(store.resolveKey(preset.providerId)?.key),
1212
1613
  // Console connect card offers the web-authorization button when the
1213
1614
  // plugin declares the capability (vendor knowledge stays in-plugin).
1214
1615
  webLogin: typeof plugin.webLogin === 'object',
@@ -1226,7 +1627,13 @@ export async function pluginPresetCatalogEntries(lang) {
1226
1627
  export function pluginLogoFile(id) {
1227
1628
  if (!isValidPluginId(id))
1228
1629
  return undefined;
1229
- for (const { view } of registry.values()) {
1630
+ // Resolve over the LISTED VIEWS, not the provider registry: the registry holds
1631
+ // only packages with a model-service half, so a pure client-gateway package —
1632
+ // the rows that declare a brand mark most often — 404'd on its own manifest
1633
+ // field. A logo is a static asset of the package, not a capability of the live
1634
+ // host, so every row the console renders (loaded, disabled or refused) serves
1635
+ // the mark it advertises.
1636
+ for (const view of listInstalledPlugins()) {
1230
1637
  if (view.id !== id)
1231
1638
  continue;
1232
1639
  const rel = view.logo;
@@ -1298,7 +1705,16 @@ export async function applyPluginConfig(id, values) {
1298
1705
  if (!manifest.configSchema?.length)
1299
1706
  throw new Error('plugin declares no configurable fields');
1300
1707
  const result = writePluginConfig(id, manifest.configSchema, values);
1301
- const target = getGatewayById(id) ?? [...registry.values()].find((r) => r.view.id === id)?.plugin;
1708
+ // The leg switch is the one config value CORE consumes rather than forwards:
1709
+ // replacing the registry tier makes the operator's pick authoritative from the
1710
+ // NEXT request to a claimed host, with no restart and no package rebuild for a
1711
+ // value that lives in a JSON file. It runs before `onConfigChange` so a plugin
1712
+ // that warms its transports in that hook does so under the leg the operator
1713
+ // just chose.
1714
+ const gateway = getGatewayById(id);
1715
+ if (gateway)
1716
+ setGatewayOperatorEgress(id, operatorEgressChoice(result.values));
1717
+ const target = gateway ?? [...registry.values()].find((r) => r.view.id === id)?.plugin;
1302
1718
  try {
1303
1719
  await target?.onConfigChange?.(result.values);
1304
1720
  }