@oneie/cli 5.1.0 → 5.2.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.
@@ -0,0 +1,192 @@
1
+ import { emitKeypressEvents } from 'node:readline';
2
+ import { createInterface } from 'node:readline/promises';
3
+ import { drawPlan, planDelta, planHeader, shortName, withOverrides } from './plan-draw.js';
4
+ const ESC = '\x1b[';
5
+ const PAINT = {
6
+ selected: `${ESC}7m`, // inverse
7
+ critical: `${ESC}33m`, // yellow
8
+ ready: `${ESC}32m`, // green
9
+ changed: `${ESC}1;35m`, // bold magenta
10
+ dim: `${ESC}2m`,
11
+ };
12
+ const RESET = `${ESC}0m`;
13
+ const HELP = '←→↑↓ select · c claim · d done · o reopen · m comment · enter notes · r refresh · q quit';
14
+ export async function runLivePlan(o) {
15
+ const input = o.input ?? process.stdin;
16
+ const out = o.output ?? process.stdout;
17
+ let data = await o.load();
18
+ const overrides = new Map();
19
+ let changed = new Set();
20
+ let message = 'Pick a row with the arrow keys, then act on it.';
21
+ let showNotes = false;
22
+ let selected;
23
+ let busy = false;
24
+ const view = () => withOverrides(data.rows, overrides);
25
+ const render = () => {
26
+ const rows = view();
27
+ const world = data.world; // the snapshot as read — never the local overrides
28
+ const d = drawPlan(rows, { selected, changed, world });
29
+ if (!selected || !d.boxes.has(selected))
30
+ selected = d.columns.flat()[0];
31
+ const d2 = selected ? drawPlan(rows, { selected, changed, world }) : d;
32
+ const cols = out.columns || 120;
33
+ const height = (out.rows || 40) - 9;
34
+ const sel = selected ? d2.boxes.get(selected) : undefined;
35
+ // Scroll so the selected box is always on screen.
36
+ const x0 = sel ? Math.max(0, Math.min(sel.x - 4, sel.x + 30 - cols)) : 0;
37
+ const y0 = sel ? Math.max(0, sel.y + 6 - height) : 0;
38
+ const body = [];
39
+ for (let y = y0; y < Math.min(d2.lines.length, y0 + height); y++) {
40
+ const line = d2.lines[y] ?? '';
41
+ let s = '';
42
+ let cur;
43
+ for (let x = x0; x < Math.min(line.length, x0 + cols); x++) {
44
+ const st = d2.styles.get(`${x},${y}`);
45
+ if (st !== cur) {
46
+ s += RESET + (st ? PAINT[st] : '');
47
+ cur = st;
48
+ }
49
+ s += line[x];
50
+ }
51
+ body.push(s + RESET);
52
+ }
53
+ const r = selected ? rows.find((t) => t.tid === selected) : undefined;
54
+ const header = planHeader(rows, d2.plan, { title: o.title, asOf: data.asOf, world });
55
+ const detail = r ? [`${ESC}1m${r.name}${RESET}`, `${r.tid} · ${r.status}${r.assignee ? ' · @' + r.assignee : ''} · priority ${r.priority ?? 0}`] : [''];
56
+ const notes = showNotes && r ? (String(r.notes ?? '(no notes)')).split('\n').slice(0, 12) : [];
57
+ out.write(`${ESC}2J${ESC}H`);
58
+ out.write([...header, '', ...body, '', ...detail, ...notes, '', `${ESC}1m${message}${RESET}`, `${ESC}2m${HELP}${RESET}`].join('\n') + '\n');
59
+ };
60
+ const move = (dx, dy) => {
61
+ const rows = view();
62
+ const d = drawPlan(rows, { world: data.world });
63
+ const here = selected ? d.boxes.get(selected) : undefined;
64
+ if (!here) {
65
+ selected = d.columns.flat()[0];
66
+ return;
67
+ }
68
+ const col = Math.max(0, Math.min(d.columns.length - 1, here.col + dx));
69
+ const list = d.columns[col] ?? [];
70
+ const idx = dx !== 0 ? Math.min(here.idx, list.length - 1) : Math.max(0, Math.min(list.length - 1, here.idx + dy));
71
+ selected = list[idx] ?? selected;
72
+ };
73
+ const doAct = async (label, receiver, extra, nextStatus) => {
74
+ if (!selected || busy)
75
+ return;
76
+ const tid = selected;
77
+ const before = view();
78
+ busy = true;
79
+ message = `${label} ${shortName(before.find((r) => r.tid === tid))} …`;
80
+ render();
81
+ try {
82
+ const res = await o.act(receiver, { tid, ...(o.workspace ? { workspace: o.workspace } : {}), ...extra });
83
+ if (!res.ok) {
84
+ message = `✗ ${label} refused: ${res.error ?? 'unknown'}${res.detail ? ' — ' + res.detail : ''} (nothing changed)`;
85
+ changed = new Set();
86
+ return;
87
+ }
88
+ if (nextStatus)
89
+ overrides.set(tid, nextStatus);
90
+ const after = view();
91
+ const delta = planDelta(before, after, data.world);
92
+ changed = new Set([tid, ...delta.nowReady]);
93
+ const name = (t) => shortName(after.find((r) => r.tid === t));
94
+ const parts = [`✓ ${label} ${name(tid)}`];
95
+ if (delta.nowReady.length)
96
+ parts.push(`now ready: ${delta.nowReady.map(name).join(', ')}`);
97
+ if (delta.critBefore.join() !== delta.critAfter.join()) {
98
+ parts.push(`critical path ${delta.critBefore.length} → ${delta.critAfter.length} steps`);
99
+ }
100
+ parts.push('(from the receipt; the board snapshot catches up within 60s — r to re-read)');
101
+ message = parts.join(' · ');
102
+ }
103
+ catch (e) {
104
+ message = `✗ ${label} failed: ${e.message} (did not land — nothing changed)`;
105
+ }
106
+ finally {
107
+ busy = false;
108
+ }
109
+ };
110
+ const ask = async (prompt) => {
111
+ input.setRawMode?.(false);
112
+ const rl = createInterface({ input, output: out });
113
+ const answer = await rl.question(prompt);
114
+ rl.close();
115
+ input.setRawMode?.(true);
116
+ return answer.trim();
117
+ };
118
+ emitKeypressEvents(input);
119
+ input.setRawMode?.(true);
120
+ input.resume();
121
+ out.write(`${ESC}?25l`); // hide cursor
122
+ render();
123
+ await new Promise((resolve) => {
124
+ const quit = () => {
125
+ input.setRawMode?.(false);
126
+ input.pause();
127
+ input.removeListener('keypress', onKey);
128
+ out.write(`${ESC}?25h\n`);
129
+ resolve();
130
+ };
131
+ const onKey = async (_s, key) => {
132
+ if (busy)
133
+ return;
134
+ if (key.ctrl && key.name === 'c')
135
+ return quit();
136
+ switch (key.name) {
137
+ case 'q': return quit();
138
+ case 'left':
139
+ move(-1, 0);
140
+ break;
141
+ case 'right':
142
+ move(1, 0);
143
+ break;
144
+ case 'up':
145
+ move(0, -1);
146
+ break;
147
+ case 'down':
148
+ move(0, 1);
149
+ break;
150
+ case 'return':
151
+ showNotes = !showNotes;
152
+ break;
153
+ case 'c':
154
+ await doAct('claimed', 'tasks:claim', {}, 'picked');
155
+ break;
156
+ case 'd':
157
+ await doAct('done', 'tasks:status', { status: 'done' }, 'done');
158
+ break;
159
+ case 'o':
160
+ await doAct('reopened', 'tasks:status', { status: 'open' }, 'open');
161
+ break;
162
+ case 'm': {
163
+ const body = await ask('comment (enter to post, empty to cancel): ');
164
+ if (body)
165
+ await doAct('commented on', 'tasks:comment', { body });
166
+ break;
167
+ }
168
+ case 'r': {
169
+ message = 're-reading the board …';
170
+ render();
171
+ try {
172
+ data = await o.load();
173
+ // A receipt stays applied until the snapshot agrees with it.
174
+ for (const [tid, st] of overrides)
175
+ if (data.rows.find((r) => r.tid === tid)?.status === st)
176
+ overrides.delete(tid);
177
+ message = overrides.size
178
+ ? `board re-read · ${overrides.size} change(s) still ahead of the snapshot, shown from their receipts`
179
+ : 'board re-read · the snapshot now matches every change you made';
180
+ }
181
+ catch (e) {
182
+ message = `✗ re-read failed: ${e.message} — still showing the last read`;
183
+ }
184
+ break;
185
+ }
186
+ default: return;
187
+ }
188
+ render();
189
+ };
190
+ input.on('keypress', onKey);
191
+ });
192
+ }
package/dist/src/tasks.js CHANGED
@@ -5,6 +5,11 @@ import { authHeaders, jsonMode, resolveBase } from './lib/client.js';
5
5
  import { askPath } from './lib/api-path.js';
6
6
  import { digest, filterKind, kindOf, renderDigest } from './lib/tasks-digest.js';
7
7
  import { planWaves, renderPlan, sequenceEdits, subtree, toDispatch } from './lib/tasks-graph.js';
8
+ import { drawPlan, planHeader, toLazydraw } from './lib/plan-draw.js';
9
+ import { runLivePlan } from './lib/plan-live.js';
10
+ import { homedir } from 'node:os';
11
+ import { join } from 'node:path';
12
+ import { mkdirSync } from 'node:fs';
8
13
  // `one tasks` — the whole board and the whole edit in one command. Both ride
9
14
  // existing receivers (tasks:board, tasks:bulk) through the ask door; the page walk
10
15
  // and the 25-row chunking live in @oneie/sdk/tasks-bulk so the SDK and the CLI
@@ -119,6 +124,13 @@ function parseKind(v) {
119
124
  async function readAll(api, req) {
120
125
  return boardAllWith(asker(api), { limit: 2000, ...req });
121
126
  }
127
+ function saveDrawing(name, lines) {
128
+ const dir = join(process.env.XDG_DATA_HOME || join(homedir(), '.local', 'share'), 'lazydraw', 'drawings');
129
+ mkdirSync(dir, { recursive: true });
130
+ const file = join(dir, `${name.replace(/[^a-z0-9-]+/gi, '-').toLowerCase()}.ld.json`);
131
+ writeFileSync(file, toLazydraw(lines, name));
132
+ process.stderr.write(`saved — open it with: one draw ${name}\n`);
133
+ }
122
134
  function writeOut(file, data) {
123
135
  if (!file)
124
136
  return;
@@ -342,6 +354,9 @@ export function tasksCmd() {
342
354
  .option('--kind <k>', 'work (default) | approval | all', 'work')
343
355
  .option('--emit <what>', "dispatch = write the hand-off JSON (waves of tid/assignee/model/effort/touches/accept)")
344
356
  .option('--out <file>', 'Write the JSON (plan, or dispatch with --emit) to this file')
357
+ .option('--draw', 'Draw the plan: waves as columns, the critical path as arrows. In a terminal it is LIVE — select a row, act on it (claim · done · reopen · comment), and see what became ready')
358
+ .option('--print', 'With --draw: print the drawing once, never interactive (the default with no TTY, e.g. an agent or a pipe)')
359
+ .option('--save <name>', 'With --draw: also save the drawing for `one draw <name>`')
345
360
  .option('--api <url>', 'API base URL', DEFAULT_API)
346
361
  .option('--json', 'Print the plan as JSON')
347
362
  .action(async (goal, opts, sub) => {
@@ -369,6 +384,43 @@ export function tasksCmd() {
369
384
  }
370
385
  if (res.nextCursor || res.truncated?.rows !== undefined)
371
386
  process.stderr.write('warning the board read was partial — at least these rows; the plan may be missing some\n');
387
+ if (opts.draw) {
388
+ const world = new Map(all.map((r) => [r.tid, r]));
389
+ const title = byGoal ? (all.find((r) => r.tid === goal)?.name ?? goal) : `tag: ${goal}`;
390
+ const live = !opts.print && !jsonMode(sub) && process.stdin.isTTY && process.stdout.isTTY;
391
+ if (!live) {
392
+ const d = drawPlan(rows, { world });
393
+ const text = [...planHeader(rows, d.plan, { title, asOf: res.asOf, world }), '', ...d.lines].join('\n');
394
+ if (opts.save)
395
+ saveDrawing(opts.save, d.lines);
396
+ process.stdout.write(text + '\n');
397
+ return;
398
+ }
399
+ const ask = asker(opts.api);
400
+ let first = true;
401
+ const load = async () => {
402
+ if (first) {
403
+ first = false;
404
+ return { rows, world, asOf: res.asOf };
405
+ }
406
+ const r2 = await readAll(opts.api, { ...(group ? { workspace: group } : {}), ...(opts.tree ? { scope: 'tree' } : {}), include: ['notes'] });
407
+ if (r2.ok === false)
408
+ throw new Error(r2.error ?? 'tasks:board failed');
409
+ const all2 = (r2.tasks ?? []);
410
+ const picked2 = byGoal ? subtree(all2, goal) : all2.filter((r) => r.tags.includes(goal));
411
+ return { rows: filterKind(picked2, kind).rows, world: new Map(all2.map((r) => [r.tid, r])), asOf: r2.asOf };
412
+ };
413
+ await runLivePlan({
414
+ title,
415
+ workspace: group,
416
+ load,
417
+ act: async (receiver, data) => {
418
+ const out = (await ask(receiver, data));
419
+ return { ok: out?.ok !== false && !out?.error, error: out?.error, detail: out?.detail };
420
+ },
421
+ });
422
+ return;
423
+ }
372
424
  const plan = planWaves(rows);
373
425
  const meta = { goal, ...(res.asOf ? { asOf: res.asOf } : {}), ...(res.truncated ? { truncated: res.truncated } : {}) };
374
426
  const payload = opts.emit === 'dispatch' ? toDispatch(plan, rows, meta) : { ...meta, ...plan };
@@ -16,3 +16,5 @@ export declare function walletCmd(): Command;
16
16
  */
17
17
  export declare function addressesOnly(source: unknown): Record<string, string>;
18
18
  export declare function writeKeysFile(filePath: string, contents: string, accepted: boolean): void;
19
+ /** Read a secret from the TTY with echo off. Never argv (world-readable in ps), never env. */
20
+ export declare function promptSecret(prompt: string): Promise<string>;
@@ -416,7 +416,7 @@ function out(cmd, data) {
416
416
  }
417
417
  }
418
418
  /** Read a secret from the TTY with echo off. Never argv (world-readable in ps), never env. */
419
- async function promptSecret(prompt) {
419
+ export async function promptSecret(prompt) {
420
420
  if (!process.stdin.isTTY)
421
421
  throw new Error('a passphrase must be typed at a terminal — refusing to read one from a pipe');
422
422
  const rl = createInterface({ input: process.stdin, output: process.stdout, terminal: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oneie/cli",
3
- "version": "5.1.0",
3
+ "version": "5.2.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": "^0.16.0"
23
+ "@oneie/sdk": "^0.16.2"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@oneie/evals": "^0.2.0",