@adhdev/daemon-standalone 0.9.33 → 0.9.34

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
@@ -29560,13 +29560,14 @@ var require_dist2 = __commonJS({
29560
29560
  function hydrateCliParsedMessages(parsedMessages, options) {
29561
29561
  const { committedMessages, scope, lastOutputAt } = options;
29562
29562
  const referenceMessages = [...committedMessages];
29563
+ const referenceComparables = referenceMessages.map((message) => normalizeComparableMessageContent(message?.content || ""));
29563
29564
  const usedReferenceIndexes = /* @__PURE__ */ new Set();
29564
29565
  const now = options.now ?? Date.now();
29565
29566
  const findReferenceTimestamp = (role, content, parsedIndex) => {
29566
29567
  const normalizedContent = normalizeComparableMessageContent(content);
29567
29568
  if (!normalizedContent) return void 0;
29568
29569
  const sameIndex = referenceMessages[parsedIndex];
29569
- if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && normalizeComparableMessageContent(sameIndex.content) === normalizedContent && typeof sameIndex.timestamp === "number" && Number.isFinite(sameIndex.timestamp)) {
29570
+ if (sameIndex && !usedReferenceIndexes.has(parsedIndex) && sameIndex.role === role && referenceComparables[parsedIndex] === normalizedContent && typeof sameIndex.timestamp === "number" && Number.isFinite(sameIndex.timestamp)) {
29570
29571
  usedReferenceIndexes.add(parsedIndex);
29571
29572
  return sameIndex.timestamp;
29572
29573
  }
@@ -29574,7 +29575,7 @@ var require_dist2 = __commonJS({
29574
29575
  if (usedReferenceIndexes.has(i)) continue;
29575
29576
  const candidate = referenceMessages[i];
29576
29577
  if (!candidate || candidate.role !== role) continue;
29577
- const candidateContent = normalizeComparableMessageContent(candidate.content);
29578
+ const candidateContent = referenceComparables[i];
29578
29579
  if (!candidateContent) continue;
29579
29580
  const exactMatch = candidateContent === normalizedContent;
29580
29581
  const fuzzyMatch = candidateContent.includes(normalizedContent) || normalizedContent.includes(candidateContent);
@@ -30663,7 +30664,7 @@ var require_dist2 = __commonJS({
30663
30664
  return;
30664
30665
  }
30665
30666
  if (this.currentTurnScope && !lastParsedAssistant) {
30666
- LOG2.info(
30667
+ LOG2.debug(
30667
30668
  "CLI",
30668
30669
  `[${this.cliType}] Settled without assistant: prompt=${JSON.stringify(this.currentTurnScope.prompt).slice(0, 140)} responseBuffer=${JSON.stringify(summarizeCliTraceText(this.responseBuffer, 220)).slice(0, 260)} screen=${JSON.stringify(summarizeCliTraceText(screenText, 220)).slice(0, 260)} providerDir=${this.providerResolutionMeta.providerDir || "-"} scriptDir=${this.providerResolutionMeta.scriptDir || "-"}`
30669
30670
  );
@@ -31479,9 +31480,43 @@ var require_dist2 = __commonJS({
31479
31480
  }
31480
31481
  armResponseTimeout() {
31481
31482
  if (this.responseTimeout) clearTimeout(this.responseTimeout);
31483
+ const timeoutMs = this.timeouts.maxResponse;
31484
+ if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
31485
+ this.responseTimeout = null;
31486
+ return;
31487
+ }
31482
31488
  this.responseTimeout = setTimeout(() => {
31483
- if (this.isWaitingForResponse) this.finishResponse();
31484
- }, this.timeouts.maxResponse);
31489
+ this.responseTimeout = null;
31490
+ if (!this.isWaitingForResponse) return;
31491
+ const detectedStatusBeforeEval = this.runDetectStatus(this.recentOutputBuffer);
31492
+ this.recordTrace("response_timeout_check", {
31493
+ timeoutMs,
31494
+ detectedStatus: detectedStatusBeforeEval,
31495
+ currentStatus: this.currentStatus,
31496
+ isWaitingForResponse: this.isWaitingForResponse,
31497
+ hasActionableApproval: this.hasActionableApproval(),
31498
+ ...buildCliTraceParseSnapshot({
31499
+ accumulatedBuffer: this.accumulatedBuffer,
31500
+ accumulatedRawBuffer: this.accumulatedRawBuffer,
31501
+ responseBuffer: this.responseBuffer,
31502
+ partialResponse: this.responseBuffer,
31503
+ scope: this.currentTurnScope
31504
+ })
31505
+ });
31506
+ this.settledBuffer = this.recentOutputBuffer;
31507
+ this.evaluateSettled();
31508
+ if (this.isWaitingForResponse && !this.hasActionableApproval()) {
31509
+ const detectedStatusAfterEval = this.runDetectStatus(this.recentOutputBuffer);
31510
+ this.recordTrace("response_timeout_kept_open", {
31511
+ timeoutMs,
31512
+ detectedStatusBeforeEval,
31513
+ detectedStatusAfterEval,
31514
+ currentStatus: this.currentStatus,
31515
+ isWaitingForResponse: this.isWaitingForResponse
31516
+ });
31517
+ this.armResponseTimeout();
31518
+ }
31519
+ }, timeoutMs);
31485
31520
  }
31486
31521
  writeSubmitKeyForRetry(mode) {
31487
31522
  void this.writeToPty(this.sendKey).catch((error48) => {
@@ -41164,6 +41199,20 @@ ${effect.notification.body || ""}`.trim();
41164
41199
  getPresentationMode() {
41165
41200
  return this.presentationMode;
41166
41201
  }
41202
+ getHotChatSessionState() {
41203
+ const adapterStatus = this.adapter.getStatus();
41204
+ const autoApproveActive = adapterStatus.status === "waiting_approval" && this.shouldAutoApprove();
41205
+ const visibleStatus = autoApproveActive ? "generating" : adapterStatus.status;
41206
+ const runtime = this.adapter.getRuntimeMetadata();
41207
+ return {
41208
+ id: this.instanceId,
41209
+ status: visibleStatus,
41210
+ runtimeLifecycle: runtime?.lifecycle ?? null,
41211
+ runtimeSurfaceKind: runtime?.surfaceKind,
41212
+ runtimeRestoredFromStorage: runtime?.restoredFromStorage === true,
41213
+ runtimeRecoveryState: runtime?.recoveryState ?? null
41214
+ };
41215
+ }
41167
41216
  updateSettings(newSettings) {
41168
41217
  this.settings = { ...newSettings };
41169
41218
  this.adapter.updateRuntimeSettings?.(this.settings);
@@ -41319,6 +41368,15 @@ ${effect.notification.body || ""}`.trim();
41319
41368
  this.completedDebouncePending = { chatTitle, duration: duration3, timestamp: now };
41320
41369
  this.completedDebounceTimer = setTimeout(() => {
41321
41370
  if (this.completedDebouncePending) {
41371
+ const latestStatus = this.adapter.getStatus();
41372
+ const latestAutoApproveActive = latestStatus.status === "waiting_approval" && this.shouldAutoApprove();
41373
+ const latestVisibleStatus = latestAutoApproveActive ? "generating" : latestStatus.status;
41374
+ if (latestVisibleStatus !== "idle") {
41375
+ LOG2.info("CLI", `[${this.type}] cancelled pending completed (resumed ${latestVisibleStatus})`);
41376
+ this.completedDebouncePending = null;
41377
+ this.completedDebounceTimer = null;
41378
+ return;
41379
+ }
41322
41380
  LOG2.info("CLI", `[${this.type}] completed in ${this.completedDebouncePending.duration}s`);
41323
41381
  this.pushEvent({ event: "agent:generating_completed", ...this.completedDebouncePending });
41324
41382
  this.completedDebouncePending = null;
@@ -46297,6 +46355,51 @@ Run 'adhdev doctor' for detailed diagnostics.`
46297
46355
  return false;
46298
46356
  }
46299
46357
  }
46358
+ function getWindowsProcessCommandLine(pid) {
46359
+ const pidFilter = `ProcessId=${pid}`;
46360
+ try {
46361
+ const psOut = (0, import_child_process8.execFileSync)("powershell.exe", [
46362
+ "-NoProfile",
46363
+ "-NonInteractive",
46364
+ "-ExecutionPolicy",
46365
+ "Bypass",
46366
+ "-Command",
46367
+ `(Get-CimInstance Win32_Process -Filter "${pidFilter}").CommandLine`
46368
+ ], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
46369
+ if (psOut) return psOut;
46370
+ } catch {
46371
+ }
46372
+ try {
46373
+ const wmicOut = (0, import_child_process8.execFileSync)("wmic", [
46374
+ "process",
46375
+ "where",
46376
+ pidFilter,
46377
+ "get",
46378
+ "CommandLine"
46379
+ ], { encoding: "utf8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] }).trim();
46380
+ if (wmicOut) return wmicOut;
46381
+ } catch {
46382
+ }
46383
+ return null;
46384
+ }
46385
+ function getProcessCommandLine(pid) {
46386
+ if (!Number.isFinite(pid) || pid <= 0) return null;
46387
+ if (process.platform === "win32") return getWindowsProcessCommandLine(pid);
46388
+ try {
46389
+ const text = (0, import_child_process8.execFileSync)("ps", ["-o", "command=", "-p", String(pid)], {
46390
+ encoding: "utf8",
46391
+ timeout: 3e3,
46392
+ stdio: ["ignore", "pipe", "ignore"]
46393
+ }).trim();
46394
+ return text || null;
46395
+ } catch {
46396
+ return null;
46397
+ }
46398
+ }
46399
+ function isManagedSessionHostPid(pid) {
46400
+ const commandLine = getProcessCommandLine(pid);
46401
+ return !!commandLine && /session-host-daemon/i.test(commandLine);
46402
+ }
46300
46403
  async function waitForPidExit(pid, timeoutMs) {
46301
46404
  const start = Date.now();
46302
46405
  while (Date.now() - start < timeoutMs) {
@@ -46313,7 +46416,7 @@ Run 'adhdev doctor' for detailed diagnostics.`
46313
46416
  try {
46314
46417
  if (fs8.existsSync(pidFile)) {
46315
46418
  const pid = Number.parseInt(fs8.readFileSync(pidFile, "utf8").trim(), 10);
46316
- if (Number.isFinite(pid)) {
46419
+ if (Number.isFinite(pid) && pid !== process.pid && isManagedSessionHostPid(pid)) {
46317
46420
  killPid2(pid);
46318
46421
  }
46319
46422
  }
@@ -46324,18 +46427,6 @@ Run 'adhdev doctor' for detailed diagnostics.`
46324
46427
  } catch {
46325
46428
  }
46326
46429
  }
46327
- if (process.platform !== "win32") {
46328
- try {
46329
- const raw = (0, import_child_process8.execFileSync)("pgrep", ["-f", "session-host-daemon"], { encoding: "utf8" }).trim();
46330
- for (const line of raw.split("\n")) {
46331
- const pid = Number.parseInt(line.trim(), 10);
46332
- if (Number.isFinite(pid)) {
46333
- killPid2(pid);
46334
- }
46335
- }
46336
- } catch {
46337
- }
46338
- }
46339
46430
  }
46340
46431
  function removeDaemonPidFile() {
46341
46432
  const pidFile = path16.join(os17.homedir(), ".adhdev", "daemon.pid");
@@ -48548,6 +48639,20 @@ Run 'adhdev doctor' for detailed diagnostics.`
48548
48639
  }
48549
48640
  }
48550
48641
  init_logger();
48642
+ function projectHotChatSessionStatesFromProviderState(state) {
48643
+ const project = (item) => ({
48644
+ id: item.instanceId,
48645
+ status: item.activeChat?.status || item.status,
48646
+ runtimeLifecycle: item.runtime?.lifecycle ?? null,
48647
+ runtimeSurfaceKind: item.runtime?.surfaceKind,
48648
+ runtimeRestoredFromStorage: item.runtime?.restoredFromStorage === true,
48649
+ runtimeRecoveryState: item.runtime?.recoveryState ?? null
48650
+ });
48651
+ if (state.category === "ide") {
48652
+ return [project(state), ...state.extensions.map(project)];
48653
+ }
48654
+ return [project(state)];
48655
+ }
48551
48656
  var ProviderInstanceManager = class {
48552
48657
  instances = /* @__PURE__ */ new Map();
48553
48658
  tickTimer = null;
@@ -48643,6 +48748,27 @@ Run 'adhdev doctor' for detailed diagnostics.`
48643
48748
  }
48644
48749
  return states;
48645
48750
  }
48751
+ collectHotChatSessionStates() {
48752
+ const sessions = [];
48753
+ for (const [id, instance] of this.instances) {
48754
+ try {
48755
+ const projected = instance.getHotChatSessionState?.();
48756
+ if (Array.isArray(projected)) {
48757
+ sessions.push(...projected.filter((session) => !!session?.id));
48758
+ continue;
48759
+ }
48760
+ if (projected?.id) {
48761
+ sessions.push(projected);
48762
+ continue;
48763
+ }
48764
+ const state = instance.getState();
48765
+ sessions.push(...projectHotChatSessionStatesFromProviderState(state));
48766
+ } catch (e) {
48767
+ LOG2.warn("InstanceMgr", `[InstanceManager] Failed to collect hot chat metadata from ${id}: ${e.message}`);
48768
+ }
48769
+ }
48770
+ return sessions;
48771
+ }
48646
48772
  /**
48647
48773
  * Per-category status collect
48648
48774
  */