@adhdev/daemon-core 0.9.76-rc.50 → 0.9.76-rc.52

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.mjs CHANGED
@@ -11718,6 +11718,7 @@ function buildSessionModalDeliverySignature(payload) {
11718
11718
  // src/commands/chat-commands.ts
11719
11719
  var RECENT_SEND_WINDOW_MS = 1200;
11720
11720
  var READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
11721
+ var HERMES_CLI_STARTING_SEND_SETTLE_MS = 2e3;
11721
11722
  var recentSendByTarget = /* @__PURE__ */ new Map();
11722
11723
  function getCurrentProviderType(h, fallback = "") {
11723
11724
  return h.currentSession?.providerType || h.currentProviderType || fallback;
@@ -11770,6 +11771,16 @@ function buildSendInputSignature(input) {
11770
11771
  function getSendChatInputEnvelope(args) {
11771
11772
  return normalizeInputEnvelope(args?.input ? { input: args.input } : args);
11772
11773
  }
11774
+ function sleep(ms) {
11775
+ return new Promise((resolve16) => setTimeout(resolve16, ms));
11776
+ }
11777
+ async function waitOnceForFreshHermesCliStart(adapter, log) {
11778
+ if (adapter.cliType !== "hermes-cli") return;
11779
+ const status = typeof adapter.getStatus === "function" ? adapter.getStatus()?.status : void 0;
11780
+ if (status !== "starting") return;
11781
+ log(`Hermes CLI is still starting; waiting ${HERMES_CLI_STARTING_SEND_SETTLE_MS}ms before first send`);
11782
+ await sleep(HERMES_CLI_STARTING_SEND_SETTLE_MS);
11783
+ }
11773
11784
  function getHistorySessionId(h, args) {
11774
11785
  const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
11775
11786
  if (explicit) return explicit;
@@ -12629,6 +12640,7 @@ async function handleSendChat(h, args) {
12629
12640
  try {
12630
12641
  assertTextOnlyInput(provider, input);
12631
12642
  if (!text) return { success: false, error: "text required for PTY send" };
12643
+ await waitOnceForFreshHermesCliStart(adapter, _log);
12632
12644
  await adapter.sendMessage(text);
12633
12645
  return _logSendSuccess(`${transport}-adapter`, adapter.cliType);
12634
12646
  } catch (e) {
@@ -15556,8 +15568,6 @@ ${effect.notification.body || ""}`.trim();
15556
15568
  const aTime = getTime(a.message);
15557
15569
  const bTime = getTime(b.message);
15558
15570
  if (aTime && bTime && aTime !== bTime) return aTime - bTime;
15559
- if (aTime && !bTime && a.source === "runtime" && b.source === "parsed") return -1;
15560
- if (!aTime && bTime && a.source === "parsed" && b.source === "runtime") return 1;
15561
15571
  return a.index - b.index;
15562
15572
  }).map((entry) => entry.message));
15563
15573
  }
@@ -25915,7 +25925,7 @@ function getCliTargetBundle(ctx, type, instanceId) {
25915
25925
  if (!adapter) return null;
25916
25926
  return { target, instance, adapter };
25917
25927
  }
25918
- function sleep(ms) {
25928
+ function sleep2(ms) {
25919
25929
  return new Promise((resolve16) => setTimeout(resolve16, ms));
25920
25930
  }
25921
25931
  async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
@@ -25932,7 +25942,7 @@ async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
25932
25942
  return bundle;
25933
25943
  }
25934
25944
  }
25935
- await sleep(100);
25945
+ await sleep2(100);
25936
25946
  }
25937
25947
  return getCliTargetBundle(ctx, type, instanceId);
25938
25948
  }
@@ -25988,7 +25998,7 @@ async function runCliExerciseInternal(ctx, body) {
25988
25998
  const message = String(lastLaunchError.message || "");
25989
25999
  const retryable = /ECONNREFUSED|session-host|Session host/i.test(message);
25990
26000
  if (!retryable || attempt === 2) break;
25991
- await sleep(1e3);
26001
+ await sleep2(1e3);
25992
26002
  }
25993
26003
  }
25994
26004
  if (!launched) {
@@ -26051,16 +26061,16 @@ async function runCliExerciseInternal(ctx, body) {
26051
26061
  const modal = debug?.activeModal || trace?.activeModal || null;
26052
26062
  noteStatus(status);
26053
26063
  if (resolveActiveModalIfNeeded(status, modal)) {
26054
- await sleep(150);
26064
+ await sleep2(150);
26055
26065
  continue;
26056
26066
  }
26057
26067
  const startupParseGate = !!debug?.startupParseGate;
26058
26068
  if (status === "idle" && !startupParseGate) break;
26059
- await sleep(150);
26069
+ await sleep2(150);
26060
26070
  }
26061
26071
  ctx.instanceManager.sendEvent(bundle.target.instanceId, "send_message", { text });
26062
26072
  while (Date.now() - startAt < Math.max(1e3, timeoutMs)) {
26063
- await sleep(150);
26073
+ await sleep2(150);
26064
26074
  bundle = getCliTargetBundle(ctx, type, bundle.target.instanceId);
26065
26075
  if (!bundle) {
26066
26076
  throw new Error("CLI instance disappeared during exercise");
@@ -29953,29 +29963,58 @@ import {
29953
29963
  } from "@adhdev/session-host-core";
29954
29964
  var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
29955
29965
  var STARTUP_POLL_MS = 200;
29956
- async function canConnect(endpoint) {
29966
+ var SessionHostCompatibilityError = class extends Error {
29967
+ constructor(message) {
29968
+ super(message);
29969
+ this.name = "SessionHostCompatibilityError";
29970
+ }
29971
+ };
29972
+ function getMissingRequestTypes(diagnostics, requiredRequestTypes) {
29973
+ const supported = new Set(diagnostics?.supportedRequestTypes || []);
29974
+ return requiredRequestTypes.filter((requestType) => !supported.has(requestType));
29975
+ }
29976
+ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
29977
+ if (requiredRequestTypes.length === 0) return;
29978
+ const response = await client.request({
29979
+ type: "get_host_diagnostics",
29980
+ payload: { includeSessions: false }
29981
+ });
29982
+ const missing = getMissingRequestTypes(response.success ? response.result : void 0, requiredRequestTypes);
29983
+ if (missing.length > 0) {
29984
+ const detail = response.success ? "" : ` (${response.error || "capability probe failed"})`;
29985
+ throw new SessionHostCompatibilityError(
29986
+ `Session host does not support required request types: ${missing.join(", ")}${detail}`
29987
+ );
29988
+ }
29989
+ }
29990
+ async function canConnect(endpoint, requiredRequestTypes = []) {
29957
29991
  const client = new SessionHostClient2({ endpoint });
29958
29992
  try {
29959
29993
  await client.connect();
29960
- await client.close();
29994
+ await assertRequiredRequestTypes(client, requiredRequestTypes);
29961
29995
  return true;
29962
- } catch {
29996
+ } catch (error) {
29997
+ if (error instanceof SessionHostCompatibilityError) throw error;
29963
29998
  return false;
29999
+ } finally {
30000
+ await client.close().catch(() => {
30001
+ });
29964
30002
  }
29965
30003
  }
29966
- async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
30004
+ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRequestTypes = []) {
29967
30005
  const deadline = Date.now() + timeoutMs;
29968
30006
  while (Date.now() < deadline) {
29969
- if (await canConnect(endpoint)) return;
30007
+ if (await canConnect(endpoint, requiredRequestTypes)) return;
29970
30008
  await new Promise((resolve16) => setTimeout(resolve16, STARTUP_POLL_MS));
29971
30009
  }
29972
30010
  throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
29973
30011
  }
29974
30012
  async function ensureSessionHostReady(options) {
29975
30013
  const endpoint = getDefaultSessionHostEndpoint(options.appName || "adhdev");
29976
- if (await canConnect(endpoint)) return endpoint;
30014
+ const requiredRequestTypes = options.requiredRequestTypes || [];
30015
+ if (await canConnect(endpoint, requiredRequestTypes)) return endpoint;
29977
30016
  options.spawnHost();
29978
- await waitForReady(endpoint, options.timeoutMs);
30017
+ await waitForReady(endpoint, options.timeoutMs, requiredRequestTypes);
29979
30018
  return endpoint;
29980
30019
  }
29981
30020
  async function listHostedCliRuntimes(endpoint) {