@oneie/cli 0.5.3 → 0.5.4

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.
package/README.md CHANGED
@@ -24,13 +24,15 @@ A ONE node (agency or client) is three folders the CLI compiles to the substrate
24
24
  ```bash
25
25
  one setup # stand up your agency workspace (idempotent)
26
26
  one client add <slug> # provision a managed client (workspace + credits + brand + agents)
27
- one push [clients/<slug>] # compile ai/ + data/ → agents, skills, context, lifecycles, types
27
+ one push [clients/<slug>] # compile ai/ + data/ → agents, skills, context, lifecycles, types, workflows
28
28
  one status # P&L — funded · burned · margin · balance
29
29
  one deploy # wrangler deploy the node's site/
30
30
  ```
31
31
 
32
- `one push` understands TOML array-of-tables (`[[stages]]`, `[[fields]]`) and compiles
33
- `data/lifecycles/*.toml` and `data/types/*.toml` into the shapes the substrate expects.
32
+ `one push` understands TOML array-of-tables (`[[stages]]`, `[[fields]]`), compiles
33
+ `data/lifecycles/*.toml` and `data/types/*.toml` into the shapes the substrate expects, and
34
+ deploys `ai/workflows/*.md` as runnable workflows — the step graph rides in a fenced
35
+ ` ```graph ` block (`{ "steps": [...], "edges": [...] }`), prose above it is human docs.
34
36
 
35
37
  ## Reach the whole surface
36
38
 
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,6 +15,7 @@
15
15
  "build": "tsc && cp package.json dist/ && chmod +x dist/src/index.js",
16
16
  "dev": "tsx src/index.ts",
17
17
  "typecheck": "tsc --noEmit",
18
+ "test": "vitest run",
18
19
  "prepublishOnly": "bun run build"
19
20
  },
20
21
  "dependencies": {
@@ -25,7 +26,8 @@
25
26
  "devDependencies": {
26
27
  "@types/node": "^25.6.0",
27
28
  "tsx": "^4.0.0",
28
- "typescript": "^5.4.0"
29
+ "typescript": "^5.4.0",
30
+ "vitest": "^4.1.6"
29
31
  },
30
32
  "license": "SEE LICENSE IN LICENSE",
31
33
  "repository": {
@@ -2,7 +2,25 @@ export interface CompileItem {
2
2
  path: string;
3
3
  receiver: string;
4
4
  payload: Record<string, unknown>;
5
+ /** Workflow two-phase: after `workflow:create` returns an id, push applies this diff. */
6
+ applyDiff?: {
7
+ add: Record<string, unknown>[];
8
+ connect: Record<string, unknown>[];
9
+ };
5
10
  }
11
+ /**
12
+ * Parse a workflow `.md` into a WorkflowDiff (`{add, connect}` per @oneie/sdk/schemas).
13
+ * The deterministic step graph rides in a fenced ```graph JSON block:
14
+ * { "steps": [{ "id", "kind", "name", "config": {…} }],
15
+ * "edges": [ ["a","b"], { "from":"a", "to":"b", "condition":"…" } ] }
16
+ * Prose above the block is human docs. `config` objects are JSON-stringified (the receiver
17
+ * wants a string). Frontmatter `trigger:` seeds a trigger step when the graph omits one.
18
+ * No graph block → null (the workflow is created as a shell). Unknown kind → throws.
19
+ */
20
+ export declare function parseWorkflowGraph(md: string, fm: Record<string, string>): {
21
+ add: Record<string, unknown>[];
22
+ connect: Record<string, unknown>[];
23
+ } | null;
6
24
  export interface CompileResult {
7
25
  compiled: CompileItem[];
8
26
  errors: {
@@ -1,5 +1,50 @@
1
1
  import { readdirSync, readFileSync, statSync, existsSync } from 'node:fs';
2
2
  import { join, basename } from 'node:path';
3
+ // The 8 LOCKED workflow step kinds (one-ie/CLAUDE.md · @oneie/sdk/schemas StepKind).
4
+ const WORKFLOW_STEP_KINDS = new Set(['trigger', 'tool', 'skill', 'agent', 'condition', 'human', 'delay', 'sell']);
5
+ /**
6
+ * Parse a workflow `.md` into a WorkflowDiff (`{add, connect}` per @oneie/sdk/schemas).
7
+ * The deterministic step graph rides in a fenced ```graph JSON block:
8
+ * { "steps": [{ "id", "kind", "name", "config": {…} }],
9
+ * "edges": [ ["a","b"], { "from":"a", "to":"b", "condition":"…" } ] }
10
+ * Prose above the block is human docs. `config` objects are JSON-stringified (the receiver
11
+ * wants a string). Frontmatter `trigger:` seeds a trigger step when the graph omits one.
12
+ * No graph block → null (the workflow is created as a shell). Unknown kind → throws.
13
+ */
14
+ export function parseWorkflowGraph(md, fm) {
15
+ const m = md.match(/```graph\s*\n([\s\S]*?)```/);
16
+ if (!m)
17
+ return null;
18
+ let graph;
19
+ try {
20
+ graph = JSON.parse(m[1]);
21
+ }
22
+ catch (e) {
23
+ throw new Error(`invalid \`\`\`graph JSON: ${String(e)}`);
24
+ }
25
+ const steps = Array.isArray(graph.steps) ? graph.steps : [];
26
+ const add = steps.map((s) => {
27
+ const kind = String(s.kind ?? '');
28
+ if (!WORKFLOW_STEP_KINDS.has(kind))
29
+ throw new Error(`unknown workflow step kind "${kind}"`);
30
+ const config = typeof s.config === 'string' ? s.config : JSON.stringify(s.config ?? {});
31
+ return { tempId: String(s.id ?? ''), kind, name: String(s.name ?? s.id ?? ''), config };
32
+ });
33
+ const edges = Array.isArray(graph.edges) ? graph.edges : [];
34
+ const connect = edges.map((e) => {
35
+ if (Array.isArray(e))
36
+ return { source: String(e[0]), target: String(e[1]) };
37
+ const o = e;
38
+ return { source: String(o.from), target: String(o.to), ...(o.condition ? { condition: String(o.condition) } : {}) };
39
+ });
40
+ // Seed a trigger from frontmatter when the graph has none, wiring it to the first step.
41
+ if (fm.trigger && !add.some((s) => s.kind === 'trigger')) {
42
+ add.unshift({ tempId: 'trigger', kind: 'trigger', name: String(fm.label ?? 'Trigger'), config: JSON.stringify({ source: fm.trigger }) });
43
+ if (add.length > 1)
44
+ connect.unshift({ source: 'trigger', target: String(add[1].tempId) });
45
+ }
46
+ return { add, connect };
47
+ }
3
48
  /** Minimal TOML parser: key="v", key=123, key=true, [section], key=["a","b"] */
4
49
  export function parseToml(src) {
5
50
  const root = {};
@@ -230,6 +275,22 @@ export async function compileNode(dir, agencySlug, opts) {
230
275
  errors.push({ path: f, message: String(e) });
231
276
  }
232
277
  }
278
+ // ai/workflows/*.md → workflow:create (+ workflow:apply-diff via item.applyDiff, two-phase in push)
279
+ for (const f of walk(join(dir, 'ai', 'workflows'), '.md')) {
280
+ try {
281
+ const md = readFileSync(f, 'utf8');
282
+ const fm = frontmatter(md);
283
+ const name = String(fm.label ?? fm.id ?? basename(f, '.md'));
284
+ const item = { path: f, receiver: 'workflow:create', payload: { name, description: String(fm.description ?? '') } };
285
+ const graph = parseWorkflowGraph(md, fm);
286
+ if (graph && graph.add.length)
287
+ item.applyDiff = graph;
288
+ compiled.push(item);
289
+ }
290
+ catch (e) {
291
+ errors.push({ path: f, message: String(e) });
292
+ }
293
+ }
233
294
  // data/content/contacts.csv → people:create (batch)
234
295
  const contactsPath = join(dir, 'data', 'content', 'contacts.csv');
235
296
  if (existsSync(contactsPath)) {
package/dist/src/push.js CHANGED
@@ -5,6 +5,27 @@ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'ht
5
5
  function apiKey(env) {
6
6
  return env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
7
7
  }
8
+ async function ask(base, headers, receiver, data) {
9
+ try {
10
+ const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
11
+ method: 'POST', headers, body: JSON.stringify({ data }),
12
+ });
13
+ if (!res.ok)
14
+ return { ok: false, result: {} };
15
+ const json = (await res.json().catch(() => ({})));
16
+ return { ok: true, result: json.result ?? {} };
17
+ }
18
+ catch {
19
+ return { ok: false, result: {} };
20
+ }
21
+ }
22
+ /** workflow:create resolves the target from requireSlug(ctx), so child workflows need that
23
+ * workspace's own owner key. The configured (possibly parent) key can mint it via the walk. */
24
+ async function mintOwnerKey(base, headers, slug) {
25
+ const r = await ask(base, headers, 'world:mint-owner-key', { slug, label: 'push' });
26
+ const k = r.result.key ?? r.result.ownerKey ?? r.result.scopedKey;
27
+ return typeof k === 'string' && k ? k : null;
28
+ }
8
29
  export function pushCmd() {
9
30
  return new Command('push')
10
31
  .description('Compile ai/ + data/ folders and push to substrate')
@@ -29,8 +50,10 @@ export function pushCmd() {
29
50
  }
30
51
  if (opts.dryRun) {
31
52
  process.stdout.write(`[dry-run] ${compiled.length} item(s) would push:\n`);
32
- for (const item of compiled)
33
- process.stdout.write(` ${item.receiver} ${item.path}\n`);
53
+ for (const item of compiled) {
54
+ const steps = item.applyDiff ? ` (+${item.applyDiff.add.length} steps)` : '';
55
+ process.stdout.write(` ${item.receiver} ${item.path}${steps}\n`);
56
+ }
34
57
  return;
35
58
  }
36
59
  const base = (opts.api ?? DEFAULT_API).replace(/\/$/, '');
@@ -38,17 +61,51 @@ export function pushCmd() {
38
61
  const authHeaders = { 'Content-Type': 'application/json' };
39
62
  if (key)
40
63
  authHeaders['Authorization'] = `Bearer ${key}`;
64
+ const isWorkflow = (i) => i.receiver === 'workflow:create';
41
65
  let ok = 0;
42
- for (const item of compiled) {
66
+ // Standard items (agents, skills, context, lifecycles, types …) — explicit-slug receivers
67
+ // authorize via the ownership walk, so the configured key covers owned child workspaces.
68
+ for (const item of compiled.filter((i) => !isWorkflow(i))) {
43
69
  const res = await fetch(`${base}/api/ask/${encodeURIComponent(item.receiver)}`, {
44
- method: 'POST',
45
- headers: authHeaders,
46
- body: JSON.stringify({ data: item.payload }),
70
+ method: 'POST', headers: authHeaders, body: JSON.stringify({ data: item.payload }),
47
71
  });
48
- if (!res.ok) {
72
+ if (res.ok)
73
+ ok++;
74
+ else
49
75
  process.stderr.write(` failed: ${item.receiver} ${res.status}\n`);
76
+ }
77
+ // Workflows — two-phase (create → apply-diff) under a workspace-owner key, idempotent by name.
78
+ const wfItems = compiled.filter(isWorkflow);
79
+ if (wfItems.length) {
80
+ const wfKey = (await mintOwnerKey(base, authHeaders, agencySlug)) ?? key;
81
+ const wfHeaders = { 'Content-Type': 'application/json', Authorization: `Bearer ${wfKey}` };
82
+ // Existing workflows by name → delete a same-name match before recreating (clean re-push).
83
+ const list = await ask(base, wfHeaders, 'workflow:list', {});
84
+ const rows = (Array.isArray(list.result) ? list.result : (list.result.workflows ?? list.result.items ?? []));
85
+ const byName = new Map();
86
+ for (const w of rows) {
87
+ const n = String(w.name ?? '');
88
+ const id = String(w.id ?? w.workflowId ?? '');
89
+ if (n && id)
90
+ byName.set(n, [...(byName.get(n) ?? []), id]);
50
91
  }
51
- else {
92
+ for (const item of wfItems) {
93
+ const name = String(item.payload.name ?? '');
94
+ for (const id of byName.get(name) ?? [])
95
+ await ask(base, wfHeaders, 'workflow:delete', { workflowId: id });
96
+ const created = await ask(base, wfHeaders, 'workflow:create', item.payload);
97
+ const wid = created.result.workflowId ?? created.result.id;
98
+ if (!created.ok || typeof wid !== 'string') {
99
+ process.stderr.write(` failed: workflow:create ${name}\n`);
100
+ continue;
101
+ }
102
+ if (item.applyDiff) {
103
+ const applied = await ask(base, wfHeaders, 'workflow:apply-diff', { workflowId: wid, diff: item.applyDiff });
104
+ if (!applied.ok || applied.result.ok === false) {
105
+ process.stderr.write(` failed: workflow:apply-diff ${name}\n`);
106
+ continue;
107
+ }
108
+ }
52
109
  ok++;
53
110
  }
54
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "0.5.3",
3
+ "version": "0.5.4",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,6 +15,7 @@
15
15
  "build": "tsc && cp package.json dist/ && chmod +x dist/src/index.js",
16
16
  "dev": "tsx src/index.ts",
17
17
  "typecheck": "tsc --noEmit",
18
+ "test": "vitest run",
18
19
  "prepublishOnly": "bun run build"
19
20
  },
20
21
  "dependencies": {
@@ -25,7 +26,8 @@
25
26
  "devDependencies": {
26
27
  "@types/node": "^25.6.0",
27
28
  "tsx": "^4.0.0",
28
- "typescript": "^5.4.0"
29
+ "typescript": "^5.4.0",
30
+ "vitest": "^4.1.6"
29
31
  },
30
32
  "license": "SEE LICENSE IN LICENSE",
31
33
  "repository": {