b58f3edf6d
Replace PreToolUse hook-based question tool blocking with the existing
tools parameter approach (tools: { question: false }) which physically
removes the tool from the LLM's toolset before inference.
The hook was redundant because every session.prompt() call already passes
question: false via the tools parameter. OpenCode converts this to a
PermissionNext deny rule and deletes the tool from the toolset, preventing
the LLM from even seeing it. The hook only fired after the LLM already
called the tool, wasting tokens.
Changes:
- Remove subagent-question-blocker hook invocation from PreToolUse chain
- Remove hook registration from create-session-hooks.ts
- Delete src/hooks/subagent-question-blocker/ directory (dead code)
- Remove hook from HookNameSchema and barrel export
- Fix sync-executor.ts missing question: false in tools parameter
- Add regression tests for both the removal and the tools parameter
163 lines
3.7 KiB
TypeScript
163 lines
3.7 KiB
TypeScript
const { describe, test, expect, mock } = require("bun:test")
|
|
|
|
describe("sendSyncPrompt", () => {
|
|
test("passes question=false via tools parameter", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = mock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "sisyphus-junior",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient as any, input)
|
|
|
|
//#then
|
|
expect(promptAsync).toHaveBeenCalled()
|
|
expect(promptArgs.body.tools.question).toBe(false)
|
|
})
|
|
|
|
test("applies agent tool restrictions for explore agent", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = mock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "explore",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
category: "quick",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient as any, input)
|
|
|
|
//#then
|
|
expect(promptAsync).toHaveBeenCalled()
|
|
expect(promptArgs.body.tools.call_omo_agent).toBe(false)
|
|
})
|
|
|
|
test("applies agent tool restrictions for librarian agent", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = mock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "librarian",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
category: "quick",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient as any, input)
|
|
|
|
//#then
|
|
expect(promptAsync).toHaveBeenCalled()
|
|
expect(promptArgs.body.tools.call_omo_agent).toBe(false)
|
|
})
|
|
|
|
test("does not restrict call_omo_agent for sisyphus agent", async () => {
|
|
//#given
|
|
const { sendSyncPrompt } = require("./sync-prompt-sender")
|
|
|
|
let promptArgs: any
|
|
const promptAsync = mock(async (input: any) => {
|
|
promptArgs = input
|
|
return { data: {} }
|
|
})
|
|
|
|
const mockClient = {
|
|
session: {
|
|
promptAsync,
|
|
},
|
|
}
|
|
|
|
const input = {
|
|
sessionID: "test-session",
|
|
agentToUse: "sisyphus",
|
|
args: {
|
|
description: "test task",
|
|
prompt: "test prompt",
|
|
category: "quick",
|
|
run_in_background: false,
|
|
load_skills: [],
|
|
},
|
|
systemContent: undefined,
|
|
categoryModel: undefined,
|
|
toastManager: null,
|
|
taskId: undefined,
|
|
}
|
|
|
|
//#when
|
|
await sendSyncPrompt(mockClient as any, input)
|
|
|
|
//#then
|
|
expect(promptAsync).toHaveBeenCalled()
|
|
expect(promptArgs.body.tools.call_omo_agent).toBe(true)
|
|
})
|
|
})
|