@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
package/dist/src/trade.js CHANGED
@@ -1,97 +1,94 @@
1
- /** `one market|hire|bounty|earn|usage` — trade layer commands. */
2
- import { Command } from 'commander';
3
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
1
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
4
2
  function apiKey() {
5
3
  return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
6
4
  }
7
- async function ask(base, receiver, data) {
8
- const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
5
+ function base(opts) {
6
+ return (opts.api ?? DEFAULT_API).replace(/\/$/, '');
7
+ }
8
+ function authHeaders() {
9
+ const h = { 'Content-Type': 'application/json' };
10
+ const k = apiKey();
11
+ if (k)
12
+ h['Authorization'] = `Bearer ${k}`;
13
+ return h;
14
+ }
15
+ async function ask(b, receiver, data) {
16
+ const res = await fetch(`${b}/api/ask/${encodeURIComponent(receiver)}`, {
9
17
  method: 'POST',
10
- headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey()}` },
18
+ headers: authHeaders(),
11
19
  body: JSON.stringify({ data }),
12
20
  });
13
- return res.json();
14
- }
15
- function out(cmd, data) {
16
- const isJson = cmd.parent?.opts()?.json;
17
- if (isJson) {
18
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
19
- return;
20
- }
21
- const d = data;
22
- if (d?.kind === 'failure') {
23
- process.stderr.write(` x ${d?.error ?? 'failed'}\n`);
24
- return;
25
- }
26
- if (d?.kind === 'result') {
27
- const r = d.result;
28
- if (typeof r === 'object' && r !== null) {
29
- for (const [k, v] of Object.entries(r)) {
30
- if (typeof v !== 'object')
31
- process.stdout.write(` ${k}: ${v}\n`);
32
- }
33
- return;
34
- }
21
+ if (!res.ok) {
22
+ process.stderr.write(`${receiver} → ${res.status}\n`);
23
+ process.exit(1);
35
24
  }
36
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
25
+ return res.json();
37
26
  }
38
- export function tradeCmd() {
39
- const cmd = new Command('trade').description('Trade layer — market, hire, bounty, earn, usage');
40
- cmd.command('market')
41
- .description('List the capability market')
42
- .argument('[query]', 'Optional search term')
43
- .option('--limit <n>', 'Max results', '20')
27
+ export function tradeCommands(program) {
28
+ program
29
+ .command('market')
30
+ .description('Discover agents and skills on the market')
31
+ .option('--query <text>', 'Search for agents or skills by keyword')
44
32
  .option('--api <url>', 'API base URL', DEFAULT_API)
45
- .action(async (query, opts) => {
46
- const base = opts.api.replace(/\/$/, '');
47
- const result = await ask(base, 'market:list', { query, limit: Number(opts.limit) });
48
- out(cmd, result);
33
+ .option('--json', 'Output raw JSON')
34
+ .action(async (opts) => {
35
+ const b = base(opts);
36
+ const data = opts.query
37
+ ? await ask(b, 'actors:find', { search: opts.query, type: 'agent' })
38
+ : await ask(b, 'market:list', {});
39
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
49
40
  });
50
- cmd.command('hire <skillId>')
51
- .description('Hire a peer agent for a skill')
52
- .option('--budget <credits>', 'Credit budget', '1000')
53
- .option('--dry-run', 'Simulate (passes simulate:true)')
41
+ program
42
+ .command('hire <skillId>')
43
+ .description('Hire an agent for a skill (use --dry-run to simulate)')
44
+ .option('--dry-run', 'Simulate — no settlement, no cost')
54
45
  .option('--api <url>', 'API base URL', DEFAULT_API)
46
+ .option('--provider <uid>', 'Preferred provider UID')
47
+ .option('--budget <n>', 'Credit budget', '0')
55
48
  .action(async (skillId, opts) => {
56
- const base = opts.api.replace(/\/$/, '');
57
- const result = await ask(base, 'market:hire', {
58
- skillId, budget: Number(opts.budget), simulate: opts.dryRun ?? false,
59
- });
60
- out(cmd, result);
49
+ const payload = { skillId };
50
+ if (opts.provider)
51
+ payload.provider = opts.provider;
52
+ if (opts.budget)
53
+ payload.budget = Number(opts.budget);
54
+ if (opts.dryRun)
55
+ payload.simulate = true;
56
+ const data = await ask(base(opts), 'market:hire', payload);
57
+ if (opts.dryRun)
58
+ process.stdout.write('[dry-run] market:hire simulated — nothing settled\n');
59
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
61
60
  });
62
- cmd.command('bounty <skillId>')
63
- .description('Post a bounty for a skill')
64
- .requiredOption('--price <credits>', 'Bounty price in credits')
65
- .option('--dry-run', 'Simulate (passes simulate:true)')
61
+ program
62
+ .command('bounty <skillId>')
63
+ .description('Post a bounty for a skill (use --dry-run to simulate)')
64
+ .option('--dry-run', 'Simulate — no settlement, no cost')
66
65
  .option('--api <url>', 'API base URL', DEFAULT_API)
66
+ .option('--price <n>', 'Bounty price in credits', '0')
67
67
  .action(async (skillId, opts) => {
68
- const base = opts.api.replace(/\/$/, '');
69
- const result = await ask(base, 'market:bounty', {
70
- skillId, price: Number(opts.price), simulate: opts.dryRun ?? false,
71
- });
72
- out(cmd, result);
68
+ const payload = { skillId, price: Number(opts.price) };
69
+ if (opts.dryRun)
70
+ payload.simulate = true;
71
+ const data = await ask(base(opts), 'market:bounty', payload);
72
+ if (opts.dryRun)
73
+ process.stdout.write('[dry-run] market:bounty simulated — nothing settled\n');
74
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
73
75
  });
74
- cmd.command('earn')
75
- .description('Accept a payment (pay:weight)')
76
- .option('--bounty-id <id>', 'Bounty to settle')
77
- .option('--dry-run', 'Simulate (passes simulate:true)')
76
+ program
77
+ .command('earn')
78
+ .description('Show credit earned summary (pay:weight)')
78
79
  .option('--api <url>', 'API base URL', DEFAULT_API)
80
+ .option('--json', 'Output raw JSON')
79
81
  .action(async (opts) => {
80
- const base = opts.api.replace(/\/$/, '');
81
- const result = await ask(base, 'pay:weight', {
82
- bountyId: opts.bountyId, simulate: opts.dryRun ?? false,
83
- });
84
- out(cmd, result);
82
+ const data = await ask(base(opts), 'pay:weight', {});
83
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
85
84
  });
86
- cmd.command('usage')
87
- .description('Plan metering — credit balance, burns, quota')
88
- .option('--slug <slug>', 'Workspace slug')
85
+ program
86
+ .command('usage')
87
+ .description('Show credit usage dashboard')
89
88
  .option('--api <url>', 'API base URL', DEFAULT_API)
89
+ .option('--json', 'Output raw JSON')
90
90
  .action(async (opts) => {
91
- const base = opts.api.replace(/\/$/, '');
92
- const slug = opts.slug ?? process.env.ONEIE_SLUG ?? process.env.ONE_SLUG ?? '';
93
- const result = await ask(base, 'dashboard:usage', { slug });
94
- out(cmd, result);
91
+ const data = await ask(base(opts), 'dashboard:usage', {});
92
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
95
93
  });
96
- return cmd;
97
94
  }
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare function trailCmd(): Command;
@@ -0,0 +1,47 @@
1
+ import { Command } from 'commander';
2
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://one.ie';
3
+ function apiKey() {
4
+ return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
5
+ }
6
+ export function trailCmd() {
7
+ return new Command('trail')
8
+ .description('read trail confidence for a tag combination — ranked next tasks from KV')
9
+ .argument('<tags>', 'comma-separated tags, e.g. fn:engineering,builds,deploy')
10
+ .option('--workspace <ws>', 'workspace slug', 'global')
11
+ .option('--limit <n>', 'max results', '10')
12
+ .option('--api <url>', 'api base url', DEFAULT_API)
13
+ .action(async (tags, opts) => {
14
+ const base = opts.api.replace(/\/$/, '');
15
+ const key = apiKey();
16
+ const sorted = tags.split(',').map((t) => t.trim()).filter(Boolean).sort().join(',');
17
+ const params = new URLSearchParams({ tags: sorted, workspace: opts.workspace, limit: opts.limit });
18
+ const res = await fetch(`${base}/api/export/trail?${params}`, {
19
+ headers: {
20
+ 'Content-Type': 'application/json',
21
+ ...(key ? { Authorization: `Bearer ${key}` } : {}),
22
+ },
23
+ });
24
+ if (!res.ok) {
25
+ const body = await res.text().catch(() => '');
26
+ process.stderr.write(`trail: ${res.status}\n${body}\n`);
27
+ process.exit(1);
28
+ }
29
+ const data = (await res.json());
30
+ const isJson = process.argv.includes('--json');
31
+ if (isJson) {
32
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
33
+ return;
34
+ }
35
+ process.stdout.write(`fingerprint: ${data.fingerprint}\n`);
36
+ process.stdout.write(`confidence: ${(data.confidence * 100).toFixed(1)}%\n\n`);
37
+ if (!data.tasks.length) {
38
+ process.stdout.write('no trail data for these tags — run some /do cycles with matching tags\n');
39
+ return;
40
+ }
41
+ for (const t of data.tasks) {
42
+ const pct = (t.confidence * 100).toFixed(0).padStart(3);
43
+ const score = t.score.toFixed(2).padStart(6);
44
+ process.stdout.write(` ${pct}% score=${score} ${t.slug}\n`);
45
+ }
46
+ });
47
+ }
@@ -1,12 +1,13 @@
1
- export interface ValidationResult {
2
- ok: boolean;
3
- errors: string[];
4
- warnings: string[];
1
+ export interface ClientShape {
2
+ slug?: string;
3
+ name?: string;
4
+ markup_pct?: number | null;
5
+ monthly_cap?: number | null;
6
+ credits?: number | null;
5
7
  }
6
- /** Validate that `dir` looks like a valid node root. */
7
- export declare function validateNodeDir(dir: string): ValidationResult;
8
- /** Parse YAML-style frontmatter from a Markdown file. */
9
- export declare function parseFrontmatter(content: string): {
10
- fm: Record<string, string>;
11
- body: string;
8
+ export declare function validateClient(c: ClientShape): string[];
9
+ export declare function frontmatter(md: string): Record<string, string>;
10
+ export declare function validateAgent(md: string): {
11
+ name: string;
12
+ errors: string[];
12
13
  };
@@ -1,37 +1,35 @@
1
- /** Structural validation for nodes before `one push`. */
2
- import { existsSync } from 'node:fs';
3
- import { resolve } from 'node:path';
4
- /** Validate that `dir` looks like a valid node root. */
5
- export function validateNodeDir(dir) {
6
- const errors = [];
7
- const warnings = [];
8
- const hasToml = existsSync(resolve(dir, '_node.toml')) ||
9
- existsSync(resolve(dir, 'agency.toml')) ||
10
- existsSync(resolve(dir, 'client.toml'));
11
- if (!hasToml) {
12
- errors.push(`No _node.toml / agency.toml / client.toml found in ${dir}`);
13
- }
14
- if (!existsSync(resolve(dir, 'ai'))) {
15
- warnings.push('ai/ directory missing — nothing to push for agents/skills');
16
- }
17
- if (!existsSync(resolve(dir, 'data'))) {
18
- warnings.push('data/ directory missing — nothing to push for types/lifecycles');
19
- }
20
- return { ok: errors.length === 0, errors, warnings };
1
+ export function validateClient(c) {
2
+ const errs = [];
3
+ if (!c.slug)
4
+ errs.push('client: slug required');
5
+ if (!c.name)
6
+ errs.push('client: name required');
7
+ if (c.markup_pct != null && (c.markup_pct < 0 || c.markup_pct > 100))
8
+ errs.push('client: markup_pct must be 0–100');
9
+ if (c.monthly_cap != null && c.monthly_cap < 0)
10
+ errs.push('client: monthly_cap must be ≥ 0');
11
+ if (c.credits != null && c.credits < 0)
12
+ errs.push('client: credits must be ≥ 0');
13
+ return errs;
21
14
  }
22
- /** Parse YAML-style frontmatter from a Markdown file. */
23
- export function parseFrontmatter(content) {
24
- const fm = {};
25
- if (!content.startsWith('---'))
26
- return { fm, body: content };
27
- const end = content.indexOf('\n---', 3);
28
- if (end < 0)
29
- return { fm, body: content };
30
- for (const line of content.slice(3, end).split('\n')) {
31
- const col = line.indexOf(':');
32
- if (col < 0)
33
- continue;
34
- fm[line.slice(0, col).trim()] = line.slice(col + 1).trim();
15
+ export function frontmatter(md) {
16
+ const m = md.match(/^---\n([\s\S]*?)\n---/);
17
+ if (!m)
18
+ return {};
19
+ const out = {};
20
+ for (const line of m[1].split('\n')) {
21
+ const kv = line.match(/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/);
22
+ if (kv)
23
+ out[kv[1]] = kv[2].trim();
35
24
  }
36
- return { fm, body: content.slice(end + 4).trim() };
25
+ return out;
26
+ }
27
+ export function validateAgent(md) {
28
+ const fm = frontmatter(md);
29
+ const errors = [];
30
+ if (!fm.name)
31
+ errors.push('agent: frontmatter `name` required');
32
+ if (!fm.description)
33
+ errors.push('agent: frontmatter `description` required');
34
+ return { name: fm.name ?? '', errors };
37
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -27,7 +27,7 @@
27
27
  "tsx": "^4.0.0",
28
28
  "typescript": "^5.4.0"
29
29
  },
30
- "license": "SEE LICENSE IN https://one.ie/free-license",
30
+ "license": "SEE LICENSE IN LICENSE",
31
31
  "repository": {
32
32
  "type": "git",
33
33
  "url": "git+https://github.com/one-ie/packages.git",