@hasna/switcher 0.1.9 → 0.2.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.
package/README.md CHANGED
@@ -95,6 +95,20 @@ on-request approvals. These are startup defaults; the app's own permission
95
95
  controls and managed requirements still apply. Start a new conversation after
96
96
  changing launch defaults; existing conversations can retain their own settings.
97
97
 
98
+ Browser and Computer Use are local app tools, separate from the inference
99
+ provider. Switcher preserves the app's sandbox-helper arguments so
100
+ the installed tool runtime can start. Enable the app's browser/computer plugins
101
+ and the browser extension in the desired profile; website permissions, macOS
102
+ Accessibility/Screen Recording permissions, workspace policy and model
103
+ eligibility still apply. Full access does not override those controls.
104
+
105
+ Models need function calling; screenshot workflows also need image input.
106
+ DeepSeek's Responses API supports both for `deepseek-flash`, but ignores OpenAI's
107
+ built-in `computer_use` tool. The desktop's local MCP tools are a separate path.
108
+ Successful inference does not establish browser or computer compatibility for
109
+ every provider. See the [browser extension guide](https://learn.chatgpt.com/docs/chrome-extension)
110
+ and [DeepSeek compatibility details](https://api-docs.deepseek.com/guides/responses_api/).
111
+
98
112
  Switcher starts a separate app instance with persistent provider/model state
99
113
  under `~/.hasna/switcher/state/desktop/PROFILE`. Your regular ChatGPT app and its
100
114
  signed-in state are preserved. Each profile retains its own local conversations
@@ -121,6 +135,11 @@ It verifies selected-model configuration, direct responses, delegated task
121
135
  creation, follow-up delivery, and history replay against the real provider.
122
136
  It is separate from visual desktop acceptance.
123
137
 
138
+ `test:native-chatgpt-tools` checks the installed browser/computer tool kernel
139
+ through the generated launcher without provider calls or UI actions. Set
140
+ `SWITCHER_TEST_CUA_CONFIG` to the installed unified-computer-use plugin's
141
+ `.mcp.json`; the check uses disposable state and leaves that configuration intact.
142
+
124
143
  References: [OpenAI custom provider configuration](https://learn.chatgpt.com/docs/config-file/config-advanced),
125
144
  [community desktop custom-model profiles](https://github.com/ademisler/codex-desktop-custom-models),
126
145
  [reported signed-in provider routing issue](https://github.com/openai/codex/issues/37245),
@@ -129,6 +148,12 @@ and [DeepSeek thinking controls](https://api-docs.deepseek.com/guides/thinking_m
129
148
 
130
149
  ## Claude desktop with a provider
131
150
 
151
+ Claude Code's official Chrome integration requires direct Anthropic sign-in;
152
+ API-key and third-party-provider sessions cannot use it. Routing Claude desktop
153
+ inference through Switcher does not remove that restriction. A separately
154
+ configured, provider-compatible browser MCP server is another integration path.
155
+ See [Anthropic's Chrome prerequisites](https://code.claude.com/docs/en/chrome#prerequisites).
156
+
132
157
  ```sh
133
158
  switcher launch claude-desktop --provider deepseek --model deepseek-flash
134
159
  switcher launch claude-desktop --provider my-messages-provider --model vendor/model
@@ -143,7 +168,8 @@ launching the terminal CLI. `detectClaudeDesktopApp()` is available in the SDK.
143
168
  The provider must implement Anthropic Messages, including streaming and tool
144
169
  calling for the chosen model. DeepSeek and compatible gateway presets select
145
170
  the Messages endpoint automatically. Saved provider IDs retain their explicit
146
- protocol. Switcher does not convert Chat Completions or Responses into Messages.
171
+ protocol. OpenCode Zen and Go additionally use the Claude translation adapter
172
+ described below for models served on another native wire.
147
173
  A configured provider works in both desktop apps when it offers both required
148
174
  APIs; a preset's existence is not proof that every model supports every feature.
149
175
 
@@ -200,11 +226,64 @@ switcher launch codex --provider openrouter --model anthropic/claude-sonnet-4.6
200
226
 
201
227
  An interactive terminal can choose or search the catalog when `--model` is omitted. Noninteractive launches require an explicit model. `--dry-run` resolves and saves the provider/profile and fresh catalog, then prints the launch plan without starting the harness or creating a run record. Existing `switcher launch PROFILE` commands remain supported. Direct launches create or reuse records without overwriting customized providers or profiles.
202
228
 
203
- When no remote API configuration is present, each CLI invocation starts an authenticated loopback API on an allocated port, stores SQLite data in `~/.hasna/switcher`, and closes its own listener on completion. Its random operator key remains in memory. Use `HASNA_SWITCHER_HOME` to choose another owner-only home, `HASNA_SWITCHER_SQLITE_PATH` for an explicit database, or `HASNA_SWITCHER_DATABASE_URL` for PostgreSQL. API and SDK data access remains HTTP.
229
+ With no Switcher API credential configured, the CLI and `switcher-mcp` exit non-zero and name the sources they consulted (Keychain item `hasna.credentials.switcher.api-key`, `~/.hasna/switcher/config/credentials`, `HASNA_SWITCHER_API_KEY`); they never open local data by default. Set `HASNA_SWITCHER_LOCAL=1` (alias `SWITCHER_LOCAL=1`) to deliberately run on the box: each invocation then starts an authenticated loopback API on an allocated port, stores SQLite data in `~/.hasna/switcher`, prints one `switcher: LOCAL mode` line on stderr, and closes its own listener on completion. Its random operator key remains in memory. Under that opt-in, use `HASNA_SWITCHER_HOME` to choose another owner-only home, `HASNA_SWITCHER_SQLITE_PATH` for an explicit database, or `HASNA_SWITCHER_DATABASE_URL` for PostgreSQL. A configured API URL or key outranks the flag. API and SDK data access remains HTTP.
204
230
 
205
231
  Remote API configuration is resolved through Contracts, including canonical credential stores and the default gateway URL. Invalid, unavailable or unauthorized remote services fail without opening local SQLite.
206
232
 
207
- The registry contains DeepSeek, OpenRouter, Anthropic, OpenAI, xAI, Ollama, LM Studio, Groq, Cerebras, Mistral, Together AI, Fireworks, Moonshot/Kimi, DashScope, Z.AI, MiniMax, SiliconFlow, and generic protocol entries. `switcher providers presets ID` exposes documented routes, aliases and limitations; this is not a claim that every combination has passed live tests. Remaining adapters and acceptance gates are tracked in [TODOS.md](TODOS.md).
233
+ The registry contains DeepSeek, OpenCode Zen, OpenCode Go, OpenRouter, Anthropic, OpenAI, xAI, Ollama, LM Studio, Groq, Cerebras, Mistral, Together AI, Fireworks, Moonshot/Kimi, DashScope, Z.AI, MiniMax, SiliconFlow, and generic protocol entries. `switcher providers presets ID` exposes documented routes, aliases and limitations; this is not a claim that every combination has passed live tests. Remaining adapters and acceptance gates are tracked in [TODOS.md](TODOS.md).
234
+
235
+ ### OpenCode and OpenRouter providers
236
+
237
+ From 0.2.1, `opencode` selects OpenCode Zen and `opencode-go` selects its Go
238
+ subscription. Both discover their complete live `/models` catalogs. Supply
239
+ `OPENCODE_API_KEY` through environment injection or bind each preset to your
240
+ existing vault/keychain reference. Go requires an active Go subscription.
241
+ `SWITCHER_PROVIDER_OPENCODE` and `SWITCHER_PROVIDER_OPENCODE_GO` can bind
242
+ different accounts explicitly. OpenRouter uses `OPENROUTER_API_KEY` or its
243
+ `SWITCHER_PROVIDER_OPENROUTER` binding.
244
+
245
+ ```sh
246
+ switcher models opencode --limit 1000
247
+ switcher models opencode-go --limit 1000
248
+ switcher models openrouter --limit 1000
249
+ switcher launch claude --provider opencode --model big-pickle
250
+ switcher launch claude --provider opencode-go --model kimi-k3
251
+ switcher launch claude --provider openrouter --model deepseek/deepseek-v4-flash
252
+ ```
253
+
254
+ Use the exact API model ID from the catalog. OpenCode IDs are unprefixed;
255
+ OpenRouter IDs include their provider prefix. `--limit` controls the displayed
256
+ page, and `--offset` accesses subsequent pages. The stored catalog includes all
257
+ pages and modalities; coding selections exclude models explicitly lacking text
258
+ output or tools. OpenRouter's declared reasoning efforts are retained.
259
+
260
+ Claude Code and `claude-desktop` speak Messages to Switcher. For OpenCode,
261
+ Switcher forwards Claude/Qwen Messages requests natively, uses Messages for
262
+ Go's MiniMax models, and translates the other documented model families to
263
+ Chat Completions, Responses, or Gemini generateContent. Translation preserves
264
+ streaming text, tool arguments/results, images, reasoning text, and token usage.
265
+ It keeps Gemini tool signatures within the current launch. Restarting a launch
266
+ does not restore that transient signature cache, so start a fresh conversation
267
+ for Gemini tool workflows. Token counting on translated routes and provider
268
+ server tools are rejected explicitly; model capabilities and entitlements still
269
+ apply. Other harnesses use the preset's selected native protocol and require a
270
+ model compatible with it. OpenRouter provides its own Messages translation.
271
+
272
+ OpenCode inference receives Switcher's own user agent and a stable conversation
273
+ identifier. Native session headers are preserved from an explicit allowlist;
274
+ Claude's session metadata is used when available, with a per-launch fallback.
275
+ Credential and session handling is scoped to the exact OpenCode service URLs.
276
+
277
+ `bun run test:native-claude-providers` uses installed Claude Code with controlled
278
+ upstream fixtures and verifies actual file reads through Chat Completions,
279
+ Responses, Gemini, Go Messages, and OpenRouter Messages. This is separate from
280
+ paid-provider acceptance. Development live checks discovered all three catalogs
281
+ and received answers from OpenCode's free Chat endpoint; the saved paid keys
282
+ were rejected and the free endpoint subsequently rate-limited native testing.
283
+
284
+ Sources: [OpenCode Zen](https://opencode.ai/docs/zen/),
285
+ [OpenCode Go](https://opencode.ai/docs/go/), and
286
+ [OpenRouter Claude Code integration](https://openrouter.ai/docs/cookbook/coding-agents/claude-code-integration).
208
287
 
209
288
  ## Canonical API configuration
210
289
 
@@ -214,7 +293,7 @@ The canonical file is `~/.hasna/switcher/config/credentials` (owner-only mode 06
214
293
 
215
294
  `HASNA_HOME` replaces `~/.hasna`; `HASNA_CONFIG_HOME` places credentials at `<root>/switcher/credentials` and `<root>/secrets/credentials`. These shared overrides must be absolute and nonblank. `HASNA_PROFILE` selects `credentials-<profile>`; API authority stays in the common credentials file. `HASNA_SWITCHER_HOME` changes Switcher's local database, bindings and launch state only, and does not relocate shared credentials. `HOME` is respected by both paths.
216
295
 
217
- Configured but missing, unsafe, conflicting or inaccessible remote credentials fail before local data is opened. Only complete absence of Switcher remote configuration retains the user-authorized automatic local API. The owned local API uses a random in-memory key. Server-side authentication remains configured separately through `HASNA_SWITCHER_API_KEY` on `switcher-serve`.
296
+ Configured but missing, unsafe, conflicting or inaccessible remote credentials fail before local data is opened, and a Keychain item that exists but cannot be read is a terminal error, never treated as absent. Complete absence of Switcher remote configuration also fails closed; the owned local API is reachable only through `HASNA_SWITCHER_LOCAL=1` and uses a random in-memory key. Server-side authentication remains configured separately through `HASNA_SWITCHER_API_KEY` on `switcher-serve`.
218
297
 
219
298
  ## Credential bindings
220
299
 
@@ -464,7 +543,7 @@ switcher providers add catalog-provider --url https://inference.example/v1 --pro
464
543
 
465
544
  For advanced provider settings, use `providers add ID --file provider.json` with `manualModels` when discovery is unavailable. Each model needs `id` and `name`; optional fields are `contextWindow`, `maxOutputTokens`, `inputModalities`, `outputModalities`, `supportedParameters`, and `available`. Use `catalogBaseUrl` and `modelsPath` for a separate discovery root/path; CLI equivalents are `--catalog-url` and `--models-path`. Use `catalogFormat: "ollama"` for `/api/tags`. Mistral presets select a capability-aware parser, including archived status. Together presets select its native bare-array parser. Fireworks requires `--catalog-account-id ID` or an explicit catalog URL and retains count evidence across its paginated account catalog. DashScope requires an explicit region/workspace `--catalog-url` with `--catalog-format dashscope`. Z.AI currently requires an explicit catalog or manual models because its documented API has no model-list contract. MiniMax defaults to its `.cn` Open Platform endpoints; use an explicit authority and credential reference for another product or region. A different authenticated catalog origin requires an explicit `catalogCredentialEnv`; a public catalog can declare `catalogAuthStyle: "none"`. Standard credential aliases are resolved only for the matching built-in provider origin. The default parser follows Anthropic-style `has_more/last_id` pagination and otherwise expects an OpenAI-style `data` array. HTTP redirects are rejected.
466
545
 
467
- Grok uses a per-launch authenticated loopback bridge because its environment overlay cannot define providers. The bridge serves model metadata and forwards the selected protocol unchanged. It holds upstream credentials only in memory; Grok receives an ephemeral local token. The same bridge handles credentialless endpoints and OpenCode auth-header mismatches. Bridged requests are limited to 4 MiB and four minutes. Grok resumes retain the selected profile model. Use `-- --resume SESSION_ID -p PROMPT` for headless continuation, or omit the prompt and type after the interactive session loads. Interactive resume with an inline positional prompt is rejected because the native client can send it before applying the selected model. Grok 1.0.13 passed source and installed development CLI resume checks against a controlled Messages fixture and live DeepSeek Flash. OpenCode's provider identity stays stable across temporary bridge ports; `-- run --session SESSION_ID PROMPT` resumes with fresh launch settings. The installed beta-19157 passed two-process Messages resume checks against a controlled local upstream and live DeepSeek Flash, including a proof-file read and preserved history. Other provider/protocol and registry-release cells remain tracked separately in COMPATIBILITY.md.
546
+ Grok uses a per-launch authenticated loopback bridge because its environment overlay cannot define providers. The bridge serves model metadata and forwards the selected protocol unchanged. It holds upstream credentials only in memory; Grok receives an ephemeral local token. The same bridge handles credentialless endpoints and OpenCode auth-header mismatches. Bridged requests are limited to 4 MiB. Inference bridges allow long responses while bytes continue arriving, including SSE keepalive comments. A four-minute inactivity watchdog bounds the wait for upstream headers and each response read; time spent waiting for a slow native client to consume buffered bytes does not count as provider inactivity. Idle failures report `provider_idle_timeout` in routing evidence and a sanitized timeout message. Caller cancellation still releases the request, and partial responses are never replayed. Grok resumes retain the selected profile model. Use `-- --resume SESSION_ID -p PROMPT` for headless continuation, or omit the prompt and type after the interactive session loads. Interactive resume with an inline positional prompt is rejected because the native client can send it before applying the selected model. Grok 1.0.13 passed source and installed development CLI resume checks against a controlled Messages fixture and live DeepSeek Flash. OpenCode's provider identity stays stable across temporary bridge ports; `-- run --session SESSION_ID PROMPT` resumes with fresh launch settings. The installed beta-19157 passed two-process Messages resume checks against a controlled local upstream and live DeepSeek Flash, including a proof-file read and preserved history. Other provider/protocol and registry-release cells remain tracked separately in COMPATIBILITY.md.
468
547
 
469
548
  Hermes uses the same loopback boundary with its documented `custom` provider. The bridge exposes only the Switcher catalog, translates the selected provider's Bearer, `x-api-key` or literal `api-key` credential, and forwards deployment prefixes unchanged. Hermes `state.db` and `sessions/` are linked to a profile-owned stable directory for resume; generated config and bridge credentials remain per-launch. Focused bridge tests cover all three native protocol routes and auth styles, including cleanup of an active stream without caller cancellation. Run `bun scripts/test-native-hermes.ts` with `SWITCHER_TEST_HERMES_EXECUTABLE` for the installed native CLI fixture proof, which performs a real `read_file` loop and deleted-file resume against a generic preset.
470
549