Files

29 lines
1.3 KiB
TypeScript

// lib/reconcile.ts — pure exact active-tool reconciliation (PRD R3 core, AC2).
//
// The reconciliation output is the COMPLETE target state: applying it makes
// the active tool set EXACTLY the manifest's set — no more (an injected
// third-party tool is removed), no less (a manifest tool missing from the
// active set is listed for addition). NG-2 binds this to setActiveTools();
// this module never touches Pi state.
export interface ReconcilePlan {
/** the exact target active set (sorted manifest tools) */
exact: string[];
/** active tools absent from the manifest — must be removed */
toRemove: string[];
/** manifest tools absent from the active set — must be added */
toAdd: string[];
/** true when the active set already equals the manifest set */
unchanged: boolean;
}
export function reconcileActiveTools(manifestTools: string[], activeTools: string[]): ReconcilePlan {
const target = [...new Set(manifestTools)].sort();
const active = [...new Set(activeTools)].sort();
const inManifest = new Set(target);
const inActive = new Set(active);
const toRemove = active.filter((t) => !inManifest.has(t));
const toAdd = target.filter((t) => !inActive.has(t));
return { exact: target, toRemove, toAdd, unchanged: toRemove.length === 0 && toAdd.length === 0 };
}