fix(HAI-002): inline dependency ordering to avoid Vite alias limitation

This commit is contained in:
Dustin Byrne
2026-03-25 18:54:50 -04:00
parent 6e0fe0554d
commit 674826e838

View File

@@ -1,5 +1,4 @@
import type { Task } from "@hai/core";
import { resolveDependencyOrder } from "@hai/core";
export interface WorktreeGroupData {
label: string;
@@ -17,6 +16,36 @@ export function getWorktreeLabel(worktreePath: string): string {
return segments[segments.length - 1] || worktreePath;
}
/**
* Topological sort of tasks by dependency order.
* Mirrors resolveDependencyOrder from @hai/core but inlined to avoid
* build alias issues (Vite aliases @hai/core to types.ts only).
*/
function resolveDependencyOrder(tasks: Task[]): string[] {
const taskMap = new Map(tasks.map((t) => [t.id, t]));
const ordered: string[] = [];
const visited = new Set<string>();
const visiting = new Set<string>();
function visit(id: string): void {
if (visited.has(id)) return;
if (visiting.has(id)) return;
visiting.add(id);
const task = taskMap.get(id);
if (task) {
for (const depId of task.dependencies) {
if (taskMap.has(depId)) visit(depId);
}
}
visiting.delete(id);
visited.add(id);
ordered.push(id);
}
for (const task of tasks) visit(task.id);
return ordered;
}
/**
* Group in-progress tasks by worktree and distribute queued todo tasks
* as visual previews across the worktree groups.