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

View File

@@ -3,55 +3,55 @@ import { resolveSkillContent, resolveMultipleSkills, resolveSkillContentAsync, r
describe("resolveSkillContent", () => {
it("should return template for existing skill", () => {
// #given: builtin skills with 'frontend-ui-ux' skill
// #when: resolving content for 'frontend-ui-ux'
// given: builtin skills with 'frontend-ui-ux' skill
// when: resolving content for 'frontend-ui-ux'
const result = resolveSkillContent("frontend-ui-ux")
// #then: returns template string
// then: returns template string
expect(result).not.toBeNull()
expect(typeof result).toBe("string")
expect(result).toContain("Role: Designer-Turned-Developer")
})
it("should return template for 'playwright' skill", () => {
// #given: builtin skills with 'playwright' skill
// #when: resolving content for 'playwright'
// given: builtin skills with 'playwright' skill
// when: resolving content for 'playwright'
const result = resolveSkillContent("playwright")
// #then: returns template string
// then: returns template string
expect(result).not.toBeNull()
expect(typeof result).toBe("string")
expect(result).toContain("Playwright Browser Automation")
})
it("should return null for non-existent skill", () => {
// #given: builtin skills without 'nonexistent' skill
// #when: resolving content for 'nonexistent'
// given: builtin skills without 'nonexistent' skill
// when: resolving content for 'nonexistent'
const result = resolveSkillContent("nonexistent")
// #then: returns null
// then: returns null
expect(result).toBeNull()
})
it("should return null for empty string", () => {
// #given: builtin skills
// #when: resolving content for empty string
// given: builtin skills
// when: resolving content for empty string
const result = resolveSkillContent("")
// #then: returns null
// then: returns null
expect(result).toBeNull()
})
})
describe("resolveMultipleSkills", () => {
it("should resolve all existing skills", () => {
// #given: list of existing skill names
// given: list of existing skill names
const skillNames = ["frontend-ui-ux", "playwright"]
// #when: resolving multiple skills
// when: resolving multiple skills
const result = resolveMultipleSkills(skillNames)
// #then: all skills resolved, none not found
// then: all skills resolved, none not found
expect(result.resolved.size).toBe(2)
expect(result.notFound).toEqual([])
expect(result.resolved.get("frontend-ui-ux")).toContain("Designer-Turned-Developer")
@@ -59,13 +59,13 @@ describe("resolveMultipleSkills", () => {
})
it("should handle partial success - some skills not found", () => {
// #given: list with existing and non-existing skills
// given: list with existing and non-existing skills
const skillNames = ["frontend-ui-ux", "nonexistent", "playwright", "another-missing"]
// #when: resolving multiple skills
// when: resolving multiple skills
const result = resolveMultipleSkills(skillNames)
// #then: resolves existing skills, lists not found skills
// then: resolves existing skills, lists not found skills
expect(result.resolved.size).toBe(2)
expect(result.notFound).toEqual(["nonexistent", "another-missing"])
expect(result.resolved.get("frontend-ui-ux")).toContain("Designer-Turned-Developer")
@@ -73,37 +73,37 @@ describe("resolveMultipleSkills", () => {
})
it("should handle empty array", () => {
// #given: empty skill names list
// given: empty skill names list
const skillNames: string[] = []
// #when: resolving multiple skills
// when: resolving multiple skills
const result = resolveMultipleSkills(skillNames)
// #then: returns empty resolved and notFound
// then: returns empty resolved and notFound
expect(result.resolved.size).toBe(0)
expect(result.notFound).toEqual([])
})
it("should handle all skills not found", () => {
// #given: list of non-existing skills
// given: list of non-existing skills
const skillNames = ["skill-one", "skill-two", "skill-three"]
// #when: resolving multiple skills
// when: resolving multiple skills
const result = resolveMultipleSkills(skillNames)
// #then: no skills resolved, all in notFound
// then: no skills resolved, all in notFound
expect(result.resolved.size).toBe(0)
expect(result.notFound).toEqual(["skill-one", "skill-two", "skill-three"])
})
it("should preserve skill order in resolved map", () => {
// #given: list of skill names in specific order
// given: list of skill names in specific order
const skillNames = ["playwright", "frontend-ui-ux"]
// #when: resolving multiple skills
// when: resolving multiple skills
const result = resolveMultipleSkills(skillNames)
// #then: map contains skills with expected keys
// then: map contains skills with expected keys
expect(result.resolved.has("playwright")).toBe(true)
expect(result.resolved.has("frontend-ui-ux")).toBe(true)
expect(result.resolved.size).toBe(2)
@@ -112,35 +112,35 @@ describe("resolveMultipleSkills", () => {
describe("resolveSkillContentAsync", () => {
it("should return template for builtin skill", async () => {
// #given: builtin skill 'frontend-ui-ux'
// #when: resolving content async
// given: builtin skill 'frontend-ui-ux'
// when: resolving content async
const result = await resolveSkillContentAsync("frontend-ui-ux")
// #then: returns template string
// then: returns template string
expect(result).not.toBeNull()
expect(typeof result).toBe("string")
expect(result).toContain("Role: Designer-Turned-Developer")
})
it("should return null for non-existent skill", async () => {
// #given: non-existent skill name
// #when: resolving content async
// given: non-existent skill name
// when: resolving content async
const result = await resolveSkillContentAsync("definitely-not-a-skill-12345")
// #then: returns null
// then: returns null
expect(result).toBeNull()
})
})
describe("resolveMultipleSkillsAsync", () => {
it("should resolve builtin skills", async () => {
// #given: builtin skill names
// given: builtin skill names
const skillNames = ["playwright", "frontend-ui-ux"]
// #when: resolving multiple skills async
// when: resolving multiple skills async
const result = await resolveMultipleSkillsAsync(skillNames)
// #then: all builtin skills resolved
// then: all builtin skills resolved
expect(result.resolved.size).toBe(2)
expect(result.notFound).toEqual([])
expect(result.resolved.get("playwright")).toContain("Playwright Browser Automation")
@@ -148,20 +148,20 @@ describe("resolveMultipleSkillsAsync", () => {
})
it("should handle partial success with non-existent skills", async () => {
// #given: mix of existing and non-existing skills
// given: mix of existing and non-existing skills
const skillNames = ["playwright", "nonexistent-skill-12345"]
// #when: resolving multiple skills async
// when: resolving multiple skills async
const result = await resolveMultipleSkillsAsync(skillNames)
// #then: existing skills resolved, non-existing in notFound
// then: existing skills resolved, non-existing in notFound
expect(result.resolved.size).toBe(1)
expect(result.notFound).toEqual(["nonexistent-skill-12345"])
expect(result.resolved.get("playwright")).toContain("Playwright Browser Automation")
})
it("should NOT inject watermark when both options are disabled", async () => {
// #given: git-master skill with watermark disabled
// given: git-master skill with watermark disabled
const skillNames = ["git-master"]
const options = {
gitMasterConfig: {
@@ -170,10 +170,10 @@ describe("resolveMultipleSkillsAsync", () => {
},
}
// #when: resolving with git-master config
// when: resolving with git-master config
const result = await resolveMultipleSkillsAsync(skillNames, options)
// #then: no watermark section injected
// then: no watermark section injected
expect(result.resolved.size).toBe(1)
expect(result.notFound).toEqual([])
const gitMasterContent = result.resolved.get("git-master")
@@ -182,7 +182,7 @@ describe("resolveMultipleSkillsAsync", () => {
})
it("should inject watermark when enabled (default)", async () => {
// #given: git-master skill with default config (watermark enabled)
// given: git-master skill with default config (watermark enabled)
const skillNames = ["git-master"]
const options = {
gitMasterConfig: {
@@ -191,10 +191,10 @@ describe("resolveMultipleSkillsAsync", () => {
},
}
// #when: resolving with git-master config
// when: resolving with git-master config
const result = await resolveMultipleSkillsAsync(skillNames, options)
// #then: watermark section is injected
// then: watermark section is injected
expect(result.resolved.size).toBe(1)
const gitMasterContent = result.resolved.get("git-master")
expect(gitMasterContent).toContain("Ultraworked with [Sisyphus]")
@@ -202,7 +202,7 @@ describe("resolveMultipleSkillsAsync", () => {
})
it("should inject only footer when co-author is disabled", async () => {
// #given: git-master skill with only footer enabled
// given: git-master skill with only footer enabled
const skillNames = ["git-master"]
const options = {
gitMasterConfig: {
@@ -211,23 +211,23 @@ describe("resolveMultipleSkillsAsync", () => {
},
}
// #when: resolving with git-master config
// when: resolving with git-master config
const result = await resolveMultipleSkillsAsync(skillNames, options)
// #then: only footer is injected
// then: only footer is injected
const gitMasterContent = result.resolved.get("git-master")
expect(gitMasterContent).toContain("Ultraworked with [Sisyphus]")
expect(gitMasterContent).not.toContain("Co-authored-by: Sisyphus")
})
it("should inject watermark by default when no config provided", async () => {
// #given: git-master skill with NO config (default behavior)
// given: git-master skill with NO config (default behavior)
const skillNames = ["git-master"]
// #when: resolving without any gitMasterConfig
// when: resolving without any gitMasterConfig
const result = await resolveMultipleSkillsAsync(skillNames)
// #then: watermark is injected (default is ON)
// then: watermark is injected (default is ON)
expect(result.resolved.size).toBe(1)
const gitMasterContent = result.resolved.get("git-master")
expect(gitMasterContent).toContain("Ultraworked with [Sisyphus]")
@@ -235,7 +235,7 @@ describe("resolveMultipleSkillsAsync", () => {
})
it("should inject only co-author when footer is disabled", async () => {
// #given: git-master skill with only co-author enabled
// given: git-master skill with only co-author enabled
const skillNames = ["git-master"]
const options = {
gitMasterConfig: {
@@ -244,23 +244,23 @@ describe("resolveMultipleSkillsAsync", () => {
},
}
// #when: resolving with git-master config
// when: resolving with git-master config
const result = await resolveMultipleSkillsAsync(skillNames, options)
// #then: only co-author is injected
// then: only co-author is injected
const gitMasterContent = result.resolved.get("git-master")
expect(gitMasterContent).not.toContain("Ultraworked with [Sisyphus]")
expect(gitMasterContent).toContain("Co-authored-by: Sisyphus")
})
it("should handle empty array", async () => {
// #given: empty skill names
// given: empty skill names
const skillNames: string[] = []
// #when: resolving multiple skills async
// when: resolving multiple skills async
const result = await resolveMultipleSkillsAsync(skillNames)
// #then: empty results
// then: empty results
expect(result.resolved.size).toBe(0)
expect(result.notFound).toEqual([])
})
@@ -268,62 +268,62 @@ describe("resolveMultipleSkillsAsync", () => {
describe("resolveSkillContent with browserProvider", () => {
it("should resolve agent-browser skill when browserProvider is 'agent-browser'", () => {
// #given: browserProvider set to agent-browser
// given: browserProvider set to agent-browser
const options = { browserProvider: "agent-browser" as const }
// #when: resolving content for 'agent-browser'
// when: resolving content for 'agent-browser'
const result = resolveSkillContent("agent-browser", options)
// #then: returns agent-browser template
// then: returns agent-browser template
expect(result).not.toBeNull()
expect(result).toContain("agent-browser")
})
it("should return null for agent-browser when browserProvider is default", () => {
// #given: no browserProvider (defaults to playwright)
// given: no browserProvider (defaults to playwright)
// #when: resolving content for 'agent-browser'
// when: resolving content for 'agent-browser'
const result = resolveSkillContent("agent-browser")
// #then: returns null because agent-browser is not in default builtin skills
// then: returns null because agent-browser is not in default builtin skills
expect(result).toBeNull()
})
it("should return null for playwright when browserProvider is agent-browser", () => {
// #given: browserProvider set to agent-browser
// given: browserProvider set to agent-browser
const options = { browserProvider: "agent-browser" as const }
// #when: resolving content for 'playwright'
// when: resolving content for 'playwright'
const result = resolveSkillContent("playwright", options)
// #then: returns null because playwright is replaced by agent-browser
// then: returns null because playwright is replaced by agent-browser
expect(result).toBeNull()
})
})
describe("resolveMultipleSkills with browserProvider", () => {
it("should resolve agent-browser when browserProvider is set", () => {
// #given: agent-browser and git-master requested with browserProvider
// given: agent-browser and git-master requested with browserProvider
const skillNames = ["agent-browser", "git-master"]
const options = { browserProvider: "agent-browser" as const }
// #when: resolving multiple skills
// when: resolving multiple skills
const result = resolveMultipleSkills(skillNames, options)
// #then: both resolved
// then: both resolved
expect(result.resolved.has("agent-browser")).toBe(true)
expect(result.resolved.has("git-master")).toBe(true)
expect(result.notFound).toHaveLength(0)
})
it("should not resolve agent-browser without browserProvider option", () => {
// #given: agent-browser requested without browserProvider
// given: agent-browser requested without browserProvider
const skillNames = ["agent-browser"]
// #when: resolving multiple skills
// when: resolving multiple skills
const result = resolveMultipleSkills(skillNames)
// #then: agent-browser not found
// then: agent-browser not found
expect(result.resolved.has("agent-browser")).toBe(false)
expect(result.notFound).toContain("agent-browser")
})