MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / hydrateRemoteSession

Function hydrateRemoteSession

source code/utils/sessionStorage.ts:1589–1624  ·  view source on GitHub ↗
(
  sessionId: string,
  ingressUrl: string,
)

Source from the content-addressed store, hash-verified

1587}
1588
1589export async function hydrateRemoteSession(
1590 sessionId: string,
1591 ingressUrl: string,
1592): Promise<boolean> {
1593 switchSession(asSessionId(sessionId))
1594
1595 const project = getProject()
1596
1597 try {
1598 const remoteLogs =
1599 (await sessionIngress.getSessionLogs(sessionId, ingressUrl)) || []
1600
1601 // Ensure the project directory and session file exist
1602 const projectDir = getProjectDir(getOriginalCwd())
1603 await mkdir(projectDir, { recursive: true, mode: 0o700 })
1604
1605 const sessionFile = getTranscriptPathForSession(sessionId)
1606
1607 // Replace local logs with remote logs. writeFile truncates, so no
1608 // unlink is needed; an empty remoteLogs array produces an empty file.
1609 const content = remoteLogs.map(e => jsonStringify(e) + '\n').join('')
1610 await writeFile(sessionFile, content, { encoding: 'utf8', mode: 0o600 })
1611
1612 logForDebugging(`Hydrated ${remoteLogs.length} entries from remote`)
1613 return remoteLogs.length > 0
1614 } catch (error) {
1615 logForDebugging(`Error hydrating session from remote: ${error}`)
1616 logForDiagnosticsNoPII('error', 'hydrate_remote_session_fail')
1617 return false
1618 } finally {
1619 // Set remote ingress URL after hydrating the remote session
1620 // to ensure we've always synced with the remote session
1621 // prior to enabling persistence
1622 project.setRemoteIngressUrl(ingressUrl)
1623 }
1624}
1625
1626/**
1627 * Hydrate session state from CCR v2 internal events.

Callers 1

loadInitialMessagesFunction · 0.85

Calls 11

switchSessionFunction · 0.85
asSessionIdFunction · 0.85
getProjectFunction · 0.85
getOriginalCwdFunction · 0.85
mkdirFunction · 0.85
jsonStringifyFunction · 0.85
logForDebuggingFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
setRemoteIngressUrlMethod · 0.80
getProjectDirFunction · 0.70

Tested by

no test coverage detected