$ show bobthecow/psysh
PsySH is a production-grade interactive PHP shell, REPL, and runtime debugger. It accepts PHP input from a terminal, validates and rewrites it through a pipeline of PHP-Parser AST passes, evaluates it inside an isolated execution context, and renders results using a custom VarDumper presenter, formatters, and support for paging, themes, clipboard copy, and OSC 8 hyperlinks. It is distributed both as a Composer library and a self-updating PHAR binary, with primary entry points in src/functions.php (sh(), debug(), info(), bin()) and the bin/psysh launcher. The architecture is modular and interface-driven: a central Shell/Configuration core coordinates commands built on Symfony Console, multiple readline backends (GNU, libedit, userland, and a new experimental interactive readline), a completion engine with typed sources and refiners, legacy tab-completion matchers, execution-loop listeners, manual/documentation loaders, and updater strategies for both the PHP manual and PsySH itself. The main data flow is: terminal input -> readline -> code cleaning/validation -> eval -> output; completion and history are layered on top via AST analysis, fuzzy matching, suggestions, and JSONL-backed history persistence. The codebase is unusually thorough for a developer tool: nearly every subsystem has unit and integration tests, CI spans PHP 7.4 through 8.6 plus 32-bit and downstream consumer tests, and static analysis baselines manage compatibility across php-parser 4-5 and Symfony 3.4-7.x. The main weaknesses are the vendored Hoa terminal library, a wide compatibility surface requiring deprecation baselines and version shims, and the complexity of the experimental interactive readline, which creates maintenance risk. Overall this is a high-craft, actively maintained project with several genuinely reusable components.
The LLM identified 5 files worth highlighting for reuse:
Implements Fish-shell-style fuzzy completion matching with subsequence scoring. It is self-contained, dependency-light, and can be extracted into any terminal UI or search tool that needs ranked fuzzy candidate filtering.
Provides ANSI- and OSC 8-aware string width measurement, grapheme-safe truncation, and hyperlink extraction. This solves a recurring terminal-rendering problem and can be reused in any CLI project that must align or wrap colored text correctly.
Implements a bounded, deduplicating, searchable command history with JSONL persistence and session tracking. The pattern is directly portable to other interactive shells or CLI applications needing robust history management.
An AST visitor that auto-imports unqualified class names into the current namespace based on loaded classes and namespace filters. Demonstrates non-obvious PHP-Parser traversal and is reusable in PHP tooling that needs automatic use-statement insertion.
A PHPDoc parser for extracting @method, @property, @param, @return, and @throws metadata, with caching support for magic method/property reflection. It is a self-contained parsing utility useful beyond PsySH for static analysis or IDE-like tooling.