import type { Accessor } from '../accessor/base.ts'; import type { IndexCacheStore } from '../cache/index/index.ts'; import { IOResult, type ByteSource } from '../io/types.ts'; import type { Limit, PathSpec } from '../types.ts'; import type { Runtime } from '../runtime/base.ts'; import type { DispatchFn } from '../runtime/types.ts'; import type { NamespaceView, ReaddirPath, SessionView, StatPath } from '../ops/types.ts'; import type { AggregateResult } from './builtin/aggregators.ts'; import { CommandSpec, Option, type FlagValue } from './spec/types.ts'; /** * The execution context `Mount.executeCmd` takes: everything the * workspace supplies for one invocation beyond the parsed line — the * one bag its fifth argument has always been, now named (mirrors * Python's `ExecContext`, commands/config.py). `executeCmd` re-boxes * these onto `CommandOpts` beside the facts only the mount can supply * (mountPrefix, index, filetypeFns), so every field is spelled exactly * as `CommandOpts` spells it — pinned by a mapped type in * workspace/mount/mount.test.ts. The two exceptions are execution * controls `executeCmd` consumes itself rather than forwards: * `limitOverride` (the caller-resolved limit guard), while `signal` * both rides onto `CommandOpts` and arms the guard. `sessionView` * stays although no opts reader wants it today, because * `CLIDoors.sessionView` has production readers and the doors record * is pinned to be a subset of `CommandOpts`. */ export interface ExecContext { stdin?: ByteSource | null; cwd?: string; dispatch?: DispatchFn; sessionId?: string; env?: Record; sessionView?: SessionView; execAllowed?: boolean; execPathAllowed?: (virtual: string) => boolean; runtime?: Runtime; ns?: NamespaceView; statPath?: StatPath; readdirPath?: ReaddirPath; signal?: AbortSignal; limitOverride?: Limit | null; } /** * The dispatcher context of one command invocation, as one value. * `Mount.executeCmd` constructs it once and hands it to every handler * as the fourth argument; the provision path builds the same bag with * `command`/`spec` set. Mirrors Python's `CommandOpts` * (commands/config.py) field for field. */ export interface CommandOpts { stdin: ByteSource | null; flags: Record; filetypeFns: Record | null; mountPrefix?: string; cwd: string; command?: string; spec?: CommandSpec; index?: IndexCacheStore | null; dispatch?: DispatchFn; sessionId?: string; env?: Record; sessionView?: SessionView; execAllowed?: boolean; /** * Whether code may be loaded from one path, for an interpreter's file * operand; absent outside a workspace, where `execAllowed` answers * for files too. */ execPathAllowed?: (virtual: string) => boolean; runtime?: Runtime; ns?: NamespaceView; statPath?: StatPath; readdirPath?: ReaddirPath; signal?: AbortSignal; timeoutSeconds?: number; } export type CommandFnResult = [ByteSource | null, IOResult] | null; /** * Command function signature mirroring Python's * `async def cat(accessor, paths, *texts, stdin=None, n=False, **_extra)`. * TS gets four positional params: accessor, paths, texts (Python `*texts`), * and an opts bag (Python `**kwargs`). Generic on the accessor type so * resource-specific commands can declare e.g. `accessor: RAMAccessor`. */ export type CommandFn = (accessor: A, paths: PathSpec[], texts: string[], opts: CommandOpts) => Promise | CommandFnResult; export type ProvisionFn = (accessor: A, paths: PathSpec[], texts: string[], opts: CommandOpts) => unknown; export type AggregateFn = (results: AggregateResult[]) => Uint8Array; export interface RegisteredCommandInit { name: string; spec: CommandSpec; resource: string | null; filetype?: string | null; fn: CommandFn; provisionFn?: ProvisionFn | null; aggregate?: AggregateFn | null; src?: string | null; dst?: string | null; write?: boolean; limit?: Limit | null; } export interface RegisteredCommandOverrides { fn?: CommandFn; provision?: ProvisionFn | null; } export declare class RegisteredCommand { readonly name: string; readonly spec: CommandSpec; readonly resource: string | null; readonly filetype: string | null; readonly fn: CommandFn; readonly provisionFn: ProvisionFn | null; readonly aggregate: AggregateFn | null; readonly src: string | null; readonly dst: string | null; readonly write: boolean; readonly limit: Limit | null; constructor(init: RegisteredCommandInit); /** Return an independent command definition with selected changes. */ withOverrides(overrides: RegisteredCommandOverrides): RegisteredCommand; } /** Immutable command array with exact name/filetype lookup. */ export declare class CommandCatalog extends Array { #private; constructor(commands: readonly RegisteredCommand[]); get size(): number; toArray(): readonly RegisteredCommand[]; get(name: string, filetype?: string | null): RegisteredCommand | null; require(name: string, filetype?: string | null): RegisteredCommand; private static key; static get [Symbol.species](): ArrayConstructor; } export interface CommandOptions { name: string; resource: string | string[] | null; spec: CommandSpec; fn: CommandFn; filetype?: string | null; provision?: ProvisionFn | null; aggregate?: AggregateFn | null; write?: boolean; limit?: Limit | null; } export declare const HELP_OPTION: Option; /** * Version output when argv asks a command for the injected --version. * Null when the command declares its own --version, when the flag is * absent, or when it sits after the `--` end-of-options marker. */ export declare function versionRequest(name: string, spec: CommandSpec | null, argv: string[]): Uint8Array | null; export declare function command(options: CommandOptions): RegisteredCommand[]; export interface CrossCommandOptions { name: string; src: string; dst: string; spec: CommandSpec; fn: CommandFn; } export declare function crossCommand(options: CrossCommandOptions): RegisteredCommand; //# sourceMappingURL=config.d.ts.map