@mars167/git-ai 2.3.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 (122) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +364 -0
  3. package/README.zh-CN.md +361 -0
  4. package/assets/hooks/post-checkout +28 -0
  5. package/assets/hooks/post-merge +28 -0
  6. package/assets/hooks/pre-commit +17 -0
  7. package/assets/hooks/pre-push +29 -0
  8. package/dist/bin/git-ai.js +62 -0
  9. package/dist/src/commands/ai.js +30 -0
  10. package/dist/src/commands/checkIndex.js +19 -0
  11. package/dist/src/commands/dsr.js +156 -0
  12. package/dist/src/commands/graph.js +203 -0
  13. package/dist/src/commands/hooks.js +125 -0
  14. package/dist/src/commands/index.js +92 -0
  15. package/dist/src/commands/pack.js +31 -0
  16. package/dist/src/commands/query.js +139 -0
  17. package/dist/src/commands/semantic.js +134 -0
  18. package/dist/src/commands/serve.js +14 -0
  19. package/dist/src/commands/status.js +78 -0
  20. package/dist/src/commands/trae.js +75 -0
  21. package/dist/src/commands/unpack.js +28 -0
  22. package/dist/src/core/archive.js +91 -0
  23. package/dist/src/core/astGraph.js +127 -0
  24. package/dist/src/core/astGraphQuery.js +142 -0
  25. package/dist/src/core/cozo.js +266 -0
  26. package/dist/src/core/cpg/astLayer.js +56 -0
  27. package/dist/src/core/cpg/callGraph.js +483 -0
  28. package/dist/src/core/cpg/cfgLayer.js +490 -0
  29. package/dist/src/core/cpg/dfgLayer.js +237 -0
  30. package/dist/src/core/cpg/index.js +80 -0
  31. package/dist/src/core/cpg/types.js +108 -0
  32. package/dist/src/core/crypto.js +10 -0
  33. package/dist/src/core/dsr/generate.js +308 -0
  34. package/dist/src/core/dsr/gitContext.js +74 -0
  35. package/dist/src/core/dsr/indexMaterialize.js +106 -0
  36. package/dist/src/core/dsr/paths.js +26 -0
  37. package/dist/src/core/dsr/query.js +73 -0
  38. package/dist/src/core/dsr/snapshotParser.js +73 -0
  39. package/dist/src/core/dsr/state.js +27 -0
  40. package/dist/src/core/dsr/types.js +2 -0
  41. package/dist/src/core/embedding/fusion.js +52 -0
  42. package/dist/src/core/embedding/index.js +43 -0
  43. package/dist/src/core/embedding/parser.js +14 -0
  44. package/dist/src/core/embedding/semantic.js +254 -0
  45. package/dist/src/core/embedding/structural.js +97 -0
  46. package/dist/src/core/embedding/symbolic.js +117 -0
  47. package/dist/src/core/embedding/tokenizer.js +91 -0
  48. package/dist/src/core/embedding/types.js +2 -0
  49. package/dist/src/core/embedding.js +36 -0
  50. package/dist/src/core/git.js +49 -0
  51. package/dist/src/core/gitDiff.js +73 -0
  52. package/dist/src/core/indexCheck.js +131 -0
  53. package/dist/src/core/indexer.js +185 -0
  54. package/dist/src/core/indexerIncremental.js +303 -0
  55. package/dist/src/core/indexing/config.js +51 -0
  56. package/dist/src/core/indexing/hnsw.js +568 -0
  57. package/dist/src/core/indexing/index.js +17 -0
  58. package/dist/src/core/indexing/monitor.js +82 -0
  59. package/dist/src/core/indexing/parallel.js +252 -0
  60. package/dist/src/core/lancedb.js +111 -0
  61. package/dist/src/core/lfs.js +27 -0
  62. package/dist/src/core/log.js +62 -0
  63. package/dist/src/core/manifest.js +88 -0
  64. package/dist/src/core/parser/adapter.js +2 -0
  65. package/dist/src/core/parser/c.js +93 -0
  66. package/dist/src/core/parser/chunkRelations.js +178 -0
  67. package/dist/src/core/parser/chunker.js +274 -0
  68. package/dist/src/core/parser/go.js +98 -0
  69. package/dist/src/core/parser/java.js +80 -0
  70. package/dist/src/core/parser/markdown.js +76 -0
  71. package/dist/src/core/parser/python.js +81 -0
  72. package/dist/src/core/parser/rust.js +103 -0
  73. package/dist/src/core/parser/typescript.js +98 -0
  74. package/dist/src/core/parser/utils.js +62 -0
  75. package/dist/src/core/parser/yaml.js +53 -0
  76. package/dist/src/core/parser.js +75 -0
  77. package/dist/src/core/paths.js +10 -0
  78. package/dist/src/core/repoMap.js +164 -0
  79. package/dist/src/core/retrieval/cache.js +31 -0
  80. package/dist/src/core/retrieval/classifier.js +74 -0
  81. package/dist/src/core/retrieval/expander.js +80 -0
  82. package/dist/src/core/retrieval/fuser.js +40 -0
  83. package/dist/src/core/retrieval/index.js +32 -0
  84. package/dist/src/core/retrieval/reranker.js +304 -0
  85. package/dist/src/core/retrieval/types.js +2 -0
  86. package/dist/src/core/retrieval/weights.js +42 -0
  87. package/dist/src/core/search.js +41 -0
  88. package/dist/src/core/sq8.js +65 -0
  89. package/dist/src/core/symbolSearch.js +143 -0
  90. package/dist/src/core/types.js +2 -0
  91. package/dist/src/core/workspace.js +116 -0
  92. package/dist/src/mcp/server.js +794 -0
  93. package/docs/README.md +44 -0
  94. package/docs/cross-encoder.md +157 -0
  95. package/docs/embedding.md +158 -0
  96. package/docs/logo.png +0 -0
  97. package/docs/windows-setup.md +67 -0
  98. package/docs/zh-CN/DESIGN.md +102 -0
  99. package/docs/zh-CN/README.md +46 -0
  100. package/docs/zh-CN/advanced.md +26 -0
  101. package/docs/zh-CN/architecture_explained.md +116 -0
  102. package/docs/zh-CN/cli.md +109 -0
  103. package/docs/zh-CN/dsr.md +91 -0
  104. package/docs/zh-CN/graph_scenarios.md +173 -0
  105. package/docs/zh-CN/hooks.md +14 -0
  106. package/docs/zh-CN/manifests.md +136 -0
  107. package/docs/zh-CN/mcp.md +205 -0
  108. package/docs/zh-CN/quickstart.md +35 -0
  109. package/docs/zh-CN/rules.md +7 -0
  110. package/docs/zh-CN/technical-details.md +454 -0
  111. package/docs/zh-CN/troubleshooting.md +19 -0
  112. package/docs/zh-CN/windows-setup.md +67 -0
  113. package/install.sh +183 -0
  114. package/package.json +97 -0
  115. package/skills/git-ai-mcp/SKILL.md +86 -0
  116. package/skills/git-ai-mcp/references/constraints.md +143 -0
  117. package/skills/git-ai-mcp/references/tools.md +263 -0
  118. package/templates/agents/common/documents/Fix EISDIR error and enable multi-language indexing.md +14 -0
  119. package/templates/agents/common/documents/Fix git-ai index error in CodaGraph directory.md +13 -0
  120. package/templates/agents/common/skills/git-ai-mcp/SKILL.md +86 -0
  121. package/templates/agents/common/skills/git-ai-mcp/references/constraints.md +143 -0
  122. package/templates/agents/common/skills/git-ai-mcp/references/tools.md +263 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mars167
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.
22
+
package/README.md ADDED
@@ -0,0 +1,364 @@
1
+ <p align="center">
2
+ <img src="docs/logo.png" alt="git-ai logo" width="200"/>
3
+ </p>
4
+
5
+ # git-ai
6
+
7
+ [![ci](https://github.com/mars167/git-ai-cli/actions/workflows/ci.yml/badge.svg)](https://github.com/mars167/git-ai-cli/actions/workflows/ci.yml)
8
+ [![release](https://github.com/mars167/git-ai-cli/actions/workflows/release.yml/badge.svg)](https://github.com/mars167/git-ai-cli/actions/workflows/release.yml)
9
+ [![license](https://img.shields.io/github/license/mars167/git-ai-cli)](./LICENSE)
10
+ [![npm (github packages)](https://img.shields.io/npm/v/%40mars167%2Fgit-ai?registry_uri=https%3A%2F%2Fnpm.pkg.github.com)](https://github.com/mars167/git-ai-cli/packages)
11
+ [![npm](https://img.shields.io/npm/dm/%40mars167%2Fgit-ai?label=npm%20downloads)](https://www.npmjs.com/package/%40mars167%2Fgit-ai)
12
+
13
+ [🇨🇳 简体中文](./README.zh-CN.md) | **English**
14
+
15
+ ---
16
+
17
+ ## Adding a Semantic Layer to Your Codebase, Enabling AI to Evolve from "Reading Code" to "Understanding Code"
18
+
19
+ **Code semantics should be versioned and traceable, just like code itself**
20
+
21
+ git-ai is a local code understanding tool that builds a traceable semantic layer for your codebase using DSR (Deterministic Semantic Record) and Hyper RAG, enabling AI Agents and developers to truly understand code evolution and relationships.
22
+
23
+ ### ✨ Why git-ai?
24
+
25
+ - **🔗 Hyper RAG**: Combines vector retrieval + graph retrieval + DSR for multi-dimensional semantic understanding
26
+ - **📜 Versioned Semantics**: Every commit has a semantic snapshot, historical changes are clear and traceable
27
+ - **🔄 Always Available**: Indices travel with code, available immediately after checkout, no rebuild needed
28
+ - **🤖 AI-Native**: MCP Server enables Claude, Trae and other Agents to deeply understand your codebase
29
+ - **🔒 Fully Local**: Code never leaves your machine, secure and private
30
+ - **⚡ Full Lifecycle Support**: From development to Review to refactoring, indices span the entire lifecycle
31
+ - **📊 Blazing Fast**: 10k files indexed in < 30s, search response < 100ms
32
+
33
+ ---
34
+
35
+ ## ✨ Core Capabilities
36
+
37
+ ### 1️⃣ Semantic Search
38
+
39
+ Find code using natural language, no need to remember file names or function names:
40
+
41
+ ```bash
42
+ git-ai ai semantic "user authentication logic"
43
+ git-ai ai semantic "database connection pool configuration"
44
+ git-ai ai semantic "error handling middleware"
45
+ ```
46
+
47
+ ### 2️⃣ Symbol Relationship Analysis
48
+
49
+ Understand relationships between code:
50
+
51
+ ```bash
52
+ # Find function callers
53
+ git-ai ai graph callers authenticateUser
54
+
55
+ # Find functions called by this function
56
+ git-ai ai graph callees authenticateUser
57
+
58
+ # Trace complete call chain
59
+ git-ai ai graph chain authenticateUser --max-depth 3
60
+ ```
61
+
62
+ ### 3️⃣ Historical Change Tracing
63
+
64
+ Track symbol evolution through DSR:
65
+
66
+ ```bash
67
+ # View function's historical changes
68
+ git-ai ai dsr query symbol-evolution authenticateUser --limit 50
69
+
70
+ # View complete semantic snapshot for a commit
71
+ git-ai ai dsr context
72
+ ```
73
+
74
+ ### 4️⃣ Multi-Language Support
75
+
76
+ Supports multiple mainstream programming languages:
77
+
78
+ | Language | File Extensions |
79
+ |----------|-----------------|
80
+ | JavaScript | `.js`, `.jsx` |
81
+ | TypeScript | `.ts`, `.tsx` |
82
+ | Java | `.java` |
83
+ | Python | `.py` |
84
+ | Go | `.go` |
85
+ | Rust | `.rs` |
86
+ | C | `.c`, `.h` |
87
+ | Markdown | `.md`, `.mdx` |
88
+ | YAML | `.yml`, `.yaml` |
89
+
90
+ ---
91
+
92
+ ## 💡 Design Philosophy
93
+
94
+ git-ai is not just a search tool, but a "semantic timeline" for your codebase:
95
+
96
+ ### DSR (Deterministic Semantic Record)
97
+
98
+ Each commit corresponds to an immutable semantic snapshot, recording the code structure, symbol relationships, and design intent at that time. Code semantics should be versioned—just like code itself—traceable, comparable, and evolvable.
99
+
100
+ ### Hyper RAG
101
+
102
+ Combines multiple retrieval methods for deeper understanding:
103
+ - **Vector Retrieval**: Semantic similarity matching
104
+ - **Graph Retrieval**: Call relationship, inheritance analysis
105
+ - **DSR Retrieval**: Historical evolution tracing
106
+
107
+ ### Decentralized Semantics
108
+
109
+ Indices travel with code, no central server required. checkout, branch, tag—all can use consistent semantic indices immediately.
110
+
111
+ ### Server Mode
112
+
113
+ MCP Server enables any AI Agent to invoke indices, achieving true AI-assisted development.
114
+
115
+ ---
116
+
117
+ ## 🎯 Use Cases
118
+
119
+ ### Scenario 1: Newcomers Quickly Understanding Large Projects
120
+
121
+ > "Just joined the team, facing 100k lines of code, where do I start?"
122
+
123
+ ```bash
124
+ # 1. Get project global view
125
+ git-ai ai repo-map --max-files 20
126
+
127
+ # 2. Search core business logic
128
+ git-ai ai semantic "order processing flow"
129
+
130
+ # 3. Trace key function call chains
131
+ git-ai ai graph chain processOrder --max-depth 5
132
+ ```
133
+ *From design to development, semantic indices remain consistent*
134
+
135
+ ### Scenario 2: Pre-Refactoring Impact Analysis
136
+
137
+ > "About to refactor this function, what will it affect?"
138
+
139
+ ```bash
140
+ # Find all callers
141
+ git-ai ai graph callers deprecatedFunction
142
+
143
+ # Trace historical changes, understand design intent
144
+ git-ai ai dsr query symbol-evolution deprecatedFunction --all
145
+ ```
146
+ *DSR traces historical changes, understanding design intent*
147
+
148
+ ### Scenario 3: Bug Localization and Root Cause Analysis
149
+
150
+ > "User reported an error, but don't know where the problem is"
151
+
152
+ ```bash
153
+ # Search related error handling code
154
+ git-ai ai semantic "user login failure handling"
155
+
156
+ # View error propagation path
157
+ git-ai ai graph chain handleLoginError --direction upstream
158
+ ```
159
+ *Full lifecycle indices, quickly locate problem roots*
160
+
161
+ ### Scenario 4: AI Agent-Assisted Development
162
+
163
+ > "Let Claude Desktop help me understand this project"
164
+
165
+ After configuring git-ai MCP Server in Claude Desktop, you can converse directly:
166
+
167
+ > "Help me analyze this project's architecture, find all payment-related code, and explain their relationships"
168
+
169
+ Claude will automatically invoke git-ai tools to provide deep analysis. *Enabling AI to evolve from "reading code" to "understanding code"*
170
+
171
+ ---
172
+
173
+ ## 🏗️ System Architecture
174
+
175
+ ```mermaid
176
+ graph TB
177
+ A[Git Repository] -->|On Commit| B[DSR\nDeterministic Semantic Record]
178
+ B --> C[.git-ai/dsr/commit.json\nSemantic Snapshot]
179
+ C -->|Index Rebuild| D[LanceDB\nVector Database]
180
+ C -->|Index Rebuild| E[CozoDB\nGraph Database]
181
+ D --> F[MCP Server]
182
+ E --> F
183
+ F -->|Tool Call| G[AI Agent\nClaude Desktop / Trae]
184
+ F -->|CLI| H[Developer]
185
+ C -->|Cross-Version| I[Semantic Timeline\nTraceable · Comparable · Evolvable]
186
+ style B fill:#e1f5ff,stroke:#333
187
+ style C fill:#e8f5e9,stroke:#333
188
+ style D fill:#fff4e1,stroke:#333
189
+ style E fill:#fff4e1,stroke:#333
190
+ style F fill:#e8f5e9,stroke:#333
191
+ style G fill:#f3e5f5,stroke:#333
192
+ style I fill:#fce4ec,stroke:#333
193
+ ```
194
+
195
+ **Core Components**:
196
+
197
+ - **DSR (Deterministic Semantic Record)**: Immutable semantic snapshots stored per commit, versioned semantics
198
+ - **LanceDB + SQ8**: High-performance vector database, supporting semantic search
199
+ - **CozoDB**: Graph database, supporting AST-level relationship queries
200
+ - **MCP Server**: Standard protocol interface, for AI Agent invocation
201
+
202
+ ---
203
+
204
+ ## 📊 Comparison with Other Tools
205
+
206
+ | Feature | git-ai | GitHub Code Search | Sourcegraph |
207
+ |---------|--------|-------------------|-------------|
208
+ | Local Execution | ✅ | ❌ | ❌ |
209
+ | AST-Level Analysis | ✅ | ❌ | ✅ |
210
+ | Versioned Semantics | ✅ | ❌ | ❌ |
211
+ | Historical Change Tracing | ✅ | ❌ | ❌ |
212
+ | AI Agent Integration | ✅ | ❌ | ❌ |
213
+ | Free & Open Source | ✅ | ❌ | ❌ |
214
+ | Semantic Search | ✅ | ✅ | ✅ |
215
+ | Call Chain Analysis | ✅ | ❌ | ✅ |
216
+
217
+ ---
218
+
219
+ ## 🚀 Quick Start
220
+
221
+ ### 1. Install
222
+
223
+ ```bash
224
+ npm install -g git-ai
225
+ ```
226
+
227
+ ### 2. Initialize Repository
228
+
229
+ ```bash
230
+ cd your-project
231
+ git-ai ai index --overwrite
232
+ ```
233
+
234
+ ### 3. Start Using Immediately
235
+
236
+ ```bash
237
+ # Search code using natural language
238
+ git-ai ai semantic "user authentication logic"
239
+
240
+ # View function call relationships
241
+ git-ai ai graph callers authenticateUser
242
+ ```
243
+
244
+ **Actual Output Example**:
245
+ ```json
246
+ [
247
+ {
248
+ "file": "src/auth/service.ts",
249
+ "line": 45,
250
+ "symbol": "authenticateUser",
251
+ "context": "async function authenticateUser(email: string, password: string)"
252
+ },
253
+ {
254
+ "file": "src/controllers/auth.ts",
255
+ "line": 23,
256
+ "symbol": "loginHandler",
257
+ "context": "const user = await authenticateUser(req.body.email, req.body.password)"
258
+ }
259
+ ]
260
+ ```
261
+
262
+ That's it! 3 steps to get started, immediately begin deep understanding of your codebase.
263
+
264
+ *From now on, indices are not "one-time artifacts" but "semantic assets" that evolve with your code.*
265
+
266
+ ---
267
+
268
+ ## 🤖 AI Agent Integration
269
+
270
+ git-ai provides a standard MCP Server that seamlessly integrates with:
271
+
272
+ - **Claude Desktop**: The most popular local AI programming assistant
273
+ - **Trae**: Powerful AI-driven IDE
274
+ - **Continue.dev**: VS Code AI plugin
275
+
276
+ ### Claude Desktop Configuration Example
277
+
278
+ Add to `~/.claude/claude_desktop_config.json`:
279
+
280
+ ```json
281
+ {
282
+ "mcpServers": {
283
+ "git-ai": {
284
+ "command": "git-ai",
285
+ "args": ["ai", "serve"]
286
+ }
287
+ }
288
+ }
289
+ ```
290
+
291
+ Then restart Claude Desktop and start conversing:
292
+
293
+ > "Help me analyze this project's architecture, find all payment-related code"
294
+
295
+ Claude will automatically invoke git-ai tools to provide deep analysis.
296
+
297
+ ### Agent Skills & Rules
298
+
299
+ We provide carefully designed Agent templates to help AI use git-ai better:
300
+
301
+ - [Skill Template](./templates/agents/common/skills/git-ai-mcp/SKILL.md): Guides Agents on how to use tools
302
+ - [Rule Template](./templates/agents/common/rules/git-ai-mcp/RULE.md): Constrains Agent behavior
303
+
304
+ Skills/Rules docs (Markdown/YAML) are indexed as part of semantic search, so agents can retrieve MCP guidance via `semantic_search`.
305
+
306
+ One-click install to your project:
307
+
308
+ ```bash
309
+ git-ai ai agent install
310
+ ```
311
+
312
+ ---
313
+
314
+ ## 📚 Documentation
315
+
316
+ - [Quick Start](./docs/README.md)
317
+ - [MCP Server Guide](./docs/mcp.md)
318
+ - [Architecture Explained](./docs/architecture_explained.md)
319
+ - [Design Document](./docs/design.md)
320
+ - [Development Guide](./DEVELOPMENT.md)
321
+
322
+ ---
323
+
324
+ ## 🔧 Advanced Features
325
+
326
+ ### Git Hooks Automation
327
+
328
+ Automatically rebuild indices before commit, verify pack before push:
329
+
330
+ ```bash
331
+ git-ai ai hooks install
332
+ ```
333
+
334
+ - `pre-commit`: Auto incremental index + pack
335
+ - `pre-push`: Verify pack
336
+ - `post-checkout`: Auto unpack
337
+
338
+ ### Git LFS Integration
339
+
340
+ Recommended for managing index archives:
341
+
342
+ ```bash
343
+ git lfs track ".git-ai/lancedb.tar.gz"
344
+ git-ai ai pack --lfs
345
+ ```
346
+
347
+ ---
348
+
349
+ ## 🤝 Contributing
350
+
351
+ Welcome contributions, issue reports, and suggestions!
352
+
353
+ - [Contribution Guide](./CONTRIBUTING.md)
354
+ - [Issue Tracker](https://github.com/mars167/git-ai-cli/issues)
355
+
356
+ ---
357
+
358
+ ## 📄 License
359
+
360
+ [MIT](./LICENSE)
361
+
362
+ ---
363
+
364
+ **Enabling AI to Evolve from "Reading Code" to "Understanding Code"** ⭐ Star us on GitHub!