diff --git a/src/tools/delegate-task/builtin-categories.ts b/src/tools/delegate-task/builtin-categories.ts index f8da8ecf1..335455b53 100644 --- a/src/tools/delegate-task/builtin-categories.ts +++ b/src/tools/delegate-task/builtin-categories.ts @@ -31,3 +31,9 @@ export const CATEGORY_PROMPT_APPENDS: Record = buildCategoryReco export const CATEGORY_DESCRIPTIONS: Record = buildCategoryRecord( (definition) => definition.description ) + +export const CATEGORY_PROMPT_APPEND_RESOLVERS: Record string> = Object.fromEntries( + BUILTIN_CATEGORIES + .filter((definition) => definition.resolvePromptAppend !== undefined) + .map((definition) => [definition.name, definition.resolvePromptAppend!]), +) diff --git a/src/tools/delegate-task/builtin-category-definition.ts b/src/tools/delegate-task/builtin-category-definition.ts index d9c853b63..51ac93818 100644 --- a/src/tools/delegate-task/builtin-category-definition.ts +++ b/src/tools/delegate-task/builtin-category-definition.ts @@ -5,4 +5,5 @@ export type BuiltinCategoryDefinition = { config: CategoryConfig description: string promptAppend: string + resolvePromptAppend?: (model: string | undefined) => string } diff --git a/src/tools/delegate-task/category-resolver.test.ts b/src/tools/delegate-task/category-resolver.test.ts index ffe59d705..8077054d0 100644 --- a/src/tools/delegate-task/category-resolver.test.ts +++ b/src/tools/delegate-task/category-resolver.test.ts @@ -512,4 +512,114 @@ describe("resolveCategoryExecution", () => { }) expect(result.fallbackChain).toBeUndefined() }) + + test("uses GPT-5.5 deep prompt append when category model resolves to gpt-5.5", async () => { + //#given + const args = { + category: "deep", + prompt: "test prompt", + description: "Test task", + run_in_background: false, + load_skills: [], + blockedBy: undefined, + enableSkillTools: false, + } + const executorCtx = createMockExecutorContext() + executorCtx.userCategories = { + deep: { model: "openai/gpt-5.5", variant: "medium" }, + } + + //#when + const result = await resolveCategoryExecution(args, executorCtx, undefined, "anthropic/claude-sonnet-4-6") + + //#then + expect(result.error).toBeUndefined() + expect(result.actualModel).toBe("openai/gpt-5.5") + expect(result.categoryPromptAppend).toBeDefined() + expect(result.categoryPromptAppend).toContain("operating in DEEP mode") + expect(result.categoryPromptAppend).toContain("five to fifteen minutes") + }) + + test("uses legacy deep prompt append when category model resolves to gpt-5.4", async () => { + //#given + const args = { + category: "deep", + prompt: "test prompt", + description: "Test task", + run_in_background: false, + load_skills: [], + blockedBy: undefined, + enableSkillTools: false, + } + const executorCtx = createMockExecutorContext() + executorCtx.userCategories = { + deep: { model: "openai/gpt-5.4" }, + } + + //#when + const result = await resolveCategoryExecution(args, executorCtx, undefined, "anthropic/claude-sonnet-4-6") + + //#then + expect(result.error).toBeUndefined() + expect(result.actualModel).toBe("openai/gpt-5.4") + expect(result.categoryPromptAppend).toBeDefined() + expect(result.categoryPromptAppend).toContain("GOAL-ORIENTED AUTONOMOUS") + expect(result.categoryPromptAppend).not.toContain("operating in DEEP mode") + }) + + test("appends user prompt_append to GPT-5.5 deep base prompt", async () => { + //#given + const args = { + category: "deep", + prompt: "test prompt", + description: "Test task", + run_in_background: false, + load_skills: [], + blockedBy: undefined, + enableSkillTools: false, + } + const executorCtx = createMockExecutorContext() + executorCtx.userCategories = { + deep: { + model: "openai/gpt-5.5", + prompt_append: "USER_CUSTOM_INSTRUCTION_XYZ", + }, + } + + //#when + const result = await resolveCategoryExecution(args, executorCtx, undefined, "anthropic/claude-sonnet-4-6") + + //#then + expect(result.error).toBeUndefined() + expect(result.categoryPromptAppend).toContain("operating in DEEP mode") + expect(result.categoryPromptAppend).toContain("USER_CUSTOM_INSTRUCTION_XYZ") + }) + + test("appends user prompt_append to legacy deep base prompt for non-gpt-5.5 models", async () => { + //#given + const args = { + category: "deep", + prompt: "test prompt", + description: "Test task", + run_in_background: false, + load_skills: [], + blockedBy: undefined, + enableSkillTools: false, + } + const executorCtx = createMockExecutorContext() + executorCtx.userCategories = { + deep: { + model: "openai/gpt-5.4", + prompt_append: "USER_CUSTOM_INSTRUCTION_LEGACY", + }, + } + + //#when + const result = await resolveCategoryExecution(args, executorCtx, undefined, "anthropic/claude-sonnet-4-6") + + //#then + expect(result.error).toBeUndefined() + expect(result.categoryPromptAppend).toContain("GOAL-ORIENTED AUTONOMOUS") + expect(result.categoryPromptAppend).toContain("USER_CUSTOM_INSTRUCTION_LEGACY") + }) }) diff --git a/src/tools/delegate-task/category-resolver.ts b/src/tools/delegate-task/category-resolver.ts index 25f4e8a37..f45d2452f 100644 --- a/src/tools/delegate-task/category-resolver.ts +++ b/src/tools/delegate-task/category-resolver.ts @@ -5,6 +5,7 @@ import type { FallbackEntry } from "../../shared/model-requirements" import { mergeCategories } from "../../shared/merge-categories" import { SISYPHUS_JUNIOR_AGENT } from "./sisyphus-junior-agent" import { resolveCategoryConfig } from "./categories" +import { CATEGORY_PROMPT_APPEND_RESOLVERS } from "./constants" import { parseModelString } from "../../shared/model-string-parser" import { CATEGORY_MODEL_REQUIREMENTS } from "../../shared/model-requirements" import { normalizeFallbackModels, flattenToFallbackModelStrings } from "../../shared/model-resolver" @@ -26,6 +27,23 @@ function applyCategoryParams(base: DelegatedModelConfig, config: CategoryConfig) return result } +function resolveCategoryPromptAppendForModel( + categoryName: string, + actualModel: string | undefined, + staticPromptAppend: string, + userPromptAppend: string | undefined, +): string | undefined { + const dynamicResolver = CATEGORY_PROMPT_APPEND_RESOLVERS[categoryName] + if (!dynamicResolver) { + return staticPromptAppend || undefined + } + const dynamicBase = dynamicResolver(actualModel) + if (!userPromptAppend) { + return dynamicBase || undefined + } + return dynamicBase ? `${dynamicBase}\n\n${userPromptAppend}` : userPromptAppend +} + export interface CategoryResolutionResult { agentToUse: string categoryModel: DelegatedModelConfig | undefined @@ -210,7 +228,12 @@ Available categories: ${allCategoryNames}`, const parsedModel = parseModelString(actualModel) categoryModel = parsedModel ?? undefined } - const categoryPromptAppend = resolved.promptAppend || undefined + const categoryPromptAppend = resolveCategoryPromptAppendForModel( + args.category!, + actualModel, + resolved.promptAppend, + userCategories?.[args.category!]?.prompt_append, + ) if (!categoryModel && !actualModel && !isModelResolutionSkipped) { const categoryNames = Object.keys(enabledCategories) diff --git a/src/tools/delegate-task/constants.ts b/src/tools/delegate-task/constants.ts index 3d94c90eb..ebe7d07a1 100644 --- a/src/tools/delegate-task/constants.ts +++ b/src/tools/delegate-task/constants.ts @@ -7,6 +7,7 @@ import { truncateDescription } from "../../shared/truncate-description" export { CATEGORY_DESCRIPTIONS, CATEGORY_PROMPT_APPENDS, + CATEGORY_PROMPT_APPEND_RESOLVERS, DEFAULT_CATEGORIES, } from "./builtin-categories" diff --git a/src/tools/delegate-task/openai-categories.test.ts b/src/tools/delegate-task/openai-categories.test.ts new file mode 100644 index 000000000..ec37e369c --- /dev/null +++ b/src/tools/delegate-task/openai-categories.test.ts @@ -0,0 +1,163 @@ +declare const require: (name: string) => any +const { describe, test, expect } = require("bun:test") + +import { + DEEP_CATEGORY_PROMPT_APPEND, + DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5, + OPENAI_CATEGORIES, + resolveDeepCategoryPromptAppend, +} from "./openai-categories" + +describe("DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5", () => { + test("uses Category_Context wrapper with name=\"deep\"", () => { + //#given + const prompt = DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5 + + //#then + expect(prompt).toContain('') + expect(prompt).toContain("") + }) + + test("contains GPT-5.5 prose-first style markers from the deep.md draft", () => { + //#given + const prompt = DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5 + + //#then + expect(prompt).toContain("operating in DEEP mode") + expect(prompt).toContain("Exploration budget: generous") + expect(prompt).toContain("five to fifteen minutes") + expect(prompt).toContain("Goal, not plan") + expect(prompt).toContain("Atomic task treatment") + expect(prompt).toContain("Root cause bias") + expect(prompt).toContain("Ambition scaled to context") + expect(prompt).toContain("Completion bar: full delivery") + expect(prompt).toContain("Status cadence: sparse") + }) + + test("does not use the legacy threat-frame phrasing", () => { + //#given + const prompt = DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5 + + //#then + expect(prompt).not.toContain("You are NOT an interactive assistant") + expect(prompt).not.toContain("BEFORE making ANY changes") + }) + + test("is materially different from the legacy DEEP_CATEGORY_PROMPT_APPEND", () => { + //#then + expect(DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5).not.toBe(DEEP_CATEGORY_PROMPT_APPEND) + expect(DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5.length).toBeGreaterThan( + DEEP_CATEGORY_PROMPT_APPEND.length, + ) + }) +}) + +describe("resolveDeepCategoryPromptAppend", () => { + test("returns GPT-5.5 prompt for openai/gpt-5.5", () => { + //#when + const result = resolveDeepCategoryPromptAppend("openai/gpt-5.5") + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5) + }) + + test("returns GPT-5.5 prompt for openai/gpt-5.5 with variant suffix", () => { + //#when + const result = resolveDeepCategoryPromptAppend("openai/gpt-5.5 medium") + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5) + }) + + test("returns GPT-5.5 prompt for the gpt-5-5 hyphenated form", () => { + //#when + const result = resolveDeepCategoryPromptAppend("openai/gpt-5-5") + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5) + }) + + test("returns legacy prompt for openai/gpt-5.4", () => { + //#when + const result = resolveDeepCategoryPromptAppend("openai/gpt-5.4") + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND) + }) + + test("returns legacy prompt for openai/gpt-5.3-codex", () => { + //#when + const result = resolveDeepCategoryPromptAppend("openai/gpt-5.3-codex") + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND) + }) + + test("returns legacy prompt for undefined model", () => { + //#when + const result = resolveDeepCategoryPromptAppend(undefined) + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND) + }) + + test("returns legacy prompt for a non-GPT model", () => { + //#when + const result = resolveDeepCategoryPromptAppend("anthropic/claude-opus-4-7") + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND) + }) +}) + +describe("OPENAI_CATEGORIES deep entry", () => { + test("exposes a resolvePromptAppend hook on the deep category", () => { + //#given + const deepCat = OPENAI_CATEGORIES.find((c) => c.name === "deep") + + //#then + expect(deepCat).toBeDefined() + expect(deepCat?.resolvePromptAppend).toBeDefined() + expect(typeof deepCat?.resolvePromptAppend).toBe("function") + }) + + test("deep category resolver picks GPT-5.5 prompt for gpt-5.5 model", () => { + //#given + const deepCat = OPENAI_CATEGORIES.find((c) => c.name === "deep") + + //#when + const result = deepCat?.resolvePromptAppend?.("openai/gpt-5.5") + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5) + }) + + test("deep category resolver falls back to legacy for non-gpt-5.5 models", () => { + //#given + const deepCat = OPENAI_CATEGORIES.find((c) => c.name === "deep") + + //#when + const result = deepCat?.resolvePromptAppend?.("openai/gpt-5.4") + + //#then + expect(result).toBe(DEEP_CATEGORY_PROMPT_APPEND) + }) + + test("ultrabrain category does not expose a resolvePromptAppend hook", () => { + //#given + const ultraCat = OPENAI_CATEGORIES.find((c) => c.name === "ultrabrain") + + //#then + expect(ultraCat).toBeDefined() + expect(ultraCat?.resolvePromptAppend).toBeUndefined() + }) + + test("quick category does not expose a resolvePromptAppend hook", () => { + //#given + const quickCat = OPENAI_CATEGORIES.find((c) => c.name === "quick") + + //#then + expect(quickCat).toBeDefined() + expect(quickCat?.resolvePromptAppend).toBeUndefined() + }) +}) diff --git a/src/tools/delegate-task/openai-categories.ts b/src/tools/delegate-task/openai-categories.ts index c1ee31593..6239de59b 100644 --- a/src/tools/delegate-task/openai-categories.ts +++ b/src/tools/delegate-task/openai-categories.ts @@ -1,3 +1,4 @@ +import { isGpt5_5Model } from "../../agents/types" import type { BuiltinCategoryDefinition } from "./builtin-category-definition" const ULTRABRAIN_CATEGORY_PROMPT_APPEND = ` @@ -22,7 +23,7 @@ Response format: - Risks and mitigations (if relevant) ` -const DEEP_CATEGORY_PROMPT_APPEND = ` +export const DEEP_CATEGORY_PROMPT_APPEND = ` You are working on GOAL-ORIENTED AUTONOMOUS tasks. You are NOT an interactive assistant. You are an autonomous problem-solver. @@ -43,6 +44,35 @@ Approach: explore extensively, understand deeply, then act decisively. Prefer co Minimal status updates. Focus on results, not play-by-play. Report completion with summary of changes. ` +export const DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5 = ` +You are operating in DEEP mode. This is the category reserved for goal-oriented autonomous work on hairy problems that reward thorough exploration and comprehensive solutions. + +The orchestrator chose this category because the task benefits from depth over speed. You should feel empowered to spend the time needed: five to fifteen minutes of silent exploration before the first edit is normal and correct. Rushing to implementation on a deep task is a failure mode, not a feature. + +# How deep mode adjusts the base behavior + +**Exploration budget: generous.** Read the files you need, trace dependencies both directions, fire 2-5 explore/librarian sub-agents in parallel for broader questions. Build a complete mental model before the first \`apply_patch\`. Exploration here is an investment, not overhead. + +**Goal, not plan.** You receive a GOAL describing the desired outcome. You figure out HOW to achieve it. The orchestrator deliberately did not hand you a step-by-step plan; producing one and asking for approval is not what was asked. Execute. + +**Atomic task treatment.** When the goal contains numbered steps or phases, treat them as sub-steps of ONE task and execute them all in this turn. Splitting them across turns is wrong unless they reveal an architectural blocker that requires the user's input. If the "steps" turn out to be genuinely independent tasks that should have been separate delegations, flag that in your final message and refuse the ones beyond scope. + +**Root cause bias.** Prefer root-cause fixes over symptom fixes. A null check around \`foo()\` is a symptom fix; fixing whatever causes \`foo()\` to return unexpected values is the root fix. Trace at least two levels up before settling on an answer. In deep mode, you have permission (and the expectation) to do the deeper fix. + +**Ambition scaled to context.** For brand-new greenfield work, be ambitious. Choose strong defaults, avoid AI-slop aesthetics, produce something you would be proud to hand to another senior engineer. For changes in an existing codebase, be surgical and respect the existing patterns; depth does not mean invasiveness. + +**Completion bar: full delivery.** "Simplified version", "proof of concept", and "you can extend this later" are not acceptable deliveries for a deep task. The orchestrator routed here specifically for a complete solution. If you hit a genuine blocker (missing secret, design decision only the user can make, three materially different attempts all failed), document it and return; otherwise, finish the task. + +**Status cadence: sparse.** The user is not on the other side of this conversation; the orchestrator is, and they will synthesize your progress. Send commentary only at meaningful phase transitions (starting exploration, starting implementation, starting verification, hitting a genuine blocker). Do not narrate every tool call; silence during focused work is expected. +` + +export function resolveDeepCategoryPromptAppend(model: string | undefined): string { + if (model && isGpt5_5Model(model)) { + return DEEP_CATEGORY_PROMPT_APPEND_GPT_5_5 + } + return DEEP_CATEGORY_PROMPT_APPEND +} + const QUICK_CATEGORY_PROMPT_APPEND = ` You are working on SMALL / QUICK tasks. @@ -106,6 +136,7 @@ export const OPENAI_CATEGORIES: BuiltinCategoryDefinition[] = [ config: { model: "openai/gpt-5.5", variant: "medium" }, description: "Goal-oriented autonomous problem-solving. Thorough research before action. For hairy problems requiring deep understanding.", promptAppend: DEEP_CATEGORY_PROMPT_APPEND, + resolvePromptAppend: resolveDeepCategoryPromptAppend, }, { name: "quick",