diff options
author | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2025-08-13 19:26:18 +0200 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2025-08-13 19:26:18 +0200 |
commit | 681555c9e2583d4c1c2e538cc36fd5915ca75acf (patch) | |
tree | 20ef4377b4676ee3eabce4c05efcacc0cb9d677a | |
parent | aeb4a98bb36f129000b6782f22a1f19009729634 (diff) |
Update CLAUDE.md.
-rw-r--r-- | CLAUDE.md | 108 |
1 files changed, 79 insertions, 29 deletions
@@ -4,48 +4,98 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Project Overview -**Dose** is a DOS-style command shell implementation written in Rust. The project aims to recreate classic DOS commands and shell functionality in a modern Rust environment, providing a nostalgic DOS computing experience. +**Dose** is a DOS-style command shell implementation written in Zig. Originally started in Rust, the project has been completely rewritten in Zig to provide a nostalgic DOS computing experience with modern systems programming capabilities. ## Development Commands ```bash -# Development -cargo run # Run in debug mode with REPL shell -cargo build # Build debug version -cargo check # Fast syntax/type checking -cargo clean # Clean build artifacts - -# Release builds (heavily optimized for size) -cargo build --release # Optimized build with LTO and size optimization -cargo run --release # Run optimized version +# Development (Zig) +zig build # Build debug version +zig build run # Build and run in debug mode +zig build test # Run unit tests +zig build -Doptimize=ReleaseFast # Optimized build + +# Legacy (Original Rust - archived) +cargo run # Run in debug mode with REPL shell +cargo build # Build debug version ``` ## Architecture ### Command System Design -The application uses a type-safe command architecture with Rust enums: +The application uses a type-safe command architecture with Zig unions and enums: -- **`Command`**: Top-level enum supporting pipes, redirections, external programs, and builtins -- **`BuiltinCommand`**: Comprehensive DOS command set covering file operations, shell control, scripting, and utilities +- **`Command`**: Top-level union supporting pipes, redirections, external programs, and builtins +- **`BuiltinCommand`**: Comprehensive DOS command set covering file operations, shell control, and utilities - **`FileSpec`**: Handles console (`Con`) vs file path targets for I/O redirection +- **`InputSource`**: Manages input redirection from files with line-by-line processing +- **`OutputCapture`**: Buffers command output for redirection to files + +### Implementation Status + +#### ✅ **Fully Implemented Features** +- **Interactive REPL Shell**: Command-line interface with DOS-style prompts (`C:\PATH>`) +- **Command Parsing**: Complete lexer/parser for DOS command syntax with quote support +- **Built-in Commands**: Core DOS commands with authentic behavior and error messages +- **External Command Execution**: Full process spawning with I/O redirection support +- **I/O Redirection**: Complete input (`<`), output (`>`), and append (`>>`) redirection +- **Error Handling**: DOS-authentic error messages and proper exit codes +- **Path Formatting**: DOS-style path display with drive letters and 8.3 filename conversion + +#### 📋 **Built-in Commands Available** +- **`ECHO`** (with ON/OFF variants) - Text output and echo state control +- **`CLS`** - Clear screen with ANSI escape sequences +- **`EXIT`** - Exit the shell +- **`VER`** - Version information display +- **`DATE`** - Current system date with proper calendar calculations +- **`TIME`** - Current system time display +- **`DIR`** - Directory listing with file sizes and counts +- **`TYPE`** - Display file contents with binary character filtering +- **`SORT`** - Alphabetical line sorting with input redirection support + +#### 🔧 **External Command Support** +- **Process Spawning**: Uses `std.process.Child` for external program execution +- **Argument Passing**: Proper command-line argument handling +- **I/O Redirection**: Full stdin/stdout/stderr redirection support +- **Error Handling**: DOS-compatible "command not found" messages +- **Exit Code Propagation**: Proper process exit code handling -### Current Implementation Status -- **Implemented**: Basic REPL shell with `rustyline` for interactive input -- **Stubbed**: Command parsing (`parse` method returns "Not implemented") -- **Planned**: Full DOS command execution based on the `BuiltinCommand` enum +#### 🔀 **Redirection System** +- **Input Redirection** (`<`): Read file content as command input +- **Output Redirection** (`>`): Write command output to file (overwrite) +- **Append Redirection** (`>>`): Append command output to file +- **Combined Redirection**: Support for both input and output redirection simultaneously +- **Device Handling**: Proper CON/LPT/PRN device recognition and error handling -### Key DOS Commands Planned -File operations (`type`, `copy`, `xcopy`, `dir`, `tree`), shell control (`prompt`, `echo`, `set`, `chdir`), and classic utilities (`date`, `time`, `cls`, `mem`). +### Key Technical Features -### Error Handling -Uses modern Rust error handling with `eyre::Result` and `color-eyre` for enhanced error reporting with colored output. +#### **Memory Management** +- **Allocator-based**: Uses Zig's `GeneralPurposeAllocator` for all dynamic memory +- **RAII Pattern**: Proper resource cleanup with `defer` statements +- **Leak Detection**: Built-in memory leak detection in debug builds + +#### **Error Handling** +- **Zig Error Unions**: Native `!T` error handling instead of exceptions +- **DOS-Authentic Messages**: Faithful reproduction of classic DOS error text +- **Graceful Degradation**: Robust error recovery and user guidance + +#### **Cross-Platform Support** +- **Zig Standard Library**: Portable file system and process operations +- **ANSI Terminal Support**: Cross-platform terminal manipulation +- **Path Handling**: DOS-style path formatting on all platforms ### Dependencies -- **`rustyline`**: Interactive command-line editing and history -- **`crossterm`**: Cross-platform terminal manipulation -- **`prettytable-rs`**: Table formatting for command output -- **`eyre`/`color-eyre`**: Enhanced error handling and reporting -- **`thiserror`**: Error type derivation macros - -## Release Optimization -The release profile is configured for maximum size optimization with LTO, `opt-level = "z"`, symbol stripping, and single codegen unit compilation. + +**Zero External Dependencies** - The Zig implementation uses only the standard library: +- **`std.process`**: External command execution and process management +- **`std.fs`**: File system operations for I/O redirection and DIR command +- **`std.mem`**: Memory management and string operations +- **`std.time`**: System time access for DATE/TIME commands +- **`std.io`**: Terminal I/O and file operations + +### Build Configuration + +The project uses Zig's standard build system with optimizations: +- **Debug builds**: Full error checking and memory leak detection +- **Release builds**: Size and speed optimized for production use +- **Cross-compilation**: Native Zig cross-platform compilation support |