@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
@@ -1,250 +1,201 @@
1
- /**
2
- * Folder-walking compiler for ONE fractal nodes.
3
- * Walks ai/ + data/ and emits one ask() per file via the REST API.
4
- * Client push: one push clients/<slug> merges clients/<slug>/ over root.
5
- */
6
- import { readdirSync, readFileSync, existsSync } from 'node:fs';
7
- import { resolve, join, basename, dirname } from 'node:path';
8
- import { parseFrontmatter } from './validate.js';
9
- import { namespaced } from './slug.js';
10
- import { readSecret } from './env.js';
11
- /** Minimal TOML parser — supports top-level scalars + array tables ([[section]]). */
12
- export function parseToml(text) {
13
- const result = {};
14
- let currentSection = null;
15
- for (const rawLine of text.split('\n')) {
16
- const line = rawLine.split('#')[0].trim();
17
- if (!line)
1
+ import { readdirSync, readFileSync, statSync, existsSync } from 'node:fs';
2
+ import { join, basename } from 'node:path';
3
+ /** Minimal TOML parser: key="v", key=123, key=true, [section], key=["a","b"] */
4
+ export function parseToml(src) {
5
+ const root = {};
6
+ let current = root;
7
+ for (const rawLine of src.split('\n')) {
8
+ const line = rawLine.trim();
9
+ if (!line || line.startsWith('#'))
18
10
  continue;
19
- if (line.startsWith('[[') && line.endsWith(']]')) {
20
- currentSection = line.slice(2, -2).trim();
21
- if (!Array.isArray(result[currentSection]))
22
- result[currentSection] = [];
23
- result[currentSection].push({});
24
- continue;
25
- }
26
11
  if (line.startsWith('[') && line.endsWith(']')) {
27
- currentSection = null;
12
+ const key = line.slice(1, -1).trim();
13
+ if (!root[key])
14
+ root[key] = {};
15
+ current = root[key];
28
16
  continue;
29
17
  }
30
18
  const eq = line.indexOf('=');
31
- if (eq < 1)
19
+ if (eq === -1)
32
20
  continue;
33
- const key = line.slice(0, eq).trim();
21
+ const k = line.slice(0, eq).trim();
34
22
  const raw = line.slice(eq + 1).trim();
35
- let val;
36
- if (raw === 'true')
37
- val = true;
38
- else if (raw === 'false')
39
- val = false;
40
- else if (!isNaN(Number(raw)) && raw !== '')
41
- val = Number(raw);
42
- else if (raw.startsWith('"') && raw.endsWith('"'))
43
- val = raw.slice(1, -1);
44
- else if (raw.startsWith("'") && raw.endsWith("'"))
45
- val = raw.slice(1, -1);
46
- else if (raw.startsWith('[') && raw.endsWith(']')) {
47
- val = raw.slice(1, -1)
48
- .split(',')
49
- .map(v => v.trim().replace(/^["']|["']$/g, ''))
50
- .filter(Boolean);
23
+ if (raw.startsWith('[')) {
24
+ current[k] = raw.slice(1, raw.lastIndexOf(']')).split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
51
25
  }
26
+ else if (raw === 'true')
27
+ current[k] = true;
28
+ else if (raw === 'false')
29
+ current[k] = false;
30
+ else if (!Number.isNaN(Number(raw)) && raw !== '')
31
+ current[k] = Number(raw);
52
32
  else
53
- val = raw;
54
- if (currentSection) {
55
- const arr = result[currentSection];
56
- if (arr.length > 0)
57
- arr[arr.length - 1][key] = val;
58
- }
59
- else {
60
- result[key] = val;
61
- }
33
+ current[k] = raw.replace(/^["']|["']$/g, '');
34
+ }
35
+ return root;
36
+ }
37
+ function walk(dir, ext) {
38
+ if (!existsSync(dir))
39
+ return [];
40
+ const result = [];
41
+ for (const entry of readdirSync(dir)) {
42
+ const full = join(dir, entry);
43
+ if (statSync(full).isDirectory())
44
+ result.push(...walk(full, ext));
45
+ else if (entry.endsWith(ext) && !entry.startsWith('_'))
46
+ result.push(full);
62
47
  }
63
48
  return result;
64
49
  }
65
- /** Read _node.toml / agency.toml / client.toml from a dir. */
66
- export function readNodeConfig(dir) {
67
- for (const name of ['_node.toml', 'agency.toml', 'client.toml']) {
68
- const p = resolve(dir, name);
69
- if (existsSync(p))
70
- return parseToml(readFileSync(p, 'utf8'));
50
+ function frontmatter(md) {
51
+ const m = md.match(/^---\n([\s\S]*?)\n---/);
52
+ if (!m)
53
+ return {};
54
+ const out = {};
55
+ for (const line of m[1].split('\n')) {
56
+ const kv = line.match(/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/);
57
+ if (kv)
58
+ out[kv[1]] = kv[2].trim();
71
59
  }
72
- return {};
60
+ return out;
73
61
  }
74
- function glob(dir, pattern) {
75
- if (!existsSync(dir))
76
- return [];
77
- return readdirSync(dir, { withFileTypes: true })
78
- .filter(e => e.isFile() && pattern.test(e.name))
79
- .map(e => join(dir, e.name));
62
+ function safeSlug(s) {
63
+ return s.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
80
64
  }
81
- function globDir(dir, pattern) {
82
- if (!existsSync(dir))
83
- return [];
84
- const results = [];
85
- for (const e of readdirSync(dir, { withFileTypes: true })) {
86
- if (e.isDirectory()) {
87
- const sub = join(dir, e.name);
88
- const file = resolve(sub, 'SKILL.md');
89
- if (pattern.test('SKILL.md') && existsSync(file))
90
- results.push(file);
65
+ function namespaced(agency, name) {
66
+ return `${safeSlug(agency)}--${safeSlug(name)}`;
67
+ }
68
+ /** Merge clientSlug's ai/ + data/ over root items by basename. Client file wins. */
69
+ function mergeClient(base, clientDir, slug, agencySlug) {
70
+ if (!existsSync(clientDir))
71
+ return base;
72
+ const byBase = new Map(base.map((item) => [basename(item.path), item]));
73
+ // Walk client dir for any .md and .toml files
74
+ for (const sub of ['ai/agents', 'ai/skills', 'data/lifecycles', 'data/types']) {
75
+ const dir = join(clientDir, sub);
76
+ if (!existsSync(dir))
77
+ continue;
78
+ for (const f of readdirSync(dir)) {
79
+ if (f.startsWith('_'))
80
+ continue;
81
+ const full = join(dir, f);
82
+ if (!statSync(full).isFile())
83
+ continue;
84
+ const content = readFileSync(full, 'utf8');
85
+ // Build a replacement item for this file
86
+ let item = null;
87
+ if (f.endsWith('.md')) {
88
+ const fm = frontmatter(content);
89
+ if (!fm.name)
90
+ continue;
91
+ const name = namespaced(`${agencySlug}--${safeSlug(slug)}`, fm.name);
92
+ const type = sub.includes('agents') ? 'agent' : 'skill';
93
+ item = { path: full, receiver: 'world:create-thing', payload: { name, type, md: content } };
94
+ }
95
+ else if (f.endsWith('.toml') && sub.includes('lifecycles')) {
96
+ const toml = parseToml(content);
97
+ const lifecycle = String(toml.lifecycle ?? basename(f, '.toml'));
98
+ item = { path: full, receiver: 'lifecycle:save', payload: { slug, lifecycle, def: content } };
99
+ }
100
+ if (item)
101
+ byBase.set(f, item);
91
102
  }
92
103
  }
93
- return results;
104
+ return [...byBase.values()];
94
105
  }
95
- async function askApi(ctx, receiver, data) {
96
- const label = `${receiver} (${ctx.slug})`;
97
- if (ctx.dry) {
98
- ctx.skipped.push(`[dry-run] ${label}`);
99
- return;
100
- }
101
- try {
102
- const res = await fetch(`${ctx.base}/api/ask/${encodeURIComponent(receiver)}`, { method: 'POST', headers: ctx.headers, body: JSON.stringify({ data }) });
103
- const body = (await res.json());
104
- if (!res.ok || body.kind === 'failure') {
105
- ctx.errors.push(`${label}: ${body.error ?? res.status}`);
106
+ export async function compileNode(dir, agencySlug, opts) {
107
+ const compiled = [];
108
+ const errors = [];
109
+ // ai/agents/*.md → world:create-thing (agent)
110
+ for (const f of walk(join(dir, 'ai', 'agents'), '.md')) {
111
+ try {
112
+ const md = readFileSync(f, 'utf8');
113
+ const fm = frontmatter(md);
114
+ if (!fm.name) {
115
+ errors.push({ path: f, message: 'frontmatter `name` required' });
116
+ continue;
117
+ }
118
+ if (!fm.description) {
119
+ errors.push({ path: f, message: 'frontmatter `description` required' });
120
+ continue;
121
+ }
122
+ compiled.push({ path: f, receiver: 'world:create-thing', payload: { name: namespaced(agencySlug, fm.name), type: 'agent', md } });
106
123
  }
107
- else {
108
- ctx.pushed.push(label);
124
+ catch (e) {
125
+ errors.push({ path: f, message: String(e) });
109
126
  }
110
127
  }
111
- catch (err) {
112
- ctx.errors.push(`${label}: ${err.message}`);
113
- }
114
- }
115
- async function compileAgents(ctx, aiDir) {
116
- for (const file of glob(join(aiDir, 'agents'), /\.md$/)) {
117
- const { fm, body } = parseFrontmatter(readFileSync(file, 'utf8'));
118
- const rawName = fm['name'] ?? basename(file, '.md');
119
- const name = namespaced(ctx.agencySlug, rawName);
120
- await askApi(ctx, 'world:create-thing', {
121
- slug: ctx.slug,
122
- type: 'agent',
123
- name,
124
- description: fm['description'] ?? '',
125
- instructions: body,
126
- model: fm['model'] ?? 'openrouter/auto',
127
- });
128
+ // ai/skills/*/SKILL.md → world:create-thing (skill)
129
+ for (const f of walk(join(dir, 'ai', 'skills'), 'SKILL.md')) {
130
+ try {
131
+ const md = readFileSync(f, 'utf8');
132
+ const fm = frontmatter(md);
133
+ if (!fm.name) {
134
+ errors.push({ path: f, message: 'frontmatter `name` required' });
135
+ continue;
136
+ }
137
+ compiled.push({ path: f, receiver: 'world:create-thing', payload: { name: namespaced(agencySlug, fm.name), type: 'skill', md } });
138
+ }
139
+ catch (e) {
140
+ errors.push({ path: f, message: String(e) });
141
+ }
128
142
  }
129
- }
130
- async function compileSkills(ctx, aiDir) {
131
- for (const file of globDir(join(aiDir, 'skills'), /SKILL\.md/)) {
132
- const { fm, body } = parseFrontmatter(readFileSync(file, 'utf8'));
133
- const rawName = fm['name'] ?? basename(dirname(file));
134
- const name = namespaced(ctx.agencySlug, rawName);
135
- await askApi(ctx, 'world:create-thing', {
136
- slug: ctx.slug,
137
- type: 'skill',
138
- name,
139
- description: fm['description'] ?? '',
140
- instructions: body,
141
- });
143
+ // ai/context.md → settings:write
144
+ const contextPath = join(dir, 'ai', 'context.md');
145
+ if (existsSync(contextPath)) {
146
+ const value = readFileSync(contextPath, 'utf8');
147
+ compiled.push({ path: contextPath, receiver: 'settings:write', payload: { slug: agencySlug, key: 'company_context', value } });
142
148
  }
143
- }
144
- async function compileContext(ctx, aiDir) {
145
- const file = resolve(aiDir, 'context.md');
146
- if (!existsSync(file))
147
- return;
148
- const value = readFileSync(file, 'utf8').trim();
149
- await askApi(ctx, 'settings:write', { slug: ctx.slug, key: 'company_context', value });
150
- }
151
- async function compileTools(ctx, aiDir) {
152
- for (const file of glob(join(aiDir, 'tools'), /\.toml$/)) {
153
- const cfg = parseToml(readFileSync(file, 'utf8'));
154
- const toolkit = String(cfg['toolkit'] ?? basename(file, '.toml'));
155
- const mode = String(cfg['mode'] ?? 'api_key');
156
- if (mode === 'oauth') {
157
- ctx.skipped.push(`tools:connect ${toolkit} — OAuth; run: one connect ${toolkit} --for ${ctx.slug}`);
158
- continue;
149
+ // ai/tools/*.toml → tools:connect
150
+ for (const f of walk(join(dir, 'ai', 'tools'), '.toml')) {
151
+ try {
152
+ const toml = parseToml(readFileSync(f, 'utf8'));
153
+ compiled.push({ path: f, receiver: 'tools:connect', payload: { slug: agencySlug, toolkit: String(toml.toolkit ?? basename(f, '.toml')), mode: String(toml.mode ?? 'api') } });
159
154
  }
160
- const envVar = String(cfg['env_var'] ?? '');
161
- const credential = envVar ? readSecret(envVar) : '';
162
- if (!credential) {
163
- ctx.skipped.push(`tools:connect ${toolkit} — ${envVar} not set in .env.local or env`);
164
- continue;
155
+ catch (e) {
156
+ errors.push({ path: f, message: String(e) });
165
157
  }
166
- await askApi(ctx, 'tools:connect', { slug: ctx.slug, toolkit, credentials: { api_key: credential } });
167
158
  }
168
- }
169
- async function compileLifecycles(ctx, dataDir) {
170
- for (const file of glob(join(dataDir, 'lifecycles'), /\.toml$/)) {
171
- const raw = parseToml(readFileSync(file, 'utf8'));
172
- const lifecycle = basename(file, '.toml');
173
- const def = {
174
- id: String(raw['id'] ?? lifecycle),
175
- name: String(raw['name'] ?? lifecycle),
176
- version: Number(raw['version'] ?? 1),
177
- monotonic: Boolean(raw['monotonic'] ?? true),
178
- stages: (raw['stages'] ?? []).map(s => ({
179
- id: String(s['id'] ?? ''),
180
- label: String(s['label'] ?? ''),
181
- tag: String(s['tag'] ?? `lifecycle:${lifecycle}:${s['id']}`),
182
- slot: Number(s['slot'] ?? 0),
183
- subSteps: (s['sub_steps'] ?? []),
184
- enter_when: (s['enter_when'] == null || s['enter_when'] === 'null')
185
- ? null : String(s['enter_when']),
186
- })),
187
- transitions: (raw['transitions'] ?? []).map(t => ({
188
- source: String(t['source'] ?? ''),
189
- target: String(t['target'] ?? ''),
190
- kind: String(t['kind'] ?? 'forward'),
191
- })),
192
- arcs: (raw['arcs'] ?? []).map(a => ({
193
- row: Number(a['row'] ?? 0),
194
- label: String(a['label'] ?? ''),
195
- })),
196
- };
197
- await askApi(ctx, 'lifecycle:save', { slug: ctx.slug, lifecycle, def });
159
+ // data/types/*.toml → world:declare-types
160
+ for (const f of walk(join(dir, 'data', 'types'), '.toml')) {
161
+ try {
162
+ const toml = parseToml(readFileSync(f, 'utf8'));
163
+ compiled.push({ path: f, receiver: 'world:declare-types', payload: { slug: agencySlug, types: toml } });
164
+ }
165
+ catch (e) {
166
+ errors.push({ path: f, message: String(e) });
167
+ }
198
168
  }
199
- }
200
- async function compileTypes(ctx, dataDir) {
201
- for (const file of glob(join(dataDir, 'types'), /\.toml$/)) {
202
- const cfg = parseToml(readFileSync(file, 'utf8'));
203
- await askApi(ctx, 'world:declare-types', { slug: ctx.slug, types: cfg });
169
+ // data/lifecycles/*.toml → lifecycle:save
170
+ for (const f of walk(join(dir, 'data', 'lifecycles'), '.toml')) {
171
+ try {
172
+ const src = readFileSync(f, 'utf8');
173
+ const toml = parseToml(src);
174
+ const lifecycle = String(toml.lifecycle ?? basename(f, '.toml'));
175
+ compiled.push({ path: f, receiver: 'lifecycle:save', payload: { slug: agencySlug, lifecycle, def: src } });
176
+ }
177
+ catch (e) {
178
+ errors.push({ path: f, message: String(e) });
179
+ }
204
180
  }
205
- }
206
- /**
207
- * Compile a node directory (root or clients/<slug>).
208
- * `clientDir` is the client override folder; if set, it is merged OVER `rootDir`.
209
- */
210
- export async function compileNode(opts) {
211
- const headers = {
212
- 'Content-Type': 'application/json',
213
- Authorization: `Bearer ${opts.apiKey}`,
214
- };
215
- const ctx = {
216
- base: opts.apiBase,
217
- headers,
218
- slug: opts.targetSlug,
219
- agencySlug: opts.agencySlug,
220
- rootDir: opts.rootDir,
221
- dry: opts.dry,
222
- pushed: [],
223
- skipped: [],
224
- errors: [],
225
- };
226
- // Resolve effective dirs — client overrides root when both exist
227
- const aiDirs = [
228
- join(opts.rootDir, 'ai'),
229
- ...(opts.clientDir ? [join(opts.clientDir, 'ai')] : []),
230
- ];
231
- const dataDirs = [
232
- join(opts.rootDir, 'data'),
233
- ...(opts.clientDir ? [join(opts.clientDir, 'data')] : []),
234
- ];
235
- for (const aiDir of aiDirs) {
236
- if (!existsSync(aiDir))
237
- continue;
238
- await compileAgents(ctx, aiDir);
239
- await compileSkills(ctx, aiDir);
240
- await compileContext(ctx, aiDir);
241
- await compileTools(ctx, aiDir);
181
+ // data/content/contacts.csv → people:create (batch)
182
+ const contactsPath = join(dir, 'data', 'content', 'contacts.csv');
183
+ if (existsSync(contactsPath)) {
184
+ const csv = readFileSync(contactsPath, 'utf8');
185
+ const [headerLine, ...rows] = csv.trim().split('\n');
186
+ const headers = (headerLine ?? '').split(',').map((h) => h.trim());
187
+ const contacts = rows.map((row) => {
188
+ const vals = row.split(',').map((v) => v.trim());
189
+ return Object.fromEntries(headers.map((h, i) => [h, vals[i] ?? '']));
190
+ });
191
+ if (contacts.length > 0) {
192
+ compiled.push({ path: contactsPath, receiver: 'people:create', payload: { slug: agencySlug, contacts } });
193
+ }
242
194
  }
243
- for (const dataDir of dataDirs) {
244
- if (!existsSync(dataDir))
245
- continue;
246
- await compileLifecycles(ctx, dataDir);
247
- await compileTypes(ctx, dataDir);
195
+ // Client inheritance: clients/<slug>/ merges over root by basename
196
+ if (opts?.clientSlug) {
197
+ const clientDir = join(dir, 'clients', opts.clientSlug);
198
+ return { compiled: mergeClient(compiled, clientDir, opts.clientSlug, agencySlug), errors };
248
199
  }
249
- return { pushed: ctx.pushed, skipped: ctx.skipped, errors: ctx.errors };
200
+ return { compiled, errors };
250
201
  }
@@ -0,0 +1,24 @@
1
+ export type Plan = 'free' | 'pro' | 'studio' | 'agency' | 'enterprise';
2
+ export interface AgencyConfig {
3
+ slug: string;
4
+ name: string;
5
+ plan: Plan;
6
+ markup_pct: number;
7
+ brand?: boolean;
8
+ pool?: number;
9
+ }
10
+ export interface ClientConfig {
11
+ name: string;
12
+ slug: string;
13
+ owner?: string;
14
+ plan: Plan;
15
+ markup_pct?: number;
16
+ monthly_cap?: number;
17
+ brand_lock?: boolean;
18
+ credits?: number;
19
+ agents?: string[];
20
+ }
21
+ /** Minimal TOML parser: handles key = "value", key = 123, key = true, [section] headers, key = ["a","b"]. */
22
+ export declare function parseToml(src: string): Record<string, unknown>;
23
+ export declare function readAgency(path?: string): AgencyConfig;
24
+ export declare function readClient(path: string): ClientConfig;
@@ -0,0 +1,70 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ /** Minimal TOML parser: handles key = "value", key = 123, key = true, [section] headers, key = ["a","b"]. */
3
+ export function parseToml(src) {
4
+ const root = {};
5
+ let current = root;
6
+ for (const rawLine of src.split('\n')) {
7
+ const line = rawLine.trim();
8
+ if (!line || line.startsWith('#'))
9
+ continue;
10
+ if (line.startsWith('[') && line.endsWith(']')) {
11
+ const key = line.slice(1, -1).trim();
12
+ if (!root[key])
13
+ root[key] = {};
14
+ current = root[key];
15
+ continue;
16
+ }
17
+ const eq = line.indexOf('=');
18
+ if (eq === -1)
19
+ continue;
20
+ const k = line.slice(0, eq).trim();
21
+ const raw = line.slice(eq + 1).trim();
22
+ if (raw.startsWith('[')) {
23
+ // simple inline array of strings
24
+ current[k] = raw.slice(1, raw.lastIndexOf(']')).split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
25
+ }
26
+ else if (raw === 'true')
27
+ current[k] = true;
28
+ else if (raw === 'false')
29
+ current[k] = false;
30
+ else if (!Number.isNaN(Number(raw)) && raw !== '')
31
+ current[k] = Number(raw);
32
+ else
33
+ current[k] = raw.replace(/^["']|["']$/g, '');
34
+ }
35
+ return root;
36
+ }
37
+ function readToml(path) {
38
+ if (!existsSync(path))
39
+ throw new Error(`not found: ${path}`);
40
+ return parseToml(readFileSync(path, 'utf8'));
41
+ }
42
+ export function readAgency(path = '_node.toml') {
43
+ const raw = readToml(path);
44
+ if (!raw.slug || !raw.name)
45
+ throw new Error(`${path}: 'slug' and 'name' are required`);
46
+ return {
47
+ slug: String(raw.slug),
48
+ name: String(raw.name),
49
+ plan: raw.plan ?? 'agency',
50
+ markup_pct: Number(raw.markup_pct ?? 0),
51
+ brand: Boolean(raw.brand ?? false),
52
+ pool: raw.pool != null ? Number(raw.pool) : undefined,
53
+ };
54
+ }
55
+ export function readClient(path) {
56
+ const raw = readToml(path);
57
+ if (!raw.slug || !raw.name)
58
+ throw new Error(`${path}: 'slug' and 'name' are required`);
59
+ return {
60
+ name: String(raw.name),
61
+ slug: String(raw.slug),
62
+ owner: raw.owner != null ? String(raw.owner) : undefined,
63
+ plan: raw.plan ?? 'studio',
64
+ markup_pct: raw.markup_pct != null ? Number(raw.markup_pct) : undefined,
65
+ monthly_cap: raw.monthly_cap != null ? Number(raw.monthly_cap) : undefined,
66
+ brand_lock: raw.brand_lock != null ? Boolean(raw.brand_lock) : undefined,
67
+ credits: raw.credits != null ? Number(raw.credits) : undefined,
68
+ agents: Array.isArray(raw.agents) ? raw.agents.map(String) : undefined,
69
+ };
70
+ }
@@ -1,3 +1,3 @@
1
- /** `one recall|reputation` — memory and reputation commands. */
2
1
  import { Command } from 'commander';
3
- export declare function coordinateCmd(): Command;
2
+ export declare const REPUTATION_PENDING: string;
3
+ export declare function coordinateCommands(program: Command): void;
@@ -1,71 +1,57 @@
1
- /** `one recall|reputation` — memory and reputation 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)}`, {
9
- method: 'POST',
10
- headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey()}` },
11
- body: JSON.stringify({ data }),
12
- });
13
- return res.json();
5
+ function base(opts) {
6
+ return (opts.api ?? DEFAULT_API).replace(/\/$/, '');
14
7
  }
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 === 'result') {
23
- const r = d.result;
24
- if (Array.isArray(r)) {
25
- for (const item of r) {
26
- process.stdout.write(` ${JSON.stringify(item)}\n`);
27
- }
28
- return;
29
- }
30
- if (typeof r === 'object' && r !== null) {
31
- for (const [k, v] of Object.entries(r)) {
32
- if (typeof v !== 'object')
33
- process.stdout.write(` ${k}: ${v}\n`);
34
- }
35
- return;
36
- }
37
- }
38
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
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;
39
14
  }
40
- export function coordinateCmd() {
41
- const cmd = new Command('coordinate').description('Coordination — memory and reputation');
42
- cmd.command('recall')
43
- .description('Cross-session memory lookup (meta:recall)')
44
- .argument('[about]', 'Optional search term')
45
- .option('--limit <n>', 'Max results', '10')
46
- .option('--api <url>', 'API base URL', DEFAULT_API)
47
- .action(async (about, opts) => {
48
- const base = opts.api.replace(/\/$/, '');
49
- const result = await ask(base, 'meta:recall', { about, limit: Number(opts.limit) });
50
- out(cmd, result);
51
- });
52
- cmd.command('reputation')
53
- .description('Show or signal reputation for an agent')
54
- .argument('[uid]', 'Agent uid to commend (omit to show own reputation)')
55
- .option('--commend', 'Send a commendation signal')
15
+ export const REPUTATION_PENDING = 'reputation: pending — meta:reputation is not yet shipped (agent-first follow-on).\n' +
16
+ ' Standing lives in TypeDB paths; until the receiver lands, one shows no score (no stub).';
17
+ function formatRecall(out) {
18
+ const hyps = (out?.hypotheses ?? []);
19
+ if (!hyps.length)
20
+ return ' (no memory yet — recall returns what this caller has learned)';
21
+ return hyps.map((h) => ` · [${h.status}] ${h.claim}${h.confidence != null ? ` (${h.confidence})` : ''}`).join('\n');
22
+ }
23
+ export function coordinateCommands(program) {
24
+ program
25
+ .command('recall')
26
+ .description('Read cross-session memory (meta:recall)')
27
+ .option('--about <term>', 'Filter by keyword')
28
+ .option('--limit <n>', 'Max results', '20')
56
29
  .option('--api <url>', 'API base URL', DEFAULT_API)
57
- .action(async (uid, opts) => {
58
- const base = opts.api.replace(/\/$/, '');
59
- if (opts.commend && uid) {
60
- const result = await ask(base, 'agents:commend', { uid });
61
- out(cmd, result);
30
+ .option('--json', 'Output raw JSON')
31
+ .action(async (opts) => {
32
+ const payload = { limit: Number(opts.limit) };
33
+ if (opts.about)
34
+ payload.match = opts.about;
35
+ const res = await fetch(`${base(opts)}/api/ask/${encodeURIComponent('meta:recall')}`, {
36
+ method: 'POST',
37
+ headers: authHeaders(),
38
+ body: JSON.stringify({ data: payload }),
39
+ });
40
+ if (!res.ok) {
41
+ process.stderr.write(`meta:recall → ${res.status}\n`);
42
+ process.exit(1);
62
43
  }
63
- else {
64
- const result = await ask(base, 'dashboard:usage', {
65
- slug: uid ?? (process.env.ONEIE_SLUG ?? process.env.ONE_SLUG ?? ''),
66
- });
67
- out(cmd, result);
44
+ const data = await res.json();
45
+ if (opts.json) {
46
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
47
+ return;
68
48
  }
49
+ process.stdout.write(formatRecall(data) + '\n');
50
+ });
51
+ program
52
+ .command('reputation')
53
+ .description('Agent reputation standing (pending)')
54
+ .action(() => {
55
+ process.stdout.write(REPUTATION_PENDING + '\n');
69
56
  });
70
- return cmd;
71
57
  }