mrmainspring 0.2.4 → 0.2.6
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/dist/cli.js +53 -14
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -35,6 +35,15 @@ Advanced users can still set SIGIL_ENV_FILE, SIGIL_DATA_DIR, Supabase, Casper,
|
|
|
35
35
|
and x402 env vars. No env vars are required for local memory, Grimoire, audit,
|
|
36
36
|
or payment preflight tools.
|
|
37
37
|
`;
|
|
38
|
+
function appendEnvVars(envFile, vars) {
|
|
39
|
+
const existing = existsSync(envFile) ? readFileSync(envFile, "utf8") : "";
|
|
40
|
+
const toWrite = Object.entries(vars).filter(([k]) => !existing.includes(`${k}=`));
|
|
41
|
+
if (toWrite.length === 0)
|
|
42
|
+
return [];
|
|
43
|
+
const block = "\n# Mainspring setup\n" + toWrite.map(([k, v]) => `${k}=${v}`).join("\n") + "\n";
|
|
44
|
+
appendFileSync(envFile, block, "utf8");
|
|
45
|
+
return toWrite.map(([k]) => k);
|
|
46
|
+
}
|
|
38
47
|
export async function runCliCommand(args) {
|
|
39
48
|
const [command, target] = args;
|
|
40
49
|
if (!command || command === "stdio" || command === "server" || command === "mcp") {
|
|
@@ -58,7 +67,7 @@ export async function runCliCommand(args) {
|
|
|
58
67
|
return true;
|
|
59
68
|
}
|
|
60
69
|
if (command === "setup") {
|
|
61
|
-
if (process.stdin.isTTY) {
|
|
70
|
+
if (process.stdin.isTTY ?? process.stdout.isTTY) {
|
|
62
71
|
await runInteractiveSetup();
|
|
63
72
|
}
|
|
64
73
|
else {
|
|
@@ -261,11 +270,22 @@ async function runInteractiveSetup() {
|
|
|
261
270
|
}
|
|
262
271
|
}
|
|
263
272
|
const keyPath = keyAction === "generate" ? "./keys/secret_key.pem" : "./keys/your-secret-key.pem";
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
273
|
+
const casperVars = {
|
|
274
|
+
CASPER_ENABLE_REAL_SUBMISSION: "true",
|
|
275
|
+
CASPER_RPC_URL: casperRpcUrl,
|
|
276
|
+
CASPER_ACCOUNT_KEY_PATH: keyPath
|
|
277
|
+
};
|
|
278
|
+
clack.log.info("Casper vars:\n\n" +
|
|
279
|
+
Object.entries(casperVars).map(([k, v]) => ` ${k}=${v}`).join("\n") +
|
|
280
|
+
`\n\n .env: ${result.envFile}`);
|
|
281
|
+
const writeCasper = await clack.confirm({ message: "Write these to your .env now?", initialValue: true });
|
|
282
|
+
if (!clack.isCancel(writeCasper) && writeCasper) {
|
|
283
|
+
const written = appendEnvVars(result.envFile, casperVars);
|
|
284
|
+
if (written.length > 0)
|
|
285
|
+
clack.log.success(`Written: ${written.join(", ")}`);
|
|
286
|
+
else
|
|
287
|
+
clack.log.info("Already set in .env — skipped.");
|
|
288
|
+
}
|
|
269
289
|
}
|
|
270
290
|
// ── 5. x402 payments ────────────────────────────────────────────────────────
|
|
271
291
|
const wantX402 = await clack.confirm({ message: "Enable x402 micropayments?", initialValue: false });
|
|
@@ -302,14 +322,33 @@ async function runInteractiveSetup() {
|
|
|
302
322
|
" Output looks like:\n" +
|
|
303
323
|
" account-hash-d0a57c6a95e74463de156cac761e17f0923eafc730ce3ce3a0c747c6598b0500\n\n" +
|
|
304
324
|
" No casper-client? Install: cargo install casper-client");
|
|
305
|
-
|
|
306
|
-
"
|
|
307
|
-
"
|
|
308
|
-
"
|
|
309
|
-
"
|
|
310
|
-
|
|
311
|
-
"
|
|
312
|
-
|
|
325
|
+
const x402Vars = {
|
|
326
|
+
X402_ENABLE_REAL_SETTLEMENT: "true",
|
|
327
|
+
X402_SETTLEMENT_MODE: "casper-cli",
|
|
328
|
+
X402_BUYER_ACCOUNT_HASH: "account-hash-REPLACE_WITH_YOUR_HASH",
|
|
329
|
+
CASPER_ENABLE_REAL_SUBMISSION: "true",
|
|
330
|
+
CASPER_RPC_URL: x402RpcUrl,
|
|
331
|
+
CASPER_ACCOUNT_KEY_PATH: "./keys/secret_key.pem"
|
|
332
|
+
};
|
|
333
|
+
clack.log.info("Step 2 — .env vars:\n\n" +
|
|
334
|
+
Object.entries(x402Vars).map(([k, v]) => ` ${k}=${v}`).join("\n") +
|
|
335
|
+
`\n\n .env: ${result.envFile}`);
|
|
336
|
+
const writeX402 = await clack.confirm({
|
|
337
|
+
message: "Write these to your .env? (you'll still need to replace X402_BUYER_ACCOUNT_HASH)",
|
|
338
|
+
initialValue: true
|
|
339
|
+
});
|
|
340
|
+
if (!clack.isCancel(writeX402) && writeX402) {
|
|
341
|
+
const written = appendEnvVars(result.envFile, x402Vars);
|
|
342
|
+
if (written.length > 0) {
|
|
343
|
+
clack.log.success(`Written: ${written.join(", ")}`);
|
|
344
|
+
if (written.includes("X402_BUYER_ACCOUNT_HASH")) {
|
|
345
|
+
clack.log.warn(`Edit X402_BUYER_ACCOUNT_HASH in ${result.envFile} with your actual account hash after running Step 1.`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
clack.log.info("Already set in .env — skipped.");
|
|
350
|
+
}
|
|
351
|
+
}
|
|
313
352
|
clack.log.info("Step 3 — Fund your account\n\n" +
|
|
314
353
|
(x402Network === "testnet"
|
|
315
354
|
? ` Faucet: ${explorerBase}/tools/faucet\n`
|
package/package.json
CHANGED