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
+79 -79
View File
@@ -8,11 +8,11 @@ import {
describe("AGENT_MODEL_REQUIREMENTS", () => {
test("oracle has valid fallbackChain with gpt-5.2 as primary", () => {
// #given - oracle agent requirement
// given - oracle agent requirement
const oracle = AGENT_MODEL_REQUIREMENTS["oracle"]
// #when - accessing oracle requirement
// #then - fallbackChain exists with gpt-5.2 as first entry
// when - accessing oracle requirement
// then - fallbackChain exists with gpt-5.2 as first entry
expect(oracle).toBeDefined()
expect(oracle.fallbackChain).toBeArray()
expect(oracle.fallbackChain.length).toBeGreaterThan(0)
@@ -24,11 +24,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("sisyphus has valid fallbackChain with claude-opus-4-5 as primary", () => {
// #given - sisyphus agent requirement
// given - sisyphus agent requirement
const sisyphus = AGENT_MODEL_REQUIREMENTS["sisyphus"]
// #when - accessing Sisyphus requirement
// #then - fallbackChain exists with claude-opus-4-5 as first entry
// when - accessing Sisyphus requirement
// then - fallbackChain exists with claude-opus-4-5 as first entry
expect(sisyphus).toBeDefined()
expect(sisyphus.fallbackChain).toBeArray()
expect(sisyphus.fallbackChain.length).toBeGreaterThan(0)
@@ -40,11 +40,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("librarian has valid fallbackChain with glm-4.7 as primary", () => {
// #given - librarian agent requirement
// given - librarian agent requirement
const librarian = AGENT_MODEL_REQUIREMENTS["librarian"]
// #when - accessing librarian requirement
// #then - fallbackChain exists with glm-4.7 as first entry
// when - accessing librarian requirement
// then - fallbackChain exists with glm-4.7 as first entry
expect(librarian).toBeDefined()
expect(librarian.fallbackChain).toBeArray()
expect(librarian.fallbackChain.length).toBeGreaterThan(0)
@@ -55,11 +55,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("explore has valid fallbackChain with claude-haiku-4-5 as primary", () => {
// #given - explore agent requirement
// given - explore agent requirement
const explore = AGENT_MODEL_REQUIREMENTS["explore"]
// #when - accessing explore requirement
// #then - fallbackChain exists with claude-haiku-4-5 as first entry, gpt-5-mini as second, gpt-5-nano as third
// when - accessing explore requirement
// then - fallbackChain exists with claude-haiku-4-5 as first entry, gpt-5-mini as second, gpt-5-nano as third
expect(explore).toBeDefined()
expect(explore.fallbackChain).toBeArray()
expect(explore.fallbackChain).toHaveLength(3)
@@ -79,11 +79,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("multimodal-looker has valid fallbackChain with gemini-3-flash as primary", () => {
// #given - multimodal-looker agent requirement
// given - multimodal-looker agent requirement
const multimodalLooker = AGENT_MODEL_REQUIREMENTS["multimodal-looker"]
// #when - accessing multimodal-looker requirement
// #then - fallbackChain exists with gemini-3-flash as first entry
// when - accessing multimodal-looker requirement
// then - fallbackChain exists with gemini-3-flash as first entry
expect(multimodalLooker).toBeDefined()
expect(multimodalLooker.fallbackChain).toBeArray()
expect(multimodalLooker.fallbackChain.length).toBeGreaterThan(0)
@@ -94,11 +94,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("prometheus has valid fallbackChain with claude-opus-4-5 as primary", () => {
// #given - prometheus agent requirement
// given - prometheus agent requirement
const prometheus = AGENT_MODEL_REQUIREMENTS["prometheus"]
// #when - accessing Prometheus requirement
// #then - fallbackChain exists with claude-opus-4-5 as first entry
// when - accessing Prometheus requirement
// then - fallbackChain exists with claude-opus-4-5 as first entry
expect(prometheus).toBeDefined()
expect(prometheus.fallbackChain).toBeArray()
expect(prometheus.fallbackChain.length).toBeGreaterThan(0)
@@ -110,11 +110,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("metis has valid fallbackChain with claude-opus-4-5 as primary", () => {
// #given - metis agent requirement
// given - metis agent requirement
const metis = AGENT_MODEL_REQUIREMENTS["metis"]
// #when - accessing Metis requirement
// #then - fallbackChain exists with claude-opus-4-5 as first entry
// when - accessing Metis requirement
// then - fallbackChain exists with claude-opus-4-5 as first entry
expect(metis).toBeDefined()
expect(metis.fallbackChain).toBeArray()
expect(metis.fallbackChain.length).toBeGreaterThan(0)
@@ -126,11 +126,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("momus has valid fallbackChain with gpt-5.2 as primary", () => {
// #given - momus agent requirement
// given - momus agent requirement
const momus = AGENT_MODEL_REQUIREMENTS["momus"]
// #when - accessing Momus requirement
// #then - fallbackChain exists with gpt-5.2 as first entry, variant medium
// when - accessing Momus requirement
// then - fallbackChain exists with gpt-5.2 as first entry, variant medium
expect(momus).toBeDefined()
expect(momus.fallbackChain).toBeArray()
expect(momus.fallbackChain.length).toBeGreaterThan(0)
@@ -142,11 +142,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("atlas has valid fallbackChain with k2p5 as primary (kimi-for-coding prioritized)", () => {
// #given - atlas agent requirement
// given - atlas agent requirement
const atlas = AGENT_MODEL_REQUIREMENTS["atlas"]
// #when - accessing Atlas requirement
// #then - fallbackChain exists with k2p5 as first entry (kimi-for-coding prioritized)
// when - accessing Atlas requirement
// then - fallbackChain exists with k2p5 as first entry (kimi-for-coding prioritized)
expect(atlas).toBeDefined()
expect(atlas.fallbackChain).toBeArray()
expect(atlas.fallbackChain.length).toBeGreaterThan(0)
@@ -157,7 +157,7 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
})
test("all 9 builtin agents have valid fallbackChain arrays", () => {
// #given - list of 9 agent names
// given - list of 9 agent names
const expectedAgents = [
"sisyphus",
"oracle",
@@ -170,10 +170,10 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
"atlas",
]
// #when - checking AGENT_MODEL_REQUIREMENTS
// when - checking AGENT_MODEL_REQUIREMENTS
const definedAgents = Object.keys(AGENT_MODEL_REQUIREMENTS)
// #then - all agents present with valid fallbackChain
// then - all agents present with valid fallbackChain
expect(definedAgents).toHaveLength(9)
for (const agent of expectedAgents) {
const requirement = AGENT_MODEL_REQUIREMENTS[agent]
@@ -193,11 +193,11 @@ describe("AGENT_MODEL_REQUIREMENTS", () => {
describe("CATEGORY_MODEL_REQUIREMENTS", () => {
test("ultrabrain has valid fallbackChain with gpt-5.2-codex as primary", () => {
// #given - ultrabrain category requirement
// given - ultrabrain category requirement
const ultrabrain = CATEGORY_MODEL_REQUIREMENTS["ultrabrain"]
// #when - accessing ultrabrain requirement
// #then - fallbackChain exists with gpt-5.2-codex as first entry
// when - accessing ultrabrain requirement
// then - fallbackChain exists with gpt-5.2-codex as first entry
expect(ultrabrain).toBeDefined()
expect(ultrabrain.fallbackChain).toBeArray()
expect(ultrabrain.fallbackChain.length).toBeGreaterThan(0)
@@ -209,11 +209,11 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
})
test("deep has valid fallbackChain with gpt-5.2-codex as primary", () => {
// #given - deep category requirement
// given - deep category requirement
const deep = CATEGORY_MODEL_REQUIREMENTS["deep"]
// #when - accessing deep requirement
// #then - fallbackChain exists with gpt-5.2-codex as first entry, medium variant
// when - accessing deep requirement
// then - fallbackChain exists with gpt-5.2-codex as first entry, medium variant
expect(deep).toBeDefined()
expect(deep.fallbackChain).toBeArray()
expect(deep.fallbackChain.length).toBeGreaterThan(0)
@@ -225,11 +225,11 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
})
test("visual-engineering has valid fallbackChain with gemini-3-pro as primary", () => {
// #given - visual-engineering category requirement
// given - visual-engineering category requirement
const visualEngineering = CATEGORY_MODEL_REQUIREMENTS["visual-engineering"]
// #when - accessing visual-engineering requirement
// #then - fallbackChain exists with gemini-3-pro as first entry
// when - accessing visual-engineering requirement
// then - fallbackChain exists with gemini-3-pro as first entry
expect(visualEngineering).toBeDefined()
expect(visualEngineering.fallbackChain).toBeArray()
expect(visualEngineering.fallbackChain.length).toBeGreaterThan(0)
@@ -240,11 +240,11 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
})
test("quick has valid fallbackChain with claude-haiku-4-5 as primary", () => {
// #given - quick category requirement
// given - quick category requirement
const quick = CATEGORY_MODEL_REQUIREMENTS["quick"]
// #when - accessing quick requirement
// #then - fallbackChain exists with claude-haiku-4-5 as first entry
// when - accessing quick requirement
// then - fallbackChain exists with claude-haiku-4-5 as first entry
expect(quick).toBeDefined()
expect(quick.fallbackChain).toBeArray()
expect(quick.fallbackChain.length).toBeGreaterThan(0)
@@ -255,11 +255,11 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
})
test("unspecified-low has valid fallbackChain with claude-sonnet-4-5 as primary", () => {
// #given - unspecified-low category requirement
// given - unspecified-low category requirement
const unspecifiedLow = CATEGORY_MODEL_REQUIREMENTS["unspecified-low"]
// #when - accessing unspecified-low requirement
// #then - fallbackChain exists with claude-sonnet-4-5 as first entry
// when - accessing unspecified-low requirement
// then - fallbackChain exists with claude-sonnet-4-5 as first entry
expect(unspecifiedLow).toBeDefined()
expect(unspecifiedLow.fallbackChain).toBeArray()
expect(unspecifiedLow.fallbackChain.length).toBeGreaterThan(0)
@@ -270,11 +270,11 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
})
test("unspecified-high has valid fallbackChain with claude-opus-4-5 as primary", () => {
// #given - unspecified-high category requirement
// given - unspecified-high category requirement
const unspecifiedHigh = CATEGORY_MODEL_REQUIREMENTS["unspecified-high"]
// #when - accessing unspecified-high requirement
// #then - fallbackChain exists with claude-opus-4-5 as first entry
// when - accessing unspecified-high requirement
// then - fallbackChain exists with claude-opus-4-5 as first entry
expect(unspecifiedHigh).toBeDefined()
expect(unspecifiedHigh.fallbackChain).toBeArray()
expect(unspecifiedHigh.fallbackChain.length).toBeGreaterThan(0)
@@ -286,11 +286,11 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
})
test("artistry has valid fallbackChain with gemini-3-pro as primary", () => {
// #given - artistry category requirement
// given - artistry category requirement
const artistry = CATEGORY_MODEL_REQUIREMENTS["artistry"]
// #when - accessing artistry requirement
// #then - fallbackChain exists with gemini-3-pro as first entry
// when - accessing artistry requirement
// then - fallbackChain exists with gemini-3-pro as first entry
expect(artistry).toBeDefined()
expect(artistry.fallbackChain).toBeArray()
expect(artistry.fallbackChain.length).toBeGreaterThan(0)
@@ -302,11 +302,11 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
})
test("writing has valid fallbackChain with gemini-3-flash as primary", () => {
// #given - writing category requirement
// given - writing category requirement
const writing = CATEGORY_MODEL_REQUIREMENTS["writing"]
// #when - accessing writing requirement
// #then - fallbackChain exists with gemini-3-flash as first entry
// when - accessing writing requirement
// then - fallbackChain exists with gemini-3-flash as first entry
expect(writing).toBeDefined()
expect(writing.fallbackChain).toBeArray()
expect(writing.fallbackChain.length).toBeGreaterThan(0)
@@ -317,7 +317,7 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
})
test("all 8 categories have valid fallbackChain arrays", () => {
// #given - list of 8 category names
// given - list of 8 category names
const expectedCategories = [
"visual-engineering",
"ultrabrain",
@@ -329,10 +329,10 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
"writing",
]
// #when - checking CATEGORY_MODEL_REQUIREMENTS
// when - checking CATEGORY_MODEL_REQUIREMENTS
const definedCategories = Object.keys(CATEGORY_MODEL_REQUIREMENTS)
// #then - all categories present with valid fallbackChain
// then - all categories present with valid fallbackChain
expect(definedCategories).toHaveLength(8)
for (const category of expectedCategories) {
const requirement = CATEGORY_MODEL_REQUIREMENTS[category]
@@ -352,36 +352,36 @@ describe("CATEGORY_MODEL_REQUIREMENTS", () => {
describe("FallbackEntry type", () => {
test("FallbackEntry structure is correct", () => {
// #given - a valid FallbackEntry object
// given - a valid FallbackEntry object
const entry: FallbackEntry = {
providers: ["anthropic", "github-copilot", "opencode"],
model: "claude-opus-4-5",
variant: "high",
}
// #when - accessing properties
// #then - all properties are accessible
// when - accessing properties
// then - all properties are accessible
expect(entry.providers).toEqual(["anthropic", "github-copilot", "opencode"])
expect(entry.model).toBe("claude-opus-4-5")
expect(entry.variant).toBe("high")
})
test("FallbackEntry variant is optional", () => {
// #given - a FallbackEntry without variant
// given - a FallbackEntry without variant
const entry: FallbackEntry = {
providers: ["opencode", "anthropic"],
model: "glm-4.7-free",
}
// #when - accessing variant
// #then - variant is undefined
// when - accessing variant
// then - variant is undefined
expect(entry.variant).toBeUndefined()
})
})
describe("ModelRequirement type", () => {
test("ModelRequirement structure with fallbackChain is correct", () => {
// #given - a valid ModelRequirement object
// given - a valid ModelRequirement object
const requirement: ModelRequirement = {
fallbackChain: [
{ providers: ["anthropic", "github-copilot"], model: "claude-opus-4-5", variant: "max" },
@@ -389,8 +389,8 @@ describe("ModelRequirement type", () => {
],
}
// #when - accessing properties
// #then - fallbackChain is accessible with correct structure
// when - accessing properties
// then - fallbackChain is accessible with correct structure
expect(requirement.fallbackChain).toBeArray()
expect(requirement.fallbackChain).toHaveLength(2)
expect(requirement.fallbackChain[0].model).toBe("claude-opus-4-5")
@@ -398,25 +398,25 @@ describe("ModelRequirement type", () => {
})
test("ModelRequirement variant is optional", () => {
// #given - a ModelRequirement without top-level variant
// given - a ModelRequirement without top-level variant
const requirement: ModelRequirement = {
fallbackChain: [{ providers: ["opencode"], model: "glm-4.7-free" }],
}
// #when - accessing variant
// #then - variant is undefined
// when - accessing variant
// then - variant is undefined
expect(requirement.variant).toBeUndefined()
})
test("no model in fallbackChain has provider prefix", () => {
// #given - all agent and category requirements
// given - all agent and category requirements
const allRequirements = [
...Object.values(AGENT_MODEL_REQUIREMENTS),
...Object.values(CATEGORY_MODEL_REQUIREMENTS),
]
// #when - checking each model in fallbackChain
// #then - none contain "/" (provider prefix)
// when - checking each model in fallbackChain
// then - none contain "/" (provider prefix)
for (const req of allRequirements) {
for (const entry of req.fallbackChain) {
expect(entry.model).not.toContain("/")
@@ -425,14 +425,14 @@ describe("ModelRequirement type", () => {
})
test("all fallbackChain entries have non-empty providers array", () => {
// #given - all agent and category requirements
// given - all agent and category requirements
const allRequirements = [
...Object.values(AGENT_MODEL_REQUIREMENTS),
...Object.values(CATEGORY_MODEL_REQUIREMENTS),
]
// #when - checking each entry in fallbackChain
// #then - all have non-empty providers array
// when - checking each entry in fallbackChain
// then - all have non-empty providers array
for (const req of allRequirements) {
for (const entry of req.fallbackChain) {
expect(entry.providers).toBeArray()
@@ -444,18 +444,18 @@ describe("ModelRequirement type", () => {
describe("requiresModel field in categories", () => {
test("deep category has requiresModel set to gpt-5.2-codex", () => {
// #given
// given
const deep = CATEGORY_MODEL_REQUIREMENTS["deep"]
// #when / #then
// when / #then
expect(deep.requiresModel).toBe("gpt-5.2-codex")
})
test("artistry category has requiresModel set to gemini-3-pro", () => {
// #given
// given
const artistry = CATEGORY_MODEL_REQUIREMENTS["artistry"]
// #when / #then
// when / #then
expect(artistry.requiresModel).toBe("gemini-3-pro")
})
})