Skip to content

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(server): bound OpenCode skill discovery output (#7675)

Simone58ba5594439c
diff --git a/apps/server/src/provider/Layers/OpenCodeProvider.test.ts b/apps/server/src/provider/Layers/OpenCodeProvider.test.ts
index 93f4b9799..7c07fe5ad 100644
--- a/apps/server/src/provider/Layers/OpenCodeProvider.test.ts
+++ b/apps/server/src/provider/Layers/OpenCodeProvider.test.ts
@@ -239,19 +239,16 @@ it.layer(testLayer)("checkOpenCodeProviderStatus", (it) => {
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",
},
],
};
diff --git a/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts b/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts
index 8d5ba3533..f02bf997c 100644
--- a/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts
+++ b/apps/server/src/provider/opencodeRuntime.cliParsers.test.ts
@@ -258,7 +258,7 @@ describe("parseAgentListCliOutput", () => {
});
describe("parseSkillsCliOutput", () => {
- it("parses skill metadata from the CLI JSON output", () => {
+ it("parses only skill metadata from the CLI JSON output", () => {
const result = parseSkillsCliOutput(
JSON.stringify([
{
@@ -275,7 +275,6 @@ describe("parseSkillsCliOutput", () => {
name: "review-pr",
description: "Review a pull request.",
location: "/tmp/review-pr/SKILL.md",
- content: "---\nname: review-pr\n---\n",
},
]);
});
diff --git a/apps/server/src/provider/opencodeRuntime.inventory.test.ts b/apps/server/src/provider/opencodeRuntime.inventory.test.ts
index 8b22a52a2..7db63745e 100644
--- a/apps/server/src/provider/opencodeRuntime.inventory.test.ts
+++ b/apps/server/src/provider/opencodeRuntime.inventory.test.ts
@@ -4,13 +4,20 @@ 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 FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
+import * as Path from "effect/Path";
+import {
+ HostProcessEnvironment,
+ HostProcessExecutablePath,
+ HostProcessPlatform,
+} from "@t3tools/shared/hostProcess";
import { OpenCodeRuntime, OpenCodeRuntimeLive } from "./opencodeRuntime.ts";
const testLayer = OpenCodeRuntimeLive.pipe(Layer.provideMerge(NodeServices.layer));
-it.layer(testLayer)("loadOpenCodeInventory", (it) => {
+it.layer(testLayer)("OpenCodeRuntime inventory", (it) => {
it.effect("keeps provider inventory when skill discovery fails", () =>
Effect.gen(function* () {
const runtime = yield* OpenCodeRuntime;
@@ -38,4 +45,121 @@ it.layer(testLayer)("loadOpenCodeInventory", (it) => {
NodeAssert.deepEqual(inventory.skills, []);
}),
);
+
+ it.effect("keeps only SDK skill metadata in inventory", () =>
+ 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.resolve({
+ data: [
+ {
+ name: "review",
+ description: "Review code changes",
+ location: "/skills/review/SKILL.md",
+ content: "unused skill content",
+ },
+ ],
+ }),
+ },
+ } as unknown as OpencodeClient;
+
+ const inventory = yield* runtime.loadOpenCodeInventory(client);
+
+ NodeAssert.deepEqual(inventory.skills, [
+ {
+ name: "review",
+ description: "Review code changes",
+ location: "/skills/review/SKILL.md",
+ },
+ ]);
+ }),
+ );
+
+ it.effect("drops oversized CLI skill output without losing the model inventory", () =>
+ Effect.gen(function* () {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const hostEnvironment = yield* HostProcessEnvironment;
+ const executablePath = yield* HostProcessExecutablePath;
+ const hostPlatform = yield* HostProcessPlatform;
+ const tempDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-opencode-inventory-" });
+ const isWindows = hostPlatform === "win32";
+ const binaryPath = path.join(tempDir, isWindows ? "opencode.cmd" : "opencode");
+ const scriptPath = path.join(tempDir, "opencode.mjs");
+ const oversizedContentBytes = 8 * 1024 * 1024 + 1;
+
+ yield* fs.writeFileString(
+ scriptPath,
+ [
+ 'if (process.argv[2] === "models") {',
+ ' process.stdout.write(`openai/gpt-test\\n{"id":"gpt-test","providerID":"openai","name":"GPT Test"}\\n`);',
+ '} else if (process.argv[2] === "debug") {',
+ ` const content = "x".repeat(${oversizedContentBytes});`,
+ ' process.stdout.write(`[{"name":"oversized","content":"${content}"}]`);',
+ "}",
+ "",
+ ].join("\n"),
+ );
+ yield* fs.writeFileString(
+ binaryPath,
+ [
+ ...(isWindows ? ["@echo off"] : ["#!/bin/sh"]),
+ isWindows
+ ? '"%T3_TEST_NODE_BINARY%" "%T3_TEST_OPENCODE_SCRIPT%" %*'
+ : 'exec "$T3_TEST_NODE_BINARY" "$T3_TEST_OPENCODE_SCRIPT" "$@"',
+ "",
+ ].join("\n"),
+ );
+ if (!isWindows) {
+ yield* fs.chmod(binaryPath, 0o755);
+ }
+
+ const runtime = yield* OpenCodeRuntime;
+ const inventory = yield* runtime.loadInventoryFromCli({
+ binaryPath,
+ cwd: tempDir,
+ environment: {
+ ...hostEnvironment,
+ T3_TEST_NODE_BINARY: executablePath,
+ T3_TEST_OPENCODE_SCRIPT: scriptPath,
+ },
+ });
+
+ NodeAssert.deepEqual(inventory.providerList.connected, ["openai"]);
+ NodeAssert.equal(inventory.skills.length, 0);
+ }),
+ );
+
+ it.effect("caps and drains command stdout and stderr when requested", () =>
+ Effect.gen(function* () {
+ const runtime = yield* OpenCodeRuntime;
+ const executablePath = yield* HostProcessExecutablePath;
+ const outputBytes = 2 * 1024 * 1024;
+ const result = yield* runtime.runOpenCodeCommand({
+ binaryPath: executablePath,
+ args: [
+ "-e",
+ `process.stdout.write("o".repeat(${outputBytes})); process.stderr.write("e".repeat(${outputBytes}));`,
+ ],
+ maxOutputBytes: 64,
+ });
+
+ NodeAssert.equal(result.stdout, "o".repeat(64));
+ NodeAssert.equal(result.stderr, "e".repeat(64));
+ NodeAssert.equal(result.code, 0);
+ }),
+ );
});
diff --git a/apps/server/src/provider/opencodeRuntime.ts b/apps/server/src/provider/opencodeRuntime.ts
index 2ff4fa129..6d2436ca2 100644
--- a/apps/server/src/provider/opencodeRuntime.ts
+++ b/apps/server/src/provider/opencodeRuntime.ts
@@ -51,6 +51,7 @@ export function resolveOpenCodeConfigContent(
const OPENCODE_SERVER_READY_PREFIX = "opencode server listening";
const DEFAULT_OPENCODE_SERVER_TIMEOUT_MS = 30_000;
const DEFAULT_HOSTNAME = "127.0.0.1";
+const OPENCODE_SKILL_DISCOVERY_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
export interface OpenCodeServerProcess {
readonly url: string;
readonly exitCode: Effect.Effect<number, never>;
@@ -124,14 +125,12 @@ 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)),
@@ -169,6 +168,7 @@ export interface OpenCodeRuntimeShape {
readonly args: ReadonlyArray<string>;
readonly environment?: NodeJS.ProcessEnv;
readonly cwd?: string;
+ readonly maxOutputBytes?: number;
}) => Effect.Effect<OpenCodeCommandResult, OpenCodeRuntimeError>;
readonly createOpenCodeSdkClient: (input: {
readonly baseUrl: string;
@@ -447,8 +447,14 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
...(input.environment ? { env: input.environment } : { extendEnv: true }),
}),
);
+ const collectOptions =
+ input.maxOutputBytes === undefined ? undefined : { maxBytes: input.maxOutputBytes };
const [stdout, stderr, code] = yield* Effect.all(
- [collectStreamAsString(child.stdout), collectStreamAsString(child.stderr), child.exitCode],
+ [
+ collectStreamAsString(child.stdout, collectOptions),
+ collectStreamAsString(child.stderr, collectOptions),
+ child.exitCode,
+ ],
{ concurrency: "unbounded" },
);
const exitCode = Number(code);
@@ -702,7 +708,13 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
const loadSkills = (client: OpencodeClient) =>
runOpenCodeSdk("app.skills", () => client.app.skills()).pipe(
- Effect.map((result) => (result.data ?? []) as ReadonlyArray<OpenCodeSkill>),
+ Effect.map((result) =>
+ (result.data ?? []).map((skill) => ({
+ name: skill.name,
+ ...(skill.description === undefined ? {} : { description: skill.description }),
+ location: skill.location,
+ })),
+ ),
Effect.orElseSucceed((): ReadonlyArray<OpenCodeSkill> => []),
);
@@ -732,6 +744,7 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
runOpenCodeCommand({
binaryPath: input.binaryPath,
args: ["debug", "skill"],
+ maxOutputBytes: OPENCODE_SKILL_DISCOVERY_MAX_OUTPUT_BYTES,
...commandContext,
}).pipe(Effect.exit);
diff --git a/apps/server/src/provider/providerSnapshot.ts b/apps/server/src/provider/providerSnapshot.ts
index 03b4cf4a3..adbe110d9 100644
--- a/apps/server/src/provider/providerSnapshot.ts
+++ b/apps/server/src/provider/providerSnapshot.ts
@@ -255,5 +255,6 @@ export function buildServerProvider(input: {
export const collectStreamAsString = <E>(
stream: Stream.Stream<Uint8Array, E>,
+ options?: { readonly maxBytes?: number | undefined },
): Effect.Effect<string, E> =>
- collectUint8StreamText({ stream }).pipe(Effect.map((collected) => collected.text));
+ collectUint8StreamText({ stream, ...options }).pipe(Effect.map((collected) => collected.text));