Expose project provider skills in chat #3982
Closedjakeleventhal(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/3982/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:XL
- apps/web/src/components/ComposerPromptEditor.tsx lines 369 to 374OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -354,3 +360,15 @@354360 return $applyNodeReplacement(new ComposerSkillNode(skillName, skillLabel, skillDescription));355361 }356362363+function $updateComposerSkillMetadata(364+ skillMetadata: ReadonlyMap<string, ComposerSkillMetadata>,365+): void {366+ const visit = (node: LexicalNode): void => {367+ if (node instanceof ComposerSkillNode) {368+ const metadata = skillMetadata.get(node.__skillName);369+ if (!metadata) {370+ return;371+ }372+ const { label, description } = metadata;373+ if (node.__skillLabel === label && node.__skillDescription === description) {374+ return;
- apps/server/src/provider/Layers/GrokAdapter.ts line 1026Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -949,4 +982,19 @@949982 mapAcpToAdapterError(PROVIDER, input.threadId, "session/set_model", cause),950983 });951984952- const text = input.input?.trim();985+ const rawText = input.input?.trim();986+ const text =987+ rawText && options?.listSkills && submittedSkillTokens(rawText).length > 0988+ ? yield* options.listSkills(ctx.session.cwd ?? "").pipe(989+ Effect.map((skills) => rewriteGrokSkillReferences(rawText, skills)),990+ Effect.mapError(991+ (cause) =>992+ new ProviderAdapterRequestError({993+ provider: PROVIDER,994+ method: "skills/list",995+ detail: "Failed to resolve Grok skill references for this prompt.",996+ cause,997+ }),998+ ),999+ )1000+ : rawText;apps/web/src/components/chat/ChatComposer.tsx line 1223Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1070,4 +1102,5 @@10701102 ]);1071110310721104 const isComposerMenuLoading =1073- composerTriggerKind === "path" && pathTriggerQuery.length > 0 && workspaceEntries.isPending;1105+ (composerTriggerKind === "path" && pathTriggerQuery.length > 0 && workspaceEntries.isPending) ||1106+ (composerTriggerKind === "skill" && providerSkills.isPending && composerMenuItems.length === 0);
- @@ -0,0 +114,21 @@114+ ["--cwd", input.cwd, "inspect", "--json"],115+ input.environment ? { env: input.environment } : {},116+ ).pipe(117+ Effect.mapError(118+ (cause) =>119+ new GrokSkillDiscoveryError({120+ operation: "run",121+ detail: "The Grok executable could not be resolved.",122+ cause,123+ }),124+ ),125+ );126+127+ const commandResult = yield* spawnAndCollect(128+ binaryPath,129+ ChildProcess.make(spawnCommand.command, spawnCommand.args, {130+ cwd: input.cwd,131+ ...(input.environment ? { env: input.environment } : {}),132+ shell: spawnCommand.shell,133+ }),134+ ).pipe(@@ -0,0 +20,21 @@20+ return {21+ targetKey: input.targetKey,22+ skills: input.snapshotSkills ?? EMPTY_PROVIDER_SKILLS,23+ };24+ }25+ return null;26+}27+28+export function resolveComposerProviderSkills(input: {29+ readonly targetKey: string;30+ readonly discoveredSkills: ReadonlyArray<ServerProviderSkill> | null;31+ readonly cachedSkills: CachedComposerProviderSkills | null;32+ readonly snapshotSkills: ReadonlyArray<ServerProviderSkill> | undefined;33+ readonly discoveryUnsupported: boolean;34+}): ReadonlyArray<ServerProviderSkill> {35+ if (input.discoveredSkills !== null) {36+ return input.discoveredSkills;37+ }38+39+ if (input.cachedSkills?.targetKey === input.targetKey) {40+ return input.cachedSkills.skills;@@ -951,3 +957,8 @@951957 cwd: isPathTrigger ? gitCwd : null,952958 query: isPathTrigger ? pathTriggerQuery : null,953959 });960+ const providerSkills = useProviderSkills({961+ environmentId,962+ instanceId: selectedProviderStatus?.instanceId ?? null,963+ cwd: gitCwd,964+ enabled: composerTriggerKind === "skill",
- @@ -161,3 +165,16 @@161165 ...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),162166 });163167 const textGeneration = yield* makeCodexTextGeneration(effectiveConfig, processEnv);168+ const listSkills = Effect.fn("CodexDriver.listSkills")(function* (cwd: string) {169+ if (!effectiveConfig.enabled) {170+ return [];171+ }172+173+ return yield* probeCodexAppServerProvider({174+ binaryPath: effectiveConfig.binaryPath,175+ homePath: effectiveConfig.homePath,176+ cwd,177+ customModels: [],178+ environment: processEnv,179+ includeModels: false,180+ }).pipe(
- apps/server/src/provider/Drivers/CodexDriver.ts line 181Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -161,3 +165,16 @@161165 ...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),162166 });163167 const textGeneration = yield* makeCodexTextGeneration(effectiveConfig, processEnv);168+ const listSkills = Effect.fn("CodexDriver.listSkills")(function* (cwd: string) {169+ if (!effectiveConfig.enabled) {170+ return [];171+ }172+173+ return yield* probeCodexAppServerProvider({174+ binaryPath: effectiveConfig.binaryPath,175+ homePath: effectiveConfig.homePath,176+ cwd,177+ customModels: [],178+ environment: processEnv,179+ includeModels: false,180+ }).pipe(apps/server/src/provider/Layers/ProviderRegistry.ts line 522Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -486,3 +486,15 @@486486 );487487 });488488489+ const listSkills = Effect.fn("ProviderRegistry.listSkills")(function* (input: {490+ readonly instanceId: ProviderInstanceId;491+ readonly cwd: string;492+ }) {493+ const instance = Array.from((yield* Ref.get(liveSubsRef)).values()).find(494+ (candidate) => candidate.instanceId === input.instanceId,495+ );496+ if (!instance?.listSkills) {497+ return undefined;498+ }499+ return yield* instance.listSkills(input.cwd);500+ });
- @@ -161,3 +165,15 @@161165 ...(eventLoggers.native ? { nativeEventLogger: eventLoggers.native } : {}),162166 });163167 const textGeneration = yield* makeCodexTextGeneration(effectiveConfig, processEnv);168+ const listSkills = Effect.fn("CodexDriver.listSkills")(function* (cwd: string) {169+ if (!effectiveConfig.enabled) {170+ return [];171+ }172+173+ return yield* probeCodexAppServerProvider({174+ binaryPath: effectiveConfig.binaryPath,175+ homePath: effectiveConfig.homePath,176+ cwd,177+ customModels: [],178+ environment: processEnv,179+ includeModels: false,apps/server/src/ws.ts line 300Outdated@@ -295,3 +297,4 @@295297 [WS_METHODS.serverProbe, AuthOrchestrationReadScope],296298 [WS_METHODS.serverGetConfig, AuthOrchestrationReadScope],297299 [WS_METHODS.serverRefreshProviders, AuthOrchestrationOperateScope],300+ [WS_METHODS.serverListProviderSkills, AuthOrchestrationReadScope],
- @@ -111,3 +119,14 @@111119 };112120 }113121122+export function useProviderSkills(target: {123+ readonly environmentId: EnvironmentId | null;124+ readonly instanceId: ProviderInstanceId | null;125+ readonly cwd: string | null;126+ readonly enabled: boolean;127+}) {128+ const result = useEnvironmentQuery(129+ target.enabled &&130+ target.environmentId !== null &&131+ target.instanceId !== null &&132+ target.cwd !== null@@ -86 +89,21 @@8689 readonly instanceId?: ProviderInstanceId;90+ readonly listSkills?: (91+ cwd: string,92+ ) => Effect.Effect<ReadonlyArray<ServerProviderSkill>, ProviderDriverError>;93+}94+95+// Provider requests contain only flattened prompt text, so an inserted skill96+// chip cannot be distinguished from manually typed shell syntax here. Grok's97+// normal skill names are lowercase or qualified; reserve conventional98+// all-uppercase identifiers for environment variables so `$PATH` does not run99+// (or fail on) `grok inspect`. An all-uppercase skill can still be rewritten100+// when discovery is triggered by another normal skill token in the prompt.101+const ENVIRONMENT_VARIABLE_STYLE_TOKEN = /^[A-Z][A-Z0-9_]*$/;102+103+function submittedSkillTokens(input: string) {104+ return collectComposerInlineTokens(input, { includeTrailingSkillToken: true }).filter(105+ (token) => token.type === "skill",106+ );107+}108+109+function potentialGrokSkillTokens(input: string) {@@ -508,3 +508,4 @@508508 );509509 });510510511+ const listSkills = Effect.fn("ProviderRegistry.listSkills")(function* (input: {
- @@ -1018,0 +1032,21 @@1032+ const [cachedProviderSkills, setCachedProviderSkills] =1033+ useState<CachedComposerProviderSkills | null>(null);1034+ useEffect(() => {1035+ const cacheEntry = getComposerProviderSkillsCacheEntry({1036+ targetKey: providerSkillsTargetKey,1037+ discoveredSkills: providerSkills.data?.skills ?? null,1038+ snapshotSkills: selectedProviderStatus?.skills,1039+ discoveryUnsupported: providerSkills.isUnsupported,1040+ });1041+ if (cacheEntry !== null) {1042+ setCachedProviderSkills(cacheEntry);1043+ }1044+ }, [1045+ providerSkills.data,1046+ providerSkills.isUnsupported,1047+ providerSkillsTargetKey,1048+ selectedProviderStatus?.skills,1049+ ]);1050+ const composerProviderSkills = resolveComposerProviderSkills({1051+ targetKey: providerSkillsTargetKey,1052+ discoveredSkills: providerSkills.data?.skills ?? null,@@ -365,3 +371,7 @@365371 cwd: composerTrigger?.kind === "path" ? props.projectCwd : null,366372 query: composerTrigger?.kind === "path" ? composerTrigger.query : null,367373 });374+ const providerSkills = useProviderSkills({375+ environmentId: props.environmentId,376+ instanceId: selectedProviderStatus?.instanceId ?? null,377+ cwd: props.projectCwd,
- @@ -391,10 +397,11 @@391397 option.selection.instanceId === selectedModel.instanceId &&392398 option.selection.model === selectedModel.model,393399 ) ?? null;394- const selectedProviderSkills = useMemo(400+ const selectedProviderSnapshotSkills = useMemo(395401 () =>396402 selectedEnvironmentServerConfig?.providers.find(397403 (provider) => provider.instanceId === selectedModel?.instanceId,398404 )?.skills ?? [],399405 [selectedEnvironmentServerConfig, selectedModel?.instanceId],400406 );407+ const providerSkillsCwd = selectedWorktreePath ?? selectedProject?.workspaceRoot ?? null;
- @@ -391,10 +397,18 @@391397 option.selection.instanceId === selectedModel.instanceId &&392398 option.selection.model === selectedModel.model,393399 ) ?? null;394- const selectedProviderSkills = useMemo(400+ const selectedProviderSnapshotSkills = useMemo(395401 () =>396402 selectedEnvironmentServerConfig?.providers.find(397403 (provider) => provider.instanceId === selectedModel?.instanceId,398404 )?.skills ?? [],399405 [selectedEnvironmentServerConfig, selectedModel?.instanceId],400406 );407+ const providerSkillsCwd = selectedWorktreePath ?? selectedProject?.workspaceRoot ?? null;408+ const providerSkillsEnvironmentId = selectedProject?.environmentId ?? selectedEnvironmentId;409+ const providerSkills = useProviderSkills({410+ environmentId: providerSkillsEnvironmentId,411+ instanceId: selectedModel?.instanceId ?? null,412+ cwd: providerSkillsCwd,413+ enabled: detectComposerTrigger(prompt, prompt.length)?.kind === "skill",414+ });
- @@ -106,3 +107,20 @@106107 env: processEnv,107108 });108109110+ const listSkills = Effect.fn("GrokDriver.listSkills")(function* (cwd: string) {111+ if (!effectiveConfig.enabled) {112+ return [];113+ }114+115+ return yield* listGrokSkills({116+ settings: effectiveConfig,117+ cwd,118+ environment: processEnv,119+ }).pipe(120+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),121+ Effect.mapError(122+ (cause) =>123+ new ProviderDriverError({124+ driver: DRIVER_KIND,125+ instanceId,126+ detail: cause.message,@@ -163,0 +169,21 @@169+ const listSkills = Effect.fn("CodexDriver.listSkills")(function* (cwd: string) {170+ if (!effectiveConfig.enabled) {171+ return [];172+ }173+174+ return yield* probeCodexAppServerProvider({175+ binaryPath: effectiveConfig.binaryPath,176+ homePath: effectiveConfig.homePath,177+ cwd,178+ customModels: [],179+ environment: processEnv,180+ includeModels: false,181+ }).pipe(182+ Effect.scoped,183+ Effect.map((result) => result.skills),184+ Effect.mapError(185+ (cause) =>186+ new ProviderDriverError({187+ driver: DRIVER_KIND,188+ instanceId,189+ detail: `Failed to list Codex skills: ${cause.message}`,@@ -1352,3 +1354,17 @@13521354 ).pipe(Effect.map((providers) => ({ providers }))),13531355 { "rpc.aggregate": "server" },13541356 ),1357+ [WS_METHODS.serverListProviderSkills]: (input) =>1358+ observeRpcEffect(1359+ WS_METHODS.serverListProviderSkills,1360+ Effect.gen(function* () {1361+ const skills = yield* providerRegistry.listSkills(input);1362+ if (!skills) {1363+ return yield* new ServerProviderSkillsUnsupportedError({1364+ instanceId: input.instanceId,1365+ cwd: input.cwd,1366+ });1367+ }1368+ return { skills };1369+ }).pipe(1370+ Effect.mapError((cause) =>
- @@ -106,3 +107,20 @@106107 env: processEnv,107108 });108109110+ const listSkills = Effect.fn("GrokDriver.listSkills")(function* (cwd: string) {111+ if (!effectiveConfig.enabled) {112+ return [];113+ }114+115+ return yield* listGrokSkills({116+ settings: effectiveConfig,117+ cwd,118+ environment: processEnv,119+ }).pipe(120+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),121+ Effect.mapError(122+ (cause) =>123+ new ProviderDriverError({124+ driver: DRIVER_KIND,125+ instanceId,126+ detail: cause.message,@@ -163,0 +169,21 @@169+ const listSkills = Effect.fn("CodexDriver.listSkills")(function* (cwd: string) {170+ if (!effectiveConfig.enabled) {171+ return [];172+ }173+174+ return yield* probeCodexAppServerProvider({175+ binaryPath: effectiveConfig.binaryPath,176+ homePath: effectiveConfig.homePath,177+ cwd,178+ customModels: [],179+ environment: processEnv,180+ includeModels: false,181+ }).pipe(182+ Effect.scoped,183+ Effect.map((result) => result.skills),184+ Effect.mapError(185+ (cause) =>186+ new ProviderDriverError({187+ driver: DRIVER_KIND,188+ instanceId,189+ detail: `Failed to list Codex skills: ${cause.message}`,@@ -1352,3 +1354,17 @@13521354 ).pipe(Effect.map((providers) => ({ providers }))),13531355 { "rpc.aggregate": "server" },13541356 ),1357+ [WS_METHODS.serverListProviderSkills]: (input) =>1358+ observeRpcEffect(1359+ WS_METHODS.serverListProviderSkills,1360+ Effect.gen(function* () {1361+ const skills = yield* providerRegistry.listSkills(input);1362+ if (!skills) {1363+ return yield* new ServerProviderSkillsUnsupportedError({1364+ instanceId: input.instanceId,1365+ cwd: input.cwd,1366+ });1367+ }1368+ return { skills };1369+ }).pipe(1370+ Effect.mapError((cause) =>
- @@ -949,5 +996,19 @@949996 mapError: (cause) =>950997 mapAcpToAdapterError(PROVIDER, input.threadId, "session/set_model", cause),951998 });999+ // ACP has already committed the model switch at this point. Keep1000+ // both the internal comparison state and the public snapshot in1001+ // sync even if later prompt preparation (for example, skill1002+ // discovery) fails.1003+ ctx.currentModelId = currentModelId;1004+ const displayModel = currentModelId1005+ ? resolveGrokAcpBaseModelId(currentModelId)1006+ : undefined;1007+ if (displayModel) {1008+ ctx.session = { ...ctx.session, model: displayModel };1009+ }9521010953- const text = input.input?.trim();1011+ const rawText = input.input?.trim();1012+ const text =1013+ rawText && options?.listSkills && potentialGrokSkillTokens(rawText).length > 01014+ ? yield* options.listSkills(ctx.session.cwd ?? "").pipe(@@ -1097,16 +1135,4 @@10971135 return searchSlashCommandItems(slashCommandItems, query);10981136 }10991137 if (composerTrigger.kind === "skill") {1100- return searchProviderSkills(selectedProviderStatus?.skills ?? [], composerTrigger.query).map(1101- (skill) => ({1102- id: `skill:${selectedProvider}:${skill.name}`,1103- type: "skill" as const,1104- provider: selectedProvider,1105- skill,1106- label: formatProviderSkillDisplayName(skill),1107- description:1108- skill.shortDescription ??1109- skill.description ??1110- (skill.scope ? `${skill.scope} skill` : "Run provider skill"),1111- }),1112- );1138+ return searchProviderSkills(composerProviderSkills, composerTrigger.query).map((skill) => ({
juliusmarminge closed this
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:
c01af707-168f-42d8-b9cf-61ac153356caYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
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