16170b7145
* refactor(shared): extract isCallerOrchestrator to session-utils * refactor(atlas): use shared isCallerOrchestrator, change to prepend * refactor(prometheus-md-only): change to prepend pattern * refactor(sisyphus-junior): remove Work_Context (moved to hook) * feat(hooks): add sisyphus-junior-notepad hook * fix(shared): replace dynamic require with static import in session-utils - Change from dynamic require to static import for better bundler compatibility - Fix import path: ../../features -> ../features - Add barrel export to src/shared/index.ts * feat(hooks): register sisyphus-junior-notepad hook - Add to HookNameSchema in schema.ts - Export from hooks/index.ts - Register with isHookEnabled in index.ts - Auto-generated schema.json update --------- Co-authored-by: justsisyphus <justsisyphus@users.noreply.github.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import type { PluginInput } from "@opencode-ai/plugin"
|
|
import { isCallerOrchestrator } from "../../shared/session-utils"
|
|
import { SYSTEM_DIRECTIVE_PREFIX } from "../../shared/system-directive"
|
|
import { log } from "../../shared/logger"
|
|
import { HOOK_NAME, NOTEPAD_DIRECTIVE } from "./constants"
|
|
|
|
export * from "./constants"
|
|
|
|
export function createSisyphusJuniorNotepadHook(ctx: PluginInput) {
|
|
return {
|
|
"tool.execute.before": async (
|
|
input: { tool: string; sessionID: string; callID: string },
|
|
output: { args: Record<string, unknown>; message?: string }
|
|
): Promise<void> => {
|
|
// 1. Check if tool is delegate_task
|
|
if (input.tool !== "delegate_task") {
|
|
return
|
|
}
|
|
|
|
// 2. Check if caller is Atlas (orchestrator)
|
|
if (!isCallerOrchestrator(input.sessionID)) {
|
|
return
|
|
}
|
|
|
|
// 3. Get prompt from output.args
|
|
const prompt = output.args.prompt as string | undefined
|
|
if (!prompt) {
|
|
return
|
|
}
|
|
|
|
// 4. Check for double injection
|
|
if (prompt.includes(SYSTEM_DIRECTIVE_PREFIX)) {
|
|
return
|
|
}
|
|
|
|
// 5. Prepend directive
|
|
output.args.prompt = NOTEPAD_DIRECTIVE + prompt
|
|
|
|
// 6. Log injection
|
|
log(`[${HOOK_NAME}] Injected notepad directive to delegate_task`, {
|
|
sessionID: input.sessionID,
|
|
})
|
|
},
|
|
}
|
|
}
|