@adhdev/daemon-core 0.9.82-rc.401 → 0.9.82-rc.403

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
@@ -399,10 +399,10 @@ function readInjected(value) {
399
399
  }
400
400
  function getDaemonBuildInfo() {
401
401
  if (cached) return cached;
402
- const commit = readInjected(true ? "c31eb449e8febc28e378bd25394830a96a67594e" : void 0) ?? "unknown";
403
- const commitShort = readInjected(true ? "c31eb449" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
404
- const version = readInjected(true ? "0.9.82-rc.401" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
405
- const builtAt = readInjected(true ? "2026-06-27T16:14:32.200Z" : void 0);
402
+ const commit = readInjected(true ? "9522954406c86758c979231d4f96b280d09efd7a" : void 0) ?? "unknown";
403
+ const commitShort = readInjected(true ? "95229544" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
404
+ const version = readInjected(true ? "0.9.82-rc.403" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
405
+ const builtAt = readInjected(true ? "2026-06-27T17:53:59.574Z" : void 0);
406
406
  cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
407
407
  return cached;
408
408
  }
@@ -4491,6 +4491,176 @@ var init_mesh_ledger = __esm({
4491
4491
  }
4492
4492
  });
4493
4493
 
4494
+ // src/mesh/mesh-delivery-policy.ts
4495
+ function resolveDeliveryDecision(sessionStatus, opts) {
4496
+ const status = (sessionStatus || "").trim().toLowerCase();
4497
+ if (!status) {
4498
+ return {
4499
+ decision: "rejected",
4500
+ reason: "unknown_session_status",
4501
+ message: "Session status is unknown. Delivery rejected (fail-closed). Use mesh_launch_session to start a fresh session."
4502
+ };
4503
+ }
4504
+ if (IMMEDIATE_DELIVERY_STATUSES.has(status)) {
4505
+ return {
4506
+ decision: "immediate",
4507
+ reason: `session_${status}`,
4508
+ message: `Session is ${status} \u2014 delivery allowed immediately.`
4509
+ };
4510
+ }
4511
+ if (BUSY_DELIVERY_STATUSES.has(status)) {
4512
+ if (opts?.allowBusyInjection) {
4513
+ return {
4514
+ decision: "immediate",
4515
+ reason: `session_${status}_busy_injection_allowed`,
4516
+ message: `Session is ${status} but provider supports busy injection. Delivered immediately.`
4517
+ };
4518
+ }
4519
+ if (status === "waiting_approval" && opts?.kind === "approval") {
4520
+ return {
4521
+ decision: "immediate",
4522
+ reason: "session_waiting_approval_approval_message",
4523
+ message: "Session is waiting for approval \u2014 approval message delivered immediately."
4524
+ };
4525
+ }
4526
+ return {
4527
+ decision: "queued",
4528
+ reason: `session_${status}_busy`,
4529
+ message: `Session is ${status}. Task queued for delivery when session becomes idle. Do not inject directly into a busy session.`
4530
+ };
4531
+ }
4532
+ if (TERMINAL_DELIVERY_STATUSES.has(status)) {
4533
+ return {
4534
+ decision: "rejected",
4535
+ reason: `session_${status}_terminal`,
4536
+ message: `Session is ${status} (terminal). Delivery rejected. Launch a new session before dispatching tasks.`
4537
+ };
4538
+ }
4539
+ return {
4540
+ decision: "rejected",
4541
+ reason: "unrecognized_session_status",
4542
+ message: `Session status '${sessionStatus}' is not recognized. Delivery rejected (fail-closed). Inspect session state before retrying.`
4543
+ };
4544
+ }
4545
+ function createSessionDelivery(opts) {
4546
+ const now = (/* @__PURE__ */ new Date()).toISOString();
4547
+ const id = (0, import_crypto5.randomUUID)();
4548
+ const record = {
4549
+ id,
4550
+ meshId: opts.meshId,
4551
+ nodeId: opts.nodeId,
4552
+ sessionId: opts.sessionId,
4553
+ providerType: opts.providerType,
4554
+ taskId: opts.taskId,
4555
+ kind: opts.kind,
4556
+ priority: opts.priority ?? 0,
4557
+ message: opts.message,
4558
+ status: opts.status,
4559
+ deliverAfter: opts.deliverAfter,
4560
+ expiresAt: opts.expiresAt,
4561
+ attemptCount: 0,
4562
+ sourceCoordinatorSessionId: opts.sourceCoordinatorSessionId,
4563
+ sourceCoordinatorDaemonId: opts.sourceCoordinatorDaemonId,
4564
+ createdAt: now,
4565
+ updatedAt: now
4566
+ };
4567
+ MeshRuntimeStore.getInstance().insertSessionDelivery({
4568
+ id,
4569
+ meshId: opts.meshId,
4570
+ nodeId: opts.nodeId,
4571
+ sessionId: opts.sessionId,
4572
+ providerType: opts.providerType,
4573
+ taskId: opts.taskId,
4574
+ kind: opts.kind,
4575
+ priority: opts.priority ?? 0,
4576
+ message: opts.message,
4577
+ status: opts.status,
4578
+ deliverAfter: opts.deliverAfter,
4579
+ expiresAt: opts.expiresAt,
4580
+ sourceCoordinatorSessionId: opts.sourceCoordinatorSessionId,
4581
+ sourceCoordinatorDaemonId: opts.sourceCoordinatorDaemonId,
4582
+ createdAt: now,
4583
+ updatedAt: now
4584
+ });
4585
+ return record;
4586
+ }
4587
+ function updateSessionDeliveryStatus(id, status, opts) {
4588
+ try {
4589
+ MeshRuntimeStore.getInstance().updateSessionDeliveryStatus(id, status, opts);
4590
+ } catch {
4591
+ }
4592
+ }
4593
+ function getActiveSessionDeliveries(meshId, sessionId) {
4594
+ try {
4595
+ return MeshRuntimeStore.getInstance().getActiveSessionDeliveries(meshId, sessionId);
4596
+ } catch {
4597
+ return [];
4598
+ }
4599
+ }
4600
+ function recordCompletionConflict(opts) {
4601
+ try {
4602
+ MeshRuntimeStore.getInstance().recordCompletionConflict({
4603
+ id: (0, import_crypto5.randomUUID)(),
4604
+ meshId: opts.meshId,
4605
+ fingerprint: opts.fingerprint,
4606
+ conflictingTaskId: opts.conflictingTaskId,
4607
+ conflictingSessionId: opts.conflictingSessionId,
4608
+ originalTaskId: opts.originalTaskId,
4609
+ originalSessionId: opts.originalSessionId,
4610
+ event: opts.event,
4611
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
4612
+ });
4613
+ } catch {
4614
+ }
4615
+ }
4616
+ function getRecentCompletionConflicts(meshId, limitMs) {
4617
+ try {
4618
+ return MeshRuntimeStore.getInstance().getRecentCompletionConflicts(meshId, limitMs);
4619
+ } catch {
4620
+ return [];
4621
+ }
4622
+ }
4623
+ function markSessionDeliveriesTerminal(meshId, sessionId, terminalStatus) {
4624
+ try {
4625
+ const active = MeshRuntimeStore.getInstance().getActiveSessionDeliveries(meshId, sessionId);
4626
+ for (const delivery of active) {
4627
+ MeshRuntimeStore.getInstance().updateSessionDeliveryStatus(delivery.id, terminalStatus);
4628
+ }
4629
+ } catch {
4630
+ }
4631
+ }
4632
+ var import_crypto5, IMMEDIATE_DELIVERY_STATUSES, BUSY_DELIVERY_STATUSES, TERMINAL_DELIVERY_STATUSES;
4633
+ var init_mesh_delivery_policy = __esm({
4634
+ "src/mesh/mesh-delivery-policy.ts"() {
4635
+ "use strict";
4636
+ import_crypto5 = require("crypto");
4637
+ init_mesh_runtime_store();
4638
+ IMMEDIATE_DELIVERY_STATUSES = /* @__PURE__ */ new Set([
4639
+ "idle",
4640
+ "waiting_input",
4641
+ "ready"
4642
+ ]);
4643
+ BUSY_DELIVERY_STATUSES = /* @__PURE__ */ new Set([
4644
+ "generating",
4645
+ "running",
4646
+ "streaming",
4647
+ "busy",
4648
+ "starting",
4649
+ "initializing",
4650
+ "waiting_approval"
4651
+ ]);
4652
+ TERMINAL_DELIVERY_STATUSES = /* @__PURE__ */ new Set([
4653
+ "stopped",
4654
+ "failed",
4655
+ "terminated",
4656
+ "exited",
4657
+ "closed",
4658
+ "deleted",
4659
+ "error"
4660
+ ]);
4661
+ }
4662
+ });
4663
+
4494
4664
  // src/mesh/mesh-work-queue.ts
4495
4665
  var mesh_work_queue_exports = {};
4496
4666
  __export(mesh_work_queue_exports, {
@@ -4852,7 +5022,7 @@ function enqueueTask(meshId, message, opts) {
4852
5022
  if (!modeValidation.valid) {
4853
5023
  throw new Error(`live_debug_readonly_guardrail_violation: forbidden operations (${modeValidation.violations.join(", ")})`);
4854
5024
  }
4855
- const id = typeof opts?.id === "string" && opts.id.trim() ? opts.id.trim() : (0, import_crypto5.randomUUID)();
5025
+ const id = typeof opts?.id === "string" && opts.id.trim() ? opts.id.trim() : (0, import_crypto6.randomUUID)();
4856
5026
  const dependsOn = normalizeDependsOn(opts?.dependsOn);
4857
5027
  return withQueueLock(meshId, () => {
4858
5028
  if (MeshRuntimeStore.getInstance().findQueueEntryById(meshId, id)) {
@@ -4913,6 +5083,18 @@ function recordDirectDispatchTask(meshId, message, opts) {
4913
5083
  updatedAt: now
4914
5084
  };
4915
5085
  MeshRuntimeStore.getInstance().insertQueueEntry(entry);
5086
+ try {
5087
+ createSessionDelivery({
5088
+ meshId,
5089
+ ...opts.assignedNodeId ? { nodeId: opts.assignedNodeId } : {},
5090
+ ...opts.assignedSessionId ? { sessionId: opts.assignedSessionId } : {},
5091
+ taskId,
5092
+ kind: "task",
5093
+ message,
5094
+ status: "delivered"
5095
+ });
5096
+ } catch {
5097
+ }
4916
5098
  return entry;
4917
5099
  });
4918
5100
  }
@@ -5186,17 +5368,18 @@ function recordMeshToolCall(opts) {
5186
5368
  return { rateLimitExceeded: false, callsInWindow: 0, advisory: null };
5187
5369
  }
5188
5370
  }
5189
- var import_crypto5, ACTIVE_MESH_QUEUE_STATUSES, HISTORICAL_MESH_QUEUE_STATUSES, MESH_TASK_MODES, LIVE_DEBUG_READONLY_FORBIDDEN, NEGATION_CUES, NEGATION_WINDOW_TOKENS, GIT_MUTATION_SUBCOMMANDS, GIT_STASH_READONLY_SUBCOMMANDS, DEPENDENCY_FAILURE_TERMINALS, MAX_STRANDED_RECLAIMS;
5371
+ var import_crypto6, ACTIVE_MESH_QUEUE_STATUSES, HISTORICAL_MESH_QUEUE_STATUSES, MESH_TASK_MODES, LIVE_DEBUG_READONLY_FORBIDDEN, NEGATION_CUES, NEGATION_WINDOW_TOKENS, GIT_MUTATION_SUBCOMMANDS, GIT_STASH_READONLY_SUBCOMMANDS, DEPENDENCY_FAILURE_TERMINALS, MAX_STRANDED_RECLAIMS;
5190
5372
  var init_mesh_work_queue = __esm({
5191
5373
  "src/mesh/mesh-work-queue.ts"() {
5192
5374
  "use strict";
5193
- import_crypto5 = require("crypto");
5375
+ import_crypto6 = require("crypto");
5194
5376
  init_mesh_host_ownership();
5195
5377
  init_repo_mesh_types();
5196
5378
  init_mesh_runtime_store();
5197
5379
  init_mesh_config();
5198
5380
  init_logger();
5199
5381
  init_mesh_ledger();
5382
+ init_mesh_delivery_policy();
5200
5383
  ACTIVE_MESH_QUEUE_STATUSES = ["pending", "assigned"];
5201
5384
  HISTORICAL_MESH_QUEUE_STATUSES = ["completed", "failed", "cancelled"];
5202
5385
  MESH_TASK_MODES = ["code_change", "validation", "live_debug_readonly", "launch_app", "convergence"];
@@ -6850,7 +7033,7 @@ function upsertMeshMission(meshId, input) {
6850
7033
  if (input.status !== void 0 && !MESH_MISSION_STATUSES.includes(input.status)) {
6851
7034
  throw new Error(`invalid_mission_status: '${input.status}' (valid: ${MESH_MISSION_STATUSES.join(", ")})`);
6852
7035
  }
6853
- const id = typeof input.id === "string" && input.id.trim() ? input.id.trim() : (0, import_crypto6.randomUUID)();
7036
+ const id = typeof input.id === "string" && input.id.trim() ? input.id.trim() : (0, import_crypto7.randomUUID)();
6854
7037
  const store = MeshRuntimeStore.getInstance();
6855
7038
  const existing = store.getMission(meshId, id);
6856
7039
  const record = {
@@ -6966,11 +7149,11 @@ function buildMissionPromptSection(meshId) {
6966
7149
  );
6967
7150
  return lines.join("\n");
6968
7151
  }
6969
- var import_crypto6, MESH_MISSION_STATUSES, GOAL_PREVIEW_MAX, COMPACT_STATUS_GOAL_PREVIEW_MAX;
7152
+ var import_crypto7, MESH_MISSION_STATUSES, GOAL_PREVIEW_MAX, COMPACT_STATUS_GOAL_PREVIEW_MAX;
6970
7153
  var init_mesh_missions = __esm({
6971
7154
  "src/mesh/mesh-missions.ts"() {
6972
7155
  "use strict";
6973
- import_crypto6 = require("crypto");
7156
+ import_crypto7 = require("crypto");
6974
7157
  init_mesh_runtime_store();
6975
7158
  init_mesh_work_queue();
6976
7159
  init_mesh_task_stats();
@@ -10037,7 +10220,7 @@ function queuePendingMeshCoordinatorEvent(event) {
10037
10220
  let sqliteOk = false;
10038
10221
  try {
10039
10222
  MeshRuntimeStore.getInstance().insertPendingEvent({
10040
- id: (0, import_crypto7.randomUUID)(),
10223
+ id: (0, import_crypto8.randomUUID)(),
10041
10224
  meshId: event.meshId,
10042
10225
  coordinatorDaemonId: event.targetCoordinatorDaemonId ?? null,
10043
10226
  event: event.event,
@@ -10225,13 +10408,13 @@ function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
10225
10408
  }
10226
10409
  }
10227
10410
  }
10228
- var import_fs10, import_path9, import_crypto7, REFINE_TERMINAL_EVENTS, TERMINAL_COMPLETION_EVENTS, MAX_PENDING_EVENTS_BYTES, MAX_PENDING_EVENTS_KEEP;
10411
+ var import_fs10, import_path9, import_crypto8, REFINE_TERMINAL_EVENTS, TERMINAL_COMPLETION_EVENTS, MAX_PENDING_EVENTS_BYTES, MAX_PENDING_EVENTS_KEEP;
10229
10412
  var init_mesh_events_pending = __esm({
10230
10413
  "src/mesh/mesh-events-pending.ts"() {
10231
10414
  "use strict";
10232
10415
  import_fs10 = require("fs");
10233
10416
  import_path9 = require("path");
10234
- import_crypto7 = require("crypto");
10417
+ import_crypto8 = require("crypto");
10235
10418
  init_logger();
10236
10419
  init_mesh_ledger();
10237
10420
  init_mesh_runtime_store();
@@ -10244,176 +10427,6 @@ var init_mesh_events_pending = __esm({
10244
10427
  }
10245
10428
  });
10246
10429
 
10247
- // src/mesh/mesh-delivery-policy.ts
10248
- function resolveDeliveryDecision(sessionStatus, opts) {
10249
- const status = (sessionStatus || "").trim().toLowerCase();
10250
- if (!status) {
10251
- return {
10252
- decision: "rejected",
10253
- reason: "unknown_session_status",
10254
- message: "Session status is unknown. Delivery rejected (fail-closed). Use mesh_launch_session to start a fresh session."
10255
- };
10256
- }
10257
- if (IMMEDIATE_DELIVERY_STATUSES.has(status)) {
10258
- return {
10259
- decision: "immediate",
10260
- reason: `session_${status}`,
10261
- message: `Session is ${status} \u2014 delivery allowed immediately.`
10262
- };
10263
- }
10264
- if (BUSY_DELIVERY_STATUSES.has(status)) {
10265
- if (opts?.allowBusyInjection) {
10266
- return {
10267
- decision: "immediate",
10268
- reason: `session_${status}_busy_injection_allowed`,
10269
- message: `Session is ${status} but provider supports busy injection. Delivered immediately.`
10270
- };
10271
- }
10272
- if (status === "waiting_approval" && opts?.kind === "approval") {
10273
- return {
10274
- decision: "immediate",
10275
- reason: "session_waiting_approval_approval_message",
10276
- message: "Session is waiting for approval \u2014 approval message delivered immediately."
10277
- };
10278
- }
10279
- return {
10280
- decision: "queued",
10281
- reason: `session_${status}_busy`,
10282
- message: `Session is ${status}. Task queued for delivery when session becomes idle. Do not inject directly into a busy session.`
10283
- };
10284
- }
10285
- if (TERMINAL_DELIVERY_STATUSES.has(status)) {
10286
- return {
10287
- decision: "rejected",
10288
- reason: `session_${status}_terminal`,
10289
- message: `Session is ${status} (terminal). Delivery rejected. Launch a new session before dispatching tasks.`
10290
- };
10291
- }
10292
- return {
10293
- decision: "rejected",
10294
- reason: "unrecognized_session_status",
10295
- message: `Session status '${sessionStatus}' is not recognized. Delivery rejected (fail-closed). Inspect session state before retrying.`
10296
- };
10297
- }
10298
- function createSessionDelivery(opts) {
10299
- const now = (/* @__PURE__ */ new Date()).toISOString();
10300
- const id = (0, import_crypto8.randomUUID)();
10301
- const record = {
10302
- id,
10303
- meshId: opts.meshId,
10304
- nodeId: opts.nodeId,
10305
- sessionId: opts.sessionId,
10306
- providerType: opts.providerType,
10307
- taskId: opts.taskId,
10308
- kind: opts.kind,
10309
- priority: opts.priority ?? 0,
10310
- message: opts.message,
10311
- status: opts.status,
10312
- deliverAfter: opts.deliverAfter,
10313
- expiresAt: opts.expiresAt,
10314
- attemptCount: 0,
10315
- sourceCoordinatorSessionId: opts.sourceCoordinatorSessionId,
10316
- sourceCoordinatorDaemonId: opts.sourceCoordinatorDaemonId,
10317
- createdAt: now,
10318
- updatedAt: now
10319
- };
10320
- MeshRuntimeStore.getInstance().insertSessionDelivery({
10321
- id,
10322
- meshId: opts.meshId,
10323
- nodeId: opts.nodeId,
10324
- sessionId: opts.sessionId,
10325
- providerType: opts.providerType,
10326
- taskId: opts.taskId,
10327
- kind: opts.kind,
10328
- priority: opts.priority ?? 0,
10329
- message: opts.message,
10330
- status: opts.status,
10331
- deliverAfter: opts.deliverAfter,
10332
- expiresAt: opts.expiresAt,
10333
- sourceCoordinatorSessionId: opts.sourceCoordinatorSessionId,
10334
- sourceCoordinatorDaemonId: opts.sourceCoordinatorDaemonId,
10335
- createdAt: now,
10336
- updatedAt: now
10337
- });
10338
- return record;
10339
- }
10340
- function updateSessionDeliveryStatus(id, status, opts) {
10341
- try {
10342
- MeshRuntimeStore.getInstance().updateSessionDeliveryStatus(id, status, opts);
10343
- } catch {
10344
- }
10345
- }
10346
- function getActiveSessionDeliveries(meshId, sessionId) {
10347
- try {
10348
- return MeshRuntimeStore.getInstance().getActiveSessionDeliveries(meshId, sessionId);
10349
- } catch {
10350
- return [];
10351
- }
10352
- }
10353
- function recordCompletionConflict(opts) {
10354
- try {
10355
- MeshRuntimeStore.getInstance().recordCompletionConflict({
10356
- id: (0, import_crypto8.randomUUID)(),
10357
- meshId: opts.meshId,
10358
- fingerprint: opts.fingerprint,
10359
- conflictingTaskId: opts.conflictingTaskId,
10360
- conflictingSessionId: opts.conflictingSessionId,
10361
- originalTaskId: opts.originalTaskId,
10362
- originalSessionId: opts.originalSessionId,
10363
- event: opts.event,
10364
- createdAt: (/* @__PURE__ */ new Date()).toISOString()
10365
- });
10366
- } catch {
10367
- }
10368
- }
10369
- function getRecentCompletionConflicts(meshId, limitMs) {
10370
- try {
10371
- return MeshRuntimeStore.getInstance().getRecentCompletionConflicts(meshId, limitMs);
10372
- } catch {
10373
- return [];
10374
- }
10375
- }
10376
- function markSessionDeliveriesTerminal(meshId, sessionId, terminalStatus) {
10377
- try {
10378
- const active = MeshRuntimeStore.getInstance().getActiveSessionDeliveries(meshId, sessionId);
10379
- for (const delivery of active) {
10380
- MeshRuntimeStore.getInstance().updateSessionDeliveryStatus(delivery.id, terminalStatus);
10381
- }
10382
- } catch {
10383
- }
10384
- }
10385
- var import_crypto8, IMMEDIATE_DELIVERY_STATUSES, BUSY_DELIVERY_STATUSES, TERMINAL_DELIVERY_STATUSES;
10386
- var init_mesh_delivery_policy = __esm({
10387
- "src/mesh/mesh-delivery-policy.ts"() {
10388
- "use strict";
10389
- import_crypto8 = require("crypto");
10390
- init_mesh_runtime_store();
10391
- IMMEDIATE_DELIVERY_STATUSES = /* @__PURE__ */ new Set([
10392
- "idle",
10393
- "waiting_input",
10394
- "ready"
10395
- ]);
10396
- BUSY_DELIVERY_STATUSES = /* @__PURE__ */ new Set([
10397
- "generating",
10398
- "running",
10399
- "streaming",
10400
- "busy",
10401
- "starting",
10402
- "initializing",
10403
- "waiting_approval"
10404
- ]);
10405
- TERMINAL_DELIVERY_STATUSES = /* @__PURE__ */ new Set([
10406
- "stopped",
10407
- "failed",
10408
- "terminated",
10409
- "exited",
10410
- "closed",
10411
- "deleted",
10412
- "error"
10413
- ]);
10414
- }
10415
- });
10416
-
10417
10430
  // src/mesh/mesh-events-stale.ts
10418
10431
  function findRecentTerminalLedgerEvidence(args) {
10419
10432
  if (!args.sessionId && !args.nodeId) return null;
@@ -41227,6 +41240,42 @@ var CliProviderInstance = class _CliProviderInstance {
41227
41240
  }
41228
41241
  } else if (newStatus === "idle" && this.lastStatus === "starting") {
41229
41242
  this.emitAgentReadyOnce(chatTitle, now);
41243
+ const startedTurnTaskId = typeof this.adapter?.currentTurnTaskId === "string" && this.adapter.currentTurnTaskId.trim() ? this.adapter.currentTurnTaskId : void 0;
41244
+ const fastCollapsed = !!startedTurnTaskId && !this.hasAdapterPendingResponse() && !this.generatingStartedAt && !this.generatingDebouncePending;
41245
+ if (fastCollapsed) {
41246
+ let fcFinalSummary;
41247
+ let fcEvidenceSource = "unavailable";
41248
+ try {
41249
+ const parsedMessages = this.adapter?.getScriptParsedStatus()?.messages;
41250
+ const evidence = this.completionFinalAssistantEvidence(parsedMessages);
41251
+ fcEvidenceSource = evidence.source;
41252
+ fcFinalSummary = extractFinalSummaryFromMessages(evidence.messages);
41253
+ } catch {
41254
+ }
41255
+ const missingEvidence = (this.provider.requiresFinalAssistantBeforeIdle === true || fcEvidenceSource === "external-native") && !fcFinalSummary;
41256
+ const hasMeshContext = !!(this.settings.meshNodeFor || this.settings.meshActiveTaskId || this.settings.launchedByCoordinator);
41257
+ if (missingEvidence && !hasMeshContext) {
41258
+ LOG.info("CLI", `[${this.type}] startup-grace fast-collapse suppressed: missing final assistant evidence, no mesh context (source=${fcEvidenceSource})`);
41259
+ } else {
41260
+ LOG.info("CLI", `[${this.type}] startup-grace fast-collapse: synthesizing started+completed (taskId=${startedTurnTaskId} source=${fcEvidenceSource} hadFinalSummary=${!!fcFinalSummary})`);
41261
+ this.pushEvent({ event: "agent:generating_started", chatTitle, timestamp: now });
41262
+ if (this.isMeshWorkerSession()) {
41263
+ traceMeshEventStage("fired", this.meshTraceCtx(), `startup-grace fast-collapse (source=${fcEvidenceSource})`);
41264
+ }
41265
+ this.pushEvent({
41266
+ event: "agent:generating_completed",
41267
+ chatTitle,
41268
+ duration: 0,
41269
+ timestamp: now,
41270
+ finalSummary: fcFinalSummary,
41271
+ completionDiagnostic: {
41272
+ reason: "startup_grace_fast_collapse",
41273
+ finalAssistantEvidenceSource: fcEvidenceSource,
41274
+ ...missingEvidence ? { blockReason: "missing_final_assistant" } : {}
41275
+ }
41276
+ });
41277
+ }
41278
+ }
41230
41279
  } else if (newStatus === "error") {
41231
41280
  if (this.generatingDebounceTimer) {
41232
41281
  clearTimeout(this.generatingDebounceTimer);