← Back to PRs

#12956: fix: guard .trim() calls on potentially undefined workspaceDir

by omair445 open 2026-02-10 00:04 View on GitHub →
agents size: XS
## Summary Fixes sub-agent spawning crashing with `TypeError: Cannot read properties of undefined (reading 'trim')` when agent config includes `workspace: null`. ## Problem When an agent is configured with `workspace: null`, `resolveAgentConfig()` correctly resolves it to `undefined`. However, downstream functions in the skills subsystem call `.trim()` directly on the workspace string without null guards, causing a crash during sub-agent initialization. ## Changes **`src/agents/skills/plugin-skills.ts`** - `resolvePluginSkillDirs()`: `(params.workspaceDir ?? "").trim()` **`src/agents/skills/refresh.ts`** - `resolveWatchPaths()`: `(workspaceDir ?? "").trim()` - `ensureSkillsWatcher()`: `(params.workspaceDir ?? "").trim()` **`src/agents/skills/refresh.test.ts`** - New test: verifies `ensureSkillsWatcher` doesn't crash with `undefined` workspaceDir ## Testing - All 2 skills refresh tests pass ✅ - 🤖 AI-assisted (Claude) — fully tested Closes #12888 <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> This PR prevents crashes in the skills subsystem when an agent config resolves `workspace` to `undefined` by guarding `.trim()` calls in skills refresh and plugin skill directory resolution. Changes are localized to the skills watcher setup (`src/agents/skills/refresh.ts`) and plugin skill dir resolution (`src/agents/skills/plugin-skills.ts`), plus a new Vitest case asserting `ensureSkillsWatcher` doesn’t throw when `workspaceDir` is undefined. <h3>Confidence Score: 4/5</h3> - This PR is likely safe to merge, but the public function types no longer match the new optional-handling behavior. - Runtime crash is addressed by null-guarding `.trim()`; however, keeping parameters typed as `string` while treating them as optional reduces compile-time protection and may allow similar bugs to recur without TypeScript catching them. - src/agents/skills/refresh.ts, src/agents/skills/plugin-skills.ts, src/agents/skills/refresh.test.ts <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs