@adhdev/daemon-core 0.9.82-rc.464 → 0.9.82-rc.466
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1022 -823
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1028 -829
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-events-pending.d.ts +18 -0
- package/dist/mesh/mesh-reconcile-acked-hold.d.ts +17 -0
- package/dist/mesh/mesh-reconcile-identity.d.ts +6 -0
- package/dist/mesh/mesh-reconcile-loop.d.ts +2 -14
- package/dist/mesh/mesh-reconcile-v2-backstop.d.ts +16 -0
- package/dist/mesh/mesh-runtime-store.d.ts +26 -0
- package/dist/providers/cli-provider-history-dedup.d.ts +17 -0
- package/dist/providers/cli-provider-input-prompt.d.ts +12 -0
- package/dist/providers/cli-provider-instance.d.ts +43 -35
- package/dist/providers/cli-provider-status-helpers.d.ts +46 -0
- package/package.json +3 -3
- package/src/mesh/mesh-event-forwarding.ts +16 -1
- package/src/mesh/mesh-events-pending.ts +94 -5
- package/src/mesh/mesh-ledger.ts +10 -0
- package/src/mesh/mesh-reconcile-acked-hold.ts +230 -0
- package/src/mesh/mesh-reconcile-identity.ts +103 -0
- package/src/mesh/mesh-reconcile-loop.ts +28 -393
- package/src/mesh/mesh-reconcile-v2-backstop.ts +62 -0
- package/src/mesh/mesh-runtime-store.ts +53 -0
- package/src/providers/cli-provider-history-dedup.ts +75 -0
- package/src/providers/cli-provider-input-prompt.ts +133 -0
- package/src/providers/cli-provider-instance.ts +139 -298
- package/src/providers/cli-provider-status-helpers.ts +123 -0
package/dist/index.mjs
CHANGED
|
@@ -404,10 +404,10 @@ function readInjected(value) {
|
|
|
404
404
|
}
|
|
405
405
|
function getDaemonBuildInfo() {
|
|
406
406
|
if (cached) return cached;
|
|
407
|
-
const commit = readInjected(true ? "
|
|
408
|
-
const commitShort = readInjected(true ? "
|
|
409
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
410
|
-
const builtAt = readInjected(true ? "2026-07-
|
|
407
|
+
const commit = readInjected(true ? "e0f04b7d54855e0f0d5ed4200078d95596ab9f6f" : void 0) ?? "unknown";
|
|
408
|
+
const commitShort = readInjected(true ? "e0f04b7d" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
409
|
+
const version = readInjected(true ? "0.9.82-rc.466" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
410
|
+
const builtAt = readInjected(true ? "2026-07-05T08:18:54.364Z" : void 0);
|
|
411
411
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
412
412
|
return cached;
|
|
413
413
|
}
|
|
@@ -484,8 +484,8 @@ function validateChangeImpactConfig(raw, source = "inline") {
|
|
|
484
484
|
}
|
|
485
485
|
return { valid: errors.length === 0, errors, config: errors.length === 0 ? config : void 0 };
|
|
486
486
|
}
|
|
487
|
-
function parseConfigText(
|
|
488
|
-
if (/\.json$/i.test(
|
|
487
|
+
function parseConfigText(path45, text) {
|
|
488
|
+
if (/\.json$/i.test(path45)) return JSON.parse(text);
|
|
489
489
|
return yaml.load(text);
|
|
490
490
|
}
|
|
491
491
|
function loadChangeImpactConfig(repoRoot) {
|
|
@@ -1099,14 +1099,14 @@ async function deriveSubmoduleGitlinkStatuses(repo, options) {
|
|
|
1099
1099
|
const lastCheckedAt = Date.now();
|
|
1100
1100
|
const headOidByPath = /* @__PURE__ */ new Map();
|
|
1101
1101
|
const entries = await Promise.all(
|
|
1102
|
-
paths.filter((
|
|
1103
|
-
const repoPath = repo.repoRoot + "/" +
|
|
1104
|
-
const expected = await readGitlinkExpectedSha(repo,
|
|
1102
|
+
paths.filter((path45) => !ignoreSet.has(path45)).map(async (path45) => {
|
|
1103
|
+
const repoPath = repo.repoRoot + "/" + path45;
|
|
1104
|
+
const expected = await readGitlinkExpectedSha(repo, path45, options);
|
|
1105
1105
|
const actual = await readSubmoduleHeadSha(repo, repoPath, options);
|
|
1106
|
-
if (actual) headOidByPath.set(
|
|
1106
|
+
if (actual) headOidByPath.set(path45, actual);
|
|
1107
1107
|
const outOfSync = actual === null ? true : expected !== null && expected !== actual;
|
|
1108
1108
|
return {
|
|
1109
|
-
path:
|
|
1109
|
+
path: path45,
|
|
1110
1110
|
// Prefer the recorded gitlink SHA (matches the legacy column); fall back
|
|
1111
1111
|
// to the checked-out SHA so the field is never empty when both are known.
|
|
1112
1112
|
commit: expected ?? actual ?? "",
|
|
@@ -2553,12 +2553,12 @@ function readGitSubmodules(value, parentRepoRoot) {
|
|
|
2553
2553
|
if (!Array.isArray(value)) return void 0;
|
|
2554
2554
|
const submodules = value.map((entry) => {
|
|
2555
2555
|
const submodule = readRecord(entry);
|
|
2556
|
-
const
|
|
2556
|
+
const path45 = readString2(submodule.path);
|
|
2557
2557
|
const commit = readString2(submodule.commit);
|
|
2558
|
-
const repoPath = readString2(submodule.repoPath, submodule.repo_root) ?? joinRepoPath(parentRepoRoot,
|
|
2559
|
-
if (!
|
|
2558
|
+
const repoPath = readString2(submodule.repoPath, submodule.repo_root) ?? joinRepoPath(parentRepoRoot, path45);
|
|
2559
|
+
if (!path45 || !commit) return null;
|
|
2560
2560
|
const result = {
|
|
2561
|
-
path:
|
|
2561
|
+
path: path45,
|
|
2562
2562
|
commit,
|
|
2563
2563
|
dirty: readBoolean(submodule.dirty) ?? false,
|
|
2564
2564
|
outOfSync: readBoolean(submodule.outOfSync, submodule.out_of_sync) ?? false,
|
|
@@ -2892,10 +2892,10 @@ function getMeshConfigPath() {
|
|
|
2892
2892
|
return join5(getConfigDir(), "meshes.json");
|
|
2893
2893
|
}
|
|
2894
2894
|
function loadMeshConfig() {
|
|
2895
|
-
const
|
|
2896
|
-
if (!existsSync5(
|
|
2895
|
+
const path45 = getMeshConfigPath();
|
|
2896
|
+
if (!existsSync5(path45)) return { meshes: [] };
|
|
2897
2897
|
try {
|
|
2898
|
-
const raw = JSON.parse(readFileSync3(
|
|
2898
|
+
const raw = JSON.parse(readFileSync3(path45, "utf-8"));
|
|
2899
2899
|
if (!raw || !Array.isArray(raw.meshes)) return { meshes: [] };
|
|
2900
2900
|
const config = raw;
|
|
2901
2901
|
const migrated = migrateLoadedMeshConfig(config);
|
|
@@ -2944,16 +2944,16 @@ function normalizeCapabilityTags(value) {
|
|
|
2944
2944
|
return tags.length ? tags : void 0;
|
|
2945
2945
|
}
|
|
2946
2946
|
function saveMeshConfig(config) {
|
|
2947
|
-
const
|
|
2948
|
-
writeFileSync2(
|
|
2947
|
+
const path45 = getMeshConfigPath();
|
|
2948
|
+
writeFileSync2(path45, JSON.stringify(config, null, 2), { encoding: "utf-8", mode: 384 });
|
|
2949
2949
|
}
|
|
2950
2950
|
function normalizeRepoIdentity(remoteUrl) {
|
|
2951
2951
|
let identity = remoteUrl.trim();
|
|
2952
2952
|
if (identity.startsWith("http://") || identity.startsWith("https://")) {
|
|
2953
2953
|
try {
|
|
2954
2954
|
const url = new URL(identity);
|
|
2955
|
-
const
|
|
2956
|
-
return `${url.hostname}/${
|
|
2955
|
+
const path45 = url.pathname.replace(/^\//, "").replace(/\.git$/, "");
|
|
2956
|
+
return `${url.hostname}/${path45}`;
|
|
2957
2957
|
} catch {
|
|
2958
2958
|
}
|
|
2959
2959
|
}
|
|
@@ -4196,59 +4196,59 @@ function isMeshEventScope(value) {
|
|
|
4196
4196
|
function isNonEmptyString(value) {
|
|
4197
4197
|
return typeof value === "string" && value.length > 0;
|
|
4198
4198
|
}
|
|
4199
|
-
function assertCoordinatorIdentity(raw,
|
|
4199
|
+
function assertCoordinatorIdentity(raw, path45) {
|
|
4200
4200
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
4201
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2,
|
|
4201
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, path45, "must be an object");
|
|
4202
4202
|
}
|
|
4203
4203
|
const obj = raw;
|
|
4204
4204
|
if (!isNonEmptyString(obj.daemonId)) {
|
|
4205
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4205
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.daemonId`, "must be a non-empty string");
|
|
4206
4206
|
}
|
|
4207
4207
|
if (!isNonEmptyString(obj.coordinatorRunId)) {
|
|
4208
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4208
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.coordinatorRunId`, "must be a non-empty string");
|
|
4209
4209
|
}
|
|
4210
4210
|
const sessionId = obj.sessionId;
|
|
4211
4211
|
if (sessionId !== void 0 && !isNonEmptyString(sessionId)) {
|
|
4212
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4212
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.sessionId`, "must be a non-empty string when provided");
|
|
4213
4213
|
}
|
|
4214
4214
|
return sessionId !== void 0 ? { daemonId: obj.daemonId, coordinatorRunId: obj.coordinatorRunId, sessionId } : { daemonId: obj.daemonId, coordinatorRunId: obj.coordinatorRunId };
|
|
4215
4215
|
}
|
|
4216
|
-
function assertPendingMeshCoordinatorEventV2(raw,
|
|
4216
|
+
function assertPendingMeshCoordinatorEventV2(raw, path45 = "$") {
|
|
4217
4217
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
4218
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2,
|
|
4218
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, path45, "must be an object");
|
|
4219
4219
|
}
|
|
4220
4220
|
const obj = raw;
|
|
4221
4221
|
if (!isSupportedMeshProtocolVersion(obj.protocolVersion)) {
|
|
4222
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4222
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.protocolVersion`, `must be one of ${SUPPORTED_MESH_PROTOCOL_VERSIONS.join(", ")}`);
|
|
4223
4223
|
}
|
|
4224
4224
|
if (!isNonEmptyString(obj.eventId)) {
|
|
4225
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4225
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.eventId`, "must be a non-empty string");
|
|
4226
4226
|
}
|
|
4227
4227
|
if (!isMeshEventScope(obj.scope)) {
|
|
4228
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4228
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.scope`, `must be one of ${MESH_EVENT_SCOPES.join(", ")}`);
|
|
4229
4229
|
}
|
|
4230
4230
|
if (!isNonEmptyString(obj.event)) {
|
|
4231
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4231
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.event`, "must be a non-empty string");
|
|
4232
4232
|
}
|
|
4233
4233
|
if (!isNonEmptyString(obj.meshId)) {
|
|
4234
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4234
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.meshId`, "must be a non-empty string");
|
|
4235
4235
|
}
|
|
4236
|
-
const dispatchedBy = assertCoordinatorIdentity(obj.dispatchedBy, `${
|
|
4236
|
+
const dispatchedBy = assertCoordinatorIdentity(obj.dispatchedBy, `${path45}.dispatchedBy`);
|
|
4237
4237
|
if (obj.scope === "unicast") {
|
|
4238
4238
|
if (!obj.intendedFor) {
|
|
4239
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4239
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.intendedFor`, "unicast scope requires intendedFor");
|
|
4240
4240
|
}
|
|
4241
4241
|
} else if (obj.intendedFor !== void 0) {
|
|
4242
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4242
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.intendedFor`, "only unicast scope may set intendedFor");
|
|
4243
4243
|
}
|
|
4244
|
-
const intendedFor = obj.intendedFor ? assertCoordinatorIdentity(obj.intendedFor, `${
|
|
4244
|
+
const intendedFor = obj.intendedFor ? assertCoordinatorIdentity(obj.intendedFor, `${path45}.intendedFor`) : void 0;
|
|
4245
4245
|
const metadata = obj.metadataEvent && typeof obj.metadataEvent === "object" && !Array.isArray(obj.metadataEvent) ? obj.metadataEvent : null;
|
|
4246
4246
|
if (!metadata) {
|
|
4247
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4247
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.metadataEvent`, "must be an object");
|
|
4248
4248
|
}
|
|
4249
4249
|
const queuedAt = typeof obj.queuedAt === "number" && Number.isFinite(obj.queuedAt) ? obj.queuedAt : null;
|
|
4250
4250
|
if (queuedAt === null) {
|
|
4251
|
-
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${
|
|
4251
|
+
throw new MeshContractViolationError(MESH_PROTOCOL_VERSION_V2, `${path45}.queuedAt`, "must be a finite number");
|
|
4252
4252
|
}
|
|
4253
4253
|
return {
|
|
4254
4254
|
event: obj.event,
|
|
@@ -4415,10 +4415,10 @@ function rotateArchiveFile(meshId, archivePath) {
|
|
|
4415
4415
|
}
|
|
4416
4416
|
}
|
|
4417
4417
|
function readArchivedCounts(meshId) {
|
|
4418
|
-
const
|
|
4419
|
-
if (!existsSync7(
|
|
4418
|
+
const path45 = getArchivedCountsPath(meshId);
|
|
4419
|
+
if (!existsSync7(path45)) return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
4420
4420
|
try {
|
|
4421
|
-
return JSON.parse(readFileSync5(
|
|
4421
|
+
return JSON.parse(readFileSync5(path45, "utf-8"));
|
|
4422
4422
|
} catch {
|
|
4423
4423
|
return { taskCompleted: 0, taskFailed: 0, taskStalled: 0, recoveryAttempted: 0, totalArchived: 0, lastArchivedAt: "" };
|
|
4424
4424
|
}
|
|
@@ -5144,7 +5144,8 @@ var init_mesh_ledger = __esm({
|
|
|
5144
5144
|
"task_completed",
|
|
5145
5145
|
"task_failed",
|
|
5146
5146
|
"task_stalled",
|
|
5147
|
-
"recovery_attempted"
|
|
5147
|
+
"recovery_attempted",
|
|
5148
|
+
"session_auto_launch"
|
|
5148
5149
|
]);
|
|
5149
5150
|
DEFAULT_LEDGER_SLICE_LIMIT = 100;
|
|
5150
5151
|
MAX_LEDGER_SLICE_LIMIT = 500;
|
|
@@ -5637,11 +5638,11 @@ function readNodeReporter(node, key2) {
|
|
|
5637
5638
|
function buildMeshNodeCapabilityTags(node, providerType) {
|
|
5638
5639
|
const provider = typeof providerType === "string" && providerType.trim() ? providerType.trim() : firstProviderPriority(node?.policy);
|
|
5639
5640
|
const worktreeBranch = typeof node?.worktreeBranch === "string" && node.worktreeBranch.trim() ? node.worktreeBranch.trim() : null;
|
|
5640
|
-
const
|
|
5641
|
+
const os32 = readNodeOverride(node, "platform") ?? readNodeReporter(node, "platform") ?? process.platform;
|
|
5641
5642
|
const arch2 = readNodeOverride(node, "arch") ?? readNodeReporter(node, "arch") ?? process.arch;
|
|
5642
5643
|
return normalizeMeshCapabilityTags([
|
|
5643
5644
|
...Array.isArray(node?.capabilities) ? node.capabilities : [],
|
|
5644
|
-
`os=${
|
|
5645
|
+
`os=${os32}`,
|
|
5645
5646
|
`arch=${arch2}`,
|
|
5646
5647
|
...provider ? [`provider=${provider}`] : [],
|
|
5647
5648
|
// Worktree nodes automatically expose a "worktree=<branch>" tag so that
|
|
@@ -6594,10 +6595,10 @@ var init_mesh_runtime_store = __esm({
|
|
|
6594
6595
|
this.migratedMeshIds.add(meshId);
|
|
6595
6596
|
const count = this.db.prepare("SELECT COUNT(*) AS count FROM mesh_queue WHERE mesh_id = ?").get(meshId);
|
|
6596
6597
|
if (count.count > 0) return;
|
|
6597
|
-
const
|
|
6598
|
-
if (!existsSync8(
|
|
6598
|
+
const path45 = legacyQueuePath(meshId);
|
|
6599
|
+
if (!existsSync8(path45)) return;
|
|
6599
6600
|
try {
|
|
6600
|
-
const entries = JSON.parse(readFileSync6(
|
|
6601
|
+
const entries = JSON.parse(readFileSync6(path45, "utf-8"));
|
|
6601
6602
|
if (!Array.isArray(entries)) return;
|
|
6602
6603
|
const insert = this.db.prepare(`
|
|
6603
6604
|
INSERT OR REPLACE INTO mesh_queue (
|
|
@@ -7337,6 +7338,10 @@ var init_mesh_runtime_store = __esm({
|
|
|
7337
7338
|
}
|
|
7338
7339
|
// ── G2: Event Ledger ────────────────────────────────────────────────────
|
|
7339
7340
|
appendLedgerEntry(entry) {
|
|
7341
|
+
if (!entry.kind || !String(entry.kind).trim()) {
|
|
7342
|
+
LOG.warn("MeshRuntimeStore", `Refusing to append ledger entry with empty kind for mesh ${entry.meshId} (id ${entry.id})`);
|
|
7343
|
+
return;
|
|
7344
|
+
}
|
|
7340
7345
|
this.db.prepare(
|
|
7341
7346
|
`INSERT OR IGNORE INTO mesh_event_ledger
|
|
7342
7347
|
(id, mesh_id, timestamp, kind, node_id, session_id, provider_type, payload)
|
|
@@ -7471,6 +7476,7 @@ var init_mesh_runtime_store = __esm({
|
|
|
7471
7476
|
);
|
|
7472
7477
|
this.db.transaction(() => {
|
|
7473
7478
|
for (const e of entries) {
|
|
7479
|
+
if (!e.kind || !String(e.kind).trim()) continue;
|
|
7474
7480
|
const result = stmt.run(
|
|
7475
7481
|
e.id,
|
|
7476
7482
|
e.meshId,
|
|
@@ -7765,6 +7771,41 @@ var init_mesh_runtime_store = __esm({
|
|
|
7765
7771
|
`DELETE FROM mesh_pending_events WHERE id IN (${idList.map(() => "?").join(",")})`
|
|
7766
7772
|
).run(...idList).changes;
|
|
7767
7773
|
}
|
|
7774
|
+
/**
|
|
7775
|
+
* Retention prune for mesh_pending_events. This table has no lifecycle GC of its
|
|
7776
|
+
* own: a drained row is soft-marked (drained=1) and RETAINED — deliberately, so
|
|
7777
|
+
* drainedEventIdsForMesh() has a durable v2-eventId dedup baseline — and an
|
|
7778
|
+
* undrained row queued for a coordinator that never returned (a dead/evicted
|
|
7779
|
+
* coordinator identity) stays drained=0 forever. Both accumulate without bound
|
|
7780
|
+
* (observed: tens of thousands of rows, mostly stale). This is the missing
|
|
7781
|
+
* retention step. Two independent windows:
|
|
7782
|
+
*
|
|
7783
|
+
* - drained rows older than `drainedOlderThanMs`: the coordinator consumed them
|
|
7784
|
+
* long ago; the only thing they still back is the eventId re-delivery guard,
|
|
7785
|
+
* which is only meaningful for the recent past (a re-delivery of a week-old
|
|
7786
|
+
* event cannot occur — its producer session is long gone). Safe to delete.
|
|
7787
|
+
* - UNDRAINED rows older than `undrainedOlderThanMs` (a much wider window):
|
|
7788
|
+
* these are orphaned events for a coordinator identity that never drained
|
|
7789
|
+
* them. Kept wide so a genuinely-offline-but-returning coordinator still
|
|
7790
|
+
* receives its backlog; only genuinely unrecoverable orphans are swept.
|
|
7791
|
+
*
|
|
7792
|
+
* Both windows key off `queued_at` (always present) — `drained_at` can be NULL on
|
|
7793
|
+
* legacy rows. Returns the number of rows deleted. Best-effort / idempotent:
|
|
7794
|
+
* running it repeatedly with nothing to prune is a cheap no-op.
|
|
7795
|
+
*/
|
|
7796
|
+
prunePendingEvents(opts) {
|
|
7797
|
+
const now = Date.now();
|
|
7798
|
+
const drainedCutoff = now - Math.max(0, opts.drainedOlderThanMs);
|
|
7799
|
+
const undrainedCutoff = now - Math.max(0, opts.undrainedOlderThanMs);
|
|
7800
|
+
let removed = 0;
|
|
7801
|
+
removed += this.db.prepare(
|
|
7802
|
+
"DELETE FROM mesh_pending_events WHERE drained = 1 AND queued_at < ?"
|
|
7803
|
+
).run(drainedCutoff).changes;
|
|
7804
|
+
removed += this.db.prepare(
|
|
7805
|
+
"DELETE FROM mesh_pending_events WHERE drained = 0 AND queued_at < ?"
|
|
7806
|
+
).run(undrainedCutoff).changes;
|
|
7807
|
+
return removed;
|
|
7808
|
+
}
|
|
7768
7809
|
};
|
|
7769
7810
|
}
|
|
7770
7811
|
});
|
|
@@ -8510,8 +8551,8 @@ function resolveMeshCoordinatorSetup(options) {
|
|
|
8510
8551
|
}
|
|
8511
8552
|
const serverName = mcpConfig.serverName?.trim() || DEFAULT_SERVER_NAME;
|
|
8512
8553
|
if (mcpConfig.mode === "auto_import") {
|
|
8513
|
-
const
|
|
8514
|
-
if (!
|
|
8554
|
+
const path45 = mcpConfig.path?.trim();
|
|
8555
|
+
if (!path45) {
|
|
8515
8556
|
return { kind: "unsupported", reason: "Provider auto-import MCP config is missing a config path" };
|
|
8516
8557
|
}
|
|
8517
8558
|
const mcpServer = resolveAdhdevMcpServerLaunch({
|
|
@@ -8531,7 +8572,7 @@ function resolveMeshCoordinatorSetup(options) {
|
|
|
8531
8572
|
return {
|
|
8532
8573
|
kind: "auto_import",
|
|
8533
8574
|
serverName,
|
|
8534
|
-
configPath: resolveMcpConfigPath(
|
|
8575
|
+
configPath: resolveMcpConfigPath(path45, workspace),
|
|
8535
8576
|
configFormat: mcpConfig.format,
|
|
8536
8577
|
mcpServer
|
|
8537
8578
|
};
|
|
@@ -8732,8 +8773,8 @@ function stripCoordinatorWrapperFile(filePath) {
|
|
|
8732
8773
|
const remaining = (existing.slice(0, openIdx) + existing.slice(closeIdx + CLOSE.length)).replace(/^\s*\n+/, "").replace(/\n+\s*$/, "");
|
|
8733
8774
|
if (!remaining.trim()) {
|
|
8734
8775
|
try {
|
|
8735
|
-
const
|
|
8736
|
-
|
|
8776
|
+
const fs41 = __require("fs");
|
|
8777
|
+
fs41.unlinkSync(filePath);
|
|
8737
8778
|
} catch {
|
|
8738
8779
|
}
|
|
8739
8780
|
} else {
|
|
@@ -8833,10 +8874,10 @@ function getRegistryPath() {
|
|
|
8833
8874
|
return join11(getDaemonDataDir(), "mesh-coordinators.json");
|
|
8834
8875
|
}
|
|
8835
8876
|
function loadMeshCoordinatorRegistry() {
|
|
8836
|
-
const
|
|
8837
|
-
if (!existsSync10(
|
|
8877
|
+
const path45 = getRegistryPath();
|
|
8878
|
+
if (!existsSync10(path45)) return;
|
|
8838
8879
|
try {
|
|
8839
|
-
const raw = JSON.parse(readFileSync8(
|
|
8880
|
+
const raw = JSON.parse(readFileSync8(path45, "utf-8"));
|
|
8840
8881
|
if (!Array.isArray(raw)) return;
|
|
8841
8882
|
_registry.clear();
|
|
8842
8883
|
for (const entry of raw) {
|
|
@@ -9008,8 +9049,8 @@ function validateMeshRefineConfig(config, source = "inline") {
|
|
|
9008
9049
|
if (rejectedCommands.length) errors.push("one or more validation commands are invalid");
|
|
9009
9050
|
return { valid: errors.length === 0, errors, bootstrapCommands, commands, rejectedCommands, bootstrapMode, deprecationWarnings };
|
|
9010
9051
|
}
|
|
9011
|
-
function parseConfigText2(
|
|
9012
|
-
if (/\.json$/i.test(
|
|
9052
|
+
function parseConfigText2(path45, text) {
|
|
9053
|
+
if (/\.json$/i.test(path45)) return JSON.parse(text);
|
|
9013
9054
|
return yaml2.load(text);
|
|
9014
9055
|
}
|
|
9015
9056
|
function loadMeshRefineConfig(mesh, workspace) {
|
|
@@ -9419,8 +9460,8 @@ function isCleanIgnoringSubmoduleGitlinks(porcelain, submodulePaths) {
|
|
|
9419
9460
|
const lines = porcelain.split(/\r?\n/).filter((line) => line.length > 0);
|
|
9420
9461
|
for (const line of lines) {
|
|
9421
9462
|
const status = line.slice(0, 2);
|
|
9422
|
-
const
|
|
9423
|
-
const isGitlinkPointerMove = (status === " M" || status === "M ") && submodulePaths.has(
|
|
9463
|
+
const path45 = line.slice(3).trim().replace(/\\/g, "/").replace(/\/+$/, "");
|
|
9464
|
+
const isGitlinkPointerMove = (status === " M" || status === "M ") && submodulePaths.has(path45);
|
|
9424
9465
|
if (!isGitlinkPointerMove) return false;
|
|
9425
9466
|
}
|
|
9426
9467
|
return true;
|
|
@@ -9455,8 +9496,8 @@ function shouldDeferDispatchForBootstrap(node, nowMs = Date.now()) {
|
|
|
9455
9496
|
if (node?.worktreeBootstrap?.status !== "running") return false;
|
|
9456
9497
|
return !isWorktreeBootstrapStaleRunning(node, nowMs);
|
|
9457
9498
|
}
|
|
9458
|
-
function parseConfigText3(
|
|
9459
|
-
if (/\.json$/i.test(
|
|
9499
|
+
function parseConfigText3(path45, text) {
|
|
9500
|
+
if (/\.json$/i.test(path45)) return JSON.parse(text);
|
|
9460
9501
|
return yaml3.load(text);
|
|
9461
9502
|
}
|
|
9462
9503
|
function truncateOutput(value) {
|
|
@@ -9731,8 +9772,8 @@ import * as yaml4 from "js-yaml";
|
|
|
9731
9772
|
function isRecord3(value) {
|
|
9732
9773
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
9733
9774
|
}
|
|
9734
|
-
function parseConfigText4(
|
|
9735
|
-
if (/\.json$/i.test(
|
|
9775
|
+
function parseConfigText4(path45, text) {
|
|
9776
|
+
if (/\.json$/i.test(path45)) return JSON.parse(text);
|
|
9736
9777
|
return yaml4.load(text);
|
|
9737
9778
|
}
|
|
9738
9779
|
function normalizeOperatingNote(value) {
|
|
@@ -11688,10 +11729,10 @@ function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
|
|
|
11688
11729
|
const primaryDaemonId = daemonIds[0];
|
|
11689
11730
|
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
11690
11731
|
const events = [];
|
|
11691
|
-
for (const
|
|
11692
|
-
if (!existsSync15(
|
|
11732
|
+
for (const path45 of paths) {
|
|
11733
|
+
if (!existsSync15(path45)) continue;
|
|
11693
11734
|
try {
|
|
11694
|
-
const raw = readFileSync12(
|
|
11735
|
+
const raw = readFileSync12(path45, "utf-8");
|
|
11695
11736
|
const parsed = raw.split("\n").filter(Boolean).flatMap((line) => {
|
|
11696
11737
|
try {
|
|
11697
11738
|
return [JSON.parse(line)];
|
|
@@ -11699,7 +11740,7 @@ function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
|
|
|
11699
11740
|
return [];
|
|
11700
11741
|
}
|
|
11701
11742
|
});
|
|
11702
|
-
const filtered = primaryDaemonId &&
|
|
11743
|
+
const filtered = primaryDaemonId && path45 === getPendingEventsPath(meshId) ? parsed.filter((e) => !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId)) : parsed;
|
|
11703
11744
|
events.push(...filtered);
|
|
11704
11745
|
} catch {
|
|
11705
11746
|
}
|
|
@@ -11764,11 +11805,26 @@ function reconcilePendingMeshCoordinatorEvents(meshId, events) {
|
|
|
11764
11805
|
const reconciled = terminalJobIds.size === 0 ? events : events.filter((event) => !(event.event === "refine:accepted" && terminalJobIds.has(readRefineJobId2(event))));
|
|
11765
11806
|
return backfilled.length === 0 ? reconciled : [...reconciled, ...backfilled];
|
|
11766
11807
|
}
|
|
11767
|
-
function
|
|
11808
|
+
function prunePendingMeshCoordinatorEventsRetention() {
|
|
11809
|
+
try {
|
|
11810
|
+
const removed = MeshRuntimeStore.getInstance().prunePendingEvents({
|
|
11811
|
+
drainedOlderThanMs: PENDING_EVENTS_DRAINED_RETENTION_MS,
|
|
11812
|
+
undrainedOlderThanMs: PENDING_EVENTS_UNDRAINED_RETENTION_MS
|
|
11813
|
+
});
|
|
11814
|
+
if (removed > 0) {
|
|
11815
|
+
LOG.info("MeshEvents", `Pruned ${removed} stale pending-event row(s) (drained >7d / undrained >30d)`);
|
|
11816
|
+
}
|
|
11817
|
+
return removed;
|
|
11818
|
+
} catch (e) {
|
|
11819
|
+
LOG.warn("MeshEvents", `Pending-event retention prune failed: ${e?.message || e}`);
|
|
11820
|
+
return 0;
|
|
11821
|
+
}
|
|
11822
|
+
}
|
|
11823
|
+
function trimPendingEventsIfNeeded(path45) {
|
|
11768
11824
|
try {
|
|
11769
|
-
if (!existsSync15(
|
|
11770
|
-
if (statSync6(
|
|
11771
|
-
const lines = readFileSync12(
|
|
11825
|
+
if (!existsSync15(path45)) return;
|
|
11826
|
+
if (statSync6(path45).size <= MAX_PENDING_EVENTS_BYTES) return;
|
|
11827
|
+
const lines = readFileSync12(path45, "utf-8").split("\n").filter(Boolean);
|
|
11772
11828
|
if (lines.length <= MAX_PENDING_EVENTS_KEEP) return;
|
|
11773
11829
|
const dropped = lines.slice(0, lines.length - MAX_PENDING_EVENTS_KEEP);
|
|
11774
11830
|
for (const line of dropped) {
|
|
@@ -11801,7 +11857,7 @@ function trimPendingEventsIfNeeded(path44) {
|
|
|
11801
11857
|
LOG.warn("MeshEvents", `Failed to ledger-record trim-dropped ${event.event} for mesh ${event.meshId}: ${e?.message || e}`);
|
|
11802
11858
|
}
|
|
11803
11859
|
}
|
|
11804
|
-
writeFileSync6(
|
|
11860
|
+
writeFileSync6(path45, lines.slice(-MAX_PENDING_EVENTS_KEEP).join("\n") + "\n", "utf-8");
|
|
11805
11861
|
} catch {
|
|
11806
11862
|
}
|
|
11807
11863
|
}
|
|
@@ -11809,18 +11865,24 @@ function stampPendingEventV2(event, hint) {
|
|
|
11809
11865
|
if (event.protocolVersion === MESH_PROTOCOL_VERSION_V2 && readNonEmptyString2(event.eventId)) {
|
|
11810
11866
|
return event;
|
|
11811
11867
|
}
|
|
11812
|
-
const
|
|
11868
|
+
const coordinatorIdentity = hint?.dispatchedBy ?? coordinatorIdentityFromEmitFields({
|
|
11813
11869
|
daemonId: event.targetCoordinatorDaemonId,
|
|
11814
11870
|
coordinatorRunId: hint?.coordinatorRunId,
|
|
11815
11871
|
sessionId: event.targetCoordinatorSessionId
|
|
11816
11872
|
});
|
|
11817
|
-
const
|
|
11873
|
+
const selfFallback = !coordinatorIdentity;
|
|
11874
|
+
const dispatchedBy = coordinatorIdentity ?? coordinatorIdentityFromEmitFields({
|
|
11875
|
+
daemonId: readNonEmptyString2(loadConfig().machineId)
|
|
11876
|
+
});
|
|
11877
|
+
const intendedFor = hint?.intendedFor ?? (selfFallback ? void 0 : coordinatorIdentity);
|
|
11818
11878
|
const stamp = buildPendingEventEmitStamp({
|
|
11819
11879
|
eventName: event.event,
|
|
11820
11880
|
eventId: randomUUID8(),
|
|
11821
11881
|
dispatchedBy,
|
|
11822
11882
|
intendedFor,
|
|
11823
|
-
|
|
11883
|
+
// Force broadcast for the self-fallback so a unicast-defaulting terminal
|
|
11884
|
+
// event isn't addressed to this daemon alone; an explicit hint still wins.
|
|
11885
|
+
scope: hint?.scope ?? (selfFallback ? "broadcast" : void 0)
|
|
11824
11886
|
});
|
|
11825
11887
|
if (!stamp) return event;
|
|
11826
11888
|
return {
|
|
@@ -11864,6 +11926,9 @@ function readV2EnvelopeFromWire(payload) {
|
|
|
11864
11926
|
}
|
|
11865
11927
|
function queuePendingMeshCoordinatorEvent(rawEvent, hint) {
|
|
11866
11928
|
const event = stampPendingEventV2(rawEvent, hint);
|
|
11929
|
+
return persistPendingMeshCoordinatorEvent(event);
|
|
11930
|
+
}
|
|
11931
|
+
function persistPendingMeshCoordinatorEvent(event) {
|
|
11867
11932
|
try {
|
|
11868
11933
|
if (hasPendingRefineTerminalEventDuplicate(event)) {
|
|
11869
11934
|
LOG.info("MeshEvents", `Suppressed duplicate pending ${event.event} for refine job ${readRefineJobId2(event)}`);
|
|
@@ -11898,9 +11963,9 @@ function queuePendingMeshCoordinatorEvent(rawEvent, hint) {
|
|
|
11898
11963
|
} catch {
|
|
11899
11964
|
}
|
|
11900
11965
|
try {
|
|
11901
|
-
const
|
|
11902
|
-
trimPendingEventsIfNeeded(
|
|
11903
|
-
appendFileSync2(
|
|
11966
|
+
const path45 = getPendingEventsPath(event.meshId, event.targetCoordinatorDaemonId);
|
|
11967
|
+
trimPendingEventsIfNeeded(path45);
|
|
11968
|
+
appendFileSync2(path45, JSON.stringify(event) + "\n", "utf-8");
|
|
11904
11969
|
} catch (e) {
|
|
11905
11970
|
if (!sqliteOk) throw e;
|
|
11906
11971
|
LOG.warn("MeshEvents", `JSONL append failed for mesh ${event.meshId}; SQLite holds the event: ${e?.message || e}`);
|
|
@@ -11911,10 +11976,10 @@ function queuePendingMeshCoordinatorEvent(rawEvent, hint) {
|
|
|
11911
11976
|
return false;
|
|
11912
11977
|
}
|
|
11913
11978
|
}
|
|
11914
|
-
function atomicDrainFile(
|
|
11915
|
-
const tmpPath = `${
|
|
11979
|
+
function atomicDrainFile(path45) {
|
|
11980
|
+
const tmpPath = `${path45}.draining`;
|
|
11916
11981
|
try {
|
|
11917
|
-
renameSync4(
|
|
11982
|
+
renameSync4(path45, tmpPath);
|
|
11918
11983
|
} catch {
|
|
11919
11984
|
return null;
|
|
11920
11985
|
}
|
|
@@ -11933,10 +11998,10 @@ function atomicDrainFile(path44) {
|
|
|
11933
11998
|
return null;
|
|
11934
11999
|
}
|
|
11935
12000
|
}
|
|
11936
|
-
function selectiveDrainFile(
|
|
11937
|
-
const tmpPath = `${
|
|
12001
|
+
function selectiveDrainFile(path45, predicate) {
|
|
12002
|
+
const tmpPath = `${path45}.draining`;
|
|
11938
12003
|
try {
|
|
11939
|
-
renameSync4(
|
|
12004
|
+
renameSync4(path45, tmpPath);
|
|
11940
12005
|
} catch {
|
|
11941
12006
|
return [];
|
|
11942
12007
|
}
|
|
@@ -11968,12 +12033,12 @@ function selectiveDrainFile(path44, predicate) {
|
|
|
11968
12033
|
}
|
|
11969
12034
|
try {
|
|
11970
12035
|
if (keptLines.length > 0) {
|
|
11971
|
-
writeFileSync6(
|
|
12036
|
+
writeFileSync6(path45, keptLines.join("\n") + "\n", "utf-8");
|
|
11972
12037
|
}
|
|
11973
12038
|
unlinkSync2(tmpPath);
|
|
11974
12039
|
} catch {
|
|
11975
12040
|
try {
|
|
11976
|
-
if (existsSync15(tmpPath) && !existsSync15(
|
|
12041
|
+
if (existsSync15(tmpPath) && !existsSync15(path45)) renameSync4(tmpPath, path45);
|
|
11977
12042
|
} catch {
|
|
11978
12043
|
}
|
|
11979
12044
|
return [];
|
|
@@ -12014,16 +12079,16 @@ function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
|
|
|
12014
12079
|
LOG.warn("MeshEvents", `SQLite pending-event drain failed for mesh ${meshId}; JSONL fallback only: ${e?.message || e}`);
|
|
12015
12080
|
}
|
|
12016
12081
|
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
12017
|
-
for (const
|
|
12018
|
-
const isSharedFile = !!primaryDaemonId &&
|
|
12082
|
+
for (const path45 of paths) {
|
|
12083
|
+
const isSharedFile = !!primaryDaemonId && path45 === getPendingEventsPath(meshId);
|
|
12019
12084
|
const targets = (e) => !isSharedFile || !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId);
|
|
12020
12085
|
if (onlyEvents) {
|
|
12021
|
-
for (const event of selectiveDrainFile(
|
|
12086
|
+
for (const event of selectiveDrainFile(path45, (e) => targets(e) && matchesFilter(e.event))) {
|
|
12022
12087
|
pushUnique(event);
|
|
12023
12088
|
}
|
|
12024
12089
|
continue;
|
|
12025
12090
|
}
|
|
12026
|
-
const content = atomicDrainFile(
|
|
12091
|
+
const content = atomicDrainFile(path45);
|
|
12027
12092
|
if (!content) continue;
|
|
12028
12093
|
const parsed = content.split("\n").filter(Boolean).flatMap((line) => {
|
|
12029
12094
|
try {
|
|
@@ -12064,9 +12129,9 @@ function retractPendingDispatchBlockedEvent(meshId, taskId, coordinatorDaemonId)
|
|
|
12064
12129
|
const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
|
|
12065
12130
|
const primaryDaemonId = daemonIds[0];
|
|
12066
12131
|
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
12067
|
-
for (const
|
|
12132
|
+
for (const path45 of paths) {
|
|
12068
12133
|
try {
|
|
12069
|
-
removed += selectiveDrainFile(
|
|
12134
|
+
removed += selectiveDrainFile(path45, matchesTask).length;
|
|
12070
12135
|
} catch {
|
|
12071
12136
|
}
|
|
12072
12137
|
}
|
|
@@ -12118,18 +12183,19 @@ function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
12118
12183
|
} catch {
|
|
12119
12184
|
}
|
|
12120
12185
|
const paths = coordinatorDaemonId ? [getPendingEventsPath(meshId, coordinatorDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
12121
|
-
for (const
|
|
12122
|
-
if (existsSync15(
|
|
12123
|
-
unlinkSync2(
|
|
12186
|
+
for (const path45 of paths) {
|
|
12187
|
+
if (existsSync15(path45)) try {
|
|
12188
|
+
unlinkSync2(path45);
|
|
12124
12189
|
} catch {
|
|
12125
12190
|
}
|
|
12126
12191
|
}
|
|
12127
12192
|
}
|
|
12128
|
-
var REFINE_TERMINAL_EVENTS, meshV2DrainCounters, warnedV2Violations, TERMINAL_COMPLETION_EVENTS, MAX_PENDING_EVENTS_BYTES, MAX_PENDING_EVENTS_KEEP;
|
|
12193
|
+
var REFINE_TERMINAL_EVENTS, meshV2DrainCounters, warnedV2Violations, TERMINAL_COMPLETION_EVENTS, MAX_PENDING_EVENTS_BYTES, MAX_PENDING_EVENTS_KEEP, PENDING_EVENTS_DRAINED_RETENTION_MS, PENDING_EVENTS_UNDRAINED_RETENTION_MS;
|
|
12129
12194
|
var init_mesh_events_pending = __esm({
|
|
12130
12195
|
"src/mesh/mesh-events-pending.ts"() {
|
|
12131
12196
|
"use strict";
|
|
12132
12197
|
init_logger();
|
|
12198
|
+
init_config();
|
|
12133
12199
|
init_mesh_ledger();
|
|
12134
12200
|
init_mesh_runtime_store();
|
|
12135
12201
|
init_mesh_events_utils();
|
|
@@ -12165,6 +12231,8 @@ var init_mesh_events_pending = __esm({
|
|
|
12165
12231
|
TERMINAL_COMPLETION_EVENTS = /* @__PURE__ */ new Set(["agent:generating_completed", "agent:stopped"]);
|
|
12166
12232
|
MAX_PENDING_EVENTS_BYTES = 100 * 1024;
|
|
12167
12233
|
MAX_PENDING_EVENTS_KEEP = 50;
|
|
12234
|
+
PENDING_EVENTS_DRAINED_RETENTION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
12235
|
+
PENDING_EVENTS_UNDRAINED_RETENTION_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
12168
12236
|
}
|
|
12169
12237
|
});
|
|
12170
12238
|
|
|
@@ -12802,9 +12870,9 @@ function findBinary(name) {
|
|
|
12802
12870
|
for (const ext of exes) {
|
|
12803
12871
|
const fullPath = path11.join(p, trimmed + ext);
|
|
12804
12872
|
try {
|
|
12805
|
-
const
|
|
12806
|
-
if (
|
|
12807
|
-
const stat2 =
|
|
12873
|
+
const fs41 = __require("fs");
|
|
12874
|
+
if (fs41.existsSync(fullPath)) {
|
|
12875
|
+
const stat2 = fs41.statSync(fullPath);
|
|
12808
12876
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
12809
12877
|
return fullPath;
|
|
12810
12878
|
}
|
|
@@ -12818,12 +12886,12 @@ function findBinary(name) {
|
|
|
12818
12886
|
function isScriptBinary(binaryPath) {
|
|
12819
12887
|
if (!path11.isAbsolute(binaryPath)) return false;
|
|
12820
12888
|
try {
|
|
12821
|
-
const
|
|
12822
|
-
const resolved =
|
|
12889
|
+
const fs41 = __require("fs");
|
|
12890
|
+
const resolved = fs41.realpathSync(binaryPath);
|
|
12823
12891
|
const head = Buffer.alloc(8);
|
|
12824
|
-
const fd =
|
|
12825
|
-
|
|
12826
|
-
|
|
12892
|
+
const fd = fs41.openSync(resolved, "r");
|
|
12893
|
+
fs41.readSync(fd, head, 0, 8, 0);
|
|
12894
|
+
fs41.closeSync(fd);
|
|
12827
12895
|
let i = 0;
|
|
12828
12896
|
if (head[0] === 239 && head[1] === 187 && head[2] === 191) i = 3;
|
|
12829
12897
|
return head[i] === 35 && head[i + 1] === 33;
|
|
@@ -12834,12 +12902,12 @@ function isScriptBinary(binaryPath) {
|
|
|
12834
12902
|
function looksLikeMachOOrElf(filePath) {
|
|
12835
12903
|
if (!path11.isAbsolute(filePath)) return false;
|
|
12836
12904
|
try {
|
|
12837
|
-
const
|
|
12838
|
-
const resolved =
|
|
12905
|
+
const fs41 = __require("fs");
|
|
12906
|
+
const resolved = fs41.realpathSync(filePath);
|
|
12839
12907
|
const buf = Buffer.alloc(8);
|
|
12840
|
-
const fd =
|
|
12841
|
-
|
|
12842
|
-
|
|
12908
|
+
const fd = fs41.openSync(resolved, "r");
|
|
12909
|
+
fs41.readSync(fd, buf, 0, 8, 0);
|
|
12910
|
+
fs41.closeSync(fd);
|
|
12843
12911
|
let i = 0;
|
|
12844
12912
|
if (buf[0] === 239 && buf[1] === 187 && buf[2] === 191) i = 3;
|
|
12845
12913
|
const b = buf.subarray(i);
|
|
@@ -17225,6 +17293,11 @@ function sweepExpiredRemoteIdleSessions() {
|
|
|
17225
17293
|
MeshRuntimeStore.getInstance().pruneExpiredRemoteIdleSessions();
|
|
17226
17294
|
} catch {
|
|
17227
17295
|
}
|
|
17296
|
+
const now = Date.now();
|
|
17297
|
+
if (now - lastPendingEventsPruneAt >= PENDING_EVENTS_PRUNE_INTERVAL_MS) {
|
|
17298
|
+
lastPendingEventsPruneAt = now;
|
|
17299
|
+
prunePendingMeshCoordinatorEventsRetention();
|
|
17300
|
+
}
|
|
17228
17301
|
}
|
|
17229
17302
|
function isIntentionalCleanupStopMetadata(event) {
|
|
17230
17303
|
return event.intentional === true || event.intentionalStop === true || event.operatorCleanup === true || event.reason === "operator_cleanup" || event.stopReason === "operator_cleanup" || event.cleanupReason === "operator_cleanup" || event.source === "mesh_cleanup_sessions" || event.source === "mesh_remove_node";
|
|
@@ -18283,7 +18356,7 @@ function setupMeshEventForwarding(components) {
|
|
|
18283
18356
|
flushPendingForMeshIdleCoordinators(components, routing.meshId);
|
|
18284
18357
|
});
|
|
18285
18358
|
}
|
|
18286
|
-
var REMOTE_IDLE_SESSION_TTL_MS, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, RECONCILED_COMPLETION_SOURCES, coordinatorForwardLanes;
|
|
18359
|
+
var REMOTE_IDLE_SESSION_TTL_MS, meshByWorkspaceCache, MESH_WORKSPACE_CACHE_TTL_MS, lastPendingEventsPruneAt, PENDING_EVENTS_PRUNE_INTERVAL_MS, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, RECONCILED_COMPLETION_SOURCES, coordinatorForwardLanes;
|
|
18287
18360
|
var init_mesh_event_forwarding = __esm({
|
|
18288
18361
|
"src/mesh/mesh-event-forwarding.ts"() {
|
|
18289
18362
|
"use strict";
|
|
@@ -18310,6 +18383,8 @@ var init_mesh_event_forwarding = __esm({
|
|
|
18310
18383
|
REMOTE_IDLE_SESSION_TTL_MS = 5 * 60 * 1e3;
|
|
18311
18384
|
meshByWorkspaceCache = /* @__PURE__ */ new Map();
|
|
18312
18385
|
MESH_WORKSPACE_CACHE_TTL_MS = 5e3;
|
|
18386
|
+
lastPendingEventsPruneAt = 0;
|
|
18387
|
+
PENDING_EVENTS_PRUNE_INTERVAL_MS = 60 * 60 * 1e3;
|
|
18313
18388
|
INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS = 30 * 60 * 1e3;
|
|
18314
18389
|
RECENT_COMPLETION_FINGERPRINT_TTL_MS = 10 * 60 * 1e3;
|
|
18315
18390
|
RECONCILED_COMPLETION_SOURCES = /* @__PURE__ */ new Set([
|
|
@@ -18332,40 +18407,48 @@ var init_mesh_events_coordinator = __esm({
|
|
|
18332
18407
|
}
|
|
18333
18408
|
});
|
|
18334
18409
|
|
|
18335
|
-
// src/mesh/mesh-reconcile-
|
|
18336
|
-
function
|
|
18337
|
-
const
|
|
18338
|
-
|
|
18339
|
-
|
|
18340
|
-
if (Number.isFinite(parsed) && parsed >= 60 * 6e4 && parsed <= 30 * 24 * 60 * 6e4) return parsed;
|
|
18341
|
-
}
|
|
18342
|
-
return DEFAULT_AUTO_PRUNE_MIN_AGE_MS;
|
|
18410
|
+
// src/mesh/mesh-reconcile-identity.ts
|
|
18411
|
+
function resolveCoordinatorDaemonIds(components) {
|
|
18412
|
+
const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
|
|
18413
|
+
const machineId = readNonEmptyString2(loadConfig().machineId);
|
|
18414
|
+
return expandDaemonIdForms([statusInstanceId, machineId]);
|
|
18343
18415
|
}
|
|
18344
|
-
function
|
|
18345
|
-
|
|
18416
|
+
function daemonHostsMesh(mesh, daemonIds) {
|
|
18417
|
+
const host = mesh.meshHost;
|
|
18418
|
+
if (!host) return true;
|
|
18419
|
+
if (host.role && host.role !== "host") return false;
|
|
18420
|
+
const hostDaemonId = readNonEmptyString2(host.hostDaemonId);
|
|
18421
|
+
if (!hostDaemonId) return true;
|
|
18422
|
+
return daemonIdListIncludes(daemonIds, hostDaemonId);
|
|
18346
18423
|
}
|
|
18347
|
-
function
|
|
18348
|
-
|
|
18349
|
-
|
|
18350
|
-
const parsed = Number.parseInt(raw, 10);
|
|
18351
|
-
if (Number.isFinite(parsed) && parsed >= 1e3 && parsed <= 6e4) return parsed;
|
|
18352
|
-
}
|
|
18353
|
-
return DEFAULT_RECONCILE_INTERVAL_MS;
|
|
18424
|
+
function daemonIdListIncludes(ids, id) {
|
|
18425
|
+
if (!id) return false;
|
|
18426
|
+
return ids.some((candidate) => candidate === id || daemonIdsEquivalent(candidate, id));
|
|
18354
18427
|
}
|
|
18355
|
-
function
|
|
18356
|
-
const
|
|
18357
|
-
|
|
18358
|
-
const
|
|
18359
|
-
|
|
18428
|
+
function resolveCoordinatorSelfIds(mesh, drainDaemonIds) {
|
|
18429
|
+
const ids = new Set(drainDaemonIds);
|
|
18430
|
+
for (const node of mesh.nodes) {
|
|
18431
|
+
const nodeDaemonId = readNonEmptyString2(node.daemonId);
|
|
18432
|
+
const nodeMachineId = readNonEmptyString2(node.machineId);
|
|
18433
|
+
const isSelf = nodeDaemonId && daemonIdListIncludes(drainDaemonIds, nodeDaemonId) || nodeMachineId && daemonIdListIncludes(drainDaemonIds, nodeMachineId);
|
|
18434
|
+
if (!isSelf) continue;
|
|
18435
|
+
if (nodeDaemonId) ids.add(nodeDaemonId);
|
|
18436
|
+
if (nodeMachineId) ids.add(nodeMachineId);
|
|
18360
18437
|
}
|
|
18361
|
-
|
|
18362
|
-
|
|
18363
|
-
|
|
18364
|
-
return resolveTunedReconcileMs("MESH_INFLIGHT_ACKED_DEATH_DEADLINE_MS", 8 * 6e4, 0, 60 * 6e4);
|
|
18365
|
-
}
|
|
18366
|
-
function resolveAckedTranscriptFastTrackGraceMs() {
|
|
18367
|
-
return resolveTunedReconcileMs("MESH_INFLIGHT_ACKED_TRANSCRIPT_FASTTRACK_GRACE_MS", 4e4, 0, 5 * 6e4);
|
|
18438
|
+
const hostDaemonId = readNonEmptyString2(mesh.meshHost?.hostDaemonId);
|
|
18439
|
+
if (hostDaemonId && daemonIdListIncludes([...ids], hostDaemonId)) ids.add(hostDaemonId);
|
|
18440
|
+
return [...ids];
|
|
18368
18441
|
}
|
|
18442
|
+
var init_mesh_reconcile_identity = __esm({
|
|
18443
|
+
"src/mesh/mesh-reconcile-identity.ts"() {
|
|
18444
|
+
"use strict";
|
|
18445
|
+
init_config();
|
|
18446
|
+
init_dist();
|
|
18447
|
+
init_mesh_events_utils();
|
|
18448
|
+
}
|
|
18449
|
+
});
|
|
18450
|
+
|
|
18451
|
+
// src/mesh/mesh-reconcile-v2-backstop.ts
|
|
18369
18452
|
function getMeshV2BackstopCounters() {
|
|
18370
18453
|
return { ...meshV2BackstopCounters };
|
|
18371
18454
|
}
|
|
@@ -18381,6 +18464,37 @@ function recordBackstopFire(kind, detail) {
|
|
|
18381
18464
|
LOG.warn("MeshReconcileV2", `v2 ENFORCE last-resort backstop fired (${kind}): ${detail}. Under a healthy v2 completion contract this should be 0 \u2014 a worker's real terminal emit was lost/late.`);
|
|
18382
18465
|
}
|
|
18383
18466
|
}
|
|
18467
|
+
var meshV2BackstopCounters;
|
|
18468
|
+
var init_mesh_reconcile_v2_backstop = __esm({
|
|
18469
|
+
"src/mesh/mesh-reconcile-v2-backstop.ts"() {
|
|
18470
|
+
"use strict";
|
|
18471
|
+
init_logger();
|
|
18472
|
+
meshV2BackstopCounters = {
|
|
18473
|
+
/** PHASE-4 transcript synthesis actually reconciled a missing completion. */
|
|
18474
|
+
phase4SynthesisFired: 0,
|
|
18475
|
+
/** Acked-hold transcript fast-track promoted a synth ahead of the death deadline. */
|
|
18476
|
+
ackedHoldFastTrackFired: 0,
|
|
18477
|
+
/** Acked-hold death-deadline backstop released a held synth (the 8-min net). */
|
|
18478
|
+
ackedHoldDeathDeadlineFired: 0
|
|
18479
|
+
};
|
|
18480
|
+
}
|
|
18481
|
+
});
|
|
18482
|
+
|
|
18483
|
+
// src/mesh/mesh-reconcile-acked-hold.ts
|
|
18484
|
+
function resolveTunedReconcileMs(envName, def, min, max) {
|
|
18485
|
+
const raw = readNonEmptyString2(process.env[envName]);
|
|
18486
|
+
if (raw) {
|
|
18487
|
+
const parsed = Number.parseInt(raw, 10);
|
|
18488
|
+
if (Number.isFinite(parsed) && parsed >= min && parsed <= max) return parsed;
|
|
18489
|
+
}
|
|
18490
|
+
return def;
|
|
18491
|
+
}
|
|
18492
|
+
function resolveAckedDeathDeadlineMs() {
|
|
18493
|
+
return resolveTunedReconcileMs("MESH_INFLIGHT_ACKED_DEATH_DEADLINE_MS", 8 * 6e4, 0, 60 * 6e4);
|
|
18494
|
+
}
|
|
18495
|
+
function resolveAckedTranscriptFastTrackGraceMs() {
|
|
18496
|
+
return resolveTunedReconcileMs("MESH_INFLIGHT_ACKED_TRANSCRIPT_FASTTRACK_GRACE_MS", 4e4, 0, 5 * 6e4);
|
|
18497
|
+
}
|
|
18384
18498
|
function inFlightSynthKey(meshId, taskId) {
|
|
18385
18499
|
return `${meshId}::${taskId}`;
|
|
18386
18500
|
}
|
|
@@ -18463,36 +18577,54 @@ function rehydrateAckedHoldsForMesh(meshId) {
|
|
|
18463
18577
|
LOG.info("MeshReconcile", `Rehydrated ${rows.length} persisted acked-hold row(s) for mesh ${meshId} after (re)start`);
|
|
18464
18578
|
}
|
|
18465
18579
|
}
|
|
18466
|
-
function
|
|
18467
|
-
const
|
|
18468
|
-
const
|
|
18469
|
-
|
|
18580
|
+
function collectHeldSynthKeysForMesh(meshId) {
|
|
18581
|
+
const heldKeys = /* @__PURE__ */ new Set();
|
|
18582
|
+
for (const key2 of inFlightAckedHoldState.keys()) {
|
|
18583
|
+
if (key2.startsWith(`${meshId}::`)) heldKeys.add(key2);
|
|
18584
|
+
}
|
|
18585
|
+
const store = holdStore();
|
|
18586
|
+
if (store) {
|
|
18587
|
+
try {
|
|
18588
|
+
for (const row of store.listInflightHoldsByMesh(meshId)) {
|
|
18589
|
+
heldKeys.add(inFlightSynthKey(meshId, row.taskId));
|
|
18590
|
+
}
|
|
18591
|
+
} catch {
|
|
18592
|
+
}
|
|
18593
|
+
}
|
|
18594
|
+
return heldKeys;
|
|
18470
18595
|
}
|
|
18471
|
-
|
|
18472
|
-
|
|
18473
|
-
|
|
18474
|
-
|
|
18475
|
-
|
|
18476
|
-
|
|
18477
|
-
|
|
18596
|
+
var ACKED_DEATH_CONSECUTIVE_READ_FAILURES, inFlightAckedHoldState, rehydratedHoldMeshes;
|
|
18597
|
+
var init_mesh_reconcile_acked_hold = __esm({
|
|
18598
|
+
"src/mesh/mesh-reconcile-acked-hold.ts"() {
|
|
18599
|
+
"use strict";
|
|
18600
|
+
init_logger();
|
|
18601
|
+
init_mesh_runtime_store();
|
|
18602
|
+
init_mesh_events_utils();
|
|
18603
|
+
ACKED_DEATH_CONSECUTIVE_READ_FAILURES = 3;
|
|
18604
|
+
inFlightAckedHoldState = /* @__PURE__ */ new Map();
|
|
18605
|
+
rehydratedHoldMeshes = /* @__PURE__ */ new Set();
|
|
18606
|
+
}
|
|
18607
|
+
});
|
|
18608
|
+
|
|
18609
|
+
// src/mesh/mesh-reconcile-loop.ts
|
|
18610
|
+
function resolveAutoPruneMinAgeMs() {
|
|
18611
|
+
const raw = readNonEmptyString2(process.env.MESH_AUTO_PRUNE_MIN_AGE_MS);
|
|
18612
|
+
if (raw) {
|
|
18613
|
+
const parsed = Number.parseInt(raw, 10);
|
|
18614
|
+
if (Number.isFinite(parsed) && parsed >= 60 * 6e4 && parsed <= 30 * 24 * 60 * 6e4) return parsed;
|
|
18615
|
+
}
|
|
18616
|
+
return DEFAULT_AUTO_PRUNE_MIN_AGE_MS;
|
|
18478
18617
|
}
|
|
18479
|
-
function
|
|
18480
|
-
|
|
18481
|
-
return ids.some((candidate) => candidate === id || daemonIdsEquivalent(candidate, id));
|
|
18618
|
+
function resolvePendingHeldDrainEscalateMs() {
|
|
18619
|
+
return resolveTunedReconcileMs("MESH_PENDING_HELD_DRAIN_ESCALATE_MS", DEFAULT_PENDING_HELD_DRAIN_ESCALATE_MS, 4e3, 5 * 6e4);
|
|
18482
18620
|
}
|
|
18483
|
-
function
|
|
18484
|
-
const
|
|
18485
|
-
|
|
18486
|
-
const
|
|
18487
|
-
|
|
18488
|
-
const isSelf = nodeDaemonId && daemonIdListIncludes(drainDaemonIds, nodeDaemonId) || nodeMachineId && daemonIdListIncludes(drainDaemonIds, nodeMachineId);
|
|
18489
|
-
if (!isSelf) continue;
|
|
18490
|
-
if (nodeDaemonId) ids.add(nodeDaemonId);
|
|
18491
|
-
if (nodeMachineId) ids.add(nodeMachineId);
|
|
18621
|
+
function resolveReconcileIntervalMs() {
|
|
18622
|
+
const raw = readNonEmptyString2(process.env.MESH_RECONCILE_INTERVAL_MS);
|
|
18623
|
+
if (raw) {
|
|
18624
|
+
const parsed = Number.parseInt(raw, 10);
|
|
18625
|
+
if (Number.isFinite(parsed) && parsed >= 1e3 && parsed <= 6e4) return parsed;
|
|
18492
18626
|
}
|
|
18493
|
-
|
|
18494
|
-
if (hostDaemonId && daemonIdListIncludes([...ids], hostDaemonId)) ids.add(hostDaemonId);
|
|
18495
|
-
return [...ids];
|
|
18627
|
+
return DEFAULT_RECONCILE_INTERVAL_MS;
|
|
18496
18628
|
}
|
|
18497
18629
|
function findLiveCoordinators(components) {
|
|
18498
18630
|
const out = [];
|
|
@@ -19258,19 +19390,7 @@ async function reconcileUnterminatedDirectDispatches(components, mesh, selfIds,
|
|
|
19258
19390
|
const activeTaskKeys = new Set(
|
|
19259
19391
|
dispatches.map((d) => readNonEmptyString2(d.taskId)).filter(Boolean).map((taskId) => inFlightSynthKey(mesh.id, taskId))
|
|
19260
19392
|
);
|
|
19261
|
-
const heldKeys =
|
|
19262
|
-
for (const key2 of inFlightAckedHoldState.keys()) {
|
|
19263
|
-
if (key2.startsWith(`${mesh.id}::`)) heldKeys.add(key2);
|
|
19264
|
-
}
|
|
19265
|
-
const store = holdStore();
|
|
19266
|
-
if (store) {
|
|
19267
|
-
try {
|
|
19268
|
-
for (const row of store.listInflightHoldsByMesh(mesh.id)) {
|
|
19269
|
-
heldKeys.add(inFlightSynthKey(mesh.id, row.taskId));
|
|
19270
|
-
}
|
|
19271
|
-
} catch {
|
|
19272
|
-
}
|
|
19273
|
-
}
|
|
19393
|
+
const heldKeys = collectHeldSynthKeysForMesh(mesh.id);
|
|
19274
19394
|
for (const key2 of heldKeys) {
|
|
19275
19395
|
if (!activeTaskKeys.has(key2)) deleteHoldState(key2, mesh.id);
|
|
19276
19396
|
}
|
|
@@ -19546,7 +19666,7 @@ function setupMeshReconcileLoop(components) {
|
|
|
19546
19666
|
}
|
|
19547
19667
|
};
|
|
19548
19668
|
}
|
|
19549
|
-
var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, DEFAULT_PENDING_HELD_DRAIN_ESCALATE_MS,
|
|
19669
|
+
var DEFAULT_RECONCILE_INTERVAL_MS, DEFAULT_AUTO_PRUNE_MIN_AGE_MS, DEFAULT_PENDING_HELD_DRAIN_ESCALATE_MS, coordinatorModalParkState, heldEventLedgerRecorded, ASSIGNED_STRANDED_DEADLINE_MS, DELIVERED_NO_TURN_DEADLINE_MS, RECLAIM_UNKNOWN_GRACE_TICKS, deliveredNoTurnUnknownStreak, STRICT_SESSION_MATCH_TTL_MS, unresolvedForwardRejectionCounts, MAX_FORWARD_REJECTIONS;
|
|
19550
19670
|
var init_mesh_reconcile_loop = __esm({
|
|
19551
19671
|
"src/mesh/mesh-reconcile-loop.ts"() {
|
|
19552
19672
|
"use strict";
|
|
@@ -19568,20 +19688,14 @@ var init_mesh_reconcile_loop = __esm({
|
|
|
19568
19688
|
init_mesh_active_work();
|
|
19569
19689
|
init_mesh_events_stale();
|
|
19570
19690
|
init_chat_message_normalization();
|
|
19691
|
+
init_mesh_reconcile_identity();
|
|
19692
|
+
init_mesh_reconcile_v2_backstop();
|
|
19693
|
+
init_mesh_reconcile_acked_hold();
|
|
19694
|
+
init_mesh_reconcile_v2_backstop();
|
|
19695
|
+
init_mesh_reconcile_acked_hold();
|
|
19571
19696
|
DEFAULT_RECONCILE_INTERVAL_MS = 4e3;
|
|
19572
19697
|
DEFAULT_AUTO_PRUNE_MIN_AGE_MS = 24 * 60 * 6e4;
|
|
19573
19698
|
DEFAULT_PENDING_HELD_DRAIN_ESCALATE_MS = 12e3;
|
|
19574
|
-
ACKED_DEATH_CONSECUTIVE_READ_FAILURES = 3;
|
|
19575
|
-
inFlightAckedHoldState = /* @__PURE__ */ new Map();
|
|
19576
|
-
rehydratedHoldMeshes = /* @__PURE__ */ new Set();
|
|
19577
|
-
meshV2BackstopCounters = {
|
|
19578
|
-
/** PHASE-4 transcript synthesis actually reconciled a missing completion. */
|
|
19579
|
-
phase4SynthesisFired: 0,
|
|
19580
|
-
/** Acked-hold transcript fast-track promoted a synth ahead of the death deadline. */
|
|
19581
|
-
ackedHoldFastTrackFired: 0,
|
|
19582
|
-
/** Acked-hold death-deadline backstop released a held synth (the 8-min net). */
|
|
19583
|
-
ackedHoldDeathDeadlineFired: 0
|
|
19584
|
-
};
|
|
19585
19699
|
coordinatorModalParkState = /* @__PURE__ */ new Map();
|
|
19586
19700
|
heldEventLedgerRecorded = /* @__PURE__ */ new Set();
|
|
19587
19701
|
ASSIGNED_STRANDED_DEADLINE_MS = 5 * 6e4;
|
|
@@ -20278,7 +20392,7 @@ function getCliValidator() {
|
|
|
20278
20392
|
return _cliValidator;
|
|
20279
20393
|
}
|
|
20280
20394
|
function formatIssue(err) {
|
|
20281
|
-
const
|
|
20395
|
+
const path45 = err.instancePath || "";
|
|
20282
20396
|
const params = err.params;
|
|
20283
20397
|
let message = err.message || "validation failed";
|
|
20284
20398
|
let allowed;
|
|
@@ -20296,7 +20410,7 @@ function formatIssue(err) {
|
|
|
20296
20410
|
} else if (err.keyword === "type") {
|
|
20297
20411
|
message = `must be ${params.type}`;
|
|
20298
20412
|
}
|
|
20299
|
-
return { path:
|
|
20413
|
+
return { path: path45, keyword: err.keyword, message, ...allowed !== void 0 ? { allowed } : {} };
|
|
20300
20414
|
}
|
|
20301
20415
|
function validateCliProviderManifest(manifest) {
|
|
20302
20416
|
const validator = getCliValidator();
|
|
@@ -20591,49 +20705,49 @@ function validateFsmSpec(raw) {
|
|
|
20591
20705
|
}
|
|
20592
20706
|
return errs;
|
|
20593
20707
|
}
|
|
20594
|
-
function validateCondition(c, sectionIds,
|
|
20708
|
+
function validateCondition(c, sectionIds, path45) {
|
|
20595
20709
|
const errs = [];
|
|
20596
20710
|
const w = c;
|
|
20597
20711
|
if ("all" in w) {
|
|
20598
|
-
w.all.forEach((x, i) => errs.push(...validateCondition(x, sectionIds, `${
|
|
20712
|
+
w.all.forEach((x, i) => errs.push(...validateCondition(x, sectionIds, `${path45}.all[${i}]`)));
|
|
20599
20713
|
return errs;
|
|
20600
20714
|
}
|
|
20601
20715
|
if ("any" in w) {
|
|
20602
|
-
w.any.forEach((x, i) => errs.push(...validateCondition(x, sectionIds, `${
|
|
20716
|
+
w.any.forEach((x, i) => errs.push(...validateCondition(x, sectionIds, `${path45}.any[${i}]`)));
|
|
20603
20717
|
return errs;
|
|
20604
20718
|
}
|
|
20605
20719
|
if ("not" in w) {
|
|
20606
|
-
errs.push(...validateCondition(w.not, sectionIds, `${
|
|
20720
|
+
errs.push(...validateCondition(w.not, sectionIds, `${path45}.not`));
|
|
20607
20721
|
return errs;
|
|
20608
20722
|
}
|
|
20609
20723
|
if ("matches" in w) {
|
|
20610
|
-
if (w.section && !sectionIds.has(w.section)) errs.push(`${
|
|
20724
|
+
if (w.section && !sectionIds.has(w.section)) errs.push(`${path45}.section "${w.section}" unknown`);
|
|
20611
20725
|
try {
|
|
20612
20726
|
new RegExp(w.matches, w.flags ?? "i");
|
|
20613
20727
|
} catch (e) {
|
|
20614
|
-
errs.push(`${
|
|
20728
|
+
errs.push(`${path45}.matches invalid regex: ${e.message}`);
|
|
20615
20729
|
}
|
|
20616
20730
|
return errs;
|
|
20617
20731
|
}
|
|
20618
20732
|
if ("cursor_above" in w && "changed" in w) return errs;
|
|
20619
20733
|
if ("elapsed_ms" in w) {
|
|
20620
|
-
if (typeof w.elapsed_ms !== "number") errs.push(`${
|
|
20734
|
+
if (typeof w.elapsed_ms !== "number") errs.push(`${path45}.elapsed_ms must be a number`);
|
|
20621
20735
|
return errs;
|
|
20622
20736
|
}
|
|
20623
20737
|
if ("stable_ms" in w) {
|
|
20624
|
-
if (typeof w.stable_ms !== "number") errs.push(`${
|
|
20625
|
-
if (w.section && !sectionIds.has(w.section)) errs.push(`${
|
|
20738
|
+
if (typeof w.stable_ms !== "number") errs.push(`${path45}.stable_ms must be a number`);
|
|
20739
|
+
if (w.section && !sectionIds.has(w.section)) errs.push(`${path45}.section "${w.section}" unknown`);
|
|
20626
20740
|
if (w.ignore_lines !== void 0) {
|
|
20627
|
-
if (typeof w.ignore_lines !== "string") errs.push(`${
|
|
20741
|
+
if (typeof w.ignore_lines !== "string") errs.push(`${path45}.ignore_lines must be a string`);
|
|
20628
20742
|
else try {
|
|
20629
20743
|
new RegExp(w.ignore_lines, "m");
|
|
20630
20744
|
} catch (e) {
|
|
20631
|
-
errs.push(`${
|
|
20745
|
+
errs.push(`${path45}.ignore_lines invalid regex: ${e.message}`);
|
|
20632
20746
|
}
|
|
20633
20747
|
}
|
|
20634
20748
|
return errs;
|
|
20635
20749
|
}
|
|
20636
|
-
errs.push(`${
|
|
20750
|
+
errs.push(`${path45} is not a recognized condition`);
|
|
20637
20751
|
return errs;
|
|
20638
20752
|
}
|
|
20639
20753
|
var init_fsm_loader = __esm({
|
|
@@ -21130,8 +21244,8 @@ var init_pty_transport = __esm({
|
|
|
21130
21244
|
let cwd = options.cwd;
|
|
21131
21245
|
if (cwd) {
|
|
21132
21246
|
try {
|
|
21133
|
-
const
|
|
21134
|
-
const stat2 =
|
|
21247
|
+
const fs41 = __require("fs");
|
|
21248
|
+
const stat2 = fs41.statSync(cwd);
|
|
21135
21249
|
if (!stat2.isDirectory()) cwd = os14.homedir();
|
|
21136
21250
|
} catch {
|
|
21137
21251
|
cwd = os14.homedir();
|
|
@@ -24926,7 +25040,7 @@ __export(require_whitelist_exports, {
|
|
|
24926
25040
|
registerProviderScriptRoot: () => registerProviderScriptRoot,
|
|
24927
25041
|
unregisterProviderScriptRoot: () => unregisterProviderScriptRoot
|
|
24928
25042
|
});
|
|
24929
|
-
import * as
|
|
25043
|
+
import * as path35 from "path";
|
|
24930
25044
|
import { createRequire as createRequire3 } from "module";
|
|
24931
25045
|
import * as nodeFs from "fs";
|
|
24932
25046
|
import * as nodeChildProcess from "child_process";
|
|
@@ -25067,7 +25181,7 @@ function _getRegisteredRoots() {
|
|
|
25067
25181
|
}
|
|
25068
25182
|
function canonicalize(p) {
|
|
25069
25183
|
try {
|
|
25070
|
-
const resolved =
|
|
25184
|
+
const resolved = path35.resolve(p);
|
|
25071
25185
|
try {
|
|
25072
25186
|
return nodeFs.realpathSync.native ? nodeFs.realpathSync.native(resolved) : nodeFs.realpathSync(resolved);
|
|
25073
25187
|
} catch {
|
|
@@ -25087,7 +25201,7 @@ function isCallerInsideGatedRoot(callerFilename) {
|
|
|
25087
25201
|
}
|
|
25088
25202
|
for (const root of _gatedRoots) {
|
|
25089
25203
|
if (normalized === root.rootPath) return root;
|
|
25090
|
-
if (normalized.startsWith(root.rootPath +
|
|
25204
|
+
if (normalized.startsWith(root.rootPath + path35.sep)) return root;
|
|
25091
25205
|
}
|
|
25092
25206
|
return null;
|
|
25093
25207
|
}
|
|
@@ -25106,16 +25220,16 @@ function ensureInstalled() {
|
|
|
25106
25220
|
};
|
|
25107
25221
|
}
|
|
25108
25222
|
function gatedRequire(request, parent, isMain, gated, originalLoad) {
|
|
25109
|
-
if (request.startsWith("./") || request.startsWith("../") ||
|
|
25223
|
+
if (request.startsWith("./") || request.startsWith("../") || path35.isAbsolute(request)) {
|
|
25110
25224
|
let resolved;
|
|
25111
25225
|
try {
|
|
25112
|
-
const callerRequire = parent?.filename ? createRequire3(parent.filename) : createRequire3(
|
|
25226
|
+
const callerRequire = parent?.filename ? createRequire3(parent.filename) : createRequire3(path35.join(gated.rootPath, "__entry__.js"));
|
|
25113
25227
|
resolved = callerRequire.resolve(request);
|
|
25114
25228
|
} catch {
|
|
25115
25229
|
return originalLoad.call(this, request, parent, isMain);
|
|
25116
25230
|
}
|
|
25117
25231
|
const resolvedCanon = canonicalize(resolved) || resolved;
|
|
25118
|
-
if (!(resolvedCanon === gated.rootPath || resolvedCanon.startsWith(gated.rootPath +
|
|
25232
|
+
if (!(resolvedCanon === gated.rootPath || resolvedCanon.startsWith(gated.rootPath + path35.sep))) {
|
|
25119
25233
|
denyRequire(request, parent, `relative path escapes provider root (resolved to ${resolvedCanon})`);
|
|
25120
25234
|
}
|
|
25121
25235
|
return originalLoad.call(this, request, parent, isMain);
|
|
@@ -26832,17 +26946,17 @@ function checkPathExists(paths) {
|
|
|
26832
26946
|
return null;
|
|
26833
26947
|
}
|
|
26834
26948
|
async function detectIDEs(providerLoader) {
|
|
26835
|
-
const
|
|
26949
|
+
const os32 = platform5();
|
|
26836
26950
|
const results = [];
|
|
26837
26951
|
for (const def of getMergedDefinitions()) {
|
|
26838
26952
|
const cliPath = findCliCommand(providerLoader?.getIdeCliCommand(def.id, def.cli) || def.cli);
|
|
26839
|
-
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[
|
|
26953
|
+
const appPath = checkPathExists(providerLoader?.getIdePathCandidates(def.id, def.paths[os32] || []) || []);
|
|
26840
26954
|
let resolvedCli = cliPath;
|
|
26841
|
-
if (!resolvedCli && appPath &&
|
|
26955
|
+
if (!resolvedCli && appPath && os32 === "darwin") {
|
|
26842
26956
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
26843
26957
|
if (existsSync20(bundledCli)) resolvedCli = bundledCli;
|
|
26844
26958
|
}
|
|
26845
|
-
if (!resolvedCli && appPath &&
|
|
26959
|
+
if (!resolvedCli && appPath && os32 === "win32") {
|
|
26846
26960
|
const { dirname: dirname17 } = await import("path");
|
|
26847
26961
|
const appDir = dirname17(appPath);
|
|
26848
26962
|
const candidates = [
|
|
@@ -26859,7 +26973,7 @@ async function detectIDEs(providerLoader) {
|
|
|
26859
26973
|
}
|
|
26860
26974
|
}
|
|
26861
26975
|
}
|
|
26862
|
-
const installed =
|
|
26976
|
+
const installed = os32 === "darwin" ? !!(resolvedCli || appPath) : !!resolvedCli;
|
|
26863
26977
|
const version = null;
|
|
26864
26978
|
results.push({
|
|
26865
26979
|
id: def.id,
|
|
@@ -36289,9 +36403,9 @@ var DaemonCommandHandler = class {
|
|
|
36289
36403
|
* point at a sibling git checkout.
|
|
36290
36404
|
*/
|
|
36291
36405
|
getUpstreamInstallRoot() {
|
|
36292
|
-
const
|
|
36293
|
-
const
|
|
36294
|
-
return
|
|
36406
|
+
const os32 = __require("os");
|
|
36407
|
+
const path45 = __require("path");
|
|
36408
|
+
return path45.join(os32.homedir(), ".adhdev", "providers", ".upstream");
|
|
36295
36409
|
}
|
|
36296
36410
|
/**
|
|
36297
36411
|
* Download a single provider manifest from the registry and write it to
|
|
@@ -36315,8 +36429,8 @@ var DaemonCommandHandler = class {
|
|
|
36315
36429
|
return { success: false, error: "invalid type" };
|
|
36316
36430
|
}
|
|
36317
36431
|
const https = __require("https");
|
|
36318
|
-
const
|
|
36319
|
-
const
|
|
36432
|
+
const fs41 = __require("fs");
|
|
36433
|
+
const path45 = __require("path");
|
|
36320
36434
|
const REGISTRY = resolveRegistryBaseUrl(loadConfig().registryUrl);
|
|
36321
36435
|
function fetchText(url, timeoutMs) {
|
|
36322
36436
|
return new Promise((resolve25, reject) => {
|
|
@@ -36353,12 +36467,12 @@ var DaemonCommandHandler = class {
|
|
|
36353
36467
|
return { success: false, error: `checksum mismatch: expected ${meta.checksum}, got ${actualChecksum}` };
|
|
36354
36468
|
}
|
|
36355
36469
|
const installRoot = this.getUpstreamInstallRoot();
|
|
36356
|
-
const installRootResolved =
|
|
36357
|
-
const targetDir =
|
|
36358
|
-
if (!targetDir.startsWith(installRootResolved +
|
|
36470
|
+
const installRootResolved = path45.resolve(installRoot);
|
|
36471
|
+
const targetDir = path45.resolve(path45.join(installRoot, category, type));
|
|
36472
|
+
if (!targetDir.startsWith(installRootResolved + path45.sep)) {
|
|
36359
36473
|
return { success: false, error: "install path escaped upstream root" };
|
|
36360
36474
|
}
|
|
36361
|
-
|
|
36475
|
+
fs41.mkdirSync(targetDir, { recursive: true });
|
|
36362
36476
|
let manifestProbe = {};
|
|
36363
36477
|
try {
|
|
36364
36478
|
manifestProbe = JSON.parse(manifestBody);
|
|
@@ -36382,8 +36496,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36382
36496
|
}
|
|
36383
36497
|
}
|
|
36384
36498
|
const targetFile = isV1 ? "provider.v1.json" : "provider.json";
|
|
36385
|
-
const targetPath =
|
|
36386
|
-
|
|
36499
|
+
const targetPath = path45.join(targetDir, targetFile);
|
|
36500
|
+
fs41.writeFileSync(targetPath, manifestBody, "utf-8");
|
|
36387
36501
|
const manifestJson = JSON.parse(manifestBody);
|
|
36388
36502
|
const scriptFetch = await this.fetchProviderSources(
|
|
36389
36503
|
manifestJson,
|
|
@@ -36453,8 +36567,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36453
36567
|
const repo = source.repo;
|
|
36454
36568
|
const ref = source.ref;
|
|
36455
36569
|
const https = __require("https");
|
|
36456
|
-
const
|
|
36457
|
-
const
|
|
36570
|
+
const fs41 = __require("fs");
|
|
36571
|
+
const path45 = __require("path");
|
|
36458
36572
|
function fetchJson(url, timeoutMs) {
|
|
36459
36573
|
return new Promise((resolve25, reject) => {
|
|
36460
36574
|
const req = https.get(url, {
|
|
@@ -36510,9 +36624,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36510
36624
|
}
|
|
36511
36625
|
let fetchedCount = 0;
|
|
36512
36626
|
const sharedDirRel = `${category}/_shared`;
|
|
36513
|
-
const sharedTargetDir =
|
|
36514
|
-
const installRootResolved =
|
|
36515
|
-
if (sharedTargetDir.startsWith(installRootResolved +
|
|
36627
|
+
const sharedTargetDir = path45.resolve(path45.join(targetDir, "../_shared"));
|
|
36628
|
+
const installRootResolved = path45.resolve(path45.join(targetDir, "../.."));
|
|
36629
|
+
if (sharedTargetDir.startsWith(installRootResolved + path45.sep)) {
|
|
36516
36630
|
const sharedStack = [sharedDirRel];
|
|
36517
36631
|
while (sharedStack.length) {
|
|
36518
36632
|
const relDir = sharedStack.pop();
|
|
@@ -36535,10 +36649,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36535
36649
|
try {
|
|
36536
36650
|
const body = await fetchBinary(entry.download_url, 3e4);
|
|
36537
36651
|
const relInside = entry.path.startsWith(sharedDirRel + "/") ? entry.path.slice(sharedDirRel.length + 1) : entry.path;
|
|
36538
|
-
const outPath =
|
|
36539
|
-
if (!outPath.startsWith(
|
|
36540
|
-
|
|
36541
|
-
|
|
36652
|
+
const outPath = path45.resolve(path45.join(sharedTargetDir, relInside));
|
|
36653
|
+
if (!outPath.startsWith(path45.resolve(sharedTargetDir) + path45.sep)) continue;
|
|
36654
|
+
fs41.mkdirSync(path45.dirname(outPath), { recursive: true });
|
|
36655
|
+
fs41.writeFileSync(outPath, body);
|
|
36542
36656
|
fetchedCount++;
|
|
36543
36657
|
} catch (e) {
|
|
36544
36658
|
errors.push(`fetch shared ${entry.path}: ${e?.message ?? e}`);
|
|
@@ -36571,13 +36685,13 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36571
36685
|
try {
|
|
36572
36686
|
const body = await fetchBinary(entry.download_url, 3e4);
|
|
36573
36687
|
const relInsideProvider = entry.path.startsWith(subdir + "/") ? entry.path.slice(subdir.length + 1) : entry.path;
|
|
36574
|
-
const outPath =
|
|
36575
|
-
if (!outPath.startsWith(
|
|
36688
|
+
const outPath = path45.resolve(path45.join(targetDir, relInsideProvider));
|
|
36689
|
+
if (!outPath.startsWith(path45.resolve(targetDir) + path45.sep)) {
|
|
36576
36690
|
errors.push(`refusing to write outside targetDir: ${entry.path}`);
|
|
36577
36691
|
continue;
|
|
36578
36692
|
}
|
|
36579
|
-
|
|
36580
|
-
|
|
36693
|
+
fs41.mkdirSync(path45.dirname(outPath), { recursive: true });
|
|
36694
|
+
fs41.writeFileSync(outPath, body);
|
|
36581
36695
|
fetchedCount++;
|
|
36582
36696
|
} catch (e) {
|
|
36583
36697
|
errors.push(`fetch ${entry.path}: ${e?.message ?? e}`);
|
|
@@ -36605,19 +36719,19 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36605
36719
|
if (!["cli", "ide", "extension", "acp"].includes(category)) {
|
|
36606
36720
|
return { success: false, error: `unknown category: ${category}` };
|
|
36607
36721
|
}
|
|
36608
|
-
const
|
|
36609
|
-
const
|
|
36722
|
+
const fs41 = __require("fs");
|
|
36723
|
+
const path45 = __require("path");
|
|
36610
36724
|
try {
|
|
36611
36725
|
const installRoot = this.getUpstreamInstallRoot();
|
|
36612
|
-
const installRootResolved =
|
|
36613
|
-
const targetDir =
|
|
36614
|
-
if (!targetDir.startsWith(installRootResolved +
|
|
36726
|
+
const installRootResolved = path45.resolve(installRoot);
|
|
36727
|
+
const targetDir = path45.resolve(path45.join(installRoot, category, type));
|
|
36728
|
+
if (!targetDir.startsWith(installRootResolved + path45.sep)) {
|
|
36615
36729
|
return { success: false, error: "refusing to delete outside upstream root" };
|
|
36616
36730
|
}
|
|
36617
|
-
if (!
|
|
36731
|
+
if (!fs41.existsSync(targetDir)) {
|
|
36618
36732
|
return { success: false, error: "not installed" };
|
|
36619
36733
|
}
|
|
36620
|
-
|
|
36734
|
+
fs41.rmSync(targetDir, { recursive: true, force: true });
|
|
36621
36735
|
if (this._ctx.providerLoader) {
|
|
36622
36736
|
this._ctx.providerLoader.reload();
|
|
36623
36737
|
this._ctx.providerLoader.registerToDetector();
|
|
@@ -36633,28 +36747,28 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36633
36747
|
* the UI and by the update checker.
|
|
36634
36748
|
*/
|
|
36635
36749
|
handleListInstalledProviders(_args) {
|
|
36636
|
-
const
|
|
36637
|
-
const
|
|
36750
|
+
const fs41 = __require("fs");
|
|
36751
|
+
const path45 = __require("path");
|
|
36638
36752
|
const installRoot = this.getUpstreamInstallRoot();
|
|
36639
|
-
if (!
|
|
36753
|
+
if (!fs41.existsSync(installRoot)) return { success: true, providers: [] };
|
|
36640
36754
|
const CATEGORIES = ["cli", "ide", "extension", "acp"];
|
|
36641
36755
|
const items = [];
|
|
36642
36756
|
for (const category of CATEGORIES) {
|
|
36643
|
-
const categoryDir =
|
|
36644
|
-
if (!
|
|
36757
|
+
const categoryDir = path45.join(installRoot, category);
|
|
36758
|
+
if (!fs41.existsSync(categoryDir)) continue;
|
|
36645
36759
|
let entries;
|
|
36646
36760
|
try {
|
|
36647
|
-
entries =
|
|
36761
|
+
entries = fs41.readdirSync(categoryDir);
|
|
36648
36762
|
} catch {
|
|
36649
36763
|
continue;
|
|
36650
36764
|
}
|
|
36651
36765
|
for (const type of entries) {
|
|
36652
|
-
const v1Path =
|
|
36653
|
-
const v0Path =
|
|
36654
|
-
const manifestPath =
|
|
36766
|
+
const v1Path = path45.join(categoryDir, type, "provider.v1.json");
|
|
36767
|
+
const v0Path = path45.join(categoryDir, type, "provider.json");
|
|
36768
|
+
const manifestPath = fs41.existsSync(v1Path) ? v1Path : fs41.existsSync(v0Path) ? v0Path : null;
|
|
36655
36769
|
if (!manifestPath) continue;
|
|
36656
36770
|
try {
|
|
36657
|
-
const m = JSON.parse(
|
|
36771
|
+
const m = JSON.parse(fs41.readFileSync(manifestPath, "utf-8"));
|
|
36658
36772
|
items.push({
|
|
36659
36773
|
type,
|
|
36660
36774
|
category,
|
|
@@ -36765,8 +36879,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36765
36879
|
if (!/^@[a-z0-9_-]+$/i.test(requestedName)) {
|
|
36766
36880
|
return { success: false, error: "name must match @[a-z0-9_-]+" };
|
|
36767
36881
|
}
|
|
36768
|
-
const
|
|
36769
|
-
const
|
|
36882
|
+
const fs41 = __require("fs");
|
|
36883
|
+
const path45 = __require("path");
|
|
36770
36884
|
const { spawnSync: spawnSync2 } = __require("child_process");
|
|
36771
36885
|
const file = ext.loadExternalSources();
|
|
36772
36886
|
if (file.sources.some((s2) => s2.name === requestedName)) {
|
|
@@ -36775,9 +36889,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36775
36889
|
if (file.sources.some((s2) => s2.url === url && s2.ref === ref)) {
|
|
36776
36890
|
return { success: false, error: `source url+ref already registered (use a different name to track another ref)` };
|
|
36777
36891
|
}
|
|
36778
|
-
const sourceDir =
|
|
36779
|
-
if (!
|
|
36780
|
-
if (
|
|
36892
|
+
const sourceDir = path45.join(ext.externalRoot(), requestedName);
|
|
36893
|
+
if (!fs41.existsSync(ext.externalRoot())) fs41.mkdirSync(ext.externalRoot(), { recursive: true });
|
|
36894
|
+
if (fs41.existsSync(sourceDir)) {
|
|
36781
36895
|
return { success: false, error: `directory already exists: ${sourceDir} (rename or remove first)` };
|
|
36782
36896
|
}
|
|
36783
36897
|
const clone = spawnSync2("git", ["clone", "--depth=1", "--branch", ref, "--", url, sourceDir], {
|
|
@@ -36787,7 +36901,7 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36787
36901
|
});
|
|
36788
36902
|
if (clone.status !== 0) {
|
|
36789
36903
|
try {
|
|
36790
|
-
|
|
36904
|
+
fs41.rmSync(sourceDir, { recursive: true, force: true });
|
|
36791
36905
|
} catch {
|
|
36792
36906
|
}
|
|
36793
36907
|
return { success: false, error: `git clone failed: ${(clone.stderr || clone.stdout || "").trim() || "unknown error"}` };
|
|
@@ -36831,15 +36945,15 @@ ${formatManifestValidationIssues2(validation.issues)}`,
|
|
|
36831
36945
|
const name = typeof args?.name === "string" ? args.name.trim() : "";
|
|
36832
36946
|
if (!name) return { success: false, error: "name is required" };
|
|
36833
36947
|
const ext = (init_external_sources(), __toCommonJS(external_sources_exports));
|
|
36834
|
-
const
|
|
36835
|
-
const
|
|
36948
|
+
const fs41 = __require("fs");
|
|
36949
|
+
const path45 = __require("path");
|
|
36836
36950
|
const file = ext.loadExternalSources();
|
|
36837
36951
|
const match = file.sources.find((s2) => s2.name === name);
|
|
36838
36952
|
if (!match) return { success: false, error: `source "${name}" not registered` };
|
|
36839
|
-
const sourceDir =
|
|
36840
|
-
if (
|
|
36953
|
+
const sourceDir = path45.join(ext.externalRoot(), name);
|
|
36954
|
+
if (fs41.existsSync(sourceDir)) {
|
|
36841
36955
|
try {
|
|
36842
|
-
|
|
36956
|
+
fs41.rmSync(sourceDir, { recursive: true, force: true });
|
|
36843
36957
|
} catch (e) {
|
|
36844
36958
|
return { success: false, error: `failed to delete ${sourceDir}: ${e?.message || e}` };
|
|
36845
36959
|
}
|
|
@@ -37624,24 +37738,24 @@ var statusMetaHandlers = {
|
|
|
37624
37738
|
// src/commands/low-family/coordinator-prompt.ts
|
|
37625
37739
|
var coordinatorPromptHandlers = {
|
|
37626
37740
|
list_coordinator_prompts: async (_ctx, _args) => {
|
|
37627
|
-
const
|
|
37628
|
-
const
|
|
37629
|
-
const
|
|
37630
|
-
const dir =
|
|
37741
|
+
const fs41 = await import("fs");
|
|
37742
|
+
const path45 = await import("path");
|
|
37743
|
+
const os32 = await import("os");
|
|
37744
|
+
const dir = path45.join(os32.homedir(), ".adhdev", "coordinator-prompts");
|
|
37631
37745
|
const entries = {};
|
|
37632
37746
|
try {
|
|
37633
|
-
if (
|
|
37634
|
-
for (const name of
|
|
37747
|
+
if (fs41.existsSync(dir)) {
|
|
37748
|
+
for (const name of fs41.readdirSync(dir)) {
|
|
37635
37749
|
const matchOverride = name.match(/^([a-zA-Z0-9_.-]+)\.md$/);
|
|
37636
37750
|
const matchAppend = name.match(/^([a-zA-Z0-9_.-]+)\.append\.md$/);
|
|
37637
37751
|
const m = matchAppend || matchOverride;
|
|
37638
37752
|
if (!m) continue;
|
|
37639
37753
|
const isAppend = !!matchAppend;
|
|
37640
37754
|
const key2 = m[1];
|
|
37641
|
-
const full =
|
|
37755
|
+
const full = path45.join(dir, name);
|
|
37642
37756
|
let content = "";
|
|
37643
37757
|
try {
|
|
37644
|
-
content =
|
|
37758
|
+
content = fs41.readFileSync(full, "utf8");
|
|
37645
37759
|
} catch {
|
|
37646
37760
|
}
|
|
37647
37761
|
if (!entries[key2]) entries[key2] = { override: "", append: "" };
|
|
@@ -37655,24 +37769,24 @@ var coordinatorPromptHandlers = {
|
|
|
37655
37769
|
return { success: true, dir, entries };
|
|
37656
37770
|
},
|
|
37657
37771
|
write_coordinator_prompt: async (_ctx, args) => {
|
|
37658
|
-
const
|
|
37659
|
-
const
|
|
37660
|
-
const
|
|
37772
|
+
const fs41 = await import("fs");
|
|
37773
|
+
const path45 = await import("path");
|
|
37774
|
+
const os32 = await import("os");
|
|
37661
37775
|
const key2 = typeof args?.key === "string" ? args.key.trim() : "";
|
|
37662
37776
|
const kind = args?.kind === "append" ? "append" : "override";
|
|
37663
37777
|
const content = typeof args?.content === "string" ? args.content : "";
|
|
37664
37778
|
if (!key2 || !/^[a-zA-Z0-9_.-]+$/.test(key2)) {
|
|
37665
37779
|
return { success: false, error: "key must match [a-zA-Z0-9_.-]+" };
|
|
37666
37780
|
}
|
|
37667
|
-
const dir =
|
|
37781
|
+
const dir = path45.join(os32.homedir(), ".adhdev", "coordinator-prompts");
|
|
37668
37782
|
const filename = kind === "append" ? `${key2}.append.md` : `${key2}.md`;
|
|
37669
|
-
const full =
|
|
37783
|
+
const full = path45.join(dir, filename);
|
|
37670
37784
|
try {
|
|
37671
|
-
|
|
37785
|
+
fs41.mkdirSync(dir, { recursive: true });
|
|
37672
37786
|
if (content.trim()) {
|
|
37673
|
-
|
|
37674
|
-
} else if (
|
|
37675
|
-
|
|
37787
|
+
fs41.writeFileSync(full, content, { encoding: "utf8", mode: 384 });
|
|
37788
|
+
} else if (fs41.existsSync(full)) {
|
|
37789
|
+
fs41.unlinkSync(full);
|
|
37676
37790
|
}
|
|
37677
37791
|
return { success: true, path: full, kind, key: key2 };
|
|
37678
37792
|
} catch (error) {
|
|
@@ -38763,9 +38877,9 @@ init_workspaces();
|
|
|
38763
38877
|
init_recent_activity();
|
|
38764
38878
|
init_hash();
|
|
38765
38879
|
init_coordinator_registry();
|
|
38766
|
-
import * as
|
|
38767
|
-
import * as
|
|
38768
|
-
import * as
|
|
38880
|
+
import * as os22 from "os";
|
|
38881
|
+
import * as path29 from "path";
|
|
38882
|
+
import * as crypto6 from "crypto";
|
|
38769
38883
|
import { existsSync as existsSync31, mkdirSync as mkdirSync13, writeFileSync as writeFileSync16 } from "fs";
|
|
38770
38884
|
import { execFileSync as execFileSync4 } from "child_process";
|
|
38771
38885
|
import chalk from "chalk";
|
|
@@ -38774,11 +38888,9 @@ init_summary_metadata();
|
|
|
38774
38888
|
// src/providers/cli-provider-instance.ts
|
|
38775
38889
|
init_contracts2();
|
|
38776
38890
|
init_provider_input_support();
|
|
38777
|
-
import * as
|
|
38778
|
-
import * as
|
|
38779
|
-
import * as
|
|
38780
|
-
import * as fs19 from "fs";
|
|
38781
|
-
import { createRequire as createRequire2 } from "module";
|
|
38891
|
+
import * as os21 from "os";
|
|
38892
|
+
import * as crypto5 from "crypto";
|
|
38893
|
+
import * as fs20 from "fs";
|
|
38782
38894
|
init_hash();
|
|
38783
38895
|
|
|
38784
38896
|
// src/providers/spec/route.ts
|
|
@@ -41982,28 +42094,11 @@ function workingDirBasename(p) {
|
|
|
41982
42094
|
return (p || "").split(/[\\/]/).filter(Boolean).pop() || "session";
|
|
41983
42095
|
}
|
|
41984
42096
|
|
|
41985
|
-
// src/providers/cli-provider-
|
|
41986
|
-
|
|
41987
|
-
|
|
41988
|
-
|
|
41989
|
-
|
|
41990
|
-
}
|
|
41991
|
-
function getMessageTime(message) {
|
|
41992
|
-
if (!message || typeof message !== "object") return 0;
|
|
41993
|
-
const record = message;
|
|
41994
|
-
const value = Number(record.receivedAt ?? record.timestamp ?? 0);
|
|
41995
|
-
return Number.isFinite(value) ? value : 0;
|
|
41996
|
-
}
|
|
41997
|
-
var COMPLETED_FINALIZATION_RETRY_MS = 1e3;
|
|
41998
|
-
var COMPLETED_FINALIZATION_MAX_WAIT_MS = 3e4;
|
|
41999
|
-
var NATIVE_HISTORY_MESH_IDLE_SETTLE_MS = 4e3;
|
|
42000
|
-
var USER_INPUT_ACK_DEDUP_WINDOW_MS = 6e4;
|
|
42001
|
-
var STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS = 12e3;
|
|
42002
|
-
var TERMINAL_MESH_EVENTS = /* @__PURE__ */ new Set([
|
|
42003
|
-
"agent:generating_completed",
|
|
42004
|
-
"agent:stopped",
|
|
42005
|
-
"agent:ready"
|
|
42006
|
-
]);
|
|
42097
|
+
// src/providers/cli-provider-input-prompt.ts
|
|
42098
|
+
import * as os20 from "os";
|
|
42099
|
+
import * as path26 from "path";
|
|
42100
|
+
import * as crypto4 from "crypto";
|
|
42101
|
+
import * as fs19 from "fs";
|
|
42007
42102
|
var IMAGE_MIME_EXTENSIONS = {
|
|
42008
42103
|
"image/png": ".png",
|
|
42009
42104
|
"image/jpeg": ".jpg",
|
|
@@ -42067,19 +42162,6 @@ function cleanupStaleMaterializedImages(dir) {
|
|
|
42067
42162
|
} catch {
|
|
42068
42163
|
}
|
|
42069
42164
|
}
|
|
42070
|
-
function hasNonEmptyCliModalButtons(activeModal) {
|
|
42071
|
-
const buttons = activeModal?.buttons;
|
|
42072
|
-
return Array.isArray(buttons) && buttons.some((button) => String(button || "").trim().length > 0);
|
|
42073
|
-
}
|
|
42074
|
-
function isCliGeneratingLikeStatus(status) {
|
|
42075
|
-
return status === "generating" || status === "streaming" || status === "no_progress" || status === "long_generating" || status === "starting";
|
|
42076
|
-
}
|
|
42077
|
-
function computeTurnAnchoredDurationMs(engineTurnStartedAt, generatingStartedAt, now) {
|
|
42078
|
-
const engineStart = typeof engineTurnStartedAt === "number" && Number.isFinite(engineTurnStartedAt) ? engineTurnStartedAt : 0;
|
|
42079
|
-
if (engineStart > 0) return { durationMs: now - engineStart, anchor: "turn-start" };
|
|
42080
|
-
if (generatingStartedAt > 0) return { durationMs: now - generatingStartedAt, anchor: "generatingStartedAt" };
|
|
42081
|
-
return { durationMs: 0, anchor: "none" };
|
|
42082
|
-
}
|
|
42083
42165
|
function buildCliStructuredInputPrompt(input, options = {}) {
|
|
42084
42166
|
const promptParts = [];
|
|
42085
42167
|
const imageRefs = [];
|
|
@@ -42117,6 +42199,9 @@ function buildCliStructuredInputPrompt(input, options = {}) {
|
|
|
42117
42199
|
].filter((value, index, values) => value.trim().length > 0 && values.indexOf(value) === index);
|
|
42118
42200
|
return ordered.join("\n");
|
|
42119
42201
|
}
|
|
42202
|
+
|
|
42203
|
+
// src/providers/cli-provider-history-dedup.ts
|
|
42204
|
+
init_contracts2();
|
|
42120
42205
|
function normalizePersistableCliHistoryContent(content) {
|
|
42121
42206
|
return flattenContent(content).replace(/\s+/g, " ").trim();
|
|
42122
42207
|
}
|
|
@@ -42148,10 +42233,37 @@ function buildIncrementalHistoryAppendMessages(previousMessages, currentMessages
|
|
|
42148
42233
|
if (sharedPrefixLength === previousMessages.length) return currentMessages.slice(sharedPrefixLength);
|
|
42149
42234
|
return currentMessages;
|
|
42150
42235
|
}
|
|
42236
|
+
|
|
42237
|
+
// src/providers/cli-provider-status-helpers.ts
|
|
42238
|
+
import * as path27 from "path";
|
|
42239
|
+
import { createRequire as createRequire2 } from "module";
|
|
42240
|
+
function isIdleStatus(value) {
|
|
42241
|
+
const status = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
42242
|
+
return !status || status === "idle" || status === "ready";
|
|
42243
|
+
}
|
|
42244
|
+
function getMessageTime(message) {
|
|
42245
|
+
if (!message || typeof message !== "object") return 0;
|
|
42246
|
+
const record = message;
|
|
42247
|
+
const value = Number(record.receivedAt ?? record.timestamp ?? 0);
|
|
42248
|
+
return Number.isFinite(value) ? value : 0;
|
|
42249
|
+
}
|
|
42250
|
+
function hasNonEmptyCliModalButtons(activeModal) {
|
|
42251
|
+
const buttons = activeModal?.buttons;
|
|
42252
|
+
return Array.isArray(buttons) && buttons.some((button) => String(button || "").trim().length > 0);
|
|
42253
|
+
}
|
|
42254
|
+
function isCliGeneratingLikeStatus(status) {
|
|
42255
|
+
return status === "generating" || status === "streaming" || status === "no_progress" || status === "long_generating" || status === "starting";
|
|
42256
|
+
}
|
|
42257
|
+
function computeTurnAnchoredDurationMs(engineTurnStartedAt, generatingStartedAt, now) {
|
|
42258
|
+
const engineStart = typeof engineTurnStartedAt === "number" && Number.isFinite(engineTurnStartedAt) ? engineTurnStartedAt : 0;
|
|
42259
|
+
if (engineStart > 0) return { durationMs: now - engineStart, anchor: "turn-start" };
|
|
42260
|
+
if (generatingStartedAt > 0) return { durationMs: now - generatingStartedAt, anchor: "generatingStartedAt" };
|
|
42261
|
+
return { durationMs: 0, anchor: "none" };
|
|
42262
|
+
}
|
|
42151
42263
|
var CachedDatabaseSync = null;
|
|
42152
42264
|
function getDatabaseSync() {
|
|
42153
42265
|
if (CachedDatabaseSync) return CachedDatabaseSync;
|
|
42154
|
-
const requireFn = typeof __require === "function" ? __require : createRequire2(
|
|
42266
|
+
const requireFn = typeof __require === "function" ? __require : createRequire2(path27.join(process.cwd(), "__adhdev_sqlite_loader__.js"));
|
|
42155
42267
|
const sqliteModule = requireFn(`node:${"sqlite"}`);
|
|
42156
42268
|
CachedDatabaseSync = sqliteModule.DatabaseSync;
|
|
42157
42269
|
if (!CachedDatabaseSync) {
|
|
@@ -42193,13 +42305,26 @@ async function waitForCliAdapterReady(adapter, options) {
|
|
|
42193
42305
|
}
|
|
42194
42306
|
throw new Error(`CLI runtime did not become ready within ${timeoutMs}ms`);
|
|
42195
42307
|
}
|
|
42308
|
+
|
|
42309
|
+
// src/providers/cli-provider-instance.ts
|
|
42310
|
+
var STATUS_HYDRATION_TAIL_LIMIT = 200;
|
|
42311
|
+
var COMPLETED_FINALIZATION_RETRY_MS = 1e3;
|
|
42312
|
+
var COMPLETED_FINALIZATION_MAX_WAIT_MS = 3e4;
|
|
42313
|
+
var NATIVE_HISTORY_MESH_IDLE_SETTLE_MS = 4e3;
|
|
42314
|
+
var USER_INPUT_ACK_DEDUP_WINDOW_MS = 6e4;
|
|
42315
|
+
var STARTUP_GRACE_IDLE_COLLAPSE_WINDOW_MS = 12e3;
|
|
42316
|
+
var TERMINAL_MESH_EVENTS = /* @__PURE__ */ new Set([
|
|
42317
|
+
"agent:generating_completed",
|
|
42318
|
+
"agent:stopped",
|
|
42319
|
+
"agent:ready"
|
|
42320
|
+
]);
|
|
42196
42321
|
var CliProviderInstance = class _CliProviderInstance {
|
|
42197
42322
|
constructor(provider, workingDir, cliArgs = [], instanceId, transportFactory, options) {
|
|
42198
42323
|
this.provider = provider;
|
|
42199
42324
|
this.workingDir = workingDir;
|
|
42200
42325
|
this.cliArgs = cliArgs;
|
|
42201
42326
|
this.type = provider.type;
|
|
42202
|
-
this.instanceId = instanceId ||
|
|
42327
|
+
this.instanceId = instanceId || crypto5.randomUUID();
|
|
42203
42328
|
this.presentationMode = "chat";
|
|
42204
42329
|
this.providerSessionId = options?.providerSessionId;
|
|
42205
42330
|
this.launchMode = options?.launchMode || "new";
|
|
@@ -42239,6 +42364,33 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
42239
42364
|
* from scratch rather than firing on a stale timestamp.
|
|
42240
42365
|
*/
|
|
42241
42366
|
static AUTO_APPROVE_GATE_HYSTERESIS_MS = 1500;
|
|
42367
|
+
/**
|
|
42368
|
+
* AUTOAPPROVE-FLAP-RECUR (Fix B): extended busy-side continuity window for a
|
|
42369
|
+
* DELEGATED-WORKER auto-approve episode that is genuinely still cycling.
|
|
42370
|
+
*
|
|
42371
|
+
* The default AUTO_APPROVE_GATE_HYSTERESIS_MS (1500) absorbs a *momentary*
|
|
42372
|
+
* `generating` blip. But a delegated worker running a Bash approval observed
|
|
42373
|
+
* the FSM cycle the FULL state waiting_approval → busy → waiting_approval on a
|
|
42374
|
+
* 2–5s period (the button set scrolls in/out AND the modal question repaints,
|
|
42375
|
+
* so the adapter genuinely reports status=generating for whole seconds between
|
|
42376
|
+
* approval frames). Each busy phase outran the 1500ms hysteresis, so the
|
|
42377
|
+
* settle clock was WIPED (the genuine-resolution branch), the 600ms settle
|
|
42378
|
+
* window never accumulated across the flap, resolveModal never fired
|
|
42379
|
+
* (resolveModal count 0), and the mask-stall clock instead tripped at 4500ms →
|
|
42380
|
+
* coordinator nudge → the flap the coordinator observed.
|
|
42381
|
+
*
|
|
42382
|
+
* A genuine resolution and a flap both start with a busy phase; they diverge
|
|
42383
|
+
* only in whether waiting_approval RETURNS. So we cannot simply lengthen the
|
|
42384
|
+
* blanket hysteresis (that would make every real resolution hold the gate
|
|
42385
|
+
* open for seconds). Instead this longer window applies ONLY while an active
|
|
42386
|
+
* mask episode is alive (autoApproveMaskSince > 0) AND the session is a
|
|
42387
|
+
* delegated worker — i.e. exactly the never-resolving-flap case. A foreground
|
|
42388
|
+
* / attended session keeps the tight 1500ms window unchanged. The mask-stall
|
|
42389
|
+
* bound below still caps the episode, so a worker whose approval truly never
|
|
42390
|
+
* returns is surfaced to the coordinator within AUTO_APPROVE_MASK_STALL_MS
|
|
42391
|
+
* rather than held forever.
|
|
42392
|
+
*/
|
|
42393
|
+
static AUTO_APPROVE_FLAP_CONTINUITY_MS = 4e3;
|
|
42242
42394
|
/**
|
|
42243
42395
|
* STATUS-MISMATCH: upper bound on how long the auto-approve→`generating` SURFACE
|
|
42244
42396
|
* mask may hide a worker's `waiting_approval` (status + activeModal) before we give
|
|
@@ -42313,9 +42465,22 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
42313
42465
|
pendingAutoApprovalSince = 0;
|
|
42314
42466
|
autoApproveSettleTimer = null;
|
|
42315
42467
|
// Wall-clock when auto-approve first observed status!=waiting_approval while
|
|
42316
|
-
// a settle gate was in progress. Drives AUTO_APPROVE_GATE_HYSTERESIS_MS
|
|
42468
|
+
// a settle gate was in progress. Drives AUTO_APPROVE_GATE_HYSTERESIS_MS (or,
|
|
42469
|
+
// for a delegated-worker flap episode, AUTO_APPROVE_FLAP_CONTINUITY_MS) so a
|
|
42317
42470
|
// brief generating flip does not immediately wipe the settle clock.
|
|
42318
42471
|
autoApproveInactiveSince = 0;
|
|
42472
|
+
// AUTOAPPROVE-FLAP-RECUR (Fix A): wall-clock when the CURRENT waiting_approval
|
|
42473
|
+
// episode last presented a concrete, captured modal (buttons.length > 0). The
|
|
42474
|
+
// Claude TUI momentarily reports status=waiting_approval with activeModal=null
|
|
42475
|
+
// / an empty button block while the button block scrolls out of the captured
|
|
42476
|
+
// frame; the raw guard below (buttons.length===0) used to bail on that frame,
|
|
42477
|
+
// never advancing the settle gate and leaving no re-check armed — so a modal
|
|
42478
|
+
// that flapped modal=none ↔ N-buttons around the settle boundary never
|
|
42479
|
+
// accumulated its 600ms. This tracks the last GOOD-modal frame so a short
|
|
42480
|
+
// scroll-out blip is absorbed (settle keeps running against the last captured
|
|
42481
|
+
// signature) while a genuinely closed modal — buttons empty continuously past
|
|
42482
|
+
// the continuity window — is still recognised and resets the gate.
|
|
42483
|
+
autoApproveLastModalSeenAt = 0;
|
|
42319
42484
|
// STATUS-MISMATCH: wall-clock when the CURRENT auto-approve episode (waiting_approval
|
|
42320
42485
|
// + shouldAutoApprove) first began wanting to mask. Unlike pendingAutoApprovalSince it
|
|
42321
42486
|
// is NOT reset when the modal signature changes (a still-streaming/flapping prompt) and
|
|
@@ -42425,10 +42590,10 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
42425
42590
|
* Replaces the previously duplicated probeOpenCode/Codex/Goose functions.
|
|
42426
42591
|
*/
|
|
42427
42592
|
probeSessionIdFromConfig(probe) {
|
|
42428
|
-
const resolvedDbPath = probe.dbPath.replace(/^~/,
|
|
42593
|
+
const resolvedDbPath = probe.dbPath.replace(/^~/, os21.homedir());
|
|
42429
42594
|
const now = Date.now();
|
|
42430
42595
|
if (this.cachedSqliteDbMissingUntil > now) return null;
|
|
42431
|
-
if (!
|
|
42596
|
+
if (!fs20.existsSync(resolvedDbPath)) {
|
|
42432
42597
|
this.cachedSqliteDbMissingUntil = now + 1e4;
|
|
42433
42598
|
return null;
|
|
42434
42599
|
}
|
|
@@ -43024,7 +43189,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
43024
43189
|
if (!isNativeSourceCanonicalHistory(this.provider.nativeHistory)) return null;
|
|
43025
43190
|
if (this.lastExternalCompletionProbe?.sourcePath) {
|
|
43026
43191
|
try {
|
|
43027
|
-
|
|
43192
|
+
fs20.statSync(this.lastExternalCompletionProbe.sourcePath);
|
|
43028
43193
|
} catch {
|
|
43029
43194
|
}
|
|
43030
43195
|
}
|
|
@@ -43278,6 +43443,20 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
43278
43443
|
isMeshWorkerSession() {
|
|
43279
43444
|
return !!(this.settings.meshNodeFor || this.settings.meshActiveTaskId || this.settings.meshNodeId || this.settings.launchedByCoordinator);
|
|
43280
43445
|
}
|
|
43446
|
+
/**
|
|
43447
|
+
* AUTOAPPROVE-FLAP-RECUR (Fix A+B): how long a busy blip / modal scroll-out may
|
|
43448
|
+
* persist before the in-progress settle gate is torn down. For a delegated
|
|
43449
|
+
* worker whose auto-approve episode is genuinely still cycling (mask clock
|
|
43450
|
+
* alive), the FSM's full waiting_approval → busy → waiting_approval flap runs
|
|
43451
|
+
* on a multi-second period, so the settle continuity window is extended to
|
|
43452
|
+
* AUTO_APPROVE_FLAP_CONTINUITY_MS to bridge it (still bounded, and still capped
|
|
43453
|
+
* by AUTO_APPROVE_MASK_STALL_MS). Every other case — foreground/attended
|
|
43454
|
+
* session, or no active mask episode — keeps the tight default hysteresis so a
|
|
43455
|
+
* genuine resolution frees the gate promptly.
|
|
43456
|
+
*/
|
|
43457
|
+
autoApproveContinuityWindowMs() {
|
|
43458
|
+
return this.autoApproveMaskSince > 0 && this.isMeshWorkerSession() ? _CliProviderInstance.AUTO_APPROVE_FLAP_CONTINUITY_MS : _CliProviderInstance.AUTO_APPROVE_GATE_HYSTERESIS_MS;
|
|
43459
|
+
}
|
|
43281
43460
|
// FALSE-IDLE (self-coordinator settle): an autonomously-progressing mesh session
|
|
43282
43461
|
// is either a delegated worker (isMeshWorkerSession) OR the coordinator's OWN
|
|
43283
43462
|
// claude-cli session (meshCoordinatorFor). Both run auto-approved tool turns whose
|
|
@@ -43513,6 +43692,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
43513
43692
|
this.autoApproveInactiveSince = 0;
|
|
43514
43693
|
this.autoApproveMaskSince = 0;
|
|
43515
43694
|
this.stalledApprovalNudgeEpisode = 0;
|
|
43695
|
+
this.autoApproveLastModalSeenAt = 0;
|
|
43516
43696
|
if (this.autoApproveSettleTimer) clearTimeout(this.autoApproveSettleTimer);
|
|
43517
43697
|
this.autoApproveSettleTimer = setTimeout(() => {
|
|
43518
43698
|
this.autoApproveSettleTimer = null;
|
|
@@ -43526,12 +43706,13 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
43526
43706
|
if (this.pendingAutoApprovalSince) {
|
|
43527
43707
|
if (!this.autoApproveInactiveSince) this.autoApproveInactiveSince = now;
|
|
43528
43708
|
const goneForMs = now - this.autoApproveInactiveSince;
|
|
43529
|
-
|
|
43709
|
+
const continuityMs = this.autoApproveContinuityWindowMs();
|
|
43710
|
+
if (goneForMs < continuityMs) {
|
|
43530
43711
|
if (this.autoApproveSettleTimer) clearTimeout(this.autoApproveSettleTimer);
|
|
43531
43712
|
this.autoApproveSettleTimer = setTimeout(() => {
|
|
43532
43713
|
this.autoApproveSettleTimer = null;
|
|
43533
43714
|
this.recheckAutoApproveSettled();
|
|
43534
|
-
},
|
|
43715
|
+
}, continuityMs - goneForMs + 20);
|
|
43535
43716
|
return autoApproveActive;
|
|
43536
43717
|
}
|
|
43537
43718
|
}
|
|
@@ -43540,6 +43721,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
43540
43721
|
this.autoApproveInactiveSince = 0;
|
|
43541
43722
|
this.autoApproveMaskSince = 0;
|
|
43542
43723
|
this.stalledApprovalNudgeEpisode = 0;
|
|
43724
|
+
this.autoApproveLastModalSeenAt = 0;
|
|
43543
43725
|
if (this.autoApproveSettleTimer) {
|
|
43544
43726
|
clearTimeout(this.autoApproveSettleTimer);
|
|
43545
43727
|
this.autoApproveSettleTimer = null;
|
|
@@ -43552,8 +43734,22 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
43552
43734
|
const modal = adapterStatus.activeModal;
|
|
43553
43735
|
const buttons = Array.isArray(modal?.buttons) ? modal.buttons.map((b) => String(b || "").trim()).filter(Boolean) : [];
|
|
43554
43736
|
if (!modal || buttons.length === 0) {
|
|
43737
|
+
const blipForMs = this.autoApproveLastModalSeenAt ? now - this.autoApproveLastModalSeenAt : Infinity;
|
|
43738
|
+
if (this.pendingAutoApprovalSince && blipForMs < this.autoApproveContinuityWindowMs()) {
|
|
43739
|
+
if (this.autoApproveSettleTimer) clearTimeout(this.autoApproveSettleTimer);
|
|
43740
|
+
this.autoApproveSettleTimer = setTimeout(() => {
|
|
43741
|
+
this.autoApproveSettleTimer = null;
|
|
43742
|
+
this.recheckAutoApproveSettled();
|
|
43743
|
+
}, this.autoApproveContinuityWindowMs() - blipForMs + 20);
|
|
43744
|
+
return autoApproveActive;
|
|
43745
|
+
}
|
|
43746
|
+
if (blipForMs >= this.autoApproveContinuityWindowMs()) {
|
|
43747
|
+
this.pendingAutoApprovalSignature = "";
|
|
43748
|
+
this.pendingAutoApprovalSince = 0;
|
|
43749
|
+
}
|
|
43555
43750
|
return autoApproveActive;
|
|
43556
43751
|
}
|
|
43752
|
+
this.autoApproveLastModalSeenAt = now;
|
|
43557
43753
|
const modalKind = typeof modal?.kind === "string" ? modal.kind : "approval";
|
|
43558
43754
|
if (modalKind !== "approval") {
|
|
43559
43755
|
return autoApproveActive;
|
|
@@ -43597,6 +43793,7 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
43597
43793
|
this.autoApproveInactiveSince = 0;
|
|
43598
43794
|
this.autoApproveMaskSince = 0;
|
|
43599
43795
|
this.stalledApprovalNudgeEpisode = 0;
|
|
43796
|
+
this.autoApproveLastModalSeenAt = 0;
|
|
43600
43797
|
if (this.autoApproveBusyTimer) clearTimeout(this.autoApproveBusyTimer);
|
|
43601
43798
|
this.autoApproveBusyTimer = setTimeout(() => {
|
|
43602
43799
|
this.autoApproveBusy = false;
|
|
@@ -44242,6 +44439,8 @@ ${effect.notification.body || ""}`.trim();
|
|
|
44242
44439
|
if (!this.isMeshWorkerSession()) return;
|
|
44243
44440
|
if (adapterStatus?.status !== "waiting_approval") return;
|
|
44244
44441
|
if (!this.autoApproveMaskStalled(now)) return;
|
|
44442
|
+
const modalButtons = Array.isArray(adapterStatus.activeModal?.buttons) ? adapterStatus.activeModal.buttons.map((b) => String(b || "").trim()).filter(Boolean) : [];
|
|
44443
|
+
if (this.pendingAutoApprovalSince && modalButtons.length > 0) return;
|
|
44245
44444
|
if (this.stalledApprovalNudgeEpisode === this.autoApproveMaskSince) return;
|
|
44246
44445
|
this.stalledApprovalNudgeEpisode = this.autoApproveMaskSince;
|
|
44247
44446
|
const modal = adapterStatus.activeModal;
|
|
@@ -44557,7 +44756,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
44557
44756
|
};
|
|
44558
44757
|
addDir(this.workingDir);
|
|
44559
44758
|
try {
|
|
44560
|
-
addDir(
|
|
44759
|
+
addDir(fs20.realpathSync.native(this.workingDir));
|
|
44561
44760
|
} catch {
|
|
44562
44761
|
}
|
|
44563
44762
|
return Array.from(dirs);
|
|
@@ -44596,7 +44795,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
44596
44795
|
// src/providers/acp-provider-instance.ts
|
|
44597
44796
|
init_contracts2();
|
|
44598
44797
|
init_provider_input_support();
|
|
44599
|
-
import * as
|
|
44798
|
+
import * as path28 from "path";
|
|
44600
44799
|
import { Readable, Writable } from "stream";
|
|
44601
44800
|
import { spawn as spawn2 } from "child_process";
|
|
44602
44801
|
import {
|
|
@@ -45389,7 +45588,7 @@ var AcpProviderInstance = class {
|
|
|
45389
45588
|
return b.uri ? {
|
|
45390
45589
|
type: "resource_link",
|
|
45391
45590
|
uri: b.uri,
|
|
45392
|
-
name:
|
|
45591
|
+
name: path28.basename(b.uri),
|
|
45393
45592
|
mimeType: b.mimeType,
|
|
45394
45593
|
...b.transcript ? { description: b.transcript } : {}
|
|
45395
45594
|
} : { type: "text", text: b.transcript || `[Video attachment: ${b.mimeType}]` };
|
|
@@ -45861,11 +46060,11 @@ function shouldRestoreHostedRuntime(record, managerTag) {
|
|
|
45861
46060
|
// src/commands/cli-manager.ts
|
|
45862
46061
|
function isExplicitCommand(command) {
|
|
45863
46062
|
const trimmed = command.trim();
|
|
45864
|
-
return
|
|
46063
|
+
return path29.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~");
|
|
45865
46064
|
}
|
|
45866
46065
|
function expandExecutable(command) {
|
|
45867
46066
|
const trimmed = command.trim();
|
|
45868
|
-
return trimmed.startsWith("~") ?
|
|
46067
|
+
return trimmed.startsWith("~") ? path29.join(os22.homedir(), trimmed.slice(1)) : trimmed;
|
|
45869
46068
|
}
|
|
45870
46069
|
function commandExists(command) {
|
|
45871
46070
|
const trimmed = command.trim();
|
|
@@ -46010,10 +46209,10 @@ function hasConfigOverride(args, key2) {
|
|
|
46010
46209
|
return false;
|
|
46011
46210
|
}
|
|
46012
46211
|
function ensureEmptyDelegatedMcpConfig(workspace) {
|
|
46013
|
-
const baseDir =
|
|
46212
|
+
const baseDir = path29.join(os22.tmpdir(), "adhdev-delegated-agent-empty-mcp");
|
|
46014
46213
|
mkdirSync13(baseDir, { recursive: true });
|
|
46015
|
-
const workspaceHash = shortHash(
|
|
46016
|
-
const filePath =
|
|
46214
|
+
const workspaceHash = shortHash(path29.resolve(workspace || os22.tmpdir()));
|
|
46215
|
+
const filePath = path29.join(baseDir, `${workspaceHash}.json`);
|
|
46017
46216
|
writeFileSync16(filePath, JSON.stringify({ mcpServers: {} }, null, 2), "utf-8");
|
|
46018
46217
|
return filePath;
|
|
46019
46218
|
}
|
|
@@ -46167,7 +46366,7 @@ function resolveCliSessionBinding(provider, normalizedType, cliArgs, requestedRe
|
|
|
46167
46366
|
if (!supportsExplicitSessionStart(resume)) {
|
|
46168
46367
|
return { cliArgs: baseArgs, launchMode: "new" };
|
|
46169
46368
|
}
|
|
46170
|
-
const providerSessionId =
|
|
46369
|
+
const providerSessionId = crypto6.randomUUID();
|
|
46171
46370
|
const newSessionArgs = expandResumeArgs(resume.newSessionArgs, providerSessionId);
|
|
46172
46371
|
return {
|
|
46173
46372
|
cliArgs: [...baseArgs || [], ...newSessionArgs || []],
|
|
@@ -46351,7 +46550,7 @@ var DaemonCliManager = class {
|
|
|
46351
46550
|
async startSession(cliType, workingDir, cliArgs, initialModel, options) {
|
|
46352
46551
|
const trimmed = (workingDir || "").trim();
|
|
46353
46552
|
if (!trimmed) throw new Error("working directory required");
|
|
46354
|
-
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/,
|
|
46553
|
+
const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os22.homedir()) : path29.resolve(trimmed);
|
|
46355
46554
|
const normalizedType = this.providerLoader.resolveAlias(cliType);
|
|
46356
46555
|
const rawProvider = this.providerLoader.getByAlias(cliType);
|
|
46357
46556
|
const provider = rawProvider ? this.providerLoader.resolve(normalizedType) || rawProvider : void 0;
|
|
@@ -46362,7 +46561,7 @@ var DaemonCliManager = class {
|
|
|
46362
46561
|
Enable and detect this provider from the Machine Providers page before starting a runtime.`
|
|
46363
46562
|
);
|
|
46364
46563
|
}
|
|
46365
|
-
const key2 =
|
|
46564
|
+
const key2 = crypto6.randomUUID();
|
|
46366
46565
|
{
|
|
46367
46566
|
const coordinatorMeshId = options?.settingsOverride?.meshCoordinatorFor;
|
|
46368
46567
|
if (typeof coordinatorMeshId === "string" && coordinatorMeshId.trim()) {
|
|
@@ -47203,13 +47402,13 @@ var cliAgentHandlers = {
|
|
|
47203
47402
|
// src/launch.ts
|
|
47204
47403
|
import { exec as exec4, spawn as spawn3 } from "child_process";
|
|
47205
47404
|
import * as net from "net";
|
|
47206
|
-
import * as
|
|
47207
|
-
import * as
|
|
47405
|
+
import * as os27 from "os";
|
|
47406
|
+
import * as path37 from "path";
|
|
47208
47407
|
|
|
47209
47408
|
// src/providers/provider-loader.ts
|
|
47210
|
-
import * as
|
|
47211
|
-
import * as
|
|
47212
|
-
import * as
|
|
47409
|
+
import * as fs26 from "fs";
|
|
47410
|
+
import * as path36 from "path";
|
|
47411
|
+
import * as os26 from "os";
|
|
47213
47412
|
import * as chokidar from "chokidar";
|
|
47214
47413
|
init_hash();
|
|
47215
47414
|
init_logger();
|
|
@@ -47601,13 +47800,13 @@ function validateControl(control, errors) {
|
|
|
47601
47800
|
init_external_sources();
|
|
47602
47801
|
|
|
47603
47802
|
// src/providers/native-history/dispatcher.ts
|
|
47604
|
-
import * as
|
|
47605
|
-
import * as
|
|
47606
|
-
import * as
|
|
47803
|
+
import * as fs25 from "fs";
|
|
47804
|
+
import * as os25 from "os";
|
|
47805
|
+
import * as path34 from "path";
|
|
47607
47806
|
|
|
47608
47807
|
// src/providers/native-history/claude-cli-transcript.ts
|
|
47609
|
-
import * as
|
|
47610
|
-
import * as
|
|
47808
|
+
import * as fs21 from "fs";
|
|
47809
|
+
import * as path30 from "path";
|
|
47611
47810
|
function extractTimestampValue(value) {
|
|
47612
47811
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
47613
47812
|
if (typeof value === "string") {
|
|
@@ -47620,7 +47819,7 @@ function extractTimestampValue(value) {
|
|
|
47620
47819
|
}
|
|
47621
47820
|
function statMtimeMs(filePath) {
|
|
47622
47821
|
try {
|
|
47623
|
-
return
|
|
47822
|
+
return fs21.statSync(filePath).mtimeMs;
|
|
47624
47823
|
} catch {
|
|
47625
47824
|
return 0;
|
|
47626
47825
|
}
|
|
@@ -47690,7 +47889,7 @@ function extractUserContentParts(content) {
|
|
|
47690
47889
|
function parseTranscriptFile(filePath, sessionId, workspaceFallback) {
|
|
47691
47890
|
let raw;
|
|
47692
47891
|
try {
|
|
47693
|
-
raw =
|
|
47892
|
+
raw = fs21.readFileSync(filePath, "utf-8");
|
|
47694
47893
|
} catch {
|
|
47695
47894
|
return [];
|
|
47696
47895
|
}
|
|
@@ -47763,10 +47962,10 @@ function parseTranscriptFile(filePath, sessionId, workspaceFallback) {
|
|
|
47763
47962
|
return records;
|
|
47764
47963
|
}
|
|
47765
47964
|
function readSession(sessionPath) {
|
|
47766
|
-
if (!sessionPath || !
|
|
47767
|
-
const basename14 =
|
|
47965
|
+
if (!sessionPath || !path30.isAbsolute(sessionPath)) return null;
|
|
47966
|
+
const basename14 = path30.basename(sessionPath, ".jsonl");
|
|
47768
47967
|
if (!isSafeSessionId(basename14)) return null;
|
|
47769
|
-
if (!
|
|
47968
|
+
if (!fs21.existsSync(sessionPath)) return null;
|
|
47770
47969
|
const sourceMtimeMs = statMtimeMs(sessionPath);
|
|
47771
47970
|
const messages = parseTranscriptFile(sessionPath, basename14);
|
|
47772
47971
|
if (messages.length === 0) return null;
|
|
@@ -47784,8 +47983,8 @@ function readSession(sessionPath) {
|
|
|
47784
47983
|
}
|
|
47785
47984
|
|
|
47786
47985
|
// src/providers/native-history/codex-cli-transcript.ts
|
|
47787
|
-
import * as
|
|
47788
|
-
import * as
|
|
47986
|
+
import * as fs22 from "fs";
|
|
47987
|
+
import * as path31 from "path";
|
|
47789
47988
|
function extractTimestampValue2(value) {
|
|
47790
47989
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
47791
47990
|
if (typeof value === "string") {
|
|
@@ -47798,7 +47997,7 @@ function extractTimestampValue2(value) {
|
|
|
47798
47997
|
}
|
|
47799
47998
|
function statMtimeMs2(filePath) {
|
|
47800
47999
|
try {
|
|
47801
|
-
return
|
|
48000
|
+
return fs22.statSync(filePath).mtimeMs;
|
|
47802
48001
|
} catch {
|
|
47803
48002
|
return 0;
|
|
47804
48003
|
}
|
|
@@ -47895,7 +48094,7 @@ function pushAssistantStandardMessage(records, sessionId, receivedAt, content, w
|
|
|
47895
48094
|
}
|
|
47896
48095
|
function readSessionMeta(filePath) {
|
|
47897
48096
|
try {
|
|
47898
|
-
const firstLine =
|
|
48097
|
+
const firstLine = fs22.readFileSync(filePath, "utf-8").split("\n").find(Boolean);
|
|
47899
48098
|
if (!firstLine) return null;
|
|
47900
48099
|
const parsed = JSON.parse(firstLine);
|
|
47901
48100
|
if (String(parsed.type ?? "") !== "session_meta") return null;
|
|
@@ -47907,7 +48106,7 @@ function readSessionMeta(filePath) {
|
|
|
47907
48106
|
function parseSessionFile(filePath, sessionId, workspaceFallback) {
|
|
47908
48107
|
let raw;
|
|
47909
48108
|
try {
|
|
47910
|
-
raw =
|
|
48109
|
+
raw = fs22.readFileSync(filePath, "utf-8");
|
|
47911
48110
|
} catch {
|
|
47912
48111
|
return [];
|
|
47913
48112
|
}
|
|
@@ -48022,11 +48221,11 @@ function parseSessionFile(filePath, sessionId, workspaceFallback) {
|
|
|
48022
48221
|
return records;
|
|
48023
48222
|
}
|
|
48024
48223
|
function readSession2(sessionPath) {
|
|
48025
|
-
if (!sessionPath || !
|
|
48026
|
-
if (!
|
|
48224
|
+
if (!sessionPath || !path31.isAbsolute(sessionPath)) return null;
|
|
48225
|
+
if (!fs22.existsSync(sessionPath)) return null;
|
|
48027
48226
|
const meta = readSessionMeta(sessionPath);
|
|
48028
48227
|
const metaId = String(meta?.id ?? "").trim();
|
|
48029
|
-
const basename14 =
|
|
48228
|
+
const basename14 = path31.basename(sessionPath, ".jsonl");
|
|
48030
48229
|
const uuidMatch = basename14.match(/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/i);
|
|
48031
48230
|
const filenameUuid2 = uuidMatch ? uuidMatch[1] : "";
|
|
48032
48231
|
if (metaId && filenameUuid2 && metaId !== filenameUuid2) return null;
|
|
@@ -48052,9 +48251,9 @@ function readSession2(sessionPath) {
|
|
|
48052
48251
|
// src/providers/native-history/antigravity-cli-transcript.ts
|
|
48053
48252
|
init_load_better_sqlite3();
|
|
48054
48253
|
init_logger();
|
|
48055
|
-
import * as
|
|
48056
|
-
import * as
|
|
48057
|
-
import * as
|
|
48254
|
+
import * as fs23 from "fs";
|
|
48255
|
+
import * as path32 from "path";
|
|
48256
|
+
import * as os23 from "os";
|
|
48058
48257
|
function extractTimestampValue3(value) {
|
|
48059
48258
|
if (typeof value === "number" && Number.isFinite(value) && value > 0) return value;
|
|
48060
48259
|
if (typeof value === "string") {
|
|
@@ -48067,7 +48266,7 @@ function extractTimestampValue3(value) {
|
|
|
48067
48266
|
}
|
|
48068
48267
|
function statMtimeMs3(filePath) {
|
|
48069
48268
|
try {
|
|
48070
|
-
return
|
|
48269
|
+
return fs23.statSync(filePath).mtimeMs;
|
|
48071
48270
|
} catch {
|
|
48072
48271
|
return 0;
|
|
48073
48272
|
}
|
|
@@ -48076,13 +48275,13 @@ function isUuidLike(value) {
|
|
|
48076
48275
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
48077
48276
|
}
|
|
48078
48277
|
function antigravityRoot() {
|
|
48079
|
-
return
|
|
48278
|
+
return path32.join(os23.homedir(), ".gemini", "antigravity-cli");
|
|
48080
48279
|
}
|
|
48081
48280
|
function historyJsonlPath() {
|
|
48082
|
-
return
|
|
48281
|
+
return path32.join(antigravityRoot(), "history.jsonl");
|
|
48083
48282
|
}
|
|
48084
48283
|
function brainRoot() {
|
|
48085
|
-
return
|
|
48284
|
+
return path32.join(antigravityRoot(), "brain");
|
|
48086
48285
|
}
|
|
48087
48286
|
function extractUserRequestContent(content) {
|
|
48088
48287
|
const raw = content.trim();
|
|
@@ -48098,7 +48297,7 @@ function antigravityRowKind(rowType) {
|
|
|
48098
48297
|
function parseBrainTranscript(filePath, sessionId, workspace) {
|
|
48099
48298
|
let raw;
|
|
48100
48299
|
try {
|
|
48101
|
-
raw =
|
|
48300
|
+
raw = fs23.readFileSync(filePath, "utf-8");
|
|
48102
48301
|
} catch {
|
|
48103
48302
|
return null;
|
|
48104
48303
|
}
|
|
@@ -48158,7 +48357,7 @@ function readHistoryRows() {
|
|
|
48158
48357
|
const sourcePath = historyJsonlPath();
|
|
48159
48358
|
let lines = [];
|
|
48160
48359
|
try {
|
|
48161
|
-
lines =
|
|
48360
|
+
lines = fs23.readFileSync(sourcePath, "utf-8").split("\n").filter(Boolean);
|
|
48162
48361
|
} catch {
|
|
48163
48362
|
return [];
|
|
48164
48363
|
}
|
|
@@ -48206,7 +48405,7 @@ function extractStringsFromBuffer(buf) {
|
|
|
48206
48405
|
function parsePbFile(filePath, sessionId) {
|
|
48207
48406
|
let buf;
|
|
48208
48407
|
try {
|
|
48209
|
-
buf =
|
|
48408
|
+
buf = fs23.readFileSync(filePath);
|
|
48210
48409
|
} catch {
|
|
48211
48410
|
return null;
|
|
48212
48411
|
}
|
|
@@ -48376,7 +48575,7 @@ function parseConversationDb(filePath, sessionId, workspace) {
|
|
|
48376
48575
|
} catch (err) {
|
|
48377
48576
|
LOG.warn(
|
|
48378
48577
|
"NativeHistory",
|
|
48379
|
-
`antigravity .db reader could not load better-sqlite3 for ${
|
|
48578
|
+
`antigravity .db reader could not load better-sqlite3 for ${path32.basename(filePath)}: ${err instanceof Error ? err.message : String(err)} (native binding unavailable \u2014 assistant answers in this .db will not surface)`
|
|
48380
48579
|
);
|
|
48381
48580
|
return null;
|
|
48382
48581
|
}
|
|
@@ -48406,13 +48605,13 @@ function parseConversationDb(filePath, sessionId, workspace) {
|
|
|
48406
48605
|
}
|
|
48407
48606
|
LOG.warn(
|
|
48408
48607
|
"NativeHistory",
|
|
48409
|
-
`antigravity .db ${
|
|
48608
|
+
`antigravity .db ${path32.basename(filePath)} stayed locked (SQLITE_BUSY) after ${AGY_DB_MAX_ATTEMPTS} attempts: ${err instanceof Error ? err.message : String(err)} (WAL write/checkpoint lock contention \u2014 assistant answers may transiently not surface this read)`
|
|
48410
48609
|
);
|
|
48411
48610
|
return null;
|
|
48412
48611
|
}
|
|
48413
48612
|
LOG.debug(
|
|
48414
48613
|
"NativeHistory",
|
|
48415
|
-
`antigravity .db ${
|
|
48614
|
+
`antigravity .db ${path32.basename(filePath)} not readable: ${err instanceof Error ? err.message : String(err)}`
|
|
48416
48615
|
);
|
|
48417
48616
|
return null;
|
|
48418
48617
|
} finally {
|
|
@@ -48439,12 +48638,12 @@ function parseConversationDb(filePath, sessionId, workspace) {
|
|
|
48439
48638
|
content = recovered;
|
|
48440
48639
|
LOG.debug(
|
|
48441
48640
|
"NativeHistory",
|
|
48442
|
-
`antigravity .db ${
|
|
48641
|
+
`antigravity .db ${path32.basename(filePath)} step ${row.idx} (type ${row.step_type}): user prompt absent at field 19; recovered ${content.length} chars via printable-run fallback \u2014 possible step_payload schema drift`
|
|
48443
48642
|
);
|
|
48444
48643
|
} else {
|
|
48445
48644
|
LOG.debug(
|
|
48446
48645
|
"NativeHistory",
|
|
48447
|
-
`antigravity .db ${
|
|
48646
|
+
`antigravity .db ${path32.basename(filePath)} step ${row.idx} (type ${row.step_type}) dropped: no user prompt text (payload ${payload.length}B, top-level fields [${topLevelFieldNumbers(payload).join(",")}])`
|
|
48448
48647
|
);
|
|
48449
48648
|
continue;
|
|
48450
48649
|
}
|
|
@@ -48469,12 +48668,12 @@ function parseConversationDb(filePath, sessionId, workspace) {
|
|
|
48469
48668
|
content = recovered;
|
|
48470
48669
|
LOG.debug(
|
|
48471
48670
|
"NativeHistory",
|
|
48472
|
-
`antigravity .db ${
|
|
48671
|
+
`antigravity .db ${path32.basename(filePath)} step ${row.idx} (type ${row.step_type}): answer absent at field 20; recovered ${content.length} chars via printable-run fallback \u2014 possible step_payload schema drift`
|
|
48473
48672
|
);
|
|
48474
48673
|
} else {
|
|
48475
48674
|
LOG.debug(
|
|
48476
48675
|
"NativeHistory",
|
|
48477
|
-
`antigravity .db ${
|
|
48676
|
+
`antigravity .db ${path32.basename(filePath)} step ${row.idx} (type ${row.step_type}) dropped: no answer text (payload ${payload.length}B, top-level fields [${topLevelFieldNumbers(payload).join(",")}], reasoningOnly=${reasoning ? "yes" : "no"})`
|
|
48478
48677
|
);
|
|
48479
48678
|
continue;
|
|
48480
48679
|
}
|
|
@@ -48495,13 +48694,13 @@ function parseConversationDb(filePath, sessionId, workspace) {
|
|
|
48495
48694
|
return messages.length > 0 ? messages : null;
|
|
48496
48695
|
}
|
|
48497
48696
|
function readSession3(sessionPath, sessionId, workspace) {
|
|
48498
|
-
if (!sessionPath || !
|
|
48499
|
-
if (!
|
|
48697
|
+
if (!sessionPath || !path32.isAbsolute(sessionPath)) return null;
|
|
48698
|
+
if (!fs23.existsSync(sessionPath)) return null;
|
|
48500
48699
|
const sourceMtimeMs = statMtimeMs3(sessionPath);
|
|
48501
48700
|
const brainRootPath = brainRoot();
|
|
48502
|
-
if (sessionPath.startsWith(brainRootPath +
|
|
48701
|
+
if (sessionPath.startsWith(brainRootPath + path32.sep) && sessionPath.endsWith(".jsonl")) {
|
|
48503
48702
|
const relative5 = sessionPath.slice(brainRootPath.length + 1);
|
|
48504
|
-
const uuidFromPath = relative5.split(
|
|
48703
|
+
const uuidFromPath = relative5.split(path32.sep)[0];
|
|
48505
48704
|
const resolvedSessionId = sessionId || (isUuidLike(uuidFromPath) ? uuidFromPath : "");
|
|
48506
48705
|
if (!resolvedSessionId) return null;
|
|
48507
48706
|
const messages = parseBrainTranscript(sessionPath, resolvedSessionId, workspace);
|
|
@@ -48517,7 +48716,7 @@ function readSession3(sessionPath, sessionId, workspace) {
|
|
|
48517
48716
|
};
|
|
48518
48717
|
}
|
|
48519
48718
|
if (sessionPath.endsWith(".db")) {
|
|
48520
|
-
const dbSessionId = sessionId ||
|
|
48719
|
+
const dbSessionId = sessionId || path32.basename(sessionPath, ".db");
|
|
48521
48720
|
if (!isUuidLike(dbSessionId)) return null;
|
|
48522
48721
|
const messages = parseConversationDb(sessionPath, dbSessionId, workspace);
|
|
48523
48722
|
if (!messages || messages.length === 0) return null;
|
|
@@ -48532,7 +48731,7 @@ function readSession3(sessionPath, sessionId, workspace) {
|
|
|
48532
48731
|
};
|
|
48533
48732
|
}
|
|
48534
48733
|
if (sessionPath.endsWith(".pb")) {
|
|
48535
|
-
const pbSessionId = sessionId ||
|
|
48734
|
+
const pbSessionId = sessionId || path32.basename(sessionPath, ".pb");
|
|
48536
48735
|
if (!isUuidLike(pbSessionId)) return null;
|
|
48537
48736
|
const messages = parsePbFile(sessionPath, pbSessionId);
|
|
48538
48737
|
if (!messages || messages.length === 0) return null;
|
|
@@ -48546,7 +48745,7 @@ function readSession3(sessionPath, sessionId, workspace) {
|
|
|
48546
48745
|
partialReason: "antigravity_cli_pb_raw_text_extraction"
|
|
48547
48746
|
};
|
|
48548
48747
|
}
|
|
48549
|
-
if (
|
|
48748
|
+
if (path32.basename(sessionPath) === "history.jsonl") {
|
|
48550
48749
|
const resolvedSessionId = sessionId || "";
|
|
48551
48750
|
if (!resolvedSessionId || !isUuidLike(resolvedSessionId)) return null;
|
|
48552
48751
|
const rows = readHistoryRows().filter((r) => r.conversationId === resolvedSessionId);
|
|
@@ -48594,20 +48793,20 @@ function readSession3(sessionPath, sessionId, workspace) {
|
|
|
48594
48793
|
|
|
48595
48794
|
// src/providers/native-history/hermes-cli-transcript.ts
|
|
48596
48795
|
init_load_better_sqlite3();
|
|
48597
|
-
import * as
|
|
48598
|
-
import * as
|
|
48599
|
-
import * as
|
|
48600
|
-
var HERMES_STATE_DB =
|
|
48601
|
-
var HERMES_LEGACY_SESSIONS_DIR =
|
|
48796
|
+
import * as fs24 from "fs";
|
|
48797
|
+
import * as path33 from "path";
|
|
48798
|
+
import * as os24 from "os";
|
|
48799
|
+
var HERMES_STATE_DB = path33.join(os24.homedir(), ".hermes", "state.db");
|
|
48800
|
+
var HERMES_LEGACY_SESSIONS_DIR = path33.join(os24.homedir(), ".hermes", "sessions");
|
|
48602
48801
|
function statMtimeMs4(p) {
|
|
48603
48802
|
try {
|
|
48604
|
-
return Math.floor(
|
|
48803
|
+
return Math.floor(fs24.statSync(p).mtimeMs);
|
|
48605
48804
|
} catch {
|
|
48606
48805
|
return 0;
|
|
48607
48806
|
}
|
|
48608
48807
|
}
|
|
48609
48808
|
function openDb() {
|
|
48610
|
-
if (!
|
|
48809
|
+
if (!fs24.existsSync(HERMES_STATE_DB)) return null;
|
|
48611
48810
|
try {
|
|
48612
48811
|
const Database = loadBetterSqlite3();
|
|
48613
48812
|
return new Database(HERMES_STATE_DB, { readonly: true, fileMustExist: true });
|
|
@@ -48703,10 +48902,10 @@ function readSession4(sessionPath, requestedSessionId) {
|
|
|
48703
48902
|
}
|
|
48704
48903
|
}
|
|
48705
48904
|
}
|
|
48706
|
-
if (!
|
|
48905
|
+
if (!path33.isAbsolute(sessionPath) || !fs24.existsSync(sessionPath)) return null;
|
|
48707
48906
|
let raw;
|
|
48708
48907
|
try {
|
|
48709
|
-
raw = JSON.parse(
|
|
48908
|
+
raw = JSON.parse(fs24.readFileSync(sessionPath, "utf8"));
|
|
48710
48909
|
} catch {
|
|
48711
48910
|
return null;
|
|
48712
48911
|
}
|
|
@@ -48729,7 +48928,7 @@ function readSession4(sessionPath, requestedSessionId) {
|
|
|
48729
48928
|
});
|
|
48730
48929
|
}
|
|
48731
48930
|
if (messages.length === 0) return null;
|
|
48732
|
-
const sessionId = typeof raw.session_id === "string" && raw.session_id ? raw.session_id :
|
|
48931
|
+
const sessionId = typeof raw.session_id === "string" && raw.session_id ? raw.session_id : path33.basename(sessionPath, ".json").replace(/^session_/, "");
|
|
48733
48932
|
return {
|
|
48734
48933
|
messages,
|
|
48735
48934
|
providerSessionId: sessionId,
|
|
@@ -48759,7 +48958,7 @@ function createNativeHistoryDispatcher(reader) {
|
|
|
48759
48958
|
if (!sourcePath) return null;
|
|
48760
48959
|
if (input.forceRefresh === true || input.args?.forceRefresh === true) {
|
|
48761
48960
|
try {
|
|
48762
|
-
|
|
48961
|
+
fs25.statSync(sourcePath);
|
|
48763
48962
|
} catch {
|
|
48764
48963
|
}
|
|
48765
48964
|
}
|
|
@@ -48796,11 +48995,11 @@ function resolveSourcePath(reader, workspace, sessionId, sessionStartedAtMs, ins
|
|
|
48796
48995
|
}
|
|
48797
48996
|
}
|
|
48798
48997
|
function resolveClaudePath(workspace, sessionId) {
|
|
48799
|
-
const dir =
|
|
48800
|
-
if (!
|
|
48998
|
+
const dir = path34.join(os25.homedir(), ".claude", "projects", cwdAsDashes(workspace));
|
|
48999
|
+
if (!fs25.existsSync(dir)) return null;
|
|
48801
49000
|
if (sessionId) {
|
|
48802
|
-
const candidate =
|
|
48803
|
-
if (
|
|
49001
|
+
const candidate = path34.join(dir, `${sessionId}.jsonl`);
|
|
49002
|
+
if (fs25.existsSync(candidate)) return candidate;
|
|
48804
49003
|
}
|
|
48805
49004
|
return null;
|
|
48806
49005
|
}
|
|
@@ -48812,7 +49011,7 @@ function resolveCodexPath(workspace, sessionId, sessionStartedAtMs) {
|
|
|
48812
49011
|
return findCodexPathByRuntime(root, workspace, sessionStartedAtMs);
|
|
48813
49012
|
}
|
|
48814
49013
|
function findCodexPathBySessionId(root, sessionId) {
|
|
48815
|
-
if (!
|
|
49014
|
+
if (!fs25.existsSync(root)) return null;
|
|
48816
49015
|
const needle = sessionId.toLowerCase();
|
|
48817
49016
|
const matches = [];
|
|
48818
49017
|
const stack = [root];
|
|
@@ -48820,12 +49019,12 @@ function findCodexPathBySessionId(root, sessionId) {
|
|
|
48820
49019
|
const current = stack.pop();
|
|
48821
49020
|
let entries = [];
|
|
48822
49021
|
try {
|
|
48823
|
-
entries =
|
|
49022
|
+
entries = fs25.readdirSync(current, { withFileTypes: true });
|
|
48824
49023
|
} catch {
|
|
48825
49024
|
continue;
|
|
48826
49025
|
}
|
|
48827
49026
|
for (const entry of entries) {
|
|
48828
|
-
const entryPath =
|
|
49027
|
+
const entryPath = path34.join(current, entry.name);
|
|
48829
49028
|
if (entry.isDirectory()) {
|
|
48830
49029
|
stack.push(entryPath);
|
|
48831
49030
|
continue;
|
|
@@ -48840,7 +49039,7 @@ function findCodexPathBySessionId(root, sessionId) {
|
|
|
48840
49039
|
return matches[0]?.p ?? null;
|
|
48841
49040
|
}
|
|
48842
49041
|
function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
48843
|
-
if (!
|
|
49042
|
+
if (!fs25.existsSync(root) || !workspace) return null;
|
|
48844
49043
|
const workspaceResolved = resolveRealPath(workspace);
|
|
48845
49044
|
const cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
48846
49045
|
const matches = [];
|
|
@@ -48849,12 +49048,12 @@ function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
|
48849
49048
|
const current = stack.pop();
|
|
48850
49049
|
let entries = [];
|
|
48851
49050
|
try {
|
|
48852
|
-
entries =
|
|
49051
|
+
entries = fs25.readdirSync(current, { withFileTypes: true });
|
|
48853
49052
|
} catch {
|
|
48854
49053
|
continue;
|
|
48855
49054
|
}
|
|
48856
49055
|
for (const entry of entries) {
|
|
48857
|
-
const entryPath =
|
|
49056
|
+
const entryPath = path34.join(current, entry.name);
|
|
48858
49057
|
if (entry.isDirectory()) {
|
|
48859
49058
|
stack.push(entryPath);
|
|
48860
49059
|
continue;
|
|
@@ -48874,10 +49073,10 @@ function findCodexPathByRuntime(root, workspace, sessionStartedAtMs) {
|
|
|
48874
49073
|
}
|
|
48875
49074
|
function readCodexSessionMeta(filePath) {
|
|
48876
49075
|
try {
|
|
48877
|
-
const fd =
|
|
49076
|
+
const fd = fs25.openSync(filePath, "r");
|
|
48878
49077
|
try {
|
|
48879
49078
|
const buffer = Buffer.alloc(8192);
|
|
48880
|
-
const bytes =
|
|
49079
|
+
const bytes = fs25.readSync(fd, buffer, 0, buffer.length, 0);
|
|
48881
49080
|
if (bytes <= 0) return null;
|
|
48882
49081
|
const text = buffer.subarray(0, bytes).toString("utf8");
|
|
48883
49082
|
const firstLine = text.slice(0, text.indexOf("\n") >= 0 ? text.indexOf("\n") : text.length).trim();
|
|
@@ -48892,7 +49091,7 @@ function readCodexSessionMeta(filePath) {
|
|
|
48892
49091
|
timestampMs: Number.isFinite(timestampMs) ? timestampMs : void 0
|
|
48893
49092
|
};
|
|
48894
49093
|
} finally {
|
|
48895
|
-
|
|
49094
|
+
fs25.closeSync(fd);
|
|
48896
49095
|
}
|
|
48897
49096
|
} catch {
|
|
48898
49097
|
return null;
|
|
@@ -48900,35 +49099,35 @@ function readCodexSessionMeta(filePath) {
|
|
|
48900
49099
|
}
|
|
48901
49100
|
function resolveRealPath(value) {
|
|
48902
49101
|
try {
|
|
48903
|
-
return
|
|
49102
|
+
return fs25.realpathSync(value);
|
|
48904
49103
|
} catch {
|
|
48905
49104
|
return value;
|
|
48906
49105
|
}
|
|
48907
49106
|
}
|
|
48908
49107
|
var AGY_SPAWN_CLAIM_GRACE_MS = 2e3;
|
|
48909
49108
|
function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instanceId) {
|
|
48910
|
-
const agyRoot =
|
|
49109
|
+
const agyRoot = path34.join(os25.homedir(), ".gemini", "antigravity-cli");
|
|
48911
49110
|
const owner = antigravityOwnerToken(workspace, sessionStartedAtMs, instanceId);
|
|
48912
49111
|
if (sessionId && isUuidLikeSessionId2(sessionId)) {
|
|
48913
|
-
const dbPath =
|
|
48914
|
-
if (
|
|
49112
|
+
const dbPath = path34.join(agyRoot, "conversations", `${sessionId}.db`);
|
|
49113
|
+
if (fs25.existsSync(dbPath)) {
|
|
48915
49114
|
if (owner) claimAntigravityConversation(sessionId, owner);
|
|
48916
49115
|
return dbPath;
|
|
48917
49116
|
}
|
|
48918
49117
|
}
|
|
48919
|
-
const brainRoot2 =
|
|
48920
|
-
if (
|
|
49118
|
+
const brainRoot2 = path34.join(agyRoot, "brain");
|
|
49119
|
+
if (fs25.existsSync(brainRoot2)) {
|
|
48921
49120
|
const cutoff = spawnAwareCutoff(sessionStartedAtMs);
|
|
48922
|
-
const entries =
|
|
49121
|
+
const entries = fs25.readdirSync(brainRoot2, { withFileTypes: true }).filter((e) => e.isDirectory() && isUuidLikeSessionId2(e.name)).filter((e) => !isAntigravityConversationClaimedByOther(e.name, owner)).map((e) => ({ uuid: e.name, p: path34.join(brainRoot2, e.name), mtime: safeMtime(path34.join(brainRoot2, e.name)) })).filter((e) => e.mtime >= cutoff).sort((a, b) => b.mtime - a.mtime);
|
|
48923
49122
|
for (const e of entries) {
|
|
48924
|
-
const t =
|
|
48925
|
-
if (
|
|
49123
|
+
const t = path34.join(e.p, ".system_generated", "logs", "transcript.jsonl");
|
|
49124
|
+
if (fs25.existsSync(t) && safeSize(t) > 0) {
|
|
48926
49125
|
if (owner) claimAntigravityConversation(e.uuid, owner);
|
|
48927
49126
|
return t;
|
|
48928
49127
|
}
|
|
48929
49128
|
}
|
|
48930
49129
|
}
|
|
48931
|
-
const convRoot =
|
|
49130
|
+
const convRoot = path34.join(agyRoot, "conversations");
|
|
48932
49131
|
const picked = pickUnboundConversationDb(convRoot, sessionStartedAtMs, owner);
|
|
48933
49132
|
if (picked) {
|
|
48934
49133
|
if (owner) claimAntigravityConversation(picked.uuid, owner);
|
|
@@ -48939,7 +49138,7 @@ function resolveAntigravityPath(workspace, sessionId, sessionStartedAtMs, instan
|
|
|
48939
49138
|
function pickUnboundConversationDb(convRoot, sessionFloorMs, owner) {
|
|
48940
49139
|
let entries = [];
|
|
48941
49140
|
try {
|
|
48942
|
-
entries =
|
|
49141
|
+
entries = fs25.readdirSync(convRoot, { withFileTypes: true });
|
|
48943
49142
|
} catch {
|
|
48944
49143
|
return null;
|
|
48945
49144
|
}
|
|
@@ -48951,7 +49150,7 @@ function pickUnboundConversationDb(convRoot, sessionFloorMs, owner) {
|
|
|
48951
49150
|
if (!match || !isUuidLikeSessionId2(match[1])) continue;
|
|
48952
49151
|
const uuid = match[1];
|
|
48953
49152
|
if (isAntigravityConversationClaimedByOther(uuid, owner)) continue;
|
|
48954
|
-
const p =
|
|
49153
|
+
const p = path34.join(convRoot, entry.name);
|
|
48955
49154
|
const mtime = safeMtime(p);
|
|
48956
49155
|
if (mtime < recencyCutoff) continue;
|
|
48957
49156
|
candidates.push({ path: p, uuid, mtime, birth: safeBirthtime(p) });
|
|
@@ -48975,10 +49174,10 @@ function spawnAwareCutoff(sessionStartedAtMs) {
|
|
|
48975
49174
|
function resolveHermesPath(workspace, sessionId) {
|
|
48976
49175
|
void workspace;
|
|
48977
49176
|
void sessionId;
|
|
48978
|
-
const dbPath =
|
|
48979
|
-
if (
|
|
48980
|
-
const dir =
|
|
48981
|
-
if (!
|
|
49177
|
+
const dbPath = path34.join(os25.homedir(), ".hermes", "state.db");
|
|
49178
|
+
if (fs25.existsSync(dbPath)) return dbPath;
|
|
49179
|
+
const dir = path34.join(os25.homedir(), ".hermes", "sessions");
|
|
49180
|
+
if (!fs25.existsSync(dir)) return null;
|
|
48982
49181
|
return newestRecentFile2(dir, /^session_.*\.json$/);
|
|
48983
49182
|
}
|
|
48984
49183
|
function readByReader(reader, sourcePath, sessionId, workspace, requestedProviderSid) {
|
|
@@ -49003,7 +49202,7 @@ function cwdAsDashes(cwd) {
|
|
|
49003
49202
|
return cwd.replace(/\//g, "-");
|
|
49004
49203
|
}
|
|
49005
49204
|
function codexSessionsRoot() {
|
|
49006
|
-
return
|
|
49205
|
+
return path34.join(os25.homedir(), ".codex", "sessions");
|
|
49007
49206
|
}
|
|
49008
49207
|
function isUuidLikeSessionId2(sessionId) {
|
|
49009
49208
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(sessionId);
|
|
@@ -49015,7 +49214,7 @@ var RECENT_WINDOW_MS = 5 * 60 * 1e3;
|
|
|
49015
49214
|
function newestRecentFile2(dir, pattern) {
|
|
49016
49215
|
try {
|
|
49017
49216
|
const cutoff = Date.now() - RECENT_WINDOW_MS;
|
|
49018
|
-
const entries =
|
|
49217
|
+
const entries = fs25.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);
|
|
49019
49218
|
return entries[0]?.p ?? null;
|
|
49020
49219
|
} catch {
|
|
49021
49220
|
return null;
|
|
@@ -49023,14 +49222,14 @@ function newestRecentFile2(dir, pattern) {
|
|
|
49023
49222
|
}
|
|
49024
49223
|
function safeMtime(p) {
|
|
49025
49224
|
try {
|
|
49026
|
-
return Math.floor(
|
|
49225
|
+
return Math.floor(fs25.statSync(p).mtimeMs);
|
|
49027
49226
|
} catch {
|
|
49028
49227
|
return 0;
|
|
49029
49228
|
}
|
|
49030
49229
|
}
|
|
49031
49230
|
function safeBirthtime(p) {
|
|
49032
49231
|
try {
|
|
49033
|
-
const st =
|
|
49232
|
+
const st = fs25.statSync(p);
|
|
49034
49233
|
const birth = Math.floor(st.birthtimeMs);
|
|
49035
49234
|
return birth > 0 ? birth : Math.floor(st.mtimeMs);
|
|
49036
49235
|
} catch {
|
|
@@ -49039,7 +49238,7 @@ function safeBirthtime(p) {
|
|
|
49039
49238
|
}
|
|
49040
49239
|
function safeSize(p) {
|
|
49041
49240
|
try {
|
|
49042
|
-
return
|
|
49241
|
+
return fs25.statSync(p).size;
|
|
49043
49242
|
} catch {
|
|
49044
49243
|
return 0;
|
|
49045
49244
|
}
|
|
@@ -49133,9 +49332,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49133
49332
|
static siblingStderrLogged = /* @__PURE__ */ new Set();
|
|
49134
49333
|
static looksLikeProviderRoot(candidate) {
|
|
49135
49334
|
try {
|
|
49136
|
-
if (!
|
|
49335
|
+
if (!fs26.existsSync(candidate) || !fs26.statSync(candidate).isDirectory()) return false;
|
|
49137
49336
|
return ["ide", "extension", "cli", "acp"].some(
|
|
49138
|
-
(category) =>
|
|
49337
|
+
(category) => fs26.existsSync(path36.join(candidate, category))
|
|
49139
49338
|
);
|
|
49140
49339
|
} catch {
|
|
49141
49340
|
return false;
|
|
@@ -49143,20 +49342,20 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49143
49342
|
}
|
|
49144
49343
|
static hasProviderRootMarker(candidate) {
|
|
49145
49344
|
try {
|
|
49146
|
-
return
|
|
49345
|
+
return fs26.existsSync(path36.join(candidate, _ProviderLoader.SIBLING_MARKER_FILE));
|
|
49147
49346
|
} catch {
|
|
49148
49347
|
return false;
|
|
49149
49348
|
}
|
|
49150
49349
|
}
|
|
49151
49350
|
detectDefaultUserDir() {
|
|
49152
|
-
const fallback =
|
|
49351
|
+
const fallback = path36.join(os26.homedir(), ".adhdev", "providers");
|
|
49153
49352
|
const envOptIn = process.env[_ProviderLoader.SIBLING_ENV_VAR] === "1";
|
|
49154
49353
|
const visited = /* @__PURE__ */ new Set();
|
|
49155
49354
|
for (const start of this.probeStarts) {
|
|
49156
|
-
let current =
|
|
49355
|
+
let current = path36.resolve(start);
|
|
49157
49356
|
while (!visited.has(current)) {
|
|
49158
49357
|
visited.add(current);
|
|
49159
|
-
const siblingCandidate =
|
|
49358
|
+
const siblingCandidate = path36.join(path36.dirname(current), _ProviderLoader.REPO_PROVIDER_DIRNAME);
|
|
49160
49359
|
if (_ProviderLoader.looksLikeProviderRoot(siblingCandidate)) {
|
|
49161
49360
|
const hasMarker = _ProviderLoader.hasProviderRootMarker(siblingCandidate);
|
|
49162
49361
|
if (envOptIn || hasMarker) {
|
|
@@ -49178,7 +49377,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49178
49377
|
return { path: siblingCandidate, source };
|
|
49179
49378
|
}
|
|
49180
49379
|
}
|
|
49181
|
-
const parent =
|
|
49380
|
+
const parent = path36.dirname(current);
|
|
49182
49381
|
if (parent === current) break;
|
|
49183
49382
|
current = parent;
|
|
49184
49383
|
}
|
|
@@ -49190,11 +49389,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49190
49389
|
this.probeStarts = options?.probeStarts ?? [process.cwd(), __dirname];
|
|
49191
49390
|
this.registryBaseUrl = resolveRegistryBaseUrl(options?.registryUrl);
|
|
49192
49391
|
this.providerTarballUrl = resolveProviderTarballUrl(options?.providerTarballUrl);
|
|
49193
|
-
this.defaultProvidersDir =
|
|
49392
|
+
this.defaultProvidersDir = path36.join(os26.homedir(), ".adhdev", "providers");
|
|
49194
49393
|
const detected = this.detectDefaultUserDir();
|
|
49195
49394
|
this.userDir = detected.path;
|
|
49196
49395
|
this.userDirSource = detected.source;
|
|
49197
|
-
this.upstreamDir =
|
|
49396
|
+
this.upstreamDir = path36.join(this.defaultProvidersDir, ".upstream");
|
|
49198
49397
|
this.disableUpstream = false;
|
|
49199
49398
|
this.applySourceConfig({
|
|
49200
49399
|
userDir: options?.userDir,
|
|
@@ -49205,15 +49404,15 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49205
49404
|
}
|
|
49206
49405
|
migrateMarketplaceDirToExternal() {
|
|
49207
49406
|
try {
|
|
49208
|
-
const home =
|
|
49209
|
-
const oldDir =
|
|
49210
|
-
const newDir =
|
|
49211
|
-
if (!
|
|
49212
|
-
if (
|
|
49407
|
+
const home = os26.homedir();
|
|
49408
|
+
const oldDir = path36.join(home, ".adhdev", "marketplace");
|
|
49409
|
+
const newDir = path36.join(home, ".adhdev", "external");
|
|
49410
|
+
if (!fs26.existsSync(oldDir)) return;
|
|
49411
|
+
if (fs26.existsSync(newDir)) {
|
|
49213
49412
|
this.log(`Migration skipped: both ~/.adhdev/marketplace and ~/.adhdev/external exist (marketplace dir is now inert and can be removed manually).`);
|
|
49214
49413
|
return;
|
|
49215
49414
|
}
|
|
49216
|
-
|
|
49415
|
+
fs26.renameSync(oldDir, newDir);
|
|
49217
49416
|
this.log(`Migrated ~/.adhdev/marketplace \u2192 ~/.adhdev/external (one-time rename after provider source-layer cleanup).`);
|
|
49218
49417
|
} catch (e) {
|
|
49219
49418
|
this.log(`Marketplace\u2192external migration failed: ${e?.message || e}`);
|
|
@@ -49243,7 +49442,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49243
49442
|
* Highest-priority editable overrides come first.
|
|
49244
49443
|
*/
|
|
49245
49444
|
getProviderRoots() {
|
|
49246
|
-
const externalDir =
|
|
49445
|
+
const externalDir = path36.join(os26.homedir(), ".adhdev", "external");
|
|
49247
49446
|
return [this.userDir, externalDir, this.upstreamDir];
|
|
49248
49447
|
}
|
|
49249
49448
|
getSourceConfig() {
|
|
@@ -49271,7 +49470,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49271
49470
|
this.userDir = detected.path;
|
|
49272
49471
|
this.userDirSource = detected.source;
|
|
49273
49472
|
}
|
|
49274
|
-
this.upstreamDir =
|
|
49473
|
+
this.upstreamDir = path36.join(this.defaultProvidersDir, ".upstream");
|
|
49275
49474
|
this.disableUpstream = this.sourceMode === "no-upstream";
|
|
49276
49475
|
if (this.explicitProviderDir) {
|
|
49277
49476
|
this.log(`Config 'providerDir' applied: ${this.userDir}`);
|
|
@@ -49285,7 +49484,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49285
49484
|
* Canonical provider directory shape for a given root.
|
|
49286
49485
|
*/
|
|
49287
49486
|
getProviderDir(root, category, type) {
|
|
49288
|
-
return
|
|
49487
|
+
return path36.join(root, category, type);
|
|
49289
49488
|
}
|
|
49290
49489
|
/**
|
|
49291
49490
|
* Canonical user override directory for a provider.
|
|
@@ -49312,7 +49511,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49312
49511
|
resolveProviderFile(type, ...segments) {
|
|
49313
49512
|
const dir = this.findProviderDirInternal(type);
|
|
49314
49513
|
if (!dir) return null;
|
|
49315
|
-
return
|
|
49514
|
+
return path36.join(dir, ...segments);
|
|
49316
49515
|
}
|
|
49317
49516
|
/**
|
|
49318
49517
|
* Load all providers (3-tier priority)
|
|
@@ -49328,7 +49527,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49328
49527
|
this.providers.clear();
|
|
49329
49528
|
this.providerAvailability.clear();
|
|
49330
49529
|
let upstreamCount = 0;
|
|
49331
|
-
if (!this.disableUpstream &&
|
|
49530
|
+
if (!this.disableUpstream && fs26.existsSync(this.upstreamDir)) {
|
|
49332
49531
|
upstreamCount = this.loadDir(this.upstreamDir);
|
|
49333
49532
|
if (upstreamCount > 0) {
|
|
49334
49533
|
this.log(`Loaded ${upstreamCount} upstream providers (auto-updated)`);
|
|
@@ -49336,11 +49535,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49336
49535
|
} else if (this.disableUpstream) {
|
|
49337
49536
|
this.log("Upstream loading disabled (sourceMode=no-upstream)");
|
|
49338
49537
|
}
|
|
49339
|
-
const externalDir =
|
|
49340
|
-
if (
|
|
49538
|
+
const externalDir = path36.join(os26.homedir(), ".adhdev", "external");
|
|
49539
|
+
if (fs26.existsSync(externalDir)) {
|
|
49341
49540
|
const rootEntries = (() => {
|
|
49342
49541
|
try {
|
|
49343
|
-
return
|
|
49542
|
+
return fs26.readdirSync(externalDir, { withFileTypes: true });
|
|
49344
49543
|
} catch {
|
|
49345
49544
|
return [];
|
|
49346
49545
|
}
|
|
@@ -49358,7 +49557,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49358
49557
|
const ambiguousTypes = [];
|
|
49359
49558
|
for (const sourceEntry of rootEntries) {
|
|
49360
49559
|
if (!sourceEntry.isDirectory()) continue;
|
|
49361
|
-
const sourceDir =
|
|
49560
|
+
const sourceDir = path36.join(externalDir, sourceEntry.name);
|
|
49362
49561
|
const sourceLoaded = this.loadDir(sourceDir);
|
|
49363
49562
|
if (sourceLoaded > 0) {
|
|
49364
49563
|
totalLoaded += sourceLoaded;
|
|
@@ -49374,7 +49573,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49374
49573
|
ambiguousTypes.push({ type, chosen: resolved.source ?? "?", candidates: resolved.candidates });
|
|
49375
49574
|
}
|
|
49376
49575
|
if (resolved.source && resolved.source !== "?") {
|
|
49377
|
-
const sourceDir =
|
|
49576
|
+
const sourceDir = path36.join(externalDir, resolved.source);
|
|
49378
49577
|
const reloadCount = this.loadDir(sourceDir);
|
|
49379
49578
|
if (reloadCount === 0) {
|
|
49380
49579
|
this.log(`Active source "${resolved.source}" no longer provides ${type}`);
|
|
@@ -49389,7 +49588,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49389
49588
|
}
|
|
49390
49589
|
}
|
|
49391
49590
|
}
|
|
49392
|
-
if (
|
|
49591
|
+
if (fs26.existsSync(this.userDir)) {
|
|
49393
49592
|
const userCount = this.loadDir(this.userDir, [".upstream"]);
|
|
49394
49593
|
if (userCount > 0) {
|
|
49395
49594
|
this.log(`Loaded ${userCount} user custom providers (never auto-updated)`);
|
|
@@ -49404,10 +49603,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49404
49603
|
* Check if upstream directory exists and has providers.
|
|
49405
49604
|
*/
|
|
49406
49605
|
hasUpstream() {
|
|
49407
|
-
if (!
|
|
49606
|
+
if (!fs26.existsSync(this.upstreamDir)) return false;
|
|
49408
49607
|
try {
|
|
49409
|
-
return
|
|
49410
|
-
(d) =>
|
|
49608
|
+
return fs26.readdirSync(this.upstreamDir).some(
|
|
49609
|
+
(d) => fs26.statSync(path36.join(this.upstreamDir, d)).isDirectory()
|
|
49411
49610
|
);
|
|
49412
49611
|
} catch {
|
|
49413
49612
|
return false;
|
|
@@ -49905,8 +50104,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49905
50104
|
resolved._resolvedScriptDir = entry.scriptDir;
|
|
49906
50105
|
resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
|
|
49907
50106
|
if (providerDir) {
|
|
49908
|
-
const fullDir =
|
|
49909
|
-
resolved._resolvedScriptsPath =
|
|
50107
|
+
const fullDir = path36.join(providerDir, entry.scriptDir);
|
|
50108
|
+
resolved._resolvedScriptsPath = fs26.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
49910
50109
|
}
|
|
49911
50110
|
matched = true;
|
|
49912
50111
|
}
|
|
@@ -49924,8 +50123,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49924
50123
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
49925
50124
|
resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
|
|
49926
50125
|
if (providerDir) {
|
|
49927
|
-
const fullDir =
|
|
49928
|
-
resolved._resolvedScriptsPath =
|
|
50126
|
+
const fullDir = path36.join(providerDir, base.defaultScriptDir);
|
|
50127
|
+
resolved._resolvedScriptsPath = fs26.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
49929
50128
|
}
|
|
49930
50129
|
}
|
|
49931
50130
|
resolved._versionWarning = `Version ${currentVersion} not in compatibility matrix. Using default scripts.`;
|
|
@@ -49942,8 +50141,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49942
50141
|
resolved._resolvedScriptDir = dirOverride;
|
|
49943
50142
|
resolved._resolvedScriptsSource = `versions:${range}`;
|
|
49944
50143
|
if (providerDir) {
|
|
49945
|
-
const fullDir =
|
|
49946
|
-
resolved._resolvedScriptsPath =
|
|
50144
|
+
const fullDir = path36.join(providerDir, dirOverride);
|
|
50145
|
+
resolved._resolvedScriptsPath = fs26.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
49947
50146
|
}
|
|
49948
50147
|
}
|
|
49949
50148
|
} else if (override.scripts) {
|
|
@@ -49959,8 +50158,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49959
50158
|
resolved._resolvedScriptDir = base.defaultScriptDir;
|
|
49960
50159
|
resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
|
|
49961
50160
|
if (providerDir) {
|
|
49962
|
-
const fullDir =
|
|
49963
|
-
resolved._resolvedScriptsPath =
|
|
50161
|
+
const fullDir = path36.join(providerDir, base.defaultScriptDir);
|
|
50162
|
+
resolved._resolvedScriptsPath = fs26.existsSync(path36.join(fullDir, "scripts.js")) ? path36.join(fullDir, "scripts.js") : fullDir;
|
|
49964
50163
|
}
|
|
49965
50164
|
}
|
|
49966
50165
|
}
|
|
@@ -49977,13 +50176,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
49977
50176
|
if (providerDir2) {
|
|
49978
50177
|
for (const [scriptName, override] of Object.entries(base.overrides)) {
|
|
49979
50178
|
if (!override || typeof override.path !== "string") continue;
|
|
49980
|
-
const fullPath =
|
|
49981
|
-
if (!
|
|
50179
|
+
const fullPath = path36.join(providerDir2, override.path);
|
|
50180
|
+
if (!fs26.existsSync(fullPath)) {
|
|
49982
50181
|
this.log(` [overrides] ${base.type}: ${scriptName} path not found: ${fullPath}`);
|
|
49983
50182
|
continue;
|
|
49984
50183
|
}
|
|
49985
50184
|
try {
|
|
49986
|
-
registerProviderScriptRootSafely(
|
|
50185
|
+
registerProviderScriptRootSafely(path36.dirname(path36.dirname(providerDir2)));
|
|
49987
50186
|
delete __require.cache[__require.resolve(fullPath)];
|
|
49988
50187
|
const fn = __require(fullPath);
|
|
49989
50188
|
const target = typeof fn === "function" ? fn : fn && fn[scriptName];
|
|
@@ -50008,25 +50207,25 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50008
50207
|
}
|
|
50009
50208
|
if (providerDir) {
|
|
50010
50209
|
try {
|
|
50011
|
-
const
|
|
50012
|
-
const
|
|
50210
|
+
const fs41 = __require("fs");
|
|
50211
|
+
const path45 = __require("path");
|
|
50013
50212
|
const candidates = [];
|
|
50014
50213
|
if (Array.isArray(base.compatibility)) {
|
|
50015
50214
|
for (const entry of base.compatibility) {
|
|
50016
50215
|
if (typeof entry?.spec !== "string") continue;
|
|
50017
50216
|
const matches = !entry.ideVersion || currentVersion && this.matchesVersion(currentVersion, entry.ideVersion) || !currentVersion;
|
|
50018
|
-
if (matches) candidates.push(
|
|
50217
|
+
if (matches) candidates.push(path45.join(providerDir, entry.spec));
|
|
50019
50218
|
}
|
|
50020
50219
|
}
|
|
50021
|
-
candidates.push(
|
|
50022
|
-
candidates.push(
|
|
50023
|
-
const specPath = candidates.find((p) =>
|
|
50220
|
+
candidates.push(path45.join(providerDir, "specs", "default.json"));
|
|
50221
|
+
candidates.push(path45.join(providerDir, "spec.json"));
|
|
50222
|
+
const specPath = candidates.find((p) => fs41.existsSync(p));
|
|
50024
50223
|
if (specPath) {
|
|
50025
50224
|
resolved._resolvedSpecPath = specPath;
|
|
50026
50225
|
let specControls;
|
|
50027
50226
|
let nh;
|
|
50028
50227
|
try {
|
|
50029
|
-
const rawSpec = JSON.parse(
|
|
50228
|
+
const rawSpec = JSON.parse(fs41.readFileSync(specPath, "utf8"));
|
|
50030
50229
|
specControls = rawSpec.control_bar;
|
|
50031
50230
|
nh = rawSpec.native_history;
|
|
50032
50231
|
} catch {
|
|
@@ -50057,10 +50256,10 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50057
50256
|
format = `spec-${nh.source.kind}`;
|
|
50058
50257
|
reader = (input) => executeNativeHistory(nh, input);
|
|
50059
50258
|
} else if (nh.override_path) {
|
|
50060
|
-
const overrideFile =
|
|
50061
|
-
if (
|
|
50259
|
+
const overrideFile = path45.resolve(providerDir, nh.override_path);
|
|
50260
|
+
if (fs41.existsSync(overrideFile)) {
|
|
50062
50261
|
try {
|
|
50063
|
-
registerProviderScriptRootSafely(
|
|
50262
|
+
registerProviderScriptRootSafely(path45.dirname(path45.dirname(providerDir)));
|
|
50064
50263
|
delete __require.cache[__require.resolve(overrideFile)];
|
|
50065
50264
|
const mod = __require(overrideFile);
|
|
50066
50265
|
const fn = typeof mod === "function" ? mod : mod && typeof mod.default === "function" ? mod.default : null;
|
|
@@ -50103,16 +50302,16 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50103
50302
|
this.debugLog(`[loadScriptsFromDir] ${type}: providerDir not found`);
|
|
50104
50303
|
return null;
|
|
50105
50304
|
}
|
|
50106
|
-
const dir =
|
|
50107
|
-
if (!
|
|
50305
|
+
const dir = path36.join(providerDir, scriptDir);
|
|
50306
|
+
if (!fs26.existsSync(dir)) {
|
|
50108
50307
|
this.debugLog(`[loadScriptsFromDir] ${type}: dir not found: ${dir}`);
|
|
50109
50308
|
return null;
|
|
50110
50309
|
}
|
|
50111
|
-
registerProviderScriptRootSafely(
|
|
50310
|
+
registerProviderScriptRootSafely(path36.dirname(path36.dirname(providerDir)));
|
|
50112
50311
|
const cached3 = this.scriptsCache.get(dir);
|
|
50113
50312
|
if (cached3) return cached3;
|
|
50114
|
-
const scriptsJs =
|
|
50115
|
-
if (
|
|
50313
|
+
const scriptsJs = path36.join(dir, "scripts.js");
|
|
50314
|
+
if (fs26.existsSync(scriptsJs)) {
|
|
50116
50315
|
try {
|
|
50117
50316
|
delete __require.cache[__require.resolve(scriptsJs)];
|
|
50118
50317
|
const loaded = __require(scriptsJs);
|
|
@@ -50133,9 +50332,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50133
50332
|
watch() {
|
|
50134
50333
|
this.stopWatch();
|
|
50135
50334
|
const watchDir = (dir) => {
|
|
50136
|
-
if (!
|
|
50335
|
+
if (!fs26.existsSync(dir)) {
|
|
50137
50336
|
try {
|
|
50138
|
-
|
|
50337
|
+
fs26.mkdirSync(dir, { recursive: true });
|
|
50139
50338
|
} catch {
|
|
50140
50339
|
return;
|
|
50141
50340
|
}
|
|
@@ -50156,7 +50355,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50156
50355
|
if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
|
|
50157
50356
|
if (reloadTimer) clearTimeout(reloadTimer);
|
|
50158
50357
|
reloadTimer = setTimeout(() => {
|
|
50159
|
-
this.log(`File changed: ${
|
|
50358
|
+
this.log(`File changed: ${path36.basename(filePath)}, reloading...`);
|
|
50160
50359
|
this.reload();
|
|
50161
50360
|
}, 300);
|
|
50162
50361
|
}
|
|
@@ -50224,11 +50423,11 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50224
50423
|
}
|
|
50225
50424
|
this.log(`Registry sync starting (${this.registryBaseUrl})...`);
|
|
50226
50425
|
const https = __require("https");
|
|
50227
|
-
const regMetaPath =
|
|
50426
|
+
const regMetaPath = path36.join(this.upstreamDir, _ProviderLoader.REGISTRY_META_FILE);
|
|
50228
50427
|
let cachedChecksums = {};
|
|
50229
50428
|
try {
|
|
50230
|
-
if (
|
|
50231
|
-
cachedChecksums = JSON.parse(
|
|
50429
|
+
if (fs26.existsSync(regMetaPath)) {
|
|
50430
|
+
cachedChecksums = JSON.parse(fs26.readFileSync(regMetaPath, "utf-8")).checksums ?? {};
|
|
50232
50431
|
}
|
|
50233
50432
|
} catch {
|
|
50234
50433
|
}
|
|
@@ -50279,15 +50478,15 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50279
50478
|
this.log(`\u26A0 Registry checksum mismatch for ${type}@${version} \u2014 skipping`);
|
|
50280
50479
|
continue;
|
|
50281
50480
|
}
|
|
50282
|
-
const providerDir =
|
|
50283
|
-
|
|
50284
|
-
|
|
50481
|
+
const providerDir = path36.join(this.upstreamDir, category, type);
|
|
50482
|
+
fs26.mkdirSync(providerDir, { recursive: true });
|
|
50483
|
+
fs26.writeFileSync(path36.join(providerDir, "provider.json"), manifestBody, "utf-8");
|
|
50285
50484
|
cachedChecksums[cacheKey] = checksum;
|
|
50286
50485
|
updatedCount++;
|
|
50287
50486
|
this.log(`\u2713 Registry updated: ${category}/${type}@${version}`);
|
|
50288
50487
|
}
|
|
50289
|
-
|
|
50290
|
-
|
|
50488
|
+
fs26.mkdirSync(this.upstreamDir, { recursive: true });
|
|
50489
|
+
fs26.writeFileSync(regMetaPath, JSON.stringify({
|
|
50291
50490
|
checksums: cachedChecksums,
|
|
50292
50491
|
syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
50293
50492
|
providerCount: list.providers.length
|
|
@@ -50308,12 +50507,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50308
50507
|
const { exec: exec7 } = __require("child_process");
|
|
50309
50508
|
const { promisify: promisify8 } = __require("util");
|
|
50310
50509
|
const execAsync5 = promisify8(exec7);
|
|
50311
|
-
const metaPath =
|
|
50510
|
+
const metaPath = path36.join(this.upstreamDir, _ProviderLoader.META_FILE);
|
|
50312
50511
|
let prevEtag = "";
|
|
50313
50512
|
let prevTimestamp = 0;
|
|
50314
50513
|
try {
|
|
50315
|
-
if (
|
|
50316
|
-
const meta = JSON.parse(
|
|
50514
|
+
if (fs26.existsSync(metaPath)) {
|
|
50515
|
+
const meta = JSON.parse(fs26.readFileSync(metaPath, "utf-8"));
|
|
50317
50516
|
prevEtag = meta.etag || "";
|
|
50318
50517
|
prevTimestamp = meta.timestamp || 0;
|
|
50319
50518
|
}
|
|
@@ -50369,39 +50568,39 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50369
50568
|
return { updated: false };
|
|
50370
50569
|
}
|
|
50371
50570
|
this.log("Downloading latest providers from GitHub...");
|
|
50372
|
-
const tmpTar =
|
|
50373
|
-
const tmpExtract =
|
|
50571
|
+
const tmpTar = path36.join(os26.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
|
|
50572
|
+
const tmpExtract = path36.join(os26.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
|
|
50374
50573
|
await this.downloadFile(tarballTarget.url, tmpTar);
|
|
50375
|
-
|
|
50574
|
+
fs26.mkdirSync(tmpExtract, { recursive: true });
|
|
50376
50575
|
await execAsync5(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
|
|
50377
|
-
const extracted =
|
|
50576
|
+
const extracted = fs26.readdirSync(tmpExtract);
|
|
50378
50577
|
const rootDir = extracted.find(
|
|
50379
|
-
(d) =>
|
|
50578
|
+
(d) => fs26.statSync(path36.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
|
|
50380
50579
|
);
|
|
50381
50580
|
if (!rootDir) throw new Error("Unexpected tarball structure");
|
|
50382
|
-
const sourceDir =
|
|
50581
|
+
const sourceDir = path36.join(tmpExtract, rootDir);
|
|
50383
50582
|
const backupDir = this.upstreamDir + ".bak";
|
|
50384
|
-
if (
|
|
50385
|
-
if (
|
|
50386
|
-
|
|
50583
|
+
if (fs26.existsSync(this.upstreamDir)) {
|
|
50584
|
+
if (fs26.existsSync(backupDir)) fs26.rmSync(backupDir, { recursive: true, force: true });
|
|
50585
|
+
fs26.renameSync(this.upstreamDir, backupDir);
|
|
50387
50586
|
}
|
|
50388
50587
|
try {
|
|
50389
50588
|
this.copyDirRecursive(sourceDir, this.upstreamDir);
|
|
50390
50589
|
this.writeMeta(metaPath, etag || `ts-${Date.now()}`, Date.now());
|
|
50391
|
-
if (
|
|
50590
|
+
if (fs26.existsSync(backupDir)) fs26.rmSync(backupDir, { recursive: true, force: true });
|
|
50392
50591
|
} catch (e) {
|
|
50393
|
-
if (
|
|
50394
|
-
if (
|
|
50395
|
-
|
|
50592
|
+
if (fs26.existsSync(backupDir)) {
|
|
50593
|
+
if (fs26.existsSync(this.upstreamDir)) fs26.rmSync(this.upstreamDir, { recursive: true, force: true });
|
|
50594
|
+
fs26.renameSync(backupDir, this.upstreamDir);
|
|
50396
50595
|
}
|
|
50397
50596
|
throw e;
|
|
50398
50597
|
}
|
|
50399
50598
|
try {
|
|
50400
|
-
|
|
50599
|
+
fs26.rmSync(tmpTar, { force: true });
|
|
50401
50600
|
} catch {
|
|
50402
50601
|
}
|
|
50403
50602
|
try {
|
|
50404
|
-
|
|
50603
|
+
fs26.rmSync(tmpExtract, { recursive: true, force: true });
|
|
50405
50604
|
} catch {
|
|
50406
50605
|
}
|
|
50407
50606
|
const upstreamCount = this.countProviders(this.upstreamDir);
|
|
@@ -50433,7 +50632,7 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50433
50632
|
reject(new Error(`HTTP ${res.statusCode}`));
|
|
50434
50633
|
return;
|
|
50435
50634
|
}
|
|
50436
|
-
const ws =
|
|
50635
|
+
const ws = fs26.createWriteStream(destPath);
|
|
50437
50636
|
res.pipe(ws);
|
|
50438
50637
|
ws.on("finish", () => {
|
|
50439
50638
|
ws.close();
|
|
@@ -50452,22 +50651,22 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50452
50651
|
}
|
|
50453
50652
|
/** Recursive directory copy */
|
|
50454
50653
|
copyDirRecursive(src, dest) {
|
|
50455
|
-
|
|
50456
|
-
for (const entry of
|
|
50457
|
-
const srcPath =
|
|
50458
|
-
const destPath =
|
|
50654
|
+
fs26.mkdirSync(dest, { recursive: true });
|
|
50655
|
+
for (const entry of fs26.readdirSync(src, { withFileTypes: true })) {
|
|
50656
|
+
const srcPath = path36.join(src, entry.name);
|
|
50657
|
+
const destPath = path36.join(dest, entry.name);
|
|
50459
50658
|
if (entry.isDirectory()) {
|
|
50460
50659
|
this.copyDirRecursive(srcPath, destPath);
|
|
50461
50660
|
} else {
|
|
50462
|
-
|
|
50661
|
+
fs26.copyFileSync(srcPath, destPath);
|
|
50463
50662
|
}
|
|
50464
50663
|
}
|
|
50465
50664
|
}
|
|
50466
50665
|
/** .meta.json save */
|
|
50467
50666
|
writeMeta(metaPath, etag, timestamp) {
|
|
50468
50667
|
try {
|
|
50469
|
-
|
|
50470
|
-
|
|
50668
|
+
fs26.mkdirSync(path36.dirname(metaPath), { recursive: true });
|
|
50669
|
+
fs26.writeFileSync(metaPath, JSON.stringify({
|
|
50471
50670
|
etag,
|
|
50472
50671
|
timestamp,
|
|
50473
50672
|
lastCheck: new Date(timestamp).toISOString(),
|
|
@@ -50478,15 +50677,15 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50478
50677
|
}
|
|
50479
50678
|
/** Count provider files (provider.v1.json or provider.json — at most one per dir). */
|
|
50480
50679
|
countProviders(dir) {
|
|
50481
|
-
if (!
|
|
50680
|
+
if (!fs26.existsSync(dir)) return 0;
|
|
50482
50681
|
let count = 0;
|
|
50483
50682
|
const scan = (d) => {
|
|
50484
50683
|
try {
|
|
50485
|
-
const entries =
|
|
50684
|
+
const entries = fs26.readdirSync(d, { withFileTypes: true });
|
|
50486
50685
|
const hasManifest = entries.some((e) => e.name === "provider.v1.json" || e.name === "provider.json");
|
|
50487
50686
|
if (hasManifest) count++;
|
|
50488
50687
|
for (const entry of entries) {
|
|
50489
|
-
if (entry.isDirectory()) scan(
|
|
50688
|
+
if (entry.isDirectory()) scan(path36.join(d, entry.name));
|
|
50490
50689
|
}
|
|
50491
50690
|
} catch {
|
|
50492
50691
|
}
|
|
@@ -50712,13 +50911,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50712
50911
|
if (!provider) return null;
|
|
50713
50912
|
const cat = provider.category;
|
|
50714
50913
|
const searchRoots = this.getProviderRoots();
|
|
50715
|
-
const hasManifest = (dir) =>
|
|
50914
|
+
const hasManifest = (dir) => fs26.existsSync(path36.join(dir, "provider.v1.json")) || fs26.existsSync(path36.join(dir, "provider.json"));
|
|
50716
50915
|
const readManifestType = (dir) => {
|
|
50717
50916
|
for (const file of ["provider.v1.json", "provider.json"]) {
|
|
50718
|
-
const p =
|
|
50719
|
-
if (!
|
|
50917
|
+
const p = path36.join(dir, file);
|
|
50918
|
+
if (!fs26.existsSync(p)) continue;
|
|
50720
50919
|
try {
|
|
50721
|
-
const data = JSON.parse(
|
|
50920
|
+
const data = JSON.parse(fs26.readFileSync(p, "utf-8"));
|
|
50722
50921
|
if (typeof data?.type === "string") return data.type;
|
|
50723
50922
|
} catch {
|
|
50724
50923
|
}
|
|
@@ -50726,15 +50925,15 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50726
50925
|
return null;
|
|
50727
50926
|
};
|
|
50728
50927
|
for (const root of searchRoots) {
|
|
50729
|
-
if (!
|
|
50928
|
+
if (!fs26.existsSync(root)) continue;
|
|
50730
50929
|
const candidate = this.getProviderDir(root, cat, type);
|
|
50731
50930
|
if (hasManifest(candidate)) return candidate;
|
|
50732
|
-
const catDir =
|
|
50733
|
-
if (
|
|
50931
|
+
const catDir = path36.join(root, cat);
|
|
50932
|
+
if (fs26.existsSync(catDir)) {
|
|
50734
50933
|
try {
|
|
50735
|
-
for (const entry of
|
|
50934
|
+
for (const entry of fs26.readdirSync(catDir, { withFileTypes: true })) {
|
|
50736
50935
|
if (!entry.isDirectory()) continue;
|
|
50737
|
-
const entryDir =
|
|
50936
|
+
const entryDir = path36.join(catDir, entry.name);
|
|
50738
50937
|
const manifestType = readManifestType(entryDir);
|
|
50739
50938
|
if (manifestType === type) return entryDir;
|
|
50740
50939
|
}
|
|
@@ -50750,8 +50949,8 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50750
50949
|
* (template substitution is NOT applied here — scripts.js handles that)
|
|
50751
50950
|
*/
|
|
50752
50951
|
buildScriptWrappersFromDir(dir) {
|
|
50753
|
-
const scriptsJs =
|
|
50754
|
-
if (
|
|
50952
|
+
const scriptsJs = path36.join(dir, "scripts.js");
|
|
50953
|
+
if (fs26.existsSync(scriptsJs)) {
|
|
50755
50954
|
try {
|
|
50756
50955
|
delete __require.cache[__require.resolve(scriptsJs)];
|
|
50757
50956
|
return __require(scriptsJs);
|
|
@@ -50761,13 +50960,13 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50761
50960
|
const toCamel = (name) => name.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
50762
50961
|
const result = {};
|
|
50763
50962
|
try {
|
|
50764
|
-
for (const file of
|
|
50963
|
+
for (const file of fs26.readdirSync(dir)) {
|
|
50765
50964
|
if (!file.endsWith(".js")) continue;
|
|
50766
50965
|
const scriptName = toCamel(file.replace(".js", ""));
|
|
50767
|
-
const filePath =
|
|
50966
|
+
const filePath = path36.join(dir, file);
|
|
50768
50967
|
result[scriptName] = (...args) => {
|
|
50769
50968
|
try {
|
|
50770
|
-
let content =
|
|
50969
|
+
let content = fs26.readFileSync(filePath, "utf-8");
|
|
50771
50970
|
if (args[0] && typeof args[0] === "object") {
|
|
50772
50971
|
for (const [key2, val] of Object.entries(args[0])) {
|
|
50773
50972
|
let v = val;
|
|
@@ -50813,12 +51012,12 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50813
51012
|
* Structure: dir/category/agent-name/provider.{json,js}
|
|
50814
51013
|
*/
|
|
50815
51014
|
loadDir(dir, excludeDirs) {
|
|
50816
|
-
if (!
|
|
51015
|
+
if (!fs26.existsSync(dir)) return 0;
|
|
50817
51016
|
let count = 0;
|
|
50818
51017
|
const scan = (d) => {
|
|
50819
51018
|
let entries;
|
|
50820
51019
|
try {
|
|
50821
|
-
entries =
|
|
51020
|
+
entries = fs26.readdirSync(d, { withFileTypes: true });
|
|
50822
51021
|
} catch {
|
|
50823
51022
|
return;
|
|
50824
51023
|
}
|
|
@@ -50826,9 +51025,9 @@ var ProviderLoader = class _ProviderLoader {
|
|
|
50826
51025
|
const hasJson = entries.some((e) => e.name === "provider.json");
|
|
50827
51026
|
if (hasV1 || hasJson) {
|
|
50828
51027
|
const manifestFile = hasV1 ? "provider.v1.json" : "provider.json";
|
|
50829
|
-
const jsonPath =
|
|
51028
|
+
const jsonPath = path36.join(d, manifestFile);
|
|
50830
51029
|
try {
|
|
50831
|
-
const raw =
|
|
51030
|
+
const raw = fs26.readFileSync(jsonPath, "utf-8");
|
|
50832
51031
|
const mod = JSON.parse(raw);
|
|
50833
51032
|
if (hasV1 && mod?.category === "cli") {
|
|
50834
51033
|
try {
|
|
@@ -50866,10 +51065,10 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
50866
51065
|
this.log(`\u26A0 Invalid provider at ${jsonPath}: ${validation.errors.join("; ")}`);
|
|
50867
51066
|
} else {
|
|
50868
51067
|
const hasCompatibility = Array.isArray(normalizedProvider.compatibility);
|
|
50869
|
-
const scriptsPath =
|
|
50870
|
-
if (!hasCompatibility &&
|
|
51068
|
+
const scriptsPath = path36.join(d, "scripts.js");
|
|
51069
|
+
if (!hasCompatibility && fs26.existsSync(scriptsPath)) {
|
|
50871
51070
|
try {
|
|
50872
|
-
registerProviderScriptRootSafely(
|
|
51071
|
+
registerProviderScriptRootSafely(path36.dirname(path36.dirname(d)));
|
|
50873
51072
|
delete __require.cache[__require.resolve(scriptsPath)];
|
|
50874
51073
|
const scripts = __require(scriptsPath);
|
|
50875
51074
|
normalizedProvider.scripts = scripts;
|
|
@@ -50877,7 +51076,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
50877
51076
|
this.log(`\u26A0 Failed to load scripts: ${scriptsPath}: ${e.message}`);
|
|
50878
51077
|
}
|
|
50879
51078
|
}
|
|
50880
|
-
const externalDirAbs =
|
|
51079
|
+
const externalDirAbs = path36.join(os26.homedir(), ".adhdev", "external");
|
|
50881
51080
|
const layer = d.startsWith(externalDirAbs) ? "external" : d.startsWith(this.userDir) && !d.includes(".upstream") ? "user" : "upstream";
|
|
50882
51081
|
try {
|
|
50883
51082
|
const { inspectManifestShape: inspectManifestShape2, classifyTrust: classifyTrust2 } = (init_provider_trust(), __toCommonJS(provider_trust_exports));
|
|
@@ -50887,8 +51086,8 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
50887
51086
|
normalizedProvider._sourceTrust = trust;
|
|
50888
51087
|
normalizedProvider._manifestShape = shape;
|
|
50889
51088
|
if (layer === "external") {
|
|
50890
|
-
const rel =
|
|
50891
|
-
const firstSeg = rel.split(
|
|
51089
|
+
const rel = path36.relative(externalDirAbs, d);
|
|
51090
|
+
const firstSeg = rel.split(path36.sep)[0];
|
|
50892
51091
|
if (firstSeg && firstSeg !== "..") normalizedProvider._sourceName = firstSeg;
|
|
50893
51092
|
}
|
|
50894
51093
|
} catch {
|
|
@@ -50912,7 +51111,7 @@ ${formatManifestValidationIssues2(validation2.issues)}`);
|
|
|
50912
51111
|
if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
|
|
50913
51112
|
if (d === dir && entry.name === "examples") continue;
|
|
50914
51113
|
if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
|
|
50915
|
-
scan(
|
|
51114
|
+
scan(path36.join(d, entry.name));
|
|
50916
51115
|
}
|
|
50917
51116
|
}
|
|
50918
51117
|
};
|
|
@@ -51110,7 +51309,7 @@ async function isCdpActive(port) {
|
|
|
51110
51309
|
});
|
|
51111
51310
|
}
|
|
51112
51311
|
async function killIdeProcess(ideId) {
|
|
51113
|
-
const plat =
|
|
51312
|
+
const plat = os27.platform();
|
|
51114
51313
|
const appName = getMacAppIdentifiers()[ideId];
|
|
51115
51314
|
const winProcesses = getWinProcessNames()[ideId];
|
|
51116
51315
|
try {
|
|
@@ -51171,7 +51370,7 @@ async function killIdeProcess(ideId) {
|
|
|
51171
51370
|
}
|
|
51172
51371
|
}
|
|
51173
51372
|
async function isIdeRunning(ideId) {
|
|
51174
|
-
const plat =
|
|
51373
|
+
const plat = os27.platform();
|
|
51175
51374
|
try {
|
|
51176
51375
|
if (plat === "darwin") {
|
|
51177
51376
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -51226,7 +51425,7 @@ async function isIdeRunning(ideId) {
|
|
|
51226
51425
|
}
|
|
51227
51426
|
}
|
|
51228
51427
|
async function detectCurrentWorkspace(ideId) {
|
|
51229
|
-
const plat =
|
|
51428
|
+
const plat = os27.platform();
|
|
51230
51429
|
if (plat === "darwin") {
|
|
51231
51430
|
try {
|
|
51232
51431
|
const appName = getMacAppIdentifiers()[ideId];
|
|
@@ -51241,17 +51440,17 @@ async function detectCurrentWorkspace(ideId) {
|
|
|
51241
51440
|
}
|
|
51242
51441
|
} else if (plat === "win32") {
|
|
51243
51442
|
try {
|
|
51244
|
-
const
|
|
51443
|
+
const fs41 = __require("fs");
|
|
51245
51444
|
const appNameMap = getMacAppIdentifiers();
|
|
51246
51445
|
const appName = appNameMap[ideId];
|
|
51247
51446
|
if (appName) {
|
|
51248
|
-
const storagePath =
|
|
51249
|
-
process.env.APPDATA ||
|
|
51447
|
+
const storagePath = path37.join(
|
|
51448
|
+
process.env.APPDATA || path37.join(os27.homedir(), "AppData", "Roaming"),
|
|
51250
51449
|
appName,
|
|
51251
51450
|
"storage.json"
|
|
51252
51451
|
);
|
|
51253
|
-
if (
|
|
51254
|
-
const data = JSON.parse(
|
|
51452
|
+
if (fs41.existsSync(storagePath)) {
|
|
51453
|
+
const data = JSON.parse(fs41.readFileSync(storagePath, "utf-8"));
|
|
51255
51454
|
const workspaces = data?.openedPathsList?.workspaces3 || data?.openedPathsList?.entries || [];
|
|
51256
51455
|
if (workspaces.length > 0) {
|
|
51257
51456
|
const recent = workspaces[0];
|
|
@@ -51268,7 +51467,7 @@ async function detectCurrentWorkspace(ideId) {
|
|
|
51268
51467
|
return void 0;
|
|
51269
51468
|
}
|
|
51270
51469
|
async function launchWithCdp(options = {}) {
|
|
51271
|
-
const platform10 =
|
|
51470
|
+
const platform10 = os27.platform();
|
|
51272
51471
|
let targetIde;
|
|
51273
51472
|
const ides = await detectIDEs(getProviderLoader());
|
|
51274
51473
|
if (options.ideId) {
|
|
@@ -51771,11 +51970,11 @@ var meshCrudHandlers = {
|
|
|
51771
51970
|
MESH_JSON_CONFIG_LOCATIONS: MESH_JSON_CONFIG_LOCATIONS2
|
|
51772
51971
|
} = await Promise.resolve().then(() => (init_mesh_json_config(), mesh_json_config_exports));
|
|
51773
51972
|
const { mkdirSync: mkdirSync22, writeFileSync: writeFileSync24 } = await import("fs");
|
|
51774
|
-
const { dirname: dirname17, join:
|
|
51973
|
+
const { dirname: dirname17, join: join51 } = await import("path");
|
|
51775
51974
|
const scaffold = buildMeshJsonConfigScaffold2(mesh);
|
|
51776
51975
|
const scaffoldJson = serializeMeshJsonConfigScaffold2(scaffold);
|
|
51777
51976
|
const relativePath = MESH_JSON_CONFIG_LOCATIONS2[0];
|
|
51778
|
-
const absolutePath =
|
|
51977
|
+
const absolutePath = join51(workspace, relativePath);
|
|
51779
51978
|
const validation = normalizeRepoMeshDeclarativeConfig2(scaffold);
|
|
51780
51979
|
if (!validation.valid) {
|
|
51781
51980
|
return { success: false, meshId, error: `invalid mesh.json scaffold: ${validation.errors.join("; ")}` };
|
|
@@ -52840,7 +53039,7 @@ init_worktree_bootstrap_config();
|
|
|
52840
53039
|
init_change_impact_config();
|
|
52841
53040
|
init_mesh_config();
|
|
52842
53041
|
import { existsSync as existsSync38, mkdirSync as mkdirSync15, writeFileSync as writeFileSync18 } from "fs";
|
|
52843
|
-
import { dirname as dirname11, join as
|
|
53042
|
+
import { dirname as dirname11, join as join42 } from "path";
|
|
52844
53043
|
var MESH_INIT_REFINE_CONFIG_PATH = MESH_REFINE_CONFIG_LOCATIONS[0];
|
|
52845
53044
|
var MESH_INIT_WORKTREE_BOOTSTRAP_CONFIG_PATH = MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS[0];
|
|
52846
53045
|
var MESH_INIT_CHANGE_IMPACT_CONFIG_PATH = CHANGE_IMPACT_CONFIG_LOCATIONS[0];
|
|
@@ -52855,7 +53054,7 @@ var CANDIDATE_STALE_INPUTS = [
|
|
|
52855
53054
|
"requirements.txt"
|
|
52856
53055
|
];
|
|
52857
53056
|
function writeConfigFile(workspace, relativePath, config) {
|
|
52858
|
-
const target =
|
|
53057
|
+
const target = join42(workspace, relativePath);
|
|
52859
53058
|
mkdirSync15(dirname11(target), { recursive: true });
|
|
52860
53059
|
writeFileSync18(target, `${JSON.stringify(config, null, 2)}
|
|
52861
53060
|
`, "utf-8");
|
|
@@ -52863,14 +53062,14 @@ function writeConfigFile(workspace, relativePath, config) {
|
|
|
52863
53062
|
}
|
|
52864
53063
|
function suggestMeshWorktreeBootstrapConfig(workspace) {
|
|
52865
53064
|
const commands = [];
|
|
52866
|
-
const hasPackageJson = existsSync38(
|
|
52867
|
-
const hasNpmLock = existsSync38(
|
|
53065
|
+
const hasPackageJson = existsSync38(join42(workspace, "package.json"));
|
|
53066
|
+
const hasNpmLock = existsSync38(join42(workspace, "package-lock.json"));
|
|
52868
53067
|
if (hasPackageJson) {
|
|
52869
53068
|
commands.push(
|
|
52870
53069
|
hasNpmLock ? { command: "npm", args: ["ci"] } : { command: "npm", args: ["install"] }
|
|
52871
53070
|
);
|
|
52872
53071
|
}
|
|
52873
|
-
const staleInputs = CANDIDATE_STALE_INPUTS.filter((relative5) => existsSync38(
|
|
53072
|
+
const staleInputs = CANDIDATE_STALE_INPUTS.filter((relative5) => existsSync38(join42(workspace, relative5)));
|
|
52874
53073
|
if (!commands.length) {
|
|
52875
53074
|
return { commands, staleInputs };
|
|
52876
53075
|
}
|
|
@@ -52969,7 +53168,7 @@ function runMeshInit(mesh, workspace, detected, options = {}) {
|
|
|
52969
53168
|
}
|
|
52970
53169
|
function applyConfigSuggestion(input) {
|
|
52971
53170
|
const { workspace, relativePath, existing, suggestedConfig, validate, write, overwrite } = input;
|
|
52972
|
-
const absolute =
|
|
53171
|
+
const absolute = join42(workspace, relativePath);
|
|
52973
53172
|
if (existing !== void 0 && !overwrite) {
|
|
52974
53173
|
return { path: absolute, relativePath, written: false, skippedReason: "already_exists", config: existing };
|
|
52975
53174
|
}
|
|
@@ -53231,7 +53430,7 @@ init_logger();
|
|
|
53231
53430
|
init_mesh_host_ownership();
|
|
53232
53431
|
init_coordinator_registry();
|
|
53233
53432
|
import { join as pathJoin } from "path";
|
|
53234
|
-
import * as
|
|
53433
|
+
import * as fs27 from "fs";
|
|
53235
53434
|
init_mesh_coordinator();
|
|
53236
53435
|
init_dist();
|
|
53237
53436
|
var meshCoordinatorLaunchHandlers = {
|
|
@@ -53463,15 +53662,15 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
53463
53662
|
}
|
|
53464
53663
|
if (cliType === "codex-cli") {
|
|
53465
53664
|
const repoMcpConfigPath = pathJoin(workspace, ".mcp.json");
|
|
53466
|
-
if (
|
|
53665
|
+
if (fs27.existsSync(repoMcpConfigPath)) {
|
|
53467
53666
|
try {
|
|
53468
53667
|
const repoMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
53469
|
-
|
|
53668
|
+
fs27.readFileSync(repoMcpConfigPath, "utf-8"),
|
|
53470
53669
|
"claude_mcp_json"
|
|
53471
53670
|
);
|
|
53472
53671
|
const existingServers2 = repoMcpConfig.mcpServers;
|
|
53473
53672
|
if (existingServers2 && typeof existingServers2 === "object" && !Array.isArray(existingServers2) && existingServers2[coordinatorSetup.serverName]) {
|
|
53474
|
-
|
|
53673
|
+
fs27.writeFileSync(repoMcpConfigPath, serializeMeshCoordinatorMcpConfig({
|
|
53475
53674
|
...repoMcpConfig,
|
|
53476
53675
|
mcpServers: {
|
|
53477
53676
|
...existingServers2,
|
|
@@ -53760,7 +53959,7 @@ init_dist();
|
|
|
53760
53959
|
init_mesh_events();
|
|
53761
53960
|
init_mesh_routing();
|
|
53762
53961
|
init_mesh_host_ownership();
|
|
53763
|
-
import * as
|
|
53962
|
+
import * as fs28 from "fs";
|
|
53764
53963
|
import { hostname as osHostname } from "os";
|
|
53765
53964
|
|
|
53766
53965
|
// src/mesh/preview-freshness.ts
|
|
@@ -53801,10 +54000,10 @@ function runGit2(repoRoot, args) {
|
|
|
53801
54000
|
}
|
|
53802
54001
|
}
|
|
53803
54002
|
function readRecord6(repoRoot) {
|
|
53804
|
-
const
|
|
53805
|
-
if (!existsSync40(
|
|
54003
|
+
const path45 = resolve19(repoRoot, PREVIEW_DEPLOY_RECORD);
|
|
54004
|
+
if (!existsSync40(path45)) return null;
|
|
53806
54005
|
try {
|
|
53807
|
-
const parsed = JSON.parse(readFileSync31(
|
|
54006
|
+
const parsed = JSON.parse(readFileSync31(path45, "utf8"));
|
|
53808
54007
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
53809
54008
|
} catch {
|
|
53810
54009
|
return null;
|
|
@@ -54115,7 +54314,7 @@ var meshStatusHandlers = {
|
|
|
54115
54314
|
}
|
|
54116
54315
|
}
|
|
54117
54316
|
if (workspace) {
|
|
54118
|
-
if (!
|
|
54317
|
+
if (!fs28.existsSync(workspace)) {
|
|
54119
54318
|
const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
|
|
54120
54319
|
let remoteProbeApplied = false;
|
|
54121
54320
|
if (inlineTransitGit) {
|
|
@@ -54245,7 +54444,7 @@ var meshStatusHandlers = {
|
|
|
54245
54444
|
backstop: { ...getMeshV2BackstopCounters() }
|
|
54246
54445
|
};
|
|
54247
54446
|
const previewFreshness = (() => {
|
|
54248
|
-
const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate &&
|
|
54447
|
+
const localRepoRoot = nodeStatuses.map((node) => readStringValue(node?.git?.repoRoot, node?.repoRoot, node?.workspace)).find((candidate) => !!candidate && fs28.existsSync(candidate));
|
|
54249
54448
|
return localRepoRoot ? buildPreviewFreshness(localRepoRoot) : void 0;
|
|
54250
54449
|
})();
|
|
54251
54450
|
const asyncRefineJobs = buildMeshAsyncRefineJobs({
|
|
@@ -54445,15 +54644,15 @@ init_dist();
|
|
|
54445
54644
|
init_logger();
|
|
54446
54645
|
|
|
54447
54646
|
// src/logging/command-log.ts
|
|
54448
|
-
import * as
|
|
54449
|
-
import * as
|
|
54450
|
-
import * as
|
|
54451
|
-
var ADHDEV_HOME2 = process.env.ADHDEV_CONFIG_DIR && process.env.ADHDEV_CONFIG_DIR.trim() ? process.env.ADHDEV_CONFIG_DIR.trim() :
|
|
54452
|
-
var LOG_DIR2 =
|
|
54647
|
+
import * as fs29 from "fs";
|
|
54648
|
+
import * as path38 from "path";
|
|
54649
|
+
import * as os28 from "os";
|
|
54650
|
+
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");
|
|
54651
|
+
var LOG_DIR2 = path38.join(ADHDEV_HOME2, "logs");
|
|
54453
54652
|
var MAX_FILE_SIZE = 5 * 1024 * 1024;
|
|
54454
54653
|
var MAX_DAYS = 7;
|
|
54455
54654
|
try {
|
|
54456
|
-
|
|
54655
|
+
fs29.mkdirSync(LOG_DIR2, { recursive: true });
|
|
54457
54656
|
} catch {
|
|
54458
54657
|
}
|
|
54459
54658
|
var SENSITIVE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -54487,19 +54686,19 @@ function getDateStr2() {
|
|
|
54487
54686
|
return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
54488
54687
|
}
|
|
54489
54688
|
var currentDate2 = getDateStr2();
|
|
54490
|
-
var currentFile =
|
|
54689
|
+
var currentFile = path38.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
54491
54690
|
var writeCount2 = 0;
|
|
54492
54691
|
function checkRotation() {
|
|
54493
54692
|
const today = getDateStr2();
|
|
54494
54693
|
if (today !== currentDate2) {
|
|
54495
54694
|
currentDate2 = today;
|
|
54496
|
-
currentFile =
|
|
54695
|
+
currentFile = path38.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
|
|
54497
54696
|
cleanOldFiles();
|
|
54498
54697
|
}
|
|
54499
54698
|
}
|
|
54500
54699
|
function cleanOldFiles() {
|
|
54501
54700
|
try {
|
|
54502
|
-
const files =
|
|
54701
|
+
const files = fs29.readdirSync(LOG_DIR2).filter((f) => f.startsWith("commands-") && f.endsWith(".jsonl"));
|
|
54503
54702
|
const cutoff = /* @__PURE__ */ new Date();
|
|
54504
54703
|
cutoff.setDate(cutoff.getDate() - MAX_DAYS);
|
|
54505
54704
|
const cutoffStr = cutoff.toISOString().slice(0, 10);
|
|
@@ -54507,7 +54706,7 @@ function cleanOldFiles() {
|
|
|
54507
54706
|
const dateMatch = file.match(/commands-(\d{4}-\d{2}-\d{2})/);
|
|
54508
54707
|
if (dateMatch && dateMatch[1] < cutoffStr) {
|
|
54509
54708
|
try {
|
|
54510
|
-
|
|
54709
|
+
fs29.unlinkSync(path38.join(LOG_DIR2, file));
|
|
54511
54710
|
} catch {
|
|
54512
54711
|
}
|
|
54513
54712
|
}
|
|
@@ -54517,14 +54716,14 @@ function cleanOldFiles() {
|
|
|
54517
54716
|
}
|
|
54518
54717
|
function checkSize() {
|
|
54519
54718
|
try {
|
|
54520
|
-
const stat2 =
|
|
54719
|
+
const stat2 = fs29.statSync(currentFile);
|
|
54521
54720
|
if (stat2.size > MAX_FILE_SIZE) {
|
|
54522
54721
|
const backup = currentFile.replace(".jsonl", ".1.jsonl");
|
|
54523
54722
|
try {
|
|
54524
|
-
|
|
54723
|
+
fs29.unlinkSync(backup);
|
|
54525
54724
|
} catch {
|
|
54526
54725
|
}
|
|
54527
|
-
|
|
54726
|
+
fs29.renameSync(currentFile, backup);
|
|
54528
54727
|
}
|
|
54529
54728
|
} catch {
|
|
54530
54729
|
}
|
|
@@ -54557,14 +54756,14 @@ function logCommand(entry) {
|
|
|
54557
54756
|
...entry.error ? { err: entry.error } : {},
|
|
54558
54757
|
...entry.durationMs !== void 0 ? { ms: entry.durationMs } : {}
|
|
54559
54758
|
});
|
|
54560
|
-
|
|
54759
|
+
fs29.appendFileSync(currentFile, line + "\n");
|
|
54561
54760
|
} catch {
|
|
54562
54761
|
}
|
|
54563
54762
|
}
|
|
54564
54763
|
function getRecentCommands(count = 50) {
|
|
54565
54764
|
try {
|
|
54566
|
-
if (!
|
|
54567
|
-
const content =
|
|
54765
|
+
if (!fs29.existsSync(currentFile)) return [];
|
|
54766
|
+
const content = fs29.readFileSync(currentFile, "utf-8");
|
|
54568
54767
|
const lines = content.trim().split("\n").filter(Boolean);
|
|
54569
54768
|
return lines.slice(-count).map((line) => {
|
|
54570
54769
|
try {
|
|
@@ -54592,7 +54791,7 @@ cleanOldFiles();
|
|
|
54592
54791
|
// src/commands/router.ts
|
|
54593
54792
|
init_debug_trace();
|
|
54594
54793
|
init_mesh_host_ownership();
|
|
54595
|
-
import * as
|
|
54794
|
+
import * as fs34 from "fs";
|
|
54596
54795
|
|
|
54597
54796
|
// src/mesh/mesh-node-identity.ts
|
|
54598
54797
|
init_cli_detector();
|
|
@@ -54600,7 +54799,7 @@ init_git_status();
|
|
|
54600
54799
|
init_dist();
|
|
54601
54800
|
init_logger();
|
|
54602
54801
|
init_mesh_warmup_deadline();
|
|
54603
|
-
import * as
|
|
54802
|
+
import * as fs30 from "fs";
|
|
54604
54803
|
init_runtime_defaults();
|
|
54605
54804
|
function readProviderPriorityFromPolicy(policy) {
|
|
54606
54805
|
const record = policy && typeof policy === "object" && !Array.isArray(policy) ? policy : {};
|
|
@@ -54987,7 +55186,7 @@ function isDeadLocalWorktreeNode(node) {
|
|
|
54987
55186
|
if (node?.isLocalWorktree !== true) return false;
|
|
54988
55187
|
const workspace = readStringValue(node?.workspace);
|
|
54989
55188
|
if (!workspace) return false;
|
|
54990
|
-
return !
|
|
55189
|
+
return !fs30.existsSync(workspace);
|
|
54991
55190
|
}
|
|
54992
55191
|
function foldMeshNodeIdentityToCanonical(node) {
|
|
54993
55192
|
if (!node || typeof node !== "object" || Array.isArray(node)) return node;
|
|
@@ -55235,7 +55434,7 @@ function summarizeInlineMeshBranchConvergence(nodes) {
|
|
|
55235
55434
|
const followUps = nodes.filter((node) => {
|
|
55236
55435
|
if (readObjectRecord(node.branchConvergence).needsConvergence !== true) return false;
|
|
55237
55436
|
const workspace = typeof node.workspace === "string" ? node.workspace : "";
|
|
55238
|
-
if (workspace && !
|
|
55437
|
+
if (workspace && !fs30.existsSync(workspace)) return false;
|
|
55239
55438
|
return true;
|
|
55240
55439
|
}).map((node) => {
|
|
55241
55440
|
const convergence = readObjectRecord(node.branchConvergence);
|
|
@@ -55665,7 +55864,7 @@ async function hydrateInlineMeshDirectTruth(args) {
|
|
|
55665
55864
|
if (!workspace) {
|
|
55666
55865
|
return !isSelfNode && daemonId ? { kind: "unavailable", nodeId } : { kind: "skip" };
|
|
55667
55866
|
}
|
|
55668
|
-
if (
|
|
55867
|
+
if (fs30.existsSync(workspace)) {
|
|
55669
55868
|
try {
|
|
55670
55869
|
const runLocalProbe = () => getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
|
|
55671
55870
|
const localGit = args.probeCache ? await args.probeCache.probeLocal(workspace, runLocalProbe) : await runLocalProbe();
|
|
@@ -55812,7 +56011,7 @@ function readLiveMeshNodeWorkspace(args) {
|
|
|
55812
56011
|
}
|
|
55813
56012
|
function collectLiveMeshSessionRecords(args) {
|
|
55814
56013
|
const nodeWorkspace = readStringValue(args.node?.workspace);
|
|
55815
|
-
const nodeIsMissingLocalWorktree = args.node?.isLocalWorktree === true && !!nodeWorkspace && !
|
|
56014
|
+
const nodeIsMissingLocalWorktree = args.node?.isLocalWorktree === true && !!nodeWorkspace && !fs30.existsSync(nodeWorkspace);
|
|
55816
56015
|
const matches = args.liveSessionRecords.filter((record) => {
|
|
55817
56016
|
const recordNodeId = readStringValue(record?.meta?.meshNodeId);
|
|
55818
56017
|
if (recordNodeId && !daemonIdsEquivalent(recordNodeId, args.nodeId)) return false;
|
|
@@ -55839,7 +56038,7 @@ function buildHistoricalMeshSessions(args) {
|
|
|
55839
56038
|
const workspace = readStringValue(node?.workspace);
|
|
55840
56039
|
if (nodeId) liveNodeIds.add(nodeId);
|
|
55841
56040
|
if (workspace) liveWorkspaces.add(workspace);
|
|
55842
|
-
if (nodeId && node?.isLocalWorktree === true && workspace && !
|
|
56041
|
+
if (nodeId && node?.isLocalWorktree === true && workspace && !fs30.existsSync(workspace)) {
|
|
55843
56042
|
missingLocalWorktreeNodeIds.add(nodeId);
|
|
55844
56043
|
}
|
|
55845
56044
|
}
|
|
@@ -55935,9 +56134,9 @@ import { promisify as promisify6 } from "util";
|
|
|
55935
56134
|
var execFileAsync3 = promisify6(execFile4);
|
|
55936
56135
|
var GIT = process.platform === "win32" ? resolveWin32Executable("git") : "git";
|
|
55937
56136
|
var MAX_CHANGED_FILES2 = 500;
|
|
55938
|
-
function topLevel(
|
|
55939
|
-
const slash =
|
|
55940
|
-
return slash === -1 ?
|
|
56137
|
+
function topLevel(path45) {
|
|
56138
|
+
const slash = path45.indexOf("/");
|
|
56139
|
+
return slash === -1 ? path45 : path45.slice(0, slash);
|
|
55941
56140
|
}
|
|
55942
56141
|
async function analyzeMeshRefineNodeChangeArea(args) {
|
|
55943
56142
|
const { nodeId, workspace, branch, baseRef, branchRef, diffCwd, submodulePaths } = args;
|
|
@@ -56026,7 +56225,7 @@ init_refine_config();
|
|
|
56026
56225
|
init_worktree_bootstrap_config();
|
|
56027
56226
|
init_resolve_executable();
|
|
56028
56227
|
import { basename as pathBasename, join as pathJoin2, resolve as pathResolve2 } from "path";
|
|
56029
|
-
import * as
|
|
56228
|
+
import * as fs31 from "fs";
|
|
56030
56229
|
import { execFileSync as execFileSync7 } from "child_process";
|
|
56031
56230
|
var GIT2 = process.platform === "win32" ? resolveWin32Executable("git") : "git";
|
|
56032
56231
|
var REFINE_VALIDATION_TIMEOUT_MS = 12e4;
|
|
@@ -56085,7 +56284,7 @@ async function computeGitPatchId(cwd, fromRef, toRef, excludePaths = []) {
|
|
|
56085
56284
|
const { execFileSync: execFileSync10 } = await import("child_process");
|
|
56086
56285
|
const diffArgs = ["diff", "--patch", "--full-index", fromRef, toRef];
|
|
56087
56286
|
if (excludePaths.length > 0) {
|
|
56088
|
-
diffArgs.push("--", ".", ...excludePaths.map((
|
|
56287
|
+
diffArgs.push("--", ".", ...excludePaths.map((path45) => `:(exclude)${path45}`));
|
|
56089
56288
|
}
|
|
56090
56289
|
const diff = execFileSync10(GIT2, diffArgs, {
|
|
56091
56290
|
cwd,
|
|
@@ -56286,9 +56485,9 @@ async function runMeshRefineEffectiveDiffGate(repoRoot, baseHead, branchHead) {
|
|
|
56286
56485
|
if (!trimmed) continue;
|
|
56287
56486
|
if (trimmed.startsWith("+")) {
|
|
56288
56487
|
const parts = trimmed.slice(1).trim().split(/\s+/);
|
|
56289
|
-
const
|
|
56488
|
+
const path45 = parts[1] || parts[0] || "(unknown)";
|
|
56290
56489
|
submoduleHints.push({
|
|
56291
|
-
path:
|
|
56490
|
+
path: path45,
|
|
56292
56491
|
reason: "submodule checked-out commit differs from the committed gitlink (pointer bump not committed on the root branch)"
|
|
56293
56492
|
});
|
|
56294
56493
|
}
|
|
@@ -56318,10 +56517,10 @@ async function runMeshRefineEffectiveDiffGate(repoRoot, baseHead, branchHead) {
|
|
|
56318
56517
|
}
|
|
56319
56518
|
function buildPatchEquivalenceSubmoduleConflictHint(repoRoot, baseHead, branchHead, output) {
|
|
56320
56519
|
if (!/(submodule|160000)/i.test(output) || !/(conflict|failed to merge)/i.test(output)) return void 0;
|
|
56321
|
-
const conflicts = readChangedGitlinkPaths(repoRoot, baseHead, branchHead).map((
|
|
56322
|
-
path:
|
|
56323
|
-
baseCommit: readTreeObject(repoRoot, baseHead,
|
|
56324
|
-
branchCommit: readTreeObject(repoRoot, branchHead,
|
|
56520
|
+
const conflicts = readChangedGitlinkPaths(repoRoot, baseHead, branchHead).map((path45) => ({
|
|
56521
|
+
path: path45,
|
|
56522
|
+
baseCommit: readTreeObject(repoRoot, baseHead, path45),
|
|
56523
|
+
branchCommit: readTreeObject(repoRoot, branchHead, path45)
|
|
56325
56524
|
}));
|
|
56326
56525
|
if (conflicts.length === 0) return void 0;
|
|
56327
56526
|
return {
|
|
@@ -56347,11 +56546,11 @@ function readChangedGitlinkPaths(repoRoot, fromRef, toRef) {
|
|
|
56347
56546
|
if (!line.trim()) continue;
|
|
56348
56547
|
const metaAndPath = line.split(" ");
|
|
56349
56548
|
const meta = metaAndPath[0] || "";
|
|
56350
|
-
const
|
|
56351
|
-
if (!
|
|
56549
|
+
const path45 = metaAndPath[metaAndPath.length - 1]?.trim();
|
|
56550
|
+
if (!path45) continue;
|
|
56352
56551
|
const parts = meta.split(/\s+/);
|
|
56353
56552
|
if (parts[0]?.includes("160000") || parts[1]?.includes("160000")) {
|
|
56354
|
-
paths.add(
|
|
56553
|
+
paths.add(path45);
|
|
56355
56554
|
}
|
|
56356
56555
|
}
|
|
56357
56556
|
return [...paths].sort();
|
|
@@ -56359,9 +56558,9 @@ function readChangedGitlinkPaths(repoRoot, fromRef, toRef) {
|
|
|
56359
56558
|
return [];
|
|
56360
56559
|
}
|
|
56361
56560
|
}
|
|
56362
|
-
function readTreeObject(repoRoot, ref,
|
|
56561
|
+
function readTreeObject(repoRoot, ref, path45) {
|
|
56363
56562
|
try {
|
|
56364
|
-
const output = execFileSync7(GIT2, ["ls-tree", ref, "--",
|
|
56563
|
+
const output = execFileSync7(GIT2, ["ls-tree", ref, "--", path45], {
|
|
56365
56564
|
cwd: repoRoot,
|
|
56366
56565
|
encoding: "utf8",
|
|
56367
56566
|
maxBuffer: 1024 * 1024
|
|
@@ -56384,7 +56583,7 @@ function isSubmoduleFastForward(submoduleRepoPath, baseCommit, branchCommit) {
|
|
|
56384
56583
|
if (!baseCommit || !branchCommit) return false;
|
|
56385
56584
|
if (baseCommit === branchCommit) return true;
|
|
56386
56585
|
try {
|
|
56387
|
-
if (!
|
|
56586
|
+
if (!fs31.existsSync(submoduleRepoPath)) return false;
|
|
56388
56587
|
execFileSync7(GIT2, ["cat-file", "-e", `${baseCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
56389
56588
|
execFileSync7(GIT2, ["cat-file", "-e", `${branchCommit}^{commit}`], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
56390
56589
|
execFileSync7(GIT2, ["merge-base", "--is-ancestor", baseCommit, branchCommit], { cwd: submoduleRepoPath, stdio: "ignore" });
|
|
@@ -56406,12 +56605,12 @@ function readChangedPathKinds(repoRoot, fromRef, toRef) {
|
|
|
56406
56605
|
if (!line.trim()) continue;
|
|
56407
56606
|
const metaAndPath = line.split(" ");
|
|
56408
56607
|
const meta = metaAndPath[0] || "";
|
|
56409
|
-
const
|
|
56410
|
-
if (!
|
|
56411
|
-
seen.add(
|
|
56608
|
+
const path45 = metaAndPath[metaAndPath.length - 1]?.trim();
|
|
56609
|
+
if (!path45 || seen.has(path45)) continue;
|
|
56610
|
+
seen.add(path45);
|
|
56412
56611
|
const parts = meta.split(/\s+/);
|
|
56413
56612
|
const isGitlink = !!(parts[0]?.includes("160000") || parts[1]?.includes("160000"));
|
|
56414
|
-
result.push({ path:
|
|
56613
|
+
result.push({ path: path45, isGitlink });
|
|
56415
56614
|
}
|
|
56416
56615
|
return result;
|
|
56417
56616
|
} catch {
|
|
@@ -56419,20 +56618,20 @@ function readChangedPathKinds(repoRoot, fromRef, toRef) {
|
|
|
56419
56618
|
}
|
|
56420
56619
|
}
|
|
56421
56620
|
function collectFastForwardGitlinkPaths(repoRoot, baseHead, branchHead) {
|
|
56422
|
-
return readChangedGitlinkPaths(repoRoot, baseHead, branchHead).filter((
|
|
56423
|
-
const baseCommit = readTreeObject(repoRoot, baseHead,
|
|
56424
|
-
const branchCommit = readTreeObject(repoRoot, branchHead,
|
|
56621
|
+
return readChangedGitlinkPaths(repoRoot, baseHead, branchHead).filter((path45) => {
|
|
56622
|
+
const baseCommit = readTreeObject(repoRoot, baseHead, path45);
|
|
56623
|
+
const branchCommit = readTreeObject(repoRoot, branchHead, path45);
|
|
56425
56624
|
if (!baseCommit || !branchCommit) return false;
|
|
56426
|
-
return isSubmoduleFastForward(pathResolve2(repoRoot,
|
|
56625
|
+
return isSubmoduleFastForward(pathResolve2(repoRoot, path45), baseCommit, branchCommit);
|
|
56427
56626
|
});
|
|
56428
56627
|
}
|
|
56429
56628
|
function evaluateGitlinkTrivialFastForward(repoRoot, baseHead, branchHead) {
|
|
56430
|
-
const changedGitlinks = readChangedGitlinkPaths(repoRoot, baseHead, branchHead).map((
|
|
56431
|
-
const baseCommit = readTreeObject(repoRoot, baseHead,
|
|
56432
|
-
const branchCommit = readTreeObject(repoRoot, branchHead,
|
|
56433
|
-
const submoduleRepoPath = pathResolve2(repoRoot,
|
|
56629
|
+
const changedGitlinks = readChangedGitlinkPaths(repoRoot, baseHead, branchHead).map((path45) => {
|
|
56630
|
+
const baseCommit = readTreeObject(repoRoot, baseHead, path45);
|
|
56631
|
+
const branchCommit = readTreeObject(repoRoot, branchHead, path45);
|
|
56632
|
+
const submoduleRepoPath = pathResolve2(repoRoot, path45);
|
|
56434
56633
|
const fastForward = !!baseCommit && !!branchCommit && isSubmoduleFastForward(submoduleRepoPath, baseCommit, branchCommit);
|
|
56435
|
-
return { path:
|
|
56634
|
+
return { path: path45, baseCommit, branchCommit, fastForward };
|
|
56436
56635
|
});
|
|
56437
56636
|
if (changedGitlinks.length === 0) {
|
|
56438
56637
|
return { trivial: false, reason: "no_changed_gitlinks", gitlinks: changedGitlinks };
|
|
@@ -56483,7 +56682,7 @@ function buildTreeWithGitlinksEqualized(repoRoot, commitish, paths, placeholderC
|
|
|
56483
56682
|
maxBuffer: 1024 * 1024
|
|
56484
56683
|
}).trim();
|
|
56485
56684
|
if (!tree) return void 0;
|
|
56486
|
-
const updates = paths.map((
|
|
56685
|
+
const updates = paths.map((path45) => `160000 commit ${placeholderCommit} ${path45}`).join("\n");
|
|
56487
56686
|
if (!updates) return tree;
|
|
56488
56687
|
const tmpIndex = pathJoin2(resolveGitDir(repoRoot), `adhdev-refine-eq-${commitish.slice(0, 12)}.index`);
|
|
56489
56688
|
const env = { ...process.env, GIT_INDEX_FILE: tmpIndex };
|
|
@@ -56501,7 +56700,7 @@ function buildTreeWithGitlinksEqualized(repoRoot, commitish, paths, placeholderC
|
|
|
56501
56700
|
return newTree || void 0;
|
|
56502
56701
|
} finally {
|
|
56503
56702
|
try {
|
|
56504
|
-
|
|
56703
|
+
fs31.rmSync(tmpIndex, { force: true });
|
|
56505
56704
|
} catch {
|
|
56506
56705
|
}
|
|
56507
56706
|
}
|
|
@@ -56576,7 +56775,7 @@ function synthesizeTrivialFastForwardMergeTree(repoRoot, baseHead, branchHead, g
|
|
|
56576
56775
|
return newTree || void 0;
|
|
56577
56776
|
} finally {
|
|
56578
56777
|
try {
|
|
56579
|
-
|
|
56778
|
+
fs31.rmSync(tmpIndex, { force: true });
|
|
56580
56779
|
} catch {
|
|
56581
56780
|
}
|
|
56582
56781
|
}
|
|
@@ -56586,7 +56785,7 @@ function synthesizeTrivialFastForwardMergeTree(repoRoot, baseHead, branchHead, g
|
|
|
56586
56785
|
}
|
|
56587
56786
|
async function alignRefinerySubmodulesAfterMerge(repoRoot, previousBaseHead, currentHead, options = {}) {
|
|
56588
56787
|
const startedAt = Date.now();
|
|
56589
|
-
const changedGitlinkPaths = readChangedGitlinkPaths(repoRoot, previousBaseHead, currentHead).filter((
|
|
56788
|
+
const changedGitlinkPaths = readChangedGitlinkPaths(repoRoot, previousBaseHead, currentHead).filter((path45) => !(options.submoduleIgnorePaths || []).includes(path45));
|
|
56590
56789
|
const preStatus = await getGitRepoStatus(repoRoot, {
|
|
56591
56790
|
includeSubmodules: true,
|
|
56592
56791
|
submoduleIgnorePaths: options.submoduleIgnorePaths,
|
|
@@ -56633,7 +56832,7 @@ async function alignRefinerySubmodulesAfterMerge(repoRoot, previousBaseHead, cur
|
|
|
56633
56832
|
changedGitlinkPaths,
|
|
56634
56833
|
outOfSyncPaths,
|
|
56635
56834
|
updatedPaths: updatePaths,
|
|
56636
|
-
verifiedPaths: updatePaths.filter((
|
|
56835
|
+
verifiedPaths: updatePaths.filter((path45) => !remaining.some((submodule) => submodule.path === path45)),
|
|
56637
56836
|
durationMs: Date.now() - startedAt,
|
|
56638
56837
|
command: `git ${commandArgs.join(" ")}`,
|
|
56639
56838
|
stdout: truncateValidationOutput(result.stdout),
|
|
@@ -56688,7 +56887,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
56688
56887
|
return { stdout: String(stdout || ""), stderr: String(stderr || ""), refspec };
|
|
56689
56888
|
};
|
|
56690
56889
|
const importCommitFromWorktreeSubmodule = async (submodulePath, worktreeSubmodulePath, commit) => {
|
|
56691
|
-
if (!
|
|
56890
|
+
if (!fs31.existsSync(worktreeSubmodulePath)) return false;
|
|
56692
56891
|
try {
|
|
56693
56892
|
await runGit3(worktreeSubmodulePath, ["cat-file", "-e", `${commit}^{commit}`]);
|
|
56694
56893
|
} catch {
|
|
@@ -56712,7 +56911,7 @@ async function runMeshRefineSubmoduleReachabilityGate(repoRoot, mergedTree, opti
|
|
|
56712
56911
|
};
|
|
56713
56912
|
let submoduleDefaultBranch = "main";
|
|
56714
56913
|
try {
|
|
56715
|
-
if (!
|
|
56914
|
+
if (!fs31.existsSync(submodulePath)) {
|
|
56716
56915
|
entry.error = `Submodule checkout missing at ${gitlink.path}`;
|
|
56717
56916
|
entry.publishRequired = true;
|
|
56718
56917
|
if (options.allowAutoPublishSubmoduleMainCommits === true) {
|
|
@@ -56954,9 +57153,9 @@ async function runMeshRefineValidationGate(mesh, workspace, opts) {
|
|
|
56954
57153
|
return ["npm", "pnpm", "yarn", "bun"].includes(command) && candidate.args.some((arg) => arg === "run" || arg === "test" || arg === "exec");
|
|
56955
57154
|
};
|
|
56956
57155
|
const dependenciesLikelyMissing = (cwd) => {
|
|
56957
|
-
if (!
|
|
56958
|
-
if (
|
|
56959
|
-
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) =>
|
|
57156
|
+
if (!fs31.existsSync(pathJoin2(cwd, "package.json"))) return false;
|
|
57157
|
+
if (fs31.existsSync(pathJoin2(cwd, "node_modules"))) return false;
|
|
57158
|
+
return ["package-lock.json", "npm-shrinkwrap.json", "pnpm-lock.yaml", "yarn.lock", "bun.lockb", "bun.lock"].some((lock) => fs31.existsSync(pathJoin2(cwd, lock)));
|
|
56960
57159
|
};
|
|
56961
57160
|
if (runLegacyBootstrapCommands) {
|
|
56962
57161
|
summary.bootstrap = { stage: "legacy" };
|
|
@@ -58372,7 +58571,7 @@ async function startMeshRefineJob(self, meshId, nodeId, args) {
|
|
|
58372
58571
|
// src/commands/router-worktree-cleanup.ts
|
|
58373
58572
|
init_logger();
|
|
58374
58573
|
init_dist();
|
|
58375
|
-
import * as
|
|
58574
|
+
import * as fs32 from "fs";
|
|
58376
58575
|
import { resolve as pathResolve3 } from "path";
|
|
58377
58576
|
init_repo_mesh_types();
|
|
58378
58577
|
function sessionMatchesMeshNode(self, record, node, nodeId, sessionIds) {
|
|
@@ -58385,14 +58584,14 @@ function sessionMatchesMeshNode(self, record, node, nodeId, sessionIds) {
|
|
|
58385
58584
|
return false;
|
|
58386
58585
|
}
|
|
58387
58586
|
async function bestEffortRemoveWorktreeDir(self, dir) {
|
|
58388
|
-
if (!dir || !
|
|
58587
|
+
if (!dir || !fs32.existsSync(dir)) return { removed: true, residue: false };
|
|
58389
58588
|
const sleep3 = (ms) => new Promise((resolve25) => setTimeout(resolve25, ms));
|
|
58390
58589
|
const ABSORB = /* @__PURE__ */ new Set(["EINVAL", "EPERM", "EBUSY", "ENOTEMPTY", "EACCES", "EMFILE", "ENFILE"]);
|
|
58391
58590
|
let lastErr;
|
|
58392
58591
|
for (let attempt = 0; attempt < 4; attempt++) {
|
|
58393
58592
|
try {
|
|
58394
|
-
|
|
58395
|
-
if (!
|
|
58593
|
+
fs32.rmSync(dir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
58594
|
+
if (!fs32.existsSync(dir)) return { removed: true, residue: false };
|
|
58396
58595
|
lastErr = new Error("directory still present after rmSync");
|
|
58397
58596
|
} catch (e) {
|
|
58398
58597
|
lastErr = e;
|
|
@@ -58403,7 +58602,7 @@ async function bestEffortRemoveWorktreeDir(self, dir) {
|
|
|
58403
58602
|
}
|
|
58404
58603
|
await sleep3(150 * (attempt + 1));
|
|
58405
58604
|
}
|
|
58406
|
-
return
|
|
58605
|
+
return fs32.existsSync(dir) ? { removed: false, residue: true, error: String(lastErr?.message || lastErr || "unknown rm error") } : { removed: true, residue: false };
|
|
58407
58606
|
}
|
|
58408
58607
|
async function precheckLocalWorktreeRemovable(self, args) {
|
|
58409
58608
|
const sessionPreservedNote = " The delegated session was left running (not stopped) \u2014 resolve the issue and retry mesh_remove_node.";
|
|
@@ -58416,10 +58615,10 @@ async function precheckLocalWorktreeRemovable(self, args) {
|
|
|
58416
58615
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains." + sessionPreservedNote
|
|
58417
58616
|
};
|
|
58418
58617
|
}
|
|
58419
|
-
if (!
|
|
58618
|
+
if (!fs32.existsSync(workspace)) return { ok: true };
|
|
58420
58619
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
58421
58620
|
const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
|
|
58422
|
-
if (!repoRoot || !
|
|
58621
|
+
if (!repoRoot || !fs32.existsSync(repoRoot)) {
|
|
58423
58622
|
return {
|
|
58424
58623
|
ok: false,
|
|
58425
58624
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -58439,7 +58638,7 @@ async function precheckLocalWorktreeRemovable(self, args) {
|
|
|
58439
58638
|
const normalizePath = (value) => {
|
|
58440
58639
|
const resolved = pathResolve3(value);
|
|
58441
58640
|
try {
|
|
58442
|
-
return
|
|
58641
|
+
return fs32.realpathSync(resolved);
|
|
58443
58642
|
} catch {
|
|
58444
58643
|
return resolved;
|
|
58445
58644
|
}
|
|
@@ -58501,13 +58700,13 @@ async function cleanupLocalWorktreeNode(self, args) {
|
|
|
58501
58700
|
recoveryHint: "Inspect the mesh node record before removing it, or remove stale metadata manually only after confirming no managed worktree remains."
|
|
58502
58701
|
};
|
|
58503
58702
|
}
|
|
58504
|
-
const worktreeExists =
|
|
58703
|
+
const worktreeExists = fs32.existsSync(workspace);
|
|
58505
58704
|
const sourceNode = args.node?.clonedFromNodeId ? args.mesh?.nodes?.find((n) => meshNodeIdMatches(n, args.node.clonedFromNodeId)) : args.mesh?.nodes?.find((n) => !n.isLocalWorktree);
|
|
58506
58705
|
const repoRoot = typeof sourceNode?.repoRoot === "string" && sourceNode.repoRoot.trim() ? sourceNode.repoRoot.trim() : typeof sourceNode?.workspace === "string" && sourceNode.workspace.trim() ? sourceNode.workspace.trim() : "";
|
|
58507
58706
|
if (!worktreeExists) {
|
|
58508
58707
|
return { success: true, skipped: true, removedPath: workspace, repoRoot: repoRoot || void 0, reason: "worktree_path_missing" };
|
|
58509
58708
|
}
|
|
58510
|
-
if (!repoRoot || !
|
|
58709
|
+
if (!repoRoot || !fs32.existsSync(repoRoot)) {
|
|
58511
58710
|
return {
|
|
58512
58711
|
success: false,
|
|
58513
58712
|
code: "mesh_worktree_cleanup_missing_source_repo",
|
|
@@ -58527,7 +58726,7 @@ async function cleanupLocalWorktreeNode(self, args) {
|
|
|
58527
58726
|
const normalizePath = (value) => {
|
|
58528
58727
|
const resolved = pathResolve3(value);
|
|
58529
58728
|
try {
|
|
58530
|
-
return
|
|
58729
|
+
return fs32.realpathSync(resolved);
|
|
58531
58730
|
} catch {
|
|
58532
58731
|
return resolved;
|
|
58533
58732
|
}
|
|
@@ -59161,7 +59360,7 @@ init_logger();
|
|
|
59161
59360
|
import * as yaml5 from "js-yaml";
|
|
59162
59361
|
import { homedir as homedir26 } from "os";
|
|
59163
59362
|
import { join as pathJoin3, resolve as pathResolve4 } from "path";
|
|
59164
|
-
import * as
|
|
59363
|
+
import * as fs33 from "fs";
|
|
59165
59364
|
function loadYamlModule() {
|
|
59166
59365
|
return yaml5;
|
|
59167
59366
|
}
|
|
@@ -59185,9 +59384,9 @@ function resolveHermesUserHome() {
|
|
|
59185
59384
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
59186
59385
|
const sourceHome = resolveHermesUserHome();
|
|
59187
59386
|
const sourceConfigPath = pathJoin3(sourceHome, "config.yaml");
|
|
59188
|
-
if (!
|
|
59387
|
+
if (!fs33.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
59189
59388
|
if (pathResolve4(sourceConfigPath) === pathResolve4(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
59190
|
-
const parsed = parseMeshCoordinatorMcpConfig(
|
|
59389
|
+
const parsed = parseMeshCoordinatorMcpConfig(fs33.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
59191
59390
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
59192
59391
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
59193
59392
|
}
|
|
@@ -59224,9 +59423,9 @@ function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
|
59224
59423
|
for (const fileName of [".env", "auth.json"]) {
|
|
59225
59424
|
const sourcePath = pathJoin3(sourceHome, fileName);
|
|
59226
59425
|
const targetPath = pathJoin3(targetHome, fileName);
|
|
59227
|
-
if (!
|
|
59426
|
+
if (!fs33.existsSync(sourcePath)) continue;
|
|
59228
59427
|
try {
|
|
59229
|
-
|
|
59428
|
+
fs33.copyFileSync(sourcePath, targetPath);
|
|
59230
59429
|
} catch (error) {
|
|
59231
59430
|
LOG.warn("MeshCoordinator", `Could not copy Hermes ${fileName} into isolated coordinator home: ${error?.message || error}`);
|
|
59232
59431
|
}
|
|
@@ -59618,7 +59817,7 @@ var DaemonCommandRouter = class {
|
|
|
59618
59817
|
const nodeId = readInlineMeshNodeId(node);
|
|
59619
59818
|
if (!nodeId || !tombstones.has(nodeId)) return true;
|
|
59620
59819
|
const workspace = readStringValue(node?.workspace);
|
|
59621
|
-
if (workspace &&
|
|
59820
|
+
if (workspace && fs34.existsSync(workspace)) {
|
|
59622
59821
|
tombstones.delete(nodeId);
|
|
59623
59822
|
return true;
|
|
59624
59823
|
}
|
|
@@ -61537,12 +61736,12 @@ init_io_contracts();
|
|
|
61537
61736
|
init_chat_message_normalization();
|
|
61538
61737
|
|
|
61539
61738
|
// src/providers/version-archive.ts
|
|
61540
|
-
import * as
|
|
61541
|
-
import * as
|
|
61542
|
-
import * as
|
|
61739
|
+
import * as fs35 from "fs";
|
|
61740
|
+
import * as path39 from "path";
|
|
61741
|
+
import * as os29 from "os";
|
|
61543
61742
|
import { platform as platform8 } from "os";
|
|
61544
61743
|
import { exec as exec5 } from "child_process";
|
|
61545
|
-
var ARCHIVE_PATH =
|
|
61744
|
+
var ARCHIVE_PATH = path39.join(os29.homedir(), ".adhdev", "version-history.json");
|
|
61546
61745
|
var MAX_ENTRIES_PER_PROVIDER = 20;
|
|
61547
61746
|
var VersionArchive = class {
|
|
61548
61747
|
history = {};
|
|
@@ -61551,8 +61750,8 @@ var VersionArchive = class {
|
|
|
61551
61750
|
}
|
|
61552
61751
|
load() {
|
|
61553
61752
|
try {
|
|
61554
|
-
if (
|
|
61555
|
-
this.history = JSON.parse(
|
|
61753
|
+
if (fs35.existsSync(ARCHIVE_PATH)) {
|
|
61754
|
+
this.history = JSON.parse(fs35.readFileSync(ARCHIVE_PATH, "utf-8"));
|
|
61556
61755
|
}
|
|
61557
61756
|
} catch {
|
|
61558
61757
|
this.history = {};
|
|
@@ -61589,8 +61788,8 @@ var VersionArchive = class {
|
|
|
61589
61788
|
}
|
|
61590
61789
|
save() {
|
|
61591
61790
|
try {
|
|
61592
|
-
|
|
61593
|
-
|
|
61791
|
+
fs35.mkdirSync(path39.dirname(ARCHIVE_PATH), { recursive: true });
|
|
61792
|
+
fs35.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
|
|
61594
61793
|
} catch {
|
|
61595
61794
|
}
|
|
61596
61795
|
}
|
|
@@ -61613,10 +61812,10 @@ function findBinary2(name) {
|
|
|
61613
61812
|
for (const p of paths) {
|
|
61614
61813
|
if (!p) continue;
|
|
61615
61814
|
for (const ext of exes) {
|
|
61616
|
-
const fullPath =
|
|
61815
|
+
const fullPath = path39.join(p, name + ext);
|
|
61617
61816
|
try {
|
|
61618
|
-
if (
|
|
61619
|
-
const stat2 =
|
|
61817
|
+
if (fs35.existsSync(fullPath)) {
|
|
61818
|
+
const stat2 = fs35.statSync(fullPath);
|
|
61620
61819
|
if (stat2.isFile() && (isWin || stat2.mode & 73)) {
|
|
61621
61820
|
return fullPath;
|
|
61622
61821
|
}
|
|
@@ -61661,19 +61860,19 @@ async function getVersion(binary, versionCommand) {
|
|
|
61661
61860
|
function checkPathExists2(paths) {
|
|
61662
61861
|
for (const p of paths) {
|
|
61663
61862
|
if (p.includes("*")) {
|
|
61664
|
-
const home =
|
|
61665
|
-
const resolved = p.replace(/\*/g, home.split(
|
|
61666
|
-
if (
|
|
61863
|
+
const home = os29.homedir();
|
|
61864
|
+
const resolved = p.replace(/\*/g, home.split(path39.sep).pop() || "");
|
|
61865
|
+
if (fs35.existsSync(resolved)) return resolved;
|
|
61667
61866
|
} else {
|
|
61668
|
-
if (
|
|
61867
|
+
if (fs35.existsSync(p)) return p;
|
|
61669
61868
|
}
|
|
61670
61869
|
}
|
|
61671
61870
|
return null;
|
|
61672
61871
|
}
|
|
61673
61872
|
async function getMacAppVersion(appPath) {
|
|
61674
61873
|
if (platform8() !== "darwin" || !appPath.endsWith(".app")) return null;
|
|
61675
|
-
const plistPath =
|
|
61676
|
-
if (!
|
|
61874
|
+
const plistPath = path39.join(appPath, "Contents", "Info.plist");
|
|
61875
|
+
if (!fs35.existsSync(plistPath)) return null;
|
|
61677
61876
|
const raw = await runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
|
|
61678
61877
|
return raw || null;
|
|
61679
61878
|
}
|
|
@@ -61699,8 +61898,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
61699
61898
|
const cliBin = provider.cli ? findBinary2(provider.cli) : null;
|
|
61700
61899
|
let resolvedBin = cliBin;
|
|
61701
61900
|
if (!resolvedBin && appPath && currentOs === "darwin") {
|
|
61702
|
-
const bundled =
|
|
61703
|
-
if (provider.cli &&
|
|
61901
|
+
const bundled = path39.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
|
|
61902
|
+
if (provider.cli && fs35.existsSync(bundled)) resolvedBin = bundled;
|
|
61704
61903
|
}
|
|
61705
61904
|
info.installed = !!(appPath || resolvedBin);
|
|
61706
61905
|
info.path = appPath || null;
|
|
@@ -61748,8 +61947,8 @@ async function detectAllVersions(loader, archive) {
|
|
|
61748
61947
|
|
|
61749
61948
|
// src/daemon/dev-server.ts
|
|
61750
61949
|
import * as http2 from "http";
|
|
61751
|
-
import * as
|
|
61752
|
-
import * as
|
|
61950
|
+
import * as fs39 from "fs";
|
|
61951
|
+
import * as path43 from "path";
|
|
61753
61952
|
init_config();
|
|
61754
61953
|
|
|
61755
61954
|
// src/daemon/scaffold-template.ts
|
|
@@ -62101,8 +62300,8 @@ init_builders();
|
|
|
62101
62300
|
|
|
62102
62301
|
// src/daemon/dev-cdp-handlers.ts
|
|
62103
62302
|
init_logger();
|
|
62104
|
-
import * as
|
|
62105
|
-
import * as
|
|
62303
|
+
import * as fs36 from "fs";
|
|
62304
|
+
import * as path40 from "path";
|
|
62106
62305
|
async function handleCdpEvaluate(ctx, req, res) {
|
|
62107
62306
|
const body = await ctx.readBody(req);
|
|
62108
62307
|
const { expression, timeout, ideType } = body;
|
|
@@ -62280,18 +62479,18 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
62280
62479
|
return;
|
|
62281
62480
|
}
|
|
62282
62481
|
let scriptsPath = "";
|
|
62283
|
-
const directScripts =
|
|
62284
|
-
if (
|
|
62482
|
+
const directScripts = path40.join(dir, "scripts.js");
|
|
62483
|
+
if (fs36.existsSync(directScripts)) {
|
|
62285
62484
|
scriptsPath = directScripts;
|
|
62286
62485
|
} else {
|
|
62287
|
-
const scriptsDir =
|
|
62288
|
-
if (
|
|
62289
|
-
const versions =
|
|
62290
|
-
return
|
|
62486
|
+
const scriptsDir = path40.join(dir, "scripts");
|
|
62487
|
+
if (fs36.existsSync(scriptsDir)) {
|
|
62488
|
+
const versions = fs36.readdirSync(scriptsDir).filter((d) => {
|
|
62489
|
+
return fs36.statSync(path40.join(scriptsDir, d)).isDirectory();
|
|
62291
62490
|
}).sort().reverse();
|
|
62292
62491
|
for (const ver of versions) {
|
|
62293
|
-
const p =
|
|
62294
|
-
if (
|
|
62492
|
+
const p = path40.join(scriptsDir, ver, "scripts.js");
|
|
62493
|
+
if (fs36.existsSync(p)) {
|
|
62295
62494
|
scriptsPath = p;
|
|
62296
62495
|
break;
|
|
62297
62496
|
}
|
|
@@ -62303,7 +62502,7 @@ async function handleScriptHints(ctx, type, _req, res) {
|
|
|
62303
62502
|
return;
|
|
62304
62503
|
}
|
|
62305
62504
|
try {
|
|
62306
|
-
const source =
|
|
62505
|
+
const source = fs36.readFileSync(scriptsPath, "utf-8");
|
|
62307
62506
|
const hints = {};
|
|
62308
62507
|
const funcRegex = /module\.exports\.(\w+)\s*=\s*function\s+\w+\s*\(params\)/g;
|
|
62309
62508
|
let match;
|
|
@@ -63118,8 +63317,8 @@ async function handleDomContext(ctx, type, req, res) {
|
|
|
63118
63317
|
}
|
|
63119
63318
|
|
|
63120
63319
|
// src/daemon/dev-cli-debug.ts
|
|
63121
|
-
import * as
|
|
63122
|
-
import * as
|
|
63320
|
+
import * as fs37 from "fs";
|
|
63321
|
+
import * as path41 from "path";
|
|
63123
63322
|
function slugifyFixtureName(value) {
|
|
63124
63323
|
const normalized = String(value || "").trim().toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
63125
63324
|
return normalized || `fixture-${Date.now()}`;
|
|
@@ -63129,15 +63328,15 @@ function getCliFixtureDir(ctx, type) {
|
|
|
63129
63328
|
if (!providerDir) {
|
|
63130
63329
|
throw new Error(`Provider directory not found for '${type}'`);
|
|
63131
63330
|
}
|
|
63132
|
-
return
|
|
63331
|
+
return path41.join(providerDir, "fixtures");
|
|
63133
63332
|
}
|
|
63134
63333
|
function readCliFixture(ctx, type, name) {
|
|
63135
63334
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
63136
|
-
const filePath =
|
|
63137
|
-
if (!
|
|
63335
|
+
const filePath = path41.join(fixtureDir, `${name}.json`);
|
|
63336
|
+
if (!fs37.existsSync(filePath)) {
|
|
63138
63337
|
throw new Error(`Fixture not found: ${filePath}`);
|
|
63139
63338
|
}
|
|
63140
|
-
return JSON.parse(
|
|
63339
|
+
return JSON.parse(fs37.readFileSync(filePath, "utf-8"));
|
|
63141
63340
|
}
|
|
63142
63341
|
function getExerciseTranscriptText(result) {
|
|
63143
63342
|
const parts = [];
|
|
@@ -63882,7 +64081,7 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
63882
64081
|
return;
|
|
63883
64082
|
}
|
|
63884
64083
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
63885
|
-
|
|
64084
|
+
fs37.mkdirSync(fixtureDir, { recursive: true });
|
|
63886
64085
|
const name = slugifyFixtureName(String(body?.name || `${type}-${Date.now()}`));
|
|
63887
64086
|
const result = await runCliExerciseInternal(ctx, { ...request, type });
|
|
63888
64087
|
const fixture = {
|
|
@@ -63909,8 +64108,8 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
63909
64108
|
},
|
|
63910
64109
|
notes: typeof body?.notes === "string" ? body.notes : void 0
|
|
63911
64110
|
};
|
|
63912
|
-
const filePath =
|
|
63913
|
-
|
|
64111
|
+
const filePath = path41.join(fixtureDir, `${name}.json`);
|
|
64112
|
+
fs37.writeFileSync(filePath, JSON.stringify(fixture, null, 2));
|
|
63914
64113
|
ctx.json(res, 200, {
|
|
63915
64114
|
saved: true,
|
|
63916
64115
|
name,
|
|
@@ -63928,14 +64127,14 @@ async function handleCliFixtureCapture(ctx, req, res) {
|
|
|
63928
64127
|
async function handleCliFixtureList(ctx, type, _req, res) {
|
|
63929
64128
|
try {
|
|
63930
64129
|
const fixtureDir = getCliFixtureDir(ctx, type);
|
|
63931
|
-
if (!
|
|
64130
|
+
if (!fs37.existsSync(fixtureDir)) {
|
|
63932
64131
|
ctx.json(res, 200, { fixtures: [], count: 0 });
|
|
63933
64132
|
return;
|
|
63934
64133
|
}
|
|
63935
|
-
const fixtures =
|
|
63936
|
-
const fullPath =
|
|
64134
|
+
const fixtures = fs37.readdirSync(fixtureDir).filter((file) => file.endsWith(".json")).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" })).map((file) => {
|
|
64135
|
+
const fullPath = path41.join(fixtureDir, file);
|
|
63937
64136
|
try {
|
|
63938
|
-
const raw = JSON.parse(
|
|
64137
|
+
const raw = JSON.parse(fs37.readFileSync(fullPath, "utf-8"));
|
|
63939
64138
|
return {
|
|
63940
64139
|
name: raw.name || file.replace(/\.json$/i, ""),
|
|
63941
64140
|
path: fullPath,
|
|
@@ -64068,9 +64267,9 @@ async function handleCliRaw(ctx, req, res) {
|
|
|
64068
64267
|
}
|
|
64069
64268
|
|
|
64070
64269
|
// src/daemon/dev-auto-implement.ts
|
|
64071
|
-
import * as
|
|
64072
|
-
import * as
|
|
64073
|
-
import * as
|
|
64270
|
+
import * as fs38 from "fs";
|
|
64271
|
+
import * as path42 from "path";
|
|
64272
|
+
import * as os30 from "os";
|
|
64074
64273
|
import { DEFAULT_SESSION_HOST_COLS as DEFAULT_SESSION_HOST_COLS7, DEFAULT_SESSION_HOST_ROWS as DEFAULT_SESSION_HOST_ROWS7 } from "@adhdev/session-host-core";
|
|
64075
64274
|
function getAutoImplPid(ctx) {
|
|
64076
64275
|
const pid = ctx.autoImplProcess?.pid;
|
|
@@ -64117,38 +64316,38 @@ function resolveAutoImplReference(ctx, category, requestedReference, targetType)
|
|
|
64117
64316
|
return fallback?.type || null;
|
|
64118
64317
|
}
|
|
64119
64318
|
function getLatestScriptVersionDir(scriptsDir) {
|
|
64120
|
-
if (!
|
|
64121
|
-
const versions =
|
|
64319
|
+
if (!fs38.existsSync(scriptsDir)) return null;
|
|
64320
|
+
const versions = fs38.readdirSync(scriptsDir).filter((d) => {
|
|
64122
64321
|
try {
|
|
64123
|
-
return
|
|
64322
|
+
return fs38.statSync(path42.join(scriptsDir, d)).isDirectory();
|
|
64124
64323
|
} catch {
|
|
64125
64324
|
return false;
|
|
64126
64325
|
}
|
|
64127
64326
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
64128
64327
|
if (versions.length === 0) return null;
|
|
64129
|
-
return
|
|
64328
|
+
return path42.join(scriptsDir, versions[0]);
|
|
64130
64329
|
}
|
|
64131
64330
|
function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
64132
|
-
const canonicalUserDir =
|
|
64133
|
-
const desiredDir = requestedDir ?
|
|
64134
|
-
const upstreamRoot =
|
|
64135
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
64331
|
+
const canonicalUserDir = path42.resolve(ctx.providerLoader.getUserProviderDir(category, type));
|
|
64332
|
+
const desiredDir = requestedDir ? path42.resolve(requestedDir) : canonicalUserDir;
|
|
64333
|
+
const upstreamRoot = path42.resolve(ctx.providerLoader.getUpstreamDir());
|
|
64334
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path42.sep}`)) {
|
|
64136
64335
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
64137
64336
|
}
|
|
64138
|
-
if (
|
|
64337
|
+
if (path42.basename(desiredDir) !== type) {
|
|
64139
64338
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
64140
64339
|
}
|
|
64141
64340
|
const sourceDir = ctx.findProviderDir(type);
|
|
64142
64341
|
if (!sourceDir) {
|
|
64143
64342
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
64144
64343
|
}
|
|
64145
|
-
if (!
|
|
64146
|
-
|
|
64147
|
-
|
|
64344
|
+
if (!fs38.existsSync(desiredDir)) {
|
|
64345
|
+
fs38.mkdirSync(path42.dirname(desiredDir), { recursive: true });
|
|
64346
|
+
fs38.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
64148
64347
|
ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
64149
64348
|
}
|
|
64150
|
-
const providerJson =
|
|
64151
|
-
if (!
|
|
64349
|
+
const providerJson = path42.join(desiredDir, "provider.json");
|
|
64350
|
+
if (!fs38.existsSync(providerJson)) {
|
|
64152
64351
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
64153
64352
|
}
|
|
64154
64353
|
return { dir: desiredDir };
|
|
@@ -64156,15 +64355,15 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
|
|
|
64156
64355
|
function loadAutoImplReferenceScripts(ctx, referenceType) {
|
|
64157
64356
|
if (!referenceType) return {};
|
|
64158
64357
|
const refDir = ctx.findProviderDir(referenceType);
|
|
64159
|
-
if (!refDir || !
|
|
64358
|
+
if (!refDir || !fs38.existsSync(refDir)) return {};
|
|
64160
64359
|
const referenceScripts = {};
|
|
64161
|
-
const scriptsDir =
|
|
64360
|
+
const scriptsDir = path42.join(refDir, "scripts");
|
|
64162
64361
|
const latestDir = getLatestScriptVersionDir(scriptsDir);
|
|
64163
64362
|
if (!latestDir) return referenceScripts;
|
|
64164
|
-
for (const file of
|
|
64363
|
+
for (const file of fs38.readdirSync(latestDir)) {
|
|
64165
64364
|
if (!file.endsWith(".js")) continue;
|
|
64166
64365
|
try {
|
|
64167
|
-
referenceScripts[file] =
|
|
64366
|
+
referenceScripts[file] = fs38.readFileSync(path42.join(latestDir, file), "utf-8");
|
|
64168
64367
|
} catch {
|
|
64169
64368
|
}
|
|
64170
64369
|
}
|
|
@@ -64272,16 +64471,16 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
64272
64471
|
});
|
|
64273
64472
|
const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
|
|
64274
64473
|
const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference, verification);
|
|
64275
|
-
const tmpDir =
|
|
64276
|
-
if (!
|
|
64277
|
-
const promptFile =
|
|
64278
|
-
|
|
64474
|
+
const tmpDir = path42.join(os30.tmpdir(), "adhdev-autoimpl");
|
|
64475
|
+
if (!fs38.existsSync(tmpDir)) fs38.mkdirSync(tmpDir, { recursive: true });
|
|
64476
|
+
const promptFile = path42.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
|
|
64477
|
+
fs38.writeFileSync(promptFile, prompt, "utf-8");
|
|
64279
64478
|
ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
|
|
64280
64479
|
const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
|
|
64281
64480
|
const spawn5 = agentProvider?.spawn;
|
|
64282
64481
|
if (!spawn5?.command) {
|
|
64283
64482
|
try {
|
|
64284
|
-
|
|
64483
|
+
fs38.unlinkSync(promptFile);
|
|
64285
64484
|
} catch {
|
|
64286
64485
|
}
|
|
64287
64486
|
ctx.json(res, 400, { error: `Agent '${agent}' has no spawn config. Select a CLI provider with a spawn configuration.` });
|
|
@@ -64383,7 +64582,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
64383
64582
|
} catch {
|
|
64384
64583
|
}
|
|
64385
64584
|
try {
|
|
64386
|
-
|
|
64585
|
+
fs38.unlinkSync(promptFile);
|
|
64387
64586
|
} catch {
|
|
64388
64587
|
}
|
|
64389
64588
|
ctx.log(`Auto-implement (ACP) ${success ? "completed" : "failed"}: ${type} (exit: ${code})`);
|
|
@@ -64427,7 +64626,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
64427
64626
|
const interactiveFlags = ["--yolo", "--interactive", "-i"];
|
|
64428
64627
|
const baseArgs = [...spawn5.args || []].filter((a) => !interactiveFlags.includes(a));
|
|
64429
64628
|
let shellCmd;
|
|
64430
|
-
const isWin =
|
|
64629
|
+
const isWin = os30.platform() === "win32";
|
|
64431
64630
|
const escapeArg = (a) => isWin ? `"${a.replace(/"/g, '""')}"` : `'${a.replace(/'/g, "'\\''")}'`;
|
|
64432
64631
|
const promptMode = autoImpl?.promptMode ?? "stdin";
|
|
64433
64632
|
const extraArgs = autoImpl?.extraArgs ?? [];
|
|
@@ -64466,7 +64665,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
64466
64665
|
try {
|
|
64467
64666
|
const pty = __require("node-pty");
|
|
64468
64667
|
ctx.log(`Auto-implement spawn (PTY): ${shellCmd}`);
|
|
64469
|
-
const isWin2 =
|
|
64668
|
+
const isWin2 = os30.platform() === "win32";
|
|
64470
64669
|
child = pty.spawn(isWin2 ? "cmd.exe" : process.env.SHELL || "/bin/zsh", [isWin2 ? "/c" : "-c", shellCmd], {
|
|
64471
64670
|
name: "xterm-256color",
|
|
64472
64671
|
cols: DEFAULT_SESSION_HOST_COLS7,
|
|
@@ -64609,7 +64808,7 @@ async function handleAutoImplement(ctx, type, req, res) {
|
|
|
64609
64808
|
}
|
|
64610
64809
|
});
|
|
64611
64810
|
try {
|
|
64612
|
-
|
|
64811
|
+
fs38.unlinkSync(promptFile);
|
|
64613
64812
|
} catch {
|
|
64614
64813
|
}
|
|
64615
64814
|
ctx.log(`Auto-implement ${success ? "completed" : "failed"}: ${type} (exit: ${code})${verificationSummary ? ` verify=${verificationSummary.pass ? "pass" : "fail"}` : ""}`);
|
|
@@ -64706,7 +64905,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
64706
64905
|
setMode: "set_mode.js"
|
|
64707
64906
|
};
|
|
64708
64907
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
64709
|
-
const scriptsDir =
|
|
64908
|
+
const scriptsDir = path42.join(providerDir, "scripts");
|
|
64710
64909
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
64711
64910
|
if (latestScriptsDir) {
|
|
64712
64911
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -64714,10 +64913,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
64714
64913
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
64715
64914
|
lines.push("These are the ONLY files you are allowed to modify. Replace the TODO stubs with working implementations.");
|
|
64716
64915
|
lines.push("");
|
|
64717
|
-
for (const file of
|
|
64916
|
+
for (const file of fs38.readdirSync(latestScriptsDir)) {
|
|
64718
64917
|
if (file.endsWith(".js") && targetFileNames.has(file)) {
|
|
64719
64918
|
try {
|
|
64720
|
-
const content =
|
|
64919
|
+
const content = fs38.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
64721
64920
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
64722
64921
|
lines.push("```javascript");
|
|
64723
64922
|
lines.push(content);
|
|
@@ -64727,14 +64926,14 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
64727
64926
|
}
|
|
64728
64927
|
}
|
|
64729
64928
|
}
|
|
64730
|
-
const refFiles =
|
|
64929
|
+
const refFiles = fs38.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
64731
64930
|
if (refFiles.length > 0) {
|
|
64732
64931
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
64733
64932
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
64734
64933
|
lines.push("");
|
|
64735
64934
|
for (const file of refFiles) {
|
|
64736
64935
|
try {
|
|
64737
|
-
const content =
|
|
64936
|
+
const content = fs38.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
64738
64937
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
64739
64938
|
lines.push("```javascript");
|
|
64740
64939
|
lines.push(content);
|
|
@@ -64775,11 +64974,11 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
|
|
|
64775
64974
|
lines.push("");
|
|
64776
64975
|
}
|
|
64777
64976
|
}
|
|
64778
|
-
const docsDir =
|
|
64977
|
+
const docsDir = path42.join(providerDir, "../../docs");
|
|
64779
64978
|
const loadGuide = (name) => {
|
|
64780
64979
|
try {
|
|
64781
|
-
const p =
|
|
64782
|
-
if (
|
|
64980
|
+
const p = path42.join(docsDir, name);
|
|
64981
|
+
if (fs38.existsSync(p)) return fs38.readFileSync(p, "utf-8");
|
|
64783
64982
|
} catch {
|
|
64784
64983
|
}
|
|
64785
64984
|
return null;
|
|
@@ -65015,7 +65214,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
65015
65214
|
parseApproval: "parse_approval.js"
|
|
65016
65215
|
};
|
|
65017
65216
|
const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
|
|
65018
|
-
const scriptsDir =
|
|
65217
|
+
const scriptsDir = path42.join(providerDir, "scripts");
|
|
65019
65218
|
const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
|
|
65020
65219
|
if (latestScriptsDir) {
|
|
65021
65220
|
lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
|
|
@@ -65023,11 +65222,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
65023
65222
|
lines.push("## \u270F\uFE0F Target Files (EDIT THESE)");
|
|
65024
65223
|
lines.push("These are the ONLY files you are allowed to modify. Replace TODO or heuristic-only logic with working PTY-aware implementations.");
|
|
65025
65224
|
lines.push("");
|
|
65026
|
-
for (const file of
|
|
65225
|
+
for (const file of fs38.readdirSync(latestScriptsDir)) {
|
|
65027
65226
|
if (!file.endsWith(".js")) continue;
|
|
65028
65227
|
if (!targetFileNames.has(file)) continue;
|
|
65029
65228
|
try {
|
|
65030
|
-
const content =
|
|
65229
|
+
const content = fs38.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
65031
65230
|
lines.push(`### \`${file}\` \u270F\uFE0F EDIT`);
|
|
65032
65231
|
lines.push("```javascript");
|
|
65033
65232
|
lines.push(content);
|
|
@@ -65036,14 +65235,14 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
65036
65235
|
} catch {
|
|
65037
65236
|
}
|
|
65038
65237
|
}
|
|
65039
|
-
const refFiles =
|
|
65238
|
+
const refFiles = fs38.readdirSync(latestScriptsDir).filter((f) => f.endsWith(".js") && !targetFileNames.has(f));
|
|
65040
65239
|
if (refFiles.length > 0) {
|
|
65041
65240
|
lines.push("## \u{1F512} Other Scripts (REFERENCE ONLY \u2014 DO NOT EDIT)");
|
|
65042
65241
|
lines.push("These files are shown for context only. Do NOT modify them under any circumstances.");
|
|
65043
65242
|
lines.push("");
|
|
65044
65243
|
for (const file of refFiles) {
|
|
65045
65244
|
try {
|
|
65046
|
-
const content =
|
|
65245
|
+
const content = fs38.readFileSync(path42.join(latestScriptsDir, file), "utf-8");
|
|
65047
65246
|
lines.push(`### \`${file}\` \u{1F512}`);
|
|
65048
65247
|
lines.push("```javascript");
|
|
65049
65248
|
lines.push(content);
|
|
@@ -65076,11 +65275,11 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
|
|
|
65076
65275
|
lines.push("");
|
|
65077
65276
|
}
|
|
65078
65277
|
}
|
|
65079
|
-
const docsDir =
|
|
65278
|
+
const docsDir = path42.join(providerDir, "../../docs");
|
|
65080
65279
|
const loadGuide = (name) => {
|
|
65081
65280
|
try {
|
|
65082
|
-
const p =
|
|
65083
|
-
if (
|
|
65281
|
+
const p = path42.join(docsDir, name);
|
|
65282
|
+
if (fs38.existsSync(p)) return fs38.readFileSync(p, "utf-8");
|
|
65084
65283
|
} catch {
|
|
65085
65284
|
}
|
|
65086
65285
|
return null;
|
|
@@ -65526,8 +65725,8 @@ var DevServer = class _DevServer {
|
|
|
65526
65725
|
}
|
|
65527
65726
|
getEndpointList() {
|
|
65528
65727
|
return this.routes.map((r) => {
|
|
65529
|
-
const
|
|
65530
|
-
return `${r.method.padEnd(5)} ${
|
|
65728
|
+
const path45 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
|
|
65729
|
+
return `${r.method.padEnd(5)} ${path45}`;
|
|
65531
65730
|
});
|
|
65532
65731
|
}
|
|
65533
65732
|
async start(port = DEV_SERVER_PORT) {
|
|
@@ -65815,12 +66014,12 @@ var DevServer = class _DevServer {
|
|
|
65815
66014
|
// ─── DevConsole SPA ───
|
|
65816
66015
|
getConsoleDistDir() {
|
|
65817
66016
|
const candidates = [
|
|
65818
|
-
|
|
65819
|
-
|
|
65820
|
-
|
|
66017
|
+
path43.resolve(__dirname, "../../web-devconsole/dist"),
|
|
66018
|
+
path43.resolve(__dirname, "../../../web-devconsole/dist"),
|
|
66019
|
+
path43.join(process.cwd(), "packages/web-devconsole/dist")
|
|
65821
66020
|
];
|
|
65822
66021
|
for (const dir of candidates) {
|
|
65823
|
-
if (
|
|
66022
|
+
if (fs39.existsSync(path43.join(dir, "index.html"))) return dir;
|
|
65824
66023
|
}
|
|
65825
66024
|
return null;
|
|
65826
66025
|
}
|
|
@@ -65830,9 +66029,9 @@ var DevServer = class _DevServer {
|
|
|
65830
66029
|
this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
|
|
65831
66030
|
return;
|
|
65832
66031
|
}
|
|
65833
|
-
const htmlPath =
|
|
66032
|
+
const htmlPath = path43.join(distDir, "index.html");
|
|
65834
66033
|
try {
|
|
65835
|
-
const html =
|
|
66034
|
+
const html = fs39.readFileSync(htmlPath, "utf-8");
|
|
65836
66035
|
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
65837
66036
|
res.end(html);
|
|
65838
66037
|
} catch (e) {
|
|
@@ -65855,15 +66054,15 @@ var DevServer = class _DevServer {
|
|
|
65855
66054
|
this.json(res, 404, { error: "Not found" });
|
|
65856
66055
|
return;
|
|
65857
66056
|
}
|
|
65858
|
-
const safePath =
|
|
65859
|
-
const filePath =
|
|
66057
|
+
const safePath = path43.normalize(pathname).replace(/^\.\.\//, "");
|
|
66058
|
+
const filePath = path43.join(distDir, safePath);
|
|
65860
66059
|
if (!filePath.startsWith(distDir)) {
|
|
65861
66060
|
this.json(res, 403, { error: "Forbidden" });
|
|
65862
66061
|
return;
|
|
65863
66062
|
}
|
|
65864
66063
|
try {
|
|
65865
|
-
const content =
|
|
65866
|
-
const ext =
|
|
66064
|
+
const content = fs39.readFileSync(filePath);
|
|
66065
|
+
const ext = path43.extname(filePath);
|
|
65867
66066
|
const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
|
|
65868
66067
|
res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
|
|
65869
66068
|
res.end(content);
|
|
@@ -65971,14 +66170,14 @@ var DevServer = class _DevServer {
|
|
|
65971
66170
|
const files = [];
|
|
65972
66171
|
const scan = (d, prefix) => {
|
|
65973
66172
|
try {
|
|
65974
|
-
for (const entry of
|
|
66173
|
+
for (const entry of fs39.readdirSync(d, { withFileTypes: true })) {
|
|
65975
66174
|
if (entry.name.startsWith(".") || entry.name.endsWith(".bak")) continue;
|
|
65976
66175
|
const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
65977
66176
|
if (entry.isDirectory()) {
|
|
65978
66177
|
files.push({ path: rel, size: 0, type: "dir" });
|
|
65979
|
-
scan(
|
|
66178
|
+
scan(path43.join(d, entry.name), rel);
|
|
65980
66179
|
} else {
|
|
65981
|
-
const stat2 =
|
|
66180
|
+
const stat2 = fs39.statSync(path43.join(d, entry.name));
|
|
65982
66181
|
files.push({ path: rel, size: stat2.size, type: "file" });
|
|
65983
66182
|
}
|
|
65984
66183
|
}
|
|
@@ -66001,16 +66200,16 @@ var DevServer = class _DevServer {
|
|
|
66001
66200
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
66002
66201
|
return;
|
|
66003
66202
|
}
|
|
66004
|
-
const fullPath =
|
|
66203
|
+
const fullPath = path43.resolve(dir, path43.normalize(filePath));
|
|
66005
66204
|
if (!fullPath.startsWith(dir)) {
|
|
66006
66205
|
this.json(res, 403, { error: "Forbidden" });
|
|
66007
66206
|
return;
|
|
66008
66207
|
}
|
|
66009
|
-
if (!
|
|
66208
|
+
if (!fs39.existsSync(fullPath) || fs39.statSync(fullPath).isDirectory()) {
|
|
66010
66209
|
this.json(res, 404, { error: `File not found: ${filePath}` });
|
|
66011
66210
|
return;
|
|
66012
66211
|
}
|
|
66013
|
-
const content =
|
|
66212
|
+
const content = fs39.readFileSync(fullPath, "utf-8");
|
|
66014
66213
|
this.json(res, 200, { type, path: filePath, content, lines: content.split("\n").length });
|
|
66015
66214
|
}
|
|
66016
66215
|
/** POST /api/providers/:type/file — write a file { path, content } */
|
|
@@ -66026,15 +66225,15 @@ var DevServer = class _DevServer {
|
|
|
66026
66225
|
this.json(res, 404, { error: `Provider directory not found: ${type}` });
|
|
66027
66226
|
return;
|
|
66028
66227
|
}
|
|
66029
|
-
const fullPath =
|
|
66228
|
+
const fullPath = path43.resolve(dir, path43.normalize(filePath));
|
|
66030
66229
|
if (!fullPath.startsWith(dir)) {
|
|
66031
66230
|
this.json(res, 403, { error: "Forbidden" });
|
|
66032
66231
|
return;
|
|
66033
66232
|
}
|
|
66034
66233
|
try {
|
|
66035
|
-
if (
|
|
66036
|
-
|
|
66037
|
-
|
|
66234
|
+
if (fs39.existsSync(fullPath)) fs39.copyFileSync(fullPath, fullPath + ".bak");
|
|
66235
|
+
fs39.mkdirSync(path43.dirname(fullPath), { recursive: true });
|
|
66236
|
+
fs39.writeFileSync(fullPath, content, "utf-8");
|
|
66038
66237
|
this.log(`File saved: ${fullPath} (${content.length} chars)`);
|
|
66039
66238
|
this.providerLoader.reload();
|
|
66040
66239
|
this.json(res, 200, { saved: true, path: filePath, chars: content.length });
|
|
@@ -66050,9 +66249,9 @@ var DevServer = class _DevServer {
|
|
|
66050
66249
|
return;
|
|
66051
66250
|
}
|
|
66052
66251
|
for (const name of ["scripts.js", "provider.json"]) {
|
|
66053
|
-
const p =
|
|
66054
|
-
if (
|
|
66055
|
-
const source =
|
|
66252
|
+
const p = path43.join(dir, name);
|
|
66253
|
+
if (fs39.existsSync(p)) {
|
|
66254
|
+
const source = fs39.readFileSync(p, "utf-8");
|
|
66056
66255
|
this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
|
|
66057
66256
|
return;
|
|
66058
66257
|
}
|
|
@@ -66071,11 +66270,11 @@ var DevServer = class _DevServer {
|
|
|
66071
66270
|
this.json(res, 404, { error: `Provider not found: ${type}` });
|
|
66072
66271
|
return;
|
|
66073
66272
|
}
|
|
66074
|
-
const target =
|
|
66075
|
-
const targetPath =
|
|
66273
|
+
const target = fs39.existsSync(path43.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
|
|
66274
|
+
const targetPath = path43.join(dir, target);
|
|
66076
66275
|
try {
|
|
66077
|
-
if (
|
|
66078
|
-
|
|
66276
|
+
if (fs39.existsSync(targetPath)) fs39.copyFileSync(targetPath, targetPath + ".bak");
|
|
66277
|
+
fs39.writeFileSync(targetPath, source, "utf-8");
|
|
66079
66278
|
this.log(`Saved provider: ${targetPath} (${source.length} chars)`);
|
|
66080
66279
|
this.providerLoader.reload();
|
|
66081
66280
|
this.json(res, 200, { saved: true, path: targetPath, chars: source.length });
|
|
@@ -66219,21 +66418,21 @@ var DevServer = class _DevServer {
|
|
|
66219
66418
|
}
|
|
66220
66419
|
let targetDir;
|
|
66221
66420
|
targetDir = this.providerLoader.getUserProviderDir(category, type);
|
|
66222
|
-
const jsonPath =
|
|
66223
|
-
if (
|
|
66421
|
+
const jsonPath = path43.join(targetDir, "provider.json");
|
|
66422
|
+
if (fs39.existsSync(jsonPath)) {
|
|
66224
66423
|
this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
|
|
66225
66424
|
return;
|
|
66226
66425
|
}
|
|
66227
66426
|
try {
|
|
66228
66427
|
const result = generateFiles(type, name, category, { cdpPorts, cli, processName, installPath, binary, extensionId, version, osPaths, processNames });
|
|
66229
|
-
|
|
66230
|
-
|
|
66428
|
+
fs39.mkdirSync(targetDir, { recursive: true });
|
|
66429
|
+
fs39.writeFileSync(jsonPath, result["provider.json"], "utf-8");
|
|
66231
66430
|
const createdFiles = ["provider.json"];
|
|
66232
66431
|
if (result.files) {
|
|
66233
66432
|
for (const [relPath, content] of Object.entries(result.files)) {
|
|
66234
|
-
const fullPath =
|
|
66235
|
-
|
|
66236
|
-
|
|
66433
|
+
const fullPath = path43.join(targetDir, relPath);
|
|
66434
|
+
fs39.mkdirSync(path43.dirname(fullPath), { recursive: true });
|
|
66435
|
+
fs39.writeFileSync(fullPath, content, "utf-8");
|
|
66237
66436
|
createdFiles.push(relPath);
|
|
66238
66437
|
}
|
|
66239
66438
|
}
|
|
@@ -66282,38 +66481,38 @@ var DevServer = class _DevServer {
|
|
|
66282
66481
|
}
|
|
66283
66482
|
// ─── Phase 2: Auto-Implement Backend ───
|
|
66284
66483
|
getLatestScriptVersionDir(scriptsDir) {
|
|
66285
|
-
if (!
|
|
66286
|
-
const versions =
|
|
66484
|
+
if (!fs39.existsSync(scriptsDir)) return null;
|
|
66485
|
+
const versions = fs39.readdirSync(scriptsDir).filter((d) => {
|
|
66287
66486
|
try {
|
|
66288
|
-
return
|
|
66487
|
+
return fs39.statSync(path43.join(scriptsDir, d)).isDirectory();
|
|
66289
66488
|
} catch {
|
|
66290
66489
|
return false;
|
|
66291
66490
|
}
|
|
66292
66491
|
}).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
|
|
66293
66492
|
if (versions.length === 0) return null;
|
|
66294
|
-
return
|
|
66493
|
+
return path43.join(scriptsDir, versions[0]);
|
|
66295
66494
|
}
|
|
66296
66495
|
resolveAutoImplWritableProviderDir(category, type, requestedDir) {
|
|
66297
|
-
const canonicalUserDir =
|
|
66298
|
-
const desiredDir = requestedDir ?
|
|
66299
|
-
const upstreamRoot =
|
|
66300
|
-
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${
|
|
66496
|
+
const canonicalUserDir = path43.resolve(this.providerLoader.getUserProviderDir(category, type));
|
|
66497
|
+
const desiredDir = requestedDir ? path43.resolve(requestedDir) : canonicalUserDir;
|
|
66498
|
+
const upstreamRoot = path43.resolve(this.providerLoader.getUpstreamDir());
|
|
66499
|
+
if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path43.sep}`)) {
|
|
66301
66500
|
return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
|
|
66302
66501
|
}
|
|
66303
|
-
if (
|
|
66502
|
+
if (path43.basename(desiredDir) !== type) {
|
|
66304
66503
|
return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
|
|
66305
66504
|
}
|
|
66306
66505
|
const sourceDir = this.findProviderDir(type);
|
|
66307
66506
|
if (!sourceDir) {
|
|
66308
66507
|
return { dir: null, reason: `Provider source directory not found for '${type}'` };
|
|
66309
66508
|
}
|
|
66310
|
-
if (!
|
|
66311
|
-
|
|
66312
|
-
|
|
66509
|
+
if (!fs39.existsSync(desiredDir)) {
|
|
66510
|
+
fs39.mkdirSync(path43.dirname(desiredDir), { recursive: true });
|
|
66511
|
+
fs39.cpSync(sourceDir, desiredDir, { recursive: true });
|
|
66313
66512
|
this.log(`Auto-implement writable copy created: ${desiredDir}`);
|
|
66314
66513
|
}
|
|
66315
|
-
const providerJson =
|
|
66316
|
-
if (!
|
|
66514
|
+
const providerJson = path43.join(desiredDir, "provider.json");
|
|
66515
|
+
if (!fs39.existsSync(providerJson)) {
|
|
66317
66516
|
return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
|
|
66318
66517
|
}
|
|
66319
66518
|
return { dir: desiredDir };
|
|
@@ -67162,9 +67361,9 @@ async function listHostedCliRuntimes(endpoint) {
|
|
|
67162
67361
|
|
|
67163
67362
|
// src/session-host/managed-host.ts
|
|
67164
67363
|
import { execFileSync as execFileSync9, spawn as spawn4 } from "child_process";
|
|
67165
|
-
import * as
|
|
67166
|
-
import * as
|
|
67167
|
-
import * as
|
|
67364
|
+
import * as fs40 from "fs";
|
|
67365
|
+
import * as os31 from "os";
|
|
67366
|
+
import * as path44 from "path";
|
|
67168
67367
|
import {
|
|
67169
67368
|
getDefaultSessionHostEndpoint as getDefaultSessionHostEndpoint2,
|
|
67170
67369
|
sanitizeSpawnEnv as sanitizeSpawnEnv2
|
|
@@ -67182,24 +67381,24 @@ function createManagedSessionHost(options) {
|
|
|
67182
67381
|
}
|
|
67183
67382
|
function resolveEntry() {
|
|
67184
67383
|
const packagedCandidates = [
|
|
67185
|
-
|
|
67186
|
-
|
|
67384
|
+
path44.resolve(__dirname, "../vendor/session-host-daemon/index.js"),
|
|
67385
|
+
path44.resolve(__dirname, "../../vendor/session-host-daemon/index.js")
|
|
67187
67386
|
];
|
|
67188
67387
|
for (const candidate of packagedCandidates) {
|
|
67189
|
-
if (
|
|
67388
|
+
if (fs40.existsSync(candidate)) {
|
|
67190
67389
|
return candidate;
|
|
67191
67390
|
}
|
|
67192
67391
|
}
|
|
67193
67392
|
return __require.resolve("@adhdev/session-host-daemon");
|
|
67194
67393
|
}
|
|
67195
67394
|
function getPidFile() {
|
|
67196
|
-
return
|
|
67395
|
+
return path44.join(os31.homedir(), ".adhdev", `${appName}-session-host.pid`);
|
|
67197
67396
|
}
|
|
67198
67397
|
function getPid() {
|
|
67199
67398
|
try {
|
|
67200
67399
|
const pidFile = getPidFile();
|
|
67201
|
-
if (!
|
|
67202
|
-
const pid = Number.parseInt(
|
|
67400
|
+
if (!fs40.existsSync(pidFile)) return null;
|
|
67401
|
+
const pid = Number.parseInt(fs40.readFileSync(pidFile, "utf8").trim(), 10);
|
|
67203
67402
|
return Number.isFinite(pid) ? pid : null;
|
|
67204
67403
|
} catch {
|
|
67205
67404
|
return null;
|
|
@@ -67224,9 +67423,9 @@ function createManagedSessionHost(options) {
|
|
|
67224
67423
|
let stdio = "ignore";
|
|
67225
67424
|
let logFd = null;
|
|
67226
67425
|
if (options.spawnStdio === "logfile") {
|
|
67227
|
-
const logDir =
|
|
67228
|
-
|
|
67229
|
-
logFd =
|
|
67426
|
+
const logDir = path44.join(os31.homedir(), ".adhdev", "logs");
|
|
67427
|
+
fs40.mkdirSync(logDir, { recursive: true });
|
|
67428
|
+
logFd = fs40.openSync(path44.join(logDir, "session-host.log"), "a");
|
|
67230
67429
|
stdio = ["ignore", logFd, logFd];
|
|
67231
67430
|
}
|
|
67232
67431
|
const child = spawn4(process.execPath, [entry], {
|
|
@@ -67238,7 +67437,7 @@ function createManagedSessionHost(options) {
|
|
|
67238
67437
|
child.unref();
|
|
67239
67438
|
if (logFd !== null) {
|
|
67240
67439
|
try {
|
|
67241
|
-
|
|
67440
|
+
fs40.closeSync(logFd);
|
|
67242
67441
|
} catch {
|
|
67243
67442
|
}
|
|
67244
67443
|
}
|
|
@@ -67247,8 +67446,8 @@ function createManagedSessionHost(options) {
|
|
|
67247
67446
|
let stopped = false;
|
|
67248
67447
|
const pidFile = getPidFile();
|
|
67249
67448
|
try {
|
|
67250
|
-
if (
|
|
67251
|
-
const pid = Number.parseInt(
|
|
67449
|
+
if (fs40.existsSync(pidFile)) {
|
|
67450
|
+
const pid = Number.parseInt(fs40.readFileSync(pidFile, "utf8").trim(), 10);
|
|
67252
67451
|
if (Number.isFinite(pid) && pid !== process.pid && isManagedPid(pid)) {
|
|
67253
67452
|
stopped = killPid2(pid) || stopped;
|
|
67254
67453
|
}
|
|
@@ -67256,7 +67455,7 @@ function createManagedSessionHost(options) {
|
|
|
67256
67455
|
} catch {
|
|
67257
67456
|
} finally {
|
|
67258
67457
|
try {
|
|
67259
|
-
|
|
67458
|
+
fs40.unlinkSync(pidFile);
|
|
67260
67459
|
} catch {
|
|
67261
67460
|
}
|
|
67262
67461
|
}
|
|
@@ -67442,8 +67641,8 @@ async function installExtension(ide, extension) {
|
|
|
67442
67641
|
const res = await fetch(extension.vsixUrl);
|
|
67443
67642
|
if (res.ok) {
|
|
67444
67643
|
const buffer = Buffer.from(await res.arrayBuffer());
|
|
67445
|
-
const
|
|
67446
|
-
|
|
67644
|
+
const fs41 = await import("fs");
|
|
67645
|
+
fs41.writeFileSync(vsixPath, buffer);
|
|
67447
67646
|
return new Promise((resolve25) => {
|
|
67448
67647
|
const cmd = `"${ide.cliCommand}" --install-extension "${vsixPath}" --force`;
|
|
67449
67648
|
exec6(cmd, { timeout: 6e4 }, (error, _stdout, stderr) => {
|
|
@@ -68042,7 +68241,7 @@ import { dirname as dirname15, resolve as resolve23 } from "path";
|
|
|
68042
68241
|
|
|
68043
68242
|
// src/providers/sdk/v1/validators/taint.ts
|
|
68044
68243
|
import { readFileSync as readFileSync41, existsSync as existsSync54 } from "fs";
|
|
68045
|
-
import { resolve as resolve24, dirname as dirname16, join as
|
|
68244
|
+
import { resolve as resolve24, dirname as dirname16, join as join50 } from "path";
|
|
68046
68245
|
|
|
68047
68246
|
// src/providers/sdk/v1/validators/index.ts
|
|
68048
68247
|
init_manifest();
|