@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
84 lines • 4.13 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.getTasks = getTasks;
const fs_extra_1 = require("fs-extra");
const node_path_1 = require("node:path");
const config_1 = require("../../config");
const createCommit_1 = require("../git/createCommit");
const getBranchState_1 = require("../git/getBranchState");
const pullBranch_1 = require("../git/pullBranch");
const pushBranch_1 = require("../git/pushBranch");
const logger_1 = require("../logger");
const loadTaskFromFile_1 = require("./loadTaskFromFile");
function getTasks() {
return __awaiter(this, arguments, void 0, function* (options = {}) {
const { status, refresh = false } = options;
// Sync worktree if refresh is requested
if (refresh)
yield syncStorageData();
// Always use absolute path to worktree tasks directory
const foundTasks = [];
try {
// Check if directory exists before reading
if (!(0, fs_extra_1.existsSync)(config_1.TASKS_DIR)) {
return [];
}
const files = (0, fs_extra_1.readdirSync)(config_1.TASKS_DIR);
for (const file of files) {
if (!file.endsWith('.json'))
continue;
const filePath = (0, node_path_1.join)(config_1.TASKS_DIR, file);
const task = (0, loadTaskFromFile_1.loadTaskFromFile)(filePath);
if (task && (!status || task.status === status))
foundTasks.push(task);
}
}
catch (_a) {
// Directory doesn't exist or other error occurred
}
return foundTasks;
});
}
function syncStorageData() {
return __awaiter(this, void 0, void 0, function* () {
try {
// Check if there are uncommitted changes using the utility
const gitState = yield (0, getBranchState_1.getBranchState)(config_1.STORAGE_PATH);
if (gitState.hasChanges) {
(0, logger_1.log)('Committing changes in storage...', 'info');
// Create commit using the utility
const timestamp = new Date().toISOString();
const commitResult = yield (0, createCommit_1.createCommit)(`Auto-sync tasks: ${timestamp}`, {
all: true,
cwd: config_1.STORAGE_PATH
});
if (!commitResult.success)
(0, logger_1.log)(`Failed to commit: ${commitResult.error}`, 'warn');
// Push local commits using the utility
const pushResult = yield (0, pushBranch_1.pushBranch)(config_1.STORAGE_BRANCH, config_1.STORAGE_PATH);
if (!pushResult.success && pushResult.error && !pushResult.error.includes('up-to-date')) {
(0, logger_1.log)(`Push warning: ${pushResult.error}`, 'info');
}
}
// Pull latest changes using the utility
const pullResult = yield (0, pullBranch_1.pullBranch)(config_1.STORAGE_BRANCH, config_1.STORAGE_PATH);
if (pullResult.success) {
(0, logger_1.log)('Pulled latest task updates', 'success');
}
}
catch (error) {
(0, logger_1.log)(`Failed to sync worktree: ${String(error)}`, 'warn');
// Don't throw - continue with local data
}
});
}
//# sourceMappingURL=getTasks.js.map