mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-18 03:57:06 +08:00
Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2f47f02497 | ||
|
|
058aaa532e | ||
|
|
622a57fed7 | ||
|
|
639c452a00 | ||
|
|
0c9a07e018 | ||
|
|
1adca7f600 | ||
|
|
5df3e8f512 | ||
|
|
a2e3a07773 | ||
|
|
6b7c077448 | ||
|
|
c64911e8c6 | ||
|
|
d1d56bd6eb | ||
|
|
ee47f187f0 | ||
|
|
424235f11d | ||
|
|
58770aa206 | ||
|
|
eb0ad7b636 | ||
|
|
697fa99245 | ||
|
|
1854a3ab9a | ||
|
|
2c650b3765 | ||
|
|
14b286a466 | ||
|
|
828e0a9941 |
@@ -23,6 +23,29 @@ description: 本地模式实现指南
|
|||||||
客户端是:/Users/leokun/Library/Application\ Support/Cursor
|
客户端是:/Users/leokun/Library/Application\ Support/Cursor
|
||||||
客户端 bundle 是:/Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist/main.js
|
客户端 bundle 是:/Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist/main.js
|
||||||
|
|
||||||
|
## 可选抓包调试工具
|
||||||
|
|
||||||
|
仓库提供了独立的 Cursor 协议抓包调试器。开发者在手动排查协议问题时,可以运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go run ./cmd/cursor-proxy-debugger
|
||||||
|
```
|
||||||
|
|
||||||
|
默认代理地址是 `http://127.0.0.1:9090`,调试界面是 `http://127.0.0.1:9091`。该工具可以辅助查看:
|
||||||
|
|
||||||
|
- `agent.v1.AgentService/RunSSE`
|
||||||
|
- `aiserver.v1.BidiService/BidiAppend`
|
||||||
|
- Connect 帧、gzip 压缩内容、Protobuf 解码结果和原始二进制数据
|
||||||
|
- 同一 `request_id` 对应的上下行消息
|
||||||
|
|
||||||
|
开发者启动工具后,需要自行完成以下配置:
|
||||||
|
|
||||||
|
1. 在 Cursor 的代理设置中,将代理修改为工具启动时显示的代理地址,默认是 `http://127.0.0.1:9090`。
|
||||||
|
2. 在 Cursor 的 Network 设置中开启 HTTP/1.1。
|
||||||
|
3. 从 `http://127.0.0.1:9091/api/ca.crt` 下载代理 CA 证书,并确保 Cursor 信任该证书。
|
||||||
|
|
||||||
|
这只是供开发者手动使用的辅助工具,不属于自动化 Debug 流程。不要因为加载此指南就自动启动代理、修改 Cursor 或系统设置、安装证书,或操作 Cursor 发起请求。只有开发者明确表示已经启用抓包时,才把调试界面中的数据作为当前运行证据。调试结束后,提醒开发者恢复原来的 Cursor 代理和 Network 设置。
|
||||||
|
|
||||||
## Cursor 客户端格式化快照
|
## Cursor 客户端格式化快照
|
||||||
|
|
||||||
- 如果用户要求提取、格式化、刷新或规范化 Cursor.app 快照流程,使用 `cursor-app-formatted` skill。
|
- 如果用户要求提取、格式化、刷新或规范化 Cursor.app 快照流程,使用 `cursor-app-formatted` skill。
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ server-go/log/
|
|||||||
.cursor-local-assistant
|
.cursor-local-assistant
|
||||||
.cursor-local-assistant-v2
|
.cursor-local-assistant-v2
|
||||||
.cursor-app-formatted/
|
.cursor-app-formatted/
|
||||||
|
proto/extensions-cursor-app/
|
||||||
ads-server-linux-amd64.tar
|
ads-server-linux-amd64.tar
|
||||||
cmd/ads-server/*.db
|
cmd/ads-server/*.db
|
||||||
cmd/ads-server/*.db-*
|
cmd/ads-server/*.db-*
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ https://t.me/cursor_byok
|
|||||||
## 路线图
|
## 路线图
|
||||||
|
|
||||||
[正式版路线图](https://github.com/leookun/cursor-byok/discussions/32)
|
[正式版路线图](https://github.com/leookun/cursor-byok/discussions/32)
|
||||||
[详细使用教程](https://dcne38qm5vlg.feishu.cn/wiki/JeP7wdGnziBXuikNaF5czWbrn8c)
|
[详细使用教程](https://docs.leokun.cn)
|
||||||
|
|
||||||
## 后续
|
## 后续
|
||||||
|
|
||||||
@@ -37,13 +37,3 @@ https://t.me/cursor_byok
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Star History
|
|
||||||
|
|
||||||
<a href="https://www.star-history.com/?repos=leookun%2Fcursor-byok&type=timeline&legend=top-left">
|
|
||||||
<picture>
|
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=leookun/cursor-byok&type=timeline&theme=dark&legend=top-left" />
|
|
||||||
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=leookun/cursor-byok&type=timeline&legend=top-left" />
|
|
||||||
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=leookun/cursor-byok&type=timeline&legend=top-left" />
|
|
||||||
</picture>
|
|
||||||
</a>
|
|
||||||
|
|||||||
@@ -178,6 +178,16 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- wails3 dev -config ./build/config.yml -port {{.VITE_PORT}}
|
- wails3 dev -config ./build/config.yml -port {{.VITE_PORT}}
|
||||||
|
|
||||||
|
proxy-debugger:
|
||||||
|
summary: 启动独立 Cursor 协议调试代理
|
||||||
|
cmds:
|
||||||
|
- go run ./cmd/cursor-proxy-debugger
|
||||||
|
|
||||||
|
proxy-debugger:build:
|
||||||
|
summary: 构建独立 Cursor 协议调试代理
|
||||||
|
cmds:
|
||||||
|
- go build -o ./bin/cursor-proxy-debugger ./cmd/cursor-proxy-debugger
|
||||||
|
|
||||||
ads:install:
|
ads:install:
|
||||||
summary: 安装广告页依赖
|
summary: 安装广告页依赖
|
||||||
dir: '{{.TASKFILE_DIR}}/ads-page'
|
dir: '{{.TASKFILE_DIR}}/ads-page'
|
||||||
|
|||||||
+2
-2
@@ -13,8 +13,8 @@ tasks:
|
|||||||
preconditions:
|
preconditions:
|
||||||
- sh: 'test -z "{{.PROTO_INPUT}}" || test -f "{{.PROTO_INPUT}}"'
|
- sh: 'test -z "{{.PROTO_INPUT}}" || test -f "{{.PROTO_INPUT}}"'
|
||||||
msg: "PROTO_INPUT 指向的 Cursor 扩展 bundle 不存在。"
|
msg: "PROTO_INPUT 指向的 Cursor 扩展 bundle 不存在。"
|
||||||
- sh: 'test -n "{{.PROTO_INPUT}}" || test -f ./proto/extensions-cursor-app/cursor-always-local/dist/main.js || test -f /Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist/main.js'
|
- sh: 'test -n "{{.PROTO_INPUT}}" || test -f /Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist/main.js'
|
||||||
msg: "未找到 Cursor 扩展 bundle;请传入 PROTO_INPUT=/path/to/cursor-always-local/dist/main.js。"
|
msg: "未找到已安装 Cursor 的扩展 bundle;请传入 PROTO_INPUT=/path/to/cursor-always-local/dist/main.js。"
|
||||||
cmds:
|
cmds:
|
||||||
- chmod +x ./proto/extract_extensions_proto.sh
|
- chmod +x ./proto/extract_extensions_proto.sh
|
||||||
- '{{if .PROTO_INPUT}}./proto/extract_extensions_proto.sh "{{.PROTO_INPUT}}"{{else}}./proto/extract_extensions_proto.sh{{end}}'
|
- '{{if .PROTO_INPUT}}./proto/extract_extensions_proto.sh "{{.PROTO_INPUT}}"{{else}}./proto/extract_extensions_proto.sh{{end}}'
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ info:
|
|||||||
description: "Cursor助手"
|
description: "Cursor助手"
|
||||||
copyright: "© 2026, Cursor助手"
|
copyright: "© 2026, Cursor助手"
|
||||||
comments: "Cursor助手"
|
comments: "Cursor助手"
|
||||||
version: "0.0.43"
|
version: "0.0.44"
|
||||||
|
|
||||||
dev_mode:
|
dev_mode:
|
||||||
root_path: .
|
root_path: .
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.0.43</string>
|
<string>0.0.44</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>0.0.43</string>
|
<string>0.0.44</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>12.0.0</string>
|
<string>12.0.0</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
|
|||||||
@@ -17,9 +17,9 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>0.0.43</string>
|
<string>0.0.44</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>0.0.43</string>
|
<string>0.0.44</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>12.0.0</string>
|
<string>12.0.0</string>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
name: "Cursor助手"
|
name: "Cursor助手"
|
||||||
arch: ${GOARCH}
|
arch: ${GOARCH}
|
||||||
platform: "linux"
|
platform: "linux"
|
||||||
version: "0.0.43"
|
version: "0.0.44"
|
||||||
section: "default"
|
section: "default"
|
||||||
priority: "extra"
|
priority: "extra"
|
||||||
maintainer: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>
|
maintainer: ${GIT_COMMITTER_NAME} <${GIT_COMMITTER_EMAIL}>
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"fixed": {
|
"fixed": {
|
||||||
"file_version": "0.0.43"
|
"file_version": "0.0.44"
|
||||||
},
|
},
|
||||||
"info": {
|
"info": {
|
||||||
"0000": {
|
"0000": {
|
||||||
"ProductVersion": "0.0.43",
|
"ProductVersion": "0.0.44",
|
||||||
"CompanyName": "Cursor助手",
|
"CompanyName": "Cursor助手",
|
||||||
"FileDescription": "Cursor助手",
|
"FileDescription": "Cursor助手",
|
||||||
"LegalCopyright": "© 2026, Cursor助手",
|
"LegalCopyright": "© 2026, Cursor助手",
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
!define INFO_PRODUCTNAME "Cursor助手"
|
!define INFO_PRODUCTNAME "Cursor助手"
|
||||||
!endif
|
!endif
|
||||||
!ifndef INFO_PRODUCTVERSION
|
!ifndef INFO_PRODUCTVERSION
|
||||||
!define INFO_PRODUCTVERSION "0.0.43"
|
!define INFO_PRODUCTVERSION "0.0.44"
|
||||||
!endif
|
!endif
|
||||||
!ifndef INFO_COPYRIGHT
|
!ifndef INFO_COPYRIGHT
|
||||||
!define INFO_COPYRIGHT "© 2026, Cursor助手"
|
!define INFO_COPYRIGHT "© 2026, Cursor助手"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
|
||||||
<assemblyIdentity type="win32" name="com.cursor.wuxianxubei" version="0.0.43" processorArchitecture="*"/>
|
<assemblyIdentity type="win32" name="com.cursor.wuxianxubei" version="0.0.44" processorArchitecture="*"/>
|
||||||
<dependency>
|
<dependency>
|
||||||
<dependentAssembly>
|
<dependentAssembly>
|
||||||
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
<assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
proxydebugger "cursor/cursor-proxy-debugger"
|
||||||
|
|
||||||
|
"github.com/pkg/browser"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
config := proxydebugger.Config{}
|
||||||
|
openBrowser := true
|
||||||
|
flag.StringVar(&config.ProxyAddr, "proxy-addr", "127.0.0.1:9090", "HTTP/HTTPS 代理监听地址")
|
||||||
|
flag.StringVar(&config.UIAddr, "ui-addr", "127.0.0.1:9091", "调试界面监听地址")
|
||||||
|
flag.StringVar(&config.TargetHost, "target-host", "api2.cursor.sh", "需要解密和抓取的目标主机")
|
||||||
|
flag.IntVar(&config.MaxExchanges, "max-exchanges", 200, "内存中保留的最大请求数")
|
||||||
|
flag.BoolVar(&openBrowser, "open", true, "启动后打开浏览器")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
server, err := proxydebugger.New(config)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := server.Start(); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Cursor 协议调试代理已启动\n")
|
||||||
|
fmt.Printf("代理地址: http://%s\n", server.ProxyAddr())
|
||||||
|
fmt.Printf("调试界面: %s\n", server.UIURL())
|
||||||
|
if openBrowser {
|
||||||
|
_ = browser.OpenURL(server.UIURL())
|
||||||
|
}
|
||||||
|
|
||||||
|
signals := make(chan os.Signal, 1)
|
||||||
|
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
<-signals
|
||||||
|
|
||||||
|
shutdownContext, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
if err := server.Close(shutdownContext); err != nil {
|
||||||
|
log.Printf("关闭调试代理失败:%v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
# Cursor Protocol Debugger
|
||||||
|
|
||||||
|
[中文](README.md) | [English](README.en.md)
|
||||||
|
|
||||||
|
This standalone local HTTPS debugging proxy captures Cursor's `BidiAppend`, `RunSSE`, and Fork Chat traffic. It does not modify Cursor, the system proxy, or the installed client.
|
||||||
|
|
||||||
|
## Start
|
||||||
|
|
||||||
|
Run the following command from the repository root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go run ./cmd/cursor-proxy-debugger
|
||||||
|
```
|
||||||
|
|
||||||
|
Default addresses:
|
||||||
|
|
||||||
|
- HTTP/HTTPS proxy: `127.0.0.1:9090`
|
||||||
|
- Debugging UI: `http://127.0.0.1:9091`
|
||||||
|
- MITM target: `api2.cursor.sh`
|
||||||
|
|
||||||
|
The debugging UI opens automatically after startup.
|
||||||
|
|
||||||
|
## Configure Cursor
|
||||||
|
|
||||||
|
The tool does not modify Cursor automatically. After starting it, configure Cursor manually:
|
||||||
|
|
||||||
|
1. Open Cursor's proxy settings and set the proxy to the address printed by the tool. The default is `http://127.0.0.1:9090`.
|
||||||
|
2. Open Cursor's Network settings and enable HTTP/1.1.
|
||||||
|
3. Download the proxy CA certificate from `http://127.0.0.1:9091/api/ca.crt` and make sure Cursor trusts it.
|
||||||
|
|
||||||
|
Restore the original Cursor proxy and Network settings after debugging to avoid affecting normal network requests.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go build -o bin/cursor-proxy-debugger ./cmd/cursor-proxy-debugger
|
||||||
|
```
|
||||||
|
|
||||||
|
## Options
|
||||||
|
|
||||||
|
```text
|
||||||
|
-proxy-addr Proxy listen address; default: 127.0.0.1:9090
|
||||||
|
-ui-addr Debugging UI listen address; default: 127.0.0.1:9091
|
||||||
|
-target-host Host to decrypt and capture; default: api2.cursor.sh
|
||||||
|
-max-exchanges Maximum number of exchanges retained in memory; default: 200
|
||||||
|
-open Open the browser after startup; default: true
|
||||||
|
```
|
||||||
|
|
||||||
|
## Data Handling
|
||||||
|
|
||||||
|
- HTTPS MITM is applied only to `target-host`; other CONNECT traffic passes through unchanged.
|
||||||
|
- `RunSSE` is decoded incrementally using the 5-byte Connect frame header and supports per-frame gzip decompression.
|
||||||
|
- `BidiAppendRequest.data` is further decoded as `agent.v1.AgentClientMessage`.
|
||||||
|
- Fork Chat's `ForkBackgroundComposer`, `NotifyConversationClone`, and `UploadConversationBlobs` traffic is decoded bidirectionally as protobuf JSON.
|
||||||
|
- Local Fork Chat is primarily client-side and only emits `NotifyConversationClone` and `UploadConversationBlobs` when clone blob synchronization is enabled and privacy settings allow it.
|
||||||
|
- Requests can be sorted chronologically or in reverse chronological order and filtered by protocol `request_id`.
|
||||||
|
- The UI supports Simplified Chinese and English, follows the browser language, and remembers a manual selection.
|
||||||
|
- Captured traffic is stored only in process memory and is discarded when the process exits.
|
||||||
|
- Sensitive HTTP headers such as `Authorization`, `Cookie`, and `Set-Cookie` are hidden in the UI by default.
|
||||||
|
- Raw bodies are retained up to 2 MiB per side by default; forwarded traffic is never truncated.
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
# Cursor 协议调试器
|
||||||
|
|
||||||
|
[中文](README.md) | [English](README.en.md)
|
||||||
|
|
||||||
|
这是一个独立运行的本地 HTTPS 调试代理,用于观察 Cursor 的 `BidiAppend`、`RunSSE` 和 Fork Chat 相关通信。它不会修改 Cursor、系统代理或已安装客户端。
|
||||||
|
|
||||||
|
## 启动
|
||||||
|
|
||||||
|
在仓库根目录运行:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go run ./cmd/cursor-proxy-debugger
|
||||||
|
```
|
||||||
|
|
||||||
|
默认监听:
|
||||||
|
|
||||||
|
- HTTP/HTTPS 代理:`127.0.0.1:9090`
|
||||||
|
- 调试界面:`http://127.0.0.1:9091`
|
||||||
|
- MITM 目标:`api2.cursor.sh`
|
||||||
|
|
||||||
|
启动后会自动打开调试界面。
|
||||||
|
|
||||||
|
## 配置 Cursor
|
||||||
|
|
||||||
|
工具不会自动修改 Cursor。启动后需要手动完成以下配置:
|
||||||
|
|
||||||
|
1. 打开 Cursor 的代理设置,将代理地址修改为工具启动时显示的地址,默认是 `http://127.0.0.1:9090`。
|
||||||
|
2. 打开 Cursor 的 Network 设置,启用 HTTP/1.1。
|
||||||
|
3. 从 `http://127.0.0.1:9091/api/ca.crt` 下载代理 CA 证书,并确保 Cursor 信任该证书。
|
||||||
|
|
||||||
|
调试结束后,请恢复原来的 Cursor 代理和 Network 设置,以免影响正常网络请求。
|
||||||
|
|
||||||
|
## 构建
|
||||||
|
|
||||||
|
```bash
|
||||||
|
go build -o bin/cursor-proxy-debugger ./cmd/cursor-proxy-debugger
|
||||||
|
```
|
||||||
|
|
||||||
|
## 参数
|
||||||
|
|
||||||
|
```text
|
||||||
|
-proxy-addr 代理监听地址,默认 127.0.0.1:9090
|
||||||
|
-ui-addr 调试界面监听地址,默认 127.0.0.1:9091
|
||||||
|
-target-host 需要解密的目标主机,默认 api2.cursor.sh
|
||||||
|
-max-exchanges 内存中保留的最大请求数,默认 200
|
||||||
|
-open 启动后是否打开浏览器,默认 true
|
||||||
|
```
|
||||||
|
|
||||||
|
## 数据处理
|
||||||
|
|
||||||
|
- 仅对 `target-host` 执行 HTTPS MITM,其他 CONNECT 流量直接透传。
|
||||||
|
- `RunSSE` 按 5 字节 Connect 帧头增量拆帧,支持逐帧 gzip 解压。
|
||||||
|
- `BidiAppendRequest.data` 会继续解码为 `agent.v1.AgentClientMessage`。
|
||||||
|
- Fork Chat 相关的 `ForkBackgroundComposer`、`NotifyConversationClone` 和 `UploadConversationBlobs` 会双向解码为 protobuf JSON。
|
||||||
|
- 本地 Fork Chat 主要在客户端完成,只有启用克隆 blob 同步且隐私设置允许时才会产生 `NotifyConversationClone` 和 `UploadConversationBlobs` 流量。
|
||||||
|
- 请求列表支持按抓包时间正序/倒序排列,并可按协议中的 `request_id` 过滤。
|
||||||
|
- 调试界面支持简体中文和英文,可跟随浏览器语言并记住手动选择。
|
||||||
|
- 抓包只保留在当前进程内存中;关闭进程后消失。
|
||||||
|
- `Authorization`、`Cookie`、`Set-Cookie` 等 HTTP 头在界面中默认隐藏。
|
||||||
|
- 单侧原始正文默认最多保留 2 MiB;代理转发的数据不会被截断。
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package proxydebugger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/hex"
|
||||||
|
"io"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
type captureReadCloser struct {
|
||||||
|
source io.ReadCloser
|
||||||
|
mu sync.Mutex
|
||||||
|
buffer bytes.Buffer
|
||||||
|
limit int
|
||||||
|
size int64
|
||||||
|
truncated bool
|
||||||
|
done bool
|
||||||
|
onChunk func([]byte)
|
||||||
|
onDone func(captured []byte, size int64, truncated bool, readErr error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newCaptureReadCloser(
|
||||||
|
source io.ReadCloser,
|
||||||
|
limit int,
|
||||||
|
onChunk func([]byte),
|
||||||
|
onDone func(captured []byte, size int64, truncated bool, readErr error),
|
||||||
|
) *captureReadCloser {
|
||||||
|
return &captureReadCloser{
|
||||||
|
source: source,
|
||||||
|
limit: limit,
|
||||||
|
onChunk: onChunk,
|
||||||
|
onDone: onDone,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (reader *captureReadCloser) Read(payload []byte) (int, error) {
|
||||||
|
read, err := reader.source.Read(payload)
|
||||||
|
if read > 0 {
|
||||||
|
chunk := payload[:read]
|
||||||
|
reader.mu.Lock()
|
||||||
|
reader.size += int64(read)
|
||||||
|
remaining := reader.limit - reader.buffer.Len()
|
||||||
|
if remaining > 0 {
|
||||||
|
captured := read
|
||||||
|
if captured > remaining {
|
||||||
|
captured = remaining
|
||||||
|
}
|
||||||
|
_, _ = reader.buffer.Write(chunk[:captured])
|
||||||
|
}
|
||||||
|
if reader.buffer.Len() >= reader.limit && reader.size > int64(reader.buffer.Len()) {
|
||||||
|
reader.truncated = true
|
||||||
|
}
|
||||||
|
reader.mu.Unlock()
|
||||||
|
if reader.onChunk != nil {
|
||||||
|
reader.onChunk(append([]byte(nil), chunk...))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
reader.finish(err)
|
||||||
|
}
|
||||||
|
return read, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (reader *captureReadCloser) Close() error {
|
||||||
|
err := reader.source.Close()
|
||||||
|
reader.finish(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (reader *captureReadCloser) finish(readErr error) {
|
||||||
|
reader.mu.Lock()
|
||||||
|
if reader.done {
|
||||||
|
reader.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
reader.done = true
|
||||||
|
captured := append([]byte(nil), reader.buffer.Bytes()...)
|
||||||
|
size := reader.size
|
||||||
|
truncated := reader.truncated
|
||||||
|
reader.mu.Unlock()
|
||||||
|
if reader.onDone != nil {
|
||||||
|
reader.onDone(captured, size, truncated, readErr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func rawHex(payload []byte) string {
|
||||||
|
return hex.EncodeToString(payload)
|
||||||
|
}
|
||||||
@@ -0,0 +1,294 @@
|
|||||||
|
package proxydebugger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
|
"encoding/binary"
|
||||||
|
"encoding/hex"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"cursor/gen/agentv1"
|
||||||
|
"cursor/gen/aiserverv1"
|
||||||
|
agentprotocol "cursor/internal/backend/agent/protocol"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/encoding/protojson"
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
const maxConnectFrameBytes = 64 << 20
|
||||||
|
|
||||||
|
const (
|
||||||
|
bidiAppendPath = "/aiserver.v1.BidiService/BidiAppend"
|
||||||
|
forkBackgroundComposerPath = "/aiserver.v1.BackgroundComposerService/ForkBackgroundComposer"
|
||||||
|
notifyConversationClonePath = "/agent.v1.AgentService/NotifyConversationClone"
|
||||||
|
uploadConversationBlobsPath = "/agent.v1.AgentService/UploadConversationBlobs"
|
||||||
|
)
|
||||||
|
|
||||||
|
type connectFrameDecoder struct {
|
||||||
|
buffer []byte
|
||||||
|
messageType string
|
||||||
|
codec string
|
||||||
|
maxFrames int
|
||||||
|
frameCount int
|
||||||
|
onFrame func(FrameView)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConnectFrameDecoder(messageType string, codec string, maxFrames int, onFrame func(FrameView)) *connectFrameDecoder {
|
||||||
|
return &connectFrameDecoder{
|
||||||
|
messageType: messageType,
|
||||||
|
codec: strings.TrimSpace(codec),
|
||||||
|
maxFrames: maxFrames,
|
||||||
|
onFrame: onFrame,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (decoder *connectFrameDecoder) Write(payload []byte) {
|
||||||
|
if len(payload) == 0 || decoder.frameCount >= decoder.maxFrames {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
decoder.buffer = append(decoder.buffer, payload...)
|
||||||
|
for len(decoder.buffer) >= 5 && decoder.frameCount < decoder.maxFrames {
|
||||||
|
flags := decoder.buffer[0]
|
||||||
|
length := int(binary.BigEndian.Uint32(decoder.buffer[1:5]))
|
||||||
|
if length < 0 || length > maxConnectFrameBytes {
|
||||||
|
decoder.emit(FrameView{Flags: flags, Length: length, Error: "Connect 帧长度异常"})
|
||||||
|
decoder.buffer = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(decoder.buffer) < 5+length {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
framePayload := append([]byte(nil), decoder.buffer[5:5+length]...)
|
||||||
|
decoder.buffer = decoder.buffer[5+length:]
|
||||||
|
decoder.emit(decoder.decode(flags, framePayload))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (decoder *connectFrameDecoder) Close() {
|
||||||
|
if len(decoder.buffer) > 0 && decoder.frameCount < decoder.maxFrames {
|
||||||
|
decoder.emit(FrameView{
|
||||||
|
Length: len(decoder.buffer),
|
||||||
|
RawHex: clippedHex(decoder.buffer, 4096),
|
||||||
|
Error: "流结束时仍有不完整的 Connect 帧",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
decoder.buffer = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (decoder *connectFrameDecoder) emit(frame FrameView) {
|
||||||
|
frame.Index = decoder.frameCount
|
||||||
|
decoder.frameCount++
|
||||||
|
if decoder.onFrame != nil {
|
||||||
|
decoder.onFrame(frame)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (decoder *connectFrameDecoder) decode(flags uint8, payload []byte) FrameView {
|
||||||
|
frame := FrameView{
|
||||||
|
Flags: flags,
|
||||||
|
Length: len(payload),
|
||||||
|
Compressed: flags&0x01 != 0,
|
||||||
|
EndStream: flags&0x02 != 0,
|
||||||
|
RawHex: clippedHex(payload, 4096),
|
||||||
|
}
|
||||||
|
decoded := payload
|
||||||
|
if frame.Compressed {
|
||||||
|
var err error
|
||||||
|
decoded, err = decompressPayload(payload, decoder.codec)
|
||||||
|
if err != nil {
|
||||||
|
frame.Error = err.Error()
|
||||||
|
return frame
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if frame.EndStream {
|
||||||
|
frame.Kind = "end_stream"
|
||||||
|
frame.MessageType = "connect.error.v1.EndStreamResponse"
|
||||||
|
frame.JSON = prettyJSON(decoded)
|
||||||
|
return frame
|
||||||
|
}
|
||||||
|
|
||||||
|
message := newMessage(decoder.messageType)
|
||||||
|
if message == nil {
|
||||||
|
frame.Error = "未知的 protobuf 消息类型"
|
||||||
|
return frame
|
||||||
|
}
|
||||||
|
if err := proto.Unmarshal(decoded, message); err != nil {
|
||||||
|
frame.Error = fmt.Sprintf("protobuf 解码失败:%v", err)
|
||||||
|
return frame
|
||||||
|
}
|
||||||
|
frame.MessageType = decoder.messageType
|
||||||
|
frame.Kind = activeOneofName(message)
|
||||||
|
if requestID, ok := message.(*aiserverv1.BidiRequestId); ok {
|
||||||
|
frame.RequestID = strings.TrimSpace(requestID.GetRequestId())
|
||||||
|
}
|
||||||
|
frame.JSON = marshalProtoJSON(message)
|
||||||
|
return frame
|
||||||
|
}
|
||||||
|
|
||||||
|
func decompressPayload(payload []byte, codec string) ([]byte, error) {
|
||||||
|
if codec != "" && !strings.EqualFold(codec, "gzip") {
|
||||||
|
return nil, fmt.Errorf("暂不支持压缩算法 %q", codec)
|
||||||
|
}
|
||||||
|
reader, err := gzip.NewReader(bytes.NewReader(payload))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("gzip 解压失败:%w", err)
|
||||||
|
}
|
||||||
|
defer reader.Close()
|
||||||
|
decoded, err := io.ReadAll(io.LimitReader(reader, maxConnectFrameBytes+1))
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("读取 gzip 内容失败:%w", err)
|
||||||
|
}
|
||||||
|
if len(decoded) > maxConnectFrameBytes {
|
||||||
|
return nil, fmt.Errorf("gzip 解压后超过 %d 字节限制", maxConnectFrameBytes)
|
||||||
|
}
|
||||||
|
return decoded, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeUnaryRequest(path string, payload []byte) (decodedJSON string, kind string, requestID string, err error) {
|
||||||
|
switch path {
|
||||||
|
case bidiAppendPath:
|
||||||
|
request := &aiserverv1.BidiAppendRequest{}
|
||||||
|
if err := proto.Unmarshal(payload, request); err != nil {
|
||||||
|
return "", "", "", err
|
||||||
|
}
|
||||||
|
requestID := strings.TrimSpace(request.GetRequestId().GetRequestId())
|
||||||
|
outer := marshalProtoJSON(request)
|
||||||
|
clientMessage, clientKind, decodeErr := agentprotocol.DecodeAgentClientMessage(request.GetData())
|
||||||
|
if decodeErr != nil || clientMessage == nil {
|
||||||
|
return outer, "bidi_append", requestID, decodeErr
|
||||||
|
}
|
||||||
|
combined := struct {
|
||||||
|
BidiAppendRequest json.RawMessage `json:"bidi_append_request"`
|
||||||
|
AgentClientKind string `json:"agent_client_kind"`
|
||||||
|
AgentClient json.RawMessage `json:"agent_client_message"`
|
||||||
|
}{
|
||||||
|
BidiAppendRequest: json.RawMessage(outer),
|
||||||
|
AgentClientKind: clientKind,
|
||||||
|
AgentClient: json.RawMessage(marshalProtoJSON(clientMessage)),
|
||||||
|
}
|
||||||
|
formatted, marshalErr := json.MarshalIndent(combined, "", " ")
|
||||||
|
return string(formatted), clientKind, requestID, marshalErr
|
||||||
|
}
|
||||||
|
message, kind := unaryRequestMessage(path)
|
||||||
|
if message == nil {
|
||||||
|
return "", "", "", nil
|
||||||
|
}
|
||||||
|
if err := proto.Unmarshal(payload, message); err != nil {
|
||||||
|
return "", "", "", err
|
||||||
|
}
|
||||||
|
return marshalProtoJSON(message), kind, "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodeUnaryResponse(path string, payload []byte) (decodedJSON string, kind string, err error) {
|
||||||
|
message, kind := unaryResponseMessage(path)
|
||||||
|
if message == nil {
|
||||||
|
return "", "", nil
|
||||||
|
}
|
||||||
|
if err := proto.Unmarshal(payload, message); err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
return marshalProtoJSON(message), kind, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func unaryRequestMessage(path string) (proto.Message, string) {
|
||||||
|
switch path {
|
||||||
|
case forkBackgroundComposerPath:
|
||||||
|
return &aiserverv1.ForkBackgroundComposerRequest{}, "fork_background_composer_request"
|
||||||
|
case notifyConversationClonePath:
|
||||||
|
return &agentv1.NotifyConversationCloneRequest{}, "notify_conversation_clone_request"
|
||||||
|
case uploadConversationBlobsPath:
|
||||||
|
return &agentv1.UploadConversationBlobsRequest{}, "upload_conversation_blobs_request"
|
||||||
|
default:
|
||||||
|
return nil, ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func unaryResponseMessage(path string) (proto.Message, string) {
|
||||||
|
switch path {
|
||||||
|
case forkBackgroundComposerPath:
|
||||||
|
return &aiserverv1.ForkBackgroundComposerResponse{}, "fork_background_composer_response"
|
||||||
|
case notifyConversationClonePath:
|
||||||
|
return &agentv1.NotifyConversationCloneResponse{}, "notify_conversation_clone_response"
|
||||||
|
case uploadConversationBlobsPath:
|
||||||
|
return &agentv1.UploadConversationBlobsResponse{}, "upload_conversation_blobs_response"
|
||||||
|
default:
|
||||||
|
return nil, ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodesUnaryRequest(path string) bool {
|
||||||
|
if path == bidiAppendPath {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
message, _ := unaryRequestMessage(path)
|
||||||
|
return message != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func decodesUnaryResponse(path string) bool {
|
||||||
|
message, _ := unaryResponseMessage(path)
|
||||||
|
return message != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMessage(messageType string) proto.Message {
|
||||||
|
switch messageType {
|
||||||
|
case "aiserver.v1.BidiRequestId":
|
||||||
|
return &aiserverv1.BidiRequestId{}
|
||||||
|
case "agent.v1.AgentServerMessage":
|
||||||
|
return &agentv1.AgentServerMessage{}
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func marshalProtoJSON(message proto.Message) string {
|
||||||
|
if message == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
payload, err := (protojson.MarshalOptions{
|
||||||
|
UseProtoNames: true,
|
||||||
|
EmitUnpopulated: false,
|
||||||
|
Indent: " ",
|
||||||
|
}).Marshal(message)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
func activeOneofName(message proto.Message) string {
|
||||||
|
if message == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
reflected := message.ProtoReflect()
|
||||||
|
oneofs := reflected.Descriptor().Oneofs()
|
||||||
|
for index := 0; index < oneofs.Len(); index++ {
|
||||||
|
oneof := oneofs.Get(index)
|
||||||
|
field := reflected.WhichOneof(oneof)
|
||||||
|
if field != nil {
|
||||||
|
return string(field.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return string(reflected.Descriptor().Name())
|
||||||
|
}
|
||||||
|
|
||||||
|
func prettyJSON(payload []byte) string {
|
||||||
|
var target any
|
||||||
|
if err := json.Unmarshal(payload, &target); err != nil {
|
||||||
|
return string(payload)
|
||||||
|
}
|
||||||
|
formatted, err := json.MarshalIndent(target, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return string(payload)
|
||||||
|
}
|
||||||
|
return string(formatted)
|
||||||
|
}
|
||||||
|
|
||||||
|
func clippedHex(payload []byte, max int) string {
|
||||||
|
if len(payload) > max {
|
||||||
|
return hex.EncodeToString(payload[:max]) + "..."
|
||||||
|
}
|
||||||
|
return hex.EncodeToString(payload)
|
||||||
|
}
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
package proxydebugger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"compress/gzip"
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"cursor/gen/agentv1"
|
||||||
|
"cursor/gen/aiserverv1"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDecodeForkTrafficRequests(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
message proto.Message
|
||||||
|
kind string
|
||||||
|
contains []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "fork background composer",
|
||||||
|
path: forkBackgroundComposerPath,
|
||||||
|
message: &aiserverv1.ForkBackgroundComposerRequest{
|
||||||
|
SourceBcId: "bc-source",
|
||||||
|
Mode: aiserverv1.ForkBackgroundComposerMode_FORK_BACKGROUND_COMPOSER_MODE_CONVERSATION,
|
||||||
|
Name: proto.String("forked chat"),
|
||||||
|
TurnCount: proto.Uint32(4),
|
||||||
|
},
|
||||||
|
kind: "fork_background_composer_request",
|
||||||
|
contains: []string{`"source_bc_id":"bc-source"`, `"turn_count":4`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "notify conversation clone",
|
||||||
|
path: notifyConversationClonePath,
|
||||||
|
message: &agentv1.NotifyConversationCloneRequest{
|
||||||
|
ConversationId: "new-conversation",
|
||||||
|
SourceConversationId: "source-conversation",
|
||||||
|
SourceRequestId: "source-request",
|
||||||
|
},
|
||||||
|
kind: "notify_conversation_clone_request",
|
||||||
|
contains: []string{`"conversation_id":"new-conversation"`, `"source_conversation_id":"source-conversation"`},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "upload conversation blobs",
|
||||||
|
path: uploadConversationBlobsPath,
|
||||||
|
message: &agentv1.UploadConversationBlobsRequest{
|
||||||
|
ConversationId: "new-conversation",
|
||||||
|
Blobs: []*agentv1.BlobEntry{{
|
||||||
|
Id: []byte{1, 2},
|
||||||
|
Value: []byte("blob-value"),
|
||||||
|
}},
|
||||||
|
ChunkIndex: 1,
|
||||||
|
TotalChunks: 2,
|
||||||
|
},
|
||||||
|
kind: "upload_conversation_blobs_request",
|
||||||
|
contains: []string{`"conversation_id":"new-conversation"`, `"total_chunks":2`, `"value":"YmxvYi12YWx1ZQ=="`},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
test := test
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
payload, err := proto.Marshal(test.message)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
decoded, kind, requestID, err := decodeUnaryRequest(test.path, payload)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("decode request: %v", err)
|
||||||
|
}
|
||||||
|
if kind != test.kind {
|
||||||
|
t.Fatalf("kind = %q, want %q", kind, test.kind)
|
||||||
|
}
|
||||||
|
if requestID != "" {
|
||||||
|
t.Fatalf("request ID = %q, want empty", requestID)
|
||||||
|
}
|
||||||
|
compact := compactJSON(t, decoded)
|
||||||
|
for _, expected := range test.contains {
|
||||||
|
if !strings.Contains(compact, expected) {
|
||||||
|
t.Errorf("decoded JSON does not contain %q:\n%s", expected, decoded)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDecodeForkTrafficResponses(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
path string
|
||||||
|
message proto.Message
|
||||||
|
kind string
|
||||||
|
contains string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "fork background composer",
|
||||||
|
path: forkBackgroundComposerPath,
|
||||||
|
message: &aiserverv1.ForkBackgroundComposerResponse{
|
||||||
|
BcId: "bc-fork",
|
||||||
|
SourceBcId: "bc-source",
|
||||||
|
Mode: aiserverv1.ForkBackgroundComposerMode_FORK_BACKGROUND_COMPOSER_MODE_CONVERSATION,
|
||||||
|
},
|
||||||
|
kind: "fork_background_composer_response",
|
||||||
|
contains: `"bc_id":"bc-fork"`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "notify conversation clone",
|
||||||
|
path: notifyConversationClonePath,
|
||||||
|
message: &agentv1.NotifyConversationCloneResponse{},
|
||||||
|
kind: "notify_conversation_clone_response",
|
||||||
|
contains: `{}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "upload conversation blobs",
|
||||||
|
path: uploadConversationBlobsPath,
|
||||||
|
message: &agentv1.UploadConversationBlobsResponse{},
|
||||||
|
kind: "upload_conversation_blobs_response",
|
||||||
|
contains: `{}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
test := test
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
payload, err := proto.Marshal(test.message)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
decoded, kind, err := decodeUnaryResponse(test.path, payload)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("decode response: %v", err)
|
||||||
|
}
|
||||||
|
if kind != test.kind {
|
||||||
|
t.Fatalf("kind = %q, want %q", kind, test.kind)
|
||||||
|
}
|
||||||
|
if !strings.Contains(compactJSON(t, decoded), test.contains) {
|
||||||
|
t.Errorf("decoded JSON does not contain %q:\n%s", test.contains, decoded)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFinishResponseBodyDecodesCompressedForkResponse(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
payload, err := proto.Marshal(&aiserverv1.ForkBackgroundComposerResponse{
|
||||||
|
BcId: "bc-fork",
|
||||||
|
SourceBcId: "bc-source",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var compressed bytes.Buffer
|
||||||
|
writer := gzip.NewWriter(&compressed)
|
||||||
|
if _, err := writer.Write(payload); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := writer.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
server := &Server{store: newExchangeStore(1)}
|
||||||
|
server.store.create(&Exchange{
|
||||||
|
ExchangeSummary: ExchangeSummary{ID: "1", StartedAt: time.Now()},
|
||||||
|
})
|
||||||
|
server.finishResponseBody("1", forkBackgroundComposerPath, "gzip", compressed.Bytes(), int64(compressed.Len()), false, nil)
|
||||||
|
|
||||||
|
exchange, ok := server.store.get("1")
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("exchange was not stored")
|
||||||
|
}
|
||||||
|
if exchange.ResponseKind != "fork_background_composer_response" {
|
||||||
|
t.Fatalf("response kind = %q", exchange.ResponseKind)
|
||||||
|
}
|
||||||
|
if !strings.Contains(compactJSON(t, exchange.Response.DecodedJSON), `"bc_id":"bc-fork"`) {
|
||||||
|
t.Fatalf("unexpected decoded response:\n%s", exchange.Response.DecodedJSON)
|
||||||
|
}
|
||||||
|
if exchange.Response.DecodeError != "" {
|
||||||
|
t.Fatalf("decode error = %q", exchange.Response.DecodeError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFinishRequestBodyDecodesCompressedCloneRequest(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
payload, err := proto.Marshal(&agentv1.NotifyConversationCloneRequest{
|
||||||
|
ConversationId: "new-conversation",
|
||||||
|
SourceConversationId: "source-conversation",
|
||||||
|
SourceRequestId: "source-request",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var compressed bytes.Buffer
|
||||||
|
writer := gzip.NewWriter(&compressed)
|
||||||
|
if _, err := writer.Write(payload); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := writer.Close(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
server := &Server{store: newExchangeStore(1)}
|
||||||
|
server.store.create(&Exchange{
|
||||||
|
ExchangeSummary: ExchangeSummary{ID: "1", StartedAt: time.Now()},
|
||||||
|
})
|
||||||
|
server.finishRequestBody("1", notifyConversationClonePath, "gzip", compressed.Bytes(), int64(compressed.Len()), false, nil)
|
||||||
|
|
||||||
|
exchange, ok := server.store.get("1")
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("exchange was not stored")
|
||||||
|
}
|
||||||
|
if exchange.RequestKind != "notify_conversation_clone_request" {
|
||||||
|
t.Fatalf("request kind = %q", exchange.RequestKind)
|
||||||
|
}
|
||||||
|
if !strings.Contains(compactJSON(t, exchange.Request.DecodedJSON), `"source_conversation_id":"source-conversation"`) {
|
||||||
|
t.Fatalf("unexpected decoded request:\n%s", exchange.Request.DecodedJSON)
|
||||||
|
}
|
||||||
|
if exchange.Request.DecodeError != "" {
|
||||||
|
t.Fatalf("decode error = %q", exchange.Request.DecodeError)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func compactJSON(t *testing.T, value string) string {
|
||||||
|
t.Helper()
|
||||||
|
var compact bytes.Buffer
|
||||||
|
if err := json.Compact(&compact, []byte(value)); err != nil {
|
||||||
|
t.Fatalf("compact JSON: %v\n%s", err, value)
|
||||||
|
}
|
||||||
|
return compact.String()
|
||||||
|
}
|
||||||
@@ -0,0 +1,447 @@
|
|||||||
|
package proxydebugger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/tls"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"cursor/internal/certs"
|
||||||
|
|
||||||
|
"github.com/elazarl/goproxy"
|
||||||
|
)
|
||||||
|
|
||||||
|
type exchangeContext struct {
|
||||||
|
id string
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server runs the HTTPS debugging proxy and its local web UI.
|
||||||
|
type Server struct {
|
||||||
|
config Config
|
||||||
|
certManager *certs.Manager
|
||||||
|
store *exchangeStore
|
||||||
|
counter atomic.Uint64
|
||||||
|
proxyServer *http.Server
|
||||||
|
uiServer *http.Server
|
||||||
|
proxyLn net.Listener
|
||||||
|
uiLn net.Listener
|
||||||
|
runMu sync.Mutex
|
||||||
|
}
|
||||||
|
|
||||||
|
// New creates a standalone Cursor protocol debugger.
|
||||||
|
func New(config Config) (*Server, error) {
|
||||||
|
config = config.normalized()
|
||||||
|
if err := validateLoopbackAddress(config.UIAddr); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
manager, err := certs.NewEmbeddedManager()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("加载 MITM CA 失败:%w", err)
|
||||||
|
}
|
||||||
|
server := &Server{
|
||||||
|
config: config,
|
||||||
|
certManager: manager,
|
||||||
|
store: newExchangeStore(config.MaxExchanges),
|
||||||
|
}
|
||||||
|
proxyHandler, err := server.newProxyHandler()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
server.proxyServer = &http.Server{
|
||||||
|
Handler: proxyHandler,
|
||||||
|
ErrorLog: log.New(io.Discard, "", 0),
|
||||||
|
}
|
||||||
|
server.uiServer = &http.Server{Handler: server.newUIHandler()}
|
||||||
|
return server, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start starts both listeners without modifying Cursor or system proxy settings.
|
||||||
|
func (server *Server) Start() error {
|
||||||
|
server.runMu.Lock()
|
||||||
|
defer server.runMu.Unlock()
|
||||||
|
if server.proxyLn != nil || server.uiLn != nil {
|
||||||
|
return errors.New("调试代理已经启动")
|
||||||
|
}
|
||||||
|
proxyListener, err := net.Listen("tcp", server.config.ProxyAddr)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("启动代理监听失败:%w", err)
|
||||||
|
}
|
||||||
|
uiListener, err := net.Listen("tcp", server.config.UIAddr)
|
||||||
|
if err != nil {
|
||||||
|
_ = proxyListener.Close()
|
||||||
|
return fmt.Errorf("启动调试界面失败:%w", err)
|
||||||
|
}
|
||||||
|
server.proxyLn = proxyListener
|
||||||
|
server.uiLn = uiListener
|
||||||
|
go func() { _ = server.proxyServer.Serve(proxyListener) }()
|
||||||
|
go func() { _ = server.uiServer.Serve(uiListener) }()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close stops both listeners.
|
||||||
|
func (server *Server) Close(ctx context.Context) error {
|
||||||
|
server.runMu.Lock()
|
||||||
|
proxyServer := server.proxyServer
|
||||||
|
uiServer := server.uiServer
|
||||||
|
server.proxyLn = nil
|
||||||
|
server.uiLn = nil
|
||||||
|
server.runMu.Unlock()
|
||||||
|
var errorsList []error
|
||||||
|
if proxyServer != nil {
|
||||||
|
if err := proxyServer.Shutdown(ctx); err != nil {
|
||||||
|
errorsList = append(errorsList, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if uiServer != nil {
|
||||||
|
if err := uiServer.Shutdown(ctx); err != nil {
|
||||||
|
errorsList = append(errorsList, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.Join(errorsList...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) ProxyAddr() string { return server.config.ProxyAddr }
|
||||||
|
func (server *Server) UIAddr() string { return server.config.UIAddr }
|
||||||
|
func (server *Server) UIURL() string { return "http://" + browserAddress(server.config.UIAddr) }
|
||||||
|
|
||||||
|
func (server *Server) newProxyHandler() (*goproxy.ProxyHttpServer, error) {
|
||||||
|
proxy := goproxy.NewProxyHttpServer()
|
||||||
|
proxy.Verbose = false
|
||||||
|
proxy.AllowHTTP2 = true
|
||||||
|
proxy.Logger = log.New(io.Discard, "", 0)
|
||||||
|
proxy.ConnectionErrHandler = func(_ io.Writer, context *goproxy.ProxyCtx, connectionErr error) {
|
||||||
|
id := exchangeID(context)
|
||||||
|
if id == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
server.store.update(id, func(exchange *Exchange) {
|
||||||
|
exchange.State = "error"
|
||||||
|
exchange.Error = connectionErr.Error()
|
||||||
|
exchange.DurationMS = elapsedMS(exchange.StartedAt)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
proxy.Tr = &http.Transport{
|
||||||
|
Proxy: nil,
|
||||||
|
DialContext: (&net.Dialer{Timeout: 10 * time.Second, KeepAlive: 30 * time.Second}).DialContext,
|
||||||
|
ForceAttemptHTTP2: true,
|
||||||
|
MaxIdleConns: 200,
|
||||||
|
IdleConnTimeout: 90 * time.Second,
|
||||||
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
|
ExpectContinueTimeout: 1 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
caCertificate, err := server.certManager.CATLSCertificate()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("读取 MITM CA 失败:%w", err)
|
||||||
|
}
|
||||||
|
baseTLSConfig := goproxy.TLSConfigFromCA(caCertificate)
|
||||||
|
mitmAction := &goproxy.ConnectAction{
|
||||||
|
Action: goproxy.ConnectMitm,
|
||||||
|
TLSConfig: func(host string, context *goproxy.ProxyCtx) (*tls.Config, error) {
|
||||||
|
return baseTLSConfig(host, context)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
proxy.OnRequest().HandleConnectFunc(func(host string, _ *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
|
||||||
|
if server.matchesTargetHost(host) {
|
||||||
|
return mitmAction, host
|
||||||
|
}
|
||||||
|
return goproxy.OkConnect, host
|
||||||
|
})
|
||||||
|
|
||||||
|
proxy.OnRequest().DoFunc(server.captureRequest)
|
||||||
|
proxy.OnResponse().DoFunc(server.captureResponse)
|
||||||
|
return proxy, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) captureRequest(request *http.Request, context *goproxy.ProxyCtx) (*http.Request, *http.Response) {
|
||||||
|
if request == nil || request.Method == http.MethodConnect || !server.matchesHTTPRequest(request) {
|
||||||
|
return request, nil
|
||||||
|
}
|
||||||
|
id := strconv.FormatUint(server.counter.Add(1), 10)
|
||||||
|
path := request.URL.Path
|
||||||
|
requestCodec := requestContentCodec(path, request.Header)
|
||||||
|
exchange := &Exchange{
|
||||||
|
ExchangeSummary: ExchangeSummary{
|
||||||
|
ID: id,
|
||||||
|
StartedAt: time.Now(),
|
||||||
|
Method: request.Method,
|
||||||
|
URL: request.URL.String(),
|
||||||
|
Host: request.URL.Host,
|
||||||
|
Path: path,
|
||||||
|
State: "pending",
|
||||||
|
},
|
||||||
|
Request: Payload{
|
||||||
|
Headers: sortedHeaders(request.Header),
|
||||||
|
ContentType: request.Header.Get("Content-Type"),
|
||||||
|
ContentCodec: requestCodec,
|
||||||
|
Frames: make([]FrameView, 0),
|
||||||
|
},
|
||||||
|
Response: Payload{Headers: make([]Header, 0), Frames: make([]FrameView, 0)},
|
||||||
|
}
|
||||||
|
server.store.create(exchange)
|
||||||
|
context.UserData = exchangeContext{id: id}
|
||||||
|
|
||||||
|
if request.Body == nil {
|
||||||
|
server.finishRequestBody(id, path, requestCodec, nil, 0, false, nil)
|
||||||
|
return request, nil
|
||||||
|
}
|
||||||
|
var frameDecoder *connectFrameDecoder
|
||||||
|
if path == "/agent.v1.AgentService/RunSSE" {
|
||||||
|
frameDecoder = newConnectFrameDecoder(
|
||||||
|
"aiserver.v1.BidiRequestId",
|
||||||
|
requestCodec,
|
||||||
|
server.config.MaxFrames,
|
||||||
|
func(frame FrameView) { server.appendRequestFrame(id, frame) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
request.Body = newCaptureReadCloser(
|
||||||
|
request.Body,
|
||||||
|
server.config.MaxCaptureBytes,
|
||||||
|
func(chunk []byte) {
|
||||||
|
if frameDecoder != nil {
|
||||||
|
frameDecoder.Write(chunk)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
func(captured []byte, size int64, truncated bool, readErr error) {
|
||||||
|
if frameDecoder != nil {
|
||||||
|
frameDecoder.Close()
|
||||||
|
}
|
||||||
|
server.finishRequestBody(id, path, requestCodec, captured, size, truncated, readErr)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return request, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) captureResponse(response *http.Response, context *goproxy.ProxyCtx) *http.Response {
|
||||||
|
id := exchangeID(context)
|
||||||
|
if id == "" || response == nil {
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
path := ""
|
||||||
|
if response.Request != nil && response.Request.URL != nil {
|
||||||
|
path = response.Request.URL.Path
|
||||||
|
}
|
||||||
|
responseCodec := responseContentCodec(path, response.Header)
|
||||||
|
server.store.update(id, func(exchange *Exchange) {
|
||||||
|
exchange.Status = response.StatusCode
|
||||||
|
exchange.State = "streaming"
|
||||||
|
exchange.DurationMS = elapsedMS(exchange.StartedAt)
|
||||||
|
exchange.Response.Headers = sortedHeaders(response.Header)
|
||||||
|
exchange.Response.ContentType = response.Header.Get("Content-Type")
|
||||||
|
exchange.Response.ContentCodec = responseCodec
|
||||||
|
})
|
||||||
|
if response.Body == nil {
|
||||||
|
server.finishResponseBody(id, path, responseCodec, nil, 0, false, nil)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
var frameDecoder *connectFrameDecoder
|
||||||
|
if path == "/agent.v1.AgentService/RunSSE" {
|
||||||
|
frameDecoder = newConnectFrameDecoder(
|
||||||
|
"agent.v1.AgentServerMessage",
|
||||||
|
responseCodec,
|
||||||
|
server.config.MaxFrames,
|
||||||
|
func(frame FrameView) { server.appendResponseFrame(id, frame) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
response.Body = newCaptureReadCloser(
|
||||||
|
response.Body,
|
||||||
|
server.config.MaxCaptureBytes,
|
||||||
|
func(chunk []byte) {
|
||||||
|
if frameDecoder != nil {
|
||||||
|
frameDecoder.Write(chunk)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
func(captured []byte, size int64, truncated bool, readErr error) {
|
||||||
|
if frameDecoder != nil {
|
||||||
|
frameDecoder.Close()
|
||||||
|
}
|
||||||
|
server.finishResponseBody(id, path, responseCodec, captured, size, truncated, readErr)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) finishRequestBody(id, path string, codec string, captured []byte, size int64, truncated bool, readErr error) {
|
||||||
|
decodePayload := captured
|
||||||
|
var contentDecodeErr error
|
||||||
|
if decodesUnaryRequest(path) && truncated {
|
||||||
|
contentDecodeErr = errors.New("请求正文超过抓取上限,无法完整解码")
|
||||||
|
} else if decodesUnaryRequest(path) && codec != "" && !strings.EqualFold(codec, "identity") {
|
||||||
|
decodePayload, contentDecodeErr = decompressPayload(captured, codec)
|
||||||
|
}
|
||||||
|
decodedJSON, kind, requestID, decodeErr := "", "", "", contentDecodeErr
|
||||||
|
if decodeErr == nil {
|
||||||
|
decodedJSON, kind, requestID, decodeErr = decodeUnaryRequest(path, decodePayload)
|
||||||
|
}
|
||||||
|
server.store.update(id, func(exchange *Exchange) {
|
||||||
|
exchange.RequestBytes = size
|
||||||
|
exchange.Request.Size = size
|
||||||
|
exchange.Request.RawHex = rawHex(captured)
|
||||||
|
exchange.Request.RawTruncated = truncated
|
||||||
|
if decodedJSON != "" {
|
||||||
|
exchange.Request.DecodedJSON = decodedJSON
|
||||||
|
}
|
||||||
|
if kind != "" {
|
||||||
|
exchange.RequestKind = kind
|
||||||
|
}
|
||||||
|
if requestID != "" {
|
||||||
|
exchange.RequestID = requestID
|
||||||
|
}
|
||||||
|
if decodeErr != nil {
|
||||||
|
exchange.Request.DecodeError = decodeErr.Error()
|
||||||
|
}
|
||||||
|
if readErr != nil && !errors.Is(readErr, io.EOF) {
|
||||||
|
exchange.Error = readErr.Error()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func requestContentCodec(path string, headers http.Header) string {
|
||||||
|
if path == "/agent.v1.AgentService/RunSSE" {
|
||||||
|
return strings.TrimSpace(headers.Get("Connect-Content-Encoding"))
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(headers.Get("Content-Encoding"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func responseContentCodec(path string, headers http.Header) string {
|
||||||
|
if path == "/agent.v1.AgentService/RunSSE" {
|
||||||
|
return strings.TrimSpace(headers.Get("Connect-Content-Encoding"))
|
||||||
|
}
|
||||||
|
if !decodesUnaryResponse(path) {
|
||||||
|
if codec := strings.TrimSpace(headers.Get("Connect-Content-Encoding")); codec != "" {
|
||||||
|
return codec
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(headers.Get("Content-Encoding"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) finishResponseBody(id, path, codec string, captured []byte, size int64, truncated bool, readErr error) {
|
||||||
|
decodePayload := captured
|
||||||
|
var contentDecodeErr error
|
||||||
|
if decodesUnaryResponse(path) && truncated {
|
||||||
|
contentDecodeErr = errors.New("响应正文超过抓取上限,无法完整解码")
|
||||||
|
} else if decodesUnaryResponse(path) && codec != "" && !strings.EqualFold(codec, "identity") {
|
||||||
|
decodePayload, contentDecodeErr = decompressPayload(captured, codec)
|
||||||
|
}
|
||||||
|
decodedJSON, kind, decodeErr := "", "", contentDecodeErr
|
||||||
|
if decodeErr == nil {
|
||||||
|
decodedJSON, kind, decodeErr = decodeUnaryResponse(path, decodePayload)
|
||||||
|
}
|
||||||
|
server.store.update(id, func(exchange *Exchange) {
|
||||||
|
exchange.ResponseBytes = size
|
||||||
|
exchange.Response.Size = size
|
||||||
|
exchange.Response.RawHex = rawHex(captured)
|
||||||
|
exchange.Response.RawTruncated = truncated
|
||||||
|
if decodedJSON != "" {
|
||||||
|
exchange.Response.DecodedJSON = decodedJSON
|
||||||
|
}
|
||||||
|
if kind != "" {
|
||||||
|
exchange.ResponseKind = kind
|
||||||
|
}
|
||||||
|
if decodeErr != nil {
|
||||||
|
exchange.Response.DecodeError = decodeErr.Error()
|
||||||
|
}
|
||||||
|
exchange.DurationMS = elapsedMS(exchange.StartedAt)
|
||||||
|
exchange.State = "completed"
|
||||||
|
if readErr != nil && !errors.Is(readErr, io.EOF) {
|
||||||
|
exchange.State = "error"
|
||||||
|
exchange.Error = readErr.Error()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) appendRequestFrame(id string, frame FrameView) {
|
||||||
|
server.store.update(id, func(exchange *Exchange) {
|
||||||
|
if len(exchange.Request.Frames) < server.config.MaxFrames {
|
||||||
|
exchange.Request.Frames = append(exchange.Request.Frames, frame)
|
||||||
|
}
|
||||||
|
if frame.Kind != "" {
|
||||||
|
exchange.RequestKind = frame.Kind
|
||||||
|
}
|
||||||
|
if frame.RequestID != "" {
|
||||||
|
exchange.RequestID = frame.RequestID
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) appendResponseFrame(id string, frame FrameView) {
|
||||||
|
server.store.update(id, func(exchange *Exchange) {
|
||||||
|
if len(exchange.Response.Frames) < server.config.MaxFrames {
|
||||||
|
exchange.Response.Frames = append(exchange.Response.Frames, frame)
|
||||||
|
}
|
||||||
|
exchange.FrameCount = len(exchange.Response.Frames)
|
||||||
|
if frame.Kind != "" && frame.Kind != "end_stream" {
|
||||||
|
exchange.ResponseKind = frame.Kind
|
||||||
|
}
|
||||||
|
if frame.Error != "" {
|
||||||
|
exchange.Response.DecodeError = frame.Error
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) matchesHTTPRequest(request *http.Request) bool {
|
||||||
|
if request == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
host := request.Host
|
||||||
|
if request.URL != nil && request.URL.Host != "" {
|
||||||
|
host = request.URL.Host
|
||||||
|
}
|
||||||
|
return server.matchesTargetHost(host)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) matchesTargetHost(host string) bool {
|
||||||
|
host = strings.TrimSpace(strings.ToLower(host))
|
||||||
|
if parsedHost, _, err := net.SplitHostPort(host); err == nil {
|
||||||
|
host = parsedHost
|
||||||
|
}
|
||||||
|
target := strings.TrimSpace(strings.ToLower(server.config.TargetHost))
|
||||||
|
return host == target
|
||||||
|
}
|
||||||
|
|
||||||
|
func exchangeID(context *goproxy.ProxyCtx) string {
|
||||||
|
if context == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
value, ok := context.UserData.(exchangeContext)
|
||||||
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return value.id
|
||||||
|
}
|
||||||
|
|
||||||
|
func browserAddress(address string) string {
|
||||||
|
host, port, err := net.SplitHostPort(address)
|
||||||
|
if err != nil {
|
||||||
|
return address
|
||||||
|
}
|
||||||
|
if host == "" || host == "0.0.0.0" || host == "::" {
|
||||||
|
host = "127.0.0.1"
|
||||||
|
}
|
||||||
|
return net.JoinHostPort(host, port)
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateLoopbackAddress(address string) error {
|
||||||
|
host, _, err := net.SplitHostPort(address)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("调试界面监听地址无效:%w", err)
|
||||||
|
}
|
||||||
|
if strings.EqualFold(host, "localhost") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
ip := net.ParseIP(host)
|
||||||
|
if ip == nil || !ip.IsLoopback() {
|
||||||
|
return errors.New("调试界面只能监听本机回环地址")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
package proxydebugger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sort"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type exchangeStore struct {
|
||||||
|
mu sync.RWMutex
|
||||||
|
max int
|
||||||
|
order []string
|
||||||
|
exchanges map[string]*Exchange
|
||||||
|
subscribers map[chan storeEvent]struct{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newExchangeStore(max int) *exchangeStore {
|
||||||
|
return &exchangeStore{
|
||||||
|
max: max,
|
||||||
|
exchanges: make(map[string]*Exchange),
|
||||||
|
subscribers: make(map[chan storeEvent]struct{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *exchangeStore) create(exchange *Exchange) {
|
||||||
|
store.mu.Lock()
|
||||||
|
store.exchanges[exchange.ID] = exchange
|
||||||
|
store.order = append([]string{exchange.ID}, store.order...)
|
||||||
|
for len(store.order) > store.max {
|
||||||
|
oldest := store.order[len(store.order)-1]
|
||||||
|
store.order = store.order[:len(store.order)-1]
|
||||||
|
delete(store.exchanges, oldest)
|
||||||
|
}
|
||||||
|
store.mu.Unlock()
|
||||||
|
store.publish(storeEvent{Type: "created", ID: exchange.ID})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *exchangeStore) update(id string, apply func(*Exchange)) {
|
||||||
|
store.mu.Lock()
|
||||||
|
if exchange := store.exchanges[id]; exchange != nil {
|
||||||
|
apply(exchange)
|
||||||
|
}
|
||||||
|
store.mu.Unlock()
|
||||||
|
store.publish(storeEvent{Type: "updated", ID: id})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *exchangeStore) summaries() []ExchangeSummary {
|
||||||
|
store.mu.RLock()
|
||||||
|
defer store.mu.RUnlock()
|
||||||
|
result := make([]ExchangeSummary, 0, len(store.order))
|
||||||
|
for _, id := range store.order {
|
||||||
|
if exchange := store.exchanges[id]; exchange != nil {
|
||||||
|
result = append(result, exchange.ExchangeSummary)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *exchangeStore) get(id string) (Exchange, bool) {
|
||||||
|
store.mu.RLock()
|
||||||
|
defer store.mu.RUnlock()
|
||||||
|
exchange := store.exchanges[id]
|
||||||
|
if exchange == nil {
|
||||||
|
return Exchange{}, false
|
||||||
|
}
|
||||||
|
return cloneExchange(*exchange), true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *exchangeStore) clear() {
|
||||||
|
store.mu.Lock()
|
||||||
|
store.order = nil
|
||||||
|
store.exchanges = make(map[string]*Exchange)
|
||||||
|
store.mu.Unlock()
|
||||||
|
store.publish(storeEvent{Type: "cleared"})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *exchangeStore) subscribe() (<-chan storeEvent, func()) {
|
||||||
|
updates := make(chan storeEvent, 32)
|
||||||
|
store.mu.Lock()
|
||||||
|
store.subscribers[updates] = struct{}{}
|
||||||
|
store.mu.Unlock()
|
||||||
|
return updates, func() {
|
||||||
|
store.mu.Lock()
|
||||||
|
if _, ok := store.subscribers[updates]; ok {
|
||||||
|
delete(store.subscribers, updates)
|
||||||
|
close(updates)
|
||||||
|
}
|
||||||
|
store.mu.Unlock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *exchangeStore) publish(event storeEvent) {
|
||||||
|
store.mu.RLock()
|
||||||
|
defer store.mu.RUnlock()
|
||||||
|
for subscriber := range store.subscribers {
|
||||||
|
select {
|
||||||
|
case subscriber <- event:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func cloneExchange(exchange Exchange) Exchange {
|
||||||
|
exchange.Request = clonePayload(exchange.Request)
|
||||||
|
exchange.Response = clonePayload(exchange.Response)
|
||||||
|
return exchange
|
||||||
|
}
|
||||||
|
|
||||||
|
func clonePayload(payload Payload) Payload {
|
||||||
|
payload.Headers = append([]Header(nil), payload.Headers...)
|
||||||
|
payload.Frames = append([]FrameView(nil), payload.Frames...)
|
||||||
|
return payload
|
||||||
|
}
|
||||||
|
|
||||||
|
func elapsedMS(startedAt time.Time) int64 {
|
||||||
|
if startedAt.IsZero() {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return time.Since(startedAt).Milliseconds()
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortedHeaders(headers map[string][]string) []Header {
|
||||||
|
result := make([]Header, 0, len(headers))
|
||||||
|
for name, values := range headers {
|
||||||
|
value := ""
|
||||||
|
for index, item := range values {
|
||||||
|
if index > 0 {
|
||||||
|
value += ", "
|
||||||
|
}
|
||||||
|
value += item
|
||||||
|
}
|
||||||
|
if isSensitiveHeader(name) && value != "" {
|
||||||
|
value = "[已隐藏]"
|
||||||
|
}
|
||||||
|
result = append(result, Header{Name: name, Value: value})
|
||||||
|
}
|
||||||
|
sort.Slice(result, func(left, right int) bool {
|
||||||
|
return result[left].Name < result[right].Name
|
||||||
|
})
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func isSensitiveHeader(name string) bool {
|
||||||
|
switch httpCanonicalLower(name) {
|
||||||
|
case "authorization", "cookie", "set-cookie", "proxy-authorization", "x-api-key":
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func httpCanonicalLower(value string) string {
|
||||||
|
buffer := make([]byte, len(value))
|
||||||
|
for index := range value {
|
||||||
|
character := value[index]
|
||||||
|
if character >= 'A' && character <= 'Z' {
|
||||||
|
character += 'a' - 'A'
|
||||||
|
}
|
||||||
|
buffer[index] = character
|
||||||
|
}
|
||||||
|
return string(buffer)
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package proxydebugger
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultProxyAddr = "127.0.0.1:9090"
|
||||||
|
defaultUIAddr = "127.0.0.1:9091"
|
||||||
|
defaultTargetHost = "api2.cursor.sh"
|
||||||
|
defaultMaxExchanges = 200
|
||||||
|
defaultMaxCaptureBytes = 2 << 20
|
||||||
|
defaultMaxFrames = 2000
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config controls the standalone proxy debugger.
|
||||||
|
type Config struct {
|
||||||
|
ProxyAddr string
|
||||||
|
UIAddr string
|
||||||
|
TargetHost string
|
||||||
|
MaxExchanges int
|
||||||
|
MaxCaptureBytes int
|
||||||
|
MaxFrames int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (config Config) normalized() Config {
|
||||||
|
if config.ProxyAddr == "" {
|
||||||
|
config.ProxyAddr = defaultProxyAddr
|
||||||
|
}
|
||||||
|
if config.UIAddr == "" {
|
||||||
|
config.UIAddr = defaultUIAddr
|
||||||
|
}
|
||||||
|
if config.TargetHost == "" {
|
||||||
|
config.TargetHost = defaultTargetHost
|
||||||
|
}
|
||||||
|
if config.MaxExchanges <= 0 {
|
||||||
|
config.MaxExchanges = defaultMaxExchanges
|
||||||
|
}
|
||||||
|
if config.MaxCaptureBytes <= 0 {
|
||||||
|
config.MaxCaptureBytes = defaultMaxCaptureBytes
|
||||||
|
}
|
||||||
|
if config.MaxFrames <= 0 {
|
||||||
|
config.MaxFrames = defaultMaxFrames
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExchangeSummary is the compact request-list representation.
|
||||||
|
type ExchangeSummary struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
StartedAt time.Time `json:"startedAt"`
|
||||||
|
Method string `json:"method"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Host string `json:"host"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
State string `json:"state"`
|
||||||
|
DurationMS int64 `json:"durationMs"`
|
||||||
|
RequestBytes int64 `json:"requestBytes"`
|
||||||
|
ResponseBytes int64 `json:"responseBytes"`
|
||||||
|
RequestID string `json:"requestId,omitempty"`
|
||||||
|
RequestKind string `json:"requestKind,omitempty"`
|
||||||
|
ResponseKind string `json:"responseKind,omitempty"`
|
||||||
|
FrameCount int `json:"frameCount"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exchange contains the request and response detail shown by the debugger.
|
||||||
|
type Exchange struct {
|
||||||
|
ExchangeSummary
|
||||||
|
Request Payload `json:"request"`
|
||||||
|
Response Payload `json:"response"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Payload contains headers, captured raw bytes, and decoded protobuf frames.
|
||||||
|
type Payload struct {
|
||||||
|
Headers []Header `json:"headers"`
|
||||||
|
ContentType string `json:"contentType,omitempty"`
|
||||||
|
ContentCodec string `json:"contentCodec,omitempty"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
RawHex string `json:"rawHex,omitempty"`
|
||||||
|
RawTruncated bool `json:"rawTruncated,omitempty"`
|
||||||
|
DecodedJSON string `json:"decodedJson,omitempty"`
|
||||||
|
DecodeError string `json:"decodeError,omitempty"`
|
||||||
|
Frames []FrameView `json:"frames,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Header is a stable, sorted HTTP header pair.
|
||||||
|
type Header struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// FrameView describes one Connect streaming envelope.
|
||||||
|
type FrameView struct {
|
||||||
|
Index int `json:"index"`
|
||||||
|
Flags uint8 `json:"flags"`
|
||||||
|
Length int `json:"length"`
|
||||||
|
Compressed bool `json:"compressed"`
|
||||||
|
EndStream bool `json:"endStream"`
|
||||||
|
Kind string `json:"kind,omitempty"`
|
||||||
|
MessageType string `json:"messageType,omitempty"`
|
||||||
|
RequestID string `json:"requestId,omitempty"`
|
||||||
|
JSON string `json:"json,omitempty"`
|
||||||
|
RawHex string `json:"rawHex,omitempty"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type storeEvent struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
ID string `json:"id,omitempty"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
package proxydebugger
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"cursor/internal/certs"
|
||||||
|
)
|
||||||
|
|
||||||
|
//go:embed web/*
|
||||||
|
var webAssets embed.FS
|
||||||
|
|
||||||
|
func (server *Server) newUIHandler() http.Handler {
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("GET /api/status", server.handleStatus)
|
||||||
|
mux.HandleFunc("GET /api/exchanges", server.handleExchangeList)
|
||||||
|
mux.HandleFunc("GET /api/exchanges/{id}", server.handleExchangeDetail)
|
||||||
|
mux.HandleFunc("DELETE /api/exchanges", server.handleClearExchanges)
|
||||||
|
mux.HandleFunc("GET /api/events", server.handleEvents)
|
||||||
|
mux.HandleFunc("GET /api/ca.crt", server.handleCACertificate)
|
||||||
|
assets, _ := fs.Sub(webAssets, "web")
|
||||||
|
fileServer := http.FileServer(http.FS(assets))
|
||||||
|
mux.Handle("/", fileServer)
|
||||||
|
return securityHeaders(mux)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) handleStatus(writer http.ResponseWriter, _ *http.Request) {
|
||||||
|
writeJSON(writer, http.StatusOK, map[string]any{
|
||||||
|
"proxyAddr": server.config.ProxyAddr,
|
||||||
|
"uiAddr": server.config.UIAddr,
|
||||||
|
"targetHost": server.config.TargetHost,
|
||||||
|
"running": true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) handleExchangeList(writer http.ResponseWriter, _ *http.Request) {
|
||||||
|
writeJSON(writer, http.StatusOK, server.store.summaries())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) handleExchangeDetail(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
id := strings.TrimSpace(request.PathValue("id"))
|
||||||
|
exchange, ok := server.store.get(id)
|
||||||
|
if !ok {
|
||||||
|
writeJSON(writer, http.StatusNotFound, map[string]string{"error": "请求记录不存在"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writeJSON(writer, http.StatusOK, exchange)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) handleClearExchanges(writer http.ResponseWriter, _ *http.Request) {
|
||||||
|
server.store.clear()
|
||||||
|
writer.WriteHeader(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) handleEvents(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
flusher, ok := writer.(http.Flusher)
|
||||||
|
if !ok {
|
||||||
|
http.Error(writer, "当前响应不支持流式刷新", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writer.Header().Set("Content-Type", "text/event-stream")
|
||||||
|
writer.Header().Set("Cache-Control", "no-cache")
|
||||||
|
writer.Header().Set("Connection", "keep-alive")
|
||||||
|
updates, unsubscribe := server.store.subscribe()
|
||||||
|
defer unsubscribe()
|
||||||
|
fmt.Fprint(writer, "event: ready\ndata: {}\n\n")
|
||||||
|
flusher.Flush()
|
||||||
|
heartbeat := time.NewTicker(15 * time.Second)
|
||||||
|
defer heartbeat.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-request.Context().Done():
|
||||||
|
return
|
||||||
|
case event, open := <-updates:
|
||||||
|
if !open {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
payload, _ := json.Marshal(event)
|
||||||
|
fmt.Fprintf(writer, "event: update\ndata: %s\n\n", payload)
|
||||||
|
flusher.Flush()
|
||||||
|
case <-heartbeat.C:
|
||||||
|
fmt.Fprint(writer, ": heartbeat\n\n")
|
||||||
|
flusher.Flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (server *Server) handleCACertificate(writer http.ResponseWriter, _ *http.Request) {
|
||||||
|
writer.Header().Set("Content-Type", "application/x-x509-ca-cert")
|
||||||
|
writer.Header().Set("Content-Disposition", `attachment; filename="cursor-local-proxy-ca.crt"`)
|
||||||
|
_, _ = writer.Write(certs.EmbeddedCACertPEM())
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeJSON(writer http.ResponseWriter, status int, payload any) {
|
||||||
|
writer.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
writer.WriteHeader(status)
|
||||||
|
_ = json.NewEncoder(writer).Encode(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
func securityHeaders(next http.Handler) http.Handler {
|
||||||
|
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
writer.Header().Set("X-Content-Type-Options", "nosniff")
|
||||||
|
writer.Header().Set("Referrer-Policy", "no-referrer")
|
||||||
|
writer.Header().Set("Content-Security-Policy", "default-src 'self'; script-src 'self'; style-src 'self'; connect-src 'self'")
|
||||||
|
next.ServeHTTP(writer, request)
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,460 @@
|
|||||||
|
import { getLocale, setLocale, t, translateDocument } from "./i18n.js";
|
||||||
|
|
||||||
|
const state = {
|
||||||
|
status: null,
|
||||||
|
exchanges: [],
|
||||||
|
selectedId: null,
|
||||||
|
selected: null,
|
||||||
|
search: "",
|
||||||
|
requestId: "",
|
||||||
|
endpoint: "all",
|
||||||
|
sortOrder: "desc",
|
||||||
|
paused: false,
|
||||||
|
pendingRefresh: false,
|
||||||
|
connection: { connected: false, key: "status.connecting", values: {} },
|
||||||
|
tabs: {
|
||||||
|
request: "body",
|
||||||
|
response: "frames",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const elements = {
|
||||||
|
statusDot: document.querySelector("#status-dot"),
|
||||||
|
statusText: document.querySelector("#status-text"),
|
||||||
|
proxyAddress: document.querySelector("#proxy-address"),
|
||||||
|
targetHost: document.querySelector("#target-host"),
|
||||||
|
connectionLabel: document.querySelector("#connection-label"),
|
||||||
|
trafficSummary: document.querySelector("#traffic-summary"),
|
||||||
|
searchInput: document.querySelector("#search-input"),
|
||||||
|
requestIdInput: document.querySelector("#request-id-input"),
|
||||||
|
endpointFilter: document.querySelector("#endpoint-filter"),
|
||||||
|
sortOrder: document.querySelector("#sort-order"),
|
||||||
|
requestCount: document.querySelector("#request-count"),
|
||||||
|
requestList: document.querySelector("#request-list"),
|
||||||
|
emptyState: document.querySelector("#empty-state"),
|
||||||
|
selectionSummary: document.querySelector("#selection-summary"),
|
||||||
|
requestContent: document.querySelector("#request-content"),
|
||||||
|
responseContent: document.querySelector("#response-content"),
|
||||||
|
pauseButton: document.querySelector("#pause-button"),
|
||||||
|
clearButton: document.querySelector("#clear-button"),
|
||||||
|
localeSelect: document.querySelector("#locale-select"),
|
||||||
|
workspace: document.querySelector("#workspace"),
|
||||||
|
splitter: document.querySelector("#horizontal-splitter"),
|
||||||
|
};
|
||||||
|
|
||||||
|
async function fetchJSON(url, options) {
|
||||||
|
const response = await fetch(url, options);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`${response.status} ${response.statusText}`);
|
||||||
|
}
|
||||||
|
if (response.status === 204) return null;
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadStatus() {
|
||||||
|
state.status = await fetchJSON("/api/status");
|
||||||
|
elements.statusDot.classList.toggle("online", Boolean(state.status.running));
|
||||||
|
renderRuntimeStatus();
|
||||||
|
elements.proxyAddress.textContent = `http://${state.status.proxyAddr}`;
|
||||||
|
elements.targetHost.textContent = state.status.targetHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshList() {
|
||||||
|
state.exchanges = await fetchJSON("/api/exchanges");
|
||||||
|
renderList();
|
||||||
|
renderTrafficSummary();
|
||||||
|
if (state.selectedId && state.exchanges.some((item) => item.id === state.selectedId)) {
|
||||||
|
await refreshDetail(state.selectedId);
|
||||||
|
} else if (state.selectedId) {
|
||||||
|
state.selectedId = null;
|
||||||
|
state.selected = null;
|
||||||
|
renderDetail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function refreshDetail(id) {
|
||||||
|
if (!id) return;
|
||||||
|
try {
|
||||||
|
const detail = await fetchJSON(`/api/exchanges/${encodeURIComponent(id)}`);
|
||||||
|
if (state.selectedId !== id) return;
|
||||||
|
state.selected = detail;
|
||||||
|
renderDetail();
|
||||||
|
} catch (error) {
|
||||||
|
if (state.selectedId === id) {
|
||||||
|
state.selected = null;
|
||||||
|
renderDetailError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleRefresh() {
|
||||||
|
if (state.paused) {
|
||||||
|
state.pendingRefresh = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (state.pendingRefresh) return;
|
||||||
|
state.pendingRefresh = true;
|
||||||
|
window.setTimeout(async () => {
|
||||||
|
state.pendingRefresh = false;
|
||||||
|
try {
|
||||||
|
await refreshList();
|
||||||
|
} catch (error) {
|
||||||
|
setConnectionState(false, "connection.refreshFailed", { message: error.message });
|
||||||
|
}
|
||||||
|
}, 90);
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectEvents() {
|
||||||
|
const events = new EventSource("/api/events");
|
||||||
|
events.addEventListener("open", () => setConnectionState(true, "connection.live"));
|
||||||
|
events.addEventListener("update", scheduleRefresh);
|
||||||
|
events.addEventListener("error", () => setConnectionState(false, "connection.retrying"));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setConnectionState(connected, key, values = {}) {
|
||||||
|
state.connection = { connected, key, values };
|
||||||
|
renderConnectionState();
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderRuntimeStatus() {
|
||||||
|
if (!state.status) {
|
||||||
|
elements.statusText.textContent = t("status.connecting");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
elements.statusText.textContent = t(state.status.running ? "status.running" : "status.stopped");
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderConnectionState() {
|
||||||
|
const { connected, key, values } = state.connection;
|
||||||
|
elements.connectionLabel.textContent = t(key, values);
|
||||||
|
elements.statusDot.classList.toggle("online", connected && Boolean(state.status?.running));
|
||||||
|
}
|
||||||
|
|
||||||
|
function filteredExchanges() {
|
||||||
|
const query = state.search.trim().toLowerCase();
|
||||||
|
const requestId = state.requestId.trim().toLowerCase();
|
||||||
|
const direction = state.sortOrder === "asc" ? 1 : -1;
|
||||||
|
return state.exchanges
|
||||||
|
.filter((item) => {
|
||||||
|
if (state.endpoint === "runsse" && !item.path.toLowerCase().includes("runsse")) return false;
|
||||||
|
if (state.endpoint === "bidiappend" && !item.path.toLowerCase().includes("bidiappend")) return false;
|
||||||
|
if (state.endpoint === "fork" && !isForkTrafficPath(item.path)) return false;
|
||||||
|
if (requestId && !String(item.requestId || "").toLowerCase().includes(requestId)) return false;
|
||||||
|
if (!query) return true;
|
||||||
|
return [item.url, item.requestId, item.requestKind, item.responseKind, item.state, String(item.status)]
|
||||||
|
.filter(Boolean)
|
||||||
|
.some((value) => String(value).toLowerCase().includes(query));
|
||||||
|
})
|
||||||
|
.sort((left, right) => {
|
||||||
|
const startedAtDelta = new Date(left.startedAt).getTime() - new Date(right.startedAt).getTime();
|
||||||
|
if (startedAtDelta !== 0) return startedAtDelta * direction;
|
||||||
|
return left.id.localeCompare(right.id, undefined, { numeric: true }) * direction;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function isForkTrafficPath(path) {
|
||||||
|
const normalized = String(path || "").toLowerCase();
|
||||||
|
return ["forkbackgroundcomposer", "notifyconversationclone", "uploadconversationblobs"].some((endpoint) =>
|
||||||
|
normalized.includes(endpoint),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderList() {
|
||||||
|
const exchanges = filteredExchanges();
|
||||||
|
elements.requestCount.textContent = t("count.requests", { count: exchanges.length });
|
||||||
|
elements.emptyState.classList.toggle("hidden", exchanges.length > 0);
|
||||||
|
elements.requestList.innerHTML = exchanges
|
||||||
|
.map((item) => {
|
||||||
|
const selected = item.id === state.selectedId ? " selected" : "";
|
||||||
|
const statusClass = item.status >= 400 ? "error" : item.status ? "success" : "";
|
||||||
|
const kind = item.responseKind || item.requestKind || "-";
|
||||||
|
return `<tr class="${selected.trim()}" data-id="${escapeHTML(item.id)}">
|
||||||
|
<td><span class="row-state ${escapeHTML(item.state)}"></span></td>
|
||||||
|
<td><code>${escapeHTML(item.id)}</code></td>
|
||||||
|
<td title="${escapeHTML(item.url)}"><code>${escapeHTML(item.url)}</code></td>
|
||||||
|
<td title="${escapeHTML(item.requestId || "")}"><code class="request-id-text">${escapeHTML(item.requestId || "-")}</code></td>
|
||||||
|
<td><span class="kind-text">${escapeHTML(kind)}</span></td>
|
||||||
|
<td><span class="method-text">${escapeHTML(item.method)}</span></td>
|
||||||
|
<td><span class="status-text ${statusClass}">${item.status || "-"}</span></td>
|
||||||
|
<td>${formatBytes(item.responseBytes)}</td>
|
||||||
|
<td>${formatDuration(item.durationMs)}</td>
|
||||||
|
</tr>`;
|
||||||
|
})
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTrafficSummary() {
|
||||||
|
const totals = state.exchanges.reduce(
|
||||||
|
(result, item) => {
|
||||||
|
result.up += item.requestBytes || 0;
|
||||||
|
result.down += item.responseBytes || 0;
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
{ up: 0, down: 0 },
|
||||||
|
);
|
||||||
|
elements.trafficSummary.textContent = `↑ ${formatBytes(totals.up)} ↓ ${formatBytes(totals.down)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderDetail() {
|
||||||
|
if (!state.selected) {
|
||||||
|
elements.selectionSummary.innerHTML = `<span class="method-badge">POST</span><span class="status-badge">${escapeHTML(t("selection.waiting"))}</span><code>${escapeHTML(t("selection.prompt"))}</code>`;
|
||||||
|
elements.requestContent.innerHTML = `<div class="notice">${escapeHTML(t("notices.noRequest"))}</div>`;
|
||||||
|
elements.responseContent.innerHTML = `<div class="notice">${escapeHTML(t("notices.noResponse"))}</div>`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const item = state.selected;
|
||||||
|
const statusClass = item.status >= 200 && item.status < 400 ? "success" : "";
|
||||||
|
elements.selectionSummary.innerHTML = `<span class="method-badge">${escapeHTML(item.method)}</span><span class="status-badge ${statusClass}">${escapeHTML(item.status || formatState(item.state))}</span><code>${escapeHTML(item.url)}</code>`;
|
||||||
|
elements.requestContent.innerHTML = renderPayload(item.request, state.tabs.request);
|
||||||
|
elements.responseContent.innerHTML = renderPayload(item.response, state.tabs.response);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderDetailError(error) {
|
||||||
|
elements.requestContent.innerHTML = `<div class="notice error">${escapeHTML(error.message)}</div>`;
|
||||||
|
elements.responseContent.innerHTML = `<div class="notice error">${escapeHTML(error.message)}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderPayload(payload, tab) {
|
||||||
|
if (!payload) return `<div class="notice">${escapeHTML(t("notices.noContent"))}</div>`;
|
||||||
|
if (tab === "headers") return renderHeaders(payload.headers);
|
||||||
|
if (tab === "frames") return renderFrames(payload.frames);
|
||||||
|
if (tab === "raw") {
|
||||||
|
const body = payload.rawHex ? formatHex(payload.rawHex) : t("notices.noRaw");
|
||||||
|
return `<pre class="hex-view">${escapeHTML(body)}</pre>${renderTruncated(payload.rawTruncated)}`;
|
||||||
|
}
|
||||||
|
if (payload.decodedJson) {
|
||||||
|
return `<pre class="code-view">${escapeHTML(payload.decodedJson)}</pre>${renderDecodeError(payload.decodeError)}${renderTruncated(payload.rawTruncated)}`;
|
||||||
|
}
|
||||||
|
if (payload.frames?.length) return renderFrames(payload.frames);
|
||||||
|
if (payload.decodeError) return `<div class="notice error">${escapeHTML(payload.decodeError)}</div>`;
|
||||||
|
return `<div class="notice">${escapeHTML(t("notices.noBody"))}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderHeaders(headers = []) {
|
||||||
|
const items = Array.isArray(headers) ? headers : [];
|
||||||
|
if (!items.length) return `<div class="notice">${escapeHTML(t("notices.noHeaders"))}</div>`;
|
||||||
|
return `<table class="headers-table"><tbody>${items
|
||||||
|
.map((header) => `<tr><th>${escapeHTML(header.name)}</th><td>${escapeHTML(header.value)}</td></tr>`)
|
||||||
|
.join("")}</tbody></table>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderFrames(frames = []) {
|
||||||
|
const items = Array.isArray(frames) ? frames : [];
|
||||||
|
if (!items.length) return `<div class="notice">${escapeHTML(t("notices.noFrames"))}</div>`;
|
||||||
|
return `<div class="frame-list">${items
|
||||||
|
.map((frame) => {
|
||||||
|
const kind = frame.kind || frame.messageType || t("notices.unknown");
|
||||||
|
const flags = `0x${Number(frame.flags || 0).toString(16).padStart(2, "0")}`;
|
||||||
|
const content = frame.json
|
||||||
|
? `<pre class="code-view">${escapeHTML(frame.json)}</pre>`
|
||||||
|
: `<pre class="hex-view">${escapeHTML(formatHex(frame.rawHex || ""))}</pre>`;
|
||||||
|
return `<details class="frame-item"${frame.index === items.length - 1 ? " open" : ""}>
|
||||||
|
<summary>
|
||||||
|
<span class="frame-index">#${frame.index}</span>
|
||||||
|
<span class="frame-kind" title="${escapeHTML(kind)}">${escapeHTML(kind)}</span>
|
||||||
|
<span class="frame-size">${formatBytes(frame.length)}</span>
|
||||||
|
<span class="frame-flags">${flags}${frame.compressed ? " gzip" : ""}</span>
|
||||||
|
</summary>
|
||||||
|
${frame.error ? `<div class="frame-error">${escapeHTML(frame.error)}</div>` : content}
|
||||||
|
</details>`;
|
||||||
|
})
|
||||||
|
.join("")}</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderDecodeError(error) {
|
||||||
|
return error ? `<div class="frame-error">${escapeHTML(error)}</div>` : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderTruncated(truncated) {
|
||||||
|
return truncated ? `<div class="truncated-notice">${escapeHTML(t("notices.truncated"))}</div>` : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatState(value) {
|
||||||
|
const key = {
|
||||||
|
pending: "state.pending",
|
||||||
|
streaming: "state.streaming",
|
||||||
|
completed: "state.completed",
|
||||||
|
error: "state.error",
|
||||||
|
}[value];
|
||||||
|
return key ? t(key) : value || "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
function currentCopyText(side) {
|
||||||
|
const payload = state.selected?.[side];
|
||||||
|
if (!payload) return "";
|
||||||
|
const tab = state.tabs[side];
|
||||||
|
if (tab === "headers") return (payload.headers || []).map((item) => `${item.name}: ${item.value}`).join("\n");
|
||||||
|
if (tab === "raw") return payload.rawHex || "";
|
||||||
|
if (tab === "frames") return (payload.frames || []).map((frame) => frame.json || frame.rawHex || frame.error || "").join("\n\n");
|
||||||
|
return payload.decodedJson || "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatHex(value) {
|
||||||
|
const hex = String(value || "").replace(/[^0-9a-f]/gi, "");
|
||||||
|
const lines = [];
|
||||||
|
for (let index = 0; index < hex.length; index += 32) {
|
||||||
|
const chunk = hex.slice(index, index + 32);
|
||||||
|
const bytes = chunk.match(/.{1,2}/g) || [];
|
||||||
|
lines.push(`${(index / 2).toString(16).padStart(8, "0")} ${bytes.join(" ")}`);
|
||||||
|
}
|
||||||
|
return lines.join("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatBytes(value) {
|
||||||
|
const bytes = Number(value || 0);
|
||||||
|
if (bytes < 1024) return `${bytes} B`;
|
||||||
|
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatDuration(value) {
|
||||||
|
const milliseconds = Number(value || 0);
|
||||||
|
if (milliseconds < 1000) return `${milliseconds} ms`;
|
||||||
|
return `${(milliseconds / 1000).toFixed(1)} s`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeHTML(value) {
|
||||||
|
return String(value ?? "")
|
||||||
|
.replaceAll("&", "&")
|
||||||
|
.replaceAll("<", "<")
|
||||||
|
.replaceAll(">", ">")
|
||||||
|
.replaceAll('"', """)
|
||||||
|
.replaceAll("'", "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.requestList.addEventListener("click", async (event) => {
|
||||||
|
const row = event.target.closest("tr[data-id]");
|
||||||
|
if (!row) return;
|
||||||
|
state.selectedId = row.dataset.id;
|
||||||
|
state.selected = null;
|
||||||
|
renderList();
|
||||||
|
renderDetail();
|
||||||
|
await refreshDetail(state.selectedId);
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.searchInput.addEventListener("input", (event) => {
|
||||||
|
state.search = event.target.value;
|
||||||
|
renderList();
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.requestIdInput.addEventListener("input", (event) => {
|
||||||
|
state.requestId = event.target.value;
|
||||||
|
renderList();
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.endpointFilter.addEventListener("click", (event) => {
|
||||||
|
const button = event.target.closest("button[data-value]");
|
||||||
|
if (!button) return;
|
||||||
|
state.endpoint = button.dataset.value;
|
||||||
|
for (const item of elements.endpointFilter.querySelectorAll("button")) {
|
||||||
|
item.classList.toggle("active", item === button);
|
||||||
|
}
|
||||||
|
renderList();
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.sortOrder.addEventListener("click", (event) => {
|
||||||
|
const button = event.target.closest("button[data-value]");
|
||||||
|
if (!button) return;
|
||||||
|
state.sortOrder = button.dataset.value;
|
||||||
|
for (const item of elements.sortOrder.querySelectorAll("button")) {
|
||||||
|
item.classList.toggle("active", item === button);
|
||||||
|
}
|
||||||
|
renderList();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll(".payload-panel").forEach((panel) => {
|
||||||
|
panel.querySelector(".tabs").addEventListener("click", (event) => {
|
||||||
|
const button = event.target.closest("button[data-tab]");
|
||||||
|
if (!button) return;
|
||||||
|
const side = panel.dataset.side;
|
||||||
|
state.tabs[side] = button.dataset.tab;
|
||||||
|
panel.querySelectorAll(".tabs button").forEach((item) => item.classList.toggle("active", item === button));
|
||||||
|
renderDetail();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
document.querySelectorAll("[data-copy-side]").forEach((button) => {
|
||||||
|
button.addEventListener("click", async () => {
|
||||||
|
const text = currentCopyText(button.dataset.copySide);
|
||||||
|
if (!text) return;
|
||||||
|
await navigator.clipboard.writeText(text);
|
||||||
|
button.textContent = t("actions.copied");
|
||||||
|
window.setTimeout(() => {
|
||||||
|
button.textContent = t("actions.copy");
|
||||||
|
}, 900);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function renderPauseState() {
|
||||||
|
elements.pauseButton.textContent = state.paused ? "▶" : "Ⅱ";
|
||||||
|
const actionKey = state.paused ? "actions.resume" : "actions.pause";
|
||||||
|
elements.pauseButton.title = t(actionKey);
|
||||||
|
elements.pauseButton.setAttribute("aria-label", t(actionKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.pauseButton.addEventListener("click", async () => {
|
||||||
|
state.paused = !state.paused;
|
||||||
|
elements.pauseButton.classList.toggle("active", state.paused);
|
||||||
|
renderPauseState();
|
||||||
|
setConnectionState(!state.paused, state.paused ? "connection.paused" : "connection.live");
|
||||||
|
if (!state.paused && state.pendingRefresh) {
|
||||||
|
state.pendingRefresh = false;
|
||||||
|
await refreshList();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function applyLocale() {
|
||||||
|
translateDocument();
|
||||||
|
elements.localeSelect.value = getLocale();
|
||||||
|
renderRuntimeStatus();
|
||||||
|
renderConnectionState();
|
||||||
|
renderPauseState();
|
||||||
|
renderList();
|
||||||
|
renderTrafficSummary();
|
||||||
|
renderDetail();
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.localeSelect.addEventListener("change", (event) => {
|
||||||
|
setLocale(event.target.value);
|
||||||
|
applyLocale();
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.clearButton.addEventListener("click", async () => {
|
||||||
|
await fetchJSON("/api/exchanges", { method: "DELETE" });
|
||||||
|
state.selectedId = null;
|
||||||
|
state.selected = null;
|
||||||
|
await refreshList();
|
||||||
|
renderDetail();
|
||||||
|
});
|
||||||
|
|
||||||
|
let draggingSplitter = false;
|
||||||
|
elements.splitter.addEventListener("pointerdown", (event) => {
|
||||||
|
draggingSplitter = true;
|
||||||
|
elements.splitter.classList.add("dragging");
|
||||||
|
elements.splitter.setPointerCapture(event.pointerId);
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.splitter.addEventListener("pointermove", (event) => {
|
||||||
|
if (!draggingSplitter) return;
|
||||||
|
const bounds = elements.workspace.getBoundingClientRect();
|
||||||
|
const top = Math.max(180, Math.min(bounds.height - 225, event.clientY - bounds.top));
|
||||||
|
elements.workspace.style.gridTemplateRows = `${top}px 5px minmax(220px, 1fr)`;
|
||||||
|
});
|
||||||
|
|
||||||
|
elements.splitter.addEventListener("pointerup", () => {
|
||||||
|
draggingSplitter = false;
|
||||||
|
elements.splitter.classList.remove("dragging");
|
||||||
|
});
|
||||||
|
|
||||||
|
async function bootstrap() {
|
||||||
|
applyLocale();
|
||||||
|
renderDetail();
|
||||||
|
try {
|
||||||
|
await Promise.all([loadStatus(), refreshList()]);
|
||||||
|
connectEvents();
|
||||||
|
} catch (error) {
|
||||||
|
setConnectionState(false, "connection.connectFailed", { message: error.message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void bootstrap();
|
||||||
@@ -0,0 +1,180 @@
|
|||||||
|
const SOURCE_LOCALE = "zh-CN";
|
||||||
|
const DEFAULT_LOCALE = "en-US";
|
||||||
|
const STORAGE_KEY = "cursor-proxy-debugger:locale:v1";
|
||||||
|
const SUPPORTED_LOCALES = [SOURCE_LOCALE, DEFAULT_LOCALE];
|
||||||
|
|
||||||
|
const messages = {
|
||||||
|
"zh-CN": {
|
||||||
|
"app.title": "Cursor 协议调试器",
|
||||||
|
"status.connecting": "正在连接",
|
||||||
|
"status.running": "代理运行中",
|
||||||
|
"status.stopped": "代理已停止",
|
||||||
|
"actions.downloadCA": "下载代理 CA 证书",
|
||||||
|
"actions.caCertificate": "CA 证书",
|
||||||
|
"actions.pause": "暂停界面更新",
|
||||||
|
"actions.resume": "继续界面更新",
|
||||||
|
"actions.clear": "清空",
|
||||||
|
"actions.copy": "复制",
|
||||||
|
"actions.copied": "已复制",
|
||||||
|
"language.label": "界面语言",
|
||||||
|
"filters.region": "请求过滤器",
|
||||||
|
"filters.urlPlaceholder": "过滤 URL、请求类型或状态",
|
||||||
|
"filters.requestIdPlaceholder": "按 Request ID 过滤",
|
||||||
|
"filters.endpoint": "接口过滤",
|
||||||
|
"filters.all": "全部",
|
||||||
|
"filters.fork": "Fork",
|
||||||
|
"filters.sort": "排序方向",
|
||||||
|
"filters.ascending": "正序",
|
||||||
|
"filters.descending": "倒序",
|
||||||
|
"count.requests": "{count} 条",
|
||||||
|
"table.url": "网址",
|
||||||
|
"table.message": "消息",
|
||||||
|
"table.method": "方法",
|
||||||
|
"table.status": "状态",
|
||||||
|
"table.response": "响应",
|
||||||
|
"table.duration": "耗时",
|
||||||
|
"empty.waitingForCursor": "等待来自 Cursor 的请求",
|
||||||
|
"splitter.resize": "调整详情区域高度",
|
||||||
|
"selection.waiting": "等待选择",
|
||||||
|
"selection.prompt": "选择一条请求查看详情",
|
||||||
|
"panel.request": "请求",
|
||||||
|
"panel.response": "响应",
|
||||||
|
"panel.requestDetails": "请求详情",
|
||||||
|
"panel.responseDetails": "响应详情",
|
||||||
|
"tabs.headers": "标头",
|
||||||
|
"tabs.body": "正文",
|
||||||
|
"tabs.frames": "帧",
|
||||||
|
"tabs.raw": "原始",
|
||||||
|
"notices.noRequest": "暂无请求内容",
|
||||||
|
"notices.noResponse": "暂无响应内容",
|
||||||
|
"notices.noContent": "暂无内容",
|
||||||
|
"notices.noRaw": "暂无原始数据",
|
||||||
|
"notices.noBody": "暂无可显示的正文",
|
||||||
|
"notices.noHeaders": "暂无标头",
|
||||||
|
"notices.noFrames": "尚未收到完整帧",
|
||||||
|
"notices.unknown": "未识别",
|
||||||
|
"notices.truncated": "原始正文已达到本地抓取上限,转发内容未被截断",
|
||||||
|
"connection.live": "实时连接中",
|
||||||
|
"connection.retrying": "实时连接正在重试",
|
||||||
|
"connection.refreshFailed": "刷新失败:{message}",
|
||||||
|
"connection.paused": "界面更新已暂停",
|
||||||
|
"connection.connectFailed": "连接失败:{message}",
|
||||||
|
"state.pending": "等待中",
|
||||||
|
"state.streaming": "传输中",
|
||||||
|
"state.completed": "已完成",
|
||||||
|
"state.error": "错误",
|
||||||
|
},
|
||||||
|
"en-US": {
|
||||||
|
"app.title": "Cursor Protocol Debugger",
|
||||||
|
"status.connecting": "Connecting",
|
||||||
|
"status.running": "Proxy running",
|
||||||
|
"status.stopped": "Proxy stopped",
|
||||||
|
"actions.downloadCA": "Download proxy CA certificate",
|
||||||
|
"actions.caCertificate": "CA Certificate",
|
||||||
|
"actions.pause": "Pause UI updates",
|
||||||
|
"actions.resume": "Resume UI updates",
|
||||||
|
"actions.clear": "Clear",
|
||||||
|
"actions.copy": "Copy",
|
||||||
|
"actions.copied": "Copied",
|
||||||
|
"language.label": "Interface language",
|
||||||
|
"filters.region": "Request filters",
|
||||||
|
"filters.urlPlaceholder": "Filter by URL, message type, or status",
|
||||||
|
"filters.requestIdPlaceholder": "Filter by Request ID",
|
||||||
|
"filters.endpoint": "Endpoint filter",
|
||||||
|
"filters.all": "All",
|
||||||
|
"filters.fork": "Fork",
|
||||||
|
"filters.sort": "Sort order",
|
||||||
|
"filters.ascending": "Oldest first",
|
||||||
|
"filters.descending": "Newest first",
|
||||||
|
"count.requests": "{count} requests",
|
||||||
|
"table.url": "URL",
|
||||||
|
"table.message": "Message",
|
||||||
|
"table.method": "Method",
|
||||||
|
"table.status": "Status",
|
||||||
|
"table.response": "Response",
|
||||||
|
"table.duration": "Duration",
|
||||||
|
"empty.waitingForCursor": "Waiting for requests from Cursor",
|
||||||
|
"splitter.resize": "Resize details area",
|
||||||
|
"selection.waiting": "No selection",
|
||||||
|
"selection.prompt": "Select a request to inspect its details",
|
||||||
|
"panel.request": "Request",
|
||||||
|
"panel.response": "Response",
|
||||||
|
"panel.requestDetails": "Request details",
|
||||||
|
"panel.responseDetails": "Response details",
|
||||||
|
"tabs.headers": "Headers",
|
||||||
|
"tabs.body": "Body",
|
||||||
|
"tabs.frames": "Frames",
|
||||||
|
"tabs.raw": "Raw",
|
||||||
|
"notices.noRequest": "No request content",
|
||||||
|
"notices.noResponse": "No response content",
|
||||||
|
"notices.noContent": "No content",
|
||||||
|
"notices.noRaw": "No raw data",
|
||||||
|
"notices.noBody": "No body available",
|
||||||
|
"notices.noHeaders": "No headers",
|
||||||
|
"notices.noFrames": "No complete frames received yet",
|
||||||
|
"notices.unknown": "Unknown",
|
||||||
|
"notices.truncated": "Raw body reached the local capture limit; forwarded data was not truncated",
|
||||||
|
"connection.live": "Live connection",
|
||||||
|
"connection.retrying": "Reconnecting live updates",
|
||||||
|
"connection.refreshFailed": "Refresh failed: {message}",
|
||||||
|
"connection.paused": "UI updates paused",
|
||||||
|
"connection.connectFailed": "Connection failed: {message}",
|
||||||
|
"state.pending": "Pending",
|
||||||
|
"state.streaming": "Streaming",
|
||||||
|
"state.completed": "Completed",
|
||||||
|
"state.error": "Error",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
function matchLocale(locale) {
|
||||||
|
const normalized = String(locale || "").trim().replaceAll("_", "-").toLowerCase();
|
||||||
|
if (!normalized) return "";
|
||||||
|
const exact = SUPPORTED_LOCALES.find((candidate) => candidate.toLowerCase() === normalized);
|
||||||
|
if (exact) return exact;
|
||||||
|
return normalized.split("-")[0] === "zh" ? SOURCE_LOCALE : normalized.split("-")[0] === "en" ? DEFAULT_LOCALE : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveInitialLocale() {
|
||||||
|
const stored = matchLocale(window.localStorage.getItem(STORAGE_KEY));
|
||||||
|
if (stored) return stored;
|
||||||
|
for (const candidate of navigator.languages || [navigator.language]) {
|
||||||
|
const matched = matchLocale(candidate);
|
||||||
|
if (matched) return matched;
|
||||||
|
}
|
||||||
|
return DEFAULT_LOCALE;
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentLocale = resolveInitialLocale();
|
||||||
|
|
||||||
|
export function getLocale() {
|
||||||
|
return currentLocale;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function t(key, values = {}) {
|
||||||
|
const template = messages[currentLocale]?.[key] || messages[SOURCE_LOCALE][key] || key;
|
||||||
|
return template.replace(/\{(\w+)\}/g, (_match, name) => String(values[name] ?? ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function translateDocument(root = document) {
|
||||||
|
document.documentElement.lang = currentLocale;
|
||||||
|
document.title = t("app.title");
|
||||||
|
for (const element of root.querySelectorAll("[data-i18n]")) {
|
||||||
|
element.textContent = t(element.dataset.i18n);
|
||||||
|
}
|
||||||
|
for (const [attribute, dataAttribute] of [
|
||||||
|
["aria-label", "i18nAriaLabel"],
|
||||||
|
["placeholder", "i18nPlaceholder"],
|
||||||
|
["title", "i18nTitle"],
|
||||||
|
]) {
|
||||||
|
for (const element of root.querySelectorAll(`[data-${dataAttribute.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)}]`)) {
|
||||||
|
element.setAttribute(attribute, t(element.dataset[dataAttribute]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setLocale(locale) {
|
||||||
|
currentLocale = matchLocale(locale) || DEFAULT_LOCALE;
|
||||||
|
window.localStorage.setItem(STORAGE_KEY, currentLocale);
|
||||||
|
translateDocument();
|
||||||
|
return currentLocale;
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<meta name="color-scheme" content="dark" />
|
||||||
|
<title>Cursor 协议调试器</title>
|
||||||
|
<link rel="stylesheet" href="/styles.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="app" class="app-shell">
|
||||||
|
<header class="topbar">
|
||||||
|
<div class="brand">
|
||||||
|
<span class="brand-mark" aria-hidden="true"></span>
|
||||||
|
<strong data-i18n="app.title">Cursor 协议调试器</strong>
|
||||||
|
</div>
|
||||||
|
<div class="runtime-status" aria-live="polite">
|
||||||
|
<span id="status-dot" class="status-dot"></span>
|
||||||
|
<span id="status-text" data-i18n="status.connecting">正在连接</span>
|
||||||
|
<code id="proxy-address"></code>
|
||||||
|
</div>
|
||||||
|
<div class="toolbar-actions">
|
||||||
|
<label class="locale-picker">
|
||||||
|
<span class="visually-hidden" data-i18n="language.label">界面语言</span>
|
||||||
|
<select id="locale-select" aria-label="界面语言" title="界面语言" data-i18n-aria-label="language.label" data-i18n-title="language.label">
|
||||||
|
<option value="zh-CN">中文</option>
|
||||||
|
<option value="en-US">EN</option>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
<a class="button secondary" href="/api/ca.crt" title="下载代理 CA 证书" data-i18n="actions.caCertificate" data-i18n-title="actions.downloadCA">CA 证书</a>
|
||||||
|
<button id="pause-button" class="icon-button" type="button" title="暂停界面更新" aria-label="暂停界面更新" data-i18n-title="actions.pause" data-i18n-aria-label="actions.pause">Ⅱ</button>
|
||||||
|
<button id="clear-button" class="button danger" type="button" data-i18n="actions.clear">清空</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<section class="filterbar" aria-label="请求过滤器" data-i18n-aria-label="filters.region">
|
||||||
|
<div class="search-box url-filter">
|
||||||
|
<span aria-hidden="true">⌕</span>
|
||||||
|
<input id="search-input" type="search" placeholder="过滤 URL、请求类型或状态" data-i18n-placeholder="filters.urlPlaceholder" autocomplete="off" />
|
||||||
|
</div>
|
||||||
|
<div class="search-box request-id-filter">
|
||||||
|
<span aria-hidden="true">⌕</span>
|
||||||
|
<input id="request-id-input" type="search" placeholder="按 Request ID 过滤" data-i18n-placeholder="filters.requestIdPlaceholder" autocomplete="off" />
|
||||||
|
</div>
|
||||||
|
<div id="endpoint-filter" class="segmented-control" role="group" aria-label="接口过滤" data-i18n-aria-label="filters.endpoint">
|
||||||
|
<button class="active" type="button" data-value="all" data-i18n="filters.all">全部</button>
|
||||||
|
<button type="button" data-value="runsse">RunSSE</button>
|
||||||
|
<button type="button" data-value="bidiappend">BidiAppend</button>
|
||||||
|
<button type="button" data-value="fork" data-i18n="filters.fork">Fork</button>
|
||||||
|
</div>
|
||||||
|
<div id="sort-order" class="segmented-control sort-control" role="group" aria-label="排序方向" data-i18n-aria-label="filters.sort">
|
||||||
|
<button type="button" data-value="asc" data-i18n="filters.ascending">正序</button>
|
||||||
|
<button class="active" type="button" data-value="desc" data-i18n="filters.descending">倒序</button>
|
||||||
|
</div>
|
||||||
|
<span id="request-count" class="request-count">0 条</span>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<main id="workspace" class="workspace">
|
||||||
|
<section class="request-list-pane">
|
||||||
|
<table class="request-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="status-column"></th>
|
||||||
|
<th class="index-column">#</th>
|
||||||
|
<th data-i18n="table.url">网址</th>
|
||||||
|
<th class="request-id-column">Request ID</th>
|
||||||
|
<th class="kind-column" data-i18n="table.message">消息</th>
|
||||||
|
<th class="method-column" data-i18n="table.method">方法</th>
|
||||||
|
<th class="code-column" data-i18n="table.status">状态</th>
|
||||||
|
<th class="size-column" data-i18n="table.response">响应</th>
|
||||||
|
<th class="time-column" data-i18n="table.duration">耗时</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody id="request-list"></tbody>
|
||||||
|
</table>
|
||||||
|
<div id="empty-state" class="empty-state" data-i18n="empty.waitingForCursor">等待来自 Cursor 的请求</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div id="horizontal-splitter" class="horizontal-splitter" role="separator" aria-label="调整详情区域高度" data-i18n-aria-label="splitter.resize"></div>
|
||||||
|
|
||||||
|
<section id="detail-pane" class="detail-pane">
|
||||||
|
<div id="selection-summary" class="selection-summary">
|
||||||
|
<span class="method-badge">POST</span>
|
||||||
|
<span class="status-badge" data-i18n="selection.waiting">等待选择</span>
|
||||||
|
<code data-i18n="selection.prompt">选择一条请求查看详情</code>
|
||||||
|
</div>
|
||||||
|
<div class="detail-columns">
|
||||||
|
<section class="payload-panel" data-side="request">
|
||||||
|
<div class="panel-header">
|
||||||
|
<strong data-i18n="panel.request">请求</strong>
|
||||||
|
<nav class="tabs" aria-label="请求详情" data-i18n-aria-label="panel.requestDetails">
|
||||||
|
<button type="button" data-tab="headers" data-i18n="tabs.headers">标头</button>
|
||||||
|
<button type="button" data-tab="body" class="active" data-i18n="tabs.body">正文</button>
|
||||||
|
<button type="button" data-tab="frames" data-i18n="tabs.frames">帧</button>
|
||||||
|
<button type="button" data-tab="raw" data-i18n="tabs.raw">原始</button>
|
||||||
|
</nav>
|
||||||
|
<button class="copy-button" type="button" data-copy-side="request" title="复制" data-i18n="actions.copy" data-i18n-title="actions.copy">复制</button>
|
||||||
|
</div>
|
||||||
|
<div id="request-content" class="panel-content"></div>
|
||||||
|
</section>
|
||||||
|
<section class="payload-panel" data-side="response">
|
||||||
|
<div class="panel-header">
|
||||||
|
<strong data-i18n="panel.response">响应</strong>
|
||||||
|
<nav class="tabs" aria-label="响应详情" data-i18n-aria-label="panel.responseDetails">
|
||||||
|
<button type="button" data-tab="headers" data-i18n="tabs.headers">标头</button>
|
||||||
|
<button type="button" data-tab="body" data-i18n="tabs.body">正文</button>
|
||||||
|
<button type="button" data-tab="frames" class="active" data-i18n="tabs.frames">帧</button>
|
||||||
|
<button type="button" data-tab="raw" data-i18n="tabs.raw">原始</button>
|
||||||
|
</nav>
|
||||||
|
<button class="copy-button" type="button" data-copy-side="response" title="复制" data-i18n="actions.copy" data-i18n-title="actions.copy">复制</button>
|
||||||
|
</div>
|
||||||
|
<div id="response-content" class="panel-content"></div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer class="statusbar">
|
||||||
|
<span id="connection-label" data-i18n="connection.live">实时连接中</span>
|
||||||
|
<span id="traffic-summary">↑ 0 B ↓ 0 B</span>
|
||||||
|
<span id="target-host"></span>
|
||||||
|
</footer>
|
||||||
|
</div>
|
||||||
|
<script type="module" src="/app.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,921 @@
|
|||||||
|
:root {
|
||||||
|
color-scheme: dark;
|
||||||
|
font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
||||||
|
background: #171818;
|
||||||
|
color: #dedfdd;
|
||||||
|
font-synthesis: none;
|
||||||
|
--surface-0: #171818;
|
||||||
|
--surface-1: #1d1f1f;
|
||||||
|
--surface-2: #242626;
|
||||||
|
--surface-3: #2c2f2f;
|
||||||
|
--border: #343737;
|
||||||
|
--border-strong: #454949;
|
||||||
|
--muted: #8d9390;
|
||||||
|
--text: #dedfdd;
|
||||||
|
--accent: #4ea58b;
|
||||||
|
--accent-soft: #25473d;
|
||||||
|
--cyan: #55a8ba;
|
||||||
|
--orange: #c88762;
|
||||||
|
--danger: #c56d65;
|
||||||
|
--selection: #245b73;
|
||||||
|
--mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body,
|
||||||
|
#app {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: var(--surface-0);
|
||||||
|
}
|
||||||
|
|
||||||
|
button,
|
||||||
|
input,
|
||||||
|
select,
|
||||||
|
a {
|
||||||
|
font: inherit;
|
||||||
|
letter-spacing: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
button,
|
||||||
|
a {
|
||||||
|
-webkit-tap-highlight-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
button:focus-visible,
|
||||||
|
input:focus-visible,
|
||||||
|
select:focus-visible,
|
||||||
|
a:focus-visible {
|
||||||
|
outline: 2px solid var(--cyan);
|
||||||
|
outline-offset: -1px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-shell {
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 48px 46px minmax(0, 1fr) 26px;
|
||||||
|
min-width: 760px;
|
||||||
|
background: var(--surface-0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar,
|
||||||
|
.filterbar,
|
||||||
|
.statusbar {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
border-color: var(--border);
|
||||||
|
background: var(--surface-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 18px;
|
||||||
|
padding: 0 14px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand,
|
||||||
|
.runtime-status,
|
||||||
|
.toolbar-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
gap: 9px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand strong {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand-mark {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
border: 2px solid var(--accent);
|
||||||
|
border-radius: 50%;
|
||||||
|
box-shadow: inset 0 0 0 2px var(--surface-1);
|
||||||
|
background: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.runtime-status {
|
||||||
|
justify-content: center;
|
||||||
|
gap: 7px;
|
||||||
|
min-width: 240px;
|
||||||
|
color: #bec3c0;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.runtime-status code {
|
||||||
|
overflow: hidden;
|
||||||
|
max-width: 260px;
|
||||||
|
color: var(--muted);
|
||||||
|
font-family: var(--mono);
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #7d8380;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-dot.online {
|
||||||
|
background: #42bd79;
|
||||||
|
box-shadow: 0 0 0 3px rgb(66 189 121 / 14%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-actions {
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.locale-picker {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.locale-picker select {
|
||||||
|
width: 58px;
|
||||||
|
height: 29px;
|
||||||
|
border: 1px solid var(--border-strong);
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 0 6px;
|
||||||
|
background: var(--surface-2);
|
||||||
|
color: var(--text);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.visually-hidden {
|
||||||
|
position: absolute;
|
||||||
|
width: 1px;
|
||||||
|
height: 1px;
|
||||||
|
padding: 0;
|
||||||
|
margin: -1px;
|
||||||
|
overflow: hidden;
|
||||||
|
clip: rect(0, 0, 0, 0);
|
||||||
|
white-space: nowrap;
|
||||||
|
border: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button,
|
||||||
|
.icon-button,
|
||||||
|
.copy-button {
|
||||||
|
height: 29px;
|
||||||
|
border: 1px solid var(--border-strong);
|
||||||
|
border-radius: 5px;
|
||||||
|
background: var(--surface-2);
|
||||||
|
color: var(--text);
|
||||||
|
cursor: pointer;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 10px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button:hover,
|
||||||
|
.icon-button:hover,
|
||||||
|
.copy-button:hover {
|
||||||
|
background: var(--surface-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button.danger:hover {
|
||||||
|
border-color: #744640;
|
||||||
|
color: #f2b0aa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button {
|
||||||
|
width: 31px;
|
||||||
|
padding: 0;
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.icon-button.active {
|
||||||
|
border-color: var(--orange);
|
||||||
|
color: #f1bb98;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filterbar {
|
||||||
|
gap: 10px;
|
||||||
|
padding: 7px 14px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
flex: 1;
|
||||||
|
min-width: 260px;
|
||||||
|
max-width: 640px;
|
||||||
|
height: 31px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 5px;
|
||||||
|
background: #191b1b;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box > span {
|
||||||
|
padding-left: 9px;
|
||||||
|
font-size: 17px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
height: 100%;
|
||||||
|
border: 0;
|
||||||
|
padding: 0 9px;
|
||||||
|
outline: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--text);
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-box input::placeholder {
|
||||||
|
color: #6f7572;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-filter {
|
||||||
|
min-width: 280px;
|
||||||
|
max-width: 420px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-id-filter {
|
||||||
|
flex: 0 1 320px;
|
||||||
|
min-width: 220px;
|
||||||
|
max-width: 340px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented-control {
|
||||||
|
display: flex;
|
||||||
|
height: 31px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented-control button {
|
||||||
|
min-width: 62px;
|
||||||
|
border: 0;
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
padding: 0 10px;
|
||||||
|
background: #1b1d1d;
|
||||||
|
color: var(--muted);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented-control button:last-child {
|
||||||
|
border-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented-control button.active {
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: #bce8d9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sort-control button {
|
||||||
|
min-width: 52px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-count {
|
||||||
|
margin-left: auto;
|
||||||
|
color: var(--muted);
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 11px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace {
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: minmax(180px, 52%) 5px minmax(220px, 48%);
|
||||||
|
min-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-list-pane {
|
||||||
|
position: relative;
|
||||||
|
min-height: 0;
|
||||||
|
overflow: auto;
|
||||||
|
background: #181a1a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
table-layout: fixed;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table thead {
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 2;
|
||||||
|
background: #202222;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table th,
|
||||||
|
.request-table td {
|
||||||
|
height: 30px;
|
||||||
|
border-right: 1px solid #2c2f2f;
|
||||||
|
border-bottom: 1px solid #292c2c;
|
||||||
|
padding: 0 9px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: left;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table th {
|
||||||
|
color: #9da29f;
|
||||||
|
font-weight: 550;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table tbody tr {
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table tbody tr:hover {
|
||||||
|
background: #222525;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table tbody tr.selected {
|
||||||
|
background: var(--selection);
|
||||||
|
color: #f3f8f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table code {
|
||||||
|
font-family: var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-column {
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.index-column {
|
||||||
|
width: 54px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-id-column {
|
||||||
|
width: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kind-column {
|
||||||
|
width: 180px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.method-column {
|
||||||
|
width: 72px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-column {
|
||||||
|
width: 66px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.size-column {
|
||||||
|
width: 86px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.time-column {
|
||||||
|
width: 74px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-state {
|
||||||
|
display: block;
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
margin: auto;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #7c8380;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-state.streaming {
|
||||||
|
background: #45ba77;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-state.completed {
|
||||||
|
background: var(--cyan);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-state.error {
|
||||||
|
background: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.method-text {
|
||||||
|
color: #61b9df;
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-weight: 650;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-text.success {
|
||||||
|
color: #68c991;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-text.error {
|
||||||
|
color: #e18b83;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kind-text {
|
||||||
|
color: #d3a17f;
|
||||||
|
font-family: var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-id-text {
|
||||||
|
color: #8bc2cc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
position: absolute;
|
||||||
|
inset: 34px 0 0;
|
||||||
|
display: grid;
|
||||||
|
place-items: center;
|
||||||
|
color: #686e6b;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.horizontal-splitter {
|
||||||
|
cursor: row-resize;
|
||||||
|
background: #343737;
|
||||||
|
}
|
||||||
|
|
||||||
|
.horizontal-splitter:hover,
|
||||||
|
.horizontal-splitter.dragging {
|
||||||
|
background: var(--cyan);
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-pane {
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 38px minmax(0, 1fr);
|
||||||
|
min-height: 0;
|
||||||
|
background: var(--surface-0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.selection-summary {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
min-width: 0;
|
||||||
|
padding: 0 14px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: #1b1d1d;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selection-summary code {
|
||||||
|
overflow: hidden;
|
||||||
|
color: #aeb4b1;
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 12px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.method-badge,
|
||||||
|
.status-badge,
|
||||||
|
.frame-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
height: 22px;
|
||||||
|
border: 1px solid var(--border-strong);
|
||||||
|
border-radius: 4px;
|
||||||
|
padding: 0 7px;
|
||||||
|
font-family: var(--mono);
|
||||||
|
font-size: 11px;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.method-badge {
|
||||||
|
border-color: #34667a;
|
||||||
|
color: #74c8e8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-badge.success {
|
||||||
|
border-color: #3f7157;
|
||||||
|
color: #83d5a5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-columns {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
|
||||||
|
min-height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payload-panel {
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 36px minmax(0, 1fr);
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
border-right: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.payload-panel:last-child {
|
||||||
|
border-right: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
background: #202222;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-header > strong {
|
||||||
|
padding: 0 10px;
|
||||||
|
color: #c9cdca;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs {
|
||||||
|
display: flex;
|
||||||
|
align-self: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button {
|
||||||
|
position: relative;
|
||||||
|
min-width: 46px;
|
||||||
|
border: 0;
|
||||||
|
padding: 0 9px;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--muted);
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button:hover {
|
||||||
|
color: #d7dad8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button.active {
|
||||||
|
color: #71c7e2;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button.active::after {
|
||||||
|
position: absolute;
|
||||||
|
right: 8px;
|
||||||
|
bottom: 0;
|
||||||
|
left: 8px;
|
||||||
|
height: 2px;
|
||||||
|
background: var(--cyan);
|
||||||
|
content: "";
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-button {
|
||||||
|
width: 48px;
|
||||||
|
height: 24px;
|
||||||
|
margin-right: 7px;
|
||||||
|
margin-left: auto;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-content {
|
||||||
|
min-height: 0;
|
||||||
|
overflow: auto;
|
||||||
|
background: #181a1a;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-view,
|
||||||
|
.hex-view {
|
||||||
|
min-width: 100%;
|
||||||
|
min-height: 100%;
|
||||||
|
margin: 0;
|
||||||
|
padding: 12px 14px 30px;
|
||||||
|
color: #ccd1ce;
|
||||||
|
font: 11px/1.55 var(--mono);
|
||||||
|
tab-size: 2;
|
||||||
|
white-space: pre;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hex-view {
|
||||||
|
color: #b6c2bd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.headers-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
font: 11px/1.4 var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.headers-table th,
|
||||||
|
.headers-table td {
|
||||||
|
border-bottom: 1px solid #292c2c;
|
||||||
|
padding: 7px 10px;
|
||||||
|
text-align: left;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.headers-table th {
|
||||||
|
width: 38%;
|
||||||
|
color: #62b3cd;
|
||||||
|
font-weight: 500;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.headers-table td {
|
||||||
|
color: #c5c9c6;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-list {
|
||||||
|
min-width: 480px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-item {
|
||||||
|
border-bottom: 1px solid #292c2c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-item summary {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: 58px minmax(150px, 1fr) 90px 82px;
|
||||||
|
align-items: center;
|
||||||
|
height: 32px;
|
||||||
|
padding: 0 10px;
|
||||||
|
color: #c5cac7;
|
||||||
|
cursor: pointer;
|
||||||
|
font: 11px var(--mono);
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-item summary::-webkit-details-marker {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-item summary:hover {
|
||||||
|
background: #222525;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-item[open] summary {
|
||||||
|
background: #242727;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-index {
|
||||||
|
color: #747b77;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-kind {
|
||||||
|
overflow: hidden;
|
||||||
|
color: #dfaa85;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-size,
|
||||||
|
.frame-flags {
|
||||||
|
color: #7faeb7;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-error {
|
||||||
|
margin: 10px 14px;
|
||||||
|
color: #ec968e;
|
||||||
|
font: 11px/1.5 var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice {
|
||||||
|
padding: 14px;
|
||||||
|
color: #7d8581;
|
||||||
|
font: 12px/1.6 var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.notice.error {
|
||||||
|
color: #df8b83;
|
||||||
|
}
|
||||||
|
|
||||||
|
.truncated-notice {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 0;
|
||||||
|
padding: 5px 10px;
|
||||||
|
border-top: 1px solid #674f3f;
|
||||||
|
background: #3d3028;
|
||||||
|
color: #e5b28e;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusbar {
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 0 10px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
color: #848b87;
|
||||||
|
font: 10px var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusbar span:first-child {
|
||||||
|
margin-right: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 920px) {
|
||||||
|
.app-shell {
|
||||||
|
grid-template-rows: 48px 84px minmax(0, 1fr) 26px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filterbar {
|
||||||
|
align-content: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-filter,
|
||||||
|
.request-id-filter {
|
||||||
|
flex: 1 1 300px;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.runtime-status code,
|
||||||
|
.kind-column,
|
||||||
|
.request-table td:nth-child(5) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-columns {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
grid-template-rows: minmax(180px, 1fr) minmax(180px, 1fr);
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.payload-panel {
|
||||||
|
min-height: 260px;
|
||||||
|
border-right: 0;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 640px) {
|
||||||
|
.app-shell {
|
||||||
|
grid-template-rows: 82px 122px minmax(0, 1fr) 26px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.topbar {
|
||||||
|
position: relative;
|
||||||
|
align-content: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 4px 10px;
|
||||||
|
padding: 8px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
flex: 1;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.brand strong {
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 13px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.runtime-status {
|
||||||
|
order: 3;
|
||||||
|
justify-content: flex-start;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.runtime-status code {
|
||||||
|
display: block;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-actions {
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.toolbar-actions .button {
|
||||||
|
padding: 0 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filterbar {
|
||||||
|
align-content: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 6px;
|
||||||
|
padding: 7px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.url-filter,
|
||||||
|
.request-id-filter {
|
||||||
|
flex: 0 0 100%;
|
||||||
|
width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
max-width: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-count {
|
||||||
|
order: 5;
|
||||||
|
margin-left: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endpoint-filter {
|
||||||
|
order: 3;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sort-control {
|
||||||
|
order: 4;
|
||||||
|
flex: 0 0 104px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.segmented-control button {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace {
|
||||||
|
grid-template-rows: minmax(150px, 40%) 5px minmax(260px, 60%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table th,
|
||||||
|
.request-table td {
|
||||||
|
padding: 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-table .index-column,
|
||||||
|
.request-table th:nth-child(2),
|
||||||
|
.request-table td:nth-child(2),
|
||||||
|
.size-column,
|
||||||
|
.request-table th:nth-child(8),
|
||||||
|
.request-table td:nth-child(8),
|
||||||
|
.time-column,
|
||||||
|
.request-table th:nth-child(9),
|
||||||
|
.request-table td:nth-child(9) {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.request-id-column {
|
||||||
|
width: 130px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.method-column {
|
||||||
|
width: 58px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-column {
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selection-summary {
|
||||||
|
padding: 0 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detail-columns {
|
||||||
|
grid-template-rows: minmax(220px, 1fr) minmax(220px, 1fr);
|
||||||
|
}
|
||||||
|
|
||||||
|
.panel-header > strong {
|
||||||
|
width: 72px;
|
||||||
|
padding: 0 7px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs button {
|
||||||
|
min-width: 42px;
|
||||||
|
padding: 0 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.copy-button {
|
||||||
|
width: 42px;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-list {
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.frame-item summary {
|
||||||
|
grid-template-columns: 42px minmax(100px, 1fr) 62px 72px;
|
||||||
|
padding: 0 7px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusbar {
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#target-host {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1903,11 +1903,13 @@ func openAIThinkingDisableKind(baseURL string, modelID string, endpoint string)
|
|||||||
strings.Contains(base, "zhipu") ||
|
strings.Contains(base, "zhipu") ||
|
||||||
strings.Contains(base, "xiaomimimo") ||
|
strings.Contains(base, "xiaomimimo") ||
|
||||||
strings.Contains(base, "mimo") ||
|
strings.Contains(base, "mimo") ||
|
||||||
|
strings.Contains(base, "minimax") ||
|
||||||
strings.Contains(model, "deepseek") ||
|
strings.Contains(model, "deepseek") ||
|
||||||
strings.Contains(model, "glm") ||
|
strings.Contains(model, "glm") ||
|
||||||
strings.Contains(model, "zai") ||
|
strings.Contains(model, "zai") ||
|
||||||
strings.Contains(model, "zhipu") ||
|
strings.Contains(model, "zhipu") ||
|
||||||
strings.Contains(model, "mimo"):
|
strings.Contains(model, "mimo") ||
|
||||||
|
strings.Contains(model, "minimax"):
|
||||||
return "thinking_type"
|
return "thinking_type"
|
||||||
case openAIModelSupportsReasoningNone(model):
|
case openAIModelSupportsReasoningNone(model):
|
||||||
return "reasoning_none"
|
return "reasoning_none"
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package modeladapter
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
// TestOpenAIThinkingDisableKindMiniMax verifies that the MiniMax OpenAI-compatible
|
||||||
|
// endpoint is routed to the thinking_type disable branch, so that disabling
|
||||||
|
// thinking writes thinking:{type:"disabled"} and drops reasoning_effort. This
|
||||||
|
// covers the global endpoint, the China endpoint and a custom proxy that only
|
||||||
|
// exposes the MiniMax model id, plus regression cases for the other branches.
|
||||||
|
func TestOpenAIThinkingDisableKindMiniMax(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
baseURL string
|
||||||
|
modelID string
|
||||||
|
endpoint string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
// MiniMax global endpoint
|
||||||
|
{name: "minimax global base + M3", baseURL: "https://api.minimax.io/v1", modelID: "MiniMax-M3", endpoint: "/chat/completions", want: "thinking_type"},
|
||||||
|
{name: "minimax global base + M2.7", baseURL: "https://api.minimax.io/v1", modelID: "MiniMax-M2.7", endpoint: "/chat/completions", want: "thinking_type"},
|
||||||
|
// MiniMax China endpoint
|
||||||
|
{name: "minimax cn base + M3", baseURL: "https://api.minimaxi.com/v1", modelID: "MiniMax-M3", endpoint: "/chat/completions", want: "thinking_type"},
|
||||||
|
{name: "minimax cn base + M2.7", baseURL: "https://api.minimaxi.com/v1", modelID: "MiniMax-M2.7", endpoint: "/chat/completions", want: "thinking_type"},
|
||||||
|
// MiniMax model id only (custom base)
|
||||||
|
{name: "minimax model only (custom base)", baseURL: "https://custom.proxy.example.com/v1", modelID: "MiniMax-M3", endpoint: "/chat/completions", want: "thinking_type"},
|
||||||
|
// Regression: enable_thinking branch (qwen) is unaffected
|
||||||
|
{name: "qwen via dashscope", baseURL: "https://dashscope.aliyuncs.com/v1", modelID: "qwen-max", endpoint: "/chat/completions", want: "enable_thinking"},
|
||||||
|
// Regression: reasoning_none branch (gpt-5.1+/gpt-6) is unaffected
|
||||||
|
{name: "gpt-6", baseURL: "https://api.openai.com/v1", modelID: "gpt-6", endpoint: "/chat/completions", want: "reasoning_none"},
|
||||||
|
// Regression: unknown provider does not disable
|
||||||
|
{name: "unknown provider", baseURL: "https://api.unknown-llm.com/v1", modelID: "some-model", endpoint: "/chat/completions", want: ""},
|
||||||
|
}
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
got := openAIThinkingDisableKind(tc.baseURL, tc.modelID, tc.endpoint)
|
||||||
|
if got != tc.want {
|
||||||
|
t.Fatalf("openAIThinkingDisableKind(%q, %q, %q) = %q, want %q", tc.baseURL, tc.modelID, tc.endpoint, got, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestApplyOpenAIThinkingDisableMiniMax verifies that when ThinkingEffort=disabled
|
||||||
|
// and the provider is MiniMax, applyOpenAIThinkingDisable writes
|
||||||
|
// thinking:{type:"disabled"} and deletes reasoning_effort on both the global and
|
||||||
|
// the China endpoint.
|
||||||
|
func TestApplyOpenAIThinkingDisableMiniMax(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
baseURL string
|
||||||
|
modelID string
|
||||||
|
}{
|
||||||
|
{name: "global endpoint", baseURL: "https://api.minimax.io/v1", modelID: "MiniMax-M3"},
|
||||||
|
{name: "china endpoint", baseURL: "https://api.minimaxi.com/v1", modelID: "MiniMax-M3"},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
req := StreamRequest{ThinkingEffort: "disabled", RequestKnobs: map[string]any{}}
|
||||||
|
body := map[string]any{
|
||||||
|
"model": tc.modelID,
|
||||||
|
"messages": []map[string]any{{"role": "user", "content": "hi"}},
|
||||||
|
"reasoning_effort": "high",
|
||||||
|
}
|
||||||
|
applyOpenAIThinkingDisable(body, req, tc.baseURL, tc.modelID, "/chat/completions")
|
||||||
|
|
||||||
|
thinking, ok := body["thinking"].(map[string]any)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected body[thinking] to be map[string]any, got %T (%v)", body["thinking"], body["thinking"])
|
||||||
|
}
|
||||||
|
if thinking["type"] != "disabled" {
|
||||||
|
t.Fatalf("expected thinking.type=disabled, got %v", thinking["type"])
|
||||||
|
}
|
||||||
|
if _, stillPresent := body["reasoning_effort"]; stillPresent {
|
||||||
|
t.Fatalf("reasoning_effort should be deleted when thinking disabled, got %v", body["reasoning_effort"])
|
||||||
|
}
|
||||||
|
if got := req.RequestKnobs["thinking_disabled_provider_param"]; got != "thinking.type" {
|
||||||
|
t.Fatalf("expected request knob thinking_disabled_provider_param=thinking.type, got %v", got)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestApplyOpenAIThinkingDisableMiniMaxNotTriggered verifies that a non-disabled
|
||||||
|
// thinking effort does not inject the disable field for MiniMax.
|
||||||
|
func TestApplyOpenAIThinkingDisableMiniMaxNotTriggered(t *testing.T) {
|
||||||
|
req := StreamRequest{ThinkingEffort: "high", RequestKnobs: map[string]any{}}
|
||||||
|
body := map[string]any{"model": "MiniMax-M3", "reasoning_effort": "high"}
|
||||||
|
applyOpenAIThinkingDisable(body, req, "https://api.minimax.io/v1", "MiniMax-M3", "/chat/completions")
|
||||||
|
if _, present := body["thinking"]; present {
|
||||||
|
t.Fatalf("thinking should not be injected when ThinkingEffort != disabled, got %v", body["thinking"])
|
||||||
|
}
|
||||||
|
if body["reasoning_effort"] != "high" {
|
||||||
|
t.Fatalf("reasoning_effort should be preserved when not disabled, got %v", body["reasoning_effort"])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -319,6 +319,16 @@ func (host *Host) rebuildLocked(cfg serverconfig.Config) error {
|
|||||||
MockBuilder: upstream.ServerConfigMockBuilder,
|
MockBuilder: upstream.ServerConfigMockBuilder,
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
|
server.POST("/aiserver.v1.ServerConfigService/GetServerConfig",
|
||||||
|
server.Name("server_config_service_get_server_config"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "server_config_service_get_server_config",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetServerConfigResponse",
|
||||||
|
MockBuilder: upstream.ServerConfigMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
server.POST("/aiserver.v1.AiService/AvailableModels",
|
server.POST("/aiserver.v1.AiService/AvailableModels",
|
||||||
server.Name("available_models"),
|
server.Name("available_models"),
|
||||||
server.ConnectUnary(),
|
server.ConnectUnary(),
|
||||||
@@ -329,6 +339,36 @@ func (host *Host) rebuildLocked(cfg serverconfig.Config) error {
|
|||||||
MockBuilder: upstream.AvailableModelsMockBuilder,
|
MockBuilder: upstream.AvailableModelsMockBuilder,
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
|
server.POST("/aiserver.v1.AiService/GetUsableModels",
|
||||||
|
server.Name("usable_models"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "usable_models",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetUsableModelsResponse",
|
||||||
|
MockBuilder: upstream.UsableModelsMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.AiService/GetDefaultModelForCli",
|
||||||
|
server.Name("default_model_for_cli"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "default_model_for_cli",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetDefaultModelForCliResponse",
|
||||||
|
MockBuilder: upstream.DefaultModelForCliMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.AiService/GetDefaultModel",
|
||||||
|
server.Name("default_model"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "default_model",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetDefaultModelResponse",
|
||||||
|
MockBuilder: upstream.DefaultModelMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
server.POST("/aiserver.v1.AiService/GetDefaultModelNudgeData",
|
server.POST("/aiserver.v1.AiService/GetDefaultModelNudgeData",
|
||||||
server.Name("default_model_nudge"),
|
server.Name("default_model_nudge"),
|
||||||
server.ConnectUnary(),
|
server.ConnectUnary(),
|
||||||
@@ -359,6 +399,34 @@ func (host *Host) rebuildLocked(cfg serverconfig.Config) error {
|
|||||||
MockBuilder: upstream.FirstWindowStatsigDecisionMockBuilder,
|
MockBuilder: upstream.FirstWindowStatsigDecisionMockBuilder,
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
|
server.POST("/aiserver.v1.AnalyticsService/SubmitLogs",
|
||||||
|
server.Name("analytics_submit_logs"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "analytics_submit_logs",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.SubmitLogsResponse",
|
||||||
|
MockBuilder: upstream.SubmitLogsMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.AnalyticsService/TrackEvents",
|
||||||
|
server.Name("analytics_track_events"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "analytics_track_events",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.TrackEventsResponse",
|
||||||
|
MockBuilder: upstream.EmptyMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/v1/traces",
|
||||||
|
server.Name("otlp_traces"),
|
||||||
|
server.HTTP(),
|
||||||
|
server.Local(upstream.FixedStatusAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "otlp_traces",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
})),
|
||||||
|
),
|
||||||
server.POST("/oauth/token",
|
server.POST("/oauth/token",
|
||||||
server.Name("oauth_token"),
|
server.Name("oauth_token"),
|
||||||
server.HTTP(),
|
server.HTTP(),
|
||||||
@@ -477,6 +545,76 @@ func (host *Host) rebuildLocked(cfg serverconfig.Config) error {
|
|||||||
}),
|
}),
|
||||||
)),
|
)),
|
||||||
),
|
),
|
||||||
|
server.POST("/aiserver.v1.DashboardService/GetTeamAdminSettingsOrEmptyIfNotInTeam",
|
||||||
|
server.Name("dashboard_get_team_admin_settings_or_empty"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "dashboard_get_team_admin_settings_or_empty",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetTeamAdminSettingsResponse",
|
||||||
|
MockBuilder: upstream.EmptyMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.DashboardService/GetTeamReposOrEmptyIfNotInTeam",
|
||||||
|
server.Name("dashboard_get_team_repos_or_empty"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "dashboard_get_team_repos_or_empty",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetTeamReposResponse",
|
||||||
|
MockBuilder: upstream.EmptyMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.DashboardService/ListMarketplaces",
|
||||||
|
server.Name("dashboard_list_marketplaces"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "dashboard_list_marketplaces",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.ListMarketplacesResponse",
|
||||||
|
MockBuilder: upstream.EmptyMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.DashboardService/GetGlobalCommands",
|
||||||
|
server.Name("dashboard_get_global_commands"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "dashboard_get_global_commands",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetGlobalCommandsResponse",
|
||||||
|
MockBuilder: upstream.EmptyMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.DashboardService/GetEffectiveUserPlugins",
|
||||||
|
server.Name("dashboard_get_effective_user_plugins"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "dashboard_get_effective_user_plugins",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetEffectiveUserPluginsResponse",
|
||||||
|
MockBuilder: upstream.EmptyMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.DashboardService/RegisterMarketplaceAndPlugins",
|
||||||
|
server.Name("dashboard_register_marketplace_and_plugins"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "dashboard_register_marketplace_and_plugins",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.RegisterMarketplaceAndPluginsResponse",
|
||||||
|
MockBuilder: upstream.EmptyMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
server.POST("/aiserver.v1.DashboardService/GetCliDownloadUrl",
|
||||||
|
server.Name("dashboard_get_cli_download_url"),
|
||||||
|
server.ConnectUnary(),
|
||||||
|
server.Local(upstream.MockProtoAction(routeDeps, upstream.CompatRouteConfig{
|
||||||
|
Name: "dashboard_get_cli_download_url",
|
||||||
|
StatusCode: http.StatusOK,
|
||||||
|
MockProtoType: "aiserver.v1.GetCliDownloadUrlResponse",
|
||||||
|
MockBuilder: upstream.EmptyMockBuilder,
|
||||||
|
})),
|
||||||
|
),
|
||||||
server.POST("/aiserver.v1.DashboardService/GetMe",
|
server.POST("/aiserver.v1.DashboardService/GetMe",
|
||||||
server.Name("dashboard_get_me"),
|
server.Name("dashboard_get_me"),
|
||||||
server.ConnectUnary(),
|
server.ConnectUnary(),
|
||||||
|
|||||||
@@ -193,6 +193,18 @@ func DefaultModelNudgeMockBuilder(reqCtx *RequestContext) (map[string]any, error
|
|||||||
return buildDefaultModelNudgeDataPayload(reqCtx)
|
return buildDefaultModelNudgeDataPayload(reqCtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UsableModelsMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
|
return buildUsableModelsPayload(reqCtx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DefaultModelForCliMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
|
return buildDefaultModelForCliPayload(reqCtx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DefaultModelMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
|
return buildDefaultModelPayload(reqCtx)
|
||||||
|
}
|
||||||
|
|
||||||
func BootstrapStatsigMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
func BootstrapStatsigMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
return buildBootstrapStatsigPayload(reqCtx)
|
return buildBootstrapStatsigPayload(reqCtx)
|
||||||
}
|
}
|
||||||
@@ -213,6 +225,18 @@ func DashboardManagedSkillsMockBuilder(reqCtx *RequestContext) (map[string]any,
|
|||||||
return buildDashboardManagedSkillsPayload(reqCtx)
|
return buildDashboardManagedSkillsPayload(reqCtx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EmptyMockBuilder возвращает пустой proto-ответ для ручек, где клиенту
|
||||||
|
// достаточно успешного "пусто": нет team-настроек, нет репозиториев,
|
||||||
|
// нет маркетплейсов/плагинов/команд, телеметрия принята без обработки.
|
||||||
|
func EmptyMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
|
return map[string]any{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SubmitLogsMockBuilder подтверждает приём логов телеметрии без обработки.
|
||||||
|
func SubmitLogsMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
|
return map[string]any{"success": true}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func DashboardGetMeMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
func DashboardGetMeMockBuilder(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
return buildDashboardGetMePayload(reqCtx)
|
return buildDashboardGetMePayload(reqCtx)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"cursor/gen/agentv1"
|
||||||
"cursor/gen/aiserverv1"
|
"cursor/gen/aiserverv1"
|
||||||
"cursor/internal/logger"
|
"cursor/internal/logger"
|
||||||
"cursor/internal/netproxy"
|
"cursor/internal/netproxy"
|
||||||
@@ -426,6 +427,30 @@ func newProtoMessage(typeName string) (proto.Message, error) {
|
|||||||
return &aiserverv1.GetUsageLimitStatusAndActiveGrantsResponse{}, nil
|
return &aiserverv1.GetUsageLimitStatusAndActiveGrantsResponse{}, nil
|
||||||
case "aiserver.v1.IsOnNewPricingResponse":
|
case "aiserver.v1.IsOnNewPricingResponse":
|
||||||
return &aiserverv1.IsOnNewPricingResponse{}, nil
|
return &aiserverv1.IsOnNewPricingResponse{}, nil
|
||||||
|
case "aiserver.v1.GetTeamAdminSettingsResponse":
|
||||||
|
return &aiserverv1.GetTeamAdminSettingsResponse{}, nil
|
||||||
|
case "aiserver.v1.GetTeamReposResponse":
|
||||||
|
return &aiserverv1.GetTeamReposResponse{}, nil
|
||||||
|
case "aiserver.v1.ListMarketplacesResponse":
|
||||||
|
return &aiserverv1.ListMarketplacesResponse{}, nil
|
||||||
|
case "aiserver.v1.GetUsableModelsResponse":
|
||||||
|
return &agentv1.GetUsableModelsResponse{}, nil
|
||||||
|
case "aiserver.v1.GetDefaultModelForCliResponse":
|
||||||
|
return &agentv1.GetDefaultModelForCliResponse{}, nil
|
||||||
|
case "aiserver.v1.GetDefaultModelResponse":
|
||||||
|
return &aiserverv1.GetDefaultModelResponse{}, nil
|
||||||
|
case "aiserver.v1.GetGlobalCommandsResponse":
|
||||||
|
return &aiserverv1.GetGlobalCommandsResponse{}, nil
|
||||||
|
case "aiserver.v1.GetEffectiveUserPluginsResponse":
|
||||||
|
return &aiserverv1.GetEffectiveUserPluginsResponse{}, nil
|
||||||
|
case "aiserver.v1.RegisterMarketplaceAndPluginsResponse":
|
||||||
|
return &aiserverv1.RegisterMarketplaceAndPluginsResponse{}, nil
|
||||||
|
case "aiserver.v1.GetCliDownloadUrlResponse":
|
||||||
|
return &aiserverv1.GetCliDownloadUrlResponse{}, nil
|
||||||
|
case "aiserver.v1.SubmitLogsResponse":
|
||||||
|
return &aiserverv1.SubmitLogsResponse{}, nil
|
||||||
|
case "aiserver.v1.TrackEventsResponse":
|
||||||
|
return &aiserverv1.TrackEventsResponse{}, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported proto message type %q", typeName)
|
return nil, fmt.Errorf("unsupported proto message type %q", typeName)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,13 @@ const (
|
|||||||
|
|
||||||
modelRuntimeThinkingEffortParameterID = "thinking_effort"
|
modelRuntimeThinkingEffortParameterID = "thinking_effort"
|
||||||
|
|
||||||
|
// localPathEncryptionKey — стабильный ключ шифрования путей для индексации
|
||||||
|
// репозитория, который cursor-agent CLI запрашивает через GetServerConfig
|
||||||
|
// (indexingConfig.default{User,Team}PathEncryptionKey). Без него CLI
|
||||||
|
// не может инициализировать repo identity в git-воркспейсе и вызовы
|
||||||
|
// файловых инструментов падают с "[unimplemented] HTTP 404".
|
||||||
|
localPathEncryptionKey = "6f6e63652d6c6f63616c2d706174682d656e6372797074696f6e2d6b6579"
|
||||||
|
|
||||||
localUltraMembershipType = "ultra"
|
localUltraMembershipType = "ultra"
|
||||||
localUltraPaymentID = "local_ultra"
|
localUltraPaymentID = "local_ultra"
|
||||||
localUltraSubscriptionStatus = "active"
|
localUltraSubscriptionStatus = "active"
|
||||||
@@ -425,8 +432,12 @@ func buildServerTimePayload(*RequestContext) (map[string]any, error) {
|
|||||||
func buildServerConfigPayload(*RequestContext) (map[string]any, error) {
|
func buildServerConfigPayload(*RequestContext) (map[string]any, error) {
|
||||||
return map[string]any{
|
return map[string]any{
|
||||||
"configVersion": "local_cli_sandbox_defaults_disabled_v2",
|
"configVersion": "local_cli_sandbox_defaults_disabled_v2",
|
||||||
// "http2Config": "HTTP2_CONFIG_FORCE_ALL_DISABLED",
|
"http2Config": "HTTP2_CONFIG_FORCE_ALL_DISABLED",
|
||||||
"cliSandboxDefaultEnabled": true,
|
"cliSandboxDefaultEnabled": true,
|
||||||
|
"indexingConfig": map[string]any{
|
||||||
|
"defaultUserPathEncryptionKey": localPathEncryptionKey,
|
||||||
|
"defaultTeamPathEncryptionKey": localPathEncryptionKey,
|
||||||
|
},
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,6 +451,7 @@ func buildAvailableModelsPayload(reqCtx *RequestContext) (map[string]any, error)
|
|||||||
if len(modelRefs) > 0 {
|
if len(modelRefs) > 0 {
|
||||||
defaultModel = modelRefs[0]
|
defaultModel = modelRefs[0]
|
||||||
}
|
}
|
||||||
|
modelEntries := buildAvailableModelEntries(adapters)
|
||||||
return map[string]any{
|
return map[string]any{
|
||||||
"backgroundComposerModelConfig": map[string]any{
|
"backgroundComposerModelConfig": map[string]any{
|
||||||
"bestOfNDefaultModels": append([]string(nil), modelRefs...),
|
"bestOfNDefaultModels": append([]string(nil), modelRefs...),
|
||||||
@@ -459,7 +471,7 @@ func buildAvailableModelsPayload(reqCtx *RequestContext) (map[string]any, error)
|
|||||||
"defaultModel": defaultModel,
|
"defaultModel": defaultModel,
|
||||||
},
|
},
|
||||||
"disableUnusedModelsAfterNHours": availableModelsDisableUnusedHours,
|
"disableUnusedModelsAfterNHours": availableModelsDisableUnusedHours,
|
||||||
"models": buildAvailableModelEntries(adapters),
|
"models": modelEntries,
|
||||||
"planExecutionModelConfig": map[string]any{
|
"planExecutionModelConfig": map[string]any{
|
||||||
"defaultModel": defaultModel,
|
"defaultModel": defaultModel,
|
||||||
"fallbackModels": append([]string(nil), modelRefs...),
|
"fallbackModels": append([]string(nil), modelRefs...),
|
||||||
@@ -486,6 +498,35 @@ func buildDefaultModelNudgeDataPayload(reqCtx *RequestContext) (map[string]any,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildUsableModelsPayload(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
|
adapters, err := loadConfiguredModelAdapters(reqCtx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return map[string]any{"models": buildCLIModelDetails(adapters)}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildDefaultModelForCliPayload(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
|
adapters, err := loadConfiguredModelAdapters(reqCtx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
models := buildCLIModelDetails(adapters)
|
||||||
|
if len(models) == 0 {
|
||||||
|
return map[string]any{"model": map[string]any{}}, nil
|
||||||
|
}
|
||||||
|
return map[string]any{"model": models[0]}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildDefaultModelPayload(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
|
adapters, err := loadConfiguredModelAdapters(reqCtx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defaultModel := firstModelAdapterRef(adapters)
|
||||||
|
return map[string]any{"model": defaultModel, "thinkingModel": defaultModel}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func buildBootstrapStatsigPayload(reqCtx *RequestContext) (map[string]any, error) {
|
func buildBootstrapStatsigPayload(reqCtx *RequestContext) (map[string]any, error) {
|
||||||
generatedAtMs := uint64(time.Now().UnixMilli())
|
generatedAtMs := uint64(time.Now().UnixMilli())
|
||||||
authID := resolveBootstrapStatsigAuthID(reqCtx)
|
authID := resolveBootstrapStatsigAuthID(reqCtx)
|
||||||
@@ -679,6 +720,25 @@ func buildAvailableModelEntries(adapters []legacyruntime.ModelAdapterConfig) []m
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildCLIModelDetails(adapters []legacyruntime.ModelAdapterConfig) []map[string]any {
|
||||||
|
models := make([]map[string]any, 0, len(adapters))
|
||||||
|
for _, adapter := range adapters {
|
||||||
|
channelID := strings.TrimSpace(adapter.ID)
|
||||||
|
if channelID == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
models = append(models, map[string]any{
|
||||||
|
"modelId": channelID,
|
||||||
|
"displayModelId": channelID,
|
||||||
|
"apiKeyCredentials": map[string]any{
|
||||||
|
"apiKey": strings.TrimSpace(adapter.APIKey),
|
||||||
|
"baseUrl": strings.TrimSpace(adapter.BaseURL),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return models
|
||||||
|
}
|
||||||
|
|
||||||
func buildThinkingEffortParameterDefinitions(adapterType string) []map[string]any {
|
func buildThinkingEffortParameterDefinitions(adapterType string) []map[string]any {
|
||||||
values := thinkingEffortValuesForAdapter(adapterType)
|
values := thinkingEffortValuesForAdapter(adapterType)
|
||||||
options := make([]map[string]any, 0, len(values))
|
options := make([]map[string]any, 0, len(values))
|
||||||
@@ -823,6 +883,16 @@ func collectModelAdapterRefs(adapters []legacyruntime.ModelAdapterConfig) []stri
|
|||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// firstModelAdapterRef возвращает канал первого адаптера или пустую строку,
|
||||||
|
// если ни один адаптер не сконфигурирован.
|
||||||
|
func firstModelAdapterRef(adapters []legacyruntime.ModelAdapterConfig) string {
|
||||||
|
refs := collectModelAdapterRefs(adapters)
|
||||||
|
if len(refs) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return refs[0]
|
||||||
|
}
|
||||||
|
|
||||||
func resolveBootstrapStatsigAuthID(reqCtx *RequestContext) string {
|
func resolveBootstrapStatsigAuthID(reqCtx *RequestContext) string {
|
||||||
if reqCtx != nil {
|
if reqCtx != nil {
|
||||||
if authID := authIDFromBearer(reqCtx.Headers.Get("authorization")); authID != "" {
|
if authID := authIDFromBearer(reqCtx.Headers.Get("authorization")); authID != "" {
|
||||||
|
|||||||
@@ -2,9 +2,55 @@ package upstream
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"cursor/gen/agentv1"
|
||||||
|
legacyruntime "cursor/internal/runtime"
|
||||||
|
|
||||||
|
"google.golang.org/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestBuildCLIModelDetailsPreservesChannelCredentials(t *testing.T) {
|
||||||
|
adapters := []legacyruntime.ModelAdapterConfig{
|
||||||
|
{ID: " channel-a ", ModelID: "model-a", APIKey: "provider-secret-a", BaseURL: "https://provider-a.example/v1"},
|
||||||
|
{ID: "channel-b", ModelID: "model-a"},
|
||||||
|
{ID: "", ModelID: "model-c"},
|
||||||
|
}
|
||||||
|
|
||||||
|
got := buildCLIModelDetails(adapters)
|
||||||
|
want := []map[string]any{
|
||||||
|
{"modelId": "channel-a", "displayModelId": "channel-a", "apiKeyCredentials": map[string]any{"apiKey": "provider-secret-a", "baseUrl": "https://provider-a.example/v1"}},
|
||||||
|
{"modelId": "channel-b", "displayModelId": "channel-b", "apiKeyCredentials": map[string]any{"apiKey": "", "baseUrl": ""}},
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, want) {
|
||||||
|
t.Fatalf("build CLI model details: got %v, want %v", got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEncodeCLIModelsUsesAgentModelDetailsWireFormat(t *testing.T) {
|
||||||
|
payload := map[string]any{"models": buildCLIModelDetails([]legacyruntime.ModelAdapterConfig{{ID: "channel-a", APIKey: "provider-secret", BaseURL: "https://provider.example/v1"}})}
|
||||||
|
encoded, err := encodeMockProto("aiserver.v1.GetUsableModelsResponse", payload)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("encode CLI models: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
response := &agentv1.GetUsableModelsResponse{}
|
||||||
|
if err := proto.Unmarshal(encoded, response); err != nil {
|
||||||
|
t.Fatalf("decode CLI models with agent proto: %v", err)
|
||||||
|
}
|
||||||
|
if len(response.Models) != 1 {
|
||||||
|
t.Fatalf("decoded model count: got %d, want 1", len(response.Models))
|
||||||
|
}
|
||||||
|
model := response.Models[0]
|
||||||
|
if model.GetModelId() != "channel-a" || model.GetDisplayModelId() != "channel-a" {
|
||||||
|
t.Fatalf("decoded channel IDs: model=%q display=%q", model.GetModelId(), model.GetDisplayModelId())
|
||||||
|
}
|
||||||
|
if credentials := model.GetApiKeyCredentials(); credentials == nil || credentials.GetApiKey() != "provider-secret" || credentials.GetBaseUrl() != "https://provider.example/v1" {
|
||||||
|
t.Fatalf("decoded relay credentials: %#v", credentials)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBuildBootstrapStatsigConfigJSONDisablesAlwaysLocalDecompositionGate(t *testing.T) {
|
func TestBuildBootstrapStatsigConfigJSONDisablesAlwaysLocalDecompositionGate(t *testing.T) {
|
||||||
payload, err := buildBootstrapStatsigConfigJSON(12345, "test-auth-id")
|
payload, err := buildBootstrapStatsigConfigJSON(12345, "test-auth-id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+2500
-739
File diff suppressed because it is too large
Load Diff
+10896
-4348
File diff suppressed because it is too large
Load Diff
+205
-39
@@ -113,10 +113,14 @@ var (
|
|||||||
mapValueRe = regexp.MustCompile(`V:\s*\{([^}]*)\}`)
|
mapValueRe = regexp.MustCompile(`V:\s*\{([^}]*)\}`)
|
||||||
mapValueKRe = regexp.MustCompile(`(?:^|[,{]\s*)kind:\s*["'](\w+)["']`)
|
mapValueKRe = regexp.MustCompile(`(?:^|[,{]\s*)kind:\s*["'](\w+)["']`)
|
||||||
mapValueTRe = regexp.MustCompile(`[,\s]T:\s*([\w$.]+)`)
|
mapValueTRe = regexp.MustCompile(`[,\s]T:\s*([\w$.]+)`)
|
||||||
|
shorthandTRe = regexp.MustCompile(`(?:^|[,\{])\s*T\s*(?:[,\}])`)
|
||||||
oneofNameRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
|
oneofNameRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
|
||||||
fieldNameRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
|
fieldNameRe = regexp.MustCompile(`^[A-Za-z_][A-Za-z0-9_]*$`)
|
||||||
placeholderRe = regexp.MustCompile(`^\s*(optional\s+|repeated\s+)?[A-Za-z_][A-Za-z0-9_.<>]*\s+(field_\d+|unknown(?:_[A-Za-z0-9_]+)?)\s*=\s*\d+\s*;`)
|
placeholderRe = regexp.MustCompile(`^\s*(optional\s+|repeated\s+)?[A-Za-z_][A-Za-z0-9_.<>]*\s+(field_\d+|unknown(?:_[A-Za-z0-9_]+)?)\s*=\s*\d+\s*;`)
|
||||||
varAliasRe = regexp.MustCompile(`\b(?:let|const|var)\s+([\w$]+)\s*=\s*([\w$]+)\s*(?:[,;])`)
|
varAliasRe = regexp.MustCompile(`\b(?:let|const|var)\s+([\w$]+)\s*=\s*([\w$]+)\s*(?:[,;])`)
|
||||||
|
webpackExportBlockRe = regexp.MustCompile(`[\w$]+\.d\(\s*[\w$]+\s*,\s*\{`)
|
||||||
|
webpackExportEntryRe = regexp.MustCompile(`(?:^|[,\{])\s*([\w$]+)\s*:\s*\(\s*\)\s*=>\s*([\w$]+)`)
|
||||||
|
moduleImportRe = regexp.MustCompile(`(?:\b(?:var|let|const)\s+|,)\s*([\w$]+)\s*=\s*[\w$]+\(\s*(\d+)\s*\)`)
|
||||||
streamCloseRe = regexp.MustCompile(`(?s)message\s+ExecClientControlMessage\s*\{.*?ExecClientStreamClose\s+stream_close\s*=\s*1\s*;`)
|
streamCloseRe = regexp.MustCompile(`(?s)message\s+ExecClientControlMessage\s*\{.*?ExecClientStreamClose\s+stream_close\s*=\s*1\s*;`)
|
||||||
shellStdoutRe = regexp.MustCompile(`(?s)message\s+ShellStream\s*\{.*?ShellStreamStdout\s+stdout\s*=\s*1\s*;`)
|
shellStdoutRe = regexp.MustCompile(`(?s)message\s+ShellStream\s*\{.*?ShellStreamStdout\s+stdout\s*=\s*1\s*;`)
|
||||||
)
|
)
|
||||||
@@ -186,12 +190,17 @@ type symbolDef struct {
|
|||||||
|
|
||||||
type TypeResolver struct {
|
type TypeResolver struct {
|
||||||
bySymbol map[string][]symbolDef
|
bySymbol map[string][]symbolDef
|
||||||
|
byAlias map[string][]symbolDef
|
||||||
byShort map[string][]symbolDef
|
byShort map[string][]symbolDef
|
||||||
|
moduleImports map[int]map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTypeResolver(messages []Message, enums []Enum, aliases map[string][]string) *TypeResolver {
|
type aliasIndex map[int]map[string][]string
|
||||||
|
|
||||||
|
func newTypeResolver(messages []Message, enums []Enum, aliases aliasIndex, exportAliases aliasIndex) *TypeResolver {
|
||||||
resolver := &TypeResolver{
|
resolver := &TypeResolver{
|
||||||
bySymbol: make(map[string][]symbolDef),
|
bySymbol: make(map[string][]symbolDef),
|
||||||
|
byAlias: make(map[string][]symbolDef),
|
||||||
byShort: make(map[string][]symbolDef),
|
byShort: make(map[string][]symbolDef),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,43 +227,64 @@ func newTypeResolver(messages []Message, enums []Enum, aliases map[string][]stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
addAlias := func(symbol, typeName string, pos int, moduleStart int, kind string) {
|
||||||
|
symbol = strings.TrimSpace(symbol)
|
||||||
|
typeName = strings.TrimSpace(typeName)
|
||||||
|
if symbol == "" || typeName == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resolver.byAlias[symbol] = append(resolver.byAlias[symbol], symbolDef{
|
||||||
|
TypeName: typeName, Pos: pos, ModuleStart: moduleStart, Kind: kind,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
add(msg.VarName, msg.TypeName, msg.Pos, msg.ModuleStart, "message")
|
add(msg.VarName, msg.TypeName, msg.Pos, msg.ModuleStart, "message")
|
||||||
if msg.InternalName != "" && msg.InternalName != msg.VarName {
|
if msg.InternalName != "" && msg.InternalName != msg.VarName {
|
||||||
add(msg.InternalName, msg.TypeName, msg.Pos, msg.ModuleStart, "message")
|
add(msg.InternalName, msg.TypeName, msg.Pos, msg.ModuleStart, "message")
|
||||||
}
|
}
|
||||||
for _, alias := range aliasesForSymbols(aliases, msg.VarName, msg.InternalName) {
|
for _, alias := range aliasesForSymbols(aliases[msg.ModuleStart], msg.VarName, msg.InternalName) {
|
||||||
add(alias, msg.TypeName, msg.Pos, msg.ModuleStart, "message")
|
addAlias(alias, msg.TypeName, msg.Pos, msg.ModuleStart, "message")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, enum := range enums {
|
for _, enum := range enums {
|
||||||
add(enum.VarName, enum.TypeName, enum.Pos, enum.ModuleStart, "enum")
|
add(enum.VarName, enum.TypeName, enum.Pos, enum.ModuleStart, "enum")
|
||||||
for _, alias := range aliasesForSymbols(aliases, enum.VarName) {
|
for _, alias := range aliasesForSymbols(aliases[enum.ModuleStart], enum.VarName) {
|
||||||
add(alias, enum.TypeName, enum.Pos, enum.ModuleStart, "enum")
|
addAlias(alias, enum.TypeName, enum.Pos, enum.ModuleStart, "enum")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, msg := range messages {
|
||||||
|
for _, alias := range aliasesForSymbols(exportAliases[msg.ModuleStart], msg.VarName, msg.InternalName) {
|
||||||
|
addAlias(alias, msg.TypeName, msg.Pos, msg.ModuleStart, "message")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, enum := range enums {
|
||||||
|
for _, alias := range aliasesForSymbols(exportAliases[enum.ModuleStart], enum.VarName) {
|
||||||
|
addAlias(alias, enum.TypeName, enum.Pos, enum.ModuleStart, "enum")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolver
|
return resolver
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildAliasIndex(text string) map[string][]string {
|
func buildAliasIndex(text string, moduleStarts []int) aliasIndex {
|
||||||
matches := varAliasRe.FindAllStringSubmatch(text, -1)
|
matches := varAliasRe.FindAllStringSubmatchIndex(text, -1)
|
||||||
if len(matches) == 0 {
|
directByModule := make(map[int]map[string]string)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
direct := make(map[string]string, len(matches))
|
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
alias := strings.TrimSpace(match[1])
|
alias := strings.TrimSpace(text[match[2]:match[3]])
|
||||||
target := strings.TrimSpace(match[2])
|
target := strings.TrimSpace(text[match[4]:match[5]])
|
||||||
if alias == "" || target == "" || alias == target {
|
if alias == "" || target == "" || alias == target {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
direct[alias] = target
|
moduleStart := moduleStartForPos(moduleStarts, match[0])
|
||||||
|
if directByModule[moduleStart] == nil {
|
||||||
|
directByModule[moduleStart] = make(map[string]string)
|
||||||
|
}
|
||||||
|
directByModule[moduleStart][alias] = target
|
||||||
}
|
}
|
||||||
|
|
||||||
resolveRoot := func(symbol string) string {
|
resolveRoot := func(direct map[string]string, symbol string) string {
|
||||||
seen := make(map[string]bool)
|
seen := make(map[string]bool)
|
||||||
current := symbol
|
current := symbol
|
||||||
for {
|
for {
|
||||||
@@ -270,16 +300,90 @@ func buildAliasIndex(text string) map[string][]string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aliases := make(map[string][]string)
|
aliasSets := make(map[int]map[string]map[string]bool)
|
||||||
|
addAlias := func(moduleStart int, root string, alias string) {
|
||||||
|
root = strings.TrimSpace(root)
|
||||||
|
alias = strings.TrimSpace(alias)
|
||||||
|
if root == "" || alias == "" || root == alias {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if aliasSets[moduleStart] == nil {
|
||||||
|
aliasSets[moduleStart] = make(map[string]map[string]bool)
|
||||||
|
}
|
||||||
|
if aliasSets[moduleStart][root] == nil {
|
||||||
|
aliasSets[moduleStart][root] = make(map[string]bool)
|
||||||
|
}
|
||||||
|
aliasSets[moduleStart][root][alias] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
for moduleStart, direct := range directByModule {
|
||||||
for alias := range direct {
|
for alias := range direct {
|
||||||
root := resolveRoot(alias)
|
root := resolveRoot(direct, alias)
|
||||||
if root == alias {
|
addAlias(moduleStart, root, alias)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(aliasSets) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
aliases := make(aliasIndex, len(aliasSets))
|
||||||
|
for moduleStart, roots := range aliasSets {
|
||||||
|
aliases[moduleStart] = make(map[string][]string, len(roots))
|
||||||
|
for root, set := range roots {
|
||||||
|
for alias := range set {
|
||||||
|
aliases[moduleStart][root] = append(aliases[moduleStart][root], alias)
|
||||||
|
}
|
||||||
|
sort.Strings(aliases[moduleStart][root])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return aliases
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildWebpackExportAliasIndex(text string, moduleStarts []int) aliasIndex {
|
||||||
|
aliasSets := make(map[int]map[string]map[string]bool)
|
||||||
|
addAlias := func(moduleStart int, root string, alias string) {
|
||||||
|
root = strings.TrimSpace(root)
|
||||||
|
alias = strings.TrimSpace(alias)
|
||||||
|
if root == "" || alias == "" || root == alias {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if aliasSets[moduleStart] == nil {
|
||||||
|
aliasSets[moduleStart] = make(map[string]map[string]bool)
|
||||||
|
}
|
||||||
|
if aliasSets[moduleStart][root] == nil {
|
||||||
|
aliasSets[moduleStart][root] = make(map[string]bool)
|
||||||
|
}
|
||||||
|
aliasSets[moduleStart][root][alias] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Webpack exposes module members through tables such as
|
||||||
|
// n.d(t, { KS: () => T }). Service descriptors refer to the exported
|
||||||
|
// name (r.KS), while message definitions use the local symbol (T).
|
||||||
|
for _, blockMatch := range webpackExportBlockRe.FindAllStringIndex(text, -1) {
|
||||||
|
moduleStart := moduleStartForPos(moduleStarts, blockMatch[0])
|
||||||
|
blockStart := blockMatch[1] - 1
|
||||||
|
blockEnd := findMatchingBrace(text, blockStart)
|
||||||
|
if blockEnd == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
aliases[root] = append(aliases[root], alias)
|
block := text[blockStart:blockEnd]
|
||||||
|
for _, entry := range webpackExportEntryRe.FindAllStringSubmatch(block, -1) {
|
||||||
|
addAlias(moduleStart, entry[2], entry[1])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(aliasSets) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
aliases := make(aliasIndex, len(aliasSets))
|
||||||
|
for moduleStart, roots := range aliasSets {
|
||||||
|
aliases[moduleStart] = make(map[string][]string, len(roots))
|
||||||
|
for root, set := range roots {
|
||||||
|
for alias := range set {
|
||||||
|
aliases[moduleStart][root] = append(aliases[moduleStart][root], alias)
|
||||||
|
}
|
||||||
|
sort.Strings(aliases[moduleStart][root])
|
||||||
}
|
}
|
||||||
for root := range aliases {
|
|
||||||
sort.Strings(aliases[root])
|
|
||||||
}
|
}
|
||||||
return aliases
|
return aliases
|
||||||
}
|
}
|
||||||
@@ -318,11 +422,10 @@ func pickBestDefinition(candidates []symbolDef, contextPos int, contextModuleSta
|
|||||||
}
|
}
|
||||||
|
|
||||||
filtered := candidates
|
filtered := candidates
|
||||||
if strings.TrimSpace(preferredPkg) != "" {
|
if strings.TrimSpace(expectedKind) != "" {
|
||||||
tmp := make([]symbolDef, 0, len(candidates))
|
tmp := make([]symbolDef, 0, len(candidates))
|
||||||
for _, item := range candidates {
|
for _, item := range candidates {
|
||||||
pkg, _ := parseTypeName(item.TypeName)
|
if item.Kind == expectedKind {
|
||||||
if pkg == preferredPkg {
|
|
||||||
tmp = append(tmp, item)
|
tmp = append(tmp, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -331,10 +434,11 @@ func pickBestDefinition(candidates []symbolDef, contextPos int, contextModuleSta
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.TrimSpace(expectedKind) != "" {
|
if strings.TrimSpace(preferredPkg) != "" {
|
||||||
tmp := make([]symbolDef, 0, len(filtered))
|
tmp := make([]symbolDef, 0, len(filtered))
|
||||||
for _, item := range filtered {
|
for _, item := range filtered {
|
||||||
if item.Kind == expectedKind {
|
pkg, _ := parseTypeName(item.TypeName)
|
||||||
|
if pkg == preferredPkg {
|
||||||
tmp = append(tmp, item)
|
tmp = append(tmp, item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,6 +520,17 @@ func (resolver *TypeResolver) ResolveTypeName(ref string, contextPos int, contex
|
|||||||
}
|
}
|
||||||
return best.TypeName, true
|
return best.TypeName, true
|
||||||
}
|
}
|
||||||
|
resolveByAlias := func(symbol string, targetModuleStart int) (string, bool) {
|
||||||
|
candidates := resolver.byAlias[symbol]
|
||||||
|
if len(candidates) == 0 {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
best, ok := pickBestDefinition(candidates, contextPos, targetModuleStart, preferredPkg, expectedKind)
|
||||||
|
if !ok {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return best.TypeName, true
|
||||||
|
}
|
||||||
resolveByShort := func(symbol string, preferSameModule bool) (string, bool) {
|
resolveByShort := func(symbol string, preferSameModule bool) (string, bool) {
|
||||||
candidates := resolver.byShort[symbol]
|
candidates := resolver.byShort[symbol]
|
||||||
if len(candidates) == 0 {
|
if len(candidates) == 0 {
|
||||||
@@ -435,17 +550,30 @@ func (resolver *TypeResolver) ResolveTypeName(ref string, contextPos int, contex
|
|||||||
if typeName, ok := resolveBySymbol(trimmed, !strings.Contains(trimmed, ".")); ok {
|
if typeName, ok := resolveBySymbol(trimmed, !strings.Contains(trimmed, ".")); ok {
|
||||||
return typeName, true
|
return typeName, true
|
||||||
}
|
}
|
||||||
|
if typeName, ok := resolveByAlias(trimmed, 0); ok {
|
||||||
|
return typeName, true
|
||||||
|
}
|
||||||
if typeName, ok := resolveByShort(trimmed, !strings.Contains(trimmed, ".")); ok {
|
if typeName, ok := resolveByShort(trimmed, !strings.Contains(trimmed, ".")); ok {
|
||||||
return typeName, true
|
return typeName, true
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(trimmed, ".") {
|
if strings.Contains(trimmed, ".") {
|
||||||
parts := strings.Split(trimmed, ".")
|
parts := strings.Split(trimmed, ".")
|
||||||
|
first := parts[0]
|
||||||
last := parts[len(parts)-1]
|
last := parts[len(parts)-1]
|
||||||
|
targetModuleStart := 0
|
||||||
|
if imports := resolver.moduleImports[contextModuleStart]; imports != nil {
|
||||||
|
targetModuleStart = imports[first]
|
||||||
|
}
|
||||||
|
if typeName, ok := resolveByAlias(last, targetModuleStart); ok {
|
||||||
|
return typeName, true
|
||||||
|
}
|
||||||
|
if typeName, ok := resolveBySymbol(last, false); ok {
|
||||||
|
return typeName, true
|
||||||
|
}
|
||||||
if typeName, ok := resolveByShort(last, false); ok {
|
if typeName, ok := resolveByShort(last, false); ok {
|
||||||
return typeName, true
|
return typeName, true
|
||||||
}
|
}
|
||||||
first := parts[0]
|
|
||||||
if typeName, ok := resolveBySymbol(first, false); ok {
|
if typeName, ok := resolveBySymbol(first, false); ok {
|
||||||
return typeName, true
|
return typeName, true
|
||||||
}
|
}
|
||||||
@@ -473,7 +601,7 @@ func absInt(value int) int {
|
|||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
var moduleStartRe = regexp.MustCompile(`(?:^|,)(\d+):(?:function\([\w$,]*\)|\([\w$,]*\)=>)\{`)
|
var moduleStartRe = regexp.MustCompile(`(?:^|,)\s*(\d+)\s*:\s*(?:function\s*\(\s*[\w$,\s]*\s*\)|\(\s*[\w$,\s]*\s*\)\s*=>)\s*\{`)
|
||||||
|
|
||||||
func buildModuleStarts(text string) []int {
|
func buildModuleStarts(text string) []int {
|
||||||
matches := moduleStartRe.FindAllStringSubmatchIndex(text, -1)
|
matches := moduleStartRe.FindAllStringSubmatchIndex(text, -1)
|
||||||
@@ -497,6 +625,38 @@ func moduleStartForPos(moduleStarts []int, pos int) int {
|
|||||||
return moduleStarts[index]
|
return moduleStarts[index]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildModuleImportIndex(text string, moduleStarts []int) map[int]map[string]int {
|
||||||
|
if len(moduleStarts) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleMatches := moduleStartRe.FindAllStringSubmatchIndex(text, -1)
|
||||||
|
moduleStartByID := make(map[string]int, len(moduleMatches))
|
||||||
|
for _, match := range moduleMatches {
|
||||||
|
moduleStartByID[text[match[2]:match[3]]] = match[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
importsByModule := make(map[int]map[string]int)
|
||||||
|
for index, moduleStart := range moduleStarts {
|
||||||
|
moduleEnd := len(text)
|
||||||
|
if index+1 < len(moduleStarts) {
|
||||||
|
moduleEnd = moduleStarts[index+1]
|
||||||
|
}
|
||||||
|
body := text[moduleStart:moduleEnd]
|
||||||
|
for _, match := range moduleImportRe.FindAllStringSubmatch(body, -1) {
|
||||||
|
targetModuleStart, ok := moduleStartByID[match[2]]
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if importsByModule[moduleStart] == nil {
|
||||||
|
importsByModule[moduleStart] = make(map[string]int)
|
||||||
|
}
|
||||||
|
importsByModule[moduleStart][match[1]] = targetModuleStart
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return importsByModule
|
||||||
|
}
|
||||||
|
|
||||||
// ExtractProtos extracts proto definitions from formatted JS file
|
// ExtractProtos extracts proto definitions from formatted JS file
|
||||||
func ExtractProtos(inputFile, outputDir string) {
|
func ExtractProtos(inputFile, outputDir string) {
|
||||||
activeDiagnostics = newExtractionDiagnostics()
|
activeDiagnostics = newExtractionDiagnostics()
|
||||||
@@ -512,7 +672,8 @@ func ExtractProtos(inputFile, outputDir string) {
|
|||||||
|
|
||||||
text := string(content)
|
text := string(content)
|
||||||
moduleStarts := buildModuleStarts(text)
|
moduleStarts := buildModuleStarts(text)
|
||||||
aliases := buildAliasIndex(text)
|
aliases := buildAliasIndex(text, moduleStarts)
|
||||||
|
exportAliases := buildWebpackExportAliasIndex(text, moduleStarts)
|
||||||
|
|
||||||
// Extract messages, enums, and services
|
// Extract messages, enums, and services
|
||||||
messages := extractMessages(text, moduleStarts)
|
messages := extractMessages(text, moduleStarts)
|
||||||
@@ -524,7 +685,8 @@ func ExtractProtos(inputFile, outputDir string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resolver := newTypeResolver(messages, enums, aliases)
|
resolver := newTypeResolver(messages, enums, aliases, exportAliases)
|
||||||
|
resolver.moduleImports = buildModuleImportIndex(text, moduleStarts)
|
||||||
|
|
||||||
// Generate proto files
|
// Generate proto files
|
||||||
generateProtos(messages, enums, services, resolver, outputDir)
|
generateProtos(messages, enums, services, resolver, outputDir)
|
||||||
@@ -900,6 +1062,8 @@ func parseFieldObject(obj string) (*Field, error) {
|
|||||||
} else {
|
} else {
|
||||||
field.T = tMatch[1]
|
field.T = tMatch[1]
|
||||||
}
|
}
|
||||||
|
} else if shorthandTRe.MatchString(obj) {
|
||||||
|
field.T = "T"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1195,8 +1359,9 @@ func copyAllExternalTypes(pkgName string, pkg struct {
|
|||||||
neededTypes := make(map[string]bool)
|
neededTypes := make(map[string]bool)
|
||||||
|
|
||||||
for _, msg := range result.messages {
|
for _, msg := range result.messages {
|
||||||
|
preferredPkg, _ := parseTypeName(msg.TypeName)
|
||||||
for _, f := range msg.Fields {
|
for _, f := range msg.Fields {
|
||||||
collectFieldRefsSimple(f, pkgName, msg.Pos, msg.ModuleStart, resolver, neededTypes, localTypes)
|
collectFieldRefsSimple(f, pkgName, preferredPkg, msg.Pos, msg.ModuleStart, resolver, neededTypes, localTypes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, svc := range result.services {
|
for _, svc := range result.services {
|
||||||
@@ -1268,7 +1433,7 @@ func copyAllExternalTypes(pkgName string, pkg struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// collectFieldRefsSimple collects external type references from a field (non-recursive, just this field)
|
// collectFieldRefsSimple collects external type references from a field (non-recursive, just this field)
|
||||||
func collectFieldRefsSimple(f Field, currentPkg string, contextPos int, contextModuleStart int, resolver *TypeResolver,
|
func collectFieldRefsSimple(f Field, currentPkg string, preferredPkg string, contextPos int, contextModuleStart int, resolver *TypeResolver,
|
||||||
neededTypes map[string]bool, localTypes map[string]bool) {
|
neededTypes map[string]bool, localTypes map[string]bool) {
|
||||||
|
|
||||||
type refWithKind struct {
|
type refWithKind struct {
|
||||||
@@ -1289,7 +1454,7 @@ func collectFieldRefsSimple(f Field, currentPkg string, contextPos int, contextM
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range refs {
|
for _, item := range refs {
|
||||||
typeName, ok := resolver.ResolveTypeName(item.ref, contextPos, contextModuleStart, currentPkg, item.kind)
|
typeName, ok := resolver.ResolveTypeName(item.ref, contextPos, contextModuleStart, preferredPkg, item.kind)
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -1637,6 +1802,7 @@ func writeMessageFields(msg *Message, sb *strings.Builder, resolver *TypeResolve
|
|||||||
// Get the current message's path prefix for relative type resolution
|
// Get the current message's path prefix for relative type resolution
|
||||||
msgPath := msg.ShortName
|
msgPath := msg.ShortName
|
||||||
currentPkg := msg.Package
|
currentPkg := msg.Package
|
||||||
|
preferredPkg, _ := parseTypeName(msg.TypeName)
|
||||||
|
|
||||||
// Group fields by oneof
|
// Group fields by oneof
|
||||||
oneofGroups := make(map[string][]Field)
|
oneofGroups := make(map[string][]Field)
|
||||||
@@ -1652,7 +1818,7 @@ func writeMessageFields(msg *Message, sb *strings.Builder, resolver *TypeResolve
|
|||||||
|
|
||||||
// Write regular fields
|
// Write regular fields
|
||||||
for _, f := range regularFields {
|
for _, f := range regularFields {
|
||||||
fieldType := resolveFieldTypeWithPkg(f, resolver, msgPath, currentPkg, msg.Pos, msg.ModuleStart)
|
fieldType := resolveFieldTypeWithPkg(f, resolver, msgPath, currentPkg, preferredPkg, msg.Pos, msg.ModuleStart)
|
||||||
prefix := ""
|
prefix := ""
|
||||||
if f.Repeated {
|
if f.Repeated {
|
||||||
prefix = "repeated "
|
prefix = "repeated "
|
||||||
@@ -1673,7 +1839,7 @@ func writeMessageFields(msg *Message, sb *strings.Builder, resolver *TypeResolve
|
|||||||
fields := oneofGroups[oneofName]
|
fields := oneofGroups[oneofName]
|
||||||
sb.WriteString(fmt.Sprintf("%soneof %s {\n", indentStr, oneofName))
|
sb.WriteString(fmt.Sprintf("%soneof %s {\n", indentStr, oneofName))
|
||||||
for _, f := range fields {
|
for _, f := range fields {
|
||||||
fieldType := resolveFieldTypeWithPkg(f, resolver, msgPath, currentPkg, msg.Pos, msg.ModuleStart)
|
fieldType := resolveFieldTypeWithPkg(f, resolver, msgPath, currentPkg, preferredPkg, msg.Pos, msg.ModuleStart)
|
||||||
sb.WriteString(fmt.Sprintf("%s %s %s = %d;\n", indentStr, fieldType, f.Name, f.No))
|
sb.WriteString(fmt.Sprintf("%s %s %s = %d;\n", indentStr, fieldType, f.Name, f.No))
|
||||||
}
|
}
|
||||||
sb.WriteString(fmt.Sprintf("%s}\n", indentStr))
|
sb.WriteString(fmt.Sprintf("%s}\n", indentStr))
|
||||||
@@ -1721,15 +1887,15 @@ func getNestedPath(shortName string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resolveFieldType(f Field, resolver *TypeResolver, contextPos int, contextModuleStart int) string {
|
func resolveFieldType(f Field, resolver *TypeResolver, contextPos int, contextModuleStart int) string {
|
||||||
return resolveFieldTypeWithPkg(f, resolver, "", "", contextPos, contextModuleStart)
|
return resolveFieldTypeWithPkg(f, resolver, "", "", "", contextPos, contextModuleStart)
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveFieldTypeWithPkg resolves field type with package awareness
|
// resolveFieldTypeWithPkg resolves field type with package awareness
|
||||||
// parentPath is like "ConversationMessage" or "ConversationMessage.ToolResult"
|
// parentPath is like "ConversationMessage" or "ConversationMessage.ToolResult"
|
||||||
// currentPkg is the package of the current message being written (e.g., "agent.v1")
|
// currentPkg is the package of the current message being written (e.g., "agent.v1")
|
||||||
func resolveFieldTypeWithPkg(f Field, resolver *TypeResolver, parentPath string, currentPkg string, contextPos int, contextModuleStart int) string {
|
func resolveFieldTypeWithPkg(f Field, resolver *TypeResolver, parentPath string, currentPkg string, preferredPkg string, contextPos int, contextModuleStart int) string {
|
||||||
resolveNamedType := func(ref string, expectedKind string) string {
|
resolveNamedType := func(ref string, expectedKind string) string {
|
||||||
typeName, ok := resolver.ResolveTypeName(ref, contextPos, contextModuleStart, currentPkg, expectedKind)
|
typeName, ok := resolver.ResolveTypeName(ref, contextPos, contextModuleStart, preferredPkg, expectedKind)
|
||||||
if !ok {
|
if !ok {
|
||||||
activeDiagnostics.addUnresolvedType(expectedKind + ":" + ref)
|
activeDiagnostics.addUnresolvedType(expectedKind + ":" + ref)
|
||||||
return fallbackTypeToken(ref)
|
return fallbackTypeToken(ref)
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestParseFieldObjectSupportsShorthandType(t *testing.T) {
|
||||||
|
field, err := parseFieldObject(`{no:4,name:"file_not_found",kind:"message",T,oneof:"result"}`)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("parse shorthand T: %v", err)
|
||||||
|
}
|
||||||
|
if field.T != "T" {
|
||||||
|
t.Fatalf("parsed shorthand T as %#v, want T", field.T)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWebpackExportAliasResolvesServiceMessageType(t *testing.T) {
|
||||||
|
const bundle = `
|
||||||
|
1:(e,t,n)=>{
|
||||||
|
n.d(t,{KS:()=>T,_B:()=>r});
|
||||||
|
var r;
|
||||||
|
class T {}
|
||||||
|
T.typeName="agent.v1.AgentClientMessage";
|
||||||
|
n.proto3.util.setEnumType(r,"agent.v1.DiagnosticSeverity",[]);
|
||||||
|
},
|
||||||
|
2:(e,t,n)=>{
|
||||||
|
var r=n(1);
|
||||||
|
const service={typeName:"agent.v1.AgentService",methods:{run:{name:"Run",I:r.KS,O:r.KS,kind:n.MethodKind.BiDiStreaming}}};
|
||||||
|
}`
|
||||||
|
|
||||||
|
moduleStarts := buildModuleStarts(bundle)
|
||||||
|
messages := []Message{{
|
||||||
|
TypeName: "agent.v1.AgentClientMessage",
|
||||||
|
VarName: "T",
|
||||||
|
InternalName: "T",
|
||||||
|
Package: "agent.v1",
|
||||||
|
Pos: 35,
|
||||||
|
ModuleStart: moduleStartForPos(moduleStarts, 35),
|
||||||
|
}}
|
||||||
|
enums := []Enum{{
|
||||||
|
TypeName: "agent.v1.DiagnosticSeverity",
|
||||||
|
VarName: "r",
|
||||||
|
Package: "agent.v1",
|
||||||
|
Pos: 100,
|
||||||
|
ModuleStart: moduleStartForPos(moduleStarts, 100),
|
||||||
|
}}
|
||||||
|
|
||||||
|
resolver := newTypeResolver(messages, enums, buildAliasIndex(bundle, moduleStarts), buildWebpackExportAliasIndex(bundle, moduleStarts))
|
||||||
|
resolver.moduleImports = buildModuleImportIndex(bundle, moduleStarts)
|
||||||
|
typeName, ok := resolver.ResolveTypeName("r.KS", len(bundle)-1, moduleStartForPos(moduleStarts, len(bundle)-1), "agent.v1", "message")
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("expected webpack export alias to resolve")
|
||||||
|
}
|
||||||
|
if typeName != "agent.v1.AgentClientMessage" {
|
||||||
|
t.Fatalf("resolved r.KS to %q, want agent.v1.AgentClientMessage", typeName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestResolverPrefersExpectedKindOverCurrentPackage(t *testing.T) {
|
||||||
|
resolver := &TypeResolver{bySymbol: map[string][]symbolDef{
|
||||||
|
"nt": {
|
||||||
|
{TypeName: "git_forge.v1.GetTagResponse", Kind: "message", Pos: 10, ModuleStart: 1},
|
||||||
|
{TypeName: "origin.v1.TeamGroupKind", Kind: "enum", Pos: 20, ModuleStart: 1},
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
|
||||||
|
typeName, ok := resolver.ResolveTypeName("nt", 30, 1, "origin.v1", "message")
|
||||||
|
if !ok {
|
||||||
|
t.Fatal("expected cross-package message type to resolve")
|
||||||
|
}
|
||||||
|
if typeName != "git_forge.v1.GetTagResponse" {
|
||||||
|
t.Fatalf("resolved nt to %q, want git_forge.v1.GetTagResponse", typeName)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
src/proto/**
|
|
||||||
media/index.js
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"name":"cursor-always-local","description":"Implements experimentation features for Cursor","author":"Anysphere, Inc.","publisher":"anysphere","version":"0.0.1","private":true,"repository":{"type":"git","url":"https://github.com/anysphere/vscode"},"extensionKind":["ui"],"engines":{"vscode":"^1.43.0","yarn":"please-use-npm"},"activationEvents":["onStartupFinished","onResolveRemoteAuthority:background-composer"],"enabledApiProposals":["cursor","control","externalUriOpener","contribSourceControlInputBoxMenu"],"main":"./dist/main","contributes":{"commands":[],"keybindings":[],"menus":{"scm/inputBox":[{"command":"cursor.generateGitCommitMessage","when":"scmProvider == git"}]},"jsonValidation":[{"fileMatch":".cursor/environment.json","url":"./schemas/environment.schema.json"}],"configuration":{"type":"object","title":"Cursor Always Local"}},"optionalDependencies":{"@vscode/windows-ca-certs":"^0.3.3"}}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"displayName":"Cursor Always Local","description":"Experimentation @ cursor.sh"}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"$schema":"https://json-schema.org/draft/2019-09/schema","description":"Defines a dev environment","allowComments":true,"allowTrailingCommas":false,"definitions":{"common":{"type":"object","properties":{"name":{"type":"string","description":"The name of the environment."},"user":{"type":"string","description":"The user to run the environment as."},"install":{"type":"string","description":"The update command to run on VM startup (after pulling latest changes) to refresh dependencies."},"start":{"type":"string","description":"The start command to run when the environment is started."},"repositoryDependencies":{"type":"array","description":"Repositories that are required for the environment to work, and need to be included in the GitHub access token that is generated for the environment.","items":{"type":"string","description":"The URL of the dependent repository, e.g. `github.com/org/repo`."}},"ports":{"type":"array","description":"Ports to expose from the container. Similar to devcontainers port forwarding.","items":{"type":"object","required":["port"],"properties":{"name":{"type":"string","description":"A descriptive name for the port (e.g., 'web server', 'api')."},"port":{"type":"integer","minimum":1,"maximum":65535,"description":"The port number inside the container to expose."}}}},"terminals":{"type":"array","description":"The terminals to run when the environment is started.","items":{"oneOf":[{"type":"array","items":{"type":"object","required":["command"],"properties":{"name":{"type":"string","description":"The name of the terminal."},"command":{"type":"string","description":"The command to run in the terminal."},"description":{"type":"string","description":"A description of what the terminal does. This is displayed to the agent."}}}},{"type":"object","required":["command"],"properties":{"name":{"type":"string","description":"The name of the terminal."},"command":{"type":"string","description":"The command to run in the terminal."},"description":{"type":"string","description":"A description of what the terminal does. This is displayed to the agent."}}}]}}}},"container":{"type":"object","properties":{"build":{"type":"object","description":"Docker build-related options.","properties":{"dockerfile":{"type":"string","description":"The location of the Dockerfile that defines the contents of the container. The path is relative to the folder containing the `environment.json` file."},"context":{"type":"string","description":"The location of the context folder for building the Docker image. The path is relative to the folder containing the `environment.json` file."}},"required":["dockerfile"],"unevaluatedProperties":false},"snapshot":{"type":"string","description":"A snapshot ID for the base environment."},"agentCanUpdateSnapshot":{"type":"boolean","description":"Whether the agent can update the snapshot."}},"required":[]}},"allOf":[{"$ref":"#/definitions/container"},{"$ref":"#/definitions/common"}],"unevaluatedProperties":false}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Run vitest with any additional arguments passed after --
|
|
||||||
npx vitest run --config vitest.config.ts "$@"
|
|
||||||
|
|
||||||
# Capture the exit code
|
|
||||||
exit_code=$?
|
|
||||||
|
|
||||||
# If tests failed, echo the colored error message
|
|
||||||
if [ $exit_code -ne 0 ]; then
|
|
||||||
echo -e "\033[1;31m❌ Test failed -- you can set CURSOR_EXT_TEST_LOG_LEVEL=info to see more logs\033[0m"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Exit with the same code as vitest
|
|
||||||
exit $exit_code
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
include_files=()
|
|
||||||
for f in "$@"; do
|
|
||||||
include_files+=("${f#$PWD/}")
|
|
||||||
done
|
|
||||||
node_modules/.bin/tsc --noEmit -p . | (
|
|
||||||
status=0
|
|
||||||
show_continuation=false
|
|
||||||
while IFS='' read -r line; do
|
|
||||||
case "$line" in
|
|
||||||
(' '*)
|
|
||||||
if $show_continuation; then
|
|
||||||
echo "$line" >&2
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
(*)
|
|
||||||
file="${line%%(*}"
|
|
||||||
if [[ " ${include_files[@]} " =~ " ${file} " ]]; then
|
|
||||||
show_continuation=true
|
|
||||||
echo "$line" >&2
|
|
||||||
status=1
|
|
||||||
else
|
|
||||||
show_continuation=false
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
exit $status
|
|
||||||
)
|
|
||||||
@@ -2,22 +2,8 @@
|
|||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
SNAPSHOT_DEFAULT="$SCRIPT_DIR/extensions-cursor-app/cursor-always-local"
|
|
||||||
INSTALLED_CURSOR_DEFAULT="/Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist/main.js"
|
INSTALLED_CURSOR_DEFAULT="/Applications/Cursor.app/Contents/Resources/app/extensions/cursor-always-local/dist/main.js"
|
||||||
LATEST_EXT_DIR="$(
|
INPUT_DEFAULT="$INSTALLED_CURSOR_DEFAULT"
|
||||||
find "$SCRIPT_DIR" -maxdepth 1 -type d -name 'extensions-*' 2>/dev/null \
|
|
||||||
| sort -V \
|
|
||||||
| tail -n 1
|
|
||||||
)"
|
|
||||||
if [[ -f "$SNAPSHOT_DEFAULT/dist/main.js" ]]; then
|
|
||||||
INPUT_DEFAULT="$SNAPSHOT_DEFAULT"
|
|
||||||
elif [[ -f "$INSTALLED_CURSOR_DEFAULT" ]]; then
|
|
||||||
INPUT_DEFAULT="$INSTALLED_CURSOR_DEFAULT"
|
|
||||||
elif [[ -n "$LATEST_EXT_DIR" ]]; then
|
|
||||||
INPUT_DEFAULT="$LATEST_EXT_DIR"
|
|
||||||
else
|
|
||||||
INPUT_DEFAULT="$SCRIPT_DIR/extensions-2.6.19"
|
|
||||||
fi
|
|
||||||
OUTPUT_DEFAULT="$SCRIPT_DIR/from_extensions"
|
OUTPUT_DEFAULT="$SCRIPT_DIR/from_extensions"
|
||||||
|
|
||||||
INPUT_PATH="${1:-$INPUT_DEFAULT}"
|
INPUT_PATH="${1:-$INPUT_DEFAULT}"
|
||||||
@@ -57,7 +43,8 @@ fi
|
|||||||
|
|
||||||
if [[ ! -f "$INPUT_PATH" ]]; then
|
if [[ ! -f "$INPUT_PATH" ]]; then
|
||||||
echo "Input JS not found: $INPUT_PATH" >&2
|
echo "Input JS not found: $INPUT_PATH" >&2
|
||||||
echo "Usage: $0 [input-js-file-or-extensions-dir] [output-dir]" >&2
|
echo "Install/update Cursor, or pass an explicit input bundle:" >&2
|
||||||
|
echo " $0 /path/to/cursor-always-local/dist/main.js [output-dir]" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
+10896
-4348
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,809 @@
|
|||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package git_forge.v1;
|
||||||
|
|
||||||
|
option go_package = "react-admin/cursor-server/gen/git_forge/v1;git_forgev1";
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.BatchGetRepoContentRequest (var: Qt)
|
||||||
|
message BatchGetRepoContentRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string revision = 2;
|
||||||
|
repeated string paths = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.BatchGetRepoContentResponse (var: Ht)
|
||||||
|
message BatchGetRepoContentResponse {
|
||||||
|
repeated BatchRepoContentResult results = 1;
|
||||||
|
string resolved_commit_sha = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.BatchRepoContentResult (var: Gt)
|
||||||
|
message BatchRepoContentResult {
|
||||||
|
string path = 1;
|
||||||
|
bool found = 2;
|
||||||
|
oneof content {
|
||||||
|
FileContent file_content = 3;
|
||||||
|
DirectoryContent directory_content = 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.BlameChunk (var: sn)
|
||||||
|
message BlameChunk {
|
||||||
|
repeated ShortCommit commits = 1;
|
||||||
|
repeated BlameLineRange line_ranges = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.BlameLineRange (var: rn)
|
||||||
|
message BlameLineRange {
|
||||||
|
bytes commit_sha = 1;
|
||||||
|
uint32 start_in_blamed_file = 2;
|
||||||
|
uint32 len = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CanMergeRequest (var: ft)
|
||||||
|
message CanMergeRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string ours = 2;
|
||||||
|
string theirs = 3;
|
||||||
|
uint64 change_number = 4;
|
||||||
|
MergeMode mode = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CanMergeResponse (var: gt)
|
||||||
|
message CanMergeResponse {
|
||||||
|
bool can_merge_without_conflicts = 1;
|
||||||
|
optional bytes merged_tree_sha = 2;
|
||||||
|
repeated string conflicted_paths = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ChangeKind (var: _)
|
||||||
|
enum ChangeKind {
|
||||||
|
CHANGE_KIND_UNSPECIFIED = 0;
|
||||||
|
CHANGE_KIND_ADDED = 1;
|
||||||
|
CHANGE_KIND_DELETED = 2;
|
||||||
|
CHANGE_KIND_MODIFIED = 3;
|
||||||
|
CHANGE_KIND_RENAMED = 4;
|
||||||
|
CHANGE_KIND_COPIED = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ChangedFile (var: Nn)
|
||||||
|
message ChangedFile {
|
||||||
|
string path = 1;
|
||||||
|
optional string old_path = 2;
|
||||||
|
ChangeKind change_kind = 3;
|
||||||
|
optional FileMode old_mode = 4;
|
||||||
|
optional FileMode new_mode = 5;
|
||||||
|
optional string old_sha = 6;
|
||||||
|
optional string new_sha = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ChangedFileWithStats (var: Pn)
|
||||||
|
message ChangedFileWithStats {
|
||||||
|
string path = 1;
|
||||||
|
optional string old_path = 2;
|
||||||
|
ChangeKind change_kind = 3;
|
||||||
|
bool is_binary = 4;
|
||||||
|
int32 additions = 5;
|
||||||
|
int32 deletions = 6;
|
||||||
|
optional FileMode old_mode = 7;
|
||||||
|
optional FileMode new_mode = 8;
|
||||||
|
optional string old_sha = 9;
|
||||||
|
optional string new_sha = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.Commit (var: bt)
|
||||||
|
message Commit {
|
||||||
|
string sha = 1;
|
||||||
|
string message = 2;
|
||||||
|
Signature author = 3;
|
||||||
|
Signature committer = 4;
|
||||||
|
repeated string parent_shas = 5;
|
||||||
|
string tree_sha = 7;
|
||||||
|
optional string change_id = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CommitDiffChunk (var: Jn)
|
||||||
|
message CommitDiffChunk {
|
||||||
|
optional CommitDiffHeader header = 1;
|
||||||
|
repeated FileDiff file_diffs = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CommitDiffHeader (var: Bn)
|
||||||
|
message CommitDiffHeader {
|
||||||
|
Commit commit = 1;
|
||||||
|
optional string base_commit_sha = 2;
|
||||||
|
CommitDiffStats stats = 3;
|
||||||
|
repeated ChangedFileWithStats changed_files = 4;
|
||||||
|
bool has_more = 5;
|
||||||
|
optional string next_page_cursor = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CommitDiffStats (var: Rn)
|
||||||
|
message CommitDiffStats {
|
||||||
|
uint32 files_changed = 1;
|
||||||
|
int32 additions = 2;
|
||||||
|
int32 deletions = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CommitFileDelete (var: Ct)
|
||||||
|
message CommitFileDelete {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CommitFileMode (var: g)
|
||||||
|
enum CommitFileMode {
|
||||||
|
COMMIT_FILE_MODE_UNSPECIFIED = 0;
|
||||||
|
COMMIT_FILE_MODE_REGULAR = 1;
|
||||||
|
COMMIT_FILE_MODE_EXECUTABLE = 2;
|
||||||
|
COMMIT_FILE_MODE_SYMLINK = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CommitFileOperation (var: Nt)
|
||||||
|
message CommitFileOperation {
|
||||||
|
string path = 1;
|
||||||
|
oneof operation {
|
||||||
|
CommitFileUpsert upsert = 2;
|
||||||
|
CommitFileDelete delete = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CommitFileUpsert (var: Jt)
|
||||||
|
message CommitFileUpsert {
|
||||||
|
bytes content = 1;
|
||||||
|
CommitFileMode mode = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CompareCommitsRequest (var: dt)
|
||||||
|
message CompareCommitsRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string base_revision = 2;
|
||||||
|
string head_revision = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CompareCommitsResponse (var: pt)
|
||||||
|
message CompareCommitsResponse {
|
||||||
|
CompareCommitsStatus status = 1;
|
||||||
|
int32 ahead_by = 2;
|
||||||
|
int32 behind_by = 3;
|
||||||
|
string base_commit_sha = 4;
|
||||||
|
string head_commit_sha = 5;
|
||||||
|
string merge_base_commit_sha = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CompareCommitsStatus (var: p)
|
||||||
|
enum CompareCommitsStatus {
|
||||||
|
COMPARE_COMMITS_STATUS_UNSPECIFIED = 0;
|
||||||
|
COMPARE_COMMITS_STATUS_IDENTICAL = 1;
|
||||||
|
COMPARE_COMMITS_STATUS_AHEAD = 2;
|
||||||
|
COMPARE_COMMITS_STATUS_BEHIND = 3;
|
||||||
|
COMPARE_COMMITS_STATUS_DIVERGED = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ComputeMergeCommitRequest (var: _t)
|
||||||
|
message ComputeMergeCommitRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string ours_sha = 2;
|
||||||
|
string theirs_sha = 3;
|
||||||
|
string message = 4;
|
||||||
|
Signature author = 5;
|
||||||
|
Signature committer = 6;
|
||||||
|
MergeMode mode = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ComputeMergeCommitResponse (var: Tt)
|
||||||
|
message ComputeMergeCommitResponse {
|
||||||
|
string merge_commit_sha = 1;
|
||||||
|
bytes packfile = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CreateCommitFromFilesRequest (var: Rt)
|
||||||
|
message CreateCommitFromFilesRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string target_ref = 2;
|
||||||
|
optional string expected_head_sha = 3;
|
||||||
|
string message = 4;
|
||||||
|
Signature author = 5;
|
||||||
|
optional Signature committer = 6;
|
||||||
|
repeated CommitFileOperation files = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CreateCommitFromFilesResponse (var: Pt)
|
||||||
|
message CreateCommitFromFilesResponse {
|
||||||
|
string commit_sha = 1;
|
||||||
|
string tree_sha = 2;
|
||||||
|
string old_head_sha = 3;
|
||||||
|
string wal_entry_key = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CreateMergeCommitRequest (var: ht)
|
||||||
|
message CreateMergeCommitRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
optional string ours_sha = 2;
|
||||||
|
optional string theirs_sha = 3;
|
||||||
|
string ours_ref = 4;
|
||||||
|
string theirs_ref = 5;
|
||||||
|
string message = 6;
|
||||||
|
Signature author = 7;
|
||||||
|
Signature committer = 8;
|
||||||
|
uint64 change_number = 9;
|
||||||
|
MergeMode mode = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CreateMergeCommitResponse (var: At)
|
||||||
|
message CreateMergeCommitResponse {
|
||||||
|
string merge_commit_sha = 1;
|
||||||
|
string wal_entry_key = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CreateRepoRequest (var: wn)
|
||||||
|
message CreateRepoRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.CreateRepoResponse (var: En)
|
||||||
|
message CreateRepoResponse {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.DiffHeader (var: Cn)
|
||||||
|
message DiffHeader {
|
||||||
|
string merge_base_commit_sha = 1;
|
||||||
|
repeated ChangedFile files = 2;
|
||||||
|
repeated ChangedFileWithStats files_with_stats = 3;
|
||||||
|
bool has_more = 4;
|
||||||
|
optional string next_page_cursor = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.DirectoryContent (var: qt)
|
||||||
|
message DirectoryContent {
|
||||||
|
repeated RepoContentEntry entries = 1;
|
||||||
|
string sha = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.FastForwardRefRequest (var: qn)
|
||||||
|
message FastForwardRefRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string target_ref = 2;
|
||||||
|
string expected_head_sha = 3;
|
||||||
|
string new_head_sha = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.FastForwardRefResponse (var: Dn)
|
||||||
|
message FastForwardRefResponse {
|
||||||
|
string old_head_sha = 1;
|
||||||
|
string new_head_sha = 2;
|
||||||
|
string wal_entry_key = 3;
|
||||||
|
bool unchanged = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.FileContent (var: Ft)
|
||||||
|
message FileContent {
|
||||||
|
string size = 1;
|
||||||
|
string encoding = 2;
|
||||||
|
string content = 3;
|
||||||
|
string sha = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.FileDiff (var: bn)
|
||||||
|
message FileDiff {
|
||||||
|
string path = 1;
|
||||||
|
optional string old_path = 2;
|
||||||
|
bool is_binary = 3;
|
||||||
|
string patch = 4;
|
||||||
|
int32 additions = 5;
|
||||||
|
int32 deletions = 6;
|
||||||
|
optional FileMode old_mode = 7;
|
||||||
|
optional FileMode new_mode = 8;
|
||||||
|
optional string old_sha = 9;
|
||||||
|
optional string new_sha = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.FileHistoryCommitEntry (var: Zt)
|
||||||
|
message FileHistoryCommitEntry {
|
||||||
|
ShortCommit commit = 1;
|
||||||
|
optional string diff_base_commit_sha = 2;
|
||||||
|
optional FileHistoryPathStats path_stats = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.FileHistoryPathStats (var: Xt)
|
||||||
|
message FileHistoryPathStats {
|
||||||
|
int32 additions = 1;
|
||||||
|
int32 deletions = 2;
|
||||||
|
bool is_binary = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.FileHistoryWithDiffStatsChunk (var: en)
|
||||||
|
message FileHistoryWithDiffStatsChunk {
|
||||||
|
repeated FileHistoryCommitEntry entries = 1;
|
||||||
|
bool exhausted = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.FileMode (var: A)
|
||||||
|
enum FileMode {
|
||||||
|
FILE_MODE_UNSPECIFIED = 0;
|
||||||
|
FILE_MODE_REGULAR = 1;
|
||||||
|
FILE_MODE_EXECUTABLE = 2;
|
||||||
|
FILE_MODE_SYMLINK = 3;
|
||||||
|
FILE_MODE_GITLINK = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetBlameRequest (var: nn)
|
||||||
|
message GetBlameRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string start_commit_sha = 2;
|
||||||
|
string path = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetBlobRequest (var: $e)
|
||||||
|
message GetBlobRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string blob_sha = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetBlobResponse (var: et)
|
||||||
|
message GetBlobResponse {
|
||||||
|
FileContent blob = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetCommitDiffRequest (var: vn)
|
||||||
|
message GetCommitDiffRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string commit_sha = 2;
|
||||||
|
optional string base_commit_sha = 3;
|
||||||
|
bool include_patches = 4;
|
||||||
|
repeated string paths = 5;
|
||||||
|
optional uint32 page_size = 6;
|
||||||
|
optional string page_cursor = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetCommitRequest (var: Xe)
|
||||||
|
message GetCommitRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string commit_sha = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetCommitResponse (var: Ze)
|
||||||
|
message GetCommitResponse {
|
||||||
|
Commit commit = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetFileHistoryPageWithDiffStatsResponse (var: tn)
|
||||||
|
message GetFileHistoryPageWithDiffStatsResponse {
|
||||||
|
repeated FileHistoryCommitEntry entries = 1;
|
||||||
|
bool has_more = 2;
|
||||||
|
optional string next_cursor = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetFileHistoryRequest (var: Wt)
|
||||||
|
message GetFileHistoryRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string start_commit_sha = 2;
|
||||||
|
optional string path = 3;
|
||||||
|
uint32 max_commits = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetFileHistoryResponse (var: zt)
|
||||||
|
message GetFileHistoryResponse {
|
||||||
|
repeated ShortCommit commits = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetFileHistoryWithDiffStatsRequest (var: jt)
|
||||||
|
message GetFileHistoryWithDiffStatsRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string start_commit_sha = 2;
|
||||||
|
optional string path = 3;
|
||||||
|
uint32 max_commits = 4;
|
||||||
|
optional string next_cursor = 5;
|
||||||
|
bool include_diff_stats = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetFileHistoryWithDiffStatsResponse (var: $t)
|
||||||
|
message GetFileHistoryWithDiffStatsResponse {
|
||||||
|
repeated FileHistoryCommitEntry entries = 1;
|
||||||
|
bool has_more = 2;
|
||||||
|
optional string next_cursor = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetFuzzyPathsRequest (var: un)
|
||||||
|
message GetFuzzyPathsRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string commit_sha = 2;
|
||||||
|
string query = 3;
|
||||||
|
uint32 limit = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetFuzzyPathsResponse (var: mn)
|
||||||
|
message GetFuzzyPathsResponse {
|
||||||
|
repeated string paths = 1;
|
||||||
|
bool has_more = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetLocalDevInfoRequest (var: ze)
|
||||||
|
message GetLocalDevInfoRequest {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetLocalDevInfoResponse (var: je)
|
||||||
|
message GetLocalDevInfoResponse {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string git_forge_root_dir = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetPullRequestDiffRequest (var: Sn)
|
||||||
|
message GetPullRequestDiffRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string head_commit_sha = 2;
|
||||||
|
string base_commit_sha = 3;
|
||||||
|
optional bool include_patches = 4;
|
||||||
|
optional uint32 page_size = 5;
|
||||||
|
optional string page_cursor = 6;
|
||||||
|
optional bool include_file_stats = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetRepoContentDetailsRequest (var: Yt)
|
||||||
|
message GetRepoContentDetailsRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
PathIdentifier path_identifier = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetRepoContentDetailsResponse (var: Kt)
|
||||||
|
message GetRepoContentDetailsResponse {
|
||||||
|
optional RepoContentDetails details = 1;
|
||||||
|
PathIdentifier path_identifier = 2;
|
||||||
|
string resolved_commit_sha = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetRepoContentRequest (var: Ut)
|
||||||
|
message GetRepoContentRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
oneof id {
|
||||||
|
PathIdentifier path_identifier = 2;
|
||||||
|
string ref_and_path = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetRepoContentResponse (var: xt)
|
||||||
|
message GetRepoContentResponse {
|
||||||
|
PathIdentifier path_identifier = 3;
|
||||||
|
string resolved_commit_sha = 4;
|
||||||
|
oneof content {
|
||||||
|
FileContent file_content = 1;
|
||||||
|
DirectoryContent directory_content = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetTagRequest (var: tt)
|
||||||
|
message GetTagRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string tag_sha = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetTagResponse (var: nt)
|
||||||
|
message GetTagResponse {
|
||||||
|
Tag tag = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetTreeBlameRequest (var: on)
|
||||||
|
message GetTreeBlameRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string start_commit_sha = 2;
|
||||||
|
string path = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetTreeBlameResponse (var: ln)
|
||||||
|
message GetTreeBlameResponse {
|
||||||
|
repeated TreeEntryBlame entries = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetTreeRequest (var: rt)
|
||||||
|
message GetTreeRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string tree_sha = 2;
|
||||||
|
bool recursive = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GetTreeResponse (var: st)
|
||||||
|
message GetTreeResponse {
|
||||||
|
Tree tree = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GrepLineKind (var: h)
|
||||||
|
enum GrepLineKind {
|
||||||
|
GREP_LINE_KIND_UNSPECIFIED = 0;
|
||||||
|
GREP_LINE_KIND_MATCH = 1;
|
||||||
|
GREP_LINE_KIND_CONTEXT = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GrepMatch (var: hn)
|
||||||
|
message GrepMatch {
|
||||||
|
string path = 1;
|
||||||
|
string lines = 2;
|
||||||
|
uint32 line_number = 3;
|
||||||
|
uint64 absolute_offset = 4;
|
||||||
|
repeated GrepSubmatch submatches = 5;
|
||||||
|
GrepLineKind kind = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GrepRepoChunk (var: An)
|
||||||
|
message GrepRepoChunk {
|
||||||
|
repeated GrepMatch matches = 1;
|
||||||
|
bool limit_hit = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GrepRepoRequest (var: fn)
|
||||||
|
message GrepRepoRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string revision = 2;
|
||||||
|
string query = 3;
|
||||||
|
GrepSearchOptions options = 4;
|
||||||
|
uint32 max_results = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GrepSearchOptions (var: pn)
|
||||||
|
message GrepSearchOptions {
|
||||||
|
bool literal = 1;
|
||||||
|
bool case_insensitive = 2;
|
||||||
|
bool whole_word = 3;
|
||||||
|
uint32 context_before = 4;
|
||||||
|
uint32 context_after = 5;
|
||||||
|
optional uint64 max_lines = 6;
|
||||||
|
optional string filter_path = 7;
|
||||||
|
repeated string includes = 8;
|
||||||
|
repeated string excludes = 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.GrepSubmatch (var: gn)
|
||||||
|
message GrepSubmatch {
|
||||||
|
uint32 start = 1;
|
||||||
|
uint32 end = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListCommitsInRangeRequest (var: mt)
|
||||||
|
message ListCommitsInRangeRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string base_revision = 2;
|
||||||
|
string head_revision = 3;
|
||||||
|
optional int32 max_commits = 4;
|
||||||
|
bool oldest_first = 5;
|
||||||
|
ListCommitsSort sort = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListCommitsInRangeResponse (var: ct)
|
||||||
|
message ListCommitsInRangeResponse {
|
||||||
|
repeated Commit commits = 1;
|
||||||
|
string base_commit_sha = 2;
|
||||||
|
string head_commit_sha = 3;
|
||||||
|
string merge_base_commit_sha = 4;
|
||||||
|
bool truncated = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListCommitsRequest (var: lt)
|
||||||
|
message ListCommitsRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string revision = 2;
|
||||||
|
int32 page = 3;
|
||||||
|
int32 per_page = 4;
|
||||||
|
ListCommitsSort sort = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListCommitsResponse (var: ut)
|
||||||
|
message ListCommitsResponse {
|
||||||
|
repeated Commit commits = 1;
|
||||||
|
optional int32 next_page = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListCommitsSort (var: y)
|
||||||
|
enum ListCommitsSort {
|
||||||
|
LIST_COMMITS_SORT_UNSPECIFIED = 0;
|
||||||
|
LIST_COMMITS_SORT_COMMIT_TIME = 1;
|
||||||
|
LIST_COMMITS_SORT_TOPOLOGICAL = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListRefsFilter (var: T)
|
||||||
|
enum ListRefsFilter {
|
||||||
|
LIST_REFS_FILTER_UNSPECIFIED = 0;
|
||||||
|
LIST_REFS_FILTER_ALL = 1;
|
||||||
|
LIST_REFS_FILTER_BRANCHES = 2;
|
||||||
|
LIST_REFS_FILTER_TAGS = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListRefsRequest (var: Mn)
|
||||||
|
message ListRefsRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
ListRefsFilter filter = 2;
|
||||||
|
bool names_only = 3;
|
||||||
|
string prefix = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListRefsResponse (var: Fn)
|
||||||
|
message ListRefsResponse {
|
||||||
|
repeated string refs = 1;
|
||||||
|
repeated RefInfo ref_infos = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListTreePathsRequest (var: cn)
|
||||||
|
message ListTreePathsRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string revision = 2;
|
||||||
|
repeated string includes = 3;
|
||||||
|
repeated string excludes = 4;
|
||||||
|
uint32 limit = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ListTreePathsResponse (var: dn)
|
||||||
|
message ListTreePathsResponse {
|
||||||
|
repeated string paths = 1;
|
||||||
|
bool has_more = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.MergeMode (var: f)
|
||||||
|
enum MergeMode {
|
||||||
|
MERGE_MODE_UNSPECIFIED = 0;
|
||||||
|
MERGE_MODE_MERGE_COMMIT = 1;
|
||||||
|
MERGE_MODE_SQUASH = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.NotifyRepoPushedRequest (var: _n)
|
||||||
|
message NotifyRepoPushedRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.NotifyRepoPushedResponse (var: Tn)
|
||||||
|
message NotifyRepoPushedResponse {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.PathIdentifier (var: Lt)
|
||||||
|
message PathIdentifier {
|
||||||
|
string revision = 1;
|
||||||
|
string path = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.PrepareChangeMergeRequest (var: yt)
|
||||||
|
message PrepareChangeMergeRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string base_ref = 2;
|
||||||
|
string head_ref = 3;
|
||||||
|
uint64 change_number = 4;
|
||||||
|
optional string expected_base_sha = 5;
|
||||||
|
optional string expected_head_sha = 6;
|
||||||
|
MergeMode mode = 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.PrepareChangeMergeResponse (var: kt)
|
||||||
|
message PrepareChangeMergeResponse {
|
||||||
|
bool mergeable = 1;
|
||||||
|
optional string merged_tree_sha = 2;
|
||||||
|
optional string change_merge_ref = 3;
|
||||||
|
optional string dummy_commit_sha = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.PullRequestDiffChunk (var: In)
|
||||||
|
message PullRequestDiffChunk {
|
||||||
|
optional DiffHeader header = 1;
|
||||||
|
repeated FileDiff file_diffs = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RebaseStackBranch (var: Et)
|
||||||
|
message RebaseStackBranch {
|
||||||
|
string head_ref = 1;
|
||||||
|
string expected_old_oid = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RebaseStackBranchUpdate (var: vt)
|
||||||
|
message RebaseStackBranchUpdate {
|
||||||
|
string head_ref = 1;
|
||||||
|
string old_oid = 2;
|
||||||
|
string new_oid = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RebaseStackConflict (var: Bt)
|
||||||
|
message RebaseStackConflict {
|
||||||
|
string conflicted_head_ref = 1;
|
||||||
|
repeated string conflicted_paths = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RebaseStackRequest (var: wt)
|
||||||
|
message RebaseStackRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string onto_ref = 2;
|
||||||
|
optional string expected_onto_oid = 3;
|
||||||
|
repeated RebaseStackBranch branches = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RebaseStackResponse (var: St)
|
||||||
|
message RebaseStackResponse {
|
||||||
|
oneof result {
|
||||||
|
RebaseStackSuccess success = 1;
|
||||||
|
RebaseStackConflict conflict = 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RebaseStackSuccess (var: It)
|
||||||
|
message RebaseStackSuccess {
|
||||||
|
string wal_entry_key = 1;
|
||||||
|
repeated RebaseStackBranchUpdate updates = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RefInfo (var: Ln)
|
||||||
|
message RefInfo {
|
||||||
|
string name = 1;
|
||||||
|
string target_sha = 2;
|
||||||
|
string object_sha = 3;
|
||||||
|
string object_type = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RepoContentDetails (var: Vt)
|
||||||
|
message RepoContentDetails {
|
||||||
|
string type = 1;
|
||||||
|
optional uint64 size = 2;
|
||||||
|
bool is_binary = 3;
|
||||||
|
bool too_large_to_introspect = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.RepoContentEntry (var: kn)
|
||||||
|
message RepoContentEntry {
|
||||||
|
string type = 1;
|
||||||
|
string name = 2;
|
||||||
|
string path = 3;
|
||||||
|
string sha = 4;
|
||||||
|
optional uint64 size = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ResolveRefPathRequest (var: Dt)
|
||||||
|
message ResolveRefPathRequest {
|
||||||
|
string repo_uuid = 1;
|
||||||
|
string ref_path = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ResolveRefPathResponse (var: Ot)
|
||||||
|
message ResolveRefPathResponse {
|
||||||
|
PathIdentifier path_identifier = 1;
|
||||||
|
string resolved_commit_sha = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.ShortCommit (var: yn)
|
||||||
|
message ShortCommit {
|
||||||
|
bytes sha = 1;
|
||||||
|
string summary = 2;
|
||||||
|
string author_name = 3;
|
||||||
|
string author_email = 4;
|
||||||
|
int64 timestamp = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.Signature (var: Mt)
|
||||||
|
message Signature {
|
||||||
|
string name = 1;
|
||||||
|
string email = 2;
|
||||||
|
int64 timestamp = 3;
|
||||||
|
int32 timezone_offset = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.Tag (var: at)
|
||||||
|
message Tag {
|
||||||
|
string sha = 1;
|
||||||
|
string name = 2;
|
||||||
|
string message = 3;
|
||||||
|
Signature tagger = 4;
|
||||||
|
string object_sha = 5;
|
||||||
|
string object_type = 6;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.Tree (var: ot)
|
||||||
|
message Tree {
|
||||||
|
string sha = 1;
|
||||||
|
repeated TreeEntry tree = 2;
|
||||||
|
bool truncated = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.TreeEntry (var: it)
|
||||||
|
message TreeEntry {
|
||||||
|
string path = 1;
|
||||||
|
string mode = 2;
|
||||||
|
string type = 3;
|
||||||
|
string sha = 4;
|
||||||
|
optional uint64 size = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copied from: local:git_forge.v1.TreeEntryBlame (var: an)
|
||||||
|
message TreeEntryBlame {
|
||||||
|
string name = 1;
|
||||||
|
ShortCommit last_commit = 2;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -4,7 +4,7 @@ package internapi.v1;
|
|||||||
|
|
||||||
option go_package = "react-admin/cursor-server/gen/internapi/v1;internapiv1";
|
option go_package = "react-admin/cursor-server/gen/internapi/v1;internapiv1";
|
||||||
|
|
||||||
// Copied from: local:internapi.v1.BlobData (var: hxe)
|
// Copied from: local:internapi.v1.BlobData (var: Mn)
|
||||||
message BlobData {
|
message BlobData {
|
||||||
BlobType blob_type = 1;
|
BlobType blob_type = 1;
|
||||||
bytes blob_id = 2;
|
bytes blob_id = 2;
|
||||||
@@ -14,12 +14,12 @@ message BlobData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from: local:internapi.v1.BlobDataPerMessage (var: Txe)
|
// Copied from: local:internapi.v1.BlobDataPerMessage (var: Ln)
|
||||||
message BlobDataPerMessage {
|
message BlobDataPerMessage {
|
||||||
repeated BlobData blob_data = 1;
|
repeated BlobData blob_data = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from: local:internapi.v1.BlobType (var: Axe)
|
// Copied from: local:internapi.v1.BlobType (var: Nn)
|
||||||
enum BlobType {
|
enum BlobType {
|
||||||
BLOB_TYPE_UNSPECIFIED = 0;
|
BLOB_TYPE_UNSPECIFIED = 0;
|
||||||
BLOB_TYPE_IMAGE = 1;
|
BLOB_TYPE_IMAGE = 1;
|
||||||
@@ -34,7 +34,7 @@ enum BlobType {
|
|||||||
BLOB_TYPE_VIDEO = 10;
|
BLOB_TYPE_VIDEO = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copied from: local:internapi.v1.ImageBlobData (var: pxe)
|
// Copied from: local:internapi.v1.ImageBlobData (var: bn)
|
||||||
message ImageBlobData {
|
message ImageBlobData {
|
||||||
string mime_type = 1;
|
string mime_type = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
+1
-7
@@ -8,11 +8,5 @@ QQ交流群:
|
|||||||
Tg群组:
|
Tg群组:
|
||||||
https://t.me/cursor_byok
|
https://t.me/cursor_byok
|
||||||
|
|
||||||
- 修复commands无法识别的问题 @DedSecer
|
- 支持cursor-cli
|
||||||
- 修复 summarize 指令(主动压缩) @DedSecer
|
|
||||||
- 修复 MiniMax 禁止 thinking 的问题 @Octopus
|
|
||||||
- 支持Fork message (需要新开对话) @DedSecer
|
|
||||||
- 支持 @关联对话 @DedSecer
|
|
||||||
- 支持插件市场(须登录你的任意账号) @aike1202
|
|
||||||
- 新增支持 cursor debugger 调试器, 用法请看.agents/skills/coding-guidance/SKILL.md
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user