文档代码深度分析CLI工具

一个使用双层AI架构(研究员模型进行推理和侦察模型进行文件发现)对Markdown文档和代码库进行系统深度分析的CLI工具。

  • by lox
  • Go
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 lox/deep-analysis-mcp

使用说明

深度分析CLI

一个CLI工具,用于使用两层AI架构对markdown文档和代码库进行系统深入分析:一个用于推理的研究人员模型和一个用于文件发现的侦察模型。

🤖 注: 这个项目是 “氛围设计” 与 安培 Claude Opus 4.5和其他人,作为我持续努力的一部分,以证明人工智能辅助开发可以在与严格的设计文档、全面的测试和仔细的人工审查相结合的情况下生产出高质量的软件。

特性

  • 两层技术模型:研究者模型侧重于推理,而侦察模型处理文件发现
  • OpenAI与人类学:使用GPT或Claude模型(包括Fable和Opus)运行相同的工作流
  • 三个高级工具: find_files, summarize_files, read_files 通过成本控制
  • 会话连续性:继续对话 --continue <session-id>
  • 成本跟踪:研究人员和侦察员模型的单独使用报告

先决条件

安装

mise install

# Build the CLI with the pinned toolchain
mise run build

# Install into your Go bin dir
mise run install

# Install into ~/bin
mise run install:global

# Or directly with Go if you already have it installed
mkdir -p dist
go build -o dist/deep-analysis .

配置

使用环境变量设置OpenAI API密钥:

export OPENAI_API_KEY="your-api-key-here"

对于Anthropic模型,使用:

export ANTHROPIC_API_KEY="your-api-key-here"

或者将其存储在XDG配置文件中:

./dist/deep-analysis setup

# Or configure Anthropic
./dist/deep-analysis setup --provider anthropic

共享配置将密钥存储为 openai_api_key 和 anthropic_api_key. deep-analysis 还检查特定于提供商的 ${XDG_CONFIG_HOME:-$HOME/.config}/openai/config.yaml 和 anthropic/config.yaml 文件,其中 api_key 被接受。环境变量优先于凭据。

在共享配置中设置全局研究员和侦察员默认值,以便每次运行都可以使用相同的提供者组合:

researcher: anthropic.claude-opus-4-8@xhigh
scout: openai.gpt-5.5@low

这些字段可以与API键一起使用。模型选择优先级是命令行标志,然后是全局配置,然后是编译后的OpenAI默认值。跑步 setup 添加或替换提供程序密钥会保留配置的模型默认值。

检查已安装的二进制文件、有效模型和凭据源:

./dist/deep-analysis doctor

用法

基本分析

# Analyze a markdown document (results appended in place)
./dist/deep-analysis notes.md

# Write output to a different file
./dist/deep-analysis notes.md --output annotated.md

# Analyze a project in a different directory
./dist/deep-analysis --cwd /path/to/project task.md

# Use Fable 5 for research and Sonnet 5 for scouting
./dist/deep-analysis task.md \
  --researcher anthropic.claude-fable-5@xhigh \
  --scout anthropic.claude-sonnet-5@low

# Use Opus as the researcher instead
./dist/deep-analysis task.md \
  --researcher anthropic.claude-opus-4-8@xhigh \
  --scout anthropic.claude-sonnet-5@low

# Mix providers: Fable researcher with an OpenAI scout
./dist/deep-analysis task.md \
  --researcher anthropic.claude-fable-5@xhigh \
  --scout openai.gpt-5.5@low

# Or GPT researcher with an Anthropic scout
./dist/deep-analysis task.md \
  --researcher openai.gpt-5.6-sol@xhigh \
  --scout anthropic.claude-sonnet-5@low

选择使用 provider.model[@effort]。提供者在第一个点处分开,在最后一个点处进行可选努力 @公认的努力是 low, medium, high,以及 xhigh。省略后缀以使用提供程序的模型默认值。OpenAI GPT-5.6研究人员使用Pro模式,而较旧的OpenAI覆盖保留了他们现有的请求行为。 @ 在通用shell或YAML中不需要转义。

后续问题

每次运行都会生成一个记录到stderr的会话ID:

INFO Saved session session=f1736654e6d5a7c1b58d14ac response_id=resp_xxx

要继续对话,请执行以下操作:

  1. 将您的后续问题添加到文档中
  2. 与一起跑步 --continue:
./dist/deep-analysis notes.md --continue f1736654e6d5a7c1b58d14ac

AI将看到您之前的分析,并专注于新问题。

CLI标志

标志 描述
--output 输出文件路径(默认为输入文件)
--continue 会话ID以继续之前的对话
--reset 重新启动,忽略存储的会话状态
--cwd 文件操作的工作目录
--researcher 研究员as provider.model[@effort] (覆盖全局配置;编译默认值: openai.gpt-5.6-sol@xhigh 在Pro模式下)
--scout 童子军作为 provider.model[@effort] (覆盖全局配置;编译默认值: openai.gpt-5.5@low)
--reasoning-effort 被弃用的研究人员努力被推翻;无法陪同 @effort 在 --researcher
--debug 启用调试日志记录
--version 打印已安装的版本并退出

命令

命令 描述
analyze <input> 分析markdown文档(默认命令)
setup [--provider openai|anthropic] 提示提供程序API密钥并写入XDG配置
doctor 检查已安装的二进制文件、有效模型和凭据配置
version 打印已安装的版本并退出

运作原理

两层技术模型

Researcher model           →  Reasoning, analysis, conclusions
        ↓
    find_files / summarize_files / read_files
        ↓
Scout model                →  Translates queries to glob/grep
        ↓
File System                →  Actual file access

研究人员可用的工具

  1. 查找文件(查询、路径) -发现与自然语言意图匹配的文件

    • 返回具有大小的文件路径
    • Scout翻译为glob/grep模式
  2. 摘要文件(路径、焦点) -获取人工智能生成的摘要(便宜,自由使用)

    • Scout读取并总结文件
    • 用于全面阅读前的分类
  3. read_files(路径) -读取完整文件内容(昂贵,请谨慎使用)

    • 每次通话限制为10个文件或200KB
    • 超出限制将返回带有指导的错误

工作流

研究人员如下: find → 总结→ read

  1. find_files("error handling") → 返回15个文件(共180KB)
  2. summarize_files(all paths, "error patterns") → 快速摘要
  3. 从摘要中识别3个关键文件
  4. read_files(those 3) → 完整的分析内容
  5. 引用特定代码编写分析

成本跟踪

每次运行都会报告两种模型的使用情况:

INFO Researcher usage model=gpt-5.6-sol api_calls=5 input_tokens=12000 uncached_input_tokens=4000 output_tokens=3000 cached_tokens=7000 cache_write_tokens=1000 cache_hit_rate=58.3% cost_usd=$0.1198
INFO Scout usage      model=gpt-5.5     api_calls=8 input_tokens=45000 output_tokens=800 cost_usd=$0.2490
INFO Total cost               usd=$0.3688

OpenAI GPT-5.6研究人员的请求在工具循环中保持相同的指令、工具、推理设置和模型范围的缓存键。它们的使用线将未缓存的输入、缓存写入和缓存读取分开,因此命中率和GPT-5.6缓存写入溢价在成本估算中可见。

Anthropic研究人员会自动缓存不断增长的工具使用对话五分钟。他们的使用线还报告了新的输入、缓存创建、缓存读取以及由此产生的缓存命中率,因此成本估算包括Anthropic的缓存写入溢价。

发展

mise run build  # Build to dist/deep-analysis
mise run install  # Install to GOBIN or GOPATH/bin
mise run install:global  # Install to ~/bin
mise run test   # Run tests
mise run lint   # Run linter
mise run run notes.md
mise run run notes.md --output annotated.md

建筑学

.
├── main.go                      # CLI entrypoint
├── internal/
│   ├── agent/
│   │   ├── scout.go            # Scout dispatcher default
│   │   ├── manifest.go         # Project file listing
│   │   └── file_search.go      # Legacy file search
│   ├── client/
│   │   ├── deepanalysis.go     # OpenAI researcher and shared workflow
│   │   ├── anthropic.go        # Anthropic researcher tool loop
│   │   └── session_store.go    # Session persistence
│   ├── fileops/
│   │   └── fileops.go          # File operations (read, grep, glob)
│   └── server/                 # MCP server (optional)
└── plans/
    └── two-tier-analysis.md    # Architecture documentation

许可证

麻省理工学院