oneie 5.0.0 → 5.2.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/README.md CHANGED
@@ -192,6 +192,24 @@ JSON body, so the raw door is no worse than a wrapper:
192
192
  one ask media:generate --data '{"prompt":"a red bicycle"}'
193
193
  ```
194
194
 
195
+ ## Draw — ASCII diagrams, onto the board
196
+
197
+ ```bash
198
+ one draw [name|path] # open lazydraw (the TUI) on a drawing
199
+ one draw list # saved drawings
200
+ one draw export <name> [--basic] [--fenced] [-o out.txt]
201
+ one draw attach <name> --task <tid> [--workspace S] # post it to the task's thread
202
+ ```
203
+
204
+ `one draw` runs [lazydraw](https://github.com/mpospirit/lazydraw) (MIT, Çağrı
205
+ Gökpunar). It is a Bun app, so it is spawned rather than bundled: `lazydraw` if
206
+ it is on your PATH, else `bun x lazydraw@0.1.1`. Without Bun you get one line
207
+ telling you how to install it. Everything except `attach` is passed straight
208
+ through. `attach` exports plain ASCII in a Markdown fence and posts it through
209
+ `tasks:comment`, so the sketch sits on the row it explains. A diagram over the
210
+ door's 4000-byte comment cap is **refused** with both numbers, never cut, and a
211
+ comment the door trimmed is reported as `truncated`.
212
+
195
213
  ## Chat — fan in · fan out
196
214
 
197
215
  Send to a space, broadcast to all, or stream incoming messages:
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneie",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,18 @@
1
+ import { Command } from 'commander';
2
+ /** Pinned so `bun x` cannot quietly run a different release. ONE_LAZYDRAW overrides. */
3
+ export declare const LAZYDRAW_PKG = "lazydraw@0.1.1";
4
+ /** tasks:comment's MAX_COMMENT_BYTES (one.ie/web/src/lib/resolvers/tasks.ts). */
5
+ export declare const COMMENT_MAX_BYTES = 4000;
6
+ /** The argv that runs lazydraw on this machine, or null when neither lazydraw nor bun is reachable. */
7
+ export declare function resolveRunner(has?: (bin: string) => boolean): string[] | null;
8
+ /** The comment body `attach` posts, or a refusal naming the budget that bit. */
9
+ export declare function attachBody(name: string, diagram: string): {
10
+ ok: true;
11
+ body: string;
12
+ bytes: number;
13
+ } | {
14
+ ok: false;
15
+ error: string;
16
+ bytes: number;
17
+ };
18
+ export declare function drawCmd(): Command;
@@ -0,0 +1,156 @@
1
+ import { Command } from 'commander';
2
+ import { spawnSync } from 'node:child_process';
3
+ import { accessSync, constants } from 'node:fs';
4
+ import { delimiter, join } from 'node:path';
5
+ import { authHeaders, resolveBase } from './lib/client.js';
6
+ import { askPath } from './lib/api-path.js';
7
+ // `one draw` — ASCII diagrams in the terminal, via lazydraw
8
+ // (github.com/mpospirit/lazydraw, MIT, © Çağrı Gökpunar).
9
+ //
10
+ // NOT A DEPENDENCY, on purpose. The CLI's runtime deps are exactly commander +
11
+ // @oneie/sdk, and lazydraw is a Bun TUI (its bin is `src/cli.ts`, Bun >= 1.3)
12
+ // while `one` runs on node. So we spawn it: `lazydraw` if it is on PATH, else
13
+ // `bun x lazydraw@<pinned>`. Without Bun there is no editor to open, and the
14
+ // command says so in one line instead of a stack trace.
15
+ //
16
+ // What earns a verb here:
17
+ // draw [args…] PASSTHROUGH — `one draw`, `one draw <name>`, `one draw list`,
18
+ // `one draw export <name> --basic --fenced -o f` are lazydraw's own.
19
+ // attach EARNS IT — exports a drawing and posts it to a task's thread
20
+ // through tasks:comment, so a sketch lands on the board row it
21
+ // explains. The door caps a comment at 4000 bytes; a bigger
22
+ // diagram is REFUSED here with both numbers, never cut mid-line.
23
+ /** Pinned so `bun x` cannot quietly run a different release. ONE_LAZYDRAW overrides. */
24
+ export const LAZYDRAW_PKG = 'lazydraw@0.1.1';
25
+ /** tasks:comment's MAX_COMMENT_BYTES (one.ie/web/src/lib/resolvers/tasks.ts). */
26
+ export const COMMENT_MAX_BYTES = 4000;
27
+ const DEFAULT_API = 'https://api.one.ie';
28
+ function onPath(bin, path = process.env.PATH ?? '') {
29
+ for (const dir of path.split(delimiter)) {
30
+ if (!dir)
31
+ continue;
32
+ try {
33
+ accessSync(join(dir, bin), constants.X_OK);
34
+ return true;
35
+ }
36
+ catch {
37
+ /* next dir */
38
+ }
39
+ }
40
+ return false;
41
+ }
42
+ /** The argv that runs lazydraw on this machine, or null when neither lazydraw nor bun is reachable. */
43
+ export function resolveRunner(has = (b) => onPath(b)) {
44
+ if (has('lazydraw'))
45
+ return ['lazydraw'];
46
+ if (has('bun'))
47
+ return ['bun', 'x', process.env.ONE_LAZYDRAW || LAZYDRAW_PKG];
48
+ return null;
49
+ }
50
+ const NO_BUN = 'one draw needs Bun >= 1.3 (lazydraw is a Bun app): curl -fsSL https://bun.sh/install | bash — or `bun install -g lazydraw`';
51
+ /** The comment body `attach` posts, or a refusal naming the budget that bit. */
52
+ export function attachBody(name, diagram) {
53
+ const body = `Diagram \`${name}\` (one draw):\n\n${diagram.trim()}`;
54
+ const bytes = Buffer.byteLength(body, 'utf8');
55
+ if (!diagram.trim())
56
+ return { ok: false, error: `drawing "${name}" exported empty`, bytes };
57
+ if (bytes > COMMENT_MAX_BYTES) {
58
+ return {
59
+ ok: false,
60
+ error: `drawing "${name}" is ${bytes} bytes as a comment; tasks:comment keeps ${COMMENT_MAX_BYTES} — not posted (crop it, or export -o and attach the file)`,
61
+ bytes,
62
+ };
63
+ }
64
+ return { ok: true, body, bytes };
65
+ }
66
+ function fail(msg) {
67
+ process.stderr.write(`error ${msg}\n`);
68
+ process.exitCode = 1;
69
+ }
70
+ async function askComment(api, data) {
71
+ const res = await fetch(askPath(resolveBase({ api }, DEFAULT_API), 'tasks:comment'), {
72
+ method: 'POST',
73
+ headers: authHeaders(),
74
+ body: JSON.stringify({ data }),
75
+ });
76
+ const text = await res.text();
77
+ let o;
78
+ try {
79
+ o = JSON.parse(text);
80
+ }
81
+ catch {
82
+ throw new Error(`tasks:comment → ${res.status} ${text.slice(0, 200)}`);
83
+ }
84
+ if (o.outcome && o.outcome !== 'result') {
85
+ const inner = (o.result ?? {});
86
+ // ok:false LAST — an inner body's own `ok` must never overwrite a failed outcome.
87
+ return { ...inner, ok: false, error: inner.error ?? String(o.outcome) };
88
+ }
89
+ if (!res.ok)
90
+ throw new Error(`tasks:comment → ${res.status} ${text.slice(0, 200)}`);
91
+ return (o.result ?? o) ?? {};
92
+ }
93
+ export function drawCmd() {
94
+ const cmd = new Command('draw')
95
+ .description('ASCII diagrams in the terminal (lazydraw) — `one draw [name]`, `list`, `export`, `attach`')
96
+ .argument('[args...]', 'passed to lazydraw: <name|path> · list · export <name> [--basic] [--comment s] [--fenced] [-o f] · --import f')
97
+ .allowUnknownOption()
98
+ .helpOption('-h, --help', 'show this help (lazydraw’s own: one draw -- --help)')
99
+ .action((args) => {
100
+ const runner = resolveRunner();
101
+ if (!runner)
102
+ return fail(NO_BUN);
103
+ const [bin, ...pre] = runner;
104
+ const r = spawnSync(bin, [...pre, ...args], { stdio: 'inherit' });
105
+ if (r.error)
106
+ return fail(`${bin}: ${r.error.message}`);
107
+ process.exitCode = r.status ?? 1;
108
+ });
109
+ cmd
110
+ .command('attach <name>')
111
+ .description('Export a drawing and post it to a task thread (tasks:comment); refuses over the 4000-byte comment cap')
112
+ .requiredOption('--task <tid>', 'Task id, e.g. task:01a0…')
113
+ .option('--workspace <slug>', 'Workspace the task lives in (one you control)')
114
+ .option('--extended', 'Box-drawing characters instead of plain ASCII (+ - |)')
115
+ .option('--api <url>', 'API base URL', DEFAULT_API)
116
+ .option('--json', 'Print the receipt as JSON')
117
+ .action(async (name, opts) => {
118
+ const runner = resolveRunner();
119
+ if (!runner)
120
+ return fail(NO_BUN);
121
+ const [bin, ...pre] = runner;
122
+ const exportArgs = ['export', name, '--fenced', ...(opts.extended ? [] : ['--basic'])];
123
+ const r = spawnSync(bin, [...pre, ...exportArgs], { encoding: 'utf8' });
124
+ if (r.error)
125
+ return fail(`${bin}: ${r.error.message}`);
126
+ if (r.status !== 0)
127
+ return fail((r.stderr || `lazydraw export exited ${r.status}`).trim());
128
+ const built = attachBody(name, r.stdout);
129
+ if (!built.ok)
130
+ return fail(built.error);
131
+ const res = await askComment(opts.api, {
132
+ tid: opts.task,
133
+ body: built.body,
134
+ ...(opts.workspace ? { workspace: opts.workspace } : {}),
135
+ });
136
+ // The door's own receipt decides "cut", never our byte count: it trims before
137
+ // it measures, so comparing against what we sent reads a newline as a loss.
138
+ const submitted = typeof res.submittedBytes === 'number' ? res.submittedBytes : undefined;
139
+ const stored = typeof res.storedBytes === 'number' ? res.storedBytes : undefined;
140
+ const cut = res.truncated === true || (submitted !== undefined && stored !== undefined && stored < submitted);
141
+ const json = opts.json || process.argv.includes('--json');
142
+ const failed = res.ok === false || typeof res.error === 'string';
143
+ const receipt = { ok: !failed && !cut, tid: opts.task, drawing: name, submittedBytes: submitted, storedBytes: stored, ...(cut ? { truncated: true } : {}), ...(res.error ? { error: res.error } : {}) };
144
+ if (json)
145
+ process.stdout.write(JSON.stringify(receipt, null, 2) + '\n');
146
+ if (failed) {
147
+ const landed = typeof res.durability === 'string' ? ` (${res.durability})` : '';
148
+ return fail(`tasks:comment refused: ${String(res.error)}${landed}${res.retryable ? ' — retryable, run it again' : ''}`);
149
+ }
150
+ if (cut)
151
+ return fail(`posted but CUT: ${submitted} bytes submitted, ${stored} stored`);
152
+ if (!json)
153
+ process.stdout.write(`✓ ${name} → ${opts.task} (${built.bytes} bytes)\n`);
154
+ });
155
+ return cmd;
156
+ }
package/dist/src/index.js CHANGED
@@ -35,6 +35,7 @@ import { pluginCmd } from './plugin.js';
35
35
  import { workflowCmd } from './workflow.js';
36
36
  import { tasksCmd } from './tasks.js';
37
37
  import { mediaCmd } from './media.js';
38
+ import { drawCmd } from './draw.js';
38
39
  import { endpointCmd } from './endpoint.js';
39
40
  import { shopCmd } from './shop.js';
40
41
  import { readFileSync } from 'node:fs';
@@ -84,6 +85,7 @@ program.addCommand(pluginCmd());
84
85
  program.addCommand(workflowCmd());
85
86
  program.addCommand(tasksCmd());
86
87
  program.addCommand(mediaCmd());
88
+ program.addCommand(drawCmd());
87
89
  program.addCommand(endpointCmd());
88
90
  program.addCommand(shopCmd());
89
91
  // Bare `oneie` (no args, no --help/--version): route the audience to its
@@ -2,7 +2,7 @@
2
2
  * oneie init — provision a workspace in one command.
3
3
  *
4
4
  * Calls POST /api/provision/agent with the provided options, writes the
5
- * returned scoped key to ~/.config/oneie/key, and prints the workspace URL
5
+ * returned scoped key to ~/.config/one/key, and prints the workspace URL
6
6
  * + invite link.
7
7
  *
8
8
  * No prior account or API key required. The server mints everything.
package/dist/src/init.js CHANGED
@@ -2,29 +2,16 @@
2
2
  * oneie init — provision a workspace in one command.
3
3
  *
4
4
  * Calls POST /api/provision/agent with the provided options, writes the
5
- * returned scoped key to ~/.config/oneie/key, and prints the workspace URL
5
+ * returned scoped key to ~/.config/one/key, and prints the workspace URL
6
6
  * + invite link.
7
7
  *
8
8
  * No prior account or API key required. The server mints everything.
9
9
  */
10
10
  import { Command } from 'commander';
11
- import { writeFileSync, mkdirSync } from 'node:fs';
12
- import { resolve } from 'node:path';
13
- import { homedir } from 'node:os';
14
- import { renameSync, chmodSync } from 'node:fs';
15
- import { join } from 'node:path';
16
11
  import { mergeEnv, writeEnvLocal } from './env.js';
17
12
  import { writeKeyFolder } from './lib/keyfile.js';
13
+ import { KEY_FILE, writeMachineKey } from './lib/paths.js';
18
14
  const DEFAULT_API = process.env.ONEIE_BASE_URL ?? 'https://one.ie';
19
- const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
20
- const KEY_FILE = resolve(CONFIG_DIR, 'key');
21
- function writeKey(value) {
22
- mkdirSync(CONFIG_DIR, { recursive: true });
23
- const tmp = join(CONFIG_DIR, '.key.tmp');
24
- writeFileSync(tmp, value, { mode: 0o600 });
25
- chmodSync(tmp, 0o600);
26
- renameSync(tmp, KEY_FILE);
27
- }
28
15
  function out(cmd, data) {
29
16
  const isJson = cmd.parent?.opts().json;
30
17
  if (isJson) {
@@ -67,7 +54,7 @@ export function initCmd() {
67
54
  .option('--no-content', 'Skip generating a starter agent.md')
68
55
  .option('--api <url>', 'API base URL', DEFAULT_API)
69
56
  .option('--write-env', 'Also write ONE_API_KEY to .env.local in the current directory')
70
- .option('--dir <path>', 'Write the key into THIS project folder (.oneie/agent.key, 0600, gitignored) instead of the machine-wide ~/.config/oneie/key')
57
+ .option('--dir <path>', 'Write the key into THIS project folder (.oneie/agent.key, 0600, gitignored) instead of the machine-wide ~/.config/one/key')
71
58
  .option('--ttl-days <n>', 'Key lifetime in days (default 90, max 365)')
72
59
  .action(async (opts) => {
73
60
  const dir = process.cwd();
@@ -130,7 +117,12 @@ export function initCmd() {
130
117
  keyLocation = `${res.keyPath} (0600, ignored via ${res.ignorePath})`;
131
118
  }
132
119
  else {
133
- writeKey(apiKey);
120
+ // The MACHINE key is regKey, not apiKey (text/agent-handover.md § 0). regKey's actor
121
+ // IS the workspace slug, so callerControlsWorkspace (resolvers/_shared.ts:302) and
122
+ // requireGroupOwner (world-receivers.ts:210) pass by identity; apiKey is scoped to a
123
+ // random actor id and fails deep as `forbidden`. The plugin's tools and every CLI
124
+ // command read this one file, so it must hold the key that can act on the workspace.
125
+ writeMachineKey(regKey || apiKey);
134
126
  keyLocation = `${KEY_FILE} (0600)`;
135
127
  }
136
128
  if (opts.writeEnv) {
@@ -31,3 +31,11 @@ export declare function firstExisting(...candidates: string[]): string | null;
31
31
  export declare function readMachineKey(): string;
32
32
  /** Which path the machine-wide key actually came from — for `doctor`, never for auth. */
33
33
  export declare function machineKeyPath(): string | null;
34
+ /**
35
+ * Write the machine-wide key: atomically (temp + rename, so a concurrent reader
36
+ * never sees half a key), 0600, always at the NEW path. The one writer — `onboard`
37
+ * and `init` each carried their own copy pointed at the legacy `~/.config/oneie`,
38
+ * so a key minted by `onboard` sat where only the CLI's read fallback could find it
39
+ * and the MCP server, which reads the same ladder, was one rename away from missing it.
40
+ */
41
+ export declare function writeMachineKey(value: string): void;
@@ -16,9 +16,9 @@
16
16
  * back — `one auth login` rewrites at the new path on its own, and the old file
17
17
  * is theirs to remove.
18
18
  */
19
- import { existsSync, readFileSync } from 'node:fs';
19
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
20
20
  import { homedir } from 'node:os';
21
- import { resolve } from 'node:path';
21
+ import { join, resolve } from 'node:path';
22
22
  /** `~/.config/one` — the current home for CLI state. */
23
23
  export const CONFIG_DIR = resolve(homedir(), '.config', 'one');
24
24
  /**
@@ -75,3 +75,17 @@ export function readMachineKey() {
75
75
  export function machineKeyPath() {
76
76
  return firstExisting(KEY_FILE, LEGACY_KEY_FILE);
77
77
  }
78
+ /**
79
+ * Write the machine-wide key: atomically (temp + rename, so a concurrent reader
80
+ * never sees half a key), 0600, always at the NEW path. The one writer — `onboard`
81
+ * and `init` each carried their own copy pointed at the legacy `~/.config/oneie`,
82
+ * so a key minted by `onboard` sat where only the CLI's read fallback could find it
83
+ * and the MCP server, which reads the same ladder, was one rename away from missing it.
84
+ */
85
+ export function writeMachineKey(value) {
86
+ mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
87
+ const tmp = join(CONFIG_DIR, '.key.tmp');
88
+ writeFileSync(tmp, value, { mode: 0o600 });
89
+ chmodSync(tmp, 0o600);
90
+ renameSync(tmp, KEY_FILE);
91
+ }
@@ -13,21 +13,10 @@
13
13
  * and just reports current lifecycle position.
14
14
  */
15
15
  import { Command } from 'commander';
16
- import { writeFileSync, mkdirSync, renameSync, chmodSync } from 'node:fs';
17
- import { resolve, join } from 'node:path';
18
- import { homedir } from 'node:os';
19
16
  import { mergeEnv, writeEnvLocal } from './env.js';
20
17
  import { askPath } from './lib/api-path.js';
18
+ import { KEY_FILE, readMachineKey, writeMachineKey } from './lib/paths.js';
21
19
  const DEFAULT_API = process.env.ONEIE_BASE_URL ?? process.env.ONE_API_URL ?? 'https://one.ie';
22
- const CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
23
- const KEY_FILE = resolve(CONFIG_DIR, 'key');
24
- function writeKey(value) {
25
- mkdirSync(CONFIG_DIR, { recursive: true });
26
- const tmp = join(CONFIG_DIR, '.key.tmp');
27
- writeFileSync(tmp, value, { mode: 0o600 });
28
- chmodSync(tmp, 0o600);
29
- renameSync(tmp, KEY_FILE);
30
- }
31
20
  async function ask(base, key, receiver, data) {
32
21
  const res = await fetch(askPath(base, receiver), {
33
22
  method: 'POST',
@@ -75,12 +64,19 @@ export function onboardCmd() {
75
64
  .description('Zero-to-live onboarding + a deterministic guide through the agent lifecycle')
76
65
  .option('--name <name>', 'Workspace / agent display name')
77
66
  .option('--api <url>', 'API base URL', DEFAULT_API)
78
- .option('--write-env', 'Also write ONE_API_KEY to .env.local in the current directory', true)
67
+ // Opt-in, never a default: run from Claude Code, the current directory is the
68
+ // user's own project, and a default-on write put a live key into a repo nothing
69
+ // guaranteed was gitignored. Commander cannot negate a `true` default, so there
70
+ // was no way to turn it off either.
71
+ .option('--write-env', 'Also write ONE_API_KEY to .env.local in the current directory')
79
72
  .action(async (opts) => {
80
73
  const dir = process.cwd();
81
74
  const base = opts.api.replace(/\/$/, '');
82
75
  const env = mergeEnv(dir);
83
- let apiKey = env.ONE_API_KEY ?? env.ONEIE_API_KEY ?? '';
76
+ // The machine key counts as "already connected". With .env.local now opt-in,
77
+ // reading only the folder would make every repeat run mint a NEW account on an
78
+ // unauthenticated door rate-limited by IP alone.
79
+ let apiKey = env.ONE_API_KEY ?? env.ONEIE_API_KEY ?? readMachineKey();
84
80
  // regKey is the uid-bound registration key — distinct from apiKey (the
85
81
  // workspace-scoped key `apiKey` resolves to). lifecycle:mine and any
86
82
  // other uid-scoped receiver need THIS key: ctx.ownerSlug from `apiKey`
@@ -107,7 +103,12 @@ export function onboardCmd() {
107
103
  workspace = String(json.workspace);
108
104
  apiKey = json.apiKey;
109
105
  regKey = json.regKey ?? '';
110
- writeKey(apiKey);
106
+ // The MACHINE key is regKey, not apiKey (text/agent-handover.md § 0). regKey's actor
107
+ // IS the workspace slug, so callerControlsWorkspace (resolvers/_shared.ts:302) and
108
+ // requireGroupOwner (world-receivers.ts:210) pass by identity; apiKey is scoped to a
109
+ // random actor id and fails deep as `forbidden`. The plugin's tools and every CLI
110
+ // command read this one file, so it must hold the key that can act on the workspace.
111
+ writeMachineKey(regKey || apiKey);
111
112
  if (opts.writeEnv) {
112
113
  writeEnvLocal(dir, { ONE_API_KEY: apiKey, ONE_API_URL: base, ONE_REG_KEY: regKey, ONE_UID: uid, AGENCY_WSID: workspace });
113
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oneie",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "ONE agent CLI",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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
- });