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 52ce322f4b
commit fc70dd2492
145 changed files with 10307 additions and 9562 deletions
@@ -19,16 +19,16 @@ describe("createCleanMcpEnvironment", () => {
describe("NPM_CONFIG_* filtering", () => {
it("filters out uppercase NPM_CONFIG_* variables", () => {
// #given
// given
process.env.NPM_CONFIG_REGISTRY = "https://private.registry.com"
process.env.NPM_CONFIG_CACHE = "/some/cache/path"
process.env.NPM_CONFIG_PREFIX = "/some/prefix"
process.env.PATH = "/usr/bin"
// #when
// when
const cleanEnv = createCleanMcpEnvironment()
// #then
// then
expect(cleanEnv.NPM_CONFIG_REGISTRY).toBeUndefined()
expect(cleanEnv.NPM_CONFIG_CACHE).toBeUndefined()
expect(cleanEnv.NPM_CONFIG_PREFIX).toBeUndefined()
@@ -36,17 +36,17 @@ describe("createCleanMcpEnvironment", () => {
})
it("filters out lowercase npm_config_* variables", () => {
// #given
// given
process.env.npm_config_registry = "https://private.registry.com"
process.env.npm_config_cache = "/some/cache/path"
process.env.npm_config_https_proxy = "http://proxy:8080"
process.env.npm_config_proxy = "http://proxy:8080"
process.env.HOME = "/home/user"
// #when
// when
const cleanEnv = createCleanMcpEnvironment()
// #then
// then
expect(cleanEnv.npm_config_registry).toBeUndefined()
expect(cleanEnv.npm_config_cache).toBeUndefined()
expect(cleanEnv.npm_config_https_proxy).toBeUndefined()
@@ -57,16 +57,16 @@ describe("createCleanMcpEnvironment", () => {
describe("YARN_* filtering", () => {
it("filters out YARN_* variables", () => {
// #given
// given
process.env.YARN_CACHE_FOLDER = "/yarn/cache"
process.env.YARN_ENABLE_IMMUTABLE_INSTALLS = "true"
process.env.YARN_REGISTRY = "https://yarn.registry.com"
process.env.NODE_ENV = "production"
// #when
// when
const cleanEnv = createCleanMcpEnvironment()
// #then
// then
expect(cleanEnv.YARN_CACHE_FOLDER).toBeUndefined()
expect(cleanEnv.YARN_ENABLE_IMMUTABLE_INSTALLS).toBeUndefined()
expect(cleanEnv.YARN_REGISTRY).toBeUndefined()
@@ -76,15 +76,15 @@ describe("createCleanMcpEnvironment", () => {
describe("PNPM_* filtering", () => {
it("filters out PNPM_* variables", () => {
// #given
// given
process.env.PNPM_HOME = "/pnpm/home"
process.env.PNPM_STORE_DIR = "/pnpm/store"
process.env.USER = "testuser"
// #when
// when
const cleanEnv = createCleanMcpEnvironment()
// #then
// then
expect(cleanEnv.PNPM_HOME).toBeUndefined()
expect(cleanEnv.PNPM_STORE_DIR).toBeUndefined()
expect(cleanEnv.USER).toBe("testuser")
@@ -93,14 +93,14 @@ describe("createCleanMcpEnvironment", () => {
describe("NO_UPDATE_NOTIFIER filtering", () => {
it("filters out NO_UPDATE_NOTIFIER variable", () => {
// #given
// given
process.env.NO_UPDATE_NOTIFIER = "1"
process.env.SHELL = "/bin/bash"
// #when
// when
const cleanEnv = createCleanMcpEnvironment()
// #then
// then
expect(cleanEnv.NO_UPDATE_NOTIFIER).toBeUndefined()
expect(cleanEnv.SHELL).toBe("/bin/bash")
})
@@ -108,7 +108,7 @@ describe("createCleanMcpEnvironment", () => {
describe("custom environment overlay", () => {
it("merges custom env on top of clean process.env", () => {
// #given
// given
process.env.PATH = "/usr/bin"
process.env.NPM_CONFIG_REGISTRY = "https://private.registry.com"
const customEnv = {
@@ -116,10 +116,10 @@ describe("createCleanMcpEnvironment", () => {
CUSTOM_VAR: "custom-value",
}
// #when
// when
const cleanEnv = createCleanMcpEnvironment(customEnv)
// #then
// then
expect(cleanEnv.PATH).toBe("/usr/bin")
expect(cleanEnv.NPM_CONFIG_REGISTRY).toBeUndefined()
expect(cleanEnv.MCP_API_KEY).toBe("secret-key")
@@ -127,30 +127,30 @@ describe("createCleanMcpEnvironment", () => {
})
it("custom env can override process.env values", () => {
// #given
// given
process.env.NODE_ENV = "development"
const customEnv = {
NODE_ENV: "production",
}
// #when
// when
const cleanEnv = createCleanMcpEnvironment(customEnv)
// #then
// then
expect(cleanEnv.NODE_ENV).toBe("production")
})
})
describe("undefined value handling", () => {
it("skips undefined values from process.env", () => {
// #given - process.env can have undefined values in TypeScript
// given - process.env can have undefined values in TypeScript
const envWithUndefined = { ...process.env, UNDEFINED_VAR: undefined }
Object.assign(process.env, envWithUndefined)
// #when
// when
const cleanEnv = createCleanMcpEnvironment()
// #then - should not throw and should not include undefined values
// then - should not throw and should not include undefined values
expect(cleanEnv.UNDEFINED_VAR).toBeUndefined()
expect(Object.values(cleanEnv).every((v) => v !== undefined)).toBe(true)
})
@@ -158,16 +158,16 @@ describe("createCleanMcpEnvironment", () => {
describe("mixed case handling", () => {
it("filters both uppercase and lowercase npm config variants", () => {
// #given - pnpm/yarn can set both cases simultaneously
// given - pnpm/yarn can set both cases simultaneously
process.env.NPM_CONFIG_CACHE = "/uppercase/cache"
process.env.npm_config_cache = "/lowercase/cache"
process.env.NPM_CONFIG_REGISTRY = "https://uppercase.registry.com"
process.env.npm_config_registry = "https://lowercase.registry.com"
// #when
// when
const cleanEnv = createCleanMcpEnvironment()
// #then
// then
expect(cleanEnv.NPM_CONFIG_CACHE).toBeUndefined()
expect(cleanEnv.npm_config_cache).toBeUndefined()
expect(cleanEnv.NPM_CONFIG_REGISTRY).toBeUndefined()
@@ -178,7 +178,7 @@ describe("createCleanMcpEnvironment", () => {
describe("EXCLUDED_ENV_PATTERNS", () => {
it("contains patterns for npm, yarn, and pnpm configs", () => {
// #given / #when / #then
// given / #when / #then
expect(EXCLUDED_ENV_PATTERNS.length).toBeGreaterThanOrEqual(4)
// Test that patterns match expected strings