@oneie/cli 0.2.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.
@@ -0,0 +1,3 @@
1
+ import { Command } from 'commander';
2
+ export declare function authCmd(): Command;
3
+ export declare function loadKey(): string | null;
@@ -0,0 +1,116 @@
1
+ import { Command } from 'commander';
2
+ import { writeFileSync, readFileSync, existsSync, mkdirSync, chmodSync, unlinkSync, renameSync, } from 'node:fs';
3
+ import { resolve, join } from 'node:path';
4
+ import { homedir } from 'node:os';
5
+ import { requestDeviceCode, openBrowser, pollForToken } from './device-flow.js';
6
+ const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
7
+ const KEY_FILE = resolve(CONFIG_DIR, 'key');
8
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
9
+ const CLI_CLIENT_ID = 'oneie-cli';
10
+ const CLI_SCOPE = 'read write';
11
+ export function authCmd() {
12
+ const cmd = new Command('auth').description('Authentication');
13
+ cmd.command('login')
14
+ .description('Sign in via browser and persist token to ~/.config/oneie/key')
15
+ .option('--key <key>', 'Skip browser flow — store API key directly (or set ONEIE_API_KEY)')
16
+ .option('--api <url>', 'API base URL', DEFAULT_API)
17
+ .action(async (opts) => {
18
+ // Fast path: explicit --key or ONEIE_API_KEY env var (legacy / CI)
19
+ const envKey = opts.key ?? process.env.ONEIE_API_KEY;
20
+ if (envKey) {
21
+ writeKey(envKey);
22
+ out(cmd, { ok: true, stored: KEY_FILE, permissions: '0600', method: 'key' });
23
+ return;
24
+ }
25
+ // Device-flow path
26
+ const base = opts.api.replace(/\/$/, '');
27
+ try {
28
+ // (a) Request device code
29
+ process.stderr.write('Requesting device authorization…\n');
30
+ const dc = await requestDeviceCode(base, CLI_CLIENT_ID, CLI_SCOPE);
31
+ // (b) Open browser — include user_code as a hint in the verification URL
32
+ const sep = dc.verification_uri.includes('?') ? '&' : '?';
33
+ const verifyUrl = `${dc.verification_uri}${sep}user_code=${encodeURIComponent(dc.user_code)}`;
34
+ process.stderr.write(`\nOpen this URL in your browser to sign in:\n ${verifyUrl}\n`);
35
+ process.stderr.write(`\nYour one-time code: ${dc.user_code}\n`);
36
+ process.stderr.write('(The browser should open automatically)\n\n');
37
+ await openBrowser(verifyUrl);
38
+ // (c) Poll until token or expiry
39
+ process.stderr.write(`Waiting for sign-in (expires in ${dc.expires_in}s)…\n`);
40
+ const token = await pollForToken(base, CLI_CLIENT_ID, dc.device_code, dc.interval, dc.expires_in);
41
+ // (d) Write token to ~/.config/oneie/key mode 0600
42
+ writeKey(token.access_token);
43
+ // (e) Print success — emit userId if server returned it
44
+ const userId = token.userId ?? 'unknown';
45
+ out(cmd, {
46
+ ok: true,
47
+ stored: KEY_FILE,
48
+ permissions: '0600',
49
+ method: 'device-flow',
50
+ userId,
51
+ });
52
+ }
53
+ catch (err) {
54
+ const msg = err.message;
55
+ if (process.env.DEBUG) {
56
+ process.stderr.write(`${err.stack ?? msg}\n`);
57
+ }
58
+ else {
59
+ process.stderr.write(`Login failed: ${msg}\n`);
60
+ }
61
+ process.exit(1);
62
+ }
63
+ });
64
+ cmd.command('logout')
65
+ .description('Remove stored API key')
66
+ .action(() => {
67
+ if (existsSync(KEY_FILE)) {
68
+ unlinkSync(KEY_FILE);
69
+ out(cmd, { ok: true, cleared: KEY_FILE });
70
+ }
71
+ else {
72
+ out(cmd, { ok: true, cleared: null, note: 'no key was stored' });
73
+ }
74
+ });
75
+ return cmd;
76
+ }
77
+ export function loadKey() {
78
+ if (process.env.ONEIE_API_KEY)
79
+ return process.env.ONEIE_API_KEY;
80
+ if (existsSync(KEY_FILE)) {
81
+ const val = readFileSync(KEY_FILE, 'utf8').trim();
82
+ return val || null;
83
+ }
84
+ return null;
85
+ }
86
+ // ---------------------------------------------------------------------------
87
+ // Internal helpers
88
+ // ---------------------------------------------------------------------------
89
+ /**
90
+ * Atomically write `value` to KEY_FILE with mode 0600.
91
+ * Write to a temp file first, then rename — avoids a race where a concurrent
92
+ * reader sees a half-written key file.
93
+ */
94
+ function writeKey(value) {
95
+ mkdirSync(CONFIG_DIR, { recursive: true });
96
+ const tmp = join(CONFIG_DIR, '.key.tmp');
97
+ writeFileSync(tmp, value, { mode: 0o600 });
98
+ chmodSync(tmp, 0o600);
99
+ renameSync(tmp, KEY_FILE);
100
+ }
101
+ function out(cmd, data) {
102
+ const isJson = cmd.parent?.opts().json;
103
+ if (isJson) {
104
+ process.stdout.write(JSON.stringify(data) + '\n');
105
+ }
106
+ else if (data.ok) {
107
+ const pairs = Object.entries(data)
108
+ .filter(([k]) => k !== 'ok')
109
+ .map(([k, v]) => `${k}=${JSON.stringify(v)}`)
110
+ .join(' ');
111
+ console.log('✓', pairs);
112
+ }
113
+ else {
114
+ console.error('✗', String(data.error));
115
+ }
116
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function devCmd(): Command;
@@ -0,0 +1,75 @@
1
+ import { Command } from 'commander';
2
+ import { spawn } from 'node:child_process';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ import { resolve } from 'node:path';
5
+ export function devCmd() {
6
+ const cmd = new Command('dev')
7
+ .description('Run the full Cloudflare stack locally (build + migrate + wrangler dev)')
8
+ .option('-p, --port <port>', 'HTTP port', '8787')
9
+ .option('--ip <ip>', 'Bind address', '127.0.0.1')
10
+ .option('--remote', 'Use remote bindings (real D1/KV/R2)', false)
11
+ .option('--skip-build', 'Skip astro build before wrangler dev', false)
12
+ .option('--skip-migrate', 'Skip D1 migrations', false)
13
+ .option('--cwd <path>', 'Project directory (must contain wrangler.toml)', process.cwd())
14
+ .action(async (opts) => {
15
+ const cwd = resolve(opts.cwd);
16
+ const wranglerToml = resolve(cwd, 'wrangler.toml');
17
+ if (!existsSync(wranglerToml)) {
18
+ process.stderr.write(`no wrangler.toml at ${cwd}\n`);
19
+ process.exit(1);
20
+ }
21
+ if (opts.remote) {
22
+ // Remote mode: full build → migrate → wrangler dev --remote
23
+ if (!opts.skipBuild) {
24
+ const built = await run('npm', ['run', 'build'], cwd);
25
+ if (built !== 0)
26
+ process.exit(built);
27
+ }
28
+ if (!opts.skipMigrate) {
29
+ for (const binding of d1Bindings(wranglerToml)) {
30
+ const code = await run('npx', ['wrangler', 'd1', 'migrations', 'apply', binding, '--remote'], cwd);
31
+ if (code !== 0) {
32
+ process.stderr.write(`d1 migrations failed for ${binding}\n`);
33
+ process.exit(code);
34
+ }
35
+ }
36
+ }
37
+ const args = ['dev', '--port', opts.port, '--ip', opts.ip, '--remote'];
38
+ const code = await run('npx', ['wrangler', ...args], cwd);
39
+ process.exit(code);
40
+ }
41
+ else {
42
+ // Local mode: astro dev with Vite HMR
43
+ if (!opts.skipMigrate) {
44
+ for (const binding of d1Bindings(wranglerToml)) {
45
+ const code = await run('npx', ['wrangler', 'd1', 'migrations', 'apply', binding, '--local'], cwd);
46
+ if (code !== 0) {
47
+ process.stderr.write(`d1 migrations failed for ${binding}\n`);
48
+ process.exit(code);
49
+ }
50
+ }
51
+ }
52
+ const code = await run('npm', ['run', 'dev'], cwd);
53
+ process.exit(code);
54
+ }
55
+ });
56
+ return cmd;
57
+ }
58
+ function d1Bindings(wranglerToml) {
59
+ const text = readFileSync(wranglerToml, 'utf8');
60
+ const blocks = text.match(/\[\[d1_databases\]\][^[]*/g) ?? [];
61
+ const bindings = [];
62
+ for (const block of blocks) {
63
+ const m = block.match(/binding\s*=\s*["']([^"']+)["']/);
64
+ if (m)
65
+ bindings.push(m[1]);
66
+ }
67
+ return bindings;
68
+ }
69
+ function run(bin, args, cwd) {
70
+ return new Promise(resolveP => {
71
+ const child = spawn(bin, args, { cwd, stdio: 'inherit', env: process.env });
72
+ child.on('exit', code => resolveP(code ?? 0));
73
+ child.on('error', err => { process.stderr.write(`${err.message}\n`); resolveP(1); });
74
+ });
75
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * device-flow.ts — RFC 8628 device-authorization-grant primitives
3
+ *
4
+ * Pure functions. auth.ts orchestrates; this module only does I/O
5
+ * against the network + browser open. No Commander, no key-write here.
6
+ */
7
+ export interface DeviceCodeResponse {
8
+ device_code: string;
9
+ user_code: string;
10
+ verification_uri: string;
11
+ expires_in: number;
12
+ interval: number;
13
+ }
14
+ export interface TokenResponse {
15
+ access_token: string;
16
+ token_type: string;
17
+ expires_in?: number;
18
+ refresh_token?: string;
19
+ scope?: string;
20
+ userId?: string;
21
+ }
22
+ /** Returned by pollForToken when still waiting */
23
+ export interface PollPending {
24
+ status: 'pending' | 'slow_down';
25
+ }
26
+ /** Returned by pollForToken on success */
27
+ export interface PollSuccess {
28
+ status: 'success';
29
+ token: TokenResponse;
30
+ }
31
+ /** Returned by pollForToken on terminal error */
32
+ export interface PollError {
33
+ status: 'error';
34
+ code: string;
35
+ message: string;
36
+ }
37
+ export type PollResult = PollPending | PollSuccess | PollError;
38
+ export declare function requestDeviceCode(base: string, clientId: string, scope: string): Promise<DeviceCodeResponse>;
39
+ /**
40
+ * Open `url` in the default browser.
41
+ * Tries `open` package first; falls back to platform child_process.execSync.
42
+ */
43
+ export declare function openBrowser(url: string): Promise<void>;
44
+ /**
45
+ * Poll until token, expiry, or terminal error.
46
+ *
47
+ * Respects server `interval` (RFC 8628 §3.5).
48
+ * Backs off on `slow_down` by doubling interval (minimum +5 s per RFC).
49
+ *
50
+ * @param base API base URL (e.g. https://one.ie)
51
+ * @param clientId OAuth client_id
52
+ * @param deviceCode device_code from requestDeviceCode
53
+ * @param intervalSec initial polling interval from server
54
+ * @param expiresIn seconds until device_code expires
55
+ * @returns TokenResponse on success, throws on failure/expiry
56
+ */
57
+ export declare function pollForToken(base: string, clientId: string, deviceCode: string, intervalSec: number, expiresIn: number): Promise<TokenResponse>;
@@ -0,0 +1,171 @@
1
+ /**
2
+ * device-flow.ts — RFC 8628 device-authorization-grant primitives
3
+ *
4
+ * Pure functions. auth.ts orchestrates; this module only does I/O
5
+ * against the network + browser open. No Commander, no key-write here.
6
+ */
7
+ import { execSync } from 'node:child_process';
8
+ // ---------------------------------------------------------------------------
9
+ // Step (a): Request device code
10
+ // ---------------------------------------------------------------------------
11
+ export async function requestDeviceCode(base, clientId, scope) {
12
+ const url = `${base}/api/auth/mcp/device/code`;
13
+ const res = await fetch(url, {
14
+ method: 'POST',
15
+ headers: { 'Content-Type': 'application/json' },
16
+ body: JSON.stringify({ client_id: clientId, scope }),
17
+ });
18
+ if (!res.ok) {
19
+ let detail = '';
20
+ try {
21
+ detail = await res.text();
22
+ }
23
+ catch { /* ignore */ }
24
+ throw new Error(`device-code request failed ${res.status}: ${detail}`);
25
+ }
26
+ const data = (await res.json());
27
+ if (!data.device_code || !data.user_code || !data.verification_uri) {
28
+ throw new Error('Malformed device-code response from server');
29
+ }
30
+ return data;
31
+ }
32
+ // ---------------------------------------------------------------------------
33
+ // Step (b): Open browser
34
+ // ---------------------------------------------------------------------------
35
+ /**
36
+ * Open `url` in the default browser.
37
+ * Tries `open` package first; falls back to platform child_process.execSync.
38
+ */
39
+ export async function openBrowser(url) {
40
+ // Attempt dynamic import of `open` package (optional dep)
41
+ try {
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ const mod = await import('open');
44
+ const openFn = mod.default ?? mod;
45
+ if (typeof openFn === 'function') {
46
+ await openFn(url);
47
+ return;
48
+ }
49
+ }
50
+ catch {
51
+ // `open` not installed — fall back to child_process
52
+ }
53
+ const platform = process.platform;
54
+ let cmd;
55
+ if (platform === 'darwin') {
56
+ cmd = 'open';
57
+ }
58
+ else if (platform === 'win32') {
59
+ cmd = 'start';
60
+ }
61
+ else {
62
+ cmd = 'xdg-open';
63
+ }
64
+ try {
65
+ execSync(`${cmd} "${url}"`, { stdio: 'ignore' });
66
+ }
67
+ catch (err) {
68
+ // Non-fatal: user can open manually
69
+ if (process.env.DEBUG) {
70
+ process.stderr.write(`browser open failed: ${err.message}\n`);
71
+ }
72
+ }
73
+ }
74
+ // ---------------------------------------------------------------------------
75
+ // Step (c): Poll for token
76
+ // ---------------------------------------------------------------------------
77
+ /**
78
+ * Single poll attempt against `/api/auth/mcp/device/token`.
79
+ * Returns a PollResult discriminated union.
80
+ */
81
+ async function pollOnce(base, clientId, deviceCode) {
82
+ const url = `${base}/api/auth/mcp/device/token`;
83
+ let res;
84
+ try {
85
+ res = await fetch(url, {
86
+ method: 'POST',
87
+ headers: { 'Content-Type': 'application/json' },
88
+ body: JSON.stringify({ device_code: deviceCode, client_id: clientId }),
89
+ });
90
+ }
91
+ catch (err) {
92
+ return { status: 'error', code: 'network_error', message: err.message };
93
+ }
94
+ // 200 = success
95
+ if (res.ok) {
96
+ const token = (await res.json());
97
+ if (!token.access_token) {
98
+ return { status: 'error', code: 'invalid_response', message: 'access_token missing' };
99
+ }
100
+ return { status: 'success', token };
101
+ }
102
+ // OAuth error body
103
+ let body = {};
104
+ try {
105
+ body = (await res.json());
106
+ }
107
+ catch { /* ignore */ }
108
+ const code = body.error ?? 'unknown';
109
+ switch (code) {
110
+ case 'authorization_pending':
111
+ return { status: 'pending' };
112
+ case 'slow_down':
113
+ return { status: 'slow_down' };
114
+ case 'expired_token':
115
+ case 'access_denied':
116
+ case 'invalid_grant':
117
+ case 'invalid_client':
118
+ return {
119
+ status: 'error',
120
+ code,
121
+ message: body.error_description ?? code,
122
+ };
123
+ default:
124
+ return {
125
+ status: 'error',
126
+ code,
127
+ message: body.error_description ?? `HTTP ${res.status}`,
128
+ };
129
+ }
130
+ }
131
+ /**
132
+ * Poll until token, expiry, or terminal error.
133
+ *
134
+ * Respects server `interval` (RFC 8628 §3.5).
135
+ * Backs off on `slow_down` by doubling interval (minimum +5 s per RFC).
136
+ *
137
+ * @param base API base URL (e.g. https://one.ie)
138
+ * @param clientId OAuth client_id
139
+ * @param deviceCode device_code from requestDeviceCode
140
+ * @param intervalSec initial polling interval from server
141
+ * @param expiresIn seconds until device_code expires
142
+ * @returns TokenResponse on success, throws on failure/expiry
143
+ */
144
+ export async function pollForToken(base, clientId, deviceCode, intervalSec, expiresIn) {
145
+ const deadline = Date.now() + expiresIn * 1000;
146
+ let currentInterval = Math.max(intervalSec, 5); // never below 5 s
147
+ while (Date.now() < deadline) {
148
+ await sleep(currentInterval * 1000);
149
+ const result = await pollOnce(base, clientId, deviceCode);
150
+ if (result.status === 'success') {
151
+ return result.token;
152
+ }
153
+ if (result.status === 'slow_down') {
154
+ // RFC 8628 §3.5: increase interval by 5 s minimum
155
+ currentInterval += 5;
156
+ continue;
157
+ }
158
+ if (result.status === 'pending') {
159
+ continue;
160
+ }
161
+ // Terminal error
162
+ throw new Error(`auth failed [${result.code}]: ${result.message}`);
163
+ }
164
+ throw new Error('Device code expired. Run `oneie auth login` to try again.');
165
+ }
166
+ // ---------------------------------------------------------------------------
167
+ // Internal helpers
168
+ // ---------------------------------------------------------------------------
169
+ function sleep(ms) {
170
+ return new Promise((resolve) => setTimeout(resolve, ms));
171
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function groupCmd(): Command;
@@ -0,0 +1,137 @@
1
+ import { Command } from 'commander';
2
+ import { createReadStream, existsSync } from 'node:fs';
3
+ import { createInterface } from 'node:readline';
4
+ import { homedir } from 'node:os';
5
+ import { resolve } from 'node:path';
6
+ import { readFileSync } from 'node:fs';
7
+ const DEFAULT_API = 'https://one.ie';
8
+ const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
9
+ function readApiKey() {
10
+ if (process.env.ONEIE_API_KEY)
11
+ return process.env.ONEIE_API_KEY;
12
+ if (existsSync(KEY_FILE))
13
+ return readFileSync(KEY_FILE, 'utf8').trim() || null;
14
+ return null;
15
+ }
16
+ function out(cmd, data) {
17
+ const isJson = cmd.parent?.parent?.opts().json;
18
+ if (isJson) {
19
+ process.stdout.write(JSON.stringify(data) + '\n');
20
+ }
21
+ else if (data.ok) {
22
+ const pairs = Object.entries(data)
23
+ .filter(([k]) => k !== 'ok')
24
+ .map(([k, v]) => `${k}=${JSON.stringify(v)}`);
25
+ process.stdout.write(`ok ${pairs.join(' ')}\n`);
26
+ }
27
+ else {
28
+ process.stderr.write(`error ${data.error ?? 'unknown'}\n`);
29
+ process.exit(1);
30
+ }
31
+ }
32
+ async function parseCsv(file) {
33
+ const rows = [];
34
+ const rl = createInterface({ input: createReadStream(file), crlfDelay: Infinity });
35
+ let headers = [];
36
+ let first = true;
37
+ for await (const line of rl) {
38
+ const cells = line.split(',').map((c) => c.trim());
39
+ if (first) {
40
+ headers = cells.map((h) => h.toLowerCase());
41
+ first = false;
42
+ continue;
43
+ }
44
+ if (!cells.length || cells.every((c) => !c))
45
+ continue;
46
+ const row = {};
47
+ headers.forEach((h, i) => { row[h] = cells[i] ?? ''; });
48
+ if (!row.slug && !row.name)
49
+ continue;
50
+ rows.push({ slug: row.slug, name: row.name, contacts: row.contacts || undefined });
51
+ }
52
+ return rows;
53
+ }
54
+ export function groupCmd() {
55
+ const cmd = new Command('group').description('Group management');
56
+ cmd
57
+ .command('bulk-create')
58
+ .description('Bulk-provision Groups from a CSV file (idempotent — skips existing slugs)')
59
+ .requiredOption('--csv <path>', 'CSV file with slug,name[,contacts] columns')
60
+ .option('--segment <segment>', 'ICP segment tag written to each workspace_settings row', 'ICP-1')
61
+ .option('--plan <plan>', 'Billing plan for each group', 'studio')
62
+ .option('--parent <slug>', 'Parent group slug (defaults to authenticated workspace)')
63
+ .option('--batch-size <n>', 'Rows per HTTP batch', '50')
64
+ .option('--api <url>', 'API base URL', DEFAULT_API)
65
+ .option('--dry-run', 'Print plan without writing to D1')
66
+ .action(async (opts) => {
67
+ if (!existsSync(opts.csv)) {
68
+ out(cmd, { ok: false, error: `CSV file not found: ${opts.csv}` });
69
+ return;
70
+ }
71
+ const key = readApiKey();
72
+ if (!key && !opts.dryRun) {
73
+ out(cmd, { ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
74
+ return;
75
+ }
76
+ const rows = await parseCsv(opts.csv);
77
+ if (rows.length === 0) {
78
+ out(cmd, { ok: false, error: 'CSV contains no valid rows (need slug,name columns)' });
79
+ return;
80
+ }
81
+ const batchSize = parseInt(opts.batchSize, 10);
82
+ const base = opts.api.replace(/\/$/, '');
83
+ const endpoint = `${base}/api/provision/bulk`;
84
+ let totalOwners = 0;
85
+ let totalDuplicates = 0;
86
+ let batchN = 0;
87
+ const batches = [];
88
+ for (let i = 0; i < rows.length; i += batchSize)
89
+ batches.push(rows.slice(i, i + batchSize));
90
+ for (const batch of batches) {
91
+ batchN++;
92
+ if (opts.dryRun) {
93
+ process.stdout.write(`[dry-run] batch ${batchN}/${batches.length} rows=${batch.length}\n`);
94
+ totalOwners += batch.length;
95
+ continue;
96
+ }
97
+ const body = {
98
+ rows: batch.map((r) => ({ slug: r.slug, name: r.name })),
99
+ opts: {
100
+ parentSlug: opts.parent,
101
+ plan: opts.plan,
102
+ segment: opts.segment,
103
+ },
104
+ };
105
+ const res = await fetch(endpoint, {
106
+ method: 'POST',
107
+ headers: {
108
+ 'Content-Type': 'application/json',
109
+ ...(key ? { Authorization: `Bearer ${key}` } : {}),
110
+ },
111
+ body: JSON.stringify(body),
112
+ });
113
+ if (!res.ok) {
114
+ const text = await res.text();
115
+ out(cmd, { ok: false, error: `batch ${batchN} failed (${res.status}): ${text}` });
116
+ return;
117
+ }
118
+ const json = (await res.json());
119
+ const created = json.counts?.owners ?? batch.length;
120
+ const dupes = json.duplicates ?? 0;
121
+ totalOwners += created;
122
+ totalDuplicates += dupes;
123
+ process.stdout.write(`batch ${batchN}/${batches.length} created=${created} skipped=${dupes}\n`);
124
+ }
125
+ out(cmd, {
126
+ ok: true,
127
+ total_rows: rows.length,
128
+ created: totalOwners,
129
+ duplicates: totalDuplicates,
130
+ batches: batchN,
131
+ plan: opts.plan,
132
+ segment: opts.segment,
133
+ dry_run: opts.dryRun ?? false,
134
+ });
135
+ });
136
+ return cmd;
137
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { agentCmd } from './agent.js';
4
+ import { skillCmd } from './skill.js';
5
+ import { authCmd } from './auth.js';
6
+ import { devCmd } from './dev.js';
7
+ import { groupCmd } from './group.js';
8
+ import { socialCmd } from './social.js';
9
+ import { substrateCommands } from './substrate.js';
10
+ import { readFileSync } from 'node:fs';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { resolve, dirname } from 'node:path';
13
+ const __dirname = dirname(fileURLToPath(import.meta.url));
14
+ const pkg = JSON.parse(readFileSync(resolve(__dirname, '../../package.json'), 'utf8'));
15
+ const program = new Command()
16
+ .name('oneie')
17
+ .description('ONE — agent CLI')
18
+ .version(pkg.version)
19
+ .option('--json', 'Output structured JSON');
20
+ program.addCommand(agentCmd());
21
+ program.addCommand(skillCmd());
22
+ program.addCommand(authCmd());
23
+ program.addCommand(devCmd());
24
+ program.addCommand(groupCmd());
25
+ program.addCommand(socialCmd());
26
+ substrateCommands(program);
27
+ program.parseAsync(process.argv).catch((err) => {
28
+ const isJson = process.argv.includes('--json');
29
+ if (isJson)
30
+ process.stdout.write(JSON.stringify({ ok: false, error: err.message }) + '\n');
31
+ else
32
+ process.stderr.write(err.message + '\n');
33
+ process.exit(1);
34
+ });
@@ -0,0 +1,14 @@
1
+ export interface Diagnostic {
2
+ level: 'warn' | 'info';
3
+ code: string;
4
+ message: string;
5
+ }
6
+ export interface ParsedSkill {
7
+ meta: Record<string, unknown>;
8
+ body: string;
9
+ diagnostics: Diagnostic[];
10
+ }
11
+ export interface ParseOptions {
12
+ pathStem?: string;
13
+ }
14
+ export declare function parse(md: string, opts?: ParseOptions): ParsedSkill;