fix(hooks): guard stale idle prompts
This commit is contained in:
@@ -5,12 +5,18 @@ import {
|
||||
} from "../../features/claude-code-session-state"
|
||||
import { log } from "../../shared/logger"
|
||||
import { createInternalAgentContinuationTextPart, resolveInheritedPromptTools } from "../../shared"
|
||||
import { isSessionActive } from "../shared/session-idle-settle"
|
||||
import { HOOK_NAME } from "./hook-name"
|
||||
import { BOULDER_CONTINUATION_PROMPT } from "./system-reminder-templates"
|
||||
import { resolveRecentPromptContextForSession } from "./recent-model-resolver"
|
||||
import type { BackgroundTaskStatusProvider, SessionState } from "./types"
|
||||
|
||||
export type BoulderContinuationResult = "injected" | "skipped_background_tasks" | "skipped_agent_unavailable" | "failed"
|
||||
export type BoulderContinuationResult =
|
||||
| "injected"
|
||||
| "skipped_active_session"
|
||||
| "skipped_background_tasks"
|
||||
| "skipped_agent_unavailable"
|
||||
| "failed"
|
||||
|
||||
const ACTIVE_BACKGROUND_TASK_STATUSES = new Set(["pending", "running"])
|
||||
|
||||
@@ -68,11 +74,16 @@ export async function injectBoulderContinuation(input: {
|
||||
sessionID,
|
||||
agent: continuationAgent ?? agent ?? "unknown",
|
||||
})
|
||||
return "skipped_agent_unavailable"
|
||||
}
|
||||
return "skipped_agent_unavailable"
|
||||
}
|
||||
|
||||
try {
|
||||
log(`[${HOOK_NAME}] Injecting boulder continuation`, { sessionID, planName, remaining })
|
||||
try {
|
||||
if (await isSessionActive(ctx.client, sessionID)) {
|
||||
log(`[${HOOK_NAME}] Skipped injection: session is active`, { sessionID })
|
||||
return "skipped_active_session"
|
||||
}
|
||||
|
||||
log(`[${HOOK_NAME}] Injecting boulder continuation`, { sessionID, planName, remaining })
|
||||
|
||||
const promptContext = await resolveRecentPromptContextForSession(ctx, sessionID)
|
||||
const inheritedTools = resolveInheritedPromptTools(sessionID, promptContext.tools)
|
||||
|
||||
@@ -19,7 +19,7 @@ import { isSessionInBoulderLineage } from "./boulder-session-lineage"
|
||||
import { createInternalAgentContinuationTextPart } from "../../shared"
|
||||
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
||||
import { log } from "../../shared/logger"
|
||||
import { settleAfterSessionIdle } from "../shared/session-idle-settle"
|
||||
import { shouldPromptAfterSessionIdle } from "../shared/session-idle-settle"
|
||||
import { injectBoulderContinuation } from "./boulder-continuation-injector"
|
||||
import { HOOK_NAME } from "./hook-name"
|
||||
import { resolveActiveBoulderSession } from "./resolve-active-boulder-session"
|
||||
@@ -283,6 +283,11 @@ export async function handleAtlasSessionIdle(input: {
|
||||
boulderState.agent ?? (isAgentRegistered("atlas") ? "atlas" : undefined),
|
||||
)
|
||||
if (atlasAgent && isAgentRegistered(atlasAgent)) {
|
||||
if (!(await shouldPromptAfterSessionIdle(ctx.client, sessionID, options?.idleSettleMs))) {
|
||||
log(`[${HOOK_NAME}] Boulder completion nudge skipped because session is active`, { sessionID })
|
||||
return
|
||||
}
|
||||
|
||||
await ctx.client.session.promptAsync({
|
||||
path: { id: sessionID },
|
||||
body: {
|
||||
@@ -379,7 +384,10 @@ export async function handleAtlasSessionIdle(input: {
|
||||
return
|
||||
}
|
||||
|
||||
await settleAfterSessionIdle(options?.idleSettleMs)
|
||||
if (!(await shouldPromptAfterSessionIdle(ctx.client, sessionID, options?.idleSettleMs))) {
|
||||
log(`[${HOOK_NAME}] Skipped: session became active during idle settle`, { sessionID })
|
||||
return
|
||||
}
|
||||
|
||||
await injectContinuation({
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user