@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
61 lines • 3.46 kB
JavaScript
;
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.saveCommand = saveCommand;
const checkGitInitialized_1 = require("../utils/git/checkGitInitialized");
const createCommit_1 = require("../utils/git/createCommit");
const getGitInstance_1 = require("../utils/git/getGitInstance");
const isInWorktree_1 = require("../utils/git/isInWorktree");
const pushBranch_1 = require("../utils/git/pushBranch");
const logger_1 = require("../utils/logger");
const getTasks_1 = require("../utils/tasks/getTasks");
function saveCommand(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}`;
// Stage all files except ignored ones
const gitWorktree = (0, getGitInstance_1.getGitInstance)(worktreePath);
yield gitWorktree.add('-A');
yield (0, createCommit_1.createCommit)(`complete task ${task.id} - ${task.name}`, {
prefix: 'feat',
cwd: worktreePath
});
const pushResult = yield (0, pushBranch_1.pushBranch)(branchName, worktreePath);
if (!pushResult.success)
(0, logger_1.log)(`Failed to push changes to remote: ${pushResult.error}`, 'error');
(0, logger_1.log)(`Comitted and pushed task ${task.id} - ${task.name}`, 'success');
});
}
//# sourceMappingURL=saveCommand.js.map