Files
oh-my-pi/packages/coding-agent/src/commit/agentic/topo-sort.ts
T
can1357 0fe761dc4b build(deps): refactored TypeScript and package configuration across monorepo
- Added tsconfig.publish.json files to all packages with optimized publish-time configuration.
- Updated all package.json scripts with prepublishOnly hooks for correct type checking during publish.
- Added @oh-my-pi/omp-stats path mappings to root tsconfig.json for consistent imports.
- Added WASM generation script for photon module and integrated into install:dev script.
2026-01-23 13:46:06 +01:00

45 lines
1.2 KiB
TypeScript

import type { SplitCommitGroup } from "@oh-my-pi/pi-coding-agent/commit/agentic/state";
export function computeDependencyOrder(groups: SplitCommitGroup[]): number[] | { error: string } {
const total = groups.length;
const inDegree = new Array<number>(total).fill(0);
const edges = Array.from({ length: total }, () => new Set<number>());
for (let index = 0; index < total; index += 1) {
const dependencies = groups[index]?.dependencies ?? [];
for (const dependency of dependencies) {
if (dependency < 0 || dependency >= total) {
return { error: `Invalid dependency index: ${dependency}` };
}
if (!edges[dependency]?.has(index)) {
edges[dependency]?.add(index);
inDegree[index] += 1;
}
}
}
const queue: number[] = [];
for (let index = 0; index < total; index += 1) {
if (inDegree[index] === 0) queue.push(index);
}
const order: number[] = [];
while (queue.length > 0) {
const current = queue.shift();
if (current === undefined) break;
order.push(current);
for (const next of edges[current] ?? []) {
inDegree[next] -= 1;
if (inDegree[next] === 0) {
queue.push(next);
}
}
}
if (order.length !== total) {
return { error: "Circular dependency detected in split commit plan." };
}
return order;
}