@hasna/switcher 0.2.19 → 0.2.21
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 +1 -1
- package/dist/claude-desktop.js +98 -96
- package/dist/claude-user-settings.d.ts +7 -2
- package/dist/cli/index.js +284 -95
- package/dist/harness-types.d.ts +6 -0
- package/dist/harnesses.d.ts +8 -0
- package/dist/index.js +159 -106
- package/dist/inference-gateway.d.ts +6 -0
- package/dist/launcher.d.ts +34 -0
- package/dist/mcp/index.js +166 -111
- package/dist/native-state.d.ts +11 -1
- package/dist/private-directory.d.ts +3 -0
- package/dist/runtime.d.ts +1 -1
- package/dist/sdk.js +159 -106
- package/dist/serve/index.js +2 -2
- package/docs/GATEWAY-SERVICE.md +59 -10
- package/hasna.contract.json +1 -1
- package/openapi.json +1 -1
- package/package.json +2 -2
package/dist/serve/index.js
CHANGED
|
@@ -68,7 +68,7 @@ function canonicalPolicyJSON(value) {
|
|
|
68
68
|
return JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).sort(([a], [b]) => a.localeCompare(b))) : item);
|
|
69
69
|
}
|
|
70
70
|
// package.json
|
|
71
|
-
var version = "0.2.
|
|
71
|
+
var version = "0.2.21";
|
|
72
72
|
|
|
73
73
|
// src/version.ts
|
|
74
74
|
var VERSION = version;
|
|
@@ -922,7 +922,7 @@ var openapi_default = {
|
|
|
922
922
|
openapi: "3.0.3",
|
|
923
923
|
info: {
|
|
924
924
|
title: "Switcher API",
|
|
925
|
-
version: "0.2.
|
|
925
|
+
version: "0.2.21",
|
|
926
926
|
description: "Authenticated provider/profile/catalog control plane. Launches run locally; the API never returns provider credentials."
|
|
927
927
|
},
|
|
928
928
|
security: [
|
package/docs/GATEWAY-SERVICE.md
CHANGED
|
@@ -91,12 +91,34 @@ SWITCHER_GATEWAY=local switcher launch ... # use the per-launch gateway of 0.2
|
|
|
91
91
|
served again when the loopback connection it arrives on belongs to a running
|
|
92
92
|
process of this user that runs under a live holder of a current launch (the
|
|
93
93
|
background host is one); that process becomes a holder and the launch continues as
|
|
94
|
-
in step 2. A
|
|
94
|
+
in step 2. A launch that is current again only because its durable route revived it
|
|
95
|
+
(step 7) does not count here: its holders do not qualify a process to revive a launch
|
|
96
|
+
without a route. A copied token used from any other process, and a request that cannot be
|
|
95
97
|
traced, are refused as before. A launch revoked because its harness never started is
|
|
96
98
|
not kept. A credential that came only from the launch environment stays in service
|
|
97
99
|
memory with the ended record, so such a launch is served again while the service
|
|
98
100
|
runs; after a service restart it gets `switcher_gateway_credential_unavailable`, as
|
|
99
101
|
restored launches do.
|
|
102
|
+
7. A Claude Code launch with a profile session folder (every `switcher launch` of a
|
|
103
|
+
Claude profile on the persistent gateway, since 0.2.21) registers a durable route. Its `--settings` file,
|
|
104
|
+
`state/sessions/claude/<profile>/settings/claude-route-<launch id>.json`, carries the
|
|
105
|
+
launch's route in its `env` block: `ANTHROPIC_BASE_URL`, the launch token in
|
|
106
|
+
`ANTHROPIC_AUTH_TOKEN` (or `ANTHROPIC_API_KEY` for `x-api-key` providers) and a blank
|
|
107
|
+
for the other key. These are the values the launch environment already carries, so a
|
|
108
|
+
live session is unchanged. Claude Code applies a settings file's `env` block over the
|
|
109
|
+
session's environment, and its background host replays `--settings` whenever it
|
|
110
|
+
restarts a session. So a session the host restores without the launch environment
|
|
111
|
+
(after a station or host restart, or a session opened from another folder, where
|
|
112
|
+
Claude withholds the gateway variables) still reaches its own launch. For such a
|
|
113
|
+
launch, step 6 does not require a current launch: a request on a connection from any
|
|
114
|
+
running process of this user revives it. That process then holds this launch only;
|
|
115
|
+
it does not become a holder that can revive other launches. When the service stops accepting the token
|
|
116
|
+
(30 days after the launch last ended, or when the 1000-record limit drops it), it
|
|
117
|
+
rewrites the file to `{}`, so a session restarted from it later starts and reports
|
|
118
|
+
that it is not logged in instead of refusing to start. A launch revoked because its
|
|
119
|
+
harness never started removes its file. A running gateway older than 0.2.21 refuses
|
|
120
|
+
the route; the launch then registers as before and prints a warning naming
|
|
121
|
+
`switcher gateway install`.
|
|
100
122
|
|
|
101
123
|
Every request is dispatched by its token to that launch's own handler. One launch
|
|
102
124
|
cannot use another launch's credential, catalog, aliases or fallbacks.
|
|
@@ -129,7 +151,7 @@ While the service runs, a client always gets an HTTP answer it can show:
|
|
|
129
151
|
|
|
130
152
|
| Status | Code | Meaning and fix |
|
|
131
153
|
| --- | --- | --- |
|
|
132
|
-
| 401 | `switcher_gateway_launch_unknown` | The launch was revoked, ended more than 30 days ago, or the request did not come from a process of this user running under a current launch. Start a new session with `switcher launch`. |
|
|
154
|
+
| 401 | `switcher_gateway_launch_unknown` | The launch was revoked, ended more than 30 days ago, or the request for this ended launch did not come from a process of this user running under a current launch (for a durable Claude route, from any running process of this user). Start a new session with `switcher launch`. |
|
|
133
155
|
| 401 | `switcher_gateway_credential_unavailable` | The credential came only from the launch environment and the service restarted. Start a new session, or bind the credential. |
|
|
134
156
|
| 503 | `switcher_gateway_credential_unavailable` | The binding could not be read now. Check it with `switcher credentials check REFERENCE`. |
|
|
135
157
|
| 401 | `switcher_gateway_credential_changed` | The binding changed after the launch started. |
|
|
@@ -148,20 +170,39 @@ While the service runs, a client always gets an HTTP answer it can show:
|
|
|
148
170
|
user. Otherwise it refuses with `gateway_socket_untrusted` and the launch uses a
|
|
149
171
|
per-launch gateway. This matters for the `/tmp` fallback, where another account could
|
|
150
172
|
create the directory first.
|
|
151
|
-
- Provider credentials
|
|
152
|
-
|
|
153
|
-
|
|
173
|
+
- Provider credentials are never written to disk, logs, unit files or command lines,
|
|
174
|
+
and neither are launch tokens, with one exception: a Claude launch's durable route
|
|
175
|
+
file (step 7) holds that launch's token. The file is created once, exclusively, mode
|
|
176
|
+
0600, in a settings folder that must be a real directory owned by the user with mode
|
|
177
|
+
0700 (otherwise the launch is refused), under the 0700 Switcher state folder. The token
|
|
178
|
+
is accepted only by this gateway on `127.0.0.1` and reaches only that launch's
|
|
179
|
+
provider, credential and model policy; it is not a provider key. While the launch is
|
|
180
|
+
current, including after a revival, the gateway serves it on any loopback connection
|
|
181
|
+
that presents the token, without checking which process sent it, as for every launch.
|
|
182
|
+
Only reviving the launch after it ended checks the process (any running process of
|
|
183
|
+
this user, see below).
|
|
184
|
+
Anyone who can read the file can already read the session's environment, which holds
|
|
185
|
+
the same token, while the session runs; the file keeps it readable to them for up to
|
|
186
|
+
30 days after the launch was last used, and backups of the state folder copy it. The
|
|
187
|
+
service environment is an allowlist that excludes `SWITCHER_PROVIDER_*` and API keys.
|
|
154
188
|
- Each launch has its own token, its own model policy and its own credential.
|
|
155
189
|
- The token check reads the environment only of this user's processes started after
|
|
156
190
|
the launch registered, at release and at most once a minute while the launch has no
|
|
157
191
|
holder. It looks only for a value whose SHA-256 digest equals the launch token's
|
|
158
192
|
digest and keeps nothing. macOS uses `ps -E`; Linux reads `/proc/<pid>/environ`.
|
|
159
193
|
- An ended launch is served again only on a connection from a running process of this
|
|
160
|
-
user under a live holder of a current launch, and only for 30 days.
|
|
194
|
+
user under a live holder of a current launch, and only for 30 days. A durable Claude
|
|
195
|
+
route (step 7) drops the live-holder condition: its token is served to any running
|
|
196
|
+
process of this user that presents it, a shell or script included, for 30 days after
|
|
197
|
+
the launch was last used. A process holding a launch that only its durable route
|
|
198
|
+
revived is not a live holder for this check, so it cannot revive launches without a
|
|
199
|
+
route. While a launch is current, its token is served on any loopback connection that
|
|
200
|
+
presents it, with no process check. The process is
|
|
161
201
|
found from the connection itself: macOS runs `lsof` limited to this user's
|
|
162
202
|
processes; Linux reads `/proc/net/tcp` (which names the socket's owner) and this
|
|
163
203
|
user's `/proc/<pid>/fd`. Another account's process is never matched, a copied token
|
|
164
|
-
used from a shell or script outside every current
|
|
204
|
+
of a launch without a durable route used from a shell or script outside every current
|
|
205
|
+
launch is refused, and a lookup
|
|
165
206
|
that fails or takes more than 5 seconds refuses the request. A connection whose lookup
|
|
166
207
|
failed is not looked up again for 5 seconds, and an ended launch gets at most 4
|
|
167
208
|
lookups in any 5 seconds. On Linux both ends of the connection must be 127.0.0.1.
|
|
@@ -198,9 +239,17 @@ While the service runs, a client always gets an HTTP answer it can show:
|
|
|
198
239
|
- The token check finds a process only if its environment carries the launch token
|
|
199
240
|
(Claude Code passes it in `ANTHROPIC_AUTH_TOKEN`). A background session started
|
|
200
241
|
without it keeps the launch through step 6 instead, from its first request after
|
|
201
|
-
the launch ended.
|
|
202
|
-
|
|
203
|
-
|
|
242
|
+
the launch ended. Without a durable route, step 6 needs the background host to hold
|
|
243
|
+
a current launch that a launcher registered (or that such a holder revived): a host
|
|
244
|
+
started by a plain `claude` outside Switcher, or one launchd restarted after a station
|
|
245
|
+
restart, does not qualify, even after its Claude sessions revived their own launches
|
|
246
|
+
through their durable routes. A durable route (step 7) does not need one.
|
|
247
|
+
- A durable route keeps a session on the launch that started it. A credential that came
|
|
248
|
+
only from the launch environment is still lost when the service restarts
|
|
249
|
+
(`switcher_gateway_credential_unavailable`); bind it with `switcher credentials bind`
|
|
250
|
+
so restored sessions keep working after a station restart. Sessions started before
|
|
251
|
+
0.2.21 have no durable route and still need to be dispatched again from a current
|
|
252
|
+
launch after a host restart.
|
|
204
253
|
- A launch that ended before the service ran 0.2.19 has no record, so a session that
|
|
205
254
|
still uses it gets `switcher_gateway_launch_unknown`.
|
|
206
255
|
- Claude's picker settings (`--settings`) are written to
|
package/hasna.contract.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"name": "switcher",
|
|
5
5
|
"class": "cli-with-store",
|
|
6
6
|
"contractVersion": "v1",
|
|
7
|
-
"kitVersion": "1.3.
|
|
7
|
+
"kitVersion": "1.3.11",
|
|
8
8
|
"description": "Universal provider and model switcher with API-first local and hosted operation. CLI, MCP and SDK resolve one authenticated HTTP authority through @hasna/contracts and fail closed when hosted configuration is missing or invalid. HASNA_SWITCHER_LOCAL=1 deliberately selects an owned loopback API backed by SQLite; hosted https://api.hasna.com/switcher uses PostgreSQL and signed revocable API keys. Provider credentials remain local to the launcher and are never stored or returned by the service.",
|
|
9
9
|
"bins": [
|
|
10
10
|
"switcher",
|
package/openapi.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hasna/switcher",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Universal provider and model switcher for coding harnesses with an API, SDK and self-hosted storage",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@types/pg": "8.23.1"
|
|
79
79
|
},
|
|
80
80
|
"dependencies": {
|
|
81
|
-
"@hasna/contracts": "1.3.
|
|
81
|
+
"@hasna/contracts": "1.3.11",
|
|
82
82
|
"jsonc-parser": "3.3.1",
|
|
83
83
|
"yaml": "2.9.0",
|
|
84
84
|
"@aws-sdk/client-secrets-manager": "3.1127.0",
|