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
+55 -55
View File
@@ -13,89 +13,89 @@ import {
describe("opencode-version", () => {
describe("parseVersion", () => {
test("parses simple version", () => {
// #given a simple version string
// given a simple version string
const version = "1.2.3"
// #when parsed
// when parsed
const result = parseVersion(version)
// #then returns array of numbers
// then returns array of numbers
expect(result).toEqual([1, 2, 3])
})
test("handles v prefix", () => {
// #given version with v prefix
// given version with v prefix
const version = "v1.2.3"
// #when parsed
// when parsed
const result = parseVersion(version)
// #then strips prefix and parses correctly
// then strips prefix and parses correctly
expect(result).toEqual([1, 2, 3])
})
test("handles prerelease suffix", () => {
// #given version with prerelease
// given version with prerelease
const version = "1.2.3-beta.1"
// #when parsed
// when parsed
const result = parseVersion(version)
// #then ignores prerelease part
// then ignores prerelease part
expect(result).toEqual([1, 2, 3])
})
test("handles two-part version", () => {
// #given two-part version
// given two-part version
const version = "1.2"
// #when parsed
// when parsed
const result = parseVersion(version)
// #then returns two numbers
// then returns two numbers
expect(result).toEqual([1, 2])
})
})
describe("compareVersions", () => {
test("returns 0 for equal versions", () => {
// #given two equal versions
// #when compared
// given two equal versions
// when compared
const result = compareVersions("1.1.1", "1.1.1")
// #then returns 0
// then returns 0
expect(result).toBe(0)
})
test("returns 1 when a > b", () => {
// #given a is greater than b
// #when compared
// given a is greater than b
// when compared
const result = compareVersions("1.2.0", "1.1.0")
// #then returns 1
// then returns 1
expect(result).toBe(1)
})
test("returns -1 when a < b", () => {
// #given a is less than b
// #when compared
// given a is less than b
// when compared
const result = compareVersions("1.0.9", "1.1.0")
// #then returns -1
// then returns -1
expect(result).toBe(-1)
})
test("handles different length versions", () => {
// #given versions with different lengths
// #when compared
// given versions with different lengths
// when compared
expect(compareVersions("1.1", "1.1.0")).toBe(0)
expect(compareVersions("1.1.1", "1.1")).toBe(1)
expect(compareVersions("1.1", "1.1.1")).toBe(-1)
})
test("handles major version differences", () => {
// #given major version difference
// #when compared
// given major version difference
// when compared
expect(compareVersions("2.0.0", "1.9.9")).toBe(1)
expect(compareVersions("1.9.9", "2.0.0")).toBe(-1)
})
@@ -112,24 +112,24 @@ describe("opencode-version", () => {
})
test("returns cached version on subsequent calls", () => {
// #given version is set in cache
// given version is set in cache
setVersionCache("1.2.3")
// #when getting version
// when getting version
const result = getOpenCodeVersion()
// #then returns cached value
// then returns cached value
expect(result).toBe("1.2.3")
})
test("returns null when cache is set to null", () => {
// #given cache is explicitly set to null
// given cache is explicitly set to null
setVersionCache(null)
// #when getting version (cache is already set)
// when getting version (cache is already set)
const result = getOpenCodeVersion()
// #then returns null without executing command
// then returns null without executing command
expect(result).toBe(null)
})
})
@@ -144,46 +144,46 @@ describe("opencode-version", () => {
})
test("returns true for exact version", () => {
// #given version is 1.1.1
// given version is 1.1.1
setVersionCache("1.1.1")
// #when checking against 1.1.1
// when checking against 1.1.1
const result = isOpenCodeVersionAtLeast("1.1.1")
// #then returns true
// then returns true
expect(result).toBe(true)
})
test("returns true for versions above target", () => {
// #given version is above target
// given version is above target
setVersionCache("1.2.0")
// #when checking against 1.1.1
// when checking against 1.1.1
const result = isOpenCodeVersionAtLeast("1.1.1")
// #then returns true
// then returns true
expect(result).toBe(true)
})
test("returns false for versions below target", () => {
// #given version is below target
// given version is below target
setVersionCache("1.1.0")
// #when checking against 1.1.1
// when checking against 1.1.1
const result = isOpenCodeVersionAtLeast("1.1.1")
// #then returns false
// then returns false
expect(result).toBe(false)
})
test("returns true when version cannot be detected", () => {
// #given version is null (undetectable)
// given version is null (undetectable)
setVersionCache(null)
// #when checking
// when checking
const result = isOpenCodeVersionAtLeast("1.1.1")
// #then returns true (assume newer version)
// then returns true (assume newer version)
expect(result).toBe(true)
})
})
@@ -196,42 +196,42 @@ describe("opencode-version", () => {
describe("OPENCODE_NATIVE_AGENTS_INJECTION_VERSION", () => {
test("is set to 1.1.37", () => {
// #given the native agents injection version constant
// #when exported
// #then it should be 1.1.37 (PR #10678)
// given the native agents injection version constant
// when exported
// then it should be 1.1.37 (PR #10678)
expect(OPENCODE_NATIVE_AGENTS_INJECTION_VERSION).toBe("1.1.37")
})
test("version detection works correctly with native agents version", () => {
// #given OpenCode version at or above native agents injection version
// given OpenCode version at or above native agents injection version
setVersionCache("1.1.37")
// #when checking against native agents version
// when checking against native agents version
const result = isOpenCodeVersionAtLeast(OPENCODE_NATIVE_AGENTS_INJECTION_VERSION)
// #then returns true (native support available)
// then returns true (native support available)
expect(result).toBe(true)
})
test("version detection returns false for older versions", () => {
// #given OpenCode version below native agents injection version
// given OpenCode version below native agents injection version
setVersionCache("1.1.36")
// #when checking against native agents version
// when checking against native agents version
const result = isOpenCodeVersionAtLeast(OPENCODE_NATIVE_AGENTS_INJECTION_VERSION)
// #then returns false (no native support)
// then returns false (no native support)
expect(result).toBe(false)
})
test("returns true when version detection fails (fail-safe)", () => {
// #given version cannot be detected
// given version cannot be detected
setVersionCache(null)
// #when checking against native agents version
// when checking against native agents version
const result = isOpenCodeVersionAtLeast(OPENCODE_NATIVE_AGENTS_INJECTION_VERSION)
// #then returns true (assume latest, enable native support)
// then returns true (assume latest, enable native support)
expect(result).toBe(true)
})
})