mdcontext 0.1.0 → 0.2.0

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.
Files changed (251) hide show
  1. package/.changeset/config.json +9 -9
  2. package/.claude/settings.local.json +25 -0
  3. package/.github/workflows/claude-code-review.yml +44 -0
  4. package/.github/workflows/claude.yml +85 -0
  5. package/CONTRIBUTING.md +186 -0
  6. package/NOTES/NOTES +44 -0
  7. package/README.md +206 -3
  8. package/biome.json +1 -1
  9. package/dist/chunk-23UPXDNL.js +3044 -0
  10. package/dist/chunk-2W7MO2DL.js +1366 -0
  11. package/dist/chunk-3NUAZGMA.js +1689 -0
  12. package/dist/chunk-7TOWB2XB.js +366 -0
  13. package/dist/chunk-7XOTOADQ.js +3065 -0
  14. package/dist/chunk-AH2PDM2K.js +3042 -0
  15. package/dist/chunk-BNXWSZ63.js +3742 -0
  16. package/dist/chunk-BTL5DJVU.js +3222 -0
  17. package/dist/chunk-HDHYG7E4.js +104 -0
  18. package/dist/chunk-HLR4KZBP.js +3234 -0
  19. package/dist/chunk-IP3FRFEB.js +1045 -0
  20. package/dist/chunk-KHU56VDO.js +3042 -0
  21. package/dist/chunk-KRYIFLQR.js +85 -89
  22. package/dist/chunk-LBSDNLEM.js +287 -0
  23. package/dist/chunk-MNTQ7HCP.js +2643 -0
  24. package/dist/chunk-MUJELQQ6.js +1387 -0
  25. package/dist/chunk-MXJGMSLV.js +2199 -0
  26. package/dist/chunk-N6QJGC3Z.js +2636 -0
  27. package/dist/chunk-OBELGBPM.js +1713 -0
  28. package/dist/chunk-OT7R5XTA.js +3192 -0
  29. package/dist/chunk-P7X4RA2T.js +106 -0
  30. package/dist/chunk-PIDUQNC2.js +3185 -0
  31. package/dist/chunk-POGCDIH4.js +3187 -0
  32. package/dist/chunk-PSIEOQGZ.js +3043 -0
  33. package/dist/chunk-PVRT3IHA.js +3238 -0
  34. package/dist/chunk-QNN4TT23.js +1430 -0
  35. package/dist/chunk-RE3R45RJ.js +3042 -0
  36. package/dist/chunk-S7E6TFX6.js +718 -657
  37. package/dist/chunk-SG6GLU4U.js +1378 -0
  38. package/dist/chunk-SJCDV2ST.js +274 -0
  39. package/dist/chunk-SYE5XLF3.js +104 -0
  40. package/dist/chunk-T5VLYBZD.js +103 -0
  41. package/dist/chunk-TOQB7VWU.js +3238 -0
  42. package/dist/chunk-VFNMZ4ZQ.js +3228 -0
  43. package/dist/chunk-VVTGZNBT.js +1533 -1423
  44. package/dist/chunk-W7Q4RFEV.js +104 -0
  45. package/dist/chunk-XTYYVRLO.js +3190 -0
  46. package/dist/chunk-Y6MDYVJD.js +3063 -0
  47. package/dist/cli/main.js +4072 -629
  48. package/dist/index.d.ts +420 -33
  49. package/dist/index.js +8 -15
  50. package/dist/mcp/server.js +103 -7
  51. package/dist/schema-BAWSG7KY.js +22 -0
  52. package/dist/schema-E3QUPL26.js +20 -0
  53. package/dist/schema-EHL7WUT6.js +20 -0
  54. package/docs/019-USAGE.md +44 -5
  55. package/docs/020-current-implementation.md +8 -8
  56. package/docs/021-DOGFOODING-FINDINGS.md +1 -1
  57. package/docs/CONFIG.md +1123 -0
  58. package/docs/ERRORS.md +383 -0
  59. package/docs/summarization.md +320 -0
  60. package/justfile +40 -0
  61. package/package.json +39 -33
  62. package/research/INDEX.md +315 -0
  63. package/research/code-review/README.md +90 -0
  64. package/research/code-review/cli-error-handling-review.md +979 -0
  65. package/research/code-review/code-review-validation-report.md +464 -0
  66. package/research/code-review/main-ts-review.md +1128 -0
  67. package/research/config-docs/SUMMARY.md +357 -0
  68. package/research/config-docs/TEST-RESULTS.md +776 -0
  69. package/research/config-docs/TODO.md +542 -0
  70. package/research/config-docs/analysis.md +744 -0
  71. package/research/config-docs/fix-validation.md +502 -0
  72. package/research/config-docs/help-audit.md +264 -0
  73. package/research/config-docs/help-system-analysis.md +890 -0
  74. package/research/frontmatter/COMMENTS-ARE-SKIPPED.md +149 -0
  75. package/research/frontmatter/LLM-CODE-NAVIGATION.md +276 -0
  76. package/research/issue-review.md +603 -0
  77. package/research/llm-summarization/agent-cli-tools-2026.md +1082 -0
  78. package/research/llm-summarization/alternative-providers-2026.md +1428 -0
  79. package/research/llm-summarization/anthropic-2026.md +367 -0
  80. package/research/llm-summarization/claude-cli-integration.md +1706 -0
  81. package/research/llm-summarization/cli-integration-patterns.md +3155 -0
  82. package/research/llm-summarization/openai-2026.md +473 -0
  83. package/research/llm-summarization/openai-compatible-providers-2026.md +1022 -0
  84. package/research/llm-summarization/opencode-cli-integration.md +1552 -0
  85. package/research/llm-summarization/prompt-engineering-2026.md +1426 -0
  86. package/research/llm-summarization/prototype-results.md +56 -0
  87. package/research/llm-summarization/provider-switching-patterns-2026.md +2153 -0
  88. package/research/llm-summarization/typescript-llm-libraries-2026.md +2436 -0
  89. package/research/mdcontext-pudding/00-EXECUTIVE-SUMMARY.md +282 -0
  90. package/research/mdcontext-pudding/01-index-embed.md +956 -0
  91. package/research/mdcontext-pudding/02-search-COMMANDS.md +142 -0
  92. package/research/mdcontext-pudding/02-search-SUMMARY.md +146 -0
  93. package/research/mdcontext-pudding/02-search.md +970 -0
  94. package/research/mdcontext-pudding/03-context.md +779 -0
  95. package/research/mdcontext-pudding/04-navigation-and-analytics.md +803 -0
  96. package/research/mdcontext-pudding/04-tree.md +704 -0
  97. package/research/mdcontext-pudding/05-config.md +1038 -0
  98. package/research/mdcontext-pudding/06-links-summary.txt +87 -0
  99. package/research/mdcontext-pudding/06-links.md +679 -0
  100. package/research/mdcontext-pudding/07-stats.md +693 -0
  101. package/research/mdcontext-pudding/BUG-FIX-PLAN.md +388 -0
  102. package/research/mdcontext-pudding/P0-BUG-VALIDATION.md +167 -0
  103. package/research/mdcontext-pudding/README.md +168 -0
  104. package/research/mdcontext-pudding/TESTING-SUMMARY.md +128 -0
  105. package/research/research-quality-review.md +834 -0
  106. package/research/semantic-search/embedding-text-analysis.md +156 -0
  107. package/research/semantic-search/multi-word-failure-reproduction.md +171 -0
  108. package/research/semantic-search/query-processing-analysis.md +207 -0
  109. package/research/semantic-search/root-cause-and-solution.md +114 -0
  110. package/research/semantic-search/threshold-validation-report.md +69 -0
  111. package/research/semantic-search/vector-search-analysis.md +63 -0
  112. package/research/test-path-issues.md +276 -0
  113. package/review/ALP-76/1-error-type-design.md +962 -0
  114. package/review/ALP-76/2-error-handling-patterns.md +906 -0
  115. package/review/ALP-76/3-error-presentation.md +624 -0
  116. package/review/ALP-76/4-test-coverage.md +625 -0
  117. package/review/ALP-76/5-migration-completeness.md +440 -0
  118. package/review/ALP-76/6-effect-best-practices.md +755 -0
  119. package/scripts/apply-branch-protection.sh +47 -0
  120. package/scripts/branch-protection-templates.json +79 -0
  121. package/scripts/prototype-summarization.ts +346 -0
  122. package/scripts/rebuild-hnswlib.js +32 -37
  123. package/scripts/setup-branch-protection.sh +64 -0
  124. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/active-provider.json +7 -0
  125. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/bm25.json +541 -0
  126. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/bm25.meta.json +5 -0
  127. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/config.json +8 -0
  128. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.bin +0 -0
  129. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.meta.bin +0 -0
  130. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/documents.json +60 -0
  131. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/links.json +13 -0
  132. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/.mdcontext/indexes/sections.json +1197 -0
  133. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/configuration-management.md +99 -0
  134. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/distributed-systems.md +92 -0
  135. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/error-handling.md +78 -0
  136. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/failure-automation.md +55 -0
  137. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/job-context.md +69 -0
  138. package/src/__tests__/fixtures/semantic-search/multi-word-corpus/process-orchestration.md +99 -0
  139. package/src/cli/argv-preprocessor.test.ts +2 -2
  140. package/src/cli/cli.test.ts +230 -33
  141. package/src/cli/commands/config-cmd.ts +642 -0
  142. package/src/cli/commands/context.ts +97 -9
  143. package/src/cli/commands/duplicates.ts +122 -0
  144. package/src/cli/commands/embeddings.ts +529 -0
  145. package/src/cli/commands/index-cmd.ts +210 -30
  146. package/src/cli/commands/index.ts +3 -0
  147. package/src/cli/commands/search.ts +894 -64
  148. package/src/cli/commands/stats.ts +3 -0
  149. package/src/cli/commands/tree.ts +26 -5
  150. package/src/cli/config-layer.ts +176 -0
  151. package/src/cli/error-handler.test.ts +235 -0
  152. package/src/cli/error-handler.ts +655 -0
  153. package/src/cli/flag-schemas.ts +66 -0
  154. package/src/cli/help.ts +209 -7
  155. package/src/cli/main.ts +348 -58
  156. package/src/cli/options.ts +10 -0
  157. package/src/cli/shared-error-handling.ts +199 -0
  158. package/src/cli/utils.ts +150 -17
  159. package/src/config/file-provider.test.ts +320 -0
  160. package/src/config/file-provider.ts +273 -0
  161. package/src/config/index.ts +72 -0
  162. package/src/config/integration.test.ts +667 -0
  163. package/src/config/precedence.test.ts +277 -0
  164. package/src/config/precedence.ts +451 -0
  165. package/src/config/schema.test.ts +414 -0
  166. package/src/config/schema.ts +603 -0
  167. package/src/config/service.test.ts +320 -0
  168. package/src/config/service.ts +243 -0
  169. package/src/config/testing.test.ts +264 -0
  170. package/src/config/testing.ts +110 -0
  171. package/src/core/types.ts +6 -33
  172. package/src/duplicates/detector.test.ts +183 -0
  173. package/src/duplicates/detector.ts +414 -0
  174. package/src/duplicates/index.ts +18 -0
  175. package/src/embeddings/embedding-namespace.test.ts +300 -0
  176. package/src/embeddings/embedding-namespace.ts +947 -0
  177. package/src/embeddings/heading-boost.test.ts +222 -0
  178. package/src/embeddings/hnsw-build-options.test.ts +198 -0
  179. package/src/embeddings/hyde.test.ts +272 -0
  180. package/src/embeddings/hyde.ts +264 -0
  181. package/src/embeddings/index.ts +2 -0
  182. package/src/embeddings/openai-provider.ts +332 -83
  183. package/src/embeddings/pricing.json +22 -0
  184. package/src/embeddings/provider-constants.ts +204 -0
  185. package/src/embeddings/provider-errors.test.ts +967 -0
  186. package/src/embeddings/provider-errors.ts +565 -0
  187. package/src/embeddings/provider-factory.test.ts +240 -0
  188. package/src/embeddings/provider-factory.ts +225 -0
  189. package/src/embeddings/provider-integration.test.ts +788 -0
  190. package/src/embeddings/query-preprocessing.test.ts +187 -0
  191. package/src/embeddings/semantic-search-threshold.test.ts +508 -0
  192. package/src/embeddings/semantic-search.ts +780 -93
  193. package/src/embeddings/types.ts +293 -16
  194. package/src/embeddings/vector-store.ts +486 -77
  195. package/src/embeddings/voyage-provider.ts +313 -0
  196. package/src/errors/errors.test.ts +845 -0
  197. package/src/errors/index.ts +533 -0
  198. package/src/index/ignore-patterns.test.ts +354 -0
  199. package/src/index/ignore-patterns.ts +305 -0
  200. package/src/index/indexer.ts +286 -48
  201. package/src/index/storage.ts +94 -30
  202. package/src/index/types.ts +40 -2
  203. package/src/index/watcher.ts +67 -9
  204. package/src/index.ts +22 -0
  205. package/src/integration/search-keyword.test.ts +678 -0
  206. package/src/mcp/server.ts +135 -6
  207. package/src/parser/parser.ts +18 -19
  208. package/src/parser/section-filter.test.ts +277 -0
  209. package/src/parser/section-filter.ts +125 -3
  210. package/src/search/__tests__/hybrid-search.test.ts +650 -0
  211. package/src/search/bm25-store.ts +366 -0
  212. package/src/search/cross-encoder.test.ts +253 -0
  213. package/src/search/cross-encoder.ts +406 -0
  214. package/src/search/fuzzy-search.test.ts +419 -0
  215. package/src/search/fuzzy-search.ts +273 -0
  216. package/src/search/hybrid-search.ts +448 -0
  217. package/src/search/path-matcher.test.ts +276 -0
  218. package/src/search/path-matcher.ts +33 -0
  219. package/src/search/searcher.test.ts +99 -1
  220. package/src/search/searcher.ts +189 -67
  221. package/src/search/wink-bm25.d.ts +30 -0
  222. package/src/summarization/cli-providers/claude.ts +202 -0
  223. package/src/summarization/cli-providers/detection.test.ts +273 -0
  224. package/src/summarization/cli-providers/detection.ts +118 -0
  225. package/src/summarization/cli-providers/index.ts +8 -0
  226. package/src/summarization/cost.test.ts +139 -0
  227. package/src/summarization/cost.ts +102 -0
  228. package/src/summarization/error-handler.test.ts +127 -0
  229. package/src/summarization/error-handler.ts +111 -0
  230. package/src/summarization/index.ts +102 -0
  231. package/src/summarization/pipeline.test.ts +498 -0
  232. package/src/summarization/pipeline.ts +231 -0
  233. package/src/summarization/prompts.test.ts +269 -0
  234. package/src/summarization/prompts.ts +133 -0
  235. package/src/summarization/provider-factory.test.ts +396 -0
  236. package/src/summarization/provider-factory.ts +178 -0
  237. package/src/summarization/types.ts +184 -0
  238. package/src/summarize/summarizer.ts +104 -35
  239. package/src/types/huggingface-transformers.d.ts +66 -0
  240. package/tests/fixtures/cli/.mdcontext/active-provider.json +7 -0
  241. package/tests/fixtures/cli/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.bin +0 -0
  242. package/tests/fixtures/cli/.mdcontext/embeddings/openai_text-embedding-3-small_512/vectors.meta.bin +0 -0
  243. package/tests/fixtures/cli/.mdcontext/indexes/documents.json +4 -4
  244. package/tests/fixtures/cli/.mdcontext/indexes/sections.json +14 -0
  245. package/tests/integration/embed-index.test.ts +712 -0
  246. package/tests/integration/search-context.test.ts +469 -0
  247. package/tests/integration/search-semantic.test.ts +522 -0
  248. package/vitest.config.ts +1 -6
  249. package/AGENTS.md +0 -46
  250. package/tests/fixtures/cli/.mdcontext/vectors.bin +0 -0
  251. package/tests/fixtures/cli/.mdcontext/vectors.meta.json +0 -1264
@@ -0,0 +1,704 @@
1
+ # mdcontext tree Command - Research and Testing
2
+
3
+ ## Overview
4
+
5
+ The `mdcontext tree` command serves dual purposes:
6
+ 1. **Directory mode**: Lists all markdown files in a directory hierarchy
7
+ 2. **File mode**: Shows document structure with heading hierarchy and token counts
8
+
9
+ This is a clever design that provides both high-level navigation and detailed document insight through a single command.
10
+
11
+ ## Test Environment
12
+
13
+ - Repository: `/Users/alphab/Dev/LLM/DEV/agentic-flow`
14
+ - Files indexed: 1,561 markdown documents
15
+ - Sections: 52,714
16
+ - Test date: 2026-01-26
17
+
18
+ ## Command Syntax
19
+
20
+ ```bash
21
+ mdcontext tree [path] [options]
22
+
23
+ Options:
24
+ --json Output as JSON
25
+ --pretty Pretty-print JSON output
26
+ ```
27
+
28
+ ## Usage Patterns
29
+
30
+ ### 1. File Tree (Directory Mode)
31
+
32
+ When passed a directory path, shows all markdown files in the tree:
33
+
34
+ ```bash
35
+ # List all markdown files in current directory
36
+ cd /Users/alphab/Dev/LLM/DEV/agentic-flow
37
+ mdcontext tree
38
+
39
+ # Output format:
40
+ # Markdown files in /Users/alphab/Dev/LLM/DEV/agentic-flow:
41
+ #
42
+ # CLAUDE.md
43
+ # README.md
44
+ # agentic-flow/CHANGELOG.md
45
+ # agentic-flow/README.md
46
+ # ...
47
+ ```
48
+
49
+ **Performance**: 685ms for 1,561 files (very fast)
50
+
51
+ ### 2. Document Outline (File Mode)
52
+
53
+ When passed a file path, shows heading structure with token counts:
54
+
55
+ ```bash
56
+ # Show document outline
57
+ mdcontext tree README.md
58
+
59
+ # Output:
60
+ # 🚀 Agentic-Flow v2.0.0-alpha
61
+ # Total tokens: 18095
62
+ #
63
+ # 🚀 Agentic-Flow v2.0.0-alpha [269 tokens]
64
+ # ## 🎉 What's New in v2.0.0-alpha [16 tokens]
65
+ # ### SONA: Self-Optimizing Neural Architecture 🧠 [249 tokens]
66
+ # ### Complete AgentDB@alpha Integration 🧠 [246 tokens]
67
+ # ## 📖 Table of Contents [237 tokens]
68
+ # ...
69
+ ```
70
+
71
+ **Performance**: 620ms for a 3,008-line document (42,521 tokens) - excellent
72
+
73
+ ## Output Formats
74
+
75
+ ### 1. Human-Readable (Default)
76
+
77
+ Directory listing:
78
+ ```
79
+ Markdown files in /path/to/directory:
80
+
81
+ file1.md
82
+ file2.md
83
+ subdir/file3.md
84
+
85
+ Total: X files
86
+ ```
87
+
88
+ Document outline:
89
+ ```
90
+ # Document Title
91
+ Total tokens: XXXX
92
+
93
+ # Heading 1 [XXX tokens]
94
+ ## Heading 2 [XXX tokens]
95
+ ### Heading 3 [XXX tokens]
96
+ ```
97
+
98
+ ### 2. JSON Format
99
+
100
+ Directory listing (--json):
101
+ ```json
102
+ [
103
+ {
104
+ "path": "/absolute/path/to/file.md",
105
+ "relativePath": "relative/path/to/file.md"
106
+ },
107
+ ...
108
+ ]
109
+ ```
110
+
111
+ Document outline (--json --pretty):
112
+ ```json
113
+ {
114
+ "title": "Document Title",
115
+ "path": "/absolute/path/to/file.md",
116
+ "totalTokens": 18095,
117
+ "sections": [
118
+ {
119
+ "heading": "Main Heading",
120
+ "level": 1,
121
+ "tokens": 269,
122
+ "children": [
123
+ {
124
+ "heading": "Sub Heading",
125
+ "level": 2,
126
+ "tokens": 16,
127
+ "children": []
128
+ }
129
+ ]
130
+ }
131
+ ]
132
+ }
133
+ ```
134
+
135
+ ## Test Results
136
+
137
+ ### Test 1: Large Repository Tree View
138
+
139
+ ```bash
140
+ cd /Users/alphab/Dev/LLM/DEV/agentic-flow
141
+ time mdcontext tree
142
+ ```
143
+
144
+ **Results**:
145
+ - Files listed: 1,561 markdown files
146
+ - Time: 685ms (0.75s user + 0.21s system)
147
+ - CPU: 141%
148
+ - Status: Excellent performance
149
+
150
+ ### Test 2: Subdirectory Filtering
151
+
152
+ ```bash
153
+ mdcontext tree docs/guides/
154
+ ```
155
+
156
+ **Results**:
157
+ - Files found: 28 files (including subdirectories)
158
+ - Time: 576ms
159
+ - Output: Clean, relative paths from specified directory
160
+ - Includes subdirectories: Yes (e.g., `getting-started/quick-start.md`)
161
+
162
+ **Comparison with filesystem**:
163
+ ```bash
164
+ ls -1 docs/guides/*.md | wc -l # 26 files (only top level)
165
+ mdcontext tree docs/guides/ # 28 files (includes subdirs)
166
+ ```
167
+
168
+ The tree command correctly includes nested directories, while shell globbing doesn't by default.
169
+
170
+ ### Test 3: Document Outline - Small File
171
+
172
+ ```bash
173
+ mdcontext tree docs/guides/README.md
174
+ ```
175
+
176
+ **Output**:
177
+ ```
178
+ # User Guides
179
+ Total tokens: 221
180
+
181
+ # User Guides [28 tokens]
182
+ ## Getting Started [95 tokens]
183
+ ## Model Configuration [47 tokens]
184
+ ## Examples [45 tokens]
185
+ ```
186
+
187
+ **Quality**: Perfect extraction, clear hierarchy
188
+
189
+ ### Test 4: Document Outline - Large Complex File
190
+
191
+ ```bash
192
+ mdcontext tree docs/research/JJ_INTEGRATION_ANALYSIS.md
193
+ ```
194
+
195
+ **Results**:
196
+ - File size: 3,008 lines
197
+ - Total tokens: 42,521
198
+ - Sections extracted: ~50+ headings
199
+ - Nesting levels: Up to 4 levels (####)
200
+ - Time: 620ms
201
+ - Quality: Excellent - accurately captured nested structure
202
+
203
+ **Sample output**:
204
+ ```
205
+ # Jujutsu (jj) VCS Integration with Agentic-Flow and AgentDB
206
+ Total tokens: 42521
207
+
208
+ # Jujutsu (jj) VCS Integration with Agentic-Flow and AgentDB [22 tokens]
209
+ ## Ultra-Deep Research and Analysis [71 tokens]
210
+ ## Executive Summary [139 tokens]
211
+ ### Key Findings [246 tokens]
212
+ ## 1. Jujutsu VCS Core Capabilities [13 tokens]
213
+ ### 1.1 Operation Log Architecture [489 tokens]
214
+ ### 1.2 Working Copy Management [265 tokens]
215
+ ...
216
+ ## 6. Technical Architecture [11 tokens]
217
+ ### 6.1 System Overview [2654 tokens]
218
+ ### 6.2 Data Flow [447 tokens]
219
+ ### 6.3 Integration Layers [11 tokens]
220
+ #### Layer 1: CLI Wrapper (Immediate Implementation) [981 tokens]
221
+ #### Layer 2: Node.js Native Module (Future) [569 tokens]
222
+ ```
223
+
224
+ ### Test 5: Document Outline - Medium Complexity
225
+
226
+ ```bash
227
+ mdcontext tree docs/guides/MULTI-MODEL-ROUTER.md
228
+ ```
229
+
230
+ **Results**:
231
+ - Total tokens: 9,784
232
+ - Heading levels: 1-4 (with proper nesting)
233
+ - Token distribution visible per section
234
+ - Formatting preserved (emojis in headings)
235
+
236
+ ### Test 6: JSON Output
237
+
238
+ ```bash
239
+ mdcontext tree docs/guides/ --json | head -100
240
+ ```
241
+
242
+ **Results**:
243
+ - Format: Array of objects with `path` and `relativePath`
244
+ - Size: Large (64KB for 522 files in docs/)
245
+ - Structure: Clean, parseable, useful for programmatic access
246
+ - Performance: Same speed as regular output
247
+
248
+ ### Test 7: Pretty JSON Output
249
+
250
+ ```bash
251
+ mdcontext tree README.md --json --pretty | head -100
252
+ ```
253
+
254
+ **Results**:
255
+ - Format: Hierarchical tree structure
256
+ - Fields: `title`, `path`, `totalTokens`, `sections[]`
257
+ - Section structure: `heading`, `level`, `tokens`, `children[]`
258
+ - Nesting: Properly nested with children arrays
259
+ - Quality: Machine-readable and human-inspectable
260
+
261
+ ### Test 8: Pattern Matching (Attempted)
262
+
263
+ ```bash
264
+ mdcontext tree 'docs/guides/*.md'
265
+ ```
266
+
267
+ **Result**: ❌ Error - glob patterns not supported
268
+ ```
269
+ FileReadError: Cannot access path: ENOENT: no such file or directory,
270
+ stat '/Users/alphab/Dev/LLM/DEV/agentic-flow/docs/guides/*.md'
271
+ ```
272
+
273
+ **Note**: The command expects a literal directory or file path, not shell glob patterns. Use directory mode instead to list all files in a directory.
274
+
275
+ ## Use Cases
276
+
277
+ ### 1. Repository Navigation
278
+
279
+ **Scenario**: Exploring a new codebase
280
+ ```bash
281
+ mdcontext tree # Get overview of all markdown files
282
+ mdcontext tree docs/ # Focus on documentation
283
+ mdcontext tree README.md # Understand main document structure
284
+ ```
285
+
286
+ **Value**: Quick orientation without opening files
287
+
288
+ ### 2. Documentation Planning
289
+
290
+ **Scenario**: Understanding document scope and organization
291
+ ```bash
292
+ mdcontext tree docs/guides/MULTI-MODEL-ROUTER.md
293
+ ```
294
+
295
+ **Output shows**:
296
+ - Total token count (9,784) - useful for context windows
297
+ - Section hierarchy - see organization at a glance
298
+ - Token distribution - identify heavy sections
299
+
300
+ **Value**: Token budget planning, structure review
301
+
302
+ ### 3. IDE Integration
303
+
304
+ **Scenario**: Building a documentation browser
305
+ ```bash
306
+ mdcontext tree docs/ --json --pretty
307
+ ```
308
+
309
+ **JSON output** enables:
310
+ - File tree views
311
+ - Table of contents generation
312
+ - Document navigation panels
313
+ - Search result previews
314
+
315
+ **Example integration**:
316
+ ```javascript
317
+ const files = JSON.parse(await exec('mdcontext tree docs/ --json'));
318
+ const toc = JSON.parse(await exec('mdcontext tree README.md --json'));
319
+
320
+ // Build interactive documentation browser
321
+ files.forEach(file => {
322
+ const outline = JSON.parse(await exec(`mdcontext tree ${file.path} --json`));
323
+ renderDocumentWithTOC(outline);
324
+ });
325
+ ```
326
+
327
+ ### 4. Content Analysis
328
+
329
+ **Scenario**: Finding oversized sections for splitting
330
+ ```bash
331
+ mdcontext tree large-doc.md | grep -E '\[([0-9]{4,}) tokens\]'
332
+ ```
333
+
334
+ **Use**: Identify sections > 1000 tokens that might need splitting
335
+
336
+ ### 5. Documentation Quality Checks
337
+
338
+ **Scenario**: Verify all documents have proper structure
339
+ ```bash
340
+ for file in $(mdcontext tree docs/ --json | jq -r '.[].path'); do
341
+ mdcontext tree "$file" --json | jq '.sections | length'
342
+ done
343
+ ```
344
+
345
+ **Use**: Ensure minimum heading structure exists
346
+
347
+ ### 6. LLM Context Preparation
348
+
349
+ **Scenario**: Check if document fits in context window
350
+ ```bash
351
+ mdcontext tree README.md | head -3
352
+ # Output: Total tokens: 18095
353
+ ```
354
+
355
+ **Decision**: 18k tokens fits in most context windows, proceed
356
+
357
+ ### 7. Documentation Refactoring
358
+
359
+ **Scenario**: Understanding token distribution before restructuring
360
+ ```bash
361
+ mdcontext tree docs/guides/MCP-AUTHENTICATION.md
362
+ ```
363
+
364
+ **Shows**:
365
+ - Which sections are heaviest
366
+ - Nesting depth issues
367
+ - Potential splitting points
368
+
369
+ ## Performance Analysis
370
+
371
+ ### Speed Tests
372
+
373
+ | Operation | Files/Size | Time | Notes |
374
+ |-----------|-----------|------|-------|
375
+ | Full repo tree | 1,561 files | 685ms | Excellent |
376
+ | Subdirectory tree | 28 files | 576ms | Fast (includes index lookup) |
377
+ | Small file outline | 221 tokens | ~600ms | Fast |
378
+ | Large file outline | 42,521 tokens | 620ms | Excellent (3,008 lines) |
379
+ | JSON output | Same | ~same | No performance penalty |
380
+
381
+ **Key Insights**:
382
+ - Performance scales well with repository size
383
+ - Large document parsing is very efficient
384
+ - No significant overhead for JSON formatting
385
+ - Index lookup is fast (indexed files only)
386
+
387
+ ### Scalability
388
+
389
+ The command operates on **indexed files only**, which means:
390
+ - Performance depends on index quality
391
+ - Unindexed files won't appear
392
+ - Changes require re-indexing
393
+ - Speed benefits from index caching
394
+
395
+ **Test**: After indexing (579ms for 1,561 docs), tree command is instant (685ms)
396
+
397
+ ## Heading Extraction Quality
398
+
399
+ ### Test: Complex Nesting
400
+
401
+ Tested on file with 4 levels of headings:
402
+ ```markdown
403
+ # Level 1
404
+ ## Level 2
405
+ ### Level 3
406
+ #### Level 4
407
+ ```
408
+
409
+ **Result**: ✅ All levels correctly extracted and nested
410
+
411
+ ### Test: Emoji Handling
412
+
413
+ Tested on headings with emojis:
414
+ ```markdown
415
+ # 🚀 Agentic-Flow v2.0.0-alpha
416
+ ## 🎉 What's New
417
+ ```
418
+
419
+ **Result**: ✅ Emojis preserved in output
420
+
421
+ ### Test: Numbered Headings
422
+
423
+ Tested on structured documentation:
424
+ ```markdown
425
+ ## 1. Jujutsu VCS Core Capabilities
426
+ ### 1.1 Operation Log Architecture
427
+ ### 1.2 Working Copy Management
428
+ ```
429
+
430
+ **Result**: ✅ Numbers preserved, correct nesting
431
+
432
+ ### Test: Token Counting
433
+
434
+ Examined token counts across sections:
435
+
436
+ **Observations**:
437
+ - Small headings: 10-50 tokens (mostly structure)
438
+ - Content sections: 100-500 tokens (normal paragraphs)
439
+ - Large sections: 500-2000+ tokens (complex content)
440
+ - Very heavy sections: 2654 tokens (System Overview in test file)
441
+
442
+ **Accuracy**: Token counts appear accurate (using tiktoken internally)
443
+
444
+ ## Edge Cases and Limitations
445
+
446
+ ### 1. Glob Pattern Support
447
+
448
+ **Issue**: Shell glob patterns are NOT supported
449
+ ```bash
450
+ mdcontext tree 'docs/*.md' # ❌ Fails
451
+ ```
452
+
453
+ **Workaround**: Use directory mode
454
+ ```bash
455
+ mdcontext tree docs/ # ✅ Works - lists all files recursively
456
+ ```
457
+
458
+ ### 2. Depth Limits
459
+
460
+ **Observation**: No apparent depth limit in help output
461
+ **Test needed**: Does it limit directory recursion depth?
462
+ **Current behavior**: Appears to recurse fully through directories
463
+
464
+ ### 3. Hidden Files
465
+
466
+ From indexing output: "20 hidden" files were skipped
467
+ **Question**: Can tree command show hidden files?
468
+ **Current**: Follows index, which skips hidden files by default
469
+
470
+ ### 4. Large Repositories
471
+
472
+ **Tested**: 1,561 files performed well (685ms)
473
+ **Question**: What happens with 10k+ files?
474
+ **Expectation**: Should still be fast (index-based lookup)
475
+
476
+ ### 5. Malformed Markdown
477
+
478
+ **Not tested**: How does it handle documents with:
479
+ - Missing closing headings
480
+ - Invalid nesting (### before ##)
481
+ - Duplicate heading text
482
+
483
+ **Expected**: Likely handles gracefully (remark-based parser)
484
+
485
+ ## Comparison with Alternatives
486
+
487
+ ### vs `find` + `ls`
488
+ ```bash
489
+ find . -name "*.md" # Finds all .md files
490
+ mdcontext tree # Finds indexed markdown files
491
+ ```
492
+
493
+ **Advantage mdcontext**:
494
+ - Filters to indexed files only
495
+ - Respects .gitignore patterns
496
+ - Cleaner output formatting
497
+ - Includes relative paths
498
+
499
+ ### vs `tree` command
500
+ ```bash
501
+ tree -P "*.md" # File system tree
502
+ mdcontext tree # Document tree
503
+ ```
504
+
505
+ **Advantage mdcontext**:
506
+ - Document-aware (not just files)
507
+ - Token counting built-in
508
+ - JSON output for integration
509
+ - Outline view for files
510
+
511
+ ### vs manual TOC generation
512
+ ```bash
513
+ grep "^#" README.md # Extract headings
514
+ mdcontext tree README.md # Full outline with tokens
515
+ ```
516
+
517
+ **Advantage mdcontext**:
518
+ - Token counts per section
519
+ - Proper nesting structure
520
+ - Machine-readable JSON
521
+ - Consistent formatting
522
+
523
+ ## Integration Ideas
524
+
525
+ ### 1. VSCode Extension
526
+
527
+ **Feature**: Documentation sidebar
528
+ ```typescript
529
+ // Fetch file tree
530
+ const tree = await exec('mdcontext tree --json');
531
+
532
+ // Render in sidebar
533
+ tree.forEach(file => {
534
+ const outline = await exec(`mdcontext tree ${file.path} --json`);
535
+ renderOutline(outline);
536
+ });
537
+ ```
538
+
539
+ **UI**:
540
+ - File tree with markdown files
541
+ - Click to see outline
542
+ - Token counts visible
543
+ - Search within structure
544
+
545
+ ### 2. Documentation Site Generator
546
+
547
+ **Feature**: Auto-generate navigation
548
+ ```javascript
549
+ const files = JSON.parse(await exec('mdcontext tree docs/ --json'));
550
+
551
+ // Build nav structure
552
+ const nav = buildNav(files);
553
+
554
+ // Generate TOC for each page
555
+ files.forEach(async file => {
556
+ const outline = JSON.parse(
557
+ await exec(`mdcontext tree ${file.path} --json`)
558
+ );
559
+ generatePage(file, outline);
560
+ });
561
+ ```
562
+
563
+ ### 3. LLM Context Builder
564
+
565
+ **Feature**: Smart document selection
566
+ ```bash
567
+ # Check document size before adding to context
568
+ SIZE=$(mdcontext tree README.md | head -2 | tail -1 | grep -oE '[0-9]+')
569
+
570
+ if [ $SIZE -lt 5000 ]; then
571
+ mdcontext context README.md >> context.txt
572
+ else
573
+ echo "Document too large, skipping"
574
+ fi
575
+ ```
576
+
577
+ ### 4. Documentation Linter
578
+
579
+ **Feature**: Enforce structure rules
580
+ ```javascript
581
+ const outline = JSON.parse(
582
+ await exec('mdcontext tree docs/guide.md --json')
583
+ );
584
+
585
+ // Check rules
586
+ if (outline.sections.length === 0) {
587
+ error('Document has no headings');
588
+ }
589
+
590
+ outline.sections.forEach(section => {
591
+ if (section.tokens > 1000) {
592
+ warn(`Section "${section.heading}" is too long (${section.tokens} tokens)`);
593
+ }
594
+ });
595
+ ```
596
+
597
+ ### 5. API Documentation Generator
598
+
599
+ **Feature**: Parse API docs structure
600
+ ```bash
601
+ # Find all API reference files
602
+ mdcontext tree docs/api/ --json | jq -r '.[].path' | while read file; do
603
+ # Extract structure
604
+ mdcontext tree "$file" --json | \
605
+ jq '.sections[] | select(.level == 2) | .heading'
606
+ done
607
+ ```
608
+
609
+ ### 6. Git Pre-commit Hook
610
+
611
+ **Feature**: Validate documentation changes
612
+ ```bash
613
+ # In .git/hooks/pre-commit
614
+ for file in $(git diff --cached --name-only | grep '\.md$'); do
615
+ outline=$(mdcontext tree "$file" --json)
616
+ tokens=$(echo "$outline" | jq '.totalTokens')
617
+
618
+ if [ $tokens -gt 10000 ]; then
619
+ echo "Warning: $file is very large ($tokens tokens)"
620
+ fi
621
+ done
622
+ ```
623
+
624
+ ## Issues Found
625
+
626
+ ### Issue 1: Glob Pattern Not Supported
627
+
628
+ **Expected**: `mdcontext tree 'docs/*.md'` would filter files
629
+ **Actual**: Error - literal path interpretation only
630
+ **Severity**: Minor - directory mode works well enough
631
+ **Workaround**: Use directory path instead
632
+
633
+ ### Issue 2: No Depth Limit Option
634
+
635
+ **Observation**: No `--max-depth` flag
636
+ **Use case**: List only top-level subdirectories
637
+ **Current**: Always recurses fully
638
+ **Impact**: Minor - usually want full tree anyway
639
+
640
+ ### Issue 3: No File Count in Directory Mode Output
641
+
642
+ **Observation**: Says "Total: X files" at end, but not in JSON
643
+ **JSON output**: Just array of files
644
+ **Suggestion**: Add metadata to JSON output:
645
+ ```json
646
+ {
647
+ "root": "/path/to/dir",
648
+ "count": 1561,
649
+ "files": [...]
650
+ }
651
+ ```
652
+
653
+ ## Recommendations
654
+
655
+ ### For Users
656
+
657
+ 1. **Start with tree view** - Get repository overview first
658
+ 2. **Use outline for planning** - Check token counts before editing
659
+ 3. **JSON for scripting** - Integrate with build tools
660
+ 4. **Directory mode for discovery** - Find relevant documentation quickly
661
+
662
+ ### For Integration
663
+
664
+ 1. **Cache outline data** - Parse once, use many times
665
+ 2. **Build navigation from JSON** - Clean structured data
666
+ 3. **Show token budgets** - Help users stay within context limits
667
+ 4. **Enable filtering** - Let users explore structure interactively
668
+
669
+ ### For mdcontext Development
670
+
671
+ 1. **Add glob pattern support** - More flexible file filtering
672
+ 2. **Include metadata in JSON** - File counts, timestamps
673
+ 3. **Add depth limiting** - Optional for large trees
674
+ 4. **Consider section IDs** - Enable linking to sections
675
+ 5. **Add filtering options** - By token count, heading level, etc.
676
+
677
+ ## Conclusion
678
+
679
+ The `mdcontext tree` command is a powerful dual-purpose tool that excels at both repository navigation and document structure analysis.
680
+
681
+ **Strengths**:
682
+ - Fast performance (sub-second for large repos)
683
+ - Clean, intuitive output
684
+ - Excellent heading extraction
685
+ - Useful token counting
686
+ - Strong JSON output for integration
687
+ - Smart dual-mode design (directory vs file)
688
+
689
+ **Use Cases**:
690
+ - Repository exploration and navigation
691
+ - Documentation planning and token budgeting
692
+ - IDE and tooling integration
693
+ - Content analysis and quality checks
694
+ - LLM context window management
695
+
696
+ **Performance**:
697
+ - Grade: A
698
+ - Scales well with repository size
699
+ - Handles large documents efficiently
700
+ - No performance penalty for JSON output
701
+
702
+ **Overall Assessment**: This is a well-designed, practical command that provides real value for both human users and programmatic integration. The dual-mode behavior (directory listing vs document outline) is clever and intuitive. The addition of token counts makes it particularly useful for LLM-related workflows.
703
+
704
+ **Primary Value**: Bridges the gap between file system navigation and document content understanding, all while being cognizant of token budgets.