@adhdev/daemon-standalone 0.9.82-rc.204 → 0.9.82-rc.205

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
@@ -62149,6 +62149,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62149
62149
  * explicit wake-up there's nothing to trigger the busy → idle
62150
62150
  * downshift. */
62151
62151
  busyExpiryTimer = null;
62152
+ /** Set true while reevaluate() is invoked from busyExpiryTimer callback. */
62153
+ busyExpiryFired = false;
62152
62154
  /** Pending idle-commit timer. Armed when the evaluator first returns idle;
62153
62155
  * fires after idle_hold_ms if no non-idle reading has cancelled it. */
62154
62156
  idleHoldTimer = null;
@@ -62223,11 +62225,22 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62223
62225
  }
62224
62226
  this.pendingIdleState = null;
62225
62227
  }
62226
- pushHistory(stateId, label) {
62228
+ pushHistory(stateId, label, meta3) {
62227
62229
  const now = Date.now();
62228
62230
  const durationMs = this.prevStateAt > 0 ? now - this.prevStateAt : 0;
62229
62231
  this.prevStateAt = now;
62230
- this.stateHistory.push({ stateId, label, at: now, durationMs });
62232
+ this.stateHistory.push({
62233
+ stateId,
62234
+ label,
62235
+ at: now,
62236
+ durationMs,
62237
+ reason: meta3?.reason ?? "eval_match",
62238
+ ...meta3?.matchedStateId !== void 0 ? { matchedStateId: meta3.matchedStateId } : {},
62239
+ ...meta3?.matchedRules !== void 0 ? { matchedRules: meta3.matchedRules } : {},
62240
+ ...meta3?.debounceKind !== void 0 ? { debounceKind: meta3.debounceKind } : {},
62241
+ ...meta3?.idleHoldMs !== void 0 ? { idleHoldMs: meta3.idleHoldMs } : {},
62242
+ ...meta3?.busyHoldMs !== void 0 ? { busyHoldMs: meta3.busyHoldMs } : {}
62243
+ });
62231
62244
  if (this.stateHistory.length > 50) this.stateHistory.shift();
62232
62245
  }
62233
62246
  getStateHistory() {
@@ -62311,7 +62324,9 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62311
62324
  this.busyExpiryTimer = setTimeout(() => {
62312
62325
  this.busyExpiryTimer = null;
62313
62326
  LOG2.debug("SpecDriver", `[${this.opts.specPath.split("/").slice(-3).join("/")}] busyExpiry fired holdMs=${holdMs}`);
62327
+ this.busyExpiryFired = true;
62314
62328
  this.reevaluate();
62329
+ this.busyExpiryFired = false;
62315
62330
  }, Math.max(holdMs + 50, 100));
62316
62331
  }
62317
62332
  reevaluate(forceEmit = false) {
@@ -62376,6 +62391,8 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62376
62391
  if (isIdleState && idleHoldMs > 0 && this.currentStateId !== evState.id) {
62377
62392
  if (!this.idleHoldTimer) {
62378
62393
  this.pendingIdleState = evState;
62394
+ const capturedEv = ev;
62395
+ const capturedMatchedRules = extractMatchedRules(ev);
62379
62396
  this.idleHoldTimer = setTimeout(() => {
62380
62397
  this.idleHoldTimer = null;
62381
62398
  const committed = this.pendingIdleState;
@@ -62383,16 +62400,22 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62383
62400
  if (!committed) return;
62384
62401
  LOG2.debug("SpecDriver", `[${this.opts.specPath.split("/").slice(-3).join("/")}] idleHold committed after ${idleHoldMs}ms`);
62385
62402
  this.currentStateId = committed.id;
62386
- this.currentEval = ev;
62387
- this.pushHistory(committed.id, committed.label);
62403
+ this.currentEval = capturedEv;
62404
+ this.pushHistory(committed.id, committed.label, {
62405
+ reason: "idle_hold_committed",
62406
+ matchedStateId: capturedEv.state.id,
62407
+ matchedRules: capturedMatchedRules,
62408
+ debounceKind: "idle_hold",
62409
+ idleHoldMs
62410
+ });
62388
62411
  this.emit({
62389
62412
  kind: "state_changed",
62390
62413
  state: committed,
62391
62414
  modal: null,
62392
- controls: ev.controls.map((c) => ({ id: c.id, label: c.label, action_type: c.actionType }))
62415
+ controls: capturedEv.controls.map((c) => ({ id: c.id, label: c.label, action_type: c.actionType }))
62393
62416
  });
62394
62417
  this.armOrCancelDelegateTimers(committed.id);
62395
- if (this.opts.emitTrace) this.emit({ kind: "spec_trace", entries: ev.trace });
62418
+ if (this.opts.emitTrace) this.emit({ kind: "spec_trace", entries: capturedEv.trace });
62396
62419
  }, idleHoldMs);
62397
62420
  }
62398
62421
  this.currentEval = ev;
@@ -62419,7 +62442,31 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62419
62442
  }
62420
62443
  if (changed) {
62421
62444
  this.currentStateId = evState.id;
62422
- this.pushHistory(evState.id, evState.label);
62445
+ const matchedRules = extractMatchedRules(ev);
62446
+ let transitionReason;
62447
+ let debounceKind;
62448
+ let transitionBusyHoldMs;
62449
+ if (forceEmit) {
62450
+ transitionReason = "forceEmit";
62451
+ debounceKind = "none";
62452
+ } else if (evState.id !== ev.state.id) {
62453
+ transitionReason = "completion_idle_after";
62454
+ debounceKind = "completion_idle_after";
62455
+ } else if (this.busyExpiryFired) {
62456
+ transitionReason = "busy_hold_expired";
62457
+ debounceKind = "busy_hold";
62458
+ transitionBusyHoldMs = busyHoldMs;
62459
+ } else {
62460
+ transitionReason = "eval_match";
62461
+ debounceKind = "none";
62462
+ }
62463
+ this.pushHistory(evState.id, evState.label, {
62464
+ reason: transitionReason,
62465
+ matchedStateId: ev.state.id,
62466
+ matchedRules,
62467
+ debounceKind,
62468
+ ...transitionBusyHoldMs !== void 0 ? { busyHoldMs: transitionBusyHoldMs } : {}
62469
+ });
62423
62470
  this.emit({
62424
62471
  kind: "state_changed",
62425
62472
  state: evState,
@@ -62582,6 +62629,10 @@ ${formatManifestValidationIssues2(validation.issues)}`,
62582
62629
  if (/webp/i.test(mime)) return ".webp";
62583
62630
  return ".bin";
62584
62631
  }
62632
+ function extractMatchedRules(ev) {
62633
+ if (!Array.isArray(ev.trace)) return [];
62634
+ return ev.trace.filter((t) => t.matched === true || t.kind === "state_match").map((t) => t.rule ?? t.stateId ?? t.id ?? String(t)).filter(Boolean);
62635
+ }
62585
62636
  var fs11 = __toESM2(require("fs"));
62586
62637
  var os16 = __toESM2(require("os"));
62587
62638
  var path20 = __toESM2(require("path"));
@@ -65027,8 +65078,6 @@ ${formatManifestValidationIssues2(validation.issues)}`,
65027
65078
  clearTimeout(this.generatingDebounceTimer);
65028
65079
  this.generatingDebounceTimer = null;
65029
65080
  }
65030
- this.generatingDebouncePending = null;
65031
- this.generatingStartedAt = 0;
65032
65081
  let shortFinalSummary;
65033
65082
  let shortEvidenceSource = "unavailable";
65034
65083
  try {
@@ -65038,22 +65087,28 @@ ${formatManifestValidationIssues2(validation.issues)}`,
65038
65087
  shortFinalSummary = extractFinalSummaryFromMessages(evidence.messages);
65039
65088
  } catch {
65040
65089
  }
65041
- if ((this.provider.requiresFinalAssistantBeforeIdle === true || shortEvidenceSource === "external-native") && !shortFinalSummary) {
65042
- LOG2.info("CLI", `[${this.type}] suppressed short completion without final assistant evidence`);
65043
- } else {
65044
- this.pushEvent({
65045
- event: "agent:generating_completed",
65046
- chatTitle,
65047
- duration: 0,
65048
- timestamp: now,
65049
- finalSummary: shortFinalSummary,
65050
- completionDiagnostic: {
65051
- reason: "short_generating_suppressed",
65052
- shortDurationMs,
65053
- finalAssistantEvidenceSource: shortEvidenceSource
65054
- }
65055
- });
65090
+ if (shortFinalSummary) {
65091
+ this.pushEvent({ event: "agent:generating_started", chatTitle, timestamp: now - shortDurationMs });
65056
65092
  }
65093
+ this.generatingDebouncePending = null;
65094
+ this.generatingStartedAt = 0;
65095
+ const missingEvidence = (this.provider.requiresFinalAssistantBeforeIdle === true || shortEvidenceSource === "external-native") && !shortFinalSummary;
65096
+ if (missingEvidence) {
65097
+ LOG2.warn("CLI", `[${this.type}] short completion missing final assistant evidence (source=${shortEvidenceSource})`);
65098
+ }
65099
+ this.pushEvent({
65100
+ event: "agent:generating_completed",
65101
+ chatTitle,
65102
+ duration: 0,
65103
+ timestamp: now,
65104
+ finalSummary: shortFinalSummary,
65105
+ completionDiagnostic: {
65106
+ reason: "short_generating_suppressed",
65107
+ shortDurationMs,
65108
+ finalAssistantEvidenceSource: shortEvidenceSource,
65109
+ ...missingEvidence ? { blockReason: "missing_final_assistant" } : {}
65110
+ }
65111
+ });
65057
65112
  } else {
65058
65113
  this.completedDebouncePending = {
65059
65114
  chatTitle,