refactor(background-agent): split manager.ts into focused modules

Extract 30+ single-responsibility modules from manager.ts (1556 LOC):
- task lifecycle: task-starter, task-completer, task-canceller, task-resumer
- task queries: task-queries, task-poller, task-queue-processor
- notifications: notification-builder, notification-tracker, parent-session-notifier
- session handling: session-validator, session-output-validator, session-todo-checker
- spawner: spawner/ directory with focused spawn modules
- utilities: duration-formatter, error-classifier, message-storage-locator
- result handling: result-handler-context, background-task-completer
- shutdown: background-manager-shutdown, process-signal
This commit is contained in:
YeonGyu-Kim
2026-02-08 16:20:52 +09:00
parent c7122b4127
commit e3bd43ff64
43 changed files with 2753 additions and 2071 deletions
@@ -0,0 +1,46 @@
import type { BackgroundTask } from "./types"
export type BackgroundTaskNotificationStatus = "COMPLETED" | "CANCELLED"
export function buildBackgroundTaskNotificationText(input: {
task: BackgroundTask
duration: string
statusText: BackgroundTaskNotificationStatus
allComplete: boolean
remainingCount: number
completedTasks: BackgroundTask[]
}): string {
const { task, duration, statusText, allComplete, remainingCount, completedTasks } = input
const errorInfo = task.error ? `\n**Error:** ${task.error}` : ""
if (allComplete) {
const completedTasksText = completedTasks
.map((t) => `- \`${t.id}\`: ${t.description}`)
.join("\n")
return `<system-reminder>
[ALL BACKGROUND TASKS COMPLETE]
**Completed:**
${completedTasksText || `- \`${task.id}\`: ${task.description}`}
Use \`background_output(task_id="<id>")\` to retrieve each result.
</system-reminder>`
}
const agentInfo = task.category ? `${task.agent} (${task.category})` : task.agent
return `<system-reminder>
[BACKGROUND TASK ${statusText}]
**ID:** \`${task.id}\`
**Description:** ${task.description}
**Agent:** ${agentInfo}
**Duration:** ${duration}${errorInfo}
**${remainingCount} task${remainingCount === 1 ? "" : "s"} still in progress.** You WILL be notified when ALL complete.
Do NOT poll - continue productive work.
Use \`background_output(task_id="${task.id}")\` to retrieve this result when ready.
</system-reminder>`
}