Skip to content

Commit 0b83045

Browse files
authored
feat(providers): expose native slash commands across clients (#11519)
1 parent e8ca3a8 commit 0b83045

19 files changed

Lines changed: 1023 additions & 103 deletions

‎apps/mobile/src/features/threads/use-composer-command-menu.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ import {
2929
import {
3030
dedupeProviderSkillsByName,
3131
getProviderSkillsForSlashMenu,
32+
getProviderSlashCommandsForSlashMenu,
3233
isProviderSkillUserInvocable,
3334
resolveProviderSkillsForCwd,
35+
resolveProviderSlashCommandsForCwd,
3436
} from "@t3tools/client-runtime/providerSkills";
3537
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3638

@@ -329,17 +331,26 @@ export function useComposerCommandMenu({
329331

330332
if (trigger.kind === "slash-command") {
331333
const q = trigger.query.toLowerCase();
334+
const visibleSkills = getProviderSkillsForSlashMenu(skills, true);
332335
const commandItems = buildComposerSlashCommandItems({
333336
query: q,
334337
atMessageStart: trigger.rangeStart === 0,
335338
hasThread,
336339
hasCompactableConversation,
337340
offersUsageLimits,
338341
allowInteractionMode: onUpdateInteractionMode !== undefined,
339-
selectedProviderStatus,
342+
selectedProviderStatus: selectedProviderStatus
343+
? {
344+
...selectedProviderStatus,
345+
slashCommands: getProviderSlashCommandsForSlashMenu(
346+
resolveProviderSlashCommandsForCwd(selectedProviderStatus, projectCwd),
347+
visibleSkills,
348+
),
349+
}
350+
: null,
340351
});
341352

342-
const skillItems = getProviderSkillsForSlashMenu(skills, true)
353+
const skillItems = visibleSkills
343354
.filter((skill) => matchesSlashSkillQuery(skill, q))
344355
.map((skill) => ({
345356
id: `skill:${skill.name}`,
@@ -456,6 +467,7 @@ export function useComposerCommandMenu({
456467
onUpdateInteractionMode,
457468
pathSearch.entries,
458469
pullRequestSearch.entries,
470+
projectCwd,
459471
selectedProviderStatus,
460472
skills,
461473
trigger,

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ const program = Effect.gen(function* () {
784784
sessionId: requestedSessionId,
785785
update: {
786786
sessionUpdate: "agent_message_chunk",
787-
content: { type: "text", text: "hello from " },
787+
content: { type: "text", text: "hello from" },
788788
},
789789
});
790790

@@ -826,13 +826,15 @@ const program = Effect.gen(function* () {
826826
});
827827
}
828828

829-
writeJsonRpcNotification("session/update", {
830-
sessionId: requestedSessionId,
831-
update: {
832-
sessionUpdate: "agent_message_chunk",
833-
content: { type: "text", text: "mock" },
834-
},
835-
});
829+
for (const text of [" ", "mo", "ck"]) {
830+
writeJsonRpcNotification("session/update", {
831+
sessionId: requestedSessionId,
832+
update: {
833+
sessionUpdate: "agent_message_chunk",
834+
content: { type: "text", text },
835+
},
836+
});
837+
}
836838

837839
return yield* Effect.never;
838840
}

‎apps/server/src/provider/Drivers/CursorDriver.ts‎

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
checkCursorProviderStatus,
3232
makeCursorModelDiscovery,
3333
enrichCursorSnapshot,
34+
makeCursorCommandCatalog,
3435
} from "../Layers/CursorProvider.ts";
3536
import { ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts";
3637
import { makeManagedServerProvider } from "../makeManagedServerProvider.ts";
@@ -53,7 +54,7 @@ import {
5354
makeProviderSnapshotSettingsSource,
5455
type ProviderSnapshotSettings,
5556
} from "../providerUpdateSettings.ts";
56-
import { probeCursorSkills } from "./CursorSkills.ts";
57+
import { discoverCursorSkills, probeCursorSkills } from "./CursorSkills.ts";
5758
const decodeCursorSettings = Schema.decodeSync(CursorSettings);
5859

5960
const DRIVER_KIND = ProviderDriverKind.make("cursor");
@@ -130,11 +131,6 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
130131
),
131132
);
132133

133-
const adapter = yield* makeCursorAdapter(effectiveConfig, {
134-
environment: processEnv,
135-
...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),
136-
instanceId,
137-
});
138134
const textGeneration = yield* makeCursorTextGeneration(effectiveConfig, processEnv);
139135

140136
const discoverModels = yield* makeCursorModelDiscovery(effectiveConfig, processEnv);
@@ -151,7 +147,9 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
151147
);
152148

153149
const snapshotSettings = makeProviderSnapshotSettingsSource(effectiveConfig, serverSettings);
154-
const snapshot = yield* makeManagedServerProvider<ProviderSnapshotSettings<CursorSettings>>({
150+
const managedSnapshot = yield* makeManagedServerProvider<
151+
ProviderSnapshotSettings<CursorSettings>
152+
>({
155153
resolveMaintenance,
156154
getSettings: snapshotSettings.getSettings,
157155
streamSettings: snapshotSettings.streamSettings,
@@ -188,6 +186,20 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
188186
),
189187
);
190188

189+
const { snapshot, onAvailableCommands, snapshotForCwd } =
190+
yield* makeCursorCommandCatalog(managedSnapshot);
191+
const adapter = yield* makeCursorAdapter(effectiveConfig, {
192+
environment: processEnv,
193+
...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),
194+
instanceId,
195+
onAvailableCommands: (commands, cwd) =>
196+
discoverCursorSkills(cwd, processEnv).pipe(
197+
Effect.provideService(FileSystem.FileSystem, fileSystem),
198+
Effect.provideService(Path.Path, path),
199+
Effect.flatMap((skills) => onAvailableCommands(commands, cwd, skills)),
200+
),
201+
});
202+
191203
return {
192204
instanceId,
193205
driverKind: DRIVER_KIND,
@@ -199,22 +211,20 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
199211
snapshotForCwd: (cwd) =>
200212
!effectiveConfig.enabled
201213
? snapshot.getSnapshot
202-
: Effect.all([
203-
snapshot.getSnapshot,
204-
probeCursorSkills(cwd, processEnv).pipe(
205-
Effect.provideService(FileSystem.FileSystem, fileSystem),
206-
Effect.provideService(Path.Path, path),
207-
Effect.mapError(
208-
(cause) =>
209-
new ProviderDriverError({
210-
driver: DRIVER_KIND,
211-
instanceId,
212-
detail: `Failed to discover Cursor skills for '${cwd}'`,
213-
cause,
214-
}),
215-
),
214+
: probeCursorSkills(cwd, processEnv).pipe(
215+
Effect.provideService(FileSystem.FileSystem, fileSystem),
216+
Effect.provideService(Path.Path, path),
217+
Effect.mapError(
218+
(cause) =>
219+
new ProviderDriverError({
220+
driver: DRIVER_KIND,
221+
instanceId,
222+
detail: `Failed to discover Cursor skills for '${cwd}'`,
223+
cause,
224+
}),
216225
),
217-
]).pipe(Effect.map(([machineSnapshot, skills]) => ({ ...machineSnapshot, skills }))),
226+
Effect.flatMap((skills) => snapshotForCwd(cwd, skills)),
227+
),
218228
adapter,
219229
textGeneration,
220230
} satisfies ProviderInstance;

‎apps/server/src/provider/Drivers/OpenCodeDriver.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ import {
3131
checkOpenCodeProviderStatus,
3232
makePendingOpenCodeProvider,
3333
openCodeSkillsToServerProviderSkills,
34+
openCodeCommandsToServerProviderSlashCommands,
3435
} from "../Layers/OpenCodeProvider.ts";
3536
import { ProviderEventLoggers } from "../Layers/ProviderEventLoggers.ts";
3637
import { makeManagedServerProvider } from "../makeManagedServerProvider.ts";
37-
import { OpenCodeRuntime } from "../opencodeRuntime.ts";
38+
import { OpenCodeRuntime, loadOpenCodeCommands } from "../opencodeRuntime.ts";
3839
import * as OpenCodeServerOwner from "../OpenCodeServerOwner.ts";
3940
import {
4041
defaultProviderContinuationIdentity,
@@ -164,7 +165,18 @@ export const OpenCodeDriver: ProviderDriver<OpenCodeSettings, OpenCodeDriverEnv>
164165
// empty skill list and poisons the workspace snapshot the `$` picker
165166
// reads. The SDK `app.skills` endpoint honors the per-request directory
166167
// and returns complete results regardless of size.
167-
const loadSkillsForCwd = (cwd: string) =>
168+
const loadWorkspaceInventory = (client: Parameters<typeof loadOpenCodeCommands>[0]) =>
169+
Effect.all(
170+
{
171+
skills: openCodeRuntime.loadOpenCodeSkills(client),
172+
commands: loadOpenCodeCommands(client).pipe(
173+
Effect.timeout("10 seconds"),
174+
Effect.orElseSucceed(() => []),
175+
),
176+
},
177+
{ concurrency: "unbounded" },
178+
);
179+
const loadWorkspaceForCwd = (cwd: string) =>
168180
effectiveConfig.serverUrl.trim().length > 0
169181
? Effect.scoped(
170182
Effect.gen(function* () {
@@ -184,11 +196,11 @@ export const OpenCodeDriver: ProviderDriver<OpenCodeSettings, OpenCodeDriverEnv>
184196
? { serverPassword: effectiveConfig.serverPassword }
185197
: {}),
186198
});
187-
return yield* openCodeRuntime.loadOpenCodeSkills(client);
199+
return yield* loadWorkspaceInventory(client);
188200
}),
189201
)
190202
: serverOwner.withServer((server) =>
191-
openCodeRuntime.loadOpenCodeSkills(
203+
loadWorkspaceInventory(
192204
openCodeRuntime.createOpenCodeSdkClient({
193205
baseUrl: server.url,
194206
directory: cwd,
@@ -247,18 +259,19 @@ export const OpenCodeDriver: ProviderDriver<OpenCodeSettings, OpenCodeDriverEnv>
247259
? snapshot.getSnapshot
248260
: Effect.all([
249261
snapshot.getSnapshot,
250-
loadSkillsForCwd(cwd).pipe(Effect.timeout("20 seconds")),
262+
loadWorkspaceForCwd(cwd).pipe(Effect.timeout("20 seconds")),
251263
]).pipe(
252-
Effect.map(([machineSnapshot, skills]) => ({
264+
Effect.map(([machineSnapshot, { skills, commands }]) => ({
253265
...machineSnapshot,
254266
skills: openCodeSkillsToServerProviderSkills(skills),
267+
slashCommands: openCodeCommandsToServerProviderSlashCommands(commands),
255268
})),
256269
Effect.mapError(
257270
(cause) =>
258271
new ProviderDriverError({
259272
driver: DRIVER_KIND,
260273
instanceId,
261-
detail: `Failed to probe OpenCode skills for '${cwd}'`,
274+
detail: `Failed to probe OpenCode commands and skills for '${cwd}'`,
262275
cause,
263276
}),
264277
),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ cursorAdapterTestLayer("CursorAdapterLive", (it) => {
302302
}),
303303
);
304304

305-
it.effect("sends selected project skills in Cursor's native slash form", () =>
305+
it.effect("sends skills in Cursor's native form and preserves exact slash command input", () =>
306306
Effect.gen(function* () {
307307
const adapter = yield* CursorAdapter;
308308
const settings = yield* ServerSettingsService;
@@ -347,6 +347,7 @@ cursorAdapterTestLayer("CursorAdapterLive", (it) => {
347347
],
348348
],
349349
);
350+
yield* adapter.sendTurn({ threadId, input: "/copy-request-id" });
350351
yield* adapter.stopSession(threadId);
351352

352353
const requests = yield* Effect.promise(() => readJsonLines(requestLogPath));
@@ -360,6 +361,7 @@ cursorAdapterTestLayer("CursorAdapterLive", (it) => {
360361
{ type: "text", text: "please /review this" },
361362
{ type: "text", text: buildRuntimeInstructions({ harness: "Cursor" }) },
362363
],
364+
[{ type: "text", text: "/copy-request-id" }],
363365
],
364366
);
365367
}),

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ export interface CursorAdapterLiveOptions {
118118
* the latest snapshot so the closure isn't stale.
119119
*/
120120
readonly resolveSettings?: Effect.Effect<CursorSettings>;
121+
readonly onAvailableCommands?: (
122+
commands: ReadonlyArray<EffectAcpSchema.AvailableCommand>,
123+
cwd: string,
124+
) => Effect.Effect<void>;
121125
}
122126

123127
interface PendingApproval {
@@ -810,6 +814,11 @@ export function makeCursorAdapter(
810814
return;
811815
case "ModeChanged":
812816
return;
817+
case "AvailableCommandsUpdated":
818+
yield* (
819+
options?.onAvailableCommands?.(event.availableCommands, cwd) ?? Effect.void
820+
);
821+
return;
813822
case "AssistantItemStarted":
814823
ctx.assistantReply = new CursorTransportFailure();
815824
yield* offerRuntimeEvent(
@@ -1057,16 +1066,19 @@ export function makeCursorAdapter(
10571066
});
10581067
}
10591068

1060-
// ACP has no system-message field; keep runtime context separate from the user's text.
1069+
// ACP commands parse the complete text. Extra context can turn an exact
1070+
// command into an ordinary model prompt or change its arguments.
10611071
const result = yield* ctx.acp
10621072
.prompt({
1063-
prompt: [
1064-
...promptParts,
1065-
{
1066-
type: "text",
1067-
text: buildRuntimeInstructions({ harness: "Cursor", model: resolvedModel }),
1068-
},
1069-
],
1073+
prompt: /^\/[^\s/]+(?:\s|$)/.test(rawPrompt)
1074+
? promptParts
1075+
: [
1076+
...promptParts,
1077+
{
1078+
type: "text",
1079+
text: buildRuntimeInstructions({ harness: "Cursor", model: resolvedModel }),
1080+
},
1081+
],
10701082
})
10711083
.pipe(
10721084
Effect.mapError((error) =>

0 commit comments

Comments
 (0)