abyss-ai
Version:
Autonomous AI coding agent - enhanced OpenCode with autonomous capabilities
220 lines (188 loc) • 5.61 kB
text/typescript
import { z } from "zod"
// Core Agent Types and Interfaces
export enum AgentType {
CODE_ANALYZER = 'code-analyzer',
ERROR_DETECTOR = 'error-detector',
REFACTORING_AGENT = 'refactoring-agent',
DOCUMENTATION_AGENT = 'documentation-agent',
PERFORMANCE_AGENT = 'performance-agent',
SECURITY_AGENT = 'security-agent',
FILE_PROCESSOR = 'file-processor'
}
export enum ReasoningMode {
ULTRATHINKING = 'ultrathinking', // Real-time adaptive processing
ULTRAREASONING = 'ultrareasoning', // Structural/logical validation
HYBRID_REASONING = 'hybrid-reasoning', // Multi-perspective analysis
HYBRID_THINKING = 'hybrid-thinking' // Dynamic, creative problem-solving
}
export const AgentTask = z.object({
id: z.string(),
type: z.string(),
data: z.any(),
context: z.record(z.any()),
reasoningModes: z.array(z.nativeEnum(ReasoningMode)),
priority: z.number().optional().default(1),
timeout: z.number().optional().default(30000), // 30 seconds
})
export type AgentTask = z.infer<typeof AgentTask>
export const AgentResult = z.object({
agentId: z.string(),
agentType: z.nativeEnum(AgentType),
taskId: z.string(),
reasoningMode: z.nativeEnum(ReasoningMode),
result: z.any(),
confidence: z.number().min(0).max(1),
processingTime: z.number(),
metadata: z.record(z.any()).optional(),
errors: z.array(z.string()).optional(),
warnings: z.array(z.string()).optional(),
})
export type AgentResult = z.infer<typeof AgentResult>
export const SharedContext = z.object({
sessionId: z.string(),
projectPath: z.string().optional(),
language: z.string().optional(),
frameworks: z.array(z.string()).optional(),
codeContext: z.string().optional(),
userPreferences: z.record(z.any()).optional(),
previousResults: z.array(AgentResult).optional(),
})
export type SharedContext = z.infer<typeof SharedContext>
// Core Agent Interface
export interface IAgent {
readonly id: string
readonly type: AgentType
readonly reasoningModes: ReasoningMode[]
readonly capabilities: string[]
// Core processing method
process(task: AgentTask): Promise<AgentResult>
// Collaboration with other agents
collaborate(agents: IAgent[], context: SharedContext): Promise<void>
// Health check
isHealthy(): Promise<boolean>
// Cleanup
dispose(): Promise<void>
}
// Base Agent Implementation
export abstract class BaseAgent implements IAgent {
abstract readonly id: string
abstract readonly type: AgentType
abstract readonly reasoningModes: ReasoningMode[]
abstract readonly capabilities: string[]
protected isProcessing = false
protected lastProcessedAt?: Date
abstract process(task: AgentTask): Promise<AgentResult>
async collaborate(agents: IAgent[], context: SharedContext): Promise<void> {
// Default implementation - can be overridden
const collaborationResult = await this.performCollaboration(agents, context)
await this.updateFromCollaboration(collaborationResult)
}
protected abstract performCollaboration(agents: IAgent[], context: SharedContext): Promise<any>
protected abstract updateFromCollaboration(collaborationResult: any): Promise<void>
async isHealthy(): Promise<boolean> {
// Basic health check
return !this.isProcessing || (
this.lastProcessedAt ?
Date.now() - this.lastProcessedAt.getTime() < 60000 : // 1 minute timeout
true
)
}
async dispose(): Promise<void> {
// Cleanup resources
this.isProcessing = false
this.lastProcessedAt = undefined
}
protected startProcessing(): void {
this.isProcessing = true
this.lastProcessedAt = new Date()
}
protected finishProcessing(): void {
this.isProcessing = false
this.lastProcessedAt = new Date()
}
protected createResult(
task: AgentTask,
reasoningMode: ReasoningMode,
result: any,
confidence: number,
processingTime: number,
metadata?: Record<string, any>
): AgentResult {
return {
agentId: this.id,
agentType: this.type,
taskId: task.id,
reasoningMode,
result,
confidence,
processingTime,
metadata,
}
}
}
// Processing Result Types
export interface ProcessingContext {
filePath?: string
language?: string
complexity?: number
analysisDepth?: number
projectContext?: any
}
export interface ProcessingResult {
type: string
result: any
confidence: number
processingTime?: number
adaptations?: any
validationReport?: any
perspectives?: any
conflictResolutions?: any
innovationScore?: number
}
// Error Types
export enum ErrorType {
SYNTAX_ERROR = 'syntax-error',
LOGIC_ERROR = 'logic-error',
PERFORMANCE_ERROR = 'performance-error',
SECURITY_ERROR = 'security-error',
STYLE_ERROR = 'style-error',
RUNTIME_ERROR = 'runtime-error'
}
export interface DetectedError {
id: string
type: ErrorType
severity: 'low' | 'medium' | 'high' | 'critical'
message: string
location: {
line: number
column: number
file?: string
}
context: string
suggestions?: string[]
}
export interface ErrorResolution {
errors: DetectedError[]
resolution: AgentResult
success: boolean
confidence: number
}
export interface ErrorResolutionResult {
resolvedErrors: ErrorResolution[]
failedResolutions: ErrorResolution[]
verificationResults: any
overallSuccess: boolean
}
// File Processing Types
export interface FileChunk {
index: number
content: string
startLine: number
endLine: number
overlap?: string
}
export interface ChunkResult {
chunkIndex: number
result: AgentResult
verification: any
}