pi-ast-sgrep 2.0.2 → 2.1.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 +15 -19
- package/dist/code-mode.d.ts +1 -1
- package/dist/code-mode.js +1 -1
- package/dist/codemode/connector.d.ts +17 -3
- package/dist/codemode/connector.js +59 -31
- package/dist/codemode/dispatch.d.ts +13 -1
- package/dist/codemode/dispatch.js +83 -23
- package/dist/codemode/guest-api.d.ts +16 -0
- package/dist/codemode/guest-api.js +194 -0
- package/dist/codemode/guest-worker.mjs +287 -0
- package/dist/codemode/index.d.ts +4 -3
- package/dist/codemode/index.js +4 -3
- package/dist/codemode/runner.d.ts +13 -9
- package/dist/codemode/runner.js +411 -213
- package/dist/codemode/session-pool.d.ts +6 -1
- package/dist/codemode/session-pool.js +125 -32
- package/dist/codemode/types.d.ts +33 -2
- package/dist/codemode/types.js +39 -13
- package/dist/codemode/worker.d.ts +1 -1
- package/dist/codemode/worker.js +25 -2
- package/dist/host/commands.d.ts +6 -0
- package/dist/host/commands.js +49 -0
- package/dist/host/results.d.ts +115 -0
- package/dist/host/results.js +80 -0
- package/dist/host/tools.d.ts +9 -0
- package/dist/host/tools.js +610 -0
- package/dist/index.d.ts +7 -34
- package/dist/index.js +5 -543
- package/dist/runtime/config.d.ts +36 -0
- package/dist/runtime/config.js +98 -0
- package/dist/runtime/freshness.d.ts +43 -0
- package/dist/runtime/freshness.js +413 -0
- package/dist/runtime/index-health.d.ts +16 -0
- package/dist/runtime/index-health.js +109 -0
- package/dist/runtime/runtime.d.ts +48 -0
- package/dist/runtime/runtime.js +265 -0
- package/dist/runtime/sqlite.d.ts +15 -0
- package/dist/runtime/sqlite.js +63 -0
- package/dist/runtime/types.d.ts +55 -0
- package/dist/runtime/types.js +25 -0
- package/dist/ui/card.d.ts +63 -0
- package/dist/ui/card.js +316 -0
- package/dist/{present.d.ts → ui/present.d.ts} +20 -2
- package/dist/{present.js → ui/present.js} +68 -9
- package/package.json +6 -6
- package/dist/codemode/sandbox-worker.d.ts +0 -1
- package/dist/codemode/sandbox-worker.js +0 -204
- package/dist/runtime.d.ts +0 -137
- package/dist/runtime.js +0 -799
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-result plumbing shared by tools.ts and commands.ts: bounded text,
|
|
3
|
+
* success/failure envelopes, freshness-timeout classification, reporting.
|
|
4
|
+
*/
|
|
5
|
+
import { isClosedWorkerError } from "../codemode/index.js";
|
|
6
|
+
import { RuntimeError } from "../runtime/types.js";
|
|
7
|
+
import { formatEditResult, formatIndexResult, formatReadResult, formatSearchResult, formatStatusResult } from "../ui/present.js";
|
|
8
|
+
export const MAX_CONTENT_CHARS = 8_000;
|
|
9
|
+
export function bounded(text) {
|
|
10
|
+
return text.length <= MAX_CONTENT_CHARS ? text : `${text.slice(0, MAX_CONTENT_CHARS - 1)}…`;
|
|
11
|
+
}
|
|
12
|
+
export function success(command, response, extra = {}) {
|
|
13
|
+
const text = command === "status"
|
|
14
|
+
? formatStatusResult(response)
|
|
15
|
+
: command === "index" || command === "reindex"
|
|
16
|
+
? formatIndexResult(command, response)
|
|
17
|
+
: command === "edit"
|
|
18
|
+
? formatEditResult(response)
|
|
19
|
+
: command === "read"
|
|
20
|
+
? formatReadResult(response)
|
|
21
|
+
: formatSearchResult(response, { command, ...extra });
|
|
22
|
+
return {
|
|
23
|
+
content: [{ type: "text", text: bounded(text) }],
|
|
24
|
+
// The tool execute owns its machine command: normalize the envelope's
|
|
25
|
+
// command (native catalog names like index_status/index_repo must surface
|
|
26
|
+
// as the machine commands status/index/reindex).
|
|
27
|
+
details: { ok: true, command, response: { ...response, command }, ...extra },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function errorDetails(cause, signal) {
|
|
31
|
+
if (signal?.aborted) {
|
|
32
|
+
return { code: "CANCELLED", message: "cancelled", details: {} };
|
|
33
|
+
}
|
|
34
|
+
if (cause instanceof RuntimeError) {
|
|
35
|
+
return { code: cause.code, message: cause.message, details: cause.details };
|
|
36
|
+
}
|
|
37
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
38
|
+
if (/timed out after \d+ms|timeout after \d+ms|exceeded \d+ms/i.test(message)) {
|
|
39
|
+
return { code: "TIMEOUT", message, details: {} };
|
|
40
|
+
}
|
|
41
|
+
if (isClosedWorkerError(cause)) {
|
|
42
|
+
return {
|
|
43
|
+
code: "SESSION_CLOSED",
|
|
44
|
+
message: "asgrep session closed; retry the search",
|
|
45
|
+
details: {},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return { code: "UNEXPECTED_ERROR", message, details: {} };
|
|
49
|
+
}
|
|
50
|
+
export function isFreshnessTimeout(cause, userSignal) {
|
|
51
|
+
if (userSignal?.aborted)
|
|
52
|
+
return false;
|
|
53
|
+
if (cause instanceof RuntimeError && (cause.code === "TIMEOUT" || cause.code === "CANCELLED"))
|
|
54
|
+
return true;
|
|
55
|
+
if (isClosedWorkerError(cause))
|
|
56
|
+
return true;
|
|
57
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
58
|
+
return /timed out after \d+ms|timeout after \d+ms|exceeded \d+ms/i.test(message);
|
|
59
|
+
}
|
|
60
|
+
/** Leading or mid-query `in:path` scope used to bound a fresh-directory index. */
|
|
61
|
+
export function extractInPath(query) {
|
|
62
|
+
const match = /(?:^|\s)in:([^\s]+)/.exec(query);
|
|
63
|
+
const path = match?.[1];
|
|
64
|
+
if (!path || path.split(/[/\\]/u).includes(".."))
|
|
65
|
+
return undefined;
|
|
66
|
+
return path;
|
|
67
|
+
}
|
|
68
|
+
export function failure(command, cause, signal) {
|
|
69
|
+
const error = errorDetails(cause, signal);
|
|
70
|
+
return {
|
|
71
|
+
content: [{ type: "text", text: bounded(`${command} failed [${error.code}]: ${error.message}`) }],
|
|
72
|
+
details: { ok: false, command, error },
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function report(onUpdate, command, phase) {
|
|
76
|
+
onUpdate?.({
|
|
77
|
+
content: [{ type: "text", text: `${command} ${phase}` }],
|
|
78
|
+
details: { command, phase },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The four registered pi tools: asgrep (Code Mode), asgrep_search,
|
|
3
|
+
* asgrep_index, asgrep_status — plus the session pool, freshness wiring,
|
|
4
|
+
* and workspace event hooks that serve them.
|
|
5
|
+
*/
|
|
6
|
+
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
7
|
+
import { type FreshnessLike, type RuntimeLike } from "./results.js";
|
|
8
|
+
export declare const DEFAULT_LIMIT = 8;
|
|
9
|
+
export declare function registerAstSgrepTools(pi: ExtensionAPI, runtime?: RuntimeLike, freshness?: FreshnessLike): void;
|