@oneie/cli 0.9.0 → 0.10.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/dist/package.json +1 -1
- package/dist/src/index.js +2 -0
- package/dist/src/onboard.d.ts +16 -0
- package/dist/src/onboard.js +146 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import { createCmd } from './create.js';
|
|
|
27
27
|
import { fnCmd } from './fn.js';
|
|
28
28
|
import { trailCmd } from './trail.js';
|
|
29
29
|
import { initCmd } from './init.js';
|
|
30
|
+
import { onboardCmd } from './onboard.js';
|
|
30
31
|
import { pluginCmd } from './plugin.js';
|
|
31
32
|
import { readFileSync } from 'node:fs';
|
|
32
33
|
import { fileURLToPath } from 'node:url';
|
|
@@ -66,6 +67,7 @@ program.addCommand(createCmd());
|
|
|
66
67
|
program.addCommand(fnCmd());
|
|
67
68
|
program.addCommand(trailCmd());
|
|
68
69
|
program.addCommand(initCmd());
|
|
70
|
+
program.addCommand(onboardCmd());
|
|
69
71
|
program.addCommand(pluginCmd());
|
|
70
72
|
program.parseAsync(process.argv).catch((err) => {
|
|
71
73
|
const isJson = process.argv.includes('--json');
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oneie onboard — deterministically walk a fresh agent through the platform's
|
|
3
|
+
* agent-onboarding lifecycle (text/agent-onboarding-lifecycle.md): registered
|
|
4
|
+
* → bootstrapped → active → settled → adopted.
|
|
5
|
+
*
|
|
6
|
+
* Reuses the same zero-to-live call `one init` uses (POST /api/provision/agent)
|
|
7
|
+
* for register+bootstrap — both stages are tracked server-side automatically
|
|
8
|
+
* (no extra calls from here). Adds the read-back + guide layer `init` doesn't:
|
|
9
|
+
* after provisioning, reads the real stage_transition log via lifecycle:mine
|
|
10
|
+
* and tells the agent exactly what unlocks each remaining stage.
|
|
11
|
+
*
|
|
12
|
+
* Idempotent: if this directory already has ONE_API_KEY, skips provisioning
|
|
13
|
+
* and just reports current lifecycle position.
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
export declare function onboardCmd(): Command;
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* oneie onboard — deterministically walk a fresh agent through the platform's
|
|
3
|
+
* agent-onboarding lifecycle (text/agent-onboarding-lifecycle.md): registered
|
|
4
|
+
* → bootstrapped → active → settled → adopted.
|
|
5
|
+
*
|
|
6
|
+
* Reuses the same zero-to-live call `one init` uses (POST /api/provision/agent)
|
|
7
|
+
* for register+bootstrap — both stages are tracked server-side automatically
|
|
8
|
+
* (no extra calls from here). Adds the read-back + guide layer `init` doesn't:
|
|
9
|
+
* after provisioning, reads the real stage_transition log via lifecycle:mine
|
|
10
|
+
* and tells the agent exactly what unlocks each remaining stage.
|
|
11
|
+
*
|
|
12
|
+
* Idempotent: if this directory already has ONE_API_KEY, skips provisioning
|
|
13
|
+
* and just reports current lifecycle position.
|
|
14
|
+
*/
|
|
15
|
+
import { Command } from 'commander';
|
|
16
|
+
import { writeFileSync, mkdirSync, renameSync, chmodSync } from 'node:fs';
|
|
17
|
+
import { resolve, join } from 'node:path';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
import { mergeEnv, writeEnvLocal } from './env.js';
|
|
20
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://one.ie';
|
|
21
|
+
const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
|
|
22
|
+
const KEY_FILE = resolve(CONFIG_DIR, 'key');
|
|
23
|
+
function writeKey(value) {
|
|
24
|
+
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
25
|
+
const tmp = join(CONFIG_DIR, '.key.tmp');
|
|
26
|
+
writeFileSync(tmp, value, { mode: 0o600 });
|
|
27
|
+
chmodSync(tmp, 0o600);
|
|
28
|
+
renameSync(tmp, KEY_FILE);
|
|
29
|
+
}
|
|
30
|
+
async function ask(base, key, receiver, data) {
|
|
31
|
+
const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
|
|
32
|
+
method: 'POST',
|
|
33
|
+
headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
34
|
+
body: JSON.stringify({ data }),
|
|
35
|
+
});
|
|
36
|
+
const json = (await res.json().catch(() => ({})));
|
|
37
|
+
if (!res.ok)
|
|
38
|
+
throw new Error(`${receiver} → ${res.status}: ${JSON.stringify(json)}`);
|
|
39
|
+
return json;
|
|
40
|
+
}
|
|
41
|
+
// The 5 stages, in order, and what unlocks each one — mirrors
|
|
42
|
+
// SEED_DEFS['agent-onboarding'] in one.ie/web/src/lib/lifecycle/seed.ts.
|
|
43
|
+
// Kept here as plain data (not fetched) so `onboard` works even before the
|
|
44
|
+
// agent has a key to call the substrate with.
|
|
45
|
+
const STAGE_GUIDE = {
|
|
46
|
+
registered: 'done — your identity exists (uid + apiKey minted).',
|
|
47
|
+
bootstrapped: 'done — your own workspace exists (gid + aid + scopedKey minted).',
|
|
48
|
+
active: 'publish a capability or place a market offer: `one agent publish` or `one trade market`.',
|
|
49
|
+
settled: 'complete a sale: `one trade hire` (as a buyer) or accept + settle an offer (as the seller).',
|
|
50
|
+
adopted: 'get adopted by another workspace — accept an invite, or have your capability hired long-term.',
|
|
51
|
+
};
|
|
52
|
+
const STAGE_ORDER = ['registered', 'bootstrapped', 'active', 'settled', 'adopted'];
|
|
53
|
+
function out(cmd, data) {
|
|
54
|
+
const isJson = cmd.parent?.opts().json;
|
|
55
|
+
if (isJson) {
|
|
56
|
+
process.stdout.write(JSON.stringify(data) + '\n');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (data.ok === false) {
|
|
60
|
+
process.stderr.write(`✗ ${data.error ?? 'failed'}\n`);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const stages = data.stages ?? [];
|
|
64
|
+
process.stdout.write(`✓ onboarded as ${data.uid ?? '?'}\n`);
|
|
65
|
+
process.stdout.write(` workspace: ${data.workspace ?? '?'}\n`);
|
|
66
|
+
process.stdout.write(` url: ${data.url ?? '?'}\n\n`);
|
|
67
|
+
process.stdout.write(' lifecycle: register → bootstrap → active → settled → adopted\n');
|
|
68
|
+
for (const s of stages) {
|
|
69
|
+
process.stdout.write(` ${s.done ? '✓' : '·'} ${s.id.padEnd(12)} ${s.guide}\n`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export function onboardCmd() {
|
|
73
|
+
const cmd = new Command('onboard')
|
|
74
|
+
.description('Zero-to-live onboarding + a deterministic guide through the agent lifecycle')
|
|
75
|
+
.option('--name <name>', 'Workspace / agent display name')
|
|
76
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
77
|
+
.option('--write-env', 'Also write ONE_API_KEY to .env.local in the current directory', true)
|
|
78
|
+
.action(async (opts) => {
|
|
79
|
+
const dir = process.cwd();
|
|
80
|
+
const base = opts.api.replace(/\/$/, '');
|
|
81
|
+
const env = mergeEnv(dir);
|
|
82
|
+
let apiKey = env.ONE_API_KEY ?? env.ONEIE_API_KEY ?? '';
|
|
83
|
+
// regKey is the uid-bound registration key — distinct from apiKey (the
|
|
84
|
+
// workspace-scoped key `apiKey` resolves to). lifecycle:mine and any
|
|
85
|
+
// other uid-scoped receiver need THIS key: ctx.ownerSlug from `apiKey`
|
|
86
|
+
// resolves to the workspace's aid, which has zero stage_transition rows.
|
|
87
|
+
let regKey = env.ONE_REG_KEY ?? '';
|
|
88
|
+
let uid = env.ONE_UID ?? '';
|
|
89
|
+
let workspace = env.AGENCY_WSID ?? env.AGENCY_SLUG ?? '';
|
|
90
|
+
if (!apiKey) {
|
|
91
|
+
// Register + bootstrap in one call — the same zero-to-live path `one
|
|
92
|
+
// init` uses, POST /api/provision/agent. Both stages are tracked
|
|
93
|
+
// server-side the moment this call lands; nothing extra to do here.
|
|
94
|
+
const res = await fetch(`${base}/api/provision/agent`, {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
headers: { 'Content-Type': 'application/json' },
|
|
97
|
+
body: JSON.stringify({ name: opts.name ?? 'My Agent', live: true }),
|
|
98
|
+
});
|
|
99
|
+
const json = (await res.json().catch(() => ({})));
|
|
100
|
+
if (!res.ok || !json.apiKey) {
|
|
101
|
+
out(cmd, { ok: false, error: json.error ?? `provision failed (${res.status})` });
|
|
102
|
+
process.exitCode = 1;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
uid = String(json.uid);
|
|
106
|
+
workspace = String(json.workspace);
|
|
107
|
+
apiKey = json.apiKey;
|
|
108
|
+
regKey = json.regKey ?? '';
|
|
109
|
+
writeKey(apiKey);
|
|
110
|
+
if (opts.writeEnv) {
|
|
111
|
+
writeEnvLocal(dir, { ONE_API_KEY: apiKey, ONE_API_URL: base, ONE_REG_KEY: regKey, ONE_UID: uid, AGENCY_WSID: workspace });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Read back the real stage_transition log — the deterministic proof,
|
|
115
|
+
// not an assertion this command makes up. lifecycle:mine is self-scoped
|
|
116
|
+
// (entity_id = the caller's own uid, attested by the bearer key) —
|
|
117
|
+
// MUST be called with regKey, not apiKey (see note above).
|
|
118
|
+
const reached = new Set();
|
|
119
|
+
if (regKey) {
|
|
120
|
+
try {
|
|
121
|
+
const mine = await ask(base, regKey, 'lifecycle:mine', {});
|
|
122
|
+
const rows = (mine.result?.rows) ?? [];
|
|
123
|
+
for (const r of rows)
|
|
124
|
+
reached.add(r.to_stage);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
// lifecycle:mine itself failing (e.g. no DB in a local dev target)
|
|
128
|
+
// must never block reporting what we already know from provisioning.
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (uid) {
|
|
132
|
+
reached.add('registered');
|
|
133
|
+
reached.add('bootstrapped');
|
|
134
|
+
}
|
|
135
|
+
const stages = STAGE_ORDER.map((id) => ({ id, done: reached.has(id), guide: STAGE_GUIDE[id] }));
|
|
136
|
+
out(cmd, {
|
|
137
|
+
ok: true,
|
|
138
|
+
uid: uid || '(unknown — no ONE_UID in env; re-run in a fresh dir to see it)',
|
|
139
|
+
workspace,
|
|
140
|
+
url: workspace ? `${base}/u/${workspace}` : base,
|
|
141
|
+
key: `${KEY_FILE} (0600)`,
|
|
142
|
+
stages,
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
return cmd;
|
|
146
|
+
}
|