@reasontrail/cli 0.1.3 → 0.1.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 +8 -0
- package/README.md +78 -1
- package/package.json +1 -1
- package/runtime/reasontrail-credential-broker.mjs +43419 -0
- package/runtime/reasontrail-credential-broker.mjs.sha256 +1 -0
- package/src/cli.mjs +77 -8
- package/runtime/reasontrail-runtime.mjs +0 -23448
- package/runtime/reasontrail-runtime.mjs.sha256 +0 -1
- package/src/build-info.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
099f777f93e5882c75b4ee49f6420fbf76e4cb981a12ecdb91545ad8345e6c09 reasontrail-credential-broker.mjs
|
package/src/cli.mjs
CHANGED
|
@@ -69,13 +69,17 @@ function commandExists(name) {
|
|
|
69
69
|
return spawnSync("sh", ["-c", `command -v ${name}`], { stdio: "ignore" }).status === 0;
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
function osCredentialStoreEnabled() {
|
|
73
|
+
return !(process.env.NODE_ENV === "test" && process.env.REASONTRAIL_TEST_DISABLE_OS_CREDENTIAL_STORE === "1");
|
|
74
|
+
}
|
|
75
|
+
|
|
72
76
|
async function loadCredential(profile) {
|
|
73
77
|
const paths = profilePaths(profile);
|
|
74
|
-
if (process.platform === "darwin" && commandExists("security")) {
|
|
78
|
+
if (osCredentialStoreEnabled() && process.platform === "darwin" && commandExists("security")) {
|
|
75
79
|
const found = spawnSync("security", ["find-generic-password", "-s", KEYCHAIN_SERVICE, "-a", profile, "-w"], { encoding: "utf8" });
|
|
76
80
|
if (found.status === 0 && found.stdout.trim()) return { token: found.stdout.trim(), source: "macOS Keychain" };
|
|
77
81
|
}
|
|
78
|
-
if (process.platform === "linux" && commandExists("secret-tool")) {
|
|
82
|
+
if (osCredentialStoreEnabled() && process.platform === "linux" && commandExists("secret-tool")) {
|
|
79
83
|
const found = spawnSync("secret-tool", ["lookup", "service", KEYCHAIN_SERVICE, "account", profile], { encoding: "utf8" });
|
|
80
84
|
if (found.status === 0 && found.stdout.trim()) return { token: found.stdout.trim(), source: "Secret Service" };
|
|
81
85
|
}
|
|
@@ -87,12 +91,18 @@ async function loadCredential(profile) {
|
|
|
87
91
|
async function storeCredential(profile, token) {
|
|
88
92
|
const paths = profilePaths(profile);
|
|
89
93
|
if (!token.startsWith("rtmcp_")) throw new CliError("That is not a ReasonTrail MCP access token.", 2);
|
|
90
|
-
if (process.platform === "darwin" && commandExists("security")) {
|
|
91
|
-
|
|
94
|
+
if (osCredentialStoreEnabled() && process.platform === "darwin" && commandExists("security")) {
|
|
95
|
+
// Keep the bearer token out of argv. macOS security(1) reads it from
|
|
96
|
+
// stdin when `-w` is the final argument and prompts twice on creation.
|
|
97
|
+
const stored = spawnSync(
|
|
98
|
+
"security",
|
|
99
|
+
["add-generic-password", "-U", "-s", KEYCHAIN_SERVICE, "-a", profile, "-w"],
|
|
100
|
+
{ input: `${token}\n${token}\n`, encoding: "utf8" },
|
|
101
|
+
);
|
|
92
102
|
if (stored.status !== 0) throw new CliError(stored.stderr.trim() || "Could not store the credential in macOS Keychain.");
|
|
93
103
|
return "macOS Keychain";
|
|
94
104
|
}
|
|
95
|
-
if (process.platform === "linux" && commandExists("secret-tool")) {
|
|
105
|
+
if (osCredentialStoreEnabled() && process.platform === "linux" && commandExists("secret-tool")) {
|
|
96
106
|
const stored = spawnSync("secret-tool", ["store", "--label", `ReasonTrail CLI (${profile})`, "service", KEYCHAIN_SERVICE, "account", profile], { input: token, encoding: "utf8" });
|
|
97
107
|
if (stored.status !== 0) throw new CliError(stored.stderr.trim() || "Could not store the credential in Secret Service.");
|
|
98
108
|
return "Secret Service";
|
|
@@ -104,11 +114,11 @@ async function storeCredential(profile, token) {
|
|
|
104
114
|
async function removeCredential(profile) {
|
|
105
115
|
const paths = profilePaths(profile);
|
|
106
116
|
const removed = [];
|
|
107
|
-
if (process.platform === "darwin" && commandExists("security")) {
|
|
117
|
+
if (osCredentialStoreEnabled() && process.platform === "darwin" && commandExists("security")) {
|
|
108
118
|
const result = spawnSync("security", ["delete-generic-password", "-s", KEYCHAIN_SERVICE, "-a", profile], { encoding: "utf8" });
|
|
109
119
|
if (result.status === 0) removed.push("macOS Keychain");
|
|
110
120
|
}
|
|
111
|
-
if (process.platform === "linux" && commandExists("secret-tool")) {
|
|
121
|
+
if (osCredentialStoreEnabled() && process.platform === "linux" && commandExists("secret-tool")) {
|
|
112
122
|
const result = spawnSync("secret-tool", ["clear", "service", KEYCHAIN_SERVICE, "account", profile], { encoding: "utf8" });
|
|
113
123
|
if (result.status === 0) removed.push("Secret Service");
|
|
114
124
|
}
|
|
@@ -1611,6 +1621,8 @@ async function claudeHookCommand(argv) {
|
|
|
1611
1621
|
*/
|
|
1612
1622
|
const RUNTIME_BUNDLE = join(PACKAGE_ROOT, "runtime", "reasontrail-runtime.mjs");
|
|
1613
1623
|
const RUNTIME_CHECKSUM = `${RUNTIME_BUNDLE}.sha256`;
|
|
1624
|
+
const BROKER_BUNDLE = join(PACKAGE_ROOT, "runtime", "reasontrail-credential-broker.mjs");
|
|
1625
|
+
const BROKER_CHECKSUM = `${BROKER_BUNDLE}.sha256`;
|
|
1614
1626
|
|
|
1615
1627
|
async function runtimeBundleIntegrity() {
|
|
1616
1628
|
let bundle;
|
|
@@ -1630,6 +1642,24 @@ async function runtimeBundleIntegrity() {
|
|
|
1630
1642
|
return { state: actual === expected ? "verified" : "mismatch", expected, actual };
|
|
1631
1643
|
}
|
|
1632
1644
|
|
|
1645
|
+
async function brokerBundleIntegrity() {
|
|
1646
|
+
let bundle;
|
|
1647
|
+
let checksum;
|
|
1648
|
+
try {
|
|
1649
|
+
[bundle, checksum] = await Promise.all([
|
|
1650
|
+
readFile(BROKER_BUNDLE),
|
|
1651
|
+
readFile(BROKER_CHECKSUM, "utf8"),
|
|
1652
|
+
]);
|
|
1653
|
+
} catch (error) {
|
|
1654
|
+
if (error?.code === "ENOENT") return { state: "missing" };
|
|
1655
|
+
throw new CliError(`Could not verify the credential-broker bundle: ${error.message}`);
|
|
1656
|
+
}
|
|
1657
|
+
const expected = checksum.trim().split(/\s+/)[0]?.toLowerCase();
|
|
1658
|
+
if (!/^[0-9a-f]{64}$/.test(expected || "")) return { state: "invalid-checksum" };
|
|
1659
|
+
const actual = createHash("sha256").update(bundle).digest("hex");
|
|
1660
|
+
return { state: actual === expected ? "verified" : "mismatch", expected, actual };
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1633
1663
|
async function runtimeConfig(profile) {
|
|
1634
1664
|
return readJson(profilePaths(profile).runtime, null);
|
|
1635
1665
|
}
|
|
@@ -1772,6 +1802,39 @@ async function runtimeCommand(argv) {
|
|
|
1772
1802
|
throw new CliError(`Unknown runtime command '${sub}'.\n\n` + runtimeUsage(), 2);
|
|
1773
1803
|
}
|
|
1774
1804
|
|
|
1805
|
+
function brokerUsage() {
|
|
1806
|
+
return (
|
|
1807
|
+
`Usage: reasontrail broker <command> --profile <development|production>\n\n` +
|
|
1808
|
+
` enroll --label <name> --allow-software-key\n` +
|
|
1809
|
+
` Enroll this user device in the explicitly weaker software-key tier\n` +
|
|
1810
|
+
` devices List this user's enrolled broker devices\n` +
|
|
1811
|
+
` store --project <slug> --name <label> --kind <kind> [--payload-stdin]\n` +
|
|
1812
|
+
` Encrypt locally to this device before upload (managers only on software-key devices)\n` +
|
|
1813
|
+
` migrate --project <slug> --secret <id> --version <number> --acknowledge-one-way-device-migration\n` +
|
|
1814
|
+
` One-way manager migration to this device\n` +
|
|
1815
|
+
` share --project <slug> --secret <id> --target-device <id>\n` +
|
|
1816
|
+
` Re-encrypt for another verified device\n` +
|
|
1817
|
+
` revoke Revoke this device and remove its local key\n` +
|
|
1818
|
+
` mcp Serve approved fixed operations over local MCP\n`
|
|
1819
|
+
);
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
async function brokerCommand(argv) {
|
|
1823
|
+
const sub = argv[0];
|
|
1824
|
+
if (!sub || sub === "help" || sub === "--help") return stdout.write(brokerUsage());
|
|
1825
|
+
await resolveTarget(argv.slice(1), { allowMissing: false, confirm: true });
|
|
1826
|
+
const integrity = await brokerBundleIntegrity();
|
|
1827
|
+
if (integrity.state === "missing") {
|
|
1828
|
+
throw new CliError(`The credential-broker bundle or checksum is missing from this installation (${BROKER_BUNDLE}). Reinstall the CLI.`);
|
|
1829
|
+
}
|
|
1830
|
+
if (integrity.state !== "verified") {
|
|
1831
|
+
throw new CliError(`The credential-broker bundle failed its integrity check (${integrity.state}). Reinstall the CLI before using project credentials.`);
|
|
1832
|
+
}
|
|
1833
|
+
const result = spawnSync(process.execPath, [BROKER_BUNDLE, sub, ...argv.slice(1)], { stdio: "inherit" });
|
|
1834
|
+
if (result.error) throw new CliError(`Could not start the credential broker: ${result.error.message}`);
|
|
1835
|
+
process.exitCode = result.status ?? 0;
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1775
1838
|
function helpCommand() {
|
|
1776
1839
|
stdout.write(`ReasonTrail CLI ${VERSION}\n\n` +
|
|
1777
1840
|
`Usage: reasontrail <command> --profile <development|production>\n\n` +
|
|
@@ -1797,16 +1860,21 @@ function helpCommand() {
|
|
|
1797
1860
|
` hook claude Receive a Claude Code lifecycle hook event\n` +
|
|
1798
1861
|
` config endpoint <url> --profile <profile> Configure an isolated named profile\n` +
|
|
1799
1862
|
` runtime enroll|start|status|logout ReasonTrail Runtime on this machine\n` +
|
|
1863
|
+
` broker enroll|devices|store|migrate|share|revoke|mcp Local approved credential operations\n` +
|
|
1800
1864
|
` upgrade Reserved until signed releases exist\n`);
|
|
1801
1865
|
}
|
|
1802
1866
|
|
|
1803
1867
|
async function main() {
|
|
1804
1868
|
const [command, ...argv] = process.argv.slice(2);
|
|
1805
|
-
|
|
1869
|
+
// `broker migrate --version <number>` names the credential version. Keep
|
|
1870
|
+
// that subcommand-owned option out of the CLI-wide executable-version path.
|
|
1871
|
+
const brokerMigration = command === "broker" && argv[0] === "migrate";
|
|
1872
|
+
if (command === "--version" || command === "-v" || (!brokerMigration && (argv.includes("--version") || argv.includes("-v")))) {
|
|
1806
1873
|
const build = await cliBuildIdentity();
|
|
1807
1874
|
return stdout.write(`${VERSION} revision ${build.source_revision || "unknown"}\n`);
|
|
1808
1875
|
}
|
|
1809
1876
|
if (!command || command === "help" || command === "--help" || command === "-h") return helpCommand();
|
|
1877
|
+
if (command === "broker" && (argv[0] === "help" || argv.includes("--help") || argv.includes("-h"))) return brokerCommand(argv);
|
|
1810
1878
|
if (argv.includes("--help") || argv.includes("-h") || argv[0] === "help") return helpCommand();
|
|
1811
1879
|
if (command === "status") return statusCommand(argv);
|
|
1812
1880
|
if (command === "doctor") return doctorCommand(argv);
|
|
@@ -1825,6 +1893,7 @@ async function main() {
|
|
|
1825
1893
|
if (command === "hook" && argv[0] === "claude") return claudeHookCommand(argv.slice(1));
|
|
1826
1894
|
if (command === "config") return configCommand(argv);
|
|
1827
1895
|
if (command === "runtime") return runtimeCommand(argv);
|
|
1896
|
+
if (command === "broker") return brokerCommand(argv);
|
|
1828
1897
|
if (command === "upgrade") throw new CliError("Automatic upgrade is unavailable until versioned signed artifacts are published. No changes were made.", 2);
|
|
1829
1898
|
throw new CliError(`Unknown command '${command}'. Run \`reasontrail help\`.`, 2);
|
|
1830
1899
|
}
|