@adhdev/daemon-core 0.9.77-rc.2 → 0.9.77-rc.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli-adapters/provider-cli-adapter.d.ts +2 -0
- package/dist/cli-adapters/provider-cli-shared.d.ts +14 -4
- package/dist/commands/mesh-coordinator.d.ts +8 -0
- package/dist/index.js +128 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +128 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +10 -4
- package/src/cli-adapters/provider-cli-shared.ts +14 -4
- package/src/commands/cli-manager.ts +0 -4
- package/src/commands/mesh-coordinator.ts +28 -6
- package/src/commands/router.ts +99 -0
- package/src/commands/stream-commands.ts +8 -1
- package/src/mesh/mesh-events.ts +12 -1
- package/src/providers/cli-provider-instance.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -1317,7 +1317,7 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
|
|
|
1317
1317
|
targetSessionId: sessionId,
|
|
1318
1318
|
cliType: providerType,
|
|
1319
1319
|
action: "send_chat",
|
|
1320
|
-
|
|
1320
|
+
message: task.message
|
|
1321
1321
|
}).catch((e) => {
|
|
1322
1322
|
LOG.error("MeshQueue", `Failed to dispatch task to node ${nodeId}: ${e?.message}`);
|
|
1323
1323
|
});
|
|
@@ -1399,6 +1399,15 @@ function injectMeshSystemMessage(components, args) {
|
|
|
1399
1399
|
}, 500);
|
|
1400
1400
|
}
|
|
1401
1401
|
}
|
|
1402
|
+
} else if (args.event === "agent:ready") {
|
|
1403
|
+
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
1404
|
+
const nodeId = readNonEmptyString(args.metadataEvent.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
1405
|
+
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
1406
|
+
if (sessionId && nodeId && providerType) {
|
|
1407
|
+
setTimeout(() => {
|
|
1408
|
+
tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
1409
|
+
}, 500);
|
|
1410
|
+
}
|
|
1402
1411
|
} else if (args.event === "agent:stopped") {
|
|
1403
1412
|
const sessionId = readNonEmptyString(args.metadataEvent.targetSessionId);
|
|
1404
1413
|
if (sessionId) {
|
|
@@ -1578,6 +1587,7 @@ var init_mesh_events = __esm({
|
|
|
1578
1587
|
"agent:generating_completed",
|
|
1579
1588
|
"agent:waiting_approval",
|
|
1580
1589
|
"agent:stopped",
|
|
1590
|
+
"agent:ready",
|
|
1581
1591
|
"monitor:long_generating"
|
|
1582
1592
|
]);
|
|
1583
1593
|
EVENT_TO_LEDGER_KIND = {
|
|
@@ -2695,6 +2705,8 @@ var init_provider_cli_adapter = __esm({
|
|
|
2695
2705
|
statusHistory = [];
|
|
2696
2706
|
// ─── CLI Scripts (script-based parsing) ───
|
|
2697
2707
|
cliScripts;
|
|
2708
|
+
/** Per-session opaque state object created by cliScripts.createState(), reset on stop. */
|
|
2709
|
+
scriptState = null;
|
|
2698
2710
|
runtimeSettings = {};
|
|
2699
2711
|
/** Full accumulated rendered PTY transcript for parser/readback use */
|
|
2700
2712
|
accumulatedBuffer = "";
|
|
@@ -2876,6 +2888,7 @@ ${lastSnapshot}`;
|
|
|
2876
2888
|
this.cliScripts = scripts;
|
|
2877
2889
|
this.parsedStatusCache = null;
|
|
2878
2890
|
this.parseErrorMessage = null;
|
|
2891
|
+
this.scriptState = typeof scripts.createState === "function" ? scripts.createState() : null;
|
|
2879
2892
|
const scriptNames = listCliScriptNames(scripts);
|
|
2880
2893
|
LOG.info("CLI", `[${this.cliType}] CLI scripts injected: [${scriptNames.join(", ")}]`);
|
|
2881
2894
|
}
|
|
@@ -2993,6 +3006,7 @@ ${lastSnapshot}`;
|
|
|
2993
3006
|
this.ready = false;
|
|
2994
3007
|
this.startupParseGate = false;
|
|
2995
3008
|
this.spawnAt = 0;
|
|
3009
|
+
this.scriptState = null;
|
|
2996
3010
|
this.onStatusChange?.();
|
|
2997
3011
|
});
|
|
2998
3012
|
this.spawnAt = Date.now();
|
|
@@ -3766,7 +3780,7 @@ ${lastSnapshot}`;
|
|
|
3766
3780
|
scope: this.currentTurnScope,
|
|
3767
3781
|
runtimeSettings: this.runtimeSettings
|
|
3768
3782
|
});
|
|
3769
|
-
const session = this.cliScripts.parseSession({ ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
3783
|
+
const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
|
|
3770
3784
|
this.parseErrorMessage = null;
|
|
3771
3785
|
return session && typeof session === "object" ? session : null;
|
|
3772
3786
|
} catch (e) {
|
|
@@ -3780,7 +3794,7 @@ ${lastSnapshot}`;
|
|
|
3780
3794
|
if (!this.cliScripts?.detectStatus) return null;
|
|
3781
3795
|
try {
|
|
3782
3796
|
const screenText = this.terminalScreen.getText();
|
|
3783
|
-
const status = this.cliScripts.detectStatus({
|
|
3797
|
+
const status = this.cliScripts.detectStatus(this.scriptState, {
|
|
3784
3798
|
tail: text.slice(-500),
|
|
3785
3799
|
screenText,
|
|
3786
3800
|
rawBuffer: this.accumulatedRawBuffer,
|
|
@@ -3799,7 +3813,7 @@ ${lastSnapshot}`;
|
|
|
3799
3813
|
try {
|
|
3800
3814
|
const screenText = this.terminalScreen.getText();
|
|
3801
3815
|
const buffer = screenText || this.accumulatedBuffer;
|
|
3802
|
-
return this.cliScripts.parseApproval({
|
|
3816
|
+
return this.cliScripts.parseApproval(this.scriptState, {
|
|
3803
3817
|
buffer,
|
|
3804
3818
|
screenText,
|
|
3805
3819
|
rawBuffer: this.accumulatedRawBuffer,
|
|
@@ -3907,7 +3921,7 @@ ${lastSnapshot}`;
|
|
|
3907
3921
|
scope: this.currentTurnScope,
|
|
3908
3922
|
runtimeSettings: this.runtimeSettings
|
|
3909
3923
|
});
|
|
3910
|
-
return await Promise.resolve(fn({
|
|
3924
|
+
return await Promise.resolve(fn(this.scriptState, {
|
|
3911
3925
|
...input,
|
|
3912
3926
|
args: args && typeof args === "object" ? { ...args } : {}
|
|
3913
3927
|
}));
|
|
@@ -14983,11 +14997,13 @@ async function handleOpenPanel(h, args) {
|
|
|
14983
14997
|
async function handlePtyInput(h, args) {
|
|
14984
14998
|
const { cliType, data, targetSessionId } = args || {};
|
|
14985
14999
|
if (!data) return { success: false, error: "data required" };
|
|
15000
|
+
const cleanData = typeof data === "string" ? data.replace(/\x1b\[[?>][0-9;]*c/g, "") : data;
|
|
15001
|
+
if (!cleanData) return { success: true };
|
|
14986
15002
|
const adapter = h.getCliAdapter(targetSessionId || cliType);
|
|
14987
15003
|
if (!adapter || typeof adapter.writeRaw !== "function") {
|
|
14988
15004
|
return { success: false, error: `CLI adapter not found: ${targetSessionId || cliType || "unknown"}` };
|
|
14989
15005
|
}
|
|
14990
|
-
await adapter.writeRaw(
|
|
15006
|
+
await adapter.writeRaw(cleanData);
|
|
14991
15007
|
return { success: true };
|
|
14992
15008
|
}
|
|
14993
15009
|
function handlePtyResize(_h, args) {
|
|
@@ -16617,6 +16633,8 @@ var CliProviderInstance = class {
|
|
|
16617
16633
|
this.completedDebounceTimer = null;
|
|
16618
16634
|
}, 3e3);
|
|
16619
16635
|
}
|
|
16636
|
+
} else if (newStatus === "idle" && this.lastStatus === "starting") {
|
|
16637
|
+
this.pushEvent({ event: "agent:ready", chatTitle, timestamp: now });
|
|
16620
16638
|
} else if (newStatus === "stopped") {
|
|
16621
16639
|
if (this.generatingDebounceTimer) {
|
|
16622
16640
|
clearTimeout(this.generatingDebounceTimer);
|
|
@@ -18365,9 +18383,6 @@ function buildCoordinatorDelegatedCliLaunchOptions(input) {
|
|
|
18365
18383
|
const cliType = String(input.cliType || "").trim();
|
|
18366
18384
|
const cliArgs = Array.isArray(input.cliArgs) ? [...input.cliArgs] : [];
|
|
18367
18385
|
const env = { ...input.env || {}, ...COORDINATOR_DELEGATED_ENV_UNSETS };
|
|
18368
|
-
if (cliType === "hermes-cli" && !hasCliArg(cliArgs, "--ignore-user-config")) {
|
|
18369
|
-
cliArgs.unshift("--ignore-user-config");
|
|
18370
|
-
}
|
|
18371
18386
|
if (cliType === "claude-cli" && !hasCliArg(cliArgs, "--mcp-config")) {
|
|
18372
18387
|
cliArgs.unshift("--mcp-config", ensureEmptyDelegatedMcpConfig(input.workspace));
|
|
18373
18388
|
}
|
|
@@ -21702,6 +21717,22 @@ function resolveMeshCoordinatorSetup(options) {
|
|
|
21702
21717
|
if (!instructions || !template?.trim()) {
|
|
21703
21718
|
return { kind: "unsupported", reason: "Provider manual MCP setup is missing instructions or template" };
|
|
21704
21719
|
}
|
|
21720
|
+
const renderedTemplate = renderMeshCoordinatorTemplate(template, {
|
|
21721
|
+
meshId,
|
|
21722
|
+
workspace,
|
|
21723
|
+
serverName,
|
|
21724
|
+
adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
|
|
21725
|
+
});
|
|
21726
|
+
const isCliCommand = !renderedTemplate.trim().includes("\n") && !renderedTemplate.trim().startsWith("{");
|
|
21727
|
+
if (isCliCommand) {
|
|
21728
|
+
return {
|
|
21729
|
+
kind: "cli_command",
|
|
21730
|
+
serverName,
|
|
21731
|
+
command: renderedTemplate.trim(),
|
|
21732
|
+
requiresRestart: mcpConfig.requiresRestart === true,
|
|
21733
|
+
instructions
|
|
21734
|
+
};
|
|
21735
|
+
}
|
|
21705
21736
|
return {
|
|
21706
21737
|
kind: "manual",
|
|
21707
21738
|
serverName,
|
|
@@ -21709,12 +21740,7 @@ function resolveMeshCoordinatorSetup(options) {
|
|
|
21709
21740
|
configPathCommand: mcpConfig.configPathCommand,
|
|
21710
21741
|
requiresRestart: mcpConfig.requiresRestart === true,
|
|
21711
21742
|
instructions,
|
|
21712
|
-
template:
|
|
21713
|
-
meshId,
|
|
21714
|
-
workspace,
|
|
21715
|
-
serverName,
|
|
21716
|
-
adhdevMcpCommand: options.adhdevMcpCommand || DEFAULT_ADHDEV_MCP_COMMAND
|
|
21717
|
-
})
|
|
21743
|
+
template: renderedTemplate
|
|
21718
21744
|
};
|
|
21719
21745
|
}
|
|
21720
21746
|
return {
|
|
@@ -23896,6 +23922,93 @@ var DaemonCommandRouter = class {
|
|
|
23896
23922
|
meshCoordinatorSetup: coordinatorSetup
|
|
23897
23923
|
};
|
|
23898
23924
|
}
|
|
23925
|
+
if (coordinatorSetup.kind === "cli_command") {
|
|
23926
|
+
let cliCmdSystemPrompt = "";
|
|
23927
|
+
try {
|
|
23928
|
+
cliCmdSystemPrompt = buildCoordinatorSystemPrompt2({ mesh, coordinatorCliType: cliType });
|
|
23929
|
+
} catch (error) {
|
|
23930
|
+
const message = error?.message || String(error);
|
|
23931
|
+
LOG.error("MeshCoordinator", `Failed to build coordinator prompt: ${message}`);
|
|
23932
|
+
return {
|
|
23933
|
+
success: false,
|
|
23934
|
+
code: "mesh_coordinator_prompt_failed",
|
|
23935
|
+
error: `Failed to build Repo Mesh coordinator prompt: ${message}`,
|
|
23936
|
+
meshId,
|
|
23937
|
+
cliType,
|
|
23938
|
+
workspace
|
|
23939
|
+
};
|
|
23940
|
+
}
|
|
23941
|
+
try {
|
|
23942
|
+
const { execFileSync: execCmdSync } = await import("child_process");
|
|
23943
|
+
const cmdParts = coordinatorSetup.command.trim().split(/\s+/);
|
|
23944
|
+
const [regCmd, ...regArgs] = cmdParts;
|
|
23945
|
+
LOG.info("MeshCoordinator", `Running MCP registration: ${coordinatorSetup.command}`);
|
|
23946
|
+
execCmdSync(regCmd, regArgs, { stdio: "pipe", timeout: 15e3 });
|
|
23947
|
+
} catch (error) {
|
|
23948
|
+
LOG.warn("MeshCoordinator", `MCP registration command failed (may be pre-registered): ${error?.message || error}`);
|
|
23949
|
+
}
|
|
23950
|
+
const cliCmdArgs = [];
|
|
23951
|
+
const cliCmdEnv = {};
|
|
23952
|
+
if (cliCmdSystemPrompt) {
|
|
23953
|
+
if (cliType === "codex-cli") {
|
|
23954
|
+
cliCmdArgs.push("-c", `developer_instructions=${JSON.stringify(cliCmdSystemPrompt)}`);
|
|
23955
|
+
} else if (cliType === "gemini-cli") {
|
|
23956
|
+
try {
|
|
23957
|
+
const { writeFileSync: wfs, existsSync: efs, readFileSync: rfs } = await import("fs");
|
|
23958
|
+
const geminiMdPath = `${workspace}/GEMINI.md`;
|
|
23959
|
+
const marker = "<!-- adhdev-mesh-coordinator-prompt -->";
|
|
23960
|
+
const markerEnd = "<!-- /adhdev-mesh-coordinator-prompt -->";
|
|
23961
|
+
const block = `${marker}
|
|
23962
|
+
${cliCmdSystemPrompt}
|
|
23963
|
+
${markerEnd}`;
|
|
23964
|
+
if (efs(geminiMdPath)) {
|
|
23965
|
+
const existing = rfs(geminiMdPath, "utf-8");
|
|
23966
|
+
const replaced = existing.replace(
|
|
23967
|
+
new RegExp(`${marker}[\\s\\S]*?${markerEnd}`, "g"),
|
|
23968
|
+
block
|
|
23969
|
+
);
|
|
23970
|
+
wfs(geminiMdPath, replaced.includes(marker) ? replaced : `${existing}
|
|
23971
|
+
|
|
23972
|
+
${block}`);
|
|
23973
|
+
} else {
|
|
23974
|
+
wfs(geminiMdPath, block);
|
|
23975
|
+
}
|
|
23976
|
+
LOG.info("MeshCoordinator", `Wrote coordinator prompt to ${workspace}/GEMINI.md`);
|
|
23977
|
+
} catch (e) {
|
|
23978
|
+
LOG.warn("MeshCoordinator", `Could not write GEMINI.md: ${e?.message || e}`);
|
|
23979
|
+
}
|
|
23980
|
+
}
|
|
23981
|
+
}
|
|
23982
|
+
const cliCmdLaunch = await this.deps.cliManager.handleCliCommand("launch_cli", {
|
|
23983
|
+
cliType,
|
|
23984
|
+
dir: workspace,
|
|
23985
|
+
cliArgs: cliCmdArgs.length > 0 ? cliCmdArgs : void 0,
|
|
23986
|
+
env: Object.keys(cliCmdEnv).length > 0 ? cliCmdEnv : void 0,
|
|
23987
|
+
settings: { meshCoordinatorFor: meshId }
|
|
23988
|
+
});
|
|
23989
|
+
if (!cliCmdLaunch?.success) {
|
|
23990
|
+
return { success: false, error: cliCmdLaunch?.error || "Failed to launch CLI session" };
|
|
23991
|
+
}
|
|
23992
|
+
LOG.info("MeshCoordinator", `Launched ${cliType} coordinator (cli_command) for mesh ${meshId}`);
|
|
23993
|
+
try {
|
|
23994
|
+
const { appendLedgerEntry: appendLedgerEntry2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
23995
|
+
appendLedgerEntry2(meshId, {
|
|
23996
|
+
kind: "coordinator_started",
|
|
23997
|
+
sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
|
|
23998
|
+
providerType: cliType,
|
|
23999
|
+
payload: { workspace }
|
|
24000
|
+
});
|
|
24001
|
+
} catch {
|
|
24002
|
+
}
|
|
24003
|
+
return {
|
|
24004
|
+
success: true,
|
|
24005
|
+
meshId,
|
|
24006
|
+
cliType,
|
|
24007
|
+
workspace,
|
|
24008
|
+
sessionId: cliCmdLaunch.sessionId || cliCmdLaunch.id,
|
|
24009
|
+
mcpRegistered: true
|
|
24010
|
+
};
|
|
24011
|
+
}
|
|
23899
24012
|
const configFormat = coordinatorSetup.configFormat;
|
|
23900
24013
|
if (configFormat !== "claude_mcp_json" && configFormat !== "hermes_config_yaml") {
|
|
23901
24014
|
return {
|