plan: add archive tag 2

This commit is contained in:
2026-03-19 18:39:26 +05:30
parent aa5832e69d
commit f1b09bf7de
+33 -4
View File
@@ -118,6 +118,8 @@ export interface CloseSessionResult {
cleanupPerformed?: boolean; cleanupPerformed?: boolean;
worktreesRemoved?: string[]; worktreesRemoved?: string[];
branchesDeleted?: string[]; branchesDeleted?: string[];
tagsCreated?: string[];
warnings?: string[];
} }
``` ```
@@ -298,6 +300,8 @@ async function promptUser(question: string): Promise<string> {
export async function closeMultiModel(options: CloseSessionOptions): Promise<CloseSessionResult> { export async function closeMultiModel(options: CloseSessionOptions): Promise<CloseSessionResult> {
const worktreesRemoved: string[] = []; const worktreesRemoved: string[] = [];
const branchesDeleted: string[] = []; const branchesDeleted: string[] = [];
const tagsCreated: string[] = [];
const warnings: string[] = [];
try { try {
// Check if session exists // Check if session exists
@@ -337,8 +341,17 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
worktreesRemoved.push(worktree.path); worktreesRemoved.push(worktree.path);
// Create an archive tag before deleting the branch for safe recovery // Create an archive tag before deleting the branch for safe recovery
const archiveTag = `archive/${worktree.branch}`; const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
await runCommand(["git", "tag", archiveTag, worktree.branch]); const archiveTag = `archive/${worktree.branch}-${timestamp}`;
const tagResult = await runCommand(["git", "tag", archiveTag, worktree.branch]);
if (tagResult.ok) {
tagsCreated.push(archiveTag);
} else {
const warningMsg = `Failed to create tag ${archiveTag} for branch ${worktree.branch}.`;
warnings.push(warningMsg);
console.warn(`Warning: ${warningMsg}`);
}
await runCommand(["git", "branch", "-D", worktree.branch]); await runCommand(["git", "branch", "-D", worktree.branch]);
branchesDeleted.push(worktree.branch); branchesDeleted.push(worktree.branch);
@@ -363,7 +376,9 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
sessionName: options.sessionName, sessionName: options.sessionName,
cleanupPerformed, cleanupPerformed,
worktreesRemoved, worktreesRemoved,
branchesDeleted branchesDeleted,
tagsCreated,
warnings
}; };
} catch (error) { } catch (error) {
return { return {
@@ -371,7 +386,9 @@ export async function closeMultiModel(options: CloseSessionOptions): Promise<Clo
sessionName: options.sessionName, sessionName: options.sessionName,
error: String(error), error: String(error),
worktreesRemoved, worktreesRemoved,
branchesDeleted branchesDeleted,
tagsCreated,
warnings
}; };
} }
} }
@@ -455,6 +472,12 @@ export const closeTool = tool({
let details = ""; let details = "";
if (result.cleanupPerformed) { if (result.cleanupPerformed) {
details += ` Removed ${result.worktreesRemoved?.length || 0} worktrees.`; details += ` Removed ${result.worktreesRemoved?.length || 0} worktrees.`;
if (result.tagsCreated && result.tagsCreated.length > 0) {
details += ` Created backup tags: ${result.tagsCreated.join(", ")}.`;
}
if (result.warnings && result.warnings.length > 0) {
details += ` Warnings: ${result.warnings.join("; ")}.`;
}
} }
return { return {
@@ -553,6 +576,12 @@ program
console.log(`✓ Closed session: ${result.sessionName}`); console.log(`✓ Closed session: ${result.sessionName}`);
if (result.cleanupPerformed) { if (result.cleanupPerformed) {
console.log(` Removed ${result.worktreesRemoved?.length || 0} worktrees`); console.log(` Removed ${result.worktreesRemoved?.length || 0} worktrees`);
if (result.tagsCreated && result.tagsCreated.length > 0) {
console.log(` Created backup tags: ${result.tagsCreated.join(", ")}`);
}
if (result.warnings && result.warnings.length > 0) {
console.log(` Warnings: ${result.warnings.join("; ")}`);
}
if (result.branchesDeleted && result.branchesDeleted.length > 0) { if (result.branchesDeleted && result.branchesDeleted.length > 0) {
console.log(` Deleted ${result.branchesDeleted.length} branches`); console.log(` Deleted ${result.branchesDeleted.length} branches`);
} }