#19707: fix(agents): apply per-agent skills filter to all run paths
agents
size: M
experienced-contributor
Cluster:
Skill Enhancements and Fixes
## Summary
- Thread `resolveAgentSkillsFilter()` through the embedded runner attempt, compaction, and auto-reply command system-prompt paths so that agents with a configured `skillsFilter` only see their allowed skills in prompts and env overrides
- Add `skillFilter` parameter to `resolveSkillsPromptForRun()` and `buildWorkspaceSkillSnapshot()` so downstream callers can pass a per-agent allowlist
- Prefer explicit `agentId` over session-key derivation when resolving the skill filter in `runEmbeddedAttempt`, matching the existing `hookAgentId` fallback order
- Rename test files from `.e2e.test.ts` to `.test.ts` so they're picked up by vitest, and add 18 unit tests covering filter resolution, snapshot building, and prompt generation
## Test plan
- [x] `resolveAgentSkillsFilter` returns configured allowlist per agent and `undefined` when unconfigured
- [x] `buildWorkspaceSkillSnapshot` filters skills and prompt content when `skillFilter` is provided
- [x] `resolveSkillsPromptForRun` respects `skillFilter` for both snapshot and entry-based paths
- [x] All 18 tests pass via `vitest run`
- [x] `pnpm build && pnpm check` clean
Closes #10546
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
This PR threads the per-agent `skillsFilter` through the three remaining run paths that were previously missing it: the embedded runner attempt, the compaction path, and the auto-reply commands system prompt. The changes are consistent and correct:
- In `attempt.ts`, the agent ID is resolved with the same fallback order as the existing `hookAgentId` (prefer explicit `agentId` param, then derive from `sessionKey`).
- In `compact.ts`, which lacks an `agentId` param, it correctly falls back to `resolveSessionAgentIds` from `sessionKey`.
- In `commands-system-prompt.ts`, the `sessionAgentId` resolution was moved earlier so the `skillFilter` can be passed to `buildWorkspaceSkillSnapshot`.
- The `resolveSkillsPromptForRun` and `buildWorkspaceSkillSnapshot` APIs gained a `skillFilter` parameter for callers to pass per-agent allowlists.
- Test files were renamed from `.e2e.test.ts` to `.test.ts` to be picked up by vitest, and 18 new unit tests were added covering the filter resolution, snapshot building, and prompt generation.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge — it correctly threads skill filtering through all run paths with no behavioral regressions.
- Score of 4 reflects clean, focused changes that correctly propagate the per-agent skill filter to all three previously-unfiltered paths. The snapshot path was already handling filters correctly at the construction site. No logic errors found. Minor redundant double-filtering is idempotent and harmless. Good test coverage with 18 new unit tests. Only reason it's not 5 is the minor code redundancy in how entries are pre-filtered then the same filter is passed again downstream.
- No files require special attention — the production code changes in attempt.ts, compact.ts, and commands-system-prompt.ts are all consistent and well-tested.
<sub>Last reviewed commit: d9cf6ae</sub>
<!-- greptile_other_comments_section -->
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
<!-- /greptile_comment -->
Most Similar PRs
#12076: fix(skills): recursive directory filtering to actually exclude venv...
by xiaoyaner0201 · 2026-02-08
83.7%
#10016: fix: prevent FD exhaustion from skill watcher scanning artifact trees
by oldeucryptoboi · 2026-02-06
80.4%
#12956: fix: guard .trim() calls on potentially undefined workspaceDir
by omair445 · 2026-02-10
80.3%
#22198: fix(skills): treat empty allowBundled array as block-all
by haitao-sjsu · 2026-02-20
79.8%
#21521: fix: re-resolve skill paths at runtime for cross-machine portability
by mmaghsoodnia · 2026-02-20
79.4%
#14023: fix: filter skills watcher to relevant file types to prevent FD exh...
by funmerlin · 2026-02-11
78.6%
#23749: fix some issues
by tronpis · 2026-02-22
78.5%
#21839: fix(skills): allowBundled: [] now blocks all bundled skills
by hydro13 · 2026-02-20
78.4%
#9221: fix(skills): use skillKey for env config lookup in snapshots
by gavinbmoore · 2026-02-05
78.1%
#21727: skills: treat allowBundled [] as denylist for bundled skills
by AIflow-Labs · 2026-02-20
77.7%