refactor: unify system directive prefix for keyword-detector filtering

- Add shared/system-directive.ts with SYSTEM_DIRECTIVE_PREFIX constant
- Unify all system message prefixes to [SYSTEM DIRECTIVE: OH-MY-OPENCODE - ...]
- Add isSystemDirective() filter to keyword-detector to skip system messages
- Update prometheus-md-only tests to use new prefix constants
This commit is contained in:
justsisyphus
2026-01-16 11:20:45 +09:00
parent b933992e36
commit c7ca608b38
11 changed files with 74 additions and 17 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
import { createSystemDirective, SystemDirectiveTypes } from "../../shared/system-directive"
export const HOOK_NAME = "prometheus-md-only"
export const PROMETHEUS_AGENTS = ["Prometheus (Planner)"]
@@ -12,7 +14,7 @@ export const PLANNING_CONSULT_WARNING = `
---
[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]
${createSystemDirective(SystemDirectiveTypes.PROMETHEUS_READ_ONLY)}
You are being invoked by Prometheus (Planner), a READ-ONLY planning agent.
+7 -6
View File
@@ -3,6 +3,7 @@ import { mkdirSync, rmSync, writeFileSync } from "node:fs"
import { join } from "node:path"
import { createPrometheusMdOnlyHook } from "./index"
import { MESSAGE_STORAGE } from "../../features/hook-message-injector"
import { SYSTEM_DIRECTIVE_PREFIX, createSystemDirective, SystemDirectiveTypes } from "../../shared/system-directive"
describe("prometheus-md-only", () => {
const TEST_SESSION_ID = "test-session-prometheus"
@@ -167,7 +168,7 @@ describe("prometheus-md-only", () => {
await hook["tool.execute.before"](input, output)
// #then
expect(output.args.prompt).toContain("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")
expect(output.args.prompt).toContain(SYSTEM_DIRECTIVE_PREFIX)
expect(output.args.prompt).toContain("DO NOT modify any files")
})
@@ -187,7 +188,7 @@ describe("prometheus-md-only", () => {
await hook["tool.execute.before"](input, output)
// #then
expect(output.args.prompt).toContain("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")
expect(output.args.prompt).toContain(SYSTEM_DIRECTIVE_PREFIX)
})
test("should inject read-only warning when Prometheus calls call_omo_agent", async () => {
@@ -206,7 +207,7 @@ describe("prometheus-md-only", () => {
await hook["tool.execute.before"](input, output)
// #then
expect(output.args.prompt).toContain("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")
expect(output.args.prompt).toContain(SYSTEM_DIRECTIVE_PREFIX)
})
test("should not double-inject warning if already present", async () => {
@@ -217,7 +218,7 @@ describe("prometheus-md-only", () => {
sessionID: TEST_SESSION_ID,
callID: "call-1",
}
const promptWithWarning = "Some prompt [SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION] already here"
const promptWithWarning = `Some prompt ${SYSTEM_DIRECTIVE_PREFIX} already here`
const output = {
args: { prompt: promptWithWarning },
}
@@ -226,7 +227,7 @@ describe("prometheus-md-only", () => {
await hook["tool.execute.before"](input, output)
// #then
const occurrences = (output.args.prompt as string).split("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]").length - 1
const occurrences = (output.args.prompt as string).split(SYSTEM_DIRECTIVE_PREFIX).length - 1
expect(occurrences).toBe(1)
})
})
@@ -272,7 +273,7 @@ describe("prometheus-md-only", () => {
// #then
expect(output.args.prompt).toBe(originalPrompt)
expect(output.args.prompt).not.toContain("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")
expect(output.args.prompt).not.toContain(SYSTEM_DIRECTIVE_PREFIX)
})
})
+2 -1
View File
@@ -5,6 +5,7 @@ import { HOOK_NAME, PROMETHEUS_AGENTS, ALLOWED_EXTENSIONS, ALLOWED_PATH_PREFIX,
import { findNearestMessageWithFields, findFirstMessageWithAgent, MESSAGE_STORAGE } from "../../features/hook-message-injector"
import { getSessionAgent } from "../../features/claude-code-session-state"
import { log } from "../../shared/logger"
import { SYSTEM_DIRECTIVE_PREFIX } from "../../shared/system-directive"
export * from "./constants"
@@ -89,7 +90,7 @@ export function createPrometheusMdOnlyHook(ctx: PluginInput) {
// Inject read-only warning for task tools called by Prometheus
if (TASK_TOOLS.includes(toolName)) {
const prompt = output.args.prompt as string | undefined
if (prompt && !prompt.includes("[SYSTEM DIRECTIVE - READ-ONLY PLANNING CONSULTATION]")) {
if (prompt && !prompt.includes(SYSTEM_DIRECTIVE_PREFIX)) {
output.args.prompt = prompt + PLANNING_CONSULT_WARNING
log(`[${HOOK_NAME}] Injected read-only planning warning to ${toolName}`, {
sessionID: input.sessionID,