@adhdev/daemon-standalone 0.9.82-rc.316 → 0.9.82-rc.318

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
@@ -30075,10 +30075,10 @@ var require_dist3 = __commonJS({
30075
30075
  }
30076
30076
  function getDaemonBuildInfo() {
30077
30077
  if (cached2) return cached2;
30078
- const commit = readInjected(true ? "930909642b3f28668483159d3a8f39d0a796c61a" : void 0) ?? "unknown";
30079
- const commitShort = readInjected(true ? "93090964" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30080
- const version2 = readInjected(true ? "0.9.82-rc.316" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30081
- const builtAt = readInjected(true ? "2026-06-18T07:23:33.672Z" : void 0);
30078
+ const commit = readInjected(true ? "506ca246e28984a3b699b04c4601117f62ba2d81" : void 0) ?? "unknown";
30079
+ const commitShort = readInjected(true ? "506ca246" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30080
+ const version2 = readInjected(true ? "0.9.82-rc.318" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30081
+ const builtAt = readInjected(true ? "2026-06-18T12:46:41.804Z" : void 0);
30082
30082
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30083
30083
  return cached2;
30084
30084
  }
@@ -30402,14 +30402,79 @@ var require_dist3 = __commonJS({
30402
30402
  async function getSubmoduleStatuses(repo, options) {
30403
30403
  if (!repo.repoRoot) return [];
30404
30404
  try {
30405
- const result = await runGit(repo, ["submodule", "status"], options);
30406
- const submodules = parseSubmoduleStatusOutput(result.stdout, repo.repoRoot, options.submoduleIgnorePaths);
30405
+ const submodules = await deriveSubmoduleGitlinkStatuses(repo, options);
30407
30406
  await Promise.all(submodules.map((submodule) => enrichSubmoduleWorktreeStatus(repo, submodule, options)));
30408
30407
  return submodules;
30409
30408
  } catch {
30410
30409
  return [];
30411
30410
  }
30412
30411
  }
30412
+ async function deriveSubmoduleGitlinkStatuses(repo, options) {
30413
+ if (!repo.repoRoot) return [];
30414
+ const paths = await readSubmodulePaths(repo, options);
30415
+ const ignoreSet = new Set(options.submoduleIgnorePaths || []);
30416
+ const lastCheckedAt = Date.now();
30417
+ const entries = await Promise.all(
30418
+ paths.filter((path41) => !ignoreSet.has(path41)).map(async (path41) => {
30419
+ const repoPath = repo.repoRoot + "/" + path41;
30420
+ const expected = await readGitlinkExpectedSha(repo, path41, options);
30421
+ const actual = await readSubmoduleHeadSha(repo, repoPath, options);
30422
+ const outOfSync = actual === null ? true : expected !== null && expected !== actual;
30423
+ return {
30424
+ path: path41,
30425
+ // Prefer the recorded gitlink SHA (matches the legacy column); fall back
30426
+ // to the checked-out SHA so the field is never empty when both are known.
30427
+ commit: expected ?? actual ?? "",
30428
+ repoPath,
30429
+ dirty: false,
30430
+ outOfSync,
30431
+ lastCheckedAt
30432
+ };
30433
+ })
30434
+ );
30435
+ return entries;
30436
+ }
30437
+ async function readSubmodulePaths(repo, options) {
30438
+ if (!repo.repoRoot) return [];
30439
+ const gitmodulesPath = repo.repoRoot + "/.gitmodules";
30440
+ try {
30441
+ const result = await runGit(
30442
+ repo,
30443
+ ["config", "--file", gitmodulesPath, "--get-regexp", "^submodule\\..*\\.path$"],
30444
+ options
30445
+ );
30446
+ const paths = [];
30447
+ for (const line of result.stdout.split("\n")) {
30448
+ const spaceIdx = line.indexOf(" ");
30449
+ if (spaceIdx < 0) continue;
30450
+ const value = line.slice(spaceIdx + 1).trim();
30451
+ if (value) paths.push(value);
30452
+ }
30453
+ return paths;
30454
+ } catch {
30455
+ return [];
30456
+ }
30457
+ }
30458
+ async function readGitlinkExpectedSha(repo, submodulePath, options) {
30459
+ try {
30460
+ const result = await runGit(repo, ["ls-tree", "HEAD", submodulePath], options);
30461
+ const line = result.stdout.split("\n").find((l) => l.trim().length > 0);
30462
+ if (!line) return null;
30463
+ const match = line.match(/^\s*\d+\s+commit\s+([0-9a-f]{40})\b/);
30464
+ return match ? match[1] : null;
30465
+ } catch {
30466
+ return null;
30467
+ }
30468
+ }
30469
+ async function readSubmoduleHeadSha(repo, repoPath, options) {
30470
+ try {
30471
+ const result = await runGit(repo, ["rev-parse", "HEAD"], { ...options, cwd: repoPath });
30472
+ const sha = result.stdout.trim();
30473
+ return /^[0-9a-f]{40}$/.test(sha) ? sha : null;
30474
+ } catch {
30475
+ return null;
30476
+ }
30477
+ }
30413
30478
  async function enrichSubmoduleWorktreeStatus(repo, submodule, options) {
30414
30479
  try {
30415
30480
  const result = await runGit(repo, ["status", "--porcelain=v2", "--branch"], {
@@ -30424,28 +30489,6 @@ var require_dist3 = __commonJS({
30424
30489
  submodule.error = formatGitError(error48);
30425
30490
  }
30426
30491
  }
30427
- function parseSubmoduleStatusOutput(output, repoRoot, ignorePaths) {
30428
- const submodules = [];
30429
- const ignoreSet = new Set(ignorePaths || []);
30430
- for (const line of output.split("\n")) {
30431
- if (!line.trim()) continue;
30432
- const match = line.match(/^([\-+U\s])([0-9a-f]{40})\s+(\S+)(?:\s+\(([^)]+)\))?/);
30433
- if (!match) continue;
30434
- const prefix = match[1];
30435
- const commit = match[2];
30436
- const path41 = match[3];
30437
- if (ignoreSet.has(path41)) continue;
30438
- submodules.push({
30439
- path: path41,
30440
- commit,
30441
- repoPath: repoRoot + "/" + path41,
30442
- dirty: prefix === "U",
30443
- outOfSync: prefix === "-" || prefix === "+",
30444
- lastCheckedAt: Date.now()
30445
- });
30446
- }
30447
- return submodules;
30448
- }
30449
30492
  var lastKnownGoodStatus;
30450
30493
  var DAEMON_RUNTIME_PACKAGES;
30451
30494
  var WEB_ONLY_PACKAGES;
@@ -33713,6 +33756,18 @@ Valid status values: \`completed\` | \`failed\` | \`blocked\` | \`partial\`.`;
33713
33756
  `).get(meshId, nodeId);
33714
33757
  return row?.count ?? 0;
33715
33758
  }
33759
+ /**
33760
+ * O(1) count of queue tasks in 'pending' status for a mesh. A COUNT(*) over the
33761
+ * indexed status column, so it avoids JSON.parse-ing every queue row — used as a
33762
+ * cheap guard before the reconcile loop runs a full triggerMeshQueue scan.
33763
+ */
33764
+ pendingQueueTaskCount(meshId) {
33765
+ const row = this.db.prepare(`
33766
+ SELECT COUNT(*) as count FROM mesh_queue
33767
+ WHERE mesh_id = ? AND status = 'pending'
33768
+ `).get(meshId);
33769
+ return row?.count ?? 0;
33770
+ }
33716
33771
  /**
33717
33772
  * Read the current per-mesh round-robin cursor (0 when unset). Used to rotate
33718
33773
  * the tie-break winner among nodes tied at the least load.
@@ -37630,6 +37685,404 @@ Next step: ${nextStep}`;
37630
37685
  init_dist();
37631
37686
  }
37632
37687
  });
37688
+ var import_session_host_core22;
37689
+ var init_spawn_env = __esm2({
37690
+ "src/cli-adapters/spawn-env.ts"() {
37691
+ "use strict";
37692
+ import_session_host_core22 = require_dist();
37693
+ }
37694
+ });
37695
+ function stripAnsi(str) {
37696
+ return str.replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
37697
+ }
37698
+ function parseCount(params, fallback = 1) {
37699
+ const first = Number(String(params || "").split(";")[0] || fallback);
37700
+ return Math.max(1, Number.isFinite(first) ? first : fallback);
37701
+ }
37702
+ function isCombiningMark(ch) {
37703
+ return /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/.test(ch);
37704
+ }
37705
+ function isWideCodePoint(ch) {
37706
+ const cp = ch.codePointAt(0) || 0;
37707
+ return cp >= 4352 && (cp <= 4447 || cp === 9001 || cp === 9002 || cp >= 11904 && cp <= 42191 && cp !== 12351 || cp >= 44032 && cp <= 55203 || cp >= 63744 && cp <= 64255 || cp >= 65040 && cp <= 65049 || cp >= 65072 && cp <= 65135 || cp >= 65280 && cp <= 65376 || cp >= 65504 && cp <= 65510 || cp >= 127744 && cp <= 129791);
37708
+ }
37709
+ function stripTerminalNoise(str) {
37710
+ return String(str || "").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, "").replace(/\r+/g, "\n").replace(/[ \t]+\n/g, "\n").replace(/\n{4,}/g, "\n\n\n");
37711
+ }
37712
+ function sanitizeTerminalText(str) {
37713
+ const accumulator = new TerminalTranscriptAccumulator();
37714
+ return stripTerminalNoise(stripAnsi(accumulator.append(str)));
37715
+ }
37716
+ function listCliScriptNames(scripts) {
37717
+ if (!scripts) return [];
37718
+ return Object.entries(scripts).filter(([, fn]) => typeof fn === "function").map(([name]) => name);
37719
+ }
37720
+ function splitCliScreenLines(text) {
37721
+ return String(text || "").replace(/\u0007/g, "").replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").map((line) => line.replace(/\s+$/, ""));
37722
+ }
37723
+ function isPromptLikeCliLine(line) {
37724
+ const trimmed = String(line || "").trim();
37725
+ if (!trimmed) return false;
37726
+ return /^[❯›>]\s*(?:$|\S.*)$/.test(trimmed);
37727
+ }
37728
+ function buildCliScreenSnapshot(text) {
37729
+ const normalizedText = String(text || "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
37730
+ const rawLines = splitCliScreenLines(normalizedText);
37731
+ const lines = rawLines.map((line, index, arr) => {
37732
+ const trimmed = String(line || "").trim();
37733
+ return {
37734
+ index,
37735
+ fromTop: index,
37736
+ fromBottom: arr.length - index - 1,
37737
+ text: line,
37738
+ trimmed,
37739
+ isEmpty: trimmed.length === 0
37740
+ };
37741
+ });
37742
+ const nonEmptyLines = lines.filter((line) => !line.isEmpty);
37743
+ const firstNonEmptyLine = nonEmptyLines[0] ?? null;
37744
+ const lastNonEmptyLine = nonEmptyLines[nonEmptyLines.length - 1] ?? null;
37745
+ let promptLineIndex = -1;
37746
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
37747
+ if (isPromptLikeCliLine(lines[i].text)) {
37748
+ promptLineIndex = i;
37749
+ break;
37750
+ }
37751
+ }
37752
+ return {
37753
+ text: normalizedText,
37754
+ lineCount: lines.length,
37755
+ lines,
37756
+ nonEmptyLines,
37757
+ firstNonEmptyLineIndex: firstNonEmptyLine?.index ?? -1,
37758
+ lastNonEmptyLineIndex: lastNonEmptyLine?.index ?? -1,
37759
+ firstNonEmptyLine,
37760
+ lastNonEmptyLine,
37761
+ promptLineIndex,
37762
+ promptLine: promptLineIndex >= 0 ? lines[promptLineIndex] : null,
37763
+ linesAbovePrompt: promptLineIndex >= 0 ? lines.slice(0, promptLineIndex) : [...lines],
37764
+ linesBelowPrompt: promptLineIndex >= 0 ? lines.slice(promptLineIndex + 1) : []
37765
+ };
37766
+ }
37767
+ function findBinary(name) {
37768
+ const trimmed = String(name || "").trim();
37769
+ if (!trimmed) return trimmed;
37770
+ const expanded = trimmed.startsWith("~") ? path10.join(os52.homedir(), trimmed.slice(1)) : trimmed;
37771
+ if (path10.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
37772
+ return path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
37773
+ }
37774
+ const isWin = os52.platform() === "win32";
37775
+ const paths = (process.env.PATH || "").split(path10.delimiter);
37776
+ const extraDirs = [];
37777
+ if (isWin) {
37778
+ if (process.env.APPDATA) extraDirs.push(path10.join(process.env.APPDATA, "npm"));
37779
+ try {
37780
+ extraDirs.push(path10.dirname(process.execPath));
37781
+ } catch {
37782
+ }
37783
+ } else {
37784
+ extraDirs.push(path10.join(os52.homedir(), ".npm-global", "bin"));
37785
+ extraDirs.push("/usr/local/bin", "/opt/homebrew/bin");
37786
+ try {
37787
+ extraDirs.push(path10.dirname(process.execPath));
37788
+ } catch {
37789
+ }
37790
+ }
37791
+ const searchDirs = [...paths, ...extraDirs];
37792
+ const exes = isWin ? [".exe", ".cmd", ".bat", ""] : [""];
37793
+ for (const p of searchDirs) {
37794
+ if (!p) continue;
37795
+ for (const ext of exes) {
37796
+ const fullPath = path10.join(p, trimmed + ext);
37797
+ try {
37798
+ const fs31 = require("fs");
37799
+ if (fs31.existsSync(fullPath)) {
37800
+ const stat2 = fs31.statSync(fullPath);
37801
+ if (stat2.isFile() && (isWin || stat2.mode & 73)) {
37802
+ return fullPath;
37803
+ }
37804
+ }
37805
+ } catch {
37806
+ }
37807
+ }
37808
+ }
37809
+ return isWin ? `${trimmed}.cmd` : trimmed;
37810
+ }
37811
+ function isScriptBinary(binaryPath) {
37812
+ if (!path10.isAbsolute(binaryPath)) return false;
37813
+ try {
37814
+ const fs31 = require("fs");
37815
+ const resolved = fs31.realpathSync(binaryPath);
37816
+ const head = Buffer.alloc(8);
37817
+ const fd = fs31.openSync(resolved, "r");
37818
+ fs31.readSync(fd, head, 0, 8, 0);
37819
+ fs31.closeSync(fd);
37820
+ let i = 0;
37821
+ if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
37822
+ return head[i] === 35 && head[i + 1] === 33;
37823
+ } catch {
37824
+ return false;
37825
+ }
37826
+ }
37827
+ function looksLikeMachOOrElf(filePath) {
37828
+ if (!path10.isAbsolute(filePath)) return false;
37829
+ try {
37830
+ const fs31 = require("fs");
37831
+ const resolved = fs31.realpathSync(filePath);
37832
+ const buf = Buffer.alloc(8);
37833
+ const fd = fs31.openSync(resolved, "r");
37834
+ fs31.readSync(fd, buf, 0, 8, 0);
37835
+ fs31.closeSync(fd);
37836
+ let i = 0;
37837
+ if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
37838
+ const b = buf.subarray(i);
37839
+ if (b.length < 4) return false;
37840
+ if (b[0] === 127 && b[1] === 69 && b[2] === 76 && b[3] === 70) return true;
37841
+ const le = b.readUInt32LE(0);
37842
+ const be = b.readUInt32BE(0);
37843
+ const magics = [4277009102, 4277009103, 3405691582, 3199925962];
37844
+ return magics.some((m) => m === le || m === be);
37845
+ } catch {
37846
+ return false;
37847
+ }
37848
+ }
37849
+ function shSingleQuote(arg) {
37850
+ if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
37851
+ if (os52.platform() === "win32") {
37852
+ return `"${arg.replace(/"/g, '""')}"`;
37853
+ }
37854
+ return `'${arg.replace(/'/g, `'\\''`)}'`;
37855
+ }
37856
+ function estimatePromptDisplayLines(text, cols = 80) {
37857
+ const normalized = String(text || "").replace(/\r/g, "");
37858
+ if (!normalized) return 1;
37859
+ return normalized.split("\n").reduce((sum, line) => sum + Math.max(1, Math.ceil(Math.max(1, line.length) / cols)), 0);
37860
+ }
37861
+ function extractPromptRetrySnippet(text) {
37862
+ const lines = String(text || "").replace(/\r/g, "").split("\n").map((line) => line.trim()).filter(Boolean);
37863
+ const candidate = lines[lines.length - 1] || lines[0] || "";
37864
+ return candidate.slice(-120);
37865
+ }
37866
+ function normalizePromptText(text) {
37867
+ return String(text || "").replace(/\s+/g, " ").trim();
37868
+ }
37869
+ function compactPromptText(text) {
37870
+ return String(text || "").replace(/\s+/g, "").trim();
37871
+ }
37872
+ function promptLikelyVisible(screenText, promptSnippet) {
37873
+ const snippet = normalizePromptText(promptSnippet);
37874
+ if (!snippet) return false;
37875
+ const normalizedScreen = normalizePromptText(screenText);
37876
+ if (normalizedScreen.includes(snippet)) return true;
37877
+ const compactScreen = compactPromptText(screenText);
37878
+ const compactSnippet = compactPromptText(promptSnippet);
37879
+ if (compactSnippet && compactScreen.includes(compactSnippet)) return true;
37880
+ const tokens = snippet.split(/[^A-Za-z0-9_.:/-]+/).map((token) => token.trim()).filter((token) => token.length >= 4);
37881
+ if (tokens.length === 0) return false;
37882
+ const required2 = Math.min(tokens.length, 3);
37883
+ const matched = tokens.filter(
37884
+ (token) => normalizedScreen.includes(token) || compactScreen.includes(compactPromptText(token))
37885
+ ).length;
37886
+ return matched >= required2;
37887
+ }
37888
+ function normalizeScreenSnapshot(text) {
37889
+ return sanitizeTerminalText(String(text || "")).replace(/\s+/g, " ").trim();
37890
+ }
37891
+ function parsePatternEntry(x) {
37892
+ if (x instanceof RegExp) return x;
37893
+ if (x && typeof x === "object" && typeof x.source === "string") {
37894
+ try {
37895
+ const s = x;
37896
+ return new RegExp(s.source, s.flags || "");
37897
+ } catch {
37898
+ return null;
37899
+ }
37900
+ }
37901
+ return null;
37902
+ }
37903
+ function coercePatternArray(raw) {
37904
+ if (!Array.isArray(raw)) return [];
37905
+ return raw.map(parsePatternEntry).filter((r) => r != null);
37906
+ }
37907
+ function normalizeCliProviderForRuntime(raw) {
37908
+ const patterns = raw && typeof raw === "object" ? raw.patterns : void 0;
37909
+ return {
37910
+ patterns: {
37911
+ approval: coercePatternArray(
37912
+ patterns && typeof patterns === "object" ? patterns.approval : void 0
37913
+ )
37914
+ }
37915
+ };
37916
+ }
37917
+ var os52;
37918
+ var path10;
37919
+ var TerminalTranscriptAccumulator;
37920
+ var buildCliSpawnEnv;
37921
+ var init_provider_cli_shared = __esm2({
37922
+ "src/cli-adapters/provider-cli-shared.ts"() {
37923
+ "use strict";
37924
+ os52 = __toESM2(require("os"));
37925
+ path10 = __toESM2(require("path"));
37926
+ init_spawn_env();
37927
+ TerminalTranscriptAccumulator = class {
37928
+ lines = [[]];
37929
+ row = 0;
37930
+ col = 0;
37931
+ savedCursor = null;
37932
+ pendingEscape = "";
37933
+ append(data) {
37934
+ const input = this.pendingEscape + String(data || "");
37935
+ this.pendingEscape = "";
37936
+ for (let i = 0; i < input.length; i += 1) {
37937
+ let ch = input[i];
37938
+ if (ch === "\x1B") {
37939
+ const consumed = this.consumeEscape(input.slice(i));
37940
+ if (consumed === 0) {
37941
+ this.pendingEscape = input.slice(i);
37942
+ break;
37943
+ }
37944
+ i += consumed - 1;
37945
+ continue;
37946
+ }
37947
+ const cp = input.codePointAt(i);
37948
+ if (cp && cp > 65535) {
37949
+ ch = String.fromCodePoint(cp);
37950
+ i += 1;
37951
+ }
37952
+ this.writeControlOrChar(ch);
37953
+ }
37954
+ return this.getText();
37955
+ }
37956
+ reset() {
37957
+ this.lines = [[]];
37958
+ this.row = 0;
37959
+ this.col = 0;
37960
+ this.savedCursor = null;
37961
+ this.pendingEscape = "";
37962
+ }
37963
+ getText() {
37964
+ return this.lines.map((line) => line.join("").replace(/[ \t]+$/g, "")).join("\n");
37965
+ }
37966
+ ensureRow(row = this.row) {
37967
+ while (this.lines.length <= row) this.lines.push([]);
37968
+ }
37969
+ writeControlOrChar(ch) {
37970
+ if (ch === "\r") {
37971
+ this.col = 0;
37972
+ return;
37973
+ }
37974
+ if (ch === "\n") {
37975
+ this.row += 1;
37976
+ this.col = 0;
37977
+ this.ensureRow();
37978
+ return;
37979
+ }
37980
+ if (ch === "\b") {
37981
+ this.col = Math.max(0, this.col - 1);
37982
+ return;
37983
+ }
37984
+ if (ch < " " || ch === "\x7F") return;
37985
+ this.ensureRow();
37986
+ const line = this.lines[this.row];
37987
+ if (isCombiningMark(ch) && this.col > 0) {
37988
+ line[this.col - 1] = `${line[this.col - 1] || ""}${ch}`;
37989
+ return;
37990
+ }
37991
+ while (line.length < this.col) line.push(" ");
37992
+ const wide = isWideCodePoint(ch);
37993
+ line[this.col] = ch;
37994
+ if (wide) line[this.col + 1] = "";
37995
+ this.col += wide ? 2 : 1;
37996
+ }
37997
+ consumeEscape(seq) {
37998
+ if (seq.length < 2) return 0;
37999
+ const next = seq[1];
38000
+ if (next === "7") {
38001
+ this.savedCursor = { row: this.row, col: this.col };
38002
+ return 2;
38003
+ }
38004
+ if (next === "8") {
38005
+ if (this.savedCursor) {
38006
+ this.row = this.savedCursor.row;
38007
+ this.col = this.savedCursor.col;
38008
+ this.ensureRow();
38009
+ }
38010
+ return 2;
38011
+ }
38012
+ if (next === "]") {
38013
+ const bel = seq.indexOf("\x07", 2);
38014
+ const st = seq.indexOf("\x1B\\", 2);
38015
+ const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
38016
+ return end;
38017
+ }
38018
+ if (next === "[") {
38019
+ const match = seq.match(/^\x1B\[([0-?]*)([ -/]*)([@-~])/);
38020
+ if (!match) return seq.length < 32 ? 0 : 1;
38021
+ this.applyCsi(match[1] || "", match[3]);
38022
+ return match[0].length;
38023
+ }
38024
+ if (/[P^_X]/.test(next)) {
38025
+ const bel = seq.indexOf("\x07", 2);
38026
+ const st = seq.indexOf("\x1B\\", 2);
38027
+ const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
38028
+ return end;
38029
+ }
38030
+ return 2;
38031
+ }
38032
+ applyCsi(params, final) {
38033
+ const count = parseCount(params);
38034
+ this.ensureRow();
38035
+ if (final === "A") this.row = Math.max(0, this.row - count);
38036
+ else if (final === "B") this.row += count;
38037
+ else if (final === "C") {
38038
+ const line = this.lines[this.row];
38039
+ for (let c = this.col; c < this.col + count; c += 1) {
38040
+ if (line[c] === void 0) line[c] = " ";
38041
+ }
38042
+ this.col += count;
38043
+ } else if (final === "D") this.col = Math.max(0, this.col - count);
38044
+ else if (final === "G") this.col = Math.max(0, count - 1);
38045
+ else if (final === "H" || final === "f") {
38046
+ const parts = String(params || "").split(";");
38047
+ this.row = Math.max(0, (Number(parts[0] || 1) || 1) - 1);
38048
+ this.col = Math.max(0, (Number(parts[1] || 1) || 1) - 1);
38049
+ } else if (final === "J") {
38050
+ const mode = Number(params || 0) || 0;
38051
+ if (mode === 2 || mode === 3) {
38052
+ this.lines = [[]];
38053
+ this.row = 0;
38054
+ this.col = 0;
38055
+ } else if (mode === 0) {
38056
+ this.lines[this.row] = this.lines[this.row].slice(0, this.col);
38057
+ this.lines.splice(this.row + 1);
38058
+ } else if (mode === 1) {
38059
+ for (let r = 0; r < this.row; r += 1) this.lines[r] = [];
38060
+ const line = this.lines[this.row];
38061
+ for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
38062
+ }
38063
+ } else if (final === "K") {
38064
+ const mode = Number(params || 0) || 0;
38065
+ const line = this.lines[this.row];
38066
+ if (mode === 2) this.lines[this.row] = [];
38067
+ else if (mode === 1) {
38068
+ for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
38069
+ } else {
38070
+ this.lines[this.row] = line.slice(0, this.col);
38071
+ }
38072
+ } else if (final === "s") {
38073
+ this.savedCursor = { row: this.row, col: this.col };
38074
+ } else if (final === "u") {
38075
+ if (this.savedCursor) {
38076
+ this.row = this.savedCursor.row;
38077
+ this.col = this.savedCursor.col;
38078
+ }
38079
+ }
38080
+ this.ensureRow();
38081
+ }
38082
+ };
38083
+ buildCliSpawnEnv = import_session_host_core22.sanitizeSpawnEnv;
38084
+ }
38085
+ });
37633
38086
  function parseVersion(raw) {
37634
38087
  const match = raw.match(/v?(\d+\.\d+(?:\.\d+)?(?:-[a-zA-Z0-9.]+)?)/);
37635
38088
  return match ? match[1] : raw.split("\n")[0].slice(0, 100);
@@ -37641,22 +38094,31 @@ Next step: ${nextStep}`;
37641
38094
  function expandHome(value) {
37642
38095
  const trimmed = value.trim();
37643
38096
  if (!trimmed.startsWith("~")) return trimmed;
37644
- return path10.join(os52.homedir(), trimmed.slice(1));
38097
+ return path11.join(os6.homedir(), trimmed.slice(1));
37645
38098
  }
37646
38099
  function isExplicitCommandPath(command) {
37647
38100
  const trimmed = command.trim();
37648
- return path10.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
38101
+ return path11.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
37649
38102
  }
37650
38103
  function resolveCommandPath(command) {
37651
38104
  const trimmed = command.trim();
37652
38105
  if (!trimmed) return null;
37653
38106
  if (isExplicitCommandPath(trimmed)) {
37654
38107
  const expanded = expandHome(trimmed);
37655
- const candidate = path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
38108
+ const candidate = path11.isAbsolute(expanded) ? expanded : path11.resolve(expanded);
37656
38109
  return (0, import_fs9.existsSync)(candidate) ? candidate : null;
37657
38110
  }
37658
38111
  return null;
37659
38112
  }
38113
+ async function resolveDetectionPath(command, whichCmd) {
38114
+ const explicitPath = resolveCommandPath(command);
38115
+ if (explicitPath) return explicitPath;
38116
+ const whichResult = await execAsync(`${whichCmd} ${shellQuote(command)}`);
38117
+ if (whichResult) return whichResult.split("\n")[0];
38118
+ const resolved = findBinary(command);
38119
+ if (path11.isAbsolute(resolved) && (0, import_fs9.existsSync)(resolved)) return resolved;
38120
+ return null;
38121
+ }
37660
38122
  function execAsync(cmd, timeoutMs = 5e3) {
37661
38123
  return new Promise((resolve24) => {
37662
38124
  const child = (0, import_child_process.exec)(cmd, {
@@ -37674,17 +38136,15 @@ Next step: ${nextStep}`;
37674
38136
  });
37675
38137
  }
37676
38138
  async function detectCLIs(providerLoader, options) {
37677
- const platform10 = os52.platform();
38139
+ const platform10 = os6.platform();
37678
38140
  const whichCmd = platform10 === "win32" ? "where" : "which";
37679
38141
  const includeVersion = options?.includeVersion !== false;
37680
38142
  const cliList = providerLoader ? providerLoader.getCliDetectionList() : [];
37681
38143
  const results = await Promise.all(
37682
38144
  cliList.map(async (cli) => {
37683
38145
  try {
37684
- const explicitPath = resolveCommandPath(cli.command);
37685
- const pathResult = explicitPath || await execAsync(`${whichCmd} ${shellQuote(cli.command)}`);
37686
- if (!pathResult) return { ...cli, installed: false };
37687
- const firstPath = explicitPath || pathResult.split("\n")[0];
38146
+ const firstPath = await resolveDetectionPath(cli.command, whichCmd);
38147
+ if (!firstPath) return { ...cli, installed: false };
37688
38148
  let version2;
37689
38149
  if (includeVersion) {
37690
38150
  const versionCommands = [
@@ -37718,13 +38178,11 @@ Next step: ${nextStep}`;
37718
38178
  const cliList = providerLoader.getCliDetectionList();
37719
38179
  const target = cliList.find((c) => c.id === resolvedId);
37720
38180
  if (target) {
37721
- const platform10 = os52.platform();
38181
+ const platform10 = os6.platform();
37722
38182
  const whichCmd = platform10 === "win32" ? "where" : "which";
37723
38183
  try {
37724
- const explicitPath = resolveCommandPath(target.command);
37725
- const pathResult = explicitPath || await execAsync(`${whichCmd} ${shellQuote(target.command)}`);
37726
- if (!pathResult) return null;
37727
- const firstPath = explicitPath || pathResult.split("\n")[0];
38184
+ const firstPath = await resolveDetectionPath(target.command, whichCmd);
38185
+ if (!firstPath) return null;
37728
38186
  let version2;
37729
38187
  if (options?.includeVersion !== false) {
37730
38188
  const versionCommands = [
@@ -37754,16 +38212,17 @@ Next step: ${nextStep}`;
37754
38212
  return all.find((c) => c.id === resolvedId && c.installed) || null;
37755
38213
  }
37756
38214
  var import_child_process;
37757
- var os52;
37758
- var path10;
38215
+ var os6;
38216
+ var path11;
37759
38217
  var import_fs9;
37760
38218
  var init_cli_detector = __esm2({
37761
38219
  "src/detection/cli-detector.ts"() {
37762
38220
  "use strict";
37763
38221
  import_child_process = require("child_process");
37764
- os52 = __toESM2(require("os"));
37765
- path10 = __toESM2(require("path"));
38222
+ os6 = __toESM2(require("os"));
38223
+ path11 = __toESM2(require("path"));
37766
38224
  import_fs9 = require("fs");
38225
+ init_provider_cli_shared();
37767
38226
  }
37768
38227
  });
37769
38228
  function readSettings(state) {
@@ -38660,7 +39119,7 @@ Next step: ${nextStep}`;
38660
39119
  }
38661
39120
  const remoteCandidates = [];
38662
39121
  for (const idle of remoteSessions) {
38663
- const node = mesh.nodes.find((n) => n.id === idle.nodeId);
39122
+ const node = mesh.nodes.find((n) => meshNodeIdMatches(n, idle.nodeId));
38664
39123
  if (node) {
38665
39124
  remoteIdleSessionsChecked += 1;
38666
39125
  remoteCandidates.push({ nodeId: idle.nodeId, sessionId: idle.sessionId, providerType: idle.providerType, origin: "remote", node });
@@ -39475,6 +39934,21 @@ Next step: ${nextStep}`;
39475
39934
  }
39476
39935
  }
39477
39936
  }
39937
+ for (const mesh of listMeshes()) {
39938
+ const selfIds = resolveCoordinatorSelfIds(mesh, drainDaemonIds);
39939
+ if (!daemonHostsMesh(mesh, selfIds)) continue;
39940
+ if (store) {
39941
+ try {
39942
+ if (store.pendingQueueTaskCount(mesh.id) === 0) continue;
39943
+ } catch {
39944
+ }
39945
+ }
39946
+ try {
39947
+ await triggerMeshQueue(components, mesh.id);
39948
+ } catch (e) {
39949
+ LOG2.warn("MeshReconcile", `Pending-claim recovery trigger failed for mesh ${mesh.id}: ${e?.message || e}`);
39950
+ }
39951
+ }
39478
39952
  const coordinators = findLiveCoordinators(components);
39479
39953
  if (coordinators.length === 0) {
39480
39954
  return;
@@ -40355,16 +40829,16 @@ Next step: ${nextStep}`;
40355
40829
  sourcesProviding: () => sourcesProviding
40356
40830
  });
40357
40831
  function adhdevDir() {
40358
- return path15.join(os10.homedir(), ".adhdev");
40832
+ return path16.join(os11.homedir(), ".adhdev");
40359
40833
  }
40360
40834
  function externalRoot() {
40361
- return path15.join(adhdevDir(), "external");
40835
+ return path16.join(adhdevDir(), "external");
40362
40836
  }
40363
40837
  function sourcesFilePath() {
40364
- return path15.join(adhdevDir(), SOURCES_FILENAME);
40838
+ return path16.join(adhdevDir(), SOURCES_FILENAME);
40365
40839
  }
40366
40840
  function activeFilePath() {
40367
- return path15.join(adhdevDir(), ACTIVE_FILENAME);
40841
+ return path16.join(adhdevDir(), ACTIVE_FILENAME);
40368
40842
  }
40369
40843
  function ensureAdhdevDir() {
40370
40844
  const d = adhdevDir();
@@ -40431,7 +40905,7 @@ Next step: ${nextStep}`;
40431
40905
  for (const sourceEntry of entries) {
40432
40906
  if (!sourceEntry.isDirectory()) continue;
40433
40907
  const sourceName = sourceEntry.name;
40434
- const sourceDir = path15.join(root, sourceName);
40908
+ const sourceDir = path16.join(root, sourceName);
40435
40909
  const providers = {};
40436
40910
  let categoryEntries;
40437
40911
  try {
@@ -40442,7 +40916,7 @@ Next step: ${nextStep}`;
40442
40916
  for (const categoryEntry of categoryEntries) {
40443
40917
  if (!categoryEntry.isDirectory()) continue;
40444
40918
  const category = categoryEntry.name;
40445
- const categoryDir = path15.join(sourceDir, category);
40919
+ const categoryDir = path16.join(sourceDir, category);
40446
40920
  let typeEntries;
40447
40921
  try {
40448
40922
  typeEntries = fs8.readdirSync(categoryDir, { withFileTypes: true });
@@ -40452,9 +40926,9 @@ Next step: ${nextStep}`;
40452
40926
  const types = [];
40453
40927
  for (const typeEntry of typeEntries) {
40454
40928
  if (!typeEntry.isDirectory()) continue;
40455
- const typeDir = path15.join(categoryDir, typeEntry.name);
40456
- const hasV1 = fs8.existsSync(path15.join(typeDir, "provider.v1.json"));
40457
- const hasV0 = fs8.existsSync(path15.join(typeDir, "provider.json"));
40929
+ const typeDir = path16.join(categoryDir, typeEntry.name);
40930
+ const hasV1 = fs8.existsSync(path16.join(typeDir, "provider.v1.json"));
40931
+ const hasV0 = fs8.existsSync(path16.join(typeDir, "provider.json"));
40458
40932
  if (hasV1 || hasV0) types.push(typeEntry.name);
40459
40933
  }
40460
40934
  if (types.length > 0) providers[category] = types;
@@ -40478,16 +40952,16 @@ Next step: ${nextStep}`;
40478
40952
  return { source: candidates[0], ambiguous: true, candidates };
40479
40953
  }
40480
40954
  var fs8;
40481
- var os10;
40482
- var path15;
40955
+ var os11;
40956
+ var path16;
40483
40957
  var SOURCES_FILENAME;
40484
40958
  var ACTIVE_FILENAME;
40485
40959
  var init_external_sources = __esm2({
40486
40960
  "src/providers/external-sources.ts"() {
40487
40961
  "use strict";
40488
40962
  fs8 = __toESM2(require("fs"));
40489
- os10 = __toESM2(require("os"));
40490
- path15 = __toESM2(require("path"));
40963
+ os11 = __toESM2(require("os"));
40964
+ path16 = __toESM2(require("path"));
40491
40965
  SOURCES_FILENAME = "providers-sources.json";
40492
40966
  ACTIVE_FILENAME = "providers-active.json";
40493
40967
  }
@@ -40609,21 +41083,21 @@ Next step: ${nextStep}`;
40609
41083
  function getTerminalBackendRuntimeStatus() {
40610
41084
  return { backend: "ghostty-vt" };
40611
41085
  }
40612
- var import_session_host_core22;
41086
+ var import_session_host_core32;
40613
41087
  var DEFAULT_SCROLLBACK;
40614
41088
  var TerminalScreen;
40615
41089
  var init_terminal_screen = __esm2({
40616
41090
  "src/cli-adapters/terminal-screen.ts"() {
40617
41091
  "use strict";
40618
41092
  init_ghostty_vt_backend();
40619
- import_session_host_core22 = require_dist();
41093
+ import_session_host_core32 = require_dist();
40620
41094
  DEFAULT_SCROLLBACK = 2e3;
40621
41095
  TerminalScreen = class {
40622
41096
  backendKind = "ghostty-vt";
40623
41097
  rows;
40624
41098
  cols;
40625
41099
  terminal;
40626
- constructor(rows = import_session_host_core22.DEFAULT_SESSION_HOST_ROWS, cols = import_session_host_core22.DEFAULT_SESSION_HOST_COLS) {
41100
+ constructor(rows = import_session_host_core32.DEFAULT_SESSION_HOST_ROWS, cols = import_session_host_core32.DEFAULT_SESSION_HOST_COLS) {
40627
41101
  this.rows = Math.max(1, rows | 0);
40628
41102
  this.cols = Math.max(1, cols | 0);
40629
41103
  this.terminal = this.createBackend();
@@ -40665,18 +41139,30 @@ Next step: ${nextStep}`;
40665
41139
  };
40666
41140
  }
40667
41141
  });
40668
- var import_session_host_core32;
40669
- var init_spawn_env = __esm2({
40670
- "src/cli-adapters/spawn-env.ts"() {
40671
- "use strict";
40672
- import_session_host_core32 = require_dist();
41142
+ function resolveWin32GlobalBin(trimmed) {
41143
+ if (path17.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\")) {
41144
+ return null;
40673
41145
  }
40674
- });
41146
+ const extraDirs = [];
41147
+ if (process.env.APPDATA) extraDirs.push(path17.join(process.env.APPDATA, "npm"));
41148
+ try {
41149
+ extraDirs.push(path17.dirname(process.execPath));
41150
+ } catch {
41151
+ }
41152
+ for (const dir of extraDirs) {
41153
+ if (!dir) continue;
41154
+ for (const ext of WIN_EXEC_EXT) {
41155
+ const full = path17.join(dir, trimmed + ext);
41156
+ if ((0, import_fs13.existsSync)(full)) return full;
41157
+ }
41158
+ }
41159
+ return null;
41160
+ }
40675
41161
  function resolveWin32Executable(command) {
40676
41162
  if (process.platform !== "win32") return command;
40677
41163
  const trimmed = (command || "").trim();
40678
41164
  if (!trimmed) return command;
40679
- if (path16.isAbsolute(trimmed) && (0, import_fs13.existsSync)(trimmed)) return trimmed;
41165
+ if (path17.isAbsolute(trimmed) && (0, import_fs13.existsSync)(trimmed)) return trimmed;
40680
41166
  try {
40681
41167
  const out = (0, import_child_process4.execFileSync)("where", [trimmed], {
40682
41168
  encoding: "utf8",
@@ -40684,24 +41170,28 @@ Next step: ${nextStep}`;
40684
41170
  }).trim();
40685
41171
  if (out) {
40686
41172
  const matches = out.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
40687
- const direct = matches.find((m) => DIRECT_EXEC_EXT.has(path16.extname(m).toLowerCase()));
41173
+ const direct = matches.find((m) => DIRECT_EXEC_EXT.has(path17.extname(m).toLowerCase()));
40688
41174
  return direct || matches[0] || command;
40689
41175
  }
40690
41176
  } catch {
40691
41177
  }
41178
+ const globalBin = resolveWin32GlobalBin(trimmed);
41179
+ if (globalBin) return globalBin;
40692
41180
  return command;
40693
41181
  }
40694
41182
  var import_child_process4;
40695
41183
  var import_fs13;
40696
- var path16;
41184
+ var path17;
40697
41185
  var DIRECT_EXEC_EXT;
41186
+ var WIN_EXEC_EXT;
40698
41187
  var init_resolve_executable = __esm2({
40699
41188
  "src/cli-adapters/resolve-executable.ts"() {
40700
41189
  "use strict";
40701
41190
  import_child_process4 = require("child_process");
40702
41191
  import_fs13 = require("fs");
40703
- path16 = __toESM2(require("path"));
41192
+ path17 = __toESM2(require("path"));
40704
41193
  DIRECT_EXEC_EXT = /* @__PURE__ */ new Set([".exe", ".com"]);
41194
+ WIN_EXEC_EXT = [".exe", ".com", ".cmd", ".bat"];
40705
41195
  }
40706
41196
  });
40707
41197
  var pty_transport_exports = {};
@@ -40712,20 +41202,20 @@ Next step: ${nextStep}`;
40712
41202
  if (cachedPty !== void 0) return cachedPty;
40713
41203
  try {
40714
41204
  cachedPty = require("node-pty");
40715
- (0, import_session_host_core32.ensureNodePtySpawnHelperPermissions)();
41205
+ (0, import_session_host_core22.ensureNodePtySpawnHelperPermissions)();
40716
41206
  } catch {
40717
41207
  cachedPty = null;
40718
41208
  }
40719
41209
  return cachedPty;
40720
41210
  }
40721
- var os11;
41211
+ var os12;
40722
41212
  var cachedPty;
40723
41213
  var NodePtyRuntimeTransport;
40724
41214
  var NodePtyTransportFactory;
40725
41215
  var init_pty_transport = __esm2({
40726
41216
  "src/cli-adapters/pty-transport.ts"() {
40727
41217
  "use strict";
40728
- os11 = __toESM2(require("os"));
41218
+ os12 = __toESM2(require("os"));
40729
41219
  init_spawn_env();
40730
41220
  init_resolve_executable();
40731
41221
  NodePtyRuntimeTransport = class {
@@ -40765,9 +41255,9 @@ Next step: ${nextStep}`;
40765
41255
  try {
40766
41256
  const fs31 = require("fs");
40767
41257
  const stat2 = fs31.statSync(cwd);
40768
- if (!stat2.isDirectory()) cwd = os11.homedir();
41258
+ if (!stat2.isDirectory()) cwd = os12.homedir();
40769
41259
  } catch {
40770
- cwd = os11.homedir();
41260
+ cwd = os12.homedir();
40771
41261
  }
40772
41262
  }
40773
41263
  const handle = pty.spawn(resolveWin32Executable(command), args, {
@@ -40782,397 +41272,6 @@ Next step: ${nextStep}`;
40782
41272
  };
40783
41273
  }
40784
41274
  });
40785
- function stripAnsi(str) {
40786
- return str.replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
40787
- }
40788
- function parseCount(params, fallback = 1) {
40789
- const first = Number(String(params || "").split(";")[0] || fallback);
40790
- return Math.max(1, Number.isFinite(first) ? first : fallback);
40791
- }
40792
- function isCombiningMark(ch) {
40793
- return /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/.test(ch);
40794
- }
40795
- function isWideCodePoint(ch) {
40796
- const cp = ch.codePointAt(0) || 0;
40797
- return cp >= 4352 && (cp <= 4447 || cp === 9001 || cp === 9002 || cp >= 11904 && cp <= 42191 && cp !== 12351 || cp >= 44032 && cp <= 55203 || cp >= 63744 && cp <= 64255 || cp >= 65040 && cp <= 65049 || cp >= 65072 && cp <= 65135 || cp >= 65280 && cp <= 65376 || cp >= 65504 && cp <= 65510 || cp >= 127744 && cp <= 129791);
40798
- }
40799
- function stripTerminalNoise(str) {
40800
- return String(str || "").replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]/g, "").replace(/\r+/g, "\n").replace(/[ \t]+\n/g, "\n").replace(/\n{4,}/g, "\n\n\n");
40801
- }
40802
- function sanitizeTerminalText(str) {
40803
- const accumulator = new TerminalTranscriptAccumulator();
40804
- return stripTerminalNoise(stripAnsi(accumulator.append(str)));
40805
- }
40806
- function listCliScriptNames(scripts) {
40807
- if (!scripts) return [];
40808
- return Object.entries(scripts).filter(([, fn]) => typeof fn === "function").map(([name]) => name);
40809
- }
40810
- function splitCliScreenLines(text) {
40811
- return String(text || "").replace(/\u0007/g, "").replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").map((line) => line.replace(/\s+$/, ""));
40812
- }
40813
- function isPromptLikeCliLine(line) {
40814
- const trimmed = String(line || "").trim();
40815
- if (!trimmed) return false;
40816
- return /^[❯›>]\s*(?:$|\S.*)$/.test(trimmed);
40817
- }
40818
- function buildCliScreenSnapshot(text) {
40819
- const normalizedText = String(text || "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
40820
- const rawLines = splitCliScreenLines(normalizedText);
40821
- const lines = rawLines.map((line, index, arr) => {
40822
- const trimmed = String(line || "").trim();
40823
- return {
40824
- index,
40825
- fromTop: index,
40826
- fromBottom: arr.length - index - 1,
40827
- text: line,
40828
- trimmed,
40829
- isEmpty: trimmed.length === 0
40830
- };
40831
- });
40832
- const nonEmptyLines = lines.filter((line) => !line.isEmpty);
40833
- const firstNonEmptyLine = nonEmptyLines[0] ?? null;
40834
- const lastNonEmptyLine = nonEmptyLines[nonEmptyLines.length - 1] ?? null;
40835
- let promptLineIndex = -1;
40836
- for (let i = lines.length - 1; i >= 0; i -= 1) {
40837
- if (isPromptLikeCliLine(lines[i].text)) {
40838
- promptLineIndex = i;
40839
- break;
40840
- }
40841
- }
40842
- return {
40843
- text: normalizedText,
40844
- lineCount: lines.length,
40845
- lines,
40846
- nonEmptyLines,
40847
- firstNonEmptyLineIndex: firstNonEmptyLine?.index ?? -1,
40848
- lastNonEmptyLineIndex: lastNonEmptyLine?.index ?? -1,
40849
- firstNonEmptyLine,
40850
- lastNonEmptyLine,
40851
- promptLineIndex,
40852
- promptLine: promptLineIndex >= 0 ? lines[promptLineIndex] : null,
40853
- linesAbovePrompt: promptLineIndex >= 0 ? lines.slice(0, promptLineIndex) : [...lines],
40854
- linesBelowPrompt: promptLineIndex >= 0 ? lines.slice(promptLineIndex + 1) : []
40855
- };
40856
- }
40857
- function findBinary(name) {
40858
- const trimmed = String(name || "").trim();
40859
- if (!trimmed) return trimmed;
40860
- const expanded = trimmed.startsWith("~") ? path17.join(os12.homedir(), trimmed.slice(1)) : trimmed;
40861
- if (path17.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
40862
- return path17.isAbsolute(expanded) ? expanded : path17.resolve(expanded);
40863
- }
40864
- const isWin = os12.platform() === "win32";
40865
- const paths = (process.env.PATH || "").split(path17.delimiter);
40866
- const extraDirs = [];
40867
- if (isWin) {
40868
- if (process.env.APPDATA) extraDirs.push(path17.join(process.env.APPDATA, "npm"));
40869
- try {
40870
- extraDirs.push(path17.dirname(process.execPath));
40871
- } catch {
40872
- }
40873
- } else {
40874
- extraDirs.push(path17.join(os12.homedir(), ".npm-global", "bin"));
40875
- extraDirs.push("/usr/local/bin", "/opt/homebrew/bin");
40876
- try {
40877
- extraDirs.push(path17.dirname(process.execPath));
40878
- } catch {
40879
- }
40880
- }
40881
- const searchDirs = [...paths, ...extraDirs];
40882
- const exes = isWin ? [".exe", ".cmd", ".bat", ""] : [""];
40883
- for (const p of searchDirs) {
40884
- if (!p) continue;
40885
- for (const ext of exes) {
40886
- const fullPath = path17.join(p, trimmed + ext);
40887
- try {
40888
- const fs31 = require("fs");
40889
- if (fs31.existsSync(fullPath)) {
40890
- const stat2 = fs31.statSync(fullPath);
40891
- if (stat2.isFile() && (isWin || stat2.mode & 73)) {
40892
- return fullPath;
40893
- }
40894
- }
40895
- } catch {
40896
- }
40897
- }
40898
- }
40899
- return isWin ? `${trimmed}.cmd` : trimmed;
40900
- }
40901
- function isScriptBinary(binaryPath) {
40902
- if (!path17.isAbsolute(binaryPath)) return false;
40903
- try {
40904
- const fs31 = require("fs");
40905
- const resolved = fs31.realpathSync(binaryPath);
40906
- const head = Buffer.alloc(8);
40907
- const fd = fs31.openSync(resolved, "r");
40908
- fs31.readSync(fd, head, 0, 8, 0);
40909
- fs31.closeSync(fd);
40910
- let i = 0;
40911
- if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
40912
- return head[i] === 35 && head[i + 1] === 33;
40913
- } catch {
40914
- return false;
40915
- }
40916
- }
40917
- function looksLikeMachOOrElf(filePath) {
40918
- if (!path17.isAbsolute(filePath)) return false;
40919
- try {
40920
- const fs31 = require("fs");
40921
- const resolved = fs31.realpathSync(filePath);
40922
- const buf = Buffer.alloc(8);
40923
- const fd = fs31.openSync(resolved, "r");
40924
- fs31.readSync(fd, buf, 0, 8, 0);
40925
- fs31.closeSync(fd);
40926
- let i = 0;
40927
- if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
40928
- const b = buf.subarray(i);
40929
- if (b.length < 4) return false;
40930
- if (b[0] === 127 && b[1] === 69 && b[2] === 76 && b[3] === 70) return true;
40931
- const le = b.readUInt32LE(0);
40932
- const be = b.readUInt32BE(0);
40933
- const magics = [4277009102, 4277009103, 3405691582, 3199925962];
40934
- return magics.some((m) => m === le || m === be);
40935
- } catch {
40936
- return false;
40937
- }
40938
- }
40939
- function shSingleQuote(arg) {
40940
- if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
40941
- if (os12.platform() === "win32") {
40942
- return `"${arg.replace(/"/g, '""')}"`;
40943
- }
40944
- return `'${arg.replace(/'/g, `'\\''`)}'`;
40945
- }
40946
- function estimatePromptDisplayLines(text, cols = 80) {
40947
- const normalized = String(text || "").replace(/\r/g, "");
40948
- if (!normalized) return 1;
40949
- return normalized.split("\n").reduce((sum, line) => sum + Math.max(1, Math.ceil(Math.max(1, line.length) / cols)), 0);
40950
- }
40951
- function extractPromptRetrySnippet(text) {
40952
- const lines = String(text || "").replace(/\r/g, "").split("\n").map((line) => line.trim()).filter(Boolean);
40953
- const candidate = lines[lines.length - 1] || lines[0] || "";
40954
- return candidate.slice(-120);
40955
- }
40956
- function normalizePromptText(text) {
40957
- return String(text || "").replace(/\s+/g, " ").trim();
40958
- }
40959
- function compactPromptText(text) {
40960
- return String(text || "").replace(/\s+/g, "").trim();
40961
- }
40962
- function promptLikelyVisible(screenText, promptSnippet) {
40963
- const snippet = normalizePromptText(promptSnippet);
40964
- if (!snippet) return false;
40965
- const normalizedScreen = normalizePromptText(screenText);
40966
- if (normalizedScreen.includes(snippet)) return true;
40967
- const compactScreen = compactPromptText(screenText);
40968
- const compactSnippet = compactPromptText(promptSnippet);
40969
- if (compactSnippet && compactScreen.includes(compactSnippet)) return true;
40970
- const tokens = snippet.split(/[^A-Za-z0-9_.:/-]+/).map((token) => token.trim()).filter((token) => token.length >= 4);
40971
- if (tokens.length === 0) return false;
40972
- const required2 = Math.min(tokens.length, 3);
40973
- const matched = tokens.filter(
40974
- (token) => normalizedScreen.includes(token) || compactScreen.includes(compactPromptText(token))
40975
- ).length;
40976
- return matched >= required2;
40977
- }
40978
- function normalizeScreenSnapshot(text) {
40979
- return sanitizeTerminalText(String(text || "")).replace(/\s+/g, " ").trim();
40980
- }
40981
- function parsePatternEntry(x) {
40982
- if (x instanceof RegExp) return x;
40983
- if (x && typeof x === "object" && typeof x.source === "string") {
40984
- try {
40985
- const s = x;
40986
- return new RegExp(s.source, s.flags || "");
40987
- } catch {
40988
- return null;
40989
- }
40990
- }
40991
- return null;
40992
- }
40993
- function coercePatternArray(raw) {
40994
- if (!Array.isArray(raw)) return [];
40995
- return raw.map(parsePatternEntry).filter((r) => r != null);
40996
- }
40997
- function normalizeCliProviderForRuntime(raw) {
40998
- const patterns = raw && typeof raw === "object" ? raw.patterns : void 0;
40999
- return {
41000
- patterns: {
41001
- approval: coercePatternArray(
41002
- patterns && typeof patterns === "object" ? patterns.approval : void 0
41003
- )
41004
- }
41005
- };
41006
- }
41007
- var os12;
41008
- var path17;
41009
- var TerminalTranscriptAccumulator;
41010
- var buildCliSpawnEnv;
41011
- var init_provider_cli_shared = __esm2({
41012
- "src/cli-adapters/provider-cli-shared.ts"() {
41013
- "use strict";
41014
- os12 = __toESM2(require("os"));
41015
- path17 = __toESM2(require("path"));
41016
- init_spawn_env();
41017
- TerminalTranscriptAccumulator = class {
41018
- lines = [[]];
41019
- row = 0;
41020
- col = 0;
41021
- savedCursor = null;
41022
- pendingEscape = "";
41023
- append(data) {
41024
- const input = this.pendingEscape + String(data || "");
41025
- this.pendingEscape = "";
41026
- for (let i = 0; i < input.length; i += 1) {
41027
- let ch = input[i];
41028
- if (ch === "\x1B") {
41029
- const consumed = this.consumeEscape(input.slice(i));
41030
- if (consumed === 0) {
41031
- this.pendingEscape = input.slice(i);
41032
- break;
41033
- }
41034
- i += consumed - 1;
41035
- continue;
41036
- }
41037
- const cp = input.codePointAt(i);
41038
- if (cp && cp > 65535) {
41039
- ch = String.fromCodePoint(cp);
41040
- i += 1;
41041
- }
41042
- this.writeControlOrChar(ch);
41043
- }
41044
- return this.getText();
41045
- }
41046
- reset() {
41047
- this.lines = [[]];
41048
- this.row = 0;
41049
- this.col = 0;
41050
- this.savedCursor = null;
41051
- this.pendingEscape = "";
41052
- }
41053
- getText() {
41054
- return this.lines.map((line) => line.join("").replace(/[ \t]+$/g, "")).join("\n");
41055
- }
41056
- ensureRow(row = this.row) {
41057
- while (this.lines.length <= row) this.lines.push([]);
41058
- }
41059
- writeControlOrChar(ch) {
41060
- if (ch === "\r") {
41061
- this.col = 0;
41062
- return;
41063
- }
41064
- if (ch === "\n") {
41065
- this.row += 1;
41066
- this.col = 0;
41067
- this.ensureRow();
41068
- return;
41069
- }
41070
- if (ch === "\b") {
41071
- this.col = Math.max(0, this.col - 1);
41072
- return;
41073
- }
41074
- if (ch < " " || ch === "\x7F") return;
41075
- this.ensureRow();
41076
- const line = this.lines[this.row];
41077
- if (isCombiningMark(ch) && this.col > 0) {
41078
- line[this.col - 1] = `${line[this.col - 1] || ""}${ch}`;
41079
- return;
41080
- }
41081
- while (line.length < this.col) line.push(" ");
41082
- const wide = isWideCodePoint(ch);
41083
- line[this.col] = ch;
41084
- if (wide) line[this.col + 1] = "";
41085
- this.col += wide ? 2 : 1;
41086
- }
41087
- consumeEscape(seq) {
41088
- if (seq.length < 2) return 0;
41089
- const next = seq[1];
41090
- if (next === "7") {
41091
- this.savedCursor = { row: this.row, col: this.col };
41092
- return 2;
41093
- }
41094
- if (next === "8") {
41095
- if (this.savedCursor) {
41096
- this.row = this.savedCursor.row;
41097
- this.col = this.savedCursor.col;
41098
- this.ensureRow();
41099
- }
41100
- return 2;
41101
- }
41102
- if (next === "]") {
41103
- const bel = seq.indexOf("\x07", 2);
41104
- const st = seq.indexOf("\x1B\\", 2);
41105
- const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
41106
- return end;
41107
- }
41108
- if (next === "[") {
41109
- const match = seq.match(/^\x1B\[([0-?]*)([ -/]*)([@-~])/);
41110
- if (!match) return seq.length < 32 ? 0 : 1;
41111
- this.applyCsi(match[1] || "", match[3]);
41112
- return match[0].length;
41113
- }
41114
- if (/[P^_X]/.test(next)) {
41115
- const bel = seq.indexOf("\x07", 2);
41116
- const st = seq.indexOf("\x1B\\", 2);
41117
- const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
41118
- return end;
41119
- }
41120
- return 2;
41121
- }
41122
- applyCsi(params, final) {
41123
- const count = parseCount(params);
41124
- this.ensureRow();
41125
- if (final === "A") this.row = Math.max(0, this.row - count);
41126
- else if (final === "B") this.row += count;
41127
- else if (final === "C") {
41128
- const line = this.lines[this.row];
41129
- for (let c = this.col; c < this.col + count; c += 1) {
41130
- if (line[c] === void 0) line[c] = " ";
41131
- }
41132
- this.col += count;
41133
- } else if (final === "D") this.col = Math.max(0, this.col - count);
41134
- else if (final === "G") this.col = Math.max(0, count - 1);
41135
- else if (final === "H" || final === "f") {
41136
- const parts = String(params || "").split(";");
41137
- this.row = Math.max(0, (Number(parts[0] || 1) || 1) - 1);
41138
- this.col = Math.max(0, (Number(parts[1] || 1) || 1) - 1);
41139
- } else if (final === "J") {
41140
- const mode = Number(params || 0) || 0;
41141
- if (mode === 2 || mode === 3) {
41142
- this.lines = [[]];
41143
- this.row = 0;
41144
- this.col = 0;
41145
- } else if (mode === 0) {
41146
- this.lines[this.row] = this.lines[this.row].slice(0, this.col);
41147
- this.lines.splice(this.row + 1);
41148
- } else if (mode === 1) {
41149
- for (let r = 0; r < this.row; r += 1) this.lines[r] = [];
41150
- const line = this.lines[this.row];
41151
- for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
41152
- }
41153
- } else if (final === "K") {
41154
- const mode = Number(params || 0) || 0;
41155
- const line = this.lines[this.row];
41156
- if (mode === 2) this.lines[this.row] = [];
41157
- else if (mode === 1) {
41158
- for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
41159
- } else {
41160
- this.lines[this.row] = line.slice(0, this.col);
41161
- }
41162
- } else if (final === "s") {
41163
- this.savedCursor = { row: this.row, col: this.col };
41164
- } else if (final === "u") {
41165
- if (this.savedCursor) {
41166
- this.row = this.savedCursor.row;
41167
- this.col = this.savedCursor.col;
41168
- }
41169
- }
41170
- this.ensureRow();
41171
- }
41172
- };
41173
- buildCliSpawnEnv = import_session_host_core32.sanitizeSpawnEnv;
41174
- }
41175
- });
41176
41275
  function compile(re, flags) {
41177
41276
  try {
41178
41277
  return new RegExp(re, flags ?? "");
@@ -47137,14 +47236,14 @@ ${lastSnapshot}`;
47137
47236
  init_git_worktree();
47138
47237
  init_config();
47139
47238
  var fs5 = __toESM2(require("fs"));
47140
- var os6 = __toESM2(require("os"));
47239
+ var os7 = __toESM2(require("os"));
47141
47240
  var path52 = __toESM2(require("path"));
47142
47241
  var import_crypto22 = require("crypto");
47143
47242
  var MAX_WORKSPACES = 50;
47144
47243
  function expandPath(p) {
47145
47244
  const t = (p || "").trim();
47146
47245
  if (!t) return "";
47147
- if (t.startsWith("~")) return path52.join(os6.homedir(), t.slice(1).replace(/^\//, ""));
47246
+ if (t.startsWith("~")) return path52.join(os7.homedir(), t.slice(1).replace(/^\//, ""));
47148
47247
  return path52.resolve(t);
47149
47248
  }
47150
47249
  function validateWorkspacePath(absPath) {
@@ -47217,7 +47316,7 @@ ${lastSnapshot}`;
47217
47316
  };
47218
47317
  }
47219
47318
  if (a.useHome === true) {
47220
- return { ok: true, path: os6.homedir(), source: "home" };
47319
+ return { ok: true, path: os7.homedir(), source: "home" };
47221
47320
  }
47222
47321
  return {
47223
47322
  ok: false,
@@ -48761,7 +48860,7 @@ ${lastSnapshot}`;
48761
48860
  var import_util3 = require("util");
48762
48861
  var import_fs12 = require("fs");
48763
48862
  var import_os22 = require("os");
48764
- var path11 = __toESM2(require("path"));
48863
+ var path12 = __toESM2(require("path"));
48765
48864
  var execAsync2 = (0, import_util3.promisify)(import_child_process2.exec);
48766
48865
  var BUILTIN_IDE_DEFINITIONS = [];
48767
48866
  var registeredIDEs = /* @__PURE__ */ new Map();
@@ -48781,9 +48880,9 @@ ${lastSnapshot}`;
48781
48880
  function findCliCommand(command) {
48782
48881
  const trimmed = String(command || "").trim();
48783
48882
  if (!trimmed) return null;
48784
- if (path11.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
48785
- const candidate = trimmed.startsWith("~") ? path11.join((0, import_os22.homedir)(), trimmed.slice(1)) : trimmed;
48786
- const resolved = path11.isAbsolute(candidate) ? candidate : path11.resolve(candidate);
48883
+ if (path12.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
48884
+ const candidate = trimmed.startsWith("~") ? path12.join((0, import_os22.homedir)(), trimmed.slice(1)) : trimmed;
48885
+ const resolved = path12.isAbsolute(candidate) ? candidate : path12.resolve(candidate);
48787
48886
  return (0, import_fs12.existsSync)(resolved) ? resolved : null;
48788
48887
  }
48789
48888
  const isWin = (0, import_os22.platform)() === "win32";
@@ -48792,7 +48891,7 @@ ${lastSnapshot}`;
48792
48891
  for (const p of paths) {
48793
48892
  if (!p) continue;
48794
48893
  for (const ext of exes) {
48795
- const fullPath = path11.join(p, trimmed + ext);
48894
+ const fullPath = path12.join(p, trimmed + ext);
48796
48895
  try {
48797
48896
  if ((0, import_fs12.existsSync)(fullPath)) {
48798
48897
  const stat2 = (0, import_fs12.statSync)(fullPath);
@@ -48820,7 +48919,7 @@ ${lastSnapshot}`;
48820
48919
  function checkPathExists(paths) {
48821
48920
  const home = (0, import_os22.homedir)();
48822
48921
  for (const p of paths) {
48823
- const normalized = p.startsWith("~") ? path11.join(home, p.slice(1)) : p;
48922
+ const normalized = p.startsWith("~") ? path12.join(home, p.slice(1)) : p;
48824
48923
  if (normalized.includes("*")) {
48825
48924
  const username = home.split(/[\\/]/).pop() || "";
48826
48925
  const resolved = normalized.replace("*", username);
@@ -48843,8 +48942,8 @@ ${lastSnapshot}`;
48843
48942
  if ((0, import_fs12.existsSync)(bundledCli)) resolvedCli = bundledCli;
48844
48943
  }
48845
48944
  if (!resolvedCli && appPath && os30 === "win32") {
48846
- const { dirname: dirname15 } = await import("path");
48847
- const appDir = dirname15(appPath);
48945
+ const { dirname: dirname16 } = await import("path");
48946
+ const appDir = dirname16(appPath);
48848
48947
  const candidates = [
48849
48948
  `${appDir}\\\\bin\\\\${def.cli}.cmd`,
48850
48949
  `${appDir}\\\\bin\\\\${def.cli}`,
@@ -48875,14 +48974,14 @@ ${lastSnapshot}`;
48875
48974
  return results;
48876
48975
  }
48877
48976
  init_cli_detector();
48878
- var os62 = __toESM2(require("os"));
48977
+ var os72 = __toESM2(require("os"));
48879
48978
  var import_child_process3 = require("child_process");
48880
48979
  var import_util22 = require("util");
48881
48980
  var execAsync3 = (0, import_util22.promisify)(import_child_process3.exec);
48882
48981
  var cachedDarwinAvail = null;
48883
48982
  var darwinMemoryInterval = null;
48884
48983
  async function updateDarwinMemoryCache() {
48885
- if (os62.platform() !== "darwin") return;
48984
+ if (os72.platform() !== "darwin") return;
48886
48985
  try {
48887
48986
  const { stdout } = await execAsync3("vm_stat", {
48888
48987
  encoding: "utf-8",
@@ -48906,19 +49005,19 @@ ${lastSnapshot}`;
48906
49005
  const fileBacked = counts["file_backed"] ?? 0;
48907
49006
  const availPages = free + inactive + speculative + purgeable + fileBacked;
48908
49007
  const bytes = availPages * pageSize;
48909
- cachedDarwinAvail = Number.isFinite(bytes) && bytes >= 0 ? Math.min(bytes, os62.totalmem()) : null;
49008
+ cachedDarwinAvail = Number.isFinite(bytes) && bytes >= 0 ? Math.min(bytes, os72.totalmem()) : null;
48910
49009
  } catch {
48911
49010
  }
48912
49011
  }
48913
49012
  function getHostMemorySnapshot() {
48914
- if (os62.platform() === "darwin" && !darwinMemoryInterval) {
49013
+ if (os72.platform() === "darwin" && !darwinMemoryInterval) {
48915
49014
  updateDarwinMemoryCache();
48916
49015
  darwinMemoryInterval = setInterval(updateDarwinMemoryCache, 3e3);
48917
49016
  darwinMemoryInterval.unref();
48918
49017
  }
48919
- const totalMem = os62.totalmem();
48920
- const freeMem = os62.freemem();
48921
- const availableMem = os62.platform() === "darwin" ? cachedDarwinAvail ?? freeMem : freeMem;
49018
+ const totalMem = os72.totalmem();
49019
+ const freeMem = os72.freemem();
49020
+ const availableMem = os72.platform() === "darwin" ? cachedDarwinAvail ?? freeMem : freeMem;
48922
49021
  return {
48923
49022
  totalMem,
48924
49023
  freeMem,
@@ -51258,9 +51357,9 @@ ${cleanBody}`;
51258
51357
  return cleanTitle || cleanBody;
51259
51358
  }
51260
51359
  var fs52 = __toESM2(require("fs"));
51261
- var path12 = __toESM2(require("path"));
51262
- var os7 = __toESM2(require("os"));
51263
- var HISTORY_DIR = path12.join(os7.homedir(), ".adhdev", "history");
51360
+ var path13 = __toESM2(require("path"));
51361
+ var os8 = __toESM2(require("os"));
51362
+ var HISTORY_DIR = path13.join(os8.homedir(), ".adhdev", "history");
51264
51363
  var RETAIN_DAYS = 30;
51265
51364
  var SAVED_HISTORY_INDEX_VERSION = 1;
51266
51365
  var SAVED_HISTORY_INDEX_FILE = ".saved-history-index.json";
@@ -51446,7 +51545,7 @@ ${cleanBody}`;
51446
51545
  function buildSavedHistoryFileSignatureMap(dir, files) {
51447
51546
  return new Map(files.map((file2) => {
51448
51547
  try {
51449
- const stat2 = fs52.statSync(path12.join(dir, file2));
51548
+ const stat2 = fs52.statSync(path13.join(dir, file2));
51450
51549
  return [file2, `${file2}:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`];
51451
51550
  } catch {
51452
51551
  return [file2, `${file2}:missing`];
@@ -51457,7 +51556,7 @@ ${cleanBody}`;
51457
51556
  return files.map((file2) => fileSignatures.get(file2) || `${file2}:missing`).join("|");
51458
51557
  }
51459
51558
  function getSavedHistoryIndexFilePath(dir) {
51460
- return path12.join(dir, SAVED_HISTORY_INDEX_FILE);
51559
+ return path13.join(dir, SAVED_HISTORY_INDEX_FILE);
51461
51560
  }
51462
51561
  function getSavedHistoryIndexLockPath(dir) {
51463
51562
  return `${getSavedHistoryIndexFilePath(dir)}${SAVED_HISTORY_INDEX_LOCK_SUFFIX}`;
@@ -51559,7 +51658,7 @@ ${cleanBody}`;
51559
51658
  }
51560
51659
  for (const file2 of Array.from(currentEntries.keys())) {
51561
51660
  if (incomingFiles.has(file2)) continue;
51562
- if (!fs52.existsSync(path12.join(dir, file2))) {
51661
+ if (!fs52.existsSync(path13.join(dir, file2))) {
51563
51662
  currentEntries.delete(file2);
51564
51663
  }
51565
51664
  }
@@ -51585,7 +51684,7 @@ ${cleanBody}`;
51585
51684
  const indexStat = fs52.statSync(getSavedHistoryIndexFilePath(dir));
51586
51685
  const files = listHistoryFiles(dir);
51587
51686
  for (const file2 of files) {
51588
- const stat2 = fs52.statSync(path12.join(dir, file2));
51687
+ const stat2 = fs52.statSync(path13.join(dir, file2));
51589
51688
  if (stat2.mtimeMs > indexStat.mtimeMs) return true;
51590
51689
  }
51591
51690
  return false;
@@ -51595,14 +51694,14 @@ ${cleanBody}`;
51595
51694
  }
51596
51695
  function buildSavedHistoryFileSignature(dir, file2) {
51597
51696
  try {
51598
- const stat2 = fs52.statSync(path12.join(dir, file2));
51697
+ const stat2 = fs52.statSync(path13.join(dir, file2));
51599
51698
  return `${file2}:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`;
51600
51699
  } catch {
51601
51700
  return `${file2}:missing`;
51602
51701
  }
51603
51702
  }
51604
51703
  function persistSavedHistoryFileSummaryEntry(agentType, dir, file2, updater) {
51605
- const filePath = path12.join(dir, file2);
51704
+ const filePath = path13.join(dir, file2);
51606
51705
  const result = withLockedPersistedSavedHistoryIndex(dir, (entries) => {
51607
51706
  const currentEntry = entries.get(file2) || null;
51608
51707
  const nextSummary = updater(currentEntry?.summary || null);
@@ -51675,7 +51774,7 @@ ${cleanBody}`;
51675
51774
  function computeSavedHistoryFileSummary(dir, file2) {
51676
51775
  const historySessionId = extractSavedHistorySessionIdFromFile(file2);
51677
51776
  if (!historySessionId) return null;
51678
- const filePath = path12.join(dir, file2);
51777
+ const filePath = path13.join(dir, file2);
51679
51778
  const content = fs52.readFileSync(filePath, "utf-8");
51680
51779
  const lines = content.split("\n").filter(Boolean);
51681
51780
  let messageCount = 0;
@@ -51762,7 +51861,7 @@ ${cleanBody}`;
51762
51861
  const summaryBySessionId = /* @__PURE__ */ new Map();
51763
51862
  const nextPersistedEntries = /* @__PURE__ */ new Map();
51764
51863
  for (const file2 of files.slice().sort()) {
51765
- const filePath = path12.join(dir, file2);
51864
+ const filePath = path13.join(dir, file2);
51766
51865
  const signature = fileSignatures.get(file2) || `${file2}:missing`;
51767
51866
  const cached22 = savedHistoryFileSummaryCache.get(filePath);
51768
51867
  const persisted = persistedEntries.get(file2);
@@ -51882,12 +51981,12 @@ ${cleanBody}`;
51882
51981
  });
51883
51982
  }
51884
51983
  if (newMessages.length === 0) return;
51885
- const dir = path12.join(HISTORY_DIR, this.sanitize(agentType));
51984
+ const dir = path13.join(HISTORY_DIR, this.sanitize(agentType));
51886
51985
  fs52.mkdirSync(dir, { recursive: true });
51887
51986
  const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
51888
51987
  const filePrefix = effectiveHistoryKey ? `${this.sanitize(effectiveHistoryKey)}_` : "";
51889
51988
  const fileName = `${filePrefix}${date5}.jsonl`;
51890
- const filePath = path12.join(dir, fileName);
51989
+ const filePath = path13.join(dir, fileName);
51891
51990
  const lines = newMessages.map((m) => JSON.stringify(m)).join("\n") + "\n";
51892
51991
  fs52.appendFileSync(filePath, lines, "utf-8");
51893
51992
  updateSavedHistoryIndexForAppendedMessages(agentType, dir, fileName, effectiveHistoryKey, newMessages);
@@ -51978,11 +52077,11 @@ ${cleanBody}`;
51978
52077
  const ws = String(workspace || "").trim();
51979
52078
  if (!id || !ws) return;
51980
52079
  try {
51981
- const dir = path12.join(HISTORY_DIR, this.sanitize(agentType));
52080
+ const dir = path13.join(HISTORY_DIR, this.sanitize(agentType));
51982
52081
  fs52.mkdirSync(dir, { recursive: true });
51983
52082
  const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
51984
52083
  const fileName = `${this.sanitize(id)}_${date5}.jsonl`;
51985
- const filePath = path12.join(dir, fileName);
52084
+ const filePath = path13.join(dir, fileName);
51986
52085
  const record2 = {
51987
52086
  ts: (/* @__PURE__ */ new Date()).toISOString(),
51988
52087
  receivedAt: Date.now(),
@@ -52028,14 +52127,14 @@ ${cleanBody}`;
52028
52127
  this.lastSeenCounts.set(toDedupKey, Math.max(fromCount, this.lastSeenCounts.get(toDedupKey) || 0));
52029
52128
  this.lastSeenCounts.delete(fromDedupKey);
52030
52129
  }
52031
- const dir = path12.join(HISTORY_DIR, this.sanitize(agentType));
52130
+ const dir = path13.join(HISTORY_DIR, this.sanitize(agentType));
52032
52131
  if (!fs52.existsSync(dir)) return;
52033
52132
  const fromPrefix = `${this.sanitize(fromId)}_`;
52034
52133
  const toPrefix = `${this.sanitize(toId)}_`;
52035
52134
  const files = fs52.readdirSync(dir).filter((file2) => file2.startsWith(fromPrefix) && file2.endsWith(".jsonl"));
52036
52135
  for (const file2 of files) {
52037
- const sourcePath = path12.join(dir, file2);
52038
- const targetPath = path12.join(dir, `${toPrefix}${file2.slice(fromPrefix.length)}`);
52136
+ const sourcePath = path13.join(dir, file2);
52137
+ const targetPath = path13.join(dir, `${toPrefix}${file2.slice(fromPrefix.length)}`);
52039
52138
  const sourceLines = fs52.readFileSync(sourcePath, "utf-8").split("\n").filter(Boolean);
52040
52139
  const rewritten = sourceLines.map((line) => {
52041
52140
  try {
@@ -52069,13 +52168,13 @@ ${cleanBody}`;
52069
52168
  const sessionId = String(historySessionId || "").trim();
52070
52169
  if (!sessionId) return;
52071
52170
  try {
52072
- const dir = path12.join(HISTORY_DIR, this.sanitize(agentType));
52171
+ const dir = path13.join(HISTORY_DIR, this.sanitize(agentType));
52073
52172
  if (!fs52.existsSync(dir)) return;
52074
52173
  const prefix = `${this.sanitize(sessionId)}_`;
52075
52174
  const files = fs52.readdirSync(dir).filter((file2) => file2.startsWith(prefix) && file2.endsWith(".jsonl")).sort();
52076
52175
  const seen = /* @__PURE__ */ new Set();
52077
52176
  for (const file2 of files) {
52078
- const filePath = path12.join(dir, file2);
52177
+ const filePath = path13.join(dir, file2);
52079
52178
  const lines = fs52.readFileSync(filePath, "utf-8").split("\n").filter(Boolean);
52080
52179
  const next = [];
52081
52180
  for (const line of lines) {
@@ -52129,11 +52228,11 @@ ${cleanBody}`;
52129
52228
  const cutoff = Date.now() - RETAIN_DAYS * 24 * 60 * 60 * 1e3;
52130
52229
  const agentDirs = fs52.readdirSync(HISTORY_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
52131
52230
  for (const dir of agentDirs) {
52132
- const dirPath = path12.join(HISTORY_DIR, dir.name);
52231
+ const dirPath = path13.join(HISTORY_DIR, dir.name);
52133
52232
  const files = fs52.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl") || f.endsWith(".terminal.log"));
52134
52233
  let removedAny = false;
52135
52234
  for (const file2 of files) {
52136
- const filePath = path12.join(dirPath, file2);
52235
+ const filePath = path13.join(dirPath, file2);
52137
52236
  const stat2 = fs52.statSync(filePath);
52138
52237
  if (stat2.mtimeMs < cutoff) {
52139
52238
  fs52.unlinkSync(filePath);
@@ -52336,7 +52435,7 @@ ${cleanBody}`;
52336
52435
  const seen = /* @__PURE__ */ new Set();
52337
52436
  let readAllFiles = true;
52338
52437
  for (let f = 0; f < files.length; f++) {
52339
- const filePath = path12.join(dir, files[f]);
52438
+ const filePath = path13.join(dir, files[f]);
52340
52439
  const remaining = Math.max(0, needed - collected.length);
52341
52440
  const perFileNeeded = Math.min(needed, remaining + BOUNDED_TAIL_SLACK);
52342
52441
  const { lines, coversWholeFile } = readFileTailLines(filePath, perFileNeeded);
@@ -52369,7 +52468,7 @@ ${cleanBody}`;
52369
52468
  function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, excludeRecentCount = 0, historyBehavior) {
52370
52469
  try {
52371
52470
  const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
52372
- const dir = path12.join(HISTORY_DIR, sanitized);
52471
+ const dir = path13.join(HISTORY_DIR, sanitized);
52373
52472
  if (!fs52.existsSync(dir)) return { messages: [], hasMore: false };
52374
52473
  const files = listHistoryFiles(dir, historySessionId);
52375
52474
  const bounded = isBoundedTailRequest(limit, offset, excludeRecentCount);
@@ -52392,7 +52491,7 @@ ${cleanBody}`;
52392
52491
  const allMessages = [];
52393
52492
  const seen = /* @__PURE__ */ new Set();
52394
52493
  for (const file2 of files) {
52395
- const filePath = path12.join(dir, file2);
52494
+ const filePath = path13.join(dir, file2);
52396
52495
  const content = fs52.readFileSync(filePath, "utf-8");
52397
52496
  const lines = content.trim().split("\n").filter(Boolean);
52398
52497
  for (let i = 0; i < lines.length; i++) {
@@ -52416,7 +52515,7 @@ ${cleanBody}`;
52416
52515
  function listSavedHistorySessions(agentType, options = {}, historyBehavior) {
52417
52516
  try {
52418
52517
  const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
52419
- const dir = path12.join(HISTORY_DIR, sanitized);
52518
+ const dir = path13.join(HISTORY_DIR, sanitized);
52420
52519
  if (!fs52.existsSync(dir)) {
52421
52520
  savedHistorySessionCache.delete(sanitized);
52422
52521
  return { sessions: [], hasMore: false };
@@ -52477,11 +52576,11 @@ ${cleanBody}`;
52477
52576
  }
52478
52577
  function readExistingSessionStartRecord(agentType, historySessionId) {
52479
52578
  try {
52480
- const dir = path12.join(HISTORY_DIR, agentType);
52579
+ const dir = path13.join(HISTORY_DIR, agentType);
52481
52580
  if (!fs52.existsSync(dir)) return null;
52482
52581
  const files = listHistoryFiles(dir, historySessionId).sort();
52483
52582
  for (const file2 of files) {
52484
- const lines = fs52.readFileSync(path12.join(dir, file2), "utf-8").split("\n").filter(Boolean);
52583
+ const lines = fs52.readFileSync(path13.join(dir, file2), "utf-8").split("\n").filter(Boolean);
52485
52584
  for (const line of lines) {
52486
52585
  try {
52487
52586
  const parsed = JSON.parse(line);
@@ -52501,16 +52600,16 @@ ${cleanBody}`;
52501
52600
  function rewriteCanonicalSavedHistory(agentType, historySessionId, records) {
52502
52601
  if (records.length === 0) return false;
52503
52602
  try {
52504
- const dir = path12.join(HISTORY_DIR, agentType);
52603
+ const dir = path13.join(HISTORY_DIR, agentType);
52505
52604
  fs52.mkdirSync(dir, { recursive: true });
52506
52605
  const prefix = `${historySessionId.replace(/[^a-zA-Z0-9_-]/g, "_")}_`;
52507
52606
  for (const file2 of fs52.readdirSync(dir)) {
52508
52607
  if (file2.startsWith(prefix) && file2.endsWith(".jsonl")) {
52509
- fs52.unlinkSync(path12.join(dir, file2));
52608
+ fs52.unlinkSync(path13.join(dir, file2));
52510
52609
  }
52511
52610
  }
52512
52611
  const targetDate = new Date(records[records.length - 1].receivedAt || Date.now()).toISOString().slice(0, 10);
52513
- const filePath = path12.join(dir, `${prefix}${targetDate}.jsonl`);
52612
+ const filePath = path13.join(dir, `${prefix}${targetDate}.jsonl`);
52514
52613
  fs52.writeFileSync(filePath, `${records.map((record2) => JSON.stringify(record2)).join("\n")}
52515
52614
  `, "utf-8");
52516
52615
  invalidatePersistedSavedHistoryIndex(agentType, dir);
@@ -55063,8 +55162,8 @@ ${effect.notification.body || ""}`.trim();
55063
55162
  return fn() || null;
55064
55163
  }
55065
55164
  var fs6 = __toESM2(require("fs"));
55066
- var os8 = __toESM2(require("os"));
55067
- var path13 = __toESM2(require("path"));
55165
+ var os9 = __toESM2(require("os"));
55166
+ var path14 = __toESM2(require("path"));
55068
55167
  var import_node_crypto3 = require("crypto");
55069
55168
  init_logger();
55070
55169
  init_debug_config();
@@ -56103,7 +56202,7 @@ ${effect.notification.body || ""}`.trim();
56103
56202
  function normalizeComparableWorkspace(value) {
56104
56203
  const text = typeof value === "string" ? value.trim() : "";
56105
56204
  if (!text) return "";
56106
- return path13.resolve(text);
56205
+ return path14.resolve(text);
56107
56206
  }
56108
56207
  function isCurrentRuntimePtySafelyAttributed(args) {
56109
56208
  if (args.adapter.cliType !== "codex-cli") return false;
@@ -56588,7 +56687,7 @@ ${effect.notification.body || ""}`.trim();
56588
56687
  }
56589
56688
  function getChatDebugBundleDir() {
56590
56689
  const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
56591
- return override || path13.join(os8.homedir(), ".adhdev", "debug-bundles", "chat");
56690
+ return override || path14.join(os9.homedir(), ".adhdev", "debug-bundles", "chat");
56592
56691
  }
56593
56692
  function safeBundleIdSegment(value, fallback) {
56594
56693
  const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
@@ -56645,7 +56744,7 @@ ${effect.notification.body || ""}`.trim();
56645
56744
  const bundleId = createChatDebugBundleId(targetSessionId);
56646
56745
  const dir = getChatDebugBundleDir();
56647
56746
  fs6.mkdirSync(dir, { recursive: true });
56648
- const savedPath = path13.join(dir, `${bundleId}.json`);
56747
+ const savedPath = path14.join(dir, `${bundleId}.json`);
56649
56748
  const json2 = `${JSON.stringify(bundle, null, 2)}
56650
56749
  `;
56651
56750
  fs6.writeFileSync(savedPath, json2, { encoding: "utf8", mode: 384 });
@@ -58207,8 +58306,8 @@ ${effect.notification.body || ""}`.trim();
58207
58306
  return { success: false, error: "resolveAction script not available for this provider" };
58208
58307
  }
58209
58308
  var fs7 = __toESM2(require("fs"));
58210
- var path14 = __toESM2(require("path"));
58211
- var os9 = __toESM2(require("os"));
58309
+ var path15 = __toESM2(require("path"));
58310
+ var os10 = __toESM2(require("os"));
58212
58311
  var KEY_TO_VK = {
58213
58312
  Backspace: 8,
58214
58313
  Tab: 9,
@@ -58462,27 +58561,27 @@ ${effect.notification.body || ""}`.trim();
58462
58561
  function resolveSafePath(requestedPath) {
58463
58562
  const rawPath = typeof requestedPath === "string" ? requestedPath.trim() : "";
58464
58563
  const inputPath = rawPath || ".";
58465
- const home = os9.homedir();
58564
+ const home = os10.homedir();
58466
58565
  if (inputPath.startsWith("~")) {
58467
- return path14.resolve(path14.join(home, inputPath.slice(1)));
58566
+ return path15.resolve(path15.join(home, inputPath.slice(1)));
58468
58567
  }
58469
58568
  if (process.platform === "win32") {
58470
58569
  const normalized = normalizeWindowsRequestedPath(inputPath);
58471
- if (path14.win32.isAbsolute(normalized)) {
58472
- return path14.win32.normalize(normalized);
58570
+ if (path15.win32.isAbsolute(normalized)) {
58571
+ return path15.win32.normalize(normalized);
58473
58572
  }
58474
- return path14.win32.resolve(normalized);
58573
+ return path15.win32.resolve(normalized);
58475
58574
  }
58476
- if (path14.isAbsolute(inputPath)) {
58477
- return path14.normalize(inputPath);
58575
+ if (path15.isAbsolute(inputPath)) {
58576
+ return path15.normalize(inputPath);
58478
58577
  }
58479
- return path14.resolve(inputPath);
58578
+ return path15.resolve(inputPath);
58480
58579
  }
58481
58580
  function listDirectoryEntriesSafe(dirPath) {
58482
58581
  const entries = fs7.readdirSync(dirPath, { withFileTypes: true });
58483
58582
  const files = [];
58484
58583
  for (const entry of entries) {
58485
- const entryPath = path14.join(dirPath, entry.name);
58584
+ const entryPath = path15.join(dirPath, entry.name);
58486
58585
  try {
58487
58586
  if (entry.isDirectory()) {
58488
58587
  files.push({ name: entry.name, type: "directory" });
@@ -58536,7 +58635,7 @@ ${effect.notification.body || ""}`.trim();
58536
58635
  async function handleFileWrite(h, args) {
58537
58636
  try {
58538
58637
  const filePath = resolveSafePath(args?.path);
58539
- fs7.mkdirSync(path14.dirname(filePath), { recursive: true });
58638
+ fs7.mkdirSync(path15.dirname(filePath), { recursive: true });
58540
58639
  fs7.writeFileSync(filePath, args?.content || "", "utf-8");
58541
58640
  return { success: true, path: filePath };
58542
58641
  } catch (e) {
@@ -72844,7 +72943,15 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
72844
72943
  function readMeshConnectionState(connection) {
72845
72944
  return readStringValue(connection?.state);
72846
72945
  }
72946
+ function isMeshConnectionDefinitivelyDown(connection) {
72947
+ if (!connection) return true;
72948
+ const state = readMeshConnectionState(connection);
72949
+ return state === "failed" || state === "closed" || state === "disconnected";
72950
+ }
72847
72951
  async function probeRemoteMeshGitStatusWithRetry(args) {
72952
+ if (args.getConnection && isMeshConnectionDefinitivelyDown(args.getConnection(args.daemonId))) {
72953
+ return null;
72954
+ }
72848
72955
  for (let attempt = 0; attempt <= MESH_DIRECT_PROBE_MAX_RETRIES; attempt += 1) {
72849
72956
  if (attempt > 0) {
72850
72957
  const connection = args.getConnection?.(args.daemonId);
@@ -78682,7 +78789,7 @@ ${ptyResult.output.slice(-2e3)}`);
78682
78789
  };
78683
78790
  }
78684
78791
  const { existsSync: existsSync44, readFileSync: readFileSync35, writeFileSync: writeFileSync23, copyFileSync: copyFileSync4, mkdirSync: mkdirSync21 } = await import("fs");
78685
- const { dirname: dirname15 } = await import("path");
78792
+ const { dirname: dirname16 } = await import("path");
78686
78793
  const mcpConfigPath = coordinatorSetup.configPath;
78687
78794
  const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
78688
78795
  let hermesBaseConfig = null;
@@ -78717,7 +78824,7 @@ ${ptyResult.output.slice(-2e3)}`);
78717
78824
  };
78718
78825
  }
78719
78826
  try {
78720
- mkdirSync21(dirname15(mcpConfigPath), { recursive: true });
78827
+ mkdirSync21(dirname16(mcpConfigPath), { recursive: true });
78721
78828
  } catch (error48) {
78722
78829
  const message = `Could not prepare MCP config path for automatic setup: ${error48?.message || error48}`;
78723
78830
  LOG2.error("MeshCoordinator", message);
@@ -78727,7 +78834,7 @@ ${ptyResult.output.slice(-2e3)}`);
78727
78834
  const hadExistingMcpConfig = existsSync44(mcpConfigPath);
78728
78835
  let existingMcpConfig = hermesBaseConfig?.config || {};
78729
78836
  if (hermesBaseConfig) {
78730
- copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname15(mcpConfigPath));
78837
+ copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname16(mcpConfigPath));
78731
78838
  }
78732
78839
  if (hadExistingMcpConfig) {
78733
78840
  try {
@@ -78765,7 +78872,7 @@ ${ptyResult.output.slice(-2e3)}`);
78765
78872
  const cliArgs = [];
78766
78873
  const launchEnv = {};
78767
78874
  if (configFormat === "hermes_config_yaml") {
78768
- launchEnv.HERMES_HOME = dirname15(mcpConfigPath);
78875
+ launchEnv.HERMES_HOME = dirname16(mcpConfigPath);
78769
78876
  launchEnv.HERMES_IGNORE_USER_CONFIG = "";
78770
78877
  }
78771
78878
  let autoImportContextFilePath;