|
1 | 1 | import type { PluginInput } from "@opencode-ai/plugin" |
2 | 2 | import { existsSync, readdirSync } from "node:fs" |
3 | 3 | import { join } from "node:path" |
4 | | -import { HOOK_NAME, PROMETHEUS_AGENTS, ALLOWED_EXTENSIONS, BLOCKED_TOOLS, PLANNING_CONSULT_WARNING } from "./constants" |
| 4 | +import { HOOK_NAME, PROMETHEUS_AGENTS, ALLOWED_EXTENSIONS, ALLOWED_PATH_PREFIX, BLOCKED_TOOLS, PLANNING_CONSULT_WARNING } from "./constants" |
5 | 5 | import { findNearestMessageWithFields, MESSAGE_STORAGE } from "../../features/hook-message-injector" |
6 | 6 | import { log } from "../../shared/logger" |
7 | 7 |
|
8 | 8 | export * from "./constants" |
9 | 9 |
|
10 | 10 | function isAllowedFile(filePath: string): boolean { |
11 | | - return ALLOWED_EXTENSIONS.some(ext => filePath.endsWith(ext)) |
| 11 | + const hasAllowedExtension = ALLOWED_EXTENSIONS.some(ext => filePath.endsWith(ext)) |
| 12 | + const isInAllowedPath = filePath.includes(ALLOWED_PATH_PREFIX) |
| 13 | + return hasAllowedExtension && isInAllowedPath |
12 | 14 | } |
13 | 15 |
|
14 | 16 | function getMessageDir(sessionID: string): string | null { |
@@ -71,20 +73,20 @@ export function createPrometheusMdOnlyHook(_ctx: PluginInput) { |
71 | 73 | } |
72 | 74 |
|
73 | 75 | if (!isAllowedFile(filePath)) { |
74 | | - log(`[${HOOK_NAME}] Blocked: Prometheus can only write *.md files`, { |
| 76 | + log(`[${HOOK_NAME}] Blocked: Prometheus can only write to .sisyphus/*.md`, { |
75 | 77 | sessionID: input.sessionID, |
76 | 78 | tool: toolName, |
77 | 79 | filePath, |
78 | 80 | agent: agentName, |
79 | 81 | }) |
80 | 82 | throw new Error( |
81 | | - `[${HOOK_NAME}] Prometheus (Planner) can only write/edit .md files. ` + |
| 83 | + `[${HOOK_NAME}] Prometheus (Planner) can only write/edit .md files inside .sisyphus/ directory. ` + |
82 | 84 | `Attempted to modify: ${filePath}. ` + |
83 | | - `Prometheus is a READ-ONLY planner for code. Use /start-work to execute the plan.` |
| 85 | + `Prometheus is a READ-ONLY planner. Use /start-work to execute the plan.` |
84 | 86 | ) |
85 | 87 | } |
86 | 88 |
|
87 | | - log(`[${HOOK_NAME}] Allowed: *.md write permitted`, { |
| 89 | + log(`[${HOOK_NAME}] Allowed: .sisyphus/*.md write permitted`, { |
88 | 90 | sessionID: input.sessionID, |
89 | 91 | tool: toolName, |
90 | 92 | filePath, |
|
0 commit comments