Skip to content
Source
Sign inSign up
pingdotgg/t3code

Add ACP support with Cursor provider #1355

Mergedjuliusmarmingemerged 101 commits intomain fromrefs/pull/1355/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

  • Adds Cursor as a first-class provider with ACP session lifecycle support, health checks, and adapter wiring in the server.
  • Implements Cursor model selection, including fast/plan mode mapping and session restart behavior when model options change.
  • Preserves provider/thread model state through orchestration, projection, and turn dispatch paths.
  • Updates the web app to surface Cursor traits, provider/model selection, and session drafting behavior.
  • Expands runtime ingestion so completed tool events retain structured tool metadata.

Testing

  • bun fmt
  • bun lint
  • bun typecheck
  • Added and updated tests across server, contracts, shared, and web layers for Cursor adapter behavior, orchestration routing, session model changes, and UI state handling.
  • Not run: bun run test

Note

High Risk High risk because it introduces a new Cursor ACP provider/agent integration and significantly changes orchestration/runtime-ingestion behavior around turn starts, tool/approval boundaries, and assistant message buffering/segmentation.

Overview Adds Cursor as a first-class provider using ACP (stdio JSON-RPC), including a new CursorTextGenerationLive path for git text generation that spawns an ACP runtime, applies ACP-configured model options, and tolerates noisy JSON responses.

Extends server orchestration to route text generation to Cursor and refines provider turn start handling to better surface/record start failures without crashing. Runtime ingestion is reworked to segment assistant messages across approval/user-input boundaries, flush buffered text deterministically, avoid whitespace-only artifacts/duplicate completions, and preserve structured tool-call metadata for completed tool activities.

Also updates Claude model-id resolution to use provider-specific resolveClaudeApiModelId, raises the checkpoint diff git output cap, and adds effect-acp wiring/build config so ACP code can be bundled and tested.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit aa696b5d2a0ec36b91ed7a8f4874d2f9c34aafc7. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add Cursor as a provider with ACP-backed sessions, text generation, and UI support

  • Introduces a new effect-acp workspace package implementing a typed JSON-RPC client/agent transport over stdio, matching the ACP protocol (v0.11.3), with schema-generated types and Effect-native error handling.
  • Adds CursorAdapterLive and CursorProviderLive server layers that launch the Cursor ACP agent subprocess, manage session lifecycle (start, send, interrupt, approve, stop), discover models/capabilities, and stream provider snapshots.
  • Extends contracts (ProviderKind, ModelSelection, ProviderModelOptions, ServerSettings) and shared utilities to include Cursor-specific types: CursorModelOptions, CursorModelSelection, CursorSettings, and CursorSettingsPatch.
  • Wires Cursor into the composer UI: model picker, TraitsPicker (fast mode, reasoning, context window), settings panel with 'Early Access' badge, and composerProviderRegistry.
  • Adds CursorTextGenerationLive for ACP-backed git text generation (commit messages, PR content, branch names, thread titles) with a 180s timeout and JSON extraction.
  • Improves ProviderRuntimeIngestion with segment-aware assistant message streaming, buffered flush on pause events, and suppression of empty completions.
  • Improves ProviderCommandReactor turn-start failure handling: sets lastError on the thread session, appends a provider.turn.start.failed activity, and forks the send with recovery logging.
  • Risk: ProviderSessionModelSwitchMode removes the 'restart-session' value; any persisted or in-flight state using that string will no longer match the type union.
Macroscope summarized aa696b5.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: c2d0780d-752d-49d8-b364-1135b6096558

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/greeting`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. Cursor Bugbot has reviewed your changes and found 2 potential issues.

      Autofix Details

      Bugbot Autofix prepared fixes for both issues found in the latest run.

      • ✅ Fixed: Merge never clears cached provider model options
        • Replaced ?? fallback with key in incoming check so explicitly-present-but-undefined provider keys now clear cached values, and added cache deletion when merge produces undefined.
      • ✅ Fixed: Mock agent test uses strict equal with extra fields
        • Changed toEqual to toMatchObject so the assertion tolerates the extra modes field returned by the mock agent.

      Create PR

      Or push these changes by commenting:

      @cursor push beb68c40d7
      Preview (pingdotgg/t3code@beb68c40d7)
      diff --git a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
      --- a/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
      +++ b/apps/server/src/orchestration/Layers/ProviderCommandReactor.ts
      @@ -50,20 +50,17 @@
         cached: ProviderModelOptions | undefined,
         incoming: ProviderModelOptions | undefined,
       ): ProviderModelOptions | undefined {
      -  if (!cached && !incoming) {
      -    return undefined;
      +  if (incoming === undefined) return cached;
      +  if (cached === undefined) return incoming;
      +
      +  const providerKeys = ["codex", "claudeAgent", "cursor"] as const;
      +  const next: Record<string, unknown> = {};
      +  for (const key of providerKeys) {
      +    const value = key in incoming ? incoming[key] : cached[key];
      +    if (value !== undefined) {
      +      next[key] = value;
      +    }
         }
      -  const next = {
      -    ...(incoming?.codex !== undefined || cached?.codex !== undefined
      -      ? { codex: incoming?.codex ?? cached?.codex }
      -      : {}),
      -    ...(incoming?.claudeAgent !== undefined || cached?.claudeAgent !== undefined
      -      ? { claudeAgent: incoming?.claudeAgent ?? cached?.claudeAgent }
      -      : {}),
      -    ...(incoming?.cursor !== undefined || cached?.cursor !== undefined
      -      ? { cursor: incoming?.cursor ?? cached?.cursor }
      -      : {}),
      -  } satisfies Partial<ProviderModelOptions>;
         return Object.keys(next).length > 0 ? (next as ProviderModelOptions) : undefined;
       }
       
      @@ -405,8 +402,12 @@
             threadModelOptions.get(input.threadId),
             input.modelOptions,
           );
      -    if (mergedModelOptions !== undefined) {
      -      threadModelOptions.set(input.threadId, mergedModelOptions);
      +    if (input.modelOptions !== undefined) {
      +      if (mergedModelOptions !== undefined) {
      +        threadModelOptions.set(input.threadId, mergedModelOptions);
      +      } else {
      +        threadModelOptions.delete(input.threadId);
      +      }
           }
           const normalizedInput = toNonEmptyProviderInput(input.messageText);
           const normalizedAttachments = input.attachments ?? [];
      
      diff --git a/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts b/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
      --- a/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
      +++ b/apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts
      @@ -32,7 +32,7 @@
               cwd: process.cwd(),
               mcpServers: [],
             });
      -      expect(newResult).toEqual({ sessionId: "mock-session-1" });
      +      expect(newResult).toMatchObject({ sessionId: "mock-session-1" });
       
             const promptResult = yield* conn.request("session/prompt", {
               sessionId: "mock-session-1",
      apps/server/src/provider/acp/AcpJsonRpcConnection.test.ts line 35OutdatedResolvedby juliusmarminge
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/e1f8939c6985217de23c4dc4106e0f217e4f8fbb/apps/web/src/components/chat/CompactComposerControlsMenu.browser.tsx#L254

      The test assertions at lines 255-256 expect "Reasoning" and "Fast mode", but TraitsMenuContent renders the section header as "Effort" (not "Reasoning") and uses "Fast Mode" with a capital M. These mismatches cause the test to fail even when the component renders correctly. Consider aligning the expected strings with the actual rendered text.

      ✅ Resolved in c029bac8e1b7a1bae46f0fdd8478dc7312d0cff9

    5. @@ -0,0 +198,21 @@
      198+ {
      199+ _tag: "Fail",
      200+ error: error.toProtocolError(),
      201+ },
      202+ ],
      203+ },
      204+ });
      205+
      206+ const handleExtRequest = (message: RpcMessage.RequestEncoded) => {
      207+ if (!options.onExtRequest) {
      208+ return respondWithError(message.id, AcpError.AcpRequestError.methodNotFound(message.tag));
      209+ }
      210+ return options.onExtRequest(message.tag, message.payload).pipe(
      211+ Effect.matchEffect({
      212+ onFailure: (error) => respondWithError(message.id, normalizeToRequestError(error)),
      213+ onSuccess: (value) => respondWithSuccess(message.id, value),
      214+ }),
      215+ );
      216+ };
      217+
      218+ const handleRequestEncoded = (message: RpcMessage.RequestEncoded) => {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium src/protocol.ts:218

      Malformed session/update or session/elicitation_complete notification payloads terminate the entire protocol connection instead of being logged and skipped. When decodeSessionUpdate (line 221) or decodeElicitationComplete (line 241) fails, the AcpProtocolParseError propagates through Effect.forEach (line 373), causing Stream.runForEach (line 336) to fail and trigger the Effect.catch block (line 379) that ends stdin processing. Extension notifications (lines 260-264) are dispatched without validation and survive malformed payloads, but these known notification types tear down the connection due to a single bad message. Consider catching and logging the parse error for known notification types instead of letting them propagate, similar to how Effect.tapErrorTag (line 362) handles logging for the general case.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file packages/effect-acp/src/protocol.ts around line 218:
      
      Malformed `session/update` or `session/elicitation_complete` notification payloads terminate the entire protocol connection instead of being logged and skipped. When `decodeSessionUpdate` (line 221) or `decodeElicitationComplete` (line 241) fails, the `AcpProtocolParseError` propagates through `Effect.forEach` (line 373), causing `Stream.runForEach` (line 336) to fail and trigger the `Effect.catch` block (line 379) that ends stdin processing. Extension notifications (lines 260-264) are dispatched without validation and survive malformed payloads, but these known notification types tear down the connection due to a single bad message. Consider catching and logging the parse error for known notification types instead of letting them propagate, similar to how `Effect.tapErrorTag` (line 362) handles logging for the general case.
      
      Evidence trail:
      packages/effect-acp/src/protocol.ts lines 211-255 (handleRequestEncoded - session_update decode at 211-232 with Effect.mapError creating AcpProtocolParseError, elicitation_complete at 234-250 similarly, extension notifications at 251-255 with no validation), line 373 (Effect.forEach with routeDecodedMessage that propagates errors), lines 336-378 (Stream.runForEach on stdin with Effect.tapErrorTag that only logs but doesn't catch), lines 379-393 (Effect.catch that posts ClientProtocolError ending processing)
    6. juliusmarminge changed the title

    7. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟢 Low

      https://github.com/pingdotgg/t3code/blob/981aeba768271dc4353f7f3e79b72879a7dbaf01/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts#L566

      When the reactor's scope is closed during shutdown, the forked sendTurn fiber is interrupted. Effect.catchCause(handleTurnStartFailure) catches this interrupt cause and invokes handleTurnStartFailure, which sets the session's lastError to a rendered interrupt message and changes its status to "ready". This produces misleading session error states during graceful shutdown—sessions that were running fine get marked with interrupt-related errors. Consider filtering out interrupt-only causes in handleTurnStartFailure so shutdown interruptions don't get recorded as session errors.

      ✅ Resolved in e78ff4355992f8c17fc2c2ac9c7f7b9ce72ea055

    8. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium

      https://github.com/pingdotgg/t3code/blob/8e6fc4c9e93cbfc6b7ddb2365c50c6373510ee48/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts#L16

      When providerService.sendTurn fails, handleTurnStartFailure is now forked via Effect.forkScoped instead of being awaited. If handleTurnStartFailure itself fails—for example, because orchestrationEngine.dispatch rejects—the error is silently dropped rather than propagating to processDomainEventSafely for logging. This means secondary failures during error recovery leave no trace, making debugging difficult and potentially leaving the thread state inconsistent (no session error set, no failure activity appended, and no warning logged).

      ✅ Resolved in e78ff4355992f8c17fc2c2ac9c7f7b9ce72ea055

    9. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. Diff is too large for automated approval analysis. A human reviewer should evaluate this PR.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    10. Cursor Bugbot has reviewed your changes and found 1 potential issue.

      There are 2 total unresolved issues (including 1 from previous review).

      Autofix Details

      Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Default path overridden by subsequent options spread
        • Swapped the order so ...options is spread first and the path default (using ??) comes after, ensuring the computed default wins when options.path is absent or undefined.

      Create PR

      Or push these changes by commenting:

      @cursor push 4298a93567
      Preview (pingdotgg/t3code@4298a93567)
      diff --git a/apps/desktop/src/main.ts b/apps/desktop/src/main.ts
      --- a/apps/desktop/src/main.ts
      +++ b/apps/desktop/src/main.ts
      @@ -375,8 +375,8 @@
       
         try {
           await waitForHttpReady(baseUrl, {
      +      ...options,
             path: options?.path ?? "/.well-known/t3/environment",
      -      ...options,
             signal: controller.signal,
           });
         } finally {
      You can send follow-ups to the cloud agent here.
    11. Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Child process leaked - runtime close never called
        • Wrapped makeCursorAcpRuntime with Effect.acquireRelease so that runtime.close is called as a scope finalizer when Effect.scoped exits, properly terminating the spawned child process.

      Create PR

      Or push these changes by commenting:

      @cursor push 0f4c368c4c
      Preview (pingdotgg/t3code@0f4c368c4c)
      diff --git a/apps/server/src/git/Layers/CursorTextGeneration.ts b/apps/server/src/git/Layers/CursorTextGeneration.ts
      --- a/apps/server/src/git/Layers/CursorTextGeneration.ts
      +++ b/apps/server/src/git/Layers/CursorTextGeneration.ts
      @@ -126,12 +126,15 @@
             ).pipe(Effect.catch(() => Effect.undefined));
       
             const outputRef = yield* Ref.make("");
      -      const runtime = yield* makeCursorAcpRuntime({
      -        cursorSettings,
      -        childProcessSpawner: commandSpawner,
      -        cwd,
      -        clientInfo: { name: "t3-code-git-text", version: "0.0.0" },
      -      });
      +      const runtime = yield* Effect.acquireRelease(
      +        makeCursorAcpRuntime({
      +          cursorSettings,
      +          childProcessSpawner: commandSpawner,
      +          cwd,
      +          clientInfo: { name: "t3-code-git-text", version: "0.0.0" },
      +        }),
      +        (rt) => rt.close,
      +      );
       
             yield* runtime.handleSessionUpdate((notification) => {
               const update = notification.update;
      You can send follow-ups to the cloud agent here.
    12. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High

      https://github.com/pingdotgg/t3code/blob/e78ff4355992f8c17fc2c2ac9c7f7b9ce72ea055/apps/server/src/orchestration/Layers/ProviderCommandReactor.test.ts#L269

      Line 269 declares const runtime inside the createHarness function, which shadows the module-level let runtime declared on lines 73-76. The outer runtime remains null forever, so the cleanup in afterEach (lines 86-88) never calls runtime.dispose(). This causes ManagedRuntime instances to leak between tests.

      No longer relevant as of 32df4e7f42a30d98c81270a370053c643a94ccfc

    13. @cursor push 0f4c368c4c

    14. Could not push Autofix changes. The PR branch has conflicting changes.

Sign in to join this conversation.