@zvec/zvec-grep 0.1.6 → 0.1.8

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 (161) hide show
  1. package/README.md +88 -52
  2. package/README_CN.md +85 -49
  3. package/dist/cli/args.js +40 -7
  4. package/dist/cli/args.js.map +1 -1
  5. package/dist/cli/auth.js +1 -4
  6. package/dist/cli/auth.js.map +1 -1
  7. package/dist/cli/commands.js +53 -24
  8. package/dist/cli/commands.js.map +1 -1
  9. package/dist/cli/format/context.d.ts +3 -0
  10. package/dist/cli/format/context.js +93 -22
  11. package/dist/cli/format/context.js.map +1 -1
  12. package/dist/cli/format/debug.js +10 -4
  13. package/dist/cli/format/debug.js.map +1 -1
  14. package/dist/cli/format/status.d.ts +3 -1
  15. package/dist/cli/format/status.js +34 -0
  16. package/dist/cli/format/status.js.map +1 -1
  17. package/dist/cli/help.js +149 -16
  18. package/dist/cli/help.js.map +1 -1
  19. package/dist/cli/index.d.ts +1 -1
  20. package/dist/cli/index.js +1 -1
  21. package/dist/cli/install.js +174 -56
  22. package/dist/cli/install.js.map +1 -1
  23. package/dist/cli/server-search.d.ts +3 -0
  24. package/dist/cli/server-search.js +12 -0
  25. package/dist/cli/server-search.js.map +1 -0
  26. package/dist/cli/types.d.ts +3 -0
  27. package/dist/cli/types.js.map +1 -1
  28. package/dist/client/daemon-client.d.ts +12 -0
  29. package/dist/client/daemon-client.js +23 -0
  30. package/dist/client/daemon-client.js.map +1 -1
  31. package/dist/daemon/backend.d.ts +2 -0
  32. package/dist/daemon/backend.js +121 -90
  33. package/dist/daemon/backend.js.map +1 -1
  34. package/dist/daemon/change-set.d.ts +5 -0
  35. package/dist/daemon/change-set.js +75 -13
  36. package/dist/daemon/change-set.js.map +1 -1
  37. package/dist/daemon/http-server.js +1 -0
  38. package/dist/daemon/http-server.js.map +1 -1
  39. package/dist/daemon/index-coordinator.d.ts +3 -4
  40. package/dist/daemon/index-coordinator.js +8 -21
  41. package/dist/daemon/index-coordinator.js.map +1 -1
  42. package/dist/daemon/root-runtime.js +2 -2
  43. package/dist/daemon/root-runtime.js.map +1 -1
  44. package/dist/daemon/runtime-manager.d.ts +1 -0
  45. package/dist/daemon/runtime-manager.js +4 -1
  46. package/dist/daemon/runtime-manager.js.map +1 -1
  47. package/dist/daemon/server-controller.js +138 -14
  48. package/dist/daemon/server-controller.js.map +1 -1
  49. package/dist/daemon/watch-manager.d.ts +5 -0
  50. package/dist/daemon/watch-manager.js +68 -21
  51. package/dist/daemon/watch-manager.js.map +1 -1
  52. package/dist/engine/code-formats.d.ts +3 -0
  53. package/dist/engine/code-formats.js +14 -0
  54. package/dist/engine/code-formats.js.map +1 -0
  55. package/dist/engine/extraction/code/adapter.js +1 -1
  56. package/dist/engine/extraction/code/adapter.js.map +1 -1
  57. package/dist/engine/extraction/code/extractor.d.ts +5 -0
  58. package/dist/engine/extraction/code/extractor.js +53 -26
  59. package/dist/engine/extraction/code/extractor.js.map +1 -1
  60. package/dist/engine/extraction/index.d.ts +2 -1
  61. package/dist/engine/extraction/index.js +2 -1
  62. package/dist/engine/extraction/index.js.map +1 -1
  63. package/dist/engine/extraction/markdown/extractor.js +5 -3
  64. package/dist/engine/extraction/markdown/extractor.js.map +1 -1
  65. package/dist/engine/extraction/runtime.d.ts +6 -1
  66. package/dist/engine/extraction/runtime.js +11 -0
  67. package/dist/engine/extraction/runtime.js.map +1 -1
  68. package/dist/engine/extraction/vector-content.d.ts +5 -0
  69. package/dist/engine/extraction/vector-content.js +83 -0
  70. package/dist/engine/extraction/vector-content.js.map +1 -0
  71. package/dist/engine/file-size-policy.d.ts +6 -0
  72. package/dist/engine/file-size-policy.js +20 -0
  73. package/dist/engine/file-size-policy.js.map +1 -0
  74. package/dist/engine/file-type.d.ts +10 -0
  75. package/dist/engine/file-type.js +71 -38
  76. package/dist/engine/file-type.js.map +1 -1
  77. package/dist/engine/manifest.d.ts +1 -0
  78. package/dist/engine/manifest.js +4 -0
  79. package/dist/engine/manifest.js.map +1 -1
  80. package/dist/engine/models/backends/model2vec-runtime.d.ts +63 -0
  81. package/dist/engine/models/backends/model2vec-runtime.js +112 -0
  82. package/dist/engine/models/backends/model2vec-runtime.js.map +1 -0
  83. package/dist/engine/models/backends/model2vec-tokenizer.d.ts +2 -0
  84. package/dist/engine/models/backends/model2vec-tokenizer.js +42 -0
  85. package/dist/engine/models/backends/model2vec-tokenizer.js.map +1 -0
  86. package/dist/engine/models/backends/model2vec-worker-pool.d.ts +25 -0
  87. package/dist/engine/models/backends/model2vec-worker-pool.js +264 -0
  88. package/dist/engine/models/backends/model2vec-worker-pool.js.map +1 -0
  89. package/dist/engine/models/backends/model2vec-worker.d.ts +1 -0
  90. package/dist/engine/models/backends/model2vec-worker.js +41 -0
  91. package/dist/engine/models/backends/model2vec-worker.js.map +1 -0
  92. package/dist/engine/models/backends/model2vec.d.ts +3 -20
  93. package/dist/engine/models/backends/model2vec.js +107 -128
  94. package/dist/engine/models/backends/model2vec.js.map +1 -1
  95. package/dist/engine/models/catalog.d.ts +26 -7
  96. package/dist/engine/models/catalog.js +26 -7
  97. package/dist/engine/models/catalog.js.map +1 -1
  98. package/dist/engine/models/embeddings.d.ts +1 -0
  99. package/dist/engine/models/embeddings.js.map +1 -1
  100. package/dist/engine/models/resolution.js +1 -1
  101. package/dist/engine/models/resolution.js.map +1 -1
  102. package/dist/engine/pipeline/indexing/index.js +102 -78
  103. package/dist/engine/pipeline/indexing/index.js.map +1 -1
  104. package/dist/engine/pipeline/indexing/input-budget.d.ts +2 -0
  105. package/dist/engine/pipeline/indexing/input-budget.js +51 -0
  106. package/dist/engine/pipeline/indexing/input-budget.js.map +1 -0
  107. package/dist/engine/pipeline/indexing/scanner/index.d.ts +5 -1
  108. package/dist/engine/pipeline/indexing/scanner/index.js +129 -20
  109. package/dist/engine/pipeline/indexing/scanner/index.js.map +1 -1
  110. package/dist/engine/pipeline/search/index.js.map +1 -1
  111. package/dist/engine/service/index.d.ts +1 -1
  112. package/dist/engine/service/root.d.ts +1 -4
  113. package/dist/engine/service/root.js +15 -22
  114. package/dist/engine/service/root.js.map +1 -1
  115. package/dist/engine/service/structure-enrichment.d.ts +1 -1
  116. package/dist/engine/service/structure-enrichment.js +10 -10
  117. package/dist/engine/service/structure-enrichment.js.map +1 -1
  118. package/dist/engine/service/types.d.ts +8 -1
  119. package/dist/engine/service/workspace-index.d.ts +6 -4
  120. package/dist/engine/service/workspace-index.js +18 -12
  121. package/dist/engine/service/workspace-index.js.map +1 -1
  122. package/dist/engine/service/zvec-grep.js +47 -29
  123. package/dist/engine/service/zvec-grep.js.map +1 -1
  124. package/dist/engine/storage/index.d.ts +28 -21
  125. package/dist/engine/storage/index.js +2 -1
  126. package/dist/engine/storage/index.js.map +1 -1
  127. package/dist/engine/storage/layout.d.ts +10 -0
  128. package/dist/engine/storage/layout.js +29 -0
  129. package/dist/engine/storage/layout.js.map +1 -0
  130. package/dist/engine/storage/zvec.d.ts +2 -42
  131. package/dist/engine/storage/zvec.js +62 -71
  132. package/dist/engine/storage/zvec.js.map +1 -1
  133. package/dist/engine/types.d.ts +14 -0
  134. package/dist/engine/types.js.map +1 -1
  135. package/dist/index.d.ts +2 -2
  136. package/dist/index.js.map +1 -1
  137. package/dist/mcp/input-normalization.d.ts +2 -2
  138. package/dist/mcp/input-normalization.js +14 -5
  139. package/dist/mcp/input-normalization.js.map +1 -1
  140. package/dist/mcp/schemas.d.ts +242 -0
  141. package/dist/mcp/schemas.js +73 -14
  142. package/dist/mcp/schemas.js.map +1 -1
  143. package/dist/mcp/stdio-bridge.d.ts +11 -0
  144. package/dist/mcp/stdio-bridge.js +134 -0
  145. package/dist/mcp/stdio-bridge.js.map +1 -0
  146. package/dist/mcp/tools.d.ts +4 -1
  147. package/dist/mcp/tools.js +78 -44
  148. package/dist/mcp/tools.js.map +1 -1
  149. package/dist/prompts/zvec-grep-guidance.d.ts +2 -0
  150. package/dist/prompts/zvec-grep-guidance.js +9 -0
  151. package/dist/prompts/zvec-grep-guidance.js.map +1 -0
  152. package/docs/01-agents.md +26 -5
  153. package/docs/02-cli.md +11 -1
  154. package/docs/03-mcp.md +29 -11
  155. package/docs/04-pipeline.md +10 -2
  156. package/docs/06-server.md +9 -0
  157. package/docs/07-embedding.md +6 -3
  158. package/package.json +5 -4
  159. package/skills/zvec-grep/SKILL.md +0 -61
  160. package/skills/zvec-grep/agents/openai.yaml +0 -4
  161. package/skills/zvec-grep/references/cli-fallback.md +0 -85
package/docs/03-mcp.md CHANGED
@@ -22,15 +22,33 @@ refresh, authentication, and logs.
22
22
 
23
23
  The default `agent` toolset intentionally exposes only search:
24
24
 
25
+ Agents first decide whether the requested answer should be grounded in the
26
+ current indexed workspace, then choose exact or semantic retrieval. The same
27
+ rules apply to source code and non-code material such as documentation, books,
28
+ research material, meeting notes, knowledge-base exports, manuals,
29
+ configuration, and data.
30
+
31
+ Workspace relevance requires a request to inspect, search, or ground the answer
32
+ in local material, prior context that established local material as the intended
33
+ source, or a question about whether relevant local material exists. Negative,
34
+ incidental, or comparative workspace mentions do not establish relevance.
35
+
25
36
  | Tool | Use it when | Index required |
26
37
  | --- | --- | --- |
27
- | `zvec_grep_search` | The answer requires conceptual discovery, architecture, lifecycle, or cross-component flow | Yes |
38
+ | `zvec_grep_search` | The answer is workspace-grounded and wording or location is unknown, or semantic, fuzzy, relationship, chronology, causality, comparison, or cross-file synthesis is required | Yes |
28
39
 
29
- Agents use native grep or rg when locating an exact word, symbol, filename, path,
30
- source fragment, or regex is sufficient. For mixed tasks, start with
31
- `zvec_grep_search`, then use native grep or rg for focused follow-up.
40
+ Agents use native grep or rg when locating an exact word, quotation, name, date,
41
+ key, filename, path, source fragment, or regex is sufficient. For mixed tasks,
42
+ start with `zvec_grep_search`, then use native grep or rg for focused follow-up.
43
+ When semantic discovery is selected because no sufficient exact anchor is
44
+ available and the user asks whether conceptually related material exists
45
+ locally, agents make at most one focused search probe and stop when its results
46
+ are not relevant. The probe does not apply to exact quotations, configuration
47
+ keys, filenames, regexes, or exhaustive occurrence requests. Unrelated
48
+ open-world knowledge, current external facts, and web content that does not
49
+ depend on local evidence use the appropriate external source instead.
32
50
 
33
- Every repository tool input uses an absolute `root` visible to the daemon.
51
+ Every workspace tool input uses an absolute `root` visible to the daemon.
34
52
 
35
53
  ## `zvec_grep_search`
36
54
 
@@ -41,8 +59,8 @@ Minimal conceptual search:
41
59
 
42
60
  ```json
43
61
  {
44
- "root": "/absolute/path/to/repository",
45
- "query": "theme preference persistence on startup",
62
+ "root": "/absolute/path/to/workspace",
63
+ "query": "decision history behind the launch date",
46
64
  "limit": 5
47
65
  }
48
66
  ```
@@ -51,7 +69,7 @@ Explicit query routes and scope:
51
69
 
52
70
  ```json
53
71
  {
54
- "root": "/absolute/path/to/repository",
72
+ "root": "/absolute/path/to/workspace",
55
73
  "query": "authentication flow",
56
74
  "fts": ["AuthService", "ForbiddenError"],
57
75
  "globs": ["src/**", "!src/generated/**"],
@@ -67,7 +85,7 @@ Important inputs:
67
85
  | --- | --- |
68
86
  | `query` | One hybrid natural-language or exact query |
69
87
  | `queries` | One or more hybrid query groups |
70
- | `fts` | Ranked lexical query groups |
88
+ | `fts` | Ranked lexical constraints within indexed search, not exhaustive occurrence lookup |
71
89
  | `vector` | Semantic-only query groups |
72
90
  | `fuse` | Combine every group into one ranked plan |
73
91
  | `limit` | Maximum items per group, up to 50 |
@@ -110,7 +128,7 @@ arguments and is never executed by a shell:
110
128
 
111
129
  ```json
112
130
  {
113
- "root": "/absolute/path/to/repository",
131
+ "root": "/absolute/path/to/workspace",
114
132
  "command": "rg -n -F 'loadTheme' -g '*.ts' src"
115
133
  }
116
134
  ```
@@ -120,7 +138,7 @@ requesting bounded output:
120
138
 
121
139
  ```json
122
140
  {
123
- "root": "/absolute/path/to/repository",
141
+ "root": "/absolute/path/to/workspace",
124
142
  "command": "rg -n 'TODO|FIXME' src | head -50"
125
143
  }
126
144
  ```
@@ -67,6 +67,12 @@ File-type filters narrow the result after glob rules. For example,
67
67
  `-g "docs/**" -t ts` selects TypeScript files inside `docs`, not every file in
68
68
  that directory.
69
69
 
70
+ Without an explicit `--max-filesize`, indexing uses type-aware safety limits:
71
+ 1 MiB for code, 256 MiB for text and Markdown, 16 MiB for structured data, and
72
+ 10 MiB for images. An explicit value replaces the type-aware defaults for every
73
+ selected file. Files excluded by these limits remain silent during normal
74
+ indexing; use `zg index --debug` to print skipped-file counts and samples.
75
+
70
76
  ### Supported formats and extraction
71
77
 
72
78
  The scanner assigns each admitted file to one extraction path. Structure-aware
@@ -200,8 +206,10 @@ between `auto`, `server`, `direct`, and `--refresh`.
200
206
 
201
207
  ## Output for agents and people
202
208
 
203
- Default CLI output is compact and grouped by file. Indexed source previews are
204
- omitted unless requested, reducing context passed to an agent:
209
+ Default indexed CLI output is compact, grouped by query group, and ordered by
210
+ that group's retrieval rank. A result recalled by several groups appears in
211
+ each matching group. Indexed source previews are omitted unless requested,
212
+ reducing context passed to an agent:
205
213
 
206
214
  ```bash
207
215
  zg query "plugin lifecycle" --preview short --limit 5
package/docs/06-server.md CHANGED
@@ -142,6 +142,15 @@ Server searches may return useful results with `freshness: possibly_stale`
142
142
  while an update continues. Use the result immediately when it answers the
143
143
  question; use `--refresh wait` only when the latest file state is required.
144
144
 
145
+ Watcher-reported path updates skip workspace-wide status scans. Because
146
+ file-system watchers can silently miss events, the Server schedules an hourly
147
+ full reconciliation probe; the next search uses it to scan the Workspace and
148
+ repair index drift.
149
+
150
+ Large bursts of exact watcher events are compacted into directory-scoped
151
+ updates. A full reconciliation is reserved for watcher errors, missing event
152
+ paths, resume drift, and other cases where events may have been lost.
153
+
145
154
  ## Endpoint and toolset
146
155
 
147
156
  The default endpoint is:
@@ -23,7 +23,9 @@ content to the configured provider after authorization.
23
23
 
24
24
  | Need | Start with | Why |
25
25
  | --- | --- | --- |
26
- | A fast first index for a code repository | `local/potion-code-16m-v2` | Small static Model2Vec model with an 8,192-token input limit |
26
+ | A fast first index for a code repository | `local/potion-code-16m-v2` | Small static Model2Vec model with a 1,024-token input limit |
27
+ | Fast English document retrieval | `local/potion-retrieval-32m` | Retrieval-tuned static model with 512-dimensional vectors |
28
+ | Fast multilingual document retrieval | `local/potion-multilingual-128m` | Static model trained for 101 languages with compact 256-dimensional vectors |
27
29
  | A Transformer model specialized for code | `local/jina-embeddings-v2-base-code` | Code-oriented, multilingual, and long-context |
28
30
  | General multilingual code and documents | `local/embeddinggemma-300m` | Broad language coverage in a local GGUF model |
29
31
  | A smaller multilingual model | `local/multilingual-e5-small` | Compact 384-dimensional Transformer model |
@@ -43,8 +45,9 @@ file.
43
45
 
44
46
  | Model | Runtime | Max input tokens | Dimensions |
45
47
  | --- | --- | ---: | ---: |
46
- | `local/potion-code-16m-v2` | Model2Vec FP16 | 8,192 | 256 |
47
- | `local/potion-base-8m` | Model2Vec FP32 | 512 | 256 |
48
+ | `local/potion-code-16m-v2` | Model2Vec FP16 | 1,024 | 256 |
49
+ | `local/potion-retrieval-32m` | Model2Vec FP32 | 1,024 | 512 |
50
+ | `local/potion-multilingual-128m` | Model2Vec FP32 | 1,024 | 256 |
48
51
  | `local/all-minilm-l6-v2` | ONNX Q4 | 256 | 384 |
49
52
  | `local/bge-small-en-v1.5` | ONNX Q4 | 512 | 384 |
50
53
  | `local/multilingual-e5-small` | ONNX Q8 | 512 | 384 |
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zvec/zvec-grep",
3
- "version": "0.1.6",
4
- "description": "Agent-friendly hybrid code search with indexed context and managed ripgrep.",
3
+ "version": "0.1.8",
4
+ "description": "Agent-friendly hybrid workspace search across code and non-code content.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -32,8 +32,7 @@
32
32
  "README_CN.md",
33
33
  "LICENSE",
34
34
  "docs",
35
- "dist",
36
- "skills/zvec-grep"
35
+ "dist"
37
36
  ],
38
37
  "scripts": {
39
38
  "build": "tsc -p tsconfig.json",
@@ -46,6 +45,7 @@
46
45
  "test:e2e": "npm run build && npm run test:run:e2e",
47
46
  "test:integration": "npm run build && npm run test:run:root && npm run test:run:integration",
48
47
  "test:package": "npm run build && node --test --test-concurrency=1 test/package/*.test.mjs",
48
+ "test:smoke:local-model": "node --test --test-concurrency=1 test/smoke/local-model-package.test.mjs",
49
49
  "test:run:e2e": "node --test --test-concurrency=1 test/e2e/*.test.mjs",
50
50
  "test:run:integration": "node --test --test-concurrency=1 test/integration/*.test.mjs",
51
51
  "test:run:root": "node --test --test-concurrency=1 test/*.test.mjs",
@@ -66,6 +66,7 @@
66
66
  "typescript-eslint": "^8.64.0"
67
67
  },
68
68
  "dependencies": {
69
+ "@huggingface/tokenizers": "^0.1.3",
69
70
  "@huggingface/transformers": "^3.8.1",
70
71
  "@modelcontextprotocol/client": "2.0.0",
71
72
  "@modelcontextprotocol/core": "2.0.0",
@@ -1,61 +0,0 @@
1
- ---
2
- name: zvec-grep
3
- description: Repository code search and indexing with zvec-grep. Use when exploring a codebase, locating symbols, references, or exact text, creating or inspecting a repository index, diagnosing the daemon, or whenever repository investigation would otherwise use grep, rg, or broad file reads.
4
- ---
5
-
6
- # zvec-grep
7
-
8
- ## Select the transport
9
-
10
- Use zvec-grep indexed search for conceptual repository investigation. Use native
11
- `grep` or `rg` for exact lexical searches unless the optional managed-rg MCP tool
12
- is explicitly available.
13
-
14
- Use the public native HTTP MCP search tools as the primary interface when the matching `zvec_grep_*` tool is present. Call them directly; do not run `zg`, probe the daemon through shell, or choose CLI for convenience.
15
-
16
- Use CLI fallback only when one of these conditions is true:
17
-
18
- - The task requires index lifecycle or daemon diagnostics, which are intentionally
19
- kept out of the default agent MCP toolset.
20
- - An available MCP search tool cannot perform the required operation.
21
- - MCP initialization, authentication, connection, or the required search call has
22
- failed.
23
- - The repository has no index, the user has not authorized indexing, and an explicit no-index lexical search is needed.
24
-
25
- Do not retry a submitted indexing write through another transport after a connection interruption.
26
-
27
- ## Use the MCP workflow
28
-
29
- Pass the repository's daemon-visible absolute path as `root` on every repository call.
30
-
31
- 1. Use native `grep` or `rg` when an exact keyword, text, symbol, filename,
32
- path, configuration key, error message, source fragment, literal, or regex
33
- anchor is known and locating it is sufficient to answer the question.
34
- 2. Call `zvec_grep_search` when the answer requires conceptual discovery,
35
- architecture, lifecycle, data or control flow, comparison, design rationale,
36
- or performance analysis. Search defaults to `freshness: "eventual"`; use
37
- `freshness: "wait_for_fresh"` only when the result must include all pending
38
- changes. Use hybrid `queries` for concepts plus known lexical constraints,
39
- `fts` for indexed lexical-only intent, and `vector` for semantic-only intent.
40
- 3. When exact symbols are present but the answer spans multiple components,
41
- files, stages, or implementations, call `zvec_grep_search` first with the
42
- concept and known symbols, then use native `grep` or `rg` for focused follow-up.
43
- 4. Read the indexed search response's `freshness` and `indexing` fields. Use
44
- `possibly_stale` results immediately when they are sufficient; do not call
45
- status merely because a background update is active.
46
- 5. Apply focused path and file-type filters early. Exclude dependencies,
47
- generated output, caches, build artifacts, fixtures, and logs unless the
48
- task concerns them.
49
-
50
- The default public MCP endpoint intentionally exposes only indexed search. If the
51
- index is missing, explain that indexed search requires an index and ask before
52
- creating one. After authorization, use the CLI lifecycle workflow; never silently
53
- create, rebuild, or drop an index. The optional full MCP toolset exposes
54
- `zvec_grep_rg`; the CLI `zg query --rg` route remains available for explicit
55
- managed-ripgrep fallback.
56
-
57
- Use multiple queries when comparing related concepts.
58
-
59
- ## Use CLI fallback
60
-
61
- Read [references/cli-fallback.md](references/cli-fallback.md) only after a fallback condition above is satisfied. Leave CLI mode unset for status, fallback search, and authorized indexing commands so the default Auto mode can select Server or Direct; do not probe forced Server mode and then retry forced Direct mode. Keep the selected transport consistent for the investigation unless its availability changes.
@@ -1,4 +0,0 @@
1
- interface:
2
- display_name: "zvec-grep"
3
- short_description: "Repository search with explicit index lifecycle"
4
- default_prompt: "Use $zvec-grep to investigate this repository before raw grep or rg. Prefer the public MCP search tools, and use the zg CLI only for authorized index lifecycle or daemon diagnostics."
@@ -1,85 +0,0 @@
1
- # CLI fallback
2
-
3
- Use these commands only when the native MCP tools are unavailable or when an explicit no-index lexical search is required.
4
-
5
- ## Choose the route
6
-
7
- Leave `--mode` unset for ordinary status and query commands. The default Auto mode uses the daemon when reachable and Direct mode otherwise:
8
-
9
- ```bash
10
- zg status
11
- zg query "authentication flow" --fts "AuthService" -g "src/**" -g "!tests/**" -g "!dist/**"
12
- ```
13
-
14
- Do not probe with `--mode server` and then retry with `--mode direct`. Use an explicit mode only when diagnosing routing or when the user requests one. Do not force Direct writes while a daemon lease is active.
15
-
16
- ## Check index state
17
-
18
- Check status once per repository investigation and reuse it:
19
-
20
- ```bash
21
- zg status
22
- ```
23
-
24
- If the index is missing, do not build it automatically. Mention `zg index` and wait for the user to authorize persistent indexing.
25
-
26
- ## Search an existing index
27
-
28
- Start with indexed hybrid search, then add exact or semantic routes as needed:
29
-
30
- ```bash
31
- zg query "request validation" "error handling" -g "src/**" -g "!tests/**" -g "!dist/**" --limit 10 --preview short
32
- zg query "authentication flow" --fts "AuthService" --fts "ForbiddenError" -g "src/**"
33
- zg query --vector "where incoming requests are authorized" -g "src/**"
34
- zg query "changes that must be indexed before search" --refresh wait
35
- ```
36
-
37
- When Auto selects Server, queries return the current index and refresh stale data in the background by default. Direct queries do not refresh by default. Add `--refresh wait` when the query must wait for pending index changes, or `--refresh off` to disable refresh explicitly. Use `--preview none` for broad candidate scans, `--preview short` for a small deterministic window, and `--preview full` only after narrowing.
38
-
39
- ## Recover from a Direct model failure
40
-
41
- Direct mode already attempts CPU fallback when local GPU initialization fails. Do not repeat the query with an explicit CPU override.
42
-
43
- If the local model or embedding context remains unavailable and exact anchors are available, remove positional hybrid and vector queries and search those anchors through the existing indexed FTS route. Indexed FTS does not require an embedding model:
44
-
45
- ```bash
46
- zg query --fts "AuthService" --fts "ForbiddenError" -g "src/**" --limit 20 --preview short
47
- ```
48
-
49
- Do not switch to managed ripgrep merely because semantic search is unavailable. Use it only when the task requires exhaustive literal or regex matching, or when no index exists and the user has not authorized creating one.
50
-
51
- ## Search exhaustively with managed ripgrep
52
-
53
- Use managed ripgrep only for exhaustive literal or regex matching; it does not require an index:
54
-
55
- ```bash
56
- zg query --rg "SymbolName|LogMessage"
57
- zg query --rg -F "ExactSymbolOrText" src
58
- zg query --rg -i -C 2 -g "*.ts" -g "!dist/**" "needle text" src
59
- ```
60
-
61
- Managed ripgrep always runs locally. It remains available while the daemon is running or an index writer is active; do not stop the daemon or switch client mode before using it.
62
-
63
- Use `-e` or `--regexp` when the pattern begins with `-`. Common ripgrep flags include `-n`, `-H`, `-F`, `-i`, `-w`, `-A`, `-B`, `-C`, `-g`, `--hidden`, `--type`, `--type-not`, `--no-ignore`, `--smart-case`, and `--pcre2`.
64
-
65
- ## Index only with authorization
66
-
67
- When a server default model is known, let Auto submit the index without repeating the model:
68
-
69
- ```bash
70
- zg index
71
- ```
72
-
73
- Otherwise, use the embedding model selected by the user:
74
-
75
- ```bash
76
- zg index --embedding local/embeddinggemma-300m
77
- ```
78
-
79
- Use focused path filters for a new index:
80
-
81
- ```bash
82
- zg index --embedding local/embeddinggemma-300m -g "src/**" -g "docs/**" -g "test/**" -g "!dist/**" -g "!node_modules/**" -g "!coverage/**"
83
- ```
84
-
85
- Rebuild only when an incompatible embedding schema or index version requires it. Existing indexes reuse their stored embedding schema unless the user intentionally changes it.