README
🚀 hindsight-mcp
hindsight-mcp 是一个用于人工智能辅助编码的 MCP 服务器,它利用开发历史数据来提供支持。该项目将开发数据(如 git 日志、测试结果和 GitHub Copilot 会话)整合到一个可搜索的 SQLite 数据库中,通过 VS Code 中的 MCP 工具调用,让 AI 助手能够访问这些数据。
🚀 快速开始
前提条件
- 安装了 GitHub Copilot 的 VS Code v1.99+
- cargo-nextest(用于测试数据摄入),可使用以下命令安装:
cargo install cargo-nextest
安装
使用以下命令安装 hindsight-mcp:
cargo install hindsight-mcp
配置 VS Code
在项目中创建 .vscode/mcp.json 文件,内容如下:
{
"servers": {
"hindsight": {
"type": "stdio",
"command": "hindsight-mcp",
"args": ["--workspace", "${workspaceFolder}"]
}
}
}
验证设置
- 打开 VS Code 命令面板(
Cmd+Shift+P) - 运行 "MCP: List Servers"
- 确认
hindsight已列出 - 在 Copilot Chat 中,切换到 Agent 模式
- 询问:"What have I been working on recently?"
完成以上步骤后,Copilot 就可以使用 hindsight 工具来回答关于开发历史的问题。
✨ 主要特性
- 对提交记录和 Copilot 对话进行全文搜索
- 跟踪与特定提交相关的测试结果
- 提供活动摘要和时间线视图
- 自动摄入 git 和 Copilot 会话数据
📦 安装指南
前提条件
- 安装了 GitHub Copilot 的 VS Code v1.99+
- cargo-nextest(用于测试数据摄入),可使用以下命令安装:
cargo install cargo-nextest
安装命令
cargo install hindsight-mcp
配置 VS Code
在项目中创建 .vscode/mcp.json 文件,内容如下:
{
"servers": {
"hindsight": {
"type": "stdio",
"command": "hindsight-mcp",
"args": ["--workspace", "${workspaceFolder}"]
}
}
}
💻 使用示例
基础用法
在 Copilot Chat 中,切换到 Agent 模式后,你可以询问一些问题,例如:
"What have I been working on recently?"
高级用法
你可以使用不同的 MCP 工具来完成特定的任务,例如:
"Show recent commits and test runs" # 使用 hindsight_timeline 工具
"Find commits about authentication" # 使用 hindsight_search 工具
📚 详细文档
MCP 工具
| 工具 | 用途 | 示例提示 |
|------|---------|----------------|
| hindsight_timeline | 按时间顺序查看活动 | "Show recent commits and test runs" |
| hindsight_search | 全文搜索 | "Find commits about authentication" |
| hindsight_failing_tests | 查询测试失败情况 | "What tests are failing?" |
| hindsight_activity_summary | 汇总统计信息 | "Summarise my week" |
| hindsight_commit_details | 获取提交详细信息及相关测试 | "Details for commit abc123" |
| hindsight_ingest | 触发数据刷新 | "Refresh development history" |
工具参数参考
hindsight_timeline
limit(int): 最大事件数,默认 50workspace(string): 按路径过滤
hindsight_search
query(string): 搜索查询(必需)source(string): "all", "commits", 或 "messages"limit(int): 最大结果数,默认 20
hindsight_failing_tests
limit(int): 最大测试数,默认 50workspace(string): 按路径过滤commit(string): 按 SHA 过滤
hindsight_activity_summary
days(int): 汇总天数,默认 7
hindsight_commit_details
sha(string): 提交 SHA(必需)
hindsight_ingest
workspace(string): 要摄入的路径(必需)source(string): "git", "copilot", 或 "all"incremental(bool): 仅摄入新数据,默认 truelimit(int): 最大项数
测试数据摄入
运行测试并自动摄入结果:
# 运行所有测试并摄入
hindsight-mcp test
# 测试特定包
hindsight-mcp test -p my-crate
# 预览而不写入数据库
hindsight-mcp test --dry-run
test 命令会自动执行以下操作:
- 使用正确的标志启动
cargo nextest - 自动检测当前的 git 提交
- 将结果摄入到数据库中
CI / 高级用法
对于 CI 管道或自定义 nextest 调用:
# 使用 stdin 模式
NEXTEST_EXPERIMENTAL_LIBTEST_JSON=1 cargo nextest run \
--message-format libtest-json 2>/dev/null | \
hindsight-mcp test --stdin
# 使用 ingest 命令并指定提交
NEXTEST_EXPERIMENTAL_LIBTEST_JSON=1 cargo nextest run \
--message-format libtest-json 2>/dev/null | \
hindsight-mcp ingest --tests --commit $(git rev-parse HEAD)
数据源
| 数据源 | 收集的数据 | |--------|----------------| | Git | 提交记录(SHA、作者、消息、时间戳、父提交) | | 测试 | 运行元数据、结果、持续时间、失败输出 | | Copilot | 聊天会话、提示、响应、附加文件 |
Git 和 Copilot 数据会自动摄入,测试结果需要运行 hindsight-mcp test 命令。
CLI 参考
hindsight-mcp [OPTIONS] [COMMAND]
Commands:
ingest 从各种数据源摄入数据
test 运行测试并摄入结果
Options:
-d, --database <PATH> 数据库路径 [默认: ~/.hindsight/hindsight.db]
-w, --workspace <PATH> 工作区路径 [默认: 当前目录]
-v, --verbose 调试日志
-q, --quiet 仅显示错误信息
--skip-init 跳过数据库初始化
-h, --help 显示帮助信息
-V, --version 显示版本信息
测试子命令选项
hindsight-mcp test [OPTIONS] [-- <NEXTEST_ARGS>...]
Options:
-p, --package <PKG> 要测试的包
--bin <BIN> 要运行的二进制文件
-E, --filter <EXPR> 过滤表达式
--stdin 从标准输入读取
--dry-run 仅预览
--no-commit 不关联提交
--commit <SHA> 显式指定提交 SHA
--show-output 显示测试输出
环境变量
| 变量 | 描述 |
|----------|-------------|
| HINDSIGHT_DATABASE | 数据库路径 |
| HINDSIGHT_WORKSPACE | 默认工作区 |
数据库位置
| 平台 | 默认路径 |
|----------|--------------|
| macOS | ~/Library/Application Support/hindsight/hindsight.db |
| Linux | ~/.local/share/hindsight/hindsight.db |
| Windows | %LOCALAPPDATA%\hindsight\hindsight.db |
🔧 技术细节
hindsight-mcp 项目将开发数据(git 日志、测试结果和 GitHub Copilot 会话)整合到一个可搜索的 SQLite 数据库中。通过 VS Code 中的 MCP 工具调用,AI 助手可以访问这些数据。项目的主要模块包括:
hindsight-mcp:MCP 服务器二进制文件hindsight-git:处理 git 日志hindsight-tests:处理测试结果hindsight-copilot:解析 Copilot 会话
📄 许可证
本项目采用 MIT 许可证。
Scan to join WeChat group