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:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user