# cree1116/lancet architecture

> Architecture diagram of the GitHub repository cree1116/lancet, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cree1116/lancet
- Repository: https://github.com/cree1116/lancet

## Overview

Lancet is a Rust CLI and MCP server for searching, reading, understanding, and safely changing code and documents through shared indexing and line coordinates. The main workflow dispatches a command, plans candidate files, searches or inspects extracted content, then optionally applies revision-checked edits. The graph preserves documented command branches and core runtime layers. Some command implementations were not excerpted; those links rely on README statements or the CLI dispatch excerpt, not inspection of unsampled source.

Main entry points: [`src/cli/mod.rs`](https://github.com/cree1116/lancet/blob/main/src/cli/mod.rs) (CLI Dispatch), [`src/rg.rs`](https://github.com/cree1116/lancet/blob/main/src/rg.rs) (Text Search), [`src/index/mod.rs`](https://github.com/cree1116/lancet/blob/main/src/index/mod.rs) (Trigram Index), [`src/change.rs`](https://github.com/cree1116/lancet/blob/main/src/change.rs) (Change Planning)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Interfaces"]
  node_cli["CLI Dispatch<br/>[mod.rs]"]
  node_mcp["MCP Server<br/>[mcp.rs]"]
  node_fdcli["fd Command<br/>[fd.rs]"]
  node_rgcli["rg Command<br/>[rg.rs]"]
  node_readcli["read Command<br/>[read.rs]"]
  node_editcli["edit and write<br/>[edit.rs]"]
  node_indexcli["index Command<br/>[index.rs]"]
  node_othercli["Other Commands"]
end

subgraph group_discovery["Discovery and Index"]
  node_walk["File Traversal<br/>[walk.rs]"]
  node_scope["Candidate Planning<br/>[scope.rs]"]
  node_index[("Trigram Index<br/>[mod.rs]")]
  node_segments[("Index Segments<br/>[segment.rs]")]
  node_indexreq["Index Queries<br/>[req.rs]"]
end

subgraph group_inspection["Search and Inspection"]
  node_rg["Text Search<br/>[rg.rs]"]
  node_fd["File Search<br/>[fd.rs]"]
  node_ast["AST Search and Rewrite<br/>[ast_grep.rs]"]
  node_read["Range and Symbol Read<br/>[read_cmd.rs]"]
  node_outline["Outline<br/>[outline.rs]"]
  node_refs["References<br/>[refs.rs]"]
  node_rename["Scoped Rename<br/>[rename.rs]"]
  node_code["Syntax Structure<br/>[code.rs]"]
  node_scopes["Scope Resolution<br/>[scopes.rs]"]
end

subgraph group_changes["Safe Changes"]
  node_editcmd["Edit Operations<br/>[edit_cmd.rs]"]
  node_patch["Multi-file Patch<br/>[patch.rs]"]
  node_change["Change Planning<br/>[change.rs]"]
  node_edit["Revision-checked Writes<br/>[edit.rs]"]
end

subgraph group_shared["Shared Runtime"]
  node_content["Content Loading<br/>[content.rs]"]
  node_adapters["Document Adapters<br/>[adapters.rs]"]
  node_fold["Index Folding<br/>[fold.rs]"]
  node_query["Query Filters"]
  node_output["Status and Output<br/>[output.rs]"]
end

node_agent(("User or Agent"))

node_agent -->|"invokes"| node_cli
node_agent -->|"connects"| node_mcp
node_cli -->|"dispatches"| node_fdcli
node_cli -->|"dispatches"| node_rgcli
node_cli -->|"dispatches"| node_readcli
node_cli -->|"dispatches"| node_editcli
node_cli -->|"dispatches"| node_indexcli
node_cli -->|"dispatches"| node_othercli
node_fdcli -->|"calls"| node_fd
node_rgcli -->|"calls"| node_rg
node_readcli -.->|"calls"| node_read
node_editcli -->|"calls"| node_editcmd
node_indexcli -->|"calls"| node_index
node_fd -->|"plans files"| node_scope
node_rg -->|"plans files"| node_scope
node_scope -->|"walks fresh files"| node_walk
node_scope -->|"checks candidates"| node_index
node_index -->|"opens segments"| node_segments
node_index -->|"uses queries"| node_indexreq
node_fd -->|"filters paths"| node_query
node_rg -->|"filters matches"| node_query
node_rg -->|"searches content"| node_content
node_read -->|"loads content"| node_content
node_content -->|"extracts documents"| node_adapters
node_read -->|"reads symbols"| node_code
node_outline -->|"extracts structure"| node_code
node_refs -->|"finds symbols"| node_code
node_rename -->|"resolves bindings"| node_scopes
node_refs -->|"resolves bindings"| node_scopes
node_ast -->|"parses syntax"| node_code
node_ast -->|"plans rewrites"| node_change
node_editcmd -->|"plans edits"| node_change
node_patch -->|"plans patches"| node_change
node_change -->|"writes changes"| node_edit
node_rename -->|"writes rename"| node_edit
node_editcmd -->|"checks current content"| node_read
node_index -->|"indexes files"| node_walk
node_indexreq -->|"folds index data"| node_fold
node_rg -->|"formats results"| node_output
node_change -->|"reports changes"| node_output
node_ast -->|"formats results"| node_output

click node_cli "https://github.com/cree1116/lancet/blob/main/src/cli/mod.rs"
click node_mcp "https://github.com/cree1116/lancet/blob/main/src/mcp.rs"
click node_fdcli "https://github.com/cree1116/lancet/blob/main/src/cli/fd.rs"
click node_rgcli "https://github.com/cree1116/lancet/blob/main/src/cli/rg.rs"
click node_readcli "https://github.com/cree1116/lancet/blob/main/src/cli/read.rs"
click node_editcli "https://github.com/cree1116/lancet/blob/main/src/cli/edit.rs"
click node_indexcli "https://github.com/cree1116/lancet/blob/main/src/cli/index.rs"
click node_othercli "https://github.com/cree1116/lancet/tree/main/src/cli"
click node_walk "https://github.com/cree1116/lancet/blob/main/src/walk.rs"
click node_scope "https://github.com/cree1116/lancet/blob/main/src/scope.rs"
click node_index "https://github.com/cree1116/lancet/blob/main/src/index/mod.rs"
click node_segments "https://github.com/cree1116/lancet/blob/main/src/index/segment.rs"
click node_indexreq "https://github.com/cree1116/lancet/blob/main/src/index/req.rs"
click node_rg "https://github.com/cree1116/lancet/blob/main/src/rg.rs"
click node_fd "https://github.com/cree1116/lancet/blob/main/src/fd.rs"
click node_ast "https://github.com/cree1116/lancet/blob/main/src/ast_grep.rs"
click node_read "https://github.com/cree1116/lancet/blob/main/src/read_cmd.rs"
click node_outline "https://github.com/cree1116/lancet/blob/main/src/outline.rs"
click node_refs "https://github.com/cree1116/lancet/blob/main/src/refs.rs"
click node_rename "https://github.com/cree1116/lancet/blob/main/src/rename.rs"
click node_code "https://github.com/cree1116/lancet/blob/main/src/code.rs"
click node_scopes "https://github.com/cree1116/lancet/blob/main/src/scopes.rs"
click node_editcmd "https://github.com/cree1116/lancet/blob/main/src/edit_cmd.rs"
click node_patch "https://github.com/cree1116/lancet/blob/main/src/patch.rs"
click node_change "https://github.com/cree1116/lancet/blob/main/src/change.rs"
click node_edit "https://github.com/cree1116/lancet/blob/main/src/edit.rs"
click node_content "https://github.com/cree1116/lancet/blob/main/src/content.rs"
click node_adapters "https://github.com/cree1116/lancet/blob/main/src/adapters.rs"
click node_fold "https://github.com/cree1116/lancet/blob/main/src/fold.rs"
click node_query "https://github.com/cree1116/lancet/tree/main/src/query"
click node_output "https://github.com/cree1116/lancet/blob/main/src/output.rs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_mcp,node_fdcli,node_rgcli,node_readcli,node_editcli,node_indexcli,node_othercli,node_agent toneBlue
class node_walk,node_scope,node_index,node_segments,node_indexreq toneAmber
class node_rg,node_fd,node_ast,node_read,node_outline,node_refs,node_rename,node_code,node_scopes toneMint
class node_editcmd,node_patch,node_change,node_edit toneRose
class node_content,node_adapters,node_fold,node_query,node_output toneIndigo
```

## Components

### Interfaces

- [CLI Dispatch](https://github.com/cree1116/lancet/blob/main/src/cli/mod.rs): `src/cli/mod.rs`
- [MCP Server](https://github.com/cree1116/lancet/blob/main/src/mcp.rs): `src/mcp.rs`
- [fd Command](https://github.com/cree1116/lancet/blob/main/src/cli/fd.rs): `src/cli/fd.rs`
- [rg Command](https://github.com/cree1116/lancet/blob/main/src/cli/rg.rs): `src/cli/rg.rs`
- [read Command](https://github.com/cree1116/lancet/blob/main/src/cli/read.rs): `src/cli/read.rs`
- [edit and write](https://github.com/cree1116/lancet/blob/main/src/cli/edit.rs): `src/cli/edit.rs`
- [index Command](https://github.com/cree1116/lancet/blob/main/src/cli/index.rs): `src/cli/index.rs`
- [Other Commands](https://github.com/cree1116/lancet/tree/main/src/cli): `src/cli`

### Discovery and Index

- [File Traversal](https://github.com/cree1116/lancet/blob/main/src/walk.rs): `src/walk.rs`
- [Candidate Planning](https://github.com/cree1116/lancet/blob/main/src/scope.rs): `src/scope.rs`
- [Trigram Index](https://github.com/cree1116/lancet/blob/main/src/index/mod.rs): `src/index/mod.rs`
- [Index Segments](https://github.com/cree1116/lancet/blob/main/src/index/segment.rs): `src/index/segment.rs`
- [Index Queries](https://github.com/cree1116/lancet/blob/main/src/index/req.rs): `src/index/req.rs`

### Search and Inspection

- [Text Search](https://github.com/cree1116/lancet/blob/main/src/rg.rs): `src/rg.rs`
- [File Search](https://github.com/cree1116/lancet/blob/main/src/fd.rs): `src/fd.rs`
- [AST Search and Rewrite](https://github.com/cree1116/lancet/blob/main/src/ast_grep.rs): `src/ast_grep.rs`
- [Range and Symbol Read](https://github.com/cree1116/lancet/blob/main/src/read_cmd.rs): `src/read_cmd.rs`
- [Outline](https://github.com/cree1116/lancet/blob/main/src/outline.rs): `src/outline.rs`
- [References](https://github.com/cree1116/lancet/blob/main/src/refs.rs): `src/refs.rs`
- [Scoped Rename](https://github.com/cree1116/lancet/blob/main/src/rename.rs): `src/rename.rs`
- [Syntax Structure](https://github.com/cree1116/lancet/blob/main/src/code.rs): `src/code.rs`
- [Scope Resolution](https://github.com/cree1116/lancet/blob/main/src/scopes.rs): `src/scopes.rs`

### Safe Changes

- [Edit Operations](https://github.com/cree1116/lancet/blob/main/src/edit_cmd.rs): `src/edit_cmd.rs`
- [Multi-file Patch](https://github.com/cree1116/lancet/blob/main/src/patch.rs): `src/patch.rs`
- [Change Planning](https://github.com/cree1116/lancet/blob/main/src/change.rs): `src/change.rs`
- [Revision-checked Writes](https://github.com/cree1116/lancet/blob/main/src/edit.rs): `src/edit.rs`

### Shared Runtime

- [Content Loading](https://github.com/cree1116/lancet/blob/main/src/content.rs): `src/content.rs`
- [Document Adapters](https://github.com/cree1116/lancet/blob/main/src/adapters.rs): `src/adapters.rs`
- [Index Folding](https://github.com/cree1116/lancet/blob/main/src/fold.rs): `src/fold.rs`
- [Query Filters](https://github.com/cree1116/lancet/tree/main/src/query): `src/query`
- [Status and Output](https://github.com/cree1116/lancet/blob/main/src/output.rs): `src/output.rs`

### Other components

- **User or Agent**

## Connections

- User or Agent → CLI Dispatch: invokes
- User or Agent → MCP Server: connects
- CLI Dispatch → fd Command: dispatches (evidence: `src/cli/mod.rs`)
- CLI Dispatch → rg Command: dispatches (evidence: `src/cli/mod.rs`)
- CLI Dispatch → read Command: dispatches (evidence: `src/cli/mod.rs`)
- CLI Dispatch → edit and write: dispatches (evidence: `src/cli/mod.rs`)
- CLI Dispatch → index Command: dispatches (evidence: `src/cli/mod.rs`)
- CLI Dispatch → Other Commands: dispatches (evidence: `src/cli/mod.rs`)
- fd Command → File Search: calls (evidence: `src/cli/fd.rs`)
- rg Command → Text Search: calls (evidence: `src/cli/rg.rs`)
- read Command → Range and Symbol Read: calls
- edit and write → Edit Operations: calls (evidence: `src/cli/edit.rs`)
- index Command → Trigram Index: calls (evidence: `src/cli/index.rs`)
- File Search → Candidate Planning: plans files (evidence: `src/fd.rs`)
- Text Search → Candidate Planning: plans files (evidence: `src/rg.rs`)
- Candidate Planning → File Traversal: walks fresh files (evidence: `src/scope.rs`)
- Candidate Planning → Trigram Index: checks candidates (evidence: `src/scope.rs`)
- Trigram Index → Index Segments: opens segments (evidence: `src/index/mod.rs`)
- Trigram Index → Index Queries: uses queries (evidence: `src/index/mod.rs`)
- File Search → Query Filters: filters paths (evidence: `src/fd.rs`)
- Text Search → Query Filters: filters matches (evidence: `src/rg.rs`)
- Text Search → Content Loading: searches content (evidence: `src/rg.rs`)
- Range and Symbol Read → Content Loading: loads content (evidence: `src/read_cmd.rs`)
- Content Loading → Document Adapters: extracts documents (evidence: `src/content.rs`)
- Range and Symbol Read → Syntax Structure: reads symbols (evidence: `src/read_cmd.rs`)
- Outline → Syntax Structure: extracts structure (evidence: `src/outline.rs`)
- References → Syntax Structure: finds symbols (evidence: `src/refs.rs`)
- Scoped Rename → Scope Resolution: resolves bindings (evidence: `src/rename.rs`)
- References → Scope Resolution: resolves bindings (evidence: `src/scopes.rs`)
- AST Search and Rewrite → Syntax Structure: parses syntax (evidence: `src/ast_grep.rs`)
- AST Search and Rewrite → Change Planning: plans rewrites (evidence: `src/ast_grep.rs`)
- Edit Operations → Change Planning: plans edits (evidence: `src/edit_cmd.rs`)
- Multi-file Patch → Change Planning: plans patches (evidence: `src/patch.rs`)
- Change Planning → Revision-checked Writes: writes changes (evidence: `src/change.rs`)
- Scoped Rename → Revision-checked Writes: writes rename (evidence: `src/rename.rs`)
- Edit Operations → Range and Symbol Read: checks current content (evidence: `src/edit_cmd.rs`)
- Trigram Index → File Traversal: indexes files (evidence: `src/index/mod.rs`)
- Index Queries → Index Folding: folds index data (evidence: `src/index/req.rs`)
- Text Search → Status and Output: formats results (evidence: `src/rg.rs`)
- Change Planning → Status and Output: reports changes (evidence: `src/change.rs`)
- AST Search and Rewrite → Status and Output: formats results (evidence: `src/ast_grep.rs`)
