/** * mount-command-spec — the host-owned layer that turns a declarative * {@link CommandSpec} (core, Phase 0) into a wired Commander command. * * Generalizes {@link mountResultCommand}: it mounts ANY command (tool or host) * from its typed spec — translating each `OptionSpec`/`ArgSpec` into Commander * wiring, applying the shared common flags (ADR-0021), and owning the uniform * `parse → handler → dispatch output → map error → exit` pipeline. Tools never * touch Commander; they export specs and the host mounts them (north-star §5.4). * * The single output-dispatch seam — {@link dispatchOutput} — wraps every machine * output in a `CommandOutcome` serialized through the one `renderOutcome` seam. * The wrap lives in the host emit seams this delegates to (`emitCommandResult`, * `ctx.emitEnvelope`), so the handler contract stayed byte-identical (§5.5). */ import { type CliProgram } from '@opensip-cli/contracts'; import { type CommandSpec, type ToolCliContext } from '@opensip-cli/core'; import { type RunActionHooks } from '../bootstrap/run-plane.js'; export type { CommandMountContext } from '@opensip-cli/core'; import type { CliCommandsContext } from './shared.js'; import type { CommandActionScopeRunner } from '../bootstrap/command-action-scope-runner.js'; /** * A {@link CommandSpec} whose handler receives the concrete host * {@link ToolCliContext} (render/envelope/live-view emitters), not the kernel's * unconstrained {@link CommandContext} marker. The host mounts THIS shape — the * mounter is the only place that knows the real context type, so it pins it * here. Tools author specs with `defineCommand(...)`. */ export type HostCommandSpec> = CommandSpec; /** * Mount a declarative {@link CommandSpec} onto `program` as a fully wired * Commander command. * * Steps (mirroring each tool's former hand-rolled `register()` body, now * host-owned and uniform): * 1. `program.command(name)` + description + aliases. * 2. `applyCommonFlags(cmd, spec.commonFlags)` — the ADR-0021 registry flags. * `cwd` (the only computed default) is seeded with `process.cwd()`. * 3. Each {@link OptionSpec} → a Commander `Option` (value vs boolean, * `negatable` `--no-` form, `default` / `arrayDefault`, `choices`, * `parse` argParser, `variadic`, `required` mandatory). * 4. Each {@link ArgSpec} → `cmd.argument(...)` (variadic / optional bracketing). * 5. `cmd.action(...)` → run `spec.handler(opts, ctx)` → {@link dispatchOutput} * → on a thrown {@link ToolError}, `mapToolErrorToExitCode` → `ctx.setExitCode`. * * @param program The Commander program to mount onto — the root `CliProgram` * for a flat command, or a parent command (a host subcommand * group, or a tool's primary command for a `CommandSpec.parent` * nested child) when nesting. `program.command(...)` mounts onto * whatever object it is called on, so nesting is purely a matter * of which program is passed. * @param spec The declarative command surface the tool/host exported. * @param ctx The per-invocation mount context (render/envelope/live-view * emitters, exit-code setter). Tool handlers may receive a wider * `ToolCliContext`; this is the mount plane's structural subset. * @param hooks Host-only run-lifecycle hooks (`beginRun`, `completeRun`, …). * Omitted for lean host-command contexts that carry no run plane. * @param actionScopeRunner Invocation-local bridge that binds the RunScope * across Commander's async pre-action/action continuation. * @returns The mounted Commander command, so a caller nesting children * (e.g. `mountOneTool`) can mount sub-subcommands onto it. */ export declare function mountCommandSpec(program: CliProgram, spec: CommandSpec, ctx: CliCommandsContext, hooks?: RunActionHooks, actionScopeRunner?: CommandActionScopeRunner): CliProgram; export declare function mountCommandSpec(program: CliProgram, spec: CommandSpec, ctx: ToolCliContext, hooks?: RunActionHooks, actionScopeRunner?: CommandActionScopeRunner): CliProgram; export { dispatchOutput, runCommandSpecAction } from './run-command-spec-action.js'; //# sourceMappingURL=mount-command-spec.d.ts.map