@devries-cameron20 / t3code Mirror · read-only / commits / a1e3917449
Fork 0

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 23, 01:45 UTC

fix(opencode): send pasted images with turns and steers (#16145)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Nikita Koynov committed Oct 19, 2026 at 21:43 UTC a1e39174493372daca48e6d59545a7681e64d0f6
3 files changed +351 -4
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
+266
@@ -1,6 +1,11 @@
1 +import * as NodeURL from "node:url";
2 import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
3 +import * as NodeServices from "@effect/platform-node/NodeServices";
4 import { assert, it } from "@effect/vitest";
5 import {
6 + ChatAttachmentId,
7 + ChatFileAttachment,
8 + ChatImageAttachment,
9 CheckpointId,
10 EnvironmentId,
11 MessageId,
@@ -23,6 +28,7 @@ import * as DateTime from "effect/DateTime";
28 import * as Deferred from "effect/Deferred";
29 import * as Effect from "effect/Effect";
30 import * as Fiber from "effect/Fiber";
31 +import * as FileSystem from "effect/FileSystem";
32 import * as Layer from "effect/Layer";
33 import * as Logger from "effect/Logger";
34 import * as Option from "effect/Option";
@@ -43,6 +49,7 @@ import {
49 OPENCODE_PROVIDER,
50 t3McpServerName,
51 } from "@t3tools/provider-opencode/testing";
52 +import { resolveAttachmentPath } from "../../attachmentStore.ts";
53 import { openCode2ReplayRuntime } from "./OpenCode2AdapterV2.testkit.ts";
54 import {
55 makeProviderReplayGate,
@@ -305,6 +312,9 @@ const resumed = (
312 readonly external?: boolean;
313 readonly supervised?: boolean;
314 readonly replayGate?: ProviderReplayGate;
315 + readonly attachmentsDir?: string;
316 + readonly fileSystem?: FileSystem.FileSystem;
317 + readonly onPrompt?: (input: unknown) => void;
318 },
319 ) =>
320 Effect.gen(function* () {
@@ -325,8 +335,13 @@ const resumed = (
335 ...entries,
336 ]),
337 {
338 + ...(options?.fileSystem === undefined ? {} : { fileSystem: options.fileSystem }),
339 + ...(options?.onPrompt === undefined ? {} : { onPrompt: options.onPrompt }),
340 ...(options?.external === undefined ? {} : { external: options.external }),
341 ...(options?.replayGate === undefined ? {} : { replayGate: options.replayGate }),
342 + ...(options?.attachmentsDir === undefined
343 + ? {}
344 + : { attachmentsDir: options.attachmentsDir }),
345 },
346 );
347 const thread = yield* runtime.resumeThread({
@@ -3377,6 +3392,257 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
3392 }).pipe(Effect.provide(NodeCrypto.layer)),
3393 );
3394
3395 + it.effect.each([
3396 + {
3397 + external: false,
3398 + name: "sends only existing supported images as turn and steer prompt files with path text",
3399 + },
3400 + {
3401 + external: true,
3402 + name: "keeps turn and steer attachment paths without local files for external servers",
3403 + },
3404 + ])("$name", ({ external }) =>
3405 + Effect.gen(function* () {
3406 + const fileSystem = yield* FileSystem.FileSystem;
3407 + const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
3408 + prefix: "t3 oc2 #images-",
3409 + });
3410 + const image = (id: string, name: string, mimeType = "image/png") =>
3411 + ChatImageAttachment.make({
3412 + type: "image",
3413 + id: ChatAttachmentId.make(`thread-opencode2-adapter-${id}-1234-1234-1234-123456789abc`),
3414 + name,
3415 + mimeType,
3416 + sizeBytes: 4,
3417 + });
3418 + const screenshot = image("12345678", "screen shot.png");
3419 + const chart = image("abcdefab", "chart.webp", "image/webp");
3420 + const missing = image("23456789", "missing.png");
3421 + const unsupported = image("34567890", "diagram.svg", "image/svg+xml");
3422 + const document = ChatFileAttachment.make({
3423 + type: "file",
3424 + id: ChatAttachmentId.make("thread-opencode2-adapter-45678901-1234-1234-1234-123456789abc"),
3425 + name: "requirements.pdf",
3426 + mimeType: "application/pdf",
3427 + sizeBytes: 4,
3428 + });
3429 + for (const attachment of [screenshot, chart, unsupported, document]) {
3430 + yield* fileSystem.writeFileString(
3431 + resolveAttachmentPath({ attachmentsDir, attachment })!,
3432 + "data",
3433 + );
3434 + }
3435 + const prompts: Array<unknown> = [];
3436 + const steerId = "msg_recorded_steer_image";
3437 + const { runtime, thread } = yield* resumed(
3438 + [
3439 + out("session.prompt", { sessionID: SESSION, text: "<any>" }),
3440 + promptAccepted,
3441 + event("session.execution.started", { sessionID: SESSION }),
3442 + out("session.prompt", { sessionID: SESSION, id: steerId, delivery: "steer" }),
3443 + replyData("session.prompt", {
3444 + id: steerId,
3445 + sessionID: SESSION,
3446 + time: { created: 1790656601500 },
3447 + type: "user",
3448 + payload: { text: "And this one?" },
3449 + delivery: "steer",
3450 + }),
3451 + event("session.inbox.delivered", { sessionID: SESSION, inboxID: steerId }),
3452 + event("session.execution.succeeded", { sessionID: SESSION }),
3453 + ],
3454 + { attachmentsDir, external, onPrompt: (input) => prompts.push(input) },
3455 + );
3456 + const ids = yield* IdAllocator.IdAllocatorV2;
3457 + const terminal = yield* terminalOf(runtime).pipe(Effect.forkScoped);
3458 + const input = turnInput(thread);
3459 + yield* runtime.startTurn({
3460 + ...input,
3461 + message: {
3462 + ...input.message,
3463 + text: "What is in this image?",
3464 + attachments: [screenshot, missing, unsupported, document],
3465 + },
3466 + });
3467 + yield* runtime.steerTurn({
3468 + threadId,
3469 + runId: input.runId,
3470 + providerThread: thread,
3471 + providerTurnId: ids.derive.providerTurn({
3472 + driver: OPENCODE_PROVIDER,
3473 + nativeTurnId: `${SESSION}:attempt:attempt:opencode2-adapter`,
3474 + }),
3475 + message: {
3476 + ...input.message,
3477 + messageId: MessageId.make("message:opencode2-adapter:steer"),
3478 + text: "And this one?",
3479 + attachments: [chart, missing, unsupported, document],
3480 + },
3481 + });
3482 + assert.equal((yield* Fiber.join(terminal))?.status, "completed");
3483 + assert.equal(prompts.length, 2);
3484 + for (const [index, attachment] of [screenshot, chart].entries()) {
3485 + const path = resolveAttachmentPath({ attachmentsDir, attachment })!;
3486 + assert.deepInclude(prompts[index], {
3487 + text: [
3488 + index === 0 ? "What is in this image?" : "And this one?",
3489 + `[Attached image "${attachment.name}" is saved at: ${path}]`,
3490 + `[Attached image "missing.png" is saved at: ${attachmentsDir}/${missing.id}.png]`,
3491 + `[Attached image "diagram.svg" is saved at: ${attachmentsDir}/${unsupported.id}.svg]`,
3492 + `[Attached file "requirements.pdf" is saved at: ${attachmentsDir}/${document.id}.pdf]`,
3493 + ].join("\n\n"),
3494 + });
3495 + if (external) {
3496 + assert.notProperty(prompts[index], "files");
3497 + } else {
3498 + assert.deepInclude(prompts[index], {
3499 + files: [
3500 + {
3501 + uri: NodeURL.pathToFileURL(path).href,
3502 + name: attachment.name,
3503 + },
3504 + ],
3505 + });
3506 + }
3507 + }
3508 + }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(IdAllocator.layer, NodeServices.layer))),
3509 + );
3510 +
3511 + it.effect.each([false, true])(
3512 + "rejects an image steer stopped during attachment resolution (held end: %s)",
3513 + (heldEnd) =>
3514 + Effect.gen(function* () {
3515 + const fileSystem = yield* FileSystem.FileSystem;
3516 + const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
3517 + prefix: "t3-oc2-stopped-image-",
3518 + });
3519 + const image = ChatImageAttachment.make({
3520 + type: "image",
3521 + id: ChatAttachmentId.make(
3522 + "thread-opencode2-adapter-12345678-1234-1234-1234-123456789abc",
3523 + ),
3524 + name: "screen.png",
3525 + mimeType: "image/png",
3526 + sizeBytes: 4,
3527 + });
3528 + const path = resolveAttachmentPath({ attachmentsDir, attachment: image })!;
3529 + yield* fileSystem.writeFileString(path, "data");
3530 + const resolving = yield* Deferred.make<void>();
3531 + const release = yield* Deferred.make<void>();
3532 + const gate = makeProviderReplayGate(["execution-end", "interrupt-reply"]);
3533 + const executionEnded = yield* Deferred.make<void>();
3534 + const prompts: Array<unknown> = [];
3535 + const { runtime, thread } = yield* resumed(
3536 + [
3537 + out("session.prompt", { sessionID: SESSION, text: "<any>" }),
3538 + promptAccepted,
3539 + event("session.execution.started", { sessionID: SESSION }),
3540 + ...(heldEnd
3541 + ? [
3542 + event("session.execution.succeeded", { sessionID: SESSION }, "execution-end"),
3543 + event("session.text.ended", {
3544 + sessionID: SESSION,
3545 + assistantMessageID: "msg_finished_before_stop",
3546 + ordinal: 0,
3547 + text: "Finished before Stop.",
3548 + }),
3549 + ]
3550 + : []),
3551 + out("session.interrupt", { sessionID: SESSION }),
3552 + ...(heldEnd
3553 + ? [event("session.usage.updated", { sessionID: SESSION }, "interrupt-reply")]
3554 + : []),
3555 + reply("session.interrupt", { interrupted: !heldEnd }),
3556 + ...(heldEnd ? [] : [event("session.execution.interrupted", { sessionID: SESSION })]),
3557 + out("session.prompt", { sessionID: SESSION, text: "<any>" }),
3558 + promptAccepted,
3559 + event("session.execution.started", { sessionID: SESSION }),
3560 + event("session.execution.succeeded", { sessionID: SESSION }),
3561 + ],
3562 + {
3563 + attachmentsDir,
3564 + replayGate: gate,
3565 + onPrompt: (input) => prompts.push(input),
3566 + fileSystem: {
3567 + ...fileSystem,
3568 + exists: (file) =>
3569 + file === path
3570 + ? Effect.gen(function* () {
3571 + yield* Deferred.succeed(resolving, undefined);
3572 + yield* Deferred.await(release);
3573 + return yield* fileSystem.exists(file);
3574 + })
3575 + : fileSystem.exists(file),
3576 + },
3577 + },
3578 + );
3579 + const stopped = yield* Deferred.make<void>();
3580 + const completed = yield* Deferred.make<void>();
3581 + const terminals: Array<string> = [];
3582 + yield* runtime.events.pipe(
3583 + Stream.tap((event) => {
3584 + if (
3585 + event.type === "turn_item.updated" &&
3586 + event.turnItem.type === "assistant_message" &&
3587 + event.turnItem.text === "Finished before Stop."
3588 + ) {
3589 + return Deferred.succeed(executionEnded, undefined);
3590 + }
3591 + if (event.type !== "turn.terminal") return Effect.void;
3592 + terminals.push(event.status);
3593 + return Deferred.succeed(terminals.length === 1 ? stopped : completed, undefined);
3594 + }),
3595 + Stream.runDrain,
3596 + Effect.forkScoped,
3597 + );
3598 + yield* runtime.startTurn(turnInput(thread));
3599 + const steer = yield* runtime
3600 + .steerTurn({
3601 + threadId,
3602 + runId: RunId.make("run:opencode2-adapter"),
3603 + providerThread: thread,
3604 + providerTurnId: yield* providerTurnId,
3605 + message: {
3606 + ...turnInput(thread).message,
3607 + messageId: MessageId.make("message:opencode2-adapter:steer"),
3608 + text: "Do not send this image after Stop.",
3609 + attachments: [image],
3610 + },
3611 + })
3612 + .pipe(Effect.exit, Effect.forkScoped);
3613 + yield* Deferred.await(resolving);
3614 + if (heldEnd) {
3615 + gate.release("execution-end");
3616 + yield* Deferred.await(executionEnded);
3617 + }
3618 + const interrupt = yield* runtime
3619 + .interruptTurn({
3620 + providerThread: thread,
3621 + providerTurnId: yield* providerTurnId,
3622 + })
3623 + .pipe(Effect.forkScoped);
3624 + if (heldEnd) {
3625 + assert.isTrue(yield* Effect.promise(() => gate.waitForReached("interrupt-reply")));
3626 + } else {
3627 + yield* Deferred.await(stopped);
3628 + }
3629 + yield* Deferred.succeed(release, undefined);
3630 + const result = yield* Fiber.join(steer);
3631 + assert.lengthOf(prompts, 1);
3632 + assert.isTrue(Exit.isFailure(result));
3633 + if (Exit.isFailure(result)) {
3634 + assert.deepInclude(Cause.squash(result.cause), { _tag: "ProviderAdapterProtocolError" });
3635 + }
3636 + yield* Deferred.await(stopped);
3637 + gate.release("interrupt-reply");
3638 + yield* Fiber.join(interrupt);
3639 + yield* runtime.startTurn(secondTurn(thread));
3640 + yield* Deferred.await(completed);
3641 + assert.lengthOf(prompts, 2);
3642 + assert.deepEqual(terminals, ["interrupted", "completed"]);
3643 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
3644 + );
3645 +
3646 it.effect("reads user and assistant text from the session's message list", () =>
3647 Effect.gen(function* () {
3648 const runtime = yield* openCode2ReplayRuntimeWithInstructions([
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.testkit.ts
+38 -3
@@ -7,6 +7,7 @@ import {
7 type ProviderReplayTranscript,
8 } from "@t3tools/contracts";
9 import * as Effect from "effect/Effect";
10 +import * as FileSystem from "effect/FileSystem";
11 import * as Layer from "effect/Layer";
12 import * as Schema from "effect/Schema";
13 import * as HttpClient from "effect/http/HttpClient";
@@ -17,6 +18,8 @@ import * as UrlParams from "effect/http/UrlParams";
18 import * as OpenCode2Client from "@t3tools/provider-opencode/server/v2/OpenCode2Client";
19 import * as OpenCode2Server from "@t3tools/provider-opencode/server/v2/OpenCode2Server";
20 import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
21 +import * as ProviderHost from "@t3tools/provider-core/server/ProviderHost";
22 +import { resolveAttachmentPath } from "../../attachmentStore.ts";
23 import * as ProviderAdapterRegistry from "../ProviderAdapterRegistry.ts";
24 import type { ProviderReplayGate } from "@t3tools/provider-testing/replayGate";
25 import type { OrchestratorV2ProviderReplayHarness } from "../testkit/ProviderReplayHarness.ts";
@@ -127,6 +130,7 @@ const operationOf = (
130 const replayHttpClient = (
131 controller: OpenCodeReplayController,
132 replayGate: ProviderReplayGate | undefined,
133 + onPrompt: ((input: unknown) => void) | undefined,
134 ) =>
135 HttpClient.make((request, url) =>
136 Effect.tryPromise({
@@ -148,6 +152,7 @@ const replayHttpClient = (
152 // The event stream and requests are separate connections: a request
153 // is matched only once what was recorded before it was delivered.
154 if (operation.type !== "event.subscribe") await controller.untilInboundDelivered();
155 + if (operation.type === "session.prompt") onPrompt?.(operation.input);
156 await controller.expectOutbound(operation);
157 if (operation.type === "event.subscribe") {
158 controller.exited = false;
@@ -187,6 +192,7 @@ export const replayServer = (
192 transcript: ProviderReplayTranscript,
193 options?: {
194 readonly external?: boolean;
195 + readonly onPrompt?: (input: unknown) => void;
196 readonly replayGate?: ProviderReplayGate;
197 readonly borrowers?: { current: number };
198 },
@@ -202,7 +208,7 @@ export const replayServer = (
208 const opencode = yield* OpenCode2Client.make.pipe(
209 Effect.provideService(
210 HttpClient.HttpClient,
205 - replayHttpClient(controller, options?.replayGate),
211 + replayHttpClient(controller, options?.replayGate, options?.onPrompt),
212 ),
213 );
214 const connection = {
@@ -233,6 +239,7 @@ const makeReplayAdapter = (
239 transcript: ProviderReplayTranscript,
240 options?: {
241 readonly external?: boolean;
242 + readonly onPrompt?: (input: unknown) => void;
243 readonly replayGate?: ProviderReplayGate;
244 readonly borrowers?: { current: number };
245 },
@@ -246,6 +253,20 @@ const makeReplayAdapter = (
253
254 const layerReplayHost = TestProviderHost.layer().pipe(Layer.provide(NodeServices.layer));
255
256 +const layerReplayHostWithAttachments = (attachmentsDir: string) =>
257 + Layer.effect(
258 + ProviderHost.ProviderHost,
259 + Effect.gen(function* () {
260 + const host = yield* ProviderHost.ProviderHost;
261 + return ProviderHost.ProviderHost.of({
262 + ...host,
263 + paths: { ...host.paths, attachmentsDir },
264 + resolveAttachmentPath: (attachment) =>
265 + resolveAttachmentPath({ attachmentsDir, attachment }),
266 + });
267 + }),
268 + ).pipe(Layer.provide(layerReplayHost));
269 +
270 function layerRegistry(
271 transcript: OpenCode2ReplayTranscript,
272 options?: { readonly replayGate?: ProviderReplayGate },
@@ -261,11 +282,15 @@ export const openCode2ReplayRuntime = (
282 entries: ReadonlyArray<ProviderReplayEntry>,
283 options?: {
284 readonly external?: boolean;
285 + readonly onPrompt?: (input: unknown) => void;
286 readonly borrowers?: { current: number };
287 readonly replayGate?: ProviderReplayGate;
288 + readonly attachmentsDir?: string;
289 + readonly fileSystem?: FileSystem.FileSystem;
290 },
291 ) =>
292 Effect.gen(function* () {
293 + const fileSystem = options?.fileSystem ?? (yield* FileSystem.FileSystem);
294 const adapter = yield* makeReplayAdapter(
295 {
296 provider: OPENCODE_PROVIDER,
@@ -275,7 +300,7 @@ export const openCode2ReplayRuntime = (
300 entries,
301 },
302 options,
278 - );
303 + ).pipe(Effect.provideService(FileSystem.FileSystem, fileSystem));
304 return yield* adapter.openSession({
305 threadId: ThreadId.make("thread:opencode2-adapter"),
306 providerSessionId: ProviderSessionId.make("provider-session:opencode2-adapter"),
@@ -289,7 +314,17 @@ export const openCode2ReplayRuntime = (
314 cwd: "/work/opencode2",
315 },
316 });
292 - }).pipe(Effect.provide(Layer.mergeAll(layerReplayHost, IdAllocator.layer, NodeServices.layer)));
317 + }).pipe(
318 + Effect.provide(
319 + Layer.mergeAll(
320 + options?.attachmentsDir === undefined
321 + ? layerReplayHost
322 + : layerReplayHostWithAttachments(options.attachmentsDir),
323 + IdAllocator.layer,
324 + NodeServices.layer,
325 + ),
326 + ),
327 + );
328
329 export const OpenCode2OrchestratorReplayHarness: OrchestratorV2ProviderReplayHarness<
330 OpenCode2ReplayTranscript,
packages/provider-opencode/src/server/v2/adapter.ts
+47 -1
@@ -1,3 +1,5 @@
1 +import * as NodeURL from "node:url";
2 +
3 import {
4 AbsolutePath,
5 Agent,
@@ -14,6 +16,7 @@ import {
16 import { Mcp } from "@opencode/schema/mcp";
17 import {
18 isOrchestrationV2WorkActive,
19 + type ChatAttachment,
20 type OrchestrationV2AppThread,
21 type OrchestrationV2ConversationMessage,
22 type OrchestrationV2ExecutionNode,
@@ -39,6 +42,7 @@ import * as Crypto from "effect/Crypto";
42 import * as Effect from "effect/Effect";
43 import * as Hex from "effect/encoding/Hex";
44 import * as Exit from "effect/Exit";
45 +import * as FileSystem from "effect/FileSystem";
46 import * as Option from "effect/Option";
47 import * as Queue from "effect/Queue";
48 import * as Schedule from "effect/Schedule";
@@ -59,7 +63,10 @@ import * as KeyedLock from "@t3tools/shared/KeyedLock";
63 import { getModelSelectionStringOptionValue, modelSelectionsEqual } from "@t3tools/shared/model";
64 import { causeErrorTag } from "@t3tools/shared/observability";
65
62 -import { providerMessageTextWithAttachmentPaths } from "@t3tools/provider-core/server/attachmentPrompt";
66 +import {
67 + isProviderNativeImageAttachment,
68 + providerMessageTextWithAttachmentPaths,
69 +} from "@t3tools/provider-core/server/attachmentPrompt";
70 import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
71 import {
72 backgroundWorkNotification,
@@ -665,6 +672,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
672 const idAllocator = yield* IdAllocator.IdAllocatorV2;
673 const host = yield* ProviderHost.ProviderHost;
674 const mcpSessions = yield* McpProviderSessions.McpProviderSessions;
675 + const fileSystem = yield* FileSystem.FileSystem;
676 const continuationRequests = yield* ProviderContinuationRequests.ProviderContinuationRequests;
677 const crypto = yield* Crypto.Crypto;
678 const driver = OPENCODE_PROVIDER;
@@ -2920,6 +2928,21 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
2928 resolveAttachmentPath: host.resolveAttachmentPath,
2929 }).trim();
2930
2931 + const promptFiles = Effect.fnUntraced(function* (attachments: ReadonlyArray<ChatAttachment>) {
2932 + const files: Array<{ uri: string; name: string }> = [];
2933 + // An external server may not share T3's attachment directory.
2934 + if (connection.external) return files;
2935 + for (const attachment of attachments) {
2936 + if (!isProviderNativeImageAttachment(attachment)) continue;
2937 + const path = host.resolveAttachmentPath(attachment);
2938 + if (path === null) continue;
2939 + // OpenCode rejects the whole prompt if an attached file is missing.
2940 + const exists = yield* fileSystem.exists(path).pipe(Effect.orElseSucceed(() => false));
2941 + if (exists) files.push({ uri: NodeURL.pathToFileURL(path).href, name: attachment.name });
2942 + }
2943 + return files;
2944 + });
2945 +
2946 const removeMcp = (mcp: { readonly name: string; readonly directory: string }) =>
2947 Effect.suspend(() =>
2948 client.mcp.remove({ server: mcp.name, location: { directory: mcp.directory } }),
@@ -3260,12 +3283,14 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
3283 ),
3284 )
3285 : [];
3286 + const files = yield* promptFiles(turnInput.message.attachments);
3287 if (!sending()) return;
3288 return yield* client.session
3289 .prompt({
3290 sessionID,
3291 id,
3292 text: promptText(turnInput),
3293 + ...(files.length === 0 ? {} : { files }),
3294 ...(skills.length === 0
3295 ? {}
3296 : { skills: skills.map((id) => ({ id: Skill.ID.make(id) })) }),
@@ -3587,6 +3612,26 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
3612 if (turn.settledInbox.has(inboxID)) return;
3613 turn.steers.add(inboxID);
3614 state.strandedSteers.delete(inboxID);
3615 + const files = yield* promptFiles(steerInput.message.attachments);
3616 + if (state.active !== turn || turn.interrupted) {
3617 + yield* lock.withPermit(
3618 + Effect.gen(function* () {
3619 + turn.steers.delete(inboxID);
3620 + // Stop may have stranded this steer, but it never reached OpenCode.
3621 + state.strandedSteers.delete(inboxID);
3622 + if (state.active === turn) {
3623 + if (turn.interrupted && turn.heldEnd !== undefined) {
3624 + turn.heldEnd = { status: "interrupted" };
3625 + }
3626 + yield* endIfSettled(state, turn);
3627 + }
3628 + }),
3629 + );
3630 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
3631 + driver: OPENCODE_PROVIDER,
3632 + detail: `OpenCode turn ${steerInput.providerTurnId} is not active`,
3633 + });
3634 + }
3635 yield* client.session
3636 .prompt({
3637 sessionID: Session.ID.make(sessionId),
@@ -3596,6 +3641,7 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
3641 attachments: steerInput.message.attachments,
3642 resolveAttachmentPath: host.resolveAttachmentPath,
3643 }).trim(),
3644 + ...(files.length === 0 ? {} : { files }),
3645 delivery: "steer",
3646 })
3647 .pipe(