@oneie/cli 0.10.1 → 4.0.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "0.10.1",
3
+ "version": "4.0.0",
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": "workspace:*"
23
+ "@oneie/sdk": "^0.14.6"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@oneie/evals": "workspace:*",
@@ -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
- export function authCmd() {
12
- const cmd = new Command('auth').description('Authentication');
13
- cmd.command('login')
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(() => {
@@ -1,16 +1,10 @@
1
1
  import { Command } from 'commander';
2
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
3
- function headers() {
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: 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
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://one.ie';
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: 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 = process.env.ONEIE_API_KEY ?? process.env.ONE_API_KEY ?? '';
58
+ const key = resolveKey();
65
59
  const h = { Accept: 'text/event-stream' };
66
60
  if (key)
67
61
  h['Authorization'] = `Bearer ${key}`;
@@ -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;
@@ -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')
@@ -1,4 +1,4 @@
1
- export type Plan = 'free' | 'pro' | 'studio' | 'agency' | 'enterprise';
1
+ export type Plan = 'starter' | 'free' | 'pro' | 'studio' | 'agency' | 'enterprise';
2
2
  export interface AgencyConfig {
3
3
  slug: string;
4
4
  name: string;
@@ -1,31 +1,9 @@
1
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
- 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
- if (process.env.ONEIE_API_KEY)
9
- return process.env.ONEIE_API_KEY;
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
@@ -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 { homedir } from 'node:os';
5
- import { resolve } from 'node:path';
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
- if (process.env.ONEIE_API_KEY)
11
- return process.env.ONEIE_API_KEY;
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,9 @@
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';
6
8
  import { devCmd } from './dev.js';
7
9
  import { groupCmd } from './group.js';
8
10
  import { socialCmd } from './social.js';
@@ -54,6 +56,9 @@ program.addCommand(staffCmd());
54
56
  program.addCommand(evalCmd());
55
57
  program.addCommand(setupCmd());
56
58
  program.addCommand(clientCmd());
59
+ program.addCommand(doctorCmd());
60
+ program.addCommand(whoamiCmd());
61
+ program.addCommand(buildLoginCommand());
57
62
  program.addCommand(walletCmd());
58
63
  program.addCommand(pushCmd());
59
64
  program.addCommand(deployCmd());
@@ -69,6 +74,23 @@ program.addCommand(trailCmd());
69
74
  program.addCommand(initCmd());
70
75
  program.addCommand(onboardCmd());
71
76
  program.addCommand(pluginCmd());
77
+ // Bare `oneie` (no args, no --help/--version): route the audience to its
78
+ // journey instead of commander's default help dump. Never an interactive
79
+ // prompt — agent env and human TTY both get a printed block (contract #10).
80
+ if (process.argv.length === 2) {
81
+ if (isAgentEnvironment()) {
82
+ process.stdout.write('oneie — no workspace yet.\n' +
83
+ ' oneie init --write-env # provision a workspace, no account required\n' +
84
+ ' oneie onboard # provision + walk the lifecycle stages\n' +
85
+ ' oneie --help # full command reference\n');
86
+ }
87
+ else {
88
+ process.stdout.write('oneie — ONE, the agent CLI.\n\n' +
89
+ ' npx oneie create <name> # scaffold a new workspace\n' +
90
+ ' oneie --help # full command reference\n');
91
+ }
92
+ process.exit(0);
93
+ }
72
94
  program.parseAsync(process.argv).catch((err) => {
73
95
  const isJson = process.argv.includes('--json');
74
96
  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
+ }
package/dist/src/links.js CHANGED
@@ -1,16 +1,10 @@
1
1
  import { Command } from 'commander';
2
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
3
- function headers() {
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: headers(),
7
+ headers: authHeaders(),
14
8
  body: JSON.stringify({ data }),
15
9
  });
16
10
  if (!res.ok) {
@@ -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
- function out(cmd, data) {
5
- if (process.env.ONEIE_JSON) {
6
- process.stdout.write(JSON.stringify({ cmd, ...data }) + '\n');
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 ? '✓' : '✗'} ${cmd} ${pairs}`);
15
+ console.log(`${ok ? '✓' : '✗'} ${label} ${pairs}`);
15
16
  }
16
17
  }
17
18
  function apiBase(opts) {
18
- return opts.api ?? process.env.ONEIE_BASE_URL ?? 'https://one.ie';
19
+ return resolveBase(opts, 'https://one.ie');
19
20
  }
20
21
  function bearerHeaders(workspace) {
21
- const key = process.env.ONEIE_API_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
@@ -1,7 +1,6 @@
1
1
  export interface AgencyPL {
2
2
  slug: string;
3
3
  name: string | null;
4
- plan: string;
5
4
  markup_pct: number;
6
5
  pool: number;
7
6
  }
@@ -15,4 +14,7 @@ export interface ClientPL {
15
14
  balance: number;
16
15
  cap: number | null;
17
16
  }
17
+ /** The CLIENT/PLAN/FUNDED/… table — shared by `status` (with the agency P&L
18
+ * header) and `client list` (bare, no header). */
19
+ export declare function renderClientTable(clients: ClientPL[], markupPct: number): string;
18
20
  export declare function renderStatus(agency: AgencyPL, clients: ClientPL[]): string;
@@ -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
- export function renderStatus(agency, clients) {
7
- const header = ['CLIENT', 'PLAN', 'FUNDED', 'BURNED', `MARGIN(${agency.markup_pct}%)`, 'BALANCE', 'CAP'];
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 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
+ }
@@ -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',
@@ -13,38 +14,87 @@ async function ask(base, key, receiver, data) {
13
14
  const body = await res.text().catch(() => '');
14
15
  throw new Error(`${receiver} → ${res.status}\n${body}`);
15
16
  }
16
- const json = await res.json();
17
- if (json.outcome === 'failure') {
18
- const result = (json.result ?? {});
19
- const details = Object.entries(result)
20
- .map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
21
- .join(' ');
22
- throw new Error(`${receiver} → forbidden: ${details}`);
17
+ return res.json();
18
+ }
19
+ function findConfigPath(dir) {
20
+ for (const name of ['_node.toml', 'agency.toml', 'partner.toml', 'workspace.toml']) {
21
+ if (existsSync(`${dir}/${name}`))
22
+ return `${dir}/${name}`;
23
23
  }
24
- return json;
24
+ return undefined;
25
+ }
26
+ /** No key in env — provision one via the same open call `init` uses, then
27
+ * reconcile the returned slug down into .env.local + workspace.toml. The
28
+ * route mints its own slug; it does not accept a desired one (contract #4). */
29
+ export async function keylessSetup(dir, cfgPath, web) {
30
+ let name = 'my-workspace';
31
+ if (cfgPath) {
32
+ try {
33
+ name = readAgency(cfgPath).name;
34
+ }
35
+ catch {
36
+ // toml without slug/name (e.g. a bare workspace.toml) — fall through with the default
37
+ }
38
+ }
39
+ const ownerEmail = mergeEnv(dir).WORKSPACE_OWNER_EMAIL;
40
+ const body = { name };
41
+ if (ownerEmail)
42
+ body.invite = { email: ownerEmail, role: 'owner' };
43
+ const res = await fetch(`${web}/api/provision/agent`, {
44
+ method: 'POST',
45
+ headers: { 'Content-Type': 'application/json' },
46
+ body: JSON.stringify(body),
47
+ });
48
+ const json = (await res.json());
49
+ if (!res.ok) {
50
+ process.stderr.write(`provision/agent → ${res.status}\n${JSON.stringify(json)}\n`);
51
+ process.exit(1);
52
+ }
53
+ const { uid, workspace, apiKey } = json;
54
+ writeEnvLocal(dir, {
55
+ ONE_API_KEY: apiKey,
56
+ WORKSPACE_ID: workspace,
57
+ WORKSPACE_SLUG: workspace,
58
+ AGENCY_WSID: workspace,
59
+ AGENCY_SLUG: workspace,
60
+ CC_ACTOR_ID: uid,
61
+ });
62
+ let reconciled = '';
63
+ const targetToml = cfgPath ?? `${dir}/workspace.toml`;
64
+ if (existsSync(targetToml)) {
65
+ let toml = readFileSync(targetToml, 'utf8');
66
+ if (/^slug\s*=/m.test(toml)) {
67
+ toml = toml.replace(/^slug\s*=\s*"[^"]*"/m, `slug = "${workspace}"`);
68
+ writeFileSync(targetToml, toml);
69
+ reconciled = ` reconciled: ${targetToml} slug → ${workspace}\n`;
70
+ }
71
+ }
72
+ process.stdout.write(`Workspace provisioned: ${workspace}\n`);
73
+ process.stdout.write(` key: ${apiKey.slice(0, 8)}… (written to .env.local)\n`);
74
+ process.stdout.write(reconciled);
25
75
  }
26
76
  export function setupCmd() {
27
77
  return new Command('setup')
28
- .description('Bootstrap agency workspace (idempotent)')
78
+ .description('Bootstrap a workspace (idempotent) — keyless: provisions with no prior account')
29
79
  .option('--api <url>', 'API base URL', DEFAULT_API)
30
80
  .option('--key <key>', 'API key (overrides ONEIE_API_KEY env)')
31
81
  .action(async (opts) => {
32
82
  const dir = process.cwd();
33
83
  const env = mergeEnv(dir);
34
84
  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(`Agency already set up (${env.AGENCY_WSID}). No-op.\n`);
85
+ if ((env.AGENCY_WSID && env.CC_ACTOR_ID) || env.ONE_API_KEY) {
86
+ process.stdout.write(`Workspace already set up (${env.AGENCY_WSID ?? env.WORKSPACE_SLUG}). No-op.\n`);
37
87
  return;
38
88
  }
39
- const cfgPath = existsSync(`${dir}/_node.toml`)
40
- ? `${dir}/_node.toml`
41
- : existsSync(`${dir}/agency.toml`)
42
- ? `${dir}/agency.toml`
43
- : existsSync(`${dir}/partner.toml`)
44
- ? `${dir}/partner.toml`
45
- : existsSync(`${dir}/workspace.toml`)
46
- ? `${dir}/workspace.toml`
47
- : `${dir}/agency.toml`;
89
+ const cfgPath = findConfigPath(dir);
90
+ if (!key) {
91
+ await keylessSetup(dir, cfgPath, DEFAULT_WEB);
92
+ return;
93
+ }
94
+ if (!cfgPath) {
95
+ process.stderr.write(`No _node.toml/agency.toml/partner.toml/workspace.toml found in ${dir}\n`);
96
+ process.exit(1);
97
+ }
48
98
  const agency = readAgency(cfgPath);
49
99
  const base = opts.api.replace(/\/$/, '');
50
100
  const ws = await ask(base, key, 'world:create-workspace', {
@@ -1,31 +1,9 @@
1
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
- 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
- if (process.env.ONEIE_API_KEY)
9
- return process.env.ONEIE_API_KEY;
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 { existsSync, readFileSync } from 'node:fs';
3
- import { homedir } from 'node:os';
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 = readApiKey();
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: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
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 = readApiKey();
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: { 'Content-Type': 'application/json', Authorization: `Bearer ${key}` },
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
  }
@@ -1,7 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
  import { mergeEnv } from './env.js';
3
3
  import { renderStatus } from './render.js';
4
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://one.ie';
4
+ const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://api.one.ie';
5
5
  export function statusCmd() {
6
6
  return new Command('status')
7
7
  .description('Agency P&L dashboard (pool, margin, per-client burns)')
@@ -26,21 +26,13 @@ export function statusCmd() {
26
26
  process.stderr.write(`billing:clients → ${res.status}\n`);
27
27
  process.exit(1);
28
28
  }
29
- const json = await res.json();
30
- if (json.outcome === 'failure') {
31
- const result = (json.result ?? {});
32
- const details = Object.entries(result)
33
- .map(([k, v]) => `${k}=${typeof v === 'string' ? v : JSON.stringify(v)}`)
34
- .join(' ');
35
- process.stderr.write(`billing:clients → forbidden: ${details}\n`);
36
- process.exit(1);
37
- }
29
+ const data = await res.json();
38
30
  if (opts.json) {
39
- process.stdout.write(JSON.stringify(json, null, 2) + '\n');
31
+ process.stdout.write(JSON.stringify(data, null, 2) + '\n');
40
32
  return;
41
33
  }
42
- const agency = (json.agency ?? { slug: env.AGENCY_SLUG, name: env.AGENCY_NAME ?? null, markup_pct: 0, pool: 0, plan: 'free' });
43
- const clients = (json.clients ?? []);
34
+ const agency = (data.agency ?? { slug: env.AGENCY_SLUG, name: env.AGENCY_NAME ?? null, markup_pct: 0, pool: 0 });
35
+ const clients = (data.clients ?? []);
44
36
  process.stdout.write(renderStatus(agency, clients) + '\n');
45
37
  });
46
38
  }
@@ -1,19 +1,10 @@
1
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://api.one.ie';
2
- function apiKey() {
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.api ?? DEFAULT_API).replace(/\/$/, '');
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: headers(), ...init });
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
- const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_BASE_URL ?? 'https://one.ie';
3
- function apiKey() {
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
- return new Command('trail')
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.api.replace(/\/$/, '');
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
- const isJson = process.argv.includes('--json');
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.10.1",
3
+ "version": "4.0.0",
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.5"
23
+ "@oneie/sdk": "^0.14.6"
24
24
  },
25
25
  "devDependencies": {
26
- "@oneie/evals": "0.1.0",
26
+ "@oneie/evals": "workspace:*",
27
27
  "@types/node": "^25.6.0",
28
28
  "tsx": "^4.0.0",
29
29
  "typescript": "^5.4.0",
@@ -1,2 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
@@ -1,22 +0,0 @@
1
- // @ts-nocheck — template file; typechecked in the target Astro project, not the CLI
2
- // Install: bun add @oneie/frontend
3
- // After setup: copy ONE_API_KEY from .env.local into backend.apiKey
4
- import { defineOne } from '@oneie/frontend';
5
- // The only per-node configuration:
6
- // - backend.apiKey: your workspace's scoped API key (from one setup)
7
- // - brand.tokens: 6 color tokens to match your brand
8
- export default defineOne({
9
- backend: {
10
- apiKey: process.env.ONE_API_KEY ?? '',
11
- },
12
- brand: {
13
- tokens: {
14
- primary: 'hsl(216 55% 25%)', // your brand primary
15
- secondary: 'hsl(160 40% 45%)', // secondary / accent
16
- tertiary: 'hsl(38 90% 55%)', // highlight / CTA
17
- background: 'hsl(0 0% 100%)', // page background
18
- foreground: 'hsl(220 20% 15%)', // body text
19
- font: 'Inter, system-ui, sans-serif',
20
- },
21
- },
22
- });