import { MemoryDatabase } from '../database/memory-db.js';
import { GOTCHAFramework } from '../gotcha/framework.js';
/**
* ATLAS Process - 5-Step Methodology for Task Execution
*
* A - Analyze: Understand the task and context
* T - Task Breakdown: Decompose into manageable subtasks
* L - Learn: Gather necessary knowledge and resources
* A - Act: Execute the planned actions
* S - Synthesize: Integrate results and learnings
*/
export interface ATLASTask {
id: string;
description: string;
context?: any;
}
export class ATLASProcess {
private db: MemoryDatabase;
private gotcha: GOTCHAFramework;
constructor(db: MemoryDatabase, gotcha: GOTCHAFramework) {
this.db = db;
this.gotcha = gotcha;
}
// Step 1: Analyze
async analyze(task: ATLASTask): Promise<any> {
console.log(`[ATLAS] Step 1 - Analyzing task: ${task.description}`);
const analysis = {
taskId: task.id,
description: task.description,
complexity: this.assessComplexity(task.description),
requirements: this.extractRequirements(task.description),
timestamp: new Date().toISOString()
};
const stepId = this.db.addATLASStep('Analyze', task.id, JSON.stringify(analysis));
this.gotcha.observe(`Task analyzed: ${task.description}`, 'ATLAS');
this.gotcha.think(`Analysis complete for task ${task.id}`, 'ATLAS Analyze step');
this.db.updateATLASStepStatus(stepId, 'completed');
return analysis;
}
// Step 2: Task Breakdown
async taskBreakdown(task: ATLASTask, analysis: any): Promise<string[]> {
console.log(`[ATLAS] Step 2 - Breaking down task: ${task.description}`);
const subtasks = this.decomposeTask(task.description, analysis.complexity);
const breakdown = {
taskId: task.id,
subtasks: subtasks,
estimatedSteps: subtasks.length,
timestamp: new Date().toISOString()
};
const stepId = this.db.addATLASStep('Task Breakdown', task.id, JSON.stringify(breakdown));
this.gotcha.think(`Task decomposed into ${subtasks.length} subtasks`, 'ATLAS Task Breakdown');
this.db.updateATLASStepStatus(stepId, 'completed');
return subtasks;
}
// Step 3: Learn
async learn(task: ATLASTask, subtasks: string[]): Promise<any> {
console.log(`[ATLAS] Step 3 - Learning and gathering knowledge for: ${task.description}`);
const knowledge = {
taskId: task.id,
requiredKnowledge: this.identifyKnowledgeNeeds(subtasks),
resources: this.gatherResources(task.description),
capabilities: this.assessCapabilities(),
timestamp: new Date().toISOString()
};
const stepId = this.db.addATLASStep('Learn', task.id, JSON.stringify(knowledge));
this.gotcha.observe(`Knowledge gathered for task ${task.id}`, 'ATLAS');
this.db.updateATLASStepStatus(stepId, 'completed');
return knowledge;
}
// Step 4: Act
async act(task: ATLASTask, subtasks: string[]): Promise<any[]> {
console.log(`[ATLAS] Step 4 - Acting on task: ${task.description}`);
const results: any[] = [];
for (let i = 0; i < subtasks.length; i++) {
const subtask = subtasks[i];
console.log(`[ATLAS] Executing subtask ${i + 1}/${subtasks.length}: ${subtask}`);
const commandId = this.gotcha.executeCommand(subtask, { taskId: task.id, subtaskIndex: i });
// Simulate action execution
const result = {
subtask: subtask,
status: 'completed',
output: `Executed: ${subtask}`,
timestamp: new Date().toISOString()
};
this.gotcha.updateCommandResult(commandId, JSON.stringify(result), 'completed');
results.push(result);
}
const stepId = this.db.addATLASStep('Act', task.id, JSON.stringify({ results }));
this.db.updateATLASStepStatus(stepId, 'completed');
return results;
}
// Step 5: Synthesize
async synthesize(task: ATLASTask, results: any[]): Promise<any> {
console.log(`[ATLAS] Step 5 - Synthesizing results for: ${task.description}`);
const synthesis = {
taskId: task.id,
totalResults: results.length,
successfulActions: results.filter(r => r.status === 'completed').length,
failedActions: results.filter(r => r.status === 'failed').length,
insights: this.extractInsights(results),
learnings: this.captureLearnings(task, results),
timestamp: new Date().toISOString()
};
const stepId = this.db.addATLASStep('Synthesize', task.id, JSON.stringify(synthesis));
this.gotcha.assess(
`Task ${task.id} completed`,
synthesis.successfulActions / synthesis.totalResults,
synthesis.learnings
);
this.db.updateATLASStepStatus(stepId, 'completed');
return synthesis;
}
// Execute full ATLAS process
async executeTask(task: ATLASTask): Promise<any> {
console.log(`[ATLAS] Starting full ATLAS process for task: ${task.description}`);
// Step 1: Analyze
const analysis = await this.analyze(task);
// Step 2: Task Breakdown
const subtasks = await this.taskBreakdown(task, analysis);
// Step 3: Learn
const knowledge = await this.learn(task, subtasks);
// Step 4: Act
const results = await this.act(task, subtasks);
// Step 5: Synthesize
const synthesis = await this.synthesize(task, results);
return {
task,
analysis,
subtasks,
knowledge,
results,
synthesis,
status: 'completed'
};
}
// Helper methods
private assessComplexity(description: string): string {
const wordCount = description.split(' ').length;
if (wordCount < 10) return 'simple';
if (wordCount < 30) return 'moderate';
return 'complex';
}
private extractRequirements(description: string): string[] {
// Simple requirement extraction based on keywords
const requirements: string[] = [];
if (description.toLowerCase().includes('create')) requirements.push('creation');
if (description.toLowerCase().includes('update')) requirements.push('modification');
if (description.toLowerCase().includes('delete')) requirements.push('deletion');
if (description.toLowerCase().includes('read') || description.toLowerCase().includes('get')) requirements.push('retrieval');
return requirements.length > 0 ? requirements : ['general'];
}
private decomposeTask(description: string, complexity: string): string[] {
// Basic task decomposition
const baseSubtasks = [
`Initialize task: ${description}`,
`Execute core logic for: ${description}`,
`Validate results of: ${description}`,
`Finalize task: ${description}`
];
if (complexity === 'complex') {
baseSubtasks.splice(2, 0, `Perform additional processing for: ${description}`);
}
return baseSubtasks;
}
private identifyKnowledgeNeeds(subtasks: string[]): string[] {
return [
'Task execution patterns',
'Error handling strategies',
'Validation techniques'
];
}
private gatherResources(description: string): string[] {
return [
'Memory database',
'GOTCHA framework',
'Logging system'
];
}
private assessCapabilities(): string[] {
return [
'Task analysis',
'Task decomposition',
'Action execution',
'Result synthesis'
];
}
private extractInsights(results: any[]): string[] {
return [
`Completed ${results.length} subtasks`,
'All actions executed successfully',
'Task flow was efficient'
];
}
private captureLearnings(task: ATLASTask, results: any[]): string {
return `Task ${task.id} completed with ${results.length} steps. Process executed smoothly through all ATLAS phases.`;
}
}