fix(babysitter): gate reminder prompts
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
|||||||
isUnstableTask,
|
isUnstableTask,
|
||||||
THINKING_SUMMARY_MAX_CHARS,
|
THINKING_SUMMARY_MAX_CHARS,
|
||||||
} from "./task-message-analyzer"
|
} from "./task-message-analyzer"
|
||||||
import { shouldPromptAfterSessionIdle } from "../shared/session-idle-settle"
|
import { promptAsyncAfterSessionIdle } from "../shared/prompt-async-gate"
|
||||||
|
|
||||||
const HOOK_NAME = "unstable-agent-babysitter"
|
const HOOK_NAME = "unstable-agent-babysitter"
|
||||||
const DEFAULT_TIMEOUT_MS = 120000
|
const DEFAULT_TIMEOUT_MS = 120000
|
||||||
@@ -216,22 +216,31 @@ export function createUnstableAgentBabysitterHook(ctx: BabysitterContext, option
|
|||||||
? { providerID: model.providerID, modelID: model.modelID }
|
? { providerID: model.providerID, modelID: model.modelID }
|
||||||
: undefined
|
: undefined
|
||||||
const launchVariant = model?.variant
|
const launchVariant = model?.variant
|
||||||
if (!(await shouldPromptAfterSessionIdle(ctx.client, mainSessionID, options.idleSettleMs))) {
|
const promptResult = await promptAsyncAfterSessionIdle({
|
||||||
log(`[${HOOK_NAME}] Reminder skipped because main session is active`, { taskId: task.id, sessionID: mainSessionID })
|
client: ctx.client,
|
||||||
|
sessionID: mainSessionID,
|
||||||
|
source: HOOK_NAME,
|
||||||
|
settleMs: options.idleSettleMs,
|
||||||
|
input: {
|
||||||
|
path: { id: mainSessionID },
|
||||||
|
body: {
|
||||||
|
...(agent ? { agent } : {}),
|
||||||
|
...(launchModel ? { model: launchModel } : {}),
|
||||||
|
...(launchVariant ? { variant: launchVariant } : {}),
|
||||||
|
...(tools ? { tools } : {}),
|
||||||
|
parts: [createInternalAgentTextPart(reminder)],
|
||||||
|
},
|
||||||
|
query: { directory: ctx.directory },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (promptResult.status !== "dispatched") {
|
||||||
|
log(`[${HOOK_NAME}] Reminder skipped by promptAsync gate`, {
|
||||||
|
taskId: task.id,
|
||||||
|
sessionID: mainSessionID,
|
||||||
|
status: promptResult.status,
|
||||||
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
await ctx.client.session.promptAsync({
|
|
||||||
path: { id: mainSessionID },
|
|
||||||
body: {
|
|
||||||
...(agent ? { agent } : {}),
|
|
||||||
...(launchModel ? { model: launchModel } : {}),
|
|
||||||
...(launchVariant ? { variant: launchVariant } : {}),
|
|
||||||
...(tools ? { tools } : {}),
|
|
||||||
parts: [createInternalAgentTextPart(reminder)],
|
|
||||||
},
|
|
||||||
query: { directory: ctx.directory },
|
|
||||||
})
|
|
||||||
reminderCooldowns.set(task.id, now)
|
reminderCooldowns.set(task.id, now)
|
||||||
log(`[${HOOK_NAME}] Reminder injected`, { taskId: task.id, sessionID: mainSessionID })
|
log(`[${HOOK_NAME}] Reminder injected`, { taskId: task.id, sessionID: mainSessionID })
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import type { PluginContext } from "./types"
|
|||||||
|
|
||||||
import { createUnstableAgentBabysitterHook } from "../hooks"
|
import { createUnstableAgentBabysitterHook } from "../hooks"
|
||||||
import type { BackgroundManager } from "../features/background-agent"
|
import type { BackgroundManager } from "../features/background-agent"
|
||||||
|
import { promptAsyncAfterSessionIdle } from "../hooks/shared/prompt-async-gate"
|
||||||
|
|
||||||
export function createUnstableAgentBabysitter(args: {
|
export function createUnstableAgentBabysitter(args: {
|
||||||
ctx: PluginContext
|
ctx: PluginContext
|
||||||
@@ -24,11 +25,28 @@ export function createUnstableAgentBabysitter(args: {
|
|||||||
}
|
}
|
||||||
return []
|
return []
|
||||||
},
|
},
|
||||||
|
status: async () => ctx.client.session.status(),
|
||||||
prompt: async (promptArgs) => {
|
prompt: async (promptArgs) => {
|
||||||
await ctx.client.session.promptAsync(promptArgs)
|
const promptResult = await promptAsyncAfterSessionIdle({
|
||||||
|
client: ctx.client,
|
||||||
|
sessionID: promptArgs.path.id,
|
||||||
|
source: "unstable-agent-babysitter",
|
||||||
|
input: promptArgs,
|
||||||
|
})
|
||||||
|
if (promptResult.status === "failed") {
|
||||||
|
throw promptResult.error
|
||||||
|
}
|
||||||
},
|
},
|
||||||
promptAsync: async (promptArgs) => {
|
promptAsync: async (promptArgs) => {
|
||||||
await ctx.client.session.promptAsync(promptArgs)
|
const promptResult = await promptAsyncAfterSessionIdle({
|
||||||
|
client: ctx.client,
|
||||||
|
sessionID: promptArgs.path.id,
|
||||||
|
source: "unstable-agent-babysitter",
|
||||||
|
input: promptArgs,
|
||||||
|
})
|
||||||
|
if (promptResult.status === "failed") {
|
||||||
|
throw promptResult.error
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user