@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,50 @@
1
+ import { Command } from 'commander';
2
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
3
+ function headers() {
4
+ const h = { 'Content-Type': 'application/json' };
5
+ const k = process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
6
+ if (k)
7
+ h['Authorization'] = `Bearer ${k}`;
8
+ return h;
9
+ }
10
+ async function ask(api, receiver, data) {
11
+ const res = await fetch(`${api.replace(/\/$/, '')}/api/ask/${encodeURIComponent(receiver)}`, {
12
+ method: 'POST',
13
+ headers: headers(),
14
+ body: JSON.stringify({ data }),
15
+ });
16
+ if (!res.ok) {
17
+ process.stderr.write(`POST /api/ask/${receiver} → ${res.status}\n`);
18
+ process.exit(1);
19
+ }
20
+ return res.json();
21
+ }
22
+ function out(data) {
23
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
24
+ }
25
+ /** `one links` — mint personalised, actor-bound tracked links from the terminal.
26
+ * Thin wrapper over the `links:create` receiver via ask() (no new route). The
27
+ * receiver walks authority server-side; the API key identifies the caller. */
28
+ export function linksCmd() {
29
+ const cmd = new Command('links').description('Create personalised, actor-bound tracked links');
30
+ cmd
31
+ .command('create <actorId>')
32
+ .description('Create a tracked link bound to a contact (rung-4 identity on click)')
33
+ .option('--to <path>', "Destination path, e.g. '/pricing'", '/')
34
+ .option('--context <text>', "Context injected into the agent's system prompt")
35
+ .option('--greeting <text>', "Override the chat agent's opening line")
36
+ .option('--campaign <id>', 'Group clicks under a campaign')
37
+ .option('--expires <days>', 'Link TTL in days (omit = never)')
38
+ .option('--api <url>', 'API base URL', DEFAULT_API)
39
+ .action(async (actorId, opts) => {
40
+ out(await ask(opts.api, 'links:create', {
41
+ actorId,
42
+ destination: opts.to,
43
+ context: opts.context,
44
+ greeting: opts.greeting,
45
+ campaignId: opts.campaign,
46
+ expiresInDays: opts.expires ? Number(opts.expires) : undefined,
47
+ }));
48
+ });
49
+ return cmd;
50
+ }
@@ -1,3 +1,2 @@
1
- /** `one push [clients/<slug>]` — compile a fractal node to the substrate. */
2
1
  import { Command } from 'commander';
3
2
  export declare function pushCmd(): Command;
package/dist/src/push.js CHANGED
@@ -1,112 +1,57 @@
1
- /** `one push [clients/<slug>]` — compile a fractal node to the substrate. */
2
1
  import { Command } from 'commander';
3
- import { resolve, join } from 'node:path';
4
- import { existsSync, readdirSync } from 'node:fs';
5
- import { validateNodeDir } from './validate.js';
6
- import { compileNode, readNodeConfig } from './compiler.js';
7
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
8
- function apiKey() {
9
- return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
10
- }
11
- function out(cmd, data) {
12
- const isJson = cmd.parent?.opts()?.json;
13
- if (isJson)
14
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
15
- else {
16
- const d = data;
17
- if (d['pushed'] && Array.isArray(d['pushed'])) {
18
- for (const s of d['pushed'])
19
- process.stdout.write(` ✓ ${s}\n`);
20
- }
21
- if (d['skipped'] && Array.isArray(d['skipped'])) {
22
- for (const s of d['skipped'])
23
- process.stdout.write(` ~ ${s}\n`);
24
- }
25
- if (d['errors'] && Array.isArray(d['errors'])) {
26
- for (const s of d['errors'])
27
- process.stderr.write(` ✗ ${s}\n`);
28
- }
29
- const ok = d['errors']?.length === 0;
30
- process.stdout.write(ok ? `\n✓ push complete\n` : `\n✗ push finished with errors\n`);
31
- }
2
+ import { compileNode } from './compiler.js';
3
+ import { mergeEnv } from './env.js';
4
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
5
+ function apiKey(env) {
6
+ return env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
32
7
  }
33
8
  export function pushCmd() {
34
- const cmd = new Command('push')
35
- .description('Compile ai/ and data/ folders to the ONE substrate')
36
- .argument('[target]', 'Optional: "clients/<slug>" to push a specific client, or "--all" flag')
37
- .option('--all', 'Push all clients in the clients/ directory')
38
- .option('--dry-run', 'Simulate without making API calls')
9
+ return new Command('push')
10
+ .description('Compile ai/ + data/ folders and push to substrate')
11
+ .argument('[path]', 'Node root directory (default: cwd)')
12
+ .option('--client <slug>', 'Apply client override from clients/<slug>/')
13
+ .option('--dry-run', 'Validate and print plan without making substrate calls')
39
14
  .option('--api <url>', 'API base URL', DEFAULT_API)
40
- .action(async (target, opts) => {
41
- const cwd = process.cwd();
42
- const rootDir = cwd;
43
- const cfg = readNodeConfig(rootDir);
44
- const agencySlug = String(cfg['slug'] ?? '');
45
- const key = apiKey();
46
- if (!key) {
47
- process.stderr.write('error: ONEIE_API_KEY not set — run `one auth login` first\n');
15
+ .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
16
+ .action(async (path, opts) => {
17
+ const dir = path ?? process.cwd();
18
+ const env = mergeEnv(dir);
19
+ const agencySlug = env.AGENCY_SLUG;
20
+ if (!agencySlug) {
21
+ process.stderr.write('AGENCY_SLUG missing — run `one setup` first\n');
48
22
  process.exit(1);
49
23
  }
50
- const validation = validateNodeDir(rootDir);
51
- if (!validation.ok) {
52
- for (const e of validation.errors)
53
- process.stderr.write(`error: ${e}\n`);
24
+ const { compiled, errors } = await compileNode(dir, agencySlug, { clientSlug: opts.client, dryRun: opts.dryRun });
25
+ if (errors.length) {
26
+ for (const e of errors)
27
+ process.stderr.write(` error: ${e.path}: ${e.message}\n`);
54
28
  process.exit(1);
55
29
  }
56
- for (const w of validation.warnings)
57
- process.stderr.write(`warning: ${w}\n`);
58
- // Determine targets
59
- const targets = [];
60
- if (opts.all) {
61
- const clientsDir = resolve(rootDir, 'clients');
62
- if (existsSync(clientsDir)) {
63
- for (const entry of readdirSync(clientsDir, { withFileTypes: true })) {
64
- if (entry.isDirectory()) {
65
- const clientDir = join(clientsDir, entry.name);
66
- const clientCfg = readNodeConfig(clientDir);
67
- targets.push({ clientDir, slug: String(clientCfg['slug'] ?? entry.name) });
68
- }
69
- }
70
- }
71
- }
72
- else if (target && target.startsWith('clients/')) {
73
- const clientSlug = target.split('/')[1];
74
- const clientDir = resolve(rootDir, target);
75
- const clientCfg = readNodeConfig(clientDir);
76
- targets.push({ clientDir, slug: String(clientCfg['slug'] ?? clientSlug) });
77
- }
78
- else {
79
- // Push root node (the agency itself)
80
- targets.push({ slug: agencySlug });
81
- }
82
- let totalPushed = 0;
83
- let totalErrors = 0;
84
- for (const t of targets) {
85
- if (!agencySlug && !t.slug) {
86
- process.stderr.write('error: could not resolve workspace slug — check _node.toml\n');
87
- process.exit(1);
88
- }
89
- const result = await compileNode({
90
- rootDir,
91
- clientDir: t.clientDir,
92
- apiBase: opts.api,
93
- apiKey: key,
94
- agencySlug: agencySlug || t.slug,
95
- targetSlug: t.slug || agencySlug,
96
- dry: opts.dryRun ?? false,
30
+ if (opts.dryRun) {
31
+ process.stdout.write(`[dry-run] ${compiled.length} item(s) would push:\n`);
32
+ for (const item of compiled)
33
+ process.stdout.write(` ${item.receiver} ${item.path}\n`);
34
+ return;
35
+ }
36
+ const base = (opts.api ?? DEFAULT_API).replace(/\/$/, '');
37
+ const key = opts.key ?? apiKey(env);
38
+ const authHeaders = { 'Content-Type': 'application/json' };
39
+ if (key)
40
+ authHeaders['Authorization'] = `Bearer ${key}`;
41
+ let ok = 0;
42
+ for (const item of compiled) {
43
+ const res = await fetch(`${base}/api/ask/${encodeURIComponent(item.receiver)}`, {
44
+ method: 'POST',
45
+ headers: authHeaders,
46
+ body: JSON.stringify({ data: item.payload }),
97
47
  });
98
- if (targets.length > 1) {
99
- process.stdout.write(`\n─── ${t.slug} ───\n`);
48
+ if (!res.ok) {
49
+ process.stderr.write(` failed: ${item.receiver} ${res.status}\n`);
50
+ }
51
+ else {
52
+ ok++;
100
53
  }
101
- out(cmd, result);
102
- totalPushed += result.pushed.length;
103
- totalErrors += result.errors.length;
104
- }
105
- if (targets.length > 1) {
106
- process.stdout.write(`\nTotal: ${totalPushed} pushed, ${totalErrors} errors across ${targets.length} nodes\n`);
107
54
  }
108
- if (totalErrors > 0)
109
- process.exit(1);
55
+ process.stdout.write(`Pushed ${ok}/${compiled.length} item(s).\n`);
110
56
  });
111
- return cmd;
112
57
  }
@@ -0,0 +1,17 @@
1
+ export interface AgencyPL {
2
+ slug: string;
3
+ name: string | null;
4
+ markup_pct: number;
5
+ pool: number;
6
+ }
7
+ export interface ClientPL {
8
+ slug: string;
9
+ name: string | null;
10
+ plan: string;
11
+ funded: number;
12
+ burned: number;
13
+ margin: number;
14
+ balance: number;
15
+ cap: number | null;
16
+ }
17
+ export declare function renderStatus(agency: AgencyPL, clients: ClientPL[]): string;
@@ -0,0 +1,25 @@
1
+ const fmt = (n) => n.toLocaleString('en-US');
2
+ const capFmt = (n) => (n == null ? '—' : fmt(n));
3
+ function pad(cells, widths) {
4
+ return cells.map((c, i) => c.padEnd(widths[i])).join(' ').replace(/\s+$/, '');
5
+ }
6
+ export function renderStatus(agency, clients) {
7
+ const header = ['CLIENT', 'PLAN', 'FUNDED', 'BURNED', `MARGIN(${agency.markup_pct}%)`, 'BALANCE', 'CAP'];
8
+ const rows = clients.map((c) => [
9
+ c.slug, c.plan, fmt(c.funded), fmt(c.burned), fmt(c.margin), fmt(c.balance), capFmt(c.cap),
10
+ ]);
11
+ const widths = header.map((h, i) => Math.max(h.length, ...rows.map((r) => r[i].length), 0));
12
+ const totalBurned = clients.reduce((s, c) => s + c.burned, 0);
13
+ const totalMargin = clients.reduce((s, c) => s + c.margin, 0);
14
+ const out = [];
15
+ out.push(`Agency: ${agency.name ?? agency.slug} (${agency.slug}) plan=agency markup=${agency.markup_pct}% pool=${fmt(agency.pool)} cr`);
16
+ out.push('');
17
+ out.push(pad(header, widths));
18
+ for (const r of rows)
19
+ out.push(pad(r, widths));
20
+ if (clients.length === 0)
21
+ out.push(' (no clients yet — `one client add <slug>`)');
22
+ else
23
+ out.push(`\n total burned ${fmt(totalBurned)} · margin ${fmt(totalMargin)} ← your margin this period`);
24
+ return out.join('\n');
25
+ }
@@ -1,3 +1,2 @@
1
- /** `one setup` — provision this agency workspace from agency.toml / _node.toml. */
2
1
  import { Command } from 'commander';
3
2
  export declare function setupCmd(): Command;
package/dist/src/setup.js CHANGED
@@ -1,147 +1,60 @@
1
- /** `one setup` — provision this agency workspace from agency.toml / _node.toml. */
2
1
  import { Command } from 'commander';
3
- import { readFileSync, existsSync } from 'node:fs';
4
- import { resolve } from 'node:path';
5
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
6
- function apiKey() {
7
- return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
8
- }
9
- function headers() {
10
- return { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey()}` };
11
- }
12
- async function ask(base, receiver, data) {
2
+ import { existsSync } from 'node:fs';
3
+ import { mergeEnv, writeEnvLocal } from './env.js';
4
+ import { readAgency } from './config.js';
5
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
6
+ async function ask(base, key, receiver, data) {
13
7
  const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
14
- method: 'POST', headers: headers(), body: JSON.stringify({ data }),
8
+ method: 'POST',
9
+ headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
10
+ body: JSON.stringify({ data }),
15
11
  });
16
- return res.json();
17
- }
18
- function parseToml(text) {
19
- const result = {};
20
- let currentSection = null;
21
- for (const rawLine of text.split('\n')) {
22
- const line = rawLine.split('#')[0].trim();
23
- if (!line)
24
- continue;
25
- if (line.startsWith('[[') && line.endsWith(']]')) {
26
- currentSection = line.slice(2, -2).trim();
27
- if (!Array.isArray(result[currentSection]))
28
- result[currentSection] = [];
29
- result[currentSection].push({});
30
- continue;
31
- }
32
- if (line.startsWith('[') && line.endsWith(']')) {
33
- currentSection = null;
34
- continue;
35
- }
36
- const eq = line.indexOf('=');
37
- if (eq < 1)
38
- continue;
39
- const key = line.slice(0, eq).trim();
40
- const raw = line.slice(eq + 1).trim();
41
- let val;
42
- if (raw === 'true')
43
- val = true;
44
- else if (raw === 'false')
45
- val = false;
46
- else if (!isNaN(Number(raw)) && raw !== '')
47
- val = Number(raw);
48
- else if (raw.startsWith('"') || raw.startsWith("'"))
49
- val = raw.slice(1, -1);
50
- else if (raw.startsWith('[') && raw.endsWith(']')) {
51
- val = raw.slice(1, -1).split(',').map(v => v.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
52
- }
53
- else
54
- val = raw;
55
- if (currentSection) {
56
- const arr = result[currentSection];
57
- if (arr.length > 0)
58
- arr[arr.length - 1][key] = val;
59
- }
60
- else
61
- result[key] = val;
62
- }
63
- return result;
64
- }
65
- function readConfig(cwd) {
66
- for (const name of ['agency.toml', '_node.toml']) {
67
- const p = resolve(cwd, name);
68
- if (existsSync(p))
69
- return parseToml(readFileSync(p, 'utf8'));
70
- }
71
- return {};
72
- }
73
- function out(cmd, data) {
74
- const isJson = cmd.parent?.opts()?.json;
75
- if (isJson)
76
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
77
- else {
78
- const d = data;
79
- for (const [k, v] of Object.entries(d)) {
80
- if (typeof v !== 'object')
81
- process.stdout.write(` ${k}=${v}\n`);
82
- }
12
+ if (!res.ok) {
13
+ const body = await res.text().catch(() => '');
14
+ throw new Error(`${receiver} → ${res.status}\n${body}`);
83
15
  }
16
+ return res.json();
84
17
  }
85
18
  export function setupCmd() {
86
- const cmd = new Command('setup')
87
- .description('Provision this agency workspace from agency.toml / _node.toml')
19
+ return new Command('setup')
20
+ .description('Bootstrap agency workspace (idempotent)')
88
21
  .option('--api <url>', 'API base URL', DEFAULT_API)
89
- .option('--dry-run', 'Simulate without making API calls')
22
+ .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
90
23
  .action(async (opts) => {
91
- const cwd = process.cwd();
92
- const cfg = readConfig(cwd);
93
- const name = String(cfg['name'] ?? '');
94
- const slug = String(cfg['slug'] ?? '');
95
- const plan = String(cfg['plan'] ?? 'pro');
96
- if (!name || !slug) {
97
- process.stderr.write('error: agency.toml / _node.toml must have name and slug\n');
98
- process.exit(1);
99
- }
100
- const key = apiKey();
101
- if (!key) {
102
- process.stderr.write('error: ONEIE_API_KEY not set — run `one auth login` first\n');
103
- process.exit(1);
104
- }
105
- if (opts.dryRun) {
106
- process.stdout.write(`[dry-run] would bootstrap workspace: ${slug} (${plan})\n`);
107
- out(cmd, { ok: true, slug, plan, dry: true });
24
+ const dir = process.cwd();
25
+ const env = mergeEnv(dir);
26
+ const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
27
+ if (env.AGENCY_WSID && env.CC_ACTOR_ID) {
28
+ process.stdout.write(`Agency already set up (${env.AGENCY_WSID}). No-op.\n`);
108
29
  return;
109
30
  }
31
+ const cfgPath = existsSync(`${dir}/_node.toml`)
32
+ ? `${dir}/_node.toml`
33
+ : existsSync(`${dir}/agency.toml`)
34
+ ? `${dir}/agency.toml`
35
+ : existsSync(`${dir}/partner.toml`)
36
+ ? `${dir}/partner.toml`
37
+ : existsSync(`${dir}/workspace.toml`)
38
+ ? `${dir}/workspace.toml`
39
+ : `${dir}/agency.toml`;
40
+ const agency = readAgency(cfgPath);
110
41
  const base = opts.api.replace(/\/$/, '');
111
- // 1. Bootstrap actor (creates or returns existing)
112
- const boot = (await ask(base, 'agent:bootstrap', {}));
113
- const uid = boot?.result?.uid ?? '';
114
- process.stdout.write(` ✓ actor: ${uid || 'existing'}\n`);
115
- // 2. Create workspace
116
- const workspace = (await ask(base, 'world:create-workspace', {
117
- name, slug, plan,
118
- pool: cfg['pool'],
119
- markup_pct: cfg['markup_pct'],
120
- }));
121
- if (workspace?.kind === 'failure') {
122
- process.stderr.write(` ✗ workspace: ${workspace?.error ?? 'failed'}\n`);
123
- process.exit(1);
124
- }
125
- process.stdout.write(` ✓ workspace: ${slug}\n`);
126
- // 3. Mint a scoped key for this workspace
127
- const keyResult = (await ask(base, 'world:create-key', { slug }));
128
- const scopedKey = keyResult?.result?.key ?? '';
129
- if (scopedKey) {
130
- process.stdout.write(` ✓ API key: ${scopedKey.slice(0, 8)}…\n`);
131
- process.stdout.write(`\n Add to .env.local:\n ONE_API_KEY=${scopedKey}\n\n`);
132
- }
133
- // 4. Invite staff from [[staff]] entries in toml
134
- const staff = (cfg['staff'] ?? []);
135
- for (const member of staff) {
136
- const email = String(member['email'] ?? '');
137
- const role = String(member['role'] ?? 'member');
138
- if (!email)
139
- continue;
140
- await ask(base, 'world:invite-member', { slug, email, role });
141
- process.stdout.write(` ✓ invited: ${email} (${role})\n`);
142
- }
143
- out(cmd, { ok: true, slug, plan, uid, scopedKey: scopedKey ? scopedKey.slice(0, 8) + '…' : '' });
144
- process.stdout.write(`\n✓ Agency "${name}" provisioned. Next: one push\n`);
42
+ const ws = await ask(base, key, 'world:create-workspace', {
43
+ name: agency.name,
44
+ slug: agency.slug,
45
+ plan: agency.plan,
46
+ markup: agency.markup_pct,
47
+ brand: agency.brand ?? false,
48
+ credit: agency.pool ?? 0,
49
+ });
50
+ const wsid = String(ws.wsid ?? agency.slug);
51
+ const actor = await ask(base, key, 'world:create-actor', {
52
+ name: 'claude-code',
53
+ type: 'claude-code',
54
+ group: wsid,
55
+ });
56
+ const aid = String(actor.aid ?? '');
57
+ writeEnvLocal(dir, { AGENCY_WSID: wsid, CC_ACTOR_ID: aid, AGENCY_SLUG: agency.slug });
58
+ process.stdout.write(`Agency: ${wsid} plan=${agency.plan} markup=${agency.markup_pct}% pool=${agency.pool ?? 0} cr\nClaude Code actor: ${aid}\n`);
145
59
  });
146
- return cmd;
147
60
  }
@@ -1,3 +1,2 @@
1
- /** `one ship [message]` — git add + commit + push shortcut. */
2
1
  import { Command } from 'commander';
3
2
  export declare function shipCmd(): Command;
package/dist/src/ship.js CHANGED
@@ -1,41 +1,18 @@
1
- /** `one ship [message]` — git add + commit + push shortcut. */
2
1
  import { Command } from 'commander';
3
2
  import { spawnSync } from 'node:child_process';
4
- function run(args) {
5
- const r = spawnSync(args[0], args.slice(1), { stdio: 'inherit', encoding: 'utf8' });
6
- return r.status ?? 1;
7
- }
8
- function out(cmd, data) {
9
- const isJson = cmd.parent?.opts()?.json;
10
- if (isJson)
11
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
12
- else {
13
- const d = data;
14
- if (d['ok'])
15
- process.stdout.write(`✓ shipped: ${d['message']}\n`);
16
- else
17
- process.stderr.write(`✗ ship failed at: ${d['step']}\n`);
18
- }
19
- }
20
3
  export function shipCmd() {
21
- const cmd = new Command('ship')
22
- .description('git add -A + commit + push in one step')
23
- .argument('<message>', 'Commit message')
24
- .option('--no-push', 'Commit but do not push')
25
- .action((message, opts) => {
26
- if (run(['git', 'add', '-A']) !== 0) {
27
- out(cmd, { ok: false, step: 'git add' });
28
- process.exit(1);
29
- }
30
- if (run(['git', 'commit', '-m', message]) !== 0) {
31
- out(cmd, { ok: false, step: 'git commit' });
32
- process.exit(1);
33
- }
34
- if (opts.push !== false && run(['git', 'push']) !== 0) {
35
- out(cmd, { ok: false, step: 'git push' });
36
- process.exit(1);
37
- }
38
- out(cmd, { ok: true, message });
4
+ return new Command('ship')
5
+ .description('git add -A, commit, and push (close the loop)')
6
+ .argument('[message]', 'Commit message', 'ship: update agency workspace')
7
+ .action((message) => {
8
+ const add = spawnSync('git', ['add', '-A'], { stdio: 'inherit' });
9
+ if (add.status !== 0)
10
+ process.exit(add.status ?? 1);
11
+ const commit = spawnSync('git', ['commit', '-m', message], { stdio: 'inherit' });
12
+ if (commit.status !== 0 && commit.status !== 1)
13
+ process.exit(commit.status ?? 1);
14
+ const push = spawnSync('git', ['push'], { stdio: 'inherit' });
15
+ if (push.status !== 0)
16
+ process.exit(push.status ?? 1);
39
17
  });
40
- return cmd;
41
18
  }
@@ -1,5 +1,2 @@
1
- /** Utility helpers for slug normalisation. */
2
- /** Ensure only lowercase letters, digits, hyphens (replaces everything else with `-`). */
3
- export declare function safeSlug(raw: string): string;
4
- /** Namespace a skill/agent name: `<agencySlug>--<name>` (double dash — namespace separator). */
5
- export declare function namespaced(agencySlug: string, name: string): string;
1
+ export declare function safeSlug(s: string): string;
2
+ export declare function namespaced(agency: string, name: string): string;
package/dist/src/slug.js CHANGED
@@ -1,9 +1,6 @@
1
- /** Utility helpers for slug normalisation. */
2
- /** Ensure only lowercase letters, digits, hyphens (replaces everything else with `-`). */
3
- export function safeSlug(raw) {
4
- return raw.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
1
+ export function safeSlug(s) {
2
+ return s.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
5
3
  }
6
- /** Namespace a skill/agent name: `<agencySlug>--<name>` (double dash — namespace separator). */
7
- export function namespaced(agencySlug, name) {
8
- return `${safeSlug(agencySlug)}--${safeSlug(name)}`;
4
+ export function namespaced(agency, name) {
5
+ return `${safeSlug(agency)}--${safeSlug(name)}`;
9
6
  }
@@ -1,3 +1,2 @@
1
- /** `one status` — agency P&L dashboard from the substrate. */
2
1
  import { Command } from 'commander';
3
2
  export declare function statusCmd(): Command;
@@ -1,51 +1,38 @@
1
- /** `one status` — agency P&L dashboard from the substrate. */
2
1
  import { Command } from 'commander';
3
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
4
- function apiKey() {
5
- return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
6
- }
7
- function headers() {
8
- return { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey()}` };
9
- }
10
- async function ask(base, receiver, data) {
11
- const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
12
- method: 'POST', headers: headers(), body: JSON.stringify({ data }),
13
- });
14
- return res.json();
15
- }
16
- function out(cmd, data) {
17
- const isJson = cmd.parent?.opts()?.json;
18
- if (isJson)
19
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
20
- else {
21
- const d = data;
22
- if (d['kind'] === 'result') {
23
- const r = d['result'];
24
- for (const [k, v] of Object.entries(r ?? {})) {
25
- if (typeof v !== 'object')
26
- process.stdout.write(` ${k}: ${v}\n`);
27
- }
28
- }
29
- else {
30
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
31
- }
32
- }
33
- }
2
+ import { mergeEnv } from './env.js';
3
+ import { renderStatus } from './render.js';
4
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
34
5
  export function statusCmd() {
35
- const cmd = new Command('status')
36
- .description('Agency P&L dashboard — credits, burns, markup earned')
37
- .option('--slug <slug>', 'Workspace slug (defaults to ONEIE_SLUG env or config)')
6
+ return new Command('status')
7
+ .description('Agency P&L dashboard (pool, margin, per-client burns)')
38
8
  .option('--api <url>', 'API base URL', DEFAULT_API)
9
+ .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
10
+ .option('--json', 'Output raw JSON')
39
11
  .action(async (opts) => {
40
- const key = apiKey();
41
- if (!key) {
42
- process.stderr.write('error: ONEIE_API_KEY not set\n');
12
+ const dir = process.cwd();
13
+ const env = mergeEnv(dir);
14
+ const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
15
+ if (!key || !env.AGENCY_SLUG) {
16
+ process.stderr.write('not set up — run `one setup` first\n');
43
17
  process.exit(1);
44
18
  }
45
- const slug = opts.slug ?? process.env.ONEIE_SLUG ?? process.env.ONE_SLUG ?? '';
46
19
  const base = opts.api.replace(/\/$/, '');
47
- const result = await ask(base, 'dashboard:usage', { slug });
48
- out(cmd, result);
20
+ const res = await fetch(`${base}/api/ask/${encodeURIComponent('billing:clients')}`, {
21
+ method: 'POST',
22
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
23
+ body: JSON.stringify({ data: {} }),
24
+ });
25
+ if (!res.ok) {
26
+ process.stderr.write(`billing:clients → ${res.status}\n`);
27
+ process.exit(1);
28
+ }
29
+ const data = await res.json();
30
+ if (opts.json) {
31
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
32
+ return;
33
+ }
34
+ const agency = (data.agency ?? { slug: env.AGENCY_SLUG, name: env.AGENCY_NAME ?? null, markup_pct: 0, pool: 0 });
35
+ const clients = (data.clients ?? []);
36
+ process.stdout.write(renderStatus(agency, clients) + '\n');
49
37
  });
50
- return cmd;
51
38
  }
@@ -1,3 +1,2 @@
1
- /** `one market|hire|bounty|earn|usage` — trade layer commands. */
2
1
  import { Command } from 'commander';
3
- export declare function tradeCmd(): Command;
2
+ export declare function tradeCommands(program: Command): void;