Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/plugin-abilities/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 58 additions & 5 deletions packages/plugin-abilities/src/executor/execution-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ import { executeAbility } from './index.js'

/**
* Minimal ExecutionManager
*
*
* Simplified to track SINGLE execution at a time.
* No session management, no cleanup timers, no multi-execution.
*
*
* This is the bare minimum to test the core concept.
*/
export class ExecutionManager {
private activeExecution: AbilityExecution | null = null
private executionHistory: AbilityExecution[] = []
private maxHistory = 50
private abortController: AbortController | null = null

async execute(
ability: Ability,
Expand All @@ -23,10 +26,33 @@ export class ExecutionManager {
}

console.log(`[abilities] Starting execution: ${ability.name}`)

const execution = await executeAbility(ability, inputs, ctx)

this.abortController = new AbortController()

// Set activeExecution BEFORE awaiting so getActive() returns a live
// reference during execution (needed for chat-context injection and
// concurrent-execution guards).
this.activeExecution = {
id: `exec_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
ability,
inputs,
status: 'running',
currentStep: null,
currentStepIndex: -1,
completedSteps: [],
pendingSteps: [...ability.steps],
startedAt: Date.now(),
}

const execution = await executeAbility(ability, inputs, ctx, this.abortController.signal)
this.activeExecution = execution

// Track in history
this.executionHistory.push(execution)
if (this.executionHistory.length > this.maxHistory) {
this.executionHistory = this.executionHistory.slice(-this.maxHistory)
}

// Clear active if completed/failed
if (execution.status !== 'running') {
this.activeExecution = null
Expand All @@ -35,14 +61,24 @@ export class ExecutionManager {
return execution
}

get(id: string): AbilityExecution | undefined {
return this.executionHistory.find((e) => e.id === id)
}

list(): AbilityExecution[] {
return [...this.executionHistory]
}

getActive(): AbilityExecution | null {
return this.activeExecution
}

cancel(): boolean {
if (!this.activeExecution) return false

if (this.activeExecution.status === 'running') {
this.abortController?.abort()
this.abortController = null
this.activeExecution.status = 'failed'
this.activeExecution.error = 'Cancelled by user'
this.activeExecution.completedAt = Date.now()
Expand All @@ -53,7 +89,24 @@ export class ExecutionManager {
return false
}

cancelActive(): boolean {
return this.cancel()
}

onSessionDeleted(sessionId: string): void {
if (this.activeExecution && this.activeExecution.status === 'running') {
this.abortController?.abort()
this.abortController = null
this.activeExecution.status = 'failed'
this.activeExecution.error = `Session ${sessionId} deleted`
this.activeExecution.completedAt = Date.now()
this.activeExecution = null
}
}

cleanup(): void {
this.abortController?.abort()
this.abortController = null
this.activeExecution = null
}
}
Loading
Loading