@adhdev/daemon-core 0.9.82-rc.378 → 0.9.82-rc.379

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
@@ -311,10 +311,10 @@ function readInjected(value) {
311
311
  }
312
312
  function getDaemonBuildInfo() {
313
313
  if (cached) return cached;
314
- const commit = readInjected(true ? "3920b23e979544d74c4024a0ff18e5deab7b2932" : void 0) ?? "unknown";
315
- const commitShort = readInjected(true ? "3920b23e" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
- const version = readInjected(true ? "0.9.82-rc.378" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
- const builtAt = readInjected(true ? "2026-06-25T07:59:13.420Z" : void 0);
314
+ const commit = readInjected(true ? "7b74c2c74e315b3fa6eb9f18d694b79eeb561184" : void 0) ?? "unknown";
315
+ const commitShort = readInjected(true ? "7b74c2c7" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
316
+ const version = readInjected(true ? "0.9.82-rc.379" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
317
+ const builtAt = readInjected(true ? "2026-06-25T09:33:17.234Z" : void 0);
318
318
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
319
319
  return cached;
320
320
  }
@@ -10367,6 +10367,16 @@ function warnDispatchWarmupGetterMissingOnce(daemonId) {
10367
10367
  dispatchWarmupGetterMissingWarned.add(daemonId);
10368
10368
  LOG.warn("MeshQueue", `Mesh peer connection getter unavailable for ${String(daemonId).slice(0, 12)}; remote task-dispatch warmup deadline degraded to the combined connect+response window. Avoids a cold-open false-timeout but loses warm/cold precision \u2014 wire getMeshPeerConnectionStatus on this daemon.`);
10369
10369
  }
10370
+ async function waitForLocalSessionReady(components, sessionId) {
10371
+ const adapter = components.cliManager?.adapters?.get(sessionId);
10372
+ if (!adapter || typeof adapter.isReady !== "function") return;
10373
+ const deadline = Date.now() + LOCAL_LAUNCH_READY_TIMEOUT_MS;
10374
+ while (Date.now() < deadline) {
10375
+ if (adapter.isReady() || adapter.currentStatus === "idle") return;
10376
+ await new Promise((resolve24) => setTimeout(resolve24, LOCAL_LAUNCH_READY_POLL_MS));
10377
+ }
10378
+ LOG.warn("MeshQueue", `Auto-launched session ${sessionId} not interactive after ${LOCAL_LAUNCH_READY_TIMEOUT_MS}ms; dispatching anyway (adapter queue-until-ready will buffer)`);
10379
+ }
10370
10380
  function deliverTaskToSession(dispatchThunk, ctx, warmup) {
10371
10381
  const delivery = createSessionDelivery({
10372
10382
  meshId: ctx.meshId,
@@ -10963,6 +10973,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
10963
10973
  return false;
10964
10974
  }
10965
10975
  markAutoLaunch(meshId, task.id, { status: "completed", nodeId, providerType: resolved.providerType, sessionId });
10976
+ await waitForLocalSessionReady(components, sessionId);
10966
10977
  tryAssignQueueTask(components, meshId, nodeId, sessionId, resolved.providerType);
10967
10978
  return true;
10968
10979
  } catch (e) {
@@ -11184,7 +11195,7 @@ function runIdleMaintenanceThenAssignQueue(components, args) {
11184
11195
  });
11185
11196
  });
11186
11197
  }
11187
- var IDLE_AUTO_FAST_FORWARD_THROTTLE_MS, idleAutoFastForwardLastAttempt, DISPATCH_CONFIRM_TIMEOUT_MS, DISPATCH_CONNECT_TIMEOUT_MS, dispatchWarmupGetterMissingWarned, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS, AUTO_LAUNCH_AWAIT_CLAIM_MS, lastAutoLaunchLedgerKey, AUTO_LAUNCH_LEDGER_DEDUP_MAX;
11198
+ var IDLE_AUTO_FAST_FORWARD_THROTTLE_MS, idleAutoFastForwardLastAttempt, DISPATCH_CONFIRM_TIMEOUT_MS, DISPATCH_CONNECT_TIMEOUT_MS, dispatchWarmupGetterMissingWarned, LOCAL_LAUNCH_READY_TIMEOUT_MS, LOCAL_LAUNCH_READY_POLL_MS, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS, AUTO_LAUNCH_AWAIT_CLAIM_MS, lastAutoLaunchLedgerKey, AUTO_LAUNCH_LEDGER_DEDUP_MAX;
11188
11199
  var init_mesh_queue_assignment = __esm({
11189
11200
  "src/mesh/mesh-queue-assignment.ts"() {
11190
11201
  "use strict";
@@ -11209,6 +11220,8 @@ var init_mesh_queue_assignment = __esm({
11209
11220
  DISPATCH_CONFIRM_TIMEOUT_MS = 12e4;
11210
11221
  DISPATCH_CONNECT_TIMEOUT_MS = MESH_CONNECT_TIMEOUT_MS;
11211
11222
  dispatchWarmupGetterMissingWarned = /* @__PURE__ */ new Set();
11223
+ LOCAL_LAUNCH_READY_TIMEOUT_MS = 15e3;
11224
+ LOCAL_LAUNCH_READY_POLL_MS = 100;
11212
11225
  autoLaunchInProgress = /* @__PURE__ */ new Set();
11213
11226
  autoLaunchCooldownUntil = /* @__PURE__ */ new Map();
11214
11227
  AUTO_LAUNCH_COOLDOWN_MS = 5e3;
@@ -16991,6 +17004,34 @@ var init_pty_transport = __esm({
16991
17004
  }
16992
17005
  });
16993
17006
 
17007
+ // src/cli-adapters/pty-write-chunking.ts
17008
+ function chunkPreservingSurrogates(text, size) {
17009
+ const chunks = [];
17010
+ let offset = 0;
17011
+ while (offset < text.length) {
17012
+ let end = Math.min(text.length, offset + size);
17013
+ if (end < text.length) {
17014
+ const code = text.charCodeAt(end - 1);
17015
+ if (code >= 55296 && code <= 56319) end -= 1;
17016
+ }
17017
+ if (end <= offset) end = Math.min(text.length, offset + size);
17018
+ chunks.push(text.slice(offset, end));
17019
+ offset = end;
17020
+ }
17021
+ return chunks;
17022
+ }
17023
+ function shouldChunkWin32Write(length) {
17024
+ return length > WIN32_PTY_WRITE_CHUNK_CHARS;
17025
+ }
17026
+ var WIN32_PTY_WRITE_CHUNK_CHARS, WIN32_PTY_WRITE_CHUNK_GAP_MS;
17027
+ var init_pty_write_chunking = __esm({
17028
+ "src/cli-adapters/pty-write-chunking.ts"() {
17029
+ "use strict";
17030
+ WIN32_PTY_WRITE_CHUNK_CHARS = 1024;
17031
+ WIN32_PTY_WRITE_CHUNK_GAP_MS = 8;
17032
+ }
17033
+ });
17034
+
16994
17035
  // src/providers/sdk/v1/builders/cli/visible-region.ts
16995
17036
  function compile(re, flags) {
16996
17037
  try {
@@ -18941,6 +18982,7 @@ var init_provider_cli_adapter = __esm({
18941
18982
  init_debug_config();
18942
18983
  init_terminal_screen();
18943
18984
  init_pty_transport();
18985
+ init_pty_write_chunking();
18944
18986
  init_provider_cli_shared();
18945
18987
  init_cli_script_runner();
18946
18988
  init_cli_state_engine();
@@ -19419,6 +19461,7 @@ ${lastSnapshot}`;
19419
19461
  `[${this.cliType}] Startup settled (${trigger}, stableMs=${stableMs}, modal=${!!startupModal}) providerDir=${this.providerResolutionMeta.providerDir || "-"} scriptDir=${this.providerResolutionMeta.scriptDir || "-"} scriptsPath=${this.providerResolutionMeta.scriptsPath || "-"}`
19420
19462
  );
19421
19463
  this.onStatusChange?.();
19464
+ if (!startupModal) this.schedulePendingOutboundFlush();
19422
19465
  }
19423
19466
  scheduleStartupSettleCheck() {
19424
19467
  if (!this.startupParseGate) return;
@@ -19739,8 +19782,26 @@ ${lastSnapshot}`;
19739
19782
  }
19740
19783
  async writeToPty(data) {
19741
19784
  if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
19785
+ if (process.platform === "win32" && shouldChunkWin32Write(data.length)) {
19786
+ await this.writeWin32Chunked(data);
19787
+ return;
19788
+ }
19742
19789
  await this.ptyProcess.write(data);
19743
19790
  }
19791
+ /** Write `data` to the PTY in bounded, surrogate-safe chunks with a short
19792
+ * inter-chunk gap (win32 paced write). Awaits each chunk's write and the gap
19793
+ * so the returned promise resolves only after the FINAL chunk (carrying any
19794
+ * trailing submit key) has been written. */
19795
+ async writeWin32Chunked(data) {
19796
+ const chunks = chunkPreservingSurrogates(data, WIN32_PTY_WRITE_CHUNK_CHARS);
19797
+ for (let i = 0; i < chunks.length; i += 1) {
19798
+ if (!this.ptyProcess) throw new Error(`${this.cliName} is not running`);
19799
+ await this.ptyProcess.write(chunks[i]);
19800
+ if (i + 1 < chunks.length) {
19801
+ await new Promise((resolve24) => setTimeout(resolve24, WIN32_PTY_WRITE_CHUNK_GAP_MS));
19802
+ }
19803
+ }
19804
+ }
19744
19805
  resetPendingSendState(reason) {
19745
19806
  this.responseBuffer = "";
19746
19807
  if (this.responseTimeout) {
@@ -19988,7 +20049,13 @@ ${lastSnapshot}`;
19988
20049
  LOG.info("CLI", `[${this.cliType}] sendMessage recovered idle prompt readiness`);
19989
20050
  }
19990
20051
  }
19991
- if (!this.ready) throw new Error(`${this.cliName} not ready (status: ${this.engine.currentStatus})`);
20052
+ if (!this.ready) {
20053
+ if (allowQueue) {
20054
+ this.enqueuePendingOutboundMessage(text, "not_ready_pending_prompt");
20055
+ return;
20056
+ }
20057
+ throw new Error(`${this.cliName} not ready (status: ${this.engine.currentStatus})`);
20058
+ }
19992
20059
  const parsedSessionStatus = typeof parsedStatusBeforeSend?.status === "string" ? String(parsedStatusBeforeSend.status) : "";
19993
20060
  if (!allowInputDuringGeneration && (parsedSessionStatus === "generating" || parsedSessionStatus === "no_progress" || parsedSessionStatus === "long_generating")) {
19994
20061
  const parsedModal = parsedStatusBeforeSend?.activeModal ?? parsedStatusBeforeSend?.modal ?? null;
@@ -35232,6 +35299,7 @@ function applyPreLaunchTrust(trust, workingDir) {
35232
35299
 
35233
35300
  // src/providers/spec/fsm-driver.ts
35234
35301
  init_logger();
35302
+ init_pty_write_chunking();
35235
35303
  function countNewlines(s2) {
35236
35304
  let n = 0;
35237
35305
  for (let i = 0; i < s2.length; i += 1) if (s2.charCodeAt(i) === 10) n += 1;
@@ -35242,8 +35310,6 @@ var WIN32_SUBMIT_RESEND_GAP_MS = 350;
35242
35310
  var WIN32_SUBMIT_MAX_RESENDS = 14;
35243
35311
  var WIN32_SUBMIT_SETTLE_MS = 500;
35244
35312
  var WIN32_SUBMIT_SETTLE_POLL_MS = 120;
35245
- var WIN32_PTY_WRITE_CHUNK_CHARS = 1024;
35246
- var WIN32_PTY_WRITE_CHUNK_GAP_MS = 8;
35247
35313
  var WIN32_ECHO_PROBE_CHARS = 16;
35248
35314
  var WIN32_ECHO_MAX_WAIT_MS = 2e4;
35249
35315
  function normalizeForEcho(s2) {
@@ -35255,21 +35321,7 @@ function resolveSubmitDelayMs(specBeforeSubmit, text) {
35255
35321
  const spec = typeof specBeforeSubmit === "number" && specBeforeSubmit > 0 ? specBeforeSubmit : 0;
35256
35322
  return Math.max(spec, SUBMIT_DELAY_FLOOR_MS + linesBonus);
35257
35323
  }
35258
- function chunkPreservingSurrogates(text, size) {
35259
- const chunks = [];
35260
- let offset = 0;
35261
- while (offset < text.length) {
35262
- let end = Math.min(text.length, offset + size);
35263
- if (end < text.length) {
35264
- const code = text.charCodeAt(end - 1);
35265
- if (code >= 55296 && code <= 56319) end -= 1;
35266
- }
35267
- if (end <= offset) end = Math.min(text.length, offset + size);
35268
- chunks.push(text.slice(offset, end));
35269
- offset = end;
35270
- }
35271
- return chunks;
35272
- }
35324
+ var chunkPreservingSurrogates2 = chunkPreservingSurrogates;
35273
35325
  function guessExt(mime) {
35274
35326
  if (/png/i.test(mime)) return ".png";
35275
35327
  if (/jpe?g/i.test(mime)) return ".jpg";
@@ -35940,7 +35992,7 @@ var FsmDriver = class {
35940
35992
  this.adapter.send_keys(text);
35941
35993
  return;
35942
35994
  }
35943
- const chunks = chunkPreservingSurrogates(text, WIN32_PTY_WRITE_CHUNK_CHARS);
35995
+ const chunks = chunkPreservingSurrogates2(text, WIN32_PTY_WRITE_CHUNK_CHARS);
35944
35996
  let idx = 0;
35945
35997
  const writeNext = () => {
35946
35998
  this.win32WriteTimer = null;
@@ -46779,8 +46831,9 @@ var meshCrudHandlers = {
46779
46831
  };
46780
46832
  }
46781
46833
  }
46834
+ const explicitCleanupMode = args?.sessionCleanupMode ?? args?.session_cleanup_mode;
46782
46835
  const sessionCleanupMode = ctx.normalizeMeshSessionCleanupMode(
46783
- args?.sessionCleanupMode ?? args?.session_cleanup_mode ?? mesh?.policy?.sessionCleanupOnNodeRemove
46836
+ explicitCleanupMode ?? (node?.isLocalWorktree === true ? "stop_and_delete" : void 0) ?? mesh?.policy?.sessionCleanupOnNodeRemove
46784
46837
  );
46785
46838
  const explicitSessionIds = Array.isArray(args?.sessionIds) ? args.sessionIds.filter((v) => typeof v === "string" && v.trim().length > 0).map((v) => v.trim()) : void 0;
46786
46839
  let sessionCleanup;
@@ -46852,12 +46905,16 @@ var meshCrudHandlers = {
46852
46905
  }
46853
46906
  }
46854
46907
  const residueWarning = worktreeCleanup?.residue === true && typeof worktreeCleanup?.residueWarning === "string" ? worktreeCleanup.residueWarning : void 0;
46908
+ const skippedLiveSessionIds = Array.isArray(sessionCleanup?.skippedLiveSessionIds) ? sessionCleanup.skippedLiveSessionIds.filter((v) => typeof v === "string") : [];
46909
+ const orphanedSessionsRemaining = skippedLiveSessionIds.length > 0;
46910
+ const orphanNextAction = orphanedSessionsRemaining ? `Live session(s) [${skippedLiveSessionIds.join(", ")}] were skipped and still survive this node removal. Run mesh_cleanup_sessions with mode:'stop_and_delete' and sessionIds:[${skippedLiveSessionIds.map((id) => `'${id}'`).join(", ")}] to release them.` : void 0;
46855
46911
  return {
46856
46912
  success: true,
46857
46913
  removed,
46858
46914
  ...residueWarning ? { residueWarning } : {},
46859
46915
  ...sessionCleanup ? { sessionCleanup } : {},
46860
- ...worktreeCleanup ? { worktreeCleanup } : {}
46916
+ ...worktreeCleanup ? { worktreeCleanup } : {},
46917
+ ...orphanedSessionsRemaining ? { orphanedSessionsRemaining: true, nextAction: orphanNextAction } : {}
46861
46918
  };
46862
46919
  } catch (e) {
46863
46920
  return { success: false, error: e.message };
@@ -52321,14 +52378,19 @@ var DaemonCommandRouter = class {
52321
52378
  skippedCoordinatorSessionIds.push(sessionId);
52322
52379
  continue;
52323
52380
  }
52324
- if (!hasExplicitSessionIds && liveRuntime && !delegateBoundToThisNode) {
52381
+ const matchedByWorkspaceOnly = !recordNodeId;
52382
+ const isWorktreeNodeRemoval = cleanupSource === "mesh_remove_node" && args.node?.isLocalWorktree === true;
52383
+ const cleanWorkspaceOnlyForWorktree = isWorktreeNodeRemoval && matchedByWorkspaceOnly;
52384
+ if (!hasExplicitSessionIds && liveRuntime && !delegateBoundToThisNode && !cleanWorkspaceOnlyForWorktree) {
52325
52385
  skippedSessionIds.push(sessionId);
52326
52386
  skippedLiveSessionIds.push(sessionId);
52327
- const matchedByWorkspaceOnly = !recordNodeId;
52328
52387
  const reason = recordNodeId && recordNodeId !== args.nodeId ? `live_delegate_bound_to_other_node:${recordNodeId}` : matchedByWorkspaceOnly ? "live_session_matched_by_workspace_only_no_node_binding" : "live_session_not_bound_to_this_node";
52329
52388
  skippedLiveSessionReasons.push({ sessionId, reason });
52330
52389
  continue;
52331
52390
  }
52391
+ if (cleanWorkspaceOnlyForWorktree && !delegateBoundToThisNode) {
52392
+ actedLiveDelegateSessionIds.push(sessionId);
52393
+ }
52332
52394
  if (!hasExplicitSessionIds && liveRuntime && delegateBoundToThisNode && args.mode === "delete_stopped") {
52333
52395
  skippedSessionIds.push(sessionId);
52334
52396
  skippedLiveSessionIds.push(sessionId);