- Extract atlas/ into 15 focused modules (hook, event handler, tool policies, types, etc.) - Split auto-update-checker into checker/ and hook/ subdirectories with single-purpose files - Decompose session-recovery into separate recovery strategy files per error type - Extract todo-continuation-enforcer from monolith to directory with dedicated modules - Split background-task/tools.ts into individual tool creator files - Extract command-executor, tmux-utils into focused sub-modules - Split config/schema.ts into domain-specific schema files - Decompose cli/config-manager.ts into focused modules - Rollback skill-mcp-manager, model-availability, index.ts splits that broke tests - Fix all import path depths for moved files (../../ -> ../../../) - Add explicit type annotations to resolve TS7006 implicit any errors Typecheck: 0 errors Tests: 2359 pass, 5 fail (all pre-existing)
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import type { PluginInput } from "@opencode-ai/plugin"
|
|
import type { BackgroundManager } from "../../features/background-agent"
|
|
import { log } from "../../shared/logger"
|
|
import { HOOK_NAME } from "./hook-name"
|
|
import { BOULDER_CONTINUATION_PROMPT } from "./system-reminder-templates"
|
|
import { resolveRecentModelForSession } from "./recent-model-resolver"
|
|
import type { SessionState } from "./types"
|
|
|
|
export async function injectBoulderContinuation(input: {
|
|
ctx: PluginInput
|
|
sessionID: string
|
|
planName: string
|
|
remaining: number
|
|
total: number
|
|
agent?: string
|
|
backgroundManager?: BackgroundManager
|
|
sessionState: SessionState
|
|
}): Promise<void> {
|
|
const {
|
|
ctx,
|
|
sessionID,
|
|
planName,
|
|
remaining,
|
|
total,
|
|
agent,
|
|
backgroundManager,
|
|
sessionState,
|
|
} = input
|
|
|
|
const hasRunningBgTasks = backgroundManager
|
|
? backgroundManager.getTasksByParentSession(sessionID).some((t: { status: string }) => t.status === "running")
|
|
: false
|
|
|
|
if (hasRunningBgTasks) {
|
|
log(`[${HOOK_NAME}] Skipped injection: background tasks running`, { sessionID })
|
|
return
|
|
}
|
|
|
|
const prompt =
|
|
BOULDER_CONTINUATION_PROMPT.replace(/{PLAN_NAME}/g, planName) +
|
|
`\n\n[Status: ${total - remaining}/${total} completed, ${remaining} remaining]`
|
|
|
|
try {
|
|
log(`[${HOOK_NAME}] Injecting boulder continuation`, { sessionID, planName, remaining })
|
|
|
|
const model = await resolveRecentModelForSession(ctx, sessionID)
|
|
|
|
await ctx.client.session.promptAsync({
|
|
path: { id: sessionID },
|
|
body: {
|
|
agent: agent ?? "atlas",
|
|
...(model !== undefined ? { model } : {}),
|
|
parts: [{ type: "text", text: prompt }],
|
|
},
|
|
query: { directory: ctx.directory },
|
|
})
|
|
|
|
sessionState.promptFailureCount = 0
|
|
log(`[${HOOK_NAME}] Boulder continuation injected`, { sessionID })
|
|
} catch (err) {
|
|
sessionState.promptFailureCount += 1
|
|
log(`[${HOOK_NAME}] Boulder continuation failed`, {
|
|
sessionID,
|
|
error: String(err),
|
|
promptFailureCount: sessionState.promptFailureCount,
|
|
})
|
|
}
|
|
}
|