Implementation:20000419 Fauxnix Command Registry
| Knowledge Sources | |
|---|---|
| Domains | Command_Dispatch, Code_Generation, PowerShell |
| Last Updated | 2026-10-26 00:00 GMT |
Overview
Concrete command dispatch table that maps bash command names to PowerShell generator functions, with shared helpers for strict option validation and PowerShell string escaping.
Description
The Command Registry (src/registry.ts) is a Map<string, Handler> where each key is a bash command name (ls, grep, tar, ...) and each value is a generator function (args: Word[], ctx: PipelineCtx) => string that returns a block of PowerShell statements following the Fauxnix contract. register/registerAll add generators; lookup(name) retrieves one; registeredNames() returns the sorted list. The registry also provides shared helpers: psStr (single-quoted PowerShell string escaping), psErr/psErr2 (bash-style stderr line + exit-flag), parseArgs/parseWords (word-preserving argv parsing with bundled short flags, long options, and value-taking options), and CommandSpec for strict GNU-style option validation. src/commands/install-all.ts registers all per-command generators from the src/commands/*.ts modules.
Usage
Call lookup(name) during translation to get a command's generator. Call registeredNames() for the list verb, check output, and MCP tool descriptions. The registry is populated at import time via src/commands/install-all.js, which every entry point imports for its side effects.
Code Reference
Source Location
- Repository: fauxnix
- File: src/registry.ts (L1-584), src/commands/install-all.ts (L1-24)
- Lines: register/lookup/registeredNames L45-58; psStr L66-80; psErr/psErr2 L83-89; parseArgs L111-147; parseWords L170+; PipelineCtx/Handler L32-41
Signature
export interface PipelineCtx {
position: 'first' | 'middle' | 'last';
hasStdin: boolean;
translationMode?: 'execute' | 'pure';
}
export type Handler = (args: Word[], ctx: PipelineCtx) => string;
export function register(name: string, handler: Handler): void;
export function registerAll(mod: Record<string, Handler>): void;
export function lookup(name: string): Handler | undefined;
export function registeredNames(): string[];
export function psStr(s: string): string;
export function psErr(cmd: string, msg: string): string;
export function parseArgs(args: { toDisplay: string }[], valueOpts?: Set<string>): ParsedArgs;
export function parseWords(args: Word[], shortValues?: string[], longValues?: string[]): WordArgs;
Import
import { lookup, registeredNames, psStr, parseWords, type PipelineCtx } from './registry.js';
import './commands/install-all.js'; // registers all command generators
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | string | Yes (lookup) | Bash command name to resolve |
| args | Word[] | Yes (Handler) | Parsed argv words for the command |
| ctx | PipelineCtx | Yes (Handler) | Pipeline position, stdin presence, translation mode |
Outputs
| Name | Type | Description |
|---|---|---|
| lookup returns | undefined | The generator, or undefined for pass-through commands |
| Handler returns | string | A block of PowerShell statements (no wrapper, no exit) |
Usage Examples
Resolve a Command Generator
import { lookup, type PipelineCtx } from './registry.js';
const handler = lookup('ls');
if (handler) {
const ps = handler(args, { position: 'last', hasStdin: false });
// ps is a block of PowerShell statements
} else {
// Unknown command → pass through natively
}
List All Registered Commands
import { registeredNames } from './registry.js';
console.log(registeredNames().length + ' translated commands');
for (const n of registeredNames()) console.log(' ' + n);