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

Function runStartupPrefetches

src/utils/startupPrefetch.ts:31–100  ·  view source on GitHub ↗
(
  lifecycle: SessionLifecycle,
  deps: StartupPrefetchDeps,
)

Source from the content-addressed store, hash-verified

29 * table in `startupPrefetchPolicy.ts`.
30 */
31export function runStartupPrefetches(
32 lifecycle: SessionLifecycle,
33 deps: StartupPrefetchDeps,
34): void {
35 const {
36 checkQuotaStatus,
37 prefetchPassesEligibility,
38 fetchBootstrapData,
39 prefetchFastModeStatus,
40 resolveFastModeStatusFromCache,
41 refreshExampleCommands,
42 logForDebugging,
43 logError,
44 getFeatureValue,
45 getGlobalConfig,
46 saveGlobalConfig,
47 isBareMode,
48 now,
49 } = deps
50
51 const bgRefreshThrottleMs = getFeatureValue('ncode_cicada_nap_ms', 0)
52 const lastPrefetched = getGlobalConfig().startupPrefetchedAt ?? 0
53 const skipStartupPrefetches =
54 isBareMode() ||
55 (bgRefreshThrottleMs > 0 && now() - lastPrefetched < bgRefreshThrottleMs)
56
57 if (!skipStartupPrefetches) {
58 const lastPrefetchedInfo =
59 lastPrefetched > 0
60 ? ` last ran ${Math.round((now() - lastPrefetched) / 1000)}s ago`
61 : ''
62 logForDebugging(`Starting background startup prefetches${lastPrefetchedInfo}`)
63
64 if (shouldRunStartupPrefetch(lifecycle, 'quota')) {
65 checkQuotaStatus().catch(error => logError(error))
66 }
67 if (shouldRunStartupPrefetch(lifecycle, 'passes')) {
68 void prefetchPassesEligibility()
69 }
70 if (shouldRunStartupPrefetch(lifecycle, 'bootstrap')) {
71 void fetchBootstrapData()
72 }
73 if (shouldRunStartupPrefetch(lifecycle, 'fastMode')) {
74 if (!getFeatureValue('ncode_miraculo_the_bard', false)) {
75 void prefetchFastModeStatus()
76 } else {
77 // Kill switch skips the network call, not org-policy enforcement.
78 resolveFastModeStatusFromCache()
79 }
80 }
81
82 if (bgRefreshThrottleMs > 0) {
83 saveGlobalConfig(current => ({
84 ...current,
85 startupPrefetchedAt: now(),
86 }))
87 }
88 } else {

Callers 2

runFunction · 0.85

Calls 12

isBareModeFunction · 0.85
nowFunction · 0.85
shouldRunStartupPrefetchFunction · 0.85
checkQuotaStatusFunction · 0.85
fetchBootstrapDataFunction · 0.85
prefetchFastModeStatusFunction · 0.85
getGlobalConfigFunction · 0.70
logForDebuggingFunction · 0.70
logErrorFunction · 0.70
saveGlobalConfigFunction · 0.70

Tested by

no test coverage detected