UNPKG

framework

Version:

The (AI) Framework: turnkey, zero-config AI orchestration that wraps a coding-agent CLI (Claude Code) as a black box and takes you from an idea to a running app. Vite for AI.

32 lines 1.75 kB
import { nodeGitRunner } from './project.js'; import { ghPrsForBranch } from './dashboard/gh.js'; /** * Delete a pinned routine branch whose PR is closed or merged, so the next firing proceeds. * * Deliberately conservative on the two unprovable cases: an open PR keeps the branch (that is a * triage genuinely pending), and a branch with no PR history at all keeps it too — that is either * an agent still working toward its handoff or a `gh` that could not answer, and deleting on a * hiccup would discard work. Never throws: a release that could not happen leaves the routine * exactly as jammed as it was, which the next tick retries. */ export async function releaseStalePinnedBranch(cwd, branch, deps = {}) { const git = deps.git ?? nodeGitRunner(); const prs = deps.prs ?? ghPrsForBranch; const local = await git(['show-ref', '--verify', `refs/heads/${branch}`], cwd).then(() => true, () => false); const remote = await git(['ls-remote', '--heads', 'origin', branch], cwd).then(out => out.trim() !== '', () => false); if (!local && !remote) return 'absent'; const history = await prs(cwd, branch).catch(() => []); if (history.some(pr => pr.state === 'OPEN')) return 'pending'; if (history.length === 0) return 'unproven'; if (remote) await git(['push', 'origin', '--delete', branch], cwd).catch(() => undefined); // -D, not -d: a squash merge leaves the branch unmerged in git's eyes. And git refusing because // a worktree still has the branch checked out is the in-flight guard working, not a failure. if (local) await git(['branch', '-D', branch], cwd).catch(() => undefined); return 'released'; } //# sourceMappingURL=stale-branch.js.map