feat(grok): add /compact slash command and compaction feedback #5412
main fromrefs/pull/5412/head·opened View on GitHubWhat Changed#
Grok Build already has a first-class /compact [context] command to manually compress conversation history. T3 could technically send that text as a prompt (Grok ACP treats /compact as the compact command), but:
- The command never appeared in the composer
/menu for Grok (unlike Claude provider slash commands) - When compaction finished, Grok emitted
_x.ai/session_notificationwithauto_compact_completedand T3 ignored it — so the turn looked empty with no success feedback
This PR:
- Advertises
/compacton the Grok provider snapshot as a provider slash command (Grok-only; optional note for what to preserve) - Handles
x.ai/session_notification/_x.ai/session_notificationforauto_compact_completed - Emits
thread.state.changed{ state: "compacted" }, which the existing ingestion path turns into the Context compacted work-log row (same UI as Claude/Codex compaction)
Why#
Grok 4.5’s context window is large (500k tokens), but model quality typically degrades well before that — often around the ~200k range in long agent threads. Auto-compact only kicks in near the window limit, so long productive Grok threads in T3 can get “soft-bad” (worse tool use, more drift) without an obvious way to reclaim context mid-session.
Grok Build already ships manual /compact for this reason. T3 should expose the same control so users can compact proactively instead of only when auto-compact finally runs (or when quality has already slipped). Showing Context compacted makes the action trustworthy — without it, sending /compact looks like a no-op.
Wire format (Grok 0.2.118 ACP): there is no working dedicated compact RPC in this version; manual compact is session/prompt with text /compact…, then auto_compact_completed on the session notification channel.
UI Changes#
- Before: Grok
/menu has no compact entry; sending/compactmay run but leaves no visible feedback. - After:
/compactappears under Grok provider commands; successful compact shows the existing Context compacted work-log entry (with token before/after in event detail).
No new UI components — reuses provider slash commands + context-compaction activity.
Validation#
vp test apps/server/src/provider/acp/XAiAcpExtension.test.ts apps/server/src/provider/Layers/GrokProvider.test.ts apps/server/src/provider/Layers/GrokAdapter.test.ts— 38 passed- Live ACP probe:
session/prompt/compactemits_x.ai/session_notificationauto_compact_completed - Manual T3 web (feat/grok-compact-slash): Grok menu shows compact; after send, Context compacted appears in the work log
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes (happy to add)
- A video is not applicable (no animation/timing change)
Made by Grok Build via the Grok Build harness while working on T3 Code.
Note
Medium Risk Touches Grok ACP session-notification handling and runtime event emission, which can affect turn/work-log feedback if mapping is wrong. Risk is moderated by focused tests and reuse of the existing compacted ingestion path.
Overview
Grok users can now discover and run /compact from the composer slash menu, and successful compaction shows the same Context compacted work-log feedback already used by other providers.
Advertises a compact slash command on every Grok provider snapshot (with an optional preserve-context hint). Handles x.ai/session_notification / _x.ai/session_notification auto_compact_completed events in GrokAdapter, emitting thread.state.changed with state: "compacted" plus token before/after detail.
Adds XAiSessionNotification parsing/extractXAiAutoCompactCompleted in XAiAcpExtension, and updates the ACP mock agent so /compact prompts emit the matching notification for end-to-end tests.
Note
Add /compact slash command and compaction feedback to Grok provider#
- Adds a
compactslash command to the Grok provider's snapshot metadata so clients can surface it in the UI. - Extends
GrokAdapterto handlex.ai/session_notificationand_x.ai/session_notificationACP events, translatingauto_compact_completednotifications intothread.state.changedevents with acompactedpayload includingtokensBefore,tokensAfter, and optionalsummaryPreview. - Adds
XAiAcpExtensionwith schema validation and anextractXAiAutoCompactCompletedutility to parse and normalize compaction notification payloads. - Updates the ACP mock agent to emit a session notification when a prompt starts with
/compact, enabling end-to-end integration testing.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
Approvability#
Verdict: Needs human review
This PR introduces a new user-facing feature (the
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules)./compactslash command and compaction feedback UI). New features adding user-facing capabilities warrant human review regardless of how well-scoped they are.Superseded by https://github.com/pingdotgg/t3code/pull/9293, which adds
/compact(with capability gating and compaction feedback) across providers including Grok.juliusmarminge closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
3f214e47-6a63-4ed9-aabc-344889363f67You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share