@adhdev/daemon-core 0.9.77-rc.34 → 0.9.77-rc.36

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adhdev/daemon-core",
3
- "version": "0.9.77-rc.34",
3
+ "version": "0.9.77-rc.36",
4
4
  "description": "ADHDev daemon core — CDP, IDE detection, providers, command execution",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -225,6 +225,7 @@ export class ProviderCliAdapter implements CliAdapter {
225
225
  currentTurnScope: TurnParseScope | null;
226
226
  recentOutputBuffer: string;
227
227
  accumulatedBuffer: string;
228
+ accumulatedRawBuffer: string;
228
229
  screenText: string;
229
230
  currentStatus: CliSessionStatus['status'];
230
231
  activeModal: { message: string; buttons: string[] } | null;
@@ -307,6 +308,7 @@ export class ProviderCliAdapter implements CliAdapter {
307
308
  && cached.currentTurnScope === this.currentTurnScope
308
309
  && cached.recentOutputBuffer === this.recentOutputBuffer
309
310
  && cached.accumulatedBuffer === this.accumulatedBuffer
311
+ && cached.accumulatedRawBuffer === this.accumulatedRawBuffer
310
312
  && cached.screenText === this.lastScreenText
311
313
  && cached.currentStatus === this.currentStatus
312
314
  && cached.activeModal === this.activeModal
@@ -1456,6 +1458,14 @@ export class ProviderCliAdapter implements CliAdapter {
1456
1458
 
1457
1459
  // ─── Script Execution ──────────────────────────
1458
1460
 
1461
+ private invokeCliScript<T>(script: Function, input: any): T {
1462
+ const hasStateFactory = typeof this.cliScripts?.createState === 'function';
1463
+ const expectsStateArgument = hasStateFactory || this.scriptState !== null || script.length >= 2;
1464
+ return expectsStateArgument
1465
+ ? script(this.scriptState, input)
1466
+ : script(input);
1467
+ }
1468
+
1459
1469
  private runParseSession(): ParsedSession | null {
1460
1470
  if (typeof this.cliScripts?.parseSession !== 'function') {
1461
1471
  this.parseErrorMessage = `${this.cliType} parseSession unavailable`;
@@ -1476,7 +1486,10 @@ export class ProviderCliAdapter implements CliAdapter {
1476
1486
  scope: this.currentTurnScope,
1477
1487
  runtimeSettings: this.runtimeSettings,
1478
1488
  });
1479
- const session = this.cliScripts.parseSession(this.scriptState, { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
1489
+ const session = this.invokeCliScript<ParsedSession | null>(
1490
+ this.cliScripts.parseSession,
1491
+ { ...input, tail, tailScreen: buildCliScreenSnapshot(tail) },
1492
+ );
1480
1493
  this.parseErrorMessage = null;
1481
1494
  return session && typeof session === 'object' ? session : null;
1482
1495
  } catch (e: any) {
@@ -1491,7 +1504,7 @@ export class ProviderCliAdapter implements CliAdapter {
1491
1504
  if (!this.cliScripts?.detectStatus) return null;
1492
1505
  try {
1493
1506
  const screenText = this.terminalScreen.getText();
1494
- const status = this.cliScripts.detectStatus(this.scriptState, {
1507
+ const status = this.invokeCliScript<string | null>(this.cliScripts.detectStatus, {
1495
1508
  tail: text.slice(-500),
1496
1509
  screenText,
1497
1510
  rawBuffer: this.accumulatedRawBuffer,
@@ -1511,7 +1524,7 @@ export class ProviderCliAdapter implements CliAdapter {
1511
1524
  try {
1512
1525
  const screenText = this.terminalScreen.getText();
1513
1526
  const buffer = screenText || this.accumulatedBuffer;
1514
- return this.cliScripts.parseApproval(this.scriptState, {
1527
+ return this.invokeCliScript<{ message: string; buttons: string[] } | null>(this.cliScripts.parseApproval, {
1515
1528
  buffer,
1516
1529
  screenText,
1517
1530
  rawBuffer: this.accumulatedRawBuffer,
@@ -1582,6 +1595,7 @@ export class ProviderCliAdapter implements CliAdapter {
1582
1595
  && cached.currentTurnScope === this.currentTurnScope
1583
1596
  && cached.recentOutputBuffer === this.recentOutputBuffer
1584
1597
  && cached.accumulatedBuffer === this.accumulatedBuffer
1598
+ && cached.accumulatedRawBuffer === this.accumulatedRawBuffer
1585
1599
  && cached.screenText === parseScreenText
1586
1600
  && cached.currentStatus === this.currentStatus
1587
1601
  && cached.activeModal === this.activeModal
@@ -1621,6 +1635,7 @@ export class ProviderCliAdapter implements CliAdapter {
1621
1635
  currentTurnScope: this.currentTurnScope,
1622
1636
  recentOutputBuffer: this.recentOutputBuffer,
1623
1637
  accumulatedBuffer: this.accumulatedBuffer,
1638
+ accumulatedRawBuffer: this.accumulatedRawBuffer,
1624
1639
  screenText: parseScreenText,
1625
1640
  currentStatus: this.currentStatus,
1626
1641
  activeModal: this.activeModal,
@@ -1569,7 +1569,13 @@ export class DaemonCommandRouter {
1569
1569
  appendLedgerEntry(meshId, {
1570
1570
  kind: 'node_removed',
1571
1571
  nodeId,
1572
- payload: { worktree: !!node?.isLocalWorktree, sessionCleanupMode },
1572
+ payload: {
1573
+ worktree: !!node?.isLocalWorktree,
1574
+ sessionCleanupMode,
1575
+ workspace: typeof node?.workspace === 'string' ? node.workspace : undefined,
1576
+ daemonId: typeof node?.daemonId === 'string' ? node.daemonId : undefined,
1577
+ worktreeBranch: typeof node?.worktreeBranch === 'string' ? node.worktreeBranch : undefined,
1578
+ },
1573
1579
  });
1574
1580
  } catch { /* ledger append is best-effort */ }
1575
1581
  }
@@ -240,13 +240,15 @@ function injectMeshSystemMessage(components: DaemonComponents, args: {
240
240
  metadataEvent: Record<string, unknown>;
241
241
  }) {
242
242
  // ── Task Queue & Ledger ──
243
+ let completedTaskForLedger: { id?: string } | null = null;
243
244
  if (args.event === 'agent:generating_completed') {
244
245
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
245
246
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
246
247
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
247
248
 
248
249
  if (sessionId) {
249
- updateSessionTaskStatus(args.meshId, sessionId, 'completed');
250
+ const completedTask = updateSessionTaskStatus(args.meshId, sessionId, 'completed');
251
+ completedTaskForLedger = completedTask ? { id: completedTask.id } : null;
250
252
  if (nodeId && providerType) {
251
253
  // Short delay to allow completion event to propagate before pulling next
252
254
  setTimeout(() => {
@@ -262,6 +264,7 @@ function injectMeshSystemMessage(components: DaemonComponents, args: {
262
264
  ? updateSessionTaskStatus(args.meshId, sessionId, 'completed')
263
265
  : null;
264
266
  if (completedTask) {
267
+ completedTaskForLedger = { id: completedTask.id };
265
268
  try {
266
269
  appendLedgerEntry(args.meshId, {
267
270
  kind: 'task_completed',
@@ -274,6 +277,7 @@ function injectMeshSystemMessage(components: DaemonComponents, args: {
274
277
  taskId: completedTask.id,
275
278
  completedViaReady: true,
276
279
  providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || undefined,
280
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || undefined,
277
281
  },
278
282
  });
279
283
  } catch (e: any) {
@@ -318,7 +322,9 @@ function injectMeshSystemMessage(components: DaemonComponents, args: {
318
322
  payload: {
319
323
  event: args.event,
320
324
  nodeLabel: args.nodeLabel,
325
+ taskId: completedTaskForLedger?.id || undefined,
321
326
  providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || undefined,
327
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || undefined,
322
328
  },
323
329
  });
324
330
  } catch (e: any) {
@@ -451,6 +457,7 @@ export function handleMeshForwardEvent(components: DaemonComponents, payload: Re
451
457
  targetSessionId: readNonEmptyString(payload.targetSessionId) || readNonEmptyString(payload.sessionId) || readNonEmptyString(payload.instanceId),
452
458
  providerType: readNonEmptyString(payload.providerType),
453
459
  providerSessionId: readNonEmptyString(payload.providerSessionId),
460
+ finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary),
454
461
  },
455
462
  });
456
463
  }