Skip to content

Commit c0fa3e1

Browse files
committed
fix(provider): preserve Cursor rollback semantics
1 parent 301c361 commit c0fa3e1

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

‎apps/server/src/provider/Layers/AcpAdapter.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export interface AcpProviderAdapterDefinition<Settings> {
133133
input: AcpProviderExtensionRegistrationInput,
134134
) => Effect.Effect<void, EffectAcpErrors.AcpError>;
135135
readonly userInputRequestMethod?: string;
136+
readonly supportsRollback?: boolean;
136137
readonly shouldAutoApprovePermission?: (input: {
137138
readonly runtimeMode: RuntimeMode;
138139
readonly permissionKind: string | "unknown";
@@ -1152,14 +1153,19 @@ export function makeAcpProviderAdapter<Settings>(
11521153
numTurns,
11531154
) =>
11541155
Effect.gen(function* () {
1155-
yield* requireSession(threadId);
1156+
const ctx = yield* requireSession(threadId);
11561157
if (!Number.isInteger(numTurns) || numTurns < 1) {
11571158
return yield* new ProviderAdapterValidationError({
11581159
provider: PROVIDER,
11591160
operation: "rollbackThread",
11601161
issue: "numTurns must be an integer >= 1.",
11611162
});
11621163
}
1164+
if (definition.supportsRollback) {
1165+
const nextLength = Math.max(0, ctx.turns.length - numTurns);
1166+
ctx.turns.splice(nextLength);
1167+
return { threadId, turns: ctx.turns };
1168+
}
11631169
// ACP has no rollback operation. Do not trim local history while the
11641170
// provider retains the removed turns; return an explicit error instead.
11651171
return yield* new ProviderAdapterRequestError({

‎apps/server/src/provider/Layers/CursorAdapter.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,31 @@ cursorAdapterTestLayer("CursorAdapterLive", (it) => {
250250
}),
251251
);
252252

253+
it.effect("preserves Cursor's local rollback behavior through the shared ACP adapter", () =>
254+
Effect.gen(function* () {
255+
const adapter = yield* CursorAdapter;
256+
const settings = yield* ServerSettingsService;
257+
const threadId = ThreadId.make("cursor-rollback-thread");
258+
const wrapperPath = yield* Effect.promise(() => makeMockAgentWrapper());
259+
yield* settings.updateSettings({ providers: { cursor: { binaryPath: wrapperPath } } });
260+
261+
yield* adapter.startSession({
262+
threadId,
263+
provider: ProviderDriverKind.make("cursor"),
264+
cwd: process.cwd(),
265+
runtimeMode: "full-access",
266+
modelSelection: { instanceId: ProviderInstanceId.make("cursor"), model: "default" },
267+
});
268+
yield* adapter.sendTurn({ threadId, input: "first", attachments: [] });
269+
yield* adapter.sendTurn({ threadId, input: "second", attachments: [] });
270+
271+
const rolledBack = yield* adapter.rollbackThread(threadId, 1);
272+
assert.equal(rolledBack.turns.length, 1);
273+
274+
yield* adapter.stopSession(threadId);
275+
}),
276+
);
277+
253278
it.effect("steers a running turn instead of opening a new one on mid-turn sendTurn", () =>
254279
Effect.gen(function* () {
255280
const adapter = yield* CursorAdapter;

‎apps/server/src/provider/Layers/CursorAdapter.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export function makeCursorAdapter(
145145
defaultInstanceId: ProviderInstanceId.make("cursor"),
146146
displayName: "Cursor",
147147
settings: cursorSettings,
148+
supportsRollback: true,
148149
...(options ? { options } : {}),
149150
registerExtensions: registerCursorExtensions,
150151
userInputRequestMethod: "cursor/ask_question",

‎apps/server/src/provider/Layers/OmpAdapter.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function makeOmpAdapter(ompSettings: OmpSettings, options?: OmpAdapterLiv
2424
defaultInstanceId: ProviderInstanceId.make("omp"),
2525
displayName: "OMP",
2626
settings: ompSettings,
27+
supportsRollback: false,
2728
...(options ? { options } : {}),
2829
makeRuntime: ({
2930
settings,

0 commit comments

Comments
 (0)