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

Function uploadUserSettingsInBackground

src/services/settingsSync/index.ts:60–111  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58 * Runs in background - caller should not await unless needed.
59 */
60export async function uploadUserSettingsInBackground(): Promise<void> {
61 try {
62 if (
63 !feature('UPLOAD_USER_SETTINGS') ||
64 !getFeatureValue_CACHED_MAY_BE_STALE(
65 'tengu_enable_settings_sync_push',
66 false,
67 ) ||
68 !getIsInteractive() ||
69 !isUsingOAuth()
70 ) {
71 logForDiagnosticsNoPII('info', 'settings_sync_upload_skipped')
72 logEvent('tengu_settings_sync_upload_skipped_ineligible', {})
73 return
74 }
75
76 logForDiagnosticsNoPII('info', 'settings_sync_upload_starting')
77 const result = await fetchUserSettings()
78 if (!result.success) {
79 logForDiagnosticsNoPII('warn', 'settings_sync_upload_fetch_failed')
80 logEvent('tengu_settings_sync_upload_fetch_failed', {})
81 return
82 }
83
84 const projectId = await getRepoRemoteHash()
85 const localEntries = await buildEntriesFromLocalFiles(projectId)
86 const remoteEntries = result.isEmpty ? {} : result.data!.content.entries
87 const changedEntries = pickBy(
88 localEntries,
89 (value, key) => remoteEntries[key] !== value,
90 )
91
92 const entryCount = Object.keys(changedEntries).length
93 if (entryCount === 0) {
94 logForDiagnosticsNoPII('info', 'settings_sync_upload_no_changes')
95 logEvent('tengu_settings_sync_upload_skipped', {})
96 return
97 }
98
99 const uploadResult = await uploadUserSettings(changedEntries)
100 if (uploadResult.success) {
101 logForDiagnosticsNoPII('info', 'settings_sync_upload_success')
102 logEvent('tengu_settings_sync_upload_success', { entryCount })
103 } else {
104 logForDiagnosticsNoPII('warn', 'settings_sync_upload_failed')
105 logEvent('tengu_settings_sync_upload_failed', { entryCount })
106 }
107 } catch {
108 // Fail-open: log unexpected errors but don't block startup
109 logForDiagnosticsNoPII('error', 'settings_sync_unexpected_error')
110 }
111}
112
113// Cached so the fire-and-forget at runHeadless entry and the await in
114// installPluginsAndApplyMcpInBackground share one fetch.

Callers

nothing calls this directly

Calls 11

featureFunction · 0.85
getIsInteractiveFunction · 0.85
logForDiagnosticsNoPIIFunction · 0.85
logEventFunction · 0.85
fetchUserSettingsFunction · 0.85
getRepoRemoteHashFunction · 0.85
uploadUserSettingsFunction · 0.85
keysMethod · 0.80
isUsingOAuthFunction · 0.70

Tested by

no test coverage detected