MCPcopy Create free account
hub / github.com/tiann/hapi / mergeSessionMetadata

Method mergeSessionMetadata

hub/src/sync/sessionCache.ts:815–861  ·  view source on GitHub ↗
(oldMetadata: unknown | null, newMetadata: unknown | null)

Source from the content-addressed store, hash-verified

813 }
814
815 private mergeSessionMetadata(oldMetadata: unknown | null, newMetadata: unknown | null): unknown | null {
816 if (!oldMetadata || typeof oldMetadata !== 'object') {
817 return newMetadata
818 }
819 if (!newMetadata || typeof newMetadata !== 'object') {
820 return oldMetadata
821 }
822
823 const oldObj = oldMetadata as Record<string, unknown>
824 const newObj = newMetadata as Record<string, unknown>
825 const merged: Record<string, unknown> = { ...newObj }
826 let changed = false
827
828 if (typeof oldObj.name === 'string' && typeof newObj.name !== 'string') {
829 merged.name = oldObj.name
830 changed = true
831 }
832
833 const oldSummary = oldObj.summary as { text?: unknown; updatedAt?: unknown } | undefined
834 const newSummary = newObj.summary as { text?: unknown; updatedAt?: unknown } | undefined
835 const oldUpdatedAt = typeof oldSummary?.updatedAt === 'number' ? oldSummary.updatedAt : null
836 const newUpdatedAt = typeof newSummary?.updatedAt === 'number' ? newSummary.updatedAt : null
837 if (oldUpdatedAt !== null && (newUpdatedAt === null || oldUpdatedAt > newUpdatedAt)) {
838 merged.summary = oldSummary
839 changed = true
840 }
841
842 if (oldObj.worktree && !newObj.worktree) {
843 merged.worktree = oldObj.worktree
844 changed = true
845 }
846
847 if (typeof oldObj.path === 'string' && typeof newObj.path !== 'string') {
848 merged.path = oldObj.path
849 changed = true
850 }
851 if (typeof oldObj.host === 'string' && typeof newObj.host !== 'string') {
852 merged.host = oldObj.host
853 changed = true
854 }
855 if (typeof oldObj.preferredPermissionMode === 'string' && typeof newObj.preferredPermissionMode !== 'string') {
856 merged.preferredPermissionMode = oldObj.preferredPermissionMode
857 changed = true
858 }
859
860 return changed ? merged : newMetadata
861 }
862
863 private persistPreferredPermissionMode(session: Session, permissionMode: PermissionMode): void {
864 const currentMetadata = session.metadata

Callers 1

mergeSessionDataMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected