oneie 4.0.2 → 4.2.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 +78 -1
- package/dist/package.json +4 -4
- package/dist/src/agent.d.ts +73 -0
- package/dist/src/agent.js +486 -53
- package/dist/src/auth.js +3 -4
- package/dist/src/broadcast.d.ts +2 -0
- package/dist/src/broadcast.js +24 -0
- package/dist/src/compiler.js +27 -3
- package/dist/src/doctor.js +61 -6
- package/dist/src/eval.js +1 -0
- package/dist/src/fn.js +5 -8
- package/dist/src/index.js +8 -1
- package/dist/src/init.js +33 -3
- package/dist/src/lib/agent-env.js +7 -0
- package/dist/src/lib/client.js +16 -7
- package/dist/src/lib/keyfile.d.ts +130 -0
- package/dist/src/lib/keyfile.js +381 -0
- package/dist/src/lib/paths.d.ts +33 -0
- package/dist/src/lib/paths.js +77 -0
- package/dist/src/lib/tasks-digest.d.ts +66 -0
- package/dist/src/lib/tasks-digest.js +200 -0
- package/dist/src/lib/tasks-graph.d.ts +78 -0
- package/dist/src/lib/tasks-graph.js +425 -0
- package/dist/src/lib/vaultfile.d.ts +73 -0
- package/dist/src/lib/vaultfile.js +184 -0
- package/dist/src/media.d.ts +2 -0
- package/dist/src/media.js +256 -0
- package/dist/src/plugin.js +10 -1
- package/dist/src/skill.js +128 -12
- package/dist/src/tasks.d.ts +2 -0
- package/dist/src/tasks.js +424 -0
- package/dist/src/templates.js +8 -0
- package/dist/src/wallet.d.ts +9 -0
- package/dist/src/wallet.js +259 -1
- package/dist/src/workflow.d.ts +2 -0
- package/dist/src/workflow.js +144 -0
- package/package.json +4 -4
package/dist/src/templates.js
CHANGED
|
@@ -2,6 +2,7 @@ export const TEMPLATES = {
|
|
|
2
2
|
core: `---
|
|
3
3
|
agentmd: "0.1"
|
|
4
4
|
name: template
|
|
5
|
+
kind: agent
|
|
5
6
|
title: Template Agent
|
|
6
7
|
model: anthropic/claude-haiku-4-5
|
|
7
8
|
summary: A helpful agent.
|
|
@@ -15,6 +16,7 @@ You are a helpful assistant. Complete tasks clearly and concisely.
|
|
|
15
16
|
commerce: `---
|
|
16
17
|
agentmd: "0.1"
|
|
17
18
|
name: template
|
|
19
|
+
kind: agent
|
|
18
20
|
title: Template Commerce Agent
|
|
19
21
|
model: anthropic/claude-haiku-4-5
|
|
20
22
|
summary: An agent that provides paid services.
|
|
@@ -35,6 +37,7 @@ You provide services at a fee. Verify payment before executing paid skills.
|
|
|
35
37
|
asi: `---
|
|
36
38
|
agentmd: "0.1"
|
|
37
39
|
name: template
|
|
40
|
+
kind: agent
|
|
38
41
|
title: Template ASI Agent
|
|
39
42
|
model: anthropic/claude-opus-4-7
|
|
40
43
|
summary: An autonomous agent registered on Fetch.ai Almanac.
|
|
@@ -54,6 +57,7 @@ You are an autonomous agent. Coordinate with peers, monitor signals, and act on
|
|
|
54
57
|
'travel-planner': `---
|
|
55
58
|
agentmd: "0.1"
|
|
56
59
|
name: template
|
|
60
|
+
kind: agent
|
|
57
61
|
title: Travel Planner
|
|
58
62
|
model: anthropic/claude-sonnet-4-5
|
|
59
63
|
summary: Creates detailed travel itineraries with real logistics and budgets.
|
|
@@ -81,6 +85,7 @@ Ask first: where, when, how long, who's going, budget range. Then deliver a day-
|
|
|
81
85
|
'marketing-strategist': `---
|
|
82
86
|
agentmd: "0.1"
|
|
83
87
|
name: template
|
|
88
|
+
kind: agent
|
|
84
89
|
title: Marketing Strategist
|
|
85
90
|
model: anthropic/claude-sonnet-4-5
|
|
86
91
|
summary: Audits channels, plans campaigns, writes copy, and reads metrics.
|
|
@@ -112,6 +117,7 @@ Start by understanding the product, the customer, and the current state of marke
|
|
|
112
117
|
'support-tier1': `---
|
|
113
118
|
agentmd: "0.1"
|
|
114
119
|
name: template
|
|
120
|
+
kind: agent
|
|
115
121
|
title: Support — Tier 1
|
|
116
122
|
model: anthropic/claude-sonnet-4-5
|
|
117
123
|
summary: Resolves common support issues fast; escalates edge cases with full context.
|
|
@@ -143,6 +149,7 @@ You are a Tier 1 support agent. Your job is to resolve common issues fast, escal
|
|
|
143
149
|
'sales-discovery': `---
|
|
144
150
|
agentmd: "0.1"
|
|
145
151
|
name: template
|
|
152
|
+
kind: agent
|
|
146
153
|
title: Sales Discovery
|
|
147
154
|
model: anthropic/claude-sonnet-4-5
|
|
148
155
|
summary: Qualifies leads, preps discovery calls, handles objections, and structures proposals.
|
|
@@ -174,6 +181,7 @@ Start with the lead context: industry, size, role, how they came in. Then run th
|
|
|
174
181
|
'code-reviewer': `---
|
|
175
182
|
agentmd: "0.1"
|
|
176
183
|
name: template
|
|
184
|
+
kind: agent
|
|
177
185
|
title: Code Reviewer
|
|
178
186
|
model: anthropic/claude-sonnet-4-5
|
|
179
187
|
summary: Gives concrete, severity-labelled code review findings with actionable fixes.
|
package/dist/src/wallet.d.ts
CHANGED
|
@@ -6,4 +6,13 @@ export declare function faucetOk(results: Array<{
|
|
|
6
6
|
}>): boolean;
|
|
7
7
|
export declare function okWrap(result: Record<string, unknown>): Record<string, unknown>;
|
|
8
8
|
export declare function walletCmd(): Command;
|
|
9
|
+
/**
|
|
10
|
+
* Reduce ANY keygen-shaped object to public receiving addresses. This is a
|
|
11
|
+
* whitelist build, never a spread or a delete-list: the returned object is
|
|
12
|
+
* constructed field-by-field from four known chain keys whose values must be
|
|
13
|
+
* strings, so a `privateKey`, `secretKey`, `mnemonic` or any other field on the
|
|
14
|
+
* input has no route into the value this command transmits. The custody
|
|
15
|
+
* invariant here is structural, not a policy the caller has to remember.
|
|
16
|
+
*/
|
|
17
|
+
export declare function addressesOnly(source: unknown): Record<string, string>;
|
|
9
18
|
export declare function writeKeysFile(filePath: string, contents: string, accepted: boolean): void;
|
package/dist/src/wallet.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { mergeEnv } from './env.js';
|
|
3
|
-
import { writeFileSync, chmodSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { writeFileSync, chmodSync, readFileSync, existsSync, rmSync } from 'node:fs';
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
4
5
|
import { generateWallet, recoverWallet } from '@oneie/sdk/wallet';
|
|
6
|
+
import { sealVault, openVault, mintKeychainSecret } from '@oneie/sdk/vault-file';
|
|
5
7
|
import { askPath } from './lib/api-path.js';
|
|
8
|
+
import { writeVaultFolder, readVaultFolder, vaultPath, paperSheet, keychainStore, keychainRead, keychainAvailable, } from './lib/vaultfile.js';
|
|
6
9
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
7
10
|
// Re-exported for existing callers/tests — canonical implementation now lives
|
|
8
11
|
// in ./lib/api-path.ts so trade.ts/client.ts/coordinate.ts/catalog.ts can share
|
|
@@ -147,6 +150,46 @@ export function walletCmd() {
|
|
|
147
150
|
});
|
|
148
151
|
out(cmd, okWrap(result));
|
|
149
152
|
});
|
|
153
|
+
cmd.command('register')
|
|
154
|
+
.description('Register a keygen output\'s PUBLIC receiving addresses with a workspace — reads addresses only, never a key or a mnemonic. First write wins per chain and is permanent')
|
|
155
|
+
.option('--from <file>', 'A `wallet keygen --out` file (or any JSON with `addresses` / `keys`) — only the address fields are read')
|
|
156
|
+
.option('--addresses <json>', 'Inline JSON address map, e.g. \'{"sui":"0x…","evm":"0x…"}\'')
|
|
157
|
+
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
158
|
+
.option('--actor <id>', 'Actor to register for (defaults to workspace)')
|
|
159
|
+
.option('--kind <kind>', 'human | agent', 'human')
|
|
160
|
+
.option('--yes', 'Skip the confirmation prompt (for scripted provisioning)')
|
|
161
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
162
|
+
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
163
|
+
.action(async (opts) => {
|
|
164
|
+
const { base, key } = resolveAuth(opts);
|
|
165
|
+
const workspace = resolveWorkspace(opts.workspace);
|
|
166
|
+
const source = opts.from
|
|
167
|
+
? JSON.parse(readFileSync(opts.from, 'utf8'))
|
|
168
|
+
: opts.addresses
|
|
169
|
+
? JSON.parse(opts.addresses)
|
|
170
|
+
: (() => { throw new Error('register needs --from <file> or --addresses <json>'); })();
|
|
171
|
+
const addresses = addressesOnly(source);
|
|
172
|
+
if (Object.keys(addresses).length === 0) {
|
|
173
|
+
throw new Error('no addresses found — expected an `addresses` map or a `keys` array of { chain, address }');
|
|
174
|
+
}
|
|
175
|
+
// mergeAddresses is FIRST-WRITE-WINS: a wrong address here is where every future
|
|
176
|
+
// payment lands, and the row refuses to change it afterwards (address_conflict).
|
|
177
|
+
// So the operator reads the exact strings back before anything is sent.
|
|
178
|
+
const actor = opts.actor ?? workspace;
|
|
179
|
+
process.stderr.write(`Registering PUBLIC receiving addresses for actor '${actor}' in workspace '${workspace}':\n`);
|
|
180
|
+
for (const [chain, addr] of Object.entries(addresses)) {
|
|
181
|
+
process.stderr.write(` ${chain.padEnd(7)} ${addr}\n`);
|
|
182
|
+
}
|
|
183
|
+
process.stderr.write('This is permanent — the first address written to a chain cannot be changed.\n');
|
|
184
|
+
if (!opts.yes && !(await confirm('Register these addresses? [y/N] '))) {
|
|
185
|
+
out(cmd, { ok: false, error: 'cancelled' });
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
// `actor`, not `opts.actor` — what the operator confirmed on screen is what gets
|
|
189
|
+
// written, rather than relying on the resolver's own default to agree.
|
|
190
|
+
const result = await ask(base, key, 'wallet:create', { workspace, actor, kind: opts.kind, addresses });
|
|
191
|
+
out(cmd, okWrap(result));
|
|
192
|
+
});
|
|
150
193
|
cmd.command('keygen')
|
|
151
194
|
.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
195
|
.option('--recover', 'Recover from a 24-word BIP-39 mnemonic (ONE_WALLET_MNEMONIC env or stdin) instead of generating a fresh one')
|
|
@@ -164,8 +207,173 @@ export function walletCmd() {
|
|
|
164
207
|
out(cmd, { ok: true, mnemonic: wallet.mnemonic, addresses, keys: wallet.keys });
|
|
165
208
|
}
|
|
166
209
|
});
|
|
210
|
+
// ── the encrypted wallet folder ────────────────────────────────────────────
|
|
211
|
+
cmd.command('new')
|
|
212
|
+
.description('Create an encrypted wallet in this folder — 24 words sealed with a passphrase, four chains, fully offline')
|
|
213
|
+
.option('--dir <path>', 'Project directory', '.')
|
|
214
|
+
.option('--recover', 'Seal an EXISTING 24-word phrase instead of generating a new one (ONE_WALLET_MNEMONIC or stdin)')
|
|
215
|
+
.option('--keychain', 'Seal with a random secret stored in Apple Keychain, so Touch ID opens it instead of a passphrase')
|
|
216
|
+
.action(async (opts) => {
|
|
217
|
+
// Refuse BEFORE generating. Minting a wallet and then failing to store it
|
|
218
|
+
// is the one outcome that loses money: the words would exist only in a
|
|
219
|
+
// process about to exit.
|
|
220
|
+
if (existsSync(vaultPath(opts.dir))) {
|
|
221
|
+
out(cmd, { ok: false, error: `a wallet already exists at ${vaultPath(opts.dir)} — move it aside first` });
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (opts.keychain && !keychainAvailable()) {
|
|
225
|
+
out(cmd, { ok: false, error: 'Keychain is macOS-only — omit --keychain to seal with a passphrase' });
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
let passphrase;
|
|
229
|
+
let wrap;
|
|
230
|
+
if (opts.keychain) {
|
|
231
|
+
passphrase = mintKeychainSecret();
|
|
232
|
+
wrap = 'keychain';
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
passphrase = await promptSecret('Passphrase for this wallet: ');
|
|
236
|
+
const again = await promptSecret('Repeat it: ');
|
|
237
|
+
if (passphrase !== again) {
|
|
238
|
+
out(cmd, { ok: false, error: 'passphrases did not match — nothing was written' });
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (passphrase.length < 8) {
|
|
242
|
+
out(cmd, { ok: false, error: 'passphrase too short — this is the only thing between a stolen laptop and the wallet' });
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
wrap = 'passphrase';
|
|
246
|
+
}
|
|
247
|
+
const wallet = opts.recover ? await recoverWallet(readMnemonic()) : await generateWallet();
|
|
248
|
+
const addresses = Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address]));
|
|
249
|
+
const authPub = wallet.keys.find((k) => k.chain === 'sui')?.publicKeyHex ?? '';
|
|
250
|
+
const blob = await sealVault(wallet.mnemonic, passphrase, { wrap, authPub });
|
|
251
|
+
const res = writeVaultFolder(opts.dir, { ...blob });
|
|
252
|
+
if (!res.ok) {
|
|
253
|
+
out(cmd, { ok: false, error: res.error });
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (opts.keychain) {
|
|
257
|
+
const k = keychainStore(authPub, passphrase);
|
|
258
|
+
if (!k.ok) {
|
|
259
|
+
// The vault is sealed with a secret nobody can now produce. Remove it
|
|
260
|
+
// rather than leaving an unopenable file that looks like a wallet.
|
|
261
|
+
rmSync(res.path, { force: true });
|
|
262
|
+
out(cmd, { ok: false, error: `Keychain write failed (${k.error}) — the wallet was removed rather than left unopenable` });
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
out(cmd, {
|
|
267
|
+
ok: true,
|
|
268
|
+
wallet: res.path,
|
|
269
|
+
wrap,
|
|
270
|
+
addresses,
|
|
271
|
+
next: 'one wallet paper # write the 24 words down — this is the ONLY backup',
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
cmd.command('open')
|
|
275
|
+
.description('Unlock the wallet in this folder and show its addresses — the phrase never leaves this machine')
|
|
276
|
+
.option('--dir <path>', 'Project directory', '.')
|
|
277
|
+
.action(async (opts) => {
|
|
278
|
+
const r = await unlock(opts.dir);
|
|
279
|
+
if ('error' in r) {
|
|
280
|
+
out(cmd, { ok: false, error: r.error });
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
out(cmd, { ok: true, wrap: r.blob.wrap, addresses: r.addresses });
|
|
284
|
+
});
|
|
285
|
+
cmd.command('paper')
|
|
286
|
+
.description('Print the recovery sheet — 24 numbered words plus the public addresses. Print it, then close the terminal')
|
|
287
|
+
.option('--dir <path>', 'Project directory', '.')
|
|
288
|
+
.action(async (opts) => {
|
|
289
|
+
const r = await unlock(opts.dir);
|
|
290
|
+
if ('error' in r) {
|
|
291
|
+
out(cmd, { ok: false, error: r.error });
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
// Straight to stdout, never through out(): a --json receipt carrying 24
|
|
295
|
+
// words would put the whole wallet into any pipeline or CI log that
|
|
296
|
+
// captured it.
|
|
297
|
+
process.stdout.write(paperSheet(r.mnemonic, r.addresses) + '\n');
|
|
298
|
+
});
|
|
299
|
+
cmd.command('keychain')
|
|
300
|
+
.description('Move this wallet behind Touch ID — stores its passphrase in Apple Keychain so biometrics open it')
|
|
301
|
+
.option('--dir <path>', 'Project directory', '.')
|
|
302
|
+
.action(async (opts) => {
|
|
303
|
+
if (!keychainAvailable()) {
|
|
304
|
+
out(cmd, { ok: false, error: 'Keychain is macOS-only' });
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const blob = readVaultFolder(opts.dir);
|
|
308
|
+
if (!blob) {
|
|
309
|
+
out(cmd, { ok: false, error: `no wallet at ${vaultPath(opts.dir)}` });
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (blob.wrap === 'keychain') {
|
|
313
|
+
out(cmd, { ok: true, note: 'already opened by Keychain' });
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const pass = await promptSecret('Current passphrase: ');
|
|
317
|
+
// Prove the passphrase before storing it — storing an unverified string
|
|
318
|
+
// would put a secret in Keychain that opens nothing.
|
|
319
|
+
try {
|
|
320
|
+
await openVault(blob, pass);
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
out(cmd, { ok: false, error: 'wrong passphrase — nothing was stored' });
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
const k = keychainStore(String(blob.authPub ?? ''), pass);
|
|
327
|
+
out(cmd, k.ok ? { ok: true, note: 'Touch ID now opens this wallet' } : { ok: false, error: k.error });
|
|
328
|
+
});
|
|
167
329
|
return cmd;
|
|
168
330
|
}
|
|
331
|
+
// Chain-name spellings a keygen output may use -> the four columns wallet:create
|
|
332
|
+
// declares. `eth`/`sol` are the SDK's WalletChain spellings; `evm`/`solana` are the
|
|
333
|
+
// server's.
|
|
334
|
+
const REGISTER_CHAINS = {
|
|
335
|
+
sui: 'sui', evm: 'evm', eth: 'evm', ethereum: 'evm',
|
|
336
|
+
sol: 'solana', solana: 'solana', btc: 'btc', bitcoin: 'btc',
|
|
337
|
+
};
|
|
338
|
+
/**
|
|
339
|
+
* Reduce ANY keygen-shaped object to public receiving addresses. This is a
|
|
340
|
+
* whitelist build, never a spread or a delete-list: the returned object is
|
|
341
|
+
* constructed field-by-field from four known chain keys whose values must be
|
|
342
|
+
* strings, so a `privateKey`, `secretKey`, `mnemonic` or any other field on the
|
|
343
|
+
* input has no route into the value this command transmits. The custody
|
|
344
|
+
* invariant here is structural, not a policy the caller has to remember.
|
|
345
|
+
*/
|
|
346
|
+
export function addressesOnly(source) {
|
|
347
|
+
const addresses = {};
|
|
348
|
+
const put = (rawChain, rawAddress) => {
|
|
349
|
+
const chain = REGISTER_CHAINS[String(rawChain).toLowerCase()];
|
|
350
|
+
if (!chain || typeof rawAddress !== 'string' || !rawAddress)
|
|
351
|
+
return;
|
|
352
|
+
addresses[chain] = rawAddress;
|
|
353
|
+
};
|
|
354
|
+
const src = (source && typeof source === 'object' ? source : {});
|
|
355
|
+
const nested = (src['addresses'] && typeof src['addresses'] === 'object' ? src['addresses'] : {});
|
|
356
|
+
for (const [chain, value] of Object.entries(src))
|
|
357
|
+
put(chain, value);
|
|
358
|
+
for (const [chain, value] of Object.entries(nested))
|
|
359
|
+
put(chain, value);
|
|
360
|
+
for (const k of (Array.isArray(src['keys']) ? src['keys'] : [])) {
|
|
361
|
+
put(k?.['chain'], k?.['address']);
|
|
362
|
+
}
|
|
363
|
+
return addresses;
|
|
364
|
+
}
|
|
365
|
+
// Ask the operator on the terminal. Used only for the permanent, first-write-wins
|
|
366
|
+
// address registration — every other verb is non-destructive.
|
|
367
|
+
async function confirm(prompt) {
|
|
368
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
369
|
+
try {
|
|
370
|
+
const answer = await new Promise((resolve) => rl.question(prompt, resolve));
|
|
371
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
372
|
+
}
|
|
373
|
+
finally {
|
|
374
|
+
rl.close();
|
|
375
|
+
}
|
|
376
|
+
}
|
|
169
377
|
// Read the recovery mnemonic for `keygen --recover`: ONE_WALLET_MNEMONIC env first
|
|
170
378
|
// (scriptable), else stdin (fd 0). Never a CLI arg — keeps the phrase out of the
|
|
171
379
|
// process table / shell history.
|
|
@@ -207,3 +415,53 @@ function out(cmd, data) {
|
|
|
207
415
|
console.error('✗', typeof detail === 'string' ? detail : JSON.stringify(detail));
|
|
208
416
|
}
|
|
209
417
|
}
|
|
418
|
+
/** Read a secret from the TTY with echo off. Never argv (world-readable in ps), never env. */
|
|
419
|
+
async function promptSecret(prompt) {
|
|
420
|
+
if (!process.stdin.isTTY)
|
|
421
|
+
throw new Error('a passphrase must be typed at a terminal — refusing to read one from a pipe');
|
|
422
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
423
|
+
const stdout = process.stdout;
|
|
424
|
+
const orig = stdout.write.bind(stdout);
|
|
425
|
+
process.stdout.write(prompt);
|
|
426
|
+
stdout.write = () => true;
|
|
427
|
+
try {
|
|
428
|
+
return await new Promise((resolve) => rl.question('', (a) => { resolve(a); }));
|
|
429
|
+
}
|
|
430
|
+
finally {
|
|
431
|
+
;
|
|
432
|
+
stdout.write = orig;
|
|
433
|
+
rl.close();
|
|
434
|
+
orig('\n');
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Open the folder's vault, asking Keychain or the human depending on how it was
|
|
439
|
+
* SEALED. `wrap` is what makes this possible: without it a keychain vault is
|
|
440
|
+
* indistinguishable from a passphrase one and the only way to find out is to
|
|
441
|
+
* prompt for a passphrase that was never set.
|
|
442
|
+
*/
|
|
443
|
+
async function unlock(dir) {
|
|
444
|
+
const raw = readVaultFolder(dir);
|
|
445
|
+
if (!raw)
|
|
446
|
+
return { error: `no wallet at ${vaultPath(dir)} — run \`one wallet new\`` };
|
|
447
|
+
const blob = raw;
|
|
448
|
+
let passphrase;
|
|
449
|
+
if (blob.wrap === 'keychain') {
|
|
450
|
+
const k = keychainRead(String(blob.authPub ?? ''));
|
|
451
|
+
if (!k.ok || !k.value)
|
|
452
|
+
return { error: k.ok ? 'Keychain returned nothing' : k.error };
|
|
453
|
+
passphrase = k.value;
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
passphrase = await promptSecret('Passphrase: ');
|
|
457
|
+
}
|
|
458
|
+
let mnemonic;
|
|
459
|
+
try {
|
|
460
|
+
mnemonic = await openVault(blob, passphrase);
|
|
461
|
+
}
|
|
462
|
+
catch (e) {
|
|
463
|
+
return { error: e.message };
|
|
464
|
+
}
|
|
465
|
+
const wallet = await recoverWallet(mnemonic);
|
|
466
|
+
return { blob, mnemonic, addresses: Object.fromEntries(wallet.keys.map((k) => [k.chain, k.address])) };
|
|
467
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { askPath } from './lib/api-path.js';
|
|
6
|
+
const DEFAULT_API = 'https://api.one.ie';
|
|
7
|
+
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
8
|
+
function readApiKey() {
|
|
9
|
+
// ONE_API_KEY is canonical, ONEIE_API_KEY legacy — same order lib/client.ts uses.
|
|
10
|
+
if (process.env.ONE_API_KEY)
|
|
11
|
+
return process.env.ONE_API_KEY;
|
|
12
|
+
if (process.env.ONEIE_API_KEY)
|
|
13
|
+
return process.env.ONEIE_API_KEY;
|
|
14
|
+
if (existsSync(KEY_FILE))
|
|
15
|
+
return readFileSync(KEY_FILE, 'utf8').trim() || null;
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
// Every workspace op hits an EXISTING workflow:* receiver via the ask door — no new
|
|
19
|
+
// HTTP route (cli/CLAUDE.md no-new-endpoints). pull writes the workflow:get graph
|
|
20
|
+
// verbatim as <name>/workflow.json; push takes a diff-JSON file and applies it
|
|
21
|
+
// (simulate by default, --commit persists). Mirrors the agent group's file round-trip.
|
|
22
|
+
export function workflowCmd() {
|
|
23
|
+
const cmd = new Command('workflow').description('List, pull, push (diff), and run workflows');
|
|
24
|
+
const call = async (api, slug, receiver, data) => {
|
|
25
|
+
const key = readApiKey();
|
|
26
|
+
if (!key)
|
|
27
|
+
return { ok: false, error: 'no API key — run `oneie auth login --key <key>` or set ONEIE_API_KEY' };
|
|
28
|
+
const url = askPath(api.replace(/\/$/, ''), receiver);
|
|
29
|
+
const res = await fetch(url, {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
// Bearer <key> — NOT `<slug>:<key>`. The world key carries its own ownerSlug;
|
|
32
|
+
// prefixing the slug made the gateway read the whole string as an unknown key
|
|
33
|
+
// and every workflow subcommand 403'd with "authentication required".
|
|
34
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
35
|
+
body: JSON.stringify({ data }),
|
|
36
|
+
});
|
|
37
|
+
const text = await res.text();
|
|
38
|
+
if (!text)
|
|
39
|
+
return {};
|
|
40
|
+
const body = JSON.parse(text);
|
|
41
|
+
// The ask door answers with an ENVELOPE — { outcome, result, signalId }. Every
|
|
42
|
+
// subcommand below reads the receiver's own fields (r.id, r.ok, r.runId), so
|
|
43
|
+
// unwrap here. Reading them off the envelope made `pull` report not_found for
|
|
44
|
+
// a workflow that exists, and `push` report ok=false on a successful apply.
|
|
45
|
+
if (body && typeof body === 'object' && 'outcome' in body) {
|
|
46
|
+
const inner = (body.result ?? {});
|
|
47
|
+
if (body.outcome === 'failure')
|
|
48
|
+
return { error: inner.error ?? 'failure', ...inner };
|
|
49
|
+
return { ...inner, ...(body.simulated ? { simulated: true } : {}) };
|
|
50
|
+
}
|
|
51
|
+
return body;
|
|
52
|
+
};
|
|
53
|
+
cmd.command('list')
|
|
54
|
+
.description('List workflows in a workspace')
|
|
55
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
56
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
57
|
+
.action(async (opts) => {
|
|
58
|
+
const r = await call(opts.api, opts.slug, 'workflow:list', {});
|
|
59
|
+
out(cmd, { ok: !r.error, ...r });
|
|
60
|
+
});
|
|
61
|
+
cmd.command('pull <id>')
|
|
62
|
+
.description('Download a workflow graph to <name>/workflow.json')
|
|
63
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
64
|
+
.option('--out <dir>', 'Output directory (defaults to the workflow name)')
|
|
65
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
66
|
+
.action(async (id, opts) => {
|
|
67
|
+
const r = await call(opts.api, opts.slug, 'workflow:get', { workflowId: id });
|
|
68
|
+
if (r.error || !r.id) {
|
|
69
|
+
out(cmd, { ok: false, error: r.error ?? 'not_found' });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const dir = opts.out ?? String(r.name ?? id).toLowerCase().replace(/[^a-z0-9]+/g, '-');
|
|
73
|
+
mkdirSync(dir, { recursive: true });
|
|
74
|
+
const path = `${dir}/workflow.json`;
|
|
75
|
+
writeFileSync(path, JSON.stringify(r, null, 2));
|
|
76
|
+
out(cmd, { ok: true, path, steps: (r.steps ?? []).length });
|
|
77
|
+
});
|
|
78
|
+
cmd.command('push <id> <file>')
|
|
79
|
+
.description('Apply a diff-JSON file to a workflow (simulate by default)')
|
|
80
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
81
|
+
.option('--commit', 'Persist the diff (default simulates)')
|
|
82
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
83
|
+
.action(async (id, file, opts) => {
|
|
84
|
+
if (!existsSync(file)) {
|
|
85
|
+
out(cmd, { ok: false, error: `not found: ${file}` });
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const diff = JSON.parse(readFileSync(file, 'utf8'));
|
|
89
|
+
const r = await call(opts.api, opts.slug, 'workflow:apply-diff', { workflowId: id, diff, simulate: opts.commit !== true });
|
|
90
|
+
out(cmd, { ok: !!r.ok, simulated: opts.commit !== true, ...r });
|
|
91
|
+
});
|
|
92
|
+
cmd.command('run <id>')
|
|
93
|
+
.description('Start a run of a workflow')
|
|
94
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
95
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
96
|
+
.action(async (id, opts) => {
|
|
97
|
+
const r = await call(opts.api, opts.slug, 'workflow:run', { workflowId: id });
|
|
98
|
+
out(cmd, { ok: !!r.runId, ...r });
|
|
99
|
+
});
|
|
100
|
+
cmd.command('validate <id> <file>')
|
|
101
|
+
.description('Validate a diff-JSON file against a workflow (§9 gate, never persists)')
|
|
102
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
103
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
104
|
+
.action(async (id, file, opts) => {
|
|
105
|
+
if (!existsSync(file)) {
|
|
106
|
+
out(cmd, { ok: false, error: `not found: ${file}` });
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const diff = JSON.parse(readFileSync(file, 'utf8'));
|
|
110
|
+
const r = await call(opts.api, opts.slug, 'workflow:validate', { workflowId: id, diff });
|
|
111
|
+
out(cmd, { ok: !!r.ok, ...r });
|
|
112
|
+
});
|
|
113
|
+
cmd.command('resolve <runId> <stepId>')
|
|
114
|
+
.description('Resolve a suspended human step in a run (--decision approved|rejected)')
|
|
115
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
116
|
+
.option('--decision <d>', 'approved | rejected')
|
|
117
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
118
|
+
.action(async (runId, stepId, opts) => {
|
|
119
|
+
const r = await call(opts.api, opts.slug, 'human:resolve', { runId, stepId, ...(opts.decision ? { decision: opts.decision } : {}) });
|
|
120
|
+
out(cmd, { ok: !!r.ok, ...r });
|
|
121
|
+
});
|
|
122
|
+
cmd.command('logs <id>')
|
|
123
|
+
.description("List recent runs of a workflow; --run <runId> for one run's step-event timeline")
|
|
124
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
125
|
+
.option('--run <runId>', "Return this run's event timeline")
|
|
126
|
+
.option('--limit <n>', 'Max runs to list', (v) => parseInt(v, 10))
|
|
127
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
128
|
+
.action(async (id, opts) => {
|
|
129
|
+
const r = await call(opts.api, opts.slug, 'workflow:runs', { workflowId: id, ...(opts.run ? { runId: opts.run } : {}), ...(opts.limit ? { limit: opts.limit } : {}) });
|
|
130
|
+
out(cmd, { ok: !r.error, ...r });
|
|
131
|
+
});
|
|
132
|
+
return cmd;
|
|
133
|
+
}
|
|
134
|
+
// out() mirrors agent.ts — human `✓ k=v` or --json. W3: reuse the shared helper if
|
|
135
|
+
// one is exported; otherwise copy agent.ts's local out().
|
|
136
|
+
function out(cmd, data) {
|
|
137
|
+
const json = cmd.parent?.opts()?.json ?? false;
|
|
138
|
+
if (json) {
|
|
139
|
+
process.stdout.write(JSON.stringify(data) + '\n');
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const line = Object.entries(data).map(([k, v]) => `${k}=${typeof v === 'object' ? JSON.stringify(v) : v}`).join(' ');
|
|
143
|
+
process.stdout.write((data.ok ? '✓ ' : '✗ ') + line + '\n');
|
|
144
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oneie",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "ONE agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"build": "tsc && cp package.json dist/ && chmod +x dist/src/index.js",
|
|
16
16
|
"dev": "tsx src/index.ts",
|
|
17
17
|
"typecheck": "tsc --noEmit",
|
|
18
|
-
"test": "vitest run",
|
|
18
|
+
"test": "bash ../../.claude/scripts/gate-run.sh test-cli -- vitest run",
|
|
19
19
|
"prepublishOnly": "bun run build"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"commander": "^12.0.0",
|
|
23
|
-
"@oneie/sdk": "^0.
|
|
23
|
+
"@oneie/sdk": "^0.16.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@oneie/evals": "
|
|
26
|
+
"@oneie/evals": "^0.1.1",
|
|
27
27
|
"@types/node": "^25.6.0",
|
|
28
28
|
"tsx": "^4.0.0",
|
|
29
29
|
"typescript": "^5.4.0",
|