oneie 5.0.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.
- package/README.md +44 -0
- package/dist/package.json +2 -2
- package/dist/src/draw.d.ts +18 -0
- package/dist/src/draw.js +156 -0
- package/dist/src/group.js +2 -0
- package/dist/src/index.js +9 -6
- package/dist/src/init.d.ts +1 -1
- package/dist/src/init.js +9 -17
- package/dist/src/join.d.ts +11 -0
- package/dist/src/join.js +292 -0
- package/dist/src/key.d.ts +23 -0
- package/dist/src/key.js +270 -0
- package/dist/src/lib/paths.d.ts +8 -0
- package/dist/src/lib/paths.js +16 -2
- package/dist/src/lib/plan-draw.d.ts +56 -0
- package/dist/src/lib/plan-draw.js +219 -0
- package/dist/src/lib/plan-live.d.ts +20 -0
- package/dist/src/lib/plan-live.js +192 -0
- package/dist/src/onboard.js +16 -15
- package/dist/src/tasks.js +52 -0
- package/dist/src/wallet.d.ts +2 -0
- package/dist/src/wallet.js +1 -1
- package/package.json +2 -2
- package/dist/src/templates/_node/site/one.config.d.ts +0 -2
- package/dist/src/templates/_node/site/one.config.js +0 -22
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type PlanResult, type Row } from './tasks-graph.js';
|
|
2
|
+
export declare const BOX_W = 26;
|
|
3
|
+
export type Style = 'selected' | 'critical' | 'ready' | 'changed' | 'dim';
|
|
4
|
+
export interface Drawn {
|
|
5
|
+
lines: string[];
|
|
6
|
+
/** style per cell, keyed "x,y" — only for cells that carry one */
|
|
7
|
+
styles: Map<string, Style>;
|
|
8
|
+
boxes: Map<string, {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
col: number;
|
|
12
|
+
idx: number;
|
|
13
|
+
}>;
|
|
14
|
+
/** columns[c] = tids in draw order, for arrow-key navigation */
|
|
15
|
+
columns: string[][];
|
|
16
|
+
}
|
|
17
|
+
/** Status after local receipts: a write we just made is the truth about that
|
|
18
|
+
* row, even while the board snapshot (a ≤60s memo) still shows the old state. */
|
|
19
|
+
export declare function withOverrides(rows: Row[], overrides: ReadonlyMap<string, string>): Row[];
|
|
20
|
+
/** Open blockers of a row.
|
|
21
|
+
* - in view: by name, from its CURRENT status (a local receipt counts);
|
|
22
|
+
* - outside the view but in `world` (the board read, as the snapshot saw it): by status;
|
|
23
|
+
* - not returned by the read at all (the read carries ACTIVE rows, so a DONE
|
|
24
|
+
* blocker is simply absent): the snapshot's own `openBlockers` count decides —
|
|
25
|
+
* whatever it counted open beyond the blockers we can see is still open. */
|
|
26
|
+
export declare function openBlockers(r: Row, byTid: ReadonlyMap<string, Row>, world?: ReadonlyMap<string, Row>): {
|
|
27
|
+
names: string[];
|
|
28
|
+
outside: number;
|
|
29
|
+
};
|
|
30
|
+
export declare function isReady(r: Row, byTid: ReadonlyMap<string, Row>, world?: ReadonlyMap<string, Row>): boolean;
|
|
31
|
+
/** A short handle: a `cli-*`-style slug tag when the row carries one, else its name. */
|
|
32
|
+
export declare function shortName(r: Row): string;
|
|
33
|
+
export interface DrawOpts {
|
|
34
|
+
title?: string;
|
|
35
|
+
selected?: string;
|
|
36
|
+
changed?: ReadonlySet<string>;
|
|
37
|
+
/** every row the board read returned — resolves blockers outside the view */
|
|
38
|
+
world?: ReadonlyMap<string, Row>;
|
|
39
|
+
}
|
|
40
|
+
export declare function drawPlan(rows: Row[], opts?: DrawOpts): Drawn & {
|
|
41
|
+
plan: PlanResult;
|
|
42
|
+
};
|
|
43
|
+
/** The one-paragraph header both the print and the live view carry. */
|
|
44
|
+
export declare function planHeader(rows: Row[], plan: PlanResult, opts: {
|
|
45
|
+
title?: string;
|
|
46
|
+
asOf?: string;
|
|
47
|
+
world?: ReadonlyMap<string, Row>;
|
|
48
|
+
}): string[];
|
|
49
|
+
/** What changed between two views of the same plan — the answer to "what happened?" */
|
|
50
|
+
export declare function planDelta(before: Row[], after: Row[], world?: ReadonlyMap<string, Row>): {
|
|
51
|
+
nowReady: string[];
|
|
52
|
+
critBefore: string[];
|
|
53
|
+
critAfter: string[];
|
|
54
|
+
};
|
|
55
|
+
/** lazydraw's file shape, so `one draw <name>` can open and edit the picture. */
|
|
56
|
+
export declare function toLazydraw(lines: string[], name: string): string;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { CLOSED, planWaves } from './tasks-graph.js';
|
|
2
|
+
// A plan, drawn. Pure — rows in, lines out — so the live view, `--draw` for a
|
|
3
|
+
// pipe or an agent, and the tests all render the same picture.
|
|
4
|
+
//
|
|
5
|
+
// The shape was chosen by looking, not by theory (2026-09-25): drawing every
|
|
6
|
+
// dependency as a routed arrow turned 25 edges into a wiring loom nobody could
|
|
7
|
+
// read. So only the CRITICAL PATH is drawn as arrows, on one row across the top,
|
|
8
|
+
// and every other dependency is written as words inside the box ("waits: view").
|
|
9
|
+
// The critical path is the one chain that decides when the plan can finish.
|
|
10
|
+
export const BOX_W = 26;
|
|
11
|
+
const BOX_H = 5;
|
|
12
|
+
const GAP = 6;
|
|
13
|
+
const TOP = 0;
|
|
14
|
+
/** Status after local receipts: a write we just made is the truth about that
|
|
15
|
+
* row, even while the board snapshot (a ≤60s memo) still shows the old state. */
|
|
16
|
+
export function withOverrides(rows, overrides) {
|
|
17
|
+
if (!overrides.size)
|
|
18
|
+
return rows;
|
|
19
|
+
return rows.map((r) => (overrides.has(r.tid) ? { ...r, status: overrides.get(r.tid) } : r));
|
|
20
|
+
}
|
|
21
|
+
/** Open blockers of a row.
|
|
22
|
+
* - in view: by name, from its CURRENT status (a local receipt counts);
|
|
23
|
+
* - outside the view but in `world` (the board read, as the snapshot saw it): by status;
|
|
24
|
+
* - not returned by the read at all (the read carries ACTIVE rows, so a DONE
|
|
25
|
+
* blocker is simply absent): the snapshot's own `openBlockers` count decides —
|
|
26
|
+
* whatever it counted open beyond the blockers we can see is still open. */
|
|
27
|
+
export function openBlockers(r, byTid, world) {
|
|
28
|
+
const ids = r.blockedBy ?? [];
|
|
29
|
+
const names = [];
|
|
30
|
+
let outside = 0;
|
|
31
|
+
let openAtSnapshotSeen = 0;
|
|
32
|
+
for (const b of ids) {
|
|
33
|
+
const snap = world?.get(b);
|
|
34
|
+
if (snap && !CLOSED.has(snap.status))
|
|
35
|
+
openAtSnapshotSeen++;
|
|
36
|
+
const inView = byTid.get(b);
|
|
37
|
+
if (inView) {
|
|
38
|
+
if (!CLOSED.has(inView.status))
|
|
39
|
+
names.push(shortName(inView));
|
|
40
|
+
}
|
|
41
|
+
else if (snap) {
|
|
42
|
+
if (!CLOSED.has(snap.status))
|
|
43
|
+
outside++;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const snapshotOpen = r.openBlockers ?? 0;
|
|
47
|
+
outside += Math.max(0, snapshotOpen - openAtSnapshotSeen);
|
|
48
|
+
return { names, outside };
|
|
49
|
+
}
|
|
50
|
+
export function isReady(r, byTid, world) {
|
|
51
|
+
if (r.status !== 'open')
|
|
52
|
+
return false;
|
|
53
|
+
const ob = openBlockers(r, byTid, world);
|
|
54
|
+
return ob.names.length === 0 && ob.outside === 0;
|
|
55
|
+
}
|
|
56
|
+
/** A short handle: a `cli-*`-style slug tag when the row carries one, else its name. */
|
|
57
|
+
export function shortName(r) {
|
|
58
|
+
const slug = (r.tags ?? []).find((t) => /^[a-z]+-[a-z][a-z0-9-]*$/.test(t) && !/-\d+$/.test(t));
|
|
59
|
+
const base = slug && r.name.length > BOX_W - 4 ? slug : r.name;
|
|
60
|
+
return base.replace(/\s+—.*$/, '').trim();
|
|
61
|
+
}
|
|
62
|
+
function wrap(s, w, lines) {
|
|
63
|
+
const words = s.split(/\s+/);
|
|
64
|
+
const out = [];
|
|
65
|
+
let cur = '';
|
|
66
|
+
for (const word of words) {
|
|
67
|
+
if ((cur + ' ' + word).trim().length > w) {
|
|
68
|
+
out.push(cur.trim());
|
|
69
|
+
cur = word;
|
|
70
|
+
if (out.length === lines)
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
cur += ' ' + word;
|
|
75
|
+
}
|
|
76
|
+
if (out.length < lines && cur.trim())
|
|
77
|
+
out.push(cur.trim());
|
|
78
|
+
if (out.length === lines && words.join(' ').length > out.join(' ').length) {
|
|
79
|
+
out[lines - 1] = out[lines - 1].slice(0, w - 1) + '…';
|
|
80
|
+
}
|
|
81
|
+
return out.map((l) => l.slice(0, w));
|
|
82
|
+
}
|
|
83
|
+
export function drawPlan(rows, opts = {}) {
|
|
84
|
+
const byTid = new Map(rows.map((r) => [r.tid, r]));
|
|
85
|
+
const plan = planWaves(rows);
|
|
86
|
+
const crit = plan.criticalPath.tids;
|
|
87
|
+
const critSet = new Set(crit);
|
|
88
|
+
const G = new Map();
|
|
89
|
+
const styles = new Map();
|
|
90
|
+
const put = (x, y, s, style) => {
|
|
91
|
+
;
|
|
92
|
+
[...s].forEach((c, i) => {
|
|
93
|
+
G.set(`${x + i},${y}`, c);
|
|
94
|
+
if (style)
|
|
95
|
+
styles.set(`${x + i},${y}`, style);
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
// Strip a prefix most rows share ("cli-") — it carries no information in a
|
|
99
|
+
// box 22 characters wide, and it is what cut every "waits …" line short.
|
|
100
|
+
const names = rows.map((r) => shortName(r));
|
|
101
|
+
const pre = (names.find((n) => /^[a-z]+-/.test(n)) ?? '').replace(/^([a-z]+-).*$/, '$1');
|
|
102
|
+
const strip = pre !== '' && names.filter((n) => n.startsWith(pre)).length >= names.length * 0.6;
|
|
103
|
+
const label = (r) => { const n = shortName(r); return strip && n.startsWith(pre) ? n.slice(pre.length) : n; };
|
|
104
|
+
// A row with open subtasks cannot be claimed (tasks:claim's containment gate),
|
|
105
|
+
// so it is never "ready", whatever its own blockers say.
|
|
106
|
+
const openKids = new Map();
|
|
107
|
+
for (const r of rows)
|
|
108
|
+
if (r.parent && !CLOSED.has(r.status))
|
|
109
|
+
openKids.set(r.parent, (openKids.get(r.parent) ?? 0) + 1);
|
|
110
|
+
const boxes = new Map();
|
|
111
|
+
const columns = [];
|
|
112
|
+
plan.waves.forEach((wave, col) => {
|
|
113
|
+
const critHere = wave.tids.find((t) => critSet.has(t));
|
|
114
|
+
const rest = wave.tids
|
|
115
|
+
.filter((t) => t !== critHere)
|
|
116
|
+
.sort((a, b) => {
|
|
117
|
+
const ra = byTid.get(a), rb = byTid.get(b);
|
|
118
|
+
return Number(isReady(rb, byTid, opts.world)) - Number(isReady(ra, byTid, opts.world)) || (rb.priority ?? 0) - (ra.priority ?? 0);
|
|
119
|
+
});
|
|
120
|
+
// Slot 0 of every column is the critical path's lane — empty when this wave
|
|
121
|
+
// has no critical row, so the arrow can pass straight through.
|
|
122
|
+
const order = [critHere ?? null, ...rest];
|
|
123
|
+
columns[col] = order.filter((t) => t !== null);
|
|
124
|
+
order.forEach((tid, idx) => {
|
|
125
|
+
const x = col * (BOX_W + GAP);
|
|
126
|
+
const y = TOP + idx * (BOX_H + 1);
|
|
127
|
+
if (!tid)
|
|
128
|
+
return;
|
|
129
|
+
const r = byTid.get(tid);
|
|
130
|
+
boxes.set(tid, { x, y, col, idx: columns[col].indexOf(tid) });
|
|
131
|
+
const kids = openKids.get(tid) ?? 0;
|
|
132
|
+
const ready = kids === 0 && isReady(r, byTid, opts.world);
|
|
133
|
+
const style = opts.selected === tid ? 'selected'
|
|
134
|
+
: opts.changed?.has(tid) ? 'changed'
|
|
135
|
+
: critSet.has(tid) ? 'critical'
|
|
136
|
+
: ready ? 'ready'
|
|
137
|
+
: 'dim';
|
|
138
|
+
const edge = critSet.has(tid) ? '=' : '-';
|
|
139
|
+
put(x, y, '+' + edge.repeat(BOX_W - 2) + '+', style);
|
|
140
|
+
put(x, y + BOX_H - 1, '+' + edge.repeat(BOX_W - 2) + '+', style);
|
|
141
|
+
for (let k = 1; k < BOX_H - 1; k++) {
|
|
142
|
+
put(x, y + k, '|', style);
|
|
143
|
+
put(x + BOX_W - 1, y + k, '|', style);
|
|
144
|
+
}
|
|
145
|
+
const [l1 = '', l2 = ''] = wrap(label(r), BOX_W - 4, 2);
|
|
146
|
+
put(x + 2, y + 1, l1, style);
|
|
147
|
+
put(x + 2, y + 2, l2, style);
|
|
148
|
+
const ob = openBlockers(r, byTid, opts.world);
|
|
149
|
+
const who = r.assignee ? ` @${r.assignee}` : '';
|
|
150
|
+
const status = r.status === 'picked' ? `picked${who}`
|
|
151
|
+
: ready ? '> ready to start'
|
|
152
|
+
: kids ? `waits ${kids} subtasks`
|
|
153
|
+
: r.status === 'open' ? `waits ${[...ob.names.map((n) => (strip && n.startsWith(pre) ? n.slice(pre.length) : n)), ...(ob.outside ? [`+${ob.outside} outside`] : [])].join(', ')}`
|
|
154
|
+
: r.status;
|
|
155
|
+
put(x + 2, y + 3, status.slice(0, BOX_W - 4), style);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
// The critical path, drawn along lane 0 between consecutive critical boxes.
|
|
159
|
+
for (let i = 1; i < crit.length; i++) {
|
|
160
|
+
const a = boxes.get(crit[i - 1]), b = boxes.get(crit[i]);
|
|
161
|
+
if (!a || !b)
|
|
162
|
+
continue;
|
|
163
|
+
for (let x = a.x + BOX_W; x < b.x - 1; x++) {
|
|
164
|
+
if (!G.has(`${x},2`))
|
|
165
|
+
put(x, 2, '=', 'critical');
|
|
166
|
+
}
|
|
167
|
+
put(b.x - 1, 2, '>', 'critical');
|
|
168
|
+
}
|
|
169
|
+
let maxX = 0, maxY = 0;
|
|
170
|
+
for (const k of G.keys()) {
|
|
171
|
+
const [x, y] = k.split(',').map(Number);
|
|
172
|
+
if (x > maxX)
|
|
173
|
+
maxX = x;
|
|
174
|
+
if (y > maxY)
|
|
175
|
+
maxY = y;
|
|
176
|
+
}
|
|
177
|
+
const lines = [];
|
|
178
|
+
for (let y = 0; y <= maxY; y++) {
|
|
179
|
+
let line = '';
|
|
180
|
+
for (let x = 0; x <= maxX; x++)
|
|
181
|
+
line += G.get(`${x},${y}`) ?? ' ';
|
|
182
|
+
lines.push(line.replace(/\s+$/, ''));
|
|
183
|
+
}
|
|
184
|
+
return { lines, styles, boxes, columns, plan };
|
|
185
|
+
}
|
|
186
|
+
/** The one-paragraph header both the print and the live view carry. */
|
|
187
|
+
export function planHeader(rows, plan, opts) {
|
|
188
|
+
const byTid = new Map(rows.map((r) => [r.tid, r]));
|
|
189
|
+
const open = rows.filter((r) => !CLOSED.has(r.status));
|
|
190
|
+
const parents = new Set(open.map((r) => r.parent).filter(Boolean));
|
|
191
|
+
const ready = open.filter((r) => !parents.has(r.tid) && isReady(r, byTid, opts.world)).length;
|
|
192
|
+
const cp = plan.criticalPath.tids.map((t) => shortName(byTid.get(t)));
|
|
193
|
+
return [
|
|
194
|
+
`${opts.title ?? 'plan'} — ${open.length} open · ${ready} ready to start · ${plan.waves.length} waves${opts.asOf ? ` · board read ${opts.asOf.slice(0, 16)}Z` : ''}`,
|
|
195
|
+
`critical path (${cp.length} steps decide the finish): ${cp.join(' → ') || '(none)'}`,
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
/** What changed between two views of the same plan — the answer to "what happened?" */
|
|
199
|
+
export function planDelta(before, after, world) {
|
|
200
|
+
const bBy = new Map(before.map((r) => [r.tid, r]));
|
|
201
|
+
const aBy = new Map(after.map((r) => [r.tid, r]));
|
|
202
|
+
const nowReady = after
|
|
203
|
+
.filter((r) => isReady(r, aBy, world) && !(bBy.has(r.tid) && isReady(bBy.get(r.tid), bBy, world)))
|
|
204
|
+
.map((r) => r.tid);
|
|
205
|
+
const name = (by) => (t) => shortName(by.get(t));
|
|
206
|
+
return {
|
|
207
|
+
nowReady,
|
|
208
|
+
critBefore: planWaves(before).criticalPath.tids.map(name(bBy)),
|
|
209
|
+
critAfter: planWaves(after).criticalPath.tids.map(name(aBy)),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
/** lazydraw's file shape, so `one draw <name>` can open and edit the picture. */
|
|
213
|
+
export function toLazydraw(lines, name) {
|
|
214
|
+
const cells = [];
|
|
215
|
+
lines.forEach((l, y) => [...l].forEach((c, x) => { if (c !== ' ')
|
|
216
|
+
cells.push([x, y, c]); }));
|
|
217
|
+
const now = new Date().toISOString();
|
|
218
|
+
return JSON.stringify({ version: 1, name, createdAt: now, updatedAt: now, cells }, null, 2) + '\n';
|
|
219
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Row } from './tasks-graph.js';
|
|
2
|
+
export interface LiveData {
|
|
3
|
+
rows: Row[];
|
|
4
|
+
world: Map<string, Row>;
|
|
5
|
+
asOf?: string;
|
|
6
|
+
}
|
|
7
|
+
export type Act = (receiver: string, data: Record<string, unknown>) => Promise<{
|
|
8
|
+
ok: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
detail?: string;
|
|
11
|
+
}>;
|
|
12
|
+
export interface LiveOpts {
|
|
13
|
+
title: string;
|
|
14
|
+
load: () => Promise<LiveData>;
|
|
15
|
+
act: Act;
|
|
16
|
+
workspace?: string;
|
|
17
|
+
input?: NodeJS.ReadStream;
|
|
18
|
+
output?: NodeJS.WriteStream;
|
|
19
|
+
}
|
|
20
|
+
export declare function runLivePlan(o: LiveOpts): Promise<void>;
|
|
@@ -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/onboard.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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/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 };
|
package/dist/src/wallet.d.ts
CHANGED
|
@@ -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>;
|
package/dist/src/wallet.js
CHANGED
|
@@ -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",
|
|
3
|
-
"version": "5.
|
|
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.
|
|
23
|
+
"@oneie/sdk": "^0.16.2"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@oneie/evals": "^0.2.0",
|