Skip to content

Commit 1f28c79

Browse files
mInrOzclaude
andcommitted
feat(grok): surface Grok skills in the composer $ picker
Grok provider snapshots always shipped an empty skills array, so the $ picker showed "No skills found". The provider check now runs `grok inspect --json` next to the existing version probe and maps the reported catalog (user, project, bundled, and plugin skills, with SKILL.md paths) onto the snapshot. Discovery is best-effort: an older CLI without `inspect`, a timeout, or malformed output yields an empty list and never degrades the snapshot. Built with Claude Code (Claude Fable 5). Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 4347f14 commit 1f28c79

3 files changed

Lines changed: 211 additions & 0 deletions

File tree

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { describe, expect, it } from "@effect/vitest";
2+
3+
import { parseGrokInspectSkills } from "./GrokSkills.ts";
4+
5+
const inspectPayload = (skills: ReadonlyArray<unknown>) => JSON.stringify({ skills });
6+
7+
describe("parseGrokInspectSkills", () => {
8+
it("maps inspect entries onto provider skills, sorted by name", () => {
9+
const skills = parseGrokInspectSkills(
10+
inspectPayload([
11+
{
12+
name: "writing-docs",
13+
description: "Write user docs.",
14+
source: { type: "user", path: "/home/dev/.grok/skills/writing-docs/SKILL.md" },
15+
userInvocable: true,
16+
},
17+
{
18+
name: "deploy",
19+
description: "Deploy the app.",
20+
source: {
21+
type: "plugin",
22+
path: "/home/dev/.grok/installed-plugins/pkg/plug/skills/deploy/SKILL.md",
23+
},
24+
userInvocable: true,
25+
},
26+
]),
27+
);
28+
29+
expect(skills).toEqual([
30+
{
31+
name: "deploy",
32+
description: "Deploy the app.",
33+
path: "/home/dev/.grok/installed-plugins/pkg/plug/skills/deploy/SKILL.md",
34+
scope: "plugin",
35+
enabled: true,
36+
},
37+
{
38+
name: "writing-docs",
39+
description: "Write user docs.",
40+
path: "/home/dev/.grok/skills/writing-docs/SKILL.md",
41+
scope: "user",
42+
enabled: true,
43+
},
44+
]);
45+
});
46+
47+
it("disables skills the CLI marks as not user-invocable", () => {
48+
const skills = parseGrokInspectSkills(
49+
inspectPayload([
50+
{
51+
name: "internal-helper",
52+
source: { type: "bundled", path: "/opt/grok/bundled/skills/internal-helper/SKILL.md" },
53+
userInvocable: false,
54+
},
55+
]),
56+
);
57+
58+
expect(skills).toEqual([
59+
{
60+
name: "internal-helper",
61+
path: "/opt/grok/bundled/skills/internal-helper/SKILL.md",
62+
scope: "bundled",
63+
enabled: false,
64+
},
65+
]);
66+
});
67+
68+
it("skips entries without a name or a filesystem path", () => {
69+
const skills = parseGrokInspectSkills(
70+
inspectPayload([
71+
{ name: " ", source: { type: "user", path: "/tmp/skills/a/SKILL.md" } },
72+
{ name: "no-path", source: { type: "user" } },
73+
{ name: "no-source" },
74+
"not-an-object",
75+
{ name: "kept", source: { type: "project", path: "/repo/.grok/skills/kept/SKILL.md" } },
76+
]),
77+
);
78+
79+
expect(skills.map((skill) => skill.name)).toEqual(["kept"]);
80+
});
81+
82+
it("returns an empty list for malformed or unexpected output", () => {
83+
expect(parseGrokInspectSkills("not json")).toEqual([]);
84+
expect(parseGrokInspectSkills("null")).toEqual([]);
85+
expect(parseGrokInspectSkills(JSON.stringify({ skills: "nope" }))).toEqual([]);
86+
expect(parseGrokInspectSkills(JSON.stringify({}))).toEqual([]);
87+
});
88+
});
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* GrokSkills — skill discovery for the `$` picker via `grok inspect --json`.
3+
*
4+
* Unlike Claude Code, the Grok CLI reports its full skill catalog itself:
5+
* `grok inspect --json` returns `skills[]` with `name`, `description`,
6+
* `source.type` (`user` / `project` / `bundled` / `plugin`), `source.path`
7+
* (the absolute `SKILL.md` path), and `userInvocable`. Asking the CLI beats
8+
* scanning the filesystem because the catalog honors Grok's own skill config
9+
* (ignore lists, disabled skills) and includes plugin skills, which live
10+
* three levels deep under `~/.grok/installed-plugins/` where a flat scan
11+
* cannot see them. This mirrors how the Codex app-server reports skills over
12+
* `skills/list`. Discovery is best-effort: an older CLI without `inspect`,
13+
* a timeout, or malformed output yields an empty list, never a degraded
14+
* provider snapshot.
15+
*
16+
* @module provider/Drivers/GrokSkills
17+
*/
18+
import type { GrokSettings, ServerProviderSkill } from "@t3tools/contracts";
19+
import * as Effect from "effect/Effect";
20+
import * as Option from "effect/Option";
21+
import * as Result from "effect/Result";
22+
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
23+
import { resolveSpawnCommand } from "@t3tools/shared/shell";
24+
25+
import { spawnAndCollect } from "../providerSnapshot.ts";
26+
27+
const GROK_SKILLS_PROBE_TIMEOUT_MS = 4_000;
28+
29+
/**
30+
* Map `grok inspect --json` output onto provider skills. Entries without a
31+
* name or a filesystem path are skipped; `userInvocable: false` skills are
32+
* kept but disabled so pickers that filter on `enabled` hide them.
33+
*/
34+
export function parseGrokInspectSkills(stdout: string): ReadonlyArray<ServerProviderSkill> {
35+
let parsed: unknown;
36+
try {
37+
parsed = JSON.parse(stdout);
38+
} catch {
39+
return [];
40+
}
41+
if (typeof parsed !== "object" || parsed === null) {
42+
return [];
43+
}
44+
const entries = (parsed as Record<string, unknown>).skills;
45+
if (!Array.isArray(entries)) {
46+
return [];
47+
}
48+
49+
const skillsByName = new Map<string, ServerProviderSkill>();
50+
for (const entry of entries) {
51+
if (typeof entry !== "object" || entry === null) {
52+
continue;
53+
}
54+
const record = entry as Record<string, unknown>;
55+
const name = typeof record.name === "string" ? record.name.trim() : "";
56+
const source =
57+
typeof record.source === "object" && record.source !== null
58+
? (record.source as Record<string, unknown>)
59+
: undefined;
60+
const path = typeof source?.path === "string" ? source.path.trim() : "";
61+
if (!name || !path) {
62+
continue;
63+
}
64+
const scope = typeof source?.type === "string" ? source.type.trim() : "";
65+
const description = typeof record.description === "string" ? record.description.trim() : "";
66+
skillsByName.set(name, {
67+
name,
68+
path,
69+
enabled: record.userInvocable !== false,
70+
...(scope ? { scope } : {}),
71+
...(description ? { description } : {}),
72+
});
73+
}
74+
75+
return [...skillsByName.values()].sort((left, right) => left.name.localeCompare(right.name));
76+
}
77+
78+
/**
79+
* Run `grok inspect --json` and map the reported catalog onto provider
80+
* skills. Never fails: any spawn error, non-zero exit, or timeout resolves
81+
* to an empty list.
82+
*/
83+
export const discoverGrokSkills = Effect.fn("discoverGrokSkills")(function* (
84+
grokSettings: Pick<GrokSettings, "binaryPath">,
85+
environment: NodeJS.ProcessEnv = process.env,
86+
): Effect.fn.Return<
87+
ReadonlyArray<ServerProviderSkill>,
88+
never,
89+
ChildProcessSpawner.ChildProcessSpawner
90+
> {
91+
const command = grokSettings.binaryPath || "grok";
92+
const inspectResult = yield* Effect.gen(function* () {
93+
const spawnCommand = yield* resolveSpawnCommand(command, ["inspect", "--json"], {
94+
env: environment,
95+
});
96+
return yield* spawnAndCollect(
97+
command,
98+
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
99+
env: environment,
100+
shell: spawnCommand.shell,
101+
}),
102+
);
103+
}).pipe(Effect.timeoutOption(GROK_SKILLS_PROBE_TIMEOUT_MS), Effect.result);
104+
105+
if (Result.isFailure(inspectResult) || Option.isNone(inspectResult.success)) {
106+
yield* Effect.logDebug("Grok skill discovery failed; continuing without skills.");
107+
return [];
108+
}
109+
const output = inspectResult.success.value;
110+
if (output.code !== 0) {
111+
yield* Effect.logDebug("Grok skill discovery exited non-zero; continuing without skills.", {
112+
exitCode: output.code,
113+
});
114+
return [];
115+
}
116+
return parseGrokInspectSkills(output.stdout);
117+
});

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
type ProviderMaintenanceCapabilities,
3131
} from "../providerMaintenance.ts";
3232
import { makeGrokAcpRuntime, resolveGrokAcpBaseModelId } from "../acp/GrokAcpSupport.ts";
33+
import { discoverGrokSkills } from "../Drivers/GrokSkills.ts";
3334

3435
const GROK_PRESENTATION = {
3536
displayName: "Grok",
@@ -251,6 +252,8 @@ export const checkGrokProviderStatus = Effect.fn("checkGrokProviderStatus")(func
251252
});
252253
}
253254

255+
const skills = yield* discoverGrokSkills(grokSettings, environment);
256+
254257
const discoveryExit = yield* discoverGrokModelsViaAcp(grokSettings, environment).pipe(
255258
Effect.timeoutOption(GROK_ACP_MODEL_DISCOVERY_TIMEOUT_MS),
256259
Effect.exit,
@@ -264,6 +267,7 @@ export const checkGrokProviderStatus = Effect.fn("checkGrokProviderStatus")(func
264267
enabled: grokSettings.enabled,
265268
checkedAt,
266269
models: fallbackModels,
270+
skills,
267271
probe: {
268272
installed: true,
269273
version,
@@ -282,6 +286,7 @@ export const checkGrokProviderStatus = Effect.fn("checkGrokProviderStatus")(func
282286
enabled: grokSettings.enabled,
283287
checkedAt,
284288
models: fallbackModels,
289+
skills,
285290
probe: {
286291
installed: true,
287292
version,
@@ -302,6 +307,7 @@ export const checkGrokProviderStatus = Effect.fn("checkGrokProviderStatus")(func
302307
enabled: grokSettings.enabled,
303308
checkedAt,
304309
models,
310+
skills,
305311
probe: {
306312
installed: true,
307313
version,

0 commit comments

Comments
 (0)