@zvec/zvec-grep 0.1.6 → 0.1.7

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 (148) hide show
  1. package/README.md +128 -49
  2. package/README_CN.md +116 -43
  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 +1 -0
  32. package/dist/daemon/backend.js +56 -18
  33. package/dist/daemon/backend.js.map +1 -1
  34. package/dist/daemon/http-server.js +1 -0
  35. package/dist/daemon/http-server.js.map +1 -1
  36. package/dist/daemon/index-coordinator.d.ts +2 -1
  37. package/dist/daemon/index-coordinator.js.map +1 -1
  38. package/dist/daemon/runtime-manager.d.ts +1 -0
  39. package/dist/daemon/runtime-manager.js +4 -1
  40. package/dist/daemon/runtime-manager.js.map +1 -1
  41. package/dist/daemon/server-controller.js +55 -4
  42. package/dist/daemon/server-controller.js.map +1 -1
  43. package/dist/engine/code-formats.d.ts +3 -0
  44. package/dist/engine/code-formats.js +14 -0
  45. package/dist/engine/code-formats.js.map +1 -0
  46. package/dist/engine/extraction/code/adapter.js +1 -1
  47. package/dist/engine/extraction/code/adapter.js.map +1 -1
  48. package/dist/engine/extraction/code/extractor.js +12 -5
  49. package/dist/engine/extraction/code/extractor.js.map +1 -1
  50. package/dist/engine/extraction/index.d.ts +1 -0
  51. package/dist/engine/extraction/index.js +1 -0
  52. package/dist/engine/extraction/index.js.map +1 -1
  53. package/dist/engine/extraction/markdown/extractor.js +5 -3
  54. package/dist/engine/extraction/markdown/extractor.js.map +1 -1
  55. package/dist/engine/extraction/vector-content.d.ts +5 -0
  56. package/dist/engine/extraction/vector-content.js +95 -0
  57. package/dist/engine/extraction/vector-content.js.map +1 -0
  58. package/dist/engine/file-size-policy.d.ts +6 -0
  59. package/dist/engine/file-size-policy.js +20 -0
  60. package/dist/engine/file-size-policy.js.map +1 -0
  61. package/dist/engine/file-type.d.ts +10 -0
  62. package/dist/engine/file-type.js +71 -38
  63. package/dist/engine/file-type.js.map +1 -1
  64. package/dist/engine/manifest.d.ts +1 -0
  65. package/dist/engine/manifest.js +4 -0
  66. package/dist/engine/manifest.js.map +1 -1
  67. package/dist/engine/models/backends/model2vec-runtime.d.ts +63 -0
  68. package/dist/engine/models/backends/model2vec-runtime.js +112 -0
  69. package/dist/engine/models/backends/model2vec-runtime.js.map +1 -0
  70. package/dist/engine/models/backends/model2vec-tokenizer.d.ts +2 -0
  71. package/dist/engine/models/backends/model2vec-tokenizer.js +42 -0
  72. package/dist/engine/models/backends/model2vec-tokenizer.js.map +1 -0
  73. package/dist/engine/models/backends/model2vec-worker-pool.d.ts +25 -0
  74. package/dist/engine/models/backends/model2vec-worker-pool.js +264 -0
  75. package/dist/engine/models/backends/model2vec-worker-pool.js.map +1 -0
  76. package/dist/engine/models/backends/model2vec-worker.d.ts +1 -0
  77. package/dist/engine/models/backends/model2vec-worker.js +41 -0
  78. package/dist/engine/models/backends/model2vec-worker.js.map +1 -0
  79. package/dist/engine/models/backends/model2vec.d.ts +3 -20
  80. package/dist/engine/models/backends/model2vec.js +107 -128
  81. package/dist/engine/models/backends/model2vec.js.map +1 -1
  82. package/dist/engine/models/catalog.d.ts +26 -7
  83. package/dist/engine/models/catalog.js +26 -7
  84. package/dist/engine/models/catalog.js.map +1 -1
  85. package/dist/engine/models/embeddings.d.ts +1 -0
  86. package/dist/engine/models/embeddings.js.map +1 -1
  87. package/dist/engine/models/resolution.js +1 -1
  88. package/dist/engine/models/resolution.js.map +1 -1
  89. package/dist/engine/pipeline/indexing/index.js +83 -78
  90. package/dist/engine/pipeline/indexing/index.js.map +1 -1
  91. package/dist/engine/pipeline/indexing/input-budget.d.ts +2 -0
  92. package/dist/engine/pipeline/indexing/input-budget.js +51 -0
  93. package/dist/engine/pipeline/indexing/input-budget.js.map +1 -0
  94. package/dist/engine/pipeline/indexing/scanner/index.d.ts +3 -1
  95. package/dist/engine/pipeline/indexing/scanner/index.js +70 -18
  96. package/dist/engine/pipeline/indexing/scanner/index.js.map +1 -1
  97. package/dist/engine/pipeline/search/index.js.map +1 -1
  98. package/dist/engine/service/index.d.ts +1 -1
  99. package/dist/engine/service/root.d.ts +1 -4
  100. package/dist/engine/service/root.js +15 -22
  101. package/dist/engine/service/root.js.map +1 -1
  102. package/dist/engine/service/structure-enrichment.d.ts +1 -1
  103. package/dist/engine/service/structure-enrichment.js +10 -10
  104. package/dist/engine/service/structure-enrichment.js.map +1 -1
  105. package/dist/engine/service/types.d.ts +8 -1
  106. package/dist/engine/service/workspace-index.d.ts +6 -4
  107. package/dist/engine/service/workspace-index.js +18 -12
  108. package/dist/engine/service/workspace-index.js.map +1 -1
  109. package/dist/engine/service/zvec-grep.js +47 -29
  110. package/dist/engine/service/zvec-grep.js.map +1 -1
  111. package/dist/engine/storage/index.d.ts +27 -21
  112. package/dist/engine/storage/index.js +2 -1
  113. package/dist/engine/storage/index.js.map +1 -1
  114. package/dist/engine/storage/layout.d.ts +10 -0
  115. package/dist/engine/storage/layout.js +29 -0
  116. package/dist/engine/storage/layout.js.map +1 -0
  117. package/dist/engine/storage/zvec.d.ts +2 -42
  118. package/dist/engine/storage/zvec.js +40 -67
  119. package/dist/engine/storage/zvec.js.map +1 -1
  120. package/dist/engine/types.d.ts +14 -0
  121. package/dist/engine/types.js.map +1 -1
  122. package/dist/index.d.ts +2 -2
  123. package/dist/index.js.map +1 -1
  124. package/dist/mcp/input-normalization.d.ts +2 -2
  125. package/dist/mcp/input-normalization.js +14 -5
  126. package/dist/mcp/input-normalization.js.map +1 -1
  127. package/dist/mcp/schemas.d.ts +242 -0
  128. package/dist/mcp/schemas.js +73 -14
  129. package/dist/mcp/schemas.js.map +1 -1
  130. package/dist/mcp/stdio-bridge.d.ts +9 -0
  131. package/dist/mcp/stdio-bridge.js +131 -0
  132. package/dist/mcp/stdio-bridge.js.map +1 -0
  133. package/dist/mcp/tools.d.ts +4 -1
  134. package/dist/mcp/tools.js +78 -44
  135. package/dist/mcp/tools.js.map +1 -1
  136. package/dist/prompts/zvec-grep-guidance.d.ts +2 -0
  137. package/dist/prompts/zvec-grep-guidance.js +9 -0
  138. package/dist/prompts/zvec-grep-guidance.js.map +1 -0
  139. package/docs/01-agents.md +26 -5
  140. package/docs/02-cli.md +11 -1
  141. package/docs/03-mcp.md +29 -11
  142. package/docs/04-pipeline.md +10 -2
  143. package/docs/06-server.md +5 -0
  144. package/docs/07-embedding.md +6 -3
  145. package/package.json +4 -4
  146. package/skills/zvec-grep/SKILL.md +0 -61
  147. package/skills/zvec-grep/agents/openai.yaml +0 -4
  148. package/skills/zvec-grep/references/cli-fallback.md +0 -85
package/README.md CHANGED
@@ -23,7 +23,7 @@
23
23
  <p>
24
24
  <a href="#tour">🎬 <strong>Tour</strong></a> |
25
25
  <a href="#features">💫 <strong>Features</strong></a> |
26
- <a href="#quickstart">🚀 <strong>Quickstart</strong></a> |
26
+ <a href="#try-it-yourself">🚀 <strong>Try it yourself</strong></a> |
27
27
  <a href="./docs/README.md">📚 <strong>Docs</strong></a> |
28
28
  <a href="#benchmarks">📊 <strong>Benchmarks</strong></a> |
29
29
  <a href="#community">🤝 <strong>Community</strong></a>
@@ -39,7 +39,7 @@ terminal, or let your agent use it for you.
39
39
  ## 🎬 See it in action
40
40
 
41
41
  <div align="center">
42
- <img src="./.github/assets/zvec-grep-tour.gif" width="1000" alt="Install the agent integration, index a repository, and let the agent search it with zvec-grep" />
42
+ <img src="./.github/assets/zvec-grep-tour.gif" width="1000" alt="Install the agent integration, index a workspace, and let the agent search it with zvec-grep" />
43
43
  </div>
44
44
 
45
45
  Install the integration once, index the workspace, then search from the terminal
@@ -49,81 +49,160 @@ or ask your agent naturally.
49
49
 
50
50
  ## 💫 Why zg?
51
51
 
52
- - **Works out of the box** — one guided install connects zg to your agent on
53
- macOS, Linux, or Windows; ask naturally, with no search syntax to learn.
54
- - **All-in-one retrieval layer** — semantic discovery, BM25-ranked retrieval,
55
- exact text, and regex search all stay behind zg.
56
- - **Agent- and human-friendly** — compact, file-oriented context for agents
57
- and readable terminal output for people, with less noise for both.
58
- - **Local first, permission aware** — ripgrep, indexes, and local models stay
59
- on your machine; remote embeddings require explicit authorization.
52
+ - **Ready for humans and agents** — install once, index once, then use the same
53
+ workspace from the CLI or your agent on macOS, Linux, and Windows.
54
+ - **Search beyond keywords** — discover by meaning, rank by relevance, then
55
+ verify with exact text or regex when needed.
56
+ - **Multi-format search** — search source code, documents, and structured data
57
+ while preserving useful structure and source locations.
58
+ - **Less searching, less context** — ranked, source-linked results surface the
59
+ right evidence with fewer tool calls, fewer tokens, and less noise.
60
+ - **Local by default** — files, indexes, and local models stay on your machine;
61
+ remote embeddings receive data only with your permission.
60
62
 
61
- <a id="quickstart"></a>
63
+ <a id="try-it-yourself"></a>
62
64
 
63
- ## 🚀 Quickstart
65
+ ## 🚀 Try it yourself
64
66
 
65
- Requires Node.js 22 or newer on macOS, Linux, or Windows.
67
+ Requires Node.js 22 or newer and a configured
68
+ [OpenCode](https://opencode.ai/) installation. The agent example explicitly
69
+ selects a free model, so it does not depend on your default provider.
66
70
 
67
- ### 1. Install and connect your agent
71
+ ### 1. Set up a sample bookshelf
68
72
 
69
73
  ```bash
70
74
  npm install -g @zvec/zvec-grep
71
- zg install
72
- ```
75
+ zg install --target opencode --yes
73
76
 
74
- `zg install` detects Codex, Claude Code, Cursor, and OpenCode and configures the
75
- local MCP integration. See [Agent integrations](./docs/01-agents.md) for managed
76
- configuration, permissions, and uninstall instructions. You can also select one
77
- explicitly:
77
+ mkdir zg-mystery && cd zg-mystery
78
+ curl -L https://www.gutenberg.org/files/11/11-0.txt -o alice-in-wonderland.txt
79
+ curl -L https://www.gutenberg.org/files/345/345-0.txt -o dracula.txt
80
+ curl -L https://www.gutenberg.org/files/84/84-0.txt -o frankenstein.txt
81
+ curl -L https://www.gutenberg.org/files/834/834-0.txt -o sherlock-holmes.txt
78
82
 
79
- ```bash
80
- zg install --target codex --yes
83
+ zg index --embedding local/potion-retrieval-32m
81
84
  ```
82
85
 
83
- ### 2. Index your repository
86
+ This creates a small bookshelf of four public-domain novels and indexes it
87
+ locally with Potion Retrieval.
88
+
89
+ Installation starts the shared daemon immediately. The default MCP transport is
90
+ stdio: the agent runs `zg server --stdio`, which safely starts or reuses it
91
+ again after a reboot. Advanced users can keep direct HTTP configuration with
92
+ `zg install --mcp-transport http` and `zg server on`.
93
+
94
+ Use `zg install --mcp-toolset full` when the installed MCP integration should
95
+ also expose managed rg, index, and status tools. The default is `agent`.
96
+
97
+ ### 2. Choose how to search
98
+
99
+ #### For agents: ask with OpenCode
84
100
 
85
101
  ```bash
86
- cd your-repository
87
- zg index --embedding local/potion-code-16m-v2
102
+ opencode run --model opencode/deepseek-v4-flash-free \
103
+ "An unseen creature left a few marks. What did the detective infer? Cite local evidence."
88
104
  ```
89
105
 
90
- This quickstart uses the lightweight
91
- [Potion Code v2](./docs/07-embedding.md) model so you can build the first index
92
- quickly. The first run downloads it; the index stays in `.zvec-grep/`, and later
93
- updates only need `zg index`. See the
94
- [retrieval pipeline](./docs/04-pipeline.md#indexing) to control scope, updates, and
95
- rebuilds.
96
-
97
- ### 3. Ask your agent
106
+ OpenCode chooses zg on its own—the prompt does not name a tool. Query rewrites
107
+ may vary by model, but a typical run looks like this:
98
108
 
99
109
  ```text
100
- My app forgets dark mode every time I refresh. Find out why.
110
+ ⚙ zvec_grep_zvec_grep_search {"root":".../zg-mystery","query":"An unseen creature left a few marks. What did the detective infer?","fts":["marks","unseen creature","inferred","detective"],"fuse":true}
111
+ → Read sherlock-holmes.txt [offset=5440, limit=120]
112
+
113
+ Answer:
114
+ The detective is Sherlock Holmes in *The Adventure of the Crooked Man*.
115
+ From the animal's foot-marks, he inferred:
116
+
117
+ - It was not a dog, cat, monkey, or other familiar creature: its print had
118
+ five foot-pads, long nails, and was nearly as large as a dessert-spoon
119
+ (sherlock-holmes.txt:5479-5486).
120
+ - It had a long body and very short legs: nearly two feet long, but with a
121
+ stride of only about three inches (sherlock-holmes.txt:5497-5502).
122
+ - It was carnivorous because it climbed the curtain toward a canary's cage
123
+ (sherlock-holmes.txt:5509-5510).
124
+ - It was probably from the weasel or stoat tribe, though unusually large
125
+ (sherlock-holmes.txt:5514-5516).
126
+
127
+ Holmes also inferred that a man entered through the window with it and later
128
+ left with the key (sherlock-holmes.txt:5464-5470, 5527-5528).
101
129
  ```
102
130
 
103
- The agent uses zg for semantic discovery and ranked keyword retrieval, while
104
- exact lexical lookup stays with native grep or rg. The
105
- [MCP guide](./docs/03-mcp.md) describes the default search tool and the optional
106
- full toolset, which retains managed rg.
131
+ #### For humans: search directly
107
132
 
108
- To search directly from the terminal, use the same local layer. See the
109
- [CLI guide](./docs/02-cli.md) for routes, filters, and output controls.
133
+ Search the same bookshelf directly, without an agent:
110
134
 
111
135
  ```bash
112
- zg query --human "theme preference persistence on startup" --limit 3
136
+ zg query --human "An unseen creature left a few marks. What did the detective infer?" --limit 3
113
137
  ```
114
138
 
139
+ zg returns the relevant passages from `sherlock-holmes.txt`, ranked ahead of the
140
+ other novels.
141
+
115
142
  <a id="benchmarks"></a>
116
143
 
117
144
  ## 📊 Benchmarks
118
145
 
119
- > 🚧 **Work in progress.**
120
-
121
- ## 🗺️ Roadmap
122
-
123
- zg is moving toward richer multimodal formats, stronger hybrid retrieval, a
124
- more out-of-the-box experience, and support from desktop to mobile.
125
-
126
- Explore the full [Roadmap](./docs/08-roadmap.md).
146
+ zg is a general-purpose retrieval tool. Current benchmarks cover code and text
147
+ retrieval.
148
+
149
+ ### Repository code retrieval
150
+
151
+ We use [SWE-QA-Bench](https://github.com/peng-weihan/SWE-QA-Bench), which
152
+ requires cross-file and multi-hop reasoning over real-world codebases.
153
+
154
+ - **Coverage:** 20 retrieval-intensive tasks covering the paper's four
155
+ top-level categories—**What, Where, How, and Why**—across 8 intentions and
156
+ 11 repositories.
157
+ - **Agent:** Claude Code with **Claude Opus 5**.
158
+ - **Embedding:** **Qwen3.7 Text Embedding** for the zg profile.
159
+ - **Protocol:** 3 runs per task and profile.
160
+
161
+ | Profile | Judge /100 ↑ | Input tokens ↓ | Tool calls ↓ | Time (s) ↓ | Cost ↓ |
162
+ | --- | ---: | ---: | ---: | ---: | ---: |
163
+ | Native tools | 80.42 | 558,651 | 23.42 | 127.5 | $0.905 |
164
+ | Native tools + zg | 81.92 | 294,262 | 9.70 | 79.7 | $0.558 |
165
+ | Change | **+1.50 pp** | **−47.3%** | **−58.6%** | **−37.5%** | **−38.3%** |
166
+
167
+ Across 20 tasks × 3 runs, zg increased the Judge score by 1.50 points while
168
+ reducing input tokens by 47.3%, tool calls by 58.6%, execution time by 37.5%,
169
+ and cost by 38.3%.
170
+
171
+ ### Large-scale text retrieval
172
+
173
+ We use [BrowseComp-Plus](https://github.com/texttron/BrowseComp-Plus), which
174
+ requires multi-document evidence retrieval over a fixed web corpus. The
175
+ evaluation includes 30 queries covering 10 mapped topics and three
176
+ evidence-breadth levels, with 3 runs per profile.
177
+
178
+ | Profile | Accuracy ↑ | Evidence recall ↑ | Search calls ↓ | Input tokens ↓ | Time (s) ↓ | Cost ↓ |
179
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: |
180
+ | Agent + BM25 | TBD | TBD | TBD | TBD | TBD | TBD |
181
+ | Agent + zg | TBD | TBD | TBD | TBD | TBD | TBD |
182
+ | Change | TBD | TBD | TBD | TBD | TBD | TBD |
183
+
184
+ Across 30 queries × 3 runs, zg changed accuracy by TBD pp, evidence recall by
185
+ TBD pp, search calls by TBD%, input tokens by TBD%, time by TBD%, and cost by
186
+ TBD%.
187
+
188
+ To reproduce the evaluation, follow the
189
+ [benchmark guide](./benchmarks/README.md) for environment setup, pinned
190
+ revisions, task manifests, baseline configuration, exact commands, and result
191
+ aggregation. All profiles use the same agent, model, prompt, tool budget, and
192
+ three-run protocol.
193
+
194
+ ## 📚 Documentation
195
+
196
+ | Guide | What you can do |
197
+ | :--- | :--- |
198
+ | [Agent integrations](./docs/01-agents.md) | Connect zg to Codex, Claude Code, Cursor, or OpenCode and verify that it works. |
199
+ | [CLI guide](./docs/02-cli.md) | Search, index, and manage your local workspaces from the terminal. |
200
+ | [MCP guide](./docs/03-mcp.md) | Understand which zg tools your agent can use and how access is secured. |
201
+ | [Retrieval pipeline](./docs/04-pipeline.md) | Choose what to index, keep it fresh, and get better search results. |
202
+ | [Architecture](./docs/05-architecture.md) | See how zg handles your query and where your data stays. |
203
+ | [Server and execution modes](./docs/06-server.md) | Choose between one-off commands and a long-running local server. |
204
+ | [Embedding models](./docs/07-embedding.md) | Pick the right model for speed, search quality, privacy, and your hardware. |
205
+ | [Roadmap](./docs/08-roadmap.md) | See what is coming next and help shape zg's priorities. |
127
206
 
128
207
  <a id="community"></a>
129
208
 
package/README_CN.md CHANGED
@@ -23,7 +23,7 @@
23
23
  <p>
24
24
  <a href="#tour">🎬 <strong>功能演示</strong></a> |
25
25
  <a href="#features">💫 <strong>核心特性</strong></a> |
26
- <a href="#quickstart">🚀 <strong>快速开始</strong></a> |
26
+ <a href="#try-it-yourself">🚀 <strong>动手体验</strong></a> |
27
27
  <a href="./docs/README.md">📚 <strong>文档</strong></a> |
28
28
  <a href="#benchmarks">📊 <strong>性能测试</strong></a> |
29
29
  <a href="#community">🤝 <strong>社区</strong></a>
@@ -31,15 +31,15 @@
31
31
  </div>
32
32
 
33
33
  **zg**(**z**vec-**g**rep)将 ripgrep、BM25 与向量检索统一在一个
34
- [本地优先的检索入口](./docs/05-architecture.md)中。无论是人在终端中搜索,
35
- 还是让 Agent 自主检索,只用 zg 即可。
34
+ [本地优先的检索入口](./docs/05-architecture.md)中。既可以由人在终端中搜索,
35
+ 也可以让 Agent 根据问题选择合适的本地检索方式。
36
36
 
37
37
  <a id="tour"></a>
38
38
 
39
39
  ## 🎬 功能演示
40
40
 
41
41
  <div align="center">
42
- <img src="./.github/assets/zvec-grep-tour.gif" width="1000" alt="安装 Agent 集成、为仓库建索引并让 Agent 使用 zvec-grep 搜索代码" />
42
+ <img src="./.github/assets/zvec-grep-tour.gif" width="1000" alt="安装 Agent 集成、为工作区建索引并让 Agent 使用 zvec-grep 检索本地内容" />
43
43
  </div>
44
44
 
45
45
  只需安装一次集成并为工作区建索引,之后既可以在终端中搜索,也可以直接向
@@ -49,76 +49,149 @@ Agent 提问。
49
49
 
50
50
  ## 💫 为什么选择 zg?
51
51
 
52
- - **开箱即用,零学习成本**:一套引导式安装即可在 macOS、Linux 和 Windows
53
- 上接入 Agent;直接用自然语言提问,无需学习搜索语法。
54
- - **一站式检索层**:语义发现、BM25 相关性检索、精确文本与正则搜索
55
- 都由 zg 统一提供。
56
- - **对 Agent 和开发者都友好**:为 Agent 提供紧凑、围绕文件组织的上下文,
57
- 为开发者提供易读的终端输出,双方都能减少无关噪声。
58
- - **本地优先、权限明确**:ripgrep、索引与本地模型均留在本机;远程 Embedding
59
- 需要显式授权。
52
+ - **人与 Agent 开箱即用**:安装一次、索引一次,即可在 macOS、Linux 和
53
+ Windows 上通过 CLI 或 Agent 复用同一个工作区。
54
+ - **不止关键词搜索**:先按语义发现内容、按相关性排序,再在需要时使用精确文本
55
+ 或正则完成验证。
56
+ - **多格式检索**:搜索源代码、文档和结构化数据,同时保留有用的内容结构与
57
+ 来源位置。
58
+ - **更少搜索,更少上下文**:经过排序并保留来源的结果,可以减少工具调用、
59
+ Token 消耗与无关噪声,更快找到所需证据。
60
+ - **默认本地运行**:文件、索引与本地模型都留在本机;只有经过你的授权,远程
61
+ Embedding 服务才能接收数据。
60
62
 
61
- <a id="quickstart"></a>
63
+ <a id="try-it-yourself"></a>
62
64
 
63
- ## 🚀 快速开始
65
+ ## 🚀 动手体验
64
66
 
65
- 需要 Node.js 22 或更新版本,支持 macOS、Linux 和 Windows。
67
+ 需要 Node.js 22 或更新版本,以及已经完成配置的
68
+ [OpenCode](https://opencode.ai/)。Agent 示例会显式选择免费模型,不依赖你配置的
69
+ 默认模型提供方。
66
70
 
67
- ### 1. 安装并连接 Agent
71
+ ### 1. 准备示例书架
68
72
 
69
73
  ```bash
70
74
  npm install -g @zvec/zvec-grep
71
- zg install
72
- ```
75
+ zg install --target opencode --yes
73
76
 
74
- `zg install` 会检测 Codex、Claude Code、Cursor 和 OpenCode,并配置本地 MCP 集成。
75
- 查看 [Agent 集成指南](./docs/01-agents.md),了解配置变更、权限和卸载方式。
76
- 也可以明确指定目标:
77
+ mkdir zg-mystery && cd zg-mystery
78
+ curl -L https://www.gutenberg.org/files/11/11-0.txt -o alice-in-wonderland.txt
79
+ curl -L https://www.gutenberg.org/files/345/345-0.txt -o dracula.txt
80
+ curl -L https://www.gutenberg.org/files/84/84-0.txt -o frankenstein.txt
81
+ curl -L https://www.gutenberg.org/files/834/834-0.txt -o sherlock-holmes.txt
77
82
 
78
- ```bash
79
- zg install --target codex --yes
83
+ zg index --embedding local/potion-retrieval-32m
80
84
  ```
81
85
 
82
- ### 2. 为仓库建索引
86
+ 这会创建一个包含四本公版小说的小书架,并使用 Potion Retrieval 在本地建立索引。
87
+
88
+ 安装时会立即启动共享 Daemon。默认 MCP 传输方式为 stdio:Agent 会运行
89
+ `zg server --stdio`,电脑重启后该命令会再次安全启动或复用 Daemon。高级用户
90
+ 可以通过 `zg install --mcp-transport http` 保留 HTTP 直连,并自行使用
91
+ `zg server on` 管理后续启动。
92
+
93
+ 如需让安装后的 MCP 集成额外暴露 managed rg、index 和 status 工具,可使用
94
+ `zg install --mcp-toolset full`;默认值为 `agent`。
95
+
96
+ ### 2. 选择检索方式
97
+
98
+ #### Agent:通过 OpenCode 提问
83
99
 
84
100
  ```bash
85
- cd your-repository
86
- zg index --embedding local/potion-code-16m-v2
101
+ opencode run --model opencode/deepseek-v4-flash-free \
102
+ "An unseen creature left a few marks. What did the detective infer? Cite local evidence."
87
103
  ```
88
104
 
89
- 快速开始使用轻量的 [Potion Code v2](./docs/07-embedding.md),以便快速完成首次建索引。
90
- 第一次运行会下载模型,索引保存在 `.zvec-grep/` 下;后续更新只需运行
91
- `zg index`。查看 [检索 Pipeline](./docs/04-pipeline.md#indexing),进一步控制检索范围、
92
- 增量更新和重建。
93
-
94
- ### 3. 直接向 Agent 提问
105
+ Prompt 中没有指定任何工具,OpenCode 会自主选择 zg。不同模型改写的
106
+ Query 可能略有不同,一次典型的执行过程如下:
95
107
 
96
108
  ```text
97
- 每次刷新页面,应用都会忘记深色模式。帮我找出原因。
109
+ ⚙ zvec_grep_zvec_grep_search {"root":".../zg-mystery","query":"An unseen creature left a few marks. What did the detective infer?","fts":["marks","unseen creature","inferred","detective"],"fuse":true}
110
+ → Read sherlock-holmes.txt [offset=5440, limit=120]
111
+
112
+ Answer:
113
+ 侦探是《驼背人》中的福尔摩斯。根据动物留下的脚印,他推断:
114
+
115
+ - 它不是狗、猫、猴子或其他常见动物:脚印有五个肉垫和长爪,整个脚印
116
+ 接近一把甜点勺大小(sherlock-holmes.txt:5479-5486)。
117
+ - 它身体细长、四肢很短:身长接近两英尺,步幅却只有约三英寸
118
+ (sherlock-holmes.txt:5497-5502)。
119
+ - 它是食肉动物,因为它爬上窗帘,试图接近金丝雀笼
120
+ (sherlock-holmes.txt:5509-5510)。
121
+ - 它很可能属于鼬或白鼬一类,但体型异常大
122
+ (sherlock-holmes.txt:5514-5516)。
123
+
124
+ 福尔摩斯还推断,一名男子和它一起从窗户进入房间,离开时带走了钥匙
125
+ (sherlock-holmes.txt:5464-5470, 5527-5528)。
98
126
  ```
99
127
 
100
- Agent 会始终通过 zg 完成语义发现、关键词相关性检索与穷尽精确匹配。你无需
101
- 选择或调用其他搜索工具。[MCP 指南](./docs/03-mcp.md)介绍了 Agent 使用的两个工具。
128
+ #### 用户:直接检索
102
129
 
103
- 也可以直接在终端中使用同一个本地检索层。查看 [CLI 指南](./docs/02-cli.md),了解
104
- 搜索方式、过滤条件和输出控制。
130
+ 不通过 Agent,直接搜索同一个书架:
105
131
 
106
132
  ```bash
107
- zg query --human "theme preference persistence on startup" --limit 3
133
+ zg query --human "An unseen creature left a few marks. What did the detective infer?" --limit 3
108
134
  ```
109
135
 
136
+ zg 会从四本小说中对相关段落进行排序,并将 `sherlock-holmes.txt` 中的证据排在前面。
137
+
110
138
  <a id="benchmarks"></a>
111
139
 
112
140
  ## 📊 性能测试
113
141
 
114
- > 🚧 **正在完善中。**
142
+ zg 是通用检索工具,目前的性能测试覆盖代码与文本检索。
143
+
144
+ ### 代码仓库检索
145
+
146
+ 我们使用 [SWE-QA-Bench](https://github.com/peng-weihan/SWE-QA-Bench),它要求
147
+ Agent 在真实代码库中完成跨文件、多跳推理。
148
+
149
+ - **覆盖范围:**20 个检索密集型任务,覆盖论文中的 **What、Where、How、Why**
150
+ 四个一级类别、8 种意图和 11 个代码仓库。
151
+ - **Agent:**使用 **Claude Opus 5** 的 Claude Code。
152
+ - **Embedding:**zg 方案使用 **Qwen3.7 Text Embedding**。
153
+ - **测试方式:**每个任务、每种方案运行 3 次。
154
+
155
+ | 方案 | 评审得分 /100 ↑ | 输入 Token ↓ | 工具调用 ↓ | 耗时(秒)↓ | 成本 ↓ |
156
+ | --- | ---: | ---: | ---: | ---: | ---: |
157
+ | 原生工具 | 80.42 | 558,651 | 23.42 | 127.5 | $0.905 |
158
+ | 原生工具 + zg | 81.92 | 294,262 | 9.70 | 79.7 | $0.558 |
159
+ | 变化 | **+1.50 个百分点** | **−47.3%** | **−58.6%** | **−37.5%** | **−38.3%** |
160
+
161
+ 在 20 个任务 × 3 次运行中,zg 将评审得分提升了 1.50 分,同时将输入 Token
162
+ 减少 47.3%、工具调用减少 58.6%、执行时间减少 37.5%、成本减少 38.3%。
163
+
164
+ ### 大规模文本检索
165
+
166
+ 我们使用 [BrowseComp-Plus](https://github.com/texttron/BrowseComp-Plus),它要求
167
+ Agent 从固定网页语料库中检索多文档证据。测试包含 30 个问题,覆盖 10 个映射主题
168
+ 和三个证据广度级别,每种方案运行 3 次。
169
+
170
+ | 方案 | 准确率 ↑ | 证据召回率 ↑ | 搜索调用 ↓ | 输入 Token ↓ | 耗时(秒)↓ | 成本 ↓ |
171
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: |
172
+ | Agent + BM25 | TBD | TBD | TBD | TBD | TBD | TBD |
173
+ | Agent + zg | TBD | TBD | TBD | TBD | TBD | TBD |
174
+ | 变化 | TBD | TBD | TBD | TBD | TBD | TBD |
175
+
176
+ 在 30 个问题 × 3 次运行中,zg 对准确率、证据召回率、搜索调用、输入 Token、
177
+ 执行时间和成本的影响尚待测试结果补充。
115
178
 
116
- ## 🗺️ Roadmap
179
+ 如需复现测试,请按照[性能测试指南](./benchmarks/README.md)准备环境、固定版本、
180
+ 任务清单、基线配置、运行命令和结果汇总。所有方案使用相同的 Agent、模型、Prompt、
181
+ 工具预算和三次运行协议。
117
182
 
118
- zg 正在迈向更丰富的多模态格式、更强的混合检索、更开箱即用的体验,以及从
119
- 桌面端到移动端的全平台支持。
183
+ ## 📚 文档
120
184
 
121
- 查看完整 [Roadmap](./docs/08-roadmap.md)。
185
+ | 指南 | 你可以完成什么 |
186
+ | :--- | :--- |
187
+ | [Agent 集成](./docs/01-agents.md) | 将 zg 接入 Codex、Claude Code、Cursor 或 OpenCode,并验证是否正常工作。 |
188
+ | [CLI 指南](./docs/02-cli.md) | 在终端中搜索、索引和管理本地工作区。 |
189
+ | [MCP 指南](./docs/03-mcp.md) | 了解 Agent 可以使用哪些 zg 工具,以及访问权限如何受到保护。 |
190
+ | [检索 Pipeline](./docs/04-pipeline.md) | 选择索引范围、保持内容新鲜,并获得更好的检索结果。 |
191
+ | [架构](./docs/05-architecture.md) | 了解 zg 如何处理查询,以及数据会保留在哪里。 |
192
+ | [服务端与执行模式](./docs/06-server.md) | 在一次性命令和长期运行的本地服务之间选择。 |
193
+ | [Embedding 模型](./docs/07-embedding.md) | 根据速度、检索质量、隐私和本机硬件选择合适的模型。 |
194
+ | [Roadmap](./docs/08-roadmap.md) | 了解接下来的产品方向,并参与影响 zg 的优先级。 |
122
195
 
123
196
  <a id="community"></a>
124
197
 
package/dist/cli/args.js CHANGED
@@ -146,6 +146,9 @@ export function parseArgs(args) {
146
146
  else if (arg === "--force-direct") {
147
147
  options.forceDirect = true;
148
148
  }
149
+ else if (arg === "--stdio") {
150
+ options.serverStdio = true;
151
+ }
149
152
  else if (isLongOptionWithValue(arg, "--mcp-toolset")) {
150
153
  options.mcpToolset = parseMcpToolset(valueFromLongOption(arg));
151
154
  }
@@ -182,6 +185,12 @@ export function parseArgs(args) {
182
185
  else if (arg === "--mcp-token-env") {
183
186
  options.installMcpTokenEnv = parseEnvironmentVariable(readOptionValue(args, ++index, arg), arg);
184
187
  }
188
+ else if (isLongOptionWithValue(arg, "--mcp-transport")) {
189
+ options.installMcpTransport = parseMcpInstallTransport(valueFromLongOption(arg));
190
+ }
191
+ else if (arg === "--mcp-transport") {
192
+ options.installMcpTransport = parseMcpInstallTransport(readOptionValue(args, ++index, arg));
193
+ }
185
194
  else if (arg === "--yes") {
186
195
  options.yes = true;
187
196
  }
@@ -523,7 +532,6 @@ function validateCliShape(command, options, positionals) {
523
532
  [options.hybridQueries?.length, "--hybrid"],
524
533
  [options.routes?.length, "--fts/--vector"],
525
534
  [options.fuse, "--fuse"],
526
- [options.debug, "--debug"],
527
535
  [options.trace, "--trace"],
528
536
  [options.human, "--human"],
529
537
  [options.preview, "--preview"],
@@ -538,6 +546,9 @@ function validateCliShape(command, options, positionals) {
538
546
  if (command !== "query" && queryOnly) {
539
547
  throw new Error(`${queryOnly} can only be used with zg query`);
540
548
  }
549
+ if (options.debug && command !== "query" && command !== "index") {
550
+ throw new Error("--debug can only be used with zg query or zg index");
551
+ }
541
552
  const sharedSelection = firstEnabledOption([
542
553
  [options.globs?.length, "--glob"],
543
554
  [options.insensitiveGlobs?.length, "--iglob"],
@@ -602,12 +613,16 @@ function validateCliShape(command, options, positionals) {
602
613
  throw new Error("--default can only be used with zg config model set");
603
614
  }
604
615
  if (command === "server") {
605
- if (!options.serverAction) {
606
- throw new Error("zg server requires on, off, status, or run");
616
+ if (!options.serverAction && !options.serverStdio) {
617
+ throw new Error("zg server requires on, off, status, run, or --stdio");
618
+ }
619
+ if (options.serverAction && options.serverStdio) {
620
+ throw new Error("--stdio cannot be combined with a server action");
607
621
  }
608
622
  if (options.listen !== undefined &&
609
623
  options.serverAction !== "run" &&
610
- options.serverAction !== "on") {
624
+ options.serverAction !== "on" &&
625
+ !options.serverStdio) {
611
626
  throw new Error("--listen can only be used with zg server on or run");
612
627
  }
613
628
  if (options.serverTokenFile !== undefined &&
@@ -616,12 +631,16 @@ function validateCliShape(command, options, positionals) {
616
631
  }
617
632
  if (options.mcpToolset !== undefined &&
618
633
  options.serverAction !== "on" &&
619
- options.serverAction !== "run") {
634
+ options.serverAction !== "run" &&
635
+ !options.serverStdio) {
620
636
  throw new Error("--mcp-toolset can only be used with zg server on or run");
621
637
  }
622
638
  }
623
- else if (options.mcpToolset !== undefined) {
624
- throw new Error("--mcp-toolset can only be used with zg server on or run");
639
+ else if (options.mcpToolset !== undefined && command !== "install") {
640
+ throw new Error("--mcp-toolset can only be used with zg server on, run, --stdio, or zg install");
641
+ }
642
+ else if (options.serverStdio !== undefined) {
643
+ throw new Error("--stdio can only be used with zg server");
625
644
  }
626
645
  if (options.rg &&
627
646
  (hasExplicitRoutes(options) || options.hybridQueries?.length)) {
@@ -679,6 +698,14 @@ function validateCliShape(command, options, positionals) {
679
698
  if (options.installMcpTokenEnv !== undefined && command !== "install") {
680
699
  throw new Error("--mcp-token-env can only be used with zg install");
681
700
  }
701
+ if (options.installMcpTransport !== undefined && command !== "install") {
702
+ throw new Error("--mcp-transport can only be used with zg install");
703
+ }
704
+ if (command === "install" &&
705
+ options.installMcpTransport !== "http" &&
706
+ options.installMcpTokenEnv !== undefined) {
707
+ throw new Error("--mcp-token-env requires --mcp-transport http");
708
+ }
682
709
  if (options.force && command !== "install") {
683
710
  throw new Error("--force can only be used with zg install");
684
711
  }
@@ -743,6 +770,7 @@ function validateCliShape(command, options, positionals) {
743
770
  options.ignoreFiles?.length ||
744
771
  options.maxDepth !== undefined ||
745
772
  options.maxFileSizeBytes !== undefined ||
773
+ options.debug ||
746
774
  options.follow ||
747
775
  options.embeddingConcurrency)) {
748
776
  throw new Error("zg index --drop cannot be combined with indexing options");
@@ -1014,6 +1042,11 @@ function parseEnvironmentVariable(value, option) {
1014
1042
  }
1015
1043
  return value;
1016
1044
  }
1045
+ function parseMcpInstallTransport(value) {
1046
+ if (value === "stdio" || value === "http")
1047
+ return value;
1048
+ throw new Error("--mcp-transport must be stdio or http");
1049
+ }
1017
1050
  function parseByteSize(value, option) {
1018
1051
  const match = value.trim().match(/^(\d+)([KMGT])?$/i);
1019
1052
  if (!match) {