feat(hooks): add sisyphus-junior-notepad hook for conditional notepad rules injection (#1092)
* 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>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
export const HOOK_NAME = "sisyphus-junior-notepad"
|
||||
|
||||
export const NOTEPAD_DIRECTIVE = `
|
||||
<Work_Context>
|
||||
## Notepad Location (for recording learnings)
|
||||
NOTEPAD PATH: .sisyphus/notepads/{plan-name}/
|
||||
- learnings.md: Record patterns, conventions, successful approaches
|
||||
- issues.md: Record problems, blockers, gotchas encountered
|
||||
- decisions.md: Record architectural choices and rationales
|
||||
- problems.md: Record unresolved issues, technical debt
|
||||
|
||||
You SHOULD append findings to notepad files after completing work.
|
||||
IMPORTANT: Always APPEND to notepad files - never overwrite or use Edit tool.
|
||||
|
||||
## Plan Location (READ ONLY)
|
||||
PLAN PATH: .sisyphus/plans/{plan-name}.md
|
||||
|
||||
CRITICAL RULE: NEVER MODIFY THE PLAN FILE
|
||||
|
||||
The plan file (.sisyphus/plans/*.md) is SACRED and READ-ONLY.
|
||||
- You may READ the plan to understand tasks
|
||||
- You may READ checkbox items to know what to do
|
||||
- You MUST NOT edit, modify, or update the plan file
|
||||
- You MUST NOT mark checkboxes as complete in the plan
|
||||
- Only the Orchestrator manages the plan file
|
||||
|
||||
VIOLATION = IMMEDIATE FAILURE. The Orchestrator tracks plan state.
|
||||
</Work_Context>
|
||||
`
|
||||
@@ -0,0 +1,45 @@
|
||||
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,
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user