MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / activate

Method activate

apps/cli/src/agent/extension-host.ts:368–437  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

366 // ==========================================================================
367
368 public async activate(): Promise<void> {
369 const bundlePath = path.join(this.options.extensionPath, "extension.js")
370
371 if (!fs.existsSync(bundlePath)) {
372 this.restoreConsole()
373 throw new Error(`Extension bundle not found at: ${bundlePath}`)
374 }
375
376 let storageDir: string | undefined
377
378 if (this.options.ephemeral) {
379 this.ephemeralStorageDir = await createEphemeralStorageDir()
380 storageDir = this.ephemeralStorageDir
381 }
382
383 // Create VSCode API mock.
384 this.vscode = createVSCodeAPI(this.options.extensionPath, this.options.workspacePath, undefined, {
385 appRoot: CLI_PACKAGE_ROOT,
386 storageDir,
387 })
388 ;(global as Record<string, unknown>).vscode = this.vscode
389 ;(global as Record<string, unknown>).__extensionHost = this
390
391 // Set up module resolution.
392 const require = createRequire(import.meta.url)
393 const Module = require("module")
394 const originalResolve = Module._resolveFilename
395
396 Module._resolveFilename = function (request: string, parent: unknown, isMain: boolean, options: unknown) {
397 if (request === "vscode") return "vscode-mock"
398 return originalResolve.call(this, request, parent, isMain, options)
399 }
400
401 require.cache["vscode-mock"] = {
402 id: "vscode-mock",
403 filename: "vscode-mock",
404 loaded: true,
405 exports: this.vscode,
406 children: [],
407 paths: [],
408 path: "",
409 isPreloading: false,
410 parent: null,
411 require: require,
412 } as unknown as NodeJS.Module
413
414 try {
415 this.extensionModule = require(bundlePath) as ExtensionModule
416 } catch (error) {
417 Module._resolveFilename = originalResolve
418
419 throw new Error(
420 `Failed to load extension bundle: ${error instanceof Error ? error.message : String(error)}`,
421 )
422 }
423
424 Module._resolveFilename = originalResolve
425

Callers 2

createListHostFunction · 0.95
runFunction · 0.95

Calls 6

restoreConsoleMethod · 0.95
activateMethod · 0.65
onMethod · 0.65
StringInterface · 0.50
handleMessageMethod · 0.45

Tested by

no test coverage detected