@adhdev/daemon-core 0.9.82-rc.540 → 0.9.82-rc.541
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/cli-adapters/cli-state-engine.d.ts +12 -0
- package/dist/commands/chat-commands-read.d.ts +3 -0
- package/dist/index.js +740 -588
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +747 -595
- package/dist/index.mjs.map +1 -1
- package/dist/providers/spec/types.d.ts +57 -2
- package/package.json +3 -3
- package/src/cli-adapters/cli-state-engine.ts +76 -1
- package/src/commands/chat-commands-read.ts +28 -1
- package/src/mesh/coordinator-prompt.ts +2 -1
- package/src/providers/spec/native-history-executor.ts +174 -9
- package/src/providers/spec/types.ts +54 -2
package/dist/index.js
CHANGED
|
@@ -419,10 +419,10 @@ function readInjected(value) {
|
|
|
419
419
|
}
|
|
420
420
|
function getDaemonBuildInfo() {
|
|
421
421
|
if (cached) return cached;
|
|
422
|
-
const commit = readInjected(true ? "
|
|
423
|
-
const commitShort = readInjected(true ? "
|
|
424
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
425
|
-
const builtAt = readInjected(true ? "2026-07-
|
|
422
|
+
const commit = readInjected(true ? "77f3fad0358bec7e4474ead5b2510e19a4cc2cc4" : void 0) ?? "unknown";
|
|
423
|
+
const commitShort = readInjected(true ? "77f3fad0" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
424
|
+
const version = readInjected(true ? "0.9.82-rc.541" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
425
|
+
const builtAt = readInjected(true ? "2026-07-16T05:30:52.044Z" : void 0);
|
|
426
426
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
427
427
|
return cached;
|
|
428
428
|
}
|
|
@@ -4073,7 +4073,8 @@ function buildRulesSection(coordinatorCliType) {
|
|
|
4073
4073
|
- **Coordinator runtime is not a delegation default.** This coordinator is running as \`${coordinatorCliType}\`, but delegated node sessions must follow the user's requested provider, not the coordinator's own runtime.` : "";
|
|
4074
4074
|
return `## Rules
|
|
4075
4075
|
|
|
4076
|
-
- **Route, don't implement.** Delegate all code reading, analysis, and execution to node agents. Never read source files or run commands in the coordinator \u2014 keep context lean.
|
|
4076
|
+
- **Route, don't implement.** Delegate all code reading, analysis, and execution to node agents. Never read source files or run commands in the coordinator \u2014 keep context lean. See also: **Never use local sub-agents** below.
|
|
4077
|
+
- **Never use local sub-agents.** Do NOT spawn your runtime's own sub-agents (e.g. Claude Code's Task/Explore/Agent tools, or any equivalent in-process agent-spawning tool) to read code, investigate, run RCA, or implement. Such sub-agents execute on the coordinator's machine, outside the mesh \u2014 they escape mesh parallelism, the ledger/audit trail, node capability profiles, and worktree isolation, and leave no \`mesh_task_history\` record. ALL code reading, analysis, RCA, and implementation must be delegated to mesh nodes via \`mesh_enqueue_task\` / \`mesh_send_task\` (use \`task_mode: "live_debug_readonly"\` for read-only investigation), or cross-verified via \`mesh_magi_review\` for read-only fan-out. The coordinator's own actions are limited to \`mesh_*\` tool orchestration and synthesizing results.
|
|
4077
4078
|
- **Front-load task messages.** Include everything the agent needs (files, problem, expected fix) in \`mesh_enqueue_task\` / \`mesh_send_task\`. Append a structured result request at the end: ask the worker to conclude with a JSON block containing \`status\`, \`changedFiles\`, \`gitStatus\`, \`validationResults\`, \`errors\`, \`nextAction\`. The daemon parses this automatically; you can read it from \`mesh_task_history\`.
|
|
4078
4079
|
- **Reuse idle sessions.** For follow-up, retry, commit/push, or cleanup on the same issue, send only the delta to the existing idle session. Start a fresh session only when: (a) branch/worktree isolation is required, (b) the existing session had a dispatch failure or provider mismatch, (c) the transcript/runtime is contaminated or interrupted, or (d) the user explicitly asks for a different provider/session. Continuation of the same issue in an already-idle session is allowed and preferred \u2014 this rule blocks concurrent unrelated work interleaved into a live (still-generating) session, not sequential same-issue follow-ups.
|
|
4079
4080
|
- **Worktree affinity.** A worktree is a durable per-branch workspace; keep all of a branch's code_change/fix/review work on its worktree node by targeting \`required_tags: ["worktree=<branch>"]\` or \`target_node_id\`. Get the id/branch from the \`mesh_clone_node\` result or a live \`mesh_status\` \u2014 the Configured Nodes snapshot won't list a worktree cloned after launch. Untargeted same-branch follow-ups drift to the base node. Only \`convergence\` (merge/push) runs on the base, never pinned to the worktree.
|
|
@@ -10649,8 +10650,8 @@ function stripCoordinatorWrapperFile(filePath) {
|
|
|
10649
10650
|
const remaining = (existing.slice(0, openIdx) + existing.slice(closeIdx + CLOSE.length)).replace(/^\s*\n+/, "").replace(/\n+\s*$/, "");
|
|
10650
10651
|
if (!remaining.trim()) {
|
|
10651
10652
|
try {
|
|
10652
|
-
const
|
|
10653
|
-
|
|
10653
|
+
const fs43 = require("fs");
|
|
10654
|
+
fs43.unlinkSync(filePath);
|
|
10654
10655
|
} catch {
|
|
10655
10656
|
}
|
|
10656
10657
|
} else {
|
|
@@ -12646,9 +12647,9 @@ function findBinary(name) {
|
|
|
12646
12647
|
for (const ext of exes) {
|
|
12647
12648
|
const fullPath = path11.join(p, trimmed + ext);
|
|
12648
12649
|
try {
|
|
12649
|
-
const
|
|
12650
|
-
if (
|
|
12651
|
-
const stat2 =
|
|
12650
|
+
const fs43 = require("fs");
|
|
12651
|
+
if (fs43.existsSync(fullPath)) {
|
|
12652
|
+
const stat2 = fs43.statSync(fullPath);
|
|
12652
12653
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
12653
12654
|
return fullPath;
|
|
12654
12655
|
}
|
|
@@ -12662,12 +12663,12 @@ function findBinary(name) {
|
|
|
12662
12663
|
function isScriptBinary(binaryPath) {
|
|
12663
12664
|
if (!path11.isAbsolute(binaryPath)) return false;
|
|
12664
12665
|
try {
|
|
12665
|
-
const
|
|
12666
|
-
const resolved =
|
|
12666
|
+
const fs43 = require("fs");
|
|
12667
|
+
const resolved = fs43.realpathSync(binaryPath);
|
|
12667
12668
|
const head = Buffer.alloc(8);
|
|
12668
|
-
const fd =
|
|
12669
|
-
|
|
12670
|
-
|
|
12669
|
+
const fd = fs43.openSync(resolved, "r");
|
|
12670
|
+
fs43.readSync(fd, head, 0, 8, 0);
|
|
12671
|
+
fs43.closeSync(fd);
|
|
12671
12672
|
let i = 0;
|
|
12672
12673
|
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
12673
12674
|
return head[i] === 35 && head[i + 1] === 33;
|
|
@@ -12678,12 +12679,12 @@ function isScriptBinary(binaryPath) {
|
|
|
12678
12679
|
function looksLikeMachOOrElf(filePath) {
|
|
12679
12680
|
if (!path11.isAbsolute(filePath)) return false;
|
|
12680
12681
|
try {
|
|
12681
|
-
const
|
|
12682
|
-
const resolved =
|
|
12682
|
+
const fs43 = require("fs");
|
|
12683
|
+
const resolved = fs43.realpathSync(filePath);
|
|
12683
12684
|
const buf = Buffer.alloc(8);
|
|
12684
|
-
const fd =
|
|
12685
|
-
|
|
12686
|
-
|
|
12685
|
+
const fd = fs43.openSync(resolved, "r");
|
|
12686
|
+
fs43.readSync(fd, buf, 0, 8, 0);
|
|
12687
|
+
fs43.closeSync(fd);
|
|
12687
12688
|
let i = 0;
|
|
12688
12689
|
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
12689
12690
|
const b = buf.subarray(i);
|
|
@@ -12970,19 +12971,19 @@ async function resolveDetectionPath(command, whichCmd) {
|
|
|
12970
12971
|
return null;
|
|
12971
12972
|
}
|
|
12972
12973
|
function execAsync(cmd, timeoutMs = 5e3) {
|
|
12973
|
-
return new Promise((
|
|
12974
|
+
return new Promise((resolve26) => {
|
|
12974
12975
|
const child = (0, import_child_process2.exec)(cmd, {
|
|
12975
12976
|
encoding: "utf-8",
|
|
12976
12977
|
timeout: timeoutMs,
|
|
12977
12978
|
...process.platform === "win32" ? { windowsHide: true } : {}
|
|
12978
12979
|
}, (err, stdout) => {
|
|
12979
12980
|
if (err || !stdout?.trim()) {
|
|
12980
|
-
|
|
12981
|
+
resolve26(null);
|
|
12981
12982
|
} else {
|
|
12982
|
-
|
|
12983
|
+
resolve26(stdout.trim());
|
|
12983
12984
|
}
|
|
12984
12985
|
});
|
|
12985
|
-
child.on("error", () =>
|
|
12986
|
+
child.on("error", () => resolve26(null));
|
|
12986
12987
|
});
|
|
12987
12988
|
}
|
|
12988
12989
|
async function detectCLIs(providerLoader, options) {
|
|
@@ -13124,7 +13125,7 @@ var init_runtime_surface = __esm({
|
|
|
13124
13125
|
// src/mesh/mesh-warmup-deadline.ts
|
|
13125
13126
|
function awaitWithWarmupDeadline(work, opts) {
|
|
13126
13127
|
const pollMs = Math.max(1, Math.min(opts.pollIntervalMs ?? 200, opts.connectTimeoutMs));
|
|
13127
|
-
return new Promise((
|
|
13128
|
+
return new Promise((resolve26, reject) => {
|
|
13128
13129
|
let done = false;
|
|
13129
13130
|
let poll;
|
|
13130
13131
|
let responseTimer;
|
|
@@ -13174,7 +13175,7 @@ function awaitWithWarmupDeadline(work, opts) {
|
|
|
13174
13175
|
if (typeof poll.unref === "function") poll.unref();
|
|
13175
13176
|
}
|
|
13176
13177
|
work.then(
|
|
13177
|
-
(val) => settle(() =>
|
|
13178
|
+
(val) => settle(() => resolve26(val)),
|
|
13178
13179
|
(err) => settle(() => reject(err))
|
|
13179
13180
|
);
|
|
13180
13181
|
});
|
|
@@ -14259,7 +14260,7 @@ async function probeRemoteMeshGitStatusWithRetry(args) {
|
|
|
14259
14260
|
const connection = args.getConnection?.(args.daemonId);
|
|
14260
14261
|
if (args.getConnection && readMeshConnectionState(connection) !== "connected") break;
|
|
14261
14262
|
if (connection) args.onConnection?.(connection);
|
|
14262
|
-
await new Promise((
|
|
14263
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250 * 2 ** (attempt - 1)));
|
|
14263
14264
|
}
|
|
14264
14265
|
try {
|
|
14265
14266
|
const remoteGit = await probeRemoteMeshGitStatus({
|
|
@@ -16043,7 +16044,7 @@ async function waitForLocalSessionReady(components, sessionId) {
|
|
|
16043
16044
|
const deadline = Date.now() + LOCAL_LAUNCH_READY_TIMEOUT_MS;
|
|
16044
16045
|
while (Date.now() < deadline) {
|
|
16045
16046
|
if (adapter.isReady() || adapter.currentStatus === "idle") return;
|
|
16046
|
-
await new Promise((
|
|
16047
|
+
await new Promise((resolve26) => setTimeout(resolve26, LOCAL_LAUNCH_READY_POLL_MS));
|
|
16047
16048
|
}
|
|
16048
16049
|
LOG.warn("MeshQueue", `Auto-launched session ${sessionId} not interactive after ${LOCAL_LAUNCH_READY_TIMEOUT_MS}ms; dispatching anyway (adapter queue-until-ready will buffer)`);
|
|
16049
16050
|
}
|
|
@@ -23726,13 +23727,13 @@ function activeFilePath() {
|
|
|
23726
23727
|
}
|
|
23727
23728
|
function ensureAdhdevDir() {
|
|
23728
23729
|
const d = adhdevDir();
|
|
23729
|
-
if (!
|
|
23730
|
+
if (!fs11.existsSync(d)) fs11.mkdirSync(d, { recursive: true });
|
|
23730
23731
|
}
|
|
23731
23732
|
function loadExternalSources() {
|
|
23732
23733
|
const p = sourcesFilePath();
|
|
23733
|
-
if (!
|
|
23734
|
+
if (!fs11.existsSync(p)) return { schema: 1, sources: [] };
|
|
23734
23735
|
try {
|
|
23735
|
-
const raw = JSON.parse(
|
|
23736
|
+
const raw = JSON.parse(fs11.readFileSync(p, "utf-8"));
|
|
23736
23737
|
if (!raw || typeof raw !== "object") return { schema: 1, sources: [] };
|
|
23737
23738
|
const sources = Array.isArray(raw.sources) ? raw.sources.filter(isValidSource) : [];
|
|
23738
23739
|
return { schema: 1, sources };
|
|
@@ -23743,14 +23744,14 @@ function loadExternalSources() {
|
|
|
23743
23744
|
function saveExternalSources(file) {
|
|
23744
23745
|
ensureAdhdevDir();
|
|
23745
23746
|
const tmp = sourcesFilePath() + ".tmp";
|
|
23746
|
-
|
|
23747
|
-
|
|
23747
|
+
fs11.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n", "utf-8");
|
|
23748
|
+
fs11.renameSync(tmp, sourcesFilePath());
|
|
23748
23749
|
}
|
|
23749
23750
|
function loadProvidersActive() {
|
|
23750
23751
|
const p = activeFilePath();
|
|
23751
|
-
if (!
|
|
23752
|
+
if (!fs11.existsSync(p)) return { schema: 1, active: {} };
|
|
23752
23753
|
try {
|
|
23753
|
-
const raw = JSON.parse(
|
|
23754
|
+
const raw = JSON.parse(fs11.readFileSync(p, "utf-8"));
|
|
23754
23755
|
if (!raw || typeof raw !== "object") return { schema: 1, active: {} };
|
|
23755
23756
|
const active = raw.active && typeof raw.active === "object" ? raw.active : {};
|
|
23756
23757
|
return { schema: 1, active };
|
|
@@ -23761,8 +23762,8 @@ function loadProvidersActive() {
|
|
|
23761
23762
|
function saveProvidersActive(file) {
|
|
23762
23763
|
ensureAdhdevDir();
|
|
23763
23764
|
const tmp = activeFilePath() + ".tmp";
|
|
23764
|
-
|
|
23765
|
-
|
|
23765
|
+
fs11.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n", "utf-8");
|
|
23766
|
+
fs11.renameSync(tmp, activeFilePath());
|
|
23766
23767
|
}
|
|
23767
23768
|
function isValidSource(x) {
|
|
23768
23769
|
if (!x || typeof x !== "object") return false;
|
|
@@ -23778,11 +23779,11 @@ function deriveSourceName(url) {
|
|
|
23778
23779
|
}
|
|
23779
23780
|
function inventoryExternalSources() {
|
|
23780
23781
|
const root = externalRoot();
|
|
23781
|
-
if (!
|
|
23782
|
+
if (!fs11.existsSync(root)) return [];
|
|
23782
23783
|
const out = [];
|
|
23783
23784
|
let entries;
|
|
23784
23785
|
try {
|
|
23785
|
-
entries =
|
|
23786
|
+
entries = fs11.readdirSync(root, { withFileTypes: true });
|
|
23786
23787
|
} catch {
|
|
23787
23788
|
return [];
|
|
23788
23789
|
}
|
|
@@ -23793,7 +23794,7 @@ function inventoryExternalSources() {
|
|
|
23793
23794
|
const providers = {};
|
|
23794
23795
|
let categoryEntries;
|
|
23795
23796
|
try {
|
|
23796
|
-
categoryEntries =
|
|
23797
|
+
categoryEntries = fs11.readdirSync(sourceDir, { withFileTypes: true });
|
|
23797
23798
|
} catch {
|
|
23798
23799
|
continue;
|
|
23799
23800
|
}
|
|
@@ -23803,7 +23804,7 @@ function inventoryExternalSources() {
|
|
|
23803
23804
|
const categoryDir = path19.join(sourceDir, category);
|
|
23804
23805
|
let typeEntries;
|
|
23805
23806
|
try {
|
|
23806
|
-
typeEntries =
|
|
23807
|
+
typeEntries = fs11.readdirSync(categoryDir, { withFileTypes: true });
|
|
23807
23808
|
} catch {
|
|
23808
23809
|
continue;
|
|
23809
23810
|
}
|
|
@@ -23811,8 +23812,8 @@ function inventoryExternalSources() {
|
|
|
23811
23812
|
for (const typeEntry of typeEntries) {
|
|
23812
23813
|
if (!typeEntry.isDirectory()) continue;
|
|
23813
23814
|
const typeDir = path19.join(categoryDir, typeEntry.name);
|
|
23814
|
-
const hasV1 =
|
|
23815
|
-
const hasV0 =
|
|
23815
|
+
const hasV1 = fs11.existsSync(path19.join(typeDir, "provider.v1.json"));
|
|
23816
|
+
const hasV0 = fs11.existsSync(path19.join(typeDir, "provider.json"));
|
|
23816
23817
|
if (hasV1 || hasV0) types.push(typeEntry.name);
|
|
23817
23818
|
}
|
|
23818
23819
|
if (types.length > 0) providers[category] = types;
|
|
@@ -23835,11 +23836,11 @@ function resolveActiveSource(category, type, activeFile) {
|
|
|
23835
23836
|
}
|
|
23836
23837
|
return { source: candidates[0], ambiguous: true, candidates };
|
|
23837
23838
|
}
|
|
23838
|
-
var
|
|
23839
|
+
var fs11, os12, path19, SOURCES_FILENAME, ACTIVE_FILENAME;
|
|
23839
23840
|
var init_external_sources = __esm({
|
|
23840
23841
|
"src/providers/external-sources.ts"() {
|
|
23841
23842
|
"use strict";
|
|
23842
|
-
|
|
23843
|
+
fs11 = __toESM(require("fs"));
|
|
23843
23844
|
os12 = __toESM(require("os"));
|
|
23844
23845
|
path19 = __toESM(require("path"));
|
|
23845
23846
|
SOURCES_FILENAME = "providers-sources.json";
|
|
@@ -23891,7 +23892,7 @@ __export(fsm_loader_exports, {
|
|
|
23891
23892
|
function loadFsmSpec(sourcePath) {
|
|
23892
23893
|
let raw;
|
|
23893
23894
|
try {
|
|
23894
|
-
raw = JSON.parse(
|
|
23895
|
+
raw = JSON.parse(fs12.readFileSync(sourcePath, "utf8"));
|
|
23895
23896
|
} catch (err) {
|
|
23896
23897
|
return { ok: false, errors: [`Failed to read/parse spec: ${err.message}`], sourcePath };
|
|
23897
23898
|
}
|
|
@@ -24011,11 +24012,11 @@ function validateCondition(c, sectionIds, path45) {
|
|
|
24011
24012
|
errs.push(`${path45} is not a recognized condition`);
|
|
24012
24013
|
return errs;
|
|
24013
24014
|
}
|
|
24014
|
-
var
|
|
24015
|
+
var fs12;
|
|
24015
24016
|
var init_fsm_loader = __esm({
|
|
24016
24017
|
"src/providers/spec/fsm-loader.ts"() {
|
|
24017
24018
|
"use strict";
|
|
24018
|
-
|
|
24019
|
+
fs12 = __toESM(require("fs"));
|
|
24019
24020
|
init_fsm_types();
|
|
24020
24021
|
}
|
|
24021
24022
|
});
|
|
@@ -24507,8 +24508,8 @@ var init_pty_transport = __esm({
|
|
|
24507
24508
|
let cwd = options.cwd;
|
|
24508
24509
|
if (cwd) {
|
|
24509
24510
|
try {
|
|
24510
|
-
const
|
|
24511
|
-
const stat2 =
|
|
24511
|
+
const fs43 = require("fs");
|
|
24512
|
+
const stat2 = fs43.statSync(cwd);
|
|
24512
24513
|
if (!stat2.isDirectory()) cwd = os14.homedir();
|
|
24513
24514
|
} catch {
|
|
24514
24515
|
cwd = os14.homedir();
|
|
@@ -25496,7 +25497,7 @@ var init_provider_cli_parse = __esm({
|
|
|
25496
25497
|
});
|
|
25497
25498
|
|
|
25498
25499
|
// src/cli-adapters/cli-state-engine.ts
|
|
25499
|
-
var SCRIPT_STATUS_DEBOUNCE_MS, MAX_FINISH_RETRIES, FINISH_RETRY_DELAY_MS, MAX_TRACE_ENTRIES, APPROVAL_EXIT_TIMEOUT_MS, IDLE_CONFIRMATION_GRACE_MS, APPROVAL_RESUME_IDLE_DEFER_CAP_MS, CliStateEngine;
|
|
25500
|
+
var SCRIPT_STATUS_DEBOUNCE_MS, MAX_FINISH_RETRIES, FINISH_RETRY_DELAY_MS, MAX_TRACE_ENTRIES, APPROVAL_EXIT_TIMEOUT_MS, IDLE_CONFIRMATION_GRACE_MS, APPROVAL_RESUME_IDLE_DEFER_CAP_MS, SCREEN_QUIET_IDLE_MS, CliStateEngine;
|
|
25500
25501
|
var init_cli_state_engine = __esm({
|
|
25501
25502
|
"src/cli-adapters/cli-state-engine.ts"() {
|
|
25502
25503
|
"use strict";
|
|
@@ -25510,6 +25511,7 @@ var init_cli_state_engine = __esm({
|
|
|
25510
25511
|
APPROVAL_EXIT_TIMEOUT_MS = 6e4;
|
|
25511
25512
|
IDLE_CONFIRMATION_GRACE_MS = 2e3;
|
|
25512
25513
|
APPROVAL_RESUME_IDLE_DEFER_CAP_MS = 18e3;
|
|
25514
|
+
SCREEN_QUIET_IDLE_MS = 5e3;
|
|
25513
25515
|
CliStateEngine = class {
|
|
25514
25516
|
constructor(provider, runner, transport, callbacks, timeouts) {
|
|
25515
25517
|
this.provider = provider;
|
|
@@ -26074,6 +26076,10 @@ var init_cli_state_engine = __esm({
|
|
|
26074
26076
|
this.idleTimeout = setTimeout(() => {
|
|
26075
26077
|
if (this.isWaitingForResponse && !this.hasActionableApproval()) {
|
|
26076
26078
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26079
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26080
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26081
|
+
return;
|
|
26082
|
+
}
|
|
26077
26083
|
this.finishResponse();
|
|
26078
26084
|
}
|
|
26079
26085
|
}, this.timeouts.generatingIdle);
|
|
@@ -26096,6 +26102,10 @@ var init_cli_state_engine = __esm({
|
|
|
26096
26102
|
this.idleTimeout = setTimeout(() => {
|
|
26097
26103
|
if (this.isWaitingForResponse && !this.hasActionableApproval()) {
|
|
26098
26104
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26105
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26106
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26107
|
+
return;
|
|
26108
|
+
}
|
|
26099
26109
|
this.finishResponse();
|
|
26100
26110
|
}
|
|
26101
26111
|
}, this.timeouts.generatingIdle);
|
|
@@ -26164,6 +26174,10 @@ var init_cli_state_engine = __esm({
|
|
|
26164
26174
|
this.idleTimeout = setTimeout(() => {
|
|
26165
26175
|
if (this.isWaitingForResponse) {
|
|
26166
26176
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26177
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26178
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26179
|
+
return;
|
|
26180
|
+
}
|
|
26167
26181
|
this.finishResponse();
|
|
26168
26182
|
}
|
|
26169
26183
|
}, this.timeouts.generatingIdle);
|
|
@@ -26249,7 +26263,8 @@ var init_cli_state_engine = __esm({
|
|
|
26249
26263
|
const assistantLength = lastParsedAssistant?.content?.length || 0;
|
|
26250
26264
|
const idleFinishConfirmMs = this.timeouts.idleFinishConfirm;
|
|
26251
26265
|
const idleQuietThresholdMs = Math.max(idleFinishConfirmMs, this.timeouts.outputSettle);
|
|
26252
|
-
const
|
|
26266
|
+
const screenQuietForIdle = screenStableMs >= SCREEN_QUIET_IDLE_MS;
|
|
26267
|
+
const idleReady = !modal && hasAssistantTurn && quietForMs >= idleQuietThresholdMs && screenStableMs >= idleFinishConfirmMs && screenQuietForIdle;
|
|
26253
26268
|
const candidate = this.idleFinishCandidate;
|
|
26254
26269
|
const candidateQuiet = !!candidate && candidate.responseEpoch === this.responseEpoch && candidate.lastOutputAt === snap.lastOutputAt && candidate.lastScreenChangeAt === snap.lastScreenChangeAt && assistantLength >= candidate.assistantLength && now - candidate.armedAt >= idleFinishConfirmMs;
|
|
26255
26270
|
if (this.shouldDeferIdleForApprovalResume(now)) {
|
|
@@ -26284,6 +26299,13 @@ var init_cli_state_engine = __esm({
|
|
|
26284
26299
|
return;
|
|
26285
26300
|
}
|
|
26286
26301
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26302
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26303
|
+
if (this.idleTimeout) clearTimeout(this.idleTimeout);
|
|
26304
|
+
this.idleTimeout = setTimeout(() => {
|
|
26305
|
+
if (this.isWaitingForResponse) this.evaluateSettled(this.transport.getSnapshot());
|
|
26306
|
+
}, this.timeouts.idleFinish);
|
|
26307
|
+
return;
|
|
26308
|
+
}
|
|
26287
26309
|
const parsed = this.runParseSession(this.transport.getSnapshot());
|
|
26288
26310
|
if (this.shouldDeferFinishForTranscript(parsed)) {
|
|
26289
26311
|
this.rescheduleTranscriptFinishCheck("transcript_idle_timeout_not_final");
|
|
@@ -26294,6 +26316,22 @@ var init_cli_state_engine = __esm({
|
|
|
26294
26316
|
}
|
|
26295
26317
|
}, this.timeouts.idleFinish);
|
|
26296
26318
|
}
|
|
26319
|
+
/**
|
|
26320
|
+
* FALSE-IDLE (screen-quiet gate): has the visible terminal screen content been
|
|
26321
|
+
* byte-identical for at least SCREEN_QUIET_IDLE_MS continuously?
|
|
26322
|
+
*
|
|
26323
|
+
* `lastScreenChangeAt` is bumped by the adapter every time the normalized screen
|
|
26324
|
+
* snapshot changes (spinner frame, streaming command output, etc.), so
|
|
26325
|
+
* `now - lastScreenChangeAt` is the real screen-diff quiet age. Reads the LIVE
|
|
26326
|
+
* transport snapshot so the deferred idleFinish timeout re-checks current screen
|
|
26327
|
+
* state, not the stale snapshot from when the timer was armed. A never-changed
|
|
26328
|
+
* screen (lastScreenChangeAt === 0) is treated as quiet.
|
|
26329
|
+
*/
|
|
26330
|
+
hasScreenBeenQuietForIdle(now) {
|
|
26331
|
+
const lastChange = this.transport.getSnapshot().lastScreenChangeAt;
|
|
26332
|
+
if (!lastChange) return true;
|
|
26333
|
+
return now - lastChange >= SCREEN_QUIET_IDLE_MS;
|
|
26334
|
+
}
|
|
26297
26335
|
/**
|
|
26298
26336
|
* FALSE-IDLE (Fix 2): should applyIdle suppress the idle/finish for the current
|
|
26299
26337
|
* turn because we are inside the post-approval resume grace?
|
|
@@ -27374,7 +27412,7 @@ ${lastSnapshot}`;
|
|
|
27374
27412
|
`[${this.cliType}] Waiting for interactive prompt: status=${status} stableMs=${stableMs} recentOutputMs=${recentlyOutput} screen=${JSON.stringify(summarizeCliTraceText(screenText, 220)).slice(0, 260)}`
|
|
27375
27413
|
);
|
|
27376
27414
|
}
|
|
27377
|
-
await new Promise((
|
|
27415
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
27378
27416
|
}
|
|
27379
27417
|
const finalScreenText = this.terminalScreen.getText() || "";
|
|
27380
27418
|
LOG.warn(
|
|
@@ -27741,7 +27779,7 @@ ${lastSnapshot}`;
|
|
|
27741
27779
|
if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
|
|
27742
27780
|
await this.ptyProcess.write(chunks[i]);
|
|
27743
27781
|
if (i + 1 < chunks.length) {
|
|
27744
|
-
await new Promise((
|
|
27782
|
+
await new Promise((resolve26) => setTimeout(resolve26, WIN32_PTY_WRITE_CHUNK_GAP_MS));
|
|
27745
27783
|
}
|
|
27746
27784
|
}
|
|
27747
27785
|
}
|
|
@@ -27909,7 +27947,7 @@ ${lastSnapshot}`;
|
|
|
27909
27947
|
this.onStatusChange?.();
|
|
27910
27948
|
}
|
|
27911
27949
|
async waitForForceSubmitSettle() {
|
|
27912
|
-
await new Promise((
|
|
27950
|
+
await new Promise((resolve26) => setTimeout(resolve26, FORCE_SUBMIT_SETTLE_MS));
|
|
27913
27951
|
}
|
|
27914
27952
|
enqueuePendingOutboundMessage(text, reason, meshTaskId) {
|
|
27915
27953
|
const content = String(text || "");
|
|
@@ -27988,7 +28026,7 @@ ${lastSnapshot}`;
|
|
|
27988
28026
|
const deadline = Date.now() + 1e4;
|
|
27989
28027
|
while (this.startupParseGate && Date.now() < deadline) {
|
|
27990
28028
|
this.resolveStartupState("send_wait");
|
|
27991
|
-
await new Promise((
|
|
28029
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
27992
28030
|
}
|
|
27993
28031
|
}
|
|
27994
28032
|
const parsedStatusBeforeSend = !allowInputDuringGeneration ? (() => {
|
|
@@ -28081,13 +28119,13 @@ ${lastSnapshot}`;
|
|
|
28081
28119
|
isFirstTurn: !this.firstTurnSent
|
|
28082
28120
|
};
|
|
28083
28121
|
this.engine.responseSettleIgnoreUntil = Date.now() + submitDelayMs + this.timeouts.outputSettle + 250;
|
|
28084
|
-
await new Promise((
|
|
28122
|
+
await new Promise((resolve26, reject) => {
|
|
28085
28123
|
let resolved = false;
|
|
28086
28124
|
const completion = {
|
|
28087
28125
|
resolveOnce: () => {
|
|
28088
28126
|
if (resolved) return;
|
|
28089
28127
|
resolved = true;
|
|
28090
|
-
|
|
28128
|
+
resolve26();
|
|
28091
28129
|
},
|
|
28092
28130
|
rejectOnce: (error) => {
|
|
28093
28131
|
if (resolved) return;
|
|
@@ -28275,17 +28313,17 @@ ${lastSnapshot}`;
|
|
|
28275
28313
|
}
|
|
28276
28314
|
}
|
|
28277
28315
|
waitForStopped(timeoutMs) {
|
|
28278
|
-
return new Promise((
|
|
28316
|
+
return new Promise((resolve26) => {
|
|
28279
28317
|
const startedAt = Date.now();
|
|
28280
28318
|
const timer = setInterval(() => {
|
|
28281
28319
|
if (!this.ptyProcess || this.engine.currentStatus === "stopped") {
|
|
28282
28320
|
clearInterval(timer);
|
|
28283
|
-
|
|
28321
|
+
resolve26(true);
|
|
28284
28322
|
return;
|
|
28285
28323
|
}
|
|
28286
28324
|
if (Date.now() - startedAt >= timeoutMs) {
|
|
28287
28325
|
clearInterval(timer);
|
|
28288
|
-
|
|
28326
|
+
resolve26(false);
|
|
28289
28327
|
}
|
|
28290
28328
|
}, 100);
|
|
28291
28329
|
});
|
|
@@ -31049,8 +31087,8 @@ async function detectIDEs(providerLoader) {
|
|
|
31049
31087
|
if ((0, import_fs15.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
31050
31088
|
}
|
|
31051
31089
|
if (!resolvedCli && appPath && os32 === "win32") {
|
|
31052
|
-
const { dirname:
|
|
31053
|
-
const appDir =
|
|
31090
|
+
const { dirname: dirname18 } = await import("path");
|
|
31091
|
+
const appDir = dirname18(appPath);
|
|
31054
31092
|
const candidates = [
|
|
31055
31093
|
`${appDir}\\\\bin\\\\${def.cli}.cmd`,
|
|
31056
31094
|
`${appDir}\\\\bin\\\\${def.cli}`,
|
|
@@ -31308,7 +31346,7 @@ var DaemonCdpManager = class {
|
|
|
31308
31346
|
* Returns multiple entries if multiple IDE windows are open on same port
|
|
31309
31347
|
*/
|
|
31310
31348
|
static listAllTargets(port) {
|
|
31311
|
-
return new Promise((
|
|
31349
|
+
return new Promise((resolve26) => {
|
|
31312
31350
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
31313
31351
|
let data = "";
|
|
31314
31352
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -31324,16 +31362,16 @@ var DaemonCdpManager = class {
|
|
|
31324
31362
|
(t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
|
|
31325
31363
|
);
|
|
31326
31364
|
const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
31327
|
-
|
|
31365
|
+
resolve26(mainPages.length > 0 ? mainPages : fallbackPages);
|
|
31328
31366
|
} catch {
|
|
31329
|
-
|
|
31367
|
+
resolve26([]);
|
|
31330
31368
|
}
|
|
31331
31369
|
});
|
|
31332
31370
|
});
|
|
31333
|
-
req.on("error", () =>
|
|
31371
|
+
req.on("error", () => resolve26([]));
|
|
31334
31372
|
req.setTimeout(2e3, () => {
|
|
31335
31373
|
req.destroy();
|
|
31336
|
-
|
|
31374
|
+
resolve26([]);
|
|
31337
31375
|
});
|
|
31338
31376
|
});
|
|
31339
31377
|
}
|
|
@@ -31373,7 +31411,7 @@ var DaemonCdpManager = class {
|
|
|
31373
31411
|
}
|
|
31374
31412
|
}
|
|
31375
31413
|
findTargetOnPort(port) {
|
|
31376
|
-
return new Promise((
|
|
31414
|
+
return new Promise((resolve26) => {
|
|
31377
31415
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
31378
31416
|
let data = "";
|
|
31379
31417
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -31384,7 +31422,7 @@ var DaemonCdpManager = class {
|
|
|
31384
31422
|
(t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
|
|
31385
31423
|
);
|
|
31386
31424
|
if (pages.length === 0) {
|
|
31387
|
-
|
|
31425
|
+
resolve26(targets.find((t) => t.webSocketDebuggerUrl) || null);
|
|
31388
31426
|
return;
|
|
31389
31427
|
}
|
|
31390
31428
|
const titleFilteredPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
|
|
@@ -31403,25 +31441,25 @@ var DaemonCdpManager = class {
|
|
|
31403
31441
|
this._targetId = selected.target.id;
|
|
31404
31442
|
}
|
|
31405
31443
|
this._pageTitle = selected.target.title || "";
|
|
31406
|
-
|
|
31444
|
+
resolve26(selected.target);
|
|
31407
31445
|
return;
|
|
31408
31446
|
}
|
|
31409
31447
|
if (previousTargetId) {
|
|
31410
31448
|
this.log(`[CDP] Target ${previousTargetId} not found in page list`);
|
|
31411
|
-
|
|
31449
|
+
resolve26(null);
|
|
31412
31450
|
return;
|
|
31413
31451
|
}
|
|
31414
31452
|
this._pageTitle = list[0]?.title || "";
|
|
31415
|
-
|
|
31453
|
+
resolve26(list[0]);
|
|
31416
31454
|
} catch {
|
|
31417
|
-
|
|
31455
|
+
resolve26(null);
|
|
31418
31456
|
}
|
|
31419
31457
|
});
|
|
31420
31458
|
});
|
|
31421
|
-
req.on("error", () =>
|
|
31459
|
+
req.on("error", () => resolve26(null));
|
|
31422
31460
|
req.setTimeout(2e3, () => {
|
|
31423
31461
|
req.destroy();
|
|
31424
|
-
|
|
31462
|
+
resolve26(null);
|
|
31425
31463
|
});
|
|
31426
31464
|
});
|
|
31427
31465
|
}
|
|
@@ -31432,7 +31470,7 @@ var DaemonCdpManager = class {
|
|
|
31432
31470
|
this.extensionProviders = providers;
|
|
31433
31471
|
}
|
|
31434
31472
|
connectToTarget(wsUrl) {
|
|
31435
|
-
return new Promise((
|
|
31473
|
+
return new Promise((resolve26) => {
|
|
31436
31474
|
this.ws = new import_ws.default(wsUrl);
|
|
31437
31475
|
this.ws.on("open", async () => {
|
|
31438
31476
|
this._connected = true;
|
|
@@ -31442,17 +31480,17 @@ var DaemonCdpManager = class {
|
|
|
31442
31480
|
}
|
|
31443
31481
|
this.connectBrowserWs().catch(() => {
|
|
31444
31482
|
});
|
|
31445
|
-
|
|
31483
|
+
resolve26(true);
|
|
31446
31484
|
});
|
|
31447
31485
|
this.ws.on("message", (data) => {
|
|
31448
31486
|
try {
|
|
31449
31487
|
const msg = JSON.parse(data.toString());
|
|
31450
31488
|
if (msg.id && this.pending.has(msg.id)) {
|
|
31451
|
-
const { resolve:
|
|
31489
|
+
const { resolve: resolve27, reject } = this.pending.get(msg.id);
|
|
31452
31490
|
this.pending.delete(msg.id);
|
|
31453
31491
|
this.failureCount = 0;
|
|
31454
31492
|
if (msg.error) reject(new Error(msg.error.message));
|
|
31455
|
-
else
|
|
31493
|
+
else resolve27(msg.result);
|
|
31456
31494
|
} else if (msg.method === "Runtime.executionContextCreated") {
|
|
31457
31495
|
this.contexts.add(msg.params.context.id);
|
|
31458
31496
|
} else if (msg.method === "Runtime.executionContextDestroyed") {
|
|
@@ -31475,7 +31513,7 @@ var DaemonCdpManager = class {
|
|
|
31475
31513
|
this.ws.on("error", (err) => {
|
|
31476
31514
|
this.log(`[CDP] WebSocket error: ${err.message}`);
|
|
31477
31515
|
this._connected = false;
|
|
31478
|
-
|
|
31516
|
+
resolve26(false);
|
|
31479
31517
|
});
|
|
31480
31518
|
});
|
|
31481
31519
|
}
|
|
@@ -31489,7 +31527,7 @@ var DaemonCdpManager = class {
|
|
|
31489
31527
|
return;
|
|
31490
31528
|
}
|
|
31491
31529
|
this.log(`[CDP] Connecting browser WS for target discovery...`);
|
|
31492
|
-
await new Promise((
|
|
31530
|
+
await new Promise((resolve26, reject) => {
|
|
31493
31531
|
this.browserWs = new import_ws.default(browserWsUrl);
|
|
31494
31532
|
this.browserWs.on("open", async () => {
|
|
31495
31533
|
this._browserConnected = true;
|
|
@@ -31499,16 +31537,16 @@ var DaemonCdpManager = class {
|
|
|
31499
31537
|
} catch (e) {
|
|
31500
31538
|
this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
|
|
31501
31539
|
}
|
|
31502
|
-
|
|
31540
|
+
resolve26();
|
|
31503
31541
|
});
|
|
31504
31542
|
this.browserWs.on("message", (data) => {
|
|
31505
31543
|
try {
|
|
31506
31544
|
const msg = JSON.parse(data.toString());
|
|
31507
31545
|
if (msg.id && this.browserPending.has(msg.id)) {
|
|
31508
|
-
const { resolve:
|
|
31546
|
+
const { resolve: resolve27, reject: reject2 } = this.browserPending.get(msg.id);
|
|
31509
31547
|
this.browserPending.delete(msg.id);
|
|
31510
31548
|
if (msg.error) reject2(new Error(msg.error.message));
|
|
31511
|
-
else
|
|
31549
|
+
else resolve27(msg.result);
|
|
31512
31550
|
}
|
|
31513
31551
|
} catch {
|
|
31514
31552
|
}
|
|
@@ -31528,31 +31566,31 @@ var DaemonCdpManager = class {
|
|
|
31528
31566
|
}
|
|
31529
31567
|
}
|
|
31530
31568
|
getBrowserWsUrl() {
|
|
31531
|
-
return new Promise((
|
|
31569
|
+
return new Promise((resolve26) => {
|
|
31532
31570
|
const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
|
|
31533
31571
|
let data = "";
|
|
31534
31572
|
res.on("data", (chunk) => data += chunk.toString());
|
|
31535
31573
|
res.on("end", () => {
|
|
31536
31574
|
try {
|
|
31537
31575
|
const info = JSON.parse(data);
|
|
31538
|
-
|
|
31576
|
+
resolve26(info.webSocketDebuggerUrl || null);
|
|
31539
31577
|
} catch {
|
|
31540
|
-
|
|
31578
|
+
resolve26(null);
|
|
31541
31579
|
}
|
|
31542
31580
|
});
|
|
31543
31581
|
});
|
|
31544
|
-
req.on("error", () =>
|
|
31582
|
+
req.on("error", () => resolve26(null));
|
|
31545
31583
|
req.setTimeout(3e3, () => {
|
|
31546
31584
|
req.destroy();
|
|
31547
|
-
|
|
31585
|
+
resolve26(null);
|
|
31548
31586
|
});
|
|
31549
31587
|
});
|
|
31550
31588
|
}
|
|
31551
31589
|
sendBrowser(method, params = {}, timeoutMs = 15e3) {
|
|
31552
|
-
return new Promise((
|
|
31590
|
+
return new Promise((resolve26, reject) => {
|
|
31553
31591
|
if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
|
|
31554
31592
|
const id = this.browserMsgId++;
|
|
31555
|
-
this.browserPending.set(id, { resolve:
|
|
31593
|
+
this.browserPending.set(id, { resolve: resolve26, reject });
|
|
31556
31594
|
this.browserWs.send(JSON.stringify({ id, method, params }));
|
|
31557
31595
|
setTimeout(() => {
|
|
31558
31596
|
if (this.browserPending.has(id)) {
|
|
@@ -31592,11 +31630,11 @@ var DaemonCdpManager = class {
|
|
|
31592
31630
|
}
|
|
31593
31631
|
// ─── CDP Protocol ────────────────────────────────────────
|
|
31594
31632
|
sendInternal(method, params = {}, timeoutMs = 15e3) {
|
|
31595
|
-
return new Promise((
|
|
31633
|
+
return new Promise((resolve26, reject) => {
|
|
31596
31634
|
if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
|
|
31597
31635
|
if (this.ws.readyState !== import_ws.default.OPEN) return reject(new Error("WebSocket not open"));
|
|
31598
31636
|
const id = this.msgId++;
|
|
31599
|
-
this.pending.set(id, { resolve:
|
|
31637
|
+
this.pending.set(id, { resolve: resolve26, reject });
|
|
31600
31638
|
this.ws.send(JSON.stringify({ id, method, params }));
|
|
31601
31639
|
setTimeout(() => {
|
|
31602
31640
|
if (this.pending.has(id)) {
|
|
@@ -31845,7 +31883,7 @@ var DaemonCdpManager = class {
|
|
|
31845
31883
|
const browserWs = this.browserWs;
|
|
31846
31884
|
let msgId = this.browserMsgId;
|
|
31847
31885
|
const sendWs = (method, params = {}, sessionId) => {
|
|
31848
|
-
return new Promise((
|
|
31886
|
+
return new Promise((resolve26, reject) => {
|
|
31849
31887
|
const mid = msgId++;
|
|
31850
31888
|
this.browserMsgId = msgId;
|
|
31851
31889
|
const handler = (raw) => {
|
|
@@ -31854,7 +31892,7 @@ var DaemonCdpManager = class {
|
|
|
31854
31892
|
if (msg.id === mid) {
|
|
31855
31893
|
browserWs.removeListener("message", handler);
|
|
31856
31894
|
if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
31857
|
-
else
|
|
31895
|
+
else resolve26(msg.result);
|
|
31858
31896
|
}
|
|
31859
31897
|
} catch {
|
|
31860
31898
|
}
|
|
@@ -32055,14 +32093,14 @@ var DaemonCdpManager = class {
|
|
|
32055
32093
|
if (!ws || ws.readyState !== import_ws.default.OPEN) {
|
|
32056
32094
|
throw new Error("CDP not connected");
|
|
32057
32095
|
}
|
|
32058
|
-
return new Promise((
|
|
32096
|
+
return new Promise((resolve26, reject) => {
|
|
32059
32097
|
const id = getNextId();
|
|
32060
32098
|
pendingMap.set(id, {
|
|
32061
32099
|
resolve: (result) => {
|
|
32062
32100
|
if (result?.result?.subtype === "error") {
|
|
32063
32101
|
reject(new Error(result.result.description));
|
|
32064
32102
|
} else {
|
|
32065
|
-
|
|
32103
|
+
resolve26(result?.result?.value);
|
|
32066
32104
|
}
|
|
32067
32105
|
},
|
|
32068
32106
|
reject
|
|
@@ -32094,10 +32132,10 @@ var DaemonCdpManager = class {
|
|
|
32094
32132
|
throw new Error("CDP not connected");
|
|
32095
32133
|
}
|
|
32096
32134
|
const sendViaSession = (method, params = {}) => {
|
|
32097
|
-
return new Promise((
|
|
32135
|
+
return new Promise((resolve26, reject) => {
|
|
32098
32136
|
const pendingMap = this._browserConnected ? this.browserPending : this.pending;
|
|
32099
32137
|
const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
|
|
32100
|
-
pendingMap.set(id, { resolve:
|
|
32138
|
+
pendingMap.set(id, { resolve: resolve26, reject });
|
|
32101
32139
|
ws.send(JSON.stringify({ id, sessionId, method, params }));
|
|
32102
32140
|
setTimeout(() => {
|
|
32103
32141
|
if (pendingMap.has(id)) {
|
|
@@ -36010,7 +36048,7 @@ function resolveTargetSessionActualWorkspace(h, targetSessionId) {
|
|
|
36010
36048
|
}
|
|
36011
36049
|
|
|
36012
36050
|
// src/commands/chat-commands-debug-bundle.ts
|
|
36013
|
-
var
|
|
36051
|
+
var fs9 = __toESM(require("fs"));
|
|
36014
36052
|
var os10 = __toESM(require("os"));
|
|
36015
36053
|
var path17 = __toESM(require("path"));
|
|
36016
36054
|
var import_node_crypto3 = require("crypto");
|
|
@@ -36018,6 +36056,7 @@ init_logger();
|
|
|
36018
36056
|
init_debug_trace();
|
|
36019
36057
|
|
|
36020
36058
|
// src/commands/chat-commands-read.ts
|
|
36059
|
+
var fs8 = __toESM(require("fs"));
|
|
36021
36060
|
var path16 = __toESM(require("path"));
|
|
36022
36061
|
init_contracts2();
|
|
36023
36062
|
init_state_store();
|
|
@@ -36971,7 +37010,16 @@ function readExactRuntimeMirrorMessages(args) {
|
|
|
36971
37010
|
function normalizeComparableWorkspace(value) {
|
|
36972
37011
|
const text = typeof value === "string" ? value.trim() : "";
|
|
36973
37012
|
if (!text) return "";
|
|
36974
|
-
|
|
37013
|
+
const lexical = path16.resolve(text);
|
|
37014
|
+
try {
|
|
37015
|
+
return fs8.realpathSync.native(lexical);
|
|
37016
|
+
} catch {
|
|
37017
|
+
try {
|
|
37018
|
+
return fs8.realpathSync(lexical);
|
|
37019
|
+
} catch {
|
|
37020
|
+
return lexical;
|
|
37021
|
+
}
|
|
37022
|
+
}
|
|
36975
37023
|
}
|
|
36976
37024
|
function isCurrentRuntimePtySafelyAttributed(args) {
|
|
36977
37025
|
if (args.adapter.cliType !== "codex-cli") return false;
|
|
@@ -38289,11 +38337,11 @@ function buildChatDebugBundleSummary(bundle) {
|
|
|
38289
38337
|
function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
38290
38338
|
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
38291
38339
|
const dir = getChatDebugBundleDir();
|
|
38292
|
-
|
|
38340
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
38293
38341
|
const savedPath = path17.join(dir, `${bundleId}.json`);
|
|
38294
38342
|
const json = `${JSON.stringify(bundle, null, 2)}
|
|
38295
38343
|
`;
|
|
38296
|
-
|
|
38344
|
+
fs9.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
|
|
38297
38345
|
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, "utf8") };
|
|
38298
38346
|
}
|
|
38299
38347
|
function isDaemonFileDebugDelivery(args) {
|
|
@@ -38454,7 +38502,7 @@ function getSendChatInputEnvelope(args) {
|
|
|
38454
38502
|
return normalizeInputEnvelope(args?.input ? { input: args.input } : args);
|
|
38455
38503
|
}
|
|
38456
38504
|
function sleep(ms) {
|
|
38457
|
-
return new Promise((
|
|
38505
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
38458
38506
|
}
|
|
38459
38507
|
async function waitOnceForFreshHermesCliStart(adapter, log) {
|
|
38460
38508
|
if (adapter.cliType !== "hermes-cli") return;
|
|
@@ -38509,7 +38557,7 @@ function getStateLastSignature(state) {
|
|
|
38509
38557
|
async function getStableExtensionBaseline(h) {
|
|
38510
38558
|
const first = await readExtensionChatState(h);
|
|
38511
38559
|
if (getStateMessageCount(first) > 0 || getStateLastSignature(first)) return first;
|
|
38512
|
-
await new Promise((
|
|
38560
|
+
await new Promise((resolve26) => setTimeout(resolve26, 150));
|
|
38513
38561
|
const second = await readExtensionChatState(h);
|
|
38514
38562
|
return getStateMessageCount(second) >= getStateMessageCount(first) ? second : first;
|
|
38515
38563
|
}
|
|
@@ -38517,7 +38565,7 @@ async function verifyExtensionSendObserved(h, before) {
|
|
|
38517
38565
|
const beforeCount = getStateMessageCount(before);
|
|
38518
38566
|
const beforeSignature = getStateLastSignature(before);
|
|
38519
38567
|
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
38520
|
-
await new Promise((
|
|
38568
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
38521
38569
|
const state = await readExtensionChatState(h);
|
|
38522
38570
|
if (state?.status === "waiting_approval") return true;
|
|
38523
38571
|
const afterCount = getStateMessageCount(state);
|
|
@@ -39234,7 +39282,7 @@ async function handleResolveAction(h, args) {
|
|
|
39234
39282
|
}
|
|
39235
39283
|
|
|
39236
39284
|
// src/commands/cdp-commands.ts
|
|
39237
|
-
var
|
|
39285
|
+
var fs10 = __toESM(require("fs"));
|
|
39238
39286
|
var path18 = __toESM(require("path"));
|
|
39239
39287
|
var os11 = __toESM(require("os"));
|
|
39240
39288
|
var KEY_TO_VK = {
|
|
@@ -39507,7 +39555,7 @@ function resolveSafePath(requestedPath) {
|
|
|
39507
39555
|
return path18.resolve(inputPath);
|
|
39508
39556
|
}
|
|
39509
39557
|
function listDirectoryEntriesSafe(dirPath) {
|
|
39510
|
-
const entries =
|
|
39558
|
+
const entries = fs10.readdirSync(dirPath, { withFileTypes: true });
|
|
39511
39559
|
const files = [];
|
|
39512
39560
|
for (const entry of entries) {
|
|
39513
39561
|
const entryPath = path18.join(dirPath, entry.name);
|
|
@@ -39519,14 +39567,14 @@ function listDirectoryEntriesSafe(dirPath) {
|
|
|
39519
39567
|
if (entry.isFile()) {
|
|
39520
39568
|
let size;
|
|
39521
39569
|
try {
|
|
39522
|
-
size =
|
|
39570
|
+
size = fs10.statSync(entryPath).size;
|
|
39523
39571
|
} catch {
|
|
39524
39572
|
size = void 0;
|
|
39525
39573
|
}
|
|
39526
39574
|
files.push({ name: entry.name, type: "file", size });
|
|
39527
39575
|
continue;
|
|
39528
39576
|
}
|
|
39529
|
-
const stat2 =
|
|
39577
|
+
const stat2 = fs10.statSync(entryPath);
|
|
39530
39578
|
files.push({
|
|
39531
39579
|
name: entry.name,
|
|
39532
39580
|
type: stat2.isDirectory() ? "directory" : "file",
|
|
@@ -39544,7 +39592,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
39544
39592
|
const letter = String.fromCharCode(code);
|
|
39545
39593
|
const root = `${letter}:\\`;
|
|
39546
39594
|
try {
|
|
39547
|
-
if (!
|
|
39595
|
+
if (!fs10.existsSync(root)) continue;
|
|
39548
39596
|
if (excluded && root.toLowerCase() === excluded) continue;
|
|
39549
39597
|
drives.push({ name: `${letter}:`, type: "directory", path: root });
|
|
39550
39598
|
} catch {
|
|
@@ -39555,7 +39603,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
39555
39603
|
async function handleFileRead(h, args) {
|
|
39556
39604
|
try {
|
|
39557
39605
|
const filePath = resolveSafePath(args?.path);
|
|
39558
|
-
const content =
|
|
39606
|
+
const content = fs10.readFileSync(filePath, "utf-8");
|
|
39559
39607
|
return { success: true, content, path: filePath };
|
|
39560
39608
|
} catch (e) {
|
|
39561
39609
|
return { success: false, error: e.message };
|
|
@@ -39564,8 +39612,8 @@ async function handleFileRead(h, args) {
|
|
|
39564
39612
|
async function handleFileWrite(h, args) {
|
|
39565
39613
|
try {
|
|
39566
39614
|
const filePath = resolveSafePath(args?.path);
|
|
39567
|
-
|
|
39568
|
-
|
|
39615
|
+
fs10.mkdirSync(path18.dirname(filePath), { recursive: true });
|
|
39616
|
+
fs10.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
39569
39617
|
return { success: true, path: filePath };
|
|
39570
39618
|
} catch (e) {
|
|
39571
39619
|
return { success: false, error: e.message };
|
|
@@ -39919,7 +39967,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
39919
39967
|
const enterCount = cliCommand.enterCount || 1;
|
|
39920
39968
|
await adapter.writeRaw(cliCommand.text + "\r");
|
|
39921
39969
|
for (let i = 1; i < enterCount; i += 1) {
|
|
39922
|
-
await new Promise((
|
|
39970
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
39923
39971
|
await adapter.writeRaw("\r");
|
|
39924
39972
|
}
|
|
39925
39973
|
}
|
|
@@ -40723,11 +40771,11 @@ var DaemonCommandHandler = class {
|
|
|
40723
40771
|
return { success: false, error: "invalid type" };
|
|
40724
40772
|
}
|
|
40725
40773
|
const https = require("https");
|
|
40726
|
-
const
|
|
40774
|
+
const fs43 = require("fs");
|
|
40727
40775
|
const path45 = require("path");
|
|
40728
40776
|
const REGISTRY = resolveRegistryBaseUrl(loadConfig().registryUrl);
|
|
40729
40777
|
function fetchText(url, timeoutMs) {
|
|
40730
|
-
return new Promise((
|
|
40778
|
+
return new Promise((resolve26, reject) => {
|
|
40731
40779
|
const req = https.get(url, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: timeoutMs }, (res) => {
|
|
40732
40780
|
if (res.statusCode !== 200) {
|
|
40733
40781
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
@@ -40735,7 +40783,7 @@ var DaemonCommandHandler = class {
|
|
|
40735
40783
|
}
|
|
40736
40784
|
const chunks = [];
|
|
40737
40785
|
res.on("data", (c) => chunks.push(c));
|
|
40738
|
-
res.on("end", () =>
|
|
40786
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
40739
40787
|
});
|
|
40740
40788
|
req.on("error", reject);
|
|
40741
40789
|
req.on("timeout", () => {
|
|
@@ -40766,7 +40814,7 @@ var DaemonCommandHandler = class {
|
|
|
40766
40814
|
if (!targetDir.startsWith(installRootResolved + path45.sep)) {
|
|
40767
40815
|
return { success: false, error: "install path escaped upstream root" };
|
|
40768
40816
|
}
|
|
40769
|
-
|
|
40817
|
+
fs43.mkdirSync(targetDir, { recursive: true });
|
|
40770
40818
|
let manifestProbe = {};
|
|
40771
40819
|
try {
|
|
40772
40820
|
manifestProbe = JSON.parse(manifestBody);
|
|
@@ -40791,7 +40839,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40791
40839
|
}
|
|
40792
40840
|
const targetFile = isV1 ? "provider.v1.json" : "provider.json";
|
|
40793
40841
|
const targetPath = path45.join(targetDir, targetFile);
|
|
40794
|
-
|
|
40842
|
+
fs43.writeFileSync(targetPath, manifestBody, "utf-8");
|
|
40795
40843
|
const manifestJson = JSON.parse(manifestBody);
|
|
40796
40844
|
const scriptFetch = await this.fetchProviderSources(
|
|
40797
40845
|
manifestJson,
|
|
@@ -40861,10 +40909,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40861
40909
|
const repo = source.repo;
|
|
40862
40910
|
const ref = source.ref;
|
|
40863
40911
|
const https = require("https");
|
|
40864
|
-
const
|
|
40912
|
+
const fs43 = require("fs");
|
|
40865
40913
|
const path45 = require("path");
|
|
40866
40914
|
function fetchJson(url, timeoutMs) {
|
|
40867
|
-
return new Promise((
|
|
40915
|
+
return new Promise((resolve26, reject) => {
|
|
40868
40916
|
const req = https.get(url, {
|
|
40869
40917
|
headers: { "User-Agent": "adhdev-daemon", "Accept": "application/vnd.github+json" },
|
|
40870
40918
|
timeout: timeoutMs
|
|
@@ -40877,7 +40925,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40877
40925
|
res.on("data", (c) => chunks.push(c));
|
|
40878
40926
|
res.on("end", () => {
|
|
40879
40927
|
try {
|
|
40880
|
-
|
|
40928
|
+
resolve26(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
40881
40929
|
} catch (e) {
|
|
40882
40930
|
reject(e);
|
|
40883
40931
|
}
|
|
@@ -40891,14 +40939,14 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40891
40939
|
});
|
|
40892
40940
|
}
|
|
40893
40941
|
function fetchBinary(url, timeoutMs) {
|
|
40894
|
-
return new Promise((
|
|
40942
|
+
return new Promise((resolve26, reject) => {
|
|
40895
40943
|
const req = https.get(url, {
|
|
40896
40944
|
headers: { "User-Agent": "adhdev-daemon" },
|
|
40897
40945
|
timeout: timeoutMs
|
|
40898
40946
|
}, (res) => {
|
|
40899
40947
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
40900
40948
|
if (res.headers.location) {
|
|
40901
|
-
return fetchBinary(res.headers.location, timeoutMs).then(
|
|
40949
|
+
return fetchBinary(res.headers.location, timeoutMs).then(resolve26, reject);
|
|
40902
40950
|
}
|
|
40903
40951
|
}
|
|
40904
40952
|
if (res.statusCode !== 200) {
|
|
@@ -40907,7 +40955,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40907
40955
|
}
|
|
40908
40956
|
const chunks = [];
|
|
40909
40957
|
res.on("data", (c) => chunks.push(c));
|
|
40910
|
-
res.on("end", () =>
|
|
40958
|
+
res.on("end", () => resolve26(Buffer.concat(chunks)));
|
|
40911
40959
|
});
|
|
40912
40960
|
req.on("error", reject);
|
|
40913
40961
|
req.on("timeout", () => {
|
|
@@ -40945,8 +40993,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40945
40993
|
const relInside = entry.path.startsWith(sharedDirRel + "/") ? entry.path.slice(sharedDirRel.length + 1) : entry.path;
|
|
40946
40994
|
const outPath = path45.resolve(path45.join(sharedTargetDir, relInside));
|
|
40947
40995
|
if (!outPath.startsWith(path45.resolve(sharedTargetDir) + path45.sep)) continue;
|
|
40948
|
-
|
|
40949
|
-
|
|
40996
|
+
fs43.mkdirSync(path45.dirname(outPath), { recursive: true });
|
|
40997
|
+
fs43.writeFileSync(outPath, body);
|
|
40950
40998
|
fetchedCount++;
|
|
40951
40999
|
} catch (e) {
|
|
40952
41000
|
errors.push(`fetch shared ${entry.path}: ${e?.message ?? e}`);
|
|
@@ -40984,8 +41032,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40984
41032
|
errors.push(`refusing to write outside targetDir: ${entry.path}`);
|
|
40985
41033
|
continue;
|
|
40986
41034
|
}
|
|
40987
|
-
|
|
40988
|
-
|
|
41035
|
+
fs43.mkdirSync(path45.dirname(outPath), { recursive: true });
|
|
41036
|
+
fs43.writeFileSync(outPath, body);
|
|
40989
41037
|
fetchedCount++;
|
|
40990
41038
|
} catch (e) {
|
|
40991
41039
|
errors.push(`fetch ${entry.path}: ${e?.message ?? e}`);
|
|
@@ -41013,7 +41061,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41013
41061
|
if (!["cli", "ide", "extension", "acp"].includes(category)) {
|
|
41014
41062
|
return { success: false, error: `unknown category: ${category}` };
|
|
41015
41063
|
}
|
|
41016
|
-
const
|
|
41064
|
+
const fs43 = require("fs");
|
|
41017
41065
|
const path45 = require("path");
|
|
41018
41066
|
try {
|
|
41019
41067
|
const installRoot = this.getUpstreamInstallRoot();
|
|
@@ -41022,10 +41070,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41022
41070
|
if (!targetDir.startsWith(installRootResolved + path45.sep)) {
|
|
41023
41071
|
return { success: false, error: "refusing to delete outside upstream root" };
|
|
41024
41072
|
}
|
|
41025
|
-
if (!
|
|
41073
|
+
if (!fs43.existsSync(targetDir)) {
|
|
41026
41074
|
return { success: false, error: "not installed" };
|
|
41027
41075
|
}
|
|
41028
|
-
|
|
41076
|
+
fs43.rmSync(targetDir, { recursive: true, force: true });
|
|
41029
41077
|
if (this._ctx.providerLoader) {
|
|
41030
41078
|
this._ctx.providerLoader.reload();
|
|
41031
41079
|
this._ctx.providerLoader.registerToDetector();
|
|
@@ -41041,28 +41089,28 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41041
41089
|
* the UI and by the update checker.
|
|
41042
41090
|
*/
|
|
41043
41091
|
handleListInstalledProviders(_args) {
|
|
41044
|
-
const
|
|
41092
|
+
const fs43 = require("fs");
|
|
41045
41093
|
const path45 = require("path");
|
|
41046
41094
|
const installRoot = this.getUpstreamInstallRoot();
|
|
41047
|
-
if (!
|
|
41095
|
+
if (!fs43.existsSync(installRoot)) return { success: true, providers: [] };
|
|
41048
41096
|
const CATEGORIES = ["cli", "ide", "extension", "acp"];
|
|
41049
41097
|
const items = [];
|
|
41050
41098
|
for (const category of CATEGORIES) {
|
|
41051
41099
|
const categoryDir = path45.join(installRoot, category);
|
|
41052
|
-
if (!
|
|
41100
|
+
if (!fs43.existsSync(categoryDir)) continue;
|
|
41053
41101
|
let entries;
|
|
41054
41102
|
try {
|
|
41055
|
-
entries =
|
|
41103
|
+
entries = fs43.readdirSync(categoryDir);
|
|
41056
41104
|
} catch {
|
|
41057
41105
|
continue;
|
|
41058
41106
|
}
|
|
41059
41107
|
for (const type of entries) {
|
|
41060
41108
|
const v1Path = path45.join(categoryDir, type, "provider.v1.json");
|
|
41061
41109
|
const v0Path = path45.join(categoryDir, type, "provider.json");
|
|
41062
|
-
const manifestPath =
|
|
41110
|
+
const manifestPath = fs43.existsSync(v1Path) ? v1Path : fs43.existsSync(v0Path) ? v0Path : null;
|
|
41063
41111
|
if (!manifestPath) continue;
|
|
41064
41112
|
try {
|
|
41065
|
-
const m = JSON.parse(
|
|
41113
|
+
const m = JSON.parse(fs43.readFileSync(manifestPath, "utf-8"));
|
|
41066
41114
|
const modelOptions = Array.isArray(m.modelOptions) ? m.modelOptions.filter((x) => typeof x === "string" && !!x.trim()) : [];
|
|
41067
41115
|
const thinkingLevelOptions = Array.isArray(m.thinkingLevelOptions) ? m.thinkingLevelOptions.filter((x) => typeof x === "string" && !!x.trim()) : [];
|
|
41068
41116
|
items.push({
|
|
@@ -41093,7 +41141,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41093
41141
|
const https = require("https");
|
|
41094
41142
|
const REGISTRY = resolveRegistryBaseUrl(loadConfig().registryUrl);
|
|
41095
41143
|
function fetchJson(url) {
|
|
41096
|
-
return new Promise((
|
|
41144
|
+
return new Promise((resolve26, reject) => {
|
|
41097
41145
|
const req = https.get(url, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 1e4 }, (res) => {
|
|
41098
41146
|
if (res.statusCode !== 200) {
|
|
41099
41147
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
@@ -41103,7 +41151,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41103
41151
|
res.on("data", (c) => chunks.push(c));
|
|
41104
41152
|
res.on("end", () => {
|
|
41105
41153
|
try {
|
|
41106
|
-
|
|
41154
|
+
resolve26(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
41107
41155
|
} catch (e) {
|
|
41108
41156
|
reject(e);
|
|
41109
41157
|
}
|
|
@@ -41177,7 +41225,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41177
41225
|
if (!/^@[a-z0-9_-]+$/i.test(requestedName)) {
|
|
41178
41226
|
return { success: false, error: "name must match @[a-z0-9_-]+" };
|
|
41179
41227
|
}
|
|
41180
|
-
const
|
|
41228
|
+
const fs43 = require("fs");
|
|
41181
41229
|
const path45 = require("path");
|
|
41182
41230
|
const { spawnSync: spawnSync2 } = require("child_process");
|
|
41183
41231
|
const file = ext.loadExternalSources();
|
|
@@ -41188,8 +41236,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41188
41236
|
return { success: false, error: `source url+ref already registered (use a different name to track another ref)` };
|
|
41189
41237
|
}
|
|
41190
41238
|
const sourceDir = path45.join(ext.externalRoot(), requestedName);
|
|
41191
|
-
if (!
|
|
41192
|
-
if (
|
|
41239
|
+
if (!fs43.existsSync(ext.externalRoot())) fs43.mkdirSync(ext.externalRoot(), { recursive: true });
|
|
41240
|
+
if (fs43.existsSync(sourceDir)) {
|
|
41193
41241
|
return { success: false, error: `directory already exists: ${sourceDir} (rename or remove first)` };
|
|
41194
41242
|
}
|
|
41195
41243
|
const clone = spawnSync2("git", ["clone", "--depth=1", "--branch", ref, "--", url, sourceDir], {
|
|
@@ -41199,7 +41247,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41199
41247
|
});
|
|
41200
41248
|
if (clone.status !== 0) {
|
|
41201
41249
|
try {
|
|
41202
|
-
|
|
41250
|
+
fs43.rmSync(sourceDir, { recursive: true, force: true });
|
|
41203
41251
|
} catch {
|
|
41204
41252
|
}
|
|
41205
41253
|
return { success: false, error: `git clone failed: ${(clone.stderr || clone.stdout || "").trim() || "unknown error"}` };
|
|
@@ -41243,15 +41291,15 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41243
41291
|
const name = typeof args?.name === "string" ? args.name.trim() : "";
|
|
41244
41292
|
if (!name) return { success: false, error: "name is required" };
|
|
41245
41293
|
const ext = (init_external_sources(), __toCommonJS(external_sources_exports));
|
|
41246
|
-
const
|
|
41294
|
+
const fs43 = require("fs");
|
|
41247
41295
|
const path45 = require("path");
|
|
41248
41296
|
const file = ext.loadExternalSources();
|
|
41249
41297
|
const match = file.sources.find((s2) => s2.name === name);
|
|
41250
41298
|
if (!match) return { success: false, error: `source "${name}" not registered` };
|
|
41251
41299
|
const sourceDir = path45.join(ext.externalRoot(), name);
|
|
41252
|
-
if (
|
|
41300
|
+
if (fs43.existsSync(sourceDir)) {
|
|
41253
41301
|
try {
|
|
41254
|
-
|
|
41302
|
+
fs43.rmSync(sourceDir, { recursive: true, force: true });
|
|
41255
41303
|
} catch (e) {
|
|
41256
41304
|
return { success: false, error: `failed to delete ${sourceDir}: ${e?.message || e}` };
|
|
41257
41305
|
}
|
|
@@ -41341,7 +41389,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41341
41389
|
try {
|
|
41342
41390
|
const http3 = await import("http");
|
|
41343
41391
|
const postData = JSON.stringify(body);
|
|
41344
|
-
const result = await new Promise((
|
|
41392
|
+
const result = await new Promise((resolve26, reject) => {
|
|
41345
41393
|
const req = http3.request({
|
|
41346
41394
|
hostname: "127.0.0.1",
|
|
41347
41395
|
port: 19280,
|
|
@@ -41353,9 +41401,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41353
41401
|
res.on("data", (chunk) => data += chunk);
|
|
41354
41402
|
res.on("end", () => {
|
|
41355
41403
|
try {
|
|
41356
|
-
|
|
41404
|
+
resolve26(JSON.parse(data));
|
|
41357
41405
|
} catch {
|
|
41358
|
-
|
|
41406
|
+
resolve26({ raw: data });
|
|
41359
41407
|
}
|
|
41360
41408
|
});
|
|
41361
41409
|
});
|
|
@@ -41373,15 +41421,15 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41373
41421
|
if (!providerType) return { success: false, error: "providerType required" };
|
|
41374
41422
|
try {
|
|
41375
41423
|
const http3 = await import("http");
|
|
41376
|
-
const result = await new Promise((
|
|
41424
|
+
const result = await new Promise((resolve26, reject) => {
|
|
41377
41425
|
http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
|
|
41378
41426
|
let data = "";
|
|
41379
41427
|
res.on("data", (chunk) => data += chunk);
|
|
41380
41428
|
res.on("end", () => {
|
|
41381
41429
|
try {
|
|
41382
|
-
|
|
41430
|
+
resolve26(JSON.parse(data));
|
|
41383
41431
|
} catch {
|
|
41384
|
-
|
|
41432
|
+
resolve26({ raw: data });
|
|
41385
41433
|
}
|
|
41386
41434
|
});
|
|
41387
41435
|
}).on("error", reject);
|
|
@@ -41395,7 +41443,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41395
41443
|
try {
|
|
41396
41444
|
const http3 = await import("http");
|
|
41397
41445
|
const postData = JSON.stringify(args || {});
|
|
41398
|
-
const result = await new Promise((
|
|
41446
|
+
const result = await new Promise((resolve26, reject) => {
|
|
41399
41447
|
const req = http3.request({
|
|
41400
41448
|
hostname: "127.0.0.1",
|
|
41401
41449
|
port: 19280,
|
|
@@ -41407,9 +41455,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41407
41455
|
res.on("data", (chunk) => data += chunk);
|
|
41408
41456
|
res.on("end", () => {
|
|
41409
41457
|
try {
|
|
41410
|
-
|
|
41458
|
+
resolve26(JSON.parse(data));
|
|
41411
41459
|
} catch {
|
|
41412
|
-
|
|
41460
|
+
resolve26({ raw: data });
|
|
41413
41461
|
}
|
|
41414
41462
|
});
|
|
41415
41463
|
});
|
|
@@ -41923,7 +41971,7 @@ var refineConfigHandlers = {
|
|
|
41923
41971
|
};
|
|
41924
41972
|
|
|
41925
41973
|
// src/commands/low-family/diagnostics.ts
|
|
41926
|
-
var
|
|
41974
|
+
var fs13 = __toESM(require("fs"));
|
|
41927
41975
|
init_logger();
|
|
41928
41976
|
init_debug_trace();
|
|
41929
41977
|
var diagnosticsHandlers = {
|
|
@@ -41942,8 +41990,8 @@ var diagnosticsHandlers = {
|
|
|
41942
41990
|
if (sinceTs > 0) {
|
|
41943
41991
|
return { success: true, logs: [], totalBuffered: 0 };
|
|
41944
41992
|
}
|
|
41945
|
-
if (
|
|
41946
|
-
const content =
|
|
41993
|
+
if (fs13.existsSync(LOG_PATH)) {
|
|
41994
|
+
const content = fs13.readFileSync(LOG_PATH, "utf-8");
|
|
41947
41995
|
const allLines = content.split("\n");
|
|
41948
41996
|
const recent = allLines.slice(-count).join("\n");
|
|
41949
41997
|
return { success: true, logs: recent, totalLines: allLines.length };
|
|
@@ -42090,14 +42138,14 @@ var coordinatorPromptHandlers = {
|
|
|
42090
42138
|
}
|
|
42091
42139
|
},
|
|
42092
42140
|
list_coordinator_prompts: async (_ctx, _args) => {
|
|
42093
|
-
const
|
|
42141
|
+
const fs43 = await import("fs");
|
|
42094
42142
|
const path45 = await import("path");
|
|
42095
42143
|
const os32 = await import("os");
|
|
42096
42144
|
const dir = path45.join(os32.homedir(), ".adhdev", "coordinator-prompts");
|
|
42097
42145
|
const entries = {};
|
|
42098
42146
|
try {
|
|
42099
|
-
if (
|
|
42100
|
-
for (const name of
|
|
42147
|
+
if (fs43.existsSync(dir)) {
|
|
42148
|
+
for (const name of fs43.readdirSync(dir)) {
|
|
42101
42149
|
const matchOverride = name.match(/^([a-zA-Z0-9_.-]+)\.md$/);
|
|
42102
42150
|
const matchAppend = name.match(/^([a-zA-Z0-9_.-]+)\.append\.md$/);
|
|
42103
42151
|
const m = matchAppend || matchOverride;
|
|
@@ -42107,7 +42155,7 @@ var coordinatorPromptHandlers = {
|
|
|
42107
42155
|
const full = path45.join(dir, name);
|
|
42108
42156
|
let content = "";
|
|
42109
42157
|
try {
|
|
42110
|
-
content =
|
|
42158
|
+
content = fs43.readFileSync(full, "utf8");
|
|
42111
42159
|
} catch {
|
|
42112
42160
|
}
|
|
42113
42161
|
if (!entries[key2]) entries[key2] = { override: "", append: "" };
|
|
@@ -42121,7 +42169,7 @@ var coordinatorPromptHandlers = {
|
|
|
42121
42169
|
return { success: true, dir, entries };
|
|
42122
42170
|
},
|
|
42123
42171
|
write_coordinator_prompt: async (_ctx, args) => {
|
|
42124
|
-
const
|
|
42172
|
+
const fs43 = await import("fs");
|
|
42125
42173
|
const path45 = await import("path");
|
|
42126
42174
|
const os32 = await import("os");
|
|
42127
42175
|
const key2 = typeof args?.key === "string" ? args.key.trim() : "";
|
|
@@ -42134,11 +42182,11 @@ var coordinatorPromptHandlers = {
|
|
|
42134
42182
|
const filename = kind === "append" ? `${key2}.append.md` : `${key2}.md`;
|
|
42135
42183
|
const full = path45.join(dir, filename);
|
|
42136
42184
|
try {
|
|
42137
|
-
|
|
42185
|
+
fs43.mkdirSync(dir, { recursive: true });
|
|
42138
42186
|
if (content.trim()) {
|
|
42139
|
-
|
|
42140
|
-
} else if (
|
|
42141
|
-
|
|
42187
|
+
fs43.writeFileSync(full, content, { encoding: "utf8", mode: 384 });
|
|
42188
|
+
} else if (fs43.existsSync(full)) {
|
|
42189
|
+
fs43.unlinkSync(full);
|
|
42142
42190
|
}
|
|
42143
42191
|
return { success: true, path: full, kind, key: key2 };
|
|
42144
42192
|
} catch (error) {
|
|
@@ -42254,21 +42302,21 @@ init_config();
|
|
|
42254
42302
|
// src/commands/upgrade-helper.ts
|
|
42255
42303
|
var import_child_process5 = require("child_process");
|
|
42256
42304
|
var import_child_process6 = require("child_process");
|
|
42257
|
-
var
|
|
42305
|
+
var fs14 = __toESM(require("fs"));
|
|
42258
42306
|
var os13 = __toESM(require("os"));
|
|
42259
42307
|
var path20 = __toESM(require("path"));
|
|
42260
42308
|
var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
42261
42309
|
function getUpgradeLogPath() {
|
|
42262
42310
|
const home = os13.homedir();
|
|
42263
42311
|
const dir = path20.join(home, ".adhdev");
|
|
42264
|
-
|
|
42312
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
42265
42313
|
return path20.join(dir, "daemon-upgrade.log");
|
|
42266
42314
|
}
|
|
42267
42315
|
function appendUpgradeLog(message) {
|
|
42268
42316
|
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
42269
42317
|
`;
|
|
42270
42318
|
try {
|
|
42271
|
-
|
|
42319
|
+
fs14.appendFileSync(getUpgradeLogPath(), line, "utf8");
|
|
42272
42320
|
} catch {
|
|
42273
42321
|
}
|
|
42274
42322
|
}
|
|
@@ -42276,12 +42324,12 @@ function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platfo
|
|
|
42276
42324
|
const binDir = path20.dirname(nodeExecutable);
|
|
42277
42325
|
if (platform10 === "win32") {
|
|
42278
42326
|
const npmCliPath = path20.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
42279
|
-
if (
|
|
42327
|
+
if (fs14.existsSync(npmCliPath)) {
|
|
42280
42328
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
42281
42329
|
}
|
|
42282
42330
|
for (const candidate of ["npm.exe", "npm"]) {
|
|
42283
42331
|
const candidatePath = path20.join(binDir, candidate);
|
|
42284
|
-
if (
|
|
42332
|
+
if (fs14.existsSync(candidatePath)) {
|
|
42285
42333
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
42286
42334
|
}
|
|
42287
42335
|
}
|
|
@@ -42289,7 +42337,7 @@ function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platfo
|
|
|
42289
42337
|
}
|
|
42290
42338
|
for (const candidate of ["npm"]) {
|
|
42291
42339
|
const candidatePath = path20.join(binDir, candidate);
|
|
42292
|
-
if (
|
|
42340
|
+
if (fs14.existsSync(candidatePath)) {
|
|
42293
42341
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
42294
42342
|
}
|
|
42295
42343
|
}
|
|
@@ -42299,12 +42347,12 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
42299
42347
|
if (!currentCliPath) return null;
|
|
42300
42348
|
let resolvedPath = currentCliPath;
|
|
42301
42349
|
try {
|
|
42302
|
-
resolvedPath =
|
|
42350
|
+
resolvedPath = fs14.realpathSync.native(currentCliPath);
|
|
42303
42351
|
} catch {
|
|
42304
42352
|
}
|
|
42305
42353
|
let currentDir = resolvedPath;
|
|
42306
42354
|
try {
|
|
42307
|
-
if (
|
|
42355
|
+
if (fs14.statSync(resolvedPath).isFile()) {
|
|
42308
42356
|
currentDir = path20.dirname(resolvedPath);
|
|
42309
42357
|
}
|
|
42310
42358
|
} catch {
|
|
@@ -42313,8 +42361,8 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
42313
42361
|
while (true) {
|
|
42314
42362
|
const packageJsonPath = path20.join(currentDir, "package.json");
|
|
42315
42363
|
try {
|
|
42316
|
-
if (
|
|
42317
|
-
const parsed = JSON.parse(
|
|
42364
|
+
if (fs14.existsSync(packageJsonPath)) {
|
|
42365
|
+
const parsed = JSON.parse(fs14.readFileSync(packageJsonPath, "utf8"));
|
|
42318
42366
|
if (parsed?.name === packageName) {
|
|
42319
42367
|
const normalized = currentDir.replace(/\\/g, "/");
|
|
42320
42368
|
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
@@ -42455,7 +42503,7 @@ async function waitForPidExit(pid, timeoutMs) {
|
|
|
42455
42503
|
while (Date.now() - start < timeoutMs) {
|
|
42456
42504
|
try {
|
|
42457
42505
|
process.kill(pid, 0);
|
|
42458
|
-
await new Promise((
|
|
42506
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
42459
42507
|
} catch {
|
|
42460
42508
|
return;
|
|
42461
42509
|
}
|
|
@@ -42465,8 +42513,8 @@ async function stopSessionHostProcesses(appName) {
|
|
|
42465
42513
|
const pidFile = path20.join(os13.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
42466
42514
|
let killedPid = null;
|
|
42467
42515
|
try {
|
|
42468
|
-
if (
|
|
42469
|
-
const pid = Number.parseInt(
|
|
42516
|
+
if (fs14.existsSync(pidFile)) {
|
|
42517
|
+
const pid = Number.parseInt(fs14.readFileSync(pidFile, "utf8").trim(), 10);
|
|
42470
42518
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
|
|
42471
42519
|
if (killPid(pid)) killedPid = pid;
|
|
42472
42520
|
}
|
|
@@ -42474,7 +42522,7 @@ async function stopSessionHostProcesses(appName) {
|
|
|
42474
42522
|
} catch {
|
|
42475
42523
|
} finally {
|
|
42476
42524
|
try {
|
|
42477
|
-
|
|
42525
|
+
fs14.unlinkSync(pidFile);
|
|
42478
42526
|
} catch {
|
|
42479
42527
|
}
|
|
42480
42528
|
}
|
|
@@ -42551,7 +42599,7 @@ function getUpgradeFailureNoticePath() {
|
|
|
42551
42599
|
const home = os13.homedir();
|
|
42552
42600
|
const dir = path20.join(home, ".adhdev");
|
|
42553
42601
|
try {
|
|
42554
|
-
|
|
42602
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
42555
42603
|
} catch {
|
|
42556
42604
|
}
|
|
42557
42605
|
return path20.join(dir, "daemon-upgrade-last-error.txt");
|
|
@@ -42564,7 +42612,7 @@ function emitUpgradeFailureNotice(lines) {
|
|
|
42564
42612
|
appendUpgradeLog(`Upgrade blocked \u2014 user action required:
|
|
42565
42613
|
${body}`);
|
|
42566
42614
|
try {
|
|
42567
|
-
|
|
42615
|
+
fs14.writeFileSync(getUpgradeFailureNoticePath(), `[${(/* @__PURE__ */ new Date()).toISOString()}]
|
|
42568
42616
|
${body}
|
|
42569
42617
|
`, "utf8");
|
|
42570
42618
|
} catch {
|
|
@@ -42579,13 +42627,13 @@ function isRetriableInstallLockError(error) {
|
|
|
42579
42627
|
function removeDaemonPidFile() {
|
|
42580
42628
|
const pidFile = path20.join(os13.homedir(), ".adhdev", "daemon.pid");
|
|
42581
42629
|
try {
|
|
42582
|
-
|
|
42630
|
+
fs14.unlinkSync(pidFile);
|
|
42583
42631
|
} catch {
|
|
42584
42632
|
}
|
|
42585
42633
|
}
|
|
42586
42634
|
function safeRemoveStaleEntry(target, label) {
|
|
42587
42635
|
try {
|
|
42588
|
-
|
|
42636
|
+
fs14.rmSync(target, { recursive: true, force: true });
|
|
42589
42637
|
appendUpgradeLog(`${label}: ${target}`);
|
|
42590
42638
|
} catch (error) {
|
|
42591
42639
|
appendUpgradeLog(`Skipped locked stale entry (${error?.code || "error"}): ${target} \u2014 ${error?.message || String(error)}`);
|
|
@@ -42606,19 +42654,19 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
42606
42654
|
if (pkgName.startsWith("@")) {
|
|
42607
42655
|
const [scope, name] = pkgName.split("/");
|
|
42608
42656
|
const scopeDir = path20.join(npmRoot, scope);
|
|
42609
|
-
if (!
|
|
42610
|
-
for (const entry of
|
|
42657
|
+
if (!fs14.existsSync(scopeDir)) return;
|
|
42658
|
+
for (const entry of fs14.readdirSync(scopeDir)) {
|
|
42611
42659
|
if (!entry.startsWith(`.${name}-`)) continue;
|
|
42612
42660
|
safeRemoveStaleEntry(path20.join(scopeDir, entry), "Removed stale scoped staging dir");
|
|
42613
42661
|
}
|
|
42614
42662
|
} else {
|
|
42615
|
-
for (const entry of
|
|
42663
|
+
for (const entry of fs14.readdirSync(npmRoot)) {
|
|
42616
42664
|
if (!entry.startsWith(`.${pkgName}-`)) continue;
|
|
42617
42665
|
safeRemoveStaleEntry(path20.join(npmRoot, entry), "Removed stale staging dir");
|
|
42618
42666
|
}
|
|
42619
42667
|
}
|
|
42620
|
-
if (
|
|
42621
|
-
for (const entry of
|
|
42668
|
+
if (fs14.existsSync(binDir)) {
|
|
42669
|
+
for (const entry of fs14.readdirSync(binDir)) {
|
|
42622
42670
|
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
42623
42671
|
safeRemoveStaleEntry(path20.join(binDir, entry), "Removed stale bin staging entry");
|
|
42624
42672
|
}
|
|
@@ -42681,7 +42729,7 @@ async function runDaemonUpgradeHelper(payload) {
|
|
|
42681
42729
|
appendUpgradeLog(`Install attempt ${attempt} hit a file lock (${error?.code || "lock"}); clearing holders + staging and retrying after backoff`);
|
|
42682
42730
|
await stopForeignNativeAddonHolders(installCommand.surface.packageRoot, { parentPid: payload.parentPid });
|
|
42683
42731
|
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
42684
|
-
await new Promise((
|
|
42732
|
+
await new Promise((resolve26) => setTimeout(resolve26, attempt * 1500));
|
|
42685
42733
|
continue;
|
|
42686
42734
|
}
|
|
42687
42735
|
if (isRetriableInstallLockError(error)) {
|
|
@@ -42709,7 +42757,7 @@ async function runDaemonUpgradeHelper(payload) {
|
|
|
42709
42757
|
appendUpgradeLog(installOutput.trim());
|
|
42710
42758
|
}
|
|
42711
42759
|
if (process.platform === "win32") {
|
|
42712
|
-
await new Promise((
|
|
42760
|
+
await new Promise((resolve26) => setTimeout(resolve26, 500));
|
|
42713
42761
|
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
42714
42762
|
appendUpgradeLog("Post-install staging cleanup complete");
|
|
42715
42763
|
}
|
|
@@ -42874,7 +42922,7 @@ var meshLedgerHandlers = {
|
|
|
42874
42922
|
init_dist();
|
|
42875
42923
|
|
|
42876
42924
|
// src/logging/log-tail-reader.ts
|
|
42877
|
-
var
|
|
42925
|
+
var fs15 = __toESM(require("fs"));
|
|
42878
42926
|
init_logger();
|
|
42879
42927
|
var DEFAULT_TAIL_BYTES = 64 * 1024;
|
|
42880
42928
|
var MAX_TAIL_BYTES = 128 * 1024;
|
|
@@ -42892,9 +42940,9 @@ function clampTailBytes(tailBytes) {
|
|
|
42892
42940
|
return Math.min(Math.floor(tailBytes), MAX_TAIL_BYTES);
|
|
42893
42941
|
}
|
|
42894
42942
|
function readByteBoundedTail(filePath, limitBytes) {
|
|
42895
|
-
const fd =
|
|
42943
|
+
const fd = fs15.openSync(filePath, "r");
|
|
42896
42944
|
try {
|
|
42897
|
-
const stat2 =
|
|
42945
|
+
const stat2 = fs15.fstatSync(fd);
|
|
42898
42946
|
const size = stat2.size;
|
|
42899
42947
|
if (size === 0) return { text: "", truncated: false, bytesReturned: 0 };
|
|
42900
42948
|
const want = Math.min(limitBytes, size);
|
|
@@ -42905,7 +42953,7 @@ function readByteBoundedTail(filePath, limitBytes) {
|
|
|
42905
42953
|
while (position < size) {
|
|
42906
42954
|
const chunkSize = Math.min(READ_CHUNK_BYTES, size - position);
|
|
42907
42955
|
const chunk = Buffer.alloc(chunkSize);
|
|
42908
|
-
|
|
42956
|
+
fs15.readSync(fd, chunk, 0, chunkSize, position);
|
|
42909
42957
|
buffers.push(chunk);
|
|
42910
42958
|
position += chunkSize;
|
|
42911
42959
|
}
|
|
@@ -42918,7 +42966,7 @@ function readByteBoundedTail(filePath, limitBytes) {
|
|
|
42918
42966
|
}
|
|
42919
42967
|
return { text: buf.toString("utf-8"), truncated, bytesReturned: buf.length };
|
|
42920
42968
|
} finally {
|
|
42921
|
-
|
|
42969
|
+
fs15.closeSync(fd);
|
|
42922
42970
|
}
|
|
42923
42971
|
}
|
|
42924
42972
|
function splitLogLines(text) {
|
|
@@ -42996,8 +43044,8 @@ function readDaemonLogTail(args = {}) {
|
|
|
42996
43044
|
const limitBytes = clampTailBytes(args.tailBytes);
|
|
42997
43045
|
const primaryPath = resolveLogPath(args.date);
|
|
42998
43046
|
const backupPath = primaryPath.replace(/\.log$/, ".1.log");
|
|
42999
|
-
const primaryExists =
|
|
43000
|
-
const backupExists =
|
|
43047
|
+
const primaryExists = fs15.existsSync(primaryPath);
|
|
43048
|
+
const backupExists = fs15.existsSync(backupPath);
|
|
43001
43049
|
if (!primaryExists && !backupExists) {
|
|
43002
43050
|
return errorResult(
|
|
43003
43051
|
`No daemon log file at ${primaryPath} (dir: ${getDaemonLogDir()})`,
|
|
@@ -43036,7 +43084,7 @@ function readDaemonLogTail(args = {}) {
|
|
|
43036
43084
|
try {
|
|
43037
43085
|
for (const p of [backupExists ? backupPath : null, primaryExists ? primaryPath : null]) {
|
|
43038
43086
|
if (!p) continue;
|
|
43039
|
-
const buf =
|
|
43087
|
+
const buf = fs15.readFileSync(p);
|
|
43040
43088
|
scannedBytes += buf.length;
|
|
43041
43089
|
allLines = allLines.concat(splitLogLines(buf.toString("utf-8")));
|
|
43042
43090
|
}
|
|
@@ -43240,18 +43288,18 @@ init_summary_metadata();
|
|
|
43240
43288
|
// src/providers/cli-provider-instance.ts
|
|
43241
43289
|
var os21 = __toESM(require("os"));
|
|
43242
43290
|
var crypto5 = __toESM(require("crypto"));
|
|
43243
|
-
var
|
|
43291
|
+
var fs23 = __toESM(require("fs"));
|
|
43244
43292
|
init_contracts2();
|
|
43245
43293
|
init_provider_input_support();
|
|
43246
43294
|
init_hash();
|
|
43247
43295
|
|
|
43248
43296
|
// src/providers/spec/route.ts
|
|
43249
|
-
var
|
|
43297
|
+
var fs21 = __toESM(require("fs"));
|
|
43250
43298
|
var path25 = __toESM(require("path"));
|
|
43251
43299
|
init_provider_cli_adapter();
|
|
43252
43300
|
|
|
43253
43301
|
// src/providers/spec/fsm-driver.ts
|
|
43254
|
-
var
|
|
43302
|
+
var fs17 = __toESM(require("fs"));
|
|
43255
43303
|
var os18 = __toESM(require("os"));
|
|
43256
43304
|
var path23 = __toESM(require("path"));
|
|
43257
43305
|
|
|
@@ -43430,7 +43478,7 @@ init_fsm_types();
|
|
|
43430
43478
|
init_fsm_loader();
|
|
43431
43479
|
|
|
43432
43480
|
// src/providers/spec/pre-launch-trust.ts
|
|
43433
|
-
var
|
|
43481
|
+
var fs16 = __toESM(require("fs"));
|
|
43434
43482
|
var os17 = __toESM(require("os"));
|
|
43435
43483
|
var path22 = __toESM(require("path"));
|
|
43436
43484
|
init_logger();
|
|
@@ -43441,7 +43489,7 @@ function expandHome2(p) {
|
|
|
43441
43489
|
}
|
|
43442
43490
|
function realWorkspacePath(workingDir) {
|
|
43443
43491
|
try {
|
|
43444
|
-
return
|
|
43492
|
+
return fs16.realpathSync(workingDir);
|
|
43445
43493
|
} catch {
|
|
43446
43494
|
return path22.resolve(workingDir);
|
|
43447
43495
|
}
|
|
@@ -43452,8 +43500,8 @@ function applyPreLaunchTrust(trust, workingDir) {
|
|
|
43452
43500
|
const real = realWorkspacePath(workingDir);
|
|
43453
43501
|
try {
|
|
43454
43502
|
let parsed = {};
|
|
43455
|
-
if (
|
|
43456
|
-
const text =
|
|
43503
|
+
if (fs16.existsSync(settingsPath)) {
|
|
43504
|
+
const text = fs16.readFileSync(settingsPath, "utf8");
|
|
43457
43505
|
if (text.trim().length > 0) {
|
|
43458
43506
|
const json = JSON.parse(text);
|
|
43459
43507
|
if (json && typeof json === "object" && !Array.isArray(json)) {
|
|
@@ -43469,8 +43517,8 @@ function applyPreLaunchTrust(trust, workingDir) {
|
|
|
43469
43517
|
}
|
|
43470
43518
|
list.push(real);
|
|
43471
43519
|
parsed[key2] = list;
|
|
43472
|
-
|
|
43473
|
-
|
|
43520
|
+
fs16.mkdirSync(path22.dirname(settingsPath), { recursive: true });
|
|
43521
|
+
fs16.writeFileSync(settingsPath, `${JSON.stringify(parsed, null, 2)}
|
|
43474
43522
|
`, "utf8");
|
|
43475
43523
|
LOG.info("pre-launch-trust", `pre-trusted workspace in ${trust.settings_path} (key="${key2}")`);
|
|
43476
43524
|
return real;
|
|
@@ -43833,7 +43881,7 @@ var FsmDriver = class {
|
|
|
43833
43881
|
try {
|
|
43834
43882
|
const dir = path23.dirname(this.opts.specPath);
|
|
43835
43883
|
const base = path23.basename(this.opts.specPath);
|
|
43836
|
-
this.specWatcher =
|
|
43884
|
+
this.specWatcher = fs17.watch(dir, { persistent: false }, (_event, filename) => {
|
|
43837
43885
|
if (filename && filename !== base) return;
|
|
43838
43886
|
const res = loadFsmSpec(this.opts.specPath);
|
|
43839
43887
|
if (!res.ok) {
|
|
@@ -44469,7 +44517,7 @@ var FsmDriver = class {
|
|
|
44469
44517
|
const ext = guessExt(mime);
|
|
44470
44518
|
const tmp = path23.join(os18.tmpdir(), `adhdev-attach-${Date.now()}${ext}`);
|
|
44471
44519
|
try {
|
|
44472
|
-
|
|
44520
|
+
fs17.writeFileSync(tmp, Buffer.from(blob, "base64"));
|
|
44473
44521
|
} catch {
|
|
44474
44522
|
return;
|
|
44475
44523
|
}
|
|
@@ -44601,7 +44649,7 @@ function filterIgnoredLines(lines, ignoreRe) {
|
|
|
44601
44649
|
init_evaluator();
|
|
44602
44650
|
|
|
44603
44651
|
// src/providers/spec/native-history-executor.ts
|
|
44604
|
-
var
|
|
44652
|
+
var fs18 = __toESM(require("fs"));
|
|
44605
44653
|
var os19 = __toESM(require("os"));
|
|
44606
44654
|
var path24 = __toESM(require("path"));
|
|
44607
44655
|
init_logger();
|
|
@@ -44626,7 +44674,7 @@ function executeJsonl(src, input) {
|
|
|
44626
44674
|
const wsRaw = typeof input.workspace === "string" ? input.workspace : "";
|
|
44627
44675
|
let wsReal = wsRaw;
|
|
44628
44676
|
try {
|
|
44629
|
-
if (wsRaw) wsReal =
|
|
44677
|
+
if (wsRaw) wsReal = fs18.realpathSync(wsRaw);
|
|
44630
44678
|
} catch {
|
|
44631
44679
|
}
|
|
44632
44680
|
LOG.debug("NativeHistory", `jsonl unresolved: tried=${JSON.stringify(resolved)} sessionId=${requestedSessionId || "(none)"} wsRaw=${JSON.stringify(wsRaw)} wsReal=${JSON.stringify(wsReal)} rawSlug=${JSON.stringify(claudeProjectDirName(wsRaw))} realSlug=${JSON.stringify(claudeProjectDirName(wsReal))} (concrete miss + raw-slug retry + projects scan all failed)`);
|
|
@@ -44635,23 +44683,26 @@ function executeJsonl(src, input) {
|
|
|
44635
44683
|
const mtime = safeMtimeMs(sourcePath);
|
|
44636
44684
|
const lines = readJsonlLines(sourcePath);
|
|
44637
44685
|
if (lines.length === 0) return null;
|
|
44638
|
-
const transcriptWorkspace = readSessionMetaWorkspace(lines) ?? (src.workspace_from_input ? workspaceFromInputIfSlugMatches(sourcePath, input) : void 0);
|
|
44686
|
+
const transcriptWorkspace = readSessionMetaWorkspace(lines) ?? (src.workspace_from_sidecar ? readSidecarWorkspace(sourcePath, src.workspace_from_sidecar) : void 0) ?? (src.workspace_from_input ? workspaceFromInputIfSlugMatches(sourcePath, input) : void 0);
|
|
44639
44687
|
let providerSessionId;
|
|
44640
44688
|
if (src.session_id_from === "first_record" && src.session_id_path) {
|
|
44641
44689
|
const v = jsonPathGet(lines[0], src.session_id_path);
|
|
44642
44690
|
if (typeof v === "string" && v) providerSessionId = v;
|
|
44691
|
+
} else if (src.session_id_from === "dir_uuid") {
|
|
44692
|
+
providerSessionId = dirUuid(sourcePath) || void 0;
|
|
44643
44693
|
} else if (src.session_id_from === "filename_uuid" || !src.session_id_from) {
|
|
44644
44694
|
const m = path24.basename(sourcePath).match(UUID_RE);
|
|
44645
44695
|
if (m) providerSessionId = m[1];
|
|
44646
44696
|
}
|
|
44647
44697
|
const requested = readRequestedSessionId(input) || "";
|
|
44648
|
-
if (requested && providerSessionId && providerSessionId
|
|
44649
|
-
const
|
|
44698
|
+
if (requested && providerSessionId && !sameSessionUuid(providerSessionId, requested)) return null;
|
|
44699
|
+
const shapes = compileRecordShapes(src);
|
|
44650
44700
|
const messages = [];
|
|
44651
44701
|
for (let i = 0; i < lines.length; i += 1) {
|
|
44652
44702
|
const rec = lines[i];
|
|
44653
|
-
|
|
44654
|
-
|
|
44703
|
+
const shape = shapes.pick(rec);
|
|
44704
|
+
if (!shape) continue;
|
|
44705
|
+
for (const msg of projectMessages(rec, shape.map, i, lines.length, mtime)) {
|
|
44655
44706
|
if (transcriptWorkspace) msg.workspace = transcriptWorkspace;
|
|
44656
44707
|
messages.push(msg);
|
|
44657
44708
|
}
|
|
@@ -44676,11 +44727,22 @@ function resolveJsonlSourcePath(src, input) {
|
|
|
44676
44727
|
const workspaceHint = typeof input.workspace === "string" && input.workspace.trim() ? input.workspace.trim() : "";
|
|
44677
44728
|
let sourcePath = null;
|
|
44678
44729
|
if (resolved.includes("*")) {
|
|
44679
|
-
|
|
44730
|
+
if (src.session_id_from === "dir_uuid" || src.workspace_from_sidecar) {
|
|
44731
|
+
sourcePath = pickDirUuidFileAcrossGlob(resolved, filePat, requestedSessionId);
|
|
44732
|
+
if (!sourcePath && !requestedSessionId) {
|
|
44733
|
+
if (src.workspace_from_sidecar && workspaceHint) {
|
|
44734
|
+
sourcePath = pickSidecarWorkspaceFileAcrossGlob(resolved, filePat, windowMs, sessionFloor, workspaceHint, src.workspace_from_sidecar);
|
|
44735
|
+
} else {
|
|
44736
|
+
sourcePath = newestRecentFileAcrossGlob(resolved, filePat, windowMs, sessionFloor);
|
|
44737
|
+
}
|
|
44738
|
+
}
|
|
44739
|
+
} else {
|
|
44740
|
+
sourcePath = pickExactSessionFileAcrossGlob(resolved, filePat, requestedSessionId) || pickSessionBoundFileAcrossGlob(resolved, filePat, windowMs, sessionFloor, workspaceHint) || newestRecentFileAcrossGlob(resolved, filePat, windowMs, sessionFloor);
|
|
44741
|
+
}
|
|
44680
44742
|
} else {
|
|
44681
44743
|
let stat2 = null;
|
|
44682
44744
|
try {
|
|
44683
|
-
stat2 =
|
|
44745
|
+
stat2 = fs18.statSync(resolved);
|
|
44684
44746
|
} catch {
|
|
44685
44747
|
}
|
|
44686
44748
|
if (stat2 && stat2.isFile()) {
|
|
@@ -44695,7 +44757,7 @@ function resolveJsonlSourcePath(src, input) {
|
|
|
44695
44757
|
const resolvedRaw = expandPath2(src.path, input, { skipWorkspaceRealpath: true });
|
|
44696
44758
|
if (resolvedRaw && resolvedRaw !== resolved) {
|
|
44697
44759
|
try {
|
|
44698
|
-
const rawStat =
|
|
44760
|
+
const rawStat = fs18.statSync(resolvedRaw);
|
|
44699
44761
|
if (rawStat.isFile()) sourcePath = resolvedRaw;
|
|
44700
44762
|
else if (rawStat.isDirectory()) {
|
|
44701
44763
|
sourcePath = pickExactSessionFile(resolvedRaw, filePat, requestedSessionId) || (requestedSessionId ? null : newestRecentFile(resolvedRaw, filePat, windowMs, sessionFloor));
|
|
@@ -44718,12 +44780,61 @@ function readSessionMetaWorkspace(lines) {
|
|
|
44718
44780
|
}
|
|
44719
44781
|
return void 0;
|
|
44720
44782
|
}
|
|
44783
|
+
function readSidecarWorkspace(sourcePath, cfg) {
|
|
44784
|
+
try {
|
|
44785
|
+
const sidecar = path24.resolve(path24.dirname(sourcePath), cfg.rel_path);
|
|
44786
|
+
const parsed = JSON.parse(fs18.readFileSync(sidecar, "utf8"));
|
|
44787
|
+
const v = jsonPathGet(parsed, cfg.workspace_path);
|
|
44788
|
+
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
44789
|
+
} catch {
|
|
44790
|
+
return void 0;
|
|
44791
|
+
}
|
|
44792
|
+
}
|
|
44793
|
+
function dirUuid(filePath) {
|
|
44794
|
+
const segs = path24.dirname(filePath).split(path24.sep);
|
|
44795
|
+
for (let i = segs.length - 1; i >= 0; i -= 1) {
|
|
44796
|
+
const m = segs[i].match(UUID_RE);
|
|
44797
|
+
if (m) return m[1];
|
|
44798
|
+
}
|
|
44799
|
+
return "";
|
|
44800
|
+
}
|
|
44801
|
+
function sameSessionUuid(a, b) {
|
|
44802
|
+
if (a === b) return true;
|
|
44803
|
+
const ua = a.match(UUID_RE)?.[1]?.toLowerCase();
|
|
44804
|
+
const ub = b.match(UUID_RE)?.[1]?.toLowerCase();
|
|
44805
|
+
return !!ua && !!ub && ua === ub;
|
|
44806
|
+
}
|
|
44807
|
+
function compileRecordShapes(src) {
|
|
44808
|
+
if (Array.isArray(src.records) && src.records.length > 0) {
|
|
44809
|
+
const compiled = src.records.map((r) => ({
|
|
44810
|
+
where: r.where ? compileWhere(r.where) : null,
|
|
44811
|
+
map: r.message_map
|
|
44812
|
+
}));
|
|
44813
|
+
return {
|
|
44814
|
+
pick: (record) => {
|
|
44815
|
+
for (const shape of compiled) {
|
|
44816
|
+
if (!shape.where || shape.where(record)) return { map: shape.map };
|
|
44817
|
+
}
|
|
44818
|
+
return null;
|
|
44819
|
+
}
|
|
44820
|
+
};
|
|
44821
|
+
}
|
|
44822
|
+
const filter = src.message_filter ? compileWhere(src.message_filter.where) : null;
|
|
44823
|
+
const map = src.message_map;
|
|
44824
|
+
return {
|
|
44825
|
+
pick: (record) => {
|
|
44826
|
+
if (!map) return null;
|
|
44827
|
+
if (filter && !filter(record)) return null;
|
|
44828
|
+
return { map };
|
|
44829
|
+
}
|
|
44830
|
+
};
|
|
44831
|
+
}
|
|
44721
44832
|
function workspaceFromInputIfSlugMatches(sourcePath, input) {
|
|
44722
44833
|
const wsRaw = typeof input.workspace === "string" ? input.workspace.trim() : "";
|
|
44723
44834
|
if (!wsRaw) return void 0;
|
|
44724
44835
|
let wsReal = wsRaw;
|
|
44725
44836
|
try {
|
|
44726
|
-
wsReal =
|
|
44837
|
+
wsReal = fs18.realpathSync(wsRaw);
|
|
44727
44838
|
} catch {
|
|
44728
44839
|
}
|
|
44729
44840
|
const slugs = /* @__PURE__ */ new Set();
|
|
@@ -44747,7 +44858,7 @@ function workspaceFromInputIfSlugMatches(sourcePath, input) {
|
|
|
44747
44858
|
function readJsonlLines(p) {
|
|
44748
44859
|
let text;
|
|
44749
44860
|
try {
|
|
44750
|
-
text =
|
|
44861
|
+
text = fs18.readFileSync(p, "utf8");
|
|
44751
44862
|
} catch {
|
|
44752
44863
|
return [];
|
|
44753
44864
|
}
|
|
@@ -44764,7 +44875,7 @@ function readJsonlLines(p) {
|
|
|
44764
44875
|
}
|
|
44765
44876
|
function executeSqlite(src, input) {
|
|
44766
44877
|
const resolved = expandPath2(src.path, input);
|
|
44767
|
-
if (!resolved || !
|
|
44878
|
+
if (!resolved || !fs18.existsSync(resolved)) return null;
|
|
44768
44879
|
let Database;
|
|
44769
44880
|
try {
|
|
44770
44881
|
Database = loadBetterSqlite3();
|
|
@@ -44903,7 +45014,7 @@ function expandPath2(template, input, opts) {
|
|
|
44903
45014
|
let workspaceResolved = workspaceRaw;
|
|
44904
45015
|
if (workspaceRaw && !opts?.skipWorkspaceRealpath) {
|
|
44905
45016
|
try {
|
|
44906
|
-
workspaceResolved =
|
|
45017
|
+
workspaceResolved = fs18.realpathSync(workspaceRaw);
|
|
44907
45018
|
} catch {
|
|
44908
45019
|
}
|
|
44909
45020
|
}
|
|
@@ -44942,7 +45053,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44942
45053
|
if (!base) return null;
|
|
44943
45054
|
let baseStat = null;
|
|
44944
45055
|
try {
|
|
44945
|
-
baseStat =
|
|
45056
|
+
baseStat = fs18.statSync(base);
|
|
44946
45057
|
} catch {
|
|
44947
45058
|
return null;
|
|
44948
45059
|
}
|
|
@@ -44950,7 +45061,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44950
45061
|
const needle = `${requestedSessionId.toLowerCase()}.jsonl`;
|
|
44951
45062
|
const dirsToScan = [base];
|
|
44952
45063
|
try {
|
|
44953
|
-
for (const entry of
|
|
45064
|
+
for (const entry of fs18.readdirSync(base, { withFileTypes: true })) {
|
|
44954
45065
|
if (entry.isDirectory()) dirsToScan.push(path24.join(base, entry.name));
|
|
44955
45066
|
}
|
|
44956
45067
|
} catch {
|
|
@@ -44958,7 +45069,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44958
45069
|
for (const dir of dirsToScan) {
|
|
44959
45070
|
let entries;
|
|
44960
45071
|
try {
|
|
44961
|
-
entries =
|
|
45072
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
44962
45073
|
} catch {
|
|
44963
45074
|
continue;
|
|
44964
45075
|
}
|
|
@@ -44993,7 +45104,7 @@ function expandDirGlob(template) {
|
|
|
44993
45104
|
for (const d of dirs) {
|
|
44994
45105
|
let entries;
|
|
44995
45106
|
try {
|
|
44996
|
-
entries =
|
|
45107
|
+
entries = fs18.readdirSync(d, { withFileTypes: true });
|
|
44997
45108
|
} catch {
|
|
44998
45109
|
continue;
|
|
44999
45110
|
}
|
|
@@ -45006,7 +45117,7 @@ function expandDirGlob(template) {
|
|
|
45006
45117
|
const candidate = path24.join(d, seg);
|
|
45007
45118
|
let stat2 = null;
|
|
45008
45119
|
try {
|
|
45009
|
-
stat2 =
|
|
45120
|
+
stat2 = fs18.statSync(candidate);
|
|
45010
45121
|
} catch {
|
|
45011
45122
|
continue;
|
|
45012
45123
|
}
|
|
@@ -45020,7 +45131,7 @@ function expandDirGlob(template) {
|
|
|
45020
45131
|
function walkAllDirs(root, out) {
|
|
45021
45132
|
let entries;
|
|
45022
45133
|
try {
|
|
45023
|
-
entries =
|
|
45134
|
+
entries = fs18.readdirSync(root, { withFileTypes: true });
|
|
45024
45135
|
} catch {
|
|
45025
45136
|
return;
|
|
45026
45137
|
}
|
|
@@ -45036,7 +45147,7 @@ function newestRecentFileAcrossGlob(template, pattern, windowMs, sessionFloorMs
|
|
|
45036
45147
|
for (const d of dirs) {
|
|
45037
45148
|
let entries;
|
|
45038
45149
|
try {
|
|
45039
|
-
entries =
|
|
45150
|
+
entries = fs18.readdirSync(d, { withFileTypes: true });
|
|
45040
45151
|
} catch {
|
|
45041
45152
|
continue;
|
|
45042
45153
|
}
|
|
@@ -45063,7 +45174,7 @@ function newestRecentFileAcrossDateWindow(template, input, pattern, windowMs, se
|
|
|
45063
45174
|
if (!resolved) continue;
|
|
45064
45175
|
let entries;
|
|
45065
45176
|
try {
|
|
45066
|
-
entries =
|
|
45177
|
+
entries = fs18.readdirSync(resolved, { withFileTypes: true });
|
|
45067
45178
|
} catch {
|
|
45068
45179
|
continue;
|
|
45069
45180
|
}
|
|
@@ -45092,7 +45203,7 @@ function expandPathForDate(template, input, day) {
|
|
|
45092
45203
|
let workspaceResolved = workspaceRaw;
|
|
45093
45204
|
if (workspaceRaw) {
|
|
45094
45205
|
try {
|
|
45095
|
-
workspaceResolved =
|
|
45206
|
+
workspaceResolved = fs18.realpathSync(workspaceRaw);
|
|
45096
45207
|
} catch {
|
|
45097
45208
|
}
|
|
45098
45209
|
}
|
|
@@ -45117,7 +45228,7 @@ function expandPathForDate(template, input, day) {
|
|
|
45117
45228
|
function newestRecentFile(dir, pattern, windowMs, sessionFloorMs = 0) {
|
|
45118
45229
|
let entries;
|
|
45119
45230
|
try {
|
|
45120
|
-
entries =
|
|
45231
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
45121
45232
|
} catch {
|
|
45122
45233
|
return null;
|
|
45123
45234
|
}
|
|
@@ -45134,7 +45245,7 @@ function newestRecentFile(dir, pattern, windowMs, sessionFloorMs = 0) {
|
|
|
45134
45245
|
}
|
|
45135
45246
|
function safeMtimeMs(p) {
|
|
45136
45247
|
try {
|
|
45137
|
-
return Math.floor(
|
|
45248
|
+
return Math.floor(fs18.statSync(p).mtimeMs);
|
|
45138
45249
|
} catch {
|
|
45139
45250
|
return 0;
|
|
45140
45251
|
}
|
|
@@ -45164,6 +45275,47 @@ function pickExactSessionFileAcrossGlob(template, pattern, requestedSessionId) {
|
|
|
45164
45275
|
matches.sort((a, b) => safeMtimeMs(b) - safeMtimeMs(a));
|
|
45165
45276
|
return matches[0] || null;
|
|
45166
45277
|
}
|
|
45278
|
+
function pickDirUuidFileAcrossGlob(template, pattern, requestedSessionId) {
|
|
45279
|
+
if (!requestedSessionId) return null;
|
|
45280
|
+
const wantUuid = requestedSessionId.match(UUID_RE)?.[1]?.toLowerCase();
|
|
45281
|
+
if (!wantUuid) return null;
|
|
45282
|
+
const dirs = expandDirGlob(template);
|
|
45283
|
+
const matches = [];
|
|
45284
|
+
for (const d of dirs) {
|
|
45285
|
+
for (const p of listMatchingFiles(d, pattern)) {
|
|
45286
|
+
if (dirUuid(p).toLowerCase() === wantUuid) matches.push(p);
|
|
45287
|
+
}
|
|
45288
|
+
}
|
|
45289
|
+
matches.sort((a, b) => safeMtimeMs(b) - safeMtimeMs(a));
|
|
45290
|
+
return matches[0] || null;
|
|
45291
|
+
}
|
|
45292
|
+
function pickSidecarWorkspaceFileAcrossGlob(template, pattern, windowMs, sessionFloorMs, workspaceHint, sidecar) {
|
|
45293
|
+
if (!sidecar || !workspaceHint) return null;
|
|
45294
|
+
let wsResolved = workspaceHint;
|
|
45295
|
+
try {
|
|
45296
|
+
wsResolved = fs18.realpathSync(workspaceHint);
|
|
45297
|
+
} catch {
|
|
45298
|
+
}
|
|
45299
|
+
const dirs = expandDirGlob(template);
|
|
45300
|
+
const cutoff = Math.max(Date.now() - windowMs, sessionFloorMs);
|
|
45301
|
+
let best = null;
|
|
45302
|
+
for (const d of dirs) {
|
|
45303
|
+
for (const p of listMatchingFiles(d, pattern)) {
|
|
45304
|
+
const mtime = safeMtimeMs(p);
|
|
45305
|
+
if (mtime < cutoff) continue;
|
|
45306
|
+
const ws = readSidecarWorkspace(p, sidecar);
|
|
45307
|
+
if (!ws) continue;
|
|
45308
|
+
let wsReal = ws;
|
|
45309
|
+
try {
|
|
45310
|
+
wsReal = fs18.realpathSync(ws);
|
|
45311
|
+
} catch {
|
|
45312
|
+
}
|
|
45313
|
+
if (ws !== workspaceHint && wsReal !== wsResolved) continue;
|
|
45314
|
+
if (!best || mtime > best.mtime) best = { p, mtime };
|
|
45315
|
+
}
|
|
45316
|
+
}
|
|
45317
|
+
return best ? best.p : null;
|
|
45318
|
+
}
|
|
45167
45319
|
function pickExactSessionFileAcrossDateWindow(template, input, pattern, requestedSessionId) {
|
|
45168
45320
|
if (!requestedSessionId) return null;
|
|
45169
45321
|
const matches = [];
|
|
@@ -45179,10 +45331,10 @@ function pickExactSessionFileAcrossDateWindow(template, input, pattern, requeste
|
|
|
45179
45331
|
}
|
|
45180
45332
|
function readCandidateSessionMeta(filePath) {
|
|
45181
45333
|
try {
|
|
45182
|
-
const fd =
|
|
45334
|
+
const fd = fs18.openSync(filePath, "r");
|
|
45183
45335
|
try {
|
|
45184
45336
|
const buf = Buffer.alloc(8192);
|
|
45185
|
-
const bytes =
|
|
45337
|
+
const bytes = fs18.readSync(fd, buf, 0, buf.length, 0);
|
|
45186
45338
|
if (bytes <= 0) return null;
|
|
45187
45339
|
const text = buf.subarray(0, bytes).toString("utf8");
|
|
45188
45340
|
const nl = text.indexOf("\n");
|
|
@@ -45200,7 +45352,7 @@ function readCandidateSessionMeta(filePath) {
|
|
|
45200
45352
|
sessionTimestampMs: Number.isFinite(tsMs) ? tsMs : void 0
|
|
45201
45353
|
};
|
|
45202
45354
|
} finally {
|
|
45203
|
-
|
|
45355
|
+
fs18.closeSync(fd);
|
|
45204
45356
|
}
|
|
45205
45357
|
} catch {
|
|
45206
45358
|
return null;
|
|
@@ -45210,7 +45362,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
45210
45362
|
if (!sessionFloorMs || !workspaceHint || candidatePaths.length === 0) return null;
|
|
45211
45363
|
let workspaceResolved = workspaceHint;
|
|
45212
45364
|
try {
|
|
45213
|
-
workspaceResolved =
|
|
45365
|
+
workspaceResolved = fs18.realpathSync(workspaceHint);
|
|
45214
45366
|
} catch {
|
|
45215
45367
|
}
|
|
45216
45368
|
let best = null;
|
|
@@ -45219,7 +45371,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
45219
45371
|
if (!meta || !meta.cwd || meta.sessionTimestampMs == null) continue;
|
|
45220
45372
|
let candidateCwd = meta.cwd;
|
|
45221
45373
|
try {
|
|
45222
|
-
candidateCwd =
|
|
45374
|
+
candidateCwd = fs18.realpathSync(meta.cwd);
|
|
45223
45375
|
} catch {
|
|
45224
45376
|
}
|
|
45225
45377
|
if (candidateCwd !== workspaceResolved && meta.cwd !== workspaceHint) continue;
|
|
@@ -45232,7 +45384,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
45232
45384
|
function listMatchingFiles(dir, pattern) {
|
|
45233
45385
|
let entries;
|
|
45234
45386
|
try {
|
|
45235
|
-
entries =
|
|
45387
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
45236
45388
|
} catch {
|
|
45237
45389
|
return [];
|
|
45238
45390
|
}
|
|
@@ -45526,7 +45678,7 @@ function evalTerm(t, record) {
|
|
|
45526
45678
|
}
|
|
45527
45679
|
|
|
45528
45680
|
// src/providers/spec/background-task-detector.ts
|
|
45529
|
-
var
|
|
45681
|
+
var fs19 = __toESM(require("fs"));
|
|
45530
45682
|
init_logger();
|
|
45531
45683
|
var EMPTY = { active: false, count: 0, ids: [] };
|
|
45532
45684
|
var TAIL_BYTES = 512 * 1024;
|
|
@@ -45588,19 +45740,19 @@ function detectFromRecords(records) {
|
|
|
45588
45740
|
return { active: true, count: unresolved.length, ids: unresolved };
|
|
45589
45741
|
}
|
|
45590
45742
|
function readTailJsonlLines(filePath, maxBytes) {
|
|
45591
|
-
const stat2 =
|
|
45743
|
+
const stat2 = fs19.statSync(filePath);
|
|
45592
45744
|
const size = stat2.size;
|
|
45593
45745
|
const start = size > maxBytes ? size - maxBytes : 0;
|
|
45594
45746
|
const length = size - start;
|
|
45595
45747
|
if (length <= 0) return [];
|
|
45596
|
-
const fd =
|
|
45748
|
+
const fd = fs19.openSync(filePath, "r");
|
|
45597
45749
|
let text;
|
|
45598
45750
|
try {
|
|
45599
45751
|
const buf = Buffer.alloc(length);
|
|
45600
|
-
const bytes =
|
|
45752
|
+
const bytes = fs19.readSync(fd, buf, 0, length, start);
|
|
45601
45753
|
text = buf.subarray(0, bytes).toString("utf8");
|
|
45602
45754
|
} finally {
|
|
45603
|
-
|
|
45755
|
+
fs19.closeSync(fd);
|
|
45604
45756
|
}
|
|
45605
45757
|
const rawLines = text.split("\n");
|
|
45606
45758
|
if (start > 0 && rawLines.length > 0) rawLines.shift();
|
|
@@ -45617,13 +45769,13 @@ function readTailJsonlLines(filePath, maxBytes) {
|
|
|
45617
45769
|
}
|
|
45618
45770
|
|
|
45619
45771
|
// src/providers/spec/cli-adapter.ts
|
|
45620
|
-
var
|
|
45772
|
+
var fs20 = __toESM(require("fs"));
|
|
45621
45773
|
init_logger();
|
|
45622
45774
|
function stripAnsi3(text) {
|
|
45623
45775
|
return String(text || "").replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
45624
45776
|
}
|
|
45625
45777
|
function delay(ms) {
|
|
45626
|
-
return new Promise((
|
|
45778
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
45627
45779
|
}
|
|
45628
45780
|
var SpecCliAdapter = class _SpecCliAdapter {
|
|
45629
45781
|
cliType;
|
|
@@ -45687,7 +45839,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
45687
45839
|
* hermes ships a runtime MCP override. */
|
|
45688
45840
|
spawnedEnv = {};
|
|
45689
45841
|
constructor(specPath, workingDir, cliArgs, extraEnv, transportFactory) {
|
|
45690
|
-
const raw = JSON.parse(
|
|
45842
|
+
const raw = JSON.parse(fs20.readFileSync(specPath, "utf8"));
|
|
45691
45843
|
this.spec = {
|
|
45692
45844
|
id: raw.id,
|
|
45693
45845
|
name: raw.name,
|
|
@@ -45839,7 +45991,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
45839
45991
|
const steps = buildClaudeInteractiveTuiAnswerSteps(prompt, response);
|
|
45840
45992
|
for (const step of steps) {
|
|
45841
45993
|
this.driver.dispatch({ kind: "pty_write", data: step });
|
|
45842
|
-
await new Promise((
|
|
45994
|
+
await new Promise((resolve26) => setTimeout(resolve26, 180));
|
|
45843
45995
|
}
|
|
45844
45996
|
} else {
|
|
45845
45997
|
this.driver.dispatch({ kind: "pty_write", data: `${buildClaudeInteractiveToolResult(response)}
|
|
@@ -46395,7 +46547,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
46395
46547
|
let screenText = this.driver.snapshot();
|
|
46396
46548
|
const deadline = Date.now() + _SpecCliAdapter.CLAUDE_TUI_PAGE_SETTLE_TIMEOUT_MS;
|
|
46397
46549
|
while (!detectClaudeTuiMultiSelect(screenText) && Date.now() < deadline) {
|
|
46398
|
-
await new Promise((
|
|
46550
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
46399
46551
|
screenText = this.driver.snapshot();
|
|
46400
46552
|
}
|
|
46401
46553
|
return screenText;
|
|
@@ -46404,12 +46556,12 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
46404
46556
|
const pages = [{ screenText: firstScreen, header: headers[0] }];
|
|
46405
46557
|
for (let index = 1; index < headers.length; index += 1) {
|
|
46406
46558
|
this.driver.dispatch({ kind: "pty_write", data: " " });
|
|
46407
|
-
await new Promise((
|
|
46559
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
46408
46560
|
pages.push({ screenText: await this.snapshotSettledClaudeTuiPage(), header: headers[index] });
|
|
46409
46561
|
}
|
|
46410
46562
|
for (let index = headers.length - 1; index > 0; index -= 1) {
|
|
46411
46563
|
this.driver.dispatch({ kind: "pty_write", data: "\x1B[Z" });
|
|
46412
|
-
await new Promise((
|
|
46564
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
46413
46565
|
const reread = await this.snapshotSettledClaudeTuiPage();
|
|
46414
46566
|
const landed = pages[index - 1];
|
|
46415
46567
|
if (landed && !detectClaudeTuiMultiSelect(landed.screenText) && detectClaudeTuiMultiSelect(reread)) {
|
|
@@ -46509,10 +46661,10 @@ init_logger();
|
|
|
46509
46661
|
function createCliAdapter(provider, workingDir, cliArgs, extraEnv, transportFactory) {
|
|
46510
46662
|
const resolvedSpecPath = provider._resolvedSpecPath;
|
|
46511
46663
|
const dir = provider._resolvedProviderDir;
|
|
46512
|
-
let specPath = resolvedSpecPath &&
|
|
46664
|
+
let specPath = resolvedSpecPath && fs21.existsSync(resolvedSpecPath) ? resolvedSpecPath : void 0;
|
|
46513
46665
|
if (!specPath && dir) {
|
|
46514
46666
|
const legacy = path25.join(dir, "spec.json");
|
|
46515
|
-
if (
|
|
46667
|
+
if (fs21.existsSync(legacy)) specPath = legacy;
|
|
46516
46668
|
}
|
|
46517
46669
|
if (specPath) {
|
|
46518
46670
|
try {
|
|
@@ -46597,7 +46749,7 @@ init_working_dir();
|
|
|
46597
46749
|
var os20 = __toESM(require("os"));
|
|
46598
46750
|
var path26 = __toESM(require("path"));
|
|
46599
46751
|
var crypto4 = __toESM(require("crypto"));
|
|
46600
|
-
var
|
|
46752
|
+
var fs22 = __toESM(require("fs"));
|
|
46601
46753
|
var IMAGE_MIME_EXTENSIONS = {
|
|
46602
46754
|
"image/png": ".png",
|
|
46603
46755
|
"image/jpeg": ".jpg",
|
|
@@ -46632,9 +46784,9 @@ function materializeImageDataPart(part, index, dir) {
|
|
|
46632
46784
|
if (!part.data) return null;
|
|
46633
46785
|
const rawData = part.data.includes(",") ? part.data.split(",").pop() || "" : part.data;
|
|
46634
46786
|
if (!rawData) return null;
|
|
46635
|
-
|
|
46787
|
+
fs22.mkdirSync(dir, { recursive: true });
|
|
46636
46788
|
const filePath = path26.join(dir, safeInputImageBasename(index, part.mimeType));
|
|
46637
|
-
|
|
46789
|
+
fs22.writeFileSync(filePath, Buffer.from(rawData, "base64"));
|
|
46638
46790
|
cleanupStaleMaterializedImages(dir);
|
|
46639
46791
|
return filePath;
|
|
46640
46792
|
}
|
|
@@ -46646,14 +46798,14 @@ function cleanupStaleMaterializedImages(dir) {
|
|
|
46646
46798
|
if (now - lastMaterializedImageCleanupAt < MATERIALIZED_IMAGE_CLEANUP_INTERVAL_MS) return;
|
|
46647
46799
|
lastMaterializedImageCleanupAt = now;
|
|
46648
46800
|
try {
|
|
46649
|
-
const entries =
|
|
46801
|
+
const entries = fs22.readdirSync(dir);
|
|
46650
46802
|
for (const entry of entries) {
|
|
46651
46803
|
if (!entry.startsWith("adhdev-input-image-")) continue;
|
|
46652
46804
|
const fullPath = path26.join(dir, entry);
|
|
46653
46805
|
try {
|
|
46654
|
-
const stat2 =
|
|
46806
|
+
const stat2 = fs22.statSync(fullPath);
|
|
46655
46807
|
if (now - stat2.mtimeMs > MATERIALIZED_IMAGE_MAX_AGE_MS) {
|
|
46656
|
-
|
|
46808
|
+
fs22.unlinkSync(fullPath);
|
|
46657
46809
|
}
|
|
46658
46810
|
} catch {
|
|
46659
46811
|
}
|
|
@@ -46800,7 +46952,7 @@ async function waitForCliAdapterReady(adapter, options) {
|
|
|
46800
46952
|
if (status === "stopped") {
|
|
46801
46953
|
throw new Error("CLI runtime stopped before it became ready");
|
|
46802
46954
|
}
|
|
46803
|
-
await new Promise((
|
|
46955
|
+
await new Promise((resolve26) => setTimeout(resolve26, pollMs));
|
|
46804
46956
|
}
|
|
46805
46957
|
throw new Error(`CLI runtime did not become ready within ${timeoutMs}ms`);
|
|
46806
46958
|
}
|
|
@@ -47314,7 +47466,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47314
47466
|
const resolvedDbPath = probe.dbPath.replace(/^~/, os21.homedir());
|
|
47315
47467
|
const now = Date.now();
|
|
47316
47468
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
47317
|
-
if (!
|
|
47469
|
+
if (!fs23.existsSync(resolvedDbPath)) {
|
|
47318
47470
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
47319
47471
|
return null;
|
|
47320
47472
|
}
|
|
@@ -47898,7 +48050,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47898
48050
|
const enterCount = cliCommand.enterCount || 1;
|
|
47899
48051
|
await this.adapter.writeRaw(cliCommand.text + "\r");
|
|
47900
48052
|
for (let i = 1; i < enterCount; i += 1) {
|
|
47901
|
-
await new Promise((
|
|
48053
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
47902
48054
|
await this.adapter.writeRaw("\r");
|
|
47903
48055
|
}
|
|
47904
48056
|
}
|
|
@@ -47992,7 +48144,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47992
48144
|
}
|
|
47993
48145
|
if (this.lastExternalCompletionProbe?.sourcePath) {
|
|
47994
48146
|
try {
|
|
47995
|
-
|
|
48147
|
+
fs23.statSync(this.lastExternalCompletionProbe.sourcePath);
|
|
47996
48148
|
} catch {
|
|
47997
48149
|
}
|
|
47998
48150
|
}
|
|
@@ -49688,7 +49840,7 @@ ${buttons.join("\n")}`;
|
|
|
49688
49840
|
};
|
|
49689
49841
|
addDir(this.workingDir);
|
|
49690
49842
|
try {
|
|
49691
|
-
addDir(
|
|
49843
|
+
addDir(fs23.realpathSync.native(this.workingDir));
|
|
49692
49844
|
} catch {
|
|
49693
49845
|
}
|
|
49694
49846
|
return Array.from(dirs);
|
|
@@ -50358,13 +50510,13 @@ var AcpProviderInstance = class {
|
|
|
50358
50510
|
}
|
|
50359
50511
|
this.currentStatus = "waiting_approval";
|
|
50360
50512
|
this.detectStatusTransition();
|
|
50361
|
-
const approved = await new Promise((
|
|
50362
|
-
this.permissionResolvers.push(
|
|
50513
|
+
const approved = await new Promise((resolve26) => {
|
|
50514
|
+
this.permissionResolvers.push(resolve26);
|
|
50363
50515
|
setTimeout(() => {
|
|
50364
|
-
const idx = this.permissionResolvers.indexOf(
|
|
50516
|
+
const idx = this.permissionResolvers.indexOf(resolve26);
|
|
50365
50517
|
if (idx >= 0) {
|
|
50366
50518
|
this.permissionResolvers.splice(idx, 1);
|
|
50367
|
-
|
|
50519
|
+
resolve26(false);
|
|
50368
50520
|
}
|
|
50369
50521
|
}, 3e5);
|
|
50370
50522
|
});
|
|
@@ -51100,7 +51252,7 @@ async function waitForZeroMessageStartingLaunch(adapter) {
|
|
|
51100
51252
|
} catch {
|
|
51101
51253
|
return false;
|
|
51102
51254
|
}
|
|
51103
|
-
await new Promise((
|
|
51255
|
+
await new Promise((resolve26) => setTimeout(resolve26, ZERO_MESSAGE_STARTING_SEND_WAIT_MS));
|
|
51104
51256
|
try {
|
|
51105
51257
|
return hasZeroMessageStartingLaunch(adapter);
|
|
51106
51258
|
} catch {
|
|
@@ -52415,7 +52567,7 @@ var os27 = __toESM(require("os"));
|
|
|
52415
52567
|
var path37 = __toESM(require("path"));
|
|
52416
52568
|
|
|
52417
52569
|
// src/providers/provider-loader.ts
|
|
52418
|
-
var
|
|
52570
|
+
var fs29 = __toESM(require("fs"));
|
|
52419
52571
|
var path36 = __toESM(require("path"));
|
|
52420
52572
|
var os26 = __toESM(require("os"));
|
|
52421
52573
|
var chokidar = __toESM(require("chokidar"));
|
|
@@ -52815,12 +52967,12 @@ function validateControl(control, errors) {
|
|
|
52815
52967
|
init_external_sources();
|
|
52816
52968
|
|
|
52817
52969
|
// src/providers/native-history/dispatcher.ts
|
|
52818
|
-
var
|
|
52970
|
+
var fs28 = __toESM(require("fs"));
|
|
52819
52971
|
var os25 = __toESM(require("os"));
|
|
52820
52972
|
var path34 = __toESM(require("path"));
|
|
52821
52973
|
|
|
52822
52974
|
// src/providers/native-history/claude-cli-transcript.ts
|
|
52823
|
-
var
|
|
52975
|
+
var fs24 = __toESM(require("fs"));
|
|
52824
52976
|
var path30 = __toESM(require("path"));
|
|
52825
52977
|
function extractTimestampValue(value) {
|
|
52826
52978
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
@@ -52834,7 +52986,7 @@ function extractTimestampValue(value) {
|
|
|
52834
52986
|
}
|
|
52835
52987
|
function statMtimeMs(filePath) {
|
|
52836
52988
|
try {
|
|
52837
|
-
return
|
|
52989
|
+
return fs24.statSync(filePath).mtimeMs;
|
|
52838
52990
|
} catch {
|
|
52839
52991
|
return 0;
|
|
52840
52992
|
}
|
|
@@ -52904,7 +53056,7 @@ function extractUserContentParts(content) {
|
|
|
52904
53056
|
function parseTranscriptFile(filePath, sessionId, workspaceFallback) {
|
|
52905
53057
|
let raw;
|
|
52906
53058
|
try {
|
|
52907
|
-
raw =
|
|
53059
|
+
raw = fs24.readFileSync(filePath, "utf-8");
|
|
52908
53060
|
} catch {
|
|
52909
53061
|
return [];
|
|
52910
53062
|
}
|
|
@@ -52980,7 +53132,7 @@ function readSession(sessionPath) {
|
|
|
52980
53132
|
if (!sessionPath || !path30.isAbsolute(sessionPath)) return null;
|
|
52981
53133
|
const basename14 = path30.basename(sessionPath, ".jsonl");
|
|
52982
53134
|
if (!isSafeSessionId(basename14)) return null;
|
|
52983
|
-
if (!
|
|
53135
|
+
if (!fs24.existsSync(sessionPath)) return null;
|
|
52984
53136
|
const sourceMtimeMs = statMtimeMs(sessionPath);
|
|
52985
53137
|
const messages = parseTranscriptFile(sessionPath, basename14);
|
|
52986
53138
|
if (messages.length === 0) return null;
|
|
@@ -52998,7 +53150,7 @@ function readSession(sessionPath) {
|
|
|
52998
53150
|
}
|
|
52999
53151
|
|
|
53000
53152
|
// src/providers/native-history/codex-cli-transcript.ts
|
|
53001
|
-
var
|
|
53153
|
+
var fs25 = __toESM(require("fs"));
|
|
53002
53154
|
var path31 = __toESM(require("path"));
|
|
53003
53155
|
function extractTimestampValue2(value) {
|
|
53004
53156
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
@@ -53012,7 +53164,7 @@ function extractTimestampValue2(value) {
|
|
|
53012
53164
|
}
|
|
53013
53165
|
function statMtimeMs2(filePath) {
|
|
53014
53166
|
try {
|
|
53015
|
-
return
|
|
53167
|
+
return fs25.statSync(filePath).mtimeMs;
|
|
53016
53168
|
} catch {
|
|
53017
53169
|
return 0;
|
|
53018
53170
|
}
|
|
@@ -53109,7 +53261,7 @@ function pushAssistantStandardMessage(records, sessionId, receivedAt, content, w
|
|
|
53109
53261
|
}
|
|
53110
53262
|
function readSessionMeta(filePath) {
|
|
53111
53263
|
try {
|
|
53112
|
-
const firstLine =
|
|
53264
|
+
const firstLine = fs25.readFileSync(filePath, "utf-8").split("\n").find(Boolean);
|
|
53113
53265
|
if (!firstLine) return null;
|
|
53114
53266
|
const parsed = JSON.parse(firstLine);
|
|
53115
53267
|
if (String(parsed.type ?? "") !== "session_meta") return null;
|
|
@@ -53121,7 +53273,7 @@ function readSessionMeta(filePath) {
|
|
|
53121
53273
|
function parseSessionFile(filePath, sessionId, workspaceFallback) {
|
|
53122
53274
|
let raw;
|
|
53123
53275
|
try {
|
|
53124
|
-
raw =
|
|
53276
|
+
raw = fs25.readFileSync(filePath, "utf-8");
|
|
53125
53277
|
} catch {
|
|
53126
53278
|
return [];
|
|
53127
53279
|
}
|
|
@@ -53237,7 +53389,7 @@ function parseSessionFile(filePath, sessionId, workspaceFallback) {
|
|
|
53237
53389
|
}
|
|
53238
53390
|
function readSession2(sessionPath) {
|
|
53239
53391
|
if (!sessionPath || !path31.isAbsolute(sessionPath)) return null;
|
|
53240
|
-
if (!
|
|
53392
|
+
if (!fs25.existsSync(sessionPath)) return null;
|
|
53241
53393
|
const meta = readSessionMeta(sessionPath);
|
|
53242
53394
|
const metaId = String(meta?.id ?? "").trim();
|
|
53243
53395
|
const basename14 = path31.basename(sessionPath, ".jsonl");
|
|
@@ -53264,7 +53416,7 @@ function readSession2(sessionPath) {
|
|
|
53264
53416
|
}
|
|
53265
53417
|
|
|
53266
53418
|
// src/providers/native-history/antigravity-cli-transcript.ts
|
|
53267
|
-
var
|
|
53419
|
+
var fs26 = __toESM(require("fs"));
|
|
53268
53420
|
var path32 = __toESM(require("path"));
|
|
53269
53421
|
var os23 = __toESM(require("os"));
|
|
53270
53422
|
init_load_better_sqlite3();
|
|
@@ -53281,7 +53433,7 @@ function extractTimestampValue3(value) {
|
|
|
53281
53433
|
}
|
|
53282
53434
|
function statMtimeMs3(filePath) {
|
|
53283
53435
|
try {
|
|
53284
|
-
return
|
|
53436
|
+
return fs26.statSync(filePath).mtimeMs;
|
|
53285
53437
|
} catch {
|
|
53286
53438
|
return 0;
|
|
53287
53439
|
}
|
|
@@ -53310,12 +53462,12 @@ function resolvePathInside(root, ...segments) {
|
|
|
53310
53462
|
function findBrainTranscriptPath(sessionId) {
|
|
53311
53463
|
if (!isUuidLike(sessionId)) return null;
|
|
53312
53464
|
const logsRoot = resolvePathInside(brainRoot(), sessionId, ".system_generated", "logs");
|
|
53313
|
-
if (!logsRoot || !
|
|
53314
|
-
const candidates = ["transcript_full.jsonl", "transcript.jsonl"].map((file) => resolvePathInside(logsRoot, file)).filter((p) => p !== null &&
|
|
53465
|
+
if (!logsRoot || !fs26.existsSync(logsRoot)) return null;
|
|
53466
|
+
const candidates = ["transcript_full.jsonl", "transcript.jsonl"].map((file) => resolvePathInside(logsRoot, file)).filter((p) => p !== null && fs26.existsSync(p));
|
|
53315
53467
|
if (candidates.length === 0) {
|
|
53316
53468
|
let entries = [];
|
|
53317
53469
|
try {
|
|
53318
|
-
entries =
|
|
53470
|
+
entries = fs26.readdirSync(logsRoot, { withFileTypes: true });
|
|
53319
53471
|
} catch {
|
|
53320
53472
|
return null;
|
|
53321
53473
|
}
|
|
@@ -53341,7 +53493,7 @@ function antigravityRowKind(rowType) {
|
|
|
53341
53493
|
function parseBrainTranscript(filePath, sessionId, workspace) {
|
|
53342
53494
|
let raw;
|
|
53343
53495
|
try {
|
|
53344
|
-
raw =
|
|
53496
|
+
raw = fs26.readFileSync(filePath, "utf-8");
|
|
53345
53497
|
} catch {
|
|
53346
53498
|
return null;
|
|
53347
53499
|
}
|
|
@@ -53401,7 +53553,7 @@ function readHistoryRows() {
|
|
|
53401
53553
|
const sourcePath = historyJsonlPath();
|
|
53402
53554
|
let lines = [];
|
|
53403
53555
|
try {
|
|
53404
|
-
lines =
|
|
53556
|
+
lines = fs26.readFileSync(sourcePath, "utf-8").split("\n").filter(Boolean);
|
|
53405
53557
|
} catch {
|
|
53406
53558
|
return [];
|
|
53407
53559
|
}
|
|
@@ -53449,7 +53601,7 @@ function extractStringsFromBuffer(buf) {
|
|
|
53449
53601
|
function parsePbFile(filePath, sessionId) {
|
|
53450
53602
|
let buf;
|
|
53451
53603
|
try {
|
|
53452
|
-
buf =
|
|
53604
|
+
buf = fs26.readFileSync(filePath);
|
|
53453
53605
|
} catch {
|
|
53454
53606
|
return null;
|
|
53455
53607
|
}
|
|
@@ -53797,7 +53949,7 @@ function readAntigravitySiblingFallback(sessionId, workspace) {
|
|
|
53797
53949
|
}
|
|
53798
53950
|
}
|
|
53799
53951
|
const pbPath = resolvePathInside(conversationsRoot(), `${sessionId}.pb`);
|
|
53800
|
-
if (pbPath &&
|
|
53952
|
+
if (pbPath && fs26.existsSync(pbPath)) {
|
|
53801
53953
|
const pbMessages = parsePbFile(pbPath, sessionId);
|
|
53802
53954
|
if (pbMessages && pbMessages.length > 0) {
|
|
53803
53955
|
return {
|
|
@@ -53816,7 +53968,7 @@ function readAntigravitySiblingFallback(sessionId, workspace) {
|
|
|
53816
53968
|
}
|
|
53817
53969
|
function readSession3(sessionPath, sessionId, workspace) {
|
|
53818
53970
|
if (!sessionPath || !path32.isAbsolute(sessionPath)) return null;
|
|
53819
|
-
if (!
|
|
53971
|
+
if (!fs26.existsSync(sessionPath)) return null;
|
|
53820
53972
|
const sourceMtimeMs = statMtimeMs3(sessionPath);
|
|
53821
53973
|
const brainRootPath = brainRoot();
|
|
53822
53974
|
if (sessionPath.startsWith(brainRootPath + path32.sep) && sessionPath.endsWith(".jsonl")) {
|
|
@@ -53877,7 +54029,7 @@ function readSession3(sessionPath, sessionId, workspace) {
|
|
|
53877
54029
|
}
|
|
53878
54030
|
|
|
53879
54031
|
// src/providers/native-history/hermes-cli-transcript.ts
|
|
53880
|
-
var
|
|
54032
|
+
var fs27 = __toESM(require("fs"));
|
|
53881
54033
|
var path33 = __toESM(require("path"));
|
|
53882
54034
|
var os24 = __toESM(require("os"));
|
|
53883
54035
|
init_load_better_sqlite3();
|
|
@@ -53885,13 +54037,13 @@ var HERMES_STATE_DB = path33.join(os24.homedir(), ".hermes", "state.db");
|
|
|
53885
54037
|
var HERMES_LEGACY_SESSIONS_DIR = path33.join(os24.homedir(), ".hermes", "sessions");
|
|
53886
54038
|
function statMtimeMs4(p) {
|
|
53887
54039
|
try {
|
|
53888
|
-
return Math.floor(
|
|
54040
|
+
return Math.floor(fs27.statSync(p).mtimeMs);
|
|
53889
54041
|
} catch {
|
|
53890
54042
|
return 0;
|
|
53891
54043
|
}
|
|
53892
54044
|
}
|
|
53893
54045
|
function openDb() {
|
|
53894
|
-
if (!
|
|
54046
|
+
if (!fs27.existsSync(HERMES_STATE_DB)) return null;
|
|
53895
54047
|
try {
|
|
53896
54048
|
const Database = loadBetterSqlite3();
|
|
53897
54049
|
return new Database(HERMES_STATE_DB, { readonly: true, fileMustExist: true });
|
|
@@ -53987,10 +54139,10 @@ function readSession4(sessionPath, requestedSessionId) {
|
|
|
53987
54139
|
}
|
|
53988
54140
|
}
|
|
53989
54141
|
}
|
|
53990
|
-
if (!path33.isAbsolute(sessionPath) || !
|
|
54142
|
+
if (!path33.isAbsolute(sessionPath) || !fs27.existsSync(sessionPath)) return null;
|
|
53991
54143
|
let raw;
|
|
53992
54144
|
try {
|
|
53993
|
-
raw = JSON.parse(
|
|
54145
|
+
raw = JSON.parse(fs27.readFileSync(sessionPath, "utf8"));
|
|
53994
54146
|
} catch {
|
|
53995
54147
|
return null;
|
|
53996
54148
|
}
|
|
@@ -54045,7 +54197,7 @@ function createNativeHistoryDispatcher(reader) {
|
|
|
54045
54197
|
const ownerConfirmed = reader === "antigravity-cli" ? resolved?.ownerConfirmed === true : void 0;
|
|
54046
54198
|
if (input.forceRefresh === true || input.args?.forceRefresh === true) {
|
|
54047
54199
|
try {
|
|
54048
|
-
|
|
54200
|
+
fs28.statSync(sourcePath);
|
|
54049
54201
|
} catch {
|
|
54050
54202
|
}
|
|
54051
54203
|
}
|
|
@@ -54097,10 +54249,10 @@ function resolveSourcePath(reader, workspace, sessionId, sessionStartedAtMs, ins
|
|
|
54097
54249
|
}
|
|
54098
54250
|
function resolveClaudePath(workspace, sessionId) {
|
|
54099
54251
|
const dir = path34.join(os25.homedir(), ".claude", "projects", cwdAsDashes(workspace));
|
|
54100
|
-
if (!
|
|
54252
|
+
if (!fs28.existsSync(dir)) return null;
|
|
54101
54253
|
if (sessionId) {
|
|
54102
54254
|
const candidate = path34.join(dir, `${sessionId}.jsonl`);
|
|
54103
|
-
if (
|
|
54255
|
+
if (fs28.existsSync(candidate)) return candidate;
|
|
54104
54256
|
}
|
|
54105
54257
|
return null;
|
|
54106
54258
|
}
|
|
@@ -54112,7 +54264,7 @@ function resolveCodexPath(workspace, sessionId, sessionStartedAtMs) {
|
|
|
54112
54264
|
return findCodexPathByRuntime(root, workspace, sessionStartedAtMs);
|
|
54113
54265
|
}
|
|
54114
54266
|
function findCodexPathBySessionId(root, sessionId) {
|
|
54115
|
-
if (!
|
|
54267
|
+
if (!fs28.existsSync(root)) return null;
|
|
54116
54268
|
const needle = sessionId.toLowerCase();
|
|
54117
54269
|
const matches = [];
|
|
54118
54270
|
const stack = [root];
|
|
@@ -54120,7 +54272,7 @@ function findCodexPathBySessionId(root, sessionId) {
|
|
|
54120
54272
|
const current = stack.pop();
|
|
54121
54273
|
let entries = [];
|
|
54122
54274
|
try {
|
|
54123
|
-
entries =
|
|
54275
|
+
entries = fs28.readdirSync(current, { withFileTypes: true });
|
|
54124
54276
|
} catch {
|
|
54125
54277
|
continue;
|
|
54126
54278
|
}
|
|
@@ -54140,7 +54292,7 @@ function findCodexPathBySessionId(root, sessionId) {
|
|
|
54140
54292
|
return matches[0]?.p ?? null;
|
|
54141
54293
|
}
|
|
54142
54294
|
function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
54143
|
-
if (!
|
|
54295
|
+
if (!fs28.existsSync(root) || !workspace) return null;
|
|
54144
54296
|
const workspaceResolved = resolveRealPath(workspace);
|
|
54145
54297
|
const cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
54146
54298
|
const matches = [];
|
|
@@ -54149,7 +54301,7 @@ function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
|
54149
54301
|
const current = stack.pop();
|
|
54150
54302
|
let entries = [];
|
|
54151
54303
|
try {
|
|
54152
|
-
entries =
|
|
54304
|
+
entries = fs28.readdirSync(current, { withFileTypes: true });
|
|
54153
54305
|
} catch {
|
|
54154
54306
|
continue;
|
|
54155
54307
|
}
|
|
@@ -54174,10 +54326,10 @@ function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
|
54174
54326
|
}
|
|
54175
54327
|
function readCodexSessionMeta(filePath) {
|
|
54176
54328
|
try {
|
|
54177
|
-
const fd =
|
|
54329
|
+
const fd = fs28.openSync(filePath, "r");
|
|
54178
54330
|
try {
|
|
54179
54331
|
const buffer = Buffer.alloc(8192);
|
|
54180
|
-
const bytes =
|
|
54332
|
+
const bytes = fs28.readSync(fd, buffer, 0, buffer.length, 0);
|
|
54181
54333
|
if (bytes <= 0) return null;
|
|
54182
54334
|
const text = buffer.subarray(0, bytes).toString("utf8");
|
|
54183
54335
|
const firstLine = text.slice(0, text.indexOf("\n") >= 0 ? text.indexOf("\n") : text.length).trim();
|
|
@@ -54192,7 +54344,7 @@ function readCodexSessionMeta(filePath) {
|
|
|
54192
54344
|
timestampMs: Number.isFinite(timestampMs) ? timestampMs : void 0
|
|
54193
54345
|
};
|
|
54194
54346
|
} finally {
|
|
54195
|
-
|
|
54347
|
+
fs28.closeSync(fd);
|
|
54196
54348
|
}
|
|
54197
54349
|
} catch {
|
|
54198
54350
|
return null;
|
|
@@ -54200,7 +54352,7 @@ function readCodexSessionMeta(filePath) {
|
|
|
54200
54352
|
}
|
|
54201
54353
|
function resolveRealPath(value) {
|
|
54202
54354
|
try {
|
|
54203
|
-
return
|
|
54355
|
+
return fs28.realpathSync(value);
|
|
54204
54356
|
} catch {
|
|
54205
54357
|
return value;
|
|
54206
54358
|
}
|
|
@@ -54222,19 +54374,19 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
|
|
|
54222
54374
|
const owner = antigravityOwnerToken(workspace, sessionStartedAtMs, instanceId);
|
|
54223
54375
|
if (sessionId && isUuidLikeSessionId2(sessionId)) {
|
|
54224
54376
|
const dbPath = path34.join(agyRoot, "conversations", `${sessionId}.db`);
|
|
54225
|
-
if (
|
|
54377
|
+
if (fs28.existsSync(dbPath)) {
|
|
54226
54378
|
if (owner) claimAntigravityConversation(sessionId, owner);
|
|
54227
54379
|
return { path: dbPath, ownerConfirmed: true };
|
|
54228
54380
|
}
|
|
54229
54381
|
}
|
|
54230
54382
|
const brainRoot2 = path34.join(agyRoot, "brain");
|
|
54231
|
-
if (
|
|
54383
|
+
if (fs28.existsSync(brainRoot2)) {
|
|
54232
54384
|
const cutoff = spawnAwareCutoff(sessionStartedAtMs);
|
|
54233
54385
|
const nonEmptyBrain = (uuid, p) => {
|
|
54234
54386
|
const t = path34.join(p, ".system_generated", "logs", "transcript.jsonl");
|
|
54235
|
-
return
|
|
54387
|
+
return fs28.existsSync(t) && safeSize(t) > 0 ? t : null;
|
|
54236
54388
|
};
|
|
54237
|
-
const all =
|
|
54389
|
+
const all = fs28.readdirSync(brainRoot2, { withFileTypes: true }).filter((e) => e.isDirectory() && isUuidLikeSessionId2(e.name)).filter((e) => !isAntigravityConversationClaimedByOther(e.name, owner)).map((e) => {
|
|
54238
54390
|
const p = path34.join(brainRoot2, e.name);
|
|
54239
54391
|
return { uuid: e.name, p, mtime: safeMtime(p), birth: safeBirthtime(p) };
|
|
54240
54392
|
}).filter((e) => e.mtime >= cutoff);
|
|
@@ -54265,7 +54417,7 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
|
|
|
54265
54417
|
function pickUnboundConversationDb(convRoot, sessionFloorMs, owner) {
|
|
54266
54418
|
let entries = [];
|
|
54267
54419
|
try {
|
|
54268
|
-
entries =
|
|
54420
|
+
entries = fs28.readdirSync(convRoot, { withFileTypes: true });
|
|
54269
54421
|
} catch {
|
|
54270
54422
|
return null;
|
|
54271
54423
|
}
|
|
@@ -54303,9 +54455,9 @@ function resolveHermesPath(workspace, sessionId) {
|
|
|
54303
54455
|
void workspace;
|
|
54304
54456
|
void sessionId;
|
|
54305
54457
|
const dbPath = path34.join(os25.homedir(), ".hermes", "state.db");
|
|
54306
|
-
if (
|
|
54458
|
+
if (fs28.existsSync(dbPath)) return dbPath;
|
|
54307
54459
|
const dir = path34.join(os25.homedir(), ".hermes", "sessions");
|
|
54308
|
-
if (!
|
|
54460
|
+
if (!fs28.existsSync(dir)) return null;
|
|
54309
54461
|
return newestRecentFile2(dir, /^session_.*\.json$/);
|
|
54310
54462
|
}
|
|
54311
54463
|
function readByReader(reader, sourcePath, sessionId, workspace, requestedProviderSid) {
|
|
@@ -54342,7 +54494,7 @@ var RECENT_WINDOW_MS = 5 * 60 * 1e3;
|
|
|
54342
54494
|
function newestRecentFile2(dir, pattern) {
|
|
54343
54495
|
try {
|
|
54344
54496
|
const cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
54345
|
-
const entries =
|
|
54497
|
+
const entries = fs28.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile() && pattern.test(e.name)).map((e) => ({ p: path34.join(dir, e.name), mtime: safeMtime(path34.join(dir, e.name)) })).filter((e) => e.mtime >= cutoff).sort((a, b) => b.mtime - a.mtime);
|
|
54346
54498
|
return entries[0]?.p ?? null;
|
|
54347
54499
|
} catch {
|
|
54348
54500
|
return null;
|
|
@@ -54350,14 +54502,14 @@ function newestRecentFile2(dir, pattern) {
|
|
|
54350
54502
|
}
|
|
54351
54503
|
function safeMtime(p) {
|
|
54352
54504
|
try {
|
|
54353
|
-
return Math.floor(
|
|
54505
|
+
return Math.floor(fs28.statSync(p).mtimeMs);
|
|
54354
54506
|
} catch {
|
|
54355
54507
|
return 0;
|
|
54356
54508
|
}
|
|
54357
54509
|
}
|
|
54358
54510
|
function safeBirthtime(p) {
|
|
54359
54511
|
try {
|
|
54360
|
-
const st =
|
|
54512
|
+
const st = fs28.statSync(p);
|
|
54361
54513
|
const birth = Math.floor(st.birthtimeMs);
|
|
54362
54514
|
return birth > 0 ? birth : Math.floor(st.mtimeMs);
|
|
54363
54515
|
} catch {
|
|
@@ -54366,7 +54518,7 @@ function safeBirthtime(p) {
|
|
|
54366
54518
|
}
|
|
54367
54519
|
function safeSize(p) {
|
|
54368
54520
|
try {
|
|
54369
|
-
return
|
|
54521
|
+
return fs28.statSync(p).size;
|
|
54370
54522
|
} catch {
|
|
54371
54523
|
return 0;
|
|
54372
54524
|
}
|
|
@@ -54460,9 +54612,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54460
54612
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
54461
54613
|
static looksLikeProviderRoot(candidate) {
|
|
54462
54614
|
try {
|
|
54463
|
-
if (!
|
|
54615
|
+
if (!fs29.existsSync(candidate) || !fs29.statSync(candidate).isDirectory()) return false;
|
|
54464
54616
|
return ["ide", "extension", "cli", "acp"].some(
|
|
54465
|
-
(category) =>
|
|
54617
|
+
(category) => fs29.existsSync(path36.join(candidate, category))
|
|
54466
54618
|
);
|
|
54467
54619
|
} catch {
|
|
54468
54620
|
return false;
|
|
@@ -54470,7 +54622,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54470
54622
|
}
|
|
54471
54623
|
static hasProviderRootMarker(candidate) {
|
|
54472
54624
|
try {
|
|
54473
|
-
return
|
|
54625
|
+
return fs29.existsSync(path36.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
54474
54626
|
} catch {
|
|
54475
54627
|
return false;
|
|
54476
54628
|
}
|
|
@@ -54535,12 +54687,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54535
54687
|
const home = os26.homedir();
|
|
54536
54688
|
const oldDir = path36.join(home, ".adhdev", "marketplace");
|
|
54537
54689
|
const newDir = path36.join(home, ".adhdev", "external");
|
|
54538
|
-
if (!
|
|
54539
|
-
if (
|
|
54690
|
+
if (!fs29.existsSync(oldDir)) return;
|
|
54691
|
+
if (fs29.existsSync(newDir)) {
|
|
54540
54692
|
this.log(`Migration skipped: both ~/.adhdev/marketplace and ~/.adhdev/external exist (marketplace dir is now inert and can be removed manually).`);
|
|
54541
54693
|
return;
|
|
54542
54694
|
}
|
|
54543
|
-
|
|
54695
|
+
fs29.renameSync(oldDir, newDir);
|
|
54544
54696
|
this.log(`Migrated ~/.adhdev/marketplace \u2192 ~/.adhdev/external (one-time rename after provider source-layer cleanup).`);
|
|
54545
54697
|
} catch (e) {
|
|
54546
54698
|
this.log(`Marketplace\u2192external migration failed: ${e?.message || e}`);
|
|
@@ -54655,7 +54807,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54655
54807
|
this.providers.clear();
|
|
54656
54808
|
this.providerAvailability.clear();
|
|
54657
54809
|
let upstreamCount = 0;
|
|
54658
|
-
if (!this.disableUpstream &&
|
|
54810
|
+
if (!this.disableUpstream && fs29.existsSync(this.upstreamDir)) {
|
|
54659
54811
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
54660
54812
|
if (upstreamCount > 0) {
|
|
54661
54813
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -54664,10 +54816,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54664
54816
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
54665
54817
|
}
|
|
54666
54818
|
const externalDir = path36.join(os26.homedir(), ".adhdev", "external");
|
|
54667
|
-
if (
|
|
54819
|
+
if (fs29.existsSync(externalDir)) {
|
|
54668
54820
|
const rootEntries = (() => {
|
|
54669
54821
|
try {
|
|
54670
|
-
return
|
|
54822
|
+
return fs29.readdirSync(externalDir, { withFileTypes: true });
|
|
54671
54823
|
} catch {
|
|
54672
54824
|
return [];
|
|
54673
54825
|
}
|
|
@@ -54716,7 +54868,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54716
54868
|
}
|
|
54717
54869
|
}
|
|
54718
54870
|
}
|
|
54719
|
-
if (
|
|
54871
|
+
if (fs29.existsSync(this.userDir)) {
|
|
54720
54872
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
54721
54873
|
if (userCount > 0) {
|
|
54722
54874
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -54731,10 +54883,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54731
54883
|
* Check if upstream directory exists and has providers.
|
|
54732
54884
|
*/
|
|
54733
54885
|
hasUpstream() {
|
|
54734
|
-
if (!
|
|
54886
|
+
if (!fs29.existsSync(this.upstreamDir)) return false;
|
|
54735
54887
|
try {
|
|
54736
|
-
return
|
|
54737
|
-
(d) =>
|
|
54888
|
+
return fs29.readdirSync(this.upstreamDir).some(
|
|
54889
|
+
(d) => fs29.statSync(path36.join(this.upstreamDir, d)).isDirectory()
|
|
54738
54890
|
);
|
|
54739
54891
|
} catch {
|
|
54740
54892
|
return false;
|
|
@@ -55233,7 +55385,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55233
55385
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
55234
55386
|
if (providerDir) {
|
|
55235
55387
|
const fullDir = path36.join(providerDir, entry.scriptDir);
|
|
55236
|
-
resolved._resolvedScriptsPath =
|
|
55388
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
55237
55389
|
}
|
|
55238
55390
|
matched = true;
|
|
55239
55391
|
}
|
|
@@ -55252,7 +55404,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55252
55404
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
55253
55405
|
if (providerDir) {
|
|
55254
55406
|
const fullDir = path36.join(providerDir, base.defaultScriptDir);
|
|
55255
|
-
resolved._resolvedScriptsPath =
|
|
55407
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
55256
55408
|
}
|
|
55257
55409
|
}
|
|
55258
55410
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -55270,7 +55422,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55270
55422
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
55271
55423
|
if (providerDir) {
|
|
55272
55424
|
const fullDir = path36.join(providerDir, dirOverride);
|
|
55273
|
-
resolved._resolvedScriptsPath =
|
|
55425
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
55274
55426
|
}
|
|
55275
55427
|
}
|
|
55276
55428
|
} else if (override.scripts) {
|
|
@@ -55287,7 +55439,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55287
55439
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
55288
55440
|
if (providerDir) {
|
|
55289
55441
|
const fullDir = path36.join(providerDir, base.defaultScriptDir);
|
|
55290
|
-
resolved._resolvedScriptsPath =
|
|
55442
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
55291
55443
|
}
|
|
55292
55444
|
}
|
|
55293
55445
|
}
|
|
@@ -55305,7 +55457,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55305
55457
|
for (const [scriptName, override] of Object.entries(base.overrides)) {
|
|
55306
55458
|
if (!override || typeof override.path !== "string") continue;
|
|
55307
55459
|
const fullPath = path36.join(providerDir2, override.path);
|
|
55308
|
-
if (!
|
|
55460
|
+
if (!fs29.existsSync(fullPath)) {
|
|
55309
55461
|
this.log(` [overrides] ${base.type}: ${scriptName} path not found: ${fullPath}`);
|
|
55310
55462
|
continue;
|
|
55311
55463
|
}
|
|
@@ -55335,7 +55487,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55335
55487
|
}
|
|
55336
55488
|
if (providerDir) {
|
|
55337
55489
|
try {
|
|
55338
|
-
const
|
|
55490
|
+
const fs43 = require("fs");
|
|
55339
55491
|
const path45 = require("path");
|
|
55340
55492
|
const candidates = [];
|
|
55341
55493
|
if (Array.isArray(base.compatibility)) {
|
|
@@ -55347,13 +55499,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55347
55499
|
}
|
|
55348
55500
|
candidates.push(path45.join(providerDir, "specs", "default.json"));
|
|
55349
55501
|
candidates.push(path45.join(providerDir, "spec.json"));
|
|
55350
|
-
const specPath = candidates.find((p) =>
|
|
55502
|
+
const specPath = candidates.find((p) => fs43.existsSync(p));
|
|
55351
55503
|
let nh;
|
|
55352
55504
|
if (specPath) {
|
|
55353
55505
|
resolved._resolvedSpecPath = specPath;
|
|
55354
55506
|
let specControls;
|
|
55355
55507
|
try {
|
|
55356
|
-
const rawSpec = JSON.parse(
|
|
55508
|
+
const rawSpec = JSON.parse(fs43.readFileSync(specPath, "utf8"));
|
|
55357
55509
|
specControls = rawSpec.control_bar;
|
|
55358
55510
|
nh = rawSpec.native_history;
|
|
55359
55511
|
} catch {
|
|
@@ -55392,7 +55544,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55392
55544
|
reader = (input) => executeNativeHistory(nh, input);
|
|
55393
55545
|
} else if (nh.override_path) {
|
|
55394
55546
|
const overrideFile = path45.resolve(providerDir, nh.override_path);
|
|
55395
|
-
if (
|
|
55547
|
+
if (fs43.existsSync(overrideFile)) {
|
|
55396
55548
|
try {
|
|
55397
55549
|
registerProviderScriptRootSafely(path45.dirname(path45.dirname(providerDir)));
|
|
55398
55550
|
delete require.cache[require.resolve(overrideFile)];
|
|
@@ -55437,7 +55589,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55437
55589
|
return null;
|
|
55438
55590
|
}
|
|
55439
55591
|
const dir = path36.join(providerDir, scriptDir);
|
|
55440
|
-
if (!
|
|
55592
|
+
if (!fs29.existsSync(dir)) {
|
|
55441
55593
|
this.debugLog(`[loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
55442
55594
|
return null;
|
|
55443
55595
|
}
|
|
@@ -55445,7 +55597,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55445
55597
|
const cached3 = this.scriptsCache.get(dir);
|
|
55446
55598
|
if (cached3) return cached3;
|
|
55447
55599
|
const scriptsJs = path36.join(dir, "scripts.js");
|
|
55448
|
-
if (
|
|
55600
|
+
if (fs29.existsSync(scriptsJs)) {
|
|
55449
55601
|
try {
|
|
55450
55602
|
delete require.cache[require.resolve(scriptsJs)];
|
|
55451
55603
|
const loaded = require(scriptsJs);
|
|
@@ -55466,9 +55618,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55466
55618
|
watch() {
|
|
55467
55619
|
this.stopWatch();
|
|
55468
55620
|
const watchDir = (dir) => {
|
|
55469
|
-
if (!
|
|
55621
|
+
if (!fs29.existsSync(dir)) {
|
|
55470
55622
|
try {
|
|
55471
|
-
|
|
55623
|
+
fs29.mkdirSync(dir, { recursive: true });
|
|
55472
55624
|
} catch {
|
|
55473
55625
|
return;
|
|
55474
55626
|
}
|
|
@@ -55560,14 +55712,14 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55560
55712
|
const regMetaPath = path36.join(this.upstreamDir, _ProviderLoader.REGISTRY_META_FILE);
|
|
55561
55713
|
let cachedChecksums = {};
|
|
55562
55714
|
try {
|
|
55563
|
-
if (
|
|
55564
|
-
cachedChecksums = JSON.parse(
|
|
55715
|
+
if (fs29.existsSync(regMetaPath)) {
|
|
55716
|
+
cachedChecksums = JSON.parse(fs29.readFileSync(regMetaPath, "utf-8")).checksums ?? {};
|
|
55565
55717
|
}
|
|
55566
55718
|
} catch {
|
|
55567
55719
|
}
|
|
55568
55720
|
try {
|
|
55569
55721
|
const listUrl = `${this.registryBaseUrl}/providers`;
|
|
55570
|
-
const listBody = await new Promise((
|
|
55722
|
+
const listBody = await new Promise((resolve26, reject) => {
|
|
55571
55723
|
const req = https.get(listUrl, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 1e4 }, (res) => {
|
|
55572
55724
|
if (res.statusCode !== 200) {
|
|
55573
55725
|
reject(new Error(`registry list HTTP ${res.statusCode}`));
|
|
@@ -55575,7 +55727,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55575
55727
|
}
|
|
55576
55728
|
const chunks = [];
|
|
55577
55729
|
res.on("data", (c) => chunks.push(c));
|
|
55578
|
-
res.on("end", () =>
|
|
55730
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
55579
55731
|
});
|
|
55580
55732
|
req.on("error", reject);
|
|
55581
55733
|
req.on("timeout", () => {
|
|
@@ -55591,7 +55743,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55591
55743
|
const cacheKey = `${category}/${type}`;
|
|
55592
55744
|
if (cachedChecksums[cacheKey] === checksum) continue;
|
|
55593
55745
|
const dlUrl = `${this.registryBaseUrl}/providers/${type}/${version}/download`;
|
|
55594
|
-
const manifestBody = await new Promise((
|
|
55746
|
+
const manifestBody = await new Promise((resolve26, reject) => {
|
|
55595
55747
|
const req = https.get(dlUrl, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 3e4 }, (res) => {
|
|
55596
55748
|
if (res.statusCode !== 200) {
|
|
55597
55749
|
reject(new Error(`registry download HTTP ${res.statusCode} for ${type}@${version}`));
|
|
@@ -55599,7 +55751,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55599
55751
|
}
|
|
55600
55752
|
const chunks = [];
|
|
55601
55753
|
res.on("data", (c) => chunks.push(c));
|
|
55602
|
-
res.on("end", () =>
|
|
55754
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
55603
55755
|
});
|
|
55604
55756
|
req.on("error", reject);
|
|
55605
55757
|
req.on("timeout", () => {
|
|
@@ -55613,14 +55765,14 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55613
55765
|
continue;
|
|
55614
55766
|
}
|
|
55615
55767
|
const providerDir = path36.join(this.upstreamDir, category, type);
|
|
55616
|
-
|
|
55617
|
-
|
|
55768
|
+
fs29.mkdirSync(providerDir, { recursive: true });
|
|
55769
|
+
fs29.writeFileSync(path36.join(providerDir, "provider.json"), manifestBody, "utf-8");
|
|
55618
55770
|
cachedChecksums[cacheKey] = checksum;
|
|
55619
55771
|
updatedCount++;
|
|
55620
55772
|
this.log(`\u2713 Registry updated: ${category}/${type}@${version}`);
|
|
55621
55773
|
}
|
|
55622
|
-
|
|
55623
|
-
|
|
55774
|
+
fs29.mkdirSync(this.upstreamDir, { recursive: true });
|
|
55775
|
+
fs29.writeFileSync(regMetaPath, JSON.stringify({
|
|
55624
55776
|
checksums: cachedChecksums,
|
|
55625
55777
|
syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
55626
55778
|
providerCount: list.providers.length
|
|
@@ -55645,8 +55797,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55645
55797
|
let prevEtag = "";
|
|
55646
55798
|
let prevTimestamp = 0;
|
|
55647
55799
|
try {
|
|
55648
|
-
if (
|
|
55649
|
-
const meta = JSON.parse(
|
|
55800
|
+
if (fs29.existsSync(metaPath)) {
|
|
55801
|
+
const meta = JSON.parse(fs29.readFileSync(metaPath, "utf-8"));
|
|
55650
55802
|
prevEtag = meta.etag || "";
|
|
55651
55803
|
prevTimestamp = meta.timestamp || 0;
|
|
55652
55804
|
}
|
|
@@ -55659,7 +55811,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55659
55811
|
}
|
|
55660
55812
|
const tarballTarget = resolveProviderTarballTarget(this.providerTarballUrl);
|
|
55661
55813
|
try {
|
|
55662
|
-
const etag = await new Promise((
|
|
55814
|
+
const etag = await new Promise((resolve26, reject) => {
|
|
55663
55815
|
const options = {
|
|
55664
55816
|
method: "HEAD",
|
|
55665
55817
|
hostname: tarballTarget.hostname,
|
|
@@ -55677,7 +55829,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55677
55829
|
headers: { "User-Agent": "adhdev-launcher" },
|
|
55678
55830
|
timeout: 1e4
|
|
55679
55831
|
}, (res2) => {
|
|
55680
|
-
|
|
55832
|
+
resolve26(res2.headers.etag || res2.headers["last-modified"] || "");
|
|
55681
55833
|
});
|
|
55682
55834
|
req2.on("error", reject);
|
|
55683
55835
|
req2.on("timeout", () => {
|
|
@@ -55686,7 +55838,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55686
55838
|
});
|
|
55687
55839
|
req2.end();
|
|
55688
55840
|
} else {
|
|
55689
|
-
|
|
55841
|
+
resolve26(res.headers.etag || res.headers["last-modified"] || "");
|
|
55690
55842
|
}
|
|
55691
55843
|
});
|
|
55692
55844
|
req.on("error", reject);
|
|
@@ -55705,36 +55857,36 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55705
55857
|
const tmpTar = path36.join(os26.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
55706
55858
|
const tmpExtract = path36.join(os26.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
55707
55859
|
await this.downloadFile(tarballTarget.url, tmpTar);
|
|
55708
|
-
|
|
55860
|
+
fs29.mkdirSync(tmpExtract, { recursive: true });
|
|
55709
55861
|
await execAsync5(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
55710
|
-
const extracted =
|
|
55862
|
+
const extracted = fs29.readdirSync(tmpExtract);
|
|
55711
55863
|
const rootDir = extracted.find(
|
|
55712
|
-
(d) =>
|
|
55864
|
+
(d) => fs29.statSync(path36.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
55713
55865
|
);
|
|
55714
55866
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
55715
55867
|
const sourceDir = path36.join(tmpExtract, rootDir);
|
|
55716
55868
|
const backupDir = this.upstreamDir + ".bak";
|
|
55717
|
-
if (
|
|
55718
|
-
if (
|
|
55719
|
-
|
|
55869
|
+
if (fs29.existsSync(this.upstreamDir)) {
|
|
55870
|
+
if (fs29.existsSync(backupDir)) fs29.rmSync(backupDir, { recursive: true, force: true });
|
|
55871
|
+
fs29.renameSync(this.upstreamDir, backupDir);
|
|
55720
55872
|
}
|
|
55721
55873
|
try {
|
|
55722
55874
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
55723
55875
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
55724
|
-
if (
|
|
55876
|
+
if (fs29.existsSync(backupDir)) fs29.rmSync(backupDir, { recursive: true, force: true });
|
|
55725
55877
|
} catch (e) {
|
|
55726
|
-
if (
|
|
55727
|
-
if (
|
|
55728
|
-
|
|
55878
|
+
if (fs29.existsSync(backupDir)) {
|
|
55879
|
+
if (fs29.existsSync(this.upstreamDir)) fs29.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
55880
|
+
fs29.renameSync(backupDir, this.upstreamDir);
|
|
55729
55881
|
}
|
|
55730
55882
|
throw e;
|
|
55731
55883
|
}
|
|
55732
55884
|
try {
|
|
55733
|
-
|
|
55885
|
+
fs29.rmSync(tmpTar, { force: true });
|
|
55734
55886
|
} catch {
|
|
55735
55887
|
}
|
|
55736
55888
|
try {
|
|
55737
|
-
|
|
55889
|
+
fs29.rmSync(tmpExtract, { recursive: true, force: true });
|
|
55738
55890
|
} catch {
|
|
55739
55891
|
}
|
|
55740
55892
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -55750,7 +55902,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55750
55902
|
downloadFile(url, destPath) {
|
|
55751
55903
|
const https = require("https");
|
|
55752
55904
|
const http3 = require("http");
|
|
55753
|
-
return new Promise((
|
|
55905
|
+
return new Promise((resolve26, reject) => {
|
|
55754
55906
|
const doRequest = (reqUrl, redirectCount = 0) => {
|
|
55755
55907
|
if (redirectCount > 5) {
|
|
55756
55908
|
reject(new Error("Too many redirects"));
|
|
@@ -55766,11 +55918,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55766
55918
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
55767
55919
|
return;
|
|
55768
55920
|
}
|
|
55769
|
-
const ws =
|
|
55921
|
+
const ws = fs29.createWriteStream(destPath);
|
|
55770
55922
|
res.pipe(ws);
|
|
55771
55923
|
ws.on("finish", () => {
|
|
55772
55924
|
ws.close();
|
|
55773
|
-
|
|
55925
|
+
resolve26();
|
|
55774
55926
|
});
|
|
55775
55927
|
ws.on("error", reject);
|
|
55776
55928
|
});
|
|
@@ -55785,22 +55937,22 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55785
55937
|
}
|
|
55786
55938
|
/** Recursive directory copy */
|
|
55787
55939
|
copyDirRecursive(src, dest) {
|
|
55788
|
-
|
|
55789
|
-
for (const entry of
|
|
55940
|
+
fs29.mkdirSync(dest, { recursive: true });
|
|
55941
|
+
for (const entry of fs29.readdirSync(src, { withFileTypes: true })) {
|
|
55790
55942
|
const srcPath = path36.join(src, entry.name);
|
|
55791
55943
|
const destPath = path36.join(dest, entry.name);
|
|
55792
55944
|
if (entry.isDirectory()) {
|
|
55793
55945
|
this.copyDirRecursive(srcPath, destPath);
|
|
55794
55946
|
} else {
|
|
55795
|
-
|
|
55947
|
+
fs29.copyFileSync(srcPath, destPath);
|
|
55796
55948
|
}
|
|
55797
55949
|
}
|
|
55798
55950
|
}
|
|
55799
55951
|
/** .meta.json save */
|
|
55800
55952
|
writeMeta(metaPath, etag, timestamp) {
|
|
55801
55953
|
try {
|
|
55802
|
-
|
|
55803
|
-
|
|
55954
|
+
fs29.mkdirSync(path36.dirname(metaPath), { recursive: true });
|
|
55955
|
+
fs29.writeFileSync(metaPath, JSON.stringify({
|
|
55804
55956
|
etag,
|
|
55805
55957
|
timestamp,
|
|
55806
55958
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -55811,11 +55963,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55811
55963
|
}
|
|
55812
55964
|
/** Count provider files (provider.v1.json or provider.json — at most one per dir). */
|
|
55813
55965
|
countProviders(dir) {
|
|
55814
|
-
if (!
|
|
55966
|
+
if (!fs29.existsSync(dir)) return 0;
|
|
55815
55967
|
let count = 0;
|
|
55816
55968
|
const scan = (d) => {
|
|
55817
55969
|
try {
|
|
55818
|
-
const entries =
|
|
55970
|
+
const entries = fs29.readdirSync(d, { withFileTypes: true });
|
|
55819
55971
|
const hasManifest = entries.some((e) => e.name === "provider.v1.json" || e.name === "provider.json");
|
|
55820
55972
|
if (hasManifest) count++;
|
|
55821
55973
|
for (const entry of entries) {
|
|
@@ -56045,13 +56197,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56045
56197
|
if (!provider) return null;
|
|
56046
56198
|
const cat = provider.category;
|
|
56047
56199
|
const searchRoots = this.getProviderRoots();
|
|
56048
|
-
const hasManifest = (dir) =>
|
|
56200
|
+
const hasManifest = (dir) => fs29.existsSync(path36.join(dir, "provider.v1.json")) || fs29.existsSync(path36.join(dir, "provider.json"));
|
|
56049
56201
|
const readManifestType = (dir) => {
|
|
56050
56202
|
for (const file of ["provider.v1.json", "provider.json"]) {
|
|
56051
56203
|
const p = path36.join(dir, file);
|
|
56052
|
-
if (!
|
|
56204
|
+
if (!fs29.existsSync(p)) continue;
|
|
56053
56205
|
try {
|
|
56054
|
-
const data = JSON.parse(
|
|
56206
|
+
const data = JSON.parse(fs29.readFileSync(p, "utf-8"));
|
|
56055
56207
|
if (typeof data?.type === "string") return data.type;
|
|
56056
56208
|
} catch {
|
|
56057
56209
|
}
|
|
@@ -56059,13 +56211,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56059
56211
|
return null;
|
|
56060
56212
|
};
|
|
56061
56213
|
for (const root of searchRoots) {
|
|
56062
|
-
if (!
|
|
56214
|
+
if (!fs29.existsSync(root)) continue;
|
|
56063
56215
|
const candidate = this.getProviderDir(root, cat, type);
|
|
56064
56216
|
if (hasManifest(candidate)) return candidate;
|
|
56065
56217
|
const catDir = path36.join(root, cat);
|
|
56066
|
-
if (
|
|
56218
|
+
if (fs29.existsSync(catDir)) {
|
|
56067
56219
|
try {
|
|
56068
|
-
for (const entry of
|
|
56220
|
+
for (const entry of fs29.readdirSync(catDir, { withFileTypes: true })) {
|
|
56069
56221
|
if (!entry.isDirectory()) continue;
|
|
56070
56222
|
const entryDir = path36.join(catDir, entry.name);
|
|
56071
56223
|
const manifestType = readManifestType(entryDir);
|
|
@@ -56084,7 +56236,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56084
56236
|
*/
|
|
56085
56237
|
buildScriptWrappersFromDir(dir) {
|
|
56086
56238
|
const scriptsJs = path36.join(dir, "scripts.js");
|
|
56087
|
-
if (
|
|
56239
|
+
if (fs29.existsSync(scriptsJs)) {
|
|
56088
56240
|
try {
|
|
56089
56241
|
delete require.cache[require.resolve(scriptsJs)];
|
|
56090
56242
|
return require(scriptsJs);
|
|
@@ -56094,13 +56246,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56094
56246
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
56095
56247
|
const result = {};
|
|
56096
56248
|
try {
|
|
56097
|
-
for (const file of
|
|
56249
|
+
for (const file of fs29.readdirSync(dir)) {
|
|
56098
56250
|
if (!file.endsWith(".js")) continue;
|
|
56099
56251
|
const scriptName = toCamel(file.replace(".js", ""));
|
|
56100
56252
|
const filePath = path36.join(dir, file);
|
|
56101
56253
|
result[scriptName] = (...args) => {
|
|
56102
56254
|
try {
|
|
56103
|
-
let content =
|
|
56255
|
+
let content = fs29.readFileSync(filePath, "utf-8");
|
|
56104
56256
|
if (args[0] && typeof args[0] === "object") {
|
|
56105
56257
|
for (const [key2, val] of Object.entries(args[0])) {
|
|
56106
56258
|
let v = val;
|
|
@@ -56146,12 +56298,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56146
56298
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
56147
56299
|
*/
|
|
56148
56300
|
loadDir(dir, excludeDirs) {
|
|
56149
|
-
if (!
|
|
56301
|
+
if (!fs29.existsSync(dir)) return 0;
|
|
56150
56302
|
let count = 0;
|
|
56151
56303
|
const scan = (d) => {
|
|
56152
56304
|
let entries;
|
|
56153
56305
|
try {
|
|
56154
|
-
entries =
|
|
56306
|
+
entries = fs29.readdirSync(d, { withFileTypes: true });
|
|
56155
56307
|
} catch {
|
|
56156
56308
|
return;
|
|
56157
56309
|
}
|
|
@@ -56161,7 +56313,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56161
56313
|
const manifestFile = hasV1 ? "provider.v1.json" : "provider.json";
|
|
56162
56314
|
const jsonPath = path36.join(d, manifestFile);
|
|
56163
56315
|
try {
|
|
56164
|
-
const raw =
|
|
56316
|
+
const raw = fs29.readFileSync(jsonPath, "utf-8");
|
|
56165
56317
|
const mod = JSON.parse(raw);
|
|
56166
56318
|
if (hasV1 && mod?.category === "cli") {
|
|
56167
56319
|
try {
|
|
@@ -56200,7 +56352,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
56200
56352
|
} else {
|
|
56201
56353
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
56202
56354
|
const scriptsPath = path36.join(d, "scripts.js");
|
|
56203
|
-
if (!hasCompatibility &&
|
|
56355
|
+
if (!hasCompatibility && fs29.existsSync(scriptsPath)) {
|
|
56204
56356
|
try {
|
|
56205
56357
|
registerProviderScriptRootSafely(path36.dirname(path36.dirname(d)));
|
|
56206
56358
|
delete require.cache[require.resolve(scriptsPath)];
|
|
@@ -56326,10 +56478,10 @@ function findMacAppProcessPids(psOutput, appPaths) {
|
|
|
56326
56478
|
|
|
56327
56479
|
// src/launch.ts
|
|
56328
56480
|
async function execQuiet(command, options = {}) {
|
|
56329
|
-
return new Promise((
|
|
56481
|
+
return new Promise((resolve26) => {
|
|
56330
56482
|
(0, import_child_process9.exec)(command, options, (error, stdout) => {
|
|
56331
|
-
if (error) return
|
|
56332
|
-
|
|
56483
|
+
if (error) return resolve26("");
|
|
56484
|
+
resolve26(stdout.toString());
|
|
56333
56485
|
});
|
|
56334
56486
|
});
|
|
56335
56487
|
}
|
|
@@ -56410,17 +56562,17 @@ async function findFreePort(ports) {
|
|
|
56410
56562
|
throw new Error("No free port found");
|
|
56411
56563
|
}
|
|
56412
56564
|
function checkPortFree(port) {
|
|
56413
|
-
return new Promise((
|
|
56565
|
+
return new Promise((resolve26) => {
|
|
56414
56566
|
const server = net.createServer();
|
|
56415
56567
|
server.unref();
|
|
56416
|
-
server.on("error", () =>
|
|
56568
|
+
server.on("error", () => resolve26(false));
|
|
56417
56569
|
server.listen(port, "127.0.0.1", () => {
|
|
56418
|
-
server.close(() =>
|
|
56570
|
+
server.close(() => resolve26(true));
|
|
56419
56571
|
});
|
|
56420
56572
|
});
|
|
56421
56573
|
}
|
|
56422
56574
|
async function isCdpActive(port) {
|
|
56423
|
-
return new Promise((
|
|
56575
|
+
return new Promise((resolve26) => {
|
|
56424
56576
|
const req = require("http").get(`http://127.0.0.1:${port}/json/version`, {
|
|
56425
56577
|
timeout: 2e3
|
|
56426
56578
|
}, (res) => {
|
|
@@ -56429,16 +56581,16 @@ async function isCdpActive(port) {
|
|
|
56429
56581
|
res.on("end", () => {
|
|
56430
56582
|
try {
|
|
56431
56583
|
const info = JSON.parse(data);
|
|
56432
|
-
|
|
56584
|
+
resolve26(!!info["WebKit-Version"] || !!info["Browser"]);
|
|
56433
56585
|
} catch {
|
|
56434
|
-
|
|
56586
|
+
resolve26(false);
|
|
56435
56587
|
}
|
|
56436
56588
|
});
|
|
56437
56589
|
});
|
|
56438
|
-
req.on("error", () =>
|
|
56590
|
+
req.on("error", () => resolve26(false));
|
|
56439
56591
|
req.on("timeout", () => {
|
|
56440
56592
|
req.destroy();
|
|
56441
|
-
|
|
56593
|
+
resolve26(false);
|
|
56442
56594
|
});
|
|
56443
56595
|
});
|
|
56444
56596
|
}
|
|
@@ -56574,7 +56726,7 @@ async function detectCurrentWorkspace(ideId) {
|
|
|
56574
56726
|
}
|
|
56575
56727
|
} else if (plat === "win32") {
|
|
56576
56728
|
try {
|
|
56577
|
-
const
|
|
56729
|
+
const fs43 = require("fs");
|
|
56578
56730
|
const appNameMap = getMacAppIdentifiers();
|
|
56579
56731
|
const appName = appNameMap[ideId];
|
|
56580
56732
|
if (appName) {
|
|
@@ -56583,8 +56735,8 @@ async function detectCurrentWorkspace(ideId) {
|
|
|
56583
56735
|
appName,
|
|
56584
56736
|
"storage.json"
|
|
56585
56737
|
);
|
|
56586
|
-
if (
|
|
56587
|
-
const data = JSON.parse(
|
|
56738
|
+
if (fs43.existsSync(storagePath)) {
|
|
56739
|
+
const data = JSON.parse(fs43.readFileSync(storagePath, "utf-8"));
|
|
56588
56740
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
56589
56741
|
if (workspaces.length > 0) {
|
|
56590
56742
|
const recent = workspaces[0];
|
|
@@ -57104,7 +57256,7 @@ var meshCrudHandlers = {
|
|
|
57104
57256
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
57105
57257
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
57106
57258
|
const { mkdirSync: mkdirSync22, writeFileSync: writeFileSync24 } = await import("fs");
|
|
57107
|
-
const { dirname:
|
|
57259
|
+
const { dirname: dirname18, join: join52 } = await import("path");
|
|
57108
57260
|
const scaffold = buildMeshJsonConfigScaffold2(mesh);
|
|
57109
57261
|
const scaffoldJson = serializeMeshJsonConfigScaffold2(scaffold);
|
|
57110
57262
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
@@ -57144,7 +57296,7 @@ var meshCrudHandlers = {
|
|
|
57144
57296
|
note: "Dry-run: nothing written. Re-run with write=true to persist to the repo (commit target). meshes.json is untouched."
|
|
57145
57297
|
};
|
|
57146
57298
|
}
|
|
57147
|
-
mkdirSync22(
|
|
57299
|
+
mkdirSync22(dirname18(absolutePath), { recursive: true });
|
|
57148
57300
|
writeFileSync24(absolutePath, `${scaffoldJson}
|
|
57149
57301
|
`, "utf-8");
|
|
57150
57302
|
return {
|
|
@@ -57683,7 +57835,7 @@ var meshCrudHandlers = {
|
|
|
57683
57835
|
const setupPromise = finishWorktreeSetup();
|
|
57684
57836
|
const setupResult = await Promise.race([
|
|
57685
57837
|
setupPromise.then((value) => ({ completed: true, value })),
|
|
57686
|
-
new Promise((
|
|
57838
|
+
new Promise((resolve26) => setTimeout(() => resolve26({ completed: false }), setupWaitMs))
|
|
57687
57839
|
]);
|
|
57688
57840
|
const emitBootstrapEvent = (eventStatus2, bootstrapState2, startedAtMs, extraPayload) => {
|
|
57689
57841
|
try {
|
|
@@ -58566,7 +58718,7 @@ var meshEventsHandlers = {
|
|
|
58566
58718
|
|
|
58567
58719
|
// src/commands/high-family/mesh-coordinator-launch.ts
|
|
58568
58720
|
var import_path13 = require("path");
|
|
58569
|
-
var
|
|
58721
|
+
var fs30 = __toESM(require("fs"));
|
|
58570
58722
|
init_logger();
|
|
58571
58723
|
init_mesh_host_ownership();
|
|
58572
58724
|
init_coordinator_registry();
|
|
@@ -58812,15 +58964,15 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58812
58964
|
}
|
|
58813
58965
|
if (cliType === "codex-cli") {
|
|
58814
58966
|
const repoMcpConfigPath = (0, import_path13.join)(workspace, ".mcp.json");
|
|
58815
|
-
if (
|
|
58967
|
+
if (fs30.existsSync(repoMcpConfigPath)) {
|
|
58816
58968
|
try {
|
|
58817
58969
|
const repoMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
58818
|
-
|
|
58970
|
+
fs30.readFileSync(repoMcpConfigPath, "utf-8"),
|
|
58819
58971
|
"claude_mcp_json"
|
|
58820
58972
|
);
|
|
58821
58973
|
const existingServers2 = repoMcpConfig.mcpServers;
|
|
58822
58974
|
if (existingServers2 && typeof existingServers2 === "object" && !Array.isArray(existingServers2) && existingServers2[coordinatorSetup.serverName]) {
|
|
58823
|
-
|
|
58975
|
+
fs30.writeFileSync(repoMcpConfigPath, serializeMeshCoordinatorMcpConfig({
|
|
58824
58976
|
...repoMcpConfig,
|
|
58825
58977
|
mcpServers: {
|
|
58826
58978
|
...existingServers2,
|
|
@@ -58939,7 +59091,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58939
59091
|
};
|
|
58940
59092
|
}
|
|
58941
59093
|
const { existsSync: existsSync55, readFileSync: readFileSync42, writeFileSync: writeFileSync24, copyFileSync: copyFileSync4, mkdirSync: mkdirSync22 } = await import("fs");
|
|
58942
|
-
const { dirname:
|
|
59094
|
+
const { dirname: dirname18 } = await import("path");
|
|
58943
59095
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
58944
59096
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
58945
59097
|
let hermesBaseConfig = null;
|
|
@@ -58974,7 +59126,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58974
59126
|
};
|
|
58975
59127
|
}
|
|
58976
59128
|
try {
|
|
58977
|
-
mkdirSync22(
|
|
59129
|
+
mkdirSync22(dirname18(mcpConfigPath), { recursive: true });
|
|
58978
59130
|
} catch (error) {
|
|
58979
59131
|
const message = `Could not prepare MCP config path for automatic setup: ${error?.message || error}`;
|
|
58980
59132
|
LOG.error("MeshCoordinator", message);
|
|
@@ -58984,7 +59136,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58984
59136
|
const hadExistingMcpConfig = existsSync55(mcpConfigPath);
|
|
58985
59137
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
58986
59138
|
if (hermesBaseConfig) {
|
|
58987
|
-
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome,
|
|
59139
|
+
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname18(mcpConfigPath));
|
|
58988
59140
|
}
|
|
58989
59141
|
if (hadExistingMcpConfig) {
|
|
58990
59142
|
try {
|
|
@@ -59022,7 +59174,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
59022
59174
|
const cliArgs = [];
|
|
59023
59175
|
const launchEnv = {};
|
|
59024
59176
|
if (configFormat === "hermes_config_yaml") {
|
|
59025
|
-
launchEnv.HERMES_HOME =
|
|
59177
|
+
launchEnv.HERMES_HOME = dirname18(mcpConfigPath);
|
|
59026
59178
|
launchEnv.HERMES_IGNORE_USER_CONFIG = "";
|
|
59027
59179
|
}
|
|
59028
59180
|
let autoImportContextFilePath;
|
|
@@ -59107,7 +59259,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
59107
59259
|
};
|
|
59108
59260
|
|
|
59109
59261
|
// src/commands/high-family/mesh-status.ts
|
|
59110
|
-
var
|
|
59262
|
+
var fs31 = __toESM(require("fs"));
|
|
59111
59263
|
var import_os3 = require("os");
|
|
59112
59264
|
init_config();
|
|
59113
59265
|
init_git_status();
|
|
@@ -59474,7 +59626,7 @@ var meshStatusHandlers = {
|
|
|
59474
59626
|
}
|
|
59475
59627
|
}
|
|
59476
59628
|
if (workspace) {
|
|
59477
|
-
if (!
|
|
59629
|
+
if (!fs31.existsSync(workspace)) {
|
|
59478
59630
|
const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
|
|
59479
59631
|
let remoteProbeApplied = false;
|
|
59480
59632
|
if (inlineTransitGit) {
|
|
@@ -59610,7 +59762,7 @@ var meshStatusHandlers = {
|
|
|
59610
59762
|
backstop: { ...getMeshV2BackstopCounters() }
|
|
59611
59763
|
};
|
|
59612
59764
|
const previewFreshness = (() => {
|
|
59613
|
-
const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate &&
|
|
59765
|
+
const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate && fs31.existsSync(candidate));
|
|
59614
59766
|
return localRepoRoot ? buildPreviewFreshness(localRepoRoot) : void 0;
|
|
59615
59767
|
})();
|
|
59616
59768
|
const asyncRefineJobs = buildMeshAsyncRefineJobs({
|
|
@@ -59810,7 +59962,7 @@ init_dist();
|
|
|
59810
59962
|
init_logger();
|
|
59811
59963
|
|
|
59812
59964
|
// src/logging/command-log.ts
|
|
59813
|
-
var
|
|
59965
|
+
var fs32 = __toESM(require("fs"));
|
|
59814
59966
|
var path38 = __toESM(require("path"));
|
|
59815
59967
|
var os28 = __toESM(require("os"));
|
|
59816
59968
|
var ADHDEV_HOME2 = process.env.ADHDEV_CONFIG_DIR && process.env.ADHDEV_CONFIG_DIR.trim() ? process.env.ADHDEV_CONFIG_DIR.trim() : path38.join(os28.homedir(), ".adhdev");
|
|
@@ -59818,7 +59970,7 @@ var LOG_DIR2 = path38.join(ADHDEV_HOME2, "logs");
|
|
|
59818
59970
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
59819
59971
|
var MAX_DAYS = 7;
|
|
59820
59972
|
try {
|
|
59821
|
-
|
|
59973
|
+
fs32.mkdirSync(LOG_DIR2, { recursive: true });
|
|
59822
59974
|
} catch {
|
|
59823
59975
|
}
|
|
59824
59976
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -59864,7 +60016,7 @@ function checkRotation() {
|
|
|
59864
60016
|
}
|
|
59865
60017
|
function cleanOldFiles() {
|
|
59866
60018
|
try {
|
|
59867
|
-
const files =
|
|
60019
|
+
const files = fs32.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
59868
60020
|
const cutoff = /* @__PURE__ */ new Date();
|
|
59869
60021
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
59870
60022
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -59872,7 +60024,7 @@ function cleanOldFiles() {
|
|
|
59872
60024
|
const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
59873
60025
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
59874
60026
|
try {
|
|
59875
|
-
|
|
60027
|
+
fs32.unlinkSync(path38.join(LOG_DIR2, file));
|
|
59876
60028
|
} catch {
|
|
59877
60029
|
}
|
|
59878
60030
|
}
|
|
@@ -59882,14 +60034,14 @@ function cleanOldFiles() {
|
|
|
59882
60034
|
}
|
|
59883
60035
|
function checkSize() {
|
|
59884
60036
|
try {
|
|
59885
|
-
const stat2 =
|
|
60037
|
+
const stat2 = fs32.statSync(currentFile);
|
|
59886
60038
|
if (stat2.size > MAX_FILE_SIZE) {
|
|
59887
60039
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
59888
60040
|
try {
|
|
59889
|
-
|
|
60041
|
+
fs32.unlinkSync(backup);
|
|
59890
60042
|
} catch {
|
|
59891
60043
|
}
|
|
59892
|
-
|
|
60044
|
+
fs32.renameSync(currentFile, backup);
|
|
59893
60045
|
}
|
|
59894
60046
|
} catch {
|
|
59895
60047
|
}
|
|
@@ -59922,14 +60074,14 @@ function logCommand(entry) {
|
|
|
59922
60074
|
...entry.error ? { err: entry.error } : {},
|
|
59923
60075
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
59924
60076
|
});
|
|
59925
|
-
|
|
60077
|
+
fs32.appendFileSync(currentFile, line + "\n");
|
|
59926
60078
|
} catch {
|
|
59927
60079
|
}
|
|
59928
60080
|
}
|
|
59929
60081
|
function getRecentCommands(count = 50) {
|
|
59930
60082
|
try {
|
|
59931
|
-
if (!
|
|
59932
|
-
const content =
|
|
60083
|
+
if (!fs32.existsSync(currentFile)) return [];
|
|
60084
|
+
const content = fs32.readFileSync(currentFile, "utf-8");
|
|
59933
60085
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
59934
60086
|
return lines.slice(-count).map((line) => {
|
|
59935
60087
|
try {
|
|
@@ -59957,7 +60109,7 @@ cleanOldFiles();
|
|
|
59957
60109
|
// src/commands/router.ts
|
|
59958
60110
|
init_debug_trace();
|
|
59959
60111
|
init_mesh_host_ownership();
|
|
59960
|
-
var
|
|
60112
|
+
var fs36 = __toESM(require("fs"));
|
|
59961
60113
|
init_mesh_node_identity();
|
|
59962
60114
|
|
|
59963
60115
|
// src/commands/router-refine.ts
|
|
@@ -60068,7 +60220,7 @@ init_git_status();
|
|
|
60068
60220
|
init_refine_config();
|
|
60069
60221
|
init_worktree_bootstrap_config();
|
|
60070
60222
|
var import_path14 = require("path");
|
|
60071
|
-
var
|
|
60223
|
+
var fs33 = __toESM(require("fs"));
|
|
60072
60224
|
var import_node_child_process6 = require("child_process");
|
|
60073
60225
|
init_resolve_executable();
|
|
60074
60226
|
var GIT2 = process.platform === "win32" ? resolveWin32Executable("git") : "git";
|
|
@@ -60427,7 +60579,7 @@ function isSubmoduleFastForward(submoduleRepoPath, baseCommit, branchCommit) {
|
|
|
60427
60579
|
if (!baseCommit || !branchCommit) return false;
|
|
60428
60580
|
if (baseCommit === branchCommit) return true;
|
|
60429
60581
|
try {
|
|
60430
|
-
if (!
|
|
60582
|
+
if (!fs33.existsSync(submoduleRepoPath)) return false;
|
|
60431
60583
|
(0, import_node_child_process6.execFileSync)(GIT2, ["cat-file", "-e", `${baseCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
60432
60584
|
(0, import_node_child_process6.execFileSync)(GIT2, ["cat-file", "-e", `${branchCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
60433
60585
|
(0, import_node_child_process6.execFileSync)(GIT2, ["merge-base", "--is-ancestor", baseCommit, branchCommit], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
@@ -60544,7 +60696,7 @@ function buildTreeWithGitlinksEqualized(repoRoot, commitish, paths, placeholderC
|
|
|
60544
60696
|
return newTree || void 0;
|
|
60545
60697
|
} finally {
|
|
60546
60698
|
try {
|
|
60547
|
-
|
|
60699
|
+
fs33.rmSync(tmpIndex, { force: true });
|
|
60548
60700
|
} catch {
|
|
60549
60701
|
}
|
|
60550
60702
|
}
|
|
@@ -60619,7 +60771,7 @@ function synthesizeTrivialFastForwardMergeTree(repoRoot, baseHead, branchHead, g
|
|
|
60619
60771
|
return newTree || void 0;
|
|
60620
60772
|
} finally {
|
|
60621
60773
|
try {
|
|
60622
|
-
|
|
60774
|
+
fs33.rmSync(tmpIndex, { force: true });
|
|
60623
60775
|
} catch {
|
|
60624
60776
|
}
|
|
60625
60777
|
}
|
|
@@ -60731,7 +60883,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
60731
60883
|
return { stdout: String(stdout || ""), stderr: String(stderr || ""), refspec };
|
|
60732
60884
|
};
|
|
60733
60885
|
const importCommitFromWorktreeSubmodule = async (submodulePath, worktreeSubmodulePath, commit) => {
|
|
60734
|
-
if (!
|
|
60886
|
+
if (!fs33.existsSync(worktreeSubmodulePath)) return false;
|
|
60735
60887
|
try {
|
|
60736
60888
|
await runGit3(worktreeSubmodulePath, ["cat-file", "-e", `${commit}^{commit}`]);
|
|
60737
60889
|
} catch {
|
|
@@ -60755,7 +60907,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
60755
60907
|
};
|
|
60756
60908
|
let submoduleDefaultBranch = "main";
|
|
60757
60909
|
try {
|
|
60758
|
-
if (!
|
|
60910
|
+
if (!fs33.existsSync(submodulePath)) {
|
|
60759
60911
|
entry.error = `Submodule checkout missing at ${gitlink.path}`;
|
|
60760
60912
|
entry.publishRequired = true;
|
|
60761
60913
|
if (options.allowAutoPublishSubmoduleMainCommits === true) {
|
|
@@ -61000,9 +61152,9 @@ async function runMeshRefineValidationGate(mesh, workspace, opts) {
|
|
|
61000
61152
|
return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
|
|
61001
61153
|
};
|
|
61002
61154
|
const dependenciesLikelyMissing = (cwd) => {
|
|
61003
|
-
if (!
|
|
61004
|
-
if (
|
|
61005
|
-
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) =>
|
|
61155
|
+
if (!fs33.existsSync((0, import_path14.join)(cwd, "package.json"))) return false;
|
|
61156
|
+
if (fs33.existsSync((0, import_path14.join)(cwd, "node_modules"))) return false;
|
|
61157
|
+
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs33.existsSync((0, import_path14.join)(cwd, lock)));
|
|
61006
61158
|
};
|
|
61007
61159
|
const needsNodeModules = (candidate, cwd) => isPackageManagerValidation(candidate) && dependenciesLikelyMissing(cwd);
|
|
61008
61160
|
const isDaemonScopedCommand = (candidate) => {
|
|
@@ -62898,7 +63050,7 @@ async function startMeshRefineJob(self, meshId, nodeId, args) {
|
|
|
62898
63050
|
}
|
|
62899
63051
|
|
|
62900
63052
|
// src/commands/router-worktree-cleanup.ts
|
|
62901
|
-
var
|
|
63053
|
+
var fs34 = __toESM(require("fs"));
|
|
62902
63054
|
var import_path15 = require("path");
|
|
62903
63055
|
init_logger();
|
|
62904
63056
|
init_dist();
|
|
@@ -62915,14 +63067,14 @@ function sessionMatchesMeshNode(self, record, node, nodeId, sessionIds) {
|
|
|
62915
63067
|
return false;
|
|
62916
63068
|
}
|
|
62917
63069
|
async function bestEffortRemoveWorktreeDir(self, dir) {
|
|
62918
|
-
if (!dir || !
|
|
62919
|
-
const sleep3 = (ms) => new Promise((
|
|
63070
|
+
if (!dir || !fs34.existsSync(dir)) return { removed: true, residue: false };
|
|
63071
|
+
const sleep3 = (ms) => new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
62920
63072
|
const ABSORB = /* @__PURE__ */ new Set(["EINVAL", "EPERM", "EBUSY", "ENOTEMPTY", "EACCES", "EMFILE", "ENFILE"]);
|
|
62921
63073
|
let lastErr;
|
|
62922
63074
|
for (let attempt = 0; attempt < 4; attempt++) {
|
|
62923
63075
|
try {
|
|
62924
|
-
|
|
62925
|
-
if (!
|
|
63076
|
+
fs34.rmSync(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
63077
|
+
if (!fs34.existsSync(dir)) return { removed: true, residue: false };
|
|
62926
63078
|
lastErr = new Error("directory still present after rmSync");
|
|
62927
63079
|
} catch (e) {
|
|
62928
63080
|
lastErr = e;
|
|
@@ -62933,7 +63085,7 @@ async function bestEffortRemoveWorktreeDir(self, dir) {
|
|
|
62933
63085
|
}
|
|
62934
63086
|
await sleep3(150 * (attempt + 1));
|
|
62935
63087
|
}
|
|
62936
|
-
return
|
|
63088
|
+
return fs34.existsSync(dir) ? { removed: false, residue: true, error: String(lastErr?.message || lastErr || "unknown rm error") } : { removed: true, residue: false };
|
|
62937
63089
|
}
|
|
62938
63090
|
async function precheckLocalWorktreeRemovable(self, args) {
|
|
62939
63091
|
const sessionPreservedNote = " The delegated session was left running (not stopped) \u2014 resolve the issue and retry mesh_remove_node.";
|
|
@@ -62946,10 +63098,10 @@ async function precheckLocalWorktreeRemovable(self, args) {
|
|
|
62946
63098
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains." + sessionPreservedNote
|
|
62947
63099
|
};
|
|
62948
63100
|
}
|
|
62949
|
-
if (!
|
|
63101
|
+
if (!fs34.existsSync(workspace)) return { ok: true };
|
|
62950
63102
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
62951
63103
|
const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
|
|
62952
|
-
if (!repoRoot || !
|
|
63104
|
+
if (!repoRoot || !fs34.existsSync(repoRoot)) {
|
|
62953
63105
|
return {
|
|
62954
63106
|
ok: false,
|
|
62955
63107
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -62969,7 +63121,7 @@ async function precheckLocalWorktreeRemovable(self, args) {
|
|
|
62969
63121
|
const normalizePath = (value) => {
|
|
62970
63122
|
const resolved = (0, import_path15.resolve)(value);
|
|
62971
63123
|
try {
|
|
62972
|
-
return
|
|
63124
|
+
return fs34.realpathSync(resolved);
|
|
62973
63125
|
} catch {
|
|
62974
63126
|
return resolved;
|
|
62975
63127
|
}
|
|
@@ -63031,13 +63183,13 @@ async function cleanupLocalWorktreeNode(self, args) {
|
|
|
63031
63183
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains."
|
|
63032
63184
|
};
|
|
63033
63185
|
}
|
|
63034
|
-
const worktreeExists =
|
|
63186
|
+
const worktreeExists = fs34.existsSync(workspace);
|
|
63035
63187
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
63036
63188
|
const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
|
|
63037
63189
|
if (!worktreeExists) {
|
|
63038
63190
|
return { success: true, skipped: true, removedPath: workspace, repoRoot: repoRoot || void 0, reason: "worktree_path_missing" };
|
|
63039
63191
|
}
|
|
63040
|
-
if (!repoRoot || !
|
|
63192
|
+
if (!repoRoot || !fs34.existsSync(repoRoot)) {
|
|
63041
63193
|
return {
|
|
63042
63194
|
success: false,
|
|
63043
63195
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -63057,7 +63209,7 @@ async function cleanupLocalWorktreeNode(self, args) {
|
|
|
63057
63209
|
const normalizePath = (value) => {
|
|
63058
63210
|
const resolved = (0, import_path15.resolve)(value);
|
|
63059
63211
|
try {
|
|
63060
|
-
return
|
|
63212
|
+
return fs34.realpathSync(resolved);
|
|
63061
63213
|
} catch {
|
|
63062
63214
|
return resolved;
|
|
63063
63215
|
}
|
|
@@ -63696,7 +63848,7 @@ init_logger();
|
|
|
63696
63848
|
var yaml5 = __toESM(require("js-yaml"));
|
|
63697
63849
|
var import_os4 = require("os");
|
|
63698
63850
|
var import_path16 = require("path");
|
|
63699
|
-
var
|
|
63851
|
+
var fs35 = __toESM(require("fs"));
|
|
63700
63852
|
function loadYamlModule() {
|
|
63701
63853
|
return yaml5;
|
|
63702
63854
|
}
|
|
@@ -63720,9 +63872,9 @@ function resolveHermesUserHome() {
|
|
|
63720
63872
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
63721
63873
|
const sourceHome = resolveHermesUserHome();
|
|
63722
63874
|
const sourceConfigPath = (0, import_path16.join)(sourceHome, "config.yaml");
|
|
63723
|
-
if (!
|
|
63875
|
+
if (!fs35.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
63724
63876
|
if ((0, import_path16.resolve)(sourceConfigPath) === (0, import_path16.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
63725
|
-
const parsed = parseMeshCoordinatorMcpConfig(
|
|
63877
|
+
const parsed = parseMeshCoordinatorMcpConfig(fs35.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
63726
63878
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
63727
63879
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
63728
63880
|
}
|
|
@@ -63759,9 +63911,9 @@ function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
|
63759
63911
|
for (const fileName of [".env", "auth.json"]) {
|
|
63760
63912
|
const sourcePath = (0, import_path16.join)(sourceHome, fileName);
|
|
63761
63913
|
const targetPath = (0, import_path16.join)(targetHome, fileName);
|
|
63762
|
-
if (!
|
|
63914
|
+
if (!fs35.existsSync(sourcePath)) continue;
|
|
63763
63915
|
try {
|
|
63764
|
-
|
|
63916
|
+
fs35.copyFileSync(sourcePath, targetPath);
|
|
63765
63917
|
} catch (error) {
|
|
63766
63918
|
LOG.warn("MeshCoordinator", `Could not copy Hermes ${fileName} into isolated coordinator home: ${error?.message || error}`);
|
|
63767
63919
|
}
|
|
@@ -64162,7 +64314,7 @@ var DaemonCommandRouter = class {
|
|
|
64162
64314
|
const nodeId = readInlineMeshNodeId(node);
|
|
64163
64315
|
if (!nodeId || !tombstones.has(nodeId)) return true;
|
|
64164
64316
|
const workspace = readStringValue(node?.workspace);
|
|
64165
|
-
if (workspace &&
|
|
64317
|
+
if (workspace && fs36.existsSync(workspace)) {
|
|
64166
64318
|
tombstones.delete(nodeId);
|
|
64167
64319
|
return true;
|
|
64168
64320
|
}
|
|
@@ -64975,7 +65127,7 @@ var ProviderStreamAdapter = class {
|
|
|
64975
65127
|
const beforeCount = this.messageCount(before);
|
|
64976
65128
|
const beforeSignature = this.lastMessageSignature(before);
|
|
64977
65129
|
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
64978
|
-
await new Promise((
|
|
65130
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
64979
65131
|
let state;
|
|
64980
65132
|
try {
|
|
64981
65133
|
state = await this.readChat(evaluate);
|
|
@@ -64997,7 +65149,7 @@ var ProviderStreamAdapter = class {
|
|
|
64997
65149
|
if (this.messageCount(first) > 0 || this.lastMessageSignature(first)) {
|
|
64998
65150
|
return first;
|
|
64999
65151
|
}
|
|
65000
|
-
await new Promise((
|
|
65152
|
+
await new Promise((resolve26) => setTimeout(resolve26, 150));
|
|
65001
65153
|
const second = await this.readChat(evaluate);
|
|
65002
65154
|
return this.messageCount(second) >= this.messageCount(first) ? second : first;
|
|
65003
65155
|
}
|
|
@@ -65148,7 +65300,7 @@ var ProviderStreamAdapter = class {
|
|
|
65148
65300
|
if (typeof data.error === "string" && data.error.trim()) return false;
|
|
65149
65301
|
}
|
|
65150
65302
|
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
65151
|
-
await new Promise((
|
|
65303
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
65152
65304
|
const state = await this.readChat(evaluate);
|
|
65153
65305
|
const title = this.getStateTitle(state);
|
|
65154
65306
|
if (this.titlesMatch(title, sessionId)) return true;
|
|
@@ -66081,7 +66233,7 @@ init_io_contracts();
|
|
|
66081
66233
|
init_chat_message_normalization();
|
|
66082
66234
|
|
|
66083
66235
|
// src/providers/version-archive.ts
|
|
66084
|
-
var
|
|
66236
|
+
var fs37 = __toESM(require("fs"));
|
|
66085
66237
|
var path39 = __toESM(require("path"));
|
|
66086
66238
|
var os29 = __toESM(require("os"));
|
|
66087
66239
|
var import_os5 = require("os");
|
|
@@ -66095,8 +66247,8 @@ var VersionArchive = class {
|
|
|
66095
66247
|
}
|
|
66096
66248
|
load() {
|
|
66097
66249
|
try {
|
|
66098
|
-
if (
|
|
66099
|
-
this.history = JSON.parse(
|
|
66250
|
+
if (fs37.existsSync(ARCHIVE_PATH)) {
|
|
66251
|
+
this.history = JSON.parse(fs37.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
66100
66252
|
}
|
|
66101
66253
|
} catch {
|
|
66102
66254
|
this.history = {};
|
|
@@ -66133,20 +66285,20 @@ var VersionArchive = class {
|
|
|
66133
66285
|
}
|
|
66134
66286
|
save() {
|
|
66135
66287
|
try {
|
|
66136
|
-
|
|
66137
|
-
|
|
66288
|
+
fs37.mkdirSync(path39.dirname(ARCHIVE_PATH), { recursive: true });
|
|
66289
|
+
fs37.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
66138
66290
|
} catch {
|
|
66139
66291
|
}
|
|
66140
66292
|
}
|
|
66141
66293
|
};
|
|
66142
66294
|
async function runCommand(cmd, timeout = 1e4) {
|
|
66143
|
-
return new Promise((
|
|
66295
|
+
return new Promise((resolve26) => {
|
|
66144
66296
|
(0, import_child_process10.exec)(cmd, {
|
|
66145
66297
|
encoding: "utf-8",
|
|
66146
66298
|
timeout
|
|
66147
66299
|
}, (error, stdout) => {
|
|
66148
|
-
if (error) return
|
|
66149
|
-
|
|
66300
|
+
if (error) return resolve26(null);
|
|
66301
|
+
resolve26(stdout.trim());
|
|
66150
66302
|
});
|
|
66151
66303
|
});
|
|
66152
66304
|
}
|
|
@@ -66159,8 +66311,8 @@ function findBinary2(name) {
|
|
|
66159
66311
|
for (const ext of exes) {
|
|
66160
66312
|
const fullPath = path39.join(p, name + ext);
|
|
66161
66313
|
try {
|
|
66162
|
-
if (
|
|
66163
|
-
const stat2 =
|
|
66314
|
+
if (fs37.existsSync(fullPath)) {
|
|
66315
|
+
const stat2 = fs37.statSync(fullPath);
|
|
66164
66316
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
66165
66317
|
return fullPath;
|
|
66166
66318
|
}
|
|
@@ -66207,9 +66359,9 @@ function checkPathExists2(paths) {
|
|
|
66207
66359
|
if (p.includes("*")) {
|
|
66208
66360
|
const home = os29.homedir();
|
|
66209
66361
|
const resolved = p.replace(/\*/g, home.split(path39.sep).pop() || "");
|
|
66210
|
-
if (
|
|
66362
|
+
if (fs37.existsSync(resolved)) return resolved;
|
|
66211
66363
|
} else {
|
|
66212
|
-
if (
|
|
66364
|
+
if (fs37.existsSync(p)) return p;
|
|
66213
66365
|
}
|
|
66214
66366
|
}
|
|
66215
66367
|
return null;
|
|
@@ -66217,7 +66369,7 @@ function checkPathExists2(paths) {
|
|
|
66217
66369
|
async function getMacAppVersion(appPath) {
|
|
66218
66370
|
if ((0, import_os5.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
66219
66371
|
const plistPath = path39.join(appPath, "Contents", "Info.plist");
|
|
66220
|
-
if (!
|
|
66372
|
+
if (!fs37.existsSync(plistPath)) return null;
|
|
66221
66373
|
const raw = await runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
66222
66374
|
return raw || null;
|
|
66223
66375
|
}
|
|
@@ -66244,7 +66396,7 @@ async function detectAllVersions(loader, archive) {
|
|
|
66244
66396
|
let resolvedBin = cliBin;
|
|
66245
66397
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
66246
66398
|
const bundled = path39.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
66247
|
-
if (provider.cli &&
|
|
66399
|
+
if (provider.cli && fs37.existsSync(bundled)) resolvedBin = bundled;
|
|
66248
66400
|
}
|
|
66249
66401
|
info.installed = !!(appPath || resolvedBin);
|
|
66250
66402
|
info.path = appPath || null;
|
|
@@ -66292,7 +66444,7 @@ async function detectAllVersions(loader, archive) {
|
|
|
66292
66444
|
|
|
66293
66445
|
// src/daemon/dev-server.ts
|
|
66294
66446
|
var http2 = __toESM(require("http"));
|
|
66295
|
-
var
|
|
66447
|
+
var fs41 = __toESM(require("fs"));
|
|
66296
66448
|
var path43 = __toESM(require("path"));
|
|
66297
66449
|
init_config();
|
|
66298
66450
|
|
|
@@ -66644,7 +66796,7 @@ init_logger();
|
|
|
66644
66796
|
init_builders();
|
|
66645
66797
|
|
|
66646
66798
|
// src/daemon/dev-cdp-handlers.ts
|
|
66647
|
-
var
|
|
66799
|
+
var fs38 = __toESM(require("fs"));
|
|
66648
66800
|
var path40 = __toESM(require("path"));
|
|
66649
66801
|
init_logger();
|
|
66650
66802
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
@@ -66825,17 +66977,17 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
66825
66977
|
}
|
|
66826
66978
|
let scriptsPath = "";
|
|
66827
66979
|
const directScripts = path40.join(dir, "scripts.js");
|
|
66828
|
-
if (
|
|
66980
|
+
if (fs38.existsSync(directScripts)) {
|
|
66829
66981
|
scriptsPath = directScripts;
|
|
66830
66982
|
} else {
|
|
66831
66983
|
const scriptsDir = path40.join(dir, "scripts");
|
|
66832
|
-
if (
|
|
66833
|
-
const versions =
|
|
66834
|
-
return
|
|
66984
|
+
if (fs38.existsSync(scriptsDir)) {
|
|
66985
|
+
const versions = fs38.readdirSync(scriptsDir).filter((d) => {
|
|
66986
|
+
return fs38.statSync(path40.join(scriptsDir, d)).isDirectory();
|
|
66835
66987
|
}).sort().reverse();
|
|
66836
66988
|
for (const ver of versions) {
|
|
66837
66989
|
const p = path40.join(scriptsDir, ver, "scripts.js");
|
|
66838
|
-
if (
|
|
66990
|
+
if (fs38.existsSync(p)) {
|
|
66839
66991
|
scriptsPath = p;
|
|
66840
66992
|
break;
|
|
66841
66993
|
}
|
|
@@ -66847,7 +66999,7 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
66847
66999
|
return;
|
|
66848
67000
|
}
|
|
66849
67001
|
try {
|
|
66850
|
-
const source =
|
|
67002
|
+
const source = fs38.readFileSync(scriptsPath, "utf-8");
|
|
66851
67003
|
const hints = {};
|
|
66852
67004
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
66853
67005
|
let match;
|
|
@@ -67662,7 +67814,7 @@ async function handleDomContext(ctx, type, req, res) {
|
|
|
67662
67814
|
}
|
|
67663
67815
|
|
|
67664
67816
|
// src/daemon/dev-cli-debug.ts
|
|
67665
|
-
var
|
|
67817
|
+
var fs39 = __toESM(require("fs"));
|
|
67666
67818
|
var path41 = __toESM(require("path"));
|
|
67667
67819
|
function slugifyFixtureName(value) {
|
|
67668
67820
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -67678,10 +67830,10 @@ function getCliFixtureDir(ctx, type) {
|
|
|
67678
67830
|
function readCliFixture(ctx, type, name) {
|
|
67679
67831
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
67680
67832
|
const filePath = path41.join(fixtureDir, `${name}.json`);
|
|
67681
|
-
if (!
|
|
67833
|
+
if (!fs39.existsSync(filePath)) {
|
|
67682
67834
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
67683
67835
|
}
|
|
67684
|
-
return JSON.parse(
|
|
67836
|
+
return JSON.parse(fs39.readFileSync(filePath, "utf-8"));
|
|
67685
67837
|
}
|
|
67686
67838
|
function getExerciseTranscriptText(result) {
|
|
67687
67839
|
const parts = [];
|
|
@@ -67846,7 +67998,7 @@ function getCliTargetBundle(ctx, type, instanceId) {
|
|
|
67846
67998
|
return { target, instance, adapter };
|
|
67847
67999
|
}
|
|
67848
68000
|
function sleep2(ms) {
|
|
67849
|
-
return new Promise((
|
|
68001
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
67850
68002
|
}
|
|
67851
68003
|
async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
|
|
67852
68004
|
const startedAt = Date.now();
|
|
@@ -68426,7 +68578,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68426
68578
|
return;
|
|
68427
68579
|
}
|
|
68428
68580
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
68429
|
-
|
|
68581
|
+
fs39.mkdirSync(fixtureDir, { recursive: true });
|
|
68430
68582
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
68431
68583
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
68432
68584
|
const fixture = {
|
|
@@ -68454,7 +68606,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68454
68606
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
68455
68607
|
};
|
|
68456
68608
|
const filePath = path41.join(fixtureDir, `${name}.json`);
|
|
68457
|
-
|
|
68609
|
+
fs39.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
68458
68610
|
ctx.json(res, 200, {
|
|
68459
68611
|
saved: true,
|
|
68460
68612
|
name,
|
|
@@ -68472,14 +68624,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68472
68624
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
68473
68625
|
try {
|
|
68474
68626
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
68475
|
-
if (!
|
|
68627
|
+
if (!fs39.existsSync(fixtureDir)) {
|
|
68476
68628
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
68477
68629
|
return;
|
|
68478
68630
|
}
|
|
68479
|
-
const fixtures =
|
|
68631
|
+
const fixtures = fs39.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
|
|
68480
68632
|
const fullPath = path41.join(fixtureDir, file);
|
|
68481
68633
|
try {
|
|
68482
|
-
const raw = JSON.parse(
|
|
68634
|
+
const raw = JSON.parse(fs39.readFileSync(fullPath, "utf-8"));
|
|
68483
68635
|
return {
|
|
68484
68636
|
name: raw.name || file.replace(/\.json$/i, ""),
|
|
68485
68637
|
path: fullPath,
|
|
@@ -68612,7 +68764,7 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
68612
68764
|
}
|
|
68613
68765
|
|
|
68614
68766
|
// src/daemon/dev-auto-implement.ts
|
|
68615
|
-
var
|
|
68767
|
+
var fs40 = __toESM(require("fs"));
|
|
68616
68768
|
var path42 = __toESM(require("path"));
|
|
68617
68769
|
var os30 = __toESM(require("os"));
|
|
68618
68770
|
var import_session_host_core9 = require("@adhdev/session-host-core");
|
|
@@ -68661,10 +68813,10 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
|
|
|
68661
68813
|
return fallback?.type || null;
|
|
68662
68814
|
}
|
|
68663
68815
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
68664
|
-
if (!
|
|
68665
|
-
const versions =
|
|
68816
|
+
if (!fs40.existsSync(scriptsDir)) return null;
|
|
68817
|
+
const versions = fs40.readdirSync(scriptsDir).filter((d) => {
|
|
68666
68818
|
try {
|
|
68667
|
-
return
|
|
68819
|
+
return fs40.statSync(path42.join(scriptsDir, d)).isDirectory();
|
|
68668
68820
|
} catch {
|
|
68669
68821
|
return false;
|
|
68670
68822
|
}
|
|
@@ -68686,13 +68838,13 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
68686
68838
|
if (!sourceDir) {
|
|
68687
68839
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
68688
68840
|
}
|
|
68689
|
-
if (!
|
|
68690
|
-
|
|
68691
|
-
|
|
68841
|
+
if (!fs40.existsSync(desiredDir)) {
|
|
68842
|
+
fs40.mkdirSync(path42.dirname(desiredDir), { recursive: true });
|
|
68843
|
+
fs40.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
68692
68844
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
68693
68845
|
}
|
|
68694
68846
|
const providerJson = path42.join(desiredDir, "provider.json");
|
|
68695
|
-
if (!
|
|
68847
|
+
if (!fs40.existsSync(providerJson)) {
|
|
68696
68848
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
68697
68849
|
}
|
|
68698
68850
|
return { dir: desiredDir };
|
|
@@ -68700,15 +68852,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
68700
68852
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
68701
68853
|
if (!referenceType) return {};
|
|
68702
68854
|
const refDir = ctx.findProviderDir(referenceType);
|
|
68703
|
-
if (!refDir || !
|
|
68855
|
+
if (!refDir || !fs40.existsSync(refDir)) return {};
|
|
68704
68856
|
const referenceScripts = {};
|
|
68705
68857
|
const scriptsDir = path42.join(refDir, "scripts");
|
|
68706
68858
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
68707
68859
|
if (!latestDir) return referenceScripts;
|
|
68708
|
-
for (const file of
|
|
68860
|
+
for (const file of fs40.readdirSync(latestDir)) {
|
|
68709
68861
|
if (!file.endsWith(".js")) continue;
|
|
68710
68862
|
try {
|
|
68711
|
-
referenceScripts[file] =
|
|
68863
|
+
referenceScripts[file] = fs40.readFileSync(path42.join(latestDir, file), "utf-8");
|
|
68712
68864
|
} catch {
|
|
68713
68865
|
}
|
|
68714
68866
|
}
|
|
@@ -68817,15 +68969,15 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
68817
68969
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
68818
68970
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
68819
68971
|
const tmpDir = path42.join(os30.tmpdir(), "adhdev-autoimpl");
|
|
68820
|
-
if (!
|
|
68972
|
+
if (!fs40.existsSync(tmpDir)) fs40.mkdirSync(tmpDir, { recursive: true });
|
|
68821
68973
|
const promptFile = path42.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
68822
|
-
|
|
68974
|
+
fs40.writeFileSync(promptFile, prompt, "utf-8");
|
|
68823
68975
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
68824
68976
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
68825
68977
|
const spawn5 = agentProvider?.spawn;
|
|
68826
68978
|
if (!spawn5?.command) {
|
|
68827
68979
|
try {
|
|
68828
|
-
|
|
68980
|
+
fs40.unlinkSync(promptFile);
|
|
68829
68981
|
} catch {
|
|
68830
68982
|
}
|
|
68831
68983
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -68927,7 +69079,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
68927
69079
|
} catch {
|
|
68928
69080
|
}
|
|
68929
69081
|
try {
|
|
68930
|
-
|
|
69082
|
+
fs40.unlinkSync(promptFile);
|
|
68931
69083
|
} catch {
|
|
68932
69084
|
}
|
|
68933
69085
|
ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -69153,7 +69305,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
69153
69305
|
}
|
|
69154
69306
|
});
|
|
69155
69307
|
try {
|
|
69156
|
-
|
|
69308
|
+
fs40.unlinkSync(promptFile);
|
|
69157
69309
|
} catch {
|
|
69158
69310
|
}
|
|
69159
69311
|
ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -69258,10 +69410,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
69258
69410
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
69259
69411
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
69260
69412
|
lines.push("");
|
|
69261
|
-
for (const file of
|
|
69413
|
+
for (const file of fs40.readdirSync(latestScriptsDir)) {
|
|
69262
69414
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
69263
69415
|
try {
|
|
69264
|
-
const content =
|
|
69416
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69265
69417
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
69266
69418
|
lines.push("```javascript");
|
|
69267
69419
|
lines.push(content);
|
|
@@ -69271,14 +69423,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
69271
69423
|
}
|
|
69272
69424
|
}
|
|
69273
69425
|
}
|
|
69274
|
-
const refFiles =
|
|
69426
|
+
const refFiles = fs40.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
69275
69427
|
if (refFiles.length > 0) {
|
|
69276
69428
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
69277
69429
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
69278
69430
|
lines.push("");
|
|
69279
69431
|
for (const file of refFiles) {
|
|
69280
69432
|
try {
|
|
69281
|
-
const content =
|
|
69433
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69282
69434
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
69283
69435
|
lines.push("```javascript");
|
|
69284
69436
|
lines.push(content);
|
|
@@ -69323,7 +69475,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
69323
69475
|
const loadGuide = (name) => {
|
|
69324
69476
|
try {
|
|
69325
69477
|
const p = path42.join(docsDir, name);
|
|
69326
|
-
if (
|
|
69478
|
+
if (fs40.existsSync(p)) return fs40.readFileSync(p, "utf-8");
|
|
69327
69479
|
} catch {
|
|
69328
69480
|
}
|
|
69329
69481
|
return null;
|
|
@@ -69567,11 +69719,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69567
69719
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
69568
69720
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
69569
69721
|
lines.push("");
|
|
69570
|
-
for (const file of
|
|
69722
|
+
for (const file of fs40.readdirSync(latestScriptsDir)) {
|
|
69571
69723
|
if (!file.endsWith(".js")) continue;
|
|
69572
69724
|
if (!targetFileNames.has(file)) continue;
|
|
69573
69725
|
try {
|
|
69574
|
-
const content =
|
|
69726
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69575
69727
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
69576
69728
|
lines.push("```javascript");
|
|
69577
69729
|
lines.push(content);
|
|
@@ -69580,14 +69732,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69580
69732
|
} catch {
|
|
69581
69733
|
}
|
|
69582
69734
|
}
|
|
69583
|
-
const refFiles =
|
|
69735
|
+
const refFiles = fs40.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
69584
69736
|
if (refFiles.length > 0) {
|
|
69585
69737
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
69586
69738
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
69587
69739
|
lines.push("");
|
|
69588
69740
|
for (const file of refFiles) {
|
|
69589
69741
|
try {
|
|
69590
|
-
const content =
|
|
69742
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69591
69743
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
69592
69744
|
lines.push("```javascript");
|
|
69593
69745
|
lines.push(content);
|
|
@@ -69624,7 +69776,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69624
69776
|
const loadGuide = (name) => {
|
|
69625
69777
|
try {
|
|
69626
69778
|
const p = path42.join(docsDir, name);
|
|
69627
|
-
if (
|
|
69779
|
+
if (fs40.existsSync(p)) return fs40.readFileSync(p, "utf-8");
|
|
69628
69780
|
} catch {
|
|
69629
69781
|
}
|
|
69630
69782
|
return null;
|
|
@@ -70102,15 +70254,15 @@ var DevServer = class _DevServer {
|
|
|
70102
70254
|
this.json(res, 500, { error: e.message });
|
|
70103
70255
|
}
|
|
70104
70256
|
});
|
|
70105
|
-
return new Promise((
|
|
70257
|
+
return new Promise((resolve26, reject) => {
|
|
70106
70258
|
this.server.listen(port, "127.0.0.1", () => {
|
|
70107
70259
|
this.log(`Dev server listening on http://127.0.0.1:${port}`);
|
|
70108
|
-
|
|
70260
|
+
resolve26();
|
|
70109
70261
|
});
|
|
70110
70262
|
this.server.on("error", (e) => {
|
|
70111
70263
|
if (e.code === "EADDRINUSE") {
|
|
70112
70264
|
this.log(`Port ${port} in use, skipping dev server`);
|
|
70113
|
-
|
|
70265
|
+
resolve26();
|
|
70114
70266
|
} else {
|
|
70115
70267
|
reject(e);
|
|
70116
70268
|
}
|
|
@@ -70192,20 +70344,20 @@ var DevServer = class _DevServer {
|
|
|
70192
70344
|
child.stderr?.on("data", (d) => {
|
|
70193
70345
|
stderr += d.toString().slice(0, 2e3);
|
|
70194
70346
|
});
|
|
70195
|
-
await new Promise((
|
|
70347
|
+
await new Promise((resolve26) => {
|
|
70196
70348
|
const timer = setTimeout(() => {
|
|
70197
70349
|
child.kill();
|
|
70198
|
-
|
|
70350
|
+
resolve26();
|
|
70199
70351
|
}, 3e3);
|
|
70200
70352
|
child.on("exit", () => {
|
|
70201
70353
|
clearTimeout(timer);
|
|
70202
|
-
|
|
70354
|
+
resolve26();
|
|
70203
70355
|
});
|
|
70204
70356
|
child.stdout?.once("data", () => {
|
|
70205
70357
|
setTimeout(() => {
|
|
70206
70358
|
child.kill();
|
|
70207
70359
|
clearTimeout(timer);
|
|
70208
|
-
|
|
70360
|
+
resolve26();
|
|
70209
70361
|
}, 500);
|
|
70210
70362
|
});
|
|
70211
70363
|
});
|
|
@@ -70364,7 +70516,7 @@ var DevServer = class _DevServer {
|
|
|
70364
70516
|
path43.join(process.cwd(), "packages/web-devconsole/dist")
|
|
70365
70517
|
];
|
|
70366
70518
|
for (const dir of candidates) {
|
|
70367
|
-
if (
|
|
70519
|
+
if (fs41.existsSync(path43.join(dir, "index.html"))) return dir;
|
|
70368
70520
|
}
|
|
70369
70521
|
return null;
|
|
70370
70522
|
}
|
|
@@ -70376,7 +70528,7 @@ var DevServer = class _DevServer {
|
|
|
70376
70528
|
}
|
|
70377
70529
|
const htmlPath = path43.join(distDir, "index.html");
|
|
70378
70530
|
try {
|
|
70379
|
-
const html =
|
|
70531
|
+
const html = fs41.readFileSync(htmlPath, "utf-8");
|
|
70380
70532
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
70381
70533
|
res.end(html);
|
|
70382
70534
|
} catch (e) {
|
|
@@ -70406,7 +70558,7 @@ var DevServer = class _DevServer {
|
|
|
70406
70558
|
return;
|
|
70407
70559
|
}
|
|
70408
70560
|
try {
|
|
70409
|
-
const content =
|
|
70561
|
+
const content = fs41.readFileSync(filePath);
|
|
70410
70562
|
const ext = path43.extname(filePath);
|
|
70411
70563
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
70412
70564
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
@@ -70515,14 +70667,14 @@ var DevServer = class _DevServer {
|
|
|
70515
70667
|
const files = [];
|
|
70516
70668
|
const scan = (d, prefix) => {
|
|
70517
70669
|
try {
|
|
70518
|
-
for (const entry of
|
|
70670
|
+
for (const entry of fs41.readdirSync(d, { withFileTypes: true })) {
|
|
70519
70671
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
70520
70672
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
70521
70673
|
if (entry.isDirectory()) {
|
|
70522
70674
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
70523
70675
|
scan(path43.join(d, entry.name), rel);
|
|
70524
70676
|
} else {
|
|
70525
|
-
const stat2 =
|
|
70677
|
+
const stat2 = fs41.statSync(path43.join(d, entry.name));
|
|
70526
70678
|
files.push({ path: rel, size: stat2.size, type: "file" });
|
|
70527
70679
|
}
|
|
70528
70680
|
}
|
|
@@ -70550,11 +70702,11 @@ var DevServer = class _DevServer {
|
|
|
70550
70702
|
this.json(res, 403, { error: "Forbidden" });
|
|
70551
70703
|
return;
|
|
70552
70704
|
}
|
|
70553
|
-
if (!
|
|
70705
|
+
if (!fs41.existsSync(fullPath) || fs41.statSync(fullPath).isDirectory()) {
|
|
70554
70706
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
70555
70707
|
return;
|
|
70556
70708
|
}
|
|
70557
|
-
const content =
|
|
70709
|
+
const content = fs41.readFileSync(fullPath, "utf-8");
|
|
70558
70710
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
70559
70711
|
}
|
|
70560
70712
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -70576,9 +70728,9 @@ var DevServer = class _DevServer {
|
|
|
70576
70728
|
return;
|
|
70577
70729
|
}
|
|
70578
70730
|
try {
|
|
70579
|
-
if (
|
|
70580
|
-
|
|
70581
|
-
|
|
70731
|
+
if (fs41.existsSync(fullPath)) fs41.copyFileSync(fullPath, fullPath + ".bak");
|
|
70732
|
+
fs41.mkdirSync(path43.dirname(fullPath), { recursive: true });
|
|
70733
|
+
fs41.writeFileSync(fullPath, content, "utf-8");
|
|
70582
70734
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
70583
70735
|
this.providerLoader.reload();
|
|
70584
70736
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -70595,8 +70747,8 @@ var DevServer = class _DevServer {
|
|
|
70595
70747
|
}
|
|
70596
70748
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
70597
70749
|
const p = path43.join(dir, name);
|
|
70598
|
-
if (
|
|
70599
|
-
const source =
|
|
70750
|
+
if (fs41.existsSync(p)) {
|
|
70751
|
+
const source = fs41.readFileSync(p, "utf-8");
|
|
70600
70752
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
70601
70753
|
return;
|
|
70602
70754
|
}
|
|
@@ -70615,11 +70767,11 @@ var DevServer = class _DevServer {
|
|
|
70615
70767
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
70616
70768
|
return;
|
|
70617
70769
|
}
|
|
70618
|
-
const target =
|
|
70770
|
+
const target = fs41.existsSync(path43.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
70619
70771
|
const targetPath = path43.join(dir, target);
|
|
70620
70772
|
try {
|
|
70621
|
-
if (
|
|
70622
|
-
|
|
70773
|
+
if (fs41.existsSync(targetPath)) fs41.copyFileSync(targetPath, targetPath + ".bak");
|
|
70774
|
+
fs41.writeFileSync(targetPath, source, "utf-8");
|
|
70623
70775
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
70624
70776
|
this.providerLoader.reload();
|
|
70625
70777
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -70708,14 +70860,14 @@ var DevServer = class _DevServer {
|
|
|
70708
70860
|
child.stderr?.on("data", (d) => {
|
|
70709
70861
|
stderr += d.toString();
|
|
70710
70862
|
});
|
|
70711
|
-
await new Promise((
|
|
70863
|
+
await new Promise((resolve26) => {
|
|
70712
70864
|
const timer = setTimeout(() => {
|
|
70713
70865
|
child.kill();
|
|
70714
|
-
|
|
70866
|
+
resolve26();
|
|
70715
70867
|
}, timeout);
|
|
70716
70868
|
child.on("exit", () => {
|
|
70717
70869
|
clearTimeout(timer);
|
|
70718
|
-
|
|
70870
|
+
resolve26();
|
|
70719
70871
|
});
|
|
70720
70872
|
});
|
|
70721
70873
|
const elapsed = Date.now() - start;
|
|
@@ -70764,20 +70916,20 @@ var DevServer = class _DevServer {
|
|
|
70764
70916
|
let targetDir;
|
|
70765
70917
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
70766
70918
|
const jsonPath = path43.join(targetDir, "provider.json");
|
|
70767
|
-
if (
|
|
70919
|
+
if (fs41.existsSync(jsonPath)) {
|
|
70768
70920
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
70769
70921
|
return;
|
|
70770
70922
|
}
|
|
70771
70923
|
try {
|
|
70772
70924
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
|
|
70773
|
-
|
|
70774
|
-
|
|
70925
|
+
fs41.mkdirSync(targetDir, { recursive: true });
|
|
70926
|
+
fs41.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
70775
70927
|
const createdFiles = ["provider.json"];
|
|
70776
70928
|
if (result.files) {
|
|
70777
70929
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
70778
70930
|
const fullPath = path43.join(targetDir, relPath);
|
|
70779
|
-
|
|
70780
|
-
|
|
70931
|
+
fs41.mkdirSync(path43.dirname(fullPath), { recursive: true });
|
|
70932
|
+
fs41.writeFileSync(fullPath, content, "utf-8");
|
|
70781
70933
|
createdFiles.push(relPath);
|
|
70782
70934
|
}
|
|
70783
70935
|
}
|
|
@@ -70826,10 +70978,10 @@ var DevServer = class _DevServer {
|
|
|
70826
70978
|
}
|
|
70827
70979
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
70828
70980
|
getLatestScriptVersionDir(scriptsDir) {
|
|
70829
|
-
if (!
|
|
70830
|
-
const versions =
|
|
70981
|
+
if (!fs41.existsSync(scriptsDir)) return null;
|
|
70982
|
+
const versions = fs41.readdirSync(scriptsDir).filter((d) => {
|
|
70831
70983
|
try {
|
|
70832
|
-
return
|
|
70984
|
+
return fs41.statSync(path43.join(scriptsDir, d)).isDirectory();
|
|
70833
70985
|
} catch {
|
|
70834
70986
|
return false;
|
|
70835
70987
|
}
|
|
@@ -70851,13 +71003,13 @@ var DevServer = class _DevServer {
|
|
|
70851
71003
|
if (!sourceDir) {
|
|
70852
71004
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
70853
71005
|
}
|
|
70854
|
-
if (!
|
|
70855
|
-
|
|
70856
|
-
|
|
71006
|
+
if (!fs41.existsSync(desiredDir)) {
|
|
71007
|
+
fs41.mkdirSync(path43.dirname(desiredDir), { recursive: true });
|
|
71008
|
+
fs41.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
70857
71009
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
70858
71010
|
}
|
|
70859
71011
|
const providerJson = path43.join(desiredDir, "provider.json");
|
|
70860
|
-
if (!
|
|
71012
|
+
if (!fs41.existsSync(providerJson)) {
|
|
70861
71013
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
70862
71014
|
}
|
|
70863
71015
|
return { dir: desiredDir };
|
|
@@ -70914,14 +71066,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
70914
71066
|
res.end(JSON.stringify(data, null, 2));
|
|
70915
71067
|
}
|
|
70916
71068
|
async readBody(req) {
|
|
70917
|
-
return new Promise((
|
|
71069
|
+
return new Promise((resolve26) => {
|
|
70918
71070
|
let body = "";
|
|
70919
71071
|
req.on("data", (chunk) => body += chunk);
|
|
70920
71072
|
req.on("end", () => {
|
|
70921
71073
|
try {
|
|
70922
|
-
|
|
71074
|
+
resolve26(JSON.parse(body));
|
|
70923
71075
|
} catch {
|
|
70924
|
-
|
|
71076
|
+
resolve26({});
|
|
70925
71077
|
}
|
|
70926
71078
|
});
|
|
70927
71079
|
});
|
|
@@ -71656,7 +71808,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRe
|
|
|
71656
71808
|
const deadline = Date.now() + timeoutMs;
|
|
71657
71809
|
while (Date.now() < deadline) {
|
|
71658
71810
|
if (await canConnect(endpoint, requiredRequestTypes)) return;
|
|
71659
|
-
await new Promise((
|
|
71811
|
+
await new Promise((resolve26) => setTimeout(resolve26, STARTUP_POLL_MS));
|
|
71660
71812
|
}
|
|
71661
71813
|
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
71662
71814
|
}
|
|
@@ -71699,7 +71851,7 @@ async function listHostedCliRuntimes(endpoint) {
|
|
|
71699
71851
|
|
|
71700
71852
|
// src/session-host/managed-host.ts
|
|
71701
71853
|
var import_child_process11 = require("child_process");
|
|
71702
|
-
var
|
|
71854
|
+
var fs42 = __toESM(require("fs"));
|
|
71703
71855
|
var os31 = __toESM(require("os"));
|
|
71704
71856
|
var path44 = __toESM(require("path"));
|
|
71705
71857
|
var import_session_host_core13 = require("@adhdev/session-host-core");
|
|
@@ -71720,7 +71872,7 @@ function createManagedSessionHost(options) {
|
|
|
71720
71872
|
path44.resolve(__dirname, "../../vendor/session-host-daemon/index.js")
|
|
71721
71873
|
];
|
|
71722
71874
|
for (const candidate of packagedCandidates) {
|
|
71723
|
-
if (
|
|
71875
|
+
if (fs42.existsSync(candidate)) {
|
|
71724
71876
|
return candidate;
|
|
71725
71877
|
}
|
|
71726
71878
|
}
|
|
@@ -71732,8 +71884,8 @@ function createManagedSessionHost(options) {
|
|
|
71732
71884
|
function getPid() {
|
|
71733
71885
|
try {
|
|
71734
71886
|
const pidFile = getPidFile();
|
|
71735
|
-
if (!
|
|
71736
|
-
const pid = Number.parseInt(
|
|
71887
|
+
if (!fs42.existsSync(pidFile)) return null;
|
|
71888
|
+
const pid = Number.parseInt(fs42.readFileSync(pidFile, "utf8").trim(), 10);
|
|
71737
71889
|
return Number.isFinite(pid) ? pid : null;
|
|
71738
71890
|
} catch {
|
|
71739
71891
|
return null;
|
|
@@ -71759,8 +71911,8 @@ function createManagedSessionHost(options) {
|
|
|
71759
71911
|
let logFd = null;
|
|
71760
71912
|
if (options.spawnStdio === "logfile") {
|
|
71761
71913
|
const logDir = path44.join(os31.homedir(), ".adhdev", "logs");
|
|
71762
|
-
|
|
71763
|
-
logFd =
|
|
71914
|
+
fs42.mkdirSync(logDir, { recursive: true });
|
|
71915
|
+
logFd = fs42.openSync(path44.join(logDir, "session-host.log"), "a");
|
|
71764
71916
|
stdio = ["ignore", logFd, logFd];
|
|
71765
71917
|
}
|
|
71766
71918
|
const child = (0, import_child_process11.spawn)(process.execPath, [entry], {
|
|
@@ -71772,7 +71924,7 @@ function createManagedSessionHost(options) {
|
|
|
71772
71924
|
child.unref();
|
|
71773
71925
|
if (logFd !== null) {
|
|
71774
71926
|
try {
|
|
71775
|
-
|
|
71927
|
+
fs42.closeSync(logFd);
|
|
71776
71928
|
} catch {
|
|
71777
71929
|
}
|
|
71778
71930
|
}
|
|
@@ -71781,8 +71933,8 @@ function createManagedSessionHost(options) {
|
|
|
71781
71933
|
let stopped = false;
|
|
71782
71934
|
const pidFile = getPidFile();
|
|
71783
71935
|
try {
|
|
71784
|
-
if (
|
|
71785
|
-
const pid = Number.parseInt(
|
|
71936
|
+
if (fs42.existsSync(pidFile)) {
|
|
71937
|
+
const pid = Number.parseInt(fs42.readFileSync(pidFile, "utf8").trim(), 10);
|
|
71786
71938
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedPid(pid)) {
|
|
71787
71939
|
stopped = killPid2(pid) || stopped;
|
|
71788
71940
|
}
|
|
@@ -71790,7 +71942,7 @@ function createManagedSessionHost(options) {
|
|
|
71790
71942
|
} catch {
|
|
71791
71943
|
} finally {
|
|
71792
71944
|
try {
|
|
71793
|
-
|
|
71945
|
+
fs42.unlinkSync(pidFile);
|
|
71794
71946
|
} catch {
|
|
71795
71947
|
}
|
|
71796
71948
|
}
|
|
@@ -71979,12 +72131,12 @@ async function installExtension(ide, extension) {
|
|
|
71979
72131
|
const res = await fetch(extension.vsixUrl);
|
|
71980
72132
|
if (res.ok) {
|
|
71981
72133
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
71982
|
-
const
|
|
71983
|
-
|
|
71984
|
-
return new Promise((
|
|
72134
|
+
const fs43 = await import("fs");
|
|
72135
|
+
fs43.writeFileSync(vsixPath, buffer);
|
|
72136
|
+
return new Promise((resolve26) => {
|
|
71985
72137
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
71986
72138
|
(0, import_child_process12.exec)(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|
|
71987
|
-
|
|
72139
|
+
resolve26({
|
|
71988
72140
|
extensionId: extension.id,
|
|
71989
72141
|
marketplaceId: extension.marketplaceId,
|
|
71990
72142
|
success: !error,
|
|
@@ -71997,11 +72149,11 @@ async function installExtension(ide, extension) {
|
|
|
71997
72149
|
} catch (e) {
|
|
71998
72150
|
}
|
|
71999
72151
|
}
|
|
72000
|
-
return new Promise((
|
|
72152
|
+
return new Promise((resolve26) => {
|
|
72001
72153
|
const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
|
|
72002
72154
|
(0, import_child_process12.exec)(cmd, { timeout: 6e4 }, (error, stdout, stderr) => {
|
|
72003
72155
|
if (error) {
|
|
72004
|
-
|
|
72156
|
+
resolve26({
|
|
72005
72157
|
extensionId: extension.id,
|
|
72006
72158
|
marketplaceId: extension.marketplaceId,
|
|
72007
72159
|
success: false,
|
|
@@ -72009,7 +72161,7 @@ async function installExtension(ide, extension) {
|
|
|
72009
72161
|
error: stderr || error.message
|
|
72010
72162
|
});
|
|
72011
72163
|
} else {
|
|
72012
|
-
|
|
72164
|
+
resolve26({
|
|
72013
72165
|
extensionId: extension.id,
|
|
72014
72166
|
marketplaceId: extension.marketplaceId,
|
|
72015
72167
|
success: true,
|
|
@@ -72545,7 +72697,7 @@ async function startLocalIpcServer(opts) {
|
|
|
72545
72697
|
}));
|
|
72546
72698
|
}
|
|
72547
72699
|
}
|
|
72548
|
-
await new Promise((
|
|
72700
|
+
await new Promise((resolve26, reject) => {
|
|
72549
72701
|
const onError = (error) => {
|
|
72550
72702
|
httpServer?.off("listening", onListening);
|
|
72551
72703
|
reject(error);
|
|
@@ -72553,7 +72705,7 @@ async function startLocalIpcServer(opts) {
|
|
|
72553
72705
|
const onListening = () => {
|
|
72554
72706
|
httpServer?.off("error", onError);
|
|
72555
72707
|
listening = true;
|
|
72556
|
-
|
|
72708
|
+
resolve26();
|
|
72557
72709
|
};
|
|
72558
72710
|
httpServer.once("error", onError);
|
|
72559
72711
|
httpServer.once("listening", onListening);
|
|
@@ -72580,12 +72732,12 @@ async function startLocalIpcServer(opts) {
|
|
|
72580
72732
|
}
|
|
72581
72733
|
}
|
|
72582
72734
|
clients.clear();
|
|
72583
|
-
await new Promise((
|
|
72735
|
+
await new Promise((resolve26) => {
|
|
72584
72736
|
if (!httpServer) {
|
|
72585
|
-
|
|
72737
|
+
resolve26();
|
|
72586
72738
|
return;
|
|
72587
72739
|
}
|
|
72588
|
-
httpServer.close(() =>
|
|
72740
|
+
httpServer.close(() => resolve26());
|
|
72589
72741
|
});
|
|
72590
72742
|
httpServer = null;
|
|
72591
72743
|
wss = null;
|