@adhdev/daemon-core 0.9.82-rc.540 → 0.9.82-rc.542
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 +750 -592
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +757 -599
- 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/src/status/builders.ts +10 -4
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 ? "eb1fb961d4f22983420fad4c65b982d3ab42b5cf" : void 0) ?? "unknown";
|
|
423
|
+
const commitShort = readInjected(true ? "eb1fb961" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
424
|
+
const version = readInjected(true ? "0.9.82-rc.542" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
425
|
+
const builtAt = readInjected(true ? "2026-07-16T06:30:14.678Z" : 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
|
}
|
|
@@ -19528,8 +19529,12 @@ function buildCliSession(state, options) {
|
|
|
19528
19529
|
settings: state.settings,
|
|
19529
19530
|
...coordinator && { coordinator },
|
|
19530
19531
|
...meshQueueStats && { meshQueueStats },
|
|
19531
|
-
|
|
19532
|
-
|
|
19532
|
+
// Emit these booleans explicitly (including false) so an un-hide/un-mute clears a
|
|
19533
|
+
// previously-true value downstream. Consumers merge with `?? existing` and copy only
|
|
19534
|
+
// `!== undefined` fields, so an absent field on false never overwrote a prior true —
|
|
19535
|
+
// the toggle-off direction silently stuck. See session-entry-merge.ts.
|
|
19536
|
+
surfaceHidden: resolveSurfaceHidden(state.settings),
|
|
19537
|
+
muted: resolveMuted(state.settings)
|
|
19533
19538
|
};
|
|
19534
19539
|
}
|
|
19535
19540
|
function buildAcpSession(state, options) {
|
|
@@ -19570,8 +19575,10 @@ function buildAcpSession(state, options) {
|
|
|
19570
19575
|
settings: state.settings,
|
|
19571
19576
|
...coordinator && { coordinator },
|
|
19572
19577
|
...meshQueueStats && { meshQueueStats },
|
|
19573
|
-
|
|
19574
|
-
|
|
19578
|
+
// Emit explicitly (including false) so un-hide/un-mute clears a prior true downstream —
|
|
19579
|
+
// see buildCliSession above and session-entry-merge.ts.
|
|
19580
|
+
surfaceHidden: resolveSurfaceHidden(state.settings),
|
|
19581
|
+
muted: resolveMuted(state.settings)
|
|
19575
19582
|
};
|
|
19576
19583
|
}
|
|
19577
19584
|
function buildSessionEntries(allStates, cdpManagers, options = {}) {
|
|
@@ -23726,13 +23733,13 @@ function activeFilePath() {
|
|
|
23726
23733
|
}
|
|
23727
23734
|
function ensureAdhdevDir() {
|
|
23728
23735
|
const d = adhdevDir();
|
|
23729
|
-
if (!
|
|
23736
|
+
if (!fs11.existsSync(d)) fs11.mkdirSync(d, { recursive: true });
|
|
23730
23737
|
}
|
|
23731
23738
|
function loadExternalSources() {
|
|
23732
23739
|
const p = sourcesFilePath();
|
|
23733
|
-
if (!
|
|
23740
|
+
if (!fs11.existsSync(p)) return { schema: 1, sources: [] };
|
|
23734
23741
|
try {
|
|
23735
|
-
const raw = JSON.parse(
|
|
23742
|
+
const raw = JSON.parse(fs11.readFileSync(p, "utf-8"));
|
|
23736
23743
|
if (!raw || typeof raw !== "object") return { schema: 1, sources: [] };
|
|
23737
23744
|
const sources = Array.isArray(raw.sources) ? raw.sources.filter(isValidSource) : [];
|
|
23738
23745
|
return { schema: 1, sources };
|
|
@@ -23743,14 +23750,14 @@ function loadExternalSources() {
|
|
|
23743
23750
|
function saveExternalSources(file) {
|
|
23744
23751
|
ensureAdhdevDir();
|
|
23745
23752
|
const tmp = sourcesFilePath() + ".tmp";
|
|
23746
|
-
|
|
23747
|
-
|
|
23753
|
+
fs11.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n", "utf-8");
|
|
23754
|
+
fs11.renameSync(tmp, sourcesFilePath());
|
|
23748
23755
|
}
|
|
23749
23756
|
function loadProvidersActive() {
|
|
23750
23757
|
const p = activeFilePath();
|
|
23751
|
-
if (!
|
|
23758
|
+
if (!fs11.existsSync(p)) return { schema: 1, active: {} };
|
|
23752
23759
|
try {
|
|
23753
|
-
const raw = JSON.parse(
|
|
23760
|
+
const raw = JSON.parse(fs11.readFileSync(p, "utf-8"));
|
|
23754
23761
|
if (!raw || typeof raw !== "object") return { schema: 1, active: {} };
|
|
23755
23762
|
const active = raw.active && typeof raw.active === "object" ? raw.active : {};
|
|
23756
23763
|
return { schema: 1, active };
|
|
@@ -23761,8 +23768,8 @@ function loadProvidersActive() {
|
|
|
23761
23768
|
function saveProvidersActive(file) {
|
|
23762
23769
|
ensureAdhdevDir();
|
|
23763
23770
|
const tmp = activeFilePath() + ".tmp";
|
|
23764
|
-
|
|
23765
|
-
|
|
23771
|
+
fs11.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n", "utf-8");
|
|
23772
|
+
fs11.renameSync(tmp, activeFilePath());
|
|
23766
23773
|
}
|
|
23767
23774
|
function isValidSource(x) {
|
|
23768
23775
|
if (!x || typeof x !== "object") return false;
|
|
@@ -23778,11 +23785,11 @@ function deriveSourceName(url) {
|
|
|
23778
23785
|
}
|
|
23779
23786
|
function inventoryExternalSources() {
|
|
23780
23787
|
const root = externalRoot();
|
|
23781
|
-
if (!
|
|
23788
|
+
if (!fs11.existsSync(root)) return [];
|
|
23782
23789
|
const out = [];
|
|
23783
23790
|
let entries;
|
|
23784
23791
|
try {
|
|
23785
|
-
entries =
|
|
23792
|
+
entries = fs11.readdirSync(root, { withFileTypes: true });
|
|
23786
23793
|
} catch {
|
|
23787
23794
|
return [];
|
|
23788
23795
|
}
|
|
@@ -23793,7 +23800,7 @@ function inventoryExternalSources() {
|
|
|
23793
23800
|
const providers = {};
|
|
23794
23801
|
let categoryEntries;
|
|
23795
23802
|
try {
|
|
23796
|
-
categoryEntries =
|
|
23803
|
+
categoryEntries = fs11.readdirSync(sourceDir, { withFileTypes: true });
|
|
23797
23804
|
} catch {
|
|
23798
23805
|
continue;
|
|
23799
23806
|
}
|
|
@@ -23803,7 +23810,7 @@ function inventoryExternalSources() {
|
|
|
23803
23810
|
const categoryDir = path19.join(sourceDir, category);
|
|
23804
23811
|
let typeEntries;
|
|
23805
23812
|
try {
|
|
23806
|
-
typeEntries =
|
|
23813
|
+
typeEntries = fs11.readdirSync(categoryDir, { withFileTypes: true });
|
|
23807
23814
|
} catch {
|
|
23808
23815
|
continue;
|
|
23809
23816
|
}
|
|
@@ -23811,8 +23818,8 @@ function inventoryExternalSources() {
|
|
|
23811
23818
|
for (const typeEntry of typeEntries) {
|
|
23812
23819
|
if (!typeEntry.isDirectory()) continue;
|
|
23813
23820
|
const typeDir = path19.join(categoryDir, typeEntry.name);
|
|
23814
|
-
const hasV1 =
|
|
23815
|
-
const hasV0 =
|
|
23821
|
+
const hasV1 = fs11.existsSync(path19.join(typeDir, "provider.v1.json"));
|
|
23822
|
+
const hasV0 = fs11.existsSync(path19.join(typeDir, "provider.json"));
|
|
23816
23823
|
if (hasV1 || hasV0) types.push(typeEntry.name);
|
|
23817
23824
|
}
|
|
23818
23825
|
if (types.length > 0) providers[category] = types;
|
|
@@ -23835,11 +23842,11 @@ function resolveActiveSource(category, type, activeFile) {
|
|
|
23835
23842
|
}
|
|
23836
23843
|
return { source: candidates[0], ambiguous: true, candidates };
|
|
23837
23844
|
}
|
|
23838
|
-
var
|
|
23845
|
+
var fs11, os12, path19, SOURCES_FILENAME, ACTIVE_FILENAME;
|
|
23839
23846
|
var init_external_sources = __esm({
|
|
23840
23847
|
"src/providers/external-sources.ts"() {
|
|
23841
23848
|
"use strict";
|
|
23842
|
-
|
|
23849
|
+
fs11 = __toESM(require("fs"));
|
|
23843
23850
|
os12 = __toESM(require("os"));
|
|
23844
23851
|
path19 = __toESM(require("path"));
|
|
23845
23852
|
SOURCES_FILENAME = "providers-sources.json";
|
|
@@ -23891,7 +23898,7 @@ __export(fsm_loader_exports, {
|
|
|
23891
23898
|
function loadFsmSpec(sourcePath) {
|
|
23892
23899
|
let raw;
|
|
23893
23900
|
try {
|
|
23894
|
-
raw = JSON.parse(
|
|
23901
|
+
raw = JSON.parse(fs12.readFileSync(sourcePath, "utf8"));
|
|
23895
23902
|
} catch (err) {
|
|
23896
23903
|
return { ok: false, errors: [`Failed to read/parse spec: ${err.message}`], sourcePath };
|
|
23897
23904
|
}
|
|
@@ -24011,11 +24018,11 @@ function validateCondition(c, sectionIds, path45) {
|
|
|
24011
24018
|
errs.push(`${path45} is not a recognized condition`);
|
|
24012
24019
|
return errs;
|
|
24013
24020
|
}
|
|
24014
|
-
var
|
|
24021
|
+
var fs12;
|
|
24015
24022
|
var init_fsm_loader = __esm({
|
|
24016
24023
|
"src/providers/spec/fsm-loader.ts"() {
|
|
24017
24024
|
"use strict";
|
|
24018
|
-
|
|
24025
|
+
fs12 = __toESM(require("fs"));
|
|
24019
24026
|
init_fsm_types();
|
|
24020
24027
|
}
|
|
24021
24028
|
});
|
|
@@ -24507,8 +24514,8 @@ var init_pty_transport = __esm({
|
|
|
24507
24514
|
let cwd = options.cwd;
|
|
24508
24515
|
if (cwd) {
|
|
24509
24516
|
try {
|
|
24510
|
-
const
|
|
24511
|
-
const stat2 =
|
|
24517
|
+
const fs43 = require("fs");
|
|
24518
|
+
const stat2 = fs43.statSync(cwd);
|
|
24512
24519
|
if (!stat2.isDirectory()) cwd = os14.homedir();
|
|
24513
24520
|
} catch {
|
|
24514
24521
|
cwd = os14.homedir();
|
|
@@ -25496,7 +25503,7 @@ var init_provider_cli_parse = __esm({
|
|
|
25496
25503
|
});
|
|
25497
25504
|
|
|
25498
25505
|
// 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;
|
|
25506
|
+
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
25507
|
var init_cli_state_engine = __esm({
|
|
25501
25508
|
"src/cli-adapters/cli-state-engine.ts"() {
|
|
25502
25509
|
"use strict";
|
|
@@ -25510,6 +25517,7 @@ var init_cli_state_engine = __esm({
|
|
|
25510
25517
|
APPROVAL_EXIT_TIMEOUT_MS = 6e4;
|
|
25511
25518
|
IDLE_CONFIRMATION_GRACE_MS = 2e3;
|
|
25512
25519
|
APPROVAL_RESUME_IDLE_DEFER_CAP_MS = 18e3;
|
|
25520
|
+
SCREEN_QUIET_IDLE_MS = 5e3;
|
|
25513
25521
|
CliStateEngine = class {
|
|
25514
25522
|
constructor(provider, runner, transport, callbacks, timeouts) {
|
|
25515
25523
|
this.provider = provider;
|
|
@@ -26074,6 +26082,10 @@ var init_cli_state_engine = __esm({
|
|
|
26074
26082
|
this.idleTimeout = setTimeout(() => {
|
|
26075
26083
|
if (this.isWaitingForResponse && !this.hasActionableApproval()) {
|
|
26076
26084
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26085
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26086
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26087
|
+
return;
|
|
26088
|
+
}
|
|
26077
26089
|
this.finishResponse();
|
|
26078
26090
|
}
|
|
26079
26091
|
}, this.timeouts.generatingIdle);
|
|
@@ -26096,6 +26108,10 @@ var init_cli_state_engine = __esm({
|
|
|
26096
26108
|
this.idleTimeout = setTimeout(() => {
|
|
26097
26109
|
if (this.isWaitingForResponse && !this.hasActionableApproval()) {
|
|
26098
26110
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26111
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26112
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26113
|
+
return;
|
|
26114
|
+
}
|
|
26099
26115
|
this.finishResponse();
|
|
26100
26116
|
}
|
|
26101
26117
|
}, this.timeouts.generatingIdle);
|
|
@@ -26164,6 +26180,10 @@ var init_cli_state_engine = __esm({
|
|
|
26164
26180
|
this.idleTimeout = setTimeout(() => {
|
|
26165
26181
|
if (this.isWaitingForResponse) {
|
|
26166
26182
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26183
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26184
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26185
|
+
return;
|
|
26186
|
+
}
|
|
26167
26187
|
this.finishResponse();
|
|
26168
26188
|
}
|
|
26169
26189
|
}, this.timeouts.generatingIdle);
|
|
@@ -26249,7 +26269,8 @@ var init_cli_state_engine = __esm({
|
|
|
26249
26269
|
const assistantLength = lastParsedAssistant?.content?.length || 0;
|
|
26250
26270
|
const idleFinishConfirmMs = this.timeouts.idleFinishConfirm;
|
|
26251
26271
|
const idleQuietThresholdMs = Math.max(idleFinishConfirmMs, this.timeouts.outputSettle);
|
|
26252
|
-
const
|
|
26272
|
+
const screenQuietForIdle = screenStableMs >= SCREEN_QUIET_IDLE_MS;
|
|
26273
|
+
const idleReady = !modal && hasAssistantTurn && quietForMs >= idleQuietThresholdMs && screenStableMs >= idleFinishConfirmMs && screenQuietForIdle;
|
|
26253
26274
|
const candidate = this.idleFinishCandidate;
|
|
26254
26275
|
const candidateQuiet = !!candidate && candidate.responseEpoch === this.responseEpoch && candidate.lastOutputAt === snap.lastOutputAt && candidate.lastScreenChangeAt === snap.lastScreenChangeAt && assistantLength >= candidate.assistantLength && now - candidate.armedAt >= idleFinishConfirmMs;
|
|
26255
26276
|
if (this.shouldDeferIdleForApprovalResume(now)) {
|
|
@@ -26284,6 +26305,13 @@ var init_cli_state_engine = __esm({
|
|
|
26284
26305
|
return;
|
|
26285
26306
|
}
|
|
26286
26307
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26308
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26309
|
+
if (this.idleTimeout) clearTimeout(this.idleTimeout);
|
|
26310
|
+
this.idleTimeout = setTimeout(() => {
|
|
26311
|
+
if (this.isWaitingForResponse) this.evaluateSettled(this.transport.getSnapshot());
|
|
26312
|
+
}, this.timeouts.idleFinish);
|
|
26313
|
+
return;
|
|
26314
|
+
}
|
|
26287
26315
|
const parsed = this.runParseSession(this.transport.getSnapshot());
|
|
26288
26316
|
if (this.shouldDeferFinishForTranscript(parsed)) {
|
|
26289
26317
|
this.rescheduleTranscriptFinishCheck("transcript_idle_timeout_not_final");
|
|
@@ -26294,6 +26322,22 @@ var init_cli_state_engine = __esm({
|
|
|
26294
26322
|
}
|
|
26295
26323
|
}, this.timeouts.idleFinish);
|
|
26296
26324
|
}
|
|
26325
|
+
/**
|
|
26326
|
+
* FALSE-IDLE (screen-quiet gate): has the visible terminal screen content been
|
|
26327
|
+
* byte-identical for at least SCREEN_QUIET_IDLE_MS continuously?
|
|
26328
|
+
*
|
|
26329
|
+
* `lastScreenChangeAt` is bumped by the adapter every time the normalized screen
|
|
26330
|
+
* snapshot changes (spinner frame, streaming command output, etc.), so
|
|
26331
|
+
* `now - lastScreenChangeAt` is the real screen-diff quiet age. Reads the LIVE
|
|
26332
|
+
* transport snapshot so the deferred idleFinish timeout re-checks current screen
|
|
26333
|
+
* state, not the stale snapshot from when the timer was armed. A never-changed
|
|
26334
|
+
* screen (lastScreenChangeAt === 0) is treated as quiet.
|
|
26335
|
+
*/
|
|
26336
|
+
hasScreenBeenQuietForIdle(now) {
|
|
26337
|
+
const lastChange = this.transport.getSnapshot().lastScreenChangeAt;
|
|
26338
|
+
if (!lastChange) return true;
|
|
26339
|
+
return now - lastChange >= SCREEN_QUIET_IDLE_MS;
|
|
26340
|
+
}
|
|
26297
26341
|
/**
|
|
26298
26342
|
* FALSE-IDLE (Fix 2): should applyIdle suppress the idle/finish for the current
|
|
26299
26343
|
* turn because we are inside the post-approval resume grace?
|
|
@@ -27374,7 +27418,7 @@ ${lastSnapshot}`;
|
|
|
27374
27418
|
`[${this.cliType}] Waiting for interactive prompt: status=${status} stableMs=${stableMs} recentOutputMs=${recentlyOutput} screen=${JSON.stringify(summarizeCliTraceText(screenText, 220)).slice(0, 260)}`
|
|
27375
27419
|
);
|
|
27376
27420
|
}
|
|
27377
|
-
await new Promise((
|
|
27421
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
27378
27422
|
}
|
|
27379
27423
|
const finalScreenText = this.terminalScreen.getText() || "";
|
|
27380
27424
|
LOG.warn(
|
|
@@ -27741,7 +27785,7 @@ ${lastSnapshot}`;
|
|
|
27741
27785
|
if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
|
|
27742
27786
|
await this.ptyProcess.write(chunks[i]);
|
|
27743
27787
|
if (i + 1 < chunks.length) {
|
|
27744
|
-
await new Promise((
|
|
27788
|
+
await new Promise((resolve26) => setTimeout(resolve26, WIN32_PTY_WRITE_CHUNK_GAP_MS));
|
|
27745
27789
|
}
|
|
27746
27790
|
}
|
|
27747
27791
|
}
|
|
@@ -27909,7 +27953,7 @@ ${lastSnapshot}`;
|
|
|
27909
27953
|
this.onStatusChange?.();
|
|
27910
27954
|
}
|
|
27911
27955
|
async waitForForceSubmitSettle() {
|
|
27912
|
-
await new Promise((
|
|
27956
|
+
await new Promise((resolve26) => setTimeout(resolve26, FORCE_SUBMIT_SETTLE_MS));
|
|
27913
27957
|
}
|
|
27914
27958
|
enqueuePendingOutboundMessage(text, reason, meshTaskId) {
|
|
27915
27959
|
const content = String(text || "");
|
|
@@ -27988,7 +28032,7 @@ ${lastSnapshot}`;
|
|
|
27988
28032
|
const deadline = Date.now() + 1e4;
|
|
27989
28033
|
while (this.startupParseGate && Date.now() < deadline) {
|
|
27990
28034
|
this.resolveStartupState("send_wait");
|
|
27991
|
-
await new Promise((
|
|
28035
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
27992
28036
|
}
|
|
27993
28037
|
}
|
|
27994
28038
|
const parsedStatusBeforeSend = !allowInputDuringGeneration ? (() => {
|
|
@@ -28081,13 +28125,13 @@ ${lastSnapshot}`;
|
|
|
28081
28125
|
isFirstTurn: !this.firstTurnSent
|
|
28082
28126
|
};
|
|
28083
28127
|
this.engine.responseSettleIgnoreUntil = Date.now() + submitDelayMs + this.timeouts.outputSettle + 250;
|
|
28084
|
-
await new Promise((
|
|
28128
|
+
await new Promise((resolve26, reject) => {
|
|
28085
28129
|
let resolved = false;
|
|
28086
28130
|
const completion = {
|
|
28087
28131
|
resolveOnce: () => {
|
|
28088
28132
|
if (resolved) return;
|
|
28089
28133
|
resolved = true;
|
|
28090
|
-
|
|
28134
|
+
resolve26();
|
|
28091
28135
|
},
|
|
28092
28136
|
rejectOnce: (error) => {
|
|
28093
28137
|
if (resolved) return;
|
|
@@ -28275,17 +28319,17 @@ ${lastSnapshot}`;
|
|
|
28275
28319
|
}
|
|
28276
28320
|
}
|
|
28277
28321
|
waitForStopped(timeoutMs) {
|
|
28278
|
-
return new Promise((
|
|
28322
|
+
return new Promise((resolve26) => {
|
|
28279
28323
|
const startedAt = Date.now();
|
|
28280
28324
|
const timer = setInterval(() => {
|
|
28281
28325
|
if (!this.ptyProcess || this.engine.currentStatus === "stopped") {
|
|
28282
28326
|
clearInterval(timer);
|
|
28283
|
-
|
|
28327
|
+
resolve26(true);
|
|
28284
28328
|
return;
|
|
28285
28329
|
}
|
|
28286
28330
|
if (Date.now() - startedAt >= timeoutMs) {
|
|
28287
28331
|
clearInterval(timer);
|
|
28288
|
-
|
|
28332
|
+
resolve26(false);
|
|
28289
28333
|
}
|
|
28290
28334
|
}, 100);
|
|
28291
28335
|
});
|
|
@@ -31049,8 +31093,8 @@ async function detectIDEs(providerLoader) {
|
|
|
31049
31093
|
if ((0, import_fs15.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
31050
31094
|
}
|
|
31051
31095
|
if (!resolvedCli && appPath && os32 === "win32") {
|
|
31052
|
-
const { dirname:
|
|
31053
|
-
const appDir =
|
|
31096
|
+
const { dirname: dirname18 } = await import("path");
|
|
31097
|
+
const appDir = dirname18(appPath);
|
|
31054
31098
|
const candidates = [
|
|
31055
31099
|
`${appDir}\\\\bin\\\\${def.cli}.cmd`,
|
|
31056
31100
|
`${appDir}\\\\bin\\\\${def.cli}`,
|
|
@@ -31308,7 +31352,7 @@ var DaemonCdpManager = class {
|
|
|
31308
31352
|
* Returns multiple entries if multiple IDE windows are open on same port
|
|
31309
31353
|
*/
|
|
31310
31354
|
static listAllTargets(port) {
|
|
31311
|
-
return new Promise((
|
|
31355
|
+
return new Promise((resolve26) => {
|
|
31312
31356
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
31313
31357
|
let data = "";
|
|
31314
31358
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -31324,16 +31368,16 @@ var DaemonCdpManager = class {
|
|
|
31324
31368
|
(t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
|
|
31325
31369
|
);
|
|
31326
31370
|
const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
31327
|
-
|
|
31371
|
+
resolve26(mainPages.length > 0 ? mainPages : fallbackPages);
|
|
31328
31372
|
} catch {
|
|
31329
|
-
|
|
31373
|
+
resolve26([]);
|
|
31330
31374
|
}
|
|
31331
31375
|
});
|
|
31332
31376
|
});
|
|
31333
|
-
req.on("error", () =>
|
|
31377
|
+
req.on("error", () => resolve26([]));
|
|
31334
31378
|
req.setTimeout(2e3, () => {
|
|
31335
31379
|
req.destroy();
|
|
31336
|
-
|
|
31380
|
+
resolve26([]);
|
|
31337
31381
|
});
|
|
31338
31382
|
});
|
|
31339
31383
|
}
|
|
@@ -31373,7 +31417,7 @@ var DaemonCdpManager = class {
|
|
|
31373
31417
|
}
|
|
31374
31418
|
}
|
|
31375
31419
|
findTargetOnPort(port) {
|
|
31376
|
-
return new Promise((
|
|
31420
|
+
return new Promise((resolve26) => {
|
|
31377
31421
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
31378
31422
|
let data = "";
|
|
31379
31423
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -31384,7 +31428,7 @@ var DaemonCdpManager = class {
|
|
|
31384
31428
|
(t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
|
|
31385
31429
|
);
|
|
31386
31430
|
if (pages.length === 0) {
|
|
31387
|
-
|
|
31431
|
+
resolve26(targets.find((t) => t.webSocketDebuggerUrl) || null);
|
|
31388
31432
|
return;
|
|
31389
31433
|
}
|
|
31390
31434
|
const titleFilteredPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
|
|
@@ -31403,25 +31447,25 @@ var DaemonCdpManager = class {
|
|
|
31403
31447
|
this._targetId = selected.target.id;
|
|
31404
31448
|
}
|
|
31405
31449
|
this._pageTitle = selected.target.title || "";
|
|
31406
|
-
|
|
31450
|
+
resolve26(selected.target);
|
|
31407
31451
|
return;
|
|
31408
31452
|
}
|
|
31409
31453
|
if (previousTargetId) {
|
|
31410
31454
|
this.log(`[CDP] Target ${previousTargetId} not found in page list`);
|
|
31411
|
-
|
|
31455
|
+
resolve26(null);
|
|
31412
31456
|
return;
|
|
31413
31457
|
}
|
|
31414
31458
|
this._pageTitle = list[0]?.title || "";
|
|
31415
|
-
|
|
31459
|
+
resolve26(list[0]);
|
|
31416
31460
|
} catch {
|
|
31417
|
-
|
|
31461
|
+
resolve26(null);
|
|
31418
31462
|
}
|
|
31419
31463
|
});
|
|
31420
31464
|
});
|
|
31421
|
-
req.on("error", () =>
|
|
31465
|
+
req.on("error", () => resolve26(null));
|
|
31422
31466
|
req.setTimeout(2e3, () => {
|
|
31423
31467
|
req.destroy();
|
|
31424
|
-
|
|
31468
|
+
resolve26(null);
|
|
31425
31469
|
});
|
|
31426
31470
|
});
|
|
31427
31471
|
}
|
|
@@ -31432,7 +31476,7 @@ var DaemonCdpManager = class {
|
|
|
31432
31476
|
this.extensionProviders = providers;
|
|
31433
31477
|
}
|
|
31434
31478
|
connectToTarget(wsUrl) {
|
|
31435
|
-
return new Promise((
|
|
31479
|
+
return new Promise((resolve26) => {
|
|
31436
31480
|
this.ws = new import_ws.default(wsUrl);
|
|
31437
31481
|
this.ws.on("open", async () => {
|
|
31438
31482
|
this._connected = true;
|
|
@@ -31442,17 +31486,17 @@ var DaemonCdpManager = class {
|
|
|
31442
31486
|
}
|
|
31443
31487
|
this.connectBrowserWs().catch(() => {
|
|
31444
31488
|
});
|
|
31445
|
-
|
|
31489
|
+
resolve26(true);
|
|
31446
31490
|
});
|
|
31447
31491
|
this.ws.on("message", (data) => {
|
|
31448
31492
|
try {
|
|
31449
31493
|
const msg = JSON.parse(data.toString());
|
|
31450
31494
|
if (msg.id && this.pending.has(msg.id)) {
|
|
31451
|
-
const { resolve:
|
|
31495
|
+
const { resolve: resolve27, reject } = this.pending.get(msg.id);
|
|
31452
31496
|
this.pending.delete(msg.id);
|
|
31453
31497
|
this.failureCount = 0;
|
|
31454
31498
|
if (msg.error) reject(new Error(msg.error.message));
|
|
31455
|
-
else
|
|
31499
|
+
else resolve27(msg.result);
|
|
31456
31500
|
} else if (msg.method === "Runtime.executionContextCreated") {
|
|
31457
31501
|
this.contexts.add(msg.params.context.id);
|
|
31458
31502
|
} else if (msg.method === "Runtime.executionContextDestroyed") {
|
|
@@ -31475,7 +31519,7 @@ var DaemonCdpManager = class {
|
|
|
31475
31519
|
this.ws.on("error", (err) => {
|
|
31476
31520
|
this.log(`[CDP] WebSocket error: ${err.message}`);
|
|
31477
31521
|
this._connected = false;
|
|
31478
|
-
|
|
31522
|
+
resolve26(false);
|
|
31479
31523
|
});
|
|
31480
31524
|
});
|
|
31481
31525
|
}
|
|
@@ -31489,7 +31533,7 @@ var DaemonCdpManager = class {
|
|
|
31489
31533
|
return;
|
|
31490
31534
|
}
|
|
31491
31535
|
this.log(`[CDP] Connecting browser WS for target discovery...`);
|
|
31492
|
-
await new Promise((
|
|
31536
|
+
await new Promise((resolve26, reject) => {
|
|
31493
31537
|
this.browserWs = new import_ws.default(browserWsUrl);
|
|
31494
31538
|
this.browserWs.on("open", async () => {
|
|
31495
31539
|
this._browserConnected = true;
|
|
@@ -31499,16 +31543,16 @@ var DaemonCdpManager = class {
|
|
|
31499
31543
|
} catch (e) {
|
|
31500
31544
|
this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
|
|
31501
31545
|
}
|
|
31502
|
-
|
|
31546
|
+
resolve26();
|
|
31503
31547
|
});
|
|
31504
31548
|
this.browserWs.on("message", (data) => {
|
|
31505
31549
|
try {
|
|
31506
31550
|
const msg = JSON.parse(data.toString());
|
|
31507
31551
|
if (msg.id && this.browserPending.has(msg.id)) {
|
|
31508
|
-
const { resolve:
|
|
31552
|
+
const { resolve: resolve27, reject: reject2 } = this.browserPending.get(msg.id);
|
|
31509
31553
|
this.browserPending.delete(msg.id);
|
|
31510
31554
|
if (msg.error) reject2(new Error(msg.error.message));
|
|
31511
|
-
else
|
|
31555
|
+
else resolve27(msg.result);
|
|
31512
31556
|
}
|
|
31513
31557
|
} catch {
|
|
31514
31558
|
}
|
|
@@ -31528,31 +31572,31 @@ var DaemonCdpManager = class {
|
|
|
31528
31572
|
}
|
|
31529
31573
|
}
|
|
31530
31574
|
getBrowserWsUrl() {
|
|
31531
|
-
return new Promise((
|
|
31575
|
+
return new Promise((resolve26) => {
|
|
31532
31576
|
const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
|
|
31533
31577
|
let data = "";
|
|
31534
31578
|
res.on("data", (chunk) => data += chunk.toString());
|
|
31535
31579
|
res.on("end", () => {
|
|
31536
31580
|
try {
|
|
31537
31581
|
const info = JSON.parse(data);
|
|
31538
|
-
|
|
31582
|
+
resolve26(info.webSocketDebuggerUrl || null);
|
|
31539
31583
|
} catch {
|
|
31540
|
-
|
|
31584
|
+
resolve26(null);
|
|
31541
31585
|
}
|
|
31542
31586
|
});
|
|
31543
31587
|
});
|
|
31544
|
-
req.on("error", () =>
|
|
31588
|
+
req.on("error", () => resolve26(null));
|
|
31545
31589
|
req.setTimeout(3e3, () => {
|
|
31546
31590
|
req.destroy();
|
|
31547
|
-
|
|
31591
|
+
resolve26(null);
|
|
31548
31592
|
});
|
|
31549
31593
|
});
|
|
31550
31594
|
}
|
|
31551
31595
|
sendBrowser(method, params = {}, timeoutMs = 15e3) {
|
|
31552
|
-
return new Promise((
|
|
31596
|
+
return new Promise((resolve26, reject) => {
|
|
31553
31597
|
if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
|
|
31554
31598
|
const id = this.browserMsgId++;
|
|
31555
|
-
this.browserPending.set(id, { resolve:
|
|
31599
|
+
this.browserPending.set(id, { resolve: resolve26, reject });
|
|
31556
31600
|
this.browserWs.send(JSON.stringify({ id, method, params }));
|
|
31557
31601
|
setTimeout(() => {
|
|
31558
31602
|
if (this.browserPending.has(id)) {
|
|
@@ -31592,11 +31636,11 @@ var DaemonCdpManager = class {
|
|
|
31592
31636
|
}
|
|
31593
31637
|
// ─── CDP Protocol ────────────────────────────────────────
|
|
31594
31638
|
sendInternal(method, params = {}, timeoutMs = 15e3) {
|
|
31595
|
-
return new Promise((
|
|
31639
|
+
return new Promise((resolve26, reject) => {
|
|
31596
31640
|
if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
|
|
31597
31641
|
if (this.ws.readyState !== import_ws.default.OPEN) return reject(new Error("WebSocket not open"));
|
|
31598
31642
|
const id = this.msgId++;
|
|
31599
|
-
this.pending.set(id, { resolve:
|
|
31643
|
+
this.pending.set(id, { resolve: resolve26, reject });
|
|
31600
31644
|
this.ws.send(JSON.stringify({ id, method, params }));
|
|
31601
31645
|
setTimeout(() => {
|
|
31602
31646
|
if (this.pending.has(id)) {
|
|
@@ -31845,7 +31889,7 @@ var DaemonCdpManager = class {
|
|
|
31845
31889
|
const browserWs = this.browserWs;
|
|
31846
31890
|
let msgId = this.browserMsgId;
|
|
31847
31891
|
const sendWs = (method, params = {}, sessionId) => {
|
|
31848
|
-
return new Promise((
|
|
31892
|
+
return new Promise((resolve26, reject) => {
|
|
31849
31893
|
const mid = msgId++;
|
|
31850
31894
|
this.browserMsgId = msgId;
|
|
31851
31895
|
const handler = (raw) => {
|
|
@@ -31854,7 +31898,7 @@ var DaemonCdpManager = class {
|
|
|
31854
31898
|
if (msg.id === mid) {
|
|
31855
31899
|
browserWs.removeListener("message", handler);
|
|
31856
31900
|
if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
31857
|
-
else
|
|
31901
|
+
else resolve26(msg.result);
|
|
31858
31902
|
}
|
|
31859
31903
|
} catch {
|
|
31860
31904
|
}
|
|
@@ -32055,14 +32099,14 @@ var DaemonCdpManager = class {
|
|
|
32055
32099
|
if (!ws || ws.readyState !== import_ws.default.OPEN) {
|
|
32056
32100
|
throw new Error("CDP not connected");
|
|
32057
32101
|
}
|
|
32058
|
-
return new Promise((
|
|
32102
|
+
return new Promise((resolve26, reject) => {
|
|
32059
32103
|
const id = getNextId();
|
|
32060
32104
|
pendingMap.set(id, {
|
|
32061
32105
|
resolve: (result) => {
|
|
32062
32106
|
if (result?.result?.subtype === "error") {
|
|
32063
32107
|
reject(new Error(result.result.description));
|
|
32064
32108
|
} else {
|
|
32065
|
-
|
|
32109
|
+
resolve26(result?.result?.value);
|
|
32066
32110
|
}
|
|
32067
32111
|
},
|
|
32068
32112
|
reject
|
|
@@ -32094,10 +32138,10 @@ var DaemonCdpManager = class {
|
|
|
32094
32138
|
throw new Error("CDP not connected");
|
|
32095
32139
|
}
|
|
32096
32140
|
const sendViaSession = (method, params = {}) => {
|
|
32097
|
-
return new Promise((
|
|
32141
|
+
return new Promise((resolve26, reject) => {
|
|
32098
32142
|
const pendingMap = this._browserConnected ? this.browserPending : this.pending;
|
|
32099
32143
|
const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
|
|
32100
|
-
pendingMap.set(id, { resolve:
|
|
32144
|
+
pendingMap.set(id, { resolve: resolve26, reject });
|
|
32101
32145
|
ws.send(JSON.stringify({ id, sessionId, method, params }));
|
|
32102
32146
|
setTimeout(() => {
|
|
32103
32147
|
if (pendingMap.has(id)) {
|
|
@@ -36010,7 +36054,7 @@ function resolveTargetSessionActualWorkspace(h, targetSessionId) {
|
|
|
36010
36054
|
}
|
|
36011
36055
|
|
|
36012
36056
|
// src/commands/chat-commands-debug-bundle.ts
|
|
36013
|
-
var
|
|
36057
|
+
var fs9 = __toESM(require("fs"));
|
|
36014
36058
|
var os10 = __toESM(require("os"));
|
|
36015
36059
|
var path17 = __toESM(require("path"));
|
|
36016
36060
|
var import_node_crypto3 = require("crypto");
|
|
@@ -36018,6 +36062,7 @@ init_logger();
|
|
|
36018
36062
|
init_debug_trace();
|
|
36019
36063
|
|
|
36020
36064
|
// src/commands/chat-commands-read.ts
|
|
36065
|
+
var fs8 = __toESM(require("fs"));
|
|
36021
36066
|
var path16 = __toESM(require("path"));
|
|
36022
36067
|
init_contracts2();
|
|
36023
36068
|
init_state_store();
|
|
@@ -36971,7 +37016,16 @@ function readExactRuntimeMirrorMessages(args) {
|
|
|
36971
37016
|
function normalizeComparableWorkspace(value) {
|
|
36972
37017
|
const text = typeof value === "string" ? value.trim() : "";
|
|
36973
37018
|
if (!text) return "";
|
|
36974
|
-
|
|
37019
|
+
const lexical = path16.resolve(text);
|
|
37020
|
+
try {
|
|
37021
|
+
return fs8.realpathSync.native(lexical);
|
|
37022
|
+
} catch {
|
|
37023
|
+
try {
|
|
37024
|
+
return fs8.realpathSync(lexical);
|
|
37025
|
+
} catch {
|
|
37026
|
+
return lexical;
|
|
37027
|
+
}
|
|
37028
|
+
}
|
|
36975
37029
|
}
|
|
36976
37030
|
function isCurrentRuntimePtySafelyAttributed(args) {
|
|
36977
37031
|
if (args.adapter.cliType !== "codex-cli") return false;
|
|
@@ -38289,11 +38343,11 @@ function buildChatDebugBundleSummary(bundle) {
|
|
|
38289
38343
|
function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
38290
38344
|
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
38291
38345
|
const dir = getChatDebugBundleDir();
|
|
38292
|
-
|
|
38346
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
38293
38347
|
const savedPath = path17.join(dir, `${bundleId}.json`);
|
|
38294
38348
|
const json = `${JSON.stringify(bundle, null, 2)}
|
|
38295
38349
|
`;
|
|
38296
|
-
|
|
38350
|
+
fs9.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
|
|
38297
38351
|
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, "utf8") };
|
|
38298
38352
|
}
|
|
38299
38353
|
function isDaemonFileDebugDelivery(args) {
|
|
@@ -38454,7 +38508,7 @@ function getSendChatInputEnvelope(args) {
|
|
|
38454
38508
|
return normalizeInputEnvelope(args?.input ? { input: args.input } : args);
|
|
38455
38509
|
}
|
|
38456
38510
|
function sleep(ms) {
|
|
38457
|
-
return new Promise((
|
|
38511
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
38458
38512
|
}
|
|
38459
38513
|
async function waitOnceForFreshHermesCliStart(adapter, log) {
|
|
38460
38514
|
if (adapter.cliType !== "hermes-cli") return;
|
|
@@ -38509,7 +38563,7 @@ function getStateLastSignature(state) {
|
|
|
38509
38563
|
async function getStableExtensionBaseline(h) {
|
|
38510
38564
|
const first = await readExtensionChatState(h);
|
|
38511
38565
|
if (getStateMessageCount(first) > 0 || getStateLastSignature(first)) return first;
|
|
38512
|
-
await new Promise((
|
|
38566
|
+
await new Promise((resolve26) => setTimeout(resolve26, 150));
|
|
38513
38567
|
const second = await readExtensionChatState(h);
|
|
38514
38568
|
return getStateMessageCount(second) >= getStateMessageCount(first) ? second : first;
|
|
38515
38569
|
}
|
|
@@ -38517,7 +38571,7 @@ async function verifyExtensionSendObserved(h, before) {
|
|
|
38517
38571
|
const beforeCount = getStateMessageCount(before);
|
|
38518
38572
|
const beforeSignature = getStateLastSignature(before);
|
|
38519
38573
|
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
38520
|
-
await new Promise((
|
|
38574
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
38521
38575
|
const state = await readExtensionChatState(h);
|
|
38522
38576
|
if (state?.status === "waiting_approval") return true;
|
|
38523
38577
|
const afterCount = getStateMessageCount(state);
|
|
@@ -39234,7 +39288,7 @@ async function handleResolveAction(h, args) {
|
|
|
39234
39288
|
}
|
|
39235
39289
|
|
|
39236
39290
|
// src/commands/cdp-commands.ts
|
|
39237
|
-
var
|
|
39291
|
+
var fs10 = __toESM(require("fs"));
|
|
39238
39292
|
var path18 = __toESM(require("path"));
|
|
39239
39293
|
var os11 = __toESM(require("os"));
|
|
39240
39294
|
var KEY_TO_VK = {
|
|
@@ -39507,7 +39561,7 @@ function resolveSafePath(requestedPath) {
|
|
|
39507
39561
|
return path18.resolve(inputPath);
|
|
39508
39562
|
}
|
|
39509
39563
|
function listDirectoryEntriesSafe(dirPath) {
|
|
39510
|
-
const entries =
|
|
39564
|
+
const entries = fs10.readdirSync(dirPath, { withFileTypes: true });
|
|
39511
39565
|
const files = [];
|
|
39512
39566
|
for (const entry of entries) {
|
|
39513
39567
|
const entryPath = path18.join(dirPath, entry.name);
|
|
@@ -39519,14 +39573,14 @@ function listDirectoryEntriesSafe(dirPath) {
|
|
|
39519
39573
|
if (entry.isFile()) {
|
|
39520
39574
|
let size;
|
|
39521
39575
|
try {
|
|
39522
|
-
size =
|
|
39576
|
+
size = fs10.statSync(entryPath).size;
|
|
39523
39577
|
} catch {
|
|
39524
39578
|
size = void 0;
|
|
39525
39579
|
}
|
|
39526
39580
|
files.push({ name: entry.name, type: "file", size });
|
|
39527
39581
|
continue;
|
|
39528
39582
|
}
|
|
39529
|
-
const stat2 =
|
|
39583
|
+
const stat2 = fs10.statSync(entryPath);
|
|
39530
39584
|
files.push({
|
|
39531
39585
|
name: entry.name,
|
|
39532
39586
|
type: stat2.isDirectory() ? "directory" : "file",
|
|
@@ -39544,7 +39598,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
39544
39598
|
const letter = String.fromCharCode(code);
|
|
39545
39599
|
const root = `${letter}:\\`;
|
|
39546
39600
|
try {
|
|
39547
|
-
if (!
|
|
39601
|
+
if (!fs10.existsSync(root)) continue;
|
|
39548
39602
|
if (excluded && root.toLowerCase() === excluded) continue;
|
|
39549
39603
|
drives.push({ name: `${letter}:`, type: "directory", path: root });
|
|
39550
39604
|
} catch {
|
|
@@ -39555,7 +39609,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
39555
39609
|
async function handleFileRead(h, args) {
|
|
39556
39610
|
try {
|
|
39557
39611
|
const filePath = resolveSafePath(args?.path);
|
|
39558
|
-
const content =
|
|
39612
|
+
const content = fs10.readFileSync(filePath, "utf-8");
|
|
39559
39613
|
return { success: true, content, path: filePath };
|
|
39560
39614
|
} catch (e) {
|
|
39561
39615
|
return { success: false, error: e.message };
|
|
@@ -39564,8 +39618,8 @@ async function handleFileRead(h, args) {
|
|
|
39564
39618
|
async function handleFileWrite(h, args) {
|
|
39565
39619
|
try {
|
|
39566
39620
|
const filePath = resolveSafePath(args?.path);
|
|
39567
|
-
|
|
39568
|
-
|
|
39621
|
+
fs10.mkdirSync(path18.dirname(filePath), { recursive: true });
|
|
39622
|
+
fs10.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
39569
39623
|
return { success: true, path: filePath };
|
|
39570
39624
|
} catch (e) {
|
|
39571
39625
|
return { success: false, error: e.message };
|
|
@@ -39919,7 +39973,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
39919
39973
|
const enterCount = cliCommand.enterCount || 1;
|
|
39920
39974
|
await adapter.writeRaw(cliCommand.text + "\r");
|
|
39921
39975
|
for (let i = 1; i < enterCount; i += 1) {
|
|
39922
|
-
await new Promise((
|
|
39976
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
39923
39977
|
await adapter.writeRaw("\r");
|
|
39924
39978
|
}
|
|
39925
39979
|
}
|
|
@@ -40723,11 +40777,11 @@ var DaemonCommandHandler = class {
|
|
|
40723
40777
|
return { success: false, error: "invalid type" };
|
|
40724
40778
|
}
|
|
40725
40779
|
const https = require("https");
|
|
40726
|
-
const
|
|
40780
|
+
const fs43 = require("fs");
|
|
40727
40781
|
const path45 = require("path");
|
|
40728
40782
|
const REGISTRY = resolveRegistryBaseUrl(loadConfig().registryUrl);
|
|
40729
40783
|
function fetchText(url, timeoutMs) {
|
|
40730
|
-
return new Promise((
|
|
40784
|
+
return new Promise((resolve26, reject) => {
|
|
40731
40785
|
const req = https.get(url, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: timeoutMs }, (res) => {
|
|
40732
40786
|
if (res.statusCode !== 200) {
|
|
40733
40787
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
@@ -40735,7 +40789,7 @@ var DaemonCommandHandler = class {
|
|
|
40735
40789
|
}
|
|
40736
40790
|
const chunks = [];
|
|
40737
40791
|
res.on("data", (c) => chunks.push(c));
|
|
40738
|
-
res.on("end", () =>
|
|
40792
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
40739
40793
|
});
|
|
40740
40794
|
req.on("error", reject);
|
|
40741
40795
|
req.on("timeout", () => {
|
|
@@ -40766,7 +40820,7 @@ var DaemonCommandHandler = class {
|
|
|
40766
40820
|
if (!targetDir.startsWith(installRootResolved + path45.sep)) {
|
|
40767
40821
|
return { success: false, error: "install path escaped upstream root" };
|
|
40768
40822
|
}
|
|
40769
|
-
|
|
40823
|
+
fs43.mkdirSync(targetDir, { recursive: true });
|
|
40770
40824
|
let manifestProbe = {};
|
|
40771
40825
|
try {
|
|
40772
40826
|
manifestProbe = JSON.parse(manifestBody);
|
|
@@ -40791,7 +40845,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40791
40845
|
}
|
|
40792
40846
|
const targetFile = isV1 ? "provider.v1.json" : "provider.json";
|
|
40793
40847
|
const targetPath = path45.join(targetDir, targetFile);
|
|
40794
|
-
|
|
40848
|
+
fs43.writeFileSync(targetPath, manifestBody, "utf-8");
|
|
40795
40849
|
const manifestJson = JSON.parse(manifestBody);
|
|
40796
40850
|
const scriptFetch = await this.fetchProviderSources(
|
|
40797
40851
|
manifestJson,
|
|
@@ -40861,10 +40915,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40861
40915
|
const repo = source.repo;
|
|
40862
40916
|
const ref = source.ref;
|
|
40863
40917
|
const https = require("https");
|
|
40864
|
-
const
|
|
40918
|
+
const fs43 = require("fs");
|
|
40865
40919
|
const path45 = require("path");
|
|
40866
40920
|
function fetchJson(url, timeoutMs) {
|
|
40867
|
-
return new Promise((
|
|
40921
|
+
return new Promise((resolve26, reject) => {
|
|
40868
40922
|
const req = https.get(url, {
|
|
40869
40923
|
headers: { "User-Agent": "adhdev-daemon", "Accept": "application/vnd.github+json" },
|
|
40870
40924
|
timeout: timeoutMs
|
|
@@ -40877,7 +40931,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40877
40931
|
res.on("data", (c) => chunks.push(c));
|
|
40878
40932
|
res.on("end", () => {
|
|
40879
40933
|
try {
|
|
40880
|
-
|
|
40934
|
+
resolve26(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
40881
40935
|
} catch (e) {
|
|
40882
40936
|
reject(e);
|
|
40883
40937
|
}
|
|
@@ -40891,14 +40945,14 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40891
40945
|
});
|
|
40892
40946
|
}
|
|
40893
40947
|
function fetchBinary(url, timeoutMs) {
|
|
40894
|
-
return new Promise((
|
|
40948
|
+
return new Promise((resolve26, reject) => {
|
|
40895
40949
|
const req = https.get(url, {
|
|
40896
40950
|
headers: { "User-Agent": "adhdev-daemon" },
|
|
40897
40951
|
timeout: timeoutMs
|
|
40898
40952
|
}, (res) => {
|
|
40899
40953
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
40900
40954
|
if (res.headers.location) {
|
|
40901
|
-
return fetchBinary(res.headers.location, timeoutMs).then(
|
|
40955
|
+
return fetchBinary(res.headers.location, timeoutMs).then(resolve26, reject);
|
|
40902
40956
|
}
|
|
40903
40957
|
}
|
|
40904
40958
|
if (res.statusCode !== 200) {
|
|
@@ -40907,7 +40961,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40907
40961
|
}
|
|
40908
40962
|
const chunks = [];
|
|
40909
40963
|
res.on("data", (c) => chunks.push(c));
|
|
40910
|
-
res.on("end", () =>
|
|
40964
|
+
res.on("end", () => resolve26(Buffer.concat(chunks)));
|
|
40911
40965
|
});
|
|
40912
40966
|
req.on("error", reject);
|
|
40913
40967
|
req.on("timeout", () => {
|
|
@@ -40945,8 +40999,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40945
40999
|
const relInside = entry.path.startsWith(sharedDirRel + "/") ? entry.path.slice(sharedDirRel.length + 1) : entry.path;
|
|
40946
41000
|
const outPath = path45.resolve(path45.join(sharedTargetDir, relInside));
|
|
40947
41001
|
if (!outPath.startsWith(path45.resolve(sharedTargetDir) + path45.sep)) continue;
|
|
40948
|
-
|
|
40949
|
-
|
|
41002
|
+
fs43.mkdirSync(path45.dirname(outPath), { recursive: true });
|
|
41003
|
+
fs43.writeFileSync(outPath, body);
|
|
40950
41004
|
fetchedCount++;
|
|
40951
41005
|
} catch (e) {
|
|
40952
41006
|
errors.push(`fetch shared ${entry.path}: ${e?.message ?? e}`);
|
|
@@ -40984,8 +41038,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40984
41038
|
errors.push(`refusing to write outside targetDir: ${entry.path}`);
|
|
40985
41039
|
continue;
|
|
40986
41040
|
}
|
|
40987
|
-
|
|
40988
|
-
|
|
41041
|
+
fs43.mkdirSync(path45.dirname(outPath), { recursive: true });
|
|
41042
|
+
fs43.writeFileSync(outPath, body);
|
|
40989
41043
|
fetchedCount++;
|
|
40990
41044
|
} catch (e) {
|
|
40991
41045
|
errors.push(`fetch ${entry.path}: ${e?.message ?? e}`);
|
|
@@ -41013,7 +41067,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41013
41067
|
if (!["cli", "ide", "extension", "acp"].includes(category)) {
|
|
41014
41068
|
return { success: false, error: `unknown category: ${category}` };
|
|
41015
41069
|
}
|
|
41016
|
-
const
|
|
41070
|
+
const fs43 = require("fs");
|
|
41017
41071
|
const path45 = require("path");
|
|
41018
41072
|
try {
|
|
41019
41073
|
const installRoot = this.getUpstreamInstallRoot();
|
|
@@ -41022,10 +41076,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41022
41076
|
if (!targetDir.startsWith(installRootResolved + path45.sep)) {
|
|
41023
41077
|
return { success: false, error: "refusing to delete outside upstream root" };
|
|
41024
41078
|
}
|
|
41025
|
-
if (!
|
|
41079
|
+
if (!fs43.existsSync(targetDir)) {
|
|
41026
41080
|
return { success: false, error: "not installed" };
|
|
41027
41081
|
}
|
|
41028
|
-
|
|
41082
|
+
fs43.rmSync(targetDir, { recursive: true, force: true });
|
|
41029
41083
|
if (this._ctx.providerLoader) {
|
|
41030
41084
|
this._ctx.providerLoader.reload();
|
|
41031
41085
|
this._ctx.providerLoader.registerToDetector();
|
|
@@ -41041,28 +41095,28 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41041
41095
|
* the UI and by the update checker.
|
|
41042
41096
|
*/
|
|
41043
41097
|
handleListInstalledProviders(_args) {
|
|
41044
|
-
const
|
|
41098
|
+
const fs43 = require("fs");
|
|
41045
41099
|
const path45 = require("path");
|
|
41046
41100
|
const installRoot = this.getUpstreamInstallRoot();
|
|
41047
|
-
if (!
|
|
41101
|
+
if (!fs43.existsSync(installRoot)) return { success: true, providers: [] };
|
|
41048
41102
|
const CATEGORIES = ["cli", "ide", "extension", "acp"];
|
|
41049
41103
|
const items = [];
|
|
41050
41104
|
for (const category of CATEGORIES) {
|
|
41051
41105
|
const categoryDir = path45.join(installRoot, category);
|
|
41052
|
-
if (!
|
|
41106
|
+
if (!fs43.existsSync(categoryDir)) continue;
|
|
41053
41107
|
let entries;
|
|
41054
41108
|
try {
|
|
41055
|
-
entries =
|
|
41109
|
+
entries = fs43.readdirSync(categoryDir);
|
|
41056
41110
|
} catch {
|
|
41057
41111
|
continue;
|
|
41058
41112
|
}
|
|
41059
41113
|
for (const type of entries) {
|
|
41060
41114
|
const v1Path = path45.join(categoryDir, type, "provider.v1.json");
|
|
41061
41115
|
const v0Path = path45.join(categoryDir, type, "provider.json");
|
|
41062
|
-
const manifestPath =
|
|
41116
|
+
const manifestPath = fs43.existsSync(v1Path) ? v1Path : fs43.existsSync(v0Path) ? v0Path : null;
|
|
41063
41117
|
if (!manifestPath) continue;
|
|
41064
41118
|
try {
|
|
41065
|
-
const m = JSON.parse(
|
|
41119
|
+
const m = JSON.parse(fs43.readFileSync(manifestPath, "utf-8"));
|
|
41066
41120
|
const modelOptions = Array.isArray(m.modelOptions) ? m.modelOptions.filter((x) => typeof x === "string" && !!x.trim()) : [];
|
|
41067
41121
|
const thinkingLevelOptions = Array.isArray(m.thinkingLevelOptions) ? m.thinkingLevelOptions.filter((x) => typeof x === "string" && !!x.trim()) : [];
|
|
41068
41122
|
items.push({
|
|
@@ -41093,7 +41147,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41093
41147
|
const https = require("https");
|
|
41094
41148
|
const REGISTRY = resolveRegistryBaseUrl(loadConfig().registryUrl);
|
|
41095
41149
|
function fetchJson(url) {
|
|
41096
|
-
return new Promise((
|
|
41150
|
+
return new Promise((resolve26, reject) => {
|
|
41097
41151
|
const req = https.get(url, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 1e4 }, (res) => {
|
|
41098
41152
|
if (res.statusCode !== 200) {
|
|
41099
41153
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
@@ -41103,7 +41157,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41103
41157
|
res.on("data", (c) => chunks.push(c));
|
|
41104
41158
|
res.on("end", () => {
|
|
41105
41159
|
try {
|
|
41106
|
-
|
|
41160
|
+
resolve26(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
41107
41161
|
} catch (e) {
|
|
41108
41162
|
reject(e);
|
|
41109
41163
|
}
|
|
@@ -41177,7 +41231,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41177
41231
|
if (!/^@[a-z0-9_-]+$/i.test(requestedName)) {
|
|
41178
41232
|
return { success: false, error: "name must match @[a-z0-9_-]+" };
|
|
41179
41233
|
}
|
|
41180
|
-
const
|
|
41234
|
+
const fs43 = require("fs");
|
|
41181
41235
|
const path45 = require("path");
|
|
41182
41236
|
const { spawnSync: spawnSync2 } = require("child_process");
|
|
41183
41237
|
const file = ext.loadExternalSources();
|
|
@@ -41188,8 +41242,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41188
41242
|
return { success: false, error: `source url+ref already registered (use a different name to track another ref)` };
|
|
41189
41243
|
}
|
|
41190
41244
|
const sourceDir = path45.join(ext.externalRoot(), requestedName);
|
|
41191
|
-
if (!
|
|
41192
|
-
if (
|
|
41245
|
+
if (!fs43.existsSync(ext.externalRoot())) fs43.mkdirSync(ext.externalRoot(), { recursive: true });
|
|
41246
|
+
if (fs43.existsSync(sourceDir)) {
|
|
41193
41247
|
return { success: false, error: `directory already exists: ${sourceDir} (rename or remove first)` };
|
|
41194
41248
|
}
|
|
41195
41249
|
const clone = spawnSync2("git", ["clone", "--depth=1", "--branch", ref, "--", url, sourceDir], {
|
|
@@ -41199,7 +41253,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41199
41253
|
});
|
|
41200
41254
|
if (clone.status !== 0) {
|
|
41201
41255
|
try {
|
|
41202
|
-
|
|
41256
|
+
fs43.rmSync(sourceDir, { recursive: true, force: true });
|
|
41203
41257
|
} catch {
|
|
41204
41258
|
}
|
|
41205
41259
|
return { success: false, error: `git clone failed: ${(clone.stderr || clone.stdout || "").trim() || "unknown error"}` };
|
|
@@ -41243,15 +41297,15 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41243
41297
|
const name = typeof args?.name === "string" ? args.name.trim() : "";
|
|
41244
41298
|
if (!name) return { success: false, error: "name is required" };
|
|
41245
41299
|
const ext = (init_external_sources(), __toCommonJS(external_sources_exports));
|
|
41246
|
-
const
|
|
41300
|
+
const fs43 = require("fs");
|
|
41247
41301
|
const path45 = require("path");
|
|
41248
41302
|
const file = ext.loadExternalSources();
|
|
41249
41303
|
const match = file.sources.find((s2) => s2.name === name);
|
|
41250
41304
|
if (!match) return { success: false, error: `source "${name}" not registered` };
|
|
41251
41305
|
const sourceDir = path45.join(ext.externalRoot(), name);
|
|
41252
|
-
if (
|
|
41306
|
+
if (fs43.existsSync(sourceDir)) {
|
|
41253
41307
|
try {
|
|
41254
|
-
|
|
41308
|
+
fs43.rmSync(sourceDir, { recursive: true, force: true });
|
|
41255
41309
|
} catch (e) {
|
|
41256
41310
|
return { success: false, error: `failed to delete ${sourceDir}: ${e?.message || e}` };
|
|
41257
41311
|
}
|
|
@@ -41341,7 +41395,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41341
41395
|
try {
|
|
41342
41396
|
const http3 = await import("http");
|
|
41343
41397
|
const postData = JSON.stringify(body);
|
|
41344
|
-
const result = await new Promise((
|
|
41398
|
+
const result = await new Promise((resolve26, reject) => {
|
|
41345
41399
|
const req = http3.request({
|
|
41346
41400
|
hostname: "127.0.0.1",
|
|
41347
41401
|
port: 19280,
|
|
@@ -41353,9 +41407,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41353
41407
|
res.on("data", (chunk) => data += chunk);
|
|
41354
41408
|
res.on("end", () => {
|
|
41355
41409
|
try {
|
|
41356
|
-
|
|
41410
|
+
resolve26(JSON.parse(data));
|
|
41357
41411
|
} catch {
|
|
41358
|
-
|
|
41412
|
+
resolve26({ raw: data });
|
|
41359
41413
|
}
|
|
41360
41414
|
});
|
|
41361
41415
|
});
|
|
@@ -41373,15 +41427,15 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41373
41427
|
if (!providerType) return { success: false, error: "providerType required" };
|
|
41374
41428
|
try {
|
|
41375
41429
|
const http3 = await import("http");
|
|
41376
|
-
const result = await new Promise((
|
|
41430
|
+
const result = await new Promise((resolve26, reject) => {
|
|
41377
41431
|
http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
|
|
41378
41432
|
let data = "";
|
|
41379
41433
|
res.on("data", (chunk) => data += chunk);
|
|
41380
41434
|
res.on("end", () => {
|
|
41381
41435
|
try {
|
|
41382
|
-
|
|
41436
|
+
resolve26(JSON.parse(data));
|
|
41383
41437
|
} catch {
|
|
41384
|
-
|
|
41438
|
+
resolve26({ raw: data });
|
|
41385
41439
|
}
|
|
41386
41440
|
});
|
|
41387
41441
|
}).on("error", reject);
|
|
@@ -41395,7 +41449,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41395
41449
|
try {
|
|
41396
41450
|
const http3 = await import("http");
|
|
41397
41451
|
const postData = JSON.stringify(args || {});
|
|
41398
|
-
const result = await new Promise((
|
|
41452
|
+
const result = await new Promise((resolve26, reject) => {
|
|
41399
41453
|
const req = http3.request({
|
|
41400
41454
|
hostname: "127.0.0.1",
|
|
41401
41455
|
port: 19280,
|
|
@@ -41407,9 +41461,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
41407
41461
|
res.on("data", (chunk) => data += chunk);
|
|
41408
41462
|
res.on("end", () => {
|
|
41409
41463
|
try {
|
|
41410
|
-
|
|
41464
|
+
resolve26(JSON.parse(data));
|
|
41411
41465
|
} catch {
|
|
41412
|
-
|
|
41466
|
+
resolve26({ raw: data });
|
|
41413
41467
|
}
|
|
41414
41468
|
});
|
|
41415
41469
|
});
|
|
@@ -41923,7 +41977,7 @@ var refineConfigHandlers = {
|
|
|
41923
41977
|
};
|
|
41924
41978
|
|
|
41925
41979
|
// src/commands/low-family/diagnostics.ts
|
|
41926
|
-
var
|
|
41980
|
+
var fs13 = __toESM(require("fs"));
|
|
41927
41981
|
init_logger();
|
|
41928
41982
|
init_debug_trace();
|
|
41929
41983
|
var diagnosticsHandlers = {
|
|
@@ -41942,8 +41996,8 @@ var diagnosticsHandlers = {
|
|
|
41942
41996
|
if (sinceTs > 0) {
|
|
41943
41997
|
return { success: true, logs: [], totalBuffered: 0 };
|
|
41944
41998
|
}
|
|
41945
|
-
if (
|
|
41946
|
-
const content =
|
|
41999
|
+
if (fs13.existsSync(LOG_PATH)) {
|
|
42000
|
+
const content = fs13.readFileSync(LOG_PATH, "utf-8");
|
|
41947
42001
|
const allLines = content.split("\n");
|
|
41948
42002
|
const recent = allLines.slice(-count).join("\n");
|
|
41949
42003
|
return { success: true, logs: recent, totalLines: allLines.length };
|
|
@@ -42090,14 +42144,14 @@ var coordinatorPromptHandlers = {
|
|
|
42090
42144
|
}
|
|
42091
42145
|
},
|
|
42092
42146
|
list_coordinator_prompts: async (_ctx, _args) => {
|
|
42093
|
-
const
|
|
42147
|
+
const fs43 = await import("fs");
|
|
42094
42148
|
const path45 = await import("path");
|
|
42095
42149
|
const os32 = await import("os");
|
|
42096
42150
|
const dir = path45.join(os32.homedir(), ".adhdev", "coordinator-prompts");
|
|
42097
42151
|
const entries = {};
|
|
42098
42152
|
try {
|
|
42099
|
-
if (
|
|
42100
|
-
for (const name of
|
|
42153
|
+
if (fs43.existsSync(dir)) {
|
|
42154
|
+
for (const name of fs43.readdirSync(dir)) {
|
|
42101
42155
|
const matchOverride = name.match(/^([a-zA-Z0-9_.-]+)\.md$/);
|
|
42102
42156
|
const matchAppend = name.match(/^([a-zA-Z0-9_.-]+)\.append\.md$/);
|
|
42103
42157
|
const m = matchAppend || matchOverride;
|
|
@@ -42107,7 +42161,7 @@ var coordinatorPromptHandlers = {
|
|
|
42107
42161
|
const full = path45.join(dir, name);
|
|
42108
42162
|
let content = "";
|
|
42109
42163
|
try {
|
|
42110
|
-
content =
|
|
42164
|
+
content = fs43.readFileSync(full, "utf8");
|
|
42111
42165
|
} catch {
|
|
42112
42166
|
}
|
|
42113
42167
|
if (!entries[key2]) entries[key2] = { override: "", append: "" };
|
|
@@ -42121,7 +42175,7 @@ var coordinatorPromptHandlers = {
|
|
|
42121
42175
|
return { success: true, dir, entries };
|
|
42122
42176
|
},
|
|
42123
42177
|
write_coordinator_prompt: async (_ctx, args) => {
|
|
42124
|
-
const
|
|
42178
|
+
const fs43 = await import("fs");
|
|
42125
42179
|
const path45 = await import("path");
|
|
42126
42180
|
const os32 = await import("os");
|
|
42127
42181
|
const key2 = typeof args?.key === "string" ? args.key.trim() : "";
|
|
@@ -42134,11 +42188,11 @@ var coordinatorPromptHandlers = {
|
|
|
42134
42188
|
const filename = kind === "append" ? `${key2}.append.md` : `${key2}.md`;
|
|
42135
42189
|
const full = path45.join(dir, filename);
|
|
42136
42190
|
try {
|
|
42137
|
-
|
|
42191
|
+
fs43.mkdirSync(dir, { recursive: true });
|
|
42138
42192
|
if (content.trim()) {
|
|
42139
|
-
|
|
42140
|
-
} else if (
|
|
42141
|
-
|
|
42193
|
+
fs43.writeFileSync(full, content, { encoding: "utf8", mode: 384 });
|
|
42194
|
+
} else if (fs43.existsSync(full)) {
|
|
42195
|
+
fs43.unlinkSync(full);
|
|
42142
42196
|
}
|
|
42143
42197
|
return { success: true, path: full, kind, key: key2 };
|
|
42144
42198
|
} catch (error) {
|
|
@@ -42254,21 +42308,21 @@ init_config();
|
|
|
42254
42308
|
// src/commands/upgrade-helper.ts
|
|
42255
42309
|
var import_child_process5 = require("child_process");
|
|
42256
42310
|
var import_child_process6 = require("child_process");
|
|
42257
|
-
var
|
|
42311
|
+
var fs14 = __toESM(require("fs"));
|
|
42258
42312
|
var os13 = __toESM(require("os"));
|
|
42259
42313
|
var path20 = __toESM(require("path"));
|
|
42260
42314
|
var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
42261
42315
|
function getUpgradeLogPath() {
|
|
42262
42316
|
const home = os13.homedir();
|
|
42263
42317
|
const dir = path20.join(home, ".adhdev");
|
|
42264
|
-
|
|
42318
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
42265
42319
|
return path20.join(dir, "daemon-upgrade.log");
|
|
42266
42320
|
}
|
|
42267
42321
|
function appendUpgradeLog(message) {
|
|
42268
42322
|
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
42269
42323
|
`;
|
|
42270
42324
|
try {
|
|
42271
|
-
|
|
42325
|
+
fs14.appendFileSync(getUpgradeLogPath(), line, "utf8");
|
|
42272
42326
|
} catch {
|
|
42273
42327
|
}
|
|
42274
42328
|
}
|
|
@@ -42276,12 +42330,12 @@ function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platfo
|
|
|
42276
42330
|
const binDir = path20.dirname(nodeExecutable);
|
|
42277
42331
|
if (platform10 === "win32") {
|
|
42278
42332
|
const npmCliPath = path20.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
42279
|
-
if (
|
|
42333
|
+
if (fs14.existsSync(npmCliPath)) {
|
|
42280
42334
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
42281
42335
|
}
|
|
42282
42336
|
for (const candidate of ["npm.exe", "npm"]) {
|
|
42283
42337
|
const candidatePath = path20.join(binDir, candidate);
|
|
42284
|
-
if (
|
|
42338
|
+
if (fs14.existsSync(candidatePath)) {
|
|
42285
42339
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
42286
42340
|
}
|
|
42287
42341
|
}
|
|
@@ -42289,7 +42343,7 @@ function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platfo
|
|
|
42289
42343
|
}
|
|
42290
42344
|
for (const candidate of ["npm"]) {
|
|
42291
42345
|
const candidatePath = path20.join(binDir, candidate);
|
|
42292
|
-
if (
|
|
42346
|
+
if (fs14.existsSync(candidatePath)) {
|
|
42293
42347
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
42294
42348
|
}
|
|
42295
42349
|
}
|
|
@@ -42299,12 +42353,12 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
42299
42353
|
if (!currentCliPath) return null;
|
|
42300
42354
|
let resolvedPath = currentCliPath;
|
|
42301
42355
|
try {
|
|
42302
|
-
resolvedPath =
|
|
42356
|
+
resolvedPath = fs14.realpathSync.native(currentCliPath);
|
|
42303
42357
|
} catch {
|
|
42304
42358
|
}
|
|
42305
42359
|
let currentDir = resolvedPath;
|
|
42306
42360
|
try {
|
|
42307
|
-
if (
|
|
42361
|
+
if (fs14.statSync(resolvedPath).isFile()) {
|
|
42308
42362
|
currentDir = path20.dirname(resolvedPath);
|
|
42309
42363
|
}
|
|
42310
42364
|
} catch {
|
|
@@ -42313,8 +42367,8 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
42313
42367
|
while (true) {
|
|
42314
42368
|
const packageJsonPath = path20.join(currentDir, "package.json");
|
|
42315
42369
|
try {
|
|
42316
|
-
if (
|
|
42317
|
-
const parsed = JSON.parse(
|
|
42370
|
+
if (fs14.existsSync(packageJsonPath)) {
|
|
42371
|
+
const parsed = JSON.parse(fs14.readFileSync(packageJsonPath, "utf8"));
|
|
42318
42372
|
if (parsed?.name === packageName) {
|
|
42319
42373
|
const normalized = currentDir.replace(/\\/g, "/");
|
|
42320
42374
|
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
@@ -42455,7 +42509,7 @@ async function waitForPidExit(pid, timeoutMs) {
|
|
|
42455
42509
|
while (Date.now() - start < timeoutMs) {
|
|
42456
42510
|
try {
|
|
42457
42511
|
process.kill(pid, 0);
|
|
42458
|
-
await new Promise((
|
|
42512
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
42459
42513
|
} catch {
|
|
42460
42514
|
return;
|
|
42461
42515
|
}
|
|
@@ -42465,8 +42519,8 @@ async function stopSessionHostProcesses(appName) {
|
|
|
42465
42519
|
const pidFile = path20.join(os13.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
42466
42520
|
let killedPid = null;
|
|
42467
42521
|
try {
|
|
42468
|
-
if (
|
|
42469
|
-
const pid = Number.parseInt(
|
|
42522
|
+
if (fs14.existsSync(pidFile)) {
|
|
42523
|
+
const pid = Number.parseInt(fs14.readFileSync(pidFile, "utf8").trim(), 10);
|
|
42470
42524
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
|
|
42471
42525
|
if (killPid(pid)) killedPid = pid;
|
|
42472
42526
|
}
|
|
@@ -42474,7 +42528,7 @@ async function stopSessionHostProcesses(appName) {
|
|
|
42474
42528
|
} catch {
|
|
42475
42529
|
} finally {
|
|
42476
42530
|
try {
|
|
42477
|
-
|
|
42531
|
+
fs14.unlinkSync(pidFile);
|
|
42478
42532
|
} catch {
|
|
42479
42533
|
}
|
|
42480
42534
|
}
|
|
@@ -42551,7 +42605,7 @@ function getUpgradeFailureNoticePath() {
|
|
|
42551
42605
|
const home = os13.homedir();
|
|
42552
42606
|
const dir = path20.join(home, ".adhdev");
|
|
42553
42607
|
try {
|
|
42554
|
-
|
|
42608
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
42555
42609
|
} catch {
|
|
42556
42610
|
}
|
|
42557
42611
|
return path20.join(dir, "daemon-upgrade-last-error.txt");
|
|
@@ -42564,7 +42618,7 @@ function emitUpgradeFailureNotice(lines) {
|
|
|
42564
42618
|
appendUpgradeLog(`Upgrade blocked \u2014 user action required:
|
|
42565
42619
|
${body}`);
|
|
42566
42620
|
try {
|
|
42567
|
-
|
|
42621
|
+
fs14.writeFileSync(getUpgradeFailureNoticePath(), `[${(/* @__PURE__ */ new Date()).toISOString()}]
|
|
42568
42622
|
${body}
|
|
42569
42623
|
`, "utf8");
|
|
42570
42624
|
} catch {
|
|
@@ -42579,13 +42633,13 @@ function isRetriableInstallLockError(error) {
|
|
|
42579
42633
|
function removeDaemonPidFile() {
|
|
42580
42634
|
const pidFile = path20.join(os13.homedir(), ".adhdev", "daemon.pid");
|
|
42581
42635
|
try {
|
|
42582
|
-
|
|
42636
|
+
fs14.unlinkSync(pidFile);
|
|
42583
42637
|
} catch {
|
|
42584
42638
|
}
|
|
42585
42639
|
}
|
|
42586
42640
|
function safeRemoveStaleEntry(target, label) {
|
|
42587
42641
|
try {
|
|
42588
|
-
|
|
42642
|
+
fs14.rmSync(target, { recursive: true, force: true });
|
|
42589
42643
|
appendUpgradeLog(`${label}: ${target}`);
|
|
42590
42644
|
} catch (error) {
|
|
42591
42645
|
appendUpgradeLog(`Skipped locked stale entry (${error?.code || "error"}): ${target} \u2014 ${error?.message || String(error)}`);
|
|
@@ -42606,19 +42660,19 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
42606
42660
|
if (pkgName.startsWith("@")) {
|
|
42607
42661
|
const [scope, name] = pkgName.split("/");
|
|
42608
42662
|
const scopeDir = path20.join(npmRoot, scope);
|
|
42609
|
-
if (!
|
|
42610
|
-
for (const entry of
|
|
42663
|
+
if (!fs14.existsSync(scopeDir)) return;
|
|
42664
|
+
for (const entry of fs14.readdirSync(scopeDir)) {
|
|
42611
42665
|
if (!entry.startsWith(`.${name}-`)) continue;
|
|
42612
42666
|
safeRemoveStaleEntry(path20.join(scopeDir, entry), "Removed stale scoped staging dir");
|
|
42613
42667
|
}
|
|
42614
42668
|
} else {
|
|
42615
|
-
for (const entry of
|
|
42669
|
+
for (const entry of fs14.readdirSync(npmRoot)) {
|
|
42616
42670
|
if (!entry.startsWith(`.${pkgName}-`)) continue;
|
|
42617
42671
|
safeRemoveStaleEntry(path20.join(npmRoot, entry), "Removed stale staging dir");
|
|
42618
42672
|
}
|
|
42619
42673
|
}
|
|
42620
|
-
if (
|
|
42621
|
-
for (const entry of
|
|
42674
|
+
if (fs14.existsSync(binDir)) {
|
|
42675
|
+
for (const entry of fs14.readdirSync(binDir)) {
|
|
42622
42676
|
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
42623
42677
|
safeRemoveStaleEntry(path20.join(binDir, entry), "Removed stale bin staging entry");
|
|
42624
42678
|
}
|
|
@@ -42681,7 +42735,7 @@ async function runDaemonUpgradeHelper(payload) {
|
|
|
42681
42735
|
appendUpgradeLog(`Install attempt ${attempt} hit a file lock (${error?.code || "lock"}); clearing holders + staging and retrying after backoff`);
|
|
42682
42736
|
await stopForeignNativeAddonHolders(installCommand.surface.packageRoot, { parentPid: payload.parentPid });
|
|
42683
42737
|
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
42684
|
-
await new Promise((
|
|
42738
|
+
await new Promise((resolve26) => setTimeout(resolve26, attempt * 1500));
|
|
42685
42739
|
continue;
|
|
42686
42740
|
}
|
|
42687
42741
|
if (isRetriableInstallLockError(error)) {
|
|
@@ -42709,7 +42763,7 @@ async function runDaemonUpgradeHelper(payload) {
|
|
|
42709
42763
|
appendUpgradeLog(installOutput.trim());
|
|
42710
42764
|
}
|
|
42711
42765
|
if (process.platform === "win32") {
|
|
42712
|
-
await new Promise((
|
|
42766
|
+
await new Promise((resolve26) => setTimeout(resolve26, 500));
|
|
42713
42767
|
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
42714
42768
|
appendUpgradeLog("Post-install staging cleanup complete");
|
|
42715
42769
|
}
|
|
@@ -42874,7 +42928,7 @@ var meshLedgerHandlers = {
|
|
|
42874
42928
|
init_dist();
|
|
42875
42929
|
|
|
42876
42930
|
// src/logging/log-tail-reader.ts
|
|
42877
|
-
var
|
|
42931
|
+
var fs15 = __toESM(require("fs"));
|
|
42878
42932
|
init_logger();
|
|
42879
42933
|
var DEFAULT_TAIL_BYTES = 64 * 1024;
|
|
42880
42934
|
var MAX_TAIL_BYTES = 128 * 1024;
|
|
@@ -42892,9 +42946,9 @@ function clampTailBytes(tailBytes) {
|
|
|
42892
42946
|
return Math.min(Math.floor(tailBytes), MAX_TAIL_BYTES);
|
|
42893
42947
|
}
|
|
42894
42948
|
function readByteBoundedTail(filePath, limitBytes) {
|
|
42895
|
-
const fd =
|
|
42949
|
+
const fd = fs15.openSync(filePath, "r");
|
|
42896
42950
|
try {
|
|
42897
|
-
const stat2 =
|
|
42951
|
+
const stat2 = fs15.fstatSync(fd);
|
|
42898
42952
|
const size = stat2.size;
|
|
42899
42953
|
if (size === 0) return { text: "", truncated: false, bytesReturned: 0 };
|
|
42900
42954
|
const want = Math.min(limitBytes, size);
|
|
@@ -42905,7 +42959,7 @@ function readByteBoundedTail(filePath, limitBytes) {
|
|
|
42905
42959
|
while (position < size) {
|
|
42906
42960
|
const chunkSize = Math.min(READ_CHUNK_BYTES, size - position);
|
|
42907
42961
|
const chunk = Buffer.alloc(chunkSize);
|
|
42908
|
-
|
|
42962
|
+
fs15.readSync(fd, chunk, 0, chunkSize, position);
|
|
42909
42963
|
buffers.push(chunk);
|
|
42910
42964
|
position += chunkSize;
|
|
42911
42965
|
}
|
|
@@ -42918,7 +42972,7 @@ function readByteBoundedTail(filePath, limitBytes) {
|
|
|
42918
42972
|
}
|
|
42919
42973
|
return { text: buf.toString("utf-8"), truncated, bytesReturned: buf.length };
|
|
42920
42974
|
} finally {
|
|
42921
|
-
|
|
42975
|
+
fs15.closeSync(fd);
|
|
42922
42976
|
}
|
|
42923
42977
|
}
|
|
42924
42978
|
function splitLogLines(text) {
|
|
@@ -42996,8 +43050,8 @@ function readDaemonLogTail(args = {}) {
|
|
|
42996
43050
|
const limitBytes = clampTailBytes(args.tailBytes);
|
|
42997
43051
|
const primaryPath = resolveLogPath(args.date);
|
|
42998
43052
|
const backupPath = primaryPath.replace(/\.log$/, ".1.log");
|
|
42999
|
-
const primaryExists =
|
|
43000
|
-
const backupExists =
|
|
43053
|
+
const primaryExists = fs15.existsSync(primaryPath);
|
|
43054
|
+
const backupExists = fs15.existsSync(backupPath);
|
|
43001
43055
|
if (!primaryExists && !backupExists) {
|
|
43002
43056
|
return errorResult(
|
|
43003
43057
|
`No daemon log file at ${primaryPath} (dir: ${getDaemonLogDir()})`,
|
|
@@ -43036,7 +43090,7 @@ function readDaemonLogTail(args = {}) {
|
|
|
43036
43090
|
try {
|
|
43037
43091
|
for (const p of [backupExists ? backupPath : null, primaryExists ? primaryPath : null]) {
|
|
43038
43092
|
if (!p) continue;
|
|
43039
|
-
const buf =
|
|
43093
|
+
const buf = fs15.readFileSync(p);
|
|
43040
43094
|
scannedBytes += buf.length;
|
|
43041
43095
|
allLines = allLines.concat(splitLogLines(buf.toString("utf-8")));
|
|
43042
43096
|
}
|
|
@@ -43240,18 +43294,18 @@ init_summary_metadata();
|
|
|
43240
43294
|
// src/providers/cli-provider-instance.ts
|
|
43241
43295
|
var os21 = __toESM(require("os"));
|
|
43242
43296
|
var crypto5 = __toESM(require("crypto"));
|
|
43243
|
-
var
|
|
43297
|
+
var fs23 = __toESM(require("fs"));
|
|
43244
43298
|
init_contracts2();
|
|
43245
43299
|
init_provider_input_support();
|
|
43246
43300
|
init_hash();
|
|
43247
43301
|
|
|
43248
43302
|
// src/providers/spec/route.ts
|
|
43249
|
-
var
|
|
43303
|
+
var fs21 = __toESM(require("fs"));
|
|
43250
43304
|
var path25 = __toESM(require("path"));
|
|
43251
43305
|
init_provider_cli_adapter();
|
|
43252
43306
|
|
|
43253
43307
|
// src/providers/spec/fsm-driver.ts
|
|
43254
|
-
var
|
|
43308
|
+
var fs17 = __toESM(require("fs"));
|
|
43255
43309
|
var os18 = __toESM(require("os"));
|
|
43256
43310
|
var path23 = __toESM(require("path"));
|
|
43257
43311
|
|
|
@@ -43430,7 +43484,7 @@ init_fsm_types();
|
|
|
43430
43484
|
init_fsm_loader();
|
|
43431
43485
|
|
|
43432
43486
|
// src/providers/spec/pre-launch-trust.ts
|
|
43433
|
-
var
|
|
43487
|
+
var fs16 = __toESM(require("fs"));
|
|
43434
43488
|
var os17 = __toESM(require("os"));
|
|
43435
43489
|
var path22 = __toESM(require("path"));
|
|
43436
43490
|
init_logger();
|
|
@@ -43441,7 +43495,7 @@ function expandHome2(p) {
|
|
|
43441
43495
|
}
|
|
43442
43496
|
function realWorkspacePath(workingDir) {
|
|
43443
43497
|
try {
|
|
43444
|
-
return
|
|
43498
|
+
return fs16.realpathSync(workingDir);
|
|
43445
43499
|
} catch {
|
|
43446
43500
|
return path22.resolve(workingDir);
|
|
43447
43501
|
}
|
|
@@ -43452,8 +43506,8 @@ function applyPreLaunchTrust(trust, workingDir) {
|
|
|
43452
43506
|
const real = realWorkspacePath(workingDir);
|
|
43453
43507
|
try {
|
|
43454
43508
|
let parsed = {};
|
|
43455
|
-
if (
|
|
43456
|
-
const text =
|
|
43509
|
+
if (fs16.existsSync(settingsPath)) {
|
|
43510
|
+
const text = fs16.readFileSync(settingsPath, "utf8");
|
|
43457
43511
|
if (text.trim().length > 0) {
|
|
43458
43512
|
const json = JSON.parse(text);
|
|
43459
43513
|
if (json && typeof json === "object" && !Array.isArray(json)) {
|
|
@@ -43469,8 +43523,8 @@ function applyPreLaunchTrust(trust, workingDir) {
|
|
|
43469
43523
|
}
|
|
43470
43524
|
list.push(real);
|
|
43471
43525
|
parsed[key2] = list;
|
|
43472
|
-
|
|
43473
|
-
|
|
43526
|
+
fs16.mkdirSync(path22.dirname(settingsPath), { recursive: true });
|
|
43527
|
+
fs16.writeFileSync(settingsPath, `${JSON.stringify(parsed, null, 2)}
|
|
43474
43528
|
`, "utf8");
|
|
43475
43529
|
LOG.info("pre-launch-trust", `pre-trusted workspace in ${trust.settings_path} (key="${key2}")`);
|
|
43476
43530
|
return real;
|
|
@@ -43833,7 +43887,7 @@ var FsmDriver = class {
|
|
|
43833
43887
|
try {
|
|
43834
43888
|
const dir = path23.dirname(this.opts.specPath);
|
|
43835
43889
|
const base = path23.basename(this.opts.specPath);
|
|
43836
|
-
this.specWatcher =
|
|
43890
|
+
this.specWatcher = fs17.watch(dir, { persistent: false }, (_event, filename) => {
|
|
43837
43891
|
if (filename && filename !== base) return;
|
|
43838
43892
|
const res = loadFsmSpec(this.opts.specPath);
|
|
43839
43893
|
if (!res.ok) {
|
|
@@ -44469,7 +44523,7 @@ var FsmDriver = class {
|
|
|
44469
44523
|
const ext = guessExt(mime);
|
|
44470
44524
|
const tmp = path23.join(os18.tmpdir(), `adhdev-attach-${Date.now()}${ext}`);
|
|
44471
44525
|
try {
|
|
44472
|
-
|
|
44526
|
+
fs17.writeFileSync(tmp, Buffer.from(blob, "base64"));
|
|
44473
44527
|
} catch {
|
|
44474
44528
|
return;
|
|
44475
44529
|
}
|
|
@@ -44601,7 +44655,7 @@ function filterIgnoredLines(lines, ignoreRe) {
|
|
|
44601
44655
|
init_evaluator();
|
|
44602
44656
|
|
|
44603
44657
|
// src/providers/spec/native-history-executor.ts
|
|
44604
|
-
var
|
|
44658
|
+
var fs18 = __toESM(require("fs"));
|
|
44605
44659
|
var os19 = __toESM(require("os"));
|
|
44606
44660
|
var path24 = __toESM(require("path"));
|
|
44607
44661
|
init_logger();
|
|
@@ -44626,7 +44680,7 @@ function executeJsonl(src, input) {
|
|
|
44626
44680
|
const wsRaw = typeof input.workspace === "string" ? input.workspace : "";
|
|
44627
44681
|
let wsReal = wsRaw;
|
|
44628
44682
|
try {
|
|
44629
|
-
if (wsRaw) wsReal =
|
|
44683
|
+
if (wsRaw) wsReal = fs18.realpathSync(wsRaw);
|
|
44630
44684
|
} catch {
|
|
44631
44685
|
}
|
|
44632
44686
|
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 +44689,26 @@ function executeJsonl(src, input) {
|
|
|
44635
44689
|
const mtime = safeMtimeMs(sourcePath);
|
|
44636
44690
|
const lines = readJsonlLines(sourcePath);
|
|
44637
44691
|
if (lines.length === 0) return null;
|
|
44638
|
-
const transcriptWorkspace = readSessionMetaWorkspace(lines) ?? (src.workspace_from_input ? workspaceFromInputIfSlugMatches(sourcePath, input) : void 0);
|
|
44692
|
+
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
44693
|
let providerSessionId;
|
|
44640
44694
|
if (src.session_id_from === "first_record" && src.session_id_path) {
|
|
44641
44695
|
const v = jsonPathGet(lines[0], src.session_id_path);
|
|
44642
44696
|
if (typeof v === "string" && v) providerSessionId = v;
|
|
44697
|
+
} else if (src.session_id_from === "dir_uuid") {
|
|
44698
|
+
providerSessionId = dirUuid(sourcePath) || void 0;
|
|
44643
44699
|
} else if (src.session_id_from === "filename_uuid" || !src.session_id_from) {
|
|
44644
44700
|
const m = path24.basename(sourcePath).match(UUID_RE);
|
|
44645
44701
|
if (m) providerSessionId = m[1];
|
|
44646
44702
|
}
|
|
44647
44703
|
const requested = readRequestedSessionId(input) || "";
|
|
44648
|
-
if (requested && providerSessionId && providerSessionId
|
|
44649
|
-
const
|
|
44704
|
+
if (requested && providerSessionId && !sameSessionUuid(providerSessionId, requested)) return null;
|
|
44705
|
+
const shapes = compileRecordShapes(src);
|
|
44650
44706
|
const messages = [];
|
|
44651
44707
|
for (let i = 0; i < lines.length; i += 1) {
|
|
44652
44708
|
const rec = lines[i];
|
|
44653
|
-
|
|
44654
|
-
|
|
44709
|
+
const shape = shapes.pick(rec);
|
|
44710
|
+
if (!shape) continue;
|
|
44711
|
+
for (const msg of projectMessages(rec, shape.map, i, lines.length, mtime)) {
|
|
44655
44712
|
if (transcriptWorkspace) msg.workspace = transcriptWorkspace;
|
|
44656
44713
|
messages.push(msg);
|
|
44657
44714
|
}
|
|
@@ -44676,11 +44733,22 @@ function resolveJsonlSourcePath(src, input) {
|
|
|
44676
44733
|
const workspaceHint = typeof input.workspace === "string" && input.workspace.trim() ? input.workspace.trim() : "";
|
|
44677
44734
|
let sourcePath = null;
|
|
44678
44735
|
if (resolved.includes("*")) {
|
|
44679
|
-
|
|
44736
|
+
if (src.session_id_from === "dir_uuid" || src.workspace_from_sidecar) {
|
|
44737
|
+
sourcePath = pickDirUuidFileAcrossGlob(resolved, filePat, requestedSessionId);
|
|
44738
|
+
if (!sourcePath && !requestedSessionId) {
|
|
44739
|
+
if (src.workspace_from_sidecar && workspaceHint) {
|
|
44740
|
+
sourcePath = pickSidecarWorkspaceFileAcrossGlob(resolved, filePat, windowMs, sessionFloor, workspaceHint, src.workspace_from_sidecar);
|
|
44741
|
+
} else {
|
|
44742
|
+
sourcePath = newestRecentFileAcrossGlob(resolved, filePat, windowMs, sessionFloor);
|
|
44743
|
+
}
|
|
44744
|
+
}
|
|
44745
|
+
} else {
|
|
44746
|
+
sourcePath = pickExactSessionFileAcrossGlob(resolved, filePat, requestedSessionId) || pickSessionBoundFileAcrossGlob(resolved, filePat, windowMs, sessionFloor, workspaceHint) || newestRecentFileAcrossGlob(resolved, filePat, windowMs, sessionFloor);
|
|
44747
|
+
}
|
|
44680
44748
|
} else {
|
|
44681
44749
|
let stat2 = null;
|
|
44682
44750
|
try {
|
|
44683
|
-
stat2 =
|
|
44751
|
+
stat2 = fs18.statSync(resolved);
|
|
44684
44752
|
} catch {
|
|
44685
44753
|
}
|
|
44686
44754
|
if (stat2 && stat2.isFile()) {
|
|
@@ -44695,7 +44763,7 @@ function resolveJsonlSourcePath(src, input) {
|
|
|
44695
44763
|
const resolvedRaw = expandPath2(src.path, input, { skipWorkspaceRealpath: true });
|
|
44696
44764
|
if (resolvedRaw && resolvedRaw !== resolved) {
|
|
44697
44765
|
try {
|
|
44698
|
-
const rawStat =
|
|
44766
|
+
const rawStat = fs18.statSync(resolvedRaw);
|
|
44699
44767
|
if (rawStat.isFile()) sourcePath = resolvedRaw;
|
|
44700
44768
|
else if (rawStat.isDirectory()) {
|
|
44701
44769
|
sourcePath = pickExactSessionFile(resolvedRaw, filePat, requestedSessionId) || (requestedSessionId ? null : newestRecentFile(resolvedRaw, filePat, windowMs, sessionFloor));
|
|
@@ -44718,12 +44786,61 @@ function readSessionMetaWorkspace(lines) {
|
|
|
44718
44786
|
}
|
|
44719
44787
|
return void 0;
|
|
44720
44788
|
}
|
|
44789
|
+
function readSidecarWorkspace(sourcePath, cfg) {
|
|
44790
|
+
try {
|
|
44791
|
+
const sidecar = path24.resolve(path24.dirname(sourcePath), cfg.rel_path);
|
|
44792
|
+
const parsed = JSON.parse(fs18.readFileSync(sidecar, "utf8"));
|
|
44793
|
+
const v = jsonPathGet(parsed, cfg.workspace_path);
|
|
44794
|
+
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
44795
|
+
} catch {
|
|
44796
|
+
return void 0;
|
|
44797
|
+
}
|
|
44798
|
+
}
|
|
44799
|
+
function dirUuid(filePath) {
|
|
44800
|
+
const segs = path24.dirname(filePath).split(path24.sep);
|
|
44801
|
+
for (let i = segs.length - 1; i >= 0; i -= 1) {
|
|
44802
|
+
const m = segs[i].match(UUID_RE);
|
|
44803
|
+
if (m) return m[1];
|
|
44804
|
+
}
|
|
44805
|
+
return "";
|
|
44806
|
+
}
|
|
44807
|
+
function sameSessionUuid(a, b) {
|
|
44808
|
+
if (a === b) return true;
|
|
44809
|
+
const ua = a.match(UUID_RE)?.[1]?.toLowerCase();
|
|
44810
|
+
const ub = b.match(UUID_RE)?.[1]?.toLowerCase();
|
|
44811
|
+
return !!ua && !!ub && ua === ub;
|
|
44812
|
+
}
|
|
44813
|
+
function compileRecordShapes(src) {
|
|
44814
|
+
if (Array.isArray(src.records) && src.records.length > 0) {
|
|
44815
|
+
const compiled = src.records.map((r) => ({
|
|
44816
|
+
where: r.where ? compileWhere(r.where) : null,
|
|
44817
|
+
map: r.message_map
|
|
44818
|
+
}));
|
|
44819
|
+
return {
|
|
44820
|
+
pick: (record) => {
|
|
44821
|
+
for (const shape of compiled) {
|
|
44822
|
+
if (!shape.where || shape.where(record)) return { map: shape.map };
|
|
44823
|
+
}
|
|
44824
|
+
return null;
|
|
44825
|
+
}
|
|
44826
|
+
};
|
|
44827
|
+
}
|
|
44828
|
+
const filter = src.message_filter ? compileWhere(src.message_filter.where) : null;
|
|
44829
|
+
const map = src.message_map;
|
|
44830
|
+
return {
|
|
44831
|
+
pick: (record) => {
|
|
44832
|
+
if (!map) return null;
|
|
44833
|
+
if (filter && !filter(record)) return null;
|
|
44834
|
+
return { map };
|
|
44835
|
+
}
|
|
44836
|
+
};
|
|
44837
|
+
}
|
|
44721
44838
|
function workspaceFromInputIfSlugMatches(sourcePath, input) {
|
|
44722
44839
|
const wsRaw = typeof input.workspace === "string" ? input.workspace.trim() : "";
|
|
44723
44840
|
if (!wsRaw) return void 0;
|
|
44724
44841
|
let wsReal = wsRaw;
|
|
44725
44842
|
try {
|
|
44726
|
-
wsReal =
|
|
44843
|
+
wsReal = fs18.realpathSync(wsRaw);
|
|
44727
44844
|
} catch {
|
|
44728
44845
|
}
|
|
44729
44846
|
const slugs = /* @__PURE__ */ new Set();
|
|
@@ -44747,7 +44864,7 @@ function workspaceFromInputIfSlugMatches(sourcePath, input) {
|
|
|
44747
44864
|
function readJsonlLines(p) {
|
|
44748
44865
|
let text;
|
|
44749
44866
|
try {
|
|
44750
|
-
text =
|
|
44867
|
+
text = fs18.readFileSync(p, "utf8");
|
|
44751
44868
|
} catch {
|
|
44752
44869
|
return [];
|
|
44753
44870
|
}
|
|
@@ -44764,7 +44881,7 @@ function readJsonlLines(p) {
|
|
|
44764
44881
|
}
|
|
44765
44882
|
function executeSqlite(src, input) {
|
|
44766
44883
|
const resolved = expandPath2(src.path, input);
|
|
44767
|
-
if (!resolved || !
|
|
44884
|
+
if (!resolved || !fs18.existsSync(resolved)) return null;
|
|
44768
44885
|
let Database;
|
|
44769
44886
|
try {
|
|
44770
44887
|
Database = loadBetterSqlite3();
|
|
@@ -44903,7 +45020,7 @@ function expandPath2(template, input, opts) {
|
|
|
44903
45020
|
let workspaceResolved = workspaceRaw;
|
|
44904
45021
|
if (workspaceRaw && !opts?.skipWorkspaceRealpath) {
|
|
44905
45022
|
try {
|
|
44906
|
-
workspaceResolved =
|
|
45023
|
+
workspaceResolved = fs18.realpathSync(workspaceRaw);
|
|
44907
45024
|
} catch {
|
|
44908
45025
|
}
|
|
44909
45026
|
}
|
|
@@ -44942,7 +45059,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44942
45059
|
if (!base) return null;
|
|
44943
45060
|
let baseStat = null;
|
|
44944
45061
|
try {
|
|
44945
|
-
baseStat =
|
|
45062
|
+
baseStat = fs18.statSync(base);
|
|
44946
45063
|
} catch {
|
|
44947
45064
|
return null;
|
|
44948
45065
|
}
|
|
@@ -44950,7 +45067,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44950
45067
|
const needle = `${requestedSessionId.toLowerCase()}.jsonl`;
|
|
44951
45068
|
const dirsToScan = [base];
|
|
44952
45069
|
try {
|
|
44953
|
-
for (const entry of
|
|
45070
|
+
for (const entry of fs18.readdirSync(base, { withFileTypes: true })) {
|
|
44954
45071
|
if (entry.isDirectory()) dirsToScan.push(path24.join(base, entry.name));
|
|
44955
45072
|
}
|
|
44956
45073
|
} catch {
|
|
@@ -44958,7 +45075,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44958
45075
|
for (const dir of dirsToScan) {
|
|
44959
45076
|
let entries;
|
|
44960
45077
|
try {
|
|
44961
|
-
entries =
|
|
45078
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
44962
45079
|
} catch {
|
|
44963
45080
|
continue;
|
|
44964
45081
|
}
|
|
@@ -44993,7 +45110,7 @@ function expandDirGlob(template) {
|
|
|
44993
45110
|
for (const d of dirs) {
|
|
44994
45111
|
let entries;
|
|
44995
45112
|
try {
|
|
44996
|
-
entries =
|
|
45113
|
+
entries = fs18.readdirSync(d, { withFileTypes: true });
|
|
44997
45114
|
} catch {
|
|
44998
45115
|
continue;
|
|
44999
45116
|
}
|
|
@@ -45006,7 +45123,7 @@ function expandDirGlob(template) {
|
|
|
45006
45123
|
const candidate = path24.join(d, seg);
|
|
45007
45124
|
let stat2 = null;
|
|
45008
45125
|
try {
|
|
45009
|
-
stat2 =
|
|
45126
|
+
stat2 = fs18.statSync(candidate);
|
|
45010
45127
|
} catch {
|
|
45011
45128
|
continue;
|
|
45012
45129
|
}
|
|
@@ -45020,7 +45137,7 @@ function expandDirGlob(template) {
|
|
|
45020
45137
|
function walkAllDirs(root, out) {
|
|
45021
45138
|
let entries;
|
|
45022
45139
|
try {
|
|
45023
|
-
entries =
|
|
45140
|
+
entries = fs18.readdirSync(root, { withFileTypes: true });
|
|
45024
45141
|
} catch {
|
|
45025
45142
|
return;
|
|
45026
45143
|
}
|
|
@@ -45036,7 +45153,7 @@ function newestRecentFileAcrossGlob(template, pattern, windowMs, sessionFloorMs
|
|
|
45036
45153
|
for (const d of dirs) {
|
|
45037
45154
|
let entries;
|
|
45038
45155
|
try {
|
|
45039
|
-
entries =
|
|
45156
|
+
entries = fs18.readdirSync(d, { withFileTypes: true });
|
|
45040
45157
|
} catch {
|
|
45041
45158
|
continue;
|
|
45042
45159
|
}
|
|
@@ -45063,7 +45180,7 @@ function newestRecentFileAcrossDateWindow(template, input, pattern, windowMs, se
|
|
|
45063
45180
|
if (!resolved) continue;
|
|
45064
45181
|
let entries;
|
|
45065
45182
|
try {
|
|
45066
|
-
entries =
|
|
45183
|
+
entries = fs18.readdirSync(resolved, { withFileTypes: true });
|
|
45067
45184
|
} catch {
|
|
45068
45185
|
continue;
|
|
45069
45186
|
}
|
|
@@ -45092,7 +45209,7 @@ function expandPathForDate(template, input, day) {
|
|
|
45092
45209
|
let workspaceResolved = workspaceRaw;
|
|
45093
45210
|
if (workspaceRaw) {
|
|
45094
45211
|
try {
|
|
45095
|
-
workspaceResolved =
|
|
45212
|
+
workspaceResolved = fs18.realpathSync(workspaceRaw);
|
|
45096
45213
|
} catch {
|
|
45097
45214
|
}
|
|
45098
45215
|
}
|
|
@@ -45117,7 +45234,7 @@ function expandPathForDate(template, input, day) {
|
|
|
45117
45234
|
function newestRecentFile(dir, pattern, windowMs, sessionFloorMs = 0) {
|
|
45118
45235
|
let entries;
|
|
45119
45236
|
try {
|
|
45120
|
-
entries =
|
|
45237
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
45121
45238
|
} catch {
|
|
45122
45239
|
return null;
|
|
45123
45240
|
}
|
|
@@ -45134,7 +45251,7 @@ function newestRecentFile(dir, pattern, windowMs, sessionFloorMs = 0) {
|
|
|
45134
45251
|
}
|
|
45135
45252
|
function safeMtimeMs(p) {
|
|
45136
45253
|
try {
|
|
45137
|
-
return Math.floor(
|
|
45254
|
+
return Math.floor(fs18.statSync(p).mtimeMs);
|
|
45138
45255
|
} catch {
|
|
45139
45256
|
return 0;
|
|
45140
45257
|
}
|
|
@@ -45164,6 +45281,47 @@ function pickExactSessionFileAcrossGlob(template, pattern, requestedSessionId) {
|
|
|
45164
45281
|
matches.sort((a, b) => safeMtimeMs(b) - safeMtimeMs(a));
|
|
45165
45282
|
return matches[0] || null;
|
|
45166
45283
|
}
|
|
45284
|
+
function pickDirUuidFileAcrossGlob(template, pattern, requestedSessionId) {
|
|
45285
|
+
if (!requestedSessionId) return null;
|
|
45286
|
+
const wantUuid = requestedSessionId.match(UUID_RE)?.[1]?.toLowerCase();
|
|
45287
|
+
if (!wantUuid) return null;
|
|
45288
|
+
const dirs = expandDirGlob(template);
|
|
45289
|
+
const matches = [];
|
|
45290
|
+
for (const d of dirs) {
|
|
45291
|
+
for (const p of listMatchingFiles(d, pattern)) {
|
|
45292
|
+
if (dirUuid(p).toLowerCase() === wantUuid) matches.push(p);
|
|
45293
|
+
}
|
|
45294
|
+
}
|
|
45295
|
+
matches.sort((a, b) => safeMtimeMs(b) - safeMtimeMs(a));
|
|
45296
|
+
return matches[0] || null;
|
|
45297
|
+
}
|
|
45298
|
+
function pickSidecarWorkspaceFileAcrossGlob(template, pattern, windowMs, sessionFloorMs, workspaceHint, sidecar) {
|
|
45299
|
+
if (!sidecar || !workspaceHint) return null;
|
|
45300
|
+
let wsResolved = workspaceHint;
|
|
45301
|
+
try {
|
|
45302
|
+
wsResolved = fs18.realpathSync(workspaceHint);
|
|
45303
|
+
} catch {
|
|
45304
|
+
}
|
|
45305
|
+
const dirs = expandDirGlob(template);
|
|
45306
|
+
const cutoff = Math.max(Date.now() - windowMs, sessionFloorMs);
|
|
45307
|
+
let best = null;
|
|
45308
|
+
for (const d of dirs) {
|
|
45309
|
+
for (const p of listMatchingFiles(d, pattern)) {
|
|
45310
|
+
const mtime = safeMtimeMs(p);
|
|
45311
|
+
if (mtime < cutoff) continue;
|
|
45312
|
+
const ws = readSidecarWorkspace(p, sidecar);
|
|
45313
|
+
if (!ws) continue;
|
|
45314
|
+
let wsReal = ws;
|
|
45315
|
+
try {
|
|
45316
|
+
wsReal = fs18.realpathSync(ws);
|
|
45317
|
+
} catch {
|
|
45318
|
+
}
|
|
45319
|
+
if (ws !== workspaceHint && wsReal !== wsResolved) continue;
|
|
45320
|
+
if (!best || mtime > best.mtime) best = { p, mtime };
|
|
45321
|
+
}
|
|
45322
|
+
}
|
|
45323
|
+
return best ? best.p : null;
|
|
45324
|
+
}
|
|
45167
45325
|
function pickExactSessionFileAcrossDateWindow(template, input, pattern, requestedSessionId) {
|
|
45168
45326
|
if (!requestedSessionId) return null;
|
|
45169
45327
|
const matches = [];
|
|
@@ -45179,10 +45337,10 @@ function pickExactSessionFileAcrossDateWindow(template, input, pattern, requeste
|
|
|
45179
45337
|
}
|
|
45180
45338
|
function readCandidateSessionMeta(filePath) {
|
|
45181
45339
|
try {
|
|
45182
|
-
const fd =
|
|
45340
|
+
const fd = fs18.openSync(filePath, "r");
|
|
45183
45341
|
try {
|
|
45184
45342
|
const buf = Buffer.alloc(8192);
|
|
45185
|
-
const bytes =
|
|
45343
|
+
const bytes = fs18.readSync(fd, buf, 0, buf.length, 0);
|
|
45186
45344
|
if (bytes <= 0) return null;
|
|
45187
45345
|
const text = buf.subarray(0, bytes).toString("utf8");
|
|
45188
45346
|
const nl = text.indexOf("\n");
|
|
@@ -45200,7 +45358,7 @@ function readCandidateSessionMeta(filePath) {
|
|
|
45200
45358
|
sessionTimestampMs: Number.isFinite(tsMs) ? tsMs : void 0
|
|
45201
45359
|
};
|
|
45202
45360
|
} finally {
|
|
45203
|
-
|
|
45361
|
+
fs18.closeSync(fd);
|
|
45204
45362
|
}
|
|
45205
45363
|
} catch {
|
|
45206
45364
|
return null;
|
|
@@ -45210,7 +45368,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
45210
45368
|
if (!sessionFloorMs || !workspaceHint || candidatePaths.length === 0) return null;
|
|
45211
45369
|
let workspaceResolved = workspaceHint;
|
|
45212
45370
|
try {
|
|
45213
|
-
workspaceResolved =
|
|
45371
|
+
workspaceResolved = fs18.realpathSync(workspaceHint);
|
|
45214
45372
|
} catch {
|
|
45215
45373
|
}
|
|
45216
45374
|
let best = null;
|
|
@@ -45219,7 +45377,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
45219
45377
|
if (!meta || !meta.cwd || meta.sessionTimestampMs == null) continue;
|
|
45220
45378
|
let candidateCwd = meta.cwd;
|
|
45221
45379
|
try {
|
|
45222
|
-
candidateCwd =
|
|
45380
|
+
candidateCwd = fs18.realpathSync(meta.cwd);
|
|
45223
45381
|
} catch {
|
|
45224
45382
|
}
|
|
45225
45383
|
if (candidateCwd !== workspaceResolved && meta.cwd !== workspaceHint) continue;
|
|
@@ -45232,7 +45390,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
45232
45390
|
function listMatchingFiles(dir, pattern) {
|
|
45233
45391
|
let entries;
|
|
45234
45392
|
try {
|
|
45235
|
-
entries =
|
|
45393
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
45236
45394
|
} catch {
|
|
45237
45395
|
return [];
|
|
45238
45396
|
}
|
|
@@ -45526,7 +45684,7 @@ function evalTerm(t, record) {
|
|
|
45526
45684
|
}
|
|
45527
45685
|
|
|
45528
45686
|
// src/providers/spec/background-task-detector.ts
|
|
45529
|
-
var
|
|
45687
|
+
var fs19 = __toESM(require("fs"));
|
|
45530
45688
|
init_logger();
|
|
45531
45689
|
var EMPTY = { active: false, count: 0, ids: [] };
|
|
45532
45690
|
var TAIL_BYTES = 512 * 1024;
|
|
@@ -45588,19 +45746,19 @@ function detectFromRecords(records) {
|
|
|
45588
45746
|
return { active: true, count: unresolved.length, ids: unresolved };
|
|
45589
45747
|
}
|
|
45590
45748
|
function readTailJsonlLines(filePath, maxBytes) {
|
|
45591
|
-
const stat2 =
|
|
45749
|
+
const stat2 = fs19.statSync(filePath);
|
|
45592
45750
|
const size = stat2.size;
|
|
45593
45751
|
const start = size > maxBytes ? size - maxBytes : 0;
|
|
45594
45752
|
const length = size - start;
|
|
45595
45753
|
if (length <= 0) return [];
|
|
45596
|
-
const fd =
|
|
45754
|
+
const fd = fs19.openSync(filePath, "r");
|
|
45597
45755
|
let text;
|
|
45598
45756
|
try {
|
|
45599
45757
|
const buf = Buffer.alloc(length);
|
|
45600
|
-
const bytes =
|
|
45758
|
+
const bytes = fs19.readSync(fd, buf, 0, length, start);
|
|
45601
45759
|
text = buf.subarray(0, bytes).toString("utf8");
|
|
45602
45760
|
} finally {
|
|
45603
|
-
|
|
45761
|
+
fs19.closeSync(fd);
|
|
45604
45762
|
}
|
|
45605
45763
|
const rawLines = text.split("\n");
|
|
45606
45764
|
if (start > 0 && rawLines.length > 0) rawLines.shift();
|
|
@@ -45617,13 +45775,13 @@ function readTailJsonlLines(filePath, maxBytes) {
|
|
|
45617
45775
|
}
|
|
45618
45776
|
|
|
45619
45777
|
// src/providers/spec/cli-adapter.ts
|
|
45620
|
-
var
|
|
45778
|
+
var fs20 = __toESM(require("fs"));
|
|
45621
45779
|
init_logger();
|
|
45622
45780
|
function stripAnsi3(text) {
|
|
45623
45781
|
return String(text || "").replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
45624
45782
|
}
|
|
45625
45783
|
function delay(ms) {
|
|
45626
|
-
return new Promise((
|
|
45784
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
45627
45785
|
}
|
|
45628
45786
|
var SpecCliAdapter = class _SpecCliAdapter {
|
|
45629
45787
|
cliType;
|
|
@@ -45687,7 +45845,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
45687
45845
|
* hermes ships a runtime MCP override. */
|
|
45688
45846
|
spawnedEnv = {};
|
|
45689
45847
|
constructor(specPath, workingDir, cliArgs, extraEnv, transportFactory) {
|
|
45690
|
-
const raw = JSON.parse(
|
|
45848
|
+
const raw = JSON.parse(fs20.readFileSync(specPath, "utf8"));
|
|
45691
45849
|
this.spec = {
|
|
45692
45850
|
id: raw.id,
|
|
45693
45851
|
name: raw.name,
|
|
@@ -45839,7 +45997,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
45839
45997
|
const steps = buildClaudeInteractiveTuiAnswerSteps(prompt, response);
|
|
45840
45998
|
for (const step of steps) {
|
|
45841
45999
|
this.driver.dispatch({ kind: "pty_write", data: step });
|
|
45842
|
-
await new Promise((
|
|
46000
|
+
await new Promise((resolve26) => setTimeout(resolve26, 180));
|
|
45843
46001
|
}
|
|
45844
46002
|
} else {
|
|
45845
46003
|
this.driver.dispatch({ kind: "pty_write", data: `${buildClaudeInteractiveToolResult(response)}
|
|
@@ -46395,7 +46553,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
46395
46553
|
let screenText = this.driver.snapshot();
|
|
46396
46554
|
const deadline = Date.now() + _SpecCliAdapter.CLAUDE_TUI_PAGE_SETTLE_TIMEOUT_MS;
|
|
46397
46555
|
while (!detectClaudeTuiMultiSelect(screenText) && Date.now() < deadline) {
|
|
46398
|
-
await new Promise((
|
|
46556
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
46399
46557
|
screenText = this.driver.snapshot();
|
|
46400
46558
|
}
|
|
46401
46559
|
return screenText;
|
|
@@ -46404,12 +46562,12 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
46404
46562
|
const pages = [{ screenText: firstScreen, header: headers[0] }];
|
|
46405
46563
|
for (let index = 1; index < headers.length; index += 1) {
|
|
46406
46564
|
this.driver.dispatch({ kind: "pty_write", data: " " });
|
|
46407
|
-
await new Promise((
|
|
46565
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
46408
46566
|
pages.push({ screenText: await this.snapshotSettledClaudeTuiPage(), header: headers[index] });
|
|
46409
46567
|
}
|
|
46410
46568
|
for (let index = headers.length - 1; index > 0; index -= 1) {
|
|
46411
46569
|
this.driver.dispatch({ kind: "pty_write", data: "\x1B[Z" });
|
|
46412
|
-
await new Promise((
|
|
46570
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
46413
46571
|
const reread = await this.snapshotSettledClaudeTuiPage();
|
|
46414
46572
|
const landed = pages[index - 1];
|
|
46415
46573
|
if (landed && !detectClaudeTuiMultiSelect(landed.screenText) && detectClaudeTuiMultiSelect(reread)) {
|
|
@@ -46509,10 +46667,10 @@ init_logger();
|
|
|
46509
46667
|
function createCliAdapter(provider, workingDir, cliArgs, extraEnv, transportFactory) {
|
|
46510
46668
|
const resolvedSpecPath = provider._resolvedSpecPath;
|
|
46511
46669
|
const dir = provider._resolvedProviderDir;
|
|
46512
|
-
let specPath = resolvedSpecPath &&
|
|
46670
|
+
let specPath = resolvedSpecPath && fs21.existsSync(resolvedSpecPath) ? resolvedSpecPath : void 0;
|
|
46513
46671
|
if (!specPath && dir) {
|
|
46514
46672
|
const legacy = path25.join(dir, "spec.json");
|
|
46515
|
-
if (
|
|
46673
|
+
if (fs21.existsSync(legacy)) specPath = legacy;
|
|
46516
46674
|
}
|
|
46517
46675
|
if (specPath) {
|
|
46518
46676
|
try {
|
|
@@ -46597,7 +46755,7 @@ init_working_dir();
|
|
|
46597
46755
|
var os20 = __toESM(require("os"));
|
|
46598
46756
|
var path26 = __toESM(require("path"));
|
|
46599
46757
|
var crypto4 = __toESM(require("crypto"));
|
|
46600
|
-
var
|
|
46758
|
+
var fs22 = __toESM(require("fs"));
|
|
46601
46759
|
var IMAGE_MIME_EXTENSIONS = {
|
|
46602
46760
|
"image/png": ".png",
|
|
46603
46761
|
"image/jpeg": ".jpg",
|
|
@@ -46632,9 +46790,9 @@ function materializeImageDataPart(part, index, dir) {
|
|
|
46632
46790
|
if (!part.data) return null;
|
|
46633
46791
|
const rawData = part.data.includes(",") ? part.data.split(",").pop() || "" : part.data;
|
|
46634
46792
|
if (!rawData) return null;
|
|
46635
|
-
|
|
46793
|
+
fs22.mkdirSync(dir, { recursive: true });
|
|
46636
46794
|
const filePath = path26.join(dir, safeInputImageBasename(index, part.mimeType));
|
|
46637
|
-
|
|
46795
|
+
fs22.writeFileSync(filePath, Buffer.from(rawData, "base64"));
|
|
46638
46796
|
cleanupStaleMaterializedImages(dir);
|
|
46639
46797
|
return filePath;
|
|
46640
46798
|
}
|
|
@@ -46646,14 +46804,14 @@ function cleanupStaleMaterializedImages(dir) {
|
|
|
46646
46804
|
if (now - lastMaterializedImageCleanupAt < MATERIALIZED_IMAGE_CLEANUP_INTERVAL_MS) return;
|
|
46647
46805
|
lastMaterializedImageCleanupAt = now;
|
|
46648
46806
|
try {
|
|
46649
|
-
const entries =
|
|
46807
|
+
const entries = fs22.readdirSync(dir);
|
|
46650
46808
|
for (const entry of entries) {
|
|
46651
46809
|
if (!entry.startsWith("adhdev-input-image-")) continue;
|
|
46652
46810
|
const fullPath = path26.join(dir, entry);
|
|
46653
46811
|
try {
|
|
46654
|
-
const stat2 =
|
|
46812
|
+
const stat2 = fs22.statSync(fullPath);
|
|
46655
46813
|
if (now - stat2.mtimeMs > MATERIALIZED_IMAGE_MAX_AGE_MS) {
|
|
46656
|
-
|
|
46814
|
+
fs22.unlinkSync(fullPath);
|
|
46657
46815
|
}
|
|
46658
46816
|
} catch {
|
|
46659
46817
|
}
|
|
@@ -46800,7 +46958,7 @@ async function waitForCliAdapterReady(adapter, options) {
|
|
|
46800
46958
|
if (status === "stopped") {
|
|
46801
46959
|
throw new Error("CLI runtime stopped before it became ready");
|
|
46802
46960
|
}
|
|
46803
|
-
await new Promise((
|
|
46961
|
+
await new Promise((resolve26) => setTimeout(resolve26, pollMs));
|
|
46804
46962
|
}
|
|
46805
46963
|
throw new Error(`CLI runtime did not become ready within ${timeoutMs}ms`);
|
|
46806
46964
|
}
|
|
@@ -47314,7 +47472,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47314
47472
|
const resolvedDbPath = probe.dbPath.replace(/^~/, os21.homedir());
|
|
47315
47473
|
const now = Date.now();
|
|
47316
47474
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
47317
|
-
if (!
|
|
47475
|
+
if (!fs23.existsSync(resolvedDbPath)) {
|
|
47318
47476
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
47319
47477
|
return null;
|
|
47320
47478
|
}
|
|
@@ -47898,7 +48056,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47898
48056
|
const enterCount = cliCommand.enterCount || 1;
|
|
47899
48057
|
await this.adapter.writeRaw(cliCommand.text + "\r");
|
|
47900
48058
|
for (let i = 1; i < enterCount; i += 1) {
|
|
47901
|
-
await new Promise((
|
|
48059
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
47902
48060
|
await this.adapter.writeRaw("\r");
|
|
47903
48061
|
}
|
|
47904
48062
|
}
|
|
@@ -47992,7 +48150,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47992
48150
|
}
|
|
47993
48151
|
if (this.lastExternalCompletionProbe?.sourcePath) {
|
|
47994
48152
|
try {
|
|
47995
|
-
|
|
48153
|
+
fs23.statSync(this.lastExternalCompletionProbe.sourcePath);
|
|
47996
48154
|
} catch {
|
|
47997
48155
|
}
|
|
47998
48156
|
}
|
|
@@ -49688,7 +49846,7 @@ ${buttons.join("\n")}`;
|
|
|
49688
49846
|
};
|
|
49689
49847
|
addDir(this.workingDir);
|
|
49690
49848
|
try {
|
|
49691
|
-
addDir(
|
|
49849
|
+
addDir(fs23.realpathSync.native(this.workingDir));
|
|
49692
49850
|
} catch {
|
|
49693
49851
|
}
|
|
49694
49852
|
return Array.from(dirs);
|
|
@@ -50358,13 +50516,13 @@ var AcpProviderInstance = class {
|
|
|
50358
50516
|
}
|
|
50359
50517
|
this.currentStatus = "waiting_approval";
|
|
50360
50518
|
this.detectStatusTransition();
|
|
50361
|
-
const approved = await new Promise((
|
|
50362
|
-
this.permissionResolvers.push(
|
|
50519
|
+
const approved = await new Promise((resolve26) => {
|
|
50520
|
+
this.permissionResolvers.push(resolve26);
|
|
50363
50521
|
setTimeout(() => {
|
|
50364
|
-
const idx = this.permissionResolvers.indexOf(
|
|
50522
|
+
const idx = this.permissionResolvers.indexOf(resolve26);
|
|
50365
50523
|
if (idx >= 0) {
|
|
50366
50524
|
this.permissionResolvers.splice(idx, 1);
|
|
50367
|
-
|
|
50525
|
+
resolve26(false);
|
|
50368
50526
|
}
|
|
50369
50527
|
}, 3e5);
|
|
50370
50528
|
});
|
|
@@ -51100,7 +51258,7 @@ async function waitForZeroMessageStartingLaunch(adapter) {
|
|
|
51100
51258
|
} catch {
|
|
51101
51259
|
return false;
|
|
51102
51260
|
}
|
|
51103
|
-
await new Promise((
|
|
51261
|
+
await new Promise((resolve26) => setTimeout(resolve26, ZERO_MESSAGE_STARTING_SEND_WAIT_MS));
|
|
51104
51262
|
try {
|
|
51105
51263
|
return hasZeroMessageStartingLaunch(adapter);
|
|
51106
51264
|
} catch {
|
|
@@ -52415,7 +52573,7 @@ var os27 = __toESM(require("os"));
|
|
|
52415
52573
|
var path37 = __toESM(require("path"));
|
|
52416
52574
|
|
|
52417
52575
|
// src/providers/provider-loader.ts
|
|
52418
|
-
var
|
|
52576
|
+
var fs29 = __toESM(require("fs"));
|
|
52419
52577
|
var path36 = __toESM(require("path"));
|
|
52420
52578
|
var os26 = __toESM(require("os"));
|
|
52421
52579
|
var chokidar = __toESM(require("chokidar"));
|
|
@@ -52815,12 +52973,12 @@ function validateControl(control, errors) {
|
|
|
52815
52973
|
init_external_sources();
|
|
52816
52974
|
|
|
52817
52975
|
// src/providers/native-history/dispatcher.ts
|
|
52818
|
-
var
|
|
52976
|
+
var fs28 = __toESM(require("fs"));
|
|
52819
52977
|
var os25 = __toESM(require("os"));
|
|
52820
52978
|
var path34 = __toESM(require("path"));
|
|
52821
52979
|
|
|
52822
52980
|
// src/providers/native-history/claude-cli-transcript.ts
|
|
52823
|
-
var
|
|
52981
|
+
var fs24 = __toESM(require("fs"));
|
|
52824
52982
|
var path30 = __toESM(require("path"));
|
|
52825
52983
|
function extractTimestampValue(value) {
|
|
52826
52984
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
@@ -52834,7 +52992,7 @@ function extractTimestampValue(value) {
|
|
|
52834
52992
|
}
|
|
52835
52993
|
function statMtimeMs(filePath) {
|
|
52836
52994
|
try {
|
|
52837
|
-
return
|
|
52995
|
+
return fs24.statSync(filePath).mtimeMs;
|
|
52838
52996
|
} catch {
|
|
52839
52997
|
return 0;
|
|
52840
52998
|
}
|
|
@@ -52904,7 +53062,7 @@ function extractUserContentParts(content) {
|
|
|
52904
53062
|
function parseTranscriptFile(filePath, sessionId, workspaceFallback) {
|
|
52905
53063
|
let raw;
|
|
52906
53064
|
try {
|
|
52907
|
-
raw =
|
|
53065
|
+
raw = fs24.readFileSync(filePath, "utf-8");
|
|
52908
53066
|
} catch {
|
|
52909
53067
|
return [];
|
|
52910
53068
|
}
|
|
@@ -52980,7 +53138,7 @@ function readSession(sessionPath) {
|
|
|
52980
53138
|
if (!sessionPath || !path30.isAbsolute(sessionPath)) return null;
|
|
52981
53139
|
const basename14 = path30.basename(sessionPath, ".jsonl");
|
|
52982
53140
|
if (!isSafeSessionId(basename14)) return null;
|
|
52983
|
-
if (!
|
|
53141
|
+
if (!fs24.existsSync(sessionPath)) return null;
|
|
52984
53142
|
const sourceMtimeMs = statMtimeMs(sessionPath);
|
|
52985
53143
|
const messages = parseTranscriptFile(sessionPath, basename14);
|
|
52986
53144
|
if (messages.length === 0) return null;
|
|
@@ -52998,7 +53156,7 @@ function readSession(sessionPath) {
|
|
|
52998
53156
|
}
|
|
52999
53157
|
|
|
53000
53158
|
// src/providers/native-history/codex-cli-transcript.ts
|
|
53001
|
-
var
|
|
53159
|
+
var fs25 = __toESM(require("fs"));
|
|
53002
53160
|
var path31 = __toESM(require("path"));
|
|
53003
53161
|
function extractTimestampValue2(value) {
|
|
53004
53162
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
@@ -53012,7 +53170,7 @@ function extractTimestampValue2(value) {
|
|
|
53012
53170
|
}
|
|
53013
53171
|
function statMtimeMs2(filePath) {
|
|
53014
53172
|
try {
|
|
53015
|
-
return
|
|
53173
|
+
return fs25.statSync(filePath).mtimeMs;
|
|
53016
53174
|
} catch {
|
|
53017
53175
|
return 0;
|
|
53018
53176
|
}
|
|
@@ -53109,7 +53267,7 @@ function pushAssistantStandardMessage(records, sessionId, receivedAt, content, w
|
|
|
53109
53267
|
}
|
|
53110
53268
|
function readSessionMeta(filePath) {
|
|
53111
53269
|
try {
|
|
53112
|
-
const firstLine =
|
|
53270
|
+
const firstLine = fs25.readFileSync(filePath, "utf-8").split("\n").find(Boolean);
|
|
53113
53271
|
if (!firstLine) return null;
|
|
53114
53272
|
const parsed = JSON.parse(firstLine);
|
|
53115
53273
|
if (String(parsed.type ?? "") !== "session_meta") return null;
|
|
@@ -53121,7 +53279,7 @@ function readSessionMeta(filePath) {
|
|
|
53121
53279
|
function parseSessionFile(filePath, sessionId, workspaceFallback) {
|
|
53122
53280
|
let raw;
|
|
53123
53281
|
try {
|
|
53124
|
-
raw =
|
|
53282
|
+
raw = fs25.readFileSync(filePath, "utf-8");
|
|
53125
53283
|
} catch {
|
|
53126
53284
|
return [];
|
|
53127
53285
|
}
|
|
@@ -53237,7 +53395,7 @@ function parseSessionFile(filePath, sessionId, workspaceFallback) {
|
|
|
53237
53395
|
}
|
|
53238
53396
|
function readSession2(sessionPath) {
|
|
53239
53397
|
if (!sessionPath || !path31.isAbsolute(sessionPath)) return null;
|
|
53240
|
-
if (!
|
|
53398
|
+
if (!fs25.existsSync(sessionPath)) return null;
|
|
53241
53399
|
const meta = readSessionMeta(sessionPath);
|
|
53242
53400
|
const metaId = String(meta?.id ?? "").trim();
|
|
53243
53401
|
const basename14 = path31.basename(sessionPath, ".jsonl");
|
|
@@ -53264,7 +53422,7 @@ function readSession2(sessionPath) {
|
|
|
53264
53422
|
}
|
|
53265
53423
|
|
|
53266
53424
|
// src/providers/native-history/antigravity-cli-transcript.ts
|
|
53267
|
-
var
|
|
53425
|
+
var fs26 = __toESM(require("fs"));
|
|
53268
53426
|
var path32 = __toESM(require("path"));
|
|
53269
53427
|
var os23 = __toESM(require("os"));
|
|
53270
53428
|
init_load_better_sqlite3();
|
|
@@ -53281,7 +53439,7 @@ function extractTimestampValue3(value) {
|
|
|
53281
53439
|
}
|
|
53282
53440
|
function statMtimeMs3(filePath) {
|
|
53283
53441
|
try {
|
|
53284
|
-
return
|
|
53442
|
+
return fs26.statSync(filePath).mtimeMs;
|
|
53285
53443
|
} catch {
|
|
53286
53444
|
return 0;
|
|
53287
53445
|
}
|
|
@@ -53310,12 +53468,12 @@ function resolvePathInside(root, ...segments) {
|
|
|
53310
53468
|
function findBrainTranscriptPath(sessionId) {
|
|
53311
53469
|
if (!isUuidLike(sessionId)) return null;
|
|
53312
53470
|
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 &&
|
|
53471
|
+
if (!logsRoot || !fs26.existsSync(logsRoot)) return null;
|
|
53472
|
+
const candidates = ["transcript_full.jsonl", "transcript.jsonl"].map((file) => resolvePathInside(logsRoot, file)).filter((p) => p !== null && fs26.existsSync(p));
|
|
53315
53473
|
if (candidates.length === 0) {
|
|
53316
53474
|
let entries = [];
|
|
53317
53475
|
try {
|
|
53318
|
-
entries =
|
|
53476
|
+
entries = fs26.readdirSync(logsRoot, { withFileTypes: true });
|
|
53319
53477
|
} catch {
|
|
53320
53478
|
return null;
|
|
53321
53479
|
}
|
|
@@ -53341,7 +53499,7 @@ function antigravityRowKind(rowType) {
|
|
|
53341
53499
|
function parseBrainTranscript(filePath, sessionId, workspace) {
|
|
53342
53500
|
let raw;
|
|
53343
53501
|
try {
|
|
53344
|
-
raw =
|
|
53502
|
+
raw = fs26.readFileSync(filePath, "utf-8");
|
|
53345
53503
|
} catch {
|
|
53346
53504
|
return null;
|
|
53347
53505
|
}
|
|
@@ -53401,7 +53559,7 @@ function readHistoryRows() {
|
|
|
53401
53559
|
const sourcePath = historyJsonlPath();
|
|
53402
53560
|
let lines = [];
|
|
53403
53561
|
try {
|
|
53404
|
-
lines =
|
|
53562
|
+
lines = fs26.readFileSync(sourcePath, "utf-8").split("\n").filter(Boolean);
|
|
53405
53563
|
} catch {
|
|
53406
53564
|
return [];
|
|
53407
53565
|
}
|
|
@@ -53449,7 +53607,7 @@ function extractStringsFromBuffer(buf) {
|
|
|
53449
53607
|
function parsePbFile(filePath, sessionId) {
|
|
53450
53608
|
let buf;
|
|
53451
53609
|
try {
|
|
53452
|
-
buf =
|
|
53610
|
+
buf = fs26.readFileSync(filePath);
|
|
53453
53611
|
} catch {
|
|
53454
53612
|
return null;
|
|
53455
53613
|
}
|
|
@@ -53797,7 +53955,7 @@ function readAntigravitySiblingFallback(sessionId, workspace) {
|
|
|
53797
53955
|
}
|
|
53798
53956
|
}
|
|
53799
53957
|
const pbPath = resolvePathInside(conversationsRoot(), `${sessionId}.pb`);
|
|
53800
|
-
if (pbPath &&
|
|
53958
|
+
if (pbPath && fs26.existsSync(pbPath)) {
|
|
53801
53959
|
const pbMessages = parsePbFile(pbPath, sessionId);
|
|
53802
53960
|
if (pbMessages && pbMessages.length > 0) {
|
|
53803
53961
|
return {
|
|
@@ -53816,7 +53974,7 @@ function readAntigravitySiblingFallback(sessionId, workspace) {
|
|
|
53816
53974
|
}
|
|
53817
53975
|
function readSession3(sessionPath, sessionId, workspace) {
|
|
53818
53976
|
if (!sessionPath || !path32.isAbsolute(sessionPath)) return null;
|
|
53819
|
-
if (!
|
|
53977
|
+
if (!fs26.existsSync(sessionPath)) return null;
|
|
53820
53978
|
const sourceMtimeMs = statMtimeMs3(sessionPath);
|
|
53821
53979
|
const brainRootPath = brainRoot();
|
|
53822
53980
|
if (sessionPath.startsWith(brainRootPath + path32.sep) && sessionPath.endsWith(".jsonl")) {
|
|
@@ -53877,7 +54035,7 @@ function readSession3(sessionPath, sessionId, workspace) {
|
|
|
53877
54035
|
}
|
|
53878
54036
|
|
|
53879
54037
|
// src/providers/native-history/hermes-cli-transcript.ts
|
|
53880
|
-
var
|
|
54038
|
+
var fs27 = __toESM(require("fs"));
|
|
53881
54039
|
var path33 = __toESM(require("path"));
|
|
53882
54040
|
var os24 = __toESM(require("os"));
|
|
53883
54041
|
init_load_better_sqlite3();
|
|
@@ -53885,13 +54043,13 @@ var HERMES_STATE_DB = path33.join(os24.homedir(), ".hermes", "state.db");
|
|
|
53885
54043
|
var HERMES_LEGACY_SESSIONS_DIR = path33.join(os24.homedir(), ".hermes", "sessions");
|
|
53886
54044
|
function statMtimeMs4(p) {
|
|
53887
54045
|
try {
|
|
53888
|
-
return Math.floor(
|
|
54046
|
+
return Math.floor(fs27.statSync(p).mtimeMs);
|
|
53889
54047
|
} catch {
|
|
53890
54048
|
return 0;
|
|
53891
54049
|
}
|
|
53892
54050
|
}
|
|
53893
54051
|
function openDb() {
|
|
53894
|
-
if (!
|
|
54052
|
+
if (!fs27.existsSync(HERMES_STATE_DB)) return null;
|
|
53895
54053
|
try {
|
|
53896
54054
|
const Database = loadBetterSqlite3();
|
|
53897
54055
|
return new Database(HERMES_STATE_DB, { readonly: true, fileMustExist: true });
|
|
@@ -53987,10 +54145,10 @@ function readSession4(sessionPath, requestedSessionId) {
|
|
|
53987
54145
|
}
|
|
53988
54146
|
}
|
|
53989
54147
|
}
|
|
53990
|
-
if (!path33.isAbsolute(sessionPath) || !
|
|
54148
|
+
if (!path33.isAbsolute(sessionPath) || !fs27.existsSync(sessionPath)) return null;
|
|
53991
54149
|
let raw;
|
|
53992
54150
|
try {
|
|
53993
|
-
raw = JSON.parse(
|
|
54151
|
+
raw = JSON.parse(fs27.readFileSync(sessionPath, "utf8"));
|
|
53994
54152
|
} catch {
|
|
53995
54153
|
return null;
|
|
53996
54154
|
}
|
|
@@ -54045,7 +54203,7 @@ function createNativeHistoryDispatcher(reader) {
|
|
|
54045
54203
|
const ownerConfirmed = reader === "antigravity-cli" ? resolved?.ownerConfirmed === true : void 0;
|
|
54046
54204
|
if (input.forceRefresh === true || input.args?.forceRefresh === true) {
|
|
54047
54205
|
try {
|
|
54048
|
-
|
|
54206
|
+
fs28.statSync(sourcePath);
|
|
54049
54207
|
} catch {
|
|
54050
54208
|
}
|
|
54051
54209
|
}
|
|
@@ -54097,10 +54255,10 @@ function resolveSourcePath(reader, workspace, sessionId, sessionStartedAtMs, ins
|
|
|
54097
54255
|
}
|
|
54098
54256
|
function resolveClaudePath(workspace, sessionId) {
|
|
54099
54257
|
const dir = path34.join(os25.homedir(), ".claude", "projects", cwdAsDashes(workspace));
|
|
54100
|
-
if (!
|
|
54258
|
+
if (!fs28.existsSync(dir)) return null;
|
|
54101
54259
|
if (sessionId) {
|
|
54102
54260
|
const candidate = path34.join(dir, `${sessionId}.jsonl`);
|
|
54103
|
-
if (
|
|
54261
|
+
if (fs28.existsSync(candidate)) return candidate;
|
|
54104
54262
|
}
|
|
54105
54263
|
return null;
|
|
54106
54264
|
}
|
|
@@ -54112,7 +54270,7 @@ function resolveCodexPath(workspace, sessionId, sessionStartedAtMs) {
|
|
|
54112
54270
|
return findCodexPathByRuntime(root, workspace, sessionStartedAtMs);
|
|
54113
54271
|
}
|
|
54114
54272
|
function findCodexPathBySessionId(root, sessionId) {
|
|
54115
|
-
if (!
|
|
54273
|
+
if (!fs28.existsSync(root)) return null;
|
|
54116
54274
|
const needle = sessionId.toLowerCase();
|
|
54117
54275
|
const matches = [];
|
|
54118
54276
|
const stack = [root];
|
|
@@ -54120,7 +54278,7 @@ function findCodexPathBySessionId(root, sessionId) {
|
|
|
54120
54278
|
const current = stack.pop();
|
|
54121
54279
|
let entries = [];
|
|
54122
54280
|
try {
|
|
54123
|
-
entries =
|
|
54281
|
+
entries = fs28.readdirSync(current, { withFileTypes: true });
|
|
54124
54282
|
} catch {
|
|
54125
54283
|
continue;
|
|
54126
54284
|
}
|
|
@@ -54140,7 +54298,7 @@ function findCodexPathBySessionId(root, sessionId) {
|
|
|
54140
54298
|
return matches[0]?.p ?? null;
|
|
54141
54299
|
}
|
|
54142
54300
|
function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
54143
|
-
if (!
|
|
54301
|
+
if (!fs28.existsSync(root) || !workspace) return null;
|
|
54144
54302
|
const workspaceResolved = resolveRealPath(workspace);
|
|
54145
54303
|
const cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
54146
54304
|
const matches = [];
|
|
@@ -54149,7 +54307,7 @@ function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
|
54149
54307
|
const current = stack.pop();
|
|
54150
54308
|
let entries = [];
|
|
54151
54309
|
try {
|
|
54152
|
-
entries =
|
|
54310
|
+
entries = fs28.readdirSync(current, { withFileTypes: true });
|
|
54153
54311
|
} catch {
|
|
54154
54312
|
continue;
|
|
54155
54313
|
}
|
|
@@ -54174,10 +54332,10 @@ function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
|
54174
54332
|
}
|
|
54175
54333
|
function readCodexSessionMeta(filePath) {
|
|
54176
54334
|
try {
|
|
54177
|
-
const fd =
|
|
54335
|
+
const fd = fs28.openSync(filePath, "r");
|
|
54178
54336
|
try {
|
|
54179
54337
|
const buffer = Buffer.alloc(8192);
|
|
54180
|
-
const bytes =
|
|
54338
|
+
const bytes = fs28.readSync(fd, buffer, 0, buffer.length, 0);
|
|
54181
54339
|
if (bytes <= 0) return null;
|
|
54182
54340
|
const text = buffer.subarray(0, bytes).toString("utf8");
|
|
54183
54341
|
const firstLine = text.slice(0, text.indexOf("\n") >= 0 ? text.indexOf("\n") : text.length).trim();
|
|
@@ -54192,7 +54350,7 @@ function readCodexSessionMeta(filePath) {
|
|
|
54192
54350
|
timestampMs: Number.isFinite(timestampMs) ? timestampMs : void 0
|
|
54193
54351
|
};
|
|
54194
54352
|
} finally {
|
|
54195
|
-
|
|
54353
|
+
fs28.closeSync(fd);
|
|
54196
54354
|
}
|
|
54197
54355
|
} catch {
|
|
54198
54356
|
return null;
|
|
@@ -54200,7 +54358,7 @@ function readCodexSessionMeta(filePath) {
|
|
|
54200
54358
|
}
|
|
54201
54359
|
function resolveRealPath(value) {
|
|
54202
54360
|
try {
|
|
54203
|
-
return
|
|
54361
|
+
return fs28.realpathSync(value);
|
|
54204
54362
|
} catch {
|
|
54205
54363
|
return value;
|
|
54206
54364
|
}
|
|
@@ -54222,19 +54380,19 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
|
|
|
54222
54380
|
const owner = antigravityOwnerToken(workspace, sessionStartedAtMs, instanceId);
|
|
54223
54381
|
if (sessionId && isUuidLikeSessionId2(sessionId)) {
|
|
54224
54382
|
const dbPath = path34.join(agyRoot, "conversations", `${sessionId}.db`);
|
|
54225
|
-
if (
|
|
54383
|
+
if (fs28.existsSync(dbPath)) {
|
|
54226
54384
|
if (owner) claimAntigravityConversation(sessionId, owner);
|
|
54227
54385
|
return { path: dbPath, ownerConfirmed: true };
|
|
54228
54386
|
}
|
|
54229
54387
|
}
|
|
54230
54388
|
const brainRoot2 = path34.join(agyRoot, "brain");
|
|
54231
|
-
if (
|
|
54389
|
+
if (fs28.existsSync(brainRoot2)) {
|
|
54232
54390
|
const cutoff = spawnAwareCutoff(sessionStartedAtMs);
|
|
54233
54391
|
const nonEmptyBrain = (uuid, p) => {
|
|
54234
54392
|
const t = path34.join(p, ".system_generated", "logs", "transcript.jsonl");
|
|
54235
|
-
return
|
|
54393
|
+
return fs28.existsSync(t) && safeSize(t) > 0 ? t : null;
|
|
54236
54394
|
};
|
|
54237
|
-
const all =
|
|
54395
|
+
const all = fs28.readdirSync(brainRoot2, { withFileTypes: true }).filter((e) => e.isDirectory() && isUuidLikeSessionId2(e.name)).filter((e) => !isAntigravityConversationClaimedByOther(e.name, owner)).map((e) => {
|
|
54238
54396
|
const p = path34.join(brainRoot2, e.name);
|
|
54239
54397
|
return { uuid: e.name, p, mtime: safeMtime(p), birth: safeBirthtime(p) };
|
|
54240
54398
|
}).filter((e) => e.mtime >= cutoff);
|
|
@@ -54265,7 +54423,7 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
|
|
|
54265
54423
|
function pickUnboundConversationDb(convRoot, sessionFloorMs, owner) {
|
|
54266
54424
|
let entries = [];
|
|
54267
54425
|
try {
|
|
54268
|
-
entries =
|
|
54426
|
+
entries = fs28.readdirSync(convRoot, { withFileTypes: true });
|
|
54269
54427
|
} catch {
|
|
54270
54428
|
return null;
|
|
54271
54429
|
}
|
|
@@ -54303,9 +54461,9 @@ function resolveHermesPath(workspace, sessionId) {
|
|
|
54303
54461
|
void workspace;
|
|
54304
54462
|
void sessionId;
|
|
54305
54463
|
const dbPath = path34.join(os25.homedir(), ".hermes", "state.db");
|
|
54306
|
-
if (
|
|
54464
|
+
if (fs28.existsSync(dbPath)) return dbPath;
|
|
54307
54465
|
const dir = path34.join(os25.homedir(), ".hermes", "sessions");
|
|
54308
|
-
if (!
|
|
54466
|
+
if (!fs28.existsSync(dir)) return null;
|
|
54309
54467
|
return newestRecentFile2(dir, /^session_.*\.json$/);
|
|
54310
54468
|
}
|
|
54311
54469
|
function readByReader(reader, sourcePath, sessionId, workspace, requestedProviderSid) {
|
|
@@ -54342,7 +54500,7 @@ var RECENT_WINDOW_MS = 5 * 60 * 1e3;
|
|
|
54342
54500
|
function newestRecentFile2(dir, pattern) {
|
|
54343
54501
|
try {
|
|
54344
54502
|
const cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
54345
|
-
const entries =
|
|
54503
|
+
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
54504
|
return entries[0]?.p ?? null;
|
|
54347
54505
|
} catch {
|
|
54348
54506
|
return null;
|
|
@@ -54350,14 +54508,14 @@ function newestRecentFile2(dir, pattern) {
|
|
|
54350
54508
|
}
|
|
54351
54509
|
function safeMtime(p) {
|
|
54352
54510
|
try {
|
|
54353
|
-
return Math.floor(
|
|
54511
|
+
return Math.floor(fs28.statSync(p).mtimeMs);
|
|
54354
54512
|
} catch {
|
|
54355
54513
|
return 0;
|
|
54356
54514
|
}
|
|
54357
54515
|
}
|
|
54358
54516
|
function safeBirthtime(p) {
|
|
54359
54517
|
try {
|
|
54360
|
-
const st =
|
|
54518
|
+
const st = fs28.statSync(p);
|
|
54361
54519
|
const birth = Math.floor(st.birthtimeMs);
|
|
54362
54520
|
return birth > 0 ? birth : Math.floor(st.mtimeMs);
|
|
54363
54521
|
} catch {
|
|
@@ -54366,7 +54524,7 @@ function safeBirthtime(p) {
|
|
|
54366
54524
|
}
|
|
54367
54525
|
function safeSize(p) {
|
|
54368
54526
|
try {
|
|
54369
|
-
return
|
|
54527
|
+
return fs28.statSync(p).size;
|
|
54370
54528
|
} catch {
|
|
54371
54529
|
return 0;
|
|
54372
54530
|
}
|
|
@@ -54460,9 +54618,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54460
54618
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
54461
54619
|
static looksLikeProviderRoot(candidate) {
|
|
54462
54620
|
try {
|
|
54463
|
-
if (!
|
|
54621
|
+
if (!fs29.existsSync(candidate) || !fs29.statSync(candidate).isDirectory()) return false;
|
|
54464
54622
|
return ["ide", "extension", "cli", "acp"].some(
|
|
54465
|
-
(category) =>
|
|
54623
|
+
(category) => fs29.existsSync(path36.join(candidate, category))
|
|
54466
54624
|
);
|
|
54467
54625
|
} catch {
|
|
54468
54626
|
return false;
|
|
@@ -54470,7 +54628,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54470
54628
|
}
|
|
54471
54629
|
static hasProviderRootMarker(candidate) {
|
|
54472
54630
|
try {
|
|
54473
|
-
return
|
|
54631
|
+
return fs29.existsSync(path36.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
54474
54632
|
} catch {
|
|
54475
54633
|
return false;
|
|
54476
54634
|
}
|
|
@@ -54535,12 +54693,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54535
54693
|
const home = os26.homedir();
|
|
54536
54694
|
const oldDir = path36.join(home, ".adhdev", "marketplace");
|
|
54537
54695
|
const newDir = path36.join(home, ".adhdev", "external");
|
|
54538
|
-
if (!
|
|
54539
|
-
if (
|
|
54696
|
+
if (!fs29.existsSync(oldDir)) return;
|
|
54697
|
+
if (fs29.existsSync(newDir)) {
|
|
54540
54698
|
this.log(`Migration skipped: both ~/.adhdev/marketplace and ~/.adhdev/external exist (marketplace dir is now inert and can be removed manually).`);
|
|
54541
54699
|
return;
|
|
54542
54700
|
}
|
|
54543
|
-
|
|
54701
|
+
fs29.renameSync(oldDir, newDir);
|
|
54544
54702
|
this.log(`Migrated ~/.adhdev/marketplace \u2192 ~/.adhdev/external (one-time rename after provider source-layer cleanup).`);
|
|
54545
54703
|
} catch (e) {
|
|
54546
54704
|
this.log(`Marketplace\u2192external migration failed: ${e?.message || e}`);
|
|
@@ -54655,7 +54813,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54655
54813
|
this.providers.clear();
|
|
54656
54814
|
this.providerAvailability.clear();
|
|
54657
54815
|
let upstreamCount = 0;
|
|
54658
|
-
if (!this.disableUpstream &&
|
|
54816
|
+
if (!this.disableUpstream && fs29.existsSync(this.upstreamDir)) {
|
|
54659
54817
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
54660
54818
|
if (upstreamCount > 0) {
|
|
54661
54819
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -54664,10 +54822,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54664
54822
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
54665
54823
|
}
|
|
54666
54824
|
const externalDir = path36.join(os26.homedir(), ".adhdev", "external");
|
|
54667
|
-
if (
|
|
54825
|
+
if (fs29.existsSync(externalDir)) {
|
|
54668
54826
|
const rootEntries = (() => {
|
|
54669
54827
|
try {
|
|
54670
|
-
return
|
|
54828
|
+
return fs29.readdirSync(externalDir, { withFileTypes: true });
|
|
54671
54829
|
} catch {
|
|
54672
54830
|
return [];
|
|
54673
54831
|
}
|
|
@@ -54716,7 +54874,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54716
54874
|
}
|
|
54717
54875
|
}
|
|
54718
54876
|
}
|
|
54719
|
-
if (
|
|
54877
|
+
if (fs29.existsSync(this.userDir)) {
|
|
54720
54878
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
54721
54879
|
if (userCount > 0) {
|
|
54722
54880
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -54731,10 +54889,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54731
54889
|
* Check if upstream directory exists and has providers.
|
|
54732
54890
|
*/
|
|
54733
54891
|
hasUpstream() {
|
|
54734
|
-
if (!
|
|
54892
|
+
if (!fs29.existsSync(this.upstreamDir)) return false;
|
|
54735
54893
|
try {
|
|
54736
|
-
return
|
|
54737
|
-
(d) =>
|
|
54894
|
+
return fs29.readdirSync(this.upstreamDir).some(
|
|
54895
|
+
(d) => fs29.statSync(path36.join(this.upstreamDir, d)).isDirectory()
|
|
54738
54896
|
);
|
|
54739
54897
|
} catch {
|
|
54740
54898
|
return false;
|
|
@@ -55233,7 +55391,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55233
55391
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
55234
55392
|
if (providerDir) {
|
|
55235
55393
|
const fullDir = path36.join(providerDir, entry.scriptDir);
|
|
55236
|
-
resolved._resolvedScriptsPath =
|
|
55394
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
55237
55395
|
}
|
|
55238
55396
|
matched = true;
|
|
55239
55397
|
}
|
|
@@ -55252,7 +55410,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55252
55410
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
55253
55411
|
if (providerDir) {
|
|
55254
55412
|
const fullDir = path36.join(providerDir, base.defaultScriptDir);
|
|
55255
|
-
resolved._resolvedScriptsPath =
|
|
55413
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
55256
55414
|
}
|
|
55257
55415
|
}
|
|
55258
55416
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -55270,7 +55428,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55270
55428
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
55271
55429
|
if (providerDir) {
|
|
55272
55430
|
const fullDir = path36.join(providerDir, dirOverride);
|
|
55273
|
-
resolved._resolvedScriptsPath =
|
|
55431
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
55274
55432
|
}
|
|
55275
55433
|
}
|
|
55276
55434
|
} else if (override.scripts) {
|
|
@@ -55287,7 +55445,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55287
55445
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
55288
55446
|
if (providerDir) {
|
|
55289
55447
|
const fullDir = path36.join(providerDir, base.defaultScriptDir);
|
|
55290
|
-
resolved._resolvedScriptsPath =
|
|
55448
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
55291
55449
|
}
|
|
55292
55450
|
}
|
|
55293
55451
|
}
|
|
@@ -55305,7 +55463,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55305
55463
|
for (const [scriptName, override] of Object.entries(base.overrides)) {
|
|
55306
55464
|
if (!override || typeof override.path !== "string") continue;
|
|
55307
55465
|
const fullPath = path36.join(providerDir2, override.path);
|
|
55308
|
-
if (!
|
|
55466
|
+
if (!fs29.existsSync(fullPath)) {
|
|
55309
55467
|
this.log(` [overrides] ${base.type}: ${scriptName} path not found: ${fullPath}`);
|
|
55310
55468
|
continue;
|
|
55311
55469
|
}
|
|
@@ -55335,7 +55493,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55335
55493
|
}
|
|
55336
55494
|
if (providerDir) {
|
|
55337
55495
|
try {
|
|
55338
|
-
const
|
|
55496
|
+
const fs43 = require("fs");
|
|
55339
55497
|
const path45 = require("path");
|
|
55340
55498
|
const candidates = [];
|
|
55341
55499
|
if (Array.isArray(base.compatibility)) {
|
|
@@ -55347,13 +55505,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55347
55505
|
}
|
|
55348
55506
|
candidates.push(path45.join(providerDir, "specs", "default.json"));
|
|
55349
55507
|
candidates.push(path45.join(providerDir, "spec.json"));
|
|
55350
|
-
const specPath = candidates.find((p) =>
|
|
55508
|
+
const specPath = candidates.find((p) => fs43.existsSync(p));
|
|
55351
55509
|
let nh;
|
|
55352
55510
|
if (specPath) {
|
|
55353
55511
|
resolved._resolvedSpecPath = specPath;
|
|
55354
55512
|
let specControls;
|
|
55355
55513
|
try {
|
|
55356
|
-
const rawSpec = JSON.parse(
|
|
55514
|
+
const rawSpec = JSON.parse(fs43.readFileSync(specPath, "utf8"));
|
|
55357
55515
|
specControls = rawSpec.control_bar;
|
|
55358
55516
|
nh = rawSpec.native_history;
|
|
55359
55517
|
} catch {
|
|
@@ -55392,7 +55550,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55392
55550
|
reader = (input) => executeNativeHistory(nh, input);
|
|
55393
55551
|
} else if (nh.override_path) {
|
|
55394
55552
|
const overrideFile = path45.resolve(providerDir, nh.override_path);
|
|
55395
|
-
if (
|
|
55553
|
+
if (fs43.existsSync(overrideFile)) {
|
|
55396
55554
|
try {
|
|
55397
55555
|
registerProviderScriptRootSafely(path45.dirname(path45.dirname(providerDir)));
|
|
55398
55556
|
delete require.cache[require.resolve(overrideFile)];
|
|
@@ -55437,7 +55595,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55437
55595
|
return null;
|
|
55438
55596
|
}
|
|
55439
55597
|
const dir = path36.join(providerDir, scriptDir);
|
|
55440
|
-
if (!
|
|
55598
|
+
if (!fs29.existsSync(dir)) {
|
|
55441
55599
|
this.debugLog(`[loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
55442
55600
|
return null;
|
|
55443
55601
|
}
|
|
@@ -55445,7 +55603,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55445
55603
|
const cached3 = this.scriptsCache.get(dir);
|
|
55446
55604
|
if (cached3) return cached3;
|
|
55447
55605
|
const scriptsJs = path36.join(dir, "scripts.js");
|
|
55448
|
-
if (
|
|
55606
|
+
if (fs29.existsSync(scriptsJs)) {
|
|
55449
55607
|
try {
|
|
55450
55608
|
delete require.cache[require.resolve(scriptsJs)];
|
|
55451
55609
|
const loaded = require(scriptsJs);
|
|
@@ -55466,9 +55624,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55466
55624
|
watch() {
|
|
55467
55625
|
this.stopWatch();
|
|
55468
55626
|
const watchDir = (dir) => {
|
|
55469
|
-
if (!
|
|
55627
|
+
if (!fs29.existsSync(dir)) {
|
|
55470
55628
|
try {
|
|
55471
|
-
|
|
55629
|
+
fs29.mkdirSync(dir, { recursive: true });
|
|
55472
55630
|
} catch {
|
|
55473
55631
|
return;
|
|
55474
55632
|
}
|
|
@@ -55560,14 +55718,14 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55560
55718
|
const regMetaPath = path36.join(this.upstreamDir, _ProviderLoader.REGISTRY_META_FILE);
|
|
55561
55719
|
let cachedChecksums = {};
|
|
55562
55720
|
try {
|
|
55563
|
-
if (
|
|
55564
|
-
cachedChecksums = JSON.parse(
|
|
55721
|
+
if (fs29.existsSync(regMetaPath)) {
|
|
55722
|
+
cachedChecksums = JSON.parse(fs29.readFileSync(regMetaPath, "utf-8")).checksums ?? {};
|
|
55565
55723
|
}
|
|
55566
55724
|
} catch {
|
|
55567
55725
|
}
|
|
55568
55726
|
try {
|
|
55569
55727
|
const listUrl = `${this.registryBaseUrl}/providers`;
|
|
55570
|
-
const listBody = await new Promise((
|
|
55728
|
+
const listBody = await new Promise((resolve26, reject) => {
|
|
55571
55729
|
const req = https.get(listUrl, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 1e4 }, (res) => {
|
|
55572
55730
|
if (res.statusCode !== 200) {
|
|
55573
55731
|
reject(new Error(`registry list HTTP ${res.statusCode}`));
|
|
@@ -55575,7 +55733,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55575
55733
|
}
|
|
55576
55734
|
const chunks = [];
|
|
55577
55735
|
res.on("data", (c) => chunks.push(c));
|
|
55578
|
-
res.on("end", () =>
|
|
55736
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
55579
55737
|
});
|
|
55580
55738
|
req.on("error", reject);
|
|
55581
55739
|
req.on("timeout", () => {
|
|
@@ -55591,7 +55749,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55591
55749
|
const cacheKey = `${category}/${type}`;
|
|
55592
55750
|
if (cachedChecksums[cacheKey] === checksum) continue;
|
|
55593
55751
|
const dlUrl = `${this.registryBaseUrl}/providers/${type}/${version}/download`;
|
|
55594
|
-
const manifestBody = await new Promise((
|
|
55752
|
+
const manifestBody = await new Promise((resolve26, reject) => {
|
|
55595
55753
|
const req = https.get(dlUrl, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 3e4 }, (res) => {
|
|
55596
55754
|
if (res.statusCode !== 200) {
|
|
55597
55755
|
reject(new Error(`registry download HTTP ${res.statusCode} for ${type}@${version}`));
|
|
@@ -55599,7 +55757,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55599
55757
|
}
|
|
55600
55758
|
const chunks = [];
|
|
55601
55759
|
res.on("data", (c) => chunks.push(c));
|
|
55602
|
-
res.on("end", () =>
|
|
55760
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
55603
55761
|
});
|
|
55604
55762
|
req.on("error", reject);
|
|
55605
55763
|
req.on("timeout", () => {
|
|
@@ -55613,14 +55771,14 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55613
55771
|
continue;
|
|
55614
55772
|
}
|
|
55615
55773
|
const providerDir = path36.join(this.upstreamDir, category, type);
|
|
55616
|
-
|
|
55617
|
-
|
|
55774
|
+
fs29.mkdirSync(providerDir, { recursive: true });
|
|
55775
|
+
fs29.writeFileSync(path36.join(providerDir, "provider.json"), manifestBody, "utf-8");
|
|
55618
55776
|
cachedChecksums[cacheKey] = checksum;
|
|
55619
55777
|
updatedCount++;
|
|
55620
55778
|
this.log(`\u2713 Registry updated: ${category}/${type}@${version}`);
|
|
55621
55779
|
}
|
|
55622
|
-
|
|
55623
|
-
|
|
55780
|
+
fs29.mkdirSync(this.upstreamDir, { recursive: true });
|
|
55781
|
+
fs29.writeFileSync(regMetaPath, JSON.stringify({
|
|
55624
55782
|
checksums: cachedChecksums,
|
|
55625
55783
|
syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
55626
55784
|
providerCount: list.providers.length
|
|
@@ -55645,8 +55803,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55645
55803
|
let prevEtag = "";
|
|
55646
55804
|
let prevTimestamp = 0;
|
|
55647
55805
|
try {
|
|
55648
|
-
if (
|
|
55649
|
-
const meta = JSON.parse(
|
|
55806
|
+
if (fs29.existsSync(metaPath)) {
|
|
55807
|
+
const meta = JSON.parse(fs29.readFileSync(metaPath, "utf-8"));
|
|
55650
55808
|
prevEtag = meta.etag || "";
|
|
55651
55809
|
prevTimestamp = meta.timestamp || 0;
|
|
55652
55810
|
}
|
|
@@ -55659,7 +55817,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55659
55817
|
}
|
|
55660
55818
|
const tarballTarget = resolveProviderTarballTarget(this.providerTarballUrl);
|
|
55661
55819
|
try {
|
|
55662
|
-
const etag = await new Promise((
|
|
55820
|
+
const etag = await new Promise((resolve26, reject) => {
|
|
55663
55821
|
const options = {
|
|
55664
55822
|
method: "HEAD",
|
|
55665
55823
|
hostname: tarballTarget.hostname,
|
|
@@ -55677,7 +55835,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55677
55835
|
headers: { "User-Agent": "adhdev-launcher" },
|
|
55678
55836
|
timeout: 1e4
|
|
55679
55837
|
}, (res2) => {
|
|
55680
|
-
|
|
55838
|
+
resolve26(res2.headers.etag || res2.headers["last-modified"] || "");
|
|
55681
55839
|
});
|
|
55682
55840
|
req2.on("error", reject);
|
|
55683
55841
|
req2.on("timeout", () => {
|
|
@@ -55686,7 +55844,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55686
55844
|
});
|
|
55687
55845
|
req2.end();
|
|
55688
55846
|
} else {
|
|
55689
|
-
|
|
55847
|
+
resolve26(res.headers.etag || res.headers["last-modified"] || "");
|
|
55690
55848
|
}
|
|
55691
55849
|
});
|
|
55692
55850
|
req.on("error", reject);
|
|
@@ -55705,36 +55863,36 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55705
55863
|
const tmpTar = path36.join(os26.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
55706
55864
|
const tmpExtract = path36.join(os26.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
55707
55865
|
await this.downloadFile(tarballTarget.url, tmpTar);
|
|
55708
|
-
|
|
55866
|
+
fs29.mkdirSync(tmpExtract, { recursive: true });
|
|
55709
55867
|
await execAsync5(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
55710
|
-
const extracted =
|
|
55868
|
+
const extracted = fs29.readdirSync(tmpExtract);
|
|
55711
55869
|
const rootDir = extracted.find(
|
|
55712
|
-
(d) =>
|
|
55870
|
+
(d) => fs29.statSync(path36.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
55713
55871
|
);
|
|
55714
55872
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
55715
55873
|
const sourceDir = path36.join(tmpExtract, rootDir);
|
|
55716
55874
|
const backupDir = this.upstreamDir + ".bak";
|
|
55717
|
-
if (
|
|
55718
|
-
if (
|
|
55719
|
-
|
|
55875
|
+
if (fs29.existsSync(this.upstreamDir)) {
|
|
55876
|
+
if (fs29.existsSync(backupDir)) fs29.rmSync(backupDir, { recursive: true, force: true });
|
|
55877
|
+
fs29.renameSync(this.upstreamDir, backupDir);
|
|
55720
55878
|
}
|
|
55721
55879
|
try {
|
|
55722
55880
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
55723
55881
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
55724
|
-
if (
|
|
55882
|
+
if (fs29.existsSync(backupDir)) fs29.rmSync(backupDir, { recursive: true, force: true });
|
|
55725
55883
|
} catch (e) {
|
|
55726
|
-
if (
|
|
55727
|
-
if (
|
|
55728
|
-
|
|
55884
|
+
if (fs29.existsSync(backupDir)) {
|
|
55885
|
+
if (fs29.existsSync(this.upstreamDir)) fs29.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
55886
|
+
fs29.renameSync(backupDir, this.upstreamDir);
|
|
55729
55887
|
}
|
|
55730
55888
|
throw e;
|
|
55731
55889
|
}
|
|
55732
55890
|
try {
|
|
55733
|
-
|
|
55891
|
+
fs29.rmSync(tmpTar, { force: true });
|
|
55734
55892
|
} catch {
|
|
55735
55893
|
}
|
|
55736
55894
|
try {
|
|
55737
|
-
|
|
55895
|
+
fs29.rmSync(tmpExtract, { recursive: true, force: true });
|
|
55738
55896
|
} catch {
|
|
55739
55897
|
}
|
|
55740
55898
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -55750,7 +55908,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55750
55908
|
downloadFile(url, destPath) {
|
|
55751
55909
|
const https = require("https");
|
|
55752
55910
|
const http3 = require("http");
|
|
55753
|
-
return new Promise((
|
|
55911
|
+
return new Promise((resolve26, reject) => {
|
|
55754
55912
|
const doRequest = (reqUrl, redirectCount = 0) => {
|
|
55755
55913
|
if (redirectCount > 5) {
|
|
55756
55914
|
reject(new Error("Too many redirects"));
|
|
@@ -55766,11 +55924,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55766
55924
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
55767
55925
|
return;
|
|
55768
55926
|
}
|
|
55769
|
-
const ws =
|
|
55927
|
+
const ws = fs29.createWriteStream(destPath);
|
|
55770
55928
|
res.pipe(ws);
|
|
55771
55929
|
ws.on("finish", () => {
|
|
55772
55930
|
ws.close();
|
|
55773
|
-
|
|
55931
|
+
resolve26();
|
|
55774
55932
|
});
|
|
55775
55933
|
ws.on("error", reject);
|
|
55776
55934
|
});
|
|
@@ -55785,22 +55943,22 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55785
55943
|
}
|
|
55786
55944
|
/** Recursive directory copy */
|
|
55787
55945
|
copyDirRecursive(src, dest) {
|
|
55788
|
-
|
|
55789
|
-
for (const entry of
|
|
55946
|
+
fs29.mkdirSync(dest, { recursive: true });
|
|
55947
|
+
for (const entry of fs29.readdirSync(src, { withFileTypes: true })) {
|
|
55790
55948
|
const srcPath = path36.join(src, entry.name);
|
|
55791
55949
|
const destPath = path36.join(dest, entry.name);
|
|
55792
55950
|
if (entry.isDirectory()) {
|
|
55793
55951
|
this.copyDirRecursive(srcPath, destPath);
|
|
55794
55952
|
} else {
|
|
55795
|
-
|
|
55953
|
+
fs29.copyFileSync(srcPath, destPath);
|
|
55796
55954
|
}
|
|
55797
55955
|
}
|
|
55798
55956
|
}
|
|
55799
55957
|
/** .meta.json save */
|
|
55800
55958
|
writeMeta(metaPath, etag, timestamp) {
|
|
55801
55959
|
try {
|
|
55802
|
-
|
|
55803
|
-
|
|
55960
|
+
fs29.mkdirSync(path36.dirname(metaPath), { recursive: true });
|
|
55961
|
+
fs29.writeFileSync(metaPath, JSON.stringify({
|
|
55804
55962
|
etag,
|
|
55805
55963
|
timestamp,
|
|
55806
55964
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -55811,11 +55969,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55811
55969
|
}
|
|
55812
55970
|
/** Count provider files (provider.v1.json or provider.json — at most one per dir). */
|
|
55813
55971
|
countProviders(dir) {
|
|
55814
|
-
if (!
|
|
55972
|
+
if (!fs29.existsSync(dir)) return 0;
|
|
55815
55973
|
let count = 0;
|
|
55816
55974
|
const scan = (d) => {
|
|
55817
55975
|
try {
|
|
55818
|
-
const entries =
|
|
55976
|
+
const entries = fs29.readdirSync(d, { withFileTypes: true });
|
|
55819
55977
|
const hasManifest = entries.some((e) => e.name === "provider.v1.json" || e.name === "provider.json");
|
|
55820
55978
|
if (hasManifest) count++;
|
|
55821
55979
|
for (const entry of entries) {
|
|
@@ -56045,13 +56203,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56045
56203
|
if (!provider) return null;
|
|
56046
56204
|
const cat = provider.category;
|
|
56047
56205
|
const searchRoots = this.getProviderRoots();
|
|
56048
|
-
const hasManifest = (dir) =>
|
|
56206
|
+
const hasManifest = (dir) => fs29.existsSync(path36.join(dir, "provider.v1.json")) || fs29.existsSync(path36.join(dir, "provider.json"));
|
|
56049
56207
|
const readManifestType = (dir) => {
|
|
56050
56208
|
for (const file of ["provider.v1.json", "provider.json"]) {
|
|
56051
56209
|
const p = path36.join(dir, file);
|
|
56052
|
-
if (!
|
|
56210
|
+
if (!fs29.existsSync(p)) continue;
|
|
56053
56211
|
try {
|
|
56054
|
-
const data = JSON.parse(
|
|
56212
|
+
const data = JSON.parse(fs29.readFileSync(p, "utf-8"));
|
|
56055
56213
|
if (typeof data?.type === "string") return data.type;
|
|
56056
56214
|
} catch {
|
|
56057
56215
|
}
|
|
@@ -56059,13 +56217,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56059
56217
|
return null;
|
|
56060
56218
|
};
|
|
56061
56219
|
for (const root of searchRoots) {
|
|
56062
|
-
if (!
|
|
56220
|
+
if (!fs29.existsSync(root)) continue;
|
|
56063
56221
|
const candidate = this.getProviderDir(root, cat, type);
|
|
56064
56222
|
if (hasManifest(candidate)) return candidate;
|
|
56065
56223
|
const catDir = path36.join(root, cat);
|
|
56066
|
-
if (
|
|
56224
|
+
if (fs29.existsSync(catDir)) {
|
|
56067
56225
|
try {
|
|
56068
|
-
for (const entry of
|
|
56226
|
+
for (const entry of fs29.readdirSync(catDir, { withFileTypes: true })) {
|
|
56069
56227
|
if (!entry.isDirectory()) continue;
|
|
56070
56228
|
const entryDir = path36.join(catDir, entry.name);
|
|
56071
56229
|
const manifestType = readManifestType(entryDir);
|
|
@@ -56084,7 +56242,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56084
56242
|
*/
|
|
56085
56243
|
buildScriptWrappersFromDir(dir) {
|
|
56086
56244
|
const scriptsJs = path36.join(dir, "scripts.js");
|
|
56087
|
-
if (
|
|
56245
|
+
if (fs29.existsSync(scriptsJs)) {
|
|
56088
56246
|
try {
|
|
56089
56247
|
delete require.cache[require.resolve(scriptsJs)];
|
|
56090
56248
|
return require(scriptsJs);
|
|
@@ -56094,13 +56252,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56094
56252
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
56095
56253
|
const result = {};
|
|
56096
56254
|
try {
|
|
56097
|
-
for (const file of
|
|
56255
|
+
for (const file of fs29.readdirSync(dir)) {
|
|
56098
56256
|
if (!file.endsWith(".js")) continue;
|
|
56099
56257
|
const scriptName = toCamel(file.replace(".js", ""));
|
|
56100
56258
|
const filePath = path36.join(dir, file);
|
|
56101
56259
|
result[scriptName] = (...args) => {
|
|
56102
56260
|
try {
|
|
56103
|
-
let content =
|
|
56261
|
+
let content = fs29.readFileSync(filePath, "utf-8");
|
|
56104
56262
|
if (args[0] && typeof args[0] === "object") {
|
|
56105
56263
|
for (const [key2, val] of Object.entries(args[0])) {
|
|
56106
56264
|
let v = val;
|
|
@@ -56146,12 +56304,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56146
56304
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
56147
56305
|
*/
|
|
56148
56306
|
loadDir(dir, excludeDirs) {
|
|
56149
|
-
if (!
|
|
56307
|
+
if (!fs29.existsSync(dir)) return 0;
|
|
56150
56308
|
let count = 0;
|
|
56151
56309
|
const scan = (d) => {
|
|
56152
56310
|
let entries;
|
|
56153
56311
|
try {
|
|
56154
|
-
entries =
|
|
56312
|
+
entries = fs29.readdirSync(d, { withFileTypes: true });
|
|
56155
56313
|
} catch {
|
|
56156
56314
|
return;
|
|
56157
56315
|
}
|
|
@@ -56161,7 +56319,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
56161
56319
|
const manifestFile = hasV1 ? "provider.v1.json" : "provider.json";
|
|
56162
56320
|
const jsonPath = path36.join(d, manifestFile);
|
|
56163
56321
|
try {
|
|
56164
|
-
const raw =
|
|
56322
|
+
const raw = fs29.readFileSync(jsonPath, "utf-8");
|
|
56165
56323
|
const mod = JSON.parse(raw);
|
|
56166
56324
|
if (hasV1 && mod?.category === "cli") {
|
|
56167
56325
|
try {
|
|
@@ -56200,7 +56358,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
56200
56358
|
} else {
|
|
56201
56359
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
56202
56360
|
const scriptsPath = path36.join(d, "scripts.js");
|
|
56203
|
-
if (!hasCompatibility &&
|
|
56361
|
+
if (!hasCompatibility && fs29.existsSync(scriptsPath)) {
|
|
56204
56362
|
try {
|
|
56205
56363
|
registerProviderScriptRootSafely(path36.dirname(path36.dirname(d)));
|
|
56206
56364
|
delete require.cache[require.resolve(scriptsPath)];
|
|
@@ -56326,10 +56484,10 @@ function findMacAppProcessPids(psOutput, appPaths) {
|
|
|
56326
56484
|
|
|
56327
56485
|
// src/launch.ts
|
|
56328
56486
|
async function execQuiet(command, options = {}) {
|
|
56329
|
-
return new Promise((
|
|
56487
|
+
return new Promise((resolve26) => {
|
|
56330
56488
|
(0, import_child_process9.exec)(command, options, (error, stdout) => {
|
|
56331
|
-
if (error) return
|
|
56332
|
-
|
|
56489
|
+
if (error) return resolve26("");
|
|
56490
|
+
resolve26(stdout.toString());
|
|
56333
56491
|
});
|
|
56334
56492
|
});
|
|
56335
56493
|
}
|
|
@@ -56410,17 +56568,17 @@ async function findFreePort(ports) {
|
|
|
56410
56568
|
throw new Error("No free port found");
|
|
56411
56569
|
}
|
|
56412
56570
|
function checkPortFree(port) {
|
|
56413
|
-
return new Promise((
|
|
56571
|
+
return new Promise((resolve26) => {
|
|
56414
56572
|
const server = net.createServer();
|
|
56415
56573
|
server.unref();
|
|
56416
|
-
server.on("error", () =>
|
|
56574
|
+
server.on("error", () => resolve26(false));
|
|
56417
56575
|
server.listen(port, "127.0.0.1", () => {
|
|
56418
|
-
server.close(() =>
|
|
56576
|
+
server.close(() => resolve26(true));
|
|
56419
56577
|
});
|
|
56420
56578
|
});
|
|
56421
56579
|
}
|
|
56422
56580
|
async function isCdpActive(port) {
|
|
56423
|
-
return new Promise((
|
|
56581
|
+
return new Promise((resolve26) => {
|
|
56424
56582
|
const req = require("http").get(`http://127.0.0.1:${port}/json/version`, {
|
|
56425
56583
|
timeout: 2e3
|
|
56426
56584
|
}, (res) => {
|
|
@@ -56429,16 +56587,16 @@ async function isCdpActive(port) {
|
|
|
56429
56587
|
res.on("end", () => {
|
|
56430
56588
|
try {
|
|
56431
56589
|
const info = JSON.parse(data);
|
|
56432
|
-
|
|
56590
|
+
resolve26(!!info["WebKit-Version"] || !!info["Browser"]);
|
|
56433
56591
|
} catch {
|
|
56434
|
-
|
|
56592
|
+
resolve26(false);
|
|
56435
56593
|
}
|
|
56436
56594
|
});
|
|
56437
56595
|
});
|
|
56438
|
-
req.on("error", () =>
|
|
56596
|
+
req.on("error", () => resolve26(false));
|
|
56439
56597
|
req.on("timeout", () => {
|
|
56440
56598
|
req.destroy();
|
|
56441
|
-
|
|
56599
|
+
resolve26(false);
|
|
56442
56600
|
});
|
|
56443
56601
|
});
|
|
56444
56602
|
}
|
|
@@ -56574,7 +56732,7 @@ async function detectCurrentWorkspace(ideId) {
|
|
|
56574
56732
|
}
|
|
56575
56733
|
} else if (plat === "win32") {
|
|
56576
56734
|
try {
|
|
56577
|
-
const
|
|
56735
|
+
const fs43 = require("fs");
|
|
56578
56736
|
const appNameMap = getMacAppIdentifiers();
|
|
56579
56737
|
const appName = appNameMap[ideId];
|
|
56580
56738
|
if (appName) {
|
|
@@ -56583,8 +56741,8 @@ async function detectCurrentWorkspace(ideId) {
|
|
|
56583
56741
|
appName,
|
|
56584
56742
|
"storage.json"
|
|
56585
56743
|
);
|
|
56586
|
-
if (
|
|
56587
|
-
const data = JSON.parse(
|
|
56744
|
+
if (fs43.existsSync(storagePath)) {
|
|
56745
|
+
const data = JSON.parse(fs43.readFileSync(storagePath, "utf-8"));
|
|
56588
56746
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
56589
56747
|
if (workspaces.length > 0) {
|
|
56590
56748
|
const recent = workspaces[0];
|
|
@@ -57104,7 +57262,7 @@ var meshCrudHandlers = {
|
|
|
57104
57262
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
57105
57263
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
57106
57264
|
const { mkdirSync: mkdirSync22, writeFileSync: writeFileSync24 } = await import("fs");
|
|
57107
|
-
const { dirname:
|
|
57265
|
+
const { dirname: dirname18, join: join52 } = await import("path");
|
|
57108
57266
|
const scaffold = buildMeshJsonConfigScaffold2(mesh);
|
|
57109
57267
|
const scaffoldJson = serializeMeshJsonConfigScaffold2(scaffold);
|
|
57110
57268
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
@@ -57144,7 +57302,7 @@ var meshCrudHandlers = {
|
|
|
57144
57302
|
note: "Dry-run: nothing written. Re-run with write=true to persist to the repo (commit target). meshes.json is untouched."
|
|
57145
57303
|
};
|
|
57146
57304
|
}
|
|
57147
|
-
mkdirSync22(
|
|
57305
|
+
mkdirSync22(dirname18(absolutePath), { recursive: true });
|
|
57148
57306
|
writeFileSync24(absolutePath, `${scaffoldJson}
|
|
57149
57307
|
`, "utf-8");
|
|
57150
57308
|
return {
|
|
@@ -57683,7 +57841,7 @@ var meshCrudHandlers = {
|
|
|
57683
57841
|
const setupPromise = finishWorktreeSetup();
|
|
57684
57842
|
const setupResult = await Promise.race([
|
|
57685
57843
|
setupPromise.then((value) => ({ completed: true, value })),
|
|
57686
|
-
new Promise((
|
|
57844
|
+
new Promise((resolve26) => setTimeout(() => resolve26({ completed: false }), setupWaitMs))
|
|
57687
57845
|
]);
|
|
57688
57846
|
const emitBootstrapEvent = (eventStatus2, bootstrapState2, startedAtMs, extraPayload) => {
|
|
57689
57847
|
try {
|
|
@@ -58566,7 +58724,7 @@ var meshEventsHandlers = {
|
|
|
58566
58724
|
|
|
58567
58725
|
// src/commands/high-family/mesh-coordinator-launch.ts
|
|
58568
58726
|
var import_path13 = require("path");
|
|
58569
|
-
var
|
|
58727
|
+
var fs30 = __toESM(require("fs"));
|
|
58570
58728
|
init_logger();
|
|
58571
58729
|
init_mesh_host_ownership();
|
|
58572
58730
|
init_coordinator_registry();
|
|
@@ -58812,15 +58970,15 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58812
58970
|
}
|
|
58813
58971
|
if (cliType === "codex-cli") {
|
|
58814
58972
|
const repoMcpConfigPath = (0, import_path13.join)(workspace, ".mcp.json");
|
|
58815
|
-
if (
|
|
58973
|
+
if (fs30.existsSync(repoMcpConfigPath)) {
|
|
58816
58974
|
try {
|
|
58817
58975
|
const repoMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
58818
|
-
|
|
58976
|
+
fs30.readFileSync(repoMcpConfigPath, "utf-8"),
|
|
58819
58977
|
"claude_mcp_json"
|
|
58820
58978
|
);
|
|
58821
58979
|
const existingServers2 = repoMcpConfig.mcpServers;
|
|
58822
58980
|
if (existingServers2 && typeof existingServers2 === "object" && !Array.isArray(existingServers2) && existingServers2[coordinatorSetup.serverName]) {
|
|
58823
|
-
|
|
58981
|
+
fs30.writeFileSync(repoMcpConfigPath, serializeMeshCoordinatorMcpConfig({
|
|
58824
58982
|
...repoMcpConfig,
|
|
58825
58983
|
mcpServers: {
|
|
58826
58984
|
...existingServers2,
|
|
@@ -58939,7 +59097,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58939
59097
|
};
|
|
58940
59098
|
}
|
|
58941
59099
|
const { existsSync: existsSync55, readFileSync: readFileSync42, writeFileSync: writeFileSync24, copyFileSync: copyFileSync4, mkdirSync: mkdirSync22 } = await import("fs");
|
|
58942
|
-
const { dirname:
|
|
59100
|
+
const { dirname: dirname18 } = await import("path");
|
|
58943
59101
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
58944
59102
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
58945
59103
|
let hermesBaseConfig = null;
|
|
@@ -58974,7 +59132,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58974
59132
|
};
|
|
58975
59133
|
}
|
|
58976
59134
|
try {
|
|
58977
|
-
mkdirSync22(
|
|
59135
|
+
mkdirSync22(dirname18(mcpConfigPath), { recursive: true });
|
|
58978
59136
|
} catch (error) {
|
|
58979
59137
|
const message = `Could not prepare MCP config path for automatic setup: ${error?.message || error}`;
|
|
58980
59138
|
LOG.error("MeshCoordinator", message);
|
|
@@ -58984,7 +59142,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58984
59142
|
const hadExistingMcpConfig = existsSync55(mcpConfigPath);
|
|
58985
59143
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
58986
59144
|
if (hermesBaseConfig) {
|
|
58987
|
-
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome,
|
|
59145
|
+
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname18(mcpConfigPath));
|
|
58988
59146
|
}
|
|
58989
59147
|
if (hadExistingMcpConfig) {
|
|
58990
59148
|
try {
|
|
@@ -59022,7 +59180,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
59022
59180
|
const cliArgs = [];
|
|
59023
59181
|
const launchEnv = {};
|
|
59024
59182
|
if (configFormat === "hermes_config_yaml") {
|
|
59025
|
-
launchEnv.HERMES_HOME =
|
|
59183
|
+
launchEnv.HERMES_HOME = dirname18(mcpConfigPath);
|
|
59026
59184
|
launchEnv.HERMES_IGNORE_USER_CONFIG = "";
|
|
59027
59185
|
}
|
|
59028
59186
|
let autoImportContextFilePath;
|
|
@@ -59107,7 +59265,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
59107
59265
|
};
|
|
59108
59266
|
|
|
59109
59267
|
// src/commands/high-family/mesh-status.ts
|
|
59110
|
-
var
|
|
59268
|
+
var fs31 = __toESM(require("fs"));
|
|
59111
59269
|
var import_os3 = require("os");
|
|
59112
59270
|
init_config();
|
|
59113
59271
|
init_git_status();
|
|
@@ -59474,7 +59632,7 @@ var meshStatusHandlers = {
|
|
|
59474
59632
|
}
|
|
59475
59633
|
}
|
|
59476
59634
|
if (workspace) {
|
|
59477
|
-
if (!
|
|
59635
|
+
if (!fs31.existsSync(workspace)) {
|
|
59478
59636
|
const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
|
|
59479
59637
|
let remoteProbeApplied = false;
|
|
59480
59638
|
if (inlineTransitGit) {
|
|
@@ -59610,7 +59768,7 @@ var meshStatusHandlers = {
|
|
|
59610
59768
|
backstop: { ...getMeshV2BackstopCounters() }
|
|
59611
59769
|
};
|
|
59612
59770
|
const previewFreshness = (() => {
|
|
59613
|
-
const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate &&
|
|
59771
|
+
const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate && fs31.existsSync(candidate));
|
|
59614
59772
|
return localRepoRoot ? buildPreviewFreshness(localRepoRoot) : void 0;
|
|
59615
59773
|
})();
|
|
59616
59774
|
const asyncRefineJobs = buildMeshAsyncRefineJobs({
|
|
@@ -59810,7 +59968,7 @@ init_dist();
|
|
|
59810
59968
|
init_logger();
|
|
59811
59969
|
|
|
59812
59970
|
// src/logging/command-log.ts
|
|
59813
|
-
var
|
|
59971
|
+
var fs32 = __toESM(require("fs"));
|
|
59814
59972
|
var path38 = __toESM(require("path"));
|
|
59815
59973
|
var os28 = __toESM(require("os"));
|
|
59816
59974
|
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 +59976,7 @@ var LOG_DIR2 = path38.join(ADHDEV_HOME2, "logs");
|
|
|
59818
59976
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
59819
59977
|
var MAX_DAYS = 7;
|
|
59820
59978
|
try {
|
|
59821
|
-
|
|
59979
|
+
fs32.mkdirSync(LOG_DIR2, { recursive: true });
|
|
59822
59980
|
} catch {
|
|
59823
59981
|
}
|
|
59824
59982
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -59864,7 +60022,7 @@ function checkRotation() {
|
|
|
59864
60022
|
}
|
|
59865
60023
|
function cleanOldFiles() {
|
|
59866
60024
|
try {
|
|
59867
|
-
const files =
|
|
60025
|
+
const files = fs32.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
59868
60026
|
const cutoff = /* @__PURE__ */ new Date();
|
|
59869
60027
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
59870
60028
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -59872,7 +60030,7 @@ function cleanOldFiles() {
|
|
|
59872
60030
|
const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
59873
60031
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
59874
60032
|
try {
|
|
59875
|
-
|
|
60033
|
+
fs32.unlinkSync(path38.join(LOG_DIR2, file));
|
|
59876
60034
|
} catch {
|
|
59877
60035
|
}
|
|
59878
60036
|
}
|
|
@@ -59882,14 +60040,14 @@ function cleanOldFiles() {
|
|
|
59882
60040
|
}
|
|
59883
60041
|
function checkSize() {
|
|
59884
60042
|
try {
|
|
59885
|
-
const stat2 =
|
|
60043
|
+
const stat2 = fs32.statSync(currentFile);
|
|
59886
60044
|
if (stat2.size > MAX_FILE_SIZE) {
|
|
59887
60045
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
59888
60046
|
try {
|
|
59889
|
-
|
|
60047
|
+
fs32.unlinkSync(backup);
|
|
59890
60048
|
} catch {
|
|
59891
60049
|
}
|
|
59892
|
-
|
|
60050
|
+
fs32.renameSync(currentFile, backup);
|
|
59893
60051
|
}
|
|
59894
60052
|
} catch {
|
|
59895
60053
|
}
|
|
@@ -59922,14 +60080,14 @@ function logCommand(entry) {
|
|
|
59922
60080
|
...entry.error ? { err: entry.error } : {},
|
|
59923
60081
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
59924
60082
|
});
|
|
59925
|
-
|
|
60083
|
+
fs32.appendFileSync(currentFile, line + "\n");
|
|
59926
60084
|
} catch {
|
|
59927
60085
|
}
|
|
59928
60086
|
}
|
|
59929
60087
|
function getRecentCommands(count = 50) {
|
|
59930
60088
|
try {
|
|
59931
|
-
if (!
|
|
59932
|
-
const content =
|
|
60089
|
+
if (!fs32.existsSync(currentFile)) return [];
|
|
60090
|
+
const content = fs32.readFileSync(currentFile, "utf-8");
|
|
59933
60091
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
59934
60092
|
return lines.slice(-count).map((line) => {
|
|
59935
60093
|
try {
|
|
@@ -59957,7 +60115,7 @@ cleanOldFiles();
|
|
|
59957
60115
|
// src/commands/router.ts
|
|
59958
60116
|
init_debug_trace();
|
|
59959
60117
|
init_mesh_host_ownership();
|
|
59960
|
-
var
|
|
60118
|
+
var fs36 = __toESM(require("fs"));
|
|
59961
60119
|
init_mesh_node_identity();
|
|
59962
60120
|
|
|
59963
60121
|
// src/commands/router-refine.ts
|
|
@@ -60068,7 +60226,7 @@ init_git_status();
|
|
|
60068
60226
|
init_refine_config();
|
|
60069
60227
|
init_worktree_bootstrap_config();
|
|
60070
60228
|
var import_path14 = require("path");
|
|
60071
|
-
var
|
|
60229
|
+
var fs33 = __toESM(require("fs"));
|
|
60072
60230
|
var import_node_child_process6 = require("child_process");
|
|
60073
60231
|
init_resolve_executable();
|
|
60074
60232
|
var GIT2 = process.platform === "win32" ? resolveWin32Executable("git") : "git";
|
|
@@ -60427,7 +60585,7 @@ function isSubmoduleFastForward(submoduleRepoPath, baseCommit, branchCommit) {
|
|
|
60427
60585
|
if (!baseCommit || !branchCommit) return false;
|
|
60428
60586
|
if (baseCommit === branchCommit) return true;
|
|
60429
60587
|
try {
|
|
60430
|
-
if (!
|
|
60588
|
+
if (!fs33.existsSync(submoduleRepoPath)) return false;
|
|
60431
60589
|
(0, import_node_child_process6.execFileSync)(GIT2, ["cat-file", "-e", `${baseCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
60432
60590
|
(0, import_node_child_process6.execFileSync)(GIT2, ["cat-file", "-e", `${branchCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
60433
60591
|
(0, import_node_child_process6.execFileSync)(GIT2, ["merge-base", "--is-ancestor", baseCommit, branchCommit], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
@@ -60544,7 +60702,7 @@ function buildTreeWithGitlinksEqualized(repoRoot, commitish, paths, placeholderC
|
|
|
60544
60702
|
return newTree || void 0;
|
|
60545
60703
|
} finally {
|
|
60546
60704
|
try {
|
|
60547
|
-
|
|
60705
|
+
fs33.rmSync(tmpIndex, { force: true });
|
|
60548
60706
|
} catch {
|
|
60549
60707
|
}
|
|
60550
60708
|
}
|
|
@@ -60619,7 +60777,7 @@ function synthesizeTrivialFastForwardMergeTree(repoRoot, baseHead, branchHead, g
|
|
|
60619
60777
|
return newTree || void 0;
|
|
60620
60778
|
} finally {
|
|
60621
60779
|
try {
|
|
60622
|
-
|
|
60780
|
+
fs33.rmSync(tmpIndex, { force: true });
|
|
60623
60781
|
} catch {
|
|
60624
60782
|
}
|
|
60625
60783
|
}
|
|
@@ -60731,7 +60889,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
60731
60889
|
return { stdout: String(stdout || ""), stderr: String(stderr || ""), refspec };
|
|
60732
60890
|
};
|
|
60733
60891
|
const importCommitFromWorktreeSubmodule = async (submodulePath, worktreeSubmodulePath, commit) => {
|
|
60734
|
-
if (!
|
|
60892
|
+
if (!fs33.existsSync(worktreeSubmodulePath)) return false;
|
|
60735
60893
|
try {
|
|
60736
60894
|
await runGit3(worktreeSubmodulePath, ["cat-file", "-e", `${commit}^{commit}`]);
|
|
60737
60895
|
} catch {
|
|
@@ -60755,7 +60913,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
60755
60913
|
};
|
|
60756
60914
|
let submoduleDefaultBranch = "main";
|
|
60757
60915
|
try {
|
|
60758
|
-
if (!
|
|
60916
|
+
if (!fs33.existsSync(submodulePath)) {
|
|
60759
60917
|
entry.error = `Submodule checkout missing at ${gitlink.path}`;
|
|
60760
60918
|
entry.publishRequired = true;
|
|
60761
60919
|
if (options.allowAutoPublishSubmoduleMainCommits === true) {
|
|
@@ -61000,9 +61158,9 @@ async function runMeshRefineValidationGate(mesh, workspace, opts) {
|
|
|
61000
61158
|
return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
|
|
61001
61159
|
};
|
|
61002
61160
|
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) =>
|
|
61161
|
+
if (!fs33.existsSync((0, import_path14.join)(cwd, "package.json"))) return false;
|
|
61162
|
+
if (fs33.existsSync((0, import_path14.join)(cwd, "node_modules"))) return false;
|
|
61163
|
+
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
61164
|
};
|
|
61007
61165
|
const needsNodeModules = (candidate, cwd) => isPackageManagerValidation(candidate) && dependenciesLikelyMissing(cwd);
|
|
61008
61166
|
const isDaemonScopedCommand = (candidate) => {
|
|
@@ -62898,7 +63056,7 @@ async function startMeshRefineJob(self, meshId, nodeId, args) {
|
|
|
62898
63056
|
}
|
|
62899
63057
|
|
|
62900
63058
|
// src/commands/router-worktree-cleanup.ts
|
|
62901
|
-
var
|
|
63059
|
+
var fs34 = __toESM(require("fs"));
|
|
62902
63060
|
var import_path15 = require("path");
|
|
62903
63061
|
init_logger();
|
|
62904
63062
|
init_dist();
|
|
@@ -62915,14 +63073,14 @@ function sessionMatchesMeshNode(self, record, node, nodeId, sessionIds) {
|
|
|
62915
63073
|
return false;
|
|
62916
63074
|
}
|
|
62917
63075
|
async function bestEffortRemoveWorktreeDir(self, dir) {
|
|
62918
|
-
if (!dir || !
|
|
62919
|
-
const sleep3 = (ms) => new Promise((
|
|
63076
|
+
if (!dir || !fs34.existsSync(dir)) return { removed: true, residue: false };
|
|
63077
|
+
const sleep3 = (ms) => new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
62920
63078
|
const ABSORB = /* @__PURE__ */ new Set(["EINVAL", "EPERM", "EBUSY", "ENOTEMPTY", "EACCES", "EMFILE", "ENFILE"]);
|
|
62921
63079
|
let lastErr;
|
|
62922
63080
|
for (let attempt = 0; attempt < 4; attempt++) {
|
|
62923
63081
|
try {
|
|
62924
|
-
|
|
62925
|
-
if (!
|
|
63082
|
+
fs34.rmSync(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
63083
|
+
if (!fs34.existsSync(dir)) return { removed: true, residue: false };
|
|
62926
63084
|
lastErr = new Error("directory still present after rmSync");
|
|
62927
63085
|
} catch (e) {
|
|
62928
63086
|
lastErr = e;
|
|
@@ -62933,7 +63091,7 @@ async function bestEffortRemoveWorktreeDir(self, dir) {
|
|
|
62933
63091
|
}
|
|
62934
63092
|
await sleep3(150 * (attempt + 1));
|
|
62935
63093
|
}
|
|
62936
|
-
return
|
|
63094
|
+
return fs34.existsSync(dir) ? { removed: false, residue: true, error: String(lastErr?.message || lastErr || "unknown rm error") } : { removed: true, residue: false };
|
|
62937
63095
|
}
|
|
62938
63096
|
async function precheckLocalWorktreeRemovable(self, args) {
|
|
62939
63097
|
const sessionPreservedNote = " The delegated session was left running (not stopped) \u2014 resolve the issue and retry mesh_remove_node.";
|
|
@@ -62946,10 +63104,10 @@ async function precheckLocalWorktreeRemovable(self, args) {
|
|
|
62946
63104
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains." + sessionPreservedNote
|
|
62947
63105
|
};
|
|
62948
63106
|
}
|
|
62949
|
-
if (!
|
|
63107
|
+
if (!fs34.existsSync(workspace)) return { ok: true };
|
|
62950
63108
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
62951
63109
|
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 || !
|
|
63110
|
+
if (!repoRoot || !fs34.existsSync(repoRoot)) {
|
|
62953
63111
|
return {
|
|
62954
63112
|
ok: false,
|
|
62955
63113
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -62969,7 +63127,7 @@ async function precheckLocalWorktreeRemovable(self, args) {
|
|
|
62969
63127
|
const normalizePath = (value) => {
|
|
62970
63128
|
const resolved = (0, import_path15.resolve)(value);
|
|
62971
63129
|
try {
|
|
62972
|
-
return
|
|
63130
|
+
return fs34.realpathSync(resolved);
|
|
62973
63131
|
} catch {
|
|
62974
63132
|
return resolved;
|
|
62975
63133
|
}
|
|
@@ -63031,13 +63189,13 @@ async function cleanupLocalWorktreeNode(self, args) {
|
|
|
63031
63189
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains."
|
|
63032
63190
|
};
|
|
63033
63191
|
}
|
|
63034
|
-
const worktreeExists =
|
|
63192
|
+
const worktreeExists = fs34.existsSync(workspace);
|
|
63035
63193
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
63036
63194
|
const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
|
|
63037
63195
|
if (!worktreeExists) {
|
|
63038
63196
|
return { success: true, skipped: true, removedPath: workspace, repoRoot: repoRoot || void 0, reason: "worktree_path_missing" };
|
|
63039
63197
|
}
|
|
63040
|
-
if (!repoRoot || !
|
|
63198
|
+
if (!repoRoot || !fs34.existsSync(repoRoot)) {
|
|
63041
63199
|
return {
|
|
63042
63200
|
success: false,
|
|
63043
63201
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -63057,7 +63215,7 @@ async function cleanupLocalWorktreeNode(self, args) {
|
|
|
63057
63215
|
const normalizePath = (value) => {
|
|
63058
63216
|
const resolved = (0, import_path15.resolve)(value);
|
|
63059
63217
|
try {
|
|
63060
|
-
return
|
|
63218
|
+
return fs34.realpathSync(resolved);
|
|
63061
63219
|
} catch {
|
|
63062
63220
|
return resolved;
|
|
63063
63221
|
}
|
|
@@ -63696,7 +63854,7 @@ init_logger();
|
|
|
63696
63854
|
var yaml5 = __toESM(require("js-yaml"));
|
|
63697
63855
|
var import_os4 = require("os");
|
|
63698
63856
|
var import_path16 = require("path");
|
|
63699
|
-
var
|
|
63857
|
+
var fs35 = __toESM(require("fs"));
|
|
63700
63858
|
function loadYamlModule() {
|
|
63701
63859
|
return yaml5;
|
|
63702
63860
|
}
|
|
@@ -63720,9 +63878,9 @@ function resolveHermesUserHome() {
|
|
|
63720
63878
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
63721
63879
|
const sourceHome = resolveHermesUserHome();
|
|
63722
63880
|
const sourceConfigPath = (0, import_path16.join)(sourceHome, "config.yaml");
|
|
63723
|
-
if (!
|
|
63881
|
+
if (!fs35.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
63724
63882
|
if ((0, import_path16.resolve)(sourceConfigPath) === (0, import_path16.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
63725
|
-
const parsed = parseMeshCoordinatorMcpConfig(
|
|
63883
|
+
const parsed = parseMeshCoordinatorMcpConfig(fs35.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
63726
63884
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
63727
63885
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
63728
63886
|
}
|
|
@@ -63759,9 +63917,9 @@ function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
|
63759
63917
|
for (const fileName of [".env", "auth.json"]) {
|
|
63760
63918
|
const sourcePath = (0, import_path16.join)(sourceHome, fileName);
|
|
63761
63919
|
const targetPath = (0, import_path16.join)(targetHome, fileName);
|
|
63762
|
-
if (!
|
|
63920
|
+
if (!fs35.existsSync(sourcePath)) continue;
|
|
63763
63921
|
try {
|
|
63764
|
-
|
|
63922
|
+
fs35.copyFileSync(sourcePath, targetPath);
|
|
63765
63923
|
} catch (error) {
|
|
63766
63924
|
LOG.warn("MeshCoordinator", `Could not copy Hermes ${fileName} into isolated coordinator home: ${error?.message || error}`);
|
|
63767
63925
|
}
|
|
@@ -64162,7 +64320,7 @@ var DaemonCommandRouter = class {
|
|
|
64162
64320
|
const nodeId = readInlineMeshNodeId(node);
|
|
64163
64321
|
if (!nodeId || !tombstones.has(nodeId)) return true;
|
|
64164
64322
|
const workspace = readStringValue(node?.workspace);
|
|
64165
|
-
if (workspace &&
|
|
64323
|
+
if (workspace && fs36.existsSync(workspace)) {
|
|
64166
64324
|
tombstones.delete(nodeId);
|
|
64167
64325
|
return true;
|
|
64168
64326
|
}
|
|
@@ -64975,7 +65133,7 @@ var ProviderStreamAdapter = class {
|
|
|
64975
65133
|
const beforeCount = this.messageCount(before);
|
|
64976
65134
|
const beforeSignature = this.lastMessageSignature(before);
|
|
64977
65135
|
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
64978
|
-
await new Promise((
|
|
65136
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
64979
65137
|
let state;
|
|
64980
65138
|
try {
|
|
64981
65139
|
state = await this.readChat(evaluate);
|
|
@@ -64997,7 +65155,7 @@ var ProviderStreamAdapter = class {
|
|
|
64997
65155
|
if (this.messageCount(first) > 0 || this.lastMessageSignature(first)) {
|
|
64998
65156
|
return first;
|
|
64999
65157
|
}
|
|
65000
|
-
await new Promise((
|
|
65158
|
+
await new Promise((resolve26) => setTimeout(resolve26, 150));
|
|
65001
65159
|
const second = await this.readChat(evaluate);
|
|
65002
65160
|
return this.messageCount(second) >= this.messageCount(first) ? second : first;
|
|
65003
65161
|
}
|
|
@@ -65148,7 +65306,7 @@ var ProviderStreamAdapter = class {
|
|
|
65148
65306
|
if (typeof data.error === "string" && data.error.trim()) return false;
|
|
65149
65307
|
}
|
|
65150
65308
|
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
65151
|
-
await new Promise((
|
|
65309
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
65152
65310
|
const state = await this.readChat(evaluate);
|
|
65153
65311
|
const title = this.getStateTitle(state);
|
|
65154
65312
|
if (this.titlesMatch(title, sessionId)) return true;
|
|
@@ -66081,7 +66239,7 @@ init_io_contracts();
|
|
|
66081
66239
|
init_chat_message_normalization();
|
|
66082
66240
|
|
|
66083
66241
|
// src/providers/version-archive.ts
|
|
66084
|
-
var
|
|
66242
|
+
var fs37 = __toESM(require("fs"));
|
|
66085
66243
|
var path39 = __toESM(require("path"));
|
|
66086
66244
|
var os29 = __toESM(require("os"));
|
|
66087
66245
|
var import_os5 = require("os");
|
|
@@ -66095,8 +66253,8 @@ var VersionArchive = class {
|
|
|
66095
66253
|
}
|
|
66096
66254
|
load() {
|
|
66097
66255
|
try {
|
|
66098
|
-
if (
|
|
66099
|
-
this.history = JSON.parse(
|
|
66256
|
+
if (fs37.existsSync(ARCHIVE_PATH)) {
|
|
66257
|
+
this.history = JSON.parse(fs37.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
66100
66258
|
}
|
|
66101
66259
|
} catch {
|
|
66102
66260
|
this.history = {};
|
|
@@ -66133,20 +66291,20 @@ var VersionArchive = class {
|
|
|
66133
66291
|
}
|
|
66134
66292
|
save() {
|
|
66135
66293
|
try {
|
|
66136
|
-
|
|
66137
|
-
|
|
66294
|
+
fs37.mkdirSync(path39.dirname(ARCHIVE_PATH), { recursive: true });
|
|
66295
|
+
fs37.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
66138
66296
|
} catch {
|
|
66139
66297
|
}
|
|
66140
66298
|
}
|
|
66141
66299
|
};
|
|
66142
66300
|
async function runCommand(cmd, timeout = 1e4) {
|
|
66143
|
-
return new Promise((
|
|
66301
|
+
return new Promise((resolve26) => {
|
|
66144
66302
|
(0, import_child_process10.exec)(cmd, {
|
|
66145
66303
|
encoding: "utf-8",
|
|
66146
66304
|
timeout
|
|
66147
66305
|
}, (error, stdout) => {
|
|
66148
|
-
if (error) return
|
|
66149
|
-
|
|
66306
|
+
if (error) return resolve26(null);
|
|
66307
|
+
resolve26(stdout.trim());
|
|
66150
66308
|
});
|
|
66151
66309
|
});
|
|
66152
66310
|
}
|
|
@@ -66159,8 +66317,8 @@ function findBinary2(name) {
|
|
|
66159
66317
|
for (const ext of exes) {
|
|
66160
66318
|
const fullPath = path39.join(p, name + ext);
|
|
66161
66319
|
try {
|
|
66162
|
-
if (
|
|
66163
|
-
const stat2 =
|
|
66320
|
+
if (fs37.existsSync(fullPath)) {
|
|
66321
|
+
const stat2 = fs37.statSync(fullPath);
|
|
66164
66322
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
66165
66323
|
return fullPath;
|
|
66166
66324
|
}
|
|
@@ -66207,9 +66365,9 @@ function checkPathExists2(paths) {
|
|
|
66207
66365
|
if (p.includes("*")) {
|
|
66208
66366
|
const home = os29.homedir();
|
|
66209
66367
|
const resolved = p.replace(/\*/g, home.split(path39.sep).pop() || "");
|
|
66210
|
-
if (
|
|
66368
|
+
if (fs37.existsSync(resolved)) return resolved;
|
|
66211
66369
|
} else {
|
|
66212
|
-
if (
|
|
66370
|
+
if (fs37.existsSync(p)) return p;
|
|
66213
66371
|
}
|
|
66214
66372
|
}
|
|
66215
66373
|
return null;
|
|
@@ -66217,7 +66375,7 @@ function checkPathExists2(paths) {
|
|
|
66217
66375
|
async function getMacAppVersion(appPath) {
|
|
66218
66376
|
if ((0, import_os5.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
66219
66377
|
const plistPath = path39.join(appPath, "Contents", "Info.plist");
|
|
66220
|
-
if (!
|
|
66378
|
+
if (!fs37.existsSync(plistPath)) return null;
|
|
66221
66379
|
const raw = await runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
66222
66380
|
return raw || null;
|
|
66223
66381
|
}
|
|
@@ -66244,7 +66402,7 @@ async function detectAllVersions(loader, archive) {
|
|
|
66244
66402
|
let resolvedBin = cliBin;
|
|
66245
66403
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
66246
66404
|
const bundled = path39.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
66247
|
-
if (provider.cli &&
|
|
66405
|
+
if (provider.cli && fs37.existsSync(bundled)) resolvedBin = bundled;
|
|
66248
66406
|
}
|
|
66249
66407
|
info.installed = !!(appPath || resolvedBin);
|
|
66250
66408
|
info.path = appPath || null;
|
|
@@ -66292,7 +66450,7 @@ async function detectAllVersions(loader, archive) {
|
|
|
66292
66450
|
|
|
66293
66451
|
// src/daemon/dev-server.ts
|
|
66294
66452
|
var http2 = __toESM(require("http"));
|
|
66295
|
-
var
|
|
66453
|
+
var fs41 = __toESM(require("fs"));
|
|
66296
66454
|
var path43 = __toESM(require("path"));
|
|
66297
66455
|
init_config();
|
|
66298
66456
|
|
|
@@ -66644,7 +66802,7 @@ init_logger();
|
|
|
66644
66802
|
init_builders();
|
|
66645
66803
|
|
|
66646
66804
|
// src/daemon/dev-cdp-handlers.ts
|
|
66647
|
-
var
|
|
66805
|
+
var fs38 = __toESM(require("fs"));
|
|
66648
66806
|
var path40 = __toESM(require("path"));
|
|
66649
66807
|
init_logger();
|
|
66650
66808
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
@@ -66825,17 +66983,17 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
66825
66983
|
}
|
|
66826
66984
|
let scriptsPath = "";
|
|
66827
66985
|
const directScripts = path40.join(dir, "scripts.js");
|
|
66828
|
-
if (
|
|
66986
|
+
if (fs38.existsSync(directScripts)) {
|
|
66829
66987
|
scriptsPath = directScripts;
|
|
66830
66988
|
} else {
|
|
66831
66989
|
const scriptsDir = path40.join(dir, "scripts");
|
|
66832
|
-
if (
|
|
66833
|
-
const versions =
|
|
66834
|
-
return
|
|
66990
|
+
if (fs38.existsSync(scriptsDir)) {
|
|
66991
|
+
const versions = fs38.readdirSync(scriptsDir).filter((d) => {
|
|
66992
|
+
return fs38.statSync(path40.join(scriptsDir, d)).isDirectory();
|
|
66835
66993
|
}).sort().reverse();
|
|
66836
66994
|
for (const ver of versions) {
|
|
66837
66995
|
const p = path40.join(scriptsDir, ver, "scripts.js");
|
|
66838
|
-
if (
|
|
66996
|
+
if (fs38.existsSync(p)) {
|
|
66839
66997
|
scriptsPath = p;
|
|
66840
66998
|
break;
|
|
66841
66999
|
}
|
|
@@ -66847,7 +67005,7 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
66847
67005
|
return;
|
|
66848
67006
|
}
|
|
66849
67007
|
try {
|
|
66850
|
-
const source =
|
|
67008
|
+
const source = fs38.readFileSync(scriptsPath, "utf-8");
|
|
66851
67009
|
const hints = {};
|
|
66852
67010
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
66853
67011
|
let match;
|
|
@@ -67662,7 +67820,7 @@ async function handleDomContext(ctx, type, req, res) {
|
|
|
67662
67820
|
}
|
|
67663
67821
|
|
|
67664
67822
|
// src/daemon/dev-cli-debug.ts
|
|
67665
|
-
var
|
|
67823
|
+
var fs39 = __toESM(require("fs"));
|
|
67666
67824
|
var path41 = __toESM(require("path"));
|
|
67667
67825
|
function slugifyFixtureName(value) {
|
|
67668
67826
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -67678,10 +67836,10 @@ function getCliFixtureDir(ctx, type) {
|
|
|
67678
67836
|
function readCliFixture(ctx, type, name) {
|
|
67679
67837
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
67680
67838
|
const filePath = path41.join(fixtureDir, `${name}.json`);
|
|
67681
|
-
if (!
|
|
67839
|
+
if (!fs39.existsSync(filePath)) {
|
|
67682
67840
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
67683
67841
|
}
|
|
67684
|
-
return JSON.parse(
|
|
67842
|
+
return JSON.parse(fs39.readFileSync(filePath, "utf-8"));
|
|
67685
67843
|
}
|
|
67686
67844
|
function getExerciseTranscriptText(result) {
|
|
67687
67845
|
const parts = [];
|
|
@@ -67846,7 +68004,7 @@ function getCliTargetBundle(ctx, type, instanceId) {
|
|
|
67846
68004
|
return { target, instance, adapter };
|
|
67847
68005
|
}
|
|
67848
68006
|
function sleep2(ms) {
|
|
67849
|
-
return new Promise((
|
|
68007
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
67850
68008
|
}
|
|
67851
68009
|
async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
|
|
67852
68010
|
const startedAt = Date.now();
|
|
@@ -68426,7 +68584,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68426
68584
|
return;
|
|
68427
68585
|
}
|
|
68428
68586
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
68429
|
-
|
|
68587
|
+
fs39.mkdirSync(fixtureDir, { recursive: true });
|
|
68430
68588
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
68431
68589
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
68432
68590
|
const fixture = {
|
|
@@ -68454,7 +68612,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68454
68612
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
68455
68613
|
};
|
|
68456
68614
|
const filePath = path41.join(fixtureDir, `${name}.json`);
|
|
68457
|
-
|
|
68615
|
+
fs39.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
68458
68616
|
ctx.json(res, 200, {
|
|
68459
68617
|
saved: true,
|
|
68460
68618
|
name,
|
|
@@ -68472,14 +68630,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68472
68630
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
68473
68631
|
try {
|
|
68474
68632
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
68475
|
-
if (!
|
|
68633
|
+
if (!fs39.existsSync(fixtureDir)) {
|
|
68476
68634
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
68477
68635
|
return;
|
|
68478
68636
|
}
|
|
68479
|
-
const fixtures =
|
|
68637
|
+
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
68638
|
const fullPath = path41.join(fixtureDir, file);
|
|
68481
68639
|
try {
|
|
68482
|
-
const raw = JSON.parse(
|
|
68640
|
+
const raw = JSON.parse(fs39.readFileSync(fullPath, "utf-8"));
|
|
68483
68641
|
return {
|
|
68484
68642
|
name: raw.name || file.replace(/\.json$/i, ""),
|
|
68485
68643
|
path: fullPath,
|
|
@@ -68612,7 +68770,7 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
68612
68770
|
}
|
|
68613
68771
|
|
|
68614
68772
|
// src/daemon/dev-auto-implement.ts
|
|
68615
|
-
var
|
|
68773
|
+
var fs40 = __toESM(require("fs"));
|
|
68616
68774
|
var path42 = __toESM(require("path"));
|
|
68617
68775
|
var os30 = __toESM(require("os"));
|
|
68618
68776
|
var import_session_host_core9 = require("@adhdev/session-host-core");
|
|
@@ -68661,10 +68819,10 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
|
|
|
68661
68819
|
return fallback?.type || null;
|
|
68662
68820
|
}
|
|
68663
68821
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
68664
|
-
if (!
|
|
68665
|
-
const versions =
|
|
68822
|
+
if (!fs40.existsSync(scriptsDir)) return null;
|
|
68823
|
+
const versions = fs40.readdirSync(scriptsDir).filter((d) => {
|
|
68666
68824
|
try {
|
|
68667
|
-
return
|
|
68825
|
+
return fs40.statSync(path42.join(scriptsDir, d)).isDirectory();
|
|
68668
68826
|
} catch {
|
|
68669
68827
|
return false;
|
|
68670
68828
|
}
|
|
@@ -68686,13 +68844,13 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
68686
68844
|
if (!sourceDir) {
|
|
68687
68845
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
68688
68846
|
}
|
|
68689
|
-
if (!
|
|
68690
|
-
|
|
68691
|
-
|
|
68847
|
+
if (!fs40.existsSync(desiredDir)) {
|
|
68848
|
+
fs40.mkdirSync(path42.dirname(desiredDir), { recursive: true });
|
|
68849
|
+
fs40.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
68692
68850
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
68693
68851
|
}
|
|
68694
68852
|
const providerJson = path42.join(desiredDir, "provider.json");
|
|
68695
|
-
if (!
|
|
68853
|
+
if (!fs40.existsSync(providerJson)) {
|
|
68696
68854
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
68697
68855
|
}
|
|
68698
68856
|
return { dir: desiredDir };
|
|
@@ -68700,15 +68858,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
68700
68858
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
68701
68859
|
if (!referenceType) return {};
|
|
68702
68860
|
const refDir = ctx.findProviderDir(referenceType);
|
|
68703
|
-
if (!refDir || !
|
|
68861
|
+
if (!refDir || !fs40.existsSync(refDir)) return {};
|
|
68704
68862
|
const referenceScripts = {};
|
|
68705
68863
|
const scriptsDir = path42.join(refDir, "scripts");
|
|
68706
68864
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
68707
68865
|
if (!latestDir) return referenceScripts;
|
|
68708
|
-
for (const file of
|
|
68866
|
+
for (const file of fs40.readdirSync(latestDir)) {
|
|
68709
68867
|
if (!file.endsWith(".js")) continue;
|
|
68710
68868
|
try {
|
|
68711
|
-
referenceScripts[file] =
|
|
68869
|
+
referenceScripts[file] = fs40.readFileSync(path42.join(latestDir, file), "utf-8");
|
|
68712
68870
|
} catch {
|
|
68713
68871
|
}
|
|
68714
68872
|
}
|
|
@@ -68817,15 +68975,15 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
68817
68975
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
68818
68976
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
68819
68977
|
const tmpDir = path42.join(os30.tmpdir(), "adhdev-autoimpl");
|
|
68820
|
-
if (!
|
|
68978
|
+
if (!fs40.existsSync(tmpDir)) fs40.mkdirSync(tmpDir, { recursive: true });
|
|
68821
68979
|
const promptFile = path42.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
68822
|
-
|
|
68980
|
+
fs40.writeFileSync(promptFile, prompt, "utf-8");
|
|
68823
68981
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
68824
68982
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
68825
68983
|
const spawn5 = agentProvider?.spawn;
|
|
68826
68984
|
if (!spawn5?.command) {
|
|
68827
68985
|
try {
|
|
68828
|
-
|
|
68986
|
+
fs40.unlinkSync(promptFile);
|
|
68829
68987
|
} catch {
|
|
68830
68988
|
}
|
|
68831
68989
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -68927,7 +69085,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
68927
69085
|
} catch {
|
|
68928
69086
|
}
|
|
68929
69087
|
try {
|
|
68930
|
-
|
|
69088
|
+
fs40.unlinkSync(promptFile);
|
|
68931
69089
|
} catch {
|
|
68932
69090
|
}
|
|
68933
69091
|
ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -69153,7 +69311,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
69153
69311
|
}
|
|
69154
69312
|
});
|
|
69155
69313
|
try {
|
|
69156
|
-
|
|
69314
|
+
fs40.unlinkSync(promptFile);
|
|
69157
69315
|
} catch {
|
|
69158
69316
|
}
|
|
69159
69317
|
ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -69258,10 +69416,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
69258
69416
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
69259
69417
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
69260
69418
|
lines.push("");
|
|
69261
|
-
for (const file of
|
|
69419
|
+
for (const file of fs40.readdirSync(latestScriptsDir)) {
|
|
69262
69420
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
69263
69421
|
try {
|
|
69264
|
-
const content =
|
|
69422
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69265
69423
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
69266
69424
|
lines.push("```javascript");
|
|
69267
69425
|
lines.push(content);
|
|
@@ -69271,14 +69429,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
69271
69429
|
}
|
|
69272
69430
|
}
|
|
69273
69431
|
}
|
|
69274
|
-
const refFiles =
|
|
69432
|
+
const refFiles = fs40.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
69275
69433
|
if (refFiles.length > 0) {
|
|
69276
69434
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
69277
69435
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
69278
69436
|
lines.push("");
|
|
69279
69437
|
for (const file of refFiles) {
|
|
69280
69438
|
try {
|
|
69281
|
-
const content =
|
|
69439
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69282
69440
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
69283
69441
|
lines.push("```javascript");
|
|
69284
69442
|
lines.push(content);
|
|
@@ -69323,7 +69481,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
69323
69481
|
const loadGuide = (name) => {
|
|
69324
69482
|
try {
|
|
69325
69483
|
const p = path42.join(docsDir, name);
|
|
69326
|
-
if (
|
|
69484
|
+
if (fs40.existsSync(p)) return fs40.readFileSync(p, "utf-8");
|
|
69327
69485
|
} catch {
|
|
69328
69486
|
}
|
|
69329
69487
|
return null;
|
|
@@ -69567,11 +69725,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69567
69725
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
69568
69726
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
69569
69727
|
lines.push("");
|
|
69570
|
-
for (const file of
|
|
69728
|
+
for (const file of fs40.readdirSync(latestScriptsDir)) {
|
|
69571
69729
|
if (!file.endsWith(".js")) continue;
|
|
69572
69730
|
if (!targetFileNames.has(file)) continue;
|
|
69573
69731
|
try {
|
|
69574
|
-
const content =
|
|
69732
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69575
69733
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
69576
69734
|
lines.push("```javascript");
|
|
69577
69735
|
lines.push(content);
|
|
@@ -69580,14 +69738,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69580
69738
|
} catch {
|
|
69581
69739
|
}
|
|
69582
69740
|
}
|
|
69583
|
-
const refFiles =
|
|
69741
|
+
const refFiles = fs40.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
69584
69742
|
if (refFiles.length > 0) {
|
|
69585
69743
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
69586
69744
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
69587
69745
|
lines.push("");
|
|
69588
69746
|
for (const file of refFiles) {
|
|
69589
69747
|
try {
|
|
69590
|
-
const content =
|
|
69748
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69591
69749
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
69592
69750
|
lines.push("```javascript");
|
|
69593
69751
|
lines.push(content);
|
|
@@ -69624,7 +69782,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69624
69782
|
const loadGuide = (name) => {
|
|
69625
69783
|
try {
|
|
69626
69784
|
const p = path42.join(docsDir, name);
|
|
69627
|
-
if (
|
|
69785
|
+
if (fs40.existsSync(p)) return fs40.readFileSync(p, "utf-8");
|
|
69628
69786
|
} catch {
|
|
69629
69787
|
}
|
|
69630
69788
|
return null;
|
|
@@ -70102,15 +70260,15 @@ var DevServer = class _DevServer {
|
|
|
70102
70260
|
this.json(res, 500, { error: e.message });
|
|
70103
70261
|
}
|
|
70104
70262
|
});
|
|
70105
|
-
return new Promise((
|
|
70263
|
+
return new Promise((resolve26, reject) => {
|
|
70106
70264
|
this.server.listen(port, "127.0.0.1", () => {
|
|
70107
70265
|
this.log(`Dev server listening on http://127.0.0.1:${port}`);
|
|
70108
|
-
|
|
70266
|
+
resolve26();
|
|
70109
70267
|
});
|
|
70110
70268
|
this.server.on("error", (e) => {
|
|
70111
70269
|
if (e.code === "EADDRINUSE") {
|
|
70112
70270
|
this.log(`Port ${port} in use, skipping dev server`);
|
|
70113
|
-
|
|
70271
|
+
resolve26();
|
|
70114
70272
|
} else {
|
|
70115
70273
|
reject(e);
|
|
70116
70274
|
}
|
|
@@ -70192,20 +70350,20 @@ var DevServer = class _DevServer {
|
|
|
70192
70350
|
child.stderr?.on("data", (d) => {
|
|
70193
70351
|
stderr += d.toString().slice(0, 2e3);
|
|
70194
70352
|
});
|
|
70195
|
-
await new Promise((
|
|
70353
|
+
await new Promise((resolve26) => {
|
|
70196
70354
|
const timer = setTimeout(() => {
|
|
70197
70355
|
child.kill();
|
|
70198
|
-
|
|
70356
|
+
resolve26();
|
|
70199
70357
|
}, 3e3);
|
|
70200
70358
|
child.on("exit", () => {
|
|
70201
70359
|
clearTimeout(timer);
|
|
70202
|
-
|
|
70360
|
+
resolve26();
|
|
70203
70361
|
});
|
|
70204
70362
|
child.stdout?.once("data", () => {
|
|
70205
70363
|
setTimeout(() => {
|
|
70206
70364
|
child.kill();
|
|
70207
70365
|
clearTimeout(timer);
|
|
70208
|
-
|
|
70366
|
+
resolve26();
|
|
70209
70367
|
}, 500);
|
|
70210
70368
|
});
|
|
70211
70369
|
});
|
|
@@ -70364,7 +70522,7 @@ var DevServer = class _DevServer {
|
|
|
70364
70522
|
path43.join(process.cwd(), "packages/web-devconsole/dist")
|
|
70365
70523
|
];
|
|
70366
70524
|
for (const dir of candidates) {
|
|
70367
|
-
if (
|
|
70525
|
+
if (fs41.existsSync(path43.join(dir, "index.html"))) return dir;
|
|
70368
70526
|
}
|
|
70369
70527
|
return null;
|
|
70370
70528
|
}
|
|
@@ -70376,7 +70534,7 @@ var DevServer = class _DevServer {
|
|
|
70376
70534
|
}
|
|
70377
70535
|
const htmlPath = path43.join(distDir, "index.html");
|
|
70378
70536
|
try {
|
|
70379
|
-
const html =
|
|
70537
|
+
const html = fs41.readFileSync(htmlPath, "utf-8");
|
|
70380
70538
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
70381
70539
|
res.end(html);
|
|
70382
70540
|
} catch (e) {
|
|
@@ -70406,7 +70564,7 @@ var DevServer = class _DevServer {
|
|
|
70406
70564
|
return;
|
|
70407
70565
|
}
|
|
70408
70566
|
try {
|
|
70409
|
-
const content =
|
|
70567
|
+
const content = fs41.readFileSync(filePath);
|
|
70410
70568
|
const ext = path43.extname(filePath);
|
|
70411
70569
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
70412
70570
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
@@ -70515,14 +70673,14 @@ var DevServer = class _DevServer {
|
|
|
70515
70673
|
const files = [];
|
|
70516
70674
|
const scan = (d, prefix) => {
|
|
70517
70675
|
try {
|
|
70518
|
-
for (const entry of
|
|
70676
|
+
for (const entry of fs41.readdirSync(d, { withFileTypes: true })) {
|
|
70519
70677
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
70520
70678
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
70521
70679
|
if (entry.isDirectory()) {
|
|
70522
70680
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
70523
70681
|
scan(path43.join(d, entry.name), rel);
|
|
70524
70682
|
} else {
|
|
70525
|
-
const stat2 =
|
|
70683
|
+
const stat2 = fs41.statSync(path43.join(d, entry.name));
|
|
70526
70684
|
files.push({ path: rel, size: stat2.size, type: "file" });
|
|
70527
70685
|
}
|
|
70528
70686
|
}
|
|
@@ -70550,11 +70708,11 @@ var DevServer = class _DevServer {
|
|
|
70550
70708
|
this.json(res, 403, { error: "Forbidden" });
|
|
70551
70709
|
return;
|
|
70552
70710
|
}
|
|
70553
|
-
if (!
|
|
70711
|
+
if (!fs41.existsSync(fullPath) || fs41.statSync(fullPath).isDirectory()) {
|
|
70554
70712
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
70555
70713
|
return;
|
|
70556
70714
|
}
|
|
70557
|
-
const content =
|
|
70715
|
+
const content = fs41.readFileSync(fullPath, "utf-8");
|
|
70558
70716
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
70559
70717
|
}
|
|
70560
70718
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -70576,9 +70734,9 @@ var DevServer = class _DevServer {
|
|
|
70576
70734
|
return;
|
|
70577
70735
|
}
|
|
70578
70736
|
try {
|
|
70579
|
-
if (
|
|
70580
|
-
|
|
70581
|
-
|
|
70737
|
+
if (fs41.existsSync(fullPath)) fs41.copyFileSync(fullPath, fullPath + ".bak");
|
|
70738
|
+
fs41.mkdirSync(path43.dirname(fullPath), { recursive: true });
|
|
70739
|
+
fs41.writeFileSync(fullPath, content, "utf-8");
|
|
70582
70740
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
70583
70741
|
this.providerLoader.reload();
|
|
70584
70742
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -70595,8 +70753,8 @@ var DevServer = class _DevServer {
|
|
|
70595
70753
|
}
|
|
70596
70754
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
70597
70755
|
const p = path43.join(dir, name);
|
|
70598
|
-
if (
|
|
70599
|
-
const source =
|
|
70756
|
+
if (fs41.existsSync(p)) {
|
|
70757
|
+
const source = fs41.readFileSync(p, "utf-8");
|
|
70600
70758
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
70601
70759
|
return;
|
|
70602
70760
|
}
|
|
@@ -70615,11 +70773,11 @@ var DevServer = class _DevServer {
|
|
|
70615
70773
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
70616
70774
|
return;
|
|
70617
70775
|
}
|
|
70618
|
-
const target =
|
|
70776
|
+
const target = fs41.existsSync(path43.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
70619
70777
|
const targetPath = path43.join(dir, target);
|
|
70620
70778
|
try {
|
|
70621
|
-
if (
|
|
70622
|
-
|
|
70779
|
+
if (fs41.existsSync(targetPath)) fs41.copyFileSync(targetPath, targetPath + ".bak");
|
|
70780
|
+
fs41.writeFileSync(targetPath, source, "utf-8");
|
|
70623
70781
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
70624
70782
|
this.providerLoader.reload();
|
|
70625
70783
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -70708,14 +70866,14 @@ var DevServer = class _DevServer {
|
|
|
70708
70866
|
child.stderr?.on("data", (d) => {
|
|
70709
70867
|
stderr += d.toString();
|
|
70710
70868
|
});
|
|
70711
|
-
await new Promise((
|
|
70869
|
+
await new Promise((resolve26) => {
|
|
70712
70870
|
const timer = setTimeout(() => {
|
|
70713
70871
|
child.kill();
|
|
70714
|
-
|
|
70872
|
+
resolve26();
|
|
70715
70873
|
}, timeout);
|
|
70716
70874
|
child.on("exit", () => {
|
|
70717
70875
|
clearTimeout(timer);
|
|
70718
|
-
|
|
70876
|
+
resolve26();
|
|
70719
70877
|
});
|
|
70720
70878
|
});
|
|
70721
70879
|
const elapsed = Date.now() - start;
|
|
@@ -70764,20 +70922,20 @@ var DevServer = class _DevServer {
|
|
|
70764
70922
|
let targetDir;
|
|
70765
70923
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
70766
70924
|
const jsonPath = path43.join(targetDir, "provider.json");
|
|
70767
|
-
if (
|
|
70925
|
+
if (fs41.existsSync(jsonPath)) {
|
|
70768
70926
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
70769
70927
|
return;
|
|
70770
70928
|
}
|
|
70771
70929
|
try {
|
|
70772
70930
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
|
|
70773
|
-
|
|
70774
|
-
|
|
70931
|
+
fs41.mkdirSync(targetDir, { recursive: true });
|
|
70932
|
+
fs41.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
70775
70933
|
const createdFiles = ["provider.json"];
|
|
70776
70934
|
if (result.files) {
|
|
70777
70935
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
70778
70936
|
const fullPath = path43.join(targetDir, relPath);
|
|
70779
|
-
|
|
70780
|
-
|
|
70937
|
+
fs41.mkdirSync(path43.dirname(fullPath), { recursive: true });
|
|
70938
|
+
fs41.writeFileSync(fullPath, content, "utf-8");
|
|
70781
70939
|
createdFiles.push(relPath);
|
|
70782
70940
|
}
|
|
70783
70941
|
}
|
|
@@ -70826,10 +70984,10 @@ var DevServer = class _DevServer {
|
|
|
70826
70984
|
}
|
|
70827
70985
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
70828
70986
|
getLatestScriptVersionDir(scriptsDir) {
|
|
70829
|
-
if (!
|
|
70830
|
-
const versions =
|
|
70987
|
+
if (!fs41.existsSync(scriptsDir)) return null;
|
|
70988
|
+
const versions = fs41.readdirSync(scriptsDir).filter((d) => {
|
|
70831
70989
|
try {
|
|
70832
|
-
return
|
|
70990
|
+
return fs41.statSync(path43.join(scriptsDir, d)).isDirectory();
|
|
70833
70991
|
} catch {
|
|
70834
70992
|
return false;
|
|
70835
70993
|
}
|
|
@@ -70851,13 +71009,13 @@ var DevServer = class _DevServer {
|
|
|
70851
71009
|
if (!sourceDir) {
|
|
70852
71010
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
70853
71011
|
}
|
|
70854
|
-
if (!
|
|
70855
|
-
|
|
70856
|
-
|
|
71012
|
+
if (!fs41.existsSync(desiredDir)) {
|
|
71013
|
+
fs41.mkdirSync(path43.dirname(desiredDir), { recursive: true });
|
|
71014
|
+
fs41.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
70857
71015
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
70858
71016
|
}
|
|
70859
71017
|
const providerJson = path43.join(desiredDir, "provider.json");
|
|
70860
|
-
if (!
|
|
71018
|
+
if (!fs41.existsSync(providerJson)) {
|
|
70861
71019
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
70862
71020
|
}
|
|
70863
71021
|
return { dir: desiredDir };
|
|
@@ -70914,14 +71072,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
70914
71072
|
res.end(JSON.stringify(data, null, 2));
|
|
70915
71073
|
}
|
|
70916
71074
|
async readBody(req) {
|
|
70917
|
-
return new Promise((
|
|
71075
|
+
return new Promise((resolve26) => {
|
|
70918
71076
|
let body = "";
|
|
70919
71077
|
req.on("data", (chunk) => body += chunk);
|
|
70920
71078
|
req.on("end", () => {
|
|
70921
71079
|
try {
|
|
70922
|
-
|
|
71080
|
+
resolve26(JSON.parse(body));
|
|
70923
71081
|
} catch {
|
|
70924
|
-
|
|
71082
|
+
resolve26({});
|
|
70925
71083
|
}
|
|
70926
71084
|
});
|
|
70927
71085
|
});
|
|
@@ -71656,7 +71814,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRe
|
|
|
71656
71814
|
const deadline = Date.now() + timeoutMs;
|
|
71657
71815
|
while (Date.now() < deadline) {
|
|
71658
71816
|
if (await canConnect(endpoint, requiredRequestTypes)) return;
|
|
71659
|
-
await new Promise((
|
|
71817
|
+
await new Promise((resolve26) => setTimeout(resolve26, STARTUP_POLL_MS));
|
|
71660
71818
|
}
|
|
71661
71819
|
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
71662
71820
|
}
|
|
@@ -71699,7 +71857,7 @@ async function listHostedCliRuntimes(endpoint) {
|
|
|
71699
71857
|
|
|
71700
71858
|
// src/session-host/managed-host.ts
|
|
71701
71859
|
var import_child_process11 = require("child_process");
|
|
71702
|
-
var
|
|
71860
|
+
var fs42 = __toESM(require("fs"));
|
|
71703
71861
|
var os31 = __toESM(require("os"));
|
|
71704
71862
|
var path44 = __toESM(require("path"));
|
|
71705
71863
|
var import_session_host_core13 = require("@adhdev/session-host-core");
|
|
@@ -71720,7 +71878,7 @@ function createManagedSessionHost(options) {
|
|
|
71720
71878
|
path44.resolve(__dirname, "../../vendor/session-host-daemon/index.js")
|
|
71721
71879
|
];
|
|
71722
71880
|
for (const candidate of packagedCandidates) {
|
|
71723
|
-
if (
|
|
71881
|
+
if (fs42.existsSync(candidate)) {
|
|
71724
71882
|
return candidate;
|
|
71725
71883
|
}
|
|
71726
71884
|
}
|
|
@@ -71732,8 +71890,8 @@ function createManagedSessionHost(options) {
|
|
|
71732
71890
|
function getPid() {
|
|
71733
71891
|
try {
|
|
71734
71892
|
const pidFile = getPidFile();
|
|
71735
|
-
if (!
|
|
71736
|
-
const pid = Number.parseInt(
|
|
71893
|
+
if (!fs42.existsSync(pidFile)) return null;
|
|
71894
|
+
const pid = Number.parseInt(fs42.readFileSync(pidFile, "utf8").trim(), 10);
|
|
71737
71895
|
return Number.isFinite(pid) ? pid : null;
|
|
71738
71896
|
} catch {
|
|
71739
71897
|
return null;
|
|
@@ -71759,8 +71917,8 @@ function createManagedSessionHost(options) {
|
|
|
71759
71917
|
let logFd = null;
|
|
71760
71918
|
if (options.spawnStdio === "logfile") {
|
|
71761
71919
|
const logDir = path44.join(os31.homedir(), ".adhdev", "logs");
|
|
71762
|
-
|
|
71763
|
-
logFd =
|
|
71920
|
+
fs42.mkdirSync(logDir, { recursive: true });
|
|
71921
|
+
logFd = fs42.openSync(path44.join(logDir, "session-host.log"), "a");
|
|
71764
71922
|
stdio = ["ignore", logFd, logFd];
|
|
71765
71923
|
}
|
|
71766
71924
|
const child = (0, import_child_process11.spawn)(process.execPath, [entry], {
|
|
@@ -71772,7 +71930,7 @@ function createManagedSessionHost(options) {
|
|
|
71772
71930
|
child.unref();
|
|
71773
71931
|
if (logFd !== null) {
|
|
71774
71932
|
try {
|
|
71775
|
-
|
|
71933
|
+
fs42.closeSync(logFd);
|
|
71776
71934
|
} catch {
|
|
71777
71935
|
}
|
|
71778
71936
|
}
|
|
@@ -71781,8 +71939,8 @@ function createManagedSessionHost(options) {
|
|
|
71781
71939
|
let stopped = false;
|
|
71782
71940
|
const pidFile = getPidFile();
|
|
71783
71941
|
try {
|
|
71784
|
-
if (
|
|
71785
|
-
const pid = Number.parseInt(
|
|
71942
|
+
if (fs42.existsSync(pidFile)) {
|
|
71943
|
+
const pid = Number.parseInt(fs42.readFileSync(pidFile, "utf8").trim(), 10);
|
|
71786
71944
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedPid(pid)) {
|
|
71787
71945
|
stopped = killPid2(pid) || stopped;
|
|
71788
71946
|
}
|
|
@@ -71790,7 +71948,7 @@ function createManagedSessionHost(options) {
|
|
|
71790
71948
|
} catch {
|
|
71791
71949
|
} finally {
|
|
71792
71950
|
try {
|
|
71793
|
-
|
|
71951
|
+
fs42.unlinkSync(pidFile);
|
|
71794
71952
|
} catch {
|
|
71795
71953
|
}
|
|
71796
71954
|
}
|
|
@@ -71979,12 +72137,12 @@ async function installExtension(ide, extension) {
|
|
|
71979
72137
|
const res = await fetch(extension.vsixUrl);
|
|
71980
72138
|
if (res.ok) {
|
|
71981
72139
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
71982
|
-
const
|
|
71983
|
-
|
|
71984
|
-
return new Promise((
|
|
72140
|
+
const fs43 = await import("fs");
|
|
72141
|
+
fs43.writeFileSync(vsixPath, buffer);
|
|
72142
|
+
return new Promise((resolve26) => {
|
|
71985
72143
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
71986
72144
|
(0, import_child_process12.exec)(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|
|
71987
|
-
|
|
72145
|
+
resolve26({
|
|
71988
72146
|
extensionId: extension.id,
|
|
71989
72147
|
marketplaceId: extension.marketplaceId,
|
|
71990
72148
|
success: !error,
|
|
@@ -71997,11 +72155,11 @@ async function installExtension(ide, extension) {
|
|
|
71997
72155
|
} catch (e) {
|
|
71998
72156
|
}
|
|
71999
72157
|
}
|
|
72000
|
-
return new Promise((
|
|
72158
|
+
return new Promise((resolve26) => {
|
|
72001
72159
|
const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
|
|
72002
72160
|
(0, import_child_process12.exec)(cmd, { timeout: 6e4 }, (error, stdout, stderr) => {
|
|
72003
72161
|
if (error) {
|
|
72004
|
-
|
|
72162
|
+
resolve26({
|
|
72005
72163
|
extensionId: extension.id,
|
|
72006
72164
|
marketplaceId: extension.marketplaceId,
|
|
72007
72165
|
success: false,
|
|
@@ -72009,7 +72167,7 @@ async function installExtension(ide, extension) {
|
|
|
72009
72167
|
error: stderr || error.message
|
|
72010
72168
|
});
|
|
72011
72169
|
} else {
|
|
72012
|
-
|
|
72170
|
+
resolve26({
|
|
72013
72171
|
extensionId: extension.id,
|
|
72014
72172
|
marketplaceId: extension.marketplaceId,
|
|
72015
72173
|
success: true,
|
|
@@ -72545,7 +72703,7 @@ async function startLocalIpcServer(opts) {
|
|
|
72545
72703
|
}));
|
|
72546
72704
|
}
|
|
72547
72705
|
}
|
|
72548
|
-
await new Promise((
|
|
72706
|
+
await new Promise((resolve26, reject) => {
|
|
72549
72707
|
const onError = (error) => {
|
|
72550
72708
|
httpServer?.off("listening", onListening);
|
|
72551
72709
|
reject(error);
|
|
@@ -72553,7 +72711,7 @@ async function startLocalIpcServer(opts) {
|
|
|
72553
72711
|
const onListening = () => {
|
|
72554
72712
|
httpServer?.off("error", onError);
|
|
72555
72713
|
listening = true;
|
|
72556
|
-
|
|
72714
|
+
resolve26();
|
|
72557
72715
|
};
|
|
72558
72716
|
httpServer.once("error", onError);
|
|
72559
72717
|
httpServer.once("listening", onListening);
|
|
@@ -72580,12 +72738,12 @@ async function startLocalIpcServer(opts) {
|
|
|
72580
72738
|
}
|
|
72581
72739
|
}
|
|
72582
72740
|
clients.clear();
|
|
72583
|
-
await new Promise((
|
|
72741
|
+
await new Promise((resolve26) => {
|
|
72584
72742
|
if (!httpServer) {
|
|
72585
|
-
|
|
72743
|
+
resolve26();
|
|
72586
72744
|
return;
|
|
72587
72745
|
}
|
|
72588
|
-
httpServer.close(() =>
|
|
72746
|
+
httpServer.close(() => resolve26());
|
|
72589
72747
|
});
|
|
72590
72748
|
httpServer = null;
|
|
72591
72749
|
wss = null;
|