feat(FN-4917): complete Step 2 — add worktree classification helper

Fusion-Task-Id: FN-4917
Fusion-Task-Lineage: 1422a545-f4b5-4e1f-a347-8be2a4202f45
This commit is contained in:
Fusion (runfusion.ai)
2026-05-17 11:02:03 -07:00
committed by gsxdsm
parent abd4fad929
commit 2cb141a511

View File

@@ -135,29 +135,32 @@ export async function isInsideGitWorkTree(worktreePath: string): Promise<boolean
}
}
export type TaskWorktreeClassificationResult =
| { ok: true }
| { ok: false; classification: "missing" | "incomplete" | "unregistered"; reason: string };
/**
* Language-agnostic liveness gate for task worktrees.
*
* Usable requires: directory exists, `.git` entry exists (file or directory),
* worktree is registered in `git worktree list --porcelain`, and git confirms
* the path is inside a work tree (`git rev-parse --is-inside-work-tree`).
*
* Classification intent:
* - missing: worktree directory does not exist
* - incomplete: directory exists but required git metadata is not complete
* - unregistered: directory/.git exists but not registered as a git worktree
* Language-agnostic liveness/classification gate for task worktrees.
*/
export async function isUsableTaskWorktree(rootDir: string, worktreePath: string): Promise<boolean> {
export async function classifyTaskWorktree(rootDir: string, worktreePath: string): Promise<TaskWorktreeClassificationResult> {
if (!existsSync(worktreePath)) {
return false;
return { ok: false, classification: "missing", reason: "worktree directory does not exist" };
}
if (!hasRequiredWorktreeFiles(worktreePath)) {
return false;
if (!hasRequiredWorktreeFiles(worktreePath) || !await isInsideGitWorkTree(worktreePath)) {
return { ok: false, classification: "incomplete", reason: "missing or invalid .git metadata" };
}
if (!await isRegisteredGitWorktree(rootDir, worktreePath)) {
return false;
return { ok: false, classification: "unregistered", reason: "not registered in git worktree list" };
}
return await isInsideGitWorkTree(worktreePath);
return { ok: true };
}
/**
* Language-agnostic liveness gate for task worktrees.
*/
export async function isUsableTaskWorktree(rootDir: string, worktreePath: string): Promise<boolean> {
const result = await classifyTaskWorktree(rootDir, worktreePath);
return result.ok;
}
export function isInsideWorktreesDir(