MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / writeMailboxAtomic

Function writeMailboxAtomic

src/utils/teammateMailbox.ts:152–170  ·  view source on GitHub ↗
(
  inboxPath: string,
  content: string,
)

Source from the content-addressed store, hash-verified

150}
151
152async function writeMailboxAtomic(
153 inboxPath: string,
154 content: string,
155): Promise<void> {
156 const bytes = Buffer.byteLength(content, 'utf8')
157 if (bytes > MAX_MAILBOX_FILE_BYTES) {
158 throw new Error(
159 `Compacted mailbox still exceeds ${MAX_MAILBOX_FILE_BYTES} bytes`,
160 )
161 }
162 const tempPath = `${inboxPath}.${process.pid}.${randomBytes(8).toString('hex')}.tmp`
163 try {
164 await writeFile(tempPath, content, 'utf-8')
165 await rename(tempPath, inboxPath)
166 } catch (error) {
167 await unlink(tempPath).catch(() => undefined)
168 throw error
169 }
170}
171
172export function compactMailboxMessages(
173 messages: TeammateMessage[],

Callers 1

writeCompactedMailboxFunction · 0.85

Calls 3

renameFunction · 0.85
unlinkFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected