@hilariouhiss/dsh-colgrep 1.0.0 → 1.0.1

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.
package/README.md CHANGED
@@ -27,7 +27,7 @@
27
27
 
28
28
  行为要点:
29
29
 
30
- - 结果以 `--json` 解析后折叠为紧凑可读文本(`文件:行-行 [语言, 类型, 名称] (score)` + 首行签名),不倾倒整段代码;模型可再 `read` 具体文件。
30
+ - 结果以 `--json` 解析后折叠为紧凑可读文本(`文件:行-行 [语言, 类型, 名称] (score)` + 首行签名),不倾倒整段代码;模型可再 `read` 具体文件。解析兼容顶层数组与 `{results:[...]}` 两种 JSON 形状;`query` 为空或纯空白时返回明确错误。
31
31
  - **索引重定位**:DSH 文件沙箱禁止写工作区之外,而 colgrep 检索需要写索引锁文件。插件把索引目录重定位到 `<工作区>/.colgrep-data`(通过 `COLGREP_DATA_DIR`),使全部写入落在沙箱允许范围内。ColBERT 模型与 ONNX runtime 从 `~/.cache` 只读加载,无需联网。
32
32
  - 首次检索会自动建立索引(CPU 上大仓库可能需数分钟);可用 `command:"init"` 显式建索引,`no_update:true` 走现有索引。
33
33
 
package/lib/index.js CHANGED
@@ -20,6 +20,9 @@ export function buildArgs(args) {
20
20
  const command = args.command || "search";
21
21
  const argv = ["colgrep"];
22
22
  if (command === "search") {
23
+ if (typeof args.query !== "string" || args.query.trim() === "") {
24
+ throw new Error("query must be a non-empty string");
25
+ }
23
26
  argv.push("--json", "--color", "never", "-y");
24
27
  if (args.no_update) argv.push("--no-update");
25
28
  argv.push("-k", String(args.top_k ? Number(args.top_k) : 15));
@@ -77,7 +80,7 @@ export function renderOutput(value) {
77
80
  }
78
81
  });
79
82
  } else if (value.command === "search") {
80
- lines.push(`colgrep search failed (ok=${value.ok})`);
83
+ lines.push(value.ok ? "colgrep search returned unparseable output (ok=true)" : "colgrep search failed (ok=false)");
81
84
  if (value.stderr) lines.push(`[stderr]\n${value.stderr}`);
82
85
  else if (value.stdout) lines.push(`[stdout]\n${value.stdout}`);
83
86
  } else {
@@ -144,10 +147,16 @@ export function apply(ctx) {
144
147
  } catch {
145
148
  parsed = null;
146
149
  }
150
+ let results = null;
147
151
  if (Array.isArray(parsed)) {
148
- return { ...common, query: args.query, count: parsed.length, results: normalizeResults(parsed) };
152
+ results = normalizeResults(parsed);
153
+ } else if (parsed && typeof parsed === "object" && Array.isArray(parsed.results)) {
154
+ results = normalizeResults(parsed.results);
149
155
  }
150
- return { ...common, query: args.query, results: null, stdout, stderr };
156
+ if (results === null) {
157
+ return { ...common, query: args.query, results: null, stdout, stderr };
158
+ }
159
+ return { ...common, query: args.query, count: results.length, results };
151
160
  },
152
161
  }));
153
162
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hilariouhiss/dsh-colgrep",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "colgrep — semantic code search (ColBERT multi-vector) for DeepSeek Harness. Adds a `colgrep` tool that finds code by meaning, not exact text.",
5
5
  "keywords": [
6
6
  "dsh",