事后诸葛亮
利用开发历史进行人工智能辅助编码的MCP服务器。
概述
事后诸葛亮 将开发数据(git日志、测试结果和GitHub Copilot会话)整合到一个可搜索的SQLite数据库中,使AI助手可以通过VS Code中的MCP工具调用访问它。
主要特点:
- 跨提交和复制对话的全文搜索
- 跟踪与特定提交相关的测试结果
- 活动摘要和时间线视图
- 自动接收git和Copilot会话
快速开始
先决条件
- VS代码v1.99+ 使用GitHub Copilot
- 下一个货物 (用于测试摄入):
cargo install cargo-nextest
安装
cargo install hindsight-mcp配置VS代码
创建 .vscode/mcp.json 在您的项目中:
{
"servers": {
"hindsight": {
"type": "stdio",
"command": "hindsight-mcp",
"args": ["--workspace", "${workspaceFolder}"]
}
}
}验证设置
- 打开VS代码命令面板(
Cmd+Shift+P) - 跑 “MCP:列出服务器”
- 确认
hindsight已列出 - 在Copilot聊天中,切换到 代理 模式
- 问: *“我最近在做什么?”*
就是这样!Copilot将使用后见之明工具来回答有关您的发展历史的问题。
MCP工具
| 工具 | 目的 | 示例提示 |
|---|---|---|
hindsight_timeline | 按时间顺序排列的活动视图 | “显示最近的提交和测试运行” |
hindsight_search | 全文搜索 | “查找关于身份验证的提交” |
hindsight_failing_tests | 查询测试失败 | “哪些测试失败?” |
hindsight_activity_summary | 汇总统计数据 | “总结我的一周” |
hindsight_commit_details | 通过测试提交信息 | “提交abc123的详细信息” |
hindsight_ingest | 触发数据刷新 | “刷新开发历史” |
Tool Arguments Reference
后视时间线
limit(int):最大事件数,默认值50workspace(string):按路径筛选
后视搜索
query(string):搜索查询(必填)source(string):“全部”、“提交”或“消息”limit(int):最大结果,默认值为20
后视失败测试
limit(int):最大测试数,默认值50workspace(string):按路径筛选commit(string):按SHA筛选
后视_活动_总结
days(int):总结天数,默认为7天
后视_承诺_细节
sha(string):提交SHA(必填)
妊娠期后视镜
workspace(string):摄取路径(必填)source(string):“git”、“副驾驶”或“all”incremental(bool):只有新数据,默认为truelimit(int):最大项目数
试验摄入
运行测试并自动摄取结果:
# Run all tests and ingest
hindsight-mcp test
# Test specific package
hindsight-mcp test -p my-crate
# Preview without writing to database
hindsight-mcp test --dry-run这 test 命令自动执行:
- 生成物
cargo nextest带有正确的标志 - 自动检测当前git提交
- 将结果输入数据库
CI / Advanced Usage
对于CI管道或自定义next est调用:
# Using stdin mode
NEXTEST_EXPERIMENTAL_LIBTEST_JSON=1 cargo nextest run \
--message-format libtest-json 2>/dev/null | \
hindsight-mcp test --stdin
# Using ingest command with explicit commit
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、作者、消息、时间戳、家长) |
| 测试 | 运行元数据、结果、持续时间、故障输出 |
| 副驾驶 | 聊天会话、提示、回复、附件 |
Git和Copilot数据是自动摄取的。测试结果需要运行 hindsight-mcp test.
CLI 参考
hindsight-mcp [OPTIONS] [COMMAND]
Commands:
ingest Ingest data from various sources
test Run tests and ingest results
Options:
-d, --database
Database path [default: ~/.hindsight/hindsight.db]
-w, --workspace
Workspace path [default: current directory]
-v, --verbose Debug logging
-q, --quiet Errors only
--skip-init Skip database init
-h, --help Print help
-V, --version Print versionTest Subcommand Options
hindsight-mcp test [OPTIONS] [-- ...]
Options:
-p, --package
Package(s) to test
--bin Binary(ies) to run
-E, --filter Filter expression
--stdin Read from stdin
--dry-run Preview only
--no-commit Do not link to commit
--commit Explicit commit SHA
--show-output Show test output环境变量
| 变量 | 描述 |
|---|---|
HINDSIGHT_DATABASE | 数据库路径 |
HINDSIGHT_WORKSPACE | 默认工作区 |
数据库位置
| 平台 | 默认路径 |
|---|---|
| macOS | ~/Library/Application Support/hindsight/hindsight.db |
| Linux | ~/.local/share/hindsight/hindsight.db |
| 窗户 | %LOCALAPPDATA%\hindsight\hindsight.db |
故障排除
| 问题 | 解决方案 |
|---|---|
| 服务器未启动 | 检查二进制路径;与...一起跑 --verbose |
| 没有数据显示 | 运行 hindsight_ingest 通过Copilot工具 |
| 日志干扰 | 使用 --quiet 生产中 |
发展
Building from Source
git clone https://github.com/Rbfinch/hindsight-mcp.git
cd hindsight-mcp
cargo build --releaseRunning Tests
cargo install cargo-nextest
cargo nextest run --workspaceWorkspace Structure
hindsight/
├── crates/
│ ├── hindsight-mcp/ # MCP server binary
│ ├── hindsight-git/ # Git log processing
│ ├── hindsight-tests/ # Test result processing
│ └── hindsight-copilot/ # Copilot session parsingFuzzing
cd crates/hindsight-tests
cargo +nightly fuzz run fuzz_nextest_run
cd crates/hindsight-copilot
cargo +nightly fuzz run fuzz_session_json许可证
麻省理工学院
