refactor: major codebase cleanup - BDD comments, file splitting, bug fixes (#1350)

* style(tests): normalize BDD comments from '// #given' to '// given'

- Replace 4,668 Python-style BDD comments across 107 test files
- Patterns changed: // #given -> // given, // #when -> // when, // #then -> // then
- Also handles no-space variants: //#given -> // given

* fix(rules-injector): prefer output.metadata.filePath over output.title

- Extract file path resolution to dedicated output-path.ts module
- Prefer metadata.filePath which contains actual file path
- Fall back to output.title only when metadata unavailable
- Fixes issue where rules weren't injected when tool output title was a label

* feat(slashcommand): add optional user_message parameter

- Add user_message optional parameter for command arguments
- Model can now call: command='publish' user_message='patch'
- Improves error messages with clearer format guidance
- Helps LLMs understand correct parameter usage

* feat(hooks): restore compaction-context-injector hook

- Restore hook deleted in cbbc7bd0 for session compaction context
- Injects 7 mandatory sections: User Requests, Final Goal, Work Completed,
  Remaining Tasks, Active Working Context, MUST NOT Do, Agent Verification State
- Re-register in hooks/index.ts and main plugin entry

* refactor(background-agent): split manager.ts into focused modules

- Extract constants.ts for TTL values and internal types (52 lines)
- Extract state.ts for TaskStateManager class (204 lines)
- Extract spawner.ts for task creation logic (244 lines)
- Extract result-handler.ts for completion handling (265 lines)
- Reduce manager.ts from 1377 to 755 lines (45% reduction)
- Maintain backward compatible exports

* refactor(agents): split prometheus-prompt.ts into subdirectory

- Move 1196-line prometheus-prompt.ts to prometheus/ subdirectory
- Organize prompt sections into separate files for maintainability
- Update agents/index.ts exports

* refactor(delegate-task): split tools.ts into focused modules

- Extract categories.ts for category definitions and routing
- Extract executor.ts for task execution logic
- Extract helpers.ts for utility functions
- Extract prompt-builder.ts for prompt construction
- Reduce tools.ts complexity with cleaner separation of concerns

* refactor(builtin-skills): split skills.ts into individual skill files

- Move each skill to dedicated file in skills/ subdirectory
- Create barrel export for backward compatibility
- Improve maintainability with focused skill modules

* chore: update import paths and lockfile

- Update prometheus import path after refactor
- Update bun.lock

* fix(tests): complete BDD comment normalization

- Fix remaining #when/#then patterns missed by initial sed
- Affected: state.test.ts, events.test.ts

---------

Co-authored-by: justsisyphus <justsisyphus@users.noreply.github.com>
This commit is contained in:
YeonGyu-Kim
2026-02-01 16:47:50 +09:00
committed by GitHub
parent c83150d9ea
commit f146aeff0f
145 changed files with 10307 additions and 9562 deletions
+57 -57
View File
@@ -47,7 +47,7 @@ describe("prometheus-md-only", () => {
})
test("should block Prometheus from writing non-.md files", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Write",
@@ -58,14 +58,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "/path/to/file.ts" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).rejects.toThrow("can only write/edit .md files")
})
test("should allow Prometheus to write .md files inside .sisyphus/", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Write",
@@ -76,14 +76,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "/tmp/test/.sisyphus/plans/work-plan.md" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should inject workflow reminder when Prometheus writes to .sisyphus/plans/", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Write",
@@ -94,10 +94,10 @@ describe("prometheus-md-only", () => {
args: { filePath: "/tmp/test/.sisyphus/plans/work-plan.md" },
}
// #when
// when
await hook["tool.execute.before"](input, output)
// #then
// then
expect(output.message).toContain("PROMETHEUS MANDATORY WORKFLOW REMINDER")
expect(output.message).toContain("INTERVIEW")
expect(output.message).toContain("METIS CONSULTATION")
@@ -105,7 +105,7 @@ describe("prometheus-md-only", () => {
})
test("should NOT inject workflow reminder for .sisyphus/drafts/", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Write",
@@ -116,15 +116,15 @@ describe("prometheus-md-only", () => {
args: { filePath: "/tmp/test/.sisyphus/drafts/notes.md" },
}
// #when
// when
await hook["tool.execute.before"](input, output)
// #then
// then
expect(output.message).toBeUndefined()
})
test("should block Prometheus from writing .md files outside .sisyphus/", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Write",
@@ -135,14 +135,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "/path/to/README.md" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).rejects.toThrow("can only write/edit .md files inside .sisyphus/")
})
test("should block Edit tool for non-.md files", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Edit",
@@ -153,14 +153,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "/path/to/code.py" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).rejects.toThrow("can only write/edit .md files")
})
test("should not affect non-Write/Edit tools", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Read",
@@ -171,14 +171,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "/path/to/file.ts" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should handle missing filePath gracefully", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Write",
@@ -189,14 +189,14 @@ describe("prometheus-md-only", () => {
args: {},
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should inject read-only warning when Prometheus calls delegate_task", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "delegate_task",
@@ -207,16 +207,16 @@ describe("prometheus-md-only", () => {
args: { prompt: "Analyze this codebase" },
}
// #when
// when
await hook["tool.execute.before"](input, output)
// #then
// then
expect(output.args.prompt).toContain(SYSTEM_DIRECTIVE_PREFIX)
expect(output.args.prompt).toContain("DO NOT modify any files")
})
test("should inject read-only warning when Prometheus calls task", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "task",
@@ -227,15 +227,15 @@ describe("prometheus-md-only", () => {
args: { prompt: "Research this library" },
}
// #when
// when
await hook["tool.execute.before"](input, output)
// #then
// then
expect(output.args.prompt).toContain(SYSTEM_DIRECTIVE_PREFIX)
})
test("should inject read-only warning when Prometheus calls call_omo_agent", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "call_omo_agent",
@@ -246,15 +246,15 @@ describe("prometheus-md-only", () => {
args: { prompt: "Find implementation examples" },
}
// #when
// when
await hook["tool.execute.before"](input, output)
// #then
// then
expect(output.args.prompt).toContain(SYSTEM_DIRECTIVE_PREFIX)
})
test("should not double-inject warning if already present", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "delegate_task",
@@ -266,10 +266,10 @@ describe("prometheus-md-only", () => {
args: { prompt: promptWithWarning },
}
// #when
// when
await hook["tool.execute.before"](input, output)
// #then
// then
const occurrences = (output.args.prompt as string).split(SYSTEM_DIRECTIVE_PREFIX).length - 1
expect(occurrences).toBe(1)
})
@@ -281,7 +281,7 @@ describe("prometheus-md-only", () => {
})
test("should not affect non-Prometheus agents", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Write",
@@ -292,14 +292,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "/path/to/file.ts" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should not inject warning for non-Prometheus agents calling delegate_task", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "delegate_task",
@@ -311,10 +311,10 @@ describe("prometheus-md-only", () => {
args: { prompt: originalPrompt },
}
// #when
// when
await hook["tool.execute.before"](input, output)
// #then
// then
expect(output.args.prompt).toBe(originalPrompt)
expect(output.args.prompt).not.toContain(SYSTEM_DIRECTIVE_PREFIX)
})
@@ -322,7 +322,7 @@ describe("prometheus-md-only", () => {
describe("without message storage", () => {
test("should handle missing session gracefully (no agent found)", async () => {
// #given
// given
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
tool: "Write",
@@ -333,7 +333,7 @@ describe("prometheus-md-only", () => {
args: { filePath: "/path/to/file.ts" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
@@ -346,7 +346,7 @@ describe("prometheus-md-only", () => {
})
test("should allow Windows-style backslash paths under .sisyphus/", async () => {
// #given
// given
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -358,14 +358,14 @@ describe("prometheus-md-only", () => {
args: { filePath: ".sisyphus\\plans\\work-plan.md" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should allow mixed separator paths under .sisyphus/", async () => {
// #given
// given
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -377,14 +377,14 @@ describe("prometheus-md-only", () => {
args: { filePath: ".sisyphus\\plans/work-plan.MD" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should allow uppercase .MD extension", async () => {
// #given
// given
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -396,14 +396,14 @@ describe("prometheus-md-only", () => {
args: { filePath: ".sisyphus/plans/work-plan.MD" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should block paths outside workspace root even if containing .sisyphus", async () => {
// #given
// given
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -415,14 +415,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "/other/project/.sisyphus/plans/x.md" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).rejects.toThrow("can only write/edit .md files inside .sisyphus/")
})
test("should allow nested .sisyphus directories (ctx.directory may be parent)", async () => {
// #given - when ctx.directory is parent of actual project, path includes project name
// given - when ctx.directory is parent of actual project, path includes project name
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -434,14 +434,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "src/.sisyphus/plans/x.md" },
}
// #when / #then - should allow because .sisyphus is in path
// when / #then - should allow because .sisyphus is in path
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should block path traversal attempts", async () => {
// #given
// given
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -453,14 +453,14 @@ describe("prometheus-md-only", () => {
args: { filePath: ".sisyphus/../secrets.md" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).rejects.toThrow("can only write/edit .md files inside .sisyphus/")
})
test("should allow case-insensitive .SISYPHUS directory", async () => {
// #given
// given
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -472,14 +472,14 @@ describe("prometheus-md-only", () => {
args: { filePath: ".SISYPHUS/plans/work-plan.md" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should allow nested project path with .sisyphus (Windows real-world case)", async () => {
// #given - simulates when ctx.directory is parent of actual project
// given - simulates when ctx.directory is parent of actual project
// User reported: xauusd-dxy-plan\.sisyphus\drafts\supabase-email-templates.md
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
@@ -492,14 +492,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "xauusd-dxy-plan\\.sisyphus\\drafts\\supabase-email-templates.md" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should allow nested project path with mixed separators", async () => {
// #given
// given
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -511,14 +511,14 @@ describe("prometheus-md-only", () => {
args: { filePath: "my-project/.sisyphus\\plans/task.md" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).resolves.toBeUndefined()
})
test("should block nested project path without .sisyphus", async () => {
// #given
// given
setupMessageStorage(TEST_SESSION_ID, "prometheus")
const hook = createPrometheusMdOnlyHook(createMockPluginInput())
const input = {
@@ -530,7 +530,7 @@ describe("prometheus-md-only", () => {
args: { filePath: "my-project\\src\\code.ts" },
}
// #when / #then
// when / #then
await expect(
hook["tool.execute.before"](input, output)
).rejects.toThrow("can only write/edit .md files")