{"version":3,"file":"composition.cjs","names":["fs","path","parseArgs","readHarnessState","getHarnessState","runDirectory","os","createMapResolvers","PERSONA_ENTRY","loadMajorModesConfig","resolveExtensionComposition","MUTE_ENV","packageAttribution","pathToFileURL","withExtensionSource","findSyncedRoot","readSyncState","EXTERNAL_EXTENSIONS_ENV","alreadyComposed","COMPOSED_ENV","loadHarnessState","readBundleStatus","computeInputsHash"],"sources":["../../../src/builders/cli/composition.ts"],"sourcesContent":["import fs from 'node:fs';\nimport os from 'node:os';\nimport path from 'node:path';\nimport { pathToFileURL } from 'node:url';\n\nimport { loadMajorModesConfig, type MajorModesConfig } from '@agimon-ai/doompi-config/majorModes';\nimport { alreadyComposed } from '@agimon-ai/doompi-core/child-process';\nimport { withExtensionSource } from '@agimon-ai/doompi-ui/extensionName';\nimport { type ExtensionAPI, parseArgs } from '@earendil-works/pi-coding-agent';\n\nimport {\n  createHarnessSession,\n  getHarnessState,\n  type HarnessState,\n  loadHarnessState,\n  readHarnessState,\n  updateHarnessState,\n} from '../../composition/harnessState';\nimport {\n  computeInputsHash,\n  createMapResolvers,\n  readSyncState,\n  runDirectory,\n  type SyncState,\n} from '../../composition/syncState';\nimport type { HarnessPreset } from '../../composition/types/harness';\nimport { findSyncedRoot, readBundleStatus } from './bootstrapLocator';\nimport { COMPOSED_ENV, EXTERNAL_EXTENSIONS_ENV, MUTE_ENV } from './compositionState';\nimport { PERSONA_ENTRY, packageAttribution, resolveExtensionComposition } from './extensionAssembler';\nimport { configurePreset } from './harnessContext';\n\nexport { findSyncedRoot } from './bootstrapLocator';\nexport { alreadyComposed } from '@agimon-ai/doompi-core/child-process';\nexport { COMPOSED_ENV, EXTERNAL_EXTENSIONS_ENV, MUTE_ENV } from './compositionState';\n\n/**\n * The runtime half of `doom-pi sync`.\n *\n * Pi's own config carries a single entry, the doom-pi extension, and this is\n * what that entry runs: hydrate the harness environment, apply the startup\n * flags, then load the extension set the matrix selects. It runs again on every\n * `/reload`, which is what lets `/mode` swap the set without a restart,\n * since Pi rebuilds its extension runner from whatever a reload produced.\n */\n\nconst ENABLED_FLAG = '1';\nconst SUBAGENT_AGENT_DIRS_ENV = 'PI_SUBAGENT_EXTRA_AGENT_DIRS';\nconst SUBAGENT_SKILL_DIRS_ENV = 'PI_SUBAGENT_EXTRA_SKILL_DIRS';\nconst DOMAIN_SEPARATOR = ',';\nconst PRIVATE_DIRECTORY_MODE = 0o700;\nconst DOMAIN_APPLY_MODULE = '@agimon-ai/doompi-domain/apply';\nconst SELECTION_SWITCH_MODULE = '@agimon-ai/doompi-config/selectionSwitch';\nconst NOT_SYNCED = 'doompi is configured for Pi but this repository was never synced. Run doompi sync.';\nconst UNUSABLE_STATE_MESSAGE = 'doompi could not read its synchronized state. Run doompi sync.';\nconst TIMING_ENABLED = process.env.DOOMPI_TIMING === ENABLED_FLAG || process.env.PI_TIMING === ENABLED_FLAG;\n\nexport const DOOM_FLAGS = {\n  majorMode: 'major-mode',\n  domains: 'domains',\n  profile: 'profile',\n  mute: 'mute',\n} as const;\n\n/** Removed flag, reported rather than ignored when a synced session passes it. */\nexport const REMOVED_LAYER_FLAG = 'layer';\n\nexport interface StartupFlags {\n  majorMode?: string;\n  domains?: string[];\n  profile?: string;\n  mute: boolean;\n  /** True when the caller passed the removed `--layer` flag. */\n  removedLayer: boolean;\n}\n\nexport interface ComposeOutcome {\n  /** Everything that went wrong, reported once the session can show messages. */\n  problems: string[];\n  /** Config changed since the last sync, which is a prompt to re-sync. */\n  stale: boolean;\n  loaded: string[];\n}\n\nfunction message(error: unknown): string {\n  return error instanceof Error ? error.message : String(error);\n}\n\nfunction realPath(target: string): string {\n  try {\n    return fs.realpathSync(target);\n  } catch {\n    return path.resolve(target);\n  }\n}\n\n/**\n * True when this process was handed the doom extension set on the command line.\n *\n * The launcher and detached Doom Team children both pass the composed list as\n * `--extension` arguments, and Pi merges those with whatever project settings\n * declare. Composing again here would load every extension twice, which Pi\n * reports as each tool and flag conflicting with itself.\n *\n * Matching against the synced paths rather than the mere presence of\n * `--extension` keeps an unrelated one-off, `pi -e ./debug.ts`, from silently\n * costing the user their whole setup.\n */\nexport function extensionsProvidedExternally(argv: string[], resolved: Record<string, string>): boolean {\n  const { extensions } = parseArgs(argv);\n  if (!extensions || extensions.length === 0) return false;\n  const composed = new Set(Object.values(resolved).map(realPath));\n  return extensions.some((entry) => composed.has(realPath(entry)));\n}\n\n/**\n * Opens this process's session from what sync pinned.\n *\n * The synced record is decoded underneath the live environment, so an inherited\n * value still wins: a launcher run, a nested session, or a CI override is more\n * specific than anything sync wrote. The result becomes the session's state\n * file, which is the authority from here on; the environment it publishes is\n * for the bash hooks and the packages that can only read one.\n */\nexport async function startSyncedSession(\n  state: SyncState,\n  repoRoot: string,\n  environment: NodeJS.ProcessEnv = process.env,\n): Promise<HarnessState> {\n  const directory = await prepareRunDirectory(repoRoot, environment);\n  const harness: HarnessState = {\n    ...readHarnessState({ ...state.env, ...environment }),\n    // Recorded separately because no variable carries them.\n    ...state.fileState,\n    // Every synced process gets private mutable staging. The source content\n    // identity is unchanged because the projection fingerprint excludes it.\n    mcpProjection: {\n      ...state.fileState.mcpProjection,\n      stagingDirectory: directory,\n    },\n    temporaryDirectory: directory,\n  };\n  createHarnessSession(harness, { directory, environment });\n  // The profile's own defaults, which the launcher applies at spawn. They are\n  // recorded as a map rather than as variables so /profile can tell which ones\n  // it owns when it swaps them out later.\n  for (const [key, value] of Object.entries(harness.profileEnvironment)) {\n    if (environment[key] === undefined) environment[key] = value;\n  }\n  return harness;\n}\n\n/**\n * Reads the doom flags off the command line.\n *\n * Pi collects unrecognized flags for extensions but hands their values back\n * only after every extension has loaded, which is too late to decide what to\n * load. Parsing argv with Pi's own parser keeps the value rules identical.\n */\nexport function readStartupFlags(argv: string[]): StartupFlags {\n  const { unknownFlags } = parseArgs(argv);\n  const text = (name: string): string | undefined => {\n    const value = unknownFlags.get(name);\n    return typeof value === 'string' && value.trim() ? value.trim() : undefined;\n  };\n  const domains = text(DOOM_FLAGS.domains);\n  return {\n    majorMode: text(DOOM_FLAGS.majorMode),\n    domains: domains\n      ?.split(DOMAIN_SEPARATOR)\n      .map((name) => name.trim())\n      .filter(Boolean),\n    profile: text(DOOM_FLAGS.profile),\n    mute: unknownFlags.get(DOOM_FLAGS.mute) !== undefined,\n    removedLayer: unknownFlags.get(REMOVED_LAYER_FLAG) !== undefined,\n  };\n}\n\n/** Registers the flags so Pi accepts them and lists them in `pi --help`. */\nexport function registerDoomFlags(pi: Pick<ExtensionAPI, 'registerFlag'>): void {\n  pi.registerFlag(DOOM_FLAGS.majorMode, {\n    type: 'string',\n    description: 'Named major mode from .doom/modes.yaml',\n  });\n  pi.registerFlag(DOOM_FLAGS.domains, { type: 'string', description: 'Comma-separated content domains' });\n  pi.registerFlag(DOOM_FLAGS.profile, { type: 'string', description: 'Persona and env from .doom/profiles.yaml' });\n  pi.registerFlag(DOOM_FLAGS.mute, { type: 'boolean', description: 'Disable the notification extension' });\n}\n\n/**\n * Applies the startup flags through the same switchers the slash commands use.\n *\n * A bad value is collected rather than thrown: a factory that throws takes the\n * whole doom setup down with it, which is far worse than one unapplied flag.\n */\nexport async function applyStartupFlags(\n  flags: StartupFlags,\n  majorModesConfig: MajorModesConfig,\n  repoRoot: string,\n  problems: string[],\n): Promise<void> {\n  // Reported rather than ignored: Pi hands unrecognized flags to extensions, so\n  // a stale `--layer dev` would otherwise start a session on the wrong mode\n  // without saying anything.\n  if (flags.removedLayer) problems.push(`--${REMOVED_LAYER_FLAG} was replaced by --${DOOM_FLAGS.majorMode}`);\n  if (flags.majorMode) {\n    try {\n      const { applyMajorMode } = await import(SELECTION_SWITCH_MODULE);\n      applyMajorMode(majorModesConfig, flags.majorMode, getHarnessState());\n    } catch (error) {\n      problems.push(`--${DOOM_FLAGS.majorMode} ${flags.majorMode}: ${message(error)}`);\n    }\n  }\n  if (flags.domains && flags.domains.length > 0) {\n    try {\n      const { applyDomains } = await import(DOMAIN_APPLY_MODULE);\n      await applyDomains(flags.domains, getHarnessState());\n    } catch (error) {\n      problems.push(`--domains ${flags.domains.join(DOMAIN_SEPARATOR)}: ${message(error)}`);\n    }\n  }\n  if (flags.profile) {\n    try {\n      const [{ applyProfile }, { resolveProfile }] = await Promise.all([\n        import(SELECTION_SWITCH_MODULE),\n        import('@agimon-ai/doompi-config/profiles'),\n      ]);\n      await applyProfile(resolveProfile(repoRoot, flags.profile), getHarnessState());\n    } catch (error) {\n      problems.push(`--profile ${flags.profile}: ${message(error)}`);\n    }\n  }\n}\n\n/**\n * Points harness state at a per-process directory before anything writes there.\n *\n * The synced directory is a baseline that every session reads; live switches\n * materialize into this one instead, so a second session in the same repository\n * cannot overwrite what the first is using.\n */\nexport async function prepareRunDirectory(\n  repoRoot: string,\n  environment: NodeJS.ProcessEnv = process.env,\n): Promise<string> {\n  const directory = runDirectory(repoRoot, process.pid, environment.HOME ?? os.homedir());\n  await fs.promises.mkdir(directory, { mode: PRIVATE_DIRECTORY_MODE, recursive: true });\n  // Through the store rather than the environment: the state file is the\n  // authority, and a switcher reading a stale directory would write a live\n  // session's resources into the wrong place.\n  updateHarnessState({ temporaryDirectory: directory }, environment);\n  return directory;\n}\n\n/** Removes this session's scratch directory. */\nexport async function cleanupRunDirectory(\n  repoRoot: string,\n  environment: NodeJS.ProcessEnv = process.env,\n): Promise<void> {\n  await fs.promises.rm(runDirectory(repoRoot, process.pid, environment.HOME ?? os.homedir()), {\n    recursive: true,\n    force: true,\n  });\n}\n\n/**\n * Builds the ordered list of extensions to load for the current state.\n *\n * Returns entries in actual Pi factory activation order. CLI argument adaptation\n * remains a launcher concern and synchronized bundles preserve this same order.\n */\nexport interface ComposedRuntimeLoadPlan {\n  readonly entries: string[];\n  readonly fingerprint: string;\n}\n\n/** Builds the canonical synchronized activation plan. */\nexport async function composeRuntimeLoadPlan(\n  state: SyncState,\n  harness: HarnessState = getHarnessState(),\n  environment: NodeJS.ProcessEnv = process.env,\n): Promise<ComposedRuntimeLoadPlan> {\n  const repoRoot = harness.root ?? state.root;\n  const resolvers = createMapResolvers(state.resolved, state.compiled);\n  const context = {\n    agents: harness.agents,\n    // Exiting when the agent settles is a launcher decision with no synced\n    // equivalent: a session started by hand is meant to stay open.\n    autoStop: false,\n    preset: state.selection.preset,\n    personaEntry: resolvers.packageEntry(PERSONA_ENTRY),\n    majorMode: harness.majorMode,\n    layers: [...harness.layers],\n    majorModesConfig: loadMajorModesConfig(repoRoot),\n    resolvers,\n  };\n\n  // A state field, so it goes through the store: Doom Team reads it from the\n  // environment the store publishes when it builds a child's spawn snapshot.\n  const composition = resolveExtensionComposition({\n    ...context,\n    mute: environment[MUTE_ENV] === ENABLED_FLAG,\n  });\n  updateHarnessState(\n    {\n      childExtensions: [...composition.childActivation],\n      compositionFingerprint: composition.fingerprint,\n      packageAttribution: packageAttribution(composition),\n    },\n    environment,\n  );\n  if (harness.agents) {\n    environment[SUBAGENT_AGENT_DIRS_ENV] = harness.agentDirectories.join(path.delimiter);\n    environment[SUBAGENT_SKILL_DIRS_ENV] = harness.skillDirectories.join(path.delimiter);\n  }\n  const entries = [...composition.parentActivation];\n  const bundle = state.bundles?.[composition.fingerprint];\n  return {\n    entries: bundle ? [bundle] : entries,\n    fingerprint: composition.fingerprint,\n  };\n}\n\n/** Compatibility view for callers that only need Pi extension entries. */\nexport async function composeLoadOrder(\n  state: SyncState,\n  harness: HarnessState = getHarnessState(),\n  environment: NodeJS.ProcessEnv = process.env,\n): Promise<string[]> {\n  return (await composeRuntimeLoadPlan(state, harness, environment)).entries;\n}\n\n/**\n * Imports each extension and hands it a source-aware view of the Pi API.\n *\n * Every Pi extension entry is a factory of the same shape, so one extension can\n * activate the rest. The view delegates to the same host API while retaining the\n * entry path for tools registered through a composed loader. Failures are per\n * entry: one unloadable module must not cost the session everything after it.\n */\nexport async function loadComposedExtensions(\n  pi: ExtensionAPI,\n  entries: string[],\n  problems: string[],\n): Promise<string[]> {\n  const loaded: string[] = [];\n  for (const entry of entries) {\n    const importStartedAt = performance.now();\n    let module: { default?: unknown };\n    try {\n      module = (await import(pathToFileURL(entry).href)) as { default?: unknown };\n      if (TIMING_ENABLED) {\n        process.stderr.write(`[doompi:timing] import ${(performance.now() - importStartedAt).toFixed(1)}ms ${entry}\\n`);\n      }\n    } catch (error) {\n      problems.push(`${entry}: ${message(error)}`);\n      continue;\n    }\n    if (typeof module.default !== 'function') {\n      problems.push(`${entry}: does not export an extension factory`);\n      continue;\n    }\n    const factoryStartedAt = performance.now();\n    try {\n      await (module.default as (api: ExtensionAPI) => void | Promise<void>)(withExtensionSource(pi, entry));\n      if (TIMING_ENABLED) {\n        process.stderr.write(\n          `[doompi:timing] factory ${(performance.now() - factoryStartedAt).toFixed(1)}ms ${entry}\\n`,\n        );\n      }\n      loaded.push(entry);\n    } catch (error) {\n      problems.push(`${entry}: ${message(error)}`);\n    }\n  }\n  return loaded;\n}\n\nexport interface ComposeOptions {\n  cwd?: string;\n  argv?: string[];\n  environment?: NodeJS.ProcessEnv;\n}\n\n/**\n * Runs the whole synced startup for one Pi session.\n *\n * Never throws: whatever fails is reported through the outcome so the session\n * still starts and can say what is wrong.\n */\nexport async function composeDoomSession(pi: ExtensionAPI, options: ComposeOptions = {}): Promise<ComposeOutcome> {\n  const environment = options.environment ?? process.env;\n  const problems: string[] = [];\n  const homeDirectory = environment.HOME ?? os.homedir();\n  const repoRoot = findSyncedRoot(options.cwd ?? process.cwd(), homeDirectory);\n  if (!repoRoot) return { problems: [NOT_SYNCED], stale: false, loaded: [] };\n\n  let state: SyncState | undefined;\n  try {\n    state = readSyncState(repoRoot, homeDirectory);\n  } catch (error) {\n    return { problems: [message(error)], stale: false, loaded: [] };\n  }\n  if (!state) return { problems: [NOT_SYNCED], stale: false, loaded: [] };\n\n  const argv = options.argv ?? process.argv.slice(2);\n  // The launcher and Doom Team children compose the set themselves and pass it\n  // in, so this entry has nothing left to do but stay out of the way.\n  if (\n    environment[EXTERNAL_EXTENSIONS_ENV] === ENABLED_FLAG ||\n    extensionsProvidedExternally(argv, { ...state.resolved, ...state.bundles })\n  ) {\n    return { problems: [], stale: false, loaded: [] };\n  }\n\n  configurePreset({ preset: state.selection.preset as HarnessPreset, piArgs: [] }, environment);\n\n  // Only the first load opens a session. A reload finds the pointer this set\n  // and reads the file back, which is what carries a live /domains or /profile\n  // switch across the reload instead of resetting it to what sync pinned.\n  if (!alreadyComposed(environment)) {\n    environment[COMPOSED_ENV] = ENABLED_FLAG;\n    await startSyncedSession(state, repoRoot, environment);\n    const flags = readStartupFlags(argv);\n    if (flags.mute) environment[MUTE_ENV] = ENABLED_FLAG;\n    await applyStartupFlags(flags, loadMajorModesConfig(repoRoot), repoRoot, problems);\n  }\n\n  let loadPlan: ComposedRuntimeLoadPlan;\n  try {\n    // Read back through the store rather than from this process: the startup\n    // flags may have switched the layer or the domains a moment ago, and the\n    // environment being managed is not always this process's own.\n    loadPlan = await composeRuntimeLoadPlan(state, loadHarnessState(environment).state, environment);\n  } catch (error) {\n    return { problems: [...problems, message(error)], stale: false, loaded: [] };\n  }\n\n  const selectedBundle = state.bundles?.[loadPlan.fingerprint];\n  if (selectedBundle) {\n    try {\n      const status = readBundleStatus(repoRoot, loadPlan.fingerprint, homeDirectory);\n      if (!status.fresh || status.bundle !== selectedBundle) {\n        return { problems: [...problems, UNUSABLE_STATE_MESSAGE], stale: false, loaded: [] };\n      }\n    } catch {\n      return { problems: [...problems, UNUSABLE_STATE_MESSAGE], stale: false, loaded: [] };\n    }\n  }\n\n  const loaded = await loadComposedExtensions(pi, loadPlan.entries, problems);\n  return {\n    problems,\n    stale:\n      computeInputsHash(repoRoot, state.selection, homeDirectory) !== state.inputsHash ||\n      (loadHarnessState(environment).state.majorMode === state.selection.majorMode &&\n        loadPlan.fingerprint !== state.compositionFingerprint),\n    loaded,\n  };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,MAAM,eAAe;AACrB,MAAM,0BAA0B;AAChC,MAAM,0BAA0B;AAChC,MAAM,mBAAmB;AACzB,MAAM,yBAAyB;A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