# Termos Library — Remaining Work ## Phase 6: Async Process & Event System - [x] `Process` class: lifecycle, output accumulation, signal queue, SIGKILL, result event - [x] `ProcessManager`: create process, PID generation, event forwarding, cleanup - [x] `Shell` integration: execute, sendInput, event emitter, BoundPID - [ ] **Fix `async` demo command** — currently blocking; must `await io.getSignal()` - [ ] **Write integration tests for:** - [ ] Simple command via ProcessManager (events emitted, map cleaned) - [ ] Long-running command waits for signal and exits - [ ] SIGKILL terminates pending process (exit code 137) - [ ] Shell.sendInput routes input to foreground process - [ ] Global keybind overrides process keybind - [ ] Chunked stdout/stderr (large writes split ≤1024 bytes) - [ ] **Refactor `echo` and `cd` fully to new CommandFn** - [ ] **Update all existing command tests** to async signature - [ ] **Remove/replace `serializer.ts` stubs** - [ ] **Run full TS + lint + tests clean** ## Phase 7: Frontend Adapters & REPL - [ ] **Browser frontend adapter** - [ ] Define `FrontendAdapter` interface (sendInput, onEvent) - [ ] Implement DOM terminal renderer (xterm.js or custom) - [ ] Map DOM KeyboardEvents → normalized Input strings - [ ] Subscribe to Shell events (stdout, stderr, result, process) - [ ] Display prompt, cwd, exit code - [ ] Handle keybind routing from UI - [ ] **Node.js frontend adapter** - [ ] Raw mode input reading (`process.stdin`) - [ ] Map ANSI escape sequences → Input strings - [ ] Simple line editor / prompt - [ ] Render stdout/stderr to terminal - [ ] Ctrl+C handling - [ ] **Tests for both adapters** (mocked DOM / fake stdin) ## Phase 8: Core Built-in Commands - [ ] `pwd` — print current working directory - [ ] `ls` — list directory contents - [ ] `cat` — concatenate files - [ ] `echo` — already exists; add `-n`, escapes later - [ ] `export` — set environment variables - [ ] `history` — view/manipulate history - [ ] `clear` — clear screen (emit special event to UI) - [ ] `touch` — create empty file - [ ] `mkdir` — create directory - [ ] `rm` — remove file/directory - [ ] `mv` — move/rename - [ ] `cp` — copy file/directory - [ ] `chmod` — change permissions - [ ] `chown` — change owner/group - [ ] `less` — continuous process with keybinds (paged output) - [ ] `grep` — pattern matching (flags, exit codes) - [ ] **Each command: descriptor + tests + keybinds** ## Phase 9: Pipelines & Redirection - [ ] Extend parser to recognize `|`, `>`, `<`, `>>`, `2>` - [ ] Define pipeline execution model - [ ] Each command in pipeline runs as process - [ ] stdout of one feeds stdin of next - [ ] stderr separate - [ ] Implement redirection - [ ] `>` write to file - [ ] `<` read from file - [ ] `>>` append - [ ] `2>` redirect stderr - [ ] Update `CommandIO` with stdin stream if needed - [ ] ProcessManager supports multiple simultaneous processes in pipeline - [ ] Tests for pipelines and redirections ## Phase 10: Job Control & Background Processes - [ ] Add `&` operator to parser - [ ] Jobs table in ShellState or separate - [ ] `jobs` built-in - [ ] `fg` / `bg` built-ins - [ ] Shell updates `BoundPID` accordingly - [ ] Tests for job control ## Phase 11: Session & User Management - [ ] Expand `SessionManager` with `su`, `login`, `logout` - [ ] Password hashing - [ ] User database serialization/deserialization - [ ] Root permission enforcement in commands - [ ] `whoami`, `id`, `su`, `passwd` built-ins - [ ] Tests for session stack and permission boundaries ## Phase 12: Shell Scripting & Control Flow - [ ] Parser support for `;`, `&&`, `||`, `if`, `while`, `for` - [ ] Script execution mode (batch) - [ ] Environment variable expansion (`$VAR`) - [ ] Command substitution (`$(...)`) - [ ] Exit code propagation in control flow - [ ] Aliases - [ ] Tests for scripting features ## Phase 13: Persistence & Serialization - [ ] Finish `serializer.ts` correctly (Zod schemas) - [ ] Define stable JSON schema for filesystem tree - [ ] `serializeFileSystem` implementation - [ ] `deserializeFileSystem` implementation - [ ] Integration with browser storage adapter (IndexedDB) - [ ] Node storage adapter (JSON file) - [ ] Load/save overlay and inode counter - [ ] Tests for round-trip serialization, corruption handling ## Phase 14: Configuration & Library API - [ ] Global config object - [ ] max chunk size - [ ] history capacity - [ ] keybind map - [ ] Factory functions for `Shell`, `FileSystem`, `Session` - [ ] Public API barrel (`index.ts`) - [ ] Documentation (JSDoc, README) - [ ] Error type exports - [ ] Versioning / packaging ## Phase 15: Performance & Hardening - [ ] Profile large file operations - [ ] Optimize `resolvePath` / `traverseTree` - [ ] Reduce unnecessary object allocations - [ ] Add property-based tests for filesystem operations - [ ] Fuzz parser for malformed input - [ ] Security review (path traversal, permission bypass, signal handling) ## Phase 16: Frontend polish (if browser-first) - [ ] Terminal UI component with prompt, history navigation - [ ] Keyboard shortcuts - [ ] Scrollback buffer - [ ] Colorized output (ANSI escape sequences) - [ ] Multi-tab sessions (optional)