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.
Add OpenCode skill discovery (#3154)
David Balderstoncf251c3bd00f
diff --git a/apps/server/src/provider/Layers/OpenCodeProvider.test.ts b/apps/server/src/provider/Layers/OpenCodeProvider.test.tsindex 41454b48b..93f4b9799 100644--- a/apps/server/src/provider/Layers/OpenCodeProvider.test.ts+++ b/apps/server/src/provider/Layers/OpenCodeProvider.test.ts@@ -34,20 +34,24 @@ const runtimeMock = {runVersionError: null as Error | null,versionStdout: DEFAULT_VERSION_STDOUT,inventoryError: null as Error | null,+ inventoryCwd: null as string | null,closeCalls: 0,inventory: {providerList: { connected: [] as string[], all: [] as unknown[], default: {} },agents: [] as unknown[],+ skills: [] as unknown[],} as unknown,},reset() {this.state.runVersionError = null;this.state.versionStdout = DEFAULT_VERSION_STDOUT;this.state.inventoryError = null;+ this.state.inventoryCwd = null;this.state.closeCalls = 0;this.state.inventory = {providerList: { connected: [], all: [] as unknown[], default: {} },agents: [] as unknown[],+ skills: [] as unknown[],};},};@@ -95,8 +99,9 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {}),): Effect.succeed(runtimeMock.state.inventory as OpenCodeInventory),- loadInventoryFromCli: () =>- runtimeMock.state.inventoryError+ loadInventoryFromCli: ({ cwd }) => {+ runtimeMock.state.inventoryCwd = cwd;+ return runtimeMock.state.inventoryError? Effect.fail(new OpenCodeRuntimeError({operation: "loadInventoryFromCli",@@ -104,7 +109,8 @@ const OpenCodeRuntimeTestDouble: OpenCodeRuntimeShape = {cause: runtimeMock.state.inventoryError,}),)- : Effect.succeed(runtimeMock.state.inventory as OpenCodeInventory),+ : Effect.succeed(runtimeMock.state.inventory as OpenCodeInventory);+ },};beforeEach(() => {@@ -207,11 +213,82 @@ it.layer(testLayer)("checkOpenCodeProviderStatus", (it) => {}),);+ it.effect("includes OpenCode skills in the provider snapshot", () =>+ Effect.gen(function* () {+ runtimeMock.state.inventory = {+ providerList: {+ connected: ["openai"],+ all: [+ {+ id: "openai",+ name: "OpenAI",+ models: {+ "gpt-5.4": {+ id: "gpt-5.4",+ name: "GPT-5.4",+ variants: {},+ },+ },+ },+ ],+ default: {},+ },+ agents: [],+ skills: [+ {+ name: "openclaw-review",+ description: "Review OpenClaw workflow changes.",+ location: "/Users/test/.agents/skills/openclaw-review/SKILL.md",+ content: "---\nname: openclaw-review\n---\n",+ },+ {+ name: "openclaw-triage",+ description: "Triage OpenClaw routing issues.",+ location: "/Users/test/.agents/skills/openclaw-triage/SKILL.md",+ content: "---\nname: openclaw-triage\n---\n",+ },+ {+ name: "missing-location",+ description: "This incomplete SDK row should be skipped.",+ location: "",+ content: "---\nname: missing-location\n---\n",+ },+ ],+ };++ const snapshot = yield* checkOpenCodeProviderStatus(makeOpenCodeSettings(), process.cwd());++ NodeAssert.deepEqual(+ snapshot.skills.map((skill) => ({+ name: skill.name,+ path: skill.path,+ enabled: skill.enabled,+ shortDescription: skill.shortDescription,+ })),+ [+ {+ name: "openclaw-review",+ path: "/Users/test/.agents/skills/openclaw-review/SKILL.md",+ enabled: true,+ shortDescription: "Review OpenClaw workflow changes.",+ },+ {+ name: "openclaw-triage",+ path: "/Users/test/.agents/skills/openclaw-triage/SKILL.md",+ enabled: true,+ shortDescription: "Triage OpenClaw routing issues.",+ },+ ],+ );+ }),+ );+it.effect("does not spawn a local server for health check (uses CLI instead)", () =>Effect.gen(function* () {yield* checkOpenCodeProviderStatus(makeOpenCodeSettings(), process.cwd());NodeAssert.equal(runtimeMock.state.closeCalls, 0);+ NodeAssert.equal(runtimeMock.state.inventoryCwd, process.cwd());}),);diff --git a/apps/server/src/provider/Layers/OpenCodeProvider.ts b/apps/server/src/provider/Layers/OpenCodeProvider.tsindex 21014e33f..62f29c47e 100644--- a/apps/server/src/provider/Layers/OpenCodeProvider.ts+++ b/apps/server/src/provider/Layers/OpenCodeProvider.ts@@ -2,6 +2,7 @@ import {type ModelCapabilities,type OpenCodeSettings,type ServerProviderModel,+ type ServerProviderSkill,} from "@t3tools/contracts";import * as Cause from "effect/Cause";import * as Data from "effect/Data";@@ -250,6 +251,32 @@ function flattenOpenCodeModels(input: OpenCodeInventory): ReadonlyArray<ServerPrreturn models.toSorted((left, right) => left.name.localeCompare(right.name));}+function trimOptional(value: string | null | undefined): string | undefined {+ const trimmed = value?.trim();+ return trimmed && trimmed.length > 0 ? trimmed : undefined;+}++function flattenOpenCodeSkills(input: OpenCodeInventory): ReadonlyArray<ServerProviderSkill> {+ const skills: ServerProviderSkill[] = [];+ for (const skill of input.skills ?? []) {+ const name = trimOptional(skill.name);+ const path = trimOptional(skill.location);+ if (!name || !path) {+ continue;+ }++ const description = trimOptional(skill.description);+ skills.push({+ name,+ path,+ enabled: true,+ ...(description ? { description, shortDescription: description } : {}),+ });+ }++ return skills.toSorted((left, right) => left.name.localeCompare(right.name));+}+export const makePendingOpenCodeProvider = (openCodeSettings: OpenCodeSettings,): Effect.Effect<ServerProviderDraft> =>@@ -412,6 +439,7 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatu): openCodeRuntime.loadInventoryFromCli({binaryPath: openCodeSettings.binaryPath,+ cwd,environment: resolvedEnvironment,})).pipe(@@ -429,12 +457,14 @@ export const checkOpenCodeProviderStatus = Effect.fn("checkOpenCodeProviderStatucustomModels,DEFAULT_OPENCODE_MODEL_CAPABILITIES,);+ const skills = flattenOpenCodeSkills(inventoryExit.value);const connectedCount = inventoryExit.value.providerList.connected.length;return buildServerProvider({presentation: OPENCODE_PRESENTATION,enabled: true,checkedAt,models,+ skills,probe: {installed: true,version,diff --git a/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts b/apps/server/src/provider/opencodeRuntime.cliParsers.test.tsindex 46577f377..8d5ba3533 100644--- a/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts+++ b/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts@@ -2,7 +2,11 @@ import * as NodeAssert from "node:assert/strict";import { describe, it } from "vite-plus/test";-import { parseModelsCliOutput, parseAgentListCliOutput } from "./opencodeRuntime.ts";+import {+ parseAgentListCliOutput,+ parseModelsCliOutput,+ parseSkillsCliOutput,+} from "./opencodeRuntime.ts";describe("parseModelsCliOutput", () => {it("parses a single model from a single provider", () => {@@ -252,3 +256,31 @@ describe("parseAgentListCliOutput", () => {NodeAssert.equal(result[1]!.hidden, false);});});++describe("parseSkillsCliOutput", () => {+ it("parses skill metadata from the CLI JSON output", () => {+ const result = parseSkillsCliOutput(+ JSON.stringify([+ {+ name: "review-pr",+ description: "Review a pull request.",+ location: "/tmp/review-pr/SKILL.md",+ content: "---\nname: review-pr\n---\n",+ },+ ]),+ );++ NodeAssert.deepEqual(result, [+ {+ name: "review-pr",+ description: "Review a pull request.",+ location: "/tmp/review-pr/SKILL.md",+ content: "---\nname: review-pr\n---\n",+ },+ ]);+ });++ it("degrades malformed output to an empty skill list", () => {+ NodeAssert.deepEqual(parseSkillsCliOutput("not json"), []);+ });+});diff --git a/apps/server/src/provider/opencodeRuntime.inventory.test.ts b/apps/server/src/provider/opencodeRuntime.inventory.test.tsnew file mode 100644index 000000000..8b22a52a2--- /dev/null+++ b/apps/server/src/provider/opencodeRuntime.inventory.test.ts@@ -0,0 +1,41 @@+import * as NodeAssert from "node:assert/strict";++import * as NodeServices from "@effect/platform-node/NodeServices";+import type { OpencodeClient } from "@opencode-ai/sdk/v2";+import { it } from "@effect/vitest";+import * as Effect from "effect/Effect";+import * as Layer from "effect/Layer";++import { OpenCodeRuntime, OpenCodeRuntimeLive } from "./opencodeRuntime.ts";++const testLayer = OpenCodeRuntimeLive.pipe(Layer.provideMerge(NodeServices.layer));++it.layer(testLayer)("loadOpenCodeInventory", (it) => {+ it.effect("keeps provider inventory when skill discovery fails", () =>+ Effect.gen(function* () {+ const runtime = yield* OpenCodeRuntime;+ const client = {+ provider: {+ list: () =>+ Promise.resolve({+ data: {+ connected: ["openai"],+ all: [],+ default: {},+ },+ }),+ },+ app: {+ agents: () => Promise.resolve({ data: [] }),+ skills: () => Promise.reject(new Error("skills endpoint unavailable")),+ },+ } as unknown as OpencodeClient;++ const inventory = yield* runtime.loadOpenCodeInventory(client);++ NodeAssert.deepEqual(inventory.providerList.connected, ["openai"]);+ NodeAssert.deepEqual(inventory.agents, []);+ NodeAssert.deepEqual(inventory.skills, []);+ }),+ );+});diff --git a/apps/server/src/provider/opencodeRuntime.ts b/apps/server/src/provider/opencodeRuntime.tsindex 399e7d6b3..2ff4fa129 100644--- a/apps/server/src/provider/opencodeRuntime.ts+++ b/apps/server/src/provider/opencodeRuntime.ts@@ -112,6 +112,7 @@ export interface OpenCodeCommandResult {export interface OpenCodeInventory {readonly providerList: ProviderListResponse;readonly agents: ReadonlyArray<Agent>;+ readonly skills: ReadonlyArray<OpenCodeSkill>;}export interface ParsedOpenCodeModelSlug {@@ -119,6 +120,23 @@ export interface ParsedOpenCodeModelSlug {readonly modelID: string;}+export interface OpenCodeSkill {+ readonly name?: string | null;+ readonly description?: string | null;+ readonly location?: string | null;+ readonly content?: string | null;+}++const OpenCodeSkillSchema = Schema.Struct({+ name: Schema.optionalKey(Schema.NullOr(Schema.String)),+ description: Schema.optionalKey(Schema.NullOr(Schema.String)),+ location: Schema.optionalKey(Schema.NullOr(Schema.String)),+ content: Schema.optionalKey(Schema.NullOr(Schema.String)),+});+const decodeOpenCodeSkillsCliOutputExit = Schema.decodeUnknownExit(+ Schema.fromJsonString(Schema.Array(OpenCodeSkillSchema)),+);+export interface OpenCodeRuntimeShape {/*** Spawns a local OpenCode server process. Its lifetime is bound to the caller's@@ -150,6 +168,7 @@ export interface OpenCodeRuntimeShape {readonly binaryPath: string;readonly args: ReadonlyArray<string>;readonly environment?: NodeJS.ProcessEnv;+ readonly cwd?: string;}) => Effect.Effect<OpenCodeCommandResult, OpenCodeRuntimeError>;readonly createOpenCodeSdkClient: (input: {readonly baseUrl: string;@@ -161,6 +180,7 @@ export interface OpenCodeRuntimeShape {) => Effect.Effect<OpenCodeInventory, OpenCodeRuntimeError>;readonly loadInventoryFromCli: (input: {readonly binaryPath: string;+ readonly cwd: string;readonly environment?: NodeJS.ProcessEnv;}) => Effect.Effect<OpenCodeInventory, OpenCodeRuntimeError>;}@@ -289,6 +309,12 @@ export function parseAgentListCliOutput(stdout: string): ReadonlyArray<Agent> {return agents;}+/** @internal */+export function parseSkillsCliOutput(stdout: string): ReadonlyArray<OpenCodeSkill> {+ const result = decodeOpenCodeSkillsCliOutputExit(stdout);+ return Exit.isSuccess(result) ? result.value : [];+}+export function parseOpenCodeModelSlug(slug: string | null | undefined,): ParsedOpenCodeModelSlug | null {@@ -417,6 +443,7 @@ const makeOpenCodeRuntime = Effect.gen(function* () {const child = yield* spawner.spawn(ChildProcess.make(spawnCommand.command, spawnCommand.args, {shell: spawnCommand.shell,+ ...(input.cwd ? { cwd: input.cwd } : {}),...(input.environment ? { env: input.environment } : { extendEnv: true }),}),);@@ -673,45 +700,67 @@ const makeOpenCodeRuntime = Effect.gen(function* () {Effect.map((result) => result.data ?? []),);- const loadOpenCodeInventory: OpenCodeRuntimeShape["loadOpenCodeInventory"] = (client) =>- Effect.all([loadProviders(client), loadAgents(client)], { concurrency: "unbounded" }).pipe(- Effect.map(([providerList, agents]) => ({ providerList, agents })),+ const loadSkills = (client: OpencodeClient) =>+ runOpenCodeSdk("app.skills", () => client.app.skills()).pipe(+ Effect.map((result) => (result.data ?? []) as ReadonlyArray<OpenCodeSkill>),+ Effect.orElseSucceed((): ReadonlyArray<OpenCodeSkill> => []),);+ const loadOpenCodeInventory: OpenCodeRuntimeShape["loadOpenCodeInventory"] = (client) =>+ Effect.all([loadProviders(client), loadAgents(client), loadSkills(client)], {+ concurrency: "unbounded",+ }).pipe(Effect.map(([providerList, agents, skills]) => ({ providerList, agents, skills })));+const loadInventoryFromCli: OpenCodeRuntimeShape["loadInventoryFromCli"] = (input) =>Effect.gen(function* () {const env = input.environment !== undefined ? { environment: input.environment } : ({} as {});+ const commandContext = { cwd: input.cwd, ...env };const runModelsCli = () =>runOpenCodeCommand({binaryPath: input.binaryPath,args: ["models", "--verbose"],- ...env,+ ...commandContext,}).pipe(Effect.exit);const runAgentsCli = () =>- runOpenCodeCommand({ binaryPath: input.binaryPath, args: ["agent", "list"], ...env }).pipe(- Effect.exit,- );+ runOpenCodeCommand({+ binaryPath: input.binaryPath,+ args: ["agent", "list"],+ ...commandContext,+ }).pipe(Effect.exit);+ const runSkillsCli = () =>+ runOpenCodeCommand({+ binaryPath: input.binaryPath,+ args: ["debug", "skill"],+ ...commandContext,+ }).pipe(Effect.exit);- // First attempt — run both in parallel- let [modelsResult, agentsResult] = yield* Effect.all([runModelsCli(), runAgentsCli()], {- concurrency: "unbounded",- });+ // First attempt — run all inventory commands in parallel.+ const [initialModelsResult, initialAgentsResult, initialSkillsResult] = yield* Effect.all(+ [runModelsCli(), runAgentsCli(), runSkillsCli()],+ { concurrency: "unbounded" },+ );+ let modelsResult = initialModelsResult;+ let agentsResult = initialAgentsResult;+ let skillsResult = initialSkillsResult;// Retry once after 1s on transient failures (e.g. SQLite "database is locked")const needsModelsRetry = modelsResult._tag === "Failure" || modelsResult.value.code !== 0;const needsAgentsRetry = agentsResult._tag === "Failure" || agentsResult.value.code !== 0;- if (needsModelsRetry || needsAgentsRetry) {+ const needsSkillsRetry = skillsResult._tag === "Failure" || skillsResult.value.code !== 0;+ if (needsModelsRetry || needsAgentsRetry || needsSkillsRetry) {yield* Effect.sleep("1 second");- const [m2, a2] = yield* Effect.all(+ const [m2, a2, s2] = yield* Effect.all([needsModelsRetry ? runModelsCli() : Effect.succeed(modelsResult),needsAgentsRetry ? runAgentsCli() : Effect.succeed(agentsResult),+ needsSkillsRetry ? runSkillsCli() : Effect.succeed(skillsResult),],{ concurrency: "unbounded" },);modelsResult = m2;agentsResult = a2;+ skillsResult = s2;}if (modelsResult._tag === "Failure") {@@ -742,16 +791,21 @@ const makeOpenCodeRuntime = Effect.gen(function* () {}),);- // Agent metadata enriches model capabilities but is not required for an- // authoritative model inventory, so it may still degrade to an empty list.+ // Agent and skill metadata enrich the provider snapshot but are not required+ // for an authoritative model inventory, so either may degrade to an empty list.let agents: ReadonlyArray<Agent> = [];if (agentsResult._tag === "Success" && agentsResult.value.code === 0) {agents = parseAgentListCliOutput(agentsResult.value.stdout);}+ let skills: ReadonlyArray<OpenCodeSkill> = [];+ if (skillsResult._tag === "Success" && skillsResult.value.code === 0) {+ skills = parseSkillsCliOutput(skillsResult.value.stdout);+ }return {providerList: { all: allProviders, default: {}, connected },agents,+ skills,};});