Skip to content

Commit 2447738

Browse files
committed
feat(grok): plan mode via /plan text mapping
1 parent 6c766ad commit 2447738

5 files changed

Lines changed: 63 additions & 4 deletions

File tree

‎apps/server/src/provider/Layers/GrokAdapter.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import {
6161
currentGrokModelIdFromSessionSetup,
6262
makeGrokAcpRuntime,
6363
resolveGrokAcpBaseModelId,
64+
applyGrokPlanModeToPromptText,
6465
resolveGrokReasoningEffortSelection,
6566
type GrokAcpSpawnOptions,
6667
} from "../acp/GrokAcpSupport.ts";
@@ -1440,7 +1441,10 @@ export function makeGrokAdapter(grokSettings: GrokSettings, options?: GrokAdapte
14401441
),
14411442
});
14421443

1443-
const text = input.input?.trim();
1444+
const text = applyGrokPlanModeToPromptText({
1445+
text: input.input?.trim(),
1446+
interactionMode: input.interactionMode,
1447+
});
14441448
const imagePromptParts = yield* Effect.forEach(
14451449
input.attachments ?? [],
14461450
(attachment) =>

‎apps/server/src/provider/Layers/GrokProvider.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("buildInitialGrokProviderSnapshot", () => {
3737
expect(snapshot.version).toBeNull();
3838
expect(snapshot.message).toContain("Checking Grok");
3939
expect(snapshot.requiresNewThreadForModelChange).toBe(false);
40-
expect(snapshot.showInteractionModeToggle).toBe(false);
40+
expect(snapshot.showInteractionModeToggle).toBe(true);
4141
}),
4242
);
4343
});

‎apps/server/src/provider/Layers/GrokProvider.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ import { makeGrokAcpRuntime, resolveGrokAcpBaseModelId } from "../acp/GrokAcpSup
3535

3636
const GROK_PRESENTATION = {
3737
displayName: "Grok",
38-
// Live 0.2.x: plan toggle lands in later stack layer; set_model is in-session.
39-
showInteractionModeToggle: false,
38+
// Plan/Build maps to Grok's `/plan` command on send (no ACP session modes).
39+
// Live 0.2.x: session/set_model works in-session; no forced new thread.
40+
showInteractionModeToggle: true,
4041
requiresNewThreadForModelChange: false,
4142
} as const;
4243
const EMPTY_CAPABILITIES: ModelCapabilities = createModelCapabilities({

‎apps/server/src/provider/acp/GrokAcpSupport.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as EffectAcpErrors from "effect-acp/errors";
55
import {
66
applyGrokAcpConfigSelections,
77
applyGrokAcpModelSelection,
8+
applyGrokPlanModeToPromptText,
89
buildGrokAcpSpawnInput,
910
resolveGrokAcpBaseModelId,
1011
resolveGrokReasoningEffortSelection,
@@ -199,4 +200,35 @@ describe("applyGrokAcpConfigSelections", () => {
199200
);
200201
});
201202

203+
describe("applyGrokPlanModeToPromptText", () => {
204+
it("prefixes /plan when interactionMode is plan", () => {
205+
expect(applyGrokPlanModeToPromptText({ text: "design auth", interactionMode: "plan" })).toBe(
206+
"/plan design auth",
207+
);
208+
});
209+
210+
it("does not double-prefix /plan", () => {
211+
expect(applyGrokPlanModeToPromptText({ text: "/plan already", interactionMode: "plan" })).toBe(
212+
"/plan already",
213+
);
214+
});
215+
216+
it("accepts case-insensitive existing /Plan prefix", () => {
217+
expect(applyGrokPlanModeToPromptText({ text: "/Plan design", interactionMode: "plan" })).toBe(
218+
"/Plan design",
219+
);
220+
});
221+
222+
it("leaves default mode text unchanged", () => {
223+
expect(applyGrokPlanModeToPromptText({ text: "hello", interactionMode: "default" })).toBe(
224+
"hello",
225+
);
226+
});
202227

228+
it("returns undefined/empty for blank plan prompts", () => {
229+
expect(applyGrokPlanModeToPromptText({ text: undefined, interactionMode: "plan" })).toBe(
230+
undefined,
231+
);
232+
expect(applyGrokPlanModeToPromptText({ text: " ", interactionMode: "plan" })).toBe("");
233+
});
234+
});

‎apps/server/src/provider/acp/GrokAcpSupport.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ export function resolveGrokReasoningEffortSelection(
8484

8585

8686

87+
/**
88+
* Grok has no ACP session modes on live 0.2.x. Plan mode is entered via the
89+
* `/plan` slash command (see Grok Build user guide). Map T3 interactionMode
90+
* 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;
107+
}
108+
87109
function resolveGrokAuthMethodId(environment: NodeJS.ProcessEnv | undefined): string {
88110
return environment?.[GROK_API_KEY_ENV]?.trim()
89111
? GROK_AUTH_METHOD_API_KEY

0 commit comments

Comments
 (0)