@oneie/cli 0.4.0 → 0.5.1

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.
Files changed (46) hide show
  1. package/LICENSE +86 -0
  2. package/dist/src/agent.js +6 -2
  3. package/dist/src/args.d.ts +9 -0
  4. package/dist/src/args.js +61 -0
  5. package/dist/src/catalog.d.ts +1 -2
  6. package/dist/src/catalog.js +65 -36
  7. package/dist/src/client.d.ts +0 -1
  8. package/dist/src/client.js +71 -169
  9. package/dist/src/compiler.d.ts +15 -19
  10. package/dist/src/compiler.js +170 -219
  11. package/dist/src/config.d.ts +24 -0
  12. package/dist/src/config.js +70 -0
  13. package/dist/src/coordinate.d.ts +2 -2
  14. package/dist/src/coordinate.js +47 -61
  15. package/dist/src/create.d.ts +2 -0
  16. package/dist/src/create.js +231 -0
  17. package/dist/src/deploy.d.ts +0 -1
  18. package/dist/src/deploy.js +8 -35
  19. package/dist/src/env.d.ts +3 -6
  20. package/dist/src/env.js +31 -24
  21. package/dist/src/fn.d.ts +2 -0
  22. package/dist/src/fn.js +73 -0
  23. package/dist/src/index.js +18 -8
  24. package/dist/src/init.d.ts +11 -0
  25. package/dist/src/init.js +107 -0
  26. package/dist/src/links.d.ts +5 -0
  27. package/dist/src/links.js +50 -0
  28. package/dist/src/push.d.ts +0 -1
  29. package/dist/src/push.js +44 -99
  30. package/dist/src/render.d.ts +17 -0
  31. package/dist/src/render.js +25 -0
  32. package/dist/src/setup.d.ts +0 -1
  33. package/dist/src/setup.js +47 -134
  34. package/dist/src/ship.d.ts +0 -1
  35. package/dist/src/ship.js +13 -36
  36. package/dist/src/slug.d.ts +2 -5
  37. package/dist/src/slug.js +4 -7
  38. package/dist/src/status.d.ts +0 -1
  39. package/dist/src/status.js +29 -42
  40. package/dist/src/trade.d.ts +1 -2
  41. package/dist/src/trade.js +71 -74
  42. package/dist/src/trail.d.ts +2 -0
  43. package/dist/src/trail.js +47 -0
  44. package/dist/src/validate.d.ts +11 -10
  45. package/dist/src/validate.js +32 -34
  46. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function createCmd(): Command;
@@ -0,0 +1,231 @@
1
+ import { Command } from 'commander';
2
+ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync, existsSync } from 'node:fs';
3
+ import { resolve, join } from 'node:path';
4
+ import { spawnSync } from 'node:child_process';
5
+ import { tmpdir } from 'node:os';
6
+ const SAFE_REF = /^[A-Za-z0-9._/-]+$/;
7
+ function downloadTarball(url, targetDir) {
8
+ mkdirSync(targetDir, { recursive: true });
9
+ // No shell — pipe curl stdout directly into tar stdin as a buffer
10
+ const curl = spawnSync('curl', ['-fsSL', '--location', url], {
11
+ maxBuffer: 512 * 1024 * 1024,
12
+ stdio: ['ignore', 'pipe', 'inherit'],
13
+ });
14
+ if (curl.status !== 0 || !curl.stdout)
15
+ throw new Error(`curl failed: ${url}`);
16
+ const tar = spawnSync('tar', ['-xz', '--strip-components=1', '-C', targetDir], {
17
+ input: curl.stdout,
18
+ stdio: ['pipe', 'inherit', 'inherit'],
19
+ });
20
+ if (tar.status !== 0)
21
+ throw new Error(`tar failed extracting to ${targetDir}`);
22
+ }
23
+ function downloadSubdir(url, subdir, targetDir) {
24
+ const tmp = mkdtempSync(join(tmpdir(), 'one-create-'));
25
+ try {
26
+ downloadTarball(url, tmp);
27
+ mkdirSync(targetDir, { recursive: true });
28
+ const r = spawnSync('cp', ['-r', join(tmp, subdir, '.'), targetDir], { stdio: 'inherit' });
29
+ if (r.status !== 0)
30
+ throw new Error('cp failed');
31
+ }
32
+ finally {
33
+ spawnSync('rm', ['-rf', tmp]);
34
+ }
35
+ }
36
+ export function createCmd() {
37
+ const cmd = new Command('create').description('Scaffold a new ONE node or site');
38
+ // ── one create agency [name] ──────────────────────────────────────────────
39
+ cmd
40
+ .command('agency [name]')
41
+ .description('Scaffold a new agency node from github.com/one-ie/oo')
42
+ .option('--ref <ref>', 'Git ref to download', 'main')
43
+ .option('--slug <slug>', 'Your agency slug (written into agency.toml)')
44
+ .option('--name <name>', 'Your agency display name (written into agency.toml)')
45
+ .action((dirName, opts) => {
46
+ if (!SAFE_REF.test(opts.ref)) {
47
+ process.stderr.write(`Invalid ref: ${opts.ref}\n`);
48
+ process.exit(1);
49
+ }
50
+ const label = dirName ?? opts.slug ?? 'my-agency';
51
+ const dir = resolve(process.cwd(), label);
52
+ if (existsSync(dir)) {
53
+ process.stderr.write(`Directory already exists: ${dir}\n`);
54
+ process.exit(1);
55
+ }
56
+ process.stdout.write(`Creating agency node at ${dir}...\n`);
57
+ downloadTarball(`https://api.github.com/repos/one-ie/oo/tarball/${opts.ref}`, dir);
58
+ // Patch agency.toml with the user's slug + name so they don't have to
59
+ const tomlPath = join(dir, 'agency.toml');
60
+ if (existsSync(tomlPath) && (opts.slug ?? opts.name)) {
61
+ let toml = readFileSync(tomlPath, 'utf8');
62
+ if (opts.slug)
63
+ toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug = "${opts.slug}"`);
64
+ if (opts.name)
65
+ toml = toml.replace(/^name\s*=\s*"[^"]*"/m, `name = "${opts.name}"`);
66
+ writeFileSync(tomlPath, toml);
67
+ }
68
+ process.stdout.write(`\nAgency node created.\n\n`);
69
+ process.stdout.write(`Next steps:\n`);
70
+ process.stdout.write(` cd ${label}\n`);
71
+ process.stdout.write(` cp .env.example .env.local\n`);
72
+ process.stdout.write(` # Edit .env.local — set ONE_API_KEY and AGENCY_OWNER_EMAIL\n`);
73
+ if (!opts.slug)
74
+ process.stdout.write(` # Edit agency.toml — set slug and name\n`);
75
+ process.stdout.write(` one setup\n`);
76
+ });
77
+ // ── one create client <slug> ──────────────────────────────────────────────
78
+ cmd
79
+ .command('client <slug>')
80
+ .description('Scaffold a client node in clients/<slug>/')
81
+ .option('--name <name>', 'Display name for the client')
82
+ .option('--plan <plan>', 'Plan tier', 'studio')
83
+ .action((slug, opts) => {
84
+ const base = resolve(process.cwd(), 'clients', slug);
85
+ if (existsSync(base)) {
86
+ process.stderr.write(`Client already exists: clients/${slug}\n`);
87
+ process.exit(1);
88
+ }
89
+ const displayName = opts.name ?? slug;
90
+ mkdirSync(join(base, 'ai'), { recursive: true });
91
+ mkdirSync(join(base, 'data', 'lifecycles'), { recursive: true });
92
+ mkdirSync(join(base, 'site'), { recursive: true });
93
+ writeFileSync(join(base, 'ai', 'context.md'), `# ${displayName}\n\nAdd company context here — agents read this on every turn.\n`);
94
+ writeFileSync(join(base, 'site', 'one.config.ts'), [
95
+ `import { defineOne } from '@oneie/frontend'`,
96
+ ``,
97
+ `export default defineOne({`,
98
+ ` backend: { baseUrl: 'https://one.ie' },`,
99
+ ` brand: {`,
100
+ ` tokens: {`,
101
+ ` primary: 'hsl(216 55% 25%)',`,
102
+ ` secondary: 'hsl(219 14% 28%)',`,
103
+ ` tertiary: 'hsl(105 22% 25%)',`,
104
+ ` background: 'hsl(0 0% 93%)',`,
105
+ ` foreground: 'hsl(0 0% 100%)',`,
106
+ ` font: 'hsl(0 0% 13%)',`,
107
+ ` },`,
108
+ ` },`,
109
+ ` plugins: [`,
110
+ ` // auth(),`,
111
+ ` // track({ ws: '${slug}' }),`,
112
+ ` // chat({ agent: 'your-agent' }),`,
113
+ ` ],`,
114
+ `})`,
115
+ ].join('\n') + '\n');
116
+ writeFileSync(join(base, 'client.toml'), [
117
+ `slug = "${slug}"`,
118
+ `name = "${displayName}"`,
119
+ `plan = "${opts.plan}"`,
120
+ ``,
121
+ `# markup_pct = 15 # override agency default`,
122
+ `# monthly_cap = 50000`,
123
+ ].join('\n') + '\n');
124
+ process.stdout.write(`Client node scaffolded: clients/${slug}/\n`);
125
+ process.stdout.write(` ai/context.md — add company context\n`);
126
+ process.stdout.write(` site/one.config.ts — brand tokens (6 tokens rebrand the site)\n`);
127
+ process.stdout.write(` client.toml — plan + economics\n\n`);
128
+ process.stdout.write(`Next: one client add ${slug} [--dry-run]\n`);
129
+ });
130
+ // ── one create partner [name] ────────────────────────────────────────────
131
+ cmd
132
+ .command('partner [name]')
133
+ .description('Scaffold a new partner node from github.com/one-ie/partner')
134
+ .option('--ref <ref>', 'Git ref to download', 'main')
135
+ .option('--slug <slug>', 'Your partner slug (written into partner.toml)')
136
+ .option('--name <name>', 'Your display name (written into partner.toml)')
137
+ .action((dirName, opts) => {
138
+ if (!SAFE_REF.test(opts.ref)) {
139
+ process.stderr.write(`Invalid ref: ${opts.ref}\n`);
140
+ process.exit(1);
141
+ }
142
+ const label = dirName ?? opts.slug ?? 'my-partner';
143
+ const dir = resolve(process.cwd(), label);
144
+ if (existsSync(dir)) {
145
+ process.stderr.write(`Directory already exists: ${dir}\n`);
146
+ process.exit(1);
147
+ }
148
+ process.stdout.write(`Creating partner node at ${dir}...\n`);
149
+ downloadTarball(`https://api.github.com/repos/one-ie/partner/tarball/${opts.ref}`, dir);
150
+ const tomlPath = join(dir, 'partner.toml');
151
+ if (existsSync(tomlPath) && (opts.slug ?? opts.name)) {
152
+ let toml = readFileSync(tomlPath, 'utf8');
153
+ if (opts.slug)
154
+ toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug = "${opts.slug}"`);
155
+ if (opts.name)
156
+ toml = toml.replace(/^name\s*=\s*"[^"]*"/m, `name = "${opts.name}"`);
157
+ writeFileSync(tomlPath, toml);
158
+ }
159
+ process.stdout.write(`\nPartner node created.\n\n`);
160
+ process.stdout.write(`Next steps:\n`);
161
+ process.stdout.write(` cd ${label}\n`);
162
+ process.stdout.write(` cp .env.example .env.local\n`);
163
+ process.stdout.write(` # Edit .env.local — set ONE_API_KEY\n`);
164
+ if (!opts.slug)
165
+ process.stdout.write(` # Edit partner.toml — set slug and name\n`);
166
+ process.stdout.write(` one setup\n`);
167
+ });
168
+ // ── one create client-repo [name] ───────────────────────────────────────
169
+ cmd
170
+ .command('client-repo [name]')
171
+ .description('Scaffold a single-business workspace from github.com/one-ie/client')
172
+ .option('--ref <ref>', 'Git ref to download', 'main')
173
+ .option('--slug <slug>', 'Workspace slug (written into workspace.toml)')
174
+ .option('--name <name>', 'Display name (written into workspace.toml)')
175
+ .action((dirName, opts) => {
176
+ if (!SAFE_REF.test(opts.ref)) {
177
+ process.stderr.write(`Invalid ref: ${opts.ref}\n`);
178
+ process.exit(1);
179
+ }
180
+ const label = dirName ?? opts.slug ?? 'my-business';
181
+ const dir = resolve(process.cwd(), label);
182
+ if (existsSync(dir)) {
183
+ process.stderr.write(`Directory already exists: ${dir}\n`);
184
+ process.exit(1);
185
+ }
186
+ process.stdout.write(`Creating client workspace at ${dir}...\n`);
187
+ downloadTarball(`https://api.github.com/repos/one-ie/client/tarball/${opts.ref}`, dir);
188
+ const tomlPath = join(dir, 'workspace.toml');
189
+ if (existsSync(tomlPath) && (opts.slug ?? opts.name)) {
190
+ let toml = readFileSync(tomlPath, 'utf8');
191
+ if (opts.slug)
192
+ toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug = "${opts.slug}"`);
193
+ if (opts.name)
194
+ toml = toml.replace(/^name\s*=\s*"[^"]*"/m, `name = "${opts.name}"`);
195
+ writeFileSync(tomlPath, toml);
196
+ }
197
+ process.stdout.write(`\nWorkspace created.\n\n`);
198
+ process.stdout.write(`Next steps:\n`);
199
+ process.stdout.write(` cd ${label}\n`);
200
+ process.stdout.write(` cp .env.example .env.local\n`);
201
+ process.stdout.write(` # Edit .env.local — set ONE_API_KEY\n`);
202
+ if (!opts.slug)
203
+ process.stdout.write(` # Edit workspace.toml — set slug and name\n`);
204
+ process.stdout.write(` one setup\n`);
205
+ });
206
+ // ── one create site [name] ────────────────────────────────────────────────
207
+ cmd
208
+ .command('site [name]')
209
+ .description('Scaffold a standalone ONE Astro site from github.com/one-ie/one')
210
+ .option('--ref <ref>', 'Git ref to download', 'main')
211
+ .action((name, opts) => {
212
+ if (!SAFE_REF.test(opts.ref)) {
213
+ process.stderr.write(`Invalid ref: ${opts.ref}\n`);
214
+ process.exit(1);
215
+ }
216
+ const dir = resolve(process.cwd(), name ?? 'my-site');
217
+ if (existsSync(dir)) {
218
+ process.stderr.write(`Directory already exists: ${dir}\n`);
219
+ process.exit(1);
220
+ }
221
+ process.stdout.write(`Creating site at ${dir}...\n`);
222
+ downloadSubdir(`https://api.github.com/repos/one-ie/one/tarball/${opts.ref}`, 'apps/web', dir);
223
+ const label = name ?? 'my-site';
224
+ process.stdout.write(`\nSite created.\n\n`);
225
+ process.stdout.write(`Next steps:\n`);
226
+ process.stdout.write(` cd ${label}\n`);
227
+ process.stdout.write(` cp .env.example .env.local\n`);
228
+ process.stdout.write(` bun install && bun run dev\n`);
229
+ });
230
+ return cmd;
231
+ }
@@ -1,3 +1,2 @@
1
- /** `one deploy [path]` — wrangler pages deploy wrapper. */
2
1
  import { Command } from 'commander';
3
2
  export declare function deployCmd(): Command;
@@ -1,46 +1,19 @@
1
- /** `one deploy [path]` — wrangler pages deploy wrapper. */
2
1
  import { Command } from 'commander';
3
2
  import { spawnSync } from 'node:child_process';
4
3
  import { existsSync } from 'node:fs';
5
- import { resolve } from 'node:path';
6
- function out(cmd, data) {
7
- const isJson = cmd.parent?.opts()?.json;
8
- if (isJson)
9
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
10
- else {
11
- const d = data;
12
- if (d['ok'])
13
- process.stdout.write(`✓ deployed\n`);
14
- else
15
- process.stderr.write(`✗ deploy failed\n`);
16
- }
17
- }
18
4
  export function deployCmd() {
19
- const cmd = new Command('deploy')
20
- .description('Deploy the site/ directory via wrangler pages deploy')
21
- .argument('[path]', 'Path to deploy (defaults to site/ in cwd)', 'site')
5
+ return new Command('deploy')
6
+ .description('Deploy site/ to Cloudflare Pages via wrangler')
7
+ .argument('[path]', 'Path to deploy (default: site/dist)')
22
8
  .option('--project <name>', 'Cloudflare Pages project name')
23
- .option('--branch <branch>', 'Git branch for the deployment')
24
- .option('--dry-run', 'Pass --dry-run to wrangler')
25
9
  .action((path, opts) => {
26
- const dir = resolve(process.cwd(), path);
27
- if (!existsSync(dir)) {
28
- process.stderr.write(`error: directory not found: ${dir}\n`);
29
- process.exit(1);
30
- }
31
- const args = ['wrangler', 'pages', 'deploy', dir];
10
+ const target = path ?? (existsSync('site/dist') ? 'site/dist' : 'dist');
11
+ const args = ['pages', 'deploy', target];
32
12
  if (opts.project)
33
13
  args.push('--project-name', opts.project);
34
- if (opts.branch)
35
- args.push('--branch', opts.branch);
36
- if (opts.dryRun)
37
- args.push('--dry-run');
38
- process.stdout.write(` deploying ${dir}…\n`);
39
- const result = spawnSync('npx', args, { stdio: 'inherit', encoding: 'utf8' });
40
- const ok = result.status === 0;
41
- out(cmd, { ok, path: dir, exit: result.status });
42
- if (!ok)
14
+ process.stdout.write(`Deploying ${target}...\n`);
15
+ const result = spawnSync('wrangler', args, { stdio: 'inherit' });
16
+ if (result.status !== 0)
43
17
  process.exit(result.status ?? 1);
44
18
  });
45
- return cmd;
46
19
  }
package/dist/src/env.d.ts CHANGED
@@ -1,6 +1,3 @@
1
- /** Read existing .env.local (or return empty map). */
2
- export declare function readEnvLocal(cwd?: string): Map<string, string>;
3
- /** Upsert key=value pairs into .env.local, preserving existing entries. */
4
- export declare function mergeEnvLocal(pairs: Record<string, string>, cwd?: string): void;
5
- /** Read a single key from .env.local, then fallback to process.env. */
6
- export declare function readSecret(key: string, cwd?: string): string;
1
+ export declare function readEnvFile(path: string): Record<string, string>;
2
+ export declare function mergeEnv(dir: string): Record<string, string>;
3
+ export declare function writeEnvLocal(dir: string, updates: Record<string, string>): void;
package/dist/src/env.js CHANGED
@@ -1,30 +1,37 @@
1
- /** Helpers for .env.local — merge secrets the compiler resolves from the environment. */
2
- import { readFileSync, writeFileSync, existsSync } from 'node:fs';
3
- import { resolve } from 'node:path';
4
- /** Read existing .env.local (or return empty map). */
5
- export function readEnvLocal(cwd = process.cwd()) {
6
- const path = resolve(cwd, '.env.local');
7
- const map = new Map();
1
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+ const LINE = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/;
3
+ export function readEnvFile(path) {
8
4
  if (!existsSync(path))
9
- return map;
10
- for (const line of readFileSync(path, 'utf8').split('\n')) {
11
- const eq = line.indexOf('=');
12
- if (eq < 1 || line.trim().startsWith('#'))
5
+ return {};
6
+ const out = {};
7
+ for (const raw of readFileSync(path, 'utf8').split('\n')) {
8
+ if (raw.trim().startsWith('#') || !raw.trim())
13
9
  continue;
14
- map.set(line.slice(0, eq).trim(), line.slice(eq + 1).trim());
10
+ const m = raw.match(LINE);
11
+ if (m)
12
+ out[m[1]] = m[2].replace(/^["']|["']$/g, '');
15
13
  }
16
- return map;
14
+ return out;
17
15
  }
18
- /** Upsert key=value pairs into .env.local, preserving existing entries. */
19
- export function mergeEnvLocal(pairs, cwd = process.cwd()) {
20
- const path = resolve(cwd, '.env.local');
21
- const map = readEnvLocal(cwd);
22
- for (const [k, v] of Object.entries(pairs))
23
- map.set(k, v);
24
- const lines = Array.from(map.entries()).map(([k, v]) => `${k}=${v}`);
25
- writeFileSync(path, lines.join('\n') + '\n', 'utf8');
16
+ function fromProcess() {
17
+ const out = {};
18
+ for (const k of ['ONE_API_URL', 'ONE_API_KEY', 'ONEIE_API_KEY', 'AGENCY_SLUG', 'AGENCY_NAME', 'AGENCY_WSID', 'CC_ACTOR_ID']) {
19
+ const v = process.env[k];
20
+ if (v)
21
+ out[k] = v;
22
+ }
23
+ return out;
24
+ }
25
+ export function mergeEnv(dir) {
26
+ return {
27
+ ...readEnvFile(`${dir}/.env`),
28
+ ...readEnvFile(`${dir}/.env.local`),
29
+ ...fromProcess(),
30
+ };
26
31
  }
27
- /** Read a single key from .env.local, then fallback to process.env. */
28
- export function readSecret(key, cwd = process.cwd()) {
29
- return readEnvLocal(cwd).get(key) ?? process.env[key] ?? '';
32
+ export function writeEnvLocal(dir, updates) {
33
+ const path = `${dir}/.env.local`;
34
+ const merged = { ...readEnvFile(path), ...updates };
35
+ const body = Object.entries(merged).map(([k, v]) => `${k}=${v}`).join('\n') + '\n';
36
+ writeFileSync(path, body, 'utf8');
30
37
  }
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function fnCmd(): Command;
package/dist/src/fn.js ADDED
@@ -0,0 +1,73 @@
1
+ import { Command } from 'commander';
2
+ import { FN_MAP, FN_MAP_VERSION } from '@oneie/sdk/generated/fn-map';
3
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
4
+ const ALLOWLIST = new Set([
5
+ 'actionable_hypotheses', 'active_frontiers', 'active_objectives',
6
+ 'actor_classification', 'actors_by_kind', 'actors_by_tag', 'actors_for',
7
+ 'attractive_tasks', 'blocked_tasks', 'cheapest_provider', 'exploratory_tasks',
8
+ 'highways', 'optimal_route', 'promising_frontiers', 'suggest_route', 'total_contribution',
9
+ ]);
10
+ function apiKey() {
11
+ return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
12
+ }
13
+ function base(opts) {
14
+ return (opts.api ?? DEFAULT_API).replace(/\/$/, '');
15
+ }
16
+ async function api(url, body) {
17
+ const h = { 'Content-Type': 'application/json' };
18
+ const k = apiKey();
19
+ if (k)
20
+ h['Authorization'] = `Bearer ${k}`;
21
+ const res = await fetch(url, { method: 'POST', headers: h, body: JSON.stringify(body) });
22
+ if (!res.ok) {
23
+ const text = await res.text().catch(() => '');
24
+ process.stderr.write(`fn:run → ${res.status}\n${text}\n`);
25
+ process.exit(1);
26
+ }
27
+ return res.json();
28
+ }
29
+ export function fnCmd() {
30
+ const cmd = new Command('fn').description(`Execute an allowlisted TypeDB function (FN_MAP v${FN_MAP_VERSION})`);
31
+ cmd
32
+ .command('list')
33
+ .description('List all allowlisted functions')
34
+ .action(() => {
35
+ const rows = Array.from(ALLOWLIST).map((name) => {
36
+ const entry = FN_MAP[name];
37
+ const params = entry?.params.map((p) => p.name).join(', ') ?? '';
38
+ return ` ${name.padEnd(28)}${params ? `(${params})` : '()'} → ${entry?.returnKind ?? '?'}`;
39
+ });
40
+ process.stdout.write(`Allowlisted functions (FN_MAP v${FN_MAP_VERSION}):\n${rows.join('\n')}\n`);
41
+ });
42
+ cmd
43
+ .command('run <name>')
44
+ .description('Execute a function by name')
45
+ .option('--args <json>', 'Function arguments as JSON object (keys without $ prefix)')
46
+ .option('--workspace <slug>', 'Workspace slug')
47
+ .option('--api <url>', 'API base URL', DEFAULT_API)
48
+ .action(async (name, opts) => {
49
+ if (!ALLOWLIST.has(name)) {
50
+ process.stderr.write(`error: '${name}' is not in the allowlist. Run 'one fn list' to see available functions.\n`);
51
+ process.exit(1);
52
+ }
53
+ let args = {};
54
+ if (opts.args) {
55
+ try {
56
+ args = JSON.parse(opts.args);
57
+ }
58
+ catch {
59
+ process.stderr.write('error: --args must be valid JSON\n');
60
+ process.exit(1);
61
+ }
62
+ }
63
+ const prefixed = {};
64
+ for (const [k, v] of Object.entries(args)) {
65
+ prefixed[k.startsWith('$') ? k : `$${k}`] = v;
66
+ }
67
+ const result = await api(`${base(opts)}/api/ask/fn%3Arun`, {
68
+ data: { fn: name, args: prefixed, workspace: opts.workspace },
69
+ });
70
+ process.stdout.write(JSON.stringify(result, null, 2) + '\n');
71
+ });
72
+ return cmd;
73
+ }
package/dist/src/index.js CHANGED
@@ -8,6 +8,7 @@ import { groupCmd } from './group.js';
8
8
  import { socialCmd } from './social.js';
9
9
  import { connectCmd } from './connect.js';
10
10
  import { broadcastCmd, newsletterCmd } from './broadcast.js';
11
+ import { linksCmd } from './links.js';
11
12
  import { staffCmd } from './staff.js';
12
13
  import { substrateCommands } from './substrate.js';
13
14
  import { evalCmd } from './eval.js';
@@ -17,14 +18,18 @@ import { pushCmd } from './push.js';
17
18
  import { deployCmd } from './deploy.js';
18
19
  import { statusCmd } from './status.js';
19
20
  import { shipCmd } from './ship.js';
20
- import { catalogCmd } from './catalog.js';
21
- import { tradeCmd } from './trade.js';
22
- import { coordinateCmd } from './coordinate.js';
21
+ import { catalogCommands } from './catalog.js';
22
+ import { tradeCommands } from './trade.js';
23
+ import { coordinateCommands } from './coordinate.js';
24
+ import { createCmd } from './create.js';
25
+ import { fnCmd } from './fn.js';
26
+ import { trailCmd } from './trail.js';
27
+ import { initCmd } from './init.js';
23
28
  import { readFileSync } from 'node:fs';
24
29
  import { fileURLToPath } from 'node:url';
25
30
  import { resolve, dirname } from 'node:path';
26
31
  const __dirname = dirname(fileURLToPath(import.meta.url));
27
- const pkg = JSON.parse(readFileSync(resolve(__dirname, '../../package.json'), 'utf8'));
32
+ const pkg = JSON.parse(readFileSync(resolve(__dirname, '../package.json'), 'utf8'));
28
33
  const program = new Command()
29
34
  .name('oneie')
30
35
  .description('ONE — agent CLI')
@@ -39,18 +44,23 @@ program.addCommand(socialCmd());
39
44
  program.addCommand(connectCmd());
40
45
  program.addCommand(broadcastCmd());
41
46
  program.addCommand(newsletterCmd());
47
+ program.addCommand(linksCmd());
42
48
  program.addCommand(staffCmd());
43
49
  program.addCommand(evalCmd());
44
- substrateCommands(program);
45
50
  program.addCommand(setupCmd());
46
51
  program.addCommand(clientCmd());
47
52
  program.addCommand(pushCmd());
48
53
  program.addCommand(deployCmd());
49
54
  program.addCommand(statusCmd());
50
55
  program.addCommand(shipCmd());
51
- program.addCommand(catalogCmd());
52
- program.addCommand(tradeCmd());
53
- program.addCommand(coordinateCmd());
56
+ catalogCommands(program);
57
+ tradeCommands(program);
58
+ coordinateCommands(program);
59
+ substrateCommands(program);
60
+ program.addCommand(createCmd());
61
+ program.addCommand(fnCmd());
62
+ program.addCommand(trailCmd());
63
+ program.addCommand(initCmd());
54
64
  program.parseAsync(process.argv).catch((err) => {
55
65
  const isJson = process.argv.includes('--json');
56
66
  if (isJson)
@@ -0,0 +1,11 @@
1
+ /**
2
+ * oneie init — provision a workspace in one command.
3
+ *
4
+ * Calls POST /api/provision/agent with the provided options, writes the
5
+ * returned scoped key to ~/.config/oneie/key, and prints the workspace URL
6
+ * + invite link.
7
+ *
8
+ * No prior account or API key required. The server mints everything.
9
+ */
10
+ import { Command } from 'commander';
11
+ export declare function initCmd(): Command;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * oneie init — provision a workspace in one command.
3
+ *
4
+ * Calls POST /api/provision/agent with the provided options, writes the
5
+ * returned scoped key to ~/.config/oneie/key, and prints the workspace URL
6
+ * + invite link.
7
+ *
8
+ * No prior account or API key required. The server mints everything.
9
+ */
10
+ import { Command } from 'commander';
11
+ import { writeFileSync, mkdirSync } from 'node:fs';
12
+ import { resolve } from 'node:path';
13
+ import { homedir } from 'node:os';
14
+ import { renameSync, chmodSync } from 'node:fs';
15
+ import { join } from 'node:path';
16
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
17
+ const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
18
+ const KEY_FILE = resolve(CONFIG_DIR, 'key');
19
+ function writeKey(value) {
20
+ mkdirSync(CONFIG_DIR, { recursive: true });
21
+ const tmp = join(CONFIG_DIR, '.key.tmp');
22
+ writeFileSync(tmp, value, { mode: 0o600 });
23
+ chmodSync(tmp, 0o600);
24
+ renameSync(tmp, KEY_FILE);
25
+ }
26
+ function out(cmd, data) {
27
+ const isJson = cmd.parent?.opts().json;
28
+ if (isJson) {
29
+ process.stdout.write(JSON.stringify(data) + '\n');
30
+ }
31
+ else if (data.ok) {
32
+ const lines = Object.entries(data)
33
+ .filter(([k]) => k !== 'ok')
34
+ .map(([k, v]) => ` ${k}: ${v}`)
35
+ .join('\n');
36
+ process.stdout.write(`✓ workspace ready\n${lines}\n`);
37
+ }
38
+ else {
39
+ process.stderr.write(`✗ ${data.error ?? 'failed'}\n`);
40
+ }
41
+ }
42
+ function defaultAgentMd(name) {
43
+ const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
44
+ return `---
45
+ name: ${slug}
46
+ kind: agent
47
+ title: ${name}
48
+ model: claude-sonnet-4-6
49
+ channels: [web, api]
50
+ group: default
51
+ sensitivity: 0.5
52
+ lifecycle: active
53
+ ---
54
+
55
+ You are ${name}. Answer questions clearly and helpfully.
56
+ When you complete a task, summarise what you did in one sentence.
57
+ `;
58
+ }
59
+ export function initCmd() {
60
+ const cmd = new Command('init')
61
+ .description('Provision a new workspace in one command — no account required')
62
+ .option('--name <name>', 'Workspace / agent display name')
63
+ .option('--email <email>', 'Owner email — receives an invite link')
64
+ .option('--skills <refs>', 'Comma-separated skill refs to import (e.g. cold-email,calendar-lookup)')
65
+ .option('--no-content', 'Skip generating a starter agent.md')
66
+ .option('--api <url>', 'API base URL', DEFAULT_API)
67
+ .action(async (opts) => {
68
+ const name = opts.name ?? 'My Agent';
69
+ const skills = opts.skills ? opts.skills.split(',').map(s => s.trim()).filter(Boolean) : [];
70
+ const content = opts.content !== false ? defaultAgentMd(name) : undefined;
71
+ const body = { name, live: true };
72
+ if (content)
73
+ body.content = content;
74
+ if (skills.length)
75
+ body.skills = skills;
76
+ if (opts.email)
77
+ body.invite = { email: opts.email, role: 'owner' };
78
+ let res;
79
+ try {
80
+ res = await fetch(`${opts.api.replace(/\/$/, '')}/api/provision/agent`, {
81
+ method: 'POST',
82
+ headers: { 'Content-Type': 'application/json' },
83
+ body: JSON.stringify(body),
84
+ });
85
+ }
86
+ catch (err) {
87
+ out(cmd, { ok: false, error: `network error: ${err.message}` });
88
+ return;
89
+ }
90
+ const json = await res.json();
91
+ if (!res.ok) {
92
+ out(cmd, { ok: false, ...json });
93
+ return;
94
+ }
95
+ const { workspace, apiKey, inviteUrl } = json;
96
+ writeKey(apiKey);
97
+ out(cmd, {
98
+ ok: true,
99
+ workspace,
100
+ url: `${opts.api.replace(/\/$/, '')}/u/${workspace}`,
101
+ key: `${KEY_FILE} (0600)`,
102
+ ...(inviteUrl ? { invite: inviteUrl } : {}),
103
+ ...(skills.length ? { skills: skills.join(', ') } : {}),
104
+ });
105
+ });
106
+ return cmd;
107
+ }
@@ -0,0 +1,5 @@
1
+ import { Command } from 'commander';
2
+ /** `one links` — mint personalised, actor-bound tracked links from the terminal.
3
+ * Thin wrapper over the `links:create` receiver via ask() (no new route). The
4
+ * receiver walks authority server-side; the API key identifies the caller. */
5
+ export declare function linksCmd(): Command;