@hasna/switcher 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -47,6 +47,164 @@ switcher --help
47
47
  switcher doctor
48
48
  ```
49
49
 
50
+ ## ChatGPT desktop with a provider
51
+
52
+ From 0.1.9, use the installed macOS ChatGPT app with a selected provider and model:
53
+
54
+ ```sh
55
+ switcher launch chatgpt --provider deepseek --model deepseek-flash
56
+ switcher launch chatgpt --provider openrouter --model anthropic/claude-sonnet-4.6
57
+ switcher launch chatgpt --provider my-provider --model my-model
58
+ switcher launch chatgpt --provider deepseek --model deepseek-flash --dry-run
59
+ switcher launch chatgpt --provider deepseek --model deepseek-flash --reasoning max \
60
+ --dangerously-bypass-approvals-and-sandbox
61
+ ```
62
+
63
+ This runs **local Codex conversations inside the unified ChatGPT app** through
64
+ Switcher's provider gateway. ChatGPT cloud Chat/Work, Preview Edit and other
65
+ account-only features use their own service and are outside this routing path.
66
+ The classic ChatGPT app (`com.openai.chat`) cannot use this launcher. The current
67
+ unified ChatGPT app and its former Codex name (`com.openai.codex`) are supported;
68
+ the bundled Codex runtime must meet the Codex CLI minimum above.
69
+
70
+ Providers must support the Responses protocol and the selected model's tool
71
+ calling. DeepSeek, OpenRouter, OpenAI and other Responses-compatible presets
72
+ use the same provider/model catalog and credential bindings as terminal Codex.
73
+ Use `switcher models PROVIDER` to find exact model IDs. Custom providers can be
74
+ registered with `switcher providers add NAME --url URL --protocol openai-responses`.
75
+ There is no automatic conversion from Chat Completions or Anthropic Messages.
76
+
77
+ For third-party Responses endpoints, Switcher converts the desktop's unpaired
78
+ `codex_app` task-message outputs to ordinary user input, preserving their full
79
+ text and images. This supports creating a task and sending follow-up messages
80
+ without the missing-`call_id` errors from strict providers. Paired tool results
81
+ keep their original format; OpenAI's own endpoint receives native messages.
82
+
83
+ `--reasoning EFFORT` sets the initial effort (also supported for direct terminal
84
+ Codex launches). DeepSeek's picker exposes none, low, high and max; its Responses
85
+ API maps minimal to low and medium/xhigh to high. Other models can declare an
86
+ exact `reasoningEfforts` array through `models add/update --file FILE`. An explicit
87
+ effort also enables that choice for models whose catalog omits effort metadata;
88
+ the provider must support it. The app can change effort per conversation, and
89
+ routing events record the value actually sent upstream.
90
+
91
+ `--dangerously-bypass-approvals-and-sandbox` explicitly selects full access:
92
+ commands can edit files and use the network without approval prompts or a
93
+ sandbox. Without that flag, desktop launches start with workspace-write and
94
+ on-request approvals. These are startup defaults; the app's own permission
95
+ controls and managed requirements still apply. Start a new conversation after
96
+ changing launch defaults; existing conversations can retain their own settings.
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
+
112
+ Switcher starts a separate app instance with persistent provider/model state
113
+ under `~/.hasna/switcher/state/desktop/PROFILE`. Your regular ChatGPT app and its
114
+ signed-in state are preserved. Each profile retains its own local conversations
115
+ and preferences across launches; it does not copy the regular app's login or
116
+ conversation history. A second launch of the same active profile is refused.
117
+ Keep the launching terminal running until you quit that instance: Switcher owns
118
+ its inference gateway and stops its own app process on interruption or timeout.
119
+
120
+ Upstream API keys remain in the Switcher gateway. Only a temporary loopback
121
+ credential reaches the child; its private auth file is removed after exit.
122
+ Switcher refuses to overwrite authentication added manually to a provider
123
+ profile. It does not modify or re-sign the installed app. Select a nonstandard
124
+ installation with `--app-path /absolute/path/ChatGPT.app`; native CLI arguments,
125
+ `--executable` and `--backend` are not accepted for desktop launches.
126
+
127
+ `--dry-run` validates app detection and provider/model discovery without opening
128
+ the app. The SDK offers local installation discovery through `detectChatGPTApp()`;
129
+ provider/profile/catalog operations continue to use the existing HTTP API.
130
+
131
+ The opt-in `test:native-chatgpt-runtime` script exercises the installed app's
132
+ bundled runtime against a real provider using a fresh isolated profile. Set
133
+ `SWITCHER_NATIVE_CHATGPT_PROVIDER` and `SWITCHER_NATIVE_CHATGPT_MODEL` to run it.
134
+ It verifies selected-model configuration, direct responses, delegated task
135
+ creation, follow-up delivery, and history replay against the real provider.
136
+ It is separate from visual desktop acceptance.
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
+
143
+ References: [OpenAI custom provider configuration](https://learn.chatgpt.com/docs/config-file/config-advanced),
144
+ [community desktop custom-model profiles](https://github.com/ademisler/codex-desktop-custom-models),
145
+ [reported signed-in provider routing issue](https://github.com/openai/codex/issues/37245),
146
+ and [Preview Edit routing limitation](https://github.com/openai/codex/issues/37315),
147
+ and [DeepSeek thinking controls](https://api-docs.deepseek.com/guides/thinking_mode/).
148
+
149
+ ## Claude desktop with a provider
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
+
157
+ ```sh
158
+ switcher launch claude-desktop --provider deepseek --model deepseek-flash
159
+ switcher launch claude-desktop --provider my-messages-provider --model vendor/model
160
+ switcher launch claude-desktop --provider deepseek --model deepseek-flash --dry-run
161
+ ```
162
+
163
+ Requires macOS and Claude desktop 1.52386.0 or newer. This uses the app's
164
+ supported third-party gateway mode and its own downloaded Claude Code engine;
165
+ a separately installed Claude Code CLI is not required. `launch claude` keeps
166
+ launching the terminal CLI. `detectClaudeDesktopApp()` is available in the SDK.
167
+
168
+ The provider must implement Anthropic Messages, including streaming and tool
169
+ calling for the chosen model. DeepSeek and compatible gateway presets select
170
+ the Messages endpoint automatically. Saved provider IDs retain their explicit
171
+ protocol. Switcher does not convert Chat Completions or Responses into Messages.
172
+ A configured provider works in both desktop apps when it offers both required
173
+ APIs; a preset's existence is not proof that every model supports every feature.
174
+
175
+ Claude uses its vendor-supported `~/Library/Application Support/Claude-3p`
176
+ profile, separate from the regular signed-in Claude profile. Only one third-party
177
+ instance can run at a time; quit it before switching providers. Switcher adds a
178
+ temporary configuration-library entry, leases that profile, and restores the
179
+ previous selection on exit. Its conversations remain in Claude-3p. Configuration
180
+ changes made outside Switcher are preserved and reported for review. Managed
181
+ Claude configurations are not overridden. No app patching, re-signing or
182
+ restricted development flags are used.
183
+
184
+ The selected model fills Claude's normal, planning and fast model slots using
185
+ explicit gateway aliases. `--role-model planning=MODEL` and `--role-model
186
+ fast=MODEL` can select different models from the same provider. The gateway
187
+ records the actual upstream model. Display labels identify your provider model;
188
+ the aliases do not change that model into an Anthropic model.
189
+
190
+ Choose effort and permissions in Claude's own controls; the model must support
191
+ what Claude sends. Switcher's `--reasoning` and
192
+ `--dangerously-bypass-approvals-and-sandbox` flags currently apply to Codex and
193
+ ChatGPT, and are rejected for Claude desktop. Cowork and account-dependent
194
+ features retain their native requirements. Only a temporary scoped loopback
195
+ credential is written to the private configuration file; the upstream provider
196
+ key stays in Switcher. Keep Switcher running while using the launched instance.
197
+
198
+ Live acceptance on macOS used DeepSeek `deepseek-flash`: ChatGPT local Codex
199
+ returned the requested test marker with reasoning and Full access visible;
200
+ Claude's third-party chat returned its requested marker, with successful gateway
201
+ traces identifying `deepseek-flash`. Other compatible providers have adapter
202
+ coverage, not a claim of live acceptance on every model.
203
+
204
+ References: [Claude third-party gateway](https://claude.com/docs/third-party/claude-desktop/gateway),
205
+ [configuration library and model tiers](https://claude.com/docs/third-party/claude-desktop/configuration),
206
+ and [CC Switch's Claude desktop integration](https://github.com/Chenx-13/cc_switch/blob/main/docs/user-manual/en/2-providers/2.6-claude-desktop.md).
207
+
50
208
  ## Direct launch
51
209
 
52
210
  The direct launch flow is available from 0.1.1. The additional OMP, DeepSeek Harness, Cline, Hermes, Prime Agent, legacy OpenCode, Kilo, Gemini CLI and Aider adapters are introduced in 0.1.2. Version 0.1.0 requires explicit API/provider/profile setup.
@@ -67,7 +225,7 @@ switcher launch codex --provider openrouter --model anthropic/claude-sonnet-4.6
67
225
 
68
226
  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.
69
227
 
70
- 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.
228
+ 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.
71
229
 
72
230
  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.
73
231
 
@@ -81,7 +239,7 @@ The canonical file is `~/.hasna/switcher/config/credentials` (owner-only mode 06
81
239
 
82
240
  `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.
83
241
 
84
- 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`.
242
+ 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`.
85
243
 
86
244
  ## Credential bindings
87
245
 
@@ -331,7 +489,7 @@ switcher providers add catalog-provider --url https://inference.example/v1 --pro
331
489
 
332
490
  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.
333
491
 
334
- 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.
492
+ 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.
335
493
 
336
494
  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.
337
495
 
@@ -0,0 +1,5 @@
1
+ import type { PreparedLaunch } from "./harness-types";
2
+ import type { ChatGPTInstallation } from "./desktop-apps";
3
+ /** Separate desktop state from the signed-in app. The upstream credential stays
4
+ * in the parent gateway. SQLite releases the profile lease even after a crash. */
5
+ export declare function prepareChatGPTLaunch(native: PreparedLaunch, app: ChatGPTInstallation, stateDir: string, sessionDir: string): Promise<PreparedLaunch>;
@@ -0,0 +1,11 @@
1
+ import type { ClaudeDesktopInstallation } from "./desktop-apps";
2
+ import type { HarnessLaunchInput, PreparedLaunch } from "./harness-types";
3
+ export declare const claudeDesktopDataDirectory: () => string;
4
+ type DesktopSystem = {
5
+ userData: string;
6
+ assertAvailable: () => Promise<void>;
7
+ };
8
+ /** Use the vendor-supported local configuration library, preserving the prior
9
+ * selection. The signed app rejects custom userData development overrides. */
10
+ export declare function prepareClaudeDesktopLaunch(input: HarnessLaunchInput, app: ClaudeDesktopInstallation, sessionDir: string, system?: DesktopSystem): Promise<PreparedLaunch>;
11
+ export {};