@oneie/cli 0.4.0 → 0.5.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/LICENSE +86 -0
- package/dist/src/agent.js +2 -1
- package/dist/src/args.d.ts +9 -0
- package/dist/src/args.js +61 -0
- package/dist/src/catalog.d.ts +1 -2
- package/dist/src/catalog.js +65 -36
- package/dist/src/client.d.ts +0 -1
- package/dist/src/client.js +71 -169
- package/dist/src/compiler.d.ts +15 -19
- package/dist/src/compiler.js +170 -219
- package/dist/src/config.d.ts +24 -0
- package/dist/src/config.js +70 -0
- package/dist/src/coordinate.d.ts +2 -2
- package/dist/src/coordinate.js +47 -61
- package/dist/src/create.d.ts +2 -0
- package/dist/src/create.js +193 -0
- package/dist/src/deploy.d.ts +0 -1
- package/dist/src/deploy.js +8 -35
- package/dist/src/env.d.ts +3 -6
- package/dist/src/env.js +31 -24
- package/dist/src/fn.d.ts +2 -0
- package/dist/src/fn.js +73 -0
- package/dist/src/index.js +16 -8
- package/dist/src/links.d.ts +5 -0
- package/dist/src/links.js +50 -0
- package/dist/src/push.d.ts +0 -1
- package/dist/src/push.js +44 -99
- package/dist/src/render.d.ts +17 -0
- package/dist/src/render.js +25 -0
- package/dist/src/setup.d.ts +0 -1
- package/dist/src/setup.js +43 -134
- package/dist/src/ship.d.ts +0 -1
- package/dist/src/ship.js +13 -36
- package/dist/src/slug.d.ts +2 -5
- package/dist/src/slug.js +4 -7
- package/dist/src/status.d.ts +0 -1
- package/dist/src/status.js +29 -42
- package/dist/src/trade.d.ts +1 -2
- package/dist/src/trade.js +71 -74
- package/dist/src/trail.d.ts +2 -0
- package/dist/src/trail.js +47 -0
- package/dist/src/validate.d.ts +11 -10
- package/dist/src/validate.js +32 -34
- package/package.json +2 -2
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 {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
35
|
-
.description('Compile ai/
|
|
36
|
-
.argument('[
|
|
37
|
-
.option('--
|
|
38
|
-
.option('--dry-run', '
|
|
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
|
-
.
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const agencySlug =
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
51
|
-
if (
|
|
52
|
-
for (const e of
|
|
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
|
-
|
|
57
|
-
process.
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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 (
|
|
99
|
-
process.
|
|
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
|
-
|
|
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
|
+
}
|
package/dist/src/setup.d.ts
CHANGED
package/dist/src/setup.js
CHANGED
|
@@ -1,147 +1,56 @@
|
|
|
1
|
-
/** `one setup` — provision this agency workspace from agency.toml / _node.toml. */
|
|
2
1
|
import { Command } from 'commander';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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',
|
|
8
|
+
method: 'POST',
|
|
9
|
+
headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
10
|
+
body: JSON.stringify({ data }),
|
|
15
11
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
87
|
-
.description('
|
|
19
|
+
return new Command('setup')
|
|
20
|
+
.description('Bootstrap agency workspace (idempotent)')
|
|
88
21
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
89
|
-
.option('--
|
|
22
|
+
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
90
23
|
.action(async (opts) => {
|
|
91
|
-
const
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
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
|
+
: `${dir}/partner.toml`;
|
|
36
|
+
const agency = readAgency(cfgPath);
|
|
110
37
|
const base = opts.api.replace(/\/$/, '');
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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`);
|
|
38
|
+
const ws = await ask(base, key, 'world:create-workspace', {
|
|
39
|
+
name: agency.name,
|
|
40
|
+
slug: agency.slug,
|
|
41
|
+
plan: agency.plan,
|
|
42
|
+
markup: agency.markup_pct,
|
|
43
|
+
brand: agency.brand ?? false,
|
|
44
|
+
credit: agency.pool ?? 0,
|
|
45
|
+
});
|
|
46
|
+
const wsid = String(ws.wsid ?? agency.slug);
|
|
47
|
+
const actor = await ask(base, key, 'world:create-actor', {
|
|
48
|
+
name: 'claude-code',
|
|
49
|
+
type: 'claude-code',
|
|
50
|
+
group: wsid,
|
|
51
|
+
});
|
|
52
|
+
const aid = String(actor.aid ?? '');
|
|
53
|
+
writeEnvLocal(dir, { AGENCY_WSID: wsid, CC_ACTOR_ID: aid, AGENCY_SLUG: agency.slug });
|
|
54
|
+
process.stdout.write(`Agency: ${wsid} plan=${agency.plan} markup=${agency.markup_pct}% pool=${agency.pool ?? 0} cr\nClaude Code actor: ${aid}\n`);
|
|
145
55
|
});
|
|
146
|
-
return cmd;
|
|
147
56
|
}
|
package/dist/src/ship.d.ts
CHANGED
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
|
-
|
|
22
|
-
.description('git add -A
|
|
23
|
-
.argument('
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
if (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
}
|
package/dist/src/slug.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
return `${safeSlug(agencySlug)}--${safeSlug(name)}`;
|
|
4
|
+
export function namespaced(agency, name) {
|
|
5
|
+
return `${safeSlug(agency)}--${safeSlug(name)}`;
|
|
9
6
|
}
|
package/dist/src/status.d.ts
CHANGED
package/dist/src/status.js
CHANGED
|
@@ -1,51 +1,38 @@
|
|
|
1
|
-
/** `one status` — agency P&L dashboard from the substrate. */
|
|
2
1
|
import { Command } from 'commander';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
36
|
-
.description('Agency P&L dashboard
|
|
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
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
48
|
-
|
|
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
|
}
|
package/dist/src/trade.d.ts
CHANGED