{"id":50774779,"url":"https://github.com/welllog/llm_tracer","last_synced_at":"2026-06-11T22:30:30.423Z","repository":{"id":363960571,"uuid":"1263821691","full_name":"welllog/llm_tracer","owner":"welllog","description":null,"archived":false,"fork":false,"pushed_at":"2026-06-11T03:51:41.000Z","size":1461,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-11T05:21:20.091Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/welllog.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-06-09T09:47:43.000Z","updated_at":"2026-06-11T03:51:45.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/welllog/llm_tracer","commit_stats":null,"previous_names":["welllog/llm_tracer"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/welllog/llm_tracer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welllog%2Fllm_tracer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welllog%2Fllm_tracer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welllog%2Fllm_tracer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welllog%2Fllm_tracer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/welllog","download_url":"https://codeload.github.com/welllog/llm_tracer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/welllog%2Fllm_tracer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34221150,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-11T22:30:29.174Z","updated_at":"2026-06-11T22:30:30.418Z","avatar_url":"https://github.com/welllog.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LLM Tracer 🚀\n\n`LLM Tracer` 是一个轻量级、跨平台的本地大模型代理拦截与对话追踪记录工具。它能无感地拦截发往 OpenAI、Anthropic 等主流服务商的 API 请求（包括普通接口与流式 SSE 响应），将请求流、思维链（Thinking Process）及 Token 消耗等数据持久化到本地 SQLite 数据库中，并通过内置的极美暗黑风 Web 控制台进行可视化分析与级联调试。\n\n---\n\n## 🌟 核心特性\n\n- **轻量单二进制部署**：前端 React 构建产物被完全嵌入 Go 二进制中，双击即可直接运行，包体积仅约 15MB。\n- **系统托盘常驻 (Desktop Native)**：程序常驻系统托盘，提供一键打开控制台、重启代理及优雅退出等功能，启动时自动拉起浏览器展示控制台。\n- **配置与数据库隐藏化 (`~/.llm_tracer`)**：所有配置文件（`config.json`）与本地 SQLite 数据库（`llm_tracer.db`）统一重定向至系统家目录的隐藏文件夹中，权限稳健、便于维护。\n- **端口冲突自探测与Fallback**：动态探测代理接口（默认 `:1238`）与控制台接口（默认 `:56129`），若端口被占用则自动后移分配空闲端口，支持实例多开不冲突。\n- **多路 Subagent 级联追踪**：支持追踪复杂的 Agent 级联调用（如子代理的多路并发请求），根据上下文指纹和语义匹配，将子请求完美归档至主干会话中。\n- **内置一键配置指南**：控制台配置面板内置 Python/Node.js/环境变量 等多语言客户端接入指引，支持一键复制代码段。\n\n---\n\n## 📂 项目结构\n\n```text\nllm_tracer/\n├── main.go            # 代理转发服务、SSE解析流扫描、系统托盘管理与 Web 控制台托管\n├── parser.go          # OpenAI / Responses / Anthropic 协议解析与会话指纹提取\n├── db.go              # SQLite 数据库读写、归并统计与级联关系恢复\n├── main_test.go       # 离线集成测试与级联回归测试用例\n├── Makefile           # 一键编译、构建与运行指令集合\n├── pack_mac.sh        # 一键打包 macOS 桌面端应用包 (.app) 自动化脚本\n├── logo.png           # 专为此工具生成的 App 高清原画图标（用于 macOS 打包）\n├── static/            # 前端 React 打包的静态资源目录（Go embed 静态载入）\n└── frontend/          # React + Vite + TailwindCSS 独立前端控制台源码\n```\n\n---\n\n## 🛠️ 构建与运行\n\n### 准备工作\n确保本地已安装：\n- **Go** (1.20 或更高版本，建议 1.26+)\n- **Node.js \u0026 npm** (用于前端 React 编译)\n\n### 1. 一键构建前端与后端\n在项目根目录下，直接运行以下命令：\n```bash\nmake build\n```\n这会依次执行：\n1. `npm run build` (将前端产物编译至 `static/` 目录)\n2. `go build` (编译生成 `llm_tracer_web` 单二进制文件)\n\n### 2. 运行代理服务\n```bash\n./llm_tracer_web\n```\n启动后：\n- 默认代理服务将监听在 `http://localhost:1238`。\n- 默认控制台服务将监听在 `http://localhost:56129`，并会自动在默认浏览器中拉起控制台。\n- 常驻系统托盘将出现在系统顶部菜单栏（macOS）或右下角任务栏（Windows/Linux）。\n\n\u003e [!NOTE]\n\u003e 如果您想自定义端口，可以通过命令行参数覆盖：\n\u003e `./llm_tracer_web -listen :8080 -console :3000`\n\n### 3. 运行集成测试\n运行后端的回归测试：\n```bash\nmake test\n```\n\n### 4. macOS 原生桌面应用打包 (.app)\n如果您在 macOS 上运行，并希望获得完美的系统原生体验（**双击直接静默运行、不弹出终端命令框，且拥有独立的 Dock 及状态栏图标**），可运行项目内置的自动打包脚本：\n```bash\nchmod +x pack_mac.sh\n./pack_mac.sh\n```\n运行后，当前目录将自动生成 **`LLMTracer.app`** 原生应用程序包：\n- **高清视网膜图标**：打包脚本会自动读取根目录下的 `logo.png` 原画，利用 macOS 系统内置的 `sips` 与 `iconutil` 图像引擎无损制作符合 Mac 各种分辨率标准的 `icon.icns` 图标集，注入 App 的资源中。\n- **开箱即用运行**：双击生成的 `LLMTracer.app` 即可在后台静默运行（终端不弹窗），并自动在浏览器中唤起控制台。\n- **系统集成**：您可以将 `LLMTracer.app` 拖入系统的 `/Applications`（应用程序）目录，即可直接在 Launchpad（启动台）或 Spotlight 搜索中一键拉起。\n\n---\n\n## 🚀 客户端接入指引\n\n要通过该代理拦截和记录您的 LLM 请求，仅需将您开发库的 `baseURL` 重定向到本地代理即可（ApiKey 可以填写任意非空字符串）。\n\n### 方式一：设置系统环境变量 (推荐)\n最无感的配置方式，能够使所有默认读取环境变量的 SDK 自动生效：\n```bash\nexport OPENAI_BASE_URL=http://localhost:1238/v1\nexport ANTHROPIC_BASE_URL=http://localhost:1238/v1\n```\n\n### 方式二：Python (openai-python)\n```python\nimport openai\n\n# 将 base_url 指向 LLM Tracer 本地代理\nopenai.base_url = \"http://localhost:1238/v1\"\n# apiKey 可填任意非空字符串\nopenai.api_key = \"anything\"\n\nresponse = openai.chat.completions.create(\n    model=\"gpt-4o\",\n    messages=[{\"role\": \"user\", \"content\": \"你好，这是一次测试！\"}]\n)\nprint(response.choices[0].message.content)\n```\n\n### 方式三：Node.js / TypeScript\n```javascript\nimport OpenAI from 'openai';\n\nconst openai = new OpenAI({\n  baseURL: 'http://localhost:1238/v1',\n  apiKey: 'anything'\n});\n\nconst completion = await openai.chat.completions.create({\n  model: 'gpt-4o',\n  messages: [{ role: 'user', content: 'Hello!' }],\n});\n```\n\n---\n\n## ⚖️ 授权协议\n\n本项目采用 [MIT License](LICENSE) 开源。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwelllog%2Fllm_tracer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwelllog%2Fllm_tracer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwelllog%2Fllm_tracer/lists"}