MCPcopy Create free account
hub / github.com/anomalyco/opencode / bootstrapDirectory

Function bootstrapDirectory

packages/app/src/context/global-sync/bootstrap.ts:206–377  ·  view source on GitHub ↗
(input: {
  directory: string
  scope: ServerScope
  mcp: boolean
  sdk: OpencodeClient
  store: Store<State>
  setStore: SetStoreFunction<State>
  vcsCache: VcsCache
  loadSessions: (directory: string) => Promise<void> | void
  translate: (key: string, vars?: Record<string, string | number>) => string
  global: {
    config: Config
    path: Path
    project: Project[]
    provider: NormalizedProviderListResponse
  }
  queryClient: QueryClient
  session?: ServerSession
})

Source from the content-addressed store, hash-verified

204 })
205
206export async function bootstrapDirectory(input: {
207 directory: string
208 scope: ServerScope
209 mcp: boolean
210 sdk: OpencodeClient
211 store: Store<State>
212 setStore: SetStoreFunction<State>
213 vcsCache: VcsCache
214 loadSessions: (directory: string) => Promise<void> | void
215 translate: (key: string, vars?: Record<string, string | number>) => string
216 global: {
217 config: Config
218 path: Path
219 project: Project[]
220 provider: NormalizedProviderListResponse
221 }
222 queryClient: QueryClient
223 session?: ServerSession
224}) {
225 const loading = input.store.status !== "complete"
226 const seededProject = projectID(input.directory, input.global.project)
227 const seededPath = input.global.path.directory === input.directory ? input.global.path : undefined
228 if (seededProject) input.setStore("project", seededProject)
229 if (seededPath) input.setStore("path", seededPath)
230 if (Object.keys(input.store.config).length === 0 && Object.keys(input.global.config).length > 0) {
231 input.setStore("config", reconcile(input.global.config, { merge: false }))
232 }
233 if (loading) input.setStore("status", "partial")
234
235 const revKey = ScopedKey.from(input.scope, input.directory)
236 const rev = (providerRev.get(revKey) ?? 0) + 1
237 providerRev.set(revKey, rev)
238 ;(async () => {
239 const slow = [
240 () => Promise.resolve(input.loadSessions(input.directory)),
241 () =>
242 input.queryClient
243 .ensureQueryData(loadAgentsQuery(input.scope, input.directory, input.sdk))
244 .then((data) => input.setStore("agent", data)),
245 () =>
246 retry(() => input.sdk.config.get().then((x) => input.setStore("config", reconcile(x.data!, { merge: false })))),
247 () =>
248 retry(() =>
249 input.sdk.session.status().then(async (x) => {
250 if (input.session) {
251 const statuses = x.data ?? {}
252 await Promise.all(
253 Object.keys(statuses).map((sessionID) => input.session!.resolve(sessionID).catch(() => undefined)),
254 )
255 input.session.set(
256 "session_status",
257 produce((draft) => {
258 for (const sessionID of Object.keys(draft)) {
259 if (statuses[sessionID]) continue
260 if (input.session?.get(sessionID)?.directory === input.directory) delete draft[sessionID]
261 }
262 }),
263 )

Callers 2

bootstrapInstanceFunction · 0.90
bootstrap.test.tsFile · 0.90

Calls 15

retryFunction · 0.90
cmpFunction · 0.90
loadMcpQueryFunction · 0.90
loadMcpResourcesQueryFunction · 0.90
getFilenameFunction · 0.90
showToastFunction · 0.90
formatServerErrorFunction · 0.90
projectIDFunction · 0.85
loadAgentsQueryFunction · 0.85
loadPathQueryFunction · 0.85
loadReferencesQueryFunction · 0.85
groupBySessionFunction · 0.85

Tested by

no test coverage detected