hushenv 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,2 @@
1
+ hushenv
2
+ Copyright 2026 Simplyxity Ltd
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # hushenv
2
+
3
+ Keeps your secrets hush-hush 🤫 — a local secret manager for the agent era, starting with your `.env`.
4
+
5
+ Your `.env` files hold **references**, not secrets:
6
+
7
+ ```dotenv
8
+ NEXTAUTH_URL=http://localhost:3000
9
+ DATABASE_URL=postgres://app:{hushenv.DB_PASSWORD}@localhost:5432/app
10
+ RESEND_KEY={hushenv.RESEND_KEY}
11
+ ```
12
+
13
+ Real values live AES-256-GCM-encrypted in `~/.hushenv/vault.json`, with the
14
+ master key in your OS keychain (macOS Keychain / Windows Credential Manager).
15
+ Plaintext exists in exactly one place: the child process environment, in
16
+ memory, at `hushenv run` time. The `.env` file is safe to commit and safe for
17
+ AI agents to read.
18
+
19
+ ## Quickstart
20
+
21
+ ```bash
22
+ hushenv init # master key -> OS keychain, empty vault
23
+ hushenv set DB_PASSWORD # hidden prompt
24
+ hushenv set RESEND_KEY --stdin # or pipe it in
25
+ hushenv run -- pnpm dev # resolves refs from ./.env, injects, runs
26
+ hushenv run -f .env.local -- pnpm dev
27
+ ```
28
+
29
+ ## Commands
30
+
31
+ | Command | What it does |
32
+ |---|---|
33
+ | `hushenv init` | Create the master key (keychain) and an empty vault |
34
+ | `hushenv set <name> [value]` | Store a secret. Hidden prompt by default; `--stdin` to pipe. Positional value is discouraged (shell history). |
35
+ | `hushenv get <name>` | Reveal a value. Requires an interactive TTY + confirmation; `--force` to bypass (use sparingly). |
36
+ | `hushenv ls` | List names and update dates. Never values. |
37
+ | `hushenv rm <name>` | Delete a secret |
38
+ | `hushenv run [-f file]... -- <cmd>` | Resolve refs and run the command with secrets injected |
39
+
40
+ Reference syntax: `{hushenv.NAME}` — whole-value or embedded inside a larger
41
+ string. `{mysm.NAME}` and `{mysmtool.NAME}` are accepted as legacy aliases.
42
+
43
+ ## Semantics
44
+
45
+ - Multiple `-f` files: loaded in order, the **first** occurrence of a key wins.
46
+ - Existing `process.env` variables are **not** overridden by file values
47
+ (dotenv convention).
48
+ - Missing refs **fail fast** before your app starts, with the exact
49
+ `hushenv set` commands to fix it. Exit code 2.
50
+ - Exit codes: `0` ok · `1` error · `2` missing secret.
51
+
52
+ ## No keychain? (CI, containers)
53
+
54
+ Set the master key via the environment instead:
55
+
56
+ ```bash
57
+ export HUSHENV_MASTER_KEY="<32 bytes, base64>"
58
+ ```
59
+
60
+ `hushenv init` prints exactly this fallback if no OS keychain is reachable.
61
+
62
+ ## Security model — honest version
63
+
64
+ What this protects against:
65
+
66
+ - Agents or tools reading secrets from `.env` files (they only see refs)
67
+ - Secrets leaking into git history
68
+ - Vault file theft without the OS keychain (ciphertext only)
69
+ - Ciphertext swapping between entries (AES-GCM AAD binds value to name)
70
+
71
+ What it does **not** protect against:
72
+
73
+ - `hushenv run -- env` prints that project's resolved secrets — scoping
74
+ arrives with per-project grants in v1
75
+ - `hushenv get --force` from a non-interactive shell — pair it with an agent
76
+ deny rule, e.g. `Bash(hushenv get*)` in Claude Code settings
77
+ - Malware running as your user with an unlocked keychain — same limit as any
78
+ local secret manager
79
+
80
+ ## Repo layout
81
+
82
+ ```
83
+ packages/vault-core engine: crypto, keychain, vault storage (name-agnostic)
84
+ apps/cli the hushenv CLI: ref resolution, run, prompts
85
+ ```
86
+
87
+ `vault-core` never imports anything env-file- or CLI-specific. Future
88
+ surfaces (tray UI, MCP broker) sit on the same engine.
89
+
90
+ ## Development
91
+
92
+ ```bash
93
+ pnpm install
94
+ pnpm build
95
+ pnpm test
96
+ pnpm --filter hushenv dev -- --help # run from source
97
+ ```
98
+
99
+ To use your dev build globally: `cd apps/cli && pnpm link --global`
100
+ (run `pnpm setup` once first if pnpm complains about a global bin dir).
101
+
102
+ ## Roadmap
103
+
104
+ v1: `import` (migrate an existing `.env`), append-only audit log,
105
+ per-project grants with strict mode. v2: secret versions, rotation warnings,
106
+ tray UI.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { NotInitializedError, SecretNotFoundError } from '@hushenv/vault-core';
4
+ import { getCommand } from './commands/get.js';
5
+ import { initCommand } from './commands/init.js';
6
+ import { lsCommand } from './commands/ls.js';
7
+ import { rmCommand } from './commands/rm.js';
8
+ import { runCommand } from './commands/run.js';
9
+ import { setCommand } from './commands/set.js';
10
+ const program = new Command();
11
+ program
12
+ .name('hushenv')
13
+ .description('Local secret manager for the agent era.\nYour .env holds {hushenv.X} refs; plaintext exists only in child process memory.')
14
+ .version('0.1.0')
15
+ .enablePositionalOptions()
16
+ .showHelpAfterError();
17
+ program
18
+ .command('init')
19
+ .description('Create the master key (OS keychain) and an empty vault')
20
+ .action(initCommand);
21
+ program
22
+ .command('set')
23
+ .description('Store a secret (hidden prompt by default)')
24
+ .argument('<name>', 'secret name, e.g. DB_PASSWORD')
25
+ .argument('[value]', 'value (discouraged: lands in shell history)')
26
+ .option('--stdin', 'read the value from stdin')
27
+ .action(setCommand);
28
+ program
29
+ .command('get')
30
+ .description('Reveal a secret (interactive confirmation required)')
31
+ .argument('<name>')
32
+ .option('--force', 'skip the TTY confirmation gate')
33
+ .action(getCommand);
34
+ program.command('ls').description('List secret names (never values)').action(lsCommand);
35
+ program.command('rm').description('Delete a secret').argument('<name>').action(rmCommand);
36
+ program
37
+ .command('run')
38
+ .description('Resolve {hushenv.X} refs from env file(s) and run a command')
39
+ .option('-f, --file <path>', 'env file to load (repeatable; first wins)', collect, [])
40
+ .passThroughOptions()
41
+ .argument('<cmd...>', 'command to run, after --')
42
+ .action((cmd, opts) => {
43
+ const files = opts.file.length > 0 ? opts.file : ['.env'];
44
+ runCommand(files, cmd);
45
+ });
46
+ function collect(value, previous) {
47
+ return [...previous, value];
48
+ }
49
+ try {
50
+ await program.parseAsync(process.argv);
51
+ }
52
+ catch (err) {
53
+ handleError(err);
54
+ }
55
+ function handleError(err) {
56
+ if (err instanceof SecretNotFoundError) {
57
+ console.error(`x ${err.message}`);
58
+ process.exitCode = 2;
59
+ }
60
+ else if (err instanceof NotInitializedError) {
61
+ console.error(`x ${err.message}`);
62
+ process.exitCode = 1;
63
+ }
64
+ else if (err instanceof Error && err.name === 'ExitPromptError') {
65
+ process.exitCode = 1;
66
+ }
67
+ else {
68
+ console.error(`x ${err instanceof Error ? err.message : String(err)}`);
69
+ process.exitCode = 1;
70
+ }
71
+ }
@@ -0,0 +1,9 @@
1
+ export interface GetOptions {
2
+ force?: boolean;
3
+ }
4
+ /**
5
+ * TTY gate: revealing plaintext requires an interactive terminal unless
6
+ * --force is passed. Non-interactive shells (CI, agents) fail the gate by
7
+ * design.
8
+ */
9
+ export declare function getCommand(name: string, opts: GetOptions): Promise<void>;
@@ -0,0 +1,24 @@
1
+ import { confirm } from '@inquirer/prompts';
2
+ import { getSecretValue } from '@hushenv/vault-core';
3
+ /**
4
+ * TTY gate: revealing plaintext requires an interactive terminal unless
5
+ * --force is passed. Non-interactive shells (CI, agents) fail the gate by
6
+ * design.
7
+ */
8
+ export async function getCommand(name, opts) {
9
+ if (!opts.force) {
10
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
11
+ console.error('x `hushenv get` reveals plaintext and requires an interactive terminal.');
12
+ console.error(' Non-interactive callers must pass --force explicitly.');
13
+ process.exitCode = 1;
14
+ return;
15
+ }
16
+ const ok = await confirm({ message: `Reveal "${name}" in plaintext?`, default: false });
17
+ if (!ok) {
18
+ console.error('Aborted.');
19
+ process.exitCode = 1;
20
+ return;
21
+ }
22
+ }
23
+ process.stdout.write(getSecretValue(name) + '\n');
24
+ }
@@ -0,0 +1 @@
1
+ export declare function initCommand(): void;
@@ -0,0 +1,33 @@
1
+ import { KeychainUnavailableError, createAndStoreMasterKey, hasStoredMasterKey, initVault, masterKeyFromEnv, vaultPath, } from '@hushenv/vault-core';
2
+ export function initCommand() {
3
+ if (masterKeyFromEnv()) {
4
+ console.log('Using master key from HUSHENV_MASTER_KEY (OS keychain skipped).');
5
+ }
6
+ else if (hasStoredMasterKey()) {
7
+ console.log('Master key already present in the OS keychain.');
8
+ }
9
+ else {
10
+ try {
11
+ createAndStoreMasterKey();
12
+ console.log('* Generated a master key and stored it in the OS keychain.');
13
+ }
14
+ catch (err) {
15
+ if (err instanceof KeychainUnavailableError) {
16
+ console.error(`x ${err.message}`);
17
+ console.error('\nFallback: add this to your shell profile, then re-run `hushenv init`:');
18
+ console.error(` export HUSHENV_MASTER_KEY="${err.fallbackKey}"`);
19
+ process.exitCode = 1;
20
+ return;
21
+ }
22
+ throw err;
23
+ }
24
+ }
25
+ const { created } = initVault();
26
+ console.log(created ? `* Created vault at ${vaultPath()}` : `Vault already exists at ${vaultPath()}`);
27
+ if (created) {
28
+ console.log('\nNext steps:');
29
+ console.log(' hushenv set MY_SECRET # store a value (hidden prompt)');
30
+ console.log(' echo {hushenv.MY_SECRET} in .env # reference it');
31
+ console.log(' hushenv run -- pnpm dev # run with secrets injected');
32
+ }
33
+ }
@@ -0,0 +1 @@
1
+ export declare function lsCommand(): void;
@@ -0,0 +1,12 @@
1
+ import { listSecrets } from '@hushenv/vault-core';
2
+ export function lsCommand() {
3
+ const secrets = listSecrets();
4
+ if (secrets.length === 0) {
5
+ console.log('Vault is empty. Add a secret with: hushenv set NAME');
6
+ return;
7
+ }
8
+ const width = Math.max(...secrets.map((s) => s.name.length));
9
+ for (const s of secrets) {
10
+ console.log(`${s.name.padEnd(width)} updated ${s.updatedAt.slice(0, 10)}`);
11
+ }
12
+ }
@@ -0,0 +1 @@
1
+ export declare function rmCommand(name: string): void;
@@ -0,0 +1,10 @@
1
+ import { deleteSecret } from '@hushenv/vault-core';
2
+ export function rmCommand(name) {
3
+ if (deleteSecret(name)) {
4
+ console.log(`* Removed ${name}.`);
5
+ }
6
+ else {
7
+ console.error(`x Secret "${name}" not found.`);
8
+ process.exitCode = 2;
9
+ }
10
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The core invariant: plaintext exists only in the child process
3
+ * environment, in memory, at exec time. Nothing resolved is ever written to
4
+ * disk.
5
+ */
6
+ export declare function runCommand(files: string[], cmd: string[]): void;
@@ -0,0 +1,40 @@
1
+ import spawn from 'cross-spawn';
2
+ import { decryptValue, getMasterKey, loadVault } from '@hushenv/vault-core';
3
+ import { loadEnvFiles } from '../env-files.js';
4
+ import { resolveRefs } from '../resolve.js';
5
+ /**
6
+ * The core invariant: plaintext exists only in the child process
7
+ * environment, in memory, at exec time. Nothing resolved is ever written to
8
+ * disk.
9
+ */
10
+ export function runCommand(files, cmd) {
11
+ if (cmd.length === 0) {
12
+ throw new Error('No command given. Usage: hushenv run [-f file] -- <command...>');
13
+ }
14
+ const raw = loadEnvFiles(files);
15
+ const key = getMasterKey();
16
+ const vault = loadVault();
17
+ const { resolved, missing } = resolveRefs(raw, (name) => {
18
+ const entry = vault.secrets[name];
19
+ return entry ? decryptValue(key, name, entry) : undefined;
20
+ });
21
+ if (missing.length > 0) {
22
+ console.error(`x ${missing.length} secret(s) referenced but not in the vault:`);
23
+ for (const name of missing)
24
+ console.error(` ${name}`);
25
+ console.error('\n Add them with:');
26
+ for (const name of missing)
27
+ console.error(` hushenv set ${name}`);
28
+ process.exitCode = 2;
29
+ return;
30
+ }
31
+ const childEnv = { ...resolved, ...process.env };
32
+ const child = spawn(cmd[0], cmd.slice(1), { stdio: 'inherit', env: childEnv });
33
+ child.on('error', (err) => {
34
+ console.error(`x Failed to start "${cmd[0]}": ${err.message}`);
35
+ process.exitCode = 1;
36
+ });
37
+ child.on('exit', (code, signal) => {
38
+ process.exitCode = signal ? 1 : code ?? 1;
39
+ });
40
+ }
@@ -0,0 +1,9 @@
1
+ export interface SetOptions {
2
+ stdin?: boolean;
3
+ }
4
+ export declare function setCommand(name: string, positionalValue: string | undefined, opts: SetOptions): Promise<void>;
5
+ /**
6
+ * PowerShell 5.1 prepends a UTF-8 BOM when piping a string into a native
7
+ * process, which would silently corrupt the stored secret.
8
+ */
9
+ export declare function normalizeStdinValue(raw: string): string;
@@ -0,0 +1,34 @@
1
+ import { password } from '@inquirer/prompts';
2
+ import { setSecret } from '@hushenv/vault-core';
3
+ export async function setCommand(name, positionalValue, opts) {
4
+ let value;
5
+ if (opts.stdin) {
6
+ value = normalizeStdinValue(await readStdin());
7
+ }
8
+ else if (positionalValue !== undefined) {
9
+ console.error('Warning: the value was passed on the command line and may be stored in your shell history.');
10
+ console.error('Prefer `hushenv set NAME` (hidden prompt) or `--stdin`.');
11
+ value = positionalValue;
12
+ }
13
+ else {
14
+ value = await password({ message: `Value for ${name}:`, mask: '*' });
15
+ }
16
+ setSecret(name, value);
17
+ console.log(`* Stored ${name} (encrypted).`);
18
+ }
19
+ /**
20
+ * PowerShell 5.1 prepends a UTF-8 BOM when piping a string into a native
21
+ * process, which would silently corrupt the stored secret.
22
+ */
23
+ export function normalizeStdinValue(raw) {
24
+ return raw.replace(/^\uFEFF/, '').replace(/\r?\n$/, '');
25
+ }
26
+ function readStdin() {
27
+ return new Promise((resolve, reject) => {
28
+ let data = '';
29
+ process.stdin.setEncoding('utf8');
30
+ process.stdin.on('data', (chunk) => (data += chunk));
31
+ process.stdin.on('end', () => resolve(data));
32
+ process.stdin.on('error', reject);
33
+ });
34
+ }
@@ -0,0 +1,2 @@
1
+ /** Loads env files in order; the FIRST occurrence of a key wins. */
2
+ export declare function loadEnvFiles(files: string[]): Record<string, string>;
@@ -0,0 +1,17 @@
1
+ import fs from 'node:fs';
2
+ import { parse } from 'dotenv';
3
+ /** Loads env files in order; the FIRST occurrence of a key wins. */
4
+ export function loadEnvFiles(files) {
5
+ const out = {};
6
+ for (const file of files) {
7
+ if (!fs.existsSync(file)) {
8
+ throw new Error(`Env file not found: ${file}`);
9
+ }
10
+ const parsed = parse(fs.readFileSync(file, 'utf8'));
11
+ for (const [key, value] of Object.entries(parsed)) {
12
+ if (!(key in out))
13
+ out[key] = value;
14
+ }
15
+ }
16
+ return out;
17
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Reference syntax: {hushenv.NAME}. The mysm/mysmtool prefixes are accepted
3
+ * as legacy aliases.
4
+ */
5
+ export declare const REF_RE: RegExp;
6
+ export interface ResolveResult {
7
+ resolved: Record<string, string>;
8
+ missing: string[];
9
+ used: string[];
10
+ }
11
+ /** Collect every referenced secret name across all values. */
12
+ export declare function collectRefs(values: Record<string, string>): string[];
13
+ /**
14
+ * Substitutes refs (including refs embedded inside larger strings) using the
15
+ * lookup. Missing names are collected, not thrown - the caller decides how
16
+ * to fail.
17
+ */
18
+ export declare function resolveRefs(values: Record<string, string>, lookup: (name: string) => string | undefined): ResolveResult;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Reference syntax: {hushenv.NAME}. The mysm/mysmtool prefixes are accepted
3
+ * as legacy aliases.
4
+ */
5
+ export const REF_RE = /\{(?:hushenv|mysm(?:tool)?)\.([A-Za-z_][A-Za-z0-9_]*)\}/g;
6
+ /** Collect every referenced secret name across all values. */
7
+ export function collectRefs(values) {
8
+ const names = new Set();
9
+ for (const value of Object.values(values)) {
10
+ for (const match of value.matchAll(REF_RE)) {
11
+ names.add(match[1]);
12
+ }
13
+ }
14
+ return [...names];
15
+ }
16
+ /**
17
+ * Substitutes refs (including refs embedded inside larger strings) using the
18
+ * lookup. Missing names are collected, not thrown - the caller decides how
19
+ * to fail.
20
+ */
21
+ export function resolveRefs(values, lookup) {
22
+ const missing = new Set();
23
+ const used = new Set();
24
+ const resolved = {};
25
+ for (const [key, value] of Object.entries(values)) {
26
+ resolved[key] = value.replace(REF_RE, (whole, name) => {
27
+ const secret = lookup(name);
28
+ if (secret === undefined) {
29
+ missing.add(name);
30
+ return whole;
31
+ }
32
+ used.add(name);
33
+ return secret;
34
+ });
35
+ }
36
+ return { resolved, missing: [...missing], used: [...used] };
37
+ }
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "hushenv",
3
+ "version": "0.1.0",
4
+ "description": "Local secret manager for the agent era - encrypted vault, {hushenv.X} refs in .env, plaintext only at runtime.",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/hushenv/hushenv.git",
10
+ "directory": "apps/cli"
11
+ },
12
+ "homepage": "https://github.com/hushenv/hushenv#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/hushenv/hushenv/issues"
15
+ },
16
+ "keywords": [
17
+ "secrets",
18
+ "env",
19
+ "dotenv",
20
+ "vault",
21
+ "keychain",
22
+ "security",
23
+ "cli"
24
+ ],
25
+ "bin": {
26
+ "hushenv": "./dist/cli.js"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE",
32
+ "NOTICE"
33
+ ],
34
+ "engines": {
35
+ "node": ">=20"
36
+ },
37
+ "dependencies": {
38
+ "@inquirer/prompts": "^8.5.0",
39
+ "commander": "^15.0.0",
40
+ "cross-spawn": "^7.0.6",
41
+ "dotenv": "^17.4.0",
42
+ "@hushenv/vault-core": "0.1.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/cross-spawn": "^6.0.6",
46
+ "@types/node": "^22.10.0",
47
+ "tsx": "^4.22.0",
48
+ "typescript": "^5.5.0",
49
+ "vitest": "^4.1.0"
50
+ },
51
+ "scripts": {
52
+ "build": "tsc -p tsconfig.json",
53
+ "dev": "tsx src/cli.ts",
54
+ "test": "vitest run"
55
+ }
56
+ }