MCPcopy Create free account
hub / github.com/SethGammon/Citadel / main

Function main

hooks_src/worktree-remove.js:28–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26const PROJECT_ROOT = health.PROJECT_ROOT;
27
28function main() {
29 let input = '';
30 process.stdin.setEncoding('utf8');
31 process.stdin.on('data', (chunk) => { input += chunk; });
32 process.stdin.on('end', () => {
33 let event = {};
34 try { event = JSON.parse(input); } catch { /* partial input ok */ }
35
36 const worktreePath = event.worktree_path || event.path || null;
37 const worktreeName = worktreePath ? path.basename(worktreePath) : null;
38 const branchName = event.branch || event.branch_name || null;
39
40 health.increment('worktree-remove', 'count');
41
42 // Skip cleanup for persistent worktrees (campaigns with worktree_status: active).
43 // The campaign file is the source of truth — if the branch maps to an active
44 // persistent campaign, this removal event is spurious (e.g., session end cleanup)
45 // and the worktree should be left intact for the next session.
46 if (branchName && isPersistentWorktree(branchName)) {
47 process.stderr.write(`[worktree-remove] Branch "${branchName}" is a persistent worktree (worktree_status: active). Skipping cleanup.\n`);
48 process.exit(0);
49 return;
50 }
51
52 // Log to telemetry
53 health.logTiming('worktree-remove', 0, {
54 event: 'worktree-remove',
55 worktree: worktreeName,
56 branch: branchName,
57 });
58
59 // Write to audit log
60 health.writeAuditLog('worktree-removed', {
61 worktree: worktreeName,
62 branch: branchName,
63 });
64
65 // Queue merge conflict check for this branch (processed by citadel:merge-review)
66 if (branchName) {
67 queueMergeCheck(branchName, worktreeName);
68 }
69
70 // Clean up scope claims for this worktree
71 cleanupScopeClaims(worktreeName);
72
73 // Update fleet session if this worktree was part of one
74 updateFleetSession(worktreeName, branchName);
75
76 process.exit(0);
77 });
78}
79
80/**
81 * Returns true if the given branch is owned by a persistent campaign

Callers 1

worktree-remove.jsFile · 0.70

Calls 4

isPersistentWorktreeFunction · 0.85
queueMergeCheckFunction · 0.85
cleanupScopeClaimsFunction · 0.85
updateFleetSessionFunction · 0.85

Tested by

no test coverage detected