Skip to content

Commit cf251c3

Browse files
authored
Add OpenCode skill discovery (pingdotgg#3154)
1 parent 4347f14 commit cf251c3

5 files changed

Lines changed: 253 additions & 19 deletions

File tree

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

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,24 @@ const runtimeMock = {
3434
runVersionError: null as Error | null,
3535
versionStdout: DEFAULT_VERSION_STDOUT,
3636
inventoryError: null as Error | null,
37+
inventoryCwd: null as string | null,
3738
closeCalls: 0,
3839
inventory: {
3940
providerList: { connected: [] as string[], all: [] as unknown[], default: {} },
4041
agents: [] as unknown[],
42+
skills: [] as unknown[],
4143
} as unknown,
4244
},
4345
reset() {
4446
this.state.runVersionError = null;
4547
this.state.versionStdout = DEFAULT_VERSION_STDOUT;
4648
this.state.inventoryError = null;
49+
this.state.inventoryCwd = null;
4750
this.state.closeCalls = 0;
4851
this.state.inventory = {
4952
providerList: { connected: [], all: [] as unknown[], default: {} },
5053
agents: [] as unknown[],
54+
skills: [] as unknown[],
5155
};
5256
},
5357
};
@@ -95,16 +99,18 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
9599
}),
96100
)
97101
: Effect.succeed(runtimeMock.state.inventory as OpenCodeInventory),
98-
loadInventoryFromCli: () =>
99-
runtimeMock.state.inventoryError
102+
loadInventoryFromCli: ({ cwd }) => {
103+
runtimeMock.state.inventoryCwd = cwd;
104+
return runtimeMock.state.inventoryError
100105
? Effect.fail(
101106
new OpenCodeRuntimeError({
102107
operation: "loadInventoryFromCli",
103108
detail: runtimeMock.state.inventoryError.message,
104109
cause: runtimeMock.state.inventoryError,
105110
}),
106111
)
107-
: Effect.succeed(runtimeMock.state.inventory as OpenCodeInventory),
112+
: Effect.succeed(runtimeMock.state.inventory as OpenCodeInventory);
113+
},
108114
};
109115

110116
beforeEach(() => {
@@ -207,11 +213,82 @@ it.layer(testLayer)("checkOpenCodeProviderStatus", (it) => {
207213
}),
208214
);
209215

216+
it.effect("includes OpenCode skills in the provider snapshot", () =>
217+
Effect.gen(function* () {
218+
runtimeMock.state.inventory = {
219+
providerList: {
220+
connected: ["openai"],
221+
all: [
222+
{
223+
id: "openai",
224+
name: "OpenAI",
225+
models: {
226+
"gpt-5.4": {
227+
id: "gpt-5.4",
228+
name: "GPT-5.4",
229+
variants: {},
230+
},
231+
},
232+
},
233+
],
234+
default: {},
235+
},
236+
agents: [],
237+
skills: [
238+
{
239+
name: "openclaw-review",
240+
description: "Review OpenClaw workflow changes.",
241+
location: "/Users/test/.agents/skills/openclaw-review/SKILL.md",
242+
content: "---\nname: openclaw-review\n---\n",
243+
},
244+
{
245+
name: "openclaw-triage",
246+
description: "Triage OpenClaw routing issues.",
247+
location: "/Users/test/.agents/skills/openclaw-triage/SKILL.md",
248+
content: "---\nname: openclaw-triage\n---\n",
249+
},
250+
{
251+
name: "missing-location",
252+
description: "This incomplete SDK row should be skipped.",
253+
location: "",
254+
content: "---\nname: missing-location\n---\n",
255+
},
256+
],
257+
};
258+
259+
const snapshot = yield* checkOpenCodeProviderStatus(makeOpenCodeSettings(), process.cwd());
260+
261+
NodeAssert.deepEqual(
262+
snapshot.skills.map((skill) => ({
263+
name: skill.name,
264+
path: skill.path,
265+
enabled: skill.enabled,
266+
shortDescription: skill.shortDescription,
267+
})),
268+
[
269+
{
270+
name: "openclaw-review",
271+
path: "/Users/test/.agents/skills/openclaw-review/SKILL.md",
272+
enabled: true,
273+
shortDescription: "Review OpenClaw workflow changes.",
274+
},
275+
{
276+
name: "openclaw-triage",
277+
path: "/Users/test/.agents/skills/openclaw-triage/SKILL.md",
278+
enabled: true,
279+
shortDescription: "Triage OpenClaw routing issues.",
280+
},
281+
],
282+
);
283+
}),
284+
);
285+
210286
it.effect("does not spawn a local server for health check (uses CLI instead)", () =>
211287
Effect.gen(function* () {
212288
yield* checkOpenCodeProviderStatus(makeOpenCodeSettings(), process.cwd());
213289

214290
NodeAssert.equal(runtimeMock.state.closeCalls, 0);
291+
NodeAssert.equal(runtimeMock.state.inventoryCwd, process.cwd());
215292
}),
216293
);
217294

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
type ModelCapabilities,
33
type OpenCodeSettings,
44
type ServerProviderModel,
5+
type ServerProviderSkill,
56
} from "@t3tools/contracts";
67
import * as Cause from "effect/Cause";
78
import * as Data from "effect/Data";
@@ -250,6 +251,32 @@ function flattenOpenCodeModels(input: OpenCodeInventory): ReadonlyArray<ServerPr
250251
return models.toSorted((left, right) => left.name.localeCompare(right.name));
251252
}
252253

254+
function trimOptional(value: string | null | undefined): string | undefined {
255+
const trimmed = value?.trim();
256+
return trimmed && trimmed.length > 0 ? trimmed : undefined;
257+
}
258+
259+
function flattenOpenCodeSkills(input: OpenCodeInventory): ReadonlyArray<ServerProviderSkill> {
260+
const skills: ServerProviderSkill[] = [];
261+
for (const skill of input.skills ?? []) {
262+
const name = trimOptional(skill.name);
263+
const path = trimOptional(skill.location);
264+
if (!name || !path) {
265+
continue;
266+
}
267+
268+
const description = trimOptional(skill.description);
269+
skills.push({
270+
name,
271+
path,
272+
enabled: true,
273+
...(description ? { description, shortDescription: description } : {}),
274+
});
275+
}
276+
277+
return skills.toSorted((left, right) => left.name.localeCompare(right.name));
278+
}
279+
253280
export const makePendingOpenCodeProvider = (
254281
openCodeSettings: OpenCodeSettings,
255282
): Effect.Effect<ServerProviderDraft> =>
@@ -412,6 +439,7 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
412439
)
413440
: openCodeRuntime.loadInventoryFromCli({
414441
binaryPath: openCodeSettings.binaryPath,
442+
cwd,
415443
environment: resolvedEnvironment,
416444
})
417445
).pipe(
@@ -429,12 +457,14 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
429457
customModels,
430458
DEFAULT_OPENCODE_MODEL_CAPABILITIES,
431459
);
460+
const skills = flattenOpenCodeSkills(inventoryExit.value);
432461
const connectedCount = inventoryExit.value.providerList.connected.length;
433462
return buildServerProvider({
434463
presentation: OPENCODE_PRESENTATION,
435464
enabled: true,
436465
checkedAt,
437466
models,
467+
skills,
438468
probe: {
439469
installed: true,
440470
version,

‎apps/server/src/provider/opencodeRuntime.cliParsers.test.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import * as NodeAssert from "node:assert/strict";
22

33
import { describe, it } from "vite-plus/test";
44

5-
import { parseModelsCliOutput, parseAgentListCliOutput } from "./opencodeRuntime.ts";
5+
import {
6+
parseAgentListCliOutput,
7+
parseModelsCliOutput,
8+
parseSkillsCliOutput,
9+
} from "./opencodeRuntime.ts";
610

711
describe("parseModelsCliOutput", () => {
812
it("parses a single model from a single provider", () => {
@@ -252,3 +256,31 @@ describe("parseAgentListCliOutput", () => {
252256
NodeAssert.equal(result[1]!.hidden, false);
253257
});
254258
});
259+
260+
describe("parseSkillsCliOutput", () => {
261+
it("parses skill metadata from the CLI JSON output", () => {
262+
const result = parseSkillsCliOutput(
263+
JSON.stringify([
264+
{
265+
name: "review-pr",
266+
description: "Review a pull request.",
267+
location: "/tmp/review-pr/SKILL.md",
268+
content: "---\nname: review-pr\n---\n",
269+
},
270+
]),
271+
);
272+
273+
NodeAssert.deepEqual(result, [
274+
{
275+
name: "review-pr",
276+
description: "Review a pull request.",
277+
location: "/tmp/review-pr/SKILL.md",
278+
content: "---\nname: review-pr\n---\n",
279+
},
280+
]);
281+
});
282+
283+
it("degrades malformed output to an empty skill list", () => {
284+
NodeAssert.deepEqual(parseSkillsCliOutput("not json"), []);
285+
});
286+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as NodeAssert from "node:assert/strict";
2+
3+
import * as NodeServices from "@effect/platform-node/NodeServices";
4+
import type { OpencodeClient } from "@opencode-ai/sdk/v2";
5+
import { it } from "@effect/vitest";
6+
import * as Effect from "effect/Effect";
7+
import * as Layer from "effect/Layer";
8+
9+
import { OpenCodeRuntime, OpenCodeRuntimeLive } from "./opencodeRuntime.ts";
10+
11+
const testLayer = OpenCodeRuntimeLive.pipe(Layer.provideMerge(NodeServices.layer));
12+
13+
it.layer(testLayer)("loadOpenCodeInventory", (it) => {
14+
it.effect("keeps provider inventory when skill discovery fails", () =>
15+
Effect.gen(function* () {
16+
const runtime = yield* OpenCodeRuntime;
17+
const client = {
18+
provider: {
19+
list: () =>
20+
Promise.resolve({
21+
data: {
22+
connected: ["openai"],
23+
all: [],
24+
default: {},
25+
},
26+
}),
27+
},
28+
app: {
29+
agents: () => Promise.resolve({ data: [] }),
30+
skills: () => Promise.reject(new Error("skills endpoint unavailable")),
31+
},
32+
} as unknown as OpencodeClient;
33+
34+
const inventory = yield* runtime.loadOpenCodeInventory(client);
35+
36+
NodeAssert.deepEqual(inventory.providerList.connected, ["openai"]);
37+
NodeAssert.deepEqual(inventory.agents, []);
38+
NodeAssert.deepEqual(inventory.skills, []);
39+
}),
40+
);
41+
});

0 commit comments

Comments
 (0)