@vaultkeepr/cli 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +234 -2
- package/dist/_esm-2BJT4VTJ.js +3739 -0
- package/dist/agent-OVSW5GMB.js +17 -0
- package/dist/ccip-SAAG5KQW.js +14 -0
- package/dist/chunk-4VNS5WPM.js +42 -0
- package/dist/chunk-GOWAFN6V.js +2454 -0
- package/dist/chunk-I25CVPG3.js +4603 -0
- package/dist/chunk-UDT2YIGY.js +158 -0
- package/dist/chunk-UUCFTCF4.js +3358 -0
- package/dist/chunk-V4QISPBH.js +122 -0
- package/dist/chunk-XJMVKU2V.js +22430 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +21 -0
- package/dist/dist-XKDX6HOR.js +484 -0
- package/dist/index.d.ts +794 -0
- package/dist/index.js +215 -0
- package/dist/secp256k1-SITSPVYB.js +16 -0
- package/package.json +42 -4
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// src/agent.ts
|
|
2
|
+
import { spawn } from "child_process";
|
|
3
|
+
var AGENT_SUBCOMMANDS = ["init", "list", "run", "http", "mandate"];
|
|
4
|
+
var AGENT_BIN_CANDIDATES = ["vaultkeepr-agent", "vaultkeeper-agent"];
|
|
5
|
+
var AGENT_HTTP_BIN_CANDIDATES = ["vaultkeepr-agent-http", "vaultkeeper-agent-http"];
|
|
6
|
+
function resolveAgentBinaries(env = process.env) {
|
|
7
|
+
const agentOverride = env.VK_AGENT_BIN?.trim();
|
|
8
|
+
const httpOverride = env.VK_AGENT_HTTP_BIN?.trim();
|
|
9
|
+
return {
|
|
10
|
+
agent: agentOverride && agentOverride !== "" ? agentOverride : AGENT_BIN_CANDIDATES[0],
|
|
11
|
+
http: httpOverride && httpOverride !== "" ? httpOverride : AGENT_HTTP_BIN_CANDIDATES[0]
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function agentBinaryCandidates(env = process.env, kind = "agent") {
|
|
15
|
+
const override = kind === "agent" ? env.VK_AGENT_BIN?.trim() : env.VK_AGENT_HTTP_BIN?.trim();
|
|
16
|
+
if (override !== void 0 && override !== "") return [override];
|
|
17
|
+
return kind === "agent" ? AGENT_BIN_CANDIDATES : AGENT_HTTP_BIN_CANDIDATES;
|
|
18
|
+
}
|
|
19
|
+
function agentCandidates(env, kind) {
|
|
20
|
+
return agentBinaryCandidates(env, kind);
|
|
21
|
+
}
|
|
22
|
+
async function spawnAgentBinary(candidates, argv, env = process.env) {
|
|
23
|
+
for (const bin of candidates) {
|
|
24
|
+
const result = await new Promise((resolve) => {
|
|
25
|
+
let settled = false;
|
|
26
|
+
const finish = (value) => {
|
|
27
|
+
if (settled) return;
|
|
28
|
+
settled = true;
|
|
29
|
+
resolve(value);
|
|
30
|
+
};
|
|
31
|
+
let child;
|
|
32
|
+
try {
|
|
33
|
+
child = spawn(bin, argv, { stdio: "inherit", env });
|
|
34
|
+
} catch (error) {
|
|
35
|
+
finish(error.code === "ENOENT" ? "missing" : 1);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
child.once("error", (error) => {
|
|
39
|
+
finish(error.code === "ENOENT" ? "missing" : 1);
|
|
40
|
+
});
|
|
41
|
+
child.once("close", (code, signal) => {
|
|
42
|
+
finish(code ?? (signal ? 1 : 0));
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
if (result !== "missing") return result;
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
function delegateFor(subcommand) {
|
|
50
|
+
return subcommand === "http" ? "http" : "agent";
|
|
51
|
+
}
|
|
52
|
+
async function runAgentDispatch(options) {
|
|
53
|
+
const io = options.io;
|
|
54
|
+
const env = options.env ?? process.env;
|
|
55
|
+
const [subcommand, ...rest] = options.argv;
|
|
56
|
+
if (subcommand === void 0 || subcommand === "-h" || subcommand === "--help" || subcommand === "help") {
|
|
57
|
+
io.out(agentUsage());
|
|
58
|
+
return subcommand === void 0 ? 1 : 0;
|
|
59
|
+
}
|
|
60
|
+
if (!AGENT_SUBCOMMANDS.includes(subcommand)) {
|
|
61
|
+
io.err(`error: unknown agent subcommand: ${subcommand}
|
|
62
|
+
|
|
63
|
+
${agentUsage()}`);
|
|
64
|
+
return 2;
|
|
65
|
+
}
|
|
66
|
+
if (subcommand === "mandate") {
|
|
67
|
+
io.err(
|
|
68
|
+
"error: `agent mandate` runs from the vault client, which resolves the entries\n"
|
|
69
|
+
);
|
|
70
|
+
return 2;
|
|
71
|
+
}
|
|
72
|
+
const kind = delegateFor(subcommand);
|
|
73
|
+
const code = await spawnAgentBinary(
|
|
74
|
+
agentCandidates(env, kind),
|
|
75
|
+
[subcommand, ...rest],
|
|
76
|
+
env
|
|
77
|
+
);
|
|
78
|
+
if (code === null) {
|
|
79
|
+
io.err(
|
|
80
|
+
kind === "agent" ? "error: vaultkeepr-agent not found in the PATH (install the @vaultkeepr/agent-cli package)\n" : "error: vaultkeepr-agent-http not found in the PATH (install the @vaultkeepr/agent-http package)\n"
|
|
81
|
+
);
|
|
82
|
+
return 127;
|
|
83
|
+
}
|
|
84
|
+
return code;
|
|
85
|
+
}
|
|
86
|
+
function agentUsage() {
|
|
87
|
+
return `vaultkeepr agent \u2014 the agent family, a single entry point
|
|
88
|
+
|
|
89
|
+
Usage:
|
|
90
|
+
vaultkeepr agent init [--ttl-days N] [--api <url>]
|
|
91
|
+
Creates the pair session, prints the QR, waits for the mandate signed
|
|
92
|
+
by the phone and stores it (delegates to vaultkeepr-agent init).
|
|
93
|
+
|
|
94
|
+
vaultkeepr agent list [--json]
|
|
95
|
+
Mandate entries, binaries and allowed domains (never a value).
|
|
96
|
+
|
|
97
|
+
vaultkeepr agent run [--entry <id>] -- <cmd...>
|
|
98
|
+
Runs <cmd> with the allowed values in its environment.
|
|
99
|
+
|
|
100
|
+
vaultkeepr agent http [--entry <id>] -- <method> <url>
|
|
101
|
+
HTTP request through the broker (delegates to vaultkeepr-agent-http).
|
|
102
|
+
|
|
103
|
+
vaultkeepr agent mandate --entry <id|label> [--entry \u2026] --bin <name>
|
|
104
|
+
[--ttl-days N] [--prefixes <url,\u2026>] [--api <url>]
|
|
105
|
+
Pre-filled mandate request: the QR carries the request (entries, binary,
|
|
106
|
+
domains, lifetime), the phone pre-fills its emission screen and Justin
|
|
107
|
+
confirms. The phone remains the only signer; the CLI seals nothing.
|
|
108
|
+
--prefixes default: the service URL origin of each entry.
|
|
109
|
+
|
|
110
|
+
Binaries: vaultkeepr-agent and vaultkeepr-agent-http (overrides:
|
|
111
|
+
VK_AGENT_BIN, VK_AGENT_HTTP_BIN).
|
|
112
|
+
`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export {
|
|
116
|
+
AGENT_SUBCOMMANDS,
|
|
117
|
+
resolveAgentBinaries,
|
|
118
|
+
agentBinaryCandidates,
|
|
119
|
+
spawnAgentBinary,
|
|
120
|
+
runAgentDispatch,
|
|
121
|
+
agentUsage
|
|
122
|
+
};
|