@gonzui/claude-task-manager
Version:
Task management extension for Claude Code with archiving and history
135 lines • 5.93 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClaudeExecutor = void 0;
exports.buildRunPrompt = buildRunPrompt;
const fs = __importStar(require("fs-extra"));
const path = __importStar(require("path"));
const child_process_1 = require("child_process");
const chalk_1 = __importDefault(require("chalk"));
const types_1 = require("../types");
/**
* Prompt sent by `claude-task run`. Seeds Claude Code's ephemeral in-session
* todo list from the task file's checkboxes and routes completions back
* through `claude-task done`, so task.md stays the persistent source of truth.
* Exported so tests assert against the same string.
*/
function buildRunPrompt(relativePath) {
return (`Please execute the tasks in @${relativePath} and then exit. Do not enter interactive mode. ` +
'Before starting, mirror the unchecked checkboxes into your in-session todo list. ' +
'As you finish each subtask, run `claude-task done <n>` (numbers follow checkbox order) ' +
'and update the mirrored todo — the task file is the source of truth.');
}
class ClaudeExecutor {
constructor(taskFile) {
this.taskFile = taskFile;
}
async runTask(config, verbose = false, debug = false, editPermission = true, logExecution) {
if (!await fs.pathExists(this.taskFile)) {
throw new types_1.TaskManagerError('No task.md file found. Run "claude-task new" first.', 'NO_TASK_FILE');
}
const startTime = Date.now();
try {
const claudeCommand = config.claudeCommand || 'claude';
console.log(`\n Running task with ${claudeCommand}...`);
const taskPath = path.resolve(this.taskFile);
const relativePath = path.relative(process.cwd(), taskPath);
const prompt = buildRunPrompt(relativePath);
console.log(chalk_1.default.gray(`Task file: ${relativePath}`));
if (debug) {
console.log(chalk_1.default.gray(`Command: ${claudeCommand}`));
console.log(chalk_1.default.gray(`Full path: ${taskPath}`));
console.log(chalk_1.default.gray(`Prompt: ${prompt}`));
}
let result;
try {
result = await this.executeClaude(prompt, claudeCommand, editPermission);
console.log(chalk_1.default.green('\n Claude Code execution completed'));
}
catch (error) {
console.error(chalk_1.default.red('\n Claude Code execution failed'));
throw error;
}
const duration = Date.now() - startTime;
const executionResult = {
success: true,
output: result,
timestamp: new Date().toISOString(),
duration
};
await logExecution(executionResult);
return executionResult;
}
catch (error) {
const duration = Date.now() - startTime;
const executionResult = {
success: false,
output: '',
error: error instanceof Error ? error.message : 'Unknown error',
timestamp: new Date().toISOString(),
duration
};
await logExecution(executionResult);
throw error;
}
}
async executeClaude(prompt, claudeCommand = 'claude', editPermission = true) {
return new Promise((resolve, reject) => {
const args = editPermission
? ['--dangerously-skip-permissions', '--print', prompt]
: ['--print', prompt];
const claudeProcess = (0, child_process_1.spawn)(claudeCommand, args, {
stdio: 'inherit',
shell: false
});
claudeProcess.on('close', (code) => {
if (code === 0) {
resolve('Claude Code execution completed');
}
else {
reject(new types_1.ClaudeExecutionError(`Claude Code failed with exit code ${code}`, code || undefined));
}
});
claudeProcess.on('error', (error) => {
reject(new types_1.ClaudeExecutionError(`Failed to start Claude Code: ${error.message}`));
});
});
}
}
exports.ClaudeExecutor = ClaudeExecutor;
//# sourceMappingURL=ClaudeExecutor.js.map