$ show solidsnack/arx
Arx is a Haskell CLI tool and library that archives execution contexts (source code, command, environment) into a self-extracting POSIX shell script. The generated script sets up a temporary directory, unpacks archives, sets environment variables, and executes the command with trap-based cleanup. The system is designed for reliable, reproducible remote execution via SSH/sudo piped to sh. The Haskell library provides a clean type-class based interface (ARX, SHDAT, TMPX) for building such scripts, with sub-modules for shell variable validation, tar format detection, and a novel scheme for encoding arbitrary binary data into shell HEREDOCs with minimal overhead (handling NUL bytes and escape characters). The CLI uses a custom combinator parser built with Parsec. This is a well-architected, focused tool demonstrating deep knowledge of both Haskell and shell scripting.
The LLM identified 3 files worth highlighting for reuse:
Implements a novel algorithm for encoding arbitrary binary data into POSIX shell HEREDOC chunks that can be decoded with standard 'tr' and 'sed' commands. Handles NUL bytes by selecting a null-replacer and escape byte candidates from ASCII printable characters that appear least frequently in the data, then uses a two-pass substitution pipeline. This module is self-contained, competently documented with worst-case size overhead analysis (~1% random data, ~10% pathological), and could be extracted for any project needing to embed binary blobs into shell scripts.
Provides types and validators for shell variable names and values (Var, Val) with proper character set checks, plus a Render type class for converting shell constructs to 'Blaze.Builder'. Includes environment variable export rendering and array rendering. Clean, minimal, and reusable for any Haskell shell code generation.
Defines non-overlapping token classes (EnvBinding, QualifiedPath, Dash, Size, URL, etc.) with Attoparsec recognizers and predictive parsers (e.g., size suffixes with IEC/binary multipliers). Demonstrates careful design for disambiguating command-line arguments, which could be extracted for any CLI parser needing to classify tokens by shape (not just match).