import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
import "../chunk-J2PHTRHC.mjs";
import {
  capabilities_exports
} from "../chunk-OQYHRZYF.mjs";
import {
  activation_events_exports
} from "../chunk-JAZVHID3.mjs";
import "../chunk-Z4TJPSMP.mjs";
import {
  plugin_manager_exports
} from "../chunk-XHAKT6UD.mjs";
import "../chunk-7OWSHPYK.mjs";
import {
  plugin_exports
} from "../chunk-DZ2XLAGI.mjs";
import {
  capability_exports
} from "../chunk-64IMLAS2.mjs";
import "../chunk-HSLMI22Q.mjs";

// src/cli/cli.ts
import * as Command from "@effect/cli/Command";
import * as Effect from "effect/Effect";
import * as Layer from "effect/Layer";
import { invariant } from "@dxos/invariant";
var __dxlog_file = "/__w/dxos/dxos/packages/sdk/app-framework/src/cli/cli.ts";
var defaultPluginLoader = (plugins) => (id) => Effect.sync(() => {
  const plugin = plugins.find((plugin2) => plugin2.meta.id === id);
  invariant(plugin, `Plugin not found: ${id}`, {
    F: __dxlog_file,
    L: 19,
    S: void 0,
    A: [
      "plugin",
      "`Plugin not found: ${id}`"
    ]
  });
  return plugin;
});
var createCliApp = Effect.fn(function* ({ rootCommand, subCommands: subCommandsProp, pluginManager: pluginManagerProp, pluginLoader: pluginLoaderProp, plugins: pluginsProp = [], core: coreProp, enabled: enabledProp = [], safeMode = false }) {
  const plugins = pluginsProp;
  const core = coreProp ?? plugins.map(({ meta }) => meta.id);
  const pluginLoader = pluginLoaderProp ?? defaultPluginLoader(plugins);
  const enabled = safeMode ? [] : enabledProp;
  const manager = pluginManagerProp ?? plugin_manager_exports.make({
    pluginLoader,
    plugins,
    core,
    enabled
  });
  manager.capabilities.contribute({
    interface: capabilities_exports.PluginManager,
    implementation: manager,
    module: "dxos.org/app-framework/plugin-manager"
  });
  manager.capabilities.contribute({
    interface: capabilities_exports.AtomRegistry,
    implementation: manager.registry,
    module: "dxos.org/app-framework/atom-registry"
  });
  yield* manager.activate(activation_events_exports.Startup);
  const layers = manager.capabilities.getAll(capabilities_exports.Layer);
  const capabilityServiceLayer = Layer.succeed(capability_exports.Service, manager.capabilities);
  const pluginServiceLayer = Layer.succeed(plugin_exports.Service, manager);
  const layer = Layer.mergeAll(capabilityServiceLayer, pluginServiceLayer, ...layers);
  const pluginCommands = manager.capabilities.getAll(capabilities_exports.Command);
  const subCommands = subCommandsProp ? [
    ...subCommandsProp,
    ...pluginCommands
  ] : pluginCommands;
  invariant(subCommands.length > 0, "No subcommands provided", {
    F: __dxlog_file,
    L: 103,
    S: this,
    A: [
      "subCommands.length > 0",
      "'No subcommands provided'"
    ]
  });
  const command = rootCommand.pipe(Command.withSubcommands(subCommands));
  return {
    command,
    layer
  };
});
export {
  createCliApp
};
//# sourceMappingURL=index.mjs.map
