Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(grok): add /compact slash command and compaction feedback #5412

Closedahmed-besic(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5412/headopened View on GitHub

What 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:

  1. The command never appeared in the composer / menu for Grok (unlike Claude provider slash commands)
  2. When compaction finished, Grok emitted _x.ai/session_notification with auto_compact_completed and T3 ignored it — so the turn looked empty with no success feedback

This PR:

  • Advertises /compact on 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_notification for auto_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 /compact may run but leaves no visible feedback.
  • After: /compact appears 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 /compact emits _x.ai/session_notification auto_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.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b83aa60787db919701775933d70d055971723135. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add /compact slash command and compaction feedback to Grok provider

  • Adds a compact slash command to the Grok provider's snapshot metadata so clients can surface it in the UI.
  • Extends GrokAdapter to handle x.ai/session_notification and _x.ai/session_notification ACP events, translating auto_compact_completed notifications into thread.state.changed events with a compacted payload including tokensBefore, tokensAfter, and optional summaryPreview.
  • Adds XAiAcpExtension with schema validation and an extractXAiAutoCompactCompleted utility 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.
Macroscope summarized b83aa60.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 3f214e47-6a63-4ed9-aabc-344889363f67

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Approvability

      Verdict: Needs human review

      This PR introduces a new user-facing feature (the /compact slash command and compaction feedback UI). New features adding user-facing capabilities warrant human review regardless of how well-scoped they are.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Superseded by https://github.com/pingdotgg/t3code/pull/9293, which adds /compact (with capability gating and compaction feedback) across providers including Grok.

    5. juliusmarminge closed this

Sign in to join this conversation.