@oneie/cli 0.3.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +86 -0
- package/dist/src/agent.js +2 -1
- package/dist/src/args.d.ts +9 -0
- package/dist/src/args.js +61 -0
- package/dist/src/catalog.d.ts +2 -0
- package/dist/src/catalog.js +77 -0
- package/dist/src/client.d.ts +2 -0
- package/dist/src/client.js +98 -0
- package/dist/src/compiler.d.ts +18 -0
- package/dist/src/compiler.js +201 -0
- package/dist/src/config.d.ts +24 -0
- package/dist/src/config.js +70 -0
- package/dist/src/coordinate.d.ts +3 -0
- package/dist/src/coordinate.js +57 -0
- package/dist/src/create.d.ts +2 -0
- package/dist/src/create.js +193 -0
- package/dist/src/deploy.d.ts +2 -0
- package/dist/src/deploy.js +19 -0
- package/dist/src/env.d.ts +3 -0
- package/dist/src/env.js +37 -0
- package/dist/src/eval.d.ts +2 -0
- package/dist/src/eval.js +32 -0
- package/dist/src/fn.d.ts +2 -0
- package/dist/src/fn.js +73 -0
- package/dist/src/index.js +29 -1
- package/dist/src/links.d.ts +5 -0
- package/dist/src/links.js +50 -0
- package/dist/src/push.d.ts +2 -0
- package/dist/src/push.js +57 -0
- package/dist/src/render.d.ts +17 -0
- package/dist/src/render.js +25 -0
- package/dist/src/setup.d.ts +2 -0
- package/dist/src/setup.js +56 -0
- package/dist/src/ship.d.ts +2 -0
- package/dist/src/ship.js +18 -0
- package/dist/src/skill.js +39 -0
- package/dist/src/slug.d.ts +2 -0
- package/dist/src/slug.js +6 -0
- package/dist/src/status.d.ts +2 -0
- package/dist/src/status.js +38 -0
- package/dist/src/templates/_node/site/one.config.d.ts +2 -0
- package/dist/src/templates/_node/site/one.config.js +22 -0
- package/dist/src/trade.d.ts +2 -0
- package/dist/src/trade.js +94 -0
- package/dist/src/trail.d.ts +2 -0
- package/dist/src/trail.js +47 -0
- package/dist/src/validate.d.ts +13 -0
- package/dist/src/validate.js +35 -0
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# ONE License (Version 1.0)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 one.ie
|
|
4
|
+
|
|
5
|
+
## Maximum Freedom, One Obligation
|
|
6
|
+
|
|
7
|
+
This license empowers you with complete commercial freedom to use, reuse, modify, sell and resell the software, AI and data, at any price you wish.
|
|
8
|
+
|
|
9
|
+
No usage limits. No royalty fees. Just pure, unrestricted ability to innovate and profit from the software.
|
|
10
|
+
|
|
11
|
+
You are free to run ONE locally, on your own servers, in the cloud and at the edge.
|
|
12
|
+
|
|
13
|
+
## You Receive
|
|
14
|
+
|
|
15
|
+
### Unlimited Rights
|
|
16
|
+
|
|
17
|
+
You have unrestricted rights to use, modify, license, sublicense, distribute, sell, resell and monetize the Software without restrictions, subject only to the Brand Requirement below.
|
|
18
|
+
|
|
19
|
+
### Permitted Actions
|
|
20
|
+
|
|
21
|
+
Including, but not limited to:
|
|
22
|
+
|
|
23
|
+
- Commercial use and integration into any systems
|
|
24
|
+
- Creation and sale of derivative works
|
|
25
|
+
- Providing software as a service
|
|
26
|
+
- AI training and content generation
|
|
27
|
+
- Patenting innovations based on the Software
|
|
28
|
+
- Open source applications and integrations
|
|
29
|
+
|
|
30
|
+
### License Compatibility
|
|
31
|
+
|
|
32
|
+
This license is compatible with all major open-source licenses, including:
|
|
33
|
+
|
|
34
|
+
- MIT License
|
|
35
|
+
- Apache License
|
|
36
|
+
- GNU General Public License (GPL)
|
|
37
|
+
- BSD Licenses
|
|
38
|
+
- Mozilla Public License
|
|
39
|
+
|
|
40
|
+
### Perpetual Rights
|
|
41
|
+
|
|
42
|
+
These rights are granted in perpetuity and are irrevocable, provided the Brand Requirement is maintained.
|
|
43
|
+
|
|
44
|
+
## Intellectual Property
|
|
45
|
+
|
|
46
|
+
- We retain ownership of the original Software and data.
|
|
47
|
+
- You own any modifications you make.
|
|
48
|
+
- You never have to share your code or data.
|
|
49
|
+
|
|
50
|
+
## Brand Requirement
|
|
51
|
+
|
|
52
|
+
The only obligation is:
|
|
53
|
+
|
|
54
|
+
- Don't remove the ONE brand, logo, and link to https://one.ie/ from the deployed product.
|
|
55
|
+
|
|
56
|
+
To remove the Brand Requirement — white-label, no visible ONE branding — obtain the
|
|
57
|
+
**ONE Enterprise License** (see `LICENSE-ENTERPRISE.md` or contact agent@one.ie).
|
|
58
|
+
|
|
59
|
+
## Liability and Warranty
|
|
60
|
+
|
|
61
|
+
The Software and data is provided "AS IS". We bear no liability for its use.
|
|
62
|
+
|
|
63
|
+
## Termination
|
|
64
|
+
|
|
65
|
+
This license terminates if you remove or hide the ONE brand, logo, or link without
|
|
66
|
+
holding a current ONE Enterprise License.
|
|
67
|
+
|
|
68
|
+
## Governing Law and Disputes
|
|
69
|
+
|
|
70
|
+
This license is governed by the laws of Ireland. The parties will attempt to resolve disputes through good-faith negotiation. If necessary, disputes will proceed to mediation under the Mediators' Institute of Ireland rules, and then to binding arbitration under the Arbitration Act 2010, seated in Dublin, conducted in English.
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
This license is designed to maximize freedom to innovate and profit. There is no copyleft requirement to share any code, making it suitable for enterprise use.
|
|
75
|
+
|
|
76
|
+
## Enterprise Solutions
|
|
77
|
+
|
|
78
|
+
Building something big? We're here to help:
|
|
79
|
+
|
|
80
|
+
- **Free** — use every feature with the ONE brand link in the footer
|
|
81
|
+
- **White-label** — remove the brand requirement (ONE Enterprise License)
|
|
82
|
+
- **Custom** — white-label solutions tailored to your needs
|
|
83
|
+
- **Enterprise** — full support and deployment assistance
|
|
84
|
+
- **Training** — help getting your team started
|
|
85
|
+
|
|
86
|
+
Contact agent@one.ie to share your needs · Learn at https://one.ie/learn · Agents: https://one.ie/llms.txt
|
package/dist/src/agent.js
CHANGED
|
@@ -758,7 +758,8 @@ function compileTarget(content, target) {
|
|
|
758
758
|
const fm = m ? m[1] : '';
|
|
759
759
|
const body = m ? m[2].trim() : content.trim();
|
|
760
760
|
return [
|
|
761
|
-
'//
|
|
761
|
+
'// Generated by ONE — https://one.ie',
|
|
762
|
+
'// `oneie agent compile --target web` — do not edit by hand',
|
|
762
763
|
'',
|
|
763
764
|
'export const frontmatterRaw = ' + JSON.stringify(fm),
|
|
764
765
|
'export const prompt = ' + JSON.stringify(body),
|
package/dist/src/args.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function coerce(v) {
|
|
2
|
+
if (v === 'true')
|
|
3
|
+
return true;
|
|
4
|
+
if (v === 'false')
|
|
5
|
+
return false;
|
|
6
|
+
if (v !== '' && !Number.isNaN(Number(v)))
|
|
7
|
+
return Number(v);
|
|
8
|
+
return v;
|
|
9
|
+
}
|
|
10
|
+
export function parseArgs(rest) {
|
|
11
|
+
const positional = [];
|
|
12
|
+
const flags = {};
|
|
13
|
+
const fromFlags = {};
|
|
14
|
+
let body = {};
|
|
15
|
+
let dryRun = false;
|
|
16
|
+
let simulate = false;
|
|
17
|
+
for (let i = 0; i < rest.length; i++) {
|
|
18
|
+
const tok = rest[i];
|
|
19
|
+
if (tok.startsWith('--')) {
|
|
20
|
+
const eq = tok.indexOf('=');
|
|
21
|
+
const key = (eq === -1 ? tok.slice(2) : tok.slice(2, eq));
|
|
22
|
+
if (key === 'dry-run') {
|
|
23
|
+
dryRun = true;
|
|
24
|
+
flags[key] = true;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (key === 'simulate') {
|
|
28
|
+
simulate = true;
|
|
29
|
+
flags[key] = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
let val;
|
|
33
|
+
if (eq !== -1)
|
|
34
|
+
val = tok.slice(eq + 1);
|
|
35
|
+
else if (i + 1 < rest.length && !rest[i + 1].startsWith('--'))
|
|
36
|
+
val = rest[++i];
|
|
37
|
+
else
|
|
38
|
+
val = true;
|
|
39
|
+
flags[key] = val;
|
|
40
|
+
fromFlags[key] = typeof val === 'string' ? coerce(val) : val;
|
|
41
|
+
}
|
|
42
|
+
else if (tok.trimStart().startsWith('{')) {
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(tok);
|
|
45
|
+
if (parsed && typeof parsed === 'object')
|
|
46
|
+
body = { ...body, ...parsed };
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
throw new Error(`invalid JSON payload: ${tok}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
positional.push(tok);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
body = { ...body, ...fromFlags };
|
|
57
|
+
simulate = simulate || dryRun;
|
|
58
|
+
if (simulate)
|
|
59
|
+
body.simulate = true;
|
|
60
|
+
return { receiver: positional[0], positional, body, dryRun, simulate, flags };
|
|
61
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
2
|
+
function apiKey() {
|
|
3
|
+
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
4
|
+
}
|
|
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
|
+
const RECIPE_BLURB = {
|
|
16
|
+
spine: 'onboard — become an actor, mint a key, declare capability',
|
|
17
|
+
build: 'build a world — workspace, group, actor, thing',
|
|
18
|
+
trade: 'discover peers, hire, get paid',
|
|
19
|
+
transact: 'post a bounty, settle onchain',
|
|
20
|
+
};
|
|
21
|
+
function formatItem(it) {
|
|
22
|
+
const meta = [];
|
|
23
|
+
if (it.cost != null)
|
|
24
|
+
meta.push(`cost: ${typeof it.cost === 'object' ? JSON.stringify(it.cost) : it.cost}`);
|
|
25
|
+
if (it.settles && it.settles !== 'none')
|
|
26
|
+
meta.push(`settles: ${it.settles}`);
|
|
27
|
+
if (it.reversible === false)
|
|
28
|
+
meta.push('reversible: false');
|
|
29
|
+
const tail = meta.length ? ` · ${meta.join(' · ')}` : '';
|
|
30
|
+
return ` ${it.receiver.padEnd(28)}${it.summary ?? ''}${tail}`;
|
|
31
|
+
}
|
|
32
|
+
function formatCatalog(items, goal) {
|
|
33
|
+
if (goal) {
|
|
34
|
+
const match = items.filter((it) => it.receiver.toLowerCase().includes(goal.toLowerCase()));
|
|
35
|
+
if (!match.length)
|
|
36
|
+
return ` (no receivers matching "${goal}")`;
|
|
37
|
+
return `GOAL: ${goal}\n\n` + match.map(formatItem).join('\n');
|
|
38
|
+
}
|
|
39
|
+
const grouped = {};
|
|
40
|
+
for (const it of items) {
|
|
41
|
+
const group = it.receiver.split(':')[0] ?? 'other';
|
|
42
|
+
(grouped[group] ??= []).push(it);
|
|
43
|
+
}
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const [group, groupItems] of Object.entries(grouped)) {
|
|
46
|
+
out.push(`${group.toUpperCase()} — ${RECIPE_BLURB[group] ?? ''}`);
|
|
47
|
+
groupItems.forEach((it) => out.push(formatItem(it)));
|
|
48
|
+
out.push('');
|
|
49
|
+
}
|
|
50
|
+
return out.join('\n');
|
|
51
|
+
}
|
|
52
|
+
export function catalogCommands(program) {
|
|
53
|
+
program
|
|
54
|
+
.command('catalog')
|
|
55
|
+
.description('Browse receiver surface by recipe')
|
|
56
|
+
.option('--goal <text>', 'Filter by receiver group or keyword')
|
|
57
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
58
|
+
.option('--json', 'Output raw JSON')
|
|
59
|
+
.action(async (opts) => {
|
|
60
|
+
const res = await fetch(`${base(opts)}/api/ask/${encodeURIComponent('meta:catalog')}`, {
|
|
61
|
+
method: 'POST',
|
|
62
|
+
headers: authHeaders(),
|
|
63
|
+
body: JSON.stringify({ data: opts.goal ? { goal: opts.goal } : {} }),
|
|
64
|
+
});
|
|
65
|
+
if (!res.ok) {
|
|
66
|
+
process.stderr.write(`meta:catalog → ${res.status}\n`);
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
const data = await res.json();
|
|
70
|
+
if (opts.json) {
|
|
71
|
+
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const items = (data.items ?? data.receivers ?? []);
|
|
75
|
+
process.stdout.write(formatCatalog(items, opts.goal) + '\n');
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { mergeEnv } from './env.js';
|
|
3
|
+
import { readClient } from './config.js';
|
|
4
|
+
import { validateClient } from './validate.js';
|
|
5
|
+
import { safeSlug } from './slug.js';
|
|
6
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
7
|
+
async function ask(base, key, receiver, data) {
|
|
8
|
+
const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: { 'Content-Type': 'application/json', ...(key ? { Authorization: `Bearer ${key}` } : {}) },
|
|
11
|
+
body: JSON.stringify({ data }),
|
|
12
|
+
});
|
|
13
|
+
if (!res.ok) {
|
|
14
|
+
const body = await res.text().catch(() => '');
|
|
15
|
+
throw new Error(`${receiver} → ${res.status}\n${body}`);
|
|
16
|
+
}
|
|
17
|
+
return res.json();
|
|
18
|
+
}
|
|
19
|
+
export function clientCmd() {
|
|
20
|
+
const cmd = new Command('client').description('Manage client nodes');
|
|
21
|
+
cmd.command('add <slug>')
|
|
22
|
+
.description('Atomically provision a managed client node')
|
|
23
|
+
.option('--dry-run', 'Print plan without making substrate calls')
|
|
24
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
25
|
+
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
26
|
+
.action(async (slug, opts) => {
|
|
27
|
+
const dir = process.cwd();
|
|
28
|
+
const env = mergeEnv(dir);
|
|
29
|
+
const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
|
|
30
|
+
const agencySlug = env.AGENCY_SLUG;
|
|
31
|
+
if (!agencySlug) {
|
|
32
|
+
process.stderr.write('AGENCY_SLUG missing — run `one setup` first\n');
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
const config = readClient(`${dir}/clients/${safeSlug(slug)}.toml`);
|
|
36
|
+
const errs = validateClient(config);
|
|
37
|
+
if (errs.length) {
|
|
38
|
+
process.stderr.write(errs.join('\n') + '\n');
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
const request = {
|
|
42
|
+
name: config.name,
|
|
43
|
+
slug: safeSlug(config.slug),
|
|
44
|
+
parent: agencySlug,
|
|
45
|
+
plan: config.plan,
|
|
46
|
+
credit: config.credits,
|
|
47
|
+
markup: config.markup_pct,
|
|
48
|
+
cap: config.monthly_cap ?? null,
|
|
49
|
+
brand: config.brand_lock ?? false,
|
|
50
|
+
agents: config.agents,
|
|
51
|
+
};
|
|
52
|
+
if (opts.dryRun) {
|
|
53
|
+
process.stdout.write(`[dry-run] add ${request.slug} → managed under ${agencySlug} (plan=${config.plan}, credits=${config.credits ?? 0})\n`);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const result = await ask(opts.api.replace(/\/$/, ''), key, 'world:create-workspace', request);
|
|
57
|
+
process.stdout.write(`Added ${request.slug} (managed) → ${String(result.wsid ?? request.slug)}\n`);
|
|
58
|
+
});
|
|
59
|
+
cmd.command('invite <email>')
|
|
60
|
+
.description('Invite a self-serve client (they own the workspace)')
|
|
61
|
+
.option('--slug <slug>', 'Client slug (required)')
|
|
62
|
+
.option('--dry-run', 'Print plan without making substrate calls')
|
|
63
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
64
|
+
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
65
|
+
.action(async (email, opts) => {
|
|
66
|
+
const dir = process.cwd();
|
|
67
|
+
const env = mergeEnv(dir);
|
|
68
|
+
const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
|
|
69
|
+
const agencySlug = env.AGENCY_SLUG;
|
|
70
|
+
if (!agencySlug) {
|
|
71
|
+
process.stderr.write('AGENCY_SLUG missing — run `one setup` first\n');
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
if (!opts.slug) {
|
|
75
|
+
process.stderr.write('--slug required\n');
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
const config = readClient(`${dir}/clients/${safeSlug(opts.slug)}.toml`);
|
|
79
|
+
const request = {
|
|
80
|
+
slug: safeSlug(config.slug),
|
|
81
|
+
name: config.name,
|
|
82
|
+
email,
|
|
83
|
+
plan: config.plan,
|
|
84
|
+
credits: config.credits,
|
|
85
|
+
markup: config.markup_pct,
|
|
86
|
+
cap: config.monthly_cap ?? null,
|
|
87
|
+
brand: config.brand_lock ?? false,
|
|
88
|
+
agents: config.agents,
|
|
89
|
+
};
|
|
90
|
+
if (opts.dryRun) {
|
|
91
|
+
process.stdout.write(`[dry-run] invite ${request.slug} → self-serve (client owns; ${email})\n`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const result = await ask(opts.api.replace(/\/$/, ''), key, 'world:invite-client', request);
|
|
95
|
+
process.stdout.write(`Invite for ${request.slug}: ${String(result.token ?? '(token)')}\n`);
|
|
96
|
+
});
|
|
97
|
+
return cmd;
|
|
98
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface CompileItem {
|
|
2
|
+
path: string;
|
|
3
|
+
receiver: string;
|
|
4
|
+
payload: Record<string, unknown>;
|
|
5
|
+
}
|
|
6
|
+
export interface CompileResult {
|
|
7
|
+
compiled: CompileItem[];
|
|
8
|
+
errors: {
|
|
9
|
+
path: string;
|
|
10
|
+
message: string;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
/** Minimal TOML parser: key="v", key=123, key=true, [section], key=["a","b"] */
|
|
14
|
+
export declare function parseToml(src: string): Record<string, unknown>;
|
|
15
|
+
export declare function compileNode(dir: string, agencySlug: string, opts?: {
|
|
16
|
+
clientSlug?: string;
|
|
17
|
+
dryRun?: boolean;
|
|
18
|
+
}): Promise<CompileResult>;
|
|
@@ -0,0 +1,201 @@
|
|
|
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('#'))
|
|
10
|
+
continue;
|
|
11
|
+
if (line.startsWith('[') && line.endsWith(']')) {
|
|
12
|
+
const key = line.slice(1, -1).trim();
|
|
13
|
+
if (!root[key])
|
|
14
|
+
root[key] = {};
|
|
15
|
+
current = root[key];
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const eq = line.indexOf('=');
|
|
19
|
+
if (eq === -1)
|
|
20
|
+
continue;
|
|
21
|
+
const k = line.slice(0, eq).trim();
|
|
22
|
+
const raw = line.slice(eq + 1).trim();
|
|
23
|
+
if (raw.startsWith('[')) {
|
|
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 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);
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
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();
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
function safeSlug(s) {
|
|
63
|
+
return s.toLowerCase().replace(/[^a-z0-9-]/g, '-').replace(/-+/g, '-').replace(/^-|-$/g, '');
|
|
64
|
+
}
|
|
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);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return [...byBase.values()];
|
|
105
|
+
}
|
|
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 } });
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
errors.push({ path: f, message: String(e) });
|
|
126
|
+
}
|
|
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
|
+
}
|
|
142
|
+
}
|
|
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 } });
|
|
148
|
+
}
|
|
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') } });
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
errors.push({ path: f, message: String(e) });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
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
|
+
}
|
|
168
|
+
}
|
|
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
|
+
}
|
|
180
|
+
}
|
|
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
|
+
}
|
|
194
|
+
}
|
|
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 };
|
|
199
|
+
}
|
|
200
|
+
return { compiled, errors };
|
|
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
|
+
}
|