@oneie/cli 0.5.7 → 0.7.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/dist/package.json +1 -1
- package/dist/src/create.js +21 -146
- package/dist/src/init.js +14 -0
- package/dist/src/plugin.js +70 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/src/create.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { mkdirSync,
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync, existsSync } from 'node:fs';
|
|
3
3
|
import { resolve, join } from 'node:path';
|
|
4
4
|
import { spawnSync } from 'node:child_process';
|
|
5
|
-
import { tmpdir } from 'node:os';
|
|
6
5
|
const SAFE_REF = /^[A-Za-z0-9._/-]+$/;
|
|
7
6
|
function downloadTarball(url, targetDir) {
|
|
8
7
|
mkdirSync(targetDir, { recursive: true });
|
|
@@ -20,113 +19,51 @@ function downloadTarball(url, targetDir) {
|
|
|
20
19
|
if (tar.status !== 0)
|
|
21
20
|
throw new Error(`tar failed extracting to ${targetDir}`);
|
|
22
21
|
}
|
|
23
|
-
function downloadSubdir(url, subdir, targetDir) {
|
|
24
|
-
const tmp = mkdtempSync(join(tmpdir(), 'one-create-'));
|
|
25
|
-
try {
|
|
26
|
-
downloadTarball(url, tmp);
|
|
27
|
-
mkdirSync(targetDir, { recursive: true });
|
|
28
|
-
const r = spawnSync('cp', ['-r', join(tmp, subdir, '.'), targetDir], { stdio: 'inherit' });
|
|
29
|
-
if (r.status !== 0)
|
|
30
|
-
throw new Error('cp failed');
|
|
31
|
-
}
|
|
32
|
-
finally {
|
|
33
|
-
spawnSync('rm', ['-rf', tmp]);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
22
|
export function createCmd() {
|
|
37
|
-
const cmd = new Command('create').description('Scaffold a new ONE node
|
|
38
|
-
// ── one create
|
|
23
|
+
const cmd = new Command('create').description('Scaffold a new ONE node');
|
|
24
|
+
// ── one create [name] ───────────────────────────────────────────────────
|
|
25
|
+
// github.com/one-ie/one is itself one node — ai/ data/ site/ workspace.toml
|
|
26
|
+
// at its root — so scaffolding is a plain whole-repo download, no subdir
|
|
27
|
+
// composition. .claude/ + .mcp.json come along for free: open the scaffold
|
|
28
|
+
// in Claude Code and it's connected from its first `git init`.
|
|
39
29
|
cmd
|
|
40
|
-
.command('
|
|
41
|
-
.description('Scaffold a
|
|
30
|
+
.command('node [name]', { isDefault: true })
|
|
31
|
+
.description('Scaffold a ONE business node from github.com/one-ie/one — free plan, no credit card')
|
|
42
32
|
.option('--ref <ref>', 'Git ref to download', 'main')
|
|
43
|
-
.option('--slug <slug>', '
|
|
44
|
-
.option('--name <name>', '
|
|
33
|
+
.option('--slug <slug>', 'Workspace slug (written into workspace.toml)')
|
|
34
|
+
.option('--name <name>', 'Display name (written into workspace.toml)')
|
|
45
35
|
.action((dirName, opts) => {
|
|
46
36
|
if (!SAFE_REF.test(opts.ref)) {
|
|
47
37
|
process.stderr.write(`Invalid ref: ${opts.ref}\n`);
|
|
48
38
|
process.exit(1);
|
|
49
39
|
}
|
|
50
|
-
const label = dirName ?? opts.slug ?? 'my-
|
|
40
|
+
const label = dirName ?? opts.slug ?? 'my-business';
|
|
51
41
|
const dir = resolve(process.cwd(), label);
|
|
52
42
|
if (existsSync(dir)) {
|
|
53
43
|
process.stderr.write(`Directory already exists: ${dir}\n`);
|
|
54
44
|
process.exit(1);
|
|
55
45
|
}
|
|
56
|
-
process.stdout.write(`Creating
|
|
57
|
-
downloadTarball(`https://api.github.com/repos/one-ie/
|
|
58
|
-
|
|
59
|
-
const tomlPath = join(dir, 'agency.toml');
|
|
46
|
+
process.stdout.write(`Creating business node at ${dir}...\n`);
|
|
47
|
+
downloadTarball(`https://api.github.com/repos/one-ie/one/tarball/${opts.ref}`, dir);
|
|
48
|
+
const tomlPath = join(dir, 'workspace.toml');
|
|
60
49
|
if (existsSync(tomlPath) && (opts.slug ?? opts.name)) {
|
|
61
50
|
let toml = readFileSync(tomlPath, 'utf8');
|
|
62
51
|
if (opts.slug)
|
|
63
|
-
toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug
|
|
52
|
+
toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug = "${opts.slug}"`);
|
|
64
53
|
if (opts.name)
|
|
65
|
-
toml = toml.replace(/^name\s*=\s*"[^"]*"/m, `name
|
|
54
|
+
toml = toml.replace(/^name\s*=\s*"[^"]*"/m, `name = "${opts.name}"`);
|
|
66
55
|
writeFileSync(tomlPath, toml);
|
|
67
56
|
}
|
|
68
|
-
process.stdout.write(`\
|
|
57
|
+
process.stdout.write(`\nNode created — free plan, no credit card.\n\n`);
|
|
69
58
|
process.stdout.write(`Next steps:\n`);
|
|
70
59
|
process.stdout.write(` cd ${label}\n`);
|
|
60
|
+
process.stdout.write(` bun install\n`);
|
|
71
61
|
process.stdout.write(` cp .env.example .env.local\n`);
|
|
72
|
-
process.stdout.write(` # Edit .env.local — set
|
|
62
|
+
process.stdout.write(` # Edit .env.local — set WORKSPACE_OWNER_EMAIL\n`);
|
|
73
63
|
if (!opts.slug)
|
|
74
|
-
process.stdout.write(` # Edit
|
|
64
|
+
process.stdout.write(` # Edit workspace.toml — set slug and name\n`);
|
|
75
65
|
process.stdout.write(` one setup\n`);
|
|
76
66
|
});
|
|
77
|
-
// ── one create client <slug> ──────────────────────────────────────────────
|
|
78
|
-
cmd
|
|
79
|
-
.command('client <slug>')
|
|
80
|
-
.description('Scaffold a client node in clients/<slug>/')
|
|
81
|
-
.option('--name <name>', 'Display name for the client')
|
|
82
|
-
.option('--plan <plan>', 'Plan tier', 'studio')
|
|
83
|
-
.action((slug, opts) => {
|
|
84
|
-
const base = resolve(process.cwd(), 'clients', slug);
|
|
85
|
-
if (existsSync(base)) {
|
|
86
|
-
process.stderr.write(`Client already exists: clients/${slug}\n`);
|
|
87
|
-
process.exit(1);
|
|
88
|
-
}
|
|
89
|
-
const displayName = opts.name ?? slug;
|
|
90
|
-
mkdirSync(join(base, 'ai'), { recursive: true });
|
|
91
|
-
mkdirSync(join(base, 'data', 'lifecycles'), { recursive: true });
|
|
92
|
-
mkdirSync(join(base, 'site'), { recursive: true });
|
|
93
|
-
writeFileSync(join(base, 'ai', 'context.md'), `# ${displayName}\n\nAdd company context here — agents read this on every turn.\n`);
|
|
94
|
-
writeFileSync(join(base, 'site', 'one.config.ts'), [
|
|
95
|
-
`import { defineOne } from '@oneie/frontend'`,
|
|
96
|
-
``,
|
|
97
|
-
`export default defineOne({`,
|
|
98
|
-
` backend: { baseUrl: 'https://one.ie' },`,
|
|
99
|
-
` brand: {`,
|
|
100
|
-
` tokens: {`,
|
|
101
|
-
` primary: 'hsl(216 55% 25%)',`,
|
|
102
|
-
` secondary: 'hsl(219 14% 28%)',`,
|
|
103
|
-
` tertiary: 'hsl(105 22% 25%)',`,
|
|
104
|
-
` background: 'hsl(0 0% 93%)',`,
|
|
105
|
-
` foreground: 'hsl(0 0% 100%)',`,
|
|
106
|
-
` font: 'hsl(0 0% 13%)',`,
|
|
107
|
-
` },`,
|
|
108
|
-
` },`,
|
|
109
|
-
` plugins: [`,
|
|
110
|
-
` // auth(),`,
|
|
111
|
-
` // track({ ws: '${slug}' }),`,
|
|
112
|
-
` // chat({ agent: 'your-agent' }),`,
|
|
113
|
-
` ],`,
|
|
114
|
-
`})`,
|
|
115
|
-
].join('\n') + '\n');
|
|
116
|
-
writeFileSync(join(base, 'client.toml'), [
|
|
117
|
-
`slug = "${slug}"`,
|
|
118
|
-
`name = "${displayName}"`,
|
|
119
|
-
`plan = "${opts.plan}"`,
|
|
120
|
-
``,
|
|
121
|
-
`# markup_pct = 15 # override agency default`,
|
|
122
|
-
`# monthly_cap = 50000`,
|
|
123
|
-
].join('\n') + '\n');
|
|
124
|
-
process.stdout.write(`Client node scaffolded: clients/${slug}/\n`);
|
|
125
|
-
process.stdout.write(` ai/context.md — add company context\n`);
|
|
126
|
-
process.stdout.write(` site/one.config.ts — brand tokens (6 tokens rebrand the site)\n`);
|
|
127
|
-
process.stdout.write(` client.toml — plan + economics\n\n`);
|
|
128
|
-
process.stdout.write(`Next: one client add ${slug} [--dry-run]\n`);
|
|
129
|
-
});
|
|
130
67
|
// ── one create partner [name] ────────────────────────────────────────────
|
|
131
68
|
cmd
|
|
132
69
|
.command('partner [name]')
|
|
@@ -165,67 +102,5 @@ export function createCmd() {
|
|
|
165
102
|
process.stdout.write(` # Edit partner.toml — set slug and name\n`);
|
|
166
103
|
process.stdout.write(` one setup\n`);
|
|
167
104
|
});
|
|
168
|
-
// ── one create client-repo [name] ───────────────────────────────────────
|
|
169
|
-
cmd
|
|
170
|
-
.command('client-repo [name]')
|
|
171
|
-
.description('Scaffold a single-business workspace from github.com/one-ie/client')
|
|
172
|
-
.option('--ref <ref>', 'Git ref to download', 'main')
|
|
173
|
-
.option('--slug <slug>', 'Workspace slug (written into workspace.toml)')
|
|
174
|
-
.option('--name <name>', 'Display name (written into workspace.toml)')
|
|
175
|
-
.action((dirName, opts) => {
|
|
176
|
-
if (!SAFE_REF.test(opts.ref)) {
|
|
177
|
-
process.stderr.write(`Invalid ref: ${opts.ref}\n`);
|
|
178
|
-
process.exit(1);
|
|
179
|
-
}
|
|
180
|
-
const label = dirName ?? opts.slug ?? 'my-business';
|
|
181
|
-
const dir = resolve(process.cwd(), label);
|
|
182
|
-
if (existsSync(dir)) {
|
|
183
|
-
process.stderr.write(`Directory already exists: ${dir}\n`);
|
|
184
|
-
process.exit(1);
|
|
185
|
-
}
|
|
186
|
-
process.stdout.write(`Creating client workspace at ${dir}...\n`);
|
|
187
|
-
downloadTarball(`https://api.github.com/repos/one-ie/client/tarball/${opts.ref}`, dir);
|
|
188
|
-
const tomlPath = join(dir, 'workspace.toml');
|
|
189
|
-
if (existsSync(tomlPath) && (opts.slug ?? opts.name)) {
|
|
190
|
-
let toml = readFileSync(tomlPath, 'utf8');
|
|
191
|
-
if (opts.slug)
|
|
192
|
-
toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug = "${opts.slug}"`);
|
|
193
|
-
if (opts.name)
|
|
194
|
-
toml = toml.replace(/^name\s*=\s*"[^"]*"/m, `name = "${opts.name}"`);
|
|
195
|
-
writeFileSync(tomlPath, toml);
|
|
196
|
-
}
|
|
197
|
-
process.stdout.write(`\nWorkspace created.\n\n`);
|
|
198
|
-
process.stdout.write(`Next steps:\n`);
|
|
199
|
-
process.stdout.write(` cd ${label}\n`);
|
|
200
|
-
process.stdout.write(` cp .env.example .env.local\n`);
|
|
201
|
-
process.stdout.write(` # Edit .env.local — set ONE_API_KEY\n`);
|
|
202
|
-
if (!opts.slug)
|
|
203
|
-
process.stdout.write(` # Edit workspace.toml — set slug and name\n`);
|
|
204
|
-
process.stdout.write(` one setup\n`);
|
|
205
|
-
});
|
|
206
|
-
// ── one create site [name] ────────────────────────────────────────────────
|
|
207
|
-
cmd
|
|
208
|
-
.command('site [name]')
|
|
209
|
-
.description('Scaffold a standalone ONE Astro site from github.com/one-ie/one')
|
|
210
|
-
.option('--ref <ref>', 'Git ref to download', 'main')
|
|
211
|
-
.action((name, opts) => {
|
|
212
|
-
if (!SAFE_REF.test(opts.ref)) {
|
|
213
|
-
process.stderr.write(`Invalid ref: ${opts.ref}\n`);
|
|
214
|
-
process.exit(1);
|
|
215
|
-
}
|
|
216
|
-
const dir = resolve(process.cwd(), name ?? 'my-site');
|
|
217
|
-
if (existsSync(dir)) {
|
|
218
|
-
process.stderr.write(`Directory already exists: ${dir}\n`);
|
|
219
|
-
process.exit(1);
|
|
220
|
-
}
|
|
221
|
-
process.stdout.write(`Creating site at ${dir}...\n`);
|
|
222
|
-
downloadSubdir(`https://api.github.com/repos/one-ie/one/tarball/${opts.ref}`, 'apps/web', dir);
|
|
223
|
-
const label = name ?? 'my-site';
|
|
224
|
-
process.stdout.write(`\nSite created.\n\n`);
|
|
225
|
-
process.stdout.write(`Next steps:\n`);
|
|
226
|
-
process.stdout.write(` cd ${label}\n`);
|
|
227
|
-
process.stdout.write(` cp .env.example .env.local\n`);
|
|
228
|
-
process.stdout.write(` bun install && bun run dev\n`);
|
|
229
|
-
});
|
|
230
105
|
return cmd;
|
|
231
106
|
}
|
package/dist/src/init.js
CHANGED
|
@@ -13,6 +13,7 @@ import { resolve } from 'node:path';
|
|
|
13
13
|
import { homedir } from 'node:os';
|
|
14
14
|
import { renameSync, chmodSync } from 'node:fs';
|
|
15
15
|
import { join } from 'node:path';
|
|
16
|
+
import { mergeEnv, writeEnvLocal } from './env.js';
|
|
16
17
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
17
18
|
const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
|
|
18
19
|
const KEY_FILE = resolve(CONFIG_DIR, 'key');
|
|
@@ -64,7 +65,16 @@ export function initCmd() {
|
|
|
64
65
|
.option('--skills <refs>', 'Comma-separated skill refs to import (e.g. cold-email,calendar-lookup)')
|
|
65
66
|
.option('--no-content', 'Skip generating a starter agent.md')
|
|
66
67
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
68
|
+
.option('--write-env', 'Also write ONE_API_KEY to .env.local in the current directory')
|
|
67
69
|
.action(async (opts) => {
|
|
70
|
+
const dir = process.cwd();
|
|
71
|
+
if (opts.writeEnv) {
|
|
72
|
+
const env = mergeEnv(dir);
|
|
73
|
+
if (env.ONE_API_KEY) {
|
|
74
|
+
out(cmd, { ok: true, note: 'already connected — .env.local has ONE_API_KEY' });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
68
78
|
const name = opts.name ?? 'My Agent';
|
|
69
79
|
const skills = opts.skills ? opts.skills.split(',').map(s => s.trim()).filter(Boolean) : [];
|
|
70
80
|
const content = opts.content !== false ? defaultAgentMd(name) : undefined;
|
|
@@ -94,11 +104,15 @@ export function initCmd() {
|
|
|
94
104
|
}
|
|
95
105
|
const { workspace, apiKey, inviteUrl } = json;
|
|
96
106
|
writeKey(apiKey);
|
|
107
|
+
if (opts.writeEnv) {
|
|
108
|
+
writeEnvLocal(dir, { ONE_API_KEY: apiKey, ONE_API_URL: opts.api });
|
|
109
|
+
}
|
|
97
110
|
out(cmd, {
|
|
98
111
|
ok: true,
|
|
99
112
|
workspace,
|
|
100
113
|
url: `${opts.api.replace(/\/$/, '')}/u/${workspace}`,
|
|
101
114
|
key: `${KEY_FILE} (0600)`,
|
|
115
|
+
...(opts.writeEnv ? { env: `${dir}/.env.local`, mcp: 'export ONE_API_KEY before launching Claude Code — MCP reads the shell env, not .env.local directly' } : {}),
|
|
102
116
|
...(inviteUrl ? { invite: inviteUrl } : {}),
|
|
103
117
|
...(skills.length ? { skills: skills.join(', ') } : {}),
|
|
104
118
|
});
|
package/dist/src/plugin.js
CHANGED
|
@@ -81,5 +81,75 @@ export function pluginCmd() {
|
|
|
81
81
|
}
|
|
82
82
|
out('plugin:add', { ok: true, plugin: name, source: body.source, install: body.install });
|
|
83
83
|
});
|
|
84
|
+
cmd
|
|
85
|
+
.command('buy <name>')
|
|
86
|
+
.description('Buy a plugin — card (default) or the workspace credit pool (--credits)')
|
|
87
|
+
.option('--workspace <slug>', 'Workspace slug (default: ONEIE_WORKSPACE env)')
|
|
88
|
+
.option('--credits', 'Pay from the workspace credit pool instead of card')
|
|
89
|
+
.option('--api <url>', 'API base URL')
|
|
90
|
+
.action(async (name, opts) => {
|
|
91
|
+
const workspace = opts.workspace ?? process.env.ONEIE_WORKSPACE;
|
|
92
|
+
if (!workspace) {
|
|
93
|
+
console.error('Error: --workspace or ONEIE_WORKSPACE required');
|
|
94
|
+
process.exit(1);
|
|
95
|
+
}
|
|
96
|
+
const method = opts.credits ? 'credits' : 'stripe';
|
|
97
|
+
let res;
|
|
98
|
+
try {
|
|
99
|
+
res = await fetch(`${apiBase(opts)}/api/ask/plugins:buy`, {
|
|
100
|
+
method: 'POST',
|
|
101
|
+
headers: { ...bearerHeaders(workspace), 'Content-Type': 'application/json' },
|
|
102
|
+
body: JSON.stringify({ data: { name, method } }),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
console.error(`Error: ${e instanceof Error ? e.message : e}`);
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
const env = (await res.json().catch(() => ({})));
|
|
110
|
+
const r = env.result ?? {};
|
|
111
|
+
if (!res.ok || env.outcome !== 'result' || r.error) {
|
|
112
|
+
out('plugin:buy', { ok: false, plugin: name, error: r.error ?? env.outcome ?? 'failed', status: res.status });
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
if (method === 'credits') {
|
|
116
|
+
out('plugin:buy', { ok: true, plugin: name, method, entitled: r.entitled, credits_spent: r.credits_spent, install: `one plugin add ${name}` });
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
out('plugin:buy', { ok: true, plugin: name, method, checkout_url: r.url, note: 'Open checkout_url to pay, then: one plugin add ' + name });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
cmd
|
|
123
|
+
.command('grant <name>')
|
|
124
|
+
.description('Resell a plugin to a client you control — grants the entitlement, no charge')
|
|
125
|
+
.requiredOption('--to <client>', 'Client workspace slug to grant the plugin to')
|
|
126
|
+
.option('--workspace <slug>', 'Your (reseller) workspace slug (default: ONEIE_WORKSPACE env)')
|
|
127
|
+
.option('--api <url>', 'API base URL')
|
|
128
|
+
.action(async (name, opts) => {
|
|
129
|
+
const workspace = opts.workspace ?? process.env.ONEIE_WORKSPACE;
|
|
130
|
+
if (!workspace) {
|
|
131
|
+
console.error('Error: --workspace or ONEIE_WORKSPACE required');
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
let res;
|
|
135
|
+
try {
|
|
136
|
+
res = await fetch(`${apiBase(opts)}/api/ask/plugins:grant`, {
|
|
137
|
+
method: 'POST',
|
|
138
|
+
headers: { ...bearerHeaders(workspace), 'Content-Type': 'application/json' },
|
|
139
|
+
body: JSON.stringify({ data: { name, for: opts.to } }),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
console.error(`Error: ${e instanceof Error ? e.message : e}`);
|
|
144
|
+
process.exit(1);
|
|
145
|
+
}
|
|
146
|
+
const env = (await res.json().catch(() => ({})));
|
|
147
|
+
const r = env.result ?? {};
|
|
148
|
+
if (!res.ok || env.outcome !== 'result' || r.error) {
|
|
149
|
+
out('plugin:grant', { ok: false, plugin: name, client: opts.to, error: r.error ?? env.outcome ?? 'failed', status: res.status });
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
out('plugin:grant', { ok: true, plugin: name, client: opts.to, already: r.already ?? false, note: `Client ${opts.to} is now entitled to ${name}` });
|
|
153
|
+
});
|
|
84
154
|
return cmd;
|
|
85
155
|
}
|