How emmyakine/codecrafters-shell-csharp works
1. This repository is a C#/.NET implementation of a POSIX-like shell for the CodeCrafters “Build Your Own Shell” challenge. The runtime entry point is src/main.cs, and the app is packaged as codecrafters-shell.csproj / codecrafters-shell.sln.
2. The core runtime boundary is the interactive shell loop in src/Shell.cs. It is responsible for reading user input, handing it off for parsing/dispatch, and coordinating execution results back to the terminal.
3. Input parsing is isolated in src/Tokenizer.cs and src/Token.cs. This layer turns raw command text into shell tokens, which is the main front door for handling quoting, separators, arguments, and other command-line syntax before execution.
4. After tokenization, src/CommandDispatcher.cs appears to be the orchestration layer that decides what kind of command is being run. It likely routes between builtin commands, external programs, pipelines, redirections, and special shell behaviors.
5. Built-in shell behavior is separated into src/BuiltinCommands.cs. This is where shell-native commands like cd, pwd, echo, or similar challenge-required commands are handled without spawning a child process.
6. External program execution is encapsulated in src/ExternalCommand.cs. This forms the boundary to the host operating system: resolving an executable, launching it, and capturing its exit behavior/output as needed by the shell.
7. Path and command lookup are handled by src/PathResolver.cs. This is the subsystem that maps command names to executable locations using the environment/search path semantics expected from a shell.
8. Multi-command execution is handled separately in src/PipelineRunner.cs. This is the execution graph for connecting commands together, likely managing stdin/stdout chaining so one command’s output becomes the next command’s input.
9. Input/output redirection is modeled explicitly via src/RedirectSpec.cs. That suggests redirection is parsed into a distinct execution descriptor instead of being handled inline, which keeps command execution and file I/O concerns separated.
10. Background jobs and shell job tracking are split across src/Jobs.cs and src/JobTable.cs. These classes form the stateful subsystem for job control, storing running processes and enabling status/reporting behavior typical of shells.
11. src/AutoCompletionHandler.cs is a separate user-experience layer for interactive completion. It likely depends on the current shell state, known commands, and filesystem/path context rather than being part of command execution itself.
12. src/ICommand.cs is the abstraction that ties the execution model together. It suggests the shell treats builtins, external commands, and possibly pipeline elements through a common command interface, which makes the dispatcher simpler and keeps execution polymorphic.
13. The repository also includes CodeCrafters-specific tooling: .codecrafters/compile.sh, .codecrafters/run.sh, codecrafters.yml, and your_program.sh. These are the challenge harness and launch scripts, not core shell logic, and they mainly define how the solution is built and executed in the grading environment.
14. Overall data flow: terminal input enters Shell, gets tokenized, interpreted by the dispatcher, then executed through one of several execution paths—builtin handler, external process runner, pipeline executor, or job control. That separation is the key architecture boundary for diagramming this repo.
Main entry points: CommandDispatcher.cs Dispatcher · Shell.cs Shell · ExternalCommand.cs External · Tokenizer.cs Tokenizer
Components 18
Runtime
Interactive shell entrypoint, parsing, and dispatch flow.
- main.cs · Program entry that boots the shell.
src/main.cs - Shell · Reads input and coordinates shell requests.
src/Shell.cs - Tokenizer · Splits raw input into shell tokens.
src/Tokenizer.cs - Token · Represents parsed command-line tokens.
src/Token.cs - Dispatcher · Routes parsed input to the correct execution path.
src/CommandDispatcher.cs
Execution
Builtin, external, pipeline, and redirection execution paths.
- ICommand · Shared execution abstraction for command kinds.
src/ICommand.cs - Builtins · Implements shell-native commands.
src/BuiltinCommands.cs - External · Launches host executables and manages process execution.
src/ExternalCommand.cs - Path Resolver · Resolves command names against shell search paths.
src/PathResolver.cs - Pipeline Runner · Connects commands through stdin/stdout chaining.
src/PipelineRunner.cs - Redirect Spec · Represents input/output redirection details.
src/RedirectSpec.cs
State & UX
Interactive state management and completion support.
- Jobs · Coordinates background job lifecycle and status.
src/Jobs.cs - JobTable · Stores tracked jobs and their state.
src/JobTable.cs - Completion · Provides interactive command completion.
src/AutoCompletionHandler.cs
Tooling
Build/run harness for the CodeCrafters environment.
- compile.sh · CodeCrafters build step.
.codecrafters/compile.sh - run.sh · CodeCrafters runtime launch step.
.codecrafters/run.sh - codecrafters.yml · Challenge harness configuration.
codecrafters.yml - your_program.sh · Top-level program launch wrapper.
your_program.sh
Connections 18
- main.cs → Shell: starts · Entry point boots the interactive shell.
- Shell → Tokenizer: lexes · Shell sends raw input to the tokenizer.
- Tokenizer → Token: produces · Tokenizer emits token objects.
- Shell → Dispatcher: dispatches · Shell hands parsed input to command dispatch.
- Dispatcher → ICommand: uses · Dispatcher relies on the shared command abstraction.
- Dispatcher → Builtins: builtins · Routes shell-native commands to builtin handling.
- Dispatcher → External: externals · Routes external commands to process execution.
- Dispatcher → Pipeline Runner: pipelines · Routes chained commands to pipeline execution.
- Dispatcher → Redirect Spec: redirection · Carries redirection metadata into execution.
- External → Path Resolver: resolves · External execution depends on executable lookup.
- Pipeline Runner → External: runs · Pipeline stages execute through command runners.
- Builtins → Jobs: may use · Builtin behavior can interact with job control.
- Jobs → JobTable: tracks · Job control stores active background jobs.
- Shell → Completion: supports · Interactive shell exposes completion assistance.
- your_program.sh → run.sh: invokes · Launcher delegates to the run script.
- run.sh → codecrafters.yml: follows · Run harness is driven by challenge config.
- compile.sh → codecrafters.yml: follows · Build harness is driven by challenge config.
- Shell → your_program.sh: launched by · Shell is started through the wrapper script in the challenge environment.