MCPcopy Create free account
hub / github.com/Noumena-Network/code / runFilePersistence

Function runFilePersistence

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

Source from the content-addressed store, hash-verified

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

Callers 2

executeFilePersistenceFunction · 0.85

Calls 10

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

Tested by

no test coverage detected