adhdev 0.8.87 → 0.8.89

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/cli/index.js CHANGED
@@ -6367,6 +6367,25 @@ var init_setup = __esm({
6367
6367
  }
6368
6368
  });
6369
6369
 
6370
+ // ../../oss/packages/daemon-core/src/runtime-defaults.ts
6371
+ var DEFAULT_CDP_SCAN_INTERVAL_MS, DEFAULT_CDP_DISCOVERY_INTERVAL_MS, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS, MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS, DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS, MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS, DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS, DEFAULT_SESSION_HOST_READY_TIMEOUT_MS, STANDALONE_CDP_SCAN_INTERVAL_MS;
6372
+ var init_runtime_defaults = __esm({
6373
+ "../../oss/packages/daemon-core/src/runtime-defaults.ts"() {
6374
+ "use strict";
6375
+ DEFAULT_CDP_SCAN_INTERVAL_MS = 3e4;
6376
+ DEFAULT_CDP_DISCOVERY_INTERVAL_MS = 3e4;
6377
+ DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS = 2e3;
6378
+ DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS = 3e4;
6379
+ DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS = 5e3;
6380
+ MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 5e3;
6381
+ DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 15e3;
6382
+ MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 5e3;
6383
+ DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 1e4;
6384
+ DEFAULT_SESSION_HOST_READY_TIMEOUT_MS = 15e3;
6385
+ STANDALONE_CDP_SCAN_INTERVAL_MS = 15e3;
6386
+ }
6387
+ });
6388
+
6370
6389
  // ../../oss/packages/daemon-core/src/cdp/scanner.ts
6371
6390
  var DaemonCdpScanner;
6372
6391
  var init_scanner = __esm({
@@ -6375,6 +6394,7 @@ var init_scanner = __esm({
6375
6394
  init_manager();
6376
6395
  init_setup();
6377
6396
  init_logger();
6397
+ init_runtime_defaults();
6378
6398
  DaemonCdpScanner = class {
6379
6399
  ctx;
6380
6400
  opts;
@@ -6408,7 +6428,7 @@ var init_scanner = __esm({
6408
6428
  */
6409
6429
  startPeriodicScan() {
6410
6430
  if (this.scanTimer) return;
6411
- const interval = this.opts.scanIntervalMs || 3e4;
6431
+ const interval = this.opts.scanIntervalMs || DEFAULT_CDP_SCAN_INTERVAL_MS;
6412
6432
  this.scanTimer = setInterval(async () => {
6413
6433
  const portMap = this.ctx.providerLoader.getCdpPortMap();
6414
6434
  for (const [ide, ports] of Object.entries(portMap)) {
@@ -6428,7 +6448,7 @@ var init_scanner = __esm({
6428
6448
  /**
6429
6449
  * Start periodic agent webview discovery on all connected CDPs.
6430
6450
  */
6431
- startWebviewDiscovery(intervalMs = 3e4) {
6451
+ startWebviewDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS) {
6432
6452
  if (this.discoveryTimer) return;
6433
6453
  this.discoveryTimer = setInterval(async () => {
6434
6454
  for (const m of this.ctx.cdpManagers.values()) {
@@ -6528,6 +6548,7 @@ var init_initializer = __esm({
6528
6548
  init_setup();
6529
6549
  init_setup();
6530
6550
  init_logger();
6551
+ init_runtime_defaults();
6531
6552
  DaemonCdpInitializer = class {
6532
6553
  config;
6533
6554
  scanTimer = null;
@@ -6659,7 +6680,7 @@ var init_initializer = __esm({
6659
6680
  * Start periodic scanning for newly opened IDEs.
6660
6681
  * Idempotent — ignored if already started.
6661
6682
  */
6662
- startPeriodicScan(intervalMs = 3e4) {
6683
+ startPeriodicScan(intervalMs = DEFAULT_CDP_SCAN_INTERVAL_MS) {
6663
6684
  if (this.scanTimer) return;
6664
6685
  this.scanTimer = setInterval(async () => {
6665
6686
  const { providerLoader, cdpManagers } = this.config;
@@ -6673,7 +6694,7 @@ var init_initializer = __esm({
6673
6694
  /**
6674
6695
  * Start periodic agent webview discovery.
6675
6696
  */
6676
- startDiscovery(intervalMs = 3e4) {
6697
+ startDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS) {
6677
6698
  if (this.discoveryTimer) return;
6678
6699
  this.discoveryTimer = setInterval(async () => {
6679
6700
  for (const m of this.config.cdpManagers.values()) {
@@ -12717,8 +12738,7 @@ var init_provider_cli_adapter = __esm({
12717
12738
  const buttons = Array.isArray(modal.buttons) ? modal.buttons : [];
12718
12739
  if (buttons.length !== 1) return false;
12719
12740
  const buttonLabel = String(buttons[0] || "").trim();
12720
- const modalText = `${modal.message || ""} ${buttonLabel}`.trim();
12721
- return looksLikeConfirmOnlyLabel(buttonLabel) || /Quick safety check|project trust|trust (?:this project|the contents of this directory|the files in this folder)|Enter to confirm/i.test(modalText);
12741
+ return looksLikeConfirmOnlyLabel(buttonLabel);
12722
12742
  }
12723
12743
  async waitForInteractivePrompt(maxWaitMs = 5e3) {
12724
12744
  const startedAt = Date.now();
@@ -13334,11 +13354,14 @@ var init_provider_cli_adapter = __esm({
13334
13354
  }
13335
13355
  // ─── Public API (CliAdapter) ───────────────────
13336
13356
  getStatus() {
13357
+ const screenText = this.terminalScreen.getText() || "";
13358
+ const startupModal = this.startupParseGate ? this.getStartupConfirmationModal(screenText) : null;
13359
+ const effectiveStatus = this.parseErrorMessage ? "error" : startupModal ? "waiting_approval" : this.currentStatus;
13337
13360
  return {
13338
- status: this.parseErrorMessage ? "error" : this.currentStatus,
13361
+ status: effectiveStatus,
13339
13362
  messages: [...this.committedMessages],
13340
13363
  workingDir: this.workingDir,
13341
- activeModal: this.activeModal,
13364
+ activeModal: startupModal || this.activeModal,
13342
13365
  errorMessage: this.parseErrorMessage || void 0,
13343
13366
  errorReason: this.parseErrorMessage ? "parse_error" : void 0
13344
13367
  };
@@ -13391,8 +13414,38 @@ var init_provider_cli_adapter = __esm({
13391
13414
  index: typeof message.index === "number" ? message.index : index,
13392
13415
  receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
13393
13416
  }));
13394
- const shouldPreferCommittedHistoryReplay = !this.currentTurnScope && !this.activeModal && committedHydratedMessages.length > parsedHydratedMessages.length;
13395
- const hydratedMessages = shouldPreferCommittedMessages || shouldPreferCommittedHistoryReplay ? committedHydratedMessages : parsedHydratedMessages;
13417
+ const parsedLastAssistant = [...parsedHydratedMessages].reverse().find((message) => message.role === "assistant" && typeof message.content === "string" && message.content.trim());
13418
+ const visibleIdlePrompt = this.looksLikeVisibleIdlePrompt(screenText);
13419
+ const shouldAdoptParsedIdleReplay = !this.currentTurnScope && !this.activeModal && !!parsedLastAssistant && parsedHydratedMessages.length > committedHydratedMessages.length && (this.currentStatus === "idle" || this.currentStatus === "generating" && this.isWaitingForResponse && parsed.status === "idle" && visibleIdlePrompt);
13420
+ if (shouldAdoptParsedIdleReplay) {
13421
+ this.committedMessages = normalizeCliParsedMessages(parsed.messages, {
13422
+ committedMessages: this.committedMessages,
13423
+ scope: this.currentTurnScope,
13424
+ lastOutputAt: this.lastOutputAt
13425
+ });
13426
+ this.syncMessageViews();
13427
+ if (this.currentStatus !== "idle" || this.isWaitingForResponse) {
13428
+ this.responseBuffer = "";
13429
+ this.isWaitingForResponse = false;
13430
+ this.responseSettleIgnoreUntil = 0;
13431
+ this.submitRetryUsed = false;
13432
+ this.submitRetryPromptSnippet = "";
13433
+ this.finishRetryCount = 0;
13434
+ this.currentTurnScope = null;
13435
+ this.activeModal = null;
13436
+ this.setStatus("idle", "parsed_idle_replay_commit");
13437
+ this.onStatusChange?.();
13438
+ }
13439
+ }
13440
+ const effectiveCommittedHydratedMessages = shouldAdoptParsedIdleReplay ? this.committedMessages.map((message, index) => buildChatMessage({
13441
+ ...message,
13442
+ id: message.id || `msg_${index}`,
13443
+ index: typeof message.index === "number" ? message.index : index,
13444
+ receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
13445
+ })) : committedHydratedMessages;
13446
+ const shouldPreferCommittedHistoryReplay = !this.currentTurnScope && !this.activeModal && effectiveCommittedHydratedMessages.length > parsedHydratedMessages.length;
13447
+ const shouldPreferCommittedIdleReplay = shouldPreferCommittedMessages && !shouldAdoptParsedIdleReplay;
13448
+ const hydratedMessages = shouldPreferCommittedIdleReplay || shouldPreferCommittedHistoryReplay ? effectiveCommittedHydratedMessages : parsedHydratedMessages;
13396
13449
  result = {
13397
13450
  id: parsed.id || "cli_session",
13398
13451
  status: parsed.status || this.currentStatus,
@@ -13993,8 +14046,9 @@ ${data.message || ""}`.trim();
13993
14046
  this.ptyProcess?.write(data);
13994
14047
  }
13995
14048
  resolveModal(buttonIndex) {
13996
- if (!this.ptyProcess || this.currentStatus !== "waiting_approval" && !this.activeModal) return;
13997
- const modal = this.activeModal;
14049
+ const screenText = this.terminalScreen.getText() || "";
14050
+ const modal = this.activeModal || this.getStartupConfirmationModal(screenText);
14051
+ if (!this.ptyProcess || this.currentStatus !== "waiting_approval" && !modal) return;
13998
14052
  this.clearIdleFinishCandidate("resolve_modal");
13999
14053
  this.recordTrace("resolve_modal", {
14000
14054
  buttonIndex,
@@ -14009,7 +14063,10 @@ ${data.message || ""}`.trim();
14009
14063
  }
14010
14064
  this.setStatus("generating", "approval_resolved");
14011
14065
  this.onStatusChange?.();
14012
- if (this.shouldResolveModalWithEnter(modal, buttonIndex)) {
14066
+ const startupTrustModal = /Quick safety check|project trust|trust (?:this project|the contents of this directory|the files in this folder)/i.test(String(modal?.message || ""));
14067
+ if (startupTrustModal && buttonIndex in this.approvalKeys) {
14068
+ this.ptyProcess.write(`${this.approvalKeys[buttonIndex]}\r`);
14069
+ } else if (this.shouldResolveModalWithEnter(modal, buttonIndex)) {
14013
14070
  this.ptyProcess.write("\r");
14014
14071
  } else if (buttonIndex in this.approvalKeys) {
14015
14072
  this.ptyProcess.write(this.approvalKeys[buttonIndex]);
@@ -14030,20 +14087,24 @@ ${data.message || ""}`.trim();
14030
14087
  }
14031
14088
  }
14032
14089
  getDebugState() {
14090
+ const screenText = sanitizeTerminalText(this.terminalScreen.getText());
14091
+ const startupModal = this.startupParseGate ? this.getStartupConfirmationModal(screenText) : null;
14092
+ const effectiveStatus = startupModal ? "waiting_approval" : this.currentStatus;
14093
+ const effectiveReady = this.ready || !!startupModal;
14033
14094
  return {
14034
14095
  type: this.cliType,
14035
14096
  name: this.cliName,
14036
14097
  providerResolution: this.providerResolutionMeta,
14037
- status: this.currentStatus,
14038
- ready: this.ready,
14098
+ status: effectiveStatus,
14099
+ ready: effectiveReady,
14039
14100
  startupParseGate: this.startupParseGate,
14040
14101
  spawnAt: this.spawnAt,
14041
14102
  workingDir: this.workingDir,
14042
- messages: this.messages.slice(-20),
14043
- committedMessages: this.committedMessages.slice(-20),
14044
- structuredMessages: this.structuredMessages.slice(-20),
14103
+ messages: this.messages,
14104
+ committedMessages: this.committedMessages,
14105
+ structuredMessages: this.structuredMessages,
14045
14106
  messageCount: this.committedMessages.length,
14046
- screenText: sanitizeTerminalText(this.terminalScreen.getText()).slice(-4e3),
14107
+ screenText: screenText.slice(-4e3),
14047
14108
  currentTurnScope: this.currentTurnScope,
14048
14109
  startupBuffer: this.startupBuffer.slice(-4e3),
14049
14110
  recentOutputBuffer: this.recentOutputBuffer.slice(-500),
@@ -14058,7 +14119,7 @@ ${data.message || ""}`.trim();
14058
14119
  lastScreenChangeAt: this.lastScreenChangeAt,
14059
14120
  lastScreenSnapshot: this.lastScreenSnapshot.slice(-500),
14060
14121
  isWaitingForResponse: this.isWaitingForResponse,
14061
- activeModal: this.activeModal,
14122
+ activeModal: startupModal || this.activeModal,
14062
14123
  lastApprovalResolvedAt: this.lastApprovalResolvedAt,
14063
14124
  sendDelayMs: this.sendDelayMs,
14064
14125
  sendKey: this.sendKey,
@@ -38134,6 +38195,7 @@ var init_reporter = __esm({
38134
38195
  "../../oss/packages/daemon-core/src/status/reporter.ts"() {
38135
38196
  "use strict";
38136
38197
  init_logger();
38198
+ init_runtime_defaults();
38137
38199
  init_builders();
38138
38200
  init_snapshot();
38139
38201
  DaemonStatusReporter = class {
@@ -38154,19 +38216,19 @@ var init_reporter = __esm({
38154
38216
  startReporting() {
38155
38217
  setTimeout(() => {
38156
38218
  this.sendUnifiedStatusReport({ forceServer: true, reason: "initial" }).catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
38157
- }, 2e3);
38219
+ }, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS);
38158
38220
  const scheduleServerReport = () => {
38159
38221
  this.statusTimer = setTimeout(() => {
38160
38222
  this.sendUnifiedStatusReport({ forceServer: true, reason: "periodic" }).catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
38161
38223
  scheduleServerReport();
38162
- }, 3e4);
38224
+ }, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS);
38163
38225
  };
38164
38226
  scheduleServerReport();
38165
38227
  this.p2pTimer = setInterval(() => {
38166
38228
  if (this.deps.p2p?.isConnected) {
38167
38229
  this.sendUnifiedStatusReport({ p2pOnly: true }).catch((e) => LOG.warn("Status", `P2P status send failed: ${e?.message}`));
38168
38230
  }
38169
- }, 5e3);
38231
+ }, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS);
38170
38232
  }
38171
38233
  stopReporting() {
38172
38234
  if (this.statusTimer) {
@@ -38184,14 +38246,14 @@ var init_reporter = __esm({
38184
38246
  throttledReport() {
38185
38247
  const now = Date.now();
38186
38248
  const elapsed = now - this.lastStatusSentAt;
38187
- if (elapsed >= 5e3) {
38249
+ if (elapsed >= DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS) {
38188
38250
  this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Throttled report failed: ${e?.message}`));
38189
38251
  } else if (!this.statusPendingThrottle) {
38190
38252
  this.statusPendingThrottle = true;
38191
38253
  setTimeout(() => {
38192
38254
  this.statusPendingThrottle = false;
38193
38255
  this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Deferred report failed: ${e?.message}`));
38194
- }, 5e3 - elapsed);
38256
+ }, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS - elapsed);
38195
38257
  }
38196
38258
  }
38197
38259
  toDaemonStatusEventName(value) {
@@ -45617,7 +45679,8 @@ var init_runtime_support = __esm({
45617
45679
  "../../oss/packages/daemon-core/src/session-host/runtime-support.ts"() {
45618
45680
  "use strict";
45619
45681
  init_dist();
45620
- STARTUP_TIMEOUT_MS = 8e3;
45682
+ init_runtime_defaults();
45683
+ STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
45621
45684
  STARTUP_POLL_MS = 200;
45622
45685
  }
45623
45686
  });
@@ -45997,8 +46060,8 @@ async function initDaemonComponents(config2) {
45997
46060
  }
45998
46061
  });
45999
46062
  await cdpInitializer.connectAll(detectedIdesRef.value);
46000
- cdpInitializer.startPeriodicScan(config2.cdpScanIntervalMs ?? 3e4);
46001
- cdpInitializer.startDiscovery(3e4);
46063
+ cdpInitializer.startPeriodicScan(config2.cdpScanIntervalMs ?? DEFAULT_CDP_SCAN_INTERVAL_MS);
46064
+ cdpInitializer.startDiscovery(DEFAULT_CDP_DISCOVERY_INTERVAL_MS);
46002
46065
  const commandHandler = new DaemonCommandHandler({
46003
46066
  cdpManagers,
46004
46067
  ideType: "unknown",
@@ -46137,6 +46200,7 @@ var init_daemon_lifecycle = __esm({
46137
46200
  init_cli_detector();
46138
46201
  init_registry();
46139
46202
  init_logger();
46203
+ init_runtime_defaults();
46140
46204
  init_config();
46141
46205
  }
46142
46206
  });
@@ -46151,10 +46215,19 @@ __export(src_exports, {
46151
46215
  CliProviderInstance: () => CliProviderInstance,
46152
46216
  DAEMON_WS_PATH: () => DAEMON_WS_PATH,
46153
46217
  DEFAULT_ACTIVE_CHAT_POLL_STATUSES: () => DEFAULT_ACTIVE_CHAT_POLL_STATUSES,
46218
+ DEFAULT_CDP_DISCOVERY_INTERVAL_MS: () => DEFAULT_CDP_DISCOVERY_INTERVAL_MS,
46219
+ DEFAULT_CDP_SCAN_INTERVAL_MS: () => DEFAULT_CDP_SCAN_INTERVAL_MS,
46154
46220
  DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS: () => DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS,
46155
46221
  DEFAULT_DAEMON_PORT: () => DEFAULT_DAEMON_PORT,
46222
+ DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS: () => DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
46156
46223
  DEFAULT_SESSION_HOST_APP_NAME: () => DEFAULT_SESSION_HOST_APP_NAME,
46224
+ DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS: () => DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
46225
+ DEFAULT_SESSION_HOST_READY_TIMEOUT_MS: () => DEFAULT_SESSION_HOST_READY_TIMEOUT_MS,
46157
46226
  DEFAULT_STANDALONE_SESSION_HOST_APP_NAME: () => DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
46227
+ DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS: () => DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS,
46228
+ DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS: () => DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS,
46229
+ DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS: () => DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS,
46230
+ DEV_SERVER_PORT: () => DEV_SERVER_PORT,
46158
46231
  DaemonAgentStreamManager: () => DaemonAgentStreamManager,
46159
46232
  DaemonCdpInitializer: () => DaemonCdpInitializer,
46160
46233
  DaemonCdpManager: () => DaemonCdpManager,
@@ -46166,10 +46239,13 @@ __export(src_exports, {
46166
46239
  DevServer: () => DevServer,
46167
46240
  IdeProviderInstance: () => IdeProviderInstance,
46168
46241
  LOG: () => LOG,
46242
+ MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS: () => MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
46243
+ MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS: () => MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
46169
46244
  NodePtyTransportFactory: () => NodePtyTransportFactory,
46170
46245
  ProviderCliAdapter: () => ProviderCliAdapter,
46171
46246
  ProviderInstanceManager: () => ProviderInstanceManager,
46172
46247
  ProviderLoader: () => ProviderLoader,
46248
+ STANDALONE_CDP_SCAN_INTERVAL_MS: () => STANDALONE_CDP_SCAN_INTERVAL_MS,
46173
46249
  SessionHostPtyTransportFactory: () => SessionHostPtyTransportFactory,
46174
46250
  VersionArchive: () => VersionArchive,
46175
46251
  appendRecentActivity: () => appendRecentActivity,
@@ -46308,6 +46384,7 @@ var init_src = __esm({
46308
46384
  init_cli_manager();
46309
46385
  init_launch();
46310
46386
  init_ipc_protocol();
46387
+ init_runtime_defaults();
46311
46388
  init_chat_history();
46312
46389
  init_chat_signatures();
46313
46390
  init_subscription_updates();
@@ -46350,7 +46427,7 @@ function resolveDaemonCommandPort(port, env3 = process.env) {
46350
46427
  return explicitPort;
46351
46428
  }
46352
46429
  const envPort = parseInt(env3.ADHDEV_DAEMON_PORT || "", 10);
46353
- return Number.isFinite(envPort) && envPort > 0 ? envPort : 19222;
46430
+ return Number.isFinite(envPort) && envPort > 0 ? envPort : DEFAULT_DAEMON_PORT;
46354
46431
  }
46355
46432
  async function sendDaemonCommand(cmd, args = {}, port) {
46356
46433
  const resolvedPort = resolveDaemonCommandPort(port);
@@ -46474,6 +46551,7 @@ async function directCdpEval(expression, port = 9222) {
46474
46551
  var init_cdp_utils = __esm({
46475
46552
  "src/cli/cdp-utils.ts"() {
46476
46553
  "use strict";
46554
+ init_src();
46477
46555
  }
46478
46556
  });
46479
46557
 
@@ -77797,6 +77875,10 @@ var init_server_connection = __esm({
77797
77875
  }
77798
77876
  }
77799
77877
  scheduleReconnect() {
77878
+ if (this.reconnectTimer) {
77879
+ clearTimeout(this.reconnectTimer);
77880
+ this.reconnectTimer = null;
77881
+ }
77800
77882
  const delay = Math.min(2e3 * Math.pow(1.5, this.reconnectAttempts), 6e4);
77801
77883
  this.reconnectAttempts++;
77802
77884
  LOG.info("Server", `[ServerConn] Reconnecting in ${(delay / 1e3).toFixed(1)}s (attempt ${this.reconnectAttempts})...`);
@@ -78444,9 +78526,44 @@ async function initiateConnection(deps, peerId, sharePermission) {
78444
78526
  clearTimeout(peer.failedCleanupTimer);
78445
78527
  peer.failedCleanupTimer = void 0;
78446
78528
  }
78529
+ if (peer.disconnectTimer) {
78530
+ clearTimeout(peer.disconnectTimer);
78531
+ peer.disconnectTimer = void 0;
78532
+ }
78447
78533
  deps.notifyStateChange();
78534
+ } else if (pcState === "disconnected") {
78535
+ log(`Peer ${pid} ICE disconnected \u2014 waiting 3s for recovery`);
78536
+ if (peer.disconnectTimer) clearTimeout(peer.disconnectTimer);
78537
+ peer.disconnectTimer = setTimeout(() => {
78538
+ const p = deps.peers.get(pid);
78539
+ if (!p) return;
78540
+ p.disconnectTimer = void 0;
78541
+ let currentState;
78542
+ try {
78543
+ currentState = pc.state?.();
78544
+ } catch {
78545
+ }
78546
+ if (currentState !== "connected") {
78547
+ log(`Peer ${pid} ICE recovery timeout (state=${currentState ?? "unknown"}) \u2014 marking failed`);
78548
+ p.state = "failed";
78549
+ deps.notifyStateChange();
78550
+ if (!p.failedCleanupTimer) {
78551
+ p.failedCleanupTimer = setTimeout(() => {
78552
+ const pp = deps.peers.get(pid);
78553
+ if (pp?.state === "failed") {
78554
+ log(`Auto-cleanup stale failed peer ${pid}`);
78555
+ disconnectPeer(deps.peers, pid, deps.notifyStateChange);
78556
+ }
78557
+ }, 3e4);
78558
+ }
78559
+ }
78560
+ }, 3e3);
78448
78561
  } else if (pcState === "failed" || pcState === "closed") {
78449
78562
  peer.state = "failed";
78563
+ if (peer.disconnectTimer) {
78564
+ clearTimeout(peer.disconnectTimer);
78565
+ peer.disconnectTimer = void 0;
78566
+ }
78450
78567
  deps.notifyStateChange();
78451
78568
  if (!peer.failedCleanupTimer) {
78452
78569
  peer.failedCleanupTimer = setTimeout(() => {
@@ -78604,6 +78721,7 @@ function disconnectPeer(peers, peerId, notifyStateChange) {
78604
78721
  if (peer.failedCleanupTimer) clearTimeout(peer.failedCleanupTimer);
78605
78722
  if (peer.heartbeatTimer) clearInterval(peer.heartbeatTimer);
78606
78723
  if (peer.connectionTimeout) clearTimeout(peer.connectionTimeout);
78724
+ if (peer.disconnectTimer) clearTimeout(peer.disconnectTimer);
78607
78725
  if (peer.dataChannel) try {
78608
78726
  peer.dataChannel.close();
78609
78727
  } catch {
@@ -86058,8 +86176,9 @@ var init_session_host = __esm({
86058
86176
  init_src();
86059
86177
  init_dist();
86060
86178
  init_session_host_hygiene();
86179
+ init_runtime_defaults();
86061
86180
  SESSION_HOST_APP_NAME = process.env.ADHDEV_SESSION_HOST_NAME || DEFAULT_SESSION_HOST_APP_NAME;
86062
- SESSION_HOST_START_TIMEOUT_MS = 15e3;
86181
+ SESSION_HOST_START_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
86063
86182
  }
86064
86183
  });
86065
86184
 
@@ -86381,7 +86500,8 @@ var init_adhdev_daemon = __esm({
86381
86500
  init_source();
86382
86501
  init_version();
86383
86502
  init_src();
86384
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.87" });
86503
+ init_runtime_defaults();
86504
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.89" });
86385
86505
  AdhdevDaemon = class _AdhdevDaemon {
86386
86506
  localHttpServer = null;
86387
86507
  localWss = null;
@@ -86413,7 +86533,7 @@ var init_adhdev_daemon = __esm({
86413
86533
  "session_host_restart_session"
86414
86534
  ]);
86415
86535
  constructor() {
86416
- this.localPort = 19222;
86536
+ this.localPort = DEFAULT_DAEMON_PORT;
86417
86537
  }
86418
86538
  applyDebugRuntime(options) {
86419
86539
  this.debugConfig = resolveDebugRuntimeConfig({
@@ -86604,7 +86724,10 @@ var init_adhdev_daemon = __esm({
86604
86724
  }
86605
86725
  }
86606
86726
  buildMachineRuntimeUpdateForSubscription(subscription) {
86607
- const intervalMs = Math.max(5e3, Number(subscription.params.intervalMs || 15e3));
86727
+ const intervalMs = Math.max(
86728
+ MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
86729
+ Number(subscription.params.intervalMs || DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS)
86730
+ );
86608
86731
  const now = Date.now();
86609
86732
  if (subscription.lastSentAt > 0 && now - subscription.lastSentAt < intervalMs) {
86610
86733
  return null;
@@ -86625,7 +86748,10 @@ var init_adhdev_daemon = __esm({
86625
86748
  }
86626
86749
  async buildSessionHostDiagnosticsUpdateForSubscription(subscription) {
86627
86750
  if (!this.sessionHostController) return null;
86628
- const intervalMs = Math.max(5e3, Number(subscription.params.intervalMs || 1e4));
86751
+ const intervalMs = Math.max(
86752
+ MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
86753
+ Number(subscription.params.intervalMs || DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS)
86754
+ );
86629
86755
  const now = Date.now();
86630
86756
  if (subscription.lastSentAt > 0 && now - subscription.lastSentAt < intervalMs) {
86631
86757
  return null;
@@ -87696,7 +87822,7 @@ async function startDaemonFlow() {
87696
87822
  });
87697
87823
  }
87698
87824
  } catch {
87699
- daemon.start({ localPort: 19222, foreground: false }).catch(() => {
87825
+ daemon.start({ localPort: DEFAULT_DAEMON_PORT, foreground: false }).catch(() => {
87700
87826
  });
87701
87827
  }
87702
87828
  let started = false;
@@ -88843,6 +88969,7 @@ init_src();
88843
88969
 
88844
88970
  // src/cli/setup-commands.ts
88845
88971
  init_source();
88972
+ init_src();
88846
88973
 
88847
88974
  // src/cli/provider-source-status.ts
88848
88975
  function buildProviderSourceStatusLines(config2) {
@@ -88857,6 +88984,7 @@ function buildProviderSourceStatusLines(config2) {
88857
88984
 
88858
88985
  // src/cli/setup-commands.ts
88859
88986
  init_cdp_utils();
88987
+ var DEFAULT_LOCAL_DAEMON_HEALTH_TIMEOUT_MS = 1500;
88860
88988
  function resolveLaunchableProviderTarget(providerLoader, targetArg) {
88861
88989
  if (!targetArg) return null;
88862
88990
  const resolvedType = providerLoader.resolveAlias(targetArg.toLowerCase());
@@ -89093,7 +89221,7 @@ function registerSetupCommands(program2, providerLoader) {
89093
89221
  if (!isDaemonRunning2({ port: daemonPort })) {
89094
89222
  spinner2.stop();
89095
89223
  console.log(source_default.yellow(`
89096
- \u26A0 Daemon not running on port ${daemonPort}. Start with 'adhdev daemon${daemonPort === 19222 ? "" : ` -p ${daemonPort}`}' first.
89224
+ \u26A0 Daemon not running on port ${daemonPort}. Start with 'adhdev daemon${daemonPort === DEFAULT_DAEMON_PORT ? "" : ` -p ${daemonPort}`}' first.
89097
89225
  `));
89098
89226
  console.log(source_default.gray(" Then run: adhdev launch " + targetArg));
89099
89227
  process.exit(1);
@@ -89229,7 +89357,7 @@ function registerSetupCommands(program2, providerLoader) {
89229
89357
  const daemonPort = resolveDaemonCommandPort();
89230
89358
  if (!isDaemonRunning2({ port: daemonPort })) {
89231
89359
  console.log(source_default.yellow(`
89232
- \u26A0 Daemon not running on port ${daemonPort}. Start with 'adhdev daemon${daemonPort === 19222 ? "" : ` -p ${daemonPort}`}' first.
89360
+ \u26A0 Daemon not running on port ${daemonPort}. Start with 'adhdev daemon${daemonPort === DEFAULT_DAEMON_PORT ? "" : ` -p ${daemonPort}`}' first.
89233
89361
  `));
89234
89362
  console.log(source_default.gray(` Then run: adhdev history list ${providerArg}`));
89235
89363
  process.exit(1);
@@ -89301,7 +89429,7 @@ function registerSetupCommands(program2, providerLoader) {
89301
89429
  const daemonPort = resolveDaemonCommandPort();
89302
89430
  if (!isDaemonRunning2({ port: daemonPort })) {
89303
89431
  console.log(source_default.yellow(`
89304
- \u26A0 Daemon not running on port ${daemonPort}. Start with 'adhdev daemon${daemonPort === 19222 ? "" : ` -p ${daemonPort}`}' first.
89432
+ \u26A0 Daemon not running on port ${daemonPort}. Start with 'adhdev daemon${daemonPort === DEFAULT_DAEMON_PORT ? "" : ` -p ${daemonPort}`}' first.
89305
89433
  `));
89306
89434
  console.log(source_default.gray(` Then run: adhdev history resume ${providerArg} ${historySessionId}`));
89307
89435
  process.exit(1);
@@ -89436,8 +89564,8 @@ function registerSetupCommands(program2, providerLoader) {
89436
89564
  if (daemonRunning) {
89437
89565
  try {
89438
89566
  const controller = new AbortController();
89439
- const timer = setTimeout(() => controller.abort(), 1500);
89440
- const res = await fetch("http://127.0.0.1:19222/health", { signal: controller.signal });
89567
+ const timer = setTimeout(() => controller.abort(), DEFAULT_LOCAL_DAEMON_HEALTH_TIMEOUT_MS);
89568
+ const res = await fetch(`http://127.0.0.1:${DEFAULT_DAEMON_PORT}/health`, { signal: controller.signal });
89441
89569
  clearTimeout(timer);
89442
89570
  if (res.ok) {
89443
89571
  const data = await res.json();
@@ -89613,6 +89741,7 @@ function registerSetupCommands(program2, providerLoader) {
89613
89741
 
89614
89742
  // src/cli/daemon-commands.ts
89615
89743
  init_source();
89744
+ init_src();
89616
89745
 
89617
89746
  // src/cli/runtime-tools.ts
89618
89747
  var fs24 = __toESM(require("fs"));
@@ -89776,6 +89905,11 @@ function formatDebugTraceEntryLine(entry) {
89776
89905
  }
89777
89906
 
89778
89907
  // src/cli/daemon-commands.ts
89908
+ var DEFAULT_LOCAL_DAEMON_HEALTH_TIMEOUT_MS2 = 1500;
89909
+ var DEFAULT_TRACE_FOLLOW_INTERVAL_MS = 1500;
89910
+ var DEFAULT_DAEMON_PORT_TEXT = String(DEFAULT_DAEMON_PORT);
89911
+ var DEV_SERVER_PORT2 = 19280;
89912
+ var DEV_SERVER_BASE_URL = `http://127.0.0.1:${DEV_SERVER_PORT2}`;
89779
89913
  function hideCommand(command) {
89780
89914
  if (typeof command.hideHelp === "function") {
89781
89915
  command.hideHelp();
@@ -89785,7 +89919,7 @@ function hideCommand(command) {
89785
89919
  }
89786
89920
  async function fetchLocalDaemonHealth(port) {
89787
89921
  const controller = new AbortController();
89788
- const timer = setTimeout(() => controller.abort(), 1500);
89922
+ const timer = setTimeout(() => controller.abort(), DEFAULT_LOCAL_DAEMON_HEALTH_TIMEOUT_MS2);
89789
89923
  try {
89790
89924
  const res = await fetch(`http://127.0.0.1:${port}/health`, { signal: controller.signal });
89791
89925
  if (!res.ok) return null;
@@ -89977,9 +90111,9 @@ async function printRuntimeGroups(records, options) {
89977
90111
  }
89978
90112
  }
89979
90113
  async function handleTraceCommand(options) {
89980
- const port = parseInt(String(options.port ?? "19222"), 10) || 19222;
90114
+ const port = parseInt(String(options.port ?? DEFAULT_DAEMON_PORT_TEXT), 10) || DEFAULT_DAEMON_PORT;
89981
90115
  const count = Math.max(1, Math.min(500, parseInt(String(options.count ?? "40"), 10) || 40));
89982
- const intervalMs = Math.max(250, Math.min(3e4, parseInt(String(options.interval ?? "1500"), 10) || 1500));
90116
+ const intervalMs = Math.max(250, Math.min(3e4, parseInt(String(options.interval ?? String(DEFAULT_TRACE_FOLLOW_INTERVAL_MS)), 10) || DEFAULT_TRACE_FOLLOW_INTERVAL_MS));
89983
90117
  const baseArgs = {
89984
90118
  count,
89985
90119
  category: options.category,
@@ -90083,11 +90217,11 @@ async function handleTraceCommand(options) {
90083
90217
  }
90084
90218
  }
90085
90219
  function registerDaemonCommands(program2, pkgVersion3) {
90086
- program2.command("daemon").description("\u{1F680} Start ADHDev Daemon \u2014 unified hub for IDE monitoring, agent management, and remote control").option("-p, --port <port>", "Local WS server port", "19222").option("--server <url>", "Override server URL for testing").option("--dev", "Enable Dev Mode \u2014 HTTP API on :19280 for script debugging + structured trace collection").option("--log-level <level>", "Console log level (debug|info|warn|error)").option("--trace", "Enable structured debug trace collection").option("--trace-content", "Include richer content snapshots in debug traces").option("--trace-buffer-size <count>", "Structured trace ring buffer size").action(async (options) => {
90220
+ program2.command("daemon").description("\u{1F680} Start ADHDev Daemon \u2014 unified hub for IDE monitoring, agent management, and remote control").option("-p, --port <port>", "Local WS server port", DEFAULT_DAEMON_PORT_TEXT).option("--server <url>", "Override server URL for testing").option("--dev", "Enable Dev Mode \u2014 HTTP API on :19280 for script debugging + structured trace collection").option("--log-level <level>", "Console log level (debug|info|warn|error)").option("--trace", "Enable structured debug trace collection").option("--trace-content", "Include richer content snapshots in debug traces").option("--trace-buffer-size <count>", "Structured trace ring buffer size").action(async (options) => {
90087
90221
  const { AdhdevDaemon: AdhdevDaemon2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
90088
90222
  const daemon = new AdhdevDaemon2();
90089
90223
  await daemon.start({
90090
- localPort: parseInt(options.port) || 19222,
90224
+ localPort: parseInt(options.port) || DEFAULT_DAEMON_PORT,
90091
90225
  serverUrl: options.server,
90092
90226
  foreground: true,
90093
90227
  dev: options.dev || false,
@@ -90097,7 +90231,7 @@ function registerDaemonCommands(program2, pkgVersion3) {
90097
90231
  traceBufferSize: options.traceBufferSize ? parseInt(options.traceBufferSize, 10) || void 0 : void 0
90098
90232
  });
90099
90233
  });
90100
- program2.command("trace").description("Inspect structured daemon trace from the running local daemon (for example: --category session_host)").option("-p, --port <port>", "Local daemon IPC port", "19222").option("--category <category>", "Filter by trace category (for example: session_host)").option("--interaction <id>", "Filter by interaction id").option("--count <count>", "Maximum number of trace entries to fetch", "40").option("--follow", "Keep polling and print new trace entries as they arrive").option("--interval <ms>", "Polling interval for --follow mode", "1500").option("--json", "Print raw trace JSON output").action(async (options) => {
90234
+ program2.command("trace").description("Inspect structured daemon trace from the running local daemon (for example: --category session_host)").option("-p, --port <port>", "Local daemon IPC port", DEFAULT_DAEMON_PORT_TEXT).option("--category <category>", "Filter by trace category (for example: session_host)").option("--interaction <id>", "Filter by interaction id").option("--count <count>", "Maximum number of trace entries to fetch", "40").option("--follow", "Keep polling and print new trace entries as they arrive").option("--interval <ms>", "Polling interval for --follow mode", String(DEFAULT_TRACE_FOLLOW_INTERVAL_MS)).option("--json", "Print raw trace JSON output").action(async (options) => {
90101
90235
  try {
90102
90236
  await handleTraceCommand(options);
90103
90237
  } catch (error48) {
@@ -90177,11 +90311,11 @@ function registerDaemonCommands(program2, pkgVersion3) {
90177
90311
  console.log(source_default.gray(` Set with: adhdev daemon:api ${enabled ? "disable" : "enable"}
90178
90312
  `));
90179
90313
  }));
90180
- hideCommand(program2.command("daemon:status").description("Check ADHDev Daemon status").option("-p, --port <port>", "Local WS server port", "19222").action(async (options) => {
90314
+ hideCommand(program2.command("daemon:status").description("Check ADHDev Daemon status").option("-p, --port <port>", "Local WS server port", DEFAULT_DAEMON_PORT_TEXT).action(async (options) => {
90181
90315
  const { isDaemonRunning: isDaemonRunning2, getDaemonPid: getDaemonPid2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
90182
90316
  const { getCurrentDaemonLogPath: getCurrentDaemonLogPath2 } = await Promise.resolve().then(() => (init_src(), src_exports));
90183
90317
  const { probeSessionHostStatus: probeSessionHostStatus2 } = await Promise.resolve().then(() => (init_session_host(), session_host_exports));
90184
- const port = parseInt(options.port, 10) || 19222;
90318
+ const port = parseInt(options.port, 10) || DEFAULT_DAEMON_PORT;
90185
90319
  const { loadConfig: loadConfig2, ProviderLoader: ProviderLoader2 } = await Promise.resolve().then(() => (init_src(), src_exports));
90186
90320
  const config2 = loadConfig2();
90187
90321
  const providerLoader = new ProviderLoader2({
@@ -90254,8 +90388,8 @@ function registerDaemonCommands(program2, pkgVersion3) {
90254
90388
  }
90255
90389
  try {
90256
90390
  const controller = new AbortController();
90257
- const timer = setTimeout(() => controller.abort(), 1500);
90258
- const res = await fetch("http://127.0.0.1:19280/api/status", { signal: controller.signal });
90391
+ const timer = setTimeout(() => controller.abort(), DEFAULT_LOCAL_DAEMON_HEALTH_TIMEOUT_MS2);
90392
+ const res = await fetch(`${DEV_SERVER_BASE_URL}/api/status`, { signal: controller.signal });
90259
90393
  clearTimeout(timer);
90260
90394
  if (res.ok) {
90261
90395
  const data = await res.json();
@@ -90279,10 +90413,10 @@ function registerDaemonCommands(program2, pkgVersion3) {
90279
90413
  `));
90280
90414
  }
90281
90415
  }));
90282
- hideCommand(program2.command("daemon:session-host").description("Advanced operator diagnostics and control for the raw session-host surface").option("-p, --port <port>", "Local WS server port", "19222").option("--json", "Print raw JSON diagnostics/result").option("--limit <count>", "Number of diagnostics entries to include", "20").option("--session <sessionId>", "Target session ID").option("--restart", "Restart the target session").option("--resume", "Resume the target session").option("--stop", "Stop the target session").option("--signal <signal>", "Send a signal to the target session").option("--detach-client <clientId>", "Force-detach a client from the target session").option("--prune-duplicates", "Stop and remove duplicate hosted runtimes that share the same provider session binding").option("--acquire-write <clientId>", "Force-acquire write ownership for a client").option("--release-write <clientId>", "Release write ownership for a client").option("--owner-type <type>", "ownerType for --acquire-write (user|agent)", "user").action(async (options) => {
90416
+ hideCommand(program2.command("daemon:session-host").description("Advanced operator diagnostics and control for the raw session-host surface").option("-p, --port <port>", "Local WS server port", DEFAULT_DAEMON_PORT_TEXT).option("--json", "Print raw JSON diagnostics/result").option("--limit <count>", "Number of diagnostics entries to include", "20").option("--session <sessionId>", "Target session ID").option("--restart", "Restart the target session").option("--resume", "Resume the target session").option("--stop", "Stop the target session").option("--signal <signal>", "Send a signal to the target session").option("--detach-client <clientId>", "Force-detach a client from the target session").option("--prune-duplicates", "Stop and remove duplicate hosted runtimes that share the same provider session binding").option("--acquire-write <clientId>", "Force-acquire write ownership for a client").option("--release-write <clientId>", "Release write ownership for a client").option("--owner-type <type>", "ownerType for --acquire-write (user|agent)", "user").action(async (options) => {
90283
90417
  const sessionId = typeof options.session === "string" ? options.session.trim() : "";
90284
90418
  const limit = Math.max(1, Math.min(200, parseInt(options.limit, 10) || 20));
90285
- const port = parseInt(options.port, 10) || 19222;
90419
+ const port = parseInt(options.port, 10) || DEFAULT_DAEMON_PORT;
90286
90420
  const requireSessionId = () => {
90287
90421
  if (!sessionId) {
90288
90422
  throw new Error("--session is required for this action");
@@ -90601,9 +90735,9 @@ function registerDaemonCommands(program2, pkgVersion3) {
90601
90735
  process.exit(1);
90602
90736
  }
90603
90737
  });
90604
- hideCommand(program2.command("daemon:stop").description("Stop ADHDev Daemon").option("-p, --port <port>", "Local WS server port", "19222").action(async (options) => {
90738
+ hideCommand(program2.command("daemon:stop").description("Stop ADHDev Daemon").option("-p, --port <port>", "Local WS server port", DEFAULT_DAEMON_PORT_TEXT).action(async (options) => {
90605
90739
  const { stopDaemon: stopDaemon2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
90606
- const port = parseInt(options.port, 10) || 19222;
90740
+ const port = parseInt(options.port, 10) || DEFAULT_DAEMON_PORT;
90607
90741
  if (stopDaemon2({ port })) {
90608
90742
  console.log(source_default.green(`
90609
90743
  \u2713 ADHDev Daemon stopped.
@@ -90614,19 +90748,19 @@ function registerDaemonCommands(program2, pkgVersion3) {
90614
90748
  `));
90615
90749
  }
90616
90750
  }));
90617
- hideCommand(program2.command("daemon:restart").description("Restart ADHDev Daemon (stop \u2192 start)").option("-p, --port <port>", "Local WS server port", "19222").option("--server <url>", "Override server URL").option("--dev", "Enable Dev Mode").action(async (options) => {
90751
+ hideCommand(program2.command("daemon:restart").description("Restart ADHDev Daemon (stop \u2192 start)").option("-p, --port <port>", "Local WS server port", DEFAULT_DAEMON_PORT_TEXT).option("--server <url>", "Override server URL").option("--dev", "Enable Dev Mode").action(async (options) => {
90618
90752
  const { stopDaemon: stopDaemon2, isDaemonRunning: isDaemonRunning2 } = await Promise.resolve().then(() => (init_adhdev_daemon(), adhdev_daemon_exports));
90619
90753
  const { stopManagedSessionHostProcess: stopManagedSessionHostProcess2 } = await Promise.resolve().then(() => (init_session_host(), session_host_exports));
90620
90754
  const { spawn: spawn6 } = await import("child_process");
90621
- if (isDaemonRunning2({ port: parseInt(options.port, 10) || 19222 })) {
90755
+ if (isDaemonRunning2({ port: parseInt(options.port, 10) || DEFAULT_DAEMON_PORT })) {
90622
90756
  console.log(source_default.yellow("\n Stopping existing daemon..."));
90623
- stopDaemon2({ port: parseInt(options.port, 10) || 19222 });
90757
+ stopDaemon2({ port: parseInt(options.port, 10) || DEFAULT_DAEMON_PORT });
90624
90758
  await new Promise((r) => setTimeout(r, 2e3));
90625
90759
  }
90626
90760
  stopManagedSessionHostProcess2();
90627
90761
  await new Promise((r) => setTimeout(r, 500));
90628
90762
  console.log(source_default.cyan(" Starting new daemon..."));
90629
- const args = ["daemon", "-p", options.port || "19222"];
90763
+ const args = ["daemon", "-p", options.port || DEFAULT_DAEMON_PORT_TEXT];
90630
90764
  if (options.server) args.push("--server", options.server);
90631
90765
  if (options.dev) args.push("--dev");
90632
90766
  const child = spawn6(process.execPath, [process.argv[1], ...args], {
@@ -90637,7 +90771,7 @@ function registerDaemonCommands(program2, pkgVersion3) {
90637
90771
  });
90638
90772
  child.unref();
90639
90773
  await new Promise((r) => setTimeout(r, 3e3));
90640
- if (isDaemonRunning2({ port: parseInt(options.port, 10) || 19222 })) {
90774
+ if (isDaemonRunning2({ port: parseInt(options.port, 10) || DEFAULT_DAEMON_PORT })) {
90641
90775
  console.log(source_default.green(` \u2713 ADHDev Daemon restarted (PID: ${child.pid})
90642
90776
  `));
90643
90777
  } else {
@@ -90711,7 +90845,7 @@ function registerDaemonCommands(program2, pkgVersion3) {
90711
90845
  packageName: "adhdev",
90712
90846
  targetVersion: latest,
90713
90847
  parentPid: process.pid,
90714
- restartArgv: daemonWasRunning ? [process.argv[1], "daemon", "-p", "19222"] : [],
90848
+ restartArgv: daemonWasRunning ? [process.argv[1], "daemon", "-p", DEFAULT_DAEMON_PORT_TEXT] : [],
90715
90849
  cwd: process.cwd()
90716
90850
  });
90717
90851
  if (daemonWasRunning) {
@@ -90732,7 +90866,7 @@ function registerDaemonCommands(program2, pkgVersion3) {
90732
90866
  await new Promise((r) => setTimeout(r, 2e3));
90733
90867
  stopManagedSessionHostProcess2();
90734
90868
  await new Promise((r) => setTimeout(r, 500));
90735
- const child = spawn6(process.execPath, [process.argv[1], "daemon", "-p", "19222"], {
90869
+ const child = spawn6(process.execPath, [process.argv[1], "daemon", "-p", DEFAULT_DAEMON_PORT_TEXT], {
90736
90870
  detached: true,
90737
90871
  stdio: "ignore",
90738
90872
  windowsHide: true,
@@ -91272,6 +91406,7 @@ function registerDoctorCommands(program2, pkgVersion3) {
91272
91406
  init_source();
91273
91407
  var path33 = __toESM(require("path"));
91274
91408
  init_cdp_utils();
91409
+ var DEV_SERVER_PORT3 = 19280;
91275
91410
  var IDE_AUTO_FIX_FUNCTIONS = [
91276
91411
  "openPanel",
91277
91412
  "sendMessage",
@@ -91504,7 +91639,7 @@ function registerProviderCommands(program2) {
91504
91639
  const result = await new Promise((resolve17, reject) => {
91505
91640
  const req = http3.request({
91506
91641
  hostname: "127.0.0.1",
91507
- port: 19280,
91642
+ port: DEV_SERVER_PORT3,
91508
91643
  path: "/api/providers/reload",
91509
91644
  method: "POST",
91510
91645
  headers: { "Content-Type": "application/json", "Content-Length": "2" }
@@ -91641,7 +91776,7 @@ function registerProviderCommands(program2) {
91641
91776
  const postData = JSON.stringify({ type, name, category, location, cdpPorts, osPaths, processNames });
91642
91777
  const req = http3.request({
91643
91778
  hostname: "127.0.0.1",
91644
- port: 19280,
91779
+ port: DEV_SERVER_PORT3,
91645
91780
  path: "/api/scaffold",
91646
91781
  method: "POST",
91647
91782
  headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(postData) }
@@ -91849,7 +91984,7 @@ function registerProviderCommands(program2) {
91849
91984
  const startResult = await new Promise((resolve17, reject) => {
91850
91985
  const req = http3.request({
91851
91986
  hostname: "127.0.0.1",
91852
- port: 19280,
91987
+ port: DEV_SERVER_PORT3,
91853
91988
  path: `/api/providers/${type}/auto-implement`,
91854
91989
  method: "POST",
91855
91990
  headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(postData) }
@@ -91895,7 +92030,7 @@ function registerProviderCommands(program2) {
91895
92030
  `);
91896
92031
  console.log(source_default.gray(` Agent logs: ${logFile}`));
91897
92032
  await new Promise((resolve17, reject) => {
91898
- http3.get(`http://127.0.0.1:19280${startResult.sseUrl}`, (res) => {
92033
+ http3.get(`http://127.0.0.1:${DEV_SERVER_PORT3}${startResult.sseUrl}`, (res) => {
91899
92034
  let buffer = "";
91900
92035
  res.on("data", (chunk) => {
91901
92036
  const rawStr = chunk.toString();
@@ -92004,7 +92139,7 @@ function registerProviderCommands(program2) {
92004
92139
  const result = await new Promise((resolve17, reject) => {
92005
92140
  const req = http3.request({
92006
92141
  hostname: "127.0.0.1",
92007
- port: 19280,
92142
+ port: DEV_SERVER_PORT3,
92008
92143
  path: `/api/providers/${type}/script`,
92009
92144
  method: "POST",
92010
92145
  headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(postData) }
@@ -92052,7 +92187,7 @@ function registerProviderCommands(program2) {
92052
92187
  try {
92053
92188
  const http3 = await import("http");
92054
92189
  const result = await new Promise((resolve17, reject) => {
92055
- http3.get(`http://127.0.0.1:19280/api/providers/${type}/source`, (res) => {
92190
+ http3.get(`http://127.0.0.1:${DEV_SERVER_PORT3}/api/providers/${type}/source`, (res) => {
92056
92191
  let data = "";
92057
92192
  res.on("data", (c) => data += c);
92058
92193
  res.on("end", () => {
@@ -92110,7 +92245,7 @@ function registerProviderCommands(program2) {
92110
92245
  const result = await new Promise((resolve17, reject) => {
92111
92246
  const req = http3.request({
92112
92247
  hostname: "127.0.0.1",
92113
- port: 19280,
92248
+ port: DEV_SERVER_PORT3,
92114
92249
  path: `/api/providers/${type}/script`,
92115
92250
  method: "POST",
92116
92251
  headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(postData) }
@@ -92416,6 +92551,7 @@ var import_node_os6 = __toESM(require("os"));
92416
92551
  var import_node_child_process6 = require("child_process");
92417
92552
  init_source();
92418
92553
  init_src();
92554
+ var DEFAULT_LOCAL_DAEMON_HEALTH_TIMEOUT_MS3 = 1500;
92419
92555
  var LAUNCHD_LABEL = "dev.adhf.daemon";
92420
92556
  var ADHDEV_DIR = import_node_path4.default.join(import_node_os6.default.homedir(), ".adhdev");
92421
92557
  var LOG_OUT = import_node_path4.default.join(ADHDEV_DIR, "daemon-launchd.out");
@@ -92439,7 +92575,7 @@ function ensureDir(dir) {
92439
92575
  }
92440
92576
  async function fetchHealth() {
92441
92577
  const controller = new AbortController();
92442
- const timer = setTimeout(() => controller.abort(), 1500);
92578
+ const timer = setTimeout(() => controller.abort(), DEFAULT_LOCAL_DAEMON_HEALTH_TIMEOUT_MS3);
92443
92579
  try {
92444
92580
  const res = await fetch(`http://127.0.0.1:${DEFAULT_DAEMON_PORT}/health`, { signal: controller.signal });
92445
92581
  if (!res.ok) return null;