vexp-mcp 3.3.8 → 3.3.9

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.
@@ -19,6 +19,9 @@ import { parseEngineVersion, replaceOlderDaemon } from "./daemon-upgrade.js";
19
19
  * - `until` has passed — the quota reset.
20
20
  * - a license file is newer than the marker — the user upgraded mid-day, and
21
21
  * must not stay locked out until midnight over a stale free-tier marker.
22
+ *
23
+ * Lockstep with vexp-core daily_usage::daily_limit_until, which the server
24
+ * Codex runs reads before it starts a daemon.
22
25
  */
23
26
  export function readDailyLimitMarker(workspaceRoot) {
24
27
  const markerPath = path.join(workspaceRoot, ".vexp", "daily-limit.json");
@@ -102,10 +105,17 @@ export class DaemonClient {
102
105
  * can resurrect the daemon repeatedly when VS Code is closed and the daemon
103
106
  * exits — not only on the first connection of its lifetime. */
104
107
  lastSpawnAttemptMs = 0;
108
+ // The 4 s cap on a start (maybeSpawnDaemon), these retries and the
109
+ // cooldown are what the server Codex runs does at a tool call that finds
110
+ // no daemon, in lockstep: vexp-core mcp_stdio START_WAIT_AT_A_CALL,
111
+ // CALL_RETRIES, CALL_RETRY_DELAY and START_COOLDOWN.
105
112
  static MAX_RETRIES = 3;
106
113
  static RETRY_DELAY_MS = 1500;
107
114
  static SPAWN_COOLDOWN_MS = 10_000;
108
115
  static RETRYABLE_CODES = ["ENOENT", "ECONNREFUSED", "ECONNRESET", "EPIPE"];
116
+ /** The daemon of the multi-repo workspace this connected repo belongs to,
117
+ * once it has said it serves the repo. Dropped at the first failure. */
118
+ workspaceDaemonSocket;
109
119
  /** Workspace root used to (re)spawn the daemon and, when no socket is
110
120
  * resolvable, to compute the expected socket/pipe path. Set by the HTTP
111
121
  * transport so a per-workspace request can resurrect *its* daemon even when
@@ -127,7 +137,8 @@ export class DaemonClient {
127
137
  * fails re-spawns it (after SPAWN_COOLDOWN_MS). Silent: success = next retry
128
138
  * connects; failure = the ordinary retry/error path surfaces a clear error
129
139
  * with the registry candidates and the daemon log tail. Disable via
130
- * VEXP_NO_AUTOSTART=1.
140
+ * VEXP_NO_AUTOSTART=1. The rules for when it may start one are in lockstep
141
+ * with vexp-core mcp_stdio::why_no_daemon_start, the server Codex runs.
131
142
  */
132
143
  async maybeSpawnDaemon() {
133
144
  const now = Date.now();
@@ -155,6 +166,11 @@ export class DaemonClient {
155
166
  // spawn and the "daemon did not start" it would answer with.
156
167
  if (isVexpStateHome(workspaceRoot))
157
168
  return;
169
+ // Found by walking up from a git repository of its own, nobody set this
170
+ // session's folder up: a stale .vexp above it gets no daemon, which would
171
+ // index all of that folder. Lockstep with vexp-core cmd_mcp.
172
+ if (!this.spawnWorkspaceRoot && resolveWorkspaceWithSource().source === "cwd-discovery" && gitRepoBelow(workspaceRoot, process.cwd()))
173
+ return;
158
174
  const binary = resolveVexpCoreBinary();
159
175
  if (!binary)
160
176
  return;
@@ -164,6 +180,9 @@ export class DaemonClient {
164
180
  // unrelated cwd / a stripped env (e.g. the detached HTTP supervisor).
165
181
  const env = binaryEnvFor(binary);
166
182
  env.VEXP_WORKSPACE = workspaceRoot;
183
+ // Started for an agent's session: unused, it stops by itself and frees
184
+ // its slot of the plan's daemon cap (vexp-core idle.rs, every agent alike).
185
+ env.VEXP_DAEMON_OWNER = "agent";
167
186
  // `detached` stays (DETACHED_PROCESS on Windows): a non-detached child
168
187
  // would sit in libuv's kill-on-close job object and go down with this
169
188
  // server. The daemon this starts has no console either; its git
@@ -247,6 +266,10 @@ export class DaemonClient {
247
266
  // ignored next to it.
248
267
  const env = binaryEnvFor(binary);
249
268
  env.VEXP_WORKSPACE = workspaceRoot;
269
+ // The owner it had: an upgrade does not put a daemon started by hand on
270
+ // the agent's idle stop. (On Windows a held lock cannot be read: no owner.)
271
+ if (startedForAgent(workspaceRoot))
272
+ env.VEXP_DAEMON_OWNER = "agent";
250
273
  const child = spawn(binary, ["daemon-cmd", "restart"], {
251
274
  cwd: workspaceRoot,
252
275
  stdio: "ignore",
@@ -290,6 +313,8 @@ export class DaemonClient {
290
313
  get socketPath() {
291
314
  if (this.explicitSocketPath)
292
315
  return this.explicitSocketPath;
316
+ if (this.workspaceDaemonSocket)
317
+ return this.workspaceDaemonSocket;
293
318
  // HTTP per-workspace client: target this workspace's deterministic socket
294
319
  // so a freshly respawned daemon is reconnected even if the registry was
295
320
  // stale/missing when the request arrived.
@@ -334,6 +359,17 @@ export class DaemonClient {
334
359
  }
335
360
  catch (err) {
336
361
  lastError = err instanceof Error ? err : new Error(String(err));
362
+ // A connected repo has no daemon of its own while its workspace's is
363
+ // up (the engine's parent-workspace guard): the start below did
364
+ // nothing, and three retries failed on a socket nobody would bind.
365
+ if (attempt === 0 && DaemonClient.isRetryableError(lastError) && !this.explicitSocketPath) {
366
+ this.workspaceDaemonSocket = undefined;
367
+ const found = await this.findWorkspaceDaemon();
368
+ if (found === "serves")
369
+ continue;
370
+ if (found)
371
+ throw new Error(found);
372
+ }
337
373
  // An unreachable daemon may be down BY DESIGN (free-tier quota spent).
338
374
  // Answer that in words and stop here: retrying would respawn a daemon
339
375
  // that re-exits on its next quota check, and the agent would only ever
@@ -360,6 +396,33 @@ export class DaemonClient {
360
396
  }
361
397
  throw this.augmentDaemonError(lastError);
362
398
  }
399
+ /** For a connected repo whose workspace daemon answers: "serves", with the
400
+ * socket kept for this client, or the words for a repo the plan left out of
401
+ * it. Null when this is no connected repo or that daemon is not up, and the
402
+ * ordinary start applies. Lockstep with vexp-core main.rs workspace_daemon. */
403
+ async findWorkspaceDaemon() {
404
+ const repoRoot = resolveWorkspaceRoot(this.spawnWorkspaceRoot);
405
+ const parentRoot = parentWorkspaceOf(repoRoot);
406
+ if (!parentRoot)
407
+ return null;
408
+ const socket = socketPathForWorkspace(parentRoot);
409
+ let status;
410
+ try {
411
+ const asked = new DaemonClient(socket, this.sessionId).callOnce("index_status", {});
412
+ const cap = new Promise((r) => setTimeout(() => r("no answer"), 3_000).unref());
413
+ status = await Promise.race([asked, cap]);
414
+ }
415
+ catch {
416
+ return null;
417
+ }
418
+ if (status !== "no answer" && !statusServesRepo(status, repoRoot)) {
419
+ return (`${repoRoot} is a connected repo of the workspace at ${parentRoot}, whose daemon does not ` +
420
+ `serve it: the plan's repo limit left it out (see \`vexp doctor\`). AGENT INSTRUCTION: this ` +
421
+ `repository has no vexp index available here; continue with your own tools and tell the user.`);
422
+ }
423
+ this.workspaceDaemonSocket = socket;
424
+ return "serves";
425
+ }
363
426
  /** What we say when the daemon took the request and then went away.
364
427
  *
365
428
  * The lockstep twin of `daemon_gone_message` in
@@ -720,9 +783,10 @@ export function isVexpStateHome(dir) {
720
783
  * commit vexp.toml instead, and a fresh clone still starts vexp at an
721
784
  * agent's first call (field report, 2026-10-23).
722
785
  *
723
- * Never a bare .vexp/: vexp-core creates one wherever it computes a socket
724
- * path. Never .vexp/.gitignore: the daemon writes it at every start, and
725
- * personal mode commits one to keep vexp to the person who set it up.
786
+ * Never a bare .vexp/: vexp-core created one wherever it computed a socket
787
+ * path, and those are still about. Never .vexp/.gitignore: the daemon
788
+ * writes it at every start, and personal mode commits one to keep vexp to
789
+ * the person who set it up.
726
790
  *
727
791
  * LOCAL_INDEX counts too: index.db is never committed, so it says vexp was
728
792
  * run in this folder on this machine, and Codex's own server (vexp-core
@@ -1202,11 +1266,99 @@ export function canonicalWorkspaceRoot(root) {
1202
1266
  }
1203
1267
  /** Deterministic socket/pipe path for a workspace root — mirrors the Rust
1204
1268
  * daemon's get_socket_path (vexp-core/src/utils.rs). */
1205
- function socketPathForWorkspace(ws) {
1269
+ /** The root of the multi-repo workspace `repoRoot` is a connected repo of, or
1270
+ * null: only while the parent config still exists and still lists it, so a
1271
+ * stale backlink never redirects. Lockstep with vexp-core main.rs
1272
+ * parent_workspace_redirect and the extension's resolveParentRedirect. */
1273
+ export function parentWorkspaceOf(repoRoot) {
1274
+ try {
1275
+ const backlink = JSON.parse(fs.readFileSync(path.join(repoRoot, ".vexp", "parent_workspace.json"), "utf-8"));
1276
+ if (typeof backlink?.workspace_config !== "string")
1277
+ return null;
1278
+ const configPath = backlink.workspace_config;
1279
+ const parentRoot = path.dirname(path.dirname(configPath));
1280
+ const self = path.resolve(repoRoot);
1281
+ if (path.resolve(parentRoot) === self)
1282
+ return null;
1283
+ const config = JSON.parse(fs.readFileSync(configPath, "utf-8"));
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;
1294
+ }
1295
+ catch {
1296
+ return null;
1297
+ }
1298
+ }
1299
+ /** Whether the daemon behind an index_status reply serves `repoRoot`: it lists
1300
+ * it, or it has not reached the plan's repo cap (a daemon answers before it
1301
+ * has loaded the workspace's other repos). Lockstep with vexp-core main.rs
1302
+ * status_serves_repo. */
1303
+ export function statusServesRepo(status, repoRoot) {
1304
+ const st = (status ?? {});
1305
+ const real = (p) => {
1306
+ try {
1307
+ return fs.realpathSync(p);
1308
+ }
1309
+ catch {
1310
+ return path.resolve(p);
1311
+ }
1312
+ };
1313
+ const self = real(repoRoot);
1314
+ const listed = Array.isArray(st.repos) && st.repos.some((r) => typeof r?.path === "string" && r.path !== "" && real(r.path) === self);
1315
+ return listed || st.repos_limit_reached !== true;
1316
+ }
1317
+ export function socketPathForWorkspace(ws) {
1206
1318
  if (process.platform === "win32") {
1207
1319
  return `\\\\.\\pipe\\vexp-${fnvHash(canonicalWorkspaceRoot(ws).toLowerCase()).slice(0, 8)}`;
1208
1320
  }
1209
- return path.join(ws, ".vexp", "daemon.sock");
1321
+ const candidate = path.join(ws, ".vexp", "daemon.sock");
1322
+ // The socket address limit: the engine moves it to /tmp past 100 bytes
1323
+ // (vexp-core utils.rs get_socket_path).
1324
+ if (Buffer.byteLength(candidate) <= 100)
1325
+ return candidate;
1326
+ return `/tmp/vexp-${fnvHash(ws).slice(0, 12)}.sock`;
1327
+ }
1328
+ /** Whether `cwd` sits in a git repository of its own below `root` (a `.git`
1329
+ * directory; a `.git` file is a linked worktree). Lockstep with vexp-core
1330
+ * utils.rs git_repo_below. */
1331
+ export function gitRepoBelow(root, cwd) {
1332
+ const real = (p) => {
1333
+ try {
1334
+ return fs.realpathSync(p);
1335
+ }
1336
+ catch {
1337
+ return path.resolve(p);
1338
+ }
1339
+ };
1340
+ const top = real(root);
1341
+ let current = real(cwd);
1342
+ while (current !== top && current.startsWith(top + path.sep)) {
1343
+ try {
1344
+ if (fs.statSync(path.join(current, ".git")).isDirectory())
1345
+ return true;
1346
+ }
1347
+ catch { /* none here */ }
1348
+ current = path.dirname(current);
1349
+ }
1350
+ return false;
1351
+ }
1352
+ /** Whether the daemon that last held this workspace's lock was started for an
1353
+ * agent's session (vexp-core index_lock.rs AGENT_DAEMON_ROLE). */
1354
+ export function startedForAgent(workspaceRoot) {
1355
+ try {
1356
+ const lock = JSON.parse(fs.readFileSync(path.join(workspaceRoot, ".vexp", "daemon.lock"), "utf-8"));
1357
+ return lock?.role === "agent daemon";
1358
+ }
1359
+ catch {
1360
+ return false;
1361
+ }
1210
1362
  }
1211
1363
  /** Human-friendly hint printed when a connection attempt fails — enumerates
1212
1364
  * what we tried to make the failure actionable instead of misleading. */
@@ -232,8 +232,13 @@ export function parseEngineVersion(stdout) {
232
232
  return last ? last : undefined;
233
233
  }
234
234
  /**
235
- * The folder `daemon-cmd` works on when run in `dir`: the nearest one with a
236
- * `.git` at or above it, else `dir` itself (find_repo_root in vexp-core).
235
+ * The folder `daemon-cmd` works on when run in `dir` (daemon_cmd_root in
236
+ * vexp-core): the nearest one with a `.git` at or above it, unless that one
237
+ * was never set up for vexp and a folder between it and `dir` was, which
238
+ * is then the nearest such folder; with no `.git` above, `dir` itself. Set
239
+ * up is the engine's is_workspace_marker: one of its consent files in the
240
+ * folder's .vexp/, and neither the home directory nor a filesystem root
241
+ * (forbidden_workspace_reason refuses both).
237
242
  */
238
243
  export function daemonCmdRoot(dir) {
239
244
  let start = path.resolve(dir);
@@ -243,10 +248,16 @@ export function daemonCmdRoot(dir) {
243
248
  catch {
244
249
  /* not there: the spelling given */
245
250
  }
251
+ const setUp = (d) => (process.env.VEXP_ALLOW_HOME_WORKSPACE === "1" ||
252
+ (upgradeAttemptKey(d) !== upgradeAttemptKey(vexpHome()) && path.dirname(d) !== d)) &&
253
+ ["manifest.json", "vexp.toml", "workspace.json", "index.db"].some((f) => fs.existsSync(path.join(d, ".vexp", f)));
254
+ const below = [];
246
255
  let current = start;
247
256
  for (;;) {
248
- if (fs.existsSync(path.join(current, ".git")))
249
- return current;
257
+ if (fs.existsSync(path.join(current, ".git"))) {
258
+ return setUp(current) ? current : (below.find(setUp) ?? current);
259
+ }
260
+ below.push(current);
250
261
  const parent = path.dirname(current);
251
262
  if (parent === current)
252
263
  return start;
@@ -260,8 +271,10 @@ export function daemonCmdRoot(dir) {
260
271
  *
261
272
  * - the stop half reads `<dir>/.vexp/daemon.pid`; with none there it stops
262
273
  * nothing, and the start half then races the daemon that is still up;
263
- * - `daemon-cmd` works on the git root at or above its cwd, so for a
264
- * workspace below one it would start a daemon on the folder above;
274
+ * - `daemon-cmd` works on the git root at or above its cwd unless a folder
275
+ * below an unset-up root was set up on its own (daemonCmdRoot), so for
276
+ * any other workspace below one it would start a daemon on the folder
277
+ * above;
265
278
  * - the engine refuses to start on the home directory, so a daemon an older
266
279
  * build left there would be stopped and not come back.
267
280
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vexp-mcp",
3
- "version": "3.3.8",
3
+ "version": "3.3.9",
4
4
  "license": "UNLICENSED",
5
5
  "description": "vexp MCP server — AI context tools for coding agents",
6
6
  "type": "module",