autoagent-cli
Version:
Run autonomous AI agents using Claude or Gemini for task execution
161 lines (160 loc) ⢠8.04 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;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerStatusCommand = registerStatusCommand;
const autonomous_agent_1 = require("../../core/autonomous-agent");
const logger_1 = require("../../utils/logger");
function registerStatusCommand(program) {
program
.command('status')
.description('Show current status')
.argument('[issue]', 'Issue name or number to check specific status')
.option('--history', 'Show execution history')
.option('-w, --workspace <path>', 'Workspace directory')
.action(async (issueArg, options) => {
try {
const workspace = options?.workspace ?? process.cwd();
const agent = new autonomous_agent_1.AutonomousAgent({
provider: 'claude',
workspace
});
if (options?.history === true) {
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
const path = await Promise.resolve().then(() => __importStar(require('path')));
const executionsFile = path.join(workspace, '.autoagent', 'executions.json');
try {
const content = await fs.readFile(executionsFile, 'utf-8');
const executions = JSON.parse(content);
logger_1.Logger.info('Recent Executions:\n');
executions.forEach((exec) => {
const statusIcon = exec.status === 'completed' ? 'ā
' :
exec.status === 'failed' ? 'ā' : 'š';
logger_1.Logger.info(` ${statusIcon} ${exec.issue} (${exec.status}) - ${new Date(exec.timestamp).toLocaleString()}`);
});
}
catch {
logger_1.Logger.info('No execution history found');
}
return;
}
if (issueArg !== null && issueArg !== undefined && issueArg.length > 0) {
const fs = await Promise.resolve().then(() => __importStar(require('fs/promises')));
const path = await Promise.resolve().then(() => __importStar(require('path')));
const issuesDir = path.join(workspace, 'issues');
let issueExists = false;
let resolvedIssueKey = issueArg;
try {
const files = await fs.readdir(issuesDir);
if (/^\d+$/.test(issueArg)) {
issueExists = files.some(f => f.match(new RegExp(`^${issueArg}-.*\\.md$`)));
}
else {
const statusFile = path.join(workspace, '.autoagent', 'status.json');
try {
const statusContent = await fs.readFile(statusFile, 'utf-8');
const statusData = JSON.parse(statusContent);
const issueData = statusData[issueArg];
if (issueData?.issueNumber !== undefined && issueData.issueNumber !== null) {
issueExists = files.some(f => f.match(new RegExp(`^${issueData.issueNumber}-.*\\.md$`)));
resolvedIssueKey = issueArg;
}
else {
issueExists = files.some(f => f.includes(issueArg) && f.endsWith('.md'));
}
}
catch {
issueExists = files.some(f => f.includes(issueArg) && f.endsWith('.md'));
}
}
}
catch {
}
if (!issueExists) {
logger_1.Logger.error('Issue not found');
process.exit(1);
}
const statusFile = path.join(workspace, '.autoagent', 'status.json');
let issueStatus = 'pending';
let startedAt;
try {
const statusContent = await fs.readFile(statusFile, 'utf-8');
const statusData = JSON.parse(statusContent);
const issueData = statusData[resolvedIssueKey];
issueStatus = issueData?.status ?? 'pending';
startedAt = issueData?.startedAt;
}
catch {
}
logger_1.Logger.info(`${issueArg}`);
logger_1.Logger.info(`Status: ${issueStatus}`);
if (issueStatus === 'running' && startedAt !== undefined) {
const startTime = new Date(startedAt).getTime();
const now = Date.now();
const elapsed = now - startTime;
const hours = Math.floor(elapsed / (1000 * 60 * 60));
const minutes = Math.floor((elapsed % (1000 * 60 * 60)) / (1000 * 60));
if (hours > 0) {
logger_1.Logger.info(`${hours} hour${hours > 1 ? 's' : ''} ago`);
}
else if (minutes > 0) {
logger_1.Logger.info(`${minutes} minute${minutes > 1 ? 's' : ''} ago`);
}
else {
logger_1.Logger.info('Just started');
}
}
return;
}
const status = await agent.getStatus();
logger_1.Logger.info('\nš Project Status\n');
logger_1.Logger.info(`Total Tasks: ${status.totalTasks}`);
logger_1.Logger.info(`Completed: ${status.completedTasks}`);
logger_1.Logger.info(`Pending: ${status.pendingTasks}`);
if (status.currentTaskId !== null && status.currentTaskId !== undefined) {
logger_1.Logger.info(`\nCurrent Task: ${status.currentTaskId}`);
}
if (status.availableProviders !== undefined && status.availableProviders.length > 0) {
logger_1.Logger.info(`\nā
Available Providers: ${status.availableProviders.join(', ')}`);
}
if (status.rateLimitedProviders !== undefined && status.rateLimitedProviders.length > 0) {
logger_1.Logger.info(`ā±ļø Rate Limited: ${status.rateLimitedProviders.join(', ')}`);
}
}
catch (error) {
logger_1.Logger.error(`Failed: ${error instanceof Error ? error.message : String(error)}`);
process.exit(1);
}
});
}