MCPcopy
hub / github.com/codeaashu/claude-code / runFilePersistence

Function runFilePersistence

src/utils/filePersistence/filePersistence.ts:51–144  ·  view source on GitHub ↗
(
  turnStartTime: TurnStartTime,
  signal?: AbortSignal,
)

Source from the content-addressed store, hash-verified

49 * @returns Event data, or null if not enabled or no files to persist
50 */
51export async function runFilePersistence(
52 turnStartTime: TurnStartTime,
53 signal?: AbortSignal,
54): Promise<FilesPersistedEventData | null> {
55 const environmentKind = getEnvironmentKind()
56 if (environmentKind !== 'byoc') {
57 return null
58 }
59
60 const sessionAccessToken = getSessionIngressAuthToken()
61 if (!sessionAccessToken) {
62 return null
63 }
64
65 const sessionId = process.env.CLAUDE_CODE_REMOTE_SESSION_ID
66 if (!sessionId) {
67 logError(
68 new Error(
69 'File persistence enabled but CLAUDE_CODE_REMOTE_SESSION_ID is not set',
70 ),
71 )
72 return null
73 }
74
75 const config: FilesApiConfig = {
76 oauthToken: sessionAccessToken,
77 sessionId,
78 }
79
80 const outputsDir = join(getCwd(), sessionId, OUTPUTS_SUBDIR)
81
82 // Check if aborted
83 if (signal?.aborted) {
84 logDebug('Persistence aborted before processing')
85 return null
86 }
87
88 const startTime = Date.now()
89 logEvent('tengu_file_persistence_started', {
90 mode: environmentKind as AnalyticsMetadata_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS,
91 })
92
93 try {
94 let result: FilesPersistedEventData
95 if (environmentKind === 'byoc') {
96 result = await executeBYOCPersistence(
97 turnStartTime,
98 config,
99 outputsDir,
100 signal,
101 )
102 } else {
103 result = await executeCloudPersistence()
104 }
105
106 // Nothing to report
107 if (result.files.length === 0 && result.failed.length === 0) {
108 return null

Callers 1

executeFilePersistenceFunction · 0.85

Calls 9

getEnvironmentKindFunction · 0.85
getCwdFunction · 0.85
logEventFunction · 0.85
executeBYOCPersistenceFunction · 0.85
executeCloudPersistenceFunction · 0.85
logDebugFunction · 0.70
logErrorFunction · 0.50
errorMessageFunction · 0.50

Tested by

no test coverage detected