@oneie/cli 0.2.1 → 0.3.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,4 @@
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;
@@ -0,0 +1,45 @@
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
+ }
@@ -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,8 @@ 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 } from './broadcast.js';
9
11
  import { substrateCommands } from './substrate.js';
10
12
  import { readFileSync } from 'node:fs';
11
13
  import { fileURLToPath } from 'node:url';
@@ -23,6 +25,8 @@ program.addCommand(authCmd());
23
25
  program.addCommand(devCmd());
24
26
  program.addCommand(groupCmd());
25
27
  program.addCommand(socialCmd());
28
+ program.addCommand(connectCmd());
29
+ program.addCommand(broadcastCmd());
26
30
  substrateCommands(program);
27
31
  program.parseAsync(process.argv).catch((err) => {
28
32
  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;
@@ -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.0",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {