@oneie/cli 4.1.0 → 4.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.
@@ -0,0 +1,77 @@
1
+ /**
2
+ * paths.ts — the ONE place that knows where ONE keeps things on disk.
3
+ *
4
+ * WHY THIS FILE EXISTS. Six modules each carried their own
5
+ * `resolve(homedir(), '.config', 'oneie', 'key')` — `client.ts`, `doctor.ts`,
6
+ * `auth.ts`, `keyfile.ts` and `skill.ts` in three places. Six literals is six
7
+ * chances to change five of them: `login` writes one path, `skill push` reads
8
+ * another, and the user sees "I'm logged in but nothing works", which is the
9
+ * hardest class of bug to recognise because every individual command is correct.
10
+ *
11
+ * THE MIGRATION IS A READ FALLBACK, NOT A MOVE. The directory is now
12
+ * `~/.config/one/`. Anyone who authenticated before this change has a key at
13
+ * `~/.config/oneie/key`, and an upgrade that silently logs them out would look
14
+ * like a broken release. So: writes always go to the new path, reads try the new
15
+ * path and then the old one. Nothing is copied or deleted behind the user's
16
+ * back — `one auth login` rewrites at the new path on its own, and the old file
17
+ * is theirs to remove.
18
+ */
19
+ import { existsSync, readFileSync } from 'node:fs';
20
+ import { homedir } from 'node:os';
21
+ import { resolve } from 'node:path';
22
+ /** `~/.config/one` — the current home for CLI state. */
23
+ export const CONFIG_DIR = resolve(homedir(), '.config', 'one');
24
+ /**
25
+ * `~/.config/oneie` — where everything lived until the rename. READ-ONLY: kept
26
+ * so an existing install keeps working, never written to.
27
+ */
28
+ export const LEGACY_CONFIG_DIR = resolve(homedir(), '.config', 'oneie');
29
+ /** The machine-wide API key. Written here; also read from the legacy path. */
30
+ export const KEY_FILE = resolve(CONFIG_DIR, 'key');
31
+ export const LEGACY_KEY_FILE = resolve(LEGACY_CONFIG_DIR, 'key');
32
+ /**
33
+ * The per-machine binding id used by the folder-key guard (`keyfile.ts`).
34
+ *
35
+ * Kept on the SAME fallback ladder as the key, and for a sharper reason: this
36
+ * value is baked into every `.oneie/agent.json` already on disk. Reading only
37
+ * the new path would mint a fresh id, every existing folder key would compare
38
+ * `machine` mismatched, and they would all go `foreign` at once — a silent
39
+ * mass logout caused by a rename.
40
+ */
41
+ export const MACHINE_ID_FILE = resolve(CONFIG_DIR, 'machine-id');
42
+ export const LEGACY_MACHINE_ID_FILE = resolve(LEGACY_CONFIG_DIR, 'machine-id');
43
+ /**
44
+ * First existing path from `candidates`, or null.
45
+ *
46
+ * Existence, not readability — a caller that needs the contents handles its own
47
+ * errors, and a path that exists but cannot be read is a different problem from
48
+ * one that was never there.
49
+ */
50
+ export function firstExisting(...candidates) {
51
+ for (const p of candidates) {
52
+ try {
53
+ if (existsSync(p))
54
+ return p;
55
+ }
56
+ catch {
57
+ /* unreadable home, permission denied — treat as absent */
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ /** The machine-wide key, new path first, legacy second. Empty string when absent. */
63
+ export function readMachineKey() {
64
+ const file = firstExisting(KEY_FILE, LEGACY_KEY_FILE);
65
+ if (!file)
66
+ return '';
67
+ try {
68
+ return readFileSync(file, 'utf8').trim();
69
+ }
70
+ catch {
71
+ return '';
72
+ }
73
+ }
74
+ /** Which path the machine-wide key actually came from — for `doctor`, never for auth. */
75
+ export function machineKeyPath() {
76
+ return firstExisting(KEY_FILE, LEGACY_KEY_FILE);
77
+ }
@@ -0,0 +1,66 @@
1
+ import type { BoardRes } from '@oneie/sdk/tasks-bulk';
2
+ export type Row = NonNullable<BoardRes['tasks']>[number];
3
+ export type Kind = 'work' | 'approval' | 'all';
4
+ export declare const CLOSED: ReadonlySet<string>;
5
+ export declare function kindOf(r: Row): 'work' | 'approval';
6
+ export declare function filterKind(rows: Row[], kind: Kind): {
7
+ rows: Row[];
8
+ excluded: {
9
+ approval: number;
10
+ work: number;
11
+ };
12
+ };
13
+ export declare function isStaleDone(r: Row): boolean;
14
+ export interface BlockedEntry {
15
+ tid: string;
16
+ name: string;
17
+ priority: number;
18
+ blockers: {
19
+ tid: string;
20
+ name?: string;
21
+ status?: string;
22
+ }[];
23
+ outside: number;
24
+ staleStatus: boolean;
25
+ }
26
+ export interface Move {
27
+ tid: string;
28
+ name: string;
29
+ action: string;
30
+ why: string;
31
+ }
32
+ export interface Digest {
33
+ kind: Kind;
34
+ rows: number;
35
+ excluded: {
36
+ approval: number;
37
+ work: number;
38
+ };
39
+ byStatus: Record<string, number>;
40
+ ready: Row[];
41
+ blocked: BlockedEntry[];
42
+ overdue: Row[];
43
+ unassigned: Row[];
44
+ orphans: Row[];
45
+ noNotes: Row[] | null;
46
+ staleDone: Row[];
47
+ picked: Row[];
48
+ nextMoves: Move[];
49
+ }
50
+ export declare function digest(rows: Row[], opts?: {
51
+ kind?: Kind;
52
+ }): Digest;
53
+ export interface BoardMeta {
54
+ total?: number;
55
+ asOf?: string;
56
+ pages?: number;
57
+ truncated?: {
58
+ rows?: number;
59
+ edges?: boolean;
60
+ tags?: number;
61
+ };
62
+ nextCursor?: string;
63
+ }
64
+ export declare function renderDigest(d: Digest, meta: BoardMeta, opts?: {
65
+ top?: number;
66
+ }): string;
@@ -0,0 +1,200 @@
1
+ export const CLOSED = new Set(['done', 'verified', 'dissolved', 'failed']);
2
+ export function kindOf(r) {
3
+ return r.tags?.includes('approval') ? 'approval' : 'work';
4
+ }
5
+ export function filterKind(rows, kind) {
6
+ if (kind === 'all')
7
+ return { rows, excluded: { approval: 0, work: 0 } };
8
+ let approval = 0;
9
+ let work = 0;
10
+ const out = [];
11
+ for (const r of rows) {
12
+ const k = kindOf(r);
13
+ if (k === kind) {
14
+ out.push(r);
15
+ continue;
16
+ }
17
+ if (k === 'approval')
18
+ approval += 1;
19
+ else
20
+ work += 1;
21
+ }
22
+ return { rows: out, excluded: { approval, work } };
23
+ }
24
+ const STALE_DONE_RE = /^\s*(DONE|SHIPPED|LANDED)\b/i;
25
+ export function isStaleDone(r) {
26
+ if (kindOf(r) === 'approval')
27
+ return false;
28
+ if (CLOSED.has(r.status))
29
+ return false;
30
+ if (!r.notes)
31
+ return false;
32
+ return STALE_DONE_RE.test(r.notes);
33
+ }
34
+ const byPriorityDesc = (a, b) => (b.priority ?? 0) - (a.priority ?? 0);
35
+ export function digest(rows, opts) {
36
+ const kind = opts?.kind ?? 'work';
37
+ // Blocker lookup is built from ALL rows passed in, before the kind filter —
38
+ // an approval row can still be the blocker a work row is waiting on.
39
+ const byId = new Map();
40
+ for (const r of rows)
41
+ byId.set(r.tid, r);
42
+ const { rows: filtered, excluded } = filterKind(rows, kind);
43
+ const byStatus = {};
44
+ for (const r of filtered)
45
+ byStatus[r.status] = (byStatus[r.status] ?? 0) + 1;
46
+ const ready = filtered.filter((r) => r.ready === true).sort(byPriorityDesc);
47
+ const blocked = [];
48
+ for (const r of filtered) {
49
+ const openBlockers = r.openBlockers ?? 0;
50
+ const hasBlockedStatus = r.status === 'blocked';
51
+ if (openBlockers <= 0 && !hasBlockedStatus)
52
+ continue;
53
+ const ids = r.blockedBy ?? [];
54
+ const blockers = [];
55
+ for (const bid of ids) {
56
+ const b = byId.get(bid);
57
+ if (!b)
58
+ continue;
59
+ if (CLOSED.has(b.status))
60
+ continue;
61
+ blockers.push({ tid: b.tid, name: b.name, status: b.status });
62
+ }
63
+ const outside = Math.max(0, openBlockers - blockers.length);
64
+ const staleStatus = hasBlockedStatus && openBlockers === 0;
65
+ blocked.push({
66
+ tid: r.tid,
67
+ name: r.name,
68
+ priority: r.priority,
69
+ blockers,
70
+ outside,
71
+ staleStatus,
72
+ });
73
+ }
74
+ blocked.sort((a, b) => b.priority - a.priority);
75
+ const overdue = filtered.filter((r) => r.overdue === true).sort(byPriorityDesc);
76
+ const unassigned = filtered.filter((r) => !CLOSED.has(r.status) && !r.assignee).sort(byPriorityDesc);
77
+ const orphans = filtered.filter((r) => !CLOSED.has(r.status) && !r.parent).sort(byPriorityDesc);
78
+ const notesLoaded = filtered.some((r) => 'notes' in r);
79
+ const noNotes = notesLoaded ? filtered.filter((r) => !r.notes) : null;
80
+ const staleDone = filtered.filter(isStaleDone).sort(byPriorityDesc);
81
+ const picked = filtered.filter((r) => r.status === 'picked').sort(byPriorityDesc);
82
+ const nextMoves = [];
83
+ const used = new Set();
84
+ const push = (r, action, why) => {
85
+ if (nextMoves.length >= 5 || used.has(r.tid))
86
+ return;
87
+ used.add(r.tid);
88
+ nextMoves.push({ tid: r.tid, name: r.name, action, why });
89
+ };
90
+ for (const r of staleDone) {
91
+ if (nextMoves.length >= 5)
92
+ break;
93
+ push(r, 'close', `notes say DONE but status is ${r.status}`);
94
+ }
95
+ for (const b of blocked) {
96
+ if (nextMoves.length >= 5)
97
+ break;
98
+ if (!b.staleStatus)
99
+ continue;
100
+ push(b, 'reopen', 'status blocked, no open blocker');
101
+ }
102
+ for (const r of ready) {
103
+ if (nextMoves.length >= 5)
104
+ break;
105
+ if (r.assignee)
106
+ continue;
107
+ push(r, 'assign', 'ready and unowned');
108
+ }
109
+ for (const r of ready) {
110
+ if (nextMoves.length >= 5)
111
+ break;
112
+ if (!r.assignee)
113
+ continue;
114
+ push(r, 'launch', `ready, owned by @${r.assignee}`);
115
+ }
116
+ for (const r of overdue) {
117
+ if (nextMoves.length >= 5)
118
+ break;
119
+ if (CLOSED.has(r.status))
120
+ continue;
121
+ push(r, 'reschedule', 'overdue');
122
+ }
123
+ return {
124
+ kind,
125
+ rows: filtered.length,
126
+ excluded,
127
+ byStatus,
128
+ ready,
129
+ blocked,
130
+ overdue,
131
+ unassigned,
132
+ orphans,
133
+ noNotes,
134
+ staleDone,
135
+ picked,
136
+ nextMoves,
137
+ };
138
+ }
139
+ function truncateName(name, max = 60) {
140
+ return name.length > max ? `${name.slice(0, max - 1)}…` : name;
141
+ }
142
+ export function renderDigest(d, meta, opts) {
143
+ const top = opts?.top ?? 5;
144
+ const lines = [];
145
+ lines.push(`${d.rows} ${d.kind} rows of ${meta.total ?? '?'} total · asOf ${meta.asOf ?? '?'}`);
146
+ if (meta.truncated) {
147
+ const t = meta.truncated;
148
+ const parts = [];
149
+ if (t.rows !== undefined)
150
+ parts.push(`at least ${t.rows} rows exist (total is a floor)`);
151
+ if (t.edges)
152
+ parts.push('edges capped (blocked/orphan counts may be wrong)');
153
+ if (t.tags !== undefined)
154
+ parts.push(`${t.tags} rows may be missing tags — do not plan from tags alone`);
155
+ lines.push(`TRUNCATED: ${parts.join('; ')}`);
156
+ }
157
+ if (meta.nextCursor) {
158
+ lines.push('SHORT: more rows exist beyond this read — rerun with --all');
159
+ }
160
+ if (d.excluded.approval > 0) {
161
+ lines.push(`${d.excluded.approval} approvals excluded (parked workflow runs — resolve with tasks_approve / workflow:stop, never by status). --kind all to include.`);
162
+ }
163
+ const statusEntries = Object.entries(d.byStatus).sort((a, b) => b[1] - a[1]);
164
+ lines.push(`status ${statusEntries.map(([k, v]) => `${k}=${v}`).join(' ')}`);
165
+ lines.push(`ready=${d.ready.length} blocked=${d.blocked.length} overdue=${d.overdue.length} unassigned=${d.unassigned.length} orphans=${d.orphans.length} noNotes=${d.noNotes === null ? 'unknown (notes not loaded)' : d.noNotes.length} staleDone=${d.staleDone.length} picked=${d.picked.length}`);
166
+ if (d.ready.length) {
167
+ lines.push(`ready (top ${top})`);
168
+ for (const r of d.ready.slice(0, top)) {
169
+ lines.push(` ${r.tid} p${r.priority} @${r.assignee ?? '-'} ${truncateName(r.name)}`);
170
+ }
171
+ }
172
+ if (d.blocked.length) {
173
+ lines.push(`blocked (top ${top})`);
174
+ for (const b of d.blocked.slice(0, top)) {
175
+ let line = ` ${b.tid} ${truncateName(b.name)}`;
176
+ if (b.blockers.length) {
177
+ const blockerParts = b.blockers.map((bl) => `${bl.tid} (${bl.status ?? '?'})`).join(', ');
178
+ line += ` ← ${blockerParts}`;
179
+ }
180
+ if (b.outside > 0)
181
+ line += ` +${b.outside} outside view`;
182
+ if (b.staleStatus)
183
+ line += ' STALE STATUS';
184
+ lines.push(line);
185
+ }
186
+ }
187
+ if (d.staleDone.length) {
188
+ lines.push(`stale DONE (top ${top})`);
189
+ for (const r of d.staleDone.slice(0, top)) {
190
+ lines.push(` ${r.tid} ${truncateName(r.name)}`);
191
+ }
192
+ }
193
+ if (d.nextMoves.length) {
194
+ lines.push('next moves');
195
+ d.nextMoves.forEach((m, i) => {
196
+ lines.push(` ${i + 1}. ${m.action} ${m.tid} ${truncateName(m.name)} — ${m.why}`);
197
+ });
198
+ }
199
+ return lines.join('\n');
200
+ }
@@ -0,0 +1,78 @@
1
+ import type { BoardRes, BulkEdit } from '@oneie/sdk/tasks-bulk';
2
+ export type Row = NonNullable<BoardRes['tasks']>[number];
3
+ export declare const CLOSED: ReadonlySet<string>;
4
+ export interface Hints {
5
+ model?: string;
6
+ effort?: string;
7
+ touches: string[];
8
+ accept?: string;
9
+ }
10
+ export declare function parseHints(notes?: string): Hints;
11
+ export declare function subtree(rows: Row[], rootTid: string): Row[];
12
+ export interface Implied {
13
+ tid: string;
14
+ waitsFor: string;
15
+ reason: 'containment' | 'touches';
16
+ path?: string;
17
+ }
18
+ export interface PlanResult {
19
+ waves: {
20
+ n: number;
21
+ tids: string[];
22
+ }[];
23
+ criticalPath: {
24
+ hops: number;
25
+ tids: string[];
26
+ };
27
+ cycles: string[][];
28
+ missing: {
29
+ tid: string;
30
+ blockedBy: string;
31
+ }[];
32
+ outside: {
33
+ tid: string;
34
+ open: number;
35
+ }[];
36
+ ownerless: string[];
37
+ implied: Implied[];
38
+ closed: string[];
39
+ }
40
+ export declare function planWaves(rows: Row[]): PlanResult;
41
+ export interface DispatchRow {
42
+ tid: string;
43
+ name: string;
44
+ assignee?: string;
45
+ model?: string;
46
+ effort?: string;
47
+ touches: string[];
48
+ accept?: string;
49
+ }
50
+ export interface Dispatch {
51
+ goal: string;
52
+ asOf?: string;
53
+ truncated?: unknown;
54
+ waves: {
55
+ n: number;
56
+ rows: DispatchRow[];
57
+ }[];
58
+ criticalPath: {
59
+ hops: number;
60
+ tids: string[];
61
+ };
62
+ warnings: string[];
63
+ }
64
+ export declare function toDispatch(res: PlanResult, rows: Row[], meta: {
65
+ goal: string;
66
+ asOf?: string;
67
+ truncated?: unknown;
68
+ }): Dispatch;
69
+ export declare function sequenceEdits(tids: string[]): {
70
+ ok: true;
71
+ edits: BulkEdit[];
72
+ } | {
73
+ ok: false;
74
+ error: string;
75
+ };
76
+ export declare function renderPlan(res: PlanResult, rows: Row[], opts?: {
77
+ goal?: string;
78
+ }): string;