82
id: `evt_${type.replaceAll(".", "")}0000`,
83
created: 1,
84
type,
85
+ ...(type.startsWith("rpc.") ? { location: { directory: WORK } } : {}),
86
data,
87
durable: { ...durable.durable, version },
88
},
164
"session.compact",
165
"command.list",
166
"skill.list",
167
+ "rpc.call",
168
].includes(String(entry.frame.type)),
169
);
170
const after = entries.findIndex(
317
const resumed = (
318
entries: ReadonlyArray<ProviderReplayEntry>,
319
options?: {
320
+ readonly version?: "2.2.5";
321
+ readonly goal?: OrchestrationV2ProviderThread["goal"];
322
readonly external?: boolean;
323
readonly supervised?: boolean;
324
readonly replayGate?: ProviderReplayGate;
330
) =>
331
Effect.gen(function* () {
332
const runtime = yield* openCode2ReplayRuntime(
329
- withInstructions([
333
+ [
334
...opening,
335
out("session.get", { sessionID: SESSION }),
336
replyData("session.get", sessionInfo()),
337
...noOpenRequests,
334
- ...(options?.supervised === true
335
- ? [
336
- out("agent.list", "<any>"),
337
- reply("agent.list", agentList),
338
- out("session.update", { sessionID: SESSION, permissions: supervisedRules }),
339
- reply("session.update", null),
340
- ]
338
+ ...(options?.version === "2.2.5"
339
+ ? [out("rpc.call", "<any>"), reply("rpc.call", { output: null })]
340
: []),
342
- ...entries,
343
- ]),
341
+ ...withInstructions([
342
+ ...(options?.supervised === true
343
+ ? [
344
+ out("agent.list", "<any>"),
345
+ reply("agent.list", agentList),
346
+ out("session.update", { sessionID: SESSION, permissions: supervisedRules }),
347
+ reply("session.update", null),
348
+ ]
349
+ : []),
350
+ ...entries,
351
+ ]),
352
+ ],
353
{
354
+ ...(options?.version === undefined ? {} : { version: options.version }),
355
...(options?.fileSystem === undefined ? {} : { fileSystem: options.fileSystem }),
356
...(options?.onPrompt === undefined ? {} : { onPrompt: options.onPrompt }),
357
...(options?.external === undefined ? {} : { external: options.external }),
365
},
366
);
367
const thread = yield* runtime.resumeThread({
358
- providerThread: providerThread(yield* DateTime.now),
368
+ providerThread: {
369
+ ...providerThread(yield* DateTime.now),
370
+ ...(options?.goal === undefined ? {} : { goal: options.goal }),
371
+ },
372
threadId,
373
modelSelection: bigPickle,
374
runtimePolicy: policy(options?.supervised === true ? "approval-required" : "full-access"),
435
cursor: {},
436
};
437
438
+const nativeGoal = (status: "active" | "paused" | "complete") => ({
439
+ id: "goal-1",
440
+ objective: "Write proof.txt",
441
+ status,
442
+ rounds: 2,
443
+ maxRounds: 100,
444
+ boot: "boot-1",
445
+ updatedAt: 1,
446
+ reason: "Checked proof.txt",
447
+});
448
+
449
it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
450
it.effect("switches the session's model and variant before a turn that changed them", () =>
451
Effect.gen(function* () {
2321
active: Record<string, unknown>,
2322
ended?: "succeeded",
2323
assistant: Record<string, unknown> = {},
2324
+ deliveredSteer?: string,
2325
) => [
2326
{ type: "runtime_exit", status: "success" } as const,
2327
out("event.subscribe"),
2358
finish: "stop",
2359
...assistant,
2360
},
2361
+ ...(deliveredSteer === undefined
2362
+ ? []
2363
+ : [{ id: deliveredSteer, time: { created: 2 }, text: "steered", type: "user" }]),
2364
{
2365
id: "msg_0eb735d41001NJee1EvVePJAK5",
2366
time: { created: 1 },
2386
event.type === "turn_item.updated" ? [`${event.turnItem.type}:${event.turnItem.status}`] : [],
2387
);
2388
2389
+ it.effect.each(["delivered", "pending"] as const)(
2390
+ "reconciles a %s steer after reconnect without losing its execution",
2391
+ (delivery) =>
2392
+ Effect.gen(function* () {
2393
+ const steerId = `msg_t3_steer_${SESSION}:message:opencode2-adapter:steer`;
2394
+ const reconnect = reconnected(
2395
+ {},
2396
+ "succeeded",
2397
+ {},
2398
+ delivery === "delivered" ? steerId : undefined,
2399
+ );
2400
+ const { runtime, thread } = yield* resumed(
2401
+ [
2402
+ out("session.prompt", { sessionID: SESSION, id: PROMPT_ID, text: "<any>" }),
2403
+ promptAccepted,
2404
+ ...(delivery === "pending"
2405
+ ? [
2406
+ event("rpc.opencode.goal.changed", {
2407
+ sessionID: SESSION,
2408
+ goal: nativeGoal("active"),
2409
+ }),
2410
+ ]
2411
+ : []),
2412
+ out("session.prompt", "<any>"),
2413
+ replyData("session.prompt", {
2414
+ id: steerId,
2415
+ sessionID: SESSION,
2416
+ time: { created: 2 },
2417
+ type: "user",
2418
+ payload: { text: "steered" },
2419
+ delivery: "steer",
2420
+ }),
2421
+ ...reconnect.slice(0, 2),
2422
+ ...(delivery === "pending"
2423
+ ? [out("rpc.call", "<any>"), reply("rpc.call", { output: { unreadable: true } })]
2424
+ : []),
2425
+ ...reconnect.slice(2),
2426
+ ...(delivery === "pending"
2427
+ ? [
2428
+ event("session.execution.started", { sessionID: SESSION }),
2429
+ event("session.inbox.delivered", { sessionID: SESSION, inboxID: steerId }),
2430
+ event("session.text.ended", {
2431
+ sessionID: SESSION,
2432
+ assistantMessageID: "msg_delayed_steer",
2433
+ ordinal: 0,
2434
+ text: "Steer processed",
2435
+ }),
2436
+ event("session.execution.succeeded", { sessionID: SESSION }),
2437
+ ]
2438
+ : [event("session.execution.interrupted", { sessionID: SESSION, reason: "user" })]),
2439
+ ],
2440
+ delivery === "pending" ? { version: "2.2.5" } : undefined,
2441
+ );
2442
+ const events = yield* runtime.events.pipe(
2443
+ Stream.takeUntil((e) => e.type === "turn.terminal"),
2444
+ Stream.runCollect,
2445
+ Effect.forkScoped,
2446
+ );
2447
+ yield* runtime.startTurn(turnInput(thread));
2448
+ yield* runtime.steerTurn({
2449
+ providerThread: thread,
2450
+ providerTurnId: yield* providerTurnId,
2451
+ threadId,
2452
+ runId: turnInput(thread).runId,
2453
+ message: {
2454
+ ...turnInput(thread).message,
2455
+ messageId: MessageId.make("message:opencode2-adapter:steer"),
2456
+ text: "steered",
2457
+ },
2458
+ });
2459
+ const collected = yield* Fiber.join(events);
2460
+ assert.deepInclude(collected.at(-1), { type: "turn.terminal", status: "completed" });
2461
+ if (delivery === "pending")
2462
+ assert.isTrue(
2463
+ collected.some(
2464
+ (e) =>
2465
+ e.type === "turn_item.updated" &&
2466
+ e.turnItem.type === "assistant_message" &&
2467
+ e.turnItem.text === "Steer processed",
2468
+ ),
2469
+ );
2470
+ }).pipe(Effect.scoped),
2471
+ );
2472
+
2473
it.effect("does not end a turn from an earlier turn's history when its prompt is not there", () =>
2474
Effect.gen(function* () {
2475
const { runtime, thread } = yield* resumed([
5251
assert.lengthOf(offers, 1);
5252
}).pipe(Effect.scoped, Effect.provide(IdAllocator.layer)),
5253
);
5254
+ it.effect.each(["", "pause", "clear", "resume", "Write proof.txt"])(
5255
+ "preserves older OpenCode goal command execution for /goal %s",
5256
+ (control) =>
5257
+ Effect.gen(function* () {
5258
+ const { runtime, thread } = yield* resumed(
5259
+ [
5260
+ out("command.list", "<any>"),
5261
+ reply("command.list", { location: { directory: WORK }, data: [{ name: "goal" }] }),
5262
+ out("message.list", { sessionID: SESSION, order: "desc", limit: "1" }),
5263
+ reply("message.list", { data: [], cursor: {} }),
5264
+ out("session.command", { sessionID: SESSION, name: "goal", text: control }),
5265
+ reply("session.command", null),
5266
+ event("session.text.ended", {
5267
+ sessionID: SESSION,
5268
+ assistantMessageID: "msg_legacy_goal",
5269
+ ordinal: 0,
5270
+ text: "Legacy command finished",
5271
+ }),
5272
+ event("session.execution.succeeded", { sessionID: SESSION }),
5273
+ ],
5274
+ { goal: { objective: "Saved before downgrade", status: "active" } },
5275
+ );
5276
+ assert.isFalse(runtime.providerSession.capabilities.turns.supportsNativeGoals);
5277
+ const events = yield* runtime.events.pipe(
5278
+ Stream.takeUntil((e) => e.type === "turn.terminal"),
5279
+ Stream.runCollect,
5280
+ Effect.forkScoped,
5281
+ );
5282
+ const input = turnInput(thread);
5283
+ yield* runtime.startTurn({
5284
+ ...input,
5285
+ message: { ...input.message, text: `/goal ${control}`.trim() },
5286
+ });
5287
+ const collected = yield* Fiber.join(events);
5288
+ assert.isTrue(
5289
+ collected.some(
5290
+ (e) =>
5291
+ e.type === "turn_item.updated" &&
5292
+ e.turnItem.type === "assistant_message" &&
5293
+ e.turnItem.text === "Legacy command finished",
5294
+ ),
5295
+ );
5296
+ assert.deepInclude(collected.at(-1), { type: "turn.terminal", status: "completed" });
5297
+ }).pipe(Effect.scoped),
5298
+ );
5299
+
5300
+ it.effect("reads an existing OpenCode 2.2.5 goal when resuming a session", () =>
5301
+ Effect.gen(function* () {
5302
+ const runtime = yield* openCode2ReplayRuntime(
5303
+ [
5304
+ ...opening,
5305
+ out("session.get", { sessionID: SESSION }),
5306
+ replyData("session.get", sessionInfo()),
5307
+ ...noOpenRequests,
5308
+ out("rpc.call", {
5309
+ rpcID: "opencode.goal",
5310
+ method: "get",
5311
+ "location[directory]": WORK,
5312
+ input: { sessionID: SESSION },
5313
+ }),
5314
+ reply("rpc.call", { output: nativeGoal("paused") }),
5315
+ ],
5316
+ { version: "2.2.5" },
5317
+ );
5318
+ assert.isTrue(runtime.providerSession.capabilities.turns.supportsNativeGoals);
5319
+ const thread = yield* runtime.resumeThread({
5320
+ providerThread: providerThread(yield* DateTime.now),
5321
+ threadId,
5322
+ modelSelection: bigPickle,
5323
+ runtimePolicy: policy(),
5324
+ });
5325
+ assert.deepEqual(thread.goal, {
5326
+ objective: "Write proof.txt",
5327
+ status: "paused",
5328
+ checks: 2,
5329
+ lastCheck: "Checked proof.txt",
5330
+ });
5331
+ }).pipe(Effect.scoped),
5332
+ );
5333
+
5334
+ it.effect.each([
5335
+ { status: "complete", reconnect: false },
5336
+ { status: "paused", reconnect: false },
5337
+ { status: "complete", reconnect: true },
5338
+ ] as const)(
5339
+ "keeps an OpenCode goal turn open until $status, with reconnect $reconnect",
5340
+ ({ status, reconnect }) =>
5341
+ Effect.gen(function* () {
5342
+ const recovered = reconnected({ [SESSION]: { type: "running" } });
5343
+ const { runtime, thread } = yield* resumed(
5344
+ [
5345
+ out("command.list", "<any>"),
5346
+ reply("command.list", { location: { directory: WORK }, data: [{ name: "goal" }] }),
5347
+ out("message.list", { sessionID: SESSION, order: "desc", limit: "1" }),
5348
+ reply("message.list", { data: [], cursor: {} }),
5349
+ out("session.command", { sessionID: SESSION, name: "goal", text: "Write proof.txt" }),
5350
+ reply("session.command", null),
5351
+ event("rpc.opencode.goal.changed", { sessionID: SESSION, goal: nativeGoal("active") }),
5352
+ event("session.execution.succeeded", { sessionID: SESSION }),
5353
+ ...(status === "complete"
5354
+ ? reconnect
5355
+ ? [
5356
+ ...recovered.slice(0, 2),
5357
+ out("rpc.call", "<any>"),
5358
+ reply("rpc.call", { output: nativeGoal("active") }),
5359
+ ...recovered.slice(2),
5360
+ ...noOpenRequests,
5361
+ ]
5362
+ : [event("session.execution.started", { sessionID: SESSION })]
5363
+ : []),
5364
+ event("rpc.opencode.goal.changed", { sessionID: SESSION, goal: nativeGoal(status) }),
5365
+ ...(status === "complete"
5366
+ ? [
5367
+ event("session.text.ended", {
5368
+ sessionID: SESSION,
5369
+ assistantMessageID: "msg_goal_final",
5370
+ ordinal: 0,
5371
+ text: "Final goal output",
5372
+ }),
5373
+ event("session.execution.succeeded", { sessionID: SESSION }),
5374
+ ]
5375
+ : []),
5376
+ ],
5377
+ { version: "2.2.5" },
5378
+ );
5379
+ const events = yield* runtime.events.pipe(
5380
+ Stream.takeUntil((e) => e.type === "turn.terminal"),
5381
+ Stream.runCollect,
5382
+ Effect.forkScoped,
5383
+ );
5384
+ const input = turnInput(thread);
5385
+ yield* runtime.startTurn({
5386
+ ...input,
5387
+ message: { ...input.message, text: "/goal Write proof.txt" },
5388
+ });
5389
+ const collected = yield* Fiber.join(events);
5390
+ const goals = collected.flatMap((e) =>
5391
+ e.type === "provider_thread.updated" && e.providerThread.goal
5392
+ ? [e.providerThread.goal]
5393
+ : [],
5394
+ );
5395
+ assert.includeDeepMembers(goals, [
5396
+ {
5397
+ objective: "Write proof.txt",
5398
+ status: "active",
5399
+ checks: 2,
5400
+ lastCheck: "Checked proof.txt",
5401
+ },
5402
+ {
5403
+ objective: "Write proof.txt",
5404
+ status,
5405
+ checks: 2,
5406
+ lastCheck: "Checked proof.txt",
5407
+ },
5408
+ ]);
5409
+ if (status === "complete")
5410
+ assert.isTrue(
5411
+ collected.some(
5412
+ (e) =>
5413
+ e.type === "turn_item.updated" &&
5414
+ e.turnItem.type === "assistant_message" &&
5415
+ e.turnItem.text === "Final goal output",
5416
+ ),
5417
+ );
5418
+ assert.deepInclude(collected.at(-1), { type: "turn.terminal", status: "completed" });
5419
+ }).pipe(Effect.scoped),
5420
+ );
5421
+
5422
+ it.effect("does not replace a newer goal event with an older goal RPC response", () =>
5423
+ Effect.gen(function* () {
5424
+ const gate = makeProviderReplayGate(["release-goal-read"]);
5425
+ const { runtime, thread } = yield* resumed(
5426
+ [
5427
+ out("rpc.call", "<any>"),
5428
+ event("rpc.opencode.goal.changed", { sessionID: SESSION, goal: nativeGoal("paused") }),
5429
+ event(
5430
+ "rpc.opencode.goal.changed",
5431
+ { sessionID: SESSION, goal: nativeGoal("paused") },
5432
+ "release-goal-read",
5433
+ ),
5434
+ reply("rpc.call", { output: nativeGoal("active") }),
5435
+ ],
5436
+ { version: "2.2.5", replayGate: gate },
5437
+ );
5438
+ const changed = yield* Deferred.make<void>();
5439
+ const events = yield* runtime.events.pipe(
5440
+ Stream.tap((e) =>
5441
+ e.type === "provider_thread.updated" && e.providerThread.goal?.status === "paused"
5442
+ ? Deferred.succeed(changed, undefined)
5443
+ : Effect.void,
5444
+ ),
5445
+ Stream.takeUntil((e) => e.type === "turn.terminal"),
5446
+ Stream.runCollect,
5447
+ Effect.forkScoped,
5448
+ );
5449
+ const input = turnInput(thread);
5450
+ const starting = yield* runtime
5451
+ .startTurn({ ...input, message: { ...input.message, text: "/goal" } })
5452
+ .pipe(Effect.forkScoped);
5453
+ yield* Deferred.await(changed);
5454
+ gate.release("release-goal-read");
5455
+ yield* Fiber.join(starting);
5456
+ const collected = yield* Fiber.join(events);
5457
+ const updated = collected.findLast((e) => e.type === "provider_thread.updated");
5458
+ assert.equal(
5459
+ updated?.type === "provider_thread.updated"
5460
+ ? updated.providerThread.goal?.status
5461
+ : undefined,
5462
+ "paused",
5463
+ );
5464
+ }).pipe(Effect.scoped),
5465
+ );
5466
+
5467
+ it.effect.each(["unreadable", "stalled"] as const)(
5468
+ "settles a completed execution after reconnect when goal refresh is %s",
5469
+ (failure) =>
5470
+ Effect.gen(function* () {
5471
+ const gate = makeProviderReplayGate(["goal-refresh-stalled"]);
5472
+ const reconnect = reconnected({}, "succeeded");
5473
+ const { runtime, thread } = yield* resumed(
5474
+ [
5475
+ out("session.prompt", { sessionID: SESSION, id: PROMPT_ID, text: "<any>" }),
5476
+ promptAccepted,
5477
+ event("rpc.opencode.goal.changed", { sessionID: SESSION, goal: nativeGoal("active") }),
5478
+ ...reconnect.slice(0, 2),
5479
+ out("rpc.call", "<any>"),
5480
+ reply("rpc.call", failure === "stalled" ? "<hang>" : { output: { unreadable: true } }),
5481
+ ...(failure === "stalled"
5482
+ ? [
5483
+ event(
5484
+ "rpc.opencode.goal.changed",
5485
+ { sessionID: SESSION, goal: null },
5486
+ "goal-refresh-stalled",
5487
+ ),
5488
+ ]
5489
+ : []),
5490
+ ...reconnect.slice(2),
5491
+ ],
5492
+ { version: "2.2.5", replayGate: gate },
5493
+ );
5494
+ const events = yield* runtime.events.pipe(
5495
+ Stream.takeUntil((e) => e.type === "turn.terminal"),
5496
+ Stream.runCollect,
5497
+ Effect.forkScoped,
5498
+ );
5499
+ yield* runtime.startTurn(turnInput(thread));
5500
+ if (failure === "stalled") {
5501
+ yield* Effect.promise(() => gate.waitForReached("goal-refresh-stalled"));
5502
+ gate.release("goal-refresh-stalled");
5503
+ yield* TestClock.adjust("5 seconds");
5504
+ }
5505
+ const collected = yield* Fiber.join(events);
5506
+ assert.deepInclude(collected.at(-1), { type: "turn.terminal", status: "completed" });
5507
+ }).pipe(Effect.scoped),
5508
+ );
5509
+
5510
+ it.effect.each([
5511
+ { initial: "active", recovered: "paused" },
5512
+ { initial: "paused", recovered: "active" },
5513
+ { initial: "active", recovered: "unreadable" },
5514
+ ] as const)(
5515
+ "recovers unreadable native goal updates when cached goal is $initial and RPC returns $recovered",
5516
+ ({ initial, recovered }) =>
5517
+ Effect.gen(function* () {
5518
+ const { runtime, thread } = yield* resumed(
5519
+ [
5520
+ out("session.prompt", { sessionID: SESSION, id: PROMPT_ID, text: "<any>" }),
5521
+ promptAccepted,
5522
+ event("rpc.opencode.goal.changed", { sessionID: SESSION, goal: nativeGoal(initial) }),
5523
+ event("rpc.opencode.goal.changed", {
5524
+ sessionID: SESSION,
5525
+ goal: { ...nativeGoal(initial), status: "unknown" },
5526
+ }),
5527
+ event("session.execution.succeeded", { sessionID: SESSION }),
5528
+ out("rpc.call", "<any>"),
5529
+ reply("rpc.call", { output: recovered === "unreadable" ? {} : nativeGoal(recovered) }),
5530
+ ...(recovered === "active"
5531
+ ? [
5532
+ event("session.execution.started", { sessionID: SESSION }),
5533
+ event("session.text.ended", {
5534
+ sessionID: SESSION,
5535
+ assistantMessageID: "msg_recovered_goal",
5536
+ ordinal: 0,
5537
+ text: "Continued work",
5538
+ }),
5539
+ event("rpc.opencode.goal.changed", {
5540
+ sessionID: SESSION,
5541
+ goal: nativeGoal("complete"),
5542
+ }),
5543
+ event("session.execution.succeeded", { sessionID: SESSION }),
5544
+ ]
5545
+ : []),
5546
+ ],
5547
+ { version: "2.2.5" },
5548
+ );
5549
+ const events = yield* runtime.events.pipe(
5550
+ Stream.takeUntil((e) => e.type === "turn.terminal"),
5551
+ Stream.runCollect,
5552
+ Effect.forkScoped,
5553
+ );
5554
+ yield* runtime.startTurn(turnInput(thread));
5555
+ const collected = yield* Fiber.join(events);
5556
+ const updated = collected.findLast((e) => e.type === "provider_thread.updated");
5557
+ assert.equal(
5558
+ updated?.type === "provider_thread.updated"
5559
+ ? updated.providerThread.goal?.status
5560
+ : undefined,
5561
+ recovered === "active" ? "complete" : recovered === "paused" ? "paused" : "active",
5562
+ );
5563
+ if (recovered === "active")
5564
+ assert.isTrue(
5565
+ collected.some(
5566
+ (e) =>
5567
+ e.type === "turn_item.updated" &&
5568
+ e.turnItem.type === "assistant_message" &&
5569
+ e.turnItem.text === "Continued work",
5570
+ ),
5571
+ );
5572
+ assert.deepInclude(collected.at(-1), { type: "turn.terminal", status: "completed" });
5573
+ }).pipe(Effect.scoped),
5574
+ );
5575
+
5576
+ it.effect.each(["show", "pause", "clear"] as const)(
5577
+ "a delayed /goal %s response cannot finish its replacement turn",
5578
+ (control) =>
5579
+ Effect.gen(function* () {
5580
+ const operation = control === "show" ? "rpc.call" : "session.command";
5581
+ const { runtime, thread } = yield* resumed(
5582
+ [
5583
+ ...(control === "show"
5584
+ ? []
5585
+ : [
5586
+ out("command.list", "<any>"),
5587
+ reply("command.list", {
5588
+ location: { directory: WORK },
5589
+ data: [{ name: "goal" }],
5590
+ }),
5591
+ out("message.list", { sessionID: SESSION, order: "desc", limit: "1" }),
5592
+ reply("message.list", { data: [], cursor: {} }),
5593
+ ]),
5594
+ out(operation, "<any>"),
5595
+ event("session.execution.interrupted", { sessionID: SESSION, reason: "user" }),
5596
+ out("session.prompt", "<any>"),
5597
+ promptAccepted,
5598
+ reply(operation, control === "show" ? { output: nativeGoal("paused") } : null),
5599
+ event("session.text.ended", {
5600
+ sessionID: SESSION,
5601
+ assistantMessageID: "msg_replacement",
5602
+ ordinal: 0,
5603
+ text: "Replacement still tracked",
5604
+ }),
5605
+ event("session.execution.succeeded", { sessionID: SESSION }),
5606
+ ],
5607
+ { version: "2.2.5" },
5608
+ );
5609
+ const interrupted = yield* Deferred.make<void>();
5610
+ const events = yield* runtime.events.pipe(
5611
+ Stream.tap((e) =>
5612
+ e.type === "turn.terminal" && e.status === "interrupted"
5613
+ ? Deferred.succeed(interrupted, undefined)
5614
+ : Effect.void,
5615
+ ),
5616
+ Stream.takeUntil((e) => e.type === "turn.terminal" && e.status === "completed"),
5617
+ Stream.runCollect,
5618
+ Effect.forkScoped,
5619
+ );
5620
+ const input = turnInput(thread);
5621
+ const starting = yield* runtime
5622
+ .startTurn({
5623
+ ...input,
5624
+ message: { ...input.message, text: control === "show" ? "/goal" : `/goal ${control}` },
5625
+ })
5626
+ .pipe(Effect.forkScoped);
5627
+ yield* Deferred.await(interrupted);
5628
+ yield* runtime.startTurn({
5629
+ ...input,
5630
+ attemptId: RunAttemptId.make("replacement"),
5631
+ providerTurnOrdinal: 2,
5632
+ });
5633
+ yield* Fiber.join(starting);
5634
+ const collected = yield* Fiber.join(events);
5635
+ assert.isTrue(
5636
+ collected.some(
5637
+ (e) =>
5638
+ e.type === "turn_item.updated" &&
5639
+ e.turnItem.type === "assistant_message" &&
5640
+ e.turnItem.text === "Replacement still tracked",
5641
+ ),
5642
+ );
5643
+ }).pipe(Effect.scoped),
5644
+ );
5645
+
5646
+ it.effect.each(["show", "pause", "clear"] as const)(
5647
+ "settles OpenCode /goal %s without waiting for an execution",
5648
+ (control) =>
5649
+ Effect.gen(function* () {
5650
+ const goal = control === "clear" ? null : nativeGoal("paused");
5651
+ const { runtime, thread } = yield* resumed(
5652
+ control === "show"
5653
+ ? [out("rpc.call", "<any>"), reply("rpc.call", { output: goal })]
5654
+ : [
5655
+ out("command.list", "<any>"),
5656
+ reply("command.list", { location: { directory: WORK }, data: [{ name: "goal" }] }),
5657
+ out("message.list", { sessionID: SESSION, order: "desc", limit: "1" }),
5658
+ reply("message.list", { data: [], cursor: {} }),
5659
+ out("session.command", { sessionID: SESSION, name: "goal", text: control }),
5660
+ event("rpc.opencode.goal.changed", { sessionID: SESSION, goal }),
5661
+ reply("session.command", null),
5662
+ ],
5663
+ { version: "2.2.5" },
5664
+ );
5665
+ const events = yield* runtime.events.pipe(
5666
+ Stream.takeUntil((e) => e.type === "turn.terminal"),
5667
+ Stream.runCollect,
5668
+ Effect.forkScoped,
5669
+ );
5670
+ const input = turnInput(thread);
5671
+ yield* runtime.startTurn({
5672
+ ...input,
5673
+ message: { ...input.message, text: control === "show" ? "/goal" : `/goal ${control}` },
5674
+ });
5675
+ const collected = yield* Fiber.join(events);
5676
+ const updated = collected.findLast((e) => e.type === "provider_thread.updated");
5677
+ assert.equal(
5678
+ updated?.type === "provider_thread.updated"
5679
+ ? (updated.providerThread.goal?.status ?? null)
5680
+ : undefined,
5681
+ goal?.status ?? null,
5682
+ );
5683
+ assert.deepInclude(collected.at(-1), { type: "turn.terminal", status: "completed" });
5684
+ }).pipe(Effect.scoped),
5685
+ );
5686
});
5687
5688
const providerTurnId = Effect.gen(function* () {