@joshski/dust 0.1.111 → 0.1.112

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,17 @@
1
+ export interface TaskNode {
2
+ slug: string;
3
+ blockedBy: string[];
4
+ lastCommittedAt: string | null;
5
+ }
6
+ export interface OrderedTask<T extends TaskNode> {
7
+ node: T;
8
+ executionOrder: number;
9
+ }
10
+ /**
11
+ * Computes execution order for tasks using topological sort.
12
+ * Dependencies always trump timestamps: a blocked task never appears
13
+ * before its blockers, regardless of commit time.
14
+ * Among unblocked peers, earlier lastCommittedAt values come first;
15
+ * null values sort last.
16
+ */
17
+ export declare function computeExecutionOrder<T extends TaskNode>(nodes: T[]): OrderedTask<T>[];
@@ -0,0 +1,39 @@
1
+ // lib/execution-order.ts
2
+ function computeExecutionOrder(nodes) {
3
+ if (nodes.length === 0)
4
+ return [];
5
+ const sorted = [...nodes].toSorted((a, b) => {
6
+ if (a.lastCommittedAt === null && b.lastCommittedAt === null)
7
+ return 0;
8
+ if (a.lastCommittedAt === null)
9
+ return 1;
10
+ if (b.lastCommittedAt === null)
11
+ return -1;
12
+ return new Date(a.lastCommittedAt).getTime() - new Date(b.lastCommittedAt).getTime();
13
+ });
14
+ const result = [];
15
+ const completed = new Set;
16
+ const nodeMap = new Map(nodes.map((n) => [n.slug, n]));
17
+ while (result.length < nodes.length) {
18
+ const next = sorted.find((node) => {
19
+ if (completed.has(node.slug))
20
+ return false;
21
+ return node.blockedBy.every((slug) => completed.has(slug) || !nodeMap.has(slug));
22
+ });
23
+ if (!next) {
24
+ for (const node of sorted) {
25
+ if (!completed.has(node.slug)) {
26
+ result.push({ node, executionOrder: result.length + 1 });
27
+ completed.add(node.slug);
28
+ }
29
+ }
30
+ break;
31
+ }
32
+ result.push({ node: next, executionOrder: result.length + 1 });
33
+ completed.add(next.slug);
34
+ }
35
+ return result;
36
+ }
37
+ export {
38
+ computeExecutionOrder
39
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joshski/dust",
3
- "version": "0.1.111",
3
+ "version": "0.1.112",
4
4
  "description": "Flow state for AI coding agents",
5
5
  "type": "module",
6
6
  "bin": {
@@ -49,6 +49,10 @@
49
49
  "./core-principles": {
50
50
  "import": "./dist/core-principles.js",
51
51
  "types": "./dist/core-principles.d.ts"
52
+ },
53
+ "./execution-order": {
54
+ "import": "./dist/execution-order.js",
55
+ "types": "./dist/execution-order.d.ts"
52
56
  }
53
57
  },
54
58
  "files": [