@hasna/switcher 0.2.17 → 0.2.19
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/Dockerfile +6 -1
- package/README.md +1 -1
- package/dist/claude-desktop.js +19180 -3734
- package/dist/cli/index.js +707 -330
- package/dist/codex-state-bridge.js +4 -4
- package/dist/credentials.d.ts +36 -184
- package/dist/domain.d.ts +271 -737
- package/dist/gateway-service.d.ts +3 -1
- package/dist/index.js +19121 -3675
- package/dist/inference-gateway.d.ts +2 -0
- package/dist/mcp/index.js +19608 -4116
- package/dist/model-policy-schema.d.ts +93 -112
- package/dist/native-state.d.ts +24 -0
- package/dist/opencode2-config.d.ts +8 -12
- package/dist/presets.d.ts +2 -2
- package/dist/process-table.d.ts +7 -0
- package/dist/reasoning.d.ts +11 -2
- package/dist/sdk.js +19121 -3675
- package/dist/serve/index.js +269 -223
- package/docs/GATEWAY-SERVICE.md +66 -30
- package/hasna.contract.json +1 -1
- package/openapi.json +264 -218
- package/package.json +9 -6
package/docs/GATEWAY-SERVICE.md
CHANGED
|
@@ -63,22 +63,40 @@ SWITCHER_GATEWAY=local switcher launch ... # use the per-launch gateway of 0.2
|
|
|
63
63
|
every process the launch starts, read from the process table about once a second
|
|
64
64
|
while a launch is new and every few seconds once it has settled. A detached
|
|
65
65
|
daemon remains a holder after its parent exits and it is reparented.
|
|
66
|
-
3. When the harness exits, `switcher launch` releases the launch.
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
registered
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
66
|
+
3. When the harness exits, `switcher launch` releases the launch. Some processes
|
|
67
|
+
that use the launch never appear under it: a daemon started by a double fork, or
|
|
68
|
+
detached in the moment before its parent exited, and a background session that
|
|
69
|
+
another launch's Claude Code host started for this launch. So at release (or when
|
|
70
|
+
the launcher dies without releasing) the service also checks every process started
|
|
71
|
+
since the launch registered (every process, for a launch restored after a service
|
|
72
|
+
restart), and checks again at most once a minute while the launch has no holder,
|
|
73
|
+
before it expires. One whose environment carries this launch's token becomes a
|
|
74
|
+
holder. Token-shaped values are compared by SHA-256 digest and never kept or logged.
|
|
75
|
+
4. If nothing the launch started is still running, the launch ends at once and the
|
|
76
|
+
launcher removes its state directory as before. Otherwise the service keeps the
|
|
77
|
+
token, the per-launch configuration files and the routing policy while any holder
|
|
78
|
+
runs. If the service cannot be reached at release (for example while launchd
|
|
79
|
+
restarts it), the launcher leaves the state directory to the service, which
|
|
80
|
+
removes it when the launch expires.
|
|
79
81
|
5. When the last holder exits and the token has not been used for
|
|
80
|
-
`SWITCHER_GATEWAY_GRACE_SECONDS` (default 600), the launch expires: its
|
|
81
|
-
|
|
82
|
+
`SWITCHER_GATEWAY_GRACE_SECONDS` (default 600), the launch expires: its in-memory
|
|
83
|
+
credential and retained state directory are removed.
|
|
84
|
+
6. An ended or expired launch keeps its record (policy, provider, credential binding
|
|
85
|
+
and token digest; never the token or a credential) for 30 days after it last ended,
|
|
86
|
+
and at most 1000 ended launches are kept (the oldest goes first). Requests that were
|
|
87
|
+
in flight when it ended are allowed to finish. Claude Code's
|
|
88
|
+
background host keeps each session's provider environment, token included, in its
|
|
89
|
+
own memory, starts the session without it in the process environment, and can
|
|
90
|
+
start the session again days later. So a request with an ended launch's token is
|
|
91
|
+
served again when the loopback connection it arrives on belongs to a running
|
|
92
|
+
process of this user that runs under a live holder of a current launch (the
|
|
93
|
+
background host is one); that process becomes a holder and the launch continues as
|
|
94
|
+
in step 2. A copied token used from any other process, and a request that cannot be
|
|
95
|
+
traced, are refused as before. A launch revoked because its harness never started is
|
|
96
|
+
not kept. A credential that came only from the launch environment stays in service
|
|
97
|
+
memory with the ended record, so such a launch is served again while the service
|
|
98
|
+
runs; after a service restart it gets `switcher_gateway_credential_unavailable`, as
|
|
99
|
+
restored launches do.
|
|
82
100
|
|
|
83
101
|
Every request is dispatched by its token to that launch's own handler. One launch
|
|
84
102
|
cannot use another launch's credential, catalog, aliases or fallbacks.
|
|
@@ -111,7 +129,7 @@ While the service runs, a client always gets an HTTP answer it can show:
|
|
|
111
129
|
|
|
112
130
|
| Status | Code | Meaning and fix |
|
|
113
131
|
| --- | --- | --- |
|
|
114
|
-
| 401 | `switcher_gateway_launch_unknown` | The launch ended
|
|
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`. |
|
|
115
133
|
| 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. |
|
|
116
134
|
| 503 | `switcher_gateway_credential_unavailable` | The binding could not be read now. Check it with `switcher credentials check REFERENCE`. |
|
|
117
135
|
| 401 | `switcher_gateway_credential_changed` | The binding changed after the launch started. |
|
|
@@ -134,10 +152,19 @@ While the service runs, a client always gets an HTTP answer it can show:
|
|
|
134
152
|
files or command lines. The service environment is an allowlist that excludes
|
|
135
153
|
`SWITCHER_PROVIDER_*` and API keys.
|
|
136
154
|
- Each launch has its own token, its own model policy and its own credential.
|
|
137
|
-
- The
|
|
138
|
-
|
|
139
|
-
for a value whose SHA-256 digest equals the launch token's
|
|
140
|
-
macOS uses `ps -E`; Linux reads `/proc/<pid>/environ`.
|
|
155
|
+
- The token check reads the environment only of this user's processes started after
|
|
156
|
+
the launch registered, at release and at most once a minute while the launch has no
|
|
157
|
+
holder. It looks only for a value whose SHA-256 digest equals the launch token's
|
|
158
|
+
digest and keeps nothing. macOS uses `ps -E`; Linux reads `/proc/<pid>/environ`.
|
|
159
|
+
- 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. The process is
|
|
161
|
+
found from the connection itself: macOS runs `lsof` limited to this user's
|
|
162
|
+
processes; Linux reads `/proc/net/tcp` (which names the socket's owner) and this
|
|
163
|
+
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 launch is refused, and a lookup
|
|
165
|
+
that fails or takes more than 5 seconds refuses the request. A connection whose lookup
|
|
166
|
+
failed is not looked up again for 5 seconds, and an ended launch gets at most 4
|
|
167
|
+
lookups in any 5 seconds. On Linux both ends of the connection must be 127.0.0.1.
|
|
141
168
|
- Control input is validated strictly. Policy maps use null-prototype objects, and
|
|
142
169
|
the service removes only `launch-XXXXXX` state directories owned by the user.
|
|
143
170
|
|
|
@@ -150,16 +177,15 @@ While the service runs, a client always gets an HTTP answer it can show:
|
|
|
150
177
|
example with SIGKILL) while the harness keeps running. Claude Code, Codex and the
|
|
151
178
|
other adapters talk to the gateway directly.
|
|
152
179
|
- Claude Code keeps one background host per configuration directory, and it serves
|
|
153
|
-
background sessions for later launches of the same profile too.
|
|
154
|
-
|
|
155
|
-
|
|
180
|
+
background sessions for later launches of the same profile too. A session uses the
|
|
181
|
+
launch whose window started it, or the launch that started the host, with that
|
|
182
|
+
launch's token, provider, credential and model policy; the host keeps the token in
|
|
183
|
+
its memory, not in the session's process environment. When that launch ends, the
|
|
184
|
+
session's next request revives it (step 6). A launch of a different profile normally uses
|
|
156
185
|
a different directory and its own host. If `CLAUDE_CONFIG_DIR` points several
|
|
157
186
|
profiles at one shared directory, they share one host too, so background sessions
|
|
158
187
|
can run with another profile's provider and model policy; give each profile its own
|
|
159
188
|
directory.
|
|
160
|
-
- A launch restored after a gateway restart that happened between its registration
|
|
161
|
-
and its release gets no detached-process check at release, so a double-forked
|
|
162
|
-
daemon no scan saw before the restart is not adopted.
|
|
163
189
|
- The default port is `47000 + uid % 1000`, so two accounts on one host whose uids
|
|
164
190
|
differ by 1000 collide; the second gets `gateway_port_in_use` and its launches use
|
|
165
191
|
per-launch gateways. Set `SWITCHER_GATEWAY_PORT` for one of them and run
|
|
@@ -169,10 +195,20 @@ While the service runs, a client always gets an HTTP answer it can show:
|
|
|
169
195
|
login). A new launch then detects the conflict and uses a per-launch gateway, but a
|
|
170
196
|
session that survived from before keeps sending its token and prompts to that
|
|
171
197
|
address. Stations with one interactive account are not affected.
|
|
172
|
-
- The
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
198
|
+
- The token check finds a process only if its environment carries the launch token
|
|
199
|
+
(Claude Code passes it in `ANTHROPIC_AUTH_TOKEN`). A background session started
|
|
200
|
+
without it keeps the launch through step 6 instead, from its first request after
|
|
201
|
+
the launch ended. Step 6 needs the background host to hold a current launch: a
|
|
202
|
+
host started by a plain `claude` outside Switcher, serving a session dispatched
|
|
203
|
+
from a Switcher window, does not qualify.
|
|
204
|
+
- A launch that ended before the service ran 0.2.19 has no record, so a session that
|
|
205
|
+
still uses it gets `switcher_gateway_launch_unknown`.
|
|
206
|
+
- Claude's picker settings (`--settings`) are written to
|
|
207
|
+
`state/sessions/claude/<profile>/settings/claude-settings-<digest>.json`, outside the
|
|
208
|
+
launch's temporary folder, because the background host replays that path when it
|
|
209
|
+
restarts a session. Sessions started by 0.2.18 or older name a path in a launch folder
|
|
210
|
+
that may be gone; Claude then refuses to start them ("Settings file not found") until
|
|
211
|
+
they are dispatched again from a 0.2.19 launch.
|
|
176
212
|
- Claude Desktop and the Ori backend keep their own gateways.
|
|
177
213
|
- A Claude Code daemon started by Switcher 0.2.13 or older still carries its old
|
|
178
214
|
per-launch address. It recovers after that daemon restarts under a 0.2.14 launch.
|
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.10",
|
|
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",
|