@zvec/zvec-grep 0.1.3 → 0.1.5

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 (135) hide show
  1. package/README.md +127 -42
  2. package/README_CN.md +124 -42
  3. package/dist/cli/args.d.ts +3 -0
  4. package/dist/cli/args.js +490 -192
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/cli/commands.d.ts +3 -1
  7. package/dist/cli/commands.js +590 -56
  8. package/dist/cli/commands.js.map +1 -1
  9. package/dist/cli/errors.js +6 -5
  10. package/dist/cli/errors.js.map +1 -1
  11. package/dist/cli/format/context.js +33 -29
  12. package/dist/cli/format/context.js.map +1 -1
  13. package/dist/cli/format/debug.js +12 -14
  14. package/dist/cli/format/debug.js.map +1 -1
  15. package/dist/cli/format/highlight.js.map +1 -1
  16. package/dist/cli/format/progress.js +8 -3
  17. package/dist/cli/format/progress.js.map +1 -1
  18. package/dist/cli/format/range.js.map +1 -1
  19. package/dist/cli/format/status.js +88 -26
  20. package/dist/cli/format/status.js.map +1 -1
  21. package/dist/cli/help.d.ts +1 -1
  22. package/dist/cli/help.js +170 -85
  23. package/dist/cli/help.js.map +1 -1
  24. package/dist/cli/index.js +4 -4
  25. package/dist/cli/index.js.map +1 -1
  26. package/dist/cli/mcp.d.ts +2 -0
  27. package/dist/cli/mcp.js +354 -0
  28. package/dist/cli/mcp.js.map +1 -0
  29. package/dist/cli/types.d.ts +22 -9
  30. package/dist/cli/types.js.map +1 -1
  31. package/dist/cli/version.js +3 -1
  32. package/dist/cli/version.js.map +1 -1
  33. package/dist/engine/collection/index.js +15 -15
  34. package/dist/engine/collection/index.js.map +1 -1
  35. package/dist/engine/config.d.ts +28 -0
  36. package/dist/engine/config.js +195 -0
  37. package/dist/engine/config.js.map +1 -0
  38. package/dist/engine/errors/details.js.map +1 -1
  39. package/dist/engine/errors/index.js.map +1 -1
  40. package/dist/engine/extraction/code/adapter.js.map +1 -1
  41. package/dist/engine/extraction/code/extractor.js +87 -73
  42. package/dist/engine/extraction/code/extractor.js.map +1 -1
  43. package/dist/engine/extraction/code/families/c-family.js +12 -6
  44. package/dist/engine/extraction/code/families/c-family.js.map +1 -1
  45. package/dist/engine/extraction/code/families/js-ts.js +24 -18
  46. package/dist/engine/extraction/code/families/js-ts.js.map +1 -1
  47. package/dist/engine/extraction/code/families/metadata.js +11 -8
  48. package/dist/engine/extraction/code/families/metadata.js.map +1 -1
  49. package/dist/engine/extraction/code/families/name-field.js +5 -5
  50. package/dist/engine/extraction/code/families/name-field.js.map +1 -1
  51. package/dist/engine/extraction/code/languages/c.js +1 -4
  52. package/dist/engine/extraction/code/languages/c.js.map +1 -1
  53. package/dist/engine/extraction/code/languages/cpp.js.map +1 -1
  54. package/dist/engine/extraction/code/languages/go.js +1 -3
  55. package/dist/engine/extraction/code/languages/go.js.map +1 -1
  56. package/dist/engine/extraction/code/languages/java.js.map +1 -1
  57. package/dist/engine/extraction/code/languages/javascript.js +1 -3
  58. package/dist/engine/extraction/code/languages/javascript.js.map +1 -1
  59. package/dist/engine/extraction/code/languages/python.js +5 -6
  60. package/dist/engine/extraction/code/languages/python.js.map +1 -1
  61. package/dist/engine/extraction/code/languages/rust.js +1 -5
  62. package/dist/engine/extraction/code/languages/rust.js.map +1 -1
  63. package/dist/engine/extraction/code/languages/typescript.js.map +1 -1
  64. package/dist/engine/extraction/ids.js.map +1 -1
  65. package/dist/engine/extraction/index.js +3 -3
  66. package/dist/engine/extraction/index.js.map +1 -1
  67. package/dist/engine/extraction/markdown/extractor.js +4 -2
  68. package/dist/engine/extraction/markdown/extractor.js.map +1 -1
  69. package/dist/engine/extraction/tree-sitter/grammar.js.map +1 -1
  70. package/dist/engine/extraction/tree-sitter/nodes.js +2 -1
  71. package/dist/engine/extraction/tree-sitter/nodes.js.map +1 -1
  72. package/dist/engine/extraction/tree-sitter/parser.js.map +1 -1
  73. package/dist/engine/files/file-type.js.map +1 -1
  74. package/dist/engine/models/catalog.js +7 -23
  75. package/dist/engine/models/catalog.js.map +1 -1
  76. package/dist/engine/models/embeddings.js +3 -3
  77. package/dist/engine/models/embeddings.js.map +1 -1
  78. package/dist/engine/models/factory.js.map +1 -1
  79. package/dist/engine/models/index.d.ts +1 -1
  80. package/dist/engine/models/index.js.map +1 -1
  81. package/dist/engine/models/providers/index.d.ts +1 -1
  82. package/dist/engine/models/providers/index.js +1 -1
  83. package/dist/engine/models/providers/index.js.map +1 -1
  84. package/dist/engine/models/providers/llama-cpp/embedding.js +49 -18
  85. package/dist/engine/models/providers/llama-cpp/embedding.js.map +1 -1
  86. package/dist/engine/models/providers/qwen/embedding.js +16 -11
  87. package/dist/engine/models/providers/qwen/embedding.js.map +1 -1
  88. package/dist/engine/models/providers/qwen/index.d.ts +1 -1
  89. package/dist/engine/models/providers/qwen/index.js +1 -1
  90. package/dist/engine/models/providers/qwen/index.js.map +1 -1
  91. package/dist/engine/pipeline/indexing/index.js +46 -33
  92. package/dist/engine/pipeline/indexing/index.js.map +1 -1
  93. package/dist/engine/pipeline/indexing/root-paths.js +10 -13
  94. package/dist/engine/pipeline/indexing/root-paths.js.map +1 -1
  95. package/dist/engine/pipeline/indexing/scanner/index.js +121 -46
  96. package/dist/engine/pipeline/indexing/scanner/index.js.map +1 -1
  97. package/dist/engine/pipeline/search/index.js +68 -24
  98. package/dist/engine/pipeline/search/index.js.map +1 -1
  99. package/dist/engine/service/index.d.ts +1 -1
  100. package/dist/engine/service/lexical.d.ts +14 -15
  101. package/dist/engine/service/lexical.js +78 -114
  102. package/dist/engine/service/lexical.js.map +1 -1
  103. package/dist/engine/service/root.js +2 -2
  104. package/dist/engine/service/root.js.map +1 -1
  105. package/dist/engine/service/structure-enrichment.js +17 -11
  106. package/dist/engine/service/structure-enrichment.js.map +1 -1
  107. package/dist/engine/service/types.d.ts +39 -8
  108. package/dist/engine/service/zvec-grep.js +303 -160
  109. package/dist/engine/service/zvec-grep.js.map +1 -1
  110. package/dist/engine/storage/index.js.map +1 -1
  111. package/dist/engine/storage/zvec.js +49 -28
  112. package/dist/engine/storage/zvec.js.map +1 -1
  113. package/dist/engine/types.d.ts +14 -0
  114. package/dist/engine/types.js.map +1 -1
  115. package/dist/engine/utils/file-selection.d.ts +10 -0
  116. package/dist/engine/utils/file-selection.js +120 -0
  117. package/dist/engine/utils/file-selection.js.map +1 -0
  118. package/dist/engine/utils/glob.d.ts +3 -0
  119. package/dist/engine/utils/glob.js +116 -18
  120. package/dist/engine/utils/glob.js.map +1 -1
  121. package/dist/engine/utils/hash.js.map +1 -1
  122. package/dist/engine/utils/json.d.ts +6 -2
  123. package/dist/engine/utils/json.js +50 -12
  124. package/dist/engine/utils/json.js.map +1 -1
  125. package/dist/engine/utils/lock.js +6 -6
  126. package/dist/engine/utils/lock.js.map +1 -1
  127. package/dist/engine/utils/path.js +2 -2
  128. package/dist/engine/utils/path.js.map +1 -1
  129. package/dist/engine/utils/timing.js.map +1 -1
  130. package/dist/index.d.ts +3 -3
  131. package/dist/index.js +2 -2
  132. package/dist/index.js.map +1 -1
  133. package/package.json +34 -7
  134. package/skills/zvec-grep/SKILL.md +58 -48
  135. package/skills/zvec-grep/agents/openai.yaml +1 -1
package/README.md CHANGED
@@ -11,8 +11,9 @@
11
11
 
12
12
  <p align="center">
13
13
  <a href="https://www.npmjs.com/package/@zvec/zvec-grep"><img src="https://img.shields.io/npm/v/@zvec/zvec-grep.svg" alt="npm Release"/></a>
14
+ <a href="https://github.com/zvec-ai/zvec-grep/actions/workflows/ci.yml"><img src="https://github.com/zvec-ai/zvec-grep/actions/workflows/ci.yml/badge.svg" alt="CI"/></a>
14
15
  <a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="License"/></a>
15
- <img src="https://img.shields.io/badge/node-%3E%3D20-blue.svg" alt="Node.js >=20"/>
16
+ <img src="https://img.shields.io/badge/node-%3E%3D22-blue.svg" alt="Node.js >=22"/>
16
17
  <img src="https://img.shields.io/badge/CLI-zg-2ea44f.svg" alt="zg CLI"/>
17
18
  </p>
18
19
 
@@ -29,17 +30,17 @@
29
30
  The command is intentionally short:
30
31
 
31
32
  ```bash
32
- zg "where query auto update happens"
33
+ zg query "where query auto update happens"
33
34
  ```
34
35
 
35
36
  > [!IMPORTANT]
36
- > **v0.1.3**
37
+ > **Command interface**
37
38
  >
38
39
  > - **Hybrid Code Search**: Query code with natural language, exact terms, or both in one command.
39
- > - **Explicit Index Lifecycle**: New repositories require `zg --index --embedding <model>`; agents do not silently create indexes.
40
+ > - **Explicit Index Lifecycle**: New repositories require `zg index --embedding <model>`; agents do not silently create indexes.
40
41
  > - **Automatic Refresh**: Existing anonymous indexes are checked and incrementally updated before normal queries.
41
42
  > - **Token-Efficient Output**: Agent output defaults to `--preview none`; `--human` defaults to full source previews.
42
- > - **No-Index Lexical Search**: `zg --rg` provides managed ripgrep search without requiring an index.
43
+ > - **No-Index Lexical Search**: `zg query --rg` provides managed ripgrep search without requiring an index.
43
44
 
44
45
  ## <a id="features"></a>💫 Features
45
46
 
@@ -47,9 +48,10 @@ zg "where query auto update happens"
47
48
  - **Root-Local Indexes**: Anonymous indexes live under `<repo>/.zvec-grep/`, so repository state stays with the repository.
48
49
  - **Agent-Ready Output**: Default output is grouped by file and keeps previews small to save tokens.
49
50
  - **Human Output Mode**: Add `--human` for a terminal-friendly summary with full previews by default.
50
- - **Managed ripgrep Route**: `zg --rg` supports common `rg` flags and works even before a repository is indexed.
51
+ - **Managed ripgrep Route**: `zg query --rg` supports common `rg` flags and works even before a repository is indexed.
51
52
  - **Explicit Model Choice**: The first index build requires a model such as `local/embeddinggemma-300m`, `local/qwen3-embedding-0.6b`, or `qwen/text-embedding-v4`.
52
- - **Schema Reuse**: Re-running `zg --index` on an existing index reuses the stored embedding schema unless you explicitly change it.
53
+ - **Schema Reuse**: Re-running `zg index` on an existing index reuses the stored embedding schema unless you explicitly change it.
54
+ - **MCP Server**: Run `zg serve --mcp` to expose indexed and no-index lexical search tools to MCP clients. Indexing and status remain CLI-only operations.
53
55
  - **Library API**: Use `createZvecGrep()` directly from Node.js tools, agents, or MCP servers.
54
56
 
55
57
  ## <a id="installation"></a>📦 Installation
@@ -58,87 +60,137 @@ Install the CLI from npm:
58
60
 
59
61
  ```bash
60
62
  npm install -g @zvec/zvec-grep
61
- zg --version
63
+ zg version
62
64
  ```
63
65
 
64
66
  Or run it without a global install:
65
67
 
66
68
  ```bash
67
- npx @zvec/zvec-grep --help
69
+ npx @zvec/zvec-grep help
68
70
  ```
69
71
 
72
+ Install the latest source checkout as a global `zg` command:
73
+
74
+ ```bash
75
+ git clone https://github.com/zvec-ai/zvec-grep.git
76
+ cd zvec-grep
77
+ npm ci
78
+ npm run build
79
+ npm install -g .
80
+ zg version
81
+ ```
82
+
83
+ Run the stdio MCP server:
84
+
85
+ ```bash
86
+ zg serve --mcp
87
+ ```
88
+
89
+ Install the Codex MCP integration:
90
+
91
+ ```bash
92
+ zg install --target codex --yes
93
+ ```
94
+
95
+ Codex MCP tool calls default to a 600-second timeout. Override it during installation with `--mcp-tool-timeout <seconds>`.
96
+
70
97
  ### ✅ Requirements
71
98
 
72
- - Node.js 20 or newer
99
+ - Node.js 22 or newer
73
100
  - macOS, Linux, or Windows
74
101
  - A supported embedding model for indexed search
75
102
 
76
- `zg --rg` works without any embedding model or index.
103
+ `zg query --rg` works without any embedding model or index.
77
104
 
78
105
  ## <a id="quickstart"></a>⚡ Quickstart
79
106
 
80
107
  Index a repository with an explicit embedding model:
81
108
 
82
109
  ```bash
83
- zg --index \
110
+ zg index \
84
111
  --embedding local/embeddinggemma-300m \
85
- --include "src/**" \
86
- --include "docs/**" \
87
- --include "test/**" \
88
- --exclude "dist/**,node_modules/**,coverage/**"
112
+ -g "src/**" \
113
+ -g "docs/**" \
114
+ -g "test/**" \
115
+ -g "!dist/**" \
116
+ -g "!node_modules/**" \
117
+ -g "!coverage/**"
89
118
  ```
90
119
 
91
120
  Check index state:
92
121
 
93
122
  ```bash
94
- zg --info
123
+ zg status
95
124
  ```
96
125
 
97
126
  Search with natural language:
98
127
 
99
128
  ```bash
100
- zg "where query auto update happens"
129
+ zg query "where query auto update happens"
101
130
  ```
102
131
 
103
132
  Combine semantic intent with exact anchors:
104
133
 
105
134
  ```bash
106
- zg "GPU fallback" --fts "usingCpuFallback" --include "src/**" --limit 5
135
+ zg query "GPU fallback" --fts "usingCpuFallback" -g "src/**" -t ts --limit 5
107
136
  ```
108
137
 
109
138
  Use exhaustive lexical search without an index:
110
139
 
111
140
  ```bash
112
- zg --rg -F "ZVEC_GREP_HOME" src
141
+ zg query --rg -F "ZVEC_GREP_HOME" src
113
142
  ```
114
143
 
115
144
  Switch to human-readable output:
116
145
 
117
146
  ```bash
118
- zg --human "root local index discovery" --limit 3
147
+ zg query --human "root local index discovery" --limit 3
119
148
  ```
120
149
 
150
+ Use from an MCP client with `zvec_grep_search` and `zvec_grep_rg`. MCP inputs use JSON-friendly fields such as `include: ["src/**"]`; use the CLI for `zg status` and `zg index`. The Codex installer writes managed zvec-grep blocks to `${CODEX_HOME:-$HOME/.codex}/config.toml` and `${CODEX_HOME:-$HOME/.codex}/AGENTS.md`.
151
+
121
152
  ## <a id="models"></a>🧠 Models
122
153
 
123
154
  Local models run through `node-llama-cpp` and keep code search private to your machine:
124
155
 
125
156
  ```bash
126
- zg --index --embedding local/embeddinggemma-300m
127
- zg --index --embedding local/qwen3-embedding-0.6b
157
+ zg index --embedding local/embeddinggemma-300m
158
+ zg index --embedding local/qwen3-embedding-0.6b
128
159
  ```
129
160
 
161
+ On Apple Silicon, local builds use quiet llama.cpp CMake defaults to avoid harmless OpenMP and ARM native-detection warnings. Override any llama.cpp CMake option with `NODE_LLAMA_CPP_CMAKE_OPTION_<name>`, for example `NODE_LLAMA_CPP_CMAKE_OPTION_GGML_NATIVE=ON` to opt back into native CPU tuning.
162
+
130
163
  Remote Qwen embeddings are useful when you prefer a managed embedding service or want to avoid local model setup:
131
164
 
132
165
  ```bash
133
- zg --index \
166
+ zg index \
134
167
  --embedding qwen/text-embedding-v4 \
135
168
  --api-key "$DASHSCOPE_API_KEY"
136
169
  ```
137
170
 
138
- For existing indexes, `zg --index` without `--embedding` reuses the stored schema. Use `--rebuild --embedding <model>` only when you intentionally want to rebuild with a different model:
171
+ After a successful index, explicitly passed global model and provider options are saved to `~/.zvec-grep/config.json` with user-only permissions. This lets an already-running `zg` MCP server load a newly configured remote API key on its next model request without restarting Codex. Values read only from environment variables are not persisted.
172
+
173
+ ```json
174
+ {
175
+ "version": 1,
176
+ "defaults": {
177
+ "embedding": "qwen/text-embedding-v4"
178
+ },
179
+ "providers": {
180
+ "qwen": {
181
+ "apiKey": "...",
182
+ "endpoint": "https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings"
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ Resolution order is explicit CLI or library options, then environment variables, then global config, then built-in defaults. Repository roots and file-selection settings remain in each repository's `.zvec-grep` metadata rather than global config.
189
+
190
+ For existing indexes, `zg index` without `--embedding` reuses the stored schema. Use `--rebuild --embedding <model>` only when you intentionally want to rebuild with a different model:
139
191
 
140
192
  ```bash
141
- zg --index --rebuild --embedding local/qwen3-embedding-0.6b
193
+ zg index --rebuild --embedding local/qwen3-embedding-0.6b
142
194
  ```
143
195
 
144
196
  ## 🔎 Query Patterns
@@ -146,32 +198,59 @@ zg --index --rebuild --embedding local/qwen3-embedding-0.6b
146
198
  Multiple quoted queries are treated as separate search groups:
147
199
 
148
200
  ```bash
149
- zg "request validation" "error handling" --limit 5
201
+ zg query "request validation" "error handling" --limit 5
150
202
  ```
151
203
 
152
- Use path filters early to keep results focused:
204
+ Route options each consume one query and can be repeated. Add `--fuse` when
205
+ you want all groups combined into one ranked result list:
153
206
 
154
207
  ```bash
155
- zg "cache invalidation" \
156
- --include "src/**" \
157
- --exclude "test/**,tests/**,fixtures/**,dist/**"
208
+ zg query \
209
+ --hybrid "authentication flow" \
210
+ --fts "AuthService" \
211
+ --vector "where credentials are validated" \
212
+ --fuse \
213
+ --limit 10
158
214
  ```
159
215
 
216
+ Use ripgrep-style path and file-type filters early to keep results focused.
217
+ Positive globs include paths and globs beginning with `!` exclude them:
218
+
219
+ ```bash
220
+ zg query "cache invalidation" \
221
+ -g "src/**" \
222
+ -g "!test/**" \
223
+ -g "!tests/**" \
224
+ -g "!fixtures/**" \
225
+ -g "!dist/**" \
226
+ -t ts
227
+ ```
228
+
229
+ File-type filters are applied in addition to glob filters. For example,
230
+ `-g "docs/**" -t ts` selects TypeScript files under `docs`, not every file in
231
+ that directory.
232
+
160
233
  Use `--preview` to control indexed source previews:
161
234
 
162
235
  ```bash
163
- zg "plugin lifecycle" --preview none
164
- zg "plugin lifecycle" --preview short --limit 5
165
- zg "plugin lifecycle" --preview full --limit 2
236
+ zg query "plugin lifecycle" --preview none
237
+ zg query "plugin lifecycle" --preview short --limit 5
238
+ zg query "plugin lifecycle" --preview full --limit 2
166
239
  ```
167
240
 
168
241
  For exact text, symbols, flags, or error codes, use `--fts` or `--rg`:
169
242
 
170
243
  ```bash
171
- zg "authentication flow" --fts "AuthService" "ForbiddenError"
172
- zg --rg -i -C 2 -g "*.ts" "needle text" src
244
+ zg query "authentication flow" --fts "AuthService" --fts "ForbiddenError"
245
+ zg query --rg -i -C 2 -g "*.ts" "needle text" src
173
246
  ```
174
247
 
248
+ Managed rg mode accepts common ripgrep matching, context, type, glob, ignore,
249
+ depth, size, symlink, encoding, and regex-engine options. Zvec-grep owns the
250
+ result format, so output-changing modes such as `--json`, `--count`, `--files`,
251
+ `-l`, `-o`, `--replace`, and `--vimgrep` are rejected. `.git/**` and
252
+ `.zvec-grep/**` remain excluded.
253
+
175
254
  ## <a id="library-api"></a>🛠️ Library API
176
255
 
177
256
  ```ts
@@ -187,7 +266,11 @@ const result = await zvecGrep.context({
187
266
  });
188
267
 
189
268
  for (const item of result.items) {
190
- console.log(`${item.file.relativePath}:${item.range.startLine}`);
269
+ const location =
270
+ item.range.kind === "text"
271
+ ? `${item.file.relativePath}:${item.range.startLine}`
272
+ : item.file.relativePath;
273
+ console.log(location);
191
274
  }
192
275
 
193
276
  await zvecGrep.close();
@@ -206,10 +289,10 @@ const result = await zvecGrep.context({
206
289
 
207
290
  <div align="center">
208
291
 
209
- | 💬 DingTalk | 📱 WeChat | 🎮 Discord | X (Twitter) |
210
- | :---: | :---: | :---: | :---: |
211
- | <img src="https://zvec.oss-cn-hongkong.aliyuncs.com/qrcode/dingding.png" width="150" alt="DingTalk QR Code"/> | <img src="https://zvec.oss-cn-hongkong.aliyuncs.com/qrcode/wechat.png?v=6" width="150" alt="WeChat QR Code"/> | [![Discord](https://img.shields.io/badge/Discord-Join%20Server-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/rKddFBBu9z) | [![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ZvecAI)](<https://x.com/ZvecAI>) |
212
- | Scan to join | Scan to join | Click to join | Click to follow |
292
+ | 💬 DingTalk | 📱 WeChat | 🎮 Discord | X (Twitter) |
293
+ | :-----------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
294
+ | <img src="https://zvec.oss-cn-hongkong.aliyuncs.com/qrcode/dingding.png" width="150" alt="DingTalk QR Code"/> | <img src="https://zvec.oss-cn-hongkong.aliyuncs.com/qrcode/wechat.png?v=6" width="150" alt="WeChat QR Code"/> | [![Discord](https://img.shields.io/badge/Discord-Join%20Server-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/rKddFBBu9z) | [![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ZvecAI)](https://x.com/ZvecAI) |
295
+ | Scan to join | Scan to join | Click to join | Click to follow |
213
296
 
214
297
  </div>
215
298
 
@@ -218,5 +301,7 @@ const result = await zvecGrep.context({
218
301
  Issues and pull requests are welcome. Please keep changes focused, add tests for behavior changes, and run:
219
302
 
220
303
  ```bash
221
- npm test
304
+ npm run check
222
305
  ```
306
+
307
+ Pull request titles use Conventional Commits syntax.
package/README_CN.md CHANGED
@@ -11,8 +11,9 @@
11
11
 
12
12
  <p align="center">
13
13
  <a href="https://www.npmjs.com/package/@zvec/zvec-grep"><img src="https://img.shields.io/npm/v/@zvec/zvec-grep.svg" alt="npm 版本"/></a>
14
+ <a href="https://github.com/zvec-ai/zvec-grep/actions/workflows/ci.yml"><img src="https://github.com/zvec-ai/zvec-grep/actions/workflows/ci.yml/badge.svg" alt="CI"/></a>
14
15
  <a href="./LICENSE"><img src="https://img.shields.io/badge/license-Apache%202.0-blue.svg" alt="许可证"/></a>
15
- <img src="https://img.shields.io/badge/node-%3E%3D20-blue.svg" alt="Node.js >=20"/>
16
+ <img src="https://img.shields.io/badge/node-%3E%3D22-blue.svg" alt="Node.js >=22"/>
16
17
  <img src="https://img.shields.io/badge/CLI-zg-2ea44f.svg" alt="zg CLI"/>
17
18
  </p>
18
19
 
@@ -29,17 +30,17 @@
29
30
  命令非常短:
30
31
 
31
32
  ```bash
32
- zg "where query auto update happens"
33
+ zg query "where query auto update happens"
33
34
  ```
34
35
 
35
36
  > [!IMPORTANT]
36
- > **v0.1.3**
37
+ > **命令接口**
37
38
  >
38
39
  > - **混合代码检索**:可以用自然语言、精确关键词,或两者组合来搜索代码。
39
- > - **明确的索引生命周期**:新仓库必须显式运行 `zg --index --embedding <model>`;agent 不会静默创建索引。
40
+ > - **明确的索引生命周期**:新仓库必须显式运行 `zg index --embedding <model>`;agent 不会静默创建索引。
40
41
  > - **自动刷新**:已有匿名索引会在普通查询前自动检查并增量更新。
41
42
  > - **节省 Token 的输出**:agent 默认输出 `--preview none`;`--human` 默认展示完整源码 preview。
42
- > - **无索引文本搜索**:`zg --rg` 提供托管的 ripgrep 搜索,不需要先建索引。
43
+ > - **无索引文本搜索**:`zg query --rg` 提供托管的 ripgrep 搜索,不需要先建索引。
43
44
 
44
45
  ## <a id="features"></a>💫 核心特性
45
46
 
@@ -47,9 +48,10 @@ zg "where query auto update happens"
47
48
  - **仓库本地索引**:匿名索引存放在 `<repo>/.zvec-grep/`,索引状态跟随仓库。
48
49
  - **Agent 友好输出**:默认按文件分组,并尽量减少源码 preview,降低上下文成本。
49
50
  - **人类阅读模式**:加 `--human` 后更适合终端阅读,并默认展示完整 preview。
50
- - **托管 ripgrep 通道**:`zg --rg` 支持常见 `rg` 参数,未建索引仓库也能使用。
51
+ - **托管 ripgrep 通道**:`zg query --rg` 支持常见 `rg` 参数,未建索引仓库也能使用。
51
52
  - **显式模型选择**:第一次建索引必须指定模型,例如 `local/embeddinggemma-300m`、`local/qwen3-embedding-0.6b` 或 `qwen/text-embedding-v4`。
52
- - **Schema 复用**:已有索引再次运行 `zg --index` 会复用保存的 embedding schema,除非你显式切换模型。
53
+ - **Schema 复用**:已有索引再次运行 `zg index` 会复用保存的 embedding schema,除非你显式切换模型。
54
+ - **MCP Server**:运行 `zg serve --mcp`,向 MCP 客户端暴露索引搜索和无索引文本搜索工具;建索引和状态查看仍由 CLI 提供。
53
55
  - **库 API**:Node.js 工具、agent 或 MCP server 可以直接使用 `createZvecGrep()`。
54
56
 
55
57
  ## <a id="installation"></a>📦 安装
@@ -58,87 +60,137 @@ zg "where query auto update happens"
58
60
 
59
61
  ```bash
60
62
  npm install -g @zvec/zvec-grep
61
- zg --version
63
+ zg version
62
64
  ```
63
65
 
64
66
  也可以不全局安装,直接运行:
65
67
 
66
68
  ```bash
67
- npx @zvec/zvec-grep --help
69
+ npx @zvec/zvec-grep help
68
70
  ```
69
71
 
72
+ 从最新源码构建,并将 `zg` 安装为全局命令:
73
+
74
+ ```bash
75
+ git clone https://github.com/zvec-ai/zvec-grep.git
76
+ cd zvec-grep
77
+ npm ci
78
+ npm run build
79
+ npm install -g .
80
+ zg version
81
+ ```
82
+
83
+ 运行 stdio MCP server:
84
+
85
+ ```bash
86
+ zg serve --mcp
87
+ ```
88
+
89
+ 安装 Codex MCP 集成:
90
+
91
+ ```bash
92
+ zg install --target codex --yes
93
+ ```
94
+
95
+ Codex MCP 工具调用默认超时为 600 秒,可在安装时通过 `--mcp-tool-timeout <秒数>` 覆盖。
96
+
70
97
  ### ✅ 运行要求
71
98
 
72
- - Node.js 20 或更新版本
99
+ - Node.js 22 或更新版本
73
100
  - macOS、Linux 或 Windows
74
101
  - 使用索引检索时需要选择一个支持的 embedding 模型
75
102
 
76
- `zg --rg` 不需要 embedding 模型,也不需要索引。
103
+ `zg query --rg` 不需要 embedding 模型,也不需要索引。
77
104
 
78
105
  ## <a id="quickstart"></a>⚡ 快速开始
79
106
 
80
107
  为仓库建索引,并显式指定 embedding 模型:
81
108
 
82
109
  ```bash
83
- zg --index \
110
+ zg index \
84
111
  --embedding local/embeddinggemma-300m \
85
- --include "src/**" \
86
- --include "docs/**" \
87
- --include "test/**" \
88
- --exclude "dist/**,node_modules/**,coverage/**"
112
+ -g "src/**" \
113
+ -g "docs/**" \
114
+ -g "test/**" \
115
+ -g "!dist/**" \
116
+ -g "!node_modules/**" \
117
+ -g "!coverage/**"
89
118
  ```
90
119
 
91
120
  查看索引状态:
92
121
 
93
122
  ```bash
94
- zg --info
123
+ zg status
95
124
  ```
96
125
 
97
126
  用自然语言搜索:
98
127
 
99
128
  ```bash
100
- zg "where query auto update happens"
129
+ zg query "where query auto update happens"
101
130
  ```
102
131
 
103
132
  组合语义意图和精确锚点:
104
133
 
105
134
  ```bash
106
- zg "GPU fallback" --fts "usingCpuFallback" --include "src/**" --limit 5
135
+ zg query "GPU fallback" --fts "usingCpuFallback" -g "src/**" -t ts --limit 5
107
136
  ```
108
137
 
109
138
  不依赖索引,做穷尽文本搜索:
110
139
 
111
140
  ```bash
112
- zg --rg -F "ZVEC_GREP_HOME" src
141
+ zg query --rg -F "ZVEC_GREP_HOME" src
113
142
  ```
114
143
 
115
144
  切换到适合人看的输出:
116
145
 
117
146
  ```bash
118
- zg --human "root local index discovery" --limit 3
147
+ zg query --human "root local index discovery" --limit 3
119
148
  ```
120
149
 
150
+ 在 MCP 客户端中可使用 `zvec_grep_search` 和 `zvec_grep_rg`。MCP 输入使用 JSON 友好的字段,例如 `include: ["src/**"]`;状态查看和建索引请使用 CLI 的 `zg status` 与 `zg index`。Codex installer 会向 `${CODEX_HOME:-$HOME/.codex}/config.toml` 和 `${CODEX_HOME:-$HOME/.codex}/AGENTS.md` 写入由 zvec-grep 管理的配置块。
151
+
121
152
  ## <a id="models"></a>🧠 模型
122
153
 
123
154
  本地模型通过 `node-llama-cpp` 运行,适合把代码检索留在本机:
124
155
 
125
156
  ```bash
126
- zg --index --embedding local/embeddinggemma-300m
127
- zg --index --embedding local/qwen3-embedding-0.6b
157
+ zg index --embedding local/embeddinggemma-300m
158
+ zg index --embedding local/qwen3-embedding-0.6b
128
159
  ```
129
160
 
161
+ 在 Apple Silicon 上,本地构建默认使用更安静的 llama.cpp CMake 配置,避免无害的 OpenMP 和 ARM native 探测 warning。可以通过 `NODE_LLAMA_CPP_CMAKE_OPTION_<name>` 覆盖任意 llama.cpp CMake 选项,例如设置 `NODE_LLAMA_CPP_CMAKE_OPTION_GGML_NATIVE=ON` 重新启用 native CPU 优化。
162
+
130
163
  远程 Qwen embedding 适合希望使用托管 embedding 服务,或不想在本机配置模型的场景:
131
164
 
132
165
  ```bash
133
- zg --index \
166
+ zg index \
134
167
  --embedding qwen/text-embedding-v4 \
135
168
  --api-key "$DASHSCOPE_API_KEY"
136
169
  ```
137
170
 
138
- 对于已有索引,`zg --index` 不传 `--embedding` 会复用索引里保存的 schema。只有在你明确想切换模型时,才使用 `--rebuild --embedding <model>`:
171
+ 索引成功后,通过 CLI 显式传入的全局模型和 provider 参数会保存到 `~/.zvec-grep/config.json`,并使用仅当前用户可读写的权限。已经运行的 `zg` MCP server 会在下一次需要模型时读取新的远程 API key,不需要重启 Codex。只从环境变量读取、没有作为 CLI 参数显式传入的值不会被持久化。
172
+
173
+ ```json
174
+ {
175
+ "version": 1,
176
+ "defaults": {
177
+ "embedding": "qwen/text-embedding-v4"
178
+ },
179
+ "providers": {
180
+ "qwen": {
181
+ "apiKey": "...",
182
+ "endpoint": "https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings"
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ 配置优先级为:显式 CLI 或库参数、环境变量、全局配置、内置默认值。仓库 root 和文件选择规则仍保存在各仓库自己的 `.zvec-grep` 元数据中,不进入全局配置。
189
+
190
+ 对于已有索引,`zg index` 不传 `--embedding` 会复用索引里保存的 schema。只有在你明确想切换模型时,才使用 `--rebuild --embedding <model>`:
139
191
 
140
192
  ```bash
141
- zg --index --rebuild --embedding local/qwen3-embedding-0.6b
193
+ zg index --rebuild --embedding local/qwen3-embedding-0.6b
142
194
  ```
143
195
 
144
196
  ## 🔎 查询模式
@@ -146,32 +198,56 @@ zg --index --rebuild --embedding local/qwen3-embedding-0.6b
146
198
  多个带引号的 query 会作为多个搜索组分别检索:
147
199
 
148
200
  ```bash
149
- zg "request validation" "error handling" --limit 5
201
+ zg query "request validation" "error handling" --limit 5
150
202
  ```
151
203
 
152
- 尽早使用路径过滤,让结果保持聚焦:
204
+ 每个 route 参数只接收一个 query,并且可以重复使用。需要把所有搜索组合并成一个排序结果时,使用 `--fuse`:
153
205
 
154
206
  ```bash
155
- zg "cache invalidation" \
156
- --include "src/**" \
157
- --exclude "test/**,tests/**,fixtures/**,dist/**"
207
+ zg query \
208
+ --hybrid "authentication flow" \
209
+ --fts "AuthService" \
210
+ --vector "where credentials are validated" \
211
+ --fuse \
212
+ --limit 10
158
213
  ```
159
214
 
215
+ 尽早使用与 ripgrep 一致的路径和文件类型过滤,让结果保持聚焦。普通 glob 表示包含,以 `!` 开头的 glob 表示排除:
216
+
217
+ ```bash
218
+ zg query "cache invalidation" \
219
+ -g "src/**" \
220
+ -g "!test/**" \
221
+ -g "!tests/**" \
222
+ -g "!fixtures/**" \
223
+ -g "!dist/**" \
224
+ -t ts
225
+ ```
226
+
227
+ 文件类型过滤会在 glob 过滤之后继续缩小范围。例如,`-g "docs/**" -t ts`
228
+ 只会选择 `docs` 目录下的 TypeScript 文件,而不是该目录里的所有文件。
229
+
160
230
  使用 `--preview` 控制索引结果的源码展示量:
161
231
 
162
232
  ```bash
163
- zg "plugin lifecycle" --preview none
164
- zg "plugin lifecycle" --preview short --limit 5
165
- zg "plugin lifecycle" --preview full --limit 2
233
+ zg query "plugin lifecycle" --preview none
234
+ zg query "plugin lifecycle" --preview short --limit 5
235
+ zg query "plugin lifecycle" --preview full --limit 2
166
236
  ```
167
237
 
168
238
  查精确文本、符号、配置项或错误码时,使用 `--fts` 或 `--rg`:
169
239
 
170
240
  ```bash
171
- zg "authentication flow" --fts "AuthService" "ForbiddenError"
172
- zg --rg -i -C 2 -g "*.ts" "needle text" src
241
+ zg query "authentication flow" --fts "AuthService" --fts "ForbiddenError"
242
+ zg query --rg -i -C 2 -g "*.ts" "needle text" src
173
243
  ```
174
244
 
245
+ 托管的 rg 模式支持常用的 ripgrep 匹配、上下文、文件类型、glob、ignore、
246
+ 深度、大小、符号链接、编码和正则引擎参数。结果格式由 zvec-grep 管理,
247
+ 因此 `--json`、`--count`、`--files`、`-l`、`-o`、`--replace` 和
248
+ `--vimgrep` 等会改变输出形态的模式会被拒绝。`.git/**` 和
249
+ `.zvec-grep/**` 始终保持排除。
250
+
175
251
  ## <a id="library-api"></a>🛠️ 库 API
176
252
 
177
253
  ```ts
@@ -187,7 +263,11 @@ const result = await zvecGrep.context({
187
263
  });
188
264
 
189
265
  for (const item of result.items) {
190
- console.log(`${item.file.relativePath}:${item.range.startLine}`);
266
+ const location =
267
+ item.range.kind === "text"
268
+ ? `${item.file.relativePath}:${item.range.startLine}`
269
+ : item.file.relativePath;
270
+ console.log(location);
191
271
  }
192
272
 
193
273
  await zvecGrep.close();
@@ -206,10 +286,10 @@ const result = await zvecGrep.context({
206
286
 
207
287
  <div align="center">
208
288
 
209
- | 💬 钉钉群 | 📱 微信群 | 🎮 Discord | X (Twitter) |
210
- | :---: | :---: | :---: | :---: |
211
- | <img src="https://zvec.oss-cn-hongkong.aliyuncs.com/qrcode/dingding.png" width="150" alt="钉钉二维码"/> | <img src="https://zvec.oss-cn-hongkong.aliyuncs.com/qrcode/wechat.png?v=6" width="150" alt="微信二维码"/> | [![Discord](https://img.shields.io/badge/Discord-Join%20Server-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/rKddFBBu9z) | [![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ZvecAI)](<https://x.com/ZvecAI>) |
212
- | 扫码加入 | 扫码加入 | 点击加入 | 点击关注 |
289
+ | 💬 钉钉群 | 📱 微信群 | 🎮 Discord | X (Twitter) |
290
+ | :-----------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------: |
291
+ | <img src="https://zvec.oss-cn-hongkong.aliyuncs.com/qrcode/dingding.png" width="150" alt="钉钉二维码"/> | <img src="https://zvec.oss-cn-hongkong.aliyuncs.com/qrcode/wechat.png?v=6" width="150" alt="微信二维码"/> | [![Discord](https://img.shields.io/badge/Discord-Join%20Server-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/rKddFBBu9z) | [![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ZvecAI)](https://x.com/ZvecAI) |
292
+ | 扫码加入 | 扫码加入 | 点击加入 | 点击关注 |
213
293
 
214
294
  </div>
215
295
 
@@ -218,5 +298,7 @@ const result = await zvecGrep.context({
218
298
  欢迎提交 issue 和 pull request。请保持改动聚焦;如果改变行为,请补充测试,并运行:
219
299
 
220
300
  ```bash
221
- npm test
301
+ npm run check
222
302
  ```
303
+
304
+ Pull request 标题需遵循 Conventional Commits。
@@ -1,2 +1,5 @@
1
1
  import type { ParsedArgs } from "./types.js";
2
2
  export declare function parseArgs(args: readonly string[]): ParsedArgs;
3
+ export declare function parseLlamaGpu(value: string): "auto" | "metal" | "vulkan" | "cuda" | false;
4
+ export declare function splitPathFilters(value: string): string[];
5
+ export declare function parseModifiedTime(value: string, option: string): number;