fix(prompts): normalize agent names for continuation injections
This commit is contained in:
@@ -889,7 +889,7 @@ describe("BackgroundManager.notifyParentSession - dynamic message lookup", () =>
|
|||||||
.notifyParentSession(task)
|
.notifyParentSession(task)
|
||||||
|
|
||||||
//#then
|
//#then
|
||||||
expect(capturedBody?.agent).toBe("sisyphus")
|
expect(capturedBody?.agent).toBe("Sisyphus (Ultraworker)")
|
||||||
expect(capturedBody?.model).toEqual({ providerID: "anthropic", modelID: "claude-opus-4.6" })
|
expect(capturedBody?.model).toEqual({ providerID: "anthropic", modelID: "claude-opus-4.6" })
|
||||||
|
|
||||||
manager.shutdown()
|
manager.shutdown()
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
createInternalAgentTextPart,
|
createInternalAgentTextPart,
|
||||||
} from "../../shared"
|
} from "../../shared"
|
||||||
import { applySessionPromptParams } from "../../shared/session-prompt-params-helpers"
|
import { applySessionPromptParams } from "../../shared/session-prompt-params-helpers"
|
||||||
|
import { normalizeAgentForPrompt } from "../../shared/agent-display-names"
|
||||||
import { setSessionTools } from "../../shared/session-tools-store"
|
import { setSessionTools } from "../../shared/session-tools-store"
|
||||||
import { SessionCategoryRegistry } from "../../shared/session-category-registry"
|
import { SessionCategoryRegistry } from "../../shared/session-category-registry"
|
||||||
import { ConcurrencyManager } from "./concurrency"
|
import { ConcurrencyManager } from "./concurrency"
|
||||||
@@ -1829,10 +1830,11 @@ export class BackgroundManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const resolvedTools = resolveInheritedPromptTools(task.parentSessionID, tools)
|
const resolvedTools = resolveInheritedPromptTools(task.parentSessionID, tools)
|
||||||
|
const promptAgent = normalizeAgentForPrompt(agent)
|
||||||
|
|
||||||
log("[background-agent] notifyParentSession context:", {
|
log("[background-agent] notifyParentSession context:", {
|
||||||
taskId: task.id,
|
taskId: task.id,
|
||||||
resolvedAgent: agent,
|
resolvedAgent: promptAgent,
|
||||||
resolvedModel: model,
|
resolvedModel: model,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1846,7 +1848,7 @@ export class BackgroundManager {
|
|||||||
path: { id: task.parentSessionID },
|
path: { id: task.parentSessionID },
|
||||||
body: {
|
body: {
|
||||||
noReply: !shouldReply,
|
noReply: !shouldReply,
|
||||||
...(agent !== undefined ? { agent } : {}),
|
...(promptAgent !== undefined ? { agent: promptAgent } : {}),
|
||||||
...(model !== undefined ? { model } : {}),
|
...(model !== undefined ? { model } : {}),
|
||||||
...(variant !== undefined ? { variant } : {}),
|
...(variant !== undefined ? { variant } : {}),
|
||||||
...(resolvedTools ? { tools: resolvedTools } : {}),
|
...(resolvedTools ? { tools: resolvedTools } : {}),
|
||||||
|
|||||||
@@ -1804,7 +1804,7 @@ session_id: ses_untrusted_999
|
|||||||
// then - should call prompt for sisyphus
|
// then - should call prompt for sisyphus
|
||||||
expect(mockInput._promptMock).toHaveBeenCalled()
|
expect(mockInput._promptMock).toHaveBeenCalled()
|
||||||
const callArgs = mockInput._promptMock.mock.calls[0][0]
|
const callArgs = mockInput._promptMock.mock.calls[0][0]
|
||||||
expect(callArgs.body.agent).toBe("sisyphus")
|
expect(callArgs.body.agent).toBe("Sisyphus (Ultraworker)")
|
||||||
})
|
})
|
||||||
|
|
||||||
test("should preserve display-name agent in continuation prompt when boulder agent uses display form", async () => {
|
test("should preserve display-name agent in continuation prompt when boulder agent uses display form", async () => {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {
|
|||||||
normalizeSDKResponse,
|
normalizeSDKResponse,
|
||||||
resolveInheritedPromptTools,
|
resolveInheritedPromptTools,
|
||||||
} from "../../shared"
|
} from "../../shared"
|
||||||
|
import { normalizeAgentForPrompt } from "../../shared/agent-display-names"
|
||||||
|
|
||||||
type MessageInfo = {
|
type MessageInfo = {
|
||||||
agent?: string
|
agent?: string
|
||||||
@@ -69,6 +70,7 @@ export async function injectContinuationPrompt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const inheritedTools = resolveInheritedPromptTools(sourceSessionID, tools)
|
const inheritedTools = resolveInheritedPromptTools(sourceSessionID, tools)
|
||||||
|
const promptAgent = normalizeAgentForPrompt(agent)
|
||||||
|
|
||||||
const launchModel = model
|
const launchModel = model
|
||||||
? { providerID: model.providerID, modelID: model.modelID }
|
? { providerID: model.providerID, modelID: model.modelID }
|
||||||
@@ -78,7 +80,7 @@ export async function injectContinuationPrompt(
|
|||||||
await ctx.client.session.promptAsync({
|
await ctx.client.session.promptAsync({
|
||||||
path: { id: options.sessionID },
|
path: { id: options.sessionID },
|
||||||
body: {
|
body: {
|
||||||
...(agent !== undefined ? { agent } : {}),
|
...(promptAgent ? { agent: promptAgent } : {}),
|
||||||
...(launchModel ? { model: launchModel } : {}),
|
...(launchModel ? { model: launchModel } : {}),
|
||||||
...(launchVariant ? { variant: launchVariant } : {}),
|
...(launchVariant ? { variant: launchVariant } : {}),
|
||||||
...(inheritedTools ? { tools: inheritedTools } : {}),
|
...(inheritedTools ? { tools: inheritedTools } : {}),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { createOpencodeClient } from "@opencode-ai/sdk"
|
import type { createOpencodeClient } from "@opencode-ai/sdk"
|
||||||
|
import { normalizeAgentForPrompt } from "../../shared/agent-display-names"
|
||||||
import type { MessageData, ResumeConfig } from "./types"
|
import type { MessageData, ResumeConfig } from "./types"
|
||||||
import { createInternalAgentTextPart, resolveInheritedPromptTools } from "../../shared"
|
import { createInternalAgentTextPart, resolveInheritedPromptTools } from "../../shared"
|
||||||
|
|
||||||
@@ -25,6 +26,8 @@ export function extractResumeConfig(userMessage: MessageData | undefined, sessio
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function resumeSession(client: Client, config: ResumeConfig): Promise<boolean> {
|
export async function resumeSession(client: Client, config: ResumeConfig): Promise<boolean> {
|
||||||
|
const promptAgent = normalizeAgentForPrompt(config.agent)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const inheritedTools = resolveInheritedPromptTools(config.sessionID, config.tools)
|
const inheritedTools = resolveInheritedPromptTools(config.sessionID, config.tools)
|
||||||
const launchModel = config.model
|
const launchModel = config.model
|
||||||
@@ -36,7 +39,7 @@ export async function resumeSession(client: Client, config: ResumeConfig): Promi
|
|||||||
path: { id: config.sessionID },
|
path: { id: config.sessionID },
|
||||||
body: {
|
body: {
|
||||||
parts: [createInternalAgentTextPart(RECOVERY_RESUME_TEXT)],
|
parts: [createInternalAgentTextPart(RECOVERY_RESUME_TEXT)],
|
||||||
agent: config.agent,
|
...(promptAgent ? { agent: promptAgent } : {}),
|
||||||
...(launchModel ? { model: launchModel } : {}),
|
...(launchModel ? { model: launchModel } : {}),
|
||||||
...(launchVariant ? { variant: launchVariant } : {}),
|
...(launchVariant ? { variant: launchVariant } : {}),
|
||||||
...(inheritedTools ? { tools: inheritedTools } : {}),
|
...(inheritedTools ? { tools: inheritedTools } : {}),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { BackgroundManager } from "../../features/background-agent"
|
import type { BackgroundManager } from "../../features/background-agent"
|
||||||
import { getMainSessionID, getSessionAgent } from "../../features/claude-code-session-state"
|
import { getMainSessionID, getSessionAgent } from "../../features/claude-code-session-state"
|
||||||
|
import { normalizeAgentForPrompt } from "../../shared/agent-display-names"
|
||||||
import { log } from "../../shared/logger"
|
import { log } from "../../shared/logger"
|
||||||
import { createInternalAgentTextPart, resolveInheritedPromptTools } from "../../shared"
|
import { createInternalAgentTextPart, resolveInheritedPromptTools } from "../../shared"
|
||||||
import { isAbortError } from "../../shared/is-abort-error"
|
import { isAbortError } from "../../shared/is-abort-error"
|
||||||
@@ -83,7 +84,7 @@ async function resolveMainSessionTarget(
|
|||||||
log(`[${HOOK_NAME}] Failed to resolve main session agent`, { sessionID, error: String(error) })
|
log(`[${HOOK_NAME}] Failed to resolve main session agent`, { sessionID, error: String(error) })
|
||||||
}
|
}
|
||||||
|
|
||||||
return { agent, model, tools: resolveInheritedPromptTools(sessionID, tools) }
|
return { agent: normalizeAgentForPrompt(agent), model, tools: resolveInheritedPromptTools(sessionID, tools) }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getThinkingSummary(ctx: BabysitterContext, sessionID: string): Promise<string | null> {
|
async function getThinkingSummary(ctx: BabysitterContext, sessionID: string): Promise<string | null> {
|
||||||
|
|||||||
Reference in New Issue
Block a user