feat(grok): plan mode via /plan text mapping #5424
ClosedEnzoTironi(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/5424/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
- @@ -181,0 +289,21 @@289+ : undefined;290+ return preferredMatch?._meta ?? models[0]?._meta;291+ };292+ const fromSession = pick(293+ input.sessionModels?.availableModels,294+ input.preferredModelId ?? input.sessionModels?.currentModelId,295+ );296+ if (fromSession !== undefined) return fromSession;297+ const initializeModelState = input.initializeMeta?.modelState;298+ if (isRecord(initializeModelState) && Array.isArray(initializeModelState.availableModels)) {299+ return pick(300+ initializeModelState.availableModels as ReadonlyArray<{301+ modelId: string;302+ _meta?: unknown;303+ }>,304+ input.preferredModelId ??305+ (typeof initializeModelState.currentModelId === "string"306+ ? initializeModelState.currentModelId307+ : undefined),308+ );309+ }@@ -140,0 +277,21 @@277+ started.initializeResult._meta &&278+ typeof started.initializeResult._meta === "object" &&279+ !Array.isArray(started.initializeResult._meta)280+ ? (started.initializeResult._meta as Record<string, unknown>)281+ : undefined;282+ const modelsFromSession = buildGrokDiscoveredModelsFromSessionModelState(283+ started.sessionSetupResult.models,284+ );285+ const modelsFromInitialize = buildGrokDiscoveredModelsFromSessionModelState(286+ initializeMeta?.modelState as EffectAcpSchema.SessionModelState | undefined,287+ );288+ const models = modelsFromSession.length > 0 ? modelsFromSession : modelsFromInitialize;289+ const initializeCommands = Array.isArray(initializeMeta?.availableCommands)290+ ? (291+ initializeMeta.availableCommands as ReadonlyArray<{292+ readonly name?: unknown;293+ readonly description?: unknown;294+ readonly input?: unknown;295+ }>296+ ).flatMap((command) => {297+ const name = typeof command.name === "string" ? command.name.trim() : "";@@ -181,0 +270,21 @@270+/** Live Grok model `_meta.reasoningEffort` after process spawn. */271+function reasoningEffortFromMeta(meta: unknown): string | undefined {272+ if (!isRecord(meta)) return undefined;273+ const raw = meta.reasoningEffort ?? meta.reasoning_effort;274+ return typeof raw === "string" && raw.trim() ? raw.trim() : undefined;275+}276+277+function preferredModelMeta(input: {278+ readonly sessionModels: EffectAcpSchema.SessionModelState | null | undefined;279+ readonly initializeMeta: Record<string, unknown> | undefined;280+ readonly preferredModelId: string | undefined;281+}): unknown {282+ const pick = (283+ models: ReadonlyArray<{ modelId: string; _meta?: unknown }> | undefined,284+ preferred: string | undefined,285+ ): unknown => {286+ if (!models || models.length === 0) return undefined;287+ const preferredMatch = preferred288+ ? models.find((model) => model.modelId === preferred)289+ : undefined;290+ return preferredMatch?._meta ?? models[0]?._meta;@@ -106,3 +110,4 @@106110 env: processEnv,107111 });108112113+ const commandCatalogRef = yield* Ref.make({@@ -47,0 +86,21 @@86+87+/**88+ * Grok has no ACP session modes on live 0.2.x. Plan mode is entered via the89+ * `/plan` slash command (see Grok Build user guide). Map T3 interactionMode90+ * onto that command so Plan/Build in the composer does real work.91+ */92+export function applyGrokPlanModeToPromptText(input: {93+ readonly text: string | undefined;94+ readonly interactionMode: "plan" | "default" | undefined;95+}): string | undefined {96+ const trimmed = input.text?.trim();97+ if (!trimmed) {98+ return trimmed;99+ }100+ if (input.interactionMode === "plan") {101+ if (/^\/plan(?:\s|$)/i.test(trimmed)) {102+ return trimmed;103+ }104+ return `/plan ${trimmed}`;105+ }106+ return trimmed;
- @@ -1206,3 +1704,18 @@12061704 }).pipe(12071705 Effect.ensuring(12081706 Effect.gen(function* () {1707+ // Usage must surface even when xAI settled the turn before the prompt RPC.1708+ if (yield* Ref.get(promptRpcSucceeded)) {1709+ const promptResult = yield* Ref.get(promptResultRef);1710+ if (promptResult !== undefined) {1711+ yield* withThreadLock(1712+ input.threadId,1713+ Effect.gen(function* () {1714+ const live = sessions.get(input.threadId);1715+ if (!live || live.stopped || live.acpSessionId !== prepared.acpSessionId) {1716+ return;1717+ }1718+ yield* offerGrokPromptTokenUsage(live, prepared.turnId, promptResult._meta);1719+ }),1720+ ).pipe(Effect.catch(() => Effect.void));1721+ }@@ -867 +1280,21 @@8671280 text: event.text,1281+ streamKind: event.streamKind,1282+ rawPayload: event.rawPayload,1283+ }),1284+ );1285+ return;1286+ case "UsageUpdated": {1287+ const maxTokens =1288+ event.usage.size > 01289+ ? event.usage.size1290+ : ctx.contextWindowTokens !== undefined && ctx.contextWindowTokens > 01291+ ? ctx.contextWindowTokens1292+ : undefined;1293+ yield* offerRuntimeEvent(1294+ makeAcpTokenUsageEvent({1295+ stamp,1296+ provider: PROVIDER,1297+ threadId: ctx.threadId,1298+ turnId: notificationTurnId,1299+ usedTokens: event.usage.used,1300+ ...(maxTokens !== undefined ? { maxTokens } : {}),
EnzoTironi(GitHub profile, opens in a new tab) closed this
- @@ -47,0 +78,21 @@78+ return (79+ getProviderOptionStringSelectionValue(selections, "reasoningEffort") ??80+ getProviderOptionStringSelectionValue(selections, "reasoning") ??81+ getProviderOptionStringSelectionValue(selections, "effort")82+ );83+}84+85+86+87+/**88+ * Grok has no ACP session modes on live 0.2.x. Plan mode is entered via the89+ * `/plan` slash command (see Grok Build user guide). Map T3 interactionMode90+ * onto that command so Plan/Build in the composer does real work.91+ */92+export function applyGrokPlanModeToPromptText(input: {93+ readonly text: string | undefined;94+ readonly interactionMode: "plan" | "default" | undefined;95+}): string | undefined {96+ const trimmed = input.text?.trim();97+ if (!trimmed) {98+ return trimmed;@@ -913,0 +1368,21 @@1368+ }1369+ const restart = {1370+ cwd: ctx.session.cwd,1371+ runtimeMode: ctx.session.runtimeMode,1372+ resumeCursor: ctx.session.resumeCursor,1373+ };1374+ yield* stopSessionInternal(ctx);1375+ return { _tag: "restart" as const, ...restart };1376+ }1377+ return { _tag: "continue" as const };1378+ }),1379+ );1380+ if (restartDecision._tag === "restart") {1381+ yield* startSession({1382+ threadId: input.threadId,1383+ provider: PROVIDER,1384+ cwd: restartDecision.cwd,1385+ runtimeMode: restartDecision.runtimeMode,1386+ ...(restartDecision.resumeCursor ? { resumeCursor: restartDecision.resumeCursor } : {}),1387+ ...(input.modelSelection ? { modelSelection: input.modelSelection } : {}),1388+ });
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:
5ae81d2b-494e-44e5-b86d-4bfee745feb7You 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