@adhdev/daemon-core 0.9.76-rc.32 → 0.9.76-rc.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +97 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -58
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-events.d.ts +9 -0
- package/package.json +1 -1
- package/src/commands/router.ts +5 -0
- package/src/mesh/mesh-events.ts +76 -33
package/dist/index.mjs
CHANGED
|
@@ -20333,6 +20333,100 @@ function normalizeExistingPath(filePath) {
|
|
|
20333
20333
|
}
|
|
20334
20334
|
}
|
|
20335
20335
|
|
|
20336
|
+
// src/mesh/mesh-events.ts
|
|
20337
|
+
init_mesh_config();
|
|
20338
|
+
init_logger();
|
|
20339
|
+
function readNonEmptyString(value) {
|
|
20340
|
+
return typeof value === "string" && value.trim() ? value.trim() : "";
|
|
20341
|
+
}
|
|
20342
|
+
function formatCompletionMetadata(event) {
|
|
20343
|
+
const parts = [
|
|
20344
|
+
readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
|
|
20345
|
+
readNonEmptyString(event.providerType) ? `provider=${readNonEmptyString(event.providerType)}` : "",
|
|
20346
|
+
readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : ""
|
|
20347
|
+
].filter(Boolean);
|
|
20348
|
+
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
20349
|
+
}
|
|
20350
|
+
function buildMeshSystemMessage(args) {
|
|
20351
|
+
const metadata = formatCompletionMetadata(args.metadataEvent);
|
|
20352
|
+
if (args.event === "agent:generating_completed") {
|
|
20353
|
+
return `[System] ${args.nodeLabel} has completed its task and is now idle${metadata}. You may use mesh_read_chat to review its progress.`;
|
|
20354
|
+
}
|
|
20355
|
+
if (args.event === "agent:waiting_approval") {
|
|
20356
|
+
return `[System] ${args.nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
|
|
20357
|
+
}
|
|
20358
|
+
return "";
|
|
20359
|
+
}
|
|
20360
|
+
function injectMeshSystemMessage(components, args) {
|
|
20361
|
+
const coordinatorInstances = components.instanceManager.getByCategory("cli").filter((inst) => {
|
|
20362
|
+
const instState = inst.getState();
|
|
20363
|
+
if (instState.settings?.meshCoordinatorFor !== args.meshId) return false;
|
|
20364
|
+
if (args.sourceInstanceId && instState.instanceId === args.sourceInstanceId) return false;
|
|
20365
|
+
return true;
|
|
20366
|
+
});
|
|
20367
|
+
if (coordinatorInstances.length === 0) return { success: true, forwarded: 0 };
|
|
20368
|
+
const messageText = buildMeshSystemMessage({
|
|
20369
|
+
event: args.event,
|
|
20370
|
+
nodeLabel: args.nodeLabel,
|
|
20371
|
+
metadataEvent: args.metadataEvent
|
|
20372
|
+
});
|
|
20373
|
+
if (!messageText) return { success: false, error: "unsupported mesh event" };
|
|
20374
|
+
for (const coord of coordinatorInstances) {
|
|
20375
|
+
const coordState = coord.getState();
|
|
20376
|
+
LOG.info("MeshEvents", `Forwarding mesh event to coordinator ${coordState.instanceId}`);
|
|
20377
|
+
coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
|
|
20378
|
+
}
|
|
20379
|
+
return { success: true, forwarded: coordinatorInstances.length };
|
|
20380
|
+
}
|
|
20381
|
+
function handleMeshForwardEvent(components, payload) {
|
|
20382
|
+
const eventName = readNonEmptyString(payload.event);
|
|
20383
|
+
if (eventName !== "agent:generating_completed" && eventName !== "agent:waiting_approval") {
|
|
20384
|
+
return { success: false, error: "unsupported mesh event" };
|
|
20385
|
+
}
|
|
20386
|
+
const meshId = readNonEmptyString(payload.meshId);
|
|
20387
|
+
if (!meshId) return { success: false, error: "meshId required" };
|
|
20388
|
+
const nodeId = readNonEmptyString(payload.nodeId);
|
|
20389
|
+
const workspace = readNonEmptyString(payload.workspace);
|
|
20390
|
+
const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
|
|
20391
|
+
return injectMeshSystemMessage(components, {
|
|
20392
|
+
meshId,
|
|
20393
|
+
nodeLabel,
|
|
20394
|
+
event: eventName,
|
|
20395
|
+
metadataEvent: {
|
|
20396
|
+
targetSessionId: readNonEmptyString(payload.targetSessionId) || readNonEmptyString(payload.sessionId),
|
|
20397
|
+
providerType: readNonEmptyString(payload.providerType),
|
|
20398
|
+
providerSessionId: readNonEmptyString(payload.providerSessionId)
|
|
20399
|
+
}
|
|
20400
|
+
});
|
|
20401
|
+
}
|
|
20402
|
+
function setupMeshEventForwarding(components) {
|
|
20403
|
+
components.instanceManager.onEvent((event) => {
|
|
20404
|
+
if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
|
|
20405
|
+
const instanceId = readNonEmptyString(event.instanceId);
|
|
20406
|
+
if (!instanceId) return;
|
|
20407
|
+
const sourceInstance = components.instanceManager.getInstance(instanceId);
|
|
20408
|
+
if (!sourceInstance || sourceInstance.category !== "cli") return;
|
|
20409
|
+
const state = sourceInstance.getState();
|
|
20410
|
+
const workspace = readNonEmptyString(state.workspace);
|
|
20411
|
+
if (!workspace) return;
|
|
20412
|
+
const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
|
|
20413
|
+
const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
|
|
20414
|
+
const mesh = meshIdFromRuntime ? getMesh(meshIdFromRuntime) : getMeshByRepo(workspace);
|
|
20415
|
+
const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
|
|
20416
|
+
if (!meshId) return;
|
|
20417
|
+
const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
|
|
20418
|
+
const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
|
|
20419
|
+
const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
|
|
20420
|
+
injectMeshSystemMessage(components, {
|
|
20421
|
+
meshId,
|
|
20422
|
+
sourceInstanceId: instanceId,
|
|
20423
|
+
nodeLabel,
|
|
20424
|
+
event: event.event,
|
|
20425
|
+
metadataEvent: event
|
|
20426
|
+
});
|
|
20427
|
+
});
|
|
20428
|
+
}
|
|
20429
|
+
|
|
20336
20430
|
// src/status/snapshot.ts
|
|
20337
20431
|
init_config();
|
|
20338
20432
|
import * as os18 from "os";
|
|
@@ -21302,6 +21396,9 @@ var DaemonCommandRouter = class {
|
|
|
21302
21396
|
async executeDaemonCommand(cmd, args) {
|
|
21303
21397
|
switch (cmd) {
|
|
21304
21398
|
// ─── CLI / ACP commands ───
|
|
21399
|
+
case "mesh_forward_event": {
|
|
21400
|
+
return handleMeshForwardEvent({ instanceManager: this.deps.instanceManager }, args);
|
|
21401
|
+
}
|
|
21305
21402
|
case "launch_cli":
|
|
21306
21403
|
case "stop_cli":
|
|
21307
21404
|
case "set_cli_view_mode":
|
|
@@ -29929,64 +30026,6 @@ var SessionRegistry = class {
|
|
|
29929
30026
|
// src/boot/daemon-lifecycle.ts
|
|
29930
30027
|
init_logger();
|
|
29931
30028
|
init_config();
|
|
29932
|
-
|
|
29933
|
-
// src/mesh/mesh-events.ts
|
|
29934
|
-
init_mesh_config();
|
|
29935
|
-
init_logger();
|
|
29936
|
-
function readNonEmptyString(value) {
|
|
29937
|
-
return typeof value === "string" && value.trim() ? value.trim() : "";
|
|
29938
|
-
}
|
|
29939
|
-
function formatCompletionMetadata(event) {
|
|
29940
|
-
const parts = [
|
|
29941
|
-
readNonEmptyString(event.targetSessionId) ? `session_id=${readNonEmptyString(event.targetSessionId)}` : "",
|
|
29942
|
-
readNonEmptyString(event.providerType) ? `provider=${readNonEmptyString(event.providerType)}` : "",
|
|
29943
|
-
readNonEmptyString(event.providerSessionId) ? `provider_session_id=${readNonEmptyString(event.providerSessionId)}` : ""
|
|
29944
|
-
].filter(Boolean);
|
|
29945
|
-
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
29946
|
-
}
|
|
29947
|
-
function setupMeshEventForwarding(components) {
|
|
29948
|
-
components.instanceManager.onEvent((event) => {
|
|
29949
|
-
if (event.event !== "agent:generating_completed" && event.event !== "agent:waiting_approval") return;
|
|
29950
|
-
const instanceId = readNonEmptyString(event.instanceId);
|
|
29951
|
-
if (!instanceId) return;
|
|
29952
|
-
const sourceInstance = components.instanceManager.getInstance(instanceId);
|
|
29953
|
-
if (!sourceInstance || sourceInstance.category !== "cli") return;
|
|
29954
|
-
const state = sourceInstance.getState();
|
|
29955
|
-
const workspace = readNonEmptyString(state.workspace);
|
|
29956
|
-
if (!workspace) return;
|
|
29957
|
-
const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
|
|
29958
|
-
const meshIdFromRuntime = readNonEmptyString(settings.meshNodeFor);
|
|
29959
|
-
const mesh = meshIdFromRuntime ? getMesh(meshIdFromRuntime) : getMeshByRepo(workspace);
|
|
29960
|
-
const meshId = meshIdFromRuntime || readNonEmptyString(mesh?.id);
|
|
29961
|
-
if (!meshId) return;
|
|
29962
|
-
const allInstances = components.instanceManager.getByCategory("cli");
|
|
29963
|
-
const coordinatorInstances = allInstances.filter((inst) => {
|
|
29964
|
-
const instState = inst.getState();
|
|
29965
|
-
if (instState.settings?.meshCoordinatorFor !== meshId) return false;
|
|
29966
|
-
if (instState.instanceId === instanceId) return false;
|
|
29967
|
-
return true;
|
|
29968
|
-
});
|
|
29969
|
-
if (coordinatorInstances.length === 0) return;
|
|
29970
|
-
const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
|
|
29971
|
-
const runtimeNodeId = readNonEmptyString(settings.meshNodeId);
|
|
29972
|
-
const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
|
|
29973
|
-
const metadata = formatCompletionMetadata(event);
|
|
29974
|
-
let messageText = "";
|
|
29975
|
-
if (event.event === "agent:generating_completed") {
|
|
29976
|
-
messageText = `[System] ${nodeLabel} has completed its task and is now idle${metadata}. You may use mesh_read_chat to review its progress.`;
|
|
29977
|
-
} else if (event.event === "agent:waiting_approval") {
|
|
29978
|
-
messageText = `[System] ${nodeLabel} is waiting for approval to proceed${metadata}. You may use mesh_read_chat and mesh_approve to handle it.`;
|
|
29979
|
-
}
|
|
29980
|
-
if (!messageText) return;
|
|
29981
|
-
for (const coord of coordinatorInstances) {
|
|
29982
|
-
const coordState = coord.getState();
|
|
29983
|
-
LOG.info("MeshEvents", `Forwarding event from ${workspace} to coordinator ${coordState.instanceId}`);
|
|
29984
|
-
coord.onEvent("send_message", { input: { text: messageText, textFallback: messageText } });
|
|
29985
|
-
}
|
|
29986
|
-
});
|
|
29987
|
-
}
|
|
29988
|
-
|
|
29989
|
-
// src/boot/daemon-lifecycle.ts
|
|
29990
30029
|
async function initDaemonComponents(config) {
|
|
29991
30030
|
installGlobalInterceptor();
|
|
29992
30031
|
const appConfig = loadConfig();
|