The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 18:15 UTC
fix(grok): invoke leading picked skills through native commands (#24605)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 24, 2026 at 16:46 UTC
843f4e35292391897089535e8f1af59b322e70f8
5 files changed
+149
-4
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+84
@@ -53,6 +53,7 @@ import * as EffectAcpErrors from "effect-acp/errors";
53
import type * as EffectAcpProtocol from "effect-acp/protocol";
54
import type * as EffectAcpSchema from "effect-acp/compat";
55
56
+import { writeFakeCli } from "@t3tools/provider-testing/fakeCli";
57
import * as TestProviderHost from "@t3tools/provider-testing/TestProviderHost";
58
import * as McpProviderSessions from "@t3tools/provider-core/server/McpProviderSessions";
59
import * as AcpSessionRuntime from "@t3tools/provider-acp/server/AcpSessionRuntime";
@@ -3169,6 +3170,89 @@ describe("AcpAdapterV2", () => {
3170
}).pipe(Effect.provide(layerTest), Effect.scoped),
3171
);
3172
3173
+ // Oracle: #13457. Grok expands only a leading `/name`, so a picked leading `$name`
3174
+ // must reach it in that form; anything else keeps the user's text.
3175
+ it.live.each([
3176
+ { text: "$deploy ship it", sent: "/deploy ship it", native: true },
3177
+ { text: "ship $deploy", sent: "ship $deploy", native: false },
3178
+ { text: "$other ship it", sent: "$other ship it", native: false },
3179
+ ])("Grok sends $text with a picked skill as $sent", ({ text, sent, native }) =>
3180
+ Effect.gen(function* () {
3181
+ const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
3182
+ const fileSystem = yield* FileSystem.FileSystem;
3183
+ const path = yield* Path.Path;
3184
+ const mockAgentPath = yield* path.fromFileUrl(
3185
+ new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
3186
+ );
3187
+ const hostPlatform = yield* HostProcess.Platform;
3188
+ // Stands in for `grok inspect --json`, the catalog behind the `$` picker.
3189
+ const catalog = { skills: [{ name: "deploy", source: { path: "/s/deploy/SKILL.md" } }] };
3190
+ const grokPath = writeFakeCli({
3191
+ directory: yield* fileSystem.makeTempDirectoryScoped(),
3192
+ name: "grok",
3193
+ source: `process.stdout.write(${JSON.stringify(`${JSON.stringify(catalog)}\n`)});\n`,
3194
+ platform: hostPlatform,
3195
+ });
3196
+ const protocolEvents = yield* Queue.unbounded<EffectAcpProtocol.AcpProtocolLogEvent>();
3197
+ const instanceId = ProviderInstanceId.make("grok-skill-mention");
3198
+ const adapter = yield* makeGrokAdapterV2({
3199
+ instanceId,
3200
+ settings: { ...DEFAULT_GROK_SETTINGS, binaryPath: grokPath },
3201
+ // The fake CLI needs `node` on its PATH.
3202
+ environment: { ...process.env },
3203
+ hostPlatform,
3204
+ selfInvocation: yield* resolveSelfInvocation(),
3205
+ makeRuntime: (input) =>
3206
+ makeMockRuntime({ childProcessSpawner, mockAgentPath, protocolEvents })(input).pipe(
3207
+ Effect.flatMap(makeXAiPromptCompletionRuntime),
3208
+ ),
3209
+ });
3210
+ const threadId = ThreadId.make("grok-skill-mention");
3211
+ const modelSelection = { instanceId, model: "default" } as const;
3212
+ const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
3213
+ runtimeMode: "full-access",
3214
+ interactionMode: "default",
3215
+ cwd: process.cwd(),
3216
+ });
3217
+ const runtime = yield* adapter.openSession({
3218
+ threadId,
3219
+ providerSessionId: ProviderSessionId.make("grok-skill-mention"),
3220
+ modelSelection,
3221
+ runtimePolicy,
3222
+ });
3223
+ const providerThread = yield* runtime.ensureThread({
3224
+ threadId,
3225
+ modelSelection,
3226
+ runtimePolicy,
3227
+ });
3228
+ yield* runtime.startTurn(
3229
+ makeTurnInput({
3230
+ threadId,
3231
+ providerThread,
3232
+ instanceId,
3233
+ runtimePolicy,
3234
+ now: yield* DateTime.now,
3235
+ messageText: text,
3236
+ }),
3237
+ );
3238
+ const prompt = yield* Stream.fromQueue(protocolEvents).pipe(
3239
+ Stream.filter(
3240
+ (event) =>
3241
+ event.direction === "outgoing" && rawProtocolMethod(event) === "session/prompt",
3242
+ ),
3243
+ Stream.runHead,
3244
+ );
3245
+ const blocks = rawProtocolPromptTextBlocks(Option.getOrThrow(prompt));
3246
+ if (native) {
3247
+ // Same shape as a typed native command: one bare text block, no T3 instructions.
3248
+ assert.deepEqual(blocks, [{ type: "text", text: sent }]);
3249
+ } else {
3250
+ assert.isTrue(blocks.some((block) => block.text.includes(sent)));
3251
+ assert.isFalse(blocks.some((block) => block.text.trimStart().startsWith("/")));
3252
+ }
3253
+ }).pipe(Effect.provide(layerTest), Effect.scoped),
3254
+ );
3255
+
3256
// Oracle: #15888 KillTask reports. Command completion must release the turn even
3257
// when the CLI keeps the prompt RPC and process alive. Kill calls stay visible.
3258
it.live.each([
packages/provider-acp/src/server/adapter.ts
+21
-2
@@ -225,6 +225,14 @@ class AcpModelSelectionError extends Schema.TaggedError<AcpModelSelectionError>(
225
226
export interface AcpAdapterV2Flavor {
227
readonly promptFailure?: (cause: unknown) => OrchestrationV2ProviderFailure;
228
+ /**
229
+ * Runs before attachment paths, T3 instructions and native slash-command detection,
230
+ * so a rewrite can turn the user's text into a native command.
231
+ */
232
+ readonly rewriteUserText?: (
233
+ text: string,
234
+ turnInput: ProviderAdapter.ProviderAdapterV2TurnInput,
235
+ ) => Effect.Effect<string, never, ChildProcessSpawner.ChildProcessSpawner>;
236
readonly driver: ProviderDriverKind;
237
readonly capabilities: OrchestrationV2ProviderCapabilities;
238
readonly clientCapabilitiesMeta?: NonNullable<
@@ -7162,12 +7170,23 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7170
} satisfies T3AcpInstructionState;
7171
const previousInstructionState = (yield* Ref.get(promptInstructionStates)).get(sessionId);
7172
const compactionMarker = (yield* Ref.get(compactionMarkers)).get(sessionId);
7173
+ const userText =
7174
+ flavor.rewriteUserText === undefined
7175
+ ? turnInput.message.text
7176
+ : yield* flavor
7177
+ .rewriteUserText(turnInput.message.text, turnInput)
7178
+ .pipe(
7179
+ Effect.provideService(
7180
+ ChildProcessSpawner.ChildProcessSpawner,
7181
+ childProcessSpawner,
7182
+ ),
7183
+ );
7184
const messageText = providerMessageTextWithAttachmentPaths({
7166
- text: turnInput.message.text,
7185
+ text: userText,
7186
attachments: turnInput.message.attachments,
7187
resolveAttachmentPath: host.resolveAttachmentPath,
7188
});
7170
- const isNativeSlashCommand = turnInput.message.text.trimStart().startsWith("/");
7189
+ const isNativeSlashCommand = userText.trimStart().startsWith("/");
7190
const text = t3AcpPromptWithInstructions({
7191
prompt: messageText,
7192
state: instructionState,
packages/provider-grok/src/server/adapter.ts
+19
@@ -4,6 +4,7 @@ import {
4
isXAiTaskCompletedWakeNotification,
5
xAiRateLimitedErrorCode,
6
} from "./xaiAcpExtension.ts";
7
+import { discoverGrokSkills, leadingGrokSkillMention } from "./skills.ts";
8
import * as HostProcess from "@t3tools/shared/HostProcess";
9
import { resolveSelfInvocation, type SelfInvocation } from "@t3tools/shared/nodeRuntime";
10
import {
@@ -251,6 +252,24 @@ export function makeGrokAcpAdapterFlavor(
252
// still accepts image content blocks (verified with real screenshots).
253
supportsImagePrompts: true,
254
supportsCompaction: true,
255
+ // Grok expands only a leading `/name`, while the `$` picker inserts `$name` from the
256
+ // `grok inspect` catalog. Ask that catalog again so other `$` text is left alone.
257
+ rewriteUserText: (text, turnInput) => {
258
+ const mention = leadingGrokSkillMention(text);
259
+ if (mention === undefined) return Effect.succeed(text);
260
+ return discoverGrokSkills(
261
+ options.settings,
262
+ options.environment,
263
+ turnInput.runtimePolicy.cwd ?? undefined,
264
+ ).pipe(
265
+ Effect.map((skills) =>
266
+ skills.some((skill) => skill.enabled && skill.name === mention.name)
267
+ ? `/${mention.name}${mention.rest}`
268
+ : text,
269
+ ),
270
+ Effect.orElseSucceed(() => text),
271
+ );
272
+ },
273
resolveModelId: (selection) => resolveGrokAcpBaseModelId(selection.model),
274
getModelContextWindow: (selection, session) => {
275
if (selection.instanceId !== options.instanceId) return undefined;
packages/provider-grok/src/server/skills.test.ts
+13
-2
@@ -1,11 +1,11 @@
1
-import { describe, expect, it } from "@effect/vitest";
1
+import { assert, describe, expect, it } from "@effect/vitest";
2
import * as Effect from "effect/Effect";
3
import * as Sink from "effect/Sink";
4
import * as Stream from "effect/Stream";
5
import type * as ChildProcess from "effect/process/ChildProcess";
6
import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
7
8
-import { discoverGrokSkills } from "./skills.ts";
8
+import { discoverGrokSkills, leadingGrokSkillMention } from "./skills.ts";
9
10
const inspectPayload = (skills: ReadonlyArray<unknown>) => JSON.stringify({ skills });
11
@@ -199,3 +199,14 @@ describe("discoverGrokSkills", () => {
199
});
200
});
201
});
202
+
203
+describe("leadingGrokSkillMention", () => {
204
+ it.each([
205
+ { text: " €deploy\nship it", mention: { name: "deploy", rest: "\nship it" } },
206
+ { text: "$deploy", mention: { name: "deploy", rest: "" } },
207
+ { text: "$25 off", mention: undefined },
208
+ { text: "$deploy, then ship", mention: undefined },
209
+ ])("reads $text", ({ text, mention }) => {
210
+ assert.deepEqual(leadingGrokSkillMention(text), mention);
211
+ });
212
+});
packages/provider-grok/src/server/skills.ts
+12
@@ -9,12 +9,24 @@ import * as Effect from "effect/Effect";
9
import * as Option from "effect/Option";
10
import * as Schema from "effect/Schema";
11
import * as ChildProcess from "effect/process/ChildProcess";
12
+import { SKILL_MENTION_PATTERN } from "@t3tools/shared/composerInlineTokens";
13
import { resolveSpawnCommand } from "@t3tools/shared/shell";
14
15
import { spawnAndCollect } from "@t3tools/provider-core/server/snapshotProbe";
16
import { grokProbeEnvironment } from "./probeEnvironment.ts";
17
18
const GROK_SKILLS_PROBE_TIMEOUT_MS = 4_000;
19
+// The composer's chip rule, anchored to the message start, so `$25` never names a skill.
20
+const LEADING_SKILL_MENTION = new RegExp(`^\\s*${SKILL_MENTION_PATTERN.source}`, "u");
21
+
22
+/** A message opening with a mention, such as `deploy` and ` ship it` for `$deploy ship it`. */
23
+export function leadingGrokSkillMention(
24
+ text: string,
25
+): { readonly name: string; readonly rest: string } | undefined {
26
+ const match = LEADING_SKILL_MENTION.exec(text);
27
+ if (match?.[2] === undefined) return undefined;
28
+ return { name: match[2], rest: text.slice(match[0].length) };
29
+}
30
31
class GrokSkillsProbeError extends Schema.TaggedError<GrokSkillsProbeError>()(
32
"GrokSkillsProbeError",