@sofer_agent/cli 0.2.1 → 0.3.1
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/bin.js +6 -27
- package/dist/bin.js.map +1 -1
- package/dist/env.d.ts +6 -7
- package/dist/env.d.ts.map +1 -1
- package/dist/env.js +7 -25
- package/dist/env.js.map +1 -1
- package/dist/init.d.ts +4 -3
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +144 -59
- package/dist/init.js.map +1 -1
- package/dist/secrets.d.ts +1 -1
- package/dist/secrets.d.ts.map +1 -1
- package/dist/secrets.js +5 -5
- package/dist/secrets.js.map +1 -1
- package/package.json +3 -2
- package/src/bin.ts +6 -30
- package/src/env.ts +7 -24
- package/src/init.ts +163 -65
- package/src/secrets.ts +5 -5
package/dist/bin.js
CHANGED
|
@@ -1,38 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { agentPaths } from "@sofer_agent/core";
|
|
2
3
|
import { chatCommand } from "./chat.js";
|
|
3
|
-
import { loadDotenv } from "./env.js";
|
|
4
4
|
import { infoCommand } from "./info.js";
|
|
5
5
|
import { initCommand } from "./init.js";
|
|
6
6
|
function printHelp() {
|
|
7
7
|
console.log(`sofer — sovereign AI agent on Sui (memory on Walrus)
|
|
8
8
|
|
|
9
9
|
sofer chat with your agent (default)
|
|
10
|
-
sofer init mint
|
|
10
|
+
sofer init interactive setup — mint agent + provision memory
|
|
11
11
|
sofer info print on-chain agent state
|
|
12
|
-
sofer setup print the .env template to configure
|
|
13
12
|
sofer help show this help
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function printSetup() {
|
|
18
|
-
console.log(`# Copy this into a .env file in your project directory, then fill in:
|
|
19
|
-
# - ANTHROPIC_API_KEY (your Claude API key)
|
|
20
|
-
# - SOFER_SUI_SECRET_KEY (or let \`sofer init\` generate one)
|
|
21
|
-
#
|
|
22
|
-
# Then run: sofer init
|
|
23
|
-
|
|
24
|
-
# --- Sui chain ---
|
|
25
|
-
SUI_NETWORK=testnet
|
|
26
|
-
SUI_RPC_URL=https://fullnode.testnet.sui.io:443
|
|
27
|
-
SOFER_PACKAGE_ID=0xd5291ac6fd0de787f9fe0bc16c677ef5bafffd920936a05b14e7a8a142e46434
|
|
28
|
-
SOFER_AGENT_OBJECT_ID=
|
|
29
|
-
|
|
30
|
-
# --- Brain (Claude) ---
|
|
31
|
-
ANTHROPIC_API_KEY=
|
|
32
|
-
SOFER_MODEL=claude-opus-4-8`);
|
|
14
|
+
Config + secrets stored in ${agentPaths.root}/
|
|
15
|
+
Use env vars (SOFER_*) to override any setting.`);
|
|
33
16
|
}
|
|
34
17
|
async function main() {
|
|
35
|
-
loadDotenv();
|
|
36
18
|
const cmd = process.argv[2] ?? "chat";
|
|
37
19
|
switch (cmd) {
|
|
38
20
|
case "chat":
|
|
@@ -44,9 +26,6 @@ async function main() {
|
|
|
44
26
|
case "info":
|
|
45
27
|
await infoCommand();
|
|
46
28
|
break;
|
|
47
|
-
case "setup":
|
|
48
|
-
printSetup();
|
|
49
|
-
break;
|
|
50
29
|
case "help":
|
|
51
30
|
case "-h":
|
|
52
31
|
case "--help":
|
|
@@ -61,8 +40,8 @@ async function main() {
|
|
|
61
40
|
main().catch((e) => {
|
|
62
41
|
const msg = e instanceof Error ? e.message : String(e);
|
|
63
42
|
console.error(msg);
|
|
64
|
-
if (msg.includes("
|
|
65
|
-
console.error(
|
|
43
|
+
if (msg.includes("SOFER_SUI_SECRET_KEY") || msg.includes("ANTHROPIC_API_KEY") || msg.includes("SOFER_PACKAGE_ID")) {
|
|
44
|
+
console.error(`\nFirst time? Run \`sofer init\` — an interactive wizard (creates ${agentPaths.root}/).`);
|
|
66
45
|
}
|
|
67
46
|
process.exit(1);
|
|
68
47
|
});
|
package/dist/bin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"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Q,CAAC,sBAAsB,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAClH,OAAO,CAAC,KAAK,CAAC,qEAAqE,UAAU,CAAC,IAAI,KAAK,CAAC,CAAC;IAC3G,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/env.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Load
|
|
3
|
-
*
|
|
4
|
-
* Resolution order, so `sofer` works from any working directory:
|
|
5
|
-
* 1. `.env` in the current directory (a per-project override), else
|
|
6
|
-
* 2. `.env` at the repo root, found relative to this installed binary
|
|
7
|
-
* (`<repo>/packages/cli/dist/env.js` → `<repo>/.env`).
|
|
2
|
+
* Load secrets from ~/.sofer/ (sui.key, brain.key).
|
|
3
|
+
* Falls back to SOFER_SUI_SECRET_KEY and ANTHROPIC_API_KEY env vars.
|
|
8
4
|
*/
|
|
9
|
-
export declare function
|
|
5
|
+
export declare function loadSecrets(): {
|
|
6
|
+
suiSecretKey: string | null;
|
|
7
|
+
anthropicApiKey: string | null;
|
|
8
|
+
};
|
|
10
9
|
//# sourceMappingURL=env.d.ts.map
|
package/dist/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,WAAW,IAAI;IAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAI7F"}
|
package/dist/env.js
CHANGED
|
@@ -1,29 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
1
|
+
import { agentPaths, readSecret } from "@sofer_agent/core";
|
|
4
2
|
/**
|
|
5
|
-
* Load
|
|
6
|
-
*
|
|
7
|
-
* Resolution order, so `sofer` works from any working directory:
|
|
8
|
-
* 1. `.env` in the current directory (a per-project override), else
|
|
9
|
-
* 2. `.env` at the repo root, found relative to this installed binary
|
|
10
|
-
* (`<repo>/packages/cli/dist/env.js` → `<repo>/.env`).
|
|
3
|
+
* Load secrets from ~/.sofer/ (sui.key, brain.key).
|
|
4
|
+
* Falls back to SOFER_SUI_SECRET_KEY and ANTHROPIC_API_KEY env vars.
|
|
11
5
|
*/
|
|
12
|
-
export function
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const cwdEnv = resolve(process.cwd(), ".env");
|
|
17
|
-
const here = dirname(fileURLToPath(import.meta.url)); // <repo>/packages/cli/dist
|
|
18
|
-
const repoEnv = resolve(here, "../../../.env");
|
|
19
|
-
const target = existsSync(cwdEnv) ? cwdEnv : existsSync(repoEnv) ? repoEnv : null;
|
|
20
|
-
if (!target)
|
|
21
|
-
return;
|
|
22
|
-
try {
|
|
23
|
-
loader(target);
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
/* ignore malformed env file */
|
|
27
|
-
}
|
|
6
|
+
export function loadSecrets() {
|
|
7
|
+
const suiKey = readSecret(agentPaths.suiKey) ?? process.env.SOFER_SUI_SECRET_KEY ?? null;
|
|
8
|
+
const brainKey = readSecret(agentPaths.brainKey) ?? process.env.ANTHROPIC_API_KEY ?? null;
|
|
9
|
+
return { suiSecretKey: suiKey, anthropicApiKey: brainKey };
|
|
28
10
|
}
|
|
29
11
|
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE3D;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,MAAM,MAAM,GAAG,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,IAAI,IAAI,CAAC;IACzF,MAAM,QAAQ,GAAG,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,IAAI,CAAC;IAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC;AAC7D,CAAC"}
|
package/dist/init.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Interactive init wizard — mint the agent + provision Walrus memory.
|
|
3
|
+
* Stores config to ~/.sofer/config.json and secrets to ~/.sofer/{sui,brain}.key
|
|
4
|
+
*
|
|
5
|
+
* Idempotent: re-running on an already-set-up agent prints status and exits.
|
|
5
6
|
*/
|
|
6
7
|
export declare function initCommand(): Promise<void>;
|
|
7
8
|
//# sourceMappingURL=init.d.ts.map
|
package/dist/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AA2BA;;;;;GAKG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAkLjD"}
|
package/dist/init.js
CHANGED
|
@@ -1,62 +1,116 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { cancel, intro, isCancel, note, outro, password, select, spinner, } from "@clack/prompts";
|
|
2
|
+
import { AgentClient, agentPaths, generateKeypair, keypairFromSecret, loadConfig, makeSuiClient, provisionMemwal, requestFaucet, shortAgentId, suiBalance, waitForBalance, writePersistedConfig, writeSecret, } from "@sofer_agent/core";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Interactive init wizard — mint the agent + provision Walrus memory.
|
|
5
|
+
* Stores config to ~/.sofer/config.json and secrets to ~/.sofer/{sui,brain}.key
|
|
6
|
+
*
|
|
7
|
+
* Idempotent: re-running on an already-set-up agent prints status and exits.
|
|
6
8
|
*/
|
|
7
9
|
export async function initCommand() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const net = config.network === "mainnet" ? "mainnet" : "testnet";
|
|
12
|
-
// Already fully initialized? Don't re-mint / re-provision.
|
|
13
|
-
if (config.agentObjectId && config.memwal.accountId && config.memwal.delegateKey) {
|
|
10
|
+
// ── Already initialized? ───────────────────────────────────────────────
|
|
11
|
+
const existing = loadConfig();
|
|
12
|
+
if (existing.agentObjectId && existing.memwal.accountId && existing.memwal.delegateKey) {
|
|
14
13
|
console.log("Already initialized:");
|
|
15
|
-
console.log(`
|
|
16
|
-
console.log(`
|
|
17
|
-
console.log(
|
|
18
|
-
console.log(
|
|
14
|
+
console.log(` config: ${agentPaths.config}`);
|
|
15
|
+
console.log(` sui key: ${agentPaths.suiKey}`);
|
|
16
|
+
console.log(` brain key: ${agentPaths.brainKey}`);
|
|
17
|
+
console.log(` agent: ${existing.agentObjectId}`);
|
|
18
|
+
console.log(` memory: ${existing.memwal.accountId}`);
|
|
19
|
+
console.log(`\nRun \`sofer\` to chat. To start fresh, delete ${agentPaths.root}/.`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
intro("sofer init");
|
|
23
|
+
// ── 1. Network ─────────────────────────────────────────────────────────
|
|
24
|
+
const network = (await select({
|
|
25
|
+
message: "Which network?",
|
|
26
|
+
options: [
|
|
27
|
+
{ value: "testnet", label: "Sui Testnet" },
|
|
28
|
+
{ value: "mainnet", label: "Sui Mainnet" },
|
|
29
|
+
],
|
|
30
|
+
initialValue: "testnet",
|
|
31
|
+
}));
|
|
32
|
+
if (isCancel(network)) {
|
|
33
|
+
cancel("Aborted.");
|
|
19
34
|
return;
|
|
20
35
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
36
|
+
const net = network === "mainnet" ? "mainnet" : "testnet";
|
|
37
|
+
// ── 2. Anthropic API key ───────────────────────────────────────────────
|
|
38
|
+
const apiKey = (await password({
|
|
39
|
+
message: "Anthropic API key (stored in ~/.sofer/brain.key, never in .env)",
|
|
40
|
+
mask: "*",
|
|
41
|
+
}));
|
|
42
|
+
if (isCancel(apiKey) || !apiKey) {
|
|
43
|
+
cancel("API key is required.");
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// ── 3. Sui wallet ─────────────────────────────────────────────────────
|
|
47
|
+
const existingSecret = process.env.SOFER_SUI_SECRET_KEY;
|
|
48
|
+
const sGen = spinner();
|
|
49
|
+
let secret;
|
|
50
|
+
let address;
|
|
51
|
+
if (existingSecret) {
|
|
52
|
+
sGen.start("Loading wallet from SOFER_SUI_SECRET_KEY");
|
|
53
|
+
const kp = keypairFromSecret(existingSecret);
|
|
54
|
+
secret = existingSecret;
|
|
55
|
+
address = kp.toSuiAddress();
|
|
56
|
+
sGen.stop(`wallet: ${address} (from env)`);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
sGen.start("Generating new Sui wallet");
|
|
60
|
+
const kp = generateKeypair();
|
|
61
|
+
secret = kp.getSecretKey();
|
|
62
|
+
address = kp.toSuiAddress();
|
|
63
|
+
sGen.stop(`wallet: ${address} (new)`);
|
|
64
|
+
}
|
|
65
|
+
const config = loadConfig();
|
|
28
66
|
const sui = makeSuiClient(config.network);
|
|
29
|
-
//
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
67
|
+
// ── 4. Fund from faucet (testnet only) ─────────────────────────────────
|
|
68
|
+
if (net !== "mainnet") {
|
|
69
|
+
const bal = await suiBalance(sui, address);
|
|
70
|
+
if (bal === 0n) {
|
|
71
|
+
const sFund = spinner();
|
|
72
|
+
sFund.start("Requesting testnet faucet");
|
|
73
|
+
try {
|
|
74
|
+
await requestFaucet(config.network, address);
|
|
75
|
+
await waitForBalance(sui, address, 1n);
|
|
76
|
+
sFund.stop("funded");
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
sFund.stop(`faucet failed: ${String(e).slice(0, 80)}`);
|
|
80
|
+
note(`Fund ${address} at https://faucet.sui.io/ and re-run.`, "manual funding needed");
|
|
81
|
+
}
|
|
35
82
|
}
|
|
36
|
-
|
|
37
|
-
|
|
83
|
+
else {
|
|
84
|
+
note(`${(Number(bal) / 1e9).toFixed(4)} SUI on ${address}`, "wallet balance");
|
|
38
85
|
}
|
|
39
86
|
}
|
|
40
|
-
// 3. Mint the on-chain Agent object (reuse if one is already configured).
|
|
41
87
|
const agents = new AgentClient(sui, config.packageId);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
88
|
+
// ── 5. Mint agent ─────────────────────────────────────────────────────
|
|
89
|
+
let agentId = existing.agentObjectId;
|
|
90
|
+
if (!agentId) {
|
|
91
|
+
const sMint = spinner();
|
|
92
|
+
sMint.start("Minting agent identity object on-chain");
|
|
93
|
+
try {
|
|
94
|
+
const keypair = keypairFromSecret(secret);
|
|
95
|
+
const minted = await agents.mint(keypair, "Sofer", "a sovereign AI agent on Sui with encrypted memory on Walrus", new TextEncoder().encode("sofer"));
|
|
96
|
+
agentId = minted.agentId;
|
|
97
|
+
sMint.stop(`agent: ${agentId}`);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
sMint.stop(`mint failed: ${String(e).slice(0, 120)}`);
|
|
101
|
+
cancel("Mint failed. Is the wallet funded?");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
45
104
|
}
|
|
46
105
|
else {
|
|
47
|
-
|
|
48
|
-
const minted = await agents.mint(keypair, "Sofer", "a sovereign AI agent on Sui with encrypted memory on Walrus", new TextEncoder().encode("sofer"));
|
|
49
|
-
agentId = minted.agentId;
|
|
50
|
-
console.log(` agent object: ${agentId}`);
|
|
51
|
-
}
|
|
52
|
-
// 4. Provision Walrus memory — unless this wallet already has an account.
|
|
53
|
-
let accountId = config.memwal.accountId;
|
|
54
|
-
let delegateKey = config.memwal.delegateKey;
|
|
55
|
-
if (accountId && delegateKey) {
|
|
56
|
-
console.log(`• reusing memory account: ${accountId}`);
|
|
106
|
+
note(agentId, "reusing agent");
|
|
57
107
|
}
|
|
58
|
-
|
|
59
|
-
|
|
108
|
+
// ── 6. Provision MemWal memory ────────────────────────────────────────
|
|
109
|
+
let accountId = existing.memwal.accountId;
|
|
110
|
+
let delegateKey = existing.memwal.delegateKey;
|
|
111
|
+
if (!accountId || !delegateKey) {
|
|
112
|
+
const sMem = spinner();
|
|
113
|
+
sMem.start("Provisioning Walrus memory (MemWal)");
|
|
60
114
|
try {
|
|
61
115
|
const prov = await provisionMemwal({
|
|
62
116
|
ownerSecret: secret,
|
|
@@ -67,26 +121,57 @@ export async function initCommand() {
|
|
|
67
121
|
});
|
|
68
122
|
accountId = prov.accountId;
|
|
69
123
|
delegateKey = prov.delegateKey;
|
|
70
|
-
|
|
124
|
+
sMem.stop(`account: ${accountId}`);
|
|
71
125
|
}
|
|
72
126
|
catch (e) {
|
|
127
|
+
sMem.stop(`provision failed: ${String(e).slice(0, 120)}`);
|
|
73
128
|
const msg = String(e);
|
|
74
129
|
if (msg.includes("abort code: 3") || msg.includes("create_account")) {
|
|
75
|
-
|
|
76
|
-
" • Reuse it: set MEMWAL_ACCOUNT_ID and MEMWAL_DELEGATE_KEY in .env, then run `sofer`.\n" +
|
|
77
|
-
" • Or start fresh: unset SOFER_SUI_SECRET_KEY in .env and re-run `sofer init` to mint a new wallet.");
|
|
130
|
+
cancel("This wallet already owns a MemWal account.\nDelete ~/.sofer/ and re-run, or set env vars manually.");
|
|
78
131
|
}
|
|
79
|
-
|
|
132
|
+
return;
|
|
80
133
|
}
|
|
81
134
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
135
|
+
else {
|
|
136
|
+
note(accountId, "reusing memory account");
|
|
137
|
+
}
|
|
138
|
+
// ── 7. Link memory to agent on-chain ───────────────────────────────────
|
|
139
|
+
const sLink = spinner();
|
|
140
|
+
sLink.start("Linking memory account to agent on-chain");
|
|
141
|
+
try {
|
|
142
|
+
const keypair = keypairFromSecret(secret);
|
|
143
|
+
await agents.setMemoryAccount(keypair, agentId, accountId);
|
|
144
|
+
sLink.stop("linked");
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
sLink.stop(`link failed (may already be linked): ${String(e).slice(0, 80)}`);
|
|
148
|
+
}
|
|
149
|
+
// ── 8. Persist config + secrets to ~/.sofer/ ───────────────────────────
|
|
150
|
+
const sSave = spinner();
|
|
151
|
+
sSave.start("Saving to ~/.sofer/");
|
|
152
|
+
writeSecret(agentPaths.suiKey, secret);
|
|
153
|
+
writeSecret(agentPaths.brainKey, apiKey);
|
|
154
|
+
const persisted = {
|
|
155
|
+
network: net,
|
|
156
|
+
agentObjectId: agentId,
|
|
157
|
+
agentAddress: address,
|
|
158
|
+
brain: { model: config.brain.model },
|
|
159
|
+
memwal: {
|
|
160
|
+
accountId: accountId,
|
|
161
|
+
delegateKey: delegateKey,
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
writePersistedConfig(persisted);
|
|
165
|
+
sSave.stop(`config: ${agentPaths.config}`);
|
|
166
|
+
// ── 9. Summary ────────────────────────────────────────────────────────
|
|
167
|
+
const lines = [
|
|
168
|
+
`agent ${agentId.slice(0, 30)}…`,
|
|
169
|
+
`address ${address.slice(0, 10)}…`,
|
|
170
|
+
`network ${net}`,
|
|
171
|
+
`memory ${accountId.slice(0, 10)}…`,
|
|
172
|
+
"",
|
|
173
|
+
"Run `sofer` to chat with your agent.",
|
|
174
|
+
];
|
|
175
|
+
outro(lines.join("\n"));
|
|
91
176
|
}
|
|
92
177
|
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,eAAe,EACf,aAAa,EACb,UAAU,EACV,cAAc,
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,KAAK,EACL,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,QAAQ,EACR,MAAM,EACN,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAEL,WAAW,EACX,UAAU,EACV,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,aAAa,EACb,eAAe,EACf,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,GACZ,MAAM,mBAAmB,CAAC;AAE3B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW;IAC/B,0EAA0E;IAC1E,MAAM,QAAQ,GAAG,UAAU,EAAE,CAAC;IAC9B,IAAI,QAAQ,CAAC,aAAa,IAAI,QAAQ,CAAC,MAAM,CAAC,SAAS,IAAI,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;QACvF,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,iBAAiB,UAAU,CAAC,MAAM,EAAE,CAAC,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GAAG;QACZ,YAAY,OAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG;QACpC,YAAY,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG;QACnC,YAAY,GAAG,EAAE;QACjB,YAAY,SAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG;QACtC,EAAE;QACF,sCAAsC;KACvC,CAAC;IACF,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/secrets.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { AgentSecrets } from "@sofer_agent/core";
|
|
2
|
-
/** Pull required secrets from
|
|
2
|
+
/** Pull required secrets from ~/.sofer/ or env vars, with actionable errors. */
|
|
3
3
|
export declare function requireSecrets(): AgentSecrets;
|
|
4
4
|
//# sourceMappingURL=secrets.d.ts.map
|
package/dist/secrets.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGtD,gFAAgF;AAChF,wBAAgB,cAAc,IAAI,YAAY,CAS7C"}
|
package/dist/secrets.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import { loadSecrets } from "./env.js";
|
|
2
|
+
/** Pull required secrets from ~/.sofer/ or env vars, with actionable errors. */
|
|
2
3
|
export function requireSecrets() {
|
|
3
|
-
const suiSecretKey =
|
|
4
|
-
const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
|
|
4
|
+
const { suiSecretKey, anthropicApiKey } = loadSecrets();
|
|
5
5
|
if (!suiSecretKey) {
|
|
6
|
-
throw new Error("SOFER_SUI_SECRET_KEY not
|
|
6
|
+
throw new Error("SOFER_SUI_SECRET_KEY not found — run `sofer init` first (creates ~/.sofer/sui.key)");
|
|
7
7
|
}
|
|
8
8
|
if (!anthropicApiKey) {
|
|
9
|
-
throw new Error("ANTHROPIC_API_KEY not
|
|
9
|
+
throw new Error("ANTHROPIC_API_KEY not found — run `sofer init` first (creates ~/.sofer/brain.key)");
|
|
10
10
|
}
|
|
11
11
|
return { suiSecretKey, anthropicApiKey };
|
|
12
12
|
}
|
package/dist/secrets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"secrets.js","sourceRoot":"","sources":["../src/secrets.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,gFAAgF;AAChF,MAAM,UAAU,cAAc;IAC5B,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,WAAW,EAAE,CAAC;IACxD,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,oFAAoF,CAAC,CAAC;IACxG,CAAC;IACD,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,mFAAmF,CAAC,CAAC;IACvG,CAAC;IACD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,CAAC;AAC3C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sofer_agent/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sofer": "./dist/bin.js"
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"cli"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@
|
|
28
|
+
"@clack/prompts": "^1.5.1",
|
|
29
|
+
"@sofer_agent/core": "0.3.0"
|
|
29
30
|
},
|
|
30
31
|
"devDependencies": {
|
|
31
32
|
"@types/node": "^22.10.2",
|
package/src/bin.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { agentPaths } from "@sofer_agent/core";
|
|
2
3
|
import { chatCommand } from "./chat.js";
|
|
3
|
-
import { loadDotenv } from "./env.js";
|
|
4
4
|
import { infoCommand } from "./info.js";
|
|
5
5
|
import { initCommand } from "./init.js";
|
|
6
6
|
|
|
@@ -9,37 +9,16 @@ function printHelp(): void {
|
|
|
9
9
|
`sofer — sovereign AI agent on Sui (memory on Walrus)
|
|
10
10
|
|
|
11
11
|
sofer chat with your agent (default)
|
|
12
|
-
sofer init mint
|
|
12
|
+
sofer init interactive setup — mint agent + provision memory
|
|
13
13
|
sofer info print on-chain agent state
|
|
14
|
-
sofer setup print the .env template to configure
|
|
15
14
|
sofer help show this help
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function printSetup(): void {
|
|
22
|
-
console.log(
|
|
23
|
-
`# Copy this into a .env file in your project directory, then fill in:
|
|
24
|
-
# - ANTHROPIC_API_KEY (your Claude API key)
|
|
25
|
-
# - SOFER_SUI_SECRET_KEY (or let \`sofer init\` generate one)
|
|
26
|
-
#
|
|
27
|
-
# Then run: sofer init
|
|
28
|
-
|
|
29
|
-
# --- Sui chain ---
|
|
30
|
-
SUI_NETWORK=testnet
|
|
31
|
-
SUI_RPC_URL=https://fullnode.testnet.sui.io:443
|
|
32
|
-
SOFER_PACKAGE_ID=0xd5291ac6fd0de787f9fe0bc16c677ef5bafffd920936a05b14e7a8a142e46434
|
|
33
|
-
SOFER_AGENT_OBJECT_ID=
|
|
34
|
-
|
|
35
|
-
# --- Brain (Claude) ---
|
|
36
|
-
ANTHROPIC_API_KEY=
|
|
37
|
-
SOFER_MODEL=claude-opus-4-8`,
|
|
16
|
+
Config + secrets stored in ${agentPaths.root}/
|
|
17
|
+
Use env vars (SOFER_*) to override any setting.`,
|
|
38
18
|
);
|
|
39
19
|
}
|
|
40
20
|
|
|
41
21
|
async function main(): Promise<void> {
|
|
42
|
-
loadDotenv();
|
|
43
22
|
const cmd = process.argv[2] ?? "chat";
|
|
44
23
|
switch (cmd) {
|
|
45
24
|
case "chat":
|
|
@@ -51,9 +30,6 @@ async function main(): Promise<void> {
|
|
|
51
30
|
case "info":
|
|
52
31
|
await infoCommand();
|
|
53
32
|
break;
|
|
54
|
-
case "setup":
|
|
55
|
-
printSetup();
|
|
56
|
-
break;
|
|
57
33
|
case "help":
|
|
58
34
|
case "-h":
|
|
59
35
|
case "--help":
|
|
@@ -69,8 +45,8 @@ async function main(): Promise<void> {
|
|
|
69
45
|
main().catch((e) => {
|
|
70
46
|
const msg = e instanceof Error ? e.message : String(e);
|
|
71
47
|
console.error(msg);
|
|
72
|
-
if (msg.includes("
|
|
73
|
-
console.error(
|
|
48
|
+
if (msg.includes("SOFER_SUI_SECRET_KEY") || msg.includes("ANTHROPIC_API_KEY") || msg.includes("SOFER_PACKAGE_ID")) {
|
|
49
|
+
console.error(`\nFirst time? Run \`sofer init\` — an interactive wizard (creates ${agentPaths.root}/).`);
|
|
74
50
|
}
|
|
75
51
|
process.exit(1);
|
|
76
52
|
});
|
package/src/env.ts
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
1
|
+
import { agentPaths, readSecret } from "@sofer_agent/core";
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
|
-
* Load
|
|
7
|
-
*
|
|
8
|
-
* Resolution order, so `sofer` works from any working directory:
|
|
9
|
-
* 1. `.env` in the current directory (a per-project override), else
|
|
10
|
-
* 2. `.env` at the repo root, found relative to this installed binary
|
|
11
|
-
* (`<repo>/packages/cli/dist/env.js` → `<repo>/.env`).
|
|
4
|
+
* Load secrets from ~/.sofer/ (sui.key, brain.key).
|
|
5
|
+
* Falls back to SOFER_SUI_SECRET_KEY and ANTHROPIC_API_KEY env vars.
|
|
12
6
|
*/
|
|
13
|
-
export function
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const cwdEnv = resolve(process.cwd(), ".env");
|
|
18
|
-
const here = dirname(fileURLToPath(import.meta.url)); // <repo>/packages/cli/dist
|
|
19
|
-
const repoEnv = resolve(here, "../../../.env");
|
|
20
|
-
|
|
21
|
-
const target = existsSync(cwdEnv) ? cwdEnv : existsSync(repoEnv) ? repoEnv : null;
|
|
22
|
-
if (!target) return;
|
|
23
|
-
try {
|
|
24
|
-
loader(target);
|
|
25
|
-
} catch {
|
|
26
|
-
/* ignore malformed env file */
|
|
27
|
-
}
|
|
7
|
+
export function loadSecrets(): { suiSecretKey: string | null; anthropicApiKey: string | null } {
|
|
8
|
+
const suiKey = readSecret(agentPaths.suiKey) ?? process.env.SOFER_SUI_SECRET_KEY ?? null;
|
|
9
|
+
const brainKey = readSecret(agentPaths.brainKey) ?? process.env.ANTHROPIC_API_KEY ?? null;
|
|
10
|
+
return { suiSecretKey: suiKey, anthropicApiKey: brainKey };
|
|
28
11
|
}
|
package/src/init.ts
CHANGED
|
@@ -1,82 +1,150 @@
|
|
|
1
1
|
import {
|
|
2
|
+
cancel,
|
|
3
|
+
intro,
|
|
4
|
+
isCancel,
|
|
5
|
+
note,
|
|
6
|
+
outro,
|
|
7
|
+
password,
|
|
8
|
+
select,
|
|
9
|
+
spinner,
|
|
10
|
+
} from "@clack/prompts";
|
|
11
|
+
import {
|
|
12
|
+
type PersistedConfig,
|
|
2
13
|
AgentClient,
|
|
14
|
+
agentPaths,
|
|
3
15
|
generateKeypair,
|
|
4
16
|
keypairFromSecret,
|
|
5
17
|
loadConfig,
|
|
6
18
|
makeSuiClient,
|
|
7
19
|
provisionMemwal,
|
|
8
20
|
requestFaucet,
|
|
21
|
+
shortAgentId,
|
|
9
22
|
suiBalance,
|
|
10
23
|
waitForBalance,
|
|
24
|
+
writePersistedConfig,
|
|
25
|
+
writeSecret,
|
|
11
26
|
} from "@sofer_agent/core";
|
|
12
27
|
|
|
13
28
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
29
|
+
* Interactive init wizard — mint the agent + provision Walrus memory.
|
|
30
|
+
* Stores config to ~/.sofer/config.json and secrets to ~/.sofer/{sui,brain}.key
|
|
31
|
+
*
|
|
32
|
+
* Idempotent: re-running on an already-set-up agent prints status and exits.
|
|
17
33
|
*/
|
|
18
34
|
export async function initCommand(): Promise<void> {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// Already fully initialized? Don't re-mint / re-provision.
|
|
24
|
-
if (config.agentObjectId && config.memwal.accountId && config.memwal.delegateKey) {
|
|
35
|
+
// ── Already initialized? ───────────────────────────────────────────────
|
|
36
|
+
const existing = loadConfig();
|
|
37
|
+
if (existing.agentObjectId && existing.memwal.accountId && existing.memwal.delegateKey) {
|
|
25
38
|
console.log("Already initialized:");
|
|
26
|
-
console.log(`
|
|
27
|
-
console.log(`
|
|
28
|
-
console.log(
|
|
29
|
-
console.log(
|
|
39
|
+
console.log(` config: ${agentPaths.config}`);
|
|
40
|
+
console.log(` sui key: ${agentPaths.suiKey}`);
|
|
41
|
+
console.log(` brain key: ${agentPaths.brainKey}`);
|
|
42
|
+
console.log(` agent: ${existing.agentObjectId}`);
|
|
43
|
+
console.log(` memory: ${existing.memwal.accountId}`);
|
|
44
|
+
console.log(`\nRun \`sofer\` to chat. To start fresh, delete ${agentPaths.root}/.`);
|
|
30
45
|
return;
|
|
31
46
|
}
|
|
32
47
|
|
|
33
|
-
|
|
34
|
-
const keypair = process.env.SOFER_SUI_SECRET_KEY
|
|
35
|
-
? keypairFromSecret(process.env.SOFER_SUI_SECRET_KEY)
|
|
36
|
-
: generateKeypair();
|
|
37
|
-
const secret = keypair.getSecretKey();
|
|
38
|
-
const address = keypair.toSuiAddress();
|
|
39
|
-
console.log(`• wallet: ${address}`);
|
|
48
|
+
intro("sofer init");
|
|
40
49
|
|
|
50
|
+
// ── 1. Network ─────────────────────────────────────────────────────────
|
|
51
|
+
const network = (await select({
|
|
52
|
+
message: "Which network?",
|
|
53
|
+
options: [
|
|
54
|
+
{ value: "testnet", label: "Sui Testnet" },
|
|
55
|
+
{ value: "mainnet", label: "Sui Mainnet" },
|
|
56
|
+
],
|
|
57
|
+
initialValue: "testnet",
|
|
58
|
+
})) as string | symbol;
|
|
59
|
+
if (isCancel(network)) {
|
|
60
|
+
cancel("Aborted.");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const net = network === "mainnet" ? "mainnet" : "testnet";
|
|
64
|
+
|
|
65
|
+
// ── 2. Anthropic API key ───────────────────────────────────────────────
|
|
66
|
+
const apiKey = (await password({
|
|
67
|
+
message: "Anthropic API key (stored in ~/.sofer/brain.key, never in .env)",
|
|
68
|
+
mask: "*",
|
|
69
|
+
})) as string | symbol;
|
|
70
|
+
if (isCancel(apiKey) || !apiKey) {
|
|
71
|
+
cancel("API key is required.");
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ── 3. Sui wallet ─────────────────────────────────────────────────────
|
|
76
|
+
const existingSecret = process.env.SOFER_SUI_SECRET_KEY;
|
|
77
|
+
const sGen = spinner();
|
|
78
|
+
let secret: string;
|
|
79
|
+
let address: string;
|
|
80
|
+
if (existingSecret) {
|
|
81
|
+
sGen.start("Loading wallet from SOFER_SUI_SECRET_KEY");
|
|
82
|
+
const kp = keypairFromSecret(existingSecret);
|
|
83
|
+
secret = existingSecret;
|
|
84
|
+
address = kp.toSuiAddress();
|
|
85
|
+
sGen.stop(`wallet: ${address} (from env)`);
|
|
86
|
+
} else {
|
|
87
|
+
sGen.start("Generating new Sui wallet");
|
|
88
|
+
const kp = generateKeypair();
|
|
89
|
+
secret = kp.getSecretKey();
|
|
90
|
+
address = kp.toSuiAddress();
|
|
91
|
+
sGen.stop(`wallet: ${address} (new)`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const config = loadConfig();
|
|
41
95
|
const sui = makeSuiClient(config.network);
|
|
42
96
|
|
|
43
|
-
//
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
97
|
+
// ── 4. Fund from faucet (testnet only) ─────────────────────────────────
|
|
98
|
+
if (net !== "mainnet") {
|
|
99
|
+
const bal = await suiBalance(sui, address);
|
|
100
|
+
if (bal === 0n) {
|
|
101
|
+
const sFund = spinner();
|
|
102
|
+
sFund.start("Requesting testnet faucet");
|
|
103
|
+
try {
|
|
104
|
+
await requestFaucet(config.network, address);
|
|
105
|
+
await waitForBalance(sui, address, 1n);
|
|
106
|
+
sFund.stop("funded");
|
|
107
|
+
} catch (e) {
|
|
108
|
+
sFund.stop(`faucet failed: ${String(e).slice(0, 80)}`);
|
|
109
|
+
note(`Fund ${address} at https://faucet.sui.io/ and re-run.`, "manual funding needed");
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
112
|
+
note(`${(Number(bal) / 1e9).toFixed(4)} SUI on ${address}`, "wallet balance");
|
|
53
113
|
}
|
|
54
114
|
}
|
|
55
115
|
|
|
56
|
-
// 3. Mint the on-chain Agent object (reuse if one is already configured).
|
|
57
116
|
const agents = new AgentClient(sui, config.packageId);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
117
|
+
|
|
118
|
+
// ── 5. Mint agent ─────────────────────────────────────────────────────
|
|
119
|
+
let agentId = existing.agentObjectId;
|
|
120
|
+
if (!agentId) {
|
|
121
|
+
const sMint = spinner();
|
|
122
|
+
sMint.start("Minting agent identity object on-chain");
|
|
123
|
+
try {
|
|
124
|
+
const keypair = keypairFromSecret(secret);
|
|
125
|
+
const minted = await agents.mint(
|
|
126
|
+
keypair,
|
|
127
|
+
"Sofer",
|
|
128
|
+
"a sovereign AI agent on Sui with encrypted memory on Walrus",
|
|
129
|
+
new TextEncoder().encode("sofer"),
|
|
130
|
+
);
|
|
131
|
+
agentId = minted.agentId;
|
|
132
|
+
sMint.stop(`agent: ${agentId}`);
|
|
133
|
+
} catch (e) {
|
|
134
|
+
sMint.stop(`mint failed: ${String(e).slice(0, 120)}`);
|
|
135
|
+
cancel("Mint failed. Is the wallet funded?");
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
61
138
|
} else {
|
|
62
|
-
|
|
63
|
-
const minted = await agents.mint(
|
|
64
|
-
keypair,
|
|
65
|
-
"Sofer",
|
|
66
|
-
"a sovereign AI agent on Sui with encrypted memory on Walrus",
|
|
67
|
-
new TextEncoder().encode("sofer"),
|
|
68
|
-
);
|
|
69
|
-
agentId = minted.agentId;
|
|
70
|
-
console.log(` agent object: ${agentId}`);
|
|
139
|
+
note(agentId, "reusing agent");
|
|
71
140
|
}
|
|
72
141
|
|
|
73
|
-
//
|
|
74
|
-
let accountId =
|
|
75
|
-
let delegateKey =
|
|
76
|
-
if (accountId
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
console.log("• provisioning Walrus memory (MemWal account + delegate key)…");
|
|
142
|
+
// ── 6. Provision MemWal memory ────────────────────────────────────────
|
|
143
|
+
let accountId = existing.memwal.accountId;
|
|
144
|
+
let delegateKey = existing.memwal.delegateKey;
|
|
145
|
+
if (!accountId || !delegateKey) {
|
|
146
|
+
const sMem = spinner();
|
|
147
|
+
sMem.start("Provisioning Walrus memory (MemWal)");
|
|
80
148
|
try {
|
|
81
149
|
const prov = await provisionMemwal({
|
|
82
150
|
ownerSecret: secret,
|
|
@@ -87,28 +155,58 @@ export async function initCommand(): Promise<void> {
|
|
|
87
155
|
});
|
|
88
156
|
accountId = prov.accountId;
|
|
89
157
|
delegateKey = prov.delegateKey;
|
|
90
|
-
|
|
158
|
+
sMem.stop(`account: ${accountId}`);
|
|
91
159
|
} catch (e) {
|
|
160
|
+
sMem.stop(`provision failed: ${String(e).slice(0, 120)}`);
|
|
92
161
|
const msg = String(e);
|
|
93
162
|
if (msg.includes("abort code: 3") || msg.includes("create_account")) {
|
|
94
|
-
|
|
95
|
-
"This
|
|
96
|
-
" • Reuse it: set MEMWAL_ACCOUNT_ID and MEMWAL_DELEGATE_KEY in .env, then run `sofer`.\n" +
|
|
97
|
-
" • Or start fresh: unset SOFER_SUI_SECRET_KEY in .env and re-run `sofer init` to mint a new wallet.",
|
|
163
|
+
cancel(
|
|
164
|
+
"This wallet already owns a MemWal account.\nDelete ~/.sofer/ and re-run, or set env vars manually.",
|
|
98
165
|
);
|
|
99
166
|
}
|
|
100
|
-
|
|
167
|
+
return;
|
|
101
168
|
}
|
|
169
|
+
} else {
|
|
170
|
+
note(accountId, "reusing memory account");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ── 7. Link memory to agent on-chain ───────────────────────────────────
|
|
174
|
+
const sLink = spinner();
|
|
175
|
+
sLink.start("Linking memory account to agent on-chain");
|
|
176
|
+
try {
|
|
177
|
+
const keypair = keypairFromSecret(secret);
|
|
178
|
+
await agents.setMemoryAccount(keypair, agentId!, accountId!);
|
|
179
|
+
sLink.stop("linked");
|
|
180
|
+
} catch (e) {
|
|
181
|
+
sLink.stop(`link failed (may already be linked): ${String(e).slice(0, 80)}`);
|
|
102
182
|
}
|
|
103
183
|
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
|
|
184
|
+
// ── 8. Persist config + secrets to ~/.sofer/ ───────────────────────────
|
|
185
|
+
const sSave = spinner();
|
|
186
|
+
sSave.start("Saving to ~/.sofer/");
|
|
187
|
+
writeSecret(agentPaths.suiKey, secret);
|
|
188
|
+
writeSecret(agentPaths.brainKey, apiKey);
|
|
189
|
+
const persisted: PersistedConfig = {
|
|
190
|
+
network: net,
|
|
191
|
+
agentObjectId: agentId!,
|
|
192
|
+
agentAddress: address,
|
|
193
|
+
brain: { model: config.brain.model },
|
|
194
|
+
memwal: {
|
|
195
|
+
accountId: accountId!,
|
|
196
|
+
delegateKey: delegateKey!,
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
writePersistedConfig(persisted);
|
|
200
|
+
sSave.stop(`config: ${agentPaths.config}`);
|
|
107
201
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
202
|
+
// ── 9. Summary ────────────────────────────────────────────────────────
|
|
203
|
+
const lines = [
|
|
204
|
+
`agent ${agentId!.slice(0, 30)}…`,
|
|
205
|
+
`address ${address.slice(0, 10)}…`,
|
|
206
|
+
`network ${net}`,
|
|
207
|
+
`memory ${accountId!.slice(0, 10)}…`,
|
|
208
|
+
"",
|
|
209
|
+
"Run `sofer` to chat with your agent.",
|
|
210
|
+
];
|
|
211
|
+
outro(lines.join("\n"));
|
|
114
212
|
}
|
package/src/secrets.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { AgentSecrets } from "@sofer_agent/core";
|
|
2
|
+
import { loadSecrets } from "./env.js";
|
|
2
3
|
|
|
3
|
-
/** Pull required secrets from
|
|
4
|
+
/** Pull required secrets from ~/.sofer/ or env vars, with actionable errors. */
|
|
4
5
|
export function requireSecrets(): AgentSecrets {
|
|
5
|
-
const suiSecretKey =
|
|
6
|
-
const anthropicApiKey = process.env.ANTHROPIC_API_KEY;
|
|
6
|
+
const { suiSecretKey, anthropicApiKey } = loadSecrets();
|
|
7
7
|
if (!suiSecretKey) {
|
|
8
|
-
throw new Error("SOFER_SUI_SECRET_KEY not
|
|
8
|
+
throw new Error("SOFER_SUI_SECRET_KEY not found — run `sofer init` first (creates ~/.sofer/sui.key)");
|
|
9
9
|
}
|
|
10
10
|
if (!anthropicApiKey) {
|
|
11
|
-
throw new Error("ANTHROPIC_API_KEY not
|
|
11
|
+
throw new Error("ANTHROPIC_API_KEY not found — run `sofer init` first (creates ~/.sofer/brain.key)");
|
|
12
12
|
}
|
|
13
13
|
return { suiSecretKey, anthropicApiKey };
|
|
14
14
|
}
|