Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d8ce194ed | ||
|
|
03044135db | ||
|
|
ac2cd317ce | ||
|
|
ec4f561392 | ||
|
|
f9f3ed7e35 | ||
|
|
a1d871198a |
No files matched your search
@@ -23,6 +23,7 @@ const emitXAiPromptCompleteThenHang = process.env.T3_ACP_EMIT_XAI_PROMPT_COMPLET
|
||||
const emitForeignSessionUpdates = process.env.T3_ACP_EMIT_FOREIGN_SESSION_UPDATES === "1";
|
||||
const hangPromptForever = process.env.T3_ACP_HANG_PROMPT_FOREVER === "1";
|
||||
const hangFirstPromptForever = process.env.T3_ACP_HANG_FIRST_PROMPT_FOREVER === "1";
|
||||
const hangFirstPrompts = Number(process.env.T3_ACP_HANG_FIRST_PROMPTS ?? "0");
|
||||
const emitLateUpdateAfterCancel = process.env.T3_ACP_EMIT_LATE_UPDATE_AFTER_CANCEL === "1";
|
||||
const omitXAiPromptCompleteStopReason =
|
||||
process.env.T3_ACP_OMIT_XAI_PROMPT_COMPLETE_STOP_REASON === "1";
|
||||
@@ -518,7 +519,13 @@ const program = Effect.gen(function* () {
|
||||
return yield* Effect.never;
|
||||
}
|
||||
|
||||
if (hangPromptForever || (hangFirstPromptForever && promptCount === 1)) {
|
||||
if (
|
||||
hangPromptForever ||
|
||||
(hangFirstPromptForever && promptCount === 1) ||
|
||||
(Number.isFinite(hangFirstPrompts) &&
|
||||
hangFirstPrompts > 0 &&
|
||||
promptCount <= hangFirstPrompts)
|
||||
) {
|
||||
return yield* Effect.never;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import * as Deferred from "effect/Deferred";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Fiber from "effect/Fiber";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Ref from "effect/Ref";
|
||||
import * as Schema from "effect/Schema";
|
||||
import * as Stream from "effect/Stream";
|
||||
import * as TestClock from "effect/testing/TestClock";
|
||||
@@ -60,6 +61,89 @@ exec ${JSON.stringify(mockAgentCommand)} ${mockAgentArgs.map((arg) => JSON.strin
|
||||
return wrapperPath;
|
||||
}
|
||||
|
||||
async function makeTerminalCallbackWrapper(
|
||||
kind: "permission" | "question",
|
||||
promptOutcome: "success" | "failure" | "hang" = "success",
|
||||
) {
|
||||
const dir = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "cursor-acp-terminal-"));
|
||||
const wrapperPath = NodePath.join(dir, "fake-agent.mjs");
|
||||
const callback =
|
||||
kind === "permission"
|
||||
? {
|
||||
jsonrpc: "2.0",
|
||||
id: 9001,
|
||||
method: "session/request_permission",
|
||||
params: {
|
||||
sessionId: "terminal-callback-session",
|
||||
toolCall: {
|
||||
toolCallId: "terminal-tool-call",
|
||||
title: "Terminal",
|
||||
kind: "execute",
|
||||
status: "pending",
|
||||
content: [
|
||||
{
|
||||
type: "content",
|
||||
content: { type: "text", text: "run terminal command" },
|
||||
},
|
||||
],
|
||||
},
|
||||
options: [
|
||||
{ optionId: "allow-once", name: "Allow once", kind: "allow_once" },
|
||||
{ optionId: "reject-once", name: "Reject", kind: "reject_once" },
|
||||
],
|
||||
},
|
||||
}
|
||||
: {
|
||||
jsonrpc: "2.0",
|
||||
id: 9002,
|
||||
method: "cursor/ask_question",
|
||||
params: {
|
||||
toolCallId: "terminal-question",
|
||||
title: "Question",
|
||||
questions: [
|
||||
{
|
||||
id: "scope",
|
||||
prompt: "Which scope?",
|
||||
options: [{ id: "workspace", label: "Workspace" }],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const script = `#!/usr/bin/env node
|
||||
import readline from "node:readline";
|
||||
const callback = ${JSON.stringify(callback)};
|
||||
const kind = ${JSON.stringify(kind)};
|
||||
const promptOutcome = ${JSON.stringify(promptOutcome)};
|
||||
const send = (message) => process.stdout.write(JSON.stringify(message) + "\\n");
|
||||
readline.createInterface({ input: process.stdin }).on("line", (line) => {
|
||||
const message = JSON.parse(line);
|
||||
if (!("method" in message)) return;
|
||||
if (message.method === "initialize") {
|
||||
send({ jsonrpc: "2.0", id: message.id, result: { protocolVersion: 1, agentCapabilities: {} } });
|
||||
} else if (message.method === "session/new") {
|
||||
send({ jsonrpc: "2.0", id: message.id, result: { sessionId: "terminal-callback-session" } });
|
||||
} else if (message.method === "session/prompt") {
|
||||
const response =
|
||||
promptOutcome === "failure"
|
||||
? { jsonrpc: "2.0", id: message.id, error: { code: -32603, message: "prompt failed" } }
|
||||
: { jsonrpc: "2.0", id: message.id, result: { stopReason: "end_turn" } };
|
||||
const messages =
|
||||
promptOutcome === "hang"
|
||||
? [callback]
|
||||
: kind === "question" && promptOutcome === "success"
|
||||
? [response, callback]
|
||||
: [callback, response];
|
||||
process.stdout.write(messages.map(JSON.stringify).join("\\n") + "\\n");
|
||||
} else if (message.id !== undefined) {
|
||||
send({ jsonrpc: "2.0", id: message.id, result: {} });
|
||||
}
|
||||
});
|
||||
`;
|
||||
await NodeFSP.writeFile(wrapperPath, script, "utf8");
|
||||
await NodeFSP.chmod(wrapperPath, 0o755);
|
||||
return wrapperPath;
|
||||
}
|
||||
|
||||
async function makeProbeWrapper(
|
||||
requestLogPath: string,
|
||||
argvLogPath: string,
|
||||
@@ -130,6 +214,24 @@ function waitForJsonLogMatch(
|
||||
});
|
||||
}
|
||||
|
||||
function waitForJsonLogCount(
|
||||
filePath: string,
|
||||
predicate: (entry: Record<string, unknown>) => boolean,
|
||||
expectedCount: number,
|
||||
attempts = 40,
|
||||
) {
|
||||
return Effect.gen(function* () {
|
||||
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
||||
const entries = yield* Effect.promise(() => readJsonLines(filePath));
|
||||
if (entries.filter(predicate).length >= expectedCount) {
|
||||
return entries;
|
||||
}
|
||||
yield* Effect.yieldNow;
|
||||
}
|
||||
return yield* Effect.promise(() => readJsonLines(filePath));
|
||||
});
|
||||
}
|
||||
|
||||
// Tests mutate `ServerSettingsService` mid-flight (e.g. setting
|
||||
// `providers.cursor.binaryPath` to a mock ACP wrapper). The adapter
|
||||
// captures `cursorSettings` once at construction, so without a resolver
|
||||
@@ -1047,6 +1149,360 @@ cursorAdapterTestLayer("CursorAdapterLive", (it) => {
|
||||
yield* adapter.stopSession(threadId);
|
||||
}),
|
||||
);
|
||||
it.effect("starts a fresh turn immediately after interrupting a hanging prompt", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
const serverSettings = yield* ServerSettingsService;
|
||||
const threadId = ThreadId.make("cursor-interrupt-follow-up-thread");
|
||||
const tempDir = yield* Effect.promise(() =>
|
||||
NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "cursor-acp-")),
|
||||
);
|
||||
const requestLogPath = NodePath.join(tempDir, "requests.ndjson");
|
||||
const argvLogPath = NodePath.join(tempDir, "argv.txt");
|
||||
yield* Effect.promise(() => NodeFSP.writeFile(requestLogPath, "", "utf8"));
|
||||
const wrapperPath = yield* Effect.promise(() =>
|
||||
makeProbeWrapper(requestLogPath, argvLogPath, {
|
||||
T3_ACP_HANG_FIRST_PROMPTS: "2",
|
||||
}),
|
||||
);
|
||||
yield* serverSettings.updateSettings({
|
||||
providers: { cursor: { binaryPath: wrapperPath } },
|
||||
});
|
||||
|
||||
const events: Array<ProviderRuntimeEvent> = [];
|
||||
const firstTurnStarted = yield* Deferred.make<string>();
|
||||
const secondTurnStarted = yield* Deferred.make<string>();
|
||||
const startedCountRef = yield* Ref.make(0);
|
||||
const twoTurnsCompleted = yield* Deferred.make<void>();
|
||||
const completedCountRef = yield* Ref.make(0);
|
||||
const eventFiber = yield* Stream.runForEach(adapter.streamEvents, (event) =>
|
||||
Effect.gen(function* () {
|
||||
if (String(event.threadId) !== String(threadId)) return;
|
||||
events.push(event);
|
||||
if (event.type === "turn.started") {
|
||||
const startedCount = yield* Ref.updateAndGet(startedCountRef, (count) => count + 1);
|
||||
if (startedCount === 1) {
|
||||
yield* Deferred.succeed(firstTurnStarted, String(event.turnId)).pipe(Effect.ignore);
|
||||
}
|
||||
if (startedCount === 2) {
|
||||
yield* Deferred.succeed(secondTurnStarted, String(event.turnId)).pipe(Effect.ignore);
|
||||
}
|
||||
}
|
||||
if (event.type === "turn.completed") {
|
||||
const completedCount = yield* Ref.updateAndGet(completedCountRef, (count) => count + 1);
|
||||
if (completedCount === 2) {
|
||||
yield* Deferred.succeed(twoTurnsCompleted, undefined).pipe(Effect.ignore);
|
||||
}
|
||||
}
|
||||
}),
|
||||
).pipe(Effect.forkChild);
|
||||
|
||||
yield* adapter.startSession({
|
||||
threadId,
|
||||
provider: ProviderDriverKind.make("cursor"),
|
||||
cwd: process.cwd(),
|
||||
runtimeMode: "approval-required",
|
||||
modelSelection: {
|
||||
instanceId: ProviderInstanceId.make("cursor"),
|
||||
model: "default",
|
||||
},
|
||||
});
|
||||
const firstSendFiber = yield* adapter
|
||||
.sendTurn({ threadId, input: "hang", attachments: [] })
|
||||
.pipe(Effect.forkChild);
|
||||
const firstTurnId = yield* Deferred.await(firstTurnStarted).pipe(Effect.timeout("2 seconds"));
|
||||
yield* waitForJsonLogMatch(
|
||||
requestLogPath,
|
||||
(request) => request.method === "session/prompt",
|
||||
80,
|
||||
).pipe(Effect.timeout("2 seconds"));
|
||||
|
||||
yield* adapter.interruptTurn(threadId).pipe(Effect.timeout("2 seconds"));
|
||||
const followUpFiber = yield* adapter
|
||||
.sendTurn({ threadId, input: "follow up", attachments: [] })
|
||||
.pipe(Effect.forkChild);
|
||||
yield* waitForJsonLogCount(
|
||||
requestLogPath,
|
||||
(request) => request.method === "session/prompt",
|
||||
2,
|
||||
80,
|
||||
).pipe(Effect.timeout("2 seconds"));
|
||||
const secondTurnId = yield* Deferred.await(secondTurnStarted).pipe(
|
||||
Effect.timeout("2 seconds"),
|
||||
);
|
||||
yield* Fiber.join(firstSendFiber).pipe(Effect.timeout("2 seconds"));
|
||||
const steeredFollowUpFiber = yield* adapter
|
||||
.sendTurn({ threadId, input: "steer follow up", attachments: [] })
|
||||
.pipe(Effect.forkChild);
|
||||
for (let attempt = 0; attempt < 10; attempt += 1) {
|
||||
yield* Effect.yieldNow;
|
||||
}
|
||||
|
||||
yield* adapter.interruptTurn(threadId).pipe(Effect.timeout("2 seconds"));
|
||||
const steeredFollowUp = yield* Fiber.join(steeredFollowUpFiber).pipe(
|
||||
Effect.timeout("2 seconds"),
|
||||
);
|
||||
const followUp = yield* Fiber.join(followUpFiber).pipe(Effect.timeout("2 seconds"));
|
||||
assert.notEqual(secondTurnId, firstTurnId);
|
||||
assert.equal(String(steeredFollowUp.turnId), secondTurnId);
|
||||
yield* Deferred.await(twoTurnsCompleted).pipe(Effect.timeout("2 seconds"));
|
||||
yield* Fiber.interrupt(eventFiber);
|
||||
|
||||
assert.equal(String(followUp.turnId), secondTurnId);
|
||||
const completed = events.filter(
|
||||
(event) => String(event.threadId) === String(threadId) && event.type === "turn.completed",
|
||||
);
|
||||
assert.lengthOf(completed, 2);
|
||||
assert.equal(String(completed[0]?.turnId), firstTurnId);
|
||||
if (completed[0]?.type === "turn.completed") {
|
||||
assert.equal(completed[0].payload.state, "cancelled");
|
||||
assert.equal(completed[0].payload.stopReason, "cancelled");
|
||||
}
|
||||
assert.equal(String(completed[1]?.turnId), secondTurnId);
|
||||
if (completed[1]?.type === "turn.completed") {
|
||||
assert.equal(completed[1].payload.state, "cancelled");
|
||||
assert.equal(completed[1].payload.stopReason, "cancelled");
|
||||
}
|
||||
|
||||
const requests = yield* Effect.promise(() => readJsonLines(requestLogPath));
|
||||
assert.lengthOf(
|
||||
requests.filter((request) => request.method === "session/prompt"),
|
||||
3,
|
||||
);
|
||||
yield* adapter.stopSession(threadId);
|
||||
}).pipe(TestClock.withLive),
|
||||
);
|
||||
|
||||
it.effect("resolves a pending permission before completing a normally returned turn", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
const settings = yield* ServerSettingsService;
|
||||
const threadId = ThreadId.make("cursor-terminal-permission");
|
||||
const events: Array<ProviderRuntimeEvent> = [];
|
||||
const completed = yield* Deferred.make<void>();
|
||||
const wrapperPath = yield* Effect.promise(() => makeTerminalCallbackWrapper("permission"));
|
||||
yield* settings.updateSettings({ providers: { cursor: { binaryPath: wrapperPath } } });
|
||||
|
||||
const eventsFiber = yield* Stream.runForEach(adapter.streamEvents, (event) => {
|
||||
if (String(event.threadId) !== String(threadId)) return Effect.void;
|
||||
events.push(event);
|
||||
return event.type === "turn.completed"
|
||||
? Deferred.succeed(completed, undefined).pipe(Effect.ignore)
|
||||
: Effect.void;
|
||||
}).pipe(Effect.forkChild);
|
||||
|
||||
yield* adapter.startSession({
|
||||
threadId,
|
||||
provider: ProviderDriverKind.make("cursor"),
|
||||
cwd: process.cwd(),
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
yield* adapter.sendTurn({
|
||||
threadId,
|
||||
input: "finish without permission response",
|
||||
attachments: [],
|
||||
});
|
||||
yield* Deferred.await(completed);
|
||||
yield* Fiber.interrupt(eventsFiber);
|
||||
|
||||
const relevant = events.filter(
|
||||
(event) =>
|
||||
event.type === "request.opened" ||
|
||||
event.type === "request.resolved" ||
|
||||
event.type === "turn.completed",
|
||||
);
|
||||
assert.deepStrictEqual(
|
||||
relevant.map((event) => event.type),
|
||||
["request.opened", "request.resolved", "turn.completed"],
|
||||
);
|
||||
const resolved = relevant[1];
|
||||
assert.equal(resolved?.type, "request.resolved");
|
||||
if (resolved?.type === "request.resolved") assert.equal(resolved.payload.decision, "cancel");
|
||||
yield* adapter.stopSession(threadId);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("settles a pending callback when the terminal prompt fails", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
const settings = yield* ServerSettingsService;
|
||||
const threadId = ThreadId.make("cursor-terminal-failure");
|
||||
const events: Array<ProviderRuntimeEvent> = [];
|
||||
const requested = yield* Deferred.make<ApprovalRequestId>();
|
||||
const resolved = yield* Deferred.make<void>();
|
||||
const wrapperPath = yield* Effect.promise(() =>
|
||||
makeTerminalCallbackWrapper("permission", "failure"),
|
||||
);
|
||||
yield* settings.updateSettings({ providers: { cursor: { binaryPath: wrapperPath } } });
|
||||
|
||||
const eventsFiber = yield* Stream.runForEach(adapter.streamEvents, (event) => {
|
||||
if (String(event.threadId) !== String(threadId)) return Effect.void;
|
||||
events.push(event);
|
||||
if (event.type === "request.opened") {
|
||||
return Deferred.succeed(requested, ApprovalRequestId.make(String(event.requestId))).pipe(
|
||||
Effect.ignore,
|
||||
);
|
||||
}
|
||||
if (event.type === "request.resolved") {
|
||||
return Deferred.succeed(resolved, undefined).pipe(Effect.ignore);
|
||||
}
|
||||
return Effect.void;
|
||||
}).pipe(Effect.forkChild);
|
||||
|
||||
yield* adapter.startSession({
|
||||
threadId,
|
||||
provider: ProviderDriverKind.make("cursor"),
|
||||
cwd: process.cwd(),
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
const sendTurnFiber = yield* adapter
|
||||
.sendTurn({
|
||||
threadId,
|
||||
input: "fail with a pending permission",
|
||||
attachments: [],
|
||||
})
|
||||
.pipe(Effect.forkChild);
|
||||
|
||||
const requestId = yield* Deferred.await(requested);
|
||||
const sendTurnExit = yield* Fiber.await(sendTurnFiber);
|
||||
yield* Deferred.await(resolved);
|
||||
const lateResponseExit = yield* adapter
|
||||
.respondToRequest(threadId, requestId, "accept")
|
||||
.pipe(Effect.exit);
|
||||
assert.equal(sendTurnExit._tag, "Failure");
|
||||
assert.equal(lateResponseExit._tag, "Failure");
|
||||
assert.deepStrictEqual(
|
||||
events
|
||||
.filter(
|
||||
(event) =>
|
||||
event.type === "request.opened" ||
|
||||
event.type === "request.resolved" ||
|
||||
event.type === "turn.completed",
|
||||
)
|
||||
.map((event) => event.type),
|
||||
["request.opened", "request.resolved"],
|
||||
);
|
||||
|
||||
yield* Fiber.interrupt(eventsFiber);
|
||||
yield* adapter.stopSession(threadId);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("settles a pending callback when sendTurn is interrupted", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
const settings = yield* ServerSettingsService;
|
||||
const threadId = ThreadId.make("cursor-terminal-fiber-interruption");
|
||||
const events: Array<ProviderRuntimeEvent> = [];
|
||||
const requested = yield* Deferred.make<ApprovalRequestId>();
|
||||
const resolved = yield* Deferred.make<void>();
|
||||
const wrapperPath = yield* Effect.promise(() =>
|
||||
makeTerminalCallbackWrapper("permission", "hang"),
|
||||
);
|
||||
yield* settings.updateSettings({ providers: { cursor: { binaryPath: wrapperPath } } });
|
||||
|
||||
const eventsFiber = yield* Stream.runForEach(adapter.streamEvents, (event) => {
|
||||
if (String(event.threadId) !== String(threadId)) return Effect.void;
|
||||
events.push(event);
|
||||
if (event.type === "request.opened") {
|
||||
return Deferred.succeed(requested, ApprovalRequestId.make(String(event.requestId))).pipe(
|
||||
Effect.ignore,
|
||||
);
|
||||
}
|
||||
if (event.type === "request.resolved") {
|
||||
return Deferred.succeed(resolved, undefined).pipe(Effect.ignore);
|
||||
}
|
||||
return Effect.void;
|
||||
}).pipe(Effect.forkChild);
|
||||
|
||||
yield* adapter.startSession({
|
||||
threadId,
|
||||
provider: ProviderDriverKind.make("cursor"),
|
||||
cwd: process.cwd(),
|
||||
runtimeMode: "approval-required",
|
||||
});
|
||||
const sendTurnFiber = yield* adapter
|
||||
.sendTurn({
|
||||
threadId,
|
||||
input: "interrupt with a pending permission",
|
||||
attachments: [],
|
||||
})
|
||||
.pipe(Effect.forkChild);
|
||||
|
||||
const requestId = yield* Deferred.await(requested);
|
||||
yield* Fiber.interrupt(sendTurnFiber);
|
||||
yield* Deferred.await(resolved);
|
||||
const lateResponseExit = yield* adapter
|
||||
.respondToRequest(threadId, requestId, "accept")
|
||||
.pipe(Effect.exit);
|
||||
assert.equal(lateResponseExit._tag, "Failure");
|
||||
assert.deepStrictEqual(
|
||||
events
|
||||
.filter(
|
||||
(event) =>
|
||||
event.type === "request.opened" ||
|
||||
event.type === "request.resolved" ||
|
||||
event.type === "turn.completed",
|
||||
)
|
||||
.map((event) => event.type),
|
||||
["request.opened", "request.resolved"],
|
||||
);
|
||||
|
||||
yield* Fiber.interrupt(eventsFiber);
|
||||
yield* adapter.stopSession(threadId);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("resolves a pending question before completing a normally returned turn", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
const settings = yield* ServerSettingsService;
|
||||
const threadId = ThreadId.make("cursor-terminal-question");
|
||||
const events: Array<ProviderRuntimeEvent> = [];
|
||||
const completed = yield* Deferred.make<void>();
|
||||
const wrapperPath = yield* Effect.promise(() => makeTerminalCallbackWrapper("question"));
|
||||
yield* settings.updateSettings({ providers: { cursor: { binaryPath: wrapperPath } } });
|
||||
|
||||
const eventsFiber = yield* Stream.runForEach(adapter.streamEvents, (event) => {
|
||||
if (String(event.threadId) !== String(threadId)) return Effect.void;
|
||||
events.push(event);
|
||||
return event.type === "turn.completed"
|
||||
? Deferred.succeed(completed, undefined).pipe(Effect.ignore)
|
||||
: Effect.void;
|
||||
}).pipe(Effect.forkChild);
|
||||
|
||||
yield* adapter.startSession({
|
||||
threadId,
|
||||
provider: ProviderDriverKind.make("cursor"),
|
||||
cwd: process.cwd(),
|
||||
runtimeMode: "full-access",
|
||||
});
|
||||
yield* adapter.sendTurn({
|
||||
threadId,
|
||||
input: "finish without question response",
|
||||
attachments: [],
|
||||
});
|
||||
yield* Deferred.await(completed);
|
||||
yield* Fiber.interrupt(eventsFiber);
|
||||
|
||||
const relevant = events.filter(
|
||||
(event) =>
|
||||
event.type === "user-input.requested" ||
|
||||
event.type === "user-input.resolved" ||
|
||||
event.type === "turn.completed",
|
||||
);
|
||||
assert.deepStrictEqual(
|
||||
relevant.map((event) => event.type),
|
||||
["user-input.requested", "user-input.resolved", "turn.completed"],
|
||||
);
|
||||
const resolved = relevant[1];
|
||||
assert.equal(resolved?.type, "user-input.resolved");
|
||||
if (resolved?.type === "user-input.resolved")
|
||||
assert.deepStrictEqual(resolved.payload.answers, {});
|
||||
yield* adapter.stopSession(threadId);
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect("stopping a session settles pending approval waits", () =>
|
||||
Effect.gen(function* () {
|
||||
const adapter = yield* CursorAdapter;
|
||||
|
||||
@@ -115,11 +115,19 @@ export interface CursorAdapterLiveOptions {
|
||||
|
||||
interface PendingApproval {
|
||||
readonly decision: Deferred.Deferred<ProviderApprovalDecision>;
|
||||
readonly resolutionOffered: Deferred.Deferred<void>;
|
||||
readonly kind: string | "unknown";
|
||||
}
|
||||
|
||||
interface PendingUserInput {
|
||||
readonly answers: Deferred.Deferred<ProviderUserInputAnswers>;
|
||||
readonly resolutionOffered: Deferred.Deferred<void>;
|
||||
}
|
||||
|
||||
interface CallbackLifecycle {
|
||||
readonly semaphore: Semaphore.Semaphore;
|
||||
generation: number;
|
||||
admissionOpen: boolean;
|
||||
}
|
||||
|
||||
interface CursorSessionContext {
|
||||
@@ -137,33 +145,32 @@ interface CursorSessionContext {
|
||||
* >0 means a turn is actively running, so a new sendTurn is a steer that
|
||||
* continues it, and only the last remaining prompt settles the turn. */
|
||||
promptsInFlight: number;
|
||||
readonly callbackLifecycle: CallbackLifecycle;
|
||||
stopped: boolean;
|
||||
}
|
||||
|
||||
function settlePendingApprovalsAsCancelled(
|
||||
pendingApprovals: ReadonlyMap<ApprovalRequestId, PendingApproval>,
|
||||
function settlePendingCallbacks(
|
||||
approvals: ReadonlyArray<PendingApproval>,
|
||||
userInputs: ReadonlyArray<PendingUserInput>,
|
||||
): Effect.Effect<void> {
|
||||
const pendingEntries = Array.from(pendingApprovals.values());
|
||||
return Effect.forEach(
|
||||
pendingEntries,
|
||||
(pending) => Deferred.succeed(pending.decision, "cancel").pipe(Effect.ignore),
|
||||
{
|
||||
return Effect.gen(function* () {
|
||||
yield* Effect.forEach(
|
||||
approvals,
|
||||
(pending) => Deferred.succeed(pending.decision, "cancel").pipe(Effect.ignore),
|
||||
{ discard: true },
|
||||
);
|
||||
yield* Effect.forEach(
|
||||
userInputs,
|
||||
(pending) => Deferred.succeed(pending.answers, {}).pipe(Effect.ignore),
|
||||
{ discard: true },
|
||||
);
|
||||
yield* Effect.forEach(approvals, (pending) => Deferred.await(pending.resolutionOffered), {
|
||||
discard: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function settlePendingUserInputsAsEmptyAnswers(
|
||||
pendingUserInputs: ReadonlyMap<ApprovalRequestId, PendingUserInput>,
|
||||
): Effect.Effect<void> {
|
||||
const pendingEntries = Array.from(pendingUserInputs.values());
|
||||
return Effect.forEach(
|
||||
pendingEntries,
|
||||
(pending) => Deferred.succeed(pending.answers, {}).pipe(Effect.ignore),
|
||||
{
|
||||
});
|
||||
yield* Effect.forEach(userInputs, (pending) => Deferred.await(pending.resolutionOffered), {
|
||||
discard: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||||
@@ -458,10 +465,21 @@ export function makeCursorAdapter(
|
||||
|
||||
const stopSessionInternal = (ctx: CursorSessionContext) =>
|
||||
Effect.gen(function* () {
|
||||
if (ctx.stopped) return;
|
||||
ctx.stopped = true;
|
||||
yield* settlePendingApprovalsAsCancelled(ctx.pendingApprovals);
|
||||
yield* settlePendingUserInputsAsEmptyAnswers(ctx.pendingUserInputs);
|
||||
const shouldStop = yield* Effect.uninterruptible(
|
||||
ctx.callbackLifecycle.semaphore.withPermit(
|
||||
Effect.gen(function* () {
|
||||
if (ctx.stopped) return false;
|
||||
ctx.stopped = true;
|
||||
ctx.callbackLifecycle.admissionOpen = false;
|
||||
yield* settlePendingCallbacks(
|
||||
Array.from(ctx.pendingApprovals.values()),
|
||||
Array.from(ctx.pendingUserInputs.values()),
|
||||
);
|
||||
return true;
|
||||
}),
|
||||
),
|
||||
);
|
||||
if (!shouldStop) return;
|
||||
if (ctx.notificationFiber) {
|
||||
yield* Fiber.interrupt(ctx.notificationFiber);
|
||||
}
|
||||
@@ -505,6 +523,11 @@ export function makeCursorAdapter(
|
||||
|
||||
const pendingApprovals = new Map<ApprovalRequestId, PendingApproval>();
|
||||
const pendingUserInputs = new Map<ApprovalRequestId, PendingUserInput>();
|
||||
const callbackLifecycle: CallbackLifecycle = {
|
||||
semaphore: yield* Semaphore.make(1),
|
||||
generation: 0,
|
||||
admissionOpen: false,
|
||||
};
|
||||
const sessionScope = yield* Scope.make("sequential");
|
||||
let sessionScopeTransferred = false;
|
||||
yield* Effect.addFinalizer(() =>
|
||||
@@ -571,47 +594,77 @@ export function makeCursorAdapter(
|
||||
),
|
||||
);
|
||||
const started = yield* Effect.gen(function* () {
|
||||
yield* acp.handleExtRequest("cursor/ask_question", CursorAskQuestionRequest, (params) =>
|
||||
mapExtensionFailure(
|
||||
Effect.gen(function* () {
|
||||
yield* logNative(
|
||||
input.threadId,
|
||||
"cursor/ask_question",
|
||||
params,
|
||||
"acp.cursor.extension",
|
||||
);
|
||||
const requestId = ApprovalRequestId.make(yield* randomUUIDv4);
|
||||
const runtimeRequestId = RuntimeRequestId.make(requestId);
|
||||
const answers = yield* Deferred.make<ProviderUserInputAnswers>();
|
||||
pendingUserInputs.set(requestId, { answers });
|
||||
yield* offerRuntimeEvent({
|
||||
type: "user-input.requested",
|
||||
...(yield* makeEventStamp()),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId: ctx?.activeTurnId,
|
||||
requestId: runtimeRequestId,
|
||||
payload: { questions: extractAskQuestions(params) },
|
||||
raw: {
|
||||
source: "acp.cursor.extension",
|
||||
method: "cursor/ask_question",
|
||||
payload: params,
|
||||
},
|
||||
});
|
||||
const resolved = yield* Deferred.await(answers);
|
||||
pendingUserInputs.delete(requestId);
|
||||
yield* offerRuntimeEvent({
|
||||
type: "user-input.resolved",
|
||||
...(yield* makeEventStamp()),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId: ctx?.activeTurnId,
|
||||
requestId: runtimeRequestId,
|
||||
payload: { answers: resolved },
|
||||
});
|
||||
return { answers: resolved };
|
||||
}),
|
||||
),
|
||||
yield* acp.handleExtRequest(
|
||||
"cursor/ask_question",
|
||||
CursorAskQuestionRequest,
|
||||
(params) => {
|
||||
const callbackGeneration = callbackLifecycle.generation;
|
||||
return mapExtensionFailure(
|
||||
Effect.gen(function* () {
|
||||
yield* logNative(
|
||||
input.threadId,
|
||||
"cursor/ask_question",
|
||||
params,
|
||||
"acp.cursor.extension",
|
||||
);
|
||||
const requestId = ApprovalRequestId.make(yield* randomUUIDv4);
|
||||
const runtimeRequestId = RuntimeRequestId.make(requestId);
|
||||
const answers = yield* Deferred.make<ProviderUserInputAnswers>();
|
||||
const resolutionOffered = yield* Deferred.make<void>();
|
||||
const pending: PendingUserInput = { answers, resolutionOffered };
|
||||
return yield* Effect.gen(function* () {
|
||||
const admitted = yield* callbackLifecycle.semaphore.withPermit(
|
||||
Effect.gen(function* () {
|
||||
if (
|
||||
!callbackLifecycle.admissionOpen ||
|
||||
callbackLifecycle.generation !== callbackGeneration ||
|
||||
ctx?.stopped
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
pendingUserInputs.set(requestId, pending);
|
||||
yield* offerRuntimeEvent({
|
||||
type: "user-input.requested",
|
||||
...(yield* makeEventStamp()),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId: ctx?.activeTurnId,
|
||||
requestId: runtimeRequestId,
|
||||
payload: { questions: extractAskQuestions(params) },
|
||||
raw: {
|
||||
source: "acp.cursor.extension",
|
||||
method: "cursor/ask_question",
|
||||
payload: params,
|
||||
},
|
||||
});
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
if (!admitted) {
|
||||
return { answers: {} };
|
||||
}
|
||||
const resolved = yield* Deferred.await(answers);
|
||||
yield* offerRuntimeEvent({
|
||||
type: "user-input.resolved",
|
||||
...(yield* makeEventStamp()),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId: ctx?.activeTurnId,
|
||||
requestId: runtimeRequestId,
|
||||
payload: { answers: resolved },
|
||||
});
|
||||
return { answers: resolved };
|
||||
}).pipe(
|
||||
Effect.ensuring(
|
||||
Effect.sync(() => pendingUserInputs.delete(requestId)).pipe(
|
||||
Effect.andThen(Deferred.succeed(resolutionOffered, undefined)),
|
||||
Effect.ignore,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
);
|
||||
},
|
||||
);
|
||||
yield* acp.handleExtRequest("cursor/create_plan", CursorCreatePlanRequest, (params) =>
|
||||
mapExtensionFailure(
|
||||
@@ -663,8 +716,9 @@ export function makeCursorAdapter(
|
||||
}),
|
||||
),
|
||||
);
|
||||
yield* acp.handleRequestPermission((params) =>
|
||||
mapExtensionFailure(
|
||||
yield* acp.handleRequestPermission((params) => {
|
||||
const callbackGeneration = callbackLifecycle.generation;
|
||||
return mapExtensionFailure(
|
||||
Effect.gen(function* () {
|
||||
yield* logNative(
|
||||
input.threadId,
|
||||
@@ -675,6 +729,17 @@ export function makeCursorAdapter(
|
||||
if (input.runtimeMode === "full-access") {
|
||||
const autoApprovedOptionId = selectAutoApprovedPermissionOption(params);
|
||||
if (autoApprovedOptionId !== undefined) {
|
||||
const admitted = yield* callbackLifecycle.semaphore.withPermit(
|
||||
Effect.sync(
|
||||
() =>
|
||||
callbackLifecycle.admissionOpen &&
|
||||
callbackLifecycle.generation === callbackGeneration &&
|
||||
!ctx?.stopped,
|
||||
),
|
||||
);
|
||||
if (!admitted) {
|
||||
return { outcome: { outcome: "cancelled" as const } };
|
||||
}
|
||||
return {
|
||||
outcome: {
|
||||
outcome: "selected" as const,
|
||||
@@ -687,53 +752,79 @@ export function makeCursorAdapter(
|
||||
const requestId = ApprovalRequestId.make(yield* randomUUIDv4);
|
||||
const runtimeRequestId = RuntimeRequestId.make(requestId);
|
||||
const decision = yield* Deferred.make<ProviderApprovalDecision>();
|
||||
pendingApprovals.set(requestId, {
|
||||
const resolutionOffered = yield* Deferred.make<void>();
|
||||
const pending: PendingApproval = {
|
||||
decision,
|
||||
resolutionOffered,
|
||||
kind: permissionRequest.kind,
|
||||
});
|
||||
yield* offerRuntimeEvent(
|
||||
makeAcpRequestOpenedEvent({
|
||||
stamp: yield* makeEventStamp(),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId: ctx?.activeTurnId,
|
||||
requestId: runtimeRequestId,
|
||||
permissionRequest,
|
||||
detail:
|
||||
permissionRequest.detail ??
|
||||
encodeJsonStringForDiagnostics(params)?.slice(0, 2000) ??
|
||||
"[unserializable params]",
|
||||
args: params,
|
||||
source: "acp.jsonrpc",
|
||||
method: "session/request_permission",
|
||||
rawPayload: params,
|
||||
}),
|
||||
);
|
||||
const resolved = yield* Deferred.await(decision);
|
||||
pendingApprovals.delete(requestId);
|
||||
yield* offerRuntimeEvent(
|
||||
makeAcpRequestResolvedEvent({
|
||||
stamp: yield* makeEventStamp(),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId: ctx?.activeTurnId,
|
||||
requestId: runtimeRequestId,
|
||||
permissionRequest,
|
||||
decision: resolved,
|
||||
}),
|
||||
);
|
||||
return {
|
||||
outcome:
|
||||
resolved === "cancel"
|
||||
? ({ outcome: "cancelled" } as const)
|
||||
: {
|
||||
outcome: "selected" as const,
|
||||
optionId: acpPermissionOutcome(resolved),
|
||||
},
|
||||
};
|
||||
return yield* Effect.gen(function* () {
|
||||
const admitted = yield* callbackLifecycle.semaphore.withPermit(
|
||||
Effect.gen(function* () {
|
||||
if (
|
||||
!callbackLifecycle.admissionOpen ||
|
||||
callbackLifecycle.generation !== callbackGeneration ||
|
||||
ctx?.stopped
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
pendingApprovals.set(requestId, pending);
|
||||
yield* offerRuntimeEvent(
|
||||
makeAcpRequestOpenedEvent({
|
||||
stamp: yield* makeEventStamp(),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId: ctx?.activeTurnId,
|
||||
requestId: runtimeRequestId,
|
||||
permissionRequest,
|
||||
detail:
|
||||
permissionRequest.detail ??
|
||||
encodeJsonStringForDiagnostics(params)?.slice(0, 2000) ??
|
||||
"[unserializable params]",
|
||||
args: params,
|
||||
source: "acp.jsonrpc",
|
||||
method: "session/request_permission",
|
||||
rawPayload: params,
|
||||
}),
|
||||
);
|
||||
return true;
|
||||
}),
|
||||
);
|
||||
if (!admitted) {
|
||||
return { outcome: { outcome: "cancelled" as const } };
|
||||
}
|
||||
const resolved = yield* Deferred.await(decision);
|
||||
yield* offerRuntimeEvent(
|
||||
makeAcpRequestResolvedEvent({
|
||||
stamp: yield* makeEventStamp(),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId: ctx?.activeTurnId,
|
||||
requestId: runtimeRequestId,
|
||||
permissionRequest,
|
||||
decision: resolved,
|
||||
}),
|
||||
);
|
||||
return {
|
||||
outcome:
|
||||
resolved === "cancel"
|
||||
? ({ outcome: "cancelled" } as const)
|
||||
: {
|
||||
outcome: "selected" as const,
|
||||
optionId: acpPermissionOutcome(resolved),
|
||||
},
|
||||
};
|
||||
}).pipe(
|
||||
Effect.ensuring(
|
||||
Effect.sync(() => pendingApprovals.delete(requestId)).pipe(
|
||||
Effect.andThen(Deferred.succeed(resolutionOffered, undefined)),
|
||||
Effect.ignore,
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
);
|
||||
});
|
||||
return yield* acp.start();
|
||||
}).pipe(
|
||||
Effect.mapError((error) =>
|
||||
@@ -779,6 +870,7 @@ export function makeCursorAdapter(
|
||||
lastPlanFingerprint: undefined,
|
||||
activeTurnId: undefined,
|
||||
promptsInFlight: 0,
|
||||
callbackLifecycle,
|
||||
stopped: false,
|
||||
};
|
||||
|
||||
@@ -910,15 +1002,60 @@ export function makeCursorAdapter(
|
||||
const sendTurn: CursorAdapterShape["sendTurn"] = (input) =>
|
||||
Effect.gen(function* () {
|
||||
const ctx = yield* requireSession(input.threadId);
|
||||
// A sendTurn while a prompt is in flight is a steer: the agent folds
|
||||
// the new prompt into the ongoing work, so the active turn id is
|
||||
// reused instead of opening a new turn.
|
||||
const steeringTurnId = ctx.promptsInFlight > 0 ? ctx.activeTurnId : undefined;
|
||||
const turnId = steeringTurnId ?? TurnId.make(yield* randomUUIDv4);
|
||||
// Count this prompt immediately so a superseded in-flight prompt
|
||||
// resolving from here on does not settle the turn; the matching
|
||||
// decrement is the `ensuring` below.
|
||||
ctx.promptsInFlight += 1;
|
||||
const candidateTurnId = TurnId.make(yield* randomUUIDv4);
|
||||
const admission = yield* ctx.callbackLifecycle.semaphore.withPermit(
|
||||
Effect.gen(function* () {
|
||||
if (ctx.stopped) {
|
||||
return yield* new ProviderAdapterSessionNotFoundError({
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
});
|
||||
}
|
||||
// A prompt sent while another is in flight steers the active turn.
|
||||
const startsTurn = ctx.promptsInFlight === 0;
|
||||
if (startsTurn) {
|
||||
ctx.callbackLifecycle.generation += 1;
|
||||
ctx.callbackLifecycle.admissionOpen = true;
|
||||
ctx.activeTurnId = candidateTurnId;
|
||||
ctx.lastPlanFingerprint = undefined;
|
||||
}
|
||||
// Count it immediately so an older prompt cannot settle the shared turn.
|
||||
ctx.promptsInFlight += 1;
|
||||
return {
|
||||
generation: ctx.callbackLifecycle.generation,
|
||||
startsTurn,
|
||||
turnId: ctx.activeTurnId ?? candidateTurnId,
|
||||
};
|
||||
}),
|
||||
);
|
||||
const { generation, startsTurn, turnId } = admission;
|
||||
let promptFinalized = false;
|
||||
|
||||
const finalizePrompt = (
|
||||
onLastPrompt?: () => Effect.Effect<void, ProviderAdapterRequestError>,
|
||||
): Effect.Effect<boolean, ProviderAdapterRequestError> =>
|
||||
Effect.uninterruptible(
|
||||
ctx.callbackLifecycle.semaphore.withPermit(
|
||||
Effect.gen(function* () {
|
||||
if (promptFinalized) return false;
|
||||
promptFinalized = true;
|
||||
if (ctx.callbackLifecycle.generation !== generation) return false;
|
||||
ctx.promptsInFlight = Math.max(0, ctx.promptsInFlight - 1);
|
||||
// Only the final prompt for this generation may settle and complete the turn.
|
||||
if (ctx.promptsInFlight !== 0) return false;
|
||||
|
||||
ctx.callbackLifecycle.admissionOpen = false;
|
||||
yield* settlePendingCallbacks(
|
||||
Array.from(ctx.pendingApprovals.values()),
|
||||
Array.from(ctx.pendingUserInputs.values()),
|
||||
);
|
||||
if (!ctx.stopped && onLastPrompt) {
|
||||
yield* onLastPrompt();
|
||||
}
|
||||
return true;
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
return yield* Effect.gen(function* () {
|
||||
const turnModelSelection =
|
||||
@@ -939,17 +1076,13 @@ export function makeCursorAdapter(
|
||||
mapError: ({ cause, method }) =>
|
||||
mapAcpToAdapterError(PROVIDER, input.threadId, method, cause),
|
||||
});
|
||||
ctx.activeTurnId = turnId;
|
||||
if (steeringTurnId === undefined) {
|
||||
ctx.lastPlanFingerprint = undefined;
|
||||
}
|
||||
ctx.session = {
|
||||
...ctx.session,
|
||||
activeTurnId: turnId,
|
||||
updatedAt: yield* nowIso,
|
||||
};
|
||||
|
||||
if (steeringTurnId === undefined) {
|
||||
if (startsTurn) {
|
||||
yield* offerRuntimeEvent({
|
||||
type: "turn.started",
|
||||
...(yield* makeEventStamp()),
|
||||
@@ -1027,42 +1160,53 @@ export function makeCursorAdapter(
|
||||
model: resolvedModel,
|
||||
};
|
||||
|
||||
// Only the last remaining prompt settles the turn — a steer-
|
||||
// superseded prompt resolving (usually cancelled) while another is
|
||||
// in flight or pending must leave the merged turn running.
|
||||
if (ctx.promptsInFlight === 1) {
|
||||
yield* offerRuntimeEvent({
|
||||
type: "turn.completed",
|
||||
...(yield* makeEventStamp()),
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId,
|
||||
payload: {
|
||||
state: result.stopReason === "cancelled" ? "cancelled" : "completed",
|
||||
stopReason: result.stopReason ?? null,
|
||||
},
|
||||
});
|
||||
}
|
||||
yield* finalizePrompt(() =>
|
||||
makeEventStamp().pipe(
|
||||
Effect.flatMap((stamp) =>
|
||||
offerRuntimeEvent({
|
||||
type: "turn.completed",
|
||||
...stamp,
|
||||
provider: PROVIDER,
|
||||
threadId: input.threadId,
|
||||
turnId,
|
||||
payload: {
|
||||
state: result.stopReason === "cancelled" ? "cancelled" : "completed",
|
||||
stopReason: result.stopReason ?? null,
|
||||
},
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return {
|
||||
threadId: input.threadId,
|
||||
turnId,
|
||||
resumeCursor: ctx.session.resumeCursor,
|
||||
};
|
||||
}).pipe(
|
||||
Effect.ensuring(
|
||||
Effect.sync(() => {
|
||||
ctx.promptsInFlight = Math.max(0, ctx.promptsInFlight - 1);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}).pipe(Effect.ensuring(finalizePrompt().pipe(Effect.ignore)));
|
||||
});
|
||||
|
||||
const interruptTurn: CursorAdapterShape["interruptTurn"] = (threadId) =>
|
||||
Effect.gen(function* () {
|
||||
const ctx = yield* requireSession(threadId);
|
||||
yield* settlePendingApprovalsAsCancelled(ctx.pendingApprovals);
|
||||
yield* settlePendingUserInputsAsEmptyAnswers(ctx.pendingUserInputs);
|
||||
const interruptedTurnId = yield* Effect.uninterruptible(
|
||||
ctx.callbackLifecycle.semaphore.withPermit(
|
||||
Effect.gen(function* () {
|
||||
const turnId = ctx.promptsInFlight > 0 ? ctx.activeTurnId : undefined;
|
||||
ctx.callbackLifecycle.admissionOpen = false;
|
||||
yield* settlePendingCallbacks(
|
||||
Array.from(ctx.pendingApprovals.values()),
|
||||
Array.from(ctx.pendingUserInputs.values()),
|
||||
);
|
||||
if (turnId) {
|
||||
ctx.promptsInFlight = 0;
|
||||
ctx.callbackLifecycle.generation += 1;
|
||||
ctx.lastPlanFingerprint = undefined;
|
||||
}
|
||||
return turnId;
|
||||
}),
|
||||
),
|
||||
);
|
||||
yield* Effect.ignore(
|
||||
ctx.acp.cancel.pipe(
|
||||
Effect.mapError((error) =>
|
||||
@@ -1070,6 +1214,20 @@ export function makeCursorAdapter(
|
||||
),
|
||||
),
|
||||
);
|
||||
if (interruptedTurnId && !ctx.stopped) {
|
||||
yield* makeEventStamp().pipe(
|
||||
Effect.flatMap((stamp) =>
|
||||
offerRuntimeEvent({
|
||||
type: "turn.completed",
|
||||
...stamp,
|
||||
provider: PROVIDER,
|
||||
threadId,
|
||||
turnId: interruptedTurnId,
|
||||
payload: { state: "cancelled", stopReason: "cancelled" },
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const respondToRequest: CursorAdapterShape["respondToRequest"] = (
|
||||
@@ -1087,7 +1245,14 @@ export function makeCursorAdapter(
|
||||
detail: `Unknown pending approval request: ${requestId}`,
|
||||
});
|
||||
}
|
||||
yield* Deferred.succeed(pending.decision, decision);
|
||||
const accepted = yield* Deferred.succeed(pending.decision, decision);
|
||||
if (!accepted) {
|
||||
return yield* new ProviderAdapterRequestError({
|
||||
provider: PROVIDER,
|
||||
method: "session/request_permission",
|
||||
detail: `Approval request is no longer pending: ${requestId}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const respondToUserInput: CursorAdapterShape["respondToUserInput"] = (
|
||||
@@ -1105,7 +1270,14 @@ export function makeCursorAdapter(
|
||||
detail: `Unknown pending user-input request: ${requestId}`,
|
||||
});
|
||||
}
|
||||
yield* Deferred.succeed(pending.answers, answers);
|
||||
const accepted = yield* Deferred.succeed(pending.answers, answers);
|
||||
if (!accepted) {
|
||||
return yield* new ProviderAdapterRequestError({
|
||||
provider: PROVIDER,
|
||||
method: "cursor/ask_question",
|
||||
detail: `User-input request is no longer pending: ${requestId}`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const readThread: CursorAdapterShape["readThread"] = (threadId) =>
|
||||
|
||||
Reference in new issue
Block a user