@adhdev/daemon-core 0.8.28 → 0.8.29

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.
@@ -60,6 +60,7 @@ export class CliProviderInstance implements ProviderInstance {
60
60
  private historyWriter: ChatHistoryWriter;
61
61
  private runtimeMessages: Array<{ key: string; message: ChatMessage }> = [];
62
62
  readonly instanceId: string;
63
+ private suppressIdleHistoryReplay = false;
63
64
 
64
65
  private presentationMode: 'terminal' | 'chat';
65
66
  private providerSessionId?: string;
@@ -135,7 +136,15 @@ export class CliProviderInstance implements ProviderInstance {
135
136
  await this.adapter.spawn();
136
137
  this.maybeAppendRuntimeRecoveryMessage(this.adapter.getRuntimeMetadata());
137
138
  if (this.providerSessionId) {
139
+ this.historyWriter.compactHistorySession(this.type, this.providerSessionId);
138
140
  const restoredHistory = readChatHistory(this.type, 0, 200, this.providerSessionId);
141
+ this.historyWriter.seedSessionHistory(
142
+ this.type,
143
+ restoredHistory.messages,
144
+ this.providerSessionId,
145
+ this.instanceId,
146
+ );
147
+ this.suppressIdleHistoryReplay = restoredHistory.messages.length > 0;
139
148
  if (restoredHistory.messages.length > 0) {
140
149
  this.adapter.seedCommittedMessages(
141
150
  restoredHistory.messages.map((message) => ({
@@ -184,7 +193,7 @@ export class CliProviderInstance implements ProviderInstance {
184
193
  } else if (this.type === 'codex-cli') {
185
194
  probedSessionId = this.probeSessionIdFromConfig({
186
195
  dbPath: '~/.codex/state_5.sqlite',
187
- query: 'select id from threads where cwd in ({dirs}) and created_at >= ? and archived = 0 order by created_at desc limit 1',
196
+ query: 'select id from threads where cwd in ({dirs}) and updated_at >= ? and archived = 0 order by updated_at desc limit 1',
188
197
  timestampFormat: 'unix_s',
189
198
  });
190
199
  } else if (this.type === 'goose-cli') {
@@ -260,6 +269,10 @@ export class CliProviderInstance implements ProviderInstance {
260
269
  const dirName = this.workingDir.split('/').filter(Boolean).pop() || 'session';
261
270
 
262
271
  if (parsedMessages.length > 0) {
272
+ const shouldSkipReplayPersist =
273
+ this.suppressIdleHistoryReplay
274
+ && adapterStatus.status === 'idle'
275
+ && parsedStatus?.status === 'idle';
263
276
  let messagesToSave = parsedMessages;
264
277
  if ((parsedStatus?.status === 'generating' || parsedStatus?.status === 'long_generating')) {
265
278
  const lastIdx = messagesToSave.length - 1;
@@ -267,7 +280,7 @@ export class CliProviderInstance implements ProviderInstance {
267
280
  messagesToSave = messagesToSave.slice(0, lastIdx);
268
281
  }
269
282
  }
270
- if (messagesToSave.length > 0) {
283
+ if (!shouldSkipReplayPersist && messagesToSave.length > 0) {
271
284
  this.historyWriter.appendNewMessages(
272
285
  this.type,
273
286
  messagesToSave,
@@ -374,6 +387,7 @@ export class CliProviderInstance implements ProviderInstance {
374
387
  if (newStatus !== this.lastStatus) {
375
388
  LOG.info('CLI', `[${this.type}] status: ${this.lastStatus} → ${newStatus}`);
376
389
  if (this.lastStatus === 'idle' && newStatus === 'generating') {
390
+ this.suppressIdleHistoryReplay = false;
377
391
  // Cancel any pending completed event (multi-step: idle→generating resume)
378
392
  if (this.completedDebouncePending) {
379
393
  LOG.info('CLI', `[${this.type}] cancelled pending completed (resumed generating)`);
@@ -394,6 +408,7 @@ export class CliProviderInstance implements ProviderInstance {
394
408
  this.generatingDebounceTimer = null;
395
409
  }, 1000);
396
410
  } else if (newStatus === 'waiting_approval') {
411
+ this.suppressIdleHistoryReplay = false;
397
412
  // Flush pending generating_started if debounce still pending
398
413
  if (this.generatingDebouncePending) {
399
414
  if (this.generatingDebounceTimer) { clearTimeout(this.generatingDebounceTimer); this.generatingDebounceTimer = null; }