Skip to content

feat: support additionalContext in PreCompact hook#4980

Open
abwuge wants to merge 2 commits intomicrosoft:mainfrom
abwuge:feat/precompact-additional-context
Open

feat: support additionalContext in PreCompact hook#4980
abwuge wants to merge 2 commits intomicrosoft:mainfrom
abwuge:feat/precompact-additional-context

Conversation

@abwuge
Copy link
Copy Markdown

@abwuge abwuge commented Apr 4, 2026

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

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
Copilot AI review requested due to automatic review settings April 4, 2026 15:28
@abwuge
Copy link
Copy Markdown
Author

abwuge commented Apr 4, 2026

@abwuge please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 via PreCompactHookOutput.
  • Updated summarization flow to execute PreCompact hooks and merge returned additionalContext into 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants