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
+110 -110
View File
@@ -10,15 +10,15 @@ import {
describe("disabled_mcps schema", () => {
test("should accept built-in MCP names", () => {
//#given
// given
const config = {
disabled_mcps: ["context7", "grep_app"],
}
//#when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
//#then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.disabled_mcps).toEqual(["context7", "grep_app"])
@@ -26,15 +26,15 @@ describe("disabled_mcps schema", () => {
})
test("should accept custom MCP names", () => {
//#given
// given
const config = {
disabled_mcps: ["playwright", "sqlite", "custom-mcp"],
}
//#when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
//#then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.disabled_mcps).toEqual(["playwright", "sqlite", "custom-mcp"])
@@ -42,15 +42,15 @@ describe("disabled_mcps schema", () => {
})
test("should accept mixed built-in and custom names", () => {
//#given
// given
const config = {
disabled_mcps: ["context7", "playwright", "custom-server"],
}
//#when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
//#then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.disabled_mcps).toEqual(["context7", "playwright", "custom-server"])
@@ -58,15 +58,15 @@ describe("disabled_mcps schema", () => {
})
test("should accept empty array", () => {
//#given
// given
const config = {
disabled_mcps: [],
}
//#when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
//#then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.disabled_mcps).toEqual([])
@@ -74,26 +74,26 @@ describe("disabled_mcps schema", () => {
})
test("should reject non-string values", () => {
//#given
// given
const config = {
disabled_mcps: [123, true, null],
}
//#when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
//#then
// then
expect(result.success).toBe(false)
})
test("should accept undefined (optional field)", () => {
//#given
// given
const config = {}
//#when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
//#then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.disabled_mcps).toBeUndefined()
@@ -101,20 +101,20 @@ describe("disabled_mcps schema", () => {
})
test("should reject empty strings", () => {
//#given
// given
const config = {
disabled_mcps: [""],
}
//#when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
//#then
// then
expect(result.success).toBe(false)
})
test("should accept MCP names with various naming patterns", () => {
//#given
// given
const config = {
disabled_mcps: [
"my-custom-mcp",
@@ -125,10 +125,10 @@ describe("disabled_mcps schema", () => {
],
}
//#when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
//#then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.disabled_mcps).toEqual([
@@ -145,13 +145,13 @@ describe("disabled_mcps schema", () => {
describe("AgentOverrideConfigSchema", () => {
describe("category field", () => {
test("accepts category as optional string", () => {
// #given
// given
const config = { category: "visual-engineering" }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.category).toBe("visual-engineering")
@@ -159,37 +159,37 @@ describe("AgentOverrideConfigSchema", () => {
})
test("accepts config without category", () => {
// #given
// given
const config = { temperature: 0.5 }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
})
test("rejects non-string category", () => {
// #given
// given
const config = { category: 123 }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(false)
})
})
describe("variant field", () => {
test("accepts variant as optional string", () => {
// #given
// given
const config = { variant: "high" }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.variant).toBe("high")
@@ -197,26 +197,26 @@ describe("AgentOverrideConfigSchema", () => {
})
test("rejects non-string variant", () => {
// #given
// given
const config = { variant: 123 }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(false)
})
})
describe("skills field", () => {
test("accepts skills as optional string array", () => {
// #given
// given
const config = { skills: ["frontend-ui-ux", "code-reviewer"] }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.skills).toEqual(["frontend-ui-ux", "code-reviewer"])
@@ -224,13 +224,13 @@ describe("AgentOverrideConfigSchema", () => {
})
test("accepts empty skills array", () => {
// #given
// given
const config = { skills: [] }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.skills).toEqual([])
@@ -238,37 +238,37 @@ describe("AgentOverrideConfigSchema", () => {
})
test("accepts config without skills", () => {
// #given
// given
const config = { temperature: 0.5 }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
})
test("rejects non-array skills", () => {
// #given
// given
const config = { skills: "frontend-ui-ux" }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(false)
})
})
describe("backward compatibility", () => {
test("still accepts model field (deprecated)", () => {
// #given
// given
const config = { model: "openai/gpt-5.2" }
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.model).toBe("openai/gpt-5.2")
@@ -276,16 +276,16 @@ describe("AgentOverrideConfigSchema", () => {
})
test("accepts both model and category (deprecated usage)", () => {
// #given - category should take precedence at runtime, but both should validate
// given - category should take precedence at runtime, but both should validate
const config = {
model: "openai/gpt-5.2",
category: "ultrabrain"
}
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.model).toBe("openai/gpt-5.2")
@@ -296,16 +296,16 @@ describe("AgentOverrideConfigSchema", () => {
describe("combined fields", () => {
test("accepts category with skills", () => {
// #given
// given
const config = {
category: "visual-engineering",
skills: ["frontend-ui-ux"]
}
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.category).toBe("visual-engineering")
@@ -314,7 +314,7 @@ describe("AgentOverrideConfigSchema", () => {
})
test("accepts category with skills and other fields", () => {
// #given
// given
const config = {
category: "ultrabrain",
skills: ["code-reviewer"],
@@ -322,10 +322,10 @@ describe("AgentOverrideConfigSchema", () => {
prompt_append: "Extra instructions"
}
// #when
// when
const result = AgentOverrideConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.category).toBe("ultrabrain")
@@ -339,13 +339,13 @@ describe("AgentOverrideConfigSchema", () => {
describe("CategoryConfigSchema", () => {
test("accepts variant as optional string", () => {
// #given
// given
const config = { model: "openai/gpt-5.2", variant: "xhigh" }
// #when
// when
const result = CategoryConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.variant).toBe("xhigh")
@@ -353,13 +353,13 @@ describe("CategoryConfigSchema", () => {
})
test("accepts reasoningEffort as optional string with xhigh", () => {
// #given
// given
const config = { reasoningEffort: "xhigh" }
// #when
// when
const result = CategoryConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.reasoningEffort).toBe("xhigh")
@@ -367,23 +367,23 @@ describe("CategoryConfigSchema", () => {
})
test("rejects non-string variant", () => {
// #given
// given
const config = { model: "openai/gpt-5.2", variant: 123 }
// #when
// when
const result = CategoryConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(false)
})
})
describe("BuiltinCategoryNameSchema", () => {
test("accepts all builtin category names", () => {
// #given
// given
const categories = ["visual-engineering", "ultrabrain", "artistry", "quick", "unspecified-low", "unspecified-high", "writing"]
// #when / #then
// when / #then
for (const cat of categories) {
const result = BuiltinCategoryNameSchema.safeParse(cat)
expect(result.success).toBe(true)
@@ -393,7 +393,7 @@ describe("BuiltinCategoryNameSchema", () => {
describe("Sisyphus-Junior agent override", () => {
test("schema accepts agents['Sisyphus-Junior'] and retains the key after parsing", () => {
// #given
// given
const config = {
agents: {
"sisyphus-junior": {
@@ -403,10 +403,10 @@ describe("Sisyphus-Junior agent override", () => {
},
}
// #when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.agents?.["sisyphus-junior"]).toBeDefined()
@@ -416,7 +416,7 @@ describe("Sisyphus-Junior agent override", () => {
})
test("schema accepts sisyphus-junior with prompt_append", () => {
// #given
// given
const config = {
agents: {
"sisyphus-junior": {
@@ -425,10 +425,10 @@ describe("Sisyphus-Junior agent override", () => {
},
}
// #when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.agents?.["sisyphus-junior"]?.prompt_append).toBe(
@@ -438,7 +438,7 @@ describe("Sisyphus-Junior agent override", () => {
})
test("schema accepts sisyphus-junior with tools override", () => {
// #given
// given
const config = {
agents: {
"sisyphus-junior": {
@@ -450,10 +450,10 @@ describe("Sisyphus-Junior agent override", () => {
},
}
// #when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.agents?.["sisyphus-junior"]?.tools).toEqual({
@@ -464,7 +464,7 @@ describe("Sisyphus-Junior agent override", () => {
})
test("schema accepts lowercase agent names (sisyphus, atlas, prometheus)", () => {
// #given
// given
const config = {
agents: {
sisyphus: {
@@ -479,10 +479,10 @@ describe("Sisyphus-Junior agent override", () => {
},
}
// #when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.agents?.sisyphus?.temperature).toBe(0.1)
@@ -492,7 +492,7 @@ describe("Sisyphus-Junior agent override", () => {
})
test("schema accepts lowercase metis and momus agent names", () => {
// #given
// given
const config = {
agents: {
metis: {
@@ -504,10 +504,10 @@ describe("Sisyphus-Junior agent override", () => {
},
}
// #when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(config)
// #then
// then
expect(result.success).toBe(true)
if (result.success) {
expect(result.data.agents?.metis?.category).toBe("ultrabrain")
@@ -518,90 +518,90 @@ describe("Sisyphus-Junior agent override", () => {
describe("BrowserAutomationProviderSchema", () => {
test("accepts 'playwright' as valid provider", () => {
// #given
// given
const input = "playwright"
// #when
// when
const result = BrowserAutomationProviderSchema.safeParse(input)
// #then
// then
expect(result.success).toBe(true)
expect(result.data).toBe("playwright")
})
test("accepts 'agent-browser' as valid provider", () => {
// #given
// given
const input = "agent-browser"
// #when
// when
const result = BrowserAutomationProviderSchema.safeParse(input)
// #then
// then
expect(result.success).toBe(true)
expect(result.data).toBe("agent-browser")
})
test("rejects invalid provider", () => {
// #given
// given
const input = "invalid-provider"
// #when
// when
const result = BrowserAutomationProviderSchema.safeParse(input)
// #then
// then
expect(result.success).toBe(false)
})
})
describe("BrowserAutomationConfigSchema", () => {
test("defaults provider to 'playwright' when not specified", () => {
// #given
// given
const input = {}
// #when
// when
const result = BrowserAutomationConfigSchema.parse(input)
// #then
// then
expect(result.provider).toBe("playwright")
})
test("accepts agent-browser provider", () => {
// #given
// given
const input = { provider: "agent-browser" }
// #when
// when
const result = BrowserAutomationConfigSchema.parse(input)
// #then
// then
expect(result.provider).toBe("agent-browser")
})
})
describe("OhMyOpenCodeConfigSchema - browser_automation_engine", () => {
test("accepts browser_automation_engine config", () => {
// #given
// given
const input = {
browser_automation_engine: {
provider: "agent-browser",
},
}
// #when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(input)
// #then
// then
expect(result.success).toBe(true)
expect(result.data?.browser_automation_engine?.provider).toBe("agent-browser")
})
test("accepts config without browser_automation_engine", () => {
// #given
// given
const input = {}
// #when
// when
const result = OhMyOpenCodeConfigSchema.safeParse(input)
// #then
// then
expect(result.success).toBe(true)
expect(result.data?.browser_automation_engine).toBeUndefined()
})