@kaynooo/cli-env 0.14.0 → 0.15.2
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 +13 -10
- package/dist/ev.js +17076 -1892
- package/package.json +14 -11
- package/src/commands/audit.ts +3 -4
- package/src/commands/compare.ts +26 -16
- package/src/commands/edit.ts +72 -18
- package/src/commands/pins.ts +2 -4
- package/src/commands/read.ts +32 -20
- package/src/commands/redact.ts +4 -4
- package/src/dotenv.ts +72 -22
- package/src/files.ts +77 -14
- package/src/fix.ts +3 -18
- package/src/guard-dumps.ts +27 -7
- package/src/guard-names.ts +1 -1
- package/src/guard-pipes.ts +1 -1
- package/src/guard.ts +6 -4
- package/src/mask.ts +36 -8
- package/src/structured-write.ts +383 -0
- package/src/structured.ts +68 -0
- package/dist/redact.js +0 -1836
- package/src/redact.ts +0 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ev and redact
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`ev` keeps secrets out of a Claude Code transcript: it lists and edits `.env` files with every secret masked, and `ev redact` masks secrets in any piped output.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
bun install -g @kaynooo/cli-env
|
|
@@ -16,35 +16,38 @@ bun install -g @kaynooo/cli-env
|
|
|
16
16
|
| `ev show <rev>:<file>` | an env file as a git revision holds it, values masked |
|
|
17
17
|
| `ev set KEY [file]` | sets a key in `.env` (or the file), the value read from stdin or `-F <file>` so it never appears in a command line, `--empty` for an empty value |
|
|
18
18
|
| `ev unset KEY [file]` | removes a key |
|
|
19
|
+
| `ev set`/`unset` on a `.json`, `.yaml` or `.toml` file | the key is a dotted path (`database.password`), and only its value changes: comments, order, indentation and quoting stay, a number or boolean keeps its type, and an edit that would change anything else is refused |
|
|
19
20
|
| `--quiet` (`-q`) | on set, unset, cp and mv, prints nothing on success |
|
|
20
21
|
| `ev cp KEY --from <file> --to <file>` | copies a key's value to another file without printing it, replacing the key there or appending it, `--as NEWKEY` to rename |
|
|
21
22
|
| `ev mv KEY --from <file> --to <file>` | moves a key's line as written, `--force` to replace one the target has |
|
|
22
|
-
| `ev diff <a> <b>` | names the keys set in one file and not the other, exit 1 when they differ; `--json` prints `{a, b, onlyA, onlyB}` |
|
|
23
|
+
| `ev diff <a> <b>` | names the keys set in one file and not the other, and those set to different values with both masked as `list` shows them, exit 1 when they differ; `--keys` compares the keys only, `--json` prints `{a, b, onlyA, onlyB, differ}` |
|
|
23
24
|
| `ev missing [file]` | names the keys of `.env.example` (`--against`) that the file lacks, exit 1 when some are; `--json` prints `{a, b, onlyA, onlyB}` with the reference as `a` |
|
|
24
25
|
| `ev pins [dir]` | checks an app's tests pin the env that reaches outside (see below), exit 1 when something is unpinned |
|
|
25
|
-
| `ev audit [dir...]` | lists the `.env` files any account can read or git tracks, and the compose files any account can read that write a secret or URL password out, with the fix for each, exit 1 when it finds one |
|
|
26
|
+
| `ev audit [dir...]` | lists the `.env` files any account can read or git tracks, and the compose files any account can read that write a secret or URL password out, never printing a value, with the fix for each, exit 1 when it finds one; it looks down to 5 levels, skipping `node_modules`, `vendor`, `.git` and `.example`, `.sample`, `.template` and `.dist` files, and names a folder it cannot read on stderr |
|
|
26
27
|
| `ev audit --fix [dir...]` | moves each secret a listed compose file writes out into the `.env` beside it as `${KEY}` (a key the `.env` sets to another value stays put), puts it back when `docker compose config` resolves differently, and shuts other accounts out of both files and of every listed `.env`; exit 1 when something is left |
|
|
27
28
|
|
|
28
|
-
`ev pins` lists, by name only, the optional URL, key, token, secret, password and host variables of the app's `defineEnv` schema that no `.env.test` entry, test `overrideEnv` or local bunfig preload dropping what `.env` sets pins, and each test file calling `testSite` or `proxyKeyTests` without pinning them. `// ev pins: none reached, <why>` exempts a file.
|
|
29
|
+
`ev pins` lists, by name only, the optional URL, key, token, secret, password and host variables of the app's `defineEnv` schema that no `.env.test` entry, test `overrideEnv` or local bunfig preload dropping what `.env` sets pins, and each test file calling `testSite` or `proxyKeyTests` without pinning them. `// ev pins: none reached, <why>` exempts a file. The `dir` is an app, or a monorepo holding apps one level down (the current folder by default); only variable names are read.
|
|
29
30
|
|
|
30
|
-
A value is masked when its key is named like a secret (`TOKEN`, `SECRET`, `PASSWORD`, `PASS`, `PWD`, `KEY`, `PRIVATE`, `DSN`, `AUTH`, `SALT`, `COOKIE`, `CREDENTIALS`, the definition `isSecretName` of `@kaynooo/cli-kit` that `db` shares), when it equals a secret value of the folder's `.env*` files whatever its own key, when it is a private key (PEM or PGP, also escaped on one line), or in the password part of any URL (`postgres://user:***@host/db`) and any known token format (GitHub, GitLab, Slack, AWS, npm, Stripe, Google, SendGrid, `sk-`, JWTs, `Authorization` credentials and `
|
|
31
|
+
A value is masked when its key is named like a secret (`TOKEN`, `SECRET`, `PASSWORD`, `PASS`, `PWD`, `KEY`, `PRIVATE`, `DSN`, `AUTH`, `SALT`, `COOKIE`, `CREDENTIALS`, the definition `isSecretName` of `@kaynooo/cli-kit` that `db` shares), when it equals a secret value of the folder's `.env*` files whatever its own key, when it is a private key (PEM or PGP, also escaped on one line), or in the password part of any URL (`postgres://user:***@host/db`) and any known token format (GitHub, GitLab, Slack, AWS, npm, Stripe, Google, SendGrid, `sk-`, JWTs, `Authorization` credentials, and a `name=value` or `"name": "value"` pair whose name `isSecretName` calls secret, `PGPASSWORD` or `clientSecret` alike, unless it names a setting such as `TOKEN_TTL` or `PASSWORD_FILE`). A variable printed at the start of a line, as `printenv` does, is masked to the end of the line. A URL is also masked where it carries a token, whatever its key is named: the last segment of a Discord, Slack, Uptime Kuma push or healthchecks.io ping URL, any path segment of 20 or more characters of `A-Za-z0-9_-` mixing lowercase, uppercase and digits, any path segment of 32 or more letters and digits of any case (hex, base32, dashless UUIDs), and the value of a query parameter named `token`, `key`, `apikey`, `secret`, `password`, `sig`, `signature`, `auth` or ending in `_token` or `_secret`; the host and the rest of the URL stay readable. A masked value keeps a few leading characters and its length (`ghp***(40)`) so two values can be told apart. There is no flag that prints a secret unmasked.
|
|
31
32
|
|
|
32
33
|
Files are parsed and written back preserving comments, order, `export KEY=` prefixes, quoting and multiline values; only the lines a command touches change.
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
`list`, `get`, `grep`, `show`, `diff` and `missing` also read a JSON (comments allowed), JSON5, YAML or TOML file named on the command line, its keys as dotted paths: `ev get database.password config.yaml`, `servers.0.host` for an array item. Writes stay on dotenv files: `set`, `unset`, `cp` and `mv` refuse those formats with exit 2. A file named with a `.ini` or `.xml` extension, or holding lines but no `KEY=value` one, is refused with exit 2 rather than read as empty; `ev redact < file` masks the secrets of those.
|
|
36
|
+
|
|
37
|
+
## ev redact
|
|
35
38
|
|
|
36
39
|
```sh
|
|
37
|
-
some-command 2>&1 | redact
|
|
38
|
-
git diff --cached | redact --check
|
|
40
|
+
some-command 2>&1 | ev redact
|
|
41
|
+
git diff --cached | ev redact --check
|
|
39
42
|
```
|
|
40
43
|
|
|
41
|
-
`redact` copies stdin to stdout line by line, masking:
|
|
44
|
+
`ev redact` copies stdin to stdout line by line, masking:
|
|
42
45
|
|
|
43
46
|
- known token formats: `ghp_`, `github_pat_`, `glpat-`, `sk-`, `xox?-`, JWTs and the body of PEM private key blocks
|
|
44
47
|
- the password and the tokens of any URL (webhook and push URLs, opaque path segments, token query parameters)
|
|
45
48
|
- the values of secret-looking keys in the `.env*` files of the current folder and the folders below it (whole words only, from 4 characters, also in their percent-encoded and JSON-escaped forms), `--no-env` skips them
|
|
46
49
|
|
|
47
|
-
`redact --check` prints nothing of the input: it lists `<file>:<line>: <kind>` for each secret found and exits 1. On a diff it reads the added lines only and names the new file's line numbers.
|
|
50
|
+
`ev redact --check` prints nothing of the input: it lists `<file>:<line>: <kind>` for each secret found and exits 1. On a diff it reads the added lines only and names the new file's line numbers.
|
|
48
51
|
|
|
49
52
|
## The parser and the guard
|
|
50
53
|
|