Skip to content

Commit ba3c893

Browse files
committed
fix(cursor): /compact compacts with the SDK's summarize
T3 sent /compress as a chat message, which the Cursor SDK passes to the model as plain text. Start agent.summarize() for compaction turns instead and keep the returned summary out of the chat.
1 parent a5571c5 commit ba3c893

3 files changed

Lines changed: 30 additions & 23 deletions

File tree

‎packages/provider-cursor/src/server/CursorAgentSdk.ts‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ export interface CursorAgentSdkSendInput<Error> {
8989
readonly message: string | SDKUserMessage;
9090
readonly options?: Omit<SendOptions, "onDelta">;
9191
readonly onDelta?: (update: InteractionUpdate) => Effect.Effect<void, Error>;
92+
/** Runs `agent.summarize()` instead, which takes no message or options. */
93+
readonly summarize?: boolean;
9294
}
9395

9496
export interface CursorAgentSdkRun {
@@ -465,16 +467,18 @@ export const makeCursorAgentSdkRunner = Effect.fn("makeCursorAgentSdkRunner")(fu
465467
const startRun = () =>
466468
Effect.tryPromise({
467469
try: () =>
468-
agent.send(sendInput.message, {
469-
...sendInput.options,
470-
onDelta: async ({ update }) => {
471-
if (!callbacksReady) {
472-
pendingUpdates.push(update);
473-
return;
474-
}
475-
await dispatchUpdate(update);
476-
},
477-
}),
470+
sendInput.summarize === true
471+
? agent.summarize()
472+
: agent.send(sendInput.message, {
473+
...sendInput.options,
474+
onDelta: async ({ update }) => {
475+
if (!callbacksReady) {
476+
pendingUpdates.push(update);
477+
return;
478+
}
479+
await dispatchUpdate(update);
480+
},
481+
}),
478482
catch: (cause) => runnerError(cause, "run.start"),
479483
});
480484
const run = yield* startRun().pipe(

‎packages/provider-cursor/src/server/adapter.test.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,11 @@ describe("CursorAdapterV2", () => {
508508
),
509509
);
510510

511-
it.effect("fails standalone SDK transport diagnostics and sends compaction as /compress", () =>
511+
it.effect("fails standalone SDK transport diagnostics and compacts with SDK summarize", () =>
512512
Effect.gen(function* () {
513513
const fileSystem = yield* FileSystem.FileSystem;
514514
const workspace = yield* fileSystem.makeTempDirectoryScoped({ prefix: "cursor-v2-errors-" });
515-
const sentMessages: Array<string> = [];
515+
const summarizeRequests: Array<boolean> = [];
516516
let sendCalls = 0;
517517
const instanceId = ProviderInstanceId.make("cursor");
518518
const threadId = ThreadId.make("cursor-transport-error-thread");
@@ -536,9 +536,7 @@ describe("CursorAdapterV2", () => {
536536
send: (input) =>
537537
Effect.sync(() => {
538538
sendCalls += 1;
539-
sentMessages.push(
540-
typeof input.message === "string" ? input.message : input.message.text,
541-
);
539+
summarizeRequests.push(input.summarize === true);
542540
const runId = `native-cursor-run-${sendCalls}`;
543541
return {
544542
agentId: "native-cursor-error",
@@ -549,9 +547,10 @@ describe("CursorAdapterV2", () => {
549547
status: "finished" as const,
550548
model: { id: "composer-2.5" },
551549
durationMs: 1,
552-
...(sendCalls === 1
553-
? { result: "Error: RetriableError: WritableIterable is closed" }
554-
: {}),
550+
result:
551+
sendCalls === 1
552+
? "Error: RetriableError: WritableIterable is closed"
553+
: "Summary of the conversation so far",
555554
}),
556555
cancel: Effect.void,
557556
};
@@ -644,11 +643,12 @@ describe("CursorAdapterV2", () => {
644643
attachments: [],
645644
},
646645
});
647-
yield* runtime.events.pipe(
648-
Stream.filter((event) => event.type === "turn.terminal"),
649-
Stream.runHead,
646+
const compactionEvents = yield* runtime.events.pipe(
647+
Stream.takeUntil((event) => event.type === "turn.terminal"),
648+
Stream.runCollect,
650649
);
651-
assert.equal(sentMessages[1], "/compress");
650+
assert.deepEqual(summarizeRequests, [false, true]);
651+
assert.notInclude(JSON.stringify(compactionEvents), "Summary of the conversation so far");
652652
}).pipe(
653653
Effect.scoped,
654654
Effect.provide(

‎packages/provider-cursor/src/server/adapter.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2385,12 +2385,14 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
23852385
hasDeviceTools,
23862386
delivered,
23872387
);
2388+
const compacted = message === "/compress";
23882389
const pendingUpdates: Array<InteractionUpdate> = [];
23892390
let context: ActiveCursorTurn | null = null;
23902391
// Create-time and send-time mcpServers merge with settingSources (SDK >= 1.0.39).
23912392
const sdkRun = yield* agent.session
23922393
.send({
23932394
message,
2395+
summarize: compacted,
23942396
options: {
23952397
model: cursorSdkModelSelection(turnInput.modelSelection),
23962398
mode: turnInput.runtimePolicy.interactionMode === "plan" ? "plan" : "agent",
@@ -2406,7 +2408,6 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
24062408
},
24072409
})
24082410
.pipe(Effect.mapError(classifyCursorModelRejection(turnInput.modelSelection)));
2409-
const compacted = message === "/compress";
24102411
yield* Ref.set(told, {
24112412
agent: agent.nativeThreadId,
24122413
orchestration: !compacted && (delivered.orchestration || mcpServers !== undefined),
@@ -2470,6 +2471,8 @@ export const makeCursorAdapterV2 = Effect.fn("makeCursorAdapterV2")(function* (
24702471
if (
24712472
context !== null &&
24722473
context.assistant.nextSegment === 0 &&
2474+
// A summarize run's result is the summary, not an answer.
2475+
!compacted &&
24732476
// Text from a resume that made no progress is not the turn's answer.
24742477
!isResumeFailureAfterTurnEnded(context, result) &&
24752478
result.result !== undefined &&

0 commit comments

Comments
 (0)