@oneie/cli 0.7.0 → 0.9.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 CHANGED
@@ -63,7 +63,21 @@ one login --key <key> # stored at ~/.config/oneie/key (0600)
63
63
  # or set ONEIE_API_KEY in the environment
64
64
  ```
65
65
 
66
- Workspace operations use a Bearer token `<slug>:<key>`. Override the API base per command with `--api` (default `https://one.ie`).
66
+ Workspace operations use a Bearer token `<slug>:<key>`. Override the API base per command with `--api` (default `https://api.one.ie`, the gateway).
67
+
68
+ ## Wallets
69
+
70
+ Every actor — human or agent — gets real, self-custodied multi-chain wallets. The CLI reads and writes the same `wallet:*` receivers `/w` uses:
71
+
72
+ ```bash
73
+ one wallet create --workspace <slug> --kind agent # provision a wallet row (idempotent)
74
+ one wallet get --workspace <slug> # credits, ceiling, live balances, delegated wallets
75
+ one wallet transactions --workspace <slug> --limit 50 # unified feed across every settlement rail
76
+ one wallet faucet <address> --chain sui # fund from testnet — sui/sol auto-fund, others return a manual URL
77
+ one wallet send <to> --chain SUI --amount 5 --payment-tx <hash> --workspace <slug>
78
+ ```
79
+
80
+ `send` never signs — sign and broadcast the transfer yourself first (`agent-wallet-client.ts` for an agent, `/w` for a human), then pass the resulting transaction hash. The private key never crosses this command. `faucet` talks to `pay.one.ie` directly (its own protocol, not the `/ask` gateway) and needs no credential — funding any address is public by design, funding ≠ ownership.
67
81
 
68
82
  ## Chat — fan in · fan out
69
83
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
package/dist/src/index.js CHANGED
@@ -15,6 +15,7 @@ import { substrateCommands } from './substrate.js';
15
15
  import { evalCmd } from './eval.js';
16
16
  import { setupCmd } from './setup.js';
17
17
  import { clientCmd } from './client.js';
18
+ import { walletCmd } from './wallet.js';
18
19
  import { pushCmd } from './push.js';
19
20
  import { deployCmd } from './deploy.js';
20
21
  import { statusCmd } from './status.js';
@@ -52,6 +53,7 @@ program.addCommand(staffCmd());
52
53
  program.addCommand(evalCmd());
53
54
  program.addCommand(setupCmd());
54
55
  program.addCommand(clientCmd());
56
+ program.addCommand(walletCmd());
55
57
  program.addCommand(pushCmd());
56
58
  program.addCommand(deployCmd());
57
59
  program.addCommand(statusCmd());
@@ -1,4 +1,6 @@
1
1
  import { Command } from 'commander';
2
+ import { mkdirSync } from 'node:fs';
3
+ import { spawnSync } from 'node:child_process';
2
4
  function out(cmd, data) {
3
5
  if (process.env.ONEIE_JSON) {
4
6
  process.stdout.write(JSON.stringify({ cmd, ...data }) + '\n');
@@ -19,6 +21,17 @@ function bearerHeaders(workspace) {
19
21
  const key = process.env.ONEIE_API_KEY;
20
22
  return key && workspace ? { Authorization: `Bearer ${workspace}:${key}` } : {};
21
23
  }
24
+ // npm pack wraps a package's contents under a "package/" root — strip-components=1 lands
25
+ // the real package.json + src/ directly at ./plugin-<name>/, same as a real npm install would.
26
+ function extractTarball(bytes, targetDir) {
27
+ mkdirSync(targetDir, { recursive: true });
28
+ const tar = spawnSync('tar', ['-xz', '--strip-components=1', '-C', targetDir], {
29
+ input: bytes,
30
+ stdio: ['pipe', 'inherit', 'inherit'],
31
+ });
32
+ if (tar.status !== 0)
33
+ throw new Error(`tar failed extracting to ${targetDir}`);
34
+ }
22
35
  export function pluginCmd() {
23
36
  const cmd = new Command('plugin').description('Manage ONE plugins');
24
37
  cmd
@@ -65,6 +78,21 @@ export function pluginCmd() {
65
78
  console.error(`Error: ${e instanceof Error ? e.message : e}`);
66
79
  process.exit(1);
67
80
  }
81
+ // Paid plugins (PAID_FEATURES) stream a real gzip tarball on 200; free plugins keep
82
+ // the JSON pointer to their public npm package. Discriminate before parsing the body.
83
+ if (res.ok && res.headers.get('content-type')?.startsWith('application/gzip')) {
84
+ const bytes = new Uint8Array(await res.arrayBuffer());
85
+ const targetDir = `./plugin-${name}`;
86
+ try {
87
+ extractTarball(bytes, targetDir);
88
+ }
89
+ catch (e) {
90
+ out('plugin:add', { ok: false, error: 'extract_failed', plugin: name, detail: e instanceof Error ? e.message : String(e) });
91
+ process.exit(1);
92
+ }
93
+ out('plugin:add', { ok: true, plugin: name, extracted: true, path: targetDir });
94
+ return;
95
+ }
68
96
  const body = (await res.json());
69
97
  if (res.status === 402) {
70
98
  out('plugin:add', {
@@ -0,0 +1,7 @@
1
+ import { Command } from 'commander';
2
+ export declare function askPath(base: string, receiver: string): string;
3
+ export declare function faucetOk(results: Array<{
4
+ success: boolean;
5
+ }>): boolean;
6
+ export declare function okWrap(result: Record<string, unknown>): Record<string, unknown>;
7
+ export declare function walletCmd(): Command;
@@ -0,0 +1,170 @@
1
+ import { Command } from 'commander';
2
+ import { mergeEnv } from './env.js';
3
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
4
+ // The api.one.ie GATEWAY serves substrate ops at the short form (/ask/<receiver>,
5
+ // mapped internally to one-prod's /api/ask/<receiver> — api/src/substrate-binding.ts
6
+ // PATH_MAP). Calling /api/ask/ directly against the gateway 404s (verified live
7
+ // 2026-07-03). one.ie/web itself only answers the long form. Pick the path that
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
+ }
13
+ // The ask envelope nests the resolver's return under `result`, not at the top
14
+ // level: { outcome:'result'|'timeout'|'dissolved'|'failure', result, signalId,
15
+ // receiver }. Unwrap it here so callers work with the plain wallet:* shape.
16
+ async function ask(base, key, receiver, data) {
17
+ const res = await fetch(askPath(base, receiver), {
18
+ method: 'POST',
19
+ headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
20
+ body: JSON.stringify({ data }),
21
+ });
22
+ if (!res.ok) {
23
+ const body = await res.text().catch(() => '');
24
+ throw new Error(`${receiver} → ${res.status}\n${body}`);
25
+ }
26
+ const envelope = (await res.json());
27
+ if (envelope.outcome && envelope.outcome !== 'result') {
28
+ throw new Error(`${receiver} → ${envelope.outcome}`);
29
+ }
30
+ return envelope.result ?? envelope;
31
+ }
32
+ const DEFAULT_PAY = process.env.ONEIE_PAY_URL ?? 'https://pay.one.ie';
33
+ // pay.one.ie is a separate service from the gateway/one.ie ask surface above —
34
+ // its own protocol envelope, POST <payUrl>/ { protocol, data } → { success, data,
35
+ // error? }. faucet_request is public (no credential), matching the threat model:
36
+ // funding ≠ ownership, anyone can fund any address (wallet-plan.md).
37
+ async function payProtocol(payUrl, protocol, data) {
38
+ const res = await fetch(`${payUrl.replace(/\/$/, '')}/`, {
39
+ method: 'POST',
40
+ headers: { 'Content-Type': 'application/json' },
41
+ body: JSON.stringify({ protocol, data }),
42
+ });
43
+ const body = (await res.json().catch(() => ({})));
44
+ if (!res.ok || !body.success) {
45
+ throw new Error(`${protocol} → ${body.error?.message ?? body.error?.code ?? res.status}`);
46
+ }
47
+ return body.data ?? {};
48
+ }
49
+ function resolveAuth(opts) {
50
+ const env = mergeEnv(process.cwd());
51
+ const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
52
+ return { base: opts.api.replace(/\/$/, ''), key };
53
+ }
54
+ function resolveWorkspace(explicit) {
55
+ const env = mergeEnv(process.cwd());
56
+ const workspace = explicit ?? env.AGENCY_SLUG;
57
+ if (!workspace) {
58
+ process.stderr.write('--workspace required (or set AGENCY_SLUG)\n');
59
+ process.exit(1);
60
+ }
61
+ return workspace;
62
+ }
63
+ // A chain with no auto-fund path (ETH/USDC/BTC) legitimately returns success:false
64
+ // with a manualUrls fallback — that's documented, expected behavior (wallet-plan.md:
65
+ // "SUI/SOL auto-fund; ETH/USDC/BTC return a manual URL"), never a call failure.
66
+ // `ok` here means "the request was answered" (payProtocol already throws on a real
67
+ // failure) — per-chain funded/manual status lives in `results`, read that, not `ok`.
68
+ export function faucetOk(results) {
69
+ return results.length > 0;
70
+ }
71
+ // wallet:get/create/transactions return bare data or { error } — no `ok` field
72
+ // of their own. wallet:send already returns { ok, ... }. Normalize both to the
73
+ // { ok, ... } shape out() expects without ever overwriting a real error/false
74
+ // with a hardcoded ok:true.
75
+ export function okWrap(result) {
76
+ if ('ok' in result)
77
+ return result;
78
+ if ('error' in result)
79
+ return { ok: false, ...result };
80
+ return { ok: true, ...result };
81
+ }
82
+ export function walletCmd() {
83
+ const cmd = new Command('wallet').description('Read balances, provision a wallet row, fund from testnet, send crypto — wallet:* receivers + pay.one.ie');
84
+ cmd.command('get')
85
+ .description('Credits, spend ceiling, wallet rows, live chain balances, delegated wallets')
86
+ .option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
87
+ .option('--actor <id>', 'Actor within the workspace (defaults to workspace)')
88
+ .option('--api <url>', 'API base URL', DEFAULT_API)
89
+ .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
90
+ .action(async (opts) => {
91
+ const { base, key } = resolveAuth(opts);
92
+ const workspace = resolveWorkspace(opts.workspace);
93
+ const result = await ask(base, key, 'wallet:get', { workspace, actor: opts.actor });
94
+ out(cmd, okWrap(result));
95
+ });
96
+ cmd.command('create')
97
+ .description('Provision a wallet row for an actor (idempotent)')
98
+ .option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
99
+ .option('--actor <id>', 'Actor to provision (defaults to workspace)')
100
+ .option('--kind <kind>', 'human | agent', 'human')
101
+ .option('--api <url>', 'API base URL', DEFAULT_API)
102
+ .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
103
+ .action(async (opts) => {
104
+ const { base, key } = resolveAuth(opts);
105
+ const workspace = resolveWorkspace(opts.workspace);
106
+ const result = await ask(base, key, 'wallet:create', { workspace, actor: opts.actor, kind: opts.kind });
107
+ out(cmd, okWrap(result));
108
+ });
109
+ cmd.command('transactions')
110
+ .description('Unified transaction feed across every settlement rail')
111
+ .option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
112
+ .option('--limit <n>', 'Max rows (default 100, max 500)', '100')
113
+ .option('--api <url>', 'API base URL', DEFAULT_API)
114
+ .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
115
+ .action(async (opts) => {
116
+ const { base, key } = resolveAuth(opts);
117
+ const workspace = resolveWorkspace(opts.workspace);
118
+ const result = await ask(base, key, 'wallet:transactions', { workspace, limit: Number(opts.limit) });
119
+ out(cmd, okWrap(result));
120
+ });
121
+ cmd.command('faucet <address>')
122
+ .description('Fund an address from a testnet tap — Sui and Solana auto-fund; ETH/USDC/BTC return a manual faucet URL')
123
+ .requiredOption('--chain <chain>', 'sui | sol | eth | usdc | btc | all')
124
+ .option('--network <network>', 'testnet | devnet (Sui only)')
125
+ .option('--pay-url <url>', 'pay.one.ie base URL', DEFAULT_PAY)
126
+ .action(async (address, opts) => {
127
+ const data = await payProtocol(opts.payUrl, 'faucet_request', { chain: opts.chain, address, network: opts.network });
128
+ const results = (data.results ?? []);
129
+ out(cmd, { ok: faucetOk(results), results, manualFaucets: data.manualFaucets });
130
+ });
131
+ cmd.command('send <to>')
132
+ .description('Send crypto via pay.one.ie payment links, incl. Bitcoin — sign the transfer yourself first, pass the tx hash')
133
+ .requiredOption('--chain <chain>', 'SUI | EVM | SOL | BTC | BASE | ARB | OPT')
134
+ .requiredOption('--amount <n>', 'Amount to send')
135
+ .requiredOption('--payment-tx <hash>', 'The transaction hash from signing & broadcasting client-side — this command never signs')
136
+ .option('--workspace <slug>', 'Source workspace (defaults to AGENCY_SLUG)')
137
+ .option('--unit <unit>', 'usd | token', 'usd')
138
+ .option('--currency <currency>', 'NATIVE | USDC', 'NATIVE')
139
+ .option('--user-address <address>', 'Sender address (defaults to --to)')
140
+ .option('--memo <text>', 'Payment memo')
141
+ .option('--api <url>', 'API base URL', DEFAULT_API)
142
+ .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
143
+ .action(async (to, opts) => {
144
+ const { base, key } = resolveAuth(opts);
145
+ const workspace = resolveWorkspace(opts.workspace);
146
+ const result = await ask(base, key, 'wallet:send', {
147
+ workspace, to, chain: opts.chain, amount: Number(opts.amount), paymentTx: opts.paymentTx,
148
+ unit: opts.unit, currency: opts.currency, userAddress: opts.userAddress, memo: opts.memo,
149
+ });
150
+ out(cmd, okWrap(result));
151
+ });
152
+ return cmd;
153
+ }
154
+ function out(cmd, data) {
155
+ const isJson = cmd.parent?.opts().json;
156
+ if (isJson) {
157
+ process.stdout.write(JSON.stringify(data) + '\n');
158
+ }
159
+ else if (data.ok) {
160
+ const pairs = Object.entries(data)
161
+ .filter(([k]) => k !== 'ok')
162
+ .map(([k, v]) => `${k}=${JSON.stringify(v)}`)
163
+ .join(' ');
164
+ console.log('✓', pairs);
165
+ }
166
+ else {
167
+ const detail = data.error ?? data.errors ?? data.issues ?? data;
168
+ console.error('✗', typeof detail === 'string' ? detail : JSON.stringify(detail));
169
+ }
170
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {