/** * @fileoverview Shell-completion script generator. * * Emits a sourceable completion script for bash, zsh, or fish that the * user drops into their shell init (or pipes directly into their * current shell to try it out). * * Usage: * opensip completion bash >> ~/.bashrc * opensip completion zsh >> ~/.zshrc * opensip completion fish > ~/.config/fish/completions/opensip.fish * * The emitted scripts are static — the user's shell sources them once, so * they complete fixed subcommand / flag names rather than querying the CLI * per keystroke (fast, portable, no version skew). What is NOT static is * how those names are produced: the subcommand list and each command's * flags are DERIVED from the live `CommandSpec`s at generation time (see * {@link CompletionInventory} / the `completion` command handler), so the * script can never drift from the real command surface the way a * hand-maintained flag list does. If dynamic value completion (e.g. * matching existing check slugs) is ever needed, that's an additive change * that can query `opensip fit --list` at completion time. */ import { type CommonFlagKey } from '@opensip-cli/contracts'; import type { CompletionInventory } from './completion-scripts.js'; export type { CompletionInventory } from './completion-scripts.js'; export type Shell = 'bash' | 'zsh' | 'fish'; /** Internal/machine-facing commands excluded from shell completion (host-spawned workers). */ export declare const INTERNAL_COMMANDS: ReadonlySet; /** Minimal structural view of a `CommandSpec` this module needs to read. */ export interface SpecLike { readonly name: string; readonly aliases?: readonly string[]; readonly commonFlags: readonly CommonFlagKey[]; readonly options?: readonly { readonly flag: string; }[]; /** * When set, this tool command is a ` ` sub-subcommand (the * ` ` grammar — see `CommandSpec.parent`, taxonomy Task 0.4). The * inventory then offers it as a leaf under `parent` (like a `plugin`/`sessions` * group leaf) and keys its flags under `${parent} ${name}`. Omitted ⇒ a flat * top-level command. */ readonly parent?: string; } /** A grouped command leaf whose completion surface is derived like any other spec. */ export interface GroupLeafLike { readonly name: string; readonly aliases?: readonly string[]; readonly commonFlags?: readonly CommonFlagKey[]; readonly options?: readonly { readonly flag: string; }[]; } /** One action-less group (`runs` / `sessions` / `tools`) and its leaf commands. */ export interface GroupLike { readonly name: string; readonly leaves: readonly GroupLeafLike[]; } /** * One pack-supporting tool's `plugin` group, keyed by the primary verb it mounts * under (`fit`/`sim`). The `plugin` parent is offered as a leaf under that verb * (`opensip fit ` ⇒ `… plugin`), and the `add|list|remove|sync` leaves are * registered under the `${parentVerb} plugin` path for deeper completion. */ export interface ToolPluginGroupLike { readonly parentVerb: string; readonly parentAliases?: readonly string[]; readonly leaves: readonly GroupLeafLike[]; } /** * Extract the canonical long `--flag` from a Commander flag string — * `'-y, --yes'` → `'--yes'`, `'--no-cache'` → `'--no-cache'`, * `'--resolution'` → `'--resolution'`. Returns `undefined` for a short-only * flag (none exist in the current surface, but the caller filters defensively). */ export declare function extractLongFlag(flags: string): string | undefined; /** * The long flags a single command exposes: its resolved {@link CommonFlagKey} * common flags + its option long forms + Commander's built-in `--help`. Pure — * the single place a spec's flag surface is turned into completion candidates. */ export declare function specLongFlags(spec: SpecLike): readonly string[]; /** * Assemble the completion inventory from the live specs. Pure: callers pass * the tool command specs (from the populated `ToolRegistry`), the top-level * host specs, and the action-less groups; this turns them into the flag / * subcommand maps the script builders consume. * * Internal commands are filtered out by `input.internalCommands` — the * descriptor-driven `visibility: 'internal'` set the host computes from the live * tool registry (`internalCommandNames`), so completion and the `--help` hide * pass key on the SAME source. Defaults to the static {@link INTERNAL_COMMANDS} * fallback when omitted (tests / callers without a registry). The * `OPENSIP_CLI_SHOW_INTERNAL=1` reveal is applied at the call site: the host * passes an EMPTY set to skip filtering when the override is on. */ export declare function assembleCompletionInventory(input: { readonly toolSpecs: readonly SpecLike[]; readonly hostSpecs: readonly SpecLike[]; readonly groups: readonly GroupLike[]; /** * The DOMAIN-BOUND per-tool `plugin` groups (mounted under each pack-supporting * tool primary). Folded into the group map so completion offers `plugin` under * the tool verb and `add|list|remove|sync` under `${parentVerb} plugin`. Optional * so callers without tools omit it. */ readonly toolPluginGroups?: readonly ToolPluginGroupLike[]; readonly internalCommands?: ReadonlySet; }): CompletionInventory; /** * Render the requested shell's completion script from an already-assembled * inventory. The per-shell renderers live in `completion-scripts.ts`; this * function's only job is dispatch plus supplying the ADR-0021 common-flag * fallback list (`COMMON_FLAGS`, owned by this module) to the shells that * use it. */ export declare function buildCompletionScript(shell: Shell, inventory: CompletionInventory): string; export declare function printCompletionScript(shell: Shell, inventory: CompletionInventory, write?: (s: string) => void): void; //# sourceMappingURL=completion.d.ts.map