Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3059,6 +3059,90 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
}),
);

it.effect.each([
{
action: "github_create_issue",
resources: ["*"],
metadata: { input: { title: "Fix approvals", labels: ["bug"] } },
prompt: "github_create_issue",
sourceTool: "execute",
},
{
action: "github_create_issue",
resources: ["*"],
prompt: "github_create_issue",
},
{
action: "shell",
resources: ["echo FIRST"],
prompt: "echo FIRST",
},
{
action: "external_directory",
resources: ["/first/config.json", "/second/*"],
prompt: "external_directory",
},
{
action: "shell",
resources: ["git status *"],
prompt: "shell",
},
{
action: "external_directory",
resources: ["/first/config.json", "/second/config.json"],
prompt: "/first/config.json\n/second/config.json",
},
{ action: "custom", resources: [], prompt: "custom" },
])("shows a $action permission prompt for $resources", ({ prompt, sourceTool, ...permission }) =>
Effect.gen(function* () {
const { runtime, thread } = yield* resumed([
out("session.prompt", { sessionID: SESSION, text: "<any>" }),
promptAccepted,
...(sourceTool === undefined
? []
: [
event("session.tool.input.started", {
sessionID: SESSION,
assistantMessageID: shellAsk.data.source.messageID,
id: shellAsk.data.source.id,
name: sourceTool,
}),
]),
event("permission.asked", { ...shellAsk.data, ...permission, save: ["*"] }),
out("permission.reply", {
sessionID: SESSION,
requestID: shellAsk.data.id,
decision: "once",
}),
reply("permission.reply", null),
event("session.execution.succeeded", { sessionID: SESSION }),
]);
const requested = yield* Deferred.make<RuntimeRequestId>();
const events = yield* runtime.events.pipe(
Stream.tap((entry) =>
entry.type === "runtime_request.updated" && entry.runtimeRequest.status === "pending"
? Deferred.succeed(requested, entry.runtimeRequest.id)
: Effect.void,
),
Stream.takeUntil((entry) => entry.type === "turn.terminal"),
Stream.runCollect,
Effect.forkScoped,
);

yield* runtime.startTurn(turnInput(thread));
const requestId = yield* Deferred.await(requested);
yield* runtime.respondToRuntimeRequest({ requestId, decision: "accept" });

const items = (yield* Fiber.join(events)).flatMap((entry) =>
entry.type === "turn_item.updated" && entry.turnItem.type === "approval_request"
? [entry.turnItem]
: [],
);
assert.equal(items[0]?.prompt, prompt);
assert.equal(items[0]?.title, permission.action);
}),
);

it.effect("asks a subagent's permission request on the parent thread's turn", () =>
Effect.gen(function* () {
const child = "ses_f0e5aa64cffelFnoQRL0DAA9BH";
Expand Down
5 changes: 4 additions & 1 deletion packages/provider-opencode/src/server/v2/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,10 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
{
type: "approval_request",
requestKind: openCodePermissionRequestKind(data.action, toolName),
prompt: data.resources.length === 0 ? data.action : data.resources.join("\n"),
prompt:
data.resources.length === 0 || data.resources.some((resource) => resource.includes("*"))
? data.action
: data.resources.join("\n"),
options: [
{ decision: "cancel", label: "Cancel" },
{ decision: "decline", label: "Decline" },
Expand Down
Loading