docgraphical 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- docgraphical-1.0.0/LICENSE +21 -0
- docgraphical-1.0.0/PKG-INFO +303 -0
- docgraphical-1.0.0/README.md +273 -0
- docgraphical-1.0.0/docgraph/__init__.py +13 -0
- docgraphical-1.0.0/docgraph/cli.py +61 -0
- docgraphical-1.0.0/docgraph/config.py +66 -0
- docgraphical-1.0.0/docgraph/constants.py +13 -0
- docgraphical-1.0.0/docgraph/db.py +300 -0
- docgraphical-1.0.0/docgraph/mcp_server.py +69 -0
- docgraphical-1.0.0/docgraph/parser.py +209 -0
- docgraphical-1.0.0/docgraph/scanner.py +113 -0
- docgraphical-1.0.0/docgraph/server.py +187 -0
- docgraphical-1.0.0/docgraphical/__init__.py +13 -0
- docgraphical-1.0.0/docgraphical/cli.py +61 -0
- docgraphical-1.0.0/docgraphical/config.py +112 -0
- docgraphical-1.0.0/docgraphical/constants.py +13 -0
- docgraphical-1.0.0/docgraphical/db.py +355 -0
- docgraphical-1.0.0/docgraphical/mcp_server.py +69 -0
- docgraphical-1.0.0/docgraphical/parser.py +209 -0
- docgraphical-1.0.0/docgraphical/scanner.py +118 -0
- docgraphical-1.0.0/docgraphical/server.py +219 -0
- docgraphical-1.0.0/docgraphical.egg-info/PKG-INFO +303 -0
- docgraphical-1.0.0/docgraphical.egg-info/SOURCES.txt +28 -0
- docgraphical-1.0.0/docgraphical.egg-info/dependency_links.txt +1 -0
- docgraphical-1.0.0/docgraphical.egg-info/entry_points.txt +4 -0
- docgraphical-1.0.0/docgraphical.egg-info/requires.txt +7 -0
- docgraphical-1.0.0/docgraphical.egg-info/top_level.txt +2 -0
- docgraphical-1.0.0/pyproject.toml +46 -0
- docgraphical-1.0.0/setup.cfg +4 -0
- docgraphical-1.0.0/tests/test_docgraphical.py +92 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chunghsing Tech / CodeGraph Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docgraphical
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Deterministic Markdown AST analyzer, TOC outline & surgical section slicer for AI Agents. Save 97% tokens.
|
|
5
|
+
Author-email: Chunghsing Tech / CodeGraph Team <a1081@chenbro.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/dardeaw/docgraphical
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/dardeaw/docgraphical/issues
|
|
9
|
+
Keywords: docgraphical,docgraph,markdown,ast,toc,ai-agent,mcp,llm-tokens,rag
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Provides-Extra: mcp
|
|
25
|
+
Requires-Dist: mcp>=1.0.0; extra == "mcp"
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
28
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# DocGraphical
|
|
32
|
+
|
|
33
|
+
A deterministic Markdown Abstract Syntax Tree (AST) analyzer, surgical section slicer, and 3D visual knowledge graph studio designed for LLM coding agents, RAG pipelines, and enterprise engineering workflows.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Overview
|
|
38
|
+
|
|
39
|
+
When Large Language Model (LLM) coding agents (such as Claude Code, Cursor, Windsurf, or Antigravity) inspect extensive Markdown files (e.g., product requirement documents, architecture specifications, design systems), standard tooling typically loads entire files into the model's context window.
|
|
40
|
+
|
|
41
|
+
This approach introduces several practical challenges:
|
|
42
|
+
|
|
43
|
+
1. **Context Window Saturation**: Reading large multi-thousand-line documents consumes 10,000 to 40,000 tokens per interaction, accelerating context exhaustion and driving up operational inference costs.
|
|
44
|
+
2. **Context Dilution ("Lost in the Middle")**: Flooding the context window with unrelated sections reduces attention density on target instructions, increasing the likelihood of hallucination.
|
|
45
|
+
3. **Imprecise RAG Chunking**: Naive fixed-size text splitters frequently sever code fences, mathematical formulas, and hierarchical heading relationships.
|
|
46
|
+
|
|
47
|
+
**DocGraphical** addresses these issues through AST-aware Markdown analysis:
|
|
48
|
+
|
|
49
|
+
- **Outline First (TOC Extraction)**: Extracts hierarchical headings with exact line anchors (~30 to 50 tokens), allowing agents to pinpoint target sections before reading.
|
|
50
|
+
- **Surgical Section Slicing**: Slices the exact boundary of a requested section (including all child sub-headings and code blocks) without reading preceding or succeeding chapters (~100 to 300 tokens).
|
|
51
|
+
- **Fenced Code Block Protection**: Guarantees that hash symbols (`#`) inside code blocks (e.g., Python comments, Bash scripts) are never misinterpreted as headings.
|
|
52
|
+
- **Knowledge Graph & Cross-Reference Mapping**: Maps relationships and cross-document markdown links into a lightweight local SQLite graph database (`.docgraphical/docgraphical.db`).
|
|
53
|
+
- **3D Visual AST Studio**: Interactive WebGL force-directed graph with slot-based stage swap, immediate ancestor centering, dynamic SpriteText shrine labels, and subtle translucent galactic depth.
|
|
54
|
+
- **Model Context Protocol (MCP) Native**: Exposes standard tools for automated integration with MCP-compatible agent environments via stdio JSON-RPC.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Token Economy Comparison
|
|
59
|
+
|
|
60
|
+
| Operation | Traditional File Read | Vector / Naive Splitter | DocGraphical (AST Slice) |
|
|
61
|
+
| :--- | :--- | :--- | :--- |
|
|
62
|
+
| **Inspect 1,500-line Spec** | ~18,000 tokens | ~2,500 tokens (lossy) | **~150 tokens** |
|
|
63
|
+
| **Hierarchy Preservation** | Full (High Token Cost) | Fragmented | **Strict AST Maintained** |
|
|
64
|
+
| **Code Block Integrity** | Full | Frequently Severed | **Guaranteed Intact** |
|
|
65
|
+
| **Context Noise** | High | Medium | **Zero Irrelevant Text** |
|
|
66
|
+
| **Token Savings** | 0% | ~85% | **~97.4%** |
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Installation
|
|
71
|
+
|
|
72
|
+
### Python Package (CLI & Library)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Basic installation
|
|
76
|
+
pip install docgraphical
|
|
77
|
+
|
|
78
|
+
# Installation with MCP server support
|
|
79
|
+
pip install "docgraphical[mcp]"
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Node.js / Desktop Application
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Global CLI via npm
|
|
86
|
+
npm install -g docgraphical
|
|
87
|
+
|
|
88
|
+
# Run Desktop Studio locally
|
|
89
|
+
git clone https://github.com/dardeaw/docgraphical.git
|
|
90
|
+
cd docgraphical
|
|
91
|
+
npm install
|
|
92
|
+
npm start
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Quick Start (CLI)
|
|
98
|
+
|
|
99
|
+
Both `docgraphical` and the short alias `docg` are supported:
|
|
100
|
+
|
|
101
|
+
### 1. Extract Table of Contents (TOC)
|
|
102
|
+
|
|
103
|
+
Generates a compact outline with line numbers for any Markdown file:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
docgraphical toc docs/architecture.md
|
|
107
|
+
# Or using short alias:
|
|
108
|
+
docg toc docs/architecture.md
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Output:
|
|
112
|
+
```text
|
|
113
|
+
=== [DocGraphical TOC] architecture.md ===
|
|
114
|
+
[Line 1] # Architecture Overview
|
|
115
|
+
[Line 24] ## 1. Storage Subsystem
|
|
116
|
+
[Line 58] ### 1.1 Write-Ahead Logging (WAL)
|
|
117
|
+
[Line 112] ### 1.2 LSM-Tree Compaction
|
|
118
|
+
[Line 180] ## 2. Distributed Consensus Protocol
|
|
119
|
+
[Line 245] ## 3. Network Transport Layer
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
JSON format is also supported for programmatic agent workflows:
|
|
123
|
+
```bash
|
|
124
|
+
docg toc docs/architecture.md --format json
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### 2. Surgically Slice a Section
|
|
128
|
+
|
|
129
|
+
Extracts only the specified chapter and stops precisely before the next heading of equal or higher rank:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
docg section docs/architecture.md "1. Storage Subsystem"
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
To extract only the heading body without its child sub-sections:
|
|
136
|
+
```bash
|
|
137
|
+
docg section docs/architecture.md "1. Storage Subsystem" --no-subsections
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 3. Search Keywords Across Documents
|
|
141
|
+
|
|
142
|
+
Searches documentation with exact line numbers and contextual snippets:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
docg search docs/ "compaction"
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 4. Build Repository Knowledge Graph
|
|
149
|
+
|
|
150
|
+
Scans a repository, parses all Markdown files into AST nodes and cross-document links, and stores the graph in `.docgraphical/docgraphical.db`:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
docg index .
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### 5. Launch Web Studio & 3D Knowledge Galaxy
|
|
157
|
+
|
|
158
|
+
Starts the local HTTP server and opens the visual inspection interface:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
docg serve --port 5002
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## 3D Visual AST Workstation
|
|
167
|
+
|
|
168
|
+
DocGraphical includes a high-performance 3D WebGL knowledge galaxy designed for structural exploration:
|
|
169
|
+
|
|
170
|
+
1. **Slot-Based Stage Swap**: Instant DOM-level swapping between the central Markdown Reader and the 3D Knowledge Graph without altering column proportions.
|
|
171
|
+
2. **Immediate Ancestor Centering (1-Level Parent Focus)**: Selecting a sub-section (H2, H3, H4) centers the camera directly on its immediate parent section (H1/H2), providing intuitive hierarchical context.
|
|
172
|
+
3. **Dynamic SpriteText Shrine Reveal**: Floating 3D text billboards preserve authentic AST color tokens and illuminate upon selection, while unselected background nodes transition smoothly to subtle translucent ghosting.
|
|
173
|
+
4. **Contextual Ancestor Tracing**: Clicking any deep AST node highlights the entire ancestral lineage back to the root Document node.
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Model Context Protocol (MCP) Integration
|
|
178
|
+
|
|
179
|
+
DocGraphical provides native support for the Model Context Protocol (MCP), allowing AI agents to query documentation structures via standard stdio JSON-RPC.
|
|
180
|
+
|
|
181
|
+
### Configuration (`mcp_config.json` / Claude Desktop / Cursor / Antigravity)
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"mcpServers": {
|
|
186
|
+
"docgraphical": {
|
|
187
|
+
"command": "python",
|
|
188
|
+
"args": ["-m", "docgraphical.cli", "mcp"]
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
### Available MCP Tools
|
|
195
|
+
|
|
196
|
+
| Tool Name | Parameters | Description |
|
|
197
|
+
| :--- | :--- | :--- |
|
|
198
|
+
| `docgraphical_toc` | `filePath` (string), `format` (text/json) | Returns heading outline with line numbers (~30 tokens). |
|
|
199
|
+
| `docgraphical_section` | `filePath` (string), `heading` (string), `includeSubsections` (bool) | Extracts verbatim content of target section (~100 tokens). |
|
|
200
|
+
| `docgraphical_search` | `filePath` (string), `query` (string), `limit` (int) | Fast regex-based keyword search within file or directory. |
|
|
201
|
+
| `docgraphical_graph` | `repoPath` (string) | Returns AST node graph and cross-document link relations. |
|
|
202
|
+
| `docgraphical_index` | `repoPath` (string) | Refreshes and rebuilds the SQLite AST index for a repository. |
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
## Python API Reference
|
|
207
|
+
|
|
208
|
+
DocGraphical can be imported directly into Python applications and automated scripts:
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from docgraphical.parser import parse_headings, extract_toc, extract_section, search_file
|
|
212
|
+
|
|
213
|
+
# 1. Parse AST Headings
|
|
214
|
+
headings = parse_headings("docs/spec.md")
|
|
215
|
+
for h in headings:
|
|
216
|
+
print(f"L{h['line']} [{h['level']}] {h['title']}")
|
|
217
|
+
|
|
218
|
+
# 2. Extract TOC
|
|
219
|
+
toc_text = extract_toc("docs/spec.md", output_format="text")
|
|
220
|
+
print(toc_text)
|
|
221
|
+
|
|
222
|
+
# 3. Surgically Slice Section
|
|
223
|
+
section_content = extract_section("docs/spec.md", target_heading="1. Storage Subsystem")
|
|
224
|
+
print(section_content)
|
|
225
|
+
|
|
226
|
+
# 4. Search File
|
|
227
|
+
matches = search_file("docs/spec.md", query="LSM-Tree")
|
|
228
|
+
for m in matches:
|
|
229
|
+
print(f"Line {m['line']}: {m['content']}")
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## Node.js API Reference
|
|
235
|
+
|
|
236
|
+
DocGraphical is also available as a standalone Node.js module:
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
const { parseHeadings, extractToc, extractSection, searchDoc } = require('docgraphical');
|
|
240
|
+
|
|
241
|
+
// 1. Extract TOC outline
|
|
242
|
+
const toc = extractToc('docs/spec.md');
|
|
243
|
+
console.log(toc);
|
|
244
|
+
|
|
245
|
+
// 2. Surgical section slice
|
|
246
|
+
const slice = extractSection('docs/spec.md', '1. Storage Subsystem', { includeSubsections: true });
|
|
247
|
+
console.log(slice);
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Architecture & Design Principles
|
|
253
|
+
|
|
254
|
+
DocGraphical is built upon the following core design principles:
|
|
255
|
+
|
|
256
|
+
1. **Zero External Runtime Dependencies (Core Library)**: The core parser and scanner rely solely on standard Python libraries (`re`, `sqlite3`, `pathlib`), ensuring zero friction for enterprise and air-gapped environments.
|
|
257
|
+
2. **State Machine AST Parsing**: Markdown documents are processed through a line-by-line state machine that tracks fenced code block states (```` ``` ```` and `~~~`), preventing false positive heading detections.
|
|
258
|
+
3. **Deterministic Section Boundary Slicing**: Slicing calculates exact line offsets based on AST heading depth rather than heuristic text matching.
|
|
259
|
+
4. **Relational Graph Storage**: Nodes (Files, H1-H6 Headings) and Edges (Parent-Child containment, Markdown hyperlinks) are indexed into SQLite with B-Tree indices for sub-millisecond graph queries.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
263
|
+
## Repository Structure
|
|
264
|
+
|
|
265
|
+
```text
|
|
266
|
+
docgraphical/
|
|
267
|
+
├── docgraphical/ # Python core package
|
|
268
|
+
│ ├── __init__.py # Package entry & exports
|
|
269
|
+
│ ├── cli.py # CLI argument parser (docgraphical / docg)
|
|
270
|
+
│ ├── config.py # Path & environment configuration
|
|
271
|
+
│ ├── constants.py # AST node kinds & edge types
|
|
272
|
+
│ ├── db.py # SQLite schema & query engine
|
|
273
|
+
│ ├── mcp_server.py # Model Context Protocol stdio server
|
|
274
|
+
│ ├── parser.py # Markdown AST parser & section slicer
|
|
275
|
+
│ ├── scanner.py # Multi-document repository scanner
|
|
276
|
+
│ └── server.py # Web Studio HTTP server
|
|
277
|
+
├── electron/ # Desktop application wrapper
|
|
278
|
+
│ ├── main.js # Electron main process
|
|
279
|
+
│ └── preload.js # Secure context bridge
|
|
280
|
+
├── static/ # Web Studio assets
|
|
281
|
+
│ ├── docgraph.js # Frontend graph controller
|
|
282
|
+
│ └── galaxy.css # Visual theme & layout
|
|
283
|
+
├── templates/ # Jinja2 web templates
|
|
284
|
+
│ └── index.html # Web Studio interface
|
|
285
|
+
├── tests/ # Unit & integration test suite
|
|
286
|
+
│ └── test_docgraphical.py # Pytest test cases
|
|
287
|
+
├── pyproject.toml # Python build & dependency metadata
|
|
288
|
+
├── package.json # Node.js & Electron configuration
|
|
289
|
+
├── LICENSE # MIT License
|
|
290
|
+
└── README.md # Project documentation
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Contributing
|
|
296
|
+
|
|
297
|
+
Contributions are welcome. Please refer to [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on code formatting, running test suites, and submitting pull requests.
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## License
|
|
302
|
+
|
|
303
|
+
DocGraphical is open-source software licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# DocGraphical
|
|
2
|
+
|
|
3
|
+
A deterministic Markdown Abstract Syntax Tree (AST) analyzer, surgical section slicer, and 3D visual knowledge graph studio designed for LLM coding agents, RAG pipelines, and enterprise engineering workflows.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
When Large Language Model (LLM) coding agents (such as Claude Code, Cursor, Windsurf, or Antigravity) inspect extensive Markdown files (e.g., product requirement documents, architecture specifications, design systems), standard tooling typically loads entire files into the model's context window.
|
|
10
|
+
|
|
11
|
+
This approach introduces several practical challenges:
|
|
12
|
+
|
|
13
|
+
1. **Context Window Saturation**: Reading large multi-thousand-line documents consumes 10,000 to 40,000 tokens per interaction, accelerating context exhaustion and driving up operational inference costs.
|
|
14
|
+
2. **Context Dilution ("Lost in the Middle")**: Flooding the context window with unrelated sections reduces attention density on target instructions, increasing the likelihood of hallucination.
|
|
15
|
+
3. **Imprecise RAG Chunking**: Naive fixed-size text splitters frequently sever code fences, mathematical formulas, and hierarchical heading relationships.
|
|
16
|
+
|
|
17
|
+
**DocGraphical** addresses these issues through AST-aware Markdown analysis:
|
|
18
|
+
|
|
19
|
+
- **Outline First (TOC Extraction)**: Extracts hierarchical headings with exact line anchors (~30 to 50 tokens), allowing agents to pinpoint target sections before reading.
|
|
20
|
+
- **Surgical Section Slicing**: Slices the exact boundary of a requested section (including all child sub-headings and code blocks) without reading preceding or succeeding chapters (~100 to 300 tokens).
|
|
21
|
+
- **Fenced Code Block Protection**: Guarantees that hash symbols (`#`) inside code blocks (e.g., Python comments, Bash scripts) are never misinterpreted as headings.
|
|
22
|
+
- **Knowledge Graph & Cross-Reference Mapping**: Maps relationships and cross-document markdown links into a lightweight local SQLite graph database (`.docgraphical/docgraphical.db`).
|
|
23
|
+
- **3D Visual AST Studio**: Interactive WebGL force-directed graph with slot-based stage swap, immediate ancestor centering, dynamic SpriteText shrine labels, and subtle translucent galactic depth.
|
|
24
|
+
- **Model Context Protocol (MCP) Native**: Exposes standard tools for automated integration with MCP-compatible agent environments via stdio JSON-RPC.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Token Economy Comparison
|
|
29
|
+
|
|
30
|
+
| Operation | Traditional File Read | Vector / Naive Splitter | DocGraphical (AST Slice) |
|
|
31
|
+
| :--- | :--- | :--- | :--- |
|
|
32
|
+
| **Inspect 1,500-line Spec** | ~18,000 tokens | ~2,500 tokens (lossy) | **~150 tokens** |
|
|
33
|
+
| **Hierarchy Preservation** | Full (High Token Cost) | Fragmented | **Strict AST Maintained** |
|
|
34
|
+
| **Code Block Integrity** | Full | Frequently Severed | **Guaranteed Intact** |
|
|
35
|
+
| **Context Noise** | High | Medium | **Zero Irrelevant Text** |
|
|
36
|
+
| **Token Savings** | 0% | ~85% | **~97.4%** |
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
### Python Package (CLI & Library)
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Basic installation
|
|
46
|
+
pip install docgraphical
|
|
47
|
+
|
|
48
|
+
# Installation with MCP server support
|
|
49
|
+
pip install "docgraphical[mcp]"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Node.js / Desktop Application
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Global CLI via npm
|
|
56
|
+
npm install -g docgraphical
|
|
57
|
+
|
|
58
|
+
# Run Desktop Studio locally
|
|
59
|
+
git clone https://github.com/dardeaw/docgraphical.git
|
|
60
|
+
cd docgraphical
|
|
61
|
+
npm install
|
|
62
|
+
npm start
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Quick Start (CLI)
|
|
68
|
+
|
|
69
|
+
Both `docgraphical` and the short alias `docg` are supported:
|
|
70
|
+
|
|
71
|
+
### 1. Extract Table of Contents (TOC)
|
|
72
|
+
|
|
73
|
+
Generates a compact outline with line numbers for any Markdown file:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
docgraphical toc docs/architecture.md
|
|
77
|
+
# Or using short alias:
|
|
78
|
+
docg toc docs/architecture.md
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Output:
|
|
82
|
+
```text
|
|
83
|
+
=== [DocGraphical TOC] architecture.md ===
|
|
84
|
+
[Line 1] # Architecture Overview
|
|
85
|
+
[Line 24] ## 1. Storage Subsystem
|
|
86
|
+
[Line 58] ### 1.1 Write-Ahead Logging (WAL)
|
|
87
|
+
[Line 112] ### 1.2 LSM-Tree Compaction
|
|
88
|
+
[Line 180] ## 2. Distributed Consensus Protocol
|
|
89
|
+
[Line 245] ## 3. Network Transport Layer
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
JSON format is also supported for programmatic agent workflows:
|
|
93
|
+
```bash
|
|
94
|
+
docg toc docs/architecture.md --format json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### 2. Surgically Slice a Section
|
|
98
|
+
|
|
99
|
+
Extracts only the specified chapter and stops precisely before the next heading of equal or higher rank:
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
docg section docs/architecture.md "1. Storage Subsystem"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
To extract only the heading body without its child sub-sections:
|
|
106
|
+
```bash
|
|
107
|
+
docg section docs/architecture.md "1. Storage Subsystem" --no-subsections
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 3. Search Keywords Across Documents
|
|
111
|
+
|
|
112
|
+
Searches documentation with exact line numbers and contextual snippets:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
docg search docs/ "compaction"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 4. Build Repository Knowledge Graph
|
|
119
|
+
|
|
120
|
+
Scans a repository, parses all Markdown files into AST nodes and cross-document links, and stores the graph in `.docgraphical/docgraphical.db`:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
docg index .
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 5. Launch Web Studio & 3D Knowledge Galaxy
|
|
127
|
+
|
|
128
|
+
Starts the local HTTP server and opens the visual inspection interface:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
docg serve --port 5002
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 3D Visual AST Workstation
|
|
137
|
+
|
|
138
|
+
DocGraphical includes a high-performance 3D WebGL knowledge galaxy designed for structural exploration:
|
|
139
|
+
|
|
140
|
+
1. **Slot-Based Stage Swap**: Instant DOM-level swapping between the central Markdown Reader and the 3D Knowledge Graph without altering column proportions.
|
|
141
|
+
2. **Immediate Ancestor Centering (1-Level Parent Focus)**: Selecting a sub-section (H2, H3, H4) centers the camera directly on its immediate parent section (H1/H2), providing intuitive hierarchical context.
|
|
142
|
+
3. **Dynamic SpriteText Shrine Reveal**: Floating 3D text billboards preserve authentic AST color tokens and illuminate upon selection, while unselected background nodes transition smoothly to subtle translucent ghosting.
|
|
143
|
+
4. **Contextual Ancestor Tracing**: Clicking any deep AST node highlights the entire ancestral lineage back to the root Document node.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Model Context Protocol (MCP) Integration
|
|
148
|
+
|
|
149
|
+
DocGraphical provides native support for the Model Context Protocol (MCP), allowing AI agents to query documentation structures via standard stdio JSON-RPC.
|
|
150
|
+
|
|
151
|
+
### Configuration (`mcp_config.json` / Claude Desktop / Cursor / Antigravity)
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"mcpServers": {
|
|
156
|
+
"docgraphical": {
|
|
157
|
+
"command": "python",
|
|
158
|
+
"args": ["-m", "docgraphical.cli", "mcp"]
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Available MCP Tools
|
|
165
|
+
|
|
166
|
+
| Tool Name | Parameters | Description |
|
|
167
|
+
| :--- | :--- | :--- |
|
|
168
|
+
| `docgraphical_toc` | `filePath` (string), `format` (text/json) | Returns heading outline with line numbers (~30 tokens). |
|
|
169
|
+
| `docgraphical_section` | `filePath` (string), `heading` (string), `includeSubsections` (bool) | Extracts verbatim content of target section (~100 tokens). |
|
|
170
|
+
| `docgraphical_search` | `filePath` (string), `query` (string), `limit` (int) | Fast regex-based keyword search within file or directory. |
|
|
171
|
+
| `docgraphical_graph` | `repoPath` (string) | Returns AST node graph and cross-document link relations. |
|
|
172
|
+
| `docgraphical_index` | `repoPath` (string) | Refreshes and rebuilds the SQLite AST index for a repository. |
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
## Python API Reference
|
|
177
|
+
|
|
178
|
+
DocGraphical can be imported directly into Python applications and automated scripts:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from docgraphical.parser import parse_headings, extract_toc, extract_section, search_file
|
|
182
|
+
|
|
183
|
+
# 1. Parse AST Headings
|
|
184
|
+
headings = parse_headings("docs/spec.md")
|
|
185
|
+
for h in headings:
|
|
186
|
+
print(f"L{h['line']} [{h['level']}] {h['title']}")
|
|
187
|
+
|
|
188
|
+
# 2. Extract TOC
|
|
189
|
+
toc_text = extract_toc("docs/spec.md", output_format="text")
|
|
190
|
+
print(toc_text)
|
|
191
|
+
|
|
192
|
+
# 3. Surgically Slice Section
|
|
193
|
+
section_content = extract_section("docs/spec.md", target_heading="1. Storage Subsystem")
|
|
194
|
+
print(section_content)
|
|
195
|
+
|
|
196
|
+
# 4. Search File
|
|
197
|
+
matches = search_file("docs/spec.md", query="LSM-Tree")
|
|
198
|
+
for m in matches:
|
|
199
|
+
print(f"Line {m['line']}: {m['content']}")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## Node.js API Reference
|
|
205
|
+
|
|
206
|
+
DocGraphical is also available as a standalone Node.js module:
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
const { parseHeadings, extractToc, extractSection, searchDoc } = require('docgraphical');
|
|
210
|
+
|
|
211
|
+
// 1. Extract TOC outline
|
|
212
|
+
const toc = extractToc('docs/spec.md');
|
|
213
|
+
console.log(toc);
|
|
214
|
+
|
|
215
|
+
// 2. Surgical section slice
|
|
216
|
+
const slice = extractSection('docs/spec.md', '1. Storage Subsystem', { includeSubsections: true });
|
|
217
|
+
console.log(slice);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Architecture & Design Principles
|
|
223
|
+
|
|
224
|
+
DocGraphical is built upon the following core design principles:
|
|
225
|
+
|
|
226
|
+
1. **Zero External Runtime Dependencies (Core Library)**: The core parser and scanner rely solely on standard Python libraries (`re`, `sqlite3`, `pathlib`), ensuring zero friction for enterprise and air-gapped environments.
|
|
227
|
+
2. **State Machine AST Parsing**: Markdown documents are processed through a line-by-line state machine that tracks fenced code block states (```` ``` ```` and `~~~`), preventing false positive heading detections.
|
|
228
|
+
3. **Deterministic Section Boundary Slicing**: Slicing calculates exact line offsets based on AST heading depth rather than heuristic text matching.
|
|
229
|
+
4. **Relational Graph Storage**: Nodes (Files, H1-H6 Headings) and Edges (Parent-Child containment, Markdown hyperlinks) are indexed into SQLite with B-Tree indices for sub-millisecond graph queries.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Repository Structure
|
|
234
|
+
|
|
235
|
+
```text
|
|
236
|
+
docgraphical/
|
|
237
|
+
├── docgraphical/ # Python core package
|
|
238
|
+
│ ├── __init__.py # Package entry & exports
|
|
239
|
+
│ ├── cli.py # CLI argument parser (docgraphical / docg)
|
|
240
|
+
│ ├── config.py # Path & environment configuration
|
|
241
|
+
│ ├── constants.py # AST node kinds & edge types
|
|
242
|
+
│ ├── db.py # SQLite schema & query engine
|
|
243
|
+
│ ├── mcp_server.py # Model Context Protocol stdio server
|
|
244
|
+
│ ├── parser.py # Markdown AST parser & section slicer
|
|
245
|
+
│ ├── scanner.py # Multi-document repository scanner
|
|
246
|
+
│ └── server.py # Web Studio HTTP server
|
|
247
|
+
├── electron/ # Desktop application wrapper
|
|
248
|
+
│ ├── main.js # Electron main process
|
|
249
|
+
│ └── preload.js # Secure context bridge
|
|
250
|
+
├── static/ # Web Studio assets
|
|
251
|
+
│ ├── docgraph.js # Frontend graph controller
|
|
252
|
+
│ └── galaxy.css # Visual theme & layout
|
|
253
|
+
├── templates/ # Jinja2 web templates
|
|
254
|
+
│ └── index.html # Web Studio interface
|
|
255
|
+
├── tests/ # Unit & integration test suite
|
|
256
|
+
│ └── test_docgraphical.py # Pytest test cases
|
|
257
|
+
├── pyproject.toml # Python build & dependency metadata
|
|
258
|
+
├── package.json # Node.js & Electron configuration
|
|
259
|
+
├── LICENSE # MIT License
|
|
260
|
+
└── README.md # Project documentation
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
## Contributing
|
|
266
|
+
|
|
267
|
+
Contributions are welcome. Please refer to [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on code formatting, running test suites, and submitting pull requests.
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## License
|
|
272
|
+
|
|
273
|
+
DocGraphical is open-source software licensed under the [MIT License](LICENSE).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# DocGraphical Package Entry
|
|
2
|
+
from .parser import parse_headings, extract_toc, extract_section, search_doc
|
|
3
|
+
|
|
4
|
+
search_file = search_doc
|
|
5
|
+
|
|
6
|
+
__version__ = "1.0.0"
|
|
7
|
+
__all__ = [
|
|
8
|
+
"parse_headings",
|
|
9
|
+
"extract_toc",
|
|
10
|
+
"extract_section",
|
|
11
|
+
"search_doc",
|
|
12
|
+
"search_file",
|
|
13
|
+
]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""DocGraph Command Line Interface (CLI)."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
from docgraph import __version__
|
|
6
|
+
from docgraph.parser import extract_toc, extract_section, search_doc
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
parser = argparse.ArgumentParser(
|
|
11
|
+
prog="docgraph",
|
|
12
|
+
description="DocGraph: Precision Markdown AST, TOC & Section Slicer for AI Agents & Developers."
|
|
13
|
+
)
|
|
14
|
+
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}")
|
|
15
|
+
|
|
16
|
+
subparsers = parser.add_subparsers(dest="command", help="Available subcommands")
|
|
17
|
+
|
|
18
|
+
# Command: toc
|
|
19
|
+
toc_parser = subparsers.add_parser("toc", help="Extract Table of Contents (TOC) with line numbers")
|
|
20
|
+
toc_parser.add_argument("file", help="Path to the Markdown file")
|
|
21
|
+
toc_parser.add_argument("--json", action="store_true", help="Output TOC as JSON format")
|
|
22
|
+
toc_parser.add_argument("--md", action="store_true", help="Output TOC as Markdown list")
|
|
23
|
+
|
|
24
|
+
# Command: section
|
|
25
|
+
sec_parser = subparsers.add_parser("section", help="Extract a specific section by heading")
|
|
26
|
+
sec_parser.add_argument("file", help="Path to the Markdown file")
|
|
27
|
+
sec_parser.add_argument("heading", help="Target heading title (e.g. 'Installation' or '## API')")
|
|
28
|
+
sec_parser.add_argument("--no-sub", action="store_true", help="Exclude subsections under this heading")
|
|
29
|
+
|
|
30
|
+
# Command: search
|
|
31
|
+
search_parser = subparsers.add_parser("search", help="Search keywords across Markdown file or folder")
|
|
32
|
+
search_parser.add_argument("path", help="Path to Markdown file or root directory")
|
|
33
|
+
search_parser.add_argument("query", help="Search keyword or term")
|
|
34
|
+
search_parser.add_argument("--limit", type=int, default=30, help="Maximum number of search results")
|
|
35
|
+
|
|
36
|
+
# Command: mcp
|
|
37
|
+
subparsers.add_parser("mcp", help="Start DocGraph Model Context Protocol (MCP) server")
|
|
38
|
+
|
|
39
|
+
args = parser.parse_args()
|
|
40
|
+
|
|
41
|
+
if not args.command:
|
|
42
|
+
parser.print_help()
|
|
43
|
+
sys.exit(0)
|
|
44
|
+
|
|
45
|
+
if args.command == "toc":
|
|
46
|
+
fmt = "json" if args.json else ("markdown" if args.md else "text")
|
|
47
|
+
print(extract_toc(args.file, format_type=fmt))
|
|
48
|
+
|
|
49
|
+
elif args.command == "section":
|
|
50
|
+
print(extract_section(args.file, args.heading, include_subsections=not args.no_sub))
|
|
51
|
+
|
|
52
|
+
elif args.command == "search":
|
|
53
|
+
print(search_doc(args.path, args.query, max_results=args.limit))
|
|
54
|
+
|
|
55
|
+
elif args.command == "mcp":
|
|
56
|
+
from docgraph.mcp_server import run_mcp
|
|
57
|
+
run_mcp()
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
main()
|