{"version":3,"file":"pi.mjs","names":["rootSession","hookSessionStart","resourceConfigHelp"],"sources":["../../src/services/configRuntime/index.ts","../../src/extensions/workspaces/sessions/(backend)/root.cli.ts","../../src/extensions/workspaces/sessions/(backend)/hook/session-start.cli.ts","../../src/extensions/workspaces/sessions/(backend)/resource/config-help.cli.ts","../../generated/pi.ts"],"sourcesContent":["import { DOOM_CORDIS_SESSION_SERVICE, type DoomCordisSessionService } from '@agimon-ai/doompi-core/cordisHost';\nimport {\n  createDisabledDoomMcpProjection,\n  createDoomMcpProjectionService,\n  DOOM_MCP_PROJECTION_SERVICE,\n  isDoomMcpProjection,\n} from '@agimon-ai/doompi-core/mcpProjection';\nimport { type DoomNotificationLevel, readDoomNotificationService } from '@agimon-ai/doompi-core/notification';\nimport {\n  createDoomReadinessCoordinator,\n  DOOM_READINESS_SERVICE,\n  type DoomReadinessHandle,\n  type DoomReadinessNotification,\n} from '@agimon-ai/doompi-core/readiness';\nimport { createDoomTelemetry, type DoomTelemetry } from '@agimon-ai/doompi-telemetry';\nimport type { Context } from '@deepseek-ai/cordis';\nimport type { ExtensionAPI, ExtensionContext } from '@earendil-works/pi-coding-agent';\n\nimport { PACKAGE_SOURCE } from '../../constants/config';\nimport { getHarnessState } from '../harnessStore';\nimport {\n  acknowledgeDoomConfigTransition,\n  createDoomConfigContextAsync,\n  provideDoomConfigContext,\n} from '../sessionConfig';\nimport type { ConfigRuntime } from './type';\n\nfunction notify(cordis: Context, context: ExtensionContext, body: string, level: DoomNotificationLevel): void {\n  const service = readDoomNotificationService(cordis);\n  if (service) {\n    try {\n      void Promise.resolve(service.request({ body, level })).catch(() => undefined);\n    } catch {\n      // Notification delivery is best effort and does not fall back after routing.\n    }\n    return;\n  }\n  if (context.hasUI) context.ui.notify(body, level);\n  else process.emitWarning(body);\n}\n\ninterface ConfigInitialization {\n  readonly token: symbol;\n  readonly sessionManager: ExtensionContext['sessionManager'];\n  readonly handle: DoomReadinessHandle<void>;\n}\n\nexport function createConfigRuntime(pi: ExtensionAPI): ConfigRuntime {\n  let initialization: ConfigInitialization | undefined;\n  let sessionInjection: ReturnType<Context['inject']> | undefined;\n  return {\n    plugin(cordis) {\n      sessionInjection = cordis.inject([DOOM_CORDIS_SESSION_SERVICE], (sessionContext) => {\n        const session = sessionContext.get(DOOM_CORDIS_SESSION_SERVICE) as DoomCordisSessionService;\n        const context = session.context;\n        const token = Symbol(session.generation);\n        let active = true;\n        let initializationTask: Promise<void> = Promise.resolve();\n        let telemetry: DoomTelemetry | undefined;\n        const readiness = createDoomReadinessCoordinator({\n          notify(notification: DoomReadinessNotification) {\n            const diagnostics = notification.diagnostics.join('; ');\n            const detail = (notification.error?.message ?? diagnostics) || 'Initialization did not complete.';\n            const message = `${notification.packageId} initialization ${notification.state}: ${detail}`;\n            notify(sessionContext, context, message, 'warning');\n          },\n        });\n        sessionContext.effect(\n          () => async () => {\n            active = false;\n            if (initialization?.token === token) initialization = undefined;\n            await Promise.allSettled([readiness.dispose(), initializationTask]);\n            await telemetry?.shutdown();\n          },\n          `${PACKAGE_SOURCE}/session`,\n        );\n\n        // Consumers can resolve and register their own work as soon as the host's\n        // session fiber activates. Config file I/O continues behind the barrier\n        // below so Cordis activation itself stays synchronous.\n        sessionContext.provide(DOOM_READINESS_SERVICE, readiness);\n        const sessionTelemetry = createDoomTelemetry({\n          serviceName: 'doom-config',\n          packageName: PACKAGE_SOURCE,\n          cwd: context.cwd,\n          env: process.env,\n          enableLogs: true,\n          enableTraces: true,\n        });\n        telemetry = sessionTelemetry;\n        const handle = readiness.start<void>(PACKAGE_SOURCE, session.generation, async (signal) => {\n          acknowledgeDoomConfigTransition(pi, context, getHarnessState());\n          const config = await createDoomConfigContextAsync(context);\n          if (signal.aborted) throw signal.reason;\n          if (!active || initialization?.token !== token) {\n            throw new Error(`Doom Config initialization was superseded: ${session.generation}.`);\n          }\n\n          provideDoomConfigContext(sessionContext, config, `${session.generation}:config`);\n          const repoRoot = config.harness.root ?? context.cwd;\n          const stagingDirectory = config.harness.temporaryDirectory ?? context.cwd;\n          const projection =\n            config.harness.mcp &&\n            isDoomMcpProjection(config.harness.mcpProjection) &&\n            config.harness.mcpProjection.repoRoot === repoRoot\n              ? config.harness.mcpProjection\n              : createDisabledDoomMcpProjection({ repoRoot, stagingDirectory });\n          sessionContext.provide(\n            DOOM_MCP_PROJECTION_SERVICE,\n            createDoomMcpProjectionService({\n              sessionId: session.sessionId,\n              generation: `${session.generation}:mcp-projection`,\n              projection,\n            }),\n          );\n          void Promise.allSettled([\n            sessionTelemetry.recordEvent('doom_config.context_bound', {\n              'config.major_mode': config.harness.majorMode,\n              'config.domain_count': config.harness.domains.length,\n              'config.has_profile': config.harness.profile !== undefined,\n              'config.requires_relaunch': config.requiresRelaunch,\n            }),\n          ]);\n          return { value: undefined };\n        });\n        initialization = { token, sessionManager: context.sessionManager, handle };\n        initializationTask = handle.wait();\n        // The Pi barrier observes this same promise. Attaching a rejection handler\n        // now also covers hosts that dispose before Pi reaches that handler.\n        void Promise.allSettled([initializationTask]);\n      });\n    },\n    // The host publishes its session before this barrier allows later features to start.\n    async onSessionStart(_event, context) {\n      await sessionInjection?.await();\n      const current = initialization;\n      if (!current || current.sessionManager !== context.sessionManager) {\n        throw new Error('Doom Config initialization is unavailable for the active session.');\n      }\n      await current.handle.wait();\n      if (initialization?.token !== current.token) {\n        throw new Error('Doom Config initialization was superseded before the session barrier completed.');\n      }\n    },\n  };\n}\n","import { defineRoot } from '@agimon-ai/doompi-core/extensionFile';\nimport type { PiPluginContext } from '@agimon-ai/doompi-core/piExtension';\n\nimport { createConfigRuntime } from '../../../../services/configRuntime';\nexport default defineRoot(({ pi }: PiPluginContext) => {\n  const runtime = createConfigRuntime(pi);\n  return { value: runtime, services: [runtime.plugin] };\n});\n","import { defineCliHook, type WithRoot } from '@agimon-ai/doompi-core/extensionFile';\nimport type { PiPluginContext } from '@agimon-ai/doompi-core/piExtension';\n\ntype ConfigPiScope = Awaited<ReturnType<typeof import('../root.cli').default>>['value'];\nexport default defineCliHook((context: WithRoot<PiPluginContext, ConfigPiScope>) => context.root.onSessionStart);\n","import { defineResource } from '@agimon-ai/doompi-core/extensionFile';\n\nimport { CONFIG_HELP_SKILL, PACKAGE_SOURCE } from '../../../../../constants/config';\nexport default defineResource({ source: PACKAGE_SOURCE, moduleUrl: import.meta.url, skills: [CONFIG_HELP_SKILL] });\n","// Generated by @agimon-ai/doompi-build. Do not edit by hand.\nimport { definePiExtension, type PiPluginContext, type PiPluginContributions } from '@agimon-ai/doompi-core/piExtension';\nimport { composeRootHooks } from '@agimon-ai/doompi-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.cli';\nimport hookSessionStart from '../src/extensions/workspaces/sessions/(backend)/hook/session-start.cli';\nimport resourceConfigHelp from '../src/extensions/workspaces/sessions/(backend)/resource/config-help.cli';\n\ntype OptionsOf<T> = T extends (context: PiPluginContext<infer Options>) => unknown ? Options : never;\ntype InferredOptions = Exclude<OptionsOf<typeof rootSession> | OptionsOf<typeof hookSessionStart> | OptionsOf<typeof resourceConfigHelp>, undefined>;\ntype Intersect<Union> =\n  (Union extends unknown ? (value: Union) => void : never) extends (value: infer Value) => void ? Value : never;\ntype ExtensionOptions = [InferredOptions] extends [never] ? undefined : Intersect<InferredOptions>;\n\ntype Factory<T, C> = (context: C) => T;\nconst at = <T, C>(value: T | Factory<T, C>, context: C): T =>\n  typeof value === 'function' ? (value as Factory<T, C>)(context) : value;\n\nexport const extension = definePiExtension<ExtensionOptions>('@agimon-ai/doompi-config', async (context) => {\n  const scopeSession = await rootSession(context);\n  const contextSession = { ...context, root: scopeSession.value };\n  return {\n    ...composeRootHooks(scopeSession),\n    events: {\n      session_start: at(hookSessionStart, contextSession) as NonNullable<PiPluginContributions['events']>['session_start'],\n    },\n    get resources(): PiPluginContributions['resources'] { return [at(resourceConfigHelp, contextSession)]; },\n    services: [...(scopeSession.services ?? [])],\n  };\n});\n\nexport default extension;\n"],"mappings":";;;;;;;;;;;AA2B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