@seaveyon/harness-switch 0.2.0 → 0.3.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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@seaveyon/harness-switch)
|
|
4
4
|
|
|
5
|
-
**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**, **
|
|
5
|
+
**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**, and **oh-my-pi**.
|
|
6
6
|
|
|
7
7
|
It is a configuration manager, not an API proxy: it does not route or inspect model traffic.
|
|
8
8
|
|
|
@@ -33,29 +33,58 @@ Then open <http://127.0.0.1:8787> in your local browser.
|
|
|
33
33
|
|
|
34
34
|
## Configuration
|
|
35
35
|
|
|
36
|
-
Create one or more profiles per harness in the web UI. A profile
|
|
36
|
+
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.
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
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.
|
|
39
|
+
|
|
40
|
+
| Harness | File written | Write mode | Takes effect |
|
|
41
|
+
|---|---|---|---|
|
|
42
|
+
| Claude Code | `~/.claude/settings.json` (`env` block) | replace | Immediately; Claude Code re-reads the file and its `env` values win over inherited shell variables |
|
|
43
|
+
| Codex | `$CODEX_HOME/config.toml`, plus `auth.json` only if you pick that auth mode | replace | Next `codex` start |
|
|
44
|
+
| Kimi Code | `$KIMI_CODE_HOME/config.toml` (`~/.kimi-code`) | additive | Next `kimi` start |
|
|
45
|
+
| oh-my-pi | `~/.omp/agent/models.yml` and `config.yml` | additive | Next `omp` start |
|
|
46
|
+
|
|
47
|
+
**Replace mode** means the file holds exactly one provider, so activating replaces it. **Additive mode** means the file holds many providers plus a pointer to the current one, so activating only moves that pointer and leaves providers you wrote by hand alone.
|
|
48
|
+
|
|
49
|
+
Notes on individual harnesses:
|
|
50
|
+
|
|
51
|
+
- **Claude Code** defaults to `ANTHROPIC_AUTH_TOKEN`, which is what most third-party relays require. Switch the profile to `ANTHROPIC_API_KEY` for the official API.
|
|
52
|
+
- **Codex** defaults to putting the token in `config.toml` as `experimental_bearer_token`. The alternative that writes `auth.json` will overwrite your ChatGPT login cache, so it is opt-in; the previous `auth.json` is captured in a backup first either way.
|
|
53
|
+
- **Kimi Code** (`~/.kimi-code`) is a different product from Kimi CLI (`~/.kimi`), even though both provide a `kimi` command. This project targets Kimi Code, which does not read credentials from the shell at all.
|
|
54
|
+
- **oh-my-pi** has no single "current provider" key. Activating registers the provider in `models.yml` and moves it to the front of `modelProviderOrder`, which is what breaks ties between providers offering the same model id. A `--model` flag still overrides it at runtime.
|
|
55
|
+
|
|
56
|
+
`~/.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:
|
|
39
57
|
|
|
40
58
|
```bash
|
|
41
59
|
source ~/.harness-switch/env.sh
|
|
42
60
|
```
|
|
43
61
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
| Kimi Code | Updates `~/.kimi/config.toml` and the shared env file | `KIMI_BASE_URL`, `KIMI_API_KEY`, `KIMI_MODEL` |
|
|
62
|
+
Two known limitations:
|
|
63
|
+
|
|
64
|
+
- 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.
|
|
65
|
+
- The web UI changes files on the **server**. It cannot touch an already-running shell or your local machine.
|
|
66
|
+
|
|
67
|
+
### Advanced: taking over the raw file
|
|
51
68
|
|
|
52
|
-
|
|
69
|
+
Any field the form does not expose can be set by editing the raw file content in the profile's **高级:原始配置** section. Once edited, that file is generated from your text instead of the form fields until you select **恢复为自动生成**. Content that cannot be parsed back is rejected before it reaches disk.
|
|
70
|
+
|
|
71
|
+
### Backups and rollback
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
A write either lands completely or not at all: content is validated first, and a failure part way through restores the previous state, deleting files that did not exist before rather than leaving them empty.
|
|
76
|
+
|
|
77
|
+
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.
|
|
53
78
|
|
|
54
79
|
## Security
|
|
55
80
|
|
|
56
81
|
The service defaults to loopback only. Do **not** expose the management port directly to the public Internet. Use SSH port forwarding or a TLS-enabled reverse proxy with additional access control.
|
|
57
82
|
|
|
58
|
-
API keys are encrypted with AES-256-GCM in `~/.harness-switch/profiles.json`; the local encryption key lives in `~/.harness-switch/aes-256-gcm.key`.
|
|
83
|
+
API keys are encrypted with AES-256-GCM in `~/.harness-switch/profiles.json`; the local encryption key lives in `~/.harness-switch/aes-256-gcm.key`. Those files, the generated password, and `env.sh` are stored with permissions set to `0600` on POSIX systems. When writing a harness's own configuration file, existing permissions are preserved and newly created files start at `0600`.
|
|
84
|
+
|
|
85
|
+
Two places deliberately expose a key to an authenticated session: the raw config preview and the generated files themselves must contain the credential to be useful. Profile listings never echo it.
|
|
86
|
+
|
|
87
|
+
This protects against accidental plaintext disclosure in profile storage, but does not replace host-level controls such as disk encryption and a secure Unix account.
|
|
59
88
|
|
|
60
89
|
## Environment variables
|
|
61
90
|
|
|
@@ -63,10 +92,13 @@ API keys are encrypted with AES-256-GCM in `~/.harness-switch/profiles.json`; th
|
|
|
63
92
|
|---|---:|---|
|
|
64
93
|
| `HOST` | `127.0.0.1` | Bind address. Keep the default when using SSH tunnelling. |
|
|
65
94
|
| `PORT` | `8787` | Listening port. |
|
|
66
|
-
| `HSW_DATA_DIR` | `~/.harness-switch` | Directory for encrypted profiles, active state, key, password, and env file. |
|
|
67
|
-
| `HSW_HOME_DIR` | `$HOME` | Home directory used
|
|
95
|
+
| `HSW_DATA_DIR` | `~/.harness-switch` | Directory for encrypted profiles, active state, key, password, backups, and env file. |
|
|
96
|
+
| `HSW_HOME_DIR` | `$HOME` | Home directory used to locate the harness config directories. |
|
|
97
|
+
| `HSW_BACKUP_RETAIN` | `10` | Number of snapshots to keep. |
|
|
68
98
|
| `HSW_PUBLIC_DIR` | auto | Optional override for the built frontend directory. |
|
|
69
99
|
|
|
100
|
+
The tools' own overrides are honoured when locating their config: `CODEX_HOME`, `KIMI_CODE_HOME`, and `PI_CODING_AGENT_DIR`.
|
|
101
|
+
|
|
70
102
|
## HTTP API
|
|
71
103
|
|
|
72
104
|
The UI is a React SPA. Authentication uses an HttpOnly `hsw_session` cookie.
|
|
@@ -77,12 +109,15 @@ The UI is a React SPA. Authentication uses an HttpOnly `hsw_session` cookie.
|
|
|
77
109
|
| `POST` | `/api/auth/login` | `{ "password": "..." }` |
|
|
78
110
|
| `POST` | `/api/auth/logout` | Clears the session cookie |
|
|
79
111
|
| `GET` | `/api/auth/session` | `401` when unauthenticated |
|
|
80
|
-
| `GET` | `/api/harnesses` | Collection with nested profiles |
|
|
112
|
+
| `GET` | `/api/harnesses` | Collection with nested profiles, form field specs, and live file paths |
|
|
81
113
|
| `GET` | `/api/harnesses/:id` | One harness |
|
|
82
114
|
| `POST` | `/api/harnesses/:id/profiles` | Create |
|
|
83
|
-
| `PATCH` | `/api/harnesses/:id/profiles/:name` | Update; omit `apiKey` to keep the stored secret |
|
|
84
|
-
| `DELETE` | `/api/harnesses/:id/profiles/:name` | Delete |
|
|
85
|
-
| `
|
|
115
|
+
| `PATCH` | `/api/harnesses/:id/profiles/:name` | Update; omit `apiKey` to keep the stored secret. Rewrites the live files when the profile is active |
|
|
116
|
+
| `DELETE` | `/api/harnesses/:id/profiles/:name` | Delete; `409` for the active profile |
|
|
117
|
+
| `GET` | `/api/harnesses/:id/profiles/:name/preview` | The exact content that would be written |
|
|
118
|
+
| `POST` | `/api/harnesses/:id/profiles/:name/activate` | Write the native config, then commit the switch |
|
|
119
|
+
| `GET` | `/api/backups` | Snapshots, newest first |
|
|
120
|
+
| `POST` | `/api/backups/:id/restore` | Restore a snapshot verbatim |
|
|
86
121
|
|
|
87
122
|
## systemd
|
|
88
123
|
|