fix(atlas): gate boulder continuation prompts
This commit is contained in:
@@ -5,7 +5,7 @@ import {
|
|||||||
} from "../../features/claude-code-session-state"
|
} from "../../features/claude-code-session-state"
|
||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import { createInternalAgentContinuationTextPart, resolveInheritedPromptTools } from "../../shared"
|
import { createInternalAgentContinuationTextPart, resolveInheritedPromptTools } from "../../shared"
|
||||||
import { isSessionActive } from "../shared/session-idle-settle"
|
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
||||||
import { HOOK_NAME } from "./hook-name"
|
import { HOOK_NAME } from "./hook-name"
|
||||||
import { BOULDER_CONTINUATION_PROMPT } from "./system-reminder-templates"
|
import { BOULDER_CONTINUATION_PROMPT } from "./system-reminder-templates"
|
||||||
import { resolveRecentPromptContextForSession } from "./recent-model-resolver"
|
import { resolveRecentPromptContextForSession } from "./recent-model-resolver"
|
||||||
@@ -32,6 +32,7 @@ export async function injectBoulderContinuation(input: {
|
|||||||
preferredTaskTitle?: string
|
preferredTaskTitle?: string
|
||||||
backgroundManager?: BackgroundTaskStatusProvider
|
backgroundManager?: BackgroundTaskStatusProvider
|
||||||
sessionState: SessionState
|
sessionState: SessionState
|
||||||
|
idleSettleMs?: number
|
||||||
}): Promise<BoulderContinuationResult> {
|
}): Promise<BoulderContinuationResult> {
|
||||||
const {
|
const {
|
||||||
ctx,
|
ctx,
|
||||||
@@ -45,6 +46,7 @@ export async function injectBoulderContinuation(input: {
|
|||||||
preferredTaskTitle,
|
preferredTaskTitle,
|
||||||
backgroundManager,
|
backgroundManager,
|
||||||
sessionState,
|
sessionState,
|
||||||
|
idleSettleMs,
|
||||||
} = input
|
} = input
|
||||||
|
|
||||||
const hasRunningBgTasks = backgroundManager
|
const hasRunningBgTasks = backgroundManager
|
||||||
@@ -78,11 +80,6 @@ export async function injectBoulderContinuation(input: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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 })
|
log(`[${HOOK_NAME}] Injecting boulder continuation`, { sessionID, planName, remaining })
|
||||||
|
|
||||||
const promptContext = await resolveRecentPromptContextForSession(ctx, sessionID)
|
const promptContext = await resolveRecentPromptContextForSession(ctx, sessionID)
|
||||||
@@ -93,7 +90,12 @@ export async function injectBoulderContinuation(input: {
|
|||||||
: undefined
|
: undefined
|
||||||
const launchVariant = promptContext.model?.variant
|
const launchVariant = promptContext.model?.variant
|
||||||
|
|
||||||
await ctx.client.session.promptAsync({
|
const promptResult = await promptAsyncAfterSessionIdle({
|
||||||
|
client: ctx.client,
|
||||||
|
sessionID,
|
||||||
|
source: HOOK_NAME,
|
||||||
|
settleMs: idleSettleMs,
|
||||||
|
input: {
|
||||||
path: { id: sessionID },
|
path: { id: sessionID },
|
||||||
body: {
|
body: {
|
||||||
agent: continuationAgent,
|
agent: continuationAgent,
|
||||||
@@ -103,7 +105,18 @@ export async function injectBoulderContinuation(input: {
|
|||||||
parts: [createInternalAgentContinuationTextPart(prompt)],
|
parts: [createInternalAgentContinuationTextPart(prompt)],
|
||||||
},
|
},
|
||||||
query: { directory: ctx.directory },
|
query: { directory: ctx.directory },
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
if (promptResult.status === "failed") {
|
||||||
|
throw promptResult.error
|
||||||
|
}
|
||||||
|
if (promptResult.status !== "dispatched") {
|
||||||
|
log(`[${HOOK_NAME}] Boulder continuation skipped by promptAsync gate`, {
|
||||||
|
sessionID,
|
||||||
|
status: promptResult.status,
|
||||||
|
})
|
||||||
|
return "skipped_active_session"
|
||||||
|
}
|
||||||
|
|
||||||
sessionState.promptFailureCount = 0
|
sessionState.promptFailureCount = 0
|
||||||
log(`[${HOOK_NAME}] Boulder continuation injected`, { sessionID })
|
log(`[${HOOK_NAME}] Boulder continuation injected`, { sessionID })
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { createInternalAgentContinuationTextPart } from "../../shared"
|
|||||||
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
import { getAgentConfigKey } from "../../shared/agent-display-names"
|
||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import { shouldPromptAfterSessionIdle } from "../shared/session-idle-settle"
|
import { shouldPromptAfterSessionIdle } from "../shared/session-idle-settle"
|
||||||
|
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
||||||
import { injectBoulderContinuation } from "./boulder-continuation-injector"
|
import { injectBoulderContinuation } from "./boulder-continuation-injector"
|
||||||
import { HOOK_NAME } from "./hook-name"
|
import { HOOK_NAME } from "./hook-name"
|
||||||
import { resolveActiveBoulderSession } from "./resolve-active-boulder-session"
|
import { resolveActiveBoulderSession } from "./resolve-active-boulder-session"
|
||||||
@@ -52,6 +53,7 @@ async function injectContinuation(input: {
|
|||||||
progress: { total: number; completed: number }
|
progress: { total: number; completed: number }
|
||||||
agent?: string
|
agent?: string
|
||||||
worktreePath?: string
|
worktreePath?: string
|
||||||
|
idleSettleMs?: number
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const remaining = input.progress.total - input.progress.completed
|
const remaining = input.progress.total - input.progress.completed
|
||||||
if (input.sessionState.isInjectingContinuation) {
|
if (input.sessionState.isInjectingContinuation) {
|
||||||
@@ -110,6 +112,7 @@ async function injectContinuation(input: {
|
|||||||
preferredTaskTitle: preferredTaskSession?.task_title,
|
preferredTaskTitle: preferredTaskSession?.task_title,
|
||||||
backgroundManager: input.options?.backgroundManager,
|
backgroundManager: input.options?.backgroundManager,
|
||||||
sessionState: input.sessionState,
|
sessionState: input.sessionState,
|
||||||
|
idleSettleMs: input.idleSettleMs,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (result === "injected") {
|
if (result === "injected") {
|
||||||
@@ -288,14 +291,27 @@ export async function handleAtlasSessionIdle(input: {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await ctx.client.session.promptAsync({
|
const promptResult = await promptAsyncAfterSessionIdle({
|
||||||
path: { id: sessionID },
|
client: ctx.client,
|
||||||
body: {
|
sessionID,
|
||||||
agent: atlasAgent,
|
source: HOOK_NAME,
|
||||||
parts: [createInternalAgentContinuationTextPart(prompt)],
|
settleMs: options?.idleSettleMs,
|
||||||
|
input: {
|
||||||
|
path: { id: sessionID },
|
||||||
|
body: {
|
||||||
|
agent: atlasAgent,
|
||||||
|
parts: [createInternalAgentContinuationTextPart(prompt)],
|
||||||
|
},
|
||||||
|
query: { directory: ctx.directory },
|
||||||
},
|
},
|
||||||
query: { directory: ctx.directory },
|
|
||||||
})
|
})
|
||||||
|
if (promptResult.status !== "dispatched") {
|
||||||
|
log(`[${HOOK_NAME}] Boulder completion nudge skipped by promptAsync gate`, {
|
||||||
|
sessionID,
|
||||||
|
status: promptResult.status,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
sessionState.boulderCompletionNudgedAt = {
|
sessionState.boulderCompletionNudgedAt = {
|
||||||
...(sessionState.boulderCompletionNudgedAt ?? {}),
|
...(sessionState.boulderCompletionNudgedAt ?? {}),
|
||||||
[work.work_id]: Date.now(),
|
[work.work_id]: Date.now(),
|
||||||
@@ -398,6 +414,7 @@ export async function handleAtlasSessionIdle(input: {
|
|||||||
progress,
|
progress,
|
||||||
agent: boulderState.agent,
|
agent: boulderState.agent,
|
||||||
worktreePath: boulderState.worktree_path,
|
worktreePath: boulderState.worktree_path,
|
||||||
|
idleSettleMs: options?.idleSettleMs ?? 0,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user