Skip to content

Commit e93d887

Browse files
Jonathan D.A. Jewellclaude
andcommitted
feat(validator): add comprehensive shell validation package
New Shell_Validator Ada package with 50+ validation functions: Syntax & Sequence: - Syntax validation (bash -n, shellcheck integration) - Command sequence ordering - Infinite loop detection - Dead code detection Directory & Files: - Directory structure validation - Symlink verification - File presence and completeness checks Permissions: - Read/write/execute validation - Ownership verification - World-writable and SUID/SGID detection Duplication: - Duplicate aliases, functions, exports - PATH duplicates - Conflicting settings detection POSIX Compliance: - Strict/Relaxed/Extended compliance levels - Bashism detection - Portable syntax validation Performance: - Load time analysis - Slow command detection - Lazy loading suggestions - Execution flow analysis Security: - Hardcoded secret detection - Dangerous command detection - Input sanitization validation - CVE vulnerability checks - Sudo usage validation System Integration: - SELinux context validation - Firewall safety checks - Starship, direnv, asdf, atuin integration Formal Verification: - ShellCheck, BATS, Pyre integration hooks - Theorem prover export (experimental) - SARIF output for CI/CD ROADMAP updated with: - Milestone 5: Comprehensive Validation - Appendix A: POSIX Shell Validation Roadmap - Appendix B: Non-POSIX Shell Compatibility Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 769bbc5 commit e93d887

3 files changed

Lines changed: 1364 additions & 2 deletions

File tree

ROADMAP.adoc

Lines changed: 319 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,89 @@ Inject sourcing logic into shell configurations.
173173
* [ ] Import from bash-it
174174
* [ ] Export to portable format
175175

176-
== Milestone 5: Advanced Features
176+
== Milestone 5: Comprehensive Validation (NEW)
177177

178-
=== 5.1 Remote Configuration
178+
The Shell Validator provides comprehensive validation, verification, and security analysis.
179+
180+
=== 5.1 Syntax and Sequence Validation
181+
182+
* [ ] `Validate_Syntax` - Run bash -n and shellcheck
183+
* [ ] `Validate_Command_Sequence` - Ensure correct ordering (exports before use)
184+
* [ ] `Detect_Infinite_Loops` - Static analysis for potential loops
185+
* [ ] `Detect_Skipped_Blocks` - Dead code detection
186+
187+
=== 5.2 Directory and File Validation
188+
189+
* [ ] `Validate_Directory_Structure` - Check modular structure
190+
* [ ] `Validate_Symlinks` - Verify all symlinks are valid
191+
* [ ] `Validate_File_Presence` - Check required files exist
192+
* [ ] `Validate_Completeness` - No orphaned modules
193+
194+
=== 5.3 Permission Validation
195+
196+
* [ ] `Validate_Permissions` - Correct read/write/execute
197+
* [ ] `Validate_Ownership` - File owned by current user
198+
* [ ] `Detect_World_Writable` - Security risk detection
199+
* [ ] `Detect_SUID_SGID` - Inappropriate permission bits
200+
201+
=== 5.4 Duplication Detection
202+
203+
* [ ] `Detect_Duplicate_Aliases` - Find duplicate alias definitions
204+
* [ ] `Detect_Duplicate_Functions` - Find duplicate function definitions
205+
* [ ] `Detect_Duplicate_Exports` - Find duplicate exports
206+
* [ ] `Detect_Path_Duplicates` - Find duplicate PATH entries
207+
* [ ] `Detect_Conflicting_Settings` - Find overriding settings
208+
209+
=== 5.5 POSIX Compliance
210+
211+
* [ ] `Validate_POSIX_Compliance` - Strict/Relaxed/Extended levels
212+
* [ ] `Detect_Bashisms` - Find bash-specific syntax
213+
* [ ] `Validate_Portable_Syntax` - Cross-shell compatibility
214+
215+
=== 5.6 Performance Analysis
216+
217+
* [ ] `Analyze_Load_Time` - Profile shell startup
218+
* [ ] `Detect_Slow_Commands` - Find slow initialization
219+
* [ ] `Suggest_Lazy_Loading` - Deferred loading candidates
220+
* [ ] `Analyze_Execution_Flow` - Optimal load order
221+
222+
=== 5.7 Security Validation
223+
224+
* [ ] `Detect_Hardcoded_Secrets` - Find exposed credentials
225+
* [ ] `Detect_Dangerous_Commands` - rm -rf, eval, exec
226+
* [ ] `Validate_Input_Sanitization` - Proper quoting
227+
* [ ] `Check_CVE_Vulnerabilities` - Known shell CVEs
228+
* [ ] `Validate_Sudo_Usage` - Safe sudo patterns
229+
230+
=== 5.8 SELinux and Firewall Compatibility
231+
232+
* [ ] `Validate_SELinux_Context` - Appropriate contexts
233+
* [ ] `Detect_SELinux_Conflicts` - Policy violations
234+
* [ ] `Validate_Firewall_Safety` - Network command safety
235+
236+
=== 5.9 Tool Integration Validation
237+
238+
* [ ] `Validate_Starship_Config` - Prompt configuration
239+
* [ ] `Validate_Completion_Setup` - bash-completion, carapace
240+
* [ ] `Validate_Direnv_Integration` - Hook placement
241+
* [ ] `Validate_Asdf_Integration` - Version manager setup
242+
* [ ] `Validate_Atuin_Integration` - History sync
243+
244+
=== 5.10 Formal Verification
245+
246+
* [ ] `Run_Formal_Verification` - ShellCheck, BATS, Pyre
247+
* [ ] `Generate_Verification_Report` - Comprehensive report
248+
* [ ] `Export_For_Theorem_Prover` - Experimental prover export
249+
250+
=== 5.11 Annotation and Metadata
251+
252+
* [ ] `Validate_SPDX_Headers` - License headers
253+
* [ ] `Validate_Annotations` - Required comments
254+
* [ ] `Check_Documentation_Coverage` - Function documentation
255+
256+
== Milestone 6: Advanced Features
257+
258+
=== 6.1 Remote Configuration
179259

180260
* [ ] Sync configurations via Git
181261
* [ ] Encrypted secrets handling
@@ -217,6 +297,243 @@ Inject sourcing logic into shell configurations.
217297
* [ ] Tutorial: "Modularising Your Shell in 5 Minutes"
218298
* [ ] Architecture Decision Records (ADRs)
219299

300+
== Appendix A: POSIX Shell Validation Roadmap
301+
302+
Validation support for POSIX-compliant shells. The Shell Validator will provide equivalent validation capabilities for all POSIX shells.
303+
304+
=== A.1 POSIX Shell Matrix
305+
306+
[cols="1,2,2,1"]
307+
|===
308+
| Shell | Config Files | Special Considerations | Priority
309+
310+
| **sh (Bourne)**
311+
| `/etc/profile`, `~/.profile`
312+
| Strictest POSIX compliance, no arrays
313+
| High
314+
315+
| **dash**
316+
| `ENV` variable, `~/.profile`
317+
| Debian/Ubuntu `/bin/sh`, fastest startup
318+
| High
319+
320+
| **bash**
321+
| `~/.bashrc`, `~/.bash_profile`
322+
| Most common, extensive extensions
323+
| Complete
324+
325+
| **ksh (KornShell)**
326+
| `~/.kshrc`, `~/.profile`
327+
| POSIX superset, advanced features
328+
| Medium
329+
330+
| **zsh**
331+
| `~/.zshrc`, `~/.zprofile`, `~/.zshenv`
332+
| Extensive customisation, oh-my-zsh ecosystem
333+
| High
334+
335+
| **ash (BusyBox)**
336+
| `ENV` variable
337+
| Embedded systems, Alpine Linux
338+
| Medium
339+
340+
| **mksh**
341+
| `~/.mkshrc`
342+
| Android shell, MirBSD
343+
| Low
344+
345+
| **yash**
346+
| `~/.yashrc`
347+
| Strictest POSIX compliance
348+
| Low
349+
|===
350+
351+
=== A.2 POSIX Validation Features
352+
353+
Each POSIX shell will support:
354+
355+
* [ ] Syntax validation using shell's native `-n` flag
356+
* [ ] POSIX compliance level checking (strict/relaxed)
357+
* [ ] Shell-specific extension detection
358+
* [ ] Configuration file location resolution
359+
* [ ] Startup script ordering validation
360+
* [ ] Environment variable inheritance checking
361+
* [ ] Signal handling validation
362+
* [ ] Exit code propagation analysis
363+
364+
=== A.3 Cross-Shell Portability Testing
365+
366+
* [ ] Generate portable shell scripts from modular configs
367+
* [ ] Test execution across sh, dash, bash, ksh, zsh
368+
* [ ] Report shell-specific incompatibilities
369+
* [ ] Suggest portable alternatives for non-portable constructs
370+
371+
== Appendix B: Non-POSIX Shell Compatibility
372+
373+
Support for modern non-POSIX shells requires different validation strategies.
374+
375+
=== B.1 Non-POSIX Shell Matrix
376+
377+
[cols="1,2,2,2"]
378+
|===
379+
| Shell | Config Files | Language/Paradigm | Compatibility Notes
380+
381+
| **Fish**
382+
| `~/.config/fish/config.fish`
383+
| Not POSIX, user-friendly syntax
384+
| No `$()`, uses `(command)`. No `export`, uses `set -x`. Different quoting rules.
385+
386+
| **Nushell**
387+
| `~/.config/nushell/config.nu`
388+
| Structured data, tables as first-class
389+
| Completely different paradigm. Pipeline operates on structured data, not text.
390+
391+
| **Elvish**
392+
| `~/.config/elvish/rc.elv`
393+
| Functional, structured values
394+
| Different variable syntax (`$var` vs `set var`). Rich data types.
395+
396+
| **Ion**
397+
| `~/.config/ion/initrc`
398+
| Rust-inspired, typed
399+
| Method syntax on variables. Strong typing. Array operations differ.
400+
401+
| **Oils (osh/ysh)**
402+
| `~/.oshrc`, `~/.yshrc`
403+
| POSIX-compatible (osh) + enhanced (ysh)
404+
| osh is POSIX-compatible. ysh adds JSON, expressions, better errors.
405+
406+
| **PowerShell**
407+
| `$PROFILE` (varies by platform)
408+
| Object-oriented, .NET based
409+
| Completely different. Cmdlets, objects in pipeline, `-Verb-Noun` naming.
410+
411+
| **Tcsh/Csh**
412+
| `~/.tcshrc`, `~/.cshrc`
413+
| C-like syntax
414+
| Different syntax for everything. Avoid for scripting (historical only).
415+
416+
| **Xonsh**
417+
| `~/.xonshrc`
418+
| Python + shell hybrid
419+
| Python syntax mixed with shell. Import Python directly.
420+
421+
| **Murex**
422+
| `~/.murex_profile`
423+
| Type-aware, safety-focused
424+
| Strong typing, safer defaults, different pipeline semantics.
425+
|===
426+
427+
=== B.2 Non-POSIX Validation Strategy
428+
429+
For each non-POSIX shell, implement:
430+
431+
==== Fish
432+
* [ ] Native syntax validation (`fish -n`)
433+
* [ ] Universal variable handling
434+
* [ ] Abbreviation vs alias distinction
435+
* [ ] Function autoloading paths
436+
* [ ] Fisher/oh-my-fish plugin detection
437+
438+
==== Nushell
439+
* [ ] Native syntax validation
440+
* [ ] Module system validation
441+
* [ ] Hook configuration (env_change, pre_prompt)
442+
* [ ] Plugin registration
443+
* [ ] Structured config validation (TOML-based)
444+
445+
==== Elvish
446+
* [ ] Native syntax validation
447+
* [ ] Module import validation
448+
* [ ] Edit mode configuration
449+
* [ ] Persistent variable handling
450+
451+
==== Ion
452+
* [ ] Native syntax validation
453+
* [ ] Method call validation
454+
* [ ] Array type checking
455+
* [ ] Plugin/builtin validation
456+
457+
==== Oils (osh/ysh)
458+
* [ ] osh: POSIX validation
459+
* [ ] ysh: Enhanced syntax validation
460+
* [ ] Expression evaluation safety
461+
* [ ] JSON/YAML parsing in configs
462+
463+
==== PowerShell
464+
* [ ] Native syntax validation (`Test-ScriptFileInfo`)
465+
* [ ] Module manifest validation
466+
* [ ] Execution policy compliance
467+
* [ ] Cross-platform path handling (Windows/Linux/macOS)
468+
469+
=== B.3 Translation Layer
470+
471+
For cross-shell configuration:
472+
473+
* [ ] Define common abstraction for aliases
474+
* [ ] Define common abstraction for environment variables
475+
* [ ] Define common abstraction for PATH modifications
476+
* [ ] Transpiler from abstract config to shell-specific syntax
477+
* [ ] Bidirectional sync between shell configs
478+
479+
=== B.4 Shell Feature Detection
480+
481+
Runtime detection of shell capabilities:
482+
483+
[cols="1,1,1,1,1,1"]
484+
|===
485+
| Feature | Bash | Zsh | Fish | Nushell | PowerShell
486+
487+
| Arrays
488+
| ✓
489+
| ✓
490+
| ✓
491+
| ✓ (tables)
492+
| ✓
493+
494+
| Associative Arrays
495+
| ✓ (4.0+)
496+
| ✓
497+
| ✗
498+
| ✓ (records)
499+
| ✓ (hashtables)
500+
501+
| Command Substitution
502+
| `$()`
503+
| `$()`
504+
| `()`
505+
| `()`
506+
| `$()`
507+
508+
| Process Substitution
509+
| `<()`
510+
| `<()`
511+
| `psub`
512+
| ✗
513+
| ✗
514+
515+
| Job Control
516+
| ✓
517+
| ✓
518+
| ✓
519+
| Limited
520+
| ✓
521+
522+
| Programmable Completion
523+
| ✓
524+
| ✓
525+
| ✓
526+
| ✓
527+
| ✓
528+
529+
| Unicode Support
530+
| Limited
531+
| ✓
532+
| ✓
533+
| ✓
534+
| ✓
535+
|===
536+
220537
== Non-Goals
221538

222539
The following are explicitly out of scope:

0 commit comments

Comments
 (0)