feat: support additionalContext in PreCompact hook#4980
Open
abwuge wants to merge 2 commits intomicrosoft:mainfrom
Open
feat: support additionalContext in PreCompact hook#4980abwuge wants to merge 2 commits intomicrosoft:mainfrom
abwuge wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Allow PreCompact hook to inject additional context into the summarization prompt, matching the pattern used by other hooks (PreToolUse, PostToolUse, SessionStart, SubagentStart, UserPromptSubmit). Changes: - Add IPreCompactHookSpecificCommandOutput type in hookCommandTypes.ts - Add PreCompactHookOutput interface in chatHookService.ts - Modify executePreCompactHook() to collect additionalContext from hook results - Merge hook additionalContext into summarizationInstructions in summarizeHistory() - Add unit tests for prompt rendering with summarizationInstructions - Add integration tests for PreCompact hook flow in preCompactHook.spec.tsx
Author
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the PreCompact hook flow so hook scripts can inject additionalContext into the conversation compaction/summarization prompt, aligning PreCompact with other hook types that can contribute extra prompt context.
Changes:
- Added PreCompact hook-specific output typing (
additionalContext) and exposed it viaPreCompactHookOutput. - Updated summarization flow to execute PreCompact hooks and merge returned
additionalContextinto summarization instructions. - Added unit + integration tests to validate prompt rendering and end-to-end PreCompact hook behavior.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/platform/chat/common/hookCommandTypes.ts | Defines PreCompact hook-specific command output shape (additionalContext). |
| src/platform/chat/common/chatHookService.ts | Adds PreCompactHookOutput type to represent hook output contract. |
| src/extension/prompts/node/agent/summarizedConversationHistory.tsx | Executes PreCompact hook before summarization and merges returned additionalContext into summarization instructions. |
| src/extension/prompts/node/agent/test/summarization.spec.tsx | Adds unit coverage for rendering summarizationInstructions in the summarization prompt. |
| src/extension/prompts/node/agent/test/preCompactHook.spec.tsx | Adds integration coverage for PreCompact hook invocation and additionalContext injection into LLM prompt. |
src/extension/prompts/node/agent/summarizedConversationHistory.tsx
Outdated
Show resolved
Hide resolved
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.
Allow PreCompact hook to inject additional context into the summarization prompt, matching the pattern used by other hooks (PreToolUse, PostToolUse, SessionStart, SubagentStart, UserPromptSubmit).
Changes: