MCPcopy Create free account
hub / github.com/codeaashu/claude-code / migrateLegacyAttachmentTypes

Function migrateLegacyAttachmentTypes

src/utils/conversationRecovery.ts:77–132  ·  view source on GitHub ↗

* Transforms legacy attachment types to current types for backward compatibility

(message: Message)

Source from the content-addressed store, hash-verified

75 * Transforms legacy attachment types to current types for backward compatibility
76 */
77function migrateLegacyAttachmentTypes(message: Message): Message {
78 if (message.type !== 'attachment') {
79 return message
80 }
81
82 const attachment = message.attachment as {
83 type: string
84 [key: string]: unknown
85 } // Handle legacy types not in current type system
86
87 // Transform legacy attachment types
88 if (attachment.type === 'new_file') {
89 return {
90 ...message,
91 attachment: {
92 ...attachment,
93 type: 'file',
94 displayPath: relative(getCwd(), attachment.filename as string),
95 },
96 } as SerializedMessage // Cast entire message since we know the structure is correct
97 }
98
99 if (attachment.type === 'new_directory') {
100 return {
101 ...message,
102 attachment: {
103 ...attachment,
104 type: 'directory',
105 displayPath: relative(getCwd(), attachment.path as string),
106 },
107 } as SerializedMessage // Cast entire message since we know the structure is correct
108 }
109
110 // Backfill displayPath for attachments from old sessions
111 if (!('displayPath' in attachment)) {
112 const path =
113 'filename' in attachment
114 ? (attachment.filename as string)
115 : 'path' in attachment
116 ? (attachment.path as string)
117 : 'skillDir' in attachment
118 ? (attachment.skillDir as string)
119 : undefined
120 if (path) {
121 return {
122 ...message,
123 attachment: {
124 ...attachment,
125 displayPath: relative(getCwd(), path),
126 },
127 } as Message
128 }
129 }
130
131 return message
132}
133
134export type TeleportRemoteResponse = {

Callers

nothing calls this directly

Calls 1

getCwdFunction · 0.85

Tested by

no test coverage detected