Skip to content

Commit d9d07ce

Browse files
committed
docs: update docs for v0.6.0-rc-1 with AstDiffer and 410 tests
Documents shipped v0.6.0 features: parent scope extraction, structural AST diffs via AstDiffer, import change detection, doc-vs-code SpanChangeKind classification, and adaptive token budgeting. Updates test count from 367 to 410 across README, DOCS, CHANGELOG, and PRD.
1 parent eb69b01 commit d9d07ce

4 files changed

Lines changed: 76 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
88

99
All notable changes to CommitBee are documented here.
1010

11-
## `v0.6.0` — Deep Understanding (current, in progress)
11+
## `v0.6.0-rc.1` — Deep Understanding (release candidate)
1212

1313
### Semantic Analysis
1414

@@ -18,11 +18,20 @@ All notable changes to CommitBee are documented here.
1818
- **Test file correlation** — New `RELATED FILES:` prompt section shows when source files and their matching test files are both staged. Stem-based matching, capped at 5 entries.
1919
- **Structural AST diffs**`AstDiffer` compares old and new tree-sitter nodes for modified symbols, producing structured `SymbolDiff` descriptions (parameter added, return type changed, visibility changed, async toggled, body modified). Shown as `STRUCTURED CHANGES:` section in the prompt.
2020
- **Whitespace-aware body comparison** — Body diff uses character-stream stripping so reformatting doesn't produce false `BodyModified` results.
21+
- **Structured changes in prompt** — New `STRUCTURED CHANGES:` section in the LLM prompt shows concise one-line descriptions of what changed per symbol (e.g., `CommitValidator::validate(): +param strict: bool, return bool → Result<()>, body modified`). Omitted when no structural diffs exist.
2122

2223
### Type Inference
2324

2425
- **Test-to-code ratio** — When >80% of additions are in test files, suggests `test` type even with source files present. Uses cross-multiplication to avoid integer truncation.
2526

27+
### Prompt Quality
28+
29+
- **Token budget rebalance** — Symbol budget reduced from 30% to 20% when structural diffs are available, freeing space for the raw diff. SYSTEM_PROMPT updated to guide the LLM to prefer STRUCTURED CHANGES for signature details.
30+
31+
### Testing
32+
33+
- **410 tests** total (up from 367 at v0.5.0).
34+
2635
## `v0.5.0` — Beyond the Diff
2736

2837
### Semantic Analysis
@@ -56,7 +65,7 @@ All notable changes to CommitBee are documented here.
5665
- **Evaluation harness** — 36 fixtures covering all 11 commit types, AST features, and edge cases. Per-type accuracy reporting with `EvalSummary`.
5766
- **15+ new unit tests** — Coverage for `detect_primary_change`, `detect_metadata_breaking`, `detect_bug_evidence` (all 7 patterns), Deleted/Renamed status, signature edge cases, connection content assertions.
5867
- **5 fuzz targets**`fuzz_sanitizer`, `fuzz_safety`, `fuzz_diff_parser`, `fuzz_signature`, `fuzz_classify_span`.
59-
- **367 tests** total (up from 308 at v0.4.0).
68+
- **367 tests** total (up from 308 at v0.4.0). Current count at v0.6.0-rc.1: 410.
6069

6170
### API
6271

DOCS.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ Here's what each step actually does:
8686

8787
**1. Git Service** reads your staged changes using `gix` for repo discovery and the git CLI for diffs. Paths are parsed with NUL-delimited output (`-z` flag) so filenames with spaces or special characters work correctly.
8888

89-
**2. Tree-sitter Analyzer** parses both the staged version and the HEAD version of every changed file — in parallel, using `rayon` across CPU cores. It extracts **full signatures** (e.g., `pub fn connect(host: &str, timeout: Duration) -> Result<Connection>`) by taking the definition node text before the body child. Modified symbols show old → new signature diffs. Cross-file connections are detected (caller+callee both changed). Symbols are tracked in three states: added, removed, or modified-signature.
89+
**2. Tree-sitter Analyzer** parses both the staged version and the HEAD version of every changed file — in parallel, using `rayon` across CPU cores. It extracts **full signatures** (e.g., `pub fn connect(host: &str, timeout: Duration) -> Result<Connection>`) by taking the definition node text before the body child. Methods include their **parent scope** (enclosing impl, class, or trait — e.g., `CommitValidator::validate`). Modified symbols show old → new signature diffs, with **structural AST diffs** that describe exactly what changed (parameters added/removed, return type changed, visibility changed, etc.). Cross-file connections are detected (caller+callee both changed). Symbols are tracked in three states: added, removed, or modified-signature, with a **doc-vs-code distinction** indicating whether changes were documentation-only, code-only, or mixed.
9090

9191
**3. Commit Splitter** looks at your staged changes and decides whether they contain logically independent work. It uses diff-shape fingerprinting (what kind of changes — additions, deletions, modifications) combined with Jaccard similarity on content vocabulary to group files. If it finds multiple concerns, it offers to split them into separate commits.
9292

93-
**4. Context Builder** assembles a budget-aware prompt. It classifies modified symbols as whitespace-only or semantic (via character-stream comparison), computes evidence flags (mechanical change? public APIs removed? bug-fix evidence?), detects cross-file connections, calculates the character budget for the subject line, and packs context within the token limit (~6K tokens, 30/70 symbol/diff split when signatures present).
93+
**4. Context Builder** assembles a budget-aware prompt. It classifies modified symbols as whitespace-only or semantic (via character-stream comparison), computes evidence flags (mechanical change? public APIs removed? bug-fix evidence?), detects cross-file connections, identifies import changes and test file correlations, calculates the character budget for the subject line, and packs context within the token limit (~6K tokens). The token budget adapts: when structural AST diffs are available, symbols get 20% of the budget (diffs carry more detail); when only signatures are available, symbols get 30%.
9494

9595
**5. LLM Provider** streams the prompt to your chosen model (Ollama, OpenAI, or Anthropic) and collects the response token by token.
9696

@@ -107,6 +107,10 @@ CommitBee doesn't just send a diff. The prompt includes:
107107
- **Evidence flags** telling the LLM deterministic facts about the change
108108
- **Symbol changes with full signatures**`[+] pub fn connect(host: &str) -> Result<()>`, not just "Function connect"
109109
- **Signature diffs**`[~] old_sig → new_sig` for modified symbols
110+
- **Structured AST diffs**`CommitValidator::validate(): +param timeout, return Result<()> → Result<Error>` (precise semantic changes from AST comparison)
111+
- **Import changes**`analyzer: added use crate::domain::DiffHunk` (tracked per file)
112+
- **Test file correlations**`src/services/context.rs <-> tests/context.rs (test file)`
113+
- **Doc-vs-code annotations** — modified symbols tagged `[docs only]` or `[docs + code]` when change is documentation-only or mixed
110114
- **Cross-file connections**`validator calls parse() — both changed`
111115
- **Primary change detection** — which file has the most significant changes
112116
- **Constraints** — rules the LLM must follow based on evidence (e.g., "no bug-fix comments found, prefer refactor over fix")
@@ -570,7 +574,9 @@ For supported languages, symbols are tracked in three states:
570574
- **Removed** `[-]` — Deleted symbol
571575
- **Modified (signature changed)** `[~]` — Symbol exists in both versions but its signature changed
572576

573-
This information appears in the prompt as a `SYMBOLS CHANGED` section, giving the LLM precise knowledge of what was structurally modified.
577+
Modified symbols include additional annotations: `[docs only]` when only documentation/comments changed, `[docs + code]` when both documentation and code changed. Methods show their parent scope (e.g., `CommitValidator::validate` rather than just `validate`).
578+
579+
This information appears in the prompt as a `SYMBOLS CHANGED` section. When structural AST diffs are available, a separate `STRUCTURED CHANGES` section provides precise details like `+param timeout`, `return Result<()> → Result<Error>`, or `+field name`.
574580

575581
## 🔧 Troubleshooting
576582

@@ -650,13 +656,15 @@ src/
650656
├── error.rs # Error types (thiserror + miette diagnostics)
651657
├── domain/
652658
│ ├── change.rs # FileChange, StagedChanges, ChangeStatus
653-
│ ├── symbol.rs # CodeSymbol, SymbolKind (Added/Removed/Modified)
659+
│ ├── symbol.rs # CodeSymbol, SymbolKind, SpanChangeKind
660+
│ ├── diff.rs # SymbolDiff, ChangeDetail (structural AST diffs)
654661
│ ├── context.rs # PromptContext — assembles the LLM prompt
655662
│ └── commit.rs # CommitType enum (single source of truth)
656663
└── services/
657664
├── git.rs # GitService — gix for discovery, git CLI for diffs
658665
├── analyzer.rs # AnalyzerService — tree-sitter parsing via rayon
659666
├── context.rs # ContextBuilder — evidence flags, token budget
667+
├── differ.rs # AstDiffer — structural comparison of old/new symbols
660668
├── safety.rs # Secret scanning (24 patterns), conflict detection
661669
├── sanitizer.rs # CommitSanitizer + CommitValidator
662670
├── splitter.rs # CommitSplitter — diff-shape + Jaccard clustering
@@ -678,7 +686,7 @@ src/
678686

679687
**Streaming with Cancellation** — All providers support Ctrl+C cancellation via `tokio_util::CancellationToken`. The streaming display runs in a separate tokio task with `tokio::select!` for responsive cancellation.
680688

681-
**Token Budget** — The context builder tracks character usage (~4 chars per token) and truncates the diff if it exceeds the budget, prioritizing the most important files. The default 24K char budget (~6K tokens) is safe for 8K context models.
689+
**Token Budget** — The context builder tracks character usage (~4 chars per token) and truncates the diff if it exceeds the budget, prioritizing the most important files. The budget adapts based on available information: when structural AST diffs are present, the symbol allocation shrinks (20%) since the diffs carry precise detail; when only signatures are available, symbols get 30%. The default 24K char budget (~6K tokens) is safe for 8K context models.
682690

683691
**Single Source of Truth for Types**`CommitType::ALL` is a const array that defines all valid commit types. The system prompt's type list is verified at compile time (via a `#[test]`) to match this array exactly.
684692

@@ -694,7 +702,7 @@ No panics in user-facing code paths. The sanitizer and validator are tested with
694702

695703
### Testing Strategy
696704

697-
CommitBee has 367 tests across multiple strategies:
705+
CommitBee has 410 tests across multiple strategies:
698706

699707
| Strategy | What It Covers |
700708
| --- | --- |
@@ -707,7 +715,7 @@ CommitBee has 367 tests across multiple strategies:
707715
Run them:
708716

709717
```bash
710-
cargo test # All 367 tests
718+
cargo test # All 410 tests
711719
cargo test --test sanitizer # Just sanitizer tests
712720
cargo test --test integration # LLM provider mocks
713721
COMMITBEE_LOG=debug cargo test -- --nocapture # With logging

PRD.md

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
66

77
# CommitBee — Product Requirements Document
88

9-
**Version**: 4.3
10-
**Date**: 2026-03-27
9+
**Version**: 4.3
10+
**Date**: 2026-03-27
1111
**Status**: Active
1212
**Author**: [Sephyi](https://github.com/Sephyi) + [Claude Opus 4.6](https://www.anthropic.com/news/claude-opus-4-6)
1313

@@ -18,7 +18,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
1818

1919
| Version | Date | Summary |
2020
|---------|------------|---------|
21-
| 4.3 | 2026-03-27 | v0.6.0 deep semantic understanding (in progress): Tier 2 — parent scope extraction for impl/class/trait methods (7 languages), import change detection (Rust/TS/JS/Python/Go/C/C++), doc-vs-code SpanChangeKind classification with Mixed variant, test-to-code ratio type inference, test file correlation. Tier 1 — SymbolDiff types + ChangeDetail enum (15 variants), AstDiffer for structural function diffing (params, return type, visibility, async, body), pipeline integration into extract_symbols/ContextBuilder. Plans dialectic-verified by GLM5 + Codex gpt-5.4 + Gemini 2.5 Pro with 12 fixes applied. 401+ tests. |
21+
| 4.3 | 2026-03-27 | v0.6.0-rc.1 deep semantic understanding: parent scope, import detection, doc-vs-code classification, structural AST diffs (AstDiffer + SymbolDiff), STRUCTURED CHANGES prompt section, token budget rebalance. 410 tests. |
2222
| 4.2 | 2026-03-22 | v0.5.0 hardening: security fixes (SSRF prevention, streaming caps), prompt optimization (budget fix, evidence omission, emoji removal), eval harness (36 fixtures, per-type reporting), test coverage (15+ new tests), API hygiene (pub(crate) demotions), 5 fuzz targets. 359 tests. |
2323
| 4.1 | 2026-03-22 | AST context overhaul (v0.5.0): full signature extraction from tree-sitter nodes, semantic change classification (whitespace vs body vs signature), old→new signature diffs, cross-file connection detection, formatting auto-detection via symbols. 359 tests. |
2424
| 4.0 | 2026-03-13 | PRD normalization: aligned phases with shipped versions (v0.2.0/v0.3.x/v0.4.0), collapsed revision history, unified status markers, resolved stale critical issues, canonicalized test count to 308, removed dead cross-references. FR-031 (Exclude Files) and FR-033 (Copy to Clipboard) shipped. |
@@ -61,6 +61,8 @@ CommitBee is a Rust-native CLI tool that uses tree-sitter semantic analysis and
6161
| v0.3.0 | Differentiation core (splitter enhancements, validation, heuristics) | None |
6262
| v0.3.1 | Patch — default model → `qwen3.5:4b`, subject length validation, `think` config | None |
6363
| v0.4.0 | Feature completion (templates, languages, rename detection, history learning) | None |
64+
| v0.5.0 | AST context overhaul (signatures, semantic classification, cross-file connections) | None |
65+
| v0.6.0-rc.1 | Deep semantic understanding (parent scope, imports, doc-vs-code, structural AST diffs) | None |
6466

6567
## 2. Competitive Landscape
6668

@@ -93,7 +95,7 @@ CommitBee is a Rust-native CLI tool that uses tree-sitter semantic analysis and
9395
| Multiple message generation (pick from N) | Common (aicommits, aicommit2) | ✅ v0.2.0 |
9496
| Commit splitting (multi-concern detection) | No competitor has this | ✅ v0.2.0 |
9597
| Custom prompt/instruction files | Growing (Copilot, aicommit2) | ✅ v0.4.0 |
96-
| Unit/integration tests | Non-negotiable for quality |359 tests |
98+
| Unit/integration tests | Non-negotiable for quality |410 tests |
9799

98100
## 3. Architecture
99101

@@ -479,7 +481,37 @@ Project-level `.commitbee.toml` can no longer override `openai_base_url`, `anthr
479481

480482
Subject character budget accounts for `!` suffix on breaking changes. EVIDENCE section omitted when all flags are default (~200 chars saved). Symbol marker legend added to SYSTEM_PROMPT (`[+] added, [-] removed, [~] modified`). Duplicate JSON schema removed from system prompt. Emoji replaced with text labels (`WARNING:` instead of ``). CONNECTIONS instruction softened for small models. Python tree-sitter queries enhanced with `decorated_definition` support.
481483

482-
### 4.6 Future — v0.6.0+ (Market Leadership)
484+
### 4.6 Shipped — v0.6.0-rc.1 (Deep Semantic Understanding)
485+
486+
#### FR-064: Parent Scope Extraction ✅
487+
488+
Tree-sitter AST walker extracts enclosing `impl`/`class`/`trait` scope for methods, displaying `Parent > signature` format in symbol output. Walks through intermediate nodes (`declaration_list`, `class_body`). Verified across 7 languages (Rust, Python, TypeScript, Java, Go, Ruby, C#). 10 per-language tests.
489+
490+
#### FR-065: Import Change Detection ✅
491+
492+
`detect_import_changes()` scans diff lines for added/removed import statements, producing an `IMPORTS CHANGED:` prompt section with file stem and action. Supports Rust `use`, JS/TS `import`, Python `from`/`import`, Node `require()`, C/C++ `#include`. Capped at 10 entries. 5 tests.
493+
494+
#### FR-066: Doc-vs-Code Change Classification ✅
495+
496+
`SpanChangeKind` enum (`Unchanged`, `WhitespaceOnly`, `DocsOnly`, `Mixed`, `Semantic`) replaces binary `is_whitespace_only` for richer modified-symbol classification. `classify_span_change_rich()` detects comment-line prefixes (`///`, `//!`, `#`, `"""`, `/**`). Doc-only modifications suggest `docs` type. Modified symbols show `[docs only]` or `[docs + code]` suffix in prompt output. 7 tests.
497+
498+
#### FR-067: Test-to-Code Ratio Inference ✅
499+
500+
In `infer_commit_type`, when >80% of additions are in `FileCategory::Test` files, returns `CommitType::Test` even with source files present. Uses cross-multiplication (`test * 100 > total * 80`) to avoid integer truncation. 2 tests.
501+
502+
#### FR-068: Test File Correlation ✅
503+
504+
`detect_test_correlation()` matches staged source files to test files by file stem, producing a `RELATED FILES:` prompt section (e.g., `src/services/context.rs <-> tests/context.rs (test file)`). Capped at 5 entries. 4 tests.
505+
506+
#### FR-069: Structural AST Diffs ✅
507+
508+
`AstDiffer` in `src/services/differ.rs` compares old and new tree-sitter AST nodes for modified symbols, producing `SymbolDiff` with `Vec<ChangeDetail>` (15-variant enum: `ParamAdded`, `ParamRemoved`, `ParamTypeChanged`, `ReturnTypeChanged`, `VisibilityChanged`, `AttributeAdded`/`Removed`, `AsyncChanged`, `GenericChanged`, `BodyModified`, `BodyUnchanged`, `FieldAdded`/`Removed`/`TypeChanged`). Runs inside `extract_for_file()` while both Trees are alive (Node lifetime constraint). `extract_symbols()` returns `(Vec<CodeSymbol>, Vec<SymbolDiff>)`. Struct/enum field diffing stubbed for future. Whitespace-aware body comparison via character-stream stripping. 7 unit tests + 6 per-language integration tests.
509+
510+
#### FR-070: Structured Changes Prompt Section ✅
511+
512+
`STRUCTURED CHANGES:` section in LLM prompt renders `SymbolDiff::format_oneline()` descriptions (e.g., `CommitValidator::validate(): +param strict: bool, return bool → Result<()>, body modified (+5 -2)`). Omitted when no structural diffs exist. Token budget rebalanced: symbol budget reduced from 30% to 20% when structural diffs available, freeing space for raw diff. SYSTEM_PROMPT updated to guide LLM to prefer structured changes for signature details. 3 tests.
513+
514+
### 4.7 Future — v0.7.0+ (Market Leadership)
483515

484516
#### FR-050: MCP Server Mode
485517

@@ -661,7 +693,7 @@ commitbee eval # Run evaluation harness (dev, feature-ga
661693

662694
## 8. Testing Requirements
663695

664-
**Current test count: 367**
696+
**Current test count: 410**
665697

666698
### TR-001: Unit Tests
667699

@@ -819,9 +851,9 @@ Invalid JSON → retry once with repair prompt. Second failure → heuristic ext
819851
| 2 | v0.3.x | ✅ Shipped | Differentiation — heuristics, validation, spec compliance |
820852
| 3 | v0.4.0 | ✅ Shipped | Feature completion — templates, languages, rename, history, eval, fuzzing |
821853
| 4 | v0.4.x | ✅ Shipped | Remaining polish — exclude files (FR-031), clipboard (FR-033) |
822-
| 5 | v0.5.0 | ✅ Shipped | AST context overhaul — full signatures, semantic change classification, cross-file connections. 359 tests. |
823-
| 5.5 | v0.5.x | 🔨 Next | Deep semantic understanding — parent scope, imports, doc-vs-code (T2), structural AST diffs (T1), language markers + change intent (T3). Plans dialectic-verified 2026-03-26. |
824-
| 6 | v0.6.0+ | 📋 Planned | Market leadership — MCP server, changelog, monorepo, version bumping, GitHub Action |
854+
| 5 | v0.5.0 | ✅ Shipped | AST context overhaul — full signatures, semantic change classification, cross-file connections. 367 tests. |
855+
| 6 | v0.6.0-rc.1 | ✅ Shipped | Deep semantic understanding — parent scope, import detection, doc-vs-code classification, structural AST diffs, structured changes prompt section. 410 tests. |
856+
| 7 | v0.7.0+ | 📋 Planned | Market leadership — MCP server, changelog, monorepo, version bumping, GitHub Action |
825857

826858
## 12. Success Metrics
827859

@@ -835,7 +867,7 @@ Invalid JSON → retry once with repair prompt. Second failure → heuristic ext
835867
| Commit message quality | > 80% "good enough" first try | Manual evaluation + `commitbee eval` |
836868
| Secret leak rate | 0 | Integration tests with known patterns |
837869
| MSRV | Rust 1.94 (edition 2024) | CI matrix (stable + 1.94) |
838-
| Test count | ≥ 308 | `cargo test` (current: 359) |
870+
| Test count | ≥ 308 | `cargo test` (current: 410) |
839871

840872
## 13. Non-Goals
841873

0 commit comments

Comments
 (0)