Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

latte-doc-review-graph

Rust CLI for change-driven review + LLM context pre-read.

项目简介

latte-doc-review-graph 是一个基于 Rust 的命令行工具,提供两个核心功能:

  1. 变更驱动 review:检测代码/文档变更,自动识别受影响的文档,生成 review 报告
  2. LLM context 预读:基于查询语句,预读相关文档块,生成可直接喂给 LLM 的结构化 context

安装

cargo install --path .

安装后会生成 latte-review 命令。

快速开始

# 1. 初始化项目
latte-review init .

# 2. 扫描文档并构建知识图谱
latte-review scan

# 3. 查看图谱状态
latte-review status

# 4. 检查变更影响(对比 HEAD~1 和 HEAD)
latte-review diff

# 5. 生成完整的 review 报告
latte-review review --from HEAD~1 --to HEAD

# 6. LLM context 预读
latte-review context "authentication flow"

# 7. 诊断问题
latte-review doctor

命令详解

全局选项

所有命令都支持以下全局选项:

选项 说明 默认值
-C, --dir <PATH> 项目根目录 当前目录
-v, --verbose 详细日志输出 否
--no-color 禁用 ANSI 颜色输出 否
--json JSON 格式输出(机器可读) 否

init - 初始化项目

在项目中创建 .latte-review 目录结构。

latte-review init [PATH]

参数:

  • PATH - 初始化路径,默认为当前目录

创建的目录结构:

.latte-review/
├── docs/
│   ├── entities/     # 实体文档
│   ├── concepts/     # 概念文档
│   └── features/     # 功能文档
├── cache/
│   └── vector-index/ # 向量索引缓存
├── config.toml       # 配置文件
├── graph.json        # 知识图谱
└── .gitignore        # Git 忽略规则

示例:

# 在当前目录初始化
latte-review init .

# 在指定目录初始化
latte-review init /path/to/project

scan - 扫描文档构建图谱

扫描 docs/ 目录下的所有 Markdown 文档,解析 frontmatter 和 wikilink,构建知识图谱。

latte-review scan [OPTIONS]

输出:

  • 节点数量(文档数)
  • 边数量(文档关系数)
  • 社区数量(文档聚类数)
  • 孤儿文档数(无入链/出链的文档)

示例:

# 扫描并构建图谱
latte-review scan

# JSON 格式输出
latte-review scan --json

status - 查看图谱状态

显示当前知识图谱的健康状态。

latte-review status [OPTIONS]

输出字段:

  • nodes: 文档节点数量
  • edges: 文档关系边数量
  • communities: 社区检测发现的聚类数量
  • avg_degree: 平均节点度数
  • orphans: 孤儿文档数量

示例:

latte-review status

# JSON 格式
latte-review status --json

diff - 查看变更影响

分析代码变更对文档的影响,列出受影响的文档和建议操作。

latte-review diff [OPTIONS]

默认对比: HEAD~1 vs HEAD

输出:

  • 变更的文件数量
  • 受影响的文档列表
  • 每个文档的相关性分数和建议操作

建议操作类型:

  • review: 需要审查更新
  • stale: 文档已过期
  • update: 需要更新
  • none: 无需操作

示例:

# 查看最近一次提交的影响
latte-review diff

# JSON 格式
latte-review diff --json

review - 生成完整报告

复合命令:扫描文档 + 分析变更 + 生成 Markdown 报告。

latte-review review [OPTIONS]

选项:

  • --from <REF>: Git 起始引用,默认 HEAD~1
  • --to <REF>: Git 结束引用,默认 HEAD

输出:

  • 在 .latte-review/reports/ 目录下生成时间戳命名的 Markdown 报告
  • 报告包含:变更文件列表、受影响文档、建议操作

示例:

# 生成最近一次提交的 review 报告
latte-review review

# 生成特定范围的报告
latte-review review --from main --to feature-branch

# 生成 PR 报告
latte-review review --from origin/main --to HEAD

context - LLM context 预读

基于查询语句,预读相关文档,生成结构化 context。适合作为 LLM 的预读材料。

latte-review context <QUERY> [OPTIONS]

参数:

  • QUERY: 查询语句

输出:

  • Top 10 相关文档
  • 每个文档的相关性分数

示例:

# 查询认证相关文档
latte-review context "authentication flow"

# 查询 API 相关文档
latte-review context "API endpoint"

# JSON 格式(适合程序处理)
latte-review context "error handling" --json

doctor - 诊断问题

检查知识图谱的健康状况,发现潜在问题。

latte-review doctor

检查项目:

  • 孤儿文档(无入链/出链)
  • 自环边(文档链接到自己)

退出码:

  • 0: 图谱健康
  • >0: 发现的问题数量

用途:

  • 可在 CI 中使用,阻止不健康的图谱合并

示例:

latte-review doctor

# 在 CI 中使用
latte-review doctor || exit 1

clear-cache - 清除缓存

清除 .latte-review/cache/ 目录下的所有缓存数据。

latte-review clear-cache

示例:

latte-review clear-cache

存储位置和数据流

目录结构

latte-doc-review-graph 使用两个主要目录:

项目根目录/
├── docs/                  # 用户文档(Git 跟踪)
│   ├── entities/
│   ├── concepts/
│   └── features/
│
└── .latte-review/         # 系统数据(部分 Git 跟踪)
    ├── docs/              # 文档模板(可删除)
    ├── cache/             # 缓存(Git 忽略)
    ├── reports/           # 报告(Git 忽略)
    ├── config.toml        # 配置(Git 跟踪)
    ├── graph.json         # 图谱(可选跟踪)
    └── .gitignore

数据存储位置

数据类型 存储位置 Git 状态 说明
用户文档 docs/ ✅ 跟踪 在此创建和编辑文档
知识图谱 .latte-review/graph.json ✅ 可选 scan 命令生成
Review 报告 .latte-review/reports/ ❌ 忽略 review 命令生成
缓存数据 .latte-review/cache/ ❌ 忽略 临时数据,可清除
配置文件 .latte-review/config.toml ✅ 跟踪 用户可自定义

数据流

用户编辑 docs/*.md(输入)
    ↓ latte-review scan
生成 .latte-review/graph.json(中间产物)
    ↓ latte-review review
生成 .latte-review/reports/*.md(输出)

增量文档处理

创建新文档:

# 1. 在 docs/ 目录创建新文档
vim docs/entities/new-entity.md

# 2. 扫描更新图谱
latte-review scan

# 3. 查看更新结果
latte-review status

删除文档:

# 1. 删除文档文件
rm docs/entities/old-entity.md

# 2. 扫描更新图谱
latte-review scan

# 3. 查看更新结果
latte-review status

Git 跟踪建议

推荐跟踪:

  • ✅ docs/ - 所有用户文档
  • ✅ .latte-review/config.toml - 项目配置
  • ✅ .latte-review/.gitignore - 忽略规则
  • ⚠️ .latte-review/graph.json - 可选(团队共享图谱)

不跟踪:

  • ❌ .latte-review/cache/ - 临时缓存
  • ❌ .latte-review/reports/ - 自动生成的报告
  • ❌ .latte-review/state.toml - 运行状态

详见 docs/storage-locations.md

典型工作流

开发者工作流

# 1. 修改代码
vim src/auth/AuthService.ts

# 2. 扫描文档(如果有新文档)
latte-review scan

# 3. 检查变更影响
latte-review diff

# 4. 生成 review 报告并附加到 PR
latte-review review --from origin/main --to HEAD
cat .latte-review/reports/*.md

# 5. 提交 PR
git push

CI/CD 集成

# .github/workflows/review.yml
- name: Check documentation health
  run: latte-review doctor
  
- name: Generate review report
  run: latte-review review --from origin/main --to HEAD
  
- name: Upload report
  uses: actions/upload-artifact@v3
  with:
    name: review-report
    path: .latte-review/reports/

LLM 集成

# 生成 context 并传递给 LLM
CONTEXT=$(latte-review context "authentication" --json)

# 配合 OpenAI API 使用
openai api chat.completions.create \
  -m gpt-4 \
  --messages "[{\"role\": \"system\", \"content\": \"$CONTEXT\"}, {\"role\": \"user\", \"content\": \"How does auth work?\"}]"

配置文件

配置文件位于 .latte-review/config.toml:

[graph]
# 图构建权重
direct_link_weight = 3.0           # 直接链接权重
source_overlap_weight = 4.0        # 源文件重叠权重
common_neighbor_weight = 1.5       # 共同邻居权重
type_affinity_weight = 1.0         # 类型亲和权重
semantic_similarity_weight = 2.0   # 语义相似度权重

# 社区检测
community_algorithm = "greedy"     # 算法:greedy | louvain
community_resolution = 1.0         # 分辨率参数

[search]
recall_top_k = 50                  # 召回 Top K
expansion_depth = 2                # 扩展深度
semantic_similarity_threshold = 0.3 # 语义相似度阈值

[context]
default_max_docs = 10              # 默认最大文档数
default_token_budget = 4000        # 默认 token 预算
pages_ratio = 0.55                 # 页面比例
index_ratio = 0.10                 # 索引比例
overview_ratio = 0.15              # 概览比例

[impact]
stale_threshold_days = 30          # 过期阈值(天)

文档规范

Frontmatter

文档应在 YAML frontmatter 中包含以下字段:

---
title: Authentication Service
type: entity
sources:
  - src/auth/AuthService.ts
  - src/auth/TokenManager.ts
tags:
  - authentication
  - security
---

文档内容...

必填字段:

  • title: 文档标题
  • type: 文档类型(entity | concept | feature | spec | task | bug)

可选字段:

  • sources: 关联的源代码文件路径
  • tags: 标签列表

Wikilink

使用 [[wikilink]] 语法链接文档:

认证流程使用 [[concepts/auth-service]] 提供的服务。
详见 [[concepts/auth-flow]] 了解完整流程。

重要提示: wikilink 必须使用完整的文档路径(如 concepts/auth-service),而不是短名称(如 auth-service)。

性能指标

设计目标:

  • 增量扫描 1k 文档 < 1s
  • 10k 文档全文检索 < 100ms

与 latte-doc-wiki 的关系

latte-doc-review-graph 是 latte-doc-wiki (TypeScript) 的 Rust 内核实现:

功能 latte-doc-wiki (TS) latte-doc-review-graph (Rust)
桌面 UI ✅ ❌
变更驱动 review ⚠️ 弱 ✅ 强
Git 集成 ⚠️ 弱 ✅ 强
LLM context ✅ ✅
性能 一般 优秀
分发 需要 Node.js 单一 binary

更多信息

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages