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
+45 -45
View File
@@ -31,19 +31,19 @@ describe("category-skill-reminder hook", () => {
describe("target agent detection", () => {
test("should inject reminder for sisyphus agent after 3 tool calls", async () => {
// #given - sisyphus agent session with multiple tool calls
// given - sisyphus agent session with multiple tool calls
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "sisyphus-session"
updateSessionAgent(sessionID, "Sisyphus")
const output = { title: "", output: "file content", metadata: {} }
// #when - 3 edit tool calls are made
// when - 3 edit tool calls are made
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output)
// #then - reminder should be injected
// then - reminder should be injected
expect(output.output).toContain("[Category+Skill Reminder]")
expect(output.output).toContain("delegate_task")
@@ -51,135 +51,135 @@ describe("category-skill-reminder hook", () => {
})
test("should inject reminder for atlas agent", async () => {
// #given - atlas agent session
// given - atlas agent session
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "atlas-session"
updateSessionAgent(sessionID, "Atlas")
const output = { title: "", output: "result", metadata: {} }
// #when - 3 tool calls are made
// when - 3 tool calls are made
await hook["tool.execute.after"]({ tool: "bash", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "bash", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "bash", sessionID, callID: "3" }, output)
// #then - reminder should be injected
// then - reminder should be injected
expect(output.output).toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
})
test("should inject reminder for sisyphus-junior agent", async () => {
// #given - sisyphus-junior agent session
// given - sisyphus-junior agent session
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "junior-session"
updateSessionAgent(sessionID, "sisyphus-junior")
const output = { title: "", output: "result", metadata: {} }
// #when - 3 tool calls are made
// when - 3 tool calls are made
await hook["tool.execute.after"]({ tool: "write", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "write", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "write", sessionID, callID: "3" }, output)
// #then - reminder should be injected
// then - reminder should be injected
expect(output.output).toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
})
test("should NOT inject reminder for non-target agents", async () => {
// #given - librarian agent session (not a target)
// given - librarian agent session (not a target)
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "librarian-session"
updateSessionAgent(sessionID, "librarian")
const output = { title: "", output: "result", metadata: {} }
// #when - 3 tool calls are made
// when - 3 tool calls are made
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output)
// #then - reminder should NOT be injected
// then - reminder should NOT be injected
expect(output.output).not.toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
})
test("should detect agent from input.agent when session state is empty", async () => {
// #given - no session state, agent provided in input
// given - no session state, agent provided in input
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "input-agent-session"
const output = { title: "", output: "result", metadata: {} }
// #when - 3 tool calls with agent in input
// when - 3 tool calls with agent in input
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "1", agent: "Sisyphus" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2", agent: "Sisyphus" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3", agent: "Sisyphus" }, output)
// #then - reminder should be injected
// then - reminder should be injected
expect(output.output).toContain("[Category+Skill Reminder]")
})
})
describe("delegation tool tracking", () => {
test("should NOT inject reminder if delegate_task is used", async () => {
// #given - sisyphus agent that uses delegate_task
// given - sisyphus agent that uses delegate_task
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "delegation-session"
updateSessionAgent(sessionID, "Sisyphus")
const output = { title: "", output: "result", metadata: {} }
// #when - delegate_task is used, then more tool calls
// when - delegate_task is used, then more tool calls
await hook["tool.execute.after"]({ tool: "delegate_task", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "4" }, output)
// #then - reminder should NOT be injected (delegation was used)
// then - reminder should NOT be injected (delegation was used)
expect(output.output).not.toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
})
test("should NOT inject reminder if call_omo_agent is used", async () => {
// #given - sisyphus agent that uses call_omo_agent
// given - sisyphus agent that uses call_omo_agent
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "omo-agent-session"
updateSessionAgent(sessionID, "Sisyphus")
const output = { title: "", output: "result", metadata: {} }
// #when - call_omo_agent is used first
// when - call_omo_agent is used first
await hook["tool.execute.after"]({ tool: "call_omo_agent", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "4" }, output)
// #then - reminder should NOT be injected
// then - reminder should NOT be injected
expect(output.output).not.toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
})
test("should NOT inject reminder if task tool is used", async () => {
// #given - sisyphus agent that uses task tool
// given - sisyphus agent that uses task tool
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "task-session"
updateSessionAgent(sessionID, "Sisyphus")
const output = { title: "", output: "result", metadata: {} }
// #when - task tool is used
// when - task tool is used
await hook["tool.execute.after"]({ tool: "task", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "4" }, output)
// #then - reminder should NOT be injected
// then - reminder should NOT be injected
expect(output.output).not.toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
@@ -188,25 +188,25 @@ describe("category-skill-reminder hook", () => {
describe("tool call counting", () => {
test("should NOT inject reminder before 3 tool calls", async () => {
// #given - sisyphus agent with only 2 tool calls
// given - sisyphus agent with only 2 tool calls
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "few-calls-session"
updateSessionAgent(sessionID, "Sisyphus")
const output = { title: "", output: "result", metadata: {} }
// #when - only 2 tool calls are made
// when - only 2 tool calls are made
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2" }, output)
// #then - reminder should NOT be injected yet
// then - reminder should NOT be injected yet
expect(output.output).not.toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
})
test("should only inject reminder once per session", async () => {
// #given - sisyphus agent session
// given - sisyphus agent session
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "once-session"
updateSessionAgent(sessionID, "Sisyphus")
@@ -214,7 +214,7 @@ describe("category-skill-reminder hook", () => {
const output1 = { title: "", output: "result1", metadata: {} }
const output2 = { title: "", output: "result2", metadata: {} }
// #when - 6 tool calls are made (should trigger at 3, not again at 6)
// when - 6 tool calls are made (should trigger at 3, not again at 6)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "1" }, output1)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2" }, output1)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output1)
@@ -222,7 +222,7 @@ describe("category-skill-reminder hook", () => {
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "5" }, output2)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "6" }, output2)
// #then - reminder should be in output1 but not output2
// then - reminder should be in output1 but not output2
expect(output1.output).toContain("[Category+Skill Reminder]")
expect(output2.output).not.toContain("[Category+Skill Reminder]")
@@ -230,19 +230,19 @@ describe("category-skill-reminder hook", () => {
})
test("should only count delegatable work tools", async () => {
// #given - sisyphus agent with mixed tool calls
// given - sisyphus agent with mixed tool calls
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "mixed-tools-session"
updateSessionAgent(sessionID, "Sisyphus")
const output = { title: "", output: "result", metadata: {} }
// #when - non-delegatable tools are called (should not count)
// when - non-delegatable tools are called (should not count)
await hook["tool.execute.after"]({ tool: "lsp_goto_definition", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "lsp_find_references", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "lsp_symbols", sessionID, callID: "3" }, output)
// #then - reminder should NOT be injected (LSP tools don't count)
// then - reminder should NOT be injected (LSP tools don't count)
expect(output.output).not.toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
@@ -251,7 +251,7 @@ describe("category-skill-reminder hook", () => {
describe("event handling", () => {
test("should reset state on session.deleted event", async () => {
// #given - sisyphus agent with reminder already shown
// given - sisyphus agent with reminder already shown
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "delete-session"
updateSessionAgent(sessionID, "Sisyphus")
@@ -262,7 +262,7 @@ describe("category-skill-reminder hook", () => {
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output1)
expect(output1.output).toContain("[Category+Skill Reminder]")
// #when - session is deleted and new session starts
// when - session is deleted and new session starts
await hook.event({ event: { type: "session.deleted", properties: { info: { id: sessionID } } } })
const output2 = { title: "", output: "result2", metadata: {} }
@@ -270,14 +270,14 @@ describe("category-skill-reminder hook", () => {
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "5" }, output2)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "6" }, output2)
// #then - reminder should be shown again (state was reset)
// then - reminder should be shown again (state was reset)
expect(output2.output).toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
})
test("should reset state on session.compacted event", async () => {
// #given - sisyphus agent with reminder already shown
// given - sisyphus agent with reminder already shown
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "compact-session"
updateSessionAgent(sessionID, "Sisyphus")
@@ -288,7 +288,7 @@ describe("category-skill-reminder hook", () => {
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output1)
expect(output1.output).toContain("[Category+Skill Reminder]")
// #when - session is compacted
// when - session is compacted
await hook.event({ event: { type: "session.compacted", properties: { sessionID } } })
const output2 = { title: "", output: "result2", metadata: {} }
@@ -296,7 +296,7 @@ describe("category-skill-reminder hook", () => {
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "5" }, output2)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "6" }, output2)
// #then - reminder should be shown again (state was reset)
// then - reminder should be shown again (state was reset)
expect(output2.output).toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
@@ -305,39 +305,39 @@ describe("category-skill-reminder hook", () => {
describe("case insensitivity", () => {
test("should handle tool names case-insensitively", async () => {
// #given - sisyphus agent with mixed case tool names
// given - sisyphus agent with mixed case tool names
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "case-session"
updateSessionAgent(sessionID, "Sisyphus")
const output = { title: "", output: "result", metadata: {} }
// #when - tool calls with different cases
// when - tool calls with different cases
await hook["tool.execute.after"]({ tool: "EDIT", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "Edit", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output)
// #then - reminder should be injected (all counted)
// then - reminder should be injected (all counted)
expect(output.output).toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)
})
test("should handle delegation tool names case-insensitively", async () => {
// #given - sisyphus agent using DELEGATE_TASK in uppercase
// given - sisyphus agent using DELEGATE_TASK in uppercase
const hook = createCategorySkillReminderHook(createMockPluginInput())
const sessionID = "case-delegate-session"
updateSessionAgent(sessionID, "Sisyphus")
const output = { title: "", output: "result", metadata: {} }
// #when - DELEGATE_TASK in uppercase is used
// when - DELEGATE_TASK in uppercase is used
await hook["tool.execute.after"]({ tool: "DELEGATE_TASK", sessionID, callID: "1" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "2" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "3" }, output)
await hook["tool.execute.after"]({ tool: "edit", sessionID, callID: "4" }, output)
// #then - reminder should NOT be injected (delegation was detected)
// then - reminder should NOT be injected (delegation was detected)
expect(output.output).not.toContain("[Category+Skill Reminder]")
clearSessionAgent(sessionID)