feat: support additionalContext in PreCompact hook#4980
feat: support additionalContext in PreCompact hook#4980abwuge 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
@microsoft-github-policy-service agree |
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. |
|
Can you open an issue with a description of what you want to add and why? |
|
Superseded by microsoft/vscode#308297 |
|
Actually if you want to be sure that your PR is attributed to your account, you could open the new PR on vscode yourself. We are moving copilot-chat sources to the vscode repo. |
Thank you. PR attribution isn’t a big concern for me. |
Allow PreCompact hook to inject additional context into the summarization prompt, matching the pattern used by other hooks (PreToolUse, PostToolUse, SessionStart, SubagentStart, UserPromptSubmit).
Changes: