@oneie/cli 5.2.0 → 5.2.2

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,230 @@
1
+ import { boardAllWith, bulkAllWith, } from '@oneie/sdk/tasks-bulk';
2
+ // ── Constants ──────────────────────────────────────────────────────────
3
+ /** All valid Flow IDs */
4
+ export const FLOWS = ['card', 'page', 'write', 'secure', 'decide', 'operate', 'recon', 'rollup'];
5
+ /** Valid role values (labels and signals) */
6
+ export const ROLES = ['leaf', 'epic', 'operate', 'decision', 'recon', 'settle', 'dupe'];
7
+ /** Valid rung values */
8
+ export const RUNGS = ['trivial', 'contained', 'shaped', 'irreversible'];
9
+ /** Valid family values */
10
+ export const FAMILIES = [
11
+ 'copy', 'doc', 'chain', 'security', 'schema', 'astro-page', 'puck-block',
12
+ 'ts-lib', 'react-component', 'react-hook', 'receiver', 'interface', 'worker',
13
+ 'd1', 'workflow', 'eval', 'test-gate', 'perf',
14
+ ];
15
+ // ── Derivation helpers ─────────────────────────────────────────────────
16
+ /** Compute the FlowId from a FlowRow (exact spec port) */
17
+ export function flowOf(row) {
18
+ const { role, rung, family } = row;
19
+ if (role === 'decision')
20
+ return 'decide';
21
+ if (role === 'operate')
22
+ return 'operate';
23
+ if (role === 'recon')
24
+ return 'recon';
25
+ if (role === 'epic' || role === 'dupe' || role === 'settle')
26
+ return 'rollup';
27
+ if (role !== 'leaf')
28
+ return null;
29
+ if (!rung || !RUNGS.includes(rung))
30
+ return null;
31
+ if (family == null)
32
+ return null;
33
+ if (['copy', 'doc'].includes(family))
34
+ return 'write';
35
+ if (rung === 'irreversible' || ['chain', 'security', 'schema'].includes(family))
36
+ return 'secure';
37
+ if (['astro-page', 'puck-block'].includes(family))
38
+ return 'page';
39
+ if (['ts-lib', 'react-component', 'react-hook', 'receiver', 'interface', 'worker', 'd1', 'workflow', 'eval', 'test-gate', 'perf'].includes(family)) {
40
+ return rung === 'shaped' ? 'secure' : 'card';
41
+ }
42
+ return null;
43
+ }
44
+ /** Format a flow line for notes */
45
+ export function flowNote(flow) {
46
+ return `Flow: ${flow}`;
47
+ }
48
+ /** Check if notes already contain a Flow: line */
49
+ export function hasFlowLine(notes) {
50
+ return /^[ \t]*flow[ \t]*:/im.test(notes ?? '');
51
+ }
52
+ /** Append a flow line to notes (never modify existing text) */
53
+ export function appendFlowNote(notes, flow) {
54
+ const line = flowNote(flow);
55
+ if (!notes)
56
+ return line;
57
+ return notes.endsWith('\n') ? notes + line : notes + '\n' + line;
58
+ }
59
+ /** Read signals from notes, tags, and classified data in priority order */
60
+ export function readSignals(row, classified) {
61
+ const signals = {};
62
+ const fieldSources = {};
63
+ // Helper: try to extract a value from a notes line
64
+ function getNotesValue(label, valid) {
65
+ const re = new RegExp(`^[ \\t]*${label}[ \\t]*:[ \\t]*([a-z0-9-]+)[ \\t\\r]*$`, 'im');
66
+ const m = re.exec(row.notes ?? '');
67
+ if (m) {
68
+ const val = m[1].toLowerCase();
69
+ if (valid.includes(val))
70
+ return val;
71
+ }
72
+ return undefined;
73
+ }
74
+ // Helper: try to extract a value from tags
75
+ function getTagValue(prefix, valid) {
76
+ if (!row.tags)
77
+ return undefined;
78
+ for (const tag of row.tags) {
79
+ const re = new RegExp(`^${prefix}-([a-z0-9-]+)$`, 'i');
80
+ const m = re.exec(tag);
81
+ if (m) {
82
+ const val = m[1].toLowerCase();
83
+ if (valid.includes(val))
84
+ return val;
85
+ }
86
+ }
87
+ return undefined;
88
+ }
89
+ // Role
90
+ const roleFromNotes = getNotesValue('role', ROLES);
91
+ const roleFromTags = getTagValue('role', ROLES);
92
+ const roleFromClassified = classified && ROLES.includes(classified.role ?? '') ? classified.role : undefined;
93
+ const role = roleFromNotes ?? roleFromTags ?? roleFromClassified;
94
+ if (role !== undefined) {
95
+ signals.role = role;
96
+ if (roleFromNotes !== undefined)
97
+ fieldSources['role'] = 'notes';
98
+ else if (roleFromTags !== undefined)
99
+ fieldSources['role'] = 'tags';
100
+ else if (roleFromClassified !== undefined)
101
+ fieldSources['role'] = 'classified';
102
+ }
103
+ // Family
104
+ const familyFromNotes = getNotesValue('family', FAMILIES);
105
+ const familyFromTags = getTagValue('family', FAMILIES);
106
+ const familyFromClassified = classified && FAMILIES.includes(classified.family ?? '') ? classified.family : undefined;
107
+ const family = familyFromNotes ?? familyFromTags ?? familyFromClassified;
108
+ if (family !== undefined) {
109
+ signals.family = family;
110
+ if (familyFromNotes !== undefined)
111
+ fieldSources['family'] = 'notes';
112
+ else if (familyFromTags !== undefined)
113
+ fieldSources['family'] = 'tags';
114
+ else if (familyFromClassified !== undefined)
115
+ fieldSources['family'] = 'classified';
116
+ }
117
+ // Rung
118
+ const rungFromNotes = getNotesValue('rung', RUNGS);
119
+ const rungFromTags = getTagValue('rung', RUNGS);
120
+ const rungFromClassified = classified && RUNGS.includes(classified.rung ?? '') ? classified.rung : undefined;
121
+ const rung = rungFromNotes ?? rungFromTags ?? rungFromClassified;
122
+ if (rung !== undefined) {
123
+ signals.rung = rung;
124
+ if (rungFromNotes !== undefined)
125
+ fieldSources['rung'] = 'notes';
126
+ else if (rungFromTags !== undefined)
127
+ fieldSources['rung'] = 'tags';
128
+ else if (rungFromClassified !== undefined)
129
+ fieldSources['rung'] = 'classified';
130
+ }
131
+ // Build sources list preserving priority order and only those that contributed at least one field
132
+ const sources = [];
133
+ const usedSources = new Set(Object.values(fieldSources));
134
+ if (usedSources.has('notes'))
135
+ sources.push('notes');
136
+ if (usedSources.has('tags'))
137
+ sources.push('tags');
138
+ if (usedSources.has('classified'))
139
+ sources.push('classified');
140
+ return { signals, sources };
141
+ }
142
+ /** Build a plan for applying flow tags to board rows */
143
+ export function planFlowTags(rows, classified = []) {
144
+ const classifiedByTid = new Map();
145
+ for (const c of classified) {
146
+ if (!classifiedByTid.has(c.tid))
147
+ classifiedByTid.set(c.tid, c);
148
+ }
149
+ const seen = new Set();
150
+ const counts = { card: 0, page: 0, write: 0, secure: 0, decide: 0, operate: 0, recon: 0, rollup: 0 };
151
+ const unplaced = [];
152
+ const alreadyTagged = [];
153
+ const mismatches = [];
154
+ const bySource = { notes: 0, tags: 0, classified: 0 };
155
+ const edits = [];
156
+ let placed = 0;
157
+ for (const row of rows) {
158
+ if (seen.has(row.tid))
159
+ continue;
160
+ seen.add(row.tid);
161
+ if (hasFlowLine(row.notes)) {
162
+ alreadyTagged.push(row.tid);
163
+ continue;
164
+ }
165
+ const cls = classifiedByTid.get(row.tid);
166
+ const { signals, sources } = readSignals(row, cls);
167
+ const computed = flowOf(signals);
168
+ // Mismatch? Only when cls.flow is a non-empty string and differs from computed
169
+ if (cls?.flow && cls.flow !== computed) {
170
+ mismatches.push({ tid: row.tid, computed, file: cls.flow });
171
+ // continue removed – fall through to normal placement logic
172
+ }
173
+ if (computed === null) {
174
+ unplaced.push(row.tid);
175
+ continue;
176
+ }
177
+ for (const s of sources)
178
+ bySource[s]++;
179
+ const newNotes = appendFlowNote(row.notes, computed);
180
+ counts[computed]++;
181
+ placed++;
182
+ edits.push({ tid: row.tid, notes: newNotes, addTags: [`flow-${computed}`] });
183
+ }
184
+ return { counts, placed, unplaced, alreadyTagged, mismatches, bySource, edits };
185
+ }
186
+ /** Orchestrate the flow tag operation: plan and optionally apply */
187
+ export async function runFlow(ask, classified, opts) {
188
+ const board = opts.board ??
189
+ (await boardAllWith(ask, {
190
+ ...(opts.workspace ? { workspace: opts.workspace } : {}),
191
+ scope: opts.tree ? 'tree' : undefined,
192
+ status: opts.status ?? 'active',
193
+ include: ['notes'],
194
+ limit: 2000,
195
+ ...(opts.fresh ? { fresh: true } : {}),
196
+ }));
197
+ if (board.ok === false) {
198
+ return { ok: false, dryRun: !opts.apply, error: board.error ?? 'tasks:board failed' };
199
+ }
200
+ const plan = planFlowTags(board.tasks ?? [], classified);
201
+ if (!opts.apply) {
202
+ return { ok: true, dryRun: true, plan, total: board.total, asOf: board.asOf, truncated: board.truncated };
203
+ }
204
+ // Apply refusals
205
+ if (opts.board) {
206
+ return { ok: false, dryRun: false, plan, error: 'apply_needs_live_read' };
207
+ }
208
+ if (board.truncated?.rows !== undefined) {
209
+ return { ok: false, dryRun: false, plan, error: 'apply_refused_truncated' };
210
+ }
211
+ const maxAge = opts.maxAgeSec ?? 120;
212
+ if (!Number.isFinite(maxAge) || maxAge < 0) {
213
+ return { ok: false, dryRun: false, plan, error: 'apply_refused_bad_max_age' };
214
+ }
215
+ const asOf = board.asOf;
216
+ const t = asOf ? Date.parse(asOf) : NaN;
217
+ const age = (opts.now ?? Date.now()) - t;
218
+ if (!Number.isFinite(age) || age > maxAge * 1000) {
219
+ return { ok: false, dryRun: false, plan, error: 'apply_refused_stale' };
220
+ }
221
+ if (plan.edits.length === 0) {
222
+ return { ok: true, dryRun: false, plan, applied: undefined };
223
+ }
224
+ const applied = await bulkAllWith(ask, {
225
+ ...(opts.workspace ? { workspace: opts.workspace } : {}),
226
+ edits: plan.edits,
227
+ });
228
+ const ok = applied.ok !== false && (applied.failed ?? 0) === 0;
229
+ return { ok, dryRun: false, plan, total: board.total, asOf, truncated: board.truncated, applied };
230
+ }
@@ -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>;