Conversation
- Update cursor_client_version default from 2.0.0 to 2.6.0 (Cursor is now at v2.6+) This is likely the root cause of token verification failures, as the Cursor backend returns OutdatedClient (410 Gone) for old client versions. - Update Electron/Chrome versions in UA strings: - Client UA: Chrome/138 Electron/37.7.0 -> Chrome/140 Electron/38.0.0 - Web UA: Chrome/143 -> Chrome/145 (latest stable browser) - sec-ch-ua: Chromium/138 -> Chromium/140 (matching Electron 38) - Update connect-es version from 1.6.1 to 2.1.1 - Update Version default in cursor_version.rs from 2.0.0 to 2.6.0 These changes address the most likely cause of 'token obtained but verification always fails' - the server-side OutdatedClient check rejecting requests with x-cursor-client-version: 2.0.0. Co-authored-by: hzsw1234 <hzsw1234@users.noreply.github.com>
|
Cursor Agent can help with this pull request. Just |
Add a new independent backend that calls the official Cursor CLI tool
('agent') to handle chat completion requests. This bypasses the direct
gRPC/protobuf path, using the CLI's built-in authentication and protocol
handling instead.
New endpoint: POST /cli/chat/completions (requires admin auth)
- Supports both sync and streaming (SSE) modes
- Builds prompt from OpenAI-format messages array
- Parses CLI stream-json output with deduplication
- Uses std::process via spawn_blocking (no new dependencies)
Configuration (all optional, disabled by default):
- CLI_BACKEND_ENABLED=true - Enable the CLI backend
- CLI_AGENT_BIN=agent - Path to the agent binary
- CLI_TIMEOUT_MS=300000 - Request timeout
- CLI_WORKSPACE=/tmp - Working directory for CLI
Prerequisites:
- Install Cursor CLI: curl https://cursor.com/install -fsS | bash
- Login: agent login (or set CURSOR_API_KEY)
This does NOT modify the existing gRPC code path.
Co-authored-by: hzsw1234 <hzsw1234@users.noreply.github.com>
- Rewrite StreamParser to handle CLI stream-json format correctly: - Parse 'thinking' delta events → reasoning_content field - Parse 'assistant' delta events → content field - Skip final accumulated assistant message (dedup) - Capture usage info from 'result' event - Add reasoning_content to OpenAI-compatible response format: - Sync mode: message.reasoning_content contains full thinking - Stream mode: delta.reasoning_content streams thinking chunks - Compatible with OpenAI o1/o3 reasoning_content format - Fix sync mode to use stream-json internally to capture thinking - Add proper usage token counts from CLI output Tested with claude-4.5-sonnet-thinking: - Sync: reasoning_content + content both populated correctly - Stream: 44 thinking chunks + 24 content chunks, no truncation Co-authored-by: hzsw1234 <hzsw1234@users.noreply.github.com>
When the Cursor agent writes code to files via tool_calls (editToolCall), the file content is now captured and included in the API response. This fixes the issue where thinking models (opus-thinking, sonnet-thinking) would write code to files instead of outputting to stdout, resulting in empty or summary-only responses. Changes: - StreamParser now handles 'tool_call' events with editToolCall - File content is emitted as code blocks in the response content - Both sync and stream modes capture file content - Added CLI_USE_ASK_MODE config (default false) - without ask mode, agent has full tool access and can write files - build_agent_command helper for DRY CLI argument construction Co-authored-by: hzsw1234 <hzsw1234@users.noreply.github.com>
CLI outputs deltas per segment (before/after each tool_call), followed by an accumulated message containing all segment text. Previous logic failed to detect mid-stream accumulated messages. New approach: - Track accumulated_text per segment - If current text == accumulated_text → it's the accumulated msg, skip it - Reset accumulated_text on tool_call completion - Handles multi-segment conversations (pre-tool + post-tool text) Verified: no more duplicated text in responses. Co-authored-by: hzsw1234 <hzsw1234@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request contains changes generated by a Cursor Cloud Agent