@adhdev/daemon-core 0.8.33 → 0.8.35

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.
Files changed (89) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +127 -102
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +127 -102
  5. package/dist/index.mjs.map +1 -1
  6. package/dist/shared-types.d.ts +38 -0
  7. package/dist/status/reporter.d.ts +3 -0
  8. package/node_modules/@adhdev/session-host-core/package.json +1 -1
  9. package/package.json +1 -1
  10. package/src/agent-stream/forward.d.ts +8 -0
  11. package/src/agent-stream/index.d.ts +6 -0
  12. package/src/agent-stream/manager.d.ts +60 -0
  13. package/src/agent-stream/poller.d.ts +41 -0
  14. package/src/agent-stream/provider-adapter.d.ts +36 -0
  15. package/src/agent-stream/types.d.ts +68 -0
  16. package/src/boot/daemon-lifecycle.d.ts +100 -0
  17. package/src/cdp/devtools.d.ts +51 -0
  18. package/src/cdp/initializer.d.ts +50 -0
  19. package/src/cdp/manager.d.ts +147 -0
  20. package/src/cdp/scanner.d.ts +58 -0
  21. package/src/cdp/setup.d.ts +58 -0
  22. package/src/cli-adapter-types.d.ts +57 -0
  23. package/src/cli-adapters/provider-cli-adapter.d.ts +177 -0
  24. package/src/cli-adapters/provider-cli-adapter.ts +115 -91
  25. package/src/cli-adapters/provider-cli-config.d.ts +30 -0
  26. package/src/cli-adapters/provider-cli-parse.d.ts +42 -0
  27. package/src/cli-adapters/provider-cli-runtime.d.ts +29 -0
  28. package/src/cli-adapters/provider-cli-shared.d.ts +158 -0
  29. package/src/cli-adapters/pty-transport.d.ts +48 -0
  30. package/src/cli-adapters/session-host-transport.d.ts +20 -0
  31. package/src/cli-adapters/spawn-env.d.ts +8 -0
  32. package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +16 -0
  33. package/src/cli-adapters/terminal-backends/types.d.ts +18 -0
  34. package/src/cli-adapters/terminal-backends/xterm-backend.d.ts +17 -0
  35. package/src/cli-adapters/terminal-screen.d.ts +33 -0
  36. package/src/commands/cdp-commands.d.ts +15 -0
  37. package/src/commands/chat-commands.d.ts +15 -0
  38. package/src/commands/cli-manager.d.ts +94 -0
  39. package/src/commands/handler.d.ts +103 -0
  40. package/src/commands/router.d.ts +98 -0
  41. package/src/commands/stream-commands.d.ts +14 -0
  42. package/src/commands/upgrade-helper.d.ts +10 -0
  43. package/src/commands/workspace-commands.d.ts +11 -0
  44. package/src/config/chat-history.d.ts +99 -0
  45. package/src/config/config.d.ts +14 -0
  46. package/src/config/recent-activity.d.ts +29 -0
  47. package/src/config/saved-sessions.d.ts +22 -0
  48. package/src/config/state-store.d.ts +32 -0
  49. package/src/config/workspaces.d.ts +0 -1
  50. package/src/daemon/dev-auto-implement.d.ts +43 -0
  51. package/src/daemon/dev-cdp-handlers.d.ts +22 -0
  52. package/src/daemon/dev-cli-debug.d.ts +106 -0
  53. package/src/daemon/dev-server-types.d.ts +43 -0
  54. package/src/daemon/dev-server.d.ts +140 -0
  55. package/src/daemon/scaffold-template.d.ts +32 -0
  56. package/src/daemon-core.d.ts +36 -0
  57. package/src/detection/cli-detector.d.ts +31 -0
  58. package/src/detection/ide-detector.d.ts +35 -0
  59. package/src/index.d.ts +83 -0
  60. package/src/index.ts +2 -0
  61. package/src/installer.d.ts +50 -0
  62. package/src/ipc-protocol.d.ts +111 -0
  63. package/src/launch.d.ts +46 -0
  64. package/src/logging/command-log.d.ts +31 -0
  65. package/src/logging/logger.d.ts +89 -0
  66. package/src/providers/acp-provider-instance.d.ts +102 -0
  67. package/src/providers/approval-utils.d.ts +7 -0
  68. package/src/providers/cli-provider-instance.d.ts +86 -0
  69. package/src/providers/contracts.d.ts +193 -1
  70. package/src/providers/control-effects.d.ts +4 -0
  71. package/src/providers/extension-provider-instance.d.ts +61 -0
  72. package/src/providers/ide-provider-instance.d.ts +70 -0
  73. package/src/providers/provider-instance-manager.d.ts +84 -0
  74. package/src/providers/provider-instance.d.ts +7 -1
  75. package/src/providers/provider-loader.d.ts +299 -0
  76. package/src/providers/status-monitor.d.ts +48 -0
  77. package/src/providers/version-archive.d.ts +52 -0
  78. package/src/session-host/runtime-support.d.ts +8 -0
  79. package/src/sessions/reconcile.d.ts +22 -0
  80. package/src/sessions/registry.d.ts +24 -0
  81. package/src/shared-types-extra.d.ts +29 -0
  82. package/src/shared-types.d.ts +79 -22
  83. package/src/shared-types.ts +40 -0
  84. package/src/status/builders.d.ts +33 -0
  85. package/src/status/reporter.d.ts +69 -0
  86. package/src/status/reporter.ts +16 -13
  87. package/src/status/snapshot.d.ts +58 -0
  88. package/src/system/host-memory.d.ts +19 -0
  89. package/src/types.d.ts +3 -7
package/dist/index.mjs CHANGED
@@ -2485,8 +2485,6 @@ ${data.message || ""}`.trim();
2485
2485
  if (blockingModal || this.currentStatus === "waiting_approval") {
2486
2486
  throw new Error(`${this.cliName} is awaiting confirmation before it can accept a prompt`);
2487
2487
  }
2488
- this.committedMessages.push({ role: "user", content: text, timestamp: Date.now() });
2489
- this.syncMessageViews();
2490
2488
  this.isWaitingForResponse = true;
2491
2489
  this.responseBuffer = "";
2492
2490
  this.finishRetryCount = 0;
@@ -2518,6 +2516,13 @@ ${data.message || ""}`.trim();
2518
2516
  const submitDelayMs = this.sendDelayMs + Math.min(2e3, Math.max(0, estimatedLines - 1) * 350);
2519
2517
  const maxEchoWaitMs = submitDelayMs + Math.max(1500, Math.min(5e3, estimatedLines * 500));
2520
2518
  const retryDelayMs = Math.max(350, Math.min(1500, Math.max(this.sendDelayMs, submitDelayMs)));
2519
+ let didCommitUserTurn = false;
2520
+ const commitUserTurn = () => {
2521
+ if (didCommitUserTurn) return;
2522
+ didCommitUserTurn = true;
2523
+ this.committedMessages.push({ role: "user", content: text, timestamp: Date.now() });
2524
+ this.syncMessageViews();
2525
+ };
2521
2526
  if (this.settleTimer) {
2522
2527
  clearTimeout(this.settleTimer);
2523
2528
  this.settleTimer = null;
@@ -2530,109 +2535,128 @@ ${data.message || ""}`.trim();
2530
2535
  if (this.isWaitingForResponse) this.finishResponse();
2531
2536
  }, this.timeouts.maxResponse);
2532
2537
  };
2533
- const submit = () => {
2534
- if (!this.ptyProcess) return;
2535
- this.submitPendingUntil = 0;
2536
- this.recordTrace("submit_write", {
2537
- mode: "submit_key",
2538
- sendKey: this.sendKey,
2539
- screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
2540
- });
2541
- this.ptyProcess.write(this.sendKey);
2542
- const retrySubmitIfStuck = (attempt) => {
2543
- this.submitRetryTimer = null;
2544
- if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
2545
- if (this.currentStatus === "waiting_approval") return;
2546
- if ((this.responseBuffer || "").trim()) return;
2538
+ await new Promise((resolve12) => {
2539
+ let resolved = false;
2540
+ const resolveOnce = () => {
2541
+ if (resolved) return;
2542
+ resolved = true;
2543
+ resolve12();
2544
+ };
2545
+ const submit = () => {
2546
+ if (!this.ptyProcess) {
2547
+ resolveOnce();
2548
+ return;
2549
+ }
2550
+ commitUserTurn();
2551
+ this.submitPendingUntil = 0;
2547
2552
  const screenText = this.terminalScreen.getText();
2548
- if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
2549
- if (/Esc to interrupt|Do you want to proceed|This command requires approval|Allow Codex to|Approve and run now|Always approve this session|Running…|Running\.\.\./i.test(screenText)) return;
2550
- this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
2551
- LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt ${attempt})`);
2552
2553
  this.recordTrace("submit_write", {
2553
- mode: "submit_retry",
2554
- attempt,
2554
+ mode: "submit_key",
2555
2555
  sendKey: this.sendKey,
2556
2556
  screenText: summarizeCliTraceText(screenText, 500)
2557
2557
  });
2558
2558
  this.ptyProcess.write(this.sendKey);
2559
- if (attempt >= 3) {
2560
- this.submitRetryUsed = true;
2561
- return;
2562
- }
2563
- this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
2559
+ const retrySubmitIfStuck = (attempt) => {
2560
+ this.submitRetryTimer = null;
2561
+ if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
2562
+ if (this.currentStatus === "waiting_approval") return;
2563
+ if ((this.responseBuffer || "").trim()) return;
2564
+ const screenText2 = this.terminalScreen.getText();
2565
+ if (!promptLikelyVisible(screenText2, normalizedPromptSnippet)) return;
2566
+ if (/Esc to interrupt|Do you want to proceed|This command requires approval|Allow Codex to|Approve and run now|Always approve this session|Running…|Running\.\.\./i.test(screenText2)) return;
2567
+ this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
2568
+ LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt ${attempt})`);
2569
+ this.recordTrace("submit_write", {
2570
+ mode: "submit_retry",
2571
+ attempt,
2572
+ sendKey: this.sendKey,
2573
+ screenText: summarizeCliTraceText(screenText2, 500)
2574
+ });
2575
+ this.ptyProcess.write(this.sendKey);
2576
+ if (attempt >= 3) {
2577
+ this.submitRetryUsed = true;
2578
+ return;
2579
+ }
2580
+ this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
2581
+ };
2582
+ this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
2583
+ startResponseTimeout();
2584
+ resolveOnce();
2564
2585
  };
2565
- this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
2566
- startResponseTimeout();
2567
- };
2568
- if (this.submitStrategy === "immediate") {
2569
- this.submitPendingUntil = 0;
2586
+ if (this.submitStrategy === "immediate") {
2587
+ commitUserTurn();
2588
+ this.submitPendingUntil = 0;
2589
+ this.recordTrace("submit_write", {
2590
+ mode: "immediate",
2591
+ text: summarizeCliTraceText(text, 500),
2592
+ sendKey: this.sendKey,
2593
+ screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
2594
+ });
2595
+ this.ptyProcess.write(text + this.sendKey);
2596
+ this.submitRetryTimer = setTimeout(() => {
2597
+ this.submitRetryTimer = null;
2598
+ if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
2599
+ if (this.currentStatus === "waiting_approval") return;
2600
+ if ((this.responseBuffer || "").trim()) return;
2601
+ const screenText = this.terminalScreen.getText();
2602
+ if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
2603
+ LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
2604
+ this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
2605
+ this.recordTrace("submit_write", {
2606
+ mode: "immediate_retry",
2607
+ attempt: 1,
2608
+ sendKey: this.sendKey,
2609
+ screenText: summarizeCliTraceText(screenText, 500)
2610
+ });
2611
+ this.ptyProcess.write(this.sendKey);
2612
+ this.submitRetryUsed = true;
2613
+ }, retryDelayMs);
2614
+ startResponseTimeout();
2615
+ resolveOnce();
2616
+ return;
2617
+ }
2618
+ if (submitDelayMs > 0) {
2619
+ this.submitPendingUntil = Date.now() + submitDelayMs;
2620
+ }
2621
+ this.ptyProcess.write(text);
2570
2622
  this.recordTrace("submit_write", {
2571
- mode: "immediate",
2623
+ mode: "type_then_submit",
2572
2624
  text: summarizeCliTraceText(text, 500),
2573
2625
  sendKey: this.sendKey,
2574
2626
  screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
2575
2627
  });
2576
- this.ptyProcess.write(text + this.sendKey);
2577
- this.submitRetryTimer = setTimeout(() => {
2578
- this.submitRetryTimer = null;
2579
- if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
2580
- if (this.currentStatus === "waiting_approval") return;
2581
- if ((this.responseBuffer || "").trim()) return;
2628
+ const submitStartedAt = Date.now();
2629
+ let lastNormalizedScreen = "";
2630
+ let lastScreenChangeAt = submitStartedAt;
2631
+ const waitForEchoAndSubmit = () => {
2632
+ if (!this.ptyProcess) {
2633
+ resolveOnce();
2634
+ return;
2635
+ }
2636
+ const now = Date.now();
2637
+ const elapsed = now - submitStartedAt;
2582
2638
  const screenText = this.terminalScreen.getText();
2583
- if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
2584
- LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
2585
- this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
2586
- this.recordTrace("submit_write", {
2587
- mode: "immediate_retry",
2588
- attempt: 1,
2589
- sendKey: this.sendKey,
2590
- screenText: summarizeCliTraceText(screenText, 500)
2591
- });
2592
- this.ptyProcess.write(this.sendKey);
2593
- this.submitRetryUsed = true;
2594
- }, retryDelayMs);
2595
- startResponseTimeout();
2596
- return;
2597
- }
2598
- if (submitDelayMs > 0) {
2599
- this.submitPendingUntil = Date.now() + submitDelayMs;
2600
- }
2601
- this.ptyProcess.write(text);
2602
- this.recordTrace("submit_write", {
2603
- mode: "type_then_submit",
2604
- text: summarizeCliTraceText(text, 500),
2605
- sendKey: this.sendKey,
2606
- screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
2607
- });
2608
- const submitStartedAt = Date.now();
2609
- let lastNormalizedScreen = "";
2610
- let lastScreenChangeAt = submitStartedAt;
2611
- const waitForEchoAndSubmit = () => {
2612
- if (!this.ptyProcess) return;
2613
- const now = Date.now();
2614
- const elapsed = now - submitStartedAt;
2615
- const screenText = this.terminalScreen.getText();
2616
- const normalizedScreen = normalizePromptText(screenText);
2617
- if (normalizedScreen !== lastNormalizedScreen) {
2618
- lastNormalizedScreen = normalizedScreen;
2619
- lastScreenChangeAt = now;
2620
- }
2621
- const echoVisible = !normalizedPromptSnippet || promptLikelyVisible(screenText, normalizedPromptSnippet);
2622
- if (echoVisible) {
2623
- const screenSettled = now - lastScreenChangeAt >= 500;
2624
- if (elapsed >= submitDelayMs && screenSettled) {
2639
+ const normalizedScreen = normalizePromptText(screenText);
2640
+ if (normalizedScreen !== lastNormalizedScreen) {
2641
+ lastNormalizedScreen = normalizedScreen;
2642
+ lastScreenChangeAt = now;
2643
+ }
2644
+ const echoVisible = !normalizedPromptSnippet || promptLikelyVisible(screenText, normalizedPromptSnippet);
2645
+ if (echoVisible) {
2646
+ const screenSettled = now - lastScreenChangeAt >= 500;
2647
+ if (elapsed >= submitDelayMs && screenSettled) {
2648
+ submit();
2649
+ return;
2650
+ }
2651
+ }
2652
+ if (elapsed >= maxEchoWaitMs) {
2625
2653
  submit();
2626
2654
  return;
2627
2655
  }
2628
- }
2629
- if (elapsed >= maxEchoWaitMs) {
2630
- submit();
2631
- return;
2632
- }
2633
- setTimeout(waitForEchoAndSubmit, 50);
2634
- };
2635
- waitForEchoAndSubmit();
2656
+ setTimeout(waitForEchoAndSubmit, 50);
2657
+ };
2658
+ waitForEchoAndSubmit();
2659
+ });
2636
2660
  }
2637
2661
  getPartialResponse() {
2638
2662
  if (!this.isWaitingForResponse) return "";
@@ -14336,6 +14360,7 @@ var DaemonStatusReporter = class {
14336
14360
  lastStatusSentAt = 0;
14337
14361
  statusPendingThrottle = false;
14338
14362
  lastP2PStatusHash = "";
14363
+ lastServerStatusHash = "";
14339
14364
  lastStatusSummary = "";
14340
14365
  statusTimer = null;
14341
14366
  p2pTimer = null;
@@ -14346,11 +14371,11 @@ var DaemonStatusReporter = class {
14346
14371
  // ─── Lifecycle ───────────────────────────────────
14347
14372
  startReporting() {
14348
14373
  setTimeout(() => {
14349
- this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
14374
+ this.sendUnifiedStatusReport({ forceServer: true, reason: "initial" }).catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
14350
14375
  }, 2e3);
14351
14376
  const scheduleServerReport = () => {
14352
14377
  this.statusTimer = setTimeout(() => {
14353
- this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
14378
+ this.sendUnifiedStatusReport({ forceServer: true, reason: "periodic" }).catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
14354
14379
  scheduleServerReport();
14355
14380
  }, 3e4);
14356
14381
  };
@@ -14497,24 +14522,24 @@ var DaemonStatusReporter = class {
14497
14522
  cdpConnected: session.cdpConnected,
14498
14523
  currentModel: session.currentModel,
14499
14524
  currentPlan: session.currentPlan,
14500
- currentAutoApprove: session.currentAutoApprove,
14501
- lastUpdated: session.lastUpdated,
14502
- unread: session.unread,
14503
- lastSeenAt: session.lastSeenAt,
14504
- inboxBucket: session.inboxBucket,
14505
- surfaceHidden: session.surfaceHidden,
14506
- controlValues: session.controlValues,
14507
- providerControls: session.providerControls,
14508
- acpConfigOptions: session.acpConfigOptions,
14509
- acpModes: session.acpModes
14525
+ currentAutoApprove: session.currentAutoApprove
14510
14526
  })),
14511
14527
  p2p: payload.p2p,
14512
14528
  timestamp: now,
14513
14529
  detectedIdes: payload.detectedIdes,
14514
14530
  availableProviders: payload.availableProviders
14515
14531
  };
14532
+ const wsHash = this.simpleHash(JSON.stringify({
14533
+ ...wsPayload,
14534
+ timestamp: void 0
14535
+ }));
14536
+ if (!opts?.forceServer && wsHash === this.lastServerStatusHash) {
14537
+ LOG.debug("Server", `skip duplicate status_report${opts?.reason ? ` (${opts.reason})` : ""}`);
14538
+ return;
14539
+ }
14540
+ this.lastServerStatusHash = wsHash;
14516
14541
  serverConn.sendMessage("status_report", wsPayload);
14517
- LOG.debug("Server", `sent status_report (${JSON.stringify(wsPayload).length} bytes)`);
14542
+ LOG.debug("Server", `sent status_report (${JSON.stringify(wsPayload).length} bytes)${opts?.reason ? ` [${opts.reason}]` : ""}`);
14518
14543
  }
14519
14544
  // ─── P2P ─────────────────────────────────────────
14520
14545
  sendP2PPayload(payload) {