@oneie/cli 4.0.5 → 4.0.6
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 +3 -0
- package/dist/package.json +1 -1
- package/dist/src/agent.d.ts +9 -0
- package/dist/src/agent.js +246 -41
- package/dist/src/skill.js +122 -6
- package/dist/src/wallet.d.ts +9 -0
- package/dist/src/wallet.js +87 -0
- package/dist/src/workflow.js +22 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -85,11 +85,14 @@ Every actor — human or agent — gets real, self-custodied multi-chain wallets
|
|
|
85
85
|
```bash
|
|
86
86
|
one wallet create --workspace <slug> --kind agent # provision a wallet row (idempotent)
|
|
87
87
|
one wallet get --workspace <slug> # credits, ceiling, live balances, delegated wallets
|
|
88
|
+
one wallet register --from keys.json --workspace <slug> # register the PUBLIC receiving addresses — first write wins, permanent
|
|
88
89
|
one wallet transactions --workspace <slug> --limit 50 # unified feed across every settlement rail
|
|
89
90
|
one wallet faucet <address> --chain sui # fund from testnet — sui/sol auto-fund, others return a manual URL
|
|
90
91
|
one wallet send <to> --chain SUI --amount 5 --payment-tx <hash> --workspace <slug>
|
|
91
92
|
```
|
|
92
93
|
|
|
94
|
+
`register` reads a `wallet keygen` output but transmits only its four address fields — the map it sends is built key-by-key from a fixed chain whitelist, so a `mnemonic` or `privateKey` in that file has no route onto the wire. The write is first-write-wins per chain and cannot be corrected afterwards (`address_conflict`), so it prints the addresses and asks for confirmation; `--yes` skips the prompt for scripted provisioning (needed when the JSON arrives on stdin, which leaves no terminal to answer with).
|
|
95
|
+
|
|
93
96
|
`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.
|
|
94
97
|
|
|
95
98
|
## Operate the business
|
package/dist/package.json
CHANGED
package/dist/src/agent.d.ts
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
export declare function agentCmd(): Command;
|
|
3
|
+
/**
|
|
4
|
+
* Targets the CLI can actually emit. `a2a` and `erc8004` were advertised in
|
|
5
|
+
* --target help and in the docs but had no branch — they fell through to
|
|
6
|
+
* `return content`, echoing the raw agent.md back as if it had compiled. They
|
|
7
|
+
* now FAIL LOUDLY: there is no a2a/erc8004 compiler anywhere in @oneie/sdk to
|
|
8
|
+
* delegate to, and inventing one here would be worse than an honest error.
|
|
9
|
+
*/
|
|
10
|
+
export declare const CLI_TARGETS: readonly ["mcp", "uagents", "skillmd", "web"];
|
|
11
|
+
export declare function compileTarget(content: string, target: string, skills?: Record<string, string>): string;
|
package/dist/src/agent.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
|
3
|
-
import { basename, dirname, resolve } from 'node:path';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
3
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
5
4
|
import { TEMPLATES } from './templates.js';
|
|
6
|
-
import { compileAgent } from '@oneie/sdk/compile';
|
|
5
|
+
import { compileAgent, parseAgentMd } from '@oneie/sdk/compile';
|
|
6
|
+
import { resolveKey } from './lib/client.js';
|
|
7
|
+
import { askPath } from './lib/api-path.js';
|
|
7
8
|
import { watch } from 'fs';
|
|
8
9
|
const DEFAULT_API = 'https://one.ie';
|
|
9
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The CLI-wide key contract lives in one place — `resolveKey()` in
|
|
12
|
+
* lib/client.ts: `--key` > ONE_API_KEY (canonical) > ONEIE_API_KEY (legacy) >
|
|
13
|
+
* ~/.config/oneie/key. This module used to read ONLY the legacy var, so anyone
|
|
14
|
+
* on the canonical `ONE_API_KEY` silently resolved to null.
|
|
15
|
+
*/
|
|
10
16
|
function readApiKey() {
|
|
11
|
-
|
|
12
|
-
return process.env.ONEIE_API_KEY;
|
|
13
|
-
if (existsSync(KEY_FILE))
|
|
14
|
-
return readFileSync(KEY_FILE, 'utf8').trim() || null;
|
|
15
|
-
return null;
|
|
17
|
+
return resolveKey() || null;
|
|
16
18
|
}
|
|
17
19
|
export function agentCmd() {
|
|
18
20
|
const cmd = new Command('agent').description('Agent management');
|
|
@@ -49,7 +51,8 @@ export function agentCmd() {
|
|
|
49
51
|
});
|
|
50
52
|
cmd.command('compile <path>')
|
|
51
53
|
.description('Compile agent.md to target format')
|
|
52
|
-
.option('--target <t>',
|
|
54
|
+
.option('--target <t>', `Output format: ${CLI_TARGETS.join(' | ')} (a2a and erc8004 are NOT implemented)`, 'mcp')
|
|
55
|
+
.option('--skills <dir>', 'Directory holding the skill markdown declared in the agent frontmatter')
|
|
53
56
|
.option('--out <file>', 'Write output to file instead of stdout')
|
|
54
57
|
.action((path, opts) => {
|
|
55
58
|
if (!existsSync(path)) {
|
|
@@ -57,11 +60,24 @@ export function agentCmd() {
|
|
|
57
60
|
return;
|
|
58
61
|
}
|
|
59
62
|
const content = readFileSync(path, 'utf8');
|
|
60
|
-
const
|
|
63
|
+
const found = resolveSkillMds(path, content, opts.skills);
|
|
64
|
+
if (opts.target in TARGETS_USING_SKILLS)
|
|
65
|
+
warnSkillGap(found, opts.target);
|
|
66
|
+
let result;
|
|
67
|
+
try {
|
|
68
|
+
result = compileTarget(content, opts.target, found.skills);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
out(cmd, { ok: false, target: opts.target, error: err.message });
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
61
74
|
if (opts.out) {
|
|
62
75
|
mkdirSync(dirname(opts.out), { recursive: true });
|
|
63
76
|
writeFileSync(opts.out, result);
|
|
64
|
-
out(cmd, {
|
|
77
|
+
out(cmd, {
|
|
78
|
+
ok: true, target: opts.target, written: opts.out, bytes: result.length,
|
|
79
|
+
skillsDeclared: found.declared.length, skillsResolved: found.resolved.length,
|
|
80
|
+
});
|
|
65
81
|
}
|
|
66
82
|
else {
|
|
67
83
|
process.stdout.write(result + '\n');
|
|
@@ -84,6 +100,7 @@ export function agentCmd() {
|
|
|
84
100
|
.option('--name <name>', 'Override agent name (defaults to frontmatter name:)')
|
|
85
101
|
.option('--target <t>', 'Publish target: oneie (default) | agentverse', 'oneie')
|
|
86
102
|
.option('--agentverse-key <key>', 'Agentverse API key (or set AGENTVERSE_API_KEY)')
|
|
103
|
+
.option('--skills <dir>', 'Directory holding the skill markdown declared in the agent frontmatter (agentverse target)')
|
|
87
104
|
.option('--live', 'Set lifecycle: active before publishing (skip the draft step)')
|
|
88
105
|
.action(async (path, opts) => {
|
|
89
106
|
if (!existsSync(path)) {
|
|
@@ -107,10 +124,14 @@ export function agentCmd() {
|
|
|
107
124
|
out(cmd, { ok: false, error: 'Agentverse API key required — pass --agentverse-key or set AGENTVERSE_API_KEY' });
|
|
108
125
|
return;
|
|
109
126
|
}
|
|
110
|
-
// Compile agent.md → Python uAgents
|
|
127
|
+
// Compile agent.md → Python uAgents. The skills map is what makes the
|
|
128
|
+
// compiler emit Protocol + on_message handlers; without it every
|
|
129
|
+
// deployed agent is a shell that cannot answer a message.
|
|
130
|
+
const found = resolveSkillMds(path, content, opts.skills);
|
|
131
|
+
warnSkillGap(found, 'uagents');
|
|
111
132
|
let python;
|
|
112
133
|
try {
|
|
113
|
-
python = compileAgent(content, { target: 'uagents' });
|
|
134
|
+
python = compileAgent(content, { target: 'uagents', skills: found.skills });
|
|
114
135
|
}
|
|
115
136
|
catch (err) {
|
|
116
137
|
out(cmd, { ok: false, error: `compile failed: ${err.message}` });
|
|
@@ -137,10 +158,40 @@ export function agentCmd() {
|
|
|
137
158
|
// 2. Upload code (double-encoded JSON — Agentverse requirement)
|
|
138
159
|
const codeArray = [{ language: 'python', name: 'agent.py', value: python }];
|
|
139
160
|
await avFetch('PUT', `/hosting/agents/${address}/code`, { code: JSON.stringify(codeArray) });
|
|
140
|
-
// 3.
|
|
161
|
+
// 3. Inject the secrets the hosted agent needs. Never silent: a
|
|
162
|
+
// swallowed failure here produced an agent that deploys, starts,
|
|
163
|
+
// and then dies on its first message with no trace of why.
|
|
164
|
+
const secrets = {};
|
|
165
|
+
const putSecret = async (secretName, value) => {
|
|
166
|
+
try {
|
|
167
|
+
await avFetch('POST', '/hosting/secrets', { address, name: secretName, secret: value });
|
|
168
|
+
secrets[secretName] = 'ok';
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
secrets[secretName] = `failed: ${e.message}`;
|
|
172
|
+
console.error(`warning: ${secretName} was NOT set on the Agentverse agent — ${e.message}`);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
141
175
|
const oneKey = readApiKey();
|
|
142
176
|
if (oneKey) {
|
|
143
|
-
|
|
177
|
+
console.error('Uploading secret ONEIE_API_KEY to agentverse.ai (variable name only — the value is never printed).');
|
|
178
|
+
await putSecret('ONEIE_API_KEY', oneKey);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
secrets.ONEIE_API_KEY = 'skipped: no key resolved';
|
|
182
|
+
console.error('warning: no ONE API key resolved (ONE_API_KEY / ONEIE_API_KEY / ~/.config/oneie/key) — ONEIE_API_KEY was NOT injected, so the deployed agent carries no credential for the ONE substrate. Run `oneie auth login` or set ONE_API_KEY.');
|
|
183
|
+
}
|
|
184
|
+
// The generated Python constructs Anthropic() with no explicit key,
|
|
185
|
+
// so the SDK reads ANTHROPIC_API_KEY from the hosted environment.
|
|
186
|
+
// Process env only — never a file, never invented.
|
|
187
|
+
const anthropicKey = process.env.ANTHROPIC_API_KEY;
|
|
188
|
+
if (anthropicKey) {
|
|
189
|
+
console.error('Uploading secret ANTHROPIC_API_KEY to agentverse.ai — your own Anthropic credential is being sent to this third-party host so the agent can call the model (variable name only — the value is never printed).');
|
|
190
|
+
await putSecret('ANTHROPIC_API_KEY', anthropicKey);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
secrets.ANTHROPIC_API_KEY = 'skipped: not set in the environment';
|
|
194
|
+
console.error('warning: ANTHROPIC_API_KEY is not set in this environment — it was NOT injected. The generated Python calls Anthropic() with no key, so this agent will fail on its first message.');
|
|
144
195
|
}
|
|
145
196
|
// 4. Start
|
|
146
197
|
await avFetch('POST', `/hosting/agents/${address}/start`, {});
|
|
@@ -163,6 +214,10 @@ export function agentCmd() {
|
|
|
163
214
|
walletAddress,
|
|
164
215
|
compiled,
|
|
165
216
|
agentName,
|
|
217
|
+
secrets,
|
|
218
|
+
protocols: found.resolved.length,
|
|
219
|
+
skillsDeclared: found.declared.length,
|
|
220
|
+
skillsMissing: found.missing,
|
|
166
221
|
agentverseUrl: `https://agentverse.ai/agents/details/${address}`,
|
|
167
222
|
});
|
|
168
223
|
}
|
|
@@ -172,29 +227,74 @@ export function agentCmd() {
|
|
|
172
227
|
return;
|
|
173
228
|
}
|
|
174
229
|
// ── ONE workspace publish path (default) ─────────────────────────────
|
|
230
|
+
//
|
|
231
|
+
// THE TOKEN IS THE PLAIN KEY. It used to be `${slug}:${key}`, and that one
|
|
232
|
+
// line is why publish was unusable by anybody: `requireAuth`
|
|
233
|
+
// (one.ie/web/src/lib/api-auth.ts) resolves a world key by PREFIX — `one-`
|
|
234
|
+
// or `osk_` — so prepending "one:" turns a valid key into `one:one-abc...`,
|
|
235
|
+
// which matches no prefix, falls through to session auth, and 401s. The same
|
|
236
|
+
// line was copy-pasted across ten call sites in agent.ts and skill.ts, so
|
|
237
|
+
// every workspace command in the CLI was broken the same way. The route
|
|
238
|
+
// header comments claiming `Bearer <ownerId>:<SERVER_SECRET>` are STALE —
|
|
239
|
+
// the code calls `requireAuthOver(request, "update_group", slug)`.
|
|
240
|
+
//
|
|
241
|
+
// Publish goes through the RECEIVER door rather than `/api/agents/publish`
|
|
242
|
+
// for one reason: credential CLASS. `/api/ask/*` accepts a world key OR a
|
|
243
|
+
// service credential; the route accepts only a world key or a browser
|
|
244
|
+
// session. Both authorize with the same ownership walk, and since
|
|
245
|
+
// `publishAgent` now writes the versioned archive too (world-receivers.ts),
|
|
246
|
+
// the route no longer has any semantic the receiver lacks — so `agent
|
|
247
|
+
// history` and `agent rollback` still see what this publishes.
|
|
175
248
|
if (!opts.slug) {
|
|
176
249
|
out(cmd, { ok: false, error: 'missing --slug <workspace>' });
|
|
177
250
|
return;
|
|
178
251
|
}
|
|
179
252
|
const key = readApiKey();
|
|
180
253
|
if (!key) {
|
|
181
|
-
out(cmd, { ok: false, error: 'no API key — run `oneie auth login
|
|
254
|
+
out(cmd, { ok: false, error: 'no API key — run `oneie auth login` or set ONE_API_KEY (legacy: ONEIE_API_KEY)' });
|
|
182
255
|
return;
|
|
183
256
|
}
|
|
184
|
-
const token = `${opts.slug}:${key}`;
|
|
185
257
|
try {
|
|
186
|
-
const res = await fetch(
|
|
258
|
+
const res = await fetch(askPath(opts.api.replace(/\/$/, ''), 'world:publish-agent'), {
|
|
187
259
|
method: 'POST',
|
|
188
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${
|
|
189
|
-
body: JSON.stringify({ slug: opts.slug, name: agentName, content }),
|
|
260
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
261
|
+
body: JSON.stringify({ data: { slug: opts.slug, name: agentName, content } }),
|
|
190
262
|
});
|
|
191
263
|
const text = await res.text();
|
|
192
|
-
const
|
|
193
|
-
|
|
194
|
-
|
|
264
|
+
const envelope = (text ? JSON.parse(text) : {});
|
|
265
|
+
const result = envelope.result ?? {};
|
|
266
|
+
// THE ASK ENVELOPE ANSWERS HTTP 200 ON A REFUSAL. `outcome: "failure"`
|
|
267
|
+
// carries the receiver's own error under a 200, so `res.ok` alone reports
|
|
268
|
+
// a refused publish as a success. Check all three.
|
|
269
|
+
if (!res.ok || envelope.outcome === 'failure' || result.ok === false) {
|
|
270
|
+
// A bare "forbidden" is unactionable and its two causes need OPPOSITE
|
|
271
|
+
// fixes, so read `callerRole` rather than guessing. `anonymous` = the
|
|
272
|
+
// Bearer matched no world_keys row (wrong key, or not a key); anything
|
|
273
|
+
// else = a real key the ownership walk refused for THIS workspace.
|
|
274
|
+
const base = result.error ?? envelope.error ?? text ?? 'publish failed';
|
|
275
|
+
const hint = result.error !== 'forbidden'
|
|
276
|
+
? undefined
|
|
277
|
+
: result.callerRole === 'anonymous'
|
|
278
|
+
? 'the key was not recognised — run `oneie auth login`, or set ONE_API_KEY to a world key (it starts `one-` or `osk_`)'
|
|
279
|
+
: `authenticated as ${result.callerRole}, but that identity does not control workspace "${opts.slug}"`;
|
|
280
|
+
// out() prints only `error` in human mode, so the actionable half has to
|
|
281
|
+
// live in that string; the structured fields stay for --json.
|
|
282
|
+
out(cmd, {
|
|
283
|
+
ok: false,
|
|
284
|
+
status: res.status,
|
|
285
|
+
error: hint ? `${base} — ${hint}` : base,
|
|
286
|
+
...(result.required ? { required: result.required } : {}),
|
|
287
|
+
...(result.callerRole ? { callerRole: result.callerRole } : {}),
|
|
288
|
+
});
|
|
195
289
|
return;
|
|
196
290
|
}
|
|
197
|
-
out(cmd, {
|
|
291
|
+
out(cmd, {
|
|
292
|
+
ok: true,
|
|
293
|
+
name: agentName,
|
|
294
|
+
url: result.url,
|
|
295
|
+
bytes: result.bytes,
|
|
296
|
+
subscribes: result.subscribes ?? [],
|
|
297
|
+
});
|
|
198
298
|
}
|
|
199
299
|
catch (err) {
|
|
200
300
|
out(cmd, { ok: false, error: err.message });
|
|
@@ -212,10 +312,10 @@ export function agentCmd() {
|
|
|
212
312
|
}
|
|
213
313
|
const key = readApiKey();
|
|
214
314
|
if (!key) {
|
|
215
|
-
out(cmd, { ok: false, error: 'no API key — run `oneie auth login --key <key>` or set ONEIE_API_KEY' });
|
|
315
|
+
out(cmd, { ok: false, error: 'no API key — run `oneie auth login --key <key>` or set ONE_API_KEY (legacy: ONEIE_API_KEY)' });
|
|
216
316
|
return;
|
|
217
317
|
}
|
|
218
|
-
const token =
|
|
318
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
219
319
|
const url = `${opts.api.replace(/\/$/, '')}/api/agents/publish?slug=${encodeURIComponent(opts.slug)}&name=${encodeURIComponent(name)}`;
|
|
220
320
|
try {
|
|
221
321
|
const res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
|
@@ -245,10 +345,10 @@ export function agentCmd() {
|
|
|
245
345
|
}
|
|
246
346
|
const key = readApiKey();
|
|
247
347
|
if (!key) {
|
|
248
|
-
out(cmd, { ok: false, error: 'no API key — run `oneie auth login --key <key>` or set ONEIE_API_KEY' });
|
|
348
|
+
out(cmd, { ok: false, error: 'no API key — run `oneie auth login --key <key>` or set ONE_API_KEY (legacy: ONEIE_API_KEY)' });
|
|
249
349
|
return;
|
|
250
350
|
}
|
|
251
|
-
const token =
|
|
351
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
252
352
|
const url = `${opts.api.replace(/\/$/, '')}/api/agents/publish?slug=${encodeURIComponent(opts.slug)}&name=${encodeURIComponent(name)}`;
|
|
253
353
|
try {
|
|
254
354
|
const res = await fetch(url, { method: 'DELETE', headers: { Authorization: `Bearer ${token}` } });
|
|
@@ -314,7 +414,7 @@ export function agentCmd() {
|
|
|
314
414
|
// Remote mode: call /api/chat with messages + agentId
|
|
315
415
|
const key = readApiKey();
|
|
316
416
|
if (!key) {
|
|
317
|
-
out(cmd, { ok: false, error: 'no API key for remote eval — set ONEIE_API_KEY' });
|
|
417
|
+
out(cmd, { ok: false, error: 'no API key for remote eval — set ONE_API_KEY (legacy: ONEIE_API_KEY) or run `oneie auth login`' });
|
|
318
418
|
return;
|
|
319
419
|
}
|
|
320
420
|
const nameMatch = /^name:\s+([a-z0-9-]+)/m.exec(fm);
|
|
@@ -328,7 +428,7 @@ export function agentCmd() {
|
|
|
328
428
|
try {
|
|
329
429
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/chat`, {
|
|
330
430
|
method: 'POST',
|
|
331
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${
|
|
431
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
332
432
|
body: JSON.stringify({ messages: [{ role: 'user', content: c.input }], agentId, slug: opts.slug }),
|
|
333
433
|
});
|
|
334
434
|
const text = await res.text();
|
|
@@ -416,10 +516,10 @@ export function agentCmd() {
|
|
|
416
516
|
.action(async (opts) => {
|
|
417
517
|
const key = readApiKey();
|
|
418
518
|
if (!key) {
|
|
419
|
-
out(cmd, { ok: false, error: 'no API key — set ONEIE_API_KEY or run oneie auth login' });
|
|
519
|
+
out(cmd, { ok: false, error: 'no API key — set ONE_API_KEY (legacy: ONEIE_API_KEY) or run `oneie auth login`' });
|
|
420
520
|
return;
|
|
421
521
|
}
|
|
422
|
-
const token =
|
|
522
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
423
523
|
const url = `${opts.api.replace(/\/$/, '')}/api/agents/list?slug=${encodeURIComponent(opts.slug)}`;
|
|
424
524
|
try {
|
|
425
525
|
const res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
|
@@ -442,10 +542,10 @@ export function agentCmd() {
|
|
|
442
542
|
.action(async (name, opts) => {
|
|
443
543
|
const key = readApiKey();
|
|
444
544
|
if (!key) {
|
|
445
|
-
out(cmd, { ok: false, error: 'no API key — set ONEIE_API_KEY or run oneie auth login' });
|
|
545
|
+
out(cmd, { ok: false, error: 'no API key — set ONE_API_KEY (legacy: ONEIE_API_KEY) or run `oneie auth login`' });
|
|
446
546
|
return;
|
|
447
547
|
}
|
|
448
|
-
const token =
|
|
548
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
449
549
|
const url = `${opts.api.replace(/\/$/, '')}/api/agents/history?slug=${encodeURIComponent(opts.slug)}&name=${encodeURIComponent(name)}`;
|
|
450
550
|
try {
|
|
451
551
|
const res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
|
|
@@ -470,7 +570,7 @@ export function agentCmd() {
|
|
|
470
570
|
.action(async (name, opts) => {
|
|
471
571
|
const key = readApiKey();
|
|
472
572
|
if (!key) {
|
|
473
|
-
out(cmd, { ok: false, error: 'no API key — set ONEIE_API_KEY or run oneie auth login' });
|
|
573
|
+
out(cmd, { ok: false, error: 'no API key — set ONE_API_KEY (legacy: ONEIE_API_KEY) or run `oneie auth login`' });
|
|
474
574
|
return;
|
|
475
575
|
}
|
|
476
576
|
const ts = parseInt(opts.to, 10);
|
|
@@ -490,7 +590,7 @@ export function agentCmd() {
|
|
|
490
590
|
return;
|
|
491
591
|
}
|
|
492
592
|
}
|
|
493
|
-
const token =
|
|
593
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
494
594
|
const url = `${opts.api.replace(/\/$/, '')}/api/agents/rollback`;
|
|
495
595
|
try {
|
|
496
596
|
const res = await fetch(url, {
|
|
@@ -653,6 +753,10 @@ function out(cmd, data) {
|
|
|
653
753
|
else {
|
|
654
754
|
const detail = data.error ?? data.errors ?? data.issues ?? data;
|
|
655
755
|
console.error('✗', typeof detail === 'string' ? detail : JSON.stringify(detail));
|
|
756
|
+
// Match the shared out() in lib/client.ts. Without this every `agent`
|
|
757
|
+
// failure — including an unimplemented compile target — exited 0, so a CI
|
|
758
|
+
// script could not tell a refusal from a success.
|
|
759
|
+
process.exitCode = 1;
|
|
656
760
|
}
|
|
657
761
|
}
|
|
658
762
|
/**
|
|
@@ -748,11 +852,110 @@ function lint(path) {
|
|
|
748
852
|
}
|
|
749
853
|
return issues;
|
|
750
854
|
}
|
|
751
|
-
|
|
855
|
+
/**
|
|
856
|
+
* Targets the CLI can actually emit. `a2a` and `erc8004` were advertised in
|
|
857
|
+
* --target help and in the docs but had no branch — they fell through to
|
|
858
|
+
* `return content`, echoing the raw agent.md back as if it had compiled. They
|
|
859
|
+
* now FAIL LOUDLY: there is no a2a/erc8004 compiler anywhere in @oneie/sdk to
|
|
860
|
+
* delegate to, and inventing one here would be worse than an honest error.
|
|
861
|
+
*/
|
|
862
|
+
export const CLI_TARGETS = ['mcp', 'uagents', 'skillmd', 'web'];
|
|
863
|
+
const UNIMPLEMENTED_TARGETS = {
|
|
864
|
+
a2a: 'no A2A agent-card compiler exists in @oneie/sdk/compile',
|
|
865
|
+
erc8004: 'no ERC-8004 identity-registry compiler exists in @oneie/sdk/compile',
|
|
866
|
+
};
|
|
867
|
+
/**
|
|
868
|
+
* Targets whose output is derived from the resolved skill markdown, and the
|
|
869
|
+
* noun each one actually emits — `mcp` emits tools, not protocols.
|
|
870
|
+
*/
|
|
871
|
+
const TARGETS_USING_SKILLS = {
|
|
872
|
+
mcp: 'tools',
|
|
873
|
+
uagents: 'protocols (Protocol + on_message handlers)',
|
|
874
|
+
skillmd: 'SKILL.md blocks',
|
|
875
|
+
};
|
|
876
|
+
/**
|
|
877
|
+
* Resolve the skill markdown an agent's frontmatter declares.
|
|
878
|
+
*
|
|
879
|
+
* `compileAgent` derives uAgents protocols and MCP tools from a `skills` map
|
|
880
|
+
* keyed by skill name; with no map, `hasSkills` is false and NO on_message
|
|
881
|
+
* handler is emitted — every agent the CLI ever published to Agentverse was a
|
|
882
|
+
* shell with zero protocols. Callers pass the result through so the compiler's
|
|
883
|
+
* skills-to-protocols path is actually reachable.
|
|
884
|
+
*
|
|
885
|
+
* Layouts searched (both the flat `skill new` layout and the `skill emit`
|
|
886
|
+
* SKILL.md directory layout), nearest to the agent first.
|
|
887
|
+
*/
|
|
888
|
+
function resolveSkillMds(agentPath, content, skillsDir) {
|
|
889
|
+
const { meta } = parseAgentMd(content);
|
|
890
|
+
const declared = (meta.skills ?? [])
|
|
891
|
+
.map(s => ('ref' in s ? s.ref : s.name))
|
|
892
|
+
.filter((n) => Boolean(n));
|
|
893
|
+
const dir = dirname(resolve(agentPath));
|
|
894
|
+
const roots = [
|
|
895
|
+
...(skillsDir ? [resolve(skillsDir)] : []),
|
|
896
|
+
join(dir, 'skills'),
|
|
897
|
+
join(dir, '..', 'skills'),
|
|
898
|
+
resolve('skills'),
|
|
899
|
+
resolve('ai', 'skills'),
|
|
900
|
+
];
|
|
901
|
+
const skills = {};
|
|
902
|
+
const missing = [];
|
|
903
|
+
for (const name of declared) {
|
|
904
|
+
let found;
|
|
905
|
+
for (const root of roots) {
|
|
906
|
+
for (const candidate of [join(root, `${name}.md`), join(root, name, 'SKILL.md')]) {
|
|
907
|
+
if (existsSync(candidate)) {
|
|
908
|
+
found = candidate;
|
|
909
|
+
break;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
if (found)
|
|
913
|
+
break;
|
|
914
|
+
}
|
|
915
|
+
if (found)
|
|
916
|
+
skills[name] = readFileSync(found, 'utf8');
|
|
917
|
+
else
|
|
918
|
+
missing.push(name);
|
|
919
|
+
}
|
|
920
|
+
return { skills, declared, resolved: Object.keys(skills), missing, roots };
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Never let a zero-protocol compile pass silently. Warnings go to stderr so
|
|
924
|
+
* `--json` stdout stays one machine-readable line.
|
|
925
|
+
*/
|
|
926
|
+
function warnSkillGap(found, target) {
|
|
927
|
+
const noun = TARGETS_USING_SKILLS[target] ?? 'capabilities';
|
|
928
|
+
if (found.declared.length === 0) {
|
|
929
|
+
console.error(`warning: this agent declares no skills: — the compiled ${target} output has ZERO ${noun}.`);
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
if (found.missing.length) {
|
|
933
|
+
console.error(`warning: ${found.missing.length}/${found.declared.length} declared skill(s) have no markdown file and were DROPPED: ${found.missing.join(', ')}`);
|
|
934
|
+
console.error(` searched, per skill <name>: ${found.roots.map(r => `${r}/<name>.md`).join(', ')} (and <root>/<name>/SKILL.md). Pass --skills <dir> to point elsewhere.`);
|
|
935
|
+
}
|
|
936
|
+
if (found.resolved.length === 0) {
|
|
937
|
+
console.error(`warning: ZERO skills resolved — the compiled ${target} output has ZERO ${noun}.`);
|
|
938
|
+
if (target === 'uagents') {
|
|
939
|
+
console.error(' A hosted agent with no protocols cannot answer a message.');
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
export function compileTarget(content, target, skills = {}) {
|
|
944
|
+
const why = UNIMPLEMENTED_TARGETS[target];
|
|
945
|
+
if (why) {
|
|
946
|
+
throw new Error(`target "${target}" is not implemented — ${why}. Supported: ${CLI_TARGETS.join(' | ')}`);
|
|
947
|
+
}
|
|
752
948
|
if (target === 'mcp')
|
|
753
|
-
return
|
|
949
|
+
return compileAgent(content, { target: 'mcp', skills });
|
|
754
950
|
if (target === 'uagents')
|
|
755
|
-
return compileAgent(content, { target: 'uagents' });
|
|
951
|
+
return compileAgent(content, { target: 'uagents', skills });
|
|
952
|
+
if (target === 'skillmd') {
|
|
953
|
+
const emitted = compileAgent(content, { target: 'skillmd', skills });
|
|
954
|
+
if (!emitted.trim()) {
|
|
955
|
+
throw new Error('target "skillmd" resolved no skill markdown — nothing to emit. Pass --skills <dir> pointing at the skill files this agent declares.');
|
|
956
|
+
}
|
|
957
|
+
return emitted;
|
|
958
|
+
}
|
|
756
959
|
if (target === 'web') {
|
|
757
960
|
// Emit a typed TS module — the web app can import this at build time
|
|
758
961
|
// instead of parsing .md at request time. Matches the SDK's compileWeb()
|
|
@@ -769,7 +972,9 @@ function compileTarget(content, target) {
|
|
|
769
972
|
'',
|
|
770
973
|
].join('\n');
|
|
771
974
|
}
|
|
772
|
-
return content
|
|
975
|
+
// Anything else used to `return content` — the raw agent.md echoed back as if
|
|
976
|
+
// it had compiled. A wrong-output-that-looks-right path is worse than a fail.
|
|
977
|
+
throw new Error(`unknown target "${target}" — supported: ${CLI_TARGETS.join(' | ')}`);
|
|
773
978
|
}
|
|
774
979
|
/** Lightweight issue extractor for dev-mode validation (no Zod — just structural checks). */
|
|
775
980
|
function issues_from_quick(_delta, raw) {
|
package/dist/src/skill.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync, readdirSy
|
|
|
3
3
|
import { resolve, basename, join } from 'node:path';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { parse as parseSkill } from './skill-parser.js';
|
|
6
|
+
import { askPath } from './lib/api-path.js';
|
|
6
7
|
export function skillCmd() {
|
|
7
8
|
const cmd = new Command('skill').description('Skill management');
|
|
8
9
|
cmd.command('new <name>')
|
|
@@ -112,6 +113,79 @@ export function skillCmd() {
|
|
|
112
113
|
out(cmd, { ok: false, error: err.message, hint: 'try `oneie skill validate <path>` for offline validation' });
|
|
113
114
|
}
|
|
114
115
|
});
|
|
116
|
+
// `skill:save` is the ONLY writer of the store `skill:run` / `skills:list`
|
|
117
|
+
// actually read (`{slug}/skills/{name}/SKILL.md` in R2). It had no CLI verb:
|
|
118
|
+
// `skill publish` writes the agentskills.io directory format to the LOCAL disk
|
|
119
|
+
// and `skill import` pulls someone else's in, so the one thing an author could
|
|
120
|
+
// not do from the CLI was push their own skill to their own workspace. `one push`
|
|
121
|
+
// reaches it, but only by compiling a whole `ai/` tree — there was no way to
|
|
122
|
+
// send a single file.
|
|
123
|
+
cmd.command('push <path>')
|
|
124
|
+
.description("Upload a SKILL.md into a workspace's R2 catalog — the store skill:run and skills:list read")
|
|
125
|
+
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
126
|
+
.option('--api <url>', 'API base URL', 'https://one.ie')
|
|
127
|
+
.option('--name <name>', 'Override skill name (defaults to frontmatter name:)')
|
|
128
|
+
.action(async (path, opts) => {
|
|
129
|
+
if (!existsSync(path)) {
|
|
130
|
+
out(cmd, { ok: false, error: `not found: ${path}` });
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const content = readFileSync(path, 'utf8');
|
|
134
|
+
// THE NAME IS NEVER GUESSED FROM THE PATH. An earlier draft fell back to the
|
|
135
|
+
// parent directory name, and `skill push /etc/hosts --slug one` therefore
|
|
136
|
+
// published a skill called "etc" containing the host file — accepted, live,
|
|
137
|
+
// and resolvable by `skill:run`. R2 has no skill-delete receiver, so that had
|
|
138
|
+
// to be cleaned up with a direct `wrangler r2 object delete`. A path is not
|
|
139
|
+
// an identity: the frontmatter declares the name, or the caller does.
|
|
140
|
+
if (!/^---\s*$/m.test(content.split('\n')[0] ?? '')) {
|
|
141
|
+
out(cmd, { ok: false, error: `not a skill: ${path} has no YAML frontmatter (a SKILL.md opens with ---)` });
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const fmName = /^name:\s*(\S+)\s*$/m.exec(content.split(/^---\s*$/m)[1] ?? '')?.[1];
|
|
145
|
+
const name = opts.name ?? fmName;
|
|
146
|
+
if (!name) {
|
|
147
|
+
out(cmd, { ok: false, error: 'no skill name — add `name:` to the frontmatter, or pass --name <name>' });
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) {
|
|
151
|
+
out(cmd, { ok: false, error: `invalid skill name "${name}" — lowercase alphanumeric and hyphens only` });
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const keyFile = resolve(homedir(), '.config', 'oneie', 'key');
|
|
155
|
+
const key = process.env.ONE_API_KEY ?? process.env.ONEIE_API_KEY
|
|
156
|
+
?? (existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
157
|
+
if (!key) {
|
|
158
|
+
out(cmd, { ok: false, error: 'no API key — run `oneie auth login` or set ONE_API_KEY' });
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
const res = await fetch(askPath(opts.api.replace(/\/$/, ''), 'skill:save'), {
|
|
163
|
+
method: 'POST',
|
|
164
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
|
|
165
|
+
body: JSON.stringify({ data: { slug: opts.slug, name, content } }),
|
|
166
|
+
});
|
|
167
|
+
const text = await res.text();
|
|
168
|
+
const envelope = (text ? JSON.parse(text) : {});
|
|
169
|
+
const result = envelope.result ?? {};
|
|
170
|
+
// THE ASK ENVELOPE ANSWERS HTTP 200 ON A REFUSAL — `outcome: "failure"`
|
|
171
|
+
// carries the receiver's error under a 200, so `res.ok` alone would report
|
|
172
|
+
// a refused push as a success.
|
|
173
|
+
if (!res.ok || envelope.outcome === 'failure' || result.ok === false) {
|
|
174
|
+
const base = result.error ?? text ?? 'push failed';
|
|
175
|
+
const hint = result.callerRole === 'anonymous'
|
|
176
|
+
? 'the key was not recognised — run `oneie auth login`, or set ONE_API_KEY to a world key (it starts `one-` or `osk_`)'
|
|
177
|
+
: result.error === 'forbidden'
|
|
178
|
+
? `the key is valid but does not control workspace "${opts.slug}"`
|
|
179
|
+
: undefined;
|
|
180
|
+
out(cmd, { ok: false, status: res.status, error: hint ? `${base} — ${hint}` : base });
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
out(cmd, { ok: true, name: result.name ?? name, slug: opts.slug, bytes: result.bytes ?? content.length });
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
out(cmd, { ok: false, error: err.message });
|
|
187
|
+
}
|
|
188
|
+
});
|
|
115
189
|
cmd.command('fork <name>')
|
|
116
190
|
.description('Copy an open skill into a workspace (refuses sealed — invoke-only)')
|
|
117
191
|
.requiredOption('--slug <slug>', 'Workspace slug')
|
|
@@ -123,7 +197,7 @@ export function skillCmd() {
|
|
|
123
197
|
out(cmd, { ok: false, error: 'no API key — run `oneie auth login`' });
|
|
124
198
|
return;
|
|
125
199
|
}
|
|
126
|
-
const token =
|
|
200
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
127
201
|
try {
|
|
128
202
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/skills/workspace?slug=${encodeURIComponent(opts.slug)}`, {
|
|
129
203
|
headers: { Authorization: `Bearer ${token}` },
|
|
@@ -159,7 +233,7 @@ export function skillCmd() {
|
|
|
159
233
|
out(cmd, { ok: false, error: 'no API key — run `oneie auth login`' });
|
|
160
234
|
return;
|
|
161
235
|
}
|
|
162
|
-
const token =
|
|
236
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
163
237
|
try {
|
|
164
238
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/skills/workspace?slug=${encodeURIComponent(opts.slug)}`, {
|
|
165
239
|
headers: { Authorization: `Bearer ${token}` },
|
|
@@ -186,7 +260,7 @@ export function skillCmd() {
|
|
|
186
260
|
out(cmd, { ok: false, error: 'no API key — run `oneie auth login`' });
|
|
187
261
|
return;
|
|
188
262
|
}
|
|
189
|
-
const token =
|
|
263
|
+
const token = key; // PLAIN key: requireAuth resolves a world key by `one-`/`osk_` PREFIX; a `slug:` prefix breaks it
|
|
190
264
|
try {
|
|
191
265
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/skill/${encodeURIComponent(name)}?slug=${encodeURIComponent(opts.slug)}`, {
|
|
192
266
|
method: 'DELETE',
|
|
@@ -276,15 +350,17 @@ export function skillCmd() {
|
|
|
276
350
|
const content = readFileSync(path, 'utf8');
|
|
277
351
|
const parsed = parseSkill(content, { pathStem: basename(path, '.md') });
|
|
278
352
|
const skillName = typeof parsed.meta.name === 'string' ? parsed.meta.name : basename(path, '.md');
|
|
279
|
-
|
|
353
|
+
// Frontmatter is canonical when present; otherwise fall back to the bank.
|
|
354
|
+
const frontmatterEvals = extractEvals(content);
|
|
355
|
+
const evals = frontmatterEvals.length ? frontmatterEvals : readSidecarEvals(path);
|
|
280
356
|
if (!evals.length) {
|
|
281
|
-
out(cmd, { ok: false, error:
|
|
357
|
+
out(cmd, { ok: false, error: `no evals for ${skillName} — add an evals: block to the frontmatter, or an evals/evals.json bank beside it (see \`oneie skill new\`)` });
|
|
282
358
|
return;
|
|
283
359
|
}
|
|
284
360
|
try {
|
|
285
361
|
const res = await fetch(`${opts.api.replace(/\/$/, '')}/api/eval`, {
|
|
286
362
|
method: 'POST',
|
|
287
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${
|
|
363
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${token}` },
|
|
288
364
|
body: JSON.stringify({ slug: opts.slug, skillPath: skillName, iteration: Number(opts.iteration), draftContent: content, draftEvals: evals }),
|
|
289
365
|
});
|
|
290
366
|
const data = await res.json().catch(() => ({}));
|
|
@@ -310,6 +386,46 @@ export function skillCmd() {
|
|
|
310
386
|
});
|
|
311
387
|
return cmd;
|
|
312
388
|
}
|
|
389
|
+
/**
|
|
390
|
+
* Evals live in two places and only one of them was ever read here:
|
|
391
|
+
* 1. an `evals:` block in SKILL.md frontmatter
|
|
392
|
+
* 2. a sibling `evals/evals.json` bank
|
|
393
|
+
* Every shipped skill uses (2) — measured 51 sidecar banks and 0 frontmatter
|
|
394
|
+
* blocks under one.ie/ai/skills — so `skill eval` refused every real skill with
|
|
395
|
+
* "no evals found in frontmatter". The server already reads both
|
|
396
|
+
* (pages/api/eval.ts), so this only brings the CLI's local read in line.
|
|
397
|
+
*
|
|
398
|
+
* The bank is either a bare array or `{ skill_name, evals: [...] }`, and its
|
|
399
|
+
* cases say `expected_output` where TestCase says `expected`. Normalise both.
|
|
400
|
+
*/
|
|
401
|
+
function readSidecarEvals(skillPath) {
|
|
402
|
+
const dir = skillPath.endsWith('.md') ? resolve(skillPath, '..') : skillPath;
|
|
403
|
+
const bank = join(dir, 'evals', 'evals.json');
|
|
404
|
+
if (!existsSync(bank))
|
|
405
|
+
return [];
|
|
406
|
+
try {
|
|
407
|
+
const raw = JSON.parse(readFileSync(bank, 'utf8'));
|
|
408
|
+
const list = Array.isArray(raw)
|
|
409
|
+
? raw
|
|
410
|
+
: Array.isArray(raw.evals)
|
|
411
|
+
? raw.evals
|
|
412
|
+
: [];
|
|
413
|
+
return list
|
|
414
|
+
.map((c, i) => {
|
|
415
|
+
const o = c;
|
|
416
|
+
return {
|
|
417
|
+
id: o.id === undefined ? `case-${i + 1}` : String(o.id),
|
|
418
|
+
prompt: typeof o.prompt === 'string' ? o.prompt : '',
|
|
419
|
+
expected: String(o.expected ?? o.expected_output ?? ''),
|
|
420
|
+
assertions: Array.isArray(o.assertions) ? o.assertions.map(String) : [],
|
|
421
|
+
};
|
|
422
|
+
})
|
|
423
|
+
.filter(c => c.prompt && c.assertions.length > 0);
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
return [];
|
|
427
|
+
}
|
|
428
|
+
}
|
|
313
429
|
// Mirrors one.ie/web/src/lib/eval/evals-source.ts and packages/mcp/src/tools/lifecycle.ts
|
|
314
430
|
function extractEvals(content) {
|
|
315
431
|
const fm = content.match(/^---\n([\s\S]*?)\n---/)?.[1];
|
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,6 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { mergeEnv } from './env.js';
|
|
3
3
|
import { writeFileSync, chmodSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
4
5
|
import { generateWallet, recoverWallet } from '@oneie/sdk/wallet';
|
|
5
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';
|
|
@@ -147,6 +148,46 @@ export function walletCmd() {
|
|
|
147
148
|
});
|
|
148
149
|
out(cmd, okWrap(result));
|
|
149
150
|
});
|
|
151
|
+
cmd.command('register')
|
|
152
|
+
.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')
|
|
153
|
+
.option('--from <file>', 'A `wallet keygen --out` file (or any JSON with `addresses` / `keys`) — only the address fields are read')
|
|
154
|
+
.option('--addresses <json>', 'Inline JSON address map, e.g. \'{"sui":"0x…","evm":"0x…"}\'')
|
|
155
|
+
.option('--workspace <slug>', 'Workspace (defaults to AGENCY_SLUG)')
|
|
156
|
+
.option('--actor <id>', 'Actor to register for (defaults to workspace)')
|
|
157
|
+
.option('--kind <kind>', 'human | agent', 'human')
|
|
158
|
+
.option('--yes', 'Skip the confirmation prompt (for scripted provisioning)')
|
|
159
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
160
|
+
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
161
|
+
.action(async (opts) => {
|
|
162
|
+
const { base, key } = resolveAuth(opts);
|
|
163
|
+
const workspace = resolveWorkspace(opts.workspace);
|
|
164
|
+
const source = opts.from
|
|
165
|
+
? JSON.parse(readFileSync(opts.from, 'utf8'))
|
|
166
|
+
: opts.addresses
|
|
167
|
+
? JSON.parse(opts.addresses)
|
|
168
|
+
: (() => { throw new Error('register needs --from <file> or --addresses <json>'); })();
|
|
169
|
+
const addresses = addressesOnly(source);
|
|
170
|
+
if (Object.keys(addresses).length === 0) {
|
|
171
|
+
throw new Error('no addresses found — expected an `addresses` map or a `keys` array of { chain, address }');
|
|
172
|
+
}
|
|
173
|
+
// mergeAddresses is FIRST-WRITE-WINS: a wrong address here is where every future
|
|
174
|
+
// payment lands, and the row refuses to change it afterwards (address_conflict).
|
|
175
|
+
// So the operator reads the exact strings back before anything is sent.
|
|
176
|
+
const actor = opts.actor ?? workspace;
|
|
177
|
+
process.stderr.write(`Registering PUBLIC receiving addresses for actor '${actor}' in workspace '${workspace}':\n`);
|
|
178
|
+
for (const [chain, addr] of Object.entries(addresses)) {
|
|
179
|
+
process.stderr.write(` ${chain.padEnd(7)} ${addr}\n`);
|
|
180
|
+
}
|
|
181
|
+
process.stderr.write('This is permanent — the first address written to a chain cannot be changed.\n');
|
|
182
|
+
if (!opts.yes && !(await confirm('Register these addresses? [y/N] '))) {
|
|
183
|
+
out(cmd, { ok: false, error: 'cancelled' });
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
// `actor`, not `opts.actor` — what the operator confirmed on screen is what gets
|
|
187
|
+
// written, rather than relying on the resolver's own default to agree.
|
|
188
|
+
const result = await ask(base, key, 'wallet:create', { workspace, actor, kind: opts.kind, addresses });
|
|
189
|
+
out(cmd, okWrap(result));
|
|
190
|
+
});
|
|
150
191
|
cmd.command('keygen')
|
|
151
192
|
.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
193
|
.option('--recover', 'Recover from a 24-word BIP-39 mnemonic (ONE_WALLET_MNEMONIC env or stdin) instead of generating a fresh one')
|
|
@@ -166,6 +207,52 @@ export function walletCmd() {
|
|
|
166
207
|
});
|
|
167
208
|
return cmd;
|
|
168
209
|
}
|
|
210
|
+
// Chain-name spellings a keygen output may use -> the four columns wallet:create
|
|
211
|
+
// declares. `eth`/`sol` are the SDK's WalletChain spellings; `evm`/`solana` are the
|
|
212
|
+
// server's.
|
|
213
|
+
const REGISTER_CHAINS = {
|
|
214
|
+
sui: 'sui', evm: 'evm', eth: 'evm', ethereum: 'evm',
|
|
215
|
+
sol: 'solana', solana: 'solana', btc: 'btc', bitcoin: 'btc',
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* Reduce ANY keygen-shaped object to public receiving addresses. This is a
|
|
219
|
+
* whitelist build, never a spread or a delete-list: the returned object is
|
|
220
|
+
* constructed field-by-field from four known chain keys whose values must be
|
|
221
|
+
* strings, so a `privateKey`, `secretKey`, `mnemonic` or any other field on the
|
|
222
|
+
* input has no route into the value this command transmits. The custody
|
|
223
|
+
* invariant here is structural, not a policy the caller has to remember.
|
|
224
|
+
*/
|
|
225
|
+
export function addressesOnly(source) {
|
|
226
|
+
const addresses = {};
|
|
227
|
+
const put = (rawChain, rawAddress) => {
|
|
228
|
+
const chain = REGISTER_CHAINS[String(rawChain).toLowerCase()];
|
|
229
|
+
if (!chain || typeof rawAddress !== 'string' || !rawAddress)
|
|
230
|
+
return;
|
|
231
|
+
addresses[chain] = rawAddress;
|
|
232
|
+
};
|
|
233
|
+
const src = (source && typeof source === 'object' ? source : {});
|
|
234
|
+
const nested = (src['addresses'] && typeof src['addresses'] === 'object' ? src['addresses'] : {});
|
|
235
|
+
for (const [chain, value] of Object.entries(src))
|
|
236
|
+
put(chain, value);
|
|
237
|
+
for (const [chain, value] of Object.entries(nested))
|
|
238
|
+
put(chain, value);
|
|
239
|
+
for (const k of (Array.isArray(src['keys']) ? src['keys'] : [])) {
|
|
240
|
+
put(k?.['chain'], k?.['address']);
|
|
241
|
+
}
|
|
242
|
+
return addresses;
|
|
243
|
+
}
|
|
244
|
+
// Ask the operator on the terminal. Used only for the permanent, first-write-wins
|
|
245
|
+
// address registration — every other verb is non-destructive.
|
|
246
|
+
async function confirm(prompt) {
|
|
247
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
248
|
+
try {
|
|
249
|
+
const answer = await new Promise((resolve) => rl.question(prompt, resolve));
|
|
250
|
+
return /^y(es)?$/i.test(answer.trim());
|
|
251
|
+
}
|
|
252
|
+
finally {
|
|
253
|
+
rl.close();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
169
256
|
// Read the recovery mnemonic for `keygen --recover`: ONE_WALLET_MNEMONIC env first
|
|
170
257
|
// (scriptable), else stdin (fd 0). Never a CLI arg — keeps the phrase out of the
|
|
171
258
|
// process table / shell history.
|
package/dist/src/workflow.js
CHANGED
|
@@ -6,6 +6,9 @@ import { askPath } from './lib/api-path.js';
|
|
|
6
6
|
const DEFAULT_API = 'https://api.one.ie';
|
|
7
7
|
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
8
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;
|
|
9
12
|
if (process.env.ONEIE_API_KEY)
|
|
10
13
|
return process.env.ONEIE_API_KEY;
|
|
11
14
|
if (existsSync(KEY_FILE))
|
|
@@ -22,14 +25,30 @@ export function workflowCmd() {
|
|
|
22
25
|
const key = readApiKey();
|
|
23
26
|
if (!key)
|
|
24
27
|
return { ok: false, error: 'no API key — run `oneie auth login --key <key>` or set ONEIE_API_KEY' };
|
|
25
|
-
const url =
|
|
28
|
+
const url = askPath(api.replace(/\/$/, ''), receiver);
|
|
26
29
|
const res = await fetch(url, {
|
|
27
30
|
method: 'POST',
|
|
28
|
-
|
|
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}` },
|
|
29
35
|
body: JSON.stringify({ data }),
|
|
30
36
|
});
|
|
31
37
|
const text = await res.text();
|
|
32
|
-
|
|
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;
|
|
33
52
|
};
|
|
34
53
|
cmd.command('list')
|
|
35
54
|
.description('List workflows in a workspace')
|