@adhdev/daemon-core 0.9.82-rc.317 → 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 +538 -510
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +549 -521
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/cli-adapters/resolve-executable.ts +46 -1
- package/src/detection/cli-detector.ts +28 -9
package/dist/index.js
CHANGED
|
@@ -353,10 +353,10 @@ function readInjected(value) {
|
|
|
353
353
|
}
|
|
354
354
|
function getDaemonBuildInfo() {
|
|
355
355
|
if (cached) return cached;
|
|
356
|
-
const commit = readInjected(true ? "
|
|
357
|
-
const commitShort = readInjected(true ? "
|
|
358
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
359
|
-
const builtAt = readInjected(true ? "2026-06-
|
|
356
|
+
const commit = readInjected(true ? "506ca246e28984a3b699b04c4601117f62ba2d81" : void 0) ?? "unknown";
|
|
357
|
+
const commitShort = readInjected(true ? "506ca246" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
358
|
+
const version = readInjected(true ? "0.9.82-rc.318" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
359
|
+
const builtAt = readInjected(true ? "2026-06-18T12:46:04.472Z" : void 0);
|
|
360
360
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
361
361
|
return cached;
|
|
362
362
|
}
|
|
@@ -7913,6 +7913,405 @@ var init_mesh_events_stale = __esm({
|
|
|
7913
7913
|
}
|
|
7914
7914
|
});
|
|
7915
7915
|
|
|
7916
|
+
// src/cli-adapters/spawn-env.ts
|
|
7917
|
+
var import_session_host_core2;
|
|
7918
|
+
var init_spawn_env = __esm({
|
|
7919
|
+
"src/cli-adapters/spawn-env.ts"() {
|
|
7920
|
+
"use strict";
|
|
7921
|
+
import_session_host_core2 = require("@adhdev/session-host-core");
|
|
7922
|
+
}
|
|
7923
|
+
});
|
|
7924
|
+
|
|
7925
|
+
// src/cli-adapters/provider-cli-shared.ts
|
|
7926
|
+
function stripAnsi(str) {
|
|
7927
|
+
return str.replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
7928
|
+
}
|
|
7929
|
+
function parseCount(params, fallback = 1) {
|
|
7930
|
+
const first = Number(String(params || "").split(";")[0] || fallback);
|
|
7931
|
+
return Math.max(1, Number.isFinite(first) ? first : fallback);
|
|
7932
|
+
}
|
|
7933
|
+
function isCombiningMark(ch) {
|
|
7934
|
+
return /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/.test(ch);
|
|
7935
|
+
}
|
|
7936
|
+
function isWideCodePoint(ch) {
|
|
7937
|
+
const cp = ch.codePointAt(0) || 0;
|
|
7938
|
+
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);
|
|
7939
|
+
}
|
|
7940
|
+
function stripTerminalNoise(str) {
|
|
7941
|
+
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");
|
|
7942
|
+
}
|
|
7943
|
+
function sanitizeTerminalText(str) {
|
|
7944
|
+
const accumulator = new TerminalTranscriptAccumulator();
|
|
7945
|
+
return stripTerminalNoise(stripAnsi(accumulator.append(str)));
|
|
7946
|
+
}
|
|
7947
|
+
function listCliScriptNames(scripts) {
|
|
7948
|
+
if (!scripts) return [];
|
|
7949
|
+
return Object.entries(scripts).filter(([, fn]) => typeof fn === "function").map(([name]) => name);
|
|
7950
|
+
}
|
|
7951
|
+
function splitCliScreenLines(text) {
|
|
7952
|
+
return String(text || "").replace(/\u0007/g, "").replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").map((line) => line.replace(/\s+$/, ""));
|
|
7953
|
+
}
|
|
7954
|
+
function isPromptLikeCliLine(line) {
|
|
7955
|
+
const trimmed = String(line || "").trim();
|
|
7956
|
+
if (!trimmed) return false;
|
|
7957
|
+
return /^[❯›>]\s*(?:$|\S.*)$/.test(trimmed);
|
|
7958
|
+
}
|
|
7959
|
+
function buildCliScreenSnapshot(text) {
|
|
7960
|
+
const normalizedText = String(text || "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
7961
|
+
const rawLines = splitCliScreenLines(normalizedText);
|
|
7962
|
+
const lines = rawLines.map((line, index, arr) => {
|
|
7963
|
+
const trimmed = String(line || "").trim();
|
|
7964
|
+
return {
|
|
7965
|
+
index,
|
|
7966
|
+
fromTop: index,
|
|
7967
|
+
fromBottom: arr.length - index - 1,
|
|
7968
|
+
text: line,
|
|
7969
|
+
trimmed,
|
|
7970
|
+
isEmpty: trimmed.length === 0
|
|
7971
|
+
};
|
|
7972
|
+
});
|
|
7973
|
+
const nonEmptyLines = lines.filter((line) => !line.isEmpty);
|
|
7974
|
+
const firstNonEmptyLine = nonEmptyLines[0] ?? null;
|
|
7975
|
+
const lastNonEmptyLine = nonEmptyLines[nonEmptyLines.length - 1] ?? null;
|
|
7976
|
+
let promptLineIndex = -1;
|
|
7977
|
+
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
7978
|
+
if (isPromptLikeCliLine(lines[i].text)) {
|
|
7979
|
+
promptLineIndex = i;
|
|
7980
|
+
break;
|
|
7981
|
+
}
|
|
7982
|
+
}
|
|
7983
|
+
return {
|
|
7984
|
+
text: normalizedText,
|
|
7985
|
+
lineCount: lines.length,
|
|
7986
|
+
lines,
|
|
7987
|
+
nonEmptyLines,
|
|
7988
|
+
firstNonEmptyLineIndex: firstNonEmptyLine?.index ?? -1,
|
|
7989
|
+
lastNonEmptyLineIndex: lastNonEmptyLine?.index ?? -1,
|
|
7990
|
+
firstNonEmptyLine,
|
|
7991
|
+
lastNonEmptyLine,
|
|
7992
|
+
promptLineIndex,
|
|
7993
|
+
promptLine: promptLineIndex >= 0 ? lines[promptLineIndex] : null,
|
|
7994
|
+
linesAbovePrompt: promptLineIndex >= 0 ? lines.slice(0, promptLineIndex) : [...lines],
|
|
7995
|
+
linesBelowPrompt: promptLineIndex >= 0 ? lines.slice(promptLineIndex + 1) : []
|
|
7996
|
+
};
|
|
7997
|
+
}
|
|
7998
|
+
function findBinary(name) {
|
|
7999
|
+
const trimmed = String(name || "").trim();
|
|
8000
|
+
if (!trimmed) return trimmed;
|
|
8001
|
+
const expanded = trimmed.startsWith("~") ? path10.join(os5.homedir(), trimmed.slice(1)) : trimmed;
|
|
8002
|
+
if (path10.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
|
|
8003
|
+
return path10.isAbsolute(expanded) ? expanded : path10.resolve(expanded);
|
|
8004
|
+
}
|
|
8005
|
+
const isWin = os5.platform() === "win32";
|
|
8006
|
+
const paths = (process.env.PATH || "").split(path10.delimiter);
|
|
8007
|
+
const extraDirs = [];
|
|
8008
|
+
if (isWin) {
|
|
8009
|
+
if (process.env.APPDATA) extraDirs.push(path10.join(process.env.APPDATA, "npm"));
|
|
8010
|
+
try {
|
|
8011
|
+
extraDirs.push(path10.dirname(process.execPath));
|
|
8012
|
+
} catch {
|
|
8013
|
+
}
|
|
8014
|
+
} else {
|
|
8015
|
+
extraDirs.push(path10.join(os5.homedir(), ".npm-global", "bin"));
|
|
8016
|
+
extraDirs.push("/usr/local/bin", "/opt/homebrew/bin");
|
|
8017
|
+
try {
|
|
8018
|
+
extraDirs.push(path10.dirname(process.execPath));
|
|
8019
|
+
} catch {
|
|
8020
|
+
}
|
|
8021
|
+
}
|
|
8022
|
+
const searchDirs = [...paths, ...extraDirs];
|
|
8023
|
+
const exes = isWin ? [".exe", ".cmd", ".bat", ""] : [""];
|
|
8024
|
+
for (const p of searchDirs) {
|
|
8025
|
+
if (!p) continue;
|
|
8026
|
+
for (const ext of exes) {
|
|
8027
|
+
const fullPath = path10.join(p, trimmed + ext);
|
|
8028
|
+
try {
|
|
8029
|
+
const fs31 = require("fs");
|
|
8030
|
+
if (fs31.existsSync(fullPath)) {
|
|
8031
|
+
const stat2 = fs31.statSync(fullPath);
|
|
8032
|
+
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
8033
|
+
return fullPath;
|
|
8034
|
+
}
|
|
8035
|
+
}
|
|
8036
|
+
} catch {
|
|
8037
|
+
}
|
|
8038
|
+
}
|
|
8039
|
+
}
|
|
8040
|
+
return isWin ? `${trimmed}.cmd` : trimmed;
|
|
8041
|
+
}
|
|
8042
|
+
function isScriptBinary(binaryPath) {
|
|
8043
|
+
if (!path10.isAbsolute(binaryPath)) return false;
|
|
8044
|
+
try {
|
|
8045
|
+
const fs31 = require("fs");
|
|
8046
|
+
const resolved = fs31.realpathSync(binaryPath);
|
|
8047
|
+
const head = Buffer.alloc(8);
|
|
8048
|
+
const fd = fs31.openSync(resolved, "r");
|
|
8049
|
+
fs31.readSync(fd, head, 0, 8, 0);
|
|
8050
|
+
fs31.closeSync(fd);
|
|
8051
|
+
let i = 0;
|
|
8052
|
+
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
8053
|
+
return head[i] === 35 && head[i + 1] === 33;
|
|
8054
|
+
} catch {
|
|
8055
|
+
return false;
|
|
8056
|
+
}
|
|
8057
|
+
}
|
|
8058
|
+
function looksLikeMachOOrElf(filePath) {
|
|
8059
|
+
if (!path10.isAbsolute(filePath)) return false;
|
|
8060
|
+
try {
|
|
8061
|
+
const fs31 = require("fs");
|
|
8062
|
+
const resolved = fs31.realpathSync(filePath);
|
|
8063
|
+
const buf = Buffer.alloc(8);
|
|
8064
|
+
const fd = fs31.openSync(resolved, "r");
|
|
8065
|
+
fs31.readSync(fd, buf, 0, 8, 0);
|
|
8066
|
+
fs31.closeSync(fd);
|
|
8067
|
+
let i = 0;
|
|
8068
|
+
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
8069
|
+
const b = buf.subarray(i);
|
|
8070
|
+
if (b.length < 4) return false;
|
|
8071
|
+
if (b[0] === 127 && b[1] === 69 && b[2] === 76 && b[3] === 70) return true;
|
|
8072
|
+
const le = b.readUInt32LE(0);
|
|
8073
|
+
const be = b.readUInt32BE(0);
|
|
8074
|
+
const magics = [4277009102, 4277009103, 3405691582, 3199925962];
|
|
8075
|
+
return magics.some((m) => m === le || m === be);
|
|
8076
|
+
} catch {
|
|
8077
|
+
return false;
|
|
8078
|
+
}
|
|
8079
|
+
}
|
|
8080
|
+
function shSingleQuote(arg) {
|
|
8081
|
+
if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
|
|
8082
|
+
if (os5.platform() === "win32") {
|
|
8083
|
+
return `"${arg.replace(/"/g, '""')}"`;
|
|
8084
|
+
}
|
|
8085
|
+
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
8086
|
+
}
|
|
8087
|
+
function estimatePromptDisplayLines(text, cols = 80) {
|
|
8088
|
+
const normalized = String(text || "").replace(/\r/g, "");
|
|
8089
|
+
if (!normalized) return 1;
|
|
8090
|
+
return normalized.split("\n").reduce((sum, line) => sum + Math.max(1, Math.ceil(Math.max(1, line.length) / cols)), 0);
|
|
8091
|
+
}
|
|
8092
|
+
function extractPromptRetrySnippet(text) {
|
|
8093
|
+
const lines = String(text || "").replace(/\r/g, "").split("\n").map((line) => line.trim()).filter(Boolean);
|
|
8094
|
+
const candidate = lines[lines.length - 1] || lines[0] || "";
|
|
8095
|
+
return candidate.slice(-120);
|
|
8096
|
+
}
|
|
8097
|
+
function normalizePromptText(text) {
|
|
8098
|
+
return String(text || "").replace(/\s+/g, " ").trim();
|
|
8099
|
+
}
|
|
8100
|
+
function compactPromptText(text) {
|
|
8101
|
+
return String(text || "").replace(/\s+/g, "").trim();
|
|
8102
|
+
}
|
|
8103
|
+
function promptLikelyVisible(screenText, promptSnippet) {
|
|
8104
|
+
const snippet = normalizePromptText(promptSnippet);
|
|
8105
|
+
if (!snippet) return false;
|
|
8106
|
+
const normalizedScreen = normalizePromptText(screenText);
|
|
8107
|
+
if (normalizedScreen.includes(snippet)) return true;
|
|
8108
|
+
const compactScreen = compactPromptText(screenText);
|
|
8109
|
+
const compactSnippet = compactPromptText(promptSnippet);
|
|
8110
|
+
if (compactSnippet && compactScreen.includes(compactSnippet)) return true;
|
|
8111
|
+
const tokens = snippet.split(/[^A-Za-z0-9_.:/-]+/).map((token) => token.trim()).filter((token) => token.length >= 4);
|
|
8112
|
+
if (tokens.length === 0) return false;
|
|
8113
|
+
const required = Math.min(tokens.length, 3);
|
|
8114
|
+
const matched = tokens.filter(
|
|
8115
|
+
(token) => normalizedScreen.includes(token) || compactScreen.includes(compactPromptText(token))
|
|
8116
|
+
).length;
|
|
8117
|
+
return matched >= required;
|
|
8118
|
+
}
|
|
8119
|
+
function normalizeScreenSnapshot(text) {
|
|
8120
|
+
return sanitizeTerminalText(String(text || "")).replace(/\s+/g, " ").trim();
|
|
8121
|
+
}
|
|
8122
|
+
function parsePatternEntry(x) {
|
|
8123
|
+
if (x instanceof RegExp) return x;
|
|
8124
|
+
if (x && typeof x === "object" && typeof x.source === "string") {
|
|
8125
|
+
try {
|
|
8126
|
+
const s = x;
|
|
8127
|
+
return new RegExp(s.source, s.flags || "");
|
|
8128
|
+
} catch {
|
|
8129
|
+
return null;
|
|
8130
|
+
}
|
|
8131
|
+
}
|
|
8132
|
+
return null;
|
|
8133
|
+
}
|
|
8134
|
+
function coercePatternArray(raw) {
|
|
8135
|
+
if (!Array.isArray(raw)) return [];
|
|
8136
|
+
return raw.map(parsePatternEntry).filter((r) => r != null);
|
|
8137
|
+
}
|
|
8138
|
+
function normalizeCliProviderForRuntime(raw) {
|
|
8139
|
+
const patterns = raw && typeof raw === "object" ? raw.patterns : void 0;
|
|
8140
|
+
return {
|
|
8141
|
+
patterns: {
|
|
8142
|
+
approval: coercePatternArray(
|
|
8143
|
+
patterns && typeof patterns === "object" ? patterns.approval : void 0
|
|
8144
|
+
)
|
|
8145
|
+
}
|
|
8146
|
+
};
|
|
8147
|
+
}
|
|
8148
|
+
var os5, path10, TerminalTranscriptAccumulator, buildCliSpawnEnv;
|
|
8149
|
+
var init_provider_cli_shared = __esm({
|
|
8150
|
+
"src/cli-adapters/provider-cli-shared.ts"() {
|
|
8151
|
+
"use strict";
|
|
8152
|
+
os5 = __toESM(require("os"));
|
|
8153
|
+
path10 = __toESM(require("path"));
|
|
8154
|
+
init_spawn_env();
|
|
8155
|
+
TerminalTranscriptAccumulator = class {
|
|
8156
|
+
lines = [[]];
|
|
8157
|
+
row = 0;
|
|
8158
|
+
col = 0;
|
|
8159
|
+
savedCursor = null;
|
|
8160
|
+
pendingEscape = "";
|
|
8161
|
+
append(data) {
|
|
8162
|
+
const input = this.pendingEscape + String(data || "");
|
|
8163
|
+
this.pendingEscape = "";
|
|
8164
|
+
for (let i = 0; i < input.length; i += 1) {
|
|
8165
|
+
let ch = input[i];
|
|
8166
|
+
if (ch === "\x1B") {
|
|
8167
|
+
const consumed = this.consumeEscape(input.slice(i));
|
|
8168
|
+
if (consumed === 0) {
|
|
8169
|
+
this.pendingEscape = input.slice(i);
|
|
8170
|
+
break;
|
|
8171
|
+
}
|
|
8172
|
+
i += consumed - 1;
|
|
8173
|
+
continue;
|
|
8174
|
+
}
|
|
8175
|
+
const cp = input.codePointAt(i);
|
|
8176
|
+
if (cp && cp > 65535) {
|
|
8177
|
+
ch = String.fromCodePoint(cp);
|
|
8178
|
+
i += 1;
|
|
8179
|
+
}
|
|
8180
|
+
this.writeControlOrChar(ch);
|
|
8181
|
+
}
|
|
8182
|
+
return this.getText();
|
|
8183
|
+
}
|
|
8184
|
+
reset() {
|
|
8185
|
+
this.lines = [[]];
|
|
8186
|
+
this.row = 0;
|
|
8187
|
+
this.col = 0;
|
|
8188
|
+
this.savedCursor = null;
|
|
8189
|
+
this.pendingEscape = "";
|
|
8190
|
+
}
|
|
8191
|
+
getText() {
|
|
8192
|
+
return this.lines.map((line) => line.join("").replace(/[ \t]+$/g, "")).join("\n");
|
|
8193
|
+
}
|
|
8194
|
+
ensureRow(row = this.row) {
|
|
8195
|
+
while (this.lines.length <= row) this.lines.push([]);
|
|
8196
|
+
}
|
|
8197
|
+
writeControlOrChar(ch) {
|
|
8198
|
+
if (ch === "\r") {
|
|
8199
|
+
this.col = 0;
|
|
8200
|
+
return;
|
|
8201
|
+
}
|
|
8202
|
+
if (ch === "\n") {
|
|
8203
|
+
this.row += 1;
|
|
8204
|
+
this.col = 0;
|
|
8205
|
+
this.ensureRow();
|
|
8206
|
+
return;
|
|
8207
|
+
}
|
|
8208
|
+
if (ch === "\b") {
|
|
8209
|
+
this.col = Math.max(0, this.col - 1);
|
|
8210
|
+
return;
|
|
8211
|
+
}
|
|
8212
|
+
if (ch < " " || ch === "\x7F") return;
|
|
8213
|
+
this.ensureRow();
|
|
8214
|
+
const line = this.lines[this.row];
|
|
8215
|
+
if (isCombiningMark(ch) && this.col > 0) {
|
|
8216
|
+
line[this.col - 1] = `${line[this.col - 1] || ""}${ch}`;
|
|
8217
|
+
return;
|
|
8218
|
+
}
|
|
8219
|
+
while (line.length < this.col) line.push(" ");
|
|
8220
|
+
const wide = isWideCodePoint(ch);
|
|
8221
|
+
line[this.col] = ch;
|
|
8222
|
+
if (wide) line[this.col + 1] = "";
|
|
8223
|
+
this.col += wide ? 2 : 1;
|
|
8224
|
+
}
|
|
8225
|
+
consumeEscape(seq) {
|
|
8226
|
+
if (seq.length < 2) return 0;
|
|
8227
|
+
const next = seq[1];
|
|
8228
|
+
if (next === "7") {
|
|
8229
|
+
this.savedCursor = { row: this.row, col: this.col };
|
|
8230
|
+
return 2;
|
|
8231
|
+
}
|
|
8232
|
+
if (next === "8") {
|
|
8233
|
+
if (this.savedCursor) {
|
|
8234
|
+
this.row = this.savedCursor.row;
|
|
8235
|
+
this.col = this.savedCursor.col;
|
|
8236
|
+
this.ensureRow();
|
|
8237
|
+
}
|
|
8238
|
+
return 2;
|
|
8239
|
+
}
|
|
8240
|
+
if (next === "]") {
|
|
8241
|
+
const bel = seq.indexOf("\x07", 2);
|
|
8242
|
+
const st = seq.indexOf("\x1B\\", 2);
|
|
8243
|
+
const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
|
|
8244
|
+
return end;
|
|
8245
|
+
}
|
|
8246
|
+
if (next === "[") {
|
|
8247
|
+
const match = seq.match(/^\x1B\[([0-?]*)([ -/]*)([@-~])/);
|
|
8248
|
+
if (!match) return seq.length < 32 ? 0 : 1;
|
|
8249
|
+
this.applyCsi(match[1] || "", match[3]);
|
|
8250
|
+
return match[0].length;
|
|
8251
|
+
}
|
|
8252
|
+
if (/[P^_X]/.test(next)) {
|
|
8253
|
+
const bel = seq.indexOf("\x07", 2);
|
|
8254
|
+
const st = seq.indexOf("\x1B\\", 2);
|
|
8255
|
+
const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
|
|
8256
|
+
return end;
|
|
8257
|
+
}
|
|
8258
|
+
return 2;
|
|
8259
|
+
}
|
|
8260
|
+
applyCsi(params, final) {
|
|
8261
|
+
const count = parseCount(params);
|
|
8262
|
+
this.ensureRow();
|
|
8263
|
+
if (final === "A") this.row = Math.max(0, this.row - count);
|
|
8264
|
+
else if (final === "B") this.row += count;
|
|
8265
|
+
else if (final === "C") {
|
|
8266
|
+
const line = this.lines[this.row];
|
|
8267
|
+
for (let c = this.col; c < this.col + count; c += 1) {
|
|
8268
|
+
if (line[c] === void 0) line[c] = " ";
|
|
8269
|
+
}
|
|
8270
|
+
this.col += count;
|
|
8271
|
+
} else if (final === "D") this.col = Math.max(0, this.col - count);
|
|
8272
|
+
else if (final === "G") this.col = Math.max(0, count - 1);
|
|
8273
|
+
else if (final === "H" || final === "f") {
|
|
8274
|
+
const parts = String(params || "").split(";");
|
|
8275
|
+
this.row = Math.max(0, (Number(parts[0] || 1) || 1) - 1);
|
|
8276
|
+
this.col = Math.max(0, (Number(parts[1] || 1) || 1) - 1);
|
|
8277
|
+
} else if (final === "J") {
|
|
8278
|
+
const mode = Number(params || 0) || 0;
|
|
8279
|
+
if (mode === 2 || mode === 3) {
|
|
8280
|
+
this.lines = [[]];
|
|
8281
|
+
this.row = 0;
|
|
8282
|
+
this.col = 0;
|
|
8283
|
+
} else if (mode === 0) {
|
|
8284
|
+
this.lines[this.row] = this.lines[this.row].slice(0, this.col);
|
|
8285
|
+
this.lines.splice(this.row + 1);
|
|
8286
|
+
} else if (mode === 1) {
|
|
8287
|
+
for (let r = 0; r < this.row; r += 1) this.lines[r] = [];
|
|
8288
|
+
const line = this.lines[this.row];
|
|
8289
|
+
for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
|
|
8290
|
+
}
|
|
8291
|
+
} else if (final === "K") {
|
|
8292
|
+
const mode = Number(params || 0) || 0;
|
|
8293
|
+
const line = this.lines[this.row];
|
|
8294
|
+
if (mode === 2) this.lines[this.row] = [];
|
|
8295
|
+
else if (mode === 1) {
|
|
8296
|
+
for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
|
|
8297
|
+
} else {
|
|
8298
|
+
this.lines[this.row] = line.slice(0, this.col);
|
|
8299
|
+
}
|
|
8300
|
+
} else if (final === "s") {
|
|
8301
|
+
this.savedCursor = { row: this.row, col: this.col };
|
|
8302
|
+
} else if (final === "u") {
|
|
8303
|
+
if (this.savedCursor) {
|
|
8304
|
+
this.row = this.savedCursor.row;
|
|
8305
|
+
this.col = this.savedCursor.col;
|
|
8306
|
+
}
|
|
8307
|
+
}
|
|
8308
|
+
this.ensureRow();
|
|
8309
|
+
}
|
|
8310
|
+
};
|
|
8311
|
+
buildCliSpawnEnv = import_session_host_core2.sanitizeSpawnEnv;
|
|
8312
|
+
}
|
|
8313
|
+
});
|
|
8314
|
+
|
|
7916
8315
|
// src/detection/cli-detector.ts
|
|
7917
8316
|
function parseVersion(raw) {
|
|
7918
8317
|
const match = raw.match(/v?(\d+\.\d+(?:\.\d+)?(?:-[a-zA-Z0-9.]+)?)/);
|
|
@@ -7925,22 +8324,31 @@ function shellQuote(value) {
|
|
|
7925
8324
|
function expandHome(value) {
|
|
7926
8325
|
const trimmed = value.trim();
|
|
7927
8326
|
if (!trimmed.startsWith("~")) return trimmed;
|
|
7928
|
-
return
|
|
8327
|
+
return path11.join(os6.homedir(), trimmed.slice(1));
|
|
7929
8328
|
}
|
|
7930
8329
|
function isExplicitCommandPath(command) {
|
|
7931
8330
|
const trimmed = command.trim();
|
|
7932
|
-
return
|
|
8331
|
+
return path11.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
|
|
7933
8332
|
}
|
|
7934
8333
|
function resolveCommandPath(command) {
|
|
7935
8334
|
const trimmed = command.trim();
|
|
7936
8335
|
if (!trimmed) return null;
|
|
7937
8336
|
if (isExplicitCommandPath(trimmed)) {
|
|
7938
8337
|
const expanded = expandHome(trimmed);
|
|
7939
|
-
const candidate =
|
|
8338
|
+
const candidate = path11.isAbsolute(expanded) ? expanded : path11.resolve(expanded);
|
|
7940
8339
|
return (0, import_fs9.existsSync)(candidate) ? candidate : null;
|
|
7941
8340
|
}
|
|
7942
8341
|
return null;
|
|
7943
8342
|
}
|
|
8343
|
+
async function resolveDetectionPath(command, whichCmd) {
|
|
8344
|
+
const explicitPath = resolveCommandPath(command);
|
|
8345
|
+
if (explicitPath) return explicitPath;
|
|
8346
|
+
const whichResult = await execAsync(`${whichCmd} ${shellQuote(command)}`);
|
|
8347
|
+
if (whichResult) return whichResult.split("\n")[0];
|
|
8348
|
+
const resolved = findBinary(command);
|
|
8349
|
+
if (path11.isAbsolute(resolved) && (0, import_fs9.existsSync)(resolved)) return resolved;
|
|
8350
|
+
return null;
|
|
8351
|
+
}
|
|
7944
8352
|
function execAsync(cmd, timeoutMs = 5e3) {
|
|
7945
8353
|
return new Promise((resolve24) => {
|
|
7946
8354
|
const child = (0, import_child_process.exec)(cmd, {
|
|
@@ -7958,17 +8366,15 @@ function execAsync(cmd, timeoutMs = 5e3) {
|
|
|
7958
8366
|
});
|
|
7959
8367
|
}
|
|
7960
8368
|
async function detectCLIs(providerLoader, options) {
|
|
7961
|
-
const platform10 =
|
|
8369
|
+
const platform10 = os6.platform();
|
|
7962
8370
|
const whichCmd = platform10 === "win32" ? "where" : "which";
|
|
7963
8371
|
const includeVersion = options?.includeVersion !== false;
|
|
7964
8372
|
const cliList = providerLoader ? providerLoader.getCliDetectionList() : [];
|
|
7965
8373
|
const results = await Promise.all(
|
|
7966
8374
|
cliList.map(async (cli) => {
|
|
7967
8375
|
try {
|
|
7968
|
-
const
|
|
7969
|
-
|
|
7970
|
-
if (!pathResult) return { ...cli, installed: false };
|
|
7971
|
-
const firstPath = explicitPath || pathResult.split("\n")[0];
|
|
8376
|
+
const firstPath = await resolveDetectionPath(cli.command, whichCmd);
|
|
8377
|
+
if (!firstPath) return { ...cli, installed: false };
|
|
7972
8378
|
let version;
|
|
7973
8379
|
if (includeVersion) {
|
|
7974
8380
|
const versionCommands = [
|
|
@@ -8002,13 +8408,11 @@ async function detectCLI(cliId, providerLoader, options) {
|
|
|
8002
8408
|
const cliList = providerLoader.getCliDetectionList();
|
|
8003
8409
|
const target = cliList.find((c) => c.id === resolvedId);
|
|
8004
8410
|
if (target) {
|
|
8005
|
-
const platform10 =
|
|
8411
|
+
const platform10 = os6.platform();
|
|
8006
8412
|
const whichCmd = platform10 === "win32" ? "where" : "which";
|
|
8007
8413
|
try {
|
|
8008
|
-
const
|
|
8009
|
-
|
|
8010
|
-
if (!pathResult) return null;
|
|
8011
|
-
const firstPath = explicitPath || pathResult.split("\n")[0];
|
|
8414
|
+
const firstPath = await resolveDetectionPath(target.command, whichCmd);
|
|
8415
|
+
if (!firstPath) return null;
|
|
8012
8416
|
let version;
|
|
8013
8417
|
if (options?.includeVersion !== false) {
|
|
8014
8418
|
const versionCommands = [
|
|
@@ -8037,14 +8441,15 @@ async function detectCLI(cliId, providerLoader, options) {
|
|
|
8037
8441
|
const all = await detectCLIs(providerLoader, options);
|
|
8038
8442
|
return all.find((c) => c.id === resolvedId && c.installed) || null;
|
|
8039
8443
|
}
|
|
8040
|
-
var import_child_process,
|
|
8444
|
+
var import_child_process, os6, path11, import_fs9;
|
|
8041
8445
|
var init_cli_detector = __esm({
|
|
8042
8446
|
"src/detection/cli-detector.ts"() {
|
|
8043
8447
|
"use strict";
|
|
8044
8448
|
import_child_process = require("child_process");
|
|
8045
|
-
|
|
8046
|
-
|
|
8449
|
+
os6 = __toESM(require("os"));
|
|
8450
|
+
path11 = __toESM(require("path"));
|
|
8047
8451
|
import_fs9 = require("fs");
|
|
8452
|
+
init_provider_cli_shared();
|
|
8048
8453
|
}
|
|
8049
8454
|
});
|
|
8050
8455
|
|
|
@@ -10648,16 +11053,16 @@ __export(external_sources_exports, {
|
|
|
10648
11053
|
sourcesProviding: () => sourcesProviding
|
|
10649
11054
|
});
|
|
10650
11055
|
function adhdevDir() {
|
|
10651
|
-
return
|
|
11056
|
+
return path16.join(os11.homedir(), ".adhdev");
|
|
10652
11057
|
}
|
|
10653
11058
|
function externalRoot() {
|
|
10654
|
-
return
|
|
11059
|
+
return path16.join(adhdevDir(), "external");
|
|
10655
11060
|
}
|
|
10656
11061
|
function sourcesFilePath() {
|
|
10657
|
-
return
|
|
11062
|
+
return path16.join(adhdevDir(), SOURCES_FILENAME);
|
|
10658
11063
|
}
|
|
10659
11064
|
function activeFilePath() {
|
|
10660
|
-
return
|
|
11065
|
+
return path16.join(adhdevDir(), ACTIVE_FILENAME);
|
|
10661
11066
|
}
|
|
10662
11067
|
function ensureAdhdevDir() {
|
|
10663
11068
|
const d = adhdevDir();
|
|
@@ -10724,7 +11129,7 @@ function inventoryExternalSources() {
|
|
|
10724
11129
|
for (const sourceEntry of entries) {
|
|
10725
11130
|
if (!sourceEntry.isDirectory()) continue;
|
|
10726
11131
|
const sourceName = sourceEntry.name;
|
|
10727
|
-
const sourceDir =
|
|
11132
|
+
const sourceDir = path16.join(root, sourceName);
|
|
10728
11133
|
const providers = {};
|
|
10729
11134
|
let categoryEntries;
|
|
10730
11135
|
try {
|
|
@@ -10735,7 +11140,7 @@ function inventoryExternalSources() {
|
|
|
10735
11140
|
for (const categoryEntry of categoryEntries) {
|
|
10736
11141
|
if (!categoryEntry.isDirectory()) continue;
|
|
10737
11142
|
const category = categoryEntry.name;
|
|
10738
|
-
const categoryDir =
|
|
11143
|
+
const categoryDir = path16.join(sourceDir, category);
|
|
10739
11144
|
let typeEntries;
|
|
10740
11145
|
try {
|
|
10741
11146
|
typeEntries = fs8.readdirSync(categoryDir, { withFileTypes: true });
|
|
@@ -10745,9 +11150,9 @@ function inventoryExternalSources() {
|
|
|
10745
11150
|
const types = [];
|
|
10746
11151
|
for (const typeEntry of typeEntries) {
|
|
10747
11152
|
if (!typeEntry.isDirectory()) continue;
|
|
10748
|
-
const typeDir =
|
|
10749
|
-
const hasV1 = fs8.existsSync(
|
|
10750
|
-
const hasV0 = fs8.existsSync(
|
|
11153
|
+
const typeDir = path16.join(categoryDir, typeEntry.name);
|
|
11154
|
+
const hasV1 = fs8.existsSync(path16.join(typeDir, "provider.v1.json"));
|
|
11155
|
+
const hasV0 = fs8.existsSync(path16.join(typeDir, "provider.json"));
|
|
10751
11156
|
if (hasV1 || hasV0) types.push(typeEntry.name);
|
|
10752
11157
|
}
|
|
10753
11158
|
if (types.length > 0) providers[category] = types;
|
|
@@ -10770,13 +11175,13 @@ function resolveActiveSource(category, type, activeFile) {
|
|
|
10770
11175
|
}
|
|
10771
11176
|
return { source: candidates[0], ambiguous: true, candidates };
|
|
10772
11177
|
}
|
|
10773
|
-
var fs8,
|
|
11178
|
+
var fs8, os11, path16, SOURCES_FILENAME, ACTIVE_FILENAME;
|
|
10774
11179
|
var init_external_sources = __esm({
|
|
10775
11180
|
"src/providers/external-sources.ts"() {
|
|
10776
11181
|
"use strict";
|
|
10777
11182
|
fs8 = __toESM(require("fs"));
|
|
10778
|
-
|
|
10779
|
-
|
|
11183
|
+
os11 = __toESM(require("os"));
|
|
11184
|
+
path16 = __toESM(require("path"));
|
|
10780
11185
|
SOURCES_FILENAME = "providers-sources.json";
|
|
10781
11186
|
ACTIVE_FILENAME = "providers-active.json";
|
|
10782
11187
|
}
|
|
@@ -10899,19 +11304,19 @@ var init_ghostty_vt_backend = __esm({
|
|
|
10899
11304
|
function getTerminalBackendRuntimeStatus() {
|
|
10900
11305
|
return { backend: "ghostty-vt" };
|
|
10901
11306
|
}
|
|
10902
|
-
var
|
|
11307
|
+
var import_session_host_core3, DEFAULT_SCROLLBACK, TerminalScreen;
|
|
10903
11308
|
var init_terminal_screen = __esm({
|
|
10904
11309
|
"src/cli-adapters/terminal-screen.ts"() {
|
|
10905
11310
|
"use strict";
|
|
10906
11311
|
init_ghostty_vt_backend();
|
|
10907
|
-
|
|
11312
|
+
import_session_host_core3 = require("@adhdev/session-host-core");
|
|
10908
11313
|
DEFAULT_SCROLLBACK = 2e3;
|
|
10909
11314
|
TerminalScreen = class {
|
|
10910
11315
|
backendKind = "ghostty-vt";
|
|
10911
11316
|
rows;
|
|
10912
11317
|
cols;
|
|
10913
11318
|
terminal;
|
|
10914
|
-
constructor(rows =
|
|
11319
|
+
constructor(rows = import_session_host_core3.DEFAULT_SESSION_HOST_ROWS, cols = import_session_host_core3.DEFAULT_SESSION_HOST_COLS) {
|
|
10915
11320
|
this.rows = Math.max(1, rows | 0);
|
|
10916
11321
|
this.cols = Math.max(1, cols | 0);
|
|
10917
11322
|
this.terminal = this.createBackend();
|
|
@@ -10954,21 +11359,31 @@ var init_terminal_screen = __esm({
|
|
|
10954
11359
|
}
|
|
10955
11360
|
});
|
|
10956
11361
|
|
|
10957
|
-
// src/cli-adapters/spawn-env.ts
|
|
10958
|
-
var import_session_host_core3;
|
|
10959
|
-
var init_spawn_env = __esm({
|
|
10960
|
-
"src/cli-adapters/spawn-env.ts"() {
|
|
10961
|
-
"use strict";
|
|
10962
|
-
import_session_host_core3 = require("@adhdev/session-host-core");
|
|
10963
|
-
}
|
|
10964
|
-
});
|
|
10965
|
-
|
|
10966
11362
|
// src/cli-adapters/resolve-executable.ts
|
|
11363
|
+
function resolveWin32GlobalBin(trimmed) {
|
|
11364
|
+
if (path17.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\")) {
|
|
11365
|
+
return null;
|
|
11366
|
+
}
|
|
11367
|
+
const extraDirs = [];
|
|
11368
|
+
if (process.env.APPDATA) extraDirs.push(path17.join(process.env.APPDATA, "npm"));
|
|
11369
|
+
try {
|
|
11370
|
+
extraDirs.push(path17.dirname(process.execPath));
|
|
11371
|
+
} catch {
|
|
11372
|
+
}
|
|
11373
|
+
for (const dir of extraDirs) {
|
|
11374
|
+
if (!dir) continue;
|
|
11375
|
+
for (const ext of WIN_EXEC_EXT) {
|
|
11376
|
+
const full = path17.join(dir, trimmed + ext);
|
|
11377
|
+
if ((0, import_fs13.existsSync)(full)) return full;
|
|
11378
|
+
}
|
|
11379
|
+
}
|
|
11380
|
+
return null;
|
|
11381
|
+
}
|
|
10967
11382
|
function resolveWin32Executable(command) {
|
|
10968
11383
|
if (process.platform !== "win32") return command;
|
|
10969
11384
|
const trimmed = (command || "").trim();
|
|
10970
11385
|
if (!trimmed) return command;
|
|
10971
|
-
if (
|
|
11386
|
+
if (path17.isAbsolute(trimmed) && (0, import_fs13.existsSync)(trimmed)) return trimmed;
|
|
10972
11387
|
try {
|
|
10973
11388
|
const out = (0, import_child_process4.execFileSync)("where", [trimmed], {
|
|
10974
11389
|
encoding: "utf8",
|
|
@@ -10976,21 +11391,24 @@ function resolveWin32Executable(command) {
|
|
|
10976
11391
|
}).trim();
|
|
10977
11392
|
if (out) {
|
|
10978
11393
|
const matches = out.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
|
|
10979
|
-
const direct = matches.find((m) => DIRECT_EXEC_EXT.has(
|
|
11394
|
+
const direct = matches.find((m) => DIRECT_EXEC_EXT.has(path17.extname(m).toLowerCase()));
|
|
10980
11395
|
return direct || matches[0] || command;
|
|
10981
11396
|
}
|
|
10982
11397
|
} catch {
|
|
10983
11398
|
}
|
|
11399
|
+
const globalBin = resolveWin32GlobalBin(trimmed);
|
|
11400
|
+
if (globalBin) return globalBin;
|
|
10984
11401
|
return command;
|
|
10985
11402
|
}
|
|
10986
|
-
var import_child_process4, import_fs13,
|
|
11403
|
+
var import_child_process4, import_fs13, path17, DIRECT_EXEC_EXT, WIN_EXEC_EXT;
|
|
10987
11404
|
var init_resolve_executable = __esm({
|
|
10988
11405
|
"src/cli-adapters/resolve-executable.ts"() {
|
|
10989
11406
|
"use strict";
|
|
10990
11407
|
import_child_process4 = require("child_process");
|
|
10991
11408
|
import_fs13 = require("fs");
|
|
10992
|
-
|
|
11409
|
+
path17 = __toESM(require("path"));
|
|
10993
11410
|
DIRECT_EXEC_EXT = /* @__PURE__ */ new Set([".exe", ".com"]);
|
|
11411
|
+
WIN_EXEC_EXT = [".exe", ".com", ".cmd", ".bat"];
|
|
10994
11412
|
}
|
|
10995
11413
|
});
|
|
10996
11414
|
|
|
@@ -11003,17 +11421,17 @@ function loadNodePty() {
|
|
|
11003
11421
|
if (cachedPty !== void 0) return cachedPty;
|
|
11004
11422
|
try {
|
|
11005
11423
|
cachedPty = require("node-pty");
|
|
11006
|
-
(0,
|
|
11424
|
+
(0, import_session_host_core2.ensureNodePtySpawnHelperPermissions)();
|
|
11007
11425
|
} catch {
|
|
11008
11426
|
cachedPty = null;
|
|
11009
11427
|
}
|
|
11010
11428
|
return cachedPty;
|
|
11011
11429
|
}
|
|
11012
|
-
var
|
|
11430
|
+
var os12, cachedPty, NodePtyRuntimeTransport, NodePtyTransportFactory;
|
|
11013
11431
|
var init_pty_transport = __esm({
|
|
11014
11432
|
"src/cli-adapters/pty-transport.ts"() {
|
|
11015
11433
|
"use strict";
|
|
11016
|
-
|
|
11434
|
+
os12 = __toESM(require("os"));
|
|
11017
11435
|
init_spawn_env();
|
|
11018
11436
|
init_resolve_executable();
|
|
11019
11437
|
NodePtyRuntimeTransport = class {
|
|
@@ -11053,9 +11471,9 @@ var init_pty_transport = __esm({
|
|
|
11053
11471
|
try {
|
|
11054
11472
|
const fs31 = require("fs");
|
|
11055
11473
|
const stat2 = fs31.statSync(cwd);
|
|
11056
|
-
if (!stat2.isDirectory()) cwd =
|
|
11474
|
+
if (!stat2.isDirectory()) cwd = os12.homedir();
|
|
11057
11475
|
} catch {
|
|
11058
|
-
cwd =
|
|
11476
|
+
cwd = os12.homedir();
|
|
11059
11477
|
}
|
|
11060
11478
|
}
|
|
11061
11479
|
const handle = pty.spawn(resolveWin32Executable(command), args, {
|
|
@@ -11071,396 +11489,6 @@ var init_pty_transport = __esm({
|
|
|
11071
11489
|
}
|
|
11072
11490
|
});
|
|
11073
11491
|
|
|
11074
|
-
// src/cli-adapters/provider-cli-shared.ts
|
|
11075
|
-
function stripAnsi(str) {
|
|
11076
|
-
return str.replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
11077
|
-
}
|
|
11078
|
-
function parseCount(params, fallback = 1) {
|
|
11079
|
-
const first = Number(String(params || "").split(";")[0] || fallback);
|
|
11080
|
-
return Math.max(1, Number.isFinite(first) ? first : fallback);
|
|
11081
|
-
}
|
|
11082
|
-
function isCombiningMark(ch) {
|
|
11083
|
-
return /[\u0300-\u036F\u1AB0-\u1AFF\u1DC0-\u1DFF\u20D0-\u20FF\uFE20-\uFE2F]/.test(ch);
|
|
11084
|
-
}
|
|
11085
|
-
function isWideCodePoint(ch) {
|
|
11086
|
-
const cp = ch.codePointAt(0) || 0;
|
|
11087
|
-
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);
|
|
11088
|
-
}
|
|
11089
|
-
function stripTerminalNoise(str) {
|
|
11090
|
-
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");
|
|
11091
|
-
}
|
|
11092
|
-
function sanitizeTerminalText(str) {
|
|
11093
|
-
const accumulator = new TerminalTranscriptAccumulator();
|
|
11094
|
-
return stripTerminalNoise(stripAnsi(accumulator.append(str)));
|
|
11095
|
-
}
|
|
11096
|
-
function listCliScriptNames(scripts) {
|
|
11097
|
-
if (!scripts) return [];
|
|
11098
|
-
return Object.entries(scripts).filter(([, fn]) => typeof fn === "function").map(([name]) => name);
|
|
11099
|
-
}
|
|
11100
|
-
function splitCliScreenLines(text) {
|
|
11101
|
-
return String(text || "").replace(/\u0007/g, "").replace(/\r\n/g, "\n").replace(/\r/g, "\n").split("\n").map((line) => line.replace(/\s+$/, ""));
|
|
11102
|
-
}
|
|
11103
|
-
function isPromptLikeCliLine(line) {
|
|
11104
|
-
const trimmed = String(line || "").trim();
|
|
11105
|
-
if (!trimmed) return false;
|
|
11106
|
-
return /^[❯›>]\s*(?:$|\S.*)$/.test(trimmed);
|
|
11107
|
-
}
|
|
11108
|
-
function buildCliScreenSnapshot(text) {
|
|
11109
|
-
const normalizedText = String(text || "").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
11110
|
-
const rawLines = splitCliScreenLines(normalizedText);
|
|
11111
|
-
const lines = rawLines.map((line, index, arr) => {
|
|
11112
|
-
const trimmed = String(line || "").trim();
|
|
11113
|
-
return {
|
|
11114
|
-
index,
|
|
11115
|
-
fromTop: index,
|
|
11116
|
-
fromBottom: arr.length - index - 1,
|
|
11117
|
-
text: line,
|
|
11118
|
-
trimmed,
|
|
11119
|
-
isEmpty: trimmed.length === 0
|
|
11120
|
-
};
|
|
11121
|
-
});
|
|
11122
|
-
const nonEmptyLines = lines.filter((line) => !line.isEmpty);
|
|
11123
|
-
const firstNonEmptyLine = nonEmptyLines[0] ?? null;
|
|
11124
|
-
const lastNonEmptyLine = nonEmptyLines[nonEmptyLines.length - 1] ?? null;
|
|
11125
|
-
let promptLineIndex = -1;
|
|
11126
|
-
for (let i = lines.length - 1; i >= 0; i -= 1) {
|
|
11127
|
-
if (isPromptLikeCliLine(lines[i].text)) {
|
|
11128
|
-
promptLineIndex = i;
|
|
11129
|
-
break;
|
|
11130
|
-
}
|
|
11131
|
-
}
|
|
11132
|
-
return {
|
|
11133
|
-
text: normalizedText,
|
|
11134
|
-
lineCount: lines.length,
|
|
11135
|
-
lines,
|
|
11136
|
-
nonEmptyLines,
|
|
11137
|
-
firstNonEmptyLineIndex: firstNonEmptyLine?.index ?? -1,
|
|
11138
|
-
lastNonEmptyLineIndex: lastNonEmptyLine?.index ?? -1,
|
|
11139
|
-
firstNonEmptyLine,
|
|
11140
|
-
lastNonEmptyLine,
|
|
11141
|
-
promptLineIndex,
|
|
11142
|
-
promptLine: promptLineIndex >= 0 ? lines[promptLineIndex] : null,
|
|
11143
|
-
linesAbovePrompt: promptLineIndex >= 0 ? lines.slice(0, promptLineIndex) : [...lines],
|
|
11144
|
-
linesBelowPrompt: promptLineIndex >= 0 ? lines.slice(promptLineIndex + 1) : []
|
|
11145
|
-
};
|
|
11146
|
-
}
|
|
11147
|
-
function findBinary(name) {
|
|
11148
|
-
const trimmed = String(name || "").trim();
|
|
11149
|
-
if (!trimmed) return trimmed;
|
|
11150
|
-
const expanded = trimmed.startsWith("~") ? path17.join(os12.homedir(), trimmed.slice(1)) : trimmed;
|
|
11151
|
-
if (path17.isAbsolute(expanded) || expanded.includes("/") || expanded.includes("\\")) {
|
|
11152
|
-
return path17.isAbsolute(expanded) ? expanded : path17.resolve(expanded);
|
|
11153
|
-
}
|
|
11154
|
-
const isWin = os12.platform() === "win32";
|
|
11155
|
-
const paths = (process.env.PATH || "").split(path17.delimiter);
|
|
11156
|
-
const extraDirs = [];
|
|
11157
|
-
if (isWin) {
|
|
11158
|
-
if (process.env.APPDATA) extraDirs.push(path17.join(process.env.APPDATA, "npm"));
|
|
11159
|
-
try {
|
|
11160
|
-
extraDirs.push(path17.dirname(process.execPath));
|
|
11161
|
-
} catch {
|
|
11162
|
-
}
|
|
11163
|
-
} else {
|
|
11164
|
-
extraDirs.push(path17.join(os12.homedir(), ".npm-global", "bin"));
|
|
11165
|
-
extraDirs.push("/usr/local/bin", "/opt/homebrew/bin");
|
|
11166
|
-
try {
|
|
11167
|
-
extraDirs.push(path17.dirname(process.execPath));
|
|
11168
|
-
} catch {
|
|
11169
|
-
}
|
|
11170
|
-
}
|
|
11171
|
-
const searchDirs = [...paths, ...extraDirs];
|
|
11172
|
-
const exes = isWin ? [".exe", ".cmd", ".bat", ""] : [""];
|
|
11173
|
-
for (const p of searchDirs) {
|
|
11174
|
-
if (!p) continue;
|
|
11175
|
-
for (const ext of exes) {
|
|
11176
|
-
const fullPath = path17.join(p, trimmed + ext);
|
|
11177
|
-
try {
|
|
11178
|
-
const fs31 = require("fs");
|
|
11179
|
-
if (fs31.existsSync(fullPath)) {
|
|
11180
|
-
const stat2 = fs31.statSync(fullPath);
|
|
11181
|
-
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
11182
|
-
return fullPath;
|
|
11183
|
-
}
|
|
11184
|
-
}
|
|
11185
|
-
} catch {
|
|
11186
|
-
}
|
|
11187
|
-
}
|
|
11188
|
-
}
|
|
11189
|
-
return isWin ? `${trimmed}.cmd` : trimmed;
|
|
11190
|
-
}
|
|
11191
|
-
function isScriptBinary(binaryPath) {
|
|
11192
|
-
if (!path17.isAbsolute(binaryPath)) return false;
|
|
11193
|
-
try {
|
|
11194
|
-
const fs31 = require("fs");
|
|
11195
|
-
const resolved = fs31.realpathSync(binaryPath);
|
|
11196
|
-
const head = Buffer.alloc(8);
|
|
11197
|
-
const fd = fs31.openSync(resolved, "r");
|
|
11198
|
-
fs31.readSync(fd, head, 0, 8, 0);
|
|
11199
|
-
fs31.closeSync(fd);
|
|
11200
|
-
let i = 0;
|
|
11201
|
-
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
11202
|
-
return head[i] === 35 && head[i + 1] === 33;
|
|
11203
|
-
} catch {
|
|
11204
|
-
return false;
|
|
11205
|
-
}
|
|
11206
|
-
}
|
|
11207
|
-
function looksLikeMachOOrElf(filePath) {
|
|
11208
|
-
if (!path17.isAbsolute(filePath)) return false;
|
|
11209
|
-
try {
|
|
11210
|
-
const fs31 = require("fs");
|
|
11211
|
-
const resolved = fs31.realpathSync(filePath);
|
|
11212
|
-
const buf = Buffer.alloc(8);
|
|
11213
|
-
const fd = fs31.openSync(resolved, "r");
|
|
11214
|
-
fs31.readSync(fd, buf, 0, 8, 0);
|
|
11215
|
-
fs31.closeSync(fd);
|
|
11216
|
-
let i = 0;
|
|
11217
|
-
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
11218
|
-
const b = buf.subarray(i);
|
|
11219
|
-
if (b.length < 4) return false;
|
|
11220
|
-
if (b[0] === 127 && b[1] === 69 && b[2] === 76 && b[3] === 70) return true;
|
|
11221
|
-
const le = b.readUInt32LE(0);
|
|
11222
|
-
const be = b.readUInt32BE(0);
|
|
11223
|
-
const magics = [4277009102, 4277009103, 3405691582, 3199925962];
|
|
11224
|
-
return magics.some((m) => m === le || m === be);
|
|
11225
|
-
} catch {
|
|
11226
|
-
return false;
|
|
11227
|
-
}
|
|
11228
|
-
}
|
|
11229
|
-
function shSingleQuote(arg) {
|
|
11230
|
-
if (/^[a-zA-Z0-9@%_+=:,./-]+$/.test(arg)) return arg;
|
|
11231
|
-
if (os12.platform() === "win32") {
|
|
11232
|
-
return `"${arg.replace(/"/g, '""')}"`;
|
|
11233
|
-
}
|
|
11234
|
-
return `'${arg.replace(/'/g, `'\\''`)}'`;
|
|
11235
|
-
}
|
|
11236
|
-
function estimatePromptDisplayLines(text, cols = 80) {
|
|
11237
|
-
const normalized = String(text || "").replace(/\r/g, "");
|
|
11238
|
-
if (!normalized) return 1;
|
|
11239
|
-
return normalized.split("\n").reduce((sum, line) => sum + Math.max(1, Math.ceil(Math.max(1, line.length) / cols)), 0);
|
|
11240
|
-
}
|
|
11241
|
-
function extractPromptRetrySnippet(text) {
|
|
11242
|
-
const lines = String(text || "").replace(/\r/g, "").split("\n").map((line) => line.trim()).filter(Boolean);
|
|
11243
|
-
const candidate = lines[lines.length - 1] || lines[0] || "";
|
|
11244
|
-
return candidate.slice(-120);
|
|
11245
|
-
}
|
|
11246
|
-
function normalizePromptText(text) {
|
|
11247
|
-
return String(text || "").replace(/\s+/g, " ").trim();
|
|
11248
|
-
}
|
|
11249
|
-
function compactPromptText(text) {
|
|
11250
|
-
return String(text || "").replace(/\s+/g, "").trim();
|
|
11251
|
-
}
|
|
11252
|
-
function promptLikelyVisible(screenText, promptSnippet) {
|
|
11253
|
-
const snippet = normalizePromptText(promptSnippet);
|
|
11254
|
-
if (!snippet) return false;
|
|
11255
|
-
const normalizedScreen = normalizePromptText(screenText);
|
|
11256
|
-
if (normalizedScreen.includes(snippet)) return true;
|
|
11257
|
-
const compactScreen = compactPromptText(screenText);
|
|
11258
|
-
const compactSnippet = compactPromptText(promptSnippet);
|
|
11259
|
-
if (compactSnippet && compactScreen.includes(compactSnippet)) return true;
|
|
11260
|
-
const tokens = snippet.split(/[^A-Za-z0-9_.:/-]+/).map((token) => token.trim()).filter((token) => token.length >= 4);
|
|
11261
|
-
if (tokens.length === 0) return false;
|
|
11262
|
-
const required = Math.min(tokens.length, 3);
|
|
11263
|
-
const matched = tokens.filter(
|
|
11264
|
-
(token) => normalizedScreen.includes(token) || compactScreen.includes(compactPromptText(token))
|
|
11265
|
-
).length;
|
|
11266
|
-
return matched >= required;
|
|
11267
|
-
}
|
|
11268
|
-
function normalizeScreenSnapshot(text) {
|
|
11269
|
-
return sanitizeTerminalText(String(text || "")).replace(/\s+/g, " ").trim();
|
|
11270
|
-
}
|
|
11271
|
-
function parsePatternEntry(x) {
|
|
11272
|
-
if (x instanceof RegExp) return x;
|
|
11273
|
-
if (x && typeof x === "object" && typeof x.source === "string") {
|
|
11274
|
-
try {
|
|
11275
|
-
const s = x;
|
|
11276
|
-
return new RegExp(s.source, s.flags || "");
|
|
11277
|
-
} catch {
|
|
11278
|
-
return null;
|
|
11279
|
-
}
|
|
11280
|
-
}
|
|
11281
|
-
return null;
|
|
11282
|
-
}
|
|
11283
|
-
function coercePatternArray(raw) {
|
|
11284
|
-
if (!Array.isArray(raw)) return [];
|
|
11285
|
-
return raw.map(parsePatternEntry).filter((r) => r != null);
|
|
11286
|
-
}
|
|
11287
|
-
function normalizeCliProviderForRuntime(raw) {
|
|
11288
|
-
const patterns = raw && typeof raw === "object" ? raw.patterns : void 0;
|
|
11289
|
-
return {
|
|
11290
|
-
patterns: {
|
|
11291
|
-
approval: coercePatternArray(
|
|
11292
|
-
patterns && typeof patterns === "object" ? patterns.approval : void 0
|
|
11293
|
-
)
|
|
11294
|
-
}
|
|
11295
|
-
};
|
|
11296
|
-
}
|
|
11297
|
-
var os12, path17, TerminalTranscriptAccumulator, buildCliSpawnEnv;
|
|
11298
|
-
var init_provider_cli_shared = __esm({
|
|
11299
|
-
"src/cli-adapters/provider-cli-shared.ts"() {
|
|
11300
|
-
"use strict";
|
|
11301
|
-
os12 = __toESM(require("os"));
|
|
11302
|
-
path17 = __toESM(require("path"));
|
|
11303
|
-
init_spawn_env();
|
|
11304
|
-
TerminalTranscriptAccumulator = class {
|
|
11305
|
-
lines = [[]];
|
|
11306
|
-
row = 0;
|
|
11307
|
-
col = 0;
|
|
11308
|
-
savedCursor = null;
|
|
11309
|
-
pendingEscape = "";
|
|
11310
|
-
append(data) {
|
|
11311
|
-
const input = this.pendingEscape + String(data || "");
|
|
11312
|
-
this.pendingEscape = "";
|
|
11313
|
-
for (let i = 0; i < input.length; i += 1) {
|
|
11314
|
-
let ch = input[i];
|
|
11315
|
-
if (ch === "\x1B") {
|
|
11316
|
-
const consumed = this.consumeEscape(input.slice(i));
|
|
11317
|
-
if (consumed === 0) {
|
|
11318
|
-
this.pendingEscape = input.slice(i);
|
|
11319
|
-
break;
|
|
11320
|
-
}
|
|
11321
|
-
i += consumed - 1;
|
|
11322
|
-
continue;
|
|
11323
|
-
}
|
|
11324
|
-
const cp = input.codePointAt(i);
|
|
11325
|
-
if (cp && cp > 65535) {
|
|
11326
|
-
ch = String.fromCodePoint(cp);
|
|
11327
|
-
i += 1;
|
|
11328
|
-
}
|
|
11329
|
-
this.writeControlOrChar(ch);
|
|
11330
|
-
}
|
|
11331
|
-
return this.getText();
|
|
11332
|
-
}
|
|
11333
|
-
reset() {
|
|
11334
|
-
this.lines = [[]];
|
|
11335
|
-
this.row = 0;
|
|
11336
|
-
this.col = 0;
|
|
11337
|
-
this.savedCursor = null;
|
|
11338
|
-
this.pendingEscape = "";
|
|
11339
|
-
}
|
|
11340
|
-
getText() {
|
|
11341
|
-
return this.lines.map((line) => line.join("").replace(/[ \t]+$/g, "")).join("\n");
|
|
11342
|
-
}
|
|
11343
|
-
ensureRow(row = this.row) {
|
|
11344
|
-
while (this.lines.length <= row) this.lines.push([]);
|
|
11345
|
-
}
|
|
11346
|
-
writeControlOrChar(ch) {
|
|
11347
|
-
if (ch === "\r") {
|
|
11348
|
-
this.col = 0;
|
|
11349
|
-
return;
|
|
11350
|
-
}
|
|
11351
|
-
if (ch === "\n") {
|
|
11352
|
-
this.row += 1;
|
|
11353
|
-
this.col = 0;
|
|
11354
|
-
this.ensureRow();
|
|
11355
|
-
return;
|
|
11356
|
-
}
|
|
11357
|
-
if (ch === "\b") {
|
|
11358
|
-
this.col = Math.max(0, this.col - 1);
|
|
11359
|
-
return;
|
|
11360
|
-
}
|
|
11361
|
-
if (ch < " " || ch === "\x7F") return;
|
|
11362
|
-
this.ensureRow();
|
|
11363
|
-
const line = this.lines[this.row];
|
|
11364
|
-
if (isCombiningMark(ch) && this.col > 0) {
|
|
11365
|
-
line[this.col - 1] = `${line[this.col - 1] || ""}${ch}`;
|
|
11366
|
-
return;
|
|
11367
|
-
}
|
|
11368
|
-
while (line.length < this.col) line.push(" ");
|
|
11369
|
-
const wide = isWideCodePoint(ch);
|
|
11370
|
-
line[this.col] = ch;
|
|
11371
|
-
if (wide) line[this.col + 1] = "";
|
|
11372
|
-
this.col += wide ? 2 : 1;
|
|
11373
|
-
}
|
|
11374
|
-
consumeEscape(seq) {
|
|
11375
|
-
if (seq.length < 2) return 0;
|
|
11376
|
-
const next = seq[1];
|
|
11377
|
-
if (next === "7") {
|
|
11378
|
-
this.savedCursor = { row: this.row, col: this.col };
|
|
11379
|
-
return 2;
|
|
11380
|
-
}
|
|
11381
|
-
if (next === "8") {
|
|
11382
|
-
if (this.savedCursor) {
|
|
11383
|
-
this.row = this.savedCursor.row;
|
|
11384
|
-
this.col = this.savedCursor.col;
|
|
11385
|
-
this.ensureRow();
|
|
11386
|
-
}
|
|
11387
|
-
return 2;
|
|
11388
|
-
}
|
|
11389
|
-
if (next === "]") {
|
|
11390
|
-
const bel = seq.indexOf("\x07", 2);
|
|
11391
|
-
const st = seq.indexOf("\x1B\\", 2);
|
|
11392
|
-
const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
|
|
11393
|
-
return end;
|
|
11394
|
-
}
|
|
11395
|
-
if (next === "[") {
|
|
11396
|
-
const match = seq.match(/^\x1B\[([0-?]*)([ -/]*)([@-~])/);
|
|
11397
|
-
if (!match) return seq.length < 32 ? 0 : 1;
|
|
11398
|
-
this.applyCsi(match[1] || "", match[3]);
|
|
11399
|
-
return match[0].length;
|
|
11400
|
-
}
|
|
11401
|
-
if (/[P^_X]/.test(next)) {
|
|
11402
|
-
const bel = seq.indexOf("\x07", 2);
|
|
11403
|
-
const st = seq.indexOf("\x1B\\", 2);
|
|
11404
|
-
const end = bel >= 0 && (st < 0 || bel < st) ? bel + 1 : st >= 0 ? st + 2 : 0;
|
|
11405
|
-
return end;
|
|
11406
|
-
}
|
|
11407
|
-
return 2;
|
|
11408
|
-
}
|
|
11409
|
-
applyCsi(params, final) {
|
|
11410
|
-
const count = parseCount(params);
|
|
11411
|
-
this.ensureRow();
|
|
11412
|
-
if (final === "A") this.row = Math.max(0, this.row - count);
|
|
11413
|
-
else if (final === "B") this.row += count;
|
|
11414
|
-
else if (final === "C") {
|
|
11415
|
-
const line = this.lines[this.row];
|
|
11416
|
-
for (let c = this.col; c < this.col + count; c += 1) {
|
|
11417
|
-
if (line[c] === void 0) line[c] = " ";
|
|
11418
|
-
}
|
|
11419
|
-
this.col += count;
|
|
11420
|
-
} else if (final === "D") this.col = Math.max(0, this.col - count);
|
|
11421
|
-
else if (final === "G") this.col = Math.max(0, count - 1);
|
|
11422
|
-
else if (final === "H" || final === "f") {
|
|
11423
|
-
const parts = String(params || "").split(";");
|
|
11424
|
-
this.row = Math.max(0, (Number(parts[0] || 1) || 1) - 1);
|
|
11425
|
-
this.col = Math.max(0, (Number(parts[1] || 1) || 1) - 1);
|
|
11426
|
-
} else if (final === "J") {
|
|
11427
|
-
const mode = Number(params || 0) || 0;
|
|
11428
|
-
if (mode === 2 || mode === 3) {
|
|
11429
|
-
this.lines = [[]];
|
|
11430
|
-
this.row = 0;
|
|
11431
|
-
this.col = 0;
|
|
11432
|
-
} else if (mode === 0) {
|
|
11433
|
-
this.lines[this.row] = this.lines[this.row].slice(0, this.col);
|
|
11434
|
-
this.lines.splice(this.row + 1);
|
|
11435
|
-
} else if (mode === 1) {
|
|
11436
|
-
for (let r = 0; r < this.row; r += 1) this.lines[r] = [];
|
|
11437
|
-
const line = this.lines[this.row];
|
|
11438
|
-
for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
|
|
11439
|
-
}
|
|
11440
|
-
} else if (final === "K") {
|
|
11441
|
-
const mode = Number(params || 0) || 0;
|
|
11442
|
-
const line = this.lines[this.row];
|
|
11443
|
-
if (mode === 2) this.lines[this.row] = [];
|
|
11444
|
-
else if (mode === 1) {
|
|
11445
|
-
for (let c = 0; c <= Math.min(this.col, line.length - 1); c += 1) line[c] = " ";
|
|
11446
|
-
} else {
|
|
11447
|
-
this.lines[this.row] = line.slice(0, this.col);
|
|
11448
|
-
}
|
|
11449
|
-
} else if (final === "s") {
|
|
11450
|
-
this.savedCursor = { row: this.row, col: this.col };
|
|
11451
|
-
} else if (final === "u") {
|
|
11452
|
-
if (this.savedCursor) {
|
|
11453
|
-
this.row = this.savedCursor.row;
|
|
11454
|
-
this.col = this.savedCursor.col;
|
|
11455
|
-
}
|
|
11456
|
-
}
|
|
11457
|
-
this.ensureRow();
|
|
11458
|
-
}
|
|
11459
|
-
};
|
|
11460
|
-
buildCliSpawnEnv = import_session_host_core3.sanitizeSpawnEnv;
|
|
11461
|
-
}
|
|
11462
|
-
});
|
|
11463
|
-
|
|
11464
11492
|
// src/providers/sdk/v1/builders/cli/visible-region.ts
|
|
11465
11493
|
function compile(re, flags) {
|
|
11466
11494
|
try {
|
|
@@ -19102,7 +19130,7 @@ var import_child_process2 = require("child_process");
|
|
|
19102
19130
|
var import_util = require("util");
|
|
19103
19131
|
var import_fs12 = require("fs");
|
|
19104
19132
|
var import_os2 = require("os");
|
|
19105
|
-
var
|
|
19133
|
+
var path12 = __toESM(require("path"));
|
|
19106
19134
|
var execAsync2 = (0, import_util.promisify)(import_child_process2.exec);
|
|
19107
19135
|
var BUILTIN_IDE_DEFINITIONS = [];
|
|
19108
19136
|
var registeredIDEs = /* @__PURE__ */ new Map();
|
|
@@ -19122,9 +19150,9 @@ function getMergedDefinitions() {
|
|
|
19122
19150
|
function findCliCommand(command) {
|
|
19123
19151
|
const trimmed = String(command || "").trim();
|
|
19124
19152
|
if (!trimmed) return null;
|
|
19125
|
-
if (
|
|
19126
|
-
const candidate = trimmed.startsWith("~") ?
|
|
19127
|
-
const resolved =
|
|
19153
|
+
if (path12.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
|
|
19154
|
+
const candidate = trimmed.startsWith("~") ? path12.join((0, import_os2.homedir)(), trimmed.slice(1)) : trimmed;
|
|
19155
|
+
const resolved = path12.isAbsolute(candidate) ? candidate : path12.resolve(candidate);
|
|
19128
19156
|
return (0, import_fs12.existsSync)(resolved) ? resolved : null;
|
|
19129
19157
|
}
|
|
19130
19158
|
const isWin = (0, import_os2.platform)() === "win32";
|
|
@@ -19133,7 +19161,7 @@ function findCliCommand(command) {
|
|
|
19133
19161
|
for (const p of paths) {
|
|
19134
19162
|
if (!p) continue;
|
|
19135
19163
|
for (const ext of exes) {
|
|
19136
|
-
const fullPath =
|
|
19164
|
+
const fullPath = path12.join(p, trimmed + ext);
|
|
19137
19165
|
try {
|
|
19138
19166
|
if ((0, import_fs12.existsSync)(fullPath)) {
|
|
19139
19167
|
const stat2 = (0, import_fs12.statSync)(fullPath);
|
|
@@ -19161,7 +19189,7 @@ async function getIdeVersion(cliCommand) {
|
|
|
19161
19189
|
function checkPathExists(paths) {
|
|
19162
19190
|
const home = (0, import_os2.homedir)();
|
|
19163
19191
|
for (const p of paths) {
|
|
19164
|
-
const normalized = p.startsWith("~") ?
|
|
19192
|
+
const normalized = p.startsWith("~") ? path12.join(home, p.slice(1)) : p;
|
|
19165
19193
|
if (normalized.includes("*")) {
|
|
19166
19194
|
const username = home.split(/[\\/]/).pop() || "";
|
|
19167
19195
|
const resolved = normalized.replace("*", username);
|
|
@@ -19184,8 +19212,8 @@ async function detectIDEs(providerLoader) {
|
|
|
19184
19212
|
if ((0, import_fs12.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
19185
19213
|
}
|
|
19186
19214
|
if (!resolvedCli && appPath && os30 === "win32") {
|
|
19187
|
-
const { dirname:
|
|
19188
|
-
const appDir =
|
|
19215
|
+
const { dirname: dirname16 } = await import("path");
|
|
19216
|
+
const appDir = dirname16(appPath);
|
|
19189
19217
|
const candidates = [
|
|
19190
19218
|
`${appDir}\\\\bin\\\\${def.cli}.cmd`,
|
|
19191
19219
|
`${appDir}\\\\bin\\\\${def.cli}`,
|
|
@@ -19220,14 +19248,14 @@ async function detectIDEs(providerLoader) {
|
|
|
19220
19248
|
init_cli_detector();
|
|
19221
19249
|
|
|
19222
19250
|
// src/system/host-memory.ts
|
|
19223
|
-
var
|
|
19251
|
+
var os7 = __toESM(require("os"));
|
|
19224
19252
|
var import_child_process3 = require("child_process");
|
|
19225
19253
|
var import_util2 = require("util");
|
|
19226
19254
|
var execAsync3 = (0, import_util2.promisify)(import_child_process3.exec);
|
|
19227
19255
|
var cachedDarwinAvail = null;
|
|
19228
19256
|
var darwinMemoryInterval = null;
|
|
19229
19257
|
async function updateDarwinMemoryCache() {
|
|
19230
|
-
if (
|
|
19258
|
+
if (os7.platform() !== "darwin") return;
|
|
19231
19259
|
try {
|
|
19232
19260
|
const { stdout } = await execAsync3("vm_stat", {
|
|
19233
19261
|
encoding: "utf-8",
|
|
@@ -19251,19 +19279,19 @@ async function updateDarwinMemoryCache() {
|
|
|
19251
19279
|
const fileBacked = counts["file_backed"] ?? 0;
|
|
19252
19280
|
const availPages = free + inactive + speculative + purgeable + fileBacked;
|
|
19253
19281
|
const bytes = availPages * pageSize;
|
|
19254
|
-
cachedDarwinAvail = Number.isFinite(bytes) && bytes >= 0 ? Math.min(bytes,
|
|
19282
|
+
cachedDarwinAvail = Number.isFinite(bytes) && bytes >= 0 ? Math.min(bytes, os7.totalmem()) : null;
|
|
19255
19283
|
} catch {
|
|
19256
19284
|
}
|
|
19257
19285
|
}
|
|
19258
19286
|
function getHostMemorySnapshot() {
|
|
19259
|
-
if (
|
|
19287
|
+
if (os7.platform() === "darwin" && !darwinMemoryInterval) {
|
|
19260
19288
|
updateDarwinMemoryCache();
|
|
19261
19289
|
darwinMemoryInterval = setInterval(updateDarwinMemoryCache, 3e3);
|
|
19262
19290
|
darwinMemoryInterval.unref();
|
|
19263
19291
|
}
|
|
19264
|
-
const totalMem =
|
|
19265
|
-
const freeMem =
|
|
19266
|
-
const availableMem =
|
|
19292
|
+
const totalMem = os7.totalmem();
|
|
19293
|
+
const freeMem = os7.freemem();
|
|
19294
|
+
const availableMem = os7.platform() === "darwin" ? cachedDarwinAvail ?? freeMem : freeMem;
|
|
19267
19295
|
return {
|
|
19268
19296
|
totalMem,
|
|
19269
19297
|
freeMem,
|
|
@@ -21625,9 +21653,9 @@ ${cleanBody}`;
|
|
|
21625
21653
|
|
|
21626
21654
|
// src/config/chat-history.ts
|
|
21627
21655
|
var fs5 = __toESM(require("fs"));
|
|
21628
|
-
var
|
|
21629
|
-
var
|
|
21630
|
-
var HISTORY_DIR =
|
|
21656
|
+
var path13 = __toESM(require("path"));
|
|
21657
|
+
var os8 = __toESM(require("os"));
|
|
21658
|
+
var HISTORY_DIR = path13.join(os8.homedir(), ".adhdev", "history");
|
|
21631
21659
|
var RETAIN_DAYS = 30;
|
|
21632
21660
|
var SAVED_HISTORY_INDEX_VERSION = 1;
|
|
21633
21661
|
var SAVED_HISTORY_INDEX_FILE = ".saved-history-index.json";
|
|
@@ -21813,7 +21841,7 @@ function extractSavedHistorySessionIdFromFile(file) {
|
|
|
21813
21841
|
function buildSavedHistoryFileSignatureMap(dir, files) {
|
|
21814
21842
|
return new Map(files.map((file) => {
|
|
21815
21843
|
try {
|
|
21816
|
-
const stat2 = fs5.statSync(
|
|
21844
|
+
const stat2 = fs5.statSync(path13.join(dir, file));
|
|
21817
21845
|
return [file, `${file}:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`];
|
|
21818
21846
|
} catch {
|
|
21819
21847
|
return [file, `${file}:missing`];
|
|
@@ -21824,7 +21852,7 @@ function buildSavedHistoryCacheSignature(files, fileSignatures) {
|
|
|
21824
21852
|
return files.map((file) => fileSignatures.get(file) || `${file}:missing`).join("|");
|
|
21825
21853
|
}
|
|
21826
21854
|
function getSavedHistoryIndexFilePath(dir) {
|
|
21827
|
-
return
|
|
21855
|
+
return path13.join(dir, SAVED_HISTORY_INDEX_FILE);
|
|
21828
21856
|
}
|
|
21829
21857
|
function getSavedHistoryIndexLockPath(dir) {
|
|
21830
21858
|
return `${getSavedHistoryIndexFilePath(dir)}${SAVED_HISTORY_INDEX_LOCK_SUFFIX}`;
|
|
@@ -21926,7 +21954,7 @@ function savePersistedSavedHistoryIndex(dir, entries) {
|
|
|
21926
21954
|
}
|
|
21927
21955
|
for (const file of Array.from(currentEntries.keys())) {
|
|
21928
21956
|
if (incomingFiles.has(file)) continue;
|
|
21929
|
-
if (!fs5.existsSync(
|
|
21957
|
+
if (!fs5.existsSync(path13.join(dir, file))) {
|
|
21930
21958
|
currentEntries.delete(file);
|
|
21931
21959
|
}
|
|
21932
21960
|
}
|
|
@@ -21952,7 +21980,7 @@ function historyDirectoryHasFilesNewerThanIndex(dir) {
|
|
|
21952
21980
|
const indexStat = fs5.statSync(getSavedHistoryIndexFilePath(dir));
|
|
21953
21981
|
const files = listHistoryFiles(dir);
|
|
21954
21982
|
for (const file of files) {
|
|
21955
|
-
const stat2 = fs5.statSync(
|
|
21983
|
+
const stat2 = fs5.statSync(path13.join(dir, file));
|
|
21956
21984
|
if (stat2.mtimeMs > indexStat.mtimeMs) return true;
|
|
21957
21985
|
}
|
|
21958
21986
|
return false;
|
|
@@ -21962,14 +21990,14 @@ function historyDirectoryHasFilesNewerThanIndex(dir) {
|
|
|
21962
21990
|
}
|
|
21963
21991
|
function buildSavedHistoryFileSignature(dir, file) {
|
|
21964
21992
|
try {
|
|
21965
|
-
const stat2 = fs5.statSync(
|
|
21993
|
+
const stat2 = fs5.statSync(path13.join(dir, file));
|
|
21966
21994
|
return `${file}:${stat2.size}:${Math.trunc(stat2.mtimeMs)}`;
|
|
21967
21995
|
} catch {
|
|
21968
21996
|
return `${file}:missing`;
|
|
21969
21997
|
}
|
|
21970
21998
|
}
|
|
21971
21999
|
function persistSavedHistoryFileSummaryEntry(agentType, dir, file, updater) {
|
|
21972
|
-
const filePath =
|
|
22000
|
+
const filePath = path13.join(dir, file);
|
|
21973
22001
|
const result = withLockedPersistedSavedHistoryIndex(dir, (entries) => {
|
|
21974
22002
|
const currentEntry = entries.get(file) || null;
|
|
21975
22003
|
const nextSummary = updater(currentEntry?.summary || null);
|
|
@@ -22042,7 +22070,7 @@ function updateSavedHistoryIndexForAppendedMessages(agentType, dir, file, histor
|
|
|
22042
22070
|
function computeSavedHistoryFileSummary(dir, file) {
|
|
22043
22071
|
const historySessionId = extractSavedHistorySessionIdFromFile(file);
|
|
22044
22072
|
if (!historySessionId) return null;
|
|
22045
|
-
const filePath =
|
|
22073
|
+
const filePath = path13.join(dir, file);
|
|
22046
22074
|
const content = fs5.readFileSync(filePath, "utf-8");
|
|
22047
22075
|
const lines = content.split("\n").filter(Boolean);
|
|
22048
22076
|
let messageCount = 0;
|
|
@@ -22129,7 +22157,7 @@ function computeSavedHistorySessionSummaries(agentType, dir, files, fileSignatur
|
|
|
22129
22157
|
const summaryBySessionId = /* @__PURE__ */ new Map();
|
|
22130
22158
|
const nextPersistedEntries = /* @__PURE__ */ new Map();
|
|
22131
22159
|
for (const file of files.slice().sort()) {
|
|
22132
|
-
const filePath =
|
|
22160
|
+
const filePath = path13.join(dir, file);
|
|
22133
22161
|
const signature = fileSignatures.get(file) || `${file}:missing`;
|
|
22134
22162
|
const cached2 = savedHistoryFileSummaryCache.get(filePath);
|
|
22135
22163
|
const persisted = persistedEntries.get(file);
|
|
@@ -22249,12 +22277,12 @@ var ChatHistoryWriter = class {
|
|
|
22249
22277
|
});
|
|
22250
22278
|
}
|
|
22251
22279
|
if (newMessages.length === 0) return;
|
|
22252
|
-
const dir =
|
|
22280
|
+
const dir = path13.join(HISTORY_DIR, this.sanitize(agentType));
|
|
22253
22281
|
fs5.mkdirSync(dir, { recursive: true });
|
|
22254
22282
|
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
22255
22283
|
const filePrefix = effectiveHistoryKey ? `${this.sanitize(effectiveHistoryKey)}_` : "";
|
|
22256
22284
|
const fileName = `${filePrefix}${date}.jsonl`;
|
|
22257
|
-
const filePath =
|
|
22285
|
+
const filePath = path13.join(dir, fileName);
|
|
22258
22286
|
const lines = newMessages.map((m) => JSON.stringify(m)).join("\n") + "\n";
|
|
22259
22287
|
fs5.appendFileSync(filePath, lines, "utf-8");
|
|
22260
22288
|
updateSavedHistoryIndexForAppendedMessages(agentType, dir, fileName, effectiveHistoryKey, newMessages);
|
|
@@ -22345,11 +22373,11 @@ var ChatHistoryWriter = class {
|
|
|
22345
22373
|
const ws = String(workspace || "").trim();
|
|
22346
22374
|
if (!id || !ws) return;
|
|
22347
22375
|
try {
|
|
22348
|
-
const dir =
|
|
22376
|
+
const dir = path13.join(HISTORY_DIR, this.sanitize(agentType));
|
|
22349
22377
|
fs5.mkdirSync(dir, { recursive: true });
|
|
22350
22378
|
const date = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
22351
22379
|
const fileName = `${this.sanitize(id)}_${date}.jsonl`;
|
|
22352
|
-
const filePath =
|
|
22380
|
+
const filePath = path13.join(dir, fileName);
|
|
22353
22381
|
const record = {
|
|
22354
22382
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
22355
22383
|
receivedAt: Date.now(),
|
|
@@ -22395,14 +22423,14 @@ var ChatHistoryWriter = class {
|
|
|
22395
22423
|
this.lastSeenCounts.set(toDedupKey, Math.max(fromCount, this.lastSeenCounts.get(toDedupKey) || 0));
|
|
22396
22424
|
this.lastSeenCounts.delete(fromDedupKey);
|
|
22397
22425
|
}
|
|
22398
|
-
const dir =
|
|
22426
|
+
const dir = path13.join(HISTORY_DIR, this.sanitize(agentType));
|
|
22399
22427
|
if (!fs5.existsSync(dir)) return;
|
|
22400
22428
|
const fromPrefix = `${this.sanitize(fromId)}_`;
|
|
22401
22429
|
const toPrefix = `${this.sanitize(toId)}_`;
|
|
22402
22430
|
const files = fs5.readdirSync(dir).filter((file) => file.startsWith(fromPrefix) && file.endsWith(".jsonl"));
|
|
22403
22431
|
for (const file of files) {
|
|
22404
|
-
const sourcePath =
|
|
22405
|
-
const targetPath =
|
|
22432
|
+
const sourcePath = path13.join(dir, file);
|
|
22433
|
+
const targetPath = path13.join(dir, `${toPrefix}${file.slice(fromPrefix.length)}`);
|
|
22406
22434
|
const sourceLines = fs5.readFileSync(sourcePath, "utf-8").split("\n").filter(Boolean);
|
|
22407
22435
|
const rewritten = sourceLines.map((line) => {
|
|
22408
22436
|
try {
|
|
@@ -22436,13 +22464,13 @@ var ChatHistoryWriter = class {
|
|
|
22436
22464
|
const sessionId = String(historySessionId || "").trim();
|
|
22437
22465
|
if (!sessionId) return;
|
|
22438
22466
|
try {
|
|
22439
|
-
const dir =
|
|
22467
|
+
const dir = path13.join(HISTORY_DIR, this.sanitize(agentType));
|
|
22440
22468
|
if (!fs5.existsSync(dir)) return;
|
|
22441
22469
|
const prefix = `${this.sanitize(sessionId)}_`;
|
|
22442
22470
|
const files = fs5.readdirSync(dir).filter((file) => file.startsWith(prefix) && file.endsWith(".jsonl")).sort();
|
|
22443
22471
|
const seen = /* @__PURE__ */ new Set();
|
|
22444
22472
|
for (const file of files) {
|
|
22445
|
-
const filePath =
|
|
22473
|
+
const filePath = path13.join(dir, file);
|
|
22446
22474
|
const lines = fs5.readFileSync(filePath, "utf-8").split("\n").filter(Boolean);
|
|
22447
22475
|
const next = [];
|
|
22448
22476
|
for (const line of lines) {
|
|
@@ -22496,11 +22524,11 @@ var ChatHistoryWriter = class {
|
|
|
22496
22524
|
const cutoff = Date.now() - RETAIN_DAYS * 24 * 60 * 60 * 1e3;
|
|
22497
22525
|
const agentDirs = fs5.readdirSync(HISTORY_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
|
|
22498
22526
|
for (const dir of agentDirs) {
|
|
22499
|
-
const dirPath =
|
|
22527
|
+
const dirPath = path13.join(HISTORY_DIR, dir.name);
|
|
22500
22528
|
const files = fs5.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl") || f.endsWith(".terminal.log"));
|
|
22501
22529
|
let removedAny = false;
|
|
22502
22530
|
for (const file of files) {
|
|
22503
|
-
const filePath =
|
|
22531
|
+
const filePath = path13.join(dirPath, file);
|
|
22504
22532
|
const stat2 = fs5.statSync(filePath);
|
|
22505
22533
|
if (stat2.mtimeMs < cutoff) {
|
|
22506
22534
|
fs5.unlinkSync(filePath);
|
|
@@ -22703,7 +22731,7 @@ function readBoundedTailRecords(agentType, dir, files, needed) {
|
|
|
22703
22731
|
const seen = /* @__PURE__ */ new Set();
|
|
22704
22732
|
let readAllFiles = true;
|
|
22705
22733
|
for (let f = 0; f < files.length; f++) {
|
|
22706
|
-
const filePath =
|
|
22734
|
+
const filePath = path13.join(dir, files[f]);
|
|
22707
22735
|
const remaining = Math.max(0, needed - collected.length);
|
|
22708
22736
|
const perFileNeeded = Math.min(needed, remaining + BOUNDED_TAIL_SLACK);
|
|
22709
22737
|
const { lines, coversWholeFile } = readFileTailLines(filePath, perFileNeeded);
|
|
@@ -22736,7 +22764,7 @@ function readBoundedTailRecords(agentType, dir, files, needed) {
|
|
|
22736
22764
|
function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, excludeRecentCount = 0, historyBehavior) {
|
|
22737
22765
|
try {
|
|
22738
22766
|
const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
22739
|
-
const dir =
|
|
22767
|
+
const dir = path13.join(HISTORY_DIR, sanitized);
|
|
22740
22768
|
if (!fs5.existsSync(dir)) return { messages: [], hasMore: false };
|
|
22741
22769
|
const files = listHistoryFiles(dir, historySessionId);
|
|
22742
22770
|
const bounded = isBoundedTailRequest(limit, offset, excludeRecentCount);
|
|
@@ -22759,7 +22787,7 @@ function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, ex
|
|
|
22759
22787
|
const allMessages = [];
|
|
22760
22788
|
const seen = /* @__PURE__ */ new Set();
|
|
22761
22789
|
for (const file of files) {
|
|
22762
|
-
const filePath =
|
|
22790
|
+
const filePath = path13.join(dir, file);
|
|
22763
22791
|
const content = fs5.readFileSync(filePath, "utf-8");
|
|
22764
22792
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
22765
22793
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -22783,7 +22811,7 @@ function readChatHistory(agentType, offset = 0, limit = 30, historySessionId, ex
|
|
|
22783
22811
|
function listSavedHistorySessions(agentType, options = {}, historyBehavior) {
|
|
22784
22812
|
try {
|
|
22785
22813
|
const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
22786
|
-
const dir =
|
|
22814
|
+
const dir = path13.join(HISTORY_DIR, sanitized);
|
|
22787
22815
|
if (!fs5.existsSync(dir)) {
|
|
22788
22816
|
savedHistorySessionCache.delete(sanitized);
|
|
22789
22817
|
return { sessions: [], hasMore: false };
|
|
@@ -22844,11 +22872,11 @@ function listSavedHistorySessions(agentType, options = {}, historyBehavior) {
|
|
|
22844
22872
|
}
|
|
22845
22873
|
function readExistingSessionStartRecord(agentType, historySessionId) {
|
|
22846
22874
|
try {
|
|
22847
|
-
const dir =
|
|
22875
|
+
const dir = path13.join(HISTORY_DIR, agentType);
|
|
22848
22876
|
if (!fs5.existsSync(dir)) return null;
|
|
22849
22877
|
const files = listHistoryFiles(dir, historySessionId).sort();
|
|
22850
22878
|
for (const file of files) {
|
|
22851
|
-
const lines = fs5.readFileSync(
|
|
22879
|
+
const lines = fs5.readFileSync(path13.join(dir, file), "utf-8").split("\n").filter(Boolean);
|
|
22852
22880
|
for (const line of lines) {
|
|
22853
22881
|
try {
|
|
22854
22882
|
const parsed = JSON.parse(line);
|
|
@@ -22868,16 +22896,16 @@ function readExistingSessionStartRecord(agentType, historySessionId) {
|
|
|
22868
22896
|
function rewriteCanonicalSavedHistory(agentType, historySessionId, records) {
|
|
22869
22897
|
if (records.length === 0) return false;
|
|
22870
22898
|
try {
|
|
22871
|
-
const dir =
|
|
22899
|
+
const dir = path13.join(HISTORY_DIR, agentType);
|
|
22872
22900
|
fs5.mkdirSync(dir, { recursive: true });
|
|
22873
22901
|
const prefix = `${historySessionId.replace(/[^a-zA-Z0-9_-]/g, "_")}_`;
|
|
22874
22902
|
for (const file of fs5.readdirSync(dir)) {
|
|
22875
22903
|
if (file.startsWith(prefix) && file.endsWith(".jsonl")) {
|
|
22876
|
-
fs5.unlinkSync(
|
|
22904
|
+
fs5.unlinkSync(path13.join(dir, file));
|
|
22877
22905
|
}
|
|
22878
22906
|
}
|
|
22879
22907
|
const targetDate = new Date(records[records.length - 1].receivedAt || Date.now()).toISOString().slice(0, 10);
|
|
22880
|
-
const filePath =
|
|
22908
|
+
const filePath = path13.join(dir, `${prefix}${targetDate}.jsonl`);
|
|
22881
22909
|
fs5.writeFileSync(filePath, `${records.map((record) => JSON.stringify(record)).join("\n")}
|
|
22882
22910
|
`, "utf-8");
|
|
22883
22911
|
invalidatePersistedSavedHistoryIndex(agentType, dir);
|
|
@@ -25472,8 +25500,8 @@ function resolveLegacyProviderScript(fn, scriptName, params) {
|
|
|
25472
25500
|
|
|
25473
25501
|
// src/commands/chat-commands.ts
|
|
25474
25502
|
var fs6 = __toESM(require("fs"));
|
|
25475
|
-
var
|
|
25476
|
-
var
|
|
25503
|
+
var os9 = __toESM(require("os"));
|
|
25504
|
+
var path14 = __toESM(require("path"));
|
|
25477
25505
|
var import_node_crypto3 = require("crypto");
|
|
25478
25506
|
init_logger();
|
|
25479
25507
|
|
|
@@ -26522,7 +26550,7 @@ function readExactRuntimeMirrorMessages(args) {
|
|
|
26522
26550
|
function normalizeComparableWorkspace(value) {
|
|
26523
26551
|
const text = typeof value === "string" ? value.trim() : "";
|
|
26524
26552
|
if (!text) return "";
|
|
26525
|
-
return
|
|
26553
|
+
return path14.resolve(text);
|
|
26526
26554
|
}
|
|
26527
26555
|
function isCurrentRuntimePtySafelyAttributed(args) {
|
|
26528
26556
|
if (args.adapter.cliType !== "codex-cli") return false;
|
|
@@ -27007,7 +27035,7 @@ function buildDebugBundleText(bundle) {
|
|
|
27007
27035
|
}
|
|
27008
27036
|
function getChatDebugBundleDir() {
|
|
27009
27037
|
const override = typeof process.env.ADHDEV_DEBUG_BUNDLE_DIR === "string" ? process.env.ADHDEV_DEBUG_BUNDLE_DIR.trim() : "";
|
|
27010
|
-
return override ||
|
|
27038
|
+
return override || path14.join(os9.homedir(), ".adhdev", "debug-bundles", "chat");
|
|
27011
27039
|
}
|
|
27012
27040
|
function safeBundleIdSegment(value, fallback) {
|
|
27013
27041
|
const normalized = String(value || fallback).trim().replace(/[^A-Za-z0-9_.-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 80);
|
|
@@ -27064,7 +27092,7 @@ function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
|
27064
27092
|
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
27065
27093
|
const dir = getChatDebugBundleDir();
|
|
27066
27094
|
fs6.mkdirSync(dir, { recursive: true });
|
|
27067
|
-
const savedPath =
|
|
27095
|
+
const savedPath = path14.join(dir, `${bundleId}.json`);
|
|
27068
27096
|
const json = `${JSON.stringify(bundle, null, 2)}
|
|
27069
27097
|
`;
|
|
27070
27098
|
fs6.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
|
|
@@ -28628,8 +28656,8 @@ async function handleResolveAction(h, args) {
|
|
|
28628
28656
|
|
|
28629
28657
|
// src/commands/cdp-commands.ts
|
|
28630
28658
|
var fs7 = __toESM(require("fs"));
|
|
28631
|
-
var
|
|
28632
|
-
var
|
|
28659
|
+
var path15 = __toESM(require("path"));
|
|
28660
|
+
var os10 = __toESM(require("os"));
|
|
28633
28661
|
var KEY_TO_VK = {
|
|
28634
28662
|
Backspace: 8,
|
|
28635
28663
|
Tab: 9,
|
|
@@ -28883,27 +28911,27 @@ function normalizeWindowsRequestedPath(requestedPath) {
|
|
|
28883
28911
|
function resolveSafePath(requestedPath) {
|
|
28884
28912
|
const rawPath = typeof requestedPath === "string" ? requestedPath.trim() : "";
|
|
28885
28913
|
const inputPath = rawPath || ".";
|
|
28886
|
-
const home =
|
|
28914
|
+
const home = os10.homedir();
|
|
28887
28915
|
if (inputPath.startsWith("~")) {
|
|
28888
|
-
return
|
|
28916
|
+
return path15.resolve(path15.join(home, inputPath.slice(1)));
|
|
28889
28917
|
}
|
|
28890
28918
|
if (process.platform === "win32") {
|
|
28891
28919
|
const normalized = normalizeWindowsRequestedPath(inputPath);
|
|
28892
|
-
if (
|
|
28893
|
-
return
|
|
28920
|
+
if (path15.win32.isAbsolute(normalized)) {
|
|
28921
|
+
return path15.win32.normalize(normalized);
|
|
28894
28922
|
}
|
|
28895
|
-
return
|
|
28923
|
+
return path15.win32.resolve(normalized);
|
|
28896
28924
|
}
|
|
28897
|
-
if (
|
|
28898
|
-
return
|
|
28925
|
+
if (path15.isAbsolute(inputPath)) {
|
|
28926
|
+
return path15.normalize(inputPath);
|
|
28899
28927
|
}
|
|
28900
|
-
return
|
|
28928
|
+
return path15.resolve(inputPath);
|
|
28901
28929
|
}
|
|
28902
28930
|
function listDirectoryEntriesSafe(dirPath) {
|
|
28903
28931
|
const entries = fs7.readdirSync(dirPath, { withFileTypes: true });
|
|
28904
28932
|
const files = [];
|
|
28905
28933
|
for (const entry of entries) {
|
|
28906
|
-
const entryPath =
|
|
28934
|
+
const entryPath = path15.join(dirPath, entry.name);
|
|
28907
28935
|
try {
|
|
28908
28936
|
if (entry.isDirectory()) {
|
|
28909
28937
|
files.push({ name: entry.name, type: "directory" });
|
|
@@ -28957,7 +28985,7 @@ async function handleFileRead(h, args) {
|
|
|
28957
28985
|
async function handleFileWrite(h, args) {
|
|
28958
28986
|
try {
|
|
28959
28987
|
const filePath = resolveSafePath(args?.path);
|
|
28960
|
-
fs7.mkdirSync(
|
|
28988
|
+
fs7.mkdirSync(path15.dirname(filePath), { recursive: true });
|
|
28961
28989
|
fs7.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
28962
28990
|
return { success: true, path: filePath };
|
|
28963
28991
|
} catch (e) {
|
|
@@ -49213,7 +49241,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
49213
49241
|
};
|
|
49214
49242
|
}
|
|
49215
49243
|
const { existsSync: existsSync44, readFileSync: readFileSync35, writeFileSync: writeFileSync23, copyFileSync: copyFileSync4, mkdirSync: mkdirSync21 } = await import("fs");
|
|
49216
|
-
const { dirname:
|
|
49244
|
+
const { dirname: dirname16 } = await import("path");
|
|
49217
49245
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
49218
49246
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
49219
49247
|
let hermesBaseConfig = null;
|
|
@@ -49248,7 +49276,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
49248
49276
|
};
|
|
49249
49277
|
}
|
|
49250
49278
|
try {
|
|
49251
|
-
mkdirSync21(
|
|
49279
|
+
mkdirSync21(dirname16(mcpConfigPath), { recursive: true });
|
|
49252
49280
|
} catch (error) {
|
|
49253
49281
|
const message = `Could not prepare MCP config path for automatic setup: ${error?.message || error}`;
|
|
49254
49282
|
LOG.error("MeshCoordinator", message);
|
|
@@ -49258,7 +49286,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
49258
49286
|
const hadExistingMcpConfig = existsSync44(mcpConfigPath);
|
|
49259
49287
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
49260
49288
|
if (hermesBaseConfig) {
|
|
49261
|
-
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome,
|
|
49289
|
+
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname16(mcpConfigPath));
|
|
49262
49290
|
}
|
|
49263
49291
|
if (hadExistingMcpConfig) {
|
|
49264
49292
|
try {
|
|
@@ -49296,7 +49324,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
49296
49324
|
const cliArgs = [];
|
|
49297
49325
|
const launchEnv = {};
|
|
49298
49326
|
if (configFormat === "hermes_config_yaml") {
|
|
49299
|
-
launchEnv.HERMES_HOME =
|
|
49327
|
+
launchEnv.HERMES_HOME = dirname16(mcpConfigPath);
|
|
49300
49328
|
launchEnv.HERMES_IGNORE_USER_CONFIG = "";
|
|
49301
49329
|
}
|
|
49302
49330
|
let autoImportContextFilePath;
|