@devries-cameron20 / t3code Mirror · read-only / commits / 2248ca8db9
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 21, 21:00 UTC

fix(cursor): steer the live run without reconnecting (#28980)

Co-authored-by: Yash Singh <saiansh2525@gmail.com>

Jaimin committed Nov 11, 2026 at 23:04 UTC 2248ca8db91f85aca3bc494086947327d472aa9e
21 files changed +831 -84
apps/server/scripts/record-cursor-agent-sdk-replay-fixture.ts
+3 -3
@@ -55,7 +55,7 @@ const RECORDINGS = {
55 message_steering: {
56 prompts: [MESSAGE_STEERING_INITIAL_PROMPT, MESSAGE_STEERING_STEER_PROMPT],
57 output: "../src/orchestration-v2/testkit/fixtures/message_steering/cursor_transcript.ndjson",
58 - interruptAfterRunStartPromptIndex: 0,
58 + steerAfterRunStartPromptIndex: 0,
59 },
60 provider_thread_resume: {
61 prompts: [PROVIDER_THREAD_RESUME_FIRST_PROMPT, PROVIDER_THREAD_RESUME_SECOND_PROMPT],
@@ -183,8 +183,8 @@ const recordScenario = Effect.fn("recordScenario")(function* (
183 ...("interruptAfterToolStart" in recording
184 ? { interruptAfterToolStart: recording.interruptAfterToolStart }
185 : {}),
186 - ...("interruptAfterRunStartPromptIndex" in recording
187 - ? { interruptAfterRunStartPromptIndex: recording.interruptAfterRunStartPromptIndex }
186 + ...("steerAfterRunStartPromptIndex" in recording
187 + ? { steerAfterRunStartPromptIndex: recording.steerAfterRunStartPromptIndex }
188 : {}),
189 ...("restartBeforePromptIndex" in recording
190 ? { restartBeforePromptIndex: recording.restartBeforePromptIndex }
apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts
+53 -7
@@ -1,5 +1,5 @@
1 import * as HostProcess from "@t3tools/shared/HostProcess";
2 -import type { InteractionUpdate, RunResult } from "@cursor/sdk";
2 +import type { InteractionUpdate, RunResult, SteerAckOutcome } from "@cursor/sdk";
3 import * as NodeServices from "@effect/platform-node/NodeServices";
4 import {
5 ProviderReplayEntry,
@@ -213,6 +213,7 @@ function replayRunnerError(
213 export function makeCursorAgentSdkReplayRunner(
214 transcript: CursorAgentSdkReplayTranscript,
215 ): CursorAgentSdk.CursorAgentSdkRunner["Service"] {
216 + const steerAcks = new Map<string, Deferred.Deferred<SteerAckOutcome>>();
217 let cursor = 0;
218 let failure: CursorAgentSdkReplayError | null = null;
219 let cursorAdvanced = makeSignal();
@@ -306,16 +307,19 @@ export function makeCursorAgentSdkReplayRunner(
307 );
308 }
309 if (entry.type === "expect_outbound") {
309 - const expectedCancel = {
310 - type: "run.cancel",
311 - runId,
312 - };
313 - if (!sameFrame(entry.frame, expectedCancel)) {
310 + const type =
311 + typeof entry.frame === "object" && entry.frame !== null
312 + ? Reflect.get(entry.frame, "type")
313 + : undefined;
314 + if (
315 + (type !== "run.cancel" && type !== "run.steer") ||
316 + Reflect.get(entry.frame as object, "runId") !== runId
317 + ) {
318 return yield* recordFailure(
319 new CursorReplayFrameMismatchError({
320 scenario: transcript.scenario,
321 cursor,
318 - expected: expectedCancel,
322 + expected: { type: "run.cancel | run.steer", runId },
323 actual: entry.frame,
324 }),
325 );
@@ -378,6 +382,23 @@ export function makeCursorAgentSdkReplayRunner(
382 yield* Effect.yieldNow;
383 continue;
384 }
385 + if (frame.type === "run.steered") {
386 + const ack = steerAcks.get(frame.runId);
387 + if (ack === undefined || frame.runId !== runId) {
388 + return yield* recordFailure(
389 + new CursorReplayFrameMismatchError({
390 + scenario: transcript.scenario,
391 + cursor,
392 + expected: { runId },
393 + actual: frame,
394 + }),
395 + );
396 + }
397 + advance();
398 + steerAcks.delete(runId);
399 + yield* Deferred.succeed(ack, frame.outcome);
400 + continue;
401 + }
402 if (frame.type === "run.completed") {
403 if (frame.result.id !== runId) {
404 return yield* recordFailure(
@@ -433,6 +454,16 @@ export function makeCursorAgentSdkReplayRunner(
454 replayRunnerError(transcript, cause, "replay.run.wait"),
455 ),
456 ),
457 + steer: Effect.fn("CursorReplay.steer")(function* (text) {
458 + const ack = yield* Deferred.make<SteerAckOutcome>();
459 + steerAcks.set(started.runId, ack);
460 + yield* Effect.try({
461 + try: () =>
462 + assertOutbound({ type: "run.steer", runId: started.runId, text }),
463 + catch: (cause) => replayRunnerError(transcript, cause, "replay.run.steer"),
464 + });
465 + return yield* Deferred.await(ack);
466 + }),
467 cancel: Effect.try({
468 try: () =>
469 assertOutbound({
@@ -663,6 +694,7 @@ interface CursorReplayRecordingInput {
694 readonly apiKey?: string;
695 readonly interruptAfterToolStart?: boolean;
696 readonly interruptAfterRunStartPromptIndex?: number;
697 + readonly steerAfterRunStartPromptIndex?: number;
698 readonly restartBeforePromptIndex?: number;
699 }
700
@@ -809,6 +841,11 @@ export const recordCursorAgentSdkReplayTranscript = Effect.fn(
841 prompt: string,
842 index: number,
843 ) {
844 + if (
845 + input.steerAfterRunStartPromptIndex !== undefined &&
846 + index === input.steerAfterRunStartPromptIndex + 1
847 + )
848 + return;
849 const interruptAfterRunStart = input.interruptAfterRunStartPromptIndex === index;
850 const firstUpdate = yield* Deferred.make<void>();
851 const toolStarted = yield* Deferred.make<void>();
@@ -831,6 +868,15 @@ export const recordCursorAgentSdkReplayTranscript = Effect.fn(
868 });
869 sent = true;
870 const waiting = yield* run.wait.pipe(Effect.forkChild({ startImmediately: true }));
871 + if (input.steerAfterRunStartPromptIndex === index) {
872 + yield* awaitSignal(firstUpdate, "Cursor SDK activity before steering");
873 + const steerText = input.prompts[index + 1];
874 + if (run.steer === undefined || steerText === undefined)
875 + return yield* invalid("Steering requires a following prompt and Run.steer.");
876 + const outcome = yield* run.steer(steerText);
877 + if (outcome !== "complete_delivered")
878 + return yield* invalid("The running turn did not accept the steer.");
879 + }
880 if (interruptAfterRunStart) {
881 yield* awaitSignal(firstUpdate, "Cursor SDK run activity before interrupt");
882 yield* run.cancel;
apps/server/src/orchestration-v2/CommandPolicy.test.ts
+13
@@ -247,6 +247,19 @@ it.each(["/compact", " /LOGOUT "])("queues a steer sent while %s runs", (text) =
247 const layer = it.layer(CommandPolicy.layer);
248
249 layer("CommandPolicyV2", (it) => {
250 + it.effect("steers a live Cursor turn in place", () =>
251 + Effect.gen(function* () {
252 + const policy = yield* CommandPolicy.CommandPolicyV2;
253 + const result = yield* policy.decideSteeringExecution({
254 + commandId,
255 + threadId,
256 + providerInstanceId: ProviderInstanceId.make("cursor"),
257 + capabilities: CursorProviderCapabilitiesV2,
258 + });
259 + assert.equal(result, "active_steering");
260 + }),
261 + );
262 +
263 it.effect("falls back to portable context when Cursor cannot fork natively", () =>
264 Effect.gen(function* () {
265 const policy = yield* CommandPolicy.CommandPolicyV2;
apps/server/src/orchestration-v2/EffectOutbox.ts
+2
@@ -5,6 +5,7 @@ import {
5 MessageId,
6 ModelSelection,
7 NodeId,
8 + NonNegativeInt,
9 ProviderSessionId,
10 RunAttemptId,
11 ProviderApprovalDecision,
@@ -65,6 +66,7 @@ export const OrchestrationEffectRequestV2 = Schema.Union([
66 providerTurnId: ProviderTurnId,
67 messageId: MessageId,
68 modelSelection: Schema.optional(ModelSelection),
69 + steerFollowUpAfterRunOrdinal: Schema.optional(NonNegativeInt),
70 }),
71 Schema.Struct({
72 type: Schema.Literal("provider-turn.restart"),
apps/server/src/orchestration-v2/EffectWorker.ts
+19 -6
@@ -29,6 +29,8 @@ import * as ThreadManagementService from "./ThreadManagementService.ts";
29 import * as ServerSettings from "../serverSettings.ts";
30 import { continueRestartedRun } from "./RestartContinuation.ts";
31
32 +const isProviderTurnControlError = Schema.is(ProviderTurnControlService.ProviderTurnControlError);
33 +
34 export class OrchestrationEffectExecutionError extends Schema.TaggedError<OrchestrationEffectExecutionError>()(
35 "OrchestrationEffectExecutionError",
36 {
@@ -284,8 +286,8 @@ export const layerExecutor: Layer.Layer<
286 Effect.catch((error) =>
287 Effect.gen(function* () {
288 if (
287 - !("turnCompleted" in error) ||
288 - !error.turnCompleted ||
289 + !isProviderTurnControlError(error) ||
290 + (!error.turnCompleted && !error.steerDeclined) ||
291 effect.request.type !== "provider-turn.steer"
292 ) {
293 return yield* error;
@@ -302,7 +304,8 @@ export const layerExecutor: Layer.Layer<
304 // Notifications must be queued messages.
305 const queued =
306 message.delegatedCompletion !== undefined ||
305 - message.notification !== undefined;
307 + message.notification !== undefined ||
308 + error.steerDeclined === true;
309 // Reuse message ids and receipts so retries cannot duplicate messages or follow-ups.
310 yield* threads
311 .dispatch({
@@ -310,12 +313,22 @@ export const layerExecutor: Layer.Layer<
313 commandId: CommandId.make(`command:steer-follow-up:${effect.id}`),
314 threadId: effect.threadId,
315 messageId: message.id,
316 + ...(error.steerDeclined ? { steerFollowUpOfRunId: run.id } : {}),
317 + ...(error.steerDeclined &&
318 + effect.request.steerFollowUpAfterRunOrdinal !== undefined
319 + ? {
320 + steerFollowUpAfterRunOrdinal:
321 + effect.request.steerFollowUpAfterRunOrdinal,
322 + }
323 + : {}),
324 text: message.text,
325 ...(message.context ? { context: message.context } : {}),
326 attachments: message.attachments,
316 - ...(message.delegatedCompletion === undefined
317 - ? {}
318 - : { modelSelection: run.modelSelection }),
327 + ...(error.steerDeclined && effect.request.modelSelection !== undefined
328 + ? { modelSelection: effect.request.modelSelection }
329 + : message.delegatedCompletion === undefined
330 + ? {}
331 + : { modelSelection: run.modelSelection }),
332 dispatchMode: {
333 type: queued ? "queue_after_active" : "start_immediately",
334 },
apps/server/src/orchestration-v2/Orchestrator.ts
+78 -2
@@ -5740,6 +5740,10 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5740 providerTurnId: providerTurn.id,
5741 messageId: input.messageId,
5742 ...(steerCarriesSelection ? { modelSelection: input.modelSelection } : {}),
5743 + steerFollowUpAfterRunOrdinal: Math.max(
5744 + 0,
5745 + ...input.projection.runs.map((run) => run.ordinal),
5746 + ),
5747 },
5748 } satisfies PendingOrchestrationEffectV2,
5749 ]);
@@ -6173,6 +6177,30 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6177 effects: Ref.Ref<Array<PendingOrchestrationEffectV2>>,
6178 ) {
6179 let projection = yield* getProjectionWithPendingEvents(command.threadId, events);
6180 + if (command.steerFollowUpOfRunId !== undefined) {
6181 + const source = projection.runs.find((run) => run.id === command.steerFollowUpOfRunId);
6182 + if (
6183 + source === undefined ||
6184 + command.dispatchMode.type !== "queue_after_active" ||
6185 + !projection.messages.some(
6186 + (message) => message.id === command.messageId && message.runId === source.id,
6187 + ) ||
6188 + projection.thread.archivedAt !== null ||
6189 + projection.thread.deletedAt !== null ||
6190 + (yield* stopReachedRun(command, command.threadId, source.id))
6191 + ) {
6192 + yield* emit(
6193 + events,
6194 + command,
6195 + )({
6196 + type: "thread.metadata-updated",
6197 + threadId: command.threadId,
6198 + occurredAt: yield* DateTime.now,
6199 + payload: projection.thread,
6200 + });
6201 + return;
6202 + }
6203 + }
6204 if (yield* isStaleQuestionWake(projection, command.messageId, command.notification)) {
6205 yield* emit(
6206 events,
@@ -6806,6 +6834,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6834 // Provider failure or usage limits re-hold the queue.
6835 const worktreeSetupUnresolved = worktreeSetupPending(projection);
6836 const sentByUserFromClient =
6837 + command.steerFollowUpOfRunId === undefined &&
6838 command.createdBy === "user" &&
6839 (command.creationSource === "web" || command.creationSource === "mobile") &&
6840 command.scheduledTaskId === undefined;
@@ -6937,6 +6966,35 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
6966 command.createdBy === "agent" &&
6967 command.creationSource === "provider" &&
6968 !(yield* stopReachedRun(command, command.threadId, activeRun.id));
6969 + let steerFollowUpQueuePosition: number | undefined;
6970 + if (
6971 + command.steerFollowUpOfRunId !== undefined &&
6972 + command.steerFollowUpAfterRunOrdinal !== undefined
6973 + ) {
6974 + const afterRunOrdinal = command.steerFollowUpAfterRunOrdinal;
6975 + const steerOrdinal =
6976 + projection.turnItems.find(
6977 + (item) => item.type === "user_message" && item.messageId === command.messageId,
6978 + )?.ordinal ?? -1;
6979 + // Earlier declined steers have newer runs but retain their original turn-item ordinals.
6980 + const earlierSteerMessageIds = new Set(
6981 + projection.turnItems.flatMap((item) =>
6982 + item.type === "user_message" && item.ordinal < steerOrdinal ? [item.messageId] : [],
6983 + ),
6984 + );
6985 + steerFollowUpQueuePosition =
6986 + Math.max(
6987 + 0,
6988 + ...projection.runs
6989 + .filter(
6990 + (candidate) =>
6991 + candidate.status === "queued" &&
6992 + (candidate.ordinal <= afterRunOrdinal ||
6993 + earlierSteerMessageIds.has(candidate.userMessageId)),
6994 + )
6995 + .map((candidate) => candidate.queuePosition ?? candidate.ordinal),
6996 + ) + 1;
6997 + }
6998 const run: OrchestrationV2Run = {
6999 id: runId,
7000 threadId: command.threadId,
@@ -6959,12 +7017,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7017 queuePosition:
7018 queuedRunStop !== undefined
7019 ? 1
6962 - : Math.max(
7020 + : (steerFollowUpQueuePosition ??
7021 + Math.max(
7022 0,
7023 ...projection.runs
7024 .filter((candidate) => candidate.status === "queued")
7025 .map((candidate) => candidate.queuePosition ?? candidate.ordinal),
6967 - ) + 1,
7026 + ) + 1),
7027 requestedAt: now,
7028 startedAt: null,
7029 completedAt: null,
@@ -7051,6 +7110,23 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
7110 occurredAt: now,
7111 payload: run,
7112 });
7113 + if (steerFollowUpQueuePosition !== undefined) {
7114 + for (const queued of projection.runs) {
7115 + if (
7116 + queued.status !== "queued" ||
7117 + (queued.queuePosition ?? queued.ordinal) < steerFollowUpQueuePosition
7118 + )
7119 + continue;
7120 + yield* emitEvent({
7121 + type: "run.updated",
7122 + threadId: command.threadId,
7123 + runId: queued.id,
7124 + providerInstanceId: queued.providerInstanceId,
7125 + occurredAt: now,
7126 + payload: { ...queued, queuePosition: (queued.queuePosition ?? queued.ordinal) + 1 },
7127 + });
7128 + }
7129 + }
7130 yield* completeSourcePlan(now);
7131 yield* emitEvent({
7132 type: "run-attempt.created",
apps/server/src/orchestration-v2/ProviderTurnControlService.ts
+17 -2
@@ -17,7 +17,7 @@ import * as Layer from "effect/Layer";
17 import * as Option from "effect/Option";
18 import * as Schema from "effect/Schema";
19
20 -import type * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
20 +import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
21 import * as ProjectionStore from "./ProjectionStore.ts";
22 import * as ProviderSessionManager from "./ProviderSessionManager.ts";
23
@@ -39,6 +39,7 @@ export class ProviderTurnControlError extends Schema.TaggedError<ProviderTurnCon
39 operation: Schema.Literals(["interrupt", "restart", "steer"]),
40 providerTurnId: ProviderTurnId,
41 turnCompleted: Schema.optional(Schema.Boolean),
42 + steerDeclined: Schema.optional(Schema.Boolean),
43 /** The provider never confirmed the stop; Force stop is the way out. */
44 unresponsive: Schema.optional(Schema.Boolean),
45 cause: Schema.optional(Schema.Defect()),
@@ -427,17 +428,31 @@ export const layer: Layer.Layer<
428 },
429 })
430 .pipe(
431 + Effect.catchTags({
432 + ProviderAdapterSteerDeclinedError: (cause) =>
433 + Effect.fail(
434 + new ProviderTurnControlError({
435 + threadId: input.threadId,
436 + operation: "steer",
437 + providerTurnId: input.providerTurnId,
438 + steerDeclined: true,
439 + cause,
440 + }),
441 + ),
442 + }),
443 Effect.catch((cause) =>
444 Effect.gen(function* () {
445 + if (isProviderTurnControlError(cause)) return yield* cause;
446 const current = yield* projections.getProviderControlContext(
447 input.threadId,
448 input,
449 );
450 + const status = current.providerTurn?.status;
451 return yield* new ProviderTurnControlError({
452 threadId: input.threadId,
453 operation: "steer",
454 providerTurnId: input.providerTurnId,
440 - turnCompleted: current.providerTurn?.status === "completed",
455 + turnCompleted: status === "completed",
456 cause,
457 });
458 }),
apps/server/src/orchestration-v2/SteeringCompletion.integration.test.ts
+178 -1
@@ -25,6 +25,7 @@ import * as Queue from "effect/Queue";
25 import * as Stream from "effect/Stream";
26 import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
27 import * as EffectWorker from "./EffectWorker.ts";
28 +import * as EffectOutbox from "./EffectOutbox.ts";
29 import * as EventSink from "./EventSink.ts";
30 import * as Orchestrator from "./Orchestrator.ts";
31 import * as ProviderAdapterRegistry from "./ProviderAdapterRegistry.ts";
@@ -493,6 +494,9 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
494 interruptTurn: Effect.Effect<void> = Effect.void,
495 steeringAcceptsAttachments = true,
496 nativeGoals?: boolean,
497 + onSteer: (
498 + turn: ProviderAdapter.ProviderAdapterV2SteerInput,
499 + ) => Effect.Effect<void, ProviderAdapter.ProviderAdapterV2Error> = () => Effect.void,
500 ) {
501 const driver = ProviderDriverKind.make(nativeGoals === undefined ? "codex" : "opencode");
502 const cwd = yield* checkpointWorkspace(name);
@@ -589,7 +593,7 @@ const nextTurnSelectionHarness = Effect.fn("nextTurnSelectionHarness")(function*
593 Effect.sync(() => {
594 steered.push(turn.message.text);
595 steeredSelections.push(turn.modelSelection);
592 - }),
596 + }).pipe(Effect.andThen(onSteer(turn))),
597 interruptTurn: ({ providerTurnId }) =>
598 Effect.sync(() => {
599 interrupted.push(providerTurnId);
@@ -1375,6 +1379,179 @@ it.effect("starts a steer that missed the turn on the saved next-turn selection"
1379 ),
1380 );
1381
1382 +it.effect.each(["complete", "stop-before-decline", "stop-after-decline", "queued-model"] as const)(
1383 + "persists a declined steer without blocking the worker: %s",
1384 + (timing) =>
1385 + Effect.scoped(
1386 + Effect.gen(function* () {
1387 + let beforeDecline: Effect.Effect<void> = Effect.void;
1388 + const { events, started, layer, startFirstTurn } = yield* nextTurnSelectionHarness(
1389 + `steering-declined-${timing}`,
1390 + false,
1391 + true,
1392 + Effect.void,
1393 + true,
1394 + undefined,
1395 + (turn) =>
1396 + Effect.suspend(() => beforeDecline).pipe(
1397 + Effect.andThen(
1398 + Effect.fail(
1399 + new ProviderAdapter.ProviderAdapterSteerDeclinedError({
1400 + driver,
1401 + providerThreadId: turn.providerThread.id,
1402 + providerTurnId: turn.providerTurnId,
1403 + }),
1404 + ),
1405 + ),
1406 + ),
1407 + );
1408 + yield* Effect.gen(function* () {
1409 + const orchestrator = yield* Orchestrator.OrchestratorV2;
1410 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
1411 + const threadId = yield* startFirstTurn;
1412 + const first = started[0]!;
1413 + const stop = orchestrator
1414 + .dispatch({
1415 + type: "run.interrupt",
1416 + commandId: CommandId.make("stop"),
1417 + threadId,
1418 + runId: first.runId,
1419 + holdQueue: true,
1420 + })
1421 + .pipe(Effect.asVoid, Effect.orDie);
1422 + if (timing === "stop-before-decline") beforeDecline = stop;
1423 + const steerSelection = { ...runSelection, model: "steer-model" };
1424 + if (timing === "queued-model") {
1425 + yield* orchestrator.dispatch({
1426 + type: "message.dispatch",
1427 + commandId: CommandId.make("queued-model"),
1428 + threadId,
1429 + messageId: MessageId.make("message:queued-model"),
1430 + text: "already queued",
1431 + attachments: [],
1432 + modelSelection: composerSelection,
1433 + dispatchMode: { type: "queue_after_active" },
1434 + createdBy: "user",
1435 + creationSource: "web",
1436 + });
1437 + beforeDecline = Effect.forEach(["queued-later", "steer-later", "queued-last"], (id) =>
1438 + orchestrator.dispatch({
1439 + type: "message.dispatch",
1440 + commandId: CommandId.make(id),
1441 + threadId,
1442 + messageId: MessageId.make(`message:${id}`),
1443 + text: id,
1444 + attachments: [],
1445 + dispatchMode:
1446 + id === "steer-later"
1447 + ? { type: "steer_active", targetRunId: first.runId }
1448 + : { type: "queue_after_active" },
1449 + createdBy: "user",
1450 + creationSource: "web",
1451 + }),
1452 + ).pipe(Effect.asVoid, Effect.orDie);
1453 + }
1454 + const messageId = MessageId.make("message:declined");
1455 + yield* orchestrator.dispatch({
1456 + type: "message.dispatch",
1457 + commandId: CommandId.make("steer"),
1458 + threadId,
1459 + messageId,
1460 + text: "follow up",
1461 + attachments: [],
1462 + ...(timing === "queued-model" ? { modelSelection: steerSelection } : {}),
1463 + dispatchMode: { type: "steer_active", targetRunId: first.runId },
1464 + createdBy: "user",
1465 + creationSource: "web",
1466 + });
1467 + yield* worker.drain();
1468 + const pending = yield* orchestrator.getThreadProjection(threadId);
1469 + const queued = pending.runs.find(
1470 + (run) => run.userMessageId === messageId && run.id !== first.runId,
1471 + );
1472 + const effects = yield* (yield* EffectOutbox.EffectOutboxV2).listByCommandId(
1473 + CommandId.make("steer"),
1474 + );
1475 + assert.deepEqual(
1476 + effects.map((effect) => [effect.request.type, effect.status]),
1477 + [["provider-turn.steer", "succeeded"]],
1478 + );
1479 + assert.equal(started.length, 1);
1480 + if (timing === "stop-before-decline") {
1481 + assert.isUndefined(queued);
1482 + return;
1483 + }
1484 + assert.equal(queued?.status, "queued");
1485 + assert.equal(queued?.userMessageId, messageId);
1486 + if (timing === "queued-model") {
1487 + assert.deepEqual(queued?.modelSelection, steerSelection);
1488 + assert.deepEqual(
1489 + pending.runs
1490 + .filter((run) => run.status === "queued")
1491 + .toSorted(
1492 + (left, right) =>
1493 + (left.queuePosition ?? left.ordinal) - (right.queuePosition ?? right.ordinal),
1494 + )
1495 + .map((run) => run.userMessageId),
1496 + [
1497 + MessageId.make("message:queued-model"),
1498 + messageId,
1499 + MessageId.make("message:queued-later"),
1500 + MessageId.make("message:steer-later"),
1501 + MessageId.make("message:queued-last"),
1502 + ],
1503 + );
1504 + return;
1505 + }
1506 + if (timing === "stop-after-decline") {
1507 + yield* stop;
1508 + yield* worker.drain();
1509 + yield* orchestrator.resumeQueuedRuns;
1510 + yield* worker.drain();
1511 + const held = yield* orchestrator.getThreadProjection(threadId);
1512 + assert.equal(held.runs.find((run) => run.id === queued?.id)?.queueHeld, true);
1513 + assert.equal(started.length, 1);
1514 + return;
1515 + }
1516 + const settled = yield* orchestrator.streamDomainEvents.pipe(
1517 + Stream.filter(
1518 + (event) =>
1519 + event.type === "run.updated" &&
1520 + event.payload.id === first.runId &&
1521 + event.payload.status === "waiting",
1522 + ),
1523 + Stream.take(1),
1524 + Stream.runDrain,
1525 + Effect.forkScoped,
1526 + );
1527 + const turn = pending.providerTurns[0]!;
1528 + yield* Queue.offer(events, {
1529 + type: "provider_turn.updated",
1530 + driver,
1531 + providerTurn: { ...turn, status: "completed", completedAt: yield* DateTime.now },
1532 + });
1533 + yield* Queue.offer(events, {
1534 + type: "turn.terminal",
1535 + driver,
1536 + providerThreadId: turn.providerThreadId,
1537 + providerTurnId: turn.id,
1538 + runOrdinal: first.runOrdinal,
1539 + status: "completed",
1540 + failure: null,
1541 + threadDisposition: "reusable",
1542 + });
1543 + yield* Fiber.join(settled);
1544 + yield* worker.drain();
1545 + yield* orchestrator.resumeQueuedRuns;
1546 + yield* worker.drain();
1547 + assert.equal(started.length, 2);
1548 + assert.equal(started[1]?.message.messageId, messageId);
1549 + assert.equal(started[1]?.runId, queued?.id);
1550 + }).pipe(Effect.provide(layer));
1551 + }),
1552 + ),
1553 +);
1554 +
1555 // regression: #26695 cancelling a Copilot prompt to steer it kills its background agents
1556 it.effect("queues a steer until the turn ends when the provider cannot steer it", () =>
1557 Effect.scoped(
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+1
@@ -1630,6 +1630,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive", (it) => {
1630 providerTurnId: providerTurn.id,
1631 messageId: steerMessageId,
1632 modelSelection: run.modelSelection,
1633 + steerFollowUpAfterRunOrdinal: run.ordinal,
1634 },
1635 ],
1636 );
apps/server/src/orchestration-v2/testkit/CursorReplayFixtures.integration.test.ts
+7 -1
@@ -21,7 +21,13 @@ describe("Cursor replay fixtures", () => {
21 runReplayFixture({
22 fixtureName: "message_steering",
23 buildInput: messageRestartInput,
24 - driver: cursorSteeringProvider,
24 + driver: {
25 + ...cursorSteeringProvider,
26 + transcriptFile: new URL(
27 + "./fixtures/message_steering/cursor_restart_transcript.ndjson",
28 + import.meta.url,
29 + ),
30 + },
31 harness: CursorOrchestratorReplayHarness,
32 }),
33 );
apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts
+4 -1
@@ -291,6 +291,7 @@ export function layerWithRegistry<Error>(
291 } = {},
292 ): Layer.Layer<
293 | Orchestrator.OrchestratorV2
294 + | EffectOutbox.EffectOutboxV2
295 | EffectWorker.OrchestrationEffectWorkerV2
296 | EventSink.EventSinkV2
297 | ProviderSessionManager.ProviderSessionManagerV2
@@ -327,6 +328,7 @@ export function layerWithRegistry<Error>(
328 ),
329 ),
330 ).pipe(Layer.orDie);
331 + const layerEffectOutboxProvided = EffectOutbox.layer.pipe(Layer.provide(layerDatabase));
332 const wrapProjectionStore = options.wrapProjectionStore;
333 const layerProjectionStore =
334 wrapProjectionStore === undefined
@@ -342,7 +344,7 @@ export function layerWithRegistry<Error>(
344 layerProjectionStore,
345 ProjectStore.layer,
346 CommandReceiptStore.layer,
345 - EffectOutbox.layer,
347 + layerEffectOutboxProvided,
348 TurnItemPositionStore.layer,
349 ).pipe(Layer.provide(layerDatabase));
350 const layerEventSinkProvided = EventSink.layerFromStores.pipe(
@@ -553,6 +555,7 @@ export function layerWithRegistry<Error>(
555 Layer.provide(Layer.merge(layerStores, layerEffectExecutorProvided)),
556 );
557 const layerReplayRuntime = Layer.mergeAll(
558 + layerEffectOutboxProvided,
559 layerOrchestratorProvided,
560 layerProviderSessionManagerProvided,
561 layerEffectWorkerProvided,
apps/server/src/orchestration-v2/testkit/fixtures/message_steering/cursor_output.ts
+16 -7
@@ -34,19 +34,28 @@ export function assertCursorMessageSteeringOutput(
34 assertAssistantTextIncludes(projection, "steering fixture observed");
35
36 assert.lengthOf(projection.runs, 1, "steering must preserve the app run");
37 + const nativeSteer = transcript.entries.some(
38 + (entry) =>
39 + entry.type === "expect_outbound" &&
40 + typeof entry.frame === "object" &&
41 + entry.frame !== null &&
42 + Reflect.get(entry.frame, "type") === "run.steer",
43 + );
44 assert.deepEqual(
45 projection.attempts.map((attempt) => [attempt.reason, attempt.status]),
39 - [
40 - ["initial", "superseded"],
41 - ["steering_restart", "completed"],
42 - ],
46 + nativeSteer
47 + ? [["initial", "completed"]]
48 + : [
49 + ["initial", "superseded"],
50 + ["steering_restart", "completed"],
51 + ],
52 );
53 assert.deepEqual(
54 projection.providerTurns.map((turn) => turn.status),
46 - ["interrupted", "completed"],
55 + nativeSteer ? ["completed"] : ["interrupted", "completed"],
56 );
48 - assert.equal(projection.runs[0]?.activeAttemptId, projection.attempts[1]?.id);
49 - assert.equal(projection.runs[0]?.rootNodeId, projection.attempts[1]?.rootNodeId);
57 + assert.equal(projection.runs[0]?.activeAttemptId, projection.attempts.at(-1)?.id);
58 + assert.equal(projection.runs[0]?.rootNodeId, projection.attempts.at(-1)?.rootNodeId);
59 assert.isFalse(
60 projection.turnItems.some(
61 (item) => item.type === "run_interrupt_request" || item.type === "run_interrupt_result",
apps/server/src/orchestration-v2/testkit/fixtures/message_steering/cursor_restart_transcript.ndjson new
+25
@@ -0,0 +1,25 @@
1 +{"type":"transcript_start","provider":"cursor","protocol":"cursor-agent-sdk.local","version":"1","scenario":"message_steering","metadata":{"generatedBy":"recordCursorAgentSdkReplayTranscript","nativeAgentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
2 +{"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["project","user","team","mdm","plugins"],"sandboxEnabled":false,"enableAgentRetries":true}}}}
3 +{"type":"emit_inbound","label":"agent.opened","frame":{"type":"agent.opened","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
4 +{"type":"expect_outbound","label":"run.start:1","frame":{"type":"run.start","message":"Respond with exactly: steering fixture initial response","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
5 +{"type":"emit_inbound","label":"run.started:1","frame":{"type":"run.started","runId":"run-046488f0-f621-4d59-976c-c4c935ad1282","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
6 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-046488f0-f621-4d59-976c-c4c935ad1282","update":{"type":"thinking-delta","text":"The user requested the"}}}
7 +{"type":"expect_outbound","label":"run.cancel:1","frame":{"type":"run.cancel","runId":"run-046488f0-f621-4d59-976c-c4c935ad1282"}}
8 +{"type":"emit_inbound","label":"run.completed:1","frame":{"type":"run.completed","result":{"id":"run-046488f0-f621-4d59-976c-c4c935ad1282","requestId":"d3b97820-1cf3-448d-a4b1-5fa7edc21460","status":"cancelled","model":{"id":"composer-2.5"},"durationMs":3177}}}
9 +{"type":"expect_outbound","label":"run.start:2","frame":{"type":"run.start","message":"Your previous turn was interrupted and is missing from your history. Some of its work may already be done. Its request was:\n\nRespond with exactly: steering fixture initial response\n\nThe new message, which may continue or change that request:\n\nActually, respond with exactly: steering fixture observed","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
10 +{"type":"emit_inbound","label":"run.started:2","frame":{"type":"run.started","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
11 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-delta","text":"The response will be"}}}
12 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":5}}}
13 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-delta","text":" exactly: \"steering "}}}
14 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":5}}}
15 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-delta","text":"fixture observed\"."}}}
16 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":4}}}
17 +{"type":"emit_inbound","label":"thinking-completed","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-completed","thinkingDurationMs":2}}}
18 +{"type":"emit_inbound","label":"text-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"text-delta","text":"ste"}}}
19 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":1}}}
20 +{"type":"emit_inbound","label":"text-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"text-delta","text":"ering fixture observed"}}}
21 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":5}}}
22 +{"type":"emit_inbound","label":"step-completed","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"step-completed","stepId":2,"stepDurationMs":789}}}
23 +{"type":"emit_inbound","label":"turn-ended","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"turn-ended","usage":{"inputTokens":11626,"outputTokens":38,"cacheReadTokens":11584,"cacheWriteTokens":0}}}}
24 +{"type":"emit_inbound","label":"run.completed:2","frame":{"type":"run.completed","result":{"id":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","requestId":"ed3603d4-2d59-409d-a131-da4a48002bed","status":"finished","result":"steering fixture observed","model":{"id":"composer-2.5"},"durationMs":1746,"usage":{"inputTokens":11626,"outputTokens":38,"cacheReadTokens":11584,"cacheWriteTokens":0,"totalTokens":23248}}}}
25 +{"type":"expect_outbound","label":"agent.close","frame":{"type":"agent.close","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
apps/server/src/orchestration-v2/testkit/fixtures/message_steering/cursor_transcript.ndjson
+35 -23
@@ -1,25 +1,37 @@
1 -{"type":"transcript_start","provider":"cursor","protocol":"cursor-agent-sdk.local","version":"1","scenario":"message_steering","metadata":{"generatedBy":"recordCursorAgentSdkReplayTranscript","nativeAgentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
1 +{"type":"transcript_start","provider":"cursor","protocol":"cursor-agent-sdk.local","version":"1","scenario":"message_steering","metadata":{"generatedBy":"recordCursorAgentSdkReplayTranscript","nativeAgentId":"agent-c1014ffc-cc3e-4086-8b10-ad7170ca0397"}}
2 {"type":"expect_outbound","label":"agent.open","frame":{"type":"agent.open","operation":"create","options":{"model":{"id":"composer-2.5"},"hasName":true,"mode":"agent","local":{"hasCwd":true,"autoReview":false,"settingSources":["project","user","team","mdm","plugins"],"sandboxEnabled":false,"enableAgentRetries":true}}}}
3 -{"type":"emit_inbound","label":"agent.opened","frame":{"type":"agent.opened","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
3 +{"type":"emit_inbound","label":"agent.opened","frame":{"type":"agent.opened","agentId":"agent-c1014ffc-cc3e-4086-8b10-ad7170ca0397"}}
4 {"type":"expect_outbound","label":"run.start:1","frame":{"type":"run.start","message":"Respond with exactly: steering fixture initial response","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
5 -{"type":"emit_inbound","label":"run.started:1","frame":{"type":"run.started","runId":"run-046488f0-f621-4d59-976c-c4c935ad1282","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
6 -{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-046488f0-f621-4d59-976c-c4c935ad1282","update":{"type":"thinking-delta","text":"The user requested the"}}}
7 -{"type":"expect_outbound","label":"run.cancel:1","frame":{"type":"run.cancel","runId":"run-046488f0-f621-4d59-976c-c4c935ad1282"}}
8 -{"type":"emit_inbound","label":"run.completed:1","frame":{"type":"run.completed","result":{"id":"run-046488f0-f621-4d59-976c-c4c935ad1282","requestId":"d3b97820-1cf3-448d-a4b1-5fa7edc21460","status":"cancelled","model":{"id":"composer-2.5"},"durationMs":3177}}}
9 -{"type":"expect_outbound","label":"run.start:2","frame":{"type":"run.start","message":"Your previous turn was interrupted and is missing from your history. Some of its work may already be done. Its request was:\n\nRespond with exactly: steering fixture initial response\n\nThe new message, which may continue or change that request:\n\nActually, respond with exactly: steering fixture observed","options":{"model":{"id":"composer-2.5"},"mode":"agent"}}}
10 -{"type":"emit_inbound","label":"run.started:2","frame":{"type":"run.started","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
11 -{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-delta","text":"The response will be"}}}
12 -{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":5}}}
13 -{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-delta","text":" exactly: \"steering "}}}
14 -{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":5}}}
15 -{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-delta","text":"fixture observed\"."}}}
16 -{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":4}}}
17 -{"type":"emit_inbound","label":"thinking-completed","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"thinking-completed","thinkingDurationMs":2}}}
18 -{"type":"emit_inbound","label":"text-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"text-delta","text":"ste"}}}
19 -{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":1}}}
20 -{"type":"emit_inbound","label":"text-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"text-delta","text":"ering fixture observed"}}}
21 -{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"token-delta","tokens":5}}}
22 -{"type":"emit_inbound","label":"step-completed","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"step-completed","stepId":2,"stepDurationMs":789}}}
23 -{"type":"emit_inbound","label":"turn-ended","frame":{"type":"interaction.update","runId":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","update":{"type":"turn-ended","usage":{"inputTokens":11626,"outputTokens":38,"cacheReadTokens":11584,"cacheWriteTokens":0}}}}
24 -{"type":"emit_inbound","label":"run.completed:2","frame":{"type":"run.completed","result":{"id":"run-e3b66d77-b2d4-4791-be2b-1a35c8e997d1","requestId":"ed3603d4-2d59-409d-a131-da4a48002bed","status":"finished","result":"steering fixture observed","model":{"id":"composer-2.5"},"durationMs":1746,"usage":{"inputTokens":11626,"outputTokens":38,"cacheReadTokens":11584,"cacheWriteTokens":0,"totalTokens":23248}}}}
25 -{"type":"expect_outbound","label":"agent.close","frame":{"type":"agent.close","agentId":"agent-575fd75e-3fd7-412e-9b74-36f3a5aa5371"}}
5 +{"type":"emit_inbound","label":"run.started:1","frame":{"type":"run.started","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","agentId":"agent-c1014ffc-cc3e-4086-8b10-ad7170ca0397"}}
6 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":"The"}}}
7 +{"type":"expect_outbound","label":"run.steer:1","frame":{"type":"run.steer","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","text":"Actually, respond with exactly: steering fixture observed"}}
8 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":" user wants the exact"}}}
9 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":6}}}
10 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":" phrase \"steering fixture"}}}
11 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":6}}}
12 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":" initial response\"."}}}
13 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":5}}}
14 +{"type":"emit_inbound","label":"thinking-completed","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-completed","thinkingDurationMs":8}}}
15 +{"type":"emit_inbound","label":"text-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"text-delta","text":"ste"}}}
16 +{"type":"emit_inbound","label":"text-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"text-delta","text":"ering fixture initial response"}}}
17 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":8}}}
18 +{"type":"emit_inbound","label":"step-completed","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"step-completed","stepId":2,"stepDurationMs":1070}}}
19 +{"type":"emit_inbound","label":"run.steered:1","frame":{"type":"run.steered","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","outcome":"complete_delivered"}}
20 +{"type":"emit_inbound","label":"user-message-appended","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"user-message-appended","userMessage":{"type":"user_message","session_id":"agent-c1014ffc-cc3e-4086-8b10-ad7170ca0397","text":"Actually, respond with exactly: steering fixture observed"}}}}
21 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":"The"}}}
22 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":" user is steering the"}}}
23 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":6}}}
24 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":" conversation toward"}}}
25 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":5}}}
26 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":" a specific response"}}}
27 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":5}}}
28 +{"type":"emit_inbound","label":"thinking-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-delta","text":"."}}}
29 +{"type":"emit_inbound","label":"thinking-completed","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"thinking-completed","thinkingDurationMs":43}}}
30 +{"type":"emit_inbound","label":"text-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"text-delta","text":"ste"}}}
31 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":1}}}
32 +{"type":"emit_inbound","label":"text-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"text-delta","text":"ering fixture observed"}}}
33 +{"type":"emit_inbound","label":"token-delta","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"token-delta","tokens":5}}}
34 +{"type":"emit_inbound","label":"step-completed","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"step-completed","stepId":2,"stepDurationMs":820}}}
35 +{"type":"emit_inbound","label":"turn-ended","frame":{"type":"interaction.update","runId":"run-abf87939-713d-43c7-ac55-2022e9e261ec","update":{"type":"turn-ended","usage":{"inputTokens":24888,"outputTokens":94,"cacheReadTokens":15040,"cacheWriteTokens":0}}}}
36 +{"type":"emit_inbound","label":"run.completed:1","frame":{"type":"run.completed","result":{"id":"run-abf87939-713d-43c7-ac55-2022e9e261ec","requestId":"dab10858-7707-4b04-add2-da77ef408775","status":"finished","result":"steering fixture observed","model":{"id":"composer-2.5"},"durationMs":4316,"usage":{"inputTokens":24888,"outputTokens":94,"cacheReadTokens":15040,"cacheWriteTokens":0,"totalTokens":24982}}}}
37 +{"type":"expect_outbound","label":"agent.close:before-prompt-2","frame":{"type":"agent.close","agentId":"agent-c1014ffc-cc3e-4086-8b10-ad7170ca0397"}}
docs/user/cursor.md
+10 -7
@@ -49,17 +49,20 @@ The adapter supports:
49 - assistant text, reasoning, tool activity, plans, and todo streaming;
50 - thread-scoped T3 Code MCP tools alongside ambient Cursor MCP/plugins from disk;
51 - image attachments;
52 -- interruption, queued app messages, and orchestrator-owned interrupt/restart steering;
52 +- interruption, queued app messages, and in-turn steering;
53 - provider conversation snapshots through `Agent.messages.list()`;
54 - Cursor `task` subagents, projected as read-only child app threads with their tool activity and
55 final result.
56
57 -The public SDK does not currently expose native agent fork, conversation rollback, active steering,
58 -or interactive approval callbacks. Direct active steering is advertised as unsupported, while V2
59 -steering uses the orchestrator's interrupt-and-restart path and preserves the app run identity across
60 -provider turns. Same-provider Cursor forks use the orchestrator's portable full-thread context
61 -handoff into a fresh Cursor agent. The SDK has in-process custom callback tools, but the V2 adapter
62 -intentionally uses the authenticated, thread-scoped MCP server instead.
57 +The public SDK does not currently expose native agent fork, conversation rollback, or interactive
58 +approval callbacks. A text-only steer reaches the current run without restarting it.
59 +When Cursor cannot deliver the steer, the same message is queued for the next turn after
60 +this run finishes. If you press Stop, that follow-up stays held until you resume the queue. Steers
61 +with attachments and provider or runtime changes that must apply immediately interrupt and restart
62 +the run.
63 +Same-provider Cursor forks use the orchestrator's portable full-thread context handoff into a fresh
64 +Cursor agent. The SDK has in-process custom callback tools, but the V2 adapter intentionally uses the
65 +authenticated, thread-scoped MCP server instead.
66
67 Portable handoffs summarize eligible timeline items and can omit the end of long messages. Read
68 [Context in portable handoffs](./portable-handoffs.md) before using a fork for work whose exact
packages/contracts/src/orchestrationV2.ts
+2
@@ -3212,6 +3212,8 @@ export const OrchestrationV2Command = Schema.Union([
3212 restartContinuationOfRunId: Schema.optional(RunId),
3213 usageLimitContinuationOfRunId: Schema.optional(RunId),
3214 manualContinuationOfRunId: Schema.optional(RunId),
3215 + steerFollowUpOfRunId: Schema.optional(RunId),
3216 + steerFollowUpAfterRunOrdinal: Schema.optional(NonNegativeInt),
3217 usageLimitRecoveryRequestId: Schema.optional(CommandId),
3218 deliveryIntent: Schema.optional(Schema.Literals(["auto", "steer", "restart"])),
3219 delegatedCompletion: Schema.optional(
packages/provider-core/src/server/ProviderAdapter.ts
+10
@@ -369,6 +369,15 @@ export class ProviderAdapterSteerRunUnsupportedError extends Schema.TaggedError<
369 }
370 }
371
372 +export class ProviderAdapterSteerDeclinedError extends Schema.TaggedError<ProviderAdapterSteerDeclinedError>()(
373 + "ProviderAdapterSteerDeclinedError",
374 + {
375 + driver: ProviderDriverKind,
376 + providerThreadId: ProviderThreadId,
377 + providerTurnId: ProviderTurnId,
378 + },
379 +) {}
380 +
381 export class ProviderAdapterSteerRunError extends Schema.TaggedError<ProviderAdapterSteerRunError>()(
382 "ProviderAdapterSteerRunError",
383 {
@@ -482,6 +491,7 @@ export const ProviderAdapterV2Error = Schema.Union([
491 ProviderAdapterTurnStartError,
492 ProviderAdapterSteerRunUnsupportedError,
493 ProviderAdapterSteerRunError,
494 + ProviderAdapterSteerDeclinedError,
495 ProviderAdapterInterruptError,
496 ProviderAdapterInterruptTimeoutError,
497 ProviderAdapterRuntimeRequestResponseError,
packages/provider-cursor/src/server/CursorAgentSdk.test.ts
+35
@@ -25,6 +25,7 @@ const cursorSdkMock = vi.hoisted(() => {
25 durationMs: 1,
26 }));
27 const runCancel = vi.fn(async () => {});
28 + const runSteer = vi.fn(async () => "complete_delivered" as const);
29 const agentClose = vi.fn(() => {
30 closeExecutionOrder.push("sdk:agent.close");
31 if (agentCloseFailure !== undefined) {
@@ -51,6 +52,7 @@ const cursorSdkMock = vi.hoisted(() => {
52 agentId: "agent-cursor-agent-sdk-test",
53 wait: runWait,
54 cancel: runCancel,
55 + steer: runSteer as typeof runSteer | undefined,
56 };
57 },
58 );
@@ -84,6 +86,7 @@ const cursorSdkMock = vi.hoisted(() => {
86 resume,
87 runOperations,
88 runCancel,
89 + runSteer,
90 runWait,
91 send,
92 setAgentCloseFailure: (failure: unknown) => {
@@ -211,4 +214,36 @@ describe("CursorAgentSdkRunner", () => {
214 ]);
215 }).pipe(Effect.provide(layerTest)),
216 );
217 +
218 + it.effect("forwards Run.steer and reports a missing method as a follow-up", () =>
219 + Effect.gen(function* () {
220 + cursorSdkMock.runSteer.mockClear();
221 + const runner = yield* CursorAgentSdk.CursorAgentSdkRunner;
222 + const session = yield* runner.open({
223 + operation: "create",
224 + options: {},
225 + threadId: ThreadId.make("thread-cursor-agent-sdk-steer"),
226 + providerSessionId: ProviderSessionId.make("provider-session-cursor-agent-sdk-steer"),
227 + });
228 + const run = yield* session.send({ message: "continue" });
229 + assert.equal(yield* run.steer!("keep going"), "complete_delivered");
230 + assert.deepStrictEqual(cursorSdkMock.runSteer.mock.calls, [["keep going"]]);
231 +
232 + cursorSdkMock.runSteer.mockImplementationOnce(async () => {
233 + throw new Error("steer transport failed");
234 + });
235 + const failed = yield* run.steer!("again").pipe(Effect.exit);
236 + assert(Exit.isFailure(failed));
237 +
238 + cursorSdkMock.send.mockImplementationOnce(async () => ({
239 + id: "run-without-steer",
240 + agentId: "agent-cursor-agent-sdk-test",
241 + wait: cursorSdkMock.runWait,
242 + cancel: cursorSdkMock.runCancel,
243 + steer: undefined,
244 + }));
245 + const plain = yield* session.send({ message: "plain" });
246 + assert.equal(yield* plain.steer!("later"), "revert_to_followup");
247 + }).pipe(Effect.provide(layerTest)),
248 + );
249 });
packages/provider-cursor/src/server/CursorAgentSdk.ts
+50
@@ -5,6 +5,7 @@ import type {
5 RunResult,
6 SDKUserMessage,
7 SendOptions,
8 + SteerAckOutcome,
9 } from "@cursor/sdk";
10 import {
11 type OrchestrationV2ProviderSession,
@@ -98,6 +99,8 @@ export interface CursorAgentSdkRun {
99 readonly agentId: string;
100 readonly wait: Effect.Effect<RunResult, CursorAgentSdkRunnerError>;
101 readonly cancel: Effect.Effect<void, CursorAgentSdkRunnerError>;
102 + /** Absent on test doubles that never steer. The live runner always sets it. */
103 + readonly steer?: (text: string) => Effect.Effect<SteerAckOutcome, CursorAgentSdkRunnerError>;
104 }
105
106 export interface CursorAgentSdkSession {
@@ -204,6 +207,24 @@ export type CursorAgentSdkProtocolLogEvent =
207 readonly result: RunResult;
208 };
209 }
210 + | {
211 + readonly direction: "outgoing";
212 + readonly stage: "decoded";
213 + readonly payload: {
214 + readonly type: "run.steer";
215 + readonly runId: string;
216 + readonly text: string;
217 + };
218 + }
219 + | {
220 + readonly direction: "incoming";
221 + readonly stage: "decoded";
222 + readonly payload: {
223 + readonly type: "run.steered";
224 + readonly runId: string;
225 + readonly outcome: SteerAckOutcome;
226 + };
227 + }
228 | {
229 readonly direction: "outgoing";
230 readonly stage: "decoded";
@@ -563,6 +584,35 @@ export const makeCursorAgentSdkRunner = Effect.fn("makeCursorAgentSdkRunner")(fu
584 }),
585 ),
586 ),
587 + steer: Effect.fn("CursorAgentSdkRun.steer")((text: string) =>
588 + log({
589 + direction: "outgoing",
590 + stage: "decoded",
591 + payload: {
592 + type: "run.steer",
593 + runId: run.id,
594 + text,
595 + },
596 + }).pipe(
597 + Effect.andThen(
598 + Effect.tryPromise({
599 + try: () => run.steer?.(text) ?? Promise.resolve("revert_to_followup" as const),
600 + catch: (cause) => runnerError(cause, "run.steer"),
601 + }),
602 + ),
603 + Effect.tap((outcome) =>
604 + log({
605 + direction: "incoming",
606 + stage: "decoded",
607 + payload: {
608 + type: "run.steered",
609 + runId: run.id,
610 + outcome,
611 + },
612 + }),
613 + ),
614 + ),
615 + ),
616 cancel: log({
617 direction: "outgoing",
618 stage: "decoded",
packages/provider-cursor/src/server/adapter.test.ts
+186
@@ -16,9 +16,11 @@ import {
16 RunId,
17 ThreadId,
18 } from "@t3tools/contracts";
19 +import * as Cause from "effect/Cause";
20 import * as DateTime from "effect/DateTime";
21 import * as Deferred from "effect/Deferred";
22 import * as Effect from "effect/Effect";
23 +import * as Exit from "effect/Exit";
24 import * as FileSystem from "effect/FileSystem";
25 import * as Layer from "effect/Layer";
26 import * as Option from "effect/Option";
@@ -2017,6 +2019,190 @@ describe("CursorAdapterV2", () => {
2019 assert.isFalse(CursorAgentSdk.isCursorCancellationError(null));
2020 });
2021
2022 + it.effect(
2023 + "rewrites skills on live steers and returns a decline without waiting for completion",
2024 + () =>
2025 + Effect.gen(function* () {
2026 + const fileSystem = yield* FileSystem.FileSystem;
2027 + const workspace = yield* fileSystem.makeTempDirectoryScoped({
2028 + prefix: "cursor-v2-steer-",
2029 + });
2030 + const path = yield* Path.Path;
2031 + const skill = path.join(workspace, ".cursor", "skills", "review");
2032 + yield* fileSystem.makeDirectory(skill, { recursive: true });
2033 + yield* fileSystem.writeFileString(
2034 + path.join(skill, "SKILL.md"),
2035 + "# Review\nReview the code.",
2036 + );
2037 + const steered: string[] = [];
2038 + let cancelled = 0;
2039 + let outcome: "complete_delivered" | "revert_to_followup" = "complete_delivered";
2040 + const finished = yield* Deferred.make<{
2041 + readonly id: string;
2042 + readonly requestId: string;
2043 + readonly status: "finished" | "cancelled";
2044 + readonly model: { readonly id: string };
2045 + readonly durationMs: number;
2046 + }>();
2047 + const instanceId = ProviderInstanceId.make("cursor");
2048 + const threadId = ThreadId.make("cursor-steer-thread");
2049 + const modelSelection = { instanceId, model: "composer-2.5" };
2050 + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
2051 + runtimeMode: "full-access",
2052 + interactionMode: "default",
2053 + cwd: workspace,
2054 + });
2055 + const adapter = yield* makeCursorAdapterV2({
2056 + instanceId,
2057 + environment: { HOME: workspace },
2058 + }).pipe(
2059 + Effect.provideService(CursorAgentSdk.CursorAgentSdkRunner, {
2060 + assertComplete: Effect.void,
2061 + open: () =>
2062 + Effect.succeed({
2063 + agentId: "native-cursor-steer",
2064 + listMessages: Effect.succeed([]),
2065 + close: Effect.void,
2066 + send: () =>
2067 + Effect.succeed({
2068 + agentId: "native-cursor-steer",
2069 + runId: "native-cursor-steer-run",
2070 + wait: Deferred.await(finished),
2071 + cancel: Effect.sync(() => {
2072 + cancelled += 1;
2073 + }).pipe(
2074 + Effect.andThen(
2075 + Deferred.succeed(finished, {
2076 + id: "native-cursor-steer-run",
2077 + requestId: "native-request",
2078 + status: "cancelled" as const,
2079 + model: { id: "composer-2.5" },
2080 + durationMs: 1,
2081 + }),
2082 + ),
2083 + ),
2084 + steer: (text) =>
2085 + Effect.sync(() => {
2086 + steered.push(text);
2087 + return outcome;
2088 + }),
2089 + }),
2090 + }),
2091 + }),
2092 + Effect.provide(TestProviderHost.layer({ cwd: workspace })),
2093 + );
2094 + const runtime = yield* adapter.openSession({
2095 + threadId,
2096 + providerSessionId: ProviderSessionId.make("cursor-steer-session"),
2097 + modelSelection,
2098 + runtimePolicy,
2099 + });
2100 + assert.equal(
2101 + runtime.providerSession.capabilities.turns.activeSteeringAcceptsAttachments,
2102 + false,
2103 + );
2104 + const providerThread = yield* runtime.ensureThread({
2105 + threadId,
2106 + modelSelection,
2107 + runtimePolicy,
2108 + });
2109 + const now = yield* DateTime.now;
2110 + const turn = {
2111 + threadId,
2112 + providerThread,
2113 + modelSelection,
2114 + runtimePolicy,
2115 + runId: RunId.make("cursor-steer-run"),
2116 + runOrdinal: 1,
2117 + providerTurnOrdinal: 1,
2118 + attemptId: RunAttemptId.make("cursor-steer-attempt"),
2119 + rootNodeId: NodeId.make("cursor-steer-root"),
2120 + appThread: {
2121 + id: threadId,
2122 + projectId: ProjectId.make("cursor-steer-project"),
2123 + createdBy: "user" as const,
2124 + creationSource: "web" as const,
2125 + title: "Cursor steer",
2126 + providerInstanceId: instanceId,
2127 + modelSelection,
2128 + runtimeMode: "full-access" as const,
2129 + interactionMode: "default" as const,
2130 + branch: null,
2131 + worktreePath: null,
2132 + activeProviderThreadId: providerThread.id,
2133 + lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: threadId },
2134 + forkedFrom: null,
2135 + createdAt: now,
2136 + updatedAt: now,
2137 + archivedAt: null,
2138 + settledOverride: null,
2139 + settledAt: null,
2140 + lastVisitedAt: null,
2141 + deletedAt: null,
2142 + },
2143 + message: {
2144 + messageId: MessageId.make("cursor-steer-message"),
2145 + createdBy: "user" as const,
2146 + creationSource: "web" as const,
2147 + text: "Review the code.",
2148 + attachments: [],
2149 + },
2150 + };
2151 + const providerTurnId = (yield* IdAllocator.IdAllocatorV2).derive.providerTurn({
2152 + driver: CursorAgentSdk.CURSOR_PROVIDER,
2153 + nativeTurnId: "native-cursor-steer-run",
2154 + });
2155 + yield* runtime.startTurn(turn);
2156 + yield* runtime.steerTurn({
2157 + threadId,
2158 + runId: turn.runId,
2159 + providerThread,
2160 + providerTurnId,
2161 + message: {
2162 + messageId: MessageId.make("cursor-steer-follow-up"),
2163 + createdBy: "user",
2164 + creationSource: "web",
2165 + text: "$review Look at the tests instead.",
2166 + attachments: [],
2167 + },
2168 + });
2169 + assert.deepEqual(steered, ["/review Look at the tests instead."]);
2170 + assert.equal(cancelled, 0);
2171 +
2172 + outcome = "revert_to_followup";
2173 + const declined = yield* runtime
2174 + .steerTurn({
2175 + threadId,
2176 + runId: turn.runId,
2177 + providerThread,
2178 + providerTurnId,
2179 + message: {
2180 + messageId: MessageId.make("cursor-steer-declined"),
2181 + createdBy: "user",
2182 + creationSource: "web",
2183 + text: "Stop and do this.",
2184 + attachments: [],
2185 + },
2186 + })
2187 + .pipe(Effect.exit);
2188 + if (!Exit.isFailure(declined)) return yield* Effect.die("Expected a declined steer");
2189 + assert.deepEqual(steered, ["/review Look at the tests instead.", "Stop and do this."]);
2190 + assert.equal(cancelled, 0);
2191 + const declinedError = Cause.squash(declined.cause);
2192 + assert.instanceOf(declinedError, ProviderAdapter.ProviderAdapterSteerDeclinedError);
2193 + yield* runtime.interruptTurn({
2194 + providerThread,
2195 + providerTurnId,
2196 + });
2197 + assert.equal(cancelled, 1);
2198 + }).pipe(
2199 + Effect.scoped,
2200 + Effect.provide(
2201 + Layer.mergeAll(NodeServices.layer, IdAllocator.layer, McpProviderSessions.layer),
2202 + ),
2203 + ),
2204 + );
2205 +
2206 it("preserves failed nested read calls when Cursor omits their path", () => {
2207 assert.deepEqual(
2208 nestedToolCallFromEnvelope({
packages/provider-cursor/src/server/adapter.ts
+87 -24
@@ -96,7 +96,11 @@ export const CursorProviderCapabilitiesV2 = {
96 emitsTurnStarted: true,
97 emitsTurnCompleted: true,
98 supportsInterrupt: true,
99 - supportsActiveSteering: false,
99 + supportsActiveSteering: true,
100 + // A steer can move a foreground subagent to the background. Mailbox wakes
101 + // stay queued so a notification does not cut into the live turn.
102 + activeSteeringInterruptsTools: true,
103 + activeSteeringAcceptsAttachments: false,
104 supportsSteeringByInterruptRestart: true,
105 supportsQueuedMessages: true,
106 terminalStatusQuality: "strong",
@@ -2292,6 +2296,24 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2296 });
2297
2298 let cursorSkillNames: ReadonlySet<string> | undefined;
2299 + const resolveCursorSkillText = Effect.fn("CursorAdapterV2.resolveCursorSkillText")(
2300 + function* (rawText: string, cwd: string | undefined) {
2301 + if (hasCursorSkillMention(rawText) && cursorSkillNames === undefined) {
2302 + const skills = yield* discoverCursorSkills(cwd, adapterOptions.environment).pipe(
2303 + Effect.provideService(FileSystem.FileSystem, fileSystem),
2304 + Effect.provideService(Path.Path, path),
2305 + );
2306 + cursorSkillNames = new Set(
2307 + skills
2308 + .filter((skill) => skill.enabled && skill.userInvocable !== false)
2309 + .map((skill) => skill.name),
2310 + );
2311 + }
2312 + return cursorSkillNames === undefined
2313 + ? rawText
2314 + : rewriteCursorSkillMentions(rawText, cursorSkillNames);
2315 + },
2316 + );
2317 const resolveUserMessage = Effect.fnUntraced(function* (
2318 turnInput: ProviderAdapter.ProviderAdapterV2TurnInput,
2319 mcpServers: Record<string, McpServerConfig> | undefined,
@@ -2303,26 +2325,12 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2325 if (rawText.trim() === "/compress" && turnInput.message.attachments.length === 0) {
2326 return { message: "/compress", prompt: undefined };
2327 }
2306 - if (hasCursorSkillMention(rawText) && cursorSkillNames === undefined) {
2307 - const skills = yield* discoverCursorSkills(
2308 - turnInput.runtimePolicy.cwd ?? undefined,
2309 - adapterOptions.environment,
2310 - ).pipe(
2311 - Effect.provideService(FileSystem.FileSystem, fileSystem),
2312 - Effect.provideService(Path.Path, path),
2313 - );
2314 - cursorSkillNames = new Set(
2315 - skills
2316 - .filter((skill) => skill.enabled && skill.userInvocable !== false)
2317 - .map((skill) => skill.name),
2318 - );
2319 - }
2328 const newText = t3OrchestrationPrompt({
2329 prompt: yield* providerMessageTextWithAttachmentPaths({
2322 - text:
2323 - cursorSkillNames === undefined
2324 - ? rawText
2325 - : rewriteCursorSkillMentions(rawText, cursorSkillNames),
2330 + text: yield* resolveCursorSkillText(
2331 + rawText,
2332 + turnInput.runtimePolicy.cwd ?? undefined,
2333 + ),
2334 attachments: turnInput.message.attachments,
2335 resolveAttachmentPath: host.resolveAttachmentPath,
2336 resolveExtractedTextPath: host.resolveExtractedTextPath,
@@ -2699,13 +2707,68 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
2707 ...turnInput,
2708 message: { ...turnInput.message, text: "/compress" },
2709 }),
2702 - steerTurn: (turnInput) =>
2703 - Effect.fail(
2704 - new ProviderAdapter.ProviderAdapterSteerRunUnsupportedError({
2710 + steerTurn: Effect.fn("CursorAdapterV2.steerTurn")(
2711 + function* (turnInput: ProviderAdapter.ProviderAdapterV2SteerInput) {
2712 + const context = yield* Ref.get(activeTurn);
2713 + if (
2714 + context === null ||
2715 + context.finalized ||
2716 + context.providerTurnId !== turnInput.providerTurnId
2717 + ) {
2718 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
2719 + driver: CursorAgentSdk.CURSOR_PROVIDER,
2720 + detail: `Cursor provider turn ${turnInput.providerTurnId} is not active.`,
2721 + });
2722 + }
2723 + // The live run already has the runtime instructions from startTurn.
2724 + const text = yield* providerMessageTextWithAttachmentPaths({
2725 + text: yield* resolveCursorSkillText(
2726 + turnInput.message.text,
2727 + context.input.runtimePolicy.cwd ?? undefined,
2728 + ),
2729 + attachments: turnInput.message.attachments,
2730 + resolveAttachmentPath: host.resolveAttachmentPath,
2731 + resolveExtractedTextPath: host.resolveExtractedTextPath,
2732 + });
2733 + if (text.trim().length === 0) {
2734 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
2735 + driver: CursorAgentSdk.CURSOR_PROVIDER,
2736 + detail: "Cursor steer requires non-empty text.",
2737 + });
2738 + }
2739 + const outcome =
2740 + context.run.steer === undefined
2741 + ? "revert_to_followup"
2742 + : yield* context.run.steer(text);
2743 + if (outcome === "complete_delivered") {
2744 + return;
2745 + }
2746 + if (context.interrupted) {
2747 + return yield* new ProviderAdapter.ProviderAdapterProtocolError({
2748 + driver: CursorAgentSdk.CURSOR_PROVIDER,
2749 + detail: "Cursor steer was interrupted before the run could take it.",
2750 + });
2751 + }
2752 + return yield* new ProviderAdapter.ProviderAdapterSteerDeclinedError({
2753 driver: CursorAgentSdk.CURSOR_PROVIDER,
2754 providerThreadId: turnInput.providerThread.id,
2707 - }),
2708 - ),
2755 + providerTurnId: turnInput.providerTurnId,
2756 + });
2757 + },
2758 + (effect, turnInput) =>
2759 + effect.pipe(
2760 + Effect.mapError((cause) =>
2761 + cause._tag === "ProviderAdapterSteerDeclinedError"
2762 + ? cause
2763 + : new ProviderAdapter.ProviderAdapterSteerRunError({
2764 + driver: CursorAgentSdk.CURSOR_PROVIDER,
2765 + providerThreadId: turnInput.providerThread.id,
2766 + providerTurnId: turnInput.providerTurnId,
2767 + cause,
2768 + }),
2769 + ),
2770 + ),
2771 + ),
2772 interruptTurn: Effect.fn("CursorAdapterV2.interruptTurn")(
2773 function* (turnInput: ProviderAdapter.ProviderAdapterV2InterruptInput) {
2774 const context = yield* Ref.get(activeTurn);