Skip to content

Commit 256be9d

Browse files
committed
feat(providers): expose native slash commands across clients
1 parent c299764 commit 256be9d

18 files changed

Lines changed: 789 additions & 75 deletions

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
getProviderSkillsForSlashMenu,
3232
isProviderSkillUserInvocable,
3333
resolveProviderSkillsForCwd,
34+
resolveProviderSlashCommandsForCwd,
3435
} from "@t3tools/client-runtime/providerSkills";
3536
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3637

@@ -336,7 +337,12 @@ export function useComposerCommandMenu({
336337
hasCompactableConversation,
337338
offersUsageLimits,
338339
allowInteractionMode: onUpdateInteractionMode !== undefined,
339-
selectedProviderStatus,
340+
selectedProviderStatus: selectedProviderStatus
341+
? {
342+
...selectedProviderStatus,
343+
slashCommands: resolveProviderSlashCommandsForCwd(selectedProviderStatus, projectCwd),
344+
}
345+
: null,
340346
});
341347

342348
const skillItems = getProviderSkillsForSlashMenu(skills, true)
@@ -456,6 +462,7 @@ export function useComposerCommandMenu({
456462
onUpdateInteractionMode,
457463
pathSearch.entries,
458464
pullRequestSearch.entries,
465+
projectCwd,
459466
selectedProviderStatus,
460467
skills,
461468
trigger,

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

Lines changed: 27 additions & 8 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,19 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
188186
),
189187
);
190188

189+
const { snapshot, onAvailableCommands } = yield* makeCursorCommandCatalog(managedSnapshot);
190+
const adapter = yield* makeCursorAdapter(effectiveConfig, {
191+
environment: processEnv,
192+
...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),
193+
instanceId,
194+
onAvailableCommands: (commands, cwd) =>
195+
discoverCursorSkills(cwd, processEnv).pipe(
196+
Effect.provideService(FileSystem.FileSystem, fileSystem),
197+
Effect.provideService(Path.Path, path),
198+
Effect.flatMap((skills) => onAvailableCommands(commands, cwd, skills)),
199+
),
200+
});
201+
191202
return {
192203
instanceId,
193204
driverKind: DRIVER_KIND,
@@ -214,7 +225,15 @@ export const CursorDriver: ProviderDriver<CursorSettings, CursorDriverEnv> = {
214225
}),
215226
),
216227
),
217-
]).pipe(Effect.map(([machineSnapshot, skills]) => ({ ...machineSnapshot, skills }))),
228+
]).pipe(
229+
Effect.map(([machineSnapshot, skills]) => ({
230+
...machineSnapshot,
231+
slashCommands:
232+
machineSnapshot.workspaceSnapshots?.find((entry) => entry.cwd === cwd)
233+
?.slashCommands ?? machineSnapshot.slashCommands,
234+
skills,
235+
})),
236+
),
218237
adapter,
219238
textGeneration,
220239
} satisfies ProviderInstance;

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

Lines changed: 17 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,15 @@ 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),
173+
},
174+
{ concurrency: "unbounded" },
175+
);
176+
const loadWorkspaceForCwd = (cwd: string) =>
168177
effectiveConfig.serverUrl.trim().length > 0
169178
? Effect.scoped(
170179
Effect.gen(function* () {
@@ -184,11 +193,11 @@ export const OpenCodeDriver: ProviderDriver<OpenCodeSettings, OpenCodeDriverEnv>
184193
? { serverPassword: effectiveConfig.serverPassword }
185194
: {}),
186195
});
187-
return yield* openCodeRuntime.loadOpenCodeSkills(client);
196+
return yield* loadWorkspaceInventory(client);
188197
}),
189198
)
190199
: serverOwner.withServer((server) =>
191-
openCodeRuntime.loadOpenCodeSkills(
200+
loadWorkspaceInventory(
192201
openCodeRuntime.createOpenCodeSdkClient({
193202
baseUrl: server.url,
194203
directory: cwd,
@@ -247,18 +256,19 @@ export const OpenCodeDriver: ProviderDriver<OpenCodeSettings, OpenCodeDriverEnv>
247256
? snapshot.getSnapshot
248257
: Effect.all([
249258
snapshot.getSnapshot,
250-
loadSkillsForCwd(cwd).pipe(Effect.timeout("20 seconds")),
259+
loadWorkspaceForCwd(cwd).pipe(Effect.timeout("20 seconds")),
251260
]).pipe(
252-
Effect.map(([machineSnapshot, skills]) => ({
261+
Effect.map(([machineSnapshot, { skills, commands }]) => ({
253262
...machineSnapshot,
254263
skills: openCodeSkillsToServerProviderSkills(skills),
264+
slashCommands: openCodeCommandsToServerProviderSlashCommands(commands),
255265
})),
256266
Effect.mapError(
257267
(cause) =>
258268
new ProviderDriverError({
259269
driver: DRIVER_KIND,
260270
instanceId,
261-
detail: `Failed to probe OpenCode skills for '${cwd}'`,
271+
detail: `Failed to probe OpenCode commands and skills for '${cwd}'`,
262272
cause,
263273
}),
264274
),

‎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) =>

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

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import * as NodeOS from "node:os";
22

33
import * as NodeServices from "@effect/platform-node/NodeServices";
4+
import { it as effectIt } from "@effect/vitest";
45
import type * as Crypto from "effect/Crypto";
56
import * as Effect from "effect/Effect";
67
import * as FileSystem from "effect/FileSystem";
78
import * as Path from "effect/Path";
9+
import * as Stream from "effect/Stream";
810
import type * as ChildProcessSpawner from "effect/unstable/process/ChildProcessSpawner";
911
import { describe, expect, it } from "vite-plus/test";
1012
import type * as EffectAcpSchema from "effect-acp/schema";
11-
import type { CursorSettings } from "@t3tools/contracts";
13+
import { ProviderDriverKind, ProviderInstanceId, type CursorSettings } from "@t3tools/contracts";
1214
import { createModelCapabilities } from "@t3tools/shared/model";
1315

1416
import {
@@ -17,6 +19,7 @@ import {
1719
checkCursorProviderStatus,
1820
discoverCursorModelsViaAcp,
1921
makeCursorModelDiscovery,
22+
makeCursorCommandCatalog,
2023
getCursorParameterizedModelPickerUnsupportedMessage,
2124
parseCursorAboutOutput,
2225
parseCursorCliConfigChannel,
@@ -475,6 +478,69 @@ describe("Cursor skills", () => {
475478
});
476479
});
477480

481+
describe("Cursor command catalog", () => {
482+
effectIt.effect(
483+
"publishes workspace commands without leaking them globally and retains them across refreshes",
484+
() =>
485+
Effect.gen(function* () {
486+
const base = {
487+
...buildCursorProviderSnapshot({
488+
checkedAt: "2026-01-01T00:00:00.000Z",
489+
cursorSettings: baseCursorSettings,
490+
parsed: { version: null, status: "ready", auth: { status: "authenticated" } },
491+
}),
492+
instanceId: ProviderInstanceId.make("cursor-catalog"),
493+
driver: ProviderDriverKind.make("cursor"),
494+
};
495+
const catalog = yield* makeCursorCommandCatalog({
496+
getSnapshot: Effect.succeed(base),
497+
refresh: Effect.succeed(base),
498+
streamChanges: Stream.empty,
499+
resolveMaintenance: () => Effect.die("Not used"),
500+
applyUsageLimits: () => Effect.void,
501+
});
502+
const skills = [
503+
{ name: "review", path: "/one/.cursor/skills/review/SKILL.md", enabled: true },
504+
];
505+
yield* catalog.onAvailableCommands(
506+
[
507+
{ name: "review", description: "Review changes", input: { hint: "target" } },
508+
{ name: "compact", description: "Native duplicate" },
509+
{ name: "review", description: "Duplicate" },
510+
],
511+
"/one",
512+
skills,
513+
);
514+
yield* catalog.onAvailableCommands([{ name: "deploy", description: "Deploy" }], "/two", []);
515+
const published = yield* catalog.snapshot.streamChanges.pipe(
516+
Stream.take(1),
517+
Stream.runCollect,
518+
);
519+
expect(published[0]?.slashCommands.map((command) => command.name)).toEqual(["compact"]);
520+
const refreshed = yield* catalog.snapshot.refresh;
521+
expect(refreshed.workspaceSnapshots?.find((entry) => entry.cwd === "/one")).toMatchObject({
522+
slashCommands: [
523+
{ name: "compact" },
524+
{ name: "review", description: "Review changes", input: { hint: "target" } },
525+
],
526+
skills,
527+
});
528+
yield* catalog.onAvailableCommands([], "/one", skills);
529+
const updated = yield* catalog.snapshot.getSnapshot;
530+
expect(
531+
updated.workspaceSnapshots
532+
?.find((entry) => entry.cwd === "/one")
533+
?.slashCommands.map((command) => command.name),
534+
).toEqual(["compact"]);
535+
expect(
536+
updated.workspaceSnapshots
537+
?.find((entry) => entry.cwd === "/two")
538+
?.slashCommands.map((command) => command.name),
539+
).toEqual(["compact", "deploy"]);
540+
}),
541+
);
542+
});
543+
478544
describe("buildCursorProviderSnapshot", () => {
479545
it("downgrades ready status to warning when ACP model discovery times out", () => {
480546
expect(

0 commit comments

Comments
 (0)