@adhdev/daemon-core 0.9.82-rc.80 → 0.9.82-rc.82
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 +150 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -18
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-active-work.d.ts +9 -0
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +76 -13
- package/src/commands/cli-manager.ts +39 -1
- package/src/mesh/mesh-active-work.ts +25 -4
- package/src/mesh/mesh-events.ts +57 -0
- package/src/providers/read-chat-contract.ts +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2555,6 +2555,29 @@ function hasPendingRefineTerminalEventDuplicate(event) {
|
|
|
2555
2555
|
(pending) => pending.event === event.event && readRefineJobId(pending) === jobId
|
|
2556
2556
|
);
|
|
2557
2557
|
}
|
|
2558
|
+
function buildPendingEventFingerprint(event) {
|
|
2559
|
+
const metadata = readRecord(event.metadataEvent) || {};
|
|
2560
|
+
const sessionId = resolveEventSessionId(metadata);
|
|
2561
|
+
const providerSessionId = readNonEmptyString2(metadata.providerSessionId);
|
|
2562
|
+
const taskId = readNonEmptyString2(metadata.taskId) || readNonEmptyString2(readRecord(metadata.payload)?.taskId);
|
|
2563
|
+
const jobId = readRefineJobId(event);
|
|
2564
|
+
const timestamp = metadata.timestamp !== void 0 && metadata.timestamp !== null ? String(metadata.timestamp) : "";
|
|
2565
|
+
return [
|
|
2566
|
+
event.meshId,
|
|
2567
|
+
event.event,
|
|
2568
|
+
event.nodeId || "",
|
|
2569
|
+
sessionId || "",
|
|
2570
|
+
providerSessionId || "",
|
|
2571
|
+
taskId || "",
|
|
2572
|
+
jobId || "",
|
|
2573
|
+
timestamp || ""
|
|
2574
|
+
].join("::");
|
|
2575
|
+
}
|
|
2576
|
+
function hasPendingCoordinatorEventDuplicate(event) {
|
|
2577
|
+
const fingerprint = buildPendingEventFingerprint(event);
|
|
2578
|
+
if (!fingerprint.trim()) return false;
|
|
2579
|
+
return getPendingMeshCoordinatorEvents(event.meshId).some((pending) => buildPendingEventFingerprint(pending) === fingerprint);
|
|
2580
|
+
}
|
|
2558
2581
|
function getPendingEventsPath(meshId) {
|
|
2559
2582
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2560
2583
|
return join10(getLedgerDir(), `${safe}.pending-events.jsonl`);
|
|
@@ -2565,6 +2588,10 @@ function queuePendingMeshCoordinatorEvent(event) {
|
|
|
2565
2588
|
LOG.info("MeshEvents", `Suppressed duplicate pending ${event.event} for refine job ${readRefineJobId(event)}`);
|
|
2566
2589
|
return true;
|
|
2567
2590
|
}
|
|
2591
|
+
if (hasPendingCoordinatorEventDuplicate(event)) {
|
|
2592
|
+
LOG.info("MeshEvents", `Suppressed duplicate pending ${event.event} for mesh ${event.meshId}`);
|
|
2593
|
+
return true;
|
|
2594
|
+
}
|
|
2568
2595
|
appendFileSync2(getPendingEventsPath(event.meshId), JSON.stringify(event) + "\n", "utf-8");
|
|
2569
2596
|
return true;
|
|
2570
2597
|
} catch (e) {
|
|
@@ -3341,6 +3368,7 @@ function injectMeshSystemMessage(components, args) {
|
|
|
3341
3368
|
if (args.sourceInstanceId && instState.instanceId === args.sourceInstanceId) return false;
|
|
3342
3369
|
return true;
|
|
3343
3370
|
});
|
|
3371
|
+
const isRefineTerminalEvent = REFINE_TERMINAL_EVENTS.has(args.event);
|
|
3344
3372
|
if (coordinatorInstances.length === 0) {
|
|
3345
3373
|
if (queuePendingMeshCoordinatorEvent({
|
|
3346
3374
|
event: args.event,
|
|
@@ -3359,6 +3387,23 @@ function injectMeshSystemMessage(components, args) {
|
|
|
3359
3387
|
}
|
|
3360
3388
|
return { success: true, forwarded: 0 };
|
|
3361
3389
|
}
|
|
3390
|
+
if (!isRefineTerminalEvent) {
|
|
3391
|
+
if (queuePendingMeshCoordinatorEvent({
|
|
3392
|
+
event: args.event,
|
|
3393
|
+
meshId: args.meshId,
|
|
3394
|
+
nodeLabel: args.nodeLabel,
|
|
3395
|
+
nodeId: args.nodeId || void 0,
|
|
3396
|
+
workspace: readNonEmptyString2(args.metadataEvent.workspace),
|
|
3397
|
+
metadataEvent: {
|
|
3398
|
+
...args.metadataEvent,
|
|
3399
|
+
...recoveryContext ? { recoveryContext } : {}
|
|
3400
|
+
},
|
|
3401
|
+
coordinatorMessage: messageText,
|
|
3402
|
+
queuedAt: Date.now()
|
|
3403
|
+
})) {
|
|
3404
|
+
LOG.info("MeshEvents", `Queued ${args.event} for MCP coordinator (mesh ${args.meshId})`);
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3362
3407
|
for (const coord of coordinatorInstances) {
|
|
3363
3408
|
const coordState = coord.getState();
|
|
3364
3409
|
LOG.info("MeshEvents", `Forwarding mesh event to coordinator ${coordState.instanceId}`);
|
|
@@ -9132,6 +9177,7 @@ function buildMeshActiveWorkSummary(activeWork) {
|
|
|
9132
9177
|
sourceCounts[item.source] += 1;
|
|
9133
9178
|
statusCounts[item.status] += 1;
|
|
9134
9179
|
}
|
|
9180
|
+
const staleDirectCount = activeWork.filter((item) => item.source === "direct" && item.staleReason).length;
|
|
9135
9181
|
return {
|
|
9136
9182
|
totalActiveCount: activeWork.length,
|
|
9137
9183
|
queueActiveCount: sourceCounts.queue,
|
|
@@ -9142,13 +9188,15 @@ function buildMeshActiveWorkSummary(activeWork) {
|
|
|
9142
9188
|
idleCount: statusCounts.idle,
|
|
9143
9189
|
sourceCounts,
|
|
9144
9190
|
statusCounts,
|
|
9145
|
-
staleDirectCount
|
|
9191
|
+
staleDirectCount,
|
|
9192
|
+
...staleDirectCount > 0 ? { staleDirectNote: "Stale direct records are orphaned ledger entries whose node/session no longer exists. They are historical recovery evidence only \u2014 not active or unresolved work. The queue (source: queue) is authoritative for pending/assigned tasks." } : {}
|
|
9146
9193
|
};
|
|
9147
9194
|
}
|
|
9148
9195
|
function buildMeshActiveWork(opts) {
|
|
9149
9196
|
const now = opts.now ?? Date.now();
|
|
9150
9197
|
const records = [];
|
|
9151
9198
|
const staleDirectWork = [];
|
|
9199
|
+
const terminalDirectWork = [];
|
|
9152
9200
|
for (const task of opts.queue || []) {
|
|
9153
9201
|
if (task.status !== "pending" && task.status !== "assigned") continue;
|
|
9154
9202
|
const { title, summary: summary2 } = summarizeMessage(task.message || "");
|
|
@@ -9177,7 +9225,6 @@ function buildMeshActiveWork(opts) {
|
|
|
9177
9225
|
const live = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
|
|
9178
9226
|
const status = terminalStatus || live.status || "assigned";
|
|
9179
9227
|
const terminalRow = Boolean(terminal && terminal.kind !== "task_approval_needed");
|
|
9180
|
-
if (terminalRow && opts.includeTerminalDirect !== true) continue;
|
|
9181
9228
|
const message = readString2(dispatch.payload?.message) || readString2(dispatch.payload?.summary) || "";
|
|
9182
9229
|
const { title, summary: summary2 } = summarizeMessage(message);
|
|
9183
9230
|
const record = {
|
|
@@ -9200,6 +9247,10 @@ function buildMeshActiveWork(opts) {
|
|
|
9200
9247
|
terminalAt: terminal?.timestamp,
|
|
9201
9248
|
staleReason: live.staleReason
|
|
9202
9249
|
};
|
|
9250
|
+
if (terminalRow) {
|
|
9251
|
+
terminalDirectWork.push(record);
|
|
9252
|
+
if (opts.includeTerminalDirect !== true) continue;
|
|
9253
|
+
}
|
|
9203
9254
|
if (live.staleReason && !terminalRow) {
|
|
9204
9255
|
staleDirectWork.push(record);
|
|
9205
9256
|
continue;
|
|
@@ -9208,9 +9259,14 @@ function buildMeshActiveWork(opts) {
|
|
|
9208
9259
|
}
|
|
9209
9260
|
records.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
9210
9261
|
staleDirectWork.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
9262
|
+
terminalDirectWork.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
9211
9263
|
const summary = buildMeshActiveWorkSummary(records);
|
|
9212
9264
|
summary.staleDirectCount = staleDirectWork.length;
|
|
9213
|
-
|
|
9265
|
+
const staleDirectWorkNote = staleDirectWork.length > 0 ? "These are orphaned ledger entries whose original node or session no longer exists in the live mesh. They are historical/recovery evidence only \u2014 not active or unresolved work. Do not treat staleDirectCount as a status mismatch; use the queue (source: queue) as authoritative for pending/assigned tasks." : void 0;
|
|
9266
|
+
if (staleDirectWorkNote) {
|
|
9267
|
+
summary.staleDirectNote = staleDirectWorkNote;
|
|
9268
|
+
}
|
|
9269
|
+
return { activeWork: records, staleDirectWork, staleDirectWorkNote, terminalDirectWork, summary };
|
|
9214
9270
|
}
|
|
9215
9271
|
|
|
9216
9272
|
// src/index.ts
|
|
@@ -13653,7 +13709,7 @@ ${effect.notification.body || ""}`.trim();
|
|
|
13653
13709
|
init_logger();
|
|
13654
13710
|
|
|
13655
13711
|
// src/providers/read-chat-contract.ts
|
|
13656
|
-
var VALID_STATUSES = ["idle", "generating", "waiting_approval", "error", "panel_hidden", "streaming", "long_generating"];
|
|
13712
|
+
var VALID_STATUSES = ["idle", "generating", "waiting_approval", "error", "panel_hidden", "starting", "streaming", "long_generating"];
|
|
13657
13713
|
var VALID_ROLES = ["user", "assistant", "system", "human"];
|
|
13658
13714
|
var VALID_BUBBLE_STATES = ["draft", "streaming", "final", "removed"];
|
|
13659
13715
|
var VALID_TURN_STATUSES = ["open", "waiting_approval", "complete", "error"];
|
|
@@ -15626,7 +15682,8 @@ function buildSessionModalDeliverySignature(payload) {
|
|
|
15626
15682
|
var RECENT_SEND_WINDOW_MS = 1200;
|
|
15627
15683
|
var READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
|
|
15628
15684
|
var HERMES_CLI_STARTING_SEND_SETTLE_MS = 2e3;
|
|
15629
|
-
var
|
|
15685
|
+
var CLI_NATIVE_HISTORY_FRESH_MS = 5 * 6e4;
|
|
15686
|
+
var CLI_NATIVE_TRANSCRIPT_PROVIDERS = /* @__PURE__ */ new Set(["codex-cli", "claude-cli"]);
|
|
15630
15687
|
var recentSendByTarget = /* @__PURE__ */ new Map();
|
|
15631
15688
|
function getCurrentProviderType(h, fallback = "") {
|
|
15632
15689
|
return h.currentSession?.providerType || h.currentProviderType || fallback;
|
|
@@ -15714,7 +15771,13 @@ function getHistorySessionId(h, args) {
|
|
|
15714
15771
|
const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
|
|
15715
15772
|
const state = instance?.getState?.();
|
|
15716
15773
|
const providerSessionId = typeof state?.providerSessionId === "string" ? state.providerSessionId.trim() : "";
|
|
15717
|
-
|
|
15774
|
+
if (providerSessionId) return providerSessionId;
|
|
15775
|
+
const currentSession = h.currentSession;
|
|
15776
|
+
if (currentSession?.sessionId === targetSessionId) {
|
|
15777
|
+
const currentProviderSessionId = typeof currentSession.providerSessionId === "string" ? currentSession.providerSessionId.trim() : "";
|
|
15778
|
+
if (currentProviderSessionId) return currentProviderSessionId;
|
|
15779
|
+
}
|
|
15780
|
+
return targetSessionId;
|
|
15718
15781
|
}
|
|
15719
15782
|
function getInteractionId(args) {
|
|
15720
15783
|
return typeof args?._interactionId === "string" && args._interactionId.trim() ? args._interactionId.trim() : void 0;
|
|
@@ -15777,7 +15840,9 @@ function buildCliMessageSourceProvenance(args) {
|
|
|
15777
15840
|
return {
|
|
15778
15841
|
selected: args.selected,
|
|
15779
15842
|
provider: args.provider,
|
|
15843
|
+
providerType: args.provider,
|
|
15780
15844
|
...args.nativeHandle ? { nativeHandle: args.nativeHandle } : {},
|
|
15845
|
+
...args.nativeHandle ? { nativeSessionId: args.nativeHandle } : {},
|
|
15781
15846
|
...args.fallbackReason ? { fallbackReason: args.fallbackReason } : {},
|
|
15782
15847
|
...args.nativeSource ? { nativeSource: args.nativeSource } : {},
|
|
15783
15848
|
...args.sourcePath ? { sourcePath: args.sourcePath } : {},
|
|
@@ -15798,7 +15863,7 @@ function buildCliMessageSourceProvenance(args) {
|
|
|
15798
15863
|
};
|
|
15799
15864
|
}
|
|
15800
15865
|
function buildNativeHistoryFallbackReason(args) {
|
|
15801
|
-
if (args.providerType
|
|
15866
|
+
if (!supportsCliNativeTranscript(args.providerType)) return "provider_native_transcript_not_supported";
|
|
15802
15867
|
if (args.nativeSource === "native-unavailable") return "native_history_unavailable";
|
|
15803
15868
|
if (args.nativeSource && args.nativeSource !== "provider-native") return `native_history_source_${args.nativeSource}`;
|
|
15804
15869
|
if (args.nativeMessageCount <= 0) return "native_history_empty";
|
|
@@ -15806,8 +15871,8 @@ function buildNativeHistoryFallbackReason(args) {
|
|
|
15806
15871
|
if (!args.freshEnough) return "native_history_stale";
|
|
15807
15872
|
return "native_history_not_selected";
|
|
15808
15873
|
}
|
|
15809
|
-
function
|
|
15810
|
-
return providerType
|
|
15874
|
+
function supportsCliNativeTranscript(providerType) {
|
|
15875
|
+
return CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType);
|
|
15811
15876
|
}
|
|
15812
15877
|
function hasSafeNativeHistoryMapping(args) {
|
|
15813
15878
|
const explicitSessionId = String(args.historySessionId || args.providerSessionId || "").trim();
|
|
@@ -15825,7 +15890,7 @@ function isNativeHistoryFreshEnough(args) {
|
|
|
15825
15890
|
const ptyNewest = getMessageNewestReceivedAt(args.ptyMessages);
|
|
15826
15891
|
if (nativeNewest > 0 && nativeNewest >= ptyNewest) return true;
|
|
15827
15892
|
const sourceMtimeMs = Number(args.sourceMtimeMs || 0);
|
|
15828
|
-
if (sourceMtimeMs > 0 && Date.now() - sourceMtimeMs <=
|
|
15893
|
+
if (sourceMtimeMs > 0 && Date.now() - sourceMtimeMs <= CLI_NATIVE_HISTORY_FRESH_MS) return true;
|
|
15829
15894
|
return ptyNewest === 0 && nativeNewest > 0;
|
|
15830
15895
|
}
|
|
15831
15896
|
function shouldPreserveReadChatPayloadField(key) {
|
|
@@ -15874,7 +15939,7 @@ function normalizeReadChatCommandStatus(status, activeModal) {
|
|
|
15874
15939
|
}
|
|
15875
15940
|
switch (raw) {
|
|
15876
15941
|
case "starting":
|
|
15877
|
-
return hasNonEmptyModalButtons(activeModal) ? "waiting_approval" : "
|
|
15942
|
+
return hasNonEmptyModalButtons(activeModal) ? "waiting_approval" : "starting";
|
|
15878
15943
|
case "stopped":
|
|
15879
15944
|
case "disconnected":
|
|
15880
15945
|
case "not_monitored":
|
|
@@ -15894,7 +15959,11 @@ function shouldTrustCliAdapterTerminalStatus(parsedStatus, activeModal, adapter,
|
|
|
15894
15959
|
if (typeof adapter.isProcessing === "function" && adapter.isProcessing()) return false;
|
|
15895
15960
|
return true;
|
|
15896
15961
|
}
|
|
15897
|
-
function normalizeCliReadChatStatus(parsedStatus, activeModal, adapter, adapterStatus) {
|
|
15962
|
+
function normalizeCliReadChatStatus(parsedStatus, activeModal, adapter, adapterStatus, parsedMessages) {
|
|
15963
|
+
const adapterRawStatus = typeof adapterStatus?.status === "string" ? adapterStatus.status.trim() : "";
|
|
15964
|
+
if (adapterRawStatus === "starting" && isGeneratingLikeStatus(parsedStatus) && !hasNonEmptyModalButtons(activeModal) && Array.isArray(parsedMessages) && parsedMessages.length === 0 && Array.isArray(adapterStatus?.messages) && adapterStatus.messages.length === 0 && !(typeof adapter.isProcessing === "function" && adapter.isProcessing())) {
|
|
15965
|
+
return "starting";
|
|
15966
|
+
}
|
|
15898
15967
|
if (shouldTrustCliAdapterTerminalStatus(parsedStatus, activeModal, adapter, adapterStatus)) return "idle";
|
|
15899
15968
|
return typeof parsedStatus === "string" && parsedStatus.trim() ? parsedStatus : "idle";
|
|
15900
15969
|
}
|
|
@@ -16385,7 +16454,7 @@ async function handleReadChat(h, args) {
|
|
|
16385
16454
|
const transcriptAuthority = parsedRecord.transcriptAuthority === "provider" || parsedRecord.transcriptAuthority === "daemon" ? parsedRecord.transcriptAuthority : void 0;
|
|
16386
16455
|
const coverage = parsedRecord.coverage === "full" || parsedRecord.coverage === "tail" || parsedRecord.coverage === "current-turn" ? parsedRecord.coverage : void 0;
|
|
16387
16456
|
const activeModal = parsedRecord.activeModal ?? parsedRecord.modal ?? null;
|
|
16388
|
-
const returnedStatus = normalizeCliReadChatStatus(parsedRecord.status, activeModal, adapter, adapterStatus);
|
|
16457
|
+
const returnedStatus = normalizeCliReadChatStatus(parsedRecord.status, activeModal, adapter, adapterStatus, parsedRecord.messages);
|
|
16389
16458
|
const runtimeMessageMerger = getTargetInstance(h, args);
|
|
16390
16459
|
const parsedMessages = finalizeStreamingMessagesWhenIdle(parsedRecord.messages, returnedStatus);
|
|
16391
16460
|
const returnedMessages = runtimeMessageMerger?.category === "cli" && runtimeMessageMerger.type === adapter.cliType && typeof runtimeMessageMerger.mergeRuntimeChatMessages === "function" ? runtimeMessageMerger.mergeRuntimeChatMessages(parsedMessages) : parsedMessages;
|
|
@@ -16398,12 +16467,12 @@ async function handleReadChat(h, args) {
|
|
|
16398
16467
|
let messageSource = buildCliMessageSourceProvenance({
|
|
16399
16468
|
selected: "pty-parser",
|
|
16400
16469
|
provider: adapter.cliType,
|
|
16401
|
-
fallbackReason:
|
|
16470
|
+
fallbackReason: supportsCliNativeTranscript(providerType) ? "native_history_not_checked" : "provider_native_transcript_not_supported",
|
|
16402
16471
|
ptyMessages: returnedMessages,
|
|
16403
16472
|
returnedMessages,
|
|
16404
16473
|
ptyStatusApprovalOnly: false
|
|
16405
16474
|
});
|
|
16406
|
-
if (
|
|
16475
|
+
if (supportsCliNativeTranscript(providerType)) {
|
|
16407
16476
|
const agentStr = provider?.type || args?.agentType || getCurrentProviderType(h, adapter.cliType);
|
|
16408
16477
|
const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : typeof adapter.workingDir === "string" ? adapter.workingDir : void 0;
|
|
16409
16478
|
const nativeHistoryLimit = Math.max(
|
|
@@ -16509,7 +16578,7 @@ async function handleReadChat(h, args) {
|
|
|
16509
16578
|
returnedStatus: String(returnedStatus || ""),
|
|
16510
16579
|
selectedMessageSource: messageSource.selected,
|
|
16511
16580
|
messageSource,
|
|
16512
|
-
shouldPreferAdapterMessages: messageSource.selected !== "native-history",
|
|
16581
|
+
shouldPreferAdapterMessages: supportsCliNativeTranscript(providerType) && messageSource.selected !== "native-history",
|
|
16513
16582
|
parsedMsgCount: parsedRecord.messages.length,
|
|
16514
16583
|
returnedMsgCount: selectedMessages.length
|
|
16515
16584
|
},
|
|
@@ -16534,9 +16603,39 @@ async function handleReadChat(h, args) {
|
|
|
16534
16603
|
scripts: provider?.scripts
|
|
16535
16604
|
});
|
|
16536
16605
|
const historyProviderSessionId = typeof history?.providerSessionId === "string" ? history.providerSessionId : historySessionId;
|
|
16606
|
+
const historyMessages = Array.isArray(history?.messages) ? normalizeChatMessages(history.messages) : [];
|
|
16607
|
+
const safeMapping = supportsCliNativeTranscript(agentStr) ? hasSafeNativeHistoryMapping({
|
|
16608
|
+
historySessionId,
|
|
16609
|
+
providerSessionId: historyProviderSessionId,
|
|
16610
|
+
workspace,
|
|
16611
|
+
nativeMessages: historyMessages
|
|
16612
|
+
}) : false;
|
|
16613
|
+
const nativeSelected = supportsCliNativeTranscript(agentStr) && history.source === "provider-native" && historyMessages.length > 0 && safeMapping;
|
|
16614
|
+
const messageSource = buildCliMessageSourceProvenance({
|
|
16615
|
+
selected: nativeSelected ? "native-history" : "pty-parser",
|
|
16616
|
+
provider: agentStr,
|
|
16617
|
+
nativeHandle: historyProviderSessionId || historySessionId,
|
|
16618
|
+
fallbackReason: nativeSelected ? void 0 : buildNativeHistoryFallbackReason({
|
|
16619
|
+
providerType: agentStr,
|
|
16620
|
+
nativeSource: history.source,
|
|
16621
|
+
nativeMessageCount: historyMessages.length,
|
|
16622
|
+
safeMapping,
|
|
16623
|
+
freshEnough: true
|
|
16624
|
+
}),
|
|
16625
|
+
nativeSource: history.source,
|
|
16626
|
+
sourcePath: history.sourcePath,
|
|
16627
|
+
sourceMtimeMs: history.sourceMtimeMs,
|
|
16628
|
+
nativeMessages: historyMessages,
|
|
16629
|
+
returnedMessages: historyMessages,
|
|
16630
|
+
safeMapping,
|
|
16631
|
+
freshEnough: true,
|
|
16632
|
+
ptyStatusApprovalOnly: false
|
|
16633
|
+
});
|
|
16537
16634
|
return buildReadChatCommandResult({
|
|
16538
|
-
messages:
|
|
16635
|
+
messages: historyMessages,
|
|
16539
16636
|
status: "idle",
|
|
16637
|
+
messageSource,
|
|
16638
|
+
transcriptProvenance: messageSource,
|
|
16540
16639
|
...typeof history?.title === "string" ? { title: history.title } : {},
|
|
16541
16640
|
...historyProviderSessionId ? { providerSessionId: historyProviderSessionId } : {},
|
|
16542
16641
|
...provider?.historyBehavior?.transcriptAuthority === "provider" || provider?.historyBehavior?.transcriptAuthority === "daemon" ? { transcriptAuthority: (provider?.historyBehavior).transcriptAuthority } : {},
|
|
@@ -21410,6 +21509,7 @@ function commandExists(command) {
|
|
|
21410
21509
|
}
|
|
21411
21510
|
}
|
|
21412
21511
|
var BUSY_AGENT_STATUSES = /* @__PURE__ */ new Set(["generating", "running", "streaming", "starting", "busy", "waiting", "waiting_approval", "long_generating"]);
|
|
21512
|
+
var ZERO_MESSAGE_STARTING_SEND_WAIT_MS = 2e3;
|
|
21413
21513
|
function normalizeAgentStatus(value) {
|
|
21414
21514
|
return typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
21415
21515
|
}
|
|
@@ -21431,6 +21531,20 @@ function hasAdapterPendingResponse(adapter) {
|
|
|
21431
21531
|
}
|
|
21432
21532
|
return false;
|
|
21433
21533
|
}
|
|
21534
|
+
function countMessages(value) {
|
|
21535
|
+
return Array.isArray(value) ? value.length : 0;
|
|
21536
|
+
}
|
|
21537
|
+
function hasZeroMessageStartingLaunch(adapter) {
|
|
21538
|
+
const adapterStatus = adapter?.getStatus?.({ allowParse: false }) ?? adapter?.getStatus?.() ?? {};
|
|
21539
|
+
const parsedStatus = typeof adapter?.getScriptParsedStatus === "function" ? adapter.getScriptParsedStatus() : {};
|
|
21540
|
+
const adapterRawStatus = normalizeAgentStatus(adapterStatus?.status);
|
|
21541
|
+
const parsedRawStatus = normalizeAgentStatus(parsedStatus?.status);
|
|
21542
|
+
if (adapterRawStatus !== "starting") return false;
|
|
21543
|
+
if (parsedRawStatus && parsedRawStatus !== "starting" && parsedRawStatus !== "generating") return false;
|
|
21544
|
+
if (hasNonEmptyModalButtons2(adapterStatus?.activeModal ?? adapterStatus?.modal ?? parsedStatus?.activeModal ?? parsedStatus?.modal)) return false;
|
|
21545
|
+
if (countMessages(adapterStatus?.messages) > 0 || countMessages(parsedStatus?.messages) > 0) return false;
|
|
21546
|
+
return !hasAdapterPendingResponse(adapter);
|
|
21547
|
+
}
|
|
21434
21548
|
function shouldSuppressStaleParsedBusyStatus(adapterStatus, parsedStatus, adapter) {
|
|
21435
21549
|
const parsedRawStatus = normalizeAgentStatus(parsedStatus?.status);
|
|
21436
21550
|
if (!BUSY_AGENT_STATUSES.has(parsedRawStatus)) return false;
|
|
@@ -21454,6 +21568,19 @@ function getEffectiveAgentSendStatus(adapter) {
|
|
|
21454
21568
|
}
|
|
21455
21569
|
return adapterStatus;
|
|
21456
21570
|
}
|
|
21571
|
+
async function waitForZeroMessageStartingLaunch(adapter) {
|
|
21572
|
+
try {
|
|
21573
|
+
if (!hasZeroMessageStartingLaunch(adapter)) return false;
|
|
21574
|
+
} catch {
|
|
21575
|
+
return false;
|
|
21576
|
+
}
|
|
21577
|
+
await new Promise((resolve16) => setTimeout(resolve16, ZERO_MESSAGE_STARTING_SEND_WAIT_MS));
|
|
21578
|
+
try {
|
|
21579
|
+
return hasZeroMessageStartingLaunch(adapter);
|
|
21580
|
+
} catch {
|
|
21581
|
+
return false;
|
|
21582
|
+
}
|
|
21583
|
+
}
|
|
21457
21584
|
var chalkModule = chalk;
|
|
21458
21585
|
var chalkApi = typeof chalkModule.yellow === "function" ? chalkModule : chalkModule.default || null;
|
|
21459
21586
|
function colorize(color, text) {
|
|
@@ -22228,7 +22355,12 @@ Run 'adhdev doctor' for detailed diagnostics.`
|
|
|
22228
22355
|
if (!found) throw new Error(`CLI agent not running: ${agentType}`);
|
|
22229
22356
|
const { adapter, key } = found;
|
|
22230
22357
|
if (action === "send_chat") {
|
|
22231
|
-
|
|
22358
|
+
let currentStatus = getEffectiveAgentSendStatus(adapter);
|
|
22359
|
+
if (currentStatus === "starting" && await waitForZeroMessageStartingLaunch(adapter)) {
|
|
22360
|
+
currentStatus = "idle";
|
|
22361
|
+
} else if (currentStatus === "starting") {
|
|
22362
|
+
currentStatus = getEffectiveAgentSendStatus(adapter);
|
|
22363
|
+
}
|
|
22232
22364
|
if (BUSY_AGENT_STATUSES.has(currentStatus)) {
|
|
22233
22365
|
return {
|
|
22234
22366
|
success: false,
|