@envseal/cli 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 +201 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.js +161 -0
- package/dist/cli-utils.d.ts +50 -0
- package/dist/cli-utils.js +228 -0
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.js +89 -0
- package/dist/commands/ensure.d.ts +2 -0
- package/dist/commands/ensure.js +126 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +101 -0
- package/dist/commands/mcp.d.ts +2 -0
- package/dist/commands/mcp.js +21 -0
- package/dist/commands/revoke.d.ts +2 -0
- package/dist/commands/revoke.js +48 -0
- package/dist/commands/run.d.ts +2 -0
- package/dist/commands/run.js +82 -0
- package/dist/commands/set.d.ts +2 -0
- package/dist/commands/set.js +122 -0
- package/dist/commands/status.d.ts +2 -0
- package/dist/commands/status.js +49 -0
- package/dist/commands/verify.d.ts +2 -0
- package/dist/commands/verify.js +52 -0
- package/dist/exit-codes.d.ts +24 -0
- package/dist/exit-codes.js +73 -0
- package/dist/exit.d.ts +37 -0
- package/dist/exit.js +66 -0
- package/dist/host.d.ts +10 -0
- package/dist/host.js +286 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +7 -0
- package/dist/output.d.ts +16 -0
- package/dist/output.js +57 -0
- package/dist/probe-approval.d.ts +10 -0
- package/dist/probe-approval.js +94 -0
- package/dist/scan.d.ts +9 -0
- package/dist/scan.js +138 -0
- package/dist/test-prompter.d.ts +33 -0
- package/dist/test-prompter.js +61 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined in Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or Object
|
|
36
|
+
form, made available under the License, as indicated by a copyright
|
|
37
|
+
notice that is included in or attached to the work (an example is
|
|
38
|
+
provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original Work and any Derivative Works thereof, that is
|
|
50
|
+
intentionally submitted to, or received by, Licensor for inclusion
|
|
51
|
+
in the Work by the copyright owner or by an individual or Legal
|
|
52
|
+
Entity authorized to submit on behalf of the copyright owner. For
|
|
53
|
+
the purposes of this definition, "submitted" means any form of
|
|
54
|
+
electronic, verbal, or written communication sent to the Licensor
|
|
55
|
+
or its representatives, including but not limited to communication
|
|
56
|
+
on electronic mailing lists, source code control systems, and issue
|
|
57
|
+
tracking systems that are managed by, or on behalf of, the Licensor
|
|
58
|
+
for the purpose of discussing and improving the Work, but excluding
|
|
59
|
+
communication that is conspicuously marked or otherwise designated
|
|
60
|
+
in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
63
|
+
which a Contribution has been received by Licensor and subsequently
|
|
64
|
+
incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file, then any
|
|
107
|
+
Derivative Works that You distribute must include a readable
|
|
108
|
+
copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE from the Work, provided that
|
|
120
|
+
such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions of this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contribution.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in appropriate
|
|
184
|
+
comment syntax for the file type. We also recommend that you
|
|
185
|
+
include a file or class name and date of last modification in
|
|
186
|
+
the header comment to make it easier to identify the original
|
|
187
|
+
author and when the file was changed.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 The envseal authors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/bin.d.ts
ADDED
package/dist/bin.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { findProjectRoot } from '@envseal/core';
|
|
3
|
+
import { EXIT } from './exit-codes.js';
|
|
4
|
+
import { fail } from './output.js';
|
|
5
|
+
import { finish } from './exit.js';
|
|
6
|
+
import { parseArgs, commandUsage } from './cli-utils.js';
|
|
7
|
+
import { status } from './commands/status.js';
|
|
8
|
+
import { ensure } from './commands/ensure.js';
|
|
9
|
+
import { set } from './commands/set.js';
|
|
10
|
+
import { verify } from './commands/verify.js';
|
|
11
|
+
import { run } from './commands/run.js';
|
|
12
|
+
import { doctor } from './commands/doctor.js';
|
|
13
|
+
import { revoke } from './commands/revoke.js';
|
|
14
|
+
import { mcp } from './commands/mcp.js';
|
|
15
|
+
import { init } from './commands/init.js';
|
|
16
|
+
const VERSION = '0.1.0';
|
|
17
|
+
async function main() {
|
|
18
|
+
const argv = process.argv.slice(2);
|
|
19
|
+
if (argv.length === 0 || argv[0] === '--help' || argv[0] === '-h') {
|
|
20
|
+
showHelp();
|
|
21
|
+
finish(EXIT.OK);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (argv[0] === '--version' || argv[0] === '-v') {
|
|
25
|
+
console.log(`envseal version ${VERSION}`);
|
|
26
|
+
finish(EXIT.OK);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const command = argv[0];
|
|
30
|
+
const rest = argv.slice(1);
|
|
31
|
+
// Parse global flags
|
|
32
|
+
const parsed = parseArgs(rest);
|
|
33
|
+
// A help request anywhere before the `--` terminator describes the
|
|
34
|
+
// subcommand and exits 0 without executing it. Before this check,
|
|
35
|
+
// `envseal ensure -h` ran the real command (exit 4 under CI) and an
|
|
36
|
+
// interactive `set --help` reached the live browser prompt — a question
|
|
37
|
+
// about the tool answered with side effects.
|
|
38
|
+
if (parsed.flags.help === true) {
|
|
39
|
+
const usage = commandUsage(command);
|
|
40
|
+
if (usage !== null) {
|
|
41
|
+
console.log(usage);
|
|
42
|
+
finish(EXIT.OK);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// An unknown command asking for help keeps its existing treatment below:
|
|
46
|
+
// the unknown-command error plus top-level help, exiting 2.
|
|
47
|
+
}
|
|
48
|
+
const json = parsed.flags.json === true;
|
|
49
|
+
const projectFlag = parsed.flags.project;
|
|
50
|
+
// Determine project root
|
|
51
|
+
let root;
|
|
52
|
+
try {
|
|
53
|
+
root = projectFlag || findProjectRoot(process.cwd());
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
root = process.cwd();
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
switch (command) {
|
|
60
|
+
case 'init': {
|
|
61
|
+
const host = parsed.flags.host;
|
|
62
|
+
await init(root, json, host);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case 'ensure': {
|
|
66
|
+
await ensure(root, json, parsed.flags.check === true);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 'set': {
|
|
70
|
+
const key = parsed.args[0];
|
|
71
|
+
if (!key) {
|
|
72
|
+
console.error('Error: set requires a KEY argument');
|
|
73
|
+
finish(EXIT.USAGE);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
await set(root, key, json);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case 'status': {
|
|
80
|
+
const keys = parsed.args;
|
|
81
|
+
await status(root, keys, json);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'verify': {
|
|
85
|
+
const keys = parsed.args;
|
|
86
|
+
await verify(root, keys, json);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case 'run': {
|
|
90
|
+
if (parsed.args.length === 0 || parsed.args[0] !== '--') {
|
|
91
|
+
console.error('Error: run requires -- followed by command');
|
|
92
|
+
finish(EXIT.USAGE);
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
const cmdArgs = parsed.args.slice(1);
|
|
96
|
+
if (cmdArgs.length === 0) {
|
|
97
|
+
console.error('Error: run requires a command after --');
|
|
98
|
+
finish(EXIT.USAGE);
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
await run(root, cmdArgs, json, parsed.flags.yes === true);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
case 'doctor': {
|
|
105
|
+
await doctor(root, json);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case 'revoke': {
|
|
109
|
+
const key = parsed.args[0];
|
|
110
|
+
if (!key) {
|
|
111
|
+
console.error('Error: revoke requires a KEY argument');
|
|
112
|
+
finish(EXIT.USAGE);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
await revoke(root, key, json);
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
case 'mcp': {
|
|
119
|
+
await mcp(root);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
default: {
|
|
123
|
+
console.error(`Error: unknown command '${command}'`);
|
|
124
|
+
showHelp();
|
|
125
|
+
finish(EXIT.USAGE);
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
fail(json, error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function showHelp() {
|
|
135
|
+
console.log(`envseal ${VERSION}
|
|
136
|
+
|
|
137
|
+
Usage: envseal <command> [options]
|
|
138
|
+
|
|
139
|
+
Commands:
|
|
140
|
+
init [--host <name>] Initialize env.schema.jsonc
|
|
141
|
+
ensure [--check] Prompt for all missing required keys
|
|
142
|
+
(--check: report only, exit 0/1, never prompt)
|
|
143
|
+
set <KEY> Prompt for a single key
|
|
144
|
+
status [KEYS...] Show status of keys
|
|
145
|
+
verify [KEYS...] Run verification probes
|
|
146
|
+
run -- <cmd...> Execute command with injected secrets
|
|
147
|
+
doctor Report project configuration status
|
|
148
|
+
revoke <KEY> Revoke a key from the sink
|
|
149
|
+
mcp Start the MCP server
|
|
150
|
+
|
|
151
|
+
Global Options:
|
|
152
|
+
--project <path> Project root (default: auto-detect)
|
|
153
|
+
--json Output as JSON
|
|
154
|
+
--help, -h Show this help
|
|
155
|
+
--version, -v Show version
|
|
156
|
+
`);
|
|
157
|
+
}
|
|
158
|
+
main().catch((error) => {
|
|
159
|
+
fail(false, error);
|
|
160
|
+
});
|
|
161
|
+
//# sourceMappingURL=bin.js.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Broker } from '@envseal/core';
|
|
2
|
+
import type { TicketKeyOutcome, TicketOutcome } from '@envseal/protocol';
|
|
3
|
+
type BrokerOpts = ConstructorParameters<typeof Broker>[0];
|
|
4
|
+
/**
|
|
5
|
+
* Create a broker for the given project root.
|
|
6
|
+
* Uses the stub prompter if ENVSEAL_TEST_MODE and ENVSEAL_TEST_PROMPTER_VALUE are both set.
|
|
7
|
+
*
|
|
8
|
+
* The broker's `dispose()` is registered with the exit path here rather than
|
|
9
|
+
* left to each command. No command called it before, so every invocation left
|
|
10
|
+
* the ticket store's sweep interval running into `process.exit()`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createBroker(root: string, opts?: {
|
|
13
|
+
onConfirm?: BrokerOpts['onConfirm'];
|
|
14
|
+
onApprovalNeeded?: BrokerOpts['onApprovalNeeded'];
|
|
15
|
+
}): Promise<Broker>;
|
|
16
|
+
/**
|
|
17
|
+
* Whether there is a human we could put a question to.
|
|
18
|
+
*
|
|
19
|
+
* `CI` is checked as well as the TTY because a CI runner can attach a pseudo
|
|
20
|
+
* terminal while there is still nobody watching it; `selectPrompter` already
|
|
21
|
+
* treats `CI` as decisive, and disagreeing with it here would mean the probe
|
|
22
|
+
* approval prompt blocks a build that `env_request` correctly refuses.
|
|
23
|
+
*/
|
|
24
|
+
export declare function hasInteractiveSurface(): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The recorded outcome for `key`, or one derived from the ticket state when the
|
|
27
|
+
* prompt surface never produced one.
|
|
28
|
+
*
|
|
29
|
+
* A ticket that expires or is torn down leaves `keys` empty. `set` used to
|
|
30
|
+
* throw a bare `Error('No outcome returned')` there, which reported a timeout
|
|
31
|
+
* as a generic internal failure and lost the documented exit code. Returns null
|
|
32
|
+
* only for the genuinely inconsistent case: the ticket resolved, yet said
|
|
33
|
+
* nothing about this key.
|
|
34
|
+
*/
|
|
35
|
+
export declare function outcomeForKey(result: TicketOutcome, key: string): TicketKeyOutcome | null;
|
|
36
|
+
/**
|
|
37
|
+
* Parse command-line arguments, extracting flags and positional args.
|
|
38
|
+
*/
|
|
39
|
+
export interface ParsedArgs {
|
|
40
|
+
flags: Record<string, string | boolean>;
|
|
41
|
+
args: string[];
|
|
42
|
+
}
|
|
43
|
+
export declare function parseArgs(argv: string[]): ParsedArgs;
|
|
44
|
+
/**
|
|
45
|
+
* The usage block for `command`, or null when the command is not one envseal
|
|
46
|
+
* knows — an unknown command keeps its unknown-command treatment in bin.ts.
|
|
47
|
+
*/
|
|
48
|
+
export declare function commandUsage(command: string | undefined): string | null;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=cli-utils.d.ts.map
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Broker } from '@envseal/core';
|
|
2
|
+
import { createStubPrompter, createRefusingPrompter, isStubOutcome } from './test-prompter.js';
|
|
3
|
+
import { registerDisposable } from './exit.js';
|
|
4
|
+
/**
|
|
5
|
+
* Create a broker for the given project root.
|
|
6
|
+
* Uses the stub prompter if ENVSEAL_TEST_MODE and ENVSEAL_TEST_PROMPTER_VALUE are both set.
|
|
7
|
+
*
|
|
8
|
+
* The broker's `dispose()` is registered with the exit path here rather than
|
|
9
|
+
* left to each command. No command called it before, so every invocation left
|
|
10
|
+
* the ticket store's sweep interval running into `process.exit()`.
|
|
11
|
+
*/
|
|
12
|
+
export async function createBroker(root, opts) {
|
|
13
|
+
let prompter;
|
|
14
|
+
// Double-gated stub prompters for testing only
|
|
15
|
+
if (process.env.ENVSEAL_TEST_MODE === '1') {
|
|
16
|
+
if (process.env.ENVSEAL_TEST_PROMPTER_VALUE) {
|
|
17
|
+
prompter = createStubPrompter(process.env.ENVSEAL_TEST_PROMPTER_VALUE);
|
|
18
|
+
}
|
|
19
|
+
else if (isStubOutcome(process.env.ENVSEAL_TEST_PROMPTER_OUTCOME)) {
|
|
20
|
+
prompter = createRefusingPrompter(process.env.ENVSEAL_TEST_PROMPTER_OUTCOME);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const broker = new Broker({
|
|
24
|
+
root,
|
|
25
|
+
prompter,
|
|
26
|
+
onConfirm: opts?.onConfirm,
|
|
27
|
+
onApprovalNeeded: opts?.onApprovalNeeded,
|
|
28
|
+
});
|
|
29
|
+
registerDisposable(() => broker.dispose());
|
|
30
|
+
return broker;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether there is a human we could put a question to.
|
|
34
|
+
*
|
|
35
|
+
* `CI` is checked as well as the TTY because a CI runner can attach a pseudo
|
|
36
|
+
* terminal while there is still nobody watching it; `selectPrompter` already
|
|
37
|
+
* treats `CI` as decisive, and disagreeing with it here would mean the probe
|
|
38
|
+
* approval prompt blocks a build that `env_request` correctly refuses.
|
|
39
|
+
*/
|
|
40
|
+
export function hasInteractiveSurface() {
|
|
41
|
+
if (process.env.CI !== undefined)
|
|
42
|
+
return false;
|
|
43
|
+
return process.stdin.isTTY === true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The recorded outcome for `key`, or one derived from the ticket state when the
|
|
47
|
+
* prompt surface never produced one.
|
|
48
|
+
*
|
|
49
|
+
* A ticket that expires or is torn down leaves `keys` empty. `set` used to
|
|
50
|
+
* throw a bare `Error('No outcome returned')` there, which reported a timeout
|
|
51
|
+
* as a generic internal failure and lost the documented exit code. Returns null
|
|
52
|
+
* only for the genuinely inconsistent case: the ticket resolved, yet said
|
|
53
|
+
* nothing about this key.
|
|
54
|
+
*/
|
|
55
|
+
export function outcomeForKey(result, key) {
|
|
56
|
+
const recorded = result.keys.find((k) => k.key === key);
|
|
57
|
+
if (recorded)
|
|
58
|
+
return recorded.outcome;
|
|
59
|
+
switch (result.state) {
|
|
60
|
+
case 'expired':
|
|
61
|
+
return 'timeout';
|
|
62
|
+
case 'cancelled':
|
|
63
|
+
return 'cancelled';
|
|
64
|
+
case 'pending':
|
|
65
|
+
// `await` returned while still pending: its own timeout fired first.
|
|
66
|
+
return 'timeout';
|
|
67
|
+
case 'resolved':
|
|
68
|
+
return null;
|
|
69
|
+
default: {
|
|
70
|
+
const _exhaustive = result.state;
|
|
71
|
+
return _exhaustive;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The only flags that consume the following token as their value — exactly the
|
|
77
|
+
* ones bin.ts reads with `as string` (`--project`, `--host`). Every other
|
|
78
|
+
* `--flag` is boolean.
|
|
79
|
+
*
|
|
80
|
+
* Without this table the parser treated ANY token after a bare flag as that
|
|
81
|
+
* flag's value, so `envseal status --json OPENAI_API_KEY` silently parsed as
|
|
82
|
+
* `status` with neither `--json` nor the key filter: flags.json became the
|
|
83
|
+
* STRING 'OPENAI_API_KEY' (so `flags.json === true` was false) and the key name
|
|
84
|
+
* never reached `args`. Plain-text status for all keys, exit 0.
|
|
85
|
+
*/
|
|
86
|
+
const VALUE_FLAGS = new Set(['project', 'host']);
|
|
87
|
+
export function parseArgs(argv) {
|
|
88
|
+
const flags = {};
|
|
89
|
+
const args = [];
|
|
90
|
+
let i = 0;
|
|
91
|
+
while (i < argv.length) {
|
|
92
|
+
const arg = argv[i];
|
|
93
|
+
if (arg === undefined)
|
|
94
|
+
break;
|
|
95
|
+
// `--` is the end-of-flags terminator, not a flag. It must be checked
|
|
96
|
+
// before the `startsWith('--')` branch, which would otherwise parse it as a
|
|
97
|
+
// flag named '' and swallow the command that follows — breaking
|
|
98
|
+
// `envseal run -- <cmd>` entirely.
|
|
99
|
+
if (arg === '--') {
|
|
100
|
+
args.push('--');
|
|
101
|
+
for (let j = i + 1; j < argv.length; j++) {
|
|
102
|
+
const a = argv[j];
|
|
103
|
+
if (a !== undefined)
|
|
104
|
+
args.push(a);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
if (arg.startsWith('--')) {
|
|
109
|
+
const eqIndex = arg.indexOf('=');
|
|
110
|
+
if (eqIndex > -1) {
|
|
111
|
+
const key = arg.slice(2, eqIndex);
|
|
112
|
+
const value = arg.slice(eqIndex + 1);
|
|
113
|
+
flags[key] = value;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
const key = arg.slice(2);
|
|
117
|
+
const nextArg = argv[i + 1];
|
|
118
|
+
// Only a known value-taking flag may swallow the next token. A bare
|
|
119
|
+
// boolean flag (`--json`) must leave it for the positional loop below,
|
|
120
|
+
// so `status --json KEY` and the documented `status KEY --json` parse
|
|
121
|
+
// identically.
|
|
122
|
+
if (VALUE_FLAGS.has(key) && nextArg !== undefined && !nextArg.startsWith('--')) {
|
|
123
|
+
flags[key] = nextArg;
|
|
124
|
+
i++;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
flags[key] = true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (arg === '-') {
|
|
132
|
+
// End of flags, rest are positional
|
|
133
|
+
for (let j = i + 1; j < argv.length; j++) {
|
|
134
|
+
const a = argv[j];
|
|
135
|
+
if (a !== undefined) {
|
|
136
|
+
args.push(a);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
else if (arg === '-h') {
|
|
142
|
+
// A help request is a control token, not data. Left in args, it made
|
|
143
|
+
// `envseal ensure -h` run the real command with '-h' as a stray
|
|
144
|
+
// positional; bin.ts reads flags.help and prints usage instead.
|
|
145
|
+
flags.help = true;
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
args.push(arg);
|
|
149
|
+
}
|
|
150
|
+
i++;
|
|
151
|
+
}
|
|
152
|
+
return { flags, args };
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Per-subcommand usage, shown when -h/--help appears anywhere before the `--`
|
|
156
|
+
* terminator. Text mirrors docs/cli-contract.md; every block opens with the
|
|
157
|
+
* word "Usage" so a caller can assert that help was shown rather than a command
|
|
158
|
+
* having run.
|
|
159
|
+
*/
|
|
160
|
+
const COMMAND_USAGE = {
|
|
161
|
+
init: `Usage: envseal init [--host <name>] [--json] [--project <path>]
|
|
162
|
+
|
|
163
|
+
Initialize env.schema.jsonc, declaring every environment-variable reference found by scanning the project.
|
|
164
|
+
|
|
165
|
+
--host <name> Override host detection. Valid values: claude-code, cursor, continue, aider, windsurf, cline, zed, codex, jetbrains, goose, copilot, generic, unknown.
|
|
166
|
+
--json Output as JSON.
|
|
167
|
+
--project <path> Project root (default: auto-detect).`,
|
|
168
|
+
ensure: `Usage: envseal ensure [--check] [--json] [--project <path>]
|
|
169
|
+
|
|
170
|
+
Prompt for every missing required key in one pass.
|
|
171
|
+
|
|
172
|
+
--check Never prompt, even interactively: report whether every required
|
|
173
|
+
key is present and exit 0 or 1 accordingly. Safe under CI.
|
|
174
|
+
--json Output as JSON.
|
|
175
|
+
--project <path> Project root (default: auto-detect).`,
|
|
176
|
+
set: `Usage: envseal set <KEY> [--json] [--project <path>]
|
|
177
|
+
|
|
178
|
+
Prompt for a single key and store it in the entry's declared sink.
|
|
179
|
+
|
|
180
|
+
--json Output as JSON.
|
|
181
|
+
--project <path> Project root (default: auto-detect).`,
|
|
182
|
+
status: `Usage: envseal status [KEY...] [--json] [--project <path>]
|
|
183
|
+
|
|
184
|
+
Show which declared keys are present. Never prints values.
|
|
185
|
+
|
|
186
|
+
--json Output as JSON.
|
|
187
|
+
--project <path> Project root (default: auto-detect).`,
|
|
188
|
+
verify: `Usage: envseal verify [KEY...] [--json] [--project <path>]
|
|
189
|
+
|
|
190
|
+
Run verification probes and report a classified result per key.
|
|
191
|
+
|
|
192
|
+
--json Output as JSON.
|
|
193
|
+
--project <path> Project root (default: auto-detect).`,
|
|
194
|
+
run: `Usage: envseal run [--yes] [--json] [--project <path>] -- <cmd...>
|
|
195
|
+
|
|
196
|
+
Execute a command with secrets injected into the child environment only.
|
|
197
|
+
Asks for confirmation first; --yes (or ENVSEAL_ASSUME_YES=1) pre-approves it.
|
|
198
|
+
|
|
199
|
+
--yes Skip the confirmation prompt.
|
|
200
|
+
--json Output exit code and redacted stdout/stderr as JSON.
|
|
201
|
+
--project <path> Project root (default: auto-detect).`,
|
|
202
|
+
doctor: `Usage: envseal doctor [--json] [--project <path>]
|
|
203
|
+
|
|
204
|
+
Audit the project configuration: detected host and tier, gitignore coverage,
|
|
205
|
+
file permissions, missing required keys.
|
|
206
|
+
|
|
207
|
+
--json Output as JSON.
|
|
208
|
+
--project <path> Project root (default: auto-detect).`,
|
|
209
|
+
revoke: `Usage: envseal revoke <KEY> [--json] [--project <path>]
|
|
210
|
+
|
|
211
|
+
Remove a key from its sink and report the provider's rotation URL.
|
|
212
|
+
|
|
213
|
+
--json Output as JSON.
|
|
214
|
+
--project <path> Project root (default: auto-detect).`,
|
|
215
|
+
mcp: `Usage: envseal mcp
|
|
216
|
+
|
|
217
|
+
Start the MCP server over stdio. The host launches this itself; do not run it directly.`,
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* The usage block for `command`, or null when the command is not one envseal
|
|
221
|
+
* knows — an unknown command keeps its unknown-command treatment in bin.ts.
|
|
222
|
+
*/
|
|
223
|
+
export function commandUsage(command) {
|
|
224
|
+
if (command === undefined)
|
|
225
|
+
return null;
|
|
226
|
+
return COMMAND_USAGE[command] ?? null;
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=cli-utils.js.map
|