@adhdev/daemon-core 0.9.82-rc.363 → 0.9.82-rc.365
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/commands/med-family/cli-agent.d.ts +2 -0
- package/dist/commands/med-family/fast-forward.d.ts +2 -0
- package/dist/commands/med-family/ide.d.ts +10 -0
- package/dist/commands/med-family/index.d.ts +3 -0
- package/dist/commands/med-family/mesh-crud.d.ts +2 -0
- package/dist/commands/med-family/mesh-host-pairing.d.ts +2 -0
- package/dist/commands/med-family/mesh-queue.d.ts +2 -0
- package/dist/commands/med-family/types.d.ts +116 -0
- package/dist/commands/router.d.ts +83 -0
- package/dist/index.js +1652 -1515
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1655 -1519
- package/dist/index.mjs.map +1 -1
- package/dist/providers/spec/fsm-driver.d.ts +27 -0
- package/dist/system/hash.d.ts +8 -0
- package/package.json +2 -2
- package/src/commands/cli-manager.ts +2 -1
- package/src/commands/med-family/cli-agent.ts +218 -0
- package/src/commands/med-family/fast-forward.ts +198 -0
- package/src/commands/med-family/ide.ts +163 -0
- package/src/commands/med-family/index.ts +35 -0
- package/src/commands/med-family/mesh-crud.ts +788 -0
- package/src/commands/med-family/mesh-host-pairing.ts +234 -0
- package/src/commands/med-family/mesh-queue.ts +131 -0
- package/src/commands/med-family/types.ts +120 -0
- package/src/commands/mesh-coordinator.ts +2 -2
- package/src/commands/router.ts +57 -1602
- package/src/config/mesh-config.ts +3 -2
- package/src/mesh/mesh-active-work.ts +59 -81
- package/src/providers/spec/fsm-driver.ts +56 -2
- package/src/system/hash.ts +23 -0
package/dist/index.mjs
CHANGED
|
@@ -311,10 +311,10 @@ function readInjected(value) {
|
|
|
311
311
|
}
|
|
312
312
|
function getDaemonBuildInfo() {
|
|
313
313
|
if (cached) return cached;
|
|
314
|
-
const commit = readInjected(true ? "
|
|
315
|
-
const commitShort = readInjected(true ? "
|
|
316
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
317
|
-
const builtAt = readInjected(true ? "2026-06-
|
|
314
|
+
const commit = readInjected(true ? "fe24f3fb158efc949e806b79bca2479b1c29d753" : void 0) ?? "unknown";
|
|
315
|
+
const commitShort = readInjected(true ? "fe24f3fb" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
316
|
+
const version = readInjected(true ? "0.9.82-rc.365" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
317
|
+
const builtAt = readInjected(true ? "2026-06-24T00:47:57.092Z" : void 0);
|
|
318
318
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
319
319
|
return cached;
|
|
320
320
|
}
|
|
@@ -2188,6 +2188,20 @@ var init_recent_activity = __esm({
|
|
|
2188
2188
|
}
|
|
2189
2189
|
});
|
|
2190
2190
|
|
|
2191
|
+
// src/system/hash.ts
|
|
2192
|
+
import { createHash } from "crypto";
|
|
2193
|
+
function sha256Hex(input) {
|
|
2194
|
+
return createHash("sha256").update(input).digest("hex");
|
|
2195
|
+
}
|
|
2196
|
+
function shortHash(input, length = 16) {
|
|
2197
|
+
return sha256Hex(input).slice(0, length);
|
|
2198
|
+
}
|
|
2199
|
+
var init_hash = __esm({
|
|
2200
|
+
"src/system/hash.ts"() {
|
|
2201
|
+
"use strict";
|
|
2202
|
+
}
|
|
2203
|
+
});
|
|
2204
|
+
|
|
2191
2205
|
// src/mesh/mesh-host-ownership.ts
|
|
2192
2206
|
function readObject(value) {
|
|
2193
2207
|
return value && typeof value === "object" && !Array.isArray(value) ? value : null;
|
|
@@ -2278,7 +2292,7 @@ __export(mesh_config_exports, {
|
|
|
2278
2292
|
});
|
|
2279
2293
|
import { existsSync as existsSync5, readFileSync as readFileSync3, writeFileSync as writeFileSync2 } from "fs";
|
|
2280
2294
|
import { join as join5 } from "path";
|
|
2281
|
-
import {
|
|
2295
|
+
import { randomBytes, randomUUID as randomUUID3 } from "crypto";
|
|
2282
2296
|
function getMeshConfigPath() {
|
|
2283
2297
|
return join5(getConfigDir(), "meshes.json");
|
|
2284
2298
|
}
|
|
@@ -2468,7 +2482,7 @@ function normalizeManualHostAddress(hostAddress) {
|
|
|
2468
2482
|
return normalized;
|
|
2469
2483
|
}
|
|
2470
2484
|
function tokenIdForManualPairing(token) {
|
|
2471
|
-
return `tok_${
|
|
2485
|
+
return `tok_${shortHash(token)}`;
|
|
2472
2486
|
}
|
|
2473
2487
|
function normalizeTokenExpiry(value) {
|
|
2474
2488
|
if (typeof value !== "string" || !value.trim()) return void 0;
|
|
@@ -2700,6 +2714,7 @@ var SESSION_CLEANUP_MODES, SPAWNED_SESSION_VISIBILITY_MODES;
|
|
|
2700
2714
|
var init_mesh_config = __esm({
|
|
2701
2715
|
"src/config/mesh-config.ts"() {
|
|
2702
2716
|
"use strict";
|
|
2717
|
+
init_hash();
|
|
2703
2718
|
init_config();
|
|
2704
2719
|
init_repo_mesh_types();
|
|
2705
2720
|
init_mesh_host_ownership();
|
|
@@ -6916,7 +6931,6 @@ __export(mesh_coordinator_exports, {
|
|
|
6916
6931
|
resolveMeshCoordinatorSetup: () => resolveMeshCoordinatorSetup,
|
|
6917
6932
|
stripCoordinatorWrapperFile: () => stripCoordinatorWrapperFile
|
|
6918
6933
|
});
|
|
6919
|
-
import { createHash as createHash2 } from "crypto";
|
|
6920
6934
|
import { existsSync as existsSync9, readFileSync as readFileSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
6921
6935
|
import * as os4 from "os";
|
|
6922
6936
|
import { DEFAULT_SESSION_HOST_COLS, DEFAULT_SESSION_HOST_ROWS } from "@adhdev/session-host-core";
|
|
@@ -7086,7 +7100,7 @@ function replaceLegacyCliCommandMcpArgs(command, args) {
|
|
|
7086
7100
|
function resolveHermesCoordinatorHome(meshId, workspace) {
|
|
7087
7101
|
const key = `${meshId || "mesh"}
|
|
7088
7102
|
${resolve7(workspace || os4.tmpdir())}`;
|
|
7089
|
-
const hash =
|
|
7103
|
+
const hash = shortHash(key);
|
|
7090
7104
|
return join10(os4.tmpdir(), `adhdev-hermes-mesh-coordinator-${hash}`);
|
|
7091
7105
|
}
|
|
7092
7106
|
function resolveMcpConfigPath(configPath, workspace) {
|
|
@@ -7300,6 +7314,7 @@ var init_mesh_coordinator = __esm({
|
|
|
7300
7314
|
"src/commands/mesh-coordinator.ts"() {
|
|
7301
7315
|
"use strict";
|
|
7302
7316
|
init_logger();
|
|
7317
|
+
init_hash();
|
|
7303
7318
|
DEFAULT_SERVER_NAME = "adhdev-mesh";
|
|
7304
7319
|
DEFAULT_ADHDEV_MCP_COMMAND = "adhdev";
|
|
7305
7320
|
HERMES_CLI_TYPE = "hermes-cli";
|
|
@@ -8168,6 +8183,46 @@ function classifyDirectDispatch(params) {
|
|
|
8168
8183
|
const isFreshUnacknowledged = Boolean(ledgerOnlyStaleReason && !liveStaleReason);
|
|
8169
8184
|
return { ledgerOnlyStaleReason, isFreshUnacknowledged };
|
|
8170
8185
|
}
|
|
8186
|
+
function buildLedgerDirectDispatchRecord(dispatch, ctx) {
|
|
8187
|
+
const taskId = directDispatchTaskId(dispatch);
|
|
8188
|
+
const terminal = ctx.terminals.filter((entry) => new Date(entry.timestamp).getTime() >= new Date(dispatch.timestamp).getTime()).find((entry) => terminalMatchesDispatch(entry, dispatch, taskId));
|
|
8189
|
+
const terminalStatus = terminal ? statusFromTerminal(terminal) : void 0;
|
|
8190
|
+
const live = sessionStatusFromNodes(ctx.nodes, dispatch.nodeId, dispatch.sessionId);
|
|
8191
|
+
const status = terminalStatus || live.status || "assigned";
|
|
8192
|
+
const terminalRow = Boolean(terminal && terminal.kind !== "task_approval_needed");
|
|
8193
|
+
const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
|
|
8194
|
+
status,
|
|
8195
|
+
isTerminalRow: terminalRow,
|
|
8196
|
+
hasTerminalStatus: Boolean(terminalStatus),
|
|
8197
|
+
liveStatus: live.status,
|
|
8198
|
+
liveStaleReason: live.staleReason,
|
|
8199
|
+
dispatchedToIdleSession: dispatch.payload?.dispatchedToIdleSession === true
|
|
8200
|
+
});
|
|
8201
|
+
const message = readString6(dispatch.payload?.message) || readString6(dispatch.payload?.summary) || "";
|
|
8202
|
+
const { title, summary } = summarizeMessage(message);
|
|
8203
|
+
const record = {
|
|
8204
|
+
taskId,
|
|
8205
|
+
source: "direct",
|
|
8206
|
+
status,
|
|
8207
|
+
nodeId: dispatch.nodeId,
|
|
8208
|
+
sessionId: dispatch.sessionId,
|
|
8209
|
+
providerType: dispatch.providerType || readString6(dispatch.payload?.providerType),
|
|
8210
|
+
taskTitle: readString6(dispatch.payload?.taskTitle) || title,
|
|
8211
|
+
taskSummary: readString6(dispatch.payload?.taskSummary) || summary,
|
|
8212
|
+
message,
|
|
8213
|
+
taskMode: readString6(dispatch.payload?.taskMode),
|
|
8214
|
+
createdAt: dispatch.timestamp,
|
|
8215
|
+
updatedAt: terminal?.timestamp || dispatch.timestamp,
|
|
8216
|
+
dispatchedAt: dispatch.timestamp,
|
|
8217
|
+
elapsedMs: elapsedSince(dispatch.timestamp, ctx.now),
|
|
8218
|
+
terminal: terminalRow,
|
|
8219
|
+
terminalKind: terminal?.kind,
|
|
8220
|
+
terminalAt: terminal?.timestamp,
|
|
8221
|
+
staleReason: live.staleReason || ledgerOnlyStaleReason,
|
|
8222
|
+
...isFreshUnacknowledged ? { staleDispatchUnacknowledged: true } : {}
|
|
8223
|
+
};
|
|
8224
|
+
return { record, terminalRow };
|
|
8225
|
+
}
|
|
8171
8226
|
function buildMeshActiveWorkSummary(activeWork) {
|
|
8172
8227
|
const statusCounts = {
|
|
8173
8228
|
pending: 0,
|
|
@@ -8273,49 +8328,13 @@ function buildMeshActiveWork(opts) {
|
|
|
8273
8328
|
const ledgerEntries = (opts.ledgerEntries || []).slice().sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
8274
8329
|
const terminals = ledgerEntries.filter((entry) => TERMINAL_LEDGER_KINDS.has(entry.kind) || entry.kind === "task_approval_needed");
|
|
8275
8330
|
for (const dispatch of ledgerEntries.filter(isDirectDispatch)) {
|
|
8276
|
-
|
|
8277
|
-
|
|
8278
|
-
const terminal = terminals.filter((entry) => new Date(entry.timestamp).getTime() >= new Date(dispatch.timestamp).getTime()).find((entry) => terminalMatchesDispatch(entry, dispatch, taskId));
|
|
8279
|
-
const terminalStatus = terminal ? statusFromTerminal(terminal) : void 0;
|
|
8280
|
-
const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
|
|
8281
|
-
const status = terminalStatus || live.status || "assigned";
|
|
8282
|
-
const terminalRow = Boolean(terminal && terminal.kind !== "task_approval_needed");
|
|
8283
|
-
const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
|
|
8284
|
-
status,
|
|
8285
|
-
isTerminalRow: terminalRow,
|
|
8286
|
-
hasTerminalStatus: Boolean(terminalStatus),
|
|
8287
|
-
liveStatus: live.status,
|
|
8288
|
-
liveStaleReason: live.staleReason,
|
|
8289
|
-
dispatchedToIdleSession: dispatch.payload?.dispatchedToIdleSession === true
|
|
8290
|
-
});
|
|
8291
|
-
const message = readString6(dispatch.payload?.message) || readString6(dispatch.payload?.summary) || "";
|
|
8292
|
-
const { title, summary: summary2 } = summarizeMessage(message);
|
|
8293
|
-
const record = {
|
|
8294
|
-
taskId,
|
|
8295
|
-
source: "direct",
|
|
8296
|
-
status,
|
|
8297
|
-
nodeId: dispatch.nodeId,
|
|
8298
|
-
sessionId: dispatch.sessionId,
|
|
8299
|
-
providerType: dispatch.providerType || readString6(dispatch.payload?.providerType),
|
|
8300
|
-
taskTitle: readString6(dispatch.payload?.taskTitle) || title,
|
|
8301
|
-
taskSummary: readString6(dispatch.payload?.taskSummary) || summary2,
|
|
8302
|
-
message,
|
|
8303
|
-
taskMode: readString6(dispatch.payload?.taskMode),
|
|
8304
|
-
createdAt: dispatch.timestamp,
|
|
8305
|
-
updatedAt: terminal?.timestamp || dispatch.timestamp,
|
|
8306
|
-
dispatchedAt: dispatch.timestamp,
|
|
8307
|
-
elapsedMs: elapsedSince(dispatch.timestamp, now),
|
|
8308
|
-
terminal: terminalRow,
|
|
8309
|
-
terminalKind: terminal?.kind,
|
|
8310
|
-
terminalAt: terminal?.timestamp,
|
|
8311
|
-
staleReason: live.staleReason || ledgerOnlyStaleReason,
|
|
8312
|
-
...isFreshUnacknowledged ? { staleDispatchUnacknowledged: true } : {}
|
|
8313
|
-
};
|
|
8331
|
+
if (dbTaskIds.has(directDispatchTaskId(dispatch))) continue;
|
|
8332
|
+
const { record, terminalRow } = buildLedgerDirectDispatchRecord(dispatch, { terminals, nodes: opts.nodes, now });
|
|
8314
8333
|
if (terminalRow) {
|
|
8315
8334
|
terminalDirectWork.push(record);
|
|
8316
8335
|
if (opts.includeTerminalDirect !== true) continue;
|
|
8317
8336
|
}
|
|
8318
|
-
if (
|
|
8337
|
+
if (record.staleReason && !terminalRow) {
|
|
8319
8338
|
staleDirectWork.push(record);
|
|
8320
8339
|
continue;
|
|
8321
8340
|
}
|
|
@@ -8325,48 +8344,12 @@ function buildMeshActiveWork(opts) {
|
|
|
8325
8344
|
const ledgerEntries = (opts.ledgerEntries || []).slice().sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
8326
8345
|
const terminals = ledgerEntries.filter((entry) => TERMINAL_LEDGER_KINDS.has(entry.kind) || entry.kind === "task_approval_needed");
|
|
8327
8346
|
for (const dispatch of ledgerEntries.filter(isDirectDispatch)) {
|
|
8328
|
-
const
|
|
8329
|
-
const terminal = terminals.filter((entry) => new Date(entry.timestamp).getTime() >= new Date(dispatch.timestamp).getTime()).find((entry) => terminalMatchesDispatch(entry, dispatch, taskId));
|
|
8330
|
-
const terminalStatus = terminal ? statusFromTerminal(terminal) : void 0;
|
|
8331
|
-
const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
|
|
8332
|
-
const status = terminalStatus || live.status || "assigned";
|
|
8333
|
-
const terminalRow = Boolean(terminal && terminal.kind !== "task_approval_needed");
|
|
8334
|
-
const { ledgerOnlyStaleReason, isFreshUnacknowledged } = classifyDirectDispatch({
|
|
8335
|
-
status,
|
|
8336
|
-
isTerminalRow: terminalRow,
|
|
8337
|
-
hasTerminalStatus: Boolean(terminalStatus),
|
|
8338
|
-
liveStatus: live.status,
|
|
8339
|
-
liveStaleReason: live.staleReason,
|
|
8340
|
-
dispatchedToIdleSession: dispatch.payload?.dispatchedToIdleSession === true
|
|
8341
|
-
});
|
|
8342
|
-
const message = readString6(dispatch.payload?.message) || readString6(dispatch.payload?.summary) || "";
|
|
8343
|
-
const { title, summary: summary2 } = summarizeMessage(message);
|
|
8344
|
-
const record = {
|
|
8345
|
-
taskId,
|
|
8346
|
-
source: "direct",
|
|
8347
|
-
status,
|
|
8348
|
-
nodeId: dispatch.nodeId,
|
|
8349
|
-
sessionId: dispatch.sessionId,
|
|
8350
|
-
providerType: dispatch.providerType || readString6(dispatch.payload?.providerType),
|
|
8351
|
-
taskTitle: readString6(dispatch.payload?.taskTitle) || title,
|
|
8352
|
-
taskSummary: readString6(dispatch.payload?.taskSummary) || summary2,
|
|
8353
|
-
message,
|
|
8354
|
-
taskMode: readString6(dispatch.payload?.taskMode),
|
|
8355
|
-
createdAt: dispatch.timestamp,
|
|
8356
|
-
updatedAt: terminal?.timestamp || dispatch.timestamp,
|
|
8357
|
-
dispatchedAt: dispatch.timestamp,
|
|
8358
|
-
elapsedMs: elapsedSince(dispatch.timestamp, now),
|
|
8359
|
-
terminal: terminalRow,
|
|
8360
|
-
terminalKind: terminal?.kind,
|
|
8361
|
-
terminalAt: terminal?.timestamp,
|
|
8362
|
-
staleReason: live.staleReason || ledgerOnlyStaleReason,
|
|
8363
|
-
...isFreshUnacknowledged ? { staleDispatchUnacknowledged: true } : {}
|
|
8364
|
-
};
|
|
8347
|
+
const { record, terminalRow } = buildLedgerDirectDispatchRecord(dispatch, { terminals, nodes: opts.nodes, now });
|
|
8365
8348
|
if (terminalRow) {
|
|
8366
8349
|
terminalDirectWork.push(record);
|
|
8367
8350
|
if (opts.includeTerminalDirect !== true) continue;
|
|
8368
8351
|
}
|
|
8369
|
-
if (
|
|
8352
|
+
if (record.staleReason && !terminalRow) {
|
|
8370
8353
|
staleDirectWork.push(record);
|
|
8371
8354
|
continue;
|
|
8372
8355
|
}
|
|
@@ -22017,7 +22000,7 @@ init_resolve_executable();
|
|
|
22017
22000
|
import { existsSync as existsSync13, readFileSync as readFileSync10 } from "fs";
|
|
22018
22001
|
import { join as join14, resolve as pathResolve } from "path";
|
|
22019
22002
|
import { execFile as execFile3 } from "child_process";
|
|
22020
|
-
import { createHash as
|
|
22003
|
+
import { createHash as createHash2 } from "crypto";
|
|
22021
22004
|
import { promisify as promisify3 } from "util";
|
|
22022
22005
|
import * as yaml3 from "js-yaml";
|
|
22023
22006
|
var MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS = [
|
|
@@ -22124,7 +22107,7 @@ function computeStaleInputsDigest(workspace, staleInputs) {
|
|
|
22124
22107
|
for (const relative5 of staleInputs ?? []) {
|
|
22125
22108
|
const filePath = join14(workspace, relative5);
|
|
22126
22109
|
try {
|
|
22127
|
-
digest[relative5] =
|
|
22110
|
+
digest[relative5] = createHash2("sha256").update(readFileSync10(filePath)).digest("hex");
|
|
22128
22111
|
} catch {
|
|
22129
22112
|
digest[relative5] = "absent";
|
|
22130
22113
|
}
|
|
@@ -34371,6 +34354,9 @@ var lowFamilyRegistry = new Map(
|
|
|
34371
34354
|
})
|
|
34372
34355
|
);
|
|
34373
34356
|
|
|
34357
|
+
// src/commands/med-family/cli-agent.ts
|
|
34358
|
+
init_dist();
|
|
34359
|
+
|
|
34374
34360
|
// src/commands/cli-manager.ts
|
|
34375
34361
|
init_provider_cli_adapter();
|
|
34376
34362
|
init_cli_detector();
|
|
@@ -34378,6 +34364,7 @@ init_config();
|
|
|
34378
34364
|
init_state_store();
|
|
34379
34365
|
init_workspaces();
|
|
34380
34366
|
init_recent_activity();
|
|
34367
|
+
init_hash();
|
|
34381
34368
|
init_coordinator_registry();
|
|
34382
34369
|
import * as os21 from "os";
|
|
34383
34370
|
import * as path27 from "path";
|
|
@@ -34723,6 +34710,11 @@ var FsmDriver = class {
|
|
|
34723
34710
|
lastWin32WriteAt = 0;
|
|
34724
34711
|
/** Pending paced chunk-write timer for a large win32 body (see writeWin32Body). */
|
|
34725
34712
|
win32WriteTimer = null;
|
|
34713
|
+
/** Timer driving the win32 verification-based modal-confirm CR resend loop (see
|
|
34714
|
+
* scheduleWin32ModalConfirm). A lone CR that confirms an approval/picker choice
|
|
34715
|
+
* is absorbed by ConPTY the same way a send_message submit CR is, so the confirm
|
|
34716
|
+
* must be resent until the modal actually resolves (status leaves 'approval'). */
|
|
34717
|
+
win32ModalConfirmTimer = null;
|
|
34726
34718
|
currentEval = null;
|
|
34727
34719
|
stateHistory = [];
|
|
34728
34720
|
prevStateAt = 0;
|
|
@@ -34847,6 +34839,10 @@ var FsmDriver = class {
|
|
|
34847
34839
|
clearTimeout(this.win32WriteTimer);
|
|
34848
34840
|
this.win32WriteTimer = null;
|
|
34849
34841
|
}
|
|
34842
|
+
if (this.win32ModalConfirmTimer) {
|
|
34843
|
+
clearTimeout(this.win32ModalConfirmTimer);
|
|
34844
|
+
this.win32ModalConfirmTimer = null;
|
|
34845
|
+
}
|
|
34850
34846
|
this.specWatcher?.close();
|
|
34851
34847
|
this.adapter.kill();
|
|
34852
34848
|
}
|
|
@@ -35442,10 +35438,61 @@ var FsmDriver = class {
|
|
|
35442
35438
|
const nav = step.repeat(Math.abs(delta));
|
|
35443
35439
|
const confirm = (rule.key_for_index || "\r").replace(/\{index\}/g, "") || "\r";
|
|
35444
35440
|
if (nav) this.adapter.send_keys(nav);
|
|
35445
|
-
this.
|
|
35441
|
+
this.submitModalConfirm(confirm);
|
|
35442
|
+
return;
|
|
35443
|
+
}
|
|
35444
|
+
this.submitModalConfirm(btn.key);
|
|
35445
|
+
}
|
|
35446
|
+
/**
|
|
35447
|
+
* Submit a modal-confirm key sequence (the choice key + its trailing CR).
|
|
35448
|
+
*
|
|
35449
|
+
* On win32 the trailing CR is the SAME lone-CR-swallow case as a send_message
|
|
35450
|
+
* submit: ConPTY can absorb a single CR as a literal newline instead of a
|
|
35451
|
+
* confirm, so the approval/picker modal never resolves and the FSM flaps
|
|
35452
|
+
* approval↔busy while auto-approve keeps firing into the void (APPROVESTUCK).
|
|
35453
|
+
* So we split any non-CR prefix (e.g. the "1" of "1\r") off, write it once, and
|
|
35454
|
+
* resend the CR on a fixed cadence until the modal actually resolves (status
|
|
35455
|
+
* leaves 'approval'). Non-win32 keeps the single direct write — its CR submits
|
|
35456
|
+
* on the first try.
|
|
35457
|
+
*/
|
|
35458
|
+
submitModalConfirm(keys) {
|
|
35459
|
+
if (process.platform !== "win32") {
|
|
35460
|
+
this.adapter.send_keys(keys);
|
|
35446
35461
|
return;
|
|
35447
35462
|
}
|
|
35448
|
-
|
|
35463
|
+
const m = /^([\s\S]*?)([\r\n]+)$/.exec(keys);
|
|
35464
|
+
const prefix = m ? m[1] : keys;
|
|
35465
|
+
const cr = m ? m[2] : "";
|
|
35466
|
+
if (prefix) this.adapter.send_keys(prefix);
|
|
35467
|
+
if (!cr) return;
|
|
35468
|
+
this.scheduleWin32ModalConfirm(cr);
|
|
35469
|
+
}
|
|
35470
|
+
/**
|
|
35471
|
+
* win32 modal-confirm CR resend loop. Mirrors scheduleWin32Submit's phase-2
|
|
35472
|
+
* verified resend, but gated on still being IN a modal (status 'approval')
|
|
35473
|
+
* rather than still idle: the first CR fires immediately, then resends every
|
|
35474
|
+
* WIN32_SUBMIT_RESEND_GAP_MS while the FSM is still showing the modal, up to
|
|
35475
|
+
* WIN32_SUBMIT_MAX_RESENDS. The instant the modal resolves (status flips to
|
|
35476
|
+
* generating/idle) we stop, so no stray CR leaks into the next turn's composer.
|
|
35477
|
+
*/
|
|
35478
|
+
scheduleWin32ModalConfirm(submitKey) {
|
|
35479
|
+
if (this.win32ModalConfirmTimer) {
|
|
35480
|
+
clearTimeout(this.win32ModalConfirmTimer);
|
|
35481
|
+
this.win32ModalConfirmTimer = null;
|
|
35482
|
+
}
|
|
35483
|
+
const fire = (attempt) => {
|
|
35484
|
+
this.win32ModalConfirmTimer = null;
|
|
35485
|
+
this.adapter.send_keys(submitKey);
|
|
35486
|
+
if (attempt + 1 >= WIN32_SUBMIT_MAX_RESENDS) return;
|
|
35487
|
+
this.win32ModalConfirmTimer = setTimeout(() => {
|
|
35488
|
+
if (this.currentStatus() !== "approval") {
|
|
35489
|
+
this.win32ModalConfirmTimer = null;
|
|
35490
|
+
return;
|
|
35491
|
+
}
|
|
35492
|
+
fire(attempt + 1);
|
|
35493
|
+
}, WIN32_SUBMIT_RESEND_GAP_MS);
|
|
35494
|
+
};
|
|
35495
|
+
fire(0);
|
|
35449
35496
|
}
|
|
35450
35497
|
handleAttachImage(blob, mime) {
|
|
35451
35498
|
const ctl = (this.spec.control_bar ?? []).find((c) => c.action.type === "attach_image");
|
|
@@ -40722,7 +40769,7 @@ function hasConfigOverride(args, key) {
|
|
|
40722
40769
|
function ensureEmptyDelegatedMcpConfig(workspace) {
|
|
40723
40770
|
const baseDir = path27.join(os21.tmpdir(), "adhdev-delegated-agent-empty-mcp");
|
|
40724
40771
|
mkdirSync13(baseDir, { recursive: true });
|
|
40725
|
-
const workspaceHash =
|
|
40772
|
+
const workspaceHash = shortHash(path27.resolve(workspace || os21.tmpdir()));
|
|
40726
40773
|
const filePath = path27.join(baseDir, `${workspaceHash}.json`);
|
|
40727
40774
|
writeFileSync16(filePath, JSON.stringify({ mcpServers: {} }, null, 2), "utf-8");
|
|
40728
40775
|
return filePath;
|
|
@@ -41690,6 +41737,156 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
41690
41737
|
}
|
|
41691
41738
|
};
|
|
41692
41739
|
|
|
41740
|
+
// src/commands/med-family/cli-agent.ts
|
|
41741
|
+
init_state_store();
|
|
41742
|
+
init_recent_activity();
|
|
41743
|
+
init_mesh_events_utils();
|
|
41744
|
+
var cliAgentHandlers = {
|
|
41745
|
+
launch_cli: async (ctx, args) => {
|
|
41746
|
+
const launchResult = await ctx.deps.cliManager.handleCliCommand("launch_cli", args);
|
|
41747
|
+
const meshNodeId = readStringValue(args?.settings?.meshNodeId);
|
|
41748
|
+
const meshId = readStringValue(args?.settings?.meshNodeFor);
|
|
41749
|
+
if (meshNodeId && meshId && launchResult?.success !== false) {
|
|
41750
|
+
try {
|
|
41751
|
+
const { getMesh: getMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
41752
|
+
const meshObj = getMesh2(meshId) ?? ctx.getCachedInlineMesh(meshId);
|
|
41753
|
+
const nodeObj = Array.isArray(meshObj?.nodes) ? meshObj.nodes.find((n) => meshNodeIdMatches(n, meshNodeId)) : void 0;
|
|
41754
|
+
const bootstrapStatus = readStringValue(nodeObj?.worktreeBootstrap?.status);
|
|
41755
|
+
if (bootstrapStatus === "running") {
|
|
41756
|
+
return { success: true, ...launchResult, bootstrapPending: true };
|
|
41757
|
+
}
|
|
41758
|
+
} catch {
|
|
41759
|
+
}
|
|
41760
|
+
}
|
|
41761
|
+
return launchResult;
|
|
41762
|
+
},
|
|
41763
|
+
stop_cli: async (ctx, args) => {
|
|
41764
|
+
return ctx.deps.cliManager.handleCliCommand("stop_cli", args);
|
|
41765
|
+
},
|
|
41766
|
+
set_cli_view_mode: async (ctx, args) => {
|
|
41767
|
+
return ctx.deps.cliManager.handleCliCommand("set_cli_view_mode", args);
|
|
41768
|
+
},
|
|
41769
|
+
record_provider_pty: async (ctx, args) => {
|
|
41770
|
+
return ctx.deps.cliManager.handleCliCommand("record_provider_pty", args);
|
|
41771
|
+
},
|
|
41772
|
+
agent_command: async (ctx, args) => {
|
|
41773
|
+
{
|
|
41774
|
+
const dispatchSessionId = readStringValue(args?.targetSessionId, args?.sessionId, args?.instanceId);
|
|
41775
|
+
const dispatchMeshContext = args?.meshContext;
|
|
41776
|
+
if (dispatchSessionId && dispatchMeshContext) {
|
|
41777
|
+
try {
|
|
41778
|
+
const inst = ctx.deps.instanceManager.getInstance(dispatchSessionId);
|
|
41779
|
+
if (inst && typeof inst.updateSettings === "function") {
|
|
41780
|
+
const stamp = buildMeshWorkerRelayStamp(
|
|
41781
|
+
inst.getState?.()?.settings,
|
|
41782
|
+
{
|
|
41783
|
+
meshId: dispatchMeshContext.meshId,
|
|
41784
|
+
nodeId: dispatchMeshContext.nodeId,
|
|
41785
|
+
coordinatorDaemonId: dispatchMeshContext.coordinatorDaemonId,
|
|
41786
|
+
// Session-level anchor: preserved across the P2P dispatch to a
|
|
41787
|
+
// remote worker so its completion echoes back to the right session.
|
|
41788
|
+
coordinatorSessionId: dispatchMeshContext.coordinatorSessionId
|
|
41789
|
+
}
|
|
41790
|
+
);
|
|
41791
|
+
if (stamp) inst.updateSettings(stamp);
|
|
41792
|
+
}
|
|
41793
|
+
} catch {
|
|
41794
|
+
}
|
|
41795
|
+
}
|
|
41796
|
+
}
|
|
41797
|
+
const agentResult = await ctx.deps.cliManager.handleCliCommand("agent_command", args);
|
|
41798
|
+
const meshCtx = args?.meshContext;
|
|
41799
|
+
const dispatchNodeId = readStringValue(meshCtx?.nodeId);
|
|
41800
|
+
const dispatchMeshId = readStringValue(meshCtx?.meshId);
|
|
41801
|
+
if (dispatchNodeId && dispatchMeshId && agentResult?.success !== false) {
|
|
41802
|
+
try {
|
|
41803
|
+
const { getMesh: getMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
41804
|
+
const meshObj = getMesh2(dispatchMeshId) ?? ctx.getCachedInlineMesh(dispatchMeshId);
|
|
41805
|
+
const nodeObj = Array.isArray(meshObj?.nodes) ? meshObj.nodes.find((n) => meshNodeIdMatches(n, dispatchNodeId)) : void 0;
|
|
41806
|
+
const bootstrapStatus = readStringValue(nodeObj?.worktreeBootstrap?.status);
|
|
41807
|
+
if (bootstrapStatus === "running") {
|
|
41808
|
+
return {
|
|
41809
|
+
success: true,
|
|
41810
|
+
...agentResult,
|
|
41811
|
+
dispatchAcknowledgementRisk: true,
|
|
41812
|
+
dispatchAcknowledgementRiskReason: "bootstrap_still_running",
|
|
41813
|
+
nextAction: "Wait for worktree_bootstrap_complete event before dispatching work to this node."
|
|
41814
|
+
};
|
|
41815
|
+
}
|
|
41816
|
+
} catch {
|
|
41817
|
+
}
|
|
41818
|
+
}
|
|
41819
|
+
return agentResult;
|
|
41820
|
+
},
|
|
41821
|
+
// ─── Logs ───
|
|
41822
|
+
list_saved_sessions: async (ctx, args) => {
|
|
41823
|
+
const providerType = typeof args?.providerType === "string" ? args.providerType.trim() : typeof args?.agentType === "string" ? args.agentType.trim() : "";
|
|
41824
|
+
const kind = args?.kind === "acp" ? "acp" : "cli";
|
|
41825
|
+
if (!providerType) {
|
|
41826
|
+
return { success: false, error: "providerType required" };
|
|
41827
|
+
}
|
|
41828
|
+
const wantsAll = args?.all === true;
|
|
41829
|
+
const offset = wantsAll ? 0 : Math.max(0, Number(args?.offset) || 0);
|
|
41830
|
+
const limit = wantsAll ? Number.MAX_SAFE_INTEGER : Math.max(1, Math.min(100, Number(args?.limit) || 30));
|
|
41831
|
+
const requestedWorkspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
|
|
41832
|
+
const requestedProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : typeof args?.activeProviderSessionId === "string" ? args.activeProviderSessionId.trim() : "";
|
|
41833
|
+
const providerMeta = ctx.deps.providerLoader.resolve?.(providerType) || ctx.deps.providerLoader.getMeta(providerType);
|
|
41834
|
+
const { sessions: historySessions, hasMore, source } = listProviderHistorySessions(providerType, {
|
|
41835
|
+
canonicalHistory: providerMeta?.nativeHistory,
|
|
41836
|
+
offset,
|
|
41837
|
+
limit,
|
|
41838
|
+
historyBehavior: providerMeta?.historyBehavior,
|
|
41839
|
+
scripts: providerMeta?.scripts
|
|
41840
|
+
});
|
|
41841
|
+
const state = loadState();
|
|
41842
|
+
const savedSessions = getSavedProviderSessions(state, { providerType, kind });
|
|
41843
|
+
const recentSessions = getRecentActivity(state, 200).filter((entry) => entry.providerType === providerType && entry.kind === kind && entry.providerSessionId);
|
|
41844
|
+
const savedSessionById = new Map(savedSessions.map((entry) => [entry.providerSessionId, entry]));
|
|
41845
|
+
const recentSessionById = new Map(recentSessions.map((entry) => [entry.providerSessionId, entry]));
|
|
41846
|
+
const canResumeById = supportsExplicitSessionResume(providerMeta?.resume);
|
|
41847
|
+
return {
|
|
41848
|
+
success: true,
|
|
41849
|
+
sessions: historySessions.map((session) => {
|
|
41850
|
+
const saved = savedSessionById.get(session.historySessionId);
|
|
41851
|
+
const recent = recentSessionById.get(session.historySessionId);
|
|
41852
|
+
const workspace = saved?.workspace || recent?.workspace || session.workspace || (requestedWorkspace && requestedProviderSessionId === session.historySessionId ? requestedWorkspace : void 0);
|
|
41853
|
+
return {
|
|
41854
|
+
id: session.historySessionId,
|
|
41855
|
+
providerSessionId: session.historySessionId,
|
|
41856
|
+
providerType,
|
|
41857
|
+
providerName: saved?.providerName || recent?.providerName || providerType,
|
|
41858
|
+
kind: saved?.kind || recent?.kind || kind,
|
|
41859
|
+
title: saved?.title || recent?.title || session.sessionTitle || session.preview || providerType,
|
|
41860
|
+
workspace,
|
|
41861
|
+
summaryMetadata: saved?.summaryMetadata || recent?.summaryMetadata,
|
|
41862
|
+
preview: session.preview,
|
|
41863
|
+
messageCount: session.messageCount,
|
|
41864
|
+
firstMessageAt: session.firstMessageAt,
|
|
41865
|
+
lastMessageAt: session.lastMessageAt,
|
|
41866
|
+
canResume: !!workspace && canResumeById,
|
|
41867
|
+
historySource: session.source,
|
|
41868
|
+
sourcePath: session.sourcePath,
|
|
41869
|
+
sourceMtimeMs: session.sourceMtimeMs
|
|
41870
|
+
};
|
|
41871
|
+
}),
|
|
41872
|
+
hasMore,
|
|
41873
|
+
source
|
|
41874
|
+
};
|
|
41875
|
+
},
|
|
41876
|
+
// ─── restart_session: IDE / CLI / ACP unified ───
|
|
41877
|
+
restart_session: async (ctx, args) => {
|
|
41878
|
+
const targetType = args?.cliType || args?.agentType || args?.ideType;
|
|
41879
|
+
if (!targetType) throw new Error("cliType or ideType required");
|
|
41880
|
+
const isIde = ctx.deps.cdpManagers.has(targetType) || ctx.deps.providerLoader.getMeta(targetType)?.category === "ide";
|
|
41881
|
+
if (isIde) {
|
|
41882
|
+
await ctx.stopIde(targetType, true);
|
|
41883
|
+
const launchResult = await ctx.launchIde({ ideType: targetType, enableCdp: true, workspace: args?.workspace });
|
|
41884
|
+
return { success: true, restarted: true, ideType: targetType, launch: launchResult };
|
|
41885
|
+
}
|
|
41886
|
+
return ctx.deps.cliManager.handleCliCommand("restart_session", args);
|
|
41887
|
+
}
|
|
41888
|
+
};
|
|
41889
|
+
|
|
41693
41890
|
// src/launch.ts
|
|
41694
41891
|
import { exec as exec4, spawn as spawn3 } from "child_process";
|
|
41695
41892
|
import * as net from "net";
|
|
@@ -45515,12 +45712,1342 @@ function getAvailableIdeIds() {
|
|
|
45515
45712
|
return getProviderLoader().getAvailableIdeTypes();
|
|
45516
45713
|
}
|
|
45517
45714
|
|
|
45518
|
-
// src/commands/
|
|
45715
|
+
// src/commands/med-family/ide.ts
|
|
45519
45716
|
init_config();
|
|
45520
45717
|
init_state_store();
|
|
45521
45718
|
init_workspaces();
|
|
45522
45719
|
init_recent_activity();
|
|
45523
45720
|
init_cli_detector();
|
|
45721
|
+
init_logger();
|
|
45722
|
+
async function launchIde(ctx, args) {
|
|
45723
|
+
const ideKey = args?.ideId || args?.ideType;
|
|
45724
|
+
const resolvedWorkspace = resolveIdeLaunchWorkspace(
|
|
45725
|
+
{
|
|
45726
|
+
workspace: args?.workspace,
|
|
45727
|
+
workspaceId: args?.workspaceId,
|
|
45728
|
+
useDefaultWorkspace: args?.useDefaultWorkspace
|
|
45729
|
+
},
|
|
45730
|
+
loadConfig()
|
|
45731
|
+
);
|
|
45732
|
+
const launchArgs = {
|
|
45733
|
+
ideId: ideKey,
|
|
45734
|
+
workspace: resolvedWorkspace,
|
|
45735
|
+
newWindow: args?.newWindow
|
|
45736
|
+
};
|
|
45737
|
+
LOG.info("LaunchIDE", `target=${ideKey || "auto"}`);
|
|
45738
|
+
const result = await launchWithCdp(launchArgs);
|
|
45739
|
+
if (result.success && result.port && result.ideId && !ctx.deps.cdpManagers.has(result.ideId)) {
|
|
45740
|
+
const logFn = ctx.deps.getCdpLogFn ? ctx.deps.getCdpLogFn(result.ideId) : LOG.forComponent(`CDP:${result.ideId}`).asLogFn();
|
|
45741
|
+
const provider = ctx.deps.providerLoader.getMeta(result.ideId);
|
|
45742
|
+
const manager = new DaemonCdpManager(result.port, logFn, void 0, provider?.targetFilter);
|
|
45743
|
+
const connected = await manager.connect();
|
|
45744
|
+
if (connected) {
|
|
45745
|
+
registerExtensionProviders(ctx.deps.providerLoader, manager, result.ideId);
|
|
45746
|
+
ctx.deps.cdpManagers.set(result.ideId, manager);
|
|
45747
|
+
LOG.info("CDP", `Connected: ${result.ideId} (port ${result.port})`);
|
|
45748
|
+
LOG.info("CDP", `${ctx.deps.cdpManagers.size} IDE(s) connected`);
|
|
45749
|
+
ctx.deps.onCdpManagerCreated?.(result.ideId, manager);
|
|
45750
|
+
}
|
|
45751
|
+
}
|
|
45752
|
+
ctx.deps.onIdeConnected?.();
|
|
45753
|
+
try {
|
|
45754
|
+
const results = await detectIDEs(ctx.deps.providerLoader);
|
|
45755
|
+
ctx.deps.detectedIdes.value = results;
|
|
45756
|
+
ctx.deps.providerLoader.setIdeDetectionResults(results, true);
|
|
45757
|
+
} catch {
|
|
45758
|
+
}
|
|
45759
|
+
if (result.success && resolvedWorkspace) {
|
|
45760
|
+
try {
|
|
45761
|
+
const next = appendRecentActivity(loadState(), {
|
|
45762
|
+
kind: "ide",
|
|
45763
|
+
providerType: result.ideId || ideKey,
|
|
45764
|
+
providerName: result.ideId || ideKey,
|
|
45765
|
+
workspace: resolvedWorkspace,
|
|
45766
|
+
title: result.ideId || ideKey
|
|
45767
|
+
});
|
|
45768
|
+
saveState(next);
|
|
45769
|
+
} catch {
|
|
45770
|
+
}
|
|
45771
|
+
} else if (result.success && (result.ideId || ideKey)) {
|
|
45772
|
+
try {
|
|
45773
|
+
saveState(appendRecentActivity(loadState(), {
|
|
45774
|
+
kind: "ide",
|
|
45775
|
+
providerType: result.ideId || ideKey,
|
|
45776
|
+
providerName: result.ideId || ideKey,
|
|
45777
|
+
title: result.ideId || ideKey
|
|
45778
|
+
}));
|
|
45779
|
+
} catch {
|
|
45780
|
+
}
|
|
45781
|
+
}
|
|
45782
|
+
return { ...result };
|
|
45783
|
+
}
|
|
45784
|
+
var ideHandlers = {
|
|
45785
|
+
// ─── IDE stop ───
|
|
45786
|
+
stop_ide: async (ctx, args) => {
|
|
45787
|
+
const ideType = args?.ideType;
|
|
45788
|
+
if (!ideType) throw new Error("ideType required");
|
|
45789
|
+
const killProcess = args?.killProcess !== false;
|
|
45790
|
+
await ctx.stopIde(ideType, killProcess);
|
|
45791
|
+
try {
|
|
45792
|
+
const results = await detectIDEs(ctx.deps.providerLoader);
|
|
45793
|
+
ctx.deps.detectedIdes.value = results;
|
|
45794
|
+
ctx.deps.providerLoader.setIdeDetectionResults(results, true);
|
|
45795
|
+
} catch {
|
|
45796
|
+
}
|
|
45797
|
+
return { success: true, ideType, stopped: true, processKilled: killProcess };
|
|
45798
|
+
},
|
|
45799
|
+
// ─── IDE restart ───
|
|
45800
|
+
restart_ide: async (ctx, args) => {
|
|
45801
|
+
const ideType = args?.ideType;
|
|
45802
|
+
if (!ideType) throw new Error("ideType required");
|
|
45803
|
+
await ctx.stopIde(ideType, true);
|
|
45804
|
+
const launchResult = await ctx.launchIde({ ideType, enableCdp: true, workspace: args?.workspace });
|
|
45805
|
+
return { success: true, ideType, restarted: true, launch: launchResult };
|
|
45806
|
+
},
|
|
45807
|
+
// ─── IDE launch + CDP connect ───
|
|
45808
|
+
launch_ide: async (ctx, args) => {
|
|
45809
|
+
return launchIde(ctx, args);
|
|
45810
|
+
},
|
|
45811
|
+
// ─── Detect providers ───
|
|
45812
|
+
detect_provider: async (ctx, args) => {
|
|
45813
|
+
const providerType = typeof args?.providerType === "string" ? args.providerType.trim() : "";
|
|
45814
|
+
if (!providerType) return { success: false, error: "providerType is required" };
|
|
45815
|
+
const normalizedType = ctx.deps.providerLoader.resolveAlias(providerType);
|
|
45816
|
+
const provider = ctx.deps.providerLoader.getByAlias(providerType);
|
|
45817
|
+
if (!provider) return { success: false, error: `Provider not found: ${providerType}` };
|
|
45818
|
+
if (provider.category !== "cli" && provider.category !== "acp") {
|
|
45819
|
+
return { success: false, error: `Provider detection is only supported for CLI/ACP providers: ${providerType}` };
|
|
45820
|
+
}
|
|
45821
|
+
if (!ctx.deps.providerLoader.isMachineProviderEnabled(normalizedType)) {
|
|
45822
|
+
return { success: false, error: `Provider is disabled on this machine: ${providerType}` };
|
|
45823
|
+
}
|
|
45824
|
+
const detected = await detectCLI(normalizedType, ctx.deps.providerLoader, { includeVersion: false });
|
|
45825
|
+
ctx.deps.providerLoader.setCliDetectionResults([{
|
|
45826
|
+
id: normalizedType,
|
|
45827
|
+
installed: !!detected,
|
|
45828
|
+
path: detected?.path
|
|
45829
|
+
}], false);
|
|
45830
|
+
ctx.deps.onStatusChange?.();
|
|
45831
|
+
return {
|
|
45832
|
+
success: true,
|
|
45833
|
+
providerType: normalizedType,
|
|
45834
|
+
detected: !!detected,
|
|
45835
|
+
path: detected?.path || null
|
|
45836
|
+
};
|
|
45837
|
+
},
|
|
45838
|
+
// ─── Detect IDEs ───
|
|
45839
|
+
detect_ides: async (ctx, _args) => {
|
|
45840
|
+
const results = await detectIDEs(ctx.deps.providerLoader);
|
|
45841
|
+
ctx.deps.detectedIdes.value = results;
|
|
45842
|
+
ctx.deps.providerLoader.setIdeDetectionResults(results, true);
|
|
45843
|
+
return { success: true, detectedInfo: results };
|
|
45844
|
+
}
|
|
45845
|
+
};
|
|
45846
|
+
|
|
45847
|
+
// src/commands/med-family/mesh-crud.ts
|
|
45848
|
+
init_dist();
|
|
45849
|
+
init_mesh_host_ownership();
|
|
45850
|
+
init_mesh_events();
|
|
45851
|
+
init_config();
|
|
45852
|
+
var meshCrudHandlers = {
|
|
45853
|
+
list_meshes: async (_ctx, _args) => {
|
|
45854
|
+
try {
|
|
45855
|
+
const { listMeshes: listMeshes2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
45856
|
+
return { success: true, meshes: listMeshes2() };
|
|
45857
|
+
} catch (e) {
|
|
45858
|
+
return { success: false, error: e.message };
|
|
45859
|
+
}
|
|
45860
|
+
},
|
|
45861
|
+
get_mesh: async (ctx, args) => {
|
|
45862
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
45863
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
45864
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
45865
|
+
if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
|
|
45866
|
+
const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
|
|
45867
|
+
const probeRemotePeers = args?.refresh === true || args?.forceRefresh === true;
|
|
45868
|
+
const directTruth = await hydrateInlineMeshDirectTruth({
|
|
45869
|
+
mesh: meshRecord.mesh,
|
|
45870
|
+
meshSource: meshRecord.source,
|
|
45871
|
+
dispatchMeshCommand: ctx.deps.dispatchMeshCommand,
|
|
45872
|
+
getMeshPeerConnectionStatus: ctx.deps.getMeshPeerConnectionStatus,
|
|
45873
|
+
statusInstanceId: ctx.deps.statusInstanceId,
|
|
45874
|
+
localMachineId: loadConfig().machineId || "",
|
|
45875
|
+
probeRemotePeers,
|
|
45876
|
+
probeCache: ctx.meshGitProbeCache
|
|
45877
|
+
});
|
|
45878
|
+
const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
|
|
45879
|
+
const sourceOfTruth = {
|
|
45880
|
+
membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
|
|
45881
|
+
coordinatorOwnsLiveTruth: directTruthSatisfied,
|
|
45882
|
+
directPeerTruth: {
|
|
45883
|
+
required: requireDirectPeerTruth,
|
|
45884
|
+
satisfied: directTruthSatisfied,
|
|
45885
|
+
directEvidenceCount: directTruth.directEvidenceCount,
|
|
45886
|
+
localConfirmedCount: directTruth.localConfirmedCount,
|
|
45887
|
+
peerAttemptedCount: directTruth.peerAttemptedCount,
|
|
45888
|
+
peerConfirmedCount: directTruth.peerConfirmedCount,
|
|
45889
|
+
unavailableNodeIds: directTruth.unavailableNodeIds
|
|
45890
|
+
}
|
|
45891
|
+
};
|
|
45892
|
+
if (requireDirectPeerTruth && !directTruthSatisfied) {
|
|
45893
|
+
return {
|
|
45894
|
+
success: false,
|
|
45895
|
+
code: "mesh_direct_peer_truth_unavailable",
|
|
45896
|
+
error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
|
|
45897
|
+
sourceOfTruth
|
|
45898
|
+
};
|
|
45899
|
+
}
|
|
45900
|
+
return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
|
|
45901
|
+
},
|
|
45902
|
+
create_mesh: async (_ctx, args) => {
|
|
45903
|
+
const name = typeof args?.name === "string" ? args.name.trim() : "";
|
|
45904
|
+
const repoIdentity = typeof args?.repoIdentity === "string" ? args.repoIdentity.trim() : "";
|
|
45905
|
+
const repoRemoteUrl = typeof args?.repoRemoteUrl === "string" ? args.repoRemoteUrl.trim() : void 0;
|
|
45906
|
+
const defaultBranch = typeof args?.defaultBranch === "string" ? args.defaultBranch.trim() : void 0;
|
|
45907
|
+
if (!name) return { success: false, error: "name required" };
|
|
45908
|
+
try {
|
|
45909
|
+
const { createMesh: createMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
45910
|
+
const meshHost = args?.meshHost && typeof args.meshHost === "object" && !Array.isArray(args.meshHost) ? args.meshHost : void 0;
|
|
45911
|
+
const mesh = createMesh2({ name, repoIdentity, repoRemoteUrl, defaultBranch, policy: args?.policy, meshHost });
|
|
45912
|
+
return { success: true, mesh };
|
|
45913
|
+
} catch (e) {
|
|
45914
|
+
return { success: false, error: e.message };
|
|
45915
|
+
}
|
|
45916
|
+
},
|
|
45917
|
+
update_mesh: async (ctx, args) => {
|
|
45918
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
45919
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
45920
|
+
try {
|
|
45921
|
+
const { updateMesh: updateMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
45922
|
+
const patch = {};
|
|
45923
|
+
if (typeof args?.name === "string") patch.name = args.name;
|
|
45924
|
+
if (typeof args?.defaultBranch === "string") patch.defaultBranch = args.defaultBranch;
|
|
45925
|
+
if (args?.policy && typeof args.policy === "object" && !Array.isArray(args.policy)) patch.policy = args.policy;
|
|
45926
|
+
if (args?.coordinator && typeof args.coordinator === "object" && !Array.isArray(args.coordinator)) patch.coordinator = args.coordinator;
|
|
45927
|
+
if (args?.meshHost && typeof args.meshHost === "object" && !Array.isArray(args.meshHost)) patch.meshHost = args.meshHost;
|
|
45928
|
+
if (!Object.keys(patch).length) return { success: false, error: "No updates provided" };
|
|
45929
|
+
const mesh = updateMesh2(meshId, patch);
|
|
45930
|
+
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
45931
|
+
ctx.inlineMeshCache.set(meshId, mesh);
|
|
45932
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
45933
|
+
return { success: true, mesh };
|
|
45934
|
+
} catch (e) {
|
|
45935
|
+
return { success: false, error: e.message };
|
|
45936
|
+
}
|
|
45937
|
+
},
|
|
45938
|
+
delete_mesh: async (_ctx, args) => {
|
|
45939
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
45940
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
45941
|
+
try {
|
|
45942
|
+
const { deleteMesh: deleteMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
45943
|
+
const deleted = deleteMesh2(meshId);
|
|
45944
|
+
return { success: true, deleted };
|
|
45945
|
+
} catch (e) {
|
|
45946
|
+
return { success: false, error: e.message };
|
|
45947
|
+
}
|
|
45948
|
+
},
|
|
45949
|
+
add_mesh_node: async (ctx, args) => {
|
|
45950
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
45951
|
+
const workspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
|
|
45952
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
45953
|
+
if (!workspace) return { success: false, error: "workspace required" };
|
|
45954
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "node addition");
|
|
45955
|
+
if (ownerFailure) return ownerFailure;
|
|
45956
|
+
try {
|
|
45957
|
+
const { addNode: addNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
45958
|
+
const providerPriority = Array.isArray(args?.providerPriority) ? args.providerPriority.map((type) => typeof type === "string" ? type.trim() : "").filter(Boolean) : [];
|
|
45959
|
+
const readOnly = args?.readOnly === true;
|
|
45960
|
+
const providerRoles = normalizeProviderRoles(args?.providerRoles);
|
|
45961
|
+
const policy = {
|
|
45962
|
+
...readOnly ? { readOnly: true } : {},
|
|
45963
|
+
...providerPriority.length ? { providerPriority } : {},
|
|
45964
|
+
...providerRoles.length ? { providerRoles } : {}
|
|
45965
|
+
};
|
|
45966
|
+
const role = normalizeMeshDaemonRole(args?.role);
|
|
45967
|
+
const daemonId = typeof args?.daemonId === "string" && args.daemonId.trim() ? args.daemonId.trim() : void 0;
|
|
45968
|
+
const machineId = typeof args?.machineId === "string" && args.machineId.trim() ? args.machineId.trim() : void 0;
|
|
45969
|
+
const repoRoot = typeof args?.repoRoot === "string" && args.repoRoot.trim() ? args.repoRoot.trim() : void 0;
|
|
45970
|
+
const node = addNode2(meshId, {
|
|
45971
|
+
workspace,
|
|
45972
|
+
...repoRoot ? { repoRoot } : {},
|
|
45973
|
+
...daemonId ? { daemonId } : {},
|
|
45974
|
+
...machineId ? { machineId } : {},
|
|
45975
|
+
...policy ? { policy } : {},
|
|
45976
|
+
...role ? { role } : {}
|
|
45977
|
+
});
|
|
45978
|
+
if (!node) return { success: false, error: "Mesh not found" };
|
|
45979
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
45980
|
+
return { success: true, node };
|
|
45981
|
+
} catch (e) {
|
|
45982
|
+
return { success: false, error: e.message };
|
|
45983
|
+
}
|
|
45984
|
+
},
|
|
45985
|
+
update_mesh_node: async (ctx, args) => {
|
|
45986
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
45987
|
+
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
45988
|
+
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
45989
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "node update");
|
|
45990
|
+
if (ownerFailure) return ownerFailure;
|
|
45991
|
+
try {
|
|
45992
|
+
const { updateNode: updateNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
45993
|
+
const policy = args?.policy && typeof args.policy === "object" && !Array.isArray(args.policy) ? { ...args.policy } : {};
|
|
45994
|
+
if (Array.isArray(args?.providerPriority)) {
|
|
45995
|
+
const providerPriority = args.providerPriority.map((type) => typeof type === "string" ? type.trim() : "").filter(Boolean);
|
|
45996
|
+
delete policy.provider_priority;
|
|
45997
|
+
if (providerPriority.length) {
|
|
45998
|
+
policy.providerPriority = providerPriority;
|
|
45999
|
+
} else {
|
|
46000
|
+
delete policy.providerPriority;
|
|
46001
|
+
}
|
|
46002
|
+
}
|
|
46003
|
+
if (Array.isArray(args?.providerRoles)) {
|
|
46004
|
+
const providerRoles = normalizeProviderRoles(args.providerRoles);
|
|
46005
|
+
if (providerRoles.length) {
|
|
46006
|
+
policy.providerRoles = providerRoles;
|
|
46007
|
+
} else {
|
|
46008
|
+
delete policy.providerRoles;
|
|
46009
|
+
}
|
|
46010
|
+
}
|
|
46011
|
+
const patch = { policy };
|
|
46012
|
+
if (typeof args?.systemPrompt === "string") {
|
|
46013
|
+
const trimmed = args.systemPrompt.trim();
|
|
46014
|
+
patch.systemPrompt = trimmed || void 0;
|
|
46015
|
+
} else if (args?.systemPrompt === null) {
|
|
46016
|
+
patch.systemPrompt = void 0;
|
|
46017
|
+
}
|
|
46018
|
+
const node = updateNode2(meshId, nodeId, patch);
|
|
46019
|
+
if (!node) return { success: false, error: "Mesh node not found" };
|
|
46020
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
46021
|
+
return { success: true, node };
|
|
46022
|
+
} catch (e) {
|
|
46023
|
+
return { success: false, error: e.message };
|
|
46024
|
+
}
|
|
46025
|
+
},
|
|
46026
|
+
cleanup_mesh_sessions: async (ctx, args) => {
|
|
46027
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46028
|
+
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
46029
|
+
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
46030
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "node removal");
|
|
46031
|
+
if (ownerFailure) return ownerFailure;
|
|
46032
|
+
try {
|
|
46033
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46034
|
+
const mesh = meshRecord?.mesh;
|
|
46035
|
+
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
46036
|
+
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
46037
|
+
if (!node) return { success: false, error: `Node '${nodeId}' not found in mesh` };
|
|
46038
|
+
const mode = ctx.normalizeMeshSessionCleanupMode(args?.mode ?? mesh?.policy?.sessionCleanupOnNodeRemove);
|
|
46039
|
+
const sessionIds = Array.isArray(args?.sessionIds) ? args.sessionIds.map((id) => typeof id === "string" ? id.trim() : "").filter(Boolean) : void 0;
|
|
46040
|
+
const result = await ctx.cleanupMeshSessions({
|
|
46041
|
+
meshId,
|
|
46042
|
+
nodeId,
|
|
46043
|
+
node,
|
|
46044
|
+
mode,
|
|
46045
|
+
sessionIds,
|
|
46046
|
+
dryRun: args?.dryRun === true,
|
|
46047
|
+
source: "mesh_cleanup_sessions"
|
|
46048
|
+
});
|
|
46049
|
+
return result;
|
|
46050
|
+
} catch (e) {
|
|
46051
|
+
return { success: false, error: e.message };
|
|
46052
|
+
}
|
|
46053
|
+
},
|
|
46054
|
+
remove_mesh_node: async (ctx, args) => {
|
|
46055
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46056
|
+
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
46057
|
+
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
46058
|
+
try {
|
|
46059
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46060
|
+
const mesh = meshRecord?.mesh;
|
|
46061
|
+
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
46062
|
+
if (node && !args?._meshDirectDispatch && node.isLocalWorktree !== true && args?.force !== true) {
|
|
46063
|
+
const nodeDaemonId = typeof node.daemonId === "string" ? node.daemonId.trim() : "";
|
|
46064
|
+
const nodeMachineId = readMeshNodeMachineId(node) || "";
|
|
46065
|
+
const selfDaemonId = ctx.deps.statusInstanceId || "";
|
|
46066
|
+
const selfMachineId = (() => {
|
|
46067
|
+
try {
|
|
46068
|
+
return loadConfig().machineId || "";
|
|
46069
|
+
} catch {
|
|
46070
|
+
return "";
|
|
46071
|
+
}
|
|
46072
|
+
})();
|
|
46073
|
+
const isCoordinatorBaseNode = !!selfDaemonId && (nodeDaemonId === selfDaemonId || nodeMachineId === selfDaemonId) || !!selfMachineId && (nodeDaemonId === selfMachineId || nodeMachineId === selfMachineId);
|
|
46074
|
+
if (isCoordinatorBaseNode) {
|
|
46075
|
+
return {
|
|
46076
|
+
success: false,
|
|
46077
|
+
removed: false,
|
|
46078
|
+
code: "mesh_remove_coordinator_base_node_protected",
|
|
46079
|
+
error: `Refusing to remove the coordinator's own base node '${typeof node.workspace === "string" ? node.workspace : nodeId}'. It is the local non-worktree node bound to this coordinator daemon; removing it breaks live mesh membership and forces a restart.`,
|
|
46080
|
+
recoveryHint: "Remove worktree clone nodes instead, or pass force:true only if you are intentionally tearing down this mesh and accept that the coordinator must be re-registered/restarted."
|
|
46081
|
+
};
|
|
46082
|
+
}
|
|
46083
|
+
}
|
|
46084
|
+
const sessionCleanupMode = ctx.normalizeMeshSessionCleanupMode(
|
|
46085
|
+
args?.sessionCleanupMode ?? args?.session_cleanup_mode ?? mesh?.policy?.sessionCleanupOnNodeRemove
|
|
46086
|
+
);
|
|
46087
|
+
const explicitSessionIds = Array.isArray(args?.sessionIds) ? args.sessionIds.filter((v) => typeof v === "string" && v.trim().length > 0).map((v) => v.trim()) : void 0;
|
|
46088
|
+
let sessionCleanup;
|
|
46089
|
+
if (node && sessionCleanupMode !== "preserve") {
|
|
46090
|
+
sessionCleanup = await ctx.cleanupMeshSessions({
|
|
46091
|
+
meshId,
|
|
46092
|
+
nodeId,
|
|
46093
|
+
node,
|
|
46094
|
+
mode: sessionCleanupMode,
|
|
46095
|
+
...explicitSessionIds && explicitSessionIds.length > 0 ? { sessionIds: explicitSessionIds } : {},
|
|
46096
|
+
source: "mesh_remove_node"
|
|
46097
|
+
});
|
|
46098
|
+
if (sessionCleanup.success === false) return { success: false, removed: false, sessionCleanup };
|
|
46099
|
+
}
|
|
46100
|
+
let worktreeCleanup;
|
|
46101
|
+
if (node?.isLocalWorktree) {
|
|
46102
|
+
const nodeDaemonId = typeof node.daemonId === "string" ? node.daemonId.trim() : void 0;
|
|
46103
|
+
const isRemoteWorktree = nodeDaemonId && !daemonIdsEquivalent(nodeDaemonId, ctx.deps.statusInstanceId) && ctx.deps.dispatchMeshCommand && !args?._meshDirectDispatch;
|
|
46104
|
+
if (isRemoteWorktree) {
|
|
46105
|
+
const forwarded = await ctx.deps.dispatchMeshCommand(nodeDaemonId, "remove_mesh_node", {
|
|
46106
|
+
...typeof args === "object" && args !== null ? args : {},
|
|
46107
|
+
_meshDirectDispatch: true
|
|
46108
|
+
});
|
|
46109
|
+
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
46110
|
+
}
|
|
46111
|
+
const cleanupResult = await ctx.cleanupLocalWorktreeNode({ mesh, node, nodeId, force: args?.force === true });
|
|
46112
|
+
if (cleanupResult.success === false) {
|
|
46113
|
+
return {
|
|
46114
|
+
success: false,
|
|
46115
|
+
removed: false,
|
|
46116
|
+
code: cleanupResult.code,
|
|
46117
|
+
error: cleanupResult.error,
|
|
46118
|
+
recoveryHint: cleanupResult.recoveryHint,
|
|
46119
|
+
...sessionCleanup ? { sessionCleanup } : {},
|
|
46120
|
+
worktreeCleanup: cleanupResult
|
|
46121
|
+
};
|
|
46122
|
+
}
|
|
46123
|
+
worktreeCleanup = cleanupResult;
|
|
46124
|
+
}
|
|
46125
|
+
let removed = false;
|
|
46126
|
+
if (meshRecord?.inline) {
|
|
46127
|
+
removed = ctx.removeInlineMeshNode(meshId, mesh, nodeId);
|
|
46128
|
+
if (removed) ctx.invalidateAggregateMeshStatus(meshId);
|
|
46129
|
+
if (!removed && !node) removed = true;
|
|
46130
|
+
} else {
|
|
46131
|
+
const { removeNode: removeNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
46132
|
+
removed = removeNode2(meshId, nodeId);
|
|
46133
|
+
if (!removed && !node) removed = true;
|
|
46134
|
+
if (removed) ctx.invalidateAggregateMeshStatus(meshId);
|
|
46135
|
+
}
|
|
46136
|
+
if (removed) {
|
|
46137
|
+
try {
|
|
46138
|
+
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
46139
|
+
appendLedgerEntry2(meshId, {
|
|
46140
|
+
kind: "node_removed",
|
|
46141
|
+
nodeId,
|
|
46142
|
+
payload: {
|
|
46143
|
+
worktree: !!node?.isLocalWorktree,
|
|
46144
|
+
sessionCleanupMode,
|
|
46145
|
+
workspace: typeof node?.workspace === "string" ? node.workspace : void 0,
|
|
46146
|
+
daemonId: typeof node?.daemonId === "string" ? node.daemonId : void 0,
|
|
46147
|
+
worktreeBranch: typeof node?.worktreeBranch === "string" ? node.worktreeBranch : void 0,
|
|
46148
|
+
worktreeCleanupFallback: typeof worktreeCleanup?.fallback === "string" ? worktreeCleanup.fallback : void 0,
|
|
46149
|
+
forced: worktreeCleanup?.forced === true ? true : void 0,
|
|
46150
|
+
forceFallbackReason: typeof worktreeCleanup?.reason === "string" ? worktreeCleanup.reason : void 0
|
|
46151
|
+
}
|
|
46152
|
+
});
|
|
46153
|
+
} catch {
|
|
46154
|
+
}
|
|
46155
|
+
}
|
|
46156
|
+
const residueWarning = worktreeCleanup?.residue === true && typeof worktreeCleanup?.residueWarning === "string" ? worktreeCleanup.residueWarning : void 0;
|
|
46157
|
+
return {
|
|
46158
|
+
success: true,
|
|
46159
|
+
removed,
|
|
46160
|
+
...residueWarning ? { residueWarning } : {},
|
|
46161
|
+
...sessionCleanup ? { sessionCleanup } : {},
|
|
46162
|
+
...worktreeCleanup ? { worktreeCleanup } : {}
|
|
46163
|
+
};
|
|
46164
|
+
} catch (e) {
|
|
46165
|
+
return { success: false, error: e.message };
|
|
46166
|
+
}
|
|
46167
|
+
},
|
|
46168
|
+
clone_mesh_node: async (ctx, args) => {
|
|
46169
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46170
|
+
const sourceNodeId = typeof args?.sourceNodeId === "string" ? args.sourceNodeId.trim() : "";
|
|
46171
|
+
const branch = typeof args?.branch === "string" ? args.branch.trim() : "";
|
|
46172
|
+
const baseBranch = typeof args?.baseBranch === "string" ? args.baseBranch.trim() : void 0;
|
|
46173
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46174
|
+
if (!sourceNodeId) return { success: false, error: "sourceNodeId required" };
|
|
46175
|
+
if (!branch) return { success: false, error: "branch required" };
|
|
46176
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "worktree clone");
|
|
46177
|
+
if (ownerFailure) return ownerFailure;
|
|
46178
|
+
try {
|
|
46179
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46180
|
+
const mesh = meshRecord?.mesh;
|
|
46181
|
+
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
46182
|
+
const sourceNode = mesh.nodes?.find((n) => meshNodeIdMatches(n, sourceNodeId));
|
|
46183
|
+
if (!sourceNode) return { success: false, error: `Source node '${sourceNodeId}' not found in mesh` };
|
|
46184
|
+
const sourceDaemonId = typeof sourceNode.daemonId === "string" ? sourceNode.daemonId.trim() : void 0;
|
|
46185
|
+
if (sourceDaemonId && !daemonIdsEquivalent(sourceDaemonId, ctx.deps.statusInstanceId) && ctx.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
|
|
46186
|
+
const forwarded = await ctx.deps.dispatchMeshCommand(sourceDaemonId, "clone_mesh_node", {
|
|
46187
|
+
...typeof args === "object" && args !== null ? args : {},
|
|
46188
|
+
_meshDirectDispatch: true
|
|
46189
|
+
});
|
|
46190
|
+
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
46191
|
+
}
|
|
46192
|
+
const repoRoot = sourceNode.repoRoot || sourceNode.workspace;
|
|
46193
|
+
const { createWorktree: createWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
46194
|
+
const result = await createWorktree2({
|
|
46195
|
+
repoRoot,
|
|
46196
|
+
branch,
|
|
46197
|
+
baseBranch,
|
|
46198
|
+
meshName: mesh.name
|
|
46199
|
+
});
|
|
46200
|
+
let node;
|
|
46201
|
+
if (meshRecord.inline) {
|
|
46202
|
+
const { randomUUID: randomUUID15 } = await import("crypto");
|
|
46203
|
+
node = {
|
|
46204
|
+
id: `node_${randomUUID15().replace(/-/g, "")}`,
|
|
46205
|
+
workspace: result.worktreePath,
|
|
46206
|
+
repoRoot: result.worktreePath,
|
|
46207
|
+
daemonId: sourceNode.daemonId,
|
|
46208
|
+
machineId: sourceNode.machineId ?? sourceNode.machine_id,
|
|
46209
|
+
userOverrides: { ...sourceNode.userOverrides || {} },
|
|
46210
|
+
policy: { ...sourceNode.policy || {} },
|
|
46211
|
+
isLocalWorktree: true,
|
|
46212
|
+
worktreeBranch: result.branch,
|
|
46213
|
+
clonedFromNodeId: sourceNodeId
|
|
46214
|
+
};
|
|
46215
|
+
ctx.updateInlineMeshNode(meshId, mesh, node);
|
|
46216
|
+
} else {
|
|
46217
|
+
const { addNode: addNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
46218
|
+
node = addNode2(meshId, {
|
|
46219
|
+
workspace: result.worktreePath,
|
|
46220
|
+
repoRoot: result.worktreePath,
|
|
46221
|
+
daemonId: sourceNode.daemonId,
|
|
46222
|
+
machineId: sourceNode.machineId ?? sourceNode.machine_id,
|
|
46223
|
+
userOverrides: { ...sourceNode.userOverrides || {} },
|
|
46224
|
+
isLocalWorktree: true,
|
|
46225
|
+
worktreeBranch: result.branch,
|
|
46226
|
+
clonedFromNodeId: sourceNodeId,
|
|
46227
|
+
policy: { ...sourceNode.policy || {} }
|
|
46228
|
+
});
|
|
46229
|
+
if (!node) return { success: false, error: "Failed to register worktree node" };
|
|
46230
|
+
const inlineForReconcile = ctx.getCachedInlineMesh(meshId);
|
|
46231
|
+
if (inlineForReconcile) ctx.updateInlineMeshNode(meshId, inlineForReconcile, node);
|
|
46232
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
46233
|
+
}
|
|
46234
|
+
const persistWorktreeSetupState = async (bootstrapState2) => {
|
|
46235
|
+
node.worktreeBootstrap = bootstrapState2;
|
|
46236
|
+
if (meshRecord.inline) {
|
|
46237
|
+
ctx.updateInlineMeshNode(meshId, mesh, node);
|
|
46238
|
+
return;
|
|
46239
|
+
}
|
|
46240
|
+
try {
|
|
46241
|
+
const { updateNode: updateNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
46242
|
+
updateNode2(meshId, node.id, { worktreeBootstrap: bootstrapState2 });
|
|
46243
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
46244
|
+
} catch {
|
|
46245
|
+
}
|
|
46246
|
+
};
|
|
46247
|
+
const appendCloneLedger = async (initSubmodules2, bootstrapState2) => {
|
|
46248
|
+
try {
|
|
46249
|
+
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
46250
|
+
appendLedgerEntry2(meshId, {
|
|
46251
|
+
kind: "node_cloned",
|
|
46252
|
+
nodeId: node.id,
|
|
46253
|
+
payload: {
|
|
46254
|
+
sourceNodeId,
|
|
46255
|
+
branch: result.branch,
|
|
46256
|
+
worktreePath: result.worktreePath,
|
|
46257
|
+
submodulesInitialized: initSubmodules2,
|
|
46258
|
+
worktreeBootstrap: {
|
|
46259
|
+
status: bootstrapState2.status,
|
|
46260
|
+
required: bootstrapState2.required,
|
|
46261
|
+
configSource: bootstrapState2.configSource,
|
|
46262
|
+
configSourceType: bootstrapState2.configSourceType,
|
|
46263
|
+
lastCommand: bootstrapState2.lastCommand,
|
|
46264
|
+
exitCode: bootstrapState2.exitCode
|
|
46265
|
+
}
|
|
46266
|
+
}
|
|
46267
|
+
});
|
|
46268
|
+
} catch {
|
|
46269
|
+
}
|
|
46270
|
+
};
|
|
46271
|
+
const initSubmodules = sourceNode.policy?.initSubmodulesOnClone !== false;
|
|
46272
|
+
const loadedBootstrap = loadMeshWorktreeBootstrapConfig(mesh, result.worktreePath);
|
|
46273
|
+
const runningBootstrapState = {
|
|
46274
|
+
status: "running",
|
|
46275
|
+
required: loadedBootstrap.config?.required !== false,
|
|
46276
|
+
configSource: loadedBootstrap.path || loadedBootstrap.source,
|
|
46277
|
+
configSourceType: loadedBootstrap.sourceType,
|
|
46278
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
46279
|
+
};
|
|
46280
|
+
await persistWorktreeSetupState(runningBootstrapState);
|
|
46281
|
+
const finishWorktreeSetup = async () => {
|
|
46282
|
+
let submodulesInitialized2 = false;
|
|
46283
|
+
if (initSubmodules) {
|
|
46284
|
+
try {
|
|
46285
|
+
const { runGit: runGit3 } = await Promise.resolve().then(() => (init_git_executor(), git_executor_exports));
|
|
46286
|
+
await runGit3(
|
|
46287
|
+
{ workspace: result.worktreePath, repoRoot: result.worktreePath, isGitRepo: true },
|
|
46288
|
+
["submodule", "update", "--init", "--recursive"],
|
|
46289
|
+
{ timeoutMs: 12e4 }
|
|
46290
|
+
);
|
|
46291
|
+
submodulesInitialized2 = true;
|
|
46292
|
+
const sourceWorkspace = sourceNode.repoRoot || sourceNode.workspace;
|
|
46293
|
+
if (sourceWorkspace) {
|
|
46294
|
+
try {
|
|
46295
|
+
const { runGit: rg } = await Promise.resolve().then(() => (init_git_executor(), git_executor_exports));
|
|
46296
|
+
const sourceCtx = { workspace: sourceWorkspace, repoRoot: sourceWorkspace, isGitRepo: true };
|
|
46297
|
+
const worktreeCtx = { workspace: result.worktreePath, repoRoot: result.worktreePath, isGitRepo: true };
|
|
46298
|
+
const sourceStatusOut = await rg(sourceCtx, ["submodule", "status", "oss"], { timeoutMs: 1e4 });
|
|
46299
|
+
const sourceStatusLine = (typeof sourceStatusOut === "string" ? sourceStatusOut : sourceStatusOut?.stdout ?? "").trim();
|
|
46300
|
+
const sourceShaMatch = sourceStatusLine.match(/^[+\- ]?([0-9a-f]{40})/);
|
|
46301
|
+
const sourceSha = sourceShaMatch?.[1];
|
|
46302
|
+
if (sourceSha) {
|
|
46303
|
+
const ossCtx = { workspace: `${result.worktreePath}/oss`, repoRoot: `${result.worktreePath}/oss`, isGitRepo: true };
|
|
46304
|
+
const worktreeOssHeadOut = await rg(ossCtx, ["rev-parse", "HEAD"], { timeoutMs: 1e4 });
|
|
46305
|
+
const worktreeOssSha = (typeof worktreeOssHeadOut === "string" ? worktreeOssHeadOut : worktreeOssHeadOut?.stdout ?? "").trim();
|
|
46306
|
+
if (worktreeOssSha !== sourceSha) {
|
|
46307
|
+
await rg(ossCtx, ["fetch", `${sourceWorkspace}/oss`, "HEAD"], { timeoutMs: 6e4 });
|
|
46308
|
+
await rg(ossCtx, ["checkout", sourceSha], { timeoutMs: 1e4 });
|
|
46309
|
+
await rg(worktreeCtx, ["add", "oss"], { timeoutMs: 1e4 });
|
|
46310
|
+
await rg(worktreeCtx, ["commit", "-m", "chore: sync oss to source node HEAD on clone"], { timeoutMs: 1e4 });
|
|
46311
|
+
console.log(`[mesh] Synced oss submodule to source HEAD ${sourceSha.slice(0, 8)} in worktree`);
|
|
46312
|
+
}
|
|
46313
|
+
}
|
|
46314
|
+
} catch (ossErr) {
|
|
46315
|
+
console.warn("[mesh] oss submodule sync to source HEAD failed (best-effort):", ossErr.message);
|
|
46316
|
+
}
|
|
46317
|
+
}
|
|
46318
|
+
} catch (subErr) {
|
|
46319
|
+
console.warn("[mesh] Submodule init failed for worktree:", subErr.message);
|
|
46320
|
+
}
|
|
46321
|
+
}
|
|
46322
|
+
const bootstrapState2 = await runMeshWorktreeBootstrap(mesh, result.worktreePath);
|
|
46323
|
+
await persistWorktreeSetupState(bootstrapState2);
|
|
46324
|
+
await appendCloneLedger(submodulesInitialized2, bootstrapState2);
|
|
46325
|
+
return { submodulesInitialized: submodulesInitialized2, bootstrapState: bootstrapState2 };
|
|
46326
|
+
};
|
|
46327
|
+
const requestedSetupWaitMs = Number(args?.setupWaitMs ?? args?.bootstrapWaitMs ?? 8e3);
|
|
46328
|
+
const setupWaitMs = Number.isFinite(requestedSetupWaitMs) ? Math.min(Math.max(requestedSetupWaitMs, 0), 14e3) : 8e3;
|
|
46329
|
+
const setupPromise = finishWorktreeSetup();
|
|
46330
|
+
const setupResult = await Promise.race([
|
|
46331
|
+
setupPromise.then((value) => ({ completed: true, value })),
|
|
46332
|
+
new Promise((resolve24) => setTimeout(() => resolve24({ completed: false }), setupWaitMs))
|
|
46333
|
+
]);
|
|
46334
|
+
const emitBootstrapEvent = (eventStatus2, bootstrapState2, startedAtMs, extraPayload) => {
|
|
46335
|
+
try {
|
|
46336
|
+
const durationMs = Date.now() - startedAtMs;
|
|
46337
|
+
const event = `worktree_${eventStatus2}`;
|
|
46338
|
+
const metadataEvent = {
|
|
46339
|
+
source: "clone_mesh_node_bootstrap",
|
|
46340
|
+
nodeId: node.id,
|
|
46341
|
+
status: eventStatus2,
|
|
46342
|
+
worktreePath: result.worktreePath,
|
|
46343
|
+
durationMs,
|
|
46344
|
+
bootstrapStatus: bootstrapState2.status,
|
|
46345
|
+
...bootstrapState2.error ? { error: bootstrapState2.error } : {},
|
|
46346
|
+
...bootstrapState2.exitCode !== void 0 ? { exitCode: bootstrapState2.exitCode } : {},
|
|
46347
|
+
...extraPayload || {}
|
|
46348
|
+
};
|
|
46349
|
+
if (typeof ctx.deps.instanceManager?.getByCategory === "function") {
|
|
46350
|
+
const forwarded = handleMeshForwardEvent(
|
|
46351
|
+
{ instanceManager: ctx.deps.instanceManager },
|
|
46352
|
+
{ event, meshId, nodeId: node.id, workspace: result.worktreePath, metadataEvent }
|
|
46353
|
+
);
|
|
46354
|
+
if (forwarded?.success === true) return;
|
|
46355
|
+
}
|
|
46356
|
+
queuePendingMeshCoordinatorEvent({
|
|
46357
|
+
event,
|
|
46358
|
+
meshId,
|
|
46359
|
+
nodeLabel: node.id,
|
|
46360
|
+
nodeId: node.id,
|
|
46361
|
+
workspace: result.worktreePath,
|
|
46362
|
+
metadataEvent,
|
|
46363
|
+
queuedAt: Date.now()
|
|
46364
|
+
});
|
|
46365
|
+
} catch {
|
|
46366
|
+
}
|
|
46367
|
+
};
|
|
46368
|
+
const bootstrapStartedMs = Date.now();
|
|
46369
|
+
if (!setupResult.completed) {
|
|
46370
|
+
setupPromise.then(({ bootstrapState: bootstrapState2 }) => {
|
|
46371
|
+
emitBootstrapEvent("bootstrap_complete", bootstrapState2, bootstrapStartedMs);
|
|
46372
|
+
}).catch((error) => {
|
|
46373
|
+
const failedState = {
|
|
46374
|
+
...runningBootstrapState,
|
|
46375
|
+
status: "failed",
|
|
46376
|
+
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
46377
|
+
error: error?.message || String(error)
|
|
46378
|
+
};
|
|
46379
|
+
void persistWorktreeSetupState(failedState);
|
|
46380
|
+
void appendCloneLedger(false, failedState);
|
|
46381
|
+
emitBootstrapEvent("bootstrap_failed", failedState, bootstrapStartedMs, { error: error?.message || String(error) });
|
|
46382
|
+
});
|
|
46383
|
+
return {
|
|
46384
|
+
success: true,
|
|
46385
|
+
async: true,
|
|
46386
|
+
status: "accepted",
|
|
46387
|
+
node,
|
|
46388
|
+
worktreePath: result.worktreePath,
|
|
46389
|
+
branch: result.branch,
|
|
46390
|
+
worktreeBootstrap: runningBootstrapState,
|
|
46391
|
+
worktreeSetup: {
|
|
46392
|
+
status: "running",
|
|
46393
|
+
setupWaitMs,
|
|
46394
|
+
message: "Worktree node is registered; submodule/bootstrap setup is continuing in the background."
|
|
46395
|
+
}
|
|
46396
|
+
};
|
|
46397
|
+
}
|
|
46398
|
+
const { submodulesInitialized, bootstrapState } = setupResult.value;
|
|
46399
|
+
emitBootstrapEvent("bootstrap_complete", bootstrapState, bootstrapStartedMs);
|
|
46400
|
+
return {
|
|
46401
|
+
success: true,
|
|
46402
|
+
node,
|
|
46403
|
+
worktreePath: result.worktreePath,
|
|
46404
|
+
branch: result.branch,
|
|
46405
|
+
submodulesInitialized,
|
|
46406
|
+
worktreeBootstrap: bootstrapState
|
|
46407
|
+
};
|
|
46408
|
+
} catch (e) {
|
|
46409
|
+
return { success: false, error: e.message };
|
|
46410
|
+
}
|
|
46411
|
+
},
|
|
46412
|
+
retry_mesh_node_bootstrap: async (ctx, args) => {
|
|
46413
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46414
|
+
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
46415
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46416
|
+
if (!nodeId) return { success: false, error: "nodeId required" };
|
|
46417
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "bootstrap retry");
|
|
46418
|
+
if (ownerFailure) return ownerFailure;
|
|
46419
|
+
try {
|
|
46420
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46421
|
+
const mesh = meshRecord?.mesh;
|
|
46422
|
+
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
46423
|
+
const node = mesh.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
46424
|
+
if (!node) return { success: false, error: `Node '${nodeId}' not found in mesh` };
|
|
46425
|
+
if (!node.isLocalWorktree) return { success: false, error: "Node is not a local worktree node" };
|
|
46426
|
+
const nodeDaemonId = typeof node.daemonId === "string" ? node.daemonId.trim() : void 0;
|
|
46427
|
+
if (nodeDaemonId && !daemonIdsEquivalent(nodeDaemonId, ctx.deps.statusInstanceId) && ctx.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
|
|
46428
|
+
const forwarded = await ctx.deps.dispatchMeshCommand(nodeDaemonId, "retry_mesh_node_bootstrap", {
|
|
46429
|
+
...typeof args === "object" && args !== null ? args : {},
|
|
46430
|
+
_meshDirectDispatch: true
|
|
46431
|
+
});
|
|
46432
|
+
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
46433
|
+
}
|
|
46434
|
+
const currentBootstrap = node.worktreeBootstrap;
|
|
46435
|
+
if (currentBootstrap?.status === "running") {
|
|
46436
|
+
return { success: false, error: "Bootstrap is already running for this node" };
|
|
46437
|
+
}
|
|
46438
|
+
const worktreePath = node.workspace || node.repoRoot;
|
|
46439
|
+
if (!worktreePath) return { success: false, error: "Node has no workspace path" };
|
|
46440
|
+
const loadedBootstrap = loadMeshWorktreeBootstrapConfig(mesh, worktreePath);
|
|
46441
|
+
const runningState = {
|
|
46442
|
+
status: "running",
|
|
46443
|
+
required: loadedBootstrap.config?.required !== false,
|
|
46444
|
+
configSource: loadedBootstrap.path || loadedBootstrap.source,
|
|
46445
|
+
configSourceType: loadedBootstrap.sourceType,
|
|
46446
|
+
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
46447
|
+
};
|
|
46448
|
+
const persistState = async (bootstrapState2) => {
|
|
46449
|
+
node.worktreeBootstrap = bootstrapState2;
|
|
46450
|
+
if (meshRecord.inline) {
|
|
46451
|
+
ctx.updateInlineMeshNode(meshId, mesh, node);
|
|
46452
|
+
return;
|
|
46453
|
+
}
|
|
46454
|
+
try {
|
|
46455
|
+
const { updateNode: updateNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
46456
|
+
updateNode2(meshId, node.id, { worktreeBootstrap: bootstrapState2 });
|
|
46457
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
46458
|
+
} catch {
|
|
46459
|
+
}
|
|
46460
|
+
};
|
|
46461
|
+
await persistState(runningState);
|
|
46462
|
+
const bootstrapState = await runMeshWorktreeBootstrap(mesh, worktreePath);
|
|
46463
|
+
await persistState(bootstrapState);
|
|
46464
|
+
return { success: true, bootstrapState };
|
|
46465
|
+
} catch (e) {
|
|
46466
|
+
return { success: false, error: e.message };
|
|
46467
|
+
}
|
|
46468
|
+
}
|
|
46469
|
+
};
|
|
46470
|
+
|
|
46471
|
+
// src/commands/med-family/mesh-host-pairing.ts
|
|
46472
|
+
init_mesh_host_ownership();
|
|
46473
|
+
var meshHostPairingHandlers = {
|
|
46474
|
+
get_mesh_host_pairing: async (ctx, args) => {
|
|
46475
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46476
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46477
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46478
|
+
const mesh = meshRecord?.mesh;
|
|
46479
|
+
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
46480
|
+
const meshHost = resolveMeshHostStatus(mesh);
|
|
46481
|
+
const pairingStatus = meshHost.pairing?.status || "not_configured";
|
|
46482
|
+
return {
|
|
46483
|
+
success: true,
|
|
46484
|
+
code: pairingStatus === "not_configured" ? "mesh_host_pairing_not_configured" : "mesh_host_pairing_pending",
|
|
46485
|
+
meshId,
|
|
46486
|
+
hostAddress: meshHost.hostAddress,
|
|
46487
|
+
meshHost,
|
|
46488
|
+
manualPairing: {
|
|
46489
|
+
status: pairingStatus,
|
|
46490
|
+
joinImplemented: true,
|
|
46491
|
+
protocol: "standalone_command_direct_v1",
|
|
46492
|
+
description: "Standalone manual pairing can save address/token metadata, apply a host join over direct standalone command HTTP or injected mesh command dispatch, and check persisted status. P2P signaling remains outside this slice."
|
|
46493
|
+
}
|
|
46494
|
+
};
|
|
46495
|
+
},
|
|
46496
|
+
configure_mesh_host_pairing: async (ctx, args) => {
|
|
46497
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46498
|
+
const hostAddress = typeof args?.hostAddress === "string" ? args.hostAddress.trim() : "";
|
|
46499
|
+
const token = typeof args?.token === "string" ? args.token.trim() : "";
|
|
46500
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46501
|
+
if (!hostAddress || !token) return { success: false, error: "hostAddress and token required" };
|
|
46502
|
+
try {
|
|
46503
|
+
const { configureMeshHostPairing: configureMeshHostPairing2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
46504
|
+
const configured = configureMeshHostPairing2(meshId, { hostAddress, token });
|
|
46505
|
+
if (!configured) return { success: false, error: "Mesh not found" };
|
|
46506
|
+
ctx.inlineMeshCache.set(meshId, configured.mesh);
|
|
46507
|
+
const meshHost = resolveMeshHostStatus(configured.mesh);
|
|
46508
|
+
return {
|
|
46509
|
+
success: true,
|
|
46510
|
+
code: "mesh_host_pairing_pending",
|
|
46511
|
+
meshId,
|
|
46512
|
+
hostAddress: configured.hostAddress,
|
|
46513
|
+
meshHost,
|
|
46514
|
+
manualPairing: {
|
|
46515
|
+
status: meshHost.pairing?.status || "pairing",
|
|
46516
|
+
joinImplemented: true,
|
|
46517
|
+
protocol: "standalone_command_direct_v1",
|
|
46518
|
+
description: "Manual Mesh Host pairing config was saved locally. Use join_mesh_host_pairing to apply it to the host. Raw token was not persisted."
|
|
46519
|
+
}
|
|
46520
|
+
};
|
|
46521
|
+
} catch (e) {
|
|
46522
|
+
return { success: false, code: "mesh_host_pairing_invalid", meshId, hostAddress, error: e.message };
|
|
46523
|
+
}
|
|
46524
|
+
},
|
|
46525
|
+
create_mesh_host_pairing_token: async (ctx, args) => {
|
|
46526
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46527
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46528
|
+
try {
|
|
46529
|
+
const { createMeshHostPairingToken: createMeshHostPairingToken2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
46530
|
+
const created = createMeshHostPairingToken2(meshId, {
|
|
46531
|
+
token: typeof args?.token === "string" ? args.token : void 0,
|
|
46532
|
+
expiresAt: typeof args?.expiresAt === "string" ? args.expiresAt : void 0
|
|
46533
|
+
});
|
|
46534
|
+
if (!created) return { success: false, error: "Mesh not found" };
|
|
46535
|
+
ctx.inlineMeshCache.set(meshId, created.mesh);
|
|
46536
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
46537
|
+
return {
|
|
46538
|
+
success: true,
|
|
46539
|
+
code: "mesh_host_pairing_token_created",
|
|
46540
|
+
meshId,
|
|
46541
|
+
token: created.token,
|
|
46542
|
+
tokenId: created.tokenId,
|
|
46543
|
+
expiresAt: created.expiresAt,
|
|
46544
|
+
meshHost: resolveMeshHostStatus(created.mesh),
|
|
46545
|
+
warning: "Raw token is returned once and is not persisted; share it with member daemons over a trusted channel."
|
|
46546
|
+
};
|
|
46547
|
+
} catch (e) {
|
|
46548
|
+
return { success: false, code: "mesh_host_pairing_token_invalid", meshId, error: e.message };
|
|
46549
|
+
}
|
|
46550
|
+
},
|
|
46551
|
+
apply_mesh_host_join: async (ctx, args) => {
|
|
46552
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46553
|
+
const token = typeof args?.token === "string" ? args.token.trim() : "";
|
|
46554
|
+
const memberNode = args?.memberNode && typeof args.memberNode === "object" && !Array.isArray(args.memberNode) ? args.memberNode : null;
|
|
46555
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46556
|
+
if (!token || !memberNode) return { success: false, error: "token and memberNode required" };
|
|
46557
|
+
try {
|
|
46558
|
+
const { applyMeshHostJoinRequest: applyMeshHostJoinRequest2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
46559
|
+
const applied = applyMeshHostJoinRequest2(meshId, {
|
|
46560
|
+
token,
|
|
46561
|
+
memberNode,
|
|
46562
|
+
memberMeshId: typeof args?.memberMeshId === "string" ? args.memberMeshId : void 0
|
|
46563
|
+
});
|
|
46564
|
+
if (!applied) return { success: false, error: "Mesh not found" };
|
|
46565
|
+
if (!applied.accepted) {
|
|
46566
|
+
return {
|
|
46567
|
+
success: false,
|
|
46568
|
+
code: "mesh_host_join_rejected",
|
|
46569
|
+
meshId,
|
|
46570
|
+
tokenId: applied.tokenId,
|
|
46571
|
+
meshHost: applied.meshHost ? resolveMeshHostStatus({ meshHost: applied.meshHost }) : void 0,
|
|
46572
|
+
error: applied.reason
|
|
46573
|
+
};
|
|
46574
|
+
}
|
|
46575
|
+
ctx.inlineMeshCache.set(meshId, applied.mesh);
|
|
46576
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
46577
|
+
try {
|
|
46578
|
+
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
46579
|
+
appendLedgerEntry2(meshId, {
|
|
46580
|
+
kind: "node_joined",
|
|
46581
|
+
nodeId: applied.node.id,
|
|
46582
|
+
payload: { role: "member", tokenId: applied.tokenId, workspace: applied.node.workspace }
|
|
46583
|
+
});
|
|
46584
|
+
} catch {
|
|
46585
|
+
}
|
|
46586
|
+
return {
|
|
46587
|
+
success: true,
|
|
46588
|
+
code: "mesh_host_join_accepted",
|
|
46589
|
+
meshId,
|
|
46590
|
+
node: applied.node,
|
|
46591
|
+
tokenId: applied.tokenId,
|
|
46592
|
+
meshHost: resolveMeshHostStatus(applied.mesh)
|
|
46593
|
+
};
|
|
46594
|
+
} catch (e) {
|
|
46595
|
+
return { success: false, code: "mesh_host_join_failed", meshId, error: e.message };
|
|
46596
|
+
}
|
|
46597
|
+
},
|
|
46598
|
+
join_mesh_host_pairing: async (ctx, args) => {
|
|
46599
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46600
|
+
const token = typeof args?.token === "string" ? args.token.trim() : "";
|
|
46601
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46602
|
+
if (!token) return { success: false, error: "token required because raw pairing tokens are not persisted" };
|
|
46603
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46604
|
+
const mesh = meshRecord?.mesh;
|
|
46605
|
+
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
46606
|
+
const meshHost = resolveMeshHostStatus(mesh);
|
|
46607
|
+
if (meshHost.role !== "member") {
|
|
46608
|
+
return { success: false, code: "mesh_host_join_not_member", meshId, meshHost, error: "join_mesh_host_pairing must run from a member daemon configured with a Mesh Host address/token." };
|
|
46609
|
+
}
|
|
46610
|
+
try {
|
|
46611
|
+
const { tokenIdForManualPairing: tokenIdForManualPairing2, markMeshHostPairingJoined: markMeshHostPairingJoined2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
46612
|
+
const tokenId = tokenIdForManualPairing2(token);
|
|
46613
|
+
if (meshHost.pairing?.tokenId && meshHost.pairing.tokenId !== tokenId) {
|
|
46614
|
+
return { success: false, code: "mesh_host_join_rejected", meshId, tokenId, meshHost, error: "invalid pairing token" };
|
|
46615
|
+
}
|
|
46616
|
+
const memberNode = buildMemberJoinNode(mesh, args, ctx.deps.statusInstanceId);
|
|
46617
|
+
if (!memberNode) return { success: false, error: "member node metadata unavailable" };
|
|
46618
|
+
const hostMeshId = typeof args?.hostMeshId === "string" && args.hostMeshId.trim() ? args.hostMeshId.trim() : meshId;
|
|
46619
|
+
const hostDaemonId = typeof args?.hostDaemonId === "string" && args.hostDaemonId.trim() ? args.hostDaemonId.trim() : meshHost.hostDaemonId;
|
|
46620
|
+
let hostResult;
|
|
46621
|
+
let transport;
|
|
46622
|
+
if (hostDaemonId && ctx.deps.dispatchMeshCommand) {
|
|
46623
|
+
transport = "mesh_command_dispatch";
|
|
46624
|
+
hostResult = await ctx.deps.dispatchMeshCommand(hostDaemonId, "apply_mesh_host_join", {
|
|
46625
|
+
meshId: hostMeshId,
|
|
46626
|
+
token,
|
|
46627
|
+
memberMeshId: meshId,
|
|
46628
|
+
memberNode
|
|
46629
|
+
});
|
|
46630
|
+
} else if (meshHost.hostAddress) {
|
|
46631
|
+
transport = "standalone_http_command";
|
|
46632
|
+
const commandUrl = normalizeStandaloneHostCommandUrl(meshHost.hostAddress);
|
|
46633
|
+
const response = await fetch(commandUrl, {
|
|
46634
|
+
method: "POST",
|
|
46635
|
+
headers: { "Content-Type": "application/json" },
|
|
46636
|
+
body: JSON.stringify({ type: "apply_mesh_host_join", payload: { meshId: hostMeshId, token, memberMeshId: meshId, memberNode } })
|
|
46637
|
+
});
|
|
46638
|
+
hostResult = await response.json().catch(() => ({ success: false, error: `Host returned HTTP ${response.status}` }));
|
|
46639
|
+
if (!response.ok && hostResult?.success !== false) hostResult = { success: false, error: `Host returned HTTP ${response.status}` };
|
|
46640
|
+
} else {
|
|
46641
|
+
return {
|
|
46642
|
+
success: false,
|
|
46643
|
+
code: "mesh_host_join_transport_unavailable",
|
|
46644
|
+
meshId,
|
|
46645
|
+
meshHost,
|
|
46646
|
+
error: "No hostDaemonId dispatch path or hostAddress HTTP command path is available. P2P signaling join is not implemented in this slice."
|
|
46647
|
+
};
|
|
46648
|
+
}
|
|
46649
|
+
if (!hostResult?.success) {
|
|
46650
|
+
return { success: false, code: hostResult?.code || "mesh_host_join_rejected", meshId, meshHost, transport, error: hostResult?.error || "Mesh Host rejected join request", hostResult };
|
|
46651
|
+
}
|
|
46652
|
+
const joined = meshRecord.inline ? null : markMeshHostPairingJoined2(meshId, {
|
|
46653
|
+
tokenId: hostResult.tokenId || tokenId,
|
|
46654
|
+
hostDaemonId: hostResult.meshHost?.hostDaemonId || hostDaemonId,
|
|
46655
|
+
hostNodeId: hostResult.meshHost?.hostNodeId,
|
|
46656
|
+
joinedAt: hostResult.meshHost?.pairing?.joinedAt
|
|
46657
|
+
});
|
|
46658
|
+
if (joined) {
|
|
46659
|
+
ctx.inlineMeshCache.set(meshId, joined.mesh);
|
|
46660
|
+
ctx.invalidateAggregateMeshStatus(meshId);
|
|
46661
|
+
}
|
|
46662
|
+
return {
|
|
46663
|
+
success: true,
|
|
46664
|
+
code: "mesh_host_join_applied",
|
|
46665
|
+
meshId,
|
|
46666
|
+
hostMeshId,
|
|
46667
|
+
transport,
|
|
46668
|
+
node: hostResult.node,
|
|
46669
|
+
tokenId: hostResult.tokenId || tokenId,
|
|
46670
|
+
meshHost: joined ? resolveMeshHostStatus(joined.mesh) : { ...meshHost, pairing: { ...meshHost.pairing || {}, status: "paired", tokenId: hostResult.tokenId || tokenId } },
|
|
46671
|
+
hostResult,
|
|
46672
|
+
manualPairing: {
|
|
46673
|
+
status: "paired",
|
|
46674
|
+
joinImplemented: true,
|
|
46675
|
+
protocol: "standalone_command_direct_v1",
|
|
46676
|
+
description: "Mesh Host accepted the join and local member pairing status was marked paired. P2P runtime signaling remains outside this slice."
|
|
46677
|
+
}
|
|
46678
|
+
};
|
|
46679
|
+
} catch (e) {
|
|
46680
|
+
return { success: false, code: "mesh_host_join_failed", meshId, meshHost, error: e.message };
|
|
46681
|
+
}
|
|
46682
|
+
}
|
|
46683
|
+
};
|
|
46684
|
+
|
|
46685
|
+
// src/commands/med-family/mesh-queue.ts
|
|
46686
|
+
var meshQueueHandlers = {
|
|
46687
|
+
get_mesh_queue: async (_ctx, args) => {
|
|
46688
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46689
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46690
|
+
try {
|
|
46691
|
+
const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2, describeTaskDependencyState: describeTaskDependencyState2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
46692
|
+
const status = Array.isArray(args?.status) ? args.status.map((s2) => typeof s2 === "string" ? s2.trim() : "").filter(Boolean) : void 0;
|
|
46693
|
+
const rawQueue = getQueue2(meshId, { status });
|
|
46694
|
+
const statusById = new Map(getQueue2(meshId).map((task) => [task.id, task.status]));
|
|
46695
|
+
const queue = rawQueue.map((task) => Array.isArray(task.dependsOn) && task.dependsOn.length > 0 ? { ...task, ...describeTaskDependencyState2(task, statusById) } : task);
|
|
46696
|
+
const summary = getMeshQueueStats2(meshId);
|
|
46697
|
+
return {
|
|
46698
|
+
success: true,
|
|
46699
|
+
queue,
|
|
46700
|
+
summary,
|
|
46701
|
+
sourceOfTruth: {
|
|
46702
|
+
kind: "mesh_work_queue_file",
|
|
46703
|
+
activeStatuses: ["pending", "assigned"],
|
|
46704
|
+
historicalStatuses: ["completed", "failed", "cancelled"],
|
|
46705
|
+
notes: "pending/assigned are active work; completed/failed/cancelled are historical records."
|
|
46706
|
+
}
|
|
46707
|
+
};
|
|
46708
|
+
} catch (e) {
|
|
46709
|
+
return { success: false, error: e.message };
|
|
46710
|
+
}
|
|
46711
|
+
},
|
|
46712
|
+
cancel_mesh_queue_task: async (ctx, args) => {
|
|
46713
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46714
|
+
const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
|
|
46715
|
+
if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
|
|
46716
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "queue cancellation");
|
|
46717
|
+
if (ownerFailure) return ownerFailure;
|
|
46718
|
+
try {
|
|
46719
|
+
const { cancelTask: cancelTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
46720
|
+
const reason = typeof args?.reason === "string" ? args.reason : void 0;
|
|
46721
|
+
const task = cancelTask2(meshId, taskId, { reason });
|
|
46722
|
+
if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
|
|
46723
|
+
return { success: true, task };
|
|
46724
|
+
} catch (e) {
|
|
46725
|
+
return { success: false, error: e.message };
|
|
46726
|
+
}
|
|
46727
|
+
},
|
|
46728
|
+
requeue_mesh_queue_task: async (ctx, args) => {
|
|
46729
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46730
|
+
const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
|
|
46731
|
+
if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
|
|
46732
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "queue requeue");
|
|
46733
|
+
if (ownerFailure) return ownerFailure;
|
|
46734
|
+
try {
|
|
46735
|
+
const { requeueTask: requeueTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
46736
|
+
const task = requeueTask2(meshId, taskId, {
|
|
46737
|
+
reason: typeof args?.reason === "string" ? args.reason : void 0,
|
|
46738
|
+
targetNodeId: typeof args?.targetNodeId === "string" ? args.targetNodeId.trim() : void 0,
|
|
46739
|
+
targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : void 0,
|
|
46740
|
+
clearTargetNode: args?.clearTargetNode === true,
|
|
46741
|
+
clearTargetSession: args?.clearTargetSession !== false
|
|
46742
|
+
});
|
|
46743
|
+
if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
|
|
46744
|
+
return { success: true, task };
|
|
46745
|
+
} catch (e) {
|
|
46746
|
+
return { success: false, error: e.message };
|
|
46747
|
+
}
|
|
46748
|
+
},
|
|
46749
|
+
trigger_mesh_queue: async (ctx, args) => {
|
|
46750
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46751
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
46752
|
+
const ownerFailure = await ctx.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "queue trigger");
|
|
46753
|
+
if (ownerFailure) return ownerFailure;
|
|
46754
|
+
try {
|
|
46755
|
+
const { triggerMeshQueue: triggerMeshQueue2, tryAssignQueueTask: tryAssignQueueTask2 } = await Promise.resolve().then(() => (init_mesh_events(), mesh_events_exports));
|
|
46756
|
+
const preferredNodeId = typeof args?.preferredNodeId === "string" ? args.preferredNodeId.trim() : "";
|
|
46757
|
+
if (preferredNodeId) {
|
|
46758
|
+
const cliInstances = ctx.deps.instanceManager.getByCategory("cli");
|
|
46759
|
+
const sorted = [...cliInstances].sort((a, b) => {
|
|
46760
|
+
const aSettings = a.getState().settings || {};
|
|
46761
|
+
const bSettings = b.getState().settings || {};
|
|
46762
|
+
const aNode = readStringValue(aSettings.meshNodeId, aSettings.nodeId);
|
|
46763
|
+
const bNode = readStringValue(bSettings.meshNodeId, bSettings.nodeId);
|
|
46764
|
+
return (aNode === preferredNodeId ? -1 : 0) - (bNode === preferredNodeId ? -1 : 0);
|
|
46765
|
+
});
|
|
46766
|
+
for (const inst of sorted) {
|
|
46767
|
+
const state = inst.getState();
|
|
46768
|
+
const settings = state.settings || {};
|
|
46769
|
+
const nodeId = readStringValue(settings.meshNodeId, settings.nodeId);
|
|
46770
|
+
if (!nodeId || nodeId !== preferredNodeId) continue;
|
|
46771
|
+
const meshNodeFor = readStringValue(settings.meshNodeFor);
|
|
46772
|
+
if (meshNodeFor !== meshId) continue;
|
|
46773
|
+
const status = (readStringValue(state.status) || "").toLowerCase();
|
|
46774
|
+
if (status !== "idle") continue;
|
|
46775
|
+
const sessionId = typeof state.instanceId === "string" ? state.instanceId : "";
|
|
46776
|
+
const providerType = readStringValue(state.type, settings.providerType) || "";
|
|
46777
|
+
if (sessionId && providerType) {
|
|
46778
|
+
tryAssignQueueTask2(ctx.deps, meshId, nodeId, sessionId, providerType);
|
|
46779
|
+
break;
|
|
46780
|
+
}
|
|
46781
|
+
}
|
|
46782
|
+
}
|
|
46783
|
+
const trigger = await triggerMeshQueue2(ctx.deps, meshId);
|
|
46784
|
+
return { success: true, trigger };
|
|
46785
|
+
} catch (e) {
|
|
46786
|
+
return { success: false, error: e.message };
|
|
46787
|
+
}
|
|
46788
|
+
}
|
|
46789
|
+
};
|
|
46790
|
+
|
|
46791
|
+
// src/commands/med-family/fast-forward.ts
|
|
46792
|
+
init_dist();
|
|
46793
|
+
init_mesh_fast_forward();
|
|
46794
|
+
|
|
46795
|
+
// src/mesh/mesh-init.ts
|
|
46796
|
+
import { existsSync as existsSync37, mkdirSync as mkdirSync15, writeFileSync as writeFileSync18 } from "fs";
|
|
46797
|
+
import { dirname as dirname11, join as join40 } from "path";
|
|
46798
|
+
var MESH_INIT_REFINE_CONFIG_PATH = MESH_REFINE_CONFIG_LOCATIONS[0];
|
|
46799
|
+
var MESH_INIT_WORKTREE_BOOTSTRAP_CONFIG_PATH = MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS[0];
|
|
46800
|
+
var CANDIDATE_STALE_INPUTS = [
|
|
46801
|
+
"package-lock.json",
|
|
46802
|
+
"pnpm-lock.yaml",
|
|
46803
|
+
"yarn.lock",
|
|
46804
|
+
"bun.lockb",
|
|
46805
|
+
"Cargo.lock",
|
|
46806
|
+
"go.sum",
|
|
46807
|
+
"poetry.lock",
|
|
46808
|
+
"requirements.txt"
|
|
46809
|
+
];
|
|
46810
|
+
function writeConfigFile(workspace, relativePath, config) {
|
|
46811
|
+
const target = join40(workspace, relativePath);
|
|
46812
|
+
mkdirSync15(dirname11(target), { recursive: true });
|
|
46813
|
+
writeFileSync18(target, `${JSON.stringify(config, null, 2)}
|
|
46814
|
+
`, "utf-8");
|
|
46815
|
+
return target;
|
|
46816
|
+
}
|
|
46817
|
+
function suggestMeshWorktreeBootstrapConfig(workspace) {
|
|
46818
|
+
const commands = [];
|
|
46819
|
+
const hasPackageJson = existsSync37(join40(workspace, "package.json"));
|
|
46820
|
+
const hasNpmLock = existsSync37(join40(workspace, "package-lock.json"));
|
|
46821
|
+
if (hasPackageJson) {
|
|
46822
|
+
commands.push(
|
|
46823
|
+
hasNpmLock ? { command: "npm", args: ["ci"] } : { command: "npm", args: ["install"] }
|
|
46824
|
+
);
|
|
46825
|
+
}
|
|
46826
|
+
const staleInputs = CANDIDATE_STALE_INPUTS.filter((relative5) => existsSync37(join40(workspace, relative5)));
|
|
46827
|
+
if (!commands.length) {
|
|
46828
|
+
return { commands, staleInputs };
|
|
46829
|
+
}
|
|
46830
|
+
return {
|
|
46831
|
+
commands,
|
|
46832
|
+
staleInputs,
|
|
46833
|
+
suggestedConfig: {
|
|
46834
|
+
version: 1,
|
|
46835
|
+
enabled: true,
|
|
46836
|
+
runOnClone: true,
|
|
46837
|
+
required: false,
|
|
46838
|
+
commands,
|
|
46839
|
+
...staleInputs.length ? { staleInputs } : {}
|
|
46840
|
+
}
|
|
46841
|
+
};
|
|
46842
|
+
}
|
|
46843
|
+
var PROVIDER_PRIORITY_PREFERENCE = ["claude-cli", "codex-cli", "gemini-cli"];
|
|
46844
|
+
function suggestNodeProviderPriority(detected) {
|
|
46845
|
+
const installed = detected.filter((cli) => cli.installed);
|
|
46846
|
+
const installedIds = installed.map((cli) => cli.id);
|
|
46847
|
+
const preferred = PROVIDER_PRIORITY_PREFERENCE.filter((id) => installedIds.includes(id));
|
|
46848
|
+
const rest = installedIds.filter((id) => !preferred.includes(id));
|
|
46849
|
+
const providerPriority = [...preferred, ...rest];
|
|
46850
|
+
return {
|
|
46851
|
+
providerPriority,
|
|
46852
|
+
installedProviders: installed.map((cli) => ({
|
|
46853
|
+
id: cli.id,
|
|
46854
|
+
displayName: cli.displayName,
|
|
46855
|
+
...cli.version ? { version: cli.version } : {}
|
|
46856
|
+
}))
|
|
46857
|
+
};
|
|
46858
|
+
}
|
|
46859
|
+
function runMeshInit(mesh, workspace, detected, options = {}) {
|
|
46860
|
+
const write = options.write === true;
|
|
46861
|
+
const overwrite = options.overwrite === true;
|
|
46862
|
+
const refine = applyConfigSuggestion({
|
|
46863
|
+
workspace,
|
|
46864
|
+
relativePath: MESH_INIT_REFINE_CONFIG_PATH,
|
|
46865
|
+
existing: loadMeshRefineConfig(mesh, workspace).config,
|
|
46866
|
+
suggestedConfig: suggestMeshRefineConfig(mesh, workspace).suggestedConfig,
|
|
46867
|
+
validate: (config) => validateMeshRefineConfig(config, MESH_INIT_REFINE_CONFIG_PATH).valid,
|
|
46868
|
+
write,
|
|
46869
|
+
overwrite
|
|
46870
|
+
});
|
|
46871
|
+
const bootstrapSuggestion = suggestMeshWorktreeBootstrapConfig(workspace);
|
|
46872
|
+
const worktreeBootstrap = applyConfigSuggestion({
|
|
46873
|
+
workspace,
|
|
46874
|
+
relativePath: MESH_INIT_WORKTREE_BOOTSTRAP_CONFIG_PATH,
|
|
46875
|
+
existing: loadMeshWorktreeBootstrapConfig(mesh, workspace).config,
|
|
46876
|
+
suggestedConfig: bootstrapSuggestion.suggestedConfig,
|
|
46877
|
+
validate: (config) => validateMeshWorktreeBootstrapConfig(config, MESH_INIT_WORKTREE_BOOTSTRAP_CONFIG_PATH).valid,
|
|
46878
|
+
write,
|
|
46879
|
+
overwrite
|
|
46880
|
+
});
|
|
46881
|
+
const providers = suggestNodeProviderPriority(detected);
|
|
46882
|
+
return {
|
|
46883
|
+
success: true,
|
|
46884
|
+
workspace,
|
|
46885
|
+
dryRun: !write,
|
|
46886
|
+
refine,
|
|
46887
|
+
worktreeBootstrap,
|
|
46888
|
+
providers,
|
|
46889
|
+
note: write ? "Configs written to disk are the execution source of truth; suggestions are scaffold and only take effect once saved. providerPriority is a recommendation \u2014 apply it to node policy via clone/policy update." : "Dry-run: no files written. Re-run with write=true to persist the suggested configs. Heuristic suggestions never execute until saved as repo config."
|
|
46890
|
+
};
|
|
46891
|
+
}
|
|
46892
|
+
function applyConfigSuggestion(input) {
|
|
46893
|
+
const { workspace, relativePath, existing, suggestedConfig, validate, write, overwrite } = input;
|
|
46894
|
+
const absolute = join40(workspace, relativePath);
|
|
46895
|
+
if (existing !== void 0 && !overwrite) {
|
|
46896
|
+
return { path: absolute, relativePath, written: false, skippedReason: "already_exists", config: existing };
|
|
46897
|
+
}
|
|
46898
|
+
if (!suggestedConfig || !validate(suggestedConfig)) {
|
|
46899
|
+
return { path: absolute, relativePath, written: false, skippedReason: "no_suggestion" };
|
|
46900
|
+
}
|
|
46901
|
+
if (!write) {
|
|
46902
|
+
return { path: absolute, relativePath, written: false, config: suggestedConfig };
|
|
46903
|
+
}
|
|
46904
|
+
const writtenPath = writeConfigFile(workspace, relativePath, suggestedConfig);
|
|
46905
|
+
return { path: writtenPath, relativePath, written: true, config: suggestedConfig };
|
|
46906
|
+
}
|
|
46907
|
+
|
|
46908
|
+
// src/commands/med-family/fast-forward.ts
|
|
46909
|
+
init_cli_detector();
|
|
46910
|
+
var fastForwardHandlers = {
|
|
46911
|
+
mesh_init: async (ctx, args) => {
|
|
46912
|
+
const workspace = typeof args?.workspace === "string" && args.workspace.trim() ? args.workspace.trim() : process.cwd();
|
|
46913
|
+
const mesh = args?.inlineMesh || {};
|
|
46914
|
+
try {
|
|
46915
|
+
const detected = await detectCLIs(ctx.deps.providerLoader, { includeVersion: true });
|
|
46916
|
+
return { ...runMeshInit(mesh, workspace, detected, {
|
|
46917
|
+
write: args?.write === true,
|
|
46918
|
+
overwrite: args?.overwrite === true
|
|
46919
|
+
}) };
|
|
46920
|
+
} catch (e) {
|
|
46921
|
+
return { success: false, error: e?.message || String(e) };
|
|
46922
|
+
}
|
|
46923
|
+
},
|
|
46924
|
+
plan_mesh_refine_node: async (ctx, args) => {
|
|
46925
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46926
|
+
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
46927
|
+
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
46928
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46929
|
+
const mesh = meshRecord?.mesh;
|
|
46930
|
+
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
46931
|
+
if (!node?.workspace) return { success: false, error: `Node '${nodeId}' workspace not found` };
|
|
46932
|
+
return {
|
|
46933
|
+
success: true,
|
|
46934
|
+
dryRun: true,
|
|
46935
|
+
nodeId,
|
|
46936
|
+
workspace: node.workspace,
|
|
46937
|
+
validationPlan: buildMeshRefineValidationPlan(mesh, node.workspace),
|
|
46938
|
+
mergeWillRun: false,
|
|
46939
|
+
cleanupWillRun: false
|
|
46940
|
+
};
|
|
46941
|
+
},
|
|
46942
|
+
fast_forward_mesh_node: async (ctx, args) => {
|
|
46943
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46944
|
+
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
46945
|
+
let workspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
|
|
46946
|
+
let submoduleIgnorePaths = Array.isArray(args?.submoduleIgnorePaths) ? args.submoduleIgnorePaths.filter((value) => typeof value === "string") : void 0;
|
|
46947
|
+
let nodeDaemonId;
|
|
46948
|
+
let allowAutoPublishSubmoduleMainCommits = false;
|
|
46949
|
+
if (meshId && nodeId) {
|
|
46950
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46951
|
+
const mesh = meshRecord?.mesh;
|
|
46952
|
+
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
46953
|
+
if (!workspace) {
|
|
46954
|
+
workspace = typeof node?.workspace === "string" ? node.workspace.trim() : "";
|
|
46955
|
+
}
|
|
46956
|
+
if (!submoduleIgnorePaths && Array.isArray(node?.policy?.submoduleIgnorePaths)) {
|
|
46957
|
+
submoduleIgnorePaths = node.policy.submoduleIgnorePaths.filter((value) => typeof value === "string");
|
|
46958
|
+
}
|
|
46959
|
+
allowAutoPublishSubmoduleMainCommits = mesh?.policy?.allowAutoPublishSubmoduleMainCommits === true;
|
|
46960
|
+
nodeDaemonId = typeof node?.daemonId === "string" ? node.daemonId.trim() : void 0;
|
|
46961
|
+
}
|
|
46962
|
+
const selfDaemonId = ctx.deps.statusInstanceId;
|
|
46963
|
+
const isRemote = nodeDaemonId && selfDaemonId && !daemonIdsEquivalent(nodeDaemonId, selfDaemonId);
|
|
46964
|
+
if (isRemote && ctx.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
|
|
46965
|
+
const forwarded = await ctx.deps.dispatchMeshCommand(nodeDaemonId, "fast_forward_mesh_node", {
|
|
46966
|
+
...typeof args === "object" && args !== null ? args : {},
|
|
46967
|
+
workspace,
|
|
46968
|
+
_meshDirectDispatch: true
|
|
46969
|
+
});
|
|
46970
|
+
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
46971
|
+
}
|
|
46972
|
+
const result = await fastForwardMeshNode({
|
|
46973
|
+
meshId: meshId || void 0,
|
|
46974
|
+
nodeId: nodeId || void 0,
|
|
46975
|
+
workspace,
|
|
46976
|
+
branch: typeof args?.branch === "string" ? args.branch : void 0,
|
|
46977
|
+
execute: args?.execute === true,
|
|
46978
|
+
dryRun: args?.dryRun === true,
|
|
46979
|
+
updateSubmodules: args?.updateSubmodules === true,
|
|
46980
|
+
submoduleIgnorePaths,
|
|
46981
|
+
mode: args?.mode === "push" ? "push" : "merge",
|
|
46982
|
+
pushSubmodules: args?.pushSubmodules === true,
|
|
46983
|
+
allowAutoPublishSubmoduleMainCommits
|
|
46984
|
+
});
|
|
46985
|
+
return result;
|
|
46986
|
+
},
|
|
46987
|
+
refine_mesh_node: async (ctx, args) => {
|
|
46988
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46989
|
+
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
46990
|
+
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
46991
|
+
{
|
|
46992
|
+
const meshRecordForForward = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
46993
|
+
const forwardNode = meshRecordForForward?.mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
46994
|
+
const nodeDaemonId = typeof forwardNode?.daemonId === "string" ? forwardNode.daemonId.trim() : void 0;
|
|
46995
|
+
const selfDaemonId = ctx.deps.statusInstanceId;
|
|
46996
|
+
const isRemote = nodeDaemonId && selfDaemonId && !daemonIdsEquivalent(nodeDaemonId, selfDaemonId);
|
|
46997
|
+
if (isRemote && ctx.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
|
|
46998
|
+
const callerCoordinatorDaemonId = typeof args?.coordinatorDaemonId === "string" && args.coordinatorDaemonId.trim() ? args.coordinatorDaemonId.trim() : void 0;
|
|
46999
|
+
const forwarded = await ctx.deps.dispatchMeshCommand(nodeDaemonId, "refine_mesh_node", {
|
|
47000
|
+
...typeof args === "object" && args !== null ? args : {},
|
|
47001
|
+
coordinatorDaemonId: callerCoordinatorDaemonId || selfDaemonId,
|
|
47002
|
+
_meshDirectDispatch: true
|
|
47003
|
+
});
|
|
47004
|
+
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
47005
|
+
}
|
|
47006
|
+
}
|
|
47007
|
+
const isDryRun = args?.dryRun !== false && args?.execute !== true;
|
|
47008
|
+
if (isDryRun) {
|
|
47009
|
+
const meshRecord = await ctx.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
47010
|
+
const mesh = meshRecord?.mesh;
|
|
47011
|
+
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
47012
|
+
if (!node?.workspace) return { success: false, error: `Node '${nodeId}' workspace not found` };
|
|
47013
|
+
return {
|
|
47014
|
+
success: true,
|
|
47015
|
+
dryRun: true,
|
|
47016
|
+
nodeId,
|
|
47017
|
+
workspace: node.workspace,
|
|
47018
|
+
validationPlan: buildMeshRefineValidationPlan(mesh, node.workspace),
|
|
47019
|
+
mergeWillRun: false,
|
|
47020
|
+
cleanupWillRun: false,
|
|
47021
|
+
hint: "Dry-run only \u2014 no merge/push/cleanup performed. Re-invoke with execute:true to converge this node."
|
|
47022
|
+
};
|
|
47023
|
+
}
|
|
47024
|
+
return ctx.startMeshRefineJob(meshId, nodeId, args);
|
|
47025
|
+
},
|
|
47026
|
+
batch_refine_mesh_nodes: async (ctx, args) => {
|
|
47027
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
47028
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
47029
|
+
const requestedNodeIds = Array.isArray(args?.nodeIds) ? args.nodeIds.filter((v) => typeof v === "string" && v.trim().length > 0).map((v) => v.trim()) : void 0;
|
|
47030
|
+
const isDryRun = args?.dryRun !== false && args?.execute !== true;
|
|
47031
|
+
if (isDryRun) return ctx.batchRefineMeshNodes(meshId, requestedNodeIds, args);
|
|
47032
|
+
return ctx.startMeshRefineBatchJob(meshId, requestedNodeIds, args);
|
|
47033
|
+
}
|
|
47034
|
+
};
|
|
47035
|
+
|
|
47036
|
+
// src/commands/med-family/index.ts
|
|
47037
|
+
var medFamilyRegistry = new Map(
|
|
47038
|
+
Object.entries({
|
|
47039
|
+
...cliAgentHandlers,
|
|
47040
|
+
...ideHandlers,
|
|
47041
|
+
...meshCrudHandlers,
|
|
47042
|
+
...meshHostPairingHandlers,
|
|
47043
|
+
...meshQueueHandlers,
|
|
47044
|
+
...fastForwardHandlers
|
|
47045
|
+
})
|
|
47046
|
+
);
|
|
47047
|
+
|
|
47048
|
+
// src/commands/router.ts
|
|
47049
|
+
init_config();
|
|
47050
|
+
init_cli_detector();
|
|
45524
47051
|
init_git_status();
|
|
45525
47052
|
init_dist();
|
|
45526
47053
|
init_logger();
|
|
@@ -45676,9 +47203,7 @@ init_mesh_coordinator();
|
|
|
45676
47203
|
init_coordinator_registry();
|
|
45677
47204
|
init_mesh_events();
|
|
45678
47205
|
init_mesh_routing();
|
|
45679
|
-
init_mesh_events_utils();
|
|
45680
47206
|
init_mesh_host_ownership();
|
|
45681
|
-
init_mesh_fast_forward();
|
|
45682
47207
|
|
|
45683
47208
|
// src/mesh/mesh-refine-batch.ts
|
|
45684
47209
|
import { execFile as execFile4 } from "child_process";
|
|
@@ -45769,7 +47294,7 @@ function orderMeshRefineBatchNodes(changeAreas) {
|
|
|
45769
47294
|
|
|
45770
47295
|
// src/mesh/preview-freshness.ts
|
|
45771
47296
|
import { execFileSync as execFileSync5 } from "child_process";
|
|
45772
|
-
import { existsSync as
|
|
47297
|
+
import { existsSync as existsSync39, readFileSync as readFileSync29 } from "fs";
|
|
45773
47298
|
import { resolve as resolve19 } from "path";
|
|
45774
47299
|
var PREVIEW_DEPLOY_RECORD = ".adhdev/preview-deploy.json";
|
|
45775
47300
|
function runGit2(repoRoot, args) {
|
|
@@ -45786,7 +47311,7 @@ function runGit2(repoRoot, args) {
|
|
|
45786
47311
|
}
|
|
45787
47312
|
function readRecord5(repoRoot) {
|
|
45788
47313
|
const path42 = resolve19(repoRoot, PREVIEW_DEPLOY_RECORD);
|
|
45789
|
-
if (!
|
|
47314
|
+
if (!existsSync39(path42)) return null;
|
|
45790
47315
|
try {
|
|
45791
47316
|
const parsed = JSON.parse(readFileSync29(path42, "utf8"));
|
|
45792
47317
|
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : null;
|
|
@@ -45851,121 +47376,6 @@ function buildPreviewFreshness(repoRoot) {
|
|
|
45851
47376
|
|
|
45852
47377
|
// src/commands/router.ts
|
|
45853
47378
|
init_mesh_refine_status();
|
|
45854
|
-
|
|
45855
|
-
// src/mesh/mesh-init.ts
|
|
45856
|
-
import { existsSync as existsSync39, mkdirSync as mkdirSync16, writeFileSync as writeFileSync18 } from "fs";
|
|
45857
|
-
import { dirname as dirname11, join as join41 } from "path";
|
|
45858
|
-
var MESH_INIT_REFINE_CONFIG_PATH = MESH_REFINE_CONFIG_LOCATIONS[0];
|
|
45859
|
-
var MESH_INIT_WORKTREE_BOOTSTRAP_CONFIG_PATH = MESH_WORKTREE_BOOTSTRAP_CONFIG_LOCATIONS[0];
|
|
45860
|
-
var CANDIDATE_STALE_INPUTS = [
|
|
45861
|
-
"package-lock.json",
|
|
45862
|
-
"pnpm-lock.yaml",
|
|
45863
|
-
"yarn.lock",
|
|
45864
|
-
"bun.lockb",
|
|
45865
|
-
"Cargo.lock",
|
|
45866
|
-
"go.sum",
|
|
45867
|
-
"poetry.lock",
|
|
45868
|
-
"requirements.txt"
|
|
45869
|
-
];
|
|
45870
|
-
function writeConfigFile(workspace, relativePath, config) {
|
|
45871
|
-
const target = join41(workspace, relativePath);
|
|
45872
|
-
mkdirSync16(dirname11(target), { recursive: true });
|
|
45873
|
-
writeFileSync18(target, `${JSON.stringify(config, null, 2)}
|
|
45874
|
-
`, "utf-8");
|
|
45875
|
-
return target;
|
|
45876
|
-
}
|
|
45877
|
-
function suggestMeshWorktreeBootstrapConfig(workspace) {
|
|
45878
|
-
const commands = [];
|
|
45879
|
-
const hasPackageJson = existsSync39(join41(workspace, "package.json"));
|
|
45880
|
-
const hasNpmLock = existsSync39(join41(workspace, "package-lock.json"));
|
|
45881
|
-
if (hasPackageJson) {
|
|
45882
|
-
commands.push(
|
|
45883
|
-
hasNpmLock ? { command: "npm", args: ["ci"] } : { command: "npm", args: ["install"] }
|
|
45884
|
-
);
|
|
45885
|
-
}
|
|
45886
|
-
const staleInputs = CANDIDATE_STALE_INPUTS.filter((relative5) => existsSync39(join41(workspace, relative5)));
|
|
45887
|
-
if (!commands.length) {
|
|
45888
|
-
return { commands, staleInputs };
|
|
45889
|
-
}
|
|
45890
|
-
return {
|
|
45891
|
-
commands,
|
|
45892
|
-
staleInputs,
|
|
45893
|
-
suggestedConfig: {
|
|
45894
|
-
version: 1,
|
|
45895
|
-
enabled: true,
|
|
45896
|
-
runOnClone: true,
|
|
45897
|
-
required: false,
|
|
45898
|
-
commands,
|
|
45899
|
-
...staleInputs.length ? { staleInputs } : {}
|
|
45900
|
-
}
|
|
45901
|
-
};
|
|
45902
|
-
}
|
|
45903
|
-
var PROVIDER_PRIORITY_PREFERENCE = ["claude-cli", "codex-cli", "gemini-cli"];
|
|
45904
|
-
function suggestNodeProviderPriority(detected) {
|
|
45905
|
-
const installed = detected.filter((cli) => cli.installed);
|
|
45906
|
-
const installedIds = installed.map((cli) => cli.id);
|
|
45907
|
-
const preferred = PROVIDER_PRIORITY_PREFERENCE.filter((id) => installedIds.includes(id));
|
|
45908
|
-
const rest = installedIds.filter((id) => !preferred.includes(id));
|
|
45909
|
-
const providerPriority = [...preferred, ...rest];
|
|
45910
|
-
return {
|
|
45911
|
-
providerPriority,
|
|
45912
|
-
installedProviders: installed.map((cli) => ({
|
|
45913
|
-
id: cli.id,
|
|
45914
|
-
displayName: cli.displayName,
|
|
45915
|
-
...cli.version ? { version: cli.version } : {}
|
|
45916
|
-
}))
|
|
45917
|
-
};
|
|
45918
|
-
}
|
|
45919
|
-
function runMeshInit(mesh, workspace, detected, options = {}) {
|
|
45920
|
-
const write = options.write === true;
|
|
45921
|
-
const overwrite = options.overwrite === true;
|
|
45922
|
-
const refine = applyConfigSuggestion({
|
|
45923
|
-
workspace,
|
|
45924
|
-
relativePath: MESH_INIT_REFINE_CONFIG_PATH,
|
|
45925
|
-
existing: loadMeshRefineConfig(mesh, workspace).config,
|
|
45926
|
-
suggestedConfig: suggestMeshRefineConfig(mesh, workspace).suggestedConfig,
|
|
45927
|
-
validate: (config) => validateMeshRefineConfig(config, MESH_INIT_REFINE_CONFIG_PATH).valid,
|
|
45928
|
-
write,
|
|
45929
|
-
overwrite
|
|
45930
|
-
});
|
|
45931
|
-
const bootstrapSuggestion = suggestMeshWorktreeBootstrapConfig(workspace);
|
|
45932
|
-
const worktreeBootstrap = applyConfigSuggestion({
|
|
45933
|
-
workspace,
|
|
45934
|
-
relativePath: MESH_INIT_WORKTREE_BOOTSTRAP_CONFIG_PATH,
|
|
45935
|
-
existing: loadMeshWorktreeBootstrapConfig(mesh, workspace).config,
|
|
45936
|
-
suggestedConfig: bootstrapSuggestion.suggestedConfig,
|
|
45937
|
-
validate: (config) => validateMeshWorktreeBootstrapConfig(config, MESH_INIT_WORKTREE_BOOTSTRAP_CONFIG_PATH).valid,
|
|
45938
|
-
write,
|
|
45939
|
-
overwrite
|
|
45940
|
-
});
|
|
45941
|
-
const providers = suggestNodeProviderPriority(detected);
|
|
45942
|
-
return {
|
|
45943
|
-
success: true,
|
|
45944
|
-
workspace,
|
|
45945
|
-
dryRun: !write,
|
|
45946
|
-
refine,
|
|
45947
|
-
worktreeBootstrap,
|
|
45948
|
-
providers,
|
|
45949
|
-
note: write ? "Configs written to disk are the execution source of truth; suggestions are scaffold and only take effect once saved. providerPriority is a recommendation \u2014 apply it to node policy via clone/policy update." : "Dry-run: no files written. Re-run with write=true to persist the suggested configs. Heuristic suggestions never execute until saved as repo config."
|
|
45950
|
-
};
|
|
45951
|
-
}
|
|
45952
|
-
function applyConfigSuggestion(input) {
|
|
45953
|
-
const { workspace, relativePath, existing, suggestedConfig, validate, write, overwrite } = input;
|
|
45954
|
-
const absolute = join41(workspace, relativePath);
|
|
45955
|
-
if (existing !== void 0 && !overwrite) {
|
|
45956
|
-
return { path: absolute, relativePath, written: false, skippedReason: "already_exists", config: existing };
|
|
45957
|
-
}
|
|
45958
|
-
if (!suggestedConfig || !validate(suggestedConfig)) {
|
|
45959
|
-
return { path: absolute, relativePath, written: false, skippedReason: "no_suggestion" };
|
|
45960
|
-
}
|
|
45961
|
-
if (!write) {
|
|
45962
|
-
return { path: absolute, relativePath, written: false, config: suggestedConfig };
|
|
45963
|
-
}
|
|
45964
|
-
const writtenPath = writeConfigFile(workspace, relativePath, suggestedConfig);
|
|
45965
|
-
return { path: writtenPath, relativePath, written: true, config: suggestedConfig };
|
|
45966
|
-
}
|
|
45967
|
-
|
|
45968
|
-
// src/commands/router.ts
|
|
45969
47379
|
init_mesh_work_queue();
|
|
45970
47380
|
init_repo_mesh_types();
|
|
45971
47381
|
import { homedir as homedir26, hostname as osHostname } from "os";
|
|
@@ -48517,6 +49927,37 @@ var DaemonCommandRouter = class {
|
|
|
48517
49927
|
this.aggregateMeshStatusCache.delete(meshId);
|
|
48518
49928
|
this.deps.onMeshStateChange?.(meshId);
|
|
48519
49929
|
}
|
|
49930
|
+
/**
|
|
49931
|
+
* Build the MedFamilyContext handed to RF-ROUTER MED family handlers. Binds the
|
|
49932
|
+
* router-private collaborators those handlers need (mesh resolution, owner
|
|
49933
|
+
* gating, inline-cache mutation, worktree / session cleanup, refine job
|
|
49934
|
+
* starters, IDE stop/launch) plus the inline-mesh and git-probe caches. The
|
|
49935
|
+
* `launchIde` field closes over the freshly-built context so restart_session /
|
|
49936
|
+
* restart_ide invoke the IDE launch directly instead of recursing through
|
|
49937
|
+
* executeDaemonCommand('launch_ide').
|
|
49938
|
+
*/
|
|
49939
|
+
buildMedFamilyContext() {
|
|
49940
|
+
const ctx = {
|
|
49941
|
+
deps: this.deps,
|
|
49942
|
+
getMeshForCommand: this.getMeshForCommand.bind(this),
|
|
49943
|
+
getCachedInlineMesh: this.getCachedInlineMesh.bind(this),
|
|
49944
|
+
requireMeshHostMutationOwner: this.requireMeshHostMutationOwner.bind(this),
|
|
49945
|
+
invalidateAggregateMeshStatus: this.invalidateAggregateMeshStatus.bind(this),
|
|
49946
|
+
updateInlineMeshNode: this.updateInlineMeshNode.bind(this),
|
|
49947
|
+
removeInlineMeshNode: this.removeInlineMeshNode.bind(this),
|
|
49948
|
+
normalizeMeshSessionCleanupMode: this.normalizeMeshSessionCleanupMode.bind(this),
|
|
49949
|
+
cleanupMeshSessions: this.cleanupMeshSessions.bind(this),
|
|
49950
|
+
cleanupLocalWorktreeNode: this.cleanupLocalWorktreeNode.bind(this),
|
|
49951
|
+
startMeshRefineJob: this.startMeshRefineJob.bind(this),
|
|
49952
|
+
batchRefineMeshNodes: this.batchRefineMeshNodes.bind(this),
|
|
49953
|
+
startMeshRefineBatchJob: this.startMeshRefineBatchJob.bind(this),
|
|
49954
|
+
stopIde: this.stopIde.bind(this),
|
|
49955
|
+
launchIde: (args) => launchIde(ctx, args),
|
|
49956
|
+
inlineMeshCache: this.inlineMeshCache,
|
|
49957
|
+
meshGitProbeCache: this.meshGitProbeCache
|
|
49958
|
+
};
|
|
49959
|
+
return ctx;
|
|
49960
|
+
}
|
|
48520
49961
|
async requireMeshHostMutationOwner(meshId, inlineMesh, operation) {
|
|
48521
49962
|
const meshRecord = await this.getMeshForCommand(meshId, inlineMesh, { preferInline: true });
|
|
48522
49963
|
const mesh = meshRecord?.mesh;
|
|
@@ -50432,6 +51873,10 @@ ${hintLines.join("\n")}` : "",
|
|
|
50432
51873
|
getMeshForCommand: this.getMeshForCommand.bind(this)
|
|
50433
51874
|
}, args);
|
|
50434
51875
|
}
|
|
51876
|
+
const medFamilyHandler = medFamilyRegistry.get(cmd);
|
|
51877
|
+
if (medFamilyHandler) {
|
|
51878
|
+
return await medFamilyHandler(this.buildMedFamilyContext(), args);
|
|
51879
|
+
}
|
|
50435
51880
|
switch (cmd) {
|
|
50436
51881
|
// ─── CLI / ACP commands ───
|
|
50437
51882
|
case "mesh_forward_event": {
|
|
@@ -50452,1315 +51897,6 @@ ${hintLines.join("\n")}` : "",
|
|
|
50452
51897
|
this.deps.instanceManager.sendEvent(sessionId, "interactive_prompt_response", response);
|
|
50453
51898
|
return { success: true };
|
|
50454
51899
|
}
|
|
50455
|
-
case "launch_cli": {
|
|
50456
|
-
const launchResult = await this.deps.cliManager.handleCliCommand(cmd, args);
|
|
50457
|
-
const meshNodeId = readStringValue(args?.settings?.meshNodeId);
|
|
50458
|
-
const meshId = readStringValue(args?.settings?.meshNodeFor);
|
|
50459
|
-
if (meshNodeId && meshId && launchResult?.success !== false) {
|
|
50460
|
-
try {
|
|
50461
|
-
const { getMesh: getMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50462
|
-
const meshObj = getMesh2(meshId) ?? this.getCachedInlineMesh(meshId);
|
|
50463
|
-
const nodeObj = Array.isArray(meshObj?.nodes) ? meshObj.nodes.find((n) => meshNodeIdMatches(n, meshNodeId)) : void 0;
|
|
50464
|
-
const bootstrapStatus = readStringValue(nodeObj?.worktreeBootstrap?.status);
|
|
50465
|
-
if (bootstrapStatus === "running") {
|
|
50466
|
-
return { success: true, ...launchResult, bootstrapPending: true };
|
|
50467
|
-
}
|
|
50468
|
-
} catch {
|
|
50469
|
-
}
|
|
50470
|
-
}
|
|
50471
|
-
return launchResult;
|
|
50472
|
-
}
|
|
50473
|
-
case "stop_cli":
|
|
50474
|
-
case "set_cli_view_mode":
|
|
50475
|
-
case "record_provider_pty": {
|
|
50476
|
-
return this.deps.cliManager.handleCliCommand(cmd, args);
|
|
50477
|
-
}
|
|
50478
|
-
case "agent_command": {
|
|
50479
|
-
{
|
|
50480
|
-
const dispatchSessionId = readStringValue(args?.targetSessionId, args?.sessionId, args?.instanceId);
|
|
50481
|
-
const dispatchMeshContext = args?.meshContext;
|
|
50482
|
-
if (dispatchSessionId && dispatchMeshContext) {
|
|
50483
|
-
try {
|
|
50484
|
-
const inst = this.deps.instanceManager.getInstance(dispatchSessionId);
|
|
50485
|
-
if (inst && typeof inst.updateSettings === "function") {
|
|
50486
|
-
const stamp = buildMeshWorkerRelayStamp(
|
|
50487
|
-
inst.getState?.()?.settings,
|
|
50488
|
-
{
|
|
50489
|
-
meshId: dispatchMeshContext.meshId,
|
|
50490
|
-
nodeId: dispatchMeshContext.nodeId,
|
|
50491
|
-
coordinatorDaemonId: dispatchMeshContext.coordinatorDaemonId,
|
|
50492
|
-
// Session-level anchor: preserved across the P2P dispatch to a
|
|
50493
|
-
// remote worker so its completion echoes back to the right session.
|
|
50494
|
-
coordinatorSessionId: dispatchMeshContext.coordinatorSessionId
|
|
50495
|
-
}
|
|
50496
|
-
);
|
|
50497
|
-
if (stamp) inst.updateSettings(stamp);
|
|
50498
|
-
}
|
|
50499
|
-
} catch {
|
|
50500
|
-
}
|
|
50501
|
-
}
|
|
50502
|
-
}
|
|
50503
|
-
const agentResult = await this.deps.cliManager.handleCliCommand(cmd, args);
|
|
50504
|
-
const meshCtx = args?.meshContext;
|
|
50505
|
-
const dispatchNodeId = readStringValue(meshCtx?.nodeId);
|
|
50506
|
-
const dispatchMeshId = readStringValue(meshCtx?.meshId);
|
|
50507
|
-
if (dispatchNodeId && dispatchMeshId && agentResult?.success !== false) {
|
|
50508
|
-
try {
|
|
50509
|
-
const { getMesh: getMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50510
|
-
const meshObj = getMesh2(dispatchMeshId) ?? this.getCachedInlineMesh(dispatchMeshId);
|
|
50511
|
-
const nodeObj = Array.isArray(meshObj?.nodes) ? meshObj.nodes.find((n) => meshNodeIdMatches(n, dispatchNodeId)) : void 0;
|
|
50512
|
-
const bootstrapStatus = readStringValue(nodeObj?.worktreeBootstrap?.status);
|
|
50513
|
-
if (bootstrapStatus === "running") {
|
|
50514
|
-
return {
|
|
50515
|
-
success: true,
|
|
50516
|
-
...agentResult,
|
|
50517
|
-
dispatchAcknowledgementRisk: true,
|
|
50518
|
-
dispatchAcknowledgementRiskReason: "bootstrap_still_running",
|
|
50519
|
-
nextAction: "Wait for worktree_bootstrap_complete event before dispatching work to this node."
|
|
50520
|
-
};
|
|
50521
|
-
}
|
|
50522
|
-
} catch {
|
|
50523
|
-
}
|
|
50524
|
-
}
|
|
50525
|
-
return agentResult;
|
|
50526
|
-
}
|
|
50527
|
-
// ─── Logs ───
|
|
50528
|
-
case "list_saved_sessions": {
|
|
50529
|
-
const providerType = typeof args?.providerType === "string" ? args.providerType.trim() : typeof args?.agentType === "string" ? args.agentType.trim() : "";
|
|
50530
|
-
const kind = args?.kind === "acp" ? "acp" : "cli";
|
|
50531
|
-
if (!providerType) {
|
|
50532
|
-
return { success: false, error: "providerType required" };
|
|
50533
|
-
}
|
|
50534
|
-
const wantsAll = args?.all === true;
|
|
50535
|
-
const offset = wantsAll ? 0 : Math.max(0, Number(args?.offset) || 0);
|
|
50536
|
-
const limit = wantsAll ? Number.MAX_SAFE_INTEGER : Math.max(1, Math.min(100, Number(args?.limit) || 30));
|
|
50537
|
-
const requestedWorkspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
|
|
50538
|
-
const requestedProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : typeof args?.activeProviderSessionId === "string" ? args.activeProviderSessionId.trim() : "";
|
|
50539
|
-
const providerMeta = this.deps.providerLoader.resolve?.(providerType) || this.deps.providerLoader.getMeta(providerType);
|
|
50540
|
-
const { sessions: historySessions, hasMore, source } = listProviderHistorySessions(providerType, {
|
|
50541
|
-
canonicalHistory: providerMeta?.nativeHistory,
|
|
50542
|
-
offset,
|
|
50543
|
-
limit,
|
|
50544
|
-
historyBehavior: providerMeta?.historyBehavior,
|
|
50545
|
-
scripts: providerMeta?.scripts
|
|
50546
|
-
});
|
|
50547
|
-
const state = loadState();
|
|
50548
|
-
const savedSessions = getSavedProviderSessions(state, { providerType, kind });
|
|
50549
|
-
const recentSessions = getRecentActivity(state, 200).filter((entry) => entry.providerType === providerType && entry.kind === kind && entry.providerSessionId);
|
|
50550
|
-
const savedSessionById = new Map(savedSessions.map((entry) => [entry.providerSessionId, entry]));
|
|
50551
|
-
const recentSessionById = new Map(recentSessions.map((entry) => [entry.providerSessionId, entry]));
|
|
50552
|
-
const canResumeById = supportsExplicitSessionResume(providerMeta?.resume);
|
|
50553
|
-
return {
|
|
50554
|
-
success: true,
|
|
50555
|
-
sessions: historySessions.map((session) => {
|
|
50556
|
-
const saved = savedSessionById.get(session.historySessionId);
|
|
50557
|
-
const recent = recentSessionById.get(session.historySessionId);
|
|
50558
|
-
const workspace = saved?.workspace || recent?.workspace || session.workspace || (requestedWorkspace && requestedProviderSessionId === session.historySessionId ? requestedWorkspace : void 0);
|
|
50559
|
-
return {
|
|
50560
|
-
id: session.historySessionId,
|
|
50561
|
-
providerSessionId: session.historySessionId,
|
|
50562
|
-
providerType,
|
|
50563
|
-
providerName: saved?.providerName || recent?.providerName || providerType,
|
|
50564
|
-
kind: saved?.kind || recent?.kind || kind,
|
|
50565
|
-
title: saved?.title || recent?.title || session.sessionTitle || session.preview || providerType,
|
|
50566
|
-
workspace,
|
|
50567
|
-
summaryMetadata: saved?.summaryMetadata || recent?.summaryMetadata,
|
|
50568
|
-
preview: session.preview,
|
|
50569
|
-
messageCount: session.messageCount,
|
|
50570
|
-
firstMessageAt: session.firstMessageAt,
|
|
50571
|
-
lastMessageAt: session.lastMessageAt,
|
|
50572
|
-
canResume: !!workspace && canResumeById,
|
|
50573
|
-
historySource: session.source,
|
|
50574
|
-
sourcePath: session.sourcePath,
|
|
50575
|
-
sourceMtimeMs: session.sourceMtimeMs
|
|
50576
|
-
};
|
|
50577
|
-
}),
|
|
50578
|
-
hasMore,
|
|
50579
|
-
source
|
|
50580
|
-
};
|
|
50581
|
-
}
|
|
50582
|
-
// ─── restart_session: IDE / CLI / ACP unified ───
|
|
50583
|
-
case "restart_session": {
|
|
50584
|
-
const targetType = args?.cliType || args?.agentType || args?.ideType;
|
|
50585
|
-
if (!targetType) throw new Error("cliType or ideType required");
|
|
50586
|
-
const isIde = this.deps.cdpManagers.has(targetType) || this.deps.providerLoader.getMeta(targetType)?.category === "ide";
|
|
50587
|
-
if (isIde) {
|
|
50588
|
-
await this.stopIde(targetType, true);
|
|
50589
|
-
const launchResult = await this.executeDaemonCommand("launch_ide", { ideType: targetType, enableCdp: true, workspace: args?.workspace });
|
|
50590
|
-
return { success: true, restarted: true, ideType: targetType, launch: launchResult };
|
|
50591
|
-
}
|
|
50592
|
-
return this.deps.cliManager.handleCliCommand(cmd, args);
|
|
50593
|
-
}
|
|
50594
|
-
// ─── IDE stop ───
|
|
50595
|
-
case "stop_ide": {
|
|
50596
|
-
const ideType = args?.ideType;
|
|
50597
|
-
if (!ideType) throw new Error("ideType required");
|
|
50598
|
-
const killProcess = args?.killProcess !== false;
|
|
50599
|
-
await this.stopIde(ideType, killProcess);
|
|
50600
|
-
try {
|
|
50601
|
-
const results = await detectIDEs(this.deps.providerLoader);
|
|
50602
|
-
this.deps.detectedIdes.value = results;
|
|
50603
|
-
this.deps.providerLoader.setIdeDetectionResults(results, true);
|
|
50604
|
-
} catch {
|
|
50605
|
-
}
|
|
50606
|
-
return { success: true, ideType, stopped: true, processKilled: killProcess };
|
|
50607
|
-
}
|
|
50608
|
-
// ─── IDE restart ───
|
|
50609
|
-
case "restart_ide": {
|
|
50610
|
-
const ideType = args?.ideType;
|
|
50611
|
-
if (!ideType) throw new Error("ideType required");
|
|
50612
|
-
await this.stopIde(ideType, true);
|
|
50613
|
-
const launchResult = await this.executeDaemonCommand("launch_ide", { ideType, enableCdp: true, workspace: args?.workspace });
|
|
50614
|
-
return { success: true, ideType, restarted: true, launch: launchResult };
|
|
50615
|
-
}
|
|
50616
|
-
// ─── IDE launch + CDP connect ───
|
|
50617
|
-
case "launch_ide": {
|
|
50618
|
-
const ideKey = args?.ideId || args?.ideType;
|
|
50619
|
-
const resolvedWorkspace = resolveIdeLaunchWorkspace(
|
|
50620
|
-
{
|
|
50621
|
-
workspace: args?.workspace,
|
|
50622
|
-
workspaceId: args?.workspaceId,
|
|
50623
|
-
useDefaultWorkspace: args?.useDefaultWorkspace
|
|
50624
|
-
},
|
|
50625
|
-
loadConfig()
|
|
50626
|
-
);
|
|
50627
|
-
const launchArgs = {
|
|
50628
|
-
ideId: ideKey,
|
|
50629
|
-
workspace: resolvedWorkspace,
|
|
50630
|
-
newWindow: args?.newWindow
|
|
50631
|
-
};
|
|
50632
|
-
LOG.info("LaunchIDE", `target=${ideKey || "auto"}`);
|
|
50633
|
-
const result = await launchWithCdp(launchArgs);
|
|
50634
|
-
if (result.success && result.port && result.ideId && !this.deps.cdpManagers.has(result.ideId)) {
|
|
50635
|
-
const logFn = this.deps.getCdpLogFn ? this.deps.getCdpLogFn(result.ideId) : LOG.forComponent(`CDP:${result.ideId}`).asLogFn();
|
|
50636
|
-
const provider = this.deps.providerLoader.getMeta(result.ideId);
|
|
50637
|
-
const manager = new DaemonCdpManager(result.port, logFn, void 0, provider?.targetFilter);
|
|
50638
|
-
const connected = await manager.connect();
|
|
50639
|
-
if (connected) {
|
|
50640
|
-
registerExtensionProviders(this.deps.providerLoader, manager, result.ideId);
|
|
50641
|
-
this.deps.cdpManagers.set(result.ideId, manager);
|
|
50642
|
-
LOG.info("CDP", `Connected: ${result.ideId} (port ${result.port})`);
|
|
50643
|
-
LOG.info("CDP", `${this.deps.cdpManagers.size} IDE(s) connected`);
|
|
50644
|
-
this.deps.onCdpManagerCreated?.(result.ideId, manager);
|
|
50645
|
-
}
|
|
50646
|
-
}
|
|
50647
|
-
this.deps.onIdeConnected?.();
|
|
50648
|
-
try {
|
|
50649
|
-
const results = await detectIDEs(this.deps.providerLoader);
|
|
50650
|
-
this.deps.detectedIdes.value = results;
|
|
50651
|
-
this.deps.providerLoader.setIdeDetectionResults(results, true);
|
|
50652
|
-
} catch {
|
|
50653
|
-
}
|
|
50654
|
-
if (result.success && resolvedWorkspace) {
|
|
50655
|
-
try {
|
|
50656
|
-
const next = appendRecentActivity(loadState(), {
|
|
50657
|
-
kind: "ide",
|
|
50658
|
-
providerType: result.ideId || ideKey,
|
|
50659
|
-
providerName: result.ideId || ideKey,
|
|
50660
|
-
workspace: resolvedWorkspace,
|
|
50661
|
-
title: result.ideId || ideKey
|
|
50662
|
-
});
|
|
50663
|
-
saveState(next);
|
|
50664
|
-
} catch {
|
|
50665
|
-
}
|
|
50666
|
-
} else if (result.success && (result.ideId || ideKey)) {
|
|
50667
|
-
try {
|
|
50668
|
-
saveState(appendRecentActivity(loadState(), {
|
|
50669
|
-
kind: "ide",
|
|
50670
|
-
providerType: result.ideId || ideKey,
|
|
50671
|
-
providerName: result.ideId || ideKey,
|
|
50672
|
-
title: result.ideId || ideKey
|
|
50673
|
-
}));
|
|
50674
|
-
} catch {
|
|
50675
|
-
}
|
|
50676
|
-
}
|
|
50677
|
-
return { ...result };
|
|
50678
|
-
}
|
|
50679
|
-
// ─── Detect providers ───
|
|
50680
|
-
case "detect_provider": {
|
|
50681
|
-
const providerType = typeof args?.providerType === "string" ? args.providerType.trim() : "";
|
|
50682
|
-
if (!providerType) return { success: false, error: "providerType is required" };
|
|
50683
|
-
const normalizedType = this.deps.providerLoader.resolveAlias(providerType);
|
|
50684
|
-
const provider = this.deps.providerLoader.getByAlias(providerType);
|
|
50685
|
-
if (!provider) return { success: false, error: `Provider not found: ${providerType}` };
|
|
50686
|
-
if (provider.category !== "cli" && provider.category !== "acp") {
|
|
50687
|
-
return { success: false, error: `Provider detection is only supported for CLI/ACP providers: ${providerType}` };
|
|
50688
|
-
}
|
|
50689
|
-
if (!this.deps.providerLoader.isMachineProviderEnabled(normalizedType)) {
|
|
50690
|
-
return { success: false, error: `Provider is disabled on this machine: ${providerType}` };
|
|
50691
|
-
}
|
|
50692
|
-
const detected = await detectCLI(normalizedType, this.deps.providerLoader, { includeVersion: false });
|
|
50693
|
-
this.deps.providerLoader.setCliDetectionResults([{
|
|
50694
|
-
id: normalizedType,
|
|
50695
|
-
installed: !!detected,
|
|
50696
|
-
path: detected?.path
|
|
50697
|
-
}], false);
|
|
50698
|
-
this.deps.onStatusChange?.();
|
|
50699
|
-
return {
|
|
50700
|
-
success: true,
|
|
50701
|
-
providerType: normalizedType,
|
|
50702
|
-
detected: !!detected,
|
|
50703
|
-
path: detected?.path || null
|
|
50704
|
-
};
|
|
50705
|
-
}
|
|
50706
|
-
// ─── Detect IDEs ───
|
|
50707
|
-
case "detect_ides": {
|
|
50708
|
-
const results = await detectIDEs(this.deps.providerLoader);
|
|
50709
|
-
this.deps.detectedIdes.value = results;
|
|
50710
|
-
this.deps.providerLoader.setIdeDetectionResults(results, true);
|
|
50711
|
-
return { success: true, detectedInfo: results };
|
|
50712
|
-
}
|
|
50713
|
-
// ─── Mesh CRUD (local meshes.json) ───
|
|
50714
|
-
case "list_meshes": {
|
|
50715
|
-
try {
|
|
50716
|
-
const { listMeshes: listMeshes2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50717
|
-
return { success: true, meshes: listMeshes2() };
|
|
50718
|
-
} catch (e) {
|
|
50719
|
-
return { success: false, error: e.message };
|
|
50720
|
-
}
|
|
50721
|
-
}
|
|
50722
|
-
case "get_mesh": {
|
|
50723
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
50724
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
50725
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
50726
|
-
if (!meshRecord?.mesh) return { success: false, error: "Mesh not found" };
|
|
50727
|
-
const requireDirectPeerTruth = args?.requireDirectPeerTruth === true;
|
|
50728
|
-
const probeRemotePeers = args?.refresh === true || args?.forceRefresh === true;
|
|
50729
|
-
const directTruth = await hydrateInlineMeshDirectTruth({
|
|
50730
|
-
mesh: meshRecord.mesh,
|
|
50731
|
-
meshSource: meshRecord.source,
|
|
50732
|
-
dispatchMeshCommand: this.deps.dispatchMeshCommand,
|
|
50733
|
-
getMeshPeerConnectionStatus: this.deps.getMeshPeerConnectionStatus,
|
|
50734
|
-
statusInstanceId: this.deps.statusInstanceId,
|
|
50735
|
-
localMachineId: loadConfig().machineId || "",
|
|
50736
|
-
probeRemotePeers,
|
|
50737
|
-
probeCache: this.meshGitProbeCache
|
|
50738
|
-
});
|
|
50739
|
-
const directTruthSatisfied = meshRecord.source !== "inline_bootstrap" || directTruth.directEvidenceCount > 0;
|
|
50740
|
-
const sourceOfTruth = {
|
|
50741
|
-
membership: meshRecord.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
|
|
50742
|
-
coordinatorOwnsLiveTruth: directTruthSatisfied,
|
|
50743
|
-
directPeerTruth: {
|
|
50744
|
-
required: requireDirectPeerTruth,
|
|
50745
|
-
satisfied: directTruthSatisfied,
|
|
50746
|
-
directEvidenceCount: directTruth.directEvidenceCount,
|
|
50747
|
-
localConfirmedCount: directTruth.localConfirmedCount,
|
|
50748
|
-
peerAttemptedCount: directTruth.peerAttemptedCount,
|
|
50749
|
-
peerConfirmedCount: directTruth.peerConfirmedCount,
|
|
50750
|
-
unavailableNodeIds: directTruth.unavailableNodeIds
|
|
50751
|
-
}
|
|
50752
|
-
};
|
|
50753
|
-
if (requireDirectPeerTruth && !directTruthSatisfied) {
|
|
50754
|
-
return {
|
|
50755
|
-
success: false,
|
|
50756
|
-
code: "mesh_direct_peer_truth_unavailable",
|
|
50757
|
-
error: "Selected coordinator could not confirm direct mesh truth yet. Bootstrap inventory stays unavailable until direct get_mesh probes succeed.",
|
|
50758
|
-
sourceOfTruth
|
|
50759
|
-
};
|
|
50760
|
-
}
|
|
50761
|
-
return { success: true, mesh: meshRecord.mesh, sourceOfTruth };
|
|
50762
|
-
}
|
|
50763
|
-
case "create_mesh": {
|
|
50764
|
-
const name = typeof args?.name === "string" ? args.name.trim() : "";
|
|
50765
|
-
const repoIdentity = typeof args?.repoIdentity === "string" ? args.repoIdentity.trim() : "";
|
|
50766
|
-
const repoRemoteUrl = typeof args?.repoRemoteUrl === "string" ? args.repoRemoteUrl.trim() : void 0;
|
|
50767
|
-
const defaultBranch = typeof args?.defaultBranch === "string" ? args.defaultBranch.trim() : void 0;
|
|
50768
|
-
if (!name) return { success: false, error: "name required" };
|
|
50769
|
-
try {
|
|
50770
|
-
const { createMesh: createMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50771
|
-
const meshHost = args?.meshHost && typeof args.meshHost === "object" && !Array.isArray(args.meshHost) ? args.meshHost : void 0;
|
|
50772
|
-
const mesh = createMesh2({ name, repoIdentity, repoRemoteUrl, defaultBranch, policy: args?.policy, meshHost });
|
|
50773
|
-
return { success: true, mesh };
|
|
50774
|
-
} catch (e) {
|
|
50775
|
-
return { success: false, error: e.message };
|
|
50776
|
-
}
|
|
50777
|
-
}
|
|
50778
|
-
case "update_mesh": {
|
|
50779
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
50780
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
50781
|
-
try {
|
|
50782
|
-
const { updateMesh: updateMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50783
|
-
const patch = {};
|
|
50784
|
-
if (typeof args?.name === "string") patch.name = args.name;
|
|
50785
|
-
if (typeof args?.defaultBranch === "string") patch.defaultBranch = args.defaultBranch;
|
|
50786
|
-
if (args?.policy && typeof args.policy === "object" && !Array.isArray(args.policy)) patch.policy = args.policy;
|
|
50787
|
-
if (args?.coordinator && typeof args.coordinator === "object" && !Array.isArray(args.coordinator)) patch.coordinator = args.coordinator;
|
|
50788
|
-
if (args?.meshHost && typeof args.meshHost === "object" && !Array.isArray(args.meshHost)) patch.meshHost = args.meshHost;
|
|
50789
|
-
if (!Object.keys(patch).length) return { success: false, error: "No updates provided" };
|
|
50790
|
-
const mesh = updateMesh2(meshId, patch);
|
|
50791
|
-
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
50792
|
-
this.inlineMeshCache.set(meshId, mesh);
|
|
50793
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
50794
|
-
return { success: true, mesh };
|
|
50795
|
-
} catch (e) {
|
|
50796
|
-
return { success: false, error: e.message };
|
|
50797
|
-
}
|
|
50798
|
-
}
|
|
50799
|
-
case "get_mesh_host_pairing": {
|
|
50800
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
50801
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
50802
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
50803
|
-
const mesh = meshRecord?.mesh;
|
|
50804
|
-
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
50805
|
-
const meshHost = resolveMeshHostStatus(mesh);
|
|
50806
|
-
const pairingStatus = meshHost.pairing?.status || "not_configured";
|
|
50807
|
-
return {
|
|
50808
|
-
success: true,
|
|
50809
|
-
code: pairingStatus === "not_configured" ? "mesh_host_pairing_not_configured" : "mesh_host_pairing_pending",
|
|
50810
|
-
meshId,
|
|
50811
|
-
hostAddress: meshHost.hostAddress,
|
|
50812
|
-
meshHost,
|
|
50813
|
-
manualPairing: {
|
|
50814
|
-
status: pairingStatus,
|
|
50815
|
-
joinImplemented: true,
|
|
50816
|
-
protocol: "standalone_command_direct_v1",
|
|
50817
|
-
description: "Standalone manual pairing can save address/token metadata, apply a host join over direct standalone command HTTP or injected mesh command dispatch, and check persisted status. P2P signaling remains outside this slice."
|
|
50818
|
-
}
|
|
50819
|
-
};
|
|
50820
|
-
}
|
|
50821
|
-
case "configure_mesh_host_pairing": {
|
|
50822
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
50823
|
-
const hostAddress = typeof args?.hostAddress === "string" ? args.hostAddress.trim() : "";
|
|
50824
|
-
const token = typeof args?.token === "string" ? args.token.trim() : "";
|
|
50825
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
50826
|
-
if (!hostAddress || !token) return { success: false, error: "hostAddress and token required" };
|
|
50827
|
-
try {
|
|
50828
|
-
const { configureMeshHostPairing: configureMeshHostPairing2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50829
|
-
const configured = configureMeshHostPairing2(meshId, { hostAddress, token });
|
|
50830
|
-
if (!configured) return { success: false, error: "Mesh not found" };
|
|
50831
|
-
this.inlineMeshCache.set(meshId, configured.mesh);
|
|
50832
|
-
const meshHost = resolveMeshHostStatus(configured.mesh);
|
|
50833
|
-
return {
|
|
50834
|
-
success: true,
|
|
50835
|
-
code: "mesh_host_pairing_pending",
|
|
50836
|
-
meshId,
|
|
50837
|
-
hostAddress: configured.hostAddress,
|
|
50838
|
-
meshHost,
|
|
50839
|
-
manualPairing: {
|
|
50840
|
-
status: meshHost.pairing?.status || "pairing",
|
|
50841
|
-
joinImplemented: true,
|
|
50842
|
-
protocol: "standalone_command_direct_v1",
|
|
50843
|
-
description: "Manual Mesh Host pairing config was saved locally. Use join_mesh_host_pairing to apply it to the host. Raw token was not persisted."
|
|
50844
|
-
}
|
|
50845
|
-
};
|
|
50846
|
-
} catch (e) {
|
|
50847
|
-
return { success: false, code: "mesh_host_pairing_invalid", meshId, hostAddress, error: e.message };
|
|
50848
|
-
}
|
|
50849
|
-
}
|
|
50850
|
-
case "create_mesh_host_pairing_token": {
|
|
50851
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
50852
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
50853
|
-
try {
|
|
50854
|
-
const { createMeshHostPairingToken: createMeshHostPairingToken2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50855
|
-
const created = createMeshHostPairingToken2(meshId, {
|
|
50856
|
-
token: typeof args?.token === "string" ? args.token : void 0,
|
|
50857
|
-
expiresAt: typeof args?.expiresAt === "string" ? args.expiresAt : void 0
|
|
50858
|
-
});
|
|
50859
|
-
if (!created) return { success: false, error: "Mesh not found" };
|
|
50860
|
-
this.inlineMeshCache.set(meshId, created.mesh);
|
|
50861
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
50862
|
-
return {
|
|
50863
|
-
success: true,
|
|
50864
|
-
code: "mesh_host_pairing_token_created",
|
|
50865
|
-
meshId,
|
|
50866
|
-
token: created.token,
|
|
50867
|
-
tokenId: created.tokenId,
|
|
50868
|
-
expiresAt: created.expiresAt,
|
|
50869
|
-
meshHost: resolveMeshHostStatus(created.mesh),
|
|
50870
|
-
warning: "Raw token is returned once and is not persisted; share it with member daemons over a trusted channel."
|
|
50871
|
-
};
|
|
50872
|
-
} catch (e) {
|
|
50873
|
-
return { success: false, code: "mesh_host_pairing_token_invalid", meshId, error: e.message };
|
|
50874
|
-
}
|
|
50875
|
-
}
|
|
50876
|
-
case "apply_mesh_host_join": {
|
|
50877
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
50878
|
-
const token = typeof args?.token === "string" ? args.token.trim() : "";
|
|
50879
|
-
const memberNode = args?.memberNode && typeof args.memberNode === "object" && !Array.isArray(args.memberNode) ? args.memberNode : null;
|
|
50880
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
50881
|
-
if (!token || !memberNode) return { success: false, error: "token and memberNode required" };
|
|
50882
|
-
try {
|
|
50883
|
-
const { applyMeshHostJoinRequest: applyMeshHostJoinRequest2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50884
|
-
const applied = applyMeshHostJoinRequest2(meshId, {
|
|
50885
|
-
token,
|
|
50886
|
-
memberNode,
|
|
50887
|
-
memberMeshId: typeof args?.memberMeshId === "string" ? args.memberMeshId : void 0
|
|
50888
|
-
});
|
|
50889
|
-
if (!applied) return { success: false, error: "Mesh not found" };
|
|
50890
|
-
if (!applied.accepted) {
|
|
50891
|
-
return {
|
|
50892
|
-
success: false,
|
|
50893
|
-
code: "mesh_host_join_rejected",
|
|
50894
|
-
meshId,
|
|
50895
|
-
tokenId: applied.tokenId,
|
|
50896
|
-
meshHost: applied.meshHost ? resolveMeshHostStatus({ meshHost: applied.meshHost }) : void 0,
|
|
50897
|
-
error: applied.reason
|
|
50898
|
-
};
|
|
50899
|
-
}
|
|
50900
|
-
this.inlineMeshCache.set(meshId, applied.mesh);
|
|
50901
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
50902
|
-
try {
|
|
50903
|
-
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
50904
|
-
appendLedgerEntry2(meshId, {
|
|
50905
|
-
kind: "node_joined",
|
|
50906
|
-
nodeId: applied.node.id,
|
|
50907
|
-
payload: { role: "member", tokenId: applied.tokenId, workspace: applied.node.workspace }
|
|
50908
|
-
});
|
|
50909
|
-
} catch {
|
|
50910
|
-
}
|
|
50911
|
-
return {
|
|
50912
|
-
success: true,
|
|
50913
|
-
code: "mesh_host_join_accepted",
|
|
50914
|
-
meshId,
|
|
50915
|
-
node: applied.node,
|
|
50916
|
-
tokenId: applied.tokenId,
|
|
50917
|
-
meshHost: resolveMeshHostStatus(applied.mesh)
|
|
50918
|
-
};
|
|
50919
|
-
} catch (e) {
|
|
50920
|
-
return { success: false, code: "mesh_host_join_failed", meshId, error: e.message };
|
|
50921
|
-
}
|
|
50922
|
-
}
|
|
50923
|
-
case "join_mesh_host_pairing": {
|
|
50924
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
50925
|
-
const token = typeof args?.token === "string" ? args.token.trim() : "";
|
|
50926
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
50927
|
-
if (!token) return { success: false, error: "token required because raw pairing tokens are not persisted" };
|
|
50928
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
50929
|
-
const mesh = meshRecord?.mesh;
|
|
50930
|
-
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
50931
|
-
const meshHost = resolveMeshHostStatus(mesh);
|
|
50932
|
-
if (meshHost.role !== "member") {
|
|
50933
|
-
return { success: false, code: "mesh_host_join_not_member", meshId, meshHost, error: "join_mesh_host_pairing must run from a member daemon configured with a Mesh Host address/token." };
|
|
50934
|
-
}
|
|
50935
|
-
try {
|
|
50936
|
-
const { tokenIdForManualPairing: tokenIdForManualPairing2, markMeshHostPairingJoined: markMeshHostPairingJoined2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
50937
|
-
const tokenId = tokenIdForManualPairing2(token);
|
|
50938
|
-
if (meshHost.pairing?.tokenId && meshHost.pairing.tokenId !== tokenId) {
|
|
50939
|
-
return { success: false, code: "mesh_host_join_rejected", meshId, tokenId, meshHost, error: "invalid pairing token" };
|
|
50940
|
-
}
|
|
50941
|
-
const memberNode = buildMemberJoinNode(mesh, args, this.deps.statusInstanceId);
|
|
50942
|
-
if (!memberNode) return { success: false, error: "member node metadata unavailable" };
|
|
50943
|
-
const hostMeshId = typeof args?.hostMeshId === "string" && args.hostMeshId.trim() ? args.hostMeshId.trim() : meshId;
|
|
50944
|
-
const hostDaemonId = typeof args?.hostDaemonId === "string" && args.hostDaemonId.trim() ? args.hostDaemonId.trim() : meshHost.hostDaemonId;
|
|
50945
|
-
let hostResult;
|
|
50946
|
-
let transport;
|
|
50947
|
-
if (hostDaemonId && this.deps.dispatchMeshCommand) {
|
|
50948
|
-
transport = "mesh_command_dispatch";
|
|
50949
|
-
hostResult = await this.deps.dispatchMeshCommand(hostDaemonId, "apply_mesh_host_join", {
|
|
50950
|
-
meshId: hostMeshId,
|
|
50951
|
-
token,
|
|
50952
|
-
memberMeshId: meshId,
|
|
50953
|
-
memberNode
|
|
50954
|
-
});
|
|
50955
|
-
} else if (meshHost.hostAddress) {
|
|
50956
|
-
transport = "standalone_http_command";
|
|
50957
|
-
const commandUrl = normalizeStandaloneHostCommandUrl(meshHost.hostAddress);
|
|
50958
|
-
const response = await fetch(commandUrl, {
|
|
50959
|
-
method: "POST",
|
|
50960
|
-
headers: { "Content-Type": "application/json" },
|
|
50961
|
-
body: JSON.stringify({ type: "apply_mesh_host_join", payload: { meshId: hostMeshId, token, memberMeshId: meshId, memberNode } })
|
|
50962
|
-
});
|
|
50963
|
-
hostResult = await response.json().catch(() => ({ success: false, error: `Host returned HTTP ${response.status}` }));
|
|
50964
|
-
if (!response.ok && hostResult?.success !== false) hostResult = { success: false, error: `Host returned HTTP ${response.status}` };
|
|
50965
|
-
} else {
|
|
50966
|
-
return {
|
|
50967
|
-
success: false,
|
|
50968
|
-
code: "mesh_host_join_transport_unavailable",
|
|
50969
|
-
meshId,
|
|
50970
|
-
meshHost,
|
|
50971
|
-
error: "No hostDaemonId dispatch path or hostAddress HTTP command path is available. P2P signaling join is not implemented in this slice."
|
|
50972
|
-
};
|
|
50973
|
-
}
|
|
50974
|
-
if (!hostResult?.success) {
|
|
50975
|
-
return { success: false, code: hostResult?.code || "mesh_host_join_rejected", meshId, meshHost, transport, error: hostResult?.error || "Mesh Host rejected join request", hostResult };
|
|
50976
|
-
}
|
|
50977
|
-
const joined = meshRecord.inline ? null : markMeshHostPairingJoined2(meshId, {
|
|
50978
|
-
tokenId: hostResult.tokenId || tokenId,
|
|
50979
|
-
hostDaemonId: hostResult.meshHost?.hostDaemonId || hostDaemonId,
|
|
50980
|
-
hostNodeId: hostResult.meshHost?.hostNodeId,
|
|
50981
|
-
joinedAt: hostResult.meshHost?.pairing?.joinedAt
|
|
50982
|
-
});
|
|
50983
|
-
if (joined) {
|
|
50984
|
-
this.inlineMeshCache.set(meshId, joined.mesh);
|
|
50985
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
50986
|
-
}
|
|
50987
|
-
return {
|
|
50988
|
-
success: true,
|
|
50989
|
-
code: "mesh_host_join_applied",
|
|
50990
|
-
meshId,
|
|
50991
|
-
hostMeshId,
|
|
50992
|
-
transport,
|
|
50993
|
-
node: hostResult.node,
|
|
50994
|
-
tokenId: hostResult.tokenId || tokenId,
|
|
50995
|
-
meshHost: joined ? resolveMeshHostStatus(joined.mesh) : { ...meshHost, pairing: { ...meshHost.pairing || {}, status: "paired", tokenId: hostResult.tokenId || tokenId } },
|
|
50996
|
-
hostResult,
|
|
50997
|
-
manualPairing: {
|
|
50998
|
-
status: "paired",
|
|
50999
|
-
joinImplemented: true,
|
|
51000
|
-
protocol: "standalone_command_direct_v1",
|
|
51001
|
-
description: "Mesh Host accepted the join and local member pairing status was marked paired. P2P runtime signaling remains outside this slice."
|
|
51002
|
-
}
|
|
51003
|
-
};
|
|
51004
|
-
} catch (e) {
|
|
51005
|
-
return { success: false, code: "mesh_host_join_failed", meshId, meshHost, error: e.message };
|
|
51006
|
-
}
|
|
51007
|
-
}
|
|
51008
|
-
case "delete_mesh": {
|
|
51009
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51010
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
51011
|
-
try {
|
|
51012
|
-
const { deleteMesh: deleteMesh2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
51013
|
-
const deleted = deleteMesh2(meshId);
|
|
51014
|
-
return { success: true, deleted };
|
|
51015
|
-
} catch (e) {
|
|
51016
|
-
return { success: false, error: e.message };
|
|
51017
|
-
}
|
|
51018
|
-
}
|
|
51019
|
-
case "get_mesh_queue": {
|
|
51020
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51021
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
51022
|
-
try {
|
|
51023
|
-
const { getMeshQueueStats: getMeshQueueStats2, getQueue: getQueue2, describeTaskDependencyState: describeTaskDependencyState2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
51024
|
-
const status = Array.isArray(args?.status) ? args.status.map((s2) => typeof s2 === "string" ? s2.trim() : "").filter(Boolean) : void 0;
|
|
51025
|
-
const rawQueue = getQueue2(meshId, { status });
|
|
51026
|
-
const statusById = new Map(getQueue2(meshId).map((task) => [task.id, task.status]));
|
|
51027
|
-
const queue = rawQueue.map((task) => Array.isArray(task.dependsOn) && task.dependsOn.length > 0 ? { ...task, ...describeTaskDependencyState2(task, statusById) } : task);
|
|
51028
|
-
const summary = getMeshQueueStats2(meshId);
|
|
51029
|
-
return {
|
|
51030
|
-
success: true,
|
|
51031
|
-
queue,
|
|
51032
|
-
summary,
|
|
51033
|
-
sourceOfTruth: {
|
|
51034
|
-
kind: "mesh_work_queue_file",
|
|
51035
|
-
activeStatuses: ["pending", "assigned"],
|
|
51036
|
-
historicalStatuses: ["completed", "failed", "cancelled"],
|
|
51037
|
-
notes: "pending/assigned are active work; completed/failed/cancelled are historical records."
|
|
51038
|
-
}
|
|
51039
|
-
};
|
|
51040
|
-
} catch (e) {
|
|
51041
|
-
return { success: false, error: e.message };
|
|
51042
|
-
}
|
|
51043
|
-
}
|
|
51044
|
-
case "cancel_mesh_queue_task": {
|
|
51045
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51046
|
-
const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
|
|
51047
|
-
if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
|
|
51048
|
-
const ownerFailure = await this.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "queue cancellation");
|
|
51049
|
-
if (ownerFailure) return ownerFailure;
|
|
51050
|
-
try {
|
|
51051
|
-
const { cancelTask: cancelTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
51052
|
-
const reason = typeof args?.reason === "string" ? args.reason : void 0;
|
|
51053
|
-
const task = cancelTask2(meshId, taskId, { reason });
|
|
51054
|
-
if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
|
|
51055
|
-
return { success: true, task };
|
|
51056
|
-
} catch (e) {
|
|
51057
|
-
return { success: false, error: e.message };
|
|
51058
|
-
}
|
|
51059
|
-
}
|
|
51060
|
-
case "requeue_mesh_queue_task": {
|
|
51061
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51062
|
-
const taskId = typeof args?.taskId === "string" ? args.taskId.trim() : "";
|
|
51063
|
-
if (!meshId || !taskId) return { success: false, error: "meshId and taskId required" };
|
|
51064
|
-
const ownerFailure = await this.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "queue requeue");
|
|
51065
|
-
if (ownerFailure) return ownerFailure;
|
|
51066
|
-
try {
|
|
51067
|
-
const { requeueTask: requeueTask2 } = await Promise.resolve().then(() => (init_mesh_work_queue(), mesh_work_queue_exports));
|
|
51068
|
-
const task = requeueTask2(meshId, taskId, {
|
|
51069
|
-
reason: typeof args?.reason === "string" ? args.reason : void 0,
|
|
51070
|
-
targetNodeId: typeof args?.targetNodeId === "string" ? args.targetNodeId.trim() : void 0,
|
|
51071
|
-
targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : void 0,
|
|
51072
|
-
clearTargetNode: args?.clearTargetNode === true,
|
|
51073
|
-
clearTargetSession: args?.clearTargetSession !== false
|
|
51074
|
-
});
|
|
51075
|
-
if (!task) return { success: false, error: `Queue task '${taskId}' not found` };
|
|
51076
|
-
return { success: true, task };
|
|
51077
|
-
} catch (e) {
|
|
51078
|
-
return { success: false, error: e.message };
|
|
51079
|
-
}
|
|
51080
|
-
}
|
|
51081
|
-
case "add_mesh_node": {
|
|
51082
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51083
|
-
const workspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
|
|
51084
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
51085
|
-
if (!workspace) return { success: false, error: "workspace required" };
|
|
51086
|
-
const ownerFailure = await this.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "node addition");
|
|
51087
|
-
if (ownerFailure) return ownerFailure;
|
|
51088
|
-
try {
|
|
51089
|
-
const { addNode: addNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
51090
|
-
const providerPriority = Array.isArray(args?.providerPriority) ? args.providerPriority.map((type) => typeof type === "string" ? type.trim() : "").filter(Boolean) : [];
|
|
51091
|
-
const readOnly = args?.readOnly === true;
|
|
51092
|
-
const providerRoles = normalizeProviderRoles(args?.providerRoles);
|
|
51093
|
-
const policy = {
|
|
51094
|
-
...readOnly ? { readOnly: true } : {},
|
|
51095
|
-
...providerPriority.length ? { providerPriority } : {},
|
|
51096
|
-
...providerRoles.length ? { providerRoles } : {}
|
|
51097
|
-
};
|
|
51098
|
-
const role = normalizeMeshDaemonRole(args?.role);
|
|
51099
|
-
const daemonId = typeof args?.daemonId === "string" && args.daemonId.trim() ? args.daemonId.trim() : void 0;
|
|
51100
|
-
const machineId = typeof args?.machineId === "string" && args.machineId.trim() ? args.machineId.trim() : void 0;
|
|
51101
|
-
const repoRoot = typeof args?.repoRoot === "string" && args.repoRoot.trim() ? args.repoRoot.trim() : void 0;
|
|
51102
|
-
const node = addNode2(meshId, {
|
|
51103
|
-
workspace,
|
|
51104
|
-
...repoRoot ? { repoRoot } : {},
|
|
51105
|
-
...daemonId ? { daemonId } : {},
|
|
51106
|
-
...machineId ? { machineId } : {},
|
|
51107
|
-
...policy ? { policy } : {},
|
|
51108
|
-
...role ? { role } : {}
|
|
51109
|
-
});
|
|
51110
|
-
if (!node) return { success: false, error: "Mesh not found" };
|
|
51111
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
51112
|
-
return { success: true, node };
|
|
51113
|
-
} catch (e) {
|
|
51114
|
-
return { success: false, error: e.message };
|
|
51115
|
-
}
|
|
51116
|
-
}
|
|
51117
|
-
case "update_mesh_node": {
|
|
51118
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51119
|
-
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
51120
|
-
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
51121
|
-
const ownerFailure = await this.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "node update");
|
|
51122
|
-
if (ownerFailure) return ownerFailure;
|
|
51123
|
-
try {
|
|
51124
|
-
const { updateNode: updateNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
51125
|
-
const policy = args?.policy && typeof args.policy === "object" && !Array.isArray(args.policy) ? { ...args.policy } : {};
|
|
51126
|
-
if (Array.isArray(args?.providerPriority)) {
|
|
51127
|
-
const providerPriority = args.providerPriority.map((type) => typeof type === "string" ? type.trim() : "").filter(Boolean);
|
|
51128
|
-
delete policy.provider_priority;
|
|
51129
|
-
if (providerPriority.length) {
|
|
51130
|
-
policy.providerPriority = providerPriority;
|
|
51131
|
-
} else {
|
|
51132
|
-
delete policy.providerPriority;
|
|
51133
|
-
}
|
|
51134
|
-
}
|
|
51135
|
-
if (Array.isArray(args?.providerRoles)) {
|
|
51136
|
-
const providerRoles = normalizeProviderRoles(args.providerRoles);
|
|
51137
|
-
if (providerRoles.length) {
|
|
51138
|
-
policy.providerRoles = providerRoles;
|
|
51139
|
-
} else {
|
|
51140
|
-
delete policy.providerRoles;
|
|
51141
|
-
}
|
|
51142
|
-
}
|
|
51143
|
-
const patch = { policy };
|
|
51144
|
-
if (typeof args?.systemPrompt === "string") {
|
|
51145
|
-
const trimmed = args.systemPrompt.trim();
|
|
51146
|
-
patch.systemPrompt = trimmed || void 0;
|
|
51147
|
-
} else if (args?.systemPrompt === null) {
|
|
51148
|
-
patch.systemPrompt = void 0;
|
|
51149
|
-
}
|
|
51150
|
-
const node = updateNode2(meshId, nodeId, patch);
|
|
51151
|
-
if (!node) return { success: false, error: "Mesh node not found" };
|
|
51152
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
51153
|
-
return { success: true, node };
|
|
51154
|
-
} catch (e) {
|
|
51155
|
-
return { success: false, error: e.message };
|
|
51156
|
-
}
|
|
51157
|
-
}
|
|
51158
|
-
case "cleanup_mesh_sessions": {
|
|
51159
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51160
|
-
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
51161
|
-
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
51162
|
-
const ownerFailure = await this.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "node removal");
|
|
51163
|
-
if (ownerFailure) return ownerFailure;
|
|
51164
|
-
try {
|
|
51165
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
51166
|
-
const mesh = meshRecord?.mesh;
|
|
51167
|
-
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
51168
|
-
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
51169
|
-
if (!node) return { success: false, error: `Node '${nodeId}' not found in mesh` };
|
|
51170
|
-
const mode = this.normalizeMeshSessionCleanupMode(args?.mode ?? mesh?.policy?.sessionCleanupOnNodeRemove);
|
|
51171
|
-
const sessionIds = Array.isArray(args?.sessionIds) ? args.sessionIds.map((id) => typeof id === "string" ? id.trim() : "").filter(Boolean) : void 0;
|
|
51172
|
-
const result = await this.cleanupMeshSessions({
|
|
51173
|
-
meshId,
|
|
51174
|
-
nodeId,
|
|
51175
|
-
node,
|
|
51176
|
-
mode,
|
|
51177
|
-
sessionIds,
|
|
51178
|
-
dryRun: args?.dryRun === true,
|
|
51179
|
-
source: "mesh_cleanup_sessions"
|
|
51180
|
-
});
|
|
51181
|
-
return result;
|
|
51182
|
-
} catch (e) {
|
|
51183
|
-
return { success: false, error: e.message };
|
|
51184
|
-
}
|
|
51185
|
-
}
|
|
51186
|
-
case "mesh_init": {
|
|
51187
|
-
const workspace = typeof args?.workspace === "string" && args.workspace.trim() ? args.workspace.trim() : process.cwd();
|
|
51188
|
-
const mesh = args?.inlineMesh || {};
|
|
51189
|
-
try {
|
|
51190
|
-
const detected = await detectCLIs(this.deps.providerLoader, { includeVersion: true });
|
|
51191
|
-
return { ...runMeshInit(mesh, workspace, detected, {
|
|
51192
|
-
write: args?.write === true,
|
|
51193
|
-
overwrite: args?.overwrite === true
|
|
51194
|
-
}) };
|
|
51195
|
-
} catch (e) {
|
|
51196
|
-
return { success: false, error: e?.message || String(e) };
|
|
51197
|
-
}
|
|
51198
|
-
}
|
|
51199
|
-
case "plan_mesh_refine_node": {
|
|
51200
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51201
|
-
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
51202
|
-
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
51203
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
51204
|
-
const mesh = meshRecord?.mesh;
|
|
51205
|
-
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
51206
|
-
if (!node?.workspace) return { success: false, error: `Node '${nodeId}' workspace not found` };
|
|
51207
|
-
return {
|
|
51208
|
-
success: true,
|
|
51209
|
-
dryRun: true,
|
|
51210
|
-
nodeId,
|
|
51211
|
-
workspace: node.workspace,
|
|
51212
|
-
validationPlan: buildMeshRefineValidationPlan(mesh, node.workspace),
|
|
51213
|
-
mergeWillRun: false,
|
|
51214
|
-
cleanupWillRun: false
|
|
51215
|
-
};
|
|
51216
|
-
}
|
|
51217
|
-
case "fast_forward_mesh_node": {
|
|
51218
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51219
|
-
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
51220
|
-
let workspace = typeof args?.workspace === "string" ? args.workspace.trim() : "";
|
|
51221
|
-
let submoduleIgnorePaths = Array.isArray(args?.submoduleIgnorePaths) ? args.submoduleIgnorePaths.filter((value) => typeof value === "string") : void 0;
|
|
51222
|
-
let nodeDaemonId;
|
|
51223
|
-
let allowAutoPublishSubmoduleMainCommits = false;
|
|
51224
|
-
if (meshId && nodeId) {
|
|
51225
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
51226
|
-
const mesh = meshRecord?.mesh;
|
|
51227
|
-
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
51228
|
-
if (!workspace) {
|
|
51229
|
-
workspace = typeof node?.workspace === "string" ? node.workspace.trim() : "";
|
|
51230
|
-
}
|
|
51231
|
-
if (!submoduleIgnorePaths && Array.isArray(node?.policy?.submoduleIgnorePaths)) {
|
|
51232
|
-
submoduleIgnorePaths = node.policy.submoduleIgnorePaths.filter((value) => typeof value === "string");
|
|
51233
|
-
}
|
|
51234
|
-
allowAutoPublishSubmoduleMainCommits = mesh?.policy?.allowAutoPublishSubmoduleMainCommits === true;
|
|
51235
|
-
nodeDaemonId = typeof node?.daemonId === "string" ? node.daemonId.trim() : void 0;
|
|
51236
|
-
}
|
|
51237
|
-
const selfDaemonId = this.deps.statusInstanceId;
|
|
51238
|
-
const isRemote = nodeDaemonId && selfDaemonId && !daemonIdsEquivalent(nodeDaemonId, selfDaemonId);
|
|
51239
|
-
if (isRemote && this.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
|
|
51240
|
-
const forwarded = await this.deps.dispatchMeshCommand(nodeDaemonId, "fast_forward_mesh_node", {
|
|
51241
|
-
...typeof args === "object" && args !== null ? args : {},
|
|
51242
|
-
workspace,
|
|
51243
|
-
_meshDirectDispatch: true
|
|
51244
|
-
});
|
|
51245
|
-
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
51246
|
-
}
|
|
51247
|
-
const result = await fastForwardMeshNode({
|
|
51248
|
-
meshId: meshId || void 0,
|
|
51249
|
-
nodeId: nodeId || void 0,
|
|
51250
|
-
workspace,
|
|
51251
|
-
branch: typeof args?.branch === "string" ? args.branch : void 0,
|
|
51252
|
-
execute: args?.execute === true,
|
|
51253
|
-
dryRun: args?.dryRun === true,
|
|
51254
|
-
updateSubmodules: args?.updateSubmodules === true,
|
|
51255
|
-
submoduleIgnorePaths,
|
|
51256
|
-
mode: args?.mode === "push" ? "push" : "merge",
|
|
51257
|
-
pushSubmodules: args?.pushSubmodules === true,
|
|
51258
|
-
allowAutoPublishSubmoduleMainCommits
|
|
51259
|
-
});
|
|
51260
|
-
return result;
|
|
51261
|
-
}
|
|
51262
|
-
case "refine_mesh_node": {
|
|
51263
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51264
|
-
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
51265
|
-
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
51266
|
-
{
|
|
51267
|
-
const meshRecordForForward = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
51268
|
-
const forwardNode = meshRecordForForward?.mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
51269
|
-
const nodeDaemonId = typeof forwardNode?.daemonId === "string" ? forwardNode.daemonId.trim() : void 0;
|
|
51270
|
-
const selfDaemonId = this.deps.statusInstanceId;
|
|
51271
|
-
const isRemote = nodeDaemonId && selfDaemonId && !daemonIdsEquivalent(nodeDaemonId, selfDaemonId);
|
|
51272
|
-
if (isRemote && this.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
|
|
51273
|
-
const callerCoordinatorDaemonId = typeof args?.coordinatorDaemonId === "string" && args.coordinatorDaemonId.trim() ? args.coordinatorDaemonId.trim() : void 0;
|
|
51274
|
-
const forwarded = await this.deps.dispatchMeshCommand(nodeDaemonId, "refine_mesh_node", {
|
|
51275
|
-
...typeof args === "object" && args !== null ? args : {},
|
|
51276
|
-
coordinatorDaemonId: callerCoordinatorDaemonId || selfDaemonId,
|
|
51277
|
-
_meshDirectDispatch: true
|
|
51278
|
-
});
|
|
51279
|
-
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
51280
|
-
}
|
|
51281
|
-
}
|
|
51282
|
-
const isDryRun = args?.dryRun !== false && args?.execute !== true;
|
|
51283
|
-
if (isDryRun) {
|
|
51284
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
51285
|
-
const mesh = meshRecord?.mesh;
|
|
51286
|
-
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
51287
|
-
if (!node?.workspace) return { success: false, error: `Node '${nodeId}' workspace not found` };
|
|
51288
|
-
return {
|
|
51289
|
-
success: true,
|
|
51290
|
-
dryRun: true,
|
|
51291
|
-
nodeId,
|
|
51292
|
-
workspace: node.workspace,
|
|
51293
|
-
validationPlan: buildMeshRefineValidationPlan(mesh, node.workspace),
|
|
51294
|
-
mergeWillRun: false,
|
|
51295
|
-
cleanupWillRun: false,
|
|
51296
|
-
hint: "Dry-run only \u2014 no merge/push/cleanup performed. Re-invoke with execute:true to converge this node."
|
|
51297
|
-
};
|
|
51298
|
-
}
|
|
51299
|
-
return this.startMeshRefineJob(meshId, nodeId, args);
|
|
51300
|
-
}
|
|
51301
|
-
case "batch_refine_mesh_nodes": {
|
|
51302
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51303
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
51304
|
-
const requestedNodeIds = Array.isArray(args?.nodeIds) ? args.nodeIds.filter((v) => typeof v === "string" && v.trim().length > 0).map((v) => v.trim()) : void 0;
|
|
51305
|
-
const isDryRun = args?.dryRun !== false && args?.execute !== true;
|
|
51306
|
-
if (isDryRun) return this.batchRefineMeshNodes(meshId, requestedNodeIds, args);
|
|
51307
|
-
return this.startMeshRefineBatchJob(meshId, requestedNodeIds, args);
|
|
51308
|
-
}
|
|
51309
|
-
case "remove_mesh_node": {
|
|
51310
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51311
|
-
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
51312
|
-
if (!meshId || !nodeId) return { success: false, error: "meshId and nodeId required" };
|
|
51313
|
-
try {
|
|
51314
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
51315
|
-
const mesh = meshRecord?.mesh;
|
|
51316
|
-
const node = mesh?.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
51317
|
-
if (node && !args?._meshDirectDispatch && node.isLocalWorktree !== true && args?.force !== true) {
|
|
51318
|
-
const nodeDaemonId = typeof node.daemonId === "string" ? node.daemonId.trim() : "";
|
|
51319
|
-
const nodeMachineId = readMeshNodeMachineId(node) || "";
|
|
51320
|
-
const selfDaemonId = this.deps.statusInstanceId || "";
|
|
51321
|
-
const selfMachineId = (() => {
|
|
51322
|
-
try {
|
|
51323
|
-
return loadConfig().machineId || "";
|
|
51324
|
-
} catch {
|
|
51325
|
-
return "";
|
|
51326
|
-
}
|
|
51327
|
-
})();
|
|
51328
|
-
const isCoordinatorBaseNode = !!selfDaemonId && (nodeDaemonId === selfDaemonId || nodeMachineId === selfDaemonId) || !!selfMachineId && (nodeDaemonId === selfMachineId || nodeMachineId === selfMachineId);
|
|
51329
|
-
if (isCoordinatorBaseNode) {
|
|
51330
|
-
return {
|
|
51331
|
-
success: false,
|
|
51332
|
-
removed: false,
|
|
51333
|
-
code: "mesh_remove_coordinator_base_node_protected",
|
|
51334
|
-
error: `Refusing to remove the coordinator's own base node '${typeof node.workspace === "string" ? node.workspace : nodeId}'. It is the local non-worktree node bound to this coordinator daemon; removing it breaks live mesh membership and forces a restart.`,
|
|
51335
|
-
recoveryHint: "Remove worktree clone nodes instead, or pass force:true only if you are intentionally tearing down this mesh and accept that the coordinator must be re-registered/restarted."
|
|
51336
|
-
};
|
|
51337
|
-
}
|
|
51338
|
-
}
|
|
51339
|
-
const sessionCleanupMode = this.normalizeMeshSessionCleanupMode(
|
|
51340
|
-
args?.sessionCleanupMode ?? args?.session_cleanup_mode ?? mesh?.policy?.sessionCleanupOnNodeRemove
|
|
51341
|
-
);
|
|
51342
|
-
const explicitSessionIds = Array.isArray(args?.sessionIds) ? args.sessionIds.filter((v) => typeof v === "string" && v.trim().length > 0).map((v) => v.trim()) : void 0;
|
|
51343
|
-
let sessionCleanup;
|
|
51344
|
-
if (node && sessionCleanupMode !== "preserve") {
|
|
51345
|
-
sessionCleanup = await this.cleanupMeshSessions({
|
|
51346
|
-
meshId,
|
|
51347
|
-
nodeId,
|
|
51348
|
-
node,
|
|
51349
|
-
mode: sessionCleanupMode,
|
|
51350
|
-
...explicitSessionIds && explicitSessionIds.length > 0 ? { sessionIds: explicitSessionIds } : {},
|
|
51351
|
-
source: "mesh_remove_node"
|
|
51352
|
-
});
|
|
51353
|
-
if (sessionCleanup.success === false) return { success: false, removed: false, sessionCleanup };
|
|
51354
|
-
}
|
|
51355
|
-
let worktreeCleanup;
|
|
51356
|
-
if (node?.isLocalWorktree) {
|
|
51357
|
-
const nodeDaemonId = typeof node.daemonId === "string" ? node.daemonId.trim() : void 0;
|
|
51358
|
-
const isRemoteWorktree = nodeDaemonId && !daemonIdsEquivalent(nodeDaemonId, this.deps.statusInstanceId) && this.deps.dispatchMeshCommand && !args?._meshDirectDispatch;
|
|
51359
|
-
if (isRemoteWorktree) {
|
|
51360
|
-
const forwarded = await this.deps.dispatchMeshCommand(nodeDaemonId, "remove_mesh_node", {
|
|
51361
|
-
...typeof args === "object" && args !== null ? args : {},
|
|
51362
|
-
_meshDirectDispatch: true
|
|
51363
|
-
});
|
|
51364
|
-
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
51365
|
-
}
|
|
51366
|
-
const cleanupResult = await this.cleanupLocalWorktreeNode({ mesh, node, nodeId, force: args?.force === true });
|
|
51367
|
-
if (cleanupResult.success === false) {
|
|
51368
|
-
return {
|
|
51369
|
-
success: false,
|
|
51370
|
-
removed: false,
|
|
51371
|
-
code: cleanupResult.code,
|
|
51372
|
-
error: cleanupResult.error,
|
|
51373
|
-
recoveryHint: cleanupResult.recoveryHint,
|
|
51374
|
-
...sessionCleanup ? { sessionCleanup } : {},
|
|
51375
|
-
worktreeCleanup: cleanupResult
|
|
51376
|
-
};
|
|
51377
|
-
}
|
|
51378
|
-
worktreeCleanup = cleanupResult;
|
|
51379
|
-
}
|
|
51380
|
-
let removed = false;
|
|
51381
|
-
if (meshRecord?.inline) {
|
|
51382
|
-
removed = this.removeInlineMeshNode(meshId, mesh, nodeId);
|
|
51383
|
-
if (removed) this.invalidateAggregateMeshStatus(meshId);
|
|
51384
|
-
if (!removed && !node) removed = true;
|
|
51385
|
-
} else {
|
|
51386
|
-
const { removeNode: removeNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
51387
|
-
removed = removeNode2(meshId, nodeId);
|
|
51388
|
-
if (!removed && !node) removed = true;
|
|
51389
|
-
if (removed) this.invalidateAggregateMeshStatus(meshId);
|
|
51390
|
-
}
|
|
51391
|
-
if (removed) {
|
|
51392
|
-
try {
|
|
51393
|
-
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
51394
|
-
appendLedgerEntry2(meshId, {
|
|
51395
|
-
kind: "node_removed",
|
|
51396
|
-
nodeId,
|
|
51397
|
-
payload: {
|
|
51398
|
-
worktree: !!node?.isLocalWorktree,
|
|
51399
|
-
sessionCleanupMode,
|
|
51400
|
-
workspace: typeof node?.workspace === "string" ? node.workspace : void 0,
|
|
51401
|
-
daemonId: typeof node?.daemonId === "string" ? node.daemonId : void 0,
|
|
51402
|
-
worktreeBranch: typeof node?.worktreeBranch === "string" ? node.worktreeBranch : void 0,
|
|
51403
|
-
worktreeCleanupFallback: typeof worktreeCleanup?.fallback === "string" ? worktreeCleanup.fallback : void 0,
|
|
51404
|
-
forced: worktreeCleanup?.forced === true ? true : void 0,
|
|
51405
|
-
forceFallbackReason: typeof worktreeCleanup?.reason === "string" ? worktreeCleanup.reason : void 0
|
|
51406
|
-
}
|
|
51407
|
-
});
|
|
51408
|
-
} catch {
|
|
51409
|
-
}
|
|
51410
|
-
}
|
|
51411
|
-
const residueWarning = worktreeCleanup?.residue === true && typeof worktreeCleanup?.residueWarning === "string" ? worktreeCleanup.residueWarning : void 0;
|
|
51412
|
-
return {
|
|
51413
|
-
success: true,
|
|
51414
|
-
removed,
|
|
51415
|
-
...residueWarning ? { residueWarning } : {},
|
|
51416
|
-
...sessionCleanup ? { sessionCleanup } : {},
|
|
51417
|
-
...worktreeCleanup ? { worktreeCleanup } : {}
|
|
51418
|
-
};
|
|
51419
|
-
} catch (e) {
|
|
51420
|
-
return { success: false, error: e.message };
|
|
51421
|
-
}
|
|
51422
|
-
}
|
|
51423
|
-
case "clone_mesh_node": {
|
|
51424
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51425
|
-
const sourceNodeId = typeof args?.sourceNodeId === "string" ? args.sourceNodeId.trim() : "";
|
|
51426
|
-
const branch = typeof args?.branch === "string" ? args.branch.trim() : "";
|
|
51427
|
-
const baseBranch = typeof args?.baseBranch === "string" ? args.baseBranch.trim() : void 0;
|
|
51428
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
51429
|
-
if (!sourceNodeId) return { success: false, error: "sourceNodeId required" };
|
|
51430
|
-
if (!branch) return { success: false, error: "branch required" };
|
|
51431
|
-
const ownerFailure = await this.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "worktree clone");
|
|
51432
|
-
if (ownerFailure) return ownerFailure;
|
|
51433
|
-
try {
|
|
51434
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
51435
|
-
const mesh = meshRecord?.mesh;
|
|
51436
|
-
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
51437
|
-
const sourceNode = mesh.nodes?.find((n) => meshNodeIdMatches(n, sourceNodeId));
|
|
51438
|
-
if (!sourceNode) return { success: false, error: `Source node '${sourceNodeId}' not found in mesh` };
|
|
51439
|
-
const sourceDaemonId = typeof sourceNode.daemonId === "string" ? sourceNode.daemonId.trim() : void 0;
|
|
51440
|
-
if (sourceDaemonId && !daemonIdsEquivalent(sourceDaemonId, this.deps.statusInstanceId) && this.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
|
|
51441
|
-
const forwarded = await this.deps.dispatchMeshCommand(sourceDaemonId, "clone_mesh_node", {
|
|
51442
|
-
...typeof args === "object" && args !== null ? args : {},
|
|
51443
|
-
_meshDirectDispatch: true
|
|
51444
|
-
});
|
|
51445
|
-
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
51446
|
-
}
|
|
51447
|
-
const repoRoot = sourceNode.repoRoot || sourceNode.workspace;
|
|
51448
|
-
const { createWorktree: createWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
51449
|
-
const result = await createWorktree2({
|
|
51450
|
-
repoRoot,
|
|
51451
|
-
branch,
|
|
51452
|
-
baseBranch,
|
|
51453
|
-
meshName: mesh.name
|
|
51454
|
-
});
|
|
51455
|
-
let node;
|
|
51456
|
-
if (meshRecord.inline) {
|
|
51457
|
-
const { randomUUID: randomUUID15 } = await import("crypto");
|
|
51458
|
-
node = {
|
|
51459
|
-
id: `node_${randomUUID15().replace(/-/g, "")}`,
|
|
51460
|
-
workspace: result.worktreePath,
|
|
51461
|
-
repoRoot: result.worktreePath,
|
|
51462
|
-
daemonId: sourceNode.daemonId,
|
|
51463
|
-
machineId: sourceNode.machineId ?? sourceNode.machine_id,
|
|
51464
|
-
userOverrides: { ...sourceNode.userOverrides || {} },
|
|
51465
|
-
policy: { ...sourceNode.policy || {} },
|
|
51466
|
-
isLocalWorktree: true,
|
|
51467
|
-
worktreeBranch: result.branch,
|
|
51468
|
-
clonedFromNodeId: sourceNodeId
|
|
51469
|
-
};
|
|
51470
|
-
this.updateInlineMeshNode(meshId, mesh, node);
|
|
51471
|
-
} else {
|
|
51472
|
-
const { addNode: addNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
51473
|
-
node = addNode2(meshId, {
|
|
51474
|
-
workspace: result.worktreePath,
|
|
51475
|
-
repoRoot: result.worktreePath,
|
|
51476
|
-
daemonId: sourceNode.daemonId,
|
|
51477
|
-
machineId: sourceNode.machineId ?? sourceNode.machine_id,
|
|
51478
|
-
userOverrides: { ...sourceNode.userOverrides || {} },
|
|
51479
|
-
isLocalWorktree: true,
|
|
51480
|
-
worktreeBranch: result.branch,
|
|
51481
|
-
clonedFromNodeId: sourceNodeId,
|
|
51482
|
-
policy: { ...sourceNode.policy || {} }
|
|
51483
|
-
});
|
|
51484
|
-
if (!node) return { success: false, error: "Failed to register worktree node" };
|
|
51485
|
-
const inlineForReconcile = this.getCachedInlineMesh(meshId);
|
|
51486
|
-
if (inlineForReconcile) this.updateInlineMeshNode(meshId, inlineForReconcile, node);
|
|
51487
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
51488
|
-
}
|
|
51489
|
-
const persistWorktreeSetupState = async (bootstrapState2) => {
|
|
51490
|
-
node.worktreeBootstrap = bootstrapState2;
|
|
51491
|
-
if (meshRecord.inline) {
|
|
51492
|
-
this.updateInlineMeshNode(meshId, mesh, node);
|
|
51493
|
-
return;
|
|
51494
|
-
}
|
|
51495
|
-
try {
|
|
51496
|
-
const { updateNode: updateNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
51497
|
-
updateNode2(meshId, node.id, { worktreeBootstrap: bootstrapState2 });
|
|
51498
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
51499
|
-
} catch {
|
|
51500
|
-
}
|
|
51501
|
-
};
|
|
51502
|
-
const appendCloneLedger = async (initSubmodules2, bootstrapState2) => {
|
|
51503
|
-
try {
|
|
51504
|
-
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
51505
|
-
appendLedgerEntry2(meshId, {
|
|
51506
|
-
kind: "node_cloned",
|
|
51507
|
-
nodeId: node.id,
|
|
51508
|
-
payload: {
|
|
51509
|
-
sourceNodeId,
|
|
51510
|
-
branch: result.branch,
|
|
51511
|
-
worktreePath: result.worktreePath,
|
|
51512
|
-
submodulesInitialized: initSubmodules2,
|
|
51513
|
-
worktreeBootstrap: {
|
|
51514
|
-
status: bootstrapState2.status,
|
|
51515
|
-
required: bootstrapState2.required,
|
|
51516
|
-
configSource: bootstrapState2.configSource,
|
|
51517
|
-
configSourceType: bootstrapState2.configSourceType,
|
|
51518
|
-
lastCommand: bootstrapState2.lastCommand,
|
|
51519
|
-
exitCode: bootstrapState2.exitCode
|
|
51520
|
-
}
|
|
51521
|
-
}
|
|
51522
|
-
});
|
|
51523
|
-
} catch {
|
|
51524
|
-
}
|
|
51525
|
-
};
|
|
51526
|
-
const initSubmodules = sourceNode.policy?.initSubmodulesOnClone !== false;
|
|
51527
|
-
const loadedBootstrap = loadMeshWorktreeBootstrapConfig(mesh, result.worktreePath);
|
|
51528
|
-
const runningBootstrapState = {
|
|
51529
|
-
status: "running",
|
|
51530
|
-
required: loadedBootstrap.config?.required !== false,
|
|
51531
|
-
configSource: loadedBootstrap.path || loadedBootstrap.source,
|
|
51532
|
-
configSourceType: loadedBootstrap.sourceType,
|
|
51533
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
51534
|
-
};
|
|
51535
|
-
await persistWorktreeSetupState(runningBootstrapState);
|
|
51536
|
-
const finishWorktreeSetup = async () => {
|
|
51537
|
-
let submodulesInitialized2 = false;
|
|
51538
|
-
if (initSubmodules) {
|
|
51539
|
-
try {
|
|
51540
|
-
const { runGit: runGit3 } = await Promise.resolve().then(() => (init_git_executor(), git_executor_exports));
|
|
51541
|
-
await runGit3(
|
|
51542
|
-
{ workspace: result.worktreePath, repoRoot: result.worktreePath, isGitRepo: true },
|
|
51543
|
-
["submodule", "update", "--init", "--recursive"],
|
|
51544
|
-
{ timeoutMs: 12e4 }
|
|
51545
|
-
);
|
|
51546
|
-
submodulesInitialized2 = true;
|
|
51547
|
-
const sourceWorkspace = sourceNode.repoRoot || sourceNode.workspace;
|
|
51548
|
-
if (sourceWorkspace) {
|
|
51549
|
-
try {
|
|
51550
|
-
const { runGit: rg } = await Promise.resolve().then(() => (init_git_executor(), git_executor_exports));
|
|
51551
|
-
const sourceCtx = { workspace: sourceWorkspace, repoRoot: sourceWorkspace, isGitRepo: true };
|
|
51552
|
-
const worktreeCtx = { workspace: result.worktreePath, repoRoot: result.worktreePath, isGitRepo: true };
|
|
51553
|
-
const sourceStatusOut = await rg(sourceCtx, ["submodule", "status", "oss"], { timeoutMs: 1e4 });
|
|
51554
|
-
const sourceStatusLine = (typeof sourceStatusOut === "string" ? sourceStatusOut : sourceStatusOut?.stdout ?? "").trim();
|
|
51555
|
-
const sourceShaMatch = sourceStatusLine.match(/^[+\- ]?([0-9a-f]{40})/);
|
|
51556
|
-
const sourceSha = sourceShaMatch?.[1];
|
|
51557
|
-
if (sourceSha) {
|
|
51558
|
-
const ossCtx = { workspace: `${result.worktreePath}/oss`, repoRoot: `${result.worktreePath}/oss`, isGitRepo: true };
|
|
51559
|
-
const worktreeOssHeadOut = await rg(ossCtx, ["rev-parse", "HEAD"], { timeoutMs: 1e4 });
|
|
51560
|
-
const worktreeOssSha = (typeof worktreeOssHeadOut === "string" ? worktreeOssHeadOut : worktreeOssHeadOut?.stdout ?? "").trim();
|
|
51561
|
-
if (worktreeOssSha !== sourceSha) {
|
|
51562
|
-
await rg(ossCtx, ["fetch", `${sourceWorkspace}/oss`, "HEAD"], { timeoutMs: 6e4 });
|
|
51563
|
-
await rg(ossCtx, ["checkout", sourceSha], { timeoutMs: 1e4 });
|
|
51564
|
-
await rg(worktreeCtx, ["add", "oss"], { timeoutMs: 1e4 });
|
|
51565
|
-
await rg(worktreeCtx, ["commit", "-m", "chore: sync oss to source node HEAD on clone"], { timeoutMs: 1e4 });
|
|
51566
|
-
console.log(`[mesh] Synced oss submodule to source HEAD ${sourceSha.slice(0, 8)} in worktree`);
|
|
51567
|
-
}
|
|
51568
|
-
}
|
|
51569
|
-
} catch (ossErr) {
|
|
51570
|
-
console.warn("[mesh] oss submodule sync to source HEAD failed (best-effort):", ossErr.message);
|
|
51571
|
-
}
|
|
51572
|
-
}
|
|
51573
|
-
} catch (subErr) {
|
|
51574
|
-
console.warn("[mesh] Submodule init failed for worktree:", subErr.message);
|
|
51575
|
-
}
|
|
51576
|
-
}
|
|
51577
|
-
const bootstrapState2 = await runMeshWorktreeBootstrap(mesh, result.worktreePath);
|
|
51578
|
-
await persistWorktreeSetupState(bootstrapState2);
|
|
51579
|
-
await appendCloneLedger(submodulesInitialized2, bootstrapState2);
|
|
51580
|
-
return { submodulesInitialized: submodulesInitialized2, bootstrapState: bootstrapState2 };
|
|
51581
|
-
};
|
|
51582
|
-
const requestedSetupWaitMs = Number(args?.setupWaitMs ?? args?.bootstrapWaitMs ?? 8e3);
|
|
51583
|
-
const setupWaitMs = Number.isFinite(requestedSetupWaitMs) ? Math.min(Math.max(requestedSetupWaitMs, 0), 14e3) : 8e3;
|
|
51584
|
-
const setupPromise = finishWorktreeSetup();
|
|
51585
|
-
const setupResult = await Promise.race([
|
|
51586
|
-
setupPromise.then((value) => ({ completed: true, value })),
|
|
51587
|
-
new Promise((resolve24) => setTimeout(() => resolve24({ completed: false }), setupWaitMs))
|
|
51588
|
-
]);
|
|
51589
|
-
const emitBootstrapEvent = (eventStatus2, bootstrapState2, startedAtMs, extraPayload) => {
|
|
51590
|
-
try {
|
|
51591
|
-
const durationMs = Date.now() - startedAtMs;
|
|
51592
|
-
const event = `worktree_${eventStatus2}`;
|
|
51593
|
-
const metadataEvent = {
|
|
51594
|
-
source: "clone_mesh_node_bootstrap",
|
|
51595
|
-
nodeId: node.id,
|
|
51596
|
-
status: eventStatus2,
|
|
51597
|
-
worktreePath: result.worktreePath,
|
|
51598
|
-
durationMs,
|
|
51599
|
-
bootstrapStatus: bootstrapState2.status,
|
|
51600
|
-
...bootstrapState2.error ? { error: bootstrapState2.error } : {},
|
|
51601
|
-
...bootstrapState2.exitCode !== void 0 ? { exitCode: bootstrapState2.exitCode } : {},
|
|
51602
|
-
...extraPayload || {}
|
|
51603
|
-
};
|
|
51604
|
-
if (typeof this.deps.instanceManager?.getByCategory === "function") {
|
|
51605
|
-
const forwarded = handleMeshForwardEvent(
|
|
51606
|
-
{ instanceManager: this.deps.instanceManager },
|
|
51607
|
-
{ event, meshId, nodeId: node.id, workspace: result.worktreePath, metadataEvent }
|
|
51608
|
-
);
|
|
51609
|
-
if (forwarded?.success === true) return;
|
|
51610
|
-
}
|
|
51611
|
-
queuePendingMeshCoordinatorEvent({
|
|
51612
|
-
event,
|
|
51613
|
-
meshId,
|
|
51614
|
-
nodeLabel: node.id,
|
|
51615
|
-
nodeId: node.id,
|
|
51616
|
-
workspace: result.worktreePath,
|
|
51617
|
-
metadataEvent,
|
|
51618
|
-
queuedAt: Date.now()
|
|
51619
|
-
});
|
|
51620
|
-
} catch {
|
|
51621
|
-
}
|
|
51622
|
-
};
|
|
51623
|
-
const bootstrapStartedMs = Date.now();
|
|
51624
|
-
if (!setupResult.completed) {
|
|
51625
|
-
setupPromise.then(({ bootstrapState: bootstrapState2 }) => {
|
|
51626
|
-
emitBootstrapEvent("bootstrap_complete", bootstrapState2, bootstrapStartedMs);
|
|
51627
|
-
}).catch((error) => {
|
|
51628
|
-
const failedState = {
|
|
51629
|
-
...runningBootstrapState,
|
|
51630
|
-
status: "failed",
|
|
51631
|
-
completedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
51632
|
-
error: error?.message || String(error)
|
|
51633
|
-
};
|
|
51634
|
-
void persistWorktreeSetupState(failedState);
|
|
51635
|
-
void appendCloneLedger(false, failedState);
|
|
51636
|
-
emitBootstrapEvent("bootstrap_failed", failedState, bootstrapStartedMs, { error: error?.message || String(error) });
|
|
51637
|
-
});
|
|
51638
|
-
return {
|
|
51639
|
-
success: true,
|
|
51640
|
-
async: true,
|
|
51641
|
-
status: "accepted",
|
|
51642
|
-
node,
|
|
51643
|
-
worktreePath: result.worktreePath,
|
|
51644
|
-
branch: result.branch,
|
|
51645
|
-
worktreeBootstrap: runningBootstrapState,
|
|
51646
|
-
worktreeSetup: {
|
|
51647
|
-
status: "running",
|
|
51648
|
-
setupWaitMs,
|
|
51649
|
-
message: "Worktree node is registered; submodule/bootstrap setup is continuing in the background."
|
|
51650
|
-
}
|
|
51651
|
-
};
|
|
51652
|
-
}
|
|
51653
|
-
const { submodulesInitialized, bootstrapState } = setupResult.value;
|
|
51654
|
-
emitBootstrapEvent("bootstrap_complete", bootstrapState, bootstrapStartedMs);
|
|
51655
|
-
return {
|
|
51656
|
-
success: true,
|
|
51657
|
-
node,
|
|
51658
|
-
worktreePath: result.worktreePath,
|
|
51659
|
-
branch: result.branch,
|
|
51660
|
-
submodulesInitialized,
|
|
51661
|
-
worktreeBootstrap: bootstrapState
|
|
51662
|
-
};
|
|
51663
|
-
} catch (e) {
|
|
51664
|
-
return { success: false, error: e.message };
|
|
51665
|
-
}
|
|
51666
|
-
}
|
|
51667
|
-
case "retry_mesh_node_bootstrap": {
|
|
51668
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51669
|
-
const nodeId = typeof args?.nodeId === "string" ? args.nodeId.trim() : "";
|
|
51670
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
51671
|
-
if (!nodeId) return { success: false, error: "nodeId required" };
|
|
51672
|
-
const ownerFailure = await this.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "bootstrap retry");
|
|
51673
|
-
if (ownerFailure) return ownerFailure;
|
|
51674
|
-
try {
|
|
51675
|
-
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
51676
|
-
const mesh = meshRecord?.mesh;
|
|
51677
|
-
if (!mesh) return { success: false, error: "Mesh not found" };
|
|
51678
|
-
const node = mesh.nodes?.find((n) => meshNodeIdMatches(n, nodeId));
|
|
51679
|
-
if (!node) return { success: false, error: `Node '${nodeId}' not found in mesh` };
|
|
51680
|
-
if (!node.isLocalWorktree) return { success: false, error: "Node is not a local worktree node" };
|
|
51681
|
-
const nodeDaemonId = typeof node.daemonId === "string" ? node.daemonId.trim() : void 0;
|
|
51682
|
-
if (nodeDaemonId && !daemonIdsEquivalent(nodeDaemonId, this.deps.statusInstanceId) && this.deps.dispatchMeshCommand && !args?._meshDirectDispatch) {
|
|
51683
|
-
const forwarded = await this.deps.dispatchMeshCommand(nodeDaemonId, "retry_mesh_node_bootstrap", {
|
|
51684
|
-
...typeof args === "object" && args !== null ? args : {},
|
|
51685
|
-
_meshDirectDispatch: true
|
|
51686
|
-
});
|
|
51687
|
-
return forwarded ?? { success: false, error: "no response from remote node" };
|
|
51688
|
-
}
|
|
51689
|
-
const currentBootstrap = node.worktreeBootstrap;
|
|
51690
|
-
if (currentBootstrap?.status === "running") {
|
|
51691
|
-
return { success: false, error: "Bootstrap is already running for this node" };
|
|
51692
|
-
}
|
|
51693
|
-
const worktreePath = node.workspace || node.repoRoot;
|
|
51694
|
-
if (!worktreePath) return { success: false, error: "Node has no workspace path" };
|
|
51695
|
-
const loadedBootstrap = loadMeshWorktreeBootstrapConfig(mesh, worktreePath);
|
|
51696
|
-
const runningState = {
|
|
51697
|
-
status: "running",
|
|
51698
|
-
required: loadedBootstrap.config?.required !== false,
|
|
51699
|
-
configSource: loadedBootstrap.path || loadedBootstrap.source,
|
|
51700
|
-
configSourceType: loadedBootstrap.sourceType,
|
|
51701
|
-
startedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
51702
|
-
};
|
|
51703
|
-
const persistState = async (bootstrapState2) => {
|
|
51704
|
-
node.worktreeBootstrap = bootstrapState2;
|
|
51705
|
-
if (meshRecord.inline) {
|
|
51706
|
-
this.updateInlineMeshNode(meshId, mesh, node);
|
|
51707
|
-
return;
|
|
51708
|
-
}
|
|
51709
|
-
try {
|
|
51710
|
-
const { updateNode: updateNode2 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
51711
|
-
updateNode2(meshId, node.id, { worktreeBootstrap: bootstrapState2 });
|
|
51712
|
-
this.invalidateAggregateMeshStatus(meshId);
|
|
51713
|
-
} catch {
|
|
51714
|
-
}
|
|
51715
|
-
};
|
|
51716
|
-
await persistState(runningState);
|
|
51717
|
-
const bootstrapState = await runMeshWorktreeBootstrap(mesh, worktreePath);
|
|
51718
|
-
await persistState(bootstrapState);
|
|
51719
|
-
return { success: true, bootstrapState };
|
|
51720
|
-
} catch (e) {
|
|
51721
|
-
return { success: false, error: e.message };
|
|
51722
|
-
}
|
|
51723
|
-
}
|
|
51724
|
-
case "trigger_mesh_queue": {
|
|
51725
|
-
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
51726
|
-
if (!meshId) return { success: false, error: "meshId required" };
|
|
51727
|
-
const ownerFailure = await this.requireMeshHostMutationOwner(meshId, args?.inlineMesh, "queue trigger");
|
|
51728
|
-
if (ownerFailure) return ownerFailure;
|
|
51729
|
-
try {
|
|
51730
|
-
const { triggerMeshQueue: triggerMeshQueue2, tryAssignQueueTask: tryAssignQueueTask2 } = await Promise.resolve().then(() => (init_mesh_events(), mesh_events_exports));
|
|
51731
|
-
const preferredNodeId = typeof args?.preferredNodeId === "string" ? args.preferredNodeId.trim() : "";
|
|
51732
|
-
if (preferredNodeId) {
|
|
51733
|
-
const cliInstances = this.deps.instanceManager.getByCategory("cli");
|
|
51734
|
-
const sorted = [...cliInstances].sort((a, b) => {
|
|
51735
|
-
const aSettings = a.getState().settings || {};
|
|
51736
|
-
const bSettings = b.getState().settings || {};
|
|
51737
|
-
const aNode = readStringValue(aSettings.meshNodeId, aSettings.nodeId);
|
|
51738
|
-
const bNode = readStringValue(bSettings.meshNodeId, bSettings.nodeId);
|
|
51739
|
-
return (aNode === preferredNodeId ? -1 : 0) - (bNode === preferredNodeId ? -1 : 0);
|
|
51740
|
-
});
|
|
51741
|
-
for (const inst of sorted) {
|
|
51742
|
-
const state = inst.getState();
|
|
51743
|
-
const settings = state.settings || {};
|
|
51744
|
-
const nodeId = readStringValue(settings.meshNodeId, settings.nodeId);
|
|
51745
|
-
if (!nodeId || nodeId !== preferredNodeId) continue;
|
|
51746
|
-
const meshNodeFor = readStringValue(settings.meshNodeFor);
|
|
51747
|
-
if (meshNodeFor !== meshId) continue;
|
|
51748
|
-
const status = (readStringValue(state.status) || "").toLowerCase();
|
|
51749
|
-
if (status !== "idle") continue;
|
|
51750
|
-
const sessionId = typeof state.instanceId === "string" ? state.instanceId : "";
|
|
51751
|
-
const providerType = readStringValue(state.type, settings.providerType) || "";
|
|
51752
|
-
if (sessionId && providerType) {
|
|
51753
|
-
tryAssignQueueTask2(this.deps, meshId, nodeId, sessionId, providerType);
|
|
51754
|
-
break;
|
|
51755
|
-
}
|
|
51756
|
-
}
|
|
51757
|
-
}
|
|
51758
|
-
const trigger = await triggerMeshQueue2(this.deps, meshId);
|
|
51759
|
-
return { success: true, trigger };
|
|
51760
|
-
} catch (e) {
|
|
51761
|
-
return { success: false, error: e.message };
|
|
51762
|
-
}
|
|
51763
|
-
}
|
|
51764
51900
|
// ─── Mesh Coordinator Launch ───
|
|
51765
51901
|
case "launch_mesh_coordinator": {
|
|
51766
51902
|
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|