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:
@@ -6,7 +6,7 @@ import { AGENT_MODEL_REQUIREMENTS } from "./model-requirements"
|
||||
describe("Agent Config Integration", () => {
|
||||
describe("Old format config migration", () => {
|
||||
test("migrates old format agent keys to lowercase", () => {
|
||||
// #given - config with old format keys
|
||||
// given - config with old format keys
|
||||
const oldConfig = {
|
||||
Sisyphus: { model: "anthropic/claude-opus-4-5" },
|
||||
Atlas: { model: "anthropic/claude-opus-4-5" },
|
||||
@@ -15,52 +15,52 @@ describe("Agent Config Integration", () => {
|
||||
"Momus (Plan Reviewer)": { model: "anthropic/claude-sonnet-4-5" },
|
||||
}
|
||||
|
||||
// #when - migration is applied
|
||||
// when - migration is applied
|
||||
const result = migrateAgentNames(oldConfig)
|
||||
|
||||
// #then - keys are lowercase
|
||||
// then - keys are lowercase
|
||||
expect(result.migrated).toHaveProperty("sisyphus")
|
||||
expect(result.migrated).toHaveProperty("atlas")
|
||||
expect(result.migrated).toHaveProperty("prometheus")
|
||||
expect(result.migrated).toHaveProperty("metis")
|
||||
expect(result.migrated).toHaveProperty("momus")
|
||||
|
||||
// #then - old keys are removed
|
||||
// then - old keys are removed
|
||||
expect(result.migrated).not.toHaveProperty("Sisyphus")
|
||||
expect(result.migrated).not.toHaveProperty("Atlas")
|
||||
expect(result.migrated).not.toHaveProperty("Prometheus (Planner)")
|
||||
expect(result.migrated).not.toHaveProperty("Metis (Plan Consultant)")
|
||||
expect(result.migrated).not.toHaveProperty("Momus (Plan Reviewer)")
|
||||
|
||||
// #then - values are preserved
|
||||
// then - values are preserved
|
||||
expect(result.migrated.sisyphus).toEqual({ model: "anthropic/claude-opus-4-5" })
|
||||
expect(result.migrated.atlas).toEqual({ model: "anthropic/claude-opus-4-5" })
|
||||
expect(result.migrated.prometheus).toEqual({ model: "anthropic/claude-opus-4-5" })
|
||||
|
||||
// #then - changed flag is true
|
||||
// then - changed flag is true
|
||||
expect(result.changed).toBe(true)
|
||||
})
|
||||
|
||||
test("preserves already lowercase keys", () => {
|
||||
// #given - config with lowercase keys
|
||||
// given - config with lowercase keys
|
||||
const config = {
|
||||
sisyphus: { model: "anthropic/claude-opus-4-5" },
|
||||
oracle: { model: "openai/gpt-5.2" },
|
||||
librarian: { model: "opencode/glm-4.7-free" },
|
||||
}
|
||||
|
||||
// #when - migration is applied
|
||||
// when - migration is applied
|
||||
const result = migrateAgentNames(config)
|
||||
|
||||
// #then - keys remain unchanged
|
||||
// then - keys remain unchanged
|
||||
expect(result.migrated).toEqual(config)
|
||||
|
||||
// #then - changed flag is false
|
||||
// then - changed flag is false
|
||||
expect(result.changed).toBe(false)
|
||||
})
|
||||
|
||||
test("handles mixed case config", () => {
|
||||
// #given - config with mixed old and new format
|
||||
// given - config with mixed old and new format
|
||||
const mixedConfig = {
|
||||
Sisyphus: { model: "anthropic/claude-opus-4-5" },
|
||||
oracle: { model: "openai/gpt-5.2" },
|
||||
@@ -68,30 +68,30 @@ describe("Agent Config Integration", () => {
|
||||
librarian: { model: "opencode/glm-4.7-free" },
|
||||
}
|
||||
|
||||
// #when - migration is applied
|
||||
// when - migration is applied
|
||||
const result = migrateAgentNames(mixedConfig)
|
||||
|
||||
// #then - all keys are lowercase
|
||||
// then - all keys are lowercase
|
||||
expect(result.migrated).toHaveProperty("sisyphus")
|
||||
expect(result.migrated).toHaveProperty("oracle")
|
||||
expect(result.migrated).toHaveProperty("prometheus")
|
||||
expect(result.migrated).toHaveProperty("librarian")
|
||||
expect(Object.keys(result.migrated).every((key) => key === key.toLowerCase())).toBe(true)
|
||||
|
||||
// #then - changed flag is true
|
||||
// then - changed flag is true
|
||||
expect(result.changed).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Display name resolution", () => {
|
||||
test("returns correct display names for all builtin agents", () => {
|
||||
// #given - lowercase config keys
|
||||
// given - lowercase config keys
|
||||
const agents = ["sisyphus", "atlas", "prometheus", "metis", "momus", "oracle", "librarian", "explore", "multimodal-looker"]
|
||||
|
||||
// #when - display names are requested
|
||||
// when - display names are requested
|
||||
const displayNames = agents.map((agent) => getAgentDisplayName(agent))
|
||||
|
||||
// #then - display names are correct
|
||||
// then - display names are correct
|
||||
expect(displayNames).toContain("Sisyphus (Ultraworker)")
|
||||
expect(displayNames).toContain("Atlas (Plan Execution Orchestrator)")
|
||||
expect(displayNames).toContain("Prometheus (Plan Builder)")
|
||||
@@ -104,13 +104,13 @@ describe("Agent Config Integration", () => {
|
||||
})
|
||||
|
||||
test("handles lowercase keys case-insensitively", () => {
|
||||
// #given - various case formats of lowercase keys
|
||||
// given - various case formats of lowercase keys
|
||||
const keys = ["Sisyphus", "Atlas", "SISYPHUS", "atlas", "prometheus", "PROMETHEUS"]
|
||||
|
||||
// #when - display names are requested
|
||||
// when - display names are requested
|
||||
const displayNames = keys.map((key) => getAgentDisplayName(key))
|
||||
|
||||
// #then - correct display names are returned
|
||||
// then - correct display names are returned
|
||||
expect(displayNames[0]).toBe("Sisyphus (Ultraworker)")
|
||||
expect(displayNames[1]).toBe("Atlas (Plan Execution Orchestrator)")
|
||||
expect(displayNames[2]).toBe("Sisyphus (Ultraworker)")
|
||||
@@ -120,103 +120,103 @@ describe("Agent Config Integration", () => {
|
||||
})
|
||||
|
||||
test("returns original key for unknown agents", () => {
|
||||
// #given - unknown agent key
|
||||
// given - unknown agent key
|
||||
const unknownKey = "custom-agent"
|
||||
|
||||
// #when - display name is requested
|
||||
// when - display name is requested
|
||||
const displayName = getAgentDisplayName(unknownKey)
|
||||
|
||||
// #then - original key is returned
|
||||
// then - original key is returned
|
||||
expect(displayName).toBe(unknownKey)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Model requirements integration", () => {
|
||||
test("all model requirements use lowercase keys", () => {
|
||||
// #given - AGENT_MODEL_REQUIREMENTS object
|
||||
// given - AGENT_MODEL_REQUIREMENTS object
|
||||
const agentKeys = Object.keys(AGENT_MODEL_REQUIREMENTS)
|
||||
|
||||
// #when - checking key format
|
||||
// when - checking key format
|
||||
const allLowercase = agentKeys.every((key) => key === key.toLowerCase())
|
||||
|
||||
// #then - all keys are lowercase
|
||||
// then - all keys are lowercase
|
||||
expect(allLowercase).toBe(true)
|
||||
})
|
||||
|
||||
test("model requirements include all builtin agents", () => {
|
||||
// #given - expected builtin agents
|
||||
// given - expected builtin agents
|
||||
const expectedAgents = ["sisyphus", "atlas", "prometheus", "metis", "momus", "oracle", "librarian", "explore", "multimodal-looker"]
|
||||
|
||||
// #when - checking AGENT_MODEL_REQUIREMENTS
|
||||
// when - checking AGENT_MODEL_REQUIREMENTS
|
||||
const agentKeys = Object.keys(AGENT_MODEL_REQUIREMENTS)
|
||||
|
||||
// #then - all expected agents are present
|
||||
// then - all expected agents are present
|
||||
for (const agent of expectedAgents) {
|
||||
expect(agentKeys).toContain(agent)
|
||||
}
|
||||
})
|
||||
|
||||
test("no uppercase keys in model requirements", () => {
|
||||
// #given - AGENT_MODEL_REQUIREMENTS object
|
||||
// given - AGENT_MODEL_REQUIREMENTS object
|
||||
const agentKeys = Object.keys(AGENT_MODEL_REQUIREMENTS)
|
||||
|
||||
// #when - checking for uppercase keys
|
||||
// when - checking for uppercase keys
|
||||
const uppercaseKeys = agentKeys.filter((key) => key !== key.toLowerCase())
|
||||
|
||||
// #then - no uppercase keys exist
|
||||
// then - no uppercase keys exist
|
||||
expect(uppercaseKeys).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe("End-to-end config flow", () => {
|
||||
test("old config migrates and displays correctly", () => {
|
||||
// #given - old format config
|
||||
// given - old format config
|
||||
const oldConfig = {
|
||||
Sisyphus: { model: "anthropic/claude-opus-4-5", temperature: 0.1 },
|
||||
"Prometheus (Planner)": { model: "anthropic/claude-opus-4-5" },
|
||||
}
|
||||
|
||||
// #when - config is migrated
|
||||
// when - config is migrated
|
||||
const result = migrateAgentNames(oldConfig)
|
||||
|
||||
// #then - keys are lowercase
|
||||
// then - keys are lowercase
|
||||
expect(result.migrated).toHaveProperty("sisyphus")
|
||||
expect(result.migrated).toHaveProperty("prometheus")
|
||||
|
||||
// #when - display names are retrieved
|
||||
// when - display names are retrieved
|
||||
const sisyphusDisplay = getAgentDisplayName("sisyphus")
|
||||
const prometheusDisplay = getAgentDisplayName("prometheus")
|
||||
|
||||
// #then - display names are correct
|
||||
// then - display names are correct
|
||||
expect(sisyphusDisplay).toBe("Sisyphus (Ultraworker)")
|
||||
expect(prometheusDisplay).toBe("Prometheus (Plan Builder)")
|
||||
|
||||
// #then - config values are preserved
|
||||
// then - config values are preserved
|
||||
expect(result.migrated.sisyphus).toEqual({ model: "anthropic/claude-opus-4-5", temperature: 0.1 })
|
||||
expect(result.migrated.prometheus).toEqual({ model: "anthropic/claude-opus-4-5" })
|
||||
})
|
||||
|
||||
test("new config works without migration", () => {
|
||||
// #given - new format config (already lowercase)
|
||||
// given - new format config (already lowercase)
|
||||
const newConfig = {
|
||||
sisyphus: { model: "anthropic/claude-opus-4-5" },
|
||||
atlas: { model: "anthropic/claude-opus-4-5" },
|
||||
}
|
||||
|
||||
// #when - migration is applied (should be no-op)
|
||||
// when - migration is applied (should be no-op)
|
||||
const result = migrateAgentNames(newConfig)
|
||||
|
||||
// #then - config is unchanged
|
||||
// then - config is unchanged
|
||||
expect(result.migrated).toEqual(newConfig)
|
||||
|
||||
// #then - changed flag is false
|
||||
// then - changed flag is false
|
||||
expect(result.changed).toBe(false)
|
||||
|
||||
// #when - display names are retrieved
|
||||
// when - display names are retrieved
|
||||
const sisyphusDisplay = getAgentDisplayName("sisyphus")
|
||||
const atlasDisplay = getAgentDisplayName("atlas")
|
||||
|
||||
// #then - display names are correct
|
||||
// then - display names are correct
|
||||
expect(sisyphusDisplay).toBe("Sisyphus (Ultraworker)")
|
||||
expect(atlasDisplay).toBe("Atlas (Plan Execution Orchestrator)")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user