fix(hooks): skip file-context injection for subagents without the MCP tools (closes #3324)#3341
Open
rodboev wants to merge 5 commits into
Open
fix(hooks): skip file-context injection for subagents without the MCP tools (closes #3324)#3341rodboev wants to merge 5 commits into
rodboev wants to merge 5 commits into
Conversation
Contributor
Greptile SummaryThis PR updates file-context handling so subagent reads do not receive main-session MCP guidance. The main changes are:
Confidence Score: 5/5Safe to merge with minimal risk. The functional change is a small early-return guard aligned with the existing summarize hook pattern. Tests cover subagent inputs, main-session inputs, and agent-type-only inputs. No blocking correctness or security issues were identified. No files require special attention.
What T-Rex did
Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant Hook as fileContextHandler
participant Logger as logger
participant FS as stat/file gate
participant Worker as worker observations API
Hook->>Hook: receive normalized hook input
alt input.agentId present
Hook->>Logger: debug skip with session/agent context
Hook-->>Hook: return continue + suppressOutput
else main session or agentType only
Hook->>Hook: collect file_path/filePaths
Hook->>FS: validate candidate files and size gate
Hook->>Worker: fetch observations by file candidates
Worker-->>Hook: observations
Hook-->>Hook: return additionalContext when timelines exist
end
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant Hook as fileContextHandler
participant Logger as logger
participant FS as stat/file gate
participant Worker as worker observations API
Hook->>Hook: receive normalized hook input
alt input.agentId present
Hook->>Logger: debug skip with session/agent context
Hook-->>Hook: return continue + suppressOutput
else main session or agentType only
Hook->>Hook: collect file_path/filePaths
Hook->>FS: validate candidate files and size gate
Hook->>Worker: fetch observations by file candidates
Worker-->>Hook: observations
Hook-->>Hook: return additionalContext when timelines exist
end
Reviews (4): Last reviewed commit: "test(sync): restore MCP client modules a..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The file-context Read hook currently injects main-session MCP guidance into subagents even when those subagents cannot use the referenced tools. This change mirrors the existing summarize-hook policy by skipping file-context injection whenever
agentIdis present, while leaving main-session Reads and agent-type-only inputs unchanged.Closes #3324
Why
The repository already treats
agentIdas the authoritative subagent discriminator insummarize.ts.file-context.tssimply never adopted the same guard, so it still performs timeline lookup and output injection for subagent Reads. The smallest correct fix is to mirror that existing policy boundary, including the debug breadcrumb that identifies the skip and its agent context.Scope
This PR changes
file-context.ts, its focused tests, and the generated hook bundles changed bynpm run build:plugin/scripts/mcp-server.cjs,plugin/scripts/server-service.cjs, andplugin/scripts/worker-service.cjs. It does not change summarize behavior, observation storage, SessionStart context, generated UI assets, or broader configuration for subagent directionality.Risk
Low. The new guard keys on the same
agentIdfield already used by another hook handler. Main-session Reads, agent-type-only inputs, excluded-project skips, and empty-path skips remain unchanged.Verification
bun test tests/hooks/file-context.test.tsnpm run typechecknpm run buildnpm run lint:hook-ionpm run lint:spawn-envnpm run strip-comments:checkmatched the 316-file check-mode baselineCloses #3324