@adhdev/daemon-standalone 0.9.82-rc.377 → 0.9.82-rc.379

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/index.js CHANGED
@@ -30036,10 +30036,10 @@ var require_dist3 = __commonJS({
30036
30036
  }
30037
30037
  function getDaemonBuildInfo() {
30038
30038
  if (cached2) return cached2;
30039
- const commit = readInjected(true ? "7393d1a7f559903bac031c3787d50b910d986783" : void 0) ?? "unknown";
30040
- const commitShort = readInjected(true ? "7393d1a7" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30041
- const version2 = readInjected(true ? "0.9.82-rc.377" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30042
- const builtAt = readInjected(true ? "2026-06-25T06:26:36.111Z" : void 0);
30039
+ const commit = readInjected(true ? "7b74c2c74e315b3fa6eb9f18d694b79eeb561184" : void 0) ?? "unknown";
30040
+ const commitShort = readInjected(true ? "7b74c2c7" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30041
+ const version2 = readInjected(true ? "0.9.82-rc.379" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30042
+ const builtAt = readInjected(true ? "2026-06-25T09:34:11.123Z" : void 0);
30043
30043
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30044
30044
  return cached2;
30045
30045
  }
@@ -37042,8 +37042,8 @@ ${rendered}`, "utf-8");
37042
37042
  const remaining = (existing.slice(0, openIdx) + existing.slice(closeIdx + CLOSE.length)).replace(/^\s*\n+/, "").replace(/\n+\s*$/, "");
37043
37043
  if (!remaining.trim()) {
37044
37044
  try {
37045
- const fs35 = require("fs");
37046
- fs35.unlinkSync(filePath);
37045
+ const fs38 = require("fs");
37046
+ fs38.unlinkSync(filePath);
37047
37047
  } catch {
37048
37048
  }
37049
37049
  } else {
@@ -39586,9 +39586,9 @@ Next step: ${nextStep}`;
39586
39586
  for (const ext of exes) {
39587
39587
  const fullPath = path11.join(p, trimmed + ext);
39588
39588
  try {
39589
- const fs35 = require("fs");
39590
- if (fs35.existsSync(fullPath)) {
39591
- const stat2 = fs35.statSync(fullPath);
39589
+ const fs38 = require("fs");
39590
+ if (fs38.existsSync(fullPath)) {
39591
+ const stat2 = fs38.statSync(fullPath);
39592
39592
  if (stat2.isFile() && (isWin || stat2.mode & 73)) {
39593
39593
  return fullPath;
39594
39594
  }
@@ -39602,12 +39602,12 @@ Next step: ${nextStep}`;
39602
39602
  function isScriptBinary(binaryPath) {
39603
39603
  if (!path11.isAbsolute(binaryPath)) return false;
39604
39604
  try {
39605
- const fs35 = require("fs");
39606
- const resolved = fs35.realpathSync(binaryPath);
39605
+ const fs38 = require("fs");
39606
+ const resolved = fs38.realpathSync(binaryPath);
39607
39607
  const head = Buffer.alloc(8);
39608
- const fd = fs35.openSync(resolved, "r");
39609
- fs35.readSync(fd, head, 0, 8, 0);
39610
- fs35.closeSync(fd);
39608
+ const fd = fs38.openSync(resolved, "r");
39609
+ fs38.readSync(fd, head, 0, 8, 0);
39610
+ fs38.closeSync(fd);
39611
39611
  let i = 0;
39612
39612
  if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
39613
39613
  return head[i] === 35 && head[i + 1] === 33;
@@ -39618,12 +39618,12 @@ Next step: ${nextStep}`;
39618
39618
  function looksLikeMachOOrElf(filePath) {
39619
39619
  if (!path11.isAbsolute(filePath)) return false;
39620
39620
  try {
39621
- const fs35 = require("fs");
39622
- const resolved = fs35.realpathSync(filePath);
39621
+ const fs38 = require("fs");
39622
+ const resolved = fs38.realpathSync(filePath);
39623
39623
  const buf = Buffer.alloc(8);
39624
- const fd = fs35.openSync(resolved, "r");
39625
- fs35.readSync(fd, buf, 0, 8, 0);
39626
- fs35.closeSync(fd);
39624
+ const fd = fs38.openSync(resolved, "r");
39625
+ fs38.readSync(fd, buf, 0, 8, 0);
39626
+ fs38.closeSync(fd);
39627
39627
  let i = 0;
39628
39628
  if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
39629
39629
  const b = buf.subarray(i);
@@ -40155,6 +40155,16 @@ Next step: ${nextStep}`;
40155
40155
  dispatchWarmupGetterMissingWarned.add(daemonId);
40156
40156
  LOG2.warn("MeshQueue", `Mesh peer connection getter unavailable for ${String(daemonId).slice(0, 12)}; remote task-dispatch warmup deadline degraded to the combined connect+response window. Avoids a cold-open false-timeout but loses warm/cold precision \u2014 wire getMeshPeerConnectionStatus on this daemon.`);
40157
40157
  }
40158
+ async function waitForLocalSessionReady(components, sessionId) {
40159
+ const adapter = components.cliManager?.adapters?.get(sessionId);
40160
+ if (!adapter || typeof adapter.isReady !== "function") return;
40161
+ const deadline = Date.now() + LOCAL_LAUNCH_READY_TIMEOUT_MS;
40162
+ while (Date.now() < deadline) {
40163
+ if (adapter.isReady() || adapter.currentStatus === "idle") return;
40164
+ await new Promise((resolve24) => setTimeout(resolve24, LOCAL_LAUNCH_READY_POLL_MS));
40165
+ }
40166
+ LOG2.warn("MeshQueue", `Auto-launched session ${sessionId} not interactive after ${LOCAL_LAUNCH_READY_TIMEOUT_MS}ms; dispatching anyway (adapter queue-until-ready will buffer)`);
40167
+ }
40158
40168
  function deliverTaskToSession(dispatchThunk, ctx, warmup) {
40159
40169
  const delivery = createSessionDelivery({
40160
40170
  meshId: ctx.meshId,
@@ -40751,6 +40761,7 @@ Next step: ${nextStep}`;
40751
40761
  return false;
40752
40762
  }
40753
40763
  markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId });
40764
+ await waitForLocalSessionReady(components, sessionId);
40754
40765
  tryAssignQueueTask(components, meshId, nodeId, sessionId, resolved.providerType);
40755
40766
  return true;
40756
40767
  } catch (e) {
@@ -40978,6 +40989,8 @@ Next step: ${nextStep}`;
40978
40989
  var DISPATCH_CONFIRM_TIMEOUT_MS;
40979
40990
  var DISPATCH_CONNECT_TIMEOUT_MS;
40980
40991
  var dispatchWarmupGetterMissingWarned;
40992
+ var LOCAL_LAUNCH_READY_TIMEOUT_MS;
40993
+ var LOCAL_LAUNCH_READY_POLL_MS;
40981
40994
  var autoLaunchInProgress;
40982
40995
  var autoLaunchCooldownUntil;
40983
40996
  var AUTO_LAUNCH_COOLDOWN_MS;
@@ -41009,6 +41022,8 @@ Next step: ${nextStep}`;
41009
41022
  DISPATCH_CONFIRM_TIMEOUT_MS = 12e4;
41010
41023
  DISPATCH_CONNECT_TIMEOUT_MS = MESH_CONNECT_TIMEOUT_MS2;
41011
41024
  dispatchWarmupGetterMissingWarned = /* @__PURE__ */ new Set();
41025
+ LOCAL_LAUNCH_READY_TIMEOUT_MS = 15e3;
41026
+ LOCAL_LAUNCH_READY_POLL_MS = 100;
41012
41027
  autoLaunchInProgress = /* @__PURE__ */ new Set();
41013
41028
  autoLaunchCooldownUntil = /* @__PURE__ */ new Map();
41014
41029
  AUTO_LAUNCH_COOLDOWN_MS = 5e3;
@@ -46778,8 +46793,8 @@ ${cleanBody}`;
46778
46793
  let cwd = options.cwd;
46779
46794
  if (cwd) {
46780
46795
  try {
46781
- const fs35 = require("fs");
46782
- const stat2 = fs35.statSync(cwd);
46796
+ const fs38 = require("fs");
46797
+ const stat2 = fs38.statSync(cwd);
46783
46798
  if (!stat2.isDirectory()) cwd = os14.homedir();
46784
46799
  } catch {
46785
46800
  cwd = os14.homedir();
@@ -46797,6 +46812,33 @@ ${cleanBody}`;
46797
46812
  };
46798
46813
  }
46799
46814
  });
46815
+ function chunkPreservingSurrogates(text, size) {
46816
+ const chunks = [];
46817
+ let offset = 0;
46818
+ while (offset < text.length) {
46819
+ let end = Math.min(text.length, offset + size);
46820
+ if (end < text.length) {
46821
+ const code = text.charCodeAt(end - 1);
46822
+ if (code >= 55296 && code <= 56319) end -= 1;
46823
+ }
46824
+ if (end <= offset) end = Math.min(text.length, offset + size);
46825
+ chunks.push(text.slice(offset, end));
46826
+ offset = end;
46827
+ }
46828
+ return chunks;
46829
+ }
46830
+ function shouldChunkWin32Write(length) {
46831
+ return length > WIN32_PTY_WRITE_CHUNK_CHARS;
46832
+ }
46833
+ var WIN32_PTY_WRITE_CHUNK_CHARS;
46834
+ var WIN32_PTY_WRITE_CHUNK_GAP_MS;
46835
+ var init_pty_write_chunking = __esm2({
46836
+ "src/cli-adapters/pty-write-chunking.ts"() {
46837
+ "use strict";
46838
+ WIN32_PTY_WRITE_CHUNK_CHARS = 1024;
46839
+ WIN32_PTY_WRITE_CHUNK_GAP_MS = 8;
46840
+ }
46841
+ });
46800
46842
  function compile(re, flags) {
46801
46843
  try {
46802
46844
  return new RegExp(re, flags ?? "");
@@ -48745,6 +48787,7 @@ ${cont}` : cont;
48745
48787
  init_terminal_screen();
48746
48788
  import_session_host_core5 = require_dist();
48747
48789
  init_pty_transport();
48790
+ init_pty_write_chunking();
48748
48791
  init_provider_cli_shared();
48749
48792
  init_cli_script_runner();
48750
48793
  init_cli_state_engine();
@@ -49223,6 +49266,7 @@ ${lastSnapshot}`;
49223
49266
  `[${this.cliType}] Startup settled (${trigger}, stableMs=${stableMs}, modal=${!!startupModal}) providerDir=${this.providerResolutionMeta.providerDir || "-"} scriptDir=${this.providerResolutionMeta.scriptDir || "-"} scriptsPath=${this.providerResolutionMeta.scriptsPath || "-"}`
49224
49267
  );
49225
49268
  this.onStatusChange?.();
49269
+ if (!startupModal) this.schedulePendingOutboundFlush();
49226
49270
  }
49227
49271
  scheduleStartupSettleCheck() {
49228
49272
  if (!this.startupParseGate) return;
@@ -49543,8 +49587,26 @@ ${lastSnapshot}`;
49543
49587
  }
49544
49588
  async writeToPty(data) {
49545
49589
  if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
49590
+ if (process.platform === "win32" && shouldChunkWin32Write(data.length)) {
49591
+ await this.writeWin32Chunked(data);
49592
+ return;
49593
+ }
49546
49594
  await this.ptyProcess.write(data);
49547
49595
  }
49596
+ /** Write `data` to the PTY in bounded, surrogate-safe chunks with a short
49597
+ * inter-chunk gap (win32 paced write). Awaits each chunk's write and the gap
49598
+ * so the returned promise resolves only after the FINAL chunk (carrying any
49599
+ * trailing submit key) has been written. */
49600
+ async writeWin32Chunked(data) {
49601
+ const chunks = chunkPreservingSurrogates(data, WIN32_PTY_WRITE_CHUNK_CHARS);
49602
+ for (let i = 0; i < chunks.length; i += 1) {
49603
+ if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
49604
+ await this.ptyProcess.write(chunks[i]);
49605
+ if (i + 1 < chunks.length) {
49606
+ await new Promise((resolve24) => setTimeout(resolve24, WIN32_PTY_WRITE_CHUNK_GAP_MS));
49607
+ }
49608
+ }
49609
+ }
49548
49610
  resetPendingSendState(reason) {
49549
49611
  this.responseBuffer = "";
49550
49612
  if (this.responseTimeout) {
@@ -49792,7 +49854,13 @@ ${lastSnapshot}`;
49792
49854
  LOG2.info("CLI", `[${this.cliType}] sendMessage recovered idle prompt readiness`);
49793
49855
  }
49794
49856
  }
49795
- if (!this.ready) throw new Error(`${this.cliName} not ready (status: ${this.engine.currentStatus})`);
49857
+ if (!this.ready) {
49858
+ if (allowQueue) {
49859
+ this.enqueuePendingOutboundMessage(text, "not_ready_pending_prompt");
49860
+ return;
49861
+ }
49862
+ throw new Error(`${this.cliName} not ready (status: ${this.engine.currentStatus})`);
49863
+ }
49796
49864
  const parsedSessionStatus = typeof parsedStatusBeforeSend?.status === "string" ? String(parsedStatusBeforeSend.status) : "";
49797
49865
  if (!allowInputDuringGeneration && (parsedSessionStatus === "generating" || parsedSessionStatus === "no_progress" || parsedSessionStatus === "long_generating")) {
49798
49866
  const parsedModal = parsedStatusBeforeSend?.activeModal ?? parsedStatusBeforeSend?.modal ?? null;
@@ -62602,7 +62670,7 @@ ${effect.notification.body || ""}`.trim();
62602
62670
  return { success: false, error: "invalid type" };
62603
62671
  }
62604
62672
  const https = require("https");
62605
- const fs35 = require("fs");
62673
+ const fs38 = require("fs");
62606
62674
  const path43 = require("path");
62607
62675
  const REGISTRY = "https://api.adhf.dev/api/v1/registry";
62608
62676
  function fetchText(url2, timeoutMs) {
@@ -62645,7 +62713,7 @@ ${effect.notification.body || ""}`.trim();
62645
62713
  if (!targetDir.startsWith(installRootResolved + path43.sep)) {
62646
62714
  return { success: false, error: "install path escaped upstream root" };
62647
62715
  }
62648
- fs35.mkdirSync(targetDir, { recursive: true });
62716
+ fs38.mkdirSync(targetDir, { recursive: true });
62649
62717
  let manifestProbe = {};
62650
62718
  try {
62651
62719
  manifestProbe = JSON.parse(manifestBody);
@@ -62670,7 +62738,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62670
62738
  }
62671
62739
  const targetFile = isV1 ? "provider.v1.json" : "provider.json";
62672
62740
  const targetPath = path43.join(targetDir, targetFile);
62673
- fs35.writeFileSync(targetPath, manifestBody, "utf-8");
62741
+ fs38.writeFileSync(targetPath, manifestBody, "utf-8");
62674
62742
  const manifestJson = JSON.parse(manifestBody);
62675
62743
  const scriptFetch = await this.fetchProviderSources(
62676
62744
  manifestJson,
@@ -62740,7 +62808,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62740
62808
  const repo = source.repo;
62741
62809
  const ref = source.ref;
62742
62810
  const https = require("https");
62743
- const fs35 = require("fs");
62811
+ const fs38 = require("fs");
62744
62812
  const path43 = require("path");
62745
62813
  function fetchJson(url2, timeoutMs) {
62746
62814
  return new Promise((resolve24, reject) => {
@@ -62824,8 +62892,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62824
62892
  const relInside = entry.path.startsWith(sharedDirRel + "/") ? entry.path.slice(sharedDirRel.length + 1) : entry.path;
62825
62893
  const outPath = path43.resolve(path43.join(sharedTargetDir, relInside));
62826
62894
  if (!outPath.startsWith(path43.resolve(sharedTargetDir) + path43.sep)) continue;
62827
- fs35.mkdirSync(path43.dirname(outPath), { recursive: true });
62828
- fs35.writeFileSync(outPath, body);
62895
+ fs38.mkdirSync(path43.dirname(outPath), { recursive: true });
62896
+ fs38.writeFileSync(outPath, body);
62829
62897
  fetchedCount++;
62830
62898
  } catch (e) {
62831
62899
  errors.push(`fetch shared ${entry.path}: ${e?.message ?? e}`);
@@ -62863,8 +62931,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62863
62931
  errors.push(`refusing to write outside targetDir: ${entry.path}`);
62864
62932
  continue;
62865
62933
  }
62866
- fs35.mkdirSync(path43.dirname(outPath), { recursive: true });
62867
- fs35.writeFileSync(outPath, body);
62934
+ fs38.mkdirSync(path43.dirname(outPath), { recursive: true });
62935
+ fs38.writeFileSync(outPath, body);
62868
62936
  fetchedCount++;
62869
62937
  } catch (e) {
62870
62938
  errors.push(`fetch ${entry.path}: ${e?.message ?? e}`);
@@ -62892,7 +62960,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62892
62960
  if (!["cli", "ide", "extension", "acp"].includes(category)) {
62893
62961
  return { success: false, error: `unknown category: ${category}` };
62894
62962
  }
62895
- const fs35 = require("fs");
62963
+ const fs38 = require("fs");
62896
62964
  const path43 = require("path");
62897
62965
  try {
62898
62966
  const installRoot = this.getUpstreamInstallRoot();
@@ -62901,10 +62969,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62901
62969
  if (!targetDir.startsWith(installRootResolved + path43.sep)) {
62902
62970
  return { success: false, error: "refusing to delete outside upstream root" };
62903
62971
  }
62904
- if (!fs35.existsSync(targetDir)) {
62972
+ if (!fs38.existsSync(targetDir)) {
62905
62973
  return { success: false, error: "not installed" };
62906
62974
  }
62907
- fs35.rmSync(targetDir, { recursive: true, force: true });
62975
+ fs38.rmSync(targetDir, { recursive: true, force: true });
62908
62976
  if (this._ctx.providerLoader) {
62909
62977
  this._ctx.providerLoader.reload();
62910
62978
  this._ctx.providerLoader.registerToDetector();
@@ -62920,28 +62988,28 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62920
62988
  * the UI and by the update checker.
62921
62989
  */
62922
62990
  handleListInstalledProviders(_args) {
62923
- const fs35 = require("fs");
62991
+ const fs38 = require("fs");
62924
62992
  const path43 = require("path");
62925
62993
  const installRoot = this.getUpstreamInstallRoot();
62926
- if (!fs35.existsSync(installRoot)) return { success: true, providers: [] };
62994
+ if (!fs38.existsSync(installRoot)) return { success: true, providers: [] };
62927
62995
  const CATEGORIES = ["cli", "ide", "extension", "acp"];
62928
62996
  const items = [];
62929
62997
  for (const category of CATEGORIES) {
62930
62998
  const categoryDir = path43.join(installRoot, category);
62931
- if (!fs35.existsSync(categoryDir)) continue;
62999
+ if (!fs38.existsSync(categoryDir)) continue;
62932
63000
  let entries;
62933
63001
  try {
62934
- entries = fs35.readdirSync(categoryDir);
63002
+ entries = fs38.readdirSync(categoryDir);
62935
63003
  } catch {
62936
63004
  continue;
62937
63005
  }
62938
63006
  for (const type of entries) {
62939
63007
  const v1Path = path43.join(categoryDir, type, "provider.v1.json");
62940
63008
  const v0Path = path43.join(categoryDir, type, "provider.json");
62941
- const manifestPath = fs35.existsSync(v1Path) ? v1Path : fs35.existsSync(v0Path) ? v0Path : null;
63009
+ const manifestPath = fs38.existsSync(v1Path) ? v1Path : fs38.existsSync(v0Path) ? v0Path : null;
62942
63010
  if (!manifestPath) continue;
62943
63011
  try {
62944
- const m = JSON.parse(fs35.readFileSync(manifestPath, "utf-8"));
63012
+ const m = JSON.parse(fs38.readFileSync(manifestPath, "utf-8"));
62945
63013
  items.push({
62946
63014
  type,
62947
63015
  category,
@@ -63052,7 +63120,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63052
63120
  if (!/^@[a-z0-9_-]+$/i.test(requestedName)) {
63053
63121
  return { success: false, error: "name must match @[a-z0-9_-]+" };
63054
63122
  }
63055
- const fs35 = require("fs");
63123
+ const fs38 = require("fs");
63056
63124
  const path43 = require("path");
63057
63125
  const { spawnSync: spawnSync2 } = require("child_process");
63058
63126
  const file2 = ext.loadExternalSources();
@@ -63063,8 +63131,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63063
63131
  return { success: false, error: `source url+ref already registered (use a different name to track another ref)` };
63064
63132
  }
63065
63133
  const sourceDir = path43.join(ext.externalRoot(), requestedName);
63066
- if (!fs35.existsSync(ext.externalRoot())) fs35.mkdirSync(ext.externalRoot(), { recursive: true });
63067
- if (fs35.existsSync(sourceDir)) {
63134
+ if (!fs38.existsSync(ext.externalRoot())) fs38.mkdirSync(ext.externalRoot(), { recursive: true });
63135
+ if (fs38.existsSync(sourceDir)) {
63068
63136
  return { success: false, error: `directory already exists: ${sourceDir} (rename or remove first)` };
63069
63137
  }
63070
63138
  const clone2 = spawnSync2("git", ["clone", "--depth=1", "--branch", ref, "--", url2, sourceDir], {
@@ -63074,7 +63142,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63074
63142
  });
63075
63143
  if (clone2.status !== 0) {
63076
63144
  try {
63077
- fs35.rmSync(sourceDir, { recursive: true, force: true });
63145
+ fs38.rmSync(sourceDir, { recursive: true, force: true });
63078
63146
  } catch {
63079
63147
  }
63080
63148
  return { success: false, error: `git clone failed: ${(clone2.stderr || clone2.stdout || "").trim() || "unknown error"}` };
@@ -63118,15 +63186,15 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63118
63186
  const name = typeof args?.name === "string" ? args.name.trim() : "";
63119
63187
  if (!name) return { success: false, error: "name is required" };
63120
63188
  const ext = (init_external_sources(), __toCommonJS2(external_sources_exports));
63121
- const fs35 = require("fs");
63189
+ const fs38 = require("fs");
63122
63190
  const path43 = require("path");
63123
63191
  const file2 = ext.loadExternalSources();
63124
63192
  const match = file2.sources.find((s2) => s2.name === name);
63125
63193
  if (!match) return { success: false, error: `source "${name}" not registered` };
63126
63194
  const sourceDir = path43.join(ext.externalRoot(), name);
63127
- if (fs35.existsSync(sourceDir)) {
63195
+ if (fs38.existsSync(sourceDir)) {
63128
63196
  try {
63129
- fs35.rmSync(sourceDir, { recursive: true, force: true });
63197
+ fs38.rmSync(sourceDir, { recursive: true, force: true });
63130
63198
  } catch (e) {
63131
63199
  return { success: false, error: `failed to delete ${sourceDir}: ${e?.message || e}` };
63132
63200
  }
@@ -63895,14 +63963,14 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63895
63963
  };
63896
63964
  var coordinatorPromptHandlers = {
63897
63965
  list_coordinator_prompts: async (_ctx, _args) => {
63898
- const fs35 = await import("fs");
63966
+ const fs38 = await import("fs");
63899
63967
  const path43 = await import("path");
63900
63968
  const os30 = await import("os");
63901
63969
  const dir = path43.join(os30.homedir(), ".adhdev", "coordinator-prompts");
63902
63970
  const entries = {};
63903
63971
  try {
63904
- if (fs35.existsSync(dir)) {
63905
- for (const name of fs35.readdirSync(dir)) {
63972
+ if (fs38.existsSync(dir)) {
63973
+ for (const name of fs38.readdirSync(dir)) {
63906
63974
  const matchOverride = name.match(/^([a-zA-Z0-9_.-]+)\.md$/);
63907
63975
  const matchAppend = name.match(/^([a-zA-Z0-9_.-]+)\.append\.md$/);
63908
63976
  const m = matchAppend || matchOverride;
@@ -63912,7 +63980,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63912
63980
  const full = path43.join(dir, name);
63913
63981
  let content = "";
63914
63982
  try {
63915
- content = fs35.readFileSync(full, "utf8");
63983
+ content = fs38.readFileSync(full, "utf8");
63916
63984
  } catch {
63917
63985
  }
63918
63986
  if (!entries[key]) entries[key] = { override: "", append: "" };
@@ -63926,7 +63994,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63926
63994
  return { success: true, dir, entries };
63927
63995
  },
63928
63996
  write_coordinator_prompt: async (_ctx, args) => {
63929
- const fs35 = await import("fs");
63997
+ const fs38 = await import("fs");
63930
63998
  const path43 = await import("path");
63931
63999
  const os30 = await import("os");
63932
64000
  const key = typeof args?.key === "string" ? args.key.trim() : "";
@@ -63939,11 +64007,11 @@ ${formatManifestValidationIssues2(validation.issues)}`,
63939
64007
  const filename = kind === "append" ? `${key}.append.md` : `${key}.md`;
63940
64008
  const full = path43.join(dir, filename);
63941
64009
  try {
63942
- fs35.mkdirSync(dir, { recursive: true });
64010
+ fs38.mkdirSync(dir, { recursive: true });
63943
64011
  if (content.trim()) {
63944
- fs35.writeFileSync(full, content, { encoding: "utf8", mode: 384 });
63945
- } else if (fs35.existsSync(full)) {
63946
- fs35.unlinkSync(full);
64012
+ fs38.writeFileSync(full, content, { encoding: "utf8", mode: 384 });
64013
+ } else if (fs38.existsSync(full)) {
64014
+ fs38.unlinkSync(full);
63947
64015
  }
63948
64016
  return { success: true, path: full, kind, key };
63949
64017
  } catch (error48) {
@@ -65236,6 +65304,7 @@ ${body}
65236
65304
  }
65237
65305
  }
65238
65306
  init_logger();
65307
+ init_pty_write_chunking();
65239
65308
  function countNewlines(s2) {
65240
65309
  let n = 0;
65241
65310
  for (let i = 0; i < s2.length; i += 1) if (s2.charCodeAt(i) === 10) n += 1;
@@ -65246,8 +65315,6 @@ ${body}
65246
65315
  var WIN32_SUBMIT_MAX_RESENDS = 14;
65247
65316
  var WIN32_SUBMIT_SETTLE_MS = 500;
65248
65317
  var WIN32_SUBMIT_SETTLE_POLL_MS = 120;
65249
- var WIN32_PTY_WRITE_CHUNK_CHARS = 1024;
65250
- var WIN32_PTY_WRITE_CHUNK_GAP_MS = 8;
65251
65318
  var WIN32_ECHO_PROBE_CHARS = 16;
65252
65319
  var WIN32_ECHO_MAX_WAIT_MS = 2e4;
65253
65320
  function normalizeForEcho(s2) {
@@ -65259,21 +65326,7 @@ ${body}
65259
65326
  const spec = typeof specBeforeSubmit === "number" && specBeforeSubmit > 0 ? specBeforeSubmit : 0;
65260
65327
  return Math.max(spec, SUBMIT_DELAY_FLOOR_MS + linesBonus);
65261
65328
  }
65262
- function chunkPreservingSurrogates(text, size) {
65263
- const chunks = [];
65264
- let offset = 0;
65265
- while (offset < text.length) {
65266
- let end = Math.min(text.length, offset + size);
65267
- if (end < text.length) {
65268
- const code = text.charCodeAt(end - 1);
65269
- if (code >= 55296 && code <= 56319) end -= 1;
65270
- }
65271
- if (end <= offset) end = Math.min(text.length, offset + size);
65272
- chunks.push(text.slice(offset, end));
65273
- offset = end;
65274
- }
65275
- return chunks;
65276
- }
65329
+ var chunkPreservingSurrogates2 = chunkPreservingSurrogates;
65277
65330
  function guessExt(mime) {
65278
65331
  if (/png/i.test(mime)) return ".png";
65279
65332
  if (/jpe?g/i.test(mime)) return ".jpg";
@@ -65944,7 +65997,7 @@ ${body}
65944
65997
  this.adapter.send_keys(text);
65945
65998
  return;
65946
65999
  }
65947
- const chunks = chunkPreservingSurrogates(text, WIN32_PTY_WRITE_CHUNK_CHARS);
66000
+ const chunks = chunkPreservingSurrogates2(text, WIN32_PTY_WRITE_CHUNK_CHARS);
65948
66001
  let idx = 0;
65949
66002
  const writeNext = () => {
65950
66003
  this.win32WriteTimer = null;
@@ -74935,7 +74988,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
74935
74988
  }
74936
74989
  if (providerDir) {
74937
74990
  try {
74938
- const fs35 = require("fs");
74991
+ const fs38 = require("fs");
74939
74992
  const path43 = require("path");
74940
74993
  const candidates = [];
74941
74994
  if (Array.isArray(base.compatibility)) {
@@ -74947,13 +75000,13 @@ Run 'adhdev doctor' for detailed diagnostics.`
74947
75000
  }
74948
75001
  candidates.push(path43.join(providerDir, "specs", "default.json"));
74949
75002
  candidates.push(path43.join(providerDir, "spec.json"));
74950
- const specPath = candidates.find((p) => fs35.existsSync(p));
75003
+ const specPath = candidates.find((p) => fs38.existsSync(p));
74951
75004
  if (specPath) {
74952
75005
  resolved._resolvedSpecPath = specPath;
74953
75006
  let specControls;
74954
75007
  let nh;
74955
75008
  try {
74956
- const rawSpec = JSON.parse(fs35.readFileSync(specPath, "utf8"));
75009
+ const rawSpec = JSON.parse(fs38.readFileSync(specPath, "utf8"));
74957
75010
  specControls = rawSpec.control_bar;
74958
75011
  nh = rawSpec.native_history;
74959
75012
  } catch {
@@ -74985,7 +75038,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
74985
75038
  reader = (input) => executeNativeHistory(nh, input);
74986
75039
  } else if (nh.override_path) {
74987
75040
  const overrideFile = path43.resolve(providerDir, nh.override_path);
74988
- if (fs35.existsSync(overrideFile)) {
75041
+ if (fs38.existsSync(overrideFile)) {
74989
75042
  try {
74990
75043
  registerProviderScriptRootSafely(path43.dirname(path43.dirname(providerDir)));
74991
75044
  delete require.cache[require.resolve(overrideFile)];
@@ -76163,7 +76216,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
76163
76216
  }
76164
76217
  } else if (plat === "win32") {
76165
76218
  try {
76166
- const fs35 = require("fs");
76219
+ const fs38 = require("fs");
76167
76220
  const appNameMap = getMacAppIdentifiers();
76168
76221
  const appName = appNameMap[ideId];
76169
76222
  if (appName) {
@@ -76172,8 +76225,8 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
76172
76225
  appName,
76173
76226
  "storage.json"
76174
76227
  );
76175
- if (fs35.existsSync(storagePath)) {
76176
- const data = JSON.parse(fs35.readFileSync(storagePath, "utf-8"));
76228
+ if (fs38.existsSync(storagePath)) {
76229
+ const data = JSON.parse(fs38.readFileSync(storagePath, "utf-8"));
76177
76230
  const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
76178
76231
  if (workspaces.length > 0) {
76179
76232
  const recent = workspaces[0];
@@ -76716,8 +76769,9 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
76716
76769
  };
76717
76770
  }
76718
76771
  }
76772
+ const explicitCleanupMode = args?.sessionCleanupMode ?? args?.session_cleanup_mode;
76719
76773
  const sessionCleanupMode = ctx.normalizeMeshSessionCleanupMode(
76720
- args?.sessionCleanupMode ?? args?.session_cleanup_mode ?? mesh?.policy?.sessionCleanupOnNodeRemove
76774
+ explicitCleanupMode ?? (node?.isLocalWorktree === true ? "stop_and_delete" : void 0) ?? mesh?.policy?.sessionCleanupOnNodeRemove
76721
76775
  );
76722
76776
  const explicitSessionIds = Array.isArray(args?.sessionIds) ? args.sessionIds.filter((v) => typeof v === "string" && v.trim().length > 0).map((v) => v.trim()) : void 0;
76723
76777
  let sessionCleanup;
@@ -76789,12 +76843,16 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
76789
76843
  }
76790
76844
  }
76791
76845
  const residueWarning = worktreeCleanup?.residue === true && typeof worktreeCleanup?.residueWarning === "string" ? worktreeCleanup.residueWarning : void 0;
76846
+ const skippedLiveSessionIds = Array.isArray(sessionCleanup?.skippedLiveSessionIds) ? sessionCleanup.skippedLiveSessionIds.filter((v) => typeof v === "string") : [];
76847
+ const orphanedSessionsRemaining = skippedLiveSessionIds.length > 0;
76848
+ const orphanNextAction = orphanedSessionsRemaining ? `Live session(s) [${skippedLiveSessionIds.join(", ")}] were skipped and still survive this node removal. Run mesh_cleanup_sessions with mode:'stop_and_delete' and sessionIds:[${skippedLiveSessionIds.map((id) => `'${id}'`).join(", ")}] to release them.` : void 0;
76792
76849
  return {
76793
76850
  success: true,
76794
76851
  removed,
76795
76852
  ...residueWarning ? { residueWarning } : {},
76796
76853
  ...sessionCleanup ? { sessionCleanup } : {},
76797
- ...worktreeCleanup ? { worktreeCleanup } : {}
76854
+ ...worktreeCleanup ? { worktreeCleanup } : {},
76855
+ ...orphanedSessionsRemaining ? { orphanedSessionsRemaining: true, nextAction: orphanNextAction } : {}
76798
76856
  };
76799
76857
  } catch (e) {
76800
76858
  return { success: false, error: e.message };
@@ -78109,7 +78167,7 @@ ${ptyResult.output.slice(-2e3)}`);
78109
78167
  workspace
78110
78168
  };
78111
78169
  }
78112
- const { existsSync: existsSync49, readFileSync: readFileSync40, writeFileSync: writeFileSync24, copyFileSync: copyFileSync4, mkdirSync: mkdirSync21 } = await import("fs");
78170
+ const { existsSync: existsSync52, readFileSync: readFileSync40, writeFileSync: writeFileSync24, copyFileSync: copyFileSync4, mkdirSync: mkdirSync21 } = await import("fs");
78113
78171
  const { dirname: dirname17 } = await import("path");
78114
78172
  const mcpConfigPath = coordinatorSetup.configPath;
78115
78173
  const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
@@ -78152,7 +78210,7 @@ ${ptyResult.output.slice(-2e3)}`);
78152
78210
  if (hermesManualFallback) return returnManualFallback(message);
78153
78211
  return { success: false, code: "mesh_coordinator_config_write_failed", error: message, meshId, cliType, workspace };
78154
78212
  }
78155
- const hadExistingMcpConfig = existsSync49(mcpConfigPath);
78213
+ const hadExistingMcpConfig = existsSync52(mcpConfigPath);
78156
78214
  let existingMcpConfig = hermesBaseConfig?.config || {};
78157
78215
  if (hermesBaseConfig) {
78158
78216
  copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname17(mcpConfigPath));
@@ -78751,7 +78809,7 @@ ${ptyResult.output.slice(-2e3)}`);
78751
78809
  const { deriveMeshReviewInboxItems: deriveMeshReviewInboxItems2 } = await Promise.resolve().then(() => (init_mesh_review_inbox(), mesh_review_inbox_exports));
78752
78810
  const { readLedgerEntries: readLedgerEntries2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
78753
78811
  const { getGitDiffSummary: getGitDiffSummary2 } = await Promise.resolve().then(() => (init_git_diff(), git_diff_exports));
78754
- const { existsSync: existsSync49 } = await import("fs");
78812
+ const { existsSync: existsSync52 } = await import("fs");
78755
78813
  const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
78756
78814
  const mesh = meshRecord?.mesh;
78757
78815
  if (!mesh) return { success: false, error: "Mesh not found" };
@@ -78770,7 +78828,7 @@ ${ptyResult.output.slice(-2e3)}`);
78770
78828
  const derivation = deriveMeshReviewInboxItems2({ nodes: nodeStatuses, ledgerEntries });
78771
78829
  for (const item of derivation.items) {
78772
78830
  const workspace = item.workspace;
78773
- if (!workspace || !existsSync49(workspace)) continue;
78831
+ if (!workspace || !existsSync52(workspace)) continue;
78774
78832
  const baseRef = item.defaultBranch ? `origin/${item.defaultBranch}` : "origin/main";
78775
78833
  try {
78776
78834
  const diffResult = await getGitDiffSummary2(workspace, { baseRef, maxFiles: 100 });
@@ -78815,8 +78873,6 @@ ${ptyResult.output.slice(-2e3)}`);
78815
78873
  ...meshStatusHandlers
78816
78874
  })
78817
78875
  );
78818
- init_cli_detector();
78819
- init_git_status();
78820
78876
  init_dist();
78821
78877
  init_logger();
78822
78878
  var fs28 = __toESM2(require("fs"));
@@ -78962,7 +79018,6 @@ ${ptyResult.output.slice(-2e3)}`);
78962
79018
  }
78963
79019
  }
78964
79020
  cleanOldFiles();
78965
- var yaml4 = __toESM2(require_js_yaml());
78966
79021
  init_mesh_events();
78967
79022
  init_mesh_host_ownership();
78968
79023
  var import_node_child_process5 = require("child_process");
@@ -79051,13 +79106,16 @@ ${ptyResult.output.slice(-2e3)}`);
79051
79106
  return { order: ranked.map((a) => a.nodeId), changeAreas: areaById, rationale };
79052
79107
  }
79053
79108
  init_mesh_work_queue();
79054
- init_mesh_warmup_deadline();
79055
79109
  init_repo_mesh_types();
79056
- var import_os4 = require("os");
79057
- var import_path13 = require("path");
79110
+ var import_path15 = require("path");
79111
+ var fs322 = __toESM2(require("fs"));
79112
+ var import_node_child_process7 = require("child_process");
79113
+ init_cli_detector();
79114
+ init_git_status();
79115
+ init_dist();
79116
+ init_logger();
79117
+ init_mesh_warmup_deadline();
79058
79118
  var fs29 = __toESM2(require("fs"));
79059
- var import_node_child_process6 = require("child_process");
79060
- init_resolve_executable();
79061
79119
  init_runtime_defaults();
79062
79120
  function readProviderPriorityFromPolicy(policy) {
79063
79121
  const record2 = policy && typeof policy === "object" && !Array.isArray(policy) ? policy : {};
@@ -80278,6 +80336,11 @@ ${ptyResult.output.slice(-2e3)}`);
80278
80336
  }
80279
80337
  return { error: `No usable provider detected for node '${args.nodeId}' from providerPriority: ${failed.join("; ")}` };
80280
80338
  }
80339
+ init_git_status();
80340
+ var import_path13 = require("path");
80341
+ var fs30 = __toESM2(require("fs"));
80342
+ var import_node_child_process6 = require("child_process");
80343
+ init_resolve_executable();
80281
80344
  var REFINE_VALIDATION_TIMEOUT_MS = 12e4;
80282
80345
  var REFINE_VALIDATION_OUTPUT_LIMIT_BYTES = 128 * 1024;
80283
80346
  var REFINE_VALIDATION_SUMMARY_CHARS = 2e3;
@@ -80331,18 +80394,18 @@ ${ptyResult.output.slice(-2e3)}`);
80331
80394
  return { enabled: false };
80332
80395
  }
80333
80396
  async function computeGitPatchId(cwd, fromRef, toRef, excludePaths = []) {
80334
- const { execFileSync: execFileSync7 } = await import("child_process");
80397
+ const { execFileSync: execFileSync8 } = await import("child_process");
80335
80398
  const diffArgs = ["diff", "--patch", "--full-index", fromRef, toRef];
80336
80399
  if (excludePaths.length > 0) {
80337
80400
  diffArgs.push("--", ".", ...excludePaths.map((path43) => `:(exclude)${path43}`));
80338
80401
  }
80339
- const diff = execFileSync7("git", diffArgs, {
80402
+ const diff = execFileSync8("git", diffArgs, {
80340
80403
  cwd,
80341
80404
  encoding: "utf8",
80342
80405
  maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
80343
80406
  });
80344
80407
  if (!diff.trim()) return "";
80345
- const patchId = execFileSync7("git", ["patch-id", "--stable"], {
80408
+ const patchId = execFileSync8("git", ["patch-id", "--stable"], {
80346
80409
  cwd,
80347
80410
  input: diff,
80348
80411
  encoding: "utf8",
@@ -80353,8 +80416,8 @@ ${ptyResult.output.slice(-2e3)}`);
80353
80416
  async function runMeshRefinePatchEquivalenceGate(repoRoot, baseHead, branchHead) {
80354
80417
  const startedAt = Date.now();
80355
80418
  try {
80356
- const { execFileSync: execFileSync7 } = await import("child_process");
80357
- const git = (args) => execFileSync7("git", args, {
80419
+ const { execFileSync: execFileSync8 } = await import("child_process");
80420
+ const git = (args) => execFileSync8("git", args, {
80358
80421
  cwd: repoRoot,
80359
80422
  encoding: "utf8",
80360
80423
  maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
@@ -80445,8 +80508,8 @@ ${e?.stderr || ""}`
80445
80508
  async function checkWorktreeChangesPatchEquivalentInRef(repoRoot, ref, worktreeHead) {
80446
80509
  const startedAt = Date.now();
80447
80510
  try {
80448
- const { execFileSync: execFileSync7 } = await import("child_process");
80449
- const git = (gitArgs) => execFileSync7("git", gitArgs, {
80511
+ const { execFileSync: execFileSync8 } = await import("child_process");
80512
+ const git = (gitArgs) => execFileSync8("git", gitArgs, {
80450
80513
  cwd: repoRoot,
80451
80514
  encoding: "utf8",
80452
80515
  maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
@@ -80509,8 +80572,8 @@ ${mergeTreeErr?.stderr || ""}`;
80509
80572
  async function runMeshRefineEffectiveDiffGate(repoRoot, baseHead, branchHead) {
80510
80573
  const startedAt = Date.now();
80511
80574
  try {
80512
- const { execFileSync: execFileSync7 } = await import("child_process");
80513
- const git = (args, opts) => execFileSync7("git", args, {
80575
+ const { execFileSync: execFileSync8 } = await import("child_process");
80576
+ const git = (args, opts) => execFileSync8("git", args, {
80514
80577
  cwd: opts?.cwd || repoRoot,
80515
80578
  encoding: "utf8",
80516
80579
  maxBuffer: REFINE_PATCH_EQUIVALENCE_OUTPUT_LIMIT_BYTES
@@ -80633,7 +80696,7 @@ ${mergeTreeErr?.stderr || ""}`;
80633
80696
  if (!baseCommit || !branchCommit) return false;
80634
80697
  if (baseCommit === branchCommit) return true;
80635
80698
  try {
80636
- if (!fs29.existsSync(submoduleRepoPath)) return false;
80699
+ if (!fs30.existsSync(submoduleRepoPath)) return false;
80637
80700
  (0, import_node_child_process6.execFileSync)("git", ["cat-file", "-e", `${baseCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
80638
80701
  (0, import_node_child_process6.execFileSync)("git", ["cat-file", "-e", `${branchCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
80639
80702
  (0, import_node_child_process6.execFileSync)("git", ["merge-base", "--is-ancestor", baseCommit, branchCommit], { cwd: submoduleRepoPath, stdio: "ignore" });
@@ -80750,7 +80813,7 @@ ${mergeTreeErr?.stderr || ""}`;
80750
80813
  return newTree || void 0;
80751
80814
  } finally {
80752
80815
  try {
80753
- fs29.rmSync(tmpIndex, { force: true });
80816
+ fs30.rmSync(tmpIndex, { force: true });
80754
80817
  } catch {
80755
80818
  }
80756
80819
  }
@@ -80825,7 +80888,7 @@ ${mergeTreeErr?.stderr || ""}`;
80825
80888
  return newTree || void 0;
80826
80889
  } finally {
80827
80890
  try {
80828
- fs29.rmSync(tmpIndex, { force: true });
80891
+ fs30.rmSync(tmpIndex, { force: true });
80829
80892
  } catch {
80830
80893
  }
80831
80894
  }
@@ -80931,7 +80994,7 @@ ${mergeTreeErr?.stderr || ""}`;
80931
80994
  return { stdout: String(stdout || ""), stderr: String(stderr || ""), refspec };
80932
80995
  };
80933
80996
  const importCommitFromWorktreeSubmodule = async (submodulePath, worktreeSubmodulePath, commit) => {
80934
- if (!fs29.existsSync(worktreeSubmodulePath)) return false;
80997
+ if (!fs30.existsSync(worktreeSubmodulePath)) return false;
80935
80998
  try {
80936
80999
  await runGit3(worktreeSubmodulePath, ["cat-file", "-e", `${commit}^{commit}`]);
80937
81000
  } catch {
@@ -80954,7 +81017,7 @@ ${mergeTreeErr?.stderr || ""}`;
80954
81017
  reachable: false
80955
81018
  };
80956
81019
  try {
80957
- if (!fs29.existsSync(submodulePath)) {
81020
+ if (!fs30.existsSync(submodulePath)) {
80958
81021
  entry.error = `Submodule checkout missing at ${gitlink.path}`;
80959
81022
  entry.publishRequired = true;
80960
81023
  if (options.allowAutoPublishSubmoduleMainCommits === true) {
@@ -81191,9 +81254,9 @@ ${mergeTreeErr?.stderr || ""}`;
81191
81254
  return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
81192
81255
  };
81193
81256
  const dependenciesLikelyMissing = (cwd) => {
81194
- if (!fs29.existsSync((0, import_path13.join)(cwd, "package.json"))) return false;
81195
- if (fs29.existsSync((0, import_path13.join)(cwd, "node_modules"))) return false;
81196
- return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs29.existsSync((0, import_path13.join)(cwd, lock)));
81257
+ if (!fs30.existsSync((0, import_path13.join)(cwd, "package.json"))) return false;
81258
+ if (fs30.existsSync((0, import_path13.join)(cwd, "node_modules"))) return false;
81259
+ return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs30.existsSync((0, import_path13.join)(cwd, lock)));
81197
81260
  };
81198
81261
  if (runLegacyBootstrapCommands) {
81199
81262
  summary.bootstrap = { stage: "legacy" };
@@ -81280,6 +81343,11 @@ ${mergeTreeErr?.stderr || ""}`;
81280
81343
  summary.status = "passed";
81281
81344
  return summary;
81282
81345
  }
81346
+ init_logger();
81347
+ var yaml4 = __toESM2(require_js_yaml());
81348
+ var import_os4 = require("os");
81349
+ var import_path14 = require("path");
81350
+ var fs31 = __toESM2(require("fs"));
81283
81351
  function loadYamlModule() {
81284
81352
  return yaml4;
81285
81353
  }
@@ -81298,14 +81366,14 @@ ${mergeTreeErr?.stderr || ""}`;
81298
81366
  }
81299
81367
  function resolveHermesUserHome() {
81300
81368
  const explicitHome = process.env.HERMES_HOME?.trim();
81301
- return explicitHome || (0, import_path13.join)((0, import_os4.homedir)(), ".hermes");
81369
+ return explicitHome || (0, import_path14.join)((0, import_os4.homedir)(), ".hermes");
81302
81370
  }
81303
81371
  function loadHermesCoordinatorBaseConfig(targetConfigPath) {
81304
81372
  const sourceHome = resolveHermesUserHome();
81305
- const sourceConfigPath = (0, import_path13.join)(sourceHome, "config.yaml");
81306
- if (!fs29.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
81307
- if ((0, import_path13.resolve)(sourceConfigPath) === (0, import_path13.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
81308
- const parsed = parseMeshCoordinatorMcpConfig(fs29.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
81373
+ const sourceConfigPath = (0, import_path14.join)(sourceHome, "config.yaml");
81374
+ if (!fs31.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
81375
+ if ((0, import_path14.resolve)(sourceConfigPath) === (0, import_path14.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
81376
+ const parsed = parseMeshCoordinatorMcpConfig(fs31.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
81309
81377
  const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
81310
81378
  return { config: baseConfig, sourceHome, sourceConfigPath };
81311
81379
  }
@@ -81338,13 +81406,13 @@ ${mergeTreeErr?.stderr || ""}`;
81338
81406
  return sanitized;
81339
81407
  }
81340
81408
  function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
81341
- if ((0, import_path13.resolve)(sourceHome) === (0, import_path13.resolve)(targetHome)) return;
81409
+ if ((0, import_path14.resolve)(sourceHome) === (0, import_path14.resolve)(targetHome)) return;
81342
81410
  for (const fileName of [".env", "auth.json"]) {
81343
- const sourcePath = (0, import_path13.join)(sourceHome, fileName);
81344
- const targetPath = (0, import_path13.join)(targetHome, fileName);
81345
- if (!fs29.existsSync(sourcePath)) continue;
81411
+ const sourcePath = (0, import_path14.join)(sourceHome, fileName);
81412
+ const targetPath = (0, import_path14.join)(targetHome, fileName);
81413
+ if (!fs31.existsSync(sourcePath)) continue;
81346
81414
  try {
81347
- fs29.copyFileSync(sourcePath, targetPath);
81415
+ fs31.copyFileSync(sourcePath, targetPath);
81348
81416
  } catch (error48) {
81349
81417
  LOG2.warn("MeshCoordinator", `Could not copy Hermes ${fileName} into isolated coordinator home: ${error48?.message || error48}`);
81350
81418
  }
@@ -81816,7 +81884,7 @@ ${mergeTreeErr?.stderr || ""}`;
81816
81884
  const nodeId = readInlineMeshNodeId(node);
81817
81885
  if (!nodeId || !tombstones.has(nodeId)) return true;
81818
81886
  const workspace = readStringValue(node?.workspace);
81819
- if (workspace && fs29.existsSync(workspace)) {
81887
+ if (workspace && fs322.existsSync(workspace)) {
81820
81888
  tombstones.delete(nodeId);
81821
81889
  return true;
81822
81890
  }
@@ -81851,14 +81919,14 @@ ${mergeTreeErr?.stderr || ""}`;
81851
81919
  * to give handles time to release, and reports whether residue remains.
81852
81920
  */
81853
81921
  async bestEffortRemoveWorktreeDir(dir) {
81854
- if (!dir || !fs29.existsSync(dir)) return { removed: true, residue: false };
81922
+ if (!dir || !fs322.existsSync(dir)) return { removed: true, residue: false };
81855
81923
  const sleep3 = (ms) => new Promise((resolve24) => setTimeout(resolve24, ms));
81856
81924
  const ABSORB = /* @__PURE__ */ new Set(["EINVAL", "EPERM", "EBUSY", "ENOTEMPTY", "EACCES", "EMFILE", "ENFILE"]);
81857
81925
  let lastErr;
81858
81926
  for (let attempt = 0; attempt < 4; attempt++) {
81859
81927
  try {
81860
- fs29.rmSync(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
81861
- if (!fs29.existsSync(dir)) return { removed: true, residue: false };
81928
+ fs322.rmSync(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
81929
+ if (!fs322.existsSync(dir)) return { removed: true, residue: false };
81862
81930
  lastErr = new Error("directory still present after rmSync");
81863
81931
  } catch (e) {
81864
81932
  lastErr = e;
@@ -81869,7 +81937,7 @@ ${mergeTreeErr?.stderr || ""}`;
81869
81937
  }
81870
81938
  await sleep3(150 * (attempt + 1));
81871
81939
  }
81872
- return fs29.existsSync(dir) ? { removed: false, residue: true, error: String(lastErr?.message || lastErr || "unknown rm error") } : { removed: true, residue: false };
81940
+ return fs322.existsSync(dir) ? { removed: false, residue: true, error: String(lastErr?.message || lastErr || "unknown rm error") } : { removed: true, residue: false };
81873
81941
  }
81874
81942
  async cleanupLocalWorktreeNode(args) {
81875
81943
  const workspace = typeof args.node?.workspace === "string" ? args.node.workspace.trim() : "";
@@ -81881,13 +81949,13 @@ ${mergeTreeErr?.stderr || ""}`;
81881
81949
  recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains."
81882
81950
  };
81883
81951
  }
81884
- const worktreeExists = fs29.existsSync(workspace);
81952
+ const worktreeExists = fs322.existsSync(workspace);
81885
81953
  const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
81886
81954
  const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
81887
81955
  if (!worktreeExists) {
81888
81956
  return { success: true, skipped: true, removedPath: workspace, repoRoot: repoRoot || void 0, reason: "worktree_path_missing" };
81889
81957
  }
81890
- if (!repoRoot || !fs29.existsSync(repoRoot)) {
81958
+ if (!repoRoot || !fs322.existsSync(repoRoot)) {
81891
81959
  return {
81892
81960
  success: false,
81893
81961
  code: "mesh_worktree_cleanup_missing_source_repo",
@@ -81905,9 +81973,9 @@ ${mergeTreeErr?.stderr || ""}`;
81905
81973
  }
81906
81974
  const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2, removeWorktree: removeWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
81907
81975
  const normalizePath = (value) => {
81908
- const resolved = (0, import_path13.resolve)(value);
81976
+ const resolved = (0, import_path15.resolve)(value);
81909
81977
  try {
81910
- return fs29.realpathSync(resolved);
81978
+ return fs322.realpathSync(resolved);
81911
81979
  } catch {
81912
81980
  return resolved;
81913
81981
  }
@@ -82204,14 +82272,19 @@ ${mergeTreeErr?.stderr || ""}`;
82204
82272
  skippedCoordinatorSessionIds.push(sessionId);
82205
82273
  continue;
82206
82274
  }
82207
- if (!hasExplicitSessionIds && liveRuntime && !delegateBoundToThisNode) {
82275
+ const matchedByWorkspaceOnly = !recordNodeId;
82276
+ const isWorktreeNodeRemoval = cleanupSource === "mesh_remove_node" && args.node?.isLocalWorktree === true;
82277
+ const cleanWorkspaceOnlyForWorktree = isWorktreeNodeRemoval && matchedByWorkspaceOnly;
82278
+ if (!hasExplicitSessionIds && liveRuntime && !delegateBoundToThisNode && !cleanWorkspaceOnlyForWorktree) {
82208
82279
  skippedSessionIds.push(sessionId);
82209
82280
  skippedLiveSessionIds.push(sessionId);
82210
- const matchedByWorkspaceOnly = !recordNodeId;
82211
82281
  const reason = recordNodeId && recordNodeId !== args.nodeId ? `live_delegate_bound_to_other_node:${recordNodeId}` : matchedByWorkspaceOnly ? "live_session_matched_by_workspace_only_no_node_binding" : "live_session_not_bound_to_this_node";
82212
82282
  skippedLiveSessionReasons.push({ sessionId, reason });
82213
82283
  continue;
82214
82284
  }
82285
+ if (cleanWorkspaceOnlyForWorktree && !delegateBoundToThisNode) {
82286
+ actedLiveDelegateSessionIds.push(sessionId);
82287
+ }
82215
82288
  if (!hasExplicitSessionIds && liveRuntime && delegateBoundToThisNode && args.mode === "delete_stopped") {
82216
82289
  skippedSessionIds.push(sessionId);
82217
82290
  skippedLiveSessionIds.push(sessionId);
@@ -82701,7 +82774,7 @@ ${tail}` : ""
82701
82774
  let didAutoRebase = false;
82702
82775
  let isBehindBase = false;
82703
82776
  try {
82704
- (0, import_node_child_process6.execFileSync)("git", ["merge-base", "--is-ancestor", branchHead, baseHead], {
82777
+ (0, import_node_child_process7.execFileSync)("git", ["merge-base", "--is-ancestor", branchHead, baseHead], {
82705
82778
  cwd: node.workspace,
82706
82779
  stdio: "ignore"
82707
82780
  });
@@ -82711,7 +82784,7 @@ ${tail}` : ""
82711
82784
  if (isBehindBase) {
82712
82785
  const autoRebaseStarted = Date.now();
82713
82786
  try {
82714
- (0, import_node_child_process6.execFileSync)("git", ["rebase", baseHead], {
82787
+ (0, import_node_child_process7.execFileSync)("git", ["rebase", baseHead], {
82715
82788
  cwd: node.workspace,
82716
82789
  stdio: ["ignore", "pipe", "pipe"]
82717
82790
  });
@@ -82752,7 +82825,7 @@ ${tail}` : ""
82752
82825
  }
82753
82826
  } catch (rebaseErr) {
82754
82827
  try {
82755
- (0, import_node_child_process6.execFileSync)("git", ["rebase", "--abort"], { cwd: node.workspace, stdio: "ignore" });
82828
+ (0, import_node_child_process7.execFileSync)("git", ["rebase", "--abort"], { cwd: node.workspace, stdio: "ignore" });
82756
82829
  } catch {
82757
82830
  }
82758
82831
  recordMeshRefineStage(refineStages, "patch_equivalence_after_auto_rebase", "failed", autoRebaseStarted, {
@@ -85489,7 +85562,7 @@ ${hintLines.join("\n")}` : "",
85489
85562
  };
85490
85563
  init_io_contracts();
85491
85564
  init_chat_message_normalization();
85492
- var fs30 = __toESM2(require("fs"));
85565
+ var fs33 = __toESM2(require("fs"));
85493
85566
  var path38 = __toESM2(require("path"));
85494
85567
  var os28 = __toESM2(require("os"));
85495
85568
  var import_os5 = require("os");
@@ -85503,8 +85576,8 @@ ${hintLines.join("\n")}` : "",
85503
85576
  }
85504
85577
  load() {
85505
85578
  try {
85506
- if (fs30.existsSync(ARCHIVE_PATH)) {
85507
- this.history = JSON.parse(fs30.readFileSync(ARCHIVE_PATH, "utf-8"));
85579
+ if (fs33.existsSync(ARCHIVE_PATH)) {
85580
+ this.history = JSON.parse(fs33.readFileSync(ARCHIVE_PATH, "utf-8"));
85508
85581
  }
85509
85582
  } catch {
85510
85583
  this.history = {};
@@ -85541,8 +85614,8 @@ ${hintLines.join("\n")}` : "",
85541
85614
  }
85542
85615
  save() {
85543
85616
  try {
85544
- fs30.mkdirSync(path38.dirname(ARCHIVE_PATH), { recursive: true });
85545
- fs30.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
85617
+ fs33.mkdirSync(path38.dirname(ARCHIVE_PATH), { recursive: true });
85618
+ fs33.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
85546
85619
  } catch {
85547
85620
  }
85548
85621
  }
@@ -85567,8 +85640,8 @@ ${hintLines.join("\n")}` : "",
85567
85640
  for (const ext of exes) {
85568
85641
  const fullPath = path38.join(p, name + ext);
85569
85642
  try {
85570
- if (fs30.existsSync(fullPath)) {
85571
- const stat2 = fs30.statSync(fullPath);
85643
+ if (fs33.existsSync(fullPath)) {
85644
+ const stat2 = fs33.statSync(fullPath);
85572
85645
  if (stat2.isFile() && (isWin || stat2.mode & 73)) {
85573
85646
  return fullPath;
85574
85647
  }
@@ -85615,9 +85688,9 @@ ${hintLines.join("\n")}` : "",
85615
85688
  if (p.includes("*")) {
85616
85689
  const home = os28.homedir();
85617
85690
  const resolved = p.replace(/\*/g, home.split(path38.sep).pop() || "");
85618
- if (fs30.existsSync(resolved)) return resolved;
85691
+ if (fs33.existsSync(resolved)) return resolved;
85619
85692
  } else {
85620
- if (fs30.existsSync(p)) return p;
85693
+ if (fs33.existsSync(p)) return p;
85621
85694
  }
85622
85695
  }
85623
85696
  return null;
@@ -85625,7 +85698,7 @@ ${hintLines.join("\n")}` : "",
85625
85698
  async function getMacAppVersion(appPath) {
85626
85699
  if ((0, import_os5.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
85627
85700
  const plistPath = path38.join(appPath, "Contents", "Info.plist");
85628
- if (!fs30.existsSync(plistPath)) return null;
85701
+ if (!fs33.existsSync(plistPath)) return null;
85629
85702
  const raw = await runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
85630
85703
  return raw || null;
85631
85704
  }
@@ -85652,7 +85725,7 @@ ${hintLines.join("\n")}` : "",
85652
85725
  let resolvedBin = cliBin;
85653
85726
  if (!resolvedBin && appPath && currentOs === "darwin") {
85654
85727
  const bundled = path38.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
85655
- if (provider.cli && fs30.existsSync(bundled)) resolvedBin = bundled;
85728
+ if (provider.cli && fs33.existsSync(bundled)) resolvedBin = bundled;
85656
85729
  }
85657
85730
  info.installed = !!(appPath || resolvedBin);
85658
85731
  info.path = appPath || null;
@@ -85698,7 +85771,7 @@ ${hintLines.join("\n")}` : "",
85698
85771
  return results;
85699
85772
  }
85700
85773
  var http2 = __toESM2(require("http"));
85701
- var fs34 = __toESM2(require("fs"));
85774
+ var fs37 = __toESM2(require("fs"));
85702
85775
  var path422 = __toESM2(require("path"));
85703
85776
  init_config();
85704
85777
  function generateFiles(type, name, category, opts = {}) {
@@ -86044,7 +86117,7 @@ async (params) => {
86044
86117
  }
86045
86118
  init_logger();
86046
86119
  init_builders();
86047
- var fs31 = __toESM2(require("fs"));
86120
+ var fs34 = __toESM2(require("fs"));
86048
86121
  var path39 = __toESM2(require("path"));
86049
86122
  init_logger();
86050
86123
  async function handleCdpEvaluate(ctx, req, res) {
@@ -86225,17 +86298,17 @@ async (params) => {
86225
86298
  }
86226
86299
  let scriptsPath = "";
86227
86300
  const directScripts = path39.join(dir, "scripts.js");
86228
- if (fs31.existsSync(directScripts)) {
86301
+ if (fs34.existsSync(directScripts)) {
86229
86302
  scriptsPath = directScripts;
86230
86303
  } else {
86231
86304
  const scriptsDir = path39.join(dir, "scripts");
86232
- if (fs31.existsSync(scriptsDir)) {
86233
- const versions = fs31.readdirSync(scriptsDir).filter((d) => {
86234
- return fs31.statSync(path39.join(scriptsDir, d)).isDirectory();
86305
+ if (fs34.existsSync(scriptsDir)) {
86306
+ const versions = fs34.readdirSync(scriptsDir).filter((d) => {
86307
+ return fs34.statSync(path39.join(scriptsDir, d)).isDirectory();
86235
86308
  }).sort().reverse();
86236
86309
  for (const ver of versions) {
86237
86310
  const p = path39.join(scriptsDir, ver, "scripts.js");
86238
- if (fs31.existsSync(p)) {
86311
+ if (fs34.existsSync(p)) {
86239
86312
  scriptsPath = p;
86240
86313
  break;
86241
86314
  }
@@ -86247,7 +86320,7 @@ async (params) => {
86247
86320
  return;
86248
86321
  }
86249
86322
  try {
86250
- const source = fs31.readFileSync(scriptsPath, "utf-8");
86323
+ const source = fs34.readFileSync(scriptsPath, "utf-8");
86251
86324
  const hints = {};
86252
86325
  const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
86253
86326
  let match;
@@ -87060,7 +87133,7 @@ async (params) => {
87060
87133
  ctx.json(res, 500, { error: `DOM context collection failed: ${e.message}` });
87061
87134
  }
87062
87135
  }
87063
- var fs322 = __toESM2(require("fs"));
87136
+ var fs35 = __toESM2(require("fs"));
87064
87137
  var path40 = __toESM2(require("path"));
87065
87138
  function slugifyFixtureName(value) {
87066
87139
  const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
@@ -87076,10 +87149,10 @@ async (params) => {
87076
87149
  function readCliFixture(ctx, type, name) {
87077
87150
  const fixtureDir = getCliFixtureDir(ctx, type);
87078
87151
  const filePath = path40.join(fixtureDir, `${name}.json`);
87079
- if (!fs322.existsSync(filePath)) {
87152
+ if (!fs35.existsSync(filePath)) {
87080
87153
  throw new Error(`Fixture not found: ${filePath}`);
87081
87154
  }
87082
- return JSON.parse(fs322.readFileSync(filePath, "utf-8"));
87155
+ return JSON.parse(fs35.readFileSync(filePath, "utf-8"));
87083
87156
  }
87084
87157
  function getExerciseTranscriptText(result) {
87085
87158
  const parts = [];
@@ -87824,7 +87897,7 @@ async (params) => {
87824
87897
  return;
87825
87898
  }
87826
87899
  const fixtureDir = getCliFixtureDir(ctx, type);
87827
- fs322.mkdirSync(fixtureDir, { recursive: true });
87900
+ fs35.mkdirSync(fixtureDir, { recursive: true });
87828
87901
  const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
87829
87902
  const result = await runCliExerciseInternal(ctx, { ...request, type });
87830
87903
  const fixture = {
@@ -87852,7 +87925,7 @@ async (params) => {
87852
87925
  notes: typeof body?.notes === "string" ? body.notes : void 0
87853
87926
  };
87854
87927
  const filePath = path40.join(fixtureDir, `${name}.json`);
87855
- fs322.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
87928
+ fs35.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
87856
87929
  ctx.json(res, 200, {
87857
87930
  saved: true,
87858
87931
  name,
@@ -87870,14 +87943,14 @@ async (params) => {
87870
87943
  async function handleCliFixtureList(ctx, type, _req, res) {
87871
87944
  try {
87872
87945
  const fixtureDir = getCliFixtureDir(ctx, type);
87873
- if (!fs322.existsSync(fixtureDir)) {
87946
+ if (!fs35.existsSync(fixtureDir)) {
87874
87947
  ctx.json(res, 200, { fixtures: [], count: 0 });
87875
87948
  return;
87876
87949
  }
87877
- const fixtures = fs322.readdirSync(fixtureDir).filter((file2) => file2.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file2) => {
87950
+ const fixtures = fs35.readdirSync(fixtureDir).filter((file2) => file2.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file2) => {
87878
87951
  const fullPath = path40.join(fixtureDir, file2);
87879
87952
  try {
87880
- const raw = JSON.parse(fs322.readFileSync(fullPath, "utf-8"));
87953
+ const raw = JSON.parse(fs35.readFileSync(fullPath, "utf-8"));
87881
87954
  return {
87882
87955
  name: raw.name || file2.replace(/\.json$/i, ""),
87883
87956
  path: fullPath,
@@ -88008,7 +88081,7 @@ async (params) => {
88008
88081
  ctx.json(res, 500, { error: `Raw send failed: ${e.message}` });
88009
88082
  }
88010
88083
  }
88011
- var fs33 = __toESM2(require("fs"));
88084
+ var fs36 = __toESM2(require("fs"));
88012
88085
  var path41 = __toESM2(require("path"));
88013
88086
  var os29 = __toESM2(require("os"));
88014
88087
  var import_session_host_core8 = require_dist();
@@ -88057,10 +88130,10 @@ async (params) => {
88057
88130
  return fallback?.type || null;
88058
88131
  }
88059
88132
  function getLatestScriptVersionDir(scriptsDir) {
88060
- if (!fs33.existsSync(scriptsDir)) return null;
88061
- const versions = fs33.readdirSync(scriptsDir).filter((d) => {
88133
+ if (!fs36.existsSync(scriptsDir)) return null;
88134
+ const versions = fs36.readdirSync(scriptsDir).filter((d) => {
88062
88135
  try {
88063
- return fs33.statSync(path41.join(scriptsDir, d)).isDirectory();
88136
+ return fs36.statSync(path41.join(scriptsDir, d)).isDirectory();
88064
88137
  } catch {
88065
88138
  return false;
88066
88139
  }
@@ -88082,13 +88155,13 @@ async (params) => {
88082
88155
  if (!sourceDir) {
88083
88156
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
88084
88157
  }
88085
- if (!fs33.existsSync(desiredDir)) {
88086
- fs33.mkdirSync(path41.dirname(desiredDir), { recursive: true });
88087
- fs33.cpSync(sourceDir, desiredDir, { recursive: true });
88158
+ if (!fs36.existsSync(desiredDir)) {
88159
+ fs36.mkdirSync(path41.dirname(desiredDir), { recursive: true });
88160
+ fs36.cpSync(sourceDir, desiredDir, { recursive: true });
88088
88161
  ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
88089
88162
  }
88090
88163
  const providerJson = path41.join(desiredDir, "provider.json");
88091
- if (!fs33.existsSync(providerJson)) {
88164
+ if (!fs36.existsSync(providerJson)) {
88092
88165
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
88093
88166
  }
88094
88167
  return { dir: desiredDir };
@@ -88096,15 +88169,15 @@ async (params) => {
88096
88169
  function loadAutoImplReferenceScripts(ctx, referenceType) {
88097
88170
  if (!referenceType) return {};
88098
88171
  const refDir = ctx.findProviderDir(referenceType);
88099
- if (!refDir || !fs33.existsSync(refDir)) return {};
88172
+ if (!refDir || !fs36.existsSync(refDir)) return {};
88100
88173
  const referenceScripts = {};
88101
88174
  const scriptsDir = path41.join(refDir, "scripts");
88102
88175
  const latestDir = getLatestScriptVersionDir(scriptsDir);
88103
88176
  if (!latestDir) return referenceScripts;
88104
- for (const file2 of fs33.readdirSync(latestDir)) {
88177
+ for (const file2 of fs36.readdirSync(latestDir)) {
88105
88178
  if (!file2.endsWith(".js")) continue;
88106
88179
  try {
88107
- referenceScripts[file2] = fs33.readFileSync(path41.join(latestDir, file2), "utf-8");
88180
+ referenceScripts[file2] = fs36.readFileSync(path41.join(latestDir, file2), "utf-8");
88108
88181
  } catch {
88109
88182
  }
88110
88183
  }
@@ -88213,15 +88286,15 @@ async (params) => {
88213
88286
  const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
88214
88287
  const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
88215
88288
  const tmpDir = path41.join(os29.tmpdir(), "adhdev-autoimpl");
88216
- if (!fs33.existsSync(tmpDir)) fs33.mkdirSync(tmpDir, { recursive: true });
88289
+ if (!fs36.existsSync(tmpDir)) fs36.mkdirSync(tmpDir, { recursive: true });
88217
88290
  const promptFile = path41.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
88218
- fs33.writeFileSync(promptFile, prompt, "utf-8");
88291
+ fs36.writeFileSync(promptFile, prompt, "utf-8");
88219
88292
  ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
88220
88293
  const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
88221
88294
  const spawn4 = agentProvider?.spawn;
88222
88295
  if (!spawn4?.command) {
88223
88296
  try {
88224
- fs33.unlinkSync(promptFile);
88297
+ fs36.unlinkSync(promptFile);
88225
88298
  } catch {
88226
88299
  }
88227
88300
  ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
@@ -88323,7 +88396,7 @@ async (params) => {
88323
88396
  } catch {
88324
88397
  }
88325
88398
  try {
88326
- fs33.unlinkSync(promptFile);
88399
+ fs36.unlinkSync(promptFile);
88327
88400
  } catch {
88328
88401
  }
88329
88402
  ctx.log(`Auto-implement (ACP) ${success2 ? "completed" : "failed"}: ${type} (exit: ${code})`);
@@ -88549,7 +88622,7 @@ async (params) => {
88549
88622
  }
88550
88623
  });
88551
88624
  try {
88552
- fs33.unlinkSync(promptFile);
88625
+ fs36.unlinkSync(promptFile);
88553
88626
  } catch {
88554
88627
  }
88555
88628
  ctx.log(`Auto-implement ${success2 ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
@@ -88654,10 +88727,10 @@ async (params) => {
88654
88727
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
88655
88728
  lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
88656
88729
  lines.push("");
88657
- for (const file2 of fs33.readdirSync(latestScriptsDir)) {
88730
+ for (const file2 of fs36.readdirSync(latestScriptsDir)) {
88658
88731
  if (file2.endsWith(".js") && targetFileNames.has(file2)) {
88659
88732
  try {
88660
- const content = fs33.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
88733
+ const content = fs36.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
88661
88734
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
88662
88735
  lines.push("```javascript");
88663
88736
  lines.push(content);
@@ -88667,14 +88740,14 @@ async (params) => {
88667
88740
  }
88668
88741
  }
88669
88742
  }
88670
- const refFiles = fs33.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
88743
+ const refFiles = fs36.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
88671
88744
  if (refFiles.length > 0) {
88672
88745
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
88673
88746
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
88674
88747
  lines.push("");
88675
88748
  for (const file2 of refFiles) {
88676
88749
  try {
88677
- const content = fs33.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
88750
+ const content = fs36.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
88678
88751
  lines.push(`### \`${file2}\` \u{1F512}`);
88679
88752
  lines.push("```javascript");
88680
88753
  lines.push(content);
@@ -88719,7 +88792,7 @@ async (params) => {
88719
88792
  const loadGuide = (name) => {
88720
88793
  try {
88721
88794
  const p = path41.join(docsDir, name);
88722
- if (fs33.existsSync(p)) return fs33.readFileSync(p, "utf-8");
88795
+ if (fs36.existsSync(p)) return fs36.readFileSync(p, "utf-8");
88723
88796
  } catch {
88724
88797
  }
88725
88798
  return null;
@@ -88963,11 +89036,11 @@ async (params) => {
88963
89036
  lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
88964
89037
  lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
88965
89038
  lines.push("");
88966
- for (const file2 of fs33.readdirSync(latestScriptsDir)) {
89039
+ for (const file2 of fs36.readdirSync(latestScriptsDir)) {
88967
89040
  if (!file2.endsWith(".js")) continue;
88968
89041
  if (!targetFileNames.has(file2)) continue;
88969
89042
  try {
88970
- const content = fs33.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
89043
+ const content = fs36.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
88971
89044
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
88972
89045
  lines.push("```javascript");
88973
89046
  lines.push(content);
@@ -88976,14 +89049,14 @@ async (params) => {
88976
89049
  } catch {
88977
89050
  }
88978
89051
  }
88979
- const refFiles = fs33.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
89052
+ const refFiles = fs36.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
88980
89053
  if (refFiles.length > 0) {
88981
89054
  lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
88982
89055
  lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
88983
89056
  lines.push("");
88984
89057
  for (const file2 of refFiles) {
88985
89058
  try {
88986
- const content = fs33.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
89059
+ const content = fs36.readFileSync(path41.join(latestScriptsDir, file2), "utf-8");
88987
89060
  lines.push(`### \`${file2}\` \u{1F512}`);
88988
89061
  lines.push("```javascript");
88989
89062
  lines.push(content);
@@ -89020,7 +89093,7 @@ async (params) => {
89020
89093
  const loadGuide = (name) => {
89021
89094
  try {
89022
89095
  const p = path41.join(docsDir, name);
89023
- if (fs33.existsSync(p)) return fs33.readFileSync(p, "utf-8");
89096
+ if (fs36.existsSync(p)) return fs36.readFileSync(p, "utf-8");
89024
89097
  } catch {
89025
89098
  }
89026
89099
  return null;
@@ -89758,7 +89831,7 @@ data: ${JSON.stringify(msg.data)}
89758
89831
  path422.join(process.cwd(), "packages/web-devconsole/dist")
89759
89832
  ];
89760
89833
  for (const dir of candidates) {
89761
- if (fs34.existsSync(path422.join(dir, "index.html"))) return dir;
89834
+ if (fs37.existsSync(path422.join(dir, "index.html"))) return dir;
89762
89835
  }
89763
89836
  return null;
89764
89837
  }
@@ -89770,7 +89843,7 @@ data: ${JSON.stringify(msg.data)}
89770
89843
  }
89771
89844
  const htmlPath = path422.join(distDir, "index.html");
89772
89845
  try {
89773
- const html = fs34.readFileSync(htmlPath, "utf-8");
89846
+ const html = fs37.readFileSync(htmlPath, "utf-8");
89774
89847
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
89775
89848
  res.end(html);
89776
89849
  } catch (e) {
@@ -89800,7 +89873,7 @@ data: ${JSON.stringify(msg.data)}
89800
89873
  return;
89801
89874
  }
89802
89875
  try {
89803
- const content = fs34.readFileSync(filePath);
89876
+ const content = fs37.readFileSync(filePath);
89804
89877
  const ext = path422.extname(filePath);
89805
89878
  const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
89806
89879
  res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
@@ -89909,14 +89982,14 @@ data: ${JSON.stringify(msg.data)}
89909
89982
  const files = [];
89910
89983
  const scan = (d, prefix) => {
89911
89984
  try {
89912
- for (const entry of fs34.readdirSync(d, { withFileTypes: true })) {
89985
+ for (const entry of fs37.readdirSync(d, { withFileTypes: true })) {
89913
89986
  if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
89914
89987
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
89915
89988
  if (entry.isDirectory()) {
89916
89989
  files.push({ path: rel, size: 0, type: "dir" });
89917
89990
  scan(path422.join(d, entry.name), rel);
89918
89991
  } else {
89919
- const stat2 = fs34.statSync(path422.join(d, entry.name));
89992
+ const stat2 = fs37.statSync(path422.join(d, entry.name));
89920
89993
  files.push({ path: rel, size: stat2.size, type: "file" });
89921
89994
  }
89922
89995
  }
@@ -89944,11 +90017,11 @@ data: ${JSON.stringify(msg.data)}
89944
90017
  this.json(res, 403, { error: "Forbidden" });
89945
90018
  return;
89946
90019
  }
89947
- if (!fs34.existsSync(fullPath) || fs34.statSync(fullPath).isDirectory()) {
90020
+ if (!fs37.existsSync(fullPath) || fs37.statSync(fullPath).isDirectory()) {
89948
90021
  this.json(res, 404, { error: `File not found: ${filePath}` });
89949
90022
  return;
89950
90023
  }
89951
- const content = fs34.readFileSync(fullPath, "utf-8");
90024
+ const content = fs37.readFileSync(fullPath, "utf-8");
89952
90025
  this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
89953
90026
  }
89954
90027
  /** POST /api/providers/:type/file — write a file { path, content } */
@@ -89970,9 +90043,9 @@ data: ${JSON.stringify(msg.data)}
89970
90043
  return;
89971
90044
  }
89972
90045
  try {
89973
- if (fs34.existsSync(fullPath)) fs34.copyFileSync(fullPath, fullPath + ".bak");
89974
- fs34.mkdirSync(path422.dirname(fullPath), { recursive: true });
89975
- fs34.writeFileSync(fullPath, content, "utf-8");
90046
+ if (fs37.existsSync(fullPath)) fs37.copyFileSync(fullPath, fullPath + ".bak");
90047
+ fs37.mkdirSync(path422.dirname(fullPath), { recursive: true });
90048
+ fs37.writeFileSync(fullPath, content, "utf-8");
89976
90049
  this.log(`File saved: ${fullPath} (${content.length} chars)`);
89977
90050
  this.providerLoader.reload();
89978
90051
  this.json(res, 200, { saved: true, path: filePath, chars: content.length });
@@ -89989,8 +90062,8 @@ data: ${JSON.stringify(msg.data)}
89989
90062
  }
89990
90063
  for (const name of ["scripts.js", "provider.json"]) {
89991
90064
  const p = path422.join(dir, name);
89992
- if (fs34.existsSync(p)) {
89993
- const source = fs34.readFileSync(p, "utf-8");
90065
+ if (fs37.existsSync(p)) {
90066
+ const source = fs37.readFileSync(p, "utf-8");
89994
90067
  this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
89995
90068
  return;
89996
90069
  }
@@ -90009,11 +90082,11 @@ data: ${JSON.stringify(msg.data)}
90009
90082
  this.json(res, 404, { error: `Provider not found: ${type}` });
90010
90083
  return;
90011
90084
  }
90012
- const target = fs34.existsSync(path422.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
90085
+ const target = fs37.existsSync(path422.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
90013
90086
  const targetPath = path422.join(dir, target);
90014
90087
  try {
90015
- if (fs34.existsSync(targetPath)) fs34.copyFileSync(targetPath, targetPath + ".bak");
90016
- fs34.writeFileSync(targetPath, source, "utf-8");
90088
+ if (fs37.existsSync(targetPath)) fs37.copyFileSync(targetPath, targetPath + ".bak");
90089
+ fs37.writeFileSync(targetPath, source, "utf-8");
90017
90090
  this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
90018
90091
  this.providerLoader.reload();
90019
90092
  this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
@@ -90158,20 +90231,20 @@ data: ${JSON.stringify(msg.data)}
90158
90231
  let targetDir;
90159
90232
  targetDir = this.providerLoader.getUserProviderDir(category, type);
90160
90233
  const jsonPath = path422.join(targetDir, "provider.json");
90161
- if (fs34.existsSync(jsonPath)) {
90234
+ if (fs37.existsSync(jsonPath)) {
90162
90235
  this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
90163
90236
  return;
90164
90237
  }
90165
90238
  try {
90166
90239
  const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version: version2, osPaths, processNames });
90167
- fs34.mkdirSync(targetDir, { recursive: true });
90168
- fs34.writeFileSync(jsonPath, result["provider.json"], "utf-8");
90240
+ fs37.mkdirSync(targetDir, { recursive: true });
90241
+ fs37.writeFileSync(jsonPath, result["provider.json"], "utf-8");
90169
90242
  const createdFiles = ["provider.json"];
90170
90243
  if (result.files) {
90171
90244
  for (const [relPath, content] of Object.entries(result.files)) {
90172
90245
  const fullPath = path422.join(targetDir, relPath);
90173
- fs34.mkdirSync(path422.dirname(fullPath), { recursive: true });
90174
- fs34.writeFileSync(fullPath, content, "utf-8");
90246
+ fs37.mkdirSync(path422.dirname(fullPath), { recursive: true });
90247
+ fs37.writeFileSync(fullPath, content, "utf-8");
90175
90248
  createdFiles.push(relPath);
90176
90249
  }
90177
90250
  }
@@ -90220,10 +90293,10 @@ data: ${JSON.stringify(msg.data)}
90220
90293
  }
90221
90294
  // ─── Phase 2: Auto-Implement Backend ───
90222
90295
  getLatestScriptVersionDir(scriptsDir) {
90223
- if (!fs34.existsSync(scriptsDir)) return null;
90224
- const versions = fs34.readdirSync(scriptsDir).filter((d) => {
90296
+ if (!fs37.existsSync(scriptsDir)) return null;
90297
+ const versions = fs37.readdirSync(scriptsDir).filter((d) => {
90225
90298
  try {
90226
- return fs34.statSync(path422.join(scriptsDir, d)).isDirectory();
90299
+ return fs37.statSync(path422.join(scriptsDir, d)).isDirectory();
90227
90300
  } catch {
90228
90301
  return false;
90229
90302
  }
@@ -90245,13 +90318,13 @@ data: ${JSON.stringify(msg.data)}
90245
90318
  if (!sourceDir) {
90246
90319
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
90247
90320
  }
90248
- if (!fs34.existsSync(desiredDir)) {
90249
- fs34.mkdirSync(path422.dirname(desiredDir), { recursive: true });
90250
- fs34.cpSync(sourceDir, desiredDir, { recursive: true });
90321
+ if (!fs37.existsSync(desiredDir)) {
90322
+ fs37.mkdirSync(path422.dirname(desiredDir), { recursive: true });
90323
+ fs37.cpSync(sourceDir, desiredDir, { recursive: true });
90251
90324
  this.log(`Auto-implement writable copy created: ${desiredDir}`);
90252
90325
  }
90253
90326
  const providerJson = path422.join(desiredDir, "provider.json");
90254
- if (!fs34.existsSync(providerJson)) {
90327
+ if (!fs37.existsSync(providerJson)) {
90255
90328
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
90256
90329
  }
90257
90330
  return { dir: desiredDir };
@@ -91214,8 +91287,8 @@ data: ${JSON.stringify(msg.data)}
91214
91287
  const res = await fetch(extension.vsixUrl);
91215
91288
  if (res.ok) {
91216
91289
  const buffer = Buffer.from(await res.arrayBuffer());
91217
- const fs35 = await import("fs");
91218
- fs35.writeFileSync(vsixPath, buffer);
91290
+ const fs38 = await import("fs");
91291
+ fs38.writeFileSync(vsixPath, buffer);
91219
91292
  return new Promise((resolve24) => {
91220
91293
  const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
91221
91294
  (0, import_child_process11.exec)(cmd, { timeout: 6e4 }, (error48, _stdout, stderr) => {