Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5f00c88
fix(cursor): background commands survive the turn and wake the agent …
Yash-Singh1 Nov 17, 2026
658b224
Merge remote-tracking branch 'origin/main' into t3/fix-daisydisk-reso…
Yash-Singh1 Nov 17, 2026
909508c
Merge remote-tracking branch 'origin/main' into t3/cursor-background-…
Yash-Singh1 Nov 17, 2026
ae74a31
fix(cursor): rollback resets the background-wait instruction flag
Yash-Singh1 Nov 17, 2026
41dda7f
chore(cursor): update @cursor/sdk to 1.4.1
Yash-Singh1 Nov 18, 2026
337a9f4
Merge remote-tracking branch 'origin/main' into t3/cursor-background-…
juliusmarminge Nov 18, 2026
1678ae9
fix(cursor): release the background-shell listener when a Cursor agen…
juliusmarminge Nov 18, 2026
bd67e50
fix(cursor): background shells keep the session loaded and a Stop rea…
juliusmarminge Nov 18, 2026
ab8457e
fix(cursor): a shell that exits after the agent's turn ends still wak…
juliusmarminge Nov 18, 2026
e7a971c
fix(cursor): rolling back stops background commands the discarded run…
Yash-Singh1 Nov 18, 2026
d9ba637
Merge remote-tracking branch 'origin/main' into t3/cursor-background-…
Yash-Singh1 Nov 18, 2026
52c3d96
fix(cursor): a Stop or rollback drops background-command wakes still …
Yash-Singh1 Nov 18, 2026
6dc806e
Merge remote-tracking branch 'origin/main' into t3/cursor-background-…
Yash-Singh1 Nov 19, 2026
b684524
Merge remote-tracking branch 'origin/main' into t3/cursor-background-…
Yash-Singh1 Nov 20, 2026
40f6af4
test(server): the background-wait tool test runs with the background-…
Yash-Singh1 Nov 20, 2026
015484f
Merge remote-tracking branch 'origin/main' into t3/cursor-background-…
Yash-Singh1 Nov 20, 2026
4c2dac8
test(server): type the background-wait test's capability set
Yash-Singh1 Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"dependencies": {
"@anthropic-ai/claude-agent-sdk": "^0.3.321",
"@cursor/sdk": "1.3.1",
"@cursor/sdk": "1.4.1",
"@effect/platform-node": "catalog:",
"@effect/platform-node-shared": "catalog:",
"@ff-labs/fff-node": "0.11.0",
Expand Down
10 changes: 10 additions & 0 deletions apps/server/src/mcp/McpInvocationContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const ALL_MCP_CAPABILITIES = [
"device",
"pull-requests",
"issues",
"background-wait",
] as const;
export type McpCapability = (typeof ALL_MCP_CAPABILITIES)[number];

Expand Down Expand Up @@ -203,6 +204,15 @@ export const hiddenFromOutsideClients = (): boolean => {
return scope === undefined || scope.thread !== undefined;
};

/** `hiddenFromOutsideClients`, and hidden from a thread whose provider cannot hold for background work. */
export const hiddenWithoutBackgroundWait = (): boolean => {
const fiber = Fiber.getCurrent();
const scope = fiber && Context.getOrUndefined(fiber.context, McpInvocationContext);
return (
scope === undefined || (scope.thread !== undefined && scope.capabilities.has("background-wait"))
);
};

/** `McpSchema.EnabledWhen` for tools that only serve links, hidden while the beta is off. */
export const hiddenWhileLinksOff = (): boolean => {
const fiber = Fiber.getCurrent();
Expand Down
8 changes: 6 additions & 2 deletions apps/server/src/mcp/McpToolAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ const linksUnavailable = new OrchestratorMcpFailure({
message: "This environment cannot reach linked environments.",
});

const THREAD_ONLY = new Set<unknown>([
McpInvocationContext.hiddenFromOutsideClients,
McpInvocationContext.hiddenWithoutBackgroundWait,
]);

/**
* Every tool that takes a linked environment runs there the same way: its
* declaration checks the caller here, and the same call goes to the other
Expand All @@ -434,8 +439,7 @@ const routed = Effect.fn("McpToolAccess.routed")(function* <Tools extends Record
const remote = remoteCheckOf(declaration);
if (
remote === undefined &&
Context.getOrUndefined(tool.annotations, McpSchema.EnabledWhen) !==
McpInvocationContext.hiddenFromOutsideClients
!THREAD_ONLY.has(Context.getOrUndefined(tool.annotations, McpSchema.EnabledWhen))
)
return yield* Effect.die(
`${name} acts as its calling thread, so outside clients must not be offered it.`,
Expand Down
8 changes: 7 additions & 1 deletion apps/server/src/mcp/toolkits/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,13 @@ it.effect(
const result = yield* server
.callTool({ name: "t3_background_wait", arguments: { taskIds: ["checks"] } })
.pipe(
Effect.provideService(McpInvocationContext.McpInvocationContext, scope),
Effect.provideService(McpInvocationContext.McpInvocationContext, {
...scope,
capabilities: new Set<McpInvocationContext.McpCapability>([
"orchestration",
"background-wait",
]),
}),
Effect.provideService(McpSchema.McpServerClient, client),
);
expect(result.structuredContent).toEqual({ matched: ["checks"], unmatched: [] });
Expand Down
4 changes: 2 additions & 2 deletions apps/server/src/mcp/toolkits/orchestrator/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const WorkflowStopTool = Tool.make("t3_workflow_stop", {

const BackgroundWaitTool = Tool.make("t3_background_wait", {
description:
"Keep this thread in Working while background work runs. Pass its task ID once started. Not for work left running (dev server, watcher). `waiting=false` clears. Doesn't stop tasks. Claude/OpenCode only.",
"Keep this thread in Working while background work runs. Pass its task ID once started. Not for work left running (dev server, watcher). `waiting=false` clears. Doesn't stop tasks.",
parameters: Schema.Struct({
taskIds: Schema.Array(TrimmedNonEmptyString).check(
Schema.isMinLength(1),
Expand All @@ -165,7 +165,7 @@ const BackgroundWaitTool = Tool.make("t3_background_wait", {
// Only marks which tasks keep the thread Working; Claude Plan mode blocks tools without this.
.annotate(Tool.Readonly, true)
.annotate(Tool.Destructive, false)
.annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenFromOutsideClients);
.annotate(McpSchema.EnabledWhen, McpInvocationContext.hiddenWithoutBackgroundWait);
Comment thread
Yash-Singh1 marked this conversation as resolved.
Resolved

const ScheduleTaskTool = Tool.make("schedule_task", {
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ export const ClaudeProviderCapabilitiesV2 = {
emitsToolOutput: true,
supportsMcpTools: true,
supportsDynamicToolCallbacks: true,
supportsBackgroundWait: true,
},
approvals: {
supportsCommandApproval: true,
Expand Down
11 changes: 11 additions & 0 deletions apps/server/src/orchestration-v2/ProviderSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,14 @@ export const layerWithOptions = (
>(["orchestration", "worktree", "pull-requests", "issues"]);
if (browserToolsAvailable) capabilities.add("preview");
if (deviceToolsAvailable) capabilities.add("device");
const backgroundWait = yield* registry.get(providerInstanceId).pipe(
Effect.flatMap((adapter) => adapter.getCapabilities()),
Effect.map((adapter) => adapter.tools.supportsBackgroundWait === true),
Effect.option,
);
if (Option.getOrElse(backgroundWait, () => false)) {
capabilities.add("background-wait");
}
const subagent = yield* projectionStore.getThread(threadId).pipe(
Effect.map((thread) => thread.lineage.relationshipToParent === "subagent"),
Effect.orElseSucceed(() => false),
Expand All @@ -607,6 +615,9 @@ export const layerWithOptions = (
resolved.thread.providerInstanceId === providerInstanceId &&
resolved.capabilities.has("preview") === browserToolsAvailable &&
resolved.capabilities.has("device") === deviceToolsAvailable &&
// A failed capability read cannot tell that the live credential is wrong.
(Option.isNone(backgroundWait) ||
resolved.capabilities.has("background-wait") === backgroundWait.value) &&
// A credential issued while the lineage read failed is replaced once it works.
(resolved.thread.subagent === true) === subagent
) {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/provider/agentContextBudget.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 6245,
"codexAdditionalContextBytes": 7639,
"mcpToolListJsonBytes": 57321
"mcpToolListJsonBytes": 57299
}
2 changes: 1 addition & 1 deletion evals/mcp-tool-use/backgroundWait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const makeBackgroundWait = Effect.fn("evaluateMcpToolUse.makeBackgroundWa
requestNamespace: "mcp-tool-use-eval",
thread: { threadId, providerSessionId: "mcp-tool-use-eval", providerInstanceId },
client: undefined,
capabilities: new Set<McpInvocationContext.McpCapability>(["orchestration"]),
capabilities: new Set<McpInvocationContext.McpCapability>(["orchestration", "background-wait"]),
issuedAt: 0,
};
const request = McpSchema.McpRequestContext.of({
Expand Down
2 changes: 2 additions & 0 deletions packages/contracts/src/orchestrationV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ export const OrchestrationV2ToolCapabilities = Schema.Struct({
emitsToolOutput: Schema.Boolean,
supportsMcpTools: Schema.Boolean,
supportsDynamicToolCallbacks: Schema.Boolean,
/** The agent can mark background work it resumes from, so the thread holds as waiting. */
supportsBackgroundWait: Schema.optional(Schema.Boolean),
});
export type OrchestrationV2ToolCapabilities = typeof OrchestrationV2ToolCapabilities.Type;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ describe("T3 device instructions", () => {
assert.include(laterRun(false), T3_CODE_DEVICE_TOOL_INSTRUCTIONS);
assert.notInclude(laterRun(false), T3_CODE_ORCHESTRATION_INSTRUCTIONS.trim());
assert.equal(laterRun(true), "Check the login screen.");

// A provider's own guidance reaches a conversation that already had the rest.
const providerRun = (providerInstructionsDelivered: boolean) =>
t3OrchestrationPrompt({
prompt: "Check the login screen.",
hasT3Mcp: true,
hasDeviceTools: false,
orchestrationDelivered: true,
deviceInstructionsDelivered: false,
providerInstructions: "Mark awaited shells.",
providerInstructionsDelivered,
});
assert.include(providerRun(false), "Mark awaited shells.");
assert.notInclude(providerRun(false), T3_CODE_ORCHESTRATION_INSTRUCTIONS.trim());
assert.equal(providerRun(true), "Check the login screen.");
});

it("reach ACP agents again when device access changes mid-thread", () => {
Expand Down
23 changes: 14 additions & 9 deletions packages/provider-core/src/server/orchestrationInstructions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,22 @@ export function t3OrchestrationPrompt(input: {
readonly hasDeviceTools: boolean;
readonly orchestrationDelivered: boolean;
readonly deviceInstructionsDelivered: boolean;
/** Guidance for this provider's own tools, sent until `providerInstructionsDelivered`. */
readonly providerInstructions?: string;
readonly providerInstructionsDelivered?: boolean;
}): string {
if (!input.hasT3Mcp) return input.prompt;
if (!input.orchestrationDelivered) {
return prependT3OrchestrationInstructions(
input.prompt,
orchestrationInstructions(input.hasDeviceTools),
);
}
return input.hasDeviceTools && !input.deviceInstructionsDelivered
? prependT3OrchestrationInstructions(input.prompt, T3_CODE_DEVICE_TOOL_INSTRUCTIONS)
: input.prompt;
const instructions = [
!input.orchestrationDelivered
? orchestrationInstructions(input.hasDeviceTools)
: input.hasDeviceTools && !input.deviceInstructionsDelivered
? T3_CODE_DEVICE_TOOL_INSTRUCTIONS
: undefined,
input.providerInstructionsDelivered === true ? undefined : input.providerInstructions,
].flatMap((part) => (part === undefined ? [] : [part.trim()]));
return instructions.length === 0
? input.prompt
: prependT3OrchestrationInstructions(input.prompt, instructions.join("\n\n"));
}

export function t3OrchestrationSystemPrompt(
Expand Down
2 changes: 1 addition & 1 deletion packages/provider-cursor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"test": "vp test run --config ../../vite.config.ts --dir ."
},
"dependencies": {
"@cursor/sdk": "1.3.1",
"@cursor/sdk": "1.4.1",
"@t3tools/contracts": "workspace:*",
"@t3tools/provider-core": "workspace:*",
"@t3tools/shared": "workspace:*",
Expand Down
78 changes: 78 additions & 0 deletions packages/provider-cursor/src/server/CursorAgentSdk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ListRunsOptions } from "@cursor/sdk";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { assert, describe, it } from "@effect/vitest";
import { ProviderSessionId, ThreadId } from "@t3tools/contracts";
import * as Deferred from "effect/Deferred";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
Expand Down Expand Up @@ -400,6 +401,83 @@ describe("CursorAgentSdkRunner", () => {
}).pipe(Effect.provide(layerTest)),
);

it.effect("keeps an agent's background shells and reports each start and end in order", () =>
Effect.gen(function* () {
const start = (conversationId: string, id: number) => {
let complete: (completion: object) => void = () => {};
const abort = vi.fn();
const kept: unknown = (
Reflect.get(globalThis, Symbol.for("@cursor/sdk.backgroundShell")) as Function
)({
conversationId,
command: "sleep 60",
shell: {
id,
pid: id + 1,
abort,
onComplete: (listener: typeof complete) => (complete = listener),
},
});
return { kept, abort, complete: (completion: object) => complete(completion) };
};
const events: Array<object> = [];
const stops: Array<() => void> = [];
const reported = yield* Deferred.make<void>();
const runner = yield* CursorAgentSdk.CursorAgentSdkRunner;
const session = yield* runner.open({
operation: "create",
options: {},
threadId: ThreadId.make("thread-cursor-agent-sdk-background"),
providerSessionId: ProviderSessionId.make("provider-session-cursor-agent-sdk-background"),
});
const run = yield* session.send({
message: "watch it",
onBackgroundShell: (event) =>
Effect.gen(function* () {
if (event.type === "started") {
const { stop, ...started } = event;
stops.push(stop);
events.push(started);
return;
}
events.push(event);
if (!event.stopped) yield* Deferred.succeed(reported, undefined);
}),
});
yield* run.wait;

const killed = start("agent-cursor-agent-sdk-test", 10);
const finished = start("agent-cursor-agent-sdk-test", 20);
const foreign = start("agent-someone-else", 30);
killed.complete({ code: null, aborted: true });
finished.complete({ code: 3, aborted: false, outputPath: "/terminals/20.txt" });
yield* Deferred.await(reported);
stops[0]!();

assert.deepStrictEqual([killed.kept, finished.kept, foreign.kept], [true, true, false]);
assert.strictEqual(killed.abort.mock.calls.length, 1);
const shell = (id: string, pid: number) => ({ id, pid, command: "sleep 60" });
assert.deepStrictEqual(events, [
{ ...shell("10", 11), type: "started" },
{ ...shell("20", 21), type: "started" },
{
...shell("10", 11),
type: "ended",
stopped: true,
exitCode: undefined,
outputPath: undefined,
},
{
...shell("20", 21),
type: "ended",
stopped: false,
exitCode: 3,
outputPath: "/terminals/20.txt",
},
]);
}).pipe(Effect.provide(layerTest)),
);

it.effect("forwards Run.steer and reports a missing method as a follow-up", () =>
Effect.gen(function* () {
cursorSdkMock.runSteer.mockClear();
Expand Down
Loading
Loading