The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 24, 15:15 UTC
Add OpenCode skill discovery (#3154)
David Balderston committed
Aug 19, 2026 at 12:38 UTC
cf251c3bd00ff0e0cc90a78b20c043cf58f330ad
5 files changed
+253
-19
apps/server/src/provider/Layers/OpenCodeProvider.test.ts
+80
-3
@@ -34,20 +34,24 @@ const runtimeMock = {
34
runVersionError: null as Error | null,
35
versionStdout: DEFAULT_VERSION_STDOUT,
36
inventoryError: null as Error | null,
37
+ inventoryCwd: null as string | null,
38
closeCalls: 0,
39
inventory: {
40
providerList: { connected: [] as string[], all: [] as unknown[], default: {} },
41
agents: [] as unknown[],
42
+ skills: [] as unknown[],
43
} as unknown,
44
},
45
reset() {
46
this.state.runVersionError = null;
47
this.state.versionStdout = DEFAULT_VERSION_STDOUT;
48
this.state.inventoryError = null;
49
+ this.state.inventoryCwd = null;
50
this.state.closeCalls = 0;
51
this.state.inventory = {
52
providerList: { connected: [], all: [] as unknown[], default: {} },
53
agents: [] as unknown[],
54
+ skills: [] as unknown[],
55
};
56
},
57
};
@@ -95,8 +99,9 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
99
}),
100
)
101
: 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
105
? Effect.fail(
106
new OpenCodeRuntimeError({
107
operation: "loadInventoryFromCli",
@@ -104,7 +109,8 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {
109
cause: runtimeMock.state.inventoryError,
110
}),
111
)
107
- : Effect.succeed(runtimeMock.state.inventory as OpenCodeInventory),
112
+ : Effect.succeed(runtimeMock.state.inventory as OpenCodeInventory);
113
+ },
114
};
115
116
beforeEach(() => {
@@ -207,11 +213,82 @@ it.layer(testLayer)("checkOpenCodeProviderStatus", (it) => {
213
}),
214
);
215
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
+
286
it.effect("does not spawn a local server for health check (uses CLI instead)", () =>
287
Effect.gen(function* () {
288
yield* checkOpenCodeProviderStatus(makeOpenCodeSettings(), process.cwd());
289
290
NodeAssert.equal(runtimeMock.state.closeCalls, 0);
291
+ NodeAssert.equal(runtimeMock.state.inventoryCwd, process.cwd());
292
}),
293
);
294
apps/server/src/provider/Layers/OpenCodeProvider.ts
+30
@@ -2,6 +2,7 @@ import {
2
type ModelCapabilities,
3
type OpenCodeSettings,
4
type ServerProviderModel,
5
+ type ServerProviderSkill,
6
} from "@t3tools/contracts";
7
import * as Cause from "effect/Cause";
8
import * as Data from "effect/Data";
@@ -250,6 +251,32 @@ function flattenOpenCodeModels(input: OpenCodeInventory): ReadonlyArray<ServerPr
251
return models.toSorted((left, right) => left.name.localeCompare(right.name));
252
}
253
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
+
280
export const makePendingOpenCodeProvider = (
281
openCodeSettings: OpenCodeSettings,
282
): Effect.Effect<ServerProviderDraft> =>
@@ -412,6 +439,7 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
439
)
440
: openCodeRuntime.loadInventoryFromCli({
441
binaryPath: openCodeSettings.binaryPath,
442
+ cwd,
443
environment: resolvedEnvironment,
444
})
445
).pipe(
@@ -429,12 +457,14 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu
457
customModels,
458
DEFAULT_OPENCODE_MODEL_CAPABILITIES,
459
);
460
+ const skills = flattenOpenCodeSkills(inventoryExit.value);
461
const connectedCount = inventoryExit.value.providerList.connected.length;
462
return buildServerProvider({
463
presentation: OPENCODE_PRESENTATION,
464
enabled: true,
465
checkedAt,
466
models,
467
+ skills,
468
probe: {
469
installed: true,
470
version,
apps/server/src/provider/opencodeRuntime.cliParsers.test.ts
+33
-1
@@ -2,7 +2,11 @@ import * as NodeAssert from "node:assert/strict";
2
3
import { describe, it } from "vite-plus/test";
4
5
-import { parseModelsCliOutput, parseAgentListCliOutput } from "./opencodeRuntime.ts";
5
+import {
6
+ parseAgentListCliOutput,
7
+ parseModelsCliOutput,
8
+ parseSkillsCliOutput,
9
+} from "./opencodeRuntime.ts";
10
11
describe("parseModelsCliOutput", () => {
12
it("parses a single model from a single provider", () => {
@@ -252,3 +256,31 @@ describe("parseAgentListCliOutput", () => {
256
NodeAssert.equal(result[1]!.hidden, false);
257
});
258
});
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
+});
apps/server/src/provider/opencodeRuntime.inventory.test.ts
new
+41
@@ -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
+});
apps/server/src/provider/opencodeRuntime.ts
+69
-15
@@ -112,6 +112,7 @@ export interface OpenCodeCommandResult {
112
export interface OpenCodeInventory {
113
readonly providerList: ProviderListResponse;
114
readonly agents: ReadonlyArray<Agent>;
115
+ readonly skills: ReadonlyArray<OpenCodeSkill>;
116
}
117
118
export interface ParsedOpenCodeModelSlug {
@@ -119,6 +120,23 @@ export interface ParsedOpenCodeModelSlug {
120
readonly modelID: string;
121
}
122
123
+export interface OpenCodeSkill {
124
+ readonly name?: string | null;
125
+ readonly description?: string | null;
126
+ readonly location?: string | null;
127
+ readonly content?: string | null;
128
+}
129
+
130
+const OpenCodeSkillSchema = Schema.Struct({
131
+ name: Schema.optionalKey(Schema.NullOr(Schema.String)),
132
+ description: Schema.optionalKey(Schema.NullOr(Schema.String)),
133
+ location: Schema.optionalKey(Schema.NullOr(Schema.String)),
134
+ content: Schema.optionalKey(Schema.NullOr(Schema.String)),
135
+});
136
+const decodeOpenCodeSkillsCliOutputExit = Schema.decodeUnknownExit(
137
+ Schema.fromJsonString(Schema.Array(OpenCodeSkillSchema)),
138
+);
139
+
140
export interface OpenCodeRuntimeShape {
141
/**
142
* Spawns a local OpenCode server process. Its lifetime is bound to the caller's
@@ -150,6 +168,7 @@ export interface OpenCodeRuntimeShape {
168
readonly binaryPath: string;
169
readonly args: ReadonlyArray<string>;
170
readonly environment?: NodeJS.ProcessEnv;
171
+ readonly cwd?: string;
172
}) => Effect.Effect<OpenCodeCommandResult, OpenCodeRuntimeError>;
173
readonly createOpenCodeSdkClient: (input: {
174
readonly baseUrl: string;
@@ -161,6 +180,7 @@ export interface OpenCodeRuntimeShape {
180
) => Effect.Effect<OpenCodeInventory, OpenCodeRuntimeError>;
181
readonly loadInventoryFromCli: (input: {
182
readonly binaryPath: string;
183
+ readonly cwd: string;
184
readonly environment?: NodeJS.ProcessEnv;
185
}) => Effect.Effect<OpenCodeInventory, OpenCodeRuntimeError>;
186
}
@@ -289,6 +309,12 @@ export function parseAgentListCliOutput(stdout: string): ReadonlyArray<Agent> {
309
return agents;
310
}
311
312
+/** @internal */
313
+export function parseSkillsCliOutput(stdout: string): ReadonlyArray<OpenCodeSkill> {
314
+ const result = decodeOpenCodeSkillsCliOutputExit(stdout);
315
+ return Exit.isSuccess(result) ? result.value : [];
316
+}
317
+
318
export function parseOpenCodeModelSlug(
319
slug: string | null | undefined,
320
): ParsedOpenCodeModelSlug | null {
@@ -417,6 +443,7 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
443
const child = yield* spawner.spawn(
444
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
445
shell: spawnCommand.shell,
446
+ ...(input.cwd ? { cwd: input.cwd } : {}),
447
...(input.environment ? { env: input.environment } : { extendEnv: true }),
448
}),
449
);
@@ -673,45 +700,67 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
700
Effect.map((result) => result.data ?? []),
701
);
702
676
- const loadOpenCodeInventory: OpenCodeRuntimeShape["loadOpenCodeInventory"] = (client) =>
677
- Effect.all([loadProviders(client), loadAgents(client)], { concurrency: "unbounded" }).pipe(
678
- Effect.map(([providerList, agents]) => ({ providerList, agents })),
703
+ const loadSkills = (client: OpencodeClient) =>
704
+ runOpenCodeSdk("app.skills", () => client.app.skills()).pipe(
705
+ Effect.map((result) => (result.data ?? []) as ReadonlyArray<OpenCodeSkill>),
706
+ Effect.orElseSucceed((): ReadonlyArray<OpenCodeSkill> => []),
707
);
708
709
+ const loadOpenCodeInventory: OpenCodeRuntimeShape["loadOpenCodeInventory"] = (client) =>
710
+ Effect.all([loadProviders(client), loadAgents(client), loadSkills(client)], {
711
+ concurrency: "unbounded",
712
+ }).pipe(Effect.map(([providerList, agents, skills]) => ({ providerList, agents, skills })));
713
+
714
const loadInventoryFromCli: OpenCodeRuntimeShape["loadInventoryFromCli"] = (input) =>
715
Effect.gen(function* () {
716
const env = input.environment !== undefined ? { environment: input.environment } : ({} as {});
717
+ const commandContext = { cwd: input.cwd, ...env };
718
719
const runModelsCli = () =>
720
runOpenCodeCommand({
721
binaryPath: input.binaryPath,
722
args: ["models", "--verbose"],
689
- ...env,
723
+ ...commandContext,
724
}).pipe(Effect.exit);
725
const runAgentsCli = () =>
692
- runOpenCodeCommand({ binaryPath: input.binaryPath, args: ["agent", "list"], ...env }).pipe(
693
- Effect.exit,
694
- );
726
+ runOpenCodeCommand({
727
+ binaryPath: input.binaryPath,
728
+ args: ["agent", "list"],
729
+ ...commandContext,
730
+ }).pipe(Effect.exit);
731
+ const runSkillsCli = () =>
732
+ runOpenCodeCommand({
733
+ binaryPath: input.binaryPath,
734
+ args: ["debug", "skill"],
735
+ ...commandContext,
736
+ }).pipe(Effect.exit);
737
696
- // First attempt — run both in parallel
697
- let [modelsResult, agentsResult] = yield* Effect.all([runModelsCli(), runAgentsCli()], {
698
- concurrency: "unbounded",
699
- });
738
+ // First attempt — run all inventory commands in parallel.
739
+ const [initialModelsResult, initialAgentsResult, initialSkillsResult] = yield* Effect.all(
740
+ [runModelsCli(), runAgentsCli(), runSkillsCli()],
741
+ { concurrency: "unbounded" },
742
+ );
743
+ let modelsResult = initialModelsResult;
744
+ let agentsResult = initialAgentsResult;
745
+ let skillsResult = initialSkillsResult;
746
747
// Retry once after 1s on transient failures (e.g. SQLite "database is locked")
748
const needsModelsRetry = modelsResult._tag === "Failure" || modelsResult.value.code !== 0;
749
const needsAgentsRetry = agentsResult._tag === "Failure" || agentsResult.value.code !== 0;
704
- if (needsModelsRetry || needsAgentsRetry) {
750
+ const needsSkillsRetry = skillsResult._tag === "Failure" || skillsResult.value.code !== 0;
751
+ if (needsModelsRetry || needsAgentsRetry || needsSkillsRetry) {
752
yield* Effect.sleep("1 second");
706
- const [m2, a2] = yield* Effect.all(
753
+ const [m2, a2, s2] = yield* Effect.all(
754
[
755
needsModelsRetry ? runModelsCli() : Effect.succeed(modelsResult),
756
needsAgentsRetry ? runAgentsCli() : Effect.succeed(agentsResult),
757
+ needsSkillsRetry ? runSkillsCli() : Effect.succeed(skillsResult),
758
],
759
{ concurrency: "unbounded" },
760
);
761
modelsResult = m2;
762
agentsResult = a2;
763
+ skillsResult = s2;
764
}
765
766
if (modelsResult._tag === "Failure") {
@@ -742,16 +791,21 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
791
}),
792
);
793
745
- // Agent metadata enriches model capabilities but is not required for an
746
- // authoritative model inventory, so it may still degrade to an empty list.
794
+ // Agent and skill metadata enrich the provider snapshot but are not required
795
+ // for an authoritative model inventory, so either may degrade to an empty list.
796
let agents: ReadonlyArray<Agent> = [];
797
if (agentsResult._tag === "Success" && agentsResult.value.code === 0) {
798
agents = parseAgentListCliOutput(agentsResult.value.stdout);
799
}
800
+ let skills: ReadonlyArray<OpenCodeSkill> = [];
801
+ if (skillsResult._tag === "Success" && skillsResult.value.code === 0) {
802
+ skills = parseSkillsCliOutput(skillsResult.value.stdout);
803
+ }
804
805
return {
806
providerList: { all: allProviders, default: {}, connected },
807
agents,
808
+ skills,
809
};
810
});
811