@adhdev/daemon-standalone 1.0.18-rc.14 → 1.0.18-rc.16

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 ? "a44f4a2814c4db171a9ebb0f6fcfb0798203aebb" : void 0) ?? "unknown";
30269
- const commitShort = readInjected(true ? "a44f4a28" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30270
- const version2 = readInjected(true ? "1.0.18-rc.14" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30271
- const builtAt = readInjected(true ? "2026-07-22T17:38:24.589Z" : void 0);
30268
+ const commit = readInjected(true ? "74f34080bcd7c145e55fd7e5fd492a40a4942bc4" : void 0) ?? "unknown";
30269
+ const commitShort = readInjected(true ? "74f34080" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
30270
+ const version2 = readInjected(true ? "1.0.18-rc.16" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
30271
+ const builtAt = readInjected(true ? "2026-07-23T02:30:18.950Z" : 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
  }
@@ -49159,6 +49165,26 @@ The mesh has no work in flight. For each mission, decide its outcome: continue i
49159
49165
  }
49160
49166
  return null;
49161
49167
  }
49168
+ function hasTrailingToolActivityAfterFinalAssistant(messages) {
49169
+ if (!Array.isArray(messages) || messages.length === 0) return false;
49170
+ let sawTrailingToolActivity = false;
49171
+ for (let i = messages.length - 1; i >= 0; i--) {
49172
+ const msg = messages[i];
49173
+ if (!msg) continue;
49174
+ const classification = classifyChatMessageVisibility(msg);
49175
+ if (classification.isUserFacing && (msg.role === "assistant" || msg.role === "model")) {
49176
+ if (flattenContent(msg.content).trim()) return sawTrailingToolActivity;
49177
+ return false;
49178
+ }
49179
+ if (classification.isUserFacing) {
49180
+ return false;
49181
+ }
49182
+ if (classification.kind === "tool" || classification.kind === "terminal") {
49183
+ sawTrailingToolActivity = true;
49184
+ }
49185
+ }
49186
+ return false;
49187
+ }
49162
49188
  function canonicalizeKindHint(value) {
49163
49189
  return value.trim().toLowerCase().replace(/[\s-]+/g, "_");
49164
49190
  }
@@ -52858,6 +52884,7 @@ ${cleanBody}`;
52858
52884
  const messages = Array.isArray(payload.messages) ? payload.messages : [];
52859
52885
  const evidence = extractFinalAssistantSummaryEvidence(messages);
52860
52886
  if (!evidence.finalSummary) return null;
52887
+ if (hasTrailingToolActivityAfterFinalAssistant(messages)) return null;
52861
52888
  const dispatchedAtMs = Date.parse(readNonEmptyString(row.dispatchTimestamp));
52862
52889
  const transcriptAtMs = Date.parse(evidence.transcriptMessageAt ?? "");
52863
52890
  if (!(Number.isFinite(dispatchedAtMs) && Number.isFinite(transcriptAtMs) && transcriptAtMs >= dispatchedAtMs)) {
@@ -53148,6 +53175,52 @@ ${cleanBody}`;
53148
53175
  return false;
53149
53176
  }
53150
53177
  }
53178
+ function resolveLocalSessionPurePty(components, sessionId) {
53179
+ try {
53180
+ const instances = components.instanceManager?.getByCategory?.("cli") || [];
53181
+ const inst = instances.find((i) => {
53182
+ const sid = readNonEmptyString(i?.getState?.().instanceId);
53183
+ return sid && sessionIdsEquivalent(sid, sessionId);
53184
+ });
53185
+ if (!inst) return void 0;
53186
+ const provider = inst.provider;
53187
+ if (!provider || typeof provider !== "object") return void 0;
53188
+ return isPurePtyTranscriptProvider(provider);
53189
+ } catch {
53190
+ return void 0;
53191
+ }
53192
+ }
53193
+ async function evaluateEarlyIdleTranscriptArm(components, mesh, store, row, localDaemonId, selfIds = []) {
53194
+ const sessionId = readNonEmptyString(row.assignedSessionId);
53195
+ if (!sessionId) return false;
53196
+ const verdict = resolveSessionBusyVerdict(components, sessionId);
53197
+ if (verdict === "GENERATING") return false;
53198
+ if (verdict === "UNKNOWN") {
53199
+ const nodeId = readNonEmptyString(row.assignedNodeId);
53200
+ const node = (mesh.nodes ?? []).find((n) => n.id === nodeId);
53201
+ const liveStatus = nodeId ? readNonEmptyString(sessionStatusFromNodes(mesh.nodes, nodeId, sessionId).status).toLowerCase() : "";
53202
+ if (liveStatus && liveStatus !== "idle") return false;
53203
+ if (!liveStatus) {
53204
+ const nodeDaemonId = readNonEmptyString(node?.daemonId);
53205
+ const isLocalNode = !nodeDaemonId || daemonIdsEquivalent(nodeDaemonId, localDaemonId) || daemonIdListIncludes(selfIds, nodeDaemonId) || !!components.instanceManager?.getInstance?.(sessionId);
53206
+ const providerType = readNonEmptyString(row.assignedProviderType);
53207
+ const readArgs = {
53208
+ sessionId,
53209
+ targetSessionId: sessionId,
53210
+ tailLimit: 1,
53211
+ ...node?.workspace ? { workspace: node.workspace } : {},
53212
+ ...providerType ? { agentType: providerType, providerType } : {}
53213
+ };
53214
+ const probedStatus = await reprobeWorkerStatus(components, { isLocalNode, nodeDaemonId, readArgs });
53215
+ if (probedStatus !== "idle") return false;
53216
+ }
53217
+ }
53218
+ if (store.taskDeliveryConsumed(mesh.id, row.id)) return true;
53219
+ const localPurePty = resolveLocalSessionPurePty(components, sessionId);
53220
+ if (localPurePty === true) return true;
53221
+ if (localPurePty === false) return false;
53222
+ return verdict === "UNKNOWN";
53223
+ }
53151
53224
  async function recoverStrandedAssignedDispatches(components, mesh, store, localDaemonId, selfIds = []) {
53152
53225
  const meshId = mesh.id;
53153
53226
  const assigned = getQueue(meshId, { status: ["assigned"] });
@@ -53161,10 +53234,55 @@ ${cleanBody}`;
53161
53234
  for (const key2 of [...deliveredUnconsumedUnknownStreak.keys()]) {
53162
53235
  if (key2.startsWith(meshKeyPrefix) && !assignedKeys.has(key2)) deliveredUnconsumedUnknownStreak.delete(key2);
53163
53236
  }
53237
+ for (const key2 of [...assignedIdleFinalAssistantSince.keys()]) {
53238
+ if (key2.startsWith(meshKeyPrefix) && !assignedKeys.has(key2)) assignedIdleFinalAssistantSince.delete(key2);
53239
+ }
53164
53240
  for (const row of assigned) {
53165
53241
  const dispatchedAtMs = Date.parse(row.dispatchTimestamp ?? "");
53166
53242
  if (!Number.isFinite(dispatchedAtMs)) continue;
53167
53243
  const ageMs = nowMs - dispatchedAtMs;
53244
+ const idleTranscriptStreakKey = `${meshId}::${row.id}`;
53245
+ const earlyArm = store.taskHasConfirmedDelivery(meshId, row.id) && !findTerminalLedgerEvidenceForTask({ meshId, taskId: row.id }) && readNonEmptyString(row.assignedSessionId) ? await evaluateEarlyIdleTranscriptArm(components, mesh, store, row, localDaemonId, selfIds) : false;
53246
+ if (earlyArm) {
53247
+ const since = assignedIdleFinalAssistantSince.get(idleTranscriptStreakKey);
53248
+ if (since === void 0) {
53249
+ assignedIdleFinalAssistantSince.set(idleTranscriptStreakKey, nowMs);
53250
+ } else if (nowMs - since >= ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS) {
53251
+ const terminalEvidence = await pollAssignedTaskTerminalEvidence(components, mesh, row);
53252
+ if (terminalEvidence) {
53253
+ assignedIdleFinalAssistantSince.delete(idleTranscriptStreakKey);
53254
+ updateTaskStatus(meshId, row.id, terminalEvidence);
53255
+ if (!findTerminalLedgerEvidenceForTask({ meshId, taskId: row.id })) {
53256
+ try {
53257
+ appendLedgerEntry(meshId, {
53258
+ kind: terminalEvidence === "completed" ? "task_completed" : "task_failed",
53259
+ nodeId: row.assignedNodeId,
53260
+ sessionId: row.assignedSessionId,
53261
+ providerType: row.assignedProviderType,
53262
+ payload: {
53263
+ taskId: row.id,
53264
+ event: "agent:generating_completed",
53265
+ source: "early_idle_transcript_evidence"
53266
+ }
53267
+ });
53268
+ } catch {
53269
+ }
53270
+ }
53271
+ 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`);
53272
+ traceMeshEventDrop("assigned_early_transcript_completed", {
53273
+ taskId: row.id,
53274
+ sessionId: row.assignedSessionId,
53275
+ nodeId: row.assignedNodeId,
53276
+ meshId,
53277
+ event: "agent:generating_completed"
53278
+ }, terminalEvidence);
53279
+ continue;
53280
+ }
53281
+ assignedIdleFinalAssistantSince.delete(idleTranscriptStreakKey);
53282
+ }
53283
+ } else {
53284
+ assignedIdleFinalAssistantSince.delete(idleTranscriptStreakKey);
53285
+ }
53168
53286
  if (ageMs >= ASSIGNED_DELIVERED_UNCONSUMED_REDRIVE_MS && ageMs < ASSIGNED_STRANDED_DEADLINE_MS && store.taskHasConfirmedDelivery(meshId, row.id) && !store.taskDeliveryConsumed(meshId, row.id)) {
53169
53287
  const terminal2 = findTerminalLedgerEvidenceForTask({ meshId, taskId: row.id });
53170
53288
  if (terminal2) {
@@ -53850,6 +53968,8 @@ ${cleanBody}`;
53850
53968
  var RECLAIM_UNKNOWN_GRACE_TICKS;
53851
53969
  var deliveredNoTurnUnknownStreak;
53852
53970
  var deliveredUnconsumedUnknownStreak;
53971
+ var ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS;
53972
+ var assignedIdleFinalAssistantSince;
53853
53973
  var ZOMBIE_ASSIGNED_MIN_AGE_MS;
53854
53974
  var STRICT_SESSION_MATCH_TTL_MS;
53855
53975
  var unresolvedForwardRejectionCounts;
@@ -53880,6 +54000,7 @@ ${cleanBody}`;
53880
54000
  init_mesh_reconcile_identity();
53881
54001
  init_mesh_reconcile_config();
53882
54002
  init_mesh_remote_event_pull();
54003
+ init_provider_cli_shared();
53883
54004
  init_mesh_disk_retention();
53884
54005
  init_mesh_completion_synthesis();
53885
54006
  init_mesh_active_work();
@@ -53894,6 +54015,8 @@ ${cleanBody}`;
53894
54015
  RECLAIM_UNKNOWN_GRACE_TICKS = 3;
53895
54016
  deliveredNoTurnUnknownStreak = /* @__PURE__ */ new Map();
53896
54017
  deliveredUnconsumedUnknownStreak = /* @__PURE__ */ new Map();
54018
+ ASSIGNED_IDLE_TRANSCRIPT_COMPLETE_MS = 8e3;
54019
+ assignedIdleFinalAssistantSince = /* @__PURE__ */ new Map();
53897
54020
  ZOMBIE_ASSIGNED_MIN_AGE_MS = 30 * 60 * 1e3;
53898
54021
  STRICT_SESSION_MATCH_TTL_MS = 6e4;
53899
54022
  unresolvedForwardRejectionCounts = /* @__PURE__ */ new Map();
@@ -56651,7 +56774,8 @@ ${cont}` : cont;
56651
56774
  this.currentTurnStartedAt = Date.now();
56652
56775
  this.responseEpoch += 1;
56653
56776
  this.clearApprovalResolutionMemory();
56654
- if (this.provider.transcriptAuthority === "provider" && this.currentStatus !== "waiting_approval") {
56777
+ const promoteOnTurnStart = this.provider.transcriptAuthority === "provider" || isPurePtyTranscriptProvider(this.provider);
56778
+ if (promoteOnTurnStart && this.currentStatus !== "waiting_approval") {
56655
56779
  this.setStatus("generating", "turn_started");
56656
56780
  this.callbacks.onStatusChange();
56657
56781
  }
@@ -58182,10 +58306,7 @@ ${lastSnapshot}`;
58182
58306
  * provider-owned) so no other provider's turn-scoped parse changes.
58183
58307
  */
58184
58308
  parsesFullPtyTranscriptFromBuffer() {
58185
- if (this.providerOwnsTranscript()) return false;
58186
- if (this.provider.nativeHistory) return false;
58187
- const transcriptPty = this.provider.tui?.transcriptPty;
58188
- return transcriptPty?.scope === "buffer";
58309
+ return isPurePtyTranscriptProvider(this.provider);
58189
58310
  }
58190
58311
  /**
58191
58312
  * The turn scope to feed the transcript parser. Normally the live turn scope
@@ -75191,6 +75312,7 @@ ${body}
75191
75312
  init_contracts2();
75192
75313
  init_provider_input_support();
75193
75314
  init_hash();
75315
+ init_provider_cli_shared();
75194
75316
  var fs222 = __toESM2(require("fs"));
75195
75317
  var path26 = __toESM2(require("path"));
75196
75318
  init_provider_cli_adapter();
@@ -80819,6 +80941,10 @@ ${body}
80819
80941
  return;
80820
80942
  }
80821
80943
  }
80944
+ if (this.tryReconcilePurePtyCompletionForStall(observedStatus)) {
80945
+ this.meshStallEmittedForAnchor = true;
80946
+ return;
80947
+ }
80822
80948
  this.meshStallEmittedForAnchor = true;
80823
80949
  if (this.meshStallLastFiredAt >= 0 && now - this.meshStallLastFiredAt < _CliProviderInstance.MESH_WORKER_STALL_REFIRE_COOLDOWN_MS) {
80824
80950
  return;
@@ -80949,6 +81075,70 @@ ${body}
80949
81075
  });
80950
81076
  return true;
80951
81077
  }
81078
+ /**
81079
+ * KIMI-PURE-PTY-COMPLETION-EMIT (Fix 3): stall-path completion reconcile for the
81080
+ * PURE-PTY transcript class (kimi and kin — no native transcript, no provider
81081
+ * authority; see isPurePtyTranscriptProvider). Such a worker whose
81082
+ * generating_completed never emitted (the onTurnStarted idle→idle collapse Fix 1
81083
+ * fixes at the source) sits at a STATIC idle prompt: its PTY output stops the
81084
+ * instant the answer is rendered, so the status-agnostic no-progress watchdog
81085
+ * (checkMeshWorkerStall) reads the finished-but-quiet session as a stall and would
81086
+ * false-fire monitor:no_progress. The native-transcript reconcile
81087
+ * (sampleNativeTranscriptProgress) does NOT cover this class (no native source →
81088
+ * null sample), so the stall path needs its own guard.
81089
+ *
81090
+ * Called from checkMeshWorkerStall just before the fire. Returns true when the
81091
+ * session is a finished pure-PTY turn — idle, no pending response, and a PTY-parsed
81092
+ * in-turn final assistant summary — in which case it emits the missing
81093
+ * generating_completed (idempotent: a real/late emit writes the terminal ledger and
81094
+ * the coordinator's reconcile makes any duplicate a no-op) and the caller SUPPRESSES
81095
+ * the stall. Returns false for every other class/state (native-source provider, a
81096
+ * genuinely mid-turn or wedged worker with no final assistant), so a real stall still
81097
+ * fires unchanged.
81098
+ *
81099
+ * Evidence bar is identical to flushMeshCompletionBeforeCleanup: injected task's turn
81100
+ * genuinely started + an in-turn final assistant summary. Conservative by
81101
+ * construction — no summary ⇒ no proof of completion ⇒ return false and let the real
81102
+ * stall fire.
81103
+ */
81104
+ tryReconcilePurePtyCompletionForStall(observedStatus) {
81105
+ if (!isPurePtyTranscriptProvider(this.provider)) return false;
81106
+ if (observedStatus !== "idle") return false;
81107
+ if (this.hasAdapterPendingResponse()) return false;
81108
+ const taskId = this.completingTurnTaskId();
81109
+ if (this.lastEmittedCompletion && this.lastEmittedCompletion.taskId === (taskId ?? "")) {
81110
+ return false;
81111
+ }
81112
+ if (!this.injectedTaskHasStartedGenerating()) return false;
81113
+ const turnStartedAt = typeof this.adapter?.currentTurnStartedAt === "number" ? this.adapter.currentTurnStartedAt : this.meshTaskInjectedAt || void 0;
81114
+ let parsedMessages;
81115
+ try {
81116
+ parsedMessages = this.adapter?.getScriptParsedStatus?.()?.messages;
81117
+ } catch {
81118
+ parsedMessages = void 0;
81119
+ }
81120
+ let finalSummary;
81121
+ try {
81122
+ finalSummary = this.completionFinalSummary(parsedMessages, turnStartedAt);
81123
+ } catch {
81124
+ finalSummary = void 0;
81125
+ }
81126
+ if (!finalSummary) return false;
81127
+ 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.`);
81128
+ if (this.isMeshWorkerSession()) {
81129
+ traceMeshEventStage("fired", this.meshTraceCtx(), "stall_pure_pty_transcript_completion");
81130
+ }
81131
+ this.emitGeneratingCompleted({
81132
+ chatTitle: "",
81133
+ duration: void 0,
81134
+ timestamp: Date.now(),
81135
+ taskId,
81136
+ finalSummary,
81137
+ evidenceLevel: "transcript",
81138
+ completionDiagnostic: { source: "stall_pure_pty_transcript_completion" }
81139
+ });
81140
+ return true;
81141
+ }
80952
81142
  /**
80953
81143
  * AUTOAPPROVE-FLAP-RECUR (Fix A+B): how long a busy blip / modal scroll-out may
80954
81144
  * persist before the in-progress settle gate is torn down. For a delegated