Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(claude): run composer-picked skills as slash commands (#254)
Leoc2a0791dea1a
diff --git a/apps/server/src/provider/Drivers/ClaudeSkillDispatch.test.ts b/apps/server/src/provider/Drivers/ClaudeSkillDispatch.test.tsnew file mode 100644index 000000000..8de7ba130--- /dev/null+++ b/apps/server/src/provider/Drivers/ClaudeSkillDispatch.test.ts@@ -0,0 +1,42 @@+import { describe, expect, it } from "vite-plus/test";++import { planClaudeSkillDispatch } from "./ClaudeSkillDispatch.ts";++const SKILLS = new Set(["implement", "review", "re-release-version", "123-review"]);++describe("planClaudeSkillDispatch", () => {+ it("leaves prompts without a known skill mention unchanged", () => {+ expect(planClaudeSkillDispatch("fix the build", SKILLS)).toBeUndefined();+ expect(planClaudeSkillDispatch("echo $HOME then $unknown", SKILLS)).toBeUndefined();+ });++ it("splits the last known skill mention into a trailing slash command", () => {+ expect(planClaudeSkillDispatch("ok, now $implement all the tickets", SKILLS)).toEqual({+ leadingText: "ok, now",+ commandText: "/implement all the tickets",+ skillName: "implement",+ });+ expect(planClaudeSkillDispatch("$review\nfocus on auth", SKILLS)).toEqual({+ leadingText: undefined,+ commandText: "/review\nfocus on auth",+ skillName: "review",+ });+ expect(planClaudeSkillDispatch("$review the diff, then $implement the fixes", SKILLS)).toEqual({+ leadingText: "/review the diff, then",+ commandText: "/implement the fixes",+ skillName: "implement",+ });+ });++ it("dispatches a numeric-leading discovered skill", () => {+ expect(planClaudeSkillDispatch("use $123-review now", SKILLS)).toEqual({+ leadingText: "use",+ commandText: "/123-review now",+ skillName: "123-review",+ });+ });++ it("does not treat a dollar amount glued to a word as a skill", () => {+ expect(planClaudeSkillDispatch("cost is 5$implement", SKILLS)).toBeUndefined();+ });+});diff --git a/apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts b/apps/server/src/provider/Drivers/ClaudeSkillDispatch.tsnew file mode 100644index 000000000..ff231ec9d--- /dev/null+++ b/apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts@@ -0,0 +1,63 @@+/**+ * ClaudeSkillDispatch — turns `$skill` mentions in a composer prompt into the+ * slash invocation Claude Code actually runs.+ *+ * The composer inserts `$name` for every provider. Codex parses that natively;+ * Claude Code does not, and treats it as prose. Claude Code's only user-side+ * invocation is a text block whose first character is `/`.+ *+ * @module provider/Drivers/ClaudeSkillDispatch+ */++/**+ * Same token shape the composer and timeline chips recognise+ * (`packages/shared/src/composerInlineTokens.ts`), so a rendered chip and a+ * dispatched skill are always the same set.+ */+const SKILL_MENTION_PATTERN = /(^|\s)\$([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/g;++export interface ClaudeSkillDispatch {+ /** Text before the dispatched mention, or `undefined` when it opens the prompt. */+ readonly leadingText: string | undefined;+ /** `/name` plus the trailing text, ready to be the message's last text block. */+ readonly commandText: string;+ readonly skillName: string;+}++/**+ * Split `prompt` around the last `$skill` mention that names a known skill.+ * Returns `undefined` when there is nothing to dispatch, in which case the+ * prompt should go out unchanged. Mentions that do not match a discovered+ * skill stay literal: a `$HOME` in prose must not become a command.+ */+export function planClaudeSkillDispatch(+ prompt: string,+ skillNames: ReadonlySet<string>,+): ClaudeSkillDispatch | undefined {+ const mentions = [...prompt.matchAll(SKILL_MENTION_PATTERN)].flatMap((match) => {+ const name = match[2] ?? "";+ if (!skillNames.has(name)) return [];+ const start = (match.index ?? 0) + (match[1]?.length ?? 0);+ return [{ name, start, end: start + name.length + 1 }];+ });+ const last = mentions.at(-1);+ if (!last) {+ return undefined;+ }++ const leading = prompt.slice(0, last.start);+ const trailing = prompt.slice(last.end);+ const leadingWithInlineSlashes = mentions+ .slice(0, -1)+ .reduceRight(+ (text, mention) => `${text.slice(0, mention.start)}/${text.slice(mention.start + 1)}`,+ leading,+ )+ .trimEnd();++ return {+ leadingText: leadingWithInlineSlashes.length > 0 ? leadingWithInlineSlashes : undefined,+ commandText: `/${last.name}${trailing}`.trimEnd(),+ skillName: last.name,+ };+}diff --git a/apps/server/src/provider/Layers/ClaudeAdapter.test.ts b/apps/server/src/provider/Layers/ClaudeAdapter.test.tsindex b1709fee1..9646403a0 100644--- a/apps/server/src/provider/Layers/ClaudeAdapter.test.ts+++ b/apps/server/src/provider/Layers/ClaudeAdapter.test.ts@@ -923,10 +923,6 @@ describe("ClaudeAdapterLive", () => {const promptMessage = yield* Effect.promise(() => readFirstPromptMessage(createInput));assert.isDefined(promptMessage);assert.deepEqual(promptMessage?.message.content, [- {- type: "text",- text: "What's in this image?",- },{type: "image",source: {@@ -935,6 +931,10 @@ describe("ClaudeAdapterLive", () => {data: "AQIDBA==",},},+ {+ type: "text",+ text: "What's in this image?",+ },]);}).pipe(Effect.provideService(Random.Random, makeDeterministicRandomService()),diff --git a/apps/server/src/provider/Layers/ClaudeAdapter.ts b/apps/server/src/provider/Layers/ClaudeAdapter.tsindex 5508a36bb..111913033 100644--- a/apps/server/src/provider/Layers/ClaudeAdapter.ts+++ b/apps/server/src/provider/Layers/ClaudeAdapter.ts@@ -86,6 +86,8 @@ import * as McpProviderSession from "../../mcp/McpProviderSession.ts";import { toClaudeMcpServers } from "../McpServerConfig.ts";import { resolveClaudeSdkExecutablePath } from "../Drivers/ClaudeExecutable.ts";import { claudeSignedOutMessage, makeClaudeEnvironment } from "../Drivers/ClaudeHome.ts";+import { planClaudeSkillDispatch } from "../Drivers/ClaudeSkillDispatch.ts";+import { discoverClaudeSkills } from "../Drivers/ClaudeSkills.ts";import {getClaudeModelCapabilities,isClaudeUltracodeEffort,@@ -1374,14 +1376,16 @@ const buildUserMessageEffect = Effect.fn("buildUserMessageEffect")(function* (readonly fileSystem: FileSystem.FileSystem;readonly attachmentsDir: string;readonly boundInstanceId: ProviderInstanceId;+ readonly skillNames: ReadonlySet<string>;},) {const text = buildPromptText(input, dependencies.boundInstanceId);const sdkContent: Array<Record<string, unknown>> = [];- if (text.length > 0) {- sdkContent.push({ type: "text", text });- }+ // Claude Code expands a skill only from the last text block, and only when+ // `/name` is its first character. Split a `$skill` mention into leading text+ // and a trailing slash command so the surrounding prose survives.+ const dispatch = planClaudeSkillDispatch(text, dependencies.skillNames);for (const attachment of input.attachments ?? []) {if (attachment.type !== "image") {@@ -1428,6 +1432,16 @@ const buildUserMessageEffect = Effect.fn("buildUserMessageEffect")(function* ();}+ // Images go first so the slash command remains the last text block.+ if (dispatch) {+ if (dispatch.leadingText !== undefined) {+ sdkContent.push({ type: "text", text: dispatch.leadingText });+ }+ sdkContent.push({ type: "text", text: dispatch.commandText });+ } else if (text.length > 0) {+ sdkContent.push({ type: "text", text });+ }+return buildUserMessage({ sdkContent });});@@ -4759,10 +4773,19 @@ export const makeClaudeAdapter = Effect.fn("makeClaudeAdapter")(function* (});}+ const skills = yield* discoverClaudeSkills(+ claudeSettings,+ context.session.cwd,+ claudeEnvironment,+ ).pipe(+ Effect.provideService(FileSystem.FileSystem, fileSystem),+ Effect.provideService(Path.Path, path),+ );const message = yield* buildUserMessageEffect(input, {fileSystem,attachmentsDir: serverConfig.attachmentsDir,boundInstanceId,+ skillNames: new Set(skills.filter((skill) => skill.enabled).map((skill) => skill.name)),});yield* Queue.offer(context.promptQueue, {diff --git a/apps/web/src/components/chat/SkillInlineText.tsx b/apps/web/src/components/chat/SkillInlineText.tsxindex 6d026ea58..6176d3acc 100644--- a/apps/web/src/components/chat/SkillInlineText.tsx+++ b/apps/web/src/components/chat/SkillInlineText.tsx@@ -10,7 +10,7 @@ import {} from "../composerInlineChip";import { cn } from "~/lib/utils";-const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s|$)/g;+const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/g;type InlineSkill = Pick<ServerProviderSkill, "name" | "displayName">;diff --git a/docs/user/composer.md b/docs/user/composer.mdindex 0e24087de..2a27609cf 100644--- a/docs/user/composer.md+++ b/docs/user/composer.md@@ -28,6 +28,9 @@ The slash menu includes skills by default. Turn off **Show skills in slash menu*`/skill:Skill Name` label and insert the same `$name` token. Akeru hides duplicate native providercommands when the same skill is already available.+On Claude, picking a skill from the `$` menu is sent as a trailing `/name` command so Claude Code+runs that skill. Codex still reads `$name` natively. The message you see in the chat stays `$name`.+## Start bot work in the backgroundFrom a new chat on desktop, press `Cmd+Enter` on macOS or `Ctrl+Enter` on Windows and Linux. Akerudiff --git a/packages/shared/src/composerInlineTokens.test.ts b/packages/shared/src/composerInlineTokens.test.tsindex 0d0f9cd8a..d8956e4c5 100644--- a/packages/shared/src/composerInlineTokens.test.ts+++ b/packages/shared/src/composerInlineTokens.test.ts@@ -31,6 +31,18 @@ describe("collectComposerInlineTokens", () => {]);});+ it("collects numeric-leading skill names", () => {+ expect(collectComposerInlineTokens("Use $123-review now")).toEqual([+ {+ type: "skill",+ value: "123-review",+ source: "$123-review",+ start: 4,+ end: 15,+ },+ ]);+ });+it("does not convert incomplete trailing tokens", () => {expect(collectComposerInlineTokens("Use $ui")).toEqual([]);expect(collectComposerInlineTokens("Inspect @AGENTS.md")).toEqual([]);diff --git a/packages/shared/src/composerInlineTokens.ts b/packages/shared/src/composerInlineTokens.tsindex d7a673589..13de4630c 100644--- a/packages/shared/src/composerInlineTokens.ts+++ b/packages/shared/src/composerInlineTokens.ts@@ -27,7 +27,7 @@ export interface CollectComposerInlineTokensOptions {readonly preserveTrailingFrom?: ReadonlyArray<ComposerInlineToken>;}-const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s)/g;+const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s)/g;const MENTION_TOKEN_REGEX = /(^|\s)@(?:"((?:\\.|[^"\\])*)"|([^\s@"]+))(?=\s)/g;/*** The label body is bounded rather than `*`. Unbounded, every whitespace in