oneie 4.0.3 → 4.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.
Files changed (42) hide show
  1. package/README.md +80 -0
  2. package/dist/package.json +4 -4
  3. package/dist/src/agent.d.ts +73 -0
  4. package/dist/src/agent.js +486 -53
  5. package/dist/src/auth.js +3 -4
  6. package/dist/src/compiler.js +38 -5
  7. package/dist/src/doctor.js +61 -6
  8. package/dist/src/endpoint.d.ts +2 -0
  9. package/dist/src/endpoint.js +250 -0
  10. package/dist/src/eval.js +1 -0
  11. package/dist/src/fn.js +5 -8
  12. package/dist/src/index.js +8 -0
  13. package/dist/src/init.js +33 -3
  14. package/dist/src/lib/agent-env.js +7 -0
  15. package/dist/src/lib/client.js +16 -7
  16. package/dist/src/lib/keyfile.d.ts +130 -0
  17. package/dist/src/lib/keyfile.js +381 -0
  18. package/dist/src/lib/paths.d.ts +33 -0
  19. package/dist/src/lib/paths.js +77 -0
  20. package/dist/src/lib/shop-init.d.ts +62 -0
  21. package/dist/src/lib/shop-init.js +63 -0
  22. package/dist/src/lib/tasks-digest.d.ts +66 -0
  23. package/dist/src/lib/tasks-digest.js +200 -0
  24. package/dist/src/lib/tasks-graph.d.ts +78 -0
  25. package/dist/src/lib/tasks-graph.js +425 -0
  26. package/dist/src/lib/vaultfile.d.ts +73 -0
  27. package/dist/src/lib/vaultfile.js +184 -0
  28. package/dist/src/media.d.ts +2 -0
  29. package/dist/src/media.js +256 -0
  30. package/dist/src/plugin.js +10 -1
  31. package/dist/src/shop.d.ts +10 -0
  32. package/dist/src/shop.js +73 -0
  33. package/dist/src/skill.js +128 -12
  34. package/dist/src/tasks.d.ts +2 -0
  35. package/dist/src/tasks.js +424 -0
  36. package/dist/src/templates.js +8 -0
  37. package/dist/src/wallet.d.ts +9 -0
  38. package/dist/src/wallet.js +259 -1
  39. package/dist/src/workflow.js +54 -3
  40. package/package.json +4 -4
  41. package/dist/src/templates/_node/site/one.config.d.ts +0 -2
  42. package/dist/src/templates/_node/site/one.config.js +0 -22
@@ -0,0 +1,62 @@
1
+ /**
2
+ * `one shop init` — the terminal half of the shop pack.
3
+ *
4
+ * Pure on purpose: every round trip arrives through `deps.ask`, so the whole
5
+ * command is exercised without a network and without a key. `src/shop.ts` is
6
+ * the commander wiring and holds no logic of its own.
7
+ *
8
+ * TWO RECEIVERS, ONE OF WHICH MAY NOT BE THERE YET.
9
+ * `pages:instantiate-shop-pack` ships. `pages:fill-shop-pack` is C9.3 of
10
+ * `text/ecommerce-site-todo.md` and lands in parallel with this — and an
11
+ * unknown receiver DISSOLVES, which answers HTTP 200. So the fill leg is read
12
+ * for its outcome and reported separately: `seeded` and `filled` are two facts,
13
+ * and a shop whose pages exist but carry no facts must not report as either a
14
+ * clean success or a total failure.
15
+ */
16
+ export interface AskEnvelope {
17
+ outcome?: string;
18
+ result?: {
19
+ ok?: boolean;
20
+ slug?: string;
21
+ error?: string;
22
+ pages?: Array<{
23
+ pageSlug?: string;
24
+ slug?: string;
25
+ }>;
26
+ filled?: number;
27
+ };
28
+ }
29
+ export interface ShopInitDeps {
30
+ ask(receiver: string, data: unknown): Promise<AskEnvelope>;
31
+ }
32
+ export interface ShopInitResult {
33
+ ok: boolean;
34
+ workspace: string;
35
+ /** The page slugs the seed reported, first one first. */
36
+ pages: string[];
37
+ /** Was a fill asked for, and did it happen. */
38
+ filled: boolean;
39
+ fillRequested: boolean;
40
+ error?: string;
41
+ fillError?: string;
42
+ }
43
+ /** One reading of an `/api/ask` answer. A dissolve and a refusal both arrive as 200. */
44
+ export declare function readEnvelope(env: AskEnvelope, receiver: string): {
45
+ ok: true;
46
+ result: NonNullable<AskEnvelope['result']>;
47
+ } | {
48
+ ok: false;
49
+ error: string;
50
+ };
51
+ /** Parse a facts file. A file that is not an object is refused by name, never coerced. */
52
+ export declare function parseFacts(raw: string): {
53
+ ok: true;
54
+ facts: Record<string, unknown>;
55
+ } | {
56
+ ok: false;
57
+ error: string;
58
+ };
59
+ export declare function shopInit(deps: ShopInitDeps, opts: {
60
+ workspace: string;
61
+ facts?: Record<string, unknown>;
62
+ }): Promise<ShopInitResult>;
@@ -0,0 +1,63 @@
1
+ /**
2
+ * `one shop init` — the terminal half of the shop pack.
3
+ *
4
+ * Pure on purpose: every round trip arrives through `deps.ask`, so the whole
5
+ * command is exercised without a network and without a key. `src/shop.ts` is
6
+ * the commander wiring and holds no logic of its own.
7
+ *
8
+ * TWO RECEIVERS, ONE OF WHICH MAY NOT BE THERE YET.
9
+ * `pages:instantiate-shop-pack` ships. `pages:fill-shop-pack` is C9.3 of
10
+ * `text/ecommerce-site-todo.md` and lands in parallel with this — and an
11
+ * unknown receiver DISSOLVES, which answers HTTP 200. So the fill leg is read
12
+ * for its outcome and reported separately: `seeded` and `filled` are two facts,
13
+ * and a shop whose pages exist but carry no facts must not report as either a
14
+ * clean success or a total failure.
15
+ */
16
+ /** One reading of an `/api/ask` answer. A dissolve and a refusal both arrive as 200. */
17
+ export function readEnvelope(env, receiver) {
18
+ if (env.outcome && env.outcome !== 'result')
19
+ return { ok: false, error: `${receiver} ${env.outcome}` };
20
+ const result = env.result;
21
+ if (!result?.ok)
22
+ return { ok: false, error: result?.error ?? `${receiver} returned no result` };
23
+ return { ok: true, result };
24
+ }
25
+ /** Parse a facts file. A file that is not an object is refused by name, never coerced. */
26
+ export function parseFacts(raw) {
27
+ let parsed;
28
+ try {
29
+ parsed = JSON.parse(raw);
30
+ }
31
+ catch (e) {
32
+ return { ok: false, error: `facts file is not valid JSON: ${e.message}` };
33
+ }
34
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
35
+ return { ok: false, error: 'facts file must be a JSON object of ShopBusinessFacts' };
36
+ }
37
+ return { ok: true, facts: parsed };
38
+ }
39
+ export async function shopInit(deps, opts) {
40
+ const fillRequested = opts.facts !== undefined;
41
+ const base = { ok: false, workspace: opts.workspace, pages: [], filled: false, fillRequested };
42
+ if (!opts.workspace)
43
+ return { ...base, error: 'no workspace — pass --workspace <slug>' };
44
+ const seedEnv = await deps.ask('pages:instantiate-shop-pack', { slug: opts.workspace });
45
+ const seed = readEnvelope(seedEnv, 'pages:instantiate-shop-pack');
46
+ if (!seed.ok)
47
+ return { ...base, error: seed.error };
48
+ // Today the receiver answers with ONE page; C9.1 answers with the whole pack.
49
+ // Read both rather than making this command wait on that cycle.
50
+ const listed = Array.isArray(seed.result.pages) ? seed.result.pages : [];
51
+ const pages = listed.map(p => p.slug).filter((s) => typeof s === 'string' && s.length > 0);
52
+ if (!pages.length && seed.result.slug)
53
+ pages.push(seed.result.slug);
54
+ if (!pages.length)
55
+ return { ...base, error: 'the pack seeded no pages' };
56
+ if (!fillRequested)
57
+ return { ...base, ok: true, pages };
58
+ const fillEnv = await deps.ask('pages:fill-shop-pack', { slug: opts.workspace, facts: opts.facts });
59
+ const fill = readEnvelope(fillEnv, 'pages:fill-shop-pack');
60
+ if (!fill.ok)
61
+ return { ...base, ok: true, pages, fillError: fill.error };
62
+ return { ...base, ok: true, pages, filled: true };
63
+ }
@@ -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;