@adhdev/daemon-core 0.8.34 → 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.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Core logic for daemon: CDP, Provider, IDE detection, CLI/ACP adapters and more.
5
5
  */
6
6
  export type { ChatMessage, ExtensionInfo, CommandResult as CoreCommandResult, ProviderConfig, DaemonEvent, StatusResponse, SystemInfo, DetectedIde, ProviderInfo, AgentEntry, } from './types.js';
7
- export type { SessionEntry, SessionTransport, SessionKind, SessionCapability, AgentSessionStream, AvailableProviderInfo, AcpConfigOption, AcpMode, ProviderControlSchema, StatusReportPayload, MachineInfo, DetectedIdeInfo, WorkspaceEntry, ProviderStatus, ProviderErrorReason, ActiveChatData, IdeProviderState, CliProviderState, AcpProviderState, ExtensionProviderState, } from './shared-types.js';
7
+ export type { SessionEntry, CompactSessionEntry, CompactDaemonEntry, SessionTransport, SessionKind, SessionCapability, AgentSessionStream, AvailableProviderInfo, AcpConfigOption, AcpMode, ProviderControlSchema, StatusReportPayload, MachineInfo, DetectedIdeInfo, WorkspaceEntry, ProviderStatus, ProviderErrorReason, ActiveChatData, IdeProviderState, CliProviderState, AcpProviderState, ExtensionProviderState, } from './shared-types.js';
8
8
  import type { RuntimeWriteOwner as _RuntimeWriteOwner } from './shared-types-extra.js';
9
9
  import type { RuntimeAttachedClient as _RuntimeAttachedClient } from './shared-types-extra.js';
10
10
  import type { RecentLaunchEntry as _RecentLaunchEntry } from './shared-types.js';
package/dist/index.js CHANGED
@@ -2488,8 +2488,6 @@ ${data.message || ""}`.trim();
2488
2488
  if (blockingModal || this.currentStatus === "waiting_approval") {
2489
2489
  throw new Error(`${this.cliName} is awaiting confirmation before it can accept a prompt`);
2490
2490
  }
2491
- this.committedMessages.push({ role: "user", content: text, timestamp: Date.now() });
2492
- this.syncMessageViews();
2493
2491
  this.isWaitingForResponse = true;
2494
2492
  this.responseBuffer = "";
2495
2493
  this.finishRetryCount = 0;
@@ -2521,6 +2519,13 @@ ${data.message || ""}`.trim();
2521
2519
  const submitDelayMs = this.sendDelayMs + Math.min(2e3, Math.max(0, estimatedLines - 1) * 350);
2522
2520
  const maxEchoWaitMs = submitDelayMs + Math.max(1500, Math.min(5e3, estimatedLines * 500));
2523
2521
  const retryDelayMs = Math.max(350, Math.min(1500, Math.max(this.sendDelayMs, submitDelayMs)));
2522
+ let didCommitUserTurn = false;
2523
+ const commitUserTurn = () => {
2524
+ if (didCommitUserTurn) return;
2525
+ didCommitUserTurn = true;
2526
+ this.committedMessages.push({ role: "user", content: text, timestamp: Date.now() });
2527
+ this.syncMessageViews();
2528
+ };
2524
2529
  if (this.settleTimer) {
2525
2530
  clearTimeout(this.settleTimer);
2526
2531
  this.settleTimer = null;
@@ -2533,109 +2538,128 @@ ${data.message || ""}`.trim();
2533
2538
  if (this.isWaitingForResponse) this.finishResponse();
2534
2539
  }, this.timeouts.maxResponse);
2535
2540
  };
2536
- const submit = () => {
2537
- if (!this.ptyProcess) return;
2538
- this.submitPendingUntil = 0;
2539
- this.recordTrace("submit_write", {
2540
- mode: "submit_key",
2541
- sendKey: this.sendKey,
2542
- screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
2543
- });
2544
- this.ptyProcess.write(this.sendKey);
2545
- const retrySubmitIfStuck = (attempt) => {
2546
- this.submitRetryTimer = null;
2547
- if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
2548
- if (this.currentStatus === "waiting_approval") return;
2549
- if ((this.responseBuffer || "").trim()) return;
2541
+ await new Promise((resolve12) => {
2542
+ let resolved = false;
2543
+ const resolveOnce = () => {
2544
+ if (resolved) return;
2545
+ resolved = true;
2546
+ resolve12();
2547
+ };
2548
+ const submit = () => {
2549
+ if (!this.ptyProcess) {
2550
+ resolveOnce();
2551
+ return;
2552
+ }
2553
+ commitUserTurn();
2554
+ this.submitPendingUntil = 0;
2550
2555
  const screenText = this.terminalScreen.getText();
2551
- if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
2552
- 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;
2553
- this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
2554
- LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt ${attempt})`);
2555
2556
  this.recordTrace("submit_write", {
2556
- mode: "submit_retry",
2557
- attempt,
2557
+ mode: "submit_key",
2558
2558
  sendKey: this.sendKey,
2559
2559
  screenText: summarizeCliTraceText(screenText, 500)
2560
2560
  });
2561
2561
  this.ptyProcess.write(this.sendKey);
2562
- if (attempt >= 3) {
2563
- this.submitRetryUsed = true;
2564
- return;
2565
- }
2566
- this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
2562
+ const retrySubmitIfStuck = (attempt) => {
2563
+ this.submitRetryTimer = null;
2564
+ if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
2565
+ if (this.currentStatus === "waiting_approval") return;
2566
+ if ((this.responseBuffer || "").trim()) return;
2567
+ const screenText2 = this.terminalScreen.getText();
2568
+ if (!promptLikelyVisible(screenText2, normalizedPromptSnippet)) return;
2569
+ 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;
2570
+ this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
2571
+ LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt ${attempt})`);
2572
+ this.recordTrace("submit_write", {
2573
+ mode: "submit_retry",
2574
+ attempt,
2575
+ sendKey: this.sendKey,
2576
+ screenText: summarizeCliTraceText(screenText2, 500)
2577
+ });
2578
+ this.ptyProcess.write(this.sendKey);
2579
+ if (attempt >= 3) {
2580
+ this.submitRetryUsed = true;
2581
+ return;
2582
+ }
2583
+ this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(attempt + 1), retryDelayMs);
2584
+ };
2585
+ this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
2586
+ startResponseTimeout();
2587
+ resolveOnce();
2567
2588
  };
2568
- this.submitRetryTimer = setTimeout(() => retrySubmitIfStuck(1), retryDelayMs);
2569
- startResponseTimeout();
2570
- };
2571
- if (this.submitStrategy === "immediate") {
2572
- this.submitPendingUntil = 0;
2589
+ if (this.submitStrategy === "immediate") {
2590
+ commitUserTurn();
2591
+ this.submitPendingUntil = 0;
2592
+ this.recordTrace("submit_write", {
2593
+ mode: "immediate",
2594
+ text: summarizeCliTraceText(text, 500),
2595
+ sendKey: this.sendKey,
2596
+ screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
2597
+ });
2598
+ this.ptyProcess.write(text + this.sendKey);
2599
+ this.submitRetryTimer = setTimeout(() => {
2600
+ this.submitRetryTimer = null;
2601
+ if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
2602
+ if (this.currentStatus === "waiting_approval") return;
2603
+ if ((this.responseBuffer || "").trim()) return;
2604
+ const screenText = this.terminalScreen.getText();
2605
+ if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
2606
+ LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
2607
+ this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
2608
+ this.recordTrace("submit_write", {
2609
+ mode: "immediate_retry",
2610
+ attempt: 1,
2611
+ sendKey: this.sendKey,
2612
+ screenText: summarizeCliTraceText(screenText, 500)
2613
+ });
2614
+ this.ptyProcess.write(this.sendKey);
2615
+ this.submitRetryUsed = true;
2616
+ }, retryDelayMs);
2617
+ startResponseTimeout();
2618
+ resolveOnce();
2619
+ return;
2620
+ }
2621
+ if (submitDelayMs > 0) {
2622
+ this.submitPendingUntil = Date.now() + submitDelayMs;
2623
+ }
2624
+ this.ptyProcess.write(text);
2573
2625
  this.recordTrace("submit_write", {
2574
- mode: "immediate",
2626
+ mode: "type_then_submit",
2575
2627
  text: summarizeCliTraceText(text, 500),
2576
2628
  sendKey: this.sendKey,
2577
2629
  screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
2578
2630
  });
2579
- this.ptyProcess.write(text + this.sendKey);
2580
- this.submitRetryTimer = setTimeout(() => {
2581
- this.submitRetryTimer = null;
2582
- if (!this.ptyProcess || !this.isWaitingForResponse || this.submitRetryUsed) return;
2583
- if (this.currentStatus === "waiting_approval") return;
2584
- if ((this.responseBuffer || "").trim()) return;
2631
+ const submitStartedAt = Date.now();
2632
+ let lastNormalizedScreen = "";
2633
+ let lastScreenChangeAt = submitStartedAt;
2634
+ const waitForEchoAndSubmit = () => {
2635
+ if (!this.ptyProcess) {
2636
+ resolveOnce();
2637
+ return;
2638
+ }
2639
+ const now = Date.now();
2640
+ const elapsed = now - submitStartedAt;
2585
2641
  const screenText = this.terminalScreen.getText();
2586
- if (!promptLikelyVisible(screenText, normalizedPromptSnippet)) return;
2587
- LOG.info("CLI", `[${this.cliType}] Retrying submit key for stuck prompt (attempt 1)`);
2588
- this.responseSettleIgnoreUntil = Date.now() + this.timeouts.outputSettle + 400;
2589
- this.recordTrace("submit_write", {
2590
- mode: "immediate_retry",
2591
- attempt: 1,
2592
- sendKey: this.sendKey,
2593
- screenText: summarizeCliTraceText(screenText, 500)
2594
- });
2595
- this.ptyProcess.write(this.sendKey);
2596
- this.submitRetryUsed = true;
2597
- }, retryDelayMs);
2598
- startResponseTimeout();
2599
- return;
2600
- }
2601
- if (submitDelayMs > 0) {
2602
- this.submitPendingUntil = Date.now() + submitDelayMs;
2603
- }
2604
- this.ptyProcess.write(text);
2605
- this.recordTrace("submit_write", {
2606
- mode: "type_then_submit",
2607
- text: summarizeCliTraceText(text, 500),
2608
- sendKey: this.sendKey,
2609
- screenText: summarizeCliTraceText(this.terminalScreen.getText(), 500)
2610
- });
2611
- const submitStartedAt = Date.now();
2612
- let lastNormalizedScreen = "";
2613
- let lastScreenChangeAt = submitStartedAt;
2614
- const waitForEchoAndSubmit = () => {
2615
- if (!this.ptyProcess) return;
2616
- const now = Date.now();
2617
- const elapsed = now - submitStartedAt;
2618
- const screenText = this.terminalScreen.getText();
2619
- const normalizedScreen = normalizePromptText(screenText);
2620
- if (normalizedScreen !== lastNormalizedScreen) {
2621
- lastNormalizedScreen = normalizedScreen;
2622
- lastScreenChangeAt = now;
2623
- }
2624
- const echoVisible = !normalizedPromptSnippet || promptLikelyVisible(screenText, normalizedPromptSnippet);
2625
- if (echoVisible) {
2626
- const screenSettled = now - lastScreenChangeAt >= 500;
2627
- if (elapsed >= submitDelayMs && screenSettled) {
2642
+ const normalizedScreen = normalizePromptText(screenText);
2643
+ if (normalizedScreen !== lastNormalizedScreen) {
2644
+ lastNormalizedScreen = normalizedScreen;
2645
+ lastScreenChangeAt = now;
2646
+ }
2647
+ const echoVisible = !normalizedPromptSnippet || promptLikelyVisible(screenText, normalizedPromptSnippet);
2648
+ if (echoVisible) {
2649
+ const screenSettled = now - lastScreenChangeAt >= 500;
2650
+ if (elapsed >= submitDelayMs && screenSettled) {
2651
+ submit();
2652
+ return;
2653
+ }
2654
+ }
2655
+ if (elapsed >= maxEchoWaitMs) {
2628
2656
  submit();
2629
2657
  return;
2630
2658
  }
2631
- }
2632
- if (elapsed >= maxEchoWaitMs) {
2633
- submit();
2634
- return;
2635
- }
2636
- setTimeout(waitForEchoAndSubmit, 50);
2637
- };
2638
- waitForEchoAndSubmit();
2659
+ setTimeout(waitForEchoAndSubmit, 50);
2660
+ };
2661
+ waitForEchoAndSubmit();
2662
+ });
2639
2663
  }
2640
2664
  getPartialResponse() {
2641
2665
  if (!this.isWaitingForResponse) return "";
@@ -14417,6 +14441,7 @@ var DaemonStatusReporter = class {
14417
14441
  lastStatusSentAt = 0;
14418
14442
  statusPendingThrottle = false;
14419
14443
  lastP2PStatusHash = "";
14444
+ lastServerStatusHash = "";
14420
14445
  lastStatusSummary = "";
14421
14446
  statusTimer = null;
14422
14447
  p2pTimer = null;
@@ -14427,11 +14452,11 @@ var DaemonStatusReporter = class {
14427
14452
  // ─── Lifecycle ───────────────────────────────────
14428
14453
  startReporting() {
14429
14454
  setTimeout(() => {
14430
- this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
14455
+ this.sendUnifiedStatusReport({ forceServer: true, reason: "initial" }).catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
14431
14456
  }, 2e3);
14432
14457
  const scheduleServerReport = () => {
14433
14458
  this.statusTimer = setTimeout(() => {
14434
- this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
14459
+ this.sendUnifiedStatusReport({ forceServer: true, reason: "periodic" }).catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
14435
14460
  scheduleServerReport();
14436
14461
  }, 3e4);
14437
14462
  };
@@ -14578,24 +14603,24 @@ var DaemonStatusReporter = class {
14578
14603
  cdpConnected: session.cdpConnected,
14579
14604
  currentModel: session.currentModel,
14580
14605
  currentPlan: session.currentPlan,
14581
- currentAutoApprove: session.currentAutoApprove,
14582
- lastUpdated: session.lastUpdated,
14583
- unread: session.unread,
14584
- lastSeenAt: session.lastSeenAt,
14585
- inboxBucket: session.inboxBucket,
14586
- surfaceHidden: session.surfaceHidden,
14587
- controlValues: session.controlValues,
14588
- providerControls: session.providerControls,
14589
- acpConfigOptions: session.acpConfigOptions,
14590
- acpModes: session.acpModes
14606
+ currentAutoApprove: session.currentAutoApprove
14591
14607
  })),
14592
14608
  p2p: payload.p2p,
14593
14609
  timestamp: now,
14594
14610
  detectedIdes: payload.detectedIdes,
14595
14611
  availableProviders: payload.availableProviders
14596
14612
  };
14613
+ const wsHash = this.simpleHash(JSON.stringify({
14614
+ ...wsPayload,
14615
+ timestamp: void 0
14616
+ }));
14617
+ if (!opts?.forceServer && wsHash === this.lastServerStatusHash) {
14618
+ LOG.debug("Server", `skip duplicate status_report${opts?.reason ? ` (${opts.reason})` : ""}`);
14619
+ return;
14620
+ }
14621
+ this.lastServerStatusHash = wsHash;
14597
14622
  serverConn.sendMessage("status_report", wsPayload);
14598
- LOG.debug("Server", `sent status_report (${JSON.stringify(wsPayload).length} bytes)`);
14623
+ LOG.debug("Server", `sent status_report (${JSON.stringify(wsPayload).length} bytes)${opts?.reason ? ` [${opts.reason}]` : ""}`);
14599
14624
  }
14600
14625
  // ─── P2P ─────────────────────────────────────────
14601
14626
  sendP2PPayload(payload) {