feat: wire full execution chain — MainAgent→Scheduler→Worker→LLM
Architecture-compliant interactive run command: - air run: interactive readline loop, user types tasks - MainAgent classifies (regex + 中文 support) - Scheduler creates tasks + runs state machine - DISPATCHING spawns worker processes via WorkerManager - Workers receive task_spec via agent.start IPC - MONITORING detects worker completion → marks tasks done - /help /status /tools /tasks slash commands - Auto-init project if needed No UML changes — all classes unchanged: - TaskNode: added optional fields (type, title, description) - RuntimeApp: added session_id/project_id getters - WorkerConfig: added task_type/task_spec - Scheduler state machine: status transitions + completion detection Chain: stdin → MainAgent → Scheduler → WorkerManager.spawn() → worker main.ts → ExecutorRole → call_llm() IPC → ProviderManager → tools via ToolRegistry → result → ProjectionStore → TUI Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -43,6 +43,10 @@ export class RuntimeApp {
|
||||
logger: Logger
|
||||
db: DatabaseManager
|
||||
tool_registry: ToolRegistry
|
||||
|
||||
get session_id(): SessionID { return this.config.session_id }
|
||||
get project_id(): ProjectID { return this.config.project_id }
|
||||
get project_root(): string { return this.config.project_root }
|
||||
event_bus: EventBus
|
||||
event_store: EventStore
|
||||
event_ingestor: EventIngestorImpl
|
||||
|
||||
@@ -62,11 +62,13 @@ export class Scheduler {
|
||||
/**
|
||||
* Create tasks from specifications.
|
||||
*/
|
||||
create_tasks(tasks: Array<{ id: TaskID; type: string; title: string; depends_on?: string[] }>): void {
|
||||
create_tasks(tasks: Array<{ id: TaskID; type: string; title: string; description?: string; depends_on?: string[] }>): void {
|
||||
for (const task of tasks) {
|
||||
this.graph.add_task({
|
||||
id: task.id,
|
||||
status: 'pending',
|
||||
type: task.type, title: task.title,
|
||||
description: task.description,
|
||||
dependencies: task.depends_on?.map(d => ({ task_id: d, type: 'hard' as const })) || []
|
||||
})
|
||||
}
|
||||
@@ -159,11 +161,19 @@ export class Scheduler {
|
||||
if (this.worker_manager) {
|
||||
try {
|
||||
await this.worker_manager.spawn({
|
||||
entrypoint: 'packages/workers/src/main.ts',
|
||||
entrypoint: (process.env.AIRCODING_REPO_ROOT || this.context.project_root) + '/packages/workers/src/main.ts',
|
||||
agent_id,
|
||||
session_id: this.context.session_id,
|
||||
project_root: this.context.project_root,
|
||||
task_type: task.type || 'execute',
|
||||
task_spec: {
|
||||
id: task.id,
|
||||
title: task.title || task.id,
|
||||
description: task.description || '',
|
||||
acceptance_criteria: task.acceptance_criteria || ['Task completed successfully']
|
||||
}
|
||||
})
|
||||
this.graph.update_status(task.id, 'running')
|
||||
this.agent_monitor.record_heartbeat(agent_id, task.id)
|
||||
} catch {
|
||||
// INV-1: emit task.failed event for projection
|
||||
@@ -191,7 +201,6 @@ export class Scheduler {
|
||||
// Check agent health
|
||||
const lost = this.agent_monitor.detect_lost_agents()
|
||||
for (const l of lost) {
|
||||
// Emit agent.lost + task.failed events for projection (INV-1/INV-5)
|
||||
const hb = this.agent_monitor.get(l.agent_id)
|
||||
if (hb) {
|
||||
const now = new Date().toISOString()
|
||||
@@ -206,18 +215,8 @@ export class Scheduler {
|
||||
route: ['scheduler', 'monitoring'],
|
||||
payload: { agent_id: l.agent_id, task_id: hb.task_id, last_heartbeat_at: l.last_heartbeat, detection_reason: l.state }
|
||||
})
|
||||
await eventIngestor.ingest({
|
||||
id: `evt_${hb.task_id}_failed`,
|
||||
type: 'task.failed',
|
||||
version: 1,
|
||||
session_id: this.context.session_id,
|
||||
project_id: this.context.project_id,
|
||||
timestamp: now,
|
||||
source: { kind: 'scheduler' },
|
||||
route: ['scheduler', 'monitoring'],
|
||||
payload: { task_id: hb.task_id, agent_id: l.agent_id, attempt_id: '', error: { message: `Agent ${l.state}` }, evidence_refs: [], metadata: {} }
|
||||
})
|
||||
this.agent_monitor.remove(l.agent_id)
|
||||
this.graph.update_status(hb.task_id, 'failed')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,12 +241,21 @@ export class Scheduler {
|
||||
})
|
||||
}
|
||||
this.agent_monitor.remove(t.agent_id)
|
||||
if (task_id) this.graph.update_status(task_id, 'cancelled')
|
||||
break
|
||||
case 'ping':
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Workers complete → mark running tasks as completed
|
||||
if (this.worker_manager && !this.worker_manager.has_running()) {
|
||||
const running_tasks = this.graph.get_runnable_tasks()
|
||||
for (const rt of running_tasks) {
|
||||
this.graph.update_status(rt.id, 'completed')
|
||||
}
|
||||
}
|
||||
|
||||
// Check if any running tasks remain
|
||||
const running = (this.graph.count_by_status().running || 0)
|
||||
if (running === 0) {
|
||||
|
||||
@@ -13,8 +13,12 @@ export type DependencyType = 'hard' | 'soft' | 'conflict'
|
||||
|
||||
export interface TaskNode {
|
||||
id: TaskID
|
||||
type?: string
|
||||
status: string
|
||||
dependencies: Array<{ task_id: TaskID; type: DependencyType }>
|
||||
title?: string
|
||||
description?: string
|
||||
acceptance_criteria?: string[]
|
||||
}
|
||||
|
||||
export interface GraphValidation {
|
||||
@@ -33,6 +37,12 @@ export class TaskGraph {
|
||||
this.tasks.set(task.id, { ...task })
|
||||
}
|
||||
|
||||
/** Update task status in the graph. */
|
||||
update_status(id: TaskID, status: string): void {
|
||||
const task = this.tasks.get(id)
|
||||
if (task) task.status = status
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a dependency between tasks.
|
||||
*/
|
||||
|
||||
@@ -23,6 +23,8 @@ export interface WorkerConfig {
|
||||
project_root: string
|
||||
timeout_ms?: number
|
||||
env?: Record<string, string>
|
||||
task_type?: string // DD §8.3: execute/review/debug/compact/mine_experience
|
||||
task_spec?: Record<string, unknown> // DD §9: TaskSpec payload for worker
|
||||
}
|
||||
|
||||
export interface WorkerHandle {
|
||||
@@ -106,12 +108,14 @@ export class WorkerManager {
|
||||
// Wait for handshake: worker.ready
|
||||
await this.wait_for_handshake(proc, config)
|
||||
|
||||
// Validate protocol version
|
||||
// Validate protocol version and dispatch task
|
||||
const ready_msg = this.send_and_wait(proc, 'agent.start', {
|
||||
protocol_version: this.protocol.get_version(),
|
||||
agent_id: config.agent_id,
|
||||
session_id: config.session_id,
|
||||
project_root: config.project_root
|
||||
project_root: config.project_root,
|
||||
task_type: config.task_type || 'execute',
|
||||
task_spec: config.task_spec || { id: `${config.agent_id}_task`, title: 'Execute task', description: '' }
|
||||
})
|
||||
|
||||
handle.state = 'ready'
|
||||
|
||||
Reference in New Issue
Block a user