@oneie/cli 0.9.0 → 0.10.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/package.json +2 -2
- package/dist/src/catalog.js +2 -1
- package/dist/src/client.js +2 -1
- package/dist/src/coordinate.js +2 -1
- package/dist/src/index.js +2 -0
- package/dist/src/lib/api-path.d.ts +1 -0
- package/dist/src/lib/api-path.js +9 -0
- package/dist/src/onboard.d.ts +16 -0
- package/dist/src/onboard.js +146 -0
- package/dist/src/render.d.ts +1 -0
- package/dist/src/render.js +1 -1
- package/dist/src/setup.js +10 -2
- package/dist/src/status.js +13 -5
- package/dist/src/trade.js +2 -1
- package/dist/src/wallet.d.ts +3 -1
- package/dist/src/wallet.js +48 -9
- package/package.json +3 -3
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "ONE agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"commander": "^12.0.0",
|
|
23
|
-
"@oneie/sdk": "
|
|
23
|
+
"@oneie/sdk": "workspace:*"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@oneie/evals": "workspace:*",
|
package/dist/src/catalog.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { askPath } from './lib/api-path.js';
|
|
1
2
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
2
3
|
function apiKey() {
|
|
3
4
|
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
@@ -57,7 +58,7 @@ export function catalogCommands(program) {
|
|
|
57
58
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
58
59
|
.option('--json', 'Output raw JSON')
|
|
59
60
|
.action(async (opts) => {
|
|
60
|
-
const res = await fetch(
|
|
61
|
+
const res = await fetch(askPath(base(opts), 'meta:catalog'), {
|
|
61
62
|
method: 'POST',
|
|
62
63
|
headers: authHeaders(),
|
|
63
64
|
body: JSON.stringify({ data: opts.goal ? { goal: opts.goal } : {} }),
|
package/dist/src/client.js
CHANGED
|
@@ -3,9 +3,10 @@ import { mergeEnv } from './env.js';
|
|
|
3
3
|
import { readClient } from './config.js';
|
|
4
4
|
import { validateClient } from './validate.js';
|
|
5
5
|
import { safeSlug } from './slug.js';
|
|
6
|
+
import { askPath } from './lib/api-path.js';
|
|
6
7
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
7
8
|
async function ask(base, key, receiver, data) {
|
|
8
|
-
const res = await fetch(
|
|
9
|
+
const res = await fetch(askPath(base, receiver), {
|
|
9
10
|
method: 'POST',
|
|
10
11
|
headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
11
12
|
body: JSON.stringify({ data }),
|
package/dist/src/coordinate.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { askPath } from './lib/api-path.js';
|
|
1
2
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
2
3
|
function apiKey() {
|
|
3
4
|
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
@@ -32,7 +33,7 @@ export function coordinateCommands(program) {
|
|
|
32
33
|
const payload = { limit: Number(opts.limit) };
|
|
33
34
|
if (opts.about)
|
|
34
35
|
payload.match = opts.about;
|
|
35
|
-
const res = await fetch(
|
|
36
|
+
const res = await fetch(askPath(base(opts), 'meta:recall'), {
|
|
36
37
|
method: 'POST',
|
|
37
38
|
headers: authHeaders(),
|
|
38
39
|
body: JSON.stringify({ data: payload }),
|
package/dist/src/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { createCmd } from './create.js';
|
|
|
27
27
|
import { fnCmd } from './fn.js';
|
|
28
28
|
import { trailCmd } from './trail.js';
|
|
29
29
|
import { initCmd } from './init.js';
|
|
30
|
+
import { onboardCmd } from './onboard.js';
|
|
30
31
|
import { pluginCmd } from './plugin.js';
|
|
31
32
|
import { readFileSync } from 'node:fs';
|
|
32
33
|
import { fileURLToPath } from 'node:url';
|
|
@@ -66,6 +67,7 @@ program.addCommand(createCmd());
|
|
|
66
67
|
program.addCommand(fnCmd());
|
|
67
68
|
program.addCommand(trailCmd());
|
|
68
69
|
program.addCommand(initCmd());
|
|
70
|
+
program.addCommand(onboardCmd());
|
|
69
71
|
program.addCommand(pluginCmd());
|
|
70
72
|
program.parseAsync(process.argv).catch((err) => {
|
|
71
73
|
const isJson = process.argv.includes('--json');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function askPath(base: string, receiver: string): string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The api.one.ie GATEWAY serves substrate ops at the short form (/ask/<receiver>,
|
|
2
|
+
// mapped internally to one-prod's /api/ask/<receiver> — api/src/substrate-binding.ts
|
|
3
|
+
// PATH_MAP). Calling /api/ask/ directly against the gateway 404s (verified live
|
|
4
|
+
// 2026-07-03). one.ie/web itself only answers the long form. Pick the path that
|
|
5
|
+
// matches whichever host --api actually points at, rather than hardcoding one.
|
|
6
|
+
export function askPath(base, receiver) {
|
|
7
|
+
const isGateway = new URL(base).hostname === 'api.one.ie';
|
|
8
|
+
return `${base}${isGateway ? '/ask' : '/api/ask'}/${encodeURIComponent(receiver)}`;
|
|
9
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oneie onboard — deterministically walk a fresh agent through the platform's
|
|
3
|
+
* agent-onboarding lifecycle (text/agent-onboarding-lifecycle.md): registered
|
|
4
|
+
* → bootstrapped → active → settled → adopted.
|
|
5
|
+
*
|
|
6
|
+
* Reuses the same zero-to-live call `one init` uses (POST /api/provision/agent)
|
|
7
|
+
* for register+bootstrap — both stages are tracked server-side automatically
|
|
8
|
+
* (no extra calls from here). Adds the read-back + guide layer `init` doesn't:
|
|
9
|
+
* after provisioning, reads the real stage_transition log via lifecycle:mine
|
|
10
|
+
* and tells the agent exactly what unlocks each remaining stage.
|
|
11
|
+
*
|
|
12
|
+
* Idempotent: if this directory already has ONE_API_KEY, skips provisioning
|
|
13
|
+
* and just reports current lifecycle position.
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
export declare function onboardCmd(): Command;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oneie onboard — deterministically walk a fresh agent through the platform's
|
|
3
|
+
* agent-onboarding lifecycle (text/agent-onboarding-lifecycle.md): registered
|
|
4
|
+
* → bootstrapped → active → settled → adopted.
|
|
5
|
+
*
|
|
6
|
+
* Reuses the same zero-to-live call `one init` uses (POST /api/provision/agent)
|
|
7
|
+
* for register+bootstrap — both stages are tracked server-side automatically
|
|
8
|
+
* (no extra calls from here). Adds the read-back + guide layer `init` doesn't:
|
|
9
|
+
* after provisioning, reads the real stage_transition log via lifecycle:mine
|
|
10
|
+
* and tells the agent exactly what unlocks each remaining stage.
|
|
11
|
+
*
|
|
12
|
+
* Idempotent: if this directory already has ONE_API_KEY, skips provisioning
|
|
13
|
+
* and just reports current lifecycle position.
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
import { writeFileSync, mkdirSync, renameSync, chmodSync } from 'node:fs';
|
|
17
|
+
import { resolve, join } from 'node:path';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
import { mergeEnv, writeEnvLocal } from './env.js';
|
|
20
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://one.ie';
|
|
21
|
+
const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
|
|
22
|
+
const KEY_FILE = resolve(CONFIG_DIR, 'key');
|
|
23
|
+
function writeKey(value) {
|
|
24
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
25
|
+
const tmp = join(CONFIG_DIR, '.key.tmp');
|
|
26
|
+
writeFileSync(tmp, value, { mode: 0o600 });
|
|
27
|
+
chmodSync(tmp, 0o600);
|
|
28
|
+
renameSync(tmp, KEY_FILE);
|
|
29
|
+
}
|
|
30
|
+
async function ask(base, key, receiver, data) {
|
|
31
|
+
const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
34
|
+
body: JSON.stringify({ data }),
|
|
35
|
+
});
|
|
36
|
+
const json = (await res.json().catch(() => ({})));
|
|
37
|
+
if (!res.ok)
|
|
38
|
+
throw new Error(`${receiver} → ${res.status}: ${JSON.stringify(json)}`);
|
|
39
|
+
return json;
|
|
40
|
+
}
|
|
41
|
+
// The 5 stages, in order, and what unlocks each one — mirrors
|
|
42
|
+
// SEED_DEFS['agent-onboarding'] in one.ie/web/src/lib/lifecycle/seed.ts.
|
|
43
|
+
// Kept here as plain data (not fetched) so `onboard` works even before the
|
|
44
|
+
// agent has a key to call the substrate with.
|
|
45
|
+
const STAGE_GUIDE = {
|
|
46
|
+
registered: 'done — your identity exists (uid + apiKey minted).',
|
|
47
|
+
bootstrapped: 'done — your own workspace exists (gid + aid + scopedKey minted).',
|
|
48
|
+
active: 'publish a capability or place a market offer: `one agent publish` or `one trade market`.',
|
|
49
|
+
settled: 'complete a sale: `one trade hire` (as a buyer) or accept + settle an offer (as the seller).',
|
|
50
|
+
adopted: 'get adopted by another workspace — accept an invite, or have your capability hired long-term.',
|
|
51
|
+
};
|
|
52
|
+
const STAGE_ORDER = ['registered', 'bootstrapped', 'active', 'settled', 'adopted'];
|
|
53
|
+
function out(cmd, data) {
|
|
54
|
+
const isJson = cmd.parent?.opts().json;
|
|
55
|
+
if (isJson) {
|
|
56
|
+
process.stdout.write(JSON.stringify(data) + '\n');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (data.ok === false) {
|
|
60
|
+
process.stderr.write(`✗ ${data.error ?? 'failed'}\n`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const stages = data.stages ?? [];
|
|
64
|
+
process.stdout.write(`✓ onboarded as ${data.uid ?? '?'}\n`);
|
|
65
|
+
process.stdout.write(` workspace: ${data.workspace ?? '?'}\n`);
|
|
66
|
+
process.stdout.write(` url: ${data.url ?? '?'}\n\n`);
|
|
67
|
+
process.stdout.write(' lifecycle: register → bootstrap → active → settled → adopted\n');
|
|
68
|
+
for (const s of stages) {
|
|
69
|
+
process.stdout.write(` ${s.done ? '✓' : '·'} ${s.id.padEnd(12)} ${s.guide}\n`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function onboardCmd() {
|
|
73
|
+
const cmd = new Command('onboard')
|
|
74
|
+
.description('Zero-to-live onboarding + a deterministic guide through the agent lifecycle')
|
|
75
|
+
.option('--name <name>', 'Workspace / agent display name')
|
|
76
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
77
|
+
.option('--write-env', 'Also write ONE_API_KEY to .env.local in the current directory', true)
|
|
78
|
+
.action(async (opts) => {
|
|
79
|
+
const dir = process.cwd();
|
|
80
|
+
const base = opts.api.replace(/\/$/, '');
|
|
81
|
+
const env = mergeEnv(dir);
|
|
82
|
+
let apiKey = env.ONE_API_KEY ?? env.ONEIE_API_KEY ?? '';
|
|
83
|
+
// regKey is the uid-bound registration key — distinct from apiKey (the
|
|
84
|
+
// workspace-scoped key `apiKey` resolves to). lifecycle:mine and any
|
|
85
|
+
// other uid-scoped receiver need THIS key: ctx.ownerSlug from `apiKey`
|
|
86
|
+
// resolves to the workspace's aid, which has zero stage_transition rows.
|
|
87
|
+
let regKey = env.ONE_REG_KEY ?? '';
|
|
88
|
+
let uid = env.ONE_UID ?? '';
|
|
89
|
+
let workspace = env.AGENCY_WSID ?? env.AGENCY_SLUG ?? '';
|
|
90
|
+
if (!apiKey) {
|
|
91
|
+
// Register + bootstrap in one call — the same zero-to-live path `one
|
|
92
|
+
// init` uses, POST /api/provision/agent. Both stages are tracked
|
|
93
|
+
// server-side the moment this call lands; nothing extra to do here.
|
|
94
|
+
const res = await fetch(`${base}/api/provision/agent`, {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
headers: { 'Content-Type': 'application/json' },
|
|
97
|
+
body: JSON.stringify({ name: opts.name ?? 'My Agent', live: true }),
|
|
98
|
+
});
|
|
99
|
+
const json = (await res.json().catch(() => ({})));
|
|
100
|
+
if (!res.ok || !json.apiKey) {
|
|
101
|
+
out(cmd, { ok: false, error: json.error ?? `provision failed (${res.status})` });
|
|
102
|
+
process.exitCode = 1;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
uid = String(json.uid);
|
|
106
|
+
workspace = String(json.workspace);
|
|
107
|
+
apiKey = json.apiKey;
|
|
108
|
+
regKey = json.regKey ?? '';
|
|
109
|
+
writeKey(apiKey);
|
|
110
|
+
if (opts.writeEnv) {
|
|
111
|
+
writeEnvLocal(dir, { ONE_API_KEY: apiKey, ONE_API_URL: base, ONE_REG_KEY: regKey, ONE_UID: uid, AGENCY_WSID: workspace });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Read back the real stage_transition log — the deterministic proof,
|
|
115
|
+
// not an assertion this command makes up. lifecycle:mine is self-scoped
|
|
116
|
+
// (entity_id = the caller's own uid, attested by the bearer key) —
|
|
117
|
+
// MUST be called with regKey, not apiKey (see note above).
|
|
118
|
+
const reached = new Set();
|
|
119
|
+
if (regKey) {
|
|
120
|
+
try {
|
|
121
|
+
const mine = await ask(base, regKey, 'lifecycle:mine', {});
|
|
122
|
+
const rows = (mine.result?.rows) ?? [];
|
|
123
|
+
for (const r of rows)
|
|
124
|
+
reached.add(r.to_stage);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// lifecycle:mine itself failing (e.g. no DB in a local dev target)
|
|
128
|
+
// must never block reporting what we already know from provisioning.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (uid) {
|
|
132
|
+
reached.add('registered');
|
|
133
|
+
reached.add('bootstrapped');
|
|
134
|
+
}
|
|
135
|
+
const stages = STAGE_ORDER.map((id) => ({ id, done: reached.has(id), guide: STAGE_GUIDE[id] }));
|
|
136
|
+
out(cmd, {
|
|
137
|
+
ok: true,
|
|
138
|
+
uid: uid || '(unknown — no ONE_UID in env; re-run in a fresh dir to see it)',
|
|
139
|
+
workspace,
|
|
140
|
+
url: workspace ? `${base}/u/${workspace}` : base,
|
|
141
|
+
key: `${KEY_FILE} (0600)`,
|
|
142
|
+
stages,
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
return cmd;
|
|
146
|
+
}
|
package/dist/src/render.d.ts
CHANGED
package/dist/src/render.js
CHANGED
|
@@ -12,7 +12,7 @@ export function renderStatus(agency, clients) {
|
|
|
12
12
|
const totalBurned = clients.reduce((s, c) => s + c.burned, 0);
|
|
13
13
|
const totalMargin = clients.reduce((s, c) => s + c.margin, 0);
|
|
14
14
|
const out = [];
|
|
15
|
-
out.push(`Agency: ${agency.name ?? agency.slug} (${agency.slug}) plan
|
|
15
|
+
out.push(`Agency: ${agency.name ?? agency.slug} (${agency.slug}) plan=${agency.plan} markup=${agency.markup_pct}% pool=${fmt(agency.pool)} cr`);
|
|
16
16
|
out.push('');
|
|
17
17
|
out.push(pad(header, widths));
|
|
18
18
|
for (const r of rows)
|
package/dist/src/setup.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Command } from 'commander';
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { mergeEnv, writeEnvLocal } from './env.js';
|
|
4
4
|
import { readAgency } from './config.js';
|
|
5
|
-
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://
|
|
5
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://one.ie';
|
|
6
6
|
async function ask(base, key, receiver, data) {
|
|
7
7
|
const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
|
|
8
8
|
method: 'POST',
|
|
@@ -13,7 +13,15 @@ async function ask(base, key, receiver, data) {
|
|
|
13
13
|
const body = await res.text().catch(() => '');
|
|
14
14
|
throw new Error(`${receiver} → ${res.status}\n${body}`);
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
const json = await res.json();
|
|
17
|
+
if (json.outcome === 'failure') {
|
|
18
|
+
const result = (json.result ?? {});
|
|
19
|
+
const details = Object.entries(result)
|
|
20
|
+
.map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
|
|
21
|
+
.join(' ');
|
|
22
|
+
throw new Error(`${receiver} → forbidden: ${details}`);
|
|
23
|
+
}
|
|
24
|
+
return json;
|
|
17
25
|
}
|
|
18
26
|
export function setupCmd() {
|
|
19
27
|
return new Command('setup')
|
package/dist/src/status.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { mergeEnv } from './env.js';
|
|
3
3
|
import { renderStatus } from './render.js';
|
|
4
|
-
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://
|
|
4
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://one.ie';
|
|
5
5
|
export function statusCmd() {
|
|
6
6
|
return new Command('status')
|
|
7
7
|
.description('Agency P&L dashboard (pool, margin, per-client burns)')
|
|
@@ -26,13 +26,21 @@ export function statusCmd() {
|
|
|
26
26
|
process.stderr.write(`billing:clients → ${res.status}\n`);
|
|
27
27
|
process.exit(1);
|
|
28
28
|
}
|
|
29
|
-
const
|
|
29
|
+
const json = await res.json();
|
|
30
|
+
if (json.outcome === 'failure') {
|
|
31
|
+
const result = (json.result ?? {});
|
|
32
|
+
const details = Object.entries(result)
|
|
33
|
+
.map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
|
|
34
|
+
.join(' ');
|
|
35
|
+
process.stderr.write(`billing:clients → forbidden: ${details}\n`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
30
38
|
if (opts.json) {
|
|
31
|
-
process.stdout.write(JSON.stringify(
|
|
39
|
+
process.stdout.write(JSON.stringify(json, null, 2) + '\n');
|
|
32
40
|
return;
|
|
33
41
|
}
|
|
34
|
-
const agency = (
|
|
35
|
-
const clients = (
|
|
42
|
+
const agency = (json.agency ?? { slug: env.AGENCY_SLUG, name: env.AGENCY_NAME ?? null, markup_pct: 0, pool: 0, plan: 'free' });
|
|
43
|
+
const clients = (json.clients ?? []);
|
|
36
44
|
process.stdout.write(renderStatus(agency, clients) + '\n');
|
|
37
45
|
});
|
|
38
46
|
}
|
package/dist/src/trade.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { askPath } from './lib/api-path.js';
|
|
1
2
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
2
3
|
function apiKey() {
|
|
3
4
|
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
@@ -13,7 +14,7 @@ function authHeaders() {
|
|
|
13
14
|
return h;
|
|
14
15
|
}
|
|
15
16
|
async function ask(b, receiver, data) {
|
|
16
|
-
const res = await fetch(
|
|
17
|
+
const res = await fetch(askPath(b, receiver), {
|
|
17
18
|
method: 'POST',
|
|
18
19
|
headers: authHeaders(),
|
|
19
20
|
body: JSON.stringify({ data }),
|
package/dist/src/wallet.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
|
|
2
|
+
import { askPath } from './lib/api-path.js';
|
|
3
|
+
export { askPath };
|
|
3
4
|
export declare function faucetOk(results: Array<{
|
|
4
5
|
success: boolean;
|
|
5
6
|
}>): boolean;
|
|
6
7
|
export declare function okWrap(result: Record<string, unknown>): Record<string, unknown>;
|
|
7
8
|
export declare function walletCmd(): Command;
|
|
9
|
+
export declare function writeKeysFile(filePath: string, contents: string, accepted: boolean): void;
|
package/dist/src/wallet.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { mergeEnv } from './env.js';
|
|
3
|
+
import { writeFileSync, chmodSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { generateWallet, recoverWallet } from '@oneie/sdk/wallet';
|
|
5
|
+
import { askPath } from './lib/api-path.js';
|
|
3
6
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
// matches whichever host --api actually points at, rather than hardcoding one.
|
|
9
|
-
export function askPath(base, receiver) {
|
|
10
|
-
const isGateway = new URL(base).hostname === 'api.one.ie';
|
|
11
|
-
return `${base}${isGateway ? '/ask' : '/api/ask'}/${encodeURIComponent(receiver)}`;
|
|
12
|
-
}
|
|
7
|
+
// Re-exported for existing callers/tests — canonical implementation now lives
|
|
8
|
+
// in ./lib/api-path.ts so trade.ts/client.ts/coordinate.ts/catalog.ts can share
|
|
9
|
+
// it instead of each hardcoding /api/ask/<receiver> against DEFAULT_API.
|
|
10
|
+
export { askPath };
|
|
13
11
|
// The ask envelope nests the resolver's return under `result`, not at the top
|
|
14
12
|
// level: { outcome:'result'|'timeout'|'dissolved'|'failure', result, signalId,
|
|
15
13
|
// receiver }. Unwrap it here so callers work with the plain wallet:* shape.
|
|
@@ -149,8 +147,49 @@ export function walletCmd() {
|
|
|
149
147
|
});
|
|
150
148
|
out(cmd, okWrap(result));
|
|
151
149
|
});
|
|
150
|
+
cmd.command('keygen')
|
|
151
|
+
.description('Generate or recover a self-hosted wallet locally — 4 chains (Sui/EVM/Sol/BTC), fully offline, never touches the network or a server. Prints once by default; use --out for scripted bulk provisioning')
|
|
152
|
+
.option('--recover', 'Recover from a 24-word BIP-39 mnemonic (ONE_WALLET_MNEMONIC env or stdin) instead of generating a fresh one')
|
|
153
|
+
.option('--out <file>', 'Write the mnemonic + keys to a file at mode 0600 instead of printing once')
|
|
154
|
+
.option('--yes-i-accept-plaintext-file', 'Required with --out — acknowledge that unencrypted key material will be written to disk')
|
|
155
|
+
.action(async (opts) => {
|
|
156
|
+
const wallet = opts.recover ? await recoverWallet(readMnemonic()) : await generateWallet();
|
|
157
|
+
const addresses = Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address]));
|
|
158
|
+
if (opts.out) {
|
|
159
|
+
const contents = JSON.stringify({ mnemonic: wallet.mnemonic, keys: wallet.keys }, null, 2) + '\n';
|
|
160
|
+
writeKeysFile(opts.out, contents, Boolean(opts.yesIAcceptPlaintextFile));
|
|
161
|
+
out(cmd, { ok: true, out: opts.out, chains: wallet.keys.map((k) => k.chain), addresses });
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
out(cmd, { ok: true, mnemonic: wallet.mnemonic, addresses, keys: wallet.keys });
|
|
165
|
+
}
|
|
166
|
+
});
|
|
152
167
|
return cmd;
|
|
153
168
|
}
|
|
169
|
+
// Read the recovery mnemonic for `keygen --recover`: ONE_WALLET_MNEMONIC env first
|
|
170
|
+
// (scriptable), else stdin (fd 0). Never a CLI arg — keeps the phrase out of the
|
|
171
|
+
// process table / shell history.
|
|
172
|
+
function readMnemonic() {
|
|
173
|
+
const fromEnv = process.env.ONE_WALLET_MNEMONIC?.trim();
|
|
174
|
+
if (fromEnv)
|
|
175
|
+
return fromEnv;
|
|
176
|
+
try {
|
|
177
|
+
return readFileSync(0, 'utf8').trim();
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
throw new Error('--recover needs a mnemonic — set ONE_WALLET_MNEMONIC or pipe the phrase on stdin');
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// Write key material to a plaintext file at mode 0600, and ONLY when the operator
|
|
184
|
+
// explicitly accepted the risk. chmod after write in case umask stripped bits at
|
|
185
|
+
// create time. Exported for the demo gate.
|
|
186
|
+
export function writeKeysFile(filePath, contents, accepted) {
|
|
187
|
+
if (!accepted) {
|
|
188
|
+
throw new Error('refusing to write plaintext key material to disk — pass --yes-i-accept-plaintext-file to override');
|
|
189
|
+
}
|
|
190
|
+
writeFileSync(filePath, contents, { mode: 0o600 });
|
|
191
|
+
chmodSync(filePath, 0o600);
|
|
192
|
+
}
|
|
154
193
|
function out(cmd, data) {
|
|
155
194
|
const isJson = cmd.parent?.opts().json;
|
|
156
195
|
if (isJson) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "ONE agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"commander": "^12.0.0",
|
|
23
|
-
"@oneie/sdk": "
|
|
23
|
+
"@oneie/sdk": "0.14.5"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@oneie/evals": "
|
|
26
|
+
"@oneie/evals": "0.1.0",
|
|
27
27
|
"@types/node": "^25.6.0",
|
|
28
28
|
"tsx": "^4.0.0",
|
|
29
29
|
"typescript": "^5.4.0",
|