@oneie/cli 5.7.6 → 5.8.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 (245) hide show
  1. package/README.md +19 -1
  2. package/dist/package.json +7 -8
  3. package/dist/src/age-yefbe8pe.js +1 -0
  4. package/dist/src/evm-tx-ee2q0e3w.js +1 -0
  5. package/dist/src/hl-run-tgrkrk69.js +1 -0
  6. package/dist/src/index-0rj9wdk9.js +4 -0
  7. package/dist/src/index-91y484c2.js +2052 -0
  8. package/dist/src/index-940y3rnv.js +12 -0
  9. package/dist/src/index.js +1047 -121
  10. package/dist/src/message-key-db1xjdkw.js +1 -0
  11. package/dist/src/message-lock-5vr8079x.js +5 -0
  12. package/dist/src/sweep-order-c2p6rk8c.js +1 -0
  13. package/dist/src/sweep-runner-t68xe7vx.js +1 -0
  14. package/package.json +7 -8
  15. package/dist/src/agent.d.ts +0 -75
  16. package/dist/src/agent.js +0 -1334
  17. package/dist/src/agentverse.d.ts +0 -26
  18. package/dist/src/agentverse.js +0 -171
  19. package/dist/src/args.d.ts +0 -9
  20. package/dist/src/args.js +0 -61
  21. package/dist/src/auth.d.ts +0 -6
  22. package/dist/src/auth.js +0 -121
  23. package/dist/src/balances.d.ts +0 -89
  24. package/dist/src/balances.js +0 -202
  25. package/dist/src/banner.d.ts +0 -1
  26. package/dist/src/banner.js +0 -17
  27. package/dist/src/broadcast.d.ts +0 -8
  28. package/dist/src/broadcast.js +0 -175
  29. package/dist/src/catalog.d.ts +0 -12
  30. package/dist/src/catalog.js +0 -76
  31. package/dist/src/chat.d.ts +0 -2
  32. package/dist/src/chat.js +0 -92
  33. package/dist/src/client.d.ts +0 -5
  34. package/dist/src/client.js +0 -157
  35. package/dist/src/compiler.d.ts +0 -36
  36. package/dist/src/compiler.js +0 -366
  37. package/dist/src/config.d.ts +0 -24
  38. package/dist/src/config.js +0 -70
  39. package/dist/src/connect.d.ts +0 -2
  40. package/dist/src/connect.js +0 -64
  41. package/dist/src/coordinate.d.ts +0 -3
  42. package/dist/src/coordinate.js +0 -58
  43. package/dist/src/create.d.ts +0 -2
  44. package/dist/src/create.js +0 -113
  45. package/dist/src/deploy.d.ts +0 -2
  46. package/dist/src/deploy.js +0 -19
  47. package/dist/src/dev.d.ts +0 -2
  48. package/dist/src/dev.js +0 -75
  49. package/dist/src/device-flow.d.ts +0 -57
  50. package/dist/src/device-flow.js +0 -173
  51. package/dist/src/doctor.d.ts +0 -26
  52. package/dist/src/doctor.js +0 -146
  53. package/dist/src/draw.d.ts +0 -18
  54. package/dist/src/draw.js +0 -156
  55. package/dist/src/endpoint.d.ts +0 -2
  56. package/dist/src/endpoint.js +0 -250
  57. package/dist/src/env.d.ts +0 -3
  58. package/dist/src/env.js +0 -37
  59. package/dist/src/eval.d.ts +0 -2
  60. package/dist/src/eval.js +0 -43
  61. package/dist/src/fn.d.ts +0 -2
  62. package/dist/src/fn.js +0 -70
  63. package/dist/src/group.d.ts +0 -2
  64. package/dist/src/group.js +0 -117
  65. package/dist/src/hl-run.d.ts +0 -119
  66. package/dist/src/hl-run.js +0 -480
  67. package/dist/src/hl.d.ts +0 -17
  68. package/dist/src/hl.js +0 -148
  69. package/dist/src/index.d.ts +0 -2
  70. package/dist/src/init.d.ts +0 -76
  71. package/dist/src/init.js +0 -278
  72. package/dist/src/join.d.ts +0 -11
  73. package/dist/src/join.js +0 -293
  74. package/dist/src/key-publish.d.ts +0 -40
  75. package/dist/src/key-publish.js +0 -232
  76. package/dist/src/key-seal.d.ts +0 -21
  77. package/dist/src/key-seal.js +0 -142
  78. package/dist/src/key-sweep.d.ts +0 -93
  79. package/dist/src/key-sweep.js +0 -263
  80. package/dist/src/key.d.ts +0 -26
  81. package/dist/src/key.js +0 -338
  82. package/dist/src/lib/age-plugin.d.ts +0 -51
  83. package/dist/src/lib/age-plugin.js +0 -130
  84. package/dist/src/lib/agent-env.d.ts +0 -12
  85. package/dist/src/lib/agent-env.js +0 -48
  86. package/dist/src/lib/api-path.d.ts +0 -2
  87. package/dist/src/lib/api-path.js +0 -40
  88. package/dist/src/lib/asker.d.ts +0 -34
  89. package/dist/src/lib/asker.js +0 -126
  90. package/dist/src/lib/client.d.ts +0 -20
  91. package/dist/src/lib/client.js +0 -71
  92. package/dist/src/lib/env-sealed.d.ts +0 -53
  93. package/dist/src/lib/env-sealed.js +0 -184
  94. package/dist/src/lib/flow-tag.d.ts +0 -86
  95. package/dist/src/lib/flow-tag.js +0 -230
  96. package/dist/src/lib/hl-core/actions.d.ts +0 -99
  97. package/dist/src/lib/hl-core/actions.js +0 -69
  98. package/dist/src/lib/hl-core/eip712.d.ts +0 -33
  99. package/dist/src/lib/hl-core/eip712.js +0 -107
  100. package/dist/src/lib/hl-core/errors.d.ts +0 -10
  101. package/dist/src/lib/hl-core/errors.js +0 -15
  102. package/dist/src/lib/hl-core/exchange.d.ts +0 -24
  103. package/dist/src/lib/hl-core/exchange.js +0 -47
  104. package/dist/src/lib/hl-core/index.d.ts +0 -13
  105. package/dist/src/lib/hl-core/index.js +0 -14
  106. package/dist/src/lib/hl-core/meta.d.ts +0 -57
  107. package/dist/src/lib/hl-core/meta.js +0 -110
  108. package/dist/src/lib/hl-core/msgpack.d.ts +0 -18
  109. package/dist/src/lib/hl-core/msgpack.js +0 -136
  110. package/dist/src/lib/hl-core/net.d.ts +0 -2
  111. package/dist/src/lib/hl-core/net.js +0 -7
  112. package/dist/src/lib/hl-core/signing.d.ts +0 -103
  113. package/dist/src/lib/hl-core/signing.js +0 -295
  114. package/dist/src/lib/hl-core/wire.d.ts +0 -34
  115. package/dist/src/lib/hl-core/wire.js +0 -81
  116. package/dist/src/lib/invoked-as.d.ts +0 -2
  117. package/dist/src/lib/invoked-as.js +0 -24
  118. package/dist/src/lib/journey-words.d.ts +0 -84
  119. package/dist/src/lib/journey-words.js +0 -360
  120. package/dist/src/lib/journey.d.ts +0 -148
  121. package/dist/src/lib/journey.js +0 -245
  122. package/dist/src/lib/key-receipt.d.ts +0 -48
  123. package/dist/src/lib/key-receipt.js +0 -116
  124. package/dist/src/lib/key-source.d.ts +0 -9
  125. package/dist/src/lib/key-source.js +0 -33
  126. package/dist/src/lib/keyfile.d.ts +0 -136
  127. package/dist/src/lib/keyfile.js +0 -397
  128. package/dist/src/lib/launch-claude.d.ts +0 -5
  129. package/dist/src/lib/launch-claude.js +0 -45
  130. package/dist/src/lib/lock-lookup.d.ts +0 -40
  131. package/dist/src/lib/lock-lookup.js +0 -92
  132. package/dist/src/lib/message-seal.d.ts +0 -63
  133. package/dist/src/lib/message-seal.js +0 -150
  134. package/dist/src/lib/network.d.ts +0 -15
  135. package/dist/src/lib/network.js +0 -41
  136. package/dist/src/lib/paths.d.ts +0 -41
  137. package/dist/src/lib/paths.js +0 -91
  138. package/dist/src/lib/plan-draw.d.ts +0 -56
  139. package/dist/src/lib/plan-draw.js +0 -219
  140. package/dist/src/lib/plan-live.d.ts +0 -20
  141. package/dist/src/lib/plan-live.js +0 -192
  142. package/dist/src/lib/qr.d.ts +0 -21
  143. package/dist/src/lib/qr.js +0 -402
  144. package/dist/src/lib/roster.d.ts +0 -20
  145. package/dist/src/lib/roster.js +0 -79
  146. package/dist/src/lib/sale-card.d.ts +0 -117
  147. package/dist/src/lib/sale-card.js +0 -261
  148. package/dist/src/lib/shop-init.d.ts +0 -62
  149. package/dist/src/lib/shop-init.js +0 -63
  150. package/dist/src/lib/sui-grpc-send.d.ts +0 -50
  151. package/dist/src/lib/sui-grpc-send.js +0 -89
  152. package/dist/src/lib/swap-core.d.ts +0 -163
  153. package/dist/src/lib/swap-core.js +0 -405
  154. package/dist/src/lib/tasks-digest.d.ts +0 -66
  155. package/dist/src/lib/tasks-digest.js +0 -200
  156. package/dist/src/lib/tasks-graph.d.ts +0 -79
  157. package/dist/src/lib/tasks-graph.js +0 -463
  158. package/dist/src/lib/tasks-lens.d.ts +0 -31
  159. package/dist/src/lib/tasks-lens.js +0 -47
  160. package/dist/src/lib/tasks-next.d.ts +0 -25
  161. package/dist/src/lib/tasks-next.js +0 -103
  162. package/dist/src/lib/tasks-prove.d.ts +0 -15
  163. package/dist/src/lib/tasks-prove.js +0 -68
  164. package/dist/src/lib/tasks-route.d.ts +0 -29
  165. package/dist/src/lib/tasks-route.js +0 -151
  166. package/dist/src/lib/tasks-score.d.ts +0 -36
  167. package/dist/src/lib/tasks-score.js +0 -152
  168. package/dist/src/lib/tasks-workspace.d.ts +0 -18
  169. package/dist/src/lib/tasks-workspace.js +0 -73
  170. package/dist/src/lib/vault-read.d.ts +0 -24
  171. package/dist/src/lib/vault-read.js +0 -77
  172. package/dist/src/lib/vaultfile.d.ts +0 -88
  173. package/dist/src/lib/vaultfile.js +0 -222
  174. package/dist/src/lib/wallet-money.d.ts +0 -222
  175. package/dist/src/lib/wallet-money.js +0 -578
  176. package/dist/src/lib/wallet-request.d.ts +0 -50
  177. package/dist/src/lib/wallet-request.js +0 -86
  178. package/dist/src/links.d.ts +0 -5
  179. package/dist/src/links.js +0 -45
  180. package/dist/src/media.d.ts +0 -29
  181. package/dist/src/media.js +0 -487
  182. package/dist/src/message-receipt.d.ts +0 -25
  183. package/dist/src/message-receipt.js +0 -71
  184. package/dist/src/message.d.ts +0 -13
  185. package/dist/src/message.js +0 -92
  186. package/dist/src/onboard.d.ts +0 -16
  187. package/dist/src/onboard.js +0 -149
  188. package/dist/src/plugin.d.ts +0 -2
  189. package/dist/src/plugin.js +0 -193
  190. package/dist/src/push.d.ts +0 -2
  191. package/dist/src/push.js +0 -115
  192. package/dist/src/render.d.ts +0 -21
  193. package/dist/src/render.js +0 -32
  194. package/dist/src/secrets-device.d.ts +0 -32
  195. package/dist/src/secrets-device.js +0 -127
  196. package/dist/src/secrets-give.d.ts +0 -125
  197. package/dist/src/secrets-give.js +0 -236
  198. package/dist/src/secrets-list.d.ts +0 -27
  199. package/dist/src/secrets-list.js +0 -84
  200. package/dist/src/secrets-run.d.ts +0 -31
  201. package/dist/src/secrets-run.js +0 -182
  202. package/dist/src/secrets.d.ts +0 -33
  203. package/dist/src/secrets.js +0 -200
  204. package/dist/src/setup.d.ts +0 -6
  205. package/dist/src/setup.js +0 -127
  206. package/dist/src/ship.d.ts +0 -2
  207. package/dist/src/ship.js +0 -18
  208. package/dist/src/shop.d.ts +0 -10
  209. package/dist/src/shop.js +0 -110
  210. package/dist/src/skill-parser.d.ts +0 -14
  211. package/dist/src/skill-parser.js +0 -113
  212. package/dist/src/skill.d.ts +0 -2
  213. package/dist/src/skill.js +0 -493
  214. package/dist/src/slug.d.ts +0 -2
  215. package/dist/src/slug.js +0 -6
  216. package/dist/src/social.d.ts +0 -2
  217. package/dist/src/social.js +0 -106
  218. package/dist/src/staff.d.ts +0 -2
  219. package/dist/src/staff.js +0 -104
  220. package/dist/src/start.d.ts +0 -15
  221. package/dist/src/start.js +0 -203
  222. package/dist/src/status.d.ts +0 -2
  223. package/dist/src/status.js +0 -52
  224. package/dist/src/substrate.d.ts +0 -2
  225. package/dist/src/substrate.js +0 -258
  226. package/dist/src/swap.d.ts +0 -93
  227. package/dist/src/swap.js +0 -622
  228. package/dist/src/tasks.d.ts +0 -2
  229. package/dist/src/tasks.js +0 -743
  230. package/dist/src/templates.d.ts +0 -1
  231. package/dist/src/templates.js +0 -213
  232. package/dist/src/trade.d.ts +0 -2
  233. package/dist/src/trade.js +0 -91
  234. package/dist/src/trail.d.ts +0 -2
  235. package/dist/src/trail.js +0 -41
  236. package/dist/src/validate.d.ts +0 -13
  237. package/dist/src/validate.js +0 -35
  238. package/dist/src/wallet-money.d.ts +0 -152
  239. package/dist/src/wallet-money.js +0 -564
  240. package/dist/src/wallet.d.ts +0 -167
  241. package/dist/src/wallet.js +0 -855
  242. package/dist/src/workflow.d.ts +0 -2
  243. package/dist/src/workflow.js +0 -166
  244. package/dist/src/write.d.ts +0 -43
  245. package/dist/src/write.js +0 -180
@@ -1,157 +0,0 @@
1
- import { Command } from 'commander';
2
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
3
- import { mergeEnv } from './env.js';
4
- import { readClient } from './config.js';
5
- import { validateClient } from './validate.js';
6
- import { safeSlug } from './slug.js';
7
- import { askPath } from './lib/api-path.js';
8
- import { renderClientTable } from './render.js';
9
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
10
- /** `clients/<slug>.toml` — the scaffold `client add` reads. Optional keys are
11
- * commented so `readClient()`'s defaults apply until the operator opts in. */
12
- export function clientToml(name, slug) {
13
- return `slug = "${safeSlug(slug)}"
14
- name = "${name}"
15
- plan = "starter"
16
-
17
- # credits = 0
18
- # markup_pct = 0
19
- # monthly_cap = 0
20
- `;
21
- }
22
- async function ask(base, key, receiver, data) {
23
- const res = await fetch(askPath(base, receiver), {
24
- method: 'POST',
25
- headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
26
- body: JSON.stringify({ data }),
27
- });
28
- if (!res.ok) {
29
- const body = await res.text().catch(() => '');
30
- throw new Error(`${receiver} → ${res.status}\n${body}`);
31
- }
32
- const json = await res.json();
33
- // Four-outcome envelope: unwrap { outcome, result } (bare shape passes through).
34
- if (json.outcome === 'failure')
35
- throw new Error(`${receiver} → failure: ${JSON.stringify(json.result ?? {})}`);
36
- return (json.result ?? json);
37
- }
38
- export function clientCmd() {
39
- const cmd = new Command('client').description('Manage client nodes');
40
- cmd.command('new <slug>')
41
- .description('Scaffold clients/<slug>.toml so `client add` works out of the box')
42
- .option('--name <name>', 'Display name (defaults to the slug)')
43
- .action((slug, opts) => {
44
- const dir = process.cwd();
45
- const clean = safeSlug(slug);
46
- const dest = `${dir}/clients/${clean}.toml`;
47
- if (existsSync(dest)) {
48
- process.stderr.write(`already exists: ${dest}\n`);
49
- process.exit(1);
50
- }
51
- mkdirSync(`${dir}/clients`, { recursive: true });
52
- writeFileSync(dest, clientToml(opts.name ?? clean, clean));
53
- process.stdout.write(`Created ${dest}\n one client add ${clean}\n`);
54
- });
55
- cmd.command('list')
56
- .description('The client portfolio (billing:clients)')
57
- .option('--api <url>', 'API base URL', DEFAULT_API)
58
- .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
59
- .option('--json', 'Output raw JSON')
60
- .action(async (opts) => {
61
- const dir = process.cwd();
62
- const env = mergeEnv(dir);
63
- const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
64
- const agencySlug = env.AGENCY_SLUG;
65
- if (!agencySlug) {
66
- process.stderr.write('AGENCY_SLUG missing — run `one setup` first\n');
67
- process.exit(1);
68
- }
69
- // slug required for staff/owner keys — {} resolves the key's personal
70
- // workspace and returns an empty portfolio.
71
- const data = await ask(opts.api.replace(/\/$/, ''), key, 'billing:clients', { slug: agencySlug });
72
- if (opts.json) {
73
- process.stdout.write(JSON.stringify(data, null, 2) + '\n');
74
- return;
75
- }
76
- const clients = (data.clients ?? []);
77
- const markupPct = (data.agency?.markup_pct) ?? 0;
78
- process.stdout.write(renderClientTable(clients, markupPct) + '\n');
79
- });
80
- cmd.command('add <slug>')
81
- .description('Atomically provision a managed client node')
82
- .option('--dry-run', 'Print plan without making substrate calls')
83
- .option('--api <url>', 'API base URL', DEFAULT_API)
84
- .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
85
- .action(async (slug, opts) => {
86
- const dir = process.cwd();
87
- const env = mergeEnv(dir);
88
- const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
89
- const agencySlug = env.AGENCY_SLUG;
90
- if (!agencySlug) {
91
- process.stderr.write('AGENCY_SLUG missing — run `one setup` first\n');
92
- process.exit(1);
93
- }
94
- const config = readClient(`${dir}/clients/${safeSlug(slug)}.toml`);
95
- const errs = validateClient(config);
96
- if (errs.length) {
97
- process.stderr.write(errs.join('\n') + '\n');
98
- process.exit(1);
99
- }
100
- const request = {
101
- name: config.name,
102
- slug: safeSlug(config.slug),
103
- parent: agencySlug,
104
- plan: config.plan,
105
- credit: config.credits,
106
- markup: config.markup_pct,
107
- cap: config.monthly_cap ?? null,
108
- brand: config.brand_lock ?? false,
109
- agents: config.agents,
110
- };
111
- if (opts.dryRun) {
112
- process.stdout.write(`[dry-run] add ${request.slug} → managed under ${agencySlug} (plan=${config.plan}, credits=${config.credits ?? 0})\n`);
113
- return;
114
- }
115
- const result = await ask(opts.api.replace(/\/$/, ''), key, 'world:create-workspace', request);
116
- process.stdout.write(`Added ${request.slug} (managed) → ${String(result.wsid ?? request.slug)}\n`);
117
- });
118
- cmd.command('invite <email>')
119
- .description('Invite a self-serve client (they own the workspace)')
120
- .option('--slug <slug>', 'Client slug (required)')
121
- .option('--dry-run', 'Print plan without making substrate calls')
122
- .option('--api <url>', 'API base URL', DEFAULT_API)
123
- .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
124
- .action(async (email, opts) => {
125
- const dir = process.cwd();
126
- const env = mergeEnv(dir);
127
- const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
128
- const agencySlug = env.AGENCY_SLUG;
129
- if (!agencySlug) {
130
- process.stderr.write('AGENCY_SLUG missing — run `one setup` first\n');
131
- process.exit(1);
132
- }
133
- if (!opts.slug) {
134
- process.stderr.write('--slug required\n');
135
- process.exit(1);
136
- }
137
- const config = readClient(`${dir}/clients/${safeSlug(opts.slug)}.toml`);
138
- const request = {
139
- slug: safeSlug(config.slug),
140
- name: config.name,
141
- email,
142
- plan: config.plan,
143
- credits: config.credits,
144
- markup: config.markup_pct,
145
- cap: config.monthly_cap ?? null,
146
- brand: config.brand_lock ?? false,
147
- agents: config.agents,
148
- };
149
- if (opts.dryRun) {
150
- process.stdout.write(`[dry-run] invite ${request.slug} → self-serve (client owns; ${email})\n`);
151
- return;
152
- }
153
- const result = await ask(opts.api.replace(/\/$/, ''), key, 'world:invite-client', request);
154
- process.stdout.write(`Invite for ${request.slug}: ${String(result.token ?? '(token)')}\n`);
155
- });
156
- return cmd;
157
- }
@@ -1,36 +0,0 @@
1
- export interface CompileItem {
2
- path: string;
3
- receiver: string;
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
- };
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;
24
- export interface CompileResult {
25
- compiled: CompileItem[];
26
- errors: {
27
- path: string;
28
- message: string;
29
- }[];
30
- }
31
- /** Minimal TOML parser: key="v", key=123, key=true, [section], key=["a","b"] */
32
- export declare function parseToml(src: string): Record<string, unknown>;
33
- export declare function compileNode(dir: string, agencySlug: string, opts?: {
34
- clientSlug?: string;
35
- dryRun?: boolean;
36
- }): Promise<CompileResult>;
@@ -1,366 +0,0 @@
1
- import { readdirSync, readFileSync, statSync, existsSync } from 'node:fs';
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
- }
48
- /** Minimal TOML parser: key="v", key=123, key=true, [section], key=["a","b"] */
49
- export function parseToml(src) {
50
- const root = {};
51
- let current = root;
52
- for (const rawLine of src.split('\n')) {
53
- const line = rawLine.trim();
54
- if (!line || line.startsWith('#'))
55
- continue;
56
- if (line.startsWith('[[') && line.endsWith(']]')) {
57
- // Array-of-tables: [[stages]] / [[fields]] — append a fresh item, point at it.
58
- const key = line.slice(2, -2).trim();
59
- if (!Array.isArray(root[key]))
60
- root[key] = [];
61
- const item = {};
62
- root[key].push(item);
63
- current = item;
64
- continue;
65
- }
66
- if (line.startsWith('[') && line.endsWith(']')) {
67
- const key = line.slice(1, -1).trim();
68
- if (!root[key])
69
- root[key] = {};
70
- current = root[key];
71
- continue;
72
- }
73
- const eq = line.indexOf('=');
74
- if (eq === -1)
75
- continue;
76
- const k = line.slice(0, eq).trim();
77
- const raw = line.slice(eq + 1).trim();
78
- if (raw.startsWith('[')) {
79
- current[k] = raw.slice(1, raw.lastIndexOf(']')).split(',').map((s) => s.trim().replace(/^["']|["']$/g, '')).filter(Boolean);
80
- }
81
- else if (raw === 'true')
82
- current[k] = true;
83
- else if (raw === 'false')
84
- current[k] = false;
85
- else if (!Number.isNaN(Number(raw)) && raw !== '')
86
- current[k] = Number(raw);
87
- else
88
- current[k] = raw.replace(/^["']|["']$/g, '');
89
- }
90
- return root;
91
- }
92
- function walk(dir, ext) {
93
- if (!existsSync(dir))
94
- return [];
95
- const result = [];
96
- for (const entry of readdirSync(dir)) {
97
- const full = join(dir, entry);
98
- if (statSync(full).isDirectory())
99
- result.push(...walk(full, ext));
100
- else if (entry.endsWith(ext) && !entry.startsWith('_'))
101
- result.push(full);
102
- }
103
- return result;
104
- }
105
- function frontmatter(md) {
106
- const m = md.match(/^---\n([\s\S]*?)\n---/);
107
- if (!m)
108
- return {};
109
- const out = {};
110
- for (const line of m[1].split('\n')) {
111
- const kv = line.match(/^([A-Za-z_][\w-]*)\s*:\s*(.*)$/);
112
- if (kv)
113
- out[kv[1]] = kv[2].trim();
114
- }
115
- return out;
116
- }
117
- function safeSlug(s) {
118
- return s.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
119
- }
120
- function namespaced(agency, name) {
121
- return `${safeSlug(agency)}--${safeSlug(name)}`;
122
- }
123
- /** Merge clientSlug's ai/ + data/ over root items by basename. Client file wins. */
124
- function mergeClient(base, clientDir, slug, agencySlug) {
125
- if (!existsSync(clientDir))
126
- return base;
127
- const byBase = new Map(base.map((item) => [basename(item.path), item]));
128
- // Walk client dir for any .md and .toml files
129
- for (const sub of ['ai/agents', 'ai/skills', 'data/lifecycles', 'data/types']) {
130
- const dir = join(clientDir, sub);
131
- if (!existsSync(dir))
132
- continue;
133
- for (const f of readdirSync(dir)) {
134
- if (f.startsWith('_'))
135
- continue;
136
- const full = join(dir, f);
137
- if (!statSync(full).isFile())
138
- continue;
139
- const content = readFileSync(full, 'utf8');
140
- // Build a replacement item for this file
141
- let item = null;
142
- if (f.endsWith('.md')) {
143
- const fm = frontmatter(content);
144
- if (!fm.name)
145
- continue;
146
- const name = namespaced(`${agencySlug}--${safeSlug(slug)}`, fm.name);
147
- const type = sub.includes('agents') ? 'agent' : 'skill';
148
- item = { path: full, receiver: 'world:create-thing', payload: { name, type, md: content } };
149
- }
150
- else if (f.endsWith('.toml') && sub.includes('lifecycles')) {
151
- const toml = parseToml(content);
152
- const lifecycle = String(toml.lifecycle ?? basename(f, '.toml'));
153
- item = { path: full, receiver: 'lifecycle:save', payload: { slug, lifecycle, def: content } };
154
- }
155
- if (item)
156
- byBase.set(f, item);
157
- }
158
- }
159
- return [...byBase.values()];
160
- }
161
- export async function compileNode(dir, agencySlug, opts) {
162
- const compiled = [];
163
- const errors = [];
164
- // ai/agents/*.md → world:create-thing (agent)
165
- for (const f of walk(join(dir, 'ai', 'agents'), '.md')) {
166
- try {
167
- // A README is documentation ABOUT the agents beside it, never an agent.
168
- // `ai/agents/templates/README.md` explains the starter org chart, has no
169
- // frontmatter, and was reported as `frontmatter \`name\` required` on every
170
- // push — an error the author cannot fix without deleting the explanation.
171
- if (basename(f).toLowerCase() === 'readme.md')
172
- continue;
173
- const md = readFileSync(f, 'utf8');
174
- const fm = frontmatter(md);
175
- if (!fm.name) {
176
- errors.push({ path: f, message: 'frontmatter `name` required' });
177
- continue;
178
- }
179
- if (!fm.description) {
180
- errors.push({ path: f, message: 'frontmatter `description` required' });
181
- continue;
182
- }
183
- compiled.push({ path: f, receiver: 'world:create-thing', payload: { name: namespaced(agencySlug, fm.name), type: 'agent', md } });
184
- }
185
- catch (e) {
186
- errors.push({ path: f, message: String(e) });
187
- }
188
- }
189
- // ai/skills/*/SKILL.md → world:create-thing (catalog listing) + skill:save (runnable
190
- // body in the workspace R2 catalog — the store skill:run reads, bare name). Without
191
- // the second item a pushed skill exists only as a world_things row and skill:run
192
- // returns skill_not_found (verified live 2026-07-12).
193
- for (const f of walk(join(dir, 'ai', 'skills'), 'SKILL.md')) {
194
- try {
195
- const md = readFileSync(f, 'utf8');
196
- const fm = frontmatter(md);
197
- if (!fm.name) {
198
- errors.push({ path: f, message: 'frontmatter `name` required' });
199
- continue;
200
- }
201
- compiled.push({ path: f, receiver: 'world:create-thing', payload: { name: namespaced(agencySlug, fm.name), type: 'skill', md } });
202
- compiled.push({ path: f, receiver: 'skill:save', payload: { slug: safeSlug(agencySlug), name: safeSlug(fm.name), content: md } });
203
- }
204
- catch (e) {
205
- errors.push({ path: f, message: String(e) });
206
- }
207
- }
208
- // ai/context.md → settings:write
209
- const contextPath = join(dir, 'ai', 'context.md');
210
- if (existsSync(contextPath)) {
211
- const value = readFileSync(contextPath, 'utf8');
212
- compiled.push({ path: contextPath, receiver: 'settings:write', payload: { slug: agencySlug, key: 'company_context', value } });
213
- }
214
- // ai/tools/*.toml → tools:connect
215
- for (const f of walk(join(dir, 'ai', 'tools'), '.toml')) {
216
- try {
217
- const toml = parseToml(readFileSync(f, 'utf8'));
218
- compiled.push({ path: f, receiver: 'tools:connect', payload: { slug: agencySlug, toolkit: String(toml.toolkit ?? basename(f, '.toml')), mode: String(toml.mode ?? 'api') } });
219
- }
220
- catch (e) {
221
- errors.push({ path: f, message: String(e) });
222
- }
223
- }
224
- // data/types/*.toml → world:declare-types
225
- // The receiver wants { group, types: [{ key, label, dimension, type, columns[], fields[] }] }
226
- // with each column/field { field, label, kind(enum) }. The TOML authors { id, label,
227
- // dimension?, [[fields]]{ name, type, label } }; map field.type → a render `kind`.
228
- const TYPE_KIND = {
229
- string: 'text', url: 'text', number: 'number', currency: 'currency', date: 'date',
230
- tags: 'tags', select: 'select', image: 'image', markdown: 'markdown', relation: 'relation', bool: 'select',
231
- };
232
- // ONE call carrying EVERY type, not one call per file. `world:declare-types`
233
- // REPLACES the whole manifest (world-receivers.ts:1953 — `INSERT … ON CONFLICT
234
- // DO UPDATE SET manifest = excluded.manifest`), and push.ts sends compiled
235
- // items sequentially, so a per-file call made every type after the first
236
- // delete the one before it. Measured 2026-09-22 on a two-file fixture:
237
- // `declare-types calls emitted: 2 → ["order"], ["product"]`, push reports
238
- // `Pushed 2/2 item(s).`, and the workspace keeps ONE type. Silent, and it is
239
- // the exact path baas-features.md sells as "declare your types, a full admin
240
- // appears" — so a starter could never ship a type SET. Files are walked in a
241
- // stable order and the batch keeps it, so the manifest order is the file order.
242
- const declaredTypes = [];
243
- const typeFiles = [];
244
- for (const f of walk(join(dir, 'data', 'types'), '.toml')) {
245
- try {
246
- const toml = parseToml(readFileSync(f, 'utf8'));
247
- const rawFields = Array.isArray(toml.fields) ? toml.fields : [];
248
- const cols = rawFields.map((fl) => {
249
- const field = String(fl.name ?? fl.field ?? '');
250
- return {
251
- field,
252
- label: String(fl.label ?? field),
253
- kind: String(fl.kind ?? TYPE_KIND[String(fl.type ?? 'string')] ?? 'text'),
254
- };
255
- });
256
- const key = String(toml.id ?? basename(f, '.toml'));
257
- const type = {
258
- key,
259
- label: String(toml.label ?? key),
260
- dimension: String(toml.dimension ?? 'things'),
261
- type: key,
262
- columns: cols,
263
- fields: cols,
264
- };
265
- declaredTypes.push(type);
266
- typeFiles.push(f);
267
- }
268
- catch (e) {
269
- errors.push({ path: f, message: String(e) });
270
- }
271
- }
272
- if (declaredTypes.length > 0) {
273
- // `path` names every file that fed the batch — a dry-run must still say which
274
- // TOMLs are in play, and an error must be traceable to more than "data/types".
275
- compiled.push({
276
- path: typeFiles.join(', '),
277
- receiver: 'world:declare-types',
278
- payload: { group: agencySlug, types: declaredTypes },
279
- });
280
- }
281
- // data/lifecycles/*.toml → lifecycle:save
282
- // Build the LifecycleDef that the receiver's saveDef() persists. The TOML authors the
283
- // human bits {id,label,tags,description,[[stages]]}; the rest is derived deterministically:
284
- // stage.slot numeric order (the wall loads ORDER BY slot) → the stage index
285
- // stage.tag full namespaced tag lifecycle:<id>:<stageId> (LifecycleStage.tag)
286
- // stage.subSteps always empty — TOML has no sub-step authoring surface
287
- // stage.enter_when optional TOML field, straight through (null when absent) — the
288
- // C7 rule engine grammar (an exact event name or a conversion-stage
289
- // category, e.g. "purchase"/"intent"); the compiler does not validate
290
- // it against event-vocabulary.ts (that package isn't a CLI dependency),
291
- // so an author who wants the stage to self-populate from real traffic
292
- // must use a value the web app's isValidEnterWhen() accepts — a bad
293
- // value just leaves the stage manual-only (evaluate() never matches it).
294
- // stage.goal / principle / band plain string fields, straight through if present
295
- // stage.levers parseToml has no nested array-of-tables, so a lever is one string per
296
- // entry in a bracket list: levers = ["page:/pricing", "agent:one"] —
297
- // "<kind>:<id>", kind ∈ page|workflow|agent|human (LeverKind)
298
- for (const f of walk(join(dir, 'data', 'lifecycles'), '.toml')) {
299
- try {
300
- const toml = parseToml(readFileSync(f, 'utf8'));
301
- const id = String(toml.id ?? toml.lifecycle ?? basename(f, '.toml'));
302
- const rawStages = Array.isArray(toml.stages) ? toml.stages : [];
303
- const stages = rawStages.map((s, i) => {
304
- const stageId = String(s.id ?? '');
305
- const rawLevers = Array.isArray(s.levers) ? s.levers : [];
306
- const levers = rawLevers.map((l) => {
307
- const [kind, ...rest] = l.split(':');
308
- return { kind, id: rest.join(':') };
309
- }).filter((l) => l.kind && l.id);
310
- return {
311
- id: stageId,
312
- label: String(s.label ?? stageId),
313
- tag: `lifecycle:${id}:${stageId}`,
314
- slot: i,
315
- subSteps: [],
316
- enter_when: s.enter_when ? String(s.enter_when) : null,
317
- ...(s.goal ? { goal: String(s.goal) } : {}),
318
- ...(s.principle ? { principle: String(s.principle) } : {}),
319
- ...(s.band ? { band: String(s.band) } : {}),
320
- ...(levers.length > 0 ? { levers } : {}),
321
- };
322
- });
323
- const def = { id, name: String(toml.label ?? id), version: 1, stages, transitions: [], arcs: [], monotonic: true };
324
- compiled.push({ path: f, receiver: 'lifecycle:save', payload: { slug: agencySlug, lifecycle: id, def } });
325
- }
326
- catch (e) {
327
- errors.push({ path: f, message: String(e) });
328
- }
329
- }
330
- // ai/workflows/*.md → workflow:create (+ workflow:apply-diff via item.applyDiff, two-phase in push)
331
- for (const f of walk(join(dir, 'ai', 'workflows'), '.md')) {
332
- try {
333
- const md = readFileSync(f, 'utf8');
334
- const fm = frontmatter(md);
335
- const name = String(fm.label ?? fm.id ?? basename(f, '.md'));
336
- const item = { path: f, receiver: 'workflow:create', payload: { name, description: String(fm.description ?? '') } };
337
- const graph = parseWorkflowGraph(md, fm);
338
- if (graph && graph.add.length)
339
- item.applyDiff = graph;
340
- compiled.push(item);
341
- }
342
- catch (e) {
343
- errors.push({ path: f, message: String(e) });
344
- }
345
- }
346
- // data/content/contacts.csv → people:create (batch)
347
- const contactsPath = join(dir, 'data', 'content', 'contacts.csv');
348
- if (existsSync(contactsPath)) {
349
- const csv = readFileSync(contactsPath, 'utf8');
350
- const [headerLine, ...rows] = csv.trim().split('\n');
351
- const headers = (headerLine ?? '').split(',').map((h) => h.trim());
352
- const contacts = rows.map((row) => {
353
- const vals = row.split(',').map((v) => v.trim());
354
- return Object.fromEntries(headers.map((h, i) => [h, vals[i] ?? '']));
355
- });
356
- if (contacts.length > 0) {
357
- compiled.push({ path: contactsPath, receiver: 'people:create', payload: { slug: agencySlug, contacts } });
358
- }
359
- }
360
- // Client inheritance: clients/<slug>/ merges over root by basename
361
- if (opts?.clientSlug) {
362
- const clientDir = join(dir, 'clients', opts.clientSlug);
363
- return { compiled: mergeClient(compiled, clientDir, opts.clientSlug, agencySlug), errors };
364
- }
365
- return { compiled, errors };
366
- }
@@ -1,24 +0,0 @@
1
- export type Plan = 'starter' | 'free' | 'pro' | '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;
@@ -1,70 +0,0 @@
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 ?? 'free',
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,2 +0,0 @@
1
- import { Command } from 'commander';
2
- export declare function connectCmd(): Command;