autoagent-cli
Version:
Run autonomous AI agents using Claude or Gemini for task execution
221 lines (220 loc) ⢠11.2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskStatusReporter = void 0;
const chalk_1 = __importDefault(require("chalk"));
class TaskStatusReporter {
reportCompletion(result) {
const validation = result.taskCompletion;
const hasToolFailures = result.toolFailures !== undefined && result.toolFailures.length > 0;
if (result.success && (!validation || validation.isComplete)) {
this.reportFullSuccess(result);
}
else if (validation && validation.confidence >= 70 && validation.issues.length === 0) {
this.reportFullSuccess(result);
}
else if (validation && (validation.confidence >= 40 || validation.issues.length <= 2)) {
this.reportPartialCompletion(result);
}
else {
this.reportFailure(result);
}
if (hasToolFailures && result.toolFailures !== undefined) {
this.reportToolFailures(result.toolFailures);
}
if (validation && validation.recommendations.length > 0) {
this.reportRecommendations(validation.recommendations);
}
}
formatDetailedReport(result) {
const lines = [];
lines.push(chalk_1.default.bold('\nš Detailed Execution Report'));
lines.push(chalk_1.default.gray('ā'.repeat(50)));
lines.push(`${chalk_1.default.bold('Task:')} ${result.taskId}${result.taskTitle !== undefined && result.taskTitle !== null && result.taskTitle !== '' ? ` - ${result.taskTitle}` : ''}`);
lines.push(`${chalk_1.default.bold('Duration:')} ${this.formatDuration(result.duration)}`);
if (result.provider !== undefined && result.provider !== null) {
lines.push(`${chalk_1.default.bold('Provider:')} ${result.provider}`);
}
const status = this.determineStatus(result);
const statusColor = status === 'completed' ? chalk_1.default.green :
status === 'partial' ? chalk_1.default.yellow :
chalk_1.default.red;
lines.push(`${chalk_1.default.bold('Status:')} ${statusColor(status)}`);
if (result.filesChanged && result.filesChanged.length > 0) {
lines.push(`\n${chalk_1.default.bold('Files Changed:')}`);
result.filesChanged.forEach(file => {
lines.push(` ⢠${file}`);
});
}
if (result.taskCompletion) {
lines.push(`\n${chalk_1.default.bold('Task Completion Analysis:')}`);
lines.push(` ${chalk_1.default.bold('Completion:')} ${result.taskCompletion.isComplete ? chalk_1.default.green('Yes') : chalk_1.default.red('No')}`);
lines.push(` ${chalk_1.default.bold('Confidence:')} ${this.formatConfidence(result.taskCompletion.confidence)}`);
if (result.taskCompletion.issues.length > 0) {
lines.push(` ${chalk_1.default.bold('Issues Found:')}`);
result.taskCompletion.issues.forEach(issue => {
lines.push(` ⢠${issue}`);
});
}
if (result.taskCompletion.recommendations.length > 0) {
lines.push(` ${chalk_1.default.bold('Recommendations:')}`);
result.taskCompletion.recommendations.forEach(rec => {
lines.push(` ⢠${rec}`);
});
}
}
if (result.toolFailures && result.toolFailures.length > 0) {
lines.push(`\n${chalk_1.default.bold('Tool Failures:')}`);
result.toolFailures.forEach(failure => {
const severityColor = failure.severity === 'error' ? chalk_1.default.red :
failure.severity === 'warning' ? chalk_1.default.yellow :
chalk_1.default.gray;
lines.push(` ${severityColor('ā¢')} ${failure.toolName !== undefined && failure.toolName !== null && failure.toolName !== '' ? failure.toolName : 'Unknown tool'}: ${failure.message}`);
if (failure.type !== 'generic_error') {
lines.push(` Type: ${failure.type}`);
}
});
}
if (result.error !== undefined && result.error !== null && result.error !== '') {
lines.push(`\n${chalk_1.default.bold('Error Details:')}`);
lines.push(chalk_1.default.red(this.wrapText(result.error, 2)));
}
if ((result.error === undefined || result.error === null || result.error === '') && result.output !== undefined && result.output !== null && result.output !== '') {
const preview = result.output.slice(0, 200);
const hasMore = result.output.length > 200;
lines.push(`\n${chalk_1.default.bold('Output Preview:')}`);
lines.push(chalk_1.default.gray(this.wrapText(preview + (hasMore ? '...' : ''), 2)));
}
lines.push(chalk_1.default.gray('ā'.repeat(50)));
return lines.join('\n');
}
reportFullSuccess(result) {
const title = result.taskTitle !== undefined && result.taskTitle !== null && result.taskTitle !== '' ? `: ${result.taskTitle}` : '';
console.log(chalk_1.default.green(`\nā
Successfully completed task ${result.taskId}${title}`));
if (result.filesChanged && result.filesChanged.length > 0) {
console.log(chalk_1.default.gray(` Modified ${result.filesChanged.length} file${result.filesChanged.length === 1 ? '' : 's'}`));
}
console.log(chalk_1.default.gray(` Duration: ${this.formatDuration(result.duration)}`));
}
reportPartialCompletion(result) {
const title = result.taskTitle !== undefined && result.taskTitle !== null && result.taskTitle !== '' ? `: ${result.taskTitle}` : '';
console.log(chalk_1.default.yellow(`\nā ļø Partially completed task ${result.taskId}${title}`));
if (result.taskCompletion) {
console.log(chalk_1.default.yellow(` Task appears incomplete (${result.taskCompletion.confidence}% confidence)`));
if (result.taskCompletion.issues.length > 0) {
console.log(chalk_1.default.yellow(' Issues detected:'));
result.taskCompletion.issues.slice(0, 3).forEach(issue => {
console.log(chalk_1.default.yellow(` ⢠${issue}`));
});
if (result.taskCompletion.issues.length > 3) {
console.log(chalk_1.default.yellow(` ⢠... and ${result.taskCompletion.issues.length - 3} more`));
}
}
}
console.log(chalk_1.default.gray(` Duration: ${this.formatDuration(result.duration)}`));
}
reportFailure(result) {
const title = result.taskTitle !== undefined && result.taskTitle !== null && result.taskTitle !== '' ? `: ${result.taskTitle}` : '';
console.log(chalk_1.default.red(`\nā Failed to complete task ${result.taskId}${title}`));
if (result.error !== undefined && result.error !== null && result.error !== '') {
const errorPreview = result.error.slice(0, 100);
const hasMore = result.error.length > 100;
console.log(chalk_1.default.red(` Error: ${errorPreview}${hasMore ? '...' : ''}`));
}
if (result.taskCompletion && result.taskCompletion.confidence < 40) {
console.log(chalk_1.default.red(` Low completion confidence: ${result.taskCompletion.confidence}%`));
}
console.log(chalk_1.default.gray(` Duration: ${this.formatDuration(result.duration)}`));
}
reportToolFailures(failures) {
const errorCount = failures.filter(f => f.severity === 'error').length;
const warningCount = failures.filter(f => f.severity === 'warning').length;
if (errorCount > 0 || warningCount > 0) {
console.log(chalk_1.default.bold('\nš§ Tool Issues:'));
if (errorCount > 0) {
console.log(chalk_1.default.red(` ${errorCount} error${errorCount === 1 ? '' : 's'} encountered`));
}
if (warningCount > 0) {
console.log(chalk_1.default.yellow(` ${warningCount} warning${warningCount === 1 ? '' : 's'} encountered`));
}
const criticalFailures = failures
.filter(f => f.severity === 'error')
.slice(0, 2);
criticalFailures.forEach(failure => {
console.log(chalk_1.default.red(` ⢠${failure.toolName !== undefined && failure.toolName !== null && failure.toolName !== '' ? failure.toolName : 'Tool'}: ${failure.message}`));
});
}
}
reportRecommendations(recommendations) {
if (recommendations.length === 0) {
return;
}
console.log(chalk_1.default.bold('\nš” Recommendations:'));
recommendations.slice(0, 3).forEach(rec => {
console.log(chalk_1.default.cyan(` ⢠${rec}`));
});
if (recommendations.length > 3) {
console.log(chalk_1.default.cyan(` ⢠... and ${recommendations.length - 3} more suggestions`));
}
}
determineStatus(result) {
if (!result.success) {
return 'failed';
}
const validation = result.taskCompletion;
if (!validation) {
return 'completed';
}
if (validation.isComplete || validation.confidence >= 70) {
return 'completed';
}
else if (validation.confidence >= 40 || validation.issues.length <= 2) {
return 'partial';
}
else {
return 'failed';
}
}
formatDuration(milliseconds) {
if (milliseconds < 1000) {
return `${milliseconds}ms`;
}
else if (milliseconds < 60000) {
return `${(milliseconds / 1000).toFixed(1)}s`;
}
else {
const minutes = Math.floor(milliseconds / 60000);
const seconds = Math.floor((milliseconds % 60000) / 1000);
return `${minutes}m ${seconds}s`;
}
}
formatConfidence(confidence) {
const color = confidence >= 70 ? chalk_1.default.green :
confidence >= 40 ? chalk_1.default.yellow :
chalk_1.default.red;
return color(`${confidence}%`);
}
wrapText(text, indent) {
const maxWidth = 80 - indent;
const words = text.split(' ');
const lines = [];
let currentLine = '';
for (const word of words) {
if (currentLine.length + word.length + 1 > maxWidth) {
lines.push(currentLine);
currentLine = word;
}
else {
currentLine += (currentLine ? ' ' : '') + word;
}
}
if (currentLine) {
lines.push(currentLine);
}
const indentStr = ' '.repeat(indent);
return lines.map(line => indentStr + line).join('\n');
}
}
exports.TaskStatusReporter = TaskStatusReporter;