@adhdev/daemon-core 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
@@ -27491,6 +27491,8 @@ var SpecDriver = class {
27491
27491
  * explicit wake-up there's nothing to trigger the busy → idle
27492
27492
  * downshift. */
27493
27493
  busyExpiryTimer = null;
27494
+ /** Set true while reevaluate() is invoked from busyExpiryTimer callback. */
27495
+ busyExpiryFired = false;
27494
27496
  /** Pending idle-commit timer. Armed when the evaluator first returns idle;
27495
27497
  * fires after idle_hold_ms if no non-idle reading has cancelled it. */
27496
27498
  idleHoldTimer = null;
@@ -27565,11 +27567,22 @@ var SpecDriver = class {
27565
27567
  }
27566
27568
  this.pendingIdleState = null;
27567
27569
  }
27568
- pushHistory(stateId, label) {
27570
+ pushHistory(stateId, label, meta) {
27569
27571
  const now = Date.now();
27570
27572
  const durationMs = this.prevStateAt > 0 ? now - this.prevStateAt : 0;
27571
27573
  this.prevStateAt = now;
27572
- this.stateHistory.push({ stateId, label, at: now, durationMs });
27574
+ this.stateHistory.push({
27575
+ stateId,
27576
+ label,
27577
+ at: now,
27578
+ durationMs,
27579
+ reason: meta?.reason ?? "eval_match",
27580
+ ...meta?.matchedStateId !== void 0 ? { matchedStateId: meta.matchedStateId } : {},
27581
+ ...meta?.matchedRules !== void 0 ? { matchedRules: meta.matchedRules } : {},
27582
+ ...meta?.debounceKind !== void 0 ? { debounceKind: meta.debounceKind } : {},
27583
+ ...meta?.idleHoldMs !== void 0 ? { idleHoldMs: meta.idleHoldMs } : {},
27584
+ ...meta?.busyHoldMs !== void 0 ? { busyHoldMs: meta.busyHoldMs } : {}
27585
+ });
27573
27586
  if (this.stateHistory.length > 50) this.stateHistory.shift();
27574
27587
  }
27575
27588
  getStateHistory() {
@@ -27653,7 +27666,9 @@ var SpecDriver = class {
27653
27666
  this.busyExpiryTimer = setTimeout(() => {
27654
27667
  this.busyExpiryTimer = null;
27655
27668
  LOG.debug("SpecDriver", `[${this.opts.specPath.split("/").slice(-3).join("/")}] busyExpiry fired holdMs=${holdMs}`);
27669
+ this.busyExpiryFired = true;
27656
27670
  this.reevaluate();
27671
+ this.busyExpiryFired = false;
27657
27672
  }, Math.max(holdMs + 50, 100));
27658
27673
  }
27659
27674
  reevaluate(forceEmit = false) {
@@ -27718,6 +27733,8 @@ var SpecDriver = class {
27718
27733
  if (isIdleState && idleHoldMs > 0 && this.currentStateId !== evState.id) {
27719
27734
  if (!this.idleHoldTimer) {
27720
27735
  this.pendingIdleState = evState;
27736
+ const capturedEv = ev;
27737
+ const capturedMatchedRules = extractMatchedRules(ev);
27721
27738
  this.idleHoldTimer = setTimeout(() => {
27722
27739
  this.idleHoldTimer = null;
27723
27740
  const committed = this.pendingIdleState;
@@ -27725,16 +27742,22 @@ var SpecDriver = class {
27725
27742
  if (!committed) return;
27726
27743
  LOG.debug("SpecDriver", `[${this.opts.specPath.split("/").slice(-3).join("/")}] idleHold committed after ${idleHoldMs}ms`);
27727
27744
  this.currentStateId = committed.id;
27728
- this.currentEval = ev;
27729
- this.pushHistory(committed.id, committed.label);
27745
+ this.currentEval = capturedEv;
27746
+ this.pushHistory(committed.id, committed.label, {
27747
+ reason: "idle_hold_committed",
27748
+ matchedStateId: capturedEv.state.id,
27749
+ matchedRules: capturedMatchedRules,
27750
+ debounceKind: "idle_hold",
27751
+ idleHoldMs
27752
+ });
27730
27753
  this.emit({
27731
27754
  kind: "state_changed",
27732
27755
  state: committed,
27733
27756
  modal: null,
27734
- controls: ev.controls.map((c) => ({ id: c.id, label: c.label, action_type: c.actionType }))
27757
+ controls: capturedEv.controls.map((c) => ({ id: c.id, label: c.label, action_type: c.actionType }))
27735
27758
  });
27736
27759
  this.armOrCancelDelegateTimers(committed.id);
27737
- if (this.opts.emitTrace) this.emit({ kind: "spec_trace", entries: ev.trace });
27760
+ if (this.opts.emitTrace) this.emit({ kind: "spec_trace", entries: capturedEv.trace });
27738
27761
  }, idleHoldMs);
27739
27762
  }
27740
27763
  this.currentEval = ev;
@@ -27761,7 +27784,31 @@ var SpecDriver = class {
27761
27784
  }
27762
27785
  if (changed) {
27763
27786
  this.currentStateId = evState.id;
27764
- this.pushHistory(evState.id, evState.label);
27787
+ const matchedRules = extractMatchedRules(ev);
27788
+ let transitionReason;
27789
+ let debounceKind;
27790
+ let transitionBusyHoldMs;
27791
+ if (forceEmit) {
27792
+ transitionReason = "forceEmit";
27793
+ debounceKind = "none";
27794
+ } else if (evState.id !== ev.state.id) {
27795
+ transitionReason = "completion_idle_after";
27796
+ debounceKind = "completion_idle_after";
27797
+ } else if (this.busyExpiryFired) {
27798
+ transitionReason = "busy_hold_expired";
27799
+ debounceKind = "busy_hold";
27800
+ transitionBusyHoldMs = busyHoldMs;
27801
+ } else {
27802
+ transitionReason = "eval_match";
27803
+ debounceKind = "none";
27804
+ }
27805
+ this.pushHistory(evState.id, evState.label, {
27806
+ reason: transitionReason,
27807
+ matchedStateId: ev.state.id,
27808
+ matchedRules,
27809
+ debounceKind,
27810
+ ...transitionBusyHoldMs !== void 0 ? { busyHoldMs: transitionBusyHoldMs } : {}
27811
+ });
27765
27812
  this.emit({
27766
27813
  kind: "state_changed",
27767
27814
  state: evState,
@@ -27924,6 +27971,10 @@ function guessExt(mime) {
27924
27971
  if (/webp/i.test(mime)) return ".webp";
27925
27972
  return ".bin";
27926
27973
  }
27974
+ function extractMatchedRules(ev) {
27975
+ if (!Array.isArray(ev.trace)) return [];
27976
+ return ev.trace.filter((t) => t.matched === true || t.kind === "state_match").map((t) => t.rule ?? t.stateId ?? t.id ?? String(t)).filter(Boolean);
27977
+ }
27927
27978
 
27928
27979
  // src/providers/spec/native-history-executor.ts
27929
27980
  var fs11 = __toESM(require("fs"));
@@ -30381,8 +30432,6 @@ var CliProviderInstance = class {
30381
30432
  clearTimeout(this.generatingDebounceTimer);
30382
30433
  this.generatingDebounceTimer = null;
30383
30434
  }
30384
- this.generatingDebouncePending = null;
30385
- this.generatingStartedAt = 0;
30386
30435
  let shortFinalSummary;
30387
30436
  let shortEvidenceSource = "unavailable";
30388
30437
  try {
@@ -30392,22 +30441,28 @@ var CliProviderInstance = class {
30392
30441
  shortFinalSummary = extractFinalSummaryFromMessages(evidence.messages);
30393
30442
  } catch {
30394
30443
  }
30395
- if ((this.provider.requiresFinalAssistantBeforeIdle === true || shortEvidenceSource === "external-native") && !shortFinalSummary) {
30396
- LOG.info("CLI", `[${this.type}] suppressed short completion without final assistant evidence`);
30397
- } else {
30398
- this.pushEvent({
30399
- event: "agent:generating_completed",
30400
- chatTitle,
30401
- duration: 0,
30402
- timestamp: now,
30403
- finalSummary: shortFinalSummary,
30404
- completionDiagnostic: {
30405
- reason: "short_generating_suppressed",
30406
- shortDurationMs,
30407
- finalAssistantEvidenceSource: shortEvidenceSource
30408
- }
30409
- });
30444
+ if (shortFinalSummary) {
30445
+ this.pushEvent({ event: "agent:generating_started", chatTitle, timestamp: now - shortDurationMs });
30410
30446
  }
30447
+ this.generatingDebouncePending = null;
30448
+ this.generatingStartedAt = 0;
30449
+ const missingEvidence = (this.provider.requiresFinalAssistantBeforeIdle === true || shortEvidenceSource === "external-native") && !shortFinalSummary;
30450
+ if (missingEvidence) {
30451
+ LOG.warn("CLI", `[${this.type}] short completion missing final assistant evidence (source=${shortEvidenceSource})`);
30452
+ }
30453
+ this.pushEvent({
30454
+ event: "agent:generating_completed",
30455
+ chatTitle,
30456
+ duration: 0,
30457
+ timestamp: now,
30458
+ finalSummary: shortFinalSummary,
30459
+ completionDiagnostic: {
30460
+ reason: "short_generating_suppressed",
30461
+ shortDurationMs,
30462
+ finalAssistantEvidenceSource: shortEvidenceSource,
30463
+ ...missingEvidence ? { blockReason: "missing_final_assistant" } : {}
30464
+ }
30465
+ });
30411
30466
  } else {
30412
30467
  this.completedDebouncePending = {
30413
30468
  chatTitle,