@oneie/cli 0.10.1 → 4.0.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.
- package/dist/package.json +2 -2
- package/dist/src/auth.d.ts +3 -0
- package/dist/src/auth.js +9 -3
- package/dist/src/banner.d.ts +1 -0
- package/dist/src/banner.js +16 -0
- package/dist/src/broadcast.js +3 -9
- package/dist/src/chat.js +4 -10
- package/dist/src/client.d.ts +3 -0
- package/dist/src/client.js +52 -0
- package/dist/src/config.d.ts +1 -1
- package/dist/src/connect.js +4 -26
- package/dist/src/create.js +8 -1
- package/dist/src/doctor.d.ts +26 -0
- package/dist/src/doctor.js +91 -0
- package/dist/src/env.js +1 -1
- package/dist/src/group.js +4 -26
- package/dist/src/index.js +24 -1
- package/dist/src/lib/agent-env.d.ts +5 -0
- package/dist/src/lib/agent-env.js +25 -0
- package/dist/src/lib/client.d.ts +16 -0
- package/dist/src/lib/client.js +57 -0
- package/dist/src/lib/launch-claude.d.ts +5 -0
- package/dist/src/lib/launch-claude.js +45 -0
- package/dist/src/links.js +3 -9
- package/dist/src/plugin.js +7 -6
- package/dist/src/render.d.ts +3 -0
- package/dist/src/render.js +11 -4
- package/dist/src/setup.d.ts +4 -0
- package/dist/src/setup.js +72 -14
- package/dist/src/social.js +4 -26
- package/dist/src/staff.js +17 -39
- package/dist/src/substrate.js +4 -13
- package/dist/src/trail.js +7 -13
- package/package.json +3 -3
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "ONE agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"commander": "^12.0.0",
|
|
23
|
-
"@oneie/sdk": "
|
|
23
|
+
"@oneie/sdk": "^0.14.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@oneie/evals": "workspace:*",
|
package/dist/src/auth.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
/** Shared by `auth login` (nested) and the top-level `login` alias — same
|
|
3
|
+
* Command shape, same action, registered under two parents (contract #11). */
|
|
4
|
+
export declare function buildLoginCommand(): Command;
|
|
2
5
|
export declare function authCmd(): Command;
|
|
3
6
|
export declare function loadKey(): string | null;
|
package/dist/src/auth.js
CHANGED
|
@@ -8,9 +8,10 @@ const KEY_FILE = resolve(CONFIG_DIR, 'key');
|
|
|
8
8
|
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
9
9
|
const CLI_CLIENT_ID = 'oneie-cli';
|
|
10
10
|
const CLI_SCOPE = 'read write';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/** Shared by `auth login` (nested) and the top-level `login` alias — same
|
|
12
|
+
* Command shape, same action, registered under two parents (contract #11). */
|
|
13
|
+
export function buildLoginCommand() {
|
|
14
|
+
const cmd = new Command('login')
|
|
14
15
|
.description('Sign in via browser and persist token to ~/.config/oneie/key')
|
|
15
16
|
.option('--key <key>', 'Skip browser flow — store API key directly (or set ONEIE_API_KEY)')
|
|
16
17
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
@@ -61,6 +62,11 @@ export function authCmd() {
|
|
|
61
62
|
process.exit(1);
|
|
62
63
|
}
|
|
63
64
|
});
|
|
65
|
+
return cmd;
|
|
66
|
+
}
|
|
67
|
+
export function authCmd() {
|
|
68
|
+
const cmd = new Command('auth').description('Authentication');
|
|
69
|
+
cmd.addCommand(buildLoginCommand());
|
|
64
70
|
cmd.command('logout')
|
|
65
71
|
.description('Remove stored API key')
|
|
66
72
|
.action(() => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function displayBanner(): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The ONE wordmark — ported from legacy 3.8.3's banner.js, plain stdout
|
|
2
|
+
// (no chalk: the current CLI stays dependency-lean). Shown only on the
|
|
3
|
+
// human-TTY paths (bare invocation, `create`) — never for an agent shell,
|
|
4
|
+
// which wants signal, not decoration.
|
|
5
|
+
export function displayBanner() {
|
|
6
|
+
process.stdout.write(`
|
|
7
|
+
██████╗ ███╗ ██╗███████╗
|
|
8
|
+
██╔═══██╗████╗ ██║██╔════╝
|
|
9
|
+
██║ ██║██╔██╗ ██║█████╗
|
|
10
|
+
██║ ██║██║╚██╗██║██╔══╝
|
|
11
|
+
╚██████╔╝██║ ╚████║███████╗
|
|
12
|
+
╚═════╝ ╚═╝ ╚═══╝╚══════╝
|
|
13
|
+
Turn ideas into reality — https://one.ie
|
|
14
|
+
|
|
15
|
+
`);
|
|
16
|
+
}
|
package/dist/src/broadcast.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const h = { 'Content-Type': 'application/json' };
|
|
5
|
-
const k = process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
6
|
-
if (k)
|
|
7
|
-
h['Authorization'] = `Bearer ${k}`;
|
|
8
|
-
return h;
|
|
9
|
-
}
|
|
2
|
+
import { authHeaders, resolveBase } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://api.one.ie');
|
|
10
4
|
async function ask(api, receiver, data) {
|
|
11
5
|
const res = await fetch(`${api.replace(/\/$/, '')}/api/ask/${encodeURIComponent(receiver)}`, {
|
|
12
6
|
method: 'POST',
|
|
13
|
-
headers:
|
|
7
|
+
headers: authHeaders(),
|
|
14
8
|
body: JSON.stringify({ data }),
|
|
15
9
|
});
|
|
16
10
|
if (!res.ok) {
|
package/dist/src/chat.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
|
|
2
|
+
import { authHeaders, resolveBase, resolveKey } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
3
4
|
const DEFAULT_CHANNELS = process.env.CHANNELS_URL ?? 'https://channels.one.ie';
|
|
4
5
|
const DEFAULT_SPACES = ['vespio', 'elitemoversca', 'world'];
|
|
5
|
-
function headers() {
|
|
6
|
-
const h = { 'Content-Type': 'application/json' };
|
|
7
|
-
const k = process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
8
|
-
if (k)
|
|
9
|
-
h['Authorization'] = `Bearer ${k}`;
|
|
10
|
-
return h;
|
|
11
|
-
}
|
|
12
6
|
async function spacePost(api, space, content) {
|
|
13
7
|
const res = await fetch(`${api.replace(/\/$/, '')}/api/ask/space:post`, {
|
|
14
8
|
method: 'POST',
|
|
15
|
-
headers:
|
|
9
|
+
headers: authHeaders(),
|
|
16
10
|
body: JSON.stringify({ data: { space, content } }),
|
|
17
11
|
});
|
|
18
12
|
if (!res.ok)
|
|
@@ -61,7 +55,7 @@ export function chatCmd() {
|
|
|
61
55
|
const group = space.startsWith('space:') ? space : `space:${space}`;
|
|
62
56
|
const url = `${opts.channels.replace(/\/$/, '')}/stream/${encodeURIComponent(group)}`;
|
|
63
57
|
process.stderr.write(`Listening on ${group} — Ctrl+C to stop\n`);
|
|
64
|
-
const key =
|
|
58
|
+
const key = resolveKey();
|
|
65
59
|
const h = { Accept: 'text/event-stream' };
|
|
66
60
|
if (key)
|
|
67
61
|
h['Authorization'] = `Bearer ${key}`;
|
package/dist/src/client.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
/** `clients/<slug>.toml` — the scaffold `client add` reads. Optional keys are
|
|
3
|
+
* commented so `readClient()`'s defaults apply until the operator opts in. */
|
|
4
|
+
export declare function clientToml(name: string, slug: string): string;
|
|
2
5
|
export declare function clientCmd(): Command;
|
package/dist/src/client.js
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
2
3
|
import { mergeEnv } from './env.js';
|
|
3
4
|
import { readClient } from './config.js';
|
|
4
5
|
import { validateClient } from './validate.js';
|
|
5
6
|
import { safeSlug } from './slug.js';
|
|
6
7
|
import { askPath } from './lib/api-path.js';
|
|
8
|
+
import { renderClientTable } from './render.js';
|
|
7
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
|
+
}
|
|
8
22
|
async function ask(base, key, receiver, data) {
|
|
9
23
|
const res = await fetch(askPath(base, receiver), {
|
|
10
24
|
method: 'POST',
|
|
@@ -19,6 +33,44 @@ async function ask(base, key, receiver, data) {
|
|
|
19
33
|
}
|
|
20
34
|
export function clientCmd() {
|
|
21
35
|
const cmd = new Command('client').description('Manage client nodes');
|
|
36
|
+
cmd.command('new <slug>')
|
|
37
|
+
.description('Scaffold clients/<slug>.toml so `client add` works out of the box')
|
|
38
|
+
.option('--name <name>', 'Display name (defaults to the slug)')
|
|
39
|
+
.action((slug, opts) => {
|
|
40
|
+
const dir = process.cwd();
|
|
41
|
+
const clean = safeSlug(slug);
|
|
42
|
+
const dest = `${dir}/clients/${clean}.toml`;
|
|
43
|
+
if (existsSync(dest)) {
|
|
44
|
+
process.stderr.write(`already exists: ${dest}\n`);
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
|
47
|
+
mkdirSync(`${dir}/clients`, { recursive: true });
|
|
48
|
+
writeFileSync(dest, clientToml(opts.name ?? clean, clean));
|
|
49
|
+
process.stdout.write(`Created ${dest}\n one client add ${clean}\n`);
|
|
50
|
+
});
|
|
51
|
+
cmd.command('list')
|
|
52
|
+
.description('The client portfolio (billing:clients)')
|
|
53
|
+
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
54
|
+
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
55
|
+
.option('--json', 'Output raw JSON')
|
|
56
|
+
.action(async (opts) => {
|
|
57
|
+
const dir = process.cwd();
|
|
58
|
+
const env = mergeEnv(dir);
|
|
59
|
+
const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
|
|
60
|
+
const agencySlug = env.AGENCY_SLUG;
|
|
61
|
+
if (!agencySlug) {
|
|
62
|
+
process.stderr.write('AGENCY_SLUG missing — run `one setup` first\n');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
const data = await ask(opts.api.replace(/\/$/, ''), key, 'billing:clients', {});
|
|
66
|
+
if (opts.json) {
|
|
67
|
+
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const clients = (data.clients ?? []);
|
|
71
|
+
const markupPct = (data.agency?.markup_pct) ?? 0;
|
|
72
|
+
process.stdout.write(renderClientTable(clients, markupPct) + '\n');
|
|
73
|
+
});
|
|
22
74
|
cmd.command('add <slug>')
|
|
23
75
|
.description('Atomically provision a managed client node')
|
|
24
76
|
.option('--dry-run', 'Print plan without making substrate calls')
|
package/dist/src/config.d.ts
CHANGED
package/dist/src/connect.js
CHANGED
|
@@ -1,31 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { resolve } from 'node:path';
|
|
5
|
-
const DEFAULT_API = 'https://one.ie';
|
|
6
|
-
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
2
|
+
import { out, resolveBase, resolveKey } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
7
4
|
function readApiKey() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (existsSync(KEY_FILE))
|
|
11
|
-
return readFileSync(KEY_FILE, 'utf8').trim() || null;
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
function out(cmd, data) {
|
|
15
|
-
const isJson = cmd.parent?.parent?.opts().json;
|
|
16
|
-
if (isJson) {
|
|
17
|
-
process.stdout.write(JSON.stringify(data) + '\n');
|
|
18
|
-
}
|
|
19
|
-
else if (data.ok) {
|
|
20
|
-
const pairs = Object.entries(data)
|
|
21
|
-
.filter(([k]) => k !== 'ok')
|
|
22
|
-
.map(([k, v]) => `${k}=${JSON.stringify(v)}`);
|
|
23
|
-
process.stdout.write(`ok ${pairs.join(' ')}\n`);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
process.stderr.write(`error ${data.error ?? 'unknown'}\n`);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
5
|
+
const key = resolveKey();
|
|
6
|
+
return key || null;
|
|
29
7
|
}
|
|
30
8
|
// `one connect <channel> --token <t>` — token-paste connect. The CLI never
|
|
31
9
|
// implements getMe/setWebhook; it POSTs to the web /api/connect/<channel> route
|
package/dist/src/create.js
CHANGED
|
@@ -2,6 +2,9 @@ import { Command } from 'commander';
|
|
|
2
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 { displayBanner } from './banner.js';
|
|
6
|
+
import { maybeLaunchClaude } from './lib/launch-claude.js';
|
|
7
|
+
import { isAgentEnvironment } from './lib/agent-env.js';
|
|
5
8
|
const SAFE_REF = /^[A-Za-z0-9._/-]+$/;
|
|
6
9
|
function downloadTarball(url, targetDir) {
|
|
7
10
|
mkdirSync(targetDir, { recursive: true });
|
|
@@ -32,11 +35,14 @@ export function createCmd() {
|
|
|
32
35
|
.option('--ref <ref>', 'Git ref to download', 'main')
|
|
33
36
|
.option('--slug <slug>', 'Workspace slug (written into workspace.toml)')
|
|
34
37
|
.option('--name <name>', 'Display name (written into workspace.toml)')
|
|
35
|
-
.action((dirName, opts) => {
|
|
38
|
+
.action(async (dirName, opts) => {
|
|
36
39
|
if (!SAFE_REF.test(opts.ref)) {
|
|
37
40
|
process.stderr.write(`Invalid ref: ${opts.ref}\n`);
|
|
38
41
|
process.exit(1);
|
|
39
42
|
}
|
|
43
|
+
const humanTTY = !isAgentEnvironment();
|
|
44
|
+
if (humanTTY)
|
|
45
|
+
displayBanner();
|
|
40
46
|
const label = dirName ?? opts.slug ?? 'my-business';
|
|
41
47
|
const dir = resolve(process.cwd(), label);
|
|
42
48
|
if (existsSync(dir)) {
|
|
@@ -63,6 +69,7 @@ export function createCmd() {
|
|
|
63
69
|
if (!opts.slug)
|
|
64
70
|
process.stdout.write(` # Edit workspace.toml — set slug and name\n`);
|
|
65
71
|
process.stdout.write(` one setup\n`);
|
|
72
|
+
await maybeLaunchClaude(dir);
|
|
66
73
|
});
|
|
67
74
|
// ── one create partner [name] ────────────────────────────────────────────
|
|
68
75
|
cmd
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
/** api.one.ie (the gateway) answers `GET /health`; one.ie/web has no /health
|
|
3
|
+
* route, so a HEAD / 200 is the reachability signal there — same host split
|
|
4
|
+
* askPath() already makes for /ask. */
|
|
5
|
+
export declare function isGatewayHost(base: string): boolean;
|
|
6
|
+
export declare function checkReachability(base: string, timeoutMs?: number): Promise<{
|
|
7
|
+
ok: boolean;
|
|
8
|
+
ms: number;
|
|
9
|
+
}>;
|
|
10
|
+
export interface DoctorCheck {
|
|
11
|
+
name: string;
|
|
12
|
+
ok: boolean;
|
|
13
|
+
detail: string;
|
|
14
|
+
}
|
|
15
|
+
export interface DoctorResult {
|
|
16
|
+
ok: boolean;
|
|
17
|
+
checks: DoctorCheck[];
|
|
18
|
+
}
|
|
19
|
+
export declare function runDoctor(dir: string, opts?: {
|
|
20
|
+
api?: string;
|
|
21
|
+
keyFile?: string;
|
|
22
|
+
}): Promise<DoctorResult>;
|
|
23
|
+
/** No `auth:whoami` receiver exists — an authenticated `dashboard:usage` call
|
|
24
|
+
* proves the key is live, alongside the env echo. */
|
|
25
|
+
export declare function whoamiCmd(): Command;
|
|
26
|
+
export declare function doctorCmd(): Command;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { resolve } from 'node:path';
|
|
5
|
+
import { mergeEnv } from './env.js';
|
|
6
|
+
import { resolveBase, resolveKey, authHeaders } from './lib/client.js';
|
|
7
|
+
import { askPath } from './lib/api-path.js';
|
|
8
|
+
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
9
|
+
/** api.one.ie (the gateway) answers `GET /health`; one.ie/web has no /health
|
|
10
|
+
* route, so a HEAD / 200 is the reachability signal there — same host split
|
|
11
|
+
* askPath() already makes for /ask. */
|
|
12
|
+
export function isGatewayHost(base) {
|
|
13
|
+
return new URL(base).hostname === 'api.one.ie';
|
|
14
|
+
}
|
|
15
|
+
export async function checkReachability(base, timeoutMs = 5000) {
|
|
16
|
+
const start = Date.now();
|
|
17
|
+
const controller = new AbortController();
|
|
18
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
19
|
+
try {
|
|
20
|
+
const res = await fetch(isGatewayHost(base) ? `${base}/health` : base, {
|
|
21
|
+
method: isGatewayHost(base) ? 'GET' : 'HEAD',
|
|
22
|
+
signal: controller.signal,
|
|
23
|
+
});
|
|
24
|
+
return { ok: res.ok, ms: Date.now() - start };
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return { ok: false, ms: Date.now() - start };
|
|
28
|
+
}
|
|
29
|
+
finally {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export async function runDoctor(dir, opts = {}) {
|
|
34
|
+
const keyFile = opts.keyFile ?? KEY_FILE;
|
|
35
|
+
const env = mergeEnv(dir);
|
|
36
|
+
const checks = [];
|
|
37
|
+
const hasConfig = existsSync(keyFile) || Boolean(env.ONE_API_KEY) || Boolean(env.ONEIE_API_KEY);
|
|
38
|
+
checks.push({
|
|
39
|
+
name: 'config',
|
|
40
|
+
ok: hasConfig,
|
|
41
|
+
detail: hasConfig ? `${keyFile} (0600)` : `${keyFile} missing — run \`one setup\` or \`one login\``,
|
|
42
|
+
});
|
|
43
|
+
const key = env.ONE_API_KEY || env.ONEIE_API_KEY || (existsSync(keyFile) ? readFileSync(keyFile, 'utf8').trim() : '');
|
|
44
|
+
checks.push({ name: 'key', ok: Boolean(key), detail: key ? `${key.slice(0, 4)}***…` : 'no key found' });
|
|
45
|
+
const base = resolveBase({ api: opts.api });
|
|
46
|
+
const reach = await checkReachability(base);
|
|
47
|
+
checks.push({ name: 'substrate', ok: reach.ok, detail: `${base} ${reach.ms}ms` });
|
|
48
|
+
return { ok: checks.every((c) => c.ok), checks };
|
|
49
|
+
}
|
|
50
|
+
/** No `auth:whoami` receiver exists — an authenticated `dashboard:usage` call
|
|
51
|
+
* proves the key is live, alongside the env echo. */
|
|
52
|
+
export function whoamiCmd() {
|
|
53
|
+
return new Command('whoami')
|
|
54
|
+
.description('Who the key is, which workspace — proves the key is live')
|
|
55
|
+
.option('--api <url>', 'API base URL')
|
|
56
|
+
.action(async (opts) => {
|
|
57
|
+
const dir = process.cwd();
|
|
58
|
+
const env = mergeEnv(dir);
|
|
59
|
+
const base = resolveBase({ api: opts.api });
|
|
60
|
+
const key = resolveKey({});
|
|
61
|
+
if (!key) {
|
|
62
|
+
process.stderr.write('no key found — run `one setup` or `one login`\n');
|
|
63
|
+
process.exitCode = 1;
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const res = await fetch(askPath(base, 'dashboard:usage'), {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: authHeaders({}),
|
|
69
|
+
body: JSON.stringify({ data: {} }),
|
|
70
|
+
});
|
|
71
|
+
const live = res.ok;
|
|
72
|
+
process.stdout.write(`workspace ${env.WORKSPACE_SLUG ?? env.AGENCY_SLUG ?? '(unset)'}\n`);
|
|
73
|
+
process.stdout.write(`key ${key.slice(0, 4)}***… ${live ? '(live)' : `(unreachable — ${base})`}\n`);
|
|
74
|
+
process.stdout.write(`base ${base}\n`);
|
|
75
|
+
if (!live)
|
|
76
|
+
process.exitCode = 1;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
export function doctorCmd() {
|
|
80
|
+
return new Command('doctor')
|
|
81
|
+
.description('Config / key / reachability checks — exit 0 or 1 for CI')
|
|
82
|
+
.option('--api <url>', 'API base URL to check (defaults to the resolved base)')
|
|
83
|
+
.action(async (opts) => {
|
|
84
|
+
const result = await runDoctor(process.cwd(), opts);
|
|
85
|
+
for (const c of result.checks) {
|
|
86
|
+
process.stdout.write(`[${c.ok ? 'ok' : 'fail'}] ${c.name.padEnd(10)} ${c.detail}\n`);
|
|
87
|
+
}
|
|
88
|
+
if (!result.ok)
|
|
89
|
+
process.exitCode = 1;
|
|
90
|
+
});
|
|
91
|
+
}
|
package/dist/src/env.js
CHANGED
|
@@ -15,7 +15,7 @@ export function readEnvFile(path) {
|
|
|
15
15
|
}
|
|
16
16
|
function fromProcess() {
|
|
17
17
|
const out = {};
|
|
18
|
-
for (const k of ['ONE_API_URL', 'ONE_API_KEY', 'ONEIE_API_KEY', 'AGENCY_SLUG', 'AGENCY_NAME', 'AGENCY_WSID', 'CC_ACTOR_ID']) {
|
|
18
|
+
for (const k of ['ONE_API_URL', 'ONE_API_KEY', 'ONEIE_API_KEY', 'AGENCY_SLUG', 'AGENCY_NAME', 'AGENCY_WSID', 'CC_ACTOR_ID', 'WORKSPACE_OWNER_EMAIL', 'WORKSPACE_ID', 'WORKSPACE_SLUG']) {
|
|
19
19
|
const v = process.env[k];
|
|
20
20
|
if (v)
|
|
21
21
|
out[k] = v;
|
package/dist/src/group.js
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { createReadStream, existsSync } from 'node:fs';
|
|
3
3
|
import { createInterface } from 'node:readline';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { readFileSync } from 'node:fs';
|
|
7
|
-
const DEFAULT_API = 'https://one.ie';
|
|
8
|
-
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
4
|
+
import { out, resolveBase, resolveKey } from './lib/client.js';
|
|
5
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
9
6
|
function readApiKey() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (existsSync(KEY_FILE))
|
|
13
|
-
return readFileSync(KEY_FILE, 'utf8').trim() || null;
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
function out(cmd, data) {
|
|
17
|
-
const isJson = cmd.parent?.parent?.opts().json;
|
|
18
|
-
if (isJson) {
|
|
19
|
-
process.stdout.write(JSON.stringify(data) + '\n');
|
|
20
|
-
}
|
|
21
|
-
else if (data.ok) {
|
|
22
|
-
const pairs = Object.entries(data)
|
|
23
|
-
.filter(([k]) => k !== 'ok')
|
|
24
|
-
.map(([k, v]) => `${k}=${JSON.stringify(v)}`);
|
|
25
|
-
process.stdout.write(`ok ${pairs.join(' ')}\n`);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
process.stderr.write(`error ${data.error ?? 'unknown'}\n`);
|
|
29
|
-
process.exit(1);
|
|
30
|
-
}
|
|
7
|
+
const key = resolveKey();
|
|
8
|
+
return key || null;
|
|
31
9
|
}
|
|
32
10
|
async function parseCsv(file) {
|
|
33
11
|
const rows = [];
|
package/dist/src/index.js
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import { agentCmd } from './agent.js';
|
|
4
4
|
import { skillCmd } from './skill.js';
|
|
5
|
-
import { authCmd } from './auth.js';
|
|
5
|
+
import { authCmd, buildLoginCommand } from './auth.js';
|
|
6
|
+
import { doctorCmd, whoamiCmd } from './doctor.js';
|
|
7
|
+
import { isAgentEnvironment } from './lib/agent-env.js';
|
|
8
|
+
import { displayBanner } from './banner.js';
|
|
6
9
|
import { devCmd } from './dev.js';
|
|
7
10
|
import { groupCmd } from './group.js';
|
|
8
11
|
import { socialCmd } from './social.js';
|
|
@@ -54,6 +57,9 @@ program.addCommand(staffCmd());
|
|
|
54
57
|
program.addCommand(evalCmd());
|
|
55
58
|
program.addCommand(setupCmd());
|
|
56
59
|
program.addCommand(clientCmd());
|
|
60
|
+
program.addCommand(doctorCmd());
|
|
61
|
+
program.addCommand(whoamiCmd());
|
|
62
|
+
program.addCommand(buildLoginCommand());
|
|
57
63
|
program.addCommand(walletCmd());
|
|
58
64
|
program.addCommand(pushCmd());
|
|
59
65
|
program.addCommand(deployCmd());
|
|
@@ -69,6 +75,23 @@ program.addCommand(trailCmd());
|
|
|
69
75
|
program.addCommand(initCmd());
|
|
70
76
|
program.addCommand(onboardCmd());
|
|
71
77
|
program.addCommand(pluginCmd());
|
|
78
|
+
// Bare `oneie` (no args, no --help/--version): route the audience to its
|
|
79
|
+
// journey instead of commander's default help dump. Never an interactive
|
|
80
|
+
// prompt — agent env and human TTY both get a printed block (contract #10).
|
|
81
|
+
if (process.argv.length === 2) {
|
|
82
|
+
if (isAgentEnvironment()) {
|
|
83
|
+
process.stdout.write('oneie — no workspace yet.\n' +
|
|
84
|
+
' oneie init --write-env # provision a workspace, no account required\n' +
|
|
85
|
+
' oneie onboard # provision + walk the lifecycle stages\n' +
|
|
86
|
+
' oneie --help # full command reference\n');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
displayBanner();
|
|
90
|
+
process.stdout.write(' npx oneie create <name> # scaffold a new workspace\n' +
|
|
91
|
+
' oneie --help # full command reference\n');
|
|
92
|
+
}
|
|
93
|
+
process.exit(0);
|
|
94
|
+
}
|
|
72
95
|
program.parseAsync(process.argv).catch((err) => {
|
|
73
96
|
const isJson = process.argv.includes('--json');
|
|
74
97
|
if (isJson)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The specific coding agent driving this shell, if env vars name one. */
|
|
2
|
+
export declare function agentType(env?: NodeJS.ProcessEnv): string | undefined;
|
|
3
|
+
/** True when stdout isn't a human's terminal (agent shell, CI, piped) or a
|
|
4
|
+
* known agent env var is set — never used to gate a prompt, only the greeting. */
|
|
5
|
+
export declare function isAgentEnvironment(env?: NodeJS.ProcessEnv, isTTY?: boolean): boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Port of legacy 3.8.3's agent-detection.js — env-var/TTY checks only, zero
|
|
2
|
+
// deps. Lets the bare `oneie` front door route each audience to its journey
|
|
3
|
+
// instead of dumping --help.
|
|
4
|
+
const AGENT_ENV_MARKERS = {
|
|
5
|
+
CLAUDECODE: 'claude-code',
|
|
6
|
+
CLAUDE_CODE: 'claude-code',
|
|
7
|
+
CURSOR_TRACE_ID: 'cursor',
|
|
8
|
+
WINDSURF: 'windsurf',
|
|
9
|
+
GITHUB_COPILOT_CLI: 'copilot',
|
|
10
|
+
};
|
|
11
|
+
/** The specific coding agent driving this shell, if env vars name one. */
|
|
12
|
+
export function agentType(env = process.env) {
|
|
13
|
+
for (const [marker, name] of Object.entries(AGENT_ENV_MARKERS)) {
|
|
14
|
+
if (env[marker])
|
|
15
|
+
return name;
|
|
16
|
+
}
|
|
17
|
+
if (env.CI)
|
|
18
|
+
return 'ci';
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
/** True when stdout isn't a human's terminal (agent shell, CI, piped) or a
|
|
22
|
+
* known agent env var is set — never used to gate a prompt, only the greeting. */
|
|
23
|
+
export function isAgentEnvironment(env = process.env, isTTY = process.stdout.isTTY) {
|
|
24
|
+
return Boolean(agentType(env)) || !isTTY;
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
/** --api flag > ONE_API_URL (canonical) > ONEIE_BASE_URL (legacy) > fallback. ONE_BASE_URL is retired. */
|
|
3
|
+
export declare function resolveBase(opts?: {
|
|
4
|
+
api?: string;
|
|
5
|
+
}, fallback?: string): string;
|
|
6
|
+
/** ONE_API_KEY (canonical) > ONEIE_API_KEY (legacy) > ~/.config/oneie/key. */
|
|
7
|
+
export declare function resolveKey(opts?: {
|
|
8
|
+
key?: string;
|
|
9
|
+
}): string;
|
|
10
|
+
export declare function authHeaders(opts?: {
|
|
11
|
+
key?: string;
|
|
12
|
+
}): Record<string, string>;
|
|
13
|
+
/** Walks cmd.parent all the way to root — never a fixed depth. ONEIE_JSON env is retired. */
|
|
14
|
+
export declare function jsonMode(cmd: Command): boolean;
|
|
15
|
+
/** ok/error human line (`ok k=v k=v`), or the same data as one JSON line under --json. */
|
|
16
|
+
export declare function out(cmd: Command, data: Record<string, unknown>): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
// Every command resolves base URL, key, and --json the same way — this module
|
|
5
|
+
// is the one place that knows the env contract. Composes askPath() from
|
|
6
|
+
// ./api-path.js for the gateway-vs-web path split; does not replace it.
|
|
7
|
+
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
8
|
+
/** --api flag > ONE_API_URL (canonical) > ONEIE_BASE_URL (legacy) > fallback. ONE_BASE_URL is retired. */
|
|
9
|
+
export function resolveBase(opts = {}, fallback = 'https://one.ie') {
|
|
10
|
+
const base = opts.api ?? process.env.ONE_API_URL ?? process.env.ONEIE_BASE_URL ?? fallback;
|
|
11
|
+
return base.replace(/\/$/, '');
|
|
12
|
+
}
|
|
13
|
+
/** ONE_API_KEY (canonical) > ONEIE_API_KEY (legacy) > ~/.config/oneie/key. */
|
|
14
|
+
export function resolveKey(opts = {}) {
|
|
15
|
+
if (opts.key)
|
|
16
|
+
return opts.key;
|
|
17
|
+
if (process.env.ONE_API_KEY)
|
|
18
|
+
return process.env.ONE_API_KEY;
|
|
19
|
+
if (process.env.ONEIE_API_KEY)
|
|
20
|
+
return process.env.ONEIE_API_KEY;
|
|
21
|
+
if (existsSync(KEY_FILE))
|
|
22
|
+
return readFileSync(KEY_FILE, 'utf8').trim();
|
|
23
|
+
return '';
|
|
24
|
+
}
|
|
25
|
+
export function authHeaders(opts = {}) {
|
|
26
|
+
const h = { 'Content-Type': 'application/json' };
|
|
27
|
+
const k = resolveKey(opts);
|
|
28
|
+
if (k)
|
|
29
|
+
h['Authorization'] = `Bearer ${k}`;
|
|
30
|
+
return h;
|
|
31
|
+
}
|
|
32
|
+
/** Walks cmd.parent all the way to root — never a fixed depth. ONEIE_JSON env is retired. */
|
|
33
|
+
export function jsonMode(cmd) {
|
|
34
|
+
let c = cmd;
|
|
35
|
+
while (c) {
|
|
36
|
+
if (c.opts().json)
|
|
37
|
+
return true;
|
|
38
|
+
c = c.parent ?? undefined;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
/** ok/error human line (`ok k=v k=v`), or the same data as one JSON line under --json. */
|
|
43
|
+
export function out(cmd, data) {
|
|
44
|
+
if (jsonMode(cmd)) {
|
|
45
|
+
process.stdout.write(JSON.stringify(data) + '\n');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (data.ok === false) {
|
|
49
|
+
process.stderr.write(`error ${data.error ?? 'unknown'}\n`);
|
|
50
|
+
process.exitCode = 1;
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const pairs = Object.entries(data)
|
|
54
|
+
.filter(([k]) => k !== 'ok')
|
|
55
|
+
.map(([k, v]) => `${k}=${JSON.stringify(v)}`);
|
|
56
|
+
process.stdout.write(`ok ${pairs.join(' ')}\n`);
|
|
57
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Offer to launch Claude Code in a freshly scaffolded node — port of legacy
|
|
2
|
+
* 3.8.3's launch-claude.js, zero new deps (no chalk/prompts: readline is a
|
|
3
|
+
* node builtin). Only ever prompts a real human TTY; an agent shell or
|
|
4
|
+
* non-interactive run gets the manual instructions and nothing hangs. */
|
|
5
|
+
export declare function maybeLaunchClaude(dir: string): Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { spawn, spawnSync } from 'node:child_process';
|
|
2
|
+
import { createInterface } from 'node:readline/promises';
|
|
3
|
+
import { isAgentEnvironment } from './agent-env.js';
|
|
4
|
+
function isClaudeInstalled() {
|
|
5
|
+
return spawnSync('which', ['claude'], { stdio: 'ignore' }).status === 0;
|
|
6
|
+
}
|
|
7
|
+
async function confirm(question) {
|
|
8
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
9
|
+
try {
|
|
10
|
+
const answer = (await rl.question(`${question} [Y/n] `)).trim().toLowerCase();
|
|
11
|
+
return answer === '' || answer === 'y' || answer === 'yes';
|
|
12
|
+
}
|
|
13
|
+
finally {
|
|
14
|
+
rl.close();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Offer to launch Claude Code in a freshly scaffolded node — port of legacy
|
|
18
|
+
* 3.8.3's launch-claude.js, zero new deps (no chalk/prompts: readline is a
|
|
19
|
+
* node builtin). Only ever prompts a real human TTY; an agent shell or
|
|
20
|
+
* non-interactive run gets the manual instructions and nothing hangs. */
|
|
21
|
+
export async function maybeLaunchClaude(dir) {
|
|
22
|
+
const claudeInstalled = isClaudeInstalled();
|
|
23
|
+
const canPrompt = claudeInstalled && process.stdin.isTTY === true && !isAgentEnvironment();
|
|
24
|
+
if (canPrompt) {
|
|
25
|
+
const launch = await confirm('\nLaunch Claude Code now?');
|
|
26
|
+
if (launch) {
|
|
27
|
+
process.stdout.write('\nLaunching Claude Code — type /do to start building.\n\n');
|
|
28
|
+
await new Promise((done) => {
|
|
29
|
+
const claude = spawn('claude', [], { stdio: 'inherit', cwd: dir });
|
|
30
|
+
claude.on('exit', () => done());
|
|
31
|
+
claude.on('error', (err) => {
|
|
32
|
+
process.stderr.write(`Failed to launch Claude Code: ${err.message}\n`);
|
|
33
|
+
done();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
process.stdout.write('\nOpen it:\n');
|
|
40
|
+
process.stdout.write(` cd ${dir}\n`);
|
|
41
|
+
if (!claudeInstalled) {
|
|
42
|
+
process.stdout.write(' # Install Claude Code: https://claude.com/product/claude-code\n');
|
|
43
|
+
}
|
|
44
|
+
process.stdout.write(' claude # then type /do to start building\n');
|
|
45
|
+
}
|
package/dist/src/links.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const h = { 'Content-Type': 'application/json' };
|
|
5
|
-
const k = process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
6
|
-
if (k)
|
|
7
|
-
h['Authorization'] = `Bearer ${k}`;
|
|
8
|
-
return h;
|
|
9
|
-
}
|
|
2
|
+
import { authHeaders, resolveBase } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://api.one.ie');
|
|
10
4
|
async function ask(api, receiver, data) {
|
|
11
5
|
const res = await fetch(`${api.replace(/\/$/, '')}/api/ask/${encodeURIComponent(receiver)}`, {
|
|
12
6
|
method: 'POST',
|
|
13
|
-
headers:
|
|
7
|
+
headers: authHeaders(),
|
|
14
8
|
body: JSON.stringify({ data }),
|
|
15
9
|
});
|
|
16
10
|
if (!res.ok) {
|
package/dist/src/plugin.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { mkdirSync } from 'node:fs';
|
|
3
3
|
import { spawnSync } from 'node:child_process';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { jsonMode, resolveBase, resolveKey } from './lib/client.js';
|
|
5
|
+
function out(label, data, cmd) {
|
|
6
|
+
if (cmd ? jsonMode(cmd) : process.env.ONEIE_JSON) {
|
|
7
|
+
process.stdout.write(JSON.stringify({ cmd: label, ...data }) + '\n');
|
|
7
8
|
}
|
|
8
9
|
else {
|
|
9
10
|
const ok = data.ok !== false;
|
|
@@ -11,14 +12,14 @@ function out(cmd, data) {
|
|
|
11
12
|
.filter(([k]) => k !== 'ok')
|
|
12
13
|
.map(([k, v]) => `${k}=${JSON.stringify(v)}`)
|
|
13
14
|
.join(' ');
|
|
14
|
-
console.log(`${ok ? '✓' : '✗'} ${
|
|
15
|
+
console.log(`${ok ? '✓' : '✗'} ${label} ${pairs}`);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
function apiBase(opts) {
|
|
18
|
-
return opts
|
|
19
|
+
return resolveBase(opts, 'https://one.ie');
|
|
19
20
|
}
|
|
20
21
|
function bearerHeaders(workspace) {
|
|
21
|
-
const key =
|
|
22
|
+
const key = resolveKey();
|
|
22
23
|
return key && workspace ? { Authorization: `Bearer ${workspace}:${key}` } : {};
|
|
23
24
|
}
|
|
24
25
|
// npm pack wraps a package's contents under a "package/" root — strip-components=1 lands
|
package/dist/src/render.d.ts
CHANGED
|
@@ -15,4 +15,7 @@ export interface ClientPL {
|
|
|
15
15
|
balance: number;
|
|
16
16
|
cap: number | null;
|
|
17
17
|
}
|
|
18
|
+
/** The CLIENT/PLAN/FUNDED/… table — shared by `status` (with the agency P&L
|
|
19
|
+
* header) and `client list` (bare, no header). */
|
|
20
|
+
export declare function renderClientTable(clients: ClientPL[], markupPct: number): string;
|
|
18
21
|
export declare function renderStatus(agency: AgencyPL, clients: ClientPL[]): string;
|
package/dist/src/render.js
CHANGED
|
@@ -3,8 +3,10 @@ const capFmt = (n) => (n == null ? '—' : fmt(n));
|
|
|
3
3
|
function pad(cells, widths) {
|
|
4
4
|
return cells.map((c, i) => c.padEnd(widths[i])).join(' ').replace(/\s+$/, '');
|
|
5
5
|
}
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/** The CLIENT/PLAN/FUNDED/… table — shared by `status` (with the agency P&L
|
|
7
|
+
* header) and `client list` (bare, no header). */
|
|
8
|
+
export function renderClientTable(clients, markupPct) {
|
|
9
|
+
const header = ['CLIENT', 'PLAN', 'FUNDED', 'BURNED', `MARGIN(${markupPct}%)`, 'BALANCE', 'CAP'];
|
|
8
10
|
const rows = clients.map((c) => [
|
|
9
11
|
c.slug, c.plan, fmt(c.funded), fmt(c.burned), fmt(c.margin), fmt(c.balance), capFmt(c.cap),
|
|
10
12
|
]);
|
|
@@ -12,8 +14,6 @@ export function renderStatus(agency, clients) {
|
|
|
12
14
|
const totalBurned = clients.reduce((s, c) => s + c.burned, 0);
|
|
13
15
|
const totalMargin = clients.reduce((s, c) => s + c.margin, 0);
|
|
14
16
|
const out = [];
|
|
15
|
-
out.push(`Agency: ${agency.name ?? agency.slug} (${agency.slug}) plan=${agency.plan} markup=${agency.markup_pct}% pool=${fmt(agency.pool)} cr`);
|
|
16
|
-
out.push('');
|
|
17
17
|
out.push(pad(header, widths));
|
|
18
18
|
for (const r of rows)
|
|
19
19
|
out.push(pad(r, widths));
|
|
@@ -23,3 +23,10 @@ export function renderStatus(agency, clients) {
|
|
|
23
23
|
out.push(`\n total burned ${fmt(totalBurned)} · margin ${fmt(totalMargin)} ← your margin this period`);
|
|
24
24
|
return out.join('\n');
|
|
25
25
|
}
|
|
26
|
+
export function renderStatus(agency, clients) {
|
|
27
|
+
const out = [];
|
|
28
|
+
out.push(`Agency: ${agency.name ?? agency.slug} (${agency.slug}) plan=${agency.plan} markup=${agency.markup_pct}% pool=${fmt(agency.pool)} cr`);
|
|
29
|
+
out.push('');
|
|
30
|
+
out.push(renderClientTable(clients, agency.markup_pct));
|
|
31
|
+
return out.join('\n');
|
|
32
|
+
}
|
package/dist/src/setup.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
/** No key in env — provision one via the same open call `init` uses, then
|
|
3
|
+
* reconcile the returned slug down into .env.local + workspace.toml. The
|
|
4
|
+
* route mints its own slug; it does not accept a desired one (contract #4). */
|
|
5
|
+
export declare function keylessSetup(dir: string, cfgPath: string | undefined, web: string): Promise<void>;
|
|
2
6
|
export declare function setupCmd(): Command;
|
package/dist/src/setup.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import { existsSync } from 'node:fs';
|
|
2
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { mergeEnv, writeEnvLocal } from './env.js';
|
|
4
4
|
import { readAgency } from './config.js';
|
|
5
|
-
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://one.ie';
|
|
5
|
+
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
|
|
6
|
+
const DEFAULT_WEB = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
|
|
6
7
|
async function ask(base, key, receiver, data) {
|
|
7
8
|
const res = await fetch(`${base}/api/ask/${encodeURIComponent(receiver)}`, {
|
|
8
9
|
method: 'POST',
|
|
@@ -23,28 +24,85 @@ async function ask(base, key, receiver, data) {
|
|
|
23
24
|
}
|
|
24
25
|
return json;
|
|
25
26
|
}
|
|
27
|
+
function findConfigPath(dir) {
|
|
28
|
+
for (const name of ['_node.toml', 'agency.toml', 'partner.toml', 'workspace.toml']) {
|
|
29
|
+
if (existsSync(`${dir}/${name}`))
|
|
30
|
+
return `${dir}/${name}`;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
/** No key in env — provision one via the same open call `init` uses, then
|
|
35
|
+
* reconcile the returned slug down into .env.local + workspace.toml. The
|
|
36
|
+
* route mints its own slug; it does not accept a desired one (contract #4). */
|
|
37
|
+
export async function keylessSetup(dir, cfgPath, web) {
|
|
38
|
+
let name = 'my-workspace';
|
|
39
|
+
if (cfgPath) {
|
|
40
|
+
try {
|
|
41
|
+
name = readAgency(cfgPath).name;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
// toml without slug/name (e.g. a bare workspace.toml) — fall through with the default
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const ownerEmail = mergeEnv(dir).WORKSPACE_OWNER_EMAIL;
|
|
48
|
+
const body = { name };
|
|
49
|
+
if (ownerEmail)
|
|
50
|
+
body.invite = { email: ownerEmail, role: 'owner' };
|
|
51
|
+
const res = await fetch(`${web}/api/provision/agent`, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers: { 'Content-Type': 'application/json' },
|
|
54
|
+
body: JSON.stringify(body),
|
|
55
|
+
});
|
|
56
|
+
const json = (await res.json());
|
|
57
|
+
if (!res.ok) {
|
|
58
|
+
process.stderr.write(`provision/agent → ${res.status}\n${JSON.stringify(json)}\n`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
const { uid, workspace, apiKey } = json;
|
|
62
|
+
writeEnvLocal(dir, {
|
|
63
|
+
ONE_API_KEY: apiKey,
|
|
64
|
+
WORKSPACE_ID: workspace,
|
|
65
|
+
WORKSPACE_SLUG: workspace,
|
|
66
|
+
AGENCY_WSID: workspace,
|
|
67
|
+
AGENCY_SLUG: workspace,
|
|
68
|
+
CC_ACTOR_ID: uid,
|
|
69
|
+
});
|
|
70
|
+
let reconciled = '';
|
|
71
|
+
const targetToml = cfgPath ?? `${dir}/workspace.toml`;
|
|
72
|
+
if (existsSync(targetToml)) {
|
|
73
|
+
let toml = readFileSync(targetToml, 'utf8');
|
|
74
|
+
if (/^slug\s*=/m.test(toml)) {
|
|
75
|
+
toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug = "${workspace}"`);
|
|
76
|
+
writeFileSync(targetToml, toml);
|
|
77
|
+
reconciled = ` reconciled: ${targetToml} slug → ${workspace}\n`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
process.stdout.write(`Workspace provisioned: ${workspace}\n`);
|
|
81
|
+
process.stdout.write(` key: ${apiKey.slice(0, 8)}… (written to .env.local)\n`);
|
|
82
|
+
process.stdout.write(reconciled);
|
|
83
|
+
}
|
|
26
84
|
export function setupCmd() {
|
|
27
85
|
return new Command('setup')
|
|
28
|
-
.description('Bootstrap
|
|
86
|
+
.description('Bootstrap a workspace (idempotent) — keyless: provisions with no prior account')
|
|
29
87
|
.option('--api <url>', 'API base URL', DEFAULT_API)
|
|
30
88
|
.option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
|
|
31
89
|
.action(async (opts) => {
|
|
32
90
|
const dir = process.cwd();
|
|
33
91
|
const env = mergeEnv(dir);
|
|
34
92
|
const key = opts.key ?? env.ONEIE_API_KEY ?? env.ONE_API_KEY ?? '';
|
|
35
|
-
if (env.AGENCY_WSID && env.CC_ACTOR_ID) {
|
|
36
|
-
process.stdout.write(`
|
|
93
|
+
if ((env.AGENCY_WSID && env.CC_ACTOR_ID) || env.ONE_API_KEY) {
|
|
94
|
+
process.stdout.write(`Workspace already set up (${env.AGENCY_WSID ?? env.WORKSPACE_SLUG}). No-op.\n`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const cfgPath = findConfigPath(dir);
|
|
98
|
+
if (!key) {
|
|
99
|
+
await keylessSetup(dir, cfgPath, DEFAULT_WEB);
|
|
37
100
|
return;
|
|
38
101
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
: existsSync(`${dir}/partner.toml`)
|
|
44
|
-
? `${dir}/partner.toml`
|
|
45
|
-
: existsSync(`${dir}/workspace.toml`)
|
|
46
|
-
? `${dir}/workspace.toml`
|
|
47
|
-
: `${dir}/agency.toml`;
|
|
102
|
+
if (!cfgPath) {
|
|
103
|
+
process.stderr.write(`No _node.toml/agency.toml/partner.toml/workspace.toml found in ${dir}\n`);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
48
106
|
const agency = readAgency(cfgPath);
|
|
49
107
|
const base = opts.api.replace(/\/$/, '');
|
|
50
108
|
const ws = await ask(base, key, 'world:create-workspace', {
|
package/dist/src/social.js
CHANGED
|
@@ -1,31 +1,9 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { resolve } from 'node:path';
|
|
5
|
-
const DEFAULT_API = 'https://one.ie';
|
|
6
|
-
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
2
|
+
import { out, resolveBase, resolveKey } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
7
4
|
function readApiKey() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (existsSync(KEY_FILE))
|
|
11
|
-
return readFileSync(KEY_FILE, 'utf8').trim() || null;
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
function out(cmd, data) {
|
|
15
|
-
const isJson = cmd.parent?.parent?.opts().json;
|
|
16
|
-
if (isJson) {
|
|
17
|
-
process.stdout.write(JSON.stringify(data) + '\n');
|
|
18
|
-
}
|
|
19
|
-
else if (data.ok) {
|
|
20
|
-
const pairs = Object.entries(data)
|
|
21
|
-
.filter(([k]) => k !== 'ok')
|
|
22
|
-
.map(([k, v]) => `${k}=${JSON.stringify(v)}`);
|
|
23
|
-
process.stdout.write(`ok ${pairs.join(' ')}\n`);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
process.stderr.write(`error ${data.error ?? 'unknown'}\n`);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
5
|
+
const key = resolveKey();
|
|
6
|
+
return key || null;
|
|
29
7
|
}
|
|
30
8
|
export function socialCmd() {
|
|
31
9
|
const cmd = new Command('social').description('Social post management');
|
package/dist/src/staff.js
CHANGED
|
@@ -1,29 +1,7 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { resolve } from 'node:path';
|
|
5
|
-
const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://one.ie';
|
|
6
|
-
const KEY_FILE = resolve(homedir(), '.config', 'oneie', 'key');
|
|
2
|
+
import { authHeaders, out, resolveBase, resolveKey } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
7
4
|
const VALID_ROLES = ['owner', 'admin', 'member', 'viewer'];
|
|
8
|
-
function readApiKey() {
|
|
9
|
-
if (process.env.ONEIE_API_KEY)
|
|
10
|
-
return process.env.ONEIE_API_KEY;
|
|
11
|
-
if (existsSync(KEY_FILE))
|
|
12
|
-
return readFileSync(KEY_FILE, 'utf8').trim() || null;
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
function out(data) {
|
|
16
|
-
if (data.ok) {
|
|
17
|
-
const pairs = Object.entries(data)
|
|
18
|
-
.filter(([k]) => k !== 'ok')
|
|
19
|
-
.map(([k, v]) => `${k}=${JSON.stringify(v)}`);
|
|
20
|
-
process.stdout.write(`ok ${pairs.join(' ')}\n`);
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
process.stderr.write(`error ${data.error ?? 'unknown'}\n`);
|
|
24
|
-
process.exit(1);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
5
|
export function staffCmd() {
|
|
28
6
|
const cmd = new Command('staff').description('Workspace staff management');
|
|
29
7
|
cmd
|
|
@@ -36,16 +14,16 @@ export function staffCmd() {
|
|
|
36
14
|
.action(async (email, opts) => {
|
|
37
15
|
const role = opts.role;
|
|
38
16
|
if (!VALID_ROLES.includes(role)) {
|
|
39
|
-
out({ ok: false, error: `--role must be one of: ${VALID_ROLES.join(', ')}` });
|
|
17
|
+
out(cmd, { ok: false, error: `--role must be one of: ${VALID_ROLES.join(', ')}` });
|
|
40
18
|
return;
|
|
41
19
|
}
|
|
42
20
|
if (opts.dryRun) {
|
|
43
|
-
out({ ok: true, dry_run: true, email: email ?? '(url-only)', role, workspace: opts.workspace ?? '(authenticated)' });
|
|
21
|
+
out(cmd, { ok: true, dry_run: true, email: email ?? '(url-only)', role, workspace: opts.workspace ?? '(authenticated)' });
|
|
44
22
|
return;
|
|
45
23
|
}
|
|
46
|
-
const key =
|
|
24
|
+
const key = resolveKey();
|
|
47
25
|
if (!key) {
|
|
48
|
-
out({ ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
|
|
26
|
+
out(cmd, { ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
|
|
49
27
|
return;
|
|
50
28
|
}
|
|
51
29
|
const base = opts.api.replace(/\/$/, '');
|
|
@@ -56,21 +34,21 @@ export function staffCmd() {
|
|
|
56
34
|
body.workspace = opts.workspace;
|
|
57
35
|
const res = await fetch(`${base}/api/ask/world:invite-member`, {
|
|
58
36
|
method: 'POST',
|
|
59
|
-
headers: {
|
|
37
|
+
headers: authHeaders({ key }),
|
|
60
38
|
body: JSON.stringify({ data: body }),
|
|
61
39
|
});
|
|
62
40
|
if (!res.ok) {
|
|
63
41
|
const text = await res.text().catch(() => '');
|
|
64
|
-
out({ ok: false, error: `${res.status}: ${text}` });
|
|
42
|
+
out(cmd, { ok: false, error: `${res.status}: ${text}` });
|
|
65
43
|
return;
|
|
66
44
|
}
|
|
67
45
|
const json = (await res.json());
|
|
68
46
|
if (json.error) {
|
|
69
|
-
out({ ok: false, error: json.error });
|
|
47
|
+
out(cmd, { ok: false, error: json.error });
|
|
70
48
|
return;
|
|
71
49
|
}
|
|
72
50
|
const inviteUrl = json.inviteUrl ?? (json.token ? `${base}/join?token=${encodeURIComponent(json.token)}` : undefined);
|
|
73
|
-
out({ ok: true, email: email ?? '(url-only)', role, invite_url: inviteUrl ?? '(sent)' });
|
|
51
|
+
out(cmd, { ok: true, email: email ?? '(url-only)', role, invite_url: inviteUrl ?? '(sent)' });
|
|
74
52
|
});
|
|
75
53
|
cmd
|
|
76
54
|
.command('add-agent <name>')
|
|
@@ -81,12 +59,12 @@ export function staffCmd() {
|
|
|
81
59
|
.action(async (name, opts) => {
|
|
82
60
|
const role = opts.role;
|
|
83
61
|
if (!VALID_ROLES.includes(role)) {
|
|
84
|
-
out({ ok: false, error: `--role must be one of: ${VALID_ROLES.join(', ')}` });
|
|
62
|
+
out(cmd, { ok: false, error: `--role must be one of: ${VALID_ROLES.join(', ')}` });
|
|
85
63
|
return;
|
|
86
64
|
}
|
|
87
|
-
const key =
|
|
65
|
+
const key = resolveKey();
|
|
88
66
|
if (!key) {
|
|
89
|
-
out({ ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
|
|
67
|
+
out(cmd, { ok: false, error: 'no API key — set ONEIE_API_KEY or run: oneie auth login' });
|
|
90
68
|
return;
|
|
91
69
|
}
|
|
92
70
|
const base = opts.api.replace(/\/$/, '');
|
|
@@ -95,21 +73,21 @@ export function staffCmd() {
|
|
|
95
73
|
body.workspace = opts.workspace;
|
|
96
74
|
const res = await fetch(`${base}/api/ask/world:invite-agent`, {
|
|
97
75
|
method: 'POST',
|
|
98
|
-
headers: {
|
|
76
|
+
headers: authHeaders({ key }),
|
|
99
77
|
body: JSON.stringify({ data: body }),
|
|
100
78
|
});
|
|
101
79
|
if (!res.ok) {
|
|
102
80
|
const text = await res.text().catch(() => '');
|
|
103
|
-
out({ ok: false, error: `${res.status}: ${text}` });
|
|
81
|
+
out(cmd, { ok: false, error: `${res.status}: ${text}` });
|
|
104
82
|
return;
|
|
105
83
|
}
|
|
106
84
|
const json = (await res.json());
|
|
107
85
|
if (json.error) {
|
|
108
|
-
out({ ok: false, error: json.error });
|
|
86
|
+
out(cmd, { ok: false, error: json.error });
|
|
109
87
|
return;
|
|
110
88
|
}
|
|
111
89
|
const result = json.result ?? json;
|
|
112
|
-
out({ ok: true, name, role, aid: result.aid, key: result.key });
|
|
90
|
+
out(cmd, { ok: true, name, role, aid: result.aid, key: result.key });
|
|
113
91
|
});
|
|
114
92
|
return cmd;
|
|
115
93
|
}
|
package/dist/src/substrate.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
4
|
-
}
|
|
1
|
+
import { authHeaders, resolveBase } from './lib/client.js';
|
|
2
|
+
const DEFAULT_API = resolveBase({}, 'https://api.one.ie');
|
|
5
3
|
function base(opts) {
|
|
6
|
-
return (opts
|
|
7
|
-
}
|
|
8
|
-
function headers() {
|
|
9
|
-
const h = { 'Content-Type': 'application/json' };
|
|
10
|
-
const k = apiKey();
|
|
11
|
-
if (k)
|
|
12
|
-
h['Authorization'] = `Bearer ${k}`;
|
|
13
|
-
return h;
|
|
4
|
+
return resolveBase(opts, 'https://api.one.ie');
|
|
14
5
|
}
|
|
15
6
|
async function api(url, init) {
|
|
16
|
-
const res = await fetch(url, { headers:
|
|
7
|
+
const res = await fetch(url, { headers: authHeaders(), ...init });
|
|
17
8
|
if (!res.ok) {
|
|
18
9
|
const body = await res.text().catch(() => '');
|
|
19
10
|
process.stderr.write(`${init?.method ?? 'GET'} ${url} → ${res.status}\n${body}\n`);
|
package/dist/src/trail.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
|
|
5
|
-
}
|
|
2
|
+
import { authHeaders, jsonMode, resolveBase } from './lib/client.js';
|
|
3
|
+
const DEFAULT_API = resolveBase({}, 'https://one.ie');
|
|
6
4
|
export function trailCmd() {
|
|
7
|
-
|
|
5
|
+
const cmd = new Command('trail')
|
|
8
6
|
.description('read trail confidence for a tag combination — ranked next tasks from KV')
|
|
9
7
|
.argument('<tags>', 'comma-separated tags, e.g. fn:engineering,builds,deploy')
|
|
10
8
|
.option('--workspace <ws>', 'workspace slug', 'global')
|
|
11
9
|
.option('--limit <n>', 'max results', '10')
|
|
12
10
|
.option('--api <url>', 'api base url', DEFAULT_API)
|
|
13
11
|
.action(async (tags, opts) => {
|
|
14
|
-
const base = opts
|
|
15
|
-
const key = apiKey();
|
|
12
|
+
const base = resolveBase(opts, 'https://one.ie');
|
|
16
13
|
const sorted = tags.split(',').map((t) => t.trim()).filter(Boolean).sort().join(',');
|
|
17
14
|
const params = new URLSearchParams({ tags: sorted, workspace: opts.workspace, limit: opts.limit });
|
|
18
15
|
const res = await fetch(`${base}/api/export/trail?${params}`, {
|
|
19
|
-
headers:
|
|
20
|
-
'Content-Type': 'application/json',
|
|
21
|
-
...(key ? { Authorization: `Bearer ${key}` } : {}),
|
|
22
|
-
},
|
|
16
|
+
headers: authHeaders(),
|
|
23
17
|
});
|
|
24
18
|
if (!res.ok) {
|
|
25
19
|
const body = await res.text().catch(() => '');
|
|
@@ -27,8 +21,7 @@ export function trailCmd() {
|
|
|
27
21
|
process.exit(1);
|
|
28
22
|
}
|
|
29
23
|
const data = (await res.json());
|
|
30
|
-
|
|
31
|
-
if (isJson) {
|
|
24
|
+
if (jsonMode(cmd)) {
|
|
32
25
|
process.stdout.write(JSON.stringify(data, null, 2) + '\n');
|
|
33
26
|
return;
|
|
34
27
|
}
|
|
@@ -44,4 +37,5 @@ export function trailCmd() {
|
|
|
44
37
|
process.stdout.write(` ${pct}% score=${score} ${t.slug}\n`);
|
|
45
38
|
}
|
|
46
39
|
});
|
|
40
|
+
return cmd;
|
|
47
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oneie/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "ONE agent CLI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"commander": "^12.0.0",
|
|
23
|
-
"@oneie/sdk": "0.14.
|
|
23
|
+
"@oneie/sdk": "^0.14.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@oneie/evals": "
|
|
26
|
+
"@oneie/evals": "workspace:*",
|
|
27
27
|
"@types/node": "^25.6.0",
|
|
28
28
|
"tsx": "^4.0.0",
|
|
29
29
|
"typescript": "^5.4.0",
|