Skip to content

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

Open
ahmed-besic wants to merge 1 commit into
pingdotgg:mainfrom
ahmed-besic:feat/grok-compact-slash
Open

feat(grok): add /compact slash command and compaction feedback#5412
ahmed-besic wants to merge 1 commit into
pingdotgg:mainfrom
ahmed-besic:feat/grok-compact-slash

Conversation

@ahmed-besic

@ahmed-besic ahmed-besic commented Aug 5, 2026

Copy link
Copy Markdown

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.ts38 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

Low Risk
Additive Grok ACP extension handling and provider metadata; no auth, billing, or shared ingestion logic changes beyond wiring an existing compacted state event.

Overview
Exposes Grok’s manual /compact flow in T3 and turns Grok’s compaction completion signal into the same Context compacted work-log feedback other providers already get.

The Grok provider snapshot now advertises a compact slash command (optional hint for what to preserve) on every probe path so it shows up in the composer / menu. On the wire, GrokAdapter listens for x.ai/session_notification / _x.ai/session_notification, parses auto_compact_completed via new XAiSessionNotification / extractXAiAutoCompactCompleted helpers, and emits thread.state.changed with state: "compacted" plus token before/after (and optional summary preview)—reusing existing ingestion for the work log. The ACP mock agent simulates /compact prompts by emitting that notification; adapter and extension tests cover the mapping.

Reviewed by Cursor Bugbot for commit c3b7351. Bugbot is set up for automated code reviews on this repo. Configure here.

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 c3b7351.

Grok 4.5 has a large context window but quality drops well before the limit.
Grok Build already supports manual /compact; T3 could send the same prompt
text but never advertised the command and ignored auto_compact_completed
notifications, so users got no feedback.

Advertise /compact on Grok provider slash commands and map
_x.ai/session_notification auto_compact_completed to thread.state.changed
compacted so the existing "Context compacted" work-log row appears.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

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: 1cf53bb9-9367-46e1-9c34-027fe842f3d9

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.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 5, 2026
@macroscopeapp

macroscopeapp Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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.

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

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant