@seaveyon/harness-switch 0.1.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,20 +2,22 @@
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/%40seaveyon%2Fharness-switch.svg)](https://www.npmjs.com/package/@seaveyon/harness-switch)
4
4
 
5
- **harness-switch** is a dependency-free Node.js 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**, **pi**, **Codex**, **zcode**, and **Kimi 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
 
9
9
  ## Install and run
10
10
 
11
+ Requires [Bun](https://bun.sh) >= 1.2.
12
+
11
13
  ```bash
12
- npx @seaveyon/harness-switch
14
+ bunx @seaveyon/harness-switch
13
15
  ```
14
16
 
15
17
  Or install it globally:
16
18
 
17
19
  ```bash
18
- npm install -g @seaveyon/harness-switch
20
+ bun add -g @seaveyon/harness-switch
19
21
  harness-switch
20
22
  ```
21
23
 
@@ -31,29 +33,58 @@ Then open <http://127.0.0.1:8787> in your local browser.
31
33
 
32
34
  ## Configuration
33
35
 
34
- Create one or more profiles per harness in the web UI. A profile contains a display name, API Base URL, API key, model, and notes. Select **Activate** to make a profile current.
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
+
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:
35
50
 
36
- Every activation writes `~/.harness-switch/env.sh`. In the exact SSH shell that launches a harness, load it with:
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:
37
57
 
38
58
  ```bash
39
59
  source ~/.harness-switch/env.sh
40
60
  ```
41
61
 
42
- | Harness | Activation behaviour | Environment variables |
43
- |---|---|---|
44
- | Claude Code | Updates `~/.claude/settings.json` and the shared env file | `ANTHROPIC_BASE_URL`, `ANTHROPIC_API_KEY`, `ANTHROPIC_MODEL` |
45
- | Codex | Writes the shared env file without overwriting complex native config | `OPENAI_BASE_URL`, `OPENAI_API_KEY`, `CODEX_MODEL` |
46
- | pi | Writes the shared env file without overwriting custom provider files | `PI_API_BASE`, `PI_API_KEY`, `PI_MODEL` |
47
- | zcode | Writes the shared env file; variable names are a portable bridge | `ZCODE_BASE_URL`, `ZCODE_API_KEY`, `ZCODE_MODEL` |
48
- | 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
68
+
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.
49
70
 
50
- > The web UI changes files on the **server**; it cannot modify an existing parent shell or the browser computer. Source the generated file again after changing profiles, or use a new shell session.
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.
51
78
 
52
79
  ## Security
53
80
 
54
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.
55
82
 
56
- 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`. Both files, the generated password, and `env.sh` are stored with permissions set to `0600` on POSIX systems. 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.
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.
57
88
 
58
89
  ## Environment variables
59
90
 
@@ -61,7 +92,32 @@ API keys are encrypted with AES-256-GCM in `~/.harness-switch/profiles.json`; th
61
92
  |---|---:|---|
62
93
  | `HOST` | `127.0.0.1` | Bind address. Keep the default when using SSH tunnelling. |
63
94
  | `PORT` | `8787` | Listening port. |
64
- | `HSW_DATA_DIR` | `~/.harness-switch` | Directory for encrypted profiles, active state, key, password, and env file. |
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. |
98
+ | `HSW_PUBLIC_DIR` | auto | Optional override for the built frontend directory. |
99
+
100
+ The tools' own overrides are honoured when locating their config: `CODEX_HOME`, `KIMI_CODE_HOME`, and `PI_CODING_AGENT_DIR`.
101
+
102
+ ## HTTP API
103
+
104
+ The UI is a React SPA. Authentication uses an HttpOnly `hsw_session` cookie.
105
+
106
+ | Method | Path | Notes |
107
+ |---|---|---|
108
+ | `GET` | `/healthz` | Liveness |
109
+ | `POST` | `/api/auth/login` | `{ "password": "..." }` |
110
+ | `POST` | `/api/auth/logout` | Clears the session cookie |
111
+ | `GET` | `/api/auth/session` | `401` when unauthenticated |
112
+ | `GET` | `/api/harnesses` | Collection with nested profiles, form field specs, and live file paths |
113
+ | `GET` | `/api/harnesses/:id` | One harness |
114
+ | `POST` | `/api/harnesses/:id/profiles` | Create |
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 |
65
121
 
66
122
  ## systemd
67
123
 
@@ -97,14 +153,63 @@ sudo journalctl -u harness-switch -f
97
153
 
98
154
  ## Development
99
155
 
156
+ This is a Bun workspace:
157
+
158
+ ```text
159
+ apps/web React + Zustand + shadcn/ui, built with Rspack
160
+ apps/server Hono + VS Code-style DI, published as @seaveyon/harness-switch
161
+ packages/shared Shared TypeScript types
162
+ ```
163
+
100
164
  ```bash
101
165
  git clone <your-repository-url>
102
166
  cd harness-switch
103
- npm test
104
- npm start
105
- npm pack --dry-run
167
+ bun install
168
+ bun run test
169
+ bun run check
170
+ bun run dev:server
171
+ bun run dev:web
172
+ ```
173
+
174
+ Linting and formatting are split: **Oxlint** for diagnostics, **Biome** for format and import organization.
175
+
176
+ ```bash
177
+ bun run lint
178
+ bun run lint:fix
179
+ bun run format
180
+ bun run format:check
181
+ bun run check
182
+ ```
183
+
184
+ `bun install` installs a git `pre-commit` hook that runs `bun run check` and `bun run test`. Commits are blocked if either step fails. To run the same gate manually:
185
+
186
+ ```bash
187
+ bun run precommit
188
+ ```
189
+
190
+ Production build (frontend assets are copied into `apps/server/public`, then the CLI is bundled):
191
+
192
+ ```bash
193
+ bun run build
194
+ bun run start
195
+ bun run pack:check
106
196
  ```
107
197
 
198
+ The web dev server listens on `http://127.0.0.1:5173` and proxies `/api` to the backend on `8787`.
199
+
200
+ ## Release
201
+
202
+ Pushes to `main` run [semantic-release](https://semantic-release.gitbook.io/). It reads conventional commits, bumps `@seaveyon/harness-switch`, tags `v*`, and publishes to npm via Trusted Publishing.
203
+
204
+ | Commit | Version bump |
205
+ |---|---|
206
+ | `fix:` | patch (`0.1.0` → `0.1.1`) |
207
+ | `feat:` | minor (`0.1.0` → `0.2.0`) |
208
+ | `feat!:` / `BREAKING CHANGE:` | major (`0.2.0` → `1.0.0`) |
209
+ | `chore:` / `ci:` / `docs:` | no release |
210
+
211
+ You can also run **Publish npm** manually from the Actions tab (`workflow_dispatch`). Commits that do not need a release will no-op.
212
+
108
213
  ## License
109
214
 
110
215
  [MIT](./LICENSE)