pi-agent-ide 0.9.2 → 0.9.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/CHANGELOG.md +17 -0
- package/README.md +8 -4
- package/dist/chunk-2TTSJOLO.js +23 -0
- package/dist/{chunk-X2WFNMQR.js → chunk-6P7LTQZT.js} +1 -1
- package/dist/chunk-7C73WVPB.js +1 -0
- package/dist/chunk-7OUML24Z.js +13 -0
- package/dist/{chunk-IOGWZNWT.js → chunk-AP2BOC24.js} +1 -1
- package/dist/chunk-AVJVTF5H.js +1 -0
- package/dist/chunk-CJPS4GXD.js +1 -0
- package/dist/{chunk-O7V6G3OO.js → chunk-DAZQSXUW.js} +1 -1
- package/dist/chunk-DEWWWKUF.js +6 -0
- package/dist/chunk-DFXXT6MJ.js +17 -0
- package/dist/{chunk-4GBFIGH3.js → chunk-GHO6TCPJ.js} +1 -1
- package/dist/{chunk-H7WAM5RH.js → chunk-ICIRQLZ4.js} +2 -2
- package/dist/{chunk-HKYVP2Q6.js → chunk-JWSJCEIB.js} +1 -1
- package/dist/chunk-K5M65CAF.js +1 -0
- package/dist/{chunk-3LVBARLW.js → chunk-KWJD7FBS.js} +1 -1
- package/dist/{chunk-VNWGT367.js → chunk-LIQ4BVOB.js} +1 -1
- package/dist/chunk-LLP3EIJL.js +1 -0
- package/dist/chunk-MJFY4RGT.js +22 -0
- package/dist/{chunk-DVNL5NZE.js → chunk-MKDOT76B.js} +1 -1
- package/dist/chunk-OTVNO5SX.js +1 -0
- package/dist/{chunk-OUCVZBOR.js → chunk-U2N73BUY.js} +9 -9
- package/dist/chunk-UI4KSKS3.js +9 -0
- package/dist/chunk-XHFAV2NI.js +1 -0
- package/dist/entry-0.js +1 -1
- package/dist/entry-52.js +1 -1
- package/dist/entry-57.js +1 -1
- package/dist/entry-58.js +1 -1
- package/dist/entry-59.js +1 -1
- package/dist/entry-85.js +1 -1
- package/dist/pi-agent-ide.js +14 -14
- package/docs/agent-guides/ssh.md +1 -1
- package/docs/architecture.md +1 -1
- package/docs/configuration.md +17 -17
- package/docs/settings-help.md +1 -1
- package/docs/tools.md +1 -1
- package/node_modules/pi-agent-doctor/package.json +1 -1
- package/node_modules/pi-agent-documentation/package.json +1 -1
- package/node_modules/pi-agent-filesystem/package.json +7 -7
- package/node_modules/pi-agent-filesystem-image/package.json +3 -3
- package/node_modules/pi-agent-filesystem-jq/package.json +5 -5
- package/node_modules/pi-agent-filesystem-pdf/package.json +3 -3
- package/node_modules/pi-agent-filesystem-text/package.json +3 -3
- package/node_modules/pi-agent-ide-ast/package.json +13 -13
- package/node_modules/pi-agent-ide-changes/package.json +8 -8
- package/node_modules/pi-agent-ide-formatter/package.json +3 -3
- package/node_modules/pi-agent-ide-languages/package.json +2 -2
- package/node_modules/pi-agent-ide-lint/package.json +7 -7
- package/node_modules/pi-agent-ide-lsp/package.json +12 -12
- package/node_modules/pi-agent-image/package.json +2 -2
- package/node_modules/pi-agent-invariant/package.json +1 -1
- package/node_modules/pi-agent-pdf/package.json +2 -2
- package/node_modules/pi-agent-read/package.json +7 -7
- package/node_modules/pi-agent-read/src/core/extension.ts +1 -1
- package/node_modules/pi-agent-read/src/core/read-core.ts +5 -1
- package/node_modules/pi-agent-read/src/core/tools/tool-read.ts +15 -3
- package/node_modules/pi-agent-resource/package.json +1 -1
- package/node_modules/pi-agent-search/package.json +5 -5
- package/node_modules/pi-agent-search/src/core/extension.ts +3 -3
- package/node_modules/pi-agent-search-text/package.json +10 -10
- package/node_modules/pi-agent-text/package.json +2 -2
- package/node_modules/pi-agent-text-anchor-constant/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-exact/package.json +3 -3
- package/node_modules/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/node_modules/pi-agent-text-editor/package.json +9 -9
- package/node_modules/pi-agent-text-editor-renderer/index.ts +4 -3
- package/node_modules/pi-agent-text-editor-renderer/package.json +5 -5
- package/node_modules/pi-agent-text-editor-renderer/src/renderer.ts +6 -2
- package/node_modules/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/node_modules/pi-agent-tool-call-interception/package.json +2 -2
- package/node_modules/pi-agent-tool-ui/package.json +1 -1
- package/node_modules/pi-agent-web/package.json +7 -7
- package/node_modules/pi-agent-web-html/package.json +2 -2
- package/node_modules/pi-agent-web-image/package.json +3 -3
- package/node_modules/pi-agent-web-pdf/package.json +3 -3
- package/node_modules/pi-agent-web-text/package.json +3 -3
- package/package.json +35 -35
- package/skills/configure-agent-ide/SKILL.md +1 -1
- package/src/code-review/extension.ts +5 -2
- package/src/composite/builtin-extensions.ts +1 -0
- package/src/composite/live-presentation.ts +22 -0
- package/src/composite/module-labels.ts +4 -0
- package/src/composite/module-settings-store.ts +3 -2
- package/src/composite/module-settings.ts +118 -30
- package/src/composite/nested-tool-rendering.ts +9 -2
- package/src/composite/preferences.ts +12 -0
- package/src/composite/presets.ts +1 -0
- package/src/composite/reload-required.ts +75 -0
- package/src/composite/selection.ts +1 -0
- package/src/composite/settings-documentation.ts +1 -1
- package/src/composite/settings-panel.ts +1 -1
- package/src/core/extension.ts +4 -6
- package/src/core/live-feature-flag.ts +25 -0
- package/src/doctor/arguments.ts +1 -1
- package/src/doctor/extension.ts +3 -3
- package/src/doctor/run.ts +1 -1
- package/src/doctor/tip-provider.ts +1 -1
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-jq/package.json +5 -5
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-filesystem/plugins/pi-agent-filesystem-text/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/package.json +7 -7
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-html/package.json +2 -2
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-image/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-pdf/package.json +3 -3
- package/src/extensions/pi-agent-read/extensions/pi-agent-web/plugins/pi-agent-web-text/package.json +3 -3
- package/src/extensions/pi-agent-read/package.json +7 -7
- package/src/extensions/pi-agent-read/src/core/extension.ts +1 -1
- package/src/extensions/pi-agent-read/src/core/read-core.ts +5 -1
- package/src/extensions/pi-agent-read/src/core/tools/tool-read.ts +15 -3
- package/src/extensions/pi-agent-search/package.json +5 -5
- package/src/extensions/pi-agent-search/plugins/pi-agent-search-text/package.json +10 -10
- package/src/extensions/pi-agent-search/src/core/extension.ts +3 -3
- package/src/extensions/pi-agent-text-editor/package.json +9 -9
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-constant/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-exact/package.json +3 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-anchor-line-hash/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/index.ts +4 -3
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/package.json +5 -5
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-renderer/src/renderer.ts +6 -2
- package/src/extensions/pi-agent-text-editor/plugins/pi-agent-text-editor-stale-anchor/package.json +5 -5
- package/src/pi-agent-ide.ts +19 -4
- package/src/plugins/pi-agent-ide-ast/package.json +13 -13
- package/src/plugins/pi-agent-ide-changes/package.json +8 -8
- package/src/plugins/pi-agent-ide-formatter/package.json +3 -3
- package/src/plugins/pi-agent-ide-languages/package.json +2 -2
- package/src/plugins/pi-agent-ide-lint/package.json +7 -7
- package/src/plugins/pi-agent-ide-lsp/package.json +12 -12
- package/src/plugins/pi-agent-ide-processes/index.ts +4 -0
- package/src/plugins/pi-agent-ide-processes/src/ui.ts +9 -1
- package/src/plugins/pi-agent-ide-semantic/src/backend.ts +335 -0
- package/src/plugins/pi-agent-ide-semantic/src/vera-backend.ts +459 -0
- package/src/plugins/pi-agent-ide-terminal/index.ts +2 -1
- package/src/plugins/pi-agent-ide-terminal/src/tools.ts +15 -3
- package/src/semantic/engine.ts +8 -0
- package/src/semantic/extension.ts +186 -0
- package/src/semantic/index.ts +65 -0
- package/dist/chunk-IUJUECXH.js +0 -9
- package/dist/chunk-OBTT5INC.js +0 -6
- package/dist/chunk-PCGBM2D6.js +0 -17
- package/dist/chunk-RIZARTUM.js +0 -23
- package/dist/chunk-W7CASEO3.js +0 -1
- package/dist/chunk-WAJW4G4F.js +0 -22
- package/dist/chunk-XUYIK4TX.js +0 -1
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { constants } from "node:fs";
|
|
4
|
+
import {
|
|
5
|
+
access,
|
|
6
|
+
chmod,
|
|
7
|
+
copyFile,
|
|
8
|
+
link,
|
|
9
|
+
lstat,
|
|
10
|
+
mkdir,
|
|
11
|
+
mkdtemp,
|
|
12
|
+
realpath,
|
|
13
|
+
readFile,
|
|
14
|
+
rm,
|
|
15
|
+
stat,
|
|
16
|
+
writeFile,
|
|
17
|
+
} from "node:fs/promises";
|
|
18
|
+
import { homedir, tmpdir } from "node:os";
|
|
19
|
+
import { delimiter, join, relative, resolve, sep } from "node:path";
|
|
20
|
+
import { searchFiles } from "#src/extensions/pi-agent-search/plugins/pi-agent-search-text/src/file-search.js";
|
|
21
|
+
import type { BackendOptions, ProjectStatus } from "./backend.js";
|
|
22
|
+
|
|
23
|
+
const VERSION = "2.3.0"; // Version with the verified JSON and filtering contracts.
|
|
24
|
+
const RELEASE = `https://github.com/VeraTools/vera/releases/download/v${VERSION}`;
|
|
25
|
+
const MODEL =
|
|
26
|
+
"models/minishlab/potion-code-16M-v2/revisions/e9d2a44ca6a05ac6685f3b23709ea57eb7352d5b";
|
|
27
|
+
const ASSETS: Record<string, { name: string; sha256: string }> = {
|
|
28
|
+
"linux:x64": {
|
|
29
|
+
name: "vera-x86_64-unknown-linux-gnu.tar.gz",
|
|
30
|
+
sha256: "cf0e4c7847eaf2b4dd95c02c623ade21532762d1cf2a9361ea91558ba42145f9",
|
|
31
|
+
},
|
|
32
|
+
"linux:arm64": {
|
|
33
|
+
name: "vera-aarch64-unknown-linux-gnu.tar.gz",
|
|
34
|
+
sha256: "ff60f0f1c2796e7c249bf72ebc0212ca7f362f0f3d951d026ac522ea27e4eed3",
|
|
35
|
+
},
|
|
36
|
+
"darwin:x64": {
|
|
37
|
+
name: "vera-x86_64-apple-darwin.tar.gz",
|
|
38
|
+
sha256: "4864b2214df81d1d30cd0fd27adb41d98bb159d37be63f839f84627300858836",
|
|
39
|
+
},
|
|
40
|
+
"darwin:arm64": {
|
|
41
|
+
name: "vera-aarch64-apple-darwin.tar.gz",
|
|
42
|
+
sha256: "62d857a3085e5560377977893c3b3ef74c8be5f042b2b16b0c79d9a83651c3b8",
|
|
43
|
+
},
|
|
44
|
+
"win32:x64": {
|
|
45
|
+
name: "vera-x86_64-pc-windows-msvc.zip",
|
|
46
|
+
sha256: "9567d4ce722d8b941c7b5b13e8a99c448875a1914216291e691611870f2fd2b6",
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
function projectPath(cwd: string): string {
|
|
51
|
+
if (/^[a-z][a-z\d+.-]*:\/\//iu.test(cwd))
|
|
52
|
+
throw new Error("Semantic search supports local projects only");
|
|
53
|
+
return resolve(cwd);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function managedRoot(env: NodeJS.ProcessEnv): string {
|
|
57
|
+
const home = env.HOME || env.USERPROFILE || homedir();
|
|
58
|
+
return process.platform === "win32"
|
|
59
|
+
? join(env.LOCALAPPDATA || join(home, "AppData", "Local"), "pi-agent-ide")
|
|
60
|
+
: join(env.XDG_DATA_HOME || join(home, ".local", "share"), "pi-agent-ide");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function veraEnvironment(env: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
|
|
64
|
+
// Never inherit Vera's external endpoint, model or reranker settings. The IDE
|
|
65
|
+
// owns this data directory so the user's Vera configuration stays unchanged.
|
|
66
|
+
const clean = Object.fromEntries(
|
|
67
|
+
Object.entries(env).filter(
|
|
68
|
+
([key]) => !/^(?:VERA_|EMBEDDING_|RERANKER_|LOCAL_RERANKER_)/iu.test(key),
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
return {
|
|
72
|
+
...clean,
|
|
73
|
+
VERA_HOME: join(managedRoot(env), "vera"),
|
|
74
|
+
VERA_BACKEND: "potion-code-cpu",
|
|
75
|
+
VERA_NO_UPDATE_CHECK: "1",
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function binaryName(): string {
|
|
80
|
+
return process.platform === "win32" ? "vera.exe" : "vera";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function run(
|
|
84
|
+
command: string,
|
|
85
|
+
args: readonly string[],
|
|
86
|
+
cwd: string,
|
|
87
|
+
options: BackendOptions,
|
|
88
|
+
env = veraEnvironment(options.env ?? process.env),
|
|
89
|
+
): Promise<string> {
|
|
90
|
+
options.signal?.throwIfAborted();
|
|
91
|
+
return new Promise((done, reject) => {
|
|
92
|
+
const child = spawn(command, [...args], {
|
|
93
|
+
cwd,
|
|
94
|
+
env,
|
|
95
|
+
signal: options.signal,
|
|
96
|
+
windowsHide: true,
|
|
97
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
98
|
+
});
|
|
99
|
+
let stdout = "";
|
|
100
|
+
let stderr = "";
|
|
101
|
+
let overflow = false;
|
|
102
|
+
child.stdout.setEncoding("utf8");
|
|
103
|
+
child.stderr.setEncoding("utf8");
|
|
104
|
+
child.stdout.on("data", (chunk: string) => {
|
|
105
|
+
stdout += chunk;
|
|
106
|
+
if (stdout.length > 4_000_000) {
|
|
107
|
+
overflow = true;
|
|
108
|
+
child.kill();
|
|
109
|
+
}
|
|
110
|
+
options.onProgress?.(chunk);
|
|
111
|
+
});
|
|
112
|
+
child.stderr.on("data", (chunk: string) => {
|
|
113
|
+
stderr = (stderr + chunk).slice(-64_000);
|
|
114
|
+
options.onProgress?.(chunk);
|
|
115
|
+
});
|
|
116
|
+
child.on("error", reject);
|
|
117
|
+
child.on("close", (code) =>
|
|
118
|
+
overflow
|
|
119
|
+
? reject(new Error("Vera output exceeded the size limit"))
|
|
120
|
+
: code === 0
|
|
121
|
+
? done(stdout)
|
|
122
|
+
: reject(new Error(`${command} exited with code ${code}: ${stderr.trim()}`)),
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function findVera(options: BackendOptions): Promise<string | undefined> {
|
|
128
|
+
const env = options.env ?? process.env;
|
|
129
|
+
const candidates = [
|
|
130
|
+
...(env.PATH ?? "")
|
|
131
|
+
.split(delimiter)
|
|
132
|
+
.filter(Boolean)
|
|
133
|
+
.map((dir) => join(dir, binaryName())),
|
|
134
|
+
join(managedRoot(env), "bin", binaryName()),
|
|
135
|
+
];
|
|
136
|
+
for (const candidate of new Set(candidates)) {
|
|
137
|
+
options.signal?.throwIfAborted();
|
|
138
|
+
try {
|
|
139
|
+
await access(candidate, process.platform === "win32" ? constants.F_OK : constants.X_OK);
|
|
140
|
+
const version = await run(candidate, ["--version"], process.cwd(), {
|
|
141
|
+
...options,
|
|
142
|
+
onProgress: undefined,
|
|
143
|
+
signal: options.signal
|
|
144
|
+
? AbortSignal.any([options.signal, AbortSignal.timeout(5000)])
|
|
145
|
+
: AbortSignal.timeout(5000),
|
|
146
|
+
});
|
|
147
|
+
if (version.trim() === `vera ${VERSION}`) return candidate;
|
|
148
|
+
} catch {
|
|
149
|
+
options.signal?.throwIfAborted();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function modelReady(options: BackendOptions): Promise<boolean> {
|
|
156
|
+
const dir = join(veraEnvironment(options.env ?? process.env).VERA_HOME as string, MODEL);
|
|
157
|
+
try {
|
|
158
|
+
for (const file of ["config.json", "tokenizer.json", "model.safetensors"])
|
|
159
|
+
await access(join(dir, file), constants.R_OK);
|
|
160
|
+
return true;
|
|
161
|
+
} catch {
|
|
162
|
+
options.signal?.throwIfAborted();
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function indexValid(
|
|
168
|
+
executable: string,
|
|
169
|
+
project: string,
|
|
170
|
+
options: BackendOptions,
|
|
171
|
+
): Promise<boolean> {
|
|
172
|
+
try {
|
|
173
|
+
if (!(await lstat(join(project, ".vera"))).isDirectory()) return false;
|
|
174
|
+
const signal = options.signal
|
|
175
|
+
? AbortSignal.any([options.signal, AbortSignal.timeout(5000)])
|
|
176
|
+
: AbortSignal.timeout(5000);
|
|
177
|
+
const result: unknown = JSON.parse(
|
|
178
|
+
await run(executable, ["stats", "--json"], project, {
|
|
179
|
+
...options,
|
|
180
|
+
onProgress: undefined,
|
|
181
|
+
signal,
|
|
182
|
+
}),
|
|
183
|
+
);
|
|
184
|
+
return (
|
|
185
|
+
typeof result === "object" &&
|
|
186
|
+
result !== null &&
|
|
187
|
+
"file_count" in result &&
|
|
188
|
+
typeof result.file_count === "number" &&
|
|
189
|
+
"chunk_count" in result &&
|
|
190
|
+
typeof result.chunk_count === "number"
|
|
191
|
+
);
|
|
192
|
+
} catch {
|
|
193
|
+
options.signal?.throwIfAborted();
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function requireLocalConfiguration(options: BackendOptions): Promise<void> {
|
|
199
|
+
const home = veraEnvironment(options.env ?? process.env).VERA_HOME as string;
|
|
200
|
+
let config: unknown;
|
|
201
|
+
try {
|
|
202
|
+
config = JSON.parse(await readFile(join(home, "config.json"), "utf8"));
|
|
203
|
+
} catch {
|
|
204
|
+
throw new Error("Vera local configuration is missing or invalid; run /semantic-index");
|
|
205
|
+
}
|
|
206
|
+
if (
|
|
207
|
+
!config ||
|
|
208
|
+
typeof config !== "object" ||
|
|
209
|
+
Array.isArray(config) ||
|
|
210
|
+
!("backend" in config) ||
|
|
211
|
+
config.backend !== "potion-code" ||
|
|
212
|
+
!("local_mode" in config) ||
|
|
213
|
+
config.local_mode !== true ||
|
|
214
|
+
Object.keys(config).some((key) => !["config_format", "local_mode", "backend"].includes(key))
|
|
215
|
+
)
|
|
216
|
+
throw new Error("Vera local configuration contains unsupported settings; refusing to search");
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Inspect only the current project's index and the IDE-managed local model. */
|
|
220
|
+
export async function inspectVeraProject(
|
|
221
|
+
cwd: string,
|
|
222
|
+
options: BackendOptions = {},
|
|
223
|
+
): Promise<ProjectStatus> {
|
|
224
|
+
const project = projectPath(cwd);
|
|
225
|
+
const executable = await findVera(options);
|
|
226
|
+
if (!executable) return { usable: false };
|
|
227
|
+
try {
|
|
228
|
+
await requireLocalConfiguration(options);
|
|
229
|
+
} catch {
|
|
230
|
+
options.signal?.throwIfAborted();
|
|
231
|
+
return { usable: false, executable };
|
|
232
|
+
}
|
|
233
|
+
if (!(await modelReady(options)) || !(await indexValid(executable, project, options)))
|
|
234
|
+
return { usable: false, executable };
|
|
235
|
+
return { usable: true, executable, indexPath: join(project, ".vera") };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
async function installVera(options: BackendOptions): Promise<string> {
|
|
239
|
+
const asset = ASSETS[`${process.platform}:${process.arch}`];
|
|
240
|
+
if (!asset)
|
|
241
|
+
throw new Error(
|
|
242
|
+
`No Vera binary for ${process.platform}/${process.arch}; install Vera ${VERSION} yourself`,
|
|
243
|
+
);
|
|
244
|
+
options.onProgress?.(`Downloading Vera ${VERSION}\n`);
|
|
245
|
+
const response = await fetch(`${RELEASE}/${asset.name}`, { signal: options.signal });
|
|
246
|
+
if (!response.ok) throw new Error(`Vera download failed: HTTP ${response.status}`);
|
|
247
|
+
const bytes = Buffer.from(await response.arrayBuffer());
|
|
248
|
+
if (createHash("sha256").update(bytes).digest("hex") !== asset.sha256)
|
|
249
|
+
throw new Error("Vera download checksum mismatch");
|
|
250
|
+
const temp = await mkdtemp(join(tmpdir(), "pi-vera-"));
|
|
251
|
+
try {
|
|
252
|
+
const archive = join(temp, asset.name);
|
|
253
|
+
await writeFile(archive, bytes);
|
|
254
|
+
await run("tar", ["-xf", archive, "-C", temp], temp, { ...options, onProgress: undefined });
|
|
255
|
+
const source = join(temp, asset.name.replace(/\.(?:tar\.gz|zip)$/u, ""), binaryName());
|
|
256
|
+
const targetDir = join(managedRoot(options.env ?? process.env), "bin");
|
|
257
|
+
await mkdir(targetDir, { recursive: true });
|
|
258
|
+
const target = join(targetDir, binaryName());
|
|
259
|
+
const staging = await mkdtemp(join(targetDir, ".vera-install-"));
|
|
260
|
+
try {
|
|
261
|
+
const staged = join(staging, binaryName());
|
|
262
|
+
await copyFile(source, staged, constants.COPYFILE_EXCL);
|
|
263
|
+
if (process.platform !== "win32") await chmod(staged, 0o755);
|
|
264
|
+
try {
|
|
265
|
+
await link(staged, target);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
268
|
+
}
|
|
269
|
+
} finally {
|
|
270
|
+
await rm(staging, { recursive: true, force: true });
|
|
271
|
+
}
|
|
272
|
+
const version = await run(target, ["--version"], temp, { ...options, onProgress: undefined });
|
|
273
|
+
if (version.trim() !== `vera ${VERSION}`)
|
|
274
|
+
throw new Error(`Managed Vera is not version ${VERSION}`);
|
|
275
|
+
return target;
|
|
276
|
+
} finally {
|
|
277
|
+
await rm(temp, { recursive: true, force: true });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function checkUpdate(output: string): void {
|
|
282
|
+
const result: unknown = JSON.parse(output);
|
|
283
|
+
if (!result || typeof result !== "object" || Array.isArray(result))
|
|
284
|
+
throw new Error("Invalid Vera indexing output");
|
|
285
|
+
if (
|
|
286
|
+
"parse_errors" in result &&
|
|
287
|
+
(!Array.isArray(result.parse_errors) || result.parse_errors.length > 0)
|
|
288
|
+
)
|
|
289
|
+
throw new Error("Vera could not parse all indexed files");
|
|
290
|
+
for (const key of ["files_deferred", "embedding_failed_batches", "embedding_timeouts"]) {
|
|
291
|
+
if (
|
|
292
|
+
key in result &&
|
|
293
|
+
(typeof result[key as keyof typeof result] !== "number" ||
|
|
294
|
+
(result[key as keyof typeof result] as number) !== 0)
|
|
295
|
+
)
|
|
296
|
+
throw new Error("Vera did not update all indexed files");
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Explicit opt-in creates or updates only this project's index using local CPU embeddings. */
|
|
301
|
+
export async function indexVeraProject(
|
|
302
|
+
cwd: string,
|
|
303
|
+
options: BackendOptions = {},
|
|
304
|
+
): Promise<ProjectStatus> {
|
|
305
|
+
const project = projectPath(cwd);
|
|
306
|
+
const executable = (await findVera(options)) ?? (await installVera(options));
|
|
307
|
+
if (!(await modelReady(options))) {
|
|
308
|
+
options.onProgress?.("Preparing Vera local model\n");
|
|
309
|
+
await run(executable, ["setup", "--potion-code", "--yes"], project, options);
|
|
310
|
+
if (!(await modelReady(options))) throw new Error("Vera did not prepare its local model");
|
|
311
|
+
}
|
|
312
|
+
await requireLocalConfiguration(options);
|
|
313
|
+
options.onProgress?.("Indexing project with Vera\n");
|
|
314
|
+
let exists = false;
|
|
315
|
+
try {
|
|
316
|
+
exists = (await stat(join(project, ".vera"))).isDirectory();
|
|
317
|
+
} catch (error) {
|
|
318
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
319
|
+
}
|
|
320
|
+
if (exists && !(await indexValid(executable, project, options)))
|
|
321
|
+
throw new Error("Existing Vera index is unusable");
|
|
322
|
+
checkUpdate(
|
|
323
|
+
await run(executable, [exists ? "update" : "index", ".", "--potion-code", "--json"], project, {
|
|
324
|
+
...options,
|
|
325
|
+
onProgress: undefined,
|
|
326
|
+
}),
|
|
327
|
+
);
|
|
328
|
+
const status = await inspectVeraProject(project, options);
|
|
329
|
+
if (!status.usable) throw new Error("Vera did not create a usable project index");
|
|
330
|
+
return status;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function inside(base: string, path: string): boolean {
|
|
334
|
+
const a = process.platform === "win32" ? base.toLowerCase() : base;
|
|
335
|
+
const b = process.platform === "win32" ? path.toLowerCase() : path;
|
|
336
|
+
return a === b || b.startsWith(a.endsWith(sep) ? a : a + sep);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** Search fresh local Vera results; scope filtering is best-effort before ranking. */
|
|
340
|
+
export async function searchVeraProject(
|
|
341
|
+
cwd: string,
|
|
342
|
+
query: string,
|
|
343
|
+
options: BackendOptions & {
|
|
344
|
+
readonly limit?: number;
|
|
345
|
+
readonly path?: string;
|
|
346
|
+
readonly include?: string;
|
|
347
|
+
readonly exclude?: string;
|
|
348
|
+
} = {},
|
|
349
|
+
): Promise<string> {
|
|
350
|
+
const project = projectPath(cwd);
|
|
351
|
+
if (!query.trim()) throw new Error("A semantic search query is required");
|
|
352
|
+
const status = await inspectVeraProject(project, options);
|
|
353
|
+
if (!status.usable || !status.executable)
|
|
354
|
+
throw new Error("No usable Vera index for this project");
|
|
355
|
+
await requireLocalConfiguration(options);
|
|
356
|
+
const limit = options.limit ?? 15;
|
|
357
|
+
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new Error("Invalid result limit");
|
|
358
|
+
let scope: string | undefined;
|
|
359
|
+
let singleFile = false;
|
|
360
|
+
if (options.path !== undefined) {
|
|
361
|
+
if (!options.path.trim() || /^[a-z][a-z\d+.-]*:\/\//iu.test(options.path))
|
|
362
|
+
throw new Error("Invalid semantic search scope");
|
|
363
|
+
const target = resolve(project, options.path);
|
|
364
|
+
const root = await realpath(project);
|
|
365
|
+
let actual: string;
|
|
366
|
+
try {
|
|
367
|
+
actual = await realpath(target);
|
|
368
|
+
} catch {
|
|
369
|
+
throw new Error("Invalid semantic search scope: path does not exist");
|
|
370
|
+
}
|
|
371
|
+
if (!inside(project, target) || !inside(root, actual))
|
|
372
|
+
throw new Error("Invalid semantic search scope: outside project");
|
|
373
|
+
const info = await stat(actual);
|
|
374
|
+
if (!info.isFile() && !info.isDirectory())
|
|
375
|
+
throw new Error("Invalid semantic search scope: not a file or directory");
|
|
376
|
+
singleFile = info.isFile();
|
|
377
|
+
scope = relative(project, target) || ".";
|
|
378
|
+
}
|
|
379
|
+
checkUpdate(
|
|
380
|
+
await run(status.executable, ["update", ".", "--potion-code", "--json"], project, {
|
|
381
|
+
...options,
|
|
382
|
+
onProgress: undefined,
|
|
383
|
+
}),
|
|
384
|
+
);
|
|
385
|
+
const filtered =
|
|
386
|
+
scope !== undefined || options.include !== undefined || options.exclude !== undefined;
|
|
387
|
+
let allowed: Set<string> | undefined;
|
|
388
|
+
if (filtered) {
|
|
389
|
+
const files = await searchFiles(
|
|
390
|
+
"",
|
|
391
|
+
{ query: "", path: scope, include: options.include, exclude: options.exclude, limit: 50_000 },
|
|
392
|
+
project,
|
|
393
|
+
options.signal,
|
|
394
|
+
);
|
|
395
|
+
if (!files.complete)
|
|
396
|
+
throw new Error("Too many files to apply semantic search filters; narrow the scope");
|
|
397
|
+
allowed = new Set(files.files.map((file) => file.split(sep).join("/")));
|
|
398
|
+
}
|
|
399
|
+
const warning = filtered
|
|
400
|
+
? "Vera may omit relevant matches when a scope or filter is used.\n"
|
|
401
|
+
: "";
|
|
402
|
+
if (allowed?.size === 0) return `${warning}No semantic search results.`;
|
|
403
|
+
const args = ["search", "--json", "--potion-code", "--limit", String(singleFile ? 100 : limit)];
|
|
404
|
+
const paths = allowed ? [...allowed] : [];
|
|
405
|
+
if (
|
|
406
|
+
paths.length &&
|
|
407
|
+
paths.length <= 512 &&
|
|
408
|
+
paths.reduce((sum, value) => sum + Buffer.byteLength(value), 0) < 48_000
|
|
409
|
+
) {
|
|
410
|
+
for (const path of paths) args.push("--path", path);
|
|
411
|
+
} else if (scope && scope !== ".") args.push("--path", scope.split(sep).join("/"));
|
|
412
|
+
args.push("--", query);
|
|
413
|
+
const output: unknown = JSON.parse(
|
|
414
|
+
await run(status.executable, args, project, { ...options, onProgress: undefined }),
|
|
415
|
+
);
|
|
416
|
+
if (!Array.isArray(output)) throw new Error("Invalid Vera search output");
|
|
417
|
+
const files = new Map<string, Set<string>>();
|
|
418
|
+
for (const item of output as unknown[]) {
|
|
419
|
+
if (
|
|
420
|
+
!item ||
|
|
421
|
+
typeof item !== "object" ||
|
|
422
|
+
!("file_path" in item) ||
|
|
423
|
+
typeof item.file_path !== "string" ||
|
|
424
|
+
!("line_start" in item) ||
|
|
425
|
+
typeof item.line_start !== "number" ||
|
|
426
|
+
!("line_end" in item) ||
|
|
427
|
+
typeof item.line_end !== "number" ||
|
|
428
|
+
!Number.isInteger(item.line_start) ||
|
|
429
|
+
!Number.isInteger(item.line_end) ||
|
|
430
|
+
item.line_start < 1 ||
|
|
431
|
+
item.line_end < item.line_start
|
|
432
|
+
)
|
|
433
|
+
throw new Error("Invalid Vera search output");
|
|
434
|
+
const absolute = resolve(project, item.file_path);
|
|
435
|
+
if (!inside(project, absolute)) throw new Error("Vera returned a file outside the project");
|
|
436
|
+
const file = relative(project, absolute).split(sep).join("/");
|
|
437
|
+
if (allowed && !allowed.has(file)) continue;
|
|
438
|
+
const ranges = files.get(file) ?? new Set<string>();
|
|
439
|
+
ranges.add(`${item.line_start}-${item.line_end}`);
|
|
440
|
+
files.set(file, ranges);
|
|
441
|
+
}
|
|
442
|
+
if (!files.size) return `${warning}No semantic search results.`;
|
|
443
|
+
if (singleFile) {
|
|
444
|
+
const lines: string[] = [];
|
|
445
|
+
for (const [file, ranges] of files) {
|
|
446
|
+
const selected = [...ranges];
|
|
447
|
+
lines.push(...selected.slice(0, 15).map((range) => `${file}:${range}`));
|
|
448
|
+
if (selected.length > 15)
|
|
449
|
+
lines.push(`${selected.length - 15} additional retrieved ranges omitted`);
|
|
450
|
+
}
|
|
451
|
+
if (output.length === 100)
|
|
452
|
+
lines.push("More candidates may exist beyond Vera's retrieval limit");
|
|
453
|
+
return `${warning}Approximate ranges (read before editing):\n${lines.join("\n")}`;
|
|
454
|
+
}
|
|
455
|
+
return (
|
|
456
|
+
warning +
|
|
457
|
+
[...files].map(([file, ranges]) => `${file} (${ranges.size} retrieved candidates)`).join("\n")
|
|
458
|
+
);
|
|
459
|
+
}
|
|
@@ -51,12 +51,13 @@ export default async function registerTerminal(
|
|
|
51
51
|
const removeProcessProvider = agentIdeProcessRegistry(pi).add(terminalProcessProvider(manager));
|
|
52
52
|
|
|
53
53
|
await Promise.all([registerTerminalResources(pi, manager), registerTerminalSearch(pi, manager)]);
|
|
54
|
+
const presentation = () => toolPresentation(context?.preferences["ui.terminal"]);
|
|
54
55
|
const releaseForegroundWaits = registerTerminalTools(
|
|
55
56
|
pi,
|
|
56
57
|
manager,
|
|
57
58
|
profile,
|
|
58
59
|
ui,
|
|
59
|
-
|
|
60
|
+
presentation,
|
|
60
61
|
targets,
|
|
61
62
|
registerTerminalOrigins(pi),
|
|
62
63
|
);
|
|
@@ -75,7 +75,11 @@ export function registerTerminalTools(
|
|
|
75
75
|
manager: TerminalSessionManager,
|
|
76
76
|
profile: ShellProfile,
|
|
77
77
|
ui: Pick<TerminalUi, "bind" | "notifyWaitTransition">,
|
|
78
|
-
presentation:
|
|
78
|
+
presentation:
|
|
79
|
+
| "full"
|
|
80
|
+
| "compact"
|
|
81
|
+
| "disabled"
|
|
82
|
+
| (() => "full" | "compact" | "disabled") = "compact",
|
|
79
83
|
targets: SshBackendRegistry = new SshBackendRegistry([]),
|
|
80
84
|
executionOrigin?: (toolCallId: string, context: ExtensionContext) => TerminalExecutionOrigin,
|
|
81
85
|
): () => void {
|
|
@@ -152,7 +156,11 @@ export function registerTerminalTools(
|
|
|
152
156
|
return terminalResult(manager.snapshot(outcome.session));
|
|
153
157
|
},
|
|
154
158
|
renderCall(args, theme, context) {
|
|
155
|
-
const mode = context.expanded
|
|
159
|
+
const mode = context.expanded
|
|
160
|
+
? "full"
|
|
161
|
+
: typeof presentation === "function"
|
|
162
|
+
? presentation()
|
|
163
|
+
: presentation;
|
|
156
164
|
if (mode === "disabled") return new Text(theme.fg("toolTitle", toolName), 0, 0);
|
|
157
165
|
const command = typeof args.command === "string" ? args.command : "";
|
|
158
166
|
const remote = typeof args.cwd === "string" && args.cwd.startsWith("ssh:");
|
|
@@ -173,7 +181,11 @@ export function registerTerminalTools(
|
|
|
173
181
|
renderResult(result, options, theme) {
|
|
174
182
|
return renderRunResult(
|
|
175
183
|
result.details as Partial<TerminalSessionSnapshot>,
|
|
176
|
-
options.expanded
|
|
184
|
+
options.expanded
|
|
185
|
+
? "full"
|
|
186
|
+
: typeof presentation === "function"
|
|
187
|
+
? presentation()
|
|
188
|
+
: presentation,
|
|
177
189
|
theme,
|
|
178
190
|
);
|
|
179
191
|
},
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type SemanticEngine = "colgrep" | "vera";
|
|
2
|
+
|
|
3
|
+
/** Resolve the configured engine without silently falling back on invalid settings. */
|
|
4
|
+
export function semanticEngine(value: string | undefined): SemanticEngine {
|
|
5
|
+
if (value === undefined || value === "colgrep") return "colgrep";
|
|
6
|
+
if (value === "vera") return "vera";
|
|
7
|
+
throw new Error(`Unknown semantic search engine: ${value}`);
|
|
8
|
+
}
|