fix: respect disabled_tools config in agent prompts (fixes #2742)
- Check disabled_tools for 'question' in tool-config-handler permission logic - Strip Question tool code examples from Prometheus prompts when disabled - Pass disabled_tools through prometheus agent config builder pipeline - Add tests for disabled_tools question permission handling
This commit is contained in:
@@ -5,6 +5,7 @@ import type { OhMyOpenCodeConfig } from "../config"
|
||||
function createParams(overrides: {
|
||||
taskSystem?: boolean
|
||||
agents?: string[]
|
||||
disabledTools?: string[]
|
||||
}) {
|
||||
const agentResult: Record<string, { permission?: Record<string, unknown> }> = {}
|
||||
for (const agent of overrides.agents ?? []) {
|
||||
@@ -15,6 +16,7 @@ function createParams(overrides: {
|
||||
config: { tools: {}, permission: {} } as Record<string, unknown>,
|
||||
pluginConfig: {
|
||||
experimental: { task_system: overrides.taskSystem ?? false },
|
||||
disabled_tools: overrides.disabledTools,
|
||||
} as OhMyOpenCodeConfig,
|
||||
agentResult: agentResult as Record<string, unknown>,
|
||||
}
|
||||
@@ -183,4 +185,86 @@ describe("applyToolConfig", () => {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("#given disabled_tools includes 'question'", () => {
|
||||
let originalConfigContent: string | undefined
|
||||
let originalCliRunMode: string | undefined
|
||||
|
||||
beforeEach(() => {
|
||||
originalConfigContent = process.env.OPENCODE_CONFIG_CONTENT
|
||||
originalCliRunMode = process.env.OPENCODE_CLI_RUN_MODE
|
||||
delete process.env.OPENCODE_CONFIG_CONTENT
|
||||
delete process.env.OPENCODE_CLI_RUN_MODE
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
if (originalConfigContent === undefined) {
|
||||
delete process.env.OPENCODE_CONFIG_CONTENT
|
||||
} else {
|
||||
process.env.OPENCODE_CONFIG_CONTENT = originalConfigContent
|
||||
}
|
||||
if (originalCliRunMode === undefined) {
|
||||
delete process.env.OPENCODE_CLI_RUN_MODE
|
||||
} else {
|
||||
process.env.OPENCODE_CLI_RUN_MODE = originalCliRunMode
|
||||
}
|
||||
})
|
||||
|
||||
describe("#when question is in disabled_tools", () => {
|
||||
it.each(["sisyphus", "hephaestus", "prometheus"])(
|
||||
"#then should deny question for %s agent",
|
||||
(agentName) => {
|
||||
const params = createParams({
|
||||
agents: [agentName],
|
||||
disabledTools: ["question"],
|
||||
})
|
||||
|
||||
applyToolConfig(params)
|
||||
|
||||
const agent = params.agentResult[agentName] as {
|
||||
permission: Record<string, unknown>
|
||||
}
|
||||
expect(agent.permission.question).toBe("deny")
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
describe("#when question is in disabled_tools alongside other tools", () => {
|
||||
it.each(["sisyphus", "hephaestus", "prometheus"])(
|
||||
"#then should deny question for %s agent",
|
||||
(agentName) => {
|
||||
const params = createParams({
|
||||
agents: [agentName],
|
||||
disabledTools: ["todowrite", "question", "interactive_bash"],
|
||||
})
|
||||
|
||||
applyToolConfig(params)
|
||||
|
||||
const agent = params.agentResult[agentName] as {
|
||||
permission: Record<string, unknown>
|
||||
}
|
||||
expect(agent.permission.question).toBe("deny")
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
describe("#when disabled_tools does not include question", () => {
|
||||
it.each(["sisyphus", "hephaestus", "prometheus"])(
|
||||
"#then should allow question for %s agent",
|
||||
(agentName) => {
|
||||
const params = createParams({
|
||||
agents: [agentName],
|
||||
disabledTools: ["todowrite", "interactive_bash"],
|
||||
})
|
||||
|
||||
applyToolConfig(params)
|
||||
|
||||
const agent = params.agentResult[agentName] as {
|
||||
permission: Record<string, unknown>
|
||||
}
|
||||
expect(agent.permission.question).toBe("allow")
|
||||
},
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user