@@ -3,6 +3,7 @@ import type { CodexCollaborationMode, PermissionMode, Session } from '@hapi/prot
33import type { Store } from '../store'
44import { clampAliveTime } from './aliveTime'
55import { EventPublisher } from './eventPublisher'
6+ import { mergeSessionMetadata } from './sessionMetadata'
67import { extractTodoWriteTodosFromMessageContent , TodosSchema } from './todos'
78
89export class SessionCache {
@@ -340,7 +341,7 @@ export class SessionCache {
340341 throw new Error ( 'Session not found' )
341342 }
342343
343- const mergedMetadata = this . mergeSessionMetadata ( source . metadata ?? null , target . metadata ?? null )
344+ const mergedMetadata = mergeSessionMetadata ( source . metadata ?? null , target . metadata ?? null )
344345 if ( mergedMetadata === target . metadata ) {
345346 return
346347 }
@@ -399,7 +400,7 @@ export class SessionCache {
399400
400401 this . store . messages . mergeSessionMessages ( oldSessionId , newSessionId )
401402
402- const mergedMetadata = this . mergeSessionMetadata ( oldStored . metadata , newStored . metadata )
403+ const mergedMetadata = mergeSessionMetadata ( oldStored . metadata , newStored . metadata )
403404 if ( mergedMetadata !== null && mergedMetadata !== newStored . metadata ) {
404405 for ( let attempt = 0 ; attempt < 2 ; attempt += 1 ) {
405406 const latest = this . store . sessions . getSessionByNamespace ( newSessionId , namespace )
@@ -470,48 +471,4 @@ export class SessionCache {
470471
471472 this . refreshSession ( newSessionId )
472473 }
473-
474- private mergeSessionMetadata ( oldMetadata : unknown | null , newMetadata : unknown | null ) : unknown | null {
475- if ( ! oldMetadata || typeof oldMetadata !== 'object' ) {
476- return newMetadata
477- }
478- if ( ! newMetadata || typeof newMetadata !== 'object' ) {
479- return oldMetadata
480- }
481-
482- const oldObj = oldMetadata as Record < string , unknown >
483- const newObj = newMetadata as Record < string , unknown >
484- const merged : Record < string , unknown > = { ...newObj }
485- let changed = false
486-
487- if ( typeof oldObj . name === 'string' && typeof newObj . name !== 'string' ) {
488- merged . name = oldObj . name
489- changed = true
490- }
491-
492- const oldSummary = oldObj . summary as { text ?: unknown ; updatedAt ?: unknown } | undefined
493- const newSummary = newObj . summary as { text ?: unknown ; updatedAt ?: unknown } | undefined
494- const oldUpdatedAt = typeof oldSummary ?. updatedAt === 'number' ? oldSummary . updatedAt : null
495- const newUpdatedAt = typeof newSummary ?. updatedAt === 'number' ? newSummary . updatedAt : null
496- if ( oldUpdatedAt !== null && ( newUpdatedAt === null || oldUpdatedAt > newUpdatedAt ) ) {
497- merged . summary = oldSummary
498- changed = true
499- }
500-
501- if ( oldObj . worktree && ! newObj . worktree ) {
502- merged . worktree = oldObj . worktree
503- changed = true
504- }
505-
506- if ( typeof oldObj . path === 'string' && typeof newObj . path !== 'string' ) {
507- merged . path = oldObj . path
508- changed = true
509- }
510- if ( typeof oldObj . host === 'string' && typeof newObj . host !== 'string' ) {
511- merged . host = oldObj . host
512- changed = true
513- }
514-
515- return changed ? merged : newMetadata
516- }
517474}
0 commit comments