2026-02-08 13:57:26 +09:00
import type { PluginInput } from "@opencode-ai/plugin"
2026-02-12 03:36:58 +09:00
import { HOOK_NAME , BLOCKED_TOOLS , PLANNING_CONSULT_WARNING , PROMETHEUS_WORKFLOW_REMINDER } from "./constants"
2026-02-08 13:57:26 +09:00
import { log } from "../../shared/logger"
import { SYSTEM_DIRECTIVE_PREFIX } from "../../shared/system-directive"
import { getAgentDisplayName } from "../../shared/agent-display-names"
import { getAgentFromSession } from "./agent-resolution"
2026-02-12 03:36:58 +09:00
import { isPrometheusAgent } from "./agent-matcher"
2026-02-08 13:57:26 +09:00
import { isAllowedFile } from "./path-policy"
const TASK_TOOLS = [ "task" , "call_omo_agent" ]
export function createPrometheusMdOnlyHook ( ctx : PluginInput ) {
return {
"tool.execute.before" : async (
input : { tool : string ; sessionID : string ; callID : string } ,
output : { args : Record < string , unknown > ; message? : string }
) : Promise < void > = > {
2026-02-15 14:56:58 +09:00
const agentName = await getAgentFromSession ( input . sessionID , ctx . directory , ctx . client )
2026-02-08 13:57:26 +09:00
2026-02-12 03:36:58 +09:00
if ( ! isPrometheusAgent ( agentName ) ) {
2026-02-08 13:57:26 +09:00
return
}
const toolName = input . tool
2026-03-23 18:07:59 +09:00
// Inject planning-only warning for task tools called by Prometheus
2026-02-08 13:57:26 +09:00
if ( TASK_TOOLS . includes ( toolName ) ) {
const prompt = output . args . prompt as string | undefined
if ( prompt && ! prompt . includes ( SYSTEM_DIRECTIVE_PREFIX ) ) {
output . args . prompt = PLANNING_CONSULT_WARNING + prompt
2026-03-23 18:07:59 +09:00
log ( ` [ ${ HOOK_NAME } ] Injected planning warning to ${ toolName } ` , {
2026-02-08 13:57:26 +09:00
sessionID : input.sessionID ,
tool : toolName ,
agent : agentName ,
} )
}
return
}
if ( ! BLOCKED_TOOLS . includes ( toolName ) ) {
return
}
const filePath = ( output . args . filePath ? ? output . args . path ? ? output . args . file ) as string | undefined
if ( ! filePath ) {
return
}
if ( ! isAllowedFile ( filePath , ctx . directory ) ) {
log ( ` [ ${ HOOK_NAME } ] Blocked: Prometheus can only write to .sisyphus/*.md ` , {
sessionID : input.sessionID ,
tool : toolName ,
filePath ,
agent : agentName ,
} )
throw new Error (
2026-03-23 18:07:59 +09:00
` [ ${ HOOK_NAME } ] Prometheus is a planning agent. File operations restricted to .sisyphus/*.md plan files only. Use task() to delegate implementation. ` +
2026-02-08 13:57:26 +09:00
` Attempted to modify: ${ filePath } . ` +
` APOLOGIZE TO THE USER, REMIND OF YOUR PLAN WRITING PROCESSES, TELL USER WHAT YOU WILL GOING TO DO AS THE PROCESS, WRITE THE PLAN `
)
}
const normalizedPath = filePath . toLowerCase ( ) . replace ( /\\/g , "/" )
if ( normalizedPath . includes ( ".sisyphus/plans/" ) || normalizedPath . includes ( ".sisyphus\\plans\\" ) ) {
log ( ` [ ${ HOOK_NAME } ] Injecting workflow reminder for plan write ` , {
sessionID : input.sessionID ,
tool : toolName ,
filePath ,
agent : agentName ,
} )
output . message = ( output . message || "" ) + PROMETHEUS_WORKFLOW_REMINDER
}
log ( ` [ ${ HOOK_NAME } ] Allowed: .sisyphus/*.md write permitted ` , {
sessionID : input.sessionID ,
tool : toolName ,
filePath ,
agent : agentName ,
} )
} ,
}
}