{"version":3,"file":"server.mjs","names":["rootSession","apiRoute","resourceHelpHowToConfig"],"sources":["../../src/constants/config.ts","../../src/services/configRuntime/index.ts","../../src/extensions/workspaces/sessions/(backend)/root.server.ts","../../src/extensions/(backend)/api/settings/route.server.ts","../../src/extensions/workspaces/sessions/(backend)/resource/help-how-to-config.server.ts","../../generated/server.ts"],"sourcesContent":["export const PACKAGE_SOURCE = '@agimon-ai/po-config';\nexport const CONFIG_HELP_SKILL = {\n  name: 'help-how-to-config',\n  description:\n    'Configure Po runtime settings, source precedence, and typed session configuration. Use for config.yaml, the po/config Cordis service, immutable context snapshots, or shared selection transition state. Do not use for defining modes.yaml, domains.yaml, or profiles.yaml.',\n};\n","import type { PoHeadlessExecutionContext } from '@agimon-ai/po-core/headless';\nimport {\n  createDisabledPoMcpProjection,\n  createPoMcpProjectionService,\n  PO_MCP_PROJECTION_SERVICE,\n  isPoMcpProjection,\n} from '@agimon-ai/po-core/mcpProjection';\nimport { readPoNotificationService } from '@agimon-ai/po-core/notification';\nimport { BACKGROUND_CONTEXT, withAbortSignal, type FileSystem } from '@agimon-ai/po-core/platform';\nimport {\n  createPoReadinessCoordinator,\n  PO_READINESS_SERVICE,\n  type PoReadinessNotification,\n} from '@agimon-ai/po-core/readiness';\nimport { createPoTelemetry } from '@agimon-ai/po-core/telemetry';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport { PACKAGE_SOURCE } from '../../constants/config';\nimport { createNativePoConfigContext, providePoConfigContext } from '../sessionConfig';\nimport type { ConfigRuntime } from './type';\n\n/** One native session fiber owns initialization and all of its services. */\nexport function createConfigRuntime(\n  cordis: Context,\n  execution: PoHeadlessExecutionContext,\n  fs: FileSystem,\n  lifetime?: AbortSignal,\n): ConfigRuntime {\n  const generation = `${execution.sessionId}:${crypto.randomUUID()}`;\n  let active = true;\n  const readiness = createPoReadinessCoordinator({\n    notify(notification: PoReadinessNotification) {\n      const diagnostics = notification.diagnostics.join('; ');\n      const detail = (notification.error?.message ?? diagnostics) || 'Initialization did not complete.';\n      const body = `${notification.packageId} initialization ${notification.state}: ${detail}`;\n      const service = readPoNotificationService(cordis);\n      // Both routes are best effort. The coordinator retains the failed outcome.\n      try {\n        void Promise.allSettled([\n          Promise.resolve(\n            service ? service.request({ body, level: 'warning' }) : execution.client.notify({ body, level: 'warning' }),\n          ),\n        ]);\n      } catch (error) {\n        process.emitWarning(`Config warning delivery failed: ${String(error)}`);\n      }\n    },\n  });\n  cordis.provide(PO_READINESS_SERVICE, readiness);\n  const telemetry = createPoTelemetry({\n    serviceName: 'po-config',\n    packageName: PACKAGE_SOURCE,\n    cwd: execution.cwd,\n    env: execution.environment,\n    enableLogs: true,\n    enableTraces: true,\n  });\n  let initializationTask: Promise<void> = Promise.resolve();\n  const cancel = (): void => {\n    active = false;\n    void Promise.allSettled([readiness.dispose()]);\n  };\n  lifetime?.addEventListener('abort', cancel, { once: true });\n  cordis.effect(\n    () => async () => {\n      active = false;\n      lifetime?.removeEventListener('abort', cancel);\n      await Promise.allSettled([readiness.dispose(), initializationTask]);\n      await telemetry.shutdown();\n    },\n    `${PACKAGE_SOURCE}/session`,\n  );\n  const handle = readiness.start<void>(PACKAGE_SOURCE, generation, async (signal) => {\n    const config = await createNativePoConfigContext(execution, fs, withAbortSignal(signal, BACKGROUND_CONTEXT));\n    signal.throwIfAborted();\n    if (!active) throw new Error(`Po Config initialization was superseded: ${generation}.`);\n    providePoConfigContext(cordis, config, `${generation}:config`);\n    const repoRoot = config.harness.root ?? execution.cwd;\n    const stagingDirectory = config.harness.temporaryDirectory ?? execution.cwd;\n    const projection =\n      config.harness.mcp &&\n      isPoMcpProjection(config.harness.mcpProjection) &&\n      config.harness.mcpProjection.repoRoot === repoRoot\n        ? config.harness.mcpProjection\n        : createDisabledPoMcpProjection({ repoRoot, stagingDirectory });\n    cordis.provide(\n      PO_MCP_PROJECTION_SERVICE,\n      createPoMcpProjectionService({\n        sessionId: execution.sessionId,\n        generation: `${generation}:mcp-projection`,\n        projection,\n      }),\n    );\n    void Promise.allSettled([\n      telemetry.recordEvent('po_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  initializationTask = handle.wait();\n  if (lifetime?.aborted) cancel();\n  void Promise.allSettled([initializationTask]);\n  return { ready: initializationTask };\n}\n","import { defineRoot } from '@agimon-ai/po-core/extensionFile';\nimport { requirePoFs } from '@agimon-ai/po-core/platform';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverPlugin';\nimport type { Context } from '@deepseek-ai/cordis';\n\nimport { createConfigRuntime } from '../../../../services/configRuntime';\nimport type { ConfigRuntime } from '../../../../services/configRuntime/type';\n\nexport default defineRoot(({ agent, context: root, signal }: PoServerPluginContext) => {\n  if (!agent) throw new Error('Config initialization requires the native session host.');\n  const fs = requirePoFs(root);\n  let runtime: ConfigRuntime | undefined;\n  return {\n    value: undefined,\n    services: [\n      (context: Context) => {\n        runtime = createConfigRuntime(context, agent.context, fs, signal);\n      },\n    ],\n    async onStart() {\n      if (!runtime) throw new Error('Native config initializer was not installed.');\n      // Pi previously awaited the barrier, then reported handler errors and continued.\n      // Keep that degraded outcome, observable through readiness and notification.\n      await Promise.allSettled([runtime.ready]);\n    },\n  };\n});\n","import { defineRoutedContribution } from '@agimon-ai/po-core/extensionFile';\nimport { requirePoFs } from '@agimon-ai/po-core/platform';\nimport type { PoServerPluginContext } from '@agimon-ai/po-core/serverPlugin';\n\nimport { createSettingsApi } from '../../../../services/settingsApi';\n\nexport default defineRoutedContribution(\n  ({ context, host }: PoServerPluginContext) =>\n    host.scope === 'session' ? undefined : createSettingsApi(requirePoFs(context)),\n  { cardinality: 'optional' },\n);\n","import { defineResource } from '@agimon-ai/po-core/extensionFile';\nimport { packageResourcePath, readPackageResource } from '@agimon-ai/po-core/serverPlugin';\n\nimport { CONFIG_HELP_SKILL } from '../../../../../constants/config';\n\nexport default defineResource({\n  ...CONFIG_HELP_SKILL,\n  when: { state: { 'minor-mode': 'help' }, attribution: { kind: 'minor' as const, mode: 'help' } },\n  kind: 'skill' as const,\n  path: packageResourcePath(import.meta.url, 'src/prompts/help-how-to-config/SKILL.md'),\n  read: () => readPackageResource(import.meta.url, 'src/prompts/help-how-to-config/SKILL.md'),\n});\n","// Generated by @agimon-ai/po-build. Do not edit by hand.\nimport { defineServerPlugin, type PoServerSessionPlugin } from '@agimon-ai/po-core/serverPlugin';\nimport { composeServerProviderOverrides } from '@agimon-ai/po-core/serverPlugin';\nimport { composeRootHooks, composeRootInjects } from '@agimon-ai/po-core/extensionFile';\n\nimport rootSession from '../src/extensions/workspaces/sessions/(backend)/root.server';\nimport apiRoute from '../src/extensions/(backend)/api/settings/route.server';\nimport resourceHelpHowToConfig from '../src/extensions/workspaces/sessions/(backend)/resource/help-how-to-config.server';\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/* v8 ignore next -- generated normalization branch */\nconst defined = <T>(values: readonly (T | undefined)[]): T[] =>\n  values.filter((value): value is T => value !== undefined);\n\nexport const serverPlugin = defineServerPlugin({\n  name: '@agimon-ai/po-config',\n  providerOverrides: composeServerProviderOverrides(rootSession),\n  injects: composeRootInjects({ session: [rootSession] }),\n  global: (context) => ({\n    get api(): PoServerSessionPlugin['api'] { return defined([at(apiRoute, context)]); },\n  }),\n  workspace: (context) => ({\n    get api(): PoServerSessionPlugin['api'] { return defined([at(apiRoute, context)]); },\n  }),\n  session: async (context) => {\n    const scopeSession = await context.scopeRoot('session', rootSession, context);\n    const contextSession = { ...context, root: scopeSession.value };\n    return {\n      ...composeRootHooks(scopeSession),\n      get api(): PoServerSessionPlugin['api'] { return defined([at(apiRoute, context)]); },\n      get resources(): PoServerSessionPlugin['resources'] { return [at(resourceHelpHowToConfig, contextSession)]; },\n      services: [...(scopeSession.services ?? [])],\n      get activities(): PoServerSessionPlugin['activities'] { return [...(scopeSession.activities ?? [])]; },\n    };\n  },\n});\n\nexport default serverPlugin;\n"],"mappings":";;;;;;;;;;AAAA,MAAa,iBAAiB;AAC9B,MAAa,oBAAoB;CAC/B,MAAM;CACN,aACE;AACJ;;;;ACiBA,SAAgB,oBACd,QACA,WACA,IACA,UACe;CACf,MAAM,aAAa,GAAG,UAAU,UAAU,GAAG,OAAO,WAAW;CAC/D,IAAI,SAAS;CACb,MAAM,YAAY,6BAA6B,EAC7C,OAAO,cAAuC;EAC5C,MAAM,cAAc,aAAa,YAAY,KAAK,IAAI;EACtD,MAAM,UAAU,aAAa,OAAO,WAAW,gBAAgB;EAC/D,MAAM,OAAO,GAAG,aAAa,UAAU,kBAAkB,aAAa,MAAM,IAAI;EAChF,MAAM,UAAU,0BAA0B,MAAM;EAEhD,IAAI;GACF,QAAa,WAAW,CACtB,QAAQ,QACN,UAAU,QAAQ,QAAQ;IAAE;IAAM,OAAO;GAAU,CAAC,IAAI,UAAU,OAAO,OAAO;IAAE;IAAM,OAAO;GAAU,CAAC,CAC5G,CACF,CAAC;EACH,SAAS,OAAO;GACd,QAAQ,YAAY,mCAAmC,OAAO,KAAK,GAAG;EACxE;CACF,EACF,CAAC;CACD,OAAO,QAAQ,sBAAsB,SAAS;CAC9C,MAAM,YAAY,kBAAkB;EAClC,aAAa;EACb,aAAa;EACb,KAAK,UAAU;EACf,KAAK,UAAU;EACf,YAAY;EACZ,cAAc;CAChB,CAAC;CACD,IAAI,qBAAoC,QAAQ,QAAQ;CACxD,MAAM,eAAqB;EACzB,SAAS;EACT,QAAa,WAAW,CAAC,UAAU,QAAQ,CAAC,CAAC;CAC/C;CACA,UAAU,iBAAiB,SAAS,QAAQ,EAAE,MAAM,KAAK,CAAC;CAC1D,OAAO,aACC,YAAY;EAChB,SAAS;EACT,UAAU,oBAAoB,SAAS,MAAM;EAC7C,MAAM,QAAQ,WAAW,CAAC,UAAU,QA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