@oneie/cli 0.2.1 → 0.3.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.
@@ -0,0 +1,6 @@
1
+ import { Command } from 'commander';
2
+ /** `one broadcast` — operate newsletters from the terminal.
3
+ * Two verbs: list + send. Both hit broadcast:* receivers via ask(); no new route. */
4
+ export declare function broadcastCmd(): Command;
5
+ /** `one newsletter` — pull/push newsletter block trees from the terminal. */
6
+ export declare function newsletterCmd(): Command;
@@ -0,0 +1,156 @@
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 broadcast` — operate newsletters from the terminal.
26
+ * Two verbs: list + send. Both hit broadcast:* receivers via ask(); no new route. */
27
+ export function broadcastCmd() {
28
+ const cmd = new Command('broadcast').description('Operate email broadcasts (newsletters)');
29
+ cmd
30
+ .command('list')
31
+ .description('List broadcasts for the workspace')
32
+ .option('--limit <n>', 'Max results', '20')
33
+ .option('--api <url>', 'API base URL', DEFAULT_API)
34
+ .action(async (opts) => {
35
+ out(await ask(opts.api, 'broadcast:list', { limit: Number(opts.limit) }));
36
+ });
37
+ cmd
38
+ .command('send <id>')
39
+ .description('Send a broadcast now (inline drain, suppression-checked)')
40
+ .option('--api <url>', 'API base URL', DEFAULT_API)
41
+ .action(async (id, opts) => {
42
+ out(await ask(opts.api, 'broadcast:send', { broadcastId: id }));
43
+ });
44
+ return cmd;
45
+ }
46
+ // ---------------------------------------------------------------------------
47
+ // Inline block serialization — mirrors serialize.ts; no Zod dep (CLI rule)
48
+ // ---------------------------------------------------------------------------
49
+ function serializeBlocksMd(blocks) {
50
+ return blocks.map(({ kind, ...rest }) => '```block ' + kind + '\n' + JSON.stringify(rest) + '\n```').join('\n\n');
51
+ }
52
+ function parseBlocksMd(md) {
53
+ const blocks = [];
54
+ const fence = /^```block ([a-z]+)\n([\s\S]*?)\n```$/gm;
55
+ let m;
56
+ while ((m = fence.exec(md)) !== null) {
57
+ const lineNo = md.slice(0, m.index).split('\n').length;
58
+ try {
59
+ const body = JSON.parse(m[2]);
60
+ blocks.push({ kind: m[1], ...body });
61
+ }
62
+ catch (e) {
63
+ throw new Error(`parseBlocks: invalid JSON at line ${lineNo}: ${e instanceof Error ? e.message : e}`);
64
+ }
65
+ }
66
+ return blocks;
67
+ }
68
+ function diffBlocks(before, after) {
69
+ const diffs = [];
70
+ const beforeById = new Map(before.map(b => [b.id, b]));
71
+ const afterById = new Map(after.map(b => [b.id, b]));
72
+ for (const [id, b] of beforeById) {
73
+ if (!afterById.has(id)) {
74
+ diffs.push({ op: '-', kind: b.kind, id });
75
+ }
76
+ }
77
+ for (const [id, a] of afterById) {
78
+ if (!beforeById.has(id)) {
79
+ diffs.push({ op: '+', kind: a.kind, id });
80
+ }
81
+ else {
82
+ const b = beforeById.get(id);
83
+ if (JSON.stringify(b) !== JSON.stringify(a)) {
84
+ diffs.push({ op: '~', kind: a.kind, id });
85
+ }
86
+ }
87
+ }
88
+ return diffs;
89
+ }
90
+ /** `one newsletter` — pull/push newsletter block trees from the terminal. */
91
+ export function newsletterCmd() {
92
+ const cmd = new Command('newsletter').description('Pull and push newsletter component trees');
93
+ cmd
94
+ .command('pull <broadcastId>')
95
+ .description('Fetch a broadcast and print its blocks as markdown')
96
+ .option('--api <url>', 'API base URL', DEFAULT_API)
97
+ .action(async (broadcastId, opts) => {
98
+ const res = await ask(opts.api, 'broadcast:get', { broadcastId });
99
+ const b = res.broadcast;
100
+ if (!b) {
101
+ process.stderr.write(`broadcast:get returned no broadcast\n`);
102
+ process.exit(1);
103
+ }
104
+ if (b.components && Array.isArray(b.components) && b.components.length > 0) {
105
+ process.stdout.write(serializeBlocksMd(b.components) + '\n');
106
+ }
107
+ else if (b.body_md) {
108
+ process.stdout.write(b.body_md + '\n');
109
+ }
110
+ else {
111
+ process.stdout.write('');
112
+ }
113
+ });
114
+ cmd
115
+ .command('push <broadcastId> <file>')
116
+ .description('Parse a markdown file and update broadcast components')
117
+ .option('--api <url>', 'API base URL', DEFAULT_API)
118
+ .option('--test', 'Dry-run: mark update as test_send')
119
+ .action(async (broadcastId, file, opts) => {
120
+ const { readFileSync } = await import('node:fs');
121
+ let md;
122
+ try {
123
+ md = readFileSync(file, 'utf8');
124
+ }
125
+ catch (e) {
126
+ process.stderr.write(`Cannot read ${file}: ${e instanceof Error ? e.message : e}\n`);
127
+ process.exit(1);
128
+ }
129
+ let components;
130
+ try {
131
+ components = parseBlocksMd(md);
132
+ }
133
+ catch (e) {
134
+ process.stderr.write(`${e instanceof Error ? e.message : e}\n`);
135
+ process.exit(1);
136
+ }
137
+ // Fetch current state for diff display
138
+ const current = await ask(opts.api, 'broadcast:get', { broadcastId });
139
+ const prev = (current.broadcast?.components ?? []);
140
+ const version = current.broadcast?.version;
141
+ const diffs = diffBlocks(prev, components);
142
+ for (const d of diffs) {
143
+ process.stdout.write(`${d.op} ${d.kind} (${d.id})\n`);
144
+ }
145
+ if (diffs.length === 0) {
146
+ process.stdout.write('(no changes)\n');
147
+ }
148
+ const payload = { broadcastId, components };
149
+ if (version !== undefined)
150
+ payload['version'] = version;
151
+ if (opts.test)
152
+ payload['test_send'] = true;
153
+ out(await ask(opts.api, 'broadcast:update', payload));
154
+ });
155
+ return cmd;
156
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function connectCmd(): Command;
@@ -0,0 +1,86 @@
1
+ import { Command } from 'commander';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { resolve } from 'node:path';
5
+ const DEFAULT_API = 'https://one.ie';
6
+ const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
7
+ function readApiKey() {
8
+ if (process.env.ONEIE_API_KEY)
9
+ return process.env.ONEIE_API_KEY;
10
+ if (existsSync(KEY_FILE))
11
+ return readFileSync(KEY_FILE, 'utf8').trim() || null;
12
+ return null;
13
+ }
14
+ function out(cmd, data) {
15
+ const isJson = cmd.parent?.parent?.opts().json;
16
+ if (isJson) {
17
+ process.stdout.write(JSON.stringify(data) + '\n');
18
+ }
19
+ else if (data.ok) {
20
+ const pairs = Object.entries(data)
21
+ .filter(([k]) => k !== 'ok')
22
+ .map(([k, v]) => `${k}=${JSON.stringify(v)}`);
23
+ process.stdout.write(`ok ${pairs.join(' ')}\n`);
24
+ }
25
+ else {
26
+ process.stderr.write(`error ${data.error ?? 'unknown'}\n`);
27
+ process.exit(1);
28
+ }
29
+ }
30
+ // `one connect <channel> --token <t>` — token-paste connect. The CLI never
31
+ // implements getMe/setWebhook; it POSTs to the web /api/connect/<channel> route
32
+ // which verifies + hands the secret to channels' sealed sink. The token is sent
33
+ // once in the request body and is NEVER echoed back to stdout (out() prints
34
+ // only the route's response, which carries status + public handle, no secret).
35
+ // With no channel argument it lists connection status (GET /api/connect/status).
36
+ export function connectCmd() {
37
+ const cmd = new Command('connect').description('Connect a channel to your workspace, or list connected channels with no argument');
38
+ cmd
39
+ .argument('[channel]', 'Channel to connect (telegram); omit to list status')
40
+ .option('--token <token>', 'Channel credential (e.g. @BotFather bot token)')
41
+ .option('--slug <slug>', 'Workspace slug (defaults to the authenticated owner)')
42
+ .option('--api <url>', 'API base URL', DEFAULT_API)
43
+ .action(async (channel, opts) => {
44
+ const key = readApiKey();
45
+ if (!key) {
46
+ out(cmd, { ok: false, error: 'no API key — run: oneie auth login' });
47
+ return;
48
+ }
49
+ const base = opts.api.replace(/\/$/, '');
50
+ if (!channel) {
51
+ // status listing — read-only, never carries credentials either way
52
+ const res = await fetch(`${base}/api/connect/status`, {
53
+ headers: { Authorization: `Bearer ${key}` },
54
+ });
55
+ if (!res.ok) {
56
+ const data = (await res.json().catch(() => ({})));
57
+ out(cmd, { ok: false, error: `${res.status}: ${data.error ?? 'status failed'}` });
58
+ return;
59
+ }
60
+ const data = (await res.json());
61
+ const connections = data.connections ?? [];
62
+ out(cmd, { ok: true, connected: connections.length, connections });
63
+ return;
64
+ }
65
+ if (!opts.token) {
66
+ out(cmd, { ok: false, error: 'token required — e.g. one connect telegram --token <t>' });
67
+ return;
68
+ }
69
+ const body = { token: opts.token };
70
+ if (opts.slug)
71
+ body.slug = opts.slug;
72
+ const res = await fetch(`${base}/api/connect/${encodeURIComponent(channel)}`, {
73
+ method: 'POST',
74
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
75
+ body: JSON.stringify(body),
76
+ });
77
+ if (!res.ok) {
78
+ const data = (await res.json().catch(() => ({})));
79
+ out(cmd, { ok: false, error: `${res.status}: ${data.error ?? 'connect failed'}` });
80
+ return;
81
+ }
82
+ const data = (await res.json());
83
+ out(cmd, { ok: true, channel, status: data.status ?? 'active', account: data.username ?? data.inbound });
84
+ });
85
+ return cmd;
86
+ }
@@ -158,8 +158,10 @@ export async function pollForToken(base, clientId, deviceCode, intervalSec, expi
158
158
  if (result.status === 'pending') {
159
159
  continue;
160
160
  }
161
- // Terminal error
162
- throw new Error(`auth failed [${result.code}]: ${result.message}`);
161
+ // Terminal error — narrow off the discriminant so code/message are present
162
+ if (result.status === 'error') {
163
+ throw new Error(`auth failed [${result.code}]: ${result.message}`);
164
+ }
163
165
  }
164
166
  throw new Error('Device code expired. Run `oneie auth login` to try again.');
165
167
  }
package/dist/src/index.js CHANGED
@@ -6,6 +6,9 @@ import { authCmd } from './auth.js';
6
6
  import { devCmd } from './dev.js';
7
7
  import { groupCmd } from './group.js';
8
8
  import { socialCmd } from './social.js';
9
+ import { connectCmd } from './connect.js';
10
+ import { broadcastCmd, newsletterCmd } from './broadcast.js';
11
+ import { staffCmd } from './staff.js';
9
12
  import { substrateCommands } from './substrate.js';
10
13
  import { readFileSync } from 'node:fs';
11
14
  import { fileURLToPath } from 'node:url';
@@ -23,6 +26,10 @@ program.addCommand(authCmd());
23
26
  program.addCommand(devCmd());
24
27
  program.addCommand(groupCmd());
25
28
  program.addCommand(socialCmd());
29
+ program.addCommand(connectCmd());
30
+ program.addCommand(broadcastCmd());
31
+ program.addCommand(newsletterCmd());
32
+ program.addCommand(staffCmd());
26
33
  substrateCommands(program);
27
34
  program.parseAsync(process.argv).catch((err) => {
28
35
  const isJson = process.argv.includes('--json');
package/dist/src/skill.js CHANGED
@@ -271,6 +271,7 @@ export function skillCmd() {
271
271
  });
272
272
  return cmd;
273
273
  }
274
+ // Mirrors one.ie/web/src/lib/eval/evals-source.ts and packages/mcp/src/tools/lifecycle.ts
274
275
  function extractEvals(content) {
275
276
  const fm = content.match(/^---\n([\s\S]*?)\n---/)?.[1];
276
277
  if (!fm)
@@ -279,6 +280,7 @@ function extractEvals(content) {
279
280
  const startIdx = lines.findIndex(l => /^evals:\s*$/.test(l));
280
281
  if (startIdx < 0)
281
282
  return [];
283
+ const unquote = (s) => s.replace(/^["']|["']$/g, '');
282
284
  const cases = [];
283
285
  let cur = null;
284
286
  let inAssertions = false;
@@ -290,23 +292,33 @@ function extractEvals(content) {
290
292
  if (promptMatch) {
291
293
  if (cur)
292
294
  cases.push(cur);
293
- cur = { prompt: promptMatch[1].replace(/^["']|["']$/g, ''), assertions: [] };
295
+ cur = { id: `case-${cases.length + 1}`, prompt: unquote(promptMatch[1]), expected: '', assertions: [] };
294
296
  inAssertions = false;
295
297
  continue;
296
298
  }
297
299
  if (!cur)
298
300
  continue;
301
+ const idMatch = line.match(/^\s+id:\s*(.+?)\s*$/);
302
+ if (idMatch) {
303
+ cur.id = unquote(idMatch[1]);
304
+ continue;
305
+ }
306
+ const expectedMatch = line.match(/^\s+expected:\s*(.+?)\s*$/);
307
+ if (expectedMatch) {
308
+ cur.expected = unquote(expectedMatch[1]);
309
+ continue;
310
+ }
299
311
  if (/^\s+assertions:\s*$/.test(line)) {
300
312
  inAssertions = true;
301
313
  continue;
302
314
  }
303
315
  const itemMatch = line.match(/^\s+-\s+(.+?)\s*$/);
304
316
  if (itemMatch && inAssertions)
305
- cur.assertions.push(itemMatch[1].replace(/^["']|["']$/g, ''));
317
+ cur.assertions.push(unquote(itemMatch[1]));
306
318
  }
307
319
  if (cur)
308
320
  cases.push(cur);
309
- return cases;
321
+ return cases.filter(c => c.prompt && c.assertions.length > 0);
310
322
  }
311
323
  function out(cmd, data) {
312
324
  const isJson = cmd.parent?.opts().json;
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function staffCmd(): Command;
@@ -0,0 +1,73 @@
1
+ import { Command } from 'commander';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { homedir } from 'node:os';
4
+ import { resolve } from 'node:path';
5
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://one.ie';
6
+ const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
7
+ const VALID_ROLES = ['owner', 'admin', 'member', 'viewer'];
8
+ function readApiKey() {
9
+ if (process.env.ONEIE_API_KEY)
10
+ return process.env.ONEIE_API_KEY;
11
+ if (existsSync(KEY_FILE))
12
+ return readFileSync(KEY_FILE, 'utf8').trim() || null;
13
+ return null;
14
+ }
15
+ function out(data) {
16
+ if (data.ok) {
17
+ const pairs = Object.entries(data)
18
+ .filter(([k]) => k !== 'ok')
19
+ .map(([k, v]) => `${k}=${JSON.stringify(v)}`);
20
+ process.stdout.write(`ok ${pairs.join(' ')}\n`);
21
+ }
22
+ else {
23
+ process.stderr.write(`error ${data.error ?? 'unknown'}\n`);
24
+ process.exit(1);
25
+ }
26
+ }
27
+ export function staffCmd() {
28
+ const cmd = new Command('staff').description('Workspace staff management');
29
+ cmd
30
+ .command('invite <email>')
31
+ .description('Invite a human to your workspace by role')
32
+ .option('--role <role>', `Role to assign: ${VALID_ROLES.join('|')}`, 'admin')
33
+ .option('--workspace <slug>', 'Workspace slug (defaults to authenticated workspace)')
34
+ .option('--dry-run', 'Print plan without sending invite')
35
+ .option('--api <url>', 'API base URL', DEFAULT_API)
36
+ .action(async (email, opts) => {
37
+ const role = opts.role;
38
+ if (!VALID_ROLES.includes(role)) {
39
+ out({ ok: false, error: `--role must be one of: ${VALID_ROLES.join(', ')}` });
40
+ return;
41
+ }
42
+ if (opts.dryRun) {
43
+ out({ ok: true, dry_run: true, email, role, workspace: opts.workspace ?? '(authenticated)' });
44
+ return;
45
+ }
46
+ const key = readApiKey();
47
+ if (!key) {
48
+ out({ ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
49
+ return;
50
+ }
51
+ const base = opts.api.replace(/\/$/, '');
52
+ const body = { email, role };
53
+ if (opts.workspace)
54
+ body.workspace = opts.workspace;
55
+ const res = await fetch(`${base}/api/ask/world:invite-member`, {
56
+ method: 'POST',
57
+ headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
58
+ body: JSON.stringify({ data: body }),
59
+ });
60
+ if (!res.ok) {
61
+ const text = await res.text().catch(() => '');
62
+ out({ ok: false, error: `${res.status}: ${text}` });
63
+ return;
64
+ }
65
+ const json = (await res.json());
66
+ if (json.error) {
67
+ out({ ok: false, error: json.error });
68
+ return;
69
+ }
70
+ out({ ok: true, email, role, invite_url: json.inviteUrl ?? json.token ?? '(sent)' });
71
+ });
72
+ return cmd;
73
+ }
@@ -129,7 +129,7 @@ export function substrateCommands(program) {
129
129
  });
130
130
  program
131
131
  .command('select <type>')
132
- .description('Probabilistic path selection (pheromone-weighted)')
132
+ .description('Probabilistic path selection (strength-weighted)')
133
133
  .option('--exploration <n>', 'Exploration factor 0–1')
134
134
  .option('--api <url>', 'API base URL', DEFAULT_API)
135
135
  .action(async (type, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {