feat(grok): native ACP parity (catalog, effort, usage, plan, multi-agent, compact) #5503
ClosedEnzoTironi(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/5503/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/provider/acp/GrokAcpSupport.ts line 122Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -47,0 +101,21 @@101+}): string | undefined {102+ const trimmed = input.text?.trim();103+ if (input.interactionMode === "plan") {104+ if (!trimmed) {105+ return "/plan";106+ }107+ if (/^\/plan(?:\s|$)/i.test(trimmed)) {108+ return trimmed;109+ }110+ return `/plan ${trimmed}`;111+ }112+ // Build (default): exit Grok plan mode when we still believe it is active.113+ if (input.planModeActive && input.interactionMode === "default") {114+ if (!trimmed) {115+ return "/default";116+ }117+ if (/^\/default(?:\s|$)/i.test(trimmed)) {118+ return trimmed;119+ }120+ return `/default ${trimmed}`;121+ }apps/server/src/provider/Layers/GrokAdapter.ts line 1693OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -952,2 +1674,20 @@1674+ cause,1675+ ),1676+ });1677+ // Only sticky-update effort when set_model had a model target1678+ // (effort-only with no model id is a no-op and must not claim apply).1679+ if (appliedEffort !== undefined && currentModelId !== undefined) {1680+ ctx.processReasoningEffort = appliedEffort;1681+ }9521682953- const text = input.input?.trim();1683+ const text = applyGrokPlanModeToPromptText({1684+ text: input.input?.trim(),1685+ interactionMode: input.interactionMode,1686+ planModeActive: ctx.planModeActive,1687+ });1688+ // Track local plan-mode state so Build can exit with /default.1689+ if (input.interactionMode === "plan") {1690+ ctx.planModeActive = true;1691+ } else if (input.interactionMode === "default" && ctx.planModeActive) {1692+ ctx.planModeActive = false;1693+ }
- apps/server/src/provider/acp/XAiAcpExtension.ts lines 291 to 291OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -198,0 +271,21 @@271+ feedback ??272+ "The client captured your proposed plan. Stop here and wait for the user's feedback or implementation request in a later turn.",273+ };274+}275+276+/**277+ * True when a path is Grok's session plan file under278+ * `~/.grok/sessions/<encoded-cwd>/<session-id>/plan.md`.279+ * Requires at least two path segments after `.grok/sessions/` so workspace280+ * files like `/repo/.grok/sessions/demo/plan.md` are rejected.281+ */282+export function isGrokPlanMarkdownPath(path: string | undefined | null): boolean {283+ if (typeof path !== "string") {284+ return false;285+ }286+ const normalized = path.trim().replace(/\\/g, "/");287+ if (normalized.length === 0) {288+ return false;289+ }290+ // Real layout: ~/.grok/sessions/<encoded-cwd>/<session-id>/plan.md291+ return /(?:^|\/)\.grok\/sessions\/[^/]+\/.+\/plan\.md$/i.test(normalized);apps/server/src/provider/Layers/GrokProvider.ts line 309OutdatedResolvedby EnzoTironi(GitHub profile, opens in a new tab)@@ -137,4 +295,15 @@137295 clientInfo: { name: "t3-code-provider-probe", version: "0.0.0" },138296 });139297 const started = yield* acp.start();140- return buildGrokDiscoveredModelsFromSessionModelState(started.sessionSetupResult.models);298+ // Prefer modelState from session setup; fall back to initialize _meta (live wire).299+ const initializeMeta =300+ started.initializeResult._meta &&301+ typeof started.initializeResult._meta === "object" &&302+ !Array.isArray(started.initializeResult._meta)303+ ? (started.initializeResult._meta as Record<string, unknown>)304+ : undefined;305+ const modelsFromSession = buildGrokDiscoveredModelsFromSessionModelState(306+ started.sessionSetupResult.models,307+ );308+ const rawInitializeModelState = initializeMeta?.modelState;309+ const initializeModelState =apps/server/src/provider/Layers/GrokAdapter.ts line 344Resolvedby EnzoTironi(GitHub profile, opens in a new tab)@@ -181,0 +317,21 @@317+ if (fromSession !== undefined) return fromSession;318+ const initializeModelState = input.initializeMeta?.modelState;319+ if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) {320+ const availableModels = initializeModelState.availableModels.flatMap((entry) => {321+ if (!isRecord(entry) || typeof entry.modelId !== "string") {322+ return [] as Array<{ modelId: string; _meta?: unknown }>;323+ }324+ return [{ modelId: entry.modelId, _meta: entry._meta }];325+ });326+ return pick(327+ availableModels,328+ input.preferredModelId ??329+ (typeof initializeModelState.currentModelId === "string"330+ ? initializeModelState.currentModelId331+ : undefined),332+ );333+ }334+ return undefined;335+}336+337+function parseGrokAvailableCommandsFromMeta(
- apps/server/src/provider/acp/AcpRuntimeModel.ts line 697Resolvedby EnzoTironi(GitHub profile, opens in a new tab)@@ -577,0 +677,21 @@677+ const used = Number.isFinite(upd.used) && upd.used >= 0 ? Math.trunc(upd.used) : undefined;678+ if (used === undefined) {679+ break;680+ }681+ // Live Grok may omit size; consumers fall back to model totalContextTokens.682+ const size = Number.isFinite(upd.size) && upd.size >= 0 ? Math.trunc(upd.size) : 0;683+ const cost = upd.cost;684+ events.push({685+ _tag: "UsageUpdated",686+ usage: {687+ used,688+ size,689+ ...(cost && typeof cost.amount === "number" && typeof cost.currency === "string"690+ ? { costAmount: cost.amount, costCurrency: cost.currency }691+ : {}),692+ },693+ rawPayload: params,694+ });695+ break;696+ }697+ case "config_option_update": {
- @@ -1096,3 +1858,8 @@10961858 input.threadId,10971859 Effect.gen(function* () {10981860 const ctx = yield* requireSession(input.threadId);1861+ // Prompt RPC succeeded — apply plan enter/exit only now so a failed1862+ // prep or send cannot leave local planModeActive desynced from Grok.1863+ if (prepared.planModeUpdate !== undefined) {1864+ ctx.planModeActive = prepared.planModeUpdate;1865+ }
t3dotgg(GitHub profile, opens in a new tab) 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:
8dbfcbe4-b12e-4900-b5a2-25332034e50cYou 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