@oneie/cli 5.5.1 → 5.5.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "5.5.1",
3
+ "version": "5.5.2",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,77 @@
1
+ /**
2
+ * key-sweep.ts — `one key sweep-rule | sweep | sweep-run`, the terminal halves of
3
+ * text/key.md deliverable 8 under Tony's ruling (2026-10-06): "the sweep is
4
+ * signed by the human who owns the agent; agents can be claimed by any owner."
5
+ *
6
+ * sweep-rule OWNER. Proves the owner's address (a signature over a fresh
7
+ * wallet:challenge) and sets the agent's threshold + float.
8
+ * sweep OWNER. Reads what is due, signs an ORDER with the owner's
9
+ * address key, and submits it to wallet:sweep, which records it.
10
+ * sweep-run AGENT. Reads its open orders, re-verifies each locally, performs
11
+ * the transfer with the agent's own key and settles it
12
+ * (@oneie/sdk/sweep-runner). Sui only; other chains are refused by
13
+ * name, because no signer for them exists here.
14
+ *
15
+ * KEYS come from the folder's sealed vault (`.one/wallet.json`) through
16
+ * wallet.ts `unlock` — Keychain or a passphrase typed at a terminal, never argv,
17
+ * env or a pipe. Nothing here prints, logs or sends a private key or the words:
18
+ * only addresses, signatures and the public order cross the wire, and every
19
+ * receipt is built field by field.
20
+ *
21
+ * THE NEW SDK MODULES LOAD LAZILY. key.ts registers these commands, so a static
22
+ * import of `@oneie/sdk/sweep-runner` would make every `one key` verb — `key new`
23
+ * included — crash on an installed SDK that predates that export. Only the three
24
+ * sweep actions reach for it, at the moment they run.
25
+ */
26
+ import { Command } from 'commander';
27
+ import type { SweepOrderChain } from '@oneie/sdk/sweep-order';
28
+ import type { SweepAsk, SweepTransfer } from '@oneie/sdk/sweep-runner';
29
+ /** The order lives 10 minutes: inside the server's 15-minute cap, with room for the agent's 2-minute floor. */
30
+ export declare const ORDER_LIFETIME_MS: number;
31
+ type VaultKey = {
32
+ chain: string;
33
+ address: string;
34
+ privateKeyHex: string;
35
+ };
36
+ export interface SweepDeps {
37
+ ask: SweepAsk;
38
+ /** The folder's vault, opened for this one act. */
39
+ unlock: () => Promise<{
40
+ keys: VaultKey[];
41
+ } | {
42
+ error: string;
43
+ }>;
44
+ /** The agent's balance in base units, read from the chain; null = could not read. */
45
+ readBalance?: (address: string) => Promise<string | null>;
46
+ now?: () => number;
47
+ }
48
+ /** One receiver call through the ask door; answers the receiver's own result. */
49
+ export declare function askVia(base: string, fetchImpl?: typeof fetch): SweepAsk;
50
+ /** Sui balance in mist via suix_getBalance — `totalBalance` is already base units. */
51
+ export declare function suiBalanceReader(rpcUrl: string, fetchImpl?: typeof fetch): (address: string) => Promise<string | null>;
52
+ export declare function ownerSweepRule(args: {
53
+ agent: string;
54
+ workspace: string;
55
+ chain: SweepOrderChain;
56
+ threshold: string;
57
+ float: string;
58
+ }, deps: SweepDeps): Promise<Record<string, unknown>>;
59
+ export declare function ownerSweep(args: {
60
+ agent: string;
61
+ workspace: string;
62
+ chain: SweepOrderChain;
63
+ amount?: string;
64
+ balance?: string;
65
+ }, deps: SweepDeps): Promise<Record<string, unknown>>;
66
+ export declare function agentSweepRun(args: {
67
+ agent: string;
68
+ workspace: string;
69
+ chain: SweepOrderChain;
70
+ rpc?: string;
71
+ network?: 'mainnet' | 'testnet';
72
+ ownerAddress?: string;
73
+ }, deps: SweepDeps & {
74
+ transfer?: Partial<Record<SweepOrderChain, SweepTransfer>>;
75
+ }): Promise<Record<string, unknown>>;
76
+ export declare function keySweepCommands(): Command[];
77
+ export {};
@@ -0,0 +1,220 @@
1
+ /**
2
+ * key-sweep.ts — `one key sweep-rule | sweep | sweep-run`, the terminal halves of
3
+ * text/key.md deliverable 8 under Tony's ruling (2026-10-06): "the sweep is
4
+ * signed by the human who owns the agent; agents can be claimed by any owner."
5
+ *
6
+ * sweep-rule OWNER. Proves the owner's address (a signature over a fresh
7
+ * wallet:challenge) and sets the agent's threshold + float.
8
+ * sweep OWNER. Reads what is due, signs an ORDER with the owner's
9
+ * address key, and submits it to wallet:sweep, which records it.
10
+ * sweep-run AGENT. Reads its open orders, re-verifies each locally, performs
11
+ * the transfer with the agent's own key and settles it
12
+ * (@oneie/sdk/sweep-runner). Sui only; other chains are refused by
13
+ * name, because no signer for them exists here.
14
+ *
15
+ * KEYS come from the folder's sealed vault (`.one/wallet.json`) through
16
+ * wallet.ts `unlock` — Keychain or a passphrase typed at a terminal, never argv,
17
+ * env or a pipe. Nothing here prints, logs or sends a private key or the words:
18
+ * only addresses, signatures and the public order cross the wire, and every
19
+ * receipt is built field by field.
20
+ *
21
+ * THE NEW SDK MODULES LOAD LAZILY. key.ts registers these commands, so a static
22
+ * import of `@oneie/sdk/sweep-runner` would make every `one key` verb — `key new`
23
+ * included — crash on an installed SDK that predates that export. Only the three
24
+ * sweep actions reach for it, at the moment they run.
25
+ */
26
+ import { Command } from 'commander';
27
+ import { addressProofMessage, signAddressProof } from '@oneie/sdk/address-proof';
28
+ import { authHeaders, out, resolveBase } from './lib/client.js';
29
+ import { askPath } from './lib/api-path.js';
30
+ import { unlock } from './wallet.js';
31
+ /** The vault's chain spelling for each sweep chain. */
32
+ const VAULT_CHAIN = { sui: 'sui', evm: 'evm', solana: 'sol', btc: 'btc' };
33
+ const isSweepChain = (c) => Object.prototype.hasOwnProperty.call(VAULT_CHAIN, c);
34
+ const digits = (v) => typeof v === 'string' && /^\d+$/.test(v);
35
+ /** The order lives 10 minutes: inside the server's 15-minute cap, with room for the agent's 2-minute floor. */
36
+ export const ORDER_LIFETIME_MS = 10 * 60 * 1000;
37
+ const runnerModule = () => import('@oneie/sdk/sweep-runner');
38
+ /** One receiver call through the ask door; answers the receiver's own result. */
39
+ export function askVia(base, fetchImpl = fetch) {
40
+ return async (receiver, data) => {
41
+ try {
42
+ const res = await fetchImpl(askPath(base.replace(/\/$/, ''), receiver), {
43
+ method: 'POST', headers: authHeaders(), body: JSON.stringify({ data }),
44
+ });
45
+ const body = (await res.json().catch(() => ({})));
46
+ if (body.outcome !== 'result')
47
+ return { ok: false, error: String(body.error ?? body.outcome ?? `HTTP ${res.status}`) };
48
+ return body.result ?? { ok: false, error: 'no result' };
49
+ }
50
+ catch (e) {
51
+ return { ok: false, error: e instanceof Error ? e.message : String(e) };
52
+ }
53
+ };
54
+ }
55
+ /** Sui balance in mist via suix_getBalance — `totalBalance` is already base units. */
56
+ export function suiBalanceReader(rpcUrl, fetchImpl = fetch) {
57
+ return async (address) => {
58
+ try {
59
+ const res = await fetchImpl(rpcUrl, {
60
+ method: 'POST', headers: { 'Content-Type': 'application/json' },
61
+ body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'suix_getBalance', params: [address, '0x2::sui::SUI'] }),
62
+ });
63
+ const json = (await res.json());
64
+ const v = json.result?.totalBalance;
65
+ return digits(v) ? v : null;
66
+ }
67
+ catch {
68
+ return null;
69
+ }
70
+ };
71
+ }
72
+ function keyFor(keys, chain, address) {
73
+ const want = VAULT_CHAIN[chain];
74
+ const k = keys.find((x) => x.chain === want && (address === undefined || x.address.toLowerCase() === address.toLowerCase()));
75
+ return k ?? null;
76
+ }
77
+ // ── owner: prove the address, set the rule ─────────────────────────────────
78
+ export async function ownerSweepRule(args, deps) {
79
+ if (!digits(args.threshold) || !digits(args.float))
80
+ return { ok: false, error: 'threshold and float are integer base units' };
81
+ const opened = await deps.unlock();
82
+ if ('error' in opened)
83
+ return { ok: false, error: opened.error };
84
+ const key = keyFor(opened.keys, args.chain);
85
+ if (!key)
86
+ return { ok: false, error: `the vault holds no ${args.chain} key` };
87
+ // workspace = actor = the caller: the challenge binds to the owner itself.
88
+ const ch = await deps.ask('wallet:challenge', {});
89
+ if (ch['ok'] !== true || typeof ch['challenge'] !== 'string')
90
+ return { ok: false, error: `wallet:challenge — ${String(ch['error'] ?? 'no challenge')}` };
91
+ const message = addressProofMessage({
92
+ challenge: ch['challenge'], workspace: String(ch['workspace']), actor: String(ch['actor']), chain: args.chain, address: key.address,
93
+ });
94
+ const proof = signAddressProof(args.chain, key.privateKeyHex, message);
95
+ const res = await deps.ask('wallet:sweep-set', {
96
+ workspace: args.workspace, actor: args.agent, chain: args.chain,
97
+ threshold: args.threshold, float: args.float, address: key.address, challenge: ch['challenge'], proof,
98
+ });
99
+ if (res['ok'] !== true)
100
+ return { ok: false, error: String(res['error'] ?? 'wallet:sweep-set refused') };
101
+ return { ok: true, agent: args.agent, chain: args.chain, owner: res['owner'], ownerAddress: res['ownerAddress'], thresholdUnits: res['thresholdUnits'], floatUnits: res['floatUnits'] };
102
+ }
103
+ // ── owner: sign and submit an order ────────────────────────────────────────
104
+ export async function ownerSweep(args, deps) {
105
+ const now = deps.now ?? (() => Date.now());
106
+ const base = { workspace: args.workspace, actor: args.agent, chain: args.chain };
107
+ const pending = await deps.ask('wallet:sweep', { ...base, pending: true });
108
+ if (pending['ok'] !== true)
109
+ return { ok: false, error: String(pending['error'] ?? 'wallet:sweep refused') };
110
+ const to = String(pending['to'] ?? '');
111
+ const agentAddress = String(pending['agentAddress'] ?? '');
112
+ let balance = args.balance;
113
+ if (balance === undefined) {
114
+ if (!deps.readBalance)
115
+ return { ok: false, error: 'pass --balance <base units>, or --rpc <url> to read it (sui only)' };
116
+ const read = await deps.readBalance(agentAddress);
117
+ if (read === null)
118
+ return { ok: false, error: 'could not read the agent balance — pass --balance' };
119
+ balance = read;
120
+ }
121
+ if (!digits(balance))
122
+ return { ok: false, error: '--balance is integer base units' };
123
+ const due = await deps.ask('wallet:sweep', { ...base, balance });
124
+ if (due['ok'] !== true)
125
+ return { ok: false, error: String(due['error'] ?? 'wallet:sweep refused') };
126
+ if (due['due'] !== true)
127
+ return { ok: true, due: false, balanceUnits: balance, thresholdUnits: due['thresholdUnits'], note: 'nothing to sweep — the balance is at or below the threshold' };
128
+ const max = BigInt(String(due['maxUnits']));
129
+ if (args.amount !== undefined && !digits(args.amount))
130
+ return { ok: false, error: '--amount is integer base units' };
131
+ const amount = args.amount !== undefined ? BigInt(args.amount) : max;
132
+ if (amount <= 0n || amount > max)
133
+ return { ok: false, error: `--amount must be in (0, ${max}] — balance minus float` };
134
+ const opened = await deps.unlock();
135
+ if ('error' in opened)
136
+ return { ok: false, error: opened.error };
137
+ const key = keyFor(opened.keys, args.chain, to);
138
+ if (!key)
139
+ return { ok: false, error: 'this vault does not hold the address you proved for sweeps — open the vault that does, or re-prove with `key sweep-rule`' };
140
+ const { newOrderNonce, signSweepOrder } = await runnerModule();
141
+ const { ORDER_MAX_TTL_MS } = await import('@oneie/sdk/sweep-order');
142
+ if (ORDER_LIFETIME_MS > ORDER_MAX_TTL_MS)
143
+ return { ok: false, error: 'order lifetime exceeds the server cap' };
144
+ const order = { ...base, destination: to, amount, nonce: newOrderNonce(), expiresAt: now() + ORDER_LIFETIME_MS };
145
+ const signature = signSweepOrder(key.privateKeyHex, order);
146
+ const res = await deps.ask('wallet:sweep', {
147
+ ...base, balance,
148
+ order: { destination: order.destination, amount: order.amount.toString(), nonce: order.nonce, expiresAt: order.expiresAt },
149
+ signature,
150
+ });
151
+ if (res['verified'] !== true)
152
+ return { ok: false, error: String(res['error'] ?? 'order not verified') };
153
+ return { ok: true, verified: true, agent: args.agent, chain: args.chain, to, amountUnits: order.amount.toString(), nonce: order.nonce, expiresAt: order.expiresAt, next: 'the agent runtime performs it: one key sweep-run' };
154
+ }
155
+ // ── agent: perform and settle ──────────────────────────────────────────────
156
+ export async function agentSweepRun(args, deps) {
157
+ const { runSweepOrders, suiTransfer } = await runnerModule();
158
+ const opened = await deps.unlock();
159
+ if ('error' in opened)
160
+ return { ok: false, error: opened.error };
161
+ const key = keyFor(opened.keys, args.chain);
162
+ if (!key)
163
+ return { ok: false, error: `the vault holds no ${args.chain} key` };
164
+ let transfer = deps.transfer;
165
+ if (!transfer && args.chain === 'sui') {
166
+ if (!args.rpc || !args.network)
167
+ return { ok: false, error: 'pass --rpc <url> and --network mainnet|testnet' };
168
+ transfer = { sui: suiTransfer({ rpcUrl: args.rpc, network: args.network }) };
169
+ }
170
+ const res = await runSweepOrders({ workspace: args.workspace, actor: args.agent, chain: args.chain, agentKey: { address: key.address, privateKeyHex: key.privateKeyHex }, ownerAddress: args.ownerAddress }, { ask: deps.ask, transfer, now: deps.now });
171
+ return { ok: res.ok, ...(res.error ? { error: res.error } : {}), agent: args.agent, chain: args.chain, results: res.results };
172
+ }
173
+ function common(c) {
174
+ return c
175
+ .requiredOption('--agent <id>', "The agent's actor id")
176
+ .option('--workspace <slug>', "The workspace that holds the agent's wallet (default: the agent id)")
177
+ .option('--chain <chain>', 'sui | evm | solana | btc', 'sui')
178
+ .option('--dir <path>', 'The folder whose sealed vault (.one/wallet.json) holds the key', '.')
179
+ .option('--api <url>', 'API base URL (default https://one.ie)');
180
+ }
181
+ function depsFor(o) {
182
+ return { ask: askVia(resolveBase({ api: o.api }, 'https://one.ie')), unlock: () => unlock(o.dir) };
183
+ }
184
+ export function keySweepCommands() {
185
+ const rule = common(new Command('sweep-rule'))
186
+ .description("OWNER — prove your address and set an agent's sweep threshold + float (base units)")
187
+ .requiredOption('--threshold <units>', 'A sweep is due when the balance is above this')
188
+ .requiredOption('--float <units>', 'What the agent keeps after a sweep')
189
+ .action(async (o, c) => {
190
+ if (!isSweepChain(o.chain))
191
+ return out(c, { ok: false, error: '--chain must be sui, evm, solana or btc' });
192
+ out(c, await ownerSweepRule({ agent: o.agent, workspace: o.workspace ?? o.agent, chain: o.chain, threshold: o.threshold, float: o.float }, depsFor(o)));
193
+ });
194
+ const sweep = common(new Command('sweep'))
195
+ .description("OWNER — sign a sweep order for what is due and submit it; the agent's runtime performs it")
196
+ .option('--amount <units>', 'Base units to sweep (default: everything above the float)')
197
+ .option('--balance <units>', "The agent's balance in base units (else read via --rpc, sui only)")
198
+ .option('--rpc <url>', 'Sui RPC to read the balance from')
199
+ .action(async (o, c) => {
200
+ if (!isSweepChain(o.chain))
201
+ return out(c, { ok: false, error: '--chain must be sui, evm, solana or btc' });
202
+ const deps = depsFor(o);
203
+ if (o.rpc && o.chain === 'sui')
204
+ deps.readBalance = suiBalanceReader(o.rpc);
205
+ out(c, await ownerSweep({ agent: o.agent, workspace: o.workspace ?? o.agent, chain: o.chain, amount: o.amount, balance: o.balance }, deps));
206
+ });
207
+ const run = common(new Command('sweep-run'))
208
+ .description("AGENT — perform and settle the owner's open sweep orders with this agent's own key (sui)")
209
+ .option('--rpc <url>', 'Sui RPC to send the transfer through')
210
+ .option('--network <n>', 'mainnet | testnet')
211
+ .option('--owner-address <addr>', "Pin the owner's address; any other is refused")
212
+ .action(async (o, c) => {
213
+ if (!isSweepChain(o.chain))
214
+ return out(c, { ok: false, error: '--chain must be sui, evm, solana or btc' });
215
+ if (o.network !== undefined && o.network !== 'mainnet' && o.network !== 'testnet')
216
+ return out(c, { ok: false, error: '--network must be mainnet or testnet' });
217
+ out(c, await agentSweepRun({ agent: o.agent, workspace: o.workspace ?? o.agent, chain: o.chain, rpc: o.rpc, network: o.network, ownerAddress: o.ownerAddress }, depsFor(o)));
218
+ });
219
+ return [rule, sweep, run];
220
+ }
package/dist/src/key.js CHANGED
@@ -29,6 +29,7 @@ import { userIdPubFromPhrase } from '@oneie/sdk/key-identity';
29
29
  import { jsonMode, resolveBase, resolveKey } from './lib/client.js';
30
30
  import { promptSecret, writeKeysFile } from './wallet.js';
31
31
  import { wordsStdoutRefusal } from './lib/agent-env.js';
32
+ import { keySweepCommands } from './key-sweep.js';
32
33
  const REFUSE_ARGV_SECRET = 'A secret on the command line is refused on purpose: it is written to your shell history and is ' +
33
34
  'visible in `ps` to every user on this machine. Set ONE_WALLET_MNEMONIC or pipe the words on stdin.';
34
35
  const REFUSE_ARGV = 'Unrecognised argument. It is not repeated here on purpose — it may BE your recovery phrase. ' +
@@ -305,6 +306,10 @@ export function keyCmd() {
305
306
  if (verdict === 'mismatch')
306
307
  process.exitCode = 1;
307
308
  }));
309
+ // sweep-rule · sweep · sweep-run — the owner's and the agent's halves of the
310
+ // sweep (key-sweep.ts). Keys come from the folder's sealed vault, never argv.
311
+ for (const sub of keySweepCommands())
312
+ cmd.addCommand(sub);
308
313
  // `one key <token>`: commander would print "unknown command '<token>'" — and the
309
314
  // token may BE the first word of a phrase. Refuse it here without repeating it.
310
315
  cmd.argument('[refused...]').allowUnknownOption().action((rest, _opts, c) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "5.5.1",
3
+ "version": "5.5.2",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {