@evandu/super-pi 0.1.239 → 0.1.241
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/dist/client/.super-pi-client-sources.json +8 -8
- package/dist/client/assets/{CodeMirrorEditor-CtzPSOsS.js → CodeMirrorEditor-CiOKD-_q.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-iNVZVVMb.js → GitDiffEditor-D5VMi7K-.js} +1 -1
- package/dist/client/assets/index-CwH7sttH.css +1 -0
- package/dist/client/assets/index-oUDSLOqG.js +347 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/extension-ui-service.d.ts +3 -1
- package/dist/server/application/extension-ui-service.js +20 -7
- package/dist/server/application/run-service.d.ts +19 -61
- package/dist/server/application/run-service.js +221 -372
- package/dist/server/application/workspace-service.js +1 -1
- package/dist/server/content-search.d.ts +13 -39
- package/dist/server/content-search.js +202 -219
- package/dist/server/exec-service.d.ts +14 -7
- package/dist/server/exec-service.js +66 -40
- package/dist/server/http-server.js +69 -31
- package/dist/server/index.js +6 -6
- package/dist/server/store.d.ts +11 -24
- package/dist/server/store.js +88 -62
- package/dist/server/subagent-runs.d.ts +3 -2
- package/dist/server/subagent-runs.js +45 -33
- package/dist/server/subagents.d.ts +1 -0
- package/dist/server/subagents.js +30 -12
- package/dist/server/types.d.ts +13 -11
- package/dist/server/ws-server.d.ts +3 -0
- package/dist/server/ws-server.js +40 -6
- package/dist/shared/background-task.d.ts +22 -0
- package/dist/shared/background-task.js +5 -0
- package/dist/shared/content-search.d.ts +22 -0
- package/dist/shared/content-search.js +1 -0
- package/package.json +1 -1
- package/dist/client/assets/index-C5kxyPTT.js +0 -340
- package/dist/client/assets/index-DN0oBG6l.css +0 -1
|
@@ -51,7 +51,7 @@ export class WorkspaceService {
|
|
|
51
51
|
const affected = snapshot.conversations.filter((c) => c.workspaceId === workspaceId);
|
|
52
52
|
for (const c of affected) {
|
|
53
53
|
this.extensionUiService.cancelPendingUi(c.id, "aborted");
|
|
54
|
-
if (this.runService.isRunning(c.id)) {
|
|
54
|
+
if (this.runService.isRunning(c.id) || snapshot.backgroundTasks.some(task => task.conversationId === c.id)) {
|
|
55
55
|
await this.runService.stopRun(c.id);
|
|
56
56
|
}
|
|
57
57
|
this.runService.stopConversationSubagents(c.id);
|
|
@@ -1,42 +1,16 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const MAX_CONTENT_RESULTS =
|
|
3
|
-
export declare const MAX_CONTENT_FILE_BYTES: number;
|
|
4
|
-
export declare const MAX_CONTENT_DEPTH = 12;
|
|
5
|
-
export declare const MAX_CONTENT_MS = 10000;
|
|
6
|
-
export type ContentSearchCandidate = {
|
|
7
|
-
path: string;
|
|
8
|
-
kind: "file" | "directory";
|
|
9
|
-
text: boolean | null;
|
|
10
|
-
size: number | null;
|
|
11
|
-
};
|
|
12
|
-
export type ContentSearchHit = {
|
|
13
|
-
path: string;
|
|
14
|
-
name: string;
|
|
15
|
-
line: number;
|
|
16
|
-
text: string;
|
|
17
|
-
};
|
|
18
|
-
export type ContentSearchResult = {
|
|
19
|
-
hits: ContentSearchHit[];
|
|
20
|
-
truncated: boolean;
|
|
21
|
-
skipped: string[];
|
|
22
|
-
complete: boolean;
|
|
23
|
-
reasons: string[];
|
|
24
|
-
};
|
|
25
|
-
type RipgrepMatch = {
|
|
26
|
-
path: string;
|
|
27
|
-
line: number;
|
|
28
|
-
text: string;
|
|
29
|
-
};
|
|
30
|
-
type RipgrepRun = (input: {
|
|
31
|
-
rgPath: string;
|
|
32
|
-
pattern: string;
|
|
33
|
-
paths: string[];
|
|
34
|
-
signal: AbortSignal;
|
|
35
|
-
onMatch: (match: RipgrepMatch) => Promise<boolean>;
|
|
36
|
-
}) => Promise<void>;
|
|
1
|
+
import type { ContentSearchHit, ContentSearchSummary } from "../shared/content-search.js";
|
|
2
|
+
export declare const MAX_CONTENT_RESULTS = 20000;
|
|
37
3
|
export type ContentSearchOptions = {
|
|
4
|
+
include?: string;
|
|
5
|
+
exclude?: string;
|
|
6
|
+
useIgnoreFiles?: boolean;
|
|
7
|
+
signal?: AbortSignal;
|
|
8
|
+
maxResults?: number;
|
|
9
|
+
onHits?: (hits: ContentSearchHit[]) => Promise<void>;
|
|
38
10
|
resolveRipgrep?: () => Promise<string | undefined>;
|
|
39
|
-
runRipgrep?: RipgrepRun;
|
|
40
11
|
};
|
|
41
|
-
export declare function
|
|
42
|
-
export {
|
|
12
|
+
export declare function isProtectedSearchPath(path: string): boolean;
|
|
13
|
+
export declare function searchByContent(root: string, query: string, options?: ContentSearchOptions): Promise<ContentSearchSummary & {
|
|
14
|
+
hits: ContentSearchHit[];
|
|
15
|
+
skipped: string[];
|
|
16
|
+
}>;
|
|
@@ -1,252 +1,235 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import { realpath } from "node:fs/promises";
|
|
4
|
+
import { basename, dirname, isAbsolute, join, posix, resolve } from "node:path";
|
|
4
5
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
|
-
import {
|
|
6
|
-
export const MAX_CONTENT_RESULTS =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
import { contains, createRootGuard, FilesError, toRelative } from "./files.js";
|
|
7
|
+
export const MAX_CONTENT_RESULTS = 20000;
|
|
8
|
+
const MAX_SEARCH_MS = 120000;
|
|
9
|
+
const MAX_EVENT_LENGTH = 8 * 1024 * 1024;
|
|
10
|
+
const PREVIEW_LENGTH = 400;
|
|
11
|
+
const BATCH_SIZE = 100;
|
|
10
12
|
let sdkRipgrep;
|
|
11
|
-
/** Pi's public package export hides this helper; resolve the installed module used by createGrepTool. */
|
|
12
13
|
async function resolveSdkRipgrep() {
|
|
13
14
|
sdkRipgrep ??= (async () => {
|
|
14
15
|
const entry = fileURLToPath(await import.meta.resolve("@earendil-works/pi-coding-agent"));
|
|
15
16
|
const manager = await import(pathToFileURL(join(dirname(entry), "utils", "tools-manager.js")).href);
|
|
16
17
|
return manager.getToolPath("rg") ?? manager.ensureTool("rg");
|
|
17
|
-
})();
|
|
18
|
-
|
|
18
|
+
})().catch((error) => { sdkRipgrep = undefined; throw error; });
|
|
19
|
+
const path = await sdkRipgrep;
|
|
20
|
+
if (!path)
|
|
21
|
+
sdkRipgrep = undefined;
|
|
22
|
+
return path;
|
|
19
23
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
child.kill();
|
|
36
|
-
} };
|
|
37
|
-
const onAbort = () => stop();
|
|
38
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
39
|
-
child.stdout.setEncoding("utf8");
|
|
40
|
-
child.stdout.on("data", (chunk) => {
|
|
41
|
-
stdout += chunk;
|
|
42
|
-
let newline;
|
|
43
|
-
while ((newline = stdout.indexOf("\n")) >= 0) {
|
|
44
|
-
const row = stdout.slice(0, newline);
|
|
45
|
-
stdout = stdout.slice(newline + 1);
|
|
46
|
-
chain = chain.then(async (continueSearch) => {
|
|
47
|
-
if (!continueSearch)
|
|
48
|
-
return false;
|
|
49
|
-
let event;
|
|
50
|
-
try {
|
|
51
|
-
event = JSON.parse(row);
|
|
52
|
-
}
|
|
53
|
-
catch {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
if (event.type !== "match")
|
|
57
|
-
return true;
|
|
58
|
-
const path = event.data?.path?.text;
|
|
59
|
-
const line = event.data?.line_number;
|
|
60
|
-
const text = event.data?.lines?.text;
|
|
61
|
-
if (!path || !Number.isSafeInteger(line))
|
|
62
|
-
return true;
|
|
63
|
-
const keepGoing = await onMatch({ path, line: line, text: typeof text === "string" ? normalizeLine(text) : "" });
|
|
64
|
-
if (!keepGoing)
|
|
65
|
-
stop();
|
|
66
|
-
return keepGoing;
|
|
67
|
-
});
|
|
68
|
-
chain.catch(() => { });
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
child.stderr.setEncoding("utf8");
|
|
72
|
-
child.stderr.on("data", (chunk) => { stderr += chunk; });
|
|
73
|
-
child.on("error", (error) => { signal.removeEventListener("abort", onAbort); reject(new Error(`Failed to run ripgrep: ${error.message}`)); });
|
|
74
|
-
child.on("close", (code) => {
|
|
75
|
-
signal.removeEventListener("abort", onAbort);
|
|
76
|
-
void chain.then(() => {
|
|
77
|
-
if (signal.aborted || stopped || code === 0 || code === 1)
|
|
78
|
-
resolve();
|
|
79
|
-
else
|
|
80
|
-
reject(new Error(`ripgrep failed (${code}): ${stderr.trim() || "unknown error"}`));
|
|
81
|
-
}, reject);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
async function checkedTextFile(absolute) {
|
|
85
|
-
try {
|
|
86
|
-
const info = await stat(absolute);
|
|
87
|
-
if (!info.isFile())
|
|
88
|
-
return "skip";
|
|
89
|
-
if (info.size > MAX_CONTENT_FILE_BYTES)
|
|
90
|
-
return "size";
|
|
91
|
-
const handle = await open(absolute, "r");
|
|
92
|
-
try {
|
|
93
|
-
const buffer = Buffer.alloc(MAX_CONTENT_FILE_BYTES + 1);
|
|
94
|
-
let length = 0;
|
|
95
|
-
while (length < buffer.length) {
|
|
96
|
-
const read = await handle.read(buffer, length, buffer.length - length, null);
|
|
97
|
-
if (!read.bytesRead)
|
|
98
|
-
break;
|
|
99
|
-
length += read.bytesRead;
|
|
100
|
-
}
|
|
101
|
-
if (length > MAX_CONTENT_FILE_BYTES)
|
|
102
|
-
return "size";
|
|
103
|
-
const bytes = buffer.subarray(0, length);
|
|
104
|
-
if (looksBinary(bytes) || bytes.includes(0))
|
|
105
|
-
return "skip";
|
|
106
|
-
new TextDecoder("utf-8", { fatal: true }).decode(bytes);
|
|
107
|
-
return "text";
|
|
108
|
-
}
|
|
109
|
-
finally {
|
|
110
|
-
await handle.close();
|
|
24
|
+
export function isProtectedSearchPath(path) {
|
|
25
|
+
return path.split("/").some((segment) => /^\.(?:git|super-pi)$/iu.test(segment));
|
|
26
|
+
}
|
|
27
|
+
function ripgrepArgs(query, { exclude, useIgnoreFiles }) {
|
|
28
|
+
const args = ["--no-config", "--json", "--hidden", "--no-follow", "--fixed-strings", "--color=never", "--no-require-git", "--threads", "4"];
|
|
29
|
+
if (useIgnoreFiles === false)
|
|
30
|
+
args.push("--no-ignore");
|
|
31
|
+
if (exclude)
|
|
32
|
+
args.push("--glob", "!" + exclude);
|
|
33
|
+
// The final exclusions cannot be overridden by an include glob.
|
|
34
|
+
for (const name of [".git", ".super-pi"])
|
|
35
|
+
args.push("--iglob", `!**/${name}`, "--iglob", `!**/${name}/**`);
|
|
36
|
+
if (useIgnoreFiles !== false) {
|
|
37
|
+
for (const name of ["node_modules", ".next", ".cache", ".venv", "coverage", "dist", "build"]) {
|
|
38
|
+
args.push("--glob", `!**/${name}`, "--glob", `!**/${name}/**`);
|
|
111
39
|
}
|
|
112
40
|
}
|
|
113
|
-
|
|
114
|
-
return "skip";
|
|
115
|
-
}
|
|
41
|
+
return [...args, "--", query, "."];
|
|
116
42
|
}
|
|
117
|
-
async function
|
|
43
|
+
async function isUtf8Text(path, signal) {
|
|
44
|
+
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
118
45
|
try {
|
|
119
|
-
const
|
|
120
|
-
|
|
46
|
+
for await (const bytes of createReadStream(path, { signal })) {
|
|
47
|
+
if (bytes.includes(0))
|
|
48
|
+
return false;
|
|
49
|
+
decoder.decode(bytes, { stream: true });
|
|
50
|
+
}
|
|
51
|
+
decoder.decode();
|
|
52
|
+
return true;
|
|
121
53
|
}
|
|
122
|
-
catch {
|
|
123
|
-
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error instanceof TypeError)
|
|
56
|
+
return false;
|
|
57
|
+
throw error;
|
|
124
58
|
}
|
|
125
59
|
}
|
|
126
|
-
function
|
|
127
|
-
|
|
60
|
+
function makeHit(path, event) {
|
|
61
|
+
const { line_number: line, lines, submatches } = event.data;
|
|
62
|
+
if (line === undefined || typeof lines?.text !== "string")
|
|
63
|
+
return;
|
|
64
|
+
const fullLine = lines.text.replace(/\r?\n$/u, "");
|
|
65
|
+
const before = submatches?.[0]?.start ?? 0;
|
|
66
|
+
const column = (before ? Buffer.from(fullLine).subarray(0, before).toString("utf8").length : 0) + 1;
|
|
67
|
+
const start = Math.max(0, column - Math.floor(PREVIEW_LENGTH / 3));
|
|
68
|
+
const excerpt = fullLine.slice(start, start + PREVIEW_LENGTH);
|
|
69
|
+
const text = (start ? "…" : "") + excerpt + (start + excerpt.length < fullLine.length ? "…" : "");
|
|
70
|
+
return { path, name: basename(path), line, column, text };
|
|
128
71
|
}
|
|
129
|
-
async function
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return output;
|
|
141
|
-
}
|
|
142
|
-
export async function searchByContent(root, candidates, query, indexStatus = { complete: true, skipped: [] }, options = {}) {
|
|
72
|
+
export async function searchByContent(root, query, options = {}) {
|
|
73
|
+
const hits = [];
|
|
74
|
+
const skipped = [];
|
|
75
|
+
const reasons = new Set();
|
|
76
|
+
const result = () => ({ hits, skipped, complete: reasons.size === 0, truncated: reasons.size > 0, reasons: [...reasons] });
|
|
77
|
+
if (!query.trim())
|
|
78
|
+
return result();
|
|
79
|
+
const timeout = AbortSignal.timeout(MAX_SEARCH_MS);
|
|
80
|
+
const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
|
|
81
|
+
const maxResults = options.maxResults ?? MAX_CONTENT_RESULTS;
|
|
82
|
+
const include = options.include && (options.include.includes("/") ? options.include : "**/" + options.include);
|
|
143
83
|
const guard = createRootGuard(root);
|
|
144
84
|
await guard("");
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
85
|
+
const canonicalRoot = await realpath(root);
|
|
86
|
+
if (isProtectedSearchPath(root.replaceAll("\\", "/").split("/").at(-1) ?? "")) {
|
|
87
|
+
throw new FilesError(403, "不能搜索应用或 Git 内部目录。", "protected_path");
|
|
88
|
+
}
|
|
89
|
+
signal.throwIfAborted();
|
|
90
|
+
const rgPath = await (options.resolveRipgrep ?? resolveSdkRipgrep)();
|
|
91
|
+
if (!rgPath)
|
|
92
|
+
throw new FilesError(503, "内容搜索不可用(ripgrep 不可用)", "ripgrep_unavailable");
|
|
93
|
+
signal.throwIfAborted();
|
|
94
|
+
const child = spawn(rgPath, ripgrepArgs(query, options), { cwd: root, stdio: ["ignore", "pipe", "pipe"], shell: false, windowsHide: true });
|
|
95
|
+
let spawnError;
|
|
96
|
+
let diagnostic = "";
|
|
97
|
+
child.stderr.setEncoding("utf8").on("data", (chunk) => { diagnostic = (diagnostic + chunk).slice(-4096); });
|
|
98
|
+
child.on("error", (error) => { spawnError = error; });
|
|
99
|
+
const closed = new Promise((done) => child.once("close", done));
|
|
100
|
+
const stop = () => { child.kill(); };
|
|
101
|
+
signal.addEventListener("abort", stop, { once: true });
|
|
102
|
+
let path = "";
|
|
103
|
+
let matches = [];
|
|
104
|
+
let overflow = false;
|
|
105
|
+
let accepted = 0;
|
|
106
|
+
let batch = [];
|
|
107
|
+
let lastFlush = 0;
|
|
108
|
+
const flush = async () => {
|
|
109
|
+
if (!batch.length)
|
|
110
|
+
return;
|
|
111
|
+
await options.onHits(batch);
|
|
112
|
+
batch = [];
|
|
113
|
+
lastFlush = Date.now();
|
|
114
|
+
};
|
|
115
|
+
const publishFile = async (event) => {
|
|
116
|
+
if ((!matches.length && !overflow) || event.data.binary_offset != null || signal.aborted)
|
|
117
|
+
return;
|
|
118
|
+
try {
|
|
119
|
+
// Ripgrep does not follow links. Revalidate on publication in case the tree changed during the scan.
|
|
120
|
+
const canonical = await realpath(await guard(path));
|
|
121
|
+
if (!contains(canonicalRoot, canonical) || isProtectedSearchPath(toRelative(canonicalRoot, canonical)))
|
|
122
|
+
return;
|
|
123
|
+
if (!await isUtf8Text(canonical, signal)) {
|
|
124
|
+
if (skipped.length < 100)
|
|
125
|
+
skipped.push(path);
|
|
126
|
+
reasons.add("encoding");
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
160
129
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error.code === "outside_workspace")
|
|
132
|
+
return;
|
|
133
|
+
if (!signal.aborted)
|
|
134
|
+
reasons.add("unreadable");
|
|
135
|
+
return;
|
|
167
136
|
}
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
137
|
+
if (signal.aborted)
|
|
138
|
+
return;
|
|
139
|
+
for (const match of matches) {
|
|
140
|
+
if (signal.aborted)
|
|
141
|
+
return;
|
|
142
|
+
if (options.onHits) {
|
|
143
|
+
batch.push(match);
|
|
144
|
+
if (batch.length >= BATCH_SIZE || Date.now() - lastFlush >= 80)
|
|
145
|
+
await flush();
|
|
146
|
+
}
|
|
147
|
+
else
|
|
148
|
+
hits.push(match);
|
|
171
149
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
reasons.add("
|
|
175
|
-
|
|
150
|
+
accepted += matches.length;
|
|
151
|
+
if (overflow) {
|
|
152
|
+
reasons.add("results");
|
|
153
|
+
stop();
|
|
176
154
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
155
|
+
};
|
|
156
|
+
const consume = async (line) => {
|
|
157
|
+
if (line.length > MAX_EVENT_LENGTH) {
|
|
158
|
+
reasons.add("line");
|
|
159
|
+
return;
|
|
181
160
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
161
|
+
const event = JSON.parse(line);
|
|
162
|
+
if (event.type === "begin") {
|
|
163
|
+
matches = [];
|
|
164
|
+
overflow = false;
|
|
165
|
+
const supplied = event.data.path?.text;
|
|
166
|
+
path = supplied && !isAbsolute(supplied) ? toRelative(root, resolve(root, supplied)) : "";
|
|
167
|
+
if (path === ".." || path.startsWith("../") || isAbsolute(path) || isProtectedSearchPath(path))
|
|
168
|
+
path = "";
|
|
169
|
+
// A positive rg glob overrides ignore files. Match includes separately so users can combine both.
|
|
170
|
+
if (include && !posix.matchesGlob(path, include))
|
|
171
|
+
path = "";
|
|
191
172
|
}
|
|
192
|
-
if (
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
|
|
173
|
+
else if (event.type === "match" && path) {
|
|
174
|
+
const match = makeHit(path, event);
|
|
175
|
+
if (match && accepted + matches.length < maxResults)
|
|
176
|
+
matches.push(match);
|
|
177
|
+
else if (match)
|
|
178
|
+
overflow = true;
|
|
179
|
+
else {
|
|
180
|
+
reasons.add("encoding");
|
|
181
|
+
if (skipped.length < 100 && !skipped.includes(path))
|
|
182
|
+
skipped.push(path);
|
|
183
|
+
}
|
|
197
184
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
185
|
+
else if (event.type === "end" && path) {
|
|
186
|
+
await publishFile(event);
|
|
187
|
+
path = "";
|
|
188
|
+
}
|
|
189
|
+
};
|
|
201
190
|
try {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
skipped.add(match.path);
|
|
223
|
-
reasons.add("unreadable");
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
if (!candidateByPath.has(path)) {
|
|
227
|
-
skipped.add(path);
|
|
228
|
-
reasons.add("unreadable");
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
const classification = await checkedTextFile(absolute);
|
|
232
|
-
if (classification !== "text") {
|
|
233
|
-
skipped.add(path);
|
|
234
|
-
if (classification === "size")
|
|
235
|
-
reasons.add("size");
|
|
236
|
-
return true;
|
|
237
|
-
}
|
|
238
|
-
hits.push({ path, name: basename(absolute), line: match.line, text: match.text });
|
|
239
|
-
if (hits.length >= MAX_CONTENT_RESULTS) {
|
|
240
|
-
reasons.add("results");
|
|
241
|
-
return false;
|
|
191
|
+
let pending = "";
|
|
192
|
+
let discard = false;
|
|
193
|
+
child.stdout.setEncoding("utf8");
|
|
194
|
+
read: for await (const chunk of child.stdout) {
|
|
195
|
+
const rows = chunk.split("\n");
|
|
196
|
+
const tail = rows.pop();
|
|
197
|
+
for (const row of rows) {
|
|
198
|
+
if (signal.aborted || reasons.has("results"))
|
|
199
|
+
break read;
|
|
200
|
+
if (!discard)
|
|
201
|
+
await consume(pending + row);
|
|
202
|
+
pending = "";
|
|
203
|
+
discard = false;
|
|
204
|
+
}
|
|
205
|
+
if (!discard) {
|
|
206
|
+
pending += tail;
|
|
207
|
+
if (pending.length > MAX_EVENT_LENGTH) {
|
|
208
|
+
reasons.add("line");
|
|
209
|
+
pending = "";
|
|
210
|
+
discard = true;
|
|
242
211
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const code = await closed;
|
|
215
|
+
if (spawnError)
|
|
216
|
+
throw new FilesError(503, "无法启动正文搜索引擎。", "ripgrep_unavailable");
|
|
217
|
+
if (timeout.aborted)
|
|
246
218
|
reasons.add("time");
|
|
219
|
+
if (!signal.aborted && !reasons.has("results") && code !== 0 && code !== 1) {
|
|
220
|
+
if (/^rg:.*(?:glob|error parsing|invalid definition)/imu.test(diagnostic))
|
|
221
|
+
throw new FilesError(400, "文件筛选规则无效。", "bad_glob");
|
|
222
|
+
if (!diagnostic.startsWith("rg: No files were searched"))
|
|
223
|
+
reasons.add("unreadable");
|
|
224
|
+
}
|
|
225
|
+
if (!options.signal?.aborted && options.onHits)
|
|
226
|
+
await flush();
|
|
227
|
+
return result();
|
|
247
228
|
}
|
|
248
229
|
finally {
|
|
249
|
-
|
|
230
|
+
signal.removeEventListener("abort", stop);
|
|
231
|
+
if (child.exitCode === null && child.signalCode === null && !spawnError)
|
|
232
|
+
stop();
|
|
233
|
+
await closed;
|
|
250
234
|
}
|
|
251
|
-
return { hits, truncated: reasons.size > 0, skipped: [...skipped], complete: indexStatus.complete, reasons: [...reasons] };
|
|
252
235
|
}
|
|
@@ -16,14 +16,19 @@ export interface ExecSession {
|
|
|
16
16
|
killed: boolean;
|
|
17
17
|
}
|
|
18
18
|
/** Callback fired when an exec session ends, with the final result. */
|
|
19
|
-
export type
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export type ExecCompletion = {
|
|
20
|
+
status: "exited" | "cancelled" | "interrupted";
|
|
21
|
+
signal?: number;
|
|
22
|
+
offset: number;
|
|
23
|
+
};
|
|
24
|
+
export type ExecCompleteHandler = (sessionId: string, exitCode: number, stdout: string, stderr: string, completion: ExecCompletion) => void;
|
|
25
|
+
type ExecCheckpoint = (id: string, output: string, offset: number) => Promise<void>;
|
|
22
26
|
export declare class ExecService {
|
|
27
|
+
private readonly onCheckpoint?;
|
|
23
28
|
private readonly sessions;
|
|
24
29
|
private readonly broadcast;
|
|
25
30
|
private readonly onComplete;
|
|
26
|
-
constructor(broadcast: (event: ExecEvent) => void, onComplete: ExecCompleteHandler);
|
|
31
|
+
constructor(broadcast: (event: ExecEvent) => void, onComplete: ExecCompleteHandler, onCheckpoint?: ExecCheckpoint | undefined);
|
|
27
32
|
get status(): {
|
|
28
33
|
enabled: boolean;
|
|
29
34
|
reason?: string;
|
|
@@ -32,7 +37,9 @@ export declare class ExecService {
|
|
|
32
37
|
outputSnapshots(state: Pick<AppState, "conversations" | "backgroundTasks">, scope?: {
|
|
33
38
|
conversationId?: string;
|
|
34
39
|
}): ExecEvent[];
|
|
35
|
-
kill(id: string): void;
|
|
36
|
-
|
|
37
|
-
|
|
40
|
+
kill(id: string, cancellation?: "cancelled" | "interrupted"): void;
|
|
41
|
+
stop(id: string, cancellation?: "cancelled" | "interrupted"): Promise<boolean>;
|
|
42
|
+
closeAll(): Promise<void>;
|
|
43
|
+
private finish;
|
|
38
44
|
}
|
|
45
|
+
export {};
|