@seaveyon/harness-switch 0.18.0 → 0.20.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
@@ -4,52 +4,80 @@
4
4
 
5
5
  English | [简体中文](https://github.com/B1anker/harness-switch/blob/main/README.zh-CN.md)
6
6
 
7
- **harness-switch** is a Bun-powered web control plane for managing API profiles on an SSH or headless server. It switches API Base URL, API key, and model profiles for **Claude Code**, **Codex**, **Kimi Code**, **Pi**, and **DeepSeek Harness (DSH)**.
7
+ **harness-switch** is a local control plane for switching the API configuration used by **Claude Code**, **Codex**, **Kimi Code**, **Pi**, and **DeepSeek Harness (DSH)**. Run it on the computer that runs those tools; open its browser UI, choose a saved profile, and activate it.
8
8
 
9
- It writes each tool's native configuration; it is not an API proxy and never routes model traffic. Profiles are encrypted at rest, writes are transactional, and every activation has a backup and an undo receipt.
9
+ It writes the tools’ native configuration files directly. It is not a proxy, never receives model traffic, and does not need you to source a shell script.
10
10
 
11
- ## Install and run
11
+ ## What you get
12
12
 
13
- Requires [Bun](https://bun.sh) >= 1.2 as the runtime. Start it with your preferred package runner:
13
+ | Capability | What it means |
14
+ |---|---|
15
+ | One profile per provider or use case | Switch base URL, key, model, and harness-specific options from one UI. |
16
+ | Safe native-file writes | Every activation is validated, transactional, backed up, and can be undone. |
17
+ | Credential reuse | Store a key once in Provider Vault and reuse it across profiles. |
18
+ | Import, export, and sync | Adopt existing configs, move encrypted bundles between machines, or copy config between Unix users. |
19
+ | Diagnostics | Compare the active profile with live files, detect drift, and re-apply or adopt changes. |
20
+
21
+ ## Compatibility
22
+
23
+ | Area | Support |
24
+ |---|---|
25
+ | Operating systems | macOS, Windows, Linux |
26
+ | Runtime | Node.js >= 18.17 or Bun >= 1.2 |
27
+ | Browser access | Open `http://127.0.0.1:8787` on the same machine by default |
28
+ | Remote access | Optional SSH tunnel or a properly secured reverse proxy |
29
+ | Multiple local users | Unix-like hosts; Windows manages the account that starts the service |
30
+
31
+ ## Get started
32
+
33
+ Start with any package runner:
14
34
 
15
35
  ```bash
16
- bunx @seaveyon/harness-switch@latest
17
36
  npx -y @seaveyon/harness-switch@latest
18
37
  pnpm dlx @seaveyon/harness-switch@latest
38
+ bunx @seaveyon/harness-switch@latest
19
39
  ```
20
40
 
21
41
  `pnpx @seaveyon/harness-switch@latest` is also supported where `pnpx` is available. Or install it globally:
22
42
 
23
43
  ```bash
24
- bun add -g @seaveyon/harness-switch
25
- # npm install -g @seaveyon/harness-switch
44
+ npm install -g @seaveyon/harness-switch
26
45
  # pnpm add -g @seaveyon/harness-switch
46
+ # bun add -g @seaveyon/harness-switch
27
47
  harness-switch
28
48
  ```
29
49
 
30
- The command starts a background daemon on `127.0.0.1:8787`. Read the generated Web password with:
50
+ The command starts a background daemon on `127.0.0.1:8787` and prints the path to the generated Web password. Then:
51
+
52
+ 1. Open [http://127.0.0.1:8787](http://127.0.0.1:8787) in a browser on that machine.
53
+ 2. Sign in with the generated password.
54
+ 3. Create a profile for one harness and select **Activate**.
55
+
56
+ Use `harness-switch status` to see the URL, log, data directory, and password-file location. On macOS and Linux, the default password file is:
31
57
 
32
58
  ```bash
33
59
  cat ~/.harness-switch/web_password
34
60
  ```
35
61
 
36
- For a remote SSH server, keep the server bound to loopback and use an SSH tunnel:
62
+ ### Accessing a remote machine
63
+
64
+ SSH is optional. When harness-switch runs on a remote or headless host, keep it bound to loopback and forward the port:
37
65
 
38
66
  ```bash
39
67
  ssh -N -L 8787:127.0.0.1:8787 user@your-server
40
68
  ```
41
69
 
42
- Then open <http://127.0.0.1:8787> locally. Use `harness-switch status`, `stop`, or `server` to inspect, stop, or run the service in the foreground.
70
+ Then open <http://127.0.0.1:8787> in your local browser. Use `harness-switch status`, `stop`, or `server` to inspect, stop, or run the service in the foreground.
43
71
 
44
72
  ### Interface language
45
73
 
46
74
  The web UI supports English and Simplified Chinese. Use the language button in the login page or dashboard header to switch languages. Chinese remains the default for existing behavior; your selection is stored in the browser and is reused on later visits. The setting affects only the web interface—it does not change profile data or generated configuration files.
47
75
 
48
- ## Configuration
76
+ ## Switch a tool
49
77
 
50
78
  Create one or more profiles per harness in the web UI. A profile holds a display name, API Base URL, API key, model, notes, and whatever extra fields that harness needs. Select **Activate** to make a profile current.
51
79
 
52
- Activation writes each tool's own configuration file. Nothing depends on you having sourced a shell script, which is what makes it work for long-lived processes that spawn a CLI as a child.
80
+ Activation writes each tool's own configuration file. Changes apply to the machine where harness-switch runs; it cannot change a tool already running elsewhere.
53
81
 
54
82
  | Harness | File written | Write mode | Takes effect |
55
83
  |---|---|---|---|
@@ -69,22 +97,22 @@ Notes on individual harnesses:
69
97
  - **Pi** (`@earendil-works/pi-coding-agent`) registers a custom provider in `models.json` and points `settings.json` at it via `defaultProvider` / `defaultModel`. The API key must live in that provider entry (or `auth.json`); otherwise Pi shows "No models available" and asks for `/login`. A `--model` flag still overrides the default at runtime.
70
98
  - **DeepSeek Harness** registers a custom `llm-pi-ai` provider, stores the API key in its separate credentials document, and updates `agent-default-model`. Existing sessions keep their selected route; newly created sessions use the activated profile.
71
99
 
72
- `~/.harness-switch/env.sh` remains as a compatibility layer and only contains variables the corresponding tool genuinely honours. It is needed only when a Codex profile uses the environment-variable auth mode:
100
+ `~/.harness-switch/env.sh` is only a compatibility layer for Codex’s environment-variable auth mode:
73
101
 
74
102
  ```bash
75
103
  source ~/.harness-switch/env.sh
76
104
  ```
77
105
 
78
- Two known limitations:
106
+ Keep in mind:
79
107
 
80
108
  - Writing TOML goes through parse and re-serialize, so comments and layout in `config.toml` are lost. YAML and JSON keep their comments and key order.
81
- - The web UI changes files on the **server**. It cannot touch an already-running shell or your local machine.
109
+ - It cannot rewrite the environment of an already-running shell.
82
110
 
83
111
  ### Advanced: taking over the raw file
84
112
 
85
113
  Any field the form does not expose can be set by editing the raw file content in the profile's **Advanced: raw configuration** section. Once edited, that file is generated from your text instead of the form fields until you select **Restore automatic generation**. Content that cannot be parsed back is rejected before it reaches disk.
86
114
 
87
- ### Backups and rollback
115
+ ## Keep changes safe
88
116
 
89
117
  Before every write, the previous content of each target file is snapshotted into `~/.harness-switch/backups/`, keeping the most recent 10. The backup panel restores a snapshot verbatim, comments included. Snapshots never land next to the live file, because tools like Claude Code scan their own config directory.
90
118
 
@@ -94,7 +122,7 @@ Backup directories live in the managed user's own home, so on a root-run service
94
122
 
95
123
  Switching away from a profile first reads the live file back into that profile's record, so edits you made directly in the CLI tool are not lost on the next switch.
96
124
 
97
- ### Operation receipts and undo
125
+ ### Recovery after an interrupted write
98
126
 
99
127
  An in-process `try/catch` only covers a thrown error. A power cut, SIGKILL, OOM or an upgrade restart never gives it the chance to run, and the native config, the profile store and the recorded active profile can be left describing three different states.
100
128
 
@@ -107,11 +135,13 @@ PREPARED → APPLYING → METADATA_COMMITTED → COMMITTED
107
135
 
108
136
  On startup the service settles whatever it finds, for every account it may manage. The boundary that matters is `METADATA_COMMITTED`: by then everything the operation set out to change is already on disk, so it rolls forward to `COMMITTED` rather than undoing a switch the user saw succeed. Anything still at `APPLYING` may be half written and is rolled back whole. A rollback that itself fails is recorded as `DEGRADED` and surfaced in the UI for a human.
109
137
 
110
- Writing `active.json` now happens inside the same transaction as the native files, so the config on disk and the record of what is live can no longer disagree. Each record doubles as a receipt: the files it changed, the backup id, the target user and where it got to. The **Operation log** in the top bar lists them and offers a one-click undo that puts the native files *and* `active.json` back together, rather than just restoring a few files. The undo takes its own snapshot first. Once a backup has been rotated away, its receipt is automatically marked as no longer undoable.
138
+ Writing `active.json` now happens inside the same transaction as the native files, so the config on disk and the record of what is live can no longer disagree. Each record doubles as a receipt: the files it changed, the backup id, the target user and where it got to. Each harness’s right-hand **Operation history** card lists them and offers a one-click undo that puts the native files *and* `active.json` back together, rather than just restoring a few files. The undo takes its own snapshot first. Once a backup has been rotated away, its receipt is automatically marked as no longer undoable.
111
139
 
112
140
  `HSW_JOURNAL_RETAIN` controls how many receipts are kept; the default is 50.
113
141
 
114
- ### Importing configuration you already have
142
+ ## Bring in and move configuration
143
+
144
+ ### Import configuration you already have
115
145
 
116
146
  If you configured these tools by hand before installing harness-switch, **Import existing config** in the top bar adopts that setup instead of making you retype it.
117
147
 
@@ -121,17 +151,17 @@ Each candidate is decided on its own: store it as a standalone profile, or extra
121
151
 
122
152
  **Neither the scan nor the import touches the tools' own config files.** An import writes only to harness-switch's own profile store and vault; making it take effect still requires an explicit activation. A config file that exists but cannot be parsed causes that tool to be skipped with a reason, rather than guessed at.
123
153
 
124
- ### Moving every profile to another machine
154
+ ### Move profiles to another machine
125
155
 
126
- Use **Import / Export** in the top bar to create one `.hsw-backup` file containing every Harness profile, API key, raw-file override, and current activation choice. The bundle is encrypted with a migration password you choose, so it does not depend on the source machine's `aes-256-gcm.key`.
156
+ Use **Import / Export** in the top bar to create one `.hsw-backup` file containing every Harness profile, Provider Vault credential and endpoint, API key, raw-file override, and current activation choice. The bundle is encrypted with a migration password you choose, so it does not depend on the source machine's `aes-256-gcm.key`.
127
157
 
128
- On the destination machine, select the bundle and enter the migration password. The UI shows profile counts and same-name conflicts before it writes anything. Import keeps destination profiles by default; overwriting is an explicit choice. Restoring the exported activation state is optional.
158
+ On the destination machine, select the bundle and enter the migration password. The UI shows profile counts, credential counts, and same-name profile conflicts before it writes anything. Import keeps destination profiles by default; overwriting is an explicit choice. Provider Vault entries are always restored as isolated copies and never replace a destination credential; an ID conflict gets a new imported ID, and imported profiles reference that copy. Restoring the exported activation state is optional.
129
159
 
130
160
  A Codex official-login cache (`$CODEX_HOME/auth.json`) is **excluded by default**. When a valid cache is available, you may explicitly include it in the encrypted bundle. Import offers the separate migration choice only when the bundled and destination JSON values differ. This carries a reusable Codex/ChatGPT login session: share such a bundle only with a trusted recipient, and expect upstream expiry or revocation to still require a fresh `codex login`. An existing destination cache is backed up before replacement; copied caches are written as the destination user with mode `0600`.
131
161
 
132
162
  Keep the migration password separately from the bundle. It cannot be recovered from the export file.
133
163
 
134
- ### Provider Vault: shared credentials
164
+ ### Reuse credentials with Provider Vault
135
165
 
136
166
  The **Provider Vault** stores an API key once under a named entry with one or more named endpoints (each a base URL), encrypted with the same AES-256-GCM key that protects `profiles.json`. A profile can reference a vault entry instead of carrying its own key:
137
167
 
@@ -140,9 +170,17 @@ The **Provider Vault** stores an API key once under a named entry with one or mo
140
170
  - An entry that is referenced by any profile cannot be deleted (HTTP `409`).
141
171
  - Detach a profile by clearing the provider selection in the profile form; the cached key stays as the profile's own inline key.
142
172
 
143
- ### Configuration drift
173
+ ## Verify and repair configuration
174
+
175
+ ### Test endpoint connectivity
144
176
 
145
- The dashboard's **Configuration drift** panel compares what the active profile would render against the actual files on disk, using parsed-value comparison for JSON/TOML/YAML so a re-render that only reorders keys does not count as drift. Each file is reported as:
177
+ Every place a credential meets a base URL offers a **Test connection** button: the profile form (draft values, before saving), each Provider Vault entry (stored credential, against any of its endpoints), and Doctor's `--probe`. The server sends one lightweight `GET {base}/v1/models` request — falling back to `{base}/models`, and carrying both `Authorization: Bearer` and Anthropic-style headers, so OpenAI- and Anthropic-shaped relays both work.
178
+
179
+ The result reports latency and translates one stable code (`probe.timeout`, `probe.unauthorized`, …) instead of a raw stack trace. A successful probe also returns the endpoint's **model catalog**, which fills the model field's dropdown in the profile form — no more mistyped model names discovered only when the CLI fails. The credential itself never appears in any response; draft keys are tested server-side without saving them first.
180
+
181
+ ### Detect configuration drift
182
+
183
+ The dashboard **Diagnostics** panel also compares what the active profile would render against the actual files on disk, using parsed-value comparison for JSON/TOML/YAML so a re-render that only reorders keys does not count as drift. Each file is reported as:
146
184
 
147
185
  - `in-sync` — disk matches what the profile would write,
148
186
  - `drifted` — disk differs from what the profile would write,
@@ -155,15 +193,17 @@ Two repair actions are offered per harness:
155
193
  - **Re-apply** rewrites the live files from the active profile, with the usual backup-before-write and all-or-nothing rollback.
156
194
  - **Adopt live configuration** reads the live files back into the profile record (same path as the pre-switch backfill). It refuses with `409` when the profile has manual raw overrides, and never adopts content the tool itself could not parse.
157
195
 
158
- ### Diagnostics (Doctor)
196
+ ### Run diagnostics
197
+
198
+ **Diagnostics (Doctor)** run per harness from that tool’s right-hand column: for CLI-delivered tools, whether the executable is on `PATH` (`install`; skipped for web-service harnesses such as DeepSeek Harness), whether each target file exists and is readable/writable (`files`, with a warning when a config file holding credentials is group/other-readable), whether the files parse (`parse`), and whether live state drifts from the active profile (`drift`). A global update check reports whether a newer release exists (`updatedAvailable`).
159
199
 
160
- The **Diagnostics (Doctor)** panel runs read-only checks per harness: whether the tool's CLI is on `PATH` (`install`), whether each target's config directory exists (`configDir`), whether each target file exists and is readable/writable (`files`, with a warning when a config file holding credentials is group/other-readable), whether the files parse (`parse`), and whether live state drifts from the active profile (`drift`). A global update check reports whether a newer release exists (`updatedAvailable`).
200
+ Passing `--probe` adds one more check per harness: a real request against the active profile's endpoint. Reachable endpoints report `ok` with latency and model count; timeouts, refused credentials and other failures report `error`, since the tool itself would fail too. Harnesses without an active profile skip the check as `unknown`. Probes for all harnesses run concurrently.
161
201
 
162
- The connectivity probe is **disabled by default in the MVP**: passing `--probe` only records a `unknown`-status check that reports the active base URL and explains that no network request is made.
202
+ ## Manage local Unix users
163
203
 
164
- ### Local Unix users
204
+ This optional multi-user feature is for Unix-like hosts. On Windows, harness-switch manages the account that starts it.
165
205
 
166
- The dashboard header can switch between local login users such as `root` and `alice`. Each user has independent profiles, Provider Vault, encryption key, active state and backups under their own home. Selecting a user does not write any harness file; only an explicit activation does.
206
+ The account menu at the right of the dashboard header switches between local login users such as `root` and `alice`, and keeps sign-out alongside those identity actions. Each user has independent profiles, Provider Vault, encryption key, active state and backups under their own home. Selecting a user does not write any harness file; only an explicit activation does.
167
207
 
168
208
  “Sync user config” performs a one-time copy of another user's profiles and referenced Provider Vault credentials into the selected user. Secrets are decrypted only on the server and re-encrypted with the destination user's local key. Active state, backups and native config files are not copied. Same-name profiles are skipped by default and can be explicitly overwritten.
169
209
 
@@ -171,7 +211,7 @@ A source user's Codex official-login cache (`auth.json`) is the sole optional ex
171
211
 
172
212
  Cross-user writes require access to the destination home. Managing both `root` and regular users therefore normally requires running harness-switch as root; newly created files and directories are assigned to the destination UID/GID. The Web password then grants control over every exposed user's configs, so keep the loopback bind and SSH tunnel. Use `HSW_USERS=root,alice` to restrict the manageable accounts.
173
213
 
174
- ### CLI automation
214
+ ## Automate with the CLI
175
215
 
176
216
  The CLI talks to the running local daemon and uses the same authenticated HTTP API as the Web UI. Start the daemon once before using API-backed commands. `help` and `version` work offline; data commands support `--json` (or `-j`) for scripting:
177
217
 
@@ -257,6 +297,7 @@ The UI is a React SPA. Authentication uses an HttpOnly `hsw_session` cookie.
257
297
  | `DELETE` | `/api/harnesses/:id/profiles/:name` | Delete; `409` for the active profile |
258
298
  | `GET` | `/api/harnesses/:id/profiles/:name/preview` | The exact content that would be written |
259
299
  | `POST` | `/api/harnesses/:id/profiles/:name/activate` | Write the native config, then commit the switch |
300
+ | `POST` | `/api/harnesses/:id/profiles/:name/probe` | Test the stored credential against the stored base URL |
260
301
  | `POST` | `/api/harnesses/:id/official/activate` | Return a supported harness to its built-in account login |
261
302
  | `GET` | `/api/backups` | Snapshots, newest first |
262
303
  | `POST` | `/api/backups/:id/restore` | Restore a snapshot verbatim |
@@ -266,35 +307,37 @@ The UI is a React SPA. Authentication uses an HttpOnly `hsw_session` cookie.
266
307
  | `GET` | `/api/providers` | Provider Vault entries (no key material) |
267
308
  | `POST` | `/api/providers` | Create a vault entry |
268
309
  | `PATCH` | `/api/providers/:id` | Update; re-applies referencing active profiles |
310
+ | `POST` | `/api/providers/:id/probe` | Test the stored key against an endpoint (`{ "endpoint": "key" }`, default first) |
269
311
  | `DELETE` | `/api/providers/:id` | Delete; `409` while referenced by a profile |
312
+ | `POST` | `/api/probe` | Test unsaved values: `{ "baseUrl", "apiKey" }` or `{ "baseUrl", "providerId" }`, stored nowhere |
270
313
  | `GET` | `/api/drift` | Drift report for every harness |
271
314
  | `POST` | `/api/drift/:harnessId/reapply` | Rewrite live files from the active profile |
272
315
  | `POST` | `/api/drift/:harnessId/adopt` | Read live files back into the profile record |
273
- | `GET` | `/api/doctor` | Read-only diagnostics (`?probe=1` includes the MVP-disabled, non-network probe check) |
316
+ | `GET` | `/api/doctor` | Read-only diagnostics (`?probe=1` also tests each active profile's endpoint) |
274
317
  | `GET` | `/api/scan` | Providers the five tools already have on disk; read-only, credentials masked |
275
318
  | `POST` | `/api/scan/import` | Save selected candidates as profiles or vault entries; the tools' own config is untouched |
276
- | `GET` | `/api/operations` | Operation receipts, newest first |
319
+ | `GET` | `/api/operations` | Operation receipts, newest first (`?harness=claude` to filter) |
277
320
  | `GET` | `/api/operations/:id` | One receipt |
278
321
  | `POST` | `/api/operations/:id/undo` | Put the native files and the active profile back to before that operation |
279
322
 
280
323
  Every POST/PATCH body is validated against a shared Zod schema (`packages/shared/src/schemas.ts`) that the server and the web client both build on. A malformed shape is rejected with a `400` naming the field *before* it reaches storage, instead of being persisted and only surfacing as a `500` on the next activation. Unknown fields are dropped rather than rejected, so an older client keeps working while nothing unrecognised enters the store.
281
324
 
282
- ## Background daemon (bunx / npx / pnpm)
325
+ ## Background daemon (npx / pnpm / Bun)
283
326
 
284
327
  The published CLI runs as a background daemon by default: the command returns
285
328
  immediately, the server keeps running after the terminal is closed, and
286
329
  re-running after a release restarts the daemon on the newest version.
287
330
 
288
331
  ```bash
289
- bunx @seaveyon/harness-switch@latest # start, or update + restart the daemon
290
- bunx @seaveyon/harness-switch@latest status # pid, url, log path
291
- bunx @seaveyon/harness-switch@latest stop # stop the daemon
292
- bunx @seaveyon/harness-switch@latest server # run in the foreground instead
293
- bunx @seaveyon/harness-switch@latest list # CLI automation (see above)
332
+ npx -y @seaveyon/harness-switch@latest # start, or update + restart the daemon
333
+ npx -y @seaveyon/harness-switch@latest status # pid, url, log path
334
+ npx -y @seaveyon/harness-switch@latest stop # stop the daemon
335
+ npx -y @seaveyon/harness-switch@latest server # run in the foreground instead
336
+ npx -y @seaveyon/harness-switch@latest list # CLI automation (see above)
294
337
  ```
295
338
 
296
- Replace `bunx` with `npx -y`, `pnpm dlx`, or `pnpx` as preferred. Append `@latest`
297
- so the package runner fetches the newest release before running. Bun remains the runtime used by the installed executable.
339
+ Replace `npx -y` with `pnpm dlx`, `pnpx`, or `bunx` as preferred. Append `@latest`
340
+ so the package runner fetches the newest release before running. The same executable supports both Node.js and Bun; use `node dist/harness-switch.js` or `bun dist/harness-switch.js` when running an installed build directly.
298
341
 
299
342
  The daemon writes its PID, instance identity, and listening address to `~/.harness-switch/daemon.pid` and its log to
300
343
  `~/.harness-switch/daemon.log` (a fresh log per start). The first run creates
@@ -305,8 +348,7 @@ new process, so the port never conflicts and the newest code wins.
305
348
  Startup reports success only after the new process answers `/healthz`. `status` returns a non-zero exit code when the recorded daemon is not healthy. Before `stop` or an update sends a signal, the recorded instance identity is verified so a stale, reused PID cannot terminate an unrelated process.
306
349
 
307
350
  The dashboard polls the npm registry and shows a one-click **update button**
308
- next to the version badge when a newer release exists; it runs the same
309
- `bunx <package>@latest` restart under the hood and reloads the page once the
351
+ next to the version badge when a newer release exists; it uses `npx -y` under Node.js or `bun x` under Bun to restart, then reloads the page once the
310
352
  new version is up. Update logs land in `~/.harness-switch/update.log`.
311
353
 
312
354
  Under systemd (or any supervisor), run the CLI in the foreground instead: