Skip to content

Commit 90debb8

Browse files
committed
Revert "feat(prometheus-md-only): allow .md files anywhere, only block code files"
This reverts commit c600111.
1 parent c600111 commit 90debb8

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/hooks/prometheus-md-only/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe("prometheus-md-only", () => {
7979
).resolves.toBeUndefined()
8080
})
8181

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

100100
test("should block Edit tool for non-.md files", async () => {

src/hooks/prometheus-md-only/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import type { PluginInput } from "@opencode-ai/plugin"
22
import { existsSync, readdirSync } from "node:fs"
33
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"
55
import { findNearestMessageWithFields, MESSAGE_STORAGE } from "../../features/hook-message-injector"
66
import { log } from "../../shared/logger"
77

88
export * from "./constants"
99

1010
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
1214
}
1315

1416
function getMessageDir(sessionID: string): string | null {
@@ -71,20 +73,20 @@ export function createPrometheusMdOnlyHook(_ctx: PluginInput) {
7173
}
7274

7375
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`, {
7577
sessionID: input.sessionID,
7678
tool: toolName,
7779
filePath,
7880
agent: agentName,
7981
})
8082
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. ` +
8284
`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.`
8486
)
8587
}
8688

87-
log(`[${HOOK_NAME}] Allowed: *.md write permitted`, {
89+
log(`[${HOOK_NAME}] Allowed: .sisyphus/*.md write permitted`, {
8890
sessionID: input.sessionID,
8991
tool: toolName,
9092
filePath,

0 commit comments

Comments
 (0)