Revert "feat(prometheus-md-only): allow .md files anywhere, only block code files"

This reverts commit c600111597591e1862696ee0b92051e587aa1a6b.
This commit is contained in:
YeonGyu-Kim 2026-01-09 00:41:45 +09:00
parent c600111597
commit 90debb8e97
2 changed files with 10 additions and 8 deletions

View File

@ -79,7 +79,7 @@ describe("prometheus-md-only", () => {
).resolves.toBeUndefined() ).resolves.toBeUndefined()
}) })
test("should allow Prometheus to write .md files anywhere", async () => { test("should block Prometheus from writing .md files outside .sisyphus/", async () => {
// #given // #given
const hook = createPrometheusMdOnlyHook(createMockPluginInput()) const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = { const input = {
@ -94,7 +94,7 @@ describe("prometheus-md-only", () => {
// #when / #then // #when / #then
await expect( await expect(
hook["tool.execute.before"](input, output) hook["tool.execute.before"](input, output)
).resolves.toBeUndefined() ).rejects.toThrow("can only write/edit .md files inside .sisyphus/")
}) })
test("should block Edit tool for non-.md files", async () => { test("should block Edit tool for non-.md files", async () => {

View File

@ -1,14 +1,16 @@
import type { PluginInput } from "@opencode-ai/plugin" import type { PluginInput } from "@opencode-ai/plugin"
import { existsSync, readdirSync } from "node:fs" import { existsSync, readdirSync } from "node:fs"
import { join } from "node:path" import { join } from "node:path"
import { HOOK_NAME, PROMETHEUS_AGENTS, ALLOWED_EXTENSIONS, BLOCKED_TOOLS, PLANNING_CONSULT_WARNING } from "./constants" import { HOOK_NAME, PROMETHEUS_AGENTS, ALLOWED_EXTENSIONS, ALLOWED_PATH_PREFIX, BLOCKED_TOOLS, PLANNING_CONSULT_WARNING } from "./constants"
import { findNearestMessageWithFields, MESSAGE_STORAGE } from "../../features/hook-message-injector" import { findNearestMessageWithFields, MESSAGE_STORAGE } from "../../features/hook-message-injector"
import { log } from "../../shared/logger" import { log } from "../../shared/logger"
export * from "./constants" export * from "./constants"
function isAllowedFile(filePath: string): boolean { function isAllowedFile(filePath: string): boolean {
return ALLOWED_EXTENSIONS.some(ext => filePath.endsWith(ext)) const hasAllowedExtension = ALLOWED_EXTENSIONS.some(ext => filePath.endsWith(ext))
const isInAllowedPath = filePath.includes(ALLOWED_PATH_PREFIX)
return hasAllowedExtension && isInAllowedPath
} }
function getMessageDir(sessionID: string): string | null { function getMessageDir(sessionID: string): string | null {
@ -71,20 +73,20 @@ export function createPrometheusMdOnlyHook(_ctx: PluginInput) {
} }
if (!isAllowedFile(filePath)) { if (!isAllowedFile(filePath)) {
log(`[${HOOK_NAME}] Blocked: Prometheus can only write *.md files`, { log(`[${HOOK_NAME}] Blocked: Prometheus can only write to .sisyphus/*.md`, {
sessionID: input.sessionID, sessionID: input.sessionID,
tool: toolName, tool: toolName,
filePath, filePath,
agent: agentName, agent: agentName,
}) })
throw new Error( throw new Error(
`[${HOOK_NAME}] Prometheus (Planner) can only write/edit .md files. ` + `[${HOOK_NAME}] Prometheus (Planner) can only write/edit .md files inside .sisyphus/ directory. ` +
`Attempted to modify: ${filePath}. ` + `Attempted to modify: ${filePath}. ` +
`Prometheus is a READ-ONLY planner for code. Use /start-work to execute the plan.` `Prometheus is a READ-ONLY planner. Use /start-work to execute the plan.`
) )
} }
log(`[${HOOK_NAME}] Allowed: *.md write permitted`, { log(`[${HOOK_NAME}] Allowed: .sisyphus/*.md write permitted`, {
sessionID: input.sessionID, sessionID: input.sessionID,
tool: toolName, tool: toolName,
filePath, filePath,