@ubercode/channelvault 0.3.0-rc.3 → 0.3.0-rc.4

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/CHANGELOG.md CHANGED
@@ -2,6 +2,37 @@
2
2
 
3
3
  All notable changes to `@ubercode/channelvault` are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the version follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
4
4
 
5
+ ## [0.3.0-rc.4] — 2026-11-27
6
+
7
+ Release candidate, published under the npm `next` tag.
8
+
9
+ ### Added
10
+
11
+ - **Connection profiles.** `~/.channelvault/profiles.json` names each server's host, port, user, TLS pin, installation and env file, with no secrets; `~/.channelvault/credentials` holds the passwords, owner-only. A command takes its connection from exactly one source, in order: `--profile`, the login flags, `MIRTH_PROFILE`, `MIRTH_HOST`, then the profile whose installation matches the tree. So any checkout or worktree, and an agent's fresh shell, reaches the right server without flags, and two servers are told apart by their installation ID. See the README's "Connection profiles".
12
+ - `profile list`, `profile add`, `profile set-password`, `profile check` and `profile repin`. `add`, `set-password` and `repin` run only at a terminal; passwords need 8 characters and are never echoed.
13
+ - **TLS certificate pinning.** A profile pins its server certificate's SHA-256 fingerprint, checked during the handshake: on a mismatch the connection closes before anything (including the login) is sent. `--tls-fingerprint` / `MIRTH_TLS_FINGERPRINT` do the same without a profile. When a certificate is untrusted, the hint now prints the fingerprint it presents and suggests pinning it before `--insecure`.
14
+ - Live commands print one `connection:` line on stderr after verifying the server: the profile, URL, user, installation, how the connection was chosen, where the password came from, the TLS mode and the env file. `diff --json` and `push --plan-only --json` gain `serverId` and `connection`; `status --json` gains `serverId` and, without connecting, which profile a read would use and whether its password is configured.
15
+ - Errors carry a reason code, as `error: [reason] message`.
16
+ - A profile's `dotenv` serves every checkout of its trees when a tree has no `.env` of its own; a different local `.env` is refused rather than guessed between.
17
+ - `AGENTS.md` with the repository's conventions for coding agents.
18
+
19
+ ### Changed
20
+
21
+ - **Real writes need a typed profile.** `push` (without `--plan-only`), `restore` and `adopt` refuse a profile chosen by the tree's installation; `MIRTH_PROFILE` selects one only when the write is confirmed at a terminal. Printed undo commands use `--profile <name>`.
22
+ - **`adopt` (without `--plan-only`) needs `--profile` or `--host` typed**, since it rebinds the tree; `MIRTH_*` alone is refused with `[connection-not-typed]`. Scripts that adopted with only `MIRTH_*` set must add `--host`.
23
+ - `--port`, `--user` or `--pass` typed without `--host` count as the `MIRTH_HOST` source, with its checks; without `MIRTH_HOST` they are refused.
24
+ - **A typed `--host` no longer borrows `MIRTH_PORT`, `MIRTH_USER` or `MIRTH_PASS` exported for a different `MIRTH_HOST`**: the command stops with `[env-conflict]` instead of sending one server's password to another. Type the matching login flags, or use a profile.
25
+ - `MIRTH_HOST` is refused when the tree, or the server that answers, belongs to a profile, which catches a stale shell variable.
26
+ - `insecure` and plain http are refused in a profile for any host but loopback, and a typed `--insecure` beside a pin is refused.
27
+ - An empty `MIRTH_*` variable counts as unset.
28
+
29
+ ### Fixed
30
+
31
+ - `pull` refused nothing when the server was another installation than the tree's: a stale `MIRTH_HOST` could rewrite one server's tree as another's, and its next push would then pass the installation check. It now refuses (`[installation-mismatch]`), whichever way the connection was chosen.
32
+ - `diff` against another installation printed a whole-server difference; it now refuses with exit 2.
33
+ - The connection password was never redacted from output. It is now removed from error text, and when it has 8 or more characters, from every line on stdout and stderr.
34
+ - Recovering an interrupted pull whose env file is a profile's no longer needs the original `--dotenv`, and a pull locks a profile env file outside the tree so two worktrees cannot write it at once. Other commands refuse to read that file while a pull elsewhere is replacing it (`[env-busy]`).
35
+
5
36
  ## [0.3.0-rc.3] — 2026-11-27
6
37
 
7
38
  Release candidate, published under the npm `next` tag.
@@ -90,6 +121,7 @@ First release. Tested against Mirth Connect 4.5.2; the offline round trip is als
90
121
  - `backup` / `restore`: the server's own configuration XML saved as `.backup/<server>-<UTC time>.xml`, identified by Mirth's server ID, restored with a preview, an undo backup and a version check. `push` backs up first unless `--no-backup`.
91
122
  - `diff` exits 0 when the tree matches the server, 1 when it differs, 2 on error.
92
123
 
124
+ [0.3.0-rc.4]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.3.0-rc.4
93
125
  [0.3.0-rc.3]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.3.0-rc.3
94
126
  [0.3.0-rc.2]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.3.0-rc.2
95
127
  [0.3.0-rc.1]: https://github.com/MichaelLeeHobbs/channelvault/releases/tag/v0.3.0-rc.1
package/README.md CHANGED
@@ -77,22 +77,51 @@ channelvault diff <dir> # tree vs live server
77
77
  channelvault status <dir> # summary of a tree
78
78
  channelvault backup # live server -> ~/.channelvault/backups/<server>-<UTC time>.xml
79
79
  channelvault restore [file] # backup -> live server (default: newest of this server)
80
+ channelvault profile list|add|set-password|check|repin # saved connections (see Connection profiles)
80
81
  ```
81
82
 
82
- `channelvault <command> --help` lists the flags. Server connection comes from flags or `MIRTH_HOST`, `MIRTH_PORT`, `MIRTH_USER`, `MIRTH_PASS`; prefer the env var over `--pass`, which shows up in process listings. Mirth's default certificate is self-signed; `--insecure` accepts it by turning verification off.
83
+ `channelvault <command> --help` lists the flags. The server connection comes from a saved profile (`--profile`, `MIRTH_PROFILE`, or the profile matching the tree), or from the login flags and `MIRTH_HOST`, `MIRTH_PORT`, `MIRTH_USER`, `MIRTH_PASS`; see [Connection profiles](#connection-profiles). Errors start with a reason code in brackets, such as `error: [profile-not-typed] …`, for scripts and agents to route on.
83
84
 
84
85
  `diff` exits 0 when the tree matches the server, 1 when they differ, and 2 on any error (including a bad flag), so a scheduled drift check can tell drift from an outage. It compares content: Mirth bumps revision numbers and timestamps on any save (even an unchanged one in the Administrator) and on a restore, so those are reported as a note ("pull to update the tree's baseline") and don't count as differences.
85
86
 
86
87
  For scripts, CI and AI agents, `status`, `diff` and `push --plan-only` take `--json` and print one JSON document on stdout; errors still go to stderr with the usual exit code.
87
88
 
88
- - `status --json`: `{ root, source, pulledAt, engineVersion, counts }`.
89
- - `diff --json`: `{ clean, files: [{ path, change }], secretDrift, staleRevisions, notes, patch }`, where `change` is `modified`, `only-in-tree` or `only-on-server` and `patch` is the redacted unified diff.
90
- - `push --plan-only --json`: `{ target, mode, changes: [{ kind, op, id, label }], conflicts, serverOnly, notPushed, wouldStop }` (plus `redeploy` and `notRedeployed` with `--deploy`). `wouldStop` lists what would refuse a real push with the same flags, such as unconfirmed deletions or conflicts.
89
+ - `status --json`: `{ root, source, pulledAt, engineVersion, serverId, connection, counts }`. Without connecting, `connection` says which profile a read would use and whether its password is configured (`{ profile, url, user, source, passwordConfigured }`), or why there is none (`{ problem }`).
90
+ - `diff --json`: `{ clean, serverId, connection, files: [{ path, change }], secretDrift, staleRevisions, notes, patch }`, where `change` is `modified`, `only-in-tree` or `only-on-server` and `patch` is the redacted unified diff.
91
+ - `push --plan-only --json`: `{ target, mode, serverId, connection, changes: [{ kind, op, id, label }], conflicts, serverOnly, notPushed, wouldStop }` (plus `redeploy` and `notRedeployed` with `--deploy`). `wouldStop` lists what would refuse a real push with the same flags, such as unconfirmed deletions or conflicts.
92
+ - `connection` in a live command's document is `{ profile, url, user, source, passwordSource, serverId, tlsFingerprint, insecure, envFile }`, never the password. Without `--json`, live commands print the same as one `connection:` line on stderr after verifying the server.
91
93
 
92
94
  `pull` and `explode` replace `server/`, `channels/`, `codeTemplates/` and `channelGroups/` in `<dir>`, so they refuse a directory that has any of those but no `channelvault.json`, an unreadable `channelvault.json`, or a `--dotenv` file inside one of those directories. All of this is checked before anything is written.
93
95
 
94
96
  Replacement is staged with its metadata, ignore rules, secret history and env updates. The previous generation is retained until every swap completes; a failed swap rolls back the whole generation. After an interrupted process, the next tree command recovers the journal before reading the tree (use the same `--dotenv` selection; `status` accepts it too). Commands hold a working-tree lock, including readers. A live lock refuses another command; abandoned locks belonging to a dead process on this host are recovered. An unreadable lock or a lock from another host requires inspection before removal. The env file may be on another volume and is replaced through files beside it.
95
97
 
98
+ ## Connection profiles
99
+
100
+ A profile saves one server's connection outside every repository and worktree, so any checkout, and any agent's fresh shell, reaches the right server without flags or exported variables.
101
+
102
+ ```
103
+ channelvault profile add gov --host mirth-gov.internal --port 8443 --user deploy --dotenv ~/secrets/mirth-gov.env
104
+ channelvault pull ./mirth --profile gov # first pull records the installation in channelvault.json
105
+ channelvault diff ./mirth # reads: the tree's installation picks the profile
106
+ channelvault push ./mirth --profile gov # writes: the profile must be typed
107
+ ```
108
+
109
+ - **Files.** `~/.channelvault/profiles.json` holds `host`, `port`, `user`, `https`, `insecure`, `tlsFingerprint`, `serverId` and `dotenv` (an absolute path) for each named profile, and no secrets. `~/.channelvault/credentials` holds one `name=password` line per profile, readable by its owner only; nothing in the process environment can override it. `CHANNELVAULT_CONFIG_DIR` moves the folder, but is refused inside a git work tree. Unknown fields are refused by name, and a `password` field is refused with a pointer to `profile set-password`.
110
+ - **Adding one.** `profile add` runs only at a terminal. It shows the host and the certificate's SHA-256 fingerprint, asks you to confirm them, asks for the password (8 characters at least, never echoed), logs in, and records the server's installation ID as `serverId`. `profile set-password <name>` changes the password after logging in with it, `profile list [--json]` shows the profiles without passwords, and `profile check [name] [--json]` logs in with each one and verifies its certificate and installation (exit 1 if any fails).
111
+ - **Which connection a command uses.** Exactly one source, never fields mixed from several, in this order:
112
+ 1. `--profile <name>`. Login or TLS flags beside it are refused.
113
+ 2. The login flags, starting with `--host`, with `MIRTH_*` filling what is not typed. A typed `--host` never borrows `MIRTH_PORT`, `MIRTH_USER`, `MIRTH_PASS` or `MIRTH_TLS_FINGERPRINT` exported for a different `MIRTH_HOST` (`[env-conflict]`). `--port`, `--user` or `--pass` without `--host` still reach `MIRTH_HOST`'s server, so they count as step 4.
114
+ 3. `MIRTH_PROFILE`.
115
+ 4. `MIRTH_HOST` and the other `MIRTH_*` variables, refused when the tree, or the server that answers, belongs to a profile (`[env-shadowed]`): that catches a stale shell variable pointing at the wrong server.
116
+ 5. The profile whose `serverId` matches the tree's `channelvault.json`.
117
+ 6. Otherwise the command fails and lists the profiles. There is no default profile.
118
+ - **Writes need a typed profile.** `push` (without `--plan-only`), `restore` and `adopt` refuse a profile the tree selected (`[profile-not-typed]`), so the command you confirm names the server. `MIRTH_PROFILE` selects a write only when you confirm it at a terminal, where the banner and prompt name the profile and host; with `--yes` the profile must be typed. `adopt` rebinds the tree, so a real adopt needs `--profile` or `--host` typed (`[connection-not-typed]`); `adopt --plan-only` takes any source but the tree. The undo command a push or restore prints uses `--profile <name>` and never `--yes`.
119
+ - **Installation checks, on every source.** An explicit profile must match the tree's `serverId` before connecting (`[profile-mismatch]`). After login, the server's installation ID must equal the profile's `serverId` (`[server-mismatch]`). `pull` refuses to rewrite a tree pulled from another installation, and `diff` refuses to compare against one (exit 2), whichever way the connection was chosen (`[installation-mismatch]`); rebind deliberately with `adopt`.
120
+ - **The env file in worktrees.** A profile's `dotenv` holds the tree's placeholder values for every checkout of it: commands use it when `--dotenv` is not given and the tree has no `.env` of its own (or `.env` is that same file). A different local `.env` is refused (`[env-ambiguous]`); pass `--dotenv` to choose. Two profiles cannot share one `dotenv`. A pull holds a lock on an env file outside the tree, and other commands refuse to read it while a pull in another checkout is replacing it (`[env-busy]`). Recovery after an interrupted pull accepts any env file the tree could have used.
121
+ - **TLS.** Mirth's certificates are self-signed, so a profile pins its certificate's SHA-256 fingerprint instead of trusting a certificate authority. channelvault checks the fingerprint during the TLS handshake and closes the connection on a mismatch before sending anything, so the login never reaches an impostor (`[tls-pin-mismatch]`, showing both fingerprints). After the administrator replaces the certificate, run `profile repin <name>` at a terminal. `insecure` and plain http are refused in a profile for anything but a loopback host. Without a profile, `--tls-fingerprint` or `MIRTH_TLS_FINGERPRINT` pins the same way, and a typed `--insecure` beside a pin is refused; when a certificate is untrusted, the hint prints the fingerprint it presents to pin.
122
+ - **Output.** channelvault never prints the connection password. Every line it writes, stdout included, has a password of 8 or more characters replaced by `<redacted>`; a shorter one is removed from error text only.
123
+ - **What this does and does not guarantee.** channelvault never shows the password and never needs it on a command line or in the environment. It is stored in plain text in the credentials file: on Windows, another program running as you (including an agent with a shell) can read it. Deny rules in an agent's settings guide its tools; they are not an operating-system boundary.
124
+
96
125
  ## Secrets and per-environment values
97
126
 
98
127
  `explode` and `pull` keep the credentials they detect out of the tree. Detection is heuristic (see below), so review a first pull of a real server before committing it. Fields named like credentials (passwords, passphrases, passcodes, tokens, secrets, API/access/private keys, and DICOM's `keyPW`, `keyStorePW` and `trustStorePW`), and every configuration-map value, become `{{env:NAME}}` placeholders, and their values go to `<dir>/.env`, which is added to the tree's `.gitignore`. `push` and `implode` fill the placeholders back in and refuse to run if any are missing, naming each one.
@@ -124,13 +153,13 @@ channelvault push ./mirth --library Formatting --deploy # one library, then red
124
153
  - **Deletions** (a channel directory or template you removed) need `--allow-deletes`. Something created on the server since your last pull is never treated as a deletion; `push` leaves it alone and says so. Library saves retain server-only templates and their membership, including with `--force`. Deleting a library containing unfamiliar templates is refused; pull and review them first.
125
154
  - **Conflicts**: if the server's copy has a newer revision than your tree (someone saved it in the Administrator since your last pull), `push` refuses. Pull, merge in git, and push again, or pass `--force`.
126
155
  Push rechecks its plan after the backup and checks each resource immediately before saving or deleting it. These checks include content changes and revision resets, and library-list saves check every library. Restore and whole-server push also recheck after their backup. The check and write are separate API requests: use a single-writer change window to exclude Administrator edits and other deployment clients during production writes.
127
- - **Installation baseline**: `pull` records Mirth's installation ID. Push refuses a different or unknown installation even with `--force`; revision numbers from another server are unrelated. For promotion, copy the tree, point the connection at the destination (`MIRTH_HOST`, `MIRTH_PORT`, `MIRTH_USER`, `MIRTH_PASS` or the connection flags; `--dotenv` supplies only the tree's placeholder values, never the login), review `channelvault adopt ./mirth --dotenv .env.prod --plan-only`, then run the same command with `--yes` instead of `--plan-only`. Adoption writes no server resources: it preserves local content and placeholders, captures destination revisions and the global-script baseline, and leaves destination-only resources unfamiliar. It rechecks the target before committing the local baseline. Review `push --plan-only` again before pushing. Older trees without an installation ID require a fresh pull with a merge, or this explicit adoption.
156
+ - **Installation baseline**: `pull` records Mirth's installation ID. Push refuses a different or unknown installation even with `--force`; revision numbers from another server are unrelated. For promotion, copy the tree, review `channelvault adopt ./mirth --profile prod --dotenv .env.prod --plan-only` (or the login flags instead of `--profile`; `--dotenv` supplies only the tree's placeholder values, never the login), then run the same command with `--yes` instead of `--plan-only`. Adoption writes no server resources: it preserves local content and placeholders, captures destination revisions and the global-script baseline, and leaves destination-only resources unfamiliar. It rechecks the target before committing the local baseline. Review `push --plan-only` again before pushing. Older trees without an installation ID require a fresh pull with a merge, or this explicit adoption.
128
157
  - **Snapshots**: live reads require the configuration wrapper, an engine version, and a valid channels collection. Present library, template and group collections are checked too. Empty or malformed success responses are refused before tree replacement or push planning; valid empty collections and plugin fields are preserved.
129
158
  - **`--deploy`** redeploys the channels that changed and the channels a changed code-template library is enabled for, but only those deployed when planning and still deployed immediately before their redeploy. Channels taken down during the push are skipped and reported. Status-read failures prevent that channel's redeploy and are reported per channel. Keep a single-writer change window: Mirth's status check and deployment are separate requests.
130
159
  - After a push the tree's revision numbers are updated from the server, so `diff` and the next `push` stay clean.
131
160
  - Server settings, the configuration map, channel groups and tags are **not** pushed; `push` names them if they differ. `--whole-server` replaces the entire server configuration instead. It shows the same change list and needs the same `--allow-deletes` / `--force`, and it can't be combined with `--channel` or `--library`.
132
161
  - A tree exploded from an XML backup is refused (its shape differs from the live API's); `--ignore-origin` overrides that.
133
- - Before it changes anything, `push` backs up the server (see below) and prints a configuration undo command with the original target, TLS options, user and backup directory. It includes `--overwrite-config-map` when the push overwrites that map. Passwords are omitted; supply the server's credential through `MIRTH_PASS`. `--no-backup` skips the backup. Backups do not capture runtime deployment state; review targeted redeployment separately after a configuration undo.
162
+ - Before it changes anything, `push` backs up the server (see below) and prints a configuration undo command with the original target (`--profile <name>`, or the host, port, user and TLS options), and the backup directory. It includes `--overwrite-config-map` when the push overwrites that map. Passwords are omitted; without a profile, supply the server's credential through `MIRTH_PASS`. `--no-backup` skips the backup. Backups do not capture runtime deployment state; review targeted redeployment separately after a configuration undo.
134
163
  - Without a terminal, `push` needs `--yes`.
135
164
  - `--plan-only` shows the plan and what would stop it, and changes nothing: no prompt, no backup, no writes. It works without a terminal.
136
165
 
@@ -178,11 +207,31 @@ An agent can safely edit a tree and check its work. Pushing, restoring and anyth
178
207
 
179
208
  - Edit the `.js` and `.json` files; leave `id`, `revision`, `channelvault.json` and the `{"@file": …}` / `{"@ref": …}` markers alone. A new channel or template needs its own new UUID for `id`; a copied directory keeps the old one.
180
209
  - Mirth runs these scripts in Rhino, not Node: no `async`/`await`, optional chaining (`?.`), classes, `require`, `import` or shorthand object properties (`{ status }`; write `{ status: status }`). `let`, `const` and arrow functions work.
181
- - `{{env:NAME}}` is a placeholder for a secret kept outside git. Never replace one with a real value, and never read, print or copy `.env`, `.secrets/`, `.backup/` or `~/.channelvault/backups/`.
210
+ - `{{env:NAME}}` is a placeholder for a secret kept outside git. Never replace one with a real value, and never read, print or copy `.env`, `.secrets/`, `.backup/`, `~/.channelvault/credentials`, a profile's env file or `~/.channelvault/backups/`.
211
+ - channelvault finds the server itself: the tree's `channelvault.json` names its installation, and the matching connection profile supplies the login. Don't pass `--host`, `--pass` or `--insecure`, and don't set `MIRTH_*` variables. If a command fails with a reason code such as `[no-connection]`, `[no-password]` or `[tls-pin-mismatch]`, stop and tell a person; only they can add a profile, set its password or repin its certificate.
182
212
  - Check your work with `channelvault diff mirth --json` (exit 0: matches the server, 1: differs) and `channelvault push mirth --plan-only --json`, which shows what a push would change and `wouldStop` reasons.
183
213
  - Do not run `channelvault push` (other than with `--plan-only`), `restore` or `pull`, and never pass `--force`, `--allow-deletes` or `--yes`. Summarise the plan and let a person push.
184
214
  ```
185
215
 
216
+ If the agent is Claude Code, back those instructions with deny rules in the repository's committed `.claude/settings.json`. They guide the agent's tools; they are not an operating-system boundary, since a program running as you can still read the files:
217
+
218
+ ```json
219
+ {
220
+ "permissions": {
221
+ "deny": [
222
+ "Read(~/.channelvault/credentials)",
223
+ "Edit(~/.channelvault/**)",
224
+ "Bash(channelvault profile add:*)",
225
+ "Bash(channelvault profile set-password:*)",
226
+ "Bash(channelvault profile repin:*)",
227
+ "Bash(channelvault restore:*)"
228
+ ]
229
+ }
230
+ }
231
+ ```
232
+
233
+ `profile add`, `set-password` and `repin` refuse to run without a terminal anyway; the deny rules stop an agent from trying to drive them another way.
234
+
186
235
  ## Local test server
187
236
 
188
237
  ```
@@ -201,11 +250,13 @@ To try channelvault on a **real** configuration, use `docker compose -f docker-c
201
250
 
202
251
  Use a separate working copy and env file for each server. Resource revisions and the sync baseline belong to the server that supplied them; they are not comparable version numbers across independent servers. Do not alternate a single working copy between destinations.
203
252
 
204
- For an initial promotion, copy the reviewed source tree into a destination working copy and supply all of its placeholders in a destination env file. The example below assumes the `MIRTH_*` connection variables point to the destination:
253
+ For an initial promotion, copy the reviewed source tree into a destination working copy and supply all of its placeholders in a destination env file. The example below assumes a profile named `destination`:
205
254
 
206
255
  ```sh
207
- channelvault diff ./destination --dotenv .env.destination
208
- channelvault push ./destination --dotenv .env.destination --channel "Report Distributor"
256
+ channelvault adopt ./destination --profile destination --dotenv .env.destination --plan-only
257
+ channelvault adopt ./destination --profile destination --dotenv .env.destination
258
+ channelvault diff ./destination --profile destination --dotenv .env.destination
259
+ channelvault push ./destination --profile destination --dotenv .env.destination --channel "Report Distributor"
209
260
  ```
210
261
 
211
262
  Review the destination differences before overriding an independent revision history with `--force`. The initial source baseline cannot establish whether an independently managed destination changed since its last review. After the first successful push, keep the destination working copy and its refreshed baseline for subsequent changes. `--force` permits overwriting concurrent edits, while deletions still require `--allow-deletes`. A scoped push does not promote the configuration map or other server settings; manage those separately.