@adhdev/daemon-standalone 1.0.18-rc.13 → 1.0.18-rc.15

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 CHANGED
@@ -30265,10 +30265,10 @@ var require_dist3 = __commonJS({
30265
30265
  }
30266
30266
  function getDaemonBuildInfo() {
30267
30267
  if (cached2) return cached2;
30268
- const commit = readInjected(true ? "2a9ab536171fcf675788ac5b41596e740046bbfa" : void 0) ?? "unknown";
30269
- const commitShort = readInjected(true ? "2a9ab536" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30270
- const version2 = readInjected(true ? "1.0.18-rc.13" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30271
- const builtAt = readInjected(true ? "2026-07-22T14:02:17.678Z" : void 0);
30268
+ const commit = readInjected(true ? "64f056340da99d3b28464efcf5c05fe643e5db63" : void 0) ?? "unknown";
30269
+ const commitShort = readInjected(true ? "64f05634" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30270
+ const version2 = readInjected(true ? "1.0.18-rc.15" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30271
+ const builtAt = readInjected(true ? "2026-07-23T00:53:09.129Z" : void 0);
30272
30272
  cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
30273
30273
  return cached2;
30274
30274
  }
@@ -42873,6 +42873,12 @@ ${rendered}`, "utf-8");
42873
42873
  import_session_host_core22 = require_dist();
42874
42874
  }
42875
42875
  });
42876
+ function isPurePtyTranscriptProvider(provider) {
42877
+ if (provider.transcriptAuthority === "provider") return false;
42878
+ if (provider.nativeHistory) return false;
42879
+ const transcriptPty = provider.tui?.transcriptPty;
42880
+ return transcriptPty?.scope === "buffer";
42881
+ }
42876
42882
  function stripAnsi(str) {
42877
42883
  return str.replace(/\x1B\][^\x07]*(?:\x07|\x1B\\)/g, "").replace(/\x1B[P^_X][\s\S]*?(?:\x07|\x1B\\)/g, "").replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
42878
42884
  }
@@ -52218,34 +52224,37 @@ ${cleanBody}`;
52218
52224
  if (!dispatchMeshCommand) return;
52219
52225
  const meshId = mesh.id;
52220
52226
  const pulls = candidateDaemonIds.length > 0 ? candidateDaemonIds.map((id) => ({ meshId, coordinatorDaemonId: id })) : [{ meshId }];
52221
- await Promise.allSettled(mesh.nodes.map(async (node) => {
52222
- const nodeDaemonId = readNonEmptyString(node.daemonId);
52223
- if (!nodeDaemonId) return;
52224
- if (daemonIdsEquivalent(nodeDaemonId, localDaemonId)) return;
52225
- if (daemonIdListIncludes(candidateDaemonIds, nodeDaemonId)) return;
52226
- const getPeerStatus = components.getMeshPeerConnectionStatus;
52227
- if (getPeerStatus) {
52228
- const peerSnapshot = getPeerStatus(nodeDaemonId);
52229
- if (!peerSnapshot || String(peerSnapshot.state) !== "connected") return;
52230
- }
52231
- for (const pendingEventArgs of pulls) {
52232
- let events;
52227
+ await Promise.allSettled(mesh.nodes.map((node) => pullPendingEventsFromNode(components, meshId, node, localDaemonId, candidateDaemonIds, pulls)));
52228
+ }
52229
+ async function pullPendingEventsFromNode(components, meshId, node, localDaemonId, candidateDaemonIds, pulls) {
52230
+ const dispatchMeshCommand = components.dispatchMeshCommand;
52231
+ if (!dispatchMeshCommand) return;
52232
+ const nodeDaemonId = readNonEmptyString(node.daemonId);
52233
+ if (!nodeDaemonId) return;
52234
+ if (daemonIdsEquivalent(nodeDaemonId, localDaemonId)) return;
52235
+ if (daemonIdListIncludes(candidateDaemonIds, nodeDaemonId)) return;
52236
+ const getPeerStatus = components.getMeshPeerConnectionStatus;
52237
+ if (getPeerStatus) {
52238
+ const peerSnapshot = getPeerStatus(nodeDaemonId);
52239
+ if (!peerSnapshot || String(peerSnapshot.state) !== "connected") return;
52240
+ }
52241
+ for (const pendingEventArgs of pulls) {
52242
+ let events;
52243
+ try {
52244
+ events = await dispatchMeshCommand(nodeDaemonId, "get_pending_mesh_events", pendingEventArgs);
52245
+ } catch {
52246
+ break;
52247
+ }
52248
+ const list = extractPendingEvents(events).filter((e) => readNonEmptyString(e?.meshId) === meshId);
52249
+ for (const event of list) {
52250
+ const payload = buildForwardPayloadFromPending(event);
52251
+ if (!payload.event || !payload.meshId) continue;
52233
52252
  try {
52234
- events = await dispatchMeshCommand(nodeDaemonId, "get_pending_mesh_events", pendingEventArgs);
52253
+ handleMeshForwardEvent(components, payload);
52235
52254
  } catch {
52236
- break;
52237
- }
52238
- const list = extractPendingEvents(events).filter((e) => readNonEmptyString(e?.meshId) === meshId);
52239
- for (const event of list) {
52240
- const payload = buildForwardPayloadFromPending(event);
52241
- if (!payload.event || !payload.meshId) continue;
52242
- try {
52243
- handleMeshForwardEvent(components, payload);
52244
- } catch {
52245
- }
52246
52255
  }
52247
52256
  }
52248
- }));
52257
+ }
52249
52258
  }
52250
52259
  function unwrapReadChatPayload(raw) {
52251
52260
  let cursor = raw;
@@ -53145,7 +53154,7 @@ ${cleanBody}`;
53145
53154
  return false;
53146
53155
  }
53147
53156
  }
53148
- async function recoverStrandedAssignedDispatches(components, mesh, store) {
53157
+ async function recoverStrandedAssignedDispatches(components, mesh, store, localDaemonId, selfIds = []) {
53149
53158
  const meshId = mesh.id;
53150
53159
  const assigned = getQueue(meshId, { status: ["assigned"] });
53151
53160
  if (!assigned.length) return;
@@ -53158,10 +53167,54 @@ ${cleanBody}`;
53158
53167
  for (const key2 of [...deliveredUnconsumedUnknownStreak.keys()]) {
53159
53168
  if (key2.startsWith(meshKeyPrefix) && !assignedKeys.has(key2)) deliveredUnconsumedUnknownStreak.delete(key2);
53160
53169
  }
53170
+ for (const key2 of [...assignedIdleFinalAssistantSince.keys()]) {
53171
+ if (key2.startsWith(meshKeyPrefix) && !assignedKeys.has(key2)) assignedIdleFinalAssistantSince.delete(key2);
53172
+ }
53161
53173
  for (const row of assigned) {
53162
53174
  const dispatchedAtMs = Date.parse(row.dispatchTimestamp ?? "");
53163
53175
  if (!Number.isFinite(dispatchedAtMs)) continue;
53164
53176
  const ageMs = nowMs - dispatchedAtMs;
53177
+ const idleTranscriptStreakKey = `${meshId}::${row.id}`;
53178
+ if (store.taskHasConfirmedDelivery(meshId, row.id) && !findTerminalLedgerEvidenceForTask({ meshId, taskId: row.id }) && readNonEmptyString(row.assignedSessionId) && resolveSessionBusyVerdict(components, row.assignedSessionId) !== "GENERATING") {
53179
+ const since = assignedIdleFinalAssistantSince.get(idleTranscriptStreakKey);
53180
+ if (since === void 0) {
53181
+ assignedIdleFinalAssistantSince.set(idleTranscriptStreakKey, nowMs);
53182
+ } else if (nowMs - since >= ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS) {
53183
+ const terminalEvidence = await pollAssignedTaskTerminalEvidence(components, mesh, row);
53184
+ if (terminalEvidence) {
53185
+ assignedIdleFinalAssistantSince.delete(idleTranscriptStreakKey);
53186
+ updateTaskStatus(meshId, row.id, terminalEvidence);
53187
+ if (!findTerminalLedgerEvidenceForTask({ meshId, taskId: row.id })) {
53188
+ try {
53189
+ appendLedgerEntry(meshId, {
53190
+ kind: terminalEvidence === "completed" ? "task_completed" : "task_failed",
53191
+ nodeId: row.assignedNodeId,
53192
+ sessionId: row.assignedSessionId,
53193
+ providerType: row.assignedProviderType,
53194
+ payload: {
53195
+ taskId: row.id,
53196
+ event: "agent:generating_completed",
53197
+ source: "early_idle_transcript_evidence"
53198
+ }
53199
+ });
53200
+ } catch {
53201
+ }
53202
+ }
53203
+ LOG2.warn("MeshReconcile", `Early-completed assigned task ${row.id} on mesh ${meshId} (node=${row.assignedNodeId ?? "?"} session=${row.assignedSessionId ?? "?"}): worker idle with a final assistant message after dispatch for \u2265${Math.round(ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS / 1e3)}s \u2014 the completion event was lost/late (pure-PTY provider), task is ${terminalEvidence} without waiting the 15-min deadline`);
53204
+ traceMeshEventDrop("assigned_early_transcript_completed", {
53205
+ taskId: row.id,
53206
+ sessionId: row.assignedSessionId,
53207
+ nodeId: row.assignedNodeId,
53208
+ meshId,
53209
+ event: "agent:generating_completed"
53210
+ }, terminalEvidence);
53211
+ continue;
53212
+ }
53213
+ assignedIdleFinalAssistantSince.delete(idleTranscriptStreakKey);
53214
+ }
53215
+ } else {
53216
+ assignedIdleFinalAssistantSince.delete(idleTranscriptStreakKey);
53217
+ }
53165
53218
  if (ageMs >= ASSIGNED_DELIVERED_UNCONSUMED_REDRIVE_MS && ageMs < ASSIGNED_STRANDED_DEADLINE_MS && store.taskHasConfirmedDelivery(meshId, row.id) && !store.taskDeliveryConsumed(meshId, row.id)) {
53166
53219
  const terminal2 = findTerminalLedgerEvidenceForTask({ meshId, taskId: row.id });
53167
53220
  if (terminal2) {
@@ -53169,6 +53222,24 @@ ${cleanBody}`;
53169
53222
  updateTaskStatus(meshId, row.id, status);
53170
53223
  continue;
53171
53224
  }
53225
+ const assignedNode = row.assignedNodeId ? mesh.nodes?.find((n) => meshNodeIdMatches(n, row.assignedNodeId)) : void 0;
53226
+ if (assignedNode?.daemonId) {
53227
+ try {
53228
+ await pullPendingEventsFromNode(
53229
+ components,
53230
+ meshId,
53231
+ assignedNode,
53232
+ localDaemonId,
53233
+ selfIds,
53234
+ selfIds.length > 0 ? selfIds.map((id) => ({ meshId, coordinatorDaemonId: id })) : [{ meshId }]
53235
+ );
53236
+ } catch {
53237
+ }
53238
+ if (store.taskDeliveryConsumed(meshId, row.id)) {
53239
+ deliveredUnconsumedUnknownStreak.delete(`${meshId}::${row.id}`);
53240
+ continue;
53241
+ }
53242
+ }
53172
53243
  const shortStreakKey = `${meshId}::${row.id}`;
53173
53244
  const verdict = row.assignedSessionId ? resolveSessionBusyVerdict(components, row.assignedSessionId) : "IDLE_CONFIRMED";
53174
53245
  if (verdict === "GENERATING") {
@@ -53427,7 +53498,7 @@ ${cleanBody}`;
53427
53498
  const selfIds = resolveCoordinatorSelfIds(mesh, drainDaemonIds);
53428
53499
  if (!daemonHostsMesh(mesh, selfIds)) continue;
53429
53500
  try {
53430
- await recoverStrandedAssignedDispatches(components, mesh, store);
53501
+ await recoverStrandedAssignedDispatches(components, mesh, store, localDaemonId, selfIds);
53431
53502
  } catch (e) {
53432
53503
  LOG2.warn("MeshReconcile", `Assigned-stranded watchdog failed for mesh ${mesh.id}: ${e?.message || e}`);
53433
53504
  }
@@ -53829,6 +53900,8 @@ ${cleanBody}`;
53829
53900
  var RECLAIM_UNKNOWN_GRACE_TICKS;
53830
53901
  var deliveredNoTurnUnknownStreak;
53831
53902
  var deliveredUnconsumedUnknownStreak;
53903
+ var ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS;
53904
+ var assignedIdleFinalAssistantSince;
53832
53905
  var ZOMBIE_ASSIGNED_MIN_AGE_MS;
53833
53906
  var STRICT_SESSION_MATCH_TTL_MS;
53834
53907
  var unresolvedForwardRejectionCounts;
@@ -53873,6 +53946,8 @@ ${cleanBody}`;
53873
53946
  RECLAIM_UNKNOWN_GRACE_TICKS = 3;
53874
53947
  deliveredNoTurnUnknownStreak = /* @__PURE__ */ new Map();
53875
53948
  deliveredUnconsumedUnknownStreak = /* @__PURE__ */ new Map();
53949
+ ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS = 8e3;
53950
+ assignedIdleFinalAssistantSince = /* @__PURE__ */ new Map();
53876
53951
  ZOMBIE_ASSIGNED_MIN_AGE_MS = 30 * 60 * 1e3;
53877
53952
  STRICT_SESSION_MATCH_TTL_MS = 6e4;
53878
53953
  unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
@@ -56630,7 +56705,8 @@ ${cont}` : cont;
56630
56705
  this.currentTurnStartedAt = Date.now();
56631
56706
  this.responseEpoch += 1;
56632
56707
  this.clearApprovalResolutionMemory();
56633
- if (this.provider.transcriptAuthority === "provider" && this.currentStatus !== "waiting_approval") {
56708
+ const promoteOnTurnStart = this.provider.transcriptAuthority === "provider" || isPurePtyTranscriptProvider(this.provider);
56709
+ if (promoteOnTurnStart && this.currentStatus !== "waiting_approval") {
56634
56710
  this.setStatus("generating", "turn_started");
56635
56711
  this.callbacks.onStatusChange();
56636
56712
  }
@@ -58161,10 +58237,7 @@ ${lastSnapshot}`;
58161
58237
  * provider-owned) so no other provider's turn-scoped parse changes.
58162
58238
  */
58163
58239
  parsesFullPtyTranscriptFromBuffer() {
58164
- if (this.providerOwnsTranscript()) return false;
58165
- if (this.provider.nativeHistory) return false;
58166
- const transcriptPty = this.provider.tui?.transcriptPty;
58167
- return transcriptPty?.scope === "buffer";
58240
+ return isPurePtyTranscriptProvider(this.provider);
58168
58241
  }
58169
58242
  /**
58170
58243
  * The turn scope to feed the transcript parser. Normally the live turn scope
@@ -75170,6 +75243,7 @@ ${body}
75170
75243
  init_contracts2();
75171
75244
  init_provider_input_support();
75172
75245
  init_hash();
75246
+ init_provider_cli_shared();
75173
75247
  var fs222 = __toESM2(require("fs"));
75174
75248
  var path26 = __toESM2(require("path"));
75175
75249
  init_provider_cli_adapter();
@@ -80798,6 +80872,10 @@ ${body}
80798
80872
  return;
80799
80873
  }
80800
80874
  }
80875
+ if (this.tryReconcilePurePtyCompletionForStall(observedStatus)) {
80876
+ this.meshStallEmittedForAnchor = true;
80877
+ return;
80878
+ }
80801
80879
  this.meshStallEmittedForAnchor = true;
80802
80880
  if (this.meshStallLastFiredAt >= 0 && now - this.meshStallLastFiredAt < _CliProviderInstance.MESH_WORKER_STALL_REFIRE_COOLDOWN_MS) {
80803
80881
  return;
@@ -80928,6 +81006,70 @@ ${body}
80928
81006
  });
80929
81007
  return true;
80930
81008
  }
81009
+ /**
81010
+ * KIMI-PURE-PTY-COMPLETION-EMIT (Fix 3): stall-path completion reconcile for the
81011
+ * PURE-PTY transcript class (kimi and kin — no native transcript, no provider
81012
+ * authority; see isPurePtyTranscriptProvider). Such a worker whose
81013
+ * generating_completed never emitted (the onTurnStarted idle→idle collapse Fix 1
81014
+ * fixes at the source) sits at a STATIC idle prompt: its PTY output stops the
81015
+ * instant the answer is rendered, so the status-agnostic no-progress watchdog
81016
+ * (checkMeshWorkerStall) reads the finished-but-quiet session as a stall and would
81017
+ * false-fire monitor:no_progress. The native-transcript reconcile
81018
+ * (sampleNativeTranscriptProgress) does NOT cover this class (no native source →
81019
+ * null sample), so the stall path needs its own guard.
81020
+ *
81021
+ * Called from checkMeshWorkerStall just before the fire. Returns true when the
81022
+ * session is a finished pure-PTY turn — idle, no pending response, and a PTY-parsed
81023
+ * in-turn final assistant summary — in which case it emits the missing
81024
+ * generating_completed (idempotent: a real/late emit writes the terminal ledger and
81025
+ * the coordinator's reconcile makes any duplicate a no-op) and the caller SUPPRESSES
81026
+ * the stall. Returns false for every other class/state (native-source provider, a
81027
+ * genuinely mid-turn or wedged worker with no final assistant), so a real stall still
81028
+ * fires unchanged.
81029
+ *
81030
+ * Evidence bar is identical to flushMeshCompletionBeforeCleanup: injected task's turn
81031
+ * genuinely started + an in-turn final assistant summary. Conservative by
81032
+ * construction — no summary ⇒ no proof of completion ⇒ return false and let the real
81033
+ * stall fire.
81034
+ */
81035
+ tryReconcilePurePtyCompletionForStall(observedStatus) {
81036
+ if (!isPurePtyTranscriptProvider(this.provider)) return false;
81037
+ if (observedStatus !== "idle") return false;
81038
+ if (this.hasAdapterPendingResponse()) return false;
81039
+ const taskId = this.completingTurnTaskId();
81040
+ if (this.lastEmittedCompletion && this.lastEmittedCompletion.taskId === (taskId ?? "")) {
81041
+ return false;
81042
+ }
81043
+ if (!this.injectedTaskHasStartedGenerating()) return false;
81044
+ const turnStartedAt = typeof this.adapter?.currentTurnStartedAt === "number" ? this.adapter.currentTurnStartedAt : this.meshTaskInjectedAt || void 0;
81045
+ let parsedMessages;
81046
+ try {
81047
+ parsedMessages = this.adapter?.getScriptParsedStatus?.()?.messages;
81048
+ } catch {
81049
+ parsedMessages = void 0;
81050
+ }
81051
+ let finalSummary;
81052
+ try {
81053
+ finalSummary = this.completionFinalSummary(parsedMessages, turnStartedAt);
81054
+ } catch {
81055
+ finalSummary = void 0;
81056
+ }
81057
+ if (!finalSummary) return false;
81058
+ LOG2.warn("CLI", `[${this.type}] reconciling pure-PTY mesh completion from the stall path for session ${this.instanceId} task=${taskId ?? "(none)"} \u2014 PTY is idle-quiet with an in-turn final assistant message but the completion event never fired (pure-PTY provider); emitting it instead of a false monitor:no_progress.`);
81059
+ if (this.isMeshWorkerSession()) {
81060
+ traceMeshEventStage("fired", this.meshTraceCtx(), "stall_pure_pty_transcript_completion");
81061
+ }
81062
+ this.emitGeneratingCompleted({
81063
+ chatTitle: "",
81064
+ duration: void 0,
81065
+ timestamp: Date.now(),
81066
+ taskId,
81067
+ finalSummary,
81068
+ evidenceLevel: "transcript",
81069
+ completionDiagnostic: { source: "stall_pure_pty_transcript_completion" }
81070
+ });
81071
+ return true;
81072
+ }
80931
81073
  /**
80932
81074
  * AUTOAPPROVE-FLAP-RECUR (Fix A+B): how long a busy blip / modal scroll-out may
80933
81075
  * persist before the in-progress settle gate is torn down. For a delegated