fix(grok): surface plan mode approval in proposed plan cards #5409
Closedahmed-besic(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/5409/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:L
- apps/server/src/provider/acp/XAiAcpExtension.ts line 266OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -198,0 +246,21 @@246+export type XAiExitPlanModeOutcome = "approved" | "abandoned" | "request_changes";247+248+export interface XAiExitPlanModeResponse {249+ readonly outcome: XAiExitPlanModeOutcome;250+ readonly feedback?: string;251+}252+253+/**254+ * Client captured the plan for T3's proposed-plan card. Abandon the native255+ * Grok plan-approval gate so the turn unblocks; the user implements via T3 UI.256+ */257+export function makeXAiExitPlanModeCapturedResponse(feedback?: string): XAiExitPlanModeResponse {258+ return {259+ outcome: "abandoned",260+ feedback:261+ feedback ??262+ "The client captured your proposed plan. Stop here and wait for the user's feedback or implementation request in a later turn.",263+ };264+}265+266+/** True when a path is Grok's session plan file (…/plan.md). */
- apps/server/src/provider/Layers/GrokAdapter.ts line 560Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -495,3 +501,20 @@495501 );496502 });497503504+ /** Surface Grok plan.md as T3's proposed-plan card (while writing + on exit). */505+ const emitProposedPlanCompleted = (506+ ctx: GrokSessionContext,507+ turnId: TurnId | undefined,508+ stamp: { readonly eventId: EventId; readonly createdAt: string },509+ planMarkdown: string,510+ raw: { readonly method: string; readonly payload: unknown },511+ ) =>512+ Effect.gen(function* () {513+ const trimmed = planMarkdown.trim();514+ if (trimmed.length === 0) {515+ return;516+ }517+ if (ctx.lastKnownProposedPlanMarkdown === trimmed) {518+ return;519+ }520+ ctx.lastKnownProposedPlanMarkdown = trimmed;apps/server/src/provider/Layers/GrokAdapter.ts line 1007Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -855,3 +939,21 @@855939 rawPayload: event.rawPayload,856940 }),857941 );942+ // While plan mode is active, Grok writes plan.md via write/edit943+ // tools. Surface that as a proposed plan so the user can see it944+ // before exit_plan_mode (which only then opens the TUI gate).945+ const planMarkdown = extractGrokPlanMarkdownFromToolCallData(946+ event.toolCall.data,947+ );948+ if (planMarkdown) {949+ yield* emitProposedPlanCompleted(950+ ctx,951+ notificationTurnId,952+ stamp,953+ planMarkdown,954+ {955+ method: "session/update",956+ payload: event.rawPayload,957+ },958+ );959+ }apps/server/src/provider/acp/XAiAcpExtension.ts line 280Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -198,0 +256,21 @@256+ */257+export function makeXAiExitPlanModeCapturedResponse(feedback?: string): XAiExitPlanModeResponse {258+ return {259+ outcome: "abandoned",260+ feedback:261+ feedback ??262+ "The client captured your proposed plan. Stop here and wait for the user's feedback or implementation request in a later turn.",263+ };264+}265+266+/** True when a path is Grok's session plan file (…/plan.md). */267+export function isGrokPlanMarkdownPath(path: string | undefined | null): boolean {268+ if (typeof path !== "string") {269+ return false;270+ }271+ const normalized = path.trim().replace(/\\/g, "/");272+ if (normalized.length === 0) {273+ return false;274+ }275+ return normalized === "plan.md" || normalized.endsWith("/plan.md");276+}
- @@ -198,0 +296,21 @@296+ (typeof rawInput.file_path === "string" ? rawInput.file_path : undefined) ??297+ (typeof rawInput.path === "string" ? rawInput.path : undefined);298+ const content = typeof rawInput.content === "string" ? rawInput.content : undefined;299+ if (isGrokPlanMarkdownPath(filePath) && content && content.trim().length > 0) {300+ return content.trim();301+ }302+ }303+304+ const content = data.content;305+ if (Array.isArray(content)) {306+ for (const block of content) {307+ if (!isRecord(block) || block.type !== "diff") {308+ continue;309+ }310+ const path = typeof block.path === "string" ? block.path : undefined;311+ const newText = typeof block.newText === "string" ? block.newText : undefined;312+ if (isGrokPlanMarkdownPath(path) && newText && newText.trim().length > 0) {313+ return newText.trim();314+ }315+ }316+ }
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:
029eba3c-21c1-4c3e-a3af-1f8edd192f5cYou 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