fix(hooks): remove dead delegate-task-english-directive hook
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
export const TARGET_SUBAGENT_TYPES = ["explore", "librarian", "oracle", "plan"] as const
|
||||
|
||||
export const ENGLISH_DIRECTIVE =
|
||||
"**YOU MUST ALWAYS THINK, REASON, AND RESPOND IN ENGLISH REGARDLESS OF THE USER'S QUERY LANGUAGE.**"
|
||||
|
||||
export function createDelegateTaskEnglishDirectiveHook() {
|
||||
return {
|
||||
"tool.execute.before": async (
|
||||
input: { tool: string; sessionID: string; callID: string; input: Record<string, unknown> },
|
||||
_output: { title: string; output: string; metadata: unknown }
|
||||
) => {
|
||||
if (input.tool.toLowerCase() !== "task") return
|
||||
|
||||
const args = input.input
|
||||
const subagentType = args.subagent_type
|
||||
if (typeof subagentType !== "string") return
|
||||
if (!TARGET_SUBAGENT_TYPES.includes(subagentType as (typeof TARGET_SUBAGENT_TYPES)[number])) return
|
||||
|
||||
if (typeof args.prompt === "string") {
|
||||
args.prompt = `${args.prompt}\n\n${ENGLISH_DIRECTIVE}`
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
import { describe, expect, it } from "bun:test"
|
||||
|
||||
import { createDelegateTaskEnglishDirectiveHook, ENGLISH_DIRECTIVE, TARGET_SUBAGENT_TYPES } from "./index"
|
||||
|
||||
describe("delegate-task-english-directive", () => {
|
||||
const hook = createDelegateTaskEnglishDirectiveHook()
|
||||
const handler = hook["tool.execute.before"]
|
||||
|
||||
describe("#given a task tool call with a targeted subagent_type", () => {
|
||||
const targetTypes = ["explore", "librarian", "oracle", "plan"]
|
||||
|
||||
for (const subagentType of targetTypes) {
|
||||
describe(`#when subagent_type is "${subagentType}"`, () => {
|
||||
it(`#then should append English directive to prompt`, async () => {
|
||||
const originalPrompt = "Find auth patterns in the codebase"
|
||||
const input = { tool: "Task", sessionID: "ses_123", callID: "call_1", input: { subagent_type: subagentType, prompt: originalPrompt } }
|
||||
const output = { title: "", output: "", metadata: undefined }
|
||||
|
||||
await handler(input, output)
|
||||
|
||||
expect(input.input.prompt).toBe(`${originalPrompt}\n\n${ENGLISH_DIRECTIVE}`)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
describe("#given a task tool call with a non-targeted subagent_type", () => {
|
||||
describe("#when subagent_type is 'metis'", () => {
|
||||
it("#then should not modify the prompt", async () => {
|
||||
const originalPrompt = "Analyze this request"
|
||||
const input = { tool: "Task", sessionID: "ses_123", callID: "call_1", input: { subagent_type: "metis", prompt: originalPrompt } }
|
||||
const output = { title: "", output: "", metadata: undefined }
|
||||
|
||||
await handler(input, output)
|
||||
|
||||
expect(input.input.prompt).toBe(originalPrompt)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given a task tool call using category instead of subagent_type", () => {
|
||||
describe("#when only category is provided", () => {
|
||||
it("#then should not modify the prompt", async () => {
|
||||
const originalPrompt = "Fix the button styling"
|
||||
const input = { tool: "Task", sessionID: "ses_123", callID: "call_1", input: { category: "visual-engineering", prompt: originalPrompt } }
|
||||
const output = { title: "", output: "", metadata: undefined }
|
||||
|
||||
await handler(input, output)
|
||||
|
||||
expect(input.input.prompt).toBe(originalPrompt)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given a non-task tool call", () => {
|
||||
describe("#when tool is 'Bash'", () => {
|
||||
it("#then should not modify anything", async () => {
|
||||
const input = { tool: "Bash", sessionID: "ses_123", callID: "call_1", input: { command: "ls" } }
|
||||
const output = { title: "", output: "", metadata: undefined }
|
||||
|
||||
await handler(input, output)
|
||||
|
||||
expect(input.input).toEqual({ command: "ls" })
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given a task tool call with empty prompt", () => {
|
||||
describe("#when prompt is empty string", () => {
|
||||
it("#then should still append directive", async () => {
|
||||
const input = { tool: "Task", sessionID: "ses_123", callID: "call_1", input: { subagent_type: "explore", prompt: "" } }
|
||||
const output = { title: "", output: "", metadata: undefined }
|
||||
|
||||
await handler(input, output)
|
||||
|
||||
expect(input.input.prompt).toBe(`\n\n${ENGLISH_DIRECTIVE}`)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given TARGET_SUBAGENT_TYPES constant", () => {
|
||||
it("#then should contain exactly explore, librarian, oracle, and plan", () => {
|
||||
expect(TARGET_SUBAGENT_TYPES).toEqual(["explore", "librarian", "oracle", "plan"])
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given ENGLISH_DIRECTIVE constant", () => {
|
||||
it("#then should be bold uppercase text", () => {
|
||||
expect(ENGLISH_DIRECTIVE).toContain("**")
|
||||
expect(ENGLISH_DIRECTIVE).toMatch(/[A-Z]/)
|
||||
})
|
||||
|
||||
it("#then should instruct English-only thinking and responding", () => {
|
||||
const lower = ENGLISH_DIRECTIVE.toLowerCase()
|
||||
expect(lower).toContain("english")
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1 +0,0 @@
|
||||
export { createDelegateTaskEnglishDirectiveHook, TARGET_SUBAGENT_TYPES, ENGLISH_DIRECTIVE } from "./hook"
|
||||
@@ -52,4 +52,3 @@ export { createWriteExistingFileGuardHook } from "./write-existing-file-guard";
|
||||
export { createHashlineReadEnhancerHook } from "./hashline-read-enhancer";
|
||||
export { createJsonErrorRecoveryHook, JSON_ERROR_TOOL_EXCLUDE_LIST, JSON_ERROR_PATTERNS, JSON_ERROR_REMINDER } from "./json-error-recovery";
|
||||
export { createReadImageResizerHook } from "./read-image-resizer"
|
||||
export { createDelegateTaskEnglishDirectiveHook } from "./delegate-task-english-directive"
|
||||
|
||||
Reference in New Issue
Block a user