feat(agents): add centralized GPT apply_patch permission guard

Extract hardcoded GPT apply_patch permission logic into a reusable module
to ensure consistent behavior across all agents. This prevents GPT models
from using the unreliable apply_patch tool while allowing other models.

- Add gpt-apply-patch-guard.ts with GPT_APPLY_PATCH_GUIDANCE and getGptApplyPatchPermission
- Update Hephaestus agent to use centralized permission logic
- Update Sisyphus-Junior agent to use centralized permission logic
- Update all GPT prompt builders to reference shared guidance constant

🤖 Generated with assistance of OhMyOpenCode
This commit is contained in:
YeonGyu-Kim
2026-04-10 10:47:27 +09:00
parent 498d021dc2
commit 2083cb0710
18 changed files with 87 additions and 41 deletions
+3 -2
View File
@@ -1,6 +1,6 @@
import type { AgentConfig } from "@opencode-ai/sdk";
import type { AgentMode, AgentPromptMetadata } from "../types";
import { isGptModel, isGpt5_4Model, isGpt5_3CodexModel } from "../types";
import { isGpt5_4Model, isGpt5_3CodexModel } from "../types";
import type {
AvailableAgent,
AvailableTool,
@@ -8,6 +8,7 @@ import type {
AvailableCategory,
} from "../dynamic-agent-prompt-builder";
import { categorizeTools, buildAgentIdentitySection } from "../dynamic-agent-prompt-builder";
import { getGptApplyPatchPermission } from "../gpt-apply-patch-guard";
import { buildHephaestusPrompt as buildGptPrompt } from "./gpt";
import { buildHephaestusPrompt as buildGpt53CodexPrompt } from "./gpt-5-3-codex";
@@ -125,7 +126,7 @@ export function createHephaestusAgent(
permission: {
question: "allow",
call_omo_agent: "deny",
...(isGptModel(model) ? { apply_patch: "deny" as const } : {}),
...getGptApplyPatchPermission(model),
} as AgentConfig["permission"],
reasoningEffort: "medium",
};
+2 -1
View File
@@ -1,4 +1,5 @@
/** GPT-5.3 Codex optimized Hephaestus prompt */
import { GPT_APPLY_PATCH_GUIDANCE } from "../gpt-apply-patch-guard";
import type { AgentConfig } from "@opencode-ai/sdk";
import type { AgentMode } from "../types";
import type {
@@ -448,7 +449,7 @@ ${oracleSection}
1. SEARCH existing codebase for similar patterns/styles
2. Match naming, indentation, import styles, error handling conventions
3. Default to ASCII. Add comments only for non-obvious blocks
4. Use the \`edit\` and \`write\` tools for file changes. Do not use \`apply_patch\` on GPT models - it is unreliable here and can hang during verification.
4. ${GPT_APPLY_PATCH_GUIDANCE}
### After Implementation (MANDATORY - DO NOT SKIP)
+2 -1
View File
@@ -21,6 +21,7 @@
* 9. <communication> - Output format, tone guidance
*/
import { GPT_APPLY_PATCH_GUIDANCE } from "../gpt-apply-patch-guard";
import type {
AvailableAgent,
AvailableTool,
@@ -252,7 +253,7 @@ ${antiPatterns}
1. **Explore**: Fire 2-5 explore/librarian agents in parallel + direct tool reads. Goal: complete understanding, not just enough context.
2. **Plan**: List files to modify, specific changes, dependencies, complexity estimate.
3. **Decide**: Trivial (<10 lines, single file) -> self. Complex (multi-file, >100 lines) -> delegate.
4. **Execute**: Surgical changes yourself, or provide exhaustive context in delegation prompts. Match existing patterns. Minimal diff. Search the codebase for similar patterns before writing code. Default to ASCII. Add comments only for non-obvious blocks. Use the \`edit\` and \`write\` tools for file changes. Do not use \`apply_patch\` on GPT models - it is unreliable here and can hang during verification.
4. **Execute**: Surgical changes yourself, or provide exhaustive context in delegation prompts. Match existing patterns. Minimal diff. Search the codebase for similar patterns before writing code. Default to ASCII. Add comments only for non-obvious blocks. ${GPT_APPLY_PATCH_GUIDANCE}
5. **Verify**: \`lsp_diagnostics\` on all modified files (zero errors) -> run related tests (\`foo.ts\` -> \`foo.test.ts\`) -> typecheck -> build if applicable (exit 0). Fix only issues your changes caused.
If verification fails, return to step 1 with a materially different approach. After three attempts: stop, revert to last working state, document what you tried, consult Oracle. If Oracle cannot resolve, ask the user.
+2 -1
View File
@@ -1,5 +1,6 @@
/** Generic GPT Hephaestus prompt - fallback for GPT models without a model-specific variant */
import { GPT_APPLY_PATCH_GUIDANCE } from "../gpt-apply-patch-guard"
import type {
AvailableAgent,
AvailableTool,
@@ -311,7 +312,7 @@ ${oracleSection}
1. SEARCH existing codebase for similar patterns/styles
2. Match naming, indentation, import styles, error handling conventions
3. Default to ASCII. Add comments only for non-obvious blocks
4. Use the \`edit\` and \`write\` tools for file changes. Do not use \`apply_patch\` on GPT models - it is unreliable here and can hang during verification.
4. ${GPT_APPLY_PATCH_GUIDANCE}
### After Implementation (MANDATORY - DO NOT SKIP)