vexp-mcp 3.3.9 → 3.4.0
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/daemon-client.js +341 -63
- package/dist/index.js +34 -42
- package/dist/tools/index-status.js +52 -3
- package/dist/tools/run-pipeline.js +18 -1
- package/package.json +2 -2
package/dist/daemon-client.js
CHANGED
|
@@ -121,7 +121,10 @@ export class DaemonClient {
|
|
|
121
121
|
* transport so a per-workspace request can resurrect *its* daemon even when
|
|
122
122
|
* VEXP_WORKSPACE is not in the supervisor's env. */
|
|
123
123
|
spawnWorkspaceRoot;
|
|
124
|
-
|
|
124
|
+
/** The OS the start rules are applied for: this process's, or the one a
|
|
125
|
+
* test names (the Windows rules are tested on every OS). */
|
|
126
|
+
platform;
|
|
127
|
+
constructor(socketPath, sessionId, spawnWorkspaceRoot, platform = process.platform) {
|
|
125
128
|
// When a caller passes an explicit path we honor it for the client's
|
|
126
129
|
// lifetime (back-compat for tests and one-shot CLI usage). When omitted,
|
|
127
130
|
// we re-resolve via the registry on every connect so a long-lived HTTP
|
|
@@ -129,6 +132,7 @@ export class DaemonClient {
|
|
|
129
132
|
this.explicitSocketPath = socketPath;
|
|
130
133
|
this.sessionId = sessionId ?? randomUUID();
|
|
131
134
|
this.spawnWorkspaceRoot = spawnWorkspaceRoot;
|
|
135
|
+
this.platform = platform;
|
|
132
136
|
}
|
|
133
137
|
/**
|
|
134
138
|
* On a connection failure, attempt to start the daemon (idempotent lato
|
|
@@ -147,7 +151,11 @@ export class DaemonClient {
|
|
|
147
151
|
this.lastSpawnAttemptMs = now;
|
|
148
152
|
if (process.env.VEXP_NO_AUTOSTART === "1")
|
|
149
153
|
return;
|
|
150
|
-
|
|
154
|
+
// A subfolder of a fresh linked worktree starts that worktree's daemon
|
|
155
|
+
// (daemonStartRoot): the consent, the quota marker and the start below
|
|
156
|
+
// all belong to the worktree root, which the registry then routes the
|
|
157
|
+
// subfolder to.
|
|
158
|
+
const workspaceRoot = daemonStartRoot(resolveWorkspaceRoot(this.spawnWorkspaceRoot));
|
|
151
159
|
// Never resurrect a daemon that stopped on purpose: it would re-exit on its
|
|
152
160
|
// first quota check. `call()` already answers this case before reaching us;
|
|
153
161
|
// the guard keeps the contract true for any other caller.
|
|
@@ -160,7 +168,7 @@ export class DaemonClient {
|
|
|
160
168
|
// `git worktree remove` (git unregisters the worktree and leaves the
|
|
161
169
|
// folder behind; reproduced on Windows 11, 2026-09-30).
|
|
162
170
|
if (!setUpForVexp(workspaceRoot) &&
|
|
163
|
-
!(
|
|
171
|
+
!(this.platform !== "win32" && worktreeConsentSource(workspaceRoot)))
|
|
164
172
|
return;
|
|
165
173
|
// The daemon refuses the home directory itself; not asking spares the
|
|
166
174
|
// spawn and the "daemon did not start" it would answer with.
|
|
@@ -379,6 +387,16 @@ export class DaemonClient {
|
|
|
379
387
|
if (quota)
|
|
380
388
|
throw dailyLimitError(quota);
|
|
381
389
|
}
|
|
390
|
+
// A fresh git worktree on Windows: no daemon of its own, and
|
|
391
|
+
// maybeSpawnDaemon starts none there. The registry no longer hands it
|
|
392
|
+
// the main checkout's daemon (that index leaves the worktree out), so
|
|
393
|
+
// the retries below could only end in a raw `connect ENOENT` on the
|
|
394
|
+
// worktree's pipe. Say what is going on and what to do, once.
|
|
395
|
+
if (attempt === 0 && DaemonClient.isRetryableError(lastError) && !this.explicitSocketPath) {
|
|
396
|
+
const worktree = windowsWorktreeWithoutDaemon(resolveWorkspaceRoot(this.spawnWorkspaceRoot), this.platform);
|
|
397
|
+
if (worktree)
|
|
398
|
+
throw new Error(worktree);
|
|
399
|
+
}
|
|
382
400
|
if (attempt < DaemonClient.MAX_RETRIES && DaemonClient.isRetryableError(lastError)) {
|
|
383
401
|
// On the first failure, (re)start the daemon (cooldown-gated so a
|
|
384
402
|
// long-lived supervisor can resurrect it whenever it dies).
|
|
@@ -665,6 +683,27 @@ export class DaemonClient {
|
|
|
665
683
|
});
|
|
666
684
|
});
|
|
667
685
|
}
|
|
686
|
+
/**
|
|
687
|
+
* The workspace whose index answers this client when it is not the
|
|
688
|
+
* target's and cannot hold the target ({@link foreignIndexRoot}), with
|
|
689
|
+
* the target, or null. For run_pipeline's header, read after the call so it
|
|
690
|
+
* names the daemon that answered. Only for a client that resolves its
|
|
691
|
+
* target from the env, the cwd and the registry: one given its socket, an
|
|
692
|
+
* HTTP client pinned to its workspace and a connected repo talking to its
|
|
693
|
+
* workspace's daemon reach what they were sent to.
|
|
694
|
+
*/
|
|
695
|
+
foreignIndex() {
|
|
696
|
+
if (this.explicitSocketPath || this.spawnWorkspaceRoot || this.workspaceDaemonSocket)
|
|
697
|
+
return null;
|
|
698
|
+
try {
|
|
699
|
+
const t = resolveTargeting();
|
|
700
|
+
const served = foreignIndexRoot(t);
|
|
701
|
+
return served ? { served, target: t.workspaceRoot } : null;
|
|
702
|
+
}
|
|
703
|
+
catch {
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
668
707
|
/**
|
|
669
708
|
* Verifica se il daemon è raggiungibile
|
|
670
709
|
*/
|
|
@@ -813,6 +852,63 @@ export function setUpForVexp(dir) {
|
|
|
813
852
|
* git_project_root.
|
|
814
853
|
*/
|
|
815
854
|
export function worktreeConsentSource(dir) {
|
|
855
|
+
const main = linkedWorktreeMain(dir);
|
|
856
|
+
if (!main || isVexpStateHome(main))
|
|
857
|
+
return null;
|
|
858
|
+
const vexp = path.join(main, ".vexp");
|
|
859
|
+
return fs.existsSync(path.join(vexp, "manifest.json")) || fs.existsSync(path.join(vexp, "index.db"))
|
|
860
|
+
? main
|
|
861
|
+
: null;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Why no agent session starts a daemon for the git worktree `worktree` of
|
|
865
|
+
* `main` on Windows: a daemon holds the worktree's index open past the
|
|
866
|
+
* session, and Windows then refuses `git worktree remove` (git unregisters
|
|
867
|
+
* the worktree and leaves the folder behind; reproduced on Windows 11,
|
|
868
|
+
* 2026-09-30). ASCII, word for word vexp-core's
|
|
869
|
+
* mcp_stdio::worktree_no_daemon_on_windows (a test reads both).
|
|
870
|
+
*/
|
|
871
|
+
export function worktreeNoDaemonOnWindows(worktree, main) {
|
|
872
|
+
return `${worktree} is a git worktree of ${main}, and on Windows vexp starts no daemon for it from an agent session: a running daemon would keep the worktree's index open, and Windows would then refuse 'git worktree remove'`;
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* What an agent reads when its session is in a git worktree that has no
|
|
876
|
+
* daemon of its own, on Windows (`platform`), where this server starts
|
|
877
|
+
* none for it (maybeSpawnDaemon): the worktree, why, and the one remedy, in
|
|
878
|
+
* one line. null anywhere else: a worktree set up on its own
|
|
879
|
+
* (setUpForVexp, a window's "vexp: Start Indexing" leaves its index.db),
|
|
880
|
+
* any other OS, a folder that is no worktree of a set-up checkout.
|
|
881
|
+
*
|
|
882
|
+
* Without it the session got `connect ENOENT \\.\pipe\vexp-<hash>` and a
|
|
883
|
+
* targeting dump; before 3.4 it was answered from the main checkout's index,
|
|
884
|
+
* which leaves the worktree's files out. vexp-core's own server serves such
|
|
885
|
+
* a worktree in-process instead (cmd_mcp), so only this one says it.
|
|
886
|
+
*/
|
|
887
|
+
export function windowsWorktreeWithoutDaemon(target, platform = process.platform) {
|
|
888
|
+
if (platform !== "win32")
|
|
889
|
+
return null;
|
|
890
|
+
// A subfolder of the worktree names the worktree, the folder to open in VS
|
|
891
|
+
// Code (daemonStartRoot, the root maybeSpawnDaemon would start).
|
|
892
|
+
const workspaceRoot = daemonStartRoot(target);
|
|
893
|
+
if (setUpForVexp(workspaceRoot))
|
|
894
|
+
return null;
|
|
895
|
+
const main = worktreeConsentSource(workspaceRoot);
|
|
896
|
+
if (!main)
|
|
897
|
+
return null;
|
|
898
|
+
return (`${worktreeNoDaemonOnWindows(workspaceRoot, main)}. To index this worktree, open ${workspaceRoot} in VS Code ` +
|
|
899
|
+
`and run "vexp: Start Indexing". AGENT INSTRUCTION: do not retry; continue with your own tools and tell the user.`);
|
|
900
|
+
}
|
|
901
|
+
/**
|
|
902
|
+
* The main checkout of the linked git worktree whose root is `dir`, read
|
|
903
|
+
* from its `.git` FILE (`gitdir: <main>/.git/worktrees/<name>`; git 2.48's
|
|
904
|
+
* relative form resolves against `dir`), or null: a `.git` folder (the main
|
|
905
|
+
* checkout, a nested clone), a submodule (`.git/modules/`, or
|
|
906
|
+
* `.git/worktrees/<wt>/modules/` for one checked out inside a linked
|
|
907
|
+
* worktree), no `.git`.
|
|
908
|
+
* Decided by the file's content, never by where the folder sits. Lockstep
|
|
909
|
+
* with vexp-core utils::git_project_root / is_linked_worktree.
|
|
910
|
+
*/
|
|
911
|
+
export function linkedWorktreeMain(dir) {
|
|
816
912
|
let content;
|
|
817
913
|
try {
|
|
818
914
|
if (!fs.statSync(path.join(dir, ".git")).isFile())
|
|
@@ -832,53 +928,120 @@ export function worktreeConsentSource(dir) {
|
|
|
832
928
|
const at = gitdir ? gitdir.indexOf("/.git/worktrees/") : -1;
|
|
833
929
|
if (!gitdir || at <= 0)
|
|
834
930
|
return null;
|
|
835
|
-
|
|
836
|
-
|
|
931
|
+
// A worktree's admin dir is one folder, <common>/.git/worktrees/<name>. A
|
|
932
|
+
// submodule checked out inside a linked worktree has its git dir under
|
|
933
|
+
// that admin dir (<main>/.git/worktrees/<wt>/modules/<path>): it is its
|
|
934
|
+
// own project, as a submodule of the main checkout is, and reading it as
|
|
935
|
+
// a worktree of <main> lent it <main>'s consent and a daemon. Lockstep
|
|
936
|
+
// with vexp-core utils::git_project_root.
|
|
937
|
+
const name = gitdir.slice(at + "/.git/worktrees/".length).replace(/\/+$/, "");
|
|
938
|
+
if (!name || name.includes("/"))
|
|
837
939
|
return null;
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
940
|
+
const main = path.resolve(dir, gitdir.slice(0, at));
|
|
941
|
+
// A gitdir naming the folder itself links to no other checkout (vexp-core:
|
|
942
|
+
// git_project_root(dir) == dir is no worktree).
|
|
943
|
+
return main === path.resolve(dir) ? null : main;
|
|
842
944
|
}
|
|
843
945
|
/**
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
*
|
|
946
|
+
* The nearest folder at or above `start` that is the root of a linked git
|
|
947
|
+
* worktree, or null.
|
|
948
|
+
*
|
|
949
|
+
* Every worktree is a full checkout of its own, and the index of a folder
|
|
950
|
+
* above it never holds its files: the walk and the watcher prune any nested
|
|
951
|
+
* `.git` (vexp-core is_nested_git_checkout). So a worktree root is a wall
|
|
952
|
+
* for every search that walks up from inside it: discovery stops there, and
|
|
953
|
+
* the daemon registry never hands out a socket registered above it. Agent
|
|
954
|
+
* harnesses put worktrees inside the main checkout (`.worktrees/x`,
|
|
955
|
+
* `.claude/worktrees/agent-*`), and a fresh one was answered from the main
|
|
956
|
+
* checkout's index, with the main checkout's files (field report, devcontainer
|
|
957
|
+
* with `.worktrees/` under the repository, 2026-11).
|
|
847
958
|
*/
|
|
848
|
-
function
|
|
849
|
-
|
|
959
|
+
export function linkedWorktreeRootOf(start) {
|
|
960
|
+
let current = path.resolve(start);
|
|
961
|
+
while (true) {
|
|
962
|
+
if (linkedWorktreeMain(current))
|
|
963
|
+
return current;
|
|
964
|
+
const parent = path.dirname(current);
|
|
965
|
+
if (parent === current)
|
|
966
|
+
return null;
|
|
967
|
+
current = parent;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* The folder a daemon is started for when a session's workspace is `dir`:
|
|
972
|
+
* `dir` itself, unless `dir` is not set up on its own and sits inside a
|
|
973
|
+
* linked git worktree with no other checkout between them, where it is that
|
|
974
|
+
* worktree's root.
|
|
975
|
+
*
|
|
976
|
+
* A session opened on a subfolder of a fresh worktree (Claude Code started
|
|
977
|
+
* in <wt>/src sets CLAUDE_PROJECT_DIR there) got no daemon at all: the
|
|
978
|
+
* registry no longer hands it the main checkout's daemon (that index leaves
|
|
979
|
+
* the worktree out), and the consent check read the subfolder, which has no
|
|
980
|
+
* .git of its own and so no inherited consent. The worktree's daemon, once
|
|
981
|
+
* started, answers the subfolder through the registry's prefix match.
|
|
982
|
+
*
|
|
983
|
+
* The walk stops at the first `.git`: a nested clone or a submodule between
|
|
984
|
+
* the subfolder and the worktree is a project of its own and keeps today's
|
|
985
|
+
* rule, and so does any normal checkout (its nearest `.git` is a folder).
|
|
986
|
+
*/
|
|
987
|
+
export function daemonStartRoot(dir) {
|
|
988
|
+
if (setUpForVexp(dir))
|
|
989
|
+
return dir;
|
|
990
|
+
let current = path.resolve(dir);
|
|
991
|
+
while (true) {
|
|
992
|
+
if (fs.existsSync(path.join(current, ".git")))
|
|
993
|
+
return linkedWorktreeMain(current) ? current : dir;
|
|
994
|
+
const parent = path.dirname(current);
|
|
995
|
+
if (parent === current)
|
|
996
|
+
return dir;
|
|
997
|
+
current = parent;
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Walk up from `start` (the cwd) looking for .vexp/ or .git/ to find the
|
|
1002
|
+
* workspace root. Used when VEXP_WORKSPACE is not set (e.g., agent spawns
|
|
1003
|
+
* MCP server without passing the workspace path).
|
|
1004
|
+
*
|
|
1005
|
+
* Passes 1 and 2 never climb past the root of a linked git worktree
|
|
1006
|
+
* ({@link linkedWorktreeRootOf}): inside one, the worktree itself is the
|
|
1007
|
+
* root (pass 3), with no .vexp/ yet if it is fresh, and the main checkout
|
|
1008
|
+
* above it only lends its consent (worktreeConsentSource). An ancestor's
|
|
1009
|
+
* .vexp/ never answers for it. A nested clone (a `.git` folder) and a
|
|
1010
|
+
* submodule keep the rule they had. Lockstep with vexp-core
|
|
1011
|
+
* utils::discover_workspace_root, which walks the same folders.
|
|
1012
|
+
*/
|
|
1013
|
+
function discoverWorkspaceRoot(start = process.cwd()) {
|
|
1014
|
+
const cwd = path.resolve(start);
|
|
1015
|
+
const boundary = linkedWorktreeRootOf(cwd);
|
|
1016
|
+
const up = (dir) => {
|
|
1017
|
+
if (dir === boundary)
|
|
1018
|
+
return null;
|
|
1019
|
+
const parent = path.dirname(dir);
|
|
1020
|
+
return parent === dir ? null : parent;
|
|
1021
|
+
};
|
|
850
1022
|
// Pass 1: nearest ancestor with an INITIALIZED .vexp/ (manifest.json or
|
|
851
1023
|
// index.db) — a real indexed workspace, not a stray/empty .vexp/ dir. The
|
|
852
1024
|
// home directory never qualifies (isVexpStateHome).
|
|
853
1025
|
// MUST stay in lockstep with vexp-core/src/utils.rs::discover_workspace_root.
|
|
854
|
-
let current = cwd;
|
|
855
|
-
while (true) {
|
|
1026
|
+
for (let current = cwd; current; current = up(current)) {
|
|
856
1027
|
const vexp = path.join(current, ".vexp");
|
|
857
1028
|
if ((fs.existsSync(path.join(vexp, "manifest.json")) || fs.existsSync(path.join(vexp, "index.db"))) &&
|
|
858
1029
|
!isVexpStateHome(current)) {
|
|
859
1030
|
return current;
|
|
860
1031
|
}
|
|
861
|
-
const parent = path.dirname(current);
|
|
862
|
-
if (parent === current)
|
|
863
|
-
break;
|
|
864
|
-
current = parent;
|
|
865
1032
|
}
|
|
866
1033
|
// Pass 2: nearest ancestor with a bare .vexp/ (workspace mid-first-index)
|
|
867
1034
|
// — except the home/VEXP_HOME directory, whose .vexp is vexp's own STATE
|
|
868
1035
|
// dir: treating it as a workspace let an agent that spawns servers from
|
|
869
1036
|
// the home dir target the whole home (field report, 2026-09-02). Lockstep
|
|
870
1037
|
// with vexp-core utils::discover_workspace_root.
|
|
871
|
-
current = cwd;
|
|
872
|
-
while (true) {
|
|
1038
|
+
for (let current = cwd; current; current = up(current)) {
|
|
873
1039
|
if (fs.existsSync(path.join(current, ".vexp")) && !isVexpStateHome(current))
|
|
874
1040
|
return current;
|
|
875
|
-
const parent = path.dirname(current);
|
|
876
|
-
if (parent === current)
|
|
877
|
-
break;
|
|
878
|
-
current = parent;
|
|
879
1041
|
}
|
|
880
|
-
// Pass 3: .git/ fallback.
|
|
881
|
-
|
|
1042
|
+
// Pass 3: .git/ fallback. Within a linked worktree this is the worktree
|
|
1043
|
+
// itself, or a nested repository between it and the cwd.
|
|
1044
|
+
let current = cwd;
|
|
882
1045
|
while (true) {
|
|
883
1046
|
const gitDir = path.join(current, ".git");
|
|
884
1047
|
if (fs.existsSync(gitDir))
|
|
@@ -900,6 +1063,23 @@ function warnOnce(msg) {
|
|
|
900
1063
|
_warnedOnce.add(msg);
|
|
901
1064
|
console.error(msg);
|
|
902
1065
|
}
|
|
1066
|
+
/**
|
|
1067
|
+
* The value of a workspace variable, or undefined when it is unset, empty,
|
|
1068
|
+
* blank, or still holds an editor variable (`${workspaceFolder}`, anything
|
|
1069
|
+
* with `${`). vexp writes `"VEXP_WORKSPACE": "${workspaceFolder}"` into
|
|
1070
|
+
* .vscode/mcp.json so a committed file names no checkout; every VS Code that
|
|
1071
|
+
* reads that file (1.99+) expands it before it starts the server, or does
|
|
1072
|
+
* not start it. The literal text arrives from a .mcp.json entry (VS Code
|
|
1073
|
+
* 1.142+ expands only `${NAME}` from its own environment there) or a client
|
|
1074
|
+
* that expands nothing. Unset, the next signal decides: CLAUDE_PROJECT_DIR,
|
|
1075
|
+
* then the cwd, which VS Code sets to the folder that holds the file
|
|
1076
|
+
* (1.101.1+, and for .mcp.json). Lockstep
|
|
1077
|
+
* with vexp-core utils::workspace_env_value, which cmd_mcp reads them with.
|
|
1078
|
+
*/
|
|
1079
|
+
export function workspaceEnv(name) {
|
|
1080
|
+
const value = process.env[name];
|
|
1081
|
+
return value && value.trim() !== "" && !value.includes("${") ? value : undefined;
|
|
1082
|
+
}
|
|
903
1083
|
/**
|
|
904
1084
|
* Decide the workspace root AND which signal chose it. Single source of truth
|
|
905
1085
|
* for {@link resolveWorkspaceRoot} and {@link resolveTargeting} so they cannot
|
|
@@ -926,8 +1106,8 @@ function warnOnce(msg) {
|
|
|
926
1106
|
function resolveWorkspaceWithSource(explicit) {
|
|
927
1107
|
if (explicit)
|
|
928
1108
|
return { root: explicit, source: "VEXP_WORKSPACE" };
|
|
929
|
-
const vw =
|
|
930
|
-
const cpd =
|
|
1109
|
+
const vw = workspaceEnv("VEXP_WORKSPACE");
|
|
1110
|
+
const cpd = workspaceEnv("CLAUDE_PROJECT_DIR");
|
|
931
1111
|
if (vw && cpd && canonicalWorkspaceRoot(path.resolve(vw)).toLowerCase() !== canonicalWorkspaceRoot(path.resolve(cpd)).toLowerCase()) {
|
|
932
1112
|
warnOnce(`[vexp-mcp] VEXP_WORKSPACE=${vw} disagrees with this session's ` +
|
|
933
1113
|
`CLAUDE_PROJECT_DIR=${cpd}; using CLAUDE_PROJECT_DIR for per-session ` +
|
|
@@ -958,7 +1138,13 @@ export function resolveWorkspaceRoot(explicit) {
|
|
|
958
1138
|
* Selection policy:
|
|
959
1139
|
* 1. Exact workspace match
|
|
960
1140
|
* 2. Longest workspace that is a prefix of `workspaceHint` (handles
|
|
961
|
-
* submodule / nested-directory cwd pointing at a parent daemon)
|
|
1141
|
+
* submodule / nested-directory cwd pointing at a parent daemon), never
|
|
1142
|
+
* one above the root of a linked git worktree the hint sits in
|
|
1143
|
+
* ({@link linkedWorktreeRootOf}): that daemon's index leaves the
|
|
1144
|
+
* worktree out, and answering from it served the main checkout's files
|
|
1145
|
+
* to a session pinned to the worktree whenever the main checkout's
|
|
1146
|
+
* daemon happened to be up. With no daemon of its own, the worktree's is
|
|
1147
|
+
* started (maybeSpawnDaemon, with the main checkout's consent).
|
|
962
1148
|
* 3. Otherwise `null` (caller surfaces a clear "no daemon for this workspace"
|
|
963
1149
|
* error and/or respawns the right one).
|
|
964
1150
|
*
|
|
@@ -969,6 +1155,11 @@ export function resolveWorkspaceRoot(explicit) {
|
|
|
969
1155
|
* / spawn path, never to an unrelated repo.
|
|
970
1156
|
*/
|
|
971
1157
|
function pickFromDaemonRegistry(workspaceHint) {
|
|
1158
|
+
return pickRegistryEntry(workspaceHint)?.[1] ?? null;
|
|
1159
|
+
}
|
|
1160
|
+
/** {@link pickFromDaemonRegistry}, with the workspace the picked daemon
|
|
1161
|
+
* registered: `[workspace, socket]`. */
|
|
1162
|
+
function pickRegistryEntry(workspaceHint) {
|
|
972
1163
|
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
973
1164
|
if (!home)
|
|
974
1165
|
return null;
|
|
@@ -1000,22 +1191,32 @@ function pickFromDaemonRegistry(workspaceHint) {
|
|
|
1000
1191
|
const hintNorm = canonicalWorkspaceRoot(workspaceHint).toLowerCase();
|
|
1001
1192
|
for (const [ws, sock] of entries) {
|
|
1002
1193
|
if (ws.toLowerCase() === hintNorm)
|
|
1003
|
-
return sock;
|
|
1194
|
+
return [ws, sock];
|
|
1004
1195
|
}
|
|
1196
|
+
// An ancestor's daemon counts only at or below the worktree root the hint
|
|
1197
|
+
// sits in: both are prefixes of the hint, so "at or below" is "at least as
|
|
1198
|
+
// long".
|
|
1199
|
+
const worktree = linkedWorktreeRootOf(workspaceHint);
|
|
1200
|
+
const floor = worktree ? canonicalWorkspaceRoot(worktree).length : 0;
|
|
1005
1201
|
let bestWs = "";
|
|
1006
|
-
let
|
|
1202
|
+
let best = null;
|
|
1007
1203
|
for (const [ws, sock] of entries) {
|
|
1008
1204
|
const wsNorm = ws.toLowerCase();
|
|
1205
|
+
if (wsNorm.length < floor)
|
|
1206
|
+
continue;
|
|
1009
1207
|
if (hintNorm.startsWith(wsNorm + path.sep) || hintNorm === wsNorm) {
|
|
1010
1208
|
if (wsNorm.length > bestWs.length) {
|
|
1011
1209
|
bestWs = wsNorm;
|
|
1012
|
-
|
|
1210
|
+
best = [ws, sock];
|
|
1013
1211
|
}
|
|
1014
1212
|
}
|
|
1015
1213
|
}
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1214
|
+
return best;
|
|
1215
|
+
}
|
|
1216
|
+
/** The workspace a live daemon registered for `socket`, or null. */
|
|
1217
|
+
function registeredWorkspaceOf(socket) {
|
|
1218
|
+
const hit = liveDaemonEntries().find(([, sock]) => sock === socket);
|
|
1219
|
+
return hit ? hit[0] : null;
|
|
1019
1220
|
}
|
|
1020
1221
|
/** All live `[workspace, socket]` entries in `~/.vexp/daemons.json`, dropping
|
|
1021
1222
|
* stale ones whose socket no longer exists (same liveness filter as
|
|
@@ -1067,7 +1268,8 @@ export function resolveTargeting() {
|
|
|
1067
1268
|
const { root: workspaceRoot, source } = resolveWorkspaceWithSource();
|
|
1068
1269
|
const explicit = process.env["VEXP_SOCKET"];
|
|
1069
1270
|
if (explicit) {
|
|
1070
|
-
|
|
1271
|
+
const daemonRoot = registeredWorkspaceOf(explicit) ?? undefined;
|
|
1272
|
+
return { socket: explicit, source, socketOrigin: "explicit", workspaceRoot, daemonRoot };
|
|
1071
1273
|
}
|
|
1072
1274
|
if (process.platform === "win32") {
|
|
1073
1275
|
// Workspace-specific pipe name file written by the daemon
|
|
@@ -1075,27 +1277,79 @@ export function resolveTargeting() {
|
|
|
1075
1277
|
try {
|
|
1076
1278
|
const pipeName = fs.readFileSync(pipeFile, "utf-8").trim();
|
|
1077
1279
|
if (pipeName)
|
|
1078
|
-
return { socket: pipeName, source, socketOrigin: "workspace-local", workspaceRoot };
|
|
1280
|
+
return { socket: pipeName, source, socketOrigin: "workspace-local", workspaceRoot, daemonRoot: workspaceRoot };
|
|
1079
1281
|
}
|
|
1080
1282
|
catch { /* missing */ }
|
|
1081
1283
|
// Registry
|
|
1082
|
-
const fromRegistry =
|
|
1083
|
-
if (fromRegistry)
|
|
1084
|
-
return { socket: fromRegistry, source, socketOrigin: "registry", workspaceRoot };
|
|
1284
|
+
const fromRegistry = pickRegistryEntry(workspaceRoot);
|
|
1285
|
+
if (fromRegistry) {
|
|
1286
|
+
return { socket: fromRegistry[1], source, socketOrigin: "registry", workspaceRoot, daemonRoot: fromRegistry[0] };
|
|
1287
|
+
}
|
|
1085
1288
|
// Hash-based last-ditch (daemon should always register, so this is rare)
|
|
1086
1289
|
const hash = fnvHash(canonicalWorkspaceRoot(workspaceRoot).toLowerCase());
|
|
1087
|
-
return {
|
|
1290
|
+
return {
|
|
1291
|
+
socket: `\\\\.\\pipe\\vexp-${hash.slice(0, 8)}`,
|
|
1292
|
+
source,
|
|
1293
|
+
socketOrigin: "hash-fallback",
|
|
1294
|
+
workspaceRoot,
|
|
1295
|
+
daemonRoot: workspaceRoot,
|
|
1296
|
+
};
|
|
1088
1297
|
}
|
|
1089
1298
|
// Unix: prefer workspace-local if the socket file actually exists
|
|
1090
1299
|
const cwdSocket = path.join(workspaceRoot, ".vexp", "daemon.sock");
|
|
1091
|
-
if (fs.existsSync(cwdSocket))
|
|
1092
|
-
return { socket: cwdSocket, source, socketOrigin: "workspace-local", workspaceRoot };
|
|
1300
|
+
if (fs.existsSync(cwdSocket)) {
|
|
1301
|
+
return { socket: cwdSocket, source, socketOrigin: "workspace-local", workspaceRoot, daemonRoot: workspaceRoot };
|
|
1302
|
+
}
|
|
1093
1303
|
// Registry (Linux + macOS)
|
|
1094
|
-
const fromRegistry =
|
|
1095
|
-
if (fromRegistry)
|
|
1096
|
-
return { socket: fromRegistry, source, socketOrigin: "registry", workspaceRoot };
|
|
1304
|
+
const fromRegistry = pickRegistryEntry(workspaceRoot);
|
|
1305
|
+
if (fromRegistry) {
|
|
1306
|
+
return { socket: fromRegistry[1], source, socketOrigin: "registry", workspaceRoot, daemonRoot: fromRegistry[0] };
|
|
1307
|
+
}
|
|
1097
1308
|
return { socket: null, source, socketOrigin: "none", workspaceRoot };
|
|
1098
1309
|
}
|
|
1310
|
+
/**
|
|
1311
|
+
* The workspace whose index answers for `t` when that index cannot hold
|
|
1312
|
+
* the target's files, or null.
|
|
1313
|
+
*
|
|
1314
|
+
* It cannot when the daemon reached is another root's (an ancestor's,
|
|
1315
|
+
* through the registry, or the one VEXP_SOCKET names) and the target lies
|
|
1316
|
+
* outside that root or inside a nested checkout below it: the walk and the
|
|
1317
|
+
* watcher prune every folder below the root that holds a `.git` file or
|
|
1318
|
+
* folder (vexp-core is_nested_git_checkout), so a nested clone, a submodule
|
|
1319
|
+
* or a worktree is never in it. A folder inside the root with no checkout
|
|
1320
|
+
* between them is in its index (a session opened on a subfolder), and a
|
|
1321
|
+
* repository the served root's workspace.json connects, and any folder
|
|
1322
|
+
* inside it, is served by that daemon on purpose: null for both. run_pipeline's header says it, because
|
|
1323
|
+
* its answers otherwise read as the target's (field report, 2026-11).
|
|
1324
|
+
*/
|
|
1325
|
+
export function foreignIndexRoot(t) {
|
|
1326
|
+
const served = t.daemonRoot;
|
|
1327
|
+
if (!served)
|
|
1328
|
+
return null;
|
|
1329
|
+
const norm = (p) => canonicalWorkspaceRoot(path.resolve(p)).replace(/[\\/]+$/, "").toLowerCase();
|
|
1330
|
+
const top = norm(served);
|
|
1331
|
+
const target = path.resolve(t.workspaceRoot);
|
|
1332
|
+
if (norm(target) === top)
|
|
1333
|
+
return null;
|
|
1334
|
+
// Walk from the target up to the checkout that holds it: the first folder
|
|
1335
|
+
// the served root's workspace connects (or whose backlink names it) is
|
|
1336
|
+
// served on purpose, whatever subfolder the session opened; the first
|
|
1337
|
+
// other folder with a .git is a checkout that index prunes; reaching the
|
|
1338
|
+
// served root means a plain subfolder of it. Deciding on the target alone
|
|
1339
|
+
// reported a subfolder of a connected repo (/work/repoA/sub) as foreign on
|
|
1340
|
+
// every call, though /work's daemon serves it (review, 2026-11-07).
|
|
1341
|
+
for (let current = target;; current = path.dirname(current)) {
|
|
1342
|
+
if (norm(current) === top)
|
|
1343
|
+
return null;
|
|
1344
|
+
const parent = parentWorkspaceOf(current);
|
|
1345
|
+
if (workspaceConnects(served, current) || (parent && norm(parent) === top))
|
|
1346
|
+
return null;
|
|
1347
|
+
if (fs.existsSync(path.join(current, ".git")))
|
|
1348
|
+
return served;
|
|
1349
|
+
if (path.dirname(current) === current)
|
|
1350
|
+
return served;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1099
1353
|
/** Resolve the daemon socket path / named pipe (metadata discarded). */
|
|
1100
1354
|
export function resolveDaemonSocket() {
|
|
1101
1355
|
return resolveTargeting().socket;
|
|
@@ -1134,14 +1388,16 @@ export function targetingDiagnostic() {
|
|
|
1134
1388
|
// daemon is down".
|
|
1135
1389
|
const unresolved = t.source === "cwd-discovery" && !indexed;
|
|
1136
1390
|
const live = liveDaemonEntries();
|
|
1391
|
+
// A value workspaceEnv set aside is shown as it came, and why it was not used.
|
|
1392
|
+
const shown = (raw, used) => !raw ? "(not set)" : used ? raw : `${raw} (not expanded by the editor: ignored)`;
|
|
1137
1393
|
const lines = [
|
|
1138
1394
|
"",
|
|
1139
1395
|
"--- vexp targeting diagnostics ---",
|
|
1140
1396
|
"The MCP server could not reach a vexp daemon for this session.",
|
|
1141
1397
|
"",
|
|
1142
1398
|
"Workspace resolution:",
|
|
1143
|
-
` VEXP_WORKSPACE ${vw
|
|
1144
|
-
` CLAUDE_PROJECT_DIR ${cpd
|
|
1399
|
+
` VEXP_WORKSPACE ${shown(vw, workspaceEnv("VEXP_WORKSPACE"))}`,
|
|
1400
|
+
` CLAUDE_PROJECT_DIR ${shown(cpd, workspaceEnv("CLAUDE_PROJECT_DIR"))}`,
|
|
1145
1401
|
` resolved workspace ${t.workspaceRoot} (via ${t.source}` +
|
|
1146
1402
|
`${unresolved ? " — no indexed .vexp/ found walking up from cwd" : ""})`,
|
|
1147
1403
|
` socket tried ${sockTried}${sockExists ? "" : " (missing)"}`,
|
|
@@ -1280,22 +1536,40 @@ export function parentWorkspaceOf(repoRoot) {
|
|
|
1280
1536
|
const self = path.resolve(repoRoot);
|
|
1281
1537
|
if (path.resolve(parentRoot) === self)
|
|
1282
1538
|
return null;
|
|
1283
|
-
|
|
1284
|
-
if (!Array.isArray(config.repos))
|
|
1285
|
-
return null;
|
|
1286
|
-
const listed = config.repos.some((r) => {
|
|
1287
|
-
if (typeof r?.path !== "string")
|
|
1288
|
-
return false;
|
|
1289
|
-
if (path.isAbsolute(r.path))
|
|
1290
|
-
return path.resolve(r.path) === self;
|
|
1291
|
-
return path.resolve(parentRoot, r.path) === self || path.resolve(parentRoot, ".vexp", r.path) === self;
|
|
1292
|
-
});
|
|
1293
|
-
return listed ? parentRoot : null;
|
|
1539
|
+
return configListsRepo(configPath, parentRoot, self) ? parentRoot : null;
|
|
1294
1540
|
}
|
|
1295
1541
|
catch {
|
|
1296
1542
|
return null;
|
|
1297
1543
|
}
|
|
1298
1544
|
}
|
|
1545
|
+
/** Whether the workspace.json at `configPath`, of the multi-repo workspace
|
|
1546
|
+
* at `parentRoot`, lists the repository at `self` (resolved). Throws when
|
|
1547
|
+
* the config cannot be read. */
|
|
1548
|
+
function configListsRepo(configPath, parentRoot, self) {
|
|
1549
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
1550
|
+
if (!Array.isArray(config.repos))
|
|
1551
|
+
return false;
|
|
1552
|
+
return config.repos.some((r) => {
|
|
1553
|
+
if (typeof r?.path !== "string")
|
|
1554
|
+
return false;
|
|
1555
|
+
if (path.isAbsolute(r.path))
|
|
1556
|
+
return path.resolve(r.path) === self;
|
|
1557
|
+
return path.resolve(parentRoot, r.path) === self || path.resolve(parentRoot, ".vexp", r.path) === self;
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
/** Whether the multi-repo workspace at `parentRoot` connects the repository
|
|
1561
|
+
* at `repoRoot` (its own .vexp/workspace.json lists it). */
|
|
1562
|
+
function workspaceConnects(parentRoot, repoRoot) {
|
|
1563
|
+
try {
|
|
1564
|
+
const self = path.resolve(repoRoot);
|
|
1565
|
+
if (path.resolve(parentRoot) === self)
|
|
1566
|
+
return false;
|
|
1567
|
+
return configListsRepo(path.join(parentRoot, ".vexp", "workspace.json"), parentRoot, self);
|
|
1568
|
+
}
|
|
1569
|
+
catch {
|
|
1570
|
+
return false;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1299
1573
|
/** Whether the daemon behind an index_status reply serves `repoRoot`: it lists
|
|
1300
1574
|
* it, or it has not reached the plan's repo cap (a daemon answers before it
|
|
1301
1575
|
* has loaded the workspace's other repos). Lockstep with vexp-core main.rs
|
|
@@ -1325,8 +1599,10 @@ export function socketPathForWorkspace(ws) {
|
|
|
1325
1599
|
return candidate;
|
|
1326
1600
|
return `/tmp/vexp-${fnvHash(ws).slice(0, 12)}.sock`;
|
|
1327
1601
|
}
|
|
1328
|
-
/** Whether `cwd` sits in a git repository of its own below `root
|
|
1329
|
-
* directory
|
|
1602
|
+
/** Whether `cwd` sits in a git repository of its own below `root`: a `.git`
|
|
1603
|
+
* directory, or the `.git` file of a linked worktree (a submodule's file
|
|
1604
|
+
* does not count). A worktree takes its main checkout's consent, not its
|
|
1605
|
+
* index, which prunes every nested checkout. Lockstep with vexp-core
|
|
1330
1606
|
* utils.rs git_repo_below. */
|
|
1331
1607
|
export function gitRepoBelow(root, cwd) {
|
|
1332
1608
|
const real = (p) => {
|
|
@@ -1345,6 +1621,8 @@ export function gitRepoBelow(root, cwd) {
|
|
|
1345
1621
|
return true;
|
|
1346
1622
|
}
|
|
1347
1623
|
catch { /* none here */ }
|
|
1624
|
+
if (linkedWorktreeMain(current))
|
|
1625
|
+
return true;
|
|
1348
1626
|
current = path.dirname(current);
|
|
1349
1627
|
}
|
|
1350
1628
|
return false;
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createServer } from "http";
|
|
|
7
7
|
import { randomUUID } from "crypto";
|
|
8
8
|
import fs from "fs";
|
|
9
9
|
import path from "path";
|
|
10
|
-
import { DaemonClient, resolveSocketByWorkspaceHash, resolveWorkspaceByHash } from "./daemon-client.js";
|
|
10
|
+
import { DaemonClient, resolveSocketByWorkspaceHash, resolveWorkspaceByHash, workspaceEnv } from "./daemon-client.js";
|
|
11
11
|
import { GET_CONTEXT_CAPSULE_DEFINITION, handleGetContextCapsule, } from "./tools/get-context-capsule.js";
|
|
12
12
|
import { GET_IMPACT_GRAPH_DEFINITION, handleGetImpactGraph, } from "./tools/get-impact-graph.js";
|
|
13
13
|
import { SEARCH_LOGIC_FLOW_DEFINITION, handleSearchLogicFlow, } from "./tools/search-logic-flow.js";
|
|
@@ -34,44 +34,6 @@ const ALL_TOOL_DEFINITIONS = [
|
|
|
34
34
|
EXPAND_VEXP_REF_DEFINITION,
|
|
35
35
|
VERIFY_DONE_DEFINITION,
|
|
36
36
|
];
|
|
37
|
-
/**
|
|
38
|
-
* Minimal tool surface exposed to agents when VEXP_ALL_TOOLS is not set.
|
|
39
|
-
*
|
|
40
|
-
* Rationale: `run_pipeline` already subsumes capsule + impact + memory +
|
|
41
|
-
* flow + save_observation + session_context internally. Exposing every
|
|
42
|
-
* tool just bloats the agent's system prompt. With this set the agent sees
|
|
43
|
-
* only the four irreducible capabilities:
|
|
44
|
-
* 1. run_pipeline — primary context/impact/memory pipeline
|
|
45
|
-
* 2. get_skeleton — file drill-down with detail levels
|
|
46
|
-
* 3. index_status — daemon + repo health, discovery
|
|
47
|
-
* 4. expand_vexp_ref — required to expand V-REF placeholders in v2
|
|
48
|
-
*
|
|
49
|
-
* Legacy tools remain registered in the dispatch switch so that any
|
|
50
|
-
* existing caller that still sends them gets a normal response —
|
|
51
|
-
* nothing is unregistered at the daemon level.
|
|
52
|
-
*/
|
|
53
|
-
const ESSENTIAL_TOOL_DEFINITIONS = [
|
|
54
|
-
RUN_PIPELINE_DEFINITION,
|
|
55
|
-
GET_SKELETON_DEFINITION,
|
|
56
|
-
INDEX_STATUS_DEFINITION,
|
|
57
|
-
EXPAND_VEXP_REF_DEFINITION,
|
|
58
|
-
VERIFY_DONE_DEFINITION,
|
|
59
|
-
];
|
|
60
|
-
/**
|
|
61
|
-
* Default surface (2.3.3): the two tools an agent needs up front. Every
|
|
62
|
-
* schema in tools/list is resident in the agent's context on EVERY turn —
|
|
63
|
-
* measured against true vanilla, the 4-tool surface plus mandate cost more
|
|
64
|
-
* than run_pipeline ever saved on oriented tasks. So:
|
|
65
|
-
* - `index_status` is diagnostics (vexp doctor / CLI territory) — hidden
|
|
66
|
-
* by default, still dispatchable if called.
|
|
67
|
-
* - `expand_vexp_ref` is only meaningful AFTER a response contains
|
|
68
|
-
* [V-REF:...] placeholders — exposed dynamically at that moment via
|
|
69
|
-
* notifications/tools/list_changed. Agents that don't refresh their
|
|
70
|
-
* tool list fall back to the in-band alternative every V-REF response
|
|
71
|
-
* already suggests ("or Read the file"), and direct calls to the tool
|
|
72
|
-
* keep working whether or not it is listed.
|
|
73
|
-
* VEXP_ALL_TOOLS=1 restores the full surface.
|
|
74
|
-
*/
|
|
75
37
|
/**
|
|
76
38
|
* Trim a definition down to what `tools/list` has to carry.
|
|
77
39
|
*
|
|
@@ -95,6 +57,9 @@ const LISTING_OVERRIDES = {
|
|
|
95
57
|
properties: {
|
|
96
58
|
task: { type: "string", description: "The task, anchored on real identifiers or paths" },
|
|
97
59
|
preset: { type: "string", enum: ["auto", "explore", "modify", "debug", "refactor"] },
|
|
60
|
+
// `eager` stays out of the listing, as in vexp-core's: the hint in
|
|
61
|
+
// every compact answer names it ("pass `eager: true` to inline
|
|
62
|
+
// bodies"), and the full schema and dispatch take it.
|
|
98
63
|
},
|
|
99
64
|
required: ["task"],
|
|
100
65
|
},
|
|
@@ -119,11 +84,31 @@ const LISTING_OVERRIDES = {
|
|
|
119
84
|
"the impacted tests. Run those tests. No parameters.",
|
|
120
85
|
inputSchema: { type: "object", properties: {} },
|
|
121
86
|
},
|
|
87
|
+
expand_vexp_ref: {
|
|
88
|
+
// Word for word vexp-core's slim_for_listing (mcp_stdio.rs).
|
|
89
|
+
description: "Fetch the code behind a [V-REF:xxxx] marker left in compressed context - or just Read the file.",
|
|
90
|
+
inputSchema: {
|
|
91
|
+
type: "object",
|
|
92
|
+
properties: { hash: { type: "string" } },
|
|
93
|
+
required: ["hash"],
|
|
94
|
+
},
|
|
95
|
+
},
|
|
122
96
|
};
|
|
123
97
|
export function slimForListing(def) {
|
|
124
98
|
const o = LISTING_OVERRIDES[def.name];
|
|
125
99
|
return o ? { ...def, description: o.description, inputSchema: o.inputSchema } : def;
|
|
126
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Default listed surface (VEXP_ALL_TOOLS unset): four tools, the ones the
|
|
103
|
+
* native vexp-core server lists (CORE_LISTED_TOOLS in mcp_stdio.rs). Every
|
|
104
|
+
* schema in tools/list is resident in the agent's context on EVERY turn, and
|
|
105
|
+
* measured against true vanilla (2.3.3) a larger surface plus mandate cost
|
|
106
|
+
* more than run_pipeline saved on oriented tasks; run_pipeline already
|
|
107
|
+
* subsumes capsule, impact, flow and memory. The listing is static (see the
|
|
108
|
+
* ListTools handler for why it never changes mid-session), and listing is
|
|
109
|
+
* not authorization: every tool in ALL_TOOL_DEFINITIONS stays dispatchable,
|
|
110
|
+
* index_status included. VEXP_ALL_TOOLS=1 lists the full surface.
|
|
111
|
+
*/
|
|
127
112
|
const MINIMAL_TOOL_DEFINITIONS = [
|
|
128
113
|
RUN_PIPELINE_DEFINITION,
|
|
129
114
|
GET_SKELETON_DEFINITION,
|
|
@@ -133,6 +118,12 @@ const MINIMAL_TOOL_DEFINITIONS = [
|
|
|
133
118
|
// instruction. The Rust server has always listed it; this surface did not
|
|
134
119
|
// even implement it, and a user found that out for us.
|
|
135
120
|
VERIFY_DONE_DEFINITION,
|
|
121
|
+
// Listed because this server's answers carry [V-REF:...] markers: compact
|
|
122
|
+
// output (the default) leaves every pivot body behind one. Unlisted, the
|
|
123
|
+
// agents behind .vscode/mcp.json could only Read the whole file for each
|
|
124
|
+
// body (field report, 2026-11: "V-REF needs extra round trips"). Appended,
|
|
125
|
+
// not inserted, so the listing's prefix is what it was.
|
|
126
|
+
EXPAND_VEXP_REF_DEFINITION,
|
|
136
127
|
];
|
|
137
128
|
function allToolsEnabled() {
|
|
138
129
|
const v = process.env.VEXP_ALL_TOOLS;
|
|
@@ -212,8 +203,8 @@ export function createMcpServer(daemon) {
|
|
|
212
203
|
// 1,200 tokens over a typical tail. Publishing the change is ~24x worse
|
|
213
204
|
// than never hiding the tool.
|
|
214
205
|
//
|
|
215
|
-
// So the listing is
|
|
216
|
-
//
|
|
206
|
+
// So the listing is static, and it carries expand_vexp_ref from the first
|
|
207
|
+
// tools/list, as vexp-core's does.
|
|
217
208
|
server.setRequestHandler(ListToolsRequestSchema, () => ({
|
|
218
209
|
tools: allToolsEnabled()
|
|
219
210
|
? ALL_TOOL_DEFINITIONS
|
|
@@ -467,7 +458,8 @@ async function startHttp(fallbackDaemon, port) {
|
|
|
467
458
|
httpServer.removeListener("error", onError);
|
|
468
459
|
console.error(`[vexp-mcp] HTTP server listening on 127.0.0.1:${actualPort}`);
|
|
469
460
|
// Write actual port and token so the extension and agent configs can discover them
|
|
470
|
-
|
|
461
|
+
// Not an unexpanded `${workspaceFolder}`: it names no folder.
|
|
462
|
+
const workspace = workspaceEnv("VEXP_WORKSPACE");
|
|
471
463
|
if (workspace) {
|
|
472
464
|
try {
|
|
473
465
|
fs.writeFileSync(`${workspace}/.vexp/mcp.port`, String(actualPort), "utf-8");
|
|
@@ -38,6 +38,55 @@ export function gateActivityLines(hook) {
|
|
|
38
38
|
}
|
|
39
39
|
return { lines, unoriented: unanchored + withheld };
|
|
40
40
|
}
|
|
41
|
+
/** The reassurance every surface says word for word (vexp-core gate.rs DEVMIND_OPTIONAL). */
|
|
42
|
+
export const DEVMIND_OPTIONAL = "DevMind is optional: everything else in vexp works the same without it.";
|
|
43
|
+
/**
|
|
44
|
+
* What an agent is told when LLM compression is on in the config and the
|
|
45
|
+
* daemon runs the rule compressor. It was always "Restart the daemon or
|
|
46
|
+
* re-run `vexp setup-llm`", whatever the daemon's reason: on a machine where
|
|
47
|
+
* DevMind stays off by policy (no GPU it can use) an agent that relayed it
|
|
48
|
+
* repeated the hour of retries a user had just spent (field report,
|
|
49
|
+
* 2026-11-08), and a bare `vexp setup-llm` is a wizard an agent's shell
|
|
50
|
+
* cannot answer. Now: off by policy is said as such, with nothing to do; any
|
|
51
|
+
* other reason is given in place of the generic advice, which stays only
|
|
52
|
+
* for a daemon that gives none.
|
|
53
|
+
*
|
|
54
|
+
* Off by policy: `llm_off_cause` is a kind. A daemon from before that field
|
|
55
|
+
* (3.3.9, the field absent, not null) said "DevMind needs a GPU and none is
|
|
56
|
+
* usable on this machine" for every such cause, and only then. Lockstep
|
|
57
|
+
* with packages/vexp-cli/src/devmind.ts (devmindOff) and
|
|
58
|
+
* packages/vexp-vscode/src/ui/llm-advice.ts.
|
|
59
|
+
*/
|
|
60
|
+
/** The agent's instruction for a cause nothing on this machine changes. */
|
|
61
|
+
export const DEVMIND_OFF_AGENT_NOTHING = "Results are complete with vexp's rule compressor; there is nothing to fix. Do not restart the daemon or re-run setup-llm.";
|
|
62
|
+
/**
|
|
63
|
+
* The agent's instruction for a cause the user can change (index_status
|
|
64
|
+
* `llm_off_fixable`, gate.rs kind_is_fixable). Lockstep with the doctors'
|
|
65
|
+
* "After the fix, restart the daemon." (vexp-cli devmind.ts, vexp-vscode
|
|
66
|
+
* doctor-lines.ts): the restart is the user's, after the user's fix.
|
|
67
|
+
*/
|
|
68
|
+
export const DEVMIND_OFF_AGENT_FIXABLE = "Results are complete with vexp's rule compressor. The fix above is the user's to make; do not restart the daemon or re-run setup-llm yourself.";
|
|
69
|
+
export function llmInactiveNote(status) {
|
|
70
|
+
if (status.llm_configured_but_inactive !== true || status.compressor === "llm")
|
|
71
|
+
return undefined;
|
|
72
|
+
const reason = typeof status.llm_inactive_reason === "string" ? status.llm_inactive_reason.trim().replace(/\.+$/, "") : "";
|
|
73
|
+
const off = "llm_off_cause" in status
|
|
74
|
+
? typeof status.llm_off_cause === "string" && status.llm_off_cause !== ""
|
|
75
|
+
: /needs a GPU/i.test(reason);
|
|
76
|
+
if (off) {
|
|
77
|
+
// A cause the user can change ends its reason with "..., then restart
|
|
78
|
+
// the daemon": "there is nothing to fix. Do not restart the daemon"
|
|
79
|
+
// after it gave an agent two opposite instructions (review,
|
|
80
|
+
// 2026-11-08). Either way the change is not the agent's to make.
|
|
81
|
+
return (`DevMind (optional local LLM) is off on this machine: ${reason || "DevMind needs a GPU"}. ${DEVMIND_OPTIONAL} ` +
|
|
82
|
+
(status.llm_off_fixable === true ? DEVMIND_OFF_AGENT_FIXABLE : DEVMIND_OFF_AGENT_NOTHING));
|
|
83
|
+
}
|
|
84
|
+
if (reason) {
|
|
85
|
+
return `**LLM compression is enabled in config, but this daemon is running the rule compressor, so results are not LLM-compressed.** Reason: ${reason}.`;
|
|
86
|
+
}
|
|
87
|
+
return ("⚠️ A local LLM model is installed and enabled in config, but this daemon is running the rule compressor. " +
|
|
88
|
+
"Restart the daemon (`vexp daemon-cmd restart`) or re-run `vexp setup-llm` — until then, results are NOT LLM-compressed.");
|
|
89
|
+
}
|
|
41
90
|
export async function handleIndexStatus(params, daemon) {
|
|
42
91
|
IndexStatusSchema.parse(params);
|
|
43
92
|
// Client-side: how THIS MCP process resolved its target (before talking to any
|
|
@@ -132,9 +181,9 @@ function formatStatusAsText(status, targeting) {
|
|
|
132
181
|
lines.push(`| Last query time | ${status.last_query_time_ms}ms |`);
|
|
133
182
|
}
|
|
134
183
|
lines.push("");
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
184
|
+
const llmNote = llmInactiveNote(status);
|
|
185
|
+
if (llmNote) {
|
|
186
|
+
lines.push(llmNote);
|
|
138
187
|
lines.push("");
|
|
139
188
|
}
|
|
140
189
|
// Coverage gaps (3.1). Files over max_file_size_kb were skipped with an
|
|
@@ -41,6 +41,14 @@ export const RunPipelineSchema = z.object({
|
|
|
41
41
|
.boolean()
|
|
42
42
|
.optional())
|
|
43
43
|
.describe("Include full file content for pivot files (default: auto — read/debug inline bodies; modify/refactor return skeletons + V-REF)"),
|
|
44
|
+
// Declared here or it never reaches the daemon: z.object drops every key it
|
|
45
|
+
// does not declare, so `eager: true` sent through this server was removed
|
|
46
|
+
// before the call while the schema offered it and the answer's hint asked
|
|
47
|
+
// for it. No default, for the reason given above.
|
|
48
|
+
eager: z.preprocess(coerceBool, z
|
|
49
|
+
.boolean()
|
|
50
|
+
.optional())
|
|
51
|
+
.describe("Inline pivot bodies, covering tests and a raised budget in this one response"),
|
|
44
52
|
repos: z.preprocess(coerceArray, z
|
|
45
53
|
.array(z.string())
|
|
46
54
|
.optional())
|
|
@@ -129,6 +137,15 @@ export async function handleRunPipeline(params, daemon) {
|
|
|
129
137
|
const result = (await daemon.call("run_pipeline", validated));
|
|
130
138
|
const scoped = validated.repos?.length ? `, repos: ${validated.repos.join(", ")}` : "";
|
|
131
139
|
const banner = `> vexp target: ${targeting.workspaceRoot} (via ${targeting.source}${scoped})`;
|
|
140
|
+
// Another root's daemon answered for a target its index cannot hold (a
|
|
141
|
+
// nested checkout with no daemon of its own yet): the answer reads as the
|
|
142
|
+
// target's unless the header says otherwise. index_status says it too, but
|
|
143
|
+
// an agent asks run_pipeline. Read after the call: it names the daemon
|
|
144
|
+
// that answered.
|
|
145
|
+
const foreign = daemon.foreignIndex?.() ?? null;
|
|
146
|
+
const mismatch = foreign
|
|
147
|
+
? `\n> MISMATCH: this answer comes from the index of ${foreign.served}, not ${foreign.target} - ${foreign.target} is not indexed yet`
|
|
148
|
+
: "";
|
|
132
149
|
// Safety net for daemons whose output predates the in-band coverage header:
|
|
133
150
|
// never let a degraded status reach the agent invisibly. Newer daemons embed
|
|
134
151
|
// an INDEX DEGRADED/EMPTY marker in `output` themselves — don't duplicate it.
|
|
@@ -136,5 +153,5 @@ export async function handleRunPipeline(params, daemon) {
|
|
|
136
153
|
? "\n> vexp status: degraded — index coverage too small to answer reliably; use Grep/Glob/Read directly and run `vexp index`."
|
|
137
154
|
: "";
|
|
138
155
|
// The Rust engine already produces formatted text output; we only prepend the banner.
|
|
139
|
-
return `${banner}${degradedNote}\n${result.output}`;
|
|
156
|
+
return `${banner}${mismatch}${degradedNote}\n${result.output}`;
|
|
140
157
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vexp-mcp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"description": "vexp MCP server — AI context tools for coding agents",
|
|
6
6
|
"type": "module",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"scripts": {
|
|
9
9
|
"build": "tsc",
|
|
10
10
|
"dev": "tsx src/index.ts",
|
|
11
|
-
"test": "node --import tsx --test test/*.test.ts",
|
|
11
|
+
"test": "node --import tsx --import ./test/_sandbox-home.mjs --test test/*.test.ts",
|
|
12
12
|
"clean": "rm -rf dist",
|
|
13
13
|
"clean:artifacts": "node -e \"const fs=require('fs'),p=require('path');function w(d){if(!fs.existsSync(d))return;for(const e of fs.readdirSync(d,{withFileTypes:true})){const f=p.join(d,e.name);if(e.isDirectory())w(f);else if(/\\.(map|d\\.ts|d\\.ts\\.map)$/.test(e.name))fs.unlinkSync(f);}}w('dist');\"",
|
|
14
14
|
"prepublishOnly": "npm run build && npm run clean:artifacts"
|