@deepseek-ai/dsh-util-ripgrep 0.0.0-stage → 0.2.2-rc.3
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/LICENSE +21 -0
- package/README.i18n.yaml +37 -0
- package/README.md +78 -2
- package/README.zh.md +79 -0
- package/lib/index.js +103 -0
- package/lib/types/index.d.ts +37 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/package.json +40 -3
- package/src/index.ts +109 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DeepSeek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Bilingual-pair consistency record for README.md (docs/i18n/README.md): per heading
|
|
2
|
+
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
|
|
3
|
+
# After editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/util/ripgrep/README.md
|
|
5
|
+
/:
|
|
6
|
+
en: bc82952963b17d8c
|
|
7
|
+
zh: 675b139ebabdc650
|
|
8
|
+
/deepseek-ai-dsh-util-ripgrep:
|
|
9
|
+
en: b04d02f7de33360d
|
|
10
|
+
zh: 1cfe8f875568591b
|
|
11
|
+
/deepseek-ai-dsh-util-ripgrep/summary:
|
|
12
|
+
en: bb3d7c655f3adebc
|
|
13
|
+
zh: bffe6ea95d686080
|
|
14
|
+
/deepseek-ai-dsh-util-ripgrep/table-of-contents:
|
|
15
|
+
en: d152484eb41ac6b4
|
|
16
|
+
zh: 09388d293f9be9cb
|
|
17
|
+
/deepseek-ai-dsh-util-ripgrep/use-this-package:
|
|
18
|
+
en: 53799d1dd3fc2137
|
|
19
|
+
zh: da69fc599badb99d
|
|
20
|
+
/deepseek-ai-dsh-util-ripgrep/understand-the-implementation:
|
|
21
|
+
en: b0b0e642476cd3a3
|
|
22
|
+
zh: fa265461d2dabe03
|
|
23
|
+
/deepseek-ai-dsh-util-ripgrep/further-exploration:
|
|
24
|
+
en: a95949bcc607ac71
|
|
25
|
+
zh: da783fcb920b894f
|
|
26
|
+
/deepseek-ai-dsh-util-ripgrep/model-experience:
|
|
27
|
+
en: 9df66fc6f8d80d3e
|
|
28
|
+
zh: cf37a67237e3c082
|
|
29
|
+
/deepseek-ai-dsh-util-ripgrep/model-experience/kv-cache-effect:
|
|
30
|
+
en: 3b134ccd04fc3436
|
|
31
|
+
zh: 46c862e01cb4b9be
|
|
32
|
+
/deepseek-ai-dsh-util-ripgrep/known-limitations-and-deferred-work:
|
|
33
|
+
en: 1bfaa2f90e3c339b
|
|
34
|
+
zh: da09b60f225fcdf6
|
|
35
|
+
/deepseek-ai-dsh-util-ripgrep/known-limitations-and-deferred-work/dev-note:
|
|
36
|
+
en: e67f633dc6fe7773
|
|
37
|
+
zh: e88aeb617ffb74ea
|
package/README.md
CHANGED
|
@@ -1,3 +1,79 @@
|
|
|
1
|
-
|
|
1
|
+
---
|
|
2
|
+
description: "Run the packaged ripgrep binary through the composed subprocess provider, with bounded streaming for file-search consumers."
|
|
3
|
+
kind: "package-library"
|
|
4
|
+
---
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
# @deepseek-ai/dsh-util-ripgrep
|
|
7
|
+
|
|
8
|
+
English | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
12
|
+
Use this library to start packaged ripgrep without a shell or a system `rg` installation. `tool-fs-search` uses collected output; `workspace-files` reads file paths incrementally and stops at its configured cap. Callers supply the working directory, arguments, stream modes, termination grace and cancellation signal, and own exit-code interpretation.
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Use this package](#use-this-package)
|
|
17
|
+
- [Understand the implementation](#understand-the-implementation)
|
|
18
|
+
- [Further Exploration](#further-exploration)
|
|
19
|
+
- [Model Experience](#model-experience)
|
|
20
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
21
|
+
- [Dev Note](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## Use this package
|
|
27
|
+
|
|
28
|
+
Import `spawnRipgrep` from this package and pass the composed subprocess service plus an explicit `SubprocessSpawnSpec`; its `argv` contains only rg arguments. The returned handle exposes collected output or piped streams as requested. With piped stdout, `readRipgrepLines` delivers newline- or NUL-separated UTF-8 records; returning false from the callback terminates rg and suppresses remaining records. It awaits stdout, the process outcome and managed-range quiescence before returning. Callback, stream and provider failures reject after cleanup. Callers classify exit codes and cancellation using their own signal.
|
|
29
|
+
|
|
30
|
+
`resolveRgPath` is available independently for consumers that only need the executable path. Resolution and spawn failures reject the call; they do not prevent importing the package. This library is a dependency, not a profile plugin.
|
|
31
|
+
|
|
32
|
+
-----
|
|
33
|
+
|
|
34
|
+
<a id="understand-the-implementation"></a>
|
|
35
|
+
## Understand the implementation
|
|
36
|
+
|
|
37
|
+
<details>
|
|
38
|
+
<summary>Implementation internals — click to expand</summary>
|
|
39
|
+
|
|
40
|
+
The resolver selects the executable's existing `-rg` sidecar in a single-file runtime, otherwise the `@vscode/ripgrep` platform package. Electron paths replace `app.asar` with `app.asar.unpacked`. Every spawn prepends `--no-config` so an ambient rg configuration cannot enable a preprocessor. The subprocess provider owns environment scrubbing and termination; the caller owns deadlines and result budgets. See [the implementation](src/index.ts).
|
|
41
|
+
|
|
42
|
+
</details>
|
|
43
|
+
|
|
44
|
+
-----
|
|
45
|
+
|
|
46
|
+
<a id="further-exploration"></a>
|
|
47
|
+
## Further Exploration
|
|
48
|
+
|
|
49
|
+
- [Subprocess provider contract](../../subprocess/subprocess/README.md) — explicit spawn specifications and managed process ranges.
|
|
50
|
+
- [Model search tools](../../fs/tool-fs-search/README.md) — collected output, tool errors and result retention.
|
|
51
|
+
- [Workspace file search](../../api/workspace-files/README.md#search) — native ignore rules and shallow-first file/ancestor matching.
|
|
52
|
+
|
|
53
|
+
-----
|
|
54
|
+
|
|
55
|
+
<a id="model-experience"></a>
|
|
56
|
+
## Model Experience
|
|
57
|
+
|
|
58
|
+
Indirectly, through the search tools that consume the subprocess output.
|
|
59
|
+
|
|
60
|
+
#### KV Cache effect
|
|
61
|
+
|
|
62
|
+
None directly; consumers own model-visible results and request assembly.
|
|
63
|
+
|
|
64
|
+
## Known Limitations and Deferred Work
|
|
65
|
+
|
|
66
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
67
|
+
|
|
68
|
+
- **Co-located executable required** — resolution uses the Host's packaged binary path. A remote subprocess provider without that binary fails; there is no system-rg lookup or filesystem-traversal fallback.
|
|
69
|
+
- **Record buffering** — streaming retains one incomplete record plus the current stream chunk; callers whose filenames may contain newlines use NUL separators rather than newlines. Records decode as UTF-8, so a filename that is not valid UTF-8 arrives with U+FFFD replacements and cannot be opened by that string.
|
|
70
|
+
|
|
71
|
+
<a id="dev-note"></a>
|
|
72
|
+
### Dev Note
|
|
73
|
+
|
|
74
|
+
<details>
|
|
75
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
76
|
+
|
|
77
|
+
None.
|
|
78
|
+
|
|
79
|
+
</details>
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "通过组合的子进程提供方运行打包的 ripgrep,为文件搜索消费方提供有界流式读取。"
|
|
3
|
+
kind: "package-library"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @deepseek-ai/dsh-util-ripgrep
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概述
|
|
11
|
+
|
|
12
|
+
使用本库,无需 shell 或系统安装的 `rg` 即可启动打包的 ripgrep。`tool-fs-search` 使用收集后的输出;`workspace-files` 增量读取文件路径,并在配置的上限处停止。调用方显式传入工作目录、参数、流模式、终止宽限期与取消信号,并负责解释退出码。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
16
|
+
- [使用本包](#use-this-package)
|
|
17
|
+
- [理解实现](#understand-the-implementation)
|
|
18
|
+
- [进一步探索](#further-exploration)
|
|
19
|
+
- [模型体验](#model-experience)
|
|
20
|
+
- [已知限制与延期工作](#known-limitations-and-deferred-work)
|
|
21
|
+
- [开发备注](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
<a id="use-this-package"></a>
|
|
26
|
+
## 使用本包
|
|
27
|
+
|
|
28
|
+
从本包导入 `spawnRipgrep`,传入组合的子进程服务与显式的 `SubprocessSpawnSpec`;其中 `argv` 只包含 rg 参数。返回的 handle 按请求提供已收集输出或管道流。stdout 为管道时,`readRipgrepLines` 逐条提供以换行或 NUL 分隔的 UTF-8 记录;回调返回 false 会终止 rg,并抑制剩余记录。该函数等待 stdout、进程结果与托管进程范围全部结束后返回。回调、流或提供方失败会在清理后拒绝。调用方按自身 signal 解释退出码与取消。
|
|
29
|
+
|
|
30
|
+
只需要可执行文件路径的消费方可以独立使用 `resolveRgPath`。解析与启动失败会拒绝调用,不阻止导入本包。本库是依赖,不是 profile 插件。
|
|
31
|
+
|
|
32
|
+
-----
|
|
33
|
+
|
|
34
|
+
<a id="understand-the-implementation"></a>
|
|
35
|
+
## 理解实现
|
|
36
|
+
|
|
37
|
+
<details>
|
|
38
|
+
<summary>实现内幕——点击展开</summary>
|
|
39
|
+
|
|
40
|
+
单文件运行时优先选用可执行文件旁已有的 `-rg` 附属程序,否则使用 `@vscode/ripgrep` 平台包。Electron 路径将 `app.asar` 替换为 `app.asar.unpacked`。每次启动前置 `--no-config`,防止环境中的 rg 配置启用预处理程序。子进程提供方负责环境清理与终止;调用方负责截止时间与结果预算。参见[实现](src/index.ts)。
|
|
41
|
+
|
|
42
|
+
</details>
|
|
43
|
+
|
|
44
|
+
-----
|
|
45
|
+
|
|
46
|
+
<a id="further-exploration"></a>
|
|
47
|
+
## 进一步探索
|
|
48
|
+
|
|
49
|
+
- [子进程提供方约定](../../subprocess/subprocess/README.zh.md)——显式启动规格与托管进程范围。
|
|
50
|
+
- [模型搜索工具](../../fs/tool-fs-search/README.zh.md)——输出收集、工具错误与结果保留。
|
|
51
|
+
- [工作区文件搜索](../../api/workspace-files/README.zh.md#search)——原生忽略规则与浅层优先的文件及祖先目录匹配。
|
|
52
|
+
|
|
53
|
+
-----
|
|
54
|
+
|
|
55
|
+
<a id="model-experience"></a>
|
|
56
|
+
## 模型体验
|
|
57
|
+
|
|
58
|
+
间接影响,通过消费子进程输出的搜索工具。
|
|
59
|
+
|
|
60
|
+
#### KV Cache 影响
|
|
61
|
+
|
|
62
|
+
没有直接影响;模型可见结果与请求装配由消费方负责。
|
|
63
|
+
|
|
64
|
+
## 已知限制与延期工作
|
|
65
|
+
|
|
66
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
67
|
+
|
|
68
|
+
- **要求同处一个执行环境的程序**——解析使用 Host 的打包二进制路径。远端子进程提供方没有该程序时调用失败;不查找系统 rg,也不回退到文件系统遍历。
|
|
69
|
+
- **记录缓冲**——流式读取保留一条尚未完整的记录与当前流块;文件名可能含换行符的调用方使用 NUL 分隔符而不是换行符。记录按 UTF-8 解码,因此不是有效 UTF-8 的文件名会带着 U+FFFD 替换字符到达,无法用该字符串打开。
|
|
70
|
+
|
|
71
|
+
<a id="dev-note"></a>
|
|
72
|
+
### 开发备注
|
|
73
|
+
|
|
74
|
+
<details>
|
|
75
|
+
<summary>维护者工作上下文——点击展开</summary>
|
|
76
|
+
|
|
77
|
+
无。
|
|
78
|
+
|
|
79
|
+
</details>
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join, parse } from "node:path";
|
|
3
|
+
//#region lib/types/index.js
|
|
4
|
+
/** Packaged ripgrep resolution and subprocess execution, independent of tool or Remote consumers. */
|
|
5
|
+
let rgPathPromise;
|
|
6
|
+
/**
|
|
7
|
+
* Resolve the packaged executable lazily, once per process. Single-file runtimes use an existing
|
|
8
|
+
* `-rg` sidecar; Electron uses the unpacked ASAR path. Resolution failures reject
|
|
9
|
+
* this call, not package loading. No system executable or remote fallback is used.
|
|
10
|
+
* @returns the packaged executable's absolute path.
|
|
11
|
+
*/
|
|
12
|
+
function resolveRgPath() {
|
|
13
|
+
rgPathPromise ??= Promise.resolve().then(async () => {
|
|
14
|
+
const executable = parse(process.execPath);
|
|
15
|
+
const executableSidecar = process.platform === "win32" ? join(executable.dir, `${executable.name}-rg.exe`) : `${process.execPath}-rg`;
|
|
16
|
+
if ("pkg" in process && existsSync(executableSidecar)) return executableSidecar;
|
|
17
|
+
const dependency = (await import("@vscode/ripgrep")).rgPath;
|
|
18
|
+
return process.versions.electron === void 0 ? dependency : dependency.replace(/\.asar(?=[\\/])/u, ".asar.unpacked");
|
|
19
|
+
});
|
|
20
|
+
return rgPathPromise;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Start packaged ripgrep with explicit subprocess settings. `spec.argv` contains
|
|
24
|
+
* only rg arguments, without an executable. This function prepends the resolved
|
|
25
|
+
* rg executable path and `--no-config`, so ambient configuration cannot enable a
|
|
26
|
+
* preprocessor. The caller owns exit classification and process cleanup.
|
|
27
|
+
* @param subprocess - the composed subprocess service.
|
|
28
|
+
* @param spec - cwd, rg arguments (without the executable), stdio, signal and termination grace.
|
|
29
|
+
* @returns the live subprocess handle; resolution and synchronous spawn failures reject.
|
|
30
|
+
*/
|
|
31
|
+
async function spawnRipgrep(subprocess, spec) {
|
|
32
|
+
const executable = await resolveRgPath();
|
|
33
|
+
return subprocess.spawn({
|
|
34
|
+
...spec,
|
|
35
|
+
argv: [
|
|
36
|
+
executable,
|
|
37
|
+
"--no-config",
|
|
38
|
+
...spec.argv
|
|
39
|
+
]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Read UTF-8 stdout records without retaining the complete output. A false
|
|
44
|
+
* callback return terminates the process and suppresses remaining records.
|
|
45
|
+
* Completion, callback failure and stream failure all await process quiescence;
|
|
46
|
+
* provider failures reject. Exit codes and cancellation remain consumer-owned.
|
|
47
|
+
* @param handle - an owned ripgrep process spawned with piped stdout.
|
|
48
|
+
* Records are decoded as UTF-8, so bytes of a name that is not valid UTF-8
|
|
49
|
+
* arrive replaced with U+FFFD.
|
|
50
|
+
* @param separator - newline for text output, or NUL for file paths that may contain newlines.
|
|
51
|
+
* @param onLine - synchronous record consumer; false requests early termination.
|
|
52
|
+
* @returns exit facts after stdout and the managed process range settle.
|
|
53
|
+
*/
|
|
54
|
+
async function readRipgrepLines(handle, separator, onLine) {
|
|
55
|
+
const stdout = handle.stdout;
|
|
56
|
+
if (stdout === void 0) {
|
|
57
|
+
handle.terminate();
|
|
58
|
+
await Promise.allSettled([handle.done, handle.waitForExit()]);
|
|
59
|
+
throw new Error("ripgrep requires piped stdout");
|
|
60
|
+
}
|
|
61
|
+
stdout.setEncoding("utf8");
|
|
62
|
+
let stopped = false;
|
|
63
|
+
let completed = false;
|
|
64
|
+
const reading = (async () => {
|
|
65
|
+
let pending = "";
|
|
66
|
+
for await (const chunk of stdout) {
|
|
67
|
+
if (stopped) continue;
|
|
68
|
+
pending += chunk;
|
|
69
|
+
let end;
|
|
70
|
+
while ((end = pending.indexOf(separator)) !== -1) {
|
|
71
|
+
const line = pending.slice(0, end);
|
|
72
|
+
pending = pending.slice(end + 1);
|
|
73
|
+
if (!onLine(line)) {
|
|
74
|
+
stopped = true;
|
|
75
|
+
pending = "";
|
|
76
|
+
handle.terminate();
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (pending.length > 0 && !onLine(pending)) {
|
|
82
|
+
stopped = true;
|
|
83
|
+
handle.terminate();
|
|
84
|
+
}
|
|
85
|
+
})();
|
|
86
|
+
try {
|
|
87
|
+
const [, outcome] = await Promise.all([reading, handle.done]);
|
|
88
|
+
completed = true;
|
|
89
|
+
return {
|
|
90
|
+
outcome,
|
|
91
|
+
stopped
|
|
92
|
+
};
|
|
93
|
+
} finally {
|
|
94
|
+
if (!completed) {
|
|
95
|
+
handle.terminate();
|
|
96
|
+
stdout.destroy();
|
|
97
|
+
}
|
|
98
|
+
await Promise.allSettled([reading, handle.done]);
|
|
99
|
+
await handle.waitForExit();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
103
|
+
export { readRipgrepLines, resolveRgPath, spawnRipgrep };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { SubprocessHandle, SubprocessOutcome, SubprocessRuntime, SubprocessSpawnSpec } from '@deepseek-ai/dsh-subprocess';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the packaged executable lazily, once per process. Single-file runtimes use an existing
|
|
4
|
+
* `-rg` sidecar; Electron uses the unpacked ASAR path. Resolution failures reject
|
|
5
|
+
* this call, not package loading. No system executable or remote fallback is used.
|
|
6
|
+
* @returns the packaged executable's absolute path.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveRgPath(): Promise<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Start packaged ripgrep with explicit subprocess settings. `spec.argv` contains
|
|
11
|
+
* only rg arguments, without an executable. This function prepends the resolved
|
|
12
|
+
* rg executable path and `--no-config`, so ambient configuration cannot enable a
|
|
13
|
+
* preprocessor. The caller owns exit classification and process cleanup.
|
|
14
|
+
* @param subprocess - the composed subprocess service.
|
|
15
|
+
* @param spec - cwd, rg arguments (without the executable), stdio, signal and termination grace.
|
|
16
|
+
* @returns the live subprocess handle; resolution and synchronous spawn failures reject.
|
|
17
|
+
*/
|
|
18
|
+
export declare function spawnRipgrep(subprocess: Pick<SubprocessRuntime, 'spawn'>, spec: SubprocessSpawnSpec): Promise<SubprocessHandle>;
|
|
19
|
+
/** Exit facts and whether the line consumer requested early termination. */
|
|
20
|
+
export interface RipgrepLinesResult {
|
|
21
|
+
readonly outcome: SubprocessOutcome;
|
|
22
|
+
readonly stopped: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read UTF-8 stdout records without retaining the complete output. A false
|
|
26
|
+
* callback return terminates the process and suppresses remaining records.
|
|
27
|
+
* Completion, callback failure and stream failure all await process quiescence;
|
|
28
|
+
* provider failures reject. Exit codes and cancellation remain consumer-owned.
|
|
29
|
+
* @param handle - an owned ripgrep process spawned with piped stdout.
|
|
30
|
+
* Records are decoded as UTF-8, so bytes of a name that is not valid UTF-8
|
|
31
|
+
* arrive replaced with U+FFFD.
|
|
32
|
+
* @param separator - newline for text output, or NUL for file paths that may contain newlines.
|
|
33
|
+
* @param onLine - synchronous record consumer; false requests early termination.
|
|
34
|
+
* @returns exit facts after stdout and the managed process range settle.
|
|
35
|
+
*/
|
|
36
|
+
export declare function readRipgrepLines(handle: SubprocessHandle, separator: '\n' | '\0', onLine: (line: string) => boolean): Promise<RipgrepLinesResult>;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAA;AAI9H;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAa/C;AAED;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAAC,UAAU,EAAE,IAAI,CAAC,iBAAiB,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAGrI;AAED,4EAA4E;AAC5E,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;IACnC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,gBAAgB,EACxB,SAAS,EAAE,IAAI,GAAG,IAAI,EACtB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAChC,OAAO,CAAC,kBAAkB,CAAC,CA4C7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACpC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AAGvC,IAAI,aAA0C,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,UAAU,aAAa;IA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QACH,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;QAC7D,SAAS,GAAG,IAAI,CAAA;QAChB,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,CAAA;IAC7B,CAAC;YAAS,CAAC;QACT,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,CAAC,SAAS,EAAE,CAAA;YAClB,MAAM,CAAC,OAAO,EAAE,CAAA;QAClB,CAAC;QACD,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;QAChD,MAAM,MAAM,CAAC,WAAW,EAAE,CAAA;IAC5B,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-util-ripgrep",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"description": "Packaged ripgrep resolution and subprocess streaming helpers",
|
|
4
|
+
"version": "0.2.2-rc.3",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/util/ripgrep"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./src/*": "./src/*",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib/index.js",
|
|
26
|
+
"lib/types/**/*.d.ts",
|
|
27
|
+
"lib/types/**/*.d.ts.map",
|
|
28
|
+
"lib/**/*.js.map",
|
|
29
|
+
"src"
|
|
30
|
+
],
|
|
31
|
+
"license": "MIT",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vscode/ripgrep": "^1.18.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@deepseek-ai/cordis": "~4.1.0",
|
|
37
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.3"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@deepseek-ai/cordis": "~4.1.0",
|
|
41
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.3"
|
|
42
|
+
}
|
|
6
43
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** Packaged ripgrep resolution and subprocess execution, independent of tool or Remote consumers. */
|
|
2
|
+
import { existsSync } from 'node:fs'
|
|
3
|
+
import { join, parse } from 'node:path'
|
|
4
|
+
import type { SubprocessHandle, SubprocessOutcome, SubprocessRuntime, SubprocessSpawnSpec } from '@deepseek-ai/dsh-subprocess'
|
|
5
|
+
|
|
6
|
+
let rgPathPromise: Promise<string> | undefined
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the packaged executable lazily, once per process. Single-file runtimes use an existing
|
|
10
|
+
* `-rg` sidecar; Electron uses the unpacked ASAR path. Resolution failures reject
|
|
11
|
+
* this call, not package loading. No system executable or remote fallback is used.
|
|
12
|
+
* @returns the packaged executable's absolute path.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveRgPath(): Promise<string> {
|
|
15
|
+
rgPathPromise ??= Promise.resolve().then(async () => {
|
|
16
|
+
const executable = parse(process.execPath)
|
|
17
|
+
const executableSidecar = process.platform === 'win32'
|
|
18
|
+
? join(executable.dir, `${executable.name}-rg.exe`)
|
|
19
|
+
: `${process.execPath}-rg`
|
|
20
|
+
if ('pkg' in process && existsSync(executableSidecar)) return executableSidecar
|
|
21
|
+
const dependency = (await import('@vscode/ripgrep')).rgPath
|
|
22
|
+
return process.versions.electron === undefined
|
|
23
|
+
? dependency
|
|
24
|
+
: dependency.replace(/\.asar(?=[\\/])/u, '.asar.unpacked')
|
|
25
|
+
})
|
|
26
|
+
return rgPathPromise
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Start packaged ripgrep with explicit subprocess settings. `spec.argv` contains
|
|
31
|
+
* only rg arguments, without an executable. This function prepends the resolved
|
|
32
|
+
* rg executable path and `--no-config`, so ambient configuration cannot enable a
|
|
33
|
+
* preprocessor. The caller owns exit classification and process cleanup.
|
|
34
|
+
* @param subprocess - the composed subprocess service.
|
|
35
|
+
* @param spec - cwd, rg arguments (without the executable), stdio, signal and termination grace.
|
|
36
|
+
* @returns the live subprocess handle; resolution and synchronous spawn failures reject.
|
|
37
|
+
*/
|
|
38
|
+
export async function spawnRipgrep(subprocess: Pick<SubprocessRuntime, 'spawn'>, spec: SubprocessSpawnSpec): Promise<SubprocessHandle> {
|
|
39
|
+
const executable = await resolveRgPath()
|
|
40
|
+
return subprocess.spawn({ ...spec, argv: [executable, '--no-config', ...spec.argv] })
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Exit facts and whether the line consumer requested early termination. */
|
|
44
|
+
export interface RipgrepLinesResult {
|
|
45
|
+
readonly outcome: SubprocessOutcome
|
|
46
|
+
readonly stopped: boolean
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Read UTF-8 stdout records without retaining the complete output. A false
|
|
51
|
+
* callback return terminates the process and suppresses remaining records.
|
|
52
|
+
* Completion, callback failure and stream failure all await process quiescence;
|
|
53
|
+
* provider failures reject. Exit codes and cancellation remain consumer-owned.
|
|
54
|
+
* @param handle - an owned ripgrep process spawned with piped stdout.
|
|
55
|
+
* Records are decoded as UTF-8, so bytes of a name that is not valid UTF-8
|
|
56
|
+
* arrive replaced with U+FFFD.
|
|
57
|
+
* @param separator - newline for text output, or NUL for file paths that may contain newlines.
|
|
58
|
+
* @param onLine - synchronous record consumer; false requests early termination.
|
|
59
|
+
* @returns exit facts after stdout and the managed process range settle.
|
|
60
|
+
*/
|
|
61
|
+
export async function readRipgrepLines(
|
|
62
|
+
handle: SubprocessHandle,
|
|
63
|
+
separator: '\n' | '\0',
|
|
64
|
+
onLine: (line: string) => boolean,
|
|
65
|
+
): Promise<RipgrepLinesResult> {
|
|
66
|
+
const stdout = handle.stdout
|
|
67
|
+
if (stdout === undefined) {
|
|
68
|
+
handle.terminate()
|
|
69
|
+
await Promise.allSettled([handle.done, handle.waitForExit()])
|
|
70
|
+
throw new Error('ripgrep requires piped stdout')
|
|
71
|
+
}
|
|
72
|
+
stdout.setEncoding('utf8')
|
|
73
|
+
let stopped = false
|
|
74
|
+
let completed = false
|
|
75
|
+
const reading = (async () => {
|
|
76
|
+
let pending = ''
|
|
77
|
+
for await (const chunk of stdout as AsyncIterable<string>) {
|
|
78
|
+
if (stopped) continue
|
|
79
|
+
pending += chunk
|
|
80
|
+
let end: number
|
|
81
|
+
while ((end = pending.indexOf(separator)) !== -1) {
|
|
82
|
+
const line = pending.slice(0, end)
|
|
83
|
+
pending = pending.slice(end + 1)
|
|
84
|
+
if (!onLine(line)) {
|
|
85
|
+
stopped = true
|
|
86
|
+
pending = ''
|
|
87
|
+
handle.terminate()
|
|
88
|
+
break
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (pending.length > 0 && !onLine(pending)) {
|
|
93
|
+
stopped = true
|
|
94
|
+
handle.terminate()
|
|
95
|
+
}
|
|
96
|
+
})()
|
|
97
|
+
try {
|
|
98
|
+
const [, outcome] = await Promise.all([reading, handle.done])
|
|
99
|
+
completed = true
|
|
100
|
+
return { outcome, stopped }
|
|
101
|
+
} finally {
|
|
102
|
+
if (!completed) {
|
|
103
|
+
handle.terminate()
|
|
104
|
+
stdout.destroy()
|
|
105
|
+
}
|
|
106
|
+
await Promise.allSettled([reading, handle.done])
|
|
107
|
+
await handle.waitForExit()
|
|
108
|
+
}
|
|
109
|
+
}
|