UNPKG

@jjdenhertog/ai-driven-development

Version:

AI-driven development workflow with learning capabilities for Claude

59 lines 3.21 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.closeCommand = closeCommand; const fs_extra_1 = require("fs-extra"); const checkGitInitialized_1 = require("../utils/git/checkGitInitialized"); const getGitInstance_1 = require("../utils/git/getGitInstance"); const isInWorktree_1 = require("../utils/git/isInWorktree"); const logger_1 = require("../utils/logger"); const getTasks_1 = require("../utils/tasks/getTasks"); function closeCommand(options) { return __awaiter(this, void 0, void 0, function* () { const { taskId } = options; // Ensure git auth if (!(yield (0, checkGitInitialized_1.checkGitInitialized)())) throw new Error('Git is not initialized. Please run `git init` in the root of the repository.'); // Check if we are in a worktree if (yield (0, isInWorktree_1.isInWorktree)()) throw new Error('This command must be run from the root of the repository.'); // Parse task ID - could be just number, just name, or "number-name" let task = null; // First try exact match by ID const allTasks = yield (0, getTasks_1.getTasks)(); task = allTasks.find(t => { const idMatch = t.id === taskId; const nameMatch = t.name.toLowerCase() === taskId.toLowerCase(); const combinedMatch = `${t.id}-${t.name}`.toLowerCase() === taskId.toLowerCase(); const combinedWithSpaceMatch = `${t.id} ${t.name}`.toLowerCase() === taskId.toLowerCase(); return idMatch || nameMatch || combinedMatch || combinedWithSpaceMatch; }); if (!task) throw new Error(`Task not found: ${taskId}`); // Get branch name and worktree path const branchName = task.branch; if (!branchName) throw new Error(`Task ${task.id} - ${task.name} has no branch`); const worktreeFolder = branchName.split('/').at(-1) || branchName; const worktreePath = `.aidev-${worktreeFolder}`; const git = (0, getGitInstance_1.getGitInstance)(); // Clean up any task-specific output directories (0, logger_1.log)(`Removing worktree...`, 'info'); try { yield git.raw(['worktree', 'remove', '--force', worktreePath]); } catch (_error) { (0, fs_extra_1.rmSync)(worktreePath, { force: true, recursive: true }); } yield git.raw(['branch', '-D', branchName, '--force']); }); } //# sourceMappingURL=closeCommand.js.map