UNPKG

@jjdenhertog/ai-driven-development

Version:

AI-driven development workflow with learning capabilities for Claude

65 lines 3.53 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.openCommand = openCommand; const checkGitInitialized_1 = require("../utils/git/checkGitInitialized"); const ensureWorktree_1 = require("../utils/git/ensureWorktree"); const isInWorktree_1 = require("../utils/git/isInWorktree"); const logger_1 = require("../utils/logger"); const getBranchName_1 = require("../utils/tasks/getBranchName"); const getTasks_1 = require("../utils/tasks/getTasks"); function openCommand(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}`); (0, logger_1.log)(`Found task: ${task.id} - ${task.name}`, 'success'); // Get branch name and create worktree const branchName = (0, getBranchName_1.getBranchName)(task); const worktreeFolder = branchName.split('/').at(-1) || branchName; const worktreePath = `.aidev-${worktreeFolder}`; (0, logger_1.log)(`Setting up worktree for branch '${branchName}' at '${worktreePath}'...`, 'info'); try { yield (0, ensureWorktree_1.ensureWorktree)({ branch: branchName, path: worktreePath, skipSymlink: true, skipClaudeCommands: true }); (0, logger_1.log)(`Worktree created successfully at: ${worktreePath}`, 'success'); (0, logger_1.log)(`You can now navigate to the worktree with: cd ${worktreePath}`, 'info'); } catch (error) { if (error instanceof Error) { throw new Error(`Failed to create worktree: ${error.message}`); } throw error; } }); } //# sourceMappingURL=openCommand.js.map