@adhdev/daemon-core 0.9.82-rc.540 → 0.9.82-rc.541
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-adapters/cli-state-engine.d.ts +12 -0
- package/dist/commands/chat-commands-read.d.ts +3 -0
- package/dist/index.js +740 -588
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +747 -595
- package/dist/index.mjs.map +1 -1
- package/dist/providers/spec/types.d.ts +57 -2
- package/package.json +3 -3
- package/src/cli-adapters/cli-state-engine.ts +76 -1
- package/src/commands/chat-commands-read.ts +28 -1
- package/src/mesh/coordinator-prompt.ts +2 -1
- package/src/providers/spec/native-history-executor.ts +174 -9
- package/src/providers/spec/types.ts +54 -2
package/dist/index.mjs
CHANGED
|
@@ -414,10 +414,10 @@ function readInjected(value) {
|
|
|
414
414
|
}
|
|
415
415
|
function getDaemonBuildInfo() {
|
|
416
416
|
if (cached) return cached;
|
|
417
|
-
const commit = readInjected(true ? "
|
|
418
|
-
const commitShort = readInjected(true ? "
|
|
419
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
420
|
-
const builtAt = readInjected(true ? "2026-07-
|
|
417
|
+
const commit = readInjected(true ? "77f3fad0358bec7e4474ead5b2510e19a4cc2cc4" : void 0) ?? "unknown";
|
|
418
|
+
const commitShort = readInjected(true ? "77f3fad0" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
419
|
+
const version = readInjected(true ? "0.9.82-rc.541" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
420
|
+
const builtAt = readInjected(true ? "2026-07-16T05:30:52.044Z" : void 0);
|
|
421
421
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
422
422
|
return cached;
|
|
423
423
|
}
|
|
@@ -4070,7 +4070,8 @@ function buildRulesSection(coordinatorCliType) {
|
|
|
4070
4070
|
- **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.` : "";
|
|
4071
4071
|
return `## Rules
|
|
4072
4072
|
|
|
4073
|
-
- **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.
|
|
4073
|
+
- **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.
|
|
4074
|
+
- **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.
|
|
4074
4075
|
- **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\`.
|
|
4075
4076
|
- **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.
|
|
4076
4077
|
- **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.
|
|
@@ -10646,8 +10647,8 @@ function stripCoordinatorWrapperFile(filePath) {
|
|
|
10646
10647
|
const remaining = (existing.slice(0, openIdx) + existing.slice(closeIdx + CLOSE.length)).replace(/^\s*\n+/, "").replace(/\n+\s*$/, "");
|
|
10647
10648
|
if (!remaining.trim()) {
|
|
10648
10649
|
try {
|
|
10649
|
-
const
|
|
10650
|
-
|
|
10650
|
+
const fs43 = __require("fs");
|
|
10651
|
+
fs43.unlinkSync(filePath);
|
|
10651
10652
|
} catch {
|
|
10652
10653
|
}
|
|
10653
10654
|
} else {
|
|
@@ -12644,9 +12645,9 @@ function findBinary(name) {
|
|
|
12644
12645
|
for (const ext of exes) {
|
|
12645
12646
|
const fullPath = path11.join(p, trimmed + ext);
|
|
12646
12647
|
try {
|
|
12647
|
-
const
|
|
12648
|
-
if (
|
|
12649
|
-
const stat2 =
|
|
12648
|
+
const fs43 = __require("fs");
|
|
12649
|
+
if (fs43.existsSync(fullPath)) {
|
|
12650
|
+
const stat2 = fs43.statSync(fullPath);
|
|
12650
12651
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
12651
12652
|
return fullPath;
|
|
12652
12653
|
}
|
|
@@ -12660,12 +12661,12 @@ function findBinary(name) {
|
|
|
12660
12661
|
function isScriptBinary(binaryPath) {
|
|
12661
12662
|
if (!path11.isAbsolute(binaryPath)) return false;
|
|
12662
12663
|
try {
|
|
12663
|
-
const
|
|
12664
|
-
const resolved =
|
|
12664
|
+
const fs43 = __require("fs");
|
|
12665
|
+
const resolved = fs43.realpathSync(binaryPath);
|
|
12665
12666
|
const head = Buffer.alloc(8);
|
|
12666
|
-
const fd =
|
|
12667
|
-
|
|
12668
|
-
|
|
12667
|
+
const fd = fs43.openSync(resolved, "r");
|
|
12668
|
+
fs43.readSync(fd, head, 0, 8, 0);
|
|
12669
|
+
fs43.closeSync(fd);
|
|
12669
12670
|
let i = 0;
|
|
12670
12671
|
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
12671
12672
|
return head[i] === 35 && head[i + 1] === 33;
|
|
@@ -12676,12 +12677,12 @@ function isScriptBinary(binaryPath) {
|
|
|
12676
12677
|
function looksLikeMachOOrElf(filePath) {
|
|
12677
12678
|
if (!path11.isAbsolute(filePath)) return false;
|
|
12678
12679
|
try {
|
|
12679
|
-
const
|
|
12680
|
-
const resolved =
|
|
12680
|
+
const fs43 = __require("fs");
|
|
12681
|
+
const resolved = fs43.realpathSync(filePath);
|
|
12681
12682
|
const buf = Buffer.alloc(8);
|
|
12682
|
-
const fd =
|
|
12683
|
-
|
|
12684
|
-
|
|
12683
|
+
const fd = fs43.openSync(resolved, "r");
|
|
12684
|
+
fs43.readSync(fd, buf, 0, 8, 0);
|
|
12685
|
+
fs43.closeSync(fd);
|
|
12685
12686
|
let i = 0;
|
|
12686
12687
|
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
12687
12688
|
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 = 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) {
|
|
@@ -13126,7 +13127,7 @@ var init_runtime_surface = __esm({
|
|
|
13126
13127
|
// src/mesh/mesh-warmup-deadline.ts
|
|
13127
13128
|
function awaitWithWarmupDeadline(work, opts) {
|
|
13128
13129
|
const pollMs = Math.max(1, Math.min(opts.pollIntervalMs ?? 200, opts.connectTimeoutMs));
|
|
13129
|
-
return new Promise((
|
|
13130
|
+
return new Promise((resolve26, reject) => {
|
|
13130
13131
|
let done = false;
|
|
13131
13132
|
let poll;
|
|
13132
13133
|
let responseTimer;
|
|
@@ -13176,7 +13177,7 @@ function awaitWithWarmupDeadline(work, opts) {
|
|
|
13176
13177
|
if (typeof poll.unref === "function") poll.unref();
|
|
13177
13178
|
}
|
|
13178
13179
|
work.then(
|
|
13179
|
-
(val) => settle(() =>
|
|
13180
|
+
(val) => settle(() => resolve26(val)),
|
|
13180
13181
|
(err) => settle(() => reject(err))
|
|
13181
13182
|
);
|
|
13182
13183
|
});
|
|
@@ -14262,7 +14263,7 @@ async function probeRemoteMeshGitStatusWithRetry(args) {
|
|
|
14262
14263
|
const connection = args.getConnection?.(args.daemonId);
|
|
14263
14264
|
if (args.getConnection && readMeshConnectionState(connection) !== "connected") break;
|
|
14264
14265
|
if (connection) args.onConnection?.(connection);
|
|
14265
|
-
await new Promise((
|
|
14266
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250 * 2 ** (attempt - 1)));
|
|
14266
14267
|
}
|
|
14267
14268
|
try {
|
|
14268
14269
|
const remoteGit = await probeRemoteMeshGitStatus({
|
|
@@ -16046,7 +16047,7 @@ async function waitForLocalSessionReady(components, sessionId) {
|
|
|
16046
16047
|
const deadline = Date.now() + LOCAL_LAUNCH_READY_TIMEOUT_MS;
|
|
16047
16048
|
while (Date.now() < deadline) {
|
|
16048
16049
|
if (adapter.isReady() || adapter.currentStatus === "idle") return;
|
|
16049
|
-
await new Promise((
|
|
16050
|
+
await new Promise((resolve26) => setTimeout(resolve26, LOCAL_LAUNCH_READY_POLL_MS));
|
|
16050
16051
|
}
|
|
16051
16052
|
LOG.warn("MeshQueue", `Auto-launched session ${sessionId} not interactive after ${LOCAL_LAUNCH_READY_TIMEOUT_MS}ms; dispatching anyway (adapter queue-until-ready will buffer)`);
|
|
16052
16053
|
}
|
|
@@ -23714,7 +23715,7 @@ __export(external_sources_exports, {
|
|
|
23714
23715
|
sourcesFilePath: () => sourcesFilePath,
|
|
23715
23716
|
sourcesProviding: () => sourcesProviding
|
|
23716
23717
|
});
|
|
23717
|
-
import * as
|
|
23718
|
+
import * as fs11 from "fs";
|
|
23718
23719
|
import * as os12 from "os";
|
|
23719
23720
|
import * as path19 from "path";
|
|
23720
23721
|
function adhdevDir() {
|
|
@@ -23731,13 +23732,13 @@ function activeFilePath() {
|
|
|
23731
23732
|
}
|
|
23732
23733
|
function ensureAdhdevDir() {
|
|
23733
23734
|
const d = adhdevDir();
|
|
23734
|
-
if (!
|
|
23735
|
+
if (!fs11.existsSync(d)) fs11.mkdirSync(d, { recursive: true });
|
|
23735
23736
|
}
|
|
23736
23737
|
function loadExternalSources() {
|
|
23737
23738
|
const p = sourcesFilePath();
|
|
23738
|
-
if (!
|
|
23739
|
+
if (!fs11.existsSync(p)) return { schema: 1, sources: [] };
|
|
23739
23740
|
try {
|
|
23740
|
-
const raw = JSON.parse(
|
|
23741
|
+
const raw = JSON.parse(fs11.readFileSync(p, "utf-8"));
|
|
23741
23742
|
if (!raw || typeof raw !== "object") return { schema: 1, sources: [] };
|
|
23742
23743
|
const sources = Array.isArray(raw.sources) ? raw.sources.filter(isValidSource) : [];
|
|
23743
23744
|
return { schema: 1, sources };
|
|
@@ -23748,14 +23749,14 @@ function loadExternalSources() {
|
|
|
23748
23749
|
function saveExternalSources(file) {
|
|
23749
23750
|
ensureAdhdevDir();
|
|
23750
23751
|
const tmp = sourcesFilePath() + ".tmp";
|
|
23751
|
-
|
|
23752
|
-
|
|
23752
|
+
fs11.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n", "utf-8");
|
|
23753
|
+
fs11.renameSync(tmp, sourcesFilePath());
|
|
23753
23754
|
}
|
|
23754
23755
|
function loadProvidersActive() {
|
|
23755
23756
|
const p = activeFilePath();
|
|
23756
|
-
if (!
|
|
23757
|
+
if (!fs11.existsSync(p)) return { schema: 1, active: {} };
|
|
23757
23758
|
try {
|
|
23758
|
-
const raw = JSON.parse(
|
|
23759
|
+
const raw = JSON.parse(fs11.readFileSync(p, "utf-8"));
|
|
23759
23760
|
if (!raw || typeof raw !== "object") return { schema: 1, active: {} };
|
|
23760
23761
|
const active = raw.active && typeof raw.active === "object" ? raw.active : {};
|
|
23761
23762
|
return { schema: 1, active };
|
|
@@ -23766,8 +23767,8 @@ function loadProvidersActive() {
|
|
|
23766
23767
|
function saveProvidersActive(file) {
|
|
23767
23768
|
ensureAdhdevDir();
|
|
23768
23769
|
const tmp = activeFilePath() + ".tmp";
|
|
23769
|
-
|
|
23770
|
-
|
|
23770
|
+
fs11.writeFileSync(tmp, JSON.stringify(file, null, 2) + "\n", "utf-8");
|
|
23771
|
+
fs11.renameSync(tmp, activeFilePath());
|
|
23771
23772
|
}
|
|
23772
23773
|
function isValidSource(x) {
|
|
23773
23774
|
if (!x || typeof x !== "object") return false;
|
|
@@ -23783,11 +23784,11 @@ function deriveSourceName(url) {
|
|
|
23783
23784
|
}
|
|
23784
23785
|
function inventoryExternalSources() {
|
|
23785
23786
|
const root = externalRoot();
|
|
23786
|
-
if (!
|
|
23787
|
+
if (!fs11.existsSync(root)) return [];
|
|
23787
23788
|
const out = [];
|
|
23788
23789
|
let entries;
|
|
23789
23790
|
try {
|
|
23790
|
-
entries =
|
|
23791
|
+
entries = fs11.readdirSync(root, { withFileTypes: true });
|
|
23791
23792
|
} catch {
|
|
23792
23793
|
return [];
|
|
23793
23794
|
}
|
|
@@ -23798,7 +23799,7 @@ function inventoryExternalSources() {
|
|
|
23798
23799
|
const providers = {};
|
|
23799
23800
|
let categoryEntries;
|
|
23800
23801
|
try {
|
|
23801
|
-
categoryEntries =
|
|
23802
|
+
categoryEntries = fs11.readdirSync(sourceDir, { withFileTypes: true });
|
|
23802
23803
|
} catch {
|
|
23803
23804
|
continue;
|
|
23804
23805
|
}
|
|
@@ -23808,7 +23809,7 @@ function inventoryExternalSources() {
|
|
|
23808
23809
|
const categoryDir = path19.join(sourceDir, category);
|
|
23809
23810
|
let typeEntries;
|
|
23810
23811
|
try {
|
|
23811
|
-
typeEntries =
|
|
23812
|
+
typeEntries = fs11.readdirSync(categoryDir, { withFileTypes: true });
|
|
23812
23813
|
} catch {
|
|
23813
23814
|
continue;
|
|
23814
23815
|
}
|
|
@@ -23816,8 +23817,8 @@ function inventoryExternalSources() {
|
|
|
23816
23817
|
for (const typeEntry of typeEntries) {
|
|
23817
23818
|
if (!typeEntry.isDirectory()) continue;
|
|
23818
23819
|
const typeDir = path19.join(categoryDir, typeEntry.name);
|
|
23819
|
-
const hasV1 =
|
|
23820
|
-
const hasV0 =
|
|
23820
|
+
const hasV1 = fs11.existsSync(path19.join(typeDir, "provider.v1.json"));
|
|
23821
|
+
const hasV0 = fs11.existsSync(path19.join(typeDir, "provider.json"));
|
|
23821
23822
|
if (hasV1 || hasV0) types.push(typeEntry.name);
|
|
23822
23823
|
}
|
|
23823
23824
|
if (types.length > 0) providers[category] = types;
|
|
@@ -23890,11 +23891,11 @@ __export(fsm_loader_exports, {
|
|
|
23890
23891
|
loadFsmSpec: () => loadFsmSpec,
|
|
23891
23892
|
validateFsmSpec: () => validateFsmSpec
|
|
23892
23893
|
});
|
|
23893
|
-
import * as
|
|
23894
|
+
import * as fs12 from "fs";
|
|
23894
23895
|
function loadFsmSpec(sourcePath) {
|
|
23895
23896
|
let raw;
|
|
23896
23897
|
try {
|
|
23897
|
-
raw = JSON.parse(
|
|
23898
|
+
raw = JSON.parse(fs12.readFileSync(sourcePath, "utf8"));
|
|
23898
23899
|
} catch (err) {
|
|
23899
23900
|
return { ok: false, errors: [`Failed to read/parse spec: ${err.message}`], sourcePath };
|
|
23900
23901
|
}
|
|
@@ -24508,8 +24509,8 @@ var init_pty_transport = __esm({
|
|
|
24508
24509
|
let cwd = options.cwd;
|
|
24509
24510
|
if (cwd) {
|
|
24510
24511
|
try {
|
|
24511
|
-
const
|
|
24512
|
-
const stat2 =
|
|
24512
|
+
const fs43 = __require("fs");
|
|
24513
|
+
const stat2 = fs43.statSync(cwd);
|
|
24513
24514
|
if (!stat2.isDirectory()) cwd = os14.homedir();
|
|
24514
24515
|
} catch {
|
|
24515
24516
|
cwd = os14.homedir();
|
|
@@ -25497,7 +25498,7 @@ var init_provider_cli_parse = __esm({
|
|
|
25497
25498
|
});
|
|
25498
25499
|
|
|
25499
25500
|
// src/cli-adapters/cli-state-engine.ts
|
|
25500
|
-
var SCRIPT_STATUS_DEBOUNCE_MS, MAX_FINISH_RETRIES, FINISH_RETRY_DELAY_MS, MAX_TRACE_ENTRIES, APPROVAL_EXIT_TIMEOUT_MS, IDLE_CONFIRMATION_GRACE_MS, APPROVAL_RESUME_IDLE_DEFER_CAP_MS, CliStateEngine;
|
|
25501
|
+
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;
|
|
25501
25502
|
var init_cli_state_engine = __esm({
|
|
25502
25503
|
"src/cli-adapters/cli-state-engine.ts"() {
|
|
25503
25504
|
"use strict";
|
|
@@ -25511,6 +25512,7 @@ var init_cli_state_engine = __esm({
|
|
|
25511
25512
|
APPROVAL_EXIT_TIMEOUT_MS = 6e4;
|
|
25512
25513
|
IDLE_CONFIRMATION_GRACE_MS = 2e3;
|
|
25513
25514
|
APPROVAL_RESUME_IDLE_DEFER_CAP_MS = 18e3;
|
|
25515
|
+
SCREEN_QUIET_IDLE_MS = 5e3;
|
|
25514
25516
|
CliStateEngine = class {
|
|
25515
25517
|
constructor(provider, runner, transport, callbacks, timeouts) {
|
|
25516
25518
|
this.provider = provider;
|
|
@@ -26075,6 +26077,10 @@ var init_cli_state_engine = __esm({
|
|
|
26075
26077
|
this.idleTimeout = setTimeout(() => {
|
|
26076
26078
|
if (this.isWaitingForResponse && !this.hasActionableApproval()) {
|
|
26077
26079
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26080
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26081
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26082
|
+
return;
|
|
26083
|
+
}
|
|
26078
26084
|
this.finishResponse();
|
|
26079
26085
|
}
|
|
26080
26086
|
}, this.timeouts.generatingIdle);
|
|
@@ -26097,6 +26103,10 @@ var init_cli_state_engine = __esm({
|
|
|
26097
26103
|
this.idleTimeout = setTimeout(() => {
|
|
26098
26104
|
if (this.isWaitingForResponse && !this.hasActionableApproval()) {
|
|
26099
26105
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26106
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26107
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26108
|
+
return;
|
|
26109
|
+
}
|
|
26100
26110
|
this.finishResponse();
|
|
26101
26111
|
}
|
|
26102
26112
|
}, this.timeouts.generatingIdle);
|
|
@@ -26165,6 +26175,10 @@ var init_cli_state_engine = __esm({
|
|
|
26165
26175
|
this.idleTimeout = setTimeout(() => {
|
|
26166
26176
|
if (this.isWaitingForResponse) {
|
|
26167
26177
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26178
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26179
|
+
this.evaluateSettled(this.transport.getSnapshot());
|
|
26180
|
+
return;
|
|
26181
|
+
}
|
|
26168
26182
|
this.finishResponse();
|
|
26169
26183
|
}
|
|
26170
26184
|
}, this.timeouts.generatingIdle);
|
|
@@ -26250,7 +26264,8 @@ var init_cli_state_engine = __esm({
|
|
|
26250
26264
|
const assistantLength = lastParsedAssistant?.content?.length || 0;
|
|
26251
26265
|
const idleFinishConfirmMs = this.timeouts.idleFinishConfirm;
|
|
26252
26266
|
const idleQuietThresholdMs = Math.max(idleFinishConfirmMs, this.timeouts.outputSettle);
|
|
26253
|
-
const
|
|
26267
|
+
const screenQuietForIdle = screenStableMs >= SCREEN_QUIET_IDLE_MS;
|
|
26268
|
+
const idleReady = !modal && hasAssistantTurn && quietForMs >= idleQuietThresholdMs && screenStableMs >= idleFinishConfirmMs && screenQuietForIdle;
|
|
26254
26269
|
const candidate = this.idleFinishCandidate;
|
|
26255
26270
|
const candidateQuiet = !!candidate && candidate.responseEpoch === this.responseEpoch && candidate.lastOutputAt === snap.lastOutputAt && candidate.lastScreenChangeAt === snap.lastScreenChangeAt && assistantLength >= candidate.assistantLength && now - candidate.armedAt >= idleFinishConfirmMs;
|
|
26256
26271
|
if (this.shouldDeferIdleForApprovalResume(now)) {
|
|
@@ -26285,6 +26300,13 @@ var init_cli_state_engine = __esm({
|
|
|
26285
26300
|
return;
|
|
26286
26301
|
}
|
|
26287
26302
|
if (this.shouldDeferIdleTimeoutFinish()) return;
|
|
26303
|
+
if (!this.hasScreenBeenQuietForIdle(Date.now())) {
|
|
26304
|
+
if (this.idleTimeout) clearTimeout(this.idleTimeout);
|
|
26305
|
+
this.idleTimeout = setTimeout(() => {
|
|
26306
|
+
if (this.isWaitingForResponse) this.evaluateSettled(this.transport.getSnapshot());
|
|
26307
|
+
}, this.timeouts.idleFinish);
|
|
26308
|
+
return;
|
|
26309
|
+
}
|
|
26288
26310
|
const parsed = this.runParseSession(this.transport.getSnapshot());
|
|
26289
26311
|
if (this.shouldDeferFinishForTranscript(parsed)) {
|
|
26290
26312
|
this.rescheduleTranscriptFinishCheck("transcript_idle_timeout_not_final");
|
|
@@ -26295,6 +26317,22 @@ var init_cli_state_engine = __esm({
|
|
|
26295
26317
|
}
|
|
26296
26318
|
}, this.timeouts.idleFinish);
|
|
26297
26319
|
}
|
|
26320
|
+
/**
|
|
26321
|
+
* FALSE-IDLE (screen-quiet gate): has the visible terminal screen content been
|
|
26322
|
+
* byte-identical for at least SCREEN_QUIET_IDLE_MS continuously?
|
|
26323
|
+
*
|
|
26324
|
+
* `lastScreenChangeAt` is bumped by the adapter every time the normalized screen
|
|
26325
|
+
* snapshot changes (spinner frame, streaming command output, etc.), so
|
|
26326
|
+
* `now - lastScreenChangeAt` is the real screen-diff quiet age. Reads the LIVE
|
|
26327
|
+
* transport snapshot so the deferred idleFinish timeout re-checks current screen
|
|
26328
|
+
* state, not the stale snapshot from when the timer was armed. A never-changed
|
|
26329
|
+
* screen (lastScreenChangeAt === 0) is treated as quiet.
|
|
26330
|
+
*/
|
|
26331
|
+
hasScreenBeenQuietForIdle(now) {
|
|
26332
|
+
const lastChange = this.transport.getSnapshot().lastScreenChangeAt;
|
|
26333
|
+
if (!lastChange) return true;
|
|
26334
|
+
return now - lastChange >= SCREEN_QUIET_IDLE_MS;
|
|
26335
|
+
}
|
|
26298
26336
|
/**
|
|
26299
26337
|
* FALSE-IDLE (Fix 2): should applyIdle suppress the idle/finish for the current
|
|
26300
26338
|
* turn because we are inside the post-approval resume grace?
|
|
@@ -27374,7 +27412,7 @@ ${lastSnapshot}`;
|
|
|
27374
27412
|
`[${this.cliType}] Waiting for interactive prompt: status=${status} stableMs=${stableMs} recentOutputMs=${recentlyOutput} screen=${JSON.stringify(summarizeCliTraceText(screenText, 220)).slice(0, 260)}`
|
|
27375
27413
|
);
|
|
27376
27414
|
}
|
|
27377
|
-
await new Promise((
|
|
27415
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
27378
27416
|
}
|
|
27379
27417
|
const finalScreenText = this.terminalScreen.getText() || "";
|
|
27380
27418
|
LOG.warn(
|
|
@@ -27741,7 +27779,7 @@ ${lastSnapshot}`;
|
|
|
27741
27779
|
if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
|
|
27742
27780
|
await this.ptyProcess.write(chunks[i]);
|
|
27743
27781
|
if (i + 1 < chunks.length) {
|
|
27744
|
-
await new Promise((
|
|
27782
|
+
await new Promise((resolve26) => setTimeout(resolve26, WIN32_PTY_WRITE_CHUNK_GAP_MS));
|
|
27745
27783
|
}
|
|
27746
27784
|
}
|
|
27747
27785
|
}
|
|
@@ -27909,7 +27947,7 @@ ${lastSnapshot}`;
|
|
|
27909
27947
|
this.onStatusChange?.();
|
|
27910
27948
|
}
|
|
27911
27949
|
async waitForForceSubmitSettle() {
|
|
27912
|
-
await new Promise((
|
|
27950
|
+
await new Promise((resolve26) => setTimeout(resolve26, FORCE_SUBMIT_SETTLE_MS));
|
|
27913
27951
|
}
|
|
27914
27952
|
enqueuePendingOutboundMessage(text, reason, meshTaskId) {
|
|
27915
27953
|
const content = String(text || "");
|
|
@@ -27988,7 +28026,7 @@ ${lastSnapshot}`;
|
|
|
27988
28026
|
const deadline = Date.now() + 1e4;
|
|
27989
28027
|
while (this.startupParseGate && Date.now() < deadline) {
|
|
27990
28028
|
this.resolveStartupState("send_wait");
|
|
27991
|
-
await new Promise((
|
|
28029
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
27992
28030
|
}
|
|
27993
28031
|
}
|
|
27994
28032
|
const parsedStatusBeforeSend = !allowInputDuringGeneration ? (() => {
|
|
@@ -28081,13 +28119,13 @@ ${lastSnapshot}`;
|
|
|
28081
28119
|
isFirstTurn: !this.firstTurnSent
|
|
28082
28120
|
};
|
|
28083
28121
|
this.engine.responseSettleIgnoreUntil = Date.now() + submitDelayMs + this.timeouts.outputSettle + 250;
|
|
28084
|
-
await new Promise((
|
|
28122
|
+
await new Promise((resolve26, reject) => {
|
|
28085
28123
|
let resolved = false;
|
|
28086
28124
|
const completion = {
|
|
28087
28125
|
resolveOnce: () => {
|
|
28088
28126
|
if (resolved) return;
|
|
28089
28127
|
resolved = true;
|
|
28090
|
-
|
|
28128
|
+
resolve26();
|
|
28091
28129
|
},
|
|
28092
28130
|
rejectOnce: (error) => {
|
|
28093
28131
|
if (resolved) return;
|
|
@@ -28275,17 +28313,17 @@ ${lastSnapshot}`;
|
|
|
28275
28313
|
}
|
|
28276
28314
|
}
|
|
28277
28315
|
waitForStopped(timeoutMs) {
|
|
28278
|
-
return new Promise((
|
|
28316
|
+
return new Promise((resolve26) => {
|
|
28279
28317
|
const startedAt = Date.now();
|
|
28280
28318
|
const timer = setInterval(() => {
|
|
28281
28319
|
if (!this.ptyProcess || this.engine.currentStatus === "stopped") {
|
|
28282
28320
|
clearInterval(timer);
|
|
28283
|
-
|
|
28321
|
+
resolve26(true);
|
|
28284
28322
|
return;
|
|
28285
28323
|
}
|
|
28286
28324
|
if (Date.now() - startedAt >= timeoutMs) {
|
|
28287
28325
|
clearInterval(timer);
|
|
28288
|
-
|
|
28326
|
+
resolve26(false);
|
|
28289
28327
|
}
|
|
28290
28328
|
}, 100);
|
|
28291
28329
|
});
|
|
@@ -30621,8 +30659,8 @@ async function detectIDEs(providerLoader) {
|
|
|
30621
30659
|
if (existsSync21(bundledCli)) resolvedCli = bundledCli;
|
|
30622
30660
|
}
|
|
30623
30661
|
if (!resolvedCli && appPath && os32 === "win32") {
|
|
30624
|
-
const { dirname:
|
|
30625
|
-
const appDir =
|
|
30662
|
+
const { dirname: dirname18 } = await import("path");
|
|
30663
|
+
const appDir = dirname18(appPath);
|
|
30626
30664
|
const candidates = [
|
|
30627
30665
|
`${appDir}\\\\bin\\\\${def.cli}.cmd`,
|
|
30628
30666
|
`${appDir}\\\\bin\\\\${def.cli}`,
|
|
@@ -30880,7 +30918,7 @@ var DaemonCdpManager = class {
|
|
|
30880
30918
|
* Returns multiple entries if multiple IDE windows are open on same port
|
|
30881
30919
|
*/
|
|
30882
30920
|
static listAllTargets(port) {
|
|
30883
|
-
return new Promise((
|
|
30921
|
+
return new Promise((resolve26) => {
|
|
30884
30922
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
30885
30923
|
let data = "";
|
|
30886
30924
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -30896,16 +30934,16 @@ var DaemonCdpManager = class {
|
|
|
30896
30934
|
(t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
|
|
30897
30935
|
);
|
|
30898
30936
|
const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
|
|
30899
|
-
|
|
30937
|
+
resolve26(mainPages.length > 0 ? mainPages : fallbackPages);
|
|
30900
30938
|
} catch {
|
|
30901
|
-
|
|
30939
|
+
resolve26([]);
|
|
30902
30940
|
}
|
|
30903
30941
|
});
|
|
30904
30942
|
});
|
|
30905
|
-
req.on("error", () =>
|
|
30943
|
+
req.on("error", () => resolve26([]));
|
|
30906
30944
|
req.setTimeout(2e3, () => {
|
|
30907
30945
|
req.destroy();
|
|
30908
|
-
|
|
30946
|
+
resolve26([]);
|
|
30909
30947
|
});
|
|
30910
30948
|
});
|
|
30911
30949
|
}
|
|
@@ -30945,7 +30983,7 @@ var DaemonCdpManager = class {
|
|
|
30945
30983
|
}
|
|
30946
30984
|
}
|
|
30947
30985
|
findTargetOnPort(port) {
|
|
30948
|
-
return new Promise((
|
|
30986
|
+
return new Promise((resolve26) => {
|
|
30949
30987
|
const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
|
|
30950
30988
|
let data = "";
|
|
30951
30989
|
res.on("data", (chunk) => data += chunk.toString());
|
|
@@ -30956,7 +30994,7 @@ var DaemonCdpManager = class {
|
|
|
30956
30994
|
(t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
|
|
30957
30995
|
);
|
|
30958
30996
|
if (pages.length === 0) {
|
|
30959
|
-
|
|
30997
|
+
resolve26(targets.find((t) => t.webSocketDebuggerUrl) || null);
|
|
30960
30998
|
return;
|
|
30961
30999
|
}
|
|
30962
31000
|
const titleFilteredPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
|
|
@@ -30975,25 +31013,25 @@ var DaemonCdpManager = class {
|
|
|
30975
31013
|
this._targetId = selected.target.id;
|
|
30976
31014
|
}
|
|
30977
31015
|
this._pageTitle = selected.target.title || "";
|
|
30978
|
-
|
|
31016
|
+
resolve26(selected.target);
|
|
30979
31017
|
return;
|
|
30980
31018
|
}
|
|
30981
31019
|
if (previousTargetId) {
|
|
30982
31020
|
this.log(`[CDP] Target ${previousTargetId} not found in page list`);
|
|
30983
|
-
|
|
31021
|
+
resolve26(null);
|
|
30984
31022
|
return;
|
|
30985
31023
|
}
|
|
30986
31024
|
this._pageTitle = list[0]?.title || "";
|
|
30987
|
-
|
|
31025
|
+
resolve26(list[0]);
|
|
30988
31026
|
} catch {
|
|
30989
|
-
|
|
31027
|
+
resolve26(null);
|
|
30990
31028
|
}
|
|
30991
31029
|
});
|
|
30992
31030
|
});
|
|
30993
|
-
req.on("error", () =>
|
|
31031
|
+
req.on("error", () => resolve26(null));
|
|
30994
31032
|
req.setTimeout(2e3, () => {
|
|
30995
31033
|
req.destroy();
|
|
30996
|
-
|
|
31034
|
+
resolve26(null);
|
|
30997
31035
|
});
|
|
30998
31036
|
});
|
|
30999
31037
|
}
|
|
@@ -31004,7 +31042,7 @@ var DaemonCdpManager = class {
|
|
|
31004
31042
|
this.extensionProviders = providers;
|
|
31005
31043
|
}
|
|
31006
31044
|
connectToTarget(wsUrl) {
|
|
31007
|
-
return new Promise((
|
|
31045
|
+
return new Promise((resolve26) => {
|
|
31008
31046
|
this.ws = new WebSocket(wsUrl);
|
|
31009
31047
|
this.ws.on("open", async () => {
|
|
31010
31048
|
this._connected = true;
|
|
@@ -31014,17 +31052,17 @@ var DaemonCdpManager = class {
|
|
|
31014
31052
|
}
|
|
31015
31053
|
this.connectBrowserWs().catch(() => {
|
|
31016
31054
|
});
|
|
31017
|
-
|
|
31055
|
+
resolve26(true);
|
|
31018
31056
|
});
|
|
31019
31057
|
this.ws.on("message", (data) => {
|
|
31020
31058
|
try {
|
|
31021
31059
|
const msg = JSON.parse(data.toString());
|
|
31022
31060
|
if (msg.id && this.pending.has(msg.id)) {
|
|
31023
|
-
const { resolve:
|
|
31061
|
+
const { resolve: resolve27, reject } = this.pending.get(msg.id);
|
|
31024
31062
|
this.pending.delete(msg.id);
|
|
31025
31063
|
this.failureCount = 0;
|
|
31026
31064
|
if (msg.error) reject(new Error(msg.error.message));
|
|
31027
|
-
else
|
|
31065
|
+
else resolve27(msg.result);
|
|
31028
31066
|
} else if (msg.method === "Runtime.executionContextCreated") {
|
|
31029
31067
|
this.contexts.add(msg.params.context.id);
|
|
31030
31068
|
} else if (msg.method === "Runtime.executionContextDestroyed") {
|
|
@@ -31047,7 +31085,7 @@ var DaemonCdpManager = class {
|
|
|
31047
31085
|
this.ws.on("error", (err) => {
|
|
31048
31086
|
this.log(`[CDP] WebSocket error: ${err.message}`);
|
|
31049
31087
|
this._connected = false;
|
|
31050
|
-
|
|
31088
|
+
resolve26(false);
|
|
31051
31089
|
});
|
|
31052
31090
|
});
|
|
31053
31091
|
}
|
|
@@ -31061,7 +31099,7 @@ var DaemonCdpManager = class {
|
|
|
31061
31099
|
return;
|
|
31062
31100
|
}
|
|
31063
31101
|
this.log(`[CDP] Connecting browser WS for target discovery...`);
|
|
31064
|
-
await new Promise((
|
|
31102
|
+
await new Promise((resolve26, reject) => {
|
|
31065
31103
|
this.browserWs = new WebSocket(browserWsUrl);
|
|
31066
31104
|
this.browserWs.on("open", async () => {
|
|
31067
31105
|
this._browserConnected = true;
|
|
@@ -31071,16 +31109,16 @@ var DaemonCdpManager = class {
|
|
|
31071
31109
|
} catch (e) {
|
|
31072
31110
|
this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
|
|
31073
31111
|
}
|
|
31074
|
-
|
|
31112
|
+
resolve26();
|
|
31075
31113
|
});
|
|
31076
31114
|
this.browserWs.on("message", (data) => {
|
|
31077
31115
|
try {
|
|
31078
31116
|
const msg = JSON.parse(data.toString());
|
|
31079
31117
|
if (msg.id && this.browserPending.has(msg.id)) {
|
|
31080
|
-
const { resolve:
|
|
31118
|
+
const { resolve: resolve27, reject: reject2 } = this.browserPending.get(msg.id);
|
|
31081
31119
|
this.browserPending.delete(msg.id);
|
|
31082
31120
|
if (msg.error) reject2(new Error(msg.error.message));
|
|
31083
|
-
else
|
|
31121
|
+
else resolve27(msg.result);
|
|
31084
31122
|
}
|
|
31085
31123
|
} catch {
|
|
31086
31124
|
}
|
|
@@ -31100,31 +31138,31 @@ var DaemonCdpManager = class {
|
|
|
31100
31138
|
}
|
|
31101
31139
|
}
|
|
31102
31140
|
getBrowserWsUrl() {
|
|
31103
|
-
return new Promise((
|
|
31141
|
+
return new Promise((resolve26) => {
|
|
31104
31142
|
const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
|
|
31105
31143
|
let data = "";
|
|
31106
31144
|
res.on("data", (chunk) => data += chunk.toString());
|
|
31107
31145
|
res.on("end", () => {
|
|
31108
31146
|
try {
|
|
31109
31147
|
const info = JSON.parse(data);
|
|
31110
|
-
|
|
31148
|
+
resolve26(info.webSocketDebuggerUrl || null);
|
|
31111
31149
|
} catch {
|
|
31112
|
-
|
|
31150
|
+
resolve26(null);
|
|
31113
31151
|
}
|
|
31114
31152
|
});
|
|
31115
31153
|
});
|
|
31116
|
-
req.on("error", () =>
|
|
31154
|
+
req.on("error", () => resolve26(null));
|
|
31117
31155
|
req.setTimeout(3e3, () => {
|
|
31118
31156
|
req.destroy();
|
|
31119
|
-
|
|
31157
|
+
resolve26(null);
|
|
31120
31158
|
});
|
|
31121
31159
|
});
|
|
31122
31160
|
}
|
|
31123
31161
|
sendBrowser(method, params = {}, timeoutMs = 15e3) {
|
|
31124
|
-
return new Promise((
|
|
31162
|
+
return new Promise((resolve26, reject) => {
|
|
31125
31163
|
if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
|
|
31126
31164
|
const id = this.browserMsgId++;
|
|
31127
|
-
this.browserPending.set(id, { resolve:
|
|
31165
|
+
this.browserPending.set(id, { resolve: resolve26, reject });
|
|
31128
31166
|
this.browserWs.send(JSON.stringify({ id, method, params }));
|
|
31129
31167
|
setTimeout(() => {
|
|
31130
31168
|
if (this.browserPending.has(id)) {
|
|
@@ -31164,11 +31202,11 @@ var DaemonCdpManager = class {
|
|
|
31164
31202
|
}
|
|
31165
31203
|
// ─── CDP Protocol ────────────────────────────────────────
|
|
31166
31204
|
sendInternal(method, params = {}, timeoutMs = 15e3) {
|
|
31167
|
-
return new Promise((
|
|
31205
|
+
return new Promise((resolve26, reject) => {
|
|
31168
31206
|
if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
|
|
31169
31207
|
if (this.ws.readyState !== WebSocket.OPEN) return reject(new Error("WebSocket not open"));
|
|
31170
31208
|
const id = this.msgId++;
|
|
31171
|
-
this.pending.set(id, { resolve:
|
|
31209
|
+
this.pending.set(id, { resolve: resolve26, reject });
|
|
31172
31210
|
this.ws.send(JSON.stringify({ id, method, params }));
|
|
31173
31211
|
setTimeout(() => {
|
|
31174
31212
|
if (this.pending.has(id)) {
|
|
@@ -31417,7 +31455,7 @@ var DaemonCdpManager = class {
|
|
|
31417
31455
|
const browserWs = this.browserWs;
|
|
31418
31456
|
let msgId = this.browserMsgId;
|
|
31419
31457
|
const sendWs = (method, params = {}, sessionId) => {
|
|
31420
|
-
return new Promise((
|
|
31458
|
+
return new Promise((resolve26, reject) => {
|
|
31421
31459
|
const mid = msgId++;
|
|
31422
31460
|
this.browserMsgId = msgId;
|
|
31423
31461
|
const handler = (raw) => {
|
|
@@ -31426,7 +31464,7 @@ var DaemonCdpManager = class {
|
|
|
31426
31464
|
if (msg.id === mid) {
|
|
31427
31465
|
browserWs.removeListener("message", handler);
|
|
31428
31466
|
if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
|
|
31429
|
-
else
|
|
31467
|
+
else resolve26(msg.result);
|
|
31430
31468
|
}
|
|
31431
31469
|
} catch {
|
|
31432
31470
|
}
|
|
@@ -31627,14 +31665,14 @@ var DaemonCdpManager = class {
|
|
|
31627
31665
|
if (!ws || ws.readyState !== WebSocket.OPEN) {
|
|
31628
31666
|
throw new Error("CDP not connected");
|
|
31629
31667
|
}
|
|
31630
|
-
return new Promise((
|
|
31668
|
+
return new Promise((resolve26, reject) => {
|
|
31631
31669
|
const id = getNextId();
|
|
31632
31670
|
pendingMap.set(id, {
|
|
31633
31671
|
resolve: (result) => {
|
|
31634
31672
|
if (result?.result?.subtype === "error") {
|
|
31635
31673
|
reject(new Error(result.result.description));
|
|
31636
31674
|
} else {
|
|
31637
|
-
|
|
31675
|
+
resolve26(result?.result?.value);
|
|
31638
31676
|
}
|
|
31639
31677
|
},
|
|
31640
31678
|
reject
|
|
@@ -31666,10 +31704,10 @@ var DaemonCdpManager = class {
|
|
|
31666
31704
|
throw new Error("CDP not connected");
|
|
31667
31705
|
}
|
|
31668
31706
|
const sendViaSession = (method, params = {}) => {
|
|
31669
|
-
return new Promise((
|
|
31707
|
+
return new Promise((resolve26, reject) => {
|
|
31670
31708
|
const pendingMap = this._browserConnected ? this.browserPending : this.pending;
|
|
31671
31709
|
const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
|
|
31672
|
-
pendingMap.set(id, { resolve:
|
|
31710
|
+
pendingMap.set(id, { resolve: resolve26, reject });
|
|
31673
31711
|
ws.send(JSON.stringify({ id, sessionId, method, params }));
|
|
31674
31712
|
setTimeout(() => {
|
|
31675
31713
|
if (pendingMap.has(id)) {
|
|
@@ -35584,13 +35622,14 @@ function resolveTargetSessionActualWorkspace(h, targetSessionId) {
|
|
|
35584
35622
|
// src/commands/chat-commands-debug-bundle.ts
|
|
35585
35623
|
init_logger();
|
|
35586
35624
|
init_debug_trace();
|
|
35587
|
-
import * as
|
|
35625
|
+
import * as fs9 from "fs";
|
|
35588
35626
|
import * as os10 from "os";
|
|
35589
35627
|
import * as path17 from "path";
|
|
35590
35628
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
35591
35629
|
|
|
35592
35630
|
// src/commands/chat-commands-read.ts
|
|
35593
35631
|
init_contracts2();
|
|
35632
|
+
import * as fs8 from "fs";
|
|
35594
35633
|
import * as path16 from "path";
|
|
35595
35634
|
init_state_store();
|
|
35596
35635
|
init_coordinator_registry();
|
|
@@ -36543,7 +36582,16 @@ function readExactRuntimeMirrorMessages(args) {
|
|
|
36543
36582
|
function normalizeComparableWorkspace(value) {
|
|
36544
36583
|
const text = typeof value === "string" ? value.trim() : "";
|
|
36545
36584
|
if (!text) return "";
|
|
36546
|
-
|
|
36585
|
+
const lexical = path16.resolve(text);
|
|
36586
|
+
try {
|
|
36587
|
+
return fs8.realpathSync.native(lexical);
|
|
36588
|
+
} catch {
|
|
36589
|
+
try {
|
|
36590
|
+
return fs8.realpathSync(lexical);
|
|
36591
|
+
} catch {
|
|
36592
|
+
return lexical;
|
|
36593
|
+
}
|
|
36594
|
+
}
|
|
36547
36595
|
}
|
|
36548
36596
|
function isCurrentRuntimePtySafelyAttributed(args) {
|
|
36549
36597
|
if (args.adapter.cliType !== "codex-cli") return false;
|
|
@@ -37861,11 +37909,11 @@ function buildChatDebugBundleSummary(bundle) {
|
|
|
37861
37909
|
function storeChatDebugBundleOnDaemon(bundle, targetSessionId) {
|
|
37862
37910
|
const bundleId = createChatDebugBundleId(targetSessionId);
|
|
37863
37911
|
const dir = getChatDebugBundleDir();
|
|
37864
|
-
|
|
37912
|
+
fs9.mkdirSync(dir, { recursive: true });
|
|
37865
37913
|
const savedPath = path17.join(dir, `${bundleId}.json`);
|
|
37866
37914
|
const json = `${JSON.stringify(bundle, null, 2)}
|
|
37867
37915
|
`;
|
|
37868
|
-
|
|
37916
|
+
fs9.writeFileSync(savedPath, json, { encoding: "utf8", mode: 384 });
|
|
37869
37917
|
return { bundleId, savedPath, sizeBytes: Buffer.byteLength(json, "utf8") };
|
|
37870
37918
|
}
|
|
37871
37919
|
function isDaemonFileDebugDelivery(args) {
|
|
@@ -38026,7 +38074,7 @@ function getSendChatInputEnvelope(args) {
|
|
|
38026
38074
|
return normalizeInputEnvelope(args?.input ? { input: args.input } : args);
|
|
38027
38075
|
}
|
|
38028
38076
|
function sleep(ms) {
|
|
38029
|
-
return new Promise((
|
|
38077
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
38030
38078
|
}
|
|
38031
38079
|
async function waitOnceForFreshHermesCliStart(adapter, log) {
|
|
38032
38080
|
if (adapter.cliType !== "hermes-cli") return;
|
|
@@ -38081,7 +38129,7 @@ function getStateLastSignature(state) {
|
|
|
38081
38129
|
async function getStableExtensionBaseline(h) {
|
|
38082
38130
|
const first = await readExtensionChatState(h);
|
|
38083
38131
|
if (getStateMessageCount(first) > 0 || getStateLastSignature(first)) return first;
|
|
38084
|
-
await new Promise((
|
|
38132
|
+
await new Promise((resolve26) => setTimeout(resolve26, 150));
|
|
38085
38133
|
const second = await readExtensionChatState(h);
|
|
38086
38134
|
return getStateMessageCount(second) >= getStateMessageCount(first) ? second : first;
|
|
38087
38135
|
}
|
|
@@ -38089,7 +38137,7 @@ async function verifyExtensionSendObserved(h, before) {
|
|
|
38089
38137
|
const beforeCount = getStateMessageCount(before);
|
|
38090
38138
|
const beforeSignature = getStateLastSignature(before);
|
|
38091
38139
|
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
38092
|
-
await new Promise((
|
|
38140
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
38093
38141
|
const state = await readExtensionChatState(h);
|
|
38094
38142
|
if (state?.status === "waiting_approval") return true;
|
|
38095
38143
|
const afterCount = getStateMessageCount(state);
|
|
@@ -38806,7 +38854,7 @@ async function handleResolveAction(h, args) {
|
|
|
38806
38854
|
}
|
|
38807
38855
|
|
|
38808
38856
|
// src/commands/cdp-commands.ts
|
|
38809
|
-
import * as
|
|
38857
|
+
import * as fs10 from "fs";
|
|
38810
38858
|
import * as path18 from "path";
|
|
38811
38859
|
import * as os11 from "os";
|
|
38812
38860
|
var KEY_TO_VK = {
|
|
@@ -39079,7 +39127,7 @@ function resolveSafePath(requestedPath) {
|
|
|
39079
39127
|
return path18.resolve(inputPath);
|
|
39080
39128
|
}
|
|
39081
39129
|
function listDirectoryEntriesSafe(dirPath) {
|
|
39082
|
-
const entries =
|
|
39130
|
+
const entries = fs10.readdirSync(dirPath, { withFileTypes: true });
|
|
39083
39131
|
const files = [];
|
|
39084
39132
|
for (const entry of entries) {
|
|
39085
39133
|
const entryPath = path18.join(dirPath, entry.name);
|
|
@@ -39091,14 +39139,14 @@ function listDirectoryEntriesSafe(dirPath) {
|
|
|
39091
39139
|
if (entry.isFile()) {
|
|
39092
39140
|
let size;
|
|
39093
39141
|
try {
|
|
39094
|
-
size =
|
|
39142
|
+
size = fs10.statSync(entryPath).size;
|
|
39095
39143
|
} catch {
|
|
39096
39144
|
size = void 0;
|
|
39097
39145
|
}
|
|
39098
39146
|
files.push({ name: entry.name, type: "file", size });
|
|
39099
39147
|
continue;
|
|
39100
39148
|
}
|
|
39101
|
-
const stat2 =
|
|
39149
|
+
const stat2 = fs10.statSync(entryPath);
|
|
39102
39150
|
files.push({
|
|
39103
39151
|
name: entry.name,
|
|
39104
39152
|
type: stat2.isDirectory() ? "directory" : "file",
|
|
@@ -39116,7 +39164,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
39116
39164
|
const letter = String.fromCharCode(code);
|
|
39117
39165
|
const root = `${letter}:\\`;
|
|
39118
39166
|
try {
|
|
39119
|
-
if (!
|
|
39167
|
+
if (!fs10.existsSync(root)) continue;
|
|
39120
39168
|
if (excluded && root.toLowerCase() === excluded) continue;
|
|
39121
39169
|
drives.push({ name: `${letter}:`, type: "directory", path: root });
|
|
39122
39170
|
} catch {
|
|
@@ -39127,7 +39175,7 @@ function listWindowsDriveEntries(excludePath) {
|
|
|
39127
39175
|
async function handleFileRead(h, args) {
|
|
39128
39176
|
try {
|
|
39129
39177
|
const filePath = resolveSafePath(args?.path);
|
|
39130
|
-
const content =
|
|
39178
|
+
const content = fs10.readFileSync(filePath, "utf-8");
|
|
39131
39179
|
return { success: true, content, path: filePath };
|
|
39132
39180
|
} catch (e) {
|
|
39133
39181
|
return { success: false, error: e.message };
|
|
@@ -39136,8 +39184,8 @@ async function handleFileRead(h, args) {
|
|
|
39136
39184
|
async function handleFileWrite(h, args) {
|
|
39137
39185
|
try {
|
|
39138
39186
|
const filePath = resolveSafePath(args?.path);
|
|
39139
|
-
|
|
39140
|
-
|
|
39187
|
+
fs10.mkdirSync(path18.dirname(filePath), { recursive: true });
|
|
39188
|
+
fs10.writeFileSync(filePath, args?.content || "", "utf-8");
|
|
39141
39189
|
return { success: true, path: filePath };
|
|
39142
39190
|
} catch (e) {
|
|
39143
39191
|
return { success: false, error: e.message };
|
|
@@ -39491,7 +39539,7 @@ async function executeProviderScript(h, args, scriptName) {
|
|
|
39491
39539
|
const enterCount = cliCommand.enterCount || 1;
|
|
39492
39540
|
await adapter.writeRaw(cliCommand.text + "\r");
|
|
39493
39541
|
for (let i = 1; i < enterCount; i += 1) {
|
|
39494
|
-
await new Promise((
|
|
39542
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
39495
39543
|
await adapter.writeRaw("\r");
|
|
39496
39544
|
}
|
|
39497
39545
|
}
|
|
@@ -40295,11 +40343,11 @@ var DaemonCommandHandler = class {
|
|
|
40295
40343
|
return { success: false, error: "invalid type" };
|
|
40296
40344
|
}
|
|
40297
40345
|
const https = __require("https");
|
|
40298
|
-
const
|
|
40346
|
+
const fs43 = __require("fs");
|
|
40299
40347
|
const path45 = __require("path");
|
|
40300
40348
|
const REGISTRY = resolveRegistryBaseUrl(loadConfig().registryUrl);
|
|
40301
40349
|
function fetchText(url, timeoutMs) {
|
|
40302
|
-
return new Promise((
|
|
40350
|
+
return new Promise((resolve26, reject) => {
|
|
40303
40351
|
const req = https.get(url, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: timeoutMs }, (res) => {
|
|
40304
40352
|
if (res.statusCode !== 200) {
|
|
40305
40353
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
@@ -40307,7 +40355,7 @@ var DaemonCommandHandler = class {
|
|
|
40307
40355
|
}
|
|
40308
40356
|
const chunks = [];
|
|
40309
40357
|
res.on("data", (c) => chunks.push(c));
|
|
40310
|
-
res.on("end", () =>
|
|
40358
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
40311
40359
|
});
|
|
40312
40360
|
req.on("error", reject);
|
|
40313
40361
|
req.on("timeout", () => {
|
|
@@ -40338,7 +40386,7 @@ var DaemonCommandHandler = class {
|
|
|
40338
40386
|
if (!targetDir.startsWith(installRootResolved + path45.sep)) {
|
|
40339
40387
|
return { success: false, error: "install path escaped upstream root" };
|
|
40340
40388
|
}
|
|
40341
|
-
|
|
40389
|
+
fs43.mkdirSync(targetDir, { recursive: true });
|
|
40342
40390
|
let manifestProbe = {};
|
|
40343
40391
|
try {
|
|
40344
40392
|
manifestProbe = JSON.parse(manifestBody);
|
|
@@ -40363,7 +40411,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40363
40411
|
}
|
|
40364
40412
|
const targetFile = isV1 ? "provider.v1.json" : "provider.json";
|
|
40365
40413
|
const targetPath = path45.join(targetDir, targetFile);
|
|
40366
|
-
|
|
40414
|
+
fs43.writeFileSync(targetPath, manifestBody, "utf-8");
|
|
40367
40415
|
const manifestJson = JSON.parse(manifestBody);
|
|
40368
40416
|
const scriptFetch = await this.fetchProviderSources(
|
|
40369
40417
|
manifestJson,
|
|
@@ -40433,10 +40481,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40433
40481
|
const repo = source.repo;
|
|
40434
40482
|
const ref = source.ref;
|
|
40435
40483
|
const https = __require("https");
|
|
40436
|
-
const
|
|
40484
|
+
const fs43 = __require("fs");
|
|
40437
40485
|
const path45 = __require("path");
|
|
40438
40486
|
function fetchJson(url, timeoutMs) {
|
|
40439
|
-
return new Promise((
|
|
40487
|
+
return new Promise((resolve26, reject) => {
|
|
40440
40488
|
const req = https.get(url, {
|
|
40441
40489
|
headers: { "User-Agent": "adhdev-daemon", "Accept": "application/vnd.github+json" },
|
|
40442
40490
|
timeout: timeoutMs
|
|
@@ -40449,7 +40497,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40449
40497
|
res.on("data", (c) => chunks.push(c));
|
|
40450
40498
|
res.on("end", () => {
|
|
40451
40499
|
try {
|
|
40452
|
-
|
|
40500
|
+
resolve26(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
40453
40501
|
} catch (e) {
|
|
40454
40502
|
reject(e);
|
|
40455
40503
|
}
|
|
@@ -40463,14 +40511,14 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40463
40511
|
});
|
|
40464
40512
|
}
|
|
40465
40513
|
function fetchBinary(url, timeoutMs) {
|
|
40466
|
-
return new Promise((
|
|
40514
|
+
return new Promise((resolve26, reject) => {
|
|
40467
40515
|
const req = https.get(url, {
|
|
40468
40516
|
headers: { "User-Agent": "adhdev-daemon" },
|
|
40469
40517
|
timeout: timeoutMs
|
|
40470
40518
|
}, (res) => {
|
|
40471
40519
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
40472
40520
|
if (res.headers.location) {
|
|
40473
|
-
return fetchBinary(res.headers.location, timeoutMs).then(
|
|
40521
|
+
return fetchBinary(res.headers.location, timeoutMs).then(resolve26, reject);
|
|
40474
40522
|
}
|
|
40475
40523
|
}
|
|
40476
40524
|
if (res.statusCode !== 200) {
|
|
@@ -40479,7 +40527,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40479
40527
|
}
|
|
40480
40528
|
const chunks = [];
|
|
40481
40529
|
res.on("data", (c) => chunks.push(c));
|
|
40482
|
-
res.on("end", () =>
|
|
40530
|
+
res.on("end", () => resolve26(Buffer.concat(chunks)));
|
|
40483
40531
|
});
|
|
40484
40532
|
req.on("error", reject);
|
|
40485
40533
|
req.on("timeout", () => {
|
|
@@ -40517,8 +40565,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40517
40565
|
const relInside = entry.path.startsWith(sharedDirRel + "/") ? entry.path.slice(sharedDirRel.length + 1) : entry.path;
|
|
40518
40566
|
const outPath = path45.resolve(path45.join(sharedTargetDir, relInside));
|
|
40519
40567
|
if (!outPath.startsWith(path45.resolve(sharedTargetDir) + path45.sep)) continue;
|
|
40520
|
-
|
|
40521
|
-
|
|
40568
|
+
fs43.mkdirSync(path45.dirname(outPath), { recursive: true });
|
|
40569
|
+
fs43.writeFileSync(outPath, body);
|
|
40522
40570
|
fetchedCount++;
|
|
40523
40571
|
} catch (e) {
|
|
40524
40572
|
errors.push(`fetch shared ${entry.path}: ${e?.message ?? e}`);
|
|
@@ -40556,8 +40604,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40556
40604
|
errors.push(`refusing to write outside targetDir: ${entry.path}`);
|
|
40557
40605
|
continue;
|
|
40558
40606
|
}
|
|
40559
|
-
|
|
40560
|
-
|
|
40607
|
+
fs43.mkdirSync(path45.dirname(outPath), { recursive: true });
|
|
40608
|
+
fs43.writeFileSync(outPath, body);
|
|
40561
40609
|
fetchedCount++;
|
|
40562
40610
|
} catch (e) {
|
|
40563
40611
|
errors.push(`fetch ${entry.path}: ${e?.message ?? e}`);
|
|
@@ -40585,7 +40633,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40585
40633
|
if (!["cli", "ide", "extension", "acp"].includes(category)) {
|
|
40586
40634
|
return { success: false, error: `unknown category: ${category}` };
|
|
40587
40635
|
}
|
|
40588
|
-
const
|
|
40636
|
+
const fs43 = __require("fs");
|
|
40589
40637
|
const path45 = __require("path");
|
|
40590
40638
|
try {
|
|
40591
40639
|
const installRoot = this.getUpstreamInstallRoot();
|
|
@@ -40594,10 +40642,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40594
40642
|
if (!targetDir.startsWith(installRootResolved + path45.sep)) {
|
|
40595
40643
|
return { success: false, error: "refusing to delete outside upstream root" };
|
|
40596
40644
|
}
|
|
40597
|
-
if (!
|
|
40645
|
+
if (!fs43.existsSync(targetDir)) {
|
|
40598
40646
|
return { success: false, error: "not installed" };
|
|
40599
40647
|
}
|
|
40600
|
-
|
|
40648
|
+
fs43.rmSync(targetDir, { recursive: true, force: true });
|
|
40601
40649
|
if (this._ctx.providerLoader) {
|
|
40602
40650
|
this._ctx.providerLoader.reload();
|
|
40603
40651
|
this._ctx.providerLoader.registerToDetector();
|
|
@@ -40613,28 +40661,28 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40613
40661
|
* the UI and by the update checker.
|
|
40614
40662
|
*/
|
|
40615
40663
|
handleListInstalledProviders(_args) {
|
|
40616
|
-
const
|
|
40664
|
+
const fs43 = __require("fs");
|
|
40617
40665
|
const path45 = __require("path");
|
|
40618
40666
|
const installRoot = this.getUpstreamInstallRoot();
|
|
40619
|
-
if (!
|
|
40667
|
+
if (!fs43.existsSync(installRoot)) return { success: true, providers: [] };
|
|
40620
40668
|
const CATEGORIES = ["cli", "ide", "extension", "acp"];
|
|
40621
40669
|
const items = [];
|
|
40622
40670
|
for (const category of CATEGORIES) {
|
|
40623
40671
|
const categoryDir = path45.join(installRoot, category);
|
|
40624
|
-
if (!
|
|
40672
|
+
if (!fs43.existsSync(categoryDir)) continue;
|
|
40625
40673
|
let entries;
|
|
40626
40674
|
try {
|
|
40627
|
-
entries =
|
|
40675
|
+
entries = fs43.readdirSync(categoryDir);
|
|
40628
40676
|
} catch {
|
|
40629
40677
|
continue;
|
|
40630
40678
|
}
|
|
40631
40679
|
for (const type of entries) {
|
|
40632
40680
|
const v1Path = path45.join(categoryDir, type, "provider.v1.json");
|
|
40633
40681
|
const v0Path = path45.join(categoryDir, type, "provider.json");
|
|
40634
|
-
const manifestPath =
|
|
40682
|
+
const manifestPath = fs43.existsSync(v1Path) ? v1Path : fs43.existsSync(v0Path) ? v0Path : null;
|
|
40635
40683
|
if (!manifestPath) continue;
|
|
40636
40684
|
try {
|
|
40637
|
-
const m = JSON.parse(
|
|
40685
|
+
const m = JSON.parse(fs43.readFileSync(manifestPath, "utf-8"));
|
|
40638
40686
|
const modelOptions = Array.isArray(m.modelOptions) ? m.modelOptions.filter((x) => typeof x === "string" && !!x.trim()) : [];
|
|
40639
40687
|
const thinkingLevelOptions = Array.isArray(m.thinkingLevelOptions) ? m.thinkingLevelOptions.filter((x) => typeof x === "string" && !!x.trim()) : [];
|
|
40640
40688
|
items.push({
|
|
@@ -40665,7 +40713,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40665
40713
|
const https = __require("https");
|
|
40666
40714
|
const REGISTRY = resolveRegistryBaseUrl(loadConfig().registryUrl);
|
|
40667
40715
|
function fetchJson(url) {
|
|
40668
|
-
return new Promise((
|
|
40716
|
+
return new Promise((resolve26, reject) => {
|
|
40669
40717
|
const req = https.get(url, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 1e4 }, (res) => {
|
|
40670
40718
|
if (res.statusCode !== 200) {
|
|
40671
40719
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
@@ -40675,7 +40723,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40675
40723
|
res.on("data", (c) => chunks.push(c));
|
|
40676
40724
|
res.on("end", () => {
|
|
40677
40725
|
try {
|
|
40678
|
-
|
|
40726
|
+
resolve26(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
40679
40727
|
} catch (e) {
|
|
40680
40728
|
reject(e);
|
|
40681
40729
|
}
|
|
@@ -40749,7 +40797,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40749
40797
|
if (!/^@[a-z0-9_-]+$/i.test(requestedName)) {
|
|
40750
40798
|
return { success: false, error: "name must match @[a-z0-9_-]+" };
|
|
40751
40799
|
}
|
|
40752
|
-
const
|
|
40800
|
+
const fs43 = __require("fs");
|
|
40753
40801
|
const path45 = __require("path");
|
|
40754
40802
|
const { spawnSync: spawnSync2 } = __require("child_process");
|
|
40755
40803
|
const file = ext.loadExternalSources();
|
|
@@ -40760,8 +40808,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40760
40808
|
return { success: false, error: `source url+ref already registered (use a different name to track another ref)` };
|
|
40761
40809
|
}
|
|
40762
40810
|
const sourceDir = path45.join(ext.externalRoot(), requestedName);
|
|
40763
|
-
if (!
|
|
40764
|
-
if (
|
|
40811
|
+
if (!fs43.existsSync(ext.externalRoot())) fs43.mkdirSync(ext.externalRoot(), { recursive: true });
|
|
40812
|
+
if (fs43.existsSync(sourceDir)) {
|
|
40765
40813
|
return { success: false, error: `directory already exists: ${sourceDir} (rename or remove first)` };
|
|
40766
40814
|
}
|
|
40767
40815
|
const clone = spawnSync2("git", ["clone", "--depth=1", "--branch", ref, "--", url, sourceDir], {
|
|
@@ -40771,7 +40819,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40771
40819
|
});
|
|
40772
40820
|
if (clone.status !== 0) {
|
|
40773
40821
|
try {
|
|
40774
|
-
|
|
40822
|
+
fs43.rmSync(sourceDir, { recursive: true, force: true });
|
|
40775
40823
|
} catch {
|
|
40776
40824
|
}
|
|
40777
40825
|
return { success: false, error: `git clone failed: ${(clone.stderr || clone.stdout || "").trim() || "unknown error"}` };
|
|
@@ -40815,15 +40863,15 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40815
40863
|
const name = typeof args?.name === "string" ? args.name.trim() : "";
|
|
40816
40864
|
if (!name) return { success: false, error: "name is required" };
|
|
40817
40865
|
const ext = (init_external_sources(), __toCommonJS(external_sources_exports));
|
|
40818
|
-
const
|
|
40866
|
+
const fs43 = __require("fs");
|
|
40819
40867
|
const path45 = __require("path");
|
|
40820
40868
|
const file = ext.loadExternalSources();
|
|
40821
40869
|
const match = file.sources.find((s2) => s2.name === name);
|
|
40822
40870
|
if (!match) return { success: false, error: `source "${name}" not registered` };
|
|
40823
40871
|
const sourceDir = path45.join(ext.externalRoot(), name);
|
|
40824
|
-
if (
|
|
40872
|
+
if (fs43.existsSync(sourceDir)) {
|
|
40825
40873
|
try {
|
|
40826
|
-
|
|
40874
|
+
fs43.rmSync(sourceDir, { recursive: true, force: true });
|
|
40827
40875
|
} catch (e) {
|
|
40828
40876
|
return { success: false, error: `failed to delete ${sourceDir}: ${e?.message || e}` };
|
|
40829
40877
|
}
|
|
@@ -40913,7 +40961,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40913
40961
|
try {
|
|
40914
40962
|
const http3 = await import("http");
|
|
40915
40963
|
const postData = JSON.stringify(body);
|
|
40916
|
-
const result = await new Promise((
|
|
40964
|
+
const result = await new Promise((resolve26, reject) => {
|
|
40917
40965
|
const req = http3.request({
|
|
40918
40966
|
hostname: "127.0.0.1",
|
|
40919
40967
|
port: 19280,
|
|
@@ -40925,9 +40973,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40925
40973
|
res.on("data", (chunk) => data += chunk);
|
|
40926
40974
|
res.on("end", () => {
|
|
40927
40975
|
try {
|
|
40928
|
-
|
|
40976
|
+
resolve26(JSON.parse(data));
|
|
40929
40977
|
} catch {
|
|
40930
|
-
|
|
40978
|
+
resolve26({ raw: data });
|
|
40931
40979
|
}
|
|
40932
40980
|
});
|
|
40933
40981
|
});
|
|
@@ -40945,15 +40993,15 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40945
40993
|
if (!providerType) return { success: false, error: "providerType required" };
|
|
40946
40994
|
try {
|
|
40947
40995
|
const http3 = await import("http");
|
|
40948
|
-
const result = await new Promise((
|
|
40996
|
+
const result = await new Promise((resolve26, reject) => {
|
|
40949
40997
|
http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
|
|
40950
40998
|
let data = "";
|
|
40951
40999
|
res.on("data", (chunk) => data += chunk);
|
|
40952
41000
|
res.on("end", () => {
|
|
40953
41001
|
try {
|
|
40954
|
-
|
|
41002
|
+
resolve26(JSON.parse(data));
|
|
40955
41003
|
} catch {
|
|
40956
|
-
|
|
41004
|
+
resolve26({ raw: data });
|
|
40957
41005
|
}
|
|
40958
41006
|
});
|
|
40959
41007
|
}).on("error", reject);
|
|
@@ -40967,7 +41015,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40967
41015
|
try {
|
|
40968
41016
|
const http3 = await import("http");
|
|
40969
41017
|
const postData = JSON.stringify(args || {});
|
|
40970
|
-
const result = await new Promise((
|
|
41018
|
+
const result = await new Promise((resolve26, reject) => {
|
|
40971
41019
|
const req = http3.request({
|
|
40972
41020
|
hostname: "127.0.0.1",
|
|
40973
41021
|
port: 19280,
|
|
@@ -40979,9 +41027,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
40979
41027
|
res.on("data", (chunk) => data += chunk);
|
|
40980
41028
|
res.on("end", () => {
|
|
40981
41029
|
try {
|
|
40982
|
-
|
|
41030
|
+
resolve26(JSON.parse(data));
|
|
40983
41031
|
} catch {
|
|
40984
|
-
|
|
41032
|
+
resolve26({ raw: data });
|
|
40985
41033
|
}
|
|
40986
41034
|
});
|
|
40987
41035
|
});
|
|
@@ -41497,7 +41545,7 @@ var refineConfigHandlers = {
|
|
|
41497
41545
|
// src/commands/low-family/diagnostics.ts
|
|
41498
41546
|
init_logger();
|
|
41499
41547
|
init_debug_trace();
|
|
41500
|
-
import * as
|
|
41548
|
+
import * as fs13 from "fs";
|
|
41501
41549
|
var diagnosticsHandlers = {
|
|
41502
41550
|
get_logs: async (_ctx, args) => {
|
|
41503
41551
|
const count = parseInt(args?.count) || parseInt(args?.lines) || 100;
|
|
@@ -41514,8 +41562,8 @@ var diagnosticsHandlers = {
|
|
|
41514
41562
|
if (sinceTs > 0) {
|
|
41515
41563
|
return { success: true, logs: [], totalBuffered: 0 };
|
|
41516
41564
|
}
|
|
41517
|
-
if (
|
|
41518
|
-
const content =
|
|
41565
|
+
if (fs13.existsSync(LOG_PATH)) {
|
|
41566
|
+
const content = fs13.readFileSync(LOG_PATH, "utf-8");
|
|
41519
41567
|
const allLines = content.split("\n");
|
|
41520
41568
|
const recent = allLines.slice(-count).join("\n");
|
|
41521
41569
|
return { success: true, logs: recent, totalLines: allLines.length };
|
|
@@ -41662,14 +41710,14 @@ var coordinatorPromptHandlers = {
|
|
|
41662
41710
|
}
|
|
41663
41711
|
},
|
|
41664
41712
|
list_coordinator_prompts: async (_ctx, _args) => {
|
|
41665
|
-
const
|
|
41713
|
+
const fs43 = await import("fs");
|
|
41666
41714
|
const path45 = await import("path");
|
|
41667
41715
|
const os32 = await import("os");
|
|
41668
41716
|
const dir = path45.join(os32.homedir(), ".adhdev", "coordinator-prompts");
|
|
41669
41717
|
const entries = {};
|
|
41670
41718
|
try {
|
|
41671
|
-
if (
|
|
41672
|
-
for (const name of
|
|
41719
|
+
if (fs43.existsSync(dir)) {
|
|
41720
|
+
for (const name of fs43.readdirSync(dir)) {
|
|
41673
41721
|
const matchOverride = name.match(/^([a-zA-Z0-9_.-]+)\.md$/);
|
|
41674
41722
|
const matchAppend = name.match(/^([a-zA-Z0-9_.-]+)\.append\.md$/);
|
|
41675
41723
|
const m = matchAppend || matchOverride;
|
|
@@ -41679,7 +41727,7 @@ var coordinatorPromptHandlers = {
|
|
|
41679
41727
|
const full = path45.join(dir, name);
|
|
41680
41728
|
let content = "";
|
|
41681
41729
|
try {
|
|
41682
|
-
content =
|
|
41730
|
+
content = fs43.readFileSync(full, "utf8");
|
|
41683
41731
|
} catch {
|
|
41684
41732
|
}
|
|
41685
41733
|
if (!entries[key2]) entries[key2] = { override: "", append: "" };
|
|
@@ -41693,7 +41741,7 @@ var coordinatorPromptHandlers = {
|
|
|
41693
41741
|
return { success: true, dir, entries };
|
|
41694
41742
|
},
|
|
41695
41743
|
write_coordinator_prompt: async (_ctx, args) => {
|
|
41696
|
-
const
|
|
41744
|
+
const fs43 = await import("fs");
|
|
41697
41745
|
const path45 = await import("path");
|
|
41698
41746
|
const os32 = await import("os");
|
|
41699
41747
|
const key2 = typeof args?.key === "string" ? args.key.trim() : "";
|
|
@@ -41706,11 +41754,11 @@ var coordinatorPromptHandlers = {
|
|
|
41706
41754
|
const filename = kind === "append" ? `${key2}.append.md` : `${key2}.md`;
|
|
41707
41755
|
const full = path45.join(dir, filename);
|
|
41708
41756
|
try {
|
|
41709
|
-
|
|
41757
|
+
fs43.mkdirSync(dir, { recursive: true });
|
|
41710
41758
|
if (content.trim()) {
|
|
41711
|
-
|
|
41712
|
-
} else if (
|
|
41713
|
-
|
|
41759
|
+
fs43.writeFileSync(full, content, { encoding: "utf8", mode: 384 });
|
|
41760
|
+
} else if (fs43.existsSync(full)) {
|
|
41761
|
+
fs43.unlinkSync(full);
|
|
41714
41762
|
}
|
|
41715
41763
|
return { success: true, path: full, kind, key: key2 };
|
|
41716
41764
|
} catch (error) {
|
|
@@ -41826,21 +41874,21 @@ init_config();
|
|
|
41826
41874
|
// src/commands/upgrade-helper.ts
|
|
41827
41875
|
import { execFileSync as execFileSync3 } from "child_process";
|
|
41828
41876
|
import { spawn } from "child_process";
|
|
41829
|
-
import * as
|
|
41877
|
+
import * as fs14 from "fs";
|
|
41830
41878
|
import * as os13 from "os";
|
|
41831
41879
|
import * as path20 from "path";
|
|
41832
41880
|
var UPGRADE_HELPER_ENV = "ADHDEV_DAEMON_UPGRADE_HELPER";
|
|
41833
41881
|
function getUpgradeLogPath() {
|
|
41834
41882
|
const home = os13.homedir();
|
|
41835
41883
|
const dir = path20.join(home, ".adhdev");
|
|
41836
|
-
|
|
41884
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
41837
41885
|
return path20.join(dir, "daemon-upgrade.log");
|
|
41838
41886
|
}
|
|
41839
41887
|
function appendUpgradeLog(message) {
|
|
41840
41888
|
const line = `[${(/* @__PURE__ */ new Date()).toISOString()}] ${message}
|
|
41841
41889
|
`;
|
|
41842
41890
|
try {
|
|
41843
|
-
|
|
41891
|
+
fs14.appendFileSync(getUpgradeLogPath(), line, "utf8");
|
|
41844
41892
|
} catch {
|
|
41845
41893
|
}
|
|
41846
41894
|
}
|
|
@@ -41848,12 +41896,12 @@ function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platfo
|
|
|
41848
41896
|
const binDir = path20.dirname(nodeExecutable);
|
|
41849
41897
|
if (platform10 === "win32") {
|
|
41850
41898
|
const npmCliPath = path20.join(binDir, "node_modules", "npm", "bin", "npm-cli.js");
|
|
41851
|
-
if (
|
|
41899
|
+
if (fs14.existsSync(npmCliPath)) {
|
|
41852
41900
|
return { executable: nodeExecutable, argsPrefix: [npmCliPath], execOptions: getNpmExecOptions(platform10) };
|
|
41853
41901
|
}
|
|
41854
41902
|
for (const candidate of ["npm.exe", "npm"]) {
|
|
41855
41903
|
const candidatePath = path20.join(binDir, candidate);
|
|
41856
|
-
if (
|
|
41904
|
+
if (fs14.existsSync(candidatePath)) {
|
|
41857
41905
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
41858
41906
|
}
|
|
41859
41907
|
}
|
|
@@ -41861,7 +41909,7 @@ function resolveSiblingNpmInvocation(nodeExecutable, platform10 = process.platfo
|
|
|
41861
41909
|
}
|
|
41862
41910
|
for (const candidate of ["npm"]) {
|
|
41863
41911
|
const candidatePath = path20.join(binDir, candidate);
|
|
41864
|
-
if (
|
|
41912
|
+
if (fs14.existsSync(candidatePath)) {
|
|
41865
41913
|
return { executable: candidatePath, argsPrefix: [], execOptions: getNpmExecOptions(platform10) };
|
|
41866
41914
|
}
|
|
41867
41915
|
}
|
|
@@ -41871,12 +41919,12 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
41871
41919
|
if (!currentCliPath) return null;
|
|
41872
41920
|
let resolvedPath = currentCliPath;
|
|
41873
41921
|
try {
|
|
41874
|
-
resolvedPath =
|
|
41922
|
+
resolvedPath = fs14.realpathSync.native(currentCliPath);
|
|
41875
41923
|
} catch {
|
|
41876
41924
|
}
|
|
41877
41925
|
let currentDir = resolvedPath;
|
|
41878
41926
|
try {
|
|
41879
|
-
if (
|
|
41927
|
+
if (fs14.statSync(resolvedPath).isFile()) {
|
|
41880
41928
|
currentDir = path20.dirname(resolvedPath);
|
|
41881
41929
|
}
|
|
41882
41930
|
} catch {
|
|
@@ -41885,8 +41933,8 @@ function findCurrentPackageRoot(currentCliPath, packageName) {
|
|
|
41885
41933
|
while (true) {
|
|
41886
41934
|
const packageJsonPath = path20.join(currentDir, "package.json");
|
|
41887
41935
|
try {
|
|
41888
|
-
if (
|
|
41889
|
-
const parsed = JSON.parse(
|
|
41936
|
+
if (fs14.existsSync(packageJsonPath)) {
|
|
41937
|
+
const parsed = JSON.parse(fs14.readFileSync(packageJsonPath, "utf8"));
|
|
41890
41938
|
if (parsed?.name === packageName) {
|
|
41891
41939
|
const normalized = currentDir.replace(/\\/g, "/");
|
|
41892
41940
|
return normalized.includes("/node_modules/") ? currentDir : null;
|
|
@@ -42027,7 +42075,7 @@ async function waitForPidExit(pid, timeoutMs) {
|
|
|
42027
42075
|
while (Date.now() - start < timeoutMs) {
|
|
42028
42076
|
try {
|
|
42029
42077
|
process.kill(pid, 0);
|
|
42030
|
-
await new Promise((
|
|
42078
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
42031
42079
|
} catch {
|
|
42032
42080
|
return;
|
|
42033
42081
|
}
|
|
@@ -42037,8 +42085,8 @@ async function stopSessionHostProcesses(appName) {
|
|
|
42037
42085
|
const pidFile = path20.join(os13.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
42038
42086
|
let killedPid = null;
|
|
42039
42087
|
try {
|
|
42040
|
-
if (
|
|
42041
|
-
const pid = Number.parseInt(
|
|
42088
|
+
if (fs14.existsSync(pidFile)) {
|
|
42089
|
+
const pid = Number.parseInt(fs14.readFileSync(pidFile, "utf8").trim(), 10);
|
|
42042
42090
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
|
|
42043
42091
|
if (killPid(pid)) killedPid = pid;
|
|
42044
42092
|
}
|
|
@@ -42046,7 +42094,7 @@ async function stopSessionHostProcesses(appName) {
|
|
|
42046
42094
|
} catch {
|
|
42047
42095
|
} finally {
|
|
42048
42096
|
try {
|
|
42049
|
-
|
|
42097
|
+
fs14.unlinkSync(pidFile);
|
|
42050
42098
|
} catch {
|
|
42051
42099
|
}
|
|
42052
42100
|
}
|
|
@@ -42123,7 +42171,7 @@ function getUpgradeFailureNoticePath() {
|
|
|
42123
42171
|
const home = os13.homedir();
|
|
42124
42172
|
const dir = path20.join(home, ".adhdev");
|
|
42125
42173
|
try {
|
|
42126
|
-
|
|
42174
|
+
fs14.mkdirSync(dir, { recursive: true });
|
|
42127
42175
|
} catch {
|
|
42128
42176
|
}
|
|
42129
42177
|
return path20.join(dir, "daemon-upgrade-last-error.txt");
|
|
@@ -42136,7 +42184,7 @@ function emitUpgradeFailureNotice(lines) {
|
|
|
42136
42184
|
appendUpgradeLog(`Upgrade blocked \u2014 user action required:
|
|
42137
42185
|
${body}`);
|
|
42138
42186
|
try {
|
|
42139
|
-
|
|
42187
|
+
fs14.writeFileSync(getUpgradeFailureNoticePath(), `[${(/* @__PURE__ */ new Date()).toISOString()}]
|
|
42140
42188
|
${body}
|
|
42141
42189
|
`, "utf8");
|
|
42142
42190
|
} catch {
|
|
@@ -42151,13 +42199,13 @@ function isRetriableInstallLockError(error) {
|
|
|
42151
42199
|
function removeDaemonPidFile() {
|
|
42152
42200
|
const pidFile = path20.join(os13.homedir(), ".adhdev", "daemon.pid");
|
|
42153
42201
|
try {
|
|
42154
|
-
|
|
42202
|
+
fs14.unlinkSync(pidFile);
|
|
42155
42203
|
} catch {
|
|
42156
42204
|
}
|
|
42157
42205
|
}
|
|
42158
42206
|
function safeRemoveStaleEntry(target, label) {
|
|
42159
42207
|
try {
|
|
42160
|
-
|
|
42208
|
+
fs14.rmSync(target, { recursive: true, force: true });
|
|
42161
42209
|
appendUpgradeLog(`${label}: ${target}`);
|
|
42162
42210
|
} catch (error) {
|
|
42163
42211
|
appendUpgradeLog(`Skipped locked stale entry (${error?.code || "error"}): ${target} \u2014 ${error?.message || String(error)}`);
|
|
@@ -42178,19 +42226,19 @@ function cleanupStaleGlobalInstallDirs(pkgName, surface) {
|
|
|
42178
42226
|
if (pkgName.startsWith("@")) {
|
|
42179
42227
|
const [scope, name] = pkgName.split("/");
|
|
42180
42228
|
const scopeDir = path20.join(npmRoot, scope);
|
|
42181
|
-
if (!
|
|
42182
|
-
for (const entry of
|
|
42229
|
+
if (!fs14.existsSync(scopeDir)) return;
|
|
42230
|
+
for (const entry of fs14.readdirSync(scopeDir)) {
|
|
42183
42231
|
if (!entry.startsWith(`.${name}-`)) continue;
|
|
42184
42232
|
safeRemoveStaleEntry(path20.join(scopeDir, entry), "Removed stale scoped staging dir");
|
|
42185
42233
|
}
|
|
42186
42234
|
} else {
|
|
42187
|
-
for (const entry of
|
|
42235
|
+
for (const entry of fs14.readdirSync(npmRoot)) {
|
|
42188
42236
|
if (!entry.startsWith(`.${pkgName}-`)) continue;
|
|
42189
42237
|
safeRemoveStaleEntry(path20.join(npmRoot, entry), "Removed stale staging dir");
|
|
42190
42238
|
}
|
|
42191
42239
|
}
|
|
42192
|
-
if (
|
|
42193
|
-
for (const entry of
|
|
42240
|
+
if (fs14.existsSync(binDir)) {
|
|
42241
|
+
for (const entry of fs14.readdirSync(binDir)) {
|
|
42194
42242
|
if (!Array.from(binNames).some((name) => entry.startsWith(`.${name}-`))) continue;
|
|
42195
42243
|
safeRemoveStaleEntry(path20.join(binDir, entry), "Removed stale bin staging entry");
|
|
42196
42244
|
}
|
|
@@ -42253,7 +42301,7 @@ async function runDaemonUpgradeHelper(payload) {
|
|
|
42253
42301
|
appendUpgradeLog(`Install attempt ${attempt} hit a file lock (${error?.code || "lock"}); clearing holders + staging and retrying after backoff`);
|
|
42254
42302
|
await stopForeignNativeAddonHolders(installCommand.surface.packageRoot, { parentPid: payload.parentPid });
|
|
42255
42303
|
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
42256
|
-
await new Promise((
|
|
42304
|
+
await new Promise((resolve26) => setTimeout(resolve26, attempt * 1500));
|
|
42257
42305
|
continue;
|
|
42258
42306
|
}
|
|
42259
42307
|
if (isRetriableInstallLockError(error)) {
|
|
@@ -42281,7 +42329,7 @@ async function runDaemonUpgradeHelper(payload) {
|
|
|
42281
42329
|
appendUpgradeLog(installOutput.trim());
|
|
42282
42330
|
}
|
|
42283
42331
|
if (process.platform === "win32") {
|
|
42284
|
-
await new Promise((
|
|
42332
|
+
await new Promise((resolve26) => setTimeout(resolve26, 500));
|
|
42285
42333
|
cleanupStaleGlobalInstallDirs(payload.packageName, installCommand.surface);
|
|
42286
42334
|
appendUpgradeLog("Post-install staging cleanup complete");
|
|
42287
42335
|
}
|
|
@@ -42447,7 +42495,7 @@ init_dist();
|
|
|
42447
42495
|
|
|
42448
42496
|
// src/logging/log-tail-reader.ts
|
|
42449
42497
|
init_logger();
|
|
42450
|
-
import * as
|
|
42498
|
+
import * as fs15 from "fs";
|
|
42451
42499
|
var DEFAULT_TAIL_BYTES = 64 * 1024;
|
|
42452
42500
|
var MAX_TAIL_BYTES = 128 * 1024;
|
|
42453
42501
|
var READ_CHUNK_BYTES = 64 * 1024;
|
|
@@ -42464,9 +42512,9 @@ function clampTailBytes(tailBytes) {
|
|
|
42464
42512
|
return Math.min(Math.floor(tailBytes), MAX_TAIL_BYTES);
|
|
42465
42513
|
}
|
|
42466
42514
|
function readByteBoundedTail(filePath, limitBytes) {
|
|
42467
|
-
const fd =
|
|
42515
|
+
const fd = fs15.openSync(filePath, "r");
|
|
42468
42516
|
try {
|
|
42469
|
-
const stat2 =
|
|
42517
|
+
const stat2 = fs15.fstatSync(fd);
|
|
42470
42518
|
const size = stat2.size;
|
|
42471
42519
|
if (size === 0) return { text: "", truncated: false, bytesReturned: 0 };
|
|
42472
42520
|
const want = Math.min(limitBytes, size);
|
|
@@ -42477,7 +42525,7 @@ function readByteBoundedTail(filePath, limitBytes) {
|
|
|
42477
42525
|
while (position < size) {
|
|
42478
42526
|
const chunkSize = Math.min(READ_CHUNK_BYTES, size - position);
|
|
42479
42527
|
const chunk = Buffer.alloc(chunkSize);
|
|
42480
|
-
|
|
42528
|
+
fs15.readSync(fd, chunk, 0, chunkSize, position);
|
|
42481
42529
|
buffers.push(chunk);
|
|
42482
42530
|
position += chunkSize;
|
|
42483
42531
|
}
|
|
@@ -42490,7 +42538,7 @@ function readByteBoundedTail(filePath, limitBytes) {
|
|
|
42490
42538
|
}
|
|
42491
42539
|
return { text: buf.toString("utf-8"), truncated, bytesReturned: buf.length };
|
|
42492
42540
|
} finally {
|
|
42493
|
-
|
|
42541
|
+
fs15.closeSync(fd);
|
|
42494
42542
|
}
|
|
42495
42543
|
}
|
|
42496
42544
|
function splitLogLines(text) {
|
|
@@ -42568,8 +42616,8 @@ function readDaemonLogTail(args = {}) {
|
|
|
42568
42616
|
const limitBytes = clampTailBytes(args.tailBytes);
|
|
42569
42617
|
const primaryPath = resolveLogPath(args.date);
|
|
42570
42618
|
const backupPath = primaryPath.replace(/\.log$/, ".1.log");
|
|
42571
|
-
const primaryExists =
|
|
42572
|
-
const backupExists =
|
|
42619
|
+
const primaryExists = fs15.existsSync(primaryPath);
|
|
42620
|
+
const backupExists = fs15.existsSync(backupPath);
|
|
42573
42621
|
if (!primaryExists && !backupExists) {
|
|
42574
42622
|
return errorResult(
|
|
42575
42623
|
`No daemon log file at ${primaryPath} (dir: ${getDaemonLogDir()})`,
|
|
@@ -42608,7 +42656,7 @@ function readDaemonLogTail(args = {}) {
|
|
|
42608
42656
|
try {
|
|
42609
42657
|
for (const p of [backupExists ? backupPath : null, primaryExists ? primaryPath : null]) {
|
|
42610
42658
|
if (!p) continue;
|
|
42611
|
-
const buf =
|
|
42659
|
+
const buf = fs15.readFileSync(p);
|
|
42612
42660
|
scannedBytes += buf.length;
|
|
42613
42661
|
allLines = allLines.concat(splitLogLines(buf.toString("utf-8")));
|
|
42614
42662
|
}
|
|
@@ -42814,16 +42862,16 @@ init_contracts2();
|
|
|
42814
42862
|
init_provider_input_support();
|
|
42815
42863
|
import * as os21 from "os";
|
|
42816
42864
|
import * as crypto5 from "crypto";
|
|
42817
|
-
import * as
|
|
42865
|
+
import * as fs23 from "fs";
|
|
42818
42866
|
init_hash();
|
|
42819
42867
|
|
|
42820
42868
|
// src/providers/spec/route.ts
|
|
42821
42869
|
init_provider_cli_adapter();
|
|
42822
|
-
import * as
|
|
42870
|
+
import * as fs21 from "fs";
|
|
42823
42871
|
import * as path25 from "path";
|
|
42824
42872
|
|
|
42825
42873
|
// src/providers/spec/fsm-driver.ts
|
|
42826
|
-
import * as
|
|
42874
|
+
import * as fs17 from "fs";
|
|
42827
42875
|
import * as os18 from "os";
|
|
42828
42876
|
import * as path23 from "path";
|
|
42829
42877
|
|
|
@@ -43003,7 +43051,7 @@ import { DEFAULT_SESSION_HOST_COLS as DEFAULT_SESSION_HOST_COLS6, DEFAULT_SESSIO
|
|
|
43003
43051
|
|
|
43004
43052
|
// src/providers/spec/pre-launch-trust.ts
|
|
43005
43053
|
init_logger();
|
|
43006
|
-
import * as
|
|
43054
|
+
import * as fs16 from "fs";
|
|
43007
43055
|
import * as os17 from "os";
|
|
43008
43056
|
import * as path22 from "path";
|
|
43009
43057
|
function expandHome2(p) {
|
|
@@ -43013,7 +43061,7 @@ function expandHome2(p) {
|
|
|
43013
43061
|
}
|
|
43014
43062
|
function realWorkspacePath(workingDir) {
|
|
43015
43063
|
try {
|
|
43016
|
-
return
|
|
43064
|
+
return fs16.realpathSync(workingDir);
|
|
43017
43065
|
} catch {
|
|
43018
43066
|
return path22.resolve(workingDir);
|
|
43019
43067
|
}
|
|
@@ -43024,8 +43072,8 @@ function applyPreLaunchTrust(trust, workingDir) {
|
|
|
43024
43072
|
const real = realWorkspacePath(workingDir);
|
|
43025
43073
|
try {
|
|
43026
43074
|
let parsed = {};
|
|
43027
|
-
if (
|
|
43028
|
-
const text =
|
|
43075
|
+
if (fs16.existsSync(settingsPath)) {
|
|
43076
|
+
const text = fs16.readFileSync(settingsPath, "utf8");
|
|
43029
43077
|
if (text.trim().length > 0) {
|
|
43030
43078
|
const json = JSON.parse(text);
|
|
43031
43079
|
if (json && typeof json === "object" && !Array.isArray(json)) {
|
|
@@ -43041,8 +43089,8 @@ function applyPreLaunchTrust(trust, workingDir) {
|
|
|
43041
43089
|
}
|
|
43042
43090
|
list.push(real);
|
|
43043
43091
|
parsed[key2] = list;
|
|
43044
|
-
|
|
43045
|
-
|
|
43092
|
+
fs16.mkdirSync(path22.dirname(settingsPath), { recursive: true });
|
|
43093
|
+
fs16.writeFileSync(settingsPath, `${JSON.stringify(parsed, null, 2)}
|
|
43046
43094
|
`, "utf8");
|
|
43047
43095
|
LOG.info("pre-launch-trust", `pre-trusted workspace in ${trust.settings_path} (key="${key2}")`);
|
|
43048
43096
|
return real;
|
|
@@ -43405,7 +43453,7 @@ var FsmDriver = class {
|
|
|
43405
43453
|
try {
|
|
43406
43454
|
const dir = path23.dirname(this.opts.specPath);
|
|
43407
43455
|
const base = path23.basename(this.opts.specPath);
|
|
43408
|
-
this.specWatcher =
|
|
43456
|
+
this.specWatcher = fs17.watch(dir, { persistent: false }, (_event, filename) => {
|
|
43409
43457
|
if (filename && filename !== base) return;
|
|
43410
43458
|
const res = loadFsmSpec(this.opts.specPath);
|
|
43411
43459
|
if (!res.ok) {
|
|
@@ -44041,7 +44089,7 @@ var FsmDriver = class {
|
|
|
44041
44089
|
const ext = guessExt(mime);
|
|
44042
44090
|
const tmp = path23.join(os18.tmpdir(), `adhdev-attach-${Date.now()}${ext}`);
|
|
44043
44091
|
try {
|
|
44044
|
-
|
|
44092
|
+
fs17.writeFileSync(tmp, Buffer.from(blob, "base64"));
|
|
44045
44093
|
} catch {
|
|
44046
44094
|
return;
|
|
44047
44095
|
}
|
|
@@ -44175,7 +44223,7 @@ init_evaluator();
|
|
|
44175
44223
|
// src/providers/spec/native-history-executor.ts
|
|
44176
44224
|
init_logger();
|
|
44177
44225
|
init_load_better_sqlite3();
|
|
44178
|
-
import * as
|
|
44226
|
+
import * as fs18 from "fs";
|
|
44179
44227
|
import * as os19 from "os";
|
|
44180
44228
|
import * as path24 from "path";
|
|
44181
44229
|
|
|
@@ -44198,7 +44246,7 @@ function executeJsonl(src, input) {
|
|
|
44198
44246
|
const wsRaw = typeof input.workspace === "string" ? input.workspace : "";
|
|
44199
44247
|
let wsReal = wsRaw;
|
|
44200
44248
|
try {
|
|
44201
|
-
if (wsRaw) wsReal =
|
|
44249
|
+
if (wsRaw) wsReal = fs18.realpathSync(wsRaw);
|
|
44202
44250
|
} catch {
|
|
44203
44251
|
}
|
|
44204
44252
|
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)`);
|
|
@@ -44207,23 +44255,26 @@ function executeJsonl(src, input) {
|
|
|
44207
44255
|
const mtime = safeMtimeMs(sourcePath);
|
|
44208
44256
|
const lines = readJsonlLines(sourcePath);
|
|
44209
44257
|
if (lines.length === 0) return null;
|
|
44210
|
-
const transcriptWorkspace = readSessionMetaWorkspace(lines) ?? (src.workspace_from_input ? workspaceFromInputIfSlugMatches(sourcePath, input) : void 0);
|
|
44258
|
+
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);
|
|
44211
44259
|
let providerSessionId;
|
|
44212
44260
|
if (src.session_id_from === "first_record" && src.session_id_path) {
|
|
44213
44261
|
const v = jsonPathGet(lines[0], src.session_id_path);
|
|
44214
44262
|
if (typeof v === "string" && v) providerSessionId = v;
|
|
44263
|
+
} else if (src.session_id_from === "dir_uuid") {
|
|
44264
|
+
providerSessionId = dirUuid(sourcePath) || void 0;
|
|
44215
44265
|
} else if (src.session_id_from === "filename_uuid" || !src.session_id_from) {
|
|
44216
44266
|
const m = path24.basename(sourcePath).match(UUID_RE);
|
|
44217
44267
|
if (m) providerSessionId = m[1];
|
|
44218
44268
|
}
|
|
44219
44269
|
const requested = readRequestedSessionId(input) || "";
|
|
44220
|
-
if (requested && providerSessionId && providerSessionId
|
|
44221
|
-
const
|
|
44270
|
+
if (requested && providerSessionId && !sameSessionUuid(providerSessionId, requested)) return null;
|
|
44271
|
+
const shapes = compileRecordShapes(src);
|
|
44222
44272
|
const messages = [];
|
|
44223
44273
|
for (let i = 0; i < lines.length; i += 1) {
|
|
44224
44274
|
const rec = lines[i];
|
|
44225
|
-
|
|
44226
|
-
|
|
44275
|
+
const shape = shapes.pick(rec);
|
|
44276
|
+
if (!shape) continue;
|
|
44277
|
+
for (const msg of projectMessages(rec, shape.map, i, lines.length, mtime)) {
|
|
44227
44278
|
if (transcriptWorkspace) msg.workspace = transcriptWorkspace;
|
|
44228
44279
|
messages.push(msg);
|
|
44229
44280
|
}
|
|
@@ -44248,11 +44299,22 @@ function resolveJsonlSourcePath(src, input) {
|
|
|
44248
44299
|
const workspaceHint = typeof input.workspace === "string" && input.workspace.trim() ? input.workspace.trim() : "";
|
|
44249
44300
|
let sourcePath = null;
|
|
44250
44301
|
if (resolved.includes("*")) {
|
|
44251
|
-
|
|
44302
|
+
if (src.session_id_from === "dir_uuid" || src.workspace_from_sidecar) {
|
|
44303
|
+
sourcePath = pickDirUuidFileAcrossGlob(resolved, filePat, requestedSessionId);
|
|
44304
|
+
if (!sourcePath && !requestedSessionId) {
|
|
44305
|
+
if (src.workspace_from_sidecar && workspaceHint) {
|
|
44306
|
+
sourcePath = pickSidecarWorkspaceFileAcrossGlob(resolved, filePat, windowMs, sessionFloor, workspaceHint, src.workspace_from_sidecar);
|
|
44307
|
+
} else {
|
|
44308
|
+
sourcePath = newestRecentFileAcrossGlob(resolved, filePat, windowMs, sessionFloor);
|
|
44309
|
+
}
|
|
44310
|
+
}
|
|
44311
|
+
} else {
|
|
44312
|
+
sourcePath = pickExactSessionFileAcrossGlob(resolved, filePat, requestedSessionId) || pickSessionBoundFileAcrossGlob(resolved, filePat, windowMs, sessionFloor, workspaceHint) || newestRecentFileAcrossGlob(resolved, filePat, windowMs, sessionFloor);
|
|
44313
|
+
}
|
|
44252
44314
|
} else {
|
|
44253
44315
|
let stat2 = null;
|
|
44254
44316
|
try {
|
|
44255
|
-
stat2 =
|
|
44317
|
+
stat2 = fs18.statSync(resolved);
|
|
44256
44318
|
} catch {
|
|
44257
44319
|
}
|
|
44258
44320
|
if (stat2 && stat2.isFile()) {
|
|
@@ -44267,7 +44329,7 @@ function resolveJsonlSourcePath(src, input) {
|
|
|
44267
44329
|
const resolvedRaw = expandPath2(src.path, input, { skipWorkspaceRealpath: true });
|
|
44268
44330
|
if (resolvedRaw && resolvedRaw !== resolved) {
|
|
44269
44331
|
try {
|
|
44270
|
-
const rawStat =
|
|
44332
|
+
const rawStat = fs18.statSync(resolvedRaw);
|
|
44271
44333
|
if (rawStat.isFile()) sourcePath = resolvedRaw;
|
|
44272
44334
|
else if (rawStat.isDirectory()) {
|
|
44273
44335
|
sourcePath = pickExactSessionFile(resolvedRaw, filePat, requestedSessionId) || (requestedSessionId ? null : newestRecentFile(resolvedRaw, filePat, windowMs, sessionFloor));
|
|
@@ -44290,12 +44352,61 @@ function readSessionMetaWorkspace(lines) {
|
|
|
44290
44352
|
}
|
|
44291
44353
|
return void 0;
|
|
44292
44354
|
}
|
|
44355
|
+
function readSidecarWorkspace(sourcePath, cfg) {
|
|
44356
|
+
try {
|
|
44357
|
+
const sidecar = path24.resolve(path24.dirname(sourcePath), cfg.rel_path);
|
|
44358
|
+
const parsed = JSON.parse(fs18.readFileSync(sidecar, "utf8"));
|
|
44359
|
+
const v = jsonPathGet(parsed, cfg.workspace_path);
|
|
44360
|
+
return typeof v === "string" && v.trim() ? v.trim() : void 0;
|
|
44361
|
+
} catch {
|
|
44362
|
+
return void 0;
|
|
44363
|
+
}
|
|
44364
|
+
}
|
|
44365
|
+
function dirUuid(filePath) {
|
|
44366
|
+
const segs = path24.dirname(filePath).split(path24.sep);
|
|
44367
|
+
for (let i = segs.length - 1; i >= 0; i -= 1) {
|
|
44368
|
+
const m = segs[i].match(UUID_RE);
|
|
44369
|
+
if (m) return m[1];
|
|
44370
|
+
}
|
|
44371
|
+
return "";
|
|
44372
|
+
}
|
|
44373
|
+
function sameSessionUuid(a, b) {
|
|
44374
|
+
if (a === b) return true;
|
|
44375
|
+
const ua = a.match(UUID_RE)?.[1]?.toLowerCase();
|
|
44376
|
+
const ub = b.match(UUID_RE)?.[1]?.toLowerCase();
|
|
44377
|
+
return !!ua && !!ub && ua === ub;
|
|
44378
|
+
}
|
|
44379
|
+
function compileRecordShapes(src) {
|
|
44380
|
+
if (Array.isArray(src.records) && src.records.length > 0) {
|
|
44381
|
+
const compiled = src.records.map((r) => ({
|
|
44382
|
+
where: r.where ? compileWhere(r.where) : null,
|
|
44383
|
+
map: r.message_map
|
|
44384
|
+
}));
|
|
44385
|
+
return {
|
|
44386
|
+
pick: (record) => {
|
|
44387
|
+
for (const shape of compiled) {
|
|
44388
|
+
if (!shape.where || shape.where(record)) return { map: shape.map };
|
|
44389
|
+
}
|
|
44390
|
+
return null;
|
|
44391
|
+
}
|
|
44392
|
+
};
|
|
44393
|
+
}
|
|
44394
|
+
const filter = src.message_filter ? compileWhere(src.message_filter.where) : null;
|
|
44395
|
+
const map = src.message_map;
|
|
44396
|
+
return {
|
|
44397
|
+
pick: (record) => {
|
|
44398
|
+
if (!map) return null;
|
|
44399
|
+
if (filter && !filter(record)) return null;
|
|
44400
|
+
return { map };
|
|
44401
|
+
}
|
|
44402
|
+
};
|
|
44403
|
+
}
|
|
44293
44404
|
function workspaceFromInputIfSlugMatches(sourcePath, input) {
|
|
44294
44405
|
const wsRaw = typeof input.workspace === "string" ? input.workspace.trim() : "";
|
|
44295
44406
|
if (!wsRaw) return void 0;
|
|
44296
44407
|
let wsReal = wsRaw;
|
|
44297
44408
|
try {
|
|
44298
|
-
wsReal =
|
|
44409
|
+
wsReal = fs18.realpathSync(wsRaw);
|
|
44299
44410
|
} catch {
|
|
44300
44411
|
}
|
|
44301
44412
|
const slugs = /* @__PURE__ */ new Set();
|
|
@@ -44319,7 +44430,7 @@ function workspaceFromInputIfSlugMatches(sourcePath, input) {
|
|
|
44319
44430
|
function readJsonlLines(p) {
|
|
44320
44431
|
let text;
|
|
44321
44432
|
try {
|
|
44322
|
-
text =
|
|
44433
|
+
text = fs18.readFileSync(p, "utf8");
|
|
44323
44434
|
} catch {
|
|
44324
44435
|
return [];
|
|
44325
44436
|
}
|
|
@@ -44336,7 +44447,7 @@ function readJsonlLines(p) {
|
|
|
44336
44447
|
}
|
|
44337
44448
|
function executeSqlite(src, input) {
|
|
44338
44449
|
const resolved = expandPath2(src.path, input);
|
|
44339
|
-
if (!resolved || !
|
|
44450
|
+
if (!resolved || !fs18.existsSync(resolved)) return null;
|
|
44340
44451
|
let Database;
|
|
44341
44452
|
try {
|
|
44342
44453
|
Database = loadBetterSqlite3();
|
|
@@ -44475,7 +44586,7 @@ function expandPath2(template, input, opts) {
|
|
|
44475
44586
|
let workspaceResolved = workspaceRaw;
|
|
44476
44587
|
if (workspaceRaw && !opts?.skipWorkspaceRealpath) {
|
|
44477
44588
|
try {
|
|
44478
|
-
workspaceResolved =
|
|
44589
|
+
workspaceResolved = fs18.realpathSync(workspaceRaw);
|
|
44479
44590
|
} catch {
|
|
44480
44591
|
}
|
|
44481
44592
|
}
|
|
@@ -44514,7 +44625,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44514
44625
|
if (!base) return null;
|
|
44515
44626
|
let baseStat = null;
|
|
44516
44627
|
try {
|
|
44517
|
-
baseStat =
|
|
44628
|
+
baseStat = fs18.statSync(base);
|
|
44518
44629
|
} catch {
|
|
44519
44630
|
return null;
|
|
44520
44631
|
}
|
|
@@ -44522,7 +44633,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44522
44633
|
const needle = `${requestedSessionId.toLowerCase()}.jsonl`;
|
|
44523
44634
|
const dirsToScan = [base];
|
|
44524
44635
|
try {
|
|
44525
|
-
for (const entry of
|
|
44636
|
+
for (const entry of fs18.readdirSync(base, { withFileTypes: true })) {
|
|
44526
44637
|
if (entry.isDirectory()) dirsToScan.push(path24.join(base, entry.name));
|
|
44527
44638
|
}
|
|
44528
44639
|
} catch {
|
|
@@ -44530,7 +44641,7 @@ function scanProjectsRootForSessionFile(template, input, requestedSessionId) {
|
|
|
44530
44641
|
for (const dir of dirsToScan) {
|
|
44531
44642
|
let entries;
|
|
44532
44643
|
try {
|
|
44533
|
-
entries =
|
|
44644
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
44534
44645
|
} catch {
|
|
44535
44646
|
continue;
|
|
44536
44647
|
}
|
|
@@ -44565,7 +44676,7 @@ function expandDirGlob(template) {
|
|
|
44565
44676
|
for (const d of dirs) {
|
|
44566
44677
|
let entries;
|
|
44567
44678
|
try {
|
|
44568
|
-
entries =
|
|
44679
|
+
entries = fs18.readdirSync(d, { withFileTypes: true });
|
|
44569
44680
|
} catch {
|
|
44570
44681
|
continue;
|
|
44571
44682
|
}
|
|
@@ -44578,7 +44689,7 @@ function expandDirGlob(template) {
|
|
|
44578
44689
|
const candidate = path24.join(d, seg);
|
|
44579
44690
|
let stat2 = null;
|
|
44580
44691
|
try {
|
|
44581
|
-
stat2 =
|
|
44692
|
+
stat2 = fs18.statSync(candidate);
|
|
44582
44693
|
} catch {
|
|
44583
44694
|
continue;
|
|
44584
44695
|
}
|
|
@@ -44592,7 +44703,7 @@ function expandDirGlob(template) {
|
|
|
44592
44703
|
function walkAllDirs(root, out) {
|
|
44593
44704
|
let entries;
|
|
44594
44705
|
try {
|
|
44595
|
-
entries =
|
|
44706
|
+
entries = fs18.readdirSync(root, { withFileTypes: true });
|
|
44596
44707
|
} catch {
|
|
44597
44708
|
return;
|
|
44598
44709
|
}
|
|
@@ -44608,7 +44719,7 @@ function newestRecentFileAcrossGlob(template, pattern, windowMs, sessionFloorMs
|
|
|
44608
44719
|
for (const d of dirs) {
|
|
44609
44720
|
let entries;
|
|
44610
44721
|
try {
|
|
44611
|
-
entries =
|
|
44722
|
+
entries = fs18.readdirSync(d, { withFileTypes: true });
|
|
44612
44723
|
} catch {
|
|
44613
44724
|
continue;
|
|
44614
44725
|
}
|
|
@@ -44635,7 +44746,7 @@ function newestRecentFileAcrossDateWindow(template, input, pattern, windowMs, se
|
|
|
44635
44746
|
if (!resolved) continue;
|
|
44636
44747
|
let entries;
|
|
44637
44748
|
try {
|
|
44638
|
-
entries =
|
|
44749
|
+
entries = fs18.readdirSync(resolved, { withFileTypes: true });
|
|
44639
44750
|
} catch {
|
|
44640
44751
|
continue;
|
|
44641
44752
|
}
|
|
@@ -44664,7 +44775,7 @@ function expandPathForDate(template, input, day) {
|
|
|
44664
44775
|
let workspaceResolved = workspaceRaw;
|
|
44665
44776
|
if (workspaceRaw) {
|
|
44666
44777
|
try {
|
|
44667
|
-
workspaceResolved =
|
|
44778
|
+
workspaceResolved = fs18.realpathSync(workspaceRaw);
|
|
44668
44779
|
} catch {
|
|
44669
44780
|
}
|
|
44670
44781
|
}
|
|
@@ -44689,7 +44800,7 @@ function expandPathForDate(template, input, day) {
|
|
|
44689
44800
|
function newestRecentFile(dir, pattern, windowMs, sessionFloorMs = 0) {
|
|
44690
44801
|
let entries;
|
|
44691
44802
|
try {
|
|
44692
|
-
entries =
|
|
44803
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
44693
44804
|
} catch {
|
|
44694
44805
|
return null;
|
|
44695
44806
|
}
|
|
@@ -44706,7 +44817,7 @@ function newestRecentFile(dir, pattern, windowMs, sessionFloorMs = 0) {
|
|
|
44706
44817
|
}
|
|
44707
44818
|
function safeMtimeMs(p) {
|
|
44708
44819
|
try {
|
|
44709
|
-
return Math.floor(
|
|
44820
|
+
return Math.floor(fs18.statSync(p).mtimeMs);
|
|
44710
44821
|
} catch {
|
|
44711
44822
|
return 0;
|
|
44712
44823
|
}
|
|
@@ -44736,6 +44847,47 @@ function pickExactSessionFileAcrossGlob(template, pattern, requestedSessionId) {
|
|
|
44736
44847
|
matches.sort((a, b) => safeMtimeMs(b) - safeMtimeMs(a));
|
|
44737
44848
|
return matches[0] || null;
|
|
44738
44849
|
}
|
|
44850
|
+
function pickDirUuidFileAcrossGlob(template, pattern, requestedSessionId) {
|
|
44851
|
+
if (!requestedSessionId) return null;
|
|
44852
|
+
const wantUuid = requestedSessionId.match(UUID_RE)?.[1]?.toLowerCase();
|
|
44853
|
+
if (!wantUuid) return null;
|
|
44854
|
+
const dirs = expandDirGlob(template);
|
|
44855
|
+
const matches = [];
|
|
44856
|
+
for (const d of dirs) {
|
|
44857
|
+
for (const p of listMatchingFiles(d, pattern)) {
|
|
44858
|
+
if (dirUuid(p).toLowerCase() === wantUuid) matches.push(p);
|
|
44859
|
+
}
|
|
44860
|
+
}
|
|
44861
|
+
matches.sort((a, b) => safeMtimeMs(b) - safeMtimeMs(a));
|
|
44862
|
+
return matches[0] || null;
|
|
44863
|
+
}
|
|
44864
|
+
function pickSidecarWorkspaceFileAcrossGlob(template, pattern, windowMs, sessionFloorMs, workspaceHint, sidecar) {
|
|
44865
|
+
if (!sidecar || !workspaceHint) return null;
|
|
44866
|
+
let wsResolved = workspaceHint;
|
|
44867
|
+
try {
|
|
44868
|
+
wsResolved = fs18.realpathSync(workspaceHint);
|
|
44869
|
+
} catch {
|
|
44870
|
+
}
|
|
44871
|
+
const dirs = expandDirGlob(template);
|
|
44872
|
+
const cutoff = Math.max(Date.now() - windowMs, sessionFloorMs);
|
|
44873
|
+
let best = null;
|
|
44874
|
+
for (const d of dirs) {
|
|
44875
|
+
for (const p of listMatchingFiles(d, pattern)) {
|
|
44876
|
+
const mtime = safeMtimeMs(p);
|
|
44877
|
+
if (mtime < cutoff) continue;
|
|
44878
|
+
const ws = readSidecarWorkspace(p, sidecar);
|
|
44879
|
+
if (!ws) continue;
|
|
44880
|
+
let wsReal = ws;
|
|
44881
|
+
try {
|
|
44882
|
+
wsReal = fs18.realpathSync(ws);
|
|
44883
|
+
} catch {
|
|
44884
|
+
}
|
|
44885
|
+
if (ws !== workspaceHint && wsReal !== wsResolved) continue;
|
|
44886
|
+
if (!best || mtime > best.mtime) best = { p, mtime };
|
|
44887
|
+
}
|
|
44888
|
+
}
|
|
44889
|
+
return best ? best.p : null;
|
|
44890
|
+
}
|
|
44739
44891
|
function pickExactSessionFileAcrossDateWindow(template, input, pattern, requestedSessionId) {
|
|
44740
44892
|
if (!requestedSessionId) return null;
|
|
44741
44893
|
const matches = [];
|
|
@@ -44751,10 +44903,10 @@ function pickExactSessionFileAcrossDateWindow(template, input, pattern, requeste
|
|
|
44751
44903
|
}
|
|
44752
44904
|
function readCandidateSessionMeta(filePath) {
|
|
44753
44905
|
try {
|
|
44754
|
-
const fd =
|
|
44906
|
+
const fd = fs18.openSync(filePath, "r");
|
|
44755
44907
|
try {
|
|
44756
44908
|
const buf = Buffer.alloc(8192);
|
|
44757
|
-
const bytes =
|
|
44909
|
+
const bytes = fs18.readSync(fd, buf, 0, buf.length, 0);
|
|
44758
44910
|
if (bytes <= 0) return null;
|
|
44759
44911
|
const text = buf.subarray(0, bytes).toString("utf8");
|
|
44760
44912
|
const nl = text.indexOf("\n");
|
|
@@ -44772,7 +44924,7 @@ function readCandidateSessionMeta(filePath) {
|
|
|
44772
44924
|
sessionTimestampMs: Number.isFinite(tsMs) ? tsMs : void 0
|
|
44773
44925
|
};
|
|
44774
44926
|
} finally {
|
|
44775
|
-
|
|
44927
|
+
fs18.closeSync(fd);
|
|
44776
44928
|
}
|
|
44777
44929
|
} catch {
|
|
44778
44930
|
return null;
|
|
@@ -44782,7 +44934,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
44782
44934
|
if (!sessionFloorMs || !workspaceHint || candidatePaths.length === 0) return null;
|
|
44783
44935
|
let workspaceResolved = workspaceHint;
|
|
44784
44936
|
try {
|
|
44785
|
-
workspaceResolved =
|
|
44937
|
+
workspaceResolved = fs18.realpathSync(workspaceHint);
|
|
44786
44938
|
} catch {
|
|
44787
44939
|
}
|
|
44788
44940
|
let best = null;
|
|
@@ -44791,7 +44943,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
44791
44943
|
if (!meta || !meta.cwd || meta.sessionTimestampMs == null) continue;
|
|
44792
44944
|
let candidateCwd = meta.cwd;
|
|
44793
44945
|
try {
|
|
44794
|
-
candidateCwd =
|
|
44946
|
+
candidateCwd = fs18.realpathSync(meta.cwd);
|
|
44795
44947
|
} catch {
|
|
44796
44948
|
}
|
|
44797
44949
|
if (candidateCwd !== workspaceResolved && meta.cwd !== workspaceHint) continue;
|
|
@@ -44804,7 +44956,7 @@ function pickBoundFromEntries(candidatePaths, sessionFloorMs, workspaceHint) {
|
|
|
44804
44956
|
function listMatchingFiles(dir, pattern) {
|
|
44805
44957
|
let entries;
|
|
44806
44958
|
try {
|
|
44807
|
-
entries =
|
|
44959
|
+
entries = fs18.readdirSync(dir, { withFileTypes: true });
|
|
44808
44960
|
} catch {
|
|
44809
44961
|
return [];
|
|
44810
44962
|
}
|
|
@@ -45099,7 +45251,7 @@ function evalTerm(t, record) {
|
|
|
45099
45251
|
|
|
45100
45252
|
// src/providers/spec/background-task-detector.ts
|
|
45101
45253
|
init_logger();
|
|
45102
|
-
import * as
|
|
45254
|
+
import * as fs19 from "fs";
|
|
45103
45255
|
var EMPTY = { active: false, count: 0, ids: [] };
|
|
45104
45256
|
var TAIL_BYTES = 512 * 1024;
|
|
45105
45257
|
function detectBackgroundTaskActive(cfg, input) {
|
|
@@ -45160,19 +45312,19 @@ function detectFromRecords(records) {
|
|
|
45160
45312
|
return { active: true, count: unresolved.length, ids: unresolved };
|
|
45161
45313
|
}
|
|
45162
45314
|
function readTailJsonlLines(filePath, maxBytes) {
|
|
45163
|
-
const stat2 =
|
|
45315
|
+
const stat2 = fs19.statSync(filePath);
|
|
45164
45316
|
const size = stat2.size;
|
|
45165
45317
|
const start = size > maxBytes ? size - maxBytes : 0;
|
|
45166
45318
|
const length = size - start;
|
|
45167
45319
|
if (length <= 0) return [];
|
|
45168
|
-
const fd =
|
|
45320
|
+
const fd = fs19.openSync(filePath, "r");
|
|
45169
45321
|
let text;
|
|
45170
45322
|
try {
|
|
45171
45323
|
const buf = Buffer.alloc(length);
|
|
45172
|
-
const bytes =
|
|
45324
|
+
const bytes = fs19.readSync(fd, buf, 0, length, start);
|
|
45173
45325
|
text = buf.subarray(0, bytes).toString("utf8");
|
|
45174
45326
|
} finally {
|
|
45175
|
-
|
|
45327
|
+
fs19.closeSync(fd);
|
|
45176
45328
|
}
|
|
45177
45329
|
const rawLines = text.split("\n");
|
|
45178
45330
|
if (start > 0 && rawLines.length > 0) rawLines.shift();
|
|
@@ -45190,12 +45342,12 @@ function readTailJsonlLines(filePath, maxBytes) {
|
|
|
45190
45342
|
|
|
45191
45343
|
// src/providers/spec/cli-adapter.ts
|
|
45192
45344
|
init_logger();
|
|
45193
|
-
import * as
|
|
45345
|
+
import * as fs20 from "fs";
|
|
45194
45346
|
function stripAnsi3(text) {
|
|
45195
45347
|
return String(text || "").replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
|
|
45196
45348
|
}
|
|
45197
45349
|
function delay(ms) {
|
|
45198
|
-
return new Promise((
|
|
45350
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
45199
45351
|
}
|
|
45200
45352
|
var SpecCliAdapter = class _SpecCliAdapter {
|
|
45201
45353
|
cliType;
|
|
@@ -45259,7 +45411,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
45259
45411
|
* hermes ships a runtime MCP override. */
|
|
45260
45412
|
spawnedEnv = {};
|
|
45261
45413
|
constructor(specPath, workingDir, cliArgs, extraEnv, transportFactory) {
|
|
45262
|
-
const raw = JSON.parse(
|
|
45414
|
+
const raw = JSON.parse(fs20.readFileSync(specPath, "utf8"));
|
|
45263
45415
|
this.spec = {
|
|
45264
45416
|
id: raw.id,
|
|
45265
45417
|
name: raw.name,
|
|
@@ -45411,7 +45563,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
45411
45563
|
const steps = buildClaudeInteractiveTuiAnswerSteps(prompt, response);
|
|
45412
45564
|
for (const step of steps) {
|
|
45413
45565
|
this.driver.dispatch({ kind: "pty_write", data: step });
|
|
45414
|
-
await new Promise((
|
|
45566
|
+
await new Promise((resolve26) => setTimeout(resolve26, 180));
|
|
45415
45567
|
}
|
|
45416
45568
|
} else {
|
|
45417
45569
|
this.driver.dispatch({ kind: "pty_write", data: `${buildClaudeInteractiveToolResult(response)}
|
|
@@ -45967,7 +46119,7 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
45967
46119
|
let screenText = this.driver.snapshot();
|
|
45968
46120
|
const deadline = Date.now() + _SpecCliAdapter.CLAUDE_TUI_PAGE_SETTLE_TIMEOUT_MS;
|
|
45969
46121
|
while (!detectClaudeTuiMultiSelect(screenText) && Date.now() < deadline) {
|
|
45970
|
-
await new Promise((
|
|
46122
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
45971
46123
|
screenText = this.driver.snapshot();
|
|
45972
46124
|
}
|
|
45973
46125
|
return screenText;
|
|
@@ -45976,12 +46128,12 @@ var SpecCliAdapter = class _SpecCliAdapter {
|
|
|
45976
46128
|
const pages = [{ screenText: firstScreen, header: headers[0] }];
|
|
45977
46129
|
for (let index = 1; index < headers.length; index += 1) {
|
|
45978
46130
|
this.driver.dispatch({ kind: "pty_write", data: " " });
|
|
45979
|
-
await new Promise((
|
|
46131
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
45980
46132
|
pages.push({ screenText: await this.snapshotSettledClaudeTuiPage(), header: headers[index] });
|
|
45981
46133
|
}
|
|
45982
46134
|
for (let index = headers.length - 1; index > 0; index -= 1) {
|
|
45983
46135
|
this.driver.dispatch({ kind: "pty_write", data: "\x1B[Z" });
|
|
45984
|
-
await new Promise((
|
|
46136
|
+
await new Promise((resolve26) => setTimeout(resolve26, _SpecCliAdapter.CLAUDE_TUI_PAGE_POLL_INTERVAL_MS));
|
|
45985
46137
|
const reread = await this.snapshotSettledClaudeTuiPage();
|
|
45986
46138
|
const landed = pages[index - 1];
|
|
45987
46139
|
if (landed && !detectClaudeTuiMultiSelect(landed.screenText) && detectClaudeTuiMultiSelect(reread)) {
|
|
@@ -46081,10 +46233,10 @@ init_logger();
|
|
|
46081
46233
|
function createCliAdapter(provider, workingDir, cliArgs, extraEnv, transportFactory) {
|
|
46082
46234
|
const resolvedSpecPath = provider._resolvedSpecPath;
|
|
46083
46235
|
const dir = provider._resolvedProviderDir;
|
|
46084
|
-
let specPath = resolvedSpecPath &&
|
|
46236
|
+
let specPath = resolvedSpecPath && fs21.existsSync(resolvedSpecPath) ? resolvedSpecPath : void 0;
|
|
46085
46237
|
if (!specPath && dir) {
|
|
46086
46238
|
const legacy = path25.join(dir, "spec.json");
|
|
46087
|
-
if (
|
|
46239
|
+
if (fs21.existsSync(legacy)) specPath = legacy;
|
|
46088
46240
|
}
|
|
46089
46241
|
if (specPath) {
|
|
46090
46242
|
try {
|
|
@@ -46169,7 +46321,7 @@ init_working_dir();
|
|
|
46169
46321
|
import * as os20 from "os";
|
|
46170
46322
|
import * as path26 from "path";
|
|
46171
46323
|
import * as crypto4 from "crypto";
|
|
46172
|
-
import * as
|
|
46324
|
+
import * as fs22 from "fs";
|
|
46173
46325
|
var IMAGE_MIME_EXTENSIONS = {
|
|
46174
46326
|
"image/png": ".png",
|
|
46175
46327
|
"image/jpeg": ".jpg",
|
|
@@ -46204,9 +46356,9 @@ function materializeImageDataPart(part, index, dir) {
|
|
|
46204
46356
|
if (!part.data) return null;
|
|
46205
46357
|
const rawData = part.data.includes(",") ? part.data.split(",").pop() || "" : part.data;
|
|
46206
46358
|
if (!rawData) return null;
|
|
46207
|
-
|
|
46359
|
+
fs22.mkdirSync(dir, { recursive: true });
|
|
46208
46360
|
const filePath = path26.join(dir, safeInputImageBasename(index, part.mimeType));
|
|
46209
|
-
|
|
46361
|
+
fs22.writeFileSync(filePath, Buffer.from(rawData, "base64"));
|
|
46210
46362
|
cleanupStaleMaterializedImages(dir);
|
|
46211
46363
|
return filePath;
|
|
46212
46364
|
}
|
|
@@ -46218,14 +46370,14 @@ function cleanupStaleMaterializedImages(dir) {
|
|
|
46218
46370
|
if (now - lastMaterializedImageCleanupAt < MATERIALIZED_IMAGE_CLEANUP_INTERVAL_MS) return;
|
|
46219
46371
|
lastMaterializedImageCleanupAt = now;
|
|
46220
46372
|
try {
|
|
46221
|
-
const entries =
|
|
46373
|
+
const entries = fs22.readdirSync(dir);
|
|
46222
46374
|
for (const entry of entries) {
|
|
46223
46375
|
if (!entry.startsWith("adhdev-input-image-")) continue;
|
|
46224
46376
|
const fullPath = path26.join(dir, entry);
|
|
46225
46377
|
try {
|
|
46226
|
-
const stat2 =
|
|
46378
|
+
const stat2 = fs22.statSync(fullPath);
|
|
46227
46379
|
if (now - stat2.mtimeMs > MATERIALIZED_IMAGE_MAX_AGE_MS) {
|
|
46228
|
-
|
|
46380
|
+
fs22.unlinkSync(fullPath);
|
|
46229
46381
|
}
|
|
46230
46382
|
} catch {
|
|
46231
46383
|
}
|
|
@@ -46372,7 +46524,7 @@ async function waitForCliAdapterReady(adapter, options) {
|
|
|
46372
46524
|
if (status === "stopped") {
|
|
46373
46525
|
throw new Error("CLI runtime stopped before it became ready");
|
|
46374
46526
|
}
|
|
46375
|
-
await new Promise((
|
|
46527
|
+
await new Promise((resolve26) => setTimeout(resolve26, pollMs));
|
|
46376
46528
|
}
|
|
46377
46529
|
throw new Error(`CLI runtime did not become ready within ${timeoutMs}ms`);
|
|
46378
46530
|
}
|
|
@@ -46886,7 +47038,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
46886
47038
|
const resolvedDbPath = probe.dbPath.replace(/^~/, os21.homedir());
|
|
46887
47039
|
const now = Date.now();
|
|
46888
47040
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
46889
|
-
if (!
|
|
47041
|
+
if (!fs23.existsSync(resolvedDbPath)) {
|
|
46890
47042
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
46891
47043
|
return null;
|
|
46892
47044
|
}
|
|
@@ -47470,7 +47622,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47470
47622
|
const enterCount = cliCommand.enterCount || 1;
|
|
47471
47623
|
await this.adapter.writeRaw(cliCommand.text + "\r");
|
|
47472
47624
|
for (let i = 1; i < enterCount; i += 1) {
|
|
47473
|
-
await new Promise((
|
|
47625
|
+
await new Promise((resolve26) => setTimeout(resolve26, 50));
|
|
47474
47626
|
await this.adapter.writeRaw("\r");
|
|
47475
47627
|
}
|
|
47476
47628
|
}
|
|
@@ -47564,7 +47716,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
47564
47716
|
}
|
|
47565
47717
|
if (this.lastExternalCompletionProbe?.sourcePath) {
|
|
47566
47718
|
try {
|
|
47567
|
-
|
|
47719
|
+
fs23.statSync(this.lastExternalCompletionProbe.sourcePath);
|
|
47568
47720
|
} catch {
|
|
47569
47721
|
}
|
|
47570
47722
|
}
|
|
@@ -49260,7 +49412,7 @@ ${buttons.join("\n")}`;
|
|
|
49260
49412
|
};
|
|
49261
49413
|
addDir(this.workingDir);
|
|
49262
49414
|
try {
|
|
49263
|
-
addDir(
|
|
49415
|
+
addDir(fs23.realpathSync.native(this.workingDir));
|
|
49264
49416
|
} catch {
|
|
49265
49417
|
}
|
|
49266
49418
|
return Array.from(dirs);
|
|
@@ -49935,13 +50087,13 @@ var AcpProviderInstance = class {
|
|
|
49935
50087
|
}
|
|
49936
50088
|
this.currentStatus = "waiting_approval";
|
|
49937
50089
|
this.detectStatusTransition();
|
|
49938
|
-
const approved = await new Promise((
|
|
49939
|
-
this.permissionResolvers.push(
|
|
50090
|
+
const approved = await new Promise((resolve26) => {
|
|
50091
|
+
this.permissionResolvers.push(resolve26);
|
|
49940
50092
|
setTimeout(() => {
|
|
49941
|
-
const idx = this.permissionResolvers.indexOf(
|
|
50093
|
+
const idx = this.permissionResolvers.indexOf(resolve26);
|
|
49942
50094
|
if (idx >= 0) {
|
|
49943
50095
|
this.permissionResolvers.splice(idx, 1);
|
|
49944
|
-
|
|
50096
|
+
resolve26(false);
|
|
49945
50097
|
}
|
|
49946
50098
|
}, 3e5);
|
|
49947
50099
|
});
|
|
@@ -50677,7 +50829,7 @@ async function waitForZeroMessageStartingLaunch(adapter) {
|
|
|
50677
50829
|
} catch {
|
|
50678
50830
|
return false;
|
|
50679
50831
|
}
|
|
50680
|
-
await new Promise((
|
|
50832
|
+
await new Promise((resolve26) => setTimeout(resolve26, ZERO_MESSAGE_STARTING_SEND_WAIT_MS));
|
|
50681
50833
|
try {
|
|
50682
50834
|
return hasZeroMessageStartingLaunch(adapter);
|
|
50683
50835
|
} catch {
|
|
@@ -51992,7 +52144,7 @@ import * as os27 from "os";
|
|
|
51992
52144
|
import * as path37 from "path";
|
|
51993
52145
|
|
|
51994
52146
|
// src/providers/provider-loader.ts
|
|
51995
|
-
import * as
|
|
52147
|
+
import * as fs29 from "fs";
|
|
51996
52148
|
import * as path36 from "path";
|
|
51997
52149
|
import * as os26 from "os";
|
|
51998
52150
|
import * as chokidar from "chokidar";
|
|
@@ -52392,12 +52544,12 @@ function validateControl(control, errors) {
|
|
|
52392
52544
|
init_external_sources();
|
|
52393
52545
|
|
|
52394
52546
|
// src/providers/native-history/dispatcher.ts
|
|
52395
|
-
import * as
|
|
52547
|
+
import * as fs28 from "fs";
|
|
52396
52548
|
import * as os25 from "os";
|
|
52397
52549
|
import * as path34 from "path";
|
|
52398
52550
|
|
|
52399
52551
|
// src/providers/native-history/claude-cli-transcript.ts
|
|
52400
|
-
import * as
|
|
52552
|
+
import * as fs24 from "fs";
|
|
52401
52553
|
import * as path30 from "path";
|
|
52402
52554
|
function extractTimestampValue(value) {
|
|
52403
52555
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
@@ -52411,7 +52563,7 @@ function extractTimestampValue(value) {
|
|
|
52411
52563
|
}
|
|
52412
52564
|
function statMtimeMs(filePath) {
|
|
52413
52565
|
try {
|
|
52414
|
-
return
|
|
52566
|
+
return fs24.statSync(filePath).mtimeMs;
|
|
52415
52567
|
} catch {
|
|
52416
52568
|
return 0;
|
|
52417
52569
|
}
|
|
@@ -52481,7 +52633,7 @@ function extractUserContentParts(content) {
|
|
|
52481
52633
|
function parseTranscriptFile(filePath, sessionId, workspaceFallback) {
|
|
52482
52634
|
let raw;
|
|
52483
52635
|
try {
|
|
52484
|
-
raw =
|
|
52636
|
+
raw = fs24.readFileSync(filePath, "utf-8");
|
|
52485
52637
|
} catch {
|
|
52486
52638
|
return [];
|
|
52487
52639
|
}
|
|
@@ -52557,7 +52709,7 @@ function readSession(sessionPath) {
|
|
|
52557
52709
|
if (!sessionPath || !path30.isAbsolute(sessionPath)) return null;
|
|
52558
52710
|
const basename14 = path30.basename(sessionPath, ".jsonl");
|
|
52559
52711
|
if (!isSafeSessionId(basename14)) return null;
|
|
52560
|
-
if (!
|
|
52712
|
+
if (!fs24.existsSync(sessionPath)) return null;
|
|
52561
52713
|
const sourceMtimeMs = statMtimeMs(sessionPath);
|
|
52562
52714
|
const messages = parseTranscriptFile(sessionPath, basename14);
|
|
52563
52715
|
if (messages.length === 0) return null;
|
|
@@ -52575,7 +52727,7 @@ function readSession(sessionPath) {
|
|
|
52575
52727
|
}
|
|
52576
52728
|
|
|
52577
52729
|
// src/providers/native-history/codex-cli-transcript.ts
|
|
52578
|
-
import * as
|
|
52730
|
+
import * as fs25 from "fs";
|
|
52579
52731
|
import * as path31 from "path";
|
|
52580
52732
|
function extractTimestampValue2(value) {
|
|
52581
52733
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
@@ -52589,7 +52741,7 @@ function extractTimestampValue2(value) {
|
|
|
52589
52741
|
}
|
|
52590
52742
|
function statMtimeMs2(filePath) {
|
|
52591
52743
|
try {
|
|
52592
|
-
return
|
|
52744
|
+
return fs25.statSync(filePath).mtimeMs;
|
|
52593
52745
|
} catch {
|
|
52594
52746
|
return 0;
|
|
52595
52747
|
}
|
|
@@ -52686,7 +52838,7 @@ function pushAssistantStandardMessage(records, sessionId, receivedAt, content, w
|
|
|
52686
52838
|
}
|
|
52687
52839
|
function readSessionMeta(filePath) {
|
|
52688
52840
|
try {
|
|
52689
|
-
const firstLine =
|
|
52841
|
+
const firstLine = fs25.readFileSync(filePath, "utf-8").split("\n").find(Boolean);
|
|
52690
52842
|
if (!firstLine) return null;
|
|
52691
52843
|
const parsed = JSON.parse(firstLine);
|
|
52692
52844
|
if (String(parsed.type ?? "") !== "session_meta") return null;
|
|
@@ -52698,7 +52850,7 @@ function readSessionMeta(filePath) {
|
|
|
52698
52850
|
function parseSessionFile(filePath, sessionId, workspaceFallback) {
|
|
52699
52851
|
let raw;
|
|
52700
52852
|
try {
|
|
52701
|
-
raw =
|
|
52853
|
+
raw = fs25.readFileSync(filePath, "utf-8");
|
|
52702
52854
|
} catch {
|
|
52703
52855
|
return [];
|
|
52704
52856
|
}
|
|
@@ -52814,7 +52966,7 @@ function parseSessionFile(filePath, sessionId, workspaceFallback) {
|
|
|
52814
52966
|
}
|
|
52815
52967
|
function readSession2(sessionPath) {
|
|
52816
52968
|
if (!sessionPath || !path31.isAbsolute(sessionPath)) return null;
|
|
52817
|
-
if (!
|
|
52969
|
+
if (!fs25.existsSync(sessionPath)) return null;
|
|
52818
52970
|
const meta = readSessionMeta(sessionPath);
|
|
52819
52971
|
const metaId = String(meta?.id ?? "").trim();
|
|
52820
52972
|
const basename14 = path31.basename(sessionPath, ".jsonl");
|
|
@@ -52843,7 +52995,7 @@ function readSession2(sessionPath) {
|
|
|
52843
52995
|
// src/providers/native-history/antigravity-cli-transcript.ts
|
|
52844
52996
|
init_load_better_sqlite3();
|
|
52845
52997
|
init_logger();
|
|
52846
|
-
import * as
|
|
52998
|
+
import * as fs26 from "fs";
|
|
52847
52999
|
import * as path32 from "path";
|
|
52848
53000
|
import * as os23 from "os";
|
|
52849
53001
|
function extractTimestampValue3(value) {
|
|
@@ -52858,7 +53010,7 @@ function extractTimestampValue3(value) {
|
|
|
52858
53010
|
}
|
|
52859
53011
|
function statMtimeMs3(filePath) {
|
|
52860
53012
|
try {
|
|
52861
|
-
return
|
|
53013
|
+
return fs26.statSync(filePath).mtimeMs;
|
|
52862
53014
|
} catch {
|
|
52863
53015
|
return 0;
|
|
52864
53016
|
}
|
|
@@ -52887,12 +53039,12 @@ function resolvePathInside(root, ...segments) {
|
|
|
52887
53039
|
function findBrainTranscriptPath(sessionId) {
|
|
52888
53040
|
if (!isUuidLike(sessionId)) return null;
|
|
52889
53041
|
const logsRoot = resolvePathInside(brainRoot(), sessionId, ".system_generated", "logs");
|
|
52890
|
-
if (!logsRoot || !
|
|
52891
|
-
const candidates = ["transcript_full.jsonl", "transcript.jsonl"].map((file) => resolvePathInside(logsRoot, file)).filter((p) => p !== null &&
|
|
53042
|
+
if (!logsRoot || !fs26.existsSync(logsRoot)) return null;
|
|
53043
|
+
const candidates = ["transcript_full.jsonl", "transcript.jsonl"].map((file) => resolvePathInside(logsRoot, file)).filter((p) => p !== null && fs26.existsSync(p));
|
|
52892
53044
|
if (candidates.length === 0) {
|
|
52893
53045
|
let entries = [];
|
|
52894
53046
|
try {
|
|
52895
|
-
entries =
|
|
53047
|
+
entries = fs26.readdirSync(logsRoot, { withFileTypes: true });
|
|
52896
53048
|
} catch {
|
|
52897
53049
|
return null;
|
|
52898
53050
|
}
|
|
@@ -52918,7 +53070,7 @@ function antigravityRowKind(rowType) {
|
|
|
52918
53070
|
function parseBrainTranscript(filePath, sessionId, workspace) {
|
|
52919
53071
|
let raw;
|
|
52920
53072
|
try {
|
|
52921
|
-
raw =
|
|
53073
|
+
raw = fs26.readFileSync(filePath, "utf-8");
|
|
52922
53074
|
} catch {
|
|
52923
53075
|
return null;
|
|
52924
53076
|
}
|
|
@@ -52978,7 +53130,7 @@ function readHistoryRows() {
|
|
|
52978
53130
|
const sourcePath = historyJsonlPath();
|
|
52979
53131
|
let lines = [];
|
|
52980
53132
|
try {
|
|
52981
|
-
lines =
|
|
53133
|
+
lines = fs26.readFileSync(sourcePath, "utf-8").split("\n").filter(Boolean);
|
|
52982
53134
|
} catch {
|
|
52983
53135
|
return [];
|
|
52984
53136
|
}
|
|
@@ -53026,7 +53178,7 @@ function extractStringsFromBuffer(buf) {
|
|
|
53026
53178
|
function parsePbFile(filePath, sessionId) {
|
|
53027
53179
|
let buf;
|
|
53028
53180
|
try {
|
|
53029
|
-
buf =
|
|
53181
|
+
buf = fs26.readFileSync(filePath);
|
|
53030
53182
|
} catch {
|
|
53031
53183
|
return null;
|
|
53032
53184
|
}
|
|
@@ -53374,7 +53526,7 @@ function readAntigravitySiblingFallback(sessionId, workspace) {
|
|
|
53374
53526
|
}
|
|
53375
53527
|
}
|
|
53376
53528
|
const pbPath = resolvePathInside(conversationsRoot(), `${sessionId}.pb`);
|
|
53377
|
-
if (pbPath &&
|
|
53529
|
+
if (pbPath && fs26.existsSync(pbPath)) {
|
|
53378
53530
|
const pbMessages = parsePbFile(pbPath, sessionId);
|
|
53379
53531
|
if (pbMessages && pbMessages.length > 0) {
|
|
53380
53532
|
return {
|
|
@@ -53393,7 +53545,7 @@ function readAntigravitySiblingFallback(sessionId, workspace) {
|
|
|
53393
53545
|
}
|
|
53394
53546
|
function readSession3(sessionPath, sessionId, workspace) {
|
|
53395
53547
|
if (!sessionPath || !path32.isAbsolute(sessionPath)) return null;
|
|
53396
|
-
if (!
|
|
53548
|
+
if (!fs26.existsSync(sessionPath)) return null;
|
|
53397
53549
|
const sourceMtimeMs = statMtimeMs3(sessionPath);
|
|
53398
53550
|
const brainRootPath = brainRoot();
|
|
53399
53551
|
if (sessionPath.startsWith(brainRootPath + path32.sep) && sessionPath.endsWith(".jsonl")) {
|
|
@@ -53455,20 +53607,20 @@ function readSession3(sessionPath, sessionId, workspace) {
|
|
|
53455
53607
|
|
|
53456
53608
|
// src/providers/native-history/hermes-cli-transcript.ts
|
|
53457
53609
|
init_load_better_sqlite3();
|
|
53458
|
-
import * as
|
|
53610
|
+
import * as fs27 from "fs";
|
|
53459
53611
|
import * as path33 from "path";
|
|
53460
53612
|
import * as os24 from "os";
|
|
53461
53613
|
var HERMES_STATE_DB = path33.join(os24.homedir(), ".hermes", "state.db");
|
|
53462
53614
|
var HERMES_LEGACY_SESSIONS_DIR = path33.join(os24.homedir(), ".hermes", "sessions");
|
|
53463
53615
|
function statMtimeMs4(p) {
|
|
53464
53616
|
try {
|
|
53465
|
-
return Math.floor(
|
|
53617
|
+
return Math.floor(fs27.statSync(p).mtimeMs);
|
|
53466
53618
|
} catch {
|
|
53467
53619
|
return 0;
|
|
53468
53620
|
}
|
|
53469
53621
|
}
|
|
53470
53622
|
function openDb() {
|
|
53471
|
-
if (!
|
|
53623
|
+
if (!fs27.existsSync(HERMES_STATE_DB)) return null;
|
|
53472
53624
|
try {
|
|
53473
53625
|
const Database = loadBetterSqlite3();
|
|
53474
53626
|
return new Database(HERMES_STATE_DB, { readonly: true, fileMustExist: true });
|
|
@@ -53564,10 +53716,10 @@ function readSession4(sessionPath, requestedSessionId) {
|
|
|
53564
53716
|
}
|
|
53565
53717
|
}
|
|
53566
53718
|
}
|
|
53567
|
-
if (!path33.isAbsolute(sessionPath) || !
|
|
53719
|
+
if (!path33.isAbsolute(sessionPath) || !fs27.existsSync(sessionPath)) return null;
|
|
53568
53720
|
let raw;
|
|
53569
53721
|
try {
|
|
53570
|
-
raw = JSON.parse(
|
|
53722
|
+
raw = JSON.parse(fs27.readFileSync(sessionPath, "utf8"));
|
|
53571
53723
|
} catch {
|
|
53572
53724
|
return null;
|
|
53573
53725
|
}
|
|
@@ -53622,7 +53774,7 @@ function createNativeHistoryDispatcher(reader) {
|
|
|
53622
53774
|
const ownerConfirmed = reader === "antigravity-cli" ? resolved?.ownerConfirmed === true : void 0;
|
|
53623
53775
|
if (input.forceRefresh === true || input.args?.forceRefresh === true) {
|
|
53624
53776
|
try {
|
|
53625
|
-
|
|
53777
|
+
fs28.statSync(sourcePath);
|
|
53626
53778
|
} catch {
|
|
53627
53779
|
}
|
|
53628
53780
|
}
|
|
@@ -53674,10 +53826,10 @@ function resolveSourcePath(reader, workspace, sessionId, sessionStartedAtMs, ins
|
|
|
53674
53826
|
}
|
|
53675
53827
|
function resolveClaudePath(workspace, sessionId) {
|
|
53676
53828
|
const dir = path34.join(os25.homedir(), ".claude", "projects", cwdAsDashes(workspace));
|
|
53677
|
-
if (!
|
|
53829
|
+
if (!fs28.existsSync(dir)) return null;
|
|
53678
53830
|
if (sessionId) {
|
|
53679
53831
|
const candidate = path34.join(dir, `${sessionId}.jsonl`);
|
|
53680
|
-
if (
|
|
53832
|
+
if (fs28.existsSync(candidate)) return candidate;
|
|
53681
53833
|
}
|
|
53682
53834
|
return null;
|
|
53683
53835
|
}
|
|
@@ -53689,7 +53841,7 @@ function resolveCodexPath(workspace, sessionId, sessionStartedAtMs) {
|
|
|
53689
53841
|
return findCodexPathByRuntime(root, workspace, sessionStartedAtMs);
|
|
53690
53842
|
}
|
|
53691
53843
|
function findCodexPathBySessionId(root, sessionId) {
|
|
53692
|
-
if (!
|
|
53844
|
+
if (!fs28.existsSync(root)) return null;
|
|
53693
53845
|
const needle = sessionId.toLowerCase();
|
|
53694
53846
|
const matches = [];
|
|
53695
53847
|
const stack = [root];
|
|
@@ -53697,7 +53849,7 @@ function findCodexPathBySessionId(root, sessionId) {
|
|
|
53697
53849
|
const current = stack.pop();
|
|
53698
53850
|
let entries = [];
|
|
53699
53851
|
try {
|
|
53700
|
-
entries =
|
|
53852
|
+
entries = fs28.readdirSync(current, { withFileTypes: true });
|
|
53701
53853
|
} catch {
|
|
53702
53854
|
continue;
|
|
53703
53855
|
}
|
|
@@ -53717,7 +53869,7 @@ function findCodexPathBySessionId(root, sessionId) {
|
|
|
53717
53869
|
return matches[0]?.p ?? null;
|
|
53718
53870
|
}
|
|
53719
53871
|
function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
53720
|
-
if (!
|
|
53872
|
+
if (!fs28.existsSync(root) || !workspace) return null;
|
|
53721
53873
|
const workspaceResolved = resolveRealPath(workspace);
|
|
53722
53874
|
const cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
53723
53875
|
const matches = [];
|
|
@@ -53726,7 +53878,7 @@ function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
|
53726
53878
|
const current = stack.pop();
|
|
53727
53879
|
let entries = [];
|
|
53728
53880
|
try {
|
|
53729
|
-
entries =
|
|
53881
|
+
entries = fs28.readdirSync(current, { withFileTypes: true });
|
|
53730
53882
|
} catch {
|
|
53731
53883
|
continue;
|
|
53732
53884
|
}
|
|
@@ -53751,10 +53903,10 @@ function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
|
53751
53903
|
}
|
|
53752
53904
|
function readCodexSessionMeta(filePath) {
|
|
53753
53905
|
try {
|
|
53754
|
-
const fd =
|
|
53906
|
+
const fd = fs28.openSync(filePath, "r");
|
|
53755
53907
|
try {
|
|
53756
53908
|
const buffer = Buffer.alloc(8192);
|
|
53757
|
-
const bytes =
|
|
53909
|
+
const bytes = fs28.readSync(fd, buffer, 0, buffer.length, 0);
|
|
53758
53910
|
if (bytes <= 0) return null;
|
|
53759
53911
|
const text = buffer.subarray(0, bytes).toString("utf8");
|
|
53760
53912
|
const firstLine = text.slice(0, text.indexOf("\n") >= 0 ? text.indexOf("\n") : text.length).trim();
|
|
@@ -53769,7 +53921,7 @@ function readCodexSessionMeta(filePath) {
|
|
|
53769
53921
|
timestampMs: Number.isFinite(timestampMs) ? timestampMs : void 0
|
|
53770
53922
|
};
|
|
53771
53923
|
} finally {
|
|
53772
|
-
|
|
53924
|
+
fs28.closeSync(fd);
|
|
53773
53925
|
}
|
|
53774
53926
|
} catch {
|
|
53775
53927
|
return null;
|
|
@@ -53777,7 +53929,7 @@ function readCodexSessionMeta(filePath) {
|
|
|
53777
53929
|
}
|
|
53778
53930
|
function resolveRealPath(value) {
|
|
53779
53931
|
try {
|
|
53780
|
-
return
|
|
53932
|
+
return fs28.realpathSync(value);
|
|
53781
53933
|
} catch {
|
|
53782
53934
|
return value;
|
|
53783
53935
|
}
|
|
@@ -53799,19 +53951,19 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
|
|
|
53799
53951
|
const owner = antigravityOwnerToken(workspace, sessionStartedAtMs, instanceId);
|
|
53800
53952
|
if (sessionId && isUuidLikeSessionId2(sessionId)) {
|
|
53801
53953
|
const dbPath = path34.join(agyRoot, "conversations", `${sessionId}.db`);
|
|
53802
|
-
if (
|
|
53954
|
+
if (fs28.existsSync(dbPath)) {
|
|
53803
53955
|
if (owner) claimAntigravityConversation(sessionId, owner);
|
|
53804
53956
|
return { path: dbPath, ownerConfirmed: true };
|
|
53805
53957
|
}
|
|
53806
53958
|
}
|
|
53807
53959
|
const brainRoot2 = path34.join(agyRoot, "brain");
|
|
53808
|
-
if (
|
|
53960
|
+
if (fs28.existsSync(brainRoot2)) {
|
|
53809
53961
|
const cutoff = spawnAwareCutoff(sessionStartedAtMs);
|
|
53810
53962
|
const nonEmptyBrain = (uuid, p) => {
|
|
53811
53963
|
const t = path34.join(p, ".system_generated", "logs", "transcript.jsonl");
|
|
53812
|
-
return
|
|
53964
|
+
return fs28.existsSync(t) && safeSize(t) > 0 ? t : null;
|
|
53813
53965
|
};
|
|
53814
|
-
const all =
|
|
53966
|
+
const all = fs28.readdirSync(brainRoot2, { withFileTypes: true }).filter((e) => e.isDirectory() && isUuidLikeSessionId2(e.name)).filter((e) => !isAntigravityConversationClaimedByOther(e.name, owner)).map((e) => {
|
|
53815
53967
|
const p = path34.join(brainRoot2, e.name);
|
|
53816
53968
|
return { uuid: e.name, p, mtime: safeMtime(p), birth: safeBirthtime(p) };
|
|
53817
53969
|
}).filter((e) => e.mtime >= cutoff);
|
|
@@ -53842,7 +53994,7 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
|
|
|
53842
53994
|
function pickUnboundConversationDb(convRoot, sessionFloorMs, owner) {
|
|
53843
53995
|
let entries = [];
|
|
53844
53996
|
try {
|
|
53845
|
-
entries =
|
|
53997
|
+
entries = fs28.readdirSync(convRoot, { withFileTypes: true });
|
|
53846
53998
|
} catch {
|
|
53847
53999
|
return null;
|
|
53848
54000
|
}
|
|
@@ -53880,9 +54032,9 @@ function resolveHermesPath(workspace, sessionId) {
|
|
|
53880
54032
|
void workspace;
|
|
53881
54033
|
void sessionId;
|
|
53882
54034
|
const dbPath = path34.join(os25.homedir(), ".hermes", "state.db");
|
|
53883
|
-
if (
|
|
54035
|
+
if (fs28.existsSync(dbPath)) return dbPath;
|
|
53884
54036
|
const dir = path34.join(os25.homedir(), ".hermes", "sessions");
|
|
53885
|
-
if (!
|
|
54037
|
+
if (!fs28.existsSync(dir)) return null;
|
|
53886
54038
|
return newestRecentFile2(dir, /^session_.*\.json$/);
|
|
53887
54039
|
}
|
|
53888
54040
|
function readByReader(reader, sourcePath, sessionId, workspace, requestedProviderSid) {
|
|
@@ -53919,7 +54071,7 @@ var RECENT_WINDOW_MS = 5 * 60 * 1e3;
|
|
|
53919
54071
|
function newestRecentFile2(dir, pattern) {
|
|
53920
54072
|
try {
|
|
53921
54073
|
const cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
53922
|
-
const entries =
|
|
54074
|
+
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);
|
|
53923
54075
|
return entries[0]?.p ?? null;
|
|
53924
54076
|
} catch {
|
|
53925
54077
|
return null;
|
|
@@ -53927,14 +54079,14 @@ function newestRecentFile2(dir, pattern) {
|
|
|
53927
54079
|
}
|
|
53928
54080
|
function safeMtime(p) {
|
|
53929
54081
|
try {
|
|
53930
|
-
return Math.floor(
|
|
54082
|
+
return Math.floor(fs28.statSync(p).mtimeMs);
|
|
53931
54083
|
} catch {
|
|
53932
54084
|
return 0;
|
|
53933
54085
|
}
|
|
53934
54086
|
}
|
|
53935
54087
|
function safeBirthtime(p) {
|
|
53936
54088
|
try {
|
|
53937
|
-
const st =
|
|
54089
|
+
const st = fs28.statSync(p);
|
|
53938
54090
|
const birth = Math.floor(st.birthtimeMs);
|
|
53939
54091
|
return birth > 0 ? birth : Math.floor(st.mtimeMs);
|
|
53940
54092
|
} catch {
|
|
@@ -53943,7 +54095,7 @@ function safeBirthtime(p) {
|
|
|
53943
54095
|
}
|
|
53944
54096
|
function safeSize(p) {
|
|
53945
54097
|
try {
|
|
53946
|
-
return
|
|
54098
|
+
return fs28.statSync(p).size;
|
|
53947
54099
|
} catch {
|
|
53948
54100
|
return 0;
|
|
53949
54101
|
}
|
|
@@ -54037,9 +54189,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54037
54189
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
54038
54190
|
static looksLikeProviderRoot(candidate) {
|
|
54039
54191
|
try {
|
|
54040
|
-
if (!
|
|
54192
|
+
if (!fs29.existsSync(candidate) || !fs29.statSync(candidate).isDirectory()) return false;
|
|
54041
54193
|
return ["ide", "extension", "cli", "acp"].some(
|
|
54042
|
-
(category) =>
|
|
54194
|
+
(category) => fs29.existsSync(path36.join(candidate, category))
|
|
54043
54195
|
);
|
|
54044
54196
|
} catch {
|
|
54045
54197
|
return false;
|
|
@@ -54047,7 +54199,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54047
54199
|
}
|
|
54048
54200
|
static hasProviderRootMarker(candidate) {
|
|
54049
54201
|
try {
|
|
54050
|
-
return
|
|
54202
|
+
return fs29.existsSync(path36.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
54051
54203
|
} catch {
|
|
54052
54204
|
return false;
|
|
54053
54205
|
}
|
|
@@ -54112,12 +54264,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54112
54264
|
const home = os26.homedir();
|
|
54113
54265
|
const oldDir = path36.join(home, ".adhdev", "marketplace");
|
|
54114
54266
|
const newDir = path36.join(home, ".adhdev", "external");
|
|
54115
|
-
if (!
|
|
54116
|
-
if (
|
|
54267
|
+
if (!fs29.existsSync(oldDir)) return;
|
|
54268
|
+
if (fs29.existsSync(newDir)) {
|
|
54117
54269
|
this.log(`Migration skipped: both ~/.adhdev/marketplace and ~/.adhdev/external exist (marketplace dir is now inert and can be removed manually).`);
|
|
54118
54270
|
return;
|
|
54119
54271
|
}
|
|
54120
|
-
|
|
54272
|
+
fs29.renameSync(oldDir, newDir);
|
|
54121
54273
|
this.log(`Migrated ~/.adhdev/marketplace \u2192 ~/.adhdev/external (one-time rename after provider source-layer cleanup).`);
|
|
54122
54274
|
} catch (e) {
|
|
54123
54275
|
this.log(`Marketplace\u2192external migration failed: ${e?.message || e}`);
|
|
@@ -54232,7 +54384,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54232
54384
|
this.providers.clear();
|
|
54233
54385
|
this.providerAvailability.clear();
|
|
54234
54386
|
let upstreamCount = 0;
|
|
54235
|
-
if (!this.disableUpstream &&
|
|
54387
|
+
if (!this.disableUpstream && fs29.existsSync(this.upstreamDir)) {
|
|
54236
54388
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
54237
54389
|
if (upstreamCount > 0) {
|
|
54238
54390
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -54241,10 +54393,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54241
54393
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
54242
54394
|
}
|
|
54243
54395
|
const externalDir = path36.join(os26.homedir(), ".adhdev", "external");
|
|
54244
|
-
if (
|
|
54396
|
+
if (fs29.existsSync(externalDir)) {
|
|
54245
54397
|
const rootEntries = (() => {
|
|
54246
54398
|
try {
|
|
54247
|
-
return
|
|
54399
|
+
return fs29.readdirSync(externalDir, { withFileTypes: true });
|
|
54248
54400
|
} catch {
|
|
54249
54401
|
return [];
|
|
54250
54402
|
}
|
|
@@ -54293,7 +54445,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54293
54445
|
}
|
|
54294
54446
|
}
|
|
54295
54447
|
}
|
|
54296
|
-
if (
|
|
54448
|
+
if (fs29.existsSync(this.userDir)) {
|
|
54297
54449
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
54298
54450
|
if (userCount > 0) {
|
|
54299
54451
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -54308,10 +54460,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54308
54460
|
* Check if upstream directory exists and has providers.
|
|
54309
54461
|
*/
|
|
54310
54462
|
hasUpstream() {
|
|
54311
|
-
if (!
|
|
54463
|
+
if (!fs29.existsSync(this.upstreamDir)) return false;
|
|
54312
54464
|
try {
|
|
54313
|
-
return
|
|
54314
|
-
(d) =>
|
|
54465
|
+
return fs29.readdirSync(this.upstreamDir).some(
|
|
54466
|
+
(d) => fs29.statSync(path36.join(this.upstreamDir, d)).isDirectory()
|
|
54315
54467
|
);
|
|
54316
54468
|
} catch {
|
|
54317
54469
|
return false;
|
|
@@ -54810,7 +54962,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54810
54962
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
54811
54963
|
if (providerDir) {
|
|
54812
54964
|
const fullDir = path36.join(providerDir, entry.scriptDir);
|
|
54813
|
-
resolved._resolvedScriptsPath =
|
|
54965
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
54814
54966
|
}
|
|
54815
54967
|
matched = true;
|
|
54816
54968
|
}
|
|
@@ -54829,7 +54981,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54829
54981
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
54830
54982
|
if (providerDir) {
|
|
54831
54983
|
const fullDir = path36.join(providerDir, base.defaultScriptDir);
|
|
54832
|
-
resolved._resolvedScriptsPath =
|
|
54984
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
54833
54985
|
}
|
|
54834
54986
|
}
|
|
54835
54987
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -54847,7 +54999,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54847
54999
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
54848
55000
|
if (providerDir) {
|
|
54849
55001
|
const fullDir = path36.join(providerDir, dirOverride);
|
|
54850
|
-
resolved._resolvedScriptsPath =
|
|
55002
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
54851
55003
|
}
|
|
54852
55004
|
}
|
|
54853
55005
|
} else if (override.scripts) {
|
|
@@ -54864,7 +55016,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54864
55016
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
54865
55017
|
if (providerDir) {
|
|
54866
55018
|
const fullDir = path36.join(providerDir, base.defaultScriptDir);
|
|
54867
|
-
resolved._resolvedScriptsPath =
|
|
55019
|
+
resolved._resolvedScriptsPath = fs29.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
54868
55020
|
}
|
|
54869
55021
|
}
|
|
54870
55022
|
}
|
|
@@ -54882,7 +55034,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54882
55034
|
for (const [scriptName, override] of Object.entries(base.overrides)) {
|
|
54883
55035
|
if (!override || typeof override.path !== "string") continue;
|
|
54884
55036
|
const fullPath = path36.join(providerDir2, override.path);
|
|
54885
|
-
if (!
|
|
55037
|
+
if (!fs29.existsSync(fullPath)) {
|
|
54886
55038
|
this.log(` [overrides] ${base.type}: ${scriptName} path not found: ${fullPath}`);
|
|
54887
55039
|
continue;
|
|
54888
55040
|
}
|
|
@@ -54912,7 +55064,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54912
55064
|
}
|
|
54913
55065
|
if (providerDir) {
|
|
54914
55066
|
try {
|
|
54915
|
-
const
|
|
55067
|
+
const fs43 = __require("fs");
|
|
54916
55068
|
const path45 = __require("path");
|
|
54917
55069
|
const candidates = [];
|
|
54918
55070
|
if (Array.isArray(base.compatibility)) {
|
|
@@ -54924,13 +55076,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54924
55076
|
}
|
|
54925
55077
|
candidates.push(path45.join(providerDir, "specs", "default.json"));
|
|
54926
55078
|
candidates.push(path45.join(providerDir, "spec.json"));
|
|
54927
|
-
const specPath = candidates.find((p) =>
|
|
55079
|
+
const specPath = candidates.find((p) => fs43.existsSync(p));
|
|
54928
55080
|
let nh;
|
|
54929
55081
|
if (specPath) {
|
|
54930
55082
|
resolved._resolvedSpecPath = specPath;
|
|
54931
55083
|
let specControls;
|
|
54932
55084
|
try {
|
|
54933
|
-
const rawSpec = JSON.parse(
|
|
55085
|
+
const rawSpec = JSON.parse(fs43.readFileSync(specPath, "utf8"));
|
|
54934
55086
|
specControls = rawSpec.control_bar;
|
|
54935
55087
|
nh = rawSpec.native_history;
|
|
54936
55088
|
} catch {
|
|
@@ -54969,7 +55121,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
54969
55121
|
reader = (input) => executeNativeHistory(nh, input);
|
|
54970
55122
|
} else if (nh.override_path) {
|
|
54971
55123
|
const overrideFile = path45.resolve(providerDir, nh.override_path);
|
|
54972
|
-
if (
|
|
55124
|
+
if (fs43.existsSync(overrideFile)) {
|
|
54973
55125
|
try {
|
|
54974
55126
|
registerProviderScriptRootSafely(path45.dirname(path45.dirname(providerDir)));
|
|
54975
55127
|
delete __require.cache[__require.resolve(overrideFile)];
|
|
@@ -55014,7 +55166,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55014
55166
|
return null;
|
|
55015
55167
|
}
|
|
55016
55168
|
const dir = path36.join(providerDir, scriptDir);
|
|
55017
|
-
if (!
|
|
55169
|
+
if (!fs29.existsSync(dir)) {
|
|
55018
55170
|
this.debugLog(`[loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
55019
55171
|
return null;
|
|
55020
55172
|
}
|
|
@@ -55022,7 +55174,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55022
55174
|
const cached3 = this.scriptsCache.get(dir);
|
|
55023
55175
|
if (cached3) return cached3;
|
|
55024
55176
|
const scriptsJs = path36.join(dir, "scripts.js");
|
|
55025
|
-
if (
|
|
55177
|
+
if (fs29.existsSync(scriptsJs)) {
|
|
55026
55178
|
try {
|
|
55027
55179
|
delete __require.cache[__require.resolve(scriptsJs)];
|
|
55028
55180
|
const loaded = __require(scriptsJs);
|
|
@@ -55043,9 +55195,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55043
55195
|
watch() {
|
|
55044
55196
|
this.stopWatch();
|
|
55045
55197
|
const watchDir = (dir) => {
|
|
55046
|
-
if (!
|
|
55198
|
+
if (!fs29.existsSync(dir)) {
|
|
55047
55199
|
try {
|
|
55048
|
-
|
|
55200
|
+
fs29.mkdirSync(dir, { recursive: true });
|
|
55049
55201
|
} catch {
|
|
55050
55202
|
return;
|
|
55051
55203
|
}
|
|
@@ -55137,14 +55289,14 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55137
55289
|
const regMetaPath = path36.join(this.upstreamDir, _ProviderLoader.REGISTRY_META_FILE);
|
|
55138
55290
|
let cachedChecksums = {};
|
|
55139
55291
|
try {
|
|
55140
|
-
if (
|
|
55141
|
-
cachedChecksums = JSON.parse(
|
|
55292
|
+
if (fs29.existsSync(regMetaPath)) {
|
|
55293
|
+
cachedChecksums = JSON.parse(fs29.readFileSync(regMetaPath, "utf-8")).checksums ?? {};
|
|
55142
55294
|
}
|
|
55143
55295
|
} catch {
|
|
55144
55296
|
}
|
|
55145
55297
|
try {
|
|
55146
55298
|
const listUrl = `${this.registryBaseUrl}/providers`;
|
|
55147
|
-
const listBody = await new Promise((
|
|
55299
|
+
const listBody = await new Promise((resolve26, reject) => {
|
|
55148
55300
|
const req = https.get(listUrl, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 1e4 }, (res) => {
|
|
55149
55301
|
if (res.statusCode !== 200) {
|
|
55150
55302
|
reject(new Error(`registry list HTTP ${res.statusCode}`));
|
|
@@ -55152,7 +55304,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55152
55304
|
}
|
|
55153
55305
|
const chunks = [];
|
|
55154
55306
|
res.on("data", (c) => chunks.push(c));
|
|
55155
|
-
res.on("end", () =>
|
|
55307
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
55156
55308
|
});
|
|
55157
55309
|
req.on("error", reject);
|
|
55158
55310
|
req.on("timeout", () => {
|
|
@@ -55168,7 +55320,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55168
55320
|
const cacheKey = `${category}/${type}`;
|
|
55169
55321
|
if (cachedChecksums[cacheKey] === checksum) continue;
|
|
55170
55322
|
const dlUrl = `${this.registryBaseUrl}/providers/${type}/${version}/download`;
|
|
55171
|
-
const manifestBody = await new Promise((
|
|
55323
|
+
const manifestBody = await new Promise((resolve26, reject) => {
|
|
55172
55324
|
const req = https.get(dlUrl, { headers: { "User-Agent": "adhdev-daemon", "Accept": "application/json" }, timeout: 3e4 }, (res) => {
|
|
55173
55325
|
if (res.statusCode !== 200) {
|
|
55174
55326
|
reject(new Error(`registry download HTTP ${res.statusCode} for ${type}@${version}`));
|
|
@@ -55176,7 +55328,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55176
55328
|
}
|
|
55177
55329
|
const chunks = [];
|
|
55178
55330
|
res.on("data", (c) => chunks.push(c));
|
|
55179
|
-
res.on("end", () =>
|
|
55331
|
+
res.on("end", () => resolve26(Buffer.concat(chunks).toString("utf-8")));
|
|
55180
55332
|
});
|
|
55181
55333
|
req.on("error", reject);
|
|
55182
55334
|
req.on("timeout", () => {
|
|
@@ -55190,14 +55342,14 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55190
55342
|
continue;
|
|
55191
55343
|
}
|
|
55192
55344
|
const providerDir = path36.join(this.upstreamDir, category, type);
|
|
55193
|
-
|
|
55194
|
-
|
|
55345
|
+
fs29.mkdirSync(providerDir, { recursive: true });
|
|
55346
|
+
fs29.writeFileSync(path36.join(providerDir, "provider.json"), manifestBody, "utf-8");
|
|
55195
55347
|
cachedChecksums[cacheKey] = checksum;
|
|
55196
55348
|
updatedCount++;
|
|
55197
55349
|
this.log(`\u2713 Registry updated: ${category}/${type}@${version}`);
|
|
55198
55350
|
}
|
|
55199
|
-
|
|
55200
|
-
|
|
55351
|
+
fs29.mkdirSync(this.upstreamDir, { recursive: true });
|
|
55352
|
+
fs29.writeFileSync(regMetaPath, JSON.stringify({
|
|
55201
55353
|
checksums: cachedChecksums,
|
|
55202
55354
|
syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
55203
55355
|
providerCount: list.providers.length
|
|
@@ -55222,8 +55374,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55222
55374
|
let prevEtag = "";
|
|
55223
55375
|
let prevTimestamp = 0;
|
|
55224
55376
|
try {
|
|
55225
|
-
if (
|
|
55226
|
-
const meta = JSON.parse(
|
|
55377
|
+
if (fs29.existsSync(metaPath)) {
|
|
55378
|
+
const meta = JSON.parse(fs29.readFileSync(metaPath, "utf-8"));
|
|
55227
55379
|
prevEtag = meta.etag || "";
|
|
55228
55380
|
prevTimestamp = meta.timestamp || 0;
|
|
55229
55381
|
}
|
|
@@ -55236,7 +55388,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55236
55388
|
}
|
|
55237
55389
|
const tarballTarget = resolveProviderTarballTarget(this.providerTarballUrl);
|
|
55238
55390
|
try {
|
|
55239
|
-
const etag = await new Promise((
|
|
55391
|
+
const etag = await new Promise((resolve26, reject) => {
|
|
55240
55392
|
const options = {
|
|
55241
55393
|
method: "HEAD",
|
|
55242
55394
|
hostname: tarballTarget.hostname,
|
|
@@ -55254,7 +55406,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55254
55406
|
headers: { "User-Agent": "adhdev-launcher" },
|
|
55255
55407
|
timeout: 1e4
|
|
55256
55408
|
}, (res2) => {
|
|
55257
|
-
|
|
55409
|
+
resolve26(res2.headers.etag || res2.headers["last-modified"] || "");
|
|
55258
55410
|
});
|
|
55259
55411
|
req2.on("error", reject);
|
|
55260
55412
|
req2.on("timeout", () => {
|
|
@@ -55263,7 +55415,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55263
55415
|
});
|
|
55264
55416
|
req2.end();
|
|
55265
55417
|
} else {
|
|
55266
|
-
|
|
55418
|
+
resolve26(res.headers.etag || res.headers["last-modified"] || "");
|
|
55267
55419
|
}
|
|
55268
55420
|
});
|
|
55269
55421
|
req.on("error", reject);
|
|
@@ -55282,36 +55434,36 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55282
55434
|
const tmpTar = path36.join(os26.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
55283
55435
|
const tmpExtract = path36.join(os26.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
55284
55436
|
await this.downloadFile(tarballTarget.url, tmpTar);
|
|
55285
|
-
|
|
55437
|
+
fs29.mkdirSync(tmpExtract, { recursive: true });
|
|
55286
55438
|
await execAsync5(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
55287
|
-
const extracted =
|
|
55439
|
+
const extracted = fs29.readdirSync(tmpExtract);
|
|
55288
55440
|
const rootDir = extracted.find(
|
|
55289
|
-
(d) =>
|
|
55441
|
+
(d) => fs29.statSync(path36.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
55290
55442
|
);
|
|
55291
55443
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
55292
55444
|
const sourceDir = path36.join(tmpExtract, rootDir);
|
|
55293
55445
|
const backupDir = this.upstreamDir + ".bak";
|
|
55294
|
-
if (
|
|
55295
|
-
if (
|
|
55296
|
-
|
|
55446
|
+
if (fs29.existsSync(this.upstreamDir)) {
|
|
55447
|
+
if (fs29.existsSync(backupDir)) fs29.rmSync(backupDir, { recursive: true, force: true });
|
|
55448
|
+
fs29.renameSync(this.upstreamDir, backupDir);
|
|
55297
55449
|
}
|
|
55298
55450
|
try {
|
|
55299
55451
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
55300
55452
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
55301
|
-
if (
|
|
55453
|
+
if (fs29.existsSync(backupDir)) fs29.rmSync(backupDir, { recursive: true, force: true });
|
|
55302
55454
|
} catch (e) {
|
|
55303
|
-
if (
|
|
55304
|
-
if (
|
|
55305
|
-
|
|
55455
|
+
if (fs29.existsSync(backupDir)) {
|
|
55456
|
+
if (fs29.existsSync(this.upstreamDir)) fs29.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
55457
|
+
fs29.renameSync(backupDir, this.upstreamDir);
|
|
55306
55458
|
}
|
|
55307
55459
|
throw e;
|
|
55308
55460
|
}
|
|
55309
55461
|
try {
|
|
55310
|
-
|
|
55462
|
+
fs29.rmSync(tmpTar, { force: true });
|
|
55311
55463
|
} catch {
|
|
55312
55464
|
}
|
|
55313
55465
|
try {
|
|
55314
|
-
|
|
55466
|
+
fs29.rmSync(tmpExtract, { recursive: true, force: true });
|
|
55315
55467
|
} catch {
|
|
55316
55468
|
}
|
|
55317
55469
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -55327,7 +55479,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55327
55479
|
downloadFile(url, destPath) {
|
|
55328
55480
|
const https = __require("https");
|
|
55329
55481
|
const http3 = __require("http");
|
|
55330
|
-
return new Promise((
|
|
55482
|
+
return new Promise((resolve26, reject) => {
|
|
55331
55483
|
const doRequest = (reqUrl, redirectCount = 0) => {
|
|
55332
55484
|
if (redirectCount > 5) {
|
|
55333
55485
|
reject(new Error("Too many redirects"));
|
|
@@ -55343,11 +55495,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55343
55495
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
55344
55496
|
return;
|
|
55345
55497
|
}
|
|
55346
|
-
const ws =
|
|
55498
|
+
const ws = fs29.createWriteStream(destPath);
|
|
55347
55499
|
res.pipe(ws);
|
|
55348
55500
|
ws.on("finish", () => {
|
|
55349
55501
|
ws.close();
|
|
55350
|
-
|
|
55502
|
+
resolve26();
|
|
55351
55503
|
});
|
|
55352
55504
|
ws.on("error", reject);
|
|
55353
55505
|
});
|
|
@@ -55362,22 +55514,22 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55362
55514
|
}
|
|
55363
55515
|
/** Recursive directory copy */
|
|
55364
55516
|
copyDirRecursive(src, dest) {
|
|
55365
|
-
|
|
55366
|
-
for (const entry of
|
|
55517
|
+
fs29.mkdirSync(dest, { recursive: true });
|
|
55518
|
+
for (const entry of fs29.readdirSync(src, { withFileTypes: true })) {
|
|
55367
55519
|
const srcPath = path36.join(src, entry.name);
|
|
55368
55520
|
const destPath = path36.join(dest, entry.name);
|
|
55369
55521
|
if (entry.isDirectory()) {
|
|
55370
55522
|
this.copyDirRecursive(srcPath, destPath);
|
|
55371
55523
|
} else {
|
|
55372
|
-
|
|
55524
|
+
fs29.copyFileSync(srcPath, destPath);
|
|
55373
55525
|
}
|
|
55374
55526
|
}
|
|
55375
55527
|
}
|
|
55376
55528
|
/** .meta.json save */
|
|
55377
55529
|
writeMeta(metaPath, etag, timestamp) {
|
|
55378
55530
|
try {
|
|
55379
|
-
|
|
55380
|
-
|
|
55531
|
+
fs29.mkdirSync(path36.dirname(metaPath), { recursive: true });
|
|
55532
|
+
fs29.writeFileSync(metaPath, JSON.stringify({
|
|
55381
55533
|
etag,
|
|
55382
55534
|
timestamp,
|
|
55383
55535
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -55388,11 +55540,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55388
55540
|
}
|
|
55389
55541
|
/** Count provider files (provider.v1.json or provider.json — at most one per dir). */
|
|
55390
55542
|
countProviders(dir) {
|
|
55391
|
-
if (!
|
|
55543
|
+
if (!fs29.existsSync(dir)) return 0;
|
|
55392
55544
|
let count = 0;
|
|
55393
55545
|
const scan = (d) => {
|
|
55394
55546
|
try {
|
|
55395
|
-
const entries =
|
|
55547
|
+
const entries = fs29.readdirSync(d, { withFileTypes: true });
|
|
55396
55548
|
const hasManifest = entries.some((e) => e.name === "provider.v1.json" || e.name === "provider.json");
|
|
55397
55549
|
if (hasManifest) count++;
|
|
55398
55550
|
for (const entry of entries) {
|
|
@@ -55622,13 +55774,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55622
55774
|
if (!provider) return null;
|
|
55623
55775
|
const cat = provider.category;
|
|
55624
55776
|
const searchRoots = this.getProviderRoots();
|
|
55625
|
-
const hasManifest = (dir) =>
|
|
55777
|
+
const hasManifest = (dir) => fs29.existsSync(path36.join(dir, "provider.v1.json")) || fs29.existsSync(path36.join(dir, "provider.json"));
|
|
55626
55778
|
const readManifestType = (dir) => {
|
|
55627
55779
|
for (const file of ["provider.v1.json", "provider.json"]) {
|
|
55628
55780
|
const p = path36.join(dir, file);
|
|
55629
|
-
if (!
|
|
55781
|
+
if (!fs29.existsSync(p)) continue;
|
|
55630
55782
|
try {
|
|
55631
|
-
const data = JSON.parse(
|
|
55783
|
+
const data = JSON.parse(fs29.readFileSync(p, "utf-8"));
|
|
55632
55784
|
if (typeof data?.type === "string") return data.type;
|
|
55633
55785
|
} catch {
|
|
55634
55786
|
}
|
|
@@ -55636,13 +55788,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55636
55788
|
return null;
|
|
55637
55789
|
};
|
|
55638
55790
|
for (const root of searchRoots) {
|
|
55639
|
-
if (!
|
|
55791
|
+
if (!fs29.existsSync(root)) continue;
|
|
55640
55792
|
const candidate = this.getProviderDir(root, cat, type);
|
|
55641
55793
|
if (hasManifest(candidate)) return candidate;
|
|
55642
55794
|
const catDir = path36.join(root, cat);
|
|
55643
|
-
if (
|
|
55795
|
+
if (fs29.existsSync(catDir)) {
|
|
55644
55796
|
try {
|
|
55645
|
-
for (const entry of
|
|
55797
|
+
for (const entry of fs29.readdirSync(catDir, { withFileTypes: true })) {
|
|
55646
55798
|
if (!entry.isDirectory()) continue;
|
|
55647
55799
|
const entryDir = path36.join(catDir, entry.name);
|
|
55648
55800
|
const manifestType = readManifestType(entryDir);
|
|
@@ -55661,7 +55813,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55661
55813
|
*/
|
|
55662
55814
|
buildScriptWrappersFromDir(dir) {
|
|
55663
55815
|
const scriptsJs = path36.join(dir, "scripts.js");
|
|
55664
|
-
if (
|
|
55816
|
+
if (fs29.existsSync(scriptsJs)) {
|
|
55665
55817
|
try {
|
|
55666
55818
|
delete __require.cache[__require.resolve(scriptsJs)];
|
|
55667
55819
|
return __require(scriptsJs);
|
|
@@ -55671,13 +55823,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55671
55823
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
55672
55824
|
const result = {};
|
|
55673
55825
|
try {
|
|
55674
|
-
for (const file of
|
|
55826
|
+
for (const file of fs29.readdirSync(dir)) {
|
|
55675
55827
|
if (!file.endsWith(".js")) continue;
|
|
55676
55828
|
const scriptName = toCamel(file.replace(".js", ""));
|
|
55677
55829
|
const filePath = path36.join(dir, file);
|
|
55678
55830
|
result[scriptName] = (...args) => {
|
|
55679
55831
|
try {
|
|
55680
|
-
let content =
|
|
55832
|
+
let content = fs29.readFileSync(filePath, "utf-8");
|
|
55681
55833
|
if (args[0] && typeof args[0] === "object") {
|
|
55682
55834
|
for (const [key2, val] of Object.entries(args[0])) {
|
|
55683
55835
|
let v = val;
|
|
@@ -55723,12 +55875,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55723
55875
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
55724
55876
|
*/
|
|
55725
55877
|
loadDir(dir, excludeDirs) {
|
|
55726
|
-
if (!
|
|
55878
|
+
if (!fs29.existsSync(dir)) return 0;
|
|
55727
55879
|
let count = 0;
|
|
55728
55880
|
const scan = (d) => {
|
|
55729
55881
|
let entries;
|
|
55730
55882
|
try {
|
|
55731
|
-
entries =
|
|
55883
|
+
entries = fs29.readdirSync(d, { withFileTypes: true });
|
|
55732
55884
|
} catch {
|
|
55733
55885
|
return;
|
|
55734
55886
|
}
|
|
@@ -55738,7 +55890,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
55738
55890
|
const manifestFile = hasV1 ? "provider.v1.json" : "provider.json";
|
|
55739
55891
|
const jsonPath = path36.join(d, manifestFile);
|
|
55740
55892
|
try {
|
|
55741
|
-
const raw =
|
|
55893
|
+
const raw = fs29.readFileSync(jsonPath, "utf-8");
|
|
55742
55894
|
const mod = JSON.parse(raw);
|
|
55743
55895
|
if (hasV1 && mod?.category === "cli") {
|
|
55744
55896
|
try {
|
|
@@ -55777,7 +55929,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
55777
55929
|
} else {
|
|
55778
55930
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
55779
55931
|
const scriptsPath = path36.join(d, "scripts.js");
|
|
55780
|
-
if (!hasCompatibility &&
|
|
55932
|
+
if (!hasCompatibility && fs29.existsSync(scriptsPath)) {
|
|
55781
55933
|
try {
|
|
55782
55934
|
registerProviderScriptRootSafely(path36.dirname(path36.dirname(d)));
|
|
55783
55935
|
delete __require.cache[__require.resolve(scriptsPath)];
|
|
@@ -55903,10 +56055,10 @@ function findMacAppProcessPids(psOutput, appPaths) {
|
|
|
55903
56055
|
|
|
55904
56056
|
// src/launch.ts
|
|
55905
56057
|
async function execQuiet(command, options = {}) {
|
|
55906
|
-
return new Promise((
|
|
56058
|
+
return new Promise((resolve26) => {
|
|
55907
56059
|
exec4(command, options, (error, stdout) => {
|
|
55908
|
-
if (error) return
|
|
55909
|
-
|
|
56060
|
+
if (error) return resolve26("");
|
|
56061
|
+
resolve26(stdout.toString());
|
|
55910
56062
|
});
|
|
55911
56063
|
});
|
|
55912
56064
|
}
|
|
@@ -55987,17 +56139,17 @@ async function findFreePort(ports) {
|
|
|
55987
56139
|
throw new Error("No free port found");
|
|
55988
56140
|
}
|
|
55989
56141
|
function checkPortFree(port) {
|
|
55990
|
-
return new Promise((
|
|
56142
|
+
return new Promise((resolve26) => {
|
|
55991
56143
|
const server = net.createServer();
|
|
55992
56144
|
server.unref();
|
|
55993
|
-
server.on("error", () =>
|
|
56145
|
+
server.on("error", () => resolve26(false));
|
|
55994
56146
|
server.listen(port, "127.0.0.1", () => {
|
|
55995
|
-
server.close(() =>
|
|
56147
|
+
server.close(() => resolve26(true));
|
|
55996
56148
|
});
|
|
55997
56149
|
});
|
|
55998
56150
|
}
|
|
55999
56151
|
async function isCdpActive(port) {
|
|
56000
|
-
return new Promise((
|
|
56152
|
+
return new Promise((resolve26) => {
|
|
56001
56153
|
const req = __require("http").get(`http://127.0.0.1:${port}/json/version`, {
|
|
56002
56154
|
timeout: 2e3
|
|
56003
56155
|
}, (res) => {
|
|
@@ -56006,16 +56158,16 @@ async function isCdpActive(port) {
|
|
|
56006
56158
|
res.on("end", () => {
|
|
56007
56159
|
try {
|
|
56008
56160
|
const info = JSON.parse(data);
|
|
56009
|
-
|
|
56161
|
+
resolve26(!!info["WebKit-Version"] || !!info["Browser"]);
|
|
56010
56162
|
} catch {
|
|
56011
|
-
|
|
56163
|
+
resolve26(false);
|
|
56012
56164
|
}
|
|
56013
56165
|
});
|
|
56014
56166
|
});
|
|
56015
|
-
req.on("error", () =>
|
|
56167
|
+
req.on("error", () => resolve26(false));
|
|
56016
56168
|
req.on("timeout", () => {
|
|
56017
56169
|
req.destroy();
|
|
56018
|
-
|
|
56170
|
+
resolve26(false);
|
|
56019
56171
|
});
|
|
56020
56172
|
});
|
|
56021
56173
|
}
|
|
@@ -56151,7 +56303,7 @@ async function detectCurrentWorkspace(ideId) {
|
|
|
56151
56303
|
}
|
|
56152
56304
|
} else if (plat === "win32") {
|
|
56153
56305
|
try {
|
|
56154
|
-
const
|
|
56306
|
+
const fs43 = __require("fs");
|
|
56155
56307
|
const appNameMap = getMacAppIdentifiers();
|
|
56156
56308
|
const appName = appNameMap[ideId];
|
|
56157
56309
|
if (appName) {
|
|
@@ -56160,8 +56312,8 @@ async function detectCurrentWorkspace(ideId) {
|
|
|
56160
56312
|
appName,
|
|
56161
56313
|
"storage.json"
|
|
56162
56314
|
);
|
|
56163
|
-
if (
|
|
56164
|
-
const data = JSON.parse(
|
|
56315
|
+
if (fs43.existsSync(storagePath)) {
|
|
56316
|
+
const data = JSON.parse(fs43.readFileSync(storagePath, "utf-8"));
|
|
56165
56317
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
56166
56318
|
if (workspaces.length > 0) {
|
|
56167
56319
|
const recent = workspaces[0];
|
|
@@ -56681,7 +56833,7 @@ var meshCrudHandlers = {
|
|
|
56681
56833
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
56682
56834
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
56683
56835
|
const { mkdirSync: mkdirSync22, writeFileSync: writeFileSync24 } = await import("fs");
|
|
56684
|
-
const { dirname:
|
|
56836
|
+
const { dirname: dirname18, join: join52 } = await import("path");
|
|
56685
56837
|
const scaffold = buildMeshJsonConfigScaffold2(mesh);
|
|
56686
56838
|
const scaffoldJson = serializeMeshJsonConfigScaffold2(scaffold);
|
|
56687
56839
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
@@ -56721,7 +56873,7 @@ var meshCrudHandlers = {
|
|
|
56721
56873
|
note: "Dry-run: nothing written. Re-run with write=true to persist to the repo (commit target). meshes.json is untouched."
|
|
56722
56874
|
};
|
|
56723
56875
|
}
|
|
56724
|
-
mkdirSync22(
|
|
56876
|
+
mkdirSync22(dirname18(absolutePath), { recursive: true });
|
|
56725
56877
|
writeFileSync24(absolutePath, `${scaffoldJson}
|
|
56726
56878
|
`, "utf-8");
|
|
56727
56879
|
return {
|
|
@@ -57260,7 +57412,7 @@ var meshCrudHandlers = {
|
|
|
57260
57412
|
const setupPromise = finishWorktreeSetup();
|
|
57261
57413
|
const setupResult = await Promise.race([
|
|
57262
57414
|
setupPromise.then((value) => ({ completed: true, value })),
|
|
57263
|
-
new Promise((
|
|
57415
|
+
new Promise((resolve26) => setTimeout(() => resolve26({ completed: false }), setupWaitMs))
|
|
57264
57416
|
]);
|
|
57265
57417
|
const emitBootstrapEvent = (eventStatus2, bootstrapState2, startedAtMs, extraPayload) => {
|
|
57266
57418
|
try {
|
|
@@ -57755,7 +57907,7 @@ init_worktree_bootstrap_config();
|
|
|
57755
57907
|
init_change_impact_config();
|
|
57756
57908
|
init_mesh_config();
|
|
57757
57909
|
import { existsSync as existsSync39, mkdirSync as mkdirSync15, writeFileSync as writeFileSync18 } from "fs";
|
|
57758
|
-
import { dirname as
|
|
57910
|
+
import { dirname as dirname12, join as join43 } from "path";
|
|
57759
57911
|
var MESH_INIT_REFINE_CONFIG_PATH = MESH_REFINE_CONFIG_LOCATIONS[0];
|
|
57760
57912
|
var MESH_INIT_WORKTREE_BOOTSTRAP_CONFIG_PATH = MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS[0];
|
|
57761
57913
|
var MESH_INIT_CHANGE_IMPACT_CONFIG_PATH = CHANGE_IMPACT_CONFIG_LOCATIONS[0];
|
|
@@ -57771,7 +57923,7 @@ var CANDIDATE_STALE_INPUTS = [
|
|
|
57771
57923
|
];
|
|
57772
57924
|
function writeConfigFile(workspace, relativePath, config) {
|
|
57773
57925
|
const target = join43(workspace, relativePath);
|
|
57774
|
-
mkdirSync15(
|
|
57926
|
+
mkdirSync15(dirname12(target), { recursive: true });
|
|
57775
57927
|
writeFileSync18(target, `${JSON.stringify(config, null, 2)}
|
|
57776
57928
|
`, "utf-8");
|
|
57777
57929
|
return target;
|
|
@@ -58149,7 +58301,7 @@ init_runtime_surface();
|
|
|
58149
58301
|
init_mesh_coordinator();
|
|
58150
58302
|
init_dist();
|
|
58151
58303
|
import { join as pathJoin } from "path";
|
|
58152
|
-
import * as
|
|
58304
|
+
import * as fs30 from "fs";
|
|
58153
58305
|
var meshCoordinatorLaunchHandlers = {
|
|
58154
58306
|
launch_mesh_coordinator: async (ctx, args) => {
|
|
58155
58307
|
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
@@ -58389,15 +58541,15 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58389
58541
|
}
|
|
58390
58542
|
if (cliType === "codex-cli") {
|
|
58391
58543
|
const repoMcpConfigPath = pathJoin(workspace, ".mcp.json");
|
|
58392
|
-
if (
|
|
58544
|
+
if (fs30.existsSync(repoMcpConfigPath)) {
|
|
58393
58545
|
try {
|
|
58394
58546
|
const repoMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
58395
|
-
|
|
58547
|
+
fs30.readFileSync(repoMcpConfigPath, "utf-8"),
|
|
58396
58548
|
"claude_mcp_json"
|
|
58397
58549
|
);
|
|
58398
58550
|
const existingServers2 = repoMcpConfig.mcpServers;
|
|
58399
58551
|
if (existingServers2 && typeof existingServers2 === "object" && !Array.isArray(existingServers2) && existingServers2[coordinatorSetup.serverName]) {
|
|
58400
|
-
|
|
58552
|
+
fs30.writeFileSync(repoMcpConfigPath, serializeMeshCoordinatorMcpConfig({
|
|
58401
58553
|
...repoMcpConfig,
|
|
58402
58554
|
mcpServers: {
|
|
58403
58555
|
...existingServers2,
|
|
@@ -58516,7 +58668,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58516
58668
|
};
|
|
58517
58669
|
}
|
|
58518
58670
|
const { existsSync: existsSync55, readFileSync: readFileSync42, writeFileSync: writeFileSync24, copyFileSync: copyFileSync4, mkdirSync: mkdirSync22 } = await import("fs");
|
|
58519
|
-
const { dirname:
|
|
58671
|
+
const { dirname: dirname18 } = await import("path");
|
|
58520
58672
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
58521
58673
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
58522
58674
|
let hermesBaseConfig = null;
|
|
@@ -58551,7 +58703,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58551
58703
|
};
|
|
58552
58704
|
}
|
|
58553
58705
|
try {
|
|
58554
|
-
mkdirSync22(
|
|
58706
|
+
mkdirSync22(dirname18(mcpConfigPath), { recursive: true });
|
|
58555
58707
|
} catch (error) {
|
|
58556
58708
|
const message = `Could not prepare MCP config path for automatic setup: ${error?.message || error}`;
|
|
58557
58709
|
LOG.error("MeshCoordinator", message);
|
|
@@ -58561,7 +58713,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58561
58713
|
const hadExistingMcpConfig = existsSync55(mcpConfigPath);
|
|
58562
58714
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
58563
58715
|
if (hermesBaseConfig) {
|
|
58564
|
-
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome,
|
|
58716
|
+
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname18(mcpConfigPath));
|
|
58565
58717
|
}
|
|
58566
58718
|
if (hadExistingMcpConfig) {
|
|
58567
58719
|
try {
|
|
@@ -58599,7 +58751,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
58599
58751
|
const cliArgs = [];
|
|
58600
58752
|
const launchEnv = {};
|
|
58601
58753
|
if (configFormat === "hermes_config_yaml") {
|
|
58602
|
-
launchEnv.HERMES_HOME =
|
|
58754
|
+
launchEnv.HERMES_HOME = dirname18(mcpConfigPath);
|
|
58603
58755
|
launchEnv.HERMES_IGNORE_USER_CONFIG = "";
|
|
58604
58756
|
}
|
|
58605
58757
|
let autoImportContextFilePath;
|
|
@@ -58690,13 +58842,13 @@ init_dist();
|
|
|
58690
58842
|
init_mesh_events();
|
|
58691
58843
|
init_mesh_routing();
|
|
58692
58844
|
init_mesh_host_ownership();
|
|
58693
|
-
import * as
|
|
58845
|
+
import * as fs31 from "fs";
|
|
58694
58846
|
import { hostname as osHostname } from "os";
|
|
58695
58847
|
|
|
58696
58848
|
// src/mesh/preview-freshness.ts
|
|
58697
58849
|
import { execFileSync as execFileSync6 } from "child_process";
|
|
58698
58850
|
import { existsSync as existsSync41, readFileSync as readFileSync31 } from "fs";
|
|
58699
|
-
import { resolve as
|
|
58851
|
+
import { resolve as resolve20 } from "path";
|
|
58700
58852
|
var PREVIEW_DEPLOY_RECORD = ".adhdev/preview-deploy.json";
|
|
58701
58853
|
var PREVIEW_PIPELINE_SCRIPTS = [
|
|
58702
58854
|
"scripts/preview-freshness.mjs",
|
|
@@ -58704,7 +58856,7 @@ var PREVIEW_PIPELINE_SCRIPTS = [
|
|
|
58704
58856
|
"scripts/deploy-preview-local.mjs"
|
|
58705
58857
|
];
|
|
58706
58858
|
function hasDeployPreviewNpmScript(repoRoot) {
|
|
58707
|
-
const pkgPath =
|
|
58859
|
+
const pkgPath = resolve20(repoRoot, "package.json");
|
|
58708
58860
|
if (!existsSync41(pkgPath)) return false;
|
|
58709
58861
|
try {
|
|
58710
58862
|
const pkg = JSON.parse(readFileSync31(pkgPath, "utf8"));
|
|
@@ -58714,8 +58866,8 @@ function hasDeployPreviewNpmScript(repoRoot) {
|
|
|
58714
58866
|
}
|
|
58715
58867
|
}
|
|
58716
58868
|
function isPreviewPipelineConfigured(repoRoot) {
|
|
58717
|
-
if (existsSync41(
|
|
58718
|
-
if (PREVIEW_PIPELINE_SCRIPTS.some((rel) => existsSync41(
|
|
58869
|
+
if (existsSync41(resolve20(repoRoot, PREVIEW_DEPLOY_RECORD))) return true;
|
|
58870
|
+
if (PREVIEW_PIPELINE_SCRIPTS.some((rel) => existsSync41(resolve20(repoRoot, rel)))) return true;
|
|
58719
58871
|
return hasDeployPreviewNpmScript(repoRoot);
|
|
58720
58872
|
}
|
|
58721
58873
|
function runGit2(repoRoot, args) {
|
|
@@ -58731,7 +58883,7 @@ function runGit2(repoRoot, args) {
|
|
|
58731
58883
|
}
|
|
58732
58884
|
}
|
|
58733
58885
|
function readRecord6(repoRoot) {
|
|
58734
|
-
const path45 =
|
|
58886
|
+
const path45 = resolve20(repoRoot, PREVIEW_DEPLOY_RECORD);
|
|
58735
58887
|
if (!existsSync41(path45)) return null;
|
|
58736
58888
|
try {
|
|
58737
58889
|
const parsed = JSON.parse(readFileSync31(path45, "utf8"));
|
|
@@ -59051,7 +59203,7 @@ var meshStatusHandlers = {
|
|
|
59051
59203
|
}
|
|
59052
59204
|
}
|
|
59053
59205
|
if (workspace) {
|
|
59054
|
-
if (!
|
|
59206
|
+
if (!fs31.existsSync(workspace)) {
|
|
59055
59207
|
const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
|
|
59056
59208
|
let remoteProbeApplied = false;
|
|
59057
59209
|
if (inlineTransitGit) {
|
|
@@ -59187,7 +59339,7 @@ var meshStatusHandlers = {
|
|
|
59187
59339
|
backstop: { ...getMeshV2BackstopCounters() }
|
|
59188
59340
|
};
|
|
59189
59341
|
const previewFreshness = (() => {
|
|
59190
|
-
const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate &&
|
|
59342
|
+
const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate && fs31.existsSync(candidate));
|
|
59191
59343
|
return localRepoRoot ? buildPreviewFreshness(localRepoRoot) : void 0;
|
|
59192
59344
|
})();
|
|
59193
59345
|
const asyncRefineJobs = buildMeshAsyncRefineJobs({
|
|
@@ -59387,7 +59539,7 @@ init_dist();
|
|
|
59387
59539
|
init_logger();
|
|
59388
59540
|
|
|
59389
59541
|
// src/logging/command-log.ts
|
|
59390
|
-
import * as
|
|
59542
|
+
import * as fs32 from "fs";
|
|
59391
59543
|
import * as path38 from "path";
|
|
59392
59544
|
import * as os28 from "os";
|
|
59393
59545
|
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");
|
|
@@ -59395,7 +59547,7 @@ var LOG_DIR2 = path38.join(ADHDEV_HOME2, "logs");
|
|
|
59395
59547
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
59396
59548
|
var MAX_DAYS = 7;
|
|
59397
59549
|
try {
|
|
59398
|
-
|
|
59550
|
+
fs32.mkdirSync(LOG_DIR2, { recursive: true });
|
|
59399
59551
|
} catch {
|
|
59400
59552
|
}
|
|
59401
59553
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -59441,7 +59593,7 @@ function checkRotation() {
|
|
|
59441
59593
|
}
|
|
59442
59594
|
function cleanOldFiles() {
|
|
59443
59595
|
try {
|
|
59444
|
-
const files =
|
|
59596
|
+
const files = fs32.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
59445
59597
|
const cutoff = /* @__PURE__ */ new Date();
|
|
59446
59598
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
59447
59599
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -59449,7 +59601,7 @@ function cleanOldFiles() {
|
|
|
59449
59601
|
const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
59450
59602
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
59451
59603
|
try {
|
|
59452
|
-
|
|
59604
|
+
fs32.unlinkSync(path38.join(LOG_DIR2, file));
|
|
59453
59605
|
} catch {
|
|
59454
59606
|
}
|
|
59455
59607
|
}
|
|
@@ -59459,14 +59611,14 @@ function cleanOldFiles() {
|
|
|
59459
59611
|
}
|
|
59460
59612
|
function checkSize() {
|
|
59461
59613
|
try {
|
|
59462
|
-
const stat2 =
|
|
59614
|
+
const stat2 = fs32.statSync(currentFile);
|
|
59463
59615
|
if (stat2.size > MAX_FILE_SIZE) {
|
|
59464
59616
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
59465
59617
|
try {
|
|
59466
|
-
|
|
59618
|
+
fs32.unlinkSync(backup);
|
|
59467
59619
|
} catch {
|
|
59468
59620
|
}
|
|
59469
|
-
|
|
59621
|
+
fs32.renameSync(currentFile, backup);
|
|
59470
59622
|
}
|
|
59471
59623
|
} catch {
|
|
59472
59624
|
}
|
|
@@ -59499,14 +59651,14 @@ function logCommand(entry) {
|
|
|
59499
59651
|
...entry.error ? { err: entry.error } : {},
|
|
59500
59652
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
59501
59653
|
});
|
|
59502
|
-
|
|
59654
|
+
fs32.appendFileSync(currentFile, line + "\n");
|
|
59503
59655
|
} catch {
|
|
59504
59656
|
}
|
|
59505
59657
|
}
|
|
59506
59658
|
function getRecentCommands(count = 50) {
|
|
59507
59659
|
try {
|
|
59508
|
-
if (!
|
|
59509
|
-
const content =
|
|
59660
|
+
if (!fs32.existsSync(currentFile)) return [];
|
|
59661
|
+
const content = fs32.readFileSync(currentFile, "utf-8");
|
|
59510
59662
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
59511
59663
|
return lines.slice(-count).map((line) => {
|
|
59512
59664
|
try {
|
|
@@ -59535,7 +59687,7 @@ cleanOldFiles();
|
|
|
59535
59687
|
init_debug_trace();
|
|
59536
59688
|
init_mesh_host_ownership();
|
|
59537
59689
|
init_mesh_node_identity();
|
|
59538
|
-
import * as
|
|
59690
|
+
import * as fs36 from "fs";
|
|
59539
59691
|
|
|
59540
59692
|
// src/commands/router-refine.ts
|
|
59541
59693
|
init_logger();
|
|
@@ -59646,7 +59798,7 @@ init_refine_config();
|
|
|
59646
59798
|
init_worktree_bootstrap_config();
|
|
59647
59799
|
init_resolve_executable();
|
|
59648
59800
|
import { basename as pathBasename, join as pathJoin2, resolve as pathResolve2 } from "path";
|
|
59649
|
-
import * as
|
|
59801
|
+
import * as fs33 from "fs";
|
|
59650
59802
|
import { execFileSync as execFileSync7 } from "child_process";
|
|
59651
59803
|
var GIT2 = process.platform === "win32" ? resolveWin32Executable("git") : "git";
|
|
59652
59804
|
var REFINE_VALIDATION_TIMEOUT_MS = 12e4;
|
|
@@ -60004,7 +60156,7 @@ function isSubmoduleFastForward(submoduleRepoPath, baseCommit, branchCommit) {
|
|
|
60004
60156
|
if (!baseCommit || !branchCommit) return false;
|
|
60005
60157
|
if (baseCommit === branchCommit) return true;
|
|
60006
60158
|
try {
|
|
60007
|
-
if (!
|
|
60159
|
+
if (!fs33.existsSync(submoduleRepoPath)) return false;
|
|
60008
60160
|
execFileSync7(GIT2, ["cat-file", "-e", `${baseCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
60009
60161
|
execFileSync7(GIT2, ["cat-file", "-e", `${branchCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
60010
60162
|
execFileSync7(GIT2, ["merge-base", "--is-ancestor", baseCommit, branchCommit], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
@@ -60121,7 +60273,7 @@ function buildTreeWithGitlinksEqualized(repoRoot, commitish, paths, placeholderC
|
|
|
60121
60273
|
return newTree || void 0;
|
|
60122
60274
|
} finally {
|
|
60123
60275
|
try {
|
|
60124
|
-
|
|
60276
|
+
fs33.rmSync(tmpIndex, { force: true });
|
|
60125
60277
|
} catch {
|
|
60126
60278
|
}
|
|
60127
60279
|
}
|
|
@@ -60196,7 +60348,7 @@ function synthesizeTrivialFastForwardMergeTree(repoRoot, baseHead, branchHead, g
|
|
|
60196
60348
|
return newTree || void 0;
|
|
60197
60349
|
} finally {
|
|
60198
60350
|
try {
|
|
60199
|
-
|
|
60351
|
+
fs33.rmSync(tmpIndex, { force: true });
|
|
60200
60352
|
} catch {
|
|
60201
60353
|
}
|
|
60202
60354
|
}
|
|
@@ -60308,7 +60460,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
60308
60460
|
return { stdout: String(stdout || ""), stderr: String(stderr || ""), refspec };
|
|
60309
60461
|
};
|
|
60310
60462
|
const importCommitFromWorktreeSubmodule = async (submodulePath, worktreeSubmodulePath, commit) => {
|
|
60311
|
-
if (!
|
|
60463
|
+
if (!fs33.existsSync(worktreeSubmodulePath)) return false;
|
|
60312
60464
|
try {
|
|
60313
60465
|
await runGit3(worktreeSubmodulePath, ["cat-file", "-e", `${commit}^{commit}`]);
|
|
60314
60466
|
} catch {
|
|
@@ -60332,7 +60484,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
60332
60484
|
};
|
|
60333
60485
|
let submoduleDefaultBranch = "main";
|
|
60334
60486
|
try {
|
|
60335
|
-
if (!
|
|
60487
|
+
if (!fs33.existsSync(submodulePath)) {
|
|
60336
60488
|
entry.error = `Submodule checkout missing at ${gitlink.path}`;
|
|
60337
60489
|
entry.publishRequired = true;
|
|
60338
60490
|
if (options.allowAutoPublishSubmoduleMainCommits === true) {
|
|
@@ -60577,9 +60729,9 @@ async function runMeshRefineValidationGate(mesh, workspace, opts) {
|
|
|
60577
60729
|
return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
|
|
60578
60730
|
};
|
|
60579
60731
|
const dependenciesLikelyMissing = (cwd) => {
|
|
60580
|
-
if (!
|
|
60581
|
-
if (
|
|
60582
|
-
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) =>
|
|
60732
|
+
if (!fs33.existsSync(pathJoin2(cwd, "package.json"))) return false;
|
|
60733
|
+
if (fs33.existsSync(pathJoin2(cwd, "node_modules"))) return false;
|
|
60734
|
+
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs33.existsSync(pathJoin2(cwd, lock)));
|
|
60583
60735
|
};
|
|
60584
60736
|
const needsNodeModules = (candidate, cwd) => isPackageManagerValidation(candidate) && dependenciesLikelyMissing(cwd);
|
|
60585
60737
|
const isDaemonScopedCommand = (candidate) => {
|
|
@@ -62478,7 +62630,7 @@ async function startMeshRefineJob(self, meshId, nodeId, args) {
|
|
|
62478
62630
|
init_logger();
|
|
62479
62631
|
init_dist();
|
|
62480
62632
|
init_mesh_node_identity();
|
|
62481
|
-
import * as
|
|
62633
|
+
import * as fs34 from "fs";
|
|
62482
62634
|
import { resolve as pathResolve3 } from "path";
|
|
62483
62635
|
init_runtime_surface();
|
|
62484
62636
|
init_repo_mesh_types();
|
|
@@ -62492,14 +62644,14 @@ function sessionMatchesMeshNode(self, record, node, nodeId, sessionIds) {
|
|
|
62492
62644
|
return false;
|
|
62493
62645
|
}
|
|
62494
62646
|
async function bestEffortRemoveWorktreeDir(self, dir) {
|
|
62495
|
-
if (!dir || !
|
|
62496
|
-
const sleep3 = (ms) => new Promise((
|
|
62647
|
+
if (!dir || !fs34.existsSync(dir)) return { removed: true, residue: false };
|
|
62648
|
+
const sleep3 = (ms) => new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
62497
62649
|
const ABSORB = /* @__PURE__ */ new Set(["EINVAL", "EPERM", "EBUSY", "ENOTEMPTY", "EACCES", "EMFILE", "ENFILE"]);
|
|
62498
62650
|
let lastErr;
|
|
62499
62651
|
for (let attempt = 0; attempt < 4; attempt++) {
|
|
62500
62652
|
try {
|
|
62501
|
-
|
|
62502
|
-
if (!
|
|
62653
|
+
fs34.rmSync(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
62654
|
+
if (!fs34.existsSync(dir)) return { removed: true, residue: false };
|
|
62503
62655
|
lastErr = new Error("directory still present after rmSync");
|
|
62504
62656
|
} catch (e) {
|
|
62505
62657
|
lastErr = e;
|
|
@@ -62510,7 +62662,7 @@ async function bestEffortRemoveWorktreeDir(self, dir) {
|
|
|
62510
62662
|
}
|
|
62511
62663
|
await sleep3(150 * (attempt + 1));
|
|
62512
62664
|
}
|
|
62513
|
-
return
|
|
62665
|
+
return fs34.existsSync(dir) ? { removed: false, residue: true, error: String(lastErr?.message || lastErr || "unknown rm error") } : { removed: true, residue: false };
|
|
62514
62666
|
}
|
|
62515
62667
|
async function precheckLocalWorktreeRemovable(self, args) {
|
|
62516
62668
|
const sessionPreservedNote = " The delegated session was left running (not stopped) \u2014 resolve the issue and retry mesh_remove_node.";
|
|
@@ -62523,10 +62675,10 @@ async function precheckLocalWorktreeRemovable(self, args) {
|
|
|
62523
62675
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains." + sessionPreservedNote
|
|
62524
62676
|
};
|
|
62525
62677
|
}
|
|
62526
|
-
if (!
|
|
62678
|
+
if (!fs34.existsSync(workspace)) return { ok: true };
|
|
62527
62679
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
62528
62680
|
const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
|
|
62529
|
-
if (!repoRoot || !
|
|
62681
|
+
if (!repoRoot || !fs34.existsSync(repoRoot)) {
|
|
62530
62682
|
return {
|
|
62531
62683
|
ok: false,
|
|
62532
62684
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -62546,7 +62698,7 @@ async function precheckLocalWorktreeRemovable(self, args) {
|
|
|
62546
62698
|
const normalizePath = (value) => {
|
|
62547
62699
|
const resolved = pathResolve3(value);
|
|
62548
62700
|
try {
|
|
62549
|
-
return
|
|
62701
|
+
return fs34.realpathSync(resolved);
|
|
62550
62702
|
} catch {
|
|
62551
62703
|
return resolved;
|
|
62552
62704
|
}
|
|
@@ -62608,13 +62760,13 @@ async function cleanupLocalWorktreeNode(self, args) {
|
|
|
62608
62760
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains."
|
|
62609
62761
|
};
|
|
62610
62762
|
}
|
|
62611
|
-
const worktreeExists =
|
|
62763
|
+
const worktreeExists = fs34.existsSync(workspace);
|
|
62612
62764
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
62613
62765
|
const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
|
|
62614
62766
|
if (!worktreeExists) {
|
|
62615
62767
|
return { success: true, skipped: true, removedPath: workspace, repoRoot: repoRoot || void 0, reason: "worktree_path_missing" };
|
|
62616
62768
|
}
|
|
62617
|
-
if (!repoRoot || !
|
|
62769
|
+
if (!repoRoot || !fs34.existsSync(repoRoot)) {
|
|
62618
62770
|
return {
|
|
62619
62771
|
success: false,
|
|
62620
62772
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -62634,7 +62786,7 @@ async function cleanupLocalWorktreeNode(self, args) {
|
|
|
62634
62786
|
const normalizePath = (value) => {
|
|
62635
62787
|
const resolved = pathResolve3(value);
|
|
62636
62788
|
try {
|
|
62637
|
-
return
|
|
62789
|
+
return fs34.realpathSync(resolved);
|
|
62638
62790
|
} catch {
|
|
62639
62791
|
return resolved;
|
|
62640
62792
|
}
|
|
@@ -63273,7 +63425,7 @@ init_logger();
|
|
|
63273
63425
|
import * as yaml5 from "js-yaml";
|
|
63274
63426
|
import { homedir as homedir26 } from "os";
|
|
63275
63427
|
import { join as pathJoin3, resolve as pathResolve4 } from "path";
|
|
63276
|
-
import * as
|
|
63428
|
+
import * as fs35 from "fs";
|
|
63277
63429
|
function loadYamlModule() {
|
|
63278
63430
|
return yaml5;
|
|
63279
63431
|
}
|
|
@@ -63297,9 +63449,9 @@ function resolveHermesUserHome() {
|
|
|
63297
63449
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
63298
63450
|
const sourceHome = resolveHermesUserHome();
|
|
63299
63451
|
const sourceConfigPath = pathJoin3(sourceHome, "config.yaml");
|
|
63300
|
-
if (!
|
|
63452
|
+
if (!fs35.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
63301
63453
|
if (pathResolve4(sourceConfigPath) === pathResolve4(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
63302
|
-
const parsed = parseMeshCoordinatorMcpConfig(
|
|
63454
|
+
const parsed = parseMeshCoordinatorMcpConfig(fs35.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
63303
63455
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
63304
63456
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
63305
63457
|
}
|
|
@@ -63336,9 +63488,9 @@ function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
|
63336
63488
|
for (const fileName of [".env", "auth.json"]) {
|
|
63337
63489
|
const sourcePath = pathJoin3(sourceHome, fileName);
|
|
63338
63490
|
const targetPath = pathJoin3(targetHome, fileName);
|
|
63339
|
-
if (!
|
|
63491
|
+
if (!fs35.existsSync(sourcePath)) continue;
|
|
63340
63492
|
try {
|
|
63341
|
-
|
|
63493
|
+
fs35.copyFileSync(sourcePath, targetPath);
|
|
63342
63494
|
} catch (error) {
|
|
63343
63495
|
LOG.warn("MeshCoordinator", `Could not copy Hermes ${fileName} into isolated coordinator home: ${error?.message || error}`);
|
|
63344
63496
|
}
|
|
@@ -63739,7 +63891,7 @@ var DaemonCommandRouter = class {
|
|
|
63739
63891
|
const nodeId = readInlineMeshNodeId(node);
|
|
63740
63892
|
if (!nodeId || !tombstones.has(nodeId)) return true;
|
|
63741
63893
|
const workspace = readStringValue(node?.workspace);
|
|
63742
|
-
if (workspace &&
|
|
63894
|
+
if (workspace && fs36.existsSync(workspace)) {
|
|
63743
63895
|
tombstones.delete(nodeId);
|
|
63744
63896
|
return true;
|
|
63745
63897
|
}
|
|
@@ -64552,7 +64704,7 @@ var ProviderStreamAdapter = class {
|
|
|
64552
64704
|
const beforeCount = this.messageCount(before);
|
|
64553
64705
|
const beforeSignature = this.lastMessageSignature(before);
|
|
64554
64706
|
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
64555
|
-
await new Promise((
|
|
64707
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
64556
64708
|
let state;
|
|
64557
64709
|
try {
|
|
64558
64710
|
state = await this.readChat(evaluate);
|
|
@@ -64574,7 +64726,7 @@ var ProviderStreamAdapter = class {
|
|
|
64574
64726
|
if (this.messageCount(first) > 0 || this.lastMessageSignature(first)) {
|
|
64575
64727
|
return first;
|
|
64576
64728
|
}
|
|
64577
|
-
await new Promise((
|
|
64729
|
+
await new Promise((resolve26) => setTimeout(resolve26, 150));
|
|
64578
64730
|
const second = await this.readChat(evaluate);
|
|
64579
64731
|
return this.messageCount(second) >= this.messageCount(first) ? second : first;
|
|
64580
64732
|
}
|
|
@@ -64725,7 +64877,7 @@ var ProviderStreamAdapter = class {
|
|
|
64725
64877
|
if (typeof data.error === "string" && data.error.trim()) return false;
|
|
64726
64878
|
}
|
|
64727
64879
|
for (let attempt = 0; attempt < 6; attempt += 1) {
|
|
64728
|
-
await new Promise((
|
|
64880
|
+
await new Promise((resolve26) => setTimeout(resolve26, 250));
|
|
64729
64881
|
const state = await this.readChat(evaluate);
|
|
64730
64882
|
const title = this.getStateTitle(state);
|
|
64731
64883
|
if (this.titlesMatch(title, sessionId)) return true;
|
|
@@ -65658,7 +65810,7 @@ init_io_contracts();
|
|
|
65658
65810
|
init_chat_message_normalization();
|
|
65659
65811
|
|
|
65660
65812
|
// src/providers/version-archive.ts
|
|
65661
|
-
import * as
|
|
65813
|
+
import * as fs37 from "fs";
|
|
65662
65814
|
import * as path39 from "path";
|
|
65663
65815
|
import * as os29 from "os";
|
|
65664
65816
|
import { platform as platform8 } from "os";
|
|
@@ -65672,8 +65824,8 @@ var VersionArchive = class {
|
|
|
65672
65824
|
}
|
|
65673
65825
|
load() {
|
|
65674
65826
|
try {
|
|
65675
|
-
if (
|
|
65676
|
-
this.history = JSON.parse(
|
|
65827
|
+
if (fs37.existsSync(ARCHIVE_PATH)) {
|
|
65828
|
+
this.history = JSON.parse(fs37.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
65677
65829
|
}
|
|
65678
65830
|
} catch {
|
|
65679
65831
|
this.history = {};
|
|
@@ -65710,20 +65862,20 @@ var VersionArchive = class {
|
|
|
65710
65862
|
}
|
|
65711
65863
|
save() {
|
|
65712
65864
|
try {
|
|
65713
|
-
|
|
65714
|
-
|
|
65865
|
+
fs37.mkdirSync(path39.dirname(ARCHIVE_PATH), { recursive: true });
|
|
65866
|
+
fs37.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
65715
65867
|
} catch {
|
|
65716
65868
|
}
|
|
65717
65869
|
}
|
|
65718
65870
|
};
|
|
65719
65871
|
async function runCommand(cmd, timeout = 1e4) {
|
|
65720
|
-
return new Promise((
|
|
65872
|
+
return new Promise((resolve26) => {
|
|
65721
65873
|
exec5(cmd, {
|
|
65722
65874
|
encoding: "utf-8",
|
|
65723
65875
|
timeout
|
|
65724
65876
|
}, (error, stdout) => {
|
|
65725
|
-
if (error) return
|
|
65726
|
-
|
|
65877
|
+
if (error) return resolve26(null);
|
|
65878
|
+
resolve26(stdout.trim());
|
|
65727
65879
|
});
|
|
65728
65880
|
});
|
|
65729
65881
|
}
|
|
@@ -65736,8 +65888,8 @@ function findBinary2(name) {
|
|
|
65736
65888
|
for (const ext of exes) {
|
|
65737
65889
|
const fullPath = path39.join(p, name + ext);
|
|
65738
65890
|
try {
|
|
65739
|
-
if (
|
|
65740
|
-
const stat2 =
|
|
65891
|
+
if (fs37.existsSync(fullPath)) {
|
|
65892
|
+
const stat2 = fs37.statSync(fullPath);
|
|
65741
65893
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
65742
65894
|
return fullPath;
|
|
65743
65895
|
}
|
|
@@ -65784,9 +65936,9 @@ function checkPathExists2(paths) {
|
|
|
65784
65936
|
if (p.includes("*")) {
|
|
65785
65937
|
const home = os29.homedir();
|
|
65786
65938
|
const resolved = p.replace(/\*/g, home.split(path39.sep).pop() || "");
|
|
65787
|
-
if (
|
|
65939
|
+
if (fs37.existsSync(resolved)) return resolved;
|
|
65788
65940
|
} else {
|
|
65789
|
-
if (
|
|
65941
|
+
if (fs37.existsSync(p)) return p;
|
|
65790
65942
|
}
|
|
65791
65943
|
}
|
|
65792
65944
|
return null;
|
|
@@ -65794,7 +65946,7 @@ function checkPathExists2(paths) {
|
|
|
65794
65946
|
async function getMacAppVersion(appPath) {
|
|
65795
65947
|
if (platform8() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
65796
65948
|
const plistPath = path39.join(appPath, "Contents", "Info.plist");
|
|
65797
|
-
if (!
|
|
65949
|
+
if (!fs37.existsSync(plistPath)) return null;
|
|
65798
65950
|
const raw = await runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
65799
65951
|
return raw || null;
|
|
65800
65952
|
}
|
|
@@ -65821,7 +65973,7 @@ async function detectAllVersions(loader, archive) {
|
|
|
65821
65973
|
let resolvedBin = cliBin;
|
|
65822
65974
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
65823
65975
|
const bundled = path39.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
65824
|
-
if (provider.cli &&
|
|
65976
|
+
if (provider.cli && fs37.existsSync(bundled)) resolvedBin = bundled;
|
|
65825
65977
|
}
|
|
65826
65978
|
info.installed = !!(appPath || resolvedBin);
|
|
65827
65979
|
info.path = appPath || null;
|
|
@@ -65869,7 +66021,7 @@ async function detectAllVersions(loader, archive) {
|
|
|
65869
66021
|
|
|
65870
66022
|
// src/daemon/dev-server.ts
|
|
65871
66023
|
import * as http2 from "http";
|
|
65872
|
-
import * as
|
|
66024
|
+
import * as fs41 from "fs";
|
|
65873
66025
|
import * as path43 from "path";
|
|
65874
66026
|
init_config();
|
|
65875
66027
|
|
|
@@ -66222,7 +66374,7 @@ init_builders();
|
|
|
66222
66374
|
|
|
66223
66375
|
// src/daemon/dev-cdp-handlers.ts
|
|
66224
66376
|
init_logger();
|
|
66225
|
-
import * as
|
|
66377
|
+
import * as fs38 from "fs";
|
|
66226
66378
|
import * as path40 from "path";
|
|
66227
66379
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
66228
66380
|
const body = await ctx.readBody(req);
|
|
@@ -66402,17 +66554,17 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
66402
66554
|
}
|
|
66403
66555
|
let scriptsPath = "";
|
|
66404
66556
|
const directScripts = path40.join(dir, "scripts.js");
|
|
66405
|
-
if (
|
|
66557
|
+
if (fs38.existsSync(directScripts)) {
|
|
66406
66558
|
scriptsPath = directScripts;
|
|
66407
66559
|
} else {
|
|
66408
66560
|
const scriptsDir = path40.join(dir, "scripts");
|
|
66409
|
-
if (
|
|
66410
|
-
const versions =
|
|
66411
|
-
return
|
|
66561
|
+
if (fs38.existsSync(scriptsDir)) {
|
|
66562
|
+
const versions = fs38.readdirSync(scriptsDir).filter((d) => {
|
|
66563
|
+
return fs38.statSync(path40.join(scriptsDir, d)).isDirectory();
|
|
66412
66564
|
}).sort().reverse();
|
|
66413
66565
|
for (const ver of versions) {
|
|
66414
66566
|
const p = path40.join(scriptsDir, ver, "scripts.js");
|
|
66415
|
-
if (
|
|
66567
|
+
if (fs38.existsSync(p)) {
|
|
66416
66568
|
scriptsPath = p;
|
|
66417
66569
|
break;
|
|
66418
66570
|
}
|
|
@@ -66424,7 +66576,7 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
66424
66576
|
return;
|
|
66425
66577
|
}
|
|
66426
66578
|
try {
|
|
66427
|
-
const source =
|
|
66579
|
+
const source = fs38.readFileSync(scriptsPath, "utf-8");
|
|
66428
66580
|
const hints = {};
|
|
66429
66581
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
66430
66582
|
let match;
|
|
@@ -67239,7 +67391,7 @@ async function handleDomContext(ctx, type, req, res) {
|
|
|
67239
67391
|
}
|
|
67240
67392
|
|
|
67241
67393
|
// src/daemon/dev-cli-debug.ts
|
|
67242
|
-
import * as
|
|
67394
|
+
import * as fs39 from "fs";
|
|
67243
67395
|
import * as path41 from "path";
|
|
67244
67396
|
function slugifyFixtureName(value) {
|
|
67245
67397
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
@@ -67255,10 +67407,10 @@ function getCliFixtureDir(ctx, type) {
|
|
|
67255
67407
|
function readCliFixture(ctx, type, name) {
|
|
67256
67408
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
67257
67409
|
const filePath = path41.join(fixtureDir, `${name}.json`);
|
|
67258
|
-
if (!
|
|
67410
|
+
if (!fs39.existsSync(filePath)) {
|
|
67259
67411
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
67260
67412
|
}
|
|
67261
|
-
return JSON.parse(
|
|
67413
|
+
return JSON.parse(fs39.readFileSync(filePath, "utf-8"));
|
|
67262
67414
|
}
|
|
67263
67415
|
function getExerciseTranscriptText(result) {
|
|
67264
67416
|
const parts = [];
|
|
@@ -67423,7 +67575,7 @@ function getCliTargetBundle(ctx, type, instanceId) {
|
|
|
67423
67575
|
return { target, instance, adapter };
|
|
67424
67576
|
}
|
|
67425
67577
|
function sleep2(ms) {
|
|
67426
|
-
return new Promise((
|
|
67578
|
+
return new Promise((resolve26) => setTimeout(resolve26, ms));
|
|
67427
67579
|
}
|
|
67428
67580
|
async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
|
|
67429
67581
|
const startedAt = Date.now();
|
|
@@ -68003,7 +68155,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68003
68155
|
return;
|
|
68004
68156
|
}
|
|
68005
68157
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
68006
|
-
|
|
68158
|
+
fs39.mkdirSync(fixtureDir, { recursive: true });
|
|
68007
68159
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
68008
68160
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
68009
68161
|
const fixture = {
|
|
@@ -68031,7 +68183,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68031
68183
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
68032
68184
|
};
|
|
68033
68185
|
const filePath = path41.join(fixtureDir, `${name}.json`);
|
|
68034
|
-
|
|
68186
|
+
fs39.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
68035
68187
|
ctx.json(res, 200, {
|
|
68036
68188
|
saved: true,
|
|
68037
68189
|
name,
|
|
@@ -68049,14 +68201,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
68049
68201
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
68050
68202
|
try {
|
|
68051
68203
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
68052
|
-
if (!
|
|
68204
|
+
if (!fs39.existsSync(fixtureDir)) {
|
|
68053
68205
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
68054
68206
|
return;
|
|
68055
68207
|
}
|
|
68056
|
-
const fixtures =
|
|
68208
|
+
const fixtures = fs39.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
|
|
68057
68209
|
const fullPath = path41.join(fixtureDir, file);
|
|
68058
68210
|
try {
|
|
68059
|
-
const raw = JSON.parse(
|
|
68211
|
+
const raw = JSON.parse(fs39.readFileSync(fullPath, "utf-8"));
|
|
68060
68212
|
return {
|
|
68061
68213
|
name: raw.name || file.replace(/\.json$/i, ""),
|
|
68062
68214
|
path: fullPath,
|
|
@@ -68189,7 +68341,7 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
68189
68341
|
}
|
|
68190
68342
|
|
|
68191
68343
|
// src/daemon/dev-auto-implement.ts
|
|
68192
|
-
import * as
|
|
68344
|
+
import * as fs40 from "fs";
|
|
68193
68345
|
import * as path42 from "path";
|
|
68194
68346
|
import * as os30 from "os";
|
|
68195
68347
|
import { DEFAULT_SESSION_HOST_COLS as DEFAULT_SESSION_HOST_COLS7, DEFAULT_SESSION_HOST_ROWS as DEFAULT_SESSION_HOST_ROWS7 } from "@adhdev/session-host-core";
|
|
@@ -68238,10 +68390,10 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
|
|
|
68238
68390
|
return fallback?.type || null;
|
|
68239
68391
|
}
|
|
68240
68392
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
68241
|
-
if (!
|
|
68242
|
-
const versions =
|
|
68393
|
+
if (!fs40.existsSync(scriptsDir)) return null;
|
|
68394
|
+
const versions = fs40.readdirSync(scriptsDir).filter((d) => {
|
|
68243
68395
|
try {
|
|
68244
|
-
return
|
|
68396
|
+
return fs40.statSync(path42.join(scriptsDir, d)).isDirectory();
|
|
68245
68397
|
} catch {
|
|
68246
68398
|
return false;
|
|
68247
68399
|
}
|
|
@@ -68263,13 +68415,13 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
68263
68415
|
if (!sourceDir) {
|
|
68264
68416
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
68265
68417
|
}
|
|
68266
|
-
if (!
|
|
68267
|
-
|
|
68268
|
-
|
|
68418
|
+
if (!fs40.existsSync(desiredDir)) {
|
|
68419
|
+
fs40.mkdirSync(path42.dirname(desiredDir), { recursive: true });
|
|
68420
|
+
fs40.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
68269
68421
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
68270
68422
|
}
|
|
68271
68423
|
const providerJson = path42.join(desiredDir, "provider.json");
|
|
68272
|
-
if (!
|
|
68424
|
+
if (!fs40.existsSync(providerJson)) {
|
|
68273
68425
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
68274
68426
|
}
|
|
68275
68427
|
return { dir: desiredDir };
|
|
@@ -68277,15 +68429,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
68277
68429
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
68278
68430
|
if (!referenceType) return {};
|
|
68279
68431
|
const refDir = ctx.findProviderDir(referenceType);
|
|
68280
|
-
if (!refDir || !
|
|
68432
|
+
if (!refDir || !fs40.existsSync(refDir)) return {};
|
|
68281
68433
|
const referenceScripts = {};
|
|
68282
68434
|
const scriptsDir = path42.join(refDir, "scripts");
|
|
68283
68435
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
68284
68436
|
if (!latestDir) return referenceScripts;
|
|
68285
|
-
for (const file of
|
|
68437
|
+
for (const file of fs40.readdirSync(latestDir)) {
|
|
68286
68438
|
if (!file.endsWith(".js")) continue;
|
|
68287
68439
|
try {
|
|
68288
|
-
referenceScripts[file] =
|
|
68440
|
+
referenceScripts[file] = fs40.readFileSync(path42.join(latestDir, file), "utf-8");
|
|
68289
68441
|
} catch {
|
|
68290
68442
|
}
|
|
68291
68443
|
}
|
|
@@ -68394,15 +68546,15 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
68394
68546
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
68395
68547
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
68396
68548
|
const tmpDir = path42.join(os30.tmpdir(), "adhdev-autoimpl");
|
|
68397
|
-
if (!
|
|
68549
|
+
if (!fs40.existsSync(tmpDir)) fs40.mkdirSync(tmpDir, { recursive: true });
|
|
68398
68550
|
const promptFile = path42.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
68399
|
-
|
|
68551
|
+
fs40.writeFileSync(promptFile, prompt, "utf-8");
|
|
68400
68552
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
68401
68553
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
68402
68554
|
const spawn5 = agentProvider?.spawn;
|
|
68403
68555
|
if (!spawn5?.command) {
|
|
68404
68556
|
try {
|
|
68405
|
-
|
|
68557
|
+
fs40.unlinkSync(promptFile);
|
|
68406
68558
|
} catch {
|
|
68407
68559
|
}
|
|
68408
68560
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -68504,7 +68656,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
68504
68656
|
} catch {
|
|
68505
68657
|
}
|
|
68506
68658
|
try {
|
|
68507
|
-
|
|
68659
|
+
fs40.unlinkSync(promptFile);
|
|
68508
68660
|
} catch {
|
|
68509
68661
|
}
|
|
68510
68662
|
ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -68730,7 +68882,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
68730
68882
|
}
|
|
68731
68883
|
});
|
|
68732
68884
|
try {
|
|
68733
|
-
|
|
68885
|
+
fs40.unlinkSync(promptFile);
|
|
68734
68886
|
} catch {
|
|
68735
68887
|
}
|
|
68736
68888
|
ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -68835,10 +68987,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
68835
68987
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
68836
68988
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
68837
68989
|
lines.push("");
|
|
68838
|
-
for (const file of
|
|
68990
|
+
for (const file of fs40.readdirSync(latestScriptsDir)) {
|
|
68839
68991
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
68840
68992
|
try {
|
|
68841
|
-
const content =
|
|
68993
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
68842
68994
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
68843
68995
|
lines.push("```javascript");
|
|
68844
68996
|
lines.push(content);
|
|
@@ -68848,14 +69000,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
68848
69000
|
}
|
|
68849
69001
|
}
|
|
68850
69002
|
}
|
|
68851
|
-
const refFiles =
|
|
69003
|
+
const refFiles = fs40.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
68852
69004
|
if (refFiles.length > 0) {
|
|
68853
69005
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
68854
69006
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
68855
69007
|
lines.push("");
|
|
68856
69008
|
for (const file of refFiles) {
|
|
68857
69009
|
try {
|
|
68858
|
-
const content =
|
|
69010
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
68859
69011
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
68860
69012
|
lines.push("```javascript");
|
|
68861
69013
|
lines.push(content);
|
|
@@ -68900,7 +69052,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
68900
69052
|
const loadGuide = (name) => {
|
|
68901
69053
|
try {
|
|
68902
69054
|
const p = path42.join(docsDir, name);
|
|
68903
|
-
if (
|
|
69055
|
+
if (fs40.existsSync(p)) return fs40.readFileSync(p, "utf-8");
|
|
68904
69056
|
} catch {
|
|
68905
69057
|
}
|
|
68906
69058
|
return null;
|
|
@@ -69144,11 +69296,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69144
69296
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
69145
69297
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
69146
69298
|
lines.push("");
|
|
69147
|
-
for (const file of
|
|
69299
|
+
for (const file of fs40.readdirSync(latestScriptsDir)) {
|
|
69148
69300
|
if (!file.endsWith(".js")) continue;
|
|
69149
69301
|
if (!targetFileNames.has(file)) continue;
|
|
69150
69302
|
try {
|
|
69151
|
-
const content =
|
|
69303
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69152
69304
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
69153
69305
|
lines.push("```javascript");
|
|
69154
69306
|
lines.push(content);
|
|
@@ -69157,14 +69309,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69157
69309
|
} catch {
|
|
69158
69310
|
}
|
|
69159
69311
|
}
|
|
69160
|
-
const refFiles =
|
|
69312
|
+
const refFiles = fs40.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
69161
69313
|
if (refFiles.length > 0) {
|
|
69162
69314
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
69163
69315
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
69164
69316
|
lines.push("");
|
|
69165
69317
|
for (const file of refFiles) {
|
|
69166
69318
|
try {
|
|
69167
|
-
const content =
|
|
69319
|
+
const content = fs40.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
69168
69320
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
69169
69321
|
lines.push("```javascript");
|
|
69170
69322
|
lines.push(content);
|
|
@@ -69201,7 +69353,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
69201
69353
|
const loadGuide = (name) => {
|
|
69202
69354
|
try {
|
|
69203
69355
|
const p = path42.join(docsDir, name);
|
|
69204
|
-
if (
|
|
69356
|
+
if (fs40.existsSync(p)) return fs40.readFileSync(p, "utf-8");
|
|
69205
69357
|
} catch {
|
|
69206
69358
|
}
|
|
69207
69359
|
return null;
|
|
@@ -69679,15 +69831,15 @@ var DevServer = class _DevServer {
|
|
|
69679
69831
|
this.json(res, 500, { error: e.message });
|
|
69680
69832
|
}
|
|
69681
69833
|
});
|
|
69682
|
-
return new Promise((
|
|
69834
|
+
return new Promise((resolve26, reject) => {
|
|
69683
69835
|
this.server.listen(port, "127.0.0.1", () => {
|
|
69684
69836
|
this.log(`Dev server listening on http://127.0.0.1:${port}`);
|
|
69685
|
-
|
|
69837
|
+
resolve26();
|
|
69686
69838
|
});
|
|
69687
69839
|
this.server.on("error", (e) => {
|
|
69688
69840
|
if (e.code === "EADDRINUSE") {
|
|
69689
69841
|
this.log(`Port ${port} in use, skipping dev server`);
|
|
69690
|
-
|
|
69842
|
+
resolve26();
|
|
69691
69843
|
} else {
|
|
69692
69844
|
reject(e);
|
|
69693
69845
|
}
|
|
@@ -69769,20 +69921,20 @@ var DevServer = class _DevServer {
|
|
|
69769
69921
|
child.stderr?.on("data", (d) => {
|
|
69770
69922
|
stderr += d.toString().slice(0, 2e3);
|
|
69771
69923
|
});
|
|
69772
|
-
await new Promise((
|
|
69924
|
+
await new Promise((resolve26) => {
|
|
69773
69925
|
const timer = setTimeout(() => {
|
|
69774
69926
|
child.kill();
|
|
69775
|
-
|
|
69927
|
+
resolve26();
|
|
69776
69928
|
}, 3e3);
|
|
69777
69929
|
child.on("exit", () => {
|
|
69778
69930
|
clearTimeout(timer);
|
|
69779
|
-
|
|
69931
|
+
resolve26();
|
|
69780
69932
|
});
|
|
69781
69933
|
child.stdout?.once("data", () => {
|
|
69782
69934
|
setTimeout(() => {
|
|
69783
69935
|
child.kill();
|
|
69784
69936
|
clearTimeout(timer);
|
|
69785
|
-
|
|
69937
|
+
resolve26();
|
|
69786
69938
|
}, 500);
|
|
69787
69939
|
});
|
|
69788
69940
|
});
|
|
@@ -69941,7 +70093,7 @@ var DevServer = class _DevServer {
|
|
|
69941
70093
|
path43.join(process.cwd(), "packages/web-devconsole/dist")
|
|
69942
70094
|
];
|
|
69943
70095
|
for (const dir of candidates) {
|
|
69944
|
-
if (
|
|
70096
|
+
if (fs41.existsSync(path43.join(dir, "index.html"))) return dir;
|
|
69945
70097
|
}
|
|
69946
70098
|
return null;
|
|
69947
70099
|
}
|
|
@@ -69953,7 +70105,7 @@ var DevServer = class _DevServer {
|
|
|
69953
70105
|
}
|
|
69954
70106
|
const htmlPath = path43.join(distDir, "index.html");
|
|
69955
70107
|
try {
|
|
69956
|
-
const html =
|
|
70108
|
+
const html = fs41.readFileSync(htmlPath, "utf-8");
|
|
69957
70109
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
69958
70110
|
res.end(html);
|
|
69959
70111
|
} catch (e) {
|
|
@@ -69983,7 +70135,7 @@ var DevServer = class _DevServer {
|
|
|
69983
70135
|
return;
|
|
69984
70136
|
}
|
|
69985
70137
|
try {
|
|
69986
|
-
const content =
|
|
70138
|
+
const content = fs41.readFileSync(filePath);
|
|
69987
70139
|
const ext = path43.extname(filePath);
|
|
69988
70140
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
69989
70141
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
@@ -70092,14 +70244,14 @@ var DevServer = class _DevServer {
|
|
|
70092
70244
|
const files = [];
|
|
70093
70245
|
const scan = (d, prefix) => {
|
|
70094
70246
|
try {
|
|
70095
|
-
for (const entry of
|
|
70247
|
+
for (const entry of fs41.readdirSync(d, { withFileTypes: true })) {
|
|
70096
70248
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
70097
70249
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
70098
70250
|
if (entry.isDirectory()) {
|
|
70099
70251
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
70100
70252
|
scan(path43.join(d, entry.name), rel);
|
|
70101
70253
|
} else {
|
|
70102
|
-
const stat2 =
|
|
70254
|
+
const stat2 = fs41.statSync(path43.join(d, entry.name));
|
|
70103
70255
|
files.push({ path: rel, size: stat2.size, type: "file" });
|
|
70104
70256
|
}
|
|
70105
70257
|
}
|
|
@@ -70127,11 +70279,11 @@ var DevServer = class _DevServer {
|
|
|
70127
70279
|
this.json(res, 403, { error: "Forbidden" });
|
|
70128
70280
|
return;
|
|
70129
70281
|
}
|
|
70130
|
-
if (!
|
|
70282
|
+
if (!fs41.existsSync(fullPath) || fs41.statSync(fullPath).isDirectory()) {
|
|
70131
70283
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
70132
70284
|
return;
|
|
70133
70285
|
}
|
|
70134
|
-
const content =
|
|
70286
|
+
const content = fs41.readFileSync(fullPath, "utf-8");
|
|
70135
70287
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
70136
70288
|
}
|
|
70137
70289
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -70153,9 +70305,9 @@ var DevServer = class _DevServer {
|
|
|
70153
70305
|
return;
|
|
70154
70306
|
}
|
|
70155
70307
|
try {
|
|
70156
|
-
if (
|
|
70157
|
-
|
|
70158
|
-
|
|
70308
|
+
if (fs41.existsSync(fullPath)) fs41.copyFileSync(fullPath, fullPath + ".bak");
|
|
70309
|
+
fs41.mkdirSync(path43.dirname(fullPath), { recursive: true });
|
|
70310
|
+
fs41.writeFileSync(fullPath, content, "utf-8");
|
|
70159
70311
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
70160
70312
|
this.providerLoader.reload();
|
|
70161
70313
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -70172,8 +70324,8 @@ var DevServer = class _DevServer {
|
|
|
70172
70324
|
}
|
|
70173
70325
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
70174
70326
|
const p = path43.join(dir, name);
|
|
70175
|
-
if (
|
|
70176
|
-
const source =
|
|
70327
|
+
if (fs41.existsSync(p)) {
|
|
70328
|
+
const source = fs41.readFileSync(p, "utf-8");
|
|
70177
70329
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
70178
70330
|
return;
|
|
70179
70331
|
}
|
|
@@ -70192,11 +70344,11 @@ var DevServer = class _DevServer {
|
|
|
70192
70344
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
70193
70345
|
return;
|
|
70194
70346
|
}
|
|
70195
|
-
const target =
|
|
70347
|
+
const target = fs41.existsSync(path43.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
70196
70348
|
const targetPath = path43.join(dir, target);
|
|
70197
70349
|
try {
|
|
70198
|
-
if (
|
|
70199
|
-
|
|
70350
|
+
if (fs41.existsSync(targetPath)) fs41.copyFileSync(targetPath, targetPath + ".bak");
|
|
70351
|
+
fs41.writeFileSync(targetPath, source, "utf-8");
|
|
70200
70352
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
70201
70353
|
this.providerLoader.reload();
|
|
70202
70354
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -70285,14 +70437,14 @@ var DevServer = class _DevServer {
|
|
|
70285
70437
|
child.stderr?.on("data", (d) => {
|
|
70286
70438
|
stderr += d.toString();
|
|
70287
70439
|
});
|
|
70288
|
-
await new Promise((
|
|
70440
|
+
await new Promise((resolve26) => {
|
|
70289
70441
|
const timer = setTimeout(() => {
|
|
70290
70442
|
child.kill();
|
|
70291
|
-
|
|
70443
|
+
resolve26();
|
|
70292
70444
|
}, timeout);
|
|
70293
70445
|
child.on("exit", () => {
|
|
70294
70446
|
clearTimeout(timer);
|
|
70295
|
-
|
|
70447
|
+
resolve26();
|
|
70296
70448
|
});
|
|
70297
70449
|
});
|
|
70298
70450
|
const elapsed = Date.now() - start;
|
|
@@ -70341,20 +70493,20 @@ var DevServer = class _DevServer {
|
|
|
70341
70493
|
let targetDir;
|
|
70342
70494
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
70343
70495
|
const jsonPath = path43.join(targetDir, "provider.json");
|
|
70344
|
-
if (
|
|
70496
|
+
if (fs41.existsSync(jsonPath)) {
|
|
70345
70497
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
70346
70498
|
return;
|
|
70347
70499
|
}
|
|
70348
70500
|
try {
|
|
70349
70501
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
|
|
70350
|
-
|
|
70351
|
-
|
|
70502
|
+
fs41.mkdirSync(targetDir, { recursive: true });
|
|
70503
|
+
fs41.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
70352
70504
|
const createdFiles = ["provider.json"];
|
|
70353
70505
|
if (result.files) {
|
|
70354
70506
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
70355
70507
|
const fullPath = path43.join(targetDir, relPath);
|
|
70356
|
-
|
|
70357
|
-
|
|
70508
|
+
fs41.mkdirSync(path43.dirname(fullPath), { recursive: true });
|
|
70509
|
+
fs41.writeFileSync(fullPath, content, "utf-8");
|
|
70358
70510
|
createdFiles.push(relPath);
|
|
70359
70511
|
}
|
|
70360
70512
|
}
|
|
@@ -70403,10 +70555,10 @@ var DevServer = class _DevServer {
|
|
|
70403
70555
|
}
|
|
70404
70556
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
70405
70557
|
getLatestScriptVersionDir(scriptsDir) {
|
|
70406
|
-
if (!
|
|
70407
|
-
const versions =
|
|
70558
|
+
if (!fs41.existsSync(scriptsDir)) return null;
|
|
70559
|
+
const versions = fs41.readdirSync(scriptsDir).filter((d) => {
|
|
70408
70560
|
try {
|
|
70409
|
-
return
|
|
70561
|
+
return fs41.statSync(path43.join(scriptsDir, d)).isDirectory();
|
|
70410
70562
|
} catch {
|
|
70411
70563
|
return false;
|
|
70412
70564
|
}
|
|
@@ -70428,13 +70580,13 @@ var DevServer = class _DevServer {
|
|
|
70428
70580
|
if (!sourceDir) {
|
|
70429
70581
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
70430
70582
|
}
|
|
70431
|
-
if (!
|
|
70432
|
-
|
|
70433
|
-
|
|
70583
|
+
if (!fs41.existsSync(desiredDir)) {
|
|
70584
|
+
fs41.mkdirSync(path43.dirname(desiredDir), { recursive: true });
|
|
70585
|
+
fs41.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
70434
70586
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
70435
70587
|
}
|
|
70436
70588
|
const providerJson = path43.join(desiredDir, "provider.json");
|
|
70437
|
-
if (!
|
|
70589
|
+
if (!fs41.existsSync(providerJson)) {
|
|
70438
70590
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
70439
70591
|
}
|
|
70440
70592
|
return { dir: desiredDir };
|
|
@@ -70491,14 +70643,14 @@ data: ${JSON.stringify(msg.data)}
|
|
|
70491
70643
|
res.end(JSON.stringify(data, null, 2));
|
|
70492
70644
|
}
|
|
70493
70645
|
async readBody(req) {
|
|
70494
|
-
return new Promise((
|
|
70646
|
+
return new Promise((resolve26) => {
|
|
70495
70647
|
let body = "";
|
|
70496
70648
|
req.on("data", (chunk) => body += chunk);
|
|
70497
70649
|
req.on("end", () => {
|
|
70498
70650
|
try {
|
|
70499
|
-
|
|
70651
|
+
resolve26(JSON.parse(body));
|
|
70500
70652
|
} catch {
|
|
70501
|
-
|
|
70653
|
+
resolve26({});
|
|
70502
70654
|
}
|
|
70503
70655
|
});
|
|
70504
70656
|
});
|
|
@@ -71240,7 +71392,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRe
|
|
|
71240
71392
|
const deadline = Date.now() + timeoutMs;
|
|
71241
71393
|
while (Date.now() < deadline) {
|
|
71242
71394
|
if (await canConnect(endpoint, requiredRequestTypes)) return;
|
|
71243
|
-
await new Promise((
|
|
71395
|
+
await new Promise((resolve26) => setTimeout(resolve26, STARTUP_POLL_MS));
|
|
71244
71396
|
}
|
|
71245
71397
|
throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
|
|
71246
71398
|
}
|
|
@@ -71283,7 +71435,7 @@ async function listHostedCliRuntimes(endpoint) {
|
|
|
71283
71435
|
|
|
71284
71436
|
// src/session-host/managed-host.ts
|
|
71285
71437
|
import { execFileSync as execFileSync9, spawn as spawn4 } from "child_process";
|
|
71286
|
-
import * as
|
|
71438
|
+
import * as fs42 from "fs";
|
|
71287
71439
|
import * as os31 from "os";
|
|
71288
71440
|
import * as path44 from "path";
|
|
71289
71441
|
import {
|
|
@@ -71307,7 +71459,7 @@ function createManagedSessionHost(options) {
|
|
|
71307
71459
|
path44.resolve(__dirname, "../../vendor/session-host-daemon/index.js")
|
|
71308
71460
|
];
|
|
71309
71461
|
for (const candidate of packagedCandidates) {
|
|
71310
|
-
if (
|
|
71462
|
+
if (fs42.existsSync(candidate)) {
|
|
71311
71463
|
return candidate;
|
|
71312
71464
|
}
|
|
71313
71465
|
}
|
|
@@ -71319,8 +71471,8 @@ function createManagedSessionHost(options) {
|
|
|
71319
71471
|
function getPid() {
|
|
71320
71472
|
try {
|
|
71321
71473
|
const pidFile = getPidFile();
|
|
71322
|
-
if (!
|
|
71323
|
-
const pid = Number.parseInt(
|
|
71474
|
+
if (!fs42.existsSync(pidFile)) return null;
|
|
71475
|
+
const pid = Number.parseInt(fs42.readFileSync(pidFile, "utf8").trim(), 10);
|
|
71324
71476
|
return Number.isFinite(pid) ? pid : null;
|
|
71325
71477
|
} catch {
|
|
71326
71478
|
return null;
|
|
@@ -71346,8 +71498,8 @@ function createManagedSessionHost(options) {
|
|
|
71346
71498
|
let logFd = null;
|
|
71347
71499
|
if (options.spawnStdio === "logfile") {
|
|
71348
71500
|
const logDir = path44.join(os31.homedir(), ".adhdev", "logs");
|
|
71349
|
-
|
|
71350
|
-
logFd =
|
|
71501
|
+
fs42.mkdirSync(logDir, { recursive: true });
|
|
71502
|
+
logFd = fs42.openSync(path44.join(logDir, "session-host.log"), "a");
|
|
71351
71503
|
stdio = ["ignore", logFd, logFd];
|
|
71352
71504
|
}
|
|
71353
71505
|
const child = spawn4(process.execPath, [entry], {
|
|
@@ -71359,7 +71511,7 @@ function createManagedSessionHost(options) {
|
|
|
71359
71511
|
child.unref();
|
|
71360
71512
|
if (logFd !== null) {
|
|
71361
71513
|
try {
|
|
71362
|
-
|
|
71514
|
+
fs42.closeSync(logFd);
|
|
71363
71515
|
} catch {
|
|
71364
71516
|
}
|
|
71365
71517
|
}
|
|
@@ -71368,8 +71520,8 @@ function createManagedSessionHost(options) {
|
|
|
71368
71520
|
let stopped = false;
|
|
71369
71521
|
const pidFile = getPidFile();
|
|
71370
71522
|
try {
|
|
71371
|
-
if (
|
|
71372
|
-
const pid = Number.parseInt(
|
|
71523
|
+
if (fs42.existsSync(pidFile)) {
|
|
71524
|
+
const pid = Number.parseInt(fs42.readFileSync(pidFile, "utf8").trim(), 10);
|
|
71373
71525
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedPid(pid)) {
|
|
71374
71526
|
stopped = killPid2(pid) || stopped;
|
|
71375
71527
|
}
|
|
@@ -71377,7 +71529,7 @@ function createManagedSessionHost(options) {
|
|
|
71377
71529
|
} catch {
|
|
71378
71530
|
} finally {
|
|
71379
71531
|
try {
|
|
71380
|
-
|
|
71532
|
+
fs42.unlinkSync(pidFile);
|
|
71381
71533
|
} catch {
|
|
71382
71534
|
}
|
|
71383
71535
|
}
|
|
@@ -71566,12 +71718,12 @@ async function installExtension(ide, extension) {
|
|
|
71566
71718
|
const res = await fetch(extension.vsixUrl);
|
|
71567
71719
|
if (res.ok) {
|
|
71568
71720
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
71569
|
-
const
|
|
71570
|
-
|
|
71571
|
-
return new Promise((
|
|
71721
|
+
const fs43 = await import("fs");
|
|
71722
|
+
fs43.writeFileSync(vsixPath, buffer);
|
|
71723
|
+
return new Promise((resolve26) => {
|
|
71572
71724
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
71573
71725
|
exec6(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|
|
71574
|
-
|
|
71726
|
+
resolve26({
|
|
71575
71727
|
extensionId: extension.id,
|
|
71576
71728
|
marketplaceId: extension.marketplaceId,
|
|
71577
71729
|
success: !error,
|
|
@@ -71584,11 +71736,11 @@ async function installExtension(ide, extension) {
|
|
|
71584
71736
|
} catch (e) {
|
|
71585
71737
|
}
|
|
71586
71738
|
}
|
|
71587
|
-
return new Promise((
|
|
71739
|
+
return new Promise((resolve26) => {
|
|
71588
71740
|
const cmd = `"${ide.cliCommand}" --install-extension ${extension.marketplaceId} --force`;
|
|
71589
71741
|
exec6(cmd, { timeout: 6e4 }, (error, stdout, stderr) => {
|
|
71590
71742
|
if (error) {
|
|
71591
|
-
|
|
71743
|
+
resolve26({
|
|
71592
71744
|
extensionId: extension.id,
|
|
71593
71745
|
marketplaceId: extension.marketplaceId,
|
|
71594
71746
|
success: false,
|
|
@@ -71596,7 +71748,7 @@ async function installExtension(ide, extension) {
|
|
|
71596
71748
|
error: stderr || error.message
|
|
71597
71749
|
});
|
|
71598
71750
|
} else {
|
|
71599
|
-
|
|
71751
|
+
resolve26({
|
|
71600
71752
|
extensionId: extension.id,
|
|
71601
71753
|
marketplaceId: extension.marketplaceId,
|
|
71602
71754
|
success: true,
|
|
@@ -72132,7 +72284,7 @@ async function startLocalIpcServer(opts) {
|
|
|
72132
72284
|
}));
|
|
72133
72285
|
}
|
|
72134
72286
|
}
|
|
72135
|
-
await new Promise((
|
|
72287
|
+
await new Promise((resolve26, reject) => {
|
|
72136
72288
|
const onError = (error) => {
|
|
72137
72289
|
httpServer?.off("listening", onListening);
|
|
72138
72290
|
reject(error);
|
|
@@ -72140,7 +72292,7 @@ async function startLocalIpcServer(opts) {
|
|
|
72140
72292
|
const onListening = () => {
|
|
72141
72293
|
httpServer?.off("error", onError);
|
|
72142
72294
|
listening = true;
|
|
72143
|
-
|
|
72295
|
+
resolve26();
|
|
72144
72296
|
};
|
|
72145
72297
|
httpServer.once("error", onError);
|
|
72146
72298
|
httpServer.once("listening", onListening);
|
|
@@ -72167,12 +72319,12 @@ async function startLocalIpcServer(opts) {
|
|
|
72167
72319
|
}
|
|
72168
72320
|
}
|
|
72169
72321
|
clients.clear();
|
|
72170
|
-
await new Promise((
|
|
72322
|
+
await new Promise((resolve26) => {
|
|
72171
72323
|
if (!httpServer) {
|
|
72172
|
-
|
|
72324
|
+
resolve26();
|
|
72173
72325
|
return;
|
|
72174
72326
|
}
|
|
72175
|
-
httpServer.close(() =>
|
|
72327
|
+
httpServer.close(() => resolve26());
|
|
72176
72328
|
});
|
|
72177
72329
|
httpServer = null;
|
|
72178
72330
|
wss = null;
|
|
@@ -72194,11 +72346,11 @@ init_parse_session();
|
|
|
72194
72346
|
// src/providers/sdk/v1/fixture-tooling/replay.ts
|
|
72195
72347
|
init_provider_cli_shared();
|
|
72196
72348
|
import { readFileSync as readFileSync40 } from "fs";
|
|
72197
|
-
import { dirname as
|
|
72349
|
+
import { dirname as dirname16, resolve as resolve24 } from "path";
|
|
72198
72350
|
|
|
72199
72351
|
// src/providers/sdk/v1/validators/taint.ts
|
|
72200
72352
|
import { readFileSync as readFileSync41, existsSync as existsSync54 } from "fs";
|
|
72201
|
-
import { resolve as
|
|
72353
|
+
import { resolve as resolve25, dirname as dirname17, join as join51 } from "path";
|
|
72202
72354
|
|
|
72203
72355
|
// src/providers/sdk/v1/validators/index.ts
|
|
72204
72356
|
init_manifest();
|