@adhdev/daemon-standalone 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.js CHANGED
@@ -9165,6 +9165,7 @@ var require_dist = __commonJS({
9165
9165
  DEFAULT_SESSION_HOST_COLS: () => DEFAULT_SESSION_HOST_COLS,
9166
9166
  DEFAULT_SESSION_HOST_ROWS: () => DEFAULT_SESSION_HOST_ROWS,
9167
9167
  DEFAULT_SESSION_RING_BUFFER_MAX_BYTES: () => DEFAULT_SESSION_RING_BUFFER_MAX_BYTES2,
9168
+ SESSION_HOST_SUPPORTED_REQUEST_TYPES: () => SESSION_HOST_SUPPORTED_REQUEST_TYPES,
9168
9169
  SessionHostClient: () => SessionHostClient2,
9169
9170
  SessionHostRegistry: () => SessionHostRegistry,
9170
9171
  SessionRingBuffer: () => SessionRingBuffer,
@@ -9189,6 +9190,27 @@ var require_dist = __commonJS({
9189
9190
  writeEnvelope: () => writeEnvelope
9190
9191
  });
9191
9192
  module2.exports = __toCommonJS2(index_exports);
9193
+ var SESSION_HOST_SUPPORTED_REQUEST_TYPES = [
9194
+ "create_session",
9195
+ "attach_session",
9196
+ "detach_session",
9197
+ "send_input",
9198
+ "resize_session",
9199
+ "stop_session",
9200
+ "delete_session",
9201
+ "resume_session",
9202
+ "acquire_write",
9203
+ "release_write",
9204
+ "get_snapshot",
9205
+ "clear_session_buffer",
9206
+ "update_session_meta",
9207
+ "get_host_diagnostics",
9208
+ "force_detach_client",
9209
+ "send_signal",
9210
+ "restart_session",
9211
+ "prune_duplicate_sessions",
9212
+ "list_sessions"
9213
+ ];
9192
9214
  var DEFAULT_SESSION_RING_BUFFER_MAX_BYTES2 = 4 * 1024 * 1024;
9193
9215
  var SessionRingBuffer = class {
9194
9216
  maxBytes;
@@ -42986,6 +43008,7 @@ ${effect.notification.body || ""}`.trim();
42986
43008
  }
42987
43009
  var RECENT_SEND_WINDOW_MS = 1200;
42988
43010
  var READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
43011
+ var HERMES_CLI_STARTING_SEND_SETTLE_MS = 2e3;
42989
43012
  var recentSendByTarget = /* @__PURE__ */ new Map();
42990
43013
  function getCurrentProviderType(h, fallback = "") {
42991
43014
  return h.currentSession?.providerType || h.currentProviderType || fallback;
@@ -43038,6 +43061,16 @@ ${effect.notification.body || ""}`.trim();
43038
43061
  function getSendChatInputEnvelope(args) {
43039
43062
  return normalizeInputEnvelope(args?.input ? { input: args.input } : args);
43040
43063
  }
43064
+ function sleep(ms2) {
43065
+ return new Promise((resolve16) => setTimeout(resolve16, ms2));
43066
+ }
43067
+ async function waitOnceForFreshHermesCliStart(adapter, log) {
43068
+ if (adapter.cliType !== "hermes-cli") return;
43069
+ const status = typeof adapter.getStatus === "function" ? adapter.getStatus()?.status : void 0;
43070
+ if (status !== "starting") return;
43071
+ log(`Hermes CLI is still starting; waiting ${HERMES_CLI_STARTING_SEND_SETTLE_MS}ms before first send`);
43072
+ await sleep(HERMES_CLI_STARTING_SEND_SETTLE_MS);
43073
+ }
43041
43074
  function getHistorySessionId(h, args) {
43042
43075
  const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
43043
43076
  if (explicit) return explicit;
@@ -43897,6 +43930,7 @@ ${effect.notification.body || ""}`.trim();
43897
43930
  try {
43898
43931
  assertTextOnlyInput(provider, input);
43899
43932
  if (!text) return { success: false, error: "text required for PTY send" };
43933
+ await waitOnceForFreshHermesCliStart(adapter, _log);
43900
43934
  await adapter.sendMessage(text);
43901
43935
  return _logSendSuccess(`${transport}-adapter`, adapter.cliType);
43902
43936
  } catch (e) {
@@ -46802,8 +46836,6 @@ ${effect.notification.body || ""}`.trim();
46802
46836
  const aTime = getTime(a.message);
46803
46837
  const bTime = getTime(b2.message);
46804
46838
  if (aTime && bTime && aTime !== bTime) return aTime - bTime;
46805
- if (aTime && !bTime && a.source === "runtime" && b2.source === "parsed") return -1;
46806
- if (!aTime && bTime && a.source === "parsed" && b2.source === "runtime") return 1;
46807
46839
  return a.index - b2.index;
46808
46840
  }).map((entry) => entry.message));
46809
46841
  }
@@ -57088,7 +57120,7 @@ async (params) => {
57088
57120
  if (!adapter) return null;
57089
57121
  return { target, instance, adapter };
57090
57122
  }
57091
- function sleep(ms2) {
57123
+ function sleep2(ms2) {
57092
57124
  return new Promise((resolve16) => setTimeout(resolve16, ms2));
57093
57125
  }
57094
57126
  async function waitForCliReady(ctx, type, instanceId, timeoutMs) {
@@ -57105,7 +57137,7 @@ async (params) => {
57105
57137
  return bundle;
57106
57138
  }
57107
57139
  }
57108
- await sleep(100);
57140
+ await sleep2(100);
57109
57141
  }
57110
57142
  return getCliTargetBundle(ctx, type, instanceId);
57111
57143
  }
@@ -57161,7 +57193,7 @@ async (params) => {
57161
57193
  const message = String(lastLaunchError.message || "");
57162
57194
  const retryable = /ECONNREFUSED|session-host|Session host/i.test(message);
57163
57195
  if (!retryable || attempt === 2) break;
57164
- await sleep(1e3);
57196
+ await sleep2(1e3);
57165
57197
  }
57166
57198
  }
57167
57199
  if (!launched) {
@@ -57224,16 +57256,16 @@ async (params) => {
57224
57256
  const modal = debug?.activeModal || trace?.activeModal || null;
57225
57257
  noteStatus(status);
57226
57258
  if (resolveActiveModalIfNeeded(status, modal)) {
57227
- await sleep(150);
57259
+ await sleep2(150);
57228
57260
  continue;
57229
57261
  }
57230
57262
  const startupParseGate = !!debug?.startupParseGate;
57231
57263
  if (status === "idle" && !startupParseGate) break;
57232
- await sleep(150);
57264
+ await sleep2(150);
57233
57265
  }
57234
57266
  ctx.instanceManager.sendEvent(bundle.target.instanceId, "send_message", { text });
57235
57267
  while (Date.now() - startAt < Math.max(1e3, timeoutMs)) {
57236
- await sleep(150);
57268
+ await sleep2(150);
57237
57269
  bundle = getCliTargetBundle(ctx, type, bundle.target.instanceId);
57238
57270
  if (!bundle) {
57239
57271
  throw new Error("CLI instance disappeared during exercise");
@@ -61109,29 +61141,58 @@ data: ${JSON.stringify(msg.data)}
61109
61141
  var import_session_host_core4 = require_dist();
61110
61142
  var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS2;
61111
61143
  var STARTUP_POLL_MS = 200;
61112
- async function canConnect(endpoint) {
61144
+ var SessionHostCompatibilityError = class extends Error {
61145
+ constructor(message) {
61146
+ super(message);
61147
+ this.name = "SessionHostCompatibilityError";
61148
+ }
61149
+ };
61150
+ function getMissingRequestTypes(diagnostics, requiredRequestTypes) {
61151
+ const supported = new Set(diagnostics?.supportedRequestTypes || []);
61152
+ return requiredRequestTypes.filter((requestType) => !supported.has(requestType));
61153
+ }
61154
+ async function assertRequiredRequestTypes(client, requiredRequestTypes) {
61155
+ if (requiredRequestTypes.length === 0) return;
61156
+ const response = await client.request({
61157
+ type: "get_host_diagnostics",
61158
+ payload: { includeSessions: false }
61159
+ });
61160
+ const missing = getMissingRequestTypes(response.success ? response.result : void 0, requiredRequestTypes);
61161
+ if (missing.length > 0) {
61162
+ const detail = response.success ? "" : ` (${response.error || "capability probe failed"})`;
61163
+ throw new SessionHostCompatibilityError(
61164
+ `Session host does not support required request types: ${missing.join(", ")}${detail}`
61165
+ );
61166
+ }
61167
+ }
61168
+ async function canConnect(endpoint, requiredRequestTypes = []) {
61113
61169
  const client = new import_session_host_core4.SessionHostClient({ endpoint });
61114
61170
  try {
61115
61171
  await client.connect();
61116
- await client.close();
61172
+ await assertRequiredRequestTypes(client, requiredRequestTypes);
61117
61173
  return true;
61118
- } catch {
61174
+ } catch (error48) {
61175
+ if (error48 instanceof SessionHostCompatibilityError) throw error48;
61119
61176
  return false;
61177
+ } finally {
61178
+ await client.close().catch(() => {
61179
+ });
61120
61180
  }
61121
61181
  }
61122
- async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
61182
+ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS, requiredRequestTypes = []) {
61123
61183
  const deadline = Date.now() + timeoutMs;
61124
61184
  while (Date.now() < deadline) {
61125
- if (await canConnect(endpoint)) return;
61185
+ if (await canConnect(endpoint, requiredRequestTypes)) return;
61126
61186
  await new Promise((resolve16) => setTimeout(resolve16, STARTUP_POLL_MS));
61127
61187
  }
61128
61188
  throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
61129
61189
  }
61130
61190
  async function ensureSessionHostReady2(options) {
61131
61191
  const endpoint = (0, import_session_host_core4.getDefaultSessionHostEndpoint)(options.appName || "adhdev");
61132
- if (await canConnect(endpoint)) return endpoint;
61192
+ const requiredRequestTypes = options.requiredRequestTypes || [];
61193
+ if (await canConnect(endpoint, requiredRequestTypes)) return endpoint;
61133
61194
  options.spawnHost();
61134
- await waitForReady(endpoint, options.timeoutMs);
61195
+ await waitForReady(endpoint, options.timeoutMs, requiredRequestTypes);
61135
61196
  return endpoint;
61136
61197
  }
61137
61198
  async function listHostedCliRuntimes2(endpoint) {
@@ -61851,14 +61912,16 @@ async function ensureSessionHostReady() {
61851
61912
  return await (0, import_daemon_core.ensureSessionHostReady)({
61852
61913
  appName: SESSION_HOST_APP_NAME,
61853
61914
  spawnHost,
61854
- timeoutMs: SESSION_HOST_START_TIMEOUT_MS
61915
+ timeoutMs: SESSION_HOST_START_TIMEOUT_MS,
61916
+ requiredRequestTypes: ["delete_session"]
61855
61917
  });
61856
61918
  } catch (error48) {
61857
61919
  stopSessionHost();
61858
61920
  return (0, import_daemon_core.ensureSessionHostReady)({
61859
61921
  appName: SESSION_HOST_APP_NAME,
61860
61922
  spawnHost,
61861
- timeoutMs: SESSION_HOST_START_TIMEOUT_MS
61923
+ timeoutMs: SESSION_HOST_START_TIMEOUT_MS,
61924
+ requiredRequestTypes: ["delete_session"]
61862
61925
  }).catch((retryError) => {
61863
61926
  const initialMessage = error48 instanceof Error ? error48.message : String(error48);
61864
61927
  const retryMessage = retryError instanceof Error ? retryError.message : String(retryError);