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
+42 -42
View File
@@ -36,15 +36,15 @@ describe("boulder-state", () => {
describe("readBoulderState", () => {
test("should return null when no boulder.json exists", () => {
// #given - no boulder.json file
// #when
// given - no boulder.json file
// when
const result = readBoulderState(TEST_DIR)
// #then
// then
expect(result).toBeNull()
})
test("should read valid boulder state", () => {
// #given - valid boulder.json
// given - valid boulder.json
const state: BoulderState = {
active_plan: "/path/to/plan.md",
started_at: "2026-01-02T10:00:00Z",
@@ -53,10 +53,10 @@ describe("boulder-state", () => {
}
writeBoulderState(TEST_DIR, state)
// #when
// when
const result = readBoulderState(TEST_DIR)
// #then
// then
expect(result).not.toBeNull()
expect(result?.active_plan).toBe("/path/to/plan.md")
expect(result?.session_ids).toEqual(["session-1", "session-2"])
@@ -66,7 +66,7 @@ describe("boulder-state", () => {
describe("writeBoulderState", () => {
test("should write state and create .sisyphus directory if needed", () => {
// #given - state to write
// given - state to write
const state: BoulderState = {
active_plan: "/test/plan.md",
started_at: "2026-01-02T12:00:00Z",
@@ -74,11 +74,11 @@ describe("boulder-state", () => {
plan_name: "test-plan",
}
// #when
// when
const success = writeBoulderState(TEST_DIR, state)
const readBack = readBoulderState(TEST_DIR)
// #then
// then
expect(success).toBe(true)
expect(readBack).not.toBeNull()
expect(readBack?.active_plan).toBe("/test/plan.md")
@@ -87,7 +87,7 @@ describe("boulder-state", () => {
describe("appendSessionId", () => {
test("should append new session id to existing state", () => {
// #given - existing state with one session
// given - existing state with one session
const state: BoulderState = {
active_plan: "/plan.md",
started_at: "2026-01-02T10:00:00Z",
@@ -96,16 +96,16 @@ describe("boulder-state", () => {
}
writeBoulderState(TEST_DIR, state)
// #when
// when
const result = appendSessionId(TEST_DIR, "session-2")
// #then
// then
expect(result).not.toBeNull()
expect(result?.session_ids).toEqual(["session-1", "session-2"])
})
test("should not duplicate existing session id", () => {
// #given - state with session-1 already
// given - state with session-1 already
const state: BoulderState = {
active_plan: "/plan.md",
started_at: "2026-01-02T10:00:00Z",
@@ -114,26 +114,26 @@ describe("boulder-state", () => {
}
writeBoulderState(TEST_DIR, state)
// #when
// when
appendSessionId(TEST_DIR, "session-1")
const result = readBoulderState(TEST_DIR)
// #then
// then
expect(result?.session_ids).toEqual(["session-1"])
})
test("should return null when no state exists", () => {
// #given - no boulder.json
// #when
// given - no boulder.json
// when
const result = appendSessionId(TEST_DIR, "new-session")
// #then
// then
expect(result).toBeNull()
})
})
describe("clearBoulderState", () => {
test("should remove boulder.json", () => {
// #given - existing state
// given - existing state
const state: BoulderState = {
active_plan: "/plan.md",
started_at: "2026-01-02T10:00:00Z",
@@ -142,27 +142,27 @@ describe("boulder-state", () => {
}
writeBoulderState(TEST_DIR, state)
// #when
// when
const success = clearBoulderState(TEST_DIR)
const result = readBoulderState(TEST_DIR)
// #then
// then
expect(success).toBe(true)
expect(result).toBeNull()
})
test("should succeed even when no file exists", () => {
// #given - no boulder.json
// #when
// given - no boulder.json
// when
const success = clearBoulderState(TEST_DIR)
// #then
// then
expect(success).toBe(true)
})
})
describe("getPlanProgress", () => {
test("should count completed and uncompleted checkboxes", () => {
// #given - plan file with checkboxes
// given - plan file with checkboxes
const planPath = join(TEST_DIR, "test-plan.md")
writeFileSync(planPath, `# Plan
- [ ] Task 1
@@ -171,50 +171,50 @@ describe("boulder-state", () => {
- [X] Task 4
`)
// #when
// when
const progress = getPlanProgress(planPath)
// #then
// then
expect(progress.total).toBe(4)
expect(progress.completed).toBe(2)
expect(progress.isComplete).toBe(false)
})
test("should return isComplete true when all checked", () => {
// #given - all tasks completed
// given - all tasks completed
const planPath = join(TEST_DIR, "complete-plan.md")
writeFileSync(planPath, `# Plan
- [x] Task 1
- [X] Task 2
`)
// #when
// when
const progress = getPlanProgress(planPath)
// #then
// then
expect(progress.total).toBe(2)
expect(progress.completed).toBe(2)
expect(progress.isComplete).toBe(true)
})
test("should return isComplete true for empty plan", () => {
// #given - plan with no checkboxes
// given - plan with no checkboxes
const planPath = join(TEST_DIR, "empty-plan.md")
writeFileSync(planPath, "# Plan\nNo tasks here")
// #when
// when
const progress = getPlanProgress(planPath)
// #then
// then
expect(progress.total).toBe(0)
expect(progress.isComplete).toBe(true)
})
test("should handle non-existent file", () => {
// #given - non-existent file
// #when
// given - non-existent file
// when
const progress = getPlanProgress("/non/existent/file.md")
// #then
// then
expect(progress.total).toBe(0)
expect(progress.isComplete).toBe(true)
})
@@ -222,25 +222,25 @@ describe("boulder-state", () => {
describe("getPlanName", () => {
test("should extract plan name from path", () => {
// #given
// given
const path = "/home/user/.sisyphus/plans/project/my-feature.md"
// #when
// when
const name = getPlanName(path)
// #then
// then
expect(name).toBe("my-feature")
})
})
describe("createBoulderState", () => {
test("should create state with correct fields", () => {
// #given
// given
const planPath = "/path/to/auth-refactor.md"
const sessionId = "ses-abc123"
// #when
// when
const state = createBoulderState(planPath, sessionId)
// #then
// then
expect(state.active_plan).toBe(planPath)
expect(state.session_ids).toEqual([sessionId])
expect(state.plan_name).toBe("auth-refactor")