Skip to content
TypeScript

fix(opencode): nested custom commands like /git/commit run as commands (#29765)

Alex Southwell136fe4336817
diff --git a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
index c334af4fad1..10006c532e9 100644
--- a/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
+++ b/apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
@@ -2453,7 +2453,7 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
// session.command returns 204 without an inbox id; the stream drops before session.inbox.enqueued provides it.
const { runtime, thread } = yield* resumed([
out("command.list", "<any>"),
- reply("command.list", { location: { directory: WORK }, data: [{ name: "hello" }] }),
+ reply("command.list", { location: { directory: WORK }, data: [{ name: "git/hello" }] }),
out("message.list", { sessionID: SESSION, order: "desc", limit: "1" }),
reply("message.list", {
data: [
@@ -2461,7 +2461,7 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
],
cursor: {},
}),
- out("session.command", { sessionID: SESSION, name: "hello", text: "WORLD" }),
+ out("session.command", { sessionID: SESSION, name: "git/hello", text: "WORLD" }),
reply("session.command", null),
{ type: "runtime_exit", status: "success" } as const,
out("event.subscribe"),
@@ -2498,7 +2498,7 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
);
yield* runtime.startTurn({
...turnInput(thread),
- message: { ...turnInput(thread).message, text: "/hello WORLD" },
+ message: { ...turnInput(thread).message, text: "/git/hello WORLD" },
});
const collected = yield* Fiber.join(events);
const texts = collected.flatMap((event) =>
diff --git a/packages/provider-opencode/src/server/adapter.test.ts b/packages/provider-opencode/src/server/adapter.test.ts
index 5313eb72a9d..4ff3c3efd0d 100644
--- a/packages/provider-opencode/src/server/adapter.test.ts
+++ b/packages/provider-opencode/src/server/adapter.test.ts
@@ -1363,7 +1363,7 @@ describe("OpenCodeAdapterV2", () => {
return { stream: nativeEvents.stream };
},
},
- command: { list: async () => ({ data: [{ name: "review" }] }) },
+ command: { list: async () => ({ data: [{ name: "git/review" }] }) },
session: {
create: async () => ({ data: { id: sessionId, time: { created: 1, updated: 1 } } }),
command: async (input: {
@@ -1382,9 +1382,9 @@ describe("OpenCodeAdapterV2", () => {
},
},
});
- const start = yield* harness.startTurn("/review staged changes").pipe(Effect.forkScoped);
+ const start = yield* harness.startTurn("/git/review staged changes").pipe(Effect.forkScoped);
const call = yield* Queue.take(calls);
- assert.equal(call.command, "review");
+ assert.equal(call.command, "git/review");
assert.equal(call.arguments, "staged changes");
assert.equal(call.model, "anthropic/claude-sonnet");
yield* Effect.promise(() =>
diff --git a/packages/provider-opencode/src/server/adapter.ts b/packages/provider-opencode/src/server/adapter.ts
index b3252825794..14b203b6087 100644
--- a/packages/provider-opencode/src/server/adapter.ts
+++ b/packages/provider-opencode/src/server/adapter.ts
@@ -2978,7 +2978,7 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
.map((part) => part.text)
.join("\n")
.trim();
- const match = text?.match(/^\/([^\s/]+)(?:\s+([\s\S]*))?$/);
+ const match = text?.match(/^\/(\S+)(?:\s+([\s\S]*))?$/);
const command = match
? (yield* OpenCodeRuntime.loadOpenCodeCommands(client).pipe(
Effect.timeout("10 seconds"),
diff --git a/packages/provider-opencode/src/server/v2/adapter.ts b/packages/provider-opencode/src/server/v2/adapter.ts
index 2e0f76c34ea..a6f7af44964 100644
--- a/packages/provider-opencode/src/server/v2/adapter.ts
+++ b/packages/provider-opencode/src/server/v2/adapter.ts
@@ -627,7 +627,7 @@ const agentFor = (input: ProviderAdapter.ProviderAdapterV2TurnInput) =>
input.runtimePolicy.interactionMode === "plan" ? "plan" : "build";
const commandOf = (text: string) => {
- const match = /^\/([^\s/]+)(?:\s+([\s\S]*))?$/.exec(text.trim());
+ const match = /^\/(\S+)(?:\s+([\s\S]*))?$/.exec(text.trim());
return match === null ? undefined : { name: match[1]!, text: match[2] ?? "" };
};